~mil/sxmo-devel

sxmo-utils: complete revision of gestures (with new lisgd), edge-based detection v1 UNKNOWN

Maarten van Gompel: 1
 complete revision of gestures (with new lisgd), edge-based detection

 6 files changed, 192 insertions(+), 21 deletions(-)
It looks very interesting. I just need to find few days to play with
it and I'll comment on the subject.
Export patchset (mbox)
How do I use this?

Copy & paste the following snippet into your terminal to import this patchset into git:

curl -s https://lists.sr.ht/~mil/sxmo-devel/patches/11924/mbox | git am -3
Learn more about email & git

[PATCH sxmo-utils] complete revision of gestures (with new lisgd), edge-based detection Export this patch

This is a big patch that revises the way gestures work in sxmo. It
builds on the new lisgd (see separate patch) that implements edges and
distances as extra features.

This patch defines the new gestures, which is mediated through a new
sxmo_gesturehandlers.sh (formerly sxmo)_lisgdonefingercheck.sh). The key
is that all gestures all edge/corner sensitive now, they either
start/end or go parallel to an edge.

There only two gestures defined that do not stick to edges (the 2-finger
swipes to move a window to another workspace). This means that lisgd
interferes less with normal operation, as any gestures in the normal
plane are not handled. This makes it so that swiping right/left in the
browser, image viewer etc no longer conflicts with switching workspaces
(as long as you don't hit the edges).

I drew up a schema of the new behaviour that this patch introduces:
https://download.anaproy.nl/sxmo_gestures.png
Things like rotating, locking, killing windows, showing/hiding the menu,
showing/hiding the keyboard can now all be done without using the
menu, the hardware buttons, or the keyboard, adding extra flexibility.

There is also default cursor/scrolling behaviour that helps navigating in
applications that are otherwise gesture-unaware. These gestures simply output
arrow keys.

The gesture handler allows for context-sensitive applications-specific
overrides to certain gestures, as well as allowing for a central place
where the actions are defined independently of gestures. A new hook is
also available so users can override handling of gestures to add custom
ones easily.


---
 programs/sxmo_screenlock.c               |   2 +-
 scripts/core/sxmo_gesturehandler.sh      | 125 +++++++++++++++++++++++
 scripts/core/sxmo_hotcorner.sh           |  25 +++++
 scripts/core/sxmo_killwindow.sh          |   2 +
 scripts/core/sxmo_lisgdonefingercheck.sh |   8 --
 scripts/core/sxmo_lisgdstart.sh          |  51 ++++++---
 6 files changed, 192 insertions(+), 21 deletions(-)
 create mode 100755 scripts/core/sxmo_gesturehandler.sh
 create mode 100755 scripts/core/sxmo_hotcorner.sh
 create mode 100755 scripts/core/sxmo_killwindow.sh
 delete mode 100755 scripts/core/sxmo_lisgdonefingercheck.sh

diff --git a/programs/sxmo_screenlock.c b/programs/sxmo_screenlock.c
index b5e8737..e4ad89e 100644
--- a/programs/sxmo_screenlock.c
+++ b/programs/sxmo_screenlock.c
@@ -418,7 +418,7 @@ writefile(char *filepath, char *str)
}

void usage() {
	fprintf(stderr, "Usage: sxmo_screenlock [--screen-off] [--suspend]\n");
	fprintf(stderr, "Usage: sxmo_screenlock [--screen-off] [--suspend] [--wake-interval n]\n");
}


diff --git a/scripts/core/sxmo_gesturehandler.sh b/scripts/core/sxmo_gesturehandler.sh
new file mode 100755
index 0000000..93f4583
--- /dev/null
+++ b/scripts/core/sxmo_gesturehandler.sh
@@ -0,0 +1,125 @@
#!/usr/bin/env sh
ACTION="$1"

XPROPOUT="$(xprop -id "$(xdotool getactivewindow)")"
WMCLASS="$(echo "$XPROPOUT" | grep WM_CLASS | cut -d ' ' -f3- | cut -d ' ' -f1 | tr -d '\",')"

