Move PartialEq from LayoutElement to an associated type
Browse files at this commitd421e1fbf8f5d10e331de0572def08a8c1bb402eParent: 23ac3d77 changed files +116 -105
- niri-visual-tests/src/cases/layout.rs +11 -11
- niri-visual-tests/src/test_window.rs +34 -30
- src/handlers/mod.rs +1 -1
- src/handlers/xdg_shell.rs +1 -1
- src/layout/mod.rs +49 -45
- src/layout/monitor.rs +1 -1
- src/layout/workspace.rs +19 -16
niri-visual-tests/src/cases/layout.rsmodified+11 -11
| @@ -2,7 +2,7 @@ use std::collections::HashMap; | |||
| 2 | use std::time::Duration; | 2 | use std::time::Duration; |
| 3 | 3 | ||
| 4 | use niri::layout::workspace::ColumnWidth; | 4 | use niri::layout::workspace::ColumnWidth; |
| 5 | -use niri::layout::Options; | 5 | +use niri::layout::{LayoutElement as _, Options}; |
| 6 | use niri::utils::get_monotonic_time; | 6 | use niri::utils::get_monotonic_time; |
| 7 | use niri_config::Color; | 7 | use niri_config::Color; |
| 8 | use smithay::backend::renderer::element::RenderElement; | 8 | use smithay::backend::renderer::element::RenderElement; |
| @@ -73,12 +73,12 @@ impl Layout { | |||
| 73 | 73 | ||
| 74 | rv.add_window(TestWindow::freeform(0), Some(ColumnWidth::Proportion(0.3))); | 74 | rv.add_window(TestWindow::freeform(0), Some(ColumnWidth::Proportion(0.3))); |
| 75 | rv.add_window(TestWindow::freeform(1), Some(ColumnWidth::Proportion(0.3))); | 75 | rv.add_window(TestWindow::freeform(1), Some(ColumnWidth::Proportion(0.3))); |
| 76 | - rv.layout.activate_window(&rv.windows[0]); | 76 | + rv.layout.activate_window(&0); |
| 77 | 77 | ||
| 78 | rv.add_step(500, |l| { | 78 | rv.add_step(500, |l| { |
| 79 | let win = TestWindow::freeform(2); | 79 | let win = TestWindow::freeform(2); |
| 80 | l.add_window(win.clone(), Some(ColumnWidth::Proportion(0.3))); | 80 | l.add_window(win.clone(), Some(ColumnWidth::Proportion(0.3))); |
| 81 | - l.layout.start_open_animation_for_window(&win); | 81 | + l.layout.start_open_animation_for_window(win.id()); |
| 82 | }); | 82 | }); |
| 83 | 83 | ||
| 84 | rv | 84 | rv |
| @@ -91,7 +91,7 @@ impl Layout { | |||
| 91 | rv.add_step(delay, move |l| { | 91 | rv.add_step(delay, move |l| { |
| 92 | let win = TestWindow::freeform(delay as usize); | 92 | let win = TestWindow::freeform(delay as usize); |
| 93 | l.add_window(win.clone(), Some(ColumnWidth::Proportion(0.3))); | 93 | l.add_window(win.clone(), Some(ColumnWidth::Proportion(0.3))); |
| 94 | - l.layout.start_open_animation_for_window(&win); | 94 | + l.layout.start_open_animation_for_window(win.id()); |
| 95 | }); | 95 | }); |
| 96 | } | 96 | } |
| 97 | 97 | ||
| @@ -105,7 +105,7 @@ impl Layout { | |||
| 105 | rv.add_step(delay, move |l| { | 105 | rv.add_step(delay, move |l| { |
| 106 | let win = TestWindow::freeform(delay as usize); | 106 | let win = TestWindow::freeform(delay as usize); |
| 107 | l.add_window(win.clone(), Some(ColumnWidth::Proportion(0.5))); | 107 | l.add_window(win.clone(), Some(ColumnWidth::Proportion(0.5))); |
| 108 | - l.layout.start_open_animation_for_window(&win); | 108 | + l.layout.start_open_animation_for_window(win.id()); |
| 109 | }); | 109 | }); |
| 110 | } | 110 | } |
| 111 | 111 | ||
| @@ -122,7 +122,7 @@ impl Layout { | |||
| 122 | let win = TestWindow::freeform(2); | 122 | let win = TestWindow::freeform(2); |
| 123 | let right_of = l.windows[0].clone(); | 123 | let right_of = l.windows[0].clone(); |
| 124 | l.add_window_right_of(&right_of, win.clone(), Some(ColumnWidth::Proportion(0.3))); | 124 | l.add_window_right_of(&right_of, win.clone(), Some(ColumnWidth::Proportion(0.3))); |
| 125 | - l.layout.start_open_animation_for_window(&win); | 125 | + l.layout.start_open_animation_for_window(win.id()); |
| 126 | }); | 126 | }); |
| 127 | 127 | ||
| 128 | rv | 128 | rv |
| @@ -138,7 +138,7 @@ impl Layout { | |||
| 138 | let win = TestWindow::freeform(2); | 138 | let win = TestWindow::freeform(2); |
| 139 | let right_of = l.windows[0].clone(); | 139 | let right_of = l.windows[0].clone(); |
| 140 | l.add_window_right_of(&right_of, win.clone(), Some(ColumnWidth::Proportion(0.5))); | 140 | l.add_window_right_of(&right_of, win.clone(), Some(ColumnWidth::Proportion(0.5))); |
| 141 | - l.layout.start_open_animation_for_window(&win); | 141 | + l.layout.start_open_animation_for_window(win.id()); |
| 142 | }); | 142 | }); |
| 143 | 143 | ||
| 144 | rv | 144 | rv |
| @@ -147,7 +147,7 @@ impl Layout { | |||
| 147 | fn add_window(&mut self, window: TestWindow, width: Option<ColumnWidth>) { | 147 | fn add_window(&mut self, window: TestWindow, width: Option<ColumnWidth>) { |
| 148 | self.layout.add_window(window.clone(), width, false); | 148 | self.layout.add_window(window.clone(), width, false); |
| 149 | if window.communicate() { | 149 | if window.communicate() { |
| 150 | - self.layout.update_window(&window); | 150 | + self.layout.update_window(window.id()); |
| 151 | } | 151 | } |
| 152 | self.windows.push(window); | 152 | self.windows.push(window); |
| 153 | } | 153 | } |
| @@ -159,9 +159,9 @@ impl Layout { | |||
| 159 | width: Option<ColumnWidth>, | 159 | width: Option<ColumnWidth>, |
| 160 | ) { | 160 | ) { |
| 161 | self.layout | 161 | self.layout |
| 162 | - .add_window_right_of(right_of, window.clone(), width, false); | 162 | + .add_window_right_of(right_of.id(), window.clone(), width, false); |
| 163 | if window.communicate() { | 163 | if window.communicate() { |
| 164 | - self.layout.update_window(&window); | 164 | + self.layout.update_window(window.id()); |
| 165 | } | 165 | } |
| 166 | self.windows.push(window); | 166 | self.windows.push(window); |
| 167 | } | 167 | } |
| @@ -183,7 +183,7 @@ impl TestCase for Layout { | |||
| 183 | self.layout.update_output_size(&self.output); | 183 | self.layout.update_output_size(&self.output); |
| 184 | for win in &self.windows { | 184 | for win in &self.windows { |
| 185 | if win.communicate() { | 185 | if win.communicate() { |
| 186 | - self.layout.update_window(win); | 186 | + self.layout.update_window(win.id()); |
| 187 | } | 187 | } |
| 188 | } | 188 | } |
| 189 | } | 189 | } |
niri-visual-tests/src/test_window.rsmodified+34 -30
| @@ -12,7 +12,6 @@ use smithay::utils::{Logical, Point, Scale, Size, Transform}; | |||
| 12 | 12 | ||
| 13 | #[derive(Debug)] | 13 | #[derive(Debug)] |
| 14 | struct TestWindowInner { | 14 | struct TestWindowInner { |
| 15 | - id: usize, | ||
| 16 | size: Size<i32, Logical>, | 15 | size: Size<i32, Logical>, |
| 17 | requested_size: Option<Size<i32, Logical>>, | 16 | requested_size: Option<Size<i32, Logical>>, |
| 18 | min_size: Size<i32, Logical>, | 17 | min_size: Size<i32, Logical>, |
| @@ -24,7 +23,10 @@ struct TestWindowInner { | |||
| 24 | } | 23 | } |
| 25 | 24 | ||
| 26 | #[derive(Debug, Clone)] | 25 | #[derive(Debug, Clone)] |
| 27 | -pub struct TestWindow(Rc<RefCell<TestWindowInner>>); | 26 | +pub struct TestWindow { |
| 27 | + id: usize, | ||
| 28 | + inner: Rc<RefCell<TestWindowInner>>, | ||
| 29 | +} | ||
| 28 | 30 | ||
| 29 | impl TestWindow { | 31 | impl TestWindow { |
| 30 | pub fn freeform(id: usize) -> Self { | 32 | pub fn freeform(id: usize) -> Self { |
| @@ -33,17 +35,19 @@ impl TestWindow { | |||
| 33 | let max_size = Size::from((0, 0)); | 35 | let max_size = Size::from((0, 0)); |
| 34 | let buffer = SolidColorBuffer::new(size, [0.15, 0.64, 0.41, 1.]); | 36 | let buffer = SolidColorBuffer::new(size, [0.15, 0.64, 0.41, 1.]); |
| 35 | 37 | ||
| 36 | - Self(Rc::new(RefCell::new(TestWindowInner { | 38 | + Self { |
| 37 | id, | 39 | id, |
| 38 | - size, | 40 | + inner: Rc::new(RefCell::new(TestWindowInner { |
| 39 | - requested_size: None, | 41 | + size, |
| 40 | - min_size, | 42 | + requested_size: None, |
| 41 | - max_size, | 43 | + min_size, |
| 42 | - buffer, | 44 | + max_size, |
| 43 | - pending_fullscreen: false, | 45 | + buffer, |
| 44 | - csd_shadow_width: 0, | 46 | + pending_fullscreen: false, |
| 45 | - csd_shadow_buffer: SolidColorBuffer::new((0, 0), [0., 0., 0., 0.3]), | 47 | + csd_shadow_width: 0, |
| 46 | - }))) | 48 | + csd_shadow_buffer: SolidColorBuffer::new((0, 0), [0., 0., 0., 0.3]), |
| 49 | + })), | ||
| 50 | + } | ||
| 47 | } | 51 | } |
| 48 | 52 | ||
| 49 | pub fn fixed_size(id: usize) -> Self { | 53 | pub fn fixed_size(id: usize) -> Self { |
| @@ -56,24 +60,24 @@ impl TestWindow { | |||
| 56 | } | 60 | } |
| 57 | 61 | ||
| 58 | pub fn set_min_size(&self, size: Size<i32, Logical>) { | 62 | pub fn set_min_size(&self, size: Size<i32, Logical>) { |
| 59 | - self.0.borrow_mut().min_size = size; | 63 | + self.inner.borrow_mut().min_size = size; |
| 60 | } | 64 | } |
| 61 | 65 | ||
| 62 | pub fn set_max_size(&self, size: Size<i32, Logical>) { | 66 | pub fn set_max_size(&self, size: Size<i32, Logical>) { |
| 63 | - self.0.borrow_mut().max_size = size; | 67 | + self.inner.borrow_mut().max_size = size; |
| 64 | } | 68 | } |
| 65 | 69 | ||
| 66 | pub fn set_color(&self, color: [f32; 4]) { | 70 | pub fn set_color(&self, color: [f32; 4]) { |
| 67 | - self.0.borrow_mut().buffer.set_color(color); | 71 | + self.inner.borrow_mut().buffer.set_color(color); |
| 68 | } | 72 | } |
| 69 | 73 | ||
| 70 | pub fn set_csd_shadow_width(&self, width: i32) { | 74 | pub fn set_csd_shadow_width(&self, width: i32) { |
| 71 | - self.0.borrow_mut().csd_shadow_width = width; | 75 | + self.inner.borrow_mut().csd_shadow_width = width; |
| 72 | } | 76 | } |
| 73 | 77 | ||
| 74 | pub fn communicate(&self) -> bool { | 78 | pub fn communicate(&self) -> bool { |
| 75 | let mut rv = false; | 79 | let mut rv = false; |
| 76 | - let mut inner = self.0.borrow_mut(); | 80 | + let mut inner = self.inner.borrow_mut(); |
| 77 | 81 | ||
| 78 | let mut new_size = inner.size; | 82 | let mut new_size = inner.size; |
| 79 | 83 | ||
| @@ -117,15 +121,15 @@ impl TestWindow { | |||
| 117 | } | 121 | } |
| 118 | } | 122 | } |
| 119 | 123 | ||
| 120 | -impl PartialEq for TestWindow { | 124 | +impl LayoutElement for TestWindow { |
| 121 | - fn eq(&self, other: &Self) -> bool { | 125 | + type Id = usize; |
| 122 | - self.0.borrow().id == other.0.borrow().id | 126 | + |
| 127 | + fn id(&self) -> &Self::Id { | ||
| 128 | + &self.id | ||
| 123 | } | 129 | } |
| 124 | -} | ||
| 125 | 130 | ||
| 126 | -impl LayoutElement for TestWindow { | ||
| 127 | fn size(&self) -> Size<i32, Logical> { | 131 | fn size(&self) -> Size<i32, Logical> { |
| 128 | - self.0.borrow().size | 132 | + self.inner.borrow().size |
| 129 | } | 133 | } |
| 130 | 134 | ||
| 131 | fn buf_loc(&self) -> Point<i32, Logical> { | 135 | fn buf_loc(&self) -> Point<i32, Logical> { |
| @@ -142,7 +146,7 @@ impl LayoutElement for TestWindow { | |||
| 142 | location: Point<i32, Logical>, | 146 | location: Point<i32, Logical>, |
| 143 | scale: Scale<f64>, | 147 | scale: Scale<f64>, |
| 144 | ) -> Vec<LayoutElementRenderElement<R>> { | 148 | ) -> Vec<LayoutElementRenderElement<R>> { |
| 145 | - let inner = self.0.borrow(); | 149 | + let inner = self.inner.borrow(); |
| 146 | 150 | ||
| 147 | vec![ | 151 | vec![ |
| 148 | SolidColorRenderElement::from_buffer( | 152 | SolidColorRenderElement::from_buffer( |
| @@ -166,20 +170,20 @@ impl LayoutElement for TestWindow { | |||
| 166 | } | 170 | } |
| 167 | 171 | ||
| 168 | fn request_size(&self, size: Size<i32, Logical>) { | 172 | fn request_size(&self, size: Size<i32, Logical>) { |
| 169 | - self.0.borrow_mut().requested_size = Some(size); | 173 | + self.inner.borrow_mut().requested_size = Some(size); |
| 170 | - self.0.borrow_mut().pending_fullscreen = false; | 174 | + self.inner.borrow_mut().pending_fullscreen = false; |
| 171 | } | 175 | } |
| 172 | 176 | ||
| 173 | fn request_fullscreen(&self, _size: Size<i32, Logical>) { | 177 | fn request_fullscreen(&self, _size: Size<i32, Logical>) { |
| 174 | - self.0.borrow_mut().pending_fullscreen = true; | 178 | + self.inner.borrow_mut().pending_fullscreen = true; |
| 175 | } | 179 | } |
| 176 | 180 | ||
| 177 | fn min_size(&self) -> Size<i32, Logical> { | 181 | fn min_size(&self) -> Size<i32, Logical> { |
| 178 | - self.0.borrow().min_size | 182 | + self.inner.borrow().min_size |
| 179 | } | 183 | } |
| 180 | 184 | ||
| 181 | fn max_size(&self) -> Size<i32, Logical> { | 185 | fn max_size(&self) -> Size<i32, Logical> { |
| 182 | - self.0.borrow().max_size | 186 | + self.inner.borrow().max_size |
| 183 | } | 187 | } |
| 184 | 188 | ||
| 185 | fn is_wl_surface(&self, _wl_surface: &WlSurface) -> bool { | 189 | fn is_wl_surface(&self, _wl_surface: &WlSurface) -> bool { |
| @@ -203,6 +207,6 @@ impl LayoutElement for TestWindow { | |||
| 203 | } | 207 | } |
| 204 | 208 | ||
| 205 | fn is_pending_fullscreen(&self) -> bool { | 209 | fn is_pending_fullscreen(&self) -> bool { |
| 206 | - self.0.borrow().pending_fullscreen | 210 | + self.inner.borrow().pending_fullscreen |
| 207 | } | 211 | } |
| 208 | } | 212 | } |
src/handlers/mod.rsmodified+1 -1
| @@ -365,7 +365,7 @@ impl ForeignToplevelHandler for State { | |||
| 365 | if &requested_output != current_output { | 365 | if &requested_output != current_output { |
| 366 | self.niri | 366 | self.niri |
| 367 | .layout | 367 | .layout |
| 368 | - .move_window_to_output(window.clone(), &requested_output); | 368 | + .move_window_to_output(&window, &requested_output); |
| 369 | } | 369 | } |
| 370 | } | 370 | } |
| 371 | 371 | ||
src/handlers/xdg_shell.rsmodified+1 -1
| @@ -289,7 +289,7 @@ impl XdgShellHandler for State { | |||
| 289 | if &requested_output != current_output { | 289 | if &requested_output != current_output { |
| 290 | self.niri | 290 | self.niri |
| 291 | .layout | 291 | .layout |
| 292 | - .move_window_to_output(window.clone(), &requested_output); | 292 | + .move_window_to_output(&window, &requested_output); |
| 293 | } | 293 | } |
| 294 | } | 294 | } |
| 295 | 295 | ||
src/layout/mod.rsmodified+49 -45
| @@ -69,7 +69,13 @@ niri_render_elements! { | |||
| 69 | } | 69 | } |
| 70 | } | 70 | } |
| 71 | 71 | ||
| 72 | -pub trait LayoutElement: PartialEq { | 72 | +pub trait LayoutElement { |
| 73 | + /// Type that can be used as a unique ID of this element. | ||
| 74 | + type Id: PartialEq; | ||
| 75 | + | ||
| 76 | + /// Unique ID of this element. | ||
| 77 | + fn id(&self) -> &Self::Id; | ||
| 78 | + | ||
| 73 | /// Visual size of the element. | 79 | /// Visual size of the element. |
| 74 | /// | 80 | /// |
| 75 | /// This is what the user would consider the size, i.e. excluding CSD shadows and whatnot. | 81 | /// This is what the user would consider the size, i.e. excluding CSD shadows and whatnot. |
| @@ -217,6 +223,12 @@ impl Options { | |||
| 217 | } | 223 | } |
| 218 | 224 | ||
| 219 | impl LayoutElement for Window { | 225 | impl LayoutElement for Window { |
| 226 | + type Id = Self; | ||
| 227 | + | ||
| 228 | + fn id(&self) -> &Self::Id { | ||
| 229 | + self | ||
| 230 | + } | ||
| 231 | + | ||
| 220 | fn size(&self) -> Size<i32, Logical> { | 232 | fn size(&self) -> Size<i32, Logical> { |
| 221 | self.geometry().size | 233 | self.geometry().size |
| 222 | } | 234 | } |
| @@ -599,7 +611,7 @@ impl<W: LayoutElement> Layout<W> { | |||
| 599 | /// Returns an output that the window was added to, if there were any outputs. | 611 | /// Returns an output that the window was added to, if there were any outputs. |
| 600 | pub fn add_window_right_of( | 612 | pub fn add_window_right_of( |
| 601 | &mut self, | 613 | &mut self, |
| 602 | - right_of: &W, | 614 | + right_of: &W::Id, |
| 603 | window: W, | 615 | window: W, |
| 604 | width: Option<ColumnWidth>, | 616 | width: Option<ColumnWidth>, |
| 605 | is_full_width: bool, | 617 | is_full_width: bool, |
| @@ -681,13 +693,15 @@ impl<W: LayoutElement> Layout<W> { | |||
| 681 | ); | 693 | ); |
| 682 | } | 694 | } |
| 683 | 695 | ||
| 684 | - pub fn remove_window(&mut self, window: &W) { | 696 | + pub fn remove_window(&mut self, window: &W::Id) -> Option<W> { |
| 697 | + let mut rv = None; | ||
| 698 | + | ||
| 685 | match &mut self.monitor_set { | 699 | match &mut self.monitor_set { |
| 686 | MonitorSet::Normal { monitors, .. } => { | 700 | MonitorSet::Normal { monitors, .. } => { |
| 687 | for mon in monitors { | 701 | for mon in monitors { |
| 688 | for (idx, ws) in mon.workspaces.iter_mut().enumerate() { | 702 | for (idx, ws) in mon.workspaces.iter_mut().enumerate() { |
| 689 | if ws.has_window(window) { | 703 | if ws.has_window(window) { |
| 690 | - ws.remove_window(window); | 704 | + rv = Some(ws.remove_window(window)); |
| 691 | 705 | ||
| 692 | // Clean up empty workspaces that are not active and not last. | 706 | // Clean up empty workspaces that are not active and not last. |
| 693 | if !ws.has_windows() | 707 | if !ws.has_windows() |
| @@ -710,7 +724,7 @@ impl<W: LayoutElement> Layout<W> { | |||
| 710 | MonitorSet::NoOutputs { workspaces, .. } => { | 724 | MonitorSet::NoOutputs { workspaces, .. } => { |
| 711 | for (idx, ws) in workspaces.iter_mut().enumerate() { | 725 | for (idx, ws) in workspaces.iter_mut().enumerate() { |
| 712 | if ws.has_window(window) { | 726 | if ws.has_window(window) { |
| 713 | - ws.remove_window(window); | 727 | + rv = Some(ws.remove_window(window)); |
| 714 | 728 | ||
| 715 | // Clean up empty workspaces. | 729 | // Clean up empty workspaces. |
| 716 | if !ws.has_windows() { | 730 | if !ws.has_windows() { |
| @@ -722,9 +736,11 @@ impl<W: LayoutElement> Layout<W> { | |||
| 722 | } | 736 | } |
| 723 | } | 737 | } |
| 724 | } | 738 | } |
| 739 | + | ||
| 740 | + rv | ||
| 725 | } | 741 | } |
| 726 | 742 | ||
| 727 | - pub fn update_window(&mut self, window: &W) { | 743 | + pub fn update_window(&mut self, window: &W::Id) { |
| 728 | match &mut self.monitor_set { | 744 | match &mut self.monitor_set { |
| 729 | MonitorSet::Normal { monitors, .. } => { | 745 | MonitorSet::Normal { monitors, .. } => { |
| 730 | for mon in monitors { | 746 | for mon in monitors { |
| @@ -761,7 +777,7 @@ impl<W: LayoutElement> Layout<W> { | |||
| 761 | None | 777 | None |
| 762 | } | 778 | } |
| 763 | 779 | ||
| 764 | - pub fn window_y(&self, window: &W) -> Option<i32> { | 780 | + pub fn window_y(&self, window: &W::Id) -> Option<i32> { |
| 765 | match &self.monitor_set { | 781 | match &self.monitor_set { |
| 766 | MonitorSet::Normal { monitors, .. } => { | 782 | MonitorSet::Normal { monitors, .. } => { |
| 767 | for mon in monitors { | 783 | for mon in monitors { |
| @@ -810,7 +826,7 @@ impl<W: LayoutElement> Layout<W> { | |||
| 810 | } | 826 | } |
| 811 | } | 827 | } |
| 812 | 828 | ||
| 813 | - pub fn activate_window(&mut self, window: &W) { | 829 | + pub fn activate_window(&mut self, window: &W::Id) { |
| 814 | let MonitorSet::Normal { | 830 | let MonitorSet::Normal { |
| 815 | monitors, | 831 | monitors, |
| 816 | active_monitor_idx, | 832 | active_monitor_idx, |
| @@ -1493,7 +1509,7 @@ impl<W: LayoutElement> Layout<W> { | |||
| 1493 | } | 1509 | } |
| 1494 | } | 1510 | } |
| 1495 | 1511 | ||
| 1496 | - pub fn move_window_to_output(&mut self, window: W, output: &Output) { | 1512 | + pub fn move_window_to_output(&mut self, window: &W::Id, output: &Output) { |
| 1497 | let mut width = None; | 1513 | let mut width = None; |
| 1498 | let mut is_full_width = false; | 1514 | let mut is_full_width = false; |
| 1499 | 1515 | ||
| @@ -1501,7 +1517,7 @@ impl<W: LayoutElement> Layout<W> { | |||
| 1501 | for mon in &*monitors { | 1517 | for mon in &*monitors { |
| 1502 | for ws in &mon.workspaces { | 1518 | for ws in &mon.workspaces { |
| 1503 | for col in &ws.columns { | 1519 | for col in &ws.columns { |
| 1504 | - if col.contains(&window) { | 1520 | + if col.contains(window) { |
| 1505 | width = Some(col.width); | 1521 | width = Some(col.width); |
| 1506 | is_full_width = col.is_full_width; | 1522 | is_full_width = col.is_full_width; |
| 1507 | break; | 1523 | break; |
| @@ -1513,7 +1529,7 @@ impl<W: LayoutElement> Layout<W> { | |||
| 1513 | 1529 | ||
| 1514 | let Some(width) = width else { return }; | 1530 | let Some(width) = width else { return }; |
| 1515 | 1531 | ||
| 1516 | - self.remove_window(&window); | 1532 | + let window = self.remove_window(window).unwrap(); |
| 1517 | 1533 | ||
| 1518 | if let MonitorSet::Normal { monitors, .. } = &mut self.monitor_set { | 1534 | if let MonitorSet::Normal { monitors, .. } = &mut self.monitor_set { |
| 1519 | let new_idx = monitors | 1535 | let new_idx = monitors |
| @@ -1570,7 +1586,7 @@ impl<W: LayoutElement> Layout<W> { | |||
| 1570 | *active_monitor_idx = target_idx; | 1586 | *active_monitor_idx = target_idx; |
| 1571 | } | 1587 | } |
| 1572 | 1588 | ||
| 1573 | - pub fn set_fullscreen(&mut self, window: &W, is_fullscreen: bool) { | 1589 | + pub fn set_fullscreen(&mut self, window: &W::Id, is_fullscreen: bool) { |
| 1574 | match &mut self.monitor_set { | 1590 | match &mut self.monitor_set { |
| 1575 | MonitorSet::Normal { monitors, .. } => { | 1591 | MonitorSet::Normal { monitors, .. } => { |
| 1576 | for mon in monitors { | 1592 | for mon in monitors { |
| @@ -1593,7 +1609,7 @@ impl<W: LayoutElement> Layout<W> { | |||
| 1593 | } | 1609 | } |
| 1594 | } | 1610 | } |
| 1595 | 1611 | ||
| 1596 | - pub fn toggle_fullscreen(&mut self, window: &W) { | 1612 | + pub fn toggle_fullscreen(&mut self, window: &W::Id) { |
| 1597 | match &mut self.monitor_set { | 1613 | match &mut self.monitor_set { |
| 1598 | MonitorSet::Normal { monitors, .. } => { | 1614 | MonitorSet::Normal { monitors, .. } => { |
| 1599 | for mon in monitors { | 1615 | for mon in monitors { |
| @@ -1746,14 +1762,14 @@ impl<W: LayoutElement> Layout<W> { | |||
| 1746 | monitor.move_workspace_up(); | 1762 | monitor.move_workspace_up(); |
| 1747 | } | 1763 | } |
| 1748 | 1764 | ||
| 1749 | - pub fn start_open_animation_for_window(&mut self, window: &W) { | 1765 | + pub fn start_open_animation_for_window(&mut self, window: &W::Id) { |
| 1750 | match &mut self.monitor_set { | 1766 | match &mut self.monitor_set { |
| 1751 | MonitorSet::Normal { monitors, .. } => { | 1767 | MonitorSet::Normal { monitors, .. } => { |
| 1752 | for mon in monitors { | 1768 | for mon in monitors { |
| 1753 | for ws in &mut mon.workspaces { | 1769 | for ws in &mut mon.workspaces { |
| 1754 | for col in &mut ws.columns { | 1770 | for col in &mut ws.columns { |
| 1755 | for tile in &mut col.tiles { | 1771 | for tile in &mut col.tiles { |
| 1756 | - if tile.window() == window { | 1772 | + if tile.window().id() == window { |
| 1757 | tile.start_open_animation(); | 1773 | tile.start_open_animation(); |
| 1758 | return; | 1774 | return; |
| 1759 | } | 1775 | } |
| @@ -1764,13 +1780,11 @@ impl<W: LayoutElement> Layout<W> { | |||
| 1764 | } | 1780 | } |
| 1765 | MonitorSet::NoOutputs { workspaces, .. } => { | 1781 | MonitorSet::NoOutputs { workspaces, .. } => { |
| 1766 | for ws in workspaces { | 1782 | for ws in workspaces { |
| 1767 | - if ws.has_window(window) { | 1783 | + for col in &mut ws.columns { |
| 1768 | - for col in &mut ws.columns { | 1784 | + for tile in &mut col.tiles { |
| 1769 | - for tile in &mut col.tiles { | 1785 | + if tile.window().id() == window { |
| 1770 | - if tile.window() == window { | 1786 | + tile.start_open_animation(); |
| 1771 | - tile.start_open_animation(); | 1787 | + return; |
| 1772 | - return; | ||
| 1773 | - } | ||
| 1774 | } | 1788 | } |
| 1775 | } | 1789 | } |
| 1776 | } | 1790 | } |
| @@ -1889,13 +1903,13 @@ mod tests { | |||
| 1889 | } | 1903 | } |
| 1890 | } | 1904 | } |
| 1891 | 1905 | ||
| 1892 | - impl PartialEq for TestWindow { | 1906 | + impl LayoutElement for TestWindow { |
| 1893 | - fn eq(&self, other: &Self) -> bool { | 1907 | + type Id = usize; |
| 1894 | - self.0.id == other.0.id | 1908 | + |
| 1909 | + fn id(&self) -> &Self::Id { | ||
| 1910 | + &self.0.id | ||
| 1895 | } | 1911 | } |
| 1896 | - } | ||
| 1897 | 1912 | ||
| 1898 | - impl LayoutElement for TestWindow { | ||
| 1899 | fn size(&self) -> Size<i32, Logical> { | 1913 | fn size(&self) -> Size<i32, Logical> { |
| 1900 | self.0.bbox.get().size | 1914 | self.0.bbox.get().size |
| 1901 | } | 1915 | } |
| @@ -2208,24 +2222,14 @@ mod tests { | |||
| 2208 | return; | 2222 | return; |
| 2209 | } | 2223 | } |
| 2210 | 2224 | ||
| 2211 | - let right_of_win = TestWindow::new( | ||
| 2212 | - right_of_id, | ||
| 2213 | - Rectangle::default(), | ||
| 2214 | - Size::default(), | ||
| 2215 | - Size::default(), | ||
| 2216 | - ); | ||
| 2217 | let win = TestWindow::new(id, bbox, min_max_size.0, min_max_size.1); | 2225 | let win = TestWindow::new(id, bbox, min_max_size.0, min_max_size.1); |
| 2218 | - layout.add_window_right_of(&right_of_win, win, None, false); | 2226 | + layout.add_window_right_of(&right_of_id, win, None, false); |
| 2219 | } | 2227 | } |
| 2220 | Op::CloseWindow(id) => { | 2228 | Op::CloseWindow(id) => { |
| 2221 | - let dummy = | 2229 | + layout.remove_window(&id); |
| 2222 | - TestWindow::new(id, Rectangle::default(), Size::default(), Size::default()); | ||
| 2223 | - layout.remove_window(&dummy); | ||
| 2224 | } | 2230 | } |
| 2225 | Op::FullscreenWindow(id) => { | 2231 | Op::FullscreenWindow(id) => { |
| 2226 | - let dummy = | 2232 | + layout.toggle_fullscreen(&id); |
| 2227 | - TestWindow::new(id, Rectangle::default(), Size::default(), Size::default()); | ||
| 2228 | - layout.toggle_fullscreen(&dummy); | ||
| 2229 | } | 2233 | } |
| 2230 | Op::FocusColumnLeft => layout.focus_left(), | 2234 | Op::FocusColumnLeft => layout.focus_left(), |
| 2231 | Op::FocusColumnRight => layout.focus_right(), | 2235 | Op::FocusColumnRight => layout.focus_right(), |
| @@ -2284,7 +2288,7 @@ mod tests { | |||
| 2284 | Op::SetColumnWidth(change) => layout.set_column_width(change), | 2288 | Op::SetColumnWidth(change) => layout.set_column_width(change), |
| 2285 | Op::SetWindowHeight(change) => layout.set_window_height(change), | 2289 | Op::SetWindowHeight(change) => layout.set_window_height(change), |
| 2286 | Op::Communicate(id) => { | 2290 | Op::Communicate(id) => { |
| 2287 | - let mut window = None; | 2291 | + let mut update = false; |
| 2288 | match &mut layout.monitor_set { | 2292 | match &mut layout.monitor_set { |
| 2289 | MonitorSet::Normal { monitors, .. } => { | 2293 | MonitorSet::Normal { monitors, .. } => { |
| 2290 | 'outer: for mon in monitors { | 2294 | 'outer: for mon in monitors { |
| @@ -2292,7 +2296,7 @@ mod tests { | |||
| 2292 | for win in ws.windows() { | 2296 | for win in ws.windows() { |
| 2293 | if win.0.id == id { | 2297 | if win.0.id == id { |
| 2294 | if win.communicate() { | 2298 | if win.communicate() { |
| 2295 | - window = Some(win.clone()); | 2299 | + update = true; |
| 2296 | } | 2300 | } |
| 2297 | break 'outer; | 2301 | break 'outer; |
| 2298 | } | 2302 | } |
| @@ -2305,7 +2309,7 @@ mod tests { | |||
| 2305 | for win in ws.windows() { | 2309 | for win in ws.windows() { |
| 2306 | if win.0.id == id { | 2310 | if win.0.id == id { |
| 2307 | if win.communicate() { | 2311 | if win.communicate() { |
| 2308 | - window = Some(win.clone()); | 2312 | + update = true; |
| 2309 | } | 2313 | } |
| 2310 | break 'outer; | 2314 | break 'outer; |
| 2311 | } | 2315 | } |
| @@ -2314,8 +2318,8 @@ mod tests { | |||
| 2314 | } | 2318 | } |
| 2315 | } | 2319 | } |
| 2316 | 2320 | ||
| 2317 | - if let Some(win) = window { | 2321 | + if update { |
| 2318 | - layout.update_window(&win); | 2322 | + layout.update_window(&id); |
| 2319 | } | 2323 | } |
| 2320 | } | 2324 | } |
| 2321 | Op::MoveWorkspaceToOutput(id) => { | 2325 | Op::MoveWorkspaceToOutput(id) => { |
src/layout/monitor.rsmodified+1 -1
| @@ -159,7 +159,7 @@ impl<W: LayoutElement> Monitor<W> { | |||
| 159 | 159 | ||
| 160 | pub fn add_window_right_of( | 160 | pub fn add_window_right_of( |
| 161 | &mut self, | 161 | &mut self, |
| 162 | - right_of: &W, | 162 | + right_of: &W::Id, |
| 163 | window: W, | 163 | window: W, |
| 164 | width: ColumnWidth, | 164 | width: ColumnWidth, |
| 165 | is_full_width: bool, | 165 | is_full_width: bool, |
src/layout/workspace.rsmodified+19 -16
| @@ -577,8 +577,8 @@ impl<W: LayoutElement> Workspace<W> { | |||
| 577 | self.windows().next().is_some() | 577 | self.windows().next().is_some() |
| 578 | } | 578 | } |
| 579 | 579 | ||
| 580 | - pub fn has_window(&self, window: &W) -> bool { | 580 | + pub fn has_window(&self, window: &W::Id) -> bool { |
| 581 | - self.windows().any(|win| win == window) | 581 | + self.windows().any(|win| win.id() == window) |
| 582 | } | 582 | } |
| 583 | 583 | ||
| 584 | pub fn find_wl_surface(&self, wl_surface: &WlSurface) -> Option<&W> { | 584 | pub fn find_wl_surface(&self, wl_surface: &WlSurface) -> Option<&W> { |
| @@ -658,7 +658,7 @@ impl<W: LayoutElement> Workspace<W> { | |||
| 658 | 658 | ||
| 659 | pub fn add_window_right_of( | 659 | pub fn add_window_right_of( |
| 660 | &mut self, | 660 | &mut self, |
| 661 | - right_of: &W, | 661 | + right_of: &W::Id, |
| 662 | window: W, | 662 | window: W, |
| 663 | width: ColumnWidth, | 663 | width: ColumnWidth, |
| 664 | is_full_width: bool, | 664 | is_full_width: bool, |
| @@ -835,7 +835,7 @@ impl<W: LayoutElement> Workspace<W> { | |||
| 835 | column | 835 | column |
| 836 | } | 836 | } |
| 837 | 837 | ||
| 838 | - pub fn remove_window(&mut self, window: &W) { | 838 | + pub fn remove_window(&mut self, window: &W::Id) -> W { |
| 839 | let column_idx = self | 839 | let column_idx = self |
| 840 | .columns | 840 | .columns |
| 841 | .iter() | 841 | .iter() |
| @@ -844,10 +844,10 @@ impl<W: LayoutElement> Workspace<W> { | |||
| 844 | let column = &self.columns[column_idx]; | 844 | let column = &self.columns[column_idx]; |
| 845 | 845 | ||
| 846 | let window_idx = column.position(window).unwrap(); | 846 | let window_idx = column.position(window).unwrap(); |
| 847 | - self.remove_window_by_idx(column_idx, window_idx); | 847 | + self.remove_window_by_idx(column_idx, window_idx) |
| 848 | } | 848 | } |
| 849 | 849 | ||
| 850 | - pub fn update_window(&mut self, window: &W) { | 850 | + pub fn update_window(&mut self, window: &W::Id) { |
| 851 | let (idx, column) = self | 851 | let (idx, column) = self |
| 852 | .columns | 852 | .columns |
| 853 | .iter_mut() | 853 | .iter_mut() |
| @@ -869,7 +869,7 @@ impl<W: LayoutElement> Workspace<W> { | |||
| 869 | } | 869 | } |
| 870 | } | 870 | } |
| 871 | 871 | ||
| 872 | - pub fn activate_window(&mut self, window: &W) { | 872 | + pub fn activate_window(&mut self, window: &W::Id) { |
| 873 | let column_idx = self | 873 | let column_idx = self |
| 874 | .columns | 874 | .columns |
| 875 | .iter() | 875 | .iter() |
| @@ -1233,7 +1233,7 @@ impl<W: LayoutElement> Workspace<W> { | |||
| 1233 | self.columns[self.active_column_idx].set_window_height(change); | 1233 | self.columns[self.active_column_idx].set_window_height(change); |
| 1234 | } | 1234 | } |
| 1235 | 1235 | ||
| 1236 | - pub fn set_fullscreen(&mut self, window: &W, is_fullscreen: bool) { | 1236 | + pub fn set_fullscreen(&mut self, window: &W::Id, is_fullscreen: bool) { |
| 1237 | let (mut col_idx, tile_idx) = self | 1237 | let (mut col_idx, tile_idx) = self |
| 1238 | .columns | 1238 | .columns |
| 1239 | .iter() | 1239 | .iter() |
| @@ -1275,7 +1275,7 @@ impl<W: LayoutElement> Workspace<W> { | |||
| 1275 | col.set_fullscreen(is_fullscreen); | 1275 | col.set_fullscreen(is_fullscreen); |
| 1276 | } | 1276 | } |
| 1277 | 1277 | ||
| 1278 | - pub fn toggle_fullscreen(&mut self, window: &W) { | 1278 | + pub fn toggle_fullscreen(&mut self, window: &W::Id) { |
| 1279 | let col = self | 1279 | let col = self |
| 1280 | .columns | 1280 | .columns |
| 1281 | .iter_mut() | 1281 | .iter_mut() |
| @@ -1654,18 +1654,21 @@ impl<W: LayoutElement> Column<W> { | |||
| 1654 | self.tiles.iter().any(Tile::are_animations_ongoing) | 1654 | self.tiles.iter().any(Tile::are_animations_ongoing) |
| 1655 | } | 1655 | } |
| 1656 | 1656 | ||
| 1657 | - pub fn contains(&self, window: &W) -> bool { | 1657 | + pub fn contains(&self, window: &W::Id) -> bool { |
| 1658 | - self.tiles.iter().map(Tile::window).any(|win| win == window) | 1658 | + self.tiles |
| 1659 | + .iter() | ||
| 1660 | + .map(Tile::window) | ||
| 1661 | + .any(|win| win.id() == window) | ||
| 1659 | } | 1662 | } |
| 1660 | 1663 | ||
| 1661 | - pub fn position(&self, window: &W) -> Option<usize> { | 1664 | + pub fn position(&self, window: &W::Id) -> Option<usize> { |
| 1662 | self.tiles | 1665 | self.tiles |
| 1663 | .iter() | 1666 | .iter() |
| 1664 | .map(Tile::window) | 1667 | .map(Tile::window) |
| 1665 | - .position(|win| win == window) | 1668 | + .position(|win| win.id() == window) |
| 1666 | } | 1669 | } |
| 1667 | 1670 | ||
| 1668 | - fn activate_window(&mut self, window: &W) { | 1671 | + fn activate_window(&mut self, window: &W::Id) { |
| 1669 | let idx = self.position(window).unwrap(); | 1672 | let idx = self.position(window).unwrap(); |
| 1670 | self.active_tile_idx = idx; | 1673 | self.active_tile_idx = idx; |
| 1671 | } | 1674 | } |
| @@ -1678,11 +1681,11 @@ impl<W: LayoutElement> Column<W> { | |||
| 1678 | self.update_tile_sizes(); | 1681 | self.update_tile_sizes(); |
| 1679 | } | 1682 | } |
| 1680 | 1683 | ||
| 1681 | - fn update_window(&mut self, window: &W) { | 1684 | + fn update_window(&mut self, window: &W::Id) { |
| 1682 | let tile = self | 1685 | let tile = self |
| 1683 | .tiles | 1686 | .tiles |
| 1684 | .iter_mut() | 1687 | .iter_mut() |
| 1685 | - .find(|tile| tile.window() == window) | 1688 | + .find(|tile| tile.window().id() == window) |
| 1686 | .unwrap(); | 1689 | .unwrap(); |
| 1687 | tile.update_window(); | 1690 | tile.update_window(); |
| 1688 | } | 1691 | } |