Skip to content

Clear and swallow the lock-screen wake key so it is not typed as a password character - #11858

Closed
h14h wants to merge 3 commits into
omacom:quattrofrom
h14h:lock-swallow-wake-key
Closed

h14h wants to merge 3 commits into
omacom:quattrofrom
h14h:lock-swallow-wake-key

Conversation

@h14h

@h14h h14h commented Sep 14, 2026 •

Copy link
Copy Markdown

Problem

Waking a blanked lock screen with a keypress also inserts that character into the password field, so you have to delete it before typing the password.

Hyprland can enable DPMS on the same key that Qt still delivers to the focused TextInput. After idle blank, any half-typed password is also guesswork.

Change

The lock already tracks displaysBlank. When that is true, the password field now treats the wake key like Escape: intercept it with Keys.BeforeItem, request a wake, clear the buffered password, and accept the event so it is not typed.

Verified locally on Omarchy 4.0.3: lock, wait for the panel to blank, press Space — the screen wakes, the field is empty, and no password dot appears.

Tests

./test/shell.d/lock-wake-key-test.sh

h14h and others added 3 commits September 14, 2026 17:26
…racter

Hyprland can enable DPMS on the same keypress that Qt still delivers to the
password field. When the lock has blanked the displays, intercept that key
before TextInput inserts it, wake the screen, and ignore the character.

Amp-Thread-ID: https://ampcode.com/threads/T-01a0a1f2-cda2-7477-9564-53cfcd45dbb7
Co-authored-by: Amp <amp@ampcode.com>
Treat the wake key like Escape: drop the buffered password and swallow the
key so it is not inserted. After idle blank, the user cannot reasonably
know what was already typed.

Amp-Thread-ID: https://ampcode.com/threads/T-01a0a1f2-cda2-7477-9564-53cfcd45dbb7
Co-authored-by: Amp <amp@ampcode.com>
@h14h
h14h force-pushed the lock-swallow-wake-key branch from 03864a4 to d64d6f2 Compare September 14, 2026 23:15
@h14h h14h changed the title Swallow the lock-screen wake key so it is not typed as a password character Clear and swallow the lock-screen wake key so it is not typed as a password character Sep 14, 2026
@omarchybot omarchybot added the bug Something isn't working label Sep 27, 2026
@llstrk

llstrk commented Sep 30, 2026

Copy link
Copy Markdown

Automated AI review

Community review: Independent automated community review, unaffiliated with the Omarchy team, intended to help prepare PRs for their review.

Outcome: On a lit lock screen, the first password key can be dropped because displaysBlank can stay true after the panel relights.

A stale displaysBlank drops the first key on a lit screen

displaysBlank records what the lock requested (Service.qml:35-38); only input reaching the lock or an output change clears it, and with a still wallpaper nothing polls the panel. With Omarchy defaults (key_press_enables_dpms = true, media/brightness binds with locked = true), such a key lights the panel but Hyprland consumes it. Impact: typing hunter2 + Enter submits unter2, a failed attempt that counts toward pam_faillock; before this PR it unlocked.

Suggested change: Base the swallow on reported DPMS state, e.g. poll hyprctl monitors -j while blanked for every wallpaper, starting after the blank lands (up to one 3 s interval remains).

Reproducer (fails at d64d6f2)

Reproducer: a password typed while displaysBlank is still set loses its first character

What it shows: LockView.qml at the PR head discards the first key whenever displaysBlank is true, whether or not the panel is actually dark. The script loads the real shell/plugins/lock/LockView.qml in Qt's QML test runner (offscreen, with small stand-ins for qs.Commons and qs.Ui), wires it the way Service.qml does (edits become passwordText; wakeRequested sets displaysBlank to false, as runWake() does), and types into it.

Precondition modelled, not run live: the second test starts with displaysBlank true on a lit screen. That is the state Service.qml is left in after a Hyprland bind marked locked = true (brightness, volume, media keys) lights the panel: Hyprland consumes the key for the bind and enables DPMS (key_press_enables_dpms = true), so the lock never sees a key and nothing calls runWake(). That part comes from source reading (Hyprland 0.56.2 InputManager.cpp and KeybindManager.cpp, Omarchy default/hypr/input.lua and default/hypr/bindings/media.lua), not from a live session.

