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).
This commit is contained in:
LGUG2Z committed 2026-11-05 15:03:26 -08:00
1 parent 96332b2578
commit 1944fd67c4
3 files changed
+29 -4

No files matched your search

+16
View File
@@ -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
);
}
}
+3 -4
View File
@@ -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)
+10
View File
@@ -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<komorebi_core::Flow> {
if !INITIAL_CONFIGURATION_LOADED.load(Ordering::SeqCst) {
return Ok(komorebi_core::Flow::Skip);