aboutsummaryrefslogtreecommitdiff
path: root/src/layout/monitor.rs
diff options
context:
space:
mode:
authorKirottu <56396750+Kirottu@users.noreply.github.com>2025-01-25 10:49:51 +0200
committerGitHub <noreply@github.com>2025-01-25 08:49:51 +0000
commit852da5714affd067de731599136ed619dc3bba40 (patch)
treee42514f81d8a7f74f5437746503367082917777a /src/layout/monitor.rs
parent4f793038117b4fef38f491e665a66589eb896e0a (diff)
downloadniri-852da5714affd067de731599136ed619dc3bba40.tar.gz
niri-852da5714affd067de731599136ed619dc3bba40.tar.bz2
niri-852da5714affd067de731599136ed619dc3bba40.zip
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>
Diffstat (limited to 'src/layout/monitor.rs')
-rw-r--r--src/layout/monitor.rs47
1 files changed, 47 insertions, 0 deletions
diff --git a/src/layout/monitor.rs b/src/layout/monitor.rs
index 8bb92a33..3eaac97f 100644
--- a/src/layout/monitor.rs
+++ b/src/layout/monitor.rs
@@ -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.