Enlightenment CVS committal

Author  : kwo
Project : e17
Module  : libs/ecore

Dir     : e17/libs/ecore/src/lib/ecore_x


Modified Files:
        Ecore_X.h ecore_x_icccm.c ecore_x_netwm.c 
        ecore_x_window_prop.c 


Log Message:
Add some utility functions for get/setting window properties.
Move a number of ecore_x_window_prop_property_get/set calls to the new ones.
Eliminate broken (64bit arch) _ATOM_SET_... macros.
New functions should be solid as they have been in e16 for ages.
Changes in ecore_x_icccm/netwm.c have not been tested thoroughly.

===================================================================
RCS file: /cvsroot/enlightenment/e17/libs/ecore/src/lib/ecore_x/Ecore_X.h,v
retrieving revision 1.152
retrieving revision 1.153
diff -u -3 -r1.152 -r1.153
--- Ecore_X.h   27 Dec 2005 17:17:31 -0000      1.152
+++ Ecore_X.h   5 Jan 2006 21:41:30 -0000       1.153
@@ -941,6 +941,12 @@
 #define ECORE_X_WINDOW_LAYER_NORMAL 4
 #define ECORE_X_WINDOW_LAYER_ABOVE 6
 
+/* Property list operations */
+#define ECORE_X_PROP_LIST_REMOVE    0
+#define ECORE_X_PROP_LIST_ADD       1
+#define ECORE_X_PROP_LIST_TOGGLE    2
+
+
 EAPI int              ecore_x_init(const char *name);
 EAPI int              ecore_x_shutdown(void);       
 EAPI int              ecore_x_disconnect(void);       
@@ -1053,6 +1059,56 @@
                                                     unsigned int *val, 
