Implement vertical window move animations
Browse files at this commit69f723d68aa28698488618e00688ef3a84e40819Parent: 568fbe22 changed files +34 -2
- src/layout/tile.rs +8 -0
- src/layout/workspace.rs +26 -2
src/layout/tile.rsmodified+8 -0
| @@ -243,6 +243,14 @@ impl<W: LayoutElement> Tile<W> { | |||
| 243 | self.resize_animation.as_ref().map(|resize| &resize.anim) | 243 | self.resize_animation.as_ref().map(|resize| &resize.anim) |
| 244 | } | 244 | } |
| 245 | 245 | ||
| 246 | + pub fn animate_move_from(&mut self, from: Point<i32, Logical>) { | ||
| 247 | + self.animate_move_from_with_config( | ||
| 248 | + from, | ||
| 249 | + self.options.animations.window_movement, | ||
| 250 | + niri_config::Animation::default_window_movement(), | ||
| 251 | + ); | ||
| 252 | + } | ||
| 253 | + | ||
| 246 | pub fn animate_move_from_with_config( | 254 | pub fn animate_move_from_with_config( |
| 247 | &mut self, | 255 | &mut self, |
| 248 | from: Point<i32, Logical>, | 256 | from: Point<i32, Logical>, |
src/layout/workspace.rsmodified+26 -2
| @@ -2250,9 +2250,19 @@ impl<W: LayoutElement> Column<W> { | |||
| 2250 | return; | 2250 | return; |
| 2251 | } | 2251 | } |
| 2252 | 2252 | ||
| 2253 | + let mut ys = self.tile_ys().skip(self.active_tile_idx); | ||
| 2254 | + let active_y = ys.next().unwrap(); | ||
| 2255 | + let next_y = ys.next().unwrap(); | ||
| 2256 | + drop(ys); | ||
| 2257 | + | ||
| 2253 | self.tiles.swap(self.active_tile_idx, new_idx); | 2258 | self.tiles.swap(self.active_tile_idx, new_idx); |
| 2254 | self.heights.swap(self.active_tile_idx, new_idx); | 2259 | self.heights.swap(self.active_tile_idx, new_idx); |
| 2255 | self.active_tile_idx = new_idx; | 2260 | self.active_tile_idx = new_idx; |
| 2261 | + | ||
| 2262 | + // Animate the movement. | ||
| 2263 | + let new_active_y = self.tile_y(new_idx); | ||
| 2264 | + self.tiles[new_idx].animate_move_from(Point::from((0, active_y - new_active_y))); | ||
| 2265 | + self.tiles[new_idx + 1].animate_move_from(Point::from((0, active_y - next_y))); | ||
| 2256 | } | 2266 | } |
| 2257 | 2267 | ||
| 2258 | fn move_down(&mut self) { | 2268 | fn move_down(&mut self) { |
| @@ -2261,9 +2271,19 @@ impl<W: LayoutElement> Column<W> { | |||
| 2261 | return; | 2271 | return; |
| 2262 | } | 2272 | } |
| 2263 | 2273 | ||
| 2274 | + let mut ys = self.tile_ys().skip(self.active_tile_idx); | ||
| 2275 | + let active_y = ys.next().unwrap(); | ||
| 2276 | + let next_y = ys.next().unwrap(); | ||
| 2277 | + drop(ys); | ||
| 2278 | + | ||
| 2264 | self.tiles.swap(self.active_tile_idx, new_idx); | 2279 | self.tiles.swap(self.active_tile_idx, new_idx); |
| 2265 | self.heights.swap(self.active_tile_idx, new_idx); | 2280 | self.heights.swap(self.active_tile_idx, new_idx); |
| 2266 | self.active_tile_idx = new_idx; | 2281 | self.active_tile_idx = new_idx; |
| 2282 | + | ||
| 2283 | + // Animate the movement. | ||
| 2284 | + let new_active_y = self.tile_y(new_idx); | ||
| 2285 | + self.tiles[new_idx].animate_move_from(Point::from((0, active_y - new_active_y))); | ||
| 2286 | + self.tiles[new_idx - 1].animate_move_from(Point::from((0, next_y - active_y))); | ||
| 2267 | } | 2287 | } |
| 2268 | 2288 | ||
| 2269 | #[cfg(test)] | 2289 | #[cfg(test)] |
| @@ -2431,9 +2451,13 @@ impl<W: LayoutElement> Column<W> { | |||
| 2431 | y = self.working_area.loc.y + self.options.gaps; | 2451 | y = self.working_area.loc.y + self.options.gaps; |
| 2432 | } | 2452 | } |
| 2433 | 2453 | ||
| 2434 | - self.tiles.iter().map(move |tile| { | 2454 | + let heights = self.tiles.iter().map(|tile| tile.tile_size().h); |
| 2455 | + | ||
| 2456 | + // Chain an arbitrary height to be able to get the Y that the next tile past the end would | ||
| 2457 | + // have. | ||
| 2458 | + heights.chain(iter::once(0)).map(move |h| { | ||
| 2435 | let pos = y; | 2459 | let pos = y; |
| 2436 | - y += tile.tile_size().h + self.options.gaps; | 2460 | + y += h + self.options.gaps; |
| 2437 | pos | 2461 | pos |
| 2438 | }) | 2462 | }) |
| 2439 | } | 2463 | } |