layout: Add animate arg to move_floating_window()
Browse files at this commit4ea4d2bd3bea5407c6ddc0ee33f55025ffc1bf38Parent: 6c520774 changed files +28 -11
- src/input/mod.rs +3 -1
- src/layout/floating.rs +18 -6
- src/layout/mod.rs +5 -3
- src/layout/workspace.rs +2 -1
src/input/mod.rsmodified+3 -1
| @@ -1373,7 +1373,9 @@ impl State { | |||
| 1373 | None | 1373 | None |
| 1374 | }; | 1374 | }; |
| 1375 | 1375 | ||
| 1376 | - self.niri.layout.move_floating_window(window.as_ref(), x, y); | 1376 | + self.niri |
| 1377 | + .layout | ||
| 1378 | + .move_floating_window(window.as_ref(), x, y, true); | ||
| 1377 | // FIXME: granular | 1379 | // FIXME: granular |
| 1378 | self.niri.queue_redraw_all(); | 1380 | self.niri.queue_redraw_all(); |
| 1379 | } | 1381 | } |
src/layout/floating.rsmodified+18 -6
| @@ -839,8 +839,13 @@ impl<W: LayoutElement> FloatingSpace<W> { | |||
| 839 | } | 839 | } |
| 840 | } | 840 | } |
| 841 | 841 | ||
| 842 | - fn move_to(&mut self, idx: usize, new_pos: Point<f64, Logical>) { | 842 | + fn move_to(&mut self, idx: usize, new_pos: Point<f64, Logical>, animate: bool) { |
| 843 | - self.move_and_animate(idx, new_pos); | 843 | + if animate { |
| 844 | + self.move_and_animate(idx, new_pos); | ||
| 845 | + } else { | ||
| 846 | + self.data[idx].set_logical_pos(new_pos); | ||
| 847 | + } | ||
| 848 | + | ||
| 844 | self.interactive_resize_end(None); | 849 | self.interactive_resize_end(None); |
| 845 | } | 850 | } |
| 846 | 851 | ||
| @@ -851,7 +856,7 @@ impl<W: LayoutElement> FloatingSpace<W> { | |||
| 851 | let idx = self.idx_of(active_id).unwrap(); | 856 | let idx = self.idx_of(active_id).unwrap(); |
| 852 | 857 | ||
| 853 | let new_pos = self.data[idx].logical_pos + amount; | 858 | let new_pos = self.data[idx].logical_pos + amount; |
| 854 | - self.move_to(idx, new_pos) | 859 | + self.move_to(idx, new_pos, true) |
| 855 | } | 860 | } |
| 856 | 861 | ||
| 857 | pub fn move_left(&mut self) { | 862 | pub fn move_left(&mut self) { |
| @@ -870,7 +875,13 @@ impl<W: LayoutElement> FloatingSpace<W> { | |||
| 870 | self.move_by(Point::from((0., DIRECTIONAL_MOVE_PX))); | 875 | self.move_by(Point::from((0., DIRECTIONAL_MOVE_PX))); |
| 871 | } | 876 | } |
| 872 | 877 | ||
| 873 | - pub fn move_window(&mut self, id: Option<&W::Id>, x: PositionChange, y: PositionChange) { | 878 | + pub fn move_window( |
| 879 | + &mut self, | ||
| 880 | + id: Option<&W::Id>, | ||
| 881 | + x: PositionChange, | ||
| 882 | + y: PositionChange, | ||
| 883 | + animate: bool, | ||
| 884 | + ) { | ||
| 874 | let Some(id) = id.or(self.active_window_id.as_ref()) else { | 885 | let Some(id) = id.or(self.active_window_id.as_ref()) else { |
| 875 | return; | 886 | return; |
| 876 | }; | 887 | }; |
| @@ -885,7 +896,8 @@ impl<W: LayoutElement> FloatingSpace<W> { | |||
| 885 | PositionChange::SetFixed(y) => new_pos.y = y + self.working_area.loc.y, | 896 | PositionChange::SetFixed(y) => new_pos.y = y + self.working_area.loc.y, |
| 886 | PositionChange::AdjustFixed(y) => new_pos.y += y, | 897 | PositionChange::AdjustFixed(y) => new_pos.y += y, |
| 887 | } | 898 | } |
| 888 | - self.move_to(idx, new_pos); | 899 | + |
| 900 | + self.move_to(idx, new_pos, animate); | ||
| 889 | } | 901 | } |
| 890 | 902 | ||
| 891 | pub fn center_window(&mut self) { | 903 | pub fn center_window(&mut self) { |
| @@ -895,7 +907,7 @@ impl<W: LayoutElement> FloatingSpace<W> { | |||
| 895 | let idx = self.idx_of(active_id).unwrap(); | 907 | let idx = self.idx_of(active_id).unwrap(); |
| 896 | 908 | ||
| 897 | let new_pos = center_preferring_top_left_in_area(self.working_area, self.data[idx].size); | 909 | let new_pos = center_preferring_top_left_in_area(self.working_area, self.data[idx].size); |
| 898 | - self.move_to(idx, new_pos); | 910 | + self.move_to(idx, new_pos, true); |
| 899 | } | 911 | } |
| 900 | 912 | ||
| 901 | pub fn descendants_added(&mut self, id: &W::Id) -> bool { | 913 | pub fn descendants_added(&mut self, id: &W::Id) -> bool { |
src/layout/mod.rsmodified+5 -3
| @@ -2755,6 +2755,7 @@ impl<W: LayoutElement> Layout<W> { | |||
| 2755 | id: Option<&W::Id>, | 2755 | id: Option<&W::Id>, |
| 2756 | x: PositionChange, | 2756 | x: PositionChange, |
| 2757 | y: PositionChange, | 2757 | y: PositionChange, |
| 2758 | + animate: bool, | ||
| 2758 | ) { | 2759 | ) { |
| 2759 | if let Some(InteractiveMoveState::Moving(move_)) = &mut self.interactive_move { | 2760 | if let Some(InteractiveMoveState::Moving(move_)) = &mut self.interactive_move { |
| 2760 | if id.is_none() || id == Some(move_.tile.window().id()) { | 2761 | if id.is_none() || id == Some(move_.tile.window().id()) { |
| @@ -2771,7 +2772,7 @@ impl<W: LayoutElement> Layout<W> { | |||
| 2771 | let Some(workspace) = workspace else { | 2772 | let Some(workspace) = workspace else { |
| 2772 | return; | 2773 | return; |
| 2773 | }; | 2774 | }; |
| 2774 | - workspace.move_floating_window(id, x, y); | 2775 | + workspace.move_floating_window(id, x, y, animate); |
| 2775 | } | 2776 | } |
| 2776 | 2777 | ||
| 2777 | pub fn focus_output(&mut self, output: &Output) { | 2778 | pub fn focus_output(&mut self, output: &Output) { |
| @@ -4450,6 +4451,7 @@ mod tests { | |||
| 4450 | x: PositionChange, | 4451 | x: PositionChange, |
| 4451 | #[proptest(strategy = "arbitrary_position_change()")] | 4452 | #[proptest(strategy = "arbitrary_position_change()")] |
| 4452 | y: PositionChange, | 4453 | y: PositionChange, |
| 4454 | + animate: bool, | ||
| 4453 | }, | 4455 | }, |
| 4454 | SetParent { | 4456 | SetParent { |
| 4455 | #[proptest(strategy = "1..=5usize")] | 4457 | #[proptest(strategy = "1..=5usize")] |
| @@ -4975,9 +4977,9 @@ mod tests { | |||
| 4975 | Op::SwitchFocusFloatingTiling => { | 4977 | Op::SwitchFocusFloatingTiling => { |
| 4976 | layout.switch_focus_floating_tiling(); | 4978 | layout.switch_focus_floating_tiling(); |
| 4977 | } | 4979 | } |
| 4978 | - Op::MoveFloatingWindow { id, x, y } => { | 4980 | + Op::MoveFloatingWindow { id, x, y, animate } => { |
| 4979 | let id = id.filter(|id| layout.has_window(id)); | 4981 | let id = id.filter(|id| layout.has_window(id)); |
| 4980 | - layout.move_floating_window(id.as_ref(), x, y); | 4982 | + layout.move_floating_window(id.as_ref(), x, y, animate); |
| 4981 | } | 4983 | } |
| 4982 | Op::SetParent { | 4984 | Op::SetParent { |
| 4983 | id, | 4985 | id, |
src/layout/workspace.rsmodified+2 -1
| @@ -1190,11 +1190,12 @@ impl<W: LayoutElement> Workspace<W> { | |||
| 1190 | id: Option<&W::Id>, | 1190 | id: Option<&W::Id>, |
| 1191 | x: PositionChange, | 1191 | x: PositionChange, |
| 1192 | y: PositionChange, | 1192 | y: PositionChange, |
| 1193 | + animate: bool, | ||
| 1193 | ) { | 1194 | ) { |
| 1194 | if id.map_or(self.floating_is_active.get(), |id| { | 1195 | if id.map_or(self.floating_is_active.get(), |id| { |
| 1195 | self.floating.has_window(id) | 1196 | self.floating.has_window(id) |
| 1196 | }) { | 1197 | }) { |
| 1197 | - self.floating.move_window(id, x, y); | 1198 | + self.floating.move_window(id, x, y, animate); |
| 1198 | } else { | 1199 | } else { |
| 1199 | // If the target tile isn't floating, set its stored floating position. | 1200 | // If the target tile isn't floating, set its stored floating position. |
| 1200 | let tile = if let Some(id) = id { | 1201 | let tile = if let Some(id) = id { |