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