Skip to content

lock: give the password field its focus back after a resume - #15677

Open
AnPod wants to merge 1 commit into
omacom:quattrofrom
AnPod:fix/lock-resume-password-focus
Open

AnPod wants to merge 1 commit into
omacom:quattrofrom
AnPod:fix/lock-resume-password-focus

Conversation

@AnPod

@AnPod AnPod commented Oct 16, 2026

Copy link
Copy Markdown
Contributor

Fixes #15673

Problem

After a suspend, the lock screen's password field no longer accepts keyboard input until it is clicked. LockView requests focus only at creation and when inputEnabled flips; Omarchy's sleep helper waits for the lock to become secure before suspending, so the compositor's suspend/resume transition happens after that request and no later event restores focus.

Fix

The lock service already notices a resume as the wall clock jumping under a repeating timer (fingerprintSleepWatch via FingerprintModel.spannedSleep). A sibling passwordFocusSleepWatch timer inside the WlSessionLockSurface uses the same detection while the lock holds the session and calls lockView.forcePasswordFocus() on the jump — refocusing an enabled field only, and never while a password PAM conversation is in flight. It lives inside the surface, so it is destroyed with it and keeps no timer ticking for an open session.

Test

New test/shell.d/lock-resume-focus-test.sh (auto-discovered by test/shell):

  • fails on clean quattro (verified via git stash) and passes with the change
  • asserts the watch refocuses the field on a spanned sleep, runs only while lockRequested, gates on inputEnabled && !authenticatingPassword, and is owned by the lock surface

Related lock tests all pass: lock-blank-fingerprint, lock-autorepeat, lock-fingerprint-service, lock-fingerprint-retry, lock-password-overflow, lock-stranded-recovery, apply-lock, and lock-appear-budget (one cold-start budget flake reproduced neither on clean quattro re-runs nor on three re-runs with the change).

A suspend between the lock's focus request and the compositor's keyboard
grab can drop the password field's focus, and nothing after the resume
asks for it back: the lock surface stays shown across the sleep, so
neither completion nor inputEnabled re-runs and typing does nothing
until the field is clicked (omacom#15673).

The lock already notices a resume as the wall clock jumping under a
repeating timer (the fingerprint sleep watch); a sibling watch does the
same while the lock holds the session and refocuses the field, staying
out of the way of a password check in flight.
@greptile-apps

greptile-apps Bot commented Oct 16, 2026 •

Copy link
Copy Markdown
Contributor

RetriggerView in GreptileConfidence Score: 4/5

[Medium impact] The change affects the lock-screen resume and password-entry flow.

The change appears safe to merge, with a non-blocking gap in the new regression test.

Findings

  1. P2 Broken timer still passes tests ▶

Summary

Adds passwordFocusSleepWatch inside the lock surface to restore password focus after a detected sleep.

  • The lock screen restores password-field focus after a resume.

Reviews (1) · Last reviewed commit: "lock: give the password field its focus ..." · Reviewed by Greptile

Comment on lines +17 to +20
assert(
/Timer\s*\{\s*id: passwordFocusSleepWatch[\s\S]*?spannedSleep\(now - lastTickMs, interval\)[\s\S]*?lockView\.forcePasswordFocus\(\)/.test(serviceQml),
'a sleep watch refocuses the password field after a resume'
)

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

P2 Broken timer still passes tests

The new test checks source text but never checks what the timer does. Removing repeat: true, replacing lastTickMs = now with lastTickMs = 0, or making slept always false would still pass every assertion. These changes would stop resume detection or repeatedly force focus without a resume.

Add a behavior check that feeds ordinary ticks and a sleep gap through the timer logic, then checks focus calls and both guards.

@omarchybot

Copy link
Copy Markdown
Collaborator

Thanks for this. I've read it but haven't reviewed it yet. I read it as a bug fix for #15673, but every item here gets its classification and review checked by a second model, and today's budget for that second opinion (Codex Medium) is used up, so the classification isn't settled yet. Until it is, I haven't labelled it and haven't run anything on a worker. The full review comes once the second opinion is available: a reproduction on a worker that fails on quattro and passes on this head, the shell suite, and a second-opinion review. For now it's waiting on the maintainer to send it round again, and nothing is needed from you.

@LeoMrel

LeoMrel commented Oct 21, 2026

Copy link
Copy Markdown

Confirming the root cause and the fix on Omarchy 7.2.8 (Hyprland, ASUS laptop, clamshell + external HDMI monitor, also reproduced with the lid open). After a real suspend/resume the password field isn't focused until clicked.

A local patch equivalent to this PR (a repeating 1s Timer inside WlSessionLockSurface that detects a wall-clock jump, same trick as idleBlankTimer, and calls lockView.forcePasswordFocus() plus a retry 600 ms later, skipped while a password check is in flight) makes the field focused right after resume with no click. I haven't tested this PR's exact code, only that approach.

Possibly useful for the review: PR #12435 takes another approach (re-grabbing focus whenever the window's active focus item is cleared), which would also cover the case where the devices are re-added without a detectable clock jump.

@mudiam

mudiam commented Oct 21, 2026

Copy link
Copy Markdown

Tested on real hardware with lid-close S3 suspends, and it fixes the bug here. One disclosure first: this was a backport to Omarchy 4.0.6, not quattro.

Machine: Lenovo ThinkPad P17 Gen 1, built-in keyboard (AT Translated Set 2 keyboard), NVIDIA Quadro T1000 only (nvidia-open-dkms 615.78.08), S3 deep. Omarchy 4.0.6-1, Hyprland 0.56.2-4, quickshell 0.3.2.r7.g2b4501a-1, qt6-base 6.12.0-3. This machine has the trigger: Hyprland logs the keyboard as device removed on every suspend (13 of 13 this boot).

Backport: the Service.qml hunk applied to the shipped 4.0.6 file at the right spot (inside WlSessionLockSurface, right after LockView). However, 4.0.6 has no FingerprintModel.js, so for the test I replaced FingerprintModel.spannedSleep(now - lastTickMs, interval) with its body inline: (now - lastTickMs) > interval + 2000 (SLEEP_GAP_MS = 2000 at ac115f9). The behaviour is identical, and nothing else changed. No QML errors were logged across the test. test/shell.d/lock-resume-focus-test.sh passes 3/3 on the PR head.

Isolation: earlier the same day I had #12435 installed on this machine (comment there). For this test I restored the stock 4.0.6 LockView.qml, so only this PR's timer could restore focus.

Same boot, same procedure (lid close → open → type password without clicking) Result
Stock 4.0.6 (baseline) 2/2 fail: keystrokes don't reach the field until a click
This PR (backported, #12435 removed) 2/2 pass: characters appear, unlocks. Sleeps were ~25 min and ~1.5 min.

The lock was secured before each suspend (secure=true ~0.6 s after lid close). Typing started a few seconds after lid-open.

For whoever picks between this and #12435 (same bug, #12525/#15673): both fix it on this machine, tested in isolation on the same boot. This PR refocuses on the first 1 s tick after the clock jump, which is probably before the keyboard's re-add (roughly 3 s after resume on a machine like this). It still worked here, so in practice the early forcePasswordFocus() seems to survive the keyboard capability drop/re-add on Qt 6.12. I didn't instrument the exact ordering, so I'm reporting that as observed, not as proven.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Lock screen password field loses keyboard focus after suspend

4 participants