From 97c96a13829ec74c83e976c2ea34e7cc717b02ec Mon Sep 17 00:00:00 2001 From: Ivan Molodetskikh Date: Sun, 9 Aug 2026 15:58:55 +0300 Subject: [PATCH] layout: Match view animation when moving between workspaces Quite ugly having to pass the anim config everywhere... --- src/layout/mod.rs | 7 +++++- src/layout/monitor.rs | 51 ++++++++++++++++++++++++++++------------- src/layout/scrolling.rs | 7 +++--- src/layout/workspace.rs | 27 ++++++++++++++++------ 4 files changed, 65 insertions(+), 27 deletions(-) diff --git a/src/layout/mod.rs b/src/layout/mod.rs index 6e203998..5fa5f87d 100644 --- a/src/layout/mod.rs +++ b/src/layout/mod.rs @@ -932,7 +932,7 @@ impl Layout { panic!() }; - monitors[monitor_idx].add_column(workspace_idx, column, activate); + monitors[monitor_idx].add_column(workspace_idx, column, activate, None); if activate { *active_monitor_idx = monitor_idx; @@ -1110,6 +1110,7 @@ impl Layout { scrolling_width, is_full_width, is_floating, + None, ); // Set the default height for scrolling windows. @@ -3381,6 +3382,7 @@ impl Layout { removed.width, removed.is_full_width, removed.is_floating, + None, ); if activate.map_smart(|| false) { *active_monitor_idx = new_idx; @@ -4252,6 +4254,7 @@ impl Layout { move_.width, move_.is_full_width, false, + None, ); } InsertPosition::InColumn(column_idx, tile_idx) => { @@ -4306,6 +4309,7 @@ impl Layout { move_.width, move_.is_full_width, true, + None, ); } } @@ -4347,6 +4351,7 @@ impl Layout { move_.width, move_.is_full_width, move_.is_floating, + None, ); } } diff --git a/src/layout/monitor.rs b/src/layout/monitor.rs index de21dc7a..f119e619 100644 --- a/src/layout/monitor.rs +++ b/src/layout/monitor.rs @@ -540,13 +540,20 @@ impl Monitor { width, is_full_width, is_floating, + None, ); } - pub fn add_column(&mut self, mut workspace_idx: usize, column: Column, activate: bool) { + pub fn add_column( + &mut self, + mut workspace_idx: usize, + column: Column, + activate: bool, + anim: Option, + ) { let workspace = &mut self.workspaces[workspace_idx]; - workspace.add_column(column, activate); + workspace.add_column(column, activate, anim); // After adding a new window, workspace becomes this output's own. if workspace.name().is_none() { @@ -577,12 +584,21 @@ impl Monitor { width: ColumnWidth, is_full_width: bool, is_floating: bool, + anim: Option, ) { let (mut workspace_idx, target) = self.resolve_add_window_target(target); let workspace = &mut self.workspaces[workspace_idx]; - workspace.add_tile(tile, target, activate, width, is_full_width, is_floating); + workspace.add_tile( + tile, + target, + activate, + width, + is_full_width, + is_floating, + anim, + ); // After adding a new window, workspace becomes this output's own. if workspace.name().is_none() { @@ -842,6 +858,13 @@ impl Monitor { let transaction = Transaction::new(); let removed = workspace.remove_tile(&window, transaction); + // If the view is following the tile, match the animation. + let config = if activate { + self.options.animations.workspace_switch.0 + } else { + self.options.animations.window_movement.0 + }; + self.add_tile( removed.tile, MonitorAddWindowTarget::Workspace { @@ -857,6 +880,7 @@ impl Monitor { removed.width, removed.is_full_width, removed.is_floating, + Some(config), ); if self.workspace_switch.is_none() { @@ -879,12 +903,6 @@ impl Monitor { .tiles_with_render_positions_mut(false) .find(|(tile, _)| tile.window().id() == &window) .unwrap(); - // If the view is following the tile, match the animation. - let config = if activate { - self.options.animations.workspace_switch.0 - } else { - self.options.animations.window_movement.0 - }; tile.animate_move_from_with_config(old_render_pos - new_render_pos, config); tile.set_anim_y_between_workspaces(); } @@ -933,8 +951,15 @@ impl Monitor { old_render_pos.y += self.workspace_size_with_gap(1.).h * (source_workspace_idx as f64 - new_idx as f64); + // If the view is following the column, match the animation. + let config = if activate { + self.options.animations.workspace_switch.0 + } else { + self.options.animations.window_movement.0 + }; + let new_id = self.workspaces[new_idx].id(); - self.add_column(new_idx, column, activate); + self.add_column(new_idx, column, activate, Some(config)); let new_idx = self.idx_of_ws(new_id).unwrap(); let (column, new_render_pos) = self.workspaces[new_idx] @@ -942,12 +967,6 @@ impl Monitor { .columns_with_render_positions_mut() .find(|(col, _pos)| col.id() == id) .unwrap(); - // If the view is following the tile, match the animation. - let config = if activate { - self.options.animations.workspace_switch.0 - } else { - self.options.animations.window_movement.0 - }; column.animate_move_from_with_config(old_render_pos - new_render_pos, config); column.set_anim_y_between_workspaces(); } diff --git a/src/layout/scrolling.rs b/src/layout/scrolling.rs index 84b8749a..c7d94c54 100644 --- a/src/layout/scrolling.rs +++ b/src/layout/scrolling.rs @@ -907,7 +907,7 @@ impl ScrollingSpace { activate: bool, width: ColumnWidth, is_full_width: bool, - anim_config: Option, + anim: Option, ) { let column = Column::new_with_tile( tile, @@ -919,7 +919,7 @@ impl ScrollingSpace { is_full_width, ); - self.add_column(col_idx, column, activate, anim_config); + self.add_column(col_idx, column, activate, anim); } pub fn add_tile_to_column( @@ -984,6 +984,7 @@ impl ScrollingSpace { activate: bool, width: ColumnWidth, is_full_width: bool, + anim: Option, ) { let right_of_idx = self .columns @@ -992,7 +993,7 @@ impl ScrollingSpace { .unwrap(); let col_idx = right_of_idx + 1; - self.add_tile(Some(col_idx), tile, activate, width, is_full_width, None); + self.add_tile(Some(col_idx), tile, activate, width, is_full_width, anim); } pub fn add_column( diff --git a/src/layout/workspace.rs b/src/layout/workspace.rs index af10629f..5e786ddf 100644 --- a/src/layout/workspace.rs +++ b/src/layout/workspace.rs @@ -604,6 +604,7 @@ impl Workspace { ) } + #[allow(clippy::too_many_arguments)] pub fn add_tile( &mut self, mut tile: Tile, @@ -612,6 +613,7 @@ impl Workspace { width: ColumnWidth, is_full_width: bool, is_floating: bool, + anim: Option, ) { self.enter_output_for_window(tile.window()); tile.restore_to_floating = is_floating; @@ -631,7 +633,7 @@ impl Workspace { } } else { self.scrolling - .add_tile(None, tile, activate, width, is_full_width, None); + .add_tile(None, tile, activate, width, is_full_width, anim); if activate { self.floating_is_active = FloatingActive::No; @@ -641,7 +643,7 @@ impl Workspace { WorkspaceAddWindowTarget::NewColumnAt(col_idx) => { let activate = activate.map_smart(|| false); self.scrolling - .add_tile(Some(col_idx), tile, activate, width, is_full_width, None); + .add_tile(Some(col_idx), tile, activate, width, is_full_width, anim); if activate { self.floating_is_active = FloatingActive::No; @@ -681,14 +683,20 @@ impl Workspace { } } else if floating_has_window { self.scrolling - .add_tile(None, tile, activate, width, is_full_width, None); + .add_tile(None, tile, activate, width, is_full_width, anim); if activate { self.floating_is_active = FloatingActive::No; } } else { - self.scrolling - .add_tile_right_of(next_to, tile, activate, width, is_full_width); + self.scrolling.add_tile_right_of( + next_to, + tile, + activate, + width, + is_full_width, + anim, + ); if activate { self.floating_is_active = FloatingActive::No; @@ -714,12 +722,17 @@ impl Workspace { } } - pub fn add_column(&mut self, column: Column, activate: bool) { + pub fn add_column( + &mut self, + column: Column, + activate: bool, + anim: Option, + ) { for (tile, _) in column.tiles() { self.enter_output_for_window(tile.window()); } - self.scrolling.add_column(None, column, activate, None); + self.scrolling.add_column(None, column, activate, anim); if activate { self.floating_is_active = FloatingActive::No;