2 * vim:ts=8:sw=3:sts=8:noexpandtab:cino=>5n-3f0^-2{2
8 #include "ecore_xcb_private.h"
9 #include "Ecore_X_Atoms.h"
13 * Set CARD32 (array) property
16 ecore_x_window_prop_card32_set(Ecore_X_Window win,
21 xcb_change_property(_ecore_xcb_conn, XCB_PROP_MODE_REPLACE, win,
22 atom, ECORE_X_ATOM_CARDINAL, 32, num, (const void *)val);
26 * Sends the GetProperty request.
27 * @param window Window whose properties are requested.
28 * @param atom The atom.
31 ecore_x_window_prop_card32_get_prefetch(Ecore_X_Window window,
34 xcb_get_property_cookie_t cookie;
36 cookie = xcb_get_property_unchecked(_ecore_xcb_conn, 0,
39 ECORE_X_ATOM_CARDINAL,
41 _ecore_xcb_cookie_cache(cookie.sequence);
46 * Gets the reply of the GetProperty request sent by ecore_x_window_prop_card32_get_prefetch().
49 ecore_x_window_prop_card32_get_fetch(void)
51 xcb_get_property_cookie_t cookie;
52 xcb_get_property_reply_t *reply;
54 cookie.sequence = _ecore_xcb_cookie_get();
55 reply = xcb_get_property_reply(_ecore_xcb_conn, cookie, NULL);
56 _ecore_xcb_reply_cache(reply);
60 * Get CARD32 (array) property
62 * At most len items are returned in val.
63 * If the property was successfully fetched the number of items stored in
64 * val is returned, otherwise -1 is returned.
65 * Note: Return value 0 means that the property exists but has no elements.
68 ecore_x_window_prop_card32_get(Ecore_X_Window win __UNUSED__,
69 Ecore_X_Atom atom __UNUSED__,
73 xcb_get_property_reply_t *reply;
75 reply = _ecore_xcb_reply_get();
77 (reply->type != ECORE_X_ATOM_CARDINAL) ||
78 (reply->format != 32))
81 if (reply->value_len < len)
82 len = xcb_get_property_value_length(reply);
85 memcpy(val, xcb_get_property_value(reply), len);
91 * Get CARD32 (array) property of any length
93 * If the property was successfully fetched the number of items stored in
94 * val is returned, otherwise -1 is returned.
95 * Note: Return value 0 means that the property exists but has no elements.
98 ecore_x_window_prop_card32_list_get(Ecore_X_Window win __UNUSED__,
99 Ecore_X_Atom atom __UNUSED__,
100 unsigned int **plist)
102 xcb_get_property_reply_t *reply;
108 reply = _ecore_xcb_reply_get();
112 if ((reply->type == XCB_NONE) ||
113 (reply->value_len == 0))
115 else if ((reply->type == ECORE_X_ATOM_CARDINAL) &&
116 (reply->format == 32))
120 num = xcb_get_property_value_length(reply);
123 val = (uint32_t *)malloc (num);
127 memcpy(val, xcb_get_property_value(reply), num);
138 * Set X ID (array) property
141 ecore_x_window_prop_xid_set(Ecore_X_Window win,
147 xcb_change_property(_ecore_xcb_conn, XCB_PROP_MODE_REPLACE, win,
148 atom, type, 32, num, xids);
152 * Sends the GetProperty request.
153 * @param window Window whose properties are requested.
154 * @param atom The atom.
155 * @param type The atom type.
158 ecore_x_window_prop_xid_get_prefetch(Ecore_X_Window window,
162 xcb_get_property_cookie_t cookie;
164 cookie = xcb_get_property_unchecked(_ecore_xcb_conn, 0,
169 _ecore_xcb_cookie_cache(cookie.sequence);
174 * Gets the reply of the GetProperty request sent by ecore_x_window_prop_xid_get_prefetch().
177 ecore_x_window_prop_xid_get_fetch(void)
179 xcb_get_property_cookie_t cookie;
180 xcb_get_property_reply_t *reply;
182 cookie.sequence = _ecore_xcb_cookie_get();
183 reply = xcb_get_property_reply(_ecore_xcb_conn, cookie, NULL);
184 _ecore_xcb_reply_cache(reply);
188 * Get X ID (array) property
190 * At most len items are returned in val.
191 * If the property was successfully fetched the number of items stored in
192 * val is returned, otherwise -1 is returned.
193 * Note: Return value 0 means that the property exists but has no elements.
196 ecore_x_window_prop_xid_get(Ecore_X_Window win __UNUSED__,
197 Ecore_X_Atom atom __UNUSED__,
198 Ecore_X_Atom type __UNUSED__,
202 xcb_get_property_reply_t *reply;
205 reply = _ecore_xcb_reply_get();
209 if (reply->type == XCB_NONE)
211 else if (reply->format == 32)
213 if (reply->value_len < len)
214 num = xcb_get_property_value_length(reply);
217 memcpy(xids, xcb_get_property_value(reply), num);
224 * Get X ID (array) property
226 * If the property was successfully fetched the number of items stored in
227 * val is returned, otherwise -1 is returned.
228 * The returned array must be freed with free().
229 * Note: Return value 0 means that the property exists but has no elements.
232 ecore_x_window_prop_xid_list_get(Ecore_X_Window win __UNUSED__,
233 Ecore_X_Atom atom __UNUSED__,
234 Ecore_X_Atom type __UNUSED__,
237 xcb_get_property_reply_t *reply;
243 reply = _ecore_xcb_reply_get();
247 if ((reply->type == XCB_NONE) ||
248 (reply->value_len == 0))
250 else if ((reply->type == ECORE_X_ATOM_CARDINAL) &&
251 (reply->format == 32))
255 num = xcb_get_property_value_length(reply);
258 val = (uint32_t *)malloc (num);
262 memcpy(val, xcb_get_property_value(reply), num);
271 * Remove/add/toggle X ID list item.
274 ecore_x_window_prop_xid_list_change(Ecore_X_Window win,
284 num = ecore_x_window_prop_xid_list_get(win, atom, type, &lst);
286 return; /* Error - assuming invalid window */
289 for (i = 0; i < num; i++)
298 if (op == ECORE_X_PROP_LIST_ADD)
307 /* Was not in list */
308 if (op == ECORE_X_PROP_LIST_REMOVE)
312 lst = realloc(lst, num * sizeof(Ecore_X_ID));
316 ecore_x_window_prop_xid_set(win, atom, type, lst, num);
324 * Set Atom (array) property
327 ecore_x_window_prop_atom_set(Ecore_X_Window win,
332 ecore_x_window_prop_xid_set(win, atom, ECORE_X_ATOM_ATOM, list, num);
336 * Sends the GetProperty request.
337 * @param window Window whose properties are requested.
338 * @param atom Property atom.
341 ecore_x_window_prop_atom_get_prefetch(Ecore_X_Window window,
344 xcb_get_property_cookie_t cookie;
346 cookie = xcb_get_property_unchecked(_ecore_xcb_conn, 0,
351 _ecore_xcb_cookie_cache(cookie.sequence);
356 * Gets the reply of the GetProperty request sent by ecore_x_window_prop_atom_get_prefetch().
359 ecore_x_window_prop_atom_get_fetch(void)
361 xcb_get_property_cookie_t cookie;
362 xcb_get_property_reply_t *reply;
364 cookie.sequence = _ecore_xcb_cookie_get();
365 reply = xcb_get_property_reply(_ecore_xcb_conn, cookie, NULL);
366 _ecore_xcb_reply_cache(reply);
370 * Get Atom (array) property
372 * At most len items are returned in val.
373 * If the property was successfully fetched the number of items stored in
374 * val is returned, otherwise -1 is returned.
375 * Note: Return value 0 means that the property exists but has no elements.
378 ecore_x_window_prop_atom_get(Ecore_X_Window win,
383 return ecore_x_window_prop_xid_get(win, atom, ECORE_X_ATOM_ATOM, list, len);
387 * Get Atom (array) property
389 * If the property was successfully fetched the number of items stored in
390 * val is returned, otherwise -1 is returned.
391 * The returned array must be freed with free().
392 * Note: Return value 0 means that the property exists but has no elements.
395 ecore_x_window_prop_atom_list_get(Ecore_X_Window win,
397 Ecore_X_Atom **plist)
399 return ecore_x_window_prop_xid_list_get(win, atom, ECORE_X_ATOM_ATOM, plist);
403 * Remove/add/toggle atom list item.
406 ecore_x_window_prop_atom_list_change(Ecore_X_Window win,
411 ecore_x_window_prop_xid_list_change(win, atom, ECORE_X_ATOM_ATOM, item, op);
415 * Set Window (array) property
418 ecore_x_window_prop_window_set(Ecore_X_Window win,
420 Ecore_X_Window *list,
423 ecore_x_window_prop_xid_set(win, atom, ECORE_X_ATOM_WINDOW, list, num);
427 * Sends the GetProperty request.
428 * @param window Window whose properties are requested.
429 * @param atom The atom.
432 ecore_x_window_prop_window_get_prefetch(Ecore_X_Window window,
435 xcb_get_property_cookie_t cookie;
437 cookie = xcb_get_property_unchecked(_ecore_xcb_conn, 0,
442 _ecore_xcb_cookie_cache(cookie.sequence);
447 * Gets the reply of the GetProperty request sent by ecore_x_window_prop_window_get_prefetch().
450 ecore_x_window_prop_window_get_fetch(void)
452 xcb_get_property_cookie_t cookie;
453 xcb_get_property_reply_t *reply;
455 cookie.sequence = _ecore_xcb_cookie_get();
456 reply = xcb_get_property_reply(_ecore_xcb_conn, cookie, NULL);
457 _ecore_xcb_reply_cache(reply);
461 * Get Window (array) property
463 * At most len items are returned in val.
464 * If the property was successfully fetched the number of items stored in
465 * val is returned, otherwise -1 is returned.
466 * Note: Return value 0 means that the property exists but has no elements.
469 ecore_x_window_prop_window_get(Ecore_X_Window win,
471 Ecore_X_Window *list,
474 return ecore_x_window_prop_xid_get(win, atom, ECORE_X_ATOM_WINDOW, list, len);
478 * Get Window (array) property
480 * If the property was successfully fetched the number of items stored in
481 * val is returned, otherwise -1 is returned.
482 * The returned array must be freed with free().
483 * Note: Return value 0 means that the property exists but has no elements.
486 ecore_x_window_prop_window_list_get(Ecore_X_Window win,
488 Ecore_X_Window **plist)
490 return ecore_x_window_prop_xid_list_get(win, atom, ECORE_X_ATOM_WINDOW, plist);
496 * FIXME: To be fixed.
499 ecore_x_window_prop_any_type(void)
501 return XCB_GET_PROPERTY_TYPE_ANY;
506 * @param window The window.
507 * @param property The property atom.
508 * @param type The type atom.
509 * @param size The size.
510 * @param data The data.
511 * @param number The size of the data.
513 * FIXME: To be fixed.
516 ecore_x_window_prop_property_set(Ecore_X_Window window,
517 Ecore_X_Atom property,
523 if (window == 0) window = ((xcb_screen_t *)_ecore_xcb_screen)->root;
524 xcb_change_property(_ecore_xcb_conn, XCB_PROP_MODE_REPLACE, window,
530 * Sends the GetProperty request.
531 * @param window Window whose properties are requested.
532 * @param property Property atom.
533 * @param type Type atom.
536 ecore_x_window_prop_property_get_prefetch(Ecore_X_Window window,
537 Ecore_X_Atom property,
540 xcb_get_property_cookie_t cookie;
542 cookie = xcb_get_property_unchecked(_ecore_xcb_conn, 0,
543 window ? window : ((xcb_screen_t *)_ecore_xcb_screen)->root,
544 property, type, 0, LONG_MAX);
545 _ecore_xcb_cookie_cache(cookie.sequence);
550 * Gets the reply of the GetProperty request sent by ecore_x_window_prop_property_get_prefetch().
553 ecore_x_window_prop_property_get_fetch(void)
555 xcb_get_property_cookie_t cookie;
556 xcb_get_property_reply_t *reply;
558 cookie.sequence = _ecore_xcb_cookie_get();
559 reply = xcb_get_property_reply(_ecore_xcb_conn, cookie, NULL);
560 _ecore_xcb_reply_cache(reply);
565 * @param window The window (Unused).
566 * @param property The property atom (Unused).
567 * @param type The type atom (Unused).
568 * @param size The size (Unused).
569 * @param data The returned data.
570 * @param num The size of the data.
571 * @return 1 on success, 0 otherwise.
573 * FIXME: To be fixed.
576 ecore_x_window_prop_property_get(Ecore_X_Window window __UNUSED__,
577 Ecore_X_Atom property __UNUSED__,
578 Ecore_X_Atom type __UNUSED__,
580 unsigned char **data,
583 xcb_get_property_reply_t *reply;
585 /* make sure these are initialized */
590 else /* we can't store the retrieved data, so just return */
593 reply = _ecore_xcb_reply_get();
597 if ((reply->format != size) ||
598 (reply->value_len == 0))
601 *data = malloc(reply->value_len);
605 memcpy(*data, xcb_get_property_value(reply),
606 xcb_get_property_value_length(reply));
609 *num = reply->value_len;
611 return reply->format;
615 ecore_x_window_prop_property_del(Ecore_X_Window window,
616 Ecore_X_Atom property)
618 xcb_delete_property(_ecore_xcb_conn, window, property);
622 * Sends the ListProperties request.
623 * @param window Window whose properties are requested.
626 ecore_x_window_prop_list_prefetch(Ecore_X_Window window)
628 xcb_list_properties_cookie_t cookie;
630 cookie = xcb_list_properties_unchecked(_ecore_xcb_conn, window);
631 _ecore_xcb_cookie_cache(cookie.sequence);
636 * Gets the reply of the ListProperties request sent by ecore_x_window_prop_list_prefetch().
639 ecore_x_window_prop_list_fetch(void)
641 xcb_list_properties_cookie_t cookie;
642 xcb_list_properties_reply_t *reply;
644 cookie.sequence = _ecore_xcb_cookie_get();
645 reply = xcb_list_properties_reply(_ecore_xcb_conn, cookie, NULL);
646 _ecore_xcb_reply_cache(reply);
652 * @param window The window (Unused).
653 * @param num_ret The number of atoms.
654 * @return The returned atoms.
656 * FIXME: To be fixed.
659 ecore_x_window_prop_list(Ecore_X_Window window __UNUSED__,
662 xcb_list_properties_reply_t *reply;
665 if (num_ret) *num_ret = 0;
667 reply = _ecore_xcb_reply_get();
671 atoms = (Ecore_X_Atom *)malloc(reply->atoms_len * sizeof(Ecore_X_Atom));
675 xcb_list_properties_atoms(reply),
676 reply->atoms_len * sizeof(Ecore_X_Atom));
678 *num_ret = reply->atoms_len;
684 * Set a window string property.
685 * @param win The window
686 * @param type The property
687 * @param str The string
689 * Set a window string property
692 ecore_x_window_prop_string_set(Ecore_X_Window win,
696 if (win == 0) win = ((xcb_screen_t *)_ecore_xcb_screen)->root;
697 xcb_change_property(_ecore_xcb_conn, XCB_PROP_MODE_REPLACE, win,
698 type, ECORE_X_ATOM_UTF8_STRING,
699 8, strlen(str), str);
703 * Sends the GetProperty request.
704 * @param window Window whose properties are requested.
705 * @param type The atom.
708 ecore_x_window_prop_string_get_prefetch(Ecore_X_Window window,
711 xcb_get_property_cookie_t cookie;
713 cookie = xcb_get_property_unchecked(_ecore_xcb_conn, 0,
714 window ? window : ((xcb_screen_t *)_ecore_xcb_screen)->root,
715 type, XCB_GET_PROPERTY_TYPE_ANY, 0L, 1000000L);
716 _ecore_xcb_cookie_cache(cookie.sequence);
721 * Gets the reply of the GetProperty request sent by ecore_x_window_prop_string_get_prefetch().
724 ecore_x_window_prop_string_get_fetch(void)
726 xcb_get_property_cookie_t cookie;
727 xcb_get_property_reply_t *reply;
729 cookie.sequence = _ecore_xcb_cookie_get();
730 reply = xcb_get_property_reply(_ecore_xcb_conn, cookie, NULL);
731 _ecore_xcb_reply_cache(reply);
735 * Get a window string property.
736 * @param window The window
737 * @param type The property
739 * Return window string property of a window. String must be free'd when done.
741 * To use this function, you must call before, and in order,
742 * ecore_x_window_prop_string_get_prefetch(), which sends the GetProperty request,
743 * then ecore_x_window_prop_string_get_fetch(), which gets the reply.
746 ecore_x_window_prop_string_get(Ecore_X_Window window __UNUSED__,
747 Ecore_X_Atom type __UNUSED__)
749 xcb_get_property_reply_t *reply;
752 reply = _ecore_xcb_reply_get();
756 if (reply->type == ECORE_X_ATOM_UTF8_STRING)
760 length = reply->value_len;
761 str = (char *)malloc(length + 1);
763 xcb_get_property_value(reply),
769 /* FIXME: to be done... */
771 /* #ifdef X_HAVE_UTF8_STRING */
772 /* s = Xutf8TextPropertyToTextList(_ecore_xcb_conn, &xtp, */
773 /* &list, &items); */
775 /* s = XmbTextPropertyToTextList(_ecore_xcb_conn, &xtp, */
776 /* &list, &items); */
778 /* if ((s == XLocaleNotSupported) || */
779 /* (s == XNoMemory) || (s == XConverterNotFound)) */
781 /* str = strdup((char *)xtp.value); */
783 /* else if ((s >= Success) && (items > 0)) */
785 /* str = strdup(list[0]); */
788 /* XFreeStringList(list); */
794 /* FIXME : round trips because of GetWMProtocols */
795 /* should we rewrite its code ? */
797 ecore_x_window_prop_protocol_isset(Ecore_X_Window window,
798 Ecore_X_WM_Protocol protocol)
800 xcb_get_property_cookie_t cookie;
801 xcb_get_wm_protocols_reply_t protocols;
806 /* check for invalid values */
807 if (protocol >= ECORE_X_WM_PROTOCOL_NUM)
810 proto = _ecore_xcb_atoms_wm_protocols[protocol];
812 cookie = xcb_get_wm_protocols(_ecore_xcb_conn, window, ECORE_X_ATOM_WM_PROTOCOLS);
814 if (!xcb_get_wm_protocols_reply(_ecore_xcb_conn, cookie, &protocols, NULL))
817 for (i = 0; i < protocols.atoms_len; i++)
818 if (protocols.atoms[i] == proto)
824 xcb_get_wm_protocols_reply_wipe(&protocols);
831 * @param window The window.
832 * @param num_ret The number of WM protocols.
833 * @return The returned WM protocols.
835 * FIXME: To be fixed.
838 /* FIXME : round trips because of get_wm_protocols */
839 /* should we rewrite its code ? */
841 EAPI Ecore_X_WM_Protocol *
842 ecore_x_window_prop_protocol_list_get(Ecore_X_Window window,
845 xcb_get_property_cookie_t cookie;
846 xcb_get_wm_protocols_reply_t protocols;
847 Ecore_X_WM_Protocol *prot_ret = NULL;
848 uint32_t protos_count;
851 cookie = xcb_get_wm_protocols(_ecore_xcb_conn, window, ECORE_X_ATOM_WM_PROTOCOLS);
853 if (!xcb_get_wm_protocols_reply(_ecore_xcb_conn, cookie, &protocols, NULL))
856 if ((protocols.atoms_len <= 0)) return NULL;
858 prot_ret = calloc(1, protocols.atoms_len * sizeof(Ecore_X_WM_Protocol));
861 xcb_get_wm_protocols_reply_wipe(&protocols);
864 for (i = 0; i < protocols.atoms_len; i++)
866 Ecore_X_WM_Protocol j;
869 for (j = 0; j < ECORE_X_WM_PROTOCOL_NUM; j++)
871 if (_ecore_xcb_atoms_wm_protocols[j] == protocols.atoms[i])
875 xcb_get_wm_protocols_reply_wipe(&protocols);
876 *num_ret = protos_count;