Skip to content

Reclaim lock screen keyboard focus after resume from suspend - #12435

Open
jonathan-downs wants to merge 1 commit into
omacom:quattrofrom
jonathan-downs:fix-lock-focus-after-resume
Open

jonathan-downs wants to merge 1 commit into
omacom:quattrofrom
jonathan-downs:fix-lock-focus-after-resume

Conversation

@jonathan-downs

@jonathan-downs jonathan-downs commented Sep 18, 2026 •

Copy link
Copy Markdown

Summary

After lid-close suspend and resume, the lock screen shows the password field, but typing does nothing until the screen is clicked. A plain lock with no suspend is unaffected.

Root cause. The field loses focus inside Qt; the compositor side is fine:

  1. On this hardware, every suspend removes and re-adds all input devices. The Hyprland log shows a device removed line for each one, and 18 keyboard adds across 17 suspends in one boot.
  2. With no keyboards left, the seat drops its keyboard capability, and Qt destroys its wl_keyboard. Qt's destructor clears the application's focus window directly (qwaylandinputdevice.cpp), so QQuickWindow::focusOutEvent clears the password field's focus.
  3. When the keyboards come back, Qt binds a new wl_keyboard, and Hyprland sends enter for the lock surface that is still focused (Seat.cpp). But QWaylandDisplay::handleKeyboardFocusChanged still records that surface as the last keyboard focus and returns early (qwaylanddisplay.cpp). The window is never re-activated: keys reach it, but no item has focus to receive them.
  4. A click works because forceActiveFocus() is honoured while no window has focus (qquickdeliveryagent.cpp).

Fix. LockView takes focus back whenever its window's active focus item is cleared while input is enabled. That is the exact state the bug leaves behind, so no resume detection is needed. It should also cover other ways every keyboard can disappear while locked, such as unplugging a desktop's only USB keyboard (untested). When another lock surface has focus, forceActiveFocus() only records the field as its window's focus item, so focus never moves between monitors.

Changes from the earlier version of this PR. That version watched logind's PrepareForSleep through a new systemd user service and poked the shell over IPC on each resume. It worked because the IPC call ran the same forceActiveFocus() a click does, but it tied the fix to resume events instead of the focus loss itself. It also added a script, a unit, an IPC verb and a second dbus-monitor, and without a migration it would never have been enabled on existing installs. All of that is gone.

Related

Test plan

  • New test/shell.d/lock-focus-reclaim-test.sh: drops the lock window's focus the way QQuickWindow::focusOutEvent does and checks that the password field takes it back. It also checks that the preview view (input disabled) never takes focus, and that focus returns after a password check disables and re-enables the field. It fails without the fix and passes with it.
  • Existing lock tests pass: lock-password-overflow, lock-fingerprint-indicator, lock-blank-fingerprint, lock-stranded-recovery, video-background, owe-integration
  • ./test/cli passes
  • ./test/shell passes except for 5 files that fail identically on a clean quattro checkout on this machine, because it lacks an omarchy-pkgs checkout and omasnap: config, kernel-headers-migration, screenshot-sanity, snapper, unowned-system-paths
  • Running locally as a clone of the lock plugin on Omarchy 4.0.2: lock and unlock by password work
  • Lid-close suspend on real hardware, reopen, type the password without clicking: the field accepts it without a click once the keyboard is back. On this laptop input devices return about 3 seconds after the lid opens, after the display restore, so earlier keystrokes never reach any client.

🤖 Generated with Claude Code

Fixes #12525

Fixes #14067

@RenanBezerraGuima

Copy link
Copy Markdown

Tested this on my machine and it fixes the issue: after suspend/resume the lock screen password field accepts typing immediately, no click on the screen needed first. Suspend via lid close, resume, type password — works on the first try. Thanks for tracking this down.

@chessing234

Copy link
Copy Markdown
Contributor

hey, this is already covered in #12894 (lock keyboard focus after lid-open / resume). mind closing this as a duplicate?

Suspend can remove every keyboard. When the seat loses its keyboard, Qt's
Wayland backend drops its focus window, which clears the password field's
focus. When the keyboard comes back, the compositor re-enters the lock
surface, but Qt still records that surface as focused and never
re-activates the window, so typing is dropped until the screen is clicked.

Take focus back as soon as the lock window's focus item is cleared. Qt
only turns that into active focus while no other window has focus, so it
cannot pull focus away from another monitor's lock surface.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
@evulz

evulz commented Sep 30, 2026 •

Copy link
Copy Markdown

Hitting this on every resume here too. Data point in case it helps review:

Setup: Omarchy 4.0.4, Hyprland 0.56.2, Quickshell 0.3.1, kernel 7.2.5-3-omarchy, Razer Blade 15 (2022), Intel iGPU driving the internal panel + NVIDIA dGPU (open 610.57.04).

Repro: lock screen comes up before sleep (lid close). Happens after both deep (S3) suspend and hibernate. After resume the field looks ready, but typing does nothing until the field is clicked.

