Skip to content

Fix password field losing autofocus on lock screen - #7164

Open
nickav wants to merge 5 commits into
omacom:quattrofrom
nickav:fix/lock-password-autofocus
Open

nickav wants to merge 5 commits into
omacom:quattrofrom
nickav:fix/lock-password-autofocus

Conversation

@nickav

@nickav nickav commented Aug 16, 2026

Copy link
Copy Markdown

I noticed that sometimes on the password screen when I type my input does not go into the password field.

According to Claude:

forcePasswordFocus() was only triggered by inputEnabled toggling true, which fires before the compositor grants the session lock surface exclusive keyboard focus. Also force focus once WlSessionLock reports secure=true, when focus is actually available.

forcePasswordFocus() was only triggered by inputEnabled toggling true,
which fires before the compositor grants the session lock surface
exclusive keyboard focus. Also force focus once WlSessionLock reports
secure=true, when focus is actually available.
Copilot AI balanced review requested due to automatic review settings August 16, 2026 17:40

Copilot AI left a comment

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.

Pull request overview

Note

Copilot was unable to run its full agentic suite in this review.

Adds a deferred focus action during session lock activation to ensure the password input is focused after starting fingerprint handling.

Changes:

  • Schedule lockView.forcePasswordFocus via Qt.callLater() after root.startFingerprint().

💡 Add a code-review agent skill or configure MCP servers for context-aware, tailored reviews. Learn more in the docs.

Comment thread shell/plugins/lock/Service.qml Resolved
Co-authored-by: Copilot Autofix powered by AI <175728472+Copilot@users.noreply.github.com>
Copilot AI review requested due to automatic review settings August 16, 2026 17:42

Copilot AI left a comment

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.

Pull request overview

Copilot reviewed 1 out of 1 changed files in this pull request and generated no new comments.

Suppressed comments (1)

shell/plugins/lock/Service.qml:242

  • Because Qt.callLater() defers execution, lockView may no longer be in a valid state by the time this runs (e.g., lock view gets torn down quickly or replaced). Consider guarding the call (e.g., ensure lockView is still the active/visible lock view before focusing), or using a cancelable Timer tied to the view’s lifecycle so you don’t attempt to focus a stale object.
        Qt.callLater(function() { lockView.forcePasswordFocus() })

@pjover

pjover commented Aug 18, 2026

Copy link
Copy Markdown

This fix hooks forcePasswordFocus() to onSecureStateChanged, which covers the initial lock. There is a second path it won't reach: the lock surfaces being rebuilt while already locked, which happens on resume when the output set changes.

Reproduction — ThinkPad docked to an external display, lid closed (Omarchy 4.0.0, Hyprland 0.56.2, quickshell 0.3.0.r20.g28771c7, Qt 6.11.1):

  1. Lock while in clamshell, so only the external output is active (realScreens: 1).
  2. Suspend.
  3. Wake by opening the lid. The internal panel returns, so the output set goes 1 → 2 while locked, and Quickshell tears down and recreates the lock surfaces (Not creating lock surface for screen ... not backed by a valid wayland output).
  4. The password field is drawn and the pointer works, but no keystroke produces a dot. Clicking the surface fixes it instantly — the MouseArea calls forcePasswordFocus() directly.

secure does not change across that rebuild, so onSecureStateChanged never re-fires:

19:01:22  secure=true     <- initial lock, before suspend
19:01:37  (resume; outputs 1 -> 2; lock surfaces recreated)
19:02:19  secure=false    <- unlock, 38s later

Instrumented during the dead window: keypresses were arriving at evdev, Hyprland still listed 7–9 keyboards including the built-in one, and omarchy-shell lock status stayed authenticating:false with lastEvent: secure=true throughout. So the keystrokes reached the compositor and were dropped for want of a focused item, rather than being lost below it.

Controlled A/B on the same machine, one variable changed:

Wake method realScreens Dead window
open the lid 1 → 2 38 s
power button, lid stays closed 1 throughout none

Keeping the output set constant avoids the surface rebuild entirely, and the field keeps focus.

