XGetImage takes a lot of time to run
<p>XGetImage takes 3-4 seconds to execute and completely freezes X11</p>

<pre><code>Display *display;
    display = XOpenDisplay(NULL);
if (!display) {fprintf(stderr, "unable to connect to display");return 7;}
    Window w;
    int x,y,i;
    unsigned m;
    Window root = XDefaultRootWindow(display);
if (!root) {fprintf(stderr, "unable to open rootwindow");return 8;}
    //sleep(1);
    if(!XQueryPointer(display,root,&amp;root,&amp;w,&amp;x,&amp;y,&amp;i,&amp;i,&amp;m))
{  printf("unable to query pointer\n"); return 9;}
    XImage *image;
    XWindowAttributes attr;
    XGetWindowAttributes(display, root, &amp;attr);
    image = XGetImage(display,root,0,0,attr.width,attr.height,AllPlanes,XYPixmap);
    XCloseDisplay(display);
if (!image) {printf("unable to get image\n"); return 10;}
</code></pre>

<p>In the Xorg log:</p>

<pre><code>[ 13234.693] AUDIT: Thu Jan  7 20:12:13 2016: 3856: client 45 connected from local host ( uid=500 gid=500 pid=12993 )
  Auth name: MIT-MAGIC-COOKIE-1 ID: 153
[ 13238.774] AUDIT: Thu Jan  7 20:12:18 2016: 3856: client 45 disconnected
</code></pre>

<hr>

<pre><code>time:
real    0m4.080s
user    0m0.002s
sys 0m0.007s
</code></pre>

<p>Ideally I want this function to run in less than 0.1 seconds </p>