From 8e54fd50f1403e99c5ed723f868b7fa41a1ffaa4 Mon Sep 17 00:00:00 2001 From: Ottatop Date: Mon, 3 Feb 2025 19:07:40 -0600 Subject: [PATCH] xwm: Update override-redirect flag on map request Stops `configure` and `set_mapped` from failing on windows that were created with override-redirect set but which later unset the flag before mapping --- src/xwayland/xwm/mod.rs | 8 ++++++++ src/xwayland/xwm/surface.rs | 10 +++++----- 2 files changed, 13 insertions(+), 5 deletions(-) diff --git a/src/xwayland/xwm/mod.rs b/src/xwayland/xwm/mod.rs index 52fd2c686bb0..ba0819018d65 100644 --- a/src/xwayland/xwm/mod.rs +++ b/src/xwayland/xwm/mod.rs @@ -1422,6 +1422,14 @@ where } surface.state.lock().unwrap().mapped_onto = Some(frame_win); + + // A MapRequest can only happen when an X11 window does not have the + // override-redirect flag set. It's possible for a window to be created as + // override-redirect and later set the flag to false before mapping. + // In that case, we set the X11Surface's override-redirect state to false here + // to prevent `set_mapped` and `configure` from failing. + surface.state.lock().unwrap().override_redirect = false; + drop(_guard); state.map_window_request(xwm_id, surface); } diff --git a/src/xwayland/xwm/surface.rs b/src/xwayland/xwm/surface.rs index 8e9fbe3f0700..09748b99fba0 100644 --- a/src/xwayland/xwm/surface.rs +++ b/src/xwayland/xwm/surface.rs @@ -43,7 +43,6 @@ pub struct X11Surface { xwm: Option, client_scale: Option>, window: X11Window, - override_redirect: bool, conn: Weak, atoms: super::Atoms, pub(crate) state: Arc>, @@ -61,6 +60,7 @@ pub(crate) struct SharedSurfaceState { pub(super) wl_surface_serial: Option, pub(super) mapped_onto: Option, pub(super) geometry: Rectangle, + pub(super) override_redirect: bool, // The associated wl_surface. pub(crate) wl_surface: Option, @@ -170,7 +170,6 @@ impl X11Surface { xwm: xwm.map(|wm| wm.id), client_scale: xwm.map(|wm| wm.client_scale.clone()), window, - override_redirect, conn, atoms, state: Arc::new(Mutex::new(SharedSurfaceState { @@ -180,6 +179,7 @@ impl X11Surface { wl_surface: None, mapped_onto: None, geometry, + override_redirect, title: String::from(""), class: String::from(""), instance: String::from(""), @@ -216,7 +216,7 @@ impl X11Surface { /// /// It is an error to call this function on override redirect windows pub fn set_mapped(&self, mapped: bool) -> Result<(), X11SurfaceError> { - if self.override_redirect { + if self.is_override_redirect() { return Err(X11SurfaceError::UnsupportedForOverrideRedirect); } @@ -251,7 +251,7 @@ impl X11Surface { /// Returns if this window has the override redirect flag set or not pub fn is_override_redirect(&self) -> bool { - self.override_redirect + self.state.lock().unwrap().override_redirect } /// Returns if the window is currently mapped or not @@ -272,7 +272,7 @@ impl X11Surface { /// If `rect` is `None` a synthetic configure event with the existing state will be send. pub fn configure(&self, rect: impl Into>>) -> Result<(), X11SurfaceError> { let rect = rect.into(); - if self.override_redirect && rect.is_some() { + if self.is_override_redirect() && rect.is_some() { return Err(X11SurfaceError::UnsupportedForOverrideRedirect); }