Requires qt6-declarative (for qmltestrunner and the QtTest QML module). Run from the checkout under test:

bash repro-lock-wake-key.sh

Script

#!/bin/bash
# Drives real key events into shell/plugins/lock/LockView.qml with qmltestrunner
# (Qt's QML test runner, part of qt6-declarative), offscreen, with minimal
# stand-ins for qs.Commons and qs.Ui. Run from an Omarchy checkout:
#   bash repro-lock-wake-key.sh [checkout]
set -euo pipefail

root=${1:-.}
runner=${QMLTESTRUNNER:-/usr/lib/qt6/bin/qmltestrunner}
work=$(mktemp -d)
trap 'rm -rf "$work"' EXIT

mkdir -p "$work/imports/qs/Commons" "$work/imports/qs/Ui"
cp "$root/shell/plugins/lock/LockView.qml" "$work/LockView.qml"

cat >"$work/imports/qs/Commons/qmldir" <<'EOF'
module qs.Commons
singleton Border 1.0 Border.qml
singleton Color 1.0 Color.qml
singleton Style 1.0 Style.qml
singleton Util 1.0 Util.qml
EOF
cat >"$work/imports/qs/Commons/Style.qml" <<'EOF'
pragma Singleton
import QtQuick
QtObject {
  property QtObject font: QtObject { property int heading: 20; property string family: "sans-serif" }
  property int cornerRadius: 0
}
EOF
cat >"$work/imports/qs/Commons/Color.qml" <<'EOF'
pragma Singleton
import QtQuick
QtObject {
  property color background: "black"
  property QtObject lock: QtObject {
    property color background: "#202020"; property color borderError: "red"; property color borderActive: "white"
    property color text: "white"; property color textError: "red"; property color selection: "gray"; property color placeholder: "gray"
  }
}
EOF
cat >"$work/imports/qs/Commons/Border.qml" <<'EOF'
pragma Singleton
import QtQuick
QtObject { function surfaceSpec(scope, key, fallback, thickness, alphaKey) { return ({}) } }
EOF
cat >"$work/imports/qs/Commons/Util.qml" <<'EOF'
pragma Singleton
import QtQuick
QtObject { function isVideoPath(path) { return false } }
EOF
cat >"$work/imports/qs/Ui/qmldir" <<'EOF'
module qs.Ui
BorderSurface 1.0 BorderSurface.qml
BackgroundMedia 1.0 BackgroundMedia.qml
EOF
cat >"$work/imports/qs/Ui/BorderSurface.qml" <<'EOF'
import QtQuick
Rectangle { property var borderSpec; property int borderTop: 3; property int borderRight: 3; property int borderBottom: 3; property int borderLeft: 3 }
EOF
cat >"$work/imports/qs/Ui/BackgroundMedia.qml" <<'EOF'
import QtQuick
Item {
  property string path; property int version; property bool playbackEnabled; property bool video: false; property bool ready: false
  property bool cached; property bool constrainDecode; property size decodeSize
}
EOF

cat >"$work/tst_lock_wake_key.qml" <<'EOF'
import QtQuick
import QtTest

Item {
  id: top
  width: 800
  height: 600

  property var submitted: []

  // Wired the way Service.qml wires the real lock: an edit becomes the next
  // passwordText, and wakeRequested runs runWake(), which sets displaysBlank
  // to false.
  function makeView(blank) {
    var c = Qt.createComponent(Qt.resolvedUrl("LockView.qml"), Component.PreferSynchronous)
    var v = c.createObject(top, { width: 800, height: 600, loadBackground: false, displaysBlank: blank })
    v.passwordTextEdited.connect(function(p) { v.passwordText = p })
    v.submitPassword.connect(function(p) { top.submitted.push(p) })
    v.wakeRequested.connect(function() { v.displaysBlank = false })
    v.forcePasswordFocus()
    return v
  }

  TestCase {
    name: "LockWakeKey"
    when: windowShown

    function type(s) { for (var i = 0; i < s.length; i++) keyClick(s[i]) }

    // What the PR sets out to do: the key that wakes a blanked lock is not typed.
    function test_space_that_wakes_a_blanked_lock_is_not_typed() {
      var v = makeView(true)
      wait(0)
      keyClick(Qt.Key_Space)
      compare(JSON.stringify(v.passwordText), JSON.stringify(""), "password after the wake key")
      v.destroy()
    }

    // Pressing a Hyprland bind marked `locked = true` (brightness, volume or
    // media keys) lights the panel through key_press_enables_dpms, but the key
    // never reaches the lock. Nothing calls runWake(), so displaysBlank is
    // still true when the user starts typing on the lit screen.
    function test_password_typed_on_lit_screen_with_stale_blank_flag() {
      top.submitted = []
      var v = makeView(true)
      wait(0)
      type("hunter2")
      keyClick(Qt.Key_Return)
      compare(top.submitted.length, 1, "one submission")
      compare(JSON.stringify(top.submitted[0]), JSON.stringify("hunter2"), "the submitted password")
      v.destroy()
    }
  }
}
EOF

