upload tizen1.0 source
[profile/ivi/libslp-utilx.git] / x11.c
1 /*
2  * libslp-utilx
3  *
4    Copyright (c) 2011 Samsung Electronics Co., Ltd All Rights Reserved
5
6    Licensed under the Apache License, Version 2.0 (the "License");
7    you may not use this file except in compliance with the License.
8    You may obtain a copy of the License at
9
10        http://www.apache.org/licenses/LICENSE-2.0
11
12    Unless required by applicable law or agreed to in writing, software
13    distributed under the License is distributed on an "AS IS" BASIS,
14    WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
15    See the License for the specific language governing permissions and
16    limitations under the License.
17  *
18  */
19
20 #include <stdio.h>
21 #include <stdlib.h>
22 #include <string.h>
23 #include <errno.h>
24
25 #include <X11/Xlib.h>
26 #include <X11/Xatom.h>
27
28 #include "utilX.h"
29 #include "util_x11.h"
30
31
32 #define UTILX_DEBUG 0
33 #if UTILX_DEBUG
34 #define UTILX_TRACE  printf
35 #else
36 #define UTILX_TRACE(...)
37 #endif
38
39 static Atom _atom_grab_key = None;
40 static Atom _atom_grab_excl_win = None;
41 static Atom _atom_grab_or_excl_win = None;
42
43 static Atom _atom_notification_level = None;
44 static Atom _atom_indicator_visible_state = None;
45 static Atom _atom_indicator_visible_state_on = None;
46 static Atom _atom_indicator_visible_state_off = None;
47
48 static Atom _atom_comp_effect_state = None;
49 static Atom _atom_comp_fake_launch = None;
50 static Atom _atom_comp_fake_launch_image = None;
51
52 static Atom _atom_comp_window_effect_type = None;
53 static Atom _atom_comp_effect_default = None;
54 static Atom _atom_comp_effect_none = None;
55 static Atom _atom_comp_effect_custom0 = None;
56 static Atom _atom_comp_effect_custom1 = None;
57 static Atom _atom_comp_effect_custom2 = None;
58 static Atom _atom_comp_effect_custom3 = None;
59 static Atom _atom_comp_effect_custom4 = None;
60 static Atom _atom_comp_effect_custom5 = None;
61 static Atom _atom_comp_effect_custom6 = None;
62 static Atom _atom_comp_effect_custom7 = None;
63 static Atom _atom_comp_effect_custom8 = None;
64 static Atom _atom_comp_effect_custom9 = None;
65
66 static Atom _atom_window_opaque = None;
67
68 static Atom _atom_screen_capture_disable = None;
69
70 static Atom _atom_comp_capture_effect = None;
71
72 const unsigned long maxlen = 1024l;
73
74 static void _utilx_set_window_property (Display* dpy, Window win, Atom atom, Atom type, unsigned int *val, unsigned int num);
75 static int _utilx_get_window_property (Display* dpy, Window win, Atom atom, Atom type, unsigned int *val, unsigned int len);
76
77 static void _utilx_effect_atom_check( Display* dpy );
78 static Atom _utilx_convert_style_to_atom( Display* dpy, Utilx_Effect_Style style );
79 static Utilx_Effect_Style _utilx_convert_atom_to_style( Display* dpy, Atom style );
80
81 static int _utilx_get_indicator_atoms(Display *dpy);
82
83 API void utilx_set_system_notification_level (Display* dpy, Window win, Utilx_Notification_Level level)
84 {
85         UTILX_TRACE ("[UTILX] utilx_set_system_notification_level... win = %x, level = %d\n", win, level);
86
87         int noti_level;
88
89         if (dpy == NULL)
90         {
91                 fprintf (stderr, "[UTILX] Error.. Invald Display.. %s (%d)\n", __func__, __LINE__);
92                 return;
93         }
94
95         switch (level)
96         {
97                 case UTILX_NOTIFICATION_LEVEL_LOW:
98                         noti_level = 50;
99                         break;
100
101                 case UTILX_NOTIFICATION_LEVEL_NORMAL:
102                         noti_level = 100;
103                         break;
104
105                 case UTILX_NOTIFICATION_LEVEL_HIGH:
106                         noti_level = 150;
107                         break;
108
109                 default:
110                         noti_level = 50;
111                         break;
112         }
113
114         if (!_atom_notification_level)
115         {
116                 _atom_notification_level = XInternAtom (dpy, "_E_ILLUME_NOTIFICATION_LEVEL", False);
117                 if (!_atom_notification_level)
118                 {
119                         fprintf (stderr, "[UTILX] Error.. Cannot create _E_ILLUME_NOTIFICATION_LEVEL atom.. %s (%d)\n", __func__, __LINE__);
120                         return;
121                 }
122         }
123
124         _utilx_set_window_property (dpy, win, _atom_notification_level, XA_CARDINAL,
125                         (unsigned int *)&noti_level, 1);
126 }
127
128
129 API Utilx_Notification_Level utilx_get_system_notification_level (Display* dpy, Window win)
130 {
131         UTILX_TRACE ("[UTILX] utilx_get_system_notification_level... win = %x\n", win);
132
133         Utilx_Notification_Level noti_level;
134         unsigned int level;
135         int ret;
136
137         noti_level = UTILX_NOTIFICATION_LEVEL_LOW;
138
139         if (dpy == NULL)
140         {
141                 fprintf (stderr, "[UTILX] Error.. Invald Display.. %s (%d)\n", __func__, __LINE__);
142                 goto error;
143         }
144
145         if (!_atom_notification_level)
146         {
147                 _atom_notification_level = XInternAtom (dpy, "_E_ILLUME_NOTIFICATION_LEVEL", False);
148                 if (!_atom_notification_level)
149                 {
150                         fprintf (stderr, "[UTILX] Error.. Cannot create _E_ILLUME_NOTIFICATION_LEVEL atom.. %s (%d)\n", __func__, __LINE__);
151                         goto error;
152                 }
153         }
154
155         ret = _utilx_get_window_property (dpy, win, _atom_notification_level, XA_CARDINAL,
156                         (unsigned int *)&level, 1);
157
158         if (ret > 0)
159         {
160                 switch (level)
161                 {
162                         case 50:
163                                 noti_level = UTILX_NOTIFICATION_LEVEL_LOW;
164                                 break;
165
166                         case 100:
167                                 noti_level = UTILX_NOTIFICATION_LEVEL_NORMAL;
168                                 break;
169
170                         case 150:
171                                 noti_level = UTILX_NOTIFICATION_LEVEL_HIGH;
172                                 break;
173
174                         default:
175                                 noti_level = UTILX_NOTIFICATION_LEVEL_LOW;
176                                 break;
177                 }
178         }
179         else
180         {
181                 noti_level = UTILX_NOTIFICATION_LEVEL_LOW;
182         }
183
184 error:
185         return noti_level;
186 }
187
188 static int _utilx_get_indicator_atoms(Display *dpy)
189 {
190         if (!_atom_indicator_visible_state)
191         {
192                 _atom_indicator_visible_state = XInternAtom (dpy, "_E_ILLUME_INDICATOR_STATE", False);
193                 if (!_atom_indicator_visible_state)
194                 {
195                         fprintf (stderr, "[UTILX] Error.. Cannot create _E_ILLUME_INDICATOR_STATE atom.. %s (%d)\n", __func__, __LINE__);
196                         return 0;
197                 }
198         }
199
200         if (!_atom_indicator_visible_state_on)
201         {
202                 _atom_indicator_visible_state_on = XInternAtom (dpy, "_E_ILLUME_INDICATOR_ON", False);
203                 if (!_atom_indicator_visible_state_on)
204                 {
205                         fprintf (stderr, "[UTILX] Error.. Cannot create _E_ILLUME_INDICATOR_ON atom.. %s (%d)\n", __func__, __LINE__);
206                         return 0;
207                 }
208         }
209
210         if (!_atom_indicator_visible_state_off)
211         {
212                 _atom_indicator_visible_state_off = XInternAtom (dpy, "_E_ILLUME_INDICATOR_OFF", False);
213                 if (!_atom_indicator_visible_state_off)
214                 {
215                         fprintf (stderr, "[UTILX] Error.. Cannot create _E_ILLUME_INDICATOR_OFF atom.. %s (%d)\n", __func__, __LINE__);
216                         return 0;
217                 }
218         }
219
220         return 1;
221 }
222
223 API void utilx_enable_indicator (Display* dpy, Window win, int enable)
224 {
225         UTILX_TRACE ("[UTILX] utilx_indicator_set_visible_state... win = %x, show_state = %d\n", win, enable);
226
227         if (dpy == NULL)
228         {
229                 fprintf (stderr, "[UTILX] Error.. Invald Display.. %s (%d)\n", __func__, __LINE__);
230                 return;
231         }
232
233         if (!_utilx_get_indicator_atoms(dpy))
234         {
235                 fprintf (stderr, "[UTILX] Error.. Cannot create atoms.. %s (%d)\n", __func__, __LINE__);
236                 return;
237         }
238
239         if (enable == 1)
240         {
241                 _utilx_set_window_property (dpy, win, _atom_indicator_visible_state, XA_ATOM,
242                         (unsigned int *)&_atom_indicator_visible_state_on, 1);
243         }
244         else
245         {
246                 _utilx_set_window_property (dpy, win, _atom_indicator_visible_state, XA_ATOM,
247                         (unsigned int *)&_atom_indicator_visible_state_off, 1);
248         }
249 }
250
251
252 API int utilx_get_indicator_state (Display* dpy, Window win)
253 {
254         UTILX_TRACE ("[UTILX] utilx_indicator_set_visible_state... win = %x, show_state = %d\n", win, enable);
255
256         int ret;
257         Atom state;
258
259         if (dpy == NULL)
260         {
261                 fprintf (stderr, "[UTILX] Error.. Invald Display.. %s (%d)\n", __func__, __LINE__);
262                 return -1;
263         }
264
265         if (!_utilx_get_indicator_atoms(dpy))
266         {
267                 fprintf (stderr, "[UTILX] Error.. Cannot create atoms.. %s (%d)\n", __func__, __LINE__);
268                 return;
269         }
270
271         ret = _utilx_get_window_property (dpy, win, _atom_indicator_visible_state, XA_ATOM,
272                         (unsigned int *)&state, 1);
273
274         if (ret > 0)
275         {
276                 if (state == _atom_indicator_visible_state_on)
277                         return 1;
278                 else if (state == _atom_indicator_visible_state_off)
279                         return 0;
280                 else
281                         return -1;
282         }
283         else
284                 return -1;
285 }
286
287 static void
288 _utilx_set_window_property (Display* dpy, Window win, Atom atom, Atom type, unsigned int *val, unsigned int num)
289 {
290         XChangeProperty (dpy, win, atom, type, 32, PropModeReplace, (unsigned char *)val, num);
291         XSync(dpy, 0 );
292 }
293
294
295 static int
296 _utilx_get_window_property (Display* dpy, Window win, Atom atom, Atom type, unsigned int *val, unsigned int len)
297 {
298         unsigned char* prop_ret;
299         Atom type_ret;
300         unsigned long bytes_after, num_ret;
301         int format_ret;
302         unsigned int i;
303         int num;
304
305         prop_ret = NULL;
306         if (XGetWindowProperty(dpy, win, atom, 0, 0x7fffffff, False,
307                                 type, &type_ret, &format_ret, &num_ret,
308                                 &bytes_after, &prop_ret) != Success)
309         {
310                 return -1;
311         }
312
313         if (type_ret != type || format_ret != 32)
314         {
315                 num = -1;
316         }
317         else if (num_ret == 0 || !prop_ret)
318         {
319                 num = 0;
320         }
321         else
322         {
323                 if (num_ret < len)
324                 len = num_ret;
325                 for (i = 0; i < len; i++)
326                 {
327                         val[i] = ((unsigned long *)prop_ret)[i];
328                 }
329                 num = len;
330         }
331
332         if (prop_ret)
333                 XFree(prop_ret);
334
335         return num;
336
337 }
338
339
340 static unsigned long _get_list_of_grabbed_key (Display *disp, Window win, int **key_list)
341 {
342         Atom ret_type;
343         int ret_format;
344         unsigned long nr_item;
345         unsigned long sz_remains_data;
346
347         if (XGetWindowProperty(disp, win,
348                 _atom_grab_key, 0, 0x7fffffff, False, XA_CARDINAL,
349                 &ret_type, &ret_format, &nr_item,
350                 &sz_remains_data, (unsigned char**)key_list) != Success)
351         {
352                 nr_item = 0;
353         }
354
355 //      fprintf(stderr, "\e[31m%d - %lu\e[0m\n", ret_format, nr_item);
356
357         return nr_item;
358 }
359
360
361 static void _free_list_of_grabbed_key (int *key_list)
362 {
363         if (key_list) {
364                 XFree(key_list);
365         }
366 }
367
368
369 static void _free_new_list_of_grabbed_key (int *new_key_list)
370 {
371         if (new_key_list) {
372                 free(new_key_list);
373         }
374 }
375
376
377 static int _search_grabbed_key (int *key_list, int key, unsigned long cnt)
378 {
379         register int i;
380
381         for (i = cnt - 1; i >= 0; i --) {
382                 if (key_list[i] == key) break;
383         }
384
385         return i;
386 }
387
388
389 static int *_del_grabbed_key (int *key_list, int i, unsigned long *cnt)
390 {
391         int *new_key_list = NULL;
392
393         // Only one element is exists in the list of grabbed key
394         (*cnt) --;
395
396         if (*cnt == 0) return NULL;
397
398         // Shrink the buffer
399         new_key_list = malloc((*cnt) * sizeof(int));
400         if (new_key_list == NULL) {
401                 perror(__func__);
402                 return NULL;
403         }
404
405         // copy head
406         if (i > 0) {
407                 memcpy(new_key_list, key_list, sizeof(int) * i);
408         }
409
410         // copy tail
411         if ((*cnt) - i > 0) {
412                 memcpy(new_key_list + i,
413                         key_list + i + 1,
414                         sizeof(int) * ((*cnt) - i)
415                 );
416         }
417         return new_key_list;
418 }
419
420
421 static void _set_exclusive_grab_info_to_root (Display *disp, int keycode, Window win, int grab_mode)
422 {
423         int i;
424         int *key_list = NULL;
425
426         Atom ret_type;
427         int ret_format;
428         unsigned long nr_item;
429         unsigned long sz_remains_data;
430         Window ex_grabwin;
431
432         if( grab_mode == EXCLUSIVE_GRAB )
433         {
434                 if( _atom_grab_excl_win == None )
435                         _atom_grab_excl_win = XInternAtom(disp, STR_ATOM_GRAB_EXCL_WIN, False);
436                 ex_grabwin = _atom_grab_excl_win;
437         }
438         else if( grab_mode == OR_EXCLUSIVE_GRAB )
439         {
440                 if( _atom_grab_or_excl_win == None )
441                         _atom_grab_or_excl_win = XInternAtom(disp, STR_ATOM_GRAB_OR_EXCL_WIN, False);
442                 ex_grabwin = _atom_grab_or_excl_win;
443         }
444         else
445                 return;
446
447         if (XGetWindowProperty(disp, DefaultRootWindow(disp),
448                 ex_grabwin, 0, 0x7fffffff, False, XA_CARDINAL,
449                 &ret_type, &ret_format, &nr_item,
450                 &sz_remains_data, (unsigned char**)&key_list) != Success)
451         {
452                 fprintf(stderr, "[utilX][%s] Fail to get root window property !\n", __FUNCTION__);
453                 goto out;
454         }
455
456 #ifdef __DEBUG__
457         printf("[%s] keycode = %d\n", __FUNCTION__, keycode);
458 #endif
459
460         for( i=0 ; i < nr_item ; i++ )
461         {
462                 if( key_list && (key_list[i] == keycode) )
463                         return;
464         }
465
466         XChangeProperty(disp, DefaultRootWindow(disp), ex_grabwin, XA_CARDINAL, 32,
467         nr_item ? PropModeAppend : PropModeReplace, (unsigned char *)&keycode, 1);
468         XSync(disp, False);
469
470 out:
471         return;
472 }
473
474
475 static void _unset_exclusive_grab_info_to_root (Display *disp, int keycode, int grab_mode)
476 {
477         int i;
478         unsigned long cnt = 0;
479         int *key_list = NULL;
480         int *new_key_list = NULL;
481
482         Atom ret_type;
483         int ret_format;
484         unsigned long nr_item;
485         unsigned long sz_remains_data;
486         Window ex_grabwin;
487
488         if( grab_mode == EXCLUSIVE_GRAB )
489         {
490                 if( _atom_grab_excl_win == None )
491                         _atom_grab_excl_win = XInternAtom(disp, STR_ATOM_GRAB_EXCL_WIN, False);
492                 ex_grabwin = _atom_grab_excl_win;
493         }
494         else if( grab_mode == OR_EXCLUSIVE_GRAB )
495         {
496                 if( _atom_grab_or_excl_win == None )
497                         _atom_grab_or_excl_win = XInternAtom(disp, STR_ATOM_GRAB_OR_EXCL_WIN, False);
498                 ex_grabwin = _atom_grab_or_excl_win;
499         }
500         else
501                 return;
502
503         if (XGetWindowProperty(disp, DefaultRootWindow(disp),
504                 ex_grabwin, 0, 0x7fffffff, False, XA_CARDINAL,
505                 &ret_type, &ret_format, &nr_item,
506                 &sz_remains_data, (unsigned char**)&key_list) != Success)
507         {
508                 nr_item = 0;
509         }
510
511         if (nr_item == 0)
512         {
513                 fprintf(stderr, "\e[32m[utilX][%s] keycode = %d\e[0m\n", __FUNCTION__, keycode);
514                 goto out;
515         }
516
517         for( i=0 ; i < nr_item ; i++ )
518         {
519                 if( key_list[i] == keycode )//&& grab_mode == EXCLUSIVE_GRAB )
520                 {
521                         continue;
522                 }
523                 cnt++;
524         }
525
526 #ifdef __DEBUG__
527         fprintf(stderr, "[utilX][%s] cnt = %d, nr_item = %d\n", __FUNCTION__, cnt, nr_item);
528 #endif
529
530         if( 0 < cnt )
531         {
532                 new_key_list = malloc(sizeof(int)*cnt);
533                 cnt = 0;
534         }
535         else
536                 new_key_list = NULL;
537
538         if( !new_key_list )
539         {
540                 //fprintf(stderr, "\e[32m[utilX][%s] Fail to allocation memory for new_key_list ! \e[0m\n", __FUNCTION__);
541                 XDeleteProperty(disp, DefaultRootWindow(disp), ex_grabwin);
542                 XSync(disp, False);
543                 goto out;
544         }
545
546         for( i=0 ; i < nr_item ; i++ )
547         {
548                 if( key_list[i] == keycode )//&& grab_mode == EXCLUSIVE_GRAB )
549                 {
550                         continue;
551                 }
552                 else
553                         new_key_list[cnt++] = key_list[i];
554         }
555
556         if (new_key_list) {
557                 XChangeProperty(disp, DefaultRootWindow(disp), ex_grabwin, XA_CARDINAL, 32,
558                         PropModeReplace, (unsigned char *)new_key_list, cnt);
559         }
560         else {
561                 XDeleteProperty(disp, DefaultRootWindow(disp), ex_grabwin);
562         }
563         XSync(disp, False);
564
565         if(new_key_list)
566                 free(new_key_list);
567
568 out:
569         return;
570 }
571
572
573 static int _is_grabbed_key_exclusively (Display* disp, int keycode, int grab_mode)
574 {
575         int i, result = 0;
576         int *key_list = NULL;
577
578         Atom ret_type;
579         int ret_format;
580         unsigned long nr_item;
581         unsigned long sz_remains_data;
582         Window ex_grabwin;
583
584         if( grab_mode == EXCLUSIVE_GRAB )
585         {
586                 if( _atom_grab_excl_win == None )
587                         _atom_grab_excl_win = XInternAtom(disp, STR_ATOM_GRAB_EXCL_WIN, False);
588                 ex_grabwin = _atom_grab_excl_win;
589         }
590         else if( grab_mode == OR_EXCLUSIVE_GRAB )
591         {
592                 if( _atom_grab_or_excl_win == None )
593                         _atom_grab_or_excl_win = XInternAtom(disp, STR_ATOM_GRAB_OR_EXCL_WIN, False);
594                 ex_grabwin = _atom_grab_or_excl_win;
595         }
596         else
597                 return result;
598
599         if (XGetWindowProperty(disp, DefaultRootWindow(disp),
600                 ex_grabwin, 0, 0x7fffffff, False, XA_CARDINAL,
601                 &ret_type, &ret_format, &nr_item,
602                 &sz_remains_data, (unsigned char**)&key_list) != Success)
603         {
604                 fprintf(stderr, "[%s] Fail to get root window property !\n", __FUNCTION__);
605                 goto out;
606         }
607
608         for( i=0 ; i < nr_item ; i++ )
609         {
610                 if( key_list[i] == keycode )
611                         return EXCLUSIVE_GRABBED_ALREADY;
612         }
613
614 out:
615         return result;
616 }
617
618 API int utilx_grab_key (Display* disp, Window win, const char* key, int grab_mode)
619 {
620         unsigned long cnt;
621         int *key_list = NULL;
622         int i, result = 0;
623         int keycode = 0;
624         KeySym keysym;
625         errno = EINVAL;
626
627         if( NULL == disp )
628         {
629                 fprintf(stderr, "[%s] Display is NULL\n", __FUNCTION__);
630                 return -1;
631         }
632
633         if (_atom_grab_key == None) {
634                 _atom_grab_key = XInternAtom(disp, STR_ATOM_GRAB_KEY, False);
635         }
636
637         if (!strncmp(key, "Keycode-", 8)) {
638                 keycode = atoi(key + 8);
639         } else {
640                 keysym = XStringToKeysym(key);
641                 if (keysym == NoSymbol) goto out;
642                 keycode = XKeysymToKeycode(disp, XStringToKeysym(key));
643         }
644         if (keycode == 0) goto out;
645
646         if( grab_mode == EXCLUSIVE_GRAB )
647         {
648                 //Window grabWin;
649                 result = _is_grabbed_key_exclusively(disp, keycode, grab_mode);
650
651 #ifdef __DEBUG__
652                 printf("[%s] _is_grabbed_key_exclusively returns result = %d\n", __FUNCTION__, result);
653 #endif
654
655                 if( result )
656                 {
657                         fprintf(stderr, "[%s] keycode(%d) was already grabbed exclusively (grab_mode=0x%X) !\n", __FUNCTION__, keycode, grab_mode);
658                         goto out;
659                 }
660         }
661         else if( grab_mode == OR_EXCLUSIVE_GRAB )
662         {
663                 result = _is_grabbed_key_exclusively(disp, keycode, grab_mode);
664
665                 if( result )
666                 {
667                         fprintf(stderr, "[%s] Keycode(%d) was already grabbed with overridable exclusive mode (grab_mode=0x%x)\n", __FUNCTION__, keycode, grab_mode);
668                         fprintf(stderr, "[%s] Now it will be overridden by a new window(0x%x) !\n", __FUNCTION__, win);
669                         utilx_ungrab_key(disp, win, key);
670                 }
671         }
672
673         keycode |= grab_mode;
674
675         cnt = _get_list_of_grabbed_key(disp, win, &key_list);
676         if (cnt > 0) {
677                 i = _search_grabbed_key(key_list, keycode, cnt);
678                 _free_list_of_grabbed_key(key_list);
679                 if ( i != -1 ) {
680                         if( grab_mode == OR_EXCLUSIVE_GRAB )
681                         {
682                                 utilx_ungrab_key(disp, win, key);
683                         }
684                         else
685                         {
686                         fprintf(stderr, "Key is already grabbed\n");
687                         goto out;
688                         }
689                 }
690         }
691
692         XChangeProperty(disp, win, _atom_grab_key, XA_CARDINAL, 32,
693                         cnt ? PropModeAppend : PropModeReplace, (unsigned char *)&keycode, 1);
694         XSync(disp, False);
695         keycode = keycode & (~GRAB_MODE_MASK);
696 #ifdef __DEBUG__
697         printf("[%s] keycode = %d\n", __FUNCTION__, keycode);
698 #endif
699
700         if( EXCLUSIVE_GRAB == grab_mode || OR_EXCLUSIVE_GRAB == grab_mode )
701                 _set_exclusive_grab_info_to_root(disp, keycode, win, grab_mode);
702
703         errno = 0;
704
705 out:
706
707         return result;
708 }
709
710
711 API int utilx_ungrab_key (Display* disp, Window win, const char* key)
712 {
713         int i;
714         unsigned long cnt;
715         int *key_list = NULL;
716         int *new_key_list = NULL;
717         long keycode = 0;
718         KeySym keysym;
719         int ret = -1;
720         errno = EINVAL;
721
722         if( NULL == disp )
723         {
724                 fprintf(stderr, "[%s] Display is NULL\n", __FUNCTION__);
725                 return -1;
726         }
727
728         if (_atom_grab_key == None) {
729                 _atom_grab_key = XInternAtom(disp, STR_ATOM_GRAB_KEY, False);
730         }
731
732         if (!strncmp(key, "Keycode-", 8)) {
733                 keycode = atoi(key + 8);
734         } else {
735                 keysym = XStringToKeysym(key);
736                 if (keysym == NoSymbol) goto out;
737                 keycode = XKeysymToKeycode(disp, XStringToKeysym(key));
738         }
739         if (keycode == 0) goto out;
740
741         cnt = _get_list_of_grabbed_key(disp, win, &key_list);
742         if (cnt == 0) goto out;
743
744         //EXCLUSIVE mode
745         i = _search_grabbed_key(key_list, keycode | EXCLUSIVE_GRAB, cnt);
746
747         if ( i == -1)
748         {
749                 //OR_EXCLUSIVE mode
750                 i = _search_grabbed_key(key_list, keycode | OR_EXCLUSIVE_GRAB, cnt);
751
752                 if ( i == -1)
753                 {
754                         //TOP_POSITION mode
755                         i = _search_grabbed_key(key_list, keycode | TOP_POSITION_GRAB, cnt);
756
757                         if (i == -1)
758                         {
759                                 //SHARED mode
760                                 i = _search_grabbed_key(key_list, keycode | SHARED_GRAB, cnt);
761
762                                 if (i == -1)
763                                 {
764                                         _free_list_of_grabbed_key(key_list);
765                                         goto out;
766                                 }
767                         }
768                 }
769                 else
770                 {
771                         _unset_exclusive_grab_info_to_root(disp, keycode, OR_EXCLUSIVE_GRAB);
772                 }
773         }
774         else
775         {
776                 _unset_exclusive_grab_info_to_root(disp, keycode, EXCLUSIVE_GRAB);
777         }
778
779         new_key_list = _del_grabbed_key(key_list, i, &cnt);
780         _free_list_of_grabbed_key(key_list);
781
782         if (new_key_list) {
783                 XChangeProperty(disp, win, _atom_grab_key, XA_CARDINAL, 32,
784                         PropModeReplace, (unsigned char *)new_key_list, cnt);
785         }
786         else {
787                 XDeleteProperty(disp, win, _atom_grab_key);
788         }
789         XSync(disp, False);
790
791         _free_new_list_of_grabbed_key(new_key_list);
792         ret = 0;
793         errno = 0;
794
795 out:
796
797         return ret;
798 }
799
800 API Utilx_Key_Status utilx_get_key_status(Display* dpy, char *key_name)
801 {
802         unsigned char keymap[32];
803         static unsigned int masktable[8] = { 0x01, 0x02, 0x04, 0x08, 0x10, 0x20, 0x40, 0x80 };
804         Utilx_Key_Status status = UTILX_KEY_STATUS_UNKNOWN;
805
806         if( !strncmp(key_name, KEY_VOLUMEDOWN, LEN_KEY_VOLUMEDOWN) ||
807                 !strncmp(key_name, KEY_VOLUMEUP, LEN_KEY_VOLUMEUP) ||
808                 !strncmp(key_name, KEY_PAUSE, LEN_KEY_PAUSE) ||
809                 !strncmp(key_name, KEY_SEND, LEN_KEY_SEND) ||
810                 !strncmp(key_name, KEY_SELECT, LEN_KEY_VOLUMEDOWN) ||
811                 !strncmp(key_name, KEY_END, LEN_KEY_END) ||
812                 !strncmp(key_name, KEY_POWER, LEN_KEY_POWER) ||
813                 !strncmp(key_name, KEY_CAMERA, LEN_KEY_CAMERA) ||
814                 !strncmp(key_name, KEY_CONFIG, LEN_KEY_CONFIG) ||
815                 !strncmp(key_name, KEY_PLAYCD, LEN_KEY_PLAYCD) ||
816                 !strncmp(key_name, KEY_STOPCD, LEN_KEY_STOPCD) ||
817                 !strncmp(key_name, KEY_PAUSECD, LEN_KEY_PAUSECD) ||
818                 !strncmp(key_name, KEY_NEXTSONG, LEN_KEY_NEXTSONG) ||
819                 !strncmp(key_name, KEY_PREVIOUSSONG, LEN_KEY_PREVIOUSSONG) ||
820                 !strncmp(key_name, KEY_REWIND, LEN_KEY_REWIND) ||
821                 !strncmp(key_name, KEY_FASTFORWARD, LEN_KEY_FASTFORWARD) ||
822                 !strncmp(key_name, KEY_MEDIA, LEN_KEY_MEDIA) )
823         {
824                 KeySym ks = XStringToKeysym(key_name);
825                 KeyCode kc = XKeysymToKeycode(dpy, ks);
826
827                 if( kc )
828                 {
829                         XQueryKeymap(dpy, (char *)keymap);
830                         if( keymap[kc >> 3] & masktable[kc & 7] )
831                                 status = UTILX_KEY_STATUS_PRESSED;
832                         else
833                                 status = UTILX_KEY_STATUS_RELEASED;
834                 }
835         }
836
837         return status;
838 }
839
840 API void utilx_set_window_effect_state(Display* dpy, Window win, int state)
841 {
842         if ( dpy == NULL )
843         {
844                 fprintf (stderr, "[UTILX] Error.. Invald Display.. %s (%d)\n", __func__, __LINE__);
845                 return;
846         }
847         if( !_atom_comp_effect_state)
848                 _atom_comp_effect_state = XInternAtom(dpy, "_NET_CM_WINDOW_EFFECT_ENABLE",False);
849
850         _utilx_set_window_property(dpy, win, _atom_comp_effect_state, XA_CARDINAL, (unsigned int *)&state, 1);
851
852         XSync(dpy, 0 );
853 }
854
855 API int utilx_get_window_effect_state(Display* dpy, Window win)
856 {
857         int state = 0;
858         if( !_atom_comp_effect_state)
859                 _atom_comp_effect_state = XInternAtom(dpy, "_NET_CM_WINDOW_EFFECT_ENABLE",False);
860         _utilx_get_window_property(dpy, win, _atom_comp_effect_state, XA_CARDINAL, (unsigned int *)&state, 1);
861         return state;
862 }
863
864 static void
865 _utilx_string_set_window_property( Display *dpy, Window win, Atom atom, char *val, unsigned int num)
866 {
867         XChangeProperty( dpy, win, atom, XA_STRING, 8, PropModeReplace, (unsigned char*)val, val ? strlen(val):0 );
868 }
869
870 API void utilx_set_fake_launch_img(Display* dpy, Window win, char *file_name)
871 {
872         //UTILX_TRACE ("[UTILX] utilx_set_effect_state... win = %x, show_state = %d\n", win, enable);
873
874         if ( dpy == NULL )
875         {
876                 fprintf (stderr, "[UTILX] Error.. Invald Display.. %s (%d)\n", __func__, __LINE__);
877                 return;
878         }
879         if( !_atom_comp_fake_launch_image)
880                 _atom_comp_fake_launch_image = XInternAtom(dpy, "_E_COMP_FAKE_LAUNCH_IMAGE",False);
881
882         _utilx_string_set_window_property(dpy, win, _atom_comp_fake_launch_image, file_name, 1);
883 }
884
885 API void utilx_show_fake_effect( Display *dpy, Window win, char *fake_image_file )
886 {
887         XEvent xev;
888
889         _atom_comp_fake_launch = XInternAtom( dpy, "_E_COMP_FAKE_LAUNCH", False );
890
891         if(  !_atom_comp_fake_launch )
892         {
893                 fprintf( stderr, "XInternAtom(_E_COMP_FAKE_LAUNCH) failed.\n" );
894                 return;
895         }
896
897         utilx_set_fake_launch_img(dpy, win, fake_image_file);
898
899         XSync(dpy, 0 );
900
901         // send fake client message
902         xev.xclient.type = ClientMessage;
903         xev.xclient.display = dpy;
904         xev.xclient.window = win;
905         xev.xclient.message_type =  _atom_comp_fake_launch;
906         xev.xclient.format = 32;
907         xev.xclient.data.l[0] = 1;  // 1 : start effect , 0 : end effect
908         xev.xclient.data.l[1] = 0;
909         xev.xclient.data.l[2] = 0;
910         xev.xclient.data.l[3] = 0;
911         xev.xclient.data.l[4] = 0;
912
913         XSendEvent( dpy, win, False,
914                                 SubstructureRedirectMask | SubstructureNotifyMask,
915                                 &xev );
916         XSync(dpy, 0 );
917
918 }
919
920
921 API void utilx_hide_fake_effect( Display *dpy, Window win)
922 {
923         XEvent xev;
924
925         _atom_comp_fake_launch = XInternAtom( dpy, "_E_COMP_FAKE_LAUNCH", False );
926         if(  !_atom_comp_fake_launch )
927         {
928                 fprintf( stderr, "XInternAtom(_E_COMP_FAKE_LAUNCH) failed.\n" );
929                 return;
930         }
931
932         // send fake client message
933         xev.xclient.type = ClientMessage;
934         xev.xclient.display = dpy;
935         xev.xclient.window = win;
936         xev.xclient.message_type =  _atom_comp_fake_launch;
937         xev.xclient.format = 32;
938         xev.xclient.data.l[0] = 0;  // 1 : start effect , 0 : end effect
939         xev.xclient.data.l[1] = 0;
940         xev.xclient.data.l[2] = 0;
941         xev.xclient.data.l[3] = 0;
942         xev.xclient.data.l[4] = 0;
943
944         XSendEvent( dpy, win, False,
945                                 SubstructureRedirectMask | SubstructureNotifyMask,
946                                 &xev );
947         XSync(dpy, 0 );
948 }
949
950 static void _utilx_effect_atom_check( Display* dpy )
951 {
952         if ( dpy == NULL )
953         {
954                 fprintf (stderr, "[UTILX] Error.. Invald Display.. %s (%d)\n", __func__, __LINE__);
955                 return;
956         }
957
958         if( !_atom_comp_window_effect_type)
959                 _atom_comp_window_effect_type =  XInternAtom(dpy, "_NET_CM_WINDOW_EFFECT_TYPE",False);
960         if( !_atom_comp_effect_default )
961                 _atom_comp_effect_default = XInternAtom(dpy, "_NET_CM_EFFECT_DEFAULT",False);
962         if( !_atom_comp_effect_none )
963                 _atom_comp_effect_none = XInternAtom(dpy, "_NET_CM_EFFECT_NONE",False);
964         if( !_atom_comp_effect_custom0 )
965                 _atom_comp_effect_custom0 = XInternAtom(dpy, "_NET_CM_EFFECT_CUSTOM0",False);
966         if( !_atom_comp_effect_custom1 )
967                 _atom_comp_effect_custom1 = XInternAtom(dpy, "_NET_CM_EFFECT_CUSTOM1",False);
968         if( !_atom_comp_effect_custom2 )
969                 _atom_comp_effect_custom2 = XInternAtom(dpy, "_NET_CM_EFFECT_CUSTOM2",False);
970         if( !_atom_comp_effect_custom3 )
971                 _atom_comp_effect_custom3 = XInternAtom(dpy, "_NET_CM_EFFECT_CUSTOM3",False);
972         if( !_atom_comp_effect_custom4 )
973                 _atom_comp_effect_custom4 = XInternAtom(dpy, "_NET_CM_EFFECT_CUSTOM4",False);
974         if( !_atom_comp_effect_custom5 )
975                 _atom_comp_effect_custom5 = XInternAtom(dpy, "_NET_CM_EFFECT_CUSTOM5",False);
976         if( !_atom_comp_effect_custom6 )
977                 _atom_comp_effect_custom6 = XInternAtom(dpy, "_NET_CM_EFFECT_CUSTOM6",False);
978         if( !_atom_comp_effect_custom7 )
979                 _atom_comp_effect_custom7 = XInternAtom(dpy, "_NET_CM_EFFECT_CUSTOM7",False);
980         if( !_atom_comp_effect_custom8 )
981                 _atom_comp_effect_custom8 = XInternAtom(dpy, "_NET_CM_EFFECT_CUSTOM8",False);
982         if( !_atom_comp_effect_custom9 )
983                 _atom_comp_effect_custom9 = XInternAtom(dpy, "_NET_CM_EFFECT_CUSTOM9",False);
984 }
985
986 static Atom _utilx_convert_style_to_atom( Display* dpy, Utilx_Effect_Style style )
987 {
988         if ( dpy == NULL )
989         {
990                 fprintf (stderr, "[UTILX] Error.. Invald Display.. %s (%d)\n", __func__, __LINE__);
991                 return _atom_comp_effect_none;
992         }
993         _utilx_effect_atom_check(dpy);
994
995         if ( style == UTILX_EFFECT_STYLE_DEFAULT )       return _atom_comp_effect_default;
996         else if ( style == UTILX_EFFECT_STYLE_NONE )     return _atom_comp_effect_none;
997         else if ( style == UTILX_EFFECT_STYLE_CUSTOM0 )  return _atom_comp_effect_custom0;
998         else if ( style == UTILX_EFFECT_STYLE_CUSTOM1 )  return _atom_comp_effect_custom1;
999         else if ( style == UTILX_EFFECT_STYLE_CUSTOM2 )  return _atom_comp_effect_custom2;
1000         else if ( style == UTILX_EFFECT_STYLE_CUSTOM3 )  return _atom_comp_effect_custom3;
1001         else if ( style == UTILX_EFFECT_STYLE_CUSTOM4 )  return _atom_comp_effect_custom4;
1002         else if ( style == UTILX_EFFECT_STYLE_CUSTOM5 )  return _atom_comp_effect_custom5;
1003         else if ( style == UTILX_EFFECT_STYLE_CUSTOM6 )  return _atom_comp_effect_custom6;
1004         else if ( style == UTILX_EFFECT_STYLE_CUSTOM7 )  return _atom_comp_effect_custom7;
1005         else if ( style == UTILX_EFFECT_STYLE_CUSTOM8 )  return _atom_comp_effect_custom8;
1006         else if ( style == UTILX_EFFECT_STYLE_CUSTOM9 )  return _atom_comp_effect_custom9;
1007         else                                             return _atom_comp_effect_none;
1008
1009 }
1010
1011 static Utilx_Effect_Style _utilx_convert_atom_to_style( Display* dpy, Atom style )
1012 {
1013         if ( dpy == NULL )
1014         {
1015                 fprintf (stderr, "[UTILX] Error.. Invald Display.. %s (%d)\n", __func__, __LINE__);
1016                 return UTILX_EFFECT_STYLE_NONE;
1017         }
1018         _utilx_effect_atom_check(dpy);
1019
1020         if ( style == _atom_comp_effect_default )       return UTILX_EFFECT_STYLE_DEFAULT;
1021         else if ( style == _atom_comp_effect_none )     return UTILX_EFFECT_STYLE_NONE;
1022         else if ( style == _atom_comp_effect_custom0 )  return UTILX_EFFECT_STYLE_CUSTOM0;
1023         else if ( style == _atom_comp_effect_custom1 )  return UTILX_EFFECT_STYLE_CUSTOM1;
1024         else if ( style == _atom_comp_effect_custom2 )  return UTILX_EFFECT_STYLE_CUSTOM2;
1025         else if ( style == _atom_comp_effect_custom3 )  return UTILX_EFFECT_STYLE_CUSTOM3;
1026         else if ( style == _atom_comp_effect_custom4 )  return UTILX_EFFECT_STYLE_CUSTOM4;
1027         else if ( style == _atom_comp_effect_custom5 )  return UTILX_EFFECT_STYLE_CUSTOM5;
1028         else if ( style == _atom_comp_effect_custom6 )  return UTILX_EFFECT_STYLE_CUSTOM6;
1029         else if ( style == _atom_comp_effect_custom7 )  return UTILX_EFFECT_STYLE_CUSTOM7;
1030         else if ( style == _atom_comp_effect_custom8 )  return UTILX_EFFECT_STYLE_CUSTOM8;
1031         else if ( style == _atom_comp_effect_custom9 )  return UTILX_EFFECT_STYLE_CUSTOM9;
1032         else                                            return UTILX_EFFECT_STYLE_DEFAULT;
1033 }
1034
1035 API void utilx_set_window_effect_style(Display* dpy, Window win, Utilx_Effect_Type type, Utilx_Effect_Style style)
1036 {
1037         Atom *window_effect_type_list = NULL;
1038         if ( dpy == NULL )
1039         {
1040                 fprintf (stderr, "[UTILX] Error.. Invald Display.. %s (%d)\n", __func__, __LINE__);
1041                 return;
1042         }
1043         _utilx_effect_atom_check(dpy);
1044
1045         window_effect_type_list = (Atom *)malloc(sizeof(Atom) * 6);
1046
1047         if ( !window_effect_type_list )
1048         {
1049                 fprintf (stderr, "[UTILX] Error.. malloc().. %s (%d)\n", __func__, __LINE__);
1050                 return;
1051         }
1052
1053         window_effect_type_list[0] = _atom_comp_effect_default;
1054         window_effect_type_list[1] = _atom_comp_effect_default;
1055         window_effect_type_list[2] = _atom_comp_effect_default;
1056         window_effect_type_list[3] = _atom_comp_effect_default;
1057         window_effect_type_list[4] = _atom_comp_effect_default;
1058         window_effect_type_list[5] = _atom_comp_effect_default;
1059
1060         _utilx_get_window_property(dpy, win, _atom_comp_window_effect_type, XA_ATOM, (unsigned int *)window_effect_type_list, 6);
1061
1062         if ( type == UTILX_EFFECT_TYPE_MAP )             window_effect_type_list[0] = _utilx_convert_style_to_atom(dpy, style);
1063         else if ( type == UTILX_EFFECT_TYPE_UNMAP )      window_effect_type_list[1] = _utilx_convert_style_to_atom(dpy, style);
1064         else if ( type == UTILX_EFFECT_TYPE_RAISEABOVE ) window_effect_type_list[2] = _utilx_convert_style_to_atom(dpy, style);
1065         else if ( type == UTILX_EFFECT_TYPE_ROTATION )   window_effect_type_list[3] = _utilx_convert_style_to_atom(dpy, style);
1066         else if ( type == UTILX_EFFECT_TYPE_FOCUSIN )    window_effect_type_list[4] = _utilx_convert_style_to_atom(dpy, style);
1067         else if ( type == UTILX_EFFECT_TYPE_FOCUSOUT )   window_effect_type_list[5] = _utilx_convert_style_to_atom(dpy, style);
1068
1069         _utilx_set_window_property(dpy, win, _atom_comp_window_effect_type, XA_ATOM, (unsigned int *)window_effect_type_list, 6);
1070
1071         XSync(dpy, 0 );
1072         free(window_effect_type_list);
1073 }
1074
1075 API Utilx_Effect_Style utilx_get_window_effect_style(Display* dpy, Window win, Utilx_Effect_Type type)
1076 {
1077         Atom *window_effect_type_list = NULL;
1078         Utilx_Effect_Style style = UTILX_EFFECT_STYLE_DEFAULT;
1079
1080         if ( dpy == NULL )
1081         {
1082                 fprintf (stderr, "[UTILX] Error.. Invald Display.. %s (%d)\n", __func__, __LINE__);
1083                 return UTILX_EFFECT_STYLE_NONE;
1084         }
1085         _utilx_effect_atom_check(dpy);
1086
1087         window_effect_type_list = (Atom *)malloc(sizeof(Atom) * 6);
1088
1089         if ( !window_effect_type_list )
1090         {
1091                 fprintf (stderr, "[UTILX] Error.. malloc().. %s (%d)\n", __func__, __LINE__);
1092                 return UTILX_EFFECT_STYLE_NONE;
1093         }
1094
1095         if ( _utilx_get_window_property(dpy, win, _atom_comp_window_effect_type, XA_ATOM, (unsigned int *)window_effect_type_list, 6) != 6 )
1096         {
1097                 fprintf (stderr, "[UTILX] Error.. get property failed!.. %s (%d)\n", __func__, __LINE__);
1098                 free(window_effect_type_list);
1099                 return UTILX_EFFECT_STYLE_NONE;
1100         }
1101
1102         if ( type == UTILX_EFFECT_TYPE_MAP )             style = _utilx_convert_atom_to_style(dpy, window_effect_type_list[0]);
1103         else if ( type == UTILX_EFFECT_TYPE_UNMAP )      style = _utilx_convert_atom_to_style(dpy, window_effect_type_list[1]);
1104         else if ( type == UTILX_EFFECT_TYPE_RAISEABOVE ) style = _utilx_convert_atom_to_style(dpy, window_effect_type_list[2]);
1105         else if ( type == UTILX_EFFECT_TYPE_ROTATION )   style = _utilx_convert_atom_to_style(dpy, window_effect_type_list[3]);
1106         else if ( type == UTILX_EFFECT_TYPE_FOCUSIN )    style = _utilx_convert_atom_to_style(dpy, window_effect_type_list[4]);
1107         else if ( type == UTILX_EFFECT_TYPE_FOCUSOUT )   style = _utilx_convert_atom_to_style(dpy, window_effect_type_list[5]);
1108
1109         XSync(dpy, 0 );
1110         free(window_effect_type_list);
1111         return style;
1112 }
1113
1114 API int utilx_set_window_opaque_state (Display* dpy, Window win, Utilx_Opaque_State state)
1115 {
1116         UTILX_TRACE ("[UTILX] utilx_set_window_opaque_state... win = %x, show_state = %d\n", win, state);
1117
1118         unsigned int is_opaque;
1119
1120         if (dpy == NULL)
1121         {
1122                 fprintf (stderr, "[UTILX] Error.. Invald Display.. %s (%d)\n", __func__, __LINE__);
1123                 return 0;
1124         }
1125
1126         switch (state)
1127         {
1128                 case UTILX_OPAQUE_STATE_OFF:
1129                         is_opaque = 0;
1130                         break;
1131
1132                 case UTILX_OPAQUE_STATE_ON:
1133                         is_opaque = 1;
1134                         break;
1135
1136                 default:
1137                         fprintf (stderr, "[UTILX] Error.. Invald State.. %s (%d)\n", __func__, __LINE__);
1138                         return 0;
1139         }
1140
1141         if (!_atom_window_opaque)
1142         {
1143                 _atom_window_opaque = XInternAtom (dpy, "_E_ILLUME_WINDOW_REGION_OPAQUE", False);
1144                 if (!_atom_window_opaque)
1145                 {
1146                         fprintf (stderr, "[UTILX] Error.. Cannot create _E_ILLUME_WINDOW_REGION_OPAQUE atom.. %s (%d)\n", __func__, __LINE__);
1147                         return 0;
1148                 }
1149         }
1150
1151         _utilx_set_window_property (dpy, win, _atom_window_opaque, XA_CARDINAL,
1152                         (unsigned int *)&is_opaque, 1);
1153
1154         return 1;
1155 }
1156
1157 static void
1158 _utilx_screen_capture_atom_ensure (Display* dpy)
1159 {
1160         if (_atom_screen_capture_disable)
1161                 return;
1162
1163         _atom_screen_capture_disable = XInternAtom (dpy, "_CB_SCREEN_CAPTURE_DISABLE", False);
1164         if (_atom_screen_capture_disable)
1165                 return;
1166
1167         fprintf (stderr, "[UTILX] Error.. Cannot create _CB_SCREEN_CAPTURE_DISABLE atom.. %s (%d)\n", __func__, __LINE__);
1168 }
1169
1170 API int
1171 utilx_set_screen_capture(Display* dpy, int enable)
1172 {
1173         Window root;
1174         int disable;
1175
1176         if (!dpy)
1177         {
1178                 fprintf (stderr, "[UTILX] Error.. dpy is NULL %s (%d)\n", __func__, __LINE__);
1179                 return 0;
1180         }
1181
1182         root = RootWindow (dpy, DefaultScreen(dpy));
1183         disable = (enable) ? 0 : 1;
1184
1185         _utilx_screen_capture_atom_ensure (dpy);
1186
1187         _utilx_set_window_property (dpy, root, _atom_screen_capture_disable, XA_CARDINAL, (unsigned int *)&disable, 1);
1188
1189         return 1;
1190 }
1191
1192 API int
1193 utilx_get_screen_capture(Display* dpy)
1194 {
1195         Window root;
1196         int disable = 0;
1197
1198         if (!dpy)
1199         {
1200                 fprintf (stderr, "[UTILX] Error.. dpy is NULL %s (%d)\n", __func__, __LINE__);
1201                 return 0;
1202         }
1203
1204         root = RootWindow (dpy, DefaultScreen(dpy));
1205
1206         _utilx_screen_capture_atom_ensure (dpy);
1207
1208         _utilx_get_window_property(dpy, root, _atom_screen_capture_disable, XA_CARDINAL,
1209                                     (unsigned int *)&disable, 1);
1210
1211         return (disable) ? 0 : 1;
1212 }
1213
1214 API void utilx_set_window_cardinal_property(Display* dpy, Window win, Atom atom, unsigned int *value)
1215 {
1216         _utilx_set_window_property(dpy, win, atom, XA_CARDINAL, value, 1);
1217 }
1218
1219 API int utilx_get_window_cardinal_property (Display* dpy, Window win, Atom atom, unsigned int *value)
1220 {
1221         return _utilx_get_window_property(dpy, win, atom, XA_CARDINAL, value, 1);
1222 }
1223
1224 API void utilx_show_capture_effect( Display *dpy, Window win)
1225 {
1226     XEvent xev;
1227
1228     _atom_comp_capture_effect = XInternAtom( dpy, "_E_COMP_CAPTURE_EFFECT", False );
1229     if(  !_atom_comp_capture_effect )
1230     {
1231         fprintf( stderr, "XInternAtom(_E_COMP_CAPTURE_EFFECT) failed.\n" );
1232         return;
1233     }
1234
1235     // send capture effect client message
1236     xev.xclient.type = ClientMessage;
1237     xev.xclient.display = dpy;
1238     xev.xclient.window = win;
1239     xev.xclient.message_type =  _atom_comp_capture_effect;
1240     xev.xclient.format = 32;
1241     xev.xclient.data.l[0] = 0;
1242     xev.xclient.data.l[1] = 0;
1243     xev.xclient.data.l[2] = 0;
1244     xev.xclient.data.l[3] = 0;
1245     xev.xclient.data.l[4] = 0;
1246
1247     XSendEvent( dpy, win, False,
1248                 SubstructureRedirectMask | SubstructureNotifyMask,
1249                 &xev );
1250     XSync(dpy, 0 );
1251 }