2 * vim:ts=8:sw=3:sts=8:noexpandtab:cino=>5n-3f0^-2{2
5 #include "ecore_x_private.h"
7 #include "Ecore_X_Atoms.h"
11 #define _ATOM_SET_CARD32(win, atom, p_val, cnt) \
12 XChangeProperty(_ecore_x_disp, win, atom, XA_CARDINAL, 32, PropModeReplace, \
13 (unsigned char *)p_val, cnt)
16 * Set CARD32 (array) property
19 ecore_x_window_prop_card32_set(Ecore_X_Window win, Ecore_X_Atom atom,
20 unsigned int *val, unsigned int num)
22 #if SIZEOF_INT == SIZEOF_LONG
23 _ATOM_SET_CARD32(win, atom, val, num);
28 v2 = malloc(num * sizeof(long));
31 for (i = 0; i < num; i++)
33 _ATOM_SET_CARD32(win, atom, v2, num);
39 * Get CARD32 (array) property
41 * At most len items are returned in val.
42 * If the property was successfully fetched the number of items stored in
43 * val is returned, otherwise -1 is returned.
44 * Note: Return value 0 means that the property exists but has no elements.
47 ecore_x_window_prop_card32_get(Ecore_X_Window win, Ecore_X_Atom atom,
48 unsigned int *val, unsigned int len)
50 unsigned char *prop_ret;
52 unsigned long bytes_after, num_ret;
58 XGetWindowProperty(_ecore_x_disp, win, atom, 0, 0x7fffffff, False,
59 XA_CARDINAL, &type_ret, &format_ret, &num_ret,
60 &bytes_after, &prop_ret);
61 if (prop_ret && type_ret == XA_CARDINAL && format_ret == 32)
66 for (i = 0; i < len; i++)
67 val[i] = ((unsigned long*)prop_ret)[i];
82 * Get CARD32 (array) property of any length
84 * If the property was successfully fetched the number of items stored in
85 * val is returned, otherwise -1 is returned.
86 * Note: Return value 0 means that the property exists but has no elements.
89 ecore_x_window_prop_card32_list_get(Ecore_X_Window win, Ecore_X_Atom atom,
92 unsigned char *prop_ret;
94 unsigned long bytes_after, num_ret;
100 if (XGetWindowProperty(_ecore_x_disp, win, atom, 0, 0x7fffffff, False,
101 XA_CARDINAL, &type_ret, &format_ret, &num_ret,
102 &bytes_after, &prop_ret) != Success)
105 if (type_ret == None || num_ret == 0)
110 else if (prop_ret && type_ret == XA_CARDINAL && format_ret == 32)
112 val = malloc(num_ret * sizeof(unsigned int));
113 for (i = 0; i < num_ret; i++)
114 val[i] = ((unsigned long *)prop_ret)[i];
130 * Set X ID (array) property
133 ecore_x_window_prop_xid_set(Ecore_X_Window win, Ecore_X_Atom atom,
134 Ecore_X_Atom type, Ecore_X_ID * lst,
137 #if SIZEOF_INT == SIZEOF_LONG
138 XChangeProperty(_ecore_x_disp, win, atom, type, 32, PropModeReplace,
139 (unsigned char *)lst, num);
144 pl = malloc(num * sizeof(long));
147 for (i = 0; i < num; i++)
149 XChangeProperty(_ecore_x_disp, win, atom, type, 32, PropModeReplace,
150 (unsigned char *)pl, num);
156 * Get X ID (array) property
158 * At most len items are returned in val.
159 * If the property was successfully fetched the number of items stored in
160 * val is returned, otherwise -1 is returned.
161 * Note: Return value 0 means that the property exists but has no elements.
164 ecore_x_window_prop_xid_get(Ecore_X_Window win, Ecore_X_Atom atom,
165 Ecore_X_Atom type, Ecore_X_ID * lst,
168 unsigned char *prop_ret;
170 unsigned long bytes_after, num_ret;
176 if (XGetWindowProperty(_ecore_x_disp, win, atom, 0, 0x7fffffff, False,
177 type, &type_ret, &format_ret, &num_ret,
178 &bytes_after, &prop_ret) != Success)
181 if (type_ret == None)
185 else if (prop_ret && type_ret == type && format_ret == 32)
189 for (i = 0; i < len; i++)
190 lst[i] = ((unsigned long *)prop_ret)[i];
204 * Get X ID (array) property
206 * If the property was successfully fetched the number of items stored in
207 * val is returned, otherwise -1 is returned.
208 * The returned array must be freed with free().
209 * Note: Return value 0 means that the property exists but has no elements.
212 ecore_x_window_prop_xid_list_get(Ecore_X_Window win, Ecore_X_Atom atom,
213 Ecore_X_Atom type, Ecore_X_ID ** val)
215 unsigned char *prop_ret;
217 unsigned long bytes_after, num_ret;
225 if (XGetWindowProperty(_ecore_x_disp, win, atom, 0, 0x7fffffff, False,
226 type, &type_ret, &format_ret, &num_ret,
227 &bytes_after, &prop_ret) != Success)
230 if (type_ret == None || num_ret == 0)
234 else if (prop_ret && type_ret == type && format_ret == 32)
236 alst = malloc(num_ret * sizeof(Ecore_X_ID));
237 for (i = 0; i < num_ret; i++)
238 alst[i] = ((unsigned long *)prop_ret)[i];
253 * Remove/add/toggle X ID list item.
256 ecore_x_window_prop_xid_list_change(Ecore_X_Window win, Ecore_X_Atom atom,
257 Ecore_X_Atom type, Ecore_X_ID item, int op)
262 num = ecore_x_window_prop_xid_list_get(win, atom, type, &lst);
264 return; /* Error - assuming invalid window */
267 for (i = 0; i < num; i++)
276 if (op == ECORE_X_PROP_LIST_ADD)
285 /* Was not in list */
286 if (op == ECORE_X_PROP_LIST_REMOVE)
290 lst = realloc(lst, num * sizeof(Ecore_X_ID));
294 ecore_x_window_prop_xid_set(win, atom, type, lst, num);
302 * Set Atom (array) property
305 ecore_x_window_prop_atom_set(Ecore_X_Window win, Ecore_X_Atom atom,
306 Ecore_X_Atom * lst, unsigned int num)
308 ecore_x_window_prop_xid_set(win, atom, XA_ATOM, lst, num);
312 * Get Atom (array) property
314 * At most len items are returned in val.
315 * If the property was successfully fetched the number of items stored in
316 * val is returned, otherwise -1 is returned.
317 * Note: Return value 0 means that the property exists but has no elements.
320 ecore_x_window_prop_atom_get(Ecore_X_Window win, Ecore_X_Atom atom,
321 Ecore_X_Atom * lst, unsigned int len)
323 return ecore_x_window_prop_xid_get(win, atom, XA_ATOM, lst, len);
327 * Get Atom (array) property
329 * If the property was successfully fetched the number of items stored in
330 * val is returned, otherwise -1 is returned.
331 * The returned array must be freed with free().
332 * Note: Return value 0 means that the property exists but has no elements.
335 ecore_x_window_prop_atom_list_get(Ecore_X_Window win, Ecore_X_Atom atom,
336 Ecore_X_Atom ** plst)
338 return ecore_x_window_prop_xid_list_get(win, atom, XA_ATOM, plst);
342 * Remove/add/toggle atom list item.
345 ecore_x_window_prop_atom_list_change(Ecore_X_Window win, Ecore_X_Atom atom,
346 Ecore_X_Atom item, int op)
348 ecore_x_window_prop_xid_list_change(win, atom, XA_ATOM, item, op);
352 * Set Window (array) property
355 ecore_x_window_prop_window_set(Ecore_X_Window win, Ecore_X_Atom atom,
356 Ecore_X_Window * lst, unsigned int num)
358 ecore_x_window_prop_xid_set(win, atom, XA_WINDOW, lst, num);
362 * Get Window (array) property
364 * At most len items are returned in val.
365 * If the property was successfully fetched the number of items stored in
366 * val is returned, otherwise -1 is returned.
367 * Note: Return value 0 means that the property exists but has no elements.
370 ecore_x_window_prop_window_get(Ecore_X_Window win, Ecore_X_Atom atom,
371 Ecore_X_Window * lst, unsigned int len)
373 return ecore_x_window_prop_xid_get(win, atom, XA_WINDOW, lst, len);
377 * Get Window (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_window_list_get(Ecore_X_Window win, Ecore_X_Atom atom,
386 Ecore_X_Window ** plst)
388 return ecore_x_window_prop_xid_list_get(win, atom, XA_WINDOW, plst);
394 * FIXME: To be fixed.
397 ecore_x_window_prop_any_type(void)
399 return AnyPropertyType;
405 * FIXME: To be fixed.
408 ecore_x_window_prop_property_set(Ecore_X_Window win, Ecore_X_Atom property, Ecore_X_Atom type, int size, void *data, int number)
410 if (win == 0) win = DefaultRootWindow(_ecore_x_disp);
412 XChangeProperty(_ecore_x_disp, win, property, type, size, PropModeReplace,
413 (unsigned char *)data, number);
419 dat = malloc(sizeof(unsigned long) * number);
422 for (ptr = (int *)data, i = 0; i < number; i++) dat[i] = ptr[i];
423 XChangeProperty(_ecore_x_disp, win, property, type, size,
424 PropModeReplace, (unsigned char *)dat, number);
433 * FIXME: To be fixed.
436 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)
439 int ret, size_ret = 0;
440 unsigned long num_ret = 0, bytes = 0, i;
441 unsigned char *prop_ret = NULL;
443 /* make sure these are initialized */
448 else /* we can't store the retrieved data, so just return */
451 if (!win) win = DefaultRootWindow(_ecore_x_disp);
453 ret = XGetWindowProperty(_ecore_x_disp, win, property, 0, LONG_MAX,
454 False, type, &type_ret, &size_ret,
455 &num_ret, &bytes, &prop_ret);
465 if (!(*data = malloc(num_ret * size_ret / 8))) {
472 for (i = 0; i < num_ret; i++)
473 (*data)[i] = prop_ret[i];
476 for (i = 0; i < num_ret; i++)
477 ((unsigned short *) *data)[i] = ((unsigned short *) prop_ret)[i];
480 for (i = 0; i < num_ret; i++)
481 ((unsigned int *) *data)[i] = ((unsigned long *) prop_ret)[i];
487 if (num) *num = num_ret;
492 ecore_x_window_prop_property_del(Ecore_X_Window win, Ecore_X_Atom property)
494 XDeleteProperty(_ecore_x_disp, win, property);
498 ecore_x_window_prop_list(Ecore_X_Window win, int *num_ret)
504 if (num_ret) *num_ret = 0;
506 atom_ret = XListProperties(_ecore_x_disp, win, &num);
507 if (!atom_ret) return NULL;
509 atoms = malloc(num * sizeof(Ecore_X_Atom));
512 for (i = 0; i < num; i++) atoms[i] = atom_ret[i];
513 if (num_ret) *num_ret = num;
520 * Set a window string property.
521 * @param win The window
522 * @param type The property
523 * @param str The string
525 * Set a window string property
528 ecore_x_window_prop_string_set(Ecore_X_Window win, Ecore_X_Atom type, const char *str)
532 if (win == 0) win = DefaultRootWindow(_ecore_x_disp);
533 xtp.value = (unsigned char *)str;
535 xtp.encoding = ECORE_X_ATOM_UTF8_STRING;
536 xtp.nitems = strlen(str);
537 XSetTextProperty(_ecore_x_disp, win, &xtp, type);
541 * Get a window string property.
542 * @param win The window
543 * @param type The property
545 * Return window string property of a window. String must be free'd when done.
548 ecore_x_window_prop_string_get(Ecore_X_Window win, Ecore_X_Atom type)
553 if (win == 0) win = DefaultRootWindow(_ecore_x_disp);
554 if (XGetTextProperty(_ecore_x_disp, win, &xtp, type))
560 if (xtp.encoding == ECORE_X_ATOM_UTF8_STRING)
562 str = strdup((char *)xtp.value);
566 #ifdef X_HAVE_UTF8_STRING
567 s = Xutf8TextPropertyToTextList(_ecore_x_disp, &xtp,
570 s = XmbTextPropertyToTextList(_ecore_x_disp, &xtp,
573 if ((s == XLocaleNotSupported) ||
574 (s == XNoMemory) || (s == XConverterNotFound))
576 str = strdup((char *)xtp.value);
578 else if ((s >= Success) && (items > 0))
580 str = strdup(list[0]);
583 XFreeStringList(list);
591 ecore_x_window_prop_protocol_isset(Ecore_X_Window win,
592 Ecore_X_WM_Protocol protocol)
594 Atom proto, *protos = NULL;
595 int i, ret = 0, protos_count = 0;
597 /* check for invalid values */
598 if (protocol >= ECORE_X_WM_PROTOCOL_NUM)
601 proto = _ecore_x_atoms_wm_protocols[protocol];
603 if (!XGetWMProtocols(_ecore_x_disp, win, &protos, &protos_count))
606 for (i = 0; i < protos_count; i++)
607 if (protos[i] == proto)
621 * FIXME: To be fixed.
623 EAPI Ecore_X_WM_Protocol *
624 ecore_x_window_prop_protocol_list_get(Ecore_X_Window win, int *num_ret)
627 int i, protos_count = 0;
628 Ecore_X_WM_Protocol *prot_ret = NULL;
630 if (!XGetWMProtocols(_ecore_x_disp, win, &protos, &protos_count))
633 if ((!protos) || (protos_count <= 0)) return NULL;
634 prot_ret = calloc(1, protos_count * sizeof(Ecore_X_WM_Protocol));
640 for (i = 0; i < protos_count; i++)
642 Ecore_X_WM_Protocol j;
645 for (j = 0; j < ECORE_X_WM_PROTOCOL_NUM; j++)
647 if (_ecore_x_atoms_wm_protocols[j] == protos[i])
652 *num_ret = protos_count;