QT_QPA_PLATFORM=offscreen QT_QUICK_BACKEND=software QML_DISABLE_DISK_CACHE=1 \
  "$runner" -import "$work/imports" -input "$work/tst_lock_wake_key.qml"

Actual output at the PR head (d64d6f2)

********* Start testing of qmltestrunner *********
Config: Using QtTest library 6.11.2, Qt 6.11.2 (x86_64-little_endian-lp64 shared (dynamic) release build; by GCC 16.2.1 20260810), omarchy 4.0.4
PASS   : qmltestrunner::LockWakeKey::initTestCase()
FAIL!  : qmltestrunner::LockWakeKey::test_password_typed_on_lit_screen_with_stale_blank_flag() the submitted password
   Actual   (): "unter2"
   Expected (): "hunter2"
   Loc: [/tmp/tmp.Pu7npkfkYm/tst_lock_wake_key.qml(50)]
PASS   : qmltestrunner::LockWakeKey::test_space_that_wakes_a_blanked_lock_is_not_typed()
PASS   : qmltestrunner::LockWakeKey::cleanupTestCase()
Totals: 3 passed, 1 failed, 0 skipped, 0 blacklisted, 26ms
********* Finished testing of qmltestrunner *********

Actual output at the merge base (86a2e58), as a control

********* Start testing of qmltestrunner *********
Config: Using QtTest library 6.11.2, Qt 6.11.2 (x86_64-little_endian-lp64 shared (dynamic) release build; by GCC 16.2.1 20260810), omarchy 4.0.4
PASS   : qmltestrunner::LockWakeKey::initTestCase()
PASS   : qmltestrunner::LockWakeKey::test_password_typed_on_lit_screen_with_stale_blank_flag()
FAIL!  : qmltestrunner::LockWakeKey::test_space_that_wakes_a_blanked_lock_is_not_typed() password after the wake key
   Actual   (): " "
   Expected (): ""
   Loc: [/tmp/tmp.4D8493S8oo/tst_lock_wake_key.qml(35)]
PASS   : qmltestrunner::LockWakeKey::cleanupTestCase()
Totals: 3 passed, 1 failed, 0 skipped, 0 blacklisted, 26ms
********* Finished testing of qmltestrunner *********

The head passes the PR's own case (the Space that wakes a blanked lock is not typed) and fails the stale-flag case: hunter2 reaches submitPassword as unter2. The merge base does the opposite. The PR merged onto quattro 8b4eae6 gives the same result as the head.

More findings

The new test checks source text and passes with the swallow broken

Adding event.accepted = false after event.accepted = clearPassword sends every key back to TextInput, yet lock-wake-key-test.sh still passes; its root.wakeRequested() assertion already holds at the merge base. Impact: the test does not protect the behaviour it describes.

Suggested change: Move the decision into a small pure JS function (for example wakeKeyAction(displaysBlank, key, modifiers)) and test it with run_node_test, as docs/testing.md describes for shell JavaScript.

Reproducer: the new test passes when the wake key is typed again

What it shows: test/shell.d/lock-wake-key-test.sh matches source text. Adding one line after event.accepted = clearPassword makes every key fall through to TextInput again, and the test still passes. The behavioural check from the other reproducer (repro-lock-wake-key.sh) catches it.

Commands, from a checkout of the PR head:

