ZIm/crates/gpui/src
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
..
app Add Caps Lock support (#30470) 2025-06-18 00:43:33 +00:00
elements debugger: Add memory view (#33955) 2025-07-14 16:32:06 +02:00
keymap Sketch in a table for the keybindings UI (#32436) 2025-06-30 19:25:11 -04:00
platform linux: Fix spacebar not working with multiple keyboard layouts (#34514) 2025-07-16 19:25:13 +05:30
text_system Improve terminal rendering performance (#33345) 2025-07-08 09:05:01 -06:00
window gpui: Improve window.prompt to support ESC with non-English cancel text on macOS (#29538) 2025-05-30 15:26:27 +00:00
action.rs gpui: Reduce manual shifting & other minor improvements (#34407) 2025-07-15 16:39:33 +02:00
app.rs gpui: Reduce manual shifting & other minor improvements (#34407) 2025-07-15 16:39:33 +02:00
arena.rs chore: Bump Rust version to 1.88 (#33439) 2025-06-26 20:54:19 +02:00
asset_cache.rs gpui: Relax AssetLogger trait bounds (#29450) 2025-04-29 12:43:54 -07:00
assets.rs chore: Bump Rust edition to 2024 (#27800) 2025-03-31 20:55:27 +02:00
bounds_tree.rs gpui: Optimize the ordering update in the BoundsTree (#31025) 2025-05-30 08:23:27 -07:00
color.rs gpui: Reduce manual shifting & other minor improvements (#34407) 2025-07-15 16:39:33 +02:00
colors.rs gpui: Add a standard text example (#30747) 2025-05-16 17:35:44 +02:00
element.rs Add initial element inspector for Zed development (#31315) 2025-05-23 23:08:59 +00:00
executor.rs Add a test for remote tool use by the agent (#30289) 2025-05-08 16:53:04 -04:00
geometry.rs Migrate to schemars version 1.0 (#33635) 2025-06-30 21:07:28 +00:00
global.rs Eliminate GPUI View, ViewContext, and WindowContext types (#22632) 2025-01-26 03:02:45 +00:00
gpui.rs Misc nitpicks, changes too small / unrelated to be in other PRs (#32768) 2025-06-15 19:51:04 +00:00
input.rs Implement character index for point (#23989) 2025-02-04 20:15:43 +00:00
inspector.rs Add a live Rust style editor to inspector to edit a sequence of no-argument style modifiers (#31443) 2025-05-26 17:43:57 +00:00
interactive.rs gpui: Simplify Action macros + support doc comments in actions! (#33263) 2025-06-24 04:34:51 +00:00
key_dispatch.rs gpui: Simplify Action macros + support doc comments in actions! (#33263) 2025-06-24 04:34:51 +00:00
keymap.rs gpui: Simplify Action macros + support doc comments in actions! (#33263) 2025-06-24 04:34:51 +00:00
path_builder.rs gpui: Improve path rendering & global multisample anti-aliasing (#29718) 2025-07-02 09:41:42 -07:00
platform.rs Windows screen sharing (#34223) 2025-07-10 14:02:00 -07:00
prelude.rs Sketch in a table for the keybindings UI (#32436) 2025-06-30 19:25:11 -04:00
scene.rs gpui: Improve path rendering & global multisample anti-aliasing (#29718) 2025-07-02 09:41:42 -07:00
shared_string.rs Migrate to schemars version 1.0 (#33635) 2025-06-30 21:07:28 +00:00
shared_uri.rs Rework loading images from files (#7088) 2024-01-30 11:26:02 -05:00
style.rs Add a live Rust style editor to inspector to edit a sequence of no-argument style modifiers (#31443) 2025-05-26 17:43:57 +00:00
styled.rs Add a live Rust style editor to inspector to edit a sequence of no-argument style modifiers (#31443) 2025-05-26 17:43:57 +00:00
subscription.rs gpui: Replace Mutex with RefCell for SubscriberSet (#30907) 2025-05-19 11:08:04 +02:00
svg_renderer.rs Use anyhow more idiomatically (#31052) 2025-05-20 23:06:07 +00:00
taffy.rs gpui: Disable rounding in the layout engine (#31836) 2025-06-24 20:28:57 +00:00
test.rs Add seed argument to #[gpui::test] attribute macro (#26764) 2025-03-14 13:40:02 -03:00
text_system.rs Improve terminal rendering performance (#33345) 2025-07-08 09:05:01 -06:00
util.rs chore: Bump Rust version to 1.88 (#33439) 2025-06-26 20:54:19 +02:00
view.rs Add initial element inspector for Zed development (#31315) 2025-05-23 23:08:59 +00:00
window.rs gpui: Add cx.intercept_keystrokes API to intercept keystrokes before action dispatch (#34084) 2025-07-09 22:44:32 +00:00