From 649547d3cce9ab5a314ba51866ee530417e838a7 Mon Sep 17 00:00:00 2001 From: Ian Douglas Scott Date: Mon, 27 Jan 2025 18:22:34 -0800 Subject: [PATCH] toplevel-management: Move window, not whole stack If the window is part of a stack, remove it then map it outside of the stack, before calling `Shell::move_window.` Somewhat similar to the code in `Shell::move_request`. It would be more elegant if `move_window` handled this in some way, but I can't think of a way to change the API there that would be better than this. (Perhaps some of the naming of methods could also be updated, given "window" in functions like this means a `CosmicMapped`.) Protocol support for moving workspaces would also be useful, but should involve a new protocol object representing the stack. Fixes https://github.com/pop-os/cosmic-workspaces-epoch/issues/41. --- src/wayland/handlers/toplevel_management.rs | 26 ++++++++++++++++++--- 1 file changed, 23 insertions(+), 3 deletions(-) diff --git a/src/wayland/handlers/toplevel_management.rs b/src/wayland/handlers/toplevel_management.rs index 28654837a..f64d2df4c 100644 --- a/src/wayland/handlers/toplevel_management.rs +++ b/src/wayland/handlers/toplevel_management.rs @@ -10,7 +10,7 @@ use smithay::{ }; use crate::{ - shell::{CosmicSurface, Shell, WorkspaceDelta}, + shell::{element::CosmicWindow, CosmicSurface, Shell, WorkspaceDelta}, utils::prelude::*, wayland::protocols::{ toplevel_info::ToplevelInfoHandler, @@ -109,8 +109,28 @@ impl ToplevelManagementHandler for State { }; let mut shell = self.common.shell.write().unwrap(); - if let Some(mapped) = shell.element_for_surface(window).cloned() { - if let Some(from_workspace) = shell.space_for(&mapped) { + if let Some(mut mapped) = shell.element_for_surface(window).cloned() { + if let Some(from_workspace) = shell.space_for_mut(&mapped) { + // If window is part of a stack, remove it and map it outside the stack + if let Some(stack) = mapped.stack_ref() { + stack.remove_window(&window); + mapped = CosmicWindow::new( + window.clone(), + self.common.event_loop_handle.clone(), + self.common.theme.clone(), + ) + .into(); + if from_workspace.tiling_enabled { + from_workspace.tiling_layer.map( + mapped.clone(), + None::>, + None, + ); + } else { + from_workspace.floating_layer.map(mapped.clone(), None); + } + } + let from_handle = from_workspace.handle; let seat = shell.seats.last_active().clone(); let res = shell.move_window(