forge
Explore
Log in

Don't you dare go Hollow

Add fractional scales to auto scale guessing

Browse files at this commit

6121e6433879d2d8b4069fe299e442cb3cf52a11Ivan MolodetskikhParent: 33b5bea
src/utils/scale.rsmodified+18 -20
@@ -7,6 +7,7 @@ use smithay::utils::{Physical, Raw, Size};
7 7
8 const MIN_SCALE: i32 = 1;8 const MIN_SCALE: i32 = 1;
9 const MAX_SCALE: i32 = 4;9 const MAX_SCALE: i32 = 4;
10+const STEPS: i32 = 4;
10 const MIN_LOGICAL_AREA: i32 = 800 * 480;11 const MIN_LOGICAL_AREA: i32 = 800 * 480;
11 12
12 const MOBILE_TARGET_DPI: f64 = 135.;13 const MOBILE_TARGET_DPI: f64 = 135.;
@@ -31,9 +32,6 @@ pub fn guess_monitor_scale(size_mm: Size<i32, Raw>, resolution: Size<i32, Physic
31 f64::from(resolution.w * resolution.w + resolution.h * resolution.h).sqrt() / diag_inches;32 f64::from(resolution.w * resolution.w + resolution.h * resolution.h).sqrt() / diag_inches;
32 let perfect_scale = physical_dpi / target_dpi;33 let perfect_scale = physical_dpi / target_dpi;
33 34
34- // For integer scaling factors (we currently only do integer), bias the perfect scale down.
35- let perfect_scale = perfect_scale - 0.15;
36-
37 supported_scales(resolution)35 supported_scales(resolution)
38 .map(|scale| (scale, (scale - perfect_scale).abs()))36 .map(|scale| (scale, (scale - perfect_scale).abs()))
39 .min_by(|a, b| a.1.partial_cmp(&b.1).unwrap())37 .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
41 }39 }
42 40
43 fn supported_scales(resolution: Size<i32, Physical>) -> impl Iterator<Item = f64> {41 fn supported_scales(resolution: Size<i32, Physical>) -> impl Iterator<Item = f64> {
44- (MIN_SCALE..=MAX_SCALE)42+ (MIN_SCALE * STEPS..=MAX_SCALE * STEPS)
43+ .map(|x| f64::from(x) / f64::from(STEPS))
45 .filter(move |scale| is_valid_for_resolution(resolution, *scale))44 .filter(move |scale| is_valid_for_resolution(resolution, *scale))
46- .map(f64::from)
47 }45 }
48 46
49-fn is_valid_for_resolution(resolution: Size<i32, Physical>, scale: i32) -> bool {47+fn is_valid_for_resolution(resolution: Size<i32, Physical>, scale: f64) -> bool {
50- let logical = resolution.to_logical(scale);48+ let logical = resolution.to_f64().to_logical(scale).to_i32_round::<i32>();
51 logical.w * logical.h >= MIN_LOGICAL_AREA49 logical.w * logical.h >= MIN_LOGICAL_AREA
52 }50 }
53 51
@@ -71,33 +69,33 @@ mod tests {
71 #[test]69 #[test]
72 fn test_guess_monitor_scale() {70 fn test_guess_monitor_scale() {
73 // Librem 5; not enough logical area when scaled71 // Librem 5; not enough logical area when scaled
74- snapshot!(check((65, 129), (720, 1440)), "1.0");72+ snapshot!(check((65, 129), (720, 1440)), "1.5");
75 // OnePlus 673 // OnePlus 6
76- snapshot!(check((68, 144), (1080, 2280)), "2.0");74+ snapshot!(check((68, 144), (1080, 2280)), "2.5");
77 // Google Pixel 6a75 // Google Pixel 6a
78- snapshot!(check((64, 142), (1080, 2400)), "2.0");76+ snapshot!(check((64, 142), (1080, 2400)), "2.5");
79 // 13" MacBook Retina77 // 13" MacBook Retina
80- snapshot!(check((286, 179), (2560, 1600)), "2.0");78+ snapshot!(check((286, 179), (2560, 1600)), "1.75");
81 // Surface Laptop Studio79 // Surface Laptop Studio
82- snapshot!(check((303, 202), (2400, 1600)), "1.0");80+ snapshot!(check((303, 202), (2400, 1600)), "1.5");
83 // Dell XPS 932081 // Dell XPS 9320
84- snapshot!(check((290, 180), (3840, 2400)), "2.0");82+ snapshot!(check((290, 180), (3840, 2400)), "2.5");
85 // Lenovo ThinkPad X1 Yoga Gen 683 // Lenovo ThinkPad X1 Yoga Gen 6
86- snapshot!(check((300, 190), (3840, 2400)), "2.0");84+ snapshot!(check((300, 190), (3840, 2400)), "2.5");
87 // Generic 23" 1080p85 // Generic 23" 1080p
88 snapshot!(check((509, 286), (1920, 1080)), "1.0");86 snapshot!(check((509, 286), (1920, 1080)), "1.0");
89 // Generic 23" 4K87 // Generic 23" 4K
90- snapshot!(check((509, 286), (3840, 2160)), "2.0");88+ snapshot!(check((509, 286), (3840, 2160)), "1.75");
91 // Generic 27" 4K89 // Generic 27" 4K
92- snapshot!(check((598, 336), (3840, 2160)), "1.0");90+ snapshot!(check((598, 336), (3840, 2160)), "1.5");
93 // Generic 32" 4K91 // Generic 32" 4K
94- snapshot!(check((708, 398), (3840, 2160)), "1.0");92+ snapshot!(check((708, 398), (3840, 2160)), "1.25");
95 // Generic 25" 4K; ideal scale is 1.60, should round to 1.5 and 1.093 // Generic 25" 4K; ideal scale is 1.60, should round to 1.5 and 1.0
96- snapshot!(check((554, 312), (3840, 2160)), "1.0");94+ snapshot!(check((554, 312), (3840, 2160)), "1.5");
97 // Generic 23.5" 4K; ideal scale is 1.70, should round to 1.75 and 2.095 // Generic 23.5" 4K; ideal scale is 1.70, should round to 1.75 and 2.0
98- snapshot!(check((522, 294), (3840, 2160)), "2.0");96+ snapshot!(check((522, 294), (3840, 2160)), "1.75");
99 // Lenovo Legion 7 Gen 7 AMD 16"97 // Lenovo Legion 7 Gen 7 AMD 16"
100- snapshot!(check((340, 210), (2560, 1600)), "1.0");98+ snapshot!(check((340, 210), (2560, 1600)), "1.5");
101 // Acer Nitro XV320QU LV 31.5"99 // Acer Nitro XV320QU LV 31.5"
102 snapshot!(check((700, 390), (2560, 1440)), "1.0");100 snapshot!(check((700, 390), (2560, 1440)), "1.0");
103 // Surface Pro 6101 // Surface Pro 6