diff options
author | Victor Kareh <[email protected]> | 2019-10-01 04:11:14 -0400 |
---|---|---|
committer | Martin Wimpress <[email protected]> | 2019-10-01 09:11:14 +0100 |
commit | 3e4ccaf000449b52670a9ac11af5c9f1ade96016 (patch) | |
tree | 98c3d277963562604a9692304c224d30bb19b4ec /libslab | |
parent | 1dfe719a0b0277a4a50b46947138b0b5b3342cd4 (diff) | |
download | mate-control-center-3e4ccaf000449b52670a9ac11af5c9f1ade96016.tar.bz2 mate-control-center-3e4ccaf000449b52670a9ac11af5c9f1ade96016.tar.xz |
icons: Force uniform size on icons (#505)
Also scale properly for HiDPI displays
Diffstat (limited to 'libslab')
-rw-r--r-- | libslab/mate-utils.c | 26 |
1 files changed, 18 insertions, 8 deletions
diff --git a/libslab/mate-utils.c b/libslab/mate-utils.c index 8dafe11a..e42d02c4 100644 --- a/libslab/mate-utils.c +++ b/libslab/mate-utils.c @@ -3,11 +3,12 @@ #include <string.h> gboolean -load_image_by_id (GtkImage * image, GtkIconSize size, const gchar * image_id) +load_image_by_id (GtkImage *image, GtkIconSize size, const gchar *image_id) { - GdkPixbuf *pixbuf; + cairo_surface_t *surface; gint width; gint height; + gint scale_factor; GtkIconTheme *icon_theme; @@ -19,20 +20,25 @@ load_image_by_id (GtkImage * image, GtkIconSize size, const gchar * image_id) return FALSE; id = g_strdup (image_id); + scale_factor = gtk_widget_get_scale_factor (GTK_WIDGET (image)); gtk_icon_size_lookup (size, &width, &height); gtk_image_set_pixel_size (image, width); if (g_path_is_absolute (id)) { - pixbuf = gdk_pixbuf_new_from_file_at_size (id, width, height, NULL); + GdkPixbuf *pixbuf; + + pixbuf = gdk_pixbuf_new_from_file_at_size (id, width * scale_factor, height * scale_factor, NULL); icon_exists = (pixbuf != NULL); if (icon_exists) { - gtk_image_set_from_pixbuf (image, pixbuf); + surface = gdk_cairo_surface_create_from_pixbuf (pixbuf, scale_factor, NULL); + gtk_image_set_from_surface (image, surface); + cairo_surface_destroy (surface); g_object_unref (pixbuf); } else @@ -55,11 +61,15 @@ load_image_by_id (GtkImage * image, GtkIconSize size, const gchar * image_id) else icon_theme = gtk_icon_theme_get_default (); - pixbuf = gtk_icon_theme_load_icon (icon_theme, id, width, 0, NULL); - icon_exists = (pixbuf != NULL); + surface = gtk_icon_theme_load_surface (icon_theme, id, + width, scale_factor, + NULL, + GTK_ICON_LOOKUP_FORCE_SIZE, + NULL); + icon_exists = (surface != NULL); if (icon_exists) { - gtk_image_set_from_pixbuf (image, pixbuf); - g_object_unref (pixbuf); + gtk_image_set_from_surface (image, surface); + cairo_surface_destroy (surface); } else gtk_image_set_from_icon_name (image, "image-missing", size); |