From: Hans de Goede Date: Thu, 6 Mar 2025 16:38:33 +0000 (+0100) Subject: ply-utils: Swap width <-> height for portrait screens when guessing device-scale X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=0a4fd6b1d261d2d6a848ccb7cbd5fc769b3f9503;p=thirdparty%2Fplymouth.git 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 --- 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 */