Skip to content
8 changes: 8 additions & 0 deletions src/shell/layout/floating/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1641,6 +1641,14 @@ impl FloatingLayout {
elements
}

pub fn snapped_geometry(&self, corners: &TiledCorners) -> Rectangle<i32, Local> {
let output = self.space.outputs().next().unwrap().clone();
let layers = layer_map_for_output(&output);
let non_exclusive = layers.non_exclusive_zone();
std::mem::drop(layers);
corners.relative_geometry(non_exclusive, self.gaps())
}

fn gaps(&self) -> (i32, i32) {
let g = self.theme.cosmic().gaps;
(g.0 as i32, g.1 as i32)
Expand Down
13 changes: 13 additions & 0 deletions src/shell/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2570,6 +2570,7 @@ impl Shell {
state:
FloatingRestoreData {
was_maximized,
was_snapped,
geometry,
..
},
Expand All @@ -2593,6 +2594,12 @@ impl Shell {
fullscreen_geometry,
true,
);
} else if let Some(corners) = was_snapped {
*window.floating_tiled.lock().unwrap() = Some(corners);
window.set_tiled(true);
let snapped_geo = workspace.floating_layer.snapped_geometry(&corners);
window.set_geometry(snapped_geo.to_global(&workspace.output));
window.configure();
Comment thread
Drakulix marked this conversation as resolved.
Outdated
}
}
Some(FullscreenRestoreState::Tiling {
Expand Down Expand Up @@ -4144,6 +4151,7 @@ impl Shell {
geometry: geo,
output_size: set.output.geometry().size.as_logical(),
was_maximized: false,
was_snapped: None,
},
});
} else if let Some((workspace, window)) =
Expand Down Expand Up @@ -4657,6 +4665,8 @@ impl Shell {
stack.remove_window(&surface);
surface
} else {
mapped.set_fullscreen(true);
Comment thread
Drakulix marked this conversation as resolved.

if let Some(state) = mapped.maximized_state.lock().unwrap().take() {
mapped.set_maximized(false);
set.sticky_layer.map_internal(
Expand Down Expand Up @@ -4688,6 +4698,7 @@ impl Shell {
geometry: from,
output_size: workspace.output.geometry().size.as_logical(),
was_maximized,
was_snapped: None,
},
}),
Some(from),
Expand All @@ -4698,6 +4709,8 @@ impl Shell {
return None;
}

mapped.set_fullscreen(true);
Comment thread
Drakulix marked this conversation as resolved.

let from = workspace.element_geometry(&mapped).unwrap();
let (surface, state) = workspace.unmap_surface(surface).unwrap();
window = surface;
Expand Down
13 changes: 12 additions & 1 deletion src/shell/workspace.rs
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ use crate::{
},
shell::{
ANIMATION_DURATION, OverviewMode, SeatMoveGrabState,
layout::{floating::FloatingLayout, tiling::TilingLayout},
layout::{floating::{FloatingLayout, TiledCorners}, tiling::TilingLayout},
},
state::State,
utils::{prelude::*, tween::EaseRectangle},
Expand Down Expand Up @@ -286,6 +286,7 @@ pub struct FloatingRestoreData {
pub geometry: Rectangle<i32, Local>,
pub output_size: Size<i32, Logical>,
pub was_maximized: bool,
pub was_snapped: Option<TiledCorners>,
}

impl FloatingRestoreData {
Expand Down Expand Up @@ -637,13 +638,15 @@ impl Workspace {
})));
}

let was_snapped = mapped.floating_tiled.lock().unwrap().clone();
// unmaximize_request might have triggered a `floating_layer.refresh()`,
// which may have already removed a non-alive surface.
if let Some(floating_geometry) = self.floating_layer.unmap(mapped, None).or(was_maximized) {
return Some(WorkspaceRestoreData::Floating(Some(FloatingRestoreData {
geometry: floating_geometry,
output_size: self.output.geometry().size.as_logical(),
was_maximized: was_maximized.is_some(),
was_snapped
})));
};

Expand Down Expand Up @@ -1066,13 +1069,15 @@ impl Workspace {
mapped.set_minimized(true);
mapped.configure();

let was_snapped = mapped.floating_tiled.lock().unwrap().clone();
if let Some(geometry) = self.floating_layer.unmap(&mapped, Some(to)) {
return Some(MinimizedWindow::Floating {
window: mapped,
previous: FloatingRestoreData {
geometry: was_maximized.unwrap_or(geometry),
output_size: self.output.geometry().size.as_logical(),
was_maximized: was_maximized.is_some(),
was_snapped,
},
});
}
Expand Down Expand Up @@ -1133,6 +1138,12 @@ impl Workspace {
});
std::mem::drop(state);
self.floating_layer.map_maximized(window, geometry, true);
} else if let Some(corners) = previous.was_snapped {
*window.floating_tiled.lock().unwrap() = Some(corners);
window.set_tiled(true);
let snapped_geo = self.floating_layer.snapped_geometry(&corners);
window.set_geometry(snapped_geo.to_global(&self.output));
window.configure();
Comment thread
Drakulix marked this conversation as resolved.
Outdated
}

None
Expand Down