Link to home
Start Free TrialLog in
Avatar of yueweng5
yueweng5

asked on

Any experts how to useknow Xlib: MotionNotify ....help!!!!

Any body know how to get the coordinate of a mouse in a xwindow??  I try doing this by writing a program below but only a window display and no motiondetect when i move my mouse inside the window... pls help me...

#include <X11/Xlib.h>

#define BUF_SIZE 2000
Display *display;
Window window;
XEvent report;

int xpositions[BUF_SIZE], ypositions[BUF_SIZE];

int count=0;


void main()
{
display=XOpenDisplay(NULL);
window=XCreateSimpleWindow(display,XDefaultRootWindow(display),100,100,200,200,4,0,0);
XMapWindow(display,window);
XSelectInput(display,window,Button1MotionMask|ExposureMask);


   while (1)  {
      XNextEvent(display, &report);
if (report.type==MotionNotify)
       
        printf("got a motion event\n");          
xpositions[count] = report.xmotion.x;
        ypositions[count] = report.xmotion.y;
printf("%d\n",xpositions[count]);
       
          /* The following implements a fast ring buffer when count reaches buffer size */
          if (count <= BUF_SIZE)
             count++;
          else {
             count = 0;
              }
         
   
   } /* End while */
}
ASKER CERTIFIED SOLUTION
Avatar of feenix
feenix
Flag of Finland image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial