ZIm/crates/gpui/src/platform
Smit Barmase d4110fd2ab
linux: Fix spacebar not working with multiple keyboard layouts (#34514)
Closes #26468 #16667

This PR fixes the spacebar not working with multiple keyboard layouts on
Linux X11. I have tested this with Czech, Russian, German, German Neo 2,
etc. It seems to work correctly.

`XkbStateNotify` events correctly update XKB state with complete
modifier info (depressed/latched/locked), but `KeyPress/KeyRelease`
events immediately overwrite that state using `update_mask()` with only
raw X11 modifier bits. This breaks xkb state as we reset `latched_mods`
and `locked_mods` to 0, as well as we might not correctly handle cases
where this new xkb state needs to change.

Previous logic is flawed because `KeyPress/KeyRelease` event only gives
you depressed modifiers (`event.state`) and not others, which we try to
fill in from `previous_xkb_state`. This patch was introduced to fix
capitalization issue with Neo 2
(https://github.com/zed-industries/zed/pull/14466) and later to fix
wrong keys with German layout
(https://github.com/zed-industries/zed/pull/31193), both of which I have
tested this PR with.

Now, instead of manually managing XKB state, we use the `update_key`
method, which internally handles modifier states and other cases we
might have missed.
  
From `update_key` docs:

> Update the keyboard state to reflect a given key being pressed or
released.
>
> This entry point is intended for programs which track the keyboard
state explictly (like an evdev client). If the state is serialized to
you by a master process (like a Wayland compositor) using functions like
`xkb_state_serialize_mods()`, you should use `xkb_state_update_mask()`
instead. **_The two functins should not generally be used together._**
>                
> A series of calls to this function should be consistent; that is, a
call with `xkb::KEY_DOWN` for a key should be matched by an
`xkb::KEY_UP`; if a key is pressed twice, it should be released twice;
etc. Otherwise (e.g. due to missed input events), situations like "stuck
modifiers" may occur.
>              
> This function is often used in conjunction with the function
`xkb_state_key_get_syms()` (or `xkb_state_key_get_one_sym()`), for
example, when handling a key event. In this case, you should prefer to
get the keysyms *before* updating the key, such that the keysyms
reported for the key event are not affected by the event itself. This is
the conventional behavior.

  
Release Notes:

- Fix the issue where the spacebar doesn’t work with multiple keyboard
layouts on Linux X11.
2025-07-16 19:25:13 +05:30
..
blade gpui: Improve path rendering & global multisample anti-aliasing (#29718) 2025-07-02 09:41:42 -07:00
linux linux: Fix spacebar not working with multiple keyboard layouts (#34514) 2025-07-16 19:25:13 +05:30
mac title_bar: Add setting to always show menu for Linux and Windows (#34139) 2025-07-09 09:44:11 -07:00
test gpui: Improve path rendering & global multisample anti-aliasing (#29718) 2025-07-02 09:41:42 -07:00
windows windows: Fix an issue where dead keys that require holding shift didn’t work properly (#34264) 2025-07-11 17:19:23 +08:00
app_menu.rs Eliminate GPUI View, ViewContext, and WindowContext types (#22632) 2025-01-26 03:02:45 +00:00
blade.rs Switch to a single GPU context in Blade (#20853) 2024-12-18 14:47:09 -07:00
keyboard.rs gpui: Refactor PlatformKeyboardLayout (#29653) 2025-04-30 08:17:26 +00:00
keystroke.rs Language independent hotkeys (#34053) 2025-07-13 23:00:03 -06:00
linux.rs gpui: Make screen capture dependency optional (#32937) 2025-07-02 10:15:06 -06:00
mac.rs gpui: Make screen capture dependency optional (#32937) 2025-07-02 10:15:06 -06:00
scap_screen_capture.rs Reapply support for X11 screenshare (#28160) 2025-04-06 11:25:29 -06:00
test.rs Introduce a new StreamingEditFileTool (#29733) 2025-05-01 17:37:43 +02:00
windows.rs Windows screen sharing (#34223) 2025-07-10 14:02:00 -07:00