From 386d74f926e9d0e8e72e15eef73172c27e1c1814 Mon Sep 17 00:00:00 2001 From: Julian Orth Date: Sun, 3 Mar 2024 15:39:04 +0100 Subject: [PATCH] tree: restack floaters and popups on demand --- src/ifs/wl_surface/xdg_surface.rs | 6 +++++ src/ifs/wl_surface/xdg_surface/xdg_popup.rs | 10 +++++++++ .../wl_surface/xdg_surface/xdg_toplevel.rs | 4 ++++ src/tree/container.rs | 13 +++++++++++ src/tree/float.rs | 22 ++++++++++++++----- src/tree/toplevel.rs | 3 +++ 6 files changed, 52 insertions(+), 6 deletions(-) diff --git a/src/ifs/wl_surface/xdg_surface.rs b/src/ifs/wl_surface/xdg_surface.rs index 51343c00..379d01dc 100644 --- a/src/ifs/wl_surface/xdg_surface.rs +++ b/src/ifs/wl_surface/xdg_surface.rs @@ -328,6 +328,12 @@ impl XdgSurface { popup.set_visible(visible); } } + + fn restack_popups(&self) { + for popup in self.popups.lock().values() { + popup.restack(); + } + } } object_base! { diff --git a/src/ifs/wl_surface/xdg_surface/xdg_popup.rs b/src/ifs/wl_surface/xdg_surface/xdg_popup.rs index ecc64343..078cc31e 100644 --- a/src/ifs/wl_surface/xdg_surface/xdg_popup.rs +++ b/src/ifs/wl_surface/xdg_surface/xdg_popup.rs @@ -259,6 +259,16 @@ impl XdgPopup { self.xdg.detach_node(); self.seat_state.destroy_node(self); } + + pub fn restack(&self) { + let state = &self.xdg.surface.client.state; + let dl = self.display_link.borrow(); + if let Some(dl) = &*dl { + state.root.stacked.add_last_existing(dl); + } + self.xdg.restack_popups(); + state.tree_changed(); + } } object_base! { diff --git a/src/ifs/wl_surface/xdg_surface/xdg_toplevel.rs b/src/ifs/wl_surface/xdg_surface/xdg_toplevel.rs index 52beb17c..f1321176 100644 --- a/src/ifs/wl_surface/xdg_surface/xdg_toplevel.rs +++ b/src/ifs/wl_surface/xdg_surface/xdg_toplevel.rs @@ -634,6 +634,10 @@ impl ToplevelNodeBase for XdgToplevel { fn tl_scanout_surface(&self) -> Option> { Some(self.xdg.surface.clone()) } + + fn tl_restack_popups(&self) { + self.xdg.restack_popups(); + } } impl XdgSurfaceExt for XdgToplevel { diff --git a/src/tree/container.rs b/src/tree/container.rs index 65fbeb5e..20f5ed9d 100644 --- a/src/tree/container.rs +++ b/src/tree/container.rs @@ -759,6 +759,7 @@ impl ContainerNode { } self.mono_child.set(Some(child.clone())); child.node.tl_set_visible(true); + child.node.tl_restack_popups(); // log::info!("activate_child2"); self.schedule_layout(); } @@ -797,6 +798,7 @@ impl ContainerNode { .clone() .node_do_focus(&seat, Direction::Unspecified); } + child.node.tl_restack_popups(); } else { for child in self.children.iter() { child.node.tl_set_visible(true); @@ -1366,6 +1368,7 @@ impl ContainingNode for ContainerNode { let mut body = None; if was_mc { self.mono_child.set(Some(link.to_ref())); + link.node.tl_restack_popups(); body = Some(self.mono_body.get()); } else if !have_mc { body = Some(link.body.get()); @@ -1537,6 +1540,16 @@ impl ToplevelNodeBase for ContainerNode { } self } + + fn tl_restack_popups(&self) { + if let Some(mc) = self.mono_child.get() { + mc.node.tl_restack_popups(); + } else { + for child in self.children.iter() { + child.node.tl_restack_popups(); + } + } + } } fn direction_to_split(dir: Direction) -> (ContainerSplit, bool) { diff --git a/src/tree/float.rs b/src/tree/float.rs index 094fcd74..7ac868d0 100644 --- a/src/tree/float.rs +++ b/src/tree/float.rs @@ -34,7 +34,7 @@ pub struct FloatNode { pub state: Rc, pub visible: Cell, pub position: Cell, - pub display_link: Cell>>>, + pub display_link: RefCell>>>, pub workspace_link: Cell>>>, pub workspace: CloneCell>, pub child: CloneCell>>, @@ -103,7 +103,7 @@ impl FloatNode { state: state.clone(), visible: Cell::new(ws.stacked_visible()), position: Cell::new(position), - display_link: Cell::new(None), + display_link: RefCell::new(None), workspace_link: Cell::new(None), workspace: CloneCell::new(ws.clone()), child: CloneCell::new(Some(child.clone())), @@ -117,14 +117,13 @@ impl FloatNode { attention_requested: Cell::new(false), }); floater.pull_child_properties(); - floater - .display_link - .set(Some(state.root.stacked.add_last(floater.clone()))); + *floater.display_link.borrow_mut() = Some(state.root.stacked.add_last(floater.clone())); floater .workspace_link .set(Some(ws.stacked.add_last(floater.clone()))); child.tl_set_parent(floater.clone()); child.tl_set_visible(floater.visible.get()); + child.tl_restack_popups(); floater.schedule_layout(); floater } @@ -389,6 +388,16 @@ impl FloatNode { .cnode_child_attention_request_changed(self, false); } } + + fn restack(&self) { + if let Some(dl) = &*self.display_link.borrow() { + self.state.root.stacked.add_last_existing(&dl); + if let Some(tl) = self.child.get() { + tl.tl_restack_popups(); + } + self.state.tree_changed(); + } + } } impl Debug for FloatNode { @@ -496,6 +505,7 @@ impl Node for FloatNode { let pos = self.position.get(); match seat_data.op_type { OpType::Move => { + self.restack(); seat_data.dist_hor = seat_data.x; seat_data.dist_ver = seat_data.y; } @@ -579,7 +589,7 @@ impl ContainingNode for FloatNode { fn cnode_remove_child2(self: Rc, _child: &dyn Node, _preserve_focus: bool) { self.discard_child_properties(); self.child.set(None); - self.display_link.set(None); + self.display_link.borrow_mut().take(); self.workspace_link.set(None); } diff --git a/src/tree/toplevel.rs b/src/tree/toplevel.rs index c4e6da03..ad7c050d 100644 --- a/src/tree/toplevel.rs +++ b/src/tree/toplevel.rs @@ -182,6 +182,9 @@ pub trait ToplevelNodeBase: Node { fn tl_scanout_surface(&self) -> Option> { None } + fn tl_restack_popups(&self) { + // nothing + } } pub struct FullscreenedData {