Skip to content

Commit

Permalink
floating: Restore size of moved maximized windows correctly
Browse files Browse the repository at this point in the history
  • Loading branch information
Drakulix committed Oct 23, 2023
1 parent b5ef37d commit 39ca180
Show file tree
Hide file tree
Showing 5 changed files with 47 additions and 2 deletions.
8 changes: 8 additions & 0 deletions src/shell/element/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -370,6 +370,14 @@ impl CosmicMapped {
window.is_activated(pending)
}

pub fn pending_size(&self) -> Option<Size<i32, Logical>> {
match &self.element {
CosmicMappedInternal::Stack(s) => s.pending_size(),
CosmicMappedInternal::Window(w) => w.pending_size(),
_ => unreachable!(),
}
}

pub fn set_geometry(&self, geo: Rectangle<i32, Global>) {
match &self.element {
CosmicMappedInternal::Stack(s) => s.set_geometry(geo),
Expand Down
10 changes: 10 additions & 0 deletions src/shell/element/stack.rs
Original file line number Diff line number Diff line change
Expand Up @@ -408,6 +408,16 @@ impl CosmicStack {
Point::from((0, TAB_HEIGHT))
}

pub fn pending_size(&self) -> Option<Size<i32, Logical>> {
self.0.with_program(|p| {
p.geometry
.lock()
.unwrap()
.clone()
.map(|geo| geo.size.as_logical())
})
}

pub fn set_geometry(&self, geo: Rectangle<i32, Global>) {
self.0.with_program(|p| {
let loc = (geo.loc.x, geo.loc.y + TAB_HEIGHT);
Expand Down
10 changes: 10 additions & 0 deletions src/shell/element/surface.rs
Original file line number Diff line number Diff line change
Expand Up @@ -123,6 +123,16 @@ impl CosmicSurface {
}
}

pub fn pending_size(&self) -> Option<Size<i32, Logical>> {
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<i32, Global>) {
match self {
CosmicSurface::Wayland(window) => window
Expand Down
10 changes: 10 additions & 0 deletions src/shell/element/window.rs
Original file line number Diff line number Diff line change
Expand Up @@ -134,6 +134,16 @@ impl CosmicWindow {
))
}

pub fn pending_size(&self) -> Option<Size<i32, Logical>> {
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<i32, Global>) {
self.0.with_program(|p| {
let loc = (
Expand Down
11 changes: 9 additions & 2 deletions src/shell/layout/floating/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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(),
)
}
}

Expand Down

0 comments on commit 39ca180

Please sign in to comment.