[ecore] merged svn latest code (svn54830)
[profile/ivi/ecore.git] / src / lib / ecore_x / xcb / ecore_xcb_window_prop.c
1 #include <stdlib.h>
2 #include <string.h>
3
4 #include "ecore_xcb_private.h"
5 #include "Ecore_X_Atoms.h"
6
7 /*
8  * Set CARD32 (array) property
9  */
10 EAPI void
11 ecore_x_window_prop_card32_set(Ecore_X_Window win,
12                                Ecore_X_Atom   atom,
13                                unsigned int  *val,
14                                unsigned int   num)
15 {
16    xcb_change_property(_ecore_xcb_conn, XCB_PROP_MODE_REPLACE, win,
17                        atom, ECORE_X_ATOM_CARDINAL, 32, num, (const void *)val);
18 } /* ecore_x_window_prop_card32_set */
19
20 /**
21  * Sends the GetProperty request.
22  * @param window Window whose properties are requested.
23  * @param atom   The atom.
24  */
25 EAPI void
26 ecore_x_window_prop_card32_get_prefetch(Ecore_X_Window window,
27                                         Ecore_X_Atom   atom)
28 {
29    xcb_get_property_cookie_t cookie;
30
31    cookie = xcb_get_property_unchecked(_ecore_xcb_conn, 0,
32                                        window,
33                                        atom,
34                                        ECORE_X_ATOM_CARDINAL,
35                                        0, 0x7fffffff);
36    _ecore_xcb_cookie_cache(cookie.sequence);
37 } /* ecore_x_window_prop_card32_get_prefetch */
38
39 /**
40  * Gets the reply of the GetProperty request sent by ecore_x_window_prop_card32_get_prefetch().
41  */
42 EAPI void
43 ecore_x_window_prop_card32_get_fetch(void)
44 {
45    xcb_get_property_cookie_t cookie;
46    xcb_get_property_reply_t *reply;
47
48    cookie.sequence = _ecore_xcb_cookie_get();
49    reply = xcb_get_property_reply(_ecore_xcb_conn, cookie, NULL);
50    _ecore_xcb_reply_cache(reply);
51 } /* ecore_x_window_prop_card32_get_fetch */
52
53 /*
54  * Get CARD32 (array) property
55  *
56  * At most len items are returned in val.
57  * If the property was successfully fetched the number of items stored in
58  * val is returned, otherwise -1 is returned.
59  * Note: Return value 0 means that the property exists but has no elements.
60  */
61 EAPI int
62 ecore_x_window_prop_card32_get(Ecore_X_Window win __UNUSED__,
63                                Ecore_X_Atom atom  __UNUSED__,
64                                unsigned int      *val,
65                                unsigned int       len)
66 {
67    xcb_get_property_reply_t *reply;
68
69    reply = _ecore_xcb_reply_get();
70    if (!reply ||
71        (reply->type != ECORE_X_ATOM_CARDINAL) ||
72        (reply->format != 32))
73       return -1;
74
75    if (reply->value_len < len)
76       len = xcb_get_property_value_length(reply);
77
78    if (val)
79       memcpy(val, xcb_get_property_value(reply), len);
80
81    return (int)len;
82 } /* ecore_x_window_prop_card32_get */
83
84 /*
85  * Get CARD32 (array) property of any length
86  *
87  * If the property was successfully fetched the number of items stored in
88  * val is returned, otherwise -1 is returned.
89  * Note: Return value 0 means that the property exists but has no elements.
90  */
91 EAPI int
92 ecore_x_window_prop_card32_list_get(Ecore_X_Window win __UNUSED__,
93                                     Ecore_X_Atom atom  __UNUSED__,
94                                     unsigned int     **plist)
95 {
96    xcb_get_property_reply_t *reply;
97    int num = -1;
98
99    if (plist)
100       *plist = NULL;
101
102    reply = _ecore_xcb_reply_get();
103    if (!reply)
104       return -1;
105
106    if ((reply->type == XCB_NONE) ||
107        (reply->value_len == 0))
108       num = 0;
109    else if ((reply->type == ECORE_X_ATOM_CARDINAL) &&
110             (reply->format == 32))
111      {
112         uint32_t *val;
113
114         num = xcb_get_property_value_length(reply);
115         if (plist)
116           {
117              val = (uint32_t *)malloc (num);
118              if (!val)
119                 goto error;
120
121              memcpy(val, xcb_get_property_value(reply), num);
122              *plist = val;
123           }
124      }
125
126 error:
127
128    return num;
129 } /* ecore_x_window_prop_card32_list_get */
130
131 /*
132  * Set X ID (array) property
133  */
134 EAPI void
135 ecore_x_window_prop_xid_set(Ecore_X_Window win,
136                             Ecore_X_Atom   atom,
137                             Ecore_X_Atom   type,
138                             Ecore_X_ID    *xids,
139                             unsigned int   num)
140 {
141    xcb_change_property(_ecore_xcb_conn, XCB_PROP_MODE_REPLACE, win,
142                        atom, type, 32, num, xids);
143 } /* ecore_x_window_prop_xid_set */
144
145 /**
146  * Sends the GetProperty request.
147  * @param window Window whose properties are requested.
148  * @param atom   The atom.
149  * @param type   The atom type.
150  */
151 EAPI void
152 ecore_x_window_prop_xid_get_prefetch(Ecore_X_Window window,
153                                      Ecore_X_Atom   atom,
154                                      Ecore_X_Atom   type)
155 {
156    xcb_get_property_cookie_t cookie;
157
158    cookie = xcb_get_property_unchecked(_ecore_xcb_conn, 0,
159                                        window,
160                                        atom,
161                                        type,
162                                        0, 0x7fffffff);
163    _ecore_xcb_cookie_cache(cookie.sequence);
164 } /* ecore_x_window_prop_xid_get_prefetch */
165
166 /**
167  * Gets the reply of the GetProperty request sent by ecore_x_window_prop_xid_get_prefetch().
168  */
169 EAPI void
170 ecore_x_window_prop_xid_get_fetch(void)
171 {
172    xcb_get_property_cookie_t cookie;
173    xcb_get_property_reply_t *reply;
174
175    cookie.sequence = _ecore_xcb_cookie_get();
176    reply = xcb_get_property_reply(_ecore_xcb_conn, cookie, NULL);
177    _ecore_xcb_reply_cache(reply);
178 } /* ecore_x_window_prop_xid_get_fetch */
179
180 /*
181  * Get X ID (array) property
182  *
183  * At most len items are returned in val.
184  * If the property was successfully fetched the number of items stored in
185  * val is returned, otherwise -1 is returned.
186  * Note: Return value 0 means that the property exists but has no elements.
187  */
188 EAPI int
189 ecore_x_window_prop_xid_get(Ecore_X_Window win __UNUSED__,
190                             Ecore_X_Atom atom  __UNUSED__,
191                             Ecore_X_Atom type  __UNUSED__,
192                             Ecore_X_ID        *xids,
193                             unsigned int       len)
194 {
195    xcb_get_property_reply_t *reply;
196    int num = len;
197
198    reply = _ecore_xcb_reply_get();
199    if (!reply)
200       return -1;
201
202    if (reply->type == XCB_NONE)
203       num = 0;
204    else if (reply->format == 32)
205      {
206         if (reply->value_len < len)
207            num = xcb_get_property_value_length(reply);
208
209         if (xids)
210            memcpy(xids, xcb_get_property_value(reply), num);
211      }
212
213    return num;
214 } /* ecore_x_window_prop_xid_get */
215
216 /*
217  * Get X ID (array) property
218  *
219  * If the property was successfully fetched the number of items stored in
220  * val is returned, otherwise -1 is returned.
221  * The returned array must be freed with free().
222  * Note: Return value 0 means that the property exists but has no elements.
223  */
224 EAPI int
225 ecore_x_window_prop_xid_list_get(Ecore_X_Window win __UNUSED__,
226                                  Ecore_X_Atom atom  __UNUSED__,
227                                  Ecore_X_Atom type  __UNUSED__,
228                                  Ecore_X_ID       **pxids)
229 {
230    xcb_get_property_reply_t *reply;
231    int num = -1;
232
233    if (pxids)
234       *pxids = NULL;
235
236    reply = _ecore_xcb_reply_get();
237    if (!reply)
238       return -1;
239
240    if ((reply->type == XCB_NONE) ||
241        (reply->value_len == 0))
242       num = 0;
243    else if ((reply->type == ECORE_X_ATOM_CARDINAL) &&
244             (reply->format == 32))
245      {
246         uint32_t *val;
247
248         num = xcb_get_property_value_length(reply);
249         if (pxids)
250           {
251              val = (uint32_t *)malloc (num);
252              if (!val)
253                 return -1;
254
255              memcpy(val, xcb_get_property_value(reply), num);
256              *pxids = val;
257           }
258      }
259
260    return num;
261 } /* ecore_x_window_prop_xid_list_get */
262
263 /*
264  * Remove/add/toggle X ID list item.
265  */
266 EAPI void
267 ecore_x_window_prop_xid_list_change(Ecore_X_Window win,
268                                     Ecore_X_Atom   atom,
269                                     Ecore_X_Atom   type,
270                                     Ecore_X_ID     item,
271                                     int            op)
272 {
273    Ecore_X_ID *lst;
274    int i;
275    int num;
276
277    num = ecore_x_window_prop_xid_list_get(win, atom, type, &lst);
278    if (num < 0)
279       return;  /* Error - assuming invalid window */
280
281    /* Is it there? */
282    for (i = 0; i < num; i++)
283      {
284         if (lst[i] == item)
285            break;
286      }
287
288    if (i < num)
289      {
290         /* Was in list */
291         if (op == ECORE_X_PROP_LIST_ADD)
292            goto done;
293
294         /* Remove it */
295         num--;
296         for (; i < num; i++)
297            lst[i] = lst[i + 1];
298      }
299    else
300      {
301         /* Was not in list */
302         if (op == ECORE_X_PROP_LIST_REMOVE)
303            goto done;
304
305         /* Add it */
306         num++;
307         lst = realloc(lst, num * sizeof(Ecore_X_ID));
308         lst[i] = item;
309      }
310
311    ecore_x_window_prop_xid_set(win, atom, type, lst, num);
312
313 done:
314    if (lst)
315       free(lst);
316 } /* ecore_x_window_prop_xid_list_change */
317
318 /*
319  * Set Atom (array) property
320  */
321 EAPI void
322 ecore_x_window_prop_atom_set(Ecore_X_Window win,
323                              Ecore_X_Atom   atom,
324                              Ecore_X_Atom  *list,
325                              unsigned int   num)
326 {
327    ecore_x_window_prop_xid_set(win, atom, ECORE_X_ATOM_ATOM, list, num);
328 } /* ecore_x_window_prop_atom_set */
329
330 /**
331  * Sends the GetProperty request.
332  * @param window Window whose properties are requested.
333  * @param atom   Property atom.
334  */
335 EAPI void
336 ecore_x_window_prop_atom_get_prefetch(Ecore_X_Window window,
337                                       Ecore_X_Atom   atom)
338 {
339    xcb_get_property_cookie_t cookie;
340
341    cookie = xcb_get_property_unchecked(_ecore_xcb_conn, 0,
342                                        window,
343                                        atom,
344                                        ECORE_X_ATOM_ATOM,
345                                        0, 0x7fffffff);
346    _ecore_xcb_cookie_cache(cookie.sequence);
347 } /* ecore_x_window_prop_atom_get_prefetch */
348
349 /**
350  * Gets the reply of the GetProperty request sent by ecore_x_window_prop_atom_get_prefetch().
351  */
352 EAPI void
353 ecore_x_window_prop_atom_get_fetch(void)
354 {
355    xcb_get_property_cookie_t cookie;
356    xcb_get_property_reply_t *reply;
357
358    cookie.sequence = _ecore_xcb_cookie_get();
359    reply = xcb_get_property_reply(_ecore_xcb_conn, cookie, NULL);
360    _ecore_xcb_reply_cache(reply);
361 } /* ecore_x_window_prop_atom_get_fetch */
362
363 /*
364  * Get Atom (array) property
365  *
366  * At most len items are returned in val.
367  * If the property was successfully fetched the number of items stored in
368  * val is returned, otherwise -1 is returned.
369  * Note: Return value 0 means that the property exists but has no elements.
370  */
371 EAPI int
372 ecore_x_window_prop_atom_get(Ecore_X_Window win,
373                              Ecore_X_Atom   atom,
374                              Ecore_X_Atom  *list,
375                              unsigned int   len)
376 {
377    return ecore_x_window_prop_xid_get(win, atom, ECORE_X_ATOM_ATOM, list, len);
378 } /* ecore_x_window_prop_atom_get */
379
380 /*
381  * Get Atom (array) property
382  *
383  * If the property was successfully fetched the number of items stored in
384  * val is returned, otherwise -1 is returned.
385  * The returned array must be freed with free().
386  * Note: Return value 0 means that the property exists but has no elements.
387  */
388 EAPI int
389 ecore_x_window_prop_atom_list_get(Ecore_X_Window win,
390                                   Ecore_X_Atom   atom,
391                                   Ecore_X_Atom **plist)
392 {
393    return ecore_x_window_prop_xid_list_get(win, atom, ECORE_X_ATOM_ATOM, plist);
394 } /* ecore_x_window_prop_atom_list_get */
395
396 /*
397  * Remove/add/toggle atom list item.
398  */
399 EAPI void
400 ecore_x_window_prop_atom_list_change(Ecore_X_Window win,
401                                      Ecore_X_Atom   atom,
402                                      Ecore_X_Atom   item,
403                                      int            op)
404 {
405    ecore_x_window_prop_xid_list_change(win, atom, ECORE_X_ATOM_ATOM, item, op);
406 } /* ecore_x_window_prop_atom_list_change */
407
408 /*
409  * Set Window (array) property
410  */
411 EAPI void
412 ecore_x_window_prop_window_set(Ecore_X_Window  win,
413                                Ecore_X_Atom    atom,
414                                Ecore_X_Window *list,
415                                unsigned int    num)
416 {
417    ecore_x_window_prop_xid_set(win, atom, ECORE_X_ATOM_WINDOW, list, num);
418 } /* ecore_x_window_prop_window_set */
419
420 /**
421  * Sends the GetProperty request.
422  * @param window Window whose properties are requested.
423  * @param atom   The atom.
424  */
425 EAPI void
426 ecore_x_window_prop_window_get_prefetch(Ecore_X_Window window,
427                                         Ecore_X_Atom   atom)
428 {
429    xcb_get_property_cookie_t cookie;
430
431    cookie = xcb_get_property_unchecked(_ecore_xcb_conn, 0,
432                                        window,
433                                        atom,
434                                        ECORE_X_ATOM_WINDOW,
435                                        0, 0x7fffffff);
436    _ecore_xcb_cookie_cache(cookie.sequence);
437 } /* ecore_x_window_prop_window_get_prefetch */
438
439 /**
440  * Gets the reply of the GetProperty request sent by ecore_x_window_prop_window_get_prefetch().
441  */
442 EAPI void
443 ecore_x_window_prop_window_get_fetch(void)
444 {
445    xcb_get_property_cookie_t cookie;
446    xcb_get_property_reply_t *reply;
447
448    cookie.sequence = _ecore_xcb_cookie_get();
449    reply = xcb_get_property_reply(_ecore_xcb_conn, cookie, NULL);
450    _ecore_xcb_reply_cache(reply);
451 } /* ecore_x_window_prop_window_get_fetch */
452
453 /*
454  * Get Window (array) property
455  *
456  * At most len items are returned in val.
457  * If the property was successfully fetched the number of items stored in
458  * val is returned, otherwise -1 is returned.
459  * Note: Return value 0 means that the property exists but has no elements.
460  */
461 EAPI int
462 ecore_x_window_prop_window_get(Ecore_X_Window  win,
463                                Ecore_X_Atom    atom,
464                                Ecore_X_Window *list,
465                                unsigned int    len)
466 {
467    return ecore_x_window_prop_xid_get(win, atom, ECORE_X_ATOM_WINDOW, list, len);
468 } /* ecore_x_window_prop_window_get */
469
470 /*
471  * Get Window (array) property
472  *
473  * If the property was successfully fetched the number of items stored in
474  * val is returned, otherwise -1 is returned.
475  * The returned array must be freed with free().
476  * Note: Return value 0 means that the property exists but has no elements.
477  */
478 EAPI int
479 ecore_x_window_prop_window_list_get(Ecore_X_Window   win,
480                                     Ecore_X_Atom     atom,
481                                     Ecore_X_Window **plist)
482 {
483    return ecore_x_window_prop_xid_list_get(win, atom, ECORE_X_ATOM_WINDOW, plist);
484 } /* ecore_x_window_prop_window_list_get */
485
486 /**
487  * To be documented.
488  *
489  * FIXME: To be fixed.
490  */
491 EAPI Ecore_X_Atom
492 ecore_x_window_prop_any_type(void)
493 {
494    return XCB_GET_PROPERTY_TYPE_ANY;
495 } /* ecore_x_window_prop_any_type */
496
497 /**
498  * To be documented.
499  * @param window   The window.
500  * @param property The property atom.
501  * @param type     The type atom.
502  * @param size     The size.
503  * @param data     The data.
504  * @param number   The size of the data.
505  *
506  * FIXME: To be fixed.
507  */
508 EAPI void
509 ecore_x_window_prop_property_set(Ecore_X_Window window,
510                                  Ecore_X_Atom   property,
511                                  Ecore_X_Atom   type,
512                                  int            size,
513                                  void          *data,
514                                  int            number)
515 {
516    if (window == 0)
517       window = ((xcb_screen_t *)_ecore_xcb_screen)->root;
518
519    xcb_change_property(_ecore_xcb_conn, XCB_PROP_MODE_REPLACE, window,
520                        property, type,
521                        size, number, data);
522 } /* ecore_x_window_prop_property_set */
523
524 /**
525  * Sends the GetProperty request.
526  * @param window   Window whose properties are requested.
527  * @param property Property atom.
528  * @param type     Type atom.
529  */
530 EAPI void
531 ecore_x_window_prop_property_get_prefetch(Ecore_X_Window window,
532                                           Ecore_X_Atom   property,
533                                           Ecore_X_Atom   type)
534 {
535    xcb_get_property_cookie_t cookie;
536
537    cookie = xcb_get_property_unchecked(_ecore_xcb_conn, 0,
538                                        window ? window : ((xcb_screen_t *)_ecore_xcb_screen)->root,
539                                        property, type, 0, LONG_MAX);
540    _ecore_xcb_cookie_cache(cookie.sequence);
541 } /* ecore_x_window_prop_property_get_prefetch */
542
543 /**
544  * Gets the reply of the GetProperty request sent by ecore_x_window_prop_property_get_prefetch().
545  */
546 EAPI void
547 ecore_x_window_prop_property_get_fetch(void)
548 {
549    xcb_get_property_cookie_t cookie;
550    xcb_get_property_reply_t *reply;
551
552    cookie.sequence = _ecore_xcb_cookie_get();
553    reply = xcb_get_property_reply(_ecore_xcb_conn, cookie, NULL);
554    _ecore_xcb_reply_cache(reply);
555 } /* ecore_x_window_prop_property_get_fetch */
556
557 /**
558  * To be documented.
559  * @param window   The window (Unused).
560  * @param property The property atom (Unused).
561  * @param type     The type atom (Unused).
562  * @param size     The size (Unused).
563  * @param data     The returned data.
564  * @param num      The size of the data.
565  * @return         1 on success, 0 otherwise.
566  *
567  * FIXME: To be fixed.
568  */
569 EAPI int
570 ecore_x_window_prop_property_get(Ecore_X_Window window __UNUSED__,
571                                  Ecore_X_Atom property __UNUSED__,
572                                  Ecore_X_Atom type     __UNUSED__,
573                                  int size              __UNUSED__,
574                                  unsigned char       **data,
575                                  int                  *num)
576 {
577    xcb_get_property_reply_t *reply;
578
579    /* make sure these are initialized */
580    if (num)
581       *num = 0L;
582
583    if (data)
584       *data = NULL;
585    else /* we can't store the retrieved data, so just return */
586       return 0;
587
588    reply = _ecore_xcb_reply_get();
589    if (!reply)
590       return 0;
591
592    if ((reply->format != size) ||
593        (reply->value_len == 0))
594       return 0;
595
596    *data = malloc(reply->value_len);
597    if (!*data)
598       return 0;
599
600    memcpy(*data, xcb_get_property_value(reply),
601           xcb_get_property_value_length(reply));
602
603    if (num)
604       *num = reply->value_len;
605
606    return reply->format;
607 } /* ecore_x_window_prop_property_get */
608
609 EAPI void
610 ecore_x_window_prop_property_del(Ecore_X_Window window,
611                                  Ecore_X_Atom   property)
612 {
613    xcb_delete_property(_ecore_xcb_conn, window, property);
614 } /* ecore_x_window_prop_property_del */
615
616 /**
617  * Sends the ListProperties request.
618  * @param window Window whose properties are requested.
619  */
620 EAPI void
621 ecore_x_window_prop_list_prefetch(Ecore_X_Window window)
622 {
623    xcb_list_properties_cookie_t cookie;
624
625    cookie = xcb_list_properties_unchecked(_ecore_xcb_conn, window);
626    _ecore_xcb_cookie_cache(cookie.sequence);
627 } /* ecore_x_window_prop_list_prefetch */
628
629 /**
630  * Gets the reply of the ListProperties request sent by ecore_x_window_prop_list_prefetch().
631  */
632 EAPI void
633 ecore_x_window_prop_list_fetch(void)
634 {
635    xcb_list_properties_cookie_t cookie;
636    xcb_list_properties_reply_t *reply;
637
638    cookie.sequence = _ecore_xcb_cookie_get();
639    reply = xcb_list_properties_reply(_ecore_xcb_conn, cookie, NULL);
640    _ecore_xcb_reply_cache(reply);
641 } /* ecore_x_window_prop_list_fetch */
642
643 /**
644  * To be documented.
645  * @param window  The window (Unused).
646  * @param num_ret The number of atoms.
647  * @return        The returned atoms.
648  *
649  * FIXME: To be fixed.
650  */
651 EAPI Ecore_X_Atom *
652 ecore_x_window_prop_list(Ecore_X_Window window __UNUSED__,
653                          int                  *num_ret)
654 {
655    xcb_list_properties_reply_t *reply;
656    Ecore_X_Atom *atoms;
657
658    if (num_ret)
659       *num_ret = 0;
660
661    reply = _ecore_xcb_reply_get();
662    if (!reply)
663       return NULL;
664
665    atoms = (Ecore_X_Atom *)malloc(reply->atoms_len * sizeof(Ecore_X_Atom));
666    if (!atoms)
667       return NULL;
668
669    memcpy(atoms,
670           xcb_list_properties_atoms(reply),
671           reply->atoms_len * sizeof(Ecore_X_Atom));
672    if(num_ret)
673       *num_ret = reply->atoms_len;
674
675    return atoms;
676 } /* ecore_x_window_prop_list */
677
678 /**
679  * Set a window string property.
680  * @param win The window
681  * @param type The property
682  * @param str The string
683  *
684  * Set a window string property
685  */
686 EAPI void
687 ecore_x_window_prop_string_set(Ecore_X_Window win,
688                                Ecore_X_Atom   type,
689                                const char    *str)
690 {
691    if (win == 0)
692       win = ((xcb_screen_t *)_ecore_xcb_screen)->root;
693
694    xcb_change_property(_ecore_xcb_conn, XCB_PROP_MODE_REPLACE, win,
695                        type, ECORE_X_ATOM_UTF8_STRING,
696                        8, strlen(str), str);
697 } /* ecore_x_window_prop_string_set */
698
699 /**
700  * Sends the GetProperty request.
701  * @param window Window whose properties are requested.
702  * @param type   The atom.
703  */
704 EAPI void
705 ecore_x_window_prop_string_get_prefetch(Ecore_X_Window window,
706                                         Ecore_X_Atom   type)
707 {
708    xcb_get_property_cookie_t cookie;
709
710    cookie = xcb_get_property_unchecked(_ecore_xcb_conn, 0,
711                                        window ? window : ((xcb_screen_t *)_ecore_xcb_screen)->root,
712                                        type, XCB_GET_PROPERTY_TYPE_ANY, 0L, 1000000L);
713    _ecore_xcb_cookie_cache(cookie.sequence);
714 } /* ecore_x_window_prop_string_get_prefetch */
715
716 /**
717  * Gets the reply of the GetProperty request sent by ecore_x_window_prop_string_get_prefetch().
718  */
719 EAPI void
720 ecore_x_window_prop_string_get_fetch(void)
721 {
722    xcb_get_property_cookie_t cookie;
723    xcb_get_property_reply_t *reply;
724
725    cookie.sequence = _ecore_xcb_cookie_get();
726    reply = xcb_get_property_reply(_ecore_xcb_conn, cookie, NULL);
727    _ecore_xcb_reply_cache(reply);
728 } /* ecore_x_window_prop_string_get_fetch */
729
730 /**
731  * Get a window string property.
732  * @param window The window
733  * @param type The property
734  *
735  * Return window string property of a window. String must be free'd when done.
736  *
737  * To use this function, you must call before, and in order,
738  * ecore_x_window_prop_string_get_prefetch(), which sends the GetProperty request,
739  * then ecore_x_window_prop_string_get_fetch(), which gets the reply.
740  */
741 EAPI char *
742 ecore_x_window_prop_string_get(Ecore_X_Window window __UNUSED__,
743                                Ecore_X_Atom type     __UNUSED__)
744 {
745    xcb_get_property_reply_t *reply;
746    char *str = NULL;
747
748    reply = _ecore_xcb_reply_get();
749    if (!reply)
750       return NULL;
751
752    if (reply->type == ECORE_X_ATOM_UTF8_STRING)
753      {
754         int length;
755
756         length = reply->value_len;
757         str = (char *)malloc(length + 1);
758         memcpy(str,
759                xcb_get_property_value(reply),
760                length);
761         str[length] = '\0';
762      }
763    else
764      {
765         /* FIXME: to be done... */
766
767 /* #ifdef X_HAVE_UTF8_STRING */
768 /*         s = Xutf8TextPropertyToTextList(_ecore_xcb_conn, &xtp, */
769 /*                                         &list, &items); */
770 /* #else */
771 /*         s = XmbTextPropertyToTextList(_ecore_xcb_conn, &xtp, */
772 /*                                       &list, &items); */
773 /* #endif */
774 /*         if ((s == XLocaleNotSupported) || */
775 /*             (s == XNoMemory) || (s == XConverterNotFound)) */
776 /*           { */
777 /*              str = strdup((char *)xtp.value); */
778 /*           } */
779 /*         else if ((s >= Success) && (items > 0)) */
780 /*           { */
781 /*              str = strdup(list[0]); */
782 /*           } */
783 /*         if (list) */
784 /*            XFreeStringList(list); */
785      }
786
787    return str;
788 } /* ecore_x_window_prop_string_get */
789
790 /* FIXME : round trips because of GetWMProtocols */
791 /*         should we rewrite its code ? */
792 EAPI Eina_Bool
793 ecore_x_window_prop_protocol_isset(Ecore_X_Window      window,
794                                    Ecore_X_WM_Protocol protocol)
795 {
796    xcb_get_property_cookie_t cookie;
797    xcb_get_wm_protocols_reply_t protocols;
798    Ecore_X_Atom proto;
799    uint32_t i;
800    uint8_t ret = 0;
801
802    /* check for invalid values */
803    if (protocol >= ECORE_X_WM_PROTOCOL_NUM)
804       return ret;
805
806    proto = _ecore_xcb_atoms_wm_protocols[protocol];
807
808    cookie = xcb_get_wm_protocols(_ecore_xcb_conn, window, ECORE_X_ATOM_WM_PROTOCOLS);
809
810    if (!xcb_get_wm_protocols_reply(_ecore_xcb_conn, cookie, &protocols, NULL))
811       return ret;
812
813    for (i = 0; i < protocols.atoms_len; i++)
814       if (protocols.atoms[i] == proto)
815         {
816            ret = 1;
817            break;
818         }
819
820    xcb_get_wm_protocols_reply_wipe(&protocols);
821
822    return ret;
823 } /* ecore_x_window_prop_protocol_isset */
824
825 /**
826  * To be documented.
827  * @param window  The window.
828  * @param num_ret The number of WM protocols.
829  * @return        The returned WM protocols.
830  *
831  * FIXME: To be fixed.
832  */
833
834 /* FIXME : round trips because of get_wm_protocols */
835 /*         should we rewrite its code ? */
836
837 EAPI Ecore_X_WM_Protocol *
838 ecore_x_window_prop_protocol_list_get(Ecore_X_Window window,
839                                       int           *num_ret)
840 {
841    xcb_get_property_cookie_t cookie;
842    xcb_get_wm_protocols_reply_t protocols;
843    Ecore_X_WM_Protocol *prot_ret = NULL;
844    uint32_t protos_count;
845    uint32_t i;
846
847    cookie = xcb_get_wm_protocols(_ecore_xcb_conn, window, ECORE_X_ATOM_WM_PROTOCOLS);
848
849    if (!xcb_get_wm_protocols_reply(_ecore_xcb_conn, cookie, &protocols, NULL))
850       return NULL;
851
852    if ((protocols.atoms_len <= 0))
853       return NULL;
854
855    prot_ret = calloc(1, protocols.atoms_len * sizeof(Ecore_X_WM_Protocol));
856    if (!prot_ret)
857      {
858         xcb_get_wm_protocols_reply_wipe(&protocols);
859         return NULL;
860      }
861
862    for (i = 0; i < protocols.atoms_len; i++)
863      {
864         Ecore_X_WM_Protocol j;
865
866         prot_ret[i] = -1;
867         for (j = 0; j < ECORE_X_WM_PROTOCOL_NUM; j++)
868           {
869              if (_ecore_xcb_atoms_wm_protocols[j] == protocols.atoms[i])
870                 prot_ret[i] = j;
871           }
872      }
873    xcb_get_wm_protocols_reply_wipe(&protocols);
874    *num_ret = protos_count;
875
876    return prot_ret;
877 } /* ecore_x_window_prop_protocol_list_get */
878