From f3e49e1b05a022a3f4b116721035790fd839b367 Mon Sep 17 00:00:00 2001 From: Michael Sloan Date: Sun, 14 Sep 2025 13:09:15 -0600 Subject: [PATCH] x11: Don't skip consecutive same key press events in the same batch (#38154) This has noticeable misbehavior when framerates are low (in my case this sometimes happens when CPUs are throttled and compilation is happening), as now a batch of x11 events can contain events over the span of 100s of millis. So in that case, key press repetitions with quite normal typing are skipped. Under normal operating conditions it can be reproduced by running this and quickly switching to Zed: > sleep 1; for i in {1..5}; do xdotool type --delay 5 "aaaaaa "; xdotool key Return; done Output before looks like: ``` aaa aaaaa aaa aaa aaaa ``` Output after looks like: ``` aaaaaa aaaaaa aaaaaa aaaaaa aaaaaa ``` This behavior was added in #13955. Release Notes: - N/A --- crates/gpui/src/platform/linux/x11/client.rs | 12 +----------- 1 file changed, 1 insertion(+), 11 deletions(-) diff --git a/crates/gpui/src/platform/linux/x11/client.rs b/crates/gpui/src/platform/linux/x11/client.rs index 42c59701d3ee644b99bc8bb58002b429265c1a45..e6af7c0d17a54223ecee7a9801eb7a1e59fd6a1a 100644 --- a/crates/gpui/src/platform/linux/x11/client.rs +++ b/crates/gpui/src/platform/linux/x11/client.rs @@ -28,7 +28,7 @@ use x11rb::{ protocol::xkb::ConnectionExt as _, protocol::xproto::{ AtomEnum, ChangeWindowAttributesAux, ClientMessageData, ClientMessageEvent, - ConnectionExt as _, EventMask, KeyPressEvent, Visibility, + ConnectionExt as _, EventMask, Visibility, }, protocol::{Event, randr, render, xinput, xkb, xproto}, resource_manager::Database, @@ -525,7 +525,6 @@ impl X11Client { let mut windows_to_refresh = HashSet::new(); let mut last_key_release = None; - let mut last_key_press: Option = None; // event handlers for new keyboard / remapping refresh the state without using event // details, this deduplicates them. @@ -545,7 +544,6 @@ impl X11Client { if let Some(last_key_release) = last_key_release.take() { events.push(last_key_release); } - last_key_press = None; events.push(last_keymap_change_event); } @@ -558,16 +556,9 @@ impl X11Client { if let Some(last_key_release) = last_key_release.take() { events.push(last_key_release); } - last_key_press = None; events.push(last_keymap_change_event); } - if let Some(last_press) = last_key_press.as_ref() - && last_press.detail == key_press.detail - { - continue; - } - if let Some(Event::KeyRelease(key_release)) = last_key_release.take() { @@ -580,7 +571,6 @@ impl X11Client { } } events.push(Event::KeyPress(key_press)); - last_key_press = Some(key_press); } Event::XkbNewKeyboardNotify(_) | Event::XkbMapNotify(_) => { if let Some(release_event) = last_key_release.take() {