unsigned int num);
 EAPI int              ecore_x_window_prop_card32_get(Ecore_X_Window win, 
Ecore_X_Atom atom,
                                                     unsigned int *val, 
unsigned int len);
+EAPI int              ecore_x_window_prop_card32_list_get(Ecore_X_Window win,
+                                                          Ecore_X_Atom atom,
+                                                          unsigned int **plst);
+
+EAPI void             ecore_x_window_prop_xid_set(Ecore_X_Window win,
+                                                  Ecore_X_Atom atom,
+                                                  Ecore_X_Atom type,
+                                                  Ecore_X_ID * lst,
+                                                  unsigned int num);
+EAPI int              ecore_x_window_prop_xid_get(Ecore_X_Window win,
+                                                  Ecore_X_Atom atom,
+                                                  Ecore_X_Atom type,
+                                                  Ecore_X_ID * lst,
+                                                  unsigned int len);
+EAPI int              ecore_x_window_prop_xid_list_get(Ecore_X_Window win,
+                                                       Ecore_X_Atom atom,
+                                                       Ecore_X_Atom type,
+                                                       Ecore_X_ID ** plst);
+EAPI void             ecore_x_window_prop_xid_list_change(Ecore_X_Window win,
+                                                          Ecore_X_Atom atom,
+                                                          Ecore_X_Atom type,
+                                                          Ecore_X_ID item,
+                                                          int op);
+EAPI void             ecore_x_window_prop_atom_set(Ecore_X_Window win,
+                                                   Ecore_X_Atom atom,
+                                                   Ecore_X_Atom * val,
+                                                   unsigned int num);
+EAPI int              ecore_x_window_prop_atom_get(Ecore_X_Window win,
+                                                   Ecore_X_Atom atom,
+                                                   Ecore_X_Atom * val,
+                                                   unsigned int len);
+EAPI int              ecore_x_window_prop_atom_list_get(Ecore_X_Window win,
+                                                        Ecore_X_Atom atom,
+                                                        Ecore_X_Atom ** plst);
+EAPI void             ecore_x_window_prop_atom_list_change(Ecore_X_Window win,
+                                                           Ecore_X_Atom atom,
+                                                           Ecore_X_Atom item,
+                                                           int op); 
+EAPI void             ecore_x_window_prop_window_set(Ecore_X_Window win,
+                                                     Ecore_X_Atom atom,
+                                                     Ecore_X_Window * val,
+                                                     unsigned int num);
+EAPI int              ecore_x_window_prop_window_get(Ecore_X_Window win,
+                                                     Ecore_X_Atom atom,
+                                                     Ecore_X_Window * val,
+                                                     unsigned int len);
+EAPI int              ecore_x_window_prop_window_list_get(Ecore_X_Window win,
+                                                          Ecore_X_Atom atom,
+                                                          Ecore_X_Window ** 
plst);
+
 EAPI Ecore_X_Atom     ecore_x_window_prop_any_type(void);
 EAPI void             ecore_x_window_prop_property_set(Ecore_X_Window win, 
Ecore_X_Atom type, Ecore_X_Atom format, int size, void *data, int number);
 EAPI int              ecore_x_window_prop_property_get(Ecore_X_Window win, 
Ecore_X_Atom property, Ecore_X_Atom type, int size, unsigned char **data, int 
*num);
===================================================================
RCS file: 
/cvsroot/enlightenment/e17/libs/ecore/src/lib/ecore_x/ecore_x_icccm.c,v
retrieving revision 1.38
retrieving revision 1.39
diff -u -3 -r1.38 -r1.39
--- ecore_x_icccm.c     7 Sep 2005 09:50:14 -0000       1.38
+++ ecore_x_icccm.c     5 Jan 2006 21:41:30 -0000       1.39
@@ -1024,9 +1024,8 @@
 void
 ecore_x_icccm_client_leader_set(Ecore_X_Window win, Ecore_X_Window l)
 {
-   ecore_x_window_prop_property_set(win,
-                                   ECORE_X_ATOM_WM_CLIENT_LEADER,
-                                   XA_WINDOW, 32, &l, 1);
+   ecore_x_window_prop_window_set(win, ECORE_X_ATOM_WM_CLIENT_LEADER,
+                                 &l, 1);
 }
 
 /**
@@ -1036,22 +1035,11 @@
 Ecore_X_Window
 ecore_x_icccm_client_leader_get(Ecore_X_Window win)
 {
-   unsigned char      *data;
-   int                 num;
+   Ecore_X_Window      l;
 
-   if (ecore_x_window_prop_property_get(win,
-                                       ECORE_X_ATOM_WM_CLIENT_LEADER,
-                                       XA_WINDOW, 32, &data, &num))
-     {
-       if (data) 
-         {
-            Ecore_X_Window wlead;
-            
-            wlead = *((Ecore_X_Window *)data);
-            free(data);
-            return wlead;
-         }
-     }
+   if (ecore_x_window_prop_window_get(win, ECORE_X_ATOM_WM_CLIENT_LEADER,
+                                     &l, 1) > 0)
+      return l;
    return 0;
 }
 
===================================================================
RCS file: 
/cvsroot/enlightenment/e17/libs/ecore/src/lib/ecore_x/ecore_x_netwm.c,v
retrieving revision 1.47
retrieving revision 1.48
diff -u -3 -r1.47 -r1.48
--- ecore_x_netwm.c     9 Oct 2005 09:56:47 -0000       1.47
+++ ecore_x_netwm.c     5 Jan 2006 21:41:30 -0000       1.48
@@ -49,21 +49,9 @@
 #define _ATOM_GET(name) \
    XInternAtom(_ecore_x_disp, name, False)
 
-#define _ATOM_SET_UTF8_STRING(win, atom, string) \
-   XChangeProperty(_ecore_x_disp, win, atom, ECORE_X_ATOM_UTF8_STRING, 8, 
PropModeReplace, \
-                   (unsigned char *)string, strlen(string))
 #define _ATOM_SET_UTF8_STRING_LIST(win, atom, string, cnt) \
    XChangeProperty(_ecore_x_disp, win, atom, ECORE_X_ATOM_UTF8_STRING, 8, 
PropModeReplace, \
                    (unsigned char *)string, cnt)
-#define _ATOM_SET_WINDOW(win, atom, p_wins, cnt) \
-   XChangeProperty(_ecore_x_disp, win, atom, XA_WINDOW, 32, PropModeReplace, \
-                   (unsigned char *)p_wins, cnt)
-#define _ATOM_SET_ATOM(win, atom, p_atom, cnt) \
-   XChangeProperty(_ecore_x_disp, win, atom, XA_ATOM, 32, PropModeReplace, \
-                   (unsigned char *)p_atom, cnt)
-#define _ATOM_SET_CARD32(win, atom, p_val, cnt) \
-   XChangeProperty(_ecore_x_disp, win, atom, XA_CARDINAL, 32, PropModeReplace, 
\
-                   (unsigned char *)p_val, cnt)
 
 /*
  * Local variables
@@ -281,11 +269,11 @@
 ecore_x_netwm_wm_identify(Ecore_X_Window root, Ecore_X_Window check,
                          const char *wm_name)
 {
-   _ATOM_SET_WINDOW(root, ECORE_X_ATOM_NET_SUPPORTING_WM_CHECK, &check, 1);
-   _ATOM_SET_WINDOW(check, ECORE_X_ATOM_NET_SUPPORTING_WM_CHECK, &check, 1);
-   _ATOM_SET_UTF8_STRING(check, ECORE_X_ATOM_NET_WM_NAME, wm_name);
+   ecore_x_window_prop_window_set(root, ECORE_X_ATOM_NET_SUPPORTING_WM_CHECK, 
&check, 1);
+   ecore_x_window_prop_window_set(check, ECORE_X_ATOM_NET_SUPPORTING_WM_CHECK, 
&check, 1);
+   _ecore_x_window_prop_string_utf8_set(check, ECORE_X_ATOM_NET_WM_NAME, 
wm_name);
    /* This one isn't mandatory */
