From 39ca180dbd405d69e05c1bebae42e44cb56939a3 Mon Sep 17 00:00:00 2001 From: Victoria Brekenfeld Date: Mon, 23 Oct 2023 22:15:27 +0200 Subject: [PATCH] floating: Restore size of moved maximized windows correctly --- src/shell/element/mod.rs | 8 ++++++++ src/shell/element/stack.rs | 10 ++++++++++ src/shell/element/surface.rs | 10 ++++++++++ src/shell/element/window.rs | 10 ++++++++++ src/shell/layout/floating/mod.rs | 11 +++++++++-- 5 files changed, 47 insertions(+), 2 deletions(-) diff --git a/src/shell/element/mod.rs b/src/shell/element/mod.rs index ca8b20cf..75c70658 100644 --- a/src/shell/element/mod.rs +++ b/src/shell/element/mod.rs @@ -370,6 +370,14 @@ impl CosmicMapped { window.is_activated(pending) } + pub fn pending_size(&self) -> Option> { + match &self.element { + CosmicMappedInternal::Stack(s) => s.pending_size(), + CosmicMappedInternal::Window(w) => w.pending_size(), + _ => unreachable!(), + } + } + pub fn set_geometry(&self, geo: Rectangle) { match &self.element { CosmicMappedInternal::Stack(s) => s.set_geometry(geo), diff --git a/src/shell/element/stack.rs b/src/shell/element/stack.rs index 7cda6936..1a37f7a6 100644 --- a/src/shell/element/stack.rs +++ b/src/shell/element/stack.rs @@ -408,6 +408,16 @@ impl CosmicStack { Point::from((0, TAB_HEIGHT)) } + pub fn pending_size(&self) -> Option> { + self.0.with_program(|p| { + p.geometry + .lock() + .unwrap() + .clone() + .map(|geo| geo.size.as_logical()) + }) + } + pub fn set_geometry(&self, geo: Rectangle) { self.0.with_program(|p| { let loc = (geo.loc.x, geo.loc.y + TAB_HEIGHT); diff --git a/src/shell/element/surface.rs b/src/shell/element/surface.rs index c427f1b9..99ccbef5 100644 --- a/src/shell/element/surface.rs +++ b/src/shell/element/surface.rs @@ -123,6 +123,16 @@ impl CosmicSurface { } } + pub fn pending_size(&self) -> Option> { + match self { + CosmicSurface::Wayland(window) => { + window.toplevel().with_pending_state(|state| state.size) + } + CosmicSurface::X11(surface) => Some(surface.geometry().size), + _ => unreachable!(), + } + } + pub fn set_geometry(&self, geo: Rectangle) { match self { CosmicSurface::Wayland(window) => window diff --git a/src/shell/element/window.rs b/src/shell/element/window.rs index ed82aeda..e56322c4 100644 --- a/src/shell/element/window.rs +++ b/src/shell/element/window.rs @@ -134,6 +134,16 @@ impl CosmicWindow { )) } + pub fn pending_size(&self) -> Option> { + self.0.with_program(|p| { + let mut size = p.window.pending_size()?; + if p.has_ssd(true) { + size.h += SSD_HEIGHT; + } + Some(size) + }) + } + pub fn set_geometry(&self, geo: Rectangle) { self.0.with_program(|p| { let loc = ( diff --git a/src/shell/layout/floating/mod.rs b/src/shell/layout/floating/mod.rs index f8af90a4..955cec54 100644 --- a/src/shell/layout/floating/mod.rs +++ b/src/shell/layout/floating/mod.rs @@ -157,8 +157,15 @@ impl FloatingLayout { pub fn unmap(&mut self, window: &CosmicMapped) -> bool { if !window.is_maximized(true) || !window.is_fullscreen(true) { if let Some(location) = self.space.element_location(window) { - *window.last_geometry.lock().unwrap() = - Some(Rectangle::from_loc_and_size(location, window.geometry().size).as_local()); + *window.last_geometry.lock().unwrap() = Some( + Rectangle::from_loc_and_size( + location, + window + .pending_size() + .unwrap_or_else(|| window.geometry().size), + ) + .as_local(), + ) } }