From c8b0f4c820ca8ac18d6504d26b907353a62e90f2 Mon Sep 17 00:00:00 2001 From: Gr-linkk <280405187+Gr-linkk@users.noreply.github.com> Date: Sat, 7 Nov 2026 20:57:02 -0700 Subject: [PATCH 1/2] omamobile-shell 0.2.102: serialize power key actions A second short press can arrive while the first is still locking and powering the panel off. Serialize short actions so the later press sees the completed transition. Use the captured release time for debounce, and close the lock descriptor in the action subprocess so background helpers cannot keep it held. The focused host regression fails against main with the wrong screen state and passes with this fix, covering wake, debounce, brightness preservation and lock descriptor inheritance. Co-Authored-By: Codex --- packages/omamobile-shell/bin/omamobile-keys | 9 ++- packages/omamobile-shell/test/all | 1 + .../omamobile-shell/test/power-overlap.sh | 59 +++++++++++++++++++ packages/omamobile-shell/version | 2 +- 4 files changed, 68 insertions(+), 3 deletions(-) create mode 100644 packages/omamobile-shell/test/power-overlap.sh diff --git a/packages/omamobile-shell/bin/omamobile-keys b/packages/omamobile-shell/bin/omamobile-keys index c3becc29c..12f5c0dff 100644 --- a/packages/omamobile-shell/bin/omamobile-keys +++ b/packages/omamobile-shell/bin/omamobile-keys @@ -161,7 +161,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: @@ -300,7 +300,12 @@ 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" + flock "$short_lock" || exit 1 + ( short_press "$released_at" ) {short_lock}>&- fi ;; wake) diff --git a/packages/omamobile-shell/test/all b/packages/omamobile-shell/test/all index 4a242065b..ba354786d 100755 --- a/packages/omamobile-shell/test/all +++ b/packages/omamobile-shell/test/all @@ -1119,3 +1119,4 @@ grep -c 'd355bdb2789f7bd1023d88b17f8a2898dc0ffa2b' widgets/OWL.md >/dev/null || pass "install stages the package" test/keys.sh || fail "omamobile-keys volume keys" +bash test/power-overlap.sh || fail "overlapping power-key presses" diff --git a/packages/omamobile-shell/test/power-overlap.sh b/packages/omamobile-shell/test/power-overlap.sh new file mode 100644 index 000000000..2b37c0210 --- /dev/null +++ b/packages/omamobile-shell/test/power-overlap.sh @@ -0,0 +1,59 @@ +#!/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" PATH="$t/bin:$PATH" +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 +sleep 1.5 +STUB +cat >"$t/bin/pgrep" <<'STUB' +#!/bin/bash +exit 1 +STUB +chmod +x "$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' diff --git a/packages/omamobile-shell/version b/packages/omamobile-shell/version index d8a838a1f..e0fe248e3 100644 --- a/packages/omamobile-shell/version +++ b/packages/omamobile-shell/version @@ -1 +1 @@ -0.2.101 +0.2.102 From 3fd5b39b0e5482cd5e8cebd77213e49a10a06184 Mon Sep 17 00:00:00 2001 From: Gr-linkk <280405187+Gr-linkk@users.noreply.github.com> Date: Sun, 8 Nov 2026 09:51:54 -0700 Subject: [PATCH 2/2] omamobile-shell 0.2.102: bound the power-key lock wait Drop a short press with a diagnostic after five seconds waiting for the previous action. Keep display transitions serialized without queueing later presses indefinitely behind a stuck helper. The regression fails against the previous unbounded wait and passes with the timeout, preserving debounce/display state and recovering after the holder exits. Restrict its PATH to explicit utilities and desktop stubs. Keep the existing draft version; the maintainer will assign it at merge. Co-Authored-By: Codex --- packages/omamobile-shell/bin/omamobile-keys | 7 ++- .../omamobile-shell/test/power-overlap.sh | 45 ++++++++++++++++++- 2 files changed, 49 insertions(+), 3 deletions(-) diff --git a/packages/omamobile-shell/bin/omamobile-keys b/packages/omamobile-shell/bin/omamobile-keys index 12f5c0dff..385f1fe52 100644 --- a/packages/omamobile-shell/bin/omamobile-keys +++ b/packages/omamobile-shell/bin/omamobile-keys @@ -304,7 +304,12 @@ case "${1:-}" in # decides whether to wake. Keep the lock out of background helpers. released_at=$(now) exec {short_lock}>"$state/short.lock" - flock "$short_lock" || exit 1 + # 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 ;; diff --git a/packages/omamobile-shell/test/power-overlap.sh b/packages/omamobile-shell/test/power-overlap.sh index 2b37c0210..1b24a40da 100644 --- a/packages/omamobile-shell/test/power-overlap.sh +++ b/packages/omamobile-shell/test/power-overlap.sh @@ -5,7 +5,7 @@ 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" PATH="$t/bin:$PATH" +export XDG_RUNTIME_DIR="$t/run" T="$t" echo 512 >"$t/brightness"; echo true >"$t/dpms" cat >"$t/bin/hyprctl" <<'STUB' #!/bin/bash @@ -33,13 +33,19 @@ cat >"$t/bin/omarchy-system-lock" <<'STUB' for fd in /proc/$$/fd/*; do [[ $(readlink "$fd" 2>/dev/null) == "$T/run/omamobile-keys/short.lock" ]] && touch "$T/inherited-lock" done -sleep 1.5 +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 @@ -57,3 +63,38 @@ run_case() { 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'