-   _ATOM_SET_UTF8_STRING(root, ECORE_X_ATOM_NET_WM_NAME, wm_name);
+   _ecore_x_window_prop_string_utf8_set(root, ECORE_X_ATOM_NET_WM_NAME, 
wm_name);
 }
 
 /*
@@ -294,26 +282,23 @@
 void
 ecore_x_netwm_supported_set(Ecore_X_Window root, Ecore_X_Atom *supported, int 
num)
 {
-   _ATOM_SET_ATOM(root, ECORE_X_ATOM_NET_SUPPORTED, supported, num);
+   ecore_x_window_prop_atom_set(root, ECORE_X_ATOM_NET_SUPPORTED, supported, 
num);
 }
 
 int
 ecore_x_netwm_supported_get(Ecore_X_Window root, Ecore_X_Atom **supported, int 
*num)
 {
    int            num_ret;
-   unsigned char *data;
 
    if (num) *num = 0;
    if (supported) *supported = NULL;
 
-   if (!ecore_x_window_prop_property_get(root, ECORE_X_ATOM_NET_SUPPORTED,
-                                        XA_ATOM, 32, &data, &num_ret))
+   num_ret = ecore_x_window_prop_atom_list_get(root, 
ECORE_X_ATOM_NET_SUPPORTED,
+                                              supported);
+   if (num_ret <= 0)
       return 0;
 
-   if ((!data) || (!num_ret)) return 0;
-
    if (num) *num = num_ret;
-   if (supported) *supported = (Ecore_X_Atom *)data;
    return 1;
 }
 
@@ -331,7 +316,7 @@
 ecore_x_netwm_desk_roots_set(Ecore_X_Window root,
                             Ecore_X_Window *vroots, unsigned int n_desks)
 {
-   _ATOM_SET_WINDOW(root, ECORE_X_ATOM_NET_VIRTUAL_ROOTS, vroots, n_desks);
+   ecore_x_window_prop_window_set(root, ECORE_X_ATOM_NET_VIRTUAL_ROOTS, 
vroots, n_desks);
 }
 
 void
@@ -436,7 +421,8 @@
 ecore_x_netwm_client_list_set(Ecore_X_Window root,
                              Ecore_X_Window *p_clients, unsigned int n_clients)
 {
-   _ATOM_SET_WINDOW(root, ECORE_X_ATOM_NET_CLIENT_LIST, p_clients, n_clients);
+   ecore_x_window_prop_window_set(root, ECORE_X_ATOM_NET_CLIENT_LIST,
+                                 p_clients, n_clients);
 }
 
 /* Stacking order */
