diff options
| author | Ivan Molodetskikh <yalterz@gmail.com> | 2025-04-18 10:47:59 +0300 |
|---|---|---|
| committer | Ivan Molodetskikh <yalterz@gmail.com> | 2025-04-25 02:00:18 -0700 |
| commit | 3f09352067434c8ff84ef3f359e784cd63138c21 (patch) | |
| tree | 57acc12a0f69235900b640bdb2ab1d79d8b0a8d0 /src/layout | |
| parent | 5059cce886d83b079e2423e3dcc57ad51b982d7b (diff) | |
| download | niri-3f09352067434c8ff84ef3f359e784cd63138c21.tar.gz niri-3f09352067434c8ff84ef3f359e784cd63138c21.tar.bz2 niri-3f09352067434c8ff84ef3f359e784cd63138c21.zip | |
layout/monitor: Extract add_workspace_at()
Diffstat (limited to 'src/layout')
| -rw-r--r-- | src/layout/monitor.rs | 24 |
1 files changed, 14 insertions, 10 deletions
diff --git a/src/layout/monitor.rs b/src/layout/monitor.rs index 85646b63..ee16dc01 100644 --- a/src/layout/monitor.rs +++ b/src/layout/monitor.rs @@ -241,27 +241,31 @@ impl<W: LayoutElement> Monitor<W> { self.windows().any(|win| win.id() == window) } - pub fn add_workspace_top(&mut self) { + pub fn add_workspace_at(&mut self, idx: usize) { let ws = Workspace::new( self.output.clone(), self.clock.clone(), self.options.clone(), ); - self.workspaces.insert(0, ws); - self.active_workspace_idx += 1; + + self.workspaces.insert(idx, ws); + if idx <= self.active_workspace_idx { + self.active_workspace_idx += 1; + } if let Some(switch) = &mut self.workspace_switch { - switch.offset(1); + if idx as f64 <= switch.target_idx() { + switch.offset(1); + } } } + pub fn add_workspace_top(&mut self) { + self.add_workspace_at(0); + } + pub fn add_workspace_bottom(&mut self) { - let ws = Workspace::new( - self.output.clone(), - self.clock.clone(), - self.options.clone(), - ); - self.workspaces.push(ws); + self.add_workspace_at(self.workspaces.len()); } fn activate_workspace(&mut self, idx: usize) { |
