diff options
Diffstat (limited to 'libslab/mate-utils.c')
-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); |