From 1944fd67c462d3e926f74b0e6e7a240a830c345e Mon Sep 17 00:00:00 2001 From: LGUG2Z Date: Sat, 31 Oct 2026 19:39:25 -0700 Subject: [PATCH] refactor(windows): promote-focus on a custom layout is a hook of WorkspacePlatform The Windows promote_focus_to_front focused the first column of a custom layout that has no primary column (first_container_idx(primary_idx().unwrap_or(0))) where the shared primary_container_idx fails for it; this was one of the Layout::Custom differences of core-model.md section 18. WorkspacePlatform gets promote_focus_container_idx(layout) -> usize, defaulting to primary_container_idx(layout).unwrap_or(0), so a shared promote_focus_to_front can call it on every platform; the Windows platform overrides it with the exact expression it had (default layouts 0, custom layouts the first container of the primary column, else of column 0). window_manager.rs calls the hook. A core test pins the default for the default layouts. Not a behaviour change on Windows (the same expression, moved). KDE and macOS see a new defaulted trait method only. Verified: tools/fast-check native (core tests), bare Windows clippy -D warnings, KDE check + lib tests, macOS fake-CC type-check PASS; e2e: commands (promote-focus), layouts (custom layout). --- crates/komorebi-core/src/workspace.rs | 16 ++++++++++++++++ komorebi/src/window_manager.rs | 7 +++---- komorebi/src/workspace.rs | 10 ++++++++++ 3 files changed, 29 insertions(+), 4 deletions(-) diff --git a/crates/komorebi-core/src/workspace.rs b/crates/komorebi-core/src/workspace.rs index 9462957d..bc46e047 100644 --- a/crates/komorebi-core/src/workspace.rs +++ b/crates/komorebi-core/src/workspace.rs @@ -164,6 +164,14 @@ pub trait WorkspacePlatform: Sized + Clone + std::fmt::Debug + PartialEq + 'stat Ok(0) } + /// The index of the container that `promote-focus` focuses: the primary position of the layout, + /// and the first container when the layout has none (a custom layout without a primary + /// column). Where [`WorkspacePlatform::primary_container_idx`] fails, the default falls back + /// to 0. + fn promote_focus_container_idx(layout: &Layout) -> usize { + Self::primary_container_idx(layout).unwrap_or(0) + } + /// Gives the maximized window back to the layout, for the platforms where that is something /// to tell the window (KDE asks the compositor; on Windows there is nothing to do). fn unmaximize_window(_window: &Self::Window) -> eyre::Result<()> { @@ -2190,4 +2198,12 @@ mod tests { assert!(workspace.tile); assert_eq!(workspace.layout, Layout::Default(DefaultLayout::BSP)); } + + #[test] + fn promote_focus_falls_back_to_the_primary_position_and_then_to_zero() { + assert_eq!( + Plat::promote_focus_container_idx(&Layout::Default(DefaultLayout::BSP)), + 0 + ); + } } diff --git a/komorebi/src/window_manager.rs b/komorebi/src/window_manager.rs index e3d66a57..9551ce3a 100644 --- a/komorebi/src/window_manager.rs +++ b/komorebi/src/window_manager.rs @@ -48,8 +48,10 @@ use crate::core::WindowContainerBehaviour; use crate::core::WindowManagementBehaviour; use crate::core::config_generation::MatchingRule; use crate::windows_backend::backend; +use crate::workspace::WindowsPlatform; use komorebi_backend::WindowId; use komorebi_core::ContainerWindow; +use komorebi_core::WorkspacePlatform; use crate::CrossBoundaryBehaviour; use crate::DATA_DIR; @@ -3048,10 +3050,7 @@ impl WindowManager { tracing::info!("promoting focus"); - let target_idx = match &workspace.layout { - Layout::Default(_) => 0, - Layout::Custom(custom) => custom.first_container_idx(custom.primary_idx().unwrap_or(0)), - }; + let target_idx = WindowsPlatform::promote_focus_container_idx(&workspace.layout); workspace.focus_container(target_idx); self.update_focused_workspace(self.mouse_follows_focus, true) diff --git a/komorebi/src/workspace.rs b/komorebi/src/workspace.rs index 6189503c..667dc9e2 100644 --- a/komorebi/src/workspace.rs +++ b/komorebi/src/workspace.rs @@ -86,6 +86,16 @@ impl komorebi_core::WorkspacePlatform for WindowsPlatform { }) } + /// `promote-focus` on a custom layout without a primary column focuses its first column rather + /// than failing, which is what the Windows daemon always did; the other layouts have the + /// primary position first. + fn promote_focus_container_idx(layout: &Layout) -> usize { + match layout { + Layout::Default(_) => 0, + Layout::Custom(custom) => custom.first_container_idx(custom.primary_idx().unwrap_or(0)), + } + } + fn begin_update(_workspace: &mut Workspace) -> eyre::Result { if !INITIAL_CONFIGURATION_LOADED.load(Ordering::SeqCst) { return Ok(komorebi_core::Flow::Skip);