From 2eea8b79a48b9c8fa3060e52dd6c493600e3b63a Mon Sep 17 00:00:00 2001 From: LGUG2Z Date: Wed, 29 Oct 2025 17:22:29 -0700 Subject: [PATCH] feat(wm): improve scrolling layout window hiding This commit makes a small improvement to the Scrolling layout by hiding windows to which layouts which are not contained within the horizontal bounds of the work area would otherwise be applied. This should also allow this layout to now be useable on configurations using multiple monitors. --- komorebi/src/core/rect.rs | 6 ++++++ komorebi/src/static_config.rs | 11 ----------- komorebi/src/window_manager.rs | 8 -------- komorebi/src/workspace.rs | 12 ++++++++++-- 4 files changed, 16 insertions(+), 21 deletions(-) diff --git a/komorebi/src/core/rect.rs b/komorebi/src/core/rect.rs index 67cc33ec..c16d3371 100644 --- a/komorebi/src/core/rect.rs +++ b/komorebi/src/core/rect.rs @@ -69,6 +69,12 @@ impl Rect { CoreGraphicsApi::contains_rect(other.into(), self.into()) } + pub fn contains_within_horizontal_bounds(&self, other: &Rect) -> bool { + let within_left_bound = other.left >= self.left; + let within_right_bound = other.left < self.left + self.right; + within_left_bound && within_right_bound + } + /// Decrease the size of self by the padding amount. pub fn add_padding(&mut self, padding: T) where diff --git a/komorebi/src/static_config.rs b/komorebi/src/static_config.rs index b2a51846..4a960b33 100644 --- a/komorebi/src/static_config.rs +++ b/komorebi/src/static_config.rs @@ -1212,8 +1212,6 @@ impl StaticConfig { workspace_matching_rules.clear(); drop(workspace_matching_rules); - let monitor_count = wm.monitors().len(); - let offset = wm.work_area_offset; for (i, monitor) in wm.monitors_mut().iter_mut().enumerate() { let preferred_config_idx = { @@ -1268,15 +1266,6 @@ impl StaticConfig { monitor.update_workspaces_globals(offset); for (j, ws) in monitor.workspaces_mut().iter_mut().enumerate() { if let Some(workspace_config) = monitor_config.workspaces.get_mut(j) { - if monitor_count > 1 - && matches!(workspace_config.layout, Some(DefaultLayout::Scrolling)) - { - tracing::warn!( - "scrolling layout is only supported for a single monitor; falling back to columns layout" - ); - workspace_config.layout = Some(DefaultLayout::Columns); - } - ws.load_static_config(workspace_config)?; } } diff --git a/komorebi/src/window_manager.rs b/komorebi/src/window_manager.rs index e38f2d2c..93a46e43 100644 --- a/komorebi/src/window_manager.rs +++ b/komorebi/src/window_manager.rs @@ -881,16 +881,8 @@ impl WindowManager { pub fn change_workspace_layout_default(&mut self, layout: DefaultLayout) -> eyre::Result<()> { tracing::info!("changing layout"); - let monitor_count = self.monitors().len(); let workspace = self.focused_workspace_mut()?; - if monitor_count > 1 && matches!(layout, DefaultLayout::Scrolling) { - tracing::warn!( - "scrolling layout is only supported for a single monitor; not changing layout" - ); - return Ok(()); - } - workspace.layout = Layout::Default(layout); self.update_focused_workspace(self.mouse_follows_focus, false) } diff --git a/komorebi/src/workspace.rs b/komorebi/src/workspace.rs index 9fc537bb..1541afbb 100644 --- a/komorebi/src/workspace.rs +++ b/komorebi/src/workspace.rs @@ -1133,6 +1133,9 @@ impl Workspace { &self.latest_layout, ); + let is_scrolling = matches!(self.layout, Layout::Default(DefaultLayout::Scrolling)); + let window_hiding_position = self.globals.window_hiding_position; + let containers = self.containers_mut(); for (i, container) in containers.iter_mut().enumerate() { @@ -1140,8 +1143,13 @@ impl Workspace { layout.add_padding(border_offset); layout.add_padding(border_width); - for window in container.windows() { - if let Err(error) = window.set_position(layout) { + for window in container.windows_mut() { + if is_scrolling && !work_area.contains_within_horizontal_bounds(layout) + { + if let Err(error) = window.hide(window_hiding_position) { + tracing::warn!("failed to set window position: {error}") + } + } else if let Err(error) = window.set_position(layout) { tracing::warn!("failed to set window position: {error}") } }