Somewhat fix height distribution logic
Browse files at this commitc0ded35783f1ab4f3cc687d857ed7ee44ecb60bbParent: 39632e91 changed file +24 -28
- src/layout/workspace.rs +24 -28
src/layout/workspace.rsmodified+24 -28
| @@ -2997,7 +2997,7 @@ impl<W: LayoutElement> Column<W> { | |||
| 2997 | .map(|(tile, data)| match data.height { | 2997 | .map(|(tile, data)| match data.height { |
| 2998 | WindowHeight::Auto => WindowHeight::Auto, | 2998 | WindowHeight::Auto => WindowHeight::Auto, |
| 2999 | WindowHeight::Fixed(height) => { | 2999 | 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.))) |
| 3001 | } | 3001 | } |
| 3002 | }) | 3002 | }) |
| 3003 | .collect::<Vec<_>>(); | 3003 | .collect::<Vec<_>>(); |
| @@ -3018,7 +3018,6 @@ impl<W: LayoutElement> Column<W> { | |||
| 3018 | if min_size.h > 0. { | 3018 | if min_size.h > 0. { |
| 3019 | *h = f64::max(*h, min_size.h); | 3019 | *h = f64::max(*h, min_size.h); |
| 3020 | } | 3020 | } |
| 3021 | - *h = f64::max(*h, 1.); | ||
| 3022 | 3021 | ||
| 3023 | height_left -= *h + self.options.gaps; | 3022 | height_left -= *h + self.options.gaps; |
| 3024 | auto_tiles_left -= 1; | 3023 | auto_tiles_left -= 1; |
| @@ -3037,37 +3036,33 @@ impl<W: LayoutElement> Column<W> { | |||
| 3037 | // However, most max height uses are for fixed-size dialogs, where min height == max_height. | 3036 | // However, most max height uses are for fixed-size dialogs, where min height == max_height. |
| 3038 | // This case is separately handled above. | 3037 | // This case is separately handled above. |
| 3039 | while auto_tiles_left > 0 { | 3038 | while auto_tiles_left > 0 { |
| 3040 | - // Compute the current auto height. | 3039 | + // Wayland requires us to round the requested size for a window to integer logical |
| 3041 | - let auto_height = height_left / auto_tiles_left as f64 - self.options.gaps; | 3040 | + // pixels, therefore we compute the remaining auto height dynamically. |
| 3042 | - let auto_height = f64::max(auto_height, 1.); | 3041 | + let mut height_left_2 = height_left; |
| 3043 | - | 3042 | + let mut auto_tiles_left_2 = auto_tiles_left; |
| 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 | - | ||
| 3051 | let mut unsatisfied_min = false; | 3043 | let mut unsatisfied_min = false; |
| 3052 | - let mut ones_left_2 = ones_left; | 3044 | + for ((h, tile), min_size) in zip(zip(&mut heights, &self.tiles), &min_size) { |
| 3053 | - for (h, min_size) in zip(&mut heights, &min_size) { | ||
| 3054 | if matches!(h, WindowHeight::Fixed(_)) { | 3045 | if matches!(h, WindowHeight::Fixed(_)) { |
| 3055 | continue; | 3046 | continue; |
| 3056 | } | 3047 | } |
| 3057 | 3048 | ||
| 3058 | - let mut auto = auto_height; | 3049 | + // Compute the current auto height. |
| 3059 | - if ones_left_2 > 0 { | 3050 | + let auto = height_left_2 / auto_tiles_left_2 as f64 - self.options.gaps; |
| 3060 | - auto += 1.; | 3051 | + let mut auto = tile.tile_height_for_window_height( |
| 3061 | - ones_left_2 -= 1; | 3052 | + tile.window_height_for_tile_height(auto).round().max(1.), |
| 3062 | - } | 3053 | + ); |
| 3063 | 3054 | ||
| 3064 | // Check if the auto height satisfies the min height. | 3055 | // Check if the auto height satisfies the min height. |
| 3065 | if min_size.h > 0. && min_size.h > auto { | 3056 | if min_size.h > 0. && min_size.h > auto { |
| 3066 | - *h = WindowHeight::Fixed(min_size.h); | 3057 | + auto = min_size.h; |
| 3067 | - height_left -= min_size.h + self.options.gaps; | 3058 | + *h = WindowHeight::Fixed(auto); |
| 3059 | + height_left -= auto + self.options.gaps; | ||
| 3068 | auto_tiles_left -= 1; | 3060 | auto_tiles_left -= 1; |
| 3069 | unsatisfied_min = true; | 3061 | unsatisfied_min = true; |
| 3070 | } | 3062 | } |
| 3063 | + | ||
| 3064 | + height_left_2 -= auto + self.options.gaps; | ||
| 3065 | + auto_tiles_left_2 -= 1; | ||
| 3071 | } | 3066 | } |
| 3072 | 3067 | ||
| 3073 | // If some min height was unsatisfied, then we allocated the tile more than the auto | 3068 | // If some min height was unsatisfied, then we allocated the tile more than the auto |
| @@ -3078,18 +3073,19 @@ impl<W: LayoutElement> Column<W> { | |||
| 3078 | } | 3073 | } |
| 3079 | 3074 | ||
| 3080 | // All min heights were satisfied, fill them in. | 3075 | // All min heights were satisfied, fill them in. |
| 3081 | - for h in &mut heights { | 3076 | + for (h, tile) in zip(&mut heights, &self.tiles) { |
| 3082 | if matches!(h, WindowHeight::Fixed(_)) { | 3077 | if matches!(h, WindowHeight::Fixed(_)) { |
| 3083 | continue; | 3078 | continue; |
| 3084 | } | 3079 | } |
| 3085 | 3080 | ||
| 3086 | - let mut auto = auto_height; | 3081 | + // Compute the current auto height. |
| 3087 | - if ones_left > 0 { | 3082 | + let auto = height_left / auto_tiles_left as f64 - self.options.gaps; |
| 3088 | - auto += 1.; | 3083 | + let auto = tile.tile_height_for_window_height( |
| 3089 | - ones_left -= 1; | 3084 | + tile.window_height_for_tile_height(auto).round().max(1.), |
| 3090 | - } | 3085 | + ); |
| 3091 | 3086 | ||
| 3092 | *h = WindowHeight::Fixed(auto); | 3087 | *h = WindowHeight::Fixed(auto); |
| 3088 | + height_left -= auto + self.options.gaps; | ||
| 3093 | auto_tiles_left -= 1; | 3089 | auto_tiles_left -= 1; |
| 3094 | } | 3090 | } |
| 3095 | 3091 | ||