From c8ebac354c7788c4edfa50953c99e5aae5acfb9b Mon Sep 17 00:00:00 2001 From: Ian Douglas Scott Date: Fri, 11 Oct 2024 13:05:51 -0700 Subject: [PATCH] Preserve active workspace when workspaces are moved back to another output Instead of preserving the active workspace index, which may not match if a workspace before it has been moved back to another output. --- src/shell/mod.rs | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-) diff --git a/src/shell/mod.rs b/src/shell/mod.rs index 39c62e2e..998af39f 100644 --- a/src/shell/mod.rs +++ b/src/shell/mod.rs @@ -668,6 +668,7 @@ impl Workspaces { self.sets.insert(output.clone(), set); let mut moved_workspaces = Vec::new(); for set in self.sets.values_mut() { + let active_handle = set.workspaces[set.active].handle; let (prefers, doesnt) = set .workspaces .drain(..) @@ -677,7 +678,11 @@ impl Workspaces { if set.workspaces.is_empty() { set.add_empty_workspace(workspace_state); } - set.active = set.active.min(set.workspaces.len() - 1); + set.active = set + .workspaces + .iter() + .position(|w| w.handle == active_handle) + .unwrap_or(set.workspaces.len() - 1); } { let set = self.sets.get_mut(output).unwrap();