@@ -445,14 +431,15 @@
                                       Ecore_X_Window *p_clients,
                                       unsigned int n_clients)
 {
-   _ATOM_SET_WINDOW(root, ECORE_X_ATOM_NET_CLIENT_LIST_STACKING, p_clients,
-                   n_clients);
+   ecore_x_window_prop_window_set(root, ECORE_X_ATOM_NET_CLIENT_LIST_STACKING,
+                                 p_clients, n_clients);
 }
 
 void
 ecore_x_netwm_client_active_set(Ecore_X_Window root, Ecore_X_Window win)
 {
-   _ATOM_SET_WINDOW(root, ECORE_X_ATOM_NET_ACTIVE_WINDOW, &win, 1);
+   ecore_x_window_prop_window_set(root, ECORE_X_ATOM_NET_ACTIVE_WINDOW,
+                                 &win, 1);
 }
 
 void
@@ -642,7 +629,6 @@
 int
 ecore_x_netwm_icons_get(Ecore_X_Window win, Ecore_X_Icon **icon, int *num)
 {
-   unsigned char *data_ret;
    unsigned int  *data, *p;
    unsigned int  *src;
    unsigned int   len, icons, i;
@@ -651,18 +637,17 @@
    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))
+   num_ret = ecore_x_window_prop_card32_list_get(win, ECORE_X_ATOM_NET_WM_ICON,
+                                                &data);
+   if (num_ret <= 0)
      return 0;
-   if (!data_ret) return 0;
+   if (!data) return 0;
    if (num_ret < 2)
      {
-       free(data_ret);
+       free(data);
        return 0;
      }
 
-   data = (unsigned int *)data_ret;
-
    /* Check how many icons there are */
    icons = 0;
    p = data;
@@ -672,7 +657,7 @@
        p += (len + 2);
        if ((p - data) > num_ret)
          {
-            free(data_ret);
+            free(data);
             return 0;
          }
        icons++;
@@ -685,7 +670,7 @@
    /* If the user doesn't want the icons, return */
    if (!icon)
      {
-       free(data_ret);
+       free(data);
        return 1;
      }
 
@@ -693,7 +678,7 @@
    *icon = malloc(icons * sizeof(Ecore_X_Icon));
    if (!(*icon))
      {
-       free(data_ret);
+       free(data);
        return 0;
      }
 
@@ -711,7 +696,7 @@
             while (i)
               free(((*icon)[--i]).data);
             free(*icon);
-            free(data_ret);
+            free(data);
             return 0;
          }
 
@@ -720,7 +705,7 @@
        p += (len + 2);
      }
 
-   free(data_ret);
+   free(data);
 
    return 1;
 }
@@ -879,7 +864,6 @@
 void
 ecore_x_netwm_window_state_set(Ecore_X_Window win, Ecore_X_Window_State 
*state, unsigned int num)
 {
-   unsigned char *data;
    Ecore_X_Atom  *set;
    int            i;
 
@@ -889,36 +873,31 @@
        return;
      }
 
-   data = malloc(num * sizeof(Ecore_X_Atom));
-   if (!data) return;
+   set = malloc(num * sizeof(Ecore_X_Atom));
+   if (!set) return;
 
-   set = (Ecore_X_Atom *) data;
    for (i = 0; i < num; i++)
      set[i] = _ecore_x_netwm_state_atom_get(state[i]);
 
-   _ATOM_SET_ATOM(win, ECORE_X_ATOM_NET_WM_STATE, data, num);
+   ecore_x_window_prop_atom_set(win, ECORE_X_ATOM_NET_WM_STATE, set, num);
 
-   free(data);
-   return;
+   free(set);
 }
 
 int
 ecore_x_netwm_window_state_get(Ecore_X_Window win, Ecore_X_Window_State 
**state, unsigned int *num)
 {
    int                   num_ret, i;
-   unsigned char        *data;
    Ecore_X_Atom         *atoms;
 
    if (num) *num = 0;
    if (state) *state = NULL;
 
-   if (!ecore_x_window_prop_property_get(win, ECORE_X_ATOM_NET_WM_STATE,
-                                        XA_ATOM, 32, &data, &num_ret))
+   num_ret = ecore_x_window_prop_atom_list_get(win, ECORE_X_ATOM_NET_WM_STATE,
+                                              &atoms);
+   if (num_ret <= 0)
       return 0;
 
-   if ((!data) || (!num_ret)) return 0;
-
-   atoms = (Ecore_X_Atom *) data;
    if (state)
      {
        *state = malloc(num_ret * sizeof(Ecore_X_Window_State));
@@ -929,7 +908,7 @@
        if (num) *num = num_ret;
      }
 
-   free(data);
+   free(atoms);
    return 1;
 }
 
