Separate tile X and Y movement animations
Browse files at this commit2c8d1030ab2ea8cf65f2000056060d70c8627edcParent: f51dd672 changed files +59 -25
- src/layout/tile.rs +52 -18
- src/layout/workspace.rs +7 -7
src/layout/tile.rsmodified+52 -18
| @@ -57,8 +57,11 @@ pub struct Tile<W: LayoutElement> { | |||
| 57 | /// The animation of the window resizing. | 57 | /// The animation of the window resizing. |
| 58 | resize_animation: Option<ResizeAnimation>, | 58 | resize_animation: Option<ResizeAnimation>, |
| 59 | 59 | ||
| 60 | - /// The animation of a tile visually moving. | 60 | + /// The animation of a tile visually moving horizontally. |
| 61 | - move_animation: Option<MoveAnimation>, | 61 | + move_x_animation: Option<MoveAnimation>, |
| 62 | + | ||
| 63 | + /// The animation of a tile visually moving vertically. | ||
| 64 | + move_y_animation: Option<MoveAnimation>, | ||
| 62 | 65 | ||
| 63 | /// Configurable properties of the layout. | 66 | /// Configurable properties of the layout. |
| 64 | pub options: Rc<Options>, | 67 | pub options: Rc<Options>, |
| @@ -99,7 +102,7 @@ struct ResizeAnimation { | |||
| 99 | #[derive(Debug)] | 102 | #[derive(Debug)] |
| 100 | struct MoveAnimation { | 103 | struct MoveAnimation { |
| 101 | anim: Animation, | 104 | anim: Animation, |
| 102 | - from: Point<i32, Logical>, | 105 | + from: i32, |
| 103 | } | 106 | } |
| 104 | 107 | ||
| 105 | impl<W: LayoutElement> Tile<W> { | 108 | impl<W: LayoutElement> Tile<W> { |
| @@ -113,7 +116,8 @@ impl<W: LayoutElement> Tile<W> { | |||
| 113 | fullscreen_size: Default::default(), | 116 | fullscreen_size: Default::default(), |
| 114 | open_animation: None, | 117 | open_animation: None, |
| 115 | resize_animation: None, | 118 | resize_animation: None, |
| 116 | - move_animation: None, | 119 | + move_x_animation: None, |
| 120 | + move_y_animation: None, | ||
| 117 | options, | 121 | options, |
| 118 | } | 122 | } |
| 119 | } | 123 | } |
| @@ -177,10 +181,16 @@ impl<W: LayoutElement> Tile<W> { | |||
| 177 | } | 181 | } |
| 178 | } | 182 | } |
| 179 | 183 | ||
| 180 | - if let Some(move_) = &mut self.move_animation { | 184 | + if let Some(move_) = &mut self.move_x_animation { |
| 185 | + move_.anim.set_current_time(current_time); | ||
| 186 | + if move_.anim.is_done() { | ||
| 187 | + self.move_x_animation = None; | ||
| 188 | + } | ||
| 189 | + } | ||
| 190 | + if let Some(move_) = &mut self.move_y_animation { | ||
| 181 | move_.anim.set_current_time(current_time); | 191 | move_.anim.set_current_time(current_time); |
| 182 | if move_.anim.is_done() { | 192 | if move_.anim.is_done() { |
| 183 | - self.move_animation = None; | 193 | + self.move_y_animation = None; |
| 184 | } | 194 | } |
| 185 | } | 195 | } |
| 186 | 196 | ||
| @@ -206,14 +216,18 @@ impl<W: LayoutElement> Tile<W> { | |||
| 206 | pub fn are_animations_ongoing(&self) -> bool { | 216 | pub fn are_animations_ongoing(&self) -> bool { |
| 207 | self.open_animation.is_some() | 217 | self.open_animation.is_some() |
| 208 | || self.resize_animation.is_some() | 218 | || self.resize_animation.is_some() |
| 209 | - || self.move_animation.is_some() | 219 | + || self.move_x_animation.is_some() |
| 220 | + || self.move_y_animation.is_some() | ||
| 210 | } | 221 | } |
| 211 | 222 | ||
| 212 | pub fn render_offset(&self) -> Point<i32, Logical> { | 223 | pub fn render_offset(&self) -> Point<i32, Logical> { |
| 213 | let mut offset = Point::from((0., 0.)); | 224 | let mut offset = Point::from((0., 0.)); |
| 214 | 225 | ||
| 215 | - if let Some(move_) = &self.move_animation { | 226 | + if let Some(move_) = &self.move_x_animation { |
| 216 | - offset += move_.from.to_f64().upscale(move_.anim.value()); | 227 | + offset.x += f64::from(move_.from) * move_.anim.value(); |
| 228 | + } | ||
| 229 | + if let Some(move_) = &self.move_y_animation { | ||
| 230 | + offset.y += f64::from(move_.from) * move_.anim.value(); | ||
| 217 | } | 231 | } |
| 218 | 232 | ||
| 219 | offset.to_i32_round() | 233 | offset.to_i32_round() |
| @@ -237,23 +251,43 @@ impl<W: LayoutElement> Tile<W> { | |||
| 237 | } | 251 | } |
| 238 | 252 | ||
| 239 | pub fn animate_move_from(&mut self, from: Point<i32, Logical>) { | 253 | pub fn animate_move_from(&mut self, from: Point<i32, Logical>) { |
| 240 | - self.animate_move_from_with_config(from, self.options.animations.window_movement.0); | 254 | + self.animate_move_x_from(from.x); |
| 255 | + self.animate_move_y_from(from.y); | ||
| 256 | + } | ||
| 257 | + | ||
| 258 | + pub fn animate_move_x_from(&mut self, from: i32) { | ||
| 259 | + self.animate_move_x_from_with_config(from, self.options.animations.window_movement.0); | ||
| 260 | + } | ||
| 261 | + | ||
| 262 | + pub fn animate_move_x_from_with_config(&mut self, from: i32, config: niri_config::Animation) { | ||
| 263 | + let current_offset = self.render_offset().x; | ||
| 264 | + | ||
| 265 | + // Preserve the previous config if ongoing. | ||
| 266 | + let anim = self.move_x_animation.take().map(|move_| move_.anim); | ||
| 267 | + let anim = anim | ||
| 268 | + .map(|anim| anim.restarted(1., 0., 0.)) | ||
| 269 | + .unwrap_or_else(|| Animation::new(1., 0., 0., config)); | ||
| 270 | + | ||
| 271 | + self.move_x_animation = Some(MoveAnimation { | ||
| 272 | + anim, | ||
| 273 | + from: from + current_offset, | ||
| 274 | + }); | ||
| 275 | + } | ||
| 276 | + | ||
| 277 | + pub fn animate_move_y_from(&mut self, from: i32) { | ||
| 278 | + self.animate_move_y_from_with_config(from, self.options.animations.window_movement.0); | ||
| 241 | } | 279 | } |
| 242 | 280 | ||
| 243 | - pub fn animate_move_from_with_config( | 281 | + pub fn animate_move_y_from_with_config(&mut self, from: i32, config: niri_config::Animation) { |
| 244 | - &mut self, | 282 | + let current_offset = self.render_offset().y; |
| 245 | - from: Point<i32, Logical>, | ||
| 246 | - config: niri_config::Animation, | ||
| 247 | - ) { | ||
| 248 | - let current_offset = self.render_offset(); | ||
| 249 | 283 | ||
| 250 | // Preserve the previous config if ongoing. | 284 | // Preserve the previous config if ongoing. |
| 251 | - let anim = self.move_animation.take().map(|move_| move_.anim); | 285 | + let anim = self.move_y_animation.take().map(|move_| move_.anim); |
| 252 | let anim = anim | 286 | let anim = anim |
| 253 | .map(|anim| anim.restarted(1., 0., 0.)) | 287 | .map(|anim| anim.restarted(1., 0., 0.)) |
| 254 | .unwrap_or_else(|| Animation::new(1., 0., 0., config)); | 288 | .unwrap_or_else(|| Animation::new(1., 0., 0., config)); |
| 255 | 289 | ||
| 256 | - self.move_animation = Some(MoveAnimation { | 290 | + self.move_y_animation = Some(MoveAnimation { |
| 257 | anim, | 291 | anim, |
| 258 | from: from + current_offset, | 292 | from: from + current_offset, |
| 259 | }); | 293 | }); |
src/layout/workspace.rsmodified+7 -7
| @@ -920,7 +920,7 @@ impl<W: LayoutElement> Workspace<W> { | |||
| 920 | // Animate movement of other tiles. | 920 | // Animate movement of other tiles. |
| 921 | let offset_y = column.tile_y(window_idx + 1) - column.tile_y(window_idx); | 921 | let offset_y = column.tile_y(window_idx + 1) - column.tile_y(window_idx); |
| 922 | for tile in &mut column.tiles[window_idx + 1..] { | 922 | for tile in &mut column.tiles[window_idx + 1..] { |
| 923 | - tile.animate_move_from(Point::from((0, offset_y))); | 923 | + tile.animate_move_y_from(offset_y); |
| 924 | } | 924 | } |
| 925 | 925 | ||
| 926 | let tile = column.tiles.remove(window_idx); | 926 | let tile = column.tiles.remove(window_idx); |
| @@ -2323,8 +2323,8 @@ impl<W: LayoutElement> Column<W> { | |||
| 2323 | // Move windows below in tandem with resizing. | 2323 | // Move windows below in tandem with resizing. |
| 2324 | if tile.resize_animation().is_some() && offset != 0 { | 2324 | if tile.resize_animation().is_some() && offset != 0 { |
| 2325 | for tile in &mut self.tiles[tile_idx + 1..] { | 2325 | for tile in &mut self.tiles[tile_idx + 1..] { |
| 2326 | - tile.animate_move_from_with_config( | 2326 | + tile.animate_move_y_from_with_config( |
| 2327 | - Point::from((0, offset)), | 2327 | + offset, |
| 2328 | self.options.animations.window_resize.0, | 2328 | self.options.animations.window_resize.0, |
| 2329 | ); | 2329 | ); |
| 2330 | } | 2330 | } |
| @@ -2525,8 +2525,8 @@ impl<W: LayoutElement> Column<W> { | |||
| 2525 | 2525 | ||
| 2526 | // Animate the movement. | 2526 | // Animate the movement. |
| 2527 | let new_active_y = self.tile_y(new_idx); | 2527 | let new_active_y = self.tile_y(new_idx); |
| 2528 | - self.tiles[new_idx].animate_move_from(Point::from((0, active_y - new_active_y))); | 2528 | + self.tiles[new_idx].animate_move_y_from(active_y - new_active_y); |
| 2529 | - self.tiles[new_idx + 1].animate_move_from(Point::from((0, active_y - next_y))); | 2529 | + self.tiles[new_idx + 1].animate_move_y_from(active_y - next_y); |
| 2530 | } | 2530 | } |
| 2531 | 2531 | ||
| 2532 | fn move_down(&mut self) { | 2532 | fn move_down(&mut self) { |
| @@ -2546,8 +2546,8 @@ impl<W: LayoutElement> Column<W> { | |||
| 2546 | 2546 | ||
| 2547 | // Animate the movement. | 2547 | // Animate the movement. |
| 2548 | let new_active_y = self.tile_y(new_idx); | 2548 | let new_active_y = self.tile_y(new_idx); |
| 2549 | - self.tiles[new_idx].animate_move_from(Point::from((0, active_y - new_active_y))); | 2549 | + self.tiles[new_idx].animate_move_y_from(active_y - new_active_y); |
| 2550 | - self.tiles[new_idx - 1].animate_move_from(Point::from((0, next_y - active_y))); | 2550 | + self.tiles[new_idx - 1].animate_move_y_from(next_y - active_y); |
| 2551 | } | 2551 | } |
| 2552 | 2552 | ||
| 2553 | #[cfg(test)] | 2553 | #[cfg(test)] |