Fix crash when _NET_WM_ICON is set but empty
This commit is contained in:
parent
f351b6fd8e
commit
82776df9d6
2 changed files with 20 additions and 17 deletions
|
@ -276,25 +276,25 @@ void task_update_icon(Task *task)
|
||||||
Imlib_Image img = NULL;
|
Imlib_Image img = NULL;
|
||||||
|
|
||||||
if (!img) {
|
if (!img) {
|
||||||
int i;
|
int len;
|
||||||
gulong *data = server_get_property(task->win, server.atom._NET_WM_ICON, XA_CARDINAL, &i);
|
gulong *data = server_get_property(task->win, server.atom._NET_WM_ICON, XA_CARDINAL, &len);
|
||||||
if (data) {
|
if (data && len > 0) {
|
||||||
// get ARGB icon
|
// get ARGB icon
|
||||||
int w, h;
|
int w, h;
|
||||||
gulong *tmp_data;
|
gulong *tmp_data = get_best_icon(data, get_icon_count(data, len), len, &w, &h, panel->g_task.icon_size1);
|
||||||
|
if (tmp_data) {
|
||||||
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);
|
if (0 && img)
|
||||||
if (0 && img)
|
fprintf(stderr,
|
||||||
fprintf(stderr,
|
"%s: Got %dx%d icon via _NET_WM_ICON for %s\n",
|
||||||
"%s: Got %dx%d icon via _NET_WM_ICON for %s\n",
|
__FUNCTION__,
|
||||||
__FUNCTION__,
|
w,
|
||||||
w,
|
h,
|
||||||
h,
|
task->title ? task->title : "task");
|
||||||
task->title ? task->title : "task");
|
}
|
||||||
XFree(data);
|
XFree(data);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -277,6 +277,9 @@ int get_icon_count(gulong *data, int num)
|
||||||
|
|
||||||
gulong *get_best_icon(gulong *data, int icon_count, int num, int *iw, int *ih, int best_icon_size)
|
gulong *get_best_icon(gulong *data, int icon_count, int num, int *iw, int *ih, int best_icon_size)
|
||||||
{
|
{
|
||||||
|
if (icon_count < 1 || num < 1)
|
||||||
|
return NULL;
|
||||||
|
|
||||||
int width[icon_count], height[icon_count], pos, i, w, h;
|
int width[icon_count], height[icon_count], pos, i, w, h;
|
||||||
gulong *icon_data[icon_count];
|
gulong *icon_data[icon_count];
|
||||||
|
|
||||||
|
|
Loading…
Reference in a new issue