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

@ -2592,9 +2592,21 @@ impl Shell {
pub fn remap_unfullscreened_window(
&mut self,
surface: CosmicSurface,
state: Option<FullscreenRestoreState>,
mut state: Option<FullscreenRestoreState>,
loop_handle: &LoopHandle<'static, State>,
) -> CosmicMapped {
if let Some(FullscreenRestoreState::Stack { state: stack_state }) = &state {
if let Some(mapped) = self.mapped().find(|m| **m == stack_state.stack)
&& let Some(stack) = mapped.stack_ref()
{
let idx = stack_state.idx.min(stack.len());
stack.add_window(surface, Some(idx), None);
return mapped.clone();
} else {
state = None;
}
}
let window = CosmicMapped::from(CosmicWindow::new(
surface,
loop_handle.clone(),
@ -2637,7 +2649,9 @@ impl Shell {
workspace
}
None => self.workspaces.active_mut(&seat.active_output()).unwrap(),
Some(FullscreenRestoreState::Sticky { .. }) => unreachable!(),
Some(FullscreenRestoreState::Sticky { .. } | FullscreenRestoreState::Stack { .. }) => {
unreachable!()
}
};
let fullscreen_geometry = workspace.output.geometry().to_local(&workspace.output);
@ -2752,7 +2766,9 @@ impl Shell {
}
}
}
Some(FullscreenRestoreState::Sticky { .. }) => unreachable!(),
Some(FullscreenRestoreState::Sticky { .. } | FullscreenRestoreState::Stack { .. }) => {
unreachable!()
}
}
window
@ -4878,6 +4894,9 @@ impl Shell {
state,
})
}
WorkspaceRestoreData::Stack(stack_state) => {
Some(FullscreenRestoreState::Stack { state: stack_state })
}
WorkspaceRestoreData::Fullscreen(_) => unreachable!(),
},
Some(from),

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,