From 0a4fd6b1d261d2d6a848ccb7cbd5fc769b3f9503 Mon Sep 17 00:00:00 2001 From: Hans de Goede Date: Thu, 6 Mar 2025 17:38:33 +0100 Subject: [PATCH 1/3] ply-utils: Swap width <-> height for portrait screens when guessing device-scale Swap width <-> height for portrait screens when guessing device-scale, this fixes the heuristics not working for portrait screens. Also move the heuristics to a new get_device_scale_guess () helper, because it has become a bit larger now. Signed-off-by: Hans de Goede --- src/libply/ply-utils.c | 21 +++++++++++++++++---- 1 file changed, 17 insertions(+), 4 deletions(-) diff --git a/src/libply/ply-utils.c b/src/libply/ply-utils.c index dee79869..755a54cc 100644 --- a/src/libply/ply-utils.c +++ b/src/libply/ply-utils.c @@ -1029,6 +1029,21 @@ ply_set_device_scale (int device_scale) */ static bool guess_device_scale; +static int +get_device_scale_guess (uint32_t width, + uint32_t height) +{ + /* Swap width <-> height for portrait screens */ + if (height > width) { + uint32_t tmp = width; + width = height; + height = tmp; + } + + return (width >= HIDPI_MIN_WIDTH && + height >= HIDPI_MIN_HEIGHT) ? 2 : 1; +} + static int get_device_scale (uint32_t width, uint32_t height, @@ -1048,10 +1063,8 @@ get_device_scale (uint32_t width, if (overridden_device_scale != 0) return overridden_device_scale; - if (guess) { - return (width >= HIDPI_MIN_WIDTH && - height >= HIDPI_MIN_HEIGHT) ? 2 : 1; - } + if (guess) + return get_device_scale_guess (width, height); /* Somebody encoded the aspect ratio (16/9 or 16/10) * instead of the physical size */ From 2123f7b9c6d0982f8caf25d6e6d36cb3ce1ece35 Mon Sep 17 00:00:00 2001 From: Hans de Goede Date: Thu, 6 Mar 2025 17:46:34 +0100 Subject: [PATCH 2/3] ply-utils: Use lower threshold for hiDPI scaling on 3:2 screens 3:2 screens are only used in mobile form factors, add a special case for this with a lower threshold to enable 2x hiDPI scaling. Also remove the HIDPI_MIN_* defines these were only used in one place and adding a second set for the 3:2 screens just makes things harder to read. Instead write the actual width/height thresholds directly in the code of the new get_device_scale_guess () helper. Signed-off-by: Hans de Goede --- src/libply/ply-utils.c | 18 +++++++++++++----- 1 file changed, 13 insertions(+), 5 deletions(-) diff --git a/src/libply/ply-utils.c b/src/libply/ply-utils.c index 755a54cc..2de2e87c 100644 --- a/src/libply/ply-utils.c +++ b/src/libply/ply-utils.c @@ -1020,9 +1020,6 @@ ply_set_device_scale (int device_scale) ply_trace ("Device scale is set to %d", device_scale); } -#define HIDPI_MIN_HEIGHT 1200 -#define HIDPI_MIN_WIDTH 2560 /* For heuristic / guessed device-scale */ - /* * If we have guessed the scale once, keep guessing to avoid * changing the scale on simpledrm -> native driver switch. @@ -1033,6 +1030,8 @@ static int get_device_scale_guess (uint32_t width, uint32_t height) { + double aspect; + /* Swap width <-> height for portrait screens */ if (height > width) { uint32_t tmp = width; @@ -1040,8 +1039,17 @@ get_device_scale_guess (uint32_t width, height = tmp; } - return (width >= HIDPI_MIN_WIDTH && - height >= HIDPI_MIN_HEIGHT) ? 2 : 1; + /* + * Special case for 3:2 screens which are only used in mobile form + * factors, with a lower threshold to enable 2x hiDPI scaling. + */ + aspect = (double) width / height; + if (aspect == 1.5) + return (width >= 1800 && + height >= 1200) ? 2 : 1; + + return (width >= 2560 && + height >= 1200) ? 2 : 1; } static int From 1421a9f65ffddad75a03f656c312df9cebff44c0 Mon Sep 17 00:00:00 2001 From: Hans de Goede Date: Thu, 6 Mar 2025 17:53:43 +0100 Subject: [PATCH 3/3] ply-utils: Increase threshold for guessed hiDPI scaling to >= 2880x1620 1440 is only 33% more then FHD, so using 2x there is a bit too much and leads to the spinner being much too large on e.g 27" monitors. And on e.g. Dell ultrawide 34" 3440x1440 which are only 110 DPI this effect is even worse. Change the threshold to >= 2880x1620 to avoid using 2x scaling on 1440p monitors. 2880x1620 is ~240DPI when used in a 14" laptop at which point using 2x scaling is really necessary. Signed-off-by: Hans de Goede --- src/libply/ply-utils.c | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/libply/ply-utils.c b/src/libply/ply-utils.c index 2de2e87c..6fa64975 100644 --- a/src/libply/ply-utils.c +++ b/src/libply/ply-utils.c @@ -1048,8 +1048,8 @@ get_device_scale_guess (uint32_t width, return (width >= 1800 && height >= 1200) ? 2 : 1; - return (width >= 2560 && - height >= 1200) ? 2 : 1; + return (width >= 2880 && + height >= 1620) ? 2 : 1; } static int