From b725af4244fab89e1f4d1587eef198cef6d848ef Mon Sep 17 00:00:00 2001 From: Wu Xiaotian Date: Sun, 1 Dec 2019 13:43:31 +0800 Subject: Show application icons whenever possible Even if some application icons do not exist in the current theme, try looking for them in the fallback themes. --- mate-volume-control/gvc-channel-bar.c | 40 +++++++++++++++++++++++++++++------ 1 file changed, 34 insertions(+), 6 deletions(-) diff --git a/mate-volume-control/gvc-channel-bar.c b/mate-volume-control/gvc-channel-bar.c index 58a3a08..571da2c 100644 --- a/mate-volume-control/gvc-channel-bar.c +++ b/mate-volume-control/gvc-channel-bar.c @@ -750,13 +750,41 @@ gvc_channel_bar_set_icon_name (GvcChannelBar *bar, const gchar *name) { g_return_if_fail (GVC_IS_CHANNEL_BAR (bar)); - gtk_image_set_from_icon_name (GTK_IMAGE (bar->priv->image), - name, - GTK_ICON_SIZE_DIALOG); - if (name != NULL) - gtk_widget_show (bar->priv->image); - else + if (name != NULL) { + GtkIconTheme *icon_theme; + GdkPixbuf *pixbuf; + gint width, height; + GError *error = NULL; + + gtk_icon_size_lookup (GTK_ICON_SIZE_DIALOG, &width, &height); + icon_theme = gtk_icon_theme_get_default (); + pixbuf = gtk_icon_theme_load_icon (icon_theme, + name, + width, + GTK_ICON_LOOKUP_GENERIC_FALLBACK | GTK_ICON_LOOKUP_FORCE_SIZE, + &error); + if (error != NULL) { + g_warning ("Couldn’t load icon: %s\n", error->message); + g_clear_error (&error); + } + + if (pixbuf == NULL) { + pixbuf = gdk_pixbuf_new_from_file_at_scale (name, width, height, TRUE, &error); + if (error != NULL) + { + g_warning ("Couldn’t load icon: %s\n", error->message); + g_clear_error (&error); + } + } + + if (pixbuf) { + gtk_image_set_from_pixbuf (GTK_IMAGE (bar->priv->image), pixbuf); + gtk_widget_show (bar->priv->image); + g_object_unref (pixbuf); + } + } else { gtk_widget_hide (bar->priv->image); + } g_object_notify_by_pspec (G_OBJECT (bar), properties[PROP_ICON_NAME]); } -- cgit v1.2.1