HANDLE=1
if [ -x "$XDG_CONFIG_HOME"/sxmo/hooks/gesture ]; then
	#hook script must exit with a zero exit code ONLY if it has handled the gesture!
	"$XDG_CONFIG_HOME"/sxmo/hooks/gesture "$WMCLASS" "$@"
	HANDLE=$?
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:
			WMNAME=$(echo "$XPROPOUT" | grep -E "^WM_NAME" | cut -d ' ' -f3-)
			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
				fi
			fi
			;;
	esac
fi

if [ "$HANDLE" -ne 0 ]; then
	#standard handling
	case "$ACTION" in
		"prevdesktop")
			xdotool key --clearmodifiers Alt+Shift+e
			;;
		"nextdesktop")
			xdotool key --clearmodifiers Alt+Shift+r
			;;
		"moveprevdesktop")
			xdotool key --clearmodifiers Alt+e
			;;
		"movenextdesktop")
			xdotool key --clearmodifiers Alt+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")
			pidof "$KEYBOARD" || "$KEYBOARD" &
			;;
		"hidekeyboard")
			pkill -9 "$KEYBOARD"
			;;
		"showmenu")
			sxmo_appmenu.sh &
			;;
		"showsysmenu")
			sxmo_appmenu.sh sys &
			;;
		"hidemenu")
			pkill -9 dmenu
			;;
		"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
			;;
		*)
			#fallback, just execute the command
			"$@"
			;;
	esac
fi
diff --git a/scripts/core/sxmo_hotcorner.sh b/scripts/core/sxmo_hotcorner.sh
new file mode 100755
index 0000000..2a9a933
--- /dev/null
+++ b/scripts/core/sxmo_hotcorner.sh
@@ -0,0 +1,25 @@
#!/usr/bin/env sh
if [ -z "$1" ]; then
	exit 1
else
	CORNER="$1"
fi

if [ -x "$XDG_CONFIG_HOME/sxmo/hooks/hotcorner_$CORNER" ]; then
	"$XDG_CONFIG_HOME/sxmo/hooks/hotcorner_$CORNER"
	exit $?
fi

case "$CORNER" in
	"topleft")
		sxmo_appmenu.sh sys &
		;;
	"topright")
		;;
	"bottomleft")
		sxmo_lock.sh &
		;;
	"bottomright")
		sxmo_rotate.sh &
		;;
esac
diff --git a/scripts/core/sxmo_killwindow.sh b/scripts/core/sxmo_killwindow.sh
new file mode 100755
index 0000000..09a8be2
--- /dev/null
+++ b/scripts/core/sxmo_killwindow.sh
@@ -0,0 +1,2 @@
#!/usr/bin/env sh
xdotool windowkill $(xdotool getactivewindow)
diff --git a/scripts/core/sxmo_lisgdonefingercheck.sh b/scripts/core/sxmo_lisgdonefingercheck.sh
deleted file mode 100755
index d970aa3..0000000
--- a/scripts/core/sxmo_lisgdonefingercheck.sh
@@ -1,8 +0,0 @@
#!/usr/bin/env sh
ACTIVEWIN="$(xdotool getactivewindow)"
WMCLASS="$(xprop -id "$ACTIVEWIN" | grep WM_CLASS | cut -d ' ' -f3-)"

# E.g. just a check to ignore 1-finger gestures in foxtrotgps
if echo "$WMCLASS" | grep -vi foxtrot; then
  "$@"
fi
diff --git a/scripts/core/sxmo_lisgdstart.sh b/scripts/core/sxmo_lisgdstart.sh
index cff9e38..a4e1df1 100755
--- a/scripts/core/sxmo_lisgdstart.sh
+++ b/scripts/core/sxmo_lisgdstart.sh
@@ -1,15 +1,42 @@
#!/usr/bin/env sh
pkill -9 lisgd

