Using the X11 library on debian jessie, I have the following code:
#include <stdio.h>
#include <X11/Xlib.h>
#include <stdlib.h>
#include <unistd.h>
#include <string.h>
Display *display;
XEvent xevent;
Window window;
int x,y;
#define BUTTON1MOTION (1L<<8)
int main(int argc, char **argv){
if( (display = XOpenDisplay(NULL)) == NULL )
return -1;
//int curr = 0;
while (1) {
XCheckMaskEvent(display, ButtonMotionMask, &xevent);
printf("x_root: %d y_root: %d \n", xevent.xmotion.x_root, xevent.xmotion.y_root);
}
}
I would like to capture MotionNotify events associated with the mouse being moved. However, the XCheckMaskEvent returns an endless stream of Motion events, even when no mouse buttons are pressed and no motion is done on the mouse; and x,y coordinates for these events are always (0,0). What can I do to get genuine mouse movement events, with the correct coordinates?
PS. use the -lX11 tag for compilation, i.e. gcc -Wall -lX11
EDIT: I used XCheckMaskEvent which works as it automatically returns, unlike the former, but this returns an endless stream of events even if the mouse is not moving.