forge
Explore
Log in

Don't you dare go Hollow

Implement floating child stacking above parents

Browse files at this commit

aac54d0ea1a5c95aba698aed583ee3fa9670f18bIvan MolodetskikhParent: 4fe7185
niri-visual-tests/src/test_window.rsmodified+4 -0
@@ -240,6 +240,10 @@ impl LayoutElement for TestWindow {
240 self.inner.borrow().requested_size240 self.inner.borrow().requested_size
241 }241 }
242 242
243+ fn is_child_of(&self, _parent: &Self) -> bool {
244+ false
245+ }
246+
243 fn refresh(&self) {}247 fn refresh(&self) {}
244 248
245 fn rules(&self) -> &ResolvedWindowRules {249 fn rules(&self) -> &ResolvedWindowRules {
src/handlers/xdg_shell.rsmodified+16 -0
@@ -647,6 +647,22 @@ impl XdgShellHandler for State {
647 fn title_changed(&mut self, toplevel: ToplevelSurface) {647 fn title_changed(&mut self, toplevel: ToplevelSurface) {
648 self.update_window_rules(&toplevel);648 self.update_window_rules(&toplevel);
649 }649 }
650+
651+ fn parent_changed(&mut self, toplevel: ToplevelSurface) {
652+ let Some(parent) = toplevel.parent() else {
653+ return;
654+ };
655+
656+ if let Some((mapped, output)) = self.niri.layout.find_window_and_output_mut(&parent) {
657+ let output = output.cloned();
658+ let window = mapped.window.clone();
659+ if self.niri.layout.descendants_added(&window) {
660+ if let Some(output) = output {
661+ self.niri.queue_redraw(&output);
662+ }
663+ }
664+ }
665+ }
650 }666 }
651 667
652 delegate_xdg_shell!(State);668 delegate_xdg_shell!(State);
src/layout/floating.rsmodified+66 -6
@@ -325,7 +325,7 @@ impl<W: LayoutElement> FloatingSpace<W> {
325 325
326 fn add_tile_at(326 fn add_tile_at(
327 &mut self,327 &mut self,
328- idx: usize,328+ mut idx: usize,
329 mut tile: Tile<W>,329 mut tile: Tile<W>,
330 pos: Option<Point<f64, Logical>>,330 pos: Option<Point<f64, Logical>>,
331 activate: bool,331 activate: bool,
@@ -353,6 +353,14 @@ impl<W: LayoutElement> FloatingSpace<W> {
353 self.active_window_id = Some(win.id().clone());353 self.active_window_id = Some(win.id().clone());
354 }354 }
355 355
356+ // Make sure the tile isn't inserted below its parent.
357+ for (i, tile_above) in self.tiles.iter().enumerate().take(idx) {
358+ if win.is_child_of(tile_above.window()) {
359+ idx = i;
360+ break;
361+ }
362+ }
363+
356 let mut pos = pos.unwrap_or_else(|| {364 let mut pos = pos.unwrap_or_else(|| {
357 let area_size = self.working_area.size.to_point();365 let area_size = self.working_area.size.to_point();
358 let tile_size = tile.tile_size().to_point();366 let tile_size = tile.tile_size().to_point();
@@ -367,6 +375,8 @@ impl<W: LayoutElement> FloatingSpace<W> {
367 let data = Data::new(self.working_area, &tile, pos);375 let data = Data::new(self.working_area, &tile, pos);
368 self.data.insert(idx, data);376 self.data.insert(idx, data);
369 self.tiles.insert(idx, tile);377 self.tiles.insert(idx, tile);
378+
379+ self.bring_up_descendants_of(idx);
370 }380 }
371 381
372 pub fn add_tile_above(&mut self, above: &W::Id, tile: Tile<W>) {382 pub fn add_tile_above(&mut self, above: &W::Id, tile: Tile<W>) {
@@ -382,6 +392,33 @@ impl<W: LayoutElement> FloatingSpace<W> {
382 self.add_tile_at(idx, tile, Some(pos), activate);392 self.add_tile_at(idx, tile, Some(pos), activate);
383 }393 }
384 394
395+ fn bring_up_descendants_of(&mut self, idx: usize) {
396+ let tile = &self.tiles[idx];
397+ let win = tile.window();
398+
399+ // We always maintain the correct stacking order, so walking descendants back to front
400+ // should give us all of them.
401+ let mut descendants: Vec<usize> = Vec::new();
402+ for (i, tile_below) in self.tiles.iter().enumerate().skip(idx + 1).rev() {
403+ let win_below = tile_below.window();
404+ if win_below.is_child_of(win)
405+ || descendants
406+ .iter()
407+ .any(|idx| win_below.is_child_of(self.tiles[*idx].window()))
408+ {
409+ descendants.push(i);
410+ }
411+ }
412+
413+ // Now, descendants is in back-to-front order, and repositioning them in the front-to-back
414+ // order will preserve the subsequent indices and work out right.
415+ let mut idx = idx;
416+ for descendant_idx in descendants.into_iter().rev() {
417+ self.raise_window(descendant_idx, idx);
418+ idx += 1;
419+ }
420+ }
421+
385 pub fn remove_active_tile(&mut self) -> Option<RemovedTile<W>> {422 pub fn remove_active_tile(&mut self) -> Option<RemovedTile<W>> {
386 let id = self.active_window_id.clone()?;423 let id = self.active_window_id.clone()?;
387 Some(self.remove_tile(&id))424 Some(self.remove_tile(&id))
@@ -434,15 +471,22 @@ impl<W: LayoutElement> FloatingSpace<W> {
434 return false;471 return false;
435 };472 };
436 473
437- let tile = self.tiles.remove(idx);474+ self.raise_window(idx, 0);
438- let data = self.data.remove(idx);
439- self.tiles.insert(0, tile);
440- self.data.insert(0, data);
441 self.active_window_id = Some(id.clone());475 self.active_window_id = Some(id.clone());
476+ self.bring_up_descendants_of(0);
442 477
443 true478 true
444 }479 }
445 480
481+ fn raise_window(&mut self, from_idx: usize, to_idx: usize) {
482+ assert!(to_idx <= from_idx);
483+
484+ let tile = self.tiles.remove(from_idx);
485+ let data = self.data.remove(from_idx);
486+ self.tiles.insert(to_idx, tile);
487+ self.data.insert(to_idx, data);
488+ }
489+
446 pub fn start_close_animation_for_window(490 pub fn start_close_animation_for_window(
447 &mut self,491 &mut self,
448 renderer: &mut GlesRenderer,492 renderer: &mut GlesRenderer,
@@ -561,6 +605,15 @@ impl<W: LayoutElement> FloatingSpace<W> {
561 win.request_size(win_size, animate, None);605 win.request_size(win_size, animate, None);
562 }606 }
563 607
608+ pub fn descendants_added(&mut self, id: &W::Id) -> bool {
609+ let Some(idx) = self.idx_of(id) else {
610+ return false;
611+ };
612+
613+ self.bring_up_descendants_of(idx);
614+ true
615+ }
616+
564 pub fn update_window(&mut self, id: &W::Id, serial: Option<Serial>) -> bool {617 pub fn update_window(&mut self, id: &W::Id, serial: Option<Serial>) -> bool {
565 let Some(tile_idx) = self.idx_of(id) else {618 let Some(tile_idx) = self.idx_of(id) else {
566 return false;619 return false;
@@ -769,7 +822,7 @@ impl<W: LayoutElement> FloatingSpace<W> {
769 assert!(self.scale.is_finite());822 assert!(self.scale.is_finite());
770 assert_eq!(self.tiles.len(), self.data.len());823 assert_eq!(self.tiles.len(), self.data.len());
771 824
772- for (tile, data) in zip(&self.tiles, &self.data) {825+ for (i, (tile, data)) in zip(&self.tiles, &self.data).enumerate() {
773 assert!(Rc::ptr_eq(&self.options, &tile.options));826 assert!(Rc::ptr_eq(&self.options, &tile.options));
774 assert_eq!(self.clock, tile.clock);827 assert_eq!(self.clock, tile.clock);
775 assert_eq!(self.scale, tile.scale());828 assert_eq!(self.scale, tile.scale());
@@ -786,6 +839,13 @@ impl<W: LayoutElement> FloatingSpace<W> {
786 data2.update(tile);839 data2.update(tile);
787 data2.update_config(self.working_area);840 data2.update_config(self.working_area);
788 assert_eq!(data, &data2, "tile data must be up to date");841 assert_eq!(data, &data2, "tile data must be up to date");
842+
843+ for tile_below in &self.tiles[i + 1..] {
844+ assert!(
845+ !tile_below.window().is_child_of(tile.window()),
846+ "children must be stacked above parents"
847+ );
848+ }
789 }849 }
790 850
791 if let Some(id) = &self.active_window_id {851 if let Some(id) = &self.active_window_id {
src/layout/mod.rsmodified+256 -3
@@ -186,6 +186,8 @@ pub trait LayoutElement {
186 /// Size previously requested through [`LayoutElement::request_size()`].186 /// Size previously requested through [`LayoutElement::request_size()`].
187 fn requested_size(&self) -> Option<Size<i32, Logical>>;187 fn requested_size(&self) -> Option<Size<i32, Logical>>;
188 188
189+ fn is_child_of(&self, parent: &Self) -> bool;
190+
189 fn rules(&self) -> &ResolvedWindowRules;191 fn rules(&self) -> &ResolvedWindowRules;
190 192
191 /// Runs periodic clean-up tasks.193 /// Runs periodic clean-up tasks.
@@ -1113,6 +1115,16 @@ impl<W: LayoutElement> Layout<W> {
1113 None1115 None
1114 }1116 }
1115 1117
1118+ pub fn descendants_added(&mut self, id: &W::Id) -> bool {
1119+ for ws in self.workspaces_mut() {
1120+ if ws.descendants_added(id) {
1121+ return true;
1122+ }
1123+ }
1124+
1125+ false
1126+ }
1127+
1116 pub fn update_window(&mut self, window: &W::Id, serial: Option<Serial>) {1128 pub fn update_window(&mut self, window: &W::Id, serial: Option<Serial>) {
1117 if let Some(InteractiveMoveState::Moving(move_)) = &mut self.interactive_move {1129 if let Some(InteractiveMoveState::Moving(move_)) = &mut self.interactive_move {
1118 if move_.tile.window().id() == window {1130 if move_.tile.window().id() == window {
@@ -3868,6 +3880,7 @@ mod tests {
3868 #[derive(Debug)]3880 #[derive(Debug)]
3869 struct TestWindowInner {3881 struct TestWindowInner {
3870 id: usize,3882 id: usize,
3883+ parent_id: Cell<Option<usize>>,
3871 bbox: Cell<Rectangle<i32, Logical>>,3884 bbox: Cell<Rectangle<i32, Logical>>,
3872 initial_bbox: Rectangle<i32, Logical>,3885 initial_bbox: Rectangle<i32, Logical>,
3873 requested_size: Cell<Option<Size<i32, Logical>>>,3886 requested_size: Cell<Option<Size<i32, Logical>>>,
@@ -3884,6 +3897,8 @@ mod tests {
3884 struct TestWindowParams {3897 struct TestWindowParams {
3885 #[proptest(strategy = "1..=5usize")]3898 #[proptest(strategy = "1..=5usize")]
3886 id: usize,3899 id: usize,
3900+ #[proptest(strategy = "arbitrary_parent_id()")]
3901+ parent_id: Option<usize>,
3887 is_floating: bool,3902 is_floating: bool,
3888 #[proptest(strategy = "arbitrary_bbox()")]3903 #[proptest(strategy = "arbitrary_bbox()")]
3889 bbox: Rectangle<i32, Logical>,3904 bbox: Rectangle<i32, Logical>,
@@ -3895,6 +3910,7 @@ mod tests {
3895 pub fn new(id: usize) -> Self {3910 pub fn new(id: usize) -> Self {
3896 Self {3911 Self {
3897 id,3912 id,
3913+ parent_id: None,
3898 is_floating: false,3914 is_floating: false,
3899 bbox: Rectangle::from_loc_and_size((0, 0), (100, 200)),3915 bbox: Rectangle::from_loc_and_size((0, 0), (100, 200)),
3900 min_max_size: Default::default(),3916 min_max_size: Default::default(),
@@ -3906,6 +3922,7 @@ mod tests {
3906 fn new(params: TestWindowParams) -> Self {3922 fn new(params: TestWindowParams) -> Self {
3907 Self(Rc::new(TestWindowInner {3923 Self(Rc::new(TestWindowInner {
3908 id: params.id,3924 id: params.id,
3925+ parent_id: Cell::new(params.parent_id),
3909 bbox: Cell::new(params.bbox),3926 bbox: Cell::new(params.bbox),
3910 initial_bbox: params.bbox,3927 initial_bbox: params.bbox,
3911 requested_size: Cell::new(None),3928 requested_size: Cell::new(None),
@@ -4033,6 +4050,10 @@ mod tests {
4033 self.0.requested_size.get()4050 self.0.requested_size.get()
4034 }4051 }
4035 4052
4053+ fn is_child_of(&self, parent: &Self) -> bool {
4054+ self.0.parent_id.get() == Some(parent.0.id)
4055+ }
4056+
4036 fn refresh(&self) {}4057 fn refresh(&self) {}
4037 4058
4038 fn rules(&self) -> &ResolvedWindowRules {4059 fn rules(&self) -> &ResolvedWindowRules {
@@ -4136,6 +4157,13 @@ mod tests {
4136 ]4157 ]
4137 }4158 }
4138 4159
4160+ fn arbitrary_parent_id() -> impl Strategy<Value = Option<usize>> {
4161+ prop_oneof![
4162+ 5 => Just(None),
4163+ 1 => prop::option::of(1..=5usize),
4164+ ]
4165+ }
4166+
4139 #[derive(Debug, Clone, Copy, Arbitrary)]4167 #[derive(Debug, Clone, Copy, Arbitrary)]
4140 enum Op {4168 enum Op {
4141 AddOutput(#[proptest(strategy = "1..=5usize")] usize),4169 AddOutput(#[proptest(strategy = "1..=5usize")] usize),
@@ -4195,6 +4223,7 @@ mod tests {
4195 FocusWindowUpOrColumnRight,4223 FocusWindowUpOrColumnRight,
4196 FocusWindowOrWorkspaceDown,4224 FocusWindowOrWorkspaceDown,
4197 FocusWindowOrWorkspaceUp,4225 FocusWindowOrWorkspaceUp,
4226+ FocusWindow(#[proptest(strategy = "1..=5usize")] usize),
4198 MoveColumnLeft,4227 MoveColumnLeft,
4199 MoveColumnRight,4228 MoveColumnRight,
4200 MoveColumnToFirst,4229 MoveColumnToFirst,
@@ -4265,6 +4294,12 @@ mod tests {
4265 id: Option<usize>,4294 id: Option<usize>,
4266 },4295 },
4267 SwitchFocusFloatingTiling,4296 SwitchFocusFloatingTiling,
4297+ SetParent {
4298+ #[proptest(strategy = "1..=5usize")]
4299+ id: usize,
4300+ #[proptest(strategy = "prop::option::of(1..=5usize)")]
4301+ new_parent_id: Option<usize>,
4302+ },
4268 Communicate(#[proptest(strategy = "1..=5usize")] usize),4303 Communicate(#[proptest(strategy = "1..=5usize")] usize),
4269 Refresh {4304 Refresh {
4270 is_active: bool,4305 is_active: bool,
@@ -4446,10 +4481,15 @@ mod tests {
4446 Op::UnnameWorkspace { ws_name } => {4481 Op::UnnameWorkspace { ws_name } => {
4447 layout.unname_workspace(&format!("ws{ws_name}"));4482 layout.unname_workspace(&format!("ws{ws_name}"));
4448 }4483 }
4449- Op::AddWindow { params } => {4484+ Op::AddWindow { mut params } => {
4450 if layout.has_window(&params.id) {4485 if layout.has_window(&params.id) {
4451 return;4486 return;
4452 }4487 }
4488+ if let Some(parent_id) = params.parent_id {
4489+ if parent_id_causes_loop(layout, params.id, parent_id) {
4490+ params.parent_id = None;
4491+ }
4492+ }
4453 4493
4454 let win = TestWindow::new(params);4494 let win = TestWindow::new(params);
4455 layout.add_window(4495 layout.add_window(
@@ -4461,7 +4501,7 @@ mod tests {
4461 );4501 );
4462 }4502 }
4463 Op::AddWindowRightOf {4503 Op::AddWindowRightOf {
4464- params,4504+ mut params,
4465 right_of_id,4505 right_of_id,
4466 } => {4506 } => {
4467 let mut found_right_of = false;4507 let mut found_right_of = false;
@@ -4511,10 +4551,19 @@ mod tests {
4511 return;4551 return;
4512 }4552 }
4513 4553
4554+ if let Some(parent_id) = params.parent_id {
4555+ if parent_id_causes_loop(layout, params.id, parent_id) {
4556+ params.parent_id = None;
4557+ }
4558+ }
4559+
4514 let win = TestWindow::new(params);4560 let win = TestWindow::new(params);
4515 layout.add_window_right_of(&right_of_id, win, None, false, params.is_floating);4561 layout.add_window_right_of(&right_of_id, win, None, false, params.is_floating);
4516 }4562 }
4517- Op::AddWindowToNamedWorkspace { params, ws_name } => {4563+ Op::AddWindowToNamedWorkspace {
4564+ mut params,
4565+ ws_name,
4566+ } => {
4518 let ws_name = format!("ws{ws_name}");4567 let ws_name = format!("ws{ws_name}");
4519 let mut found_workspace = false;4568 let mut found_workspace = false;
4520 4569
@@ -4567,6 +4616,12 @@ mod tests {
4567 return;4616 return;
4568 }4617 }
4569 4618
4619+ if let Some(parent_id) = params.parent_id {
4620+ if parent_id_causes_loop(layout, params.id, parent_id) {
4621+ params.parent_id = None;
4622+ }
4623+ }
4624+
4570 let win = TestWindow::new(params);4625 let win = TestWindow::new(params);
4571 layout.add_window_to_named_workspace(4626 layout.add_window_to_named_workspace(
4572 &ws_name,4627 &ws_name,
@@ -4635,6 +4690,7 @@ mod tests {
4635 Op::FocusWindowUpOrColumnRight => layout.focus_up_or_right(),4690 Op::FocusWindowUpOrColumnRight => layout.focus_up_or_right(),
4636 Op::FocusWindowOrWorkspaceDown => layout.focus_window_or_workspace_down(),4691 Op::FocusWindowOrWorkspaceDown => layout.focus_window_or_workspace_down(),
4637 Op::FocusWindowOrWorkspaceUp => layout.focus_window_or_workspace_up(),4692 Op::FocusWindowOrWorkspaceUp => layout.focus_window_or_workspace_up(),
4693+ Op::FocusWindow(id) => layout.activate_window(&id),
4638 Op::MoveColumnLeft => layout.move_left(),4694 Op::MoveColumnLeft => layout.move_left(),
4639 Op::MoveColumnRight => layout.move_right(),4695 Op::MoveColumnRight => layout.move_right(),
4640 Op::MoveColumnToFirst => layout.move_column_to_first(),4696 Op::MoveColumnToFirst => layout.move_column_to_first(),
@@ -4740,6 +4796,62 @@ mod tests {
4740 Op::SwitchFocusFloatingTiling => {4796 Op::SwitchFocusFloatingTiling => {
4741 layout.switch_focus_floating_tiling();4797 layout.switch_focus_floating_tiling();
4742 }4798 }
4799+ Op::SetParent {
4800+ id,
4801+ mut new_parent_id,
4802+ } => {
4803+ if !layout.has_window(&id) {
4804+ return;
4805+ }
4806+
4807+ if let Some(parent_id) = new_parent_id {
4808+ if parent_id_causes_loop(layout, id, parent_id) {
4809+ new_parent_id = None;
4810+ }
4811+ }
4812+
4813+ let mut update = false;
4814+
4815+ if let Some(InteractiveMoveState::Moving(move_)) = &layout.interactive_move {
4816+ if move_.tile.window().0.id == id {
4817+ move_.tile.window().0.parent_id.set(new_parent_id);
4818+ update = true;
4819+ }
4820+ }
4821+
4822+ match &mut layout.monitor_set {
4823+ MonitorSet::Normal { monitors, .. } => {
4824+ 'outer: for mon in monitors {
4825+ for ws in &mut mon.workspaces {
4826+ for win in ws.windows() {
4827+ if win.0.id == id {
4828+ win.0.parent_id.set(new_parent_id);
4829+ update = true;
4830+ break 'outer;
4831+ }
4832+ }
4833+ }
4834+ }
4835+ }
4836+ MonitorSet::NoOutputs { workspaces, .. } => {
4837+ 'outer: for ws in workspaces {
4838+ for win in ws.windows() {
4839+ if win.0.id == id {
4840+ win.0.parent_id.set(new_parent_id);
4841+ update = true;
4842+ break 'outer;
4843+ }
4844+ }
4845+ }
4846+ }
4847+ }
4848+
4849+ if update {
4850+ if let Some(new_parent_id) = new_parent_id {
4851+ layout.descendants_added(&new_parent_id);
4852+ }
4853+ }
4854+ }
4743 Op::Communicate(id) => {4855 Op::Communicate(id) => {
4744 let mut update = false;4856 let mut update = false;
4745 4857
@@ -6270,6 +6382,147 @@ mod tests {
6270 assert!(win.0.pending_activated.get());6382 assert!(win.0.pending_activated.get());
6271 }6383 }
6272 6384
6385+ #[test]
6386+ fn stacking_add_parent_brings_up_child() {
6387+ let ops = [
6388+ Op::AddOutput(0),
6389+ Op::AddWindow {
6390+ params: TestWindowParams {
6391+ is_floating: true,
6392+ parent_id: Some(1),
6393+ ..TestWindowParams::new(0)
6394+ },
6395+ },
6396+ Op::AddWindow {
6397+ params: TestWindowParams {
6398+ is_floating: true,
6399+ ..TestWindowParams::new(1)
6400+ },
6401+ },
6402+ ];
6403+
6404+ check_ops(&ops);
6405+ }
6406+
6407+ #[test]
6408+ fn stacking_add_parent_brings_up_descendants() {
6409+ let ops = [
6410+ Op::AddOutput(0),
6411+ Op::AddWindow {
6412+ params: TestWindowParams {
6413+ is_floating: true,
6414+ parent_id: Some(2),
6415+ ..TestWindowParams::new(0)
6416+ },
6417+ },
6418+ Op::AddWindow {
6419+ params: TestWindowParams {
6420+ is_floating: true,
6421+ parent_id: Some(0),
6422+ ..TestWindowParams::new(1)
6423+ },
6424+ },
6425+ Op::AddWindow {
6426+ params: TestWindowParams {
6427+ is_floating: true,
6428+ ..TestWindowParams::new(2)
6429+ },
6430+ },
6431+ ];
6432+
6433+ check_ops(&ops);
6434+ }
6435+
6436+ #[test]
6437+ fn stacking_activate_brings_up_descendants() {
6438+ let ops = [
6439+ Op::AddOutput(0),
6440+ Op::AddWindow {
6441+ params: TestWindowParams {
6442+ is_floating: true,
6443+ ..TestWindowParams::new(0)
6444+ },
6445+ },
6446+ Op::AddWindow {
6447+ params: TestWindowParams {
6448+ is_floating: true,
6449+ parent_id: Some(0),
6450+ ..TestWindowParams::new(1)
6451+ },
6452+ },
6453+ Op::AddWindow {
6454+ params: TestWindowParams {
6455+ is_floating: true,
6456+ parent_id: Some(1),
6457+ ..TestWindowParams::new(2)
6458+ },
6459+ },
6460+ Op::AddWindow {
6461+ params: TestWindowParams {
6462+ is_floating: true,
6463+ ..TestWindowParams::new(3)
6464+ },
6465+ },
6466+ Op::FocusWindow(0),
6467+ ];
6468+
6469+ check_ops(&ops);
6470+ }
6471+
6472+ #[test]
6473+ fn stacking_set_parent_brings_up_child() {
6474+ let ops = [
6475+ Op::AddOutput(0),
6476+ Op::AddWindow {
6477+ params: TestWindowParams {
6478+ is_floating: true,
6479+ ..TestWindowParams::new(0)
6480+ },
6481+ },
6482+ Op::AddWindow {
6483+ params: TestWindowParams {
6484+ is_floating: true,
6485+ ..TestWindowParams::new(1)
6486+ },
6487+ },
6488+ Op::SetParent {
6489+ id: 0,
6490+ new_parent_id: Some(1),
6491+ },
6492+ ];
6493+
6494+ check_ops(&ops);
6495+ }
6496+
6497+ fn parent_id_causes_loop(layout: &Layout<TestWindow>, id: usize, mut parent_id: usize) -> bool {
6498+ if parent_id == id {
6499+ return true;
6500+ }
6501+
6502+ 'outer: loop {
6503+ for (_, win) in layout.windows() {
6504+ if win.0.id == parent_id {
6505+ match win.0.parent_id.get() {
6506+ Some(new_parent_id) => {
6507+ if new_parent_id == id {
6508+ // Found a loop.
6509+ return true;
6510+ }
6511+
6512+ parent_id = new_parent_id;
6513+ continue 'outer;
6514+ }
6515+ // Reached window with no parent.
6516+ None => return false,
6517+ }
6518+ }
6519+ }
6520+
6521+ // Parent is not in the layout.
6522+ return false;
6523+ }
6524+ }
6525+
6273 fn arbitrary_spacing() -> impl Strategy<Value = f64> {6526 fn arbitrary_spacing() -> impl Strategy<Value = f64> {
6274 // Give equal weight to:6527 // Give equal weight to:
6275 // - 0: the element is disabled6528 // - 0: the element is disabled
src/layout/workspace.rsmodified+4 -0
@@ -1127,6 +1127,10 @@ impl<W: LayoutElement> Workspace<W> {
1127 })1127 })
1128 }1128 }
1129 1129
1130+ pub fn descendants_added(&mut self, id: &W::Id) -> bool {
1131+ self.floating.descendants_added(id)
1132+ }
1133+
1130 pub fn update_window(&mut self, window: &W::Id, serial: Option<Serial>) {1134 pub fn update_window(&mut self, window: &W::Id, serial: Option<Serial>) {
1131 if !self.floating.update_window(window, serial) {1135 if !self.floating.update_window(window, serial) {
1132 self.scrolling.update_window(window, serial);1136 self.scrolling.update_window(window, serial);
src/window/mapped.rsmodified+4 -0
@@ -720,6 +720,10 @@ impl LayoutElement for Mapped {
720 self.toplevel().with_pending_state(|state| state.size)720 self.toplevel().with_pending_state(|state| state.size)
721 }721 }
722 722
723+ fn is_child_of(&self, parent: &Self) -> bool {
724+ self.toplevel().parent().as_ref() == Some(parent.toplevel().wl_surface())
725+ }
726+
723 fn refresh(&self) {727 fn refresh(&self) {
724 self.window.refresh();728 self.window.refresh();
725 }729 }