diff --git a/komorebi/src/window_manager.rs b/komorebi/src/window_manager.rs index ea3c884d..074bca64 100644 --- a/komorebi/src/window_manager.rs +++ b/komorebi/src/window_manager.rs @@ -2681,12 +2681,16 @@ impl WindowManager { anyhow!("this is not a valid direction from the current position") })?; + let mut changed_focus = false; + let adjusted_new_index = if new_idx > current_container_idx && !matches!( workspace.layout(), Layout::Default(DefaultLayout::Grid) | Layout::Default(DefaultLayout::UltrawideVerticalStack) ) { + workspace.focus_container(new_idx); + changed_focus = true; new_idx.saturating_sub(1) } else { new_idx @@ -2703,12 +2707,22 @@ impl WindowManager { if let Some(current) = workspace.focused_container() { if current.windows().len() > 1 && !target_container_is_stack { workspace.focus_container(adjusted_new_index); + changed_focus = true; workspace.move_window_to_container(current_container_idx)?; } else { workspace.move_window_to_container(adjusted_new_index)?; } } + if changed_focus { + if let Some(container) = workspace.focused_container_mut() { + container.load_focused_window(); + if let Some(window) = container.focused_window() { + window.focus(self.mouse_follows_focus)?; + } + } + } + self.update_focused_workspace(self.mouse_follows_focus, false)?; }