diff options
| author | Ivan Molodetskikh <yalterz@gmail.com> | 2024-04-08 19:25:45 +0400 |
|---|---|---|
| committer | Ivan Molodetskikh <yalterz@gmail.com> | 2024-04-08 19:25:45 +0400 |
| commit | 4856522a7a96f29179b5e723537d797f779c148d (patch) | |
| tree | 892e10c3ce859d1aab5c67711b097f38a391fd7f | |
| parent | c1432bfa96e40c12f2d10174f8cd23ec9c2a68b0 (diff) | |
| download | niri-4856522a7a96f29179b5e723537d797f779c148d.tar.gz niri-4856522a7a96f29179b5e723537d797f779c148d.tar.bz2 niri-4856522a7a96f29179b5e723537d797f779c148d.zip | |
Implement window open shift in terms of window-movement
This removes the quite unobvious visual size, and fixes jerking when
opening multiple windows in quick succession.
| -rw-r--r-- | src/layout/mod.rs | 28 | ||||
| -rw-r--r-- | src/layout/tile.rs | 17 | ||||
| -rw-r--r-- | src/layout/workspace.rs | 26 | ||||
| -rw-r--r-- | wiki/Configuration:-Animations.md | 4 |
4 files changed, 34 insertions, 41 deletions
diff --git a/src/layout/mod.rs b/src/layout/mod.rs index 611f138f..9db7b140 100644 --- a/src/layout/mod.rs +++ b/src/layout/mod.rs @@ -1700,10 +1700,22 @@ impl<W: LayoutElement> Layout<W> { MonitorSet::Normal { monitors, .. } => { for mon in monitors { for ws in &mut mon.workspaces { - for col in &mut ws.columns { + for (col_idx, col) in ws.columns.iter_mut().enumerate() { 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; } } @@ -1713,10 +1725,22 @@ impl<W: LayoutElement> Layout<W> { } MonitorSet::NoOutputs { workspaces, .. } => { for ws in workspaces { - for col in &mut ws.columns { + for (col_idx, col) in ws.columns.iter_mut().enumerate() { 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/tile.rs b/src/layout/tile.rs index 3d2da48c..ed71d8a0 100644 --- a/src/layout/tile.rs +++ b/src/layout/tile.rs @@ -203,23 +203,6 @@ impl<W: LayoutElement> Tile<W> { self.window.size() } - /// Returns an animated size of the tile for rendering and input. - /// - /// During the window opening animation, windows to the right should gradually slide further to - /// the right. This is what this visual size is used for. Other things like window resizes or - /// transactions or new view position calculation always use the real size, instead of this - /// visual size. - pub fn visual_tile_size(&self) -> Size<i32, Logical> { - let size = self.tile_size(); - let v = self - .open_animation - .as_ref() - .map(|anim| anim.value()) - .unwrap_or(1.) - .max(0.); - Size::from(((f64::from(size.w) * v).round() as i32, size.h)) - } - pub fn buf_loc(&self) -> Point<i32, Logical> { let mut loc = Point::from((0, 0)); loc += self.window_loc(); diff --git a/src/layout/workspace.rs b/src/layout/workspace.rs index 40d55622..a8bc63f2 100644 --- a/src/layout/workspace.rs +++ b/src/layout/workspace.rs @@ -605,7 +605,7 @@ impl<W: LayoutElement> Workspace<W> { } /// Computes the X position of the windows in the given column, in logical coordinates. - fn column_x(&self, column_idx: usize) -> i32 { + pub fn column_x(&self, column_idx: usize) -> i32 { let mut x = 0; for column in self.columns.iter().take(column_idx) { @@ -615,16 +615,6 @@ impl<W: LayoutElement> Workspace<W> { x } - fn visual_column_x(&self, column_idx: usize) -> i32 { - let mut x = 0; - - for column in self.columns.iter().take(column_idx) { - x += column.visual_width() + self.options.gaps; - } - - x - } - pub fn add_window_at( &mut self, col_idx: usize, @@ -1164,13 +1154,13 @@ impl<W: LayoutElement> Workspace<W> { } fn tiles_in_render_order(&self) -> impl Iterator<Item = (&'_ Tile<W>, Point<i32, Logical>)> { - let view_pos = self.visual_column_x(self.active_column_idx) + self.view_offset; + let view_pos = self.view_pos(); // Start with the active window since it's drawn on top. let col = &self.columns[self.active_column_idx]; let tile = &col.tiles[col.active_tile_idx]; let tile_pos = Point::from(( - self.visual_column_x(self.active_column_idx) - view_pos, + self.column_x(self.active_column_idx) - view_pos, col.tile_y(col.active_tile_idx), )) + col.render_offset(); let first = iter::once((tile, tile_pos)); @@ -1183,7 +1173,7 @@ impl<W: LayoutElement> Workspace<W> { // Keep track of column X position. .map(move |(col_idx, col)| { let rv = (col_idx, col, x); - x += col.visual_width() + self.options.gaps; + x += col.width() + self.options.gaps; rv }) .flat_map(move |(col_idx, col, x)| { @@ -1935,14 +1925,6 @@ impl<W: LayoutElement> Column<W> { .unwrap() } - fn visual_width(&self) -> i32 { - self.tiles - .iter() - .map(|tile| tile.visual_tile_size().w) - .max() - .unwrap() - } - fn focus_up(&mut self) { self.active_tile_idx = self.active_tile_idx.saturating_sub(1); } diff --git a/wiki/Configuration:-Animations.md b/wiki/Configuration:-Animations.md index e74af219..12ba3b7f 100644 --- a/wiki/Configuration:-Animations.md +++ b/wiki/Configuration:-Animations.md @@ -137,11 +137,15 @@ animations { #### `window-movement` +<sup>Since: 0.1.5</sup> + Window movement animations, currently cover only horizontal column movement. This animation runs on actions like `move-column-left` and `move-column-right` to move the windows themselves. It can sometimes run together with the `horizontal-view-movement` animation, if the camera also moves. +Since 0.1.5, this is also the animation that moves windows out of the way upon window opening. + ``` animations { window-movement { |