cp shell/plugins/lock/LockView.qml /tmp/LockView.orig.qml
sed -i 's/^\( *\)event\.accepted = clearPassword$/&\n\1event.accepted = false/' shell/plugins/lock/LockView.qml
diff -u --label a/shell/plugins/lock/LockView.qml --label b/shell/plugins/lock/LockView.qml /tmp/LockView.orig.qml shell/plugins/lock/LockView.qml
./test/shell.d/lock-wake-key-test.sh
bash repro-lock-wake-key.sh

Actual output

The change (diff -u output):

--- a/shell/plugins/lock/LockView.qml
+++ b/shell/plugins/lock/LockView.qml
@@ -185,6 +185,7 @@
           root.wakeRequested()
           if (clearPassword) root.passwordTextEdited("")
           event.accepted = clearPassword
+          event.accepted = false
         }
       }
 

./test/shell.d/lock-wake-key-test.sh on the changed file (exit 0):

ok - the password field intercepts keys before TextInput inserts them
ok - a blanked lock screen treats the wake key like Escape: clear and swallow
ok - a key that wakes a blanked lock screen is swallowed instead of typed
ok - the swallowed wake key still requests a display wake

bash repro-lock-wake-key.sh on the changed file (exit 1):

********* Start testing of qmltestrunner *********
Config: Using QtTest library 6.11.2, Qt 6.11.2 (x86_64-little_endian-lp64 shared (dynamic) release build; by GCC 16.2.1 20260810), omarchy 4.0.4
PASS   : qmltestrunner::LockWakeKey::initTestCase()
PASS   : qmltestrunner::LockWakeKey::test_password_typed_on_lit_screen_with_stale_blank_flag()
FAIL!  : qmltestrunner::LockWakeKey::test_space_that_wakes_a_blanked_lock_is_not_typed() password after the wake key
   Actual   (): " "
   Expected (): ""
   Loc: [/tmp/tmp.JwqD16alis/tst_lock_wake_key.qml(35)]
PASS   : qmltestrunner::LockWakeKey::cleanupTestCase()
Totals: 3 passed, 1 failed, 0 skipped, 0 blacklisted, 27ms
********* Finished testing of qmltestrunner *********

Also: the last assertion (root.wakeRequested() appears in the file) already holds at the merge base, where the call is on lines 120, 121, 168 and 180, and the first one pins Keys.priority: Keys.BeforeItem, which is Qt's default.

Details

Verified (qmltestrunner, offscreen, real LockView.qml with stubbed qs.Commons/qs.Ui):

  • While displaysBlank is true, the waking key (Space, a letter, Shift, Enter) is not typed and a buffered password is cleared.
  • While awake, typing, Backspace, Enter, Escape and Ctrl+U behave as on the merge base.
  • The PR merges cleanly into current quattro and behaves the same there.

Notes:

  • Keys.priority: Keys.BeforeItem is Qt's default (qquickitem.cpp, QQuickKeysAttached constructor), so that line changes nothing; the handler already ran before TextInput.
  • From source and the harness (auto-repeat not driven directly), only the first key is swallowed; repeats of a held wake key would be typed once the flag clears.
  • Clearing on wake also drops a half-typed password after a pause longer than the 5 s idle blank, and Enter pressed while blank does not submit. Commit 71aa17a describes this as intended.

Related open PRs: #9211 adds the same wake-key swallow (without the clear) in the same Keys.onPressed block, plus a resume wake in Service.qml and its own source-text test; it conflicts textually with this PR. #7806, #12667, #13183, #13590 and #12461 also edit that block and conflict textually. #11991 removes the pointer-motion wake; with mouse_move_enables_dpms = true, moving the mouse would then also reach the stale-flag case.


Review information

Test scope: Source and sandboxed Qt Quick tests at d64d6f2; the stale-flag precondition is from Hyprland 0.56.2 source, not a live session.

AI process: Opus 5.5 Medium coordination and synthesis, Opus 5.5 Xhigh technical review and final fact check, GPT 6 Sol Xhigh search for related issues, Opus 5.5 Medium editorial check.

Opt out: To stop receiving these reviews, reply to this comment saying so.

@omarchybot

Copy link
Copy Markdown
Collaborator

Reviewed at d64d6f2 by Claude Opus 5.5 and Codex Medium. The fix works for the case it targets, but it introduces a regression: after a volume or brightness key wakes the blanked lock, the first character of the password is dropped.

