diff --git a/shell/plugins/lock/Service.qml b/shell/plugins/lock/Service.qml index a02708e05fde..118af08730d0 100644 --- a/shell/plugins/lock/Service.qml +++ b/shell/plugins/lock/Service.qml @@ -222,6 +222,7 @@ Item { resetAuthenticationState() lockRequested = true + idleBlankTimer.blanked = false armBlankTimer() logEvent("lock-requested") queueSessionLock() @@ -243,20 +244,35 @@ Item { pendingSessionLockTimer.stop() resetAuthenticationState() idleBlankTimer.stop() + idleBlankTimer.blanked = false sessionLock.locked = false logEvent("unlocked") runWake() } function armBlankTimer(delayMs) { - idleBlankTimer.interval = delayMs || idleBlankTimer.idleMs + var want = delayMs || idleBlankTimer.idleMs + // A longer pending countdown is never cut short: wake input right after + // a blank, and the output re-detection right after a resume, must not + // reset those longer graces to the idle run-up while more than the + // run-up is left. Once less of a grace remains than a run-up takes, an + // ordinary arm refreshes the countdown as before. + if (idleBlankTimer.running && idleBlankTimer.armedAt + idleBlankTimer.interval - Date.now() > want) return + idleBlankTimer.interval = want idleBlankTimer.armedAt = Date.now() idleBlankTimer.restart() } function runWake() { if (!wakeProcess.running) wakeProcess.running = true - if (lockRequested) armBlankTimer() + if (lockRequested) { + if (idleBlankTimer.blanked) { + idleBlankTimer.blanked = false + armBlankTimer(idleBlankTimer.wakeMs) + } else { + armBlankTimer() + } + } resumeFingerprint() nudgeFingerprint() } @@ -349,6 +365,7 @@ Item { } function runBlank() { + idleBlankTimer.blanked = true pauseFingerprint() if (!blankProcess.running) blankProcess.running = true } @@ -771,6 +788,10 @@ Item { // panel lights (on NVIDIA it waits out a VT switch and a modeset), so the // idle run-up blanked the lock just as it appeared. readonly property int resumeMs: 15000 + // Displays take seconds to light after DPMS off, so the first wake after a + // blank gets a longer grace before the idle countdown reblanks. + readonly property int wakeMs: 15000 + property bool blanked: false interval: idleMs repeat: false property double armedAt: 0 diff --git a/test/shell.d/fixtures/lock-fingerprint-service/shell.qml b/test/shell.d/fixtures/lock-fingerprint-service/shell.qml index 0580f4e8e74b..d1d12af0ccd3 100644 --- a/test/shell.d/fixtures/lock-fingerprint-service/shell.qml +++ b/test/shell.d/fixtures/lock-fingerprint-service/shell.qml @@ -237,6 +237,55 @@ ShellRoot { check(!service.fingerprintPaused, "unlock reset clears a pause so the next lock starts the reader") service.applyFingerprintProbe("Daemon is restarting") check(!recheck.running, "an unknown probe outside the lock cannot restart it") + + // First wake after blank grants a longer grace so the user can type + // before reblanking; bursts of wake input preserve that countdown. Move + // the armed countdown back 7s so the burst reads as seconds after the + // first wake even though both run inside the same wall-clock + // millisecond: a burst that reset or re-granted the countdown would + // move its deadline and fail the exact match. + service.lockRequested = true + service.runBlank() + service.runWake() + check(blankTimer.interval === 15000, "first wake after a blank arms the longer grace") + blankTimer.armedAt -= 7000 + var initialDeadline = blankTimer.armedAt + blankTimer.interval + blankTimer.stop() + + blankTimer.start() + service.runWake() + service.runWake() + check(blankTimer.interval === 15000 && blankTimer.armedAt + blankTimer.interval === initialDeadline, + "burst of wake inputs preserves the long grace deadline") + + blankTimer.armedAt = Date.now() - 11000 + service.runWake() + check(blankTimer.interval === 5000, "wake input once less than 5s of the grace remains re-arms the normal 5s interval") + blankTimer.stop() + service.runWake() + check(blankTimer.interval === 5000, "input ending a password check arms the normal 5s run-up even with grace left over") + + // A resume arms the same longer countdown, through the blank timer's + // own suspend-gap check; the wake paths that fire within a second of + // the resume must not reset it to the idle run-up. + blankTimer.interval = 5000 + blankTimer.armedAt = Date.now() - 60000 + blankTimer.start() + blankTimer.triggered() + check(blankTimer.interval === 15000, "a countdown frozen by suspend re-arms the resume grace instead of blanking") + service.armBlankTimer() + check(blankTimer.interval === 15000, "an output re-detection right after a resume keeps the resume grace") + service.runWake() + check(blankTimer.interval === 15000, "a wake burst right after a resume keeps the resume grace") + blankTimer.armedAt = Date.now() - 11000 + service.runWake() + check(blankTimer.interval === 5000, "input once the resume grace is mostly spent re-arms the normal 5s interval") + blankTimer.stop() + + service.runBlank() + service.runWake() + check(blankTimer.interval === 15000, "wake after blanking again arms the longer grace") + blankTimer.stop() } finally { service.lockRequested = false service.resetAuthenticationState() diff --git a/test/shell.d/lock-fingerprint-service-test.sh b/test/shell.d/lock-fingerprint-service-test.sh index fb020eece385..edf09ab5fffb 100644 --- a/test/shell.d/lock-fingerprint-service-test.sh +++ b/test/shell.d/lock-fingerprint-service-test.sh @@ -2,8 +2,17 @@ set -euo pipefail +# shellcheck disable=SC1091 source "$(cd -- "$(dirname -- "${BASH_SOURCE[0]}")" && pwd)/base-test.sh" require_quickshell "lock fingerprint service test" +qml_fixture_scratch +printf '#!/bin/bash\nexit 0\n' >"$QML_FIXTURE_TMP/bin/omarchy-system-wake" +printf '#!/bin/bash\nexit 0\n' >"$QML_FIXTURE_TMP/bin/omarchy-brightness-display" +printf '#!/bin/bash\nexit 0\n' >"$QML_FIXTURE_TMP/bin/omarchy-brightness-keyboard" +chmod +x "$QML_FIXTURE_TMP/bin/omarchy-system-wake" \ + "$QML_FIXTURE_TMP/bin/omarchy-brightness-display" \ + "$QML_FIXTURE_TMP/bin/omarchy-brightness-keyboard" + run_qml_fixture lock-fingerprint-service "fingerprint service handles enrollment, failures and recovery" Ui Commons