sane-input-handler: implement --dry-run flag
This commit is contained in:
@@ -61,7 +61,7 @@ KEYBOARD="${KEYBOARD:-wvkbd-mobintl}"
|
||||
CAMERA="${CAMERA:-org.postmarketos.Megapixels.desktop}"
|
||||
|
||||
showHelp() {
|
||||
echo "usage: sane-input-handler [--verbose] <action>"
|
||||
echo "usage: sane-input-handler [--verbose] [--dry-run] <action>"
|
||||
echo ""
|
||||
echo "where action is one of:"
|
||||
echo "- power_tap_{1,2}"
|
||||
@@ -82,6 +82,7 @@ log() {
|
||||
printf "sane-input-handler: %s\n" "$1" >&2
|
||||
}
|
||||
|
||||
VERBOSE=
|
||||
debug() {
|
||||
if [ -n "$VERBOSE" ]; then
|
||||
log "$@"
|
||||
@@ -93,12 +94,21 @@ trace() {
|
||||
"$@"
|
||||
}
|
||||
|
||||
DRY_RUN=
|
||||
effect() {
|
||||
if [ -n "$DRY_RUN" ]; then
|
||||
log "SKIP(dry run): $*"
|
||||
else
|
||||
trace "$@"
|
||||
fi
|
||||
}
|
||||
|
||||
## HELPERS
|
||||
|
||||
# swaySetOutput true|false
|
||||
# turns the display on or off
|
||||
swaySetOutput() {
|
||||
trace swaymsg -- output '*' power "$1"
|
||||
effect swaymsg -- output '*' power "$1"
|
||||
}
|
||||
# swaySetTouch enabled|disabled
|
||||
# turns touch input on or off
|
||||
@@ -106,9 +116,10 @@ swaySetTouch() {
|
||||
# XXX(2024/06/09): `type:touch` method is documented, but now silently fails
|
||||
# swaymsg -- input type:touch events "$1"
|
||||
|
||||
local inputs=$(swaymsg -t get_inputs --raw | jq '. | map(select(.type == "touch")) | map(.identifier) | join(" ")' --raw-output)
|
||||
local inputs=($(swaymsg -t get_inputs --raw | jq '. | map(select(.type == "touch")) | map(.identifier) | join(" ")' --raw-output))
|
||||
debug "detected ${#inputs[@]} sway inputs"
|
||||
for id in "${inputs[@]}"; do
|
||||
trace swaymsg -- input "$id" events "$1"
|
||||
effect swaymsg -- input "$id" events "$1"
|
||||
done
|
||||
}
|
||||
|
||||
@@ -180,7 +191,7 @@ toggleKeyboard() {
|
||||
# `env` so that we get the right `kill` binary instead of bash's builtin
|
||||
# `kill` only one keyboard process. in the case of e.g. sandboxing,
|
||||
# the keyboard might consist of multiple processes and each one we signal would cause a toggle
|
||||
if trace env kill -s RTMIN+0 "$p"; then
|
||||
if effect env kill -s RTMIN+0 "$p"; then
|
||||
break
|
||||
fi
|
||||
done
|
||||
@@ -196,14 +207,14 @@ dispatchDefault() {
|
||||
;;
|
||||
"power_hold")
|
||||
# power twice => toggle media player
|
||||
handleWith playerctl play-pause
|
||||
handleWith effect playerctl play-pause
|
||||
;;
|
||||
|
||||
volup_tap*)
|
||||
handleWith wpctl set-volume @DEFAULT_AUDIO_SINK@ "$VOL_INCR"%+
|
||||
handleWith effect wpctl set-volume @DEFAULT_AUDIO_SINK@ "$VOL_INCR"%+
|
||||
;;
|
||||
voldown_tap*)
|
||||
handleWith wpctl set-volume @DEFAULT_AUDIO_SINK@ "$VOL_INCR"%-
|
||||
handleWith effect wpctl set-volume @DEFAULT_AUDIO_SINK@ "$VOL_INCR"%-
|
||||
;;
|
||||
esac
|
||||
}
|
||||
@@ -216,13 +227,13 @@ dispatchOff() {
|
||||
;;
|
||||
"power_tap_1_hold")
|
||||
# power tap->hold: escape hatch for when bonsaid locks up
|
||||
handleWith systemctl restart bonsaid
|
||||
handleWith effect systemctl restart bonsaid
|
||||
;;
|
||||
volup_hold*)
|
||||
handleWith playerctl position 30+
|
||||
handleWith effect playerctl position 30+
|
||||
;;
|
||||
voldown_hold*)
|
||||
handleWith playerctl position 10-
|
||||
handleWith effect playerctl position 10-
|
||||
;;
|
||||
esac
|
||||
}
|
||||
@@ -234,34 +245,34 @@ dispatchOn() {
|
||||
"power_tap_1_hold")
|
||||
# power tap->hold: kill active window
|
||||
# TODO: disable this if locked (with e.g. schlock, swaylock, etc)
|
||||
handleWith swaymsg kill
|
||||
handleWith effect swaymsg kill
|
||||
;;
|
||||
"power_and_volup")
|
||||
# power (hold) -> volup: take screenshot
|
||||
handleWith sane-open --application sane-screenshot.desktop
|
||||
handleWith effect sane-open --application sane-screenshot.desktop
|
||||
;;
|
||||
"power_and_voldown")
|
||||
# power (hold) -> voldown: open camera
|
||||
handleWith sane-open --auto-keyboard --application "$CAMERA"
|
||||
handleWith effect sane-open --auto-keyboard --application "$CAMERA"
|
||||
;;
|
||||
"power_then_volup")
|
||||
# power (tap) -> volup: rotate CCW
|
||||
handleWith swaymsg -- output '-' transform 90 anticlockwise
|
||||
handleWith effect swaymsg -- output '-' transform 90 anticlockwise
|
||||
;;
|
||||
"power_then_voldown")
|
||||
# power (tap) -> voldown: rotate CW
|
||||
handleWith swaymsg -- output '-' transform 90 clockwise
|
||||
handleWith effect swaymsg -- output '-' transform 90 clockwise
|
||||
;;
|
||||
|
||||
"volup_tap_1")
|
||||
# volume up once: filesystem browser
|
||||
handleWith sane-open --auto-keyboard --application rofi-filebrowser.desktop
|
||||
handleWith effect sane-open --auto-keyboard --application rofi-filebrowser.desktop
|
||||
;;
|
||||
"volup_hold_1")
|
||||
# volume up hold: browse files and apps
|
||||
# reset fs directory: useful in case you get stuck in broken directory (e.g. one which lacks a `..` entry)
|
||||
rm -f ~/.cache/rofi/rofi3.filebrowsercache
|
||||
handleWith sane-open --auto-keyboard --application rofi.desktop
|
||||
handleWith effect sane-open --auto-keyboard --application rofi.desktop
|
||||
;;
|
||||
|
||||
"voldown_start")
|
||||
@@ -271,7 +282,7 @@ dispatchOn() {
|
||||
"voldown_hold_1")
|
||||
# hold voldown to launch terminal
|
||||
# note we already triggered the keyboard; that's fine: usually keyboard + terminal go together :)
|
||||
handleWith sane-open --auto-keyboard --application xdg-terminal-exec.desktop
|
||||
handleWith effect sane-open --auto-keyboard --application xdg-terminal-exec.desktop
|
||||
;;
|
||||
"voldown_tap_1")
|
||||
# swallow, to prevent keyboard from also triggering media controls
|
||||
@@ -288,7 +299,7 @@ dispatchInhibited() {
|
||||
case "$action" in
|
||||
"power_tap_1_hold")
|
||||
# power hold: escape hatch in case rofi has hung
|
||||
handleWith killall -9 rofi
|
||||
handleWith effect killall -9 rofi
|
||||
;;
|
||||
*)
|
||||
# eat everything else (and let rofi consume it)
|
||||
@@ -319,6 +330,9 @@ doShowHelp=
|
||||
parseArgs() {
|
||||
for arg in "$@"; do
|
||||
case "$arg" in
|
||||
(--dry-run)
|
||||
DRY_RUN=1
|
||||
;;
|
||||
(-h|--help)
|
||||
doShowHelp=1
|
||||
;;
|
||||
|
Reference in New Issue
Block a user