fix: respect xkb keysym remaps for editing keys#15
Open
raviboth wants to merge 1 commit into
Open
Conversation
GDK delivers (keyval, keycode) pairs where the keyval may have been remapped via xkb (e.g. Caps Lock to BackSpace) while the keycode still identifies the original physical key. libghostty's input handling is keycode-driven, so the original physical key wins and the remap is silently dropped. Translate the keyval to the canonical evdev+8 keycode for known editing keys before handing the event to libghostty, and clear the Lock-derived CAPS modifier when the keycode is rewritten so the remap source does not leak its lock state into the synthesized event. Repro: bind Caps Lock to BackSpace in KDE; in Seance, Caps does nothing even though wev reports `sym: BackSpace`. With this patch, Caps acts as Backspace as expected.
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.
Why I'm filing this
I use the Colemak keyboard layout and have Caps Lock remapped to Backspace at the xkb level — this is a very common ergonomic setup (Caps Lock is unused real estate, Backspace gets used constantly, the remap puts it under a home-row finger). Every other app on my system honours the remap. In Seance the remapped key does nothing, which makes the terminal effectively unusable for me without reaching across the keyboard for the real Backspace key.
This patch makes Seance honour the remap.
Summary
xkb-level keysym remaps (e.g. KDE's Caps Lock behaves as Backspace) are silently dropped inside Seance. The remapped key sends nothing to the terminal even though
wevconfirms the Wayland compositor delivers the remapped keysym.Root cause
GDK delivers a
(keyval, hardware_keycode)pair where the keyval reflects the xkb remap but the hardware keycode still identifies the original physical key.handleKeyEventinsrc/pane.zigforwards the raw keycode toghostty_surface_key. libghostty's input handling is keycode-driven (ghostty/src/apprt/embedded.ziglooks up the physical key ininput/keycodes.zigbyentry.native == keycode), so it sees the original physical key and ignores the remap.For Caps Lock to Backspace on Linux: GDK reports
keyval = BackSpace,keycode = 66(Caps physical). libghostty sees keycode 66, identifies it as Caps Lock, and treats the event as a modifier press rather than producing Backspace input.Fix
canonicalKeycode(keyval, keycode)returns the Linux evdev+8 keycode that natively produces the given keyval for a small set of named editing/navigation keys.handleKeyEventuses the canonical keycode when it differs and stripsGHOSTTY_MODS_CAPSin that case so the remap source's Lock state doesn't leak into the event.Repro
wevconfirmssym: BackSpace, utf8: '\b'for the Caps press.Notes / questions for review
gdk_display_map_keyvalwould query GDK for keycodes that produce a given keyval and avoid the hardcoded table. I went with the table because it allocates nothing on a hot input path, the editing-key set is small and stable on Linux, and Seance is already Linux-only perbuild.zig. Open to switching if you'd prefer.Test plan
zig buildsucceeds