lisgd "$@" \
	-g '1,LR,sxmo_lisgdonefingercheck.sh xdotool key --clearmodifiers Alt+Shift+e' \
	-g '1,RL,sxmo_lisgdonefingercheck.sh xdotool key --clearmodifiers Alt+Shift+r' \
	-g '1,DLUR,sxmo_lisgdonefingercheck.sh sxmo_vol.sh up' \
	-g '1,URDL,sxmo_lisgdonefingercheck.sh sxmo_vol.sh down' \
	-g '1,DRUL,sxmo_lisgdonefingercheck.sh sxmo_brightness.sh up' \
	-g '1,ULDR,sxmo_lisgdonefingercheck.sh sxmo_brightness.sh down' \
	-g '2,LR,xdotool key --clearmodifiers Alt+e' \
	-g '2,RL,xdotool key --clearmodifiers Alt+r' \
	-g "2,DU,pidof $KEYBOARD || $KEYBOARD &" \
	-g "2,UD,pkill -9 $KEYBOARD" \
	&
if [ -x "$XDG_CONFIG_HOME"/sxmo/hooks/lisgdstart ]; then
	"$XDG_CONFIG_HOME"/sxmo/hooks/lisgdstart &
else
    #-g format:
    #   fingers,swipe,edge,distance,command
    #order matters, only the first match gets executed
    lisgd "$@" -t 200 \
        -g '1,DRUL,BR,*,sxmo_hotcorner.sh bottomright' \
        -g '1,DLUR,BL,*,sxmo_hotcorner.sh bottomleft' \
        -g '1,ULDR,TL,*,sxmo_hotcorner.sh topleft' \
        -g '1,DRUL,TR,*,sxmo_hotcorner.sh topright' \
        -g '1,LR,B,L,sxmo_gesturehandler.sh enter' \
        -g '1,RL,B,L,sxmo_gesturehandler.sh back' \
        -g '1,LR,L,*,sxmo_gesturehandler.sh prevdesktop' \
        -g '1,RL,R,*,sxmo_gesturehandler.sh nextdesktop' \
        -g '1,DU,L,L,sxmo_gesturehandler.sh unmute' \
        -g '1,UD,L,L,sxmo_gesturehandler.sh mute' \
        -g '1,DU,L,*,sxmo_gesturehandler.sh volup' \
        -g '1,UD,L,*,sxmo_gesturehandler.sh voldown' \
        -g '1,LR,T,*,sxmo_gesturehandler.sh brightnessup' \
        -g '1,RL,T,*,sxmo_gesturehandler.sh brightnessdown' \
        -g "1,DU,B,*,sxmo_gesturehandler.sh showkeyboard" \
        -g "1,UD,B,*,sxmo_gesturehandler.sh hidekeyboard" \
        -g "1,UD,T,*,sxmo_gesturehandler.sh showmenu" \
        -g "1,DU,T,*,sxmo_gesturehandler.sh hidemenu" \
        -g "2,UD,T,*,sxmo_gesturehandler.sh showsysmenu" \
        -g "2,UD,B,*,sxmo_gesturehandler.sh killwindow" \
        -g '2,LR,*,*,sxmo_gesturehandler.sh moveprevdesktop' \
        -g '2,RL,*,*,sxmo_gesturehandler.sh movenextdesktop' \
        -g '1,DU,R,L,sxmo_gesturehandler.sh scrollup_long' \
        -g '1,UD,R,L,sxmo_gesturehandler.sh scrolldown_long' \
        -g '1,DU,R,M,sxmo_gesturehandler.sh scrollup_med' \
        -g '1,UD,R,M,sxmo_gesturehandler.sh scrolldown_med' \
        -g '1,DU,R,S,sxmo_gesturehandler.sh scrollup_short' \
        -g '1,UD,R,S,sxmo_gesturehandler.sh scrolldown_short' \
        -g '1,LR,R,S,sxmo_gesturehandler.sh scrollright_short' \
        -g '1,RL,L,S,sxmo_gesturehandler.sh scrollleft_short' \
        &
fi
--
2.28.0
This has now been applied and forms the new gesture system. Make sure to
update both lisgd and sxmo-utils.

--

Maarten van Gompel (proycon)
https://proycon.anaproy.nl