From d405ac8a358919ce95c449924ddfe66a8cf68ecd Mon Sep 17 00:00:00 2001 From: Simon Steinbeiss Date: Wed, 26 Jun 2019 00:17:47 +0200 Subject: [PATCH] tasklist: Add fallback for missing window icons (Bug #15511) While libwnck provides icons, we can - as final fallback - also query the name of the WM_CLASS property of the window and look for an icon of that name in the icon theme. --- plugins/tasklist/tasklist-widget.c | 43 +++++++++++++++++++++++------- 1 file changed, 34 insertions(+), 9 deletions(-) diff --git a/plugins/tasklist/tasklist-widget.c b/plugins/tasklist/tasklist-widget.c index 296093ee..33f46d92 100644 --- a/plugins/tasklist/tasklist-widget.c +++ b/plugins/tasklist/tasklist-widget.c @@ -616,7 +616,39 @@ xfce_tasklist_init (XfceTasklist *tasklist) gtk_widget_show (tasklist->arrow_button); } +static GdkPixbuf * +xfce_tasklist_get_window_icon (WnckWindow *window, + gboolean show_labels, + int size, + int type) +{ + GdkPixbuf *pixbuf; + if (show_labels || type == CHILD_TYPE_GROUP_MENU) + pixbuf = wnck_window_get_mini_icon (window); + else if (size <= 31) + pixbuf = wnck_window_get_mini_icon (window); + else + pixbuf = wnck_window_get_icon (window); + + /* Fallback: Get the pixbuf from the icon theme, and also avoid + * overwriting `pixbuf' because if it holds a valid fallback + * icon then it can become `NULL' after this call leading + * to no icon at all to render */ + if (!pixbuf || wnck_window_get_icon_is_fallback (window)) + { + GdkPixbuf *themed_icon; + const char *name; + + name = wnck_window_get_class_instance_name (window); + themed_icon = gtk_icon_theme_load_icon (gtk_icon_theme_get_default (), name, size, + GTK_ICON_LOOKUP_FORCE_SIZE, NULL); + if (themed_icon) + pixbuf = gdk_pixbuf_copy (themed_icon); + } + + return pixbuf; +} static void xfce_tasklist_get_property (GObject *object, @@ -2553,14 +2585,7 @@ xfce_tasklist_button_icon_changed (WnckWindow *window, context = gtk_widget_get_style_context (GTK_WIDGET (child->icon)); /* get the window icon */ - if (tasklist->show_labels || - child->type == CHILD_TYPE_GROUP_MENU) - pixbuf = wnck_window_get_mini_icon (window); - else if (icon_size <= 31) - pixbuf = wnck_window_get_mini_icon (window); - else - pixbuf = wnck_window_get_icon (window); - + pixbuf = xfce_tasklist_get_window_icon (child->window, tasklist->show_labels, icon_size, child->type); /* leave when there is no valid pixbuf */ if (G_UNLIKELY (pixbuf == NULL)) { @@ -3264,7 +3289,7 @@ xfce_tasklist_button_drag_begin (GtkWidget *button, } #endif - pixbuf = wnck_window_get_icon (child->window); + pixbuf = xfce_tasklist_get_window_icon (child->window, FALSE, 32, CHILD_TYPE_WINDOW); if (G_LIKELY (pixbuf != NULL)) gtk_drag_set_icon_pixbuf (context, pixbuf, 0, 0); } -- 2.19.1