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,X DefaultRoo tWindow(di splay),100 ,100,200,2 00,4,0,0);
XMapWindow(display,window) ;
XSelectInput(display,windo w,Button1M otionMask| ExposureMa sk);
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[c ount]);
/* The following implements a fast ring buffer when count reaches buffer size */
if (count <= BUF_SIZE)
count++;
else {
count = 0;
}
} /* End while */
}
#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
XMapWindow(display,window)
XSelectInput(display,windo
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[c
/* 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
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.