1 #include "ecore_xcb_private.h"
2 #include <xcb/xcb_icccm.h>
5 ecore_x_window_prop_card32_get(Ecore_X_Window win,
10 xcb_get_property_cookie_t cookie;
11 xcb_get_property_reply_t *reply;
14 LOGFN(__FILE__, __LINE__, __FUNCTION__);
17 cookie = xcb_get_property_unchecked(_ecore_xcb_conn, 0, win, atom,
18 ECORE_X_ATOM_CARDINAL, 0, 0x7fffffff);
19 reply = xcb_get_property_reply(_ecore_xcb_conn, cookie, NULL);
20 if (!reply) return -1;
22 if ((reply->type != ECORE_X_ATOM_CARDINAL) || (reply->format != 32))
24 else if (reply->value_len == 0)
28 if (reply->value_len < len)
29 len = reply->value_len;
36 v = xcb_get_property_value(reply);
37 for (i = 0; i < len; i++)
38 val[i] = ((uint32_t *)v)[i];
43 if (reply) free(reply);
48 ecore_x_window_prop_card32_set(Ecore_X_Window win,
53 LOGFN(__FILE__, __LINE__, __FUNCTION__);
56 #if SIZEOF_INT == SIZEOF_LONG
57 xcb_change_property(_ecore_xcb_conn, XCB_PROP_MODE_REPLACE, win, atom,
58 ECORE_X_ATOM_CARDINAL, 32, num, (unsigned char *)val);
64 v2 = malloc(num * sizeof(long));
66 for (i = 0; i < num; i++)
69 xcb_change_property(_ecore_xcb_conn, XCB_PROP_MODE_REPLACE, win, atom,
70 ECORE_X_ATOM_CARDINAL, 32, num, (unsigned char *)v2);
77 ecore_x_window_prop_card32_list_get(Ecore_X_Window win,
81 xcb_get_property_cookie_t cookie;
82 xcb_get_property_reply_t *reply;
85 LOGFN(__FILE__, __LINE__, __FUNCTION__);
88 if (list) *list = NULL;
90 cookie = xcb_get_property_unchecked(_ecore_xcb_conn, 0, win, atom,
91 XCB_ATOM_CARDINAL, 0, 0x7fffffff);
92 reply = xcb_get_property_reply(_ecore_xcb_conn, cookie, NULL);
93 if (!reply) return -1;
95 if ((reply->type != XCB_ATOM_CARDINAL) || (reply->format != 32))
97 else if ((reply->value_len == 0) || (!xcb_get_property_value(reply)))
101 num = reply->value_len;
108 val = malloc(num * sizeof(unsigned int));
114 data = xcb_get_property_value(reply);
115 for (i = 0; i < num; i++)
116 val[i] = ((uint32_t *)data)[i];
126 ecore_x_window_prop_atom_get(Ecore_X_Window win,
131 LOGFN(__FILE__, __LINE__, __FUNCTION__);
133 return ecore_x_window_prop_xid_get(win, atom, ECORE_X_ATOM_ATOM, list, len);
137 ecore_x_window_prop_atom_set(Ecore_X_Window win,
142 LOGFN(__FILE__, __LINE__, __FUNCTION__);
144 /* xcb_change_property(_ecore_xcb_conn, XCB_PROP_MODE_REPLACE, win, atom, */
145 /* ECORE_X_ATOM_ATOM, 32, num, list); */
146 ecore_x_window_prop_xid_set(win, atom, ECORE_X_ATOM_ATOM, list, num);
150 ecore_x_window_prop_xid_set(Ecore_X_Window win,
156 LOGFN(__FILE__, __LINE__, __FUNCTION__);
159 #if SIZEOF_INT == SIZEOF_LONG
160 xcb_change_property(_ecore_xcb_conn, XCB_PROP_MODE_REPLACE, win, atom,
161 type, 32, num, (unsigned char *)xids);
167 v2 = malloc(num * sizeof(long));
169 for (i = 0; i < num; i++)
172 xcb_change_property(_ecore_xcb_conn, XCB_PROP_MODE_REPLACE, win, atom,
173 type, 32, num, (unsigned char *)v2);
180 ecore_x_window_prop_xid_get(Ecore_X_Window win,
186 xcb_get_property_cookie_t cookie;
187 xcb_get_property_reply_t *reply;
190 LOGFN(__FILE__, __LINE__, __FUNCTION__);
194 cookie = xcb_get_property_unchecked(_ecore_xcb_conn, 0, win, atom, type,
196 reply = xcb_get_property_reply(_ecore_xcb_conn, cookie, NULL);
197 if (!reply) return -1;
199 if ((reply->type != type) || (reply->format != 32))
201 else if (reply->value_len == 0)
208 if (reply->value_len < len)
209 len = reply->value_len;
211 v = xcb_get_property_value(reply);
212 for (i = 0; i < len; i++)
213 xids[i] = ((uint32_t *)v)[i];
218 if (reply) free(reply);
223 ecore_x_window_prop_string_set(Ecore_X_Window win,
227 LOGFN(__FILE__, __LINE__, __FUNCTION__);
230 xcb_change_property(_ecore_xcb_conn, XCB_PROP_MODE_REPLACE, win, type,
231 ECORE_X_ATOM_UTF8_STRING, 8, strlen(str), str);
236 ecore_x_window_prop_string_get(Ecore_X_Window win,
239 xcb_get_property_cookie_t cookie;
240 xcb_get_property_reply_t *reply;
244 LOGFN(__FILE__, __LINE__, __FUNCTION__);
248 xcb_get_property_unchecked(_ecore_xcb_conn, 0,
249 win ? win : ((xcb_screen_t *)_ecore_xcb_screen)->root,
250 type, XCB_GET_PROPERTY_TYPE_ANY, 0, 1000000L);
251 reply = xcb_get_property_reply(_ecore_xcb_conn, cookie, NULL);
252 if (!reply) return NULL;
254 len = ((reply->value_len * reply->format) / 8);
255 str = (char *)malloc((len + 1) * sizeof(char));
256 memcpy(str, xcb_get_property_value(reply), len);
259 if (reply->type != ECORE_X_ATOM_UTF8_STRING)
261 Ecore_Xcb_Textproperty prop;
264 Eina_Bool ret = EINA_FALSE;
266 prop.value = strdup(str);
268 prop.encoding = reply->type;
271 ret = _ecore_xcb_utf8_textproperty_to_textlist(&prop, &list, &count);
273 ret = _ecore_xcb_mb_textproperty_to_textlist(&prop, &list, &count);
278 str = strdup(list[0]);
280 str = strdup((char *)prop.value);
282 if (list) free(list);
285 str = strdup((char *)prop.value);
293 ecore_x_window_prop_window_get(Ecore_X_Window win,
295 Ecore_X_Window *list,
298 LOGFN(__FILE__, __LINE__, __FUNCTION__);
300 return ecore_x_window_prop_xid_get(win, atom, ECORE_X_ATOM_WINDOW, list, len);
304 ecore_x_window_prop_window_set(Ecore_X_Window win,
306 Ecore_X_Window *list,
309 LOGFN(__FILE__, __LINE__, __FUNCTION__);
311 ecore_x_window_prop_xid_set(win, atom, ECORE_X_ATOM_WINDOW, list, num);
315 ecore_x_window_prop_window_list_get(Ecore_X_Window win,
317 Ecore_X_Window **plst)
319 LOGFN(__FILE__, __LINE__, __FUNCTION__);
321 return ecore_x_window_prop_xid_list_get(win, atom, ECORE_X_ATOM_WINDOW, plst);
325 ecore_x_window_prop_any_type(void)
331 ecore_x_window_prop_property_del(Ecore_X_Window win,
332 Ecore_X_Atom property)
334 LOGFN(__FILE__, __LINE__, __FUNCTION__);
337 xcb_delete_property(_ecore_xcb_conn, win, property);
341 ecore_x_window_prop_property_set(Ecore_X_Window win,
342 Ecore_X_Atom property,
348 LOGFN(__FILE__, __LINE__, __FUNCTION__);
352 win = ((xcb_screen_t *)_ecore_xcb_screen)->root;
356 xcb_change_property(_ecore_xcb_conn, XCB_PROP_MODE_REPLACE, win,
357 property, type, size, num, (unsigned char *)data);
365 dat = malloc(sizeof(uint32_t) * num);
368 for (ptr = (int *)data, i = 0; i < num; i++)
370 xcb_change_property(_ecore_xcb_conn, XCB_PROP_MODE_REPLACE, win,
371 property, type, size, num,
372 (unsigned char *)dat);
380 ecore_x_window_prop_property_get(Ecore_X_Window win,
381 Ecore_X_Atom property,
384 unsigned char **data,
387 xcb_get_property_cookie_t cookie;
388 xcb_get_property_reply_t *reply;
393 LOGFN(__FILE__, __LINE__, __FUNCTION__);
404 win = ((xcb_screen_t *)_ecore_xcb_screen)->root;
407 xcb_get_property_unchecked(_ecore_xcb_conn, 0, win,
408 property, type, 0, UINT_MAX);
409 reply = xcb_get_property_reply(_ecore_xcb_conn, cookie, NULL);
410 if (!reply) return 0;
411 if ((reply->format != size) || (reply->value_len == 0))
417 if (!(*data = malloc(reply->value_len * reply->format / 8)))
423 value = xcb_get_property_value(reply);
424 switch (reply->format)
427 for (i = 0; i < reply->value_len; i++)
428 (*data)[i] = ((unsigned char *)value)[i];
432 for (i = 0; i < reply->value_len; i++)
433 ((unsigned short *)*data)[i] = ((unsigned short *)value)[i];
437 for (i = 0; i < reply->value_len; i++)
438 ((unsigned int *)*data)[i] = ((uint32_t *)value)[i];
442 if (num) *num = reply->value_len;
443 format = reply->format;
449 ecore_x_window_prop_atom_list_get(Ecore_X_Window win,
453 LOGFN(__FILE__, __LINE__, __FUNCTION__);
455 return ecore_x_window_prop_xid_list_get(win, atom, ECORE_X_ATOM_ATOM, list);
459 ecore_x_window_prop_atom_list_change(Ecore_X_Window win,
464 LOGFN(__FILE__, __LINE__, __FUNCTION__);
465 ecore_x_window_prop_xid_list_change(win, atom, ECORE_X_ATOM_ATOM, item, op);
469 ecore_x_window_prop_xid_list_get(Ecore_X_Window win,
474 xcb_get_property_cookie_t cookie;
475 xcb_get_property_reply_t *reply;
478 LOGFN(__FILE__, __LINE__, __FUNCTION__);
481 if (xids) *xids = NULL;
483 cookie = xcb_get_property_unchecked(_ecore_xcb_conn, 0, win, atom, type,
485 reply = xcb_get_property_reply(_ecore_xcb_conn, cookie, NULL);
486 if (!reply) return -1;
488 if ((reply->type != type) || (reply->format != 32))
490 else if ((reply->value_len == 0) || (!xcb_get_property_value(reply)))
497 num = xcb_get_property_value_length(reply);
498 val = xcb_get_property_value(reply);
499 alst = malloc(num * sizeof(Ecore_X_ID));
504 for (i = 0; i < num; i++)
505 alst[i] = ((uint32_t *)val)[i];
515 ecore_x_window_prop_xid_list_change(Ecore_X_Window win,
524 LOGFN(__FILE__, __LINE__, __FUNCTION__);
527 num = ecore_x_window_prop_xid_list_get(win, atom, type, &lst);
530 for (i = 0; i < num; i++)
532 if (lst[i] == item) break;
537 if (op == ECORE_X_PROP_LIST_ADD)
545 if (op == ECORE_X_PROP_LIST_REMOVE)
548 lst = realloc(lst, num * sizeof(Ecore_X_ID));
551 ecore_x_window_prop_xid_set(win, atom, type, lst, num);
558 ecore_x_window_prop_protocol_isset(Ecore_X_Window win,
559 Ecore_X_WM_Protocol protocol)
561 Eina_Bool ret = EINA_FALSE;
563 #ifdef OLD_XCB_VERSION
564 xcb_get_wm_protocols_reply_t protos;
566 xcb_icccm_get_wm_protocols_reply_t protos;
568 xcb_get_property_cookie_t cookie;
570 uint32_t count = 0, i = 0;
572 LOGFN(__FILE__, __LINE__, __FUNCTION__);
575 if (protocol >= ECORE_X_WM_PROTOCOL_NUM) return EINA_FALSE;
577 proto = _ecore_xcb_atoms_wm_protocol[protocol];
578 #ifdef OLD_XCB_VERSION
579 cookie = xcb_get_wm_protocols_unchecked(_ecore_xcb_conn, win,
580 ECORE_X_ATOM_WM_PROTOCOLS);
581 reply = xcb_get_wm_protocols_reply(_ecore_xcb_conn, cookie, &protos, NULL);
583 cookie = xcb_icccm_get_wm_protocols_unchecked(_ecore_xcb_conn, win,
584 ECORE_X_ATOM_WM_PROTOCOLS);
585 reply = xcb_icccm_get_wm_protocols_reply(_ecore_xcb_conn, cookie,
588 if (!reply) return EINA_FALSE;
590 count = protos.atoms_len;
591 for (i = 0; i < count; i++)
593 if (protos.atoms[i] == proto)
600 #ifdef OLD_XCB_VERSION
601 xcb_get_wm_protocols_reply_wipe(&protos);
603 xcb_icccm_get_wm_protocols_reply_wipe(&protos);
608 EAPI Ecore_X_WM_Protocol *
609 ecore_x_window_prop_protocol_list_get(Ecore_X_Window win,
612 #ifdef OLD_XCB_VERSION
613 xcb_get_wm_protocols_reply_t protos;
615 xcb_icccm_get_wm_protocols_reply_t protos;
617 xcb_get_property_cookie_t cookie;
619 uint32_t count = 0, i = 0;
620 Ecore_X_WM_Protocol *prot_ret = NULL;
622 LOGFN(__FILE__, __LINE__, __FUNCTION__);
625 if (!num_ret) return NULL;
629 #ifdef OLD_XCB_VERSION
630 cookie = xcb_get_wm_protocols_unchecked(_ecore_xcb_conn, win,
631 ECORE_X_ATOM_WM_PROTOCOLS);
632 reply = xcb_get_wm_protocols_reply(_ecore_xcb_conn, cookie, &protos, NULL);
634 cookie = xcb_icccm_get_wm_protocols_unchecked(_ecore_xcb_conn, win,
635 ECORE_X_ATOM_WM_PROTOCOLS);
636 reply = xcb_icccm_get_wm_protocols_reply(_ecore_xcb_conn, cookie,
639 if (!reply) return NULL;
641 count = protos.atoms_len;
644 #ifdef OLD_XCB_VERSION
645 xcb_get_wm_protocols_reply_wipe(&protos);
647 xcb_icccm_get_wm_protocols_reply_wipe(&protos);
652 prot_ret = calloc(1, count * sizeof(Ecore_X_WM_Protocol));
655 #ifdef OLD_XCB_VERSION
656 xcb_get_wm_protocols_reply_wipe(&protos);
658 xcb_icccm_get_wm_protocols_reply_wipe(&protos);
663 for (i = 0; i < count; i++)
665 Ecore_X_WM_Protocol j;
668 for (j = 0; j < ECORE_X_WM_PROTOCOL_NUM; j++)
670 if (_ecore_xcb_atoms_wm_protocol[j] == protos.atoms[i])
675 if (num_ret) *num_ret = count;
677 #ifdef OLD_XCB_VERSION
678 xcb_get_wm_protocols_reply_wipe(&protos);
680 xcb_icccm_get_wm_protocols_reply_wipe(&protos);
686 ecore_x_window_prop_list(Ecore_X_Window win,
689 xcb_list_properties_cookie_t cookie;
690 xcb_list_properties_reply_t *reply;
695 LOGFN(__FILE__, __LINE__, __FUNCTION__);
700 cookie = xcb_list_properties_unchecked(_ecore_xcb_conn, win);
701 reply = xcb_list_properties_reply(_ecore_xcb_conn, cookie, NULL);
702 if (!reply) return NULL;
704 atoms = (Ecore_X_Atom *)malloc(reply->atoms_len * sizeof(Ecore_X_Atom));
711 atm = xcb_list_properties_atoms(reply);
712 for (i = 0; i < reply->atoms_len; i++)
715 if (num) *num = reply->atoms_len;