XGetImage takes 3-4 seconds to execute and completely freezes X11
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,&root,&w,&x,&y,&i,&i,&m))
{ printf("unable to query pointer\n"); return 9;}
XImage *image;
XWindowAttributes attr;
XGetWindowAttributes(display, root, &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;}
In the Xorg log:
[ 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
time:
real 0m4.080s
user 0m0.002s
sys 0m0.007s
Ideally I want this function to run in less than 0.1 seconds
if(!XQueryPointer(display,root,&root,&w,&x,&y,&i,&i,&m))
. it is unlikely that the address of variablei
would be passed twice to the XQueryPointer() function. – Kite