diff options
| author | Ivan Molodetskikh <yalterz@gmail.com> | 2024-04-16 08:55:56 +0400 |
|---|---|---|
| committer | Ivan Molodetskikh <yalterz@gmail.com> | 2024-04-16 08:59:15 +0400 |
| commit | ff42f9b9d325e5e3a77318177b769a82a66c637b (patch) | |
| tree | c63c167740cec0a473f386a0603d3b91c0e186eb /src | |
| parent | c163e581672cd16829dce54a0793d5f09be9cc59 (diff) | |
| download | niri-ff42f9b9d325e5e3a77318177b769a82a66c637b.tar.gz niri-ff42f9b9d325e5e3a77318177b769a82a66c637b.tar.bz2 niri-ff42f9b9d325e5e3a77318177b769a82a66c637b.zip | |
Start move animations from add/remove window/column
Diffstat (limited to 'src')
| -rw-r--r-- | src/layout/mod.rs | 28 | ||||
| -rw-r--r-- | src/layout/workspace.rs | 118 |
2 files changed, 82 insertions, 64 deletions
diff --git a/src/layout/mod.rs b/src/layout/mod.rs index b9c0172a..d54867ac 100644 --- a/src/layout/mod.rs +++ b/src/layout/mod.rs @@ -1715,22 +1715,10 @@ impl<W: LayoutElement> Layout<W> { MonitorSet::Normal { monitors, .. } => { for mon in monitors { for ws in &mut mon.workspaces { - for (col_idx, col) in ws.columns.iter_mut().enumerate() { + for col in &mut ws.columns { for tile in &mut col.tiles { if tile.window().id() == window { tile.start_open_animation(); - - let offset = ws.column_x(col_idx + 1) - ws.column_x(col_idx); - if ws.active_column_idx <= col_idx { - for col in &mut ws.columns[col_idx + 1..] { - col.animate_move_from(-offset); - } - } else { - for col in &mut ws.columns[..col_idx] { - col.animate_move_from(offset); - } - } - return; } } @@ -1740,22 +1728,10 @@ impl<W: LayoutElement> Layout<W> { } MonitorSet::NoOutputs { workspaces, .. } => { for ws in workspaces { - for (col_idx, col) in ws.columns.iter_mut().enumerate() { + for col in &mut ws.columns { for tile in &mut col.tiles { if tile.window().id() == window { tile.start_open_animation(); - - let offset = ws.column_x(col_idx + 1) - ws.column_x(col_idx); - if ws.active_column_idx <= col_idx { - for col in &mut ws.columns[col_idx + 1..] { - col.animate_move_from(-offset); - } - } else { - for col in &mut ws.columns[..col_idx] { - col.animate_move_from(offset); - } - } - return; } } diff --git a/src/layout/workspace.rs b/src/layout/workspace.rs index c659e2df..6c51ffb5 100644 --- a/src/layout/workspace.rs +++ b/src/layout/workspace.rs @@ -694,6 +694,18 @@ impl<W: LayoutElement> Workspace<W> { self.activate_column(col_idx); self.activate_prev_column_on_removal = prev_offset; } + + // Animate movement of other columns. + let offset = self.column_x(col_idx + 1) - self.column_x(col_idx); + if self.active_column_idx <= col_idx { + for col in &mut self.columns[col_idx + 1..] { + col.animate_move_from(-offset); + } + } else { + for col in &mut self.columns[..col_idx] { + col.animate_move_from(offset); + } + } } pub fn add_window( @@ -746,6 +758,18 @@ impl<W: LayoutElement> Workspace<W> { } else if idx <= self.active_column_idx { self.active_column_idx += 1; } + + // Animate movement of other columns. + let offset = self.column_x(idx + 1) - self.column_x(idx); + if self.active_column_idx <= idx { + for col in &mut self.columns[idx + 1..] { + col.animate_move_from(-offset); + } + } else { + for col in &mut self.columns[..idx] { + col.animate_move_from(offset); + } + } } pub fn add_column(&mut self, mut column: Column<W>, activate: bool) { @@ -785,10 +809,35 @@ impl<W: LayoutElement> Workspace<W> { self.activate_column(idx); self.activate_prev_column_on_removal = prev_offset; } + + // Animate movement of other columns. + let offset = self.column_x(idx + 1) - self.column_x(idx); + if self.active_column_idx <= idx { + for col in &mut self.columns[idx + 1..] { + col.animate_move_from(-offset); + } + } else { + for col in &mut self.columns[..idx] { + col.animate_move_from(offset); + } + } } pub fn remove_window_by_idx(&mut self, column_idx: usize, window_idx: usize) -> W { + let offset = self.column_x(column_idx + 1) - self.column_x(column_idx); + let column = &mut self.columns[column_idx]; + + // Animate movement of other tiles. + let offset_y = column.tile_y(window_idx + 1) - column.tile_y(window_idx); + for tile in &mut column.tiles[window_idx + 1..] { + tile.animate_move_from_with_config( + Point::from((0, offset_y)), + self.options.animations.window_resize, + niri_config::Animation::default_window_resize(), + ); + } + let window = column.tiles.remove(window_idx).into_window(); column.heights.remove(window_idx); @@ -807,6 +856,17 @@ impl<W: LayoutElement> Workspace<W> { self.view_offset_before_fullscreen = None; } + // Animate movement of the other columns. + if self.active_column_idx <= column_idx { + for col in &mut self.columns[column_idx + 1..] { + col.animate_move_from(offset); + } + } else { + for col in &mut self.columns[..column_idx] { + col.animate_move_from(-offset); + } + } + self.columns.remove(column_idx); if self.columns.is_empty() { return window; @@ -846,6 +906,18 @@ impl<W: LayoutElement> Workspace<W> { } pub fn remove_column_by_idx(&mut self, column_idx: usize) -> Column<W> { + // Animate movement of the other columns. + let offset = self.column_x(column_idx + 1) - self.column_x(column_idx); + if self.active_column_idx <= column_idx { + for col in &mut self.columns[column_idx + 1..] { + col.animate_move_from(offset); + } + } else { + for col in &mut self.columns[..column_idx] { + col.animate_move_from(-offset); + } + } + let column = self.columns.remove(column_idx); if let Some(output) = &self.output { @@ -1022,22 +1094,15 @@ impl<W: LayoutElement> Workspace<W> { return; }; - let (col_idx, tile_idx) = self + let col_idx = self .columns .iter() - .enumerate() - .find_map(|(col_idx, col)| { - col.tiles - .iter() - .position(|tile| tile.window().id() == window) - .map(|tile_idx| (col_idx, tile_idx)) - }) + .position(|col| col.contains(window)) .unwrap(); let col = &self.columns[col_idx]; let removing_last = col.tiles.len() == 1; let offset = self.column_x(col_idx + 1) - self.column_x(col_idx); - let offset_y = col.tile_y(tile_idx + 1) - col.tile_y(tile_idx); let mut center = Point::from((0, 0)); center.x += tile.tile_size().w / 2; @@ -1085,29 +1150,6 @@ impl<W: LayoutElement> Workspace<W> { warn!("error creating a closing window animation: {err:?}"); } } - - // Also move the other columns. - if removing_last { - if self.active_column_idx <= col_idx { - for col in &mut self.columns[col_idx + 1..] { - col.animate_move_from(offset); - } - } else { - for col in &mut self.columns[..col_idx] { - col.animate_move_from(-offset); - } - } - } - - // Also move other windows in a column. - let col = &mut self.columns[col_idx]; - for tile in &mut col.tiles[tile_idx + 1..] { - tile.animate_move_from_with_config( - Point::from((0, offset_y)), - self.options.animations.window_resize, - niri_config::Animation::default_window_resize(), - ); - } } pub fn prepare_for_resize_animation(&mut self, window: &W::Id) { @@ -1283,7 +1325,7 @@ impl<W: LayoutElement> Workspace<W> { self.enter_output_for_window(&window); let target_column = &mut self.columns[target_column_idx]; - target_column.add_window(window); + target_column.add_window(window, true); target_column.focus_last(); self.activate_column(target_column_idx); } else { @@ -1316,7 +1358,7 @@ impl<W: LayoutElement> Workspace<W> { self.enter_output_for_window(&window); let target_column = &mut self.columns[target_column_idx]; - target_column.add_window(window); + target_column.add_window(window, true); target_column.focus_last(); self.activate_column(target_column_idx); } else { @@ -1346,7 +1388,7 @@ impl<W: LayoutElement> Workspace<W> { let target_column = &mut self.columns[self.active_column_idx]; let was_fullscreen = target_column.tiles[target_column.active_tile_idx].is_fullscreen(); - target_column.add_window(window); + target_column.add_window(window, true); if !was_fullscreen { self.view_offset_before_fullscreen = None; @@ -1917,7 +1959,7 @@ impl<W: LayoutElement> Column<W> { let is_pending_fullscreen = window.is_pending_fullscreen(); - rv.add_window(window); + rv.add_window(window, false); if is_pending_fullscreen { rv.set_fullscreen(true); @@ -2049,12 +2091,12 @@ impl<W: LayoutElement> Column<W> { self.active_tile_idx = idx; } - fn add_window(&mut self, window: W) { + fn add_window(&mut self, window: W, animate: bool) { let tile = Tile::new(window, self.options.clone()); self.is_fullscreen = false; self.tiles.push(tile); self.heights.push(WindowHeight::Auto); - self.update_tile_sizes(false); + self.update_tile_sizes(animate); } fn update_window(&mut self, window: &W::Id) { |
