diff options
| author | Ivan Molodetskikh <yalterz@gmail.com> | 2024-12-28 12:06:22 +0300 |
|---|---|---|
| committer | Ivan Molodetskikh <yalterz@gmail.com> | 2024-12-30 20:12:37 +0300 |
| commit | 4ea4d2bd3bea5407c6ddc0ee33f55025ffc1bf38 (patch) | |
| tree | a1a0d3162e6411e141d0996c9f87f3d09a2562d0 | |
| parent | 6c52077d922dce3a9b57c6785647b6befb700ac9 (diff) | |
| download | niri-4ea4d2bd3bea5407c6ddc0ee33f55025ffc1bf38.tar.gz niri-4ea4d2bd3bea5407c6ddc0ee33f55025ffc1bf38.tar.bz2 niri-4ea4d2bd3bea5407c6ddc0ee33f55025ffc1bf38.zip | |
layout: Add animate arg to move_floating_window()
| -rw-r--r-- | src/input/mod.rs | 4 | ||||
| -rw-r--r-- | src/layout/floating.rs | 24 | ||||
| -rw-r--r-- | src/layout/mod.rs | 8 | ||||
| -rw-r--r-- | src/layout/workspace.rs | 3 |
4 files changed, 28 insertions, 11 deletions
diff --git a/src/input/mod.rs b/src/input/mod.rs index 83336fb3..9dd86179 100644 --- a/src/input/mod.rs +++ b/src/input/mod.rs @@ -1373,7 +1373,9 @@ impl State { None }; - self.niri.layout.move_floating_window(window.as_ref(), x, y); + self.niri + .layout + .move_floating_window(window.as_ref(), x, y, true); // FIXME: granular self.niri.queue_redraw_all(); } diff --git a/src/layout/floating.rs b/src/layout/floating.rs index d59a33e7..af208615 100644 --- a/src/layout/floating.rs +++ b/src/layout/floating.rs @@ -839,8 +839,13 @@ impl<W: LayoutElement> FloatingSpace<W> { } } - fn move_to(&mut self, idx: usize, new_pos: Point<f64, Logical>) { - self.move_and_animate(idx, new_pos); + fn move_to(&mut self, idx: usize, new_pos: Point<f64, Logical>, animate: bool) { + if animate { + self.move_and_animate(idx, new_pos); + } else { + self.data[idx].set_logical_pos(new_pos); + } + self.interactive_resize_end(None); } @@ -851,7 +856,7 @@ impl<W: LayoutElement> FloatingSpace<W> { let idx = self.idx_of(active_id).unwrap(); let new_pos = self.data[idx].logical_pos + amount; - self.move_to(idx, new_pos) + self.move_to(idx, new_pos, true) } pub fn move_left(&mut self) { @@ -870,7 +875,13 @@ impl<W: LayoutElement> FloatingSpace<W> { self.move_by(Point::from((0., DIRECTIONAL_MOVE_PX))); } - pub fn move_window(&mut self, id: Option<&W::Id>, x: PositionChange, y: PositionChange) { + pub fn move_window( + &mut self, + id: Option<&W::Id>, + x: PositionChange, + y: PositionChange, + animate: bool, + ) { let Some(id) = id.or(self.active_window_id.as_ref()) else { return; }; @@ -885,7 +896,8 @@ impl<W: LayoutElement> FloatingSpace<W> { PositionChange::SetFixed(y) => new_pos.y = y + self.working_area.loc.y, PositionChange::AdjustFixed(y) => new_pos.y += y, } - self.move_to(idx, new_pos); + + self.move_to(idx, new_pos, animate); } pub fn center_window(&mut self) { @@ -895,7 +907,7 @@ impl<W: LayoutElement> FloatingSpace<W> { let idx = self.idx_of(active_id).unwrap(); let new_pos = center_preferring_top_left_in_area(self.working_area, self.data[idx].size); - self.move_to(idx, new_pos); + self.move_to(idx, new_pos, true); } pub fn descendants_added(&mut self, id: &W::Id) -> bool { diff --git a/src/layout/mod.rs b/src/layout/mod.rs index ed92fad3..0e068499 100644 --- a/src/layout/mod.rs +++ b/src/layout/mod.rs @@ -2755,6 +2755,7 @@ impl<W: LayoutElement> Layout<W> { id: Option<&W::Id>, x: PositionChange, y: PositionChange, + animate: bool, ) { if let Some(InteractiveMoveState::Moving(move_)) = &mut self.interactive_move { if id.is_none() || id == Some(move_.tile.window().id()) { @@ -2771,7 +2772,7 @@ impl<W: LayoutElement> Layout<W> { let Some(workspace) = workspace else { return; }; - workspace.move_floating_window(id, x, y); + workspace.move_floating_window(id, x, y, animate); } pub fn focus_output(&mut self, output: &Output) { @@ -4450,6 +4451,7 @@ mod tests { x: PositionChange, #[proptest(strategy = "arbitrary_position_change()")] y: PositionChange, + animate: bool, }, SetParent { #[proptest(strategy = "1..=5usize")] @@ -4975,9 +4977,9 @@ mod tests { Op::SwitchFocusFloatingTiling => { layout.switch_focus_floating_tiling(); } - Op::MoveFloatingWindow { id, x, y } => { + Op::MoveFloatingWindow { id, x, y, animate } => { let id = id.filter(|id| layout.has_window(id)); - layout.move_floating_window(id.as_ref(), x, y); + layout.move_floating_window(id.as_ref(), x, y, animate); } Op::SetParent { id, diff --git a/src/layout/workspace.rs b/src/layout/workspace.rs index de190275..9b362eaf 100644 --- a/src/layout/workspace.rs +++ b/src/layout/workspace.rs @@ -1190,11 +1190,12 @@ impl<W: LayoutElement> Workspace<W> { id: Option<&W::Id>, x: PositionChange, y: PositionChange, + animate: bool, ) { if id.map_or(self.floating_is_active.get(), |id| { self.floating.has_window(id) }) { - self.floating.move_window(id, x, y); + self.floating.move_window(id, x, y, animate); } else { // If the target tile isn't floating, set its stored floating position. let tile = if let Some(id) = id { |
