From 67ca2cb06cce62e75ea7077f0fdaf54b9f45ea82 Mon Sep 17 00:00:00 2001 From: Ivan Molodetskikh Date: Fri, 26 Sep 2025 17:16:53 +0300 Subject: layout: Move scrolling width resolution to workspace This is required now with per-output and per-workspace options. --- src/layout/monitor.rs | 51 +++++++++++++++++++++++++++++---------------------- 1 file changed, 29 insertions(+), 22 deletions(-) (limited to 'src/layout/monitor.rs') diff --git a/src/layout/monitor.rs b/src/layout/monitor.rs index 9e34ad35..5e463a7e 100644 --- a/src/layout/monitor.rs +++ b/src/layout/monitor.rs @@ -480,6 +480,34 @@ impl Monitor { } } + pub(super) fn resolve_add_window_target<'a>( + &mut self, + target: MonitorAddWindowTarget<'a, W>, + ) -> (usize, WorkspaceAddWindowTarget<'a, W>) { + match target { + MonitorAddWindowTarget::Auto => { + (self.active_workspace_idx, WorkspaceAddWindowTarget::Auto) + } + MonitorAddWindowTarget::Workspace { id, column_idx } => { + let idx = self.workspaces.iter().position(|ws| ws.id() == id).unwrap(); + let target = if let Some(column_idx) = column_idx { + WorkspaceAddWindowTarget::NewColumnAt(column_idx) + } else { + WorkspaceAddWindowTarget::Auto + }; + (idx, target) + } + MonitorAddWindowTarget::NextTo(win_id) => { + let idx = self + .workspaces + .iter_mut() + .position(|ws| ws.has_window(win_id)) + .unwrap(); + (idx, WorkspaceAddWindowTarget::NextTo(win_id)) + } + } + } + pub fn add_window( &mut self, window: W, @@ -539,28 +567,7 @@ impl Monitor { is_full_width: bool, is_floating: bool, ) { - let (mut workspace_idx, target) = match target { - MonitorAddWindowTarget::Auto => { - (self.active_workspace_idx, WorkspaceAddWindowTarget::Auto) - } - MonitorAddWindowTarget::Workspace { id, column_idx } => { - let idx = self.workspaces.iter().position(|ws| ws.id() == id).unwrap(); - let target = if let Some(column_idx) = column_idx { - WorkspaceAddWindowTarget::NewColumnAt(column_idx) - } else { - WorkspaceAddWindowTarget::Auto - }; - (idx, target) - } - MonitorAddWindowTarget::NextTo(win_id) => { - let idx = self - .workspaces - .iter_mut() - .position(|ws| ws.has_window(win_id)) - .unwrap(); - (idx, WorkspaceAddWindowTarget::NextTo(win_id)) - } - }; + let (mut workspace_idx, target) = self.resolve_add_window_target(target); let workspace = &mut self.workspaces[workspace_idx]; -- cgit