Skip to content

Fix numpad keys not producing digits when NumLock is ON#1902

Merged
christianparpart merged 2 commits intomasterfrom
fix/numpad-numlock-digits
Feb 25, 2026
Merged

Fix numpad keys not producing digits when NumLock is ON#1902
christianparpart merged 2 commits intomasterfrom
fix/numpad-numlock-digits

Conversation

@christianparpart
Copy link
Member

  • Infer NumLock state from Qt key event context instead of relying on unreliable native modifier bits (XCB_MOD_MASK_2) that don't work on Wayland. Qt reports Key_0..9 with KeypadModifier only when NumLock is ON, making the inference definitionally correct.
  • Add numpadAssociatedText() helper and emit the third CSI u parameter (associated text codepoint) in the Kitty keyboard protocol when ReportAssociatedText is enabled, allowing shells to resolve numpad keys to their character values.
  • Add 5 new unit tests covering legacy DECKPAM override with NumLock, no-NumLock preservation, CSI u with NumLock, and associated text encoding.

Fixes #1901

@github-actions github-actions bot added VT: Backend Virtual Terminal Backend (libterminal API) frontend Contour Terminal Emulator (GUI frontend) test Unit tests labels Feb 24, 2026
On Wayland, the native modifier bit for NumLock (XCB_MOD_MASK_2 = 0x10)
is unreliable, so makeModifiers() often fails to set Modifier::NumLock.
This caused two problems:

- Legacy protocol + DECKPAM: numpad keys sent escape sequences (e.g.
  CSI E) instead of digits
- Kitty protocol: CSI u sequences omitted the NumLock modifier, so
  shells didn't know to insert a digit for numpad keys

The fix infers NumLock state from Qt's key event resolution: Qt reports
Key_0..9 with KeypadModifier only when NumLock is ON (otherwise it
reports navigation keys like Insert, End, etc.). For operator/Enter
keys, NumLock is inferred from non-empty event text.

Additionally, add numpadAssociatedText() to emit the third CSI u
parameter (associated text codepoint) when ReportAssociatedText is
enabled in the Kitty protocol, allowing shells to resolve numpad keys
to their character values.

Fixes #1901

Signed-off-by: Christian Parpart <christian@parpart.family>
@christianparpart christianparpart force-pushed the fix/numpad-numlock-digits branch from 26f940f to 8d25202 Compare February 24, 2026 18:03
@github-actions github-actions bot added the CI GitHub Actions & CI label Feb 24, 2026
Yaraslaut
Yaraslaut previously approved these changes Feb 24, 2026
Copy link
Member

@Yaraslaut Yaraslaut left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

oh, key mapping is a pain

one nitpick

- helper.cpp: Reduce numpad digit case repetition using fall-through
  with arithmetic mapping (per @Yaraslaut)

Signed-off-by: Christian Parpart <christian@parpart.family>
@christianparpart christianparpart merged commit 8326da1 into master Feb 25, 2026
32 checks passed
@christianparpart christianparpart deleted the fix/numpad-numlock-digits branch February 25, 2026 20:36
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

CI GitHub Actions & CI frontend Contour Terminal Emulator (GUI frontend) test Unit tests VT: Backend Virtual Terminal Backend (libterminal API)

Projects

None yet

Development

Successfully merging this pull request may close these issues.

keyboard shortcuts confused by numlock

2 participants