61 lines
1.4 KiB
Bash
Executable File
61 lines
1.4 KiB
Bash
Executable File
#!/bin/sh
|
|
# SPDX-License-Identifier: AGPL-3.0-only
|
|
# Copyright 2022 Sxmo Contributors
|
|
# shellcheck source=scripts/core/sxmo_common.sh
|
|
. sxmo_common.sh
|
|
|
|
if [ "$1" = clear ]; then
|
|
rm -f "$XDG_RUNTIME_DIR"/sxmo.multikey.count.*
|
|
exit
|
|
fi
|
|
|
|
identifier="$1"
|
|
threshold="${SXMO_THRESHOLD:-0.15}"
|
|
|
|
# Fast path: when locked or screenoff, single/double/triple presses on power/pickup
|
|
# all wake and unlock the phone, so execute immediately without waiting 300ms.
|
|
STATE_FILE="${SXMO_STATE:-$XDG_RUNTIME_DIR/sxmo.state}"
|
|
if [ -r "$STATE_FILE" ]; then
|
|
read -r cur_state < "$STATE_FILE" 2>/dev/null || cur_state=""
|
|
if [ "$cur_state" != "unlock" ]; then
|
|
case "$identifier" in
|
|
powerbutton|pickup)
|
|
rm -f "$XDG_RUNTIME_DIR"/sxmo.multikey.count."$identifier"
|
|
exec sxmo_hook_inputhandler.sh "$2"
|
|
;;
|
|
esac
|
|
fi
|
|
fi
|
|
|
|
count_file="$XDG_RUNTIME_DIR"/sxmo.multikey.count."$identifier"
|
|
|
|
if [ -f "$count_file" ]; then
|
|
read -r old_counter < "$count_file" 2>/dev/null || old_counter=0
|
|
counter="$((old_counter+1))"
|
|
else
|
|
counter=1
|
|
fi
|
|
|
|
printf %s "$counter" > "$count_file"
|
|
|
|
shift "$counter"
|
|
if [ "$#" -eq 0 ]; then
|
|
exit
|
|
fi
|
|
|
|
sleep "$threshold"
|
|
|
|
read -r new_counter < "$count_file" 2>/dev/null || new_counter="$counter"
|
|
if [ "$counter" != "$new_counter" ] && [ "$#" -ne 1 ]; then # Only the last count can overflow
|
|
exit
|
|
fi
|
|
|
|
eval sxmo_hook_inputhandler.sh "$1" &
|
|
|
|
if [ "$counter" != "$new_counter" ]; then # overflowed
|
|
sleep "$threshold"
|
|
sleep "$threshold"
|
|
fi
|
|
|
|
rm -f "$count_file"
|