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, Ecore_X_Atom atom,
24 unsigned int *val, unsigned int num)
26 #if SIZEOF_INT == SIZEOF_LONG
27 _ATOM_SET_CARD32(win, atom, val, num);
28 #else /* if SIZEOF_INT == SIZEOF_LONG */
32 LOGFN(__FILE__, __LINE__, __FUNCTION__);
33 v2 = malloc(num * sizeof(long));
37 for (i = 0; i < num; i++)
39 _ATOM_SET_CARD32(win, atom, v2, num);
41 #endif /* if SIZEOF_INT == SIZEOF_LONG */
42 } /* ecore_x_window_prop_card32_set */
45 * Get CARD32 (array) property
47 * At most len items are returned in val.
48 * If the property was successfully fetched the number of items stored in
49 * val is returned, otherwise -1 is returned.
50 * Note: Return value 0 means that the property exists but has no elements.
53 ecore_x_window_prop_card32_get(Ecore_X_Window win, Ecore_X_Atom atom,
54 unsigned int *val, unsigned int len)
56 unsigned char *prop_ret;
58 unsigned long bytes_after, num_ret;
63 LOGFN(__FILE__, __LINE__, __FUNCTION__);
65 if (XGetWindowProperty(_ecore_x_disp, win, atom, 0, 0x7fffffff, False,
66 XA_CARDINAL, &type_ret, &format_ret, &num_ret,
67 &bytes_after, &prop_ret) != Success)
70 if (type_ret != XA_CARDINAL || format_ret != 32)
72 else if (num_ret == 0 || !prop_ret)
79 for (i = 0; i < len; i++)
80 val[i] = ((unsigned long *)prop_ret)[i];
88 } /* ecore_x_window_prop_card32_get */
91 * Get CARD32 (array) property of any length
93 * If the property was successfully fetched the number of items stored in
94 * val is returned, otherwise -1 is returned.
95 * Note: Return value 0 means that the property exists but has no elements.
98 ecore_x_window_prop_card32_list_get(Ecore_X_Window win, Ecore_X_Atom atom,
101 unsigned char *prop_ret;
103 unsigned long bytes_after, num_ret;
105 unsigned int i, *val;
108 LOGFN(__FILE__, __LINE__, __FUNCTION__);
111 if (XGetWindowProperty(_ecore_x_disp, win, atom, 0, 0x7fffffff, False,
112 XA_CARDINAL, &type_ret, &format_ret, &num_ret,
113 &bytes_after, &prop_ret) != Success)
116 if (type_ret != XA_CARDINAL || format_ret != 32)
118 else if (num_ret == 0 || !prop_ret)
122 val = malloc(num_ret * sizeof(unsigned int));
123 for (i = 0; i < num_ret; i++)
124 val[i] = ((unsigned long *)prop_ret)[i];
133 } /* ecore_x_window_prop_card32_list_get */
136 * Set X ID (array) property
139 ecore_x_window_prop_xid_set(Ecore_X_Window win, Ecore_X_Atom atom,
140 Ecore_X_Atom type, Ecore_X_ID *lst,
143 #if SIZEOF_INT == SIZEOF_LONG
144 XChangeProperty(_ecore_x_disp, win, atom, type, 32, PropModeReplace,
145 (unsigned char *)lst, num);
146 #else /* if SIZEOF_INT == SIZEOF_LONG */
150 LOGFN(__FILE__, __LINE__, __FUNCTION__);
151 pl = malloc(num * sizeof(long));
155 for (i = 0; i < num; i++)
157 XChangeProperty(_ecore_x_disp, win, atom, type, 32, PropModeReplace,
158 (unsigned char *)pl, num);
160 #endif /* if SIZEOF_INT == SIZEOF_LONG */
161 } /* ecore_x_window_prop_xid_set */
164 * Get X ID (array) property
166 * At most len items are returned in val.
167 * If the property was successfully fetched the number of items stored in
168 * val is returned, otherwise -1 is returned.
169 * Note: Return value 0 means that the property exists but has no elements.
172 ecore_x_window_prop_xid_get(Ecore_X_Window win, Ecore_X_Atom atom,
173 Ecore_X_Atom type, Ecore_X_ID *lst,
176 unsigned char *prop_ret;
178 unsigned long bytes_after, num_ret;
183 LOGFN(__FILE__, __LINE__, __FUNCTION__);
185 if (XGetWindowProperty(_ecore_x_disp, win, atom, 0, 0x7fffffff, False,
186 type, &type_ret, &format_ret, &num_ret,
187 &bytes_after, &prop_ret) != Success)
190 if (type_ret != type || format_ret != 32)
192 else if (num_ret == 0 || !prop_ret)
199 for (i = 0; i < len; i++)
200 lst[i] = ((unsigned long *)prop_ret)[i];
208 } /* ecore_x_window_prop_xid_get */
211 * Get X ID (array) property
213 * If the property was successfully fetched the number of items stored in
214 * val is returned, otherwise -1 is returned.
215 * The returned array must be freed with free().
216 * Note: Return value 0 means that the property exists but has no elements.
219 ecore_x_window_prop_xid_list_get(Ecore_X_Window win, Ecore_X_Atom atom,
220 Ecore_X_Atom type, Ecore_X_ID **val)
222 unsigned char *prop_ret;
224 unsigned long bytes_after, num_ret;
230 LOGFN(__FILE__, __LINE__, __FUNCTION__);
233 if (XGetWindowProperty(_ecore_x_disp, win, atom, 0, 0x7fffffff, False,
234 type, &type_ret, &format_ret, &num_ret,
235 &bytes_after, &prop_ret) != Success)
238 if (type_ret != type || format_ret != 32)
240 else if (num_ret == 0 || !prop_ret)
244 alst = malloc(num_ret * sizeof(Ecore_X_ID));
245 for (i = 0; i < num_ret; i++)
246 alst[i] = ((unsigned long *)prop_ret)[i];
255 } /* ecore_x_window_prop_xid_list_get */
258 * Remove/add/toggle X ID list item.
261 ecore_x_window_prop_xid_list_change(Ecore_X_Window win, Ecore_X_Atom atom,
262 Ecore_X_Atom type, Ecore_X_ID item, int op)
267 LOGFN(__FILE__, __LINE__, __FUNCTION__);
268 num = ecore_x_window_prop_xid_list_get(win, atom, type, &lst);
271 return; /* Error - assuming invalid window */
275 for (i = 0; i < num; i++)
284 if (op == ECORE_X_PROP_LIST_ADD)
285 goto done; /* Remove it */
293 /* Was not in list */
294 if (op == ECORE_X_PROP_LIST_REMOVE)
295 goto done; /* Add it */
298 lst = realloc(lst, num * sizeof(Ecore_X_ID));
302 ecore_x_window_prop_xid_set(win, atom, type, lst, num);
307 } /* ecore_x_window_prop_xid_list_change */
310 * Set Atom (array) property
313 ecore_x_window_prop_atom_set(Ecore_X_Window win, Ecore_X_Atom atom,
314 Ecore_X_Atom *lst, unsigned int num)
316 LOGFN(__FILE__, __LINE__, __FUNCTION__);
317 ecore_x_window_prop_xid_set(win, atom, XA_ATOM, lst, num);
318 } /* ecore_x_window_prop_atom_set */
321 * Get Atom (array) property
323 * At most len items are returned in val.
324 * If the property was successfully fetched the number of items stored in
325 * val is returned, otherwise -1 is returned.
326 * Note: Return value 0 means that the property exists but has no elements.
329 ecore_x_window_prop_atom_get(Ecore_X_Window win, Ecore_X_Atom atom,
330 Ecore_X_Atom *lst, unsigned int len)
332 LOGFN(__FILE__, __LINE__, __FUNCTION__);
333 return ecore_x_window_prop_xid_get(win, atom, XA_ATOM, lst, len);
334 } /* ecore_x_window_prop_atom_get */
337 * Get Atom (array) property
339 * If the property was successfully fetched the number of items stored in
340 * val is returned, otherwise -1 is returned.
341 * The returned array must be freed with free().
342 * Note: Return value 0 means that the property exists but has no elements.
345 ecore_x_window_prop_atom_list_get(Ecore_X_Window win, Ecore_X_Atom atom,
348 LOGFN(__FILE__, __LINE__, __FUNCTION__);
349 return ecore_x_window_prop_xid_list_get(win, atom, XA_ATOM, plst);
350 } /* ecore_x_window_prop_atom_list_get */
353 * Remove/add/toggle atom list item.
356 ecore_x_window_prop_atom_list_change(Ecore_X_Window win, Ecore_X_Atom atom,
357 Ecore_X_Atom item, int op)
359 LOGFN(__FILE__, __LINE__, __FUNCTION__);
360 ecore_x_window_prop_xid_list_change(win, atom, XA_ATOM, item, op);
361 } /* ecore_x_window_prop_atom_list_change */
364 * Set Window (array) property
367 ecore_x_window_prop_window_set(Ecore_X_Window win, Ecore_X_Atom atom,
368 Ecore_X_Window *lst, unsigned int num)
370 LOGFN(__FILE__, __LINE__, __FUNCTION__);
371 ecore_x_window_prop_xid_set(win, atom, XA_WINDOW, lst, num);
372 } /* ecore_x_window_prop_window_set */
375 * Get Window (array) property
377 * At most len items are returned in val.
378 * If the property was successfully fetched the number of items stored in
379 * val is returned, otherwise -1 is returned.
380 * Note: Return value 0 means that the property exists but has no elements.
383 ecore_x_window_prop_window_get(Ecore_X_Window win, Ecore_X_Atom atom,
384 Ecore_X_Window *lst, unsigned int len)
386 LOGFN(__FILE__, __LINE__, __FUNCTION__);
387 return ecore_x_window_prop_xid_get(win, atom, XA_WINDOW, lst, len);
388 } /* ecore_x_window_prop_window_get */
391 * Get Window (array) property
393 * If the property was successfully fetched the number of items stored in
394 * val is returned, otherwise -1 is returned.
395 * The returned array must be freed with free().
396 * Note: Return value 0 means that the property exists but has no elements.
399 ecore_x_window_prop_window_list_get(Ecore_X_Window win, Ecore_X_Atom atom,
400 Ecore_X_Window **plst)
402 LOGFN(__FILE__, __LINE__, __FUNCTION__);
403 return ecore_x_window_prop_xid_list_get(win, atom, XA_WINDOW, plst);
404 } /* ecore_x_window_prop_window_list_get */
409 * FIXME: To be fixed.
412 ecore_x_window_prop_any_type(void)
414 return AnyPropertyType;
415 } /* ecore_x_window_prop_any_type */
420 * FIXME: To be fixed.
423 ecore_x_window_prop_property_set(Ecore_X_Window win,
424 Ecore_X_Atom property,
430 LOGFN(__FILE__, __LINE__, __FUNCTION__);
432 win = DefaultRootWindow(_ecore_x_disp);
435 XChangeProperty(_ecore_x_disp,
441 (unsigned char *)data,
448 dat = malloc(sizeof(unsigned long) * number);
451 for (ptr = (int *)data, i = 0; i < number; i++) dat[i] = ptr[i];
452 XChangeProperty(_ecore_x_disp, win, property, type, size,
453 PropModeReplace, (unsigned char *)dat, number);
457 } /* ecore_x_window_prop_property_set */
462 * FIXME: To be fixed.
465 ecore_x_window_prop_property_get(Ecore_X_Window win,
466 Ecore_X_Atom property,
469 unsigned char **data,
473 int ret, size_ret = 0;
474 unsigned long num_ret = 0, bytes = 0, i;
475 unsigned char *prop_ret = NULL;
477 /* make sure these are initialized */
483 else /* we can't store the retrieved data, so just return */
486 LOGFN(__FILE__, __LINE__, __FUNCTION__);
488 win = DefaultRootWindow(_ecore_x_disp);
490 ret = XGetWindowProperty(_ecore_x_disp, win, property, 0, LONG_MAX,
491 False, type, &type_ret, &size_ret,
492 &num_ret, &bytes, &prop_ret);
503 if (!(*data = malloc(num_ret * size_ret / 8)))
511 for (i = 0; i < num_ret; i++)
512 (*data)[i] = prop_ret[i];
516 for (i = 0; i < num_ret; i++)
517 ((unsigned short *)*data)[i] = ((unsigned short *)prop_ret)[i];
521 for (i = 0; i < num_ret; i++)
522 ((unsigned int *)*data)[i] = ((unsigned long *)prop_ret)[i];
532 } /* ecore_x_window_prop_property_get */
535 ecore_x_window_prop_property_del(Ecore_X_Window win, Ecore_X_Atom property)
537 LOGFN(__FILE__, __LINE__, __FUNCTION__);
538 XDeleteProperty(_ecore_x_disp, win, property);
539 } /* ecore_x_window_prop_property_del */
542 ecore_x_window_prop_list(Ecore_X_Window win, int *num_ret)
548 LOGFN(__FILE__, __LINE__, __FUNCTION__);
552 atom_ret = XListProperties(_ecore_x_disp, win, &num);
556 atoms = malloc(num * sizeof(Ecore_X_Atom));
559 for (i = 0; i < num; i++) atoms[i] = atom_ret[i];
566 } /* ecore_x_window_prop_list */
569 * Set a window string property.
570 * @param win The window
571 * @param type The property
572 * @param str The string
574 * Set a window string property
577 ecore_x_window_prop_string_set(Ecore_X_Window win,
583 LOGFN(__FILE__, __LINE__, __FUNCTION__);
585 win = DefaultRootWindow(_ecore_x_disp);
587 xtp.value = (unsigned char *)str;
589 xtp.encoding = ECORE_X_ATOM_UTF8_STRING;
590 xtp.nitems = strlen(str);
591 XSetTextProperty(_ecore_x_disp, win, &xtp, type);
592 } /* ecore_x_window_prop_string_set */
595 * Get a window string property.
596 * @param win The window
597 * @param type The property
599 * Return window string property of a window. String must be free'd when done.
602 ecore_x_window_prop_string_get(Ecore_X_Window win, Ecore_X_Atom type)
607 LOGFN(__FILE__, __LINE__, __FUNCTION__);
609 win = DefaultRootWindow(_ecore_x_disp);
611 if (XGetTextProperty(_ecore_x_disp, win, &xtp, type))
617 if (xtp.encoding == ECORE_X_ATOM_UTF8_STRING)
618 str = strdup((char *)xtp.value);
621 #ifdef X_HAVE_UTF8_STRING
622 s = Xutf8TextPropertyToTextList(_ecore_x_disp, &xtp,
624 #else /* ifdef X_HAVE_UTF8_STRING */
625 s = XmbTextPropertyToTextList(_ecore_x_disp, &xtp,
627 #endif /* ifdef X_HAVE_UTF8_STRING */
628 if ((s == XLocaleNotSupported) ||
629 (s == XNoMemory) || (s == XConverterNotFound))
630 str = strdup((char *)xtp.value);
631 else if ((s >= Success) && (items > 0))
632 str = strdup(list[0]);
635 XFreeStringList(list);
642 } /* ecore_x_window_prop_string_get */
645 ecore_x_window_prop_protocol_isset(Ecore_X_Window win,
646 Ecore_X_WM_Protocol protocol)
648 Atom proto, *protos = NULL;
649 int i, ret = 0, protos_count = 0;
651 /* check for invalid values */
652 if (protocol >= ECORE_X_WM_PROTOCOL_NUM)
655 LOGFN(__FILE__, __LINE__, __FUNCTION__);
656 proto = _ecore_x_atoms_wm_protocols[protocol];
658 if (!XGetWMProtocols(_ecore_x_disp, win, &protos, &protos_count))
661 for (i = 0; i < protos_count; i++)
662 if (protos[i] == proto)
671 } /* ecore_x_window_prop_protocol_isset */
676 * FIXME: To be fixed.
678 EAPI Ecore_X_WM_Protocol *
679 ecore_x_window_prop_protocol_list_get(Ecore_X_Window win, int *num_ret)
682 int i, protos_count = 0;
683 Ecore_X_WM_Protocol *prot_ret = NULL;
685 LOGFN(__FILE__, __LINE__, __FUNCTION__);
686 if (!XGetWMProtocols(_ecore_x_disp, win, &protos, &protos_count))
689 if ((!protos) || (protos_count <= 0))
692 prot_ret = calloc(1, protos_count * sizeof(Ecore_X_WM_Protocol));
699 for (i = 0; i < protos_count; i++)
701 Ecore_X_WM_Protocol j;
704 for (j = 0; j < ECORE_X_WM_PROTOCOL_NUM; j++)
706 if (_ecore_x_atoms_wm_protocols[j] == protos[i])
711 *num_ret = protos_count;
713 } /* ecore_x_window_prop_protocol_list_get */