diff options
Diffstat (limited to '')
-rw-r--r-- | libraries/ecore/src/lib/ecore_x/xlib/ecore_x_window_prop.c | 750 |
1 files changed, 750 insertions, 0 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 new file mode 100644 index 0000000..8d5c757 --- /dev/null +++ b/libraries/ecore/src/lib/ecore_x/xlib/ecore_x_window_prop.c | |||
@@ -0,0 +1,750 @@ | |||
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 | */ | ||
22 | EAPI void | ||
23 | ecore_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 | } /* ecore_x_window_prop_card32_set */ | ||
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 | */ | ||
54 | EAPI int | ||
55 | ecore_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 | } /* ecore_x_window_prop_card32_get */ | ||
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 | */ | ||
101 | EAPI int | ||
102 | ecore_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 | } /* ecore_x_window_prop_card32_list_get */ | ||
144 | |||
145 | /* | ||
146 | * Set X ID (array) property | ||
147 | */ | ||
148 | EAPI void | ||
149 | ecore_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 | } /* ecore_x_window_prop_xid_set */ | ||
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 | */ | ||
183 | EAPI int | ||
184 | ecore_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 | } /* ecore_x_window_prop_xid_get */ | ||
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 | */ | ||
232 | EAPI int | ||
233 | ecore_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 | } /* ecore_x_window_prop_xid_list_get */ | ||
272 | |||
273 | /* | ||
274 | * Remove/add/toggle X ID list item. | ||
275 | */ | ||
276 | EAPI void | ||
277 | ecore_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 | |||
323 | done: | ||
324 | if (lst) | ||
325 | free(lst); | ||
326 | } /* ecore_x_window_prop_xid_list_change */ | ||
327 | |||
328 | /* | ||
329 | * Set Atom (array) property | ||
330 | */ | ||
331 | EAPI void | ||
332 | ecore_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 | } /* ecore_x_window_prop_atom_set */ | ||
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 | */ | ||
349 | EAPI int | ||
350 | ecore_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 | } /* ecore_x_window_prop_atom_get */ | ||
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 | */ | ||
367 | EAPI int | ||
368 | ecore_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 | } /* ecore_x_window_prop_atom_list_get */ | ||
375 | |||
376 | /* | ||
377 | * Remove/add/toggle atom list item. | ||
378 | */ | ||
379 | EAPI void | ||
380 | ecore_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 | } /* ecore_x_window_prop_atom_list_change */ | ||
388 | |||
389 | /* | ||
390 | * Set Window (array) property | ||
391 | */ | ||
392 | EAPI void | ||
393 | ecore_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 | } /* ecore_x_window_prop_window_set */ | ||
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 | */ | ||
410 | EAPI int | ||
411 | ecore_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 | } /* ecore_x_window_prop_window_get */ | ||
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 | */ | ||
428 | EAPI int | ||
429 | ecore_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 | } /* ecore_x_window_prop_window_list_get */ | ||
436 | |||
437 | /** | ||
438 | * To be documented. | ||
439 | * | ||
440 | * FIXME: To be fixed. | ||
441 | */ | ||
442 | EAPI Ecore_X_Atom | ||
443 | ecore_x_window_prop_any_type(void) | ||
444 | { | ||
445 | return AnyPropertyType; | ||
446 | } /* ecore_x_window_prop_any_type */ | ||
447 | |||
448 | /** | ||
449 | * To be documented. | ||
450 | * | ||
451 | * FIXME: To be fixed. | ||
452 | */ | ||
453 | EAPI void | ||
454 | ecore_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++) dat[i] = ptr[i]; | ||
483 | XChangeProperty(_ecore_x_disp, win, property, type, size, | ||
484 | PropModeReplace, (unsigned char *)dat, number); | ||
485 | free(dat); | ||
486 | } | ||
487 | } | ||
488 | } /* ecore_x_window_prop_property_set */ | ||
489 | |||
490 | /** | ||
491 | * To be documented. | ||
492 | * | ||
493 | * FIXME: To be fixed. | ||
494 | */ | ||
495 | EAPI int | ||
496 | ecore_x_window_prop_property_get(Ecore_X_Window win, | ||
497 | Ecore_X_Atom property, | ||
498 | Ecore_X_Atom type, | ||
499 | int size __UNUSED__, | ||
500 | unsigned char **data, | ||
501 | int *num) | ||
502 | { | ||
503 | Atom type_ret = 0; | ||
504 | int ret, size_ret = 0; | ||
505 | unsigned long num_ret = 0, bytes = 0, i; | ||
506 | unsigned char *prop_ret = NULL; | ||
507 | |||
508 | /* make sure these are initialized */ | ||
509 | if (num) | ||
510 | *num = 0; | ||
511 | |||
512 | if (data) | ||
513 | *data = NULL; | ||
514 | else /* we can't store the retrieved data, so just return */ | ||
515 | return 0; | ||
516 | |||
517 | LOGFN(__FILE__, __LINE__, __FUNCTION__); | ||
518 | if (!win) | ||
519 | win = DefaultRootWindow(_ecore_x_disp); | ||
520 | |||
521 | ret = XGetWindowProperty(_ecore_x_disp, win, property, 0, LONG_MAX, | ||
522 | False, type, &type_ret, &size_ret, | ||
523 | &num_ret, &bytes, &prop_ret); | ||
524 | |||
525 | if (ret != Success) | ||
526 | return 0; | ||
527 | |||
528 | if (!num_ret) | ||
529 | { | ||
530 | XFree(prop_ret); | ||
531 | return 0; | ||
532 | } | ||
533 | |||
534 | if (!(*data = malloc(num_ret * size_ret / 8))) | ||
535 | { | ||
536 | XFree(prop_ret); | ||
537 | return 0; | ||
538 | } | ||
539 | |||
540 | switch (size_ret) { | ||
541 | case 8: | ||
542 | for (i = 0; i < num_ret; i++) | ||
543 | (*data)[i] = prop_ret[i]; | ||
544 | break; | ||
545 | |||
546 | case 16: | ||
547 | for (i = 0; i < num_ret; i++) | ||
548 | ((unsigned short *)*data)[i] = ((unsigned short *)prop_ret)[i]; | ||
549 | break; | ||
550 | |||
551 | case 32: | ||
552 | for (i = 0; i < num_ret; i++) | ||
553 | ((unsigned int *)*data)[i] = ((unsigned long *)prop_ret)[i]; | ||
554 | break; | ||
555 | } /* switch */ | ||
556 | |||
557 | XFree(prop_ret); | ||
558 | |||
559 | if (num) | ||
560 | *num = num_ret; | ||
561 | |||
562 | return size_ret; | ||
563 | } /* ecore_x_window_prop_property_get */ | ||
564 | |||
565 | EAPI void | ||
566 | ecore_x_window_prop_property_del(Ecore_X_Window win, | ||
567 | Ecore_X_Atom property) | ||
568 | { | ||
569 | LOGFN(__FILE__, __LINE__, __FUNCTION__); | ||
570 | XDeleteProperty(_ecore_x_disp, win, property); | ||
571 | } /* ecore_x_window_prop_property_del */ | ||
572 | |||
573 | EAPI Ecore_X_Atom * | ||
574 | ecore_x_window_prop_list(Ecore_X_Window win, | ||
575 | int *num_ret) | ||
576 | { | ||
577 | Ecore_X_Atom *atoms; | ||
578 | Atom *atom_ret; | ||
579 | int num = 0, i; | ||
580 | |||
581 | LOGFN(__FILE__, __LINE__, __FUNCTION__); | ||
582 | if (num_ret) | ||
583 | *num_ret = 0; | ||
584 | |||
585 | atom_ret = XListProperties(_ecore_x_disp, win, &num); | ||
586 | if (!atom_ret) | ||
587 | return NULL; | ||
588 | |||
589 | atoms = malloc(num * sizeof(Ecore_X_Atom)); | ||
590 | if (atoms) | ||
591 | { | ||
592 | for (i = 0; i < num; i++) atoms[i] = atom_ret[i]; | ||
593 | if (num_ret) | ||
594 | *num_ret = num; | ||
595 | } | ||
596 | |||
597 | XFree(atom_ret); | ||
598 | return atoms; | ||
599 | } /* ecore_x_window_prop_list */ | ||
600 | |||
601 | /** | ||
602 | * Set a window string property. | ||
603 | * @param win The window | ||
604 | * @param type The property | ||
605 | * @param str The string | ||
606 | * | ||
607 | * Set a window string property | ||
608 | */ | ||
609 | EAPI void | ||
610 | ecore_x_window_prop_string_set(Ecore_X_Window win, | ||
611 | Ecore_X_Atom type, | ||
612 | const char *str) | ||
613 | { | ||
614 | XTextProperty xtp; | ||
615 | |||
616 | LOGFN(__FILE__, __LINE__, __FUNCTION__); | ||
617 | if (win == 0) | ||
618 | win = DefaultRootWindow(_ecore_x_disp); | ||
619 | |||
620 | xtp.value = (unsigned char *)str; | ||
621 | xtp.format = 8; | ||
622 | xtp.encoding = ECORE_X_ATOM_UTF8_STRING; | ||
623 | xtp.nitems = strlen(str); | ||
624 | XSetTextProperty(_ecore_x_disp, win, &xtp, type); | ||
625 | } /* ecore_x_window_prop_string_set */ | ||
626 | |||
627 | /** | ||
628 | * Get a window string property. | ||
629 | * @param win The window | ||
630 | * @param type The property | ||
631 | * | ||
632 | * Return window string property of a window. String must be free'd when done. | ||
633 | */ | ||
634 | EAPI char * | ||
635 | ecore_x_window_prop_string_get(Ecore_X_Window win, | ||
636 | Ecore_X_Atom type) | ||
637 | { | ||
638 | XTextProperty xtp; | ||
639 | char *str = NULL; | ||
640 | |||
641 | LOGFN(__FILE__, __LINE__, __FUNCTION__); | ||
642 | if (win == 0) | ||
643 | win = DefaultRootWindow(_ecore_x_disp); | ||
644 | |||
645 | if (XGetTextProperty(_ecore_x_disp, win, &xtp, type)) | ||
646 | { | ||
647 | int items; | ||
648 | char **list = NULL; | ||
649 | Status s; | ||
650 | |||
651 | if (xtp.encoding == ECORE_X_ATOM_UTF8_STRING) | ||
652 | str = strdup((char *)xtp.value); | ||
653 | else | ||
654 | { | ||
655 | #ifdef X_HAVE_UTF8_STRING | ||
656 | s = Xutf8TextPropertyToTextList(_ecore_x_disp, &xtp, | ||
657 | &list, &items); | ||
658 | #else /* ifdef X_HAVE_UTF8_STRING */ | ||
659 | s = XmbTextPropertyToTextList(_ecore_x_disp, &xtp, | ||
660 | &list, &items); | ||
661 | #endif /* ifdef X_HAVE_UTF8_STRING */ | ||
662 | if ((s == XLocaleNotSupported) || | ||
663 | (s == XNoMemory) || (s == XConverterNotFound)) | ||
664 | str = strdup((char *)xtp.value); | ||
665 | else if ((s >= Success) && (items > 0)) | ||
666 | str = strdup(list[0]); | ||
667 | |||
668 | if (list) | ||
669 | XFreeStringList(list); | ||
670 | } | ||
671 | |||
672 | XFree(xtp.value); | ||
673 | } | ||
674 | |||
675 | return str; | ||
676 | } /* ecore_x_window_prop_string_get */ | ||
677 | |||
678 | EAPI Eina_Bool | ||
679 | ecore_x_window_prop_protocol_isset(Ecore_X_Window win, | ||
680 | Ecore_X_WM_Protocol protocol) | ||
681 | { | ||
682 | Atom proto, *protos = NULL; | ||
683 | int i, protos_count = 0; | ||
684 | Eina_Bool ret = EINA_FALSE; | ||
685 | |||
686 | /* check for invalid values */ | ||
687 | if (protocol >= ECORE_X_WM_PROTOCOL_NUM) | ||
688 | return EINA_FALSE; | ||
689 | |||
690 | LOGFN(__FILE__, __LINE__, __FUNCTION__); | ||
691 | proto = _ecore_x_atoms_wm_protocols[protocol]; | ||
692 | |||
693 | if (!XGetWMProtocols(_ecore_x_disp, win, &protos, &protos_count)) | ||
694 | return ret; | ||
695 | |||
696 | for (i = 0; i < protos_count; i++) | ||
697 | if (protos[i] == proto) | ||
698 | { | ||
699 | ret = EINA_TRUE; | ||
700 | break; | ||
701 | } | ||
702 | |||
703 | XFree(protos); | ||
704 | |||
705 | return ret; | ||
706 | } /* ecore_x_window_prop_protocol_isset */ | ||
707 | |||
708 | /** | ||
709 | * To be documented. | ||
710 | * | ||
711 | * FIXME: To be fixed. | ||
712 | */ | ||
713 | EAPI Ecore_X_WM_Protocol * | ||
714 | ecore_x_window_prop_protocol_list_get(Ecore_X_Window win, | ||
715 | int *num_ret) | ||
716 | { | ||
717 | Atom *protos = NULL; | ||
718 | int i, protos_count = 0; | ||
719 | Ecore_X_WM_Protocol *prot_ret = NULL; | ||
720 | |||
721 | LOGFN(__FILE__, __LINE__, __FUNCTION__); | ||
722 | if (!XGetWMProtocols(_ecore_x_disp, win, &protos, &protos_count)) | ||
723 | return NULL; | ||
724 | |||
725 | if ((!protos) || (protos_count <= 0)) | ||
726 | return NULL; | ||
727 | |||
728 | prot_ret = calloc(1, protos_count * sizeof(Ecore_X_WM_Protocol)); | ||
729 | if (!prot_ret) | ||
730 | { | ||
731 | XFree(protos); | ||
732 | return NULL; | ||
733 | } | ||
734 | |||
735 | for (i = 0; i < protos_count; i++) | ||
736 | { | ||
737 | Ecore_X_WM_Protocol j; | ||
738 | |||
739 | prot_ret[i] = -1; | ||
740 | for (j = 0; j < ECORE_X_WM_PROTOCOL_NUM; j++) | ||
741 | { | ||
742 | if (_ecore_x_atoms_wm_protocols[j] == protos[i]) | ||
743 | prot_ret[i] = j; | ||
744 | } | ||
745 | } | ||
746 | XFree(protos); | ||
747 | *num_ret = protos_count; | ||
748 | return prot_ret; | ||
749 | } /* ecore_x_window_prop_protocol_list_get */ | ||
750 | |||