4 Copyright (c) 2011 Samsung Electronics Co., Ltd All Rights Reserved
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
10 http://www.apache.org/licenses/LICENSE-2.0
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.
26 #include <X11/Xatom.h>
34 #define UTILX_TRACE printf
36 #define UTILX_TRACE(...)
39 static Atom _atom_grab_key = None;
40 static Atom _atom_grab_excl_win = None;
41 static Atom _atom_grab_or_excl_win = None;
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;
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;
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;
66 static Atom _atom_window_opaque = None;
68 static Atom _atom_screen_capture_disable = None;
70 static Atom _atom_comp_capture_effect = None;
72 const unsigned long maxlen = 1024l;
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);
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 );
81 static int _utilx_get_indicator_atoms(Display *dpy);
83 API void utilx_set_system_notification_level (Display* dpy, Window win, Utilx_Notification_Level level)
85 UTILX_TRACE ("[UTILX] utilx_set_system_notification_level... win = %x, level = %d\n", win, level);
91 fprintf (stderr, "[UTILX] Error.. Invald Display.. %s (%d)\n", __func__, __LINE__);
97 case UTILX_NOTIFICATION_LEVEL_LOW:
101 case UTILX_NOTIFICATION_LEVEL_NORMAL:
105 case UTILX_NOTIFICATION_LEVEL_HIGH:
114 if (!_atom_notification_level)
116 _atom_notification_level = XInternAtom (dpy, "_E_ILLUME_NOTIFICATION_LEVEL", False);
117 if (!_atom_notification_level)
119 fprintf (stderr, "[UTILX] Error.. Cannot create _E_ILLUME_NOTIFICATION_LEVEL atom.. %s (%d)\n", __func__, __LINE__);
124 _utilx_set_window_property (dpy, win, _atom_notification_level, XA_CARDINAL,
125 (unsigned int *)¬i_level, 1);
129 API Utilx_Notification_Level utilx_get_system_notification_level (Display* dpy, Window win)
131 UTILX_TRACE ("[UTILX] utilx_get_system_notification_level... win = %x\n", win);
133 Utilx_Notification_Level noti_level;
137 noti_level = UTILX_NOTIFICATION_LEVEL_LOW;
141 fprintf (stderr, "[UTILX] Error.. Invald Display.. %s (%d)\n", __func__, __LINE__);
145 if (!_atom_notification_level)
147 _atom_notification_level = XInternAtom (dpy, "_E_ILLUME_NOTIFICATION_LEVEL", False);
148 if (!_atom_notification_level)
150 fprintf (stderr, "[UTILX] Error.. Cannot create _E_ILLUME_NOTIFICATION_LEVEL atom.. %s (%d)\n", __func__, __LINE__);
155 ret = _utilx_get_window_property (dpy, win, _atom_notification_level, XA_CARDINAL,
156 (unsigned int *)&level, 1);
163 noti_level = UTILX_NOTIFICATION_LEVEL_LOW;
167 noti_level = UTILX_NOTIFICATION_LEVEL_NORMAL;
171 noti_level = UTILX_NOTIFICATION_LEVEL_HIGH;
175 noti_level = UTILX_NOTIFICATION_LEVEL_LOW;
181 noti_level = UTILX_NOTIFICATION_LEVEL_LOW;
188 static int _utilx_get_indicator_atoms(Display *dpy)
190 if (!_atom_indicator_visible_state)
192 _atom_indicator_visible_state = XInternAtom (dpy, "_E_ILLUME_INDICATOR_STATE", False);
193 if (!_atom_indicator_visible_state)
195 fprintf (stderr, "[UTILX] Error.. Cannot create _E_ILLUME_INDICATOR_STATE atom.. %s (%d)\n", __func__, __LINE__);
200 if (!_atom_indicator_visible_state_on)
202 _atom_indicator_visible_state_on = XInternAtom (dpy, "_E_ILLUME_INDICATOR_ON", False);
203 if (!_atom_indicator_visible_state_on)
205 fprintf (stderr, "[UTILX] Error.. Cannot create _E_ILLUME_INDICATOR_ON atom.. %s (%d)\n", __func__, __LINE__);
210 if (!_atom_indicator_visible_state_off)
212 _atom_indicator_visible_state_off = XInternAtom (dpy, "_E_ILLUME_INDICATOR_OFF", False);
213 if (!_atom_indicator_visible_state_off)
215 fprintf (stderr, "[UTILX] Error.. Cannot create _E_ILLUME_INDICATOR_OFF atom.. %s (%d)\n", __func__, __LINE__);
223 API void utilx_enable_indicator (Display* dpy, Window win, int enable)
225 UTILX_TRACE ("[UTILX] utilx_indicator_set_visible_state... win = %x, show_state = %d\n", win, enable);
229 fprintf (stderr, "[UTILX] Error.. Invald Display.. %s (%d)\n", __func__, __LINE__);
233 if (!_utilx_get_indicator_atoms(dpy))
235 fprintf (stderr, "[UTILX] Error.. Cannot create atoms.. %s (%d)\n", __func__, __LINE__);
241 _utilx_set_window_property (dpy, win, _atom_indicator_visible_state, XA_ATOM,
242 (unsigned int *)&_atom_indicator_visible_state_on, 1);
246 _utilx_set_window_property (dpy, win, _atom_indicator_visible_state, XA_ATOM,
247 (unsigned int *)&_atom_indicator_visible_state_off, 1);
252 API int utilx_get_indicator_state (Display* dpy, Window win)
254 UTILX_TRACE ("[UTILX] utilx_indicator_set_visible_state... win = %x, show_state = %d\n", win, enable);
261 fprintf (stderr, "[UTILX] Error.. Invald Display.. %s (%d)\n", __func__, __LINE__);
265 if (!_utilx_get_indicator_atoms(dpy))
267 fprintf (stderr, "[UTILX] Error.. Cannot create atoms.. %s (%d)\n", __func__, __LINE__);
271 ret = _utilx_get_window_property (dpy, win, _atom_indicator_visible_state, XA_ATOM,
272 (unsigned int *)&state, 1);
276 if (state == _atom_indicator_visible_state_on)
278 else if (state == _atom_indicator_visible_state_off)
288 _utilx_set_window_property (Display* dpy, Window win, Atom atom, Atom type, unsigned int *val, unsigned int num)
290 XChangeProperty (dpy, win, atom, type, 32, PropModeReplace, (unsigned char *)val, num);
296 _utilx_get_window_property (Display* dpy, Window win, Atom atom, Atom type, unsigned int *val, unsigned int len)
298 unsigned char* prop_ret;
300 unsigned long bytes_after, num_ret;
306 if (XGetWindowProperty(dpy, win, atom, 0, 0x7fffffff, False,
307 type, &type_ret, &format_ret, &num_ret,
308 &bytes_after, &prop_ret) != Success)
313 if (type_ret != type || format_ret != 32)
317 else if (num_ret == 0 || !prop_ret)
325 for (i = 0; i < len; i++)
327 val[i] = ((unsigned long *)prop_ret)[i];
340 static unsigned long _get_list_of_grabbed_key (Display *disp, Window win, int **key_list)
344 unsigned long nr_item;
345 unsigned long sz_remains_data;
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)
355 // fprintf(stderr, "
\e[31m%d - %lu
\e[0m\n", ret_format, nr_item);
361 static void _free_list_of_grabbed_key (int *key_list)
369 static void _free_new_list_of_grabbed_key (int *new_key_list)
377 static int _search_grabbed_key (int *key_list, int key, unsigned long cnt)
381 for (i = cnt - 1; i >= 0; i --) {
382 if (key_list[i] == key) break;
389 static int *_del_grabbed_key (int *key_list, int i, unsigned long *cnt)
391 int *new_key_list = NULL;
393 // Only one element is exists in the list of grabbed key
396 if (*cnt == 0) return NULL;
399 new_key_list = malloc((*cnt) * sizeof(int));
400 if (new_key_list == NULL) {
407 memcpy(new_key_list, key_list, sizeof(int) * i);
411 if ((*cnt) - i > 0) {
412 memcpy(new_key_list + i,
414 sizeof(int) * ((*cnt) - i)
421 static void _set_exclusive_grab_info_to_root (Display *disp, int keycode, Window win, int grab_mode)
424 int *key_list = NULL;
428 unsigned long nr_item;
429 unsigned long sz_remains_data;
432 if( grab_mode == EXCLUSIVE_GRAB )
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;
438 else if( grab_mode == OR_EXCLUSIVE_GRAB )
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;
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)
452 fprintf(stderr, "[utilX][%s] Fail to get root window property !\n", __FUNCTION__);
457 printf("[%s] keycode = %d\n", __FUNCTION__, keycode);
460 for( i=0 ; i < nr_item ; i++ )
462 if( key_list && (key_list[i] == keycode) )
466 XChangeProperty(disp, DefaultRootWindow(disp), ex_grabwin, XA_CARDINAL, 32,
467 nr_item ? PropModeAppend : PropModeReplace, (unsigned char *)&keycode, 1);
475 static void _unset_exclusive_grab_info_to_root (Display *disp, int keycode, int grab_mode)
478 unsigned long cnt = 0;
479 int *key_list = NULL;
480 int *new_key_list = NULL;
484 unsigned long nr_item;
485 unsigned long sz_remains_data;
488 if( grab_mode == EXCLUSIVE_GRAB )
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;
494 else if( grab_mode == OR_EXCLUSIVE_GRAB )
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;
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)
513 fprintf(stderr, "
\e[32m[utilX][%s] keycode = %d
\e[0m\n", __FUNCTION__, keycode);
517 for( i=0 ; i < nr_item ; i++ )
519 if( key_list[i] == keycode )//&& grab_mode == EXCLUSIVE_GRAB )
527 fprintf(stderr, "[utilX][%s] cnt = %d, nr_item = %d\n", __FUNCTION__, cnt, nr_item);
532 new_key_list = malloc(sizeof(int)*cnt);
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);
546 for( i=0 ; i < nr_item ; i++ )
548 if( key_list[i] == keycode )//&& grab_mode == EXCLUSIVE_GRAB )
553 new_key_list[cnt++] = key_list[i];
557 XChangeProperty(disp, DefaultRootWindow(disp), ex_grabwin, XA_CARDINAL, 32,
558 PropModeReplace, (unsigned char *)new_key_list, cnt);
561 XDeleteProperty(disp, DefaultRootWindow(disp), ex_grabwin);
573 static int _is_grabbed_key_exclusively (Display* disp, int keycode, int grab_mode)
576 int *key_list = NULL;
580 unsigned long nr_item;
581 unsigned long sz_remains_data;
584 if( grab_mode == EXCLUSIVE_GRAB )
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;
590 else if( grab_mode == OR_EXCLUSIVE_GRAB )
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;
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)
604 fprintf(stderr, "[%s] Fail to get root window property !\n", __FUNCTION__);
608 for( i=0 ; i < nr_item ; i++ )
610 if( key_list[i] == keycode )
611 return EXCLUSIVE_GRABBED_ALREADY;
618 API int utilx_grab_key (Display* disp, Window win, const char* key, int grab_mode)
621 int *key_list = NULL;
629 fprintf(stderr, "[%s] Display is NULL\n", __FUNCTION__);
633 if (_atom_grab_key == None) {
634 _atom_grab_key = XInternAtom(disp, STR_ATOM_GRAB_KEY, False);
637 if (!strncmp(key, "Keycode-", 8)) {
638 keycode = atoi(key + 8);
640 keysym = XStringToKeysym(key);
641 if (keysym == NoSymbol) goto out;
642 keycode = XKeysymToKeycode(disp, XStringToKeysym(key));
644 if (keycode == 0) goto out;
646 if( grab_mode == EXCLUSIVE_GRAB )
649 result = _is_grabbed_key_exclusively(disp, keycode, grab_mode);
652 printf("[%s] _is_grabbed_key_exclusively returns result = %d\n", __FUNCTION__, result);
657 fprintf(stderr, "[%s] keycode(%d) was already grabbed exclusively (grab_mode=0x%X) !\n", __FUNCTION__, keycode, grab_mode);
661 else if( grab_mode == OR_EXCLUSIVE_GRAB )
663 result = _is_grabbed_key_exclusively(disp, keycode, grab_mode);
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);
673 keycode |= grab_mode;
675 cnt = _get_list_of_grabbed_key(disp, win, &key_list);
677 i = _search_grabbed_key(key_list, keycode, cnt);
678 _free_list_of_grabbed_key(key_list);
680 if( grab_mode == OR_EXCLUSIVE_GRAB )
682 utilx_ungrab_key(disp, win, key);
686 fprintf(stderr, "Key is already grabbed\n");
692 XChangeProperty(disp, win, _atom_grab_key, XA_CARDINAL, 32,
693 cnt ? PropModeAppend : PropModeReplace, (unsigned char *)&keycode, 1);
695 keycode = keycode & (~GRAB_MODE_MASK);
697 printf("[%s] keycode = %d\n", __FUNCTION__, keycode);
700 if( EXCLUSIVE_GRAB == grab_mode || OR_EXCLUSIVE_GRAB == grab_mode )
701 _set_exclusive_grab_info_to_root(disp, keycode, win, grab_mode);
711 API int utilx_ungrab_key (Display* disp, Window win, const char* key)
715 int *key_list = NULL;
716 int *new_key_list = NULL;
724 fprintf(stderr, "[%s] Display is NULL\n", __FUNCTION__);
728 if (_atom_grab_key == None) {
729 _atom_grab_key = XInternAtom(disp, STR_ATOM_GRAB_KEY, False);
732 if (!strncmp(key, "Keycode-", 8)) {
733 keycode = atoi(key + 8);
735 keysym = XStringToKeysym(key);
736 if (keysym == NoSymbol) goto out;
737 keycode = XKeysymToKeycode(disp, XStringToKeysym(key));
739 if (keycode == 0) goto out;
741 cnt = _get_list_of_grabbed_key(disp, win, &key_list);
742 if (cnt == 0) goto out;
745 i = _search_grabbed_key(key_list, keycode | EXCLUSIVE_GRAB, cnt);
750 i = _search_grabbed_key(key_list, keycode | OR_EXCLUSIVE_GRAB, cnt);
755 i = _search_grabbed_key(key_list, keycode | TOP_POSITION_GRAB, cnt);
760 i = _search_grabbed_key(key_list, keycode | SHARED_GRAB, cnt);
764 _free_list_of_grabbed_key(key_list);
771 _unset_exclusive_grab_info_to_root(disp, keycode, OR_EXCLUSIVE_GRAB);
776 _unset_exclusive_grab_info_to_root(disp, keycode, EXCLUSIVE_GRAB);
779 new_key_list = _del_grabbed_key(key_list, i, &cnt);
780 _free_list_of_grabbed_key(key_list);
783 XChangeProperty(disp, win, _atom_grab_key, XA_CARDINAL, 32,
784 PropModeReplace, (unsigned char *)new_key_list, cnt);
787 XDeleteProperty(disp, win, _atom_grab_key);
791 _free_new_list_of_grabbed_key(new_key_list);
800 API Utilx_Key_Status utilx_get_key_status(Display* dpy, char *key_name)
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;
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) )
824 KeySym ks = XStringToKeysym(key_name);
825 KeyCode kc = XKeysymToKeycode(dpy, ks);
829 XQueryKeymap(dpy, (char *)keymap);
830 if( keymap[kc >> 3] & masktable[kc & 7] )
831 status = UTILX_KEY_STATUS_PRESSED;
833 status = UTILX_KEY_STATUS_RELEASED;
840 API void utilx_set_window_effect_state(Display* dpy, Window win, int state)
844 fprintf (stderr, "[UTILX] Error.. Invald Display.. %s (%d)\n", __func__, __LINE__);
847 if( !_atom_comp_effect_state)
848 _atom_comp_effect_state = XInternAtom(dpy, "_NET_CM_WINDOW_EFFECT_ENABLE",False);
850 _utilx_set_window_property(dpy, win, _atom_comp_effect_state, XA_CARDINAL, (unsigned int *)&state, 1);
855 API int utilx_get_window_effect_state(Display* dpy, Window win)
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);
865 _utilx_string_set_window_property( Display *dpy, Window win, Atom atom, char *val, unsigned int num)
867 XChangeProperty( dpy, win, atom, XA_STRING, 8, PropModeReplace, (unsigned char*)val, val ? strlen(val):0 );
870 API void utilx_set_fake_launch_img(Display* dpy, Window win, char *file_name)
872 //UTILX_TRACE ("[UTILX] utilx_set_effect_state... win = %x, show_state = %d\n", win, enable);
876 fprintf (stderr, "[UTILX] Error.. Invald Display.. %s (%d)\n", __func__, __LINE__);
879 if( !_atom_comp_fake_launch_image)
880 _atom_comp_fake_launch_image = XInternAtom(dpy, "_E_COMP_FAKE_LAUNCH_IMAGE",False);
882 _utilx_string_set_window_property(dpy, win, _atom_comp_fake_launch_image, file_name, 1);
885 API void utilx_show_fake_effect( Display *dpy, Window win, char *fake_image_file )
889 _atom_comp_fake_launch = XInternAtom( dpy, "_E_COMP_FAKE_LAUNCH", False );
891 if( !_atom_comp_fake_launch )
893 fprintf( stderr, "XInternAtom(_E_COMP_FAKE_LAUNCH) failed.\n" );
897 utilx_set_fake_launch_img(dpy, win, fake_image_file);
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;
913 XSendEvent( dpy, win, False,
914 SubstructureRedirectMask | SubstructureNotifyMask,
921 API void utilx_hide_fake_effect( Display *dpy, Window win)
925 _atom_comp_fake_launch = XInternAtom( dpy, "_E_COMP_FAKE_LAUNCH", False );
926 if( !_atom_comp_fake_launch )
928 fprintf( stderr, "XInternAtom(_E_COMP_FAKE_LAUNCH) failed.\n" );
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;
944 XSendEvent( dpy, win, False,
945 SubstructureRedirectMask | SubstructureNotifyMask,
950 static void _utilx_effect_atom_check( Display* dpy )
954 fprintf (stderr, "[UTILX] Error.. Invald Display.. %s (%d)\n", __func__, __LINE__);
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);
986 static Atom _utilx_convert_style_to_atom( Display* dpy, Utilx_Effect_Style style )
990 fprintf (stderr, "[UTILX] Error.. Invald Display.. %s (%d)\n", __func__, __LINE__);
991 return _atom_comp_effect_none;
993 _utilx_effect_atom_check(dpy);
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;
1011 static Utilx_Effect_Style _utilx_convert_atom_to_style( Display* dpy, Atom style )
1015 fprintf (stderr, "[UTILX] Error.. Invald Display.. %s (%d)\n", __func__, __LINE__);
1016 return UTILX_EFFECT_STYLE_NONE;
1018 _utilx_effect_atom_check(dpy);
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;
1035 API void utilx_set_window_effect_style(Display* dpy, Window win, Utilx_Effect_Type type, Utilx_Effect_Style style)
1037 Atom *window_effect_type_list = NULL;
1040 fprintf (stderr, "[UTILX] Error.. Invald Display.. %s (%d)\n", __func__, __LINE__);
1043 _utilx_effect_atom_check(dpy);
1045 window_effect_type_list = (Atom *)malloc(sizeof(Atom) * 6);
1047 if ( !window_effect_type_list )
1049 fprintf (stderr, "[UTILX] Error.. malloc().. %s (%d)\n", __func__, __LINE__);
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;
1060 _utilx_get_window_property(dpy, win, _atom_comp_window_effect_type, XA_ATOM, (unsigned int *)window_effect_type_list, 6);
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);
1069 _utilx_set_window_property(dpy, win, _atom_comp_window_effect_type, XA_ATOM, (unsigned int *)window_effect_type_list, 6);
1072 free(window_effect_type_list);
1075 API Utilx_Effect_Style utilx_get_window_effect_style(Display* dpy, Window win, Utilx_Effect_Type type)
1077 Atom *window_effect_type_list = NULL;
1078 Utilx_Effect_Style style = UTILX_EFFECT_STYLE_DEFAULT;
1082 fprintf (stderr, "[UTILX] Error.. Invald Display.. %s (%d)\n", __func__, __LINE__);
1083 return UTILX_EFFECT_STYLE_NONE;
1085 _utilx_effect_atom_check(dpy);
1087 window_effect_type_list = (Atom *)malloc(sizeof(Atom) * 6);
1089 if ( !window_effect_type_list )
1091 fprintf (stderr, "[UTILX] Error.. malloc().. %s (%d)\n", __func__, __LINE__);
1092 return UTILX_EFFECT_STYLE_NONE;
1095 if ( _utilx_get_window_property(dpy, win, _atom_comp_window_effect_type, XA_ATOM, (unsigned int *)window_effect_type_list, 6) != 6 )
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;
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]);
1110 free(window_effect_type_list);
1114 API int utilx_set_window_opaque_state (Display* dpy, Window win, Utilx_Opaque_State state)
1116 UTILX_TRACE ("[UTILX] utilx_set_window_opaque_state... win = %x, show_state = %d\n", win, state);
1118 unsigned int is_opaque;
1122 fprintf (stderr, "[UTILX] Error.. Invald Display.. %s (%d)\n", __func__, __LINE__);
1128 case UTILX_OPAQUE_STATE_OFF:
1132 case UTILX_OPAQUE_STATE_ON:
1137 fprintf (stderr, "[UTILX] Error.. Invald State.. %s (%d)\n", __func__, __LINE__);
1141 if (!_atom_window_opaque)
1143 _atom_window_opaque = XInternAtom (dpy, "_E_ILLUME_WINDOW_REGION_OPAQUE", False);
1144 if (!_atom_window_opaque)
1146 fprintf (stderr, "[UTILX] Error.. Cannot create _E_ILLUME_WINDOW_REGION_OPAQUE atom.. %s (%d)\n", __func__, __LINE__);
1151 _utilx_set_window_property (dpy, win, _atom_window_opaque, XA_CARDINAL,
1152 (unsigned int *)&is_opaque, 1);
1158 _utilx_screen_capture_atom_ensure (Display* dpy)
1160 if (_atom_screen_capture_disable)
1163 _atom_screen_capture_disable = XInternAtom (dpy, "_CB_SCREEN_CAPTURE_DISABLE", False);
1164 if (_atom_screen_capture_disable)
1167 fprintf (stderr, "[UTILX] Error.. Cannot create _CB_SCREEN_CAPTURE_DISABLE atom.. %s (%d)\n", __func__, __LINE__);
1171 utilx_set_screen_capture(Display* dpy, int enable)
1178 fprintf (stderr, "[UTILX] Error.. dpy is NULL %s (%d)\n", __func__, __LINE__);
1182 root = RootWindow (dpy, DefaultScreen(dpy));
1183 disable = (enable) ? 0 : 1;
1185 _utilx_screen_capture_atom_ensure (dpy);
1187 _utilx_set_window_property (dpy, root, _atom_screen_capture_disable, XA_CARDINAL, (unsigned int *)&disable, 1);
1193 utilx_get_screen_capture(Display* dpy)
1200 fprintf (stderr, "[UTILX] Error.. dpy is NULL %s (%d)\n", __func__, __LINE__);
1204 root = RootWindow (dpy, DefaultScreen(dpy));
1206 _utilx_screen_capture_atom_ensure (dpy);
1208 _utilx_get_window_property(dpy, root, _atom_screen_capture_disable, XA_CARDINAL,
1209 (unsigned int *)&disable, 1);
1211 return (disable) ? 0 : 1;
1214 API void utilx_set_window_cardinal_property(Display* dpy, Window win, Atom atom, unsigned int *value)
1216 _utilx_set_window_property(dpy, win, atom, XA_CARDINAL, value, 1);
1219 API int utilx_get_window_cardinal_property (Display* dpy, Window win, Atom atom, unsigned int *value)
1221 return _utilx_get_window_property(dpy, win, atom, XA_CARDINAL, value, 1);
1224 API void utilx_show_capture_effect( Display *dpy, Window win)
1228 _atom_comp_capture_effect = XInternAtom( dpy, "_E_COMP_CAPTURE_EFFECT", False );
1229 if( !_atom_comp_capture_effect )
1231 fprintf( stderr, "XInternAtom(_E_COMP_CAPTURE_EFFECT) failed.\n" );
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;
1247 XSendEvent( dpy, win, False,
1248 SubstructureRedirectMask | SubstructureNotifyMask,