mirror of
https://github.com/niri-wm/niri.git
synced 2026-06-22 02:01:55 +07:00
layout: Extract Monitor::remove_workspace_by_idx()
This commit is contained in:
+2
-30
@@ -3414,19 +3414,7 @@ impl<W: LayoutElement> Layout<W> {
|
|||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
if current.active_workspace_idx == current.workspaces.len() - 1 {
|
let mut ws = current.remove_workspace_by_idx(current.active_workspace_idx);
|
||||||
// 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();
|
|
||||||
|
|
||||||
ws.set_output(Some(output.clone()));
|
ws.set_output(Some(output.clone()));
|
||||||
ws.original_output = OutputId::new(output);
|
ws.original_output = OutputId::new(output);
|
||||||
|
|
||||||
@@ -3500,23 +3488,7 @@ impl<W: LayoutElement> Layout<W> {
|
|||||||
|
|
||||||
let current_active_ws_idx = current.active_workspace_idx;
|
let current_active_ws_idx = current.active_workspace_idx;
|
||||||
|
|
||||||
if old_idx == current.workspaces.len() - 1 {
|
let mut ws = current.remove_workspace_by_idx(old_idx);
|
||||||
// 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();
|
|
||||||
|
|
||||||
ws.set_output(Some(new_output.clone()));
|
ws.set_output(Some(new_output.clone()));
|
||||||
ws.original_output = OutputId::new(&new_output);
|
ws.original_output = OutputId::new(&new_output);
|
||||||
|
|
||||||
|
|||||||
@@ -604,6 +604,31 @@ impl<W: LayoutElement> Monitor<W> {
|
|||||||
true
|
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) {
|
pub fn move_down_or_to_workspace_down(&mut self) {
|
||||||
if !self.active_workspace().move_down() {
|
if !self.active_workspace().move_down() {
|
||||||
self.move_to_workspace_down(true);
|
self.move_to_workspace_down(true);
|
||||||
|
|||||||
Reference in New Issue
Block a user