4 #include "ecore_xcb_private.h"
5 #include "Ecore_X_Atoms.h"
8 * Set CARD32 (array) property
11 ecore_x_window_prop_card32_set(Ecore_X_Window win,
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 */
21 * Sends the GetProperty request.
22 * @param window Window whose properties are requested.
23 * @param atom The atom.
26 ecore_x_window_prop_card32_get_prefetch(Ecore_X_Window window,
29 xcb_get_property_cookie_t cookie;
31 cookie = xcb_get_property_unchecked(_ecore_xcb_conn, 0,
34 ECORE_X_ATOM_CARDINAL,
36 _ecore_xcb_cookie_cache(cookie.sequence);
37 } /* ecore_x_window_prop_card32_get_prefetch */
40 * Gets the reply of the GetProperty request sent by ecore_x_window_prop_card32_get_prefetch().
43 ecore_x_window_prop_card32_get_fetch(void)
45 xcb_get_property_cookie_t cookie;
46 xcb_get_property_reply_t *reply;
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 */
54 * Get CARD32 (array) property
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.
62 ecore_x_window_prop_card32_get(Ecore_X_Window win __UNUSED__,
63 Ecore_X_Atom atom __UNUSED__,
67 xcb_get_property_reply_t *reply;
69 reply = _ecore_xcb_reply_get();
71 (reply->type != ECORE_X_ATOM_CARDINAL) ||
72 (reply->format != 32))
75 if (reply->value_len < len)
76 len = xcb_get_property_value_length(reply);
79 memcpy(val, xcb_get_property_value(reply), len);
82 } /* ecore_x_window_prop_card32_get */
85 * Get CARD32 (array) property of any length
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.
92 ecore_x_window_prop_card32_list_get(Ecore_X_Window win __UNUSED__,
93 Ecore_X_Atom atom __UNUSED__,
96 xcb_get_property_reply_t *reply;
102 reply = _ecore_xcb_reply_get();
106 if ((reply->type == XCB_NONE) ||
107 (reply->value_len == 0))
109 else if ((reply->type == ECORE_X_ATOM_CARDINAL) &&
110 (reply->format == 32))
114 num = xcb_get_property_value_length(reply);
117 val = (uint32_t *)malloc (num);
121 memcpy(val, xcb_get_property_value(reply), num);
129 } /* ecore_x_window_prop_card32_list_get */
132 * Set X ID (array) property
135 ecore_x_window_prop_xid_set(Ecore_X_Window win,
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 */
146 * Sends the GetProperty request.
147 * @param window Window whose properties are requested.
148 * @param atom The atom.
149 * @param type The atom type.
152 ecore_x_window_prop_xid_get_prefetch(Ecore_X_Window window,
156 xcb_get_property_cookie_t cookie;
158 cookie = xcb_get_property_unchecked(_ecore_xcb_conn, 0,
163 _ecore_xcb_cookie_cache(cookie.sequence);
164 } /* ecore_x_window_prop_xid_get_prefetch */
167 * Gets the reply of the GetProperty request sent by ecore_x_window_prop_xid_get_prefetch().
170 ecore_x_window_prop_xid_get_fetch(void)
172 xcb_get_property_cookie_t cookie;
173 xcb_get_property_reply_t *reply;
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 */
181 * Get X ID (array) property
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.
189 ecore_x_window_prop_xid_get(Ecore_X_Window win __UNUSED__,
190 Ecore_X_Atom atom __UNUSED__,
191 Ecore_X_Atom type __UNUSED__,
195 xcb_get_property_reply_t *reply;
198 reply = _ecore_xcb_reply_get();
202 if (reply->type == XCB_NONE)
204 else if (reply->format == 32)
206 if (reply->value_len < len)
207 num = xcb_get_property_value_length(reply);
210 memcpy(xids, xcb_get_property_value(reply), num);
214 } /* ecore_x_window_prop_xid_get */
217 * Get X ID (array) property
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.
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__,
230 xcb_get_property_reply_t *reply;
236 reply = _ecore_xcb_reply_get();
240 if ((reply->type == XCB_NONE) ||
241 (reply->value_len == 0))
243 else if ((reply->type == ECORE_X_ATOM_CARDINAL) &&
244 (reply->format == 32))
248 num = xcb_get_property_value_length(reply);
251 val = (uint32_t *)malloc (num);
255 memcpy(val, xcb_get_property_value(reply), num);
261 } /* ecore_x_window_prop_xid_list_get */
264 * Remove/add/toggle X ID list item.
267 ecore_x_window_prop_xid_list_change(Ecore_X_Window win,
277 num = ecore_x_window_prop_xid_list_get(win, atom, type, &lst);
279 return; /* Error - assuming invalid window */
282 for (i = 0; i < num; i++)
291 if (op == ECORE_X_PROP_LIST_ADD)
301 /* Was not in list */
302 if (op == ECORE_X_PROP_LIST_REMOVE)
307 lst = realloc(lst, num * sizeof(Ecore_X_ID));
311 ecore_x_window_prop_xid_set(win, atom, type, lst, num);
316 } /* ecore_x_window_prop_xid_list_change */
319 * Set Atom (array) property
322 ecore_x_window_prop_atom_set(Ecore_X_Window win,
327 ecore_x_window_prop_xid_set(win, atom, ECORE_X_ATOM_ATOM, list, num);
328 } /* ecore_x_window_prop_atom_set */
331 * Sends the GetProperty request.
332 * @param window Window whose properties are requested.
333 * @param atom Property atom.
336 ecore_x_window_prop_atom_get_prefetch(Ecore_X_Window window,
339 xcb_get_property_cookie_t cookie;
341 cookie = xcb_get_property_unchecked(_ecore_xcb_conn, 0,
346 _ecore_xcb_cookie_cache(cookie.sequence);
347 } /* ecore_x_window_prop_atom_get_prefetch */
350 * Gets the reply of the GetProperty request sent by ecore_x_window_prop_atom_get_prefetch().
353 ecore_x_window_prop_atom_get_fetch(void)
355 xcb_get_property_cookie_t cookie;
356 xcb_get_property_reply_t *reply;
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 */
364 * Get Atom (array) property
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.
372 ecore_x_window_prop_atom_get(Ecore_X_Window win,
377 return ecore_x_window_prop_xid_get(win, atom, ECORE_X_ATOM_ATOM, list, len);
378 } /* ecore_x_window_prop_atom_get */
381 * Get Atom (array) property
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.
389 ecore_x_window_prop_atom_list_get(Ecore_X_Window win,
391 Ecore_X_Atom **plist)
393 return ecore_x_window_prop_xid_list_get(win, atom, ECORE_X_ATOM_ATOM, plist);
394 } /* ecore_x_window_prop_atom_list_get */
397 * Remove/add/toggle atom list item.
400 ecore_x_window_prop_atom_list_change(Ecore_X_Window win,
405 ecore_x_window_prop_xid_list_change(win, atom, ECORE_X_ATOM_ATOM, item, op);
406 } /* ecore_x_window_prop_atom_list_change */
409 * Set Window (array) property
412 ecore_x_window_prop_window_set(Ecore_X_Window win,
414 Ecore_X_Window *list,
417 ecore_x_window_prop_xid_set(win, atom, ECORE_X_ATOM_WINDOW, list, num);
418 } /* ecore_x_window_prop_window_set */
421 * Sends the GetProperty request.
422 * @param window Window whose properties are requested.
423 * @param atom The atom.
426 ecore_x_window_prop_window_get_prefetch(Ecore_X_Window window,
429 xcb_get_property_cookie_t cookie;
431 cookie = xcb_get_property_unchecked(_ecore_xcb_conn, 0,
436 _ecore_xcb_cookie_cache(cookie.sequence);
437 } /* ecore_x_window_prop_window_get_prefetch */
440 * Gets the reply of the GetProperty request sent by ecore_x_window_prop_window_get_prefetch().
443 ecore_x_window_prop_window_get_fetch(void)
445 xcb_get_property_cookie_t cookie;
446 xcb_get_property_reply_t *reply;
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 */
454 * Get Window (array) property
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.
462 ecore_x_window_prop_window_get(Ecore_X_Window win,
464 Ecore_X_Window *list,
467 return ecore_x_window_prop_xid_get(win, atom, ECORE_X_ATOM_WINDOW, list, len);
468 } /* ecore_x_window_prop_window_get */
471 * Get Window (array) property
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.
479 ecore_x_window_prop_window_list_get(Ecore_X_Window win,
481 Ecore_X_Window **plist)
483 return ecore_x_window_prop_xid_list_get(win, atom, ECORE_X_ATOM_WINDOW, plist);
484 } /* ecore_x_window_prop_window_list_get */
489 * FIXME: To be fixed.
492 ecore_x_window_prop_any_type(void)
494 return XCB_GET_PROPERTY_TYPE_ANY;
495 } /* ecore_x_window_prop_any_type */
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.
506 * FIXME: To be fixed.
509 ecore_x_window_prop_property_set(Ecore_X_Window window,
510 Ecore_X_Atom property,
517 window = ((xcb_screen_t *)_ecore_xcb_screen)->root;
519 xcb_change_property(_ecore_xcb_conn, XCB_PROP_MODE_REPLACE, window,
522 } /* ecore_x_window_prop_property_set */
525 * Sends the GetProperty request.
526 * @param window Window whose properties are requested.
527 * @param property Property atom.
528 * @param type Type atom.
531 ecore_x_window_prop_property_get_prefetch(Ecore_X_Window window,
532 Ecore_X_Atom property,
535 xcb_get_property_cookie_t cookie;
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 */
544 * Gets the reply of the GetProperty request sent by ecore_x_window_prop_property_get_prefetch().
547 ecore_x_window_prop_property_get_fetch(void)
549 xcb_get_property_cookie_t cookie;
550 xcb_get_property_reply_t *reply;
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 */
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.
567 * FIXME: To be fixed.
570 ecore_x_window_prop_property_get(Ecore_X_Window window __UNUSED__,
571 Ecore_X_Atom property __UNUSED__,
572 Ecore_X_Atom type __UNUSED__,
574 unsigned char **data,
577 xcb_get_property_reply_t *reply;
579 /* make sure these are initialized */
585 else /* we can't store the retrieved data, so just return */
588 reply = _ecore_xcb_reply_get();
592 if ((reply->format != size) ||
593 (reply->value_len == 0))
596 *data = malloc(reply->value_len);
600 memcpy(*data, xcb_get_property_value(reply),
601 xcb_get_property_value_length(reply));
604 *num = reply->value_len;
606 return reply->format;
607 } /* ecore_x_window_prop_property_get */
610 ecore_x_window_prop_property_del(Ecore_X_Window window,
611 Ecore_X_Atom property)
613 xcb_delete_property(_ecore_xcb_conn, window, property);
614 } /* ecore_x_window_prop_property_del */
617 * Sends the ListProperties request.
618 * @param window Window whose properties are requested.
621 ecore_x_window_prop_list_prefetch(Ecore_X_Window window)
623 xcb_list_properties_cookie_t cookie;
625 cookie = xcb_list_properties_unchecked(_ecore_xcb_conn, window);
626 _ecore_xcb_cookie_cache(cookie.sequence);
627 } /* ecore_x_window_prop_list_prefetch */
630 * Gets the reply of the ListProperties request sent by ecore_x_window_prop_list_prefetch().
633 ecore_x_window_prop_list_fetch(void)
635 xcb_list_properties_cookie_t cookie;
636 xcb_list_properties_reply_t *reply;
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 */
645 * @param window The window (Unused).
646 * @param num_ret The number of atoms.
647 * @return The returned atoms.
649 * FIXME: To be fixed.
652 ecore_x_window_prop_list(Ecore_X_Window window __UNUSED__,
655 xcb_list_properties_reply_t *reply;
661 reply = _ecore_xcb_reply_get();
665 atoms = (Ecore_X_Atom *)malloc(reply->atoms_len * sizeof(Ecore_X_Atom));
670 xcb_list_properties_atoms(reply),
671 reply->atoms_len * sizeof(Ecore_X_Atom));
673 *num_ret = reply->atoms_len;
676 } /* ecore_x_window_prop_list */
679 * Set a window string property.
680 * @param win The window
681 * @param type The property
682 * @param str The string
684 * Set a window string property
687 ecore_x_window_prop_string_set(Ecore_X_Window win,
692 win = ((xcb_screen_t *)_ecore_xcb_screen)->root;
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 */
700 * Sends the GetProperty request.
701 * @param window Window whose properties are requested.
702 * @param type The atom.
705 ecore_x_window_prop_string_get_prefetch(Ecore_X_Window window,
708 xcb_get_property_cookie_t cookie;
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 */
717 * Gets the reply of the GetProperty request sent by ecore_x_window_prop_string_get_prefetch().
720 ecore_x_window_prop_string_get_fetch(void)
722 xcb_get_property_cookie_t cookie;
723 xcb_get_property_reply_t *reply;
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 */
731 * Get a window string property.
732 * @param window The window
733 * @param type The property
735 * Return window string property of a window. String must be free'd when done.
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.
742 ecore_x_window_prop_string_get(Ecore_X_Window window __UNUSED__,
743 Ecore_X_Atom type __UNUSED__)
745 xcb_get_property_reply_t *reply;
748 reply = _ecore_xcb_reply_get();
752 if (reply->type == ECORE_X_ATOM_UTF8_STRING)
756 length = reply->value_len;
757 str = (char *)malloc(length + 1);
759 xcb_get_property_value(reply),
765 /* FIXME: to be done... */
767 /* #ifdef X_HAVE_UTF8_STRING */
768 /* s = Xutf8TextPropertyToTextList(_ecore_xcb_conn, &xtp, */
769 /* &list, &items); */
771 /* s = XmbTextPropertyToTextList(_ecore_xcb_conn, &xtp, */
772 /* &list, &items); */
774 /* if ((s == XLocaleNotSupported) || */
775 /* (s == XNoMemory) || (s == XConverterNotFound)) */
777 /* str = strdup((char *)xtp.value); */
779 /* else if ((s >= Success) && (items > 0)) */
781 /* str = strdup(list[0]); */
784 /* XFreeStringList(list); */
788 } /* ecore_x_window_prop_string_get */
790 /* FIXME : round trips because of GetWMProtocols */
791 /* should we rewrite its code ? */
793 ecore_x_window_prop_protocol_isset(Ecore_X_Window window,
794 Ecore_X_WM_Protocol protocol)
796 xcb_get_property_cookie_t cookie;
797 xcb_get_wm_protocols_reply_t protocols;
802 /* check for invalid values */
803 if (protocol >= ECORE_X_WM_PROTOCOL_NUM)
806 proto = _ecore_xcb_atoms_wm_protocols[protocol];
808 cookie = xcb_get_wm_protocols(_ecore_xcb_conn, window, ECORE_X_ATOM_WM_PROTOCOLS);
810 if (!xcb_get_wm_protocols_reply(_ecore_xcb_conn, cookie, &protocols, NULL))
813 for (i = 0; i < protocols.atoms_len; i++)
814 if (protocols.atoms[i] == proto)
820 xcb_get_wm_protocols_reply_wipe(&protocols);
823 } /* ecore_x_window_prop_protocol_isset */
827 * @param window The window.
828 * @param num_ret The number of WM protocols.
829 * @return The returned WM protocols.
831 * FIXME: To be fixed.
834 /* FIXME : round trips because of get_wm_protocols */
835 /* should we rewrite its code ? */
837 EAPI Ecore_X_WM_Protocol *
838 ecore_x_window_prop_protocol_list_get(Ecore_X_Window window,
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;
847 cookie = xcb_get_wm_protocols(_ecore_xcb_conn, window, ECORE_X_ATOM_WM_PROTOCOLS);
849 if (!xcb_get_wm_protocols_reply(_ecore_xcb_conn, cookie, &protocols, NULL))
852 if ((protocols.atoms_len <= 0))
855 prot_ret = calloc(1, protocols.atoms_len * sizeof(Ecore_X_WM_Protocol));
858 xcb_get_wm_protocols_reply_wipe(&protocols);
862 for (i = 0; i < protocols.atoms_len; i++)
864 Ecore_X_WM_Protocol j;
867 for (j = 0; j < ECORE_X_WM_PROTOCOL_NUM; j++)
869 if (_ecore_xcb_atoms_wm_protocols[j] == protocols.atoms[i])
873 xcb_get_wm_protocols_reply_wipe(&protocols);
874 *num_ret = protos_count;
877 } /* ecore_x_window_prop_protocol_list_get */