tiling: Fix focus toggling stacking

This commit is contained in:
Victoria Brekenfeld 2024-01-15 09:35:38 +00:00 committed by Victoria Brekenfeld
parent 234a3c6bf9
commit cbfda813ed

View file

@ -383,7 +383,8 @@ impl TilingLayout {
let mut tree = self.queue.trees.back().unwrap().0.copy_clone(); let mut tree = self.queue.trees.back().unwrap().0.copy_clone();
let last_active = focus_stack let last_active = focus_stack
.and_then(|focus_stack| TilingLayout::last_active_window(&mut tree, focus_stack)); .and_then(|focus_stack| TilingLayout::last_active_window(&mut tree, focus_stack))
.map(|(node_id, _)| node_id);
TilingLayout::map_to_tree(&mut tree, window, &self.output, last_active, direction); TilingLayout::map_to_tree(&mut tree, window, &self.output, last_active, direction);
let blocker = TilingLayout::update_positions(&self.output, &mut tree, gaps); let blocker = TilingLayout::update_positions(&self.output, &mut tree, gaps);
self.queue.push_tree(tree, ANIMATION_DURATION, blocker); self.queue.push_tree(tree, ANIMATION_DURATION, blocker);
@ -393,7 +394,7 @@ impl TilingLayout {
mut tree: &mut Tree<Data>, mut tree: &mut Tree<Data>,
window: impl Into<CosmicMapped>, window: impl Into<CosmicMapped>,
output: &Output, output: &Output,
node: Option<(NodeId, CosmicMapped)>, node: Option<NodeId>,
direction: Option<Direction>, direction: Option<Direction>,
) { ) {
let window = window.into(); let window = window.into();
@ -424,7 +425,7 @@ impl TilingLayout {
tree.insert(new_window, InsertBehavior::AsRoot).unwrap() tree.insert(new_window, InsertBehavior::AsRoot).unwrap()
} }
} else { } else {
if let Some((ref node_id, _)) = node { if let Some(ref node_id) = node {
let orientation = { let orientation = {
let window_size = tree.get(node_id).unwrap().data().geometry().size; let window_size = tree.get(node_id).unwrap().data().geometry().size;
if window_size.w > window_size.h { if window_size.w > window_size.h {
@ -1909,11 +1910,10 @@ impl TilingLayout {
match tree.get_mut(&node_id).unwrap().data_mut() { match tree.get_mut(&node_id).unwrap().data_mut() {
Data::Mapped { mapped, .. } => { Data::Mapped { mapped, .. } => {
mapped.convert_to_stack((&self.output, mapped.bbox()), self.theme.clone()); mapped.convert_to_stack((&self.output, mapped.bbox()), self.theme.clone());
KeyboardFocusTarget::Element(mapped.clone())
} }
_ => unreachable!(), _ => unreachable!(),
}; }
KeyboardFocusTarget::Element(mapped.clone())
} else { } else {
// if we have a stack // if we have a stack
let mut surfaces = mapped.windows().map(|(s, _)| s); let mut surfaces = mapped.windows().map(|(s, _)| s);
@ -1933,7 +1933,7 @@ impl TilingLayout {
}; };
// map the rest // map the rest
let mut current_node = (node_id.clone(), mapped.clone()); let mut current_node = node_id.clone();
for other in surfaces { for other in surfaces {
other.try_force_undecorated(false); other.try_force_undecorated(false);
other.set_tiled(false); other.set_tiled(false);
@ -1958,23 +1958,28 @@ impl TilingLayout {
); );
let node = window.tiling_node_id.lock().unwrap().clone().unwrap(); let node = window.tiling_node_id.lock().unwrap().clone().unwrap();
current_node = (node, window); current_node = node;
} }
// TODO: Focus the new group let node = tree.get(&node_id).unwrap();
if let Some(parent) = tree.get(&node_id).unwrap().parent() { let node_id = if current_node != node_id {
let Data::Group { alive, .. } = tree.get(&parent).unwrap().data() else { unreachable!() }; node.parent().cloned().unwrap_or(node_id)
KeyboardFocusTarget::Group(WindowGroup { } else {
node: parent.clone(), node_id
};
match tree.get(&node_id).unwrap().data() {
Data::Group { alive, .. } => KeyboardFocusTarget::Group(WindowGroup {
node: node_id.clone(),
alive: Arc::downgrade(alive), alive: Arc::downgrade(alive),
focus_stack: tree focus_stack: tree
.children_ids(parent) .children_ids(&node_id)
.unwrap() .unwrap()
.cloned() .cloned()
.collect::<Vec<_>>(), .collect::<Vec<_>>(),
}) }),
} else { Data::Mapped { mapped, .. } => KeyboardFocusTarget::Element(mapped.clone()),
KeyboardFocusTarget::Element(mapped.clone()) _ => unreachable!(),
} }
}; };