]> git.ipfire.org Git - thirdparty/plymouth.git/commitdiff
ply-utils: Swap width <-> height for portrait screens when guessing device-scale
authorHans de Goede <hdegoede@redhat.com>
Thu, 6 Mar 2025 16:38:33 +0000 (17:38 +0100)
committerHans de Goede <jwrdegoede@fedoraproject.org>
Tue, 6 May 2025 11:38:59 +0000 (11:38 +0000)
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 <hdegoede@redhat.com>
src/libply/ply-utils.c

index dee79869d086350ec9d82c87e47d2789092ae277..755a54ccdd26cc555216941f2d7c7b7e76e88f22 100644 (file)
@@ -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 */