forge
Explore
Log in

Don't you dare go Hollow

floating: Don't use fullscreen size as floating size

Browse files at this commit

5488aaf69ffeb6ef504a4bec0b54a893155713cfIvan MolodetskikhParent: 96e493d
src/layout/floating.rsmodified+9 -6
@@ -375,8 +375,9 @@ impl<W: LayoutElement> FloatingSpace<W> {
375375 floating_size.unwrap_or_default()
376376 } else {
377377 // If the window wasn't fullscreen without a floating size (e.g. it was tiled before),
378- // ask for the current size.
379- floating_size.unwrap_or_else(|| win.expected_size())
378+ // ask for the current size. If the current size is unknown (the window was only ever
379+ // fullscreen until now), fall back to (0, 0).
380+ floating_size.unwrap_or_else(|| win.expected_size().unwrap_or_default())
380381 };
381382 // Make sure fixed-size through window rules keeps working.
382383 let min_size = win.min_size();
@@ -482,8 +483,10 @@ impl<W: LayoutElement> FloatingSpace<W> {
482483 }
483484 }
484485
485- // Store the floating size.
486- tile.set_floating_window_size(tile.window().expected_size());
486+ // Store the floating size if we have one.
487+ if let Some(size) = tile.window().expected_size() {
488+ tile.set_floating_window_size(size);
489+ }
487490
488491 let width = ColumnWidth::Fixed(tile.window_size().w);
489492 RemovedTile {
@@ -600,7 +603,7 @@ impl<W: LayoutElement> FloatingSpace<W> {
600603 win_width = ensure_min_max_size(win_width, min_size.w, max_size.w);
601604 win_width = max(1, win_width);
602605
603- let win_height = win.expected_size().h;
606+ let win_height = win.expected_size().unwrap_or_default().h;
604607 let win_height = ensure_min_max_size(win_height, min_size.h, max_size.h);
605608
606609 let win_size = Size::from((win_width, win_height));
@@ -626,7 +629,7 @@ impl<W: LayoutElement> FloatingSpace<W> {
626629 win_height = ensure_min_max_size(win_height, min_size.h, max_size.h);
627630 win_height = max(1, win_height);
628631
629- let win_width = win.expected_size().w;
632+ let win_width = win.expected_size().unwrap_or_default().w;
630633 let win_width = ensure_min_max_size(win_width, min_size.w, max_size.w);
631634
632635 let win_size = Size::from((win_width, win_height));
src/layout/mod.rsmodified+14 -6
@@ -197,7 +197,7 @@ pub trait LayoutElement {
197197 /// Size previously requested through [`LayoutElement::request_size()`].
198198 fn requested_size(&self) -> Option<Size<i32, Logical>>;
199199
200- /// Size that we expect this window has or will shortly have.
200+ /// Non-fullscreen size that we expect this window has or will shortly have.
201201 ///
202202 /// This can be different from [`requested_size()`](LayoutElement::requested_size()). For
203203 /// example, for floating windows this will generally return the current window size, rather
@@ -205,10 +205,15 @@ pub trait LayoutElement {
205205 /// size freely. But not always: if we just requested a floating window to resize and it hasn't
206206 /// responded to it yet, this will return the newly requested size.
207207 ///
208- /// This function should never return a 0 size component.
208+ /// This function should never return a 0 size component. `None` means there's no known
209+ /// expected size (for example, the window is fullscreen).
209210 ///
210211 /// The default impl is for testing only, it will not preserve the window's own size changes.
211- fn expected_size(&self) -> Size<i32, Logical> {
212+ fn expected_size(&self) -> Option<Size<i32, Logical>> {
213+ if self.is_fullscreen() {
214+ return None;
215+ }
216+
212217 let mut requested = self.requested_size().unwrap_or_default();
213218 let current = self.size();
214219 if requested.w == 0 {
@@ -217,7 +222,7 @@ pub trait LayoutElement {
217222 if requested.h == 0 {
218223 requested.h = current.h;
219224 }
220- requested
225+ Some(requested)
221226 }
222227
223228 fn is_child_of(&self, parent: &Self) -> bool;
@@ -2722,7 +2727,8 @@ impl<W: LayoutElement> Layout<W> {
27222727 if move_.is_floating {
27232728 let floating_size = move_.tile.floating_window_size();
27242729 let win = move_.tile.window_mut();
2725- let mut size = floating_size.unwrap_or_else(|| win.expected_size());
2730+ let mut size =
2731+ floating_size.unwrap_or_else(|| win.expected_size().unwrap_or_default());
27262732 // Make sure fixed-size through window rules keeps working.
27272733 let min_size = win.min_size();
27282734 let max_size = win.max_size();
@@ -3479,7 +3485,9 @@ impl<W: LayoutElement> Layout<W> {
34793485 // Set the floating size so it takes into account any window resizing that
34803486 // took place during the move.
34813487 let mut tile = move_.tile;
3482- tile.set_floating_window_size(tile.window().expected_size());
3488+ if let Some(size) = tile.window().expected_size() {
3489+ tile.set_floating_window_size(size);
3490+ }
34833491
34843492 mon.add_floating_tile(ws_idx, tile, Some(pos), true);
34853493 }
src/tests/floating.rsmodified+60 -0
@@ -725,3 +725,63 @@ fn interactive_move_restores_floating_size_when_set_to_floating() {
725725 @""
726726 );
727727 }
728+
729+#[test]
730+fn floating_doesnt_store_fullscreen_size() {
731+ let mut f = Fixture::new();
732+ f.add_output(1, (1920, 1080));
733+ f.add_output(2, (1280, 720));
734+
735+ // Open a window fullscreen.
736+ let id = f.add_client();
737+ let window = f.client(id).create_window();
738+ let surface = window.surface.clone();
739+ window.set_fullscreen(None);
740+ window.commit();
741+ f.roundtrip(id);
742+
743+ let window = f.client(id).window(&surface);
744+ window.attach_new_buffer();
745+ window.set_size(1920, 1080);
746+ window.ack_last_and_commit();
747+ f.double_roundtrip(id);
748+
749+ let _ = f.client(id).window(&surface).recent_configures();
750+
751+ // Make it floating.
752+ f.niri().layout.toggle_window_floating(None);
753+ f.double_roundtrip(id);
754+
755+ // This should request 0 × 0 to unfullscreen.
756+ assert_snapshot!(
757+ f.client(id).window(&surface).format_recent_configures(),
758+ @"size: 0 × 0, bounds: 1920 × 1080, states: [Activated]"
759+ );
760+
761+ // Without committing, make it tiling again. We never committed while floating, so there's no
762+ // floating size to remember.
763+ f.niri().layout.toggle_window_floating(None);
764+ f.double_roundtrip(id);
765+
766+ // This should request the tiled size.
767+ assert_snapshot!(
768+ f.client(id).window(&surface).format_recent_configures(),
769+ @"size: 1920 × 1048, bounds: 1888 × 1048, states: [Activated]"
770+ );
771+
772+ // Commit in response.
773+ let window = f.client(id).window(&surface);
774+ window.set_size(100, 100);
775+ window.ack_last_and_commit();
776+ f.roundtrip(id);
777+
778+ // Make the window floating again.
779+ f.niri().layout.toggle_window_floating(None);
780+ f.double_roundtrip(id);
781+
782+ // This shouldn't request any size change, particularly not the fullscreen size.
783+ assert_snapshot!(
784+ f.client(id).window(&surface).format_recent_configures(),
785+ @"size: 100 × 100, bounds: 1920 × 1080, states: [Activated]"
786+ );
787+}
src/tests/snapshots/niri__tests__window_opening__check_target_output_and_workspace@fsT-wfsAA-spA1.snapmodified+1 -1
@@ -12,4 +12,4 @@ size: 1280 × 720, bounds: 1248 × 688, states: [Fullscreen]
1212
1313 post-map configures:
1414 size: 0 × 0, bounds: 1280 × 720, states: []
15-size: 1 × 1, bounds: 1280 × 720, states: [Activated]
15+size: 0 × 0, bounds: 1280 × 720, states: [Activated]
src/tests/snapshots/niri__tests__window_opening__check_target_output_and_workspace@fsT-wfsAA-spA2.snapmodified+1 -1
@@ -12,4 +12,4 @@ size: 1280 × 720, bounds: 1248 × 688, states: [Fullscreen]
1212
1313 post-map configures:
1414 size: 0 × 0, bounds: 1280 × 720, states: []
15-size: 1 × 1, bounds: 1280 × 720, states: [Activated]
15+size: 0 × 0, bounds: 1280 × 720, states: [Activated]
src/tests/snapshots/niri__tests__window_opening__check_target_output_and_workspace@fsT-wfsAA-spB1.snapmodified+1 -1
@@ -12,4 +12,4 @@ size: 1280 × 720, bounds: 1280 × 720, states: [Fullscreen]
1212
1313 post-map configures:
1414 size: 0 × 0, bounds: 1280 × 720, states: []
15-size: 1 × 1, bounds: 1280 × 720, states: [Activated]
15+size: 0 × 0, bounds: 1280 × 720, states: [Activated]
src/tests/snapshots/niri__tests__window_opening__check_target_output_and_workspace@out1-fsT-wfsAA-spA1.snapmodified+1 -1
@@ -12,4 +12,4 @@ size: 1280 × 720, bounds: 1248 × 688, states: [Fullscreen]
1212
1313 post-map configures:
1414 size: 0 × 0, bounds: 1280 × 720, states: []
15-size: 1 × 1, bounds: 1280 × 720, states: [Activated]
15+size: 0 × 0, bounds: 1280 × 720, states: [Activated]
src/tests/snapshots/niri__tests__window_opening__check_target_output_and_workspace@out1-fsT-wfsAA-spA2.snapmodified+1 -1
@@ -12,4 +12,4 @@ size: 1280 × 720, bounds: 1248 × 688, states: [Fullscreen]
1212
1313 post-map configures:
1414 size: 0 × 0, bounds: 1280 × 720, states: []
15-size: 1 × 1, bounds: 1280 × 720, states: [Activated]
15+size: 0 × 0, bounds: 1280 × 720, states: [Activated]
src/tests/snapshots/niri__tests__window_opening__check_target_output_and_workspace@out1-fsT-wfsAA-spB1.snapmodified+1 -1
@@ -12,4 +12,4 @@ size: 1280 × 720, bounds: 1280 × 720, states: [Fullscreen]
1212
1313 post-map configures:
1414 size: 0 × 0, bounds: 1280 × 720, states: []
15-size: 1 × 1, bounds: 1280 × 720, states: [Activated]
15+size: 0 × 0, bounds: 1280 × 720, states: [Activated]
src/tests/snapshots/niri__tests__window_opening__check_target_output_and_workspace@out1-fsT-wfsAA-spB2.snapmodified+1 -1
@@ -12,4 +12,4 @@ size: 1280 × 720, bounds: 1280 × 720, states: [Fullscreen]
1212
1313 post-map configures:
1414 size: 0 × 0, bounds: 1280 × 720, states: []
15-size: 1 × 1, bounds: 1280 × 720, states: [Activated]
15+size: 0 × 0, bounds: 1280 × 720, states: [Activated]
src/tests/snapshots/niri__tests__window_opening__check_target_output_and_workspace@ws1-fsT-wfsAA-spA1.snapmodified+1 -1
@@ -12,4 +12,4 @@ size: 1280 × 720, bounds: 1248 × 688, states: [Fullscreen]
1212
1313 post-map configures:
1414 size: 0 × 0, bounds: 1280 × 720, states: []
15-size: 1 × 1, bounds: 1280 × 720, states: [Activated]
15+size: 0 × 0, bounds: 1280 × 720, states: [Activated]
src/tests/snapshots/niri__tests__window_opening__check_target_output_and_workspace@ws1-fsT-wfsAA-spA2.snapmodified+1 -1
@@ -12,4 +12,4 @@ size: 1280 × 720, bounds: 1248 × 688, states: [Fullscreen]
1212
1313 post-map configures:
1414 size: 0 × 0, bounds: 1280 × 720, states: []
15-size: 1 × 1, bounds: 1280 × 720, states: [Activated]
15+size: 0 × 0, bounds: 1280 × 720, states: [Activated]
src/tests/snapshots/niri__tests__window_opening__check_target_output_and_workspace@ws1-fsT-wfsAA-spB1.snapmodified+1 -1
@@ -12,4 +12,4 @@ size: 1280 × 720, bounds: 1280 × 720, states: [Fullscreen]
1212
1313 post-map configures:
1414 size: 0 × 0, bounds: 1280 × 720, states: []
15-size: 1 × 1, bounds: 1280 × 720, states: [Activated]
15+size: 0 × 0, bounds: 1280 × 720, states: [Activated]
src/tests/snapshots/niri__tests__window_opening__check_target_output_and_workspace@ws1-fsT-wfsAA-spB2.snapmodified+1 -1
@@ -12,4 +12,4 @@ size: 1280 × 720, bounds: 1280 × 720, states: [Fullscreen]
1212
1313 post-map configures:
1414 size: 0 × 0, bounds: 1280 × 720, states: []
15-size: 1 × 1, bounds: 1280 × 720, states: [Activated]
15+size: 0 × 0, bounds: 1280 × 720, states: [Activated]
src/tests/snapshots/niri__tests__window_opening__check_target_output_and_workspace@ws1-out1-fsT-wfsAA-spA1.snapmodified+1 -1
@@ -12,4 +12,4 @@ size: 1280 × 720, bounds: 1248 × 688, states: [Fullscreen]
1212
1313 post-map configures:
1414 size: 0 × 0, bounds: 1280 × 720, states: []
15-size: 1 × 1, bounds: 1280 × 720, states: [Activated]
15+size: 0 × 0, bounds: 1280 × 720, states: [Activated]
src/tests/snapshots/niri__tests__window_opening__check_target_output_and_workspace@ws1-out1-fsT-wfsAA-spA2.snapmodified+1 -1
@@ -12,4 +12,4 @@ size: 1280 × 720, bounds: 1248 × 688, states: [Fullscreen]
1212
1313 post-map configures:
1414 size: 0 × 0, bounds: 1280 × 720, states: []
15-size: 1 × 1, bounds: 1280 × 720, states: [Activated]
15+size: 0 × 0, bounds: 1280 × 720, states: [Activated]
src/tests/snapshots/niri__tests__window_opening__check_target_output_and_workspace@ws1-out1-fsT-wfsAA-spB1.snapmodified+1 -1
@@ -12,4 +12,4 @@ size: 1280 × 720, bounds: 1280 × 720, states: [Fullscreen]
1212
1313 post-map configures:
1414 size: 0 × 0, bounds: 1280 × 720, states: []
15-size: 1 × 1, bounds: 1280 × 720, states: [Activated]
15+size: 0 × 0, bounds: 1280 × 720, states: [Activated]
src/tests/snapshots/niri__tests__window_opening__check_target_output_and_workspace@ws1-out1-fsT-wfsAA-spB2.snapmodified+1 -1
@@ -12,4 +12,4 @@ size: 1280 × 720, bounds: 1280 × 720, states: [Fullscreen]
1212
1313 post-map configures:
1414 size: 0 × 0, bounds: 1280 × 720, states: []
15-size: 1 × 1, bounds: 1280 × 720, states: [Activated]
15+size: 0 × 0, bounds: 1280 × 720, states: [Activated]
src/tests/snapshots/niri__tests__window_opening__check_target_output_and_workspace@ws1-out2-fsT-wfsAA-spA1.snapmodified+1 -1
@@ -12,4 +12,4 @@ size: 1280 × 720, bounds: 1248 × 688, states: [Fullscreen]
1212
1313 post-map configures:
1414 size: 0 × 0, bounds: 1280 × 720, states: []
15-size: 1 × 1, bounds: 1280 × 720, states: [Activated]
15+size: 0 × 0, bounds: 1280 × 720, states: [Activated]
src/tests/snapshots/niri__tests__window_opening__check_target_output_and_workspace@ws1-out2-fsT-wfsAA-spA2.snapmodified+1 -1
@@ -12,4 +12,4 @@ size: 1280 × 720, bounds: 1248 × 688, states: [Fullscreen]
1212
1313 post-map configures:
1414 size: 0 × 0, bounds: 1280 × 720, states: []
15-size: 1 × 1, bounds: 1280 × 720, states: [Activated]
15+size: 0 × 0, bounds: 1280 × 720, states: [Activated]
src/tests/snapshots/niri__tests__window_opening__check_target_output_and_workspace@ws1-out2-fsT-wfsAA-spB1.snapmodified+1 -1
@@ -12,4 +12,4 @@ size: 1280 × 720, bounds: 1280 × 720, states: [Fullscreen]
1212
1313 post-map configures:
1414 size: 0 × 0, bounds: 1280 × 720, states: []
15-size: 1 × 1, bounds: 1280 × 720, states: [Activated]
15+size: 0 × 0, bounds: 1280 × 720, states: [Activated]
src/tests/snapshots/niri__tests__window_opening__check_target_output_and_workspace@ws1-out2-fsT-wfsAA-spB2.snapmodified+1 -1
@@ -12,4 +12,4 @@ size: 1280 × 720, bounds: 1280 × 720, states: [Fullscreen]
1212
1313 post-map configures:
1414 size: 0 × 0, bounds: 1280 × 720, states: []
15-size: 1 × 1, bounds: 1280 × 720, states: [Activated]
15+size: 0 × 0, bounds: 1280 × 720, states: [Activated]
src/window/mapped.rsmodified+33 -14
@@ -829,8 +829,9 @@ impl LayoutElement for Mapped {
829829 self.toplevel().with_pending_state(|state| state.size)
830830 }
831831
832- fn expected_size(&self) -> Size<i32, Logical> {
833- let current_size = self.window.geometry().size;
832+ fn expected_size(&self) -> Option<Size<i32, Logical>> {
833+ // We can only use current size if it's not fullscreen.
834+ let current_size = (!self.is_fullscreen()).then(|| self.window.geometry().size);
834835
835836 // Check if we should be using the current window size.
836837 //
@@ -849,12 +850,17 @@ impl LayoutElement for Mapped {
849850 return current_size;
850851 }
851852
852- let pending_size = with_toplevel_role(self.toplevel(), |role| {
853+ let pending = with_toplevel_role(self.toplevel(), |role| {
853854 // If we have a server-pending size change that we haven't sent yet, use that size.
854855 if let Some(server_pending) = &role.server_pending {
855856 let current_server = role.current_server_state();
856857 if server_pending.size != current_server.size {
857- return Some(server_pending.size.unwrap_or_default());
858+ return Some((
859+ server_pending.size.unwrap_or_default(),
860+ server_pending
861+ .states
862+ .contains(xdg_toplevel::State::Fullscreen),
863+ ));
858864 }
859865 }
860866
@@ -871,23 +877,36 @@ impl LayoutElement for Mapped {
871877
872878 if let Some(current_serial) = role.current_serial {
873879 if !current_serial.is_no_older_than(&last_serial) {
874- return Some(last_sent.size.unwrap_or_default());
880+ return Some((
881+ last_sent.size.unwrap_or_default(),
882+ last_sent.states.contains(xdg_toplevel::State::Fullscreen),
883+ ));
875884 }
876885 }
877886
878887 None
879888 });
880889
881- // If we have no pending size change (size change that the window hasn't committed to), or
882- // if some component of the pending size change is zero, use the current window size.
883- let mut size = pending_size.unwrap_or_default();
884- if size.w == 0 {
885- size.w = current_size.w;
886- }
887- if size.h == 0 {
888- size.h = current_size.h;
890+ if let Some((mut size, fullscreen)) = pending {
891+ // If the pending change is fullscreen, we can't use that size.
892+ if fullscreen {
893+ return None;
894+ }
895+
896+ // If some component of the pending size is zero, substitute it with the current window
897+ // size. But only if the current size is not fullscreen.
898+ if size.w == 0 {
899+ size.w = current_size?.w;
900+ }
901+ if size.h == 0 {
902+ size.h = current_size?.h;
903+ }
904+
905+ Some(size)
906+ } else {
907+ // No pending size, return the current size if it's non-fullscreen.
908+ current_size
889909 }
890- size
891910 }
892911
893912 fn is_child_of(&self, parent: &Self) -> bool {