diff options
| author | Ivan Molodetskikh <yalterz@gmail.com> | 2025-09-26 17:16:53 +0300 |
|---|---|---|
| committer | Ivan Molodetskikh <yalterz@gmail.com> | 2025-10-02 09:33:08 +0300 |
| commit | 67ca2cb06cce62e75ea7077f0fdaf54b9f45ea82 (patch) | |
| tree | 04905e3ae42d7dbf574d50b2a3b356ec363ded1b /src/layout/monitor.rs | |
| parent | 9ff1c90fa6a4bb962e0a9c76e18552a245177c53 (diff) | |
| download | niri-67ca2cb06cce62e75ea7077f0fdaf54b9f45ea82.tar.gz niri-67ca2cb06cce62e75ea7077f0fdaf54b9f45ea82.tar.bz2 niri-67ca2cb06cce62e75ea7077f0fdaf54b9f45ea82.zip | |
layout: Move scrolling width resolution to workspace
This is required now with per-output and per-workspace options.
Diffstat (limited to 'src/layout/monitor.rs')
| -rw-r--r-- | src/layout/monitor.rs | 51 |
1 files changed, 29 insertions, 22 deletions
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<W: LayoutElement> Monitor<W> { } } + 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<W: LayoutElement> Monitor<W> { 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]; |
