x11: subscribe to Present extension configure notify events
The hope here is that the nvidia-specific resize issue might have a workaround if it is emitting some other events that we were previously not listening for. This commit optionally enables the Present extension and listens for its version of CONFIGURE_NOTIFY, routing it through the same logic as the base CONFIGURE_NOTIFY event. On my AMD hardware under Gnome, I see something like: ``` 18:04:26.476 TRACE window::os::x11::window > Present::ConfigureNotify: width 1168 -> 1180, height 858 -> 873, dpi 124.7998046875 -> 124.7998046875 18:04:26.478 TRACE window::os::x11::window > Ignoring X::ConfigureNotify (1180x873 dpi=124.7998046875) because width,height,dpi are unchanged ``` with the Present event firing before the X event. Let's see how this goes. refs: #2063 refs: #1992
This commit is contained in:
1 parent
402e5b7382
commit
da59a22297
4 files changed
+89
-79
No files matched your search
Generated
+23
-35
@@ -135,17 +135,16 @@ dependencies = [
|
||||
|
||||
[[package]]
|
||||
name = "async-global-executor"
|
||||
version = "2.0.4"
|
||||
version = "2.1.0"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "c290043c9a95b05d45e952fb6383c67bcb61471f60cfa21e890dba6654234f43"
|
||||
checksum = "fd8b508d585e01084059b60f06ade4cb7415cd2e4084b71dd1cb44e7d3fb9880"
|
||||
dependencies = [
|
||||
"async-channel",
|
||||
"async-executor",
|
||||
"async-io",
|
||||
"async-mutex",
|
||||
"async-lock",
|
||||
"blocking",
|
||||
"futures-lite",
|
||||
"num_cpus",
|
||||
"once_cell",
|
||||
]
|
||||
|
||||
@@ -177,15 +176,6 @@ dependencies = [
|
||||
"event-listener",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "async-mutex"
|
||||
version = "1.4.0"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "479db852db25d9dbf6204e6cb6253698f175c15726470f78af0d918e99d6156e"
|
||||
dependencies = [
|
||||
"event-listener",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "async-net"
|
||||
version = "1.6.1"
|
||||
@@ -261,9 +251,9 @@ checksum = "30696a84d817107fc028e049980e09d5e140e8da8f1caeb17e8e950658a3cea9"
|
||||
|
||||
[[package]]
|
||||
name = "async-trait"
|
||||
version = "0.1.53"
|
||||
version = "0.1.56"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "ed6aa3524a2dfcf9fe180c51eae2b58738348d819517ceadf95789c51fff7600"
|
||||
checksum = "96cf8829f67d2eab0b2dfa42c5d0ef737e0724e4a82b01b3e292456202b19716"
|
||||
dependencies = [
|
||||
"proc-macro2",
|
||||
"quote",
|
||||
@@ -310,7 +300,7 @@ dependencies = [
|
||||
"cc",
|
||||
"cfg-if 1.0.0",
|
||||
"libc",
|
||||
"miniz_oxide 0.5.1",
|
||||
"miniz_oxide 0.5.3",
|
||||
"object",
|
||||
"rustc-demangle",
|
||||
]
|
||||
@@ -432,9 +422,9 @@ dependencies = [
|
||||
|
||||
[[package]]
|
||||
name = "bumpalo"
|
||||
version = "3.9.1"
|
||||
version = "3.10.0"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "a4a45a46ab1f2412e53d3a0ade76ffad2025804294569aae387231a0cd6e0899"
|
||||
checksum = "37ccbd214614c6783386c1af30caf03192f17891059cecc394b4fb119e363de3"
|
||||
|
||||
[[package]]
|
||||
name = "byte-tools"
|
||||
@@ -1232,14 +1222,12 @@ dependencies = [
|
||||
|
||||
[[package]]
|
||||
name = "flate2"
|
||||
version = "1.0.23"
|
||||
version = "1.0.24"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "b39522e96686d38f4bc984b9198e3a0613264abaebaff2c5c918bfa6b6da09af"
|
||||
checksum = "f82b0f4c27ad9f8bfd1f3208d882da2b09c301bc1c828fd3a00d0216d2fbbff6"
|
||||
dependencies = [
|
||||
"cfg-if 1.0.0",
|
||||
"crc32fast",
|
||||
"libc",
|
||||
"miniz_oxide 0.5.1",
|
||||
"miniz_oxide 0.5.3",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
@@ -2013,9 +2001,9 @@ dependencies = [
|
||||
|
||||
[[package]]
|
||||
name = "libz-sys"
|
||||
version = "1.1.6"
|
||||
version = "1.1.8"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "92e7e15d7610cce1d9752e137625f14e61a28cd45929b6e12e47b50fe154ee2e"
|
||||
checksum = "9702761c3935f8cc2f101793272e202c72b99da8f4224a19ddcf1279a6450bbf"
|
||||
dependencies = [
|
||||
"cc",
|
||||
"libc",
|
||||
@@ -2239,9 +2227,9 @@ dependencies = [
|
||||
|
||||
[[package]]
|
||||
name = "miniz_oxide"
|
||||
version = "0.5.1"
|
||||
version = "0.5.3"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "d2b29bd4bc3f33391105ebee3589c19197c4271e3e5a9ec9bfe8127eeff8f082"
|
||||
checksum = "6f5c75688da582b8ffc1f1799e9db273f32133c49e048f614d22ec3256773ccc"
|
||||
dependencies = [
|
||||
"adler",
|
||||
]
|
||||
@@ -2304,7 +2292,7 @@ dependencies = [
|
||||
[[package]]
|
||||
name = "mlua"
|
||||
version = "0.8.0-beta.5"
|
||||
source = "git+https://github.com/khvzak/mlua?branch=master#4f06f614a98b2fcbcac325a90837af7c2f5f5201"
|
||||
source = "git+https://github.com/khvzak/mlua?branch=master#4afca8f5bbe0ecd0c6730a816552aee56c9b8d88"
|
||||
dependencies = [
|
||||
"bstr 0.2.17",
|
||||
"cc",
|
||||
@@ -2684,12 +2672,12 @@ checksum = "624a8340c38c1b80fd549087862da4ba43e08858af025b236e509b6649fc13d5"
|
||||
|
||||
[[package]]
|
||||
name = "open"
|
||||
version = "2.1.2"
|
||||
version = "2.1.3"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "e0524af9508f9b5c4eb41dce095860456727748f63b478d625f119a70e0d764a"
|
||||
checksum = "f2423ffbf445b82e58c3b1543655968923dd06f85432f10be2bb4f1b7122f98c"
|
||||
dependencies = [
|
||||
"pathdiff",
|
||||
"winapi 0.3.9",
|
||||
"windows-sys",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
@@ -3001,7 +2989,7 @@ dependencies = [
|
||||
"bitflags",
|
||||
"crc32fast",
|
||||
"deflate",
|
||||
"miniz_oxide 0.5.1",
|
||||
"miniz_oxide 0.5.3",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
@@ -3980,9 +3968,9 @@ checksum = "8fb1df15f412ee2e9dfc1c504260fa695c1c3f10fe9f4a6ee2d2184d7d6450e2"
|
||||
|
||||
[[package]]
|
||||
name = "syn"
|
||||
version = "1.0.95"
|
||||
version = "1.0.96"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "fbaf6116ab8924f39d52792136fb74fd60a80194cf1b1c6ffa6453eef1c3f942"
|
||||
checksum = "0748dd251e24453cb8717f0354206b91557e4ec8703673a4b30208f2abaf1ebf"
|
||||
dependencies = [
|
||||
"proc-macro2",
|
||||
"quote",
|
||||
@@ -5233,7 +5221,7 @@ dependencies = [
|
||||
[[package]]
|
||||
name = "xcb"
|
||||
version = "1.1.1"
|
||||
source = "git+https://github.com/wez/rust-xcb?branch=ffi#362404a8f647da4f46cf7ed2631a4b7b0daf437c"
|
||||
source = "git+https://github.com/wez/rust-xcb?branch=ffi#990a0212230acea2baf6f658e68e2f44bf7a8a1f"
|
||||
dependencies = [
|
||||
"bitflags",
|
||||
"libc",
|
||||
|
||||
+1
-1
@@ -67,7 +67,7 @@ winreg = "0.10"
|
||||
dirs-next = "2.0"
|
||||
filedescriptor = { version="0.8", path = "../filedescriptor" }
|
||||
x11 = {version ="2.19", features = ["xlib_xcb"]}
|
||||
xcb = {version="1.1", features=["render", "randr", "xkb", "xlib_xcb"]}
|
||||
xcb = {version="1.1", features=["render", "randr", "xkb", "xlib_xcb", "present"]}
|
||||
xkbcommon = { version = "0.5.0-beta.0", features = ["x11", "wayland"], git="https://github.com/wez/xkbcommon-rs.git", branch="key-by-name"}
|
||||
#xkbcommon = { version = "0.6", features = ["x11", "wayland"], path="../../xkbcommon-rs" }
|
||||
mio = {version="0.8", features=["os-ext"]}
|
||||
|
||||
@@ -93,6 +93,7 @@ fn window_id_from_event(event: &xcb::Event) -> Option<xcb::x::Window> {
|
||||
match event {
|
||||
xcb::Event::X(xcb::x::Event::Expose(e)) => Some(e.window()),
|
||||
xcb::Event::X(xcb::x::Event::ConfigureNotify(e)) => Some(e.window()),
|
||||
xcb::Event::Present(xcb::present::Event::ConfigureNotify(e)) => Some(e.window()),
|
||||
xcb::Event::X(xcb::x::Event::KeyPress(e)) => Some(e.event()),
|
||||
xcb::Event::X(xcb::x::Event::KeyRelease(e)) => Some(e.event()),
|
||||
xcb::Event::X(xcb::x::Event::MotionNotify(e)) => Some(e.event()),
|
||||
@@ -325,6 +326,7 @@ impl XConnection {
|
||||
let (conn, screen_num) = xcb::Connection::connect_with_xlib_display_and_extensions(
|
||||
&[xcb::Extension::Xkb],
|
||||
&[
|
||||
xcb::Extension::Present,
|
||||
xcb::Extension::RandR,
|
||||
xcb::Extension::Render,
|
||||
xcb::Extension::Xkb,
|
||||
|
||||
+63
-43
@@ -356,6 +356,52 @@ impl XWindowInner {
|
||||
self.do_mouse_event(event)
|
||||
}
|
||||
|
||||
fn configure_notify(&mut self, source: &str, width: u16, height: u16) -> anyhow::Result<()> {
|
||||
let conn = self.conn();
|
||||
self.update_ime_position();
|
||||
|
||||
let dpi = conn.default_dpi();
|
||||
|
||||
if width == self.width && height == self.height && dpi == self.dpi {
|
||||
// Effectively unchanged; perhaps it was simply moved?
|
||||
// Do nothing!
|
||||
log::trace!(
|
||||
"Ignoring {source} ({width}x{height} dpi={dpi}) \
|
||||
because width,height,dpi are unchanged",
|
||||
);
|
||||
return Ok(());
|
||||
}
|
||||
|
||||
log::trace!(
|
||||
"{source}: width {} -> {}, height {} -> {}, dpi {} -> {}",
|
||||
self.width,
|
||||
width,
|
||||
self.height,
|
||||
height,
|
||||
self.dpi,
|
||||
dpi
|
||||
);
|
||||
|
||||
self.width = width;
|
||||
self.height = height;
|
||||
self.dpi = dpi;
|
||||
|
||||
let dimensions = Dimensions {
|
||||
pixel_width: self.width as usize,
|
||||
pixel_height: self.height as usize,
|
||||
dpi: self.dpi as usize,
|
||||
};
|
||||
|
||||
self.queue_pending(WindowEvent::Resized {
|
||||
dimensions,
|
||||
window_state: self.get_window_state().unwrap_or(WindowState::default()),
|
||||
// Assume that we're live resizing: we don't know for sure,
|
||||
// but it seems like a reasonable assumption
|
||||
live_resizing: true,
|
||||
});
|
||||
Ok(())
|
||||
}
|
||||
|
||||
pub fn dispatch_event(&mut self, event: &Event) -> anyhow::Result<()> {
|
||||
let conn = self.conn();
|
||||
match event {
|
||||
@@ -368,50 +414,11 @@ impl XWindowInner {
|
||||
expose.count(),
|
||||
);
|
||||
}
|
||||
Event::Present(xcb::present::Event::ConfigureNotify(cfg)) => {
|
||||
self.configure_notify("Present::ConfigureNotify", cfg.width(), cfg.height())?;
|
||||
}
|
||||
Event::X(xcb::x::Event::ConfigureNotify(cfg)) => {
|
||||
self.update_ime_position();
|
||||
|
||||
let width = cfg.width();
|
||||
let height = cfg.height();
|
||||
let dpi = conn.default_dpi();
|
||||
|
||||
if width == self.width && height == self.height && dpi == self.dpi {
|
||||
// Effectively unchanged; perhaps it was simply moved?
|
||||
// Do nothing!
|
||||
log::trace!(
|
||||
"Ignoring CONFIGURE_NOTIFY ({width}x{height} dpi={dpi}) \
|
||||
because width,height,dpi are unchanged"
|
||||
);
|
||||
return Ok(());
|
||||
}
|
||||
|
||||
log::trace!(
|
||||
"CONFIGURE_NOTIFY: width {} -> {}, height {} -> {}, dpi {} -> {}",
|
||||
self.width,
|
||||
width,
|
||||
self.height,
|
||||
height,
|
||||
self.dpi,
|
||||
dpi
|
||||
);
|
||||
|
||||
self.width = width;
|
||||
self.height = height;
|
||||
self.dpi = dpi;
|
||||
|
||||
let dimensions = Dimensions {
|
||||
pixel_width: self.width as usize,
|
||||
pixel_height: self.height as usize,
|
||||
dpi: self.dpi as usize,
|
||||
};
|
||||
|
||||
self.queue_pending(WindowEvent::Resized {
|
||||
dimensions,
|
||||
window_state: self.get_window_state().unwrap_or(WindowState::default()),
|
||||
// Assume that we're live resizing: we don't know for sure,
|
||||
// but it seems like a reasonable assumption
|
||||
live_resizing: true,
|
||||
});
|
||||
self.configure_notify("X::ConfigureNotify", cfg.width(), cfg.height())?;
|
||||
}
|
||||
Event::X(xcb::x::Event::KeyPress(key_press)) => {
|
||||
self.copy_and_paste.time = key_press.time();
|
||||
@@ -1045,6 +1052,19 @@ impl XWindow {
|
||||
window_handle.set_window_position(ScreenPoint::new(x.into(), y.into()));
|
||||
}
|
||||
|
||||
if conn
|
||||
.active_extensions()
|
||||
.any(|e| e == xcb::Extension::Present)
|
||||
{
|
||||
let event_id = conn.generate_id();
|
||||
conn.check_request(conn.send_request_checked(&xcb::present::SelectInput {
|
||||
eid: event_id,
|
||||
window: window_id,
|
||||
event_mask: xcb::present::EventMask::CONFIGURE_NOTIFY,
|
||||
}))
|
||||
.context("Present::SelectInput")?;
|
||||
}
|
||||
|
||||
Ok(window_handle)
|
||||
}
|
||||
}
|
||||
|
||||
Reference in new issue
Block a user