8000 Fix numpad keys dropped on X11 with NumLock off by chiliec · Pull Request #443 · emoon/rust_minifb · GitHub
[go: up one dir, main page]

Skip to content

Fix numpad keys dropped on X11 with NumLock off - #443

Open
chiliec wants to merge 1 commit into
emoon:masterfrom
chiliec:fix-x11-numpad-numlock-off
Open

chiliec wants to merge 1 commit into
emoon:masterfrom
chiliec:fix-x11-numpad-numlock-off

Conversation

@chiliec
@chiliec chiliec commented Oct 21, 2026
Copy link
Copy Markdown
Contributor

Closes #433.

Problem

X11 and Wayland each carried their own hand-maintained keysym → Key table. The X11 table only covered the NumLock-on numpad keysyms (XK_KP_0..XK_KP_9). With NumLock off, X11 resolves the numpad through the active modifier state and reports XK_KP_Insert, XK_KP_End, XK_KP_Down, … instead — none of which were in the table, so they fell through to the catch-all arm and were silently dropped. Wayland derives Key from the level-0 (NumLock-invariant) keysym and already mapped those, so the numpad worked there in both states.

Fix

Hoist a single pub fn keysym_to_key(sym: u32) -> Option<Key> into xkb_keysyms.rs (which already owns the XKB_KEY_* constants) as the issue suggested, and call it from both backends. The function maps both the NumLock-on (KP_0..KP_9) and NumLock-off (KP_Insert/KP_End/…) numpad keysyms, so X11 picks up the missing entries as a side effect. Removes ~230 lines of duplicated table.

Verification

Added a unit test module to xkb_keysyms.rs covering the NumLock-off X11 case the issue asked for, plus the NumLock-on case and an unmapped-keysym case.

$ cargo test --lib
test result: ok. 58 passed; 0 failed; 0 ignored; 0 measured; 0 filtered out

RED→GREEN confirmed: reverting the fix to map only the NumLock-on numpad names (the original X11 behaviour) makes numpad_maps_with_numlock_off fail; the fix makes it pass.

Also built both backends in isolation to confirm neither table lost coverage:

$ cargo build --no-default-features --features "x11,dlopen"      # Finished
$ cargo build --no-default-features --features "wayland,dlopen"   # Finished

Verified on Linux (x86_64), stable Rust. No hardware/display needed — keysym_to_key is a pure function over keysym values, which also makes the X11 side unit-testable for the first time.

The X11 and Wayland backends each carried a separate hand-maintained
keysym -> Key table. The X11 table only mapped the NumLock-on numpad
keysyms (KP_0..KP_9), so with NumLock off, where the numpad reports
KP_Insert/KP_End/KP_Down/... instead, every numpad key fell through
to the catch-all arm and was silently dropped.

Hoist a single keysym_to_key() into xkb_keysyms.rs covering both the
NumLock-on and NumLock-off numpad keysyms, and call it from both
backends. X11 picks up the missing entries as a side effect; Wayland
behaviour is unchanged.

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

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Numpad keys do nothing on X11 with NumLock off; keysym table duplicated with Wayland

1 participant

0