When WM_HINTS changes for a window, reload the icon

This commit is contained in:
o9000 2016-08-20 18:07:18 +02:00
parent cbb76849ea
commit 008eebe4b1
2 changed files with 26 additions and 16 deletions

View file

@ -268,21 +268,26 @@ void task_update_icon(Task *task)
Imlib_Image img = NULL; Imlib_Image img = NULL;
int i; if (!img) {
gulong *data = server_get_property(task->win, server.atom._NET_WM_ICON, XA_CARDINAL, &i); int i;
if (data) { gulong *data = server_get_property(task->win, server.atom._NET_WM_ICON, XA_CARDINAL, &i);
// get ARGB icon if (data) {
int w, h; // get ARGB icon
gulong *tmp_data; int w, h;
gulong *tmp_data;
tmp_data = get_best_icon(data, get_icon_count(data, i), i, &w, &h, panel->g_task.icon_size1); tmp_data = get_best_icon(data, get_icon_count(data, i), i, &w, &h, panel->g_task.icon_size1);
DATA32 icon_data[w * h]; DATA32 icon_data[w * h];
for (int j = 0; j < w * h; ++j) for (int j = 0; j < w * h; ++j)
icon_data[j] = tmp_data[j]; icon_data[j] = tmp_data[j];
img = imlib_create_image_using_copied_data(w, h, icon_data); img = imlib_create_image_using_copied_data(w, h, icon_data);
XFree(data); if (img)
} else { fprintf(stderr, "%s: Got %dx%d icon via _NET_WM_ICON for %s\n", __FUNCTION__, w, h, task->title ? task->title : "task");
// get Pixmap icon XFree(data);
}
}
if (!img) {
XWMHints *hints = XGetWMHints(server.display, task->win); XWMHints *hints = XGetWMHints(server.display, task->win);
if (hints) { if (hints) {
if (hints->flags & IconPixmapHint && hints->icon_pixmap != 0) { if (hints->flags & IconPixmapHint && hints->icon_pixmap != 0) {
@ -292,17 +297,20 @@ void task_update_icon(Task *task)
uint border_width, bpp; uint border_width, bpp;
uint w, h; uint w, h;
// printf(" get pixmap\n");
XGetGeometry(server.display, hints->icon_pixmap, &root, &icon_x, &icon_y, &w, &h, &border_width, &bpp); XGetGeometry(server.display, hints->icon_pixmap, &root, &icon_x, &icon_y, &w, &h, &border_width, &bpp);
imlib_context_set_drawable(hints->icon_pixmap); imlib_context_set_drawable(hints->icon_pixmap);
img = imlib_create_image_from_drawable(hints->icon_mask, 0, 0, w, h, 0); img = imlib_create_image_from_drawable(hints->icon_mask, 0, 0, w, h, 0);
if (img)
fprintf(stderr, "%s: Got %dx%d pixmap icon via WM_HINTS for %s\n", __FUNCTION__, w, h, task->title ? task->title : "task");
} }
XFree(hints); XFree(hints);
} }
} }
if (img == NULL) { if (img == NULL) {
imlib_context_set_image(default_icon); imlib_context_set_image(default_icon);
img = imlib_clone_image(); img = imlib_clone_image();
fprintf(stderr, "%s: Using default icon for %s\n", __FUNCTION__, task->title ? task->title : "task");
} }
// transform icons // transform icons
@ -348,7 +356,7 @@ void task_update_icon(Task *task)
GPtrArray *task_buttons = get_task_buttons(task->win); GPtrArray *task_buttons = get_task_buttons(task->win);
if (task_buttons) { if (task_buttons) {
for (i = 0; i < task_buttons->len; ++i) { for (int i = 0; i < task_buttons->len; ++i) {
Task *task2 = g_ptr_array_index(task_buttons, i); Task *task2 = g_ptr_array_index(task_buttons, i);
task2->icon_width = task->icon_width; task2->icon_width = task->icon_width;
task2->icon_height = task->icon_height; task2->icon_height = task->icon_height;

View file

@ -1203,6 +1203,8 @@ void event_property_notify(XEvent *e)
add_urgent(task); add_urgent(task);
} }
XFree(wmhints); XFree(wmhints);
task_update_icon(task);
panel_refresh = TRUE;
} }
if (!server.got_root_win) if (!server.got_root_win)