gpui: Add more flushing of x11 requests (#33407)

Flushes should happen after sending messages to X11 when effects should
be applied quickly. This is not needed for requests that return replies
since it automatically flushes in that case.

Release Notes:

- N/A
This commit is contained in:
Michael Sloan 2025-06-25 13:46:15 -06:00 committed by GitHub
parent e5c812fbcb
commit aae4778b4e
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
2 changed files with 34 additions and 28 deletions

View file

@ -1,4 +1,4 @@
use crate::Capslock;
use crate::{Capslock, xcb_flush};
use core::str;
use std::{
cell::RefCell,
@ -378,6 +378,7 @@ impl X11Client {
xcb_connection
.xkb_use_extension(XKB_X11_MIN_MAJOR_XKB_VERSION, XKB_X11_MIN_MINOR_XKB_VERSION),
)?;
assert!(xkb.supported);
let events = xkb::EventType::STATE_NOTIFY
| xkb::EventType::MAP_NOTIFY
@ -401,7 +402,6 @@ impl X11Client {
&xkb::SelectEventsAux::new(),
),
)?;
assert!(xkb.supported);
let xkb_context = xkbc::Context::new(xkbc::CONTEXT_NO_FLAGS);
let xkb_device_id = xkbc::x11::get_core_keyboard_device_id(&xcb_connection);
@ -484,6 +484,8 @@ impl X11Client {
})
.map_err(|err| anyhow!("Failed to initialize XDP event source: {err:?}"))?;
xcb_flush(&xcb_connection);
Ok(X11Client(Rc::new(RefCell::new(X11ClientState {
modifiers: Modifiers::default(),
capslock: Capslock::default(),
@ -1523,6 +1525,7 @@ impl LinuxClient for X11Client {
),
)
.log_err();
xcb_flush(&state.xcb_connection);
let window_ref = WindowRef {
window: window.0.clone(),
@ -1554,19 +1557,18 @@ impl LinuxClient for X11Client {
};
state.cursor_styles.insert(focused_window, style);
state
.xcb_connection
.change_window_attributes(
check_reply(
|| "Failed to set cursor style",
state.xcb_connection.change_window_attributes(
focused_window,
&ChangeWindowAttributesAux {
cursor: Some(cursor),
..Default::default()
},
)
.anyhow()
.and_then(|cookie| cookie.check().anyhow())
.context("X11: Failed to set cursor style")
.log_err();
),
)
.log_err();
state.xcb_connection.flush().log_err();
}
fn open_uri(&self, uri: &str) {
@ -2087,6 +2089,7 @@ fn xdnd_send_finished(
xcb_connection.send_event(false, target, EventMask::default(), message),
)
.log_err();
xcb_connection.flush().log_err();
}
fn xdnd_send_status(
@ -2109,6 +2112,7 @@ fn xdnd_send_status(
xcb_connection.send_event(false, target, EventMask::default(), message),
)
.log_err();
xcb_connection.flush().log_err();
}
/// Recomputes `pointer_device_states` by querying all pointer devices.
@ -2262,6 +2266,6 @@ fn create_invisible_cursor(
connection.free_pixmap(empty_pixmap)?;
connection.flush()?;
xcb_flush(connection);
Ok(cursor)
}