From 309bf1348c67a81b99e7b3feef461584ca7cd423 Mon Sep 17 00:00:00 2001 From: Ivan Molodetskikh Date: Mon, 23 Dec 2024 08:52:45 +0300 Subject: floating: Improve expected size requests to avoid (0, 0) and duplicates --- src/layout/mod.rs | 20 ++++++++++++++++---- 1 file changed, 16 insertions(+), 4 deletions(-) (limited to 'src/layout/mod.rs') diff --git a/src/layout/mod.rs b/src/layout/mod.rs index 8e86c0ca..bc2716af 100644 --- a/src/layout/mod.rs +++ b/src/layout/mod.rs @@ -197,15 +197,27 @@ pub trait LayoutElement { /// Size previously requested through [`LayoutElement::request_size()`]. fn requested_size(&self) -> Option>; - /// Size that we will request of this window. + /// 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 /// than the last size that we requested, since we want floating windows to be able to change /// 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. - fn size_to_request(&self) -> Size { - self.requested_size().unwrap_or_else(|| self.size()) + /// + /// This function should never return a 0 size component. + /// + /// The default impl is for testing only, it will not preserve the window's own size changes. + fn expected_size(&self) -> Size { + let mut requested = self.requested_size().unwrap_or_default(); + let current = self.size(); + if requested.w == 0 { + requested.w = current.w; + } + if requested.h == 0 { + requested.h = current.h; + } + requested } fn is_child_of(&self, parent: &Self) -> bool; @@ -1155,7 +1167,7 @@ impl Layout { // Update the floating size in case the window resizes itself during an interactive // move. - let floating_size = move_.tile.window().size_to_request(); + let floating_size = move_.tile.window().expected_size(); move_.tile.set_floating_window_size(floating_size); return; -- cgit