aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorIvan Molodetskikh <yalterz@gmail.com>2025-09-25 18:15:46 +0300
committerIvan Molodetskikh <yalterz@gmail.com>2025-10-02 09:33:08 +0300
commit3b4cf1ec8f0eea992740a33e143917edb761eb7d (patch)
treeaad7f71cc659a5bc4f5177d4e87463762769b4ee
parent1484175408b72fe6d267bc08036319969fc39ea1 (diff)
downloadniri-3b4cf1ec8f0eea992740a33e143917edb761eb7d.tar.gz
niri-3b4cf1ec8f0eea992740a33e143917edb761eb7d.tar.bz2
niri-3b4cf1ec8f0eea992740a33e143917edb761eb7d.zip
layout: Extract Monitor::remove_workspace_by_idx()
-rw-r--r--src/layout/mod.rs32
-rw-r--r--src/layout/monitor.rs25
2 files changed, 27 insertions, 30 deletions
diff --git a/src/layout/mod.rs b/src/layout/mod.rs
index 60c0f1fe..084c0236 100644
--- a/src/layout/mod.rs
+++ b/src/layout/mod.rs
@@ -3414,19 +3414,7 @@ impl<W: LayoutElement> Layout<W> {
return false;
}
- if current.active_workspace_idx == current.workspaces.len() - 1 {
- // Insert a new empty workspace.
- current.add_workspace_bottom();
- }
- if current.options.layout.empty_workspace_above_first && current.active_workspace_idx == 0 {
- current.add_workspace_top();
- }
-
- let mut ws = current.workspaces.remove(current.active_workspace_idx);
- current.active_workspace_idx = current.active_workspace_idx.saturating_sub(1);
- current.workspace_switch = None;
- current.clean_up_workspaces();
-
+ let mut ws = current.remove_workspace_by_idx(current.active_workspace_idx);
ws.set_output(Some(output.clone()));
ws.original_output = OutputId::new(output);
@@ -3500,23 +3488,7 @@ impl<W: LayoutElement> Layout<W> {
let current_active_ws_idx = current.active_workspace_idx;
- if old_idx == current.workspaces.len() - 1 {
- // Insert a new empty workspace.
- current.add_workspace_bottom();
- }
-
- let mut ws = current.workspaces.remove(old_idx);
-
- if current.options.layout.empty_workspace_above_first && old_idx == 0 {
- current.add_workspace_top();
- }
-
- if old_idx < current.active_workspace_idx {
- current.active_workspace_idx -= 1;
- }
- current.workspace_switch = None;
- current.clean_up_workspaces();
-
+ let mut ws = current.remove_workspace_by_idx(old_idx);
ws.set_output(Some(new_output.clone()));
ws.original_output = OutputId::new(&new_output);
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);