I am able to grab the mouse, but my problem is that the mouse events that happen while the mouse is grabbed are just queued, and happen after I release the mouse.
this is the code I have until now:
#include <X11/Xlib.h>
#include <X11/Xutil.h>
#include <X11/Xos.h>
#include <stdio.h>
int main(int argc, char const *argv[])
{
XEvent e;
Display* dispaly = XOpenDisplay(NULL);
Window window = XDefaultRootWindow(dispaly);
unsigned int count = 0;
XGrabPointer(dispaly, window, true, PointerMotionMask | ButtonPressMask | ButtonReleaseMask, GrabModeSync, GrabModeAsync, None, None, CurrentTime);
while(count < 500000) {
if (XPending(dispaly))
XNextEvent(dispaly, &e);
count++;
printf("%d\n", count);
}
XFlush(dispaly);
XCloseDisplay(dispaly);
scanf("%d", &count);
printf("end\n");
return 0;
}
as you can see, I tried consuming the all the events in numerous ways, like with XPending and XNextEvent, with XFlush, and also with XSync. No matter what function I tried, all the mouse events I do while the mouse is grabbed just happen after I close the display.
can someone help?