gui: map evdev keycodes to HID directly, bypassing host keyboard layout#229
Open
SolAstrius wants to merge 1 commit into
Open
gui: map evdev keycodes to HID directly, bypassing host keyboard layout#229SolAstrius wants to merge 1 commit into
SolAstrius wants to merge 1 commit into
Conversation
…tion Signed-off-by: Sol Astrius <sol@astrius.ink>
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
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) andXGetKeyboardMapping()'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:
wl_keyboard.keydeliverskeyas the evdev keycode. Map directly viawayland_evdev_keycode_to_hid().xkey.keycodeis 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.