Enlightenment CVS committal Author : sebastid Project : e17 Module : libs/ecore
Dir : e17/libs/ecore/src/lib/ecore_x Modified Files: Ecore_X.h ecore_x_netwm.c Log Message: Fetch all netwm icons. =================================================================== RCS file: /cvsroot/enlightenment/e17/libs/ecore/src/lib/ecore_x/Ecore_X.h,v retrieving revision 1.145 retrieving revision 1.146 diff -u -3 -r1.145 -r1.146 --- Ecore_X.h 14 Sep 2005 03:26:23 -0000 1.145 +++ Ecore_X.h 25 Sep 2005 16:48:30 -0000 1.146 @@ -60,6 +60,11 @@ 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 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); =================================================================== RCS file: /cvsroot/enlightenment/e17/libs/ecore/src/lib/ecore_x/ecore_x_netwm.c,v retrieving revision 1.42 retrieving revision 1.43 diff -u -3 -r1.42 -r1.43 --- ecore_x_netwm.c 25 Sep 2005 02:14:01 -0000 1.42 +++ ecore_x_netwm.c 25 Sep 2005 16:48:30 -0000 1.43 @@ -623,16 +623,16 @@ } 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 @@ data = (unsigned int *)data_ret; - if (icon) - { - *icon = malloc((num_ret - 2) * sizeof(unsigned int)); - if (!(*icon)) return 0; + /* Check how many icons there are */ + icons = 0; + p = data; + while (p) + { + 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 (num) *num = (num_ret - 2); - if (width) *width = data[0]; - if (height) *height = data[1]; + /* If the user doesn't want the icons, return */ + if (!icon) + { + free(data_ret); + return 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; ------------------------------------------------------- SF.Net email is sponsored by: Tame your development challenges with Apache's Geronimo App Server. Download it for free - -and be entered to win a 42" plasma tv or your very own Sony(tm)PSP. Click here to play: http://sourceforge.net/geronimo.php _______________________________________________ enlightenment-cvs mailing list enlightenment-cvs@lists.sourceforge.net https://lists.sourceforge.net/lists/listinfo/enlightenment-cvs