shell: Restore fullscreen surface to stack

Previously, a surface that was in a stack that is fullscreened would be
removed from the stack, and on unfullscreening, restored to the
floating/tiling layer as though it were a new window outside the stack.

Instead, if the stack still exists, add the window to it at the same
position it previously occupied.
This commit is contained in:
Ian Douglas Scott 2026-06-18 20:41:28 -07:00 committed by Ian Douglas Scott
parent f765696834
commit 9e6d46c17e
2 changed files with 42 additions and 23 deletions

View file

@ -62,7 +62,7 @@ use wayland_backend::server::ClientId;
use super::{
CosmicMappedRenderElement, CosmicSurface, ResizeDirection, ResizeMode,
element::{
CosmicMapped, MaximizedState, resize_indicator::ResizeIndicator,
CosmicMapped, CosmicMappedKey, MaximizedState, resize_indicator::ResizeIndicator,
stack::CosmicStackRenderElement, swap_indicator::SwapIndicator,
window::CosmicWindowRenderElement,
},
@ -263,6 +263,9 @@ pub enum FullscreenRestoreState {
output: WeakOutput,
state: FloatingRestoreData,
},
Stack {
state: StackRestoreData,
},
}
impl FullscreenRestoreState {
@ -271,6 +274,7 @@ impl FullscreenRestoreState {
FullscreenRestoreState::Floating { state, .. }
| FullscreenRestoreState::Sticky { state, .. } => state.was_maximized,
FullscreenRestoreState::Tiling { state, .. } => state.was_maximized,
FullscreenRestoreState::Stack { .. } => false,
}
}
}
@ -280,16 +284,7 @@ pub enum WorkspaceRestoreData {
Fullscreen(Option<FullscreenRestoreData>),
Tiling(Option<TilingRestoreData>),
Floating(Option<FloatingRestoreData>),
}
impl From<ManagedLayer> for WorkspaceRestoreData {
fn from(value: ManagedLayer) -> Self {
match value {
ManagedLayer::Floating | ManagedLayer::Sticky => WorkspaceRestoreData::Floating(None),
ManagedLayer::Tiling => WorkspaceRestoreData::Tiling(None),
ManagedLayer::Fullscreen => WorkspaceRestoreData::Fullscreen(None),
}
}
Stack(StackRestoreData),
}
#[derive(Debug, Clone)]
@ -321,6 +316,12 @@ pub struct TilingRestoreData {
pub was_maximized: bool,
}
#[derive(Debug, Clone)]
pub struct StackRestoreData {
pub stack: CosmicMappedKey,
pub idx: usize,
}
#[derive(Debug, Clone)]
pub struct FullscreenRestoreData {
pub previous_state: FullscreenRestoreState,
@ -716,15 +717,14 @@ impl Workspace {
if let Some(stack) = mapped.stack_ref()
&& stack.len() > 1
{
let idx = stack.surfaces().position(|s| &s == surface);
let layer = if self.is_tiled(surface) {
ManagedLayer::Tiling
} else {
ManagedLayer::Floating
};
return idx
.and_then(|idx| stack.remove_idx(idx))
.map(|s| (s, layer.into()));
let idx = stack.surfaces().position(|s| &s == surface)?;
return Some((
stack.remove_idx(idx)?,
WorkspaceRestoreData::Stack(StackRestoreData {
stack: mapped.key(),
idx,
}),
));
}
// we know mapped is no stack with more than one element now,