From 7e02a15a27dcec0806c2d30db8ec2960483e8c3a Mon Sep 17 00:00:00 2001 From: Dani Llewellyn Date: Fri, 15 Oct 2021 13:24:50 +0100 Subject: Scale icons when loading from filename When loading an icon from a filename, not a stock icon name, we need to scale the pixbuf manually because gtk_image_set_pixel_size only works on named icons from the theme that have multiple sizes available. Signed-off-by: Dani Llewellyn --- src/indicator-image-helper.c | 16 +++++++++------- 1 file changed, 9 insertions(+), 7 deletions(-) diff --git a/src/indicator-image-helper.c b/src/indicator-image-helper.c index 2c0e244..4a22539 100644 --- a/src/indicator-image-helper.c +++ b/src/indicator-image-helper.c @@ -79,13 +79,15 @@ refresh_image (GtkImage * image) } g_object_unref (pixbuf); } else if (icon_filename != NULL) { - gtk_image_set_from_file(image, icon_filename); - - gint height; - gdk_pixbuf_get_file_info(icon_filename, NULL, &height); - - if (height > ICON_SIZE) { - gtk_image_set_pixel_size(image, ICON_SIZE); + GError* error = NULL; + GdkPixbuf* pixbuf = gdk_pixbuf_new_from_file_at_scale(icon_filename, ICON_SIZE, ICON_SIZE, TRUE, &error); + if (pixbuf != NULL) { + /* Put the pixbuf on the image */ + gtk_image_set_from_pixbuf(image, pixbuf); + g_object_unref(G_OBJECT(pixbuf)); + } else { + g_error_free(error); + gtk_image_set_from_icon_name(image, "image-missing", ICON_SIZE); } } else if (G_IS_LOADABLE_ICON(icon_names)) { /* Build a pixbuf if needed */ -- cgit v1.2.3