From 6121e6433879d2d8b4069fe299e442cb3cf52a11 Mon Sep 17 00:00:00 2001 From: Ivan Molodetskikh Date: Mon, 17 Jun 2024 09:19:32 +0300 Subject: Add fractional scales to auto scale guessing --- src/utils/scale.rs | 38 ++++++++++++++++++-------------------- 1 file changed, 18 insertions(+), 20 deletions(-) (limited to 'src') 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, resolution: Size, resolution: Size) -> impl Iterator { - (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, scale: i32) -> bool { - let logical = resolution.to_logical(scale); +fn is_valid_for_resolution(resolution: Size, scale: f64) -> bool { + let logical = resolution.to_f64().to_logical(scale).to_i32_round::(); 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 -- cgit