From 835dbe45f39a25c736e90164d2b9093e5fff5f19 Mon Sep 17 00:00:00 2001 From: Victoria Brekenfeld Date: Mon, 8 Jan 2024 18:09:43 +0000 Subject: [PATCH] shell: Unify mapping windows into stacks logic --- src/shell/grabs/menu/default.rs | 2 +- src/shell/layout/mod.rs | 6 +++- src/shell/layout/tiling/mod.rs | 37 ++++-------------------- src/shell/mod.rs | 50 ++++++++++++++++++++------------- src/shell/workspace.rs | 4 +-- 5 files changed, 43 insertions(+), 56 deletions(-) diff --git a/src/shell/grabs/menu/default.rs b/src/shell/grabs/menu/default.rs index 678253e2..9d4ad67d 100644 --- a/src/shell/grabs/menu/default.rs +++ b/src/shell/grabs/menu/default.rs @@ -124,7 +124,7 @@ pub fn tab_items( let focus_stack = workspace.focus_stack.get(&seat); workspace .tiling_layer - .map(mapped, Some(focus_stack.iter()), None, false); + .map(mapped, Some(focus_stack.iter()), None); } else { workspace.floating_layer.map(mapped, None) } diff --git a/src/shell/layout/mod.rs b/src/shell/layout/mod.rs index 9652802e..bdae6ed3 100644 --- a/src/shell/layout/mod.rs +++ b/src/shell/layout/mod.rs @@ -98,7 +98,7 @@ lazy_static::lazy_static! { ]).unwrap(); } -pub fn should_be_floating(window: &CosmicSurface) -> bool { +pub fn is_dialog(window: &CosmicSurface) -> bool { // Check "window type" match window { CosmicSurface::Wayland(window) => { @@ -136,6 +136,10 @@ pub fn should_be_floating(window: &CosmicSurface) -> bool { return true; } + false +} + +pub fn has_floating_exception(window: &CosmicSurface) -> bool { // else take a look at our exceptions let appid_matches = EXCEPTIONS_APPID.matches(&window.app_id()); let title_matches = EXCEPTIONS_TITLE.matches(&window.title()); diff --git a/src/shell/layout/tiling/mod.rs b/src/shell/layout/tiling/mod.rs index f68f9b74..3d83c47b 100644 --- a/src/shell/layout/tiling/mod.rs +++ b/src/shell/layout/tiling/mod.rs @@ -367,11 +367,10 @@ impl TilingLayout { window: CosmicMapped, focus_stack: Option + 'a>, direction: Option, - add_to_stack: bool, ) { window.output_enter(&self.output, window.bbox()); window.set_bounds(self.output.geometry().size.as_logical()); - self.map_internal(window, focus_stack, direction, add_to_stack); + self.map_internal(window, focus_stack, direction); } pub fn map_internal<'a>( @@ -379,21 +378,13 @@ impl TilingLayout { window: impl Into, focus_stack: Option + 'a>, direction: Option, - add_to_stack: bool, ) { let gaps = self.gaps(); let mut tree = self.queue.trees.back().unwrap().0.copy_clone(); let last_active = focus_stack .and_then(|focus_stack| TilingLayout::last_active_window(&mut tree, focus_stack)); - TilingLayout::map_to_tree( - &mut tree, - window, - &self.output, - last_active, - direction, - add_to_stack, - ); + TilingLayout::map_to_tree(&mut tree, window, &self.output, last_active, direction); let blocker = TilingLayout::update_positions(&self.output, &mut tree, gaps); self.queue.push_tree(tree, ANIMATION_DURATION, blocker); } @@ -404,7 +395,6 @@ impl TilingLayout { output: &Output, node: Option<(NodeId, CosmicMapped)>, direction: Option, - add_to_stack: bool, ) { let window = window.into(); let new_window = Node::new(Data::Mapped { @@ -434,16 +424,7 @@ impl TilingLayout { tree.insert(new_window, InsertBehavior::AsRoot).unwrap() } } else { - if let Some((ref node_id, mut last_active_window)) = node { - if add_to_stack && window.is_window() && last_active_window.is_stack() { - let surface = window.active_window(); - last_active_window - .stack_ref_mut() - .unwrap() - .add_window(surface, None); - return; - } - + if let Some((ref node_id, _)) = node { let orientation = { let window_size = tree.get(node_id).unwrap().data().geometry().size; if window_size.w > window_size.h { @@ -543,7 +524,7 @@ impl TilingLayout { } mapped.set_tiled(true); - other.map(mapped.clone(), Some(focus_stack), None, true); + other.map(mapped.clone(), Some(focus_stack), None); return Some(KeyboardFocusTarget::Element(mapped)); } None => { @@ -1974,7 +1955,6 @@ impl TilingLayout { &self.output, Some(current_node), None, - false, ); let node = window.tiling_node_id.lock().unwrap().clone().unwrap(); @@ -2505,14 +2485,7 @@ impl TilingLayout { } } _ => { - TilingLayout::map_to_tree( - &mut tree, - window.clone(), - &self.output, - None, - None, - false, - ); + TilingLayout::map_to_tree(&mut tree, window.clone(), &self.output, None, None); window } }; diff --git a/src/shell/mod.rs b/src/shell/mod.rs index d984b0f0..4f2f26b7 100644 --- a/src/shell/mod.rs +++ b/src/shell/mod.rs @@ -1587,12 +1587,11 @@ impl Shell { .map(mapped, None) } ManagedLayer::Floating => new_workspace.floating_layer.map(mapped, None), - ManagedLayer::Tiling => new_workspace.tiling_layer.map( - mapped, - Option::>::None, - None, - false, - ), + ManagedLayer::Tiling => { + new_workspace + .tiling_layer + .map(mapped, Option::>::None, None) + } }; } @@ -1714,6 +1713,26 @@ impl Shell { .toplevel_info_state .toplevel_enter_workspace(&window, &workspace.handle); + let workspace_output = workspace.output.clone(); + let was_activated = workspace_handle.is_some() + && (workspace_output != seat.active_output() || active_handle != workspace.handle); + let workspace_handle = workspace.handle; + let is_dialog = layout::is_dialog(&window); + let floating_exception = layout::has_floating_exception(&window); + + let maybe_focused = workspace.focus_stack.get(&seat).iter().next().cloned(); + if let Some(focused) = maybe_focused { + if (focused.is_stack() && !is_dialog && !should_be_fullscreen) + && !(workspace.is_tiled(&focused) && floating_exception) + { + focused.stack_ref().unwrap().add_window(window, None); + if was_activated { + state.common.shell.set_urgent(&workspace_handle); + } + return; + } + } + let mapped = CosmicMapped::from(CosmicWindow::new( window.clone(), state.common.event_loop_handle.clone(), @@ -1725,8 +1744,7 @@ impl Shell { } let workspace_empty = workspace.mapped().next().is_none(); - - if layout::should_be_floating(&window) || !workspace.tiling_enabled { + if is_dialog || floating_exception || !workspace.tiling_enabled { workspace.floating_layer.map(mapped.clone(), None); } else { for mapped in workspace @@ -1741,17 +1759,13 @@ impl Shell { let focus_stack = workspace.focus_stack.get(&seat); workspace .tiling_layer - .map(mapped.clone(), Some(focus_stack.iter()), None, true); + .map(mapped.clone(), Some(focus_stack.iter()), None); } if !parent_is_sticky && should_be_fullscreen { workspace.fullscreen_request(&mapped.active_window(), None); } - let was_activated = workspace_handle.is_some(); - let workspace_handle = workspace.handle; - let workspace_output = workspace.output.clone(); - if parent_is_sticky { let seats = state.common.seats().cloned().collect::>(); state @@ -1923,7 +1937,6 @@ impl Shell { mapped.clone(), focus_stack.as_ref().map(|x| x.iter()), direction, - true, ); } @@ -2891,12 +2904,9 @@ impl Shell { } ManagedLayer::Tiling => { let focus_stack = workspace.focus_stack.get(seat); - workspace.tiling_layer.map( - mapped.clone(), - Some(focus_stack.iter()), - None, - false, - ); + workspace + .tiling_layer + .map(mapped.clone(), Some(focus_stack.iter()), None); } ManagedLayer::Sticky => unreachable!(), } diff --git a/src/shell/workspace.rs b/src/shell/workspace.rs index c459ac0f..f30147d2 100644 --- a/src/shell/workspace.rs +++ b/src/shell/workspace.rs @@ -637,7 +637,7 @@ impl Workspace { { self.floating_layer.unmap(&window); self.tiling_layer - .map(window, Some(focus_stack.iter()), None, false) + .map(window, Some(focus_stack.iter()), None) } self.tiling_enabled = true; } @@ -655,7 +655,7 @@ impl Workspace { let focus_stack = self.focus_stack.get(seat); self.floating_layer.unmap(&window); self.tiling_layer - .map(window.clone(), Some(focus_stack.iter()), None, false) + .map(window.clone(), Some(focus_stack.iter()), None) } } }