From 69f723d68aa28698488618e00688ef3a84e40819 Mon Sep 17 00:00:00 2001 From: Ivan Molodetskikh Date: Mon, 15 Apr 2024 21:19:09 +0400 Subject: Implement vertical window move animations --- src/layout/tile.rs | 8 ++++++++ src/layout/workspace.rs | 28 ++++++++++++++++++++++++++-- 2 files changed, 34 insertions(+), 2 deletions(-) diff --git a/src/layout/tile.rs b/src/layout/tile.rs index e1f9297f..b578b0c0 100644 --- a/src/layout/tile.rs +++ b/src/layout/tile.rs @@ -243,6 +243,14 @@ impl Tile { self.resize_animation.as_ref().map(|resize| &resize.anim) } + pub fn animate_move_from(&mut self, from: Point) { + self.animate_move_from_with_config( + from, + self.options.animations.window_movement, + niri_config::Animation::default_window_movement(), + ); + } + pub fn animate_move_from_with_config( &mut self, from: Point, diff --git a/src/layout/workspace.rs b/src/layout/workspace.rs index 39e377b5..186b3d22 100644 --- a/src/layout/workspace.rs +++ b/src/layout/workspace.rs @@ -2250,9 +2250,19 @@ impl Column { return; } + let mut ys = self.tile_ys().skip(self.active_tile_idx); + let active_y = ys.next().unwrap(); + let next_y = ys.next().unwrap(); + drop(ys); + self.tiles.swap(self.active_tile_idx, new_idx); self.heights.swap(self.active_tile_idx, new_idx); self.active_tile_idx = new_idx; + + // Animate the movement. + let new_active_y = self.tile_y(new_idx); + self.tiles[new_idx].animate_move_from(Point::from((0, active_y - new_active_y))); + self.tiles[new_idx + 1].animate_move_from(Point::from((0, active_y - next_y))); } fn move_down(&mut self) { @@ -2261,9 +2271,19 @@ impl Column { return; } + let mut ys = self.tile_ys().skip(self.active_tile_idx); + let active_y = ys.next().unwrap(); + let next_y = ys.next().unwrap(); + drop(ys); + self.tiles.swap(self.active_tile_idx, new_idx); self.heights.swap(self.active_tile_idx, new_idx); self.active_tile_idx = new_idx; + + // Animate the movement. + let new_active_y = self.tile_y(new_idx); + self.tiles[new_idx].animate_move_from(Point::from((0, active_y - new_active_y))); + self.tiles[new_idx - 1].animate_move_from(Point::from((0, next_y - active_y))); } #[cfg(test)] @@ -2431,9 +2451,13 @@ impl Column { y = self.working_area.loc.y + self.options.gaps; } - self.tiles.iter().map(move |tile| { + let heights = self.tiles.iter().map(|tile| tile.tile_size().h); + + // Chain an arbitrary height to be able to get the Y that the next tile past the end would + // have. + heights.chain(iter::once(0)).map(move |h| { let pos = y; - y += tile.tile_size().h + self.options.gaps; + y += h + self.options.gaps; pos }) } -- cgit