Skip to content

gui: map evdev keycodes to HID directly, bypassing host keyboard layout#229

Open
SolAstrius wants to merge 1 commit into
LekKit:stagingfrom
pufit:gui/evdev-hid-keycodes
Open

gui: map evdev keycodes to HID directly, bypassing host keyboard layout#229
SolAstrius wants to merge 1 commit into
LekKit:stagingfrom
pufit:gui/evdev-hid-keycodes

Conversation

@SolAstrius

Copy link
Copy Markdown
Contributor

Both the Wayland and X11 backends previously delivered HID usage codes based on the keysym for each physical key. xkb_state_key_get_one_sym() (Wayland) and XGetKeyboardMapping()'s slot 0 (X11) both apply the user's loaded keyboard layout, so a host running Workman / Dvorak / Colemak / AZERTY would feed the emulator layout-translated letters rather than physical key positions.

For an emulator pretending to be hardware with its own keyboard — or its own layout assumptions, e.g. the ZX Spectrum expects USB-HID-style positions for its 8×5 matrix lookup — that's the wrong abstraction. Layout translation should happen inside the emulated machine, not on the host side.

This routes both backends through a direct evdev-keycode → HID usage table:

  • Wayland: wl_keyboard.key delivers key as the evdev keycode. Map directly via wayland_evdev_keycode_to_hid().
  • X11: xkey.keycode is evdev+8 on Linux X11. Subtract 8 and look up in the same table. Falls through to the existing xkb-keysym path for non-Linux X11 servers (where the offset isn't 8) or for keycodes outside the standard evdev range.

Result: the emulator sees the physical key the user pressed, regardless of host keyboard layout. On Wayland the keysym path is now fully unreachable, so it's removed; on X11 it's retained as the non-Linux fallback.

…tion

Signed-off-by: Sol Astrius <sol@astrius.ink>
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.

1 participant