diff --git a/packages/omamobile-shell/bin/omamobile-sleepd b/packages/omamobile-shell/bin/omamobile-sleepd index 41b29831d..930f4368e 100755 --- a/packages/omamobile-shell/bin/omamobile-sleepd +++ b/packages/omamobile-shell/bin/omamobile-sleepd @@ -16,8 +16,9 @@ # and the sleep hook apply) once the screen has been off and the lock secure # for OMAMOBILE_SLEEP_AFTER_OFF seconds (30), and again OMAMOBILE_SLEEP_GRACE # seconds (5) after a dark resume: a wake that left the screen off (an alarm, -# the RTC, Bluetooth, the fuel gauge, a volume key). A power-key wake lights -# the PIN pad (omamobile-keys wake, from here), and a lit screen never sleeps. +# the RTC, Bluetooth, the fuel gauge, a volume key). A power-key or a touch +# wake lights the PIN pad (omamobile-keys wake, from here), and a lit screen +# never sleeps. # # Never while: # - the toggle is off, the screen is on, or the lock isn't secure; @@ -117,6 +118,31 @@ wake_reason() { echo "IRQ $irq:${name:- (unknown)}" } +# The touchscreen's interrupt, as /proc/interrupts names it: the driver +# requests it under its device's name (the SPI or I2C device, "spi3.0"), so +# find the input device that is a direct touch surface (INPUT_PROP_DIRECT) +# with a parent device, and take that parent's name. A virtual input device +# (uinput, a test tool) has no `device` link and is skipped, so it can't +# mask the real touchscreen. Empty when there is none. +touch_irq_name() { + local d props + for d in "$sys"/class/input/input*; do + props=$(cat "$d/properties" 2>/dev/null) || continue + (( (0x${props:-0} & 0x2) )) || continue + [[ -e $d/device ]] || continue + basename "$(readlink -f "$d/device")" + return 0 + done + return 1 +} + +# A touch woke the phone: the wake IRQ is the touchscreen's. +touch_woke() { + local name + name=$(touch_irq_name) || return 1 + [[ -n $name && $1 == *" $name" ]] +} + request() { log "sleeping ($1)" # The lock goes back to its glance view before the freeze, for a screen @@ -155,10 +181,19 @@ watch() { # The press that woke the phone never reaches Hyprland's binds: the # session is frozen while the kernel takes it. Light the PIN pad here, # as that press would have (omamobile-keys ignores the press itself if - # it does arrive, so the screen doesn't go straight back off). - if [[ $woke == *KEY_POWER* ]] && command -v omamobile-keys >/dev/null; then - log "a power-key wake: lighting the lock screen" - omamobile-keys wake >/dev/null 2>&1 & + # it does arrive, so the screen doesn't go straight back off). A touch + # wake is the same: Hyprland's DPMS state and the panel's backlight + # power stay as the sleep left them unless the lock is lit through + # omamobile-keys, and on tegu that left a lit lock screen that Hyprland + # read as dark and whose panel refused the fingerprint circle. + if command -v omamobile-keys >/dev/null; then + if [[ $woke == *KEY_POWER* ]]; then + log "a power-key wake: lighting the lock screen" + omamobile-keys wake >/dev/null 2>&1 & + elif touch_woke "$woke"; then + log "a touch wake: lighting the lock screen" + omamobile-keys wake >/dev/null 2>&1 & + fi fi # Any wake that leaves the screen off and locked is dark: back to # sleep after the grace. A power-key wake lights the screen and diff --git a/packages/omamobile-shell/test/sleepd.sh b/packages/omamobile-shell/test/sleepd.sh index 6369fddb2..fe15bd53e 100755 --- a/packages/omamobile-shell/test/sleepd.sh +++ b/packages/omamobile-shell/test/sleepd.sh @@ -124,6 +124,23 @@ grep -c '^omamobile-keys' "$t/log" >/dev/null && fail "an RTC wake doesn't light reset; echo 111 >"$t/wake_irq"; printf 'echo 0 >"%s"; echo true >"%s"\n' "$t/sys/class/backlight/panel/bl_power" "$t/dpms" >"$t/on_resume"; watch 700 grep -c '^omamobile-keys wake' "$t/log" >/dev/null || fail "a power-key wake asks omamobile-keys to light the PIN pad" grep -c 'a power-key wake: lighting the lock screen' "$t/out" >/dev/null || fail "the power-key wake is logged" +# A touch woke it: the touchscreen's interrupt carries its device's name +# (the input device with INPUT_PROP_DIRECT, parent "spi3.0"), and the lock +# is lit the same way; Hyprland's DPMS state and bl_power would otherwise +# stay as the sleep left them. +reset; mkdir -p "$t/sys/class/input/input0" "$t/sys/devices/spi3.0"; echo 2 >"$t/sys/class/input/input0/properties"; ln -sfn "$t/sys/devices/spi3.0" "$t/sys/class/input/input0/device" +printf ' 73: 12 0 gpa7 6 Edge spi3.0\n' >>"$t/proc/interrupts" +echo 73 >"$t/wake_irq"; printf 'echo 0 >"%s"; echo true >"%s"\n' "$t/sys/class/backlight/panel/bl_power" "$t/dpms" >"$t/on_resume"; watch 700 +grep -c '^omamobile-keys wake' "$t/log" >/dev/null || fail "a touch wake asks omamobile-keys to light the PIN pad" +grep -c 'a touch wake: lighting the lock screen' "$t/out" >/dev/null || fail "the touch wake is logged" +# The same interrupt line with no touchscreen among the input devices is a dark resume. +reset; rm -rf "$t/sys/class/input"; printf ' 73: 12 0 gpa7 6 Edge spi3.0\n' >>"$t/proc/interrupts"; echo 73 >"$t/wake_irq"; watch 700 +grep -c '^omamobile-keys' "$t/log" >/dev/null && fail "an unknown wake doesn't light the screen" +# A virtual direct-touch device (no `device` link, as uinput makes) listed +# before the real one must not mask it: the real touchscreen's name is used. +reset; mkdir -p "$t/sys/class/input/input0" "$t/sys/class/input/input1" "$t/sys/devices/spi3.0"; echo 2 >"$t/sys/class/input/input0/properties"; echo 2 >"$t/sys/class/input/input1/properties"; ln -sfn "$t/sys/devices/spi3.0" "$t/sys/class/input/input1/device" +printf ' 73: 12 0 gpa7 6 Edge spi3.0\n' >>"$t/proc/interrupts"; echo 73 >"$t/wake_irq"; printf 'echo 0 >"%s"; echo true >"%s"\n' "$t/sys/class/backlight/panel/bl_power" "$t/dpms" >"$t/on_resume"; watch 700 +grep -c 'a touch wake: lighting the lock screen' "$t/out" >/dev/null || fail "a virtual touch device without a parent doesn't mask the real touchscreen" # A failed suspend is logged and retried no sooner than 30 s later. reset fake systemctl 'echo "systemctl $* at $(cat "$T/clock")" >>"$T/log" diff --git a/packages/omamobile-shell/version b/packages/omamobile-shell/version index 16c9e92a2..614610503 100644 --- a/packages/omamobile-shell/version +++ b/packages/omamobile-shell/version @@ -1 +1 @@ -0.2.45 +0.2.46