From 34493b2715f32788f2e5a8905a69f4c61953d054 Mon Sep 17 00:00:00 2001 From: Lef Date: Wed, 18 Nov 2026 19:58:04 +0200 Subject: [PATCH] omamobile-keys: a double tap lights the display first, behind the Android switch With OMAMOBILE_POWER_KEY_ANDROID=1, a double tap on a dark screen starts the display first, in the background, and runs the locked check and the lock's wake beside it, then waits for the display and puts the brightness floor back. The display (about 0.25 s of modeset, then the panel's 0.13 s on the Pixel 8 Pro) is the slow part, and neither call into the shell depends on it. I put it behind the switch main already has rather than making it the default, so phones without it (the Pixel 7 Pro today) keep the order they have: the locked check, the lock's wake, then the display. The brightness floor is now one function, brightness_floor, used by both wake_locked definitions, wake_unlocked and the double tap. test/keys.sh checks the double tap's order with the switch on and off. The display stand-in waits on a FIFO that the test opens only after it has seen the lock's wake (or the display's start when unlocked), and with the switch on the locked check waits for the display's start, so the check doesn't depend on sleeps or the runner's clock. --- packages/omamobile-shell/bin/omamobile-keys | 44 +++++++++++------- packages/omamobile-shell/test/keys.sh | 51 ++++++++++++++++++++- 2 files changed, 77 insertions(+), 18 deletions(-) diff --git a/packages/omamobile-shell/bin/omamobile-keys b/packages/omamobile-shell/bin/omamobile-keys index 5d7f71686..09d63f13a 100644 --- a/packages/omamobile-shell/bin/omamobile-keys +++ b/packages/omamobile-shell/bin/omamobile-keys @@ -94,6 +94,16 @@ screensaver_up() { pgrep -f '[o]rg.omarchy.screensaver' >/dev/null } +# A saved brightness of 0 would wake to a black panel: once the display is +# on, put the floor back. +brightness_floor() { + local device + device=$(omarchy-hw-display 2>/dev/null) + sleep 0.3 + [[ -n $device ]] || return 0 + [[ $(brightnessctl -d "$device" get 2>/dev/null || echo 1) -gt 0 ]] || brightnessctl -q -d "$device" set 40% +} + # Light the locked display: first the lock's own wake, as a touch on the lock # screen would, so its blank timer runs again (patches/omarchy/0009), then the # display itself, because on tegu that wake reports ok without powering the @@ -106,11 +116,7 @@ wake_locked() { omarchy-brightness-display on & omarchy-shell lock wake >/dev/null 2>&1 wait - local device - device=$(omarchy-hw-display 2>/dev/null) - sleep 0.3 - [[ -n $device ]] || return 0 - [[ $(brightnessctl -d "$device" get 2>/dev/null || echo 1) -gt 0 ]] || brightnessctl -q -d "$device" set 40% + brightness_floor } # Light an unlocked but dark display (the lock didn't engage, or the panel @@ -118,12 +124,7 @@ wake_locked() { # panel. wake_unlocked() { omarchy-brightness-display on - local device - device=$(omarchy-hw-display 2>/dev/null) - sleep 0.3 - if [[ -n $device ]]; then - [[ $(brightnessctl -d "$device" get 2>/dev/null || echo 1) -gt 0 ]] || brightnessctl -q -d "$device" set 40% - fi + brightness_floor } # The panel is off when its backlight's bl_power says so (4), or when Hyprland @@ -359,11 +360,7 @@ wake_locked() { # without powering the panel back on, so always turn the display on too. omarchy-shell lock wake >/dev/null 2>&1 omarchy-brightness-display on - local device - device=$(omarchy-hw-display 2>/dev/null) - sleep 0.3 - [[ -n $device ]] || return 0 - [[ $(brightnessctl -d "$device" get 2>/dev/null || echo 1) -gt 0 ]] || brightnessctl -q -d "$device" set 40% + brightness_floor } long_press() { @@ -559,7 +556,20 @@ case "${1:-}" in # screen wakes; the lock ignores touches while dark (patches/omarchy/0029), # so this is the double tap's only wake, and it lights the panel too. screen_off || exit 0 - if locked; then wake_locked; else wake_unlocked; fi + if [[ $android_power != 1 ]]; then + if locked; then wake_locked; else wake_unlocked; fi + else + # The display is the slow part (about 0.25 s of modeset, then the + # panel's own 0.13 s on the Pixel 8 Pro), and the locked check and the + # lock's wake (about 0.1 s each, calls into the shell) don't depend on + # it: start the display first, run them beside it, then put the + # brightness floor back. + omarchy-brightness-display on & + display_pid=$! + if locked; then omarchy-shell lock wake >/dev/null 2>&1; fi + wait "$display_pid" + brightness_floor + fi ;; dark-unlocked) # omamobile-doubletap: the screen went dark while unlocked (an idle diff --git a/packages/omamobile-shell/test/keys.sh b/packages/omamobile-shell/test/keys.sh index 423812c37..a278dec45 100755 --- a/packages/omamobile-shell/test/keys.sh +++ b/packages/omamobile-shell/test/keys.sh @@ -70,7 +70,7 @@ STUB for tool in omarchy-brightness-display omarchy-system-lock omarchy-shell brightnessctl; do cat >"$t/bin/$tool" <>"$log" STUB @@ -216,6 +216,55 @@ grep -qE "omarchy-system-lock|lock dark|omamobile-sleepd" "$log" && fail "a doub [[ ! -e $t/run/omamobile-keys/power-wake ]] || fail "a double tap doesn't swallow the next power press" echo "ok - double tap: wakes a dark screen, locked or not, and leaves a lit one alone" +# The double tap's order. OMAMOBILE_POWER_KEY_ANDROID=1: the display starts +# first and the locked check and the lock's wake run beside it; off (the shared +# default, the Pixel 7 Pro), as before: the lock's wake, then the display. No +# clock: the display stand-in logs its start and then waits on a FIFO, which +# the test opens only after it has seen the lock's wake (or, with no lock +# wake, the display's start); with the switch on, the locked check waits (up to +# 10 s) for the display's start, so a display started after it shows as a wrong +# order, never as a race between two process starts. +mkdir -p "$t/orig2"; cp "$t/bin/omarchy-brightness-display" "$t/orig2/" +mkfifo "$t/display-go" +cat >"$t/bin/omarchy-brightness-display" <>"$log" +read -r _ <"$t/display-go" +echo "omarchy-brightness-display \$* done" >>"$log" +STUB +chmod +x "$t/bin/omarchy-brightness-display" +# tapq LINE: a double tap, letting the display finish once LINE is logged. +# The handler runs in its own process group (setsid), so a failed check can +# release the FIFO and kill the whole tree instead of leaving it blocked. +release() { timeout "$1" bash -c 'echo go >"$1"' _ "$t/display-go"; } +tapq_fail() { release 1 || true; kill -- -"$1" 2>/dev/null || true; fail "$2"; } +tapq() { + local k _ seen= + reset; setsid bash "$here/bin/omamobile-keys" double-tap & k=$! + for _ in $(seq 50); do grep -qxF -- "$1" "$log" && { seen=1; break; }; sleep 0.1; done + [[ $seen ]] || tapq_fail $k "double tap: no \"$1\" within 5 s (wrong order?)" + release 5 || tapq_fail $k "double tap: the display never waited" + for _ in $(seq 50); do kill -0 $k 2>/dev/null || break; sleep 0.1; done + kill -0 $k 2>/dev/null && tapq_fail $k "double tap: the handler didn't finish within 5 s" + wait $k +} +if [[ ${OMAMOBILE_POWER_KEY_ANDROID:-} == 1 ]]; then : >"$t/isLocked-waits"; fi +echo true >"$t/locked"; echo false >"$t/dpms" +tapq "omarchy-shell lock wake" +if [[ ${OMAMOBILE_POWER_KEY_ANDROID:-} == 1 ]]; then + before "omarchy-brightness-display on start" "omarchy-shell lock wake" || fail "double tap, as Android's: the display starts before the lock's wake" + before "omarchy-shell lock wake" "omarchy-brightness-display on done" || fail "double tap, as Android's: the lock's wake runs beside the display" +else + before "omarchy-shell lock wake" "omarchy-brightness-display on start" || fail "double tap, shared default: the lock's wake, then the display, as before" +fi +grep -qxF "omarchy-brightness-display on done" "$log" || fail "double tap, locked: the handler waits for the display" +echo false >"$t/locked"; echo false >"$t/dpms" +tapq "omarchy-brightness-display on start" +grep -qxF "omarchy-brightness-display on done" "$log" || fail "double tap, unlocked: the handler waits for the display" +grep -q "omarchy-shell lock wake" "$log" && fail "double tap, unlocked: still no lock wake" +rm -f "$t/isLocked-waits" "$t/display-go"; cp "$t/orig2/omarchy-brightness-display" "$t/bin/" +echo "ok - double tap: the display first as Android's, the lock's wake first otherwise" + # The screen gone dark while unlocked (omamobile-doubletap tells): it locks, # and the new lock hears it is dark, so a touch on the dark screen reaches # the lock, never the app under it. Lit, or already locked: nothing.