From 4d215755f66d71ba3725dc380fd3373090c6cc7d Mon Sep 17 00:00:00 2001 From: Victoria Brekenfeld Date: Tue, 10 Sep 2024 21:10:02 +0200 Subject: [PATCH] shell: Fix incomplete focus_stack after swapping --- src/input/mod.rs | 24 ++++++++++++++++++++++++ src/shell/layout/tiling/mod.rs | 4 +++- src/shell/mod.rs | 1 + src/shell/workspace.rs | 8 ++++++-- 4 files changed, 34 insertions(+), 3 deletions(-) diff --git a/src/input/mod.rs b/src/input/mod.rs index ca629276..0e608117 100644 --- a/src/input/mod.rs +++ b/src/input/mod.rs @@ -272,6 +272,22 @@ impl State { let (mut old_w, mut other_w) = spaces.partition::, _>(|w| w.handle == old_descriptor.handle); if let Some(old_workspace) = old_w.get_mut(0) { if let Some(new_workspace) = other_w.iter_mut().find(|w| w.handle == new_descriptor.handle) { + { + let mut stack = new_workspace.focus_stack.get_mut(&seat); + for elem in old_descriptor.focus_stack.iter().flat_map(|node_id| { + old_workspace.tiling_layer.element_for_node(node_id) + }) { + stack.append(elem); + } + } + { + let mut stack = old_workspace.focus_stack.get_mut(&seat); + for elem in new_descriptor.focus_stack.iter().flat_map(|node_id| { + new_workspace.tiling_layer.element_for_node(node_id) + }) { + stack.append(elem); + } + } if let Some(focus) = TilingLayout::swap_trees(&mut old_workspace.tiling_layer, Some(&mut new_workspace.tiling_layer), &old_descriptor, &new_descriptor) { let seat = seat.clone(); data.common.event_loop_handle.insert_idle(move |state| { @@ -303,6 +319,14 @@ impl State { if let Some(old_workspace) = old_w.get_mut(0) { if let Some(new_workspace) = other_w.iter_mut().find(|w| w.handle == new_workspace) { if new_workspace.tiling_layer.windows().next().is_none() { + { + let mut stack = new_workspace.focus_stack.get_mut(&seat); + for elem in old_descriptor.focus_stack.iter().flat_map(|node_id| { + old_workspace.tiling_layer.element_for_node(node_id) + }) { + stack.append(elem); + } + } if let Some(focus) = TilingLayout::move_tree(&mut old_workspace.tiling_layer, &mut new_workspace.tiling_layer, &new_workspace.handle, &seat, new_workspace.focus_stack.get(&seat).iter(), old_descriptor.clone(), None) { let seat = seat.clone(); data.common.event_loop_handle.insert_idle(move |state| { diff --git a/src/shell/layout/tiling/mod.rs b/src/shell/layout/tiling/mod.rs index 371051b2..feeebcd8 100644 --- a/src/shell/layout/tiling/mod.rs +++ b/src/shell/layout/tiling/mod.rs @@ -86,6 +86,7 @@ pub struct NodeDesc { pub handle: WorkspaceHandle, pub node: NodeId, pub stack_window: Option, + pub focus_stack: Vec, } #[derive(Debug, Clone, PartialEq)] @@ -813,8 +814,9 @@ impl TilingLayout { other.node_desc_to_focus(&NodeDesc { handle: other_handle.clone(), - node: id, + node: id.clone(), stack_window: None, + focus_stack: Vec::new(), // node_desc_to_focus doesn't use this }) } } diff --git a/src/shell/mod.rs b/src/shell/mod.rs index d5750272..eb149f7a 100644 --- a/src/shell/mod.rs +++ b/src/shell/mod.rs @@ -2564,6 +2564,7 @@ impl Shell { handle: from, node, stack_window: None, + focus_stack, }, direction, ); diff --git a/src/shell/workspace.rs b/src/shell/workspace.rs index 85589efb..44af522e 100644 --- a/src/shell/workspace.rs +++ b/src/shell/workspace.rs @@ -974,7 +974,7 @@ impl Workspace { .clone() .map(|node_id| NodeDesc { handle: self.handle.clone(), - node: node_id, + node: node_id.clone(), stack_window: if mapped .stack_ref() .map(|stack| !stack.whole_stack_focused()) @@ -984,16 +984,20 @@ impl Workspace { } else { None }, + focus_stack: vec![node_id], }) } else { None } }) } - KeyboardFocusTarget::Group(WindowGroup { node, .. }) => Some(NodeDesc { + KeyboardFocusTarget::Group(WindowGroup { + node, focus_stack, .. + }) => Some(NodeDesc { handle: self.handle.clone(), node, stack_window: None, + focus_stack, }), _ => None, }