forge
Explore
Log in

Don't you dare go Hollow

layout: Pass and store view_size on a Tile

Browse files at this commit

28b78a563b3a2275874c8c4ae802be074c8b51b2Ivan MolodetskikhParent: 2f380de
niri-visual-tests/src/cases/tile.rsmodified+13 -4
@@ -55,6 +55,8 @@ impl Tile {
5555 }
5656
5757 pub fn with_window(args: Args, window: TestWindow) -> Self {
58+ let Args { size, clock } = args;
59+
5860 let options = Options {
5961 focus_ring: niri_config::FocusRing {
6062 off: true,
@@ -69,10 +71,15 @@ impl Tile {
6971 ..Default::default()
7072 };
7173
72- let mut tile =
73- niri::layout::tile::Tile::new(window.clone(), 1., args.clock, Rc::new(options));
74+ let mut tile = niri::layout::tile::Tile::new(
75+ window.clone(),
76+ size.to_f64(),
77+ 1.,
78+ clock,
79+ Rc::new(options),
80+ );
7481
75- tile.request_tile_size(args.size.to_f64(), false, None);
82+ tile.request_tile_size(size.to_f64(), false, None);
7683 window.communicate();
7784
7885 Self { window, tile }
@@ -81,8 +88,10 @@ impl Tile {
8188
8289 impl TestCase for Tile {
8390 fn resize(&mut self, width: i32, height: i32) {
91+ let size = Size::from((width, height)).to_f64();
8492 self.tile
85- .request_tile_size(Size::from((width, height)).to_f64(), false, None);
93+ .update_config(size, 1., self.tile.options().clone());
94+ self.tile.request_tile_size(size, false, None);
8695 self.window.communicate();
8796 }
8897
src/layout/floating.rsmodified+27 -14
@@ -50,6 +50,9 @@ pub struct FloatingSpace<W: LayoutElement> {
5050 /// Windows in the closing animation.
5151 closing_windows: Vec<ClosingWindow>,
5252
53+ /// View size for this space.
54+ view_size: Size<f64, Logical>,
55+
5356 /// Working area for this space.
5457 working_area: Rectangle<f64, Logical>,
5558
@@ -193,6 +196,7 @@ impl Data {
193196
194197 impl<W: LayoutElement> FloatingSpace<W> {
195198 pub fn new(
199+ view_size: Size<f64, Logical>,
196200 working_area: Rectangle<f64, Logical>,
197201 scale: f64,
198202 clock: Clock,
@@ -204,6 +208,7 @@ impl<W: LayoutElement> FloatingSpace<W> {
204208 active_window_id: None,
205209 interactive_resize: None,
206210 closing_windows: Vec::new(),
211+ view_size,
207212 working_area,
208213 scale,
209214 clock,
@@ -213,16 +218,18 @@ impl<W: LayoutElement> FloatingSpace<W> {
213218
214219 pub fn update_config(
215220 &mut self,
221+ view_size: Size<f64, Logical>,
216222 working_area: Rectangle<f64, Logical>,
217223 scale: f64,
218224 options: Rc<Options>,
219225 ) {
220226 for (tile, data) in zip(&mut self.tiles, &mut self.data) {
221- tile.update_config(scale, options.clone());
227+ tile.update_config(view_size, scale, options.clone());
222228 data.update(tile);
223229 data.update_config(working_area);
224230 }
225231
232+ self.view_size = view_size;
226233 self.working_area = working_area;
227234 self.scale = scale;
228235 self.options = options;
@@ -371,7 +378,7 @@ impl<W: LayoutElement> FloatingSpace<W> {
371378 }
372379
373380 fn add_tile_at(&mut self, mut idx: usize, mut tile: Tile<W>, activate: bool) {
374- tile.update_config(self.scale, self.options.clone());
381+ tile.update_config(self.view_size, self.scale, self.options.clone());
375382
376383 // Restore the previous floating window size, and in case the tile is fullscreen,
377384 // unfullscreen it.
@@ -602,7 +609,7 @@ impl<W: LayoutElement> FloatingSpace<W> {
602609 };
603610 let idx = self.idx_of(&id).unwrap();
604611
605- let view_size = self.working_area.size.w;
612+ let available_size = self.working_area.size.w;
606613
607614 let tile = &mut self.tiles[idx];
608615 let preset_idx = if let Some(idx) = tile.floating_preset_width_idx {
@@ -615,7 +622,7 @@ impl<W: LayoutElement> FloatingSpace<W> {
615622 .preset_column_widths
616623 .iter()
617624 .position(|preset| {
618- let resolved = preset.resolve_no_gaps(&self.options, view_size);
625+ let resolved = preset.resolve_no_gaps(&self.options, available_size);
619626 match resolved {
620627 // Some allowance for fractional scaling purposes.
621628 ResolvedSize::Tile(resolved) => current_tile + 1. < resolved,
@@ -643,7 +650,7 @@ impl<W: LayoutElement> FloatingSpace<W> {
643650 };
644651 let idx = self.idx_of(&id).unwrap();
645652
646- let view_size = self.working_area.size.h;
653+ let available_size = self.working_area.size.h;
647654
648655 let tile = &mut self.tiles[idx];
649656 let preset_idx = if let Some(idx) = tile.floating_preset_height_idx {
@@ -656,7 +663,7 @@ impl<W: LayoutElement> FloatingSpace<W> {
656663 .preset_window_heights
657664 .iter()
658665 .position(|preset| {
659- let resolved = resolve_preset_size(*preset, view_size);
666+ let resolved = resolve_preset_size(*preset, available_size);
660667 match resolved {
661668 // Some allowance for fractional scaling purposes.
662669 ResolvedSize::Tile(resolved) => current_tile + 1. < resolved,
@@ -687,7 +694,7 @@ impl<W: LayoutElement> FloatingSpace<W> {
687694 let tile = &mut self.tiles[idx];
688695 tile.floating_preset_width_idx = None;
689696
690- let view_size = self.working_area.size.w;
697+ let available_size = self.working_area.size.w;
691698 let win = tile.window();
692699 let current_window = win.expected_size().unwrap_or_else(|| win.size()).w;
693700 let current_tile = tile.tile_expected_or_current_size().w;
@@ -699,14 +706,14 @@ impl<W: LayoutElement> FloatingSpace<W> {
699706 SizeChange::SetFixed(win_width) => f64::from(win_width),
700707 SizeChange::SetProportion(prop) => {
701708 let prop = (prop / 100.).clamp(0., MAX_F);
702- let tile_width = view_size * prop;
709+ let tile_width = available_size * prop;
703710 tile.window_width_for_tile_width(tile_width)
704711 }
705712 SizeChange::AdjustFixed(delta) => f64::from(current_window.saturating_add(delta)),
706713 SizeChange::AdjustProportion(delta) => {
707- let current_prop = current_tile / view_size;
714+ let current_prop = current_tile / available_size;
708715 let prop = (current_prop + delta / 100.).clamp(0., MAX_F);
709- let tile_width = view_size * prop;
716+ let tile_width = available_size * prop;
710717 tile.window_width_for_tile_width(tile_width)
711718 }
712719 };
@@ -734,7 +741,7 @@ impl<W: LayoutElement> FloatingSpace<W> {
734741 let tile = &mut self.tiles[idx];
735742 tile.floating_preset_width_idx = None;
736743
737- let view_size = self.working_area.size.h;
744+ let available_size = self.working_area.size.h;
738745 let win = tile.window();
739746 let current_window = win.expected_size().unwrap_or_else(|| win.size()).h;
740747 let current_tile = tile.tile_expected_or_current_size().h;
@@ -746,14 +753,14 @@ impl<W: LayoutElement> FloatingSpace<W> {
746753 SizeChange::SetFixed(win_height) => f64::from(win_height),
747754 SizeChange::SetProportion(prop) => {
748755 let prop = (prop / 100.).clamp(0., MAX_F);
749- let tile_height = view_size * prop;
756+ let tile_height = available_size * prop;
750757 tile.window_height_for_tile_height(tile_height)
751758 }
752759 SizeChange::AdjustFixed(delta) => f64::from(current_window.saturating_add(delta)),
753760 SizeChange::AdjustProportion(delta) => {
754- let current_prop = current_tile / view_size;
761+ let current_prop = current_tile / available_size;
755762 let prop = (current_prop + delta / 100.).clamp(0., MAX_F);
756- let tile_height = view_size * prop;
763+ let tile_height = available_size * prop;
757764 tile.window_height_for_tile_height(tile_height)
758765 }
759766 };
@@ -1095,6 +1102,11 @@ impl<W: LayoutElement> FloatingSpace<W> {
10951102 }
10961103 }
10971104
1105+ #[cfg(test)]
1106+ pub fn view_size(&self) -> Size<f64, Logical> {
1107+ self.view_size
1108+ }
1109+
10981110 #[cfg(test)]
10991111 pub fn working_area(&self) -> Rectangle<f64, Logical> {
11001112 self.working_area
@@ -1123,6 +1135,7 @@ impl<W: LayoutElement> FloatingSpace<W> {
11231135
11241136 for (i, (tile, data)) in zip(&self.tiles, &self.data).enumerate() {
11251137 assert!(Rc::ptr_eq(&self.options, &tile.options));
1138+ assert_eq!(self.view_size, tile.view_size());
11261139 assert_eq!(self.clock, tile.clock);
11271140 assert_eq!(self.scale, tile.scale());
11281141 tile.verify_invariants();
src/layout/mod.rsmodified+6 -0
@@ -2577,8 +2577,10 @@ impl<W: LayoutElement> Layout<W> {
25772577 let options = Rc::new(options);
25782578
25792579 if let Some(InteractiveMoveState::Moving(move_)) = &mut self.interactive_move {
2580+ let view_size = output_size(&move_.output);
25802581 let scale = move_.output.current_scale().fractional_scale();
25812582 move_.tile.update_config(
2583+ view_size,
25822584 scale,
25832585 Rc::new(Options::clone(&options).adjusted_for_scale(scale)),
25842586 );
@@ -3261,8 +3263,10 @@ impl<W: LayoutElement> Layout<W> {
32613263 output.current_transform(),
32623264 );
32633265
3266+ let view_size = output_size(&output);
32643267 let scale = output.current_scale().fractional_scale();
32653268 tile.update_config(
3269+ view_size,
32663270 scale,
32673271 Rc::new(Options::clone(&self.options).adjusted_for_scale(scale)),
32683272 );
@@ -3324,8 +3328,10 @@ impl<W: LayoutElement> Layout<W> {
33243328 output.current_scale(),
33253329 output.current_transform(),
33263330 );
3331+ let view_size = output_size(&output);
33273332 let scale = output.current_scale().fractional_scale();
33283333 move_.tile.update_config(
3334+ view_size,
33293335 scale,
33303336 Rc::new(Options::clone(&self.options).adjusted_for_scale(scale)),
33313337 );
src/layout/scrolling.rsmodified+4 -3
@@ -2933,7 +2933,7 @@ impl<W: LayoutElement> Column<W> {
29332933 }
29342934
29352935 for (tile, data) in zip(&mut self.tiles, &mut self.data) {
2936- tile.update_config(scale, options.clone());
2936+ tile.update_config(view_size, scale, options.clone());
29372937 data.update(tile);
29382938 }
29392939
@@ -3033,7 +3033,7 @@ impl<W: LayoutElement> Column<W> {
30333033 }
30343034
30353035 fn add_tile_at(&mut self, idx: usize, mut tile: Tile<W>, animate: bool) {
3036- tile.update_config(self.scale, self.options.clone());
3036+ tile.update_config(self.view_size, self.scale, self.options.clone());
30373037
30383038 // Inserting a tile pushes down all tiles below it, but also in always-centering mode it
30393039 // will affect the X position of all tiles in the column.
@@ -3096,7 +3096,7 @@ impl<W: LayoutElement> Column<W> {
30963096
30973097 fn update_tile_sizes_with_transaction(&mut self, animate: bool, transaction: Transaction) {
30983098 if self.is_fullscreen {
3099- self.tiles[0].request_fullscreen(self.view_size);
3099+ self.tiles[0].request_fullscreen();
31003100 return;
31013101 }
31023102
@@ -3787,6 +3787,7 @@ impl<W: LayoutElement> Column<W> {
37873787 assert_eq!(self.clock, tile.clock);
37883788 assert_eq!(self.scale, tile.scale());
37893789 assert_eq!(self.is_fullscreen, tile.window().is_pending_fullscreen());
3790+ assert_eq!(self.view_size, tile.view_size());
37903791 tile.verify_invariants();
37913792
37923793 let mut data2 = *data;
src/layout/tile.rsmodified+48 -23
@@ -48,9 +48,6 @@ pub struct Tile<W: LayoutElement> {
4848 /// The black backdrop for fullscreen windows.
4949 fullscreen_backdrop: SolidColorBuffer,
5050
51- /// The size we were requested to fullscreen into.
52- fullscreen_size: Size<f64, Logical>,
53-
5451 /// Whether the tile should float upon unfullscreening.
5552 pub(super) unfullscreen_to_floating: bool,
5653
@@ -94,6 +91,11 @@ pub struct Tile<W: LayoutElement> {
9491 /// Extra damage for clipped surface corner radius changes.
9592 rounded_corner_damage: RoundedCornerDamage,
9693
94+ /// The view size for the tile's workspace.
95+ ///
96+ /// Used as the fullscreen target size.
97+ view_size: Size<f64, Logical>,
98+
9799 /// Scale of the output the tile is on (and rounds its sizes to).
98100 scale: f64,
99101
@@ -134,18 +136,24 @@ struct MoveAnimation {
134136 }
135137
136138 impl<W: LayoutElement> Tile<W> {
137- pub fn new(window: W, scale: f64, clock: Clock, options: Rc<Options>) -> Self {
139+ pub fn new(
140+ window: W,
141+ view_size: Size<f64, Logical>,
142+ scale: f64,
143+ clock: Clock,
144+ options: Rc<Options>,
145+ ) -> Self {
138146 let rules = window.rules();
139147 let border_config = rules.border.resolve_against(options.border);
140148 let focus_ring_config = rules.focus_ring.resolve_against(options.focus_ring.into());
149+ let is_fullscreen = window.is_fullscreen();
141150
142151 Self {
143152 window,
144153 border: FocusRing::new(border_config.into()),
145154 focus_ring: FocusRing::new(focus_ring_config.into()),
146- is_fullscreen: false, // FIXME: up-to-date fullscreen right away, but we need size.
147- fullscreen_backdrop: SolidColorBuffer::new((0., 0.), [0., 0., 0., 1.]),
148- fullscreen_size: Default::default(),
155+ is_fullscreen,
156+ fullscreen_backdrop: SolidColorBuffer::new(view_size, [0., 0., 0., 1.]),
149157 unfullscreen_to_floating: false,
150158 floating_window_size: None,
151159 floating_pos: None,
@@ -158,13 +166,19 @@ impl<W: LayoutElement> Tile<W> {
158166 interactive_move_offset: Point::from((0., 0.)),
159167 unmap_snapshot: None,
160168 rounded_corner_damage: Default::default(),
169+ view_size,
161170 scale,
162171 clock,
163172 options,
164173 }
165174 }
166175
167- pub fn update_config(&mut self, scale: f64, options: Rc<Options>) {
176+ pub fn update_config(
177+ &mut self,
178+ view_size: Size<f64, Logical>,
179+ scale: f64,
180+ options: Rc<Options>,
181+ ) {
168182 // If preset widths or heights changed, clear our stored preset index.
169183 if self.options.preset_column_widths != options.preset_column_widths {
170184 self.floating_preset_width_idx = None;
@@ -173,6 +187,7 @@ impl<W: LayoutElement> Tile<W> {
173187 self.floating_preset_height_idx = None;
174188 }
175189
190+ self.view_size = view_size;
176191 self.scale = scale;
177192 self.options = options;
178193
@@ -185,6 +200,8 @@ impl<W: LayoutElement> Tile<W> {
185200 .focus_ring
186201 .resolve_against(self.options.focus_ring.into());
187202 self.focus_ring.update_config(focus_ring_config.into());
203+
204+ self.fullscreen_backdrop.resize(view_size);
188205 }
189206
190207 pub fn update_shaders(&mut self) {
@@ -193,10 +210,7 @@ impl<W: LayoutElement> Tile<W> {
193210 }
194211
195212 pub fn update_window(&mut self) {
196- // FIXME: remove when we can get a fullscreen size right away.
197- if self.fullscreen_size != Size::from((0., 0.)) {
198- self.is_fullscreen = self.window.is_fullscreen();
199- }
213+ self.is_fullscreen = self.window.is_fullscreen();
200214
201215 if let Some(animate_from) = self.window.take_animation_snapshot() {
202216 let size_from = if let Some(resize) = self.resize_animation.take() {
@@ -448,7 +462,7 @@ impl<W: LayoutElement> Tile<W> {
448462 // In fullscreen, center the window in the given size.
449463 if self.is_fullscreen {
450464 let window_size = self.window_size();
451- let target_size = self.fullscreen_size;
465+ let target_size = self.view_size;
452466
453467 // Windows aren't supposed to be larger than the fullscreen size, but in case we get
454468 // one, leave it at the top-left as usual.
@@ -478,8 +492,8 @@ impl<W: LayoutElement> Tile<W> {
478492 if self.is_fullscreen {
479493 // Normally we'd just return the fullscreen size here, but this makes things a bit
480494 // nicer if a fullscreen window is bigger than the fullscreen size for some reason.
481- size.w = f64::max(size.w, self.fullscreen_size.w);
482- size.h = f64::max(size.h, self.fullscreen_size.h);
495+ size.w = f64::max(size.w, self.view_size.w);
496+ size.h = f64::max(size.h, self.view_size.h);
483497 return size;
484498 }
485499
@@ -497,8 +511,8 @@ impl<W: LayoutElement> Tile<W> {
497511 if self.is_fullscreen {
498512 // Normally we'd just return the fullscreen size here, but this makes things a bit
499513 // nicer if a fullscreen window is bigger than the fullscreen size for some reason.
500- size.w = f64::max(size.w, self.fullscreen_size.w);
501- size.h = f64::max(size.h, self.fullscreen_size.h);
514+ size.w = f64::max(size.w, self.view_size.w);
515+ size.h = f64::max(size.h, self.view_size.h);
502516 return size;
503517 }
504518
@@ -550,8 +564,8 @@ impl<W: LayoutElement> Tile<W> {
550564 if self.is_fullscreen {
551565 // Normally we'd just return the fullscreen size here, but this makes things a bit
552566 // nicer if a fullscreen window is bigger than the fullscreen size for some reason.
553- size.w = f64::max(size.w, self.fullscreen_size.w);
554- size.h = f64::max(size.h, self.fullscreen_size.h);
567+ size.w = f64::max(size.w, self.view_size.w);
568+ size.h = f64::max(size.h, self.view_size.h);
555569 return size;
556570 }
557571
@@ -632,10 +646,9 @@ impl<W: LayoutElement> Tile<W> {
632646 }
633647 }
634648
635- pub fn request_fullscreen(&mut self, size: Size<f64, Logical>) {
636- self.fullscreen_backdrop.resize(size);
637- self.fullscreen_size = size;
638- self.window.request_fullscreen(size.to_i32_round());
649+ pub fn request_fullscreen(&mut self) {
650+ self.window
651+ .request_fullscreen(self.view_size.to_i32_round());
639652 }
640653
641654 pub fn min_size(&self) -> Size<f64, Logical> {
@@ -982,10 +995,22 @@ impl<W: LayoutElement> Tile<W> {
982995 self.unmap_snapshot.take()
983996 }
984997
998+ pub fn options(&self) -> &Rc<Options> {
999+ &self.options
1000+ }
1001+
1002+ #[cfg(test)]
1003+ pub fn view_size(&self) -> Size<f64, Logical> {
1004+ self.view_size
1005+ }
1006+
9851007 #[cfg(test)]
9861008 pub fn verify_invariants(&self) {
9871009 use approx::assert_abs_diff_eq;
9881010
1011+ assert_eq!(self.is_fullscreen, self.window.is_fullscreen());
1012+ assert_eq!(self.fullscreen_backdrop.size(), self.view_size);
1013+
9891014 let scale = self.scale;
9901015 let size = self.tile_size();
9911016 let rounded = size.to_physical_precise_round(scale).to_logical(scale);
src/layout/workspace.rsmodified+7 -0
@@ -203,6 +203,7 @@ impl<W: LayoutElement> Workspace<W> {
203203 );
204204
205205 let floating = FloatingSpace::new(
206+ view_size,
206207 working_area,
207208 scale.fractional_scale(),
208209 clock.clone(),
@@ -255,6 +256,7 @@ impl<W: LayoutElement> Workspace<W> {
255256 );
256257
257258 let floating = FloatingSpace::new(
259+ view_size,
258260 working_area,
259261 scale.fractional_scale(),
260262 clock.clone(),
@@ -337,6 +339,7 @@ impl<W: LayoutElement> Workspace<W> {
337339 );
338340
339341 self.floating.update_config(
342+ self.view_size,
340343 self.working_area,
341344 self.scale.fractional_scale(),
342345 options.clone(),
@@ -467,6 +470,7 @@ impl<W: LayoutElement> Workspace<W> {
467470 self.options.clone(),
468471 );
469472 self.floating.update_config(
473+ size,
470474 working_area,
471475 scale.fractional_scale(),
472476 self.options.clone(),
@@ -494,6 +498,7 @@ impl<W: LayoutElement> Workspace<W> {
494498 ) {
495499 let mut tile = Tile::new(
496500 window,
501+ self.view_size,
497502 self.scale.fractional_scale(),
498503 self.clock.clone(),
499504 self.options.clone(),
@@ -562,6 +567,7 @@ impl<W: LayoutElement> Workspace<W> {
562567 ) {
563568 let mut tile = Tile::new(
564569 window,
570+ self.view_size,
565571 self.scale.fractional_scale(),
566572 self.clock.clone(),
567573 self.options.clone(),
@@ -1471,6 +1477,7 @@ impl<W: LayoutElement> Workspace<W> {
14711477 assert!(Rc::ptr_eq(&self.options, self.scrolling.options()));
14721478 self.scrolling.verify_invariants(self.working_area);
14731479
1480+ assert_eq!(self.view_size, self.floating.view_size());
14741481 assert_eq!(self.working_area, self.floating.working_area());
14751482 assert_eq!(&self.clock, self.floating.clock());
14761483 assert!(Rc::ptr_eq(&self.options, self.floating.options()));