aboutsummaryrefslogtreecommitdiffstatshomepage
path: root/libraries/ecore/src/lib/ecore_x/xlib/ecore_x_window_prop.c
diff options
context:
space:
mode:
Diffstat (limited to 'libraries/ecore/src/lib/ecore_x/xlib/ecore_x_window_prop.c')
-rw-r--r--libraries/ecore/src/lib/ecore_x/xlib/ecore_x_window_prop.c752
1 files changed, 0 insertions, 752 deletions
diff --git a/libraries/ecore/src/lib/ecore_x/xlib/ecore_x_window_prop.c b/libraries/ecore/src/lib/ecore_x/xlib/ecore_x_window_prop.c
deleted file mode 100644
index b581a0e..0000000
--- a/libraries/ecore/src/lib/ecore_x/xlib/ecore_x_window_prop.c
+++ /dev/null
@@ -1,752 +0,0 @@
1#ifdef HAVE_CONFIG_H
2# include <config.h>
3#endif /* ifdef HAVE_CONFIG_H */
4
5#include <stdlib.h>
6#include <string.h>
7
8#include "Ecore.h"
9#include "ecore_x_private.h"
10#include "Ecore_X.h"
11#include "Ecore_X_Atoms.h"
12#include <inttypes.h>
13#include <limits.h>
14
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)
18
19/*
20 * Set CARD32 (array) property
21 */
22EAPI void
23ecore_x_window_prop_card32_set(Ecore_X_Window win,
24 Ecore_X_Atom atom,
25 unsigned int *val,
26 unsigned int num)
27{
28#if SIZEOF_INT == SIZEOF_LONG
29 _ATOM_SET_CARD32(win, atom, val, num);
30#else /* if SIZEOF_INT == SIZEOF_LONG */
31 long *v2;
32 unsigned int i;
33
34 LOGFN(__FILE__, __LINE__, __FUNCTION__);
35 v2 = malloc(num * sizeof(long));
36 if (!v2)
37 return;
38
39 for (i = 0; i < num; i++)
40 v2[i] = val[i];
41 _ATOM_SET_CARD32(win, atom, v2, num);
42 free(v2);
43#endif /* if SIZEOF_INT == SIZEOF_LONG */
44}
45
46/*
47 * Get CARD32 (array) property
48 *
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.
53 */
54EAPI int
55ecore_x_window_prop_card32_get(Ecore_X_Window win,
56 Ecore_X_Atom atom,
57 unsigned int *val,
58 unsigned int len)
59{
60 unsigned char *prop_ret;
61 Atom type_ret;
62 unsigned long bytes_after, num_ret;
63 int format_ret;
64 unsigned int i;
65 int num;
66
67 LOGFN(__FILE__, __LINE__, __FUNCTION__);
68 prop_ret = NULL;
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)
72 return -1;
73
74 if (type_ret != XA_CARDINAL || format_ret != 32)
75 num = -1;
76 else if (num_ret == 0 || !prop_ret)
77 num = 0;
78 else
79 {
80 if (num_ret < len)
81 len = num_ret;
82
83 for (i = 0; i < len; i++)
84 val[i] = ((unsigned long *)prop_ret)[i];
85 num = len;
86 }
87
88 if (prop_ret)
89 XFree(prop_ret);
90
91 return num;
92}
93
94/*
95 * Get CARD32 (array) property of any length
96 *
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.
100 */
101EAPI int
102ecore_x_window_prop_card32_list_get(Ecore_X_Window win,
103 Ecore_X_Atom atom,
104 unsigned int **plst)
105{
106 unsigned char *prop_ret;
107 Atom type_ret;
108 unsigned long bytes_after, num_ret;
109 int format_ret;
110 unsigned int i, *val;
111 int num;
112
113 LOGFN(__FILE__, __LINE__, __FUNCTION__);
114 *plst = NULL;
115 prop_ret = NULL;
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)
119 return -1;
120
121 if ((type_ret != XA_CARDINAL) || (format_ret != 32))
122 num = -1;
123 else if ((num_ret == 0) || (!prop_ret))
124 num = 0;
125 else
126 {
127 val = malloc(num_ret * sizeof(unsigned int));
128 if (!val)
129 {
130 if (prop_ret) XFree(prop_ret);
131 return -1;
132 }
133 for (i = 0; i < num_ret; i++)
134 val[i] = ((unsigned long *)prop_ret)[i];
135 num = num_ret;
136 *plst = val;
137 }
138
139 if (prop_ret)
140 XFree(prop_ret);
141
142 return num;
143}
144
145/*
146 * Set X ID (array) property
147 */
148EAPI void
149ecore_x_window_prop_xid_set(Ecore_X_Window win,
150 Ecore_X_Atom atom,
151 Ecore_X_Atom type,
152 Ecore_X_ID *lst,
153 unsigned int num)
154{
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 */
159 unsigned long *pl;
160 unsigned int i;
161
162 LOGFN(__FILE__, __LINE__, __FUNCTION__);
163 pl = malloc(num * sizeof(long));
164 if (!pl)
165 return;
166
167 for (i = 0; i < num; i++)
168 pl[i] = lst[i];
169 XChangeProperty(_ecore_x_disp, win, atom, type, 32, PropModeReplace,
170 (unsigned char *)pl, num);
171 free(pl);
172#endif /* if SIZEOF_INT == SIZEOF_LONG */
173}
174
175/*
176 * Get X ID (array) property
177 *
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.
182 */
183EAPI int
184ecore_x_window_prop_xid_get(Ecore_X_Window win,
185 Ecore_X_Atom atom,
186 Ecore_X_Atom type,
187 Ecore_X_ID *lst,
188 unsigned int len)
189{
190 unsigned char *prop_ret;
191 Atom type_ret;
192 unsigned long bytes_after, num_ret;
193 int format_ret;
194 int num;
195 unsigned i;
196
197 LOGFN(__FILE__, __LINE__, __FUNCTION__);
198 prop_ret = NULL;
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)
202 return -1;
203
204 if (type_ret != type || format_ret != 32)
205 num = -1;
206 else if (num_ret == 0 || !prop_ret)
207 num = 0;
208 else
209 {
210 if (num_ret < len)
211 len = num_ret;
212
213 for (i = 0; i < len; i++)
214 lst[i] = ((unsigned long *)prop_ret)[i];
215 num = len;
216 }
217
218 if (prop_ret)
219 XFree(prop_ret);
220
221 return num;
222}
223
224/*
225 * Get X ID (array) property
226 *
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.
231 */
232EAPI int
233ecore_x_window_prop_xid_list_get(Ecore_X_Window win,
234 Ecore_X_Atom atom,
235 Ecore_X_Atom type,
236 Ecore_X_ID **val)
237{
238 unsigned char *prop_ret;
239 Atom type_ret;
240 unsigned long bytes_after, num_ret;
241 int format_ret;
242 Ecore_X_Atom *alst;
243 int num;
244 unsigned i;
245
246 LOGFN(__FILE__, __LINE__, __FUNCTION__);
247 *val = NULL;
248 prop_ret = NULL;
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)
252 return -1;
253
254 if (type_ret != type || format_ret != 32)
255 num = -1;
256 else if (num_ret == 0 || !prop_ret)
257 num = 0;
258 else
259 {
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];
263 num = num_ret;
264 *val = alst;
265 }
266
267 if (prop_ret)
268 XFree(prop_ret);
269
270 return num;
271}
272
273/*
274 * Remove/add/toggle X ID list item.
275 */
276EAPI void
277ecore_x_window_prop_xid_list_change(Ecore_X_Window win,
278 Ecore_X_Atom atom,
279 Ecore_X_Atom type,
280 Ecore_X_ID item,
281 int op)
282{
283 Ecore_X_ID *lst;
284 int i, num;
285
286 LOGFN(__FILE__, __LINE__, __FUNCTION__);
287 num = ecore_x_window_prop_xid_list_get(win, atom, type, &lst);
288 if (num < 0)
289 {
290 return; /* Error - assuming invalid window */
291 }
292
293 /* Is it there? */
294 for (i = 0; i < num; i++)
295 {
296 if (lst[i] == item)
297 break;
298 }
299
300 if (i < num)
301 {
302 /* Was in list */
303 if (op == ECORE_X_PROP_LIST_ADD)
304 goto done; /* Remove it */
305
306 num--;
307 for (; i < num; i++)
308 lst[i] = lst[i + 1];
309 }
310 else
311 {
312 /* Was not in list */
313 if (op == ECORE_X_PROP_LIST_REMOVE)
314 goto done; /* Add it */
315
316 num++;
317 lst = realloc(lst, num * sizeof(Ecore_X_ID));
318 lst[i] = item;
319 }
320
321 ecore_x_window_prop_xid_set(win, atom, type, lst, num);
322
323done:
324 if (lst)
325 free(lst);
326}
327
328/*
329 * Set Atom (array) property
330 */
331EAPI void
332ecore_x_window_prop_atom_set(Ecore_X_Window win,
333 Ecore_X_Atom atom,
334 Ecore_X_Atom *lst,
335 unsigned int num)
336{
337 LOGFN(__FILE__, __LINE__, __FUNCTION__);
338 ecore_x_window_prop_xid_set(win, atom, XA_ATOM, lst, num);
339}
340
341/*
342 * Get Atom (array) property
343 *
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.
348 */
349EAPI int
350ecore_x_window_prop_atom_get(Ecore_X_Window win,
351 Ecore_X_Atom atom,
352 Ecore_X_Atom *lst,
353 unsigned int len)
354{
355 LOGFN(__FILE__, __LINE__, __FUNCTION__);
356 return ecore_x_window_prop_xid_get(win, atom, XA_ATOM, lst, len);
357}
358
359/*
360 * Get Atom (array) property
361 *
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.
366 */
367EAPI int
368ecore_x_window_prop_atom_list_get(Ecore_X_Window win,
369 Ecore_X_Atom atom,
370 Ecore_X_Atom **plst)
371{
372 LOGFN(__FILE__, __LINE__, __FUNCTION__);
373 return ecore_x_window_prop_xid_list_get(win, atom, XA_ATOM, plst);
374}
375
376/*
377 * Remove/add/toggle atom list item.
378 */
379EAPI void
380ecore_x_window_prop_atom_list_change(Ecore_X_Window win,
381 Ecore_X_Atom atom,
382 Ecore_X_Atom item,
383 int op)
384{
385 LOGFN(__FILE__, __LINE__, __FUNCTION__);
386 ecore_x_window_prop_xid_list_change(win, atom, XA_ATOM, item, op);
387}
388
389/*
390 * Set Window (array) property
391 */
392EAPI void
393ecore_x_window_prop_window_set(Ecore_X_Window win,
394 Ecore_X_Atom atom,
395 Ecore_X_Window *lst,
396 unsigned int num)
397{
398 LOGFN(__FILE__, __LINE__, __FUNCTION__);
399 ecore_x_window_prop_xid_set(win, atom, XA_WINDOW, lst, num);
400}
401
402/*
403 * Get Window (array) property
404 *
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.
409 */
410EAPI int
411ecore_x_window_prop_window_get(Ecore_X_Window win,
412 Ecore_X_Atom atom,
413 Ecore_X_Window *lst,
414 unsigned int len)
415{
416 LOGFN(__FILE__, __LINE__, __FUNCTION__);
417 return ecore_x_window_prop_xid_get(win, atom, XA_WINDOW, lst, len);
418}
419
420/*
421 * Get Window (array) property
422 *
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.
427 */
428EAPI int
429ecore_x_window_prop_window_list_get(Ecore_X_Window win,
430 Ecore_X_Atom atom,
431 Ecore_X_Window **plst)
432{
433 LOGFN(__FILE__, __LINE__, __FUNCTION__);
434 return ecore_x_window_prop_xid_list_get(win, atom, XA_WINDOW, plst);
435}
436
437/**
438 * To be documented.
439 *
440 * FIXME: To be fixed.
441 */
442EAPI Ecore_X_Atom
443ecore_x_window_prop_any_type(void)
444{
445 return AnyPropertyType;
446}
447
448/**
449 * To be documented.
450 *
451 * FIXME: To be fixed.
452 */
453EAPI void
454ecore_x_window_prop_property_set(Ecore_X_Window win,
455 Ecore_X_Atom property,
456 Ecore_X_Atom type,
457 int size,
458 void *data,
459 int number)
460{
461 LOGFN(__FILE__, __LINE__, __FUNCTION__);
462 if (win == 0)
463 win = DefaultRootWindow(_ecore_x_disp);
464
465 if (size != 32)
466 XChangeProperty(_ecore_x_disp,
467 win,
468 property,
469 type,
470 size,
471 PropModeReplace,
472 (unsigned char *)data,
473 number);
474 else
475 {
476 unsigned long *dat;
477 int i, *ptr;
478
479 dat = malloc(sizeof(unsigned long) * number);
480 if (dat)
481 {
482 for (ptr = (int *)data, i = 0; i < number; i++)
483 dat[i] = ptr[i];
484 XChangeProperty(_ecore_x_disp, win, property, type, size,
485 PropModeReplace, (unsigned char *)dat, number);
486 free(dat);
487 }
488 }
489}
490
491/**
492 * To be documented.
493 *
494 * FIXME: To be fixed.
495 */
496EAPI int
497ecore_x_window_prop_property_get(Ecore_X_Window win,
498 Ecore_X_Atom property,
499 Ecore_X_Atom type,
500 int size __UNUSED__,
501 unsigned char **data,
502 int *num)
503{
504 Atom type_ret = 0;
505 int ret, size_ret = 0;
506 unsigned long num_ret = 0, bytes = 0, i;
507 unsigned char *prop_ret = NULL;
508
509 /* make sure these are initialized */
510 if (num)
511 *num = 0;
512
513 if (data)
514 *data = NULL;
515 else /* we can't store the retrieved data, so just return */
516 return 0;
517
518 LOGFN(__FILE__, __LINE__, __FUNCTION__);
519 if (!win)
520 win = DefaultRootWindow(_ecore_x_disp);
521
522 ret = XGetWindowProperty(_ecore_x_disp, win, property, 0, LONG_MAX,
523 False, type, &type_ret, &size_ret,
524 &num_ret, &bytes, &prop_ret);
525
526 if (ret != Success)
527 return 0;
528
529 if (!num_ret)
530 {
531 XFree(prop_ret);
532 return 0;
533 }
534
535 if (!(*data = malloc(num_ret * size_ret / 8)))
536 {
537 XFree(prop_ret);
538 return 0;
539 }
540
541 switch (size_ret) {
542 case 8:
543 for (i = 0; i < num_ret; i++)
544 (*data)[i] = prop_ret[i];
545 break;
546
547 case 16:
548 for (i = 0; i < num_ret; i++)
549 ((unsigned short *)*data)[i] = ((unsigned short *)prop_ret)[i];
550 break;
551
552 case 32:
553 for (i = 0; i < num_ret; i++)
554 ((unsigned int *)*data)[i] = ((unsigned long *)prop_ret)[i];
555 break;
556 }
557
558 XFree(prop_ret);
559
560 if (num)
561 *num = num_ret;
562
563 return size_ret;
564}
565
566EAPI void
567ecore_x_window_prop_property_del(Ecore_X_Window win,
568 Ecore_X_Atom property)
569{
570 LOGFN(__FILE__, __LINE__, __FUNCTION__);
571 XDeleteProperty(_ecore_x_disp, win, property);
572}
573
574EAPI Ecore_X_Atom *
575ecore_x_window_prop_list(Ecore_X_Window win,
576 int *num_ret)
577{
578 Ecore_X_Atom *atoms;
579 Atom *atom_ret;
580 int num = 0, i;
581
582 LOGFN(__FILE__, __LINE__, __FUNCTION__);
583 if (num_ret)
584 *num_ret = 0;
585
586 atom_ret = XListProperties(_ecore_x_disp, win, &num);
587 if (!atom_ret)
588 return NULL;
589
590 atoms = malloc(num * sizeof(Ecore_X_Atom));
591 if (atoms)
592 {
593 for (i = 0; i < num; i++)
594 atoms[i] = atom_ret[i];
595 if (num_ret)
596 *num_ret = num;
597 }
598
599 XFree(atom_ret);
600 return atoms;
601}
602
603/**
604 * Set a window string property.
605 * @param win The window
606 * @param type The property
607 * @param str The string
608 *
609 * Set a window string property
610 */
611EAPI void
612ecore_x_window_prop_string_set(Ecore_X_Window win,
613 Ecore_X_Atom type,
614 const char *str)
615{
616 XTextProperty xtp;
617
618 LOGFN(__FILE__, __LINE__, __FUNCTION__);
619 if (win == 0)
620 win = DefaultRootWindow(_ecore_x_disp);
621
622 xtp.value = (unsigned char *)str;
623 xtp.format = 8;
624 xtp.encoding = ECORE_X_ATOM_UTF8_STRING;
625 xtp.nitems = strlen(str);
626 XSetTextProperty(_ecore_x_disp, win, &xtp, type);
627}
628
629/**
630 * Get a window string property.
631 * @param win The window
632 * @param type The property
633 *
634 * Return window string property of a window. String must be free'd when done.
635 */
636EAPI char *
637ecore_x_window_prop_string_get(Ecore_X_Window win,
638 Ecore_X_Atom type)
639{
640 XTextProperty xtp;
641 char *str = NULL;
642
643 LOGFN(__FILE__, __LINE__, __FUNCTION__);
644 if (win == 0)
645 win = DefaultRootWindow(_ecore_x_disp);
646
647 if (XGetTextProperty(_ecore_x_disp, win, &xtp, type))
648 {
649 int items;
650 char **list = NULL;
651 Status s;
652
653 if (xtp.encoding == ECORE_X_ATOM_UTF8_STRING)
654 str = strdup((char *)xtp.value);
655 else
656 {
657#ifdef X_HAVE_UTF8_STRING
658 s = Xutf8TextPropertyToTextList(_ecore_x_disp, &xtp,
659 &list, &items);
660#else /* ifdef X_HAVE_UTF8_STRING */
661 s = XmbTextPropertyToTextList(_ecore_x_disp, &xtp,
662 &list, &items);
663#endif /* ifdef X_HAVE_UTF8_STRING */
664 if ((s == XLocaleNotSupported) ||
665 (s == XNoMemory) || (s == XConverterNotFound))
666 str = strdup((char *)xtp.value);
667 else if ((s >= Success) && (items > 0))
668 str = strdup(list[0]);
669
670 if (list)
671 XFreeStringList(list);
672 }
673
674 XFree(xtp.value);
675 }
676
677 return str;
678}
679
680EAPI Eina_Bool
681ecore_x_window_prop_protocol_isset(Ecore_X_Window win,
682 Ecore_X_WM_Protocol protocol)
683{
684 Atom proto, *protos = NULL;
685 int i, protos_count = 0;
686 Eina_Bool ret = EINA_FALSE;
687
688 /* check for invalid values */
689 if (protocol >= ECORE_X_WM_PROTOCOL_NUM)
690 return EINA_FALSE;
691
692 LOGFN(__FILE__, __LINE__, __FUNCTION__);
693 proto = _ecore_x_atoms_wm_protocols[protocol];
694
695 if (!XGetWMProtocols(_ecore_x_disp, win, &protos, &protos_count))
696 return ret;
697
698 for (i = 0; i < protos_count; i++)
699 if (protos[i] == proto)
700 {
701 ret = EINA_TRUE;
702 break;
703 }
704
705 XFree(protos);
706
707 return ret;
708}
709
710/**
711 * To be documented.
712 *
713 * FIXME: To be fixed.
714 */
715EAPI Ecore_X_WM_Protocol *
716ecore_x_window_prop_protocol_list_get(Ecore_X_Window win,
717 int *num_ret)
718{
719 Atom *protos = NULL;
720 int i, protos_count = 0;
721 Ecore_X_WM_Protocol *prot_ret = NULL;
722
723 LOGFN(__FILE__, __LINE__, __FUNCTION__);
724 if (!XGetWMProtocols(_ecore_x_disp, win, &protos, &protos_count))
725 return NULL;
726
727 if ((!protos) || (protos_count <= 0))
728 return NULL;
729
730 prot_ret = calloc(1, protos_count * sizeof(Ecore_X_WM_Protocol));
731 if (!prot_ret)
732 {
733 XFree(protos);
734 return NULL;
735 }
736
737 for (i = 0; i < protos_count; i++)
738 {
739 Ecore_X_WM_Protocol j;
740
741 prot_ret[i] = -1;
742 for (j = 0; j < ECORE_X_WM_PROTOCOL_NUM; j++)
743 {
744 if (_ecore_x_atoms_wm_protocols[j] == protos[i])
745 prot_ret[i] = j;
746 }
747 }
748 XFree(protos);
749 *num_ret = protos_count;
750 return prot_ret;
751}
752