remove manifest for security domain policy
[platform/core/uifw/libslp-utilx.git] / x11.c
diff --git a/x11.c b/x11.c
index 46aaee7..2dfc23a 100644 (file)
--- a/x11.c
+++ b/x11.c
@@ -30,6 +30,7 @@
 #include <X11/extensions/Xrandr.h>
 
 #include "utilX.h"
+#include "utilX_ext.h"
 #include "util_x11.h"
 
 #include <fcntl.h>
 #include <X11/extensions/Xvproto.h>
 #include <X11/extensions/Xdamage.h>
 #include <X11/extensions/XShm.h>
+#include <X11/Xresource.h>
 #include <xf86drm.h>
 #include <tbm_bufmgr.h>
 #include <dri2.h>
 
-
 #define UTILX_DEBUG 0
 #if UTILX_DEBUG
 #define UTILX_TRACE  printf
@@ -54,44 +55,18 @@ static Atom _atom_grab_excl_win = None;
 static Atom _atom_grab_or_excl_win = None;
 
 static Atom _atom_notification_level = None;
-static Atom _atom_indicator_visible_state = None;
-static Atom _atom_indicator_visible_state_on = None;
-static Atom _atom_indicator_visible_state_off = None;
 
-static Atom _atom_comp_effect_state = None;
-static Atom _atom_comp_fake_launch = None;
 static Atom _atom_comp_fake_launch_image = None;
 
-static Atom _atom_comp_window_effect_type = None;
-static Atom _atom_comp_effect_default = None;
-static Atom _atom_comp_effect_none = None;
-static Atom _atom_comp_effect_custom0 = None;
-static Atom _atom_comp_effect_custom1 = None;
-static Atom _atom_comp_effect_custom2 = None;
-static Atom _atom_comp_effect_custom3 = None;
-static Atom _atom_comp_effect_custom4 = None;
-static Atom _atom_comp_effect_custom5 = None;
-static Atom _atom_comp_effect_custom6 = None;
-static Atom _atom_comp_effect_custom7 = None;
-static Atom _atom_comp_effect_custom8 = None;
-static Atom _atom_comp_effect_custom9 = None;
-
 static Atom _atom_window_opaque = None;
 
-static Atom _atom_screen_capture_disable = None;
-
-static Atom _atom_comp_capture_effect = None;
+static Atom _atom_window_pixman = None;
 
 const unsigned long maxlen = 1024l;
 
 static void _utilx_set_window_property (Display* dpy, Window win, Atom atom, Atom type, unsigned int *val, unsigned int num);
 static int _utilx_get_window_property (Display* dpy, Window win, Atom atom, Atom type, unsigned int *val, unsigned int len);
 
-static void _utilx_effect_atom_check( Display* dpy );
-static Atom _utilx_convert_style_to_atom( Display* dpy, Utilx_Effect_Style style );
-static Utilx_Effect_Style _utilx_convert_atom_to_style( Display* dpy, Atom style );
-
-static int _utilx_get_indicator_atoms(Display *dpy);
 
 API void utilx_set_system_notification_level (Display* dpy, Window win, Utilx_Notification_Level level)
 {
@@ -198,105 +173,6 @@ error:
        return noti_level;
 }
 
