From 5488aaf69ffeb6ef504a4bec0b54a893155713cf Mon Sep 17 00:00:00 2001 From: Ivan Molodetskikh Date: Mon, 23 Dec 2024 20:31:03 +0300 Subject: floating: Don't use fullscreen size as floating size --- src/layout/floating.rs | 15 +++++++++------ src/layout/mod.rs | 20 ++++++++++++++------ 2 files changed, 23 insertions(+), 12 deletions(-) (limited to 'src/layout') diff --git a/src/layout/floating.rs b/src/layout/floating.rs index 58ef8427..6b997405 100644 --- a/src/layout/floating.rs +++ b/src/layout/floating.rs @@ -375,8 +375,9 @@ impl FloatingSpace { floating_size.unwrap_or_default() } else { // If the window wasn't fullscreen without a floating size (e.g. it was tiled before), - // ask for the current size. - floating_size.unwrap_or_else(|| win.expected_size()) + // ask for the current size. If the current size is unknown (the window was only ever + // fullscreen until now), fall back to (0, 0). + floating_size.unwrap_or_else(|| win.expected_size().unwrap_or_default()) }; // Make sure fixed-size through window rules keeps working. let min_size = win.min_size(); @@ -482,8 +483,10 @@ impl FloatingSpace { } } - // Store the floating size. - tile.set_floating_window_size(tile.window().expected_size()); + // Store the floating size if we have one. + if let Some(size) = tile.window().expected_size() { + tile.set_floating_window_size(size); + } let width = ColumnWidth::Fixed(tile.window_size().w); RemovedTile { @@ -600,7 +603,7 @@ impl FloatingSpace { win_width = ensure_min_max_size(win_width, min_size.w, max_size.w); win_width = max(1, win_width); - let win_height = win.expected_size().h; + let win_height = win.expected_size().unwrap_or_default().h; let win_height = ensure_min_max_size(win_height, min_size.h, max_size.h); let win_size = Size::from((win_width, win_height)); @@ -626,7 +629,7 @@ impl FloatingSpace { win_height = ensure_min_max_size(win_height, min_size.h, max_size.h); win_height = max(1, win_height); - let win_width = win.expected_size().w; + let win_width = win.expected_size().unwrap_or_default().w; let win_width = ensure_min_max_size(win_width, min_size.w, max_size.w); let win_size = Size::from((win_width, win_height)); diff --git a/src/layout/mod.rs b/src/layout/mod.rs index 74afa501..8bc137e0 100644 --- a/src/layout/mod.rs +++ b/src/layout/mod.rs @@ -197,7 +197,7 @@ pub trait LayoutElement { /// Size previously requested through [`LayoutElement::request_size()`]. fn requested_size(&self) -> Option>; - /// Size that we expect this window has or will shortly have. + /// Non-fullscreen size that we expect this window has or will shortly have. /// /// This can be different from [`requested_size()`](LayoutElement::requested_size()). For /// example, for floating windows this will generally return the current window size, rather @@ -205,10 +205,15 @@ pub trait LayoutElement { /// size freely. But not always: if we just requested a floating window to resize and it hasn't /// responded to it yet, this will return the newly requested size. /// - /// This function should never return a 0 size component. + /// This function should never return a 0 size component. `None` means there's no known + /// expected size (for example, the window is fullscreen). /// /// The default impl is for testing only, it will not preserve the window's own size changes. - fn expected_size(&self) -> Size { + fn expected_size(&self) -> Option> { + if self.is_fullscreen() { + return None; + } + let mut requested = self.requested_size().unwrap_or_default(); let current = self.size(); if requested.w == 0 { @@ -217,7 +222,7 @@ pub trait LayoutElement { if requested.h == 0 { requested.h = current.h; } - requested + Some(requested) } fn is_child_of(&self, parent: &Self) -> bool; @@ -2722,7 +2727,8 @@ impl Layout { if move_.is_floating { let floating_size = move_.tile.floating_window_size(); let win = move_.tile.window_mut(); - let mut size = floating_size.unwrap_or_else(|| win.expected_size()); + let mut size = + floating_size.unwrap_or_else(|| win.expected_size().unwrap_or_default()); // Make sure fixed-size through window rules keeps working. let min_size = win.min_size(); let max_size = win.max_size(); @@ -3479,7 +3485,9 @@ impl Layout { // Set the floating size so it takes into account any window resizing that // took place during the move. let mut tile = move_.tile; - tile.set_floating_window_size(tile.window().expected_size()); + if let Some(size) = tile.window().expected_size() { + tile.set_floating_window_size(size); + } mon.add_floating_tile(ws_idx, tile, Some(pos), true); } -- cgit