From f0202d90240fb916442dfaacdfe88b73c47948e4 Mon Sep 17 00:00:00 2001 From: sebastid Date: Sun, 25 Sep 2005 16:48:30 +0000 Subject: [PATCH] Fetch all netwm icons. SVN revision: 16935 --- legacy/ecore/src/lib/ecore_x/Ecore_X.h | 7 +- legacy/ecore/src/lib/ecore_x/ecore_x_netwm.c | 77 +++++++++++++++----- 2 files changed, 65 insertions(+), 19 deletions(-) diff --git a/legacy/ecore/src/lib/ecore_x/Ecore_X.h b/legacy/ecore/src/lib/ecore_x/Ecore_X.h index 5e319b4717..f3840e2a26 100644 --- a/legacy/ecore/src/lib/ecore_x/Ecore_X.h +++ b/legacy/ecore/src/lib/ecore_x/Ecore_X.h @@ -60,6 +60,11 @@ typedef struct _Ecore_X_Rectangle { unsigned int width, height; } Ecore_X_Rectangle; +typedef struct _Ecore_X_Icon { + unsigned int width, height; + unsigned int *data; +} Ecore_X_Icon; + typedef enum _Ecore_X_Window_State { /** The window is iconified. */ ECORE_X_WINDOW_STATE_ICONIFIED, @@ -1217,7 +1222,7 @@ EAPI void ecore_x_netwm_strut_set(Ecore_X_Window win, int left, i EAPI int ecore_x_netwm_strut_get(Ecore_X_Window win, int *left, int *right, int *top, int *bottom); EAPI void ecore_x_netwm_strut_partial_set(Ecore_X_Window win, int left, int right, int top, int bottom, int left_start_y, int left_end_y, int right_start_y, int right_end_y, int top_start_x, int top_end_x, int bottom_start_x, int bottom_end_x); EAPI int ecore_x_netwm_strut_partial_get(Ecore_X_Window win, int *left, int *right, int *top, int *bottom, int *left_start_y, int *left_end_y, int *right_start_y, int *right_end_y, int *top_start_x, int *top_end_x, int *bottom_start_x, int *bottom_end_x); -EAPI int ecore_x_netwm_icon_get(Ecore_X_Window win, int *width, int *height, unsigned int **data, int *num); +EAPI int ecore_x_netwm_icons_get(Ecore_X_Window win, Ecore_X_Icon **icon, int *num); EAPI void ecore_x_netwm_icon_geometry_set(Ecore_X_Window win, int x, int y, int width, int height); EAPI int ecore_x_netwm_icon_geometry_get(Ecore_X_Window win, int *x, int *y, int *width, int *height); EAPI void ecore_x_netwm_pid_set(Ecore_X_Window win, int pid); diff --git a/legacy/ecore/src/lib/ecore_x/ecore_x_netwm.c b/legacy/ecore/src/lib/ecore_x/ecore_x_netwm.c index 7d0005b267..0ddf40ec2c 100644 --- a/legacy/ecore/src/lib/ecore_x/ecore_x_netwm.c +++ b/legacy/ecore/src/lib/ecore_x/ecore_x_netwm.c @@ -623,16 +623,16 @@ ecore_x_netwm_strut_partial_get(Ecore_X_Window win, int *left, int *right, } int -ecore_x_netwm_icon_get(Ecore_X_Window win, int *width, int *height, unsigned int **icon, int *num) +ecore_x_netwm_icons_get(Ecore_X_Window win, Ecore_X_Icon **icon, int *num) { unsigned char *data_ret; - unsigned int *data; + unsigned int *data, *p; unsigned int *src; - int num_ret, len; + unsigned int len, icons, i; + int num_ret; - if (width) *width = 0; - if (height) *height = 0; if (num) *num = 0; + if (icon) *icon = NULL; if (!ecore_x_window_prop_property_get(win, ECORE_X_ATOM_NET_WM_ICON, XA_CARDINAL, 32, &data_ret, &num_ret)) @@ -646,26 +646,67 @@ ecore_x_netwm_icon_get(Ecore_X_Window win, int *width, int *height, unsigned int data = (unsigned int *)data_ret; - if (icon) + /* Check how many icons there are */ + icons = 0; + p = data; + while (p) { - *icon = malloc((num_ret - 2) * sizeof(unsigned int)); - if (!(*icon)) return 0; + len = p[0] * p[1]; + p += (len + 2); + if ((p - data) > num_ret) + { + free(data_ret); + return 0; + } + icons++; + + if ((p - data) == num_ret) + p = NULL; + } + if (num) *num = icons; + + /* If the user doesn't want the icons, return */ + if (!icon) + { + free(data_ret); + return 1; } - if (num) *num = (num_ret - 2); - if (width) *width = data[0]; - if (height) *height = data[1]; - - len = data[0] * data[1]; - src = &(data[2]); - if (len != (num_ret - 2)) + /* Allocate memory */ + *icon = malloc(icons * sizeof(Ecore_X_Icon)); + if (!(*icon)) { - if (icon) free(*icon); free(data_ret); return 0; } - if (icon) memcpy(*icon, src, len * sizeof(unsigned int)); - + + for (i = 0; i < icons; i++) + { + ((*icon)[i]).data = malloc(len * sizeof(unsigned int)); + if (!((*icon)[i]).data) + { + while (i) + free(((*icon)[--i]).data); + free(*icon); + free(data_ret); + return 0; + } + } + + /* Fetch the icons */ + p = data; + for (i = 0; i < icons; i++) + { + len = p[0] * p[1]; + ((*icon)[i]).width = p[0]; + ((*icon)[i]).height = p[1]; + src = &(p[2]); + ((*icon)[i]).data = malloc(len * sizeof(unsigned int)); + memcpy(((*icon)[i]).data, src, len * sizeof(unsigned int)); + + p += (len + 2); + } + free(data_ret); return 1;