Skip to content

Commit

Permalink
xwm: Update override-redirect flag on map request
Browse files Browse the repository at this point in the history
Stops `configure` and `set_mapped` from failing on windows that were created with override-redirect set but which later unset the flag before mapping
  • Loading branch information
Ottatop authored and Drakulix committed Feb 4, 2025
1 parent 0c2230f commit 8e54fd5
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 5 deletions.
8 changes: 8 additions & 0 deletions src/xwayland/xwm/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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);
}
Expand Down
10 changes: 5 additions & 5 deletions src/xwayland/xwm/surface.rs
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,6 @@ pub struct X11Surface {
xwm: Option<XwmId>,
client_scale: Option<Arc<AtomicU32>>,
window: X11Window,
override_redirect: bool,
conn: Weak<RustConnection>,
atoms: super::Atoms,
pub(crate) state: Arc<Mutex<SharedSurfaceState>>,
Expand All @@ -61,6 +60,7 @@ pub(crate) struct SharedSurfaceState {
pub(super) wl_surface_serial: Option<u64>,
pub(super) mapped_onto: Option<X11Window>,
pub(super) geometry: Rectangle<i32, Logical>,
pub(super) override_redirect: bool,

// The associated wl_surface.
pub(crate) wl_surface: Option<WlSurface>,
Expand Down Expand Up @@ -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 {
Expand All @@ -180,6 +179,7 @@ impl X11Surface {
wl_surface: None,
mapped_onto: None,
geometry,
override_redirect,
title: String::from(""),
class: String::from(""),
instance: String::from(""),
Expand Down Expand Up @@ -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);
}

Expand Down Expand Up @@ -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
Expand All @@ -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<Option<Rectangle<i32, Logical>>>) -> 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);
}

Expand Down

0 comments on commit 8e54fd5

Please sign in to comment.