Skip to content

Show keyboard state that changes what a keystroke types on the lock screen - #13590

Open
seantimm wants to merge 2 commits into
omacom:quattrofrom
seantimm:lock-keyboard-state-badges
Open

seantimm wants to merge 2 commits into
omacom:quattrofrom
seantimm:lock-keyboard-state-badges

Conversation

@seantimm

@seantimm seantimm commented Sep 28, 2026 •

Copy link
Copy Markdown

Summary

  • Badges above the lock screen's password field for Caps Lock, Num Lock off, a held Ctrl, Alt or Super, a non-default keyboard layout, and Shift while it is held. Hidden when there is nothing to say, so the default lock screen looks exactly as it does today.
  • Caps Lock, Num Lock and the layout are read from hyprctl devices -j through a small KeyboardStateModel.js, polled every 400 ms while the lock screen or its preview is up and on every key event the view sees (Hyprland has no event for the lock keys). Virtual keyboards (hl-virtual-keyboard-*) are ignored so an input method's own xkb state cannot mask the physical keyboards.
  • Held modifiers come from the view's own key events, identified by xkb keycode rather than Qt.Key. With the default shift:both_capslock_cancel a Shift release reaches Qt as Qt.Key_CapsLock with Shift still set in event.modifiers, which leaves a SHIFT badge stuck if keyed off event.key. Any ordinary keypress also resyncs the badges from its modifier flags.
  • Colors and radius come from the existing lock.* theme tokens (border-active / text for Shift, border-error / text-error for everything else), so themes that already style the lock's error state get a matching badge for free.

This is the request from discussion #6241 (originally #1770), which was answered for hyprlock. The Quickshell lock never carried an indicator, so a wrong-looking password today gives no hint that Caps Lock is on.

Verification

  • bash test/shell.d/lock-keyboard-state-model-test.sh (node: device parsing, virtual-keyboard exclusion, layout naming, malformed input; service wiring)
  • bash test/shell.d/lock-keyboard-state-badges-test.sh (Quickshell fixture: badge row placement above the field, each badge, the Shift-release-as-CapsLock case, resync on an ordinary key)
  • Existing lock-fingerprint-indicator, lock-password-overflow, lock-blank-fingerprint and lock-wallpaper-preload tests still pass
  • git diff --check
  • Verified in the running UI on Omarchy 4.0.4 (NVIDIA, Keychron keyboard) with the same change carried in a local clone of the lock plugin: locked, held Shift, engaged Caps Lock via both Shifts, cleared it with a single Shift; badges appeared and cleared as expected. The branch itself was exercised through the Quickshell fixture above. Captures attached: quiet lock screen (before) and with CAPS LOCK (after).
lock-before-quiet lock-after-capslock

Notes for review

🤖 Generated with Claude Code

…creen

Badges above the password field for Caps Lock, Num Lock off, a held Ctrl,
Alt or Super, a non-default layout, and Shift while held. Hidden when there
is nothing to say, so the stock lock screen looks the same as before.

Caps Lock, Num Lock and the layout come from `hyprctl devices -j`, reduced
by the new KeyboardStateModel.js and polled every 400 ms while the lock
screen or its preview is up, plus on every key event the view sees, since
Hyprland has no event for the lock keys. Virtual keyboards are ignored so an
input method's own xkb state cannot mask the physical keyboards.

Held modifiers are tracked from the view's own key events by xkb keycode
rather than by Qt.Key: with shift:both_capslock_cancel in kb_options, a
Shift release arrives as Qt.Key_CapsLock with Shift still set in
event.modifiers, which left the SHIFT badge stuck when keyed off event.key.
Any ordinary keypress resyncs the badges from its modifier flags.

Requested in discussion omacom#6241 (originally omacom#1770) back when hyprlock drew the
lock screen; the Quickshell lock never carried an indicator.

Co-Authored-By: Claude Fable 5.1 <noreply@anthropic.com>
@llstrk

llstrk commented Sep 28, 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: With two or more layouts configured, Super + Ctrl + L, idle and lid-close locks show a red badge for the default layout.