-static int _utilx_get_indicator_atoms(Display *dpy)
-{
-       if (!_atom_indicator_visible_state)
-       {
-               _atom_indicator_visible_state = XInternAtom (dpy, "_E_ILLUME_INDICATOR_STATE", False);
-               if (!_atom_indicator_visible_state)
-               {
-                       fprintf (stderr, "[UTILX] Error.. Cannot create _E_ILLUME_INDICATOR_STATE atom.. %s (%d)\n", __func__, __LINE__);
-                       return 0;
-               }
-       }
-
-       if (!_atom_indicator_visible_state_on)
-       {
-               _atom_indicator_visible_state_on = XInternAtom (dpy, "_E_ILLUME_INDICATOR_ON", False);
-               if (!_atom_indicator_visible_state_on)
-               {
-                       fprintf (stderr, "[UTILX] Error.. Cannot create _E_ILLUME_INDICATOR_ON atom.. %s (%d)\n", __func__, __LINE__);
-                       return 0;
-               }
-       }
-
-       if (!_atom_indicator_visible_state_off)
-       {
-               _atom_indicator_visible_state_off = XInternAtom (dpy, "_E_ILLUME_INDICATOR_OFF", False);
-               if (!_atom_indicator_visible_state_off)
-               {
-                       fprintf (stderr, "[UTILX] Error.. Cannot create _E_ILLUME_INDICATOR_OFF atom.. %s (%d)\n", __func__, __LINE__);
-                       return 0;
-               }
-       }
-
-       return 1;
-}
-
-API void utilx_enable_indicator (Display* dpy, Window win, int enable)
-{
-       UTILX_TRACE ("[UTILX] utilx_indicator_set_visible_state... win = %x, show_state = %d\n", win, enable);
-
-       if (dpy == NULL)
-       {
-               fprintf (stderr, "[UTILX] Error.. Invald Display.. %s (%d)\n", __func__, __LINE__);
-               return;
-       }
-
-       if (!_utilx_get_indicator_atoms(dpy))
-       {
-               fprintf (stderr, "[UTILX] Error.. Cannot create atoms.. %s (%d)\n", __func__, __LINE__);
-               return;
-       }
-
-       if (enable == 1)
-       {
-               _utilx_set_window_property (dpy, win, _atom_indicator_visible_state, XA_ATOM,
-                       (unsigned int *)&_atom_indicator_visible_state_on, 1);
-       }
-       else
-       {
-               _utilx_set_window_property (dpy, win, _atom_indicator_visible_state, XA_ATOM,
-                       (unsigned int *)&_atom_indicator_visible_state_off, 1);
-       }
-}
-
-
-API int utilx_get_indicator_state (Display* dpy, Window win)
-{
-       UTILX_TRACE ("[UTILX] utilx_indicator_set_visible_state... win = %x, show_state = %d\n", win, enable);
-
-       int ret;
-       Atom state;
-
-       if (dpy == NULL)
-       {
-               fprintf (stderr, "[UTILX] Error.. Invald Display.. %s (%d)\n", __func__, __LINE__);
-               return -1;
-       }
-
-       if (!_utilx_get_indicator_atoms(dpy))
-       {
-               fprintf (stderr, "[UTILX] Error.. Cannot create atoms.. %s (%d)\n", __func__, __LINE__);
-               return -1;
-       }
-
-       ret = _utilx_get_window_property (dpy, win, _atom_indicator_visible_state, XA_ATOM,
-                       (unsigned int *)&state, 1);
-
-       if (ret > 0)
-       {
-               if (state == _atom_indicator_visible_state_on)
-                       return 1;
-               else if (state == _atom_indicator_visible_state_off)
-                       return 0;
-               else
-                       return -1;
-       }
-       else
-               return -1;
-}
-
 static void
 _utilx_set_window_property (Display* dpy, Window win, Atom atom, Atom type, unsigned int *val, unsigned int num)
 {
@@ -466,10 +342,6 @@ static void _set_exclusive_grab_info_to_root (Display *disp, int keycode, Window
                goto out;
        }
 
-#ifdef __DEBUG__
-       printf("[%s] keycode = %d\n", __FUNCTION__, keycode);
-#endif
-
        for( i=0 ; i < nr_item ; i++ )
        {
                if( key_list && (key_list[i] == keycode) )
@@ -481,6 +353,7 @@ static void _set_exclusive_grab_info_to_root (Display *disp, int keycode, Window
        XSync(disp, False);
 
 out:
+       _free_list_of_grabbed_key(key_list);
        return;
 }
 
@@ -523,7 +396,6 @@ static void _unset_exclusive_grab_info_to_root (Display *disp, int keycode, int
 
        if (nr_item == 0)
        {
-               fprintf(stderr, "\e[32m[utilX][%s] keycode = %d\e[0m\n", __FUNCTION__, keycode);
                goto out;
        }
 
@@ -536,10 +408,6 @@ static void _unset_exclusive_grab_info_to_root (Display *disp, int keycode, int
                cnt++;
        }
 
-#ifdef __DEBUG__
-       fprintf(stderr, "[utilX][%s] cnt = %d, nr_item = %d\n", __FUNCTION__, cnt, nr_item);
-#endif
-
        if( 0 < cnt )
        {
                new_key_list = malloc(sizeof(int)*cnt);
@@ -575,10 +443,10 @@ static void _unset_exclusive_grab_info_to_root (Display *disp, int keycode, int
        }
        XSync(disp, False);
 
-       if(new_key_list)
-               free(new_key_list);
+       _free_new_list_of_grabbed_key(new_key_list);
 
 out:
+       _free_list_of_grabbed_key(key_list);
        return;
 }
 
@@ -621,18 +489,190 @@ static int _is_grabbed_key_exclusively (Display* disp, int keycode, int grab_mod
        for( i=0 ; i < nr_item ; i++ )
        {
                if( key_list[i] == keycode )
+        {
+               _free_list_of_grabbed_key(key_list);
                        return EXCLUSIVE_GRABBED_ALREADY;
+        }
        }
 
 out:
+       _free_list_of_grabbed_key(key_list);
        return result;
 }
 
+#ifndef SYSCONFDIR
+#define SYSCONFDIR "/etc/"
+#endif
+#define KEYMAP_FILE    SYSCONFDIR"/X11/xkeysymbol.map"
+#define is_space(c) ((c)==' '||(c)=='\t'||(c) =='\n')
+
+typedef struct _Symbol_Entry
+{
+       char name[64];
+       char symbol[64];
+       XrmQuark quark;
+       struct _Symbol_Entry *next;
+} Symbol_Entry;
+
+static Symbol_Entry *symbol_list;
+static int symbol_list_len;
+
+static char*
+_utilx_strip_whitespace(char *s)
+{
+    int i;
+
+    while (s[0] && is_space(s[0]))
+        s++;
+
+    i = strlen(s) - 1;
+    while (i >= 0 && is_space(s[i]))
+        s[i--] = 0;
+
+    return s;
+}
+
+static int
+_utilx_check_key_symbol_list (char *path)
+{
+       FILE *f;
+    char *stripped, *comma, *key, *value;
+    char buf[256];
+       int line;
+       Symbol_Entry *cursor;
+
+       if (symbol_list)
+               return 1;
+
+       f = fopen(path, "r");
+       if (!f) {
+        fprintf (stderr, "[utilx] '%s' open failed: %s\n", path, strerror(errno));
+               return 0;
+       }
+
+       line = 0;
+       symbol_list_len = 0;
+
+       cursor = NULL;
+    while (fgets(buf, sizeof(buf), f)) {
+               Symbol_Entry *entry;
+
+        line++;
+
+        stripped = _utilx_strip_whitespace (buf);
+        if (stripped[0] == '#' || stripped[0] == 0)
+            continue;
+
+        comma = strchr(stripped, ',');
+        if (!comma)
+               {
+            fprintf(stderr, "[utilx] Syntax error at %s line %d\n", path, line);
+            continue;
+        }
+
+        *comma = 0;
+        key   = _utilx_strip_whitespace (stripped);
+        value = _utilx_strip_whitespace (comma + 1);
+        if (!key[0])
+               {
+            fprintf (stderr, "[utilx] Missing key at %s line %d\n", path, line);
+            continue;
+        }
+        if (!value[0])
+               {
+            fprintf (stderr, "[utilx] Missing value at %s line %d\n", path, line);
+            continue;
+        }
+
+               entry = calloc (1, sizeof (Symbol_Entry));
+               if (!entry)
+                       continue;
+
+               symbol_list_len++;
+
+               if (!symbol_list)
+                       cursor = symbol_list = entry;
+               else if (cursor)
+               {
+                       cursor->next = entry;
+                       cursor = entry;
+               }
+
+               snprintf (entry->name, sizeof (entry->name), "%s", key);
+               snprintf (entry->symbol, sizeof (entry->symbol), "%s", value);
+
+               entry->quark = XrmStringToQuark (key);
+    }
+
+       fclose(f);
+
+       return 1;
+}
+
+API const char** utilx_get_available_key_names (int *count)
+{
+       char **names;
+       Symbol_Entry *entry;
+       int i;
+
+       if (!count)
+       {
+               fprintf(stderr, "[%s] 'count' param is NULL.\n", __FUNCTION__);
+               return NULL;
+       }
+
+       *count = 0;
+
+       if (!_utilx_check_key_symbol_list (KEYMAP_FILE))
+               return NULL;
+
+       names = calloc (symbol_list_len, sizeof (char*));
+       if (!names)
+       {
+               fprintf(stderr, "[%s] calloc failed.\n", __FUNCTION__);
+               return NULL;
+       }
+
+       *count = symbol_list_len;
+
+       i = 0;
+       entry = symbol_list;
+       while (entry && i < symbol_list_len)
+       {
+               names[i++] = entry->name;
+               entry = entry->next;
+       }
+
+       return (const char**)names;
+}
+
+API const char* utilx_get_key_symbol (const char *key_name)
+{
+       Symbol_Entry *entry;
+       XrmQuark quark;
+
+       if (!_utilx_check_key_symbol_list (KEYMAP_FILE))
+               return NULL;
+
+       quark = XrmStringToQuark (key_name);
+       entry = symbol_list;
+
+       while (entry)
+       {
+               if (entry->quark == quark)
+                       return (const char*)entry->symbol;
+
+               entry = entry->next;
+       }
+
+       return NULL;
+}
+
 API int utilx_grab_key (Display* disp, Window win, const char* key, int grab_mode)
 {
        unsigned long cnt;
        int *key_list = NULL;
-       int i, result = 0;
+       int i, result=0, ret = 0;
        int keycode = 0;
        KeySym keysym;
        errno = EINVAL;
@@ -643,6 +683,12 @@ API int utilx_grab_key (Display* disp, Window win, const char* key, int grab_mod
                return -1;
        }
 
+       if( NULL == key )
+       {
+               fprintf(stderr, "[%s] key is NULL\n", __FUNCTION__);
+               return -1;
+       }
+
        if (_atom_grab_key == None) {
                _atom_grab_key = XInternAtom(disp, STR_ATOM_GRAB_KEY, False);
        }
@@ -661,27 +707,11 @@ API int utilx_grab_key (Display* disp, Window win, const char* key, int grab_mod
                //Window grabWin;
                result = _is_grabbed_key_exclusively(disp, keycode, grab_mode);
 
-#ifdef __DEBUG__
-               printf("[%s] _is_grabbed_key_exclusively returns result = %d\n", __FUNCTION__, result);
-#endif
-
                if( result )
                {
-                       fprintf(stderr, "[%s] keycode(%d) was already grabbed exclusively (grab_mode=0x%X) !\n", __FUNCTION__, keycode, grab_mode);
                        goto out;
                }
        }
-       else if( grab_mode == OR_EXCLUSIVE_GRAB )
-       {
-               result = _is_grabbed_key_exclusively(disp, keycode, grab_mode);
-
-               if( result )
-               {
-                       fprintf(stderr, "[%s] Keycode(%d) was already grabbed with overridable exclusive mode (grab_mode=0x%x)\n", __FUNCTION__, keycode, grab_mode);
-                       fprintf(stderr, "[%s] Now it will be overridden by a new window(0x%x) !\n", __FUNCTION__, win);
-                       utilx_ungrab_key(disp, win, key);
-               }
-       }
 
        keycode |= grab_mode;
 
@@ -690,15 +720,8 @@ API int utilx_grab_key (Display* disp, Window win, const char* key, int grab_mod
                i = _search_grabbed_key(key_list, keycode, cnt);
                _free_list_of_grabbed_key(key_list);
                if ( i != -1 ) {
-                       if( grab_mode == OR_EXCLUSIVE_GRAB )
-                       {
-                               utilx_ungrab_key(disp, win, key);
-                       }
-                       else
-                       {
                        fprintf(stderr, "Key is already grabbed\n");
                        goto out;
-                       }
                }
        }
 
@@ -706,12 +729,18 @@ API int utilx_grab_key (Display* disp, Window win, const char* key, int grab_mod
                        cnt ? PropModeAppend : PropModeReplace, (unsigned char *)&keycode, 1);
        XSync(disp, False);
        keycode = keycode & (~GRAB_MODE_MASK);
-#ifdef __DEBUG__
-       printf("[%s] keycode = %d\n", __FUNCTION__, keycode);
-#endif
 
-       if( EXCLUSIVE_GRAB == grab_mode || OR_EXCLUSIVE_GRAB == grab_mode )
+       if( EXCLUSIVE_GRAB == grab_mode )
                _set_exclusive_grab_info_to_root(disp, keycode, win, grab_mode);
+       if( OR_EXCLUSIVE_GRAB == grab_mode )
+       {
+               ret = _is_grabbed_key_exclusively(disp, keycode, grab_mode);
+
+               if( !ret )
+               {
+                       _set_exclusive_grab_info_to_root(disp, keycode, win, grab_mode);
+               }
+       }
 
        errno = 0;
 
@@ -738,6 +767,12 @@ API int utilx_ungrab_key (Display* disp, Window win, const char* key)
                return -1;
        }
 
+       if( NULL == key )
+       {
+               fprintf(stderr, "[%s] key is NULL\n", __FUNCTION__);
+               return -1;
+       }
+
        if (_atom_grab_key == None) {
                _atom_grab_key = XInternAtom(disp, STR_ATOM_GRAB_KEY, False);
        }
@@ -779,10 +814,6 @@ API int utilx_ungrab_key (Display* disp, Window win, const char* key)
                                }
                        }
                }
