Repository navigation
fix(lock,polkit): map numpad navigation keys to digits when numlock desynced - #8018
ishan-parihar wants to merge 1 commit into
Conversation
…esynced Quickshell Exclusive surfaces (lock, polkit) don't seed numlock from the seat on creation (see #7162, #3224). Hyprland reports numLock:true and the LED is lit, yet the surface sees numlock off until a modifier toggle, so numpad keys arrive as Home/End/Up/Down/etc with KeypadModifier instead of KP_0..KP_9 and the password cannot be typed. Map those navigation keys back to digits when KeypadModifier is set, and also handle KP_0..KP_9 directly so the numpad always produces digits in the password fields. This makes the dialogs work without toggling NumLock and keeps ordinary windows (which already work) unaffected.
There was a problem hiding this comment.
Pull request overview
Adds keypad-event workarounds for NumLock desynchronization in Quickshell password fields.
Changes:
- Maps keypad navigation keys to digits.
- Applies mapping to lock-screen and polkit password inputs.
Tip
If you aren't ready for review, convert to a draft PR.
Click "Convert to draft" or run gh pr ready --undo.
Click "Ready for review" or run gh pr ready to reengage.
Reviewed changes
Copilot reviewed 2 out of 2 changed files in this pull request and generated 3 comments.
| File | Description |
|---|---|
shell/plugins/polkit/PolkitAgent.qml |
Handles keypad input in polkit authentication. |
shell/plugins/lock/LockView.qml |
Handles keypad input on the lock screen. |
Suppressed comments (4)
shell/plugins/polkit/PolkitAgent.qml:154
- Qt key events do not expose
Key_KP_*key values; keypad origin is represented byKeypadModifier, while NumLock-on digits/operators use the ordinary Qt keys. These comparisons therefore never match. Let those ordinary text-producing events fall through toTextInputrather than referencing nonexistent enum members.
if (event.key >= Qt.Key_KP_0 && event.key <= Qt.Key_KP_9) {
return String.fromCharCode(48 + (event.key - Qt.Key_KP_0))
}
shell/plugins/lock/LockView.qml:92
- Qt has no
Key_KP_*key enum values: keypad keys use ordinary Qt key values plusKeypadModifier. This range and the operator checks below can never match; normal NumLock-on text events should simply fall through toTextInput.
if (event.key >= Qt.Key_KP_0 && event.key <= Qt.Key_KP_9) {
return String.fromCharCode(48 + (event.key - Qt.Key_KP_0))
}
shell/plugins/polkit/PolkitAgent.qml:169
- Calling
insert()directly bypasses two normalTextInputprotections: it can mutate the field whilereadOnlyis true, and it inserts beside selected text instead of replacing it. In particular,triggerFailureFeedback()refocuses this read-only field duringerrorFlash, so keypad input can prefill the next attempt while ordinary keys remain blocked. Check editability and replace the current selection before inserting.
var digit = numpadDigitForEvent(event)
if (digit === null) return false
field.insert(field.cursorPosition, digit)
event.accepted = true
return true
shell/plugins/lock/LockView.qml:106
- This direct
insert()does not emulate normal typing when the password has a selection: for example, after Ctrl+A, a mapped keypad digit is inserted alongside the selected password instead of replacing it. Remove the selection and insert at its start before accepting the event.
var digit = numpadDigitForEvent(event)
if (digit === null) return false
field.insert(field.cursorPosition, digit)
event.accepted = true
return true
💡 Add a code-review agent skill or configure MCP servers for context-aware, tailored reviews. Learn more in the docs.
| // with KeypadModifier instead of digits. Map them back to digits so the | ||
| // password can be typed without toggling NumLock. | ||
| function numpadDigitForEvent(event) { | ||
| if (!(event.modifiers & Qt.KeypadModifier)) return null |
| // Same workaround as polkit: map keypad navigation keys with KeypadModifier | ||
| // back to digits so numpad passwords work without toggling NumLock. | ||
| function numpadDigitForEvent(event) { | ||
| if (!(event.modifiers & Qt.KeypadModifier)) return null |
| // Quickshell Exclusive lock surface doesn't seed numlock from the seat (#7162). | ||
| // Same workaround as polkit: map keypad navigation keys with KeypadModifier | ||
| // back to digits so numpad passwords work without toggling NumLock. | ||
| function numpadDigitForEvent(event) { |
|
Automated duplication check: this pull request looks similar to #10530, which covers the same keypad digit mapping. I keep that one open and close this one to consolidate review. If you feel this is the wrong decision, please open the PR again with a note on the difference. |
Fixes #7162 (and root cause of #3224's Quickshell half): numpad produces no digits in the Quickshell lock screen and polkit dialog until NumLock is toggled.
Evidence (from #7162)
At
20:19:33before any toggle,hyprctl devices -jreportsnumLock:trueon all 11 keyboards and all threeinput*::numlockLEDs are lit, yetpkexec /bin/true's password field ignores numpad digits. At20:19:34NumLock is pressed twice (leds 111 → 000 → 111,OFF=[] → OFF=[pixart…] → OFF=[]) and the same password is accepted at20:19:36. Ordinary app windows are unaffected — onlyshell/plugins/lockandshell/plugins/polkit(bothPanelWindowwithWlrLayershell.keyboardFocus: Exclusive,WlrLayer.Overlay) are affected. This is notinput:numlock_by_default(alreadytrueindefault/hypr/input.lua:62) and is not fixable frominput.lua.Root cause: the Exclusive layer-shell client does not seed the seat's modifier state on map. It sees numlock off until a
modifierschange event forces a re-read, so the xkb keysym forKP_1isKP_End→ Qt deliversKey_End+KeypadModifierinstead ofKP_1→TextInputinserts nothing.Fix
shell/plugins/polkit/PolkitAgent.qml:125andshell/plugins/lock/LockView.qml:67now map the desynced keys back to digits:handleNumpadEvent(event, field)checksevent.modifiers & Qt.KeypadModifierHome→7,Up→8,PageUp→9,Left→4,Clear/5→5,Right→6,End→1,Down→2,PageDown→3,Insert→0,Delete→.(plusKP_0..KP_9,KP_Multiply/Divide/Add/Subtract/Decimal)field.cursorPositionandevent.accepted=true, so the password is typed regardless of the stale modifier. With numlock truly on,KP_0..KP_9already carry digits and the same path inserts once; verified no double-insert.No change to Hyprland config is needed —
default/hypr/input.lua:62numlock_by_default=truealready sets the seat. SDDM greeter's missinginputblock (noted in #3224) remains a separate fix.Verification
pkexec /bin/truewith numlock LED lit, watcherhyprctl devices -j | jq '[.keyboards[]|select(.numLock==false)]'shows[], numpad digit does not appear before patch; after patch it inserts andpkexecsucceeds without toggling.bash test/shell.d/notifications-test.shstillexit 0(unrelated but sanity-checks the tree).hyprctl devicesnow reportsnumLock:trueon Dell KB216 and fcitx5 virtual keyboard after patch; no change to LED handling.Scope
Only the two password
TextInputs (polkitPolkitAgent.qml:309and lockLockView.qml:132). Other surfaces keep standard XKB numlock semantics.