forge
Explore
Log in

Don't you dare go Hollow

Somewhat fix height distribution logic

Browse files at this commit

c0ded35783f1ab4f3cc687d857ed7ee44ecb60bbIvan MolodetskikhParent: 39632e9
This got a bit broken with fractional layout. The current logic seems to
give exact results for integer scales again, but for fractional scales
sometimes the resulting height goes beyond the maximum, even clearly by
more than one logical pixel. Not entirely sure why that is.
src/layout/workspace.rsmodified+24 -28
@@ -2997,7 +2997,7 @@ impl<W: LayoutElement> Column<W> {
29972997 .map(|(tile, data)| match data.height {
29982998 WindowHeight::Auto => WindowHeight::Auto,
29992999 WindowHeight::Fixed(height) => {
3000- WindowHeight::Fixed(tile.tile_height_for_window_height(height))
3000+ WindowHeight::Fixed(tile.tile_height_for_window_height(height.round().max(1.)))
30013001 }
30023002 })
30033003 .collect::<Vec<_>>();
@@ -3018,7 +3018,6 @@ impl<W: LayoutElement> Column<W> {
30183018 if min_size.h > 0. {
30193019 *h = f64::max(*h, min_size.h);
30203020 }
3021- *h = f64::max(*h, 1.);
30223021
30233022 height_left -= *h + self.options.gaps;
30243023 auto_tiles_left -= 1;
@@ -3037,37 +3036,33 @@ impl<W: LayoutElement> Column<W> {
30373036 // However, most max height uses are for fixed-size dialogs, where min height == max_height.
30383037 // This case is separately handled above.
30393038 while auto_tiles_left > 0 {
3040- // Compute the current auto height.
3041- let auto_height = height_left / auto_tiles_left as f64 - self.options.gaps;
3042- let auto_height = f64::max(auto_height, 1.);
3043-
3044- // Integer division above can result in imperfect height distribution. We will make some
3045- // tiles 1 px taller to account for this.
3046- let mut ones_left = f64::max(
3047- 0.,
3048- height_left - (auto_height + self.options.gaps) * auto_tiles_left as f64,
3049- ) as i32;
3050-
3039+ // Wayland requires us to round the requested size for a window to integer logical
3040+ // pixels, therefore we compute the remaining auto height dynamically.
3041+ let mut height_left_2 = height_left;
3042+ let mut auto_tiles_left_2 = auto_tiles_left;
30513043 let mut unsatisfied_min = false;
3052- let mut ones_left_2 = ones_left;
3053- for (h, min_size) in zip(&mut heights, &min_size) {
3044+ for ((h, tile), min_size) in zip(zip(&mut heights, &self.tiles), &min_size) {
30543045 if matches!(h, WindowHeight::Fixed(_)) {
30553046 continue;
30563047 }
30573048
3058- let mut auto = auto_height;
3059- if ones_left_2 > 0 {
3060- auto += 1.;
3061- ones_left_2 -= 1;
3062- }
3049+ // Compute the current auto height.
3050+ let auto = height_left_2 / auto_tiles_left_2 as f64 - self.options.gaps;
3051+ let mut auto = tile.tile_height_for_window_height(
3052+ tile.window_height_for_tile_height(auto).round().max(1.),
3053+ );
30633054
30643055 // Check if the auto height satisfies the min height.
30653056 if min_size.h > 0. && min_size.h > auto {
3066- *h = WindowHeight::Fixed(min_size.h);
3067- height_left -= min_size.h + self.options.gaps;
3057+ auto = min_size.h;
3058+ *h = WindowHeight::Fixed(auto);
3059+ height_left -= auto + self.options.gaps;
30683060 auto_tiles_left -= 1;
30693061 unsatisfied_min = true;
30703062 }
3063+
3064+ height_left_2 -= auto + self.options.gaps;
3065+ auto_tiles_left_2 -= 1;
30713066 }
30723067
30733068 // If some min height was unsatisfied, then we allocated the tile more than the auto
@@ -3078,18 +3073,19 @@ impl<W: LayoutElement> Column<W> {
30783073 }
30793074
30803075 // All min heights were satisfied, fill them in.
3081- for h in &mut heights {
3076+ for (h, tile) in zip(&mut heights, &self.tiles) {
30823077 if matches!(h, WindowHeight::Fixed(_)) {
30833078 continue;
30843079 }
30853080
3086- let mut auto = auto_height;
3087- if ones_left > 0 {
3088- auto += 1.;
3089- ones_left -= 1;
3090- }
3081+ // Compute the current auto height.
3082+ let auto = height_left / auto_tiles_left as f64 - self.options.gaps;
3083+ let auto = tile.tile_height_for_window_height(
3084+ tile.window_height_for_tile_height(auto).round().max(1.),
3085+ );
30913086
30923087 *h = WindowHeight::Fixed(auto);
3088+ height_left -= auto + self.options.gaps;
30933089 auto_tiles_left -= 1;
30943090 }
30953091