From 52c9fac23bef41734da6b1846796d79262853733 Mon Sep 17 00:00:00 2001 From: Julian Orth Date: Wed, 19 Feb 2025 16:39:04 +0100 Subject: [PATCH] xwayland: improve damage tracking --- src/ifs/wl_surface.rs | 10 +++++-- src/ifs/wl_surface/x_surface.rs | 11 +++++++- src/ifs/wl_surface/x_surface/xwindow.rs | 36 ++++++++++++++----------- src/tree/toplevel.rs | 4 --- src/xwayland/xwm.rs | 1 + 5 files changed, 39 insertions(+), 23 deletions(-) diff --git a/src/ifs/wl_surface.rs b/src/ifs/wl_surface.rs index 8038ec82..605a9fe7 100644 --- a/src/ifs/wl_surface.rs +++ b/src/ifs/wl_surface.rs @@ -1789,8 +1789,14 @@ impl Node for WlSurface { } fn node_on_focus(self: Rc, seat: &WlSeatGlobal) { - if let Some(tl) = self.toplevel.get() { - tl.tl_on_activate(); + if let Some(xsurface) = self.ext.get().into_xsurface() { + if let Some(window) = xsurface.xwindow.get() { + self.client + .state + .xwayland + .queue + .push(XWaylandEvent::Activate(window.data.clone())); + } } seat.focus_surface(&self); } diff --git a/src/ifs/wl_surface/x_surface.rs b/src/ifs/wl_surface/x_surface.rs index eabfbf65..6ec00063 100644 --- a/src/ifs/wl_surface/x_surface.rs +++ b/src/ifs/wl_surface/x_surface.rs @@ -5,7 +5,7 @@ use { SurfaceExt, WlSurface, WlSurfaceError, }, leaks::Tracker, - tree::ToplevelNode, + tree::{Node, ToplevelNode, ToplevelNodeBase}, utils::clonecell::CloneCell, xwayland::XWaylandEvent, }, @@ -58,6 +58,15 @@ impl SurfaceExt for XSurface { } } + fn focus_node(&self) -> Option> { + if let Some(xwindow) = self.xwindow.get() { + if xwindow.tl_accepts_keyboard_focus() { + return Some(xwindow.x.surface.clone()); + } + } + None + } + fn into_xsurface(self: Rc) -> Option> { Some(self) } diff --git a/src/ifs/wl_surface/x_surface/xwindow.rs b/src/ifs/wl_surface/x_surface/xwindow.rs index 182ce5be..d182a543 100644 --- a/src/ifs/wl_surface/x_surface/xwindow.rs +++ b/src/ifs/wl_surface/x_surface/xwindow.rs @@ -222,7 +222,7 @@ impl Xwindow { } }); slf.x.xwindow.set(Some(slf.clone())); - slf.x.surface.set_toplevel(Some(slf.clone())); + slf.update_toplevel(); Ok(slf) } @@ -296,9 +296,25 @@ impl Xwindow { Change::None => {} } self.data.state.tree_changed(); - if override_redirect { - self.data.state.damage(self.data.info.pending_extents.get()); + self.damage_override_redirect(); + } + + fn damage_override_redirect(&self) { + if !self.data.info.override_redirect.get() { + return; } + let extents = self.x.surface.extents.get(); + let (x, y) = self.x.surface.buffer_abs_pos.get().position(); + let extents = extents.move_(x, y); + self.data.state.damage(extents); + } + + pub fn update_toplevel(self: &Rc) { + let mut toplevel = None; + if !self.data.info.override_redirect.get() { + toplevel = Some(self.clone() as _); + } + self.x.surface.set_toplevel(toplevel); } } @@ -398,14 +414,6 @@ impl ToplevelNodeBase for Xwindow { && self.data.info.input_model.get() != XInputModel::None } - fn tl_on_activate(&self) { - self.data - .state - .xwayland - .queue - .push(XWaylandEvent::Activate(self.data.clone())); - } - fn tl_focus_child(&self) -> Option> { Some(self.x.surface.clone()) } @@ -419,8 +427,6 @@ impl ToplevelNodeBase for Xwindow { let old = self.data.info.extents.replace(*rect); if old != *rect { if self.data.info.override_redirect.get() { - self.data.state.damage(old); - self.data.state.damage(*rect); let (x, y) = rect.center(); let output = self.data.state.find_closest_output(x, y).0; self.x.surface.set_output(&output); @@ -482,9 +488,7 @@ impl StackedNode for Xwindow { stacked_node_impl!(); fn stacked_set_visible(&self, visible: bool) { - let extents = self.x.surface.extents.get(); - let (x, y) = self.x.surface.buffer_abs_pos.get().position(); - self.data.state.damage(extents.move_(x, y)); + self.damage_override_redirect(); self.tl_set_visible(visible); } diff --git a/src/tree/toplevel.rs b/src/tree/toplevel.rs index 1d327a3e..eb274852 100644 --- a/src/tree/toplevel.rs +++ b/src/tree/toplevel.rs @@ -179,10 +179,6 @@ pub trait ToplevelNodeBase: Node { let _ = active; } - fn tl_on_activate(&self) { - // nothing - } - fn tl_focus_child(&self) -> Option> { None } diff --git a/src/xwayland/xwm.rs b/src/xwayland/xwm.rs index 9fb7f510..881b47aa 100644 --- a/src/xwayland/xwm.rs +++ b/src/xwayland/xwm.rs @@ -2115,6 +2115,7 @@ impl Wm { // log::info!("xwin {} or {}", data.window_id, or); if let Some(window) = data.window.get() { window.tl_destroy(); + window.update_toplevel(); window.map_status_changed(); } }