forge
Explore
Log in

Don't you dare go Hollow

Always clamp non-auto window height with >1 windows in column

Browse files at this commit

43578e21b154345a8564a3eba55f4fe7aa7d3b3cIvan MolodetskikhParent: 55a798b
niri-visual-tests/src/test_window.rsmodified+5 -1
@@ -87,7 +87,7 @@ impl TestWindow {
87 87
88 let mut new_size = inner.size;88 let mut new_size = inner.size;
89 89
90- if let Some(size) = inner.requested_size.take() {90+ if let Some(size) = inner.requested_size {
91 assert!(size.w >= 0);91 assert!(size.w >= 0);
92 assert!(size.h >= 0);92 assert!(size.h >= 0);
93 93
@@ -236,6 +236,10 @@ impl LayoutElement for TestWindow {
236 self.inner.borrow().pending_fullscreen236 self.inner.borrow().pending_fullscreen
237 }237 }
238 238
239+ fn requested_size(&self) -> Option<Size<i32, Logical>> {
240+ self.inner.borrow().requested_size
241+ }
242+
239 fn refresh(&self) {}243 fn refresh(&self) {}
240 244
241 fn rules(&self) -> &ResolvedWindowRules {245 fn rules(&self) -> &ResolvedWindowRules {
src/layout/mod.rsmodified+38 -1
@@ -189,6 +189,9 @@ pub trait LayoutElement {
189 /// This *will* switch immediately after a [`LayoutElement::request_fullscreen()`] call.189 /// This *will* switch immediately after a [`LayoutElement::request_fullscreen()`] call.
190 fn is_pending_fullscreen(&self) -> bool;190 fn is_pending_fullscreen(&self) -> bool;
191 191
192+ /// Size previously requested through [`LayoutElement::request_size()`].
193+ fn requested_size(&self) -> Option<Size<i32, Logical>>;
194+
192 fn rules(&self) -> &ResolvedWindowRules;195 fn rules(&self) -> &ResolvedWindowRules;
193 196
194 /// Runs periodic clean-up tasks.197 /// Runs periodic clean-up tasks.
@@ -2777,7 +2780,7 @@ mod tests {
2777 }2780 }
2778 2781
2779 fn communicate(&self) -> bool {2782 fn communicate(&self) -> bool {
2780- if let Some(size) = self.0.requested_size.take() {2783+ if let Some(size) = self.0.requested_size.get() {
2781 assert!(size.w >= 0);2784 assert!(size.w >= 0);
2782 assert!(size.h >= 0);2785 assert!(size.h >= 0);
2783 2786
@@ -2887,6 +2890,10 @@ mod tests {
2887 self.0.pending_fullscreen.get()2890 self.0.pending_fullscreen.get()
2888 }2891 }
2889 2892
2893+ fn requested_size(&self) -> Option<Size<i32, Logical>> {
2894+ self.0.requested_size.get()
2895+ }
2896+
2890 fn refresh(&self) {}2897 fn refresh(&self) {}
2891 2898
2892 fn rules(&self) -> &ResolvedWindowRules {2899 fn rules(&self) -> &ResolvedWindowRules {
@@ -4696,6 +4703,36 @@ mod tests {
4696 check_ops(&ops);4703 check_ops(&ops);
4697 }4704 }
4698 4705
4706+ #[test]
4707+ fn fixed_height_takes_max_non_auto_into_account() {
4708+ let ops = [
4709+ Op::AddOutput(1),
4710+ Op::AddWindow {
4711+ id: 0,
4712+ bbox: Rectangle::from_loc_and_size((0, 0), (100, 200)),
4713+ min_max_size: Default::default(),
4714+ },
4715+ Op::SetWindowHeight { id: Some(0), change: SizeChange::SetFixed(704) },
4716+ Op::AddWindow {
4717+ id: 1,
4718+ bbox: Rectangle::from_loc_and_size((0, 0), (100, 200)),
4719+ min_max_size: Default::default(),
4720+ },
4721+ Op::ConsumeOrExpelWindowLeft,
4722+ ];
4723+
4724+ let options = Options {
4725+ border: niri_config::Border {
4726+ off: false,
4727+ width: niri_config::FloatOrInt(4.),
4728+ ..Default::default()
4729+ },
4730+ gaps: 0.,
4731+ ..Default::default()
4732+ };
4733+ check_ops_with_options(options, &ops);
4734+ }
4735+
4699 fn arbitrary_spacing() -> impl Strategy<Value = f64> {4736 fn arbitrary_spacing() -> impl Strategy<Value = f64> {
4700 // Give equal weight to:4737 // Give equal weight to:
4701 // - 0: the element is disabled4738 // - 0: the element is disabled
src/layout/workspace.rsmodified+64 -4
@@ -3272,12 +3272,45 @@ impl<W: LayoutElement> Column<W> {
3272 let width = f64::max(f64::min(width, max_width), min_width);3272 let width = f64::max(f64::min(width, max_width), min_width);
3273 let height = self.working_area.size.h;3273 let height = self.working_area.size.h;
3274 3274
3275+ // If there are multiple windows in a column, clamp the non-auto window's height according
3276+ // to other windows' min sizes.
3277+ let mut max_non_auto_window_height = None;
3278+ if self.tiles.len() > 1 {
3279+ if let Some(non_auto_idx) = self
3280+ .data
3281+ .iter()
3282+ .position(|data| !matches!(data.height, WindowHeight::Auto { .. }))
3283+ {
3284+ let min_height_taken = min_size
3285+ .iter()
3286+ .enumerate()
3287+ .filter(|(idx, _)| *idx != non_auto_idx)
3288+ .map(|(_, min_size)| min_size.h + self.options.gaps)
3289+ .sum::<f64>();
3290+
3291+ let tile = &self.tiles[non_auto_idx];
3292+ let height_left = self.working_area.size.h
3293+ - self.options.gaps
3294+ - min_height_taken
3295+ - self.options.gaps;
3296+ max_non_auto_window_height = Some(f64::max(
3297+ 1.,
3298+ tile.window_height_for_tile_height(height_left).round(),
3299+ ));
3300+ }
3301+ }
3302+
3275 // Compute the tile heights. Start by converting window heights to tile heights.3303 // Compute the tile heights. Start by converting window heights to tile heights.
3276 let mut heights = zip(&self.tiles, &self.data)3304 let mut heights = zip(&self.tiles, &self.data)
3277 .map(|(tile, data)| match data.height {3305 .map(|(tile, data)| match data.height {
3278 auto @ WindowHeight::Auto { .. } => auto,3306 auto @ WindowHeight::Auto { .. } => auto,
3279 WindowHeight::Fixed(height) => {3307 WindowHeight::Fixed(height) => {
3280- WindowHeight::Fixed(tile.tile_height_for_window_height(height.round().max(1.)))3308+ let mut window_height = height.round().max(1.);
3309+ if let Some(max) = max_non_auto_window_height {
3310+ window_height = f64::min(window_height, max);
3311+ }
3312+
3313+ WindowHeight::Fixed(tile.tile_height_for_window_height(window_height))
3281 }3314 }
3282 WindowHeight::Preset(idx) => {3315 WindowHeight::Preset(idx) => {
3283 let preset = self.options.preset_window_heights[idx];3316 let preset = self.options.preset_window_heights[idx];
@@ -3285,8 +3318,13 @@ impl<W: LayoutElement> Column<W> {
3285 ResolvedSize::Tile(h) => tile.window_height_for_tile_height(h),3318 ResolvedSize::Tile(h) => tile.window_height_for_tile_height(h),
3286 ResolvedSize::Window(h) => h,3319 ResolvedSize::Window(h) => h,
3287 };3320 };
3288- let tile_height = tile3321+
3289- .tile_height_for_window_height(window_height.round().clamp(1., 100000.));3322+ let mut window_height = window_height.round().clamp(1., 100000.);
3323+ if let Some(max) = max_non_auto_window_height {
3324+ window_height = f64::min(window_height, max);
3325+ }
3326+
3327+ let tile_height = tile.tile_height_for_window_height(window_height);
3290 WindowHeight::Fixed(tile_height)3328 WindowHeight::Fixed(tile_height)
3291 }3329 }
3292 })3330 })
@@ -3488,7 +3526,8 @@ impl<W: LayoutElement> Column<W> {
3488 assert_eq!(self.tiles.len(), 1);3526 assert_eq!(self.tiles.len(), 1);
3489 }3527 }
3490 3528
3491- if self.tiles.len() == 1 {3529+ let tile_count = self.tiles.len();
3530+ if tile_count == 1 {
3492 if let WindowHeight::Auto { weight } = self.data[0].height {3531 if let WindowHeight::Auto { weight } = self.data[0].height {
3493 assert_eq!(3532 assert_eq!(
3494 weight, 1.,3533 weight, 1.,
@@ -3498,6 +3537,8 @@ impl<W: LayoutElement> Column<W> {
3498 }3537 }
3499 3538
3500 let mut found_fixed = false;3539 let mut found_fixed = false;
3540+ let mut total_height = 0.;
3541+ let mut total_min_height = 0.;
3501 for (tile, data) in zip(&self.tiles, &self.data) {3542 for (tile, data) in zip(&self.tiles, &self.data) {
3502 assert!(Rc::ptr_eq(&self.options, &tile.options));3543 assert!(Rc::ptr_eq(&self.options, &tile.options));
3503 assert_eq!(self.scale, tile.scale());3544 assert_eq!(self.scale, tile.scale());
@@ -3524,6 +3565,25 @@ impl<W: LayoutElement> Column<W> {
3524 if let WindowHeight::Preset(idx) = data.height {3565 if let WindowHeight::Preset(idx) = data.height {
3525 assert!(self.options.preset_window_heights.len() > idx);3566 assert!(self.options.preset_window_heights.len() > idx);
3526 }3567 }
3568+
3569+ let requested_size = tile.window().requested_size().unwrap();
3570+ total_height += tile.tile_height_for_window_height(f64::from(requested_size.h));
3571+ total_min_height += f64::max(1., tile.min_size().h);
3572+ }
3573+
3574+ if tile_count > 1
3575+ && self.scale.round() == self.scale
3576+ && self.working_area.size.h.round() == self.working_area.size.h
3577+ && self.options.gaps.round() == self.options.gaps
3578+ {
3579+ total_height += self.options.gaps * (tile_count + 1) as f64;
3580+ total_min_height += self.options.gaps * (tile_count + 1) as f64;
3581+ let max_height = f64::max(total_min_height, self.working_area.size.h);
3582+ assert!(
3583+ total_height <= max_height,
3584+ "multiple tiles in a column mustn't go beyond working area height \
3585+ (total height {total_height} > max height {max_height})"
3586+ );
3527 }3587 }
3528 }3588 }
3529 3589
src/window/mapped.rsmodified+4 -0
@@ -730,6 +730,10 @@ impl LayoutElement for Mapped {
730 .with_pending_state(|state| state.states.contains(xdg_toplevel::State::Fullscreen))730 .with_pending_state(|state| state.states.contains(xdg_toplevel::State::Fullscreen))
731 }731 }
732 732
733+ fn requested_size(&self) -> Option<Size<i32, Logical>> {
734+ self.toplevel().with_pending_state(|state| state.size)
735+ }
736+
733 fn refresh(&self) {737 fn refresh(&self) {
734 self.window.refresh();738 self.window.refresh();
735 }739 }