This also lines up with the Copilot review note about lockView possibly being invalid by the time the deferred call runs — in this path the LockView genuinely is destroyed and recreated. Tying the re-focus to the LockView/surface lifecycle (or the retry Timer suggested in #6858) would cover both the initial lock and the rebuild-while-locked case; onSecureStateChanged alone only covers the first.

Filed by Claude Opus 5 via Claude Code.

Copilot AI review requested due to automatic review settings August 18, 2026 15:01

Copilot AI left a comment

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.

Pull request overview

Copilot reviewed 2 out of 2 changed files in this pull request and generated no new comments.

Suppressed comments (3)

shell/plugins/lock/Service.qml:242

  • Qt.callLater defers execution to a future event loop tick; if lockView is destroyed/replaced before this runs, calling lockView.retryPasswordFocus() can throw a runtime error. Consider guarding inside the callback (e.g., check lockView is still valid and the function exists) before invoking.
        Qt.callLater(function() { lockView.retryPasswordFocus() })

shell/plugins/lock/LockView.qml:61

  • retryPasswordFocus() restarts the repeating timer even if forcePasswordFocus() immediately succeeds. This causes at least one extra timer tick per call. Consider checking passwordInput.activeFocus after forcePasswordFocus() (or before restarting the timer) and only starting the retry timer when focus still wasn’t obtained.
  function retryPasswordFocus() {
    if (!inputEnabled || authenticatingPassword) return
    forcePasswordFocus()
    focusRetryTimer.attemptsLeft = 20
    focusRetryTimer.restart()
  }

shell/plugins/lock/LockView.qml:70

  • The retry behavior is controlled by magic numbers (interval: 150 and attemptsLeft = 20). Making these named property int values (e.g., max attempts, retry interval) and adding a brief comment on why these values were chosen will make future tuning safer and clearer.
    interval: 150
    repeat: true
    property int attemptsLeft: 0

This reverts commit 1316280.
Copilot AI review requested due to automatic review settings August 18, 2026 15:06

Copilot AI left a comment

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.

Pull request overview

Copilot reviewed 1 out of 1 changed files in this pull request and generated no new comments.

Suppressed comments (2)

shell/plugins/lock/Service.qml:242

  • Because this runs asynchronously on the next event loop tick, it can execute after lockView has been replaced/unloaded, which would throw a runtime error when calling forcePasswordFocus(). Add a guard inside the callLater callback (e.g., verify lockView is still valid and that forcePasswordFocus exists) before invoking it.
        Qt.callLater(function() { lockView.forcePasswordFocus() })

shell/plugins/lock/Service.qml:241

  • This deferred focus change is subtle and can be hard to reason about later (especially around focus-stealing behavior). Add a brief inline comment explaining why Qt.callLater is required here (e.g., focus must occur after the lock view is shown or after fingerprint start triggers UI changes).
        Qt.callLater(function() { lockView.forcePasswordFocus() })

Copilot AI review requested due to automatic review settings August 18, 2026 15:15

Copilot AI left a comment

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.

Pull request overview

Copilot reviewed 2 out of 2 changed files in this pull request and generated no new comments.

Suppressed comments (2)

shell/plugins/lock/LockView.qml:76

  • onSecureChanged can call forcePasswordFocus even when inputEnabled is false, which may steal focus / potentially trigger unintended input behaviors while input is disabled. Consider gating the focus call by both secure and inputEnabled (or otherwise ensuring focus is only requested when input is allowed).
  onInputEnabledChanged: {
    if (inputEnabled) Qt.callLater(forcePasswordFocus)
  }
  onSecureChanged: {
    if (secure) Qt.callLater(forcePasswordFocus)
  }

shell/plugins/lock/LockView.qml:80

  • The password-focus decision is now split across onInputEnabledChanged, onSecureChanged, and Component.onCompleted. This duplication risks future divergence (e.g., different gating conditions). Consider extracting a small helper (e.g., maybeForcePasswordFocus()) and calling it from all three places so the focus rules stay consistent.
  onInputEnabledChanged: {
    if (inputEnabled) Qt.callLater(forcePasswordFocus)
  }
  onSecureChanged: {
    if (secure) Qt.callLater(forcePasswordFocus)
  }
  Component.onCompleted: {
    syncPasswordText()
    if (inputEnabled) Qt.callLater(forcePasswordFocus)

@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?

@omarchybot omarchybot added the bug Something isn't working label Sep 27, 2026
@omarchybot

Copy link
Copy Markdown
Collaborator

Reviewed at d04bdac6, with the lock tested on an Omarchy VM (Hyprland, one virtual output, keys injected with wtype), first on current quattro and then with this change merged onto it.

The initial-lock race did not reproduce. On quattro without this change, locking, waiting for secure=true and typing the password straight away unlocked in 8 of 8 trials; with it, 5 of 5. So there is no before-and-after here showing that this change fixes anything, and in Qt terms it probably would not: forceActiveFocus() called before the window gets keyboard focus is kept and takes effect once the window is focused, so a second call when secure flips is normally redundant. secure means the compositor confirmed the screens are covered, not that this surface has keyboard focus. The machine it fails on may have timing a VM does not, but that is not established.

A case that does reproduce is not covered. With a second output focused, locking and then removing that output while locked leaves keystrokes dead, on quattro and with this change alike, because secure does not change when surfaces come and go. That is the rebuild-while-locked path @pjover described above and #7811 tracks.

Competing fixes. #7592 and #7471 (by @RovshanMuradov and @notTanveer) retry focus with a timer bound to !passwordInput.activeFocus, which re-arms whenever the field loses focus later instead of trying once more at one moment. Either covers the moment this one targets and the later ones #6858's reports describe, so this is not the one to bring forward; which of those two lands is for the maintainer.

Also: this branch no longer merges cleanly with quattro (a small conflict over the property declarations in LockView.qml), and the lock shell tests that could run on the worker passed, with ./test/cli failing the same unrelated vscode test on quattro as on this branch.

Reviewed by Claude Opus 5.5, with a second opinion from Codex at medium effort. Codex came to the same Qt-focus reading on its own terms, and put #7471 ahead of #7592 because it also wakes a blanked screen from the keyboard; it could not fetch the pull requests from its sandbox, so that ranking rests on partial reading, and its independence is not guaranteed since it can read this session's transcript. Waiting on the maintainer.

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.

5 participants