From 9b6329b454a51bc7e11ebaa447500ce049035833 Mon Sep 17 00:00:00 2001 From: Wez Furlong Date: Fri, 3 Jun 2022 21:42:01 -0700 Subject: [PATCH] x11: more hacks to deal with missing CONFIGURE_NOTIFY This one triggers a short timer when a focus event is received; when that timer fires, we invalidate the geometry and repaint. refs: #2063 refs: #1992 --- window/src/os/x11/window.rs | 48 ++++++++++++++++++++++++++----------- 1 file changed, 34 insertions(+), 14 deletions(-) diff --git a/window/src/os/x11/window.rs b/window/src/os/x11/window.rs index 583330dff..9da04a8e7 100644 --- a/window/src/os/x11/window.rs +++ b/window/src/os/x11/window.rs @@ -244,7 +244,7 @@ impl XWindowInner { if !self.sure_about_geometry { self.sure_about_geometry = true; - log::trace!("About to paint, but we've unsure about geometry; querying!"); + log::trace!("About to paint, but we're unsure about geometry; querying!"); let geom = self.conn().wait_for_reply(self.conn().send_request( &xcb::x::GetGeometry { drawable: xcb::x::Drawable::Window(self.window_id), @@ -522,21 +522,10 @@ impl XWindowInner { } } Event::X(xcb::x::Event::FocusIn(_)) => { - self.sure_about_geometry = false; - if self.has_focus != Some(true) { - self.has_focus.replace(true); - self.update_ime_position(); - log::trace!("Calling focus_change(true)"); - self.events.dispatch(WindowEvent::FocusChanged(true)); - } + self.focus_changed(true); } Event::X(xcb::x::Event::FocusOut(_)) => { - self.sure_about_geometry = false; - if self.has_focus != Some(false) { - self.has_focus.replace(false); - log::trace!("Calling focus_change(false)"); - self.events.dispatch(WindowEvent::FocusChanged(false)); - } + self.focus_changed(false); } Event::X(xcb::x::Event::LeaveNotify(_)) => { self.events.dispatch(WindowEvent::MouseLeave); @@ -549,6 +538,37 @@ impl XWindowInner { Ok(()) } + fn focus_changed(&mut self, focused: bool) { + log::trace!("focus_changed {focused}, flagging geometry as unsure"); + self.sure_about_geometry = false; + if self.has_focus != Some(focused) { + self.has_focus.replace(focused); + self.update_ime_position(); + log::trace!("Calling focus_change({focused})"); + self.events.dispatch(WindowEvent::FocusChanged(focused)); + } + + // This is a bit gross; in + // we observe that CONFIGURE_NOTIFY isn't being sent around certain + // WM operations when nvidia drivers are in used. + // However, focus events are in the right ballpark, but still happen + // before the new geometry is applied. + // This schedules an invalidation of both our sense of geometry and + // the window a short time after the focus event is processed in the + // hope that it can observe the changed window properties and update + // without the human needing to interact with the window. + let window_id = self.window_id; + promise::spawn::spawn(async move { + async_io::Timer::after(std::time::Duration::from_millis(100)).await; + XConnection::with_window_inner(window_id, |inner| { + inner.sure_about_geometry = false; + inner.invalidate(); + Ok(()) + }); + }) + .detach(); + } + pub fn dispatch_ime_compose_status(&mut self, status: DeadKeyStatus) { self.events .dispatch(WindowEvent::AdviseDeadKeyStatus(status));