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 <contact@stacyharper.net>
Signed-off-by: Maarten van Gompel <proycon@anaproy.nl>
This commit is contained in:
Stacy Harper 2021-06-12 13:33:35 +02:00 committed by Maarten van Gompel
parent a3d13c6c7d
commit c427a0eb7b
2 changed files with 242 additions and 188 deletions

View file

@ -28,6 +28,21 @@ lock_screen() {
fi 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 if [ "$(sxmo_screenlock.sh getCurState)" != "unlock" ]; then
case "$ACTION" in case "$ACTION" in
"volup_three") "volup_three")
@ -51,176 +66,209 @@ XPROPOUT="$(xprop -id "$(xdotool getactivewindow)")"
WMCLASS="$(echo "$XPROPOUT" | grep WM_CLASS | cut -d ' ' -f3-)" WMCLASS="$(echo "$XPROPOUT" | grep WM_CLASS | cut -d ' ' -f3-)"
WMNAME=$(echo "$XPROPOUT" | grep -E "^WM_NAME" | cut -d ' ' -f3-) WMNAME=$(echo "$XPROPOUT" | grep -E "^WM_NAME" | cut -d ' ' -f3-)
HANDLE=1
if [ -x "$XDG_CONFIG_HOME"/sxmo/hooks/inputhandler ]; then 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! #hook script must exit with a zero exit code ONLY if it has handled the gesture!
"$XDG_CONFIG_HOME"/sxmo/hooks/inputhandler "$WMCLASS" "$WMNAME" "$@" "$XDG_CONFIG_HOME"/sxmo/hooks/inputhandler "$WMCLASS" "$WMNAME" "$@" && exit
HANDLE=$?
fi fi
if [ "$HANDLE" -ne 0 ]; then #special context-sensitive handling
#special context-sensitive handling case "$WMCLASS" in
case "$WMCLASS" in *"st-256color"*)
"foxtrotgps") # First we try to handle the app running inside st:
# E.g. just a check to ignore 1-finger gestures in foxtrotgps case "$WMNAME" in
if [ "$ACTION" != "killwindow" ]; then *"tuir"*)
HANDLE=0 if [ "$ACTION" = "rightbottomcorner" ]; then
type o
exit 0
elif [ "$ACTION" = "leftbottomcorner" ]; then
type s
exit 0
fi fi
;; ;;
"st-256color") *"less"*)
# First we try to handle the app running inside st: case "$ACTION" in
if echo "$WMNAME" | grep -i -w tuir; then "leftbottomcorner")
if [ "$ACTION" = "enter" ]; then type q
xdotool key o exit 0
HANDLE=0 ;;
elif [ "$ACTION" = "back" ]; then "leftrightcorner_short")
xdotool key s type q
HANDLE=0 exit 0
fi ;;
elif echo "$WMNAME" | grep -i -E -w "(less|mless)"; then "twodown")
if [ "$ACTION" = "back" ] || [ "$ACTION" = "scrollleft_short" ]; then type u
xdotool key q exit 0
HANDLE=0 ;;
fi "twoup")
fi type d
exit 0
;;
"left")
typeenter ":n"
exit 0
;;
"right")
typeenter ":p"
exit 0
;; ;;
esac esac
fi ;;
esac
esac
if [ "$HANDLE" -ne 0 ]; then #standard handling
#standard handling case "$ACTION" in
case "$ACTION" in "rightleftcorner")
"prevdesktop") key Super+Shift+e
xdotool key --clearmodifiers Super+Shift+e exit 0
;; ;;
"nextdesktop") "leftrightcorner")
xdotool key --clearmodifiers Super+Shift+r key Super+Shift+r
exit 0
;; ;;
"moveprevdesktop") "twoleft") # Move window previous
xdotool key --clearmodifiers Super+e key Super+e
exit 0
;; ;;
"movenextdesktop") "tworight") # Move window next
xdotool key --clearmodifiers Super+r key Super+r
exit 0
;; ;;
"unmute") "unmute")
sxmo_vol.sh unmute & sxmo_vol.sh unmute &
exit 0
;; ;;
"mute") "mute")
sxmo_vol.sh mute & sxmo_vol.sh mute &
exit 0
;; ;;
"brightnessup") "righttopcorner")
sxmo_brightness.sh up & sxmo_brightness.sh up &
exit 0
;; ;;
"brightnessdown") "lefttopcorner")
sxmo_brightness.sh down & sxmo_brightness.sh down &
exit 0
;; ;;
"volup") "upleftcorner")
sxmo_vol.sh up & sxmo_vol.sh up &
exit 0
;; ;;
"voldown") "downleftcorner")
sxmo_vol.sh down & sxmo_vol.sh down &
exit 0
;; ;;
"showkeyboard") "upbottomcorner")
sxmo_keyboard.sh open sxmo_keyboard.sh open
exit 0
;; ;;
"hidekeyboard") "downbottomcorner")
sxmo_keyboard.sh close sxmo_keyboard.sh close
exit 0
;; ;;
"showmenu") "downtopcorner")
pidof dmenu || setsid -f sxmo_appmenu.sh & pidof dmenu || setsid -f sxmo_appmenu.sh &
exit 0
;; ;;
"showsysmenu") "twodowntopcorner")
pidof dmenu || setsid -f sxmo_appmenu.sh sys & pidof dmenu || setsid -f sxmo_appmenu.sh sys &
exit 0
;; ;;
"hidemenu") "uptopcorner")
pkill -9 dmenu pkill -9 dmenu
dunstctl close-all dunstctl close-all
exit 0
;; ;;
"closewindow") "twodownbottomcorner")
sxmo_killwindow.sh close sxmo_killwindow.sh close
exit 0
;; ;;
"killwindow") "threedownbottomcorner")
sxmo_killwindow.sh sxmo_killwindow.sh
exit 0
;; ;;
"scrollup_long") "uprightcorner")
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 xdotool key Up
exit 0
;; ;;
"scrolldown_short") "downrightcorner")
xdotool key Down xdotool key Down
exit 0
;; ;;
"scrollleft_short") "leftrightcorner_short")
xdotool key Left xdotool key Left
exit 0
;; ;;
"scrollright_short") "rightrightcorner_short")
xdotool key Right xdotool key Right
exit 0
;; ;;
"enter") "rightbottomcorner")
xdotool key Return xdotool key Return
exit 0
;; ;;
"back") "leftbottomcorner")
xdotool key BackSpace xdotool key BackSpace
exit 0
;; ;;
"powerbutton_one") "powerbutton_one")
if echo "$WMCLASS" | grep -i "megapixels"; then if echo "$WMCLASS" | grep -i "megapixels"; then
xdotool key --clearmodifiers "space" key "space"
else else
sxmo_keyboard.sh toggle sxmo_keyboard.sh toggle
fi fi
exit 0
;; ;;
"powerbutton_two") "powerbutton_two")
sxmo_blinkled.sh blue && $TERMCMD -e "$SHELL" sxmo_blinkled.sh blue && $TERMCMD -e "$SHELL"
exit 0
;; ;;
"powerbutton_three") "powerbutton_three")
sxmo_blinkled.sh blue && $BROWSER sxmo_blinkled.sh blue && $BROWSER
exit 0
;; ;;
"volup_one") "volup_one")
sxmo_appmenu.sh sxmo_appmenu.sh
exit 0
;; ;;
"volup_two") "volup_two")
sxmo_appmenu.sh sys sxmo_appmenu.sh sys
exit 0
;; ;;
"volup_three") "volup_three")
lock_screen lock_screen
exit 0
;; ;;
"voldown_one") "voldown_one")
xdotool key --clearmodifiers Super+space key Super+space
exit 0
;; ;;
"voldown_two") "voldown_two")
xdotool key --clearmodifiers Super+Return key Super+Return
exit 0
;; ;;
"voldown_three") "voldown_three")
sxmo_blinkled.sh red && sxmo_killwindow.sh sxmo_blinkled.sh red && sxmo_killwindow.sh
exit 0
;; ;;
"voldown_four") "voldown_four")
sxmo_blinkled.sh red & sxmo_killwindow.sh close sxmo_blinkled.sh red & sxmo_killwindow.sh close
exit 0
;; ;;
"topleftcorner") "topleftcorner")
sxmo_appmenu.sh sys & sxmo_appmenu.sh sys &
exit 0
;; ;;
"toprightcorner") "toprightcorner")
sxmo_appmenu.sh scripts & sxmo_appmenu.sh scripts &
exit 0
;; ;;
"bottomleftcorner") "bottomleftcorner")
lock_screen lock_screen
exit 0
;; ;;
"bottomrightcorner") "bottomrightcorner")
sxmo_rotate.sh & sxmo_rotate.sh &
exit 0
;; ;;
*) esac
#fallback, just execute the command
"$@"
;;
esac
fi