-               else
-               {
-                       _unset_exclusive_grab_info_to_root(disp, keycode, OR_EXCLUSIVE_GRAB);
-               }
        }
        else
        {
@@ -810,70 +841,6 @@ out:
        return ret;
 }
 
-API Utilx_Key_Status utilx_get_key_status(Display* dpy, char *key_name)
-{
-       unsigned char keymap[32];
-       static unsigned int masktable[8] = { 0x01, 0x02, 0x04, 0x08, 0x10, 0x20, 0x40, 0x80 };
-       Utilx_Key_Status status = UTILX_KEY_STATUS_UNKNOWN;
-
-       if( !strncmp(key_name, KEY_VOLUMEDOWN, LEN_KEY_VOLUMEDOWN) ||
-               !strncmp(key_name, KEY_VOLUMEUP, LEN_KEY_VOLUMEUP) ||
-               !strncmp(key_name, KEY_PAUSE, LEN_KEY_PAUSE) ||
-               !strncmp(key_name, KEY_SEND, LEN_KEY_SEND) ||
-               !strncmp(key_name, KEY_SELECT, LEN_KEY_VOLUMEDOWN) ||
-               !strncmp(key_name, KEY_END, LEN_KEY_END) ||
-               !strncmp(key_name, KEY_POWER, LEN_KEY_POWER) ||
-               !strncmp(key_name, KEY_CAMERA, LEN_KEY_CAMERA) ||
-               !strncmp(key_name, KEY_CONFIG, LEN_KEY_CONFIG) ||
-               !strncmp(key_name, KEY_PLAYCD, LEN_KEY_PLAYCD) ||
-               !strncmp(key_name, KEY_STOPCD, LEN_KEY_STOPCD) ||
-               !strncmp(key_name, KEY_PAUSECD, LEN_KEY_PAUSECD) ||
-               !strncmp(key_name, KEY_NEXTSONG, LEN_KEY_NEXTSONG) ||
-               !strncmp(key_name, KEY_PREVIOUSSONG, LEN_KEY_PREVIOUSSONG) ||
-               !strncmp(key_name, KEY_REWIND, LEN_KEY_REWIND) ||
-               !strncmp(key_name, KEY_FASTFORWARD, LEN_KEY_FASTFORWARD) ||
-               !strncmp(key_name, KEY_MEDIA, LEN_KEY_MEDIA) )
-       {
-               KeySym ks = XStringToKeysym(key_name);
-               KeyCode kc = XKeysymToKeycode(dpy, ks);
-
-               if( kc )
-               {
-                       XQueryKeymap(dpy, (char *)keymap);
-                       if( keymap[kc >> 3] & masktable[kc & 7] )
-                               status = UTILX_KEY_STATUS_PRESSED;
-                       else
-                               status = UTILX_KEY_STATUS_RELEASED;
-               }
-       }
-
-       return status;
-}
-
-API void utilx_set_window_effect_state(Display* dpy, Window win, int state)
-{
-       if ( dpy == NULL )
-       {
-               fprintf (stderr, "[UTILX] Error.. Invald Display.. %s (%d)\n", __func__, __LINE__);
-               return;
-       }
-       if( !_atom_comp_effect_state)
-               _atom_comp_effect_state = XInternAtom(dpy, "_NET_CM_WINDOW_EFFECT_ENABLE",False);
-
-       _utilx_set_window_property(dpy, win, _atom_comp_effect_state, XA_CARDINAL, (unsigned int *)&state, 1);
-
-       XSync(dpy, 0 );
-}
-
-API int utilx_get_window_effect_state(Display* dpy, Window win)
-{
-       int state = 0;
-       if( !_atom_comp_effect_state)
-               _atom_comp_effect_state = XInternAtom(dpy, "_NET_CM_WINDOW_EFFECT_ENABLE",False);
-       _utilx_get_window_property(dpy, win, _atom_comp_effect_state, XA_CARDINAL, (unsigned int *)&state, 1);
-       return state;
-}
-
 static void
 _utilx_string_set_window_property( Display *dpy, Window win, Atom atom, char *val, unsigned int num)
 {
@@ -895,270 +862,41 @@ API void utilx_set_fake_launch_img(Display* dpy, Window win, char *file_name)
        _utilx_string_set_window_property(dpy, win, _atom_comp_fake_launch_image, file_name, 1);
 }
 
