diff options
| author | Ivan Molodetskikh <yalterz@gmail.com> | 2024-06-17 09:19:32 +0300 |
|---|---|---|
| committer | Ivan Molodetskikh <yalterz@gmail.com> | 2024-06-18 14:01:34 +0300 |
| commit | 6121e6433879d2d8b4069fe299e442cb3cf52a11 (patch) | |
| tree | 85983f89f61dc0bfcf51a749682c8c109475b23f /src | |
| parent | 33b5beaeee62e47ecaa33fc3175ef9e22931f116 (diff) | |
| download | niri-6121e6433879d2d8b4069fe299e442cb3cf52a11.tar.gz niri-6121e6433879d2d8b4069fe299e442cb3cf52a11.tar.bz2 niri-6121e6433879d2d8b4069fe299e442cb3cf52a11.zip | |
Add fractional scales to auto scale guessing
Diffstat (limited to 'src')
| -rw-r--r-- | src/utils/scale.rs | 38 |
1 files changed, 18 insertions, 20 deletions
diff --git a/src/utils/scale.rs b/src/utils/scale.rs index 6db88248..857b3825 100644 --- a/src/utils/scale.rs +++ b/src/utils/scale.rs @@ -7,6 +7,7 @@ use smithay::utils::{Physical, Raw, Size}; const MIN_SCALE: i32 = 1; const MAX_SCALE: i32 = 4; +const STEPS: i32 = 4; const MIN_LOGICAL_AREA: i32 = 800 * 480; const MOBILE_TARGET_DPI: f64 = 135.; @@ -31,9 +32,6 @@ pub fn guess_monitor_scale(size_mm: Size<i32, Raw>, resolution: Size<i32, Physic f64::from(resolution.w * resolution.w + resolution.h * resolution.h).sqrt() / diag_inches; let perfect_scale = physical_dpi / target_dpi; - // For integer scaling factors (we currently only do integer), bias the perfect scale down. - let perfect_scale = perfect_scale - 0.15; - supported_scales(resolution) .map(|scale| (scale, (scale - perfect_scale).abs())) .min_by(|a, b| a.1.partial_cmp(&b.1).unwrap()) @@ -41,13 +39,13 @@ pub fn guess_monitor_scale(size_mm: Size<i32, Raw>, resolution: Size<i32, Physic } fn supported_scales(resolution: Size<i32, Physical>) -> impl Iterator<Item = f64> { - (MIN_SCALE..=MAX_SCALE) + (MIN_SCALE * STEPS..=MAX_SCALE * STEPS) + .map(|x| f64::from(x) / f64::from(STEPS)) .filter(move |scale| is_valid_for_resolution(resolution, *scale)) - .map(f64::from) } -fn is_valid_for_resolution(resolution: Size<i32, Physical>, scale: i32) -> bool { - let logical = resolution.to_logical(scale); +fn is_valid_for_resolution(resolution: Size<i32, Physical>, scale: f64) -> bool { + let logical = resolution.to_f64().to_logical(scale).to_i32_round::<i32>(); logical.w * logical.h >= MIN_LOGICAL_AREA } @@ -71,33 +69,33 @@ mod tests { #[test] fn test_guess_monitor_scale() { // Librem 5; not enough logical area when scaled - snapshot!(check((65, 129), (720, 1440)), "1.0"); + snapshot!(check((65, 129), (720, 1440)), "1.5"); // OnePlus 6 - snapshot!(check((68, 144), (1080, 2280)), "2.0"); + snapshot!(check((68, 144), (1080, 2280)), "2.5"); // Google Pixel 6a - snapshot!(check((64, 142), (1080, 2400)), "2.0"); + snapshot!(check((64, 142), (1080, 2400)), "2.5"); // 13" MacBook Retina - snapshot!(check((286, 179), (2560, 1600)), "2.0"); + snapshot!(check((286, 179), (2560, 1600)), "1.75"); // Surface Laptop Studio - snapshot!(check((303, 202), (2400, 1600)), "1.0"); + snapshot!(check((303, 202), (2400, 1600)), "1.5"); // Dell XPS 9320 - snapshot!(check((290, 180), (3840, 2400)), "2.0"); + snapshot!(check((290, 180), (3840, 2400)), "2.5"); // Lenovo ThinkPad X1 Yoga Gen 6 - snapshot!(check((300, 190), (3840, 2400)), "2.0"); + snapshot!(check((300, 190), (3840, 2400)), "2.5"); // Generic 23" 1080p snapshot!(check((509, 286), (1920, 1080)), "1.0"); // Generic 23" 4K - snapshot!(check((509, 286), (3840, 2160)), "2.0"); + snapshot!(check((509, 286), (3840, 2160)), "1.75"); // Generic 27" 4K - snapshot!(check((598, 336), (3840, 2160)), "1.0"); + snapshot!(check((598, 336), (3840, 2160)), "1.5"); // Generic 32" 4K - snapshot!(check((708, 398), (3840, 2160)), "1.0"); + snapshot!(check((708, 398), (3840, 2160)), "1.25"); // Generic 25" 4K; ideal scale is 1.60, should round to 1.5 and 1.0 - snapshot!(check((554, 312), (3840, 2160)), "1.0"); + snapshot!(check((554, 312), (3840, 2160)), "1.5"); // Generic 23.5" 4K; ideal scale is 1.70, should round to 1.75 and 2.0 - snapshot!(check((522, 294), (3840, 2160)), "2.0"); + snapshot!(check((522, 294), (3840, 2160)), "1.75"); // Lenovo Legion 7 Gen 7 AMD 16" - snapshot!(check((340, 210), (2560, 1600)), "1.0"); + snapshot!(check((340, 210), (2560, 1600)), "1.5"); // Acer Nitro XV320QU LV 31.5" snapshot!(check((700, 390), (2560, 1440)), "1.0"); // Surface Pro 6 |
