diff options
| author | Ivan Molodetskikh <yalterz@gmail.com> | 2025-09-25 18:15:46 +0300 |
|---|---|---|
| committer | Ivan Molodetskikh <yalterz@gmail.com> | 2025-10-02 09:33:08 +0300 |
| commit | 3b4cf1ec8f0eea992740a33e143917edb761eb7d (patch) | |
| tree | aad7f71cc659a5bc4f5177d4e87463762769b4ee /src/layout/monitor.rs | |
| parent | 1484175408b72fe6d267bc08036319969fc39ea1 (diff) | |
| download | niri-3b4cf1ec8f0eea992740a33e143917edb761eb7d.tar.gz niri-3b4cf1ec8f0eea992740a33e143917edb761eb7d.tar.bz2 niri-3b4cf1ec8f0eea992740a33e143917edb761eb7d.zip | |
layout: Extract Monitor::remove_workspace_by_idx()
Diffstat (limited to 'src/layout/monitor.rs')
| -rw-r--r-- | src/layout/monitor.rs | 25 |
1 files changed, 25 insertions, 0 deletions
diff --git a/src/layout/monitor.rs b/src/layout/monitor.rs index 600907cc..3c258d49 100644 --- a/src/layout/monitor.rs +++ b/src/layout/monitor.rs @@ -604,6 +604,31 @@ impl<W: LayoutElement> Monitor<W> { true } + pub fn remove_workspace_by_idx(&mut self, mut idx: usize) -> Workspace<W> { + if idx == self.workspaces.len() - 1 { + self.add_workspace_bottom(); + } + if self.options.layout.empty_workspace_above_first && idx == 0 { + self.add_workspace_top(); + idx += 1; + } + + let mut ws = self.workspaces.remove(idx); + ws.set_output(None); + + // For monitor current workspace removal, we focus previous rather than next (<= rather + // than <). This is different from columns and tiles, but it lets move-workspace-to-monitor + // back and forth to preserve position. + if idx <= self.active_workspace_idx && self.active_workspace_idx > 0 { + self.active_workspace_idx -= 1; + } + + self.workspace_switch = None; + self.clean_up_workspaces(); + + ws + } + pub fn move_down_or_to_workspace_down(&mut self) { if !self.active_workspace().move_down() { self.move_to_workspace_down(true); |