-API void utilx_show_fake_effect( Display *dpy, Window win, char *fake_image_file )
+API int utilx_set_window_opaque_state (Display* dpy, Window win, Utilx_Opaque_State state)
 {
-       XEvent xev;
+       UTILX_TRACE ("[UTILX] utilx_set_window_opaque_state... win = %x, show_state = %d\n", win, state);
 
-       _atom_comp_fake_launch = XInternAtom( dpy, "_E_COMP_FAKE_LAUNCH", False );
+       unsigned int is_opaque;
 
-       if(  !_atom_comp_fake_launch )
+       if (dpy == NULL)
        {
-               fprintf( stderr, "XInternAtom(_E_COMP_FAKE_LAUNCH) failed.\n" );
-               return;
+               fprintf (stderr, "[UTILX] Error.. Invald Display.. %s (%d)\n", __func__, __LINE__);
+               return 0;
        }
 
-       utilx_set_fake_launch_img(dpy, win, fake_image_file);
-
-       XSync(dpy, 0 );
-
-       // send fake client message
-       xev.xclient.type = ClientMessage;
-       xev.xclient.display = dpy;
-       xev.xclient.window = win;
-       xev.xclient.message_type =  _atom_comp_fake_launch;
-       xev.xclient.format = 32;
-       xev.xclient.data.l[0] = 1;  // 1 : start effect , 0 : end effect
-       xev.xclient.data.l[1] = 0;
-       xev.xclient.data.l[2] = 0;
-       xev.xclient.data.l[3] = 0;
-       xev.xclient.data.l[4] = 0;
-
-       XSendEvent( dpy, win, False,
-                               SubstructureRedirectMask | SubstructureNotifyMask,
-                               &xev );
-       XSync(dpy, 0 );
-
-}
+       switch (state)
+       {
+               case UTILX_OPAQUE_STATE_OFF:
+                       is_opaque = 0;
+                       break;
 
+               case UTILX_OPAQUE_STATE_ON:
+                       is_opaque = 1;
+                       break;
 
-API void utilx_hide_fake_effect( Display *dpy, Window win)
-{
-       XEvent xev;
+               default:
+                       fprintf (stderr, "[UTILX] Error.. Invald State.. %s (%d)\n", __func__, __LINE__);
+                       return 0;
+       }
 
-       _atom_comp_fake_launch = XInternAtom( dpy, "_E_COMP_FAKE_LAUNCH", False );
-       if(  !_atom_comp_fake_launch )
+       if (!_atom_window_opaque)
        {
-               fprintf( stderr, "XInternAtom(_E_COMP_FAKE_LAUNCH) failed.\n" );
-               return;
-       }
-
-       // send fake client message
-       xev.xclient.type = ClientMessage;
-       xev.xclient.display = dpy;
-       xev.xclient.window = win;
-       xev.xclient.message_type =  _atom_comp_fake_launch;
-       xev.xclient.format = 32;
-       xev.xclient.data.l[0] = 0;  // 1 : start effect , 0 : end effect
-       xev.xclient.data.l[1] = 0;
-       xev.xclient.data.l[2] = 0;
-       xev.xclient.data.l[3] = 0;
-       xev.xclient.data.l[4] = 0;
-
-       XSendEvent( dpy, win, False,
-                               SubstructureRedirectMask | SubstructureNotifyMask,
-                               &xev );
-       XSync(dpy, 0 );
-}
-
-static void _utilx_effect_atom_check( Display* dpy )
-{
-       if ( dpy == NULL )
-       {
-               fprintf (stderr, "[UTILX] Error.. Invald Display.. %s (%d)\n", __func__, __LINE__);
-               return;
-       }
-
-       if( !_atom_comp_window_effect_type)
-               _atom_comp_window_effect_type =  XInternAtom(dpy, "_NET_CM_WINDOW_EFFECT_TYPE",False);
-       if( !_atom_comp_effect_default )
-               _atom_comp_effect_default = XInternAtom(dpy, "_NET_CM_EFFECT_DEFAULT",False);
-       if( !_atom_comp_effect_none )
-               _atom_comp_effect_none = XInternAtom(dpy, "_NET_CM_EFFECT_NONE",False);
-       if( !_atom_comp_effect_custom0 )
-               _atom_comp_effect_custom0 = XInternAtom(dpy, "_NET_CM_EFFECT_CUSTOM0",False);
-       if( !_atom_comp_effect_custom1 )
-               _atom_comp_effect_custom1 = XInternAtom(dpy, "_NET_CM_EFFECT_CUSTOM1",False);
-       if( !_atom_comp_effect_custom2 )
-               _atom_comp_effect_custom2 = XInternAtom(dpy, "_NET_CM_EFFECT_CUSTOM2",False);
-       if( !_atom_comp_effect_custom3 )
-               _atom_comp_effect_custom3 = XInternAtom(dpy, "_NET_CM_EFFECT_CUSTOM3",False);
-       if( !_atom_comp_effect_custom4 )
-               _atom_comp_effect_custom4 = XInternAtom(dpy, "_NET_CM_EFFECT_CUSTOM4",False);
-       if( !_atom_comp_effect_custom5 )
-               _atom_comp_effect_custom5 = XInternAtom(dpy, "_NET_CM_EFFECT_CUSTOM5",False);
-       if( !_atom_comp_effect_custom6 )
-               _atom_comp_effect_custom6 = XInternAtom(dpy, "_NET_CM_EFFECT_CUSTOM6",False);
-       if( !_atom_comp_effect_custom7 )
-               _atom_comp_effect_custom7 = XInternAtom(dpy, "_NET_CM_EFFECT_CUSTOM7",False);
-       if( !_atom_comp_effect_custom8 )
-               _atom_comp_effect_custom8 = XInternAtom(dpy, "_NET_CM_EFFECT_CUSTOM8",False);
-       if( !_atom_comp_effect_custom9 )
-               _atom_comp_effect_custom9 = XInternAtom(dpy, "_NET_CM_EFFECT_CUSTOM9",False);
-}
-
-static Atom _utilx_convert_style_to_atom( Display* dpy, Utilx_Effect_Style style )
-{
-       if ( dpy == NULL )
-       {
-               fprintf (stderr, "[UTILX] Error.. Invald Display.. %s (%d)\n", __func__, __LINE__);
-               return _atom_comp_effect_none;
-       }
-       _utilx_effect_atom_check(dpy);
-
-       if ( style == UTILX_EFFECT_STYLE_DEFAULT )       return _atom_comp_effect_default;
-       else if ( style == UTILX_EFFECT_STYLE_NONE )     return _atom_comp_effect_none;
-       else if ( style == UTILX_EFFECT_STYLE_CUSTOM0 )  return _atom_comp_effect_custom0;
-       else if ( style == UTILX_EFFECT_STYLE_CUSTOM1 )  return _atom_comp_effect_custom1;
-       else if ( style == UTILX_EFFECT_STYLE_CUSTOM2 )  return _atom_comp_effect_custom2;
-       else if ( style == UTILX_EFFECT_STYLE_CUSTOM3 )  return _atom_comp_effect_custom3;
-       else if ( style == UTILX_EFFECT_STYLE_CUSTOM4 )  return _atom_comp_effect_custom4;
-       else if ( style == UTILX_EFFECT_STYLE_CUSTOM5 )  return _atom_comp_effect_custom5;
-       else if ( style == UTILX_EFFECT_STYLE_CUSTOM6 )  return _atom_comp_effect_custom6;
-       else if ( style == UTILX_EFFECT_STYLE_CUSTOM7 )  return _atom_comp_effect_custom7;
-       else if ( style == UTILX_EFFECT_STYLE_CUSTOM8 )  return _atom_comp_effect_custom8;
-       else if ( style == UTILX_EFFECT_STYLE_CUSTOM9 )  return _atom_comp_effect_custom9;
-       else                                             return _atom_comp_effect_none;
-
-}
-
-static Utilx_Effect_Style _utilx_convert_atom_to_style( Display* dpy, Atom style )
-{
-       if ( dpy == NULL )
-       {
-               fprintf (stderr, "[UTILX] Error.. Invald Display.. %s (%d)\n", __func__, __LINE__);
-               return UTILX_EFFECT_STYLE_NONE;
-       }
-       _utilx_effect_atom_check(dpy);
-
-       if ( style == _atom_comp_effect_default )       return UTILX_EFFECT_STYLE_DEFAULT;
-       else if ( style == _atom_comp_effect_none )     return UTILX_EFFECT_STYLE_NONE;
-       else if ( style == _atom_comp_effect_custom0 )  return UTILX_EFFECT_STYLE_CUSTOM0;
-       else if ( style == _atom_comp_effect_custom1 )  return UTILX_EFFECT_STYLE_CUSTOM1;
-       else if ( style == _atom_comp_effect_custom2 )  return UTILX_EFFECT_STYLE_CUSTOM2;
-       else if ( style == _atom_comp_effect_custom3 )  return UTILX_EFFECT_STYLE_CUSTOM3;
-       else if ( style == _atom_comp_effect_custom4 )  return UTILX_EFFECT_STYLE_CUSTOM4;
-       else if ( style == _atom_comp_effect_custom5 )  return UTILX_EFFECT_STYLE_CUSTOM5;
-       else if ( style == _atom_comp_effect_custom6 )  return UTILX_EFFECT_STYLE_CUSTOM6;
-       else if ( style == _atom_comp_effect_custom7 )  return UTILX_EFFECT_STYLE_CUSTOM7;
-       else if ( style == _atom_comp_effect_custom8 )  return UTILX_EFFECT_STYLE_CUSTOM8;
-       else if ( style == _atom_comp_effect_custom9 )  return UTILX_EFFECT_STYLE_CUSTOM9;
-       else                                            return UTILX_EFFECT_STYLE_DEFAULT;
-}
-
-API void utilx_set_window_effect_style(Display* dpy, Window win, Utilx_Effect_Type type, Utilx_Effect_Style style)
-{
-       Atom *window_effect_type_list = NULL;
-       if ( dpy == NULL )
-       {
-               fprintf (stderr, "[UTILX] Error.. Invald Display.. %s (%d)\n", __func__, __LINE__);
-               return;
-       }
-       _utilx_effect_atom_check(dpy);
-
-       window_effect_type_list = (Atom *)malloc(sizeof(Atom) * 6);
-
-       if ( !window_effect_type_list )
-       {
-               fprintf (stderr, "[UTILX] Error.. malloc().. %s (%d)\n", __func__, __LINE__);
-               return;
-       }
-
-       window_effect_type_list[0] = _atom_comp_effect_default;
-       window_effect_type_list[1] = _atom_comp_effect_default;
-       window_effect_type_list[2] = _atom_comp_effect_default;
-       window_effect_type_list[3] = _atom_comp_effect_default;
-       window_effect_type_list[4] = _atom_comp_effect_default;
-       window_effect_type_list[5] = _atom_comp_effect_default;
-
-       _utilx_get_window_property(dpy, win, _atom_comp_window_effect_type, XA_ATOM, (unsigned int *)window_effect_type_list, 6);
-
-       if ( type == UTILX_EFFECT_TYPE_MAP )             window_effect_type_list[0] = _utilx_convert_style_to_atom(dpy, style);
-       else if ( type == UTILX_EFFECT_TYPE_UNMAP )      window_effect_type_list[1] = _utilx_convert_style_to_atom(dpy, style);
-       else if ( type == UTILX_EFFECT_TYPE_RAISEABOVE ) window_effect_type_list[2] = _utilx_convert_style_to_atom(dpy, style);
-       else if ( type == UTILX_EFFECT_TYPE_ROTATION )   window_effect_type_list[3] = _utilx_convert_style_to_atom(dpy, style);
-       else if ( type == UTILX_EFFECT_TYPE_FOCUSIN )    window_effect_type_list[4] = _utilx_convert_style_to_atom(dpy, style);
-       else if ( type == UTILX_EFFECT_TYPE_FOCUSOUT )   window_effect_type_list[5] = _utilx_convert_style_to_atom(dpy, style);
-
-       _utilx_set_window_property(dpy, win, _atom_comp_window_effect_type, XA_ATOM, (unsigned int *)window_effect_type_list, 6);
-
-       XSync(dpy, 0 );
-       free(window_effect_type_list);
-}
-
-API Utilx_Effect_Style utilx_get_window_effect_style(Display* dpy, Window win, Utilx_Effect_Type type)
-{
-       Atom *window_effect_type_list = NULL;
-       Utilx_Effect_Style style = UTILX_EFFECT_STYLE_DEFAULT;
-
-       if ( dpy == NULL )
-       {
-               fprintf (stderr, "[UTILX] Error.. Invald Display.. %s (%d)\n", __func__, __LINE__);
-               return UTILX_EFFECT_STYLE_NONE;
-       }
-       _utilx_effect_atom_check(dpy);
-
-       window_effect_type_list = (Atom *)malloc(sizeof(Atom) * 6);
-
-       if ( !window_effect_type_list )
-       {
-               fprintf (stderr, "[UTILX] Error.. malloc().. %s (%d)\n", __func__, __LINE__);
-               return UTILX_EFFECT_STYLE_NONE;
-       }
-
-       if ( _utilx_get_window_property(dpy, win, _atom_comp_window_effect_type, XA_ATOM, (unsigned int *)window_effect_type_list, 6) != 6 )
-       {
-               fprintf (stderr, "[UTILX] Error.. get property failed!.. %s (%d)\n", __func__, __LINE__);
-               free(window_effect_type_list);
-               return UTILX_EFFECT_STYLE_NONE;
-       }
-
-       if ( type == UTILX_EFFECT_TYPE_MAP )             style = _utilx_convert_atom_to_style(dpy, window_effect_type_list[0]);
-       else if ( type == UTILX_EFFECT_TYPE_UNMAP )      style = _utilx_convert_atom_to_style(dpy, window_effect_type_list[1]);
-       else if ( type == UTILX_EFFECT_TYPE_RAISEABOVE ) style = _utilx_convert_atom_to_style(dpy, window_effect_type_list[2]);
-       else if ( type == UTILX_EFFECT_TYPE_ROTATION )   style = _utilx_convert_atom_to_style(dpy, window_effect_type_list[3]);
-       else if ( type == UTILX_EFFECT_TYPE_FOCUSIN )    style = _utilx_convert_atom_to_style(dpy, window_effect_type_list[4]);
-       else if ( type == UTILX_EFFECT_TYPE_FOCUSOUT )   style = _utilx_convert_atom_to_style(dpy, window_effect_type_list[5]);
-
-       XSync(dpy, 0 );
-       free(window_effect_type_list);
-       return style;
-}
-
-API int utilx_set_window_opaque_state (Display* dpy, Window win, Utilx_Opaque_State state)
-{
-       UTILX_TRACE ("[UTILX] utilx_set_window_opaque_state... win = %x, show_state = %d\n", win, state);
-
-       unsigned int is_opaque;
-
-       if (dpy == NULL)
-       {
-               fprintf (stderr, "[UTILX] Error.. Invald Display.. %s (%d)\n", __func__, __LINE__);
-               return 0;
-       }
-
-       switch (state)
-       {
-               case UTILX_OPAQUE_STATE_OFF:
-                       is_opaque = 0;
-                       break;
-
-               case UTILX_OPAQUE_STATE_ON:
-                       is_opaque = 1;
-                       break;
-
-               default:
-                       fprintf (stderr, "[UTILX] Error.. Invald State.. %s (%d)\n", __func__, __LINE__);
-                       return 0;
-       }
-
-       if (!_atom_window_opaque)
-       {
-               _atom_window_opaque = XInternAtom (dpy, "_E_ILLUME_WINDOW_REGION_OPAQUE", False);
-               if (!_atom_window_opaque)
-               {
-                       fprintf (stderr, "[UTILX] Error.. Cannot create _E_ILLUME_WINDOW_REGION_OPAQUE atom.. %s (%d)\n", __func__, __LINE__);
-                       return 0;
-               }
+               _atom_window_opaque = XInternAtom (dpy, "_E_ILLUME_WINDOW_REGION_OPAQUE", False);
+               if (!_atom_window_opaque)
+               {
+                       fprintf (stderr, "[UTILX] Error.. Cannot create _E_ILLUME_WINDOW_REGION_OPAQUE atom.. %s (%d)\n", __func__, __LINE__);
+                       return 0;
+               }
        }
 
        _utilx_set_window_property (dpy, win, _atom_window_opaque, XA_CARDINAL,
@@ -1167,102 +905,6 @@ API int utilx_set_window_opaque_state (Display* dpy, Window win, Utilx_Opaque_St
        return 1;
 }
 
-static void
-_utilx_screen_capture_atom_ensure (Display* dpy)
-{
-       if (_atom_screen_capture_disable)
-               return;
-
-       _atom_screen_capture_disable = XInternAtom (dpy, "_CB_SCREEN_CAPTURE_DISABLE", False);
-       if (_atom_screen_capture_disable)
-               return;
-
-       fprintf (stderr, "[UTILX] Error.. Cannot create _CB_SCREEN_CAPTURE_DISABLE atom.. %s (%d)\n", __func__, __LINE__);
-}
-
-API int
-utilx_set_screen_capture(Display* dpy, int enable)
-{
-       Window root;
-       int disable;
-
-       if (!dpy)
-       {
-               fprintf (stderr, "[UTILX] Error.. dpy is NULL %s (%d)\n", __func__, __LINE__);
-               return 0;
-       }
-
-       root = RootWindow (dpy, DefaultScreen(dpy));
-       disable = (enable) ? 0 : 1;
-
-       _utilx_screen_capture_atom_ensure (dpy);
-
-       _utilx_set_window_property (dpy, root, _atom_screen_capture_disable, XA_CARDINAL, (unsigned int *)&disable, 1);
-
-       return 1;
-}
-
-API int
-utilx_get_screen_capture(Display* dpy)
-{
-       Window root;
-       int disable = 0;
-
-       if (!dpy)
-       {
-               fprintf (stderr, "[UTILX] Error.. dpy is NULL %s (%d)\n", __func__, __LINE__);
-               return 0;
-       }
-
-       root = RootWindow (dpy, DefaultScreen(dpy));
-
-       _utilx_screen_capture_atom_ensure (dpy);
-
-       _utilx_get_window_property(dpy, root, _atom_screen_capture_disable, XA_CARDINAL,
-                                   (unsigned int *)&disable, 1);
-
-       return (disable) ? 0 : 1;
-}
-
-API void utilx_set_window_cardinal_property(Display* dpy, Window win, Atom atom, unsigned int *value)
-{
-       _utilx_set_window_property(dpy, win, atom, XA_CARDINAL, value, 1);
-}
-
-API int utilx_get_window_cardinal_property (Display* dpy, Window win, Atom atom, unsigned int *value)
-{
-       return _utilx_get_window_property(dpy, win, atom, XA_CARDINAL, value, 1);
-}
-
-API void utilx_show_capture_effect( Display *dpy, Window win)
-{
-    XEvent xev;
-
-    _atom_comp_capture_effect = XInternAtom( dpy, "_E_COMP_CAPTURE_EFFECT", False );
-    if(  !_atom_comp_capture_effect )
-    {
-        fprintf( stderr, "XInternAtom(_E_COMP_CAPTURE_EFFECT) failed.\n" );
-        return;
-    }
-
-    // send capture effect client message
-    xev.xclient.type = ClientMessage;
-    xev.xclient.display = dpy;
-    xev.xclient.window = win;
-    xev.xclient.message_type =  _atom_comp_capture_effect;
-    xev.xclient.format = 32;
-    xev.xclient.data.l[0] = 0;
-    xev.xclient.data.l[1] = 0;
-    xev.xclient.data.l[2] = 0;
-    xev.xclient.data.l[3] = 0;
-    xev.xclient.data.l[4] = 0;
-
-    XSendEvent( dpy, win, False,
-                SubstructureRedirectMask | SubstructureNotifyMask,
-                &xev );
-    XSync(dpy, 0 );
-}
-
 API UtilxScrnConf *utilx_scrnconf_allocate (void)
 {
     UtilxScrnConf *scrnconf = calloc (1, sizeof(UtilxScrnConf));
@@ -1292,7 +934,7 @@ API void utilx_scrnconf_free (UtilxScrnConf *scrnconf)
 
 API int utilx_scrnconf_get_info (Display *dpy, UtilxScrnConf *scrnconf)
 {
-    Window win = DefaultRootWindow(dpy);
+    Window win;
        Atom scrnconf_atom = None;
     XTextProperty xtp;
     char *str = NULL;
@@ -1302,6 +944,14 @@ API int utilx_scrnconf_get_info (Display *dpy, UtilxScrnConf *scrnconf)
     int i = 0;
     int s;
 
+    if (!dpy)
+        goto fail;
+
+    if (!scrnconf)
+        goto fail;
+
+    win = DefaultRootWindow(dpy);
+
     scrnconf_atom = XInternAtom (dpy, "_SCRNCONF_INFO", False);
 
     /* get property */
@@ -1325,7 +975,7 @@ API int utilx_scrnconf_get_info (Display *dpy, UtilxScrnConf *scrnconf)
     {
         if (i == 0)
         {
-            scrnconf->str_output = calloc (1, strlen(ptr));
+            scrnconf->str_output = calloc (1, strlen(ptr)+1);
             if (!scrnconf->str_output)
                 goto fail;
 
@@ -1342,7 +992,7 @@ API int utilx_scrnconf_get_info (Display *dpy, UtilxScrnConf *scrnconf)
         }
         else if (i == 2)
         {
-            scrnconf->str_resolution = calloc (1, strlen(ptr));
+            scrnconf->str_resolution = calloc (1, strlen(ptr)+1);
             if (!scrnconf->str_resolution)
                 goto fail;
 
@@ -1436,15 +1086,9 @@ typedef struct _ShotInfo
     Damage   damage;
     int      damage_base;
 
-    /* Dri2 */
-    int      drm_fd;
-    tbm_bufmgr bufmgr;
     void    *virtual;
-    DRI2Buffer* dri2_buffers;
-    tbm_bo bo;
 
     /* XShm */
-    Bool       enable_xshm;
     XImage    *image;
     XShmSegmentInfo shminfo;
 } ShotInfo;
@@ -1460,7 +1104,7 @@ static Bool x_error_caught;
 static ShotInfo *shot_info;
 
 static int
-_get_port (Display *dpy, unsigned int id)
+_get_port (Display *dpy, unsigned int id, Window win)
 {
     unsigned int ver, rev, req_base, evt_base, err_base;
     unsigned int adaptors;
@@ -1475,7 +1119,7 @@ _get_port (Display *dpy, unsigned int id)
         return -1;
     }
 
-    if (XvQueryAdaptors (dpy, DefaultRootWindow (dpy), &adaptors, &ai) != Success)
+    if (XvQueryAdaptors (dpy, win, &adaptors, &ai) != Success)
     {
         fprintf (stderr, "[UTILX] fail : query adaptors. \n");
         return -1;
@@ -1508,10 +1152,13 @@ _get_port (Display *dpy, unsigned int id)
         if (!support_format)
             continue;
 
-        if (XvGrabPort (dpy, p, 0) == Success)
+        for (; p < ai[i].base_id + ai[i].num_ports; p++)
         {
-            XvFreeAdaptorInfo (ai);
-            return p;
+            if (XvGrabPort (dpy, p, 0) == Success)
+            {
+                XvFreeAdaptorInfo (ai);
+                return p;
+            }
         }
 
         fprintf (stderr, "[UTILX] fail : grab port. \n");
@@ -1525,15 +1172,11 @@ _get_port (Display *dpy, unsigned int id)
 static void
 _deinit_screen_shot (ShotInfo *info)
 {
-    static Atom atom_stream_off = None;
-
     if (!info)
         return;
 
-    if (atom_stream_off == None)
-        atom_stream_off = XInternAtom (info->dpy, "_USER_WM_PORT_ATTRIBUTE_STREAM_OFF", False);
-
-    XvSetPortAttribute (info->dpy, info->port, atom_stream_off, 1);
+    if (info->port > 0 && info->pixmap > 0)
+        XvStopVideo (info->dpy, info->port, info->pixmap);
 
     if (info->image)
         XDestroyImage (info->image);
@@ -1544,15 +1187,6 @@ _deinit_screen_shot (ShotInfo *info)
         shmctl (info->shminfo.shmid, IPC_RMID, 0);
     }
 
-    if (info->bo)
-        tbm_bo_unref(info->bo);
-    if (info->dri2_buffers)
-        free(info->dri2_buffers);
-    if (info->bufmgr)
-        tbm_bufmgr_deinit (info->bufmgr);
-    if (info->drm_fd >= 0)
-        close (info->drm_fd);
-
     if (info->damage)
         XDamageDestroy (info->dpy, info->damage);
 
@@ -1602,118 +1236,6 @@ _init_screen_shot_damage (ShotInfo *info)
 }
 
 static Bool
-_init_screen_shot_dri2 (ShotInfo *info)
-{
-    int screen;
-    int dri2_base = 0;
-    int dri2_err_base = 0;
-    int dri2Major, dri2Minor;
-    char *driverName = NULL, *deviceName = NULL;
-    unsigned int attachments[1];
-    int dri2_count, dri2_out_count;
-    int dri2_width, dri2_height, dri2_stride;
-    drm_magic_t magic;
-    tbm_bo_handle bo_handle;
-
-    screen = DefaultScreen(info->dpy);
-    if (!DRI2QueryExtension (info->dpy, &dri2_base, &dri2_err_base))
-    {
-        fprintf (stderr, "[UTILX] no DRI2 extension. !!\n");
-        goto fail_init_dri2;
-    }
-
-    if (!DRI2QueryVersion (info->dpy, &dri2Major, &dri2Minor))
-    {
-        fprintf (stderr, "[UTILX] fail : DRI2QueryVersion !!\n");
-        goto fail_init_dri2;
-    }
-
-    if (!DRI2Connect (info->dpy, RootWindow(info->dpy, screen), &driverName, &deviceName))
-    {
-        fprintf (stderr, "[UTILX] fail : DRI2Connect !!\n");
-        goto fail_init_dri2;
-    }
-
-    /* drm_fd */
-    info->drm_fd = open (deviceName, O_RDWR);
-    if (info->drm_fd < 0)
-    {
-        fprintf (stderr, "[UTILX] fail : open drm device (%s)\n", deviceName);
-        goto fail_init_dri2;
-    }
-
-    /* get the drm magic */
-    drmGetMagic(info->drm_fd, &magic);
-    if (!DRI2Authenticate(info->dpy, RootWindow(info->dpy, screen), magic))
-    {
-        fprintf (stderr, "[UTILX] fail : DRI2Authenticate (%d)\n", magic);
-        goto fail_init_dri2;
-    }
-
-    /* bufmgr */
-    info->bufmgr = tbm_bufmgr_init (info->drm_fd);
-    if (!info->bufmgr)
-    {
-        fprintf (stderr, "[UTILX] fail : init buffer manager \n");
-        goto fail_init_dri2;
-    }
-
-    DRI2CreateDrawable (info->dpy, info->pixmap);
-
-    attachments[0] = DRI2BufferFrontLeft;
-    dri2_count = 1;
-    info->dri2_buffers = DRI2GetBuffers (info->dpy, info->pixmap, &dri2_width, &dri2_height,
-                                         attachments, dri2_count, &dri2_out_count);
-
-    if (!info->dri2_buffers)
-    {
-        fprintf (stderr, "[UTILX] fail : get buffers\n");
-        goto fail_init_dri2;
-    }
-
-    if (!info->dri2_buffers[0].name)
-    {
-        fprintf (stderr, "[UTILX] fail : a handle of the dri2 buffer is null \n ");
-        goto fail_init_dri2;
-    }
-
-    info->bo = tbm_bo_import (info->bufmgr, info->dri2_buffers[0].name);
-    if (!info->bo)
-    {
-        fprintf (stderr, "[UTILX] fail : import bo (key:%d)\n", info->dri2_buffers[0].name);
-        goto fail_init_dri2;
-    }
-
-    dri2_stride = info->dri2_buffers[0].pitch;
-
-    /* virtual */
-    bo_handle = tbm_bo_get_handle (info->bo, TBM_DEVICE_CPU);
-    info->virtual = (void *)bo_handle.ptr;
-    if (!info->virtual)
-    {
-        fprintf (stderr, "[UTILX] fail : map \n");
-        goto fail_init_dri2;
-    }
-
-    info->enable_xshm = False;
-
-    return True;
-
-fail_init_dri2:
-
-    if (info->bo)
-        tbm_bo_unref(info->bo);
-    if (info->dri2_buffers)
-        free(info->dri2_buffers);
-    if (info->bufmgr)
-        tbm_bufmgr_deinit (info->bufmgr);
-    if (info->drm_fd >= 0)
-        close (info->drm_fd);
-
-    return False;
-}
-
-static Bool
 _init_screen_shot_shm (ShotInfo *info)
 {
     if (!XShmQueryExtension (info->dpy))
@@ -1769,8 +1291,6 @@ _init_screen_shot_shm (ShotInfo *info)
     info->image->data = info->shminfo.shmaddr;
     info->virtual = info->shminfo.shmaddr;
 
-    info->enable_xshm = True;
-
     return True;
 }
 
@@ -1779,7 +1299,6 @@ _init_screen_shot (Display* dpy, unsigned int width, unsigned int height)
 {
     ShotInfo *info = NULL;
     static Atom atom_capture = None;
-    static Atom atom_fps = None;
     XErrorHandler old_handler = NULL;
 
     if (shot_info)
@@ -1800,25 +1319,21 @@ _init_screen_shot (Display* dpy, unsigned int width, unsigned int height)
     info->dpy = dpy;
     info->shminfo.shmid = -1;
     info->shminfo.shmaddr = (void*)-1;
-    info->drm_fd = -1;
 
     /* port */
-    info->port = _get_port (info->dpy, FOURCC_RGB32);
+    info->port = _get_port (info->dpy, FOURCC_RGB32, DefaultRootWindow (dpy));
     if (info->port <= 0)
         goto fail_init;
 
     /* width, height */
     if (atom_capture == None)
         atom_capture = XInternAtom (info->dpy, "_USER_WM_PORT_ATTRIBUTE_CAPTURE", False);
-    if (atom_fps == None)
-        atom_fps = XInternAtom (info->dpy, "_USER_WM_PORT_ATTRIBUTE_FPS", False);
 
     XSync (info->dpy, 0);
     x_error_caught = False;
     old_handler = XSetErrorHandler (_screen_shot_x_error_handle);
 
     XvSetPortAttribute (info->dpy, info->port, atom_capture, 1);
-    XvSetPortAttribute (info->dpy, info->port, atom_fps, 60);
 
     XSync (info->dpy, 0);
 
@@ -1856,13 +1371,10 @@ _init_screen_shot (Display* dpy, unsigned int width, unsigned int height)
     if (!_init_screen_shot_damage (info))
         goto fail_init;
 
-    if (!_init_screen_shot_dri2 (info))
-    {
-        if (!_init_screen_shot_shm (info))
-            goto fail_init;
-        else
-            fprintf (stderr, "[UTILX] XShm success. !!\n");
-    }
+    if (!_init_screen_shot_shm (info))
+        goto fail_init;
+    else
+        fprintf (stderr, "[UTILX] XShm success. !!\n");
 
     if (!info->virtual)
     {
@@ -1960,9 +1472,211 @@ utilx_create_screen_shot (Display* dpy, int width, int height)
         XDamageNotifyEvent *damage_ev = (XDamageNotifyEvent *)&ev;
         if (damage_ev->drawable == info->pixmap)
         {
-            if (info->enable_xshm)
-                XShmGetImage (info->dpy, info->pixmap, info->image, 0, 0, AllPlanes);
+            XShmGetImage (info->dpy, info->pixmap, info->image, 0, 0, AllPlanes);
+            XDamageSubtract (info->dpy, info->damage, None, None );
+            return info->virtual;
+        }
+
+        XDamageSubtract (info->dpy, info->damage, None, None );
+    }
+
+    utilx_release_screen_shot ();
+
+    return NULL;
+}
+
+static ShotInfo*
+_init_video_screen_shot (Display* dpy, unsigned int width, unsigned int height, Window win)
+{
+    ShotInfo *info = NULL;
+    static Atom atom_capture = None;
+    static Atom atom_capture_on_win = None;
+    XErrorHandler old_handler = NULL;
+
+    if (shot_info)
+    {
+        if (shot_info->width == width && shot_info->height == height)
+            return shot_info;
+
+        _deinit_screen_shot (shot_info);
+    }
+
+    info = calloc (1, sizeof (ShotInfo));
+    if (!info)
+        goto fail_init;
+
+    shot_info = info;
+
+    /* dpy */
+    info->dpy = dpy;
+    info->shminfo.shmid = -1;
+    info->shminfo.shmaddr = (void*)-1;
+
+    /* port */
+    info->port = _get_port (info->dpy, FOURCC_RGB32, win);
+    if (info->port <= 0)
+        goto fail_init;
+
+    /* width, height */
+    if (atom_capture == None)
+        atom_capture = XInternAtom (info->dpy, "_USER_WM_PORT_ATTRIBUTE_CAPTURE", False);
+
+    if (atom_capture_on_win  == None)
+        atom_capture_on_win = XInternAtom (info->dpy, "_USER_WM_PORT_ATTRIBUTE_CAPTURE_ON_WINDOW", False);
+
+    XSync (info->dpy, 0);
+    x_error_caught = False;
+    old_handler = XSetErrorHandler (_screen_shot_x_error_handle);
+
+    XvSetPortAttribute (info->dpy, info->port, atom_capture, 3);
+    XvSetPortAttribute (info->dpy, info->port, atom_capture_on_win, 1);
+
+    XSync (info->dpy, 0);
+
+    x_error_caught = False;
+    XSetErrorHandler (old_handler);
+
+    XvQueryBestSize (info->dpy, info->port, 0, 0, 0, width, height, &width, &height);
+    if (width <= 0 || height <= 0)
+        goto fail_init;
+    info->width = width;
+    info->height = height;
+
+    /* pixmap */
+    info->pixmap = XCreatePixmap (info->dpy,
+                                  win,
+                                  width, height,
+                                  DefaultDepth (info->dpy, DefaultScreen (info->dpy)));
+    if (info->pixmap <= 0)
+    {
+        fprintf (stderr, "[UTILX] fail : create pixmap. \n");
+        goto fail_init;
+    }
+
+    /* gc */
+    info->gc = XCreateGC (info->dpy, info->pixmap, 0, 0);
+    if (info->gc == NULL)
+    {
+        fprintf (stderr, "[UTILX] fail : create gc. \n");
+        goto fail_init;
+    }
+
+    XSetForeground (info->dpy, info->gc, 0xFF000000);
+    XFillRectangle (info->dpy, info->pixmap, info->gc, 0, 0, width, height);
+
+    if (!_init_screen_shot_damage (info))
+        goto fail_init;
+
+    if (!_init_screen_shot_shm (info))
+        goto fail_init;
+    else
+        fprintf (stderr, "[UTILX] XShm success. !!\n");
+
+    if (!info->virtual)
+    {
+        fprintf (stderr, "[UTILX] fail : get virtual \n");
+        goto fail_init;
+    }
+
+    XFlush (info->dpy);
+
+    return info;
+
+fail_init:
+    _deinit_screen_shot (info);
+    return NULL;
+}
+
+Bool
+predicate_proc(Display *dpy, XEvent *event, char *arg)
+{
+    ShotInfo *info = (ShotInfo *)arg;
+
+    if(event->type == (info->damage_base + XDamageNotify))
+        return True;
+    else
+        return False;
+}
+API void*
+utilx_create_video_screen_shot (Display* dpy, Window win, int width, int height)
+{
+    ShotInfo *info;
+    XEvent ev = {0,};
+    XErrorHandler old_handler = NULL;
+    unsigned int pixmap = 0;
+
+    if (dpy == NULL)
+    {
+        fprintf (stderr, "[UTILX] invalid display(%p) \n", dpy);
+        return NULL;
+    }
+
+    if (width <= 0 || height <= 0)
+    {
+        fprintf (stderr, "[UTILX] invalid size(%dx%d) \n", width, height);
+        return NULL;
+    }
+
+    XSync (dpy, 0);
+
+    info = _init_video_screen_shot (dpy, width, height, win);
+
+    if (!info)
+    {
+        fprintf (stderr, "[UTILX] fail : initialize screenshot. \n");
+        return NULL;
+    }
+
+    if (!_atom_window_pixman)
+    {
+        _atom_window_pixman = XInternAtom (dpy, "_UTIL_WINDOW_PIXMAP_HANDLE", False);
+        if (!_atom_window_pixman)
+        {
+            fprintf (stderr, "[UTILX] Error.. Cannot create _UTIL_WINDOW_PIXMAP_HANDLE atom.. %s (%d)\n", __func__, __LINE__);
+            return 0;
+        }
+    }
+
+    x_error_caught = False;
+    old_handler = XSetErrorHandler (_screen_shot_x_error_handle);
 
+    pixmap = (unsigned int)info->pixmap;
+    XChangeProperty (dpy, win, _atom_window_pixman, XA_PIXMAP, 32, PropModeReplace, (unsigned char *)((unsigned int *)&pixmap), 1);
+    XSync (dpy, 0);
+
+    if (x_error_caught)
+    {
+        x_error_caught = False;
+        XSetErrorHandler (old_handler);
+        return NULL;
+    }
+
+    XvPutStill (info->dpy, info->port, info->pixmap, info->gc,
+                0, 0, info->width, info->height,
+                0, 0, info->width, info->height);
+    XSync (dpy, 0);
+
+    if (x_error_caught)
+    {
+        x_error_caught = False;
+        XSetErrorHandler (old_handler);
+        return NULL;
+    }
+
+    XDeleteProperty(info->dpy, win, _atom_window_pixman);
+    _atom_window_pixman = None;
+    XSync (dpy, 0);
+
+    x_error_caught = False;
+    XSetErrorHandler (old_handler);
+
+    XIfEvent(info->dpy, &ev, predicate_proc, info);
+    if (ev.type == (info->damage_base + XDamageNotify))
+    {
+        XDamageNotifyEvent *damage_ev = (XDamageNotifyEvent *)&ev;
+        if (damage_ev->drawable == info->pixmap)
+        {
+            XShmGetImage (info->dpy, info->pixmap, info->image, 0, 0, AllPlanes);
             XDamageSubtract (info->dpy, info->damage, None, None );
             return info->virtual;
         }
@@ -2147,40 +1861,3 @@ utilx_get_fb_visible (Display* dpy, Utilx_Fb_Type fb)
 
     return visible;
 }
-
-API void
-utilx_set_video_offset (Display* dpy, int x, int y)
-{
-    static Atom property = None;
-    char buf[32] = {0,};
-    char *p = buf;
-    int buf_len = 0;
-
-    if (!dpy)
-    {
-        fprintf (stderr, "[UTILX] invalid display(%p).. %s (%d)\n", dpy, __func__, __LINE__);
-        return;
-    }
-
-    p += sprintf (p, "%d,%d", x, y);
-
-    *p = '\0';
-    p++;
-
-    buf_len = p - buf;
-
-    if (property == None)
-        property = XInternAtom (dpy, XRR_PROPERTY_VIDEO_OFFSET, False);
-
-    if (property == None)
-    {
-        fprintf (stderr, "[UTILX] Warning : VIDEO_OFFSET property is None.. %s (%d)\n", __func__, __LINE__);
-        return;
-    }
-
-    if (!_utilx_xrr_set_property (dpy, property, (unsigned char*)buf, buf_len, NULL))
-    {
-        fprintf (stderr, "[UTILX] Warning : set_property failed.. %s (%d)\n", __func__, __LINE__);
-        return;
-    }
-}