From c427a0eb7bda4a71479676e9f4f98afcdd6bea8d Mon Sep 17 00:00:00 2001 From: Stacy Harper Date: Sat, 12 Jun 2021 13:33:35 +0200 Subject: [PATCH] Cleanup input handling We now use uncontextualized event name from lisgd as leftrightcorner. We will determine the action name only in the input handler. It allow events to match multiple action depending on contexts. We also add some basics events as left/rigth/up/down and twoleft/tworight/twoup/twodown and use some of them. Use use twoup and twodown to scroll in less and right left to change the page. We also prefer use case switch instead of if conditions. We remove this HANDLE variable usage and exit directly when the event has been handled. We also add some methods as type, key or typeenter to simplify some code. Signed-off-by: Stacy Harper Signed-off-by: Maarten van Gompel --- scripts/core/sxmo_inputhandler.sh | 382 +++++++++++++++++------------- scripts/core/sxmo_lisgdstart.sh | 48 ++-- 2 files changed, 242 insertions(+), 188 deletions(-) diff --git a/scripts/core/sxmo_inputhandler.sh b/scripts/core/sxmo_inputhandler.sh index eba9179..f041a9b 100755 --- a/scripts/core/sxmo_inputhandler.sh +++ b/scripts/core/sxmo_inputhandler.sh @@ -28,6 +28,21 @@ lock_screen() { fi } +key() { + xdotool windowactivate "$WIN" + xdotool key --delay 50 --clearmodifiers "$@" +} + +type() { + xdotool windowactivate "$WIN" + xdotool type --delay 50 --clearmodifiers "$@" +} + +typeenter() { + type "$@" + xdotool key Return +} + if [ "$(sxmo_screenlock.sh getCurState)" != "unlock" ]; then case "$ACTION" in "volup_three") @@ -51,176 +66,209 @@ XPROPOUT="$(xprop -id "$(xdotool getactivewindow)")" WMCLASS="$(echo "$XPROPOUT" | grep WM_CLASS | cut -d ' ' -f3-)" WMNAME=$(echo "$XPROPOUT" | grep -E "^WM_NAME" | cut -d ' ' -f3-) -HANDLE=1 if [ -x "$XDG_CONFIG_HOME"/sxmo/hooks/inputhandler ]; then #hook script must exit with a zero exit code ONLY if it has handled the gesture! - "$XDG_CONFIG_HOME"/sxmo/hooks/inputhandler "$WMCLASS" "$WMNAME" "$@" - HANDLE=$? + "$XDG_CONFIG_HOME"/sxmo/hooks/inputhandler "$WMCLASS" "$WMNAME" "$@" && exit fi -if [ "$HANDLE" -ne 0 ]; then - #special context-sensitive handling - case "$WMCLASS" in - "foxtrotgps") - # E.g. just a check to ignore 1-finger gestures in foxtrotgps - if [ "$ACTION" != "killwindow" ]; then - HANDLE=0 - fi - ;; - "st-256color") - # First we try to handle the app running inside st: - if echo "$WMNAME" | grep -i -w tuir; then - if [ "$ACTION" = "enter" ]; then - xdotool key o - HANDLE=0 - elif [ "$ACTION" = "back" ]; then - xdotool key s - HANDLE=0 +#special context-sensitive handling +case "$WMCLASS" in + *"st-256color"*) + # First we try to handle the app running inside st: + case "$WMNAME" in + *"tuir"*) + if [ "$ACTION" = "rightbottomcorner" ]; then + type o + exit 0 + elif [ "$ACTION" = "leftbottomcorner" ]; then + type s + exit 0 fi - elif echo "$WMNAME" | grep -i -E -w "(less|mless)"; then - if [ "$ACTION" = "back" ] || [ "$ACTION" = "scrollleft_short" ]; then - xdotool key q - HANDLE=0 - fi - fi - ;; - esac -fi + ;; + *"less"*) + case "$ACTION" in + "leftbottomcorner") + type q + exit 0 + ;; + "leftrightcorner_short") + type q + exit 0 + ;; + "twodown") + type u + exit 0 + ;; + "twoup") + type d + exit 0 + ;; + "left") + typeenter ":n" + exit 0 + ;; + "right") + typeenter ":p" + exit 0 + ;; + esac + ;; + esac +esac -if [ "$HANDLE" -ne 0 ]; then - #standard handling - case "$ACTION" in - "prevdesktop") - xdotool key --clearmodifiers Super+Shift+e - ;; - "nextdesktop") - xdotool key --clearmodifiers Super+Shift+r - ;; - "moveprevdesktop") - xdotool key --clearmodifiers Super+e - ;; - "movenextdesktop") - xdotool key --clearmodifiers Super+r - ;; - "unmute") - sxmo_vol.sh unmute & - ;; - "mute") - sxmo_vol.sh mute & - ;; - "brightnessup") - sxmo_brightness.sh up & - ;; - "brightnessdown") - sxmo_brightness.sh down & - ;; - "volup") - sxmo_vol.sh up & - ;; - "voldown") - sxmo_vol.sh down & - ;; - "showkeyboard") - sxmo_keyboard.sh open - ;; - "hidekeyboard") - sxmo_keyboard.sh close - ;; - "showmenu") - pidof dmenu || setsid -f sxmo_appmenu.sh & - ;; - "showsysmenu") - pidof dmenu || setsid -f sxmo_appmenu.sh sys & - ;; - "hidemenu") - pkill -9 dmenu - dunstctl close-all - ;; - "closewindow") - sxmo_killwindow.sh close - ;; - "killwindow") - sxmo_killwindow.sh - ;; - "scrollup_long") - xdotool key Prior - ;; - "scrolldown_long") - xdotool key Next - ;; - "scrollup_med") - xdotool key Up Up Up - ;; - "scrolldown_med") - xdotool key Down Down Down - ;; - "scrollup_short") - xdotool key Up - ;; - "scrolldown_short") - xdotool key Down - ;; - "scrollleft_short") - xdotool key Left - ;; - "scrollright_short") - xdotool key Right - ;; - "enter") - xdotool key Return - ;; - "back") - xdotool key BackSpace - ;; - "powerbutton_one") - if echo "$WMCLASS" | grep -i "megapixels"; then - xdotool key --clearmodifiers "space" - else - sxmo_keyboard.sh toggle - fi - ;; - "powerbutton_two") - sxmo_blinkled.sh blue && $TERMCMD -e "$SHELL" - ;; - "powerbutton_three") - sxmo_blinkled.sh blue && $BROWSER - ;; - "volup_one") - sxmo_appmenu.sh - ;; - "volup_two") - sxmo_appmenu.sh sys - ;; - "volup_three") - lock_screen - ;; - "voldown_one") - xdotool key --clearmodifiers Super+space - ;; - "voldown_two") - xdotool key --clearmodifiers Super+Return - ;; - "voldown_three") - sxmo_blinkled.sh red && sxmo_killwindow.sh - ;; - "voldown_four") - sxmo_blinkled.sh red & sxmo_killwindow.sh close - ;; - "topleftcorner") - sxmo_appmenu.sh sys & - ;; - "toprightcorner") - sxmo_appmenu.sh scripts & - ;; - "bottomleftcorner") - lock_screen - ;; - "bottomrightcorner") - sxmo_rotate.sh & - ;; - *) - #fallback, just execute the command - "$@" - ;; - esac -fi +#standard handling +case "$ACTION" in + "rightleftcorner") + key Super+Shift+e + exit 0 + ;; + "leftrightcorner") + key Super+Shift+r + exit 0 + ;; + "twoleft") # Move window previous + key Super+e + exit 0 + ;; + "tworight") # Move window next + key Super+r + exit 0 + ;; + "unmute") + sxmo_vol.sh unmute & + exit 0 + ;; + "mute") + sxmo_vol.sh mute & + exit 0 + ;; + "righttopcorner") + sxmo_brightness.sh up & + exit 0 + ;; + "lefttopcorner") + sxmo_brightness.sh down & + exit 0 + ;; + "upleftcorner") + sxmo_vol.sh up & + exit 0 + ;; + "downleftcorner") + sxmo_vol.sh down & + exit 0 + ;; + "upbottomcorner") + sxmo_keyboard.sh open + exit 0 + ;; + "downbottomcorner") + sxmo_keyboard.sh close + exit 0 + ;; + "downtopcorner") + pidof dmenu || setsid -f sxmo_appmenu.sh & + exit 0 + ;; + "twodowntopcorner") + pidof dmenu || setsid -f sxmo_appmenu.sh sys & + exit 0 + ;; + "uptopcorner") + pkill -9 dmenu + dunstctl close-all + exit 0 + ;; + "twodownbottomcorner") + sxmo_killwindow.sh close + exit 0 + ;; + "threedownbottomcorner") + sxmo_killwindow.sh + exit 0 + ;; + "uprightcorner") + xdotool key Up + exit 0 + ;; + "downrightcorner") + xdotool key Down + exit 0 + ;; + "leftrightcorner_short") + xdotool key Left + exit 0 + ;; + "rightrightcorner_short") + xdotool key Right + exit 0 + ;; + "rightbottomcorner") + xdotool key Return + exit 0 + ;; + "leftbottomcorner") + xdotool key BackSpace + exit 0 + ;; + "powerbutton_one") + if echo "$WMCLASS" | grep -i "megapixels"; then + key "space" + else + sxmo_keyboard.sh toggle + fi + exit 0 + ;; + "powerbutton_two") + sxmo_blinkled.sh blue && $TERMCMD -e "$SHELL" + exit 0 + ;; + "powerbutton_three") + sxmo_blinkled.sh blue && $BROWSER + exit 0 + ;; + "volup_one") + sxmo_appmenu.sh + exit 0 + ;; + "volup_two") + sxmo_appmenu.sh sys + exit 0 + ;; + "volup_three") + lock_screen + exit 0 + ;; + "voldown_one") + key Super+space + exit 0 + ;; + "voldown_two") + key Super+Return + exit 0 + ;; + "voldown_three") + sxmo_blinkled.sh red && sxmo_killwindow.sh + exit 0 + ;; + "voldown_four") + sxmo_blinkled.sh red & sxmo_killwindow.sh close + exit 0 + ;; + "topleftcorner") + sxmo_appmenu.sh sys & + exit 0 + ;; + "toprightcorner") + sxmo_appmenu.sh scripts & + exit 0 + ;; + "bottomleftcorner") + lock_screen + exit 0 + ;; + "bottomrightcorner") + sxmo_rotate.sh & + exit 0 + ;; +esac diff --git a/scripts/core/sxmo_lisgdstart.sh b/scripts/core/sxmo_lisgdstart.sh index 0740c98..fab8a84 100755 --- a/scripts/core/sxmo_lisgdstart.sh +++ b/scripts/core/sxmo_lisgdstart.sh @@ -24,26 +24,32 @@ else -g '1,DLUR,BL,*,sxmo_inputhandler.sh bottomleftcorner' \ -g '1,ULDR,TL,*,sxmo_inputhandler.sh topleftcorner' \ -g '1,URDL,TR,*,sxmo_inputhandler.sh toprightcorner' \ - -g '1,LR,B,L,sxmo_inputhandler.sh enter' \ - -g '1,RL,B,L,sxmo_inputhandler.sh back' \ - -g '1,LR,L,*,sxmo_inputhandler.sh prevdesktop' \ - -g '1,RL,R,*,sxmo_inputhandler.sh nextdesktop' \ - -g '1,DU,L,*,P,sxmo_inputhandler.sh volup' \ - -g '1,UD,L,*,P,sxmo_inputhandler.sh voldown' \ - -g '1,LR,T,*,P,sxmo_inputhandler.sh brightnessup' \ - -g '1,RL,T,*,P,sxmo_inputhandler.sh brightnessdown' \ - -g "1,DU,B,*,sxmo_inputhandler.sh showkeyboard" \ - -g "1,UD,B,*,sxmo_inputhandler.sh hidekeyboard" \ - -g "1,UD,T,*,sxmo_inputhandler.sh showmenu" \ - -g "1,DU,T,*,sxmo_inputhandler.sh hidemenu" \ - -g "2,UD,T,*,sxmo_inputhandler.sh showsysmenu" \ - -g "2,UD,B,*,sxmo_inputhandler.sh closewindow" \ - -g "3,UD,B,*,sxmo_inputhandler.sh killwindow" \ - -g '2,RL,*,*,sxmo_inputhandler.sh moveprevdesktop' \ - -g '2,LR,*,*,sxmo_inputhandler.sh movenextdesktop' \ - -g '1,DU,R,*,P,sxmo_inputhandler.sh scrollup_short' \ - -g '1,UD,R,*,P,sxmo_inputhandler.sh scrolldown_short' \ - -g '1,LR,R,S,sxmo_inputhandler.sh scrollright_short' \ - -g '1,RL,L,S,sxmo_inputhandler.sh scrollleft_short' \ + -g '1,LR,B,L,sxmo_inputhandler.sh rightbottomcorner' \ + -g '1,RL,B,L,sxmo_inputhandler.sh leftbottomcorner' \ + -g '1,LR,L,*,sxmo_inputhandler.sh rightleftcorner' \ + -g '1,RL,R,*,sxmo_inputhandler.sh leftrightcorner' \ + -g '1,DU,L,*,P,sxmo_inputhandler.sh upleftcorner' \ + -g '1,UD,L,*,P,sxmo_inputhandler.sh downleftcorner' \ + -g '1,LR,T,*,P,sxmo_inputhandler.sh righttopcorner' \ + -g '1,RL,T,*,P,sxmo_inputhandler.sh lefttopcorner' \ + -g "1,DU,B,*,sxmo_inputhandler.sh upbottomcorner" \ + -g "1,UD,B,*,sxmo_inputhandler.sh downbottomcorner" \ + -g "1,UD,T,*,sxmo_inputhandler.sh downtopcorner" \ + -g "1,DU,T,*,sxmo_inputhandler.sh uptopcorner" \ + -g "2,UD,T,*,sxmo_inputhandler.sh twodowntopcorner" \ + -g "2,UD,B,*,sxmo_inputhandler.sh twodownbottomcorner" \ + -g "r,UD,B,*,sxmo_inputhandler.sh threedownbottomcorner" \ + -g '1,DU,R,*,P,sxmo_inputhandler.sh uprightcorner' \ + -g '1,UD,R,*,P,sxmo_inputhandler.sh downrightcorner' \ + -g '1,LR,R,S,sxmo_inputhandler.sh rightrightcorner_short' \ + -g '1,RL,L,S,sxmo_inputhandler.sh leftrightcorner_short' \ + -g '1,RL,*,*,sxmo_inputhandler.sh left' \ + -g '1,LR,*,*,sxmo_inputhandler.sh right' \ + -g '1,DU,*,*,sxmo_inputhandler.sh up' \ + -g '1,UD,*,*,sxmo_inputhandler.sh down' \ + -g '2,RL,*,*,sxmo_inputhandler.sh twoleft' \ + -g '2,LR,*,*,sxmo_inputhandler.sh tworight' \ + -g '2,DU,*,*,sxmo_inputhandler.sh twoup' \ + -g '2,UD,*,*,sxmo_inputhandler.sh twodown' \ >"$CACHEDIR/lisgd.log" 2>&1 & fi