Layout badge shows for the default layout

keyboardStateFromDevices names active_keymap whenever layout contains a comma. omarchy-system-lock switches every keyboard to layout 0 as it locks, so us,dk and the us,<layout> default for non-Latin installs get ENGLISH (US) on each such lock. It also reads the first listed device, which can be a power button that Left Alt + Right Alt does not switch, so a switch made at the lock is not shown.

Suggested change: Name a keyboard's layout only when its active_layout_index is above 0.

Reproducer (fails at 0c36e2f)

Save as test/shell.d/lock-keyboard-state-default-layout-test.sh (same helpers and style as the PR's lock-keyboard-state-model-test.sh) and run bash test/shell.d/lock-keyboard-state-default-layout-test.sh from the repository root.

#!/bin/bash

set -euo pipefail

source "$(cd -- "$(dirname -- "${BASH_SOURCE[0]}")" && pwd)/base-test.sh"

run_node_test <<'JS'
const model = requireFromRoot('shell/plugins/lock/KeyboardStateModel.js')

function devices(keyboards) {
  return JSON.stringify({ mice: [], keyboards: keyboards })
}

// Two layouts configured (the manual's "us,dk" example, or the "us,<layout>"
// that default/hypr/input.lua writes for a non-Latin install), and the keyboard
// on the first one: omarchy-system-lock runs `hyprctl switchxkblayout all 0`
// before the lock screen shows, so this is the state at the start of every lock.
assertDeepEqual(
  model.keyboardStateFromDevices(devices([
    { name: 'keychron', layout: 'us,dk', active_layout_index: 0, active_keymap: 'English (US)', capsLock: false, numLock: true, main: true }
  ])),
  { capsLockOn: false, numLockOn: true, layoutLabel: '' },
  'the first (default) layout of a multi-layout config shows no layout badge'
)
JS

Actual output at the reviewed head (stdout empty, exit status 1):

expected: {"capsLockOn":false,"numLockOn":true,"layoutLabel":""}
actual:   {"capsLockOn":false,"numLockOn":true,"layoutLabel":"English (US)"}
not ok - the first (default) layout of a multi-layout config shows no layout badge

LockView.qml turns a non-empty layoutLabel into an ENGLISH (US) badge with warn: true (the border-error / text-error colours).

Run with Node v26.7.0. The same test passes against a copy of the model that only names the layout when active_layout_index is above 0.

More findings

Keyboard poll keeps running while the lock is blanked

The 400 ms hyprctl devices -j timer keeps running while the displays are blanked (9,000 launches an hour), when no badge is visible. Found in source; not measured on a real lock.

Suggested change: running: (root.locked && !root.displaysBlank) || root.previewVisible, updating the running: regex in the model test.

NUM LOCK OFF can stay lit (only with numlock_by_default = false)

Devices nobody types on (for example the power button) count as keyboards, and Hyprland keeps Num Lock per keyboard. Turning Num Lock on at the keyboard then leaves the badge lit for the whole lock.

Suggested change: Skip the devices KeyboardLayoutModel.js already treats as untyped (isTypedKeyboard) before reading any state.

Applies when numlock_by_default = false is set in ~/.config/hypr/input.lua (Omarchy's default is true). Hyprland keeps Num Lock per keyboard (m_modifiersState.locked), so pressing Num Lock turns it on only for the keyboard it was pressed on.

Save as test/shell.d/lock-keyboard-state-typed-numlock-test.sh and run bash test/shell.d/lock-keyboard-state-typed-numlock-test.sh from the repository root.

#!/bin/bash

set -euo pipefail

source "$(cd -- "$(dirname -- "${BASH_SOURCE[0]}")" && pwd)/base-test.sh"

run_node_test <<'JS'
const model = requireFromRoot('shell/plugins/lock/KeyboardStateModel.js')

function devices(keyboards) {
  return JSON.stringify({ mice: [], keyboards: keyboards })
}

// numlock_by_default = false in ~/.config/hypr/input.lua: every keyboard starts
// with Num Lock off. Pressing Num Lock turns it on for the keyboard it was
// pressed on only; the power button, which nobody presses Num Lock on, keeps it
// off for the rest of the session.
assertDeepEqual(
  model.keyboardStateFromDevices(devices([
    { name: 'power-button', layout: 'us', active_layout_index: 0, active_keymap: 'English (US)', capsLock: false, numLock: false, main: false },
    { name: 'at-translated-set-2-keyboard', layout: 'us', active_layout_index: 0, active_keymap: 'English (US)', capsLock: false, numLock: true, main: true }
  ])),
  { capsLockOn: false, numLockOn: true, layoutLabel: '' },
  'Num Lock turned on at the keyboard clears NUM LOCK OFF'
)
JS

Actual output at the reviewed head (stdout empty, exit status 1):

expected: {"capsLockOn":false,"numLockOn":true,"layoutLabel":""}
actual:   {"capsLockOn":false,"numLockOn":false,"layoutLabel":""}
not ok - Num Lock turned on at the keyboard clears NUM LOCK OFF

Run with Node v26.7.0. The same test passes against a copy of the model that skips the device names the bar's UNTYPED_KEYBOARDS pattern (in KeyboardLayoutModel.js) matches.

AltGr shows the ALT warning

Keycode 108 (Right Alt) maps to Qt.AltModifier, but on dk, de, fr, pl and most other non-US layouts it is AltGr, used to type password characters (such as @ on dk, de, fr). Holding it shows a red ALT badge until the next character.

Suggested change: For keycode 108, return 0 when event.key === Qt.Key_AltGr.

On layouts that include level3(ralt_switch) (dk, de, fr, pl and most non-US layouts), Right Alt is AltGr: xkb keycode 108, keysym ISO_Level3_Shift, which Qt reports as Qt.Key_AltGr with no Alt modifier. modifierForKey maps keycode 108 to Qt.AltModifier, so holding AltGr to type a password character such as @ shows a red ALT badge. The next character key clears it, because its event.modifiers carries no Alt.

The quickest form is two lines added to the PR's own fixture, test/shell.d/fixtures/lock-keyboard-state/shell.qml, right after the Super checks:

view.trackModifiers(keyEvent(Qt.Key_AltGr, 108, 0), true)
root.assertTrue(labels(view).indexOf("ALT") === -1, "holding AltGr raises no ALT warning, got " + labels(view))

The run below used the same check in a standalone fixture: a copy of the PR's lock-keyboard-state/shell.qml whose test body is replaced by these steps, plus a copy of lock-keyboard-state-badges-test.sh pointed at it. An excerpt of the fixture's timer handler:

        var view = component.createObject(host, { width: 800, height: 600, loadBackground: false })
        if (!view) {
          root.fail("LockView failed to instantiate: " + component.errorString())
          return
        }

        // On layouts that put ISO_Level3_Shift on Right Alt (dk, de, fr, pl
        // and most others), Right Alt is AltGr: xkb keycode 108, reported by
        // Qt as Key_AltGr with no Alt modifier. Holding it to type a password
        // character such as @ or { is ordinary typing.
        view.trackModifiers(keyEvent(Qt.Key_AltGr, 108, 0), true)
        root.assertTrue(labels(view).indexOf("ALT") === -1,
          "holding AltGr raises no ALT warning, got " + labels(view))

        view.destroy()

Actual output at the reviewed head (stdout empty, exit status 1). No compositor was available, so the test's require_compositor line was bypassed and Quickshell ran with QT_QPA_PLATFORM=offscreen (the fixture creates no window). The five Quickshell log lines between Lock keyboard state log: and not ok are omitted here because they only give sandbox paths and IDs:

Lock keyboard state result:
{
  "ok": false,
  "failures": [
    "holding AltGr raises no ALT warning, got ALT"
  ]
}
Lock keyboard state log:
not ok - AltGr, which types characters, is not reported as ALT

In the same run, and under the same offscreen setup, the PR's own lock-keyboard-state-badges-test.sh passed at the head, and the existing lock-fingerprint-indicator and lock-password-overflow tests passed too.

Details

Verified

  • Both new tests pass at the head and fail at the merge-base.
  • A Shift release reported as Qt.Key_CapsLock under shift:both_capslock_cancel clears the SHIFT badge (keycode path).
  • With nothing to report, the badge row is hidden and the field layout is unchanged.
  • A failing hyprctl (error text on stdout) yields the quiet state.

Optional test improvement: With the tests unchanged, each of these edits still leaves both new tests passing: removing Keys.onReleased, removing the onActiveFocusChanged reset, or removing onKeyboardActivity: root.refreshKeyboardState(). The QML fixture sets view properties and calls trackModifiers() directly, so the key handlers and the key-triggered refresh are untested.

Related open PRs: #11858 and #7806 change the same Keys.onPressed lines in LockView.qml, and #10130 adds fields at the same place in Service.qml's status(). These are text conflicts in which both sides should be kept.


Review information

Test scope: Source and sandboxed tests at 0c36e2f; not tested on a live lock screen.

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.

The first layout of several no longer gets a badge. omarchy-system-lock
switches every keyboard to its first layout, so with "us,dk" configured each
lock opened with a red ENGLISH (US). The layout is now named only once a
keyboard has moved off its first one.

Power buttons, the lid switch and the video bus report as keyboards and keep
their own xkb state. They are skipped like virtual keyboards, using the same
list as the bar's KeyboardLayoutModel.js, so a Num Lock turned on at the
keyboard clears NUM LOCK OFF and a layout switched at the lock is read from
the keyboard that switched. A test holds the two lists together.

AltGr no longer raises ALT: Right Alt is keycode 108 either way, but where
the layout makes it AltGr it types password characters.

The keyboard poll stops while the displays are blanked, when no badge can be
seen, and reads again as soon as they wake.

The model test now also checks that the key handlers, the focus reset and
the key-triggered refresh are wired up.

Co-Authored-By: Claude Fable 5.1 <noreply@anthropic.com>
@seantimm

Copy link
Copy Markdown
Author

Thanks, all four findings were right. Fixed in 83f9be1:

  • Default layout badge: the layout is named only when a keyboard's active_layout_index is above 0, so the first layout of several (the state omarchy-system-lock resets to) shows nothing.
  • NUM LOCK OFF staying lit / layout read from a button: the model skips the untyped devices (power-button, sleep-button, lid-switch, video-bus, virtual keyboards). The pattern is a copy of the bar's UNTYPED_KEYBOARDS rather than an import, since the model is unit tested with node; a test fails if the two lists drift apart. Happy to move it to a shared helper if that is preferred.
  • AltGr: modifierForKey returns 0 for Qt.Key_AltGr, so it no longer raises ALT. A plain Right Alt still does.
  • Poll while blanked: the timer runs on (root.locked && !root.displaysBlank) || root.previewVisible and reads again as soon as the displays wake.

Tests: model cases for the default layout, a layout switched at the lock, and button devices; an AltGr case in the Quickshell fixture; and source assertions for Keys.onPressed, Keys.onReleased, the focus reset and onKeyboardActivity, which covers the wiring the review noted was untested (as wiring checks, not real key events).

Both new tests and the existing lock-fingerprint-indicator, lock-password-overflow, lock-blank-fingerprint and lock-wallpaper-preload tests pass. These fixes were exercised through the tests, not on a live lock screen.

🤖 Generated with Claude Code

@jandrusk

jandrusk commented Oct 7, 2026

Copy link
Copy Markdown

This conflicts with quattro now. LockView.qml and Service.qml changed on Oct 4 with #7806 (ignore autorepeat on the lock) and #7158 (fingerprint enrollment and lock-screen recovery). Could you rebase? Both touch key handling in LockView, so please check that the badge resync still runs on the key events that #7806 now filters out. A held modifier's autorepeat shouldn't flip the SHIFT/CTRL badges.

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

Labels

enhancement New feature or request

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants