3 #endif /* ifdef HAVE_CONFIG_H */
9 #include "ecore_x_private.h"
11 #include "Ecore_X_Atoms.h"
15 #define _ATOM_SET_CARD32(win, atom, p_val, cnt) \
16 XChangeProperty(_ecore_x_disp, win, atom, XA_CARDINAL, 32, PropModeReplace, \
17 (unsigned char *)p_val, cnt)
20 * Set CARD32 (array) property
23 ecore_x_window_prop_card32_set(Ecore_X_Window win,
28 #if SIZEOF_INT == SIZEOF_LONG
29 _ATOM_SET_CARD32(win, atom, val, num);
30 #else /* if SIZEOF_INT == SIZEOF_LONG */
34 LOGFN(__FILE__, __LINE__, __FUNCTION__);
35 v2 = malloc(num * sizeof(long));
39 for (i = 0; i < num; i++)
41 _ATOM_SET_CARD32(win, atom, v2, num);
43 #endif /* if SIZEOF_INT == SIZEOF_LONG */
47 * Get CARD32 (array) property
49 * At most len items are returned in val.
50 * If the property was successfully fetched the number of items stored in
51 * val is returned, otherwise -1 is returned.
52 * Note: Return value 0 means that the property exists but has no elements.
55 ecore_x_window_prop_card32_get(Ecore_X_Window win,
60 unsigned char *prop_ret;
62 unsigned long bytes_after, num_ret;
67 LOGFN(__FILE__, __LINE__, __FUNCTION__);
69 if (XGetWindowProperty(_ecore_x_disp, win, atom, 0, 0x7fffffff, False,
70 XA_CARDINAL, &type_ret, &format_ret, &num_ret,
71 &bytes_after, &prop_ret) != Success)
74 if (type_ret != XA_CARDINAL || format_ret != 32)
76 else if (num_ret == 0 || !prop_ret)
83 for (i = 0; i < len; i++)
84 val[i] = ((unsigned long *)prop_ret)[i];
95 * Get CARD32 (array) property of any length
97 * If the property was successfully fetched the number of items stored in
98 * val is returned, otherwise -1 is returned.
99 * Note: Return value 0 means that the property exists but has no elements.
102 ecore_x_window_prop_card32_list_get(Ecore_X_Window win,
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))
123 else if ((num_ret == 0) || (!prop_ret))
127 val = malloc(num_ret * sizeof(unsigned int));
130 if (prop_ret) XFree(prop_ret);
133 for (i = 0; i < num_ret; i++)
134 val[i] = ((unsigned long *)prop_ret)[i];
146 * Set X ID (array) property
149 ecore_x_window_prop_xid_set(Ecore_X_Window win,
155 #if SIZEOF_INT == SIZEOF_LONG
156 XChangeProperty(_ecore_x_disp, win, atom, type, 32, PropModeReplace,
157 (unsigned char *)lst, num);
158 #else /* if SIZEOF_INT == SIZEOF_LONG */
162 LOGFN(__FILE__, __LINE__, __FUNCTION__);
163 pl = malloc(num * sizeof(long));
167 for (i = 0; i < num; i++)
169 XChangeProperty(_ecore_x_disp, win, atom, type, 32, PropModeReplace,
170 (unsigned char *)pl, num);
172 #endif /* if SIZEOF_INT == SIZEOF_LONG */
176 * Get X ID (array) property
178 * At most len items are returned in val.
179 * If the property was successfully fetched the number of items stored in
180 * val is returned, otherwise -1 is returned.
181 * Note: Return value 0 means that the property exists but has no elements.
184 ecore_x_window_prop_xid_get(Ecore_X_Window win,
190 unsigned char *prop_ret;
192 unsigned long bytes_after, num_ret;
197 LOGFN(__FILE__, __LINE__, __FUNCTION__);
199 if (XGetWindowProperty(_ecore_x_disp, win, atom, 0, 0x7fffffff, False,
200 type, &type_ret, &format_ret, &num_ret,
201 &bytes_after, &prop_ret) != Success)
204 if (type_ret != type || format_ret != 32)
206 else if (num_ret == 0 || !prop_ret)
213 for (i = 0; i < len; i++)
214 lst[i] = ((unsigned long *)prop_ret)[i];
225 * Get X ID (array) property
227 * If the property was successfully fetched the number of items stored in
228 * val is returned, otherwise -1 is returned.
229 * The returned array must be freed with free().
230 * Note: Return value 0 means that the property exists but has no elements.
233 ecore_x_window_prop_xid_list_get(Ecore_X_Window win,
238 unsigned char *prop_ret;
240 unsigned long bytes_after, num_ret;
246 LOGFN(__FILE__, __LINE__, __FUNCTION__);
249 if (XGetWindowProperty(_ecore_x_disp, win, atom, 0, 0x7fffffff, False,
250 type, &type_ret, &format_ret, &num_ret,
251 &bytes_after, &prop_ret) != Success)
254 if (type_ret != type || format_ret != 32)
256 else if (num_ret == 0 || !prop_ret)
260 alst = malloc(num_ret * sizeof(Ecore_X_ID));
261 for (i = 0; i < num_ret; i++)
262 alst[i] = ((unsigned long *)prop_ret)[i];
274 * Remove/add/toggle X ID list item.
277 ecore_x_window_prop_xid_list_change(Ecore_X_Window win,
286 LOGFN(__FILE__, __LINE__, __FUNCTION__);
287 num = ecore_x_window_prop_xid_list_get(win, atom, type, &lst);
290 return; /* Error - assuming invalid window */
294 for (i = 0; i < num; i++)
303 if (op == ECORE_X_PROP_LIST_ADD)
304 goto done; /* Remove it */
312 /* Was not in list */
313 if (op == ECORE_X_PROP_LIST_REMOVE)
314 goto done; /* Add it */
317 lst = realloc(lst, num * sizeof(Ecore_X_ID));
321 ecore_x_window_prop_xid_set(win, atom, type, lst, num);
329 * Set Atom (array) property
332 ecore_x_window_prop_atom_set(Ecore_X_Window win,
337 LOGFN(__FILE__, __LINE__, __FUNCTION__);
338 ecore_x_window_prop_xid_set(win, atom, XA_ATOM, lst, num);
342 * Get Atom (array) property
344 * At most len items are returned in val.
345 * If the property was successfully fetched the number of items stored in
346 * val is returned, otherwise -1 is returned.
347 * Note: Return value 0 means that the property exists but has no elements.
350 ecore_x_window_prop_atom_get(Ecore_X_Window win,
355 LOGFN(__FILE__, __LINE__, __FUNCTION__);
356 return ecore_x_window_prop_xid_get(win, atom, XA_ATOM, lst, len);
360 * Get Atom (array) property
362 * If the property was successfully fetched the number of items stored in
363 * val is returned, otherwise -1 is returned.
364 * The returned array must be freed with free().
365 * Note: Return value 0 means that the property exists but has no elements.
368 ecore_x_window_prop_atom_list_get(Ecore_X_Window win,
372 LOGFN(__FILE__, __LINE__, __FUNCTION__);
373 return ecore_x_window_prop_xid_list_get(win, atom, XA_ATOM, plst);
377 * Remove/add/toggle atom list item.
380 ecore_x_window_prop_atom_list_change(Ecore_X_Window win,
385 LOGFN(__FILE__, __LINE__, __FUNCTION__);
386 ecore_x_window_prop_xid_list_change(win, atom, XA_ATOM, item, op);
390 * Set Window (array) property
393 ecore_x_window_prop_window_set(Ecore_X_Window win,
398 LOGFN(__FILE__, __LINE__, __FUNCTION__);
399 ecore_x_window_prop_xid_set(win, atom, XA_WINDOW, lst, num);
403 * Get Window (array) property
405 * At most len items are returned in val.
406 * If the property was successfully fetched the number of items stored in
407 * val is returned, otherwise -1 is returned.
408 * Note: Return value 0 means that the property exists but has no elements.
411 ecore_x_window_prop_window_get(Ecore_X_Window win,
416 LOGFN(__FILE__, __LINE__, __FUNCTION__);
417 return ecore_x_window_prop_xid_get(win, atom, XA_WINDOW, lst, len);
421 * Get Window (array) property
423 * If the property was successfully fetched the number of items stored in
424 * val is returned, otherwise -1 is returned.
425 * The returned array must be freed with free().
426 * Note: Return value 0 means that the property exists but has no elements.
429 ecore_x_window_prop_window_list_get(Ecore_X_Window win,
431 Ecore_X_Window **plst)
433 LOGFN(__FILE__, __LINE__, __FUNCTION__);
434 return ecore_x_window_prop_xid_list_get(win, atom, XA_WINDOW, plst);
438 ecore_x_window_prop_any_type(void)
440 return AnyPropertyType;
444 * @brief Set a property of Ecore_X_Window.
445 * @param win The window for which the property will be set.
446 * @param property The property of the window to be set.
447 * @param type The type of the property that will be set.
448 * @param size The size of the property that will be set.
449 * @param data The data of the property that will be set.
450 * @param number The size of data.
453 ecore_x_window_prop_property_set(Ecore_X_Window win,
454 Ecore_X_Atom property,
460 LOGFN(__FILE__, __LINE__, __FUNCTION__);
462 win = DefaultRootWindow(_ecore_x_disp);
465 XChangeProperty(_ecore_x_disp,
471 (unsigned char *)data,
478 dat = malloc(sizeof(unsigned long) * number);
481 for (ptr = (int *)data, i = 0; i < number; i++)
483 XChangeProperty(_ecore_x_disp, win, property, type, size,
484 PropModeReplace, (unsigned char *)dat, number);
491 * @brief Get a property of Ecore_X_Window.
492 * @note If there aren't any data to be got the function return NULL.
493 * If the function can't allocate the memory then 0 is returned.
494 * @param win The window for which the property will be got.
495 * @param property The property of the window that will be gotten.
496 * @param type The type of the property that will be gotten.
497 * @param size This parameter isn't in use.
498 * @param data The data of the property that will be gotten.
499 * @param num The size of property.
500 * @return size_ret The size of array that contains the property.
503 ecore_x_window_prop_property_get(Ecore_X_Window win,
504 Ecore_X_Atom property,
507 unsigned char **data,
511 int ret, size_ret = 0;
512 unsigned long num_ret = 0, bytes = 0, i;
513 unsigned char *prop_ret = NULL;
515 /* make sure these are initialized */
521 else /* we can't store the retrieved data, so just return */
524 LOGFN(__FILE__, __LINE__, __FUNCTION__);
526 win = DefaultRootWindow(_ecore_x_disp);
528 ret = XGetWindowProperty(_ecore_x_disp, win, property, 0, LONG_MAX,
529 False, type, &type_ret, &size_ret,
530 &num_ret, &bytes, &prop_ret);
541 if (!(*data = malloc(num_ret * size_ret / 8)))
549 for (i = 0; i < num_ret; i++)
550 (*data)[i] = prop_ret[i];
554 for (i = 0; i < num_ret; i++)
555 ((unsigned short *)*data)[i] = ((unsigned short *)prop_ret)[i];
559 for (i = 0; i < num_ret; i++)
560 ((unsigned int *)*data)[i] = ((unsigned long *)prop_ret)[i];
573 ecore_x_window_prop_property_del(Ecore_X_Window win,
574 Ecore_X_Atom property)
576 LOGFN(__FILE__, __LINE__, __FUNCTION__);
577 XDeleteProperty(_ecore_x_disp, win, property);
581 ecore_x_window_prop_list(Ecore_X_Window win,
588 LOGFN(__FILE__, __LINE__, __FUNCTION__);
592 atom_ret = XListProperties(_ecore_x_disp, win, &num);
596 atoms = malloc(num * sizeof(Ecore_X_Atom));
599 for (i = 0; i < num; i++)
600 atoms[i] = atom_ret[i];
610 * Set a window string property.
611 * @param win The window
612 * @param type The property
613 * @param str The string
615 * Set a window string property
618 ecore_x_window_prop_string_set(Ecore_X_Window win,
624 LOGFN(__FILE__, __LINE__, __FUNCTION__);
626 win = DefaultRootWindow(_ecore_x_disp);
628 xtp.value = (unsigned char *)str;
630 xtp.encoding = ECORE_X_ATOM_UTF8_STRING;
631 xtp.nitems = strlen(str);
632 XSetTextProperty(_ecore_x_disp, win, &xtp, type);
636 * Get a window string property.
637 * @param win The window
638 * @param type The property
639 * @return Window string property of a window. String must be free'd when done.
642 ecore_x_window_prop_string_get(Ecore_X_Window win,
648 LOGFN(__FILE__, __LINE__, __FUNCTION__);
650 win = DefaultRootWindow(_ecore_x_disp);
652 if (XGetTextProperty(_ecore_x_disp, win, &xtp, type))
658 if (xtp.encoding == ECORE_X_ATOM_UTF8_STRING)
659 str = strdup((char *)xtp.value);
662 #ifdef X_HAVE_UTF8_STRING
663 s = Xutf8TextPropertyToTextList(_ecore_x_disp, &xtp,
665 #else /* ifdef X_HAVE_UTF8_STRING */
666 s = XmbTextPropertyToTextList(_ecore_x_disp, &xtp,
668 #endif /* ifdef X_HAVE_UTF8_STRING */
669 if ((s == XLocaleNotSupported) ||
670 (s == XNoMemory) || (s == XConverterNotFound))
671 str = strdup((char *)xtp.value);
672 else if ((s >= Success) && (items > 0))
673 str = strdup(list[0]);
676 XFreeStringList(list);
686 ecore_x_window_prop_protocol_isset(Ecore_X_Window win,
687 Ecore_X_WM_Protocol protocol)
689 Atom proto, *protos = NULL;
690 int i, protos_count = 0;
691 Eina_Bool ret = EINA_FALSE;
693 /* check for invalid values */
694 if (protocol >= ECORE_X_WM_PROTOCOL_NUM)
697 LOGFN(__FILE__, __LINE__, __FUNCTION__);
698 proto = _ecore_x_atoms_wm_protocols[protocol];
700 if (!XGetWMProtocols(_ecore_x_disp, win, &protos, &protos_count))
703 for (i = 0; i < protos_count; i++)
704 if (protos[i] == proto)
716 * @brief Get a array containing the protocols of @a win
717 * @note If there aren't any properties to be counted or any protocols to get
718 * then the function returns NULL.
719 * @param win The window for which protocol list will be got.
720 * @param num_ret Contains the number of elements of the array to be returned.
721 * @return The array that contains the protocols.
723 EAPI Ecore_X_WM_Protocol *
724 ecore_x_window_prop_protocol_list_get(Ecore_X_Window win,
728 int i, protos_count = 0;
729 Ecore_X_WM_Protocol *prot_ret = NULL;
731 LOGFN(__FILE__, __LINE__, __FUNCTION__);
732 if (!XGetWMProtocols(_ecore_x_disp, win, &protos, &protos_count))
735 if ((!protos) || (protos_count <= 0))
738 prot_ret = calloc(1, protos_count * sizeof(Ecore_X_WM_Protocol));
745 for (i = 0; i < protos_count; i++)
747 Ecore_X_WM_Protocol j;
750 for (j = 0; j < ECORE_X_WM_PROTOCOL_NUM; j++)
752 if (_ecore_x_atoms_wm_protocols[j] == protos[i])
757 *num_ret = protos_count;