bulletmark / libinput-gestures

Actions gestures on your touchpad using libinput
3.93k stars 241 forks source link

Feature request: Allow a gesture to trigger multiple _internal commands (diagonal workspace navigation) #224

Closed gschaffner closed 5 years ago

gschaffner commented 5 years ago

Description

It seems that the way commands are executed doesn't allow for full shell syntax. For example, a configuration with gesture swipe right_up 3 notify-send "hi" && notify-send "hello" will cause an error when the gesture is triggered:

Invalid number of options.
Command '['notify-send', 'hi', '&&', 'notify-send', 'hello']' returned non-zero exit status 1.

However, this is not unfixable. Examples of this sort can be made to behave as intended with bash -c "$command". For example, configuration gesture swipe right_up 3 bash -c "notify-send "hi" && notify-send "hello"" will cause the intended behavior of two separate notifications being sent.

However, this bash -c "$command" method doesn't allow one to trigger multiple _internal commands with a single gesture. For example, a configuration like gesture swipe right_up 3 _internal --col=2 ws_down && _internal --row=3 ws_up would be a useful extension to the usual 4 orthogonal gestures. However, it causes an error when launching libinput-gestures:

usage: _internal [-h] [-w] [--row ROW] [--col COL] {ws_up,ws_down}
_internal: error: unrecognized arguments: && _internal ws_down

If you have Super_L+Control_L+{Up,Down,Left,Right} bound to switch workspaces, a potential workaround for this example is gesture swipe right_up 3 xte 'keydown Super_L' 'keydown Control_L' 'key Down' 'key Left' 'keyup Super_L' 'keyup Control_L'. (xte is in package xautomation.) Another workaround would be to call an external script that works with wmctrl -d and -s.

Would you be open to a small PR that adds new _internal commands for diagonal workspace navigation? And possibly also ws_right and ws_left commands, allowing for more easily-read configs?

Version Info

$ libinput-gestures -l
libinput-gestures: session KDE+x11 on Linux-4.19.69-1-MANJARO-x86_64-with-arch-Manjaro-Linux, python 3.7.4, libinput 1.14.1
/usr/bin/libinput-gestures: hash 34ab6c1e45b5673bf2b143a6321c81c4
Gestures configured in ~/.config/libinput-gestures.conf:
swipe up         3 _internal --col=2 ws_up
swipe down       3 _internal --col=2 ws_down
swipe left       3 _internal --row=3 ws_up
swipe right      3 _internal --row=3 ws_down
swipe up         4 xdotool key XF86AudioPlay
swipe down       4 xdotool key XF86AudioPlay
swipe left       4 xdotool key XF86AudioNext
swipe right      4 xdotool key XF86AudioPrev
swipe_threshold 400
timeout 1.0
libinput-gestures: device /dev/input/event11: SYNA7DB5:00 06CB:7DB7 Touchpad
bulletmark commented 5 years ago

The second last paragraph in the configuration section discusses this and shows you the easy way to do what you want, i.e. put everything you want to do in a shell script (with appropriate shebang).

gschaffner commented 5 years ago

Thanks for the quick response!

I also thought an an external script would be one good way to accomplish this behavior. Since it's a closely related task to _internal ws_up and ws_down though, do you think that a PR to add this feature directly to libinput-gestures _internal is reasonable?

bulletmark commented 5 years ago

The _internal command exists really just to provide a default for switching workspaces in a DE and Wayland/Xorg independent manner, i.e. it works for GNOME, KDE out of the box.

I see that the shell script issue is not the real point of your problem here. You are suggesting to augment the _internal command with some more sub-commands, e.g. ws_right_up etc, in particular to use with the "extended swipe" gestures. E.g in a 2x2 desktop you could swipe right_down to go immediately from top-left quadrant to bottom-right. I can see the merit in that although it has no use in GNOME which I use and probably only is useful in KDE where you could just as well write your own script.

I will think about this as a suggested enhancement.

bulletmark commented 5 years ago

I've add this feature with commit bc69ac9a02d11d9996b939660237bb3ec0525608. See the updated libinput-gestures.conf file for how to configure it.