Florent de Lamotte: 1 Tentative to modularize inputhandler 16 files changed, 522 insertions(+), 235 deletions(-)
Hi Aren, Thanks for taking the time to review my patch, your comments are relevant and will help me provide a better solution (at least for my use ;)). I will not reply to everything now and will take some time to take everyting into account (if you find there is some interest in my proposal).
Hi Stacy and Aren, Made some progress yesterday (bored at work ;)) and think I need some guidance. First, the sourcing of scripts has been a great success, on performance side, there is a 2-3ms improvement, but that is on the readability that the gain is important, exit structure is clearer ;). Now I am faster than the original script on the op6 ... (I'd need to check profundly but it is not bad) Where I need you is for two points : - loop structure - directory structure/file naming For the loop structure, I've tried Stacy's proposal and I get a 5-6ms penalty (on the op6). The structure is clearer and edge cases are better treated (no files in the dir for instance). => is a 6ms gain worth going in a less elegant solution ? As for directories, I've tested different solutions : - current solution : a root directory (inputhandler.d) and a subdir for applications that run in the terminal and are matched with wmname - I've tried using two subdirs (wmclass and wmname) and I find it clearer (and I can put base scripts to be sourced at the root, for common actions) There does not seem to be penalties, so I ask you what you think (I'll personally go for the second choice). I've also test changing the names : 1- current scheme : scripts have a .actions extension 2- tried using a "sxmo_actions_" prefix so I don't have to remove extension 3- removed both extension and prefix The second scheme induced a time penalty (I think a match with ##*/sxmo_actions_ was costly so could probably be enhanced to match 1) There is no noticeable gain from the third scheme. I prefer the third scheme but will let you choose ;) Have a nice weekend (don't know if i'll make much process because the sun arrived), -- Florent
Copy & paste the following snippet into your terminal to import this patchset into git:
curl -s https://lists.sr.ht/~mil/sxmo-devel/patches/51634/mbox | git am -3Learn more about email & git
The idea is to split the big switch into sxmo_hook_inputhandler.sh into a script for each possible action. These script are stored in local and global inputhandler.d directories.
What do we gain from this? Is the idea that users can add actions for apps and have to deal less with conflicts when upgrading?Well, I did this mainly for myself because my own sxmo_hook_inputhandler.sh was growing out of control, and yes it is clearly a pain when upgrading. Now I only have to copy the hook and add my loop ;)On the topic of upgrading, will we want to keep inputhandler.d files up to date with sxmo_migrate.sh?Not sure this is necessary, an upgrade would break things only if there is a change in the parameters, no ?I don't think this is necessarily a bad thing to do, but I'm not convinced it's worth refactoring this much of the inputhandler. Would something simpler, such as keeping the case statement in the root inputhandler and having it hardcode hooks for different apps be enough? Or if we added the ability to have a user hook fall back to the default system one?
Some benchmarks have been done with hyperfine on op6 and moto-g3. On op6 the scripts runs in 50ms, on moto-g3, there is a small penalty (from 105ms to 110ms).
This concerns me, we really want the inputhandler to execute quickly because any latency it adds will be visible to users. I've been looking at what causes this latency and the inputhandler is the next thing on my list.I do agree and proycon pushed me in that way (that is why I did the test with an older devices). But I was not clear in my initial statement, on op6 there is no penalty, on moto-g3 original script takes 105ms and mine 110ms, so there is a 5ms penalty here ... seems better, no ?If we're going to be refactoring the inputhandler, I would at least like to make sure it won't make optimizing it harder, and that we won't need to refactor again to get better performance.
Some optimizations can be done, for instance the loop could be exited as soon as the first match has been found. Currently I let it continue, it enables some sort of "inheritance" ... --- .../default_hooks/sxmo_hook_inputhandler.sh | 263 ++---------------- configs/inputhandler.d/acme.actions | 22 ++ configs/inputhandler.d/foot.actions | 59 ++++ .../inputhandler.d/interminal/amfora.actions | 33 +++ configs/inputhandler.d/interminal/epr.actions | 21 ++ configs/inputhandler.d/interminal/epy.actions | 21 ++ .../inputhandler.d/interminal/less.actions | 25 ++ configs/inputhandler.d/interminal/lf.actions | 18 ++ configs/inputhandler.d/interminal/nnn.actions | 18 ++ configs/inputhandler.d/interminal/sms.actions | 16 ++ .../inputhandler.d/interminal/tuir.actions | 14 + .../inputhandler.d/interminal/weechat.actions | 17 ++ configs/inputhandler.d/mpv.actions | 28 ++ configs/inputhandler.d/st.actions | 84 ++++++ configs/inputhandler.d/terminal.actions | 59 ++++ configs/inputhandler.d/vte.actions | 59 ++++ 16 files changed, 522 insertions(+), 235 deletions(-) create mode 100755 configs/inputhandler.d/acme.actions create mode 100755 configs/inputhandler.d/foot.actions create mode 100755 configs/inputhandler.d/interminal/amfora.actions create mode 100755 configs/inputhandler.d/interminal/epr.actions create mode 100755 configs/inputhandler.d/interminal/epy.actions create mode 100755 configs/inputhandler.d/interminal/less.actions create mode 100755 configs/inputhandler.d/interminal/lf.actions create mode 100755 configs/inputhandler.d/interminal/nnn.actions create mode 100755 configs/inputhandler.d/interminal/sms.actions create mode 100755 configs/inputhandler.d/interminal/tuir.actions create mode 100755 configs/inputhandler.d/interminal/weechat.actions create mode 100755 configs/inputhandler.d/mpv.actions create mode 100755 configs/inputhandler.d/st.actions create mode 100755 configs/inputhandler.d/terminal.actions create mode 100755 configs/inputhandler.d/vte.actions diff --git a/configs/default_hooks/sxmo_hook_inputhandler.sh b/configs/default_hooks/sxmo_hook_inputhandler.sh index b0bba6d..c0a5e00 100755 --- a/configs/default_hooks/sxmo_hook_inputhandler.sh +++ b/configs/default_hooks/sxmo_hook_inputhandler.sh @@ -15,10 +15,32 @@ stop_proximity_lock() { sxmo_jobs.sh stop proximity_lock } +run_actiondir () {
nit: typically we don't put a space after function names, so this would just be "run_action() {"
+ WMCLASS="$1" + WMNAME="$2" + ACTION="$3" + WMID="$4" # either WMCLASS or WMNAME + ADIR="$5" # directory where are actions scripts
nit: no need to save characters, action_dir is more readable
+ + for APATH in "$ADIR"/*.actions; do
Capital case variables are generally considered "global" in shell scripts (for what is worth). I do not recommend using "for" loop on shell scripts, specifically when they rely on file path expansions. I would prefer a find command piped to a read -r apath.
+ AFILE=${APATH##*/}
nit: same, use action_file nit: It looks like this is implementing basename, it would be more clear to use that. If we need better performance, it might make sense to add a function to sxmo_common.sh, since we use basename in lots of other places too.Well, it is in fact it is an implementation of basename, which I was using in my first poc see : https://git.sr.ht/~fdlamotte/sxmo-personalscripts/tree/eb3a4f53bbaddaaf0ade2ca44cdf94d3409eaa00/item/hooks/sxmo_hook_inputhandler.sh#L104 By removing the use of basename, echo and grep, I was able to lower the execution time from around 250ms to the 110ms where we are now (with my own actions, I have currently 25) ... Regards, -- Florent PS : I'm still not used to interact on sourcehut mailing lists. Please tell me if I don't use them correctly ;)perhaps use `action_name=$(basename -s "$action_path")`?
+ if [ -z "${WMID##*"${AFILE%.actions}"*}" ] ; then
This check is a bit complicated. if I'm reading it right, you first remove the .action from the filename, then test if that's in WMID by removing it from wmid. It would be good to at least document this.
+ $APATH "$WMCLASS" "$WMNAME" "$ACTION"
If you source the file instead of executing it we won't have to redefine this function, it might help a bit with performance, and actions won't need to redefine the variables in the scripts.
+ ret=$? + [ $ret -eq 0 ] && exit 0 + return 1
I think here you could write: if $APATH "$WMCLASS" "$WMNAME" "$ACTION"; then exit 0 else return 1 fi
+ fi + done +} + +export HOME_INPUTHANDLER_D="$XDG_CONFIG_HOME"/sxmo/inputhandler.d +export SXMO_INPUTHANDLER_D=/usr/share/sxmo/inputhandler.d
BUG: This needs to respect $XDG_DATA_DIRS, we have a helper for that in sxmo_common.sh
+ XPROPOUT="$(sxmo_wm.sh focusedwindow)" WMCLASS="$(printf %s "$XPROPOUT" | grep app: | cut -d" " -f2- | tr '[:upper:]' '[:lower:]')" WMNAME="$(printf %s "$XPROPOUT" | grep title: | cut -d" " -f2- | tr '[:upper:]' '[:lower:]')" + sxmo_debug "STATE: $(sxmo_state.sh get) ACTION: $ACTION WMCLASS: $WMCLASS WMNAME: $WMNAME" if ! sxmo_state.sh get | grep -q unlock; then @@ -75,241 +97,12 @@ if ! sxmo_state.sh get | grep -q unlock; then exit 0 fi -#special context-sensitive handling -case "$WMCLASS" in - *"mpv"*) - case "$ACTION" in - "oneright") - sxmo_type.sh -k Left - exit 0 - ;; - "oneleft") - sxmo_type.sh -k Right - exit 0 - ;; - "oneup") - sxmo_type.sh m - exit 0 - ;; - "onedown") - sxmo_type.sh p - exit 0 - ;; - esac - ;; - *"acme"*) - case "$ACTION" in - "volup_one") - xdotool click 3 - exit 0 - ;; - "voldown_one") - xdotool click 2 - exit 0 - ;; - esac - ;; - *"foot"*|*"st"*|*"vte"*|"terminal") # Terminals - case "$WMCLASS" in # Handle programs without touch support - *"st"*) - case "$WMNAME" in - *"weechat"*|*'gomuks'*) - case "$ACTION" in - *"onedown") - sxmo_type.sh -k Page_Up - exit 0 - ;; - *"oneup") - sxmo_type.sh -k Page_Down - exit 0 - ;; - esac - ;; - *"less"*|*"amfora"*) - case "$ACTION" in - *"onedown") - sxmo_type.sh u - exit 0 - ;; - *"oneup") - sxmo_type.sh d - exit 0 - ;; - esac - ;; - *'irssi'*) - case "$ACTION" in - "onedown") - sxmo_type.sh -M Alt p - exit 0 - ;; - "oneup") - sxmo_type.sh -M Alt n - exit 0 - ;; - esac - ;; - *'epy'*|*'epr'*) - case "$ACTION" in - "onedown") - sxmo_type.sh h - exit 0 - ;; - "oneup") - sxmo_type.sh l - exit 0 - ;; - esac - ;; - *'nnn'*|'lf') - case "$ACTION" in - "onedown") - sxmo_type.sh -k Down - exit 0 - ;; - "oneup") - sxmo_type.sh -k Up - exit 0 - ;; - esac - ;; - esac - ;; - esac - - case "$WMNAME" in # Handle programs - *"weechat"*) - case "$ACTION" in - *"oneleft") - sxmo_type.sh -M Alt -k a - exit 0 - ;; - *"oneright") - sxmo_type.sh -M Alt -k less - exit 0 - ;; - esac - ;; - *" sms") - case "$ACTION" in - *"upbottomedge") - number="$(printf %s "$WMNAME" | sed -e 's|^\"||' -e 's|\"$||' | cut -f1 -d' ')" - sxmo_terminal.sh sxmo_modemtext.sh conversationloop "$number" - exit 0 - ;; - esac - ;; - *"tuir"*) - if [ "$ACTION" = "rightbottomedge" ]; then - sxmo_type.sh o - exit 0 - elif [ "$ACTION" = "leftbottomedge" ]; then - sxmo_type.sh s - exit 0 - fi - ;; - *"less"*) - case "$ACTION" in - "leftbottomedge") - sxmo_type.sh q - exit 0 - ;; - "leftrightedge_short") - sxmo_type.sh q - exit 0 - ;; - *"oneleft") - sxmo_type.sh ":n" -k Return - exit 0 - ;; - *"oneright") - sxmo_type.sh ":p" -k Return - exit 0 - ;; - esac - ;; - *"amfora"*) - case "$ACTION" in - "downright") - sxmo_type.sh -k Tab - exit 0 - ;; - "upleft") - sxmo_type.sh -M Shift -k Tab - exit 0 - ;; - *"oneright") - sxmo_type.sh -k Return - exit 0 - ;; - "upright") - sxmo_type.sh -M Ctrl t - exit 0 - ;; - *"oneleft") - sxmo_type.sh b - exit 0 - ;; - "downleft") - sxmo_type.sh -M Ctrl w - exit 0 - ;; - esac - ;; - *"epy"*|*"epr"*) - case "$ACTION" in - *"left"|"voldown_one") - sxmo_type.sh l - exit 0 - ;; - *"right"|"volup_one") - sxmo_type.sh h - exit 0 - ;; - "voldown_three"|"twodownbottomedge") - sxmo_type.sh q - exit - ;; - esac - ;; - *'nnn'*|'lf') - case "$ACTION" in - *"left") - sxmo_type.sh -k Right - exit 0 - ;; - *"right") - sxmo_type.sh -k Left - exit 0 - ;; - esac - ;; - esac - - case "$WMCLASS" in # Handle general scrolling without touch support - *"st"*) - case "$ACTION" in - *"onedown") - sxmo_type.sh -M Ctrl -M Shift -k b - exit 0 - ;; - *"oneup") - sxmo_type.sh -M Ctrl -M Shift -k f - exit 0 - ;; - esac - ;; - "org.gnome.vte.application"|"terminal") - case "$ACTION" in - # For VTE, fallback to doing nothing, - # you're probably dragging the scrollbar - *"uprightedge") exit 0 ;; - *"downrightedge") exit 0 ;; - esac - ;; - esac - ;; -esac +# Process actions for current application +for DIR in "$HOME_INPUTHANDLER_D" "$SXMO_INPUTHANDLER_D" ; do + if [ -n "$WMCLASS" ] && [ -d "$DIR" ]; then + run_actiondir "$WMCLASS" "$WMNAME" "$ACTION" "$WMCLASS" "$DIR" + fi +done #standard handling case "$ACTION" in diff --git a/configs/inputhandler.d/acme.actions b/configs/inputhandler.d/acme.actions new file mode 100755 index 0000000..f96175a --- /dev/null +++ b/configs/inputhandler.d/acme.actions @@ -0,0 +1,22 @@ +#!/bin/sh + +WMCLASS="$1" +WMNAME="$2" +ACTION="$3" + +case "$ACTION" in + "volup_one") + xdotool click 3 + exit 0 + ;; + "voldown_one") + xdotool click 2 + exit 0 + ;; +esac + +# no branch taken +exit 1 + + +
nit: trailing newlines
diff --git a/configs/inputhandler.d/foot.actions b/configs/inputhandler.d/foot.actions new file mode 100755 index 0000000..278bbd3 --- /dev/null +++ b/configs/inputhandler.d/foot.actions @@ -0,0 +1,59 @@ +#!/bin/sh + +WMCLASS="$1" +WMNAME="$2" +ACTION="$3" + +run_actiondir () { + WMCLASS="$1" + WMNAME="$2" + ACTION="$3" + WMID="$4" # either WMCLASS or WMNAME + ADIR="$5" # directory where are actions scripts + + for APATH in "$ADIR"/*.actions; do + AFILE=${APATH##*/} + if [ -z "${WMID##*"${AFILE%.actions}"*}" ] ; then + $APATH "$WMCLASS" "$WMNAME" "$ACTION" + ret=$? + [ $ret -eq 0 ] && exit 0 + fi + done +} + +for DIR in $HOME_INPUTHANDLER_D/interminal $SXMO_INPUTHANDLER_D/interminal +do + if [ -n "$WMNAME" ] && [ -d "$DIR" ]; then + run_actiondir "$WMCLASS" "$WMNAME" "$ACTION" "$WMNAME" "$DIR" + fi +done
This all looks like duplicated code, ideally we should have it only in one place.
Be carefull with trailing whitespaces too. I recommend for you to configure your text EDITOR to at least display them, so that you notice them. By example, here what I see: https://dav.missbanal.net/05ec7fce-52b4-4e50-8744-1c3dab4d4406.png
+ +# Now we try generic actions for terminal +case "$WMCLASS" in # Handle general scrolling without touch support + *"st"*) + case "$ACTION" in + *"onedown") + sxmo_type.sh -M Ctrl -M Shift -k b + exit 0 + ;; + *"oneup") + sxmo_type.sh -M Ctrl -M Shift -k f + exit 0 + ;; + esac + ;; + "org.gnome.vte.application"|"terminal") + case "$ACTION" in + # For VTE, fallback to doing nothing, + # you're probably dragging the scrollbar + *"uprightedge") exit 0 ;; + *"downrightedge") exit 0 ;; + esac + ;; +esac + +# no branch taken +exit 1 + + +
trailing newlines
diff --git a/configs/inputhandler.d/interminal/amfora.actions b/configs/inputhandler.d/interminal/amfora.actions new file mode 100755 index 0000000..c97b253 --- /dev/null +++ b/configs/inputhandler.d/interminal/amfora.actions @@ -0,0 +1,33 @@ +#!/bin/sh + +ACTION="$3" + +case "$ACTION" in + "downright") + sxmo_type.sh -k Tab + exit 0 + ;; + "upleft") + sxmo_type.sh -M Shift -k Tab + exit 0 + ;; + *"oneright") + sxmo_type.sh -k Return + exit 0 + ;; + "upright") + sxmo_type.sh -M Ctrl t + exit 0 + ;; + *"oneleft") + sxmo_type.sh b + exit 0 + ;; + "downleft") + sxmo_type.sh -M Ctrl w + exit 0 + ;; +esac + +exit 1 + diff --git a/configs/inputhandler.d/interminal/epr.actions b/configs/inputhandler.d/interminal/epr.actions new file mode 100755 index 0000000..c831b63 --- /dev/null +++ b/configs/inputhandler.d/interminal/epr.actions @@ -0,0 +1,21 @@ +#!/bin/sh + +ACTION="$3" + +case "$ACTION" in + *"left"|"voldown_one") + sxmo_type.sh l + exit 0 + ;; + *"right"|"volup_one") + sxmo_type.sh h + exit 0 + ;; + "voldown_three"|"twodownbottomedge") + sxmo_type.sh q + exit + ;; +esac + +exit 1 + diff --git a/configs/inputhandler.d/interminal/epy.actions b/configs/inputhandler.d/interminal/epy.actions new file mode 100755 index 0000000..c831b63 --- /dev/null +++ b/configs/inputhandler.d/interminal/epy.actions @@ -0,0 +1,21 @@ +#!/bin/sh + +ACTION="$3" + +case "$ACTION" in + *"left"|"voldown_one") + sxmo_type.sh l + exit 0 + ;; + *"right"|"volup_one") + sxmo_type.sh h + exit 0 + ;; + "voldown_three"|"twodownbottomedge") + sxmo_type.sh q + exit + ;; +esac + +exit 1 + diff --git a/configs/inputhandler.d/interminal/less.actions b/configs/inputhandler.d/interminal/less.actions new file mode 100755 index 0000000..fd90a44 --- /dev/null +++ b/configs/inputhandler.d/interminal/less.actions @@ -0,0 +1,25 @@ +#!/bin/sh + +ACTION="$3" + +case "$ACTION" in + "leftbottomedge") + sxmo_type.sh q + exit 0 + ;; + "leftrightedge_short") + sxmo_type.sh q + exit 0 + ;; + *"oneleft") + sxmo_type.sh ":n" -k Return + exit 0 + ;; + *"oneright") + sxmo_type.sh ":p" -k Return + exit 0 + ;; +esac + +exit 1 + diff --git a/configs/inputhandler.d/interminal/lf.actions b/configs/inputhandler.d/interminal/lf.actions new file mode 100755 index 0000000..6f651be --- /dev/null +++ b/configs/inputhandler.d/interminal/lf.actions @@ -0,0 +1,18 @@ +#!/bin/sh + +ACTION="$3" + +case "$ACTION" in + *"left") + sxmo_type.sh -k Right + exit 0 + ;; + *"right") + sxmo_type.sh -k Left + exit 0 + ;; +esac + + +exit 1 + diff --git a/configs/inputhandler.d/interminal/nnn.actions b/configs/inputhandler.d/interminal/nnn.actions new file mode 100755 index 0000000..6f651be --- /dev/null +++ b/configs/inputhandler.d/interminal/nnn.actions @@ -0,0 +1,18 @@ +#!/bin/sh + +ACTION="$3" + +case "$ACTION" in + *"left") + sxmo_type.sh -k Right + exit 0 + ;; + *"right") + sxmo_type.sh -k Left + exit 0 + ;; +esac + + +exit 1 + diff --git a/configs/inputhandler.d/interminal/sms.actions b/configs/inputhandler.d/interminal/sms.actions new file mode 100755 index 0000000..1f9db39 --- /dev/null +++ b/configs/inputhandler.d/interminal/sms.actions @@ -0,0 +1,16 @@ +#!/bin/sh + +WMNAME="$2" +ACTION="$3" + +number="$(printf %s "$WMNAME" | sed -e 's|^\"||' -e 's|\"$||' | cut -f1 -d' ')" +case "$ACTION" in + *"upbottomedge") + number="$(printf %s "$WMNAME" | sed -e 's|^\"||' -e 's|\"$||' | cut -f1 -d' ')" + sxmo_terminal.sh sxmo_modemtext.sh conversationloop "$number" & + exit 0 + ;; +esac + +exit 1 + diff --git a/configs/inputhandler.d/interminal/tuir.actions b/configs/inputhandler.d/interminal/tuir.actions new file mode 100755 index 0000000..7e0acd9 --- /dev/null +++ b/configs/inputhandler.d/interminal/tuir.actions @@ -0,0 +1,14 @@ +#!/bin/sh + +ACTION="$3" + +if [ "$ACTION" = "rightbottomedge" ]; then + sxmo_type.sh o + exit 0 +elif [ "$ACTION" = "leftbottomedge" ]; then + sxmo_type.sh s + exit 0 +fi + +exit 1 + diff --git a/configs/inputhandler.d/interminal/weechat.actions b/configs/inputhandler.d/interminal/weechat.actions new file mode 100755 index 0000000..4e52a8c --- /dev/null +++ b/configs/inputhandler.d/interminal/weechat.actions @@ -0,0 +1,17 @@ +#!/bin/sh + +ACTION="$3" + +case "$ACTION" in + *"oneleft") + sxmo_type.sh -M Alt -k a + exit 0 + ;; + *"oneright") + sxmo_type.sh -M Alt -k less + exit 0 + ;; +esac + +exit 1 + diff --git a/configs/inputhandler.d/mpv.actions b/configs/inputhandler.d/mpv.actions new file mode 100755 index 0000000..3b1dca2 --- /dev/null +++ b/configs/inputhandler.d/mpv.actions @@ -0,0 +1,28 @@ +#!/bin/sh + +ACTION="$3" + +case "$ACTION" in + "oneright") + sxmo_type.sh -k Left + exit 0 + ;; + "oneleft") + sxmo_type.sh -k Right + exit 0 + ;; + "oneup") + sxmo_type.sh m + exit 0 + ;; + "onedown") + sxmo_type.sh p + exit 0 + ;; +esac + +# no branch taken +exit 1 + + +
trailing newlines
diff --git a/configs/inputhandler.d/st.actions b/configs/inputhandler.d/st.actions new file mode 100755 index 0000000..5926f4a --- /dev/null +++ b/configs/inputhandler.d/st.actions @@ -0,0 +1,84 @@ +#!/bin/sh + +WMCLASS="$1" +WMNAME="$2" +ACTION="$3" + +# specific actions to st (for handling scrolling) +case "$WMNAME" in + *"weechat"*|*'gomuks'*) + case "$ACTION" in + *"onedown") + sxmo_type.sh -k Page_Up + exit 0 + ;; + *"oneup") + sxmo_type.sh -k Page_Down + exit 0 + ;; + esac + ;; + *"less"*|*"amfora"*) + case "$ACTION" in + *"onedown") + sxmo_type.sh u + exit 0 + ;; + *"oneup") + sxmo_type.sh d + exit 0 + ;; + esac + ;; + *'irssi'*) + case "$ACTION" in + "onedown") + sxmo_type.sh -M Alt p + exit 0 + ;; + "oneup") + sxmo_type.sh -M Alt n + exit 0 + ;; + esac + ;; + *'epy'*|*'epr'*) + case "$ACTION" in + "onedown") + sxmo_type.sh h + exit 0 + ;; + "oneup") + sxmo_type.sh l + exit 0 + ;; + esac + ;; + *'nnn'*|'lf') + case "$ACTION" in + "onedown") + sxmo_type.sh -k Down + exit 0 + ;; + "oneup") + sxmo_type.sh -k Up + exit 0 + ;; + esac + ;; +esac + +# handle generic terminal actions +if [ -e "$HOME_INPUTHANDLER_D"/terminal.actions ]; then + "$HOME_INPUTHANDLER_D"/terminal.actions "$WMCLASS" "$WMNAME" "$ACTION" + [ $? -eq 0 ] && exit 0 +else + "$SXMO_INPUTHANDLER_D"/terminal.actions "$WMCLASS" "$WMNAME" "$ACTION" + [ $? -eq 0 ] && exit 0 +fi + +# no branch taken +exit 1 + + +
trailing newlines
diff --git a/configs/inputhandler.d/terminal.actions b/configs/inputhandler.d/terminal.actions new file mode 100755 index 0000000..278bbd3 --- /dev/null +++ b/configs/inputhandler.d/terminal.actions @@ -0,0 +1,59 @@ +#!/bin/sh + +WMCLASS="$1" +WMNAME="$2" +ACTION="$3" + +run_actiondir () { + WMCLASS="$1" + WMNAME="$2" + ACTION="$3" + WMID="$4" # either WMCLASS or WMNAME + ADIR="$5" # directory where are actions scripts + + for APATH in "$ADIR"/*.actions; do + AFILE=${APATH##*/} + if [ -z "${WMID##*"${AFILE%.actions}"*}" ] ; then + $APATH "$WMCLASS" "$WMNAME" "$ACTION" + ret=$? + [ $ret -eq 0 ] && exit 0 + fi + done +} + +for DIR in $HOME_INPUTHANDLER_D/interminal $SXMO_INPUTHANDLER_D/interminal +do + if [ -n "$WMNAME" ] && [ -d "$DIR" ]; then + run_actiondir "$WMCLASS" "$WMNAME" "$ACTION" "$WMNAME" "$DIR" + fi +done
more duplicated code
Trailing whitespace here too.
+ +# Now we try generic actions for terminal +case "$WMCLASS" in # Handle general scrolling without touch support + *"st"*) + case "$ACTION" in + *"onedown") + sxmo_type.sh -M Ctrl -M Shift -k b + exit 0 + ;; + *"oneup") + sxmo_type.sh -M Ctrl -M Shift -k f + exit 0 + ;; + esac + ;; + "org.gnome.vte.application"|"terminal") + case "$ACTION" in + # For VTE, fallback to doing nothing, + # you're probably dragging the scrollbar + *"uprightedge") exit 0 ;; + *"downrightedge") exit 0 ;; + esac + ;; +esac + +# no branch taken +exit 1 + + +
more trailing newlines
diff --git a/configs/inputhandler.d/vte.actions b/configs/inputhandler.d/vte.actions new file mode 100755 index 0000000..278bbd3 --- /dev/null +++ b/configs/inputhandler.d/vte.actions @@ -0,0 +1,59 @@ +#!/bin/sh + +WMCLASS="$1" +WMNAME="$2" +ACTION="$3" + +run_actiondir () { + WMCLASS="$1" + WMNAME="$2" + ACTION="$3" + WMID="$4" # either WMCLASS or WMNAME + ADIR="$5" # directory where are actions scripts + + for APATH in "$ADIR"/*.actions; do + AFILE=${APATH##*/} + if [ -z "${WMID##*"${AFILE%.actions}"*}" ] ; then + $APATH "$WMCLASS" "$WMNAME" "$ACTION" + ret=$? + [ $ret -eq 0 ] && exit 0 + fi + done +} + +for DIR in $HOME_INPUTHANDLER_D/interminal $SXMO_INPUTHANDLER_D/interminal +do + if [ -n "$WMNAME" ] && [ -d "$DIR" ]; then + run_actiondir "$WMCLASS" "$WMNAME" "$ACTION" "$WMNAME" "$DIR" + fi +done
Trailing whitespace here too.
+ +# Now we try generic actions for terminal +case "$WMCLASS" in # Handle general scrolling without touch support + *"st"*) + case "$ACTION" in + *"onedown") + sxmo_type.sh -M Ctrl -M Shift -k b + exit 0 + ;; + *"oneup") + sxmo_type.sh -M Ctrl -M Shift -k f + exit 0 + ;; + esac + ;; + "org.gnome.vte.application"|"terminal") + case "$ACTION" in + # For VTE, fallback to doing nothing, + # you're probably dragging the scrollbar + *"uprightedge") exit 0 ;; + *"downrightedge") exit 0 ;; + esac + ;; +esac + +# no branch taken +exit 1 + + + -- 2.43.0
builds.sr.ht <builds@sr.ht>sxmo-utils/patches/test.yml: SUCCESS in 22s [Tentative to modularize inputhandler][0] from [Florent de Lamotte][1] [0]: https://lists.sr.ht/~mil/sxmo-devel/patches/51634 [1]: mailto:florent@frizoncorrea.fr ✓ #1213930 SUCCESS sxmo-utils/patches/test.yml https://builds.sr.ht/~mil/job/1213930
I agree with Aren here. The idea is interesting and I am willing to help on this, but only if (1) there is no performance impact, (2) sxmo_migrate.sh manage them, and (3) it is still easy for user to add/expand them. I mark this as needing_revision anyway. Additionnaly to Aren review, here some comments: