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 */
44 if (_ecore_xlib_sync) ecore_x_sync();
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,
61 unsigned char *prop_ret;
63 unsigned long bytes_after, num_ret;
68 LOGFN(__FILE__, __LINE__, __FUNCTION__);
70 if (XGetWindowProperty(_ecore_x_disp, win, atom, 0, 0x7fffffff, False,
71 XA_CARDINAL, &type_ret, &format_ret, &num_ret,
72 &bytes_after, &prop_ret) != Success)
75 if (type_ret != XA_CARDINAL || format_ret != 32)
77 else if (num_ret == 0 || !prop_ret)
84 for (i = 0; i < len; i++)
85 val[i] = ((unsigned long *)prop_ret)[i];
89 if (_ecore_xlib_sync) ecore_x_sync();
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,
107 unsigned char *prop_ret;
109 unsigned long bytes_after, num_ret;
111 unsigned int i, *val;
114 LOGFN(__FILE__, __LINE__, __FUNCTION__);
117 if (XGetWindowProperty(_ecore_x_disp, win, atom, 0, 0x7fffffff, False,
118 XA_CARDINAL, &type_ret, &format_ret, &num_ret,
119 &bytes_after, &prop_ret) != Success)
122 if ((type_ret != XA_CARDINAL) || (format_ret != 32))
124 else if ((num_ret == 0) || (!prop_ret))
128 val = malloc(num_ret * sizeof(unsigned int));
131 if (prop_ret) XFree(prop_ret);
134 for (i = 0; i < num_ret; i++)
135 val[i] = ((unsigned long *)prop_ret)[i];
140 if (_ecore_xlib_sync) ecore_x_sync();
147 * Set X ID (array) property
150 ecore_x_window_prop_xid_set(Ecore_X_Window win,
156 #if SIZEOF_INT == SIZEOF_LONG
157 XChangeProperty(_ecore_x_disp, win, atom, type, 32, PropModeReplace,
158 (unsigned char *)lst, num);
159 #else /* if SIZEOF_INT == SIZEOF_LONG */
163 LOGFN(__FILE__, __LINE__, __FUNCTION__);
164 pl = malloc(num * sizeof(unsigned long));
168 for (i = 0; i < num; i++)
170 XChangeProperty(_ecore_x_disp, win, atom, type, 32, PropModeReplace,
171 (unsigned char *)pl, num);
173 #endif /* if SIZEOF_INT == SIZEOF_LONG */
174 if (_ecore_xlib_sync) ecore_x_sync();
178 * Get X ID (array) property
180 * At most len items are returned in val.
181 * If the property was successfully fetched the number of items stored in
182 * val is returned, otherwise -1 is returned.
183 * Note: Return value 0 means that the property exists but has no elements.
186 ecore_x_window_prop_xid_get(Ecore_X_Window win,
192 unsigned char *prop_ret;
194 unsigned long bytes_after, num_ret;
200 LOGFN(__FILE__, __LINE__, __FUNCTION__);
202 success = (XGetWindowProperty(_ecore_x_disp, win, atom, 0, 0x7fffffff, False,
203 type, &type_ret, &format_ret, &num_ret,
204 &bytes_after, &prop_ret) == Success);
205 if (_ecore_xlib_sync) ecore_x_sync();
206 if (!success) return -1;
208 if (type_ret != type || format_ret != 32)
210 else if (num_ret == 0 || !prop_ret)
217 for (i = 0; i < len; i++)
218 lst[i] = ((unsigned long *)prop_ret)[i];
229 * Get X ID (array) property
231 * If the property was successfully fetched the number of items stored in
232 * val is returned, otherwise -1 is returned.
233 * The returned array must be freed with free().
234 * Note: Return value 0 means that the property exists but has no elements.
237 ecore_x_window_prop_xid_list_get(Ecore_X_Window win,
242 unsigned char *prop_ret;
244 unsigned long bytes_after, num_ret;
251 LOGFN(__FILE__, __LINE__, __FUNCTION__);
254 success = (XGetWindowProperty(_ecore_x_disp, win, atom, 0, 0x7fffffff, False,
255 type, &type_ret, &format_ret, &num_ret,
256 &bytes_after, &prop_ret) == Success);
257 if (_ecore_xlib_sync) ecore_x_sync();
258 if (!success) return -1;
260 if (type_ret != type || format_ret != 32)
262 else if (num_ret == 0 || !prop_ret)
266 alst = malloc(num_ret * sizeof(Ecore_X_ID));
267 for (i = 0; i < num_ret; i++)
268 alst[i] = ((unsigned long *)prop_ret)[i];
279 * Remove/add/toggle X ID list item.
282 ecore_x_window_prop_xid_list_change(Ecore_X_Window win,
288 Ecore_X_ID *lst, *temp;
291 LOGFN(__FILE__, __LINE__, __FUNCTION__);
292 num = ecore_x_window_prop_xid_list_get(win, atom, type, &lst);
295 return; /* Error - assuming invalid window */
299 for (i = 0; i < num; i++)
308 if (op == ECORE_X_PROP_LIST_ADD)
309 goto done; /* Remove it */
317 /* Was not in list */
318 if (op == ECORE_X_PROP_LIST_REMOVE)
319 goto done; /* Add it */
324 lst = realloc(lst, num * sizeof(Ecore_X_ID));
336 ecore_x_window_prop_xid_set(win, atom, type, lst, num);
344 * Set Atom (array) property
347 ecore_x_window_prop_atom_set(Ecore_X_Window win,
352 LOGFN(__FILE__, __LINE__, __FUNCTION__);
353 ecore_x_window_prop_xid_set(win, atom, XA_ATOM, lst, num);
357 * Get Atom (array) property
359 * At most len items are returned in val.
360 * If the property was successfully fetched the number of items stored in
361 * val is returned, otherwise -1 is returned.
362 * Note: Return value 0 means that the property exists but has no elements.
365 ecore_x_window_prop_atom_get(Ecore_X_Window win,
371 LOGFN(__FILE__, __LINE__, __FUNCTION__);
372 ret = ecore_x_window_prop_xid_get(win, atom, XA_ATOM, lst, len);
377 * Get Atom (array) property
379 * If the property was successfully fetched the number of items stored in
380 * val is returned, otherwise -1 is returned.
381 * The returned array must be freed with free().
382 * Note: Return value 0 means that the property exists but has no elements.
385 ecore_x_window_prop_atom_list_get(Ecore_X_Window win,
390 LOGFN(__FILE__, __LINE__, __FUNCTION__);
391 ret = ecore_x_window_prop_xid_list_get(win, atom, XA_ATOM, plst);
396 * Remove/add/toggle atom list item.
399 ecore_x_window_prop_atom_list_change(Ecore_X_Window win,
404 LOGFN(__FILE__, __LINE__, __FUNCTION__);
405 ecore_x_window_prop_xid_list_change(win, atom, XA_ATOM, item, op);
409 * Set Window (array) property
412 ecore_x_window_prop_window_set(Ecore_X_Window win,
417 LOGFN(__FILE__, __LINE__, __FUNCTION__);
418 ecore_x_window_prop_xid_set(win, atom, XA_WINDOW, lst, num);
422 * Get Window (array) property
424 * At most len items are returned in val.
425 * If the property was successfully fetched the number of items stored in
426 * val is returned, otherwise -1 is returned.
427 * Note: Return value 0 means that the property exists but has no elements.
430 ecore_x_window_prop_window_get(Ecore_X_Window win,
436 LOGFN(__FILE__, __LINE__, __FUNCTION__);
437 ret = ecore_x_window_prop_xid_get(win, atom, XA_WINDOW, lst, len);
442 * Get Window (array) property
444 * If the property was successfully fetched the number of items stored in
445 * val is returned, otherwise -1 is returned.
446 * The returned array must be freed with free().
447 * Note: Return value 0 means that the property exists but has no elements.
450 ecore_x_window_prop_window_list_get(Ecore_X_Window win,
452 Ecore_X_Window **plst)
455 LOGFN(__FILE__, __LINE__, __FUNCTION__);
456 ret = ecore_x_window_prop_xid_list_get(win, atom, XA_WINDOW, plst);
461 ecore_x_window_prop_any_type(void)
463 return AnyPropertyType;
467 * @brief Set a property of Ecore_X_Window.
468 * @param win The window for which the property will be set.
469 * @param property The property of the window to be set.
470 * @param type The type of the property that will be set.
471 * @param size The size of the property that will be set.
472 * @param data The data of the property that will be set.
473 * @param number The size of data.
476 ecore_x_window_prop_property_set(Ecore_X_Window win,
477 Ecore_X_Atom property,
483 LOGFN(__FILE__, __LINE__, __FUNCTION__);
485 win = DefaultRootWindow(_ecore_x_disp);
488 XChangeProperty(_ecore_x_disp,
494 (unsigned char *)data,
501 dat = malloc(sizeof(unsigned long) * number);
504 for (ptr = (int *)data, i = 0; i < number; i++)
506 XChangeProperty(_ecore_x_disp, win, property, type, size,
507 PropModeReplace, (unsigned char *)dat, number);
511 if (_ecore_xlib_sync) ecore_x_sync();
515 * @brief Get a property of Ecore_X_Window.
516 * @note If there aren't any data to be got the function return NULL.
517 * If the function can't allocate the memory then 0 is returned.
518 * @param win The window for which the property will be got.
519 * @param property The property of the window that will be gotten.
520 * @param type The type of the property that will be gotten.
521 * @param size This parameter isn't in use.
522 * @param data The data of the property that will be gotten.
523 * @param num The size of property.
524 * @return size_ret The size of array that contains the property.
527 ecore_x_window_prop_property_get(Ecore_X_Window win,
528 Ecore_X_Atom property,
530 int size EINA_UNUSED,
531 unsigned char **data,
535 int ret, size_ret = 0;
536 unsigned long num_ret = 0, bytes = 0, i;
537 unsigned char *prop_ret = NULL;
539 /* make sure these are initialized */
545 else /* we can't store the retrieved data, so just return */
548 LOGFN(__FILE__, __LINE__, __FUNCTION__);
550 win = DefaultRootWindow(_ecore_x_disp);
552 ret = XGetWindowProperty(_ecore_x_disp, win, property, 0, LONG_MAX,
553 False, type, &type_ret, &size_ret,
554 &num_ret, &bytes, &prop_ret);
555 if (_ecore_xlib_sync) ecore_x_sync();
558 if ((!num_ret) || (size_ret <= 0))
564 if (!(*data = malloc(num_ret * size_ret / 8)))
572 for (i = 0; i < num_ret; i++)
573 (*data)[i] = prop_ret[i];
577 for (i = 0; i < num_ret; i++)
578 ((unsigned short *)*data)[i] = ((unsigned short *)prop_ret)[i];
582 for (i = 0; i < num_ret; i++)
583 ((unsigned int *)*data)[i] = ((unsigned long *)prop_ret)[i];
596 ecore_x_window_prop_property_del(Ecore_X_Window win,
597 Ecore_X_Atom property)
599 LOGFN(__FILE__, __LINE__, __FUNCTION__);
600 XDeleteProperty(_ecore_x_disp, win, property);
601 if (_ecore_xlib_sync) ecore_x_sync();
605 ecore_x_window_prop_list(Ecore_X_Window win,
612 LOGFN(__FILE__, __LINE__, __FUNCTION__);
616 atom_ret = XListProperties(_ecore_x_disp, win, &num);
617 if (_ecore_xlib_sync) ecore_x_sync();
621 atoms = malloc(num * sizeof(Ecore_X_Atom));
624 for (i = 0; i < num; i++)
625 atoms[i] = atom_ret[i];
635 * Set a window string property.
636 * @param win The window
637 * @param type The property
638 * @param str The string
640 * Set a window string property
643 ecore_x_window_prop_string_set(Ecore_X_Window win,
649 LOGFN(__FILE__, __LINE__, __FUNCTION__);
651 win = DefaultRootWindow(_ecore_x_disp);
653 xtp.value = (unsigned char *)str;
655 xtp.encoding = ECORE_X_ATOM_UTF8_STRING;
656 xtp.nitems = strlen(str);
657 XSetTextProperty(_ecore_x_disp, win, &xtp, type);
658 if (_ecore_xlib_sync) ecore_x_sync();
662 * Get a window string property.
663 * @param win The window
664 * @param type The property
665 * @return Window string property of a window. String must be free'd when done.
668 ecore_x_window_prop_string_get(Ecore_X_Window win,
674 LOGFN(__FILE__, __LINE__, __FUNCTION__);
676 win = DefaultRootWindow(_ecore_x_disp);
678 if (XGetTextProperty(_ecore_x_disp, win, &xtp, type))
684 if (_ecore_xlib_sync) ecore_x_sync();
685 if (xtp.encoding == ECORE_X_ATOM_UTF8_STRING)
686 str = strdup((char *)xtp.value);
689 #ifdef X_HAVE_UTF8_STRING
690 s = Xutf8TextPropertyToTextList(_ecore_x_disp, &xtp,
692 #else /* ifdef X_HAVE_UTF8_STRING */
693 s = XmbTextPropertyToTextList(_ecore_x_disp, &xtp,
695 #endif /* ifdef X_HAVE_UTF8_STRING */
696 if (_ecore_xlib_sync) ecore_x_sync();
697 if ((s == XLocaleNotSupported) ||
698 (s == XNoMemory) || (s == XConverterNotFound))
699 str = strdup((char *)xtp.value);
700 else if ((s >= Success) && (items > 0))
701 str = strdup(list[0]);
704 XFreeStringList(list);
713 ecore_x_window_prop_protocol_isset(Ecore_X_Window win,
714 Ecore_X_WM_Protocol protocol)
716 Atom proto, *protos = NULL;
717 int i, protos_count = 0;
718 Eina_Bool ret = EINA_FALSE;
720 /* check for invalid values */
721 if (protocol >= ECORE_X_WM_PROTOCOL_NUM)
724 LOGFN(__FILE__, __LINE__, __FUNCTION__);
725 proto = _ecore_x_atoms_wm_protocols[protocol];
727 ret = XGetWMProtocols(_ecore_x_disp, win, &protos, &protos_count);
728 if (_ecore_xlib_sync) ecore_x_sync();
732 for (i = 0; i < protos_count; i++)
733 if (protos[i] == proto)
744 * @brief Get a array containing the protocols of @a win
745 * @note If there aren't any properties to be counted or any protocols to get
746 * then the function returns NULL.
747 * @param win The window for which protocol list will be got.
748 * @param num_ret Contains the number of elements of the array to be returned.
749 * @return The array that contains the protocols.
751 EAPI Ecore_X_WM_Protocol *
752 ecore_x_window_prop_protocol_list_get(Ecore_X_Window win,
756 int i, protos_count = 0;
757 Ecore_X_WM_Protocol *prot_ret = NULL;
760 LOGFN(__FILE__, __LINE__, __FUNCTION__);
761 success = XGetWMProtocols(_ecore_x_disp, win, &protos, &protos_count);
762 if (_ecore_xlib_sync) ecore_x_sync();
766 if ((!protos) || (protos_count <= 0))
769 prot_ret = calloc(1, protos_count * sizeof(Ecore_X_WM_Protocol));
776 for (i = 0; i < protos_count; i++)
778 Ecore_X_WM_Protocol j;
781 for (j = 0; j < ECORE_X_WM_PROTOCOL_NUM; j++)
783 if (_ecore_x_atoms_wm_protocols[j] == protos[i])
788 *num_ret = protos_count;