2 * vim:ts=8:sw=3:sts=8:noexpandtab:cino=>5n-3f0^-2{2
13 #include "ecore_x_private.h"
15 #include "Ecore_X_Atoms.h"
19 #define _ATOM_SET_CARD32(win, atom, p_val, cnt) \
20 XChangeProperty(_ecore_x_disp, win, atom, XA_CARDINAL, 32, PropModeReplace, \
21 (unsigned char *)p_val, cnt)
24 * Set CARD32 (array) property
27 ecore_x_window_prop_card32_set(Ecore_X_Window win, Ecore_X_Atom atom,
28 unsigned int *val, unsigned int num)
30 #if SIZEOF_INT == SIZEOF_LONG
31 _ATOM_SET_CARD32(win, atom, val, num);
36 LOGFN(__FILE__, __LINE__, __FUNCTION__);
37 v2 = malloc(num * sizeof(long));
40 for (i = 0; i < num; i++)
42 _ATOM_SET_CARD32(win, atom, v2, num);
48 * Get CARD32 (array) property
50 * At most len items are returned in val.
51 * If the property was successfully fetched the number of items stored in
52 * val is returned, otherwise -1 is returned.
53 * Note: Return value 0 means that the property exists but has no elements.
56 ecore_x_window_prop_card32_get(Ecore_X_Window win, Ecore_X_Atom atom,
57 unsigned int *val, unsigned int len)
59 unsigned char *prop_ret;
61 unsigned long bytes_after, num_ret;
66 LOGFN(__FILE__, __LINE__, __FUNCTION__);
68 if (XGetWindowProperty(_ecore_x_disp, win, atom, 0, 0x7fffffff, False,
69 XA_CARDINAL, &type_ret, &format_ret, &num_ret,
70 &bytes_after, &prop_ret) != Success)
73 if (type_ret != XA_CARDINAL || format_ret != 32)
77 else if (num_ret == 0 || !prop_ret)
85 for (i = 0; i < len; i++)
86 val[i] = ((unsigned long *)prop_ret)[i];
96 * Get CARD32 (array) property of any length
98 * If the property was successfully fetched the number of items stored in
99 * val is returned, otherwise -1 is returned.
100 * Note: Return value 0 means that the property exists but has no elements.
103 ecore_x_window_prop_card32_list_get(Ecore_X_Window win, Ecore_X_Atom atom,
106 unsigned char *prop_ret;
108 unsigned long bytes_after, num_ret;
110 unsigned int i, *val;
113 LOGFN(__FILE__, __LINE__, __FUNCTION__);
116 if (XGetWindowProperty(_ecore_x_disp, win, atom, 0, 0x7fffffff, False,
117 XA_CARDINAL, &type_ret, &format_ret, &num_ret,
118 &bytes_after, &prop_ret) != Success)
121 if (type_ret != XA_CARDINAL || format_ret != 32)
125 else if (num_ret == 0 || !prop_ret)
131 val = malloc(num_ret * sizeof(unsigned int));
132 for (i = 0; i < num_ret; i++)
133 val[i] = ((unsigned long *)prop_ret)[i];
144 * Set X ID (array) property
147 ecore_x_window_prop_xid_set(Ecore_X_Window win, Ecore_X_Atom atom,
148 Ecore_X_Atom type, Ecore_X_ID * lst,
151 #if SIZEOF_INT == SIZEOF_LONG
152 XChangeProperty(_ecore_x_disp, win, atom, type, 32, PropModeReplace,
153 (unsigned char *)lst, num);
158 LOGFN(__FILE__, __LINE__, __FUNCTION__);
159 pl = malloc(num * sizeof(long));
162 for (i = 0; i < num; i++)
164 XChangeProperty(_ecore_x_disp, win, atom, type, 32, PropModeReplace,
165 (unsigned char *)pl, num);
171 * Get X ID (array) property
173 * At most len items are returned in val.
174 * If the property was successfully fetched the number of items stored in
175 * val is returned, otherwise -1 is returned.
176 * Note: Return value 0 means that the property exists but has no elements.
179 ecore_x_window_prop_xid_get(Ecore_X_Window win, Ecore_X_Atom atom,
180 Ecore_X_Atom type, Ecore_X_ID * lst,
183 unsigned char *prop_ret;
185 unsigned long bytes_after, num_ret;
190 LOGFN(__FILE__, __LINE__, __FUNCTION__);
192 if (XGetWindowProperty(_ecore_x_disp, win, atom, 0, 0x7fffffff, False,
193 type, &type_ret, &format_ret, &num_ret,
194 &bytes_after, &prop_ret) != Success)
197 if (type_ret != type || format_ret != 32)
201 else if (num_ret == 0 || !prop_ret)
209 for (i = 0; i < len; i++)
210 lst[i] = ((unsigned long *)prop_ret)[i];
220 * Get X ID (array) property
222 * If the property was successfully fetched the number of items stored in
223 * val is returned, otherwise -1 is returned.
224 * The returned array must be freed with free().
225 * Note: Return value 0 means that the property exists but has no elements.
228 ecore_x_window_prop_xid_list_get(Ecore_X_Window win, Ecore_X_Atom atom,
229 Ecore_X_Atom type, Ecore_X_ID ** val)
231 unsigned char *prop_ret;
233 unsigned long bytes_after, num_ret;
239 LOGFN(__FILE__, __LINE__, __FUNCTION__);
242 if (XGetWindowProperty(_ecore_x_disp, win, atom, 0, 0x7fffffff, False,
243 type, &type_ret, &format_ret, &num_ret,
244 &bytes_after, &prop_ret) != Success)
247 if (type_ret != type || format_ret != 32)
251 else if (num_ret == 0 || !prop_ret)
257 alst = malloc(num_ret * sizeof(Ecore_X_ID));
258 for (i = 0; i < num_ret; i++)
259 alst[i] = ((unsigned long *)prop_ret)[i];
270 * Remove/add/toggle X ID list item.
273 ecore_x_window_prop_xid_list_change(Ecore_X_Window win, Ecore_X_Atom atom,
274 Ecore_X_Atom type, Ecore_X_ID item, int op)
279 LOGFN(__FILE__, __LINE__, __FUNCTION__);
280 num = ecore_x_window_prop_xid_list_get(win, atom, type, &lst);
282 return; /* Error - assuming invalid window */
285 for (i = 0; i < num; i++)
294 if (op == ECORE_X_PROP_LIST_ADD)
303 /* Was not in list */
304 if (op == ECORE_X_PROP_LIST_REMOVE)
308 lst = realloc(lst, num * sizeof(Ecore_X_ID));
312 ecore_x_window_prop_xid_set(win, atom, type, lst, num);
320 * Set Atom (array) property
323 ecore_x_window_prop_atom_set(Ecore_X_Window win, Ecore_X_Atom atom,
324 Ecore_X_Atom * lst, unsigned int num)
326 LOGFN(__FILE__, __LINE__, __FUNCTION__);
327 ecore_x_window_prop_xid_set(win, atom, XA_ATOM, lst, num);
331 * Get Atom (array) property
333 * At most len items are returned in val.
334 * If the property was successfully fetched the number of items stored in
335 * val is returned, otherwise -1 is returned.
336 * Note: Return value 0 means that the property exists but has no elements.
339 ecore_x_window_prop_atom_get(Ecore_X_Window win, Ecore_X_Atom atom,
340 Ecore_X_Atom * lst, unsigned int len)
342 LOGFN(__FILE__, __LINE__, __FUNCTION__);
343 return ecore_x_window_prop_xid_get(win, atom, XA_ATOM, lst, len);
347 * Get Atom (array) property
349 * If the property was successfully fetched the number of items stored in
350 * val is returned, otherwise -1 is returned.
351 * The returned array must be freed with free().
352 * Note: Return value 0 means that the property exists but has no elements.
355 ecore_x_window_prop_atom_list_get(Ecore_X_Window win, Ecore_X_Atom atom,
356 Ecore_X_Atom ** plst)
358 LOGFN(__FILE__, __LINE__, __FUNCTION__);
359 return ecore_x_window_prop_xid_list_get(win, atom, XA_ATOM, plst);
363 * Remove/add/toggle atom list item.
366 ecore_x_window_prop_atom_list_change(Ecore_X_Window win, Ecore_X_Atom atom,
367 Ecore_X_Atom item, int op)
369 LOGFN(__FILE__, __LINE__, __FUNCTION__);
370 ecore_x_window_prop_xid_list_change(win, atom, XA_ATOM, item, op);
374 * Set Window (array) property
377 ecore_x_window_prop_window_set(Ecore_X_Window win, Ecore_X_Atom atom,
378 Ecore_X_Window * lst, unsigned int num)
380 LOGFN(__FILE__, __LINE__, __FUNCTION__);
381 ecore_x_window_prop_xid_set(win, atom, XA_WINDOW, lst, num);
385 * Get Window (array) property
387 * At most len items are returned in val.
388 * If the property was successfully fetched the number of items stored in
389 * val is returned, otherwise -1 is returned.
390 * Note: Return value 0 means that the property exists but has no elements.
393 ecore_x_window_prop_window_get(Ecore_X_Window win, Ecore_X_Atom atom,
394 Ecore_X_Window * lst, unsigned int len)
396 LOGFN(__FILE__, __LINE__, __FUNCTION__);
397 return ecore_x_window_prop_xid_get(win, atom, XA_WINDOW, lst, len);
401 * Get Window (array) property
403 * If the property was successfully fetched the number of items stored in
404 * val is returned, otherwise -1 is returned.
405 * The returned array must be freed with free().
406 * Note: Return value 0 means that the property exists but has no elements.
409 ecore_x_window_prop_window_list_get(Ecore_X_Window win, Ecore_X_Atom atom,
410 Ecore_X_Window ** plst)
412 LOGFN(__FILE__, __LINE__, __FUNCTION__);
413 return ecore_x_window_prop_xid_list_get(win, atom, XA_WINDOW, plst);
419 * FIXME: To be fixed.
422 ecore_x_window_prop_any_type(void)
424 return AnyPropertyType;
430 * FIXME: To be fixed.
433 ecore_x_window_prop_property_set(Ecore_X_Window win, Ecore_X_Atom property, Ecore_X_Atom type, int size, void *data, int number)
435 LOGFN(__FILE__, __LINE__, __FUNCTION__);
436 if (win == 0) win = DefaultRootWindow(_ecore_x_disp);
438 XChangeProperty(_ecore_x_disp, win, property, type, size, PropModeReplace,
439 (unsigned char *)data, number);
445 dat = malloc(sizeof(unsigned long) * number);
448 for (ptr = (int *)data, i = 0; i < number; i++) dat[i] = ptr[i];
449 XChangeProperty(_ecore_x_disp, win, property, type, size,
450 PropModeReplace, (unsigned char *)dat, number);
459 * FIXME: To be fixed.
462 ecore_x_window_prop_property_get(Ecore_X_Window win, Ecore_X_Atom property, Ecore_X_Atom type, int size __UNUSED__, unsigned char **data, int *num)
465 int ret, size_ret = 0;
466 unsigned long num_ret = 0, bytes = 0, i;
467 unsigned char *prop_ret = NULL;
469 /* make sure these are initialized */
474 else /* we can't store the retrieved data, so just return */
477 LOGFN(__FILE__, __LINE__, __FUNCTION__);
478 if (!win) win = DefaultRootWindow(_ecore_x_disp);
480 ret = XGetWindowProperty(_ecore_x_disp, win, property, 0, LONG_MAX,
481 False, type, &type_ret, &size_ret,
482 &num_ret, &bytes, &prop_ret);
492 if (!(*data = malloc(num_ret * size_ret / 8))) {
499 for (i = 0; i < num_ret; i++)
500 (*data)[i] = prop_ret[i];
503 for (i = 0; i < num_ret; i++)
504 ((unsigned short *) *data)[i] = ((unsigned short *) prop_ret)[i];
507 for (i = 0; i < num_ret; i++)
508 ((unsigned int *) *data)[i] = ((unsigned long *) prop_ret)[i];
514 if (num) *num = num_ret;
519 ecore_x_window_prop_property_del(Ecore_X_Window win, Ecore_X_Atom property)
521 LOGFN(__FILE__, __LINE__, __FUNCTION__);
522 XDeleteProperty(_ecore_x_disp, win, property);
526 ecore_x_window_prop_list(Ecore_X_Window win, int *num_ret)
532 LOGFN(__FILE__, __LINE__, __FUNCTION__);
533 if (num_ret) *num_ret = 0;
535 atom_ret = XListProperties(_ecore_x_disp, win, &num);
536 if (!atom_ret) return NULL;
538 atoms = malloc(num * sizeof(Ecore_X_Atom));
541 for (i = 0; i < num; i++) atoms[i] = atom_ret[i];
542 if (num_ret) *num_ret = num;
549 * Set a window string property.
550 * @param win The window
551 * @param type The property
552 * @param str The string
554 * Set a window string property
557 ecore_x_window_prop_string_set(Ecore_X_Window win, Ecore_X_Atom type, const char *str)
561 LOGFN(__FILE__, __LINE__, __FUNCTION__);
562 if (win == 0) win = DefaultRootWindow(_ecore_x_disp);
563 xtp.value = (unsigned char *)str;
565 xtp.encoding = ECORE_X_ATOM_UTF8_STRING;
566 xtp.nitems = strlen(str);
567 XSetTextProperty(_ecore_x_disp, win, &xtp, type);
571 * Get a window string property.
572 * @param win The window
573 * @param type The property
575 * Return window string property of a window. String must be free'd when done.
578 ecore_x_window_prop_string_get(Ecore_X_Window win, Ecore_X_Atom type)
583 LOGFN(__FILE__, __LINE__, __FUNCTION__);
584 if (win == 0) win = DefaultRootWindow(_ecore_x_disp);
585 if (XGetTextProperty(_ecore_x_disp, win, &xtp, type))
591 if (xtp.encoding == ECORE_X_ATOM_UTF8_STRING)
593 str = strdup((char *)xtp.value);
597 #ifdef X_HAVE_UTF8_STRING
598 s = Xutf8TextPropertyToTextList(_ecore_x_disp, &xtp,
601 s = XmbTextPropertyToTextList(_ecore_x_disp, &xtp,
604 if ((s == XLocaleNotSupported) ||
605 (s == XNoMemory) || (s == XConverterNotFound))
607 str = strdup((char *)xtp.value);
609 else if ((s >= Success) && (items > 0))
611 str = strdup(list[0]);
614 XFreeStringList(list);
622 ecore_x_window_prop_protocol_isset(Ecore_X_Window win,
623 Ecore_X_WM_Protocol protocol)
625 Atom proto, *protos = NULL;
626 int i, ret = 0, protos_count = 0;
628 /* check for invalid values */
629 if (protocol >= ECORE_X_WM_PROTOCOL_NUM)
632 LOGFN(__FILE__, __LINE__, __FUNCTION__);
633 proto = _ecore_x_atoms_wm_protocols[protocol];
635 if (!XGetWMProtocols(_ecore_x_disp, win, &protos, &protos_count))
638 for (i = 0; i < protos_count; i++)
639 if (protos[i] == proto)
653 * FIXME: To be fixed.
655 EAPI Ecore_X_WM_Protocol *
656 ecore_x_window_prop_protocol_list_get(Ecore_X_Window win, int *num_ret)
659 int i, protos_count = 0;
660 Ecore_X_WM_Protocol *prot_ret = NULL;
662 LOGFN(__FILE__, __LINE__, __FUNCTION__);
663 if (!XGetWMProtocols(_ecore_x_disp, win, &protos, &protos_count))
666 if ((!protos) || (protos_count <= 0)) return NULL;
667 prot_ret = calloc(1, protos_count * sizeof(Ecore_X_WM_Protocol));
673 for (i = 0; i < protos_count; i++)
675 Ecore_X_WM_Protocol j;
678 for (j = 0; j < ECORE_X_WM_PROTOCOL_NUM; j++)
680 if (_ecore_x_atoms_wm_protocols[j] == protos[i])
685 *num_ret = protos_count;