]> jfr.im git - irc/hexchat/hexchat.git/commitdiff
Add a workaround for icons not scaling right on HiDPI screens. (#2573)
authorSadie Powell <redacted>
Sun, 23 May 2021 18:01:39 +0000 (19:01 +0100)
committerGitHub <redacted>
Sun, 23 May 2021 18:01:39 +0000 (13:01 -0500)
src/fe-gtk/pixmaps.c

index 6c6cfaeb4aaf13d6247e5c35c613398b8e89f489..9bdf46fc4ea54fcfa88e1fc92e0a416bae0ae1a9 100644 (file)
@@ -89,7 +89,9 @@ pixmap_load_from_file (char *filename)
 static GdkPixbuf *
 load_pixmap (const char *filename)
 {
-       GdkPixbuf *pixbuf;
+       GdkPixbuf *pixbuf, *scaledpixbuf;
+       const char *scale;
+       int iscale;
 
        gchar *path = g_strdup_printf ("%s" G_DIR_SEPARATOR_S "icons" G_DIR_SEPARATOR_S "%s.png", get_xdir (), filename);
        pixbuf = gdk_pixbuf_new_from_file (path, 0);
@@ -102,6 +104,24 @@ load_pixmap (const char *filename)
                g_free (path);
        }
 
+       // Hack to avoid unbearably tiny icons on HiDPI screens.
+       scale = g_getenv ("GDK_SCALE");
+       if (scale)
+       {
+               iscale = atoi (scale);
+               if (iscale > 0)
+               {
+                       scaledpixbuf = gdk_pixbuf_scale_simple (pixbuf, gdk_pixbuf_get_width (pixbuf) * iscale,
+                               gdk_pixbuf_get_height (pixbuf) * iscale, GDK_INTERP_BILINEAR);
+
+                       if (scaledpixbuf)
+                       {
+                               g_object_unref (pixbuf);
+                               pixbuf = scaledpixbuf;
+                       }
+               }
+       }
+
        g_warn_if_fail (pixbuf != NULL);
 
        return pixbuf;