sane-input-handler: implement --verbose flag

This commit is contained in:
2025-03-30 00:10:00 +00:00
parent 6a14303395
commit 617babafad

View File

@@ -60,10 +60,8 @@ VOL_INCR=5
KEYBOARD="${KEYBOARD:-wvkbd-mobintl}"
CAMERA="${CAMERA:-org.postmarketos.Megapixels.desktop}"
action="$1"
showHelp() {
echo "usage: sane-input-handler <action>"
echo "usage: sane-input-handler [--verbose] <action>"
echo ""
echo "where action is one of:"
echo "- power_tap_{1,2}"
@@ -81,7 +79,18 @@ showHelp() {
}
log() {
printf "sane-input-handler: %s\n" "$1"
printf "sane-input-handler: %s\n" "$1" >&2
}
debug() {
if [ -n "$VERBOSE" ]; then
log "$@"
fi
}
trace() {
debug "$*"
"$@"
}
## HELPERS
@@ -89,7 +98,7 @@ log() {
# swaySetOutput true|false
# turns the display on or off
swaySetOutput() {
swaymsg -- output '*' power "$1"
trace swaymsg -- output '*' power "$1"
}
# swaySetTouch enabled|disabled
# turns touch input on or off
@@ -99,7 +108,7 @@ swaySetTouch() {
local inputs=$(swaymsg -t get_inputs --raw | jq '. | map(select(.type == "touch")) | map(.identifier) | join(" ")' --raw-output)
for id in "${inputs[@]}"; do
swaymsg -- input "$id" events "$1"
trace swaymsg -- input "$id" events "$1"
done
}
@@ -171,7 +180,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 env kill -s RTMIN+0 "$p"; then
if trace env kill -s RTMIN+0 "$p"; then
break
fi
done
@@ -292,27 +301,43 @@ dispatchToplevel() {
_isAllOn="$(isAllOn && echo 1 || true)"
if [ -z "$_isAllOn" ]; then
dispatchOff
trace dispatchOff
else
_isInhibited="$(isInhibited && echo 1 || true)"
if [ -n "$_isInhibited" ]; then
dispatchInhibited
trace dispatchInhibited
else
dispatchOn
trace dispatchOn
fi
fi
dispatchDefault
trace dispatchDefault
}
case "$action" in
(--help)
showHelp
exit 0
;;
(*)
dispatchToplevel
handleWith unmapped
;;
esac
action=
doShowHelp=
parseArgs() {
for arg in "$@"; do
case "$arg" in
(-h|--help)
doShowHelp=1
;;
(-v|--verbose)
VERBOSE=1
;;
(*)
action="$arg"
;;
esac
done
}
parseArgs "$@"
if [ -n "$doShowHelp" ]; then
showHelp
exit 0
fi
trace dispatchToplevel
handleWith unmapped