View file

@ -24,26 +24,32 @@ else
-g '1,DLUR,BL,*,sxmo_inputhandler.sh bottomleftcorner' \ -g '1,DLUR,BL,*,sxmo_inputhandler.sh bottomleftcorner' \
-g '1,ULDR,TL,*,sxmo_inputhandler.sh topleftcorner' \ -g '1,ULDR,TL,*,sxmo_inputhandler.sh topleftcorner' \
-g '1,URDL,TR,*,sxmo_inputhandler.sh toprightcorner' \ -g '1,URDL,TR,*,sxmo_inputhandler.sh toprightcorner' \
-g '1,LR,B,L,sxmo_inputhandler.sh enter' \ -g '1,LR,B,L,sxmo_inputhandler.sh rightbottomcorner' \
-g '1,RL,B,L,sxmo_inputhandler.sh back' \ -g '1,RL,B,L,sxmo_inputhandler.sh leftbottomcorner' \
-g '1,LR,L,*,sxmo_inputhandler.sh prevdesktop' \ -g '1,LR,L,*,sxmo_inputhandler.sh rightleftcorner' \
-g '1,RL,R,*,sxmo_inputhandler.sh nextdesktop' \ -g '1,RL,R,*,sxmo_inputhandler.sh leftrightcorner' \
-g '1,DU,L,*,P,sxmo_inputhandler.sh volup' \ -g '1,DU,L,*,P,sxmo_inputhandler.sh upleftcorner' \
-g '1,UD,L,*,P,sxmo_inputhandler.sh voldown' \ -g '1,UD,L,*,P,sxmo_inputhandler.sh downleftcorner' \
-g '1,LR,T,*,P,sxmo_inputhandler.sh brightnessup' \ -g '1,LR,T,*,P,sxmo_inputhandler.sh righttopcorner' \
-g '1,RL,T,*,P,sxmo_inputhandler.sh brightnessdown' \ -g '1,RL,T,*,P,sxmo_inputhandler.sh lefttopcorner' \
-g "1,DU,B,*,sxmo_inputhandler.sh showkeyboard" \ -g "1,DU,B,*,sxmo_inputhandler.sh upbottomcorner" \
-g "1,UD,B,*,sxmo_inputhandler.sh hidekeyboard" \ -g "1,UD,B,*,sxmo_inputhandler.sh downbottomcorner" \
-g "1,UD,T,*,sxmo_inputhandler.sh showmenu" \ -g "1,UD,T,*,sxmo_inputhandler.sh downtopcorner" \
-g "1,DU,T,*,sxmo_inputhandler.sh hidemenu" \ -g "1,DU,T,*,sxmo_inputhandler.sh uptopcorner" \
-g "2,UD,T,*,sxmo_inputhandler.sh showsysmenu" \ -g "2,UD,T,*,sxmo_inputhandler.sh twodowntopcorner" \
-g "2,UD,B,*,sxmo_inputhandler.sh closewindow" \ -g "2,UD,B,*,sxmo_inputhandler.sh twodownbottomcorner" \
-g "3,UD,B,*,sxmo_inputhandler.sh killwindow" \ -g "r,UD,B,*,sxmo_inputhandler.sh threedownbottomcorner" \
-g '2,RL,*,*,sxmo_inputhandler.sh moveprevdesktop' \ -g '1,DU,R,*,P,sxmo_inputhandler.sh uprightcorner' \
-g '2,LR,*,*,sxmo_inputhandler.sh movenextdesktop' \ -g '1,UD,R,*,P,sxmo_inputhandler.sh downrightcorner' \
-g '1,DU,R,*,P,sxmo_inputhandler.sh scrollup_short' \ -g '1,LR,R,S,sxmo_inputhandler.sh rightrightcorner_short' \
-g '1,UD,R,*,P,sxmo_inputhandler.sh scrolldown_short' \ -g '1,RL,L,S,sxmo_inputhandler.sh leftrightcorner_short' \
-g '1,LR,R,S,sxmo_inputhandler.sh scrollright_short' \ -g '1,RL,*,*,sxmo_inputhandler.sh left' \
-g '1,RL,L,S,sxmo_inputhandler.sh scrollleft_short' \ -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 & >"$CACHEDIR/lisgd.log" 2>&1 &
fi fi