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 | 2 | use std::time::Duration; |
| 3 | 3 | |
| 4 | 4 | use niri::layout::workspace::ColumnWidth; |
| 5 | -use niri::layout::Options; | |
| 5 | +use niri::layout::{LayoutElement as _, Options}; | |
| 6 | 6 | use niri::utils::get_monotonic_time; |
| 7 | 7 | use niri_config::Color; |
| 8 | 8 | use smithay::backend::renderer::element::RenderElement; |
| @@ -73,12 +73,12 @@ impl Layout { | ||
| 73 | 73 | |
| 74 | 74 | rv.add_window(TestWindow::freeform(0), Some(ColumnWidth::Proportion(0.3))); |
| 75 | 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 | 78 | rv.add_step(500, |l| { |
| 79 | 79 | let win = TestWindow::freeform(2); |
| 80 | 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 | 84 | rv |
| @@ -91,7 +91,7 @@ impl Layout { | ||
| 91 | 91 | rv.add_step(delay, move |l| { |
| 92 | 92 | let win = TestWindow::freeform(delay as usize); |
| 93 | 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 | 105 | rv.add_step(delay, move |l| { |
| 106 | 106 | let win = TestWindow::freeform(delay as usize); |
| 107 | 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 | 122 | let win = TestWindow::freeform(2); |
| 123 | 123 | let right_of = l.windows[0].clone(); |
| 124 | 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 | 128 | rv |
| @@ -138,7 +138,7 @@ impl Layout { | ||
| 138 | 138 | let win = TestWindow::freeform(2); |
| 139 | 139 | let right_of = l.windows[0].clone(); |
| 140 | 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 | 144 | rv |
| @@ -147,7 +147,7 @@ impl Layout { | ||
| 147 | 147 | fn add_window(&mut self, window: TestWindow, width: Option<ColumnWidth>) { |
| 148 | 148 | self.layout.add_window(window.clone(), width, false); |
| 149 | 149 | if window.communicate() { |
| 150 | - self.layout.update_window(&window); | |
| 150 | + self.layout.update_window(window.id()); | |
| 151 | 151 | } |
| 152 | 152 | self.windows.push(window); |
| 153 | 153 | } |
| @@ -159,9 +159,9 @@ impl Layout { | ||
| 159 | 159 | width: Option<ColumnWidth>, |
| 160 | 160 | ) { |
| 161 | 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 | 163 | if window.communicate() { |
| 164 | - self.layout.update_window(&window); | |
| 164 | + self.layout.update_window(window.id()); | |
| 165 | 165 | } |
| 166 | 166 | self.windows.push(window); |
| 167 | 167 | } |
| @@ -183,7 +183,7 @@ impl TestCase for Layout { | ||
| 183 | 183 | self.layout.update_output_size(&self.output); |
| 184 | 184 | for win in &self.windows { |
| 185 | 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 | 13 | #[derive(Debug)] |
| 14 | 14 | struct TestWindowInner { |
| 15 | - id: usize, | |
| 16 | 15 | size: Size<i32, Logical>, |
| 17 | 16 | requested_size: Option<Size<i32, Logical>>, |
| 18 | 17 | min_size: Size<i32, Logical>, |
| @@ -24,7 +23,10 @@ struct TestWindowInner { | ||
| 24 | 23 | } |
| 25 | 24 | |
| 26 | 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 | 31 | impl TestWindow { |
| 30 | 32 | pub fn freeform(id: usize) -> Self { |
| @@ -33,17 +35,19 @@ impl TestWindow { | ||
| 33 | 35 | let max_size = Size::from((0, 0)); |
| 34 | 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 | 39 | id, |
| 38 | - size, | |
| 39 | - requested_size: None, | |
| 40 | - min_size, | |
| 41 | - max_size, | |
| 42 | - buffer, | |
| 43 | - pending_fullscreen: false, | |
| 44 | - csd_shadow_width: 0, | |
| 45 | - csd_shadow_buffer: SolidColorBuffer::new((0, 0), [0., 0., 0., 0.3]), | |
| 46 | - }))) | |
| 40 | + inner: Rc::new(RefCell::new(TestWindowInner { | |
| 41 | + size, | |
| 42 | + requested_size: None, | |
| 43 | + min_size, | |
| 44 | + max_size, | |
| 45 | + buffer, | |
| 46 | + pending_fullscreen: false, | |
| 47 | + csd_shadow_width: 0, | |
| 48 | + csd_shadow_buffer: SolidColorBuffer::new((0, 0), [0., 0., 0., 0.3]), | |
| 49 | + })), | |
| 50 | + } | |
| 47 | 51 | } |
| 48 | 52 | |
| 49 | 53 | pub fn fixed_size(id: usize) -> Self { |
| @@ -56,24 +60,24 @@ impl TestWindow { | ||
| 56 | 60 | } |
| 57 | 61 | |
| 58 | 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 | 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 | 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 | 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 | 78 | pub fn communicate(&self) -> bool { |
| 75 | 79 | let mut rv = false; |
| 76 | - let mut inner = self.0.borrow_mut(); | |
| 80 | + let mut inner = self.inner.borrow_mut(); | |
| 77 | 81 | |
| 78 | 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 { | |
| 121 | - fn eq(&self, other: &Self) -> bool { | |
| 122 | - self.0.borrow().id == other.0.borrow().id | |
| 124 | +impl LayoutElement for TestWindow { | |
| 125 | + type Id = usize; | |
| 126 | + | |
| 127 | + fn id(&self) -> &Self::Id { | |
| 128 | + &self.id | |
| 123 | 129 | } |
| 124 | -} | |
| 125 | 130 | |
| 126 | -impl LayoutElement for TestWindow { | |
| 127 | 131 | fn size(&self) -> Size<i32, Logical> { |
| 128 | - self.0.borrow().size | |
| 132 | + self.inner.borrow().size | |
| 129 | 133 | } |
| 130 | 134 | |
| 131 | 135 | fn buf_loc(&self) -> Point<i32, Logical> { |
| @@ -142,7 +146,7 @@ impl LayoutElement for TestWindow { | ||
| 142 | 146 | location: Point<i32, Logical>, |
| 143 | 147 | scale: Scale<f64>, |
| 144 | 148 | ) -> Vec<LayoutElementRenderElement<R>> { |
| 145 | - let inner = self.0.borrow(); | |
| 149 | + let inner = self.inner.borrow(); | |
| 146 | 150 | |
| 147 | 151 | vec![ |
| 148 | 152 | SolidColorRenderElement::from_buffer( |
| @@ -166,20 +170,20 @@ impl LayoutElement for TestWindow { | ||
| 166 | 170 | } |
| 167 | 171 | |
| 168 | 172 | fn request_size(&self, size: Size<i32, Logical>) { |
| 169 | - self.0.borrow_mut().requested_size = Some(size); | |
| 170 | - self.0.borrow_mut().pending_fullscreen = false; | |
| 173 | + self.inner.borrow_mut().requested_size = Some(size); | |
| 174 | + self.inner.borrow_mut().pending_fullscreen = false; | |
| 171 | 175 | } |
| 172 | 176 | |
| 173 | 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 | 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 | 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 | 189 | fn is_wl_surface(&self, _wl_surface: &WlSurface) -> bool { |
| @@ -203,6 +207,6 @@ impl LayoutElement for TestWindow { | ||
| 203 | 207 | } |
| 204 | 208 | |
| 205 | 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 | 365 | if &requested_output != current_output { |
| 366 | 366 | self.niri |
| 367 | 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 | 289 | if &requested_output != current_output { |
| 290 | 290 | self.niri |
| 291 | 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 | 79 | /// Visual size of the element. |
| 74 | 80 | /// |
| 75 | 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 | 225 | impl LayoutElement for Window { |
| 226 | + type Id = Self; | |
| 227 | + | |
| 228 | + fn id(&self) -> &Self::Id { | |
| 229 | + self | |
| 230 | + } | |
| 231 | + | |
| 220 | 232 | fn size(&self) -> Size<i32, Logical> { |
| 221 | 233 | self.geometry().size |
| 222 | 234 | } |
| @@ -599,7 +611,7 @@ impl<W: LayoutElement> Layout<W> { | ||
| 599 | 611 | /// Returns an output that the window was added to, if there were any outputs. |
| 600 | 612 | pub fn add_window_right_of( |
| 601 | 613 | &mut self, |
| 602 | - right_of: &W, | |
| 614 | + right_of: &W::Id, | |
| 603 | 615 | window: W, |
| 604 | 616 | width: Option<ColumnWidth>, |
| 605 | 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 | 699 | match &mut self.monitor_set { |
| 686 | 700 | MonitorSet::Normal { monitors, .. } => { |
| 687 | 701 | for mon in monitors { |
| 688 | 702 | for (idx, ws) in mon.workspaces.iter_mut().enumerate() { |
| 689 | 703 | if ws.has_window(window) { |
| 690 | - ws.remove_window(window); | |
| 704 | + rv = Some(ws.remove_window(window)); | |
| 691 | 705 | |
| 692 | 706 | // Clean up empty workspaces that are not active and not last. |
| 693 | 707 | if !ws.has_windows() |
| @@ -710,7 +724,7 @@ impl<W: LayoutElement> Layout<W> { | ||
| 710 | 724 | MonitorSet::NoOutputs { workspaces, .. } => { |
| 711 | 725 | for (idx, ws) in workspaces.iter_mut().enumerate() { |
| 712 | 726 | if ws.has_window(window) { |
| 713 | - ws.remove_window(window); | |
| 727 | + rv = Some(ws.remove_window(window)); | |
| 714 | 728 | |
| 715 | 729 | // Clean up empty workspaces. |
| 716 | 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 | 744 | match &mut self.monitor_set { |
| 729 | 745 | MonitorSet::Normal { monitors, .. } => { |
| 730 | 746 | for mon in monitors { |
| @@ -761,7 +777,7 @@ impl<W: LayoutElement> Layout<W> { | ||
| 761 | 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 | 781 | match &self.monitor_set { |
| 766 | 782 | MonitorSet::Normal { monitors, .. } => { |
| 767 | 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 | 830 | let MonitorSet::Normal { |
| 815 | 831 | monitors, |
| 816 | 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 | 1513 | let mut width = None; |
| 1498 | 1514 | let mut is_full_width = false; |
| 1499 | 1515 | |
| @@ -1501,7 +1517,7 @@ impl<W: LayoutElement> Layout<W> { | ||
| 1501 | 1517 | for mon in &*monitors { |
| 1502 | 1518 | for ws in &mon.workspaces { |
| 1503 | 1519 | for col in &ws.columns { |
| 1504 | - if col.contains(&window) { | |
| 1520 | + if col.contains(window) { | |
| 1505 | 1521 | width = Some(col.width); |
| 1506 | 1522 | is_full_width = col.is_full_width; |
| 1507 | 1523 | break; |
| @@ -1513,7 +1529,7 @@ impl<W: LayoutElement> Layout<W> { | ||
| 1513 | 1529 | |
| 1514 | 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 | 1534 | if let MonitorSet::Normal { monitors, .. } = &mut self.monitor_set { |
| 1519 | 1535 | let new_idx = monitors |
| @@ -1570,7 +1586,7 @@ impl<W: LayoutElement> Layout<W> { | ||
| 1570 | 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 | 1590 | match &mut self.monitor_set { |
| 1575 | 1591 | MonitorSet::Normal { monitors, .. } => { |
| 1576 | 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 | 1613 | match &mut self.monitor_set { |
| 1598 | 1614 | MonitorSet::Normal { monitors, .. } => { |
| 1599 | 1615 | for mon in monitors { |
| @@ -1746,14 +1762,14 @@ impl<W: LayoutElement> Layout<W> { | ||
| 1746 | 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 | 1766 | match &mut self.monitor_set { |
| 1751 | 1767 | MonitorSet::Normal { monitors, .. } => { |
| 1752 | 1768 | for mon in monitors { |
| 1753 | 1769 | for ws in &mut mon.workspaces { |
| 1754 | 1770 | for col in &mut ws.columns { |
| 1755 | 1771 | for tile in &mut col.tiles { |
| 1756 | - if tile.window() == window { | |
| 1772 | + if tile.window().id() == window { | |
| 1757 | 1773 | tile.start_open_animation(); |
| 1758 | 1774 | return; |
| 1759 | 1775 | } |
| @@ -1764,13 +1780,11 @@ impl<W: LayoutElement> Layout<W> { | ||
| 1764 | 1780 | } |
| 1765 | 1781 | MonitorSet::NoOutputs { workspaces, .. } => { |
| 1766 | 1782 | for ws in workspaces { |
| 1767 | - if ws.has_window(window) { | |
| 1768 | - for col in &mut ws.columns { | |
| 1769 | - for tile in &mut col.tiles { | |
| 1770 | - if tile.window() == window { | |
| 1771 | - tile.start_open_animation(); | |
| 1772 | - return; | |
| 1773 | - } | |
| 1783 | + for col in &mut ws.columns { | |
| 1784 | + for tile in &mut col.tiles { | |
| 1785 | + if tile.window().id() == window { | |
| 1786 | + tile.start_open_animation(); | |
| 1787 | + return; | |
| 1774 | 1788 | } |
| 1775 | 1789 | } |
| 1776 | 1790 | } |
| @@ -1889,13 +1903,13 @@ mod tests { | ||
| 1889 | 1903 | } |
| 1890 | 1904 | } |
| 1891 | 1905 | |
| 1892 | - impl PartialEq for TestWindow { | |
| 1893 | - fn eq(&self, other: &Self) -> bool { | |
| 1894 | - self.0.id == other.0.id | |
| 1906 | + impl LayoutElement for TestWindow { | |
| 1907 | + type Id = usize; | |
| 1908 | + | |
| 1909 | + fn id(&self) -> &Self::Id { | |
| 1910 | + &self.0.id | |
| 1895 | 1911 | } |
| 1896 | - } | |
| 1897 | 1912 | |
| 1898 | - impl LayoutElement for TestWindow { | |
| 1899 | 1913 | fn size(&self) -> Size<i32, Logical> { |
| 1900 | 1914 | self.0.bbox.get().size |
| 1901 | 1915 | } |
| @@ -2208,24 +2222,14 @@ mod tests { | ||
| 2208 | 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 | 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 | 2228 | Op::CloseWindow(id) => { |
| 2221 | - let dummy = | |
| 2222 | - TestWindow::new(id, Rectangle::default(), Size::default(), Size::default()); | |
| 2223 | - layout.remove_window(&dummy); | |
| 2229 | + layout.remove_window(&id); | |
| 2224 | 2230 | } |
| 2225 | 2231 | Op::FullscreenWindow(id) => { |
| 2226 | - let dummy = | |
| 2227 | - TestWindow::new(id, Rectangle::default(), Size::default(), Size::default()); | |
| 2228 | - layout.toggle_fullscreen(&dummy); | |
| 2232 | + layout.toggle_fullscreen(&id); | |
| 2229 | 2233 | } |
| 2230 | 2234 | Op::FocusColumnLeft => layout.focus_left(), |
| 2231 | 2235 | Op::FocusColumnRight => layout.focus_right(), |
| @@ -2284,7 +2288,7 @@ mod tests { | ||
| 2284 | 2288 | Op::SetColumnWidth(change) => layout.set_column_width(change), |
| 2285 | 2289 | Op::SetWindowHeight(change) => layout.set_window_height(change), |
| 2286 | 2290 | Op::Communicate(id) => { |
| 2287 | - let mut window = None; | |
| 2291 | + let mut update = false; | |
| 2288 | 2292 | match &mut layout.monitor_set { |
| 2289 | 2293 | MonitorSet::Normal { monitors, .. } => { |
| 2290 | 2294 | 'outer: for mon in monitors { |
| @@ -2292,7 +2296,7 @@ mod tests { | ||
| 2292 | 2296 | for win in ws.windows() { |
| 2293 | 2297 | if win.0.id == id { |
| 2294 | 2298 | if win.communicate() { |
| 2295 | - window = Some(win.clone()); | |
| 2299 | + update = true; | |
| 2296 | 2300 | } |
| 2297 | 2301 | break 'outer; |
| 2298 | 2302 | } |
| @@ -2305,7 +2309,7 @@ mod tests { | ||
| 2305 | 2309 | for win in ws.windows() { |
| 2306 | 2310 | if win.0.id == id { |
| 2307 | 2311 | if win.communicate() { |
| 2308 | - window = Some(win.clone()); | |
| 2312 | + update = true; | |
| 2309 | 2313 | } |
| 2310 | 2314 | break 'outer; |
| 2311 | 2315 | } |
| @@ -2314,8 +2318,8 @@ mod tests { | ||
| 2314 | 2318 | } |
| 2315 | 2319 | } |
| 2316 | 2320 | |
| 2317 | - if let Some(win) = window { | |
| 2318 | - layout.update_window(&win); | |
| 2321 | + if update { | |
| 2322 | + layout.update_window(&id); | |
| 2319 | 2323 | } |
| 2320 | 2324 | } |
| 2321 | 2325 | Op::MoveWorkspaceToOutput(id) => { |
src/layout/monitor.rsmodified+1 -1
| @@ -159,7 +159,7 @@ impl<W: LayoutElement> Monitor<W> { | ||
| 159 | 159 | |
| 160 | 160 | pub fn add_window_right_of( |
| 161 | 161 | &mut self, |
| 162 | - right_of: &W, | |
| 162 | + right_of: &W::Id, | |
| 163 | 163 | window: W, |
| 164 | 164 | width: ColumnWidth, |
| 165 | 165 | is_full_width: bool, |
src/layout/workspace.rsmodified+19 -16
| @@ -577,8 +577,8 @@ impl<W: LayoutElement> Workspace<W> { | ||
| 577 | 577 | self.windows().next().is_some() |
| 578 | 578 | } |
| 579 | 579 | |
| 580 | - pub fn has_window(&self, window: &W) -> bool { | |
| 581 | - self.windows().any(|win| win == window) | |
| 580 | + pub fn has_window(&self, window: &W::Id) -> bool { | |
| 581 | + self.windows().any(|win| win.id() == window) | |
| 582 | 582 | } |
| 583 | 583 | |
| 584 | 584 | pub fn find_wl_surface(&self, wl_surface: &WlSurface) -> Option<&W> { |
| @@ -658,7 +658,7 @@ impl<W: LayoutElement> Workspace<W> { | ||
| 658 | 658 | |
| 659 | 659 | pub fn add_window_right_of( |
| 660 | 660 | &mut self, |
| 661 | - right_of: &W, | |
| 661 | + right_of: &W::Id, | |
| 662 | 662 | window: W, |
| 663 | 663 | width: ColumnWidth, |
| 664 | 664 | is_full_width: bool, |
| @@ -835,7 +835,7 @@ impl<W: LayoutElement> Workspace<W> { | ||
| 835 | 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 | 839 | let column_idx = self |
| 840 | 840 | .columns |
| 841 | 841 | .iter() |
| @@ -844,10 +844,10 @@ impl<W: LayoutElement> Workspace<W> { | ||
| 844 | 844 | let column = &self.columns[column_idx]; |
| 845 | 845 | |
| 846 | 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 | 851 | let (idx, column) = self |
| 852 | 852 | .columns |
| 853 | 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 | 873 | let column_idx = self |
| 874 | 874 | .columns |
| 875 | 875 | .iter() |
| @@ -1233,7 +1233,7 @@ impl<W: LayoutElement> Workspace<W> { | ||
| 1233 | 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 | 1237 | let (mut col_idx, tile_idx) = self |
| 1238 | 1238 | .columns |
| 1239 | 1239 | .iter() |
| @@ -1275,7 +1275,7 @@ impl<W: LayoutElement> Workspace<W> { | ||
| 1275 | 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 | 1279 | let col = self |
| 1280 | 1280 | .columns |
| 1281 | 1281 | .iter_mut() |
| @@ -1654,18 +1654,21 @@ impl<W: LayoutElement> Column<W> { | ||
| 1654 | 1654 | self.tiles.iter().any(Tile::are_animations_ongoing) |
| 1655 | 1655 | } |
| 1656 | 1656 | |
| 1657 | - pub fn contains(&self, window: &W) -> bool { | |
| 1658 | - self.tiles.iter().map(Tile::window).any(|win| win == window) | |
| 1657 | + pub fn contains(&self, window: &W::Id) -> bool { | |
| 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 | 1665 | self.tiles |
| 1663 | 1666 | .iter() |
| 1664 | 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 | 1672 | let idx = self.position(window).unwrap(); |
| 1670 | 1673 | self.active_tile_idx = idx; |
| 1671 | 1674 | } |
| @@ -1678,11 +1681,11 @@ impl<W: LayoutElement> Column<W> { | ||
| 1678 | 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 | 1685 | let tile = self |
| 1683 | 1686 | .tiles |
| 1684 | 1687 | .iter_mut() |
| 1685 | - .find(|tile| tile.window() == window) | |
| 1688 | + .find(|tile| tile.window().id() == window) | |
| 1686 | 1689 | .unwrap(); |
| 1687 | 1690 | tile.update_window(); |
| 1688 | 1691 | } |