What it fixes, confirmed live. On a worker built from the Omarchy ISO, with the shell linked to this branch, I locked the session, waited for the idle blank, and woke the panel with a real Space keypress through a uinput keyboard. On the merge base 86a2e58 the space went into the password and the unlock failed. On this head the unlock succeeded.

What it breaks, also confirmed live. Volume, brightness and media keys are locked = true binds in default/hypr/bindings/media.lua, and key_press_enables_dpms is on. So pressing one at a blanked lock turns the panel on while Hyprland consumes the key for the bind. The lock never sees that key, nothing calls runWake(), and displaysBlank stays true on a lit screen. With a still wallpaper nothing corrects it, because the monitorDpms poll in Service.qml only runs for video wallpapers. The next real keypress then hits LockView.qml:181 as if it were the wake key: it clears the field and is swallowed. On the worker, Volume Up lit the panel and raised the volume from 0.50 to 0.55. A probe in the handler then logged the first password key with blank=true, the unlock failed, and faillock recorded a failure (the PAM config denies after 10). On the merge base the same sequence unlocked, because the stale flag only paused the wallpaper there. This matches what the earlier community review on this PR found from source.

Smaller points, from both reviewers:

  • Enter pressed while the screen is blank clears a typed password instead of submitting it. Today it submits.
  • Auto-repeat of a held wake key types characters once the first press has cleared the flag.
  • test/shell.d/lock-wake-key-test.sh matches source text. It still passes with event.accepted = false appended or with the clear removed, so it does not protect the behaviour. A qmltestrunner harness that loads the real LockView.qml with small stubs for qs.Commons and qs.Ui reproduces both the fix and the regression offscreen, if you want a behavioural test.
  • Keys.priority: Keys.BeforeItem is already Qt's default.

Tests. The lock tests under test/shell.d/ (lock-*, sleep-lock, system-lock, hyprland-session-locked, apply-lock, update-lock, clock) pass on the worker, this PR's new test included. The full suite was not run.

Related. #9211 swallows the wake key from the same handler, keyed on the same displaysBlank flag, so it has the same regression. It also adds a resume-wake timer. Codex, asked separately which of the two to prefer, said neither as they stand. Both reviews read the stale flag as the thing to solve before either swallow can land. Polling the real DPMS state for every wallpaper while blanked would narrow the window to the 3 s poll interval but not close it. A signal that cannot go stale is a design choice about how the lock and the compositor talk, so I have not pushed a fix here.

Waiting on the author. The maintainer has both this PR and #9211 to choose between once the stale-flag case is handled.

@h14h
h14h marked this pull request as draft October 1, 2026 13:19
@h14h

h14h commented Oct 1, 2026

Copy link
Copy Markdown
Author

Moved this PR to draft. I reproduced the regression in the offscreen Qt harness: with a stale displaysBlank flag, hunter2 is submitted as unter2, while the Space-to-wake case passes. The current source-text test also passes despite the regression.

Volume/brightness binds can wake the display without reaching the lock, leaving that flag stale. Polling DPMS would only narrow the race window; querying it when the key reaches QML can already report “on” for the actual wake key. A reliable approach appears to require Hyprland to identify and suppress the wake key before forwarding it, including repeats until release. That would need a companion upstream change.

Which path would maintainers prefer: merge with the known regression, close this PR, or keep it as a draft pending a Hyprland fix? My preference is to avoid merging with the regression.

@omarchybot

Copy link
Copy Markdown
Collaborator

Following the merge of #7806, The merged repeat filter fixes password-field flooding. Consuming the first wake key and clearing buffered input remain separate work in this draft. The reported stale displaysBlank regression can still discard the first password character after media/brightness wake and needs fixing.

Scope checked by GPT-6 in Codex and Codex Medium against the discussion and landed change; review independence is not guaranteed. No tests were rerun for this cleanup.

Omabot on behalf of DHH

@jandrusk

Copy link
Copy Markdown

Same problem as #12398 / overlapping #9211 (wake/auto-repeat keys landing in the password field).

Logic looks right (Keys.BeforeItem, swallow while displaysBlank). Needs a quattro rebase — then I'd pick one of #11858/#9211 rather than both.

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.

4 participants