Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
14 changes: 12 additions & 2 deletions packages/omamobile-shell/bin/omamobile-keys
Original file line number Diff line number Diff line change
Expand Up @@ -180,7 +180,7 @@ short_press() {
# brightness of 0, which left the phone dark on the next wake. A press a
# few seconds later must still count: it is the wake.
local now last
now=$(date +%s%3N); last=$(cat "$state/last-press" 2>/dev/null || echo 0)
now=$1; last=$(cat "$state/last-press" 2>/dev/null || echo 0)
echo "$now" >"$state/last-press"
(( now - last < 800 )) && return 0
# The press that woke the phone from sleep, if it gets here at all:
Expand Down Expand Up @@ -312,7 +312,17 @@ case "${1:-}" in
elif [[ -f $state/long ]]; then
rm -f "$state/long"
else
short_press
# Let a second press observe the finished off transition before it
# decides whether to wake. Keep the lock out of background helpers.
released_at=$(now)
exec {short_lock}>"$state/short.lock"
# A stuck action must not queue every later press forever. Drop this
# press after five seconds rather than overlap display transitions.
if ! flock -w 5 "$short_lock"; then
echo 'omamobile-keys: short-press lock wait failed; dropping press' >&2
exit 0
fi
( short_press "$released_at" ) {short_lock}>&-
fi
;;
wake)
Expand Down
1 change: 1 addition & 0 deletions packages/omamobile-shell/test/all
Original file line number Diff line number Diff line change
Expand Up @@ -1166,3 +1166,4 @@ elif [[ $rc != 0 ]]; then
else
pass "Back threshold feedback: once per gesture, both edges and retreat"
fi
bash test/power-overlap.sh || fail "overlapping power-key presses"
100 changes: 100 additions & 0 deletions packages/omamobile-shell/test/power-overlap.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,100 @@
#!/bin/bash
# SPDX-License-Identifier: MIT
# Two presses during a slow lock must leave the phone awake at its old brightness.
set -euo pipefail
here=$(cd -- "$(dirname -- "${BASH_SOURCE[0]}")/.." && pwd)
t=$(mktemp -d); trap 'rm -rf "$t"' EXIT
mkdir -p "$t/bin" "$t/run"
export XDG_RUNTIME_DIR="$t/run" T="$t"
echo 512 >"$t/brightness"; echo true >"$t/dpms"
cat >"$t/bin/hyprctl" <<'STUB'
#!/bin/bash
printf '[{"dpmsStatus":%s}]\n' "$(cat "$T/dpms")"
STUB
cat >"$t/bin/omarchy-shell" <<'STUB'
#!/bin/bash
[[ $2 == isLocked ]] && echo false
exit 0
STUB
cat >"$t/bin/omarchy-hw-display" <<'STUB'
#!/bin/bash
echo fake-panel
STUB
cat >"$t/bin/brightnessctl" <<'STUB'
#!/bin/bash
if [[ $* == *get* ]]; then cat "$T/brightness"; else echo "${@: -1}" >"$T/brightness"; fi
STUB
cat >"$t/bin/omarchy-brightness-display" <<'STUB'
#!/bin/bash
case $1 in off) echo false >"$T/dpms";; on) echo true >"$T/dpms";; esac
STUB
cat >"$t/bin/omarchy-system-lock" <<'STUB'
#!/bin/bash
for fd in /proc/$$/fd/*; do
[[ $(readlink "$fd" 2>/dev/null) == "$T/run/omamobile-keys/short.lock" ]] && touch "$T/inherited-lock"
done
touch "$T/locking"
sleep "${LOCK_DELAY:-1.5}"
STUB
cat >"$t/bin/pgrep" <<'STUB'
#!/bin/bash
exit 1
STUB
chmod +x "$t"/bin/*
# Only these host tools are reachable; unstubbed desktop commands must fail.
for tool in bash cat readlink touch sleep mkdir rm seq grep jq flock date stat timeout; do
ln -s "$(command -v "$tool")" "$t/bin/$tool"
done
export PATH="$t/bin"
keys() { bash "$here/bin/omamobile-keys" "$@"; }
run_case() {
local delay=$1 expected=$2 first second
rm -rf "$t/run/omamobile-keys"
echo 512 >"$t/brightness"; echo true >"$t/dpms"
keys power-down; sleep 0.1; keys power-up & first=$!
sleep "$delay"; keys power-down; sleep 0.1; keys power-up & second=$!
wait "$first"; wait "$second"
[[ ! -e $t/inherited-lock ]] || { echo 'not ok - helper inherited the power-key lock' >&2; exit 1; }
[[ $(cat "$t/dpms") == "$expected" && $(cat "$t/brightness") == 512 ]] || {
echo "not ok - delay $delay produced wrong screen state or brightness" >&2
exit 1
}
}
run_case 1 true
run_case 0.2 false
echo 'ok - overlapping presses wake after one second and debounce at 0.2 seconds'

# A hung lock helper must not queue later presses indefinitely. The second
# press is dropped after five seconds without changing debounce or display.
rm -rf "$t/run/omamobile-keys"
rm -f "$t/locking"
echo 512 >"$t/brightness"; echo true >"$t/dpms"
export LOCK_DELAY=8
keys power-down; sleep 0.1; keys power-up & first=$!
for _ in {1..100}; do
[[ -e $t/locking ]] && break
sleep 0.05
done
[[ -e $t/locking ]] || { echo 'not ok - slow action never started' >&2; exit 1; }
last=$(cat "$t/run/omamobile-keys/last-press")
keys power-down; sleep 0.1
start=$(date +%s%3N)
rc=0
timeout 7 bash "$here/bin/omamobile-keys" power-up 2>"$t/timeout-log" || rc=$?
elapsed=$(( $(date +%s%3N) - start ))
if [[ $rc != 0 || $elapsed -lt 4500 || $elapsed -ge 7000 ]] ||
! grep -q 'short-press lock wait failed; dropping press' "$t/timeout-log" ||
[[ $(cat "$t/run/omamobile-keys/last-press") != "$last" ||
$(cat "$t/dpms") != true || $(cat "$t/brightness") != 0 ]]; then
wait "$first"
echo 'not ok - blocked press did not time out without acting' >&2
exit 1
fi
wait "$first"
unset LOCK_DELAY
# Once the slow action releases the lock, a fresh press still wakes normally.
keys power-down; sleep 0.1; keys power-up
[[ $(cat "$t/dpms") == true && $(cat "$t/brightness") == 512 ]] || {
echo 'not ok - power key failed to recover after lock release' >&2; exit 1;
}
echo 'ok - blocked press is dropped after five seconds; next press works after release'
2 changes: 1 addition & 1 deletion packages/omamobile-shell/version
Original file line number Diff line number Diff line change
@@ -1 +1 @@
0.2.111
0.2.112