What I tried from outside the lock surface after PrepareForSleep(false), 1–4 s after resume, while lock isLocked returned true:

  • Moving the pointer via hl.dsp.cursor.move did not help.
  • A synthetic left click via wlrctl pointer click left (virtual pointer) did not help either. Only a physical click works.

That points at the Qt side, as this PR describes: the compositor-level focus looks fine, and the window's focus item just never comes back. It would be great to see this merged.


This comment was written by Claude Code (Anthropic's AI assistant) while it helped me debug this on my machine. The tests and log results above are from my system.

@omarchybot omarchybot added the verified Omarchy Triage has verified that this issue is ready for final review label Oct 1, 2026
@omarchybot

Copy link
Copy Markdown
Collaborator

Reviewed at 21025d3 by Claude Opus 5.5 in Claude Code, with a second opinion from Codex at medium effort. Neither found a defect in the change, and it now carries verified.

Reproduced on a worker. On a disposable VM with a real compositor serving this branch, lock-focus-reclaim-test.sh fails against the base LockView.qml (with only the objectName hook added) and with the new handler removed: the field does not take focus back after the window loses it. It passes on this branch. A VM cannot suspend, so the suspend itself was not reproduced. That suspend causes this state rests on the QtWayland chain in the description and on the before-and-after reports from you, @RenanBezerraGuima and @evulz. Locking the worker's real session with this tree loaded reached the locked state, and the shell used no CPU over the next 10 seconds, so the handler does not spin.

Tests. On the same worker: ./test/cli passed. The full ./test/shell suite was not green: 49 failures on this branch and 49 on its base, almost all because the worker has no node. lock-blank-fingerprint, lock-stranded-recovery and video-background are among them, and fail the same way on the base. lock-fingerprint-indicator, lock-password-overflow, sleep-lock, system-lock and owe-integration pass. The branch merges cleanly into current quattro, which still has no focus recovery in LockView.qml. CI reports no checks on this branch.

Competing fixes. #8560, #7592, #10944 and #7164 are open against the same bug. #8560 does the same repair from the password field's onActiveFocusChanged, and it also reacts when the field is disabled for a password check or when focus moves to another item in the window. This one acts only when the window is left with no focus item at all, and its test checks the behaviour where #8560's matches the source text. #7592 polls every 100 ms while the field lacks focus, which keeps firing on every monitor whose lock surface does not hold the keyboard. #7164 only acts when the lock becomes secure, which does not happen again on resume. Asked separately to rank them, Codex also chose this one, though its independence is not guaranteed because it can read this session's notes. It treated #8560 as equivalent for the suspend case. #12894, raised above as a duplicate, is closed, and it targeted the clamshell reload path. I have linked #12525, which reports exactly this symptom.

Where it stands. Waiting on the maintainer, who has to choose between this and #8560. Nothing is left for you to do. It is not ready: that also needs the full suite green on a worker and a green CI run.

@jandrusk

Copy link
Copy Markdown

Still needed — #12894 was closed without merge, so this isn't covered yet.

Same resume/lock-focus cluster as #9180 / #14882 / #13907 / #10944 / #8560 / #6858. This head has a focused reclaim + test and omarchybot verified it; merge is clean. Suggest picking one implementation from the cluster and closing the rest.

@mudiam

mudiam commented Oct 21, 2026

Copy link
Copy Markdown

Tested on real hardware with a before/after comparison on the same boot. It fixes the bug here, including on Qt 6.12 (the analysis above was against 6.11.2).

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, qt6-declarative 6.12.0-1, qt6-wayland 6.12.0-1.

Trigger confirmed: the Hyprland log shows AT Translated Set 2 keyboard: device removed once per suspend (9 of 9 this boot), along with the other 7 input devices. That matches step 1 of the root cause.

Setup: the PR's LockView.qml hunk applied cleanly with patch to the shipped 4.0.6 file (+10 lines, offset only), installed over /usr/share/omarchy/shell/plugins/lock/LockView.qml, then omarchy-restart-shell. No QML warnings from the lock plugin on load. test/shell.d/lock-focus-reclaim-test.sh at 21025d3 passes with the fix and fails with the new block removed (password field takes focus back after the window loses it, got none).

4.0.6 as shipped With this PR
Lid-close suspend → open → type password without clicking 2/2 fail: keys don't reach the field; a click is needed 2/2 pass: characters appear and it unlocks
Plain idle lock (no suspend), ~31 min, then type — pass
Lock secured before suspend yes yes (secure=true ~0.6s after lid close)

The PR cycles covered a short (~27s) and a long (~22 min) sleep. Typing was done a few seconds after lid-open, once input was back.

Not tested: multi-monitor (single internal panel here), fingerprint (no reader enrolled), and #12438's numpad state.

@manuaudio

Copy link
Copy Markdown
Contributor

@celestial-fix added another matching real-hardware trace on #14067: Dell Inspiron, s2idle, secure lock surface, no PAM conversation before the click, and the keyboard is removed and re-added across the seat transition while pointer input still works. Full evidence: #14067 (comment)

One useful addition is that a locked VT round-trip produced the same symptom. That may be a cheaper way to exercise this focus-loss path than a lid-close suspend. They have not isolated that trigger yet, so I would treat it as a reproduction lead rather than confirmed coverage.

@manuaudio

Copy link
Copy Markdown
Contributor

@celestial-fix has now tested this PR on the Dell Inspiron from #14067. With the patched lock plugin applied, lid-close suspend and resume accepted password input immediately without a click and unlocked normally. That moves their earlier trace from a matching reproduction to direct real-hardware confirmation of this fix. Full result: #14067 (comment)

@omarchybot omarchybot removed the verified Omarchy Triage has verified that this issue is ready for final review label Nov 3, 2026
@theswampdawg

Copy link
Copy Markdown

Adding an archived VM before/after result for 21025d3, tested on 2026-10-24. It confirms that a locked VT round trip can exercise this path without suspending the VM.

Stack: Omarchy 4.0.6-1, packaged Hyprland 0.56.2-4, Quickshell 0.3.2.r7.g2b4501a-1, qt6-base 6.12.0-3, qt6-wayland 6.12.0-1, UWSM 0.27.1-1, QEMU/KVM, one output.

The native-lock sequence was:

  1. Lock, wait for compositor secure=true, then authenticate with the native PAM password. This control passed.
  2. Lock again, confirm secure state, visit an unused text VT, return, and type the same password without clicking.
  3. With shipped LockView.qml, input did not reach native PAM and the session remained securely locked.
  4. With this PR's ten-line LockView.qml hunk and the original packaged Hyprland binary restored, both the initial native authentication and the authentication after VT return passed. No debugger or synthetic focus window was involved in that passing run.

An ordinary FloatingWindow/TextInput control passed across the same kind of VT round trip even when the native lock failed, so a generic text-input fixture would have missed this regression.

This is corroboration for the native lock fix. A separate retained-SDDM-greeter/direct-VT input problem remained unresolved in the wider multi-user experiment. Physical multiple monitors and fingerprint hardware were not tested, and this is not a complete aggregate-suite signoff. The VM experiment has now ended.

@manuaudio

Copy link
Copy Markdown
Contributor

@theswampdawg Thanks for preserving this. The controlled shipped-versus-21025d3 result turns the VT round trip from the reproduction lead I mentioned above into a confirmed way to exercise this focus-loss path without suspend. The native lock detail matters too: your FloatingWindow/TextInput control shows why a generic text-input fixture would not have proved this fix.

@omarchybot

Copy link
Copy Markdown
Collaborator

Re-checked at 21025d3 by Claude Opus 5.5 in Claude Code, with second opinions from Codex at medium effort and muse-wonder via pi at high thinking. The branch no longer merges into quattro: shell/plugins/lock/LockView.qml conflicts with #17277 (1843592), which the maintainer merged on November 1. That is why verified came off.

quattro already fixes the reported bug. #17277 adds Window.onActiveFocusItemChanged: Qt.callLater(restorePasswordFocus), which hands focus back to the field when the window's focus item is cleared. That is the same signal this PR uses, for the same cause, which #17277 traced through an NVIDIA VT switch. Both reviewers agree it covers lid-close resume with the field idle, and the result below shows it.

This PR still covers one case quattro misses. Codex raised it and a worker confirmed it: if the window loses focus while a password check is running, the field never gets focus back on quattro. restorePasswordFocus does nothing while the field is disabled. Once the check ends, no focus change fires to try again, so after a failed password the field again needs a click. This handler calls forceActiveFocus() even while the field is disabled. That puts focus back on the window, so the field picks it up when the check ends. In practice this means a wrong password followed by closing the lid, or a VT switch, before the check finishes.

What ran. On a disposable VM with a real compositor, I put your lock-focus-reclaim test and the lockPasswordInput hook on current quattro (3b36b9e). I added one step to the fixture: start a check, drop the window's focus, end the check. Results:

Nothing was pushed to your branch, and the suite was not run on it, because it does not merge.

What else is still open. #8560, #10944 and #7164 are still open against the same bug. Apart from the password-check case, this PR now adds only the regression test. The reviewers noted three things about that test. Its preview and password-check steps pass whichever handler is present, so they do not check the handler. It uses its own launcher where quattro's base-test.sh now has run_qml_fixture. And the repository's AGENTS.md asks for an existing lock test to be extended rather than a new file added.

Waiting on the maintainer. They need to decide whether the password-check case and the test are worth keeping on top of #17277. If they are, resolving the conflict means choosing how this handler and #17277's fit together. Otherwise this can be closed as fixed by #17277. Nothing is needed from you until then.

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

Labels

bug Something isn't working

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Lock screen ignores keyboard after lid close/resume until clicked [Bug] Password input field is not focused on lock screen after suspend/wake

9 participants