2 * vim:ts=8:sw=3:sts=8:noexpandtab:cino=>5n-3f0^-2{2
5 #include "ecore_xcb_private.h"
6 #include "Ecore_X_Atoms.h"
10 * Set CARD32 (array) property
13 ecore_x_window_prop_card32_set(Ecore_X_Window win,
18 xcb_change_property(_ecore_xcb_conn, XCB_PROP_MODE_REPLACE, win,
19 atom, ECORE_X_ATOM_CARDINAL, 32, num, (const void *)val);
23 * Sends the GetProperty request.
24 * @param window Window whose properties are requested.
25 * @param atom The atom.
28 ecore_x_window_prop_card32_get_prefetch(Ecore_X_Window window,
31 xcb_get_property_cookie_t cookie;
33 cookie = xcb_get_property_unchecked(_ecore_xcb_conn, 0,
36 ECORE_X_ATOM_CARDINAL,
38 _ecore_xcb_cookie_cache(cookie.sequence);
43 * Gets the reply of the GetProperty request sent by ecore_x_window_prop_card32_get_prefetch().
46 ecore_x_window_prop_card32_get_fetch(void)
48 xcb_get_property_cookie_t cookie;
49 xcb_get_property_reply_t *reply;
51 cookie.sequence = _ecore_xcb_cookie_get();
52 reply = xcb_get_property_reply(_ecore_xcb_conn, cookie, NULL);
53 _ecore_xcb_reply_cache(reply);
57 * Get CARD32 (array) property
59 * At most len items are returned in val.
60 * If the property was successfully fetched the number of items stored in
61 * val is returned, otherwise -1 is returned.
62 * Note: Return value 0 means that the property exists but has no elements.
65 ecore_x_window_prop_card32_get(Ecore_X_Window win __UNUSED__,
66 Ecore_X_Atom atom __UNUSED__,
70 xcb_get_property_reply_t *reply;
72 reply = _ecore_xcb_reply_get();
74 (reply->type != ECORE_X_ATOM_CARDINAL) ||
75 (reply->format != 32))
78 if (reply->value_len < len)
79 len = xcb_get_property_value_length(reply);
82 memcpy(val, xcb_get_property_value(reply), len);
88 * Get CARD32 (array) property of any length
90 * If the property was successfully fetched the number of items stored in
91 * val is returned, otherwise -1 is returned.
92 * Note: Return value 0 means that the property exists but has no elements.
95 ecore_x_window_prop_card32_list_get(Ecore_X_Window win __UNUSED__,
96 Ecore_X_Atom atom __UNUSED__,
99 xcb_get_property_reply_t *reply;
105 reply = _ecore_xcb_reply_get();
109 if ((reply->type == XCB_NONE) ||
110 (reply->value_len == 0))
112 else if ((reply->type == ECORE_X_ATOM_CARDINAL) &&
113 (reply->format == 32))
117 num = xcb_get_property_value_length(reply);
120 val = (uint32_t *)malloc (num);
124 memcpy(val, xcb_get_property_value(reply), num);
135 * Set X ID (array) property
138 ecore_x_window_prop_xid_set(Ecore_X_Window win,
144 xcb_change_property(_ecore_xcb_conn, XCB_PROP_MODE_REPLACE, win,
145 atom, type, 32, num, xids);
149 * Sends the GetProperty request.
150 * @param window Window whose properties are requested.
151 * @param atom The atom.
152 * @param type The atom type.
155 ecore_x_window_prop_xid_get_prefetch(Ecore_X_Window window,
159 xcb_get_property_cookie_t cookie;
161 cookie = xcb_get_property_unchecked(_ecore_xcb_conn, 0,
166 _ecore_xcb_cookie_cache(cookie.sequence);
171 * Gets the reply of the GetProperty request sent by ecore_x_window_prop_xid_get_prefetch().
174 ecore_x_window_prop_xid_get_fetch(void)
176 xcb_get_property_cookie_t cookie;
177 xcb_get_property_reply_t *reply;
179 cookie.sequence = _ecore_xcb_cookie_get();
180 reply = xcb_get_property_reply(_ecore_xcb_conn, cookie, NULL);
181 _ecore_xcb_reply_cache(reply);
185 * Get X ID (array) property
187 * At most len items are returned in val.
188 * If the property was successfully fetched the number of items stored in
189 * val is returned, otherwise -1 is returned.
190 * Note: Return value 0 means that the property exists but has no elements.
193 ecore_x_window_prop_xid_get(Ecore_X_Window win __UNUSED__,
194 Ecore_X_Atom atom __UNUSED__,
195 Ecore_X_Atom type __UNUSED__,
199 xcb_get_property_reply_t *reply;
202 reply = _ecore_xcb_reply_get();
206 if (reply->type == XCB_NONE)
208 else if (reply->format == 32)
210 if (reply->value_len < len)
211 num = xcb_get_property_value_length(reply);
214 memcpy(xids, xcb_get_property_value(reply), num);
221 * Get X ID (array) property
223 * If the property was successfully fetched the number of items stored in
224 * val is returned, otherwise -1 is returned.
225 * The returned array must be freed with free().
226 * Note: Return value 0 means that the property exists but has no elements.
229 ecore_x_window_prop_xid_list_get(Ecore_X_Window win __UNUSED__,
230 Ecore_X_Atom atom __UNUSED__,
231 Ecore_X_Atom type __UNUSED__,
234 xcb_get_property_reply_t *reply;
240 reply = _ecore_xcb_reply_get();
244 if ((reply->type == XCB_NONE) ||
245 (reply->value_len == 0))
247 else if ((reply->type == ECORE_X_ATOM_CARDINAL) &&
248 (reply->format == 32))
252 num = xcb_get_property_value_length(reply);
255 val = (uint32_t *)malloc (num);
259 memcpy(val, xcb_get_property_value(reply), num);
268 * Remove/add/toggle X ID list item.
271 ecore_x_window_prop_xid_list_change(Ecore_X_Window win,
281 num = ecore_x_window_prop_xid_list_get(win, atom, type, &lst);
283 return; /* Error - assuming invalid window */
286 for (i = 0; i < num; i++)
295 if (op == ECORE_X_PROP_LIST_ADD)
304 /* Was not in list */
305 if (op == ECORE_X_PROP_LIST_REMOVE)
309 lst = realloc(lst, num * sizeof(Ecore_X_ID));
313 ecore_x_window_prop_xid_set(win, atom, type, lst, num);
321 * Set Atom (array) property
324 ecore_x_window_prop_atom_set(Ecore_X_Window win,
329 ecore_x_window_prop_xid_set(win, atom, ECORE_X_ATOM_ATOM, list, num);
333 * Sends the GetProperty request.
334 * @param window Window whose properties are requested.
335 * @param atom Property atom.
338 ecore_x_window_prop_atom_get_prefetch(Ecore_X_Window window,
341 xcb_get_property_cookie_t cookie;
343 cookie = xcb_get_property_unchecked(_ecore_xcb_conn, 0,
348 _ecore_xcb_cookie_cache(cookie.sequence);
353 * Gets the reply of the GetProperty request sent by ecore_x_window_prop_atom_get_prefetch().
356 ecore_x_window_prop_atom_get_fetch(void)
358 xcb_get_property_cookie_t cookie;
359 xcb_get_property_reply_t *reply;
361 cookie.sequence = _ecore_xcb_cookie_get();
362 reply = xcb_get_property_reply(_ecore_xcb_conn, cookie, NULL);
363 _ecore_xcb_reply_cache(reply);
367 * Get Atom (array) property
369 * At most len items are returned in val.
370 * If the property was successfully fetched the number of items stored in
371 * val is returned, otherwise -1 is returned.
372 * Note: Return value 0 means that the property exists but has no elements.
375 ecore_x_window_prop_atom_get(Ecore_X_Window win,
380 return ecore_x_window_prop_xid_get(win, atom, ECORE_X_ATOM_ATOM, list, len);
384 * Get Atom (array) property
386 * If the property was successfully fetched the number of items stored in
387 * val is returned, otherwise -1 is returned.
388 * The returned array must be freed with free().
389 * Note: Return value 0 means that the property exists but has no elements.
392 ecore_x_window_prop_atom_list_get(Ecore_X_Window win,
394 Ecore_X_Atom **plist)
396 return ecore_x_window_prop_xid_list_get(win, atom, ECORE_X_ATOM_ATOM, plist);
400 * Remove/add/toggle atom list item.
403 ecore_x_window_prop_atom_list_change(Ecore_X_Window win,
408 ecore_x_window_prop_xid_list_change(win, atom, ECORE_X_ATOM_ATOM, item, op);
412 * Set Window (array) property
415 ecore_x_window_prop_window_set(Ecore_X_Window win,
417 Ecore_X_Window *list,
420 ecore_x_window_prop_xid_set(win, atom, ECORE_X_ATOM_WINDOW, list, num);
424 * Sends the GetProperty request.
425 * @param window Window whose properties are requested.
426 * @param atom The atom.
429 ecore_x_window_prop_window_get_prefetch(Ecore_X_Window window,
432 xcb_get_property_cookie_t cookie;
434 cookie = xcb_get_property_unchecked(_ecore_xcb_conn, 0,
439 _ecore_xcb_cookie_cache(cookie.sequence);
444 * Gets the reply of the GetProperty request sent by ecore_x_window_prop_window_get_prefetch().
447 ecore_x_window_prop_window_get_fetch(void)
449 xcb_get_property_cookie_t cookie;
450 xcb_get_property_reply_t *reply;
452 cookie.sequence = _ecore_xcb_cookie_get();
453 reply = xcb_get_property_reply(_ecore_xcb_conn, cookie, NULL);
454 _ecore_xcb_reply_cache(reply);
458 * Get Window (array) property
460 * At most len items are returned in val.
461 * If the property was successfully fetched the number of items stored in
462 * val is returned, otherwise -1 is returned.
463 * Note: Return value 0 means that the property exists but has no elements.
466 ecore_x_window_prop_window_get(Ecore_X_Window win,
468 Ecore_X_Window *list,
471 return ecore_x_window_prop_xid_get(win, atom, ECORE_X_ATOM_WINDOW, list, len);
475 * Get Window (array) property
477 * If the property was successfully fetched the number of items stored in
478 * val is returned, otherwise -1 is returned.
479 * The returned array must be freed with free().
480 * Note: Return value 0 means that the property exists but has no elements.
483 ecore_x_window_prop_window_list_get(Ecore_X_Window win,
485 Ecore_X_Window **plist)
487 return ecore_x_window_prop_xid_list_get(win, atom, ECORE_X_ATOM_WINDOW, plist);
493 * FIXME: To be fixed.
496 ecore_x_window_prop_any_type(void)
498 return XCB_GET_PROPERTY_TYPE_ANY;
503 * @param window The window.
504 * @param property The property atom.
505 * @param type The type atom.
506 * @param size The size.
507 * @param data The data.
508 * @param number The size of the data.
510 * FIXME: To be fixed.
513 ecore_x_window_prop_property_set(Ecore_X_Window window,
514 Ecore_X_Atom property,
520 if (window == 0) window = ((xcb_screen_t *)_ecore_xcb_screen)->root;
521 xcb_change_property(_ecore_xcb_conn, XCB_PROP_MODE_REPLACE, window,
527 * Sends the GetProperty request.
528 * @param window Window whose properties are requested.
529 * @param property Property atom.
530 * @param type Type atom.
533 ecore_x_window_prop_property_get_prefetch(Ecore_X_Window window,
534 Ecore_X_Atom property,
537 xcb_get_property_cookie_t cookie;
539 cookie = xcb_get_property_unchecked(_ecore_xcb_conn, 0,
540 window ? window : ((xcb_screen_t *)_ecore_xcb_screen)->root,
541 property, type, 0, LONG_MAX);
542 _ecore_xcb_cookie_cache(cookie.sequence);
547 * Gets the reply of the GetProperty request sent by ecore_x_window_prop_property_get_prefetch().
550 ecore_x_window_prop_property_get_fetch(void)
552 xcb_get_property_cookie_t cookie;
553 xcb_get_property_reply_t *reply;
555 cookie.sequence = _ecore_xcb_cookie_get();
556 reply = xcb_get_property_reply(_ecore_xcb_conn, cookie, NULL);
557 _ecore_xcb_reply_cache(reply);
562 * @param window The window (Unused).
563 * @param property The property atom (Unused).
564 * @param type The type atom (Unused).
565 * @param size The size (Unused).
566 * @param data The returned data.
567 * @param num The size of the data.
568 * @return 1 on success, 0 otherwise.
570 * FIXME: To be fixed.
573 ecore_x_window_prop_property_get(Ecore_X_Window window __UNUSED__,
574 Ecore_X_Atom property __UNUSED__,
575 Ecore_X_Atom type __UNUSED__,
577 unsigned char **data,
580 xcb_get_property_reply_t *reply;
582 /* make sure these are initialized */
587 else /* we can't store the retrieved data, so just return */
590 reply = _ecore_xcb_reply_get();
594 if ((reply->format != size) ||
595 (reply->value_len == 0))
598 *data = malloc(reply->value_len);
602 memcpy(*data, xcb_get_property_value(reply),
603 xcb_get_property_value_length(reply));
606 *num = reply->value_len;
608 return reply->format;
612 ecore_x_window_prop_property_del(Ecore_X_Window window,
613 Ecore_X_Atom property)
615 xcb_delete_property(_ecore_xcb_conn, window, property);
619 * Sends the ListProperties request.
620 * @param window Window whose properties are requested.
623 ecore_x_window_prop_list_prefetch(Ecore_X_Window window)
625 xcb_list_properties_cookie_t cookie;
627 cookie = xcb_list_properties_unchecked(_ecore_xcb_conn, window);
628 _ecore_xcb_cookie_cache(cookie.sequence);
633 * Gets the reply of the ListProperties request sent by ecore_x_window_prop_list_prefetch().
636 ecore_x_window_prop_list_fetch(void)
638 xcb_list_properties_cookie_t cookie;
639 xcb_list_properties_reply_t *reply;
641 cookie.sequence = _ecore_xcb_cookie_get();
642 reply = xcb_list_properties_reply(_ecore_xcb_conn, cookie, NULL);
643 _ecore_xcb_reply_cache(reply);
649 * @param window The window (Unused).
650 * @param num_ret The number of atoms.
651 * @return The returned atoms.
653 * FIXME: To be fixed.
656 ecore_x_window_prop_list(Ecore_X_Window window __UNUSED__,
659 xcb_list_properties_reply_t *reply;
662 if (num_ret) *num_ret = 0;
664 reply = _ecore_xcb_reply_get();
668 atoms = (Ecore_X_Atom *)malloc(reply->atoms_len * sizeof(Ecore_X_Atom));
672 xcb_list_properties_atoms(reply),
673 reply->atoms_len * sizeof(Ecore_X_Atom));
675 *num_ret = reply->atoms_len;
681 * Set a window string property.
682 * @param win The window
683 * @param type The property
684 * @param str The string
686 * Set a window string property
689 ecore_x_window_prop_string_set(Ecore_X_Window win,
693 if (win == 0) 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);
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);
718 * Gets the reply of the GetProperty request sent by ecore_x_window_prop_string_get_prefetch().
721 ecore_x_window_prop_string_get_fetch(void)
723 xcb_get_property_cookie_t cookie;
724 xcb_get_property_reply_t *reply;
726 cookie.sequence = _ecore_xcb_cookie_get();
727 reply = xcb_get_property_reply(_ecore_xcb_conn, cookie, NULL);
728 _ecore_xcb_reply_cache(reply);
732 * Get a window string property.
733 * @param window The window
734 * @param type The property
736 * Return window string property of a window. String must be free'd when done.
738 * To use this function, you must call before, and in order,
739 * ecore_x_window_prop_string_get_prefetch(), which sends the GetProperty request,
740 * then ecore_x_window_prop_string_get_fetch(), which gets the reply.
743 ecore_x_window_prop_string_get(Ecore_X_Window window __UNUSED__,
744 Ecore_X_Atom type __UNUSED__)
746 xcb_get_property_reply_t *reply;
749 reply = _ecore_xcb_reply_get();
753 if (reply->type == ECORE_X_ATOM_UTF8_STRING)
757 length = reply->value_len;
758 str = (char *)malloc(length + 1);
760 xcb_get_property_value(reply),
766 /* FIXME: to be done... */
768 /* #ifdef X_HAVE_UTF8_STRING */
769 /* s = Xutf8TextPropertyToTextList(_ecore_xcb_conn, &xtp, */
770 /* &list, &items); */
772 /* s = XmbTextPropertyToTextList(_ecore_xcb_conn, &xtp, */
773 /* &list, &items); */
775 /* if ((s == XLocaleNotSupported) || */
776 /* (s == XNoMemory) || (s == XConverterNotFound)) */
778 /* str = strdup((char *)xtp.value); */
780 /* else if ((s >= Success) && (items > 0)) */
782 /* str = strdup(list[0]); */
785 /* XFreeStringList(list); */
791 /* FIXME : round trips because of GetWMProtocols */
792 /* should we rewrite its code ? */
794 ecore_x_window_prop_protocol_isset(Ecore_X_Window window,
795 Ecore_X_WM_Protocol protocol)
797 Ecore_X_Atom *protos;
799 uint32_t protos_count;
803 /* check for invalid values */
804 if (protocol >= ECORE_X_WM_PROTOCOL_NUM)
807 proto = _ecore_xcb_atoms_wm_protocols[protocol];
809 if (!xcb_get_wm_protocols(_ecore_xcb_conn, window, &protos_count, &protos))
812 for (i = 0; i < protos_count; i++)
813 if (protos[i] == proto)
826 * @param window The window.
827 * @param num_ret The number of WM protocols.
828 * @return The returned WM protocols.
830 * FIXME: To be fixed.
833 /* FIXME : round trips because of get_wm_protocols */
834 /* should we rewrite its code ? */
836 EAPI Ecore_X_WM_Protocol *
837 ecore_x_window_prop_protocol_list_get(Ecore_X_Window window,
840 Ecore_X_WM_Protocol *prot_ret = NULL;
841 Ecore_X_Atom *protos;
842 uint32_t protos_count;
845 if (!xcb_get_wm_protocols(_ecore_xcb_conn, window, &protos_count, &protos))
848 if ((!protos) || (protos_count <= 0)) return NULL;
850 prot_ret = calloc(1, protos_count * sizeof(Ecore_X_WM_Protocol));
856 for (i = 0; i < protos_count; i++)
858 Ecore_X_WM_Protocol j;
861 for (j = 0; j < ECORE_X_WM_PROTOCOL_NUM; j++)
863 if (_ecore_xcb_atoms_wm_protocols[j] == protos[i])
868 *num_ret = protos_count;