mirror of
https://github.com/niri-wm/niri.git
synced 2026-06-22 02:01:55 +07:00
Add move-workspace-to-index and move-workspace-to-monitor actions (#1007)
* Added move-workspace-to-index and move-workspace-to-monitor IPC actions * Added redraws to the workspace handling actions, fixed tests that panicked, fixed other mentioned problems. * Fixed workspace focusing and handling numbered workspaces with `move-workspace-to-index` * Fixed more inconsistencies with move-workspace-to-monitor * Added back `self.workspace_switch = None` * Reordered some workspace cleanup logic * Fix formatting * Add missing blank lines * Fix moving workspace to same monitor and wrong current index updating * Move function up and add fixme comment --------- Co-authored-by: Ivan Molodetskikh <yalterz@gmail.com>
This commit is contained in:
@@ -858,6 +858,53 @@ impl<W: LayoutElement> Monitor<W> {
|
||||
self.clean_up_workspaces();
|
||||
}
|
||||
|
||||
pub fn move_workspace_to_idx(&mut self, old_idx: usize, new_idx: usize) {
|
||||
let mut new_idx = new_idx.clamp(0, self.workspaces.len() - 1);
|
||||
if old_idx == new_idx {
|
||||
return;
|
||||
}
|
||||
|
||||
let ws = self.workspaces.remove(old_idx);
|
||||
self.workspaces.insert(new_idx, ws);
|
||||
|
||||
if new_idx > old_idx {
|
||||
if new_idx == self.workspaces.len() - 1 {
|
||||
// Insert a new empty workspace.
|
||||
self.add_workspace_bottom();
|
||||
}
|
||||
|
||||
if self.options.empty_workspace_above_first && old_idx == 0 {
|
||||
self.add_workspace_top();
|
||||
new_idx += 1;
|
||||
}
|
||||
} else {
|
||||
if old_idx == self.workspaces.len() - 1 {
|
||||
// Insert a new empty workspace.
|
||||
self.add_workspace_bottom();
|
||||
}
|
||||
|
||||
if self.options.empty_workspace_above_first && new_idx == 0 {
|
||||
self.add_workspace_top();
|
||||
new_idx += 1;
|
||||
}
|
||||
}
|
||||
|
||||
// Only refocus the workspace if it was already focused
|
||||
if self.active_workspace_idx == old_idx {
|
||||
self.active_workspace_idx = new_idx;
|
||||
// If the workspace order was switched so that the current workspace moved down the
|
||||
// workspace stack, focus correctly
|
||||
} else if new_idx <= self.active_workspace_idx && old_idx > self.active_workspace_idx {
|
||||
self.active_workspace_idx += 1;
|
||||
} else if new_idx >= self.active_workspace_idx && old_idx < self.active_workspace_idx {
|
||||
self.active_workspace_idx = self.active_workspace_idx.saturating_sub(1);
|
||||
}
|
||||
|
||||
self.workspace_switch = None;
|
||||
|
||||
self.clean_up_workspaces();
|
||||
}
|
||||
|
||||
/// Returns the geometry of the active tile relative to and clamped to the output.
|
||||
///
|
||||
/// During animations, assumes the final view position.
|
||||
|
||||
Reference in New Issue
Block a user