@@ -992,8 +971,8 @@
    Ecore_X_Atom atom;
 
    atom = _ecore_x_netwm_window_type_atom_get(type);
-   ecore_x_window_prop_property_set(win, ECORE_X_ATOM_NET_WM_WINDOW_TYPE,
-                                   XA_ATOM, 32, (unsigned char *)&atom, 1);
+   ecore_x_window_prop_atom_set(win, ECORE_X_ATOM_NET_WM_WINDOW_TYPE,
+                               &atom, 1);
 }
 
 /* FIXME: Maybe return 0 on some conditions? */
@@ -1001,22 +980,21 @@
 ecore_x_netwm_window_type_get(Ecore_X_Window win, Ecore_X_Window_Type *type)
 {
    int                  num, i;
-   unsigned char       *data;
    Ecore_X_Atom        *atoms;
 
    if (type) *type = ECORE_X_WINDOW_TYPE_NORMAL;
 
-   if (!ecore_x_window_prop_property_get(win, ECORE_X_ATOM_NET_WM_WINDOW_TYPE,
-                                        XA_ATOM, 32, &data, &num))
+   num = ecore_x_window_prop_atom_list_get(win, 
ECORE_X_ATOM_NET_WM_WINDOW_TYPE,
+                                          &atoms);
+   if (num < 0)
      {
+       /* IMO this is not the place to mix netwm and icccm /kwo */
        /* Check if WM_TRANSIENT_FOR is set */
        if ((type) && (ecore_x_icccm_transient_for_get(win)))
          *type = ECORE_X_WINDOW_TYPE_DIALOG;
        return 1;
      }
 
-   atoms = (Ecore_X_Atom *) data;
-
    if (type)
      {
        for (i = 0; i < num; ++i)
@@ -1027,7 +1005,7 @@
          }
      }
 
-   free(data);
+   free(atoms);
    return 1;
 }
 
@@ -1066,15 +1044,14 @@
 ecore_x_netwm_allowed_action_isset(Ecore_X_Window win, Ecore_X_Action action)
 {
    int                  num, i, ret = 0;
-   unsigned char       *data;
    Ecore_X_Atom        *atoms, atom;
 
-   if (!ecore_x_window_prop_property_get(win, ECORE_X_ATOM_NET_WM_WINDOW_TYPE,
-                                        XA_ATOM, 32, &data, &num))
+   num = ecore_x_window_prop_atom_list_get(win, 
ECORE_X_ATOM_NET_WM_WINDOW_TYPE,
+                                          &atoms);
+   if (num <= 0)
      return ret;
 
    atom = _ecore_x_netwm_action_atom_get(action);
-   atoms = (Ecore_X_Atom *) data;
 
    for (i = 0; i < num; ++i)
      {
@@ -1085,7 +1062,7 @@
          }
      }
 
-   free(data);
+   free(atoms);
    return ret;
 }
 
@@ -1093,66 +1070,13 @@
 void
 ecore_x_netwm_allowed_action_set(Ecore_X_Window win, Ecore_X_Action action, 
int on)
 {
-   Ecore_X_Atom      atom;
-   Ecore_X_Atom      *oldset = NULL, *newset = NULL;
-   int               i, j = 0, num = 0;
-   unsigned char     *data = NULL;
-   unsigned char     *old_data = NULL;
+   Ecore_X_Atom atom;
 
    atom = _ecore_x_netwm_action_atom_get(action);
+   on = (on) ? ECORE_X_PROP_LIST_ADD : ECORE_X_PROP_LIST_REMOVE;
 
-   ecore_x_window_prop_property_get(win, ECORE_X_ATOM_NET_WM_ALLOWED_ACTIONS,
-                                    XA_ATOM, 32, &old_data, &num);
-   oldset = (Ecore_X_Atom *) old_data;
-
-   if (on)
-     {
-       for (i = 0; i < num; ++i)
-         {
-            if (oldset[i] == atom)
-              goto done;
-         }
-
-       newset = calloc(num + 1, sizeof(Ecore_X_Atom));
-       if (!newset)
-         goto done;
-
-       data = (unsigned char *) newset;
-       for (i = 0; i < num; i++)
-         newset[i] = oldset[i];
-       newset[num] = atom;
-
-       ecore_x_window_prop_property_set(win, 
ECORE_X_ATOM_NET_WM_ALLOWED_ACTIONS,
-                                        XA_ATOM, 32, data, num + 1);
-     }
-   else
-     {
-       int has;
-
-       has = 0;
-       for (i = 0; i < num; ++i)
-         {
-            if (oldset[i] == atom)
-              has = 1;
-         }
-       if (!has)
-         goto done;
-
-       newset = calloc(num - 1, sizeof(Ecore_X_Atom));
-       if (!newset)
-         goto done;
-
-       data = (unsigned char *) newset;
-       for (i = 0; i < num; i++)
-         if (oldset[i] != atom)
-           newset[j++] = oldset[i];
-
-       ecore_x_window_prop_property_set(win, 
ECORE_X_ATOM_NET_WM_ALLOWED_ACTIONS,
-                                        XA_ATOM, 32, data, num - 1);
-     }
-   free(newset);
-done:
-   free(oldset);
+   ecore_x_window_prop_atom_list_change(win, 
ECORE_X_ATOM_NET_WM_ALLOWED_ACTIONS,
+                                        atom, on);
 }
 
 void
@@ -1388,7 +1312,8 @@
 _ecore_x_window_prop_string_utf8_set(Ecore_X_Window win, Ecore_X_Atom atom,
                                     const char *str)
 {
-   _ATOM_SET_UTF8_STRING(win, atom, str);
+   XChangeProperty(_ecore_x_disp, win, atom, ECORE_X_ATOM_UTF8_STRING, 8,
+                  PropModeReplace, (unsigned char *)str, strlen(str));
 }
 
 /*
===================================================================
RCS file: 
/cvsroot/enlightenment/e17/libs/ecore/src/lib/ecore_x/ecore_x_window_prop.c,v
retrieving revision 1.78
retrieving revision 1.79
diff -u -3 -r1.78 -r1.79
--- ecore_x_window_prop.c       7 Sep 2005 23:21:42 -0000       1.78
+++ ecore_x_window_prop.c       5 Jan 2006 21:41:30 -0000       1.79
@@ -78,6 +78,316 @@
    return num;
 }
 
+/*
+ * Get CARD32 (array) property of any length
+ *
+ * If the property was successfully fetched the number of items stored in
+ * val is returned, otherwise -1 is returned.
+ * Note: Return value 0 means that the property exists but has no elements.
+ */
+int
+ecore_x_window_prop_card32_list_get(Ecore_X_Window win, Ecore_X_Atom atom,
+                                   unsigned int **plst)
+{
+   unsigned char      *prop_ret;
+   Atom                type_ret;
+   unsigned long       bytes_after, num_ret;
+   int                 format_ret;
+   unsigned int        i, *val;
+   int                 num;
+
+   prop_ret = NULL;
+   if (XGetWindowProperty(_ecore_x_disp, win, atom, 0, 0x7fffffff, False,
+                         XA_CARDINAL, &type_ret, &format_ret, &num_ret,
+                         &bytes_after, &prop_ret) != Success)
+      return -1;
+
+   if (type_ret == None || num_ret == 0)
+     {
+       num = 0;
+       *plst = NULL;
+     }
+   else if (prop_ret && type_ret == XA_CARDINAL && format_ret == 32)
+     {
+       val = malloc(num_ret * sizeof(unsigned int));
+       for (i = 0; i < num_ret; i++)
+          val[i] = ((unsigned long *)prop_ret)[i];
+       num = num_ret;
+       *plst = val;
+     }
+   else
+     {
+       num = -1;
+       *plst = NULL;
+     }
+   if (prop_ret)
+      XFree(prop_ret);
+
+   return num;
+}
+
+/*
+ * Set X ID (array) property
+ */
+void
+ecore_x_window_prop_xid_set(Ecore_X_Window win, Ecore_X_Atom atom,
+                           Ecore_X_Atom type, Ecore_X_ID * lst,
+                           unsigned int num)
+{
+#if SIZEOF_INT == SIZEOF_LONG
+   XChangeProperty(_ecore_x_disp, win, atom, type, 32, PropModeReplace,
+                  (unsigned char *)lst, num);
+#else
+   unsigned long      *pl;
+   unsigned int        i;
+
+   pl = malloc(num * sizeof(long));
+   if (!pl)
+      return;
+   for (i = 0; i < num; i++)
+      pl[i] = lst[i];
+   XChangeProperty(_ecore_x_disp, win, atom, type, 32, PropModeReplace,
+                  (unsigned char *)pl, num);
+   free(pl);
+#endif
+}
+
+/*
+ * Get X ID (array) property
+ *
+ * At most len items are returned in val.
+ * If the property was successfully fetched the number of items stored in
+ * val is returned, otherwise -1 is returned.
+ * Note: Return value 0 means that the property exists but has no elements.
+ */
+int
+ecore_x_window_prop_xid_get(Ecore_X_Window win, Ecore_X_Atom atom,
+                           Ecore_X_Atom type, Ecore_X_ID * lst,
+                           unsigned int len)
+{
+   unsigned char      *prop_ret;
+   Atom                type_ret;
+   unsigned long       bytes_after, num_ret;
+   int                 format_ret;
+   int                 num;
+   unsigned            i;
+
+   prop_ret = NULL;
+   if (XGetWindowProperty(_ecore_x_disp, win, atom, 0, 0x7fffffff, False,
+                         type, &type_ret, &format_ret, &num_ret,
+                         &bytes_after, &prop_ret) != Success)
+      return -1;
+
+   if (type_ret == None)
+     {
+       num = 0;
+     }
+   else if (prop_ret && type_ret == type && format_ret == 32)
+     {
+       if (num_ret < len)
+          len = num_ret;
+       for (i = 0; i < len; i++)
+          lst[i] = ((unsigned long *)prop_ret)[i];
+       num = len;
+     }
+   else
+     {
+       num = -1;
+     }
+   if (prop_ret)
+      XFree(prop_ret);
+
+   return num;
+}
+
+/*
+ * Get X ID (array) property
+ *
+ * If the property was successfully fetched the number of items stored in
+ * val is returned, otherwise -1 is returned.
+ * The returned array must be freed with free().
+ * Note: Return value 0 means that the property exists but has no elements.
+ */
+int
+ecore_x_window_prop_xid_list_get(Ecore_X_Window win, Ecore_X_Atom atom,
+                                Ecore_X_Atom type, Ecore_X_ID ** val)
+{
+   unsigned char      *prop_ret;
+   Atom                type_ret;
+   unsigned long       bytes_after, num_ret;
+   int                 format_ret;
+   Ecore_X_Atom       *alst;
+   int                 num;
+   unsigned            i;
+
+   *val = NULL;
+   prop_ret = NULL;
+   if (XGetWindowProperty(_ecore_x_disp, win, atom, 0, 0x7fffffff, False,
+                         type, &type_ret, &format_ret, &num_ret,
+                         &bytes_after, &prop_ret) != Success)
+      return -1;
+
+   if (type_ret == None || num_ret == 0)
+     {
+       num = 0;
+     }
+   else if (prop_ret && type_ret == type && format_ret == 32)
+     {
+       alst = malloc(num_ret * sizeof(Ecore_X_ID));
+       for (i = 0; i < num_ret; i++)
+          alst[i] = ((unsigned long *)prop_ret)[i];
+       *val = alst;
+       num = num_ret;
+     }
+   else
+     {
+       num = -1;
+     }
+   if (prop_ret)
+      XFree(prop_ret);
+
+   return num;
+}
+
+/*
+ * Remove/add/toggle X ID list item.
+ */
+void
+ecore_x_window_prop_xid_list_change(Ecore_X_Window win, Ecore_X_Atom atom,
+                                   Ecore_X_Atom type, Ecore_X_ID item, int op)
+{
+   Ecore_X_ID         *lst;
+   int                 i, num;
+
+   num = ecore_x_window_prop_xid_list_get(win, atom, type, &lst);
+   if (num < 0)
+      return;                  /* Error - assuming invalid window */
+
+   /* Is it there? */
+   for (i = 0; i < num; i++)
+     {
+       if (lst[i] == item)
+          break;
+     }
+
+   if (i < num)
+     {
+       /* Was in list */
+       if (op == ECORE_X_PROP_LIST_ADD)
+          goto done;
+       /* Remove it */
+       num--;
+       for (; i < num; i++)
+          lst[i] = lst[i + 1];
+     }
+   else
+     {
+       /* Was not in list */
+       if (op == ECORE_X_PROP_LIST_REMOVE)
+          goto done;
+       /* Add it */
+       num++;
+       lst = realloc(lst, num * sizeof(Ecore_X_ID));
+       lst[i] = item;
+     }
+
+   ecore_x_window_prop_xid_set(win, atom, type, lst, num);
+
+ done:
+   if (lst)
+      free(lst);
+}
+
+/*
+ * Set Atom (array) property
+ */
+void
+ecore_x_window_prop_atom_set(Ecore_X_Window win, Ecore_X_Atom atom,
+                            Ecore_X_Atom * lst, unsigned int num)
+{
+   ecore_x_window_prop_xid_set(win, atom, XA_ATOM, lst, num);
+}
+
+/*
+ * Get Atom (array) property
+ *
+ * At most len items are returned in val.
+ * If the property was successfully fetched the number of items stored in
+ * val is returned, otherwise -1 is returned.
+ * Note: Return value 0 means that the property exists but has no elements.
+ */
+int
+ecore_x_window_prop_atom_get(Ecore_X_Window win, Ecore_X_Atom atom,
+                            Ecore_X_Atom * lst, unsigned int len)
+{
+   return ecore_x_window_prop_xid_get(win, atom, XA_ATOM, lst, len);
+}
+
+/*
+ * Get Atom (array) property
+ *
+ * If the property was successfully fetched the number of items stored in
+ * val is returned, otherwise -1 is returned.
+ * The returned array must be freed with free().
+ * Note: Return value 0 means that the property exists but has no elements.
+ */
+int
+ecore_x_window_prop_atom_list_get(Ecore_X_Window win, Ecore_X_Atom atom,
+                                 Ecore_X_Atom ** plst)
+{
+   return ecore_x_window_prop_xid_list_get(win, atom, XA_ATOM, plst);
+}
+
+/*
+ * Remove/add/toggle atom list item.
+ */
+void
+ecore_x_window_prop_atom_list_change(Ecore_X_Window win, Ecore_X_Atom atom,
+                                    Ecore_X_Atom item, int op)
+{
+   ecore_x_window_prop_xid_list_change(win, atom, XA_ATOM, item, op);
+}
+
+/*
+ * Set Window (array) property
+ */
+void
+ecore_x_window_prop_window_set(Ecore_X_Window win, Ecore_X_Atom atom,
+                              Ecore_X_Window * lst, unsigned int num)
+{
+   ecore_x_window_prop_xid_set(win, atom, XA_WINDOW, lst, num);
+}
+
+/*
+ * Get Window (array) property
+ *
+ * At most len items are returned in val.
+ * If the property was successfully fetched the number of items stored in
+ * val is returned, otherwise -1 is returned.
+ * Note: Return value 0 means that the property exists but has no elements.
+ */
+int
+ecore_x_window_prop_window_get(Ecore_X_Window win, Ecore_X_Atom atom,
+                              Ecore_X_Window * lst, unsigned int len)
+{
+   return ecore_x_window_prop_xid_get(win, atom, XA_WINDOW, lst, len);
+}
+
+/*
+ * Get Window (array) property
+ *
+ * If the property was successfully fetched the number of items stored in
+ * val is returned, otherwise -1 is returned.
+ * The returned array must be freed with free().
+ * Note: Return value 0 means that the property exists but has no elements.
+ */
+int
+ecore_x_window_prop_window_list_get(Ecore_X_Window win, Ecore_X_Atom atom,
+                                   Ecore_X_Window ** plst)
+{
+   return ecore_x_window_prop_xid_list_get(win, atom, XA_WINDOW, plst);
+}
+
 /**
  * To be documented.
  *




-------------------------------------------------------
This SF.net email is sponsored by: Splunk Inc. Do you grep through log files
for problems?  Stop!  Download the new AJAX search engine that makes
searching your log files as easy as surfing the  web.  DOWNLOAD SPLUNK!
http://ads.osdn.com/?ad_id=7637&alloc_id=16865&op=click
_______________________________________________
enlightenment-cvs mailing list
enlightenment-cvs@lists.sourceforge.net
https://lists.sourceforge.net/lists/listinfo/enlightenment-cvs

Reply via email to