diff options
author | Dani Llewellyn <diddledani@ubuntu.com> | 2021-10-15 13:24:50 +0100 |
---|---|---|
committer | Mike Gabriel <mike.gabriel@das-netzwerkteam.de> | 2021-10-21 21:45:02 +0200 |
commit | 7e02a15a27dcec0806c2d30db8ec2960483e8c3a (patch) | |
tree | f475322a12ef79083935c9145fd021828f051cb9 | |
parent | 1904f33e7cada3bad46cf2c559f12b6302f3336f (diff) | |
download | libayatana-indicator-7e02a15a27dcec0806c2d30db8ec2960483e8c3a.tar.gz libayatana-indicator-7e02a15a27dcec0806c2d30db8ec2960483e8c3a.tar.bz2 libayatana-indicator-7e02a15a27dcec0806c2d30db8ec2960483e8c3a.zip |
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 <diddledani@ubuntu.com>
-rw-r--r-- | src/indicator-image-helper.c | 16 |
1 files 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 */ |