#! /bin/zsh

function mkInterf() {
  set -A fun
  while read tab; do
    ((++n))
    eval fun=$tab
    cat << EOF
[Data_1_${n}]
Comments=
Enabled=true
Name=$fun[1]
Type=GENERIC_ACTION_DATA

[Data_1_${n}Actions]
ActionsCount=1

[Data_1_${n}Actions0]
Arguments=$fun[3]
Call=$fun[2]
RemoteApp=kwin
RemoteObj=$1
Type=DCOP

[Data_1_${n}Conditions]
Comment=
ConditionsCount=0

EOF
    c=0
    [[ -n "$fun[4]" ]] && ((c++))
    [[ -n "$fun[5]" ]] && ((c++))
    cat << EOF
[Data_1_${n}Triggers]
Comment=
TriggersCount=$c

EOF
    c=0
    [[ -n "$fun[4]" ]] &&
    cat << EOF
[Data_1_${n}Triggers$((c++))]
Key=$fun[4]
Type=SHORTCUT

EOF
    [[ -n "$fun[5]" ]] &&
    cat << EOF
[Data_1_${n}Triggers${c}]
Gesture=$fun[5]
Type=GESTURE

EOF
  done
}



n=0; 
cat << EOF
[Main]
Version=2
ImportId=$RANDOM

[Data]
DataCount=1

[Data_1]
Comment=
DataCount=35
Enabled=true
Name=Kwin
SystemGroup=0
Type=ACTION_DATA_GROUP

[Data_1Conditions]
Comment=
ConditionsCount=0

EOF
 
# WIN+CTRL+ALT+arrows/tab/stab
mkInterf Windows << EOF
("Move Window to Next Desktop"   "setDesktop" "1 1 0"  "Win+Ctrl+Alt+Tab")
("Move Window to Prev Desktop"   "setDesktop" "-1 1 0" "Win+Ctrl+Alt+Shift+Tab")
("Move Window to Left Desktop"   "setDesktop" "-1 2 0" "Win+Ctrl+Alt+Left")
("Move Window to Right Desktop"  "setDesktop" "1 2 0"  "Win+Ctrl+Alt+Right")
("Move Window to Top Desktop"    "setDesktop" "-1 3 0"  "Win+Ctrl+Alt+Up")
("Move Window to Bottom Desktop" "setDesktop" "1 3 0" "Win+Ctrl+Alt+down")
EOF

# WIN+CTRL+arrows, WIN+CTRL+space
mkInterf Windows << EOF
("Move Window Up"    "setPosRel" "0,-10 0"  "Win+Ctrl+Up")
("Move Window Down"  "setPosRel" "0,10 0"  "Win+Ctrl+Down")
("Move Window Left"  "setPosRel" "-10,0 0" "Win+Ctrl+Left")
("Move Window Right" "setPosRel" "10,0 0"  "Win+Ctrl+Right")
("Move Window Interactive" "setPosInteractive" "0" "Win+Ctrl+Space")
EOF

# KGesture 'V' minimize (1478963)
# KGesture '^' maximize (7412369)
# KGesture 'X' close (7532159)
# KGesture '|' Raise or Lower (258) 
# KGesture '-' Shade (456)
mkInterf Windows << EOF
("Close" "close" "0" "" "7532159")
("Kill" "kill" "0")
("KillInteractive" "killInteractive" "")
("Raise Window" "raiseOrLower" "1 0")
("Low Window" "raiseOrLower" "-1 0")
("Raise or Low Window" "raiseOrLower" "0 0" "" "258")
("Set Window Size Interactive" "setSizeInteractive" "0" "Win+Ctrl+Shift+Space")
("Set Shortcut Interactive" "setShortcutInteractive" "0" "Win+space")
("Switch FullScreen" "setFullscreen" "0 0")
("Switch Maximize" "setMaximized" "0 0" "" "1478963")
("Switch Minimize" "setMinimized" "0 0" "" "7412369")
("Switch Shade" "setShaded" "0 0" "" "456")
("Switch Keep Above" "setKeepAbove" "0 0")
("Switch Keep Below" "setKeepBelow" "0 0")
EOF

# Desktops WIN+Arrows/tab/stab
# Mouse gestures '[' (9874123) and ']' (7896321) for next and prev
mkInterf Desktops << EOF
("Goto Next Desktop"     "gotoDesktopRel" "1 1"  "Win+Tab" "7896321")
("Goto Previous Desktop" "gotoDesktopRel" "-1 1" "Win+Shift+Tab" "9874123")
("Goto Left Desktop"     "gotoDesktopRel" "-1 2" "Win+Left")
("Goto Right Desktop"    "gotoDesktopRel" "1 2"  "Win+Right")
("Goto Bottom Desktop"   "gotoDesktopRel" "1 3"  "Win+Down")
("Goto Top Desktop"      "gotoDesktopRel" "-1 3" "Win+Up")
EOF

# Cursor WIN+ALT+arrows
mkInterf Cursor << EOF
("Move Cursor Up"    "moveCursorRel" "0,-10"  "Win+Alt+Up")
("Move Cursor Down"  "moveCursorRel" "0,10" "Win+Alt+Down")
("Move Cursor Left"  "moveCursorRel" "-10,0" "Win+Alt+Left")
("Move Cursor Right" "moveCursorRel" "10,0"  "Win+Alt+Right")
EOF
