diff --git a/src/layout/mod.rs b/src/layout/mod.rs index 09cc68c1..c04a72ba 100644 --- a/src/layout/mod.rs +++ b/src/layout/mod.rs @@ -865,7 +865,6 @@ impl Layout { is_floating: bool, activate: ActivateWindow, ) -> Option<&Output> { - let scrolling_width = self.resolve_scrolling_width(&window, width); let scrolling_height = height.map(SizeChange::from); let id = window.id().clone(); @@ -933,6 +932,10 @@ impl Layout { }; let mon = &mut monitors[mon_idx]; + let (ws_idx, _) = mon.resolve_add_window_target(target); + let ws = &mon.workspaces[ws_idx]; + let scrolling_width = ws.resolve_scrolling_width(&window, width); + mon.add_window( window, target, @@ -1012,6 +1015,8 @@ impl Layout { }; let ws = &mut workspaces[ws_idx]; + let scrolling_width = ws.resolve_scrolling_width(&window, width); + let tile = ws.make_tile(window); ws.add_tile( tile, @@ -4901,25 +4906,6 @@ impl Layout { pub fn is_overview_open(&self) -> bool { self.overview_open } - - fn resolve_scrolling_width(&self, window: &W, width: Option) -> ColumnWidth { - let width = width.unwrap_or_else(|| PresetSize::Fixed(window.size().w)); - match width { - PresetSize::Fixed(fixed) => { - let mut fixed = f64::from(fixed); - - // Add border width since ColumnWidth includes borders. - let rules = window.rules(); - let border = self.options.layout.border.merged_with(&rules.border); - if !border.off { - fixed += border.width * 2.; - } - - ColumnWidth::Fixed(fixed) - } - PresetSize::Proportion(prop) => ColumnWidth::Proportion(prop), - } - } } impl Default for MonitorSet { 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]; diff --git a/src/layout/workspace.rs b/src/layout/workspace.rs index 3831ffe3..5bdd2624 100644 --- a/src/layout/workspace.rs +++ b/src/layout/workspace.rs @@ -2,6 +2,7 @@ use std::cmp::max; use std::rc::Rc; use std::time::Duration; +use niri_config::utils::MergeWith as _; use niri_config::{ CenterFocusedColumn, CornerRadius, OutputName, PresetSize, Workspace as WorkspaceConfig, }; @@ -882,6 +883,29 @@ impl Workspace { }); } + pub(super) fn resolve_scrolling_width( + &self, + window: &W, + width: Option, + ) -> ColumnWidth { + let width = width.unwrap_or_else(|| PresetSize::Fixed(window.size().w)); + match width { + PresetSize::Fixed(fixed) => { + let mut fixed = f64::from(fixed); + + // Add border width since ColumnWidth includes borders. + let rules = window.rules(); + let border = self.options.layout.border.merged_with(&rules.border); + if !border.off { + fixed += border.width * 2.; + } + + ColumnWidth::Fixed(fixed) + } + PresetSize::Proportion(prop) => ColumnWidth::Proportion(prop), + } + } + pub fn focus_left(&mut self) -> bool { if self.floating_is_active.get() { self.floating.focus_left()