Solved

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

Posted on 1998-10-01
1
560 Views
Last Modified: 2012-05-04
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 */
}
0
Comment
Question by:yueweng5
1 Comment
 
LVL 4

Accepted Solution

by:
feenix earned 200 total points
ID: 1174146
Use are using Button1MotionMask, so you get the movement events only when you press the mouse button and move. You should use PointerMotionMask instead.
0

Featured Post

Courses: Start Training Online With Pros, Today

Brush up on the basics or master the advanced techniques required to earn essential industry certifications, with Courses. Enroll in a course and start learning today. Training topics range from Android App Dev to the Xen Virtualization Platform.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Errors will happen. It is a fact of life for the programmer. How and when errors are detected have a great impact on quality and cost of a product. It is better to detect errors at compile time, when possible and practical. Errors that make their wa…
In days of old, returning something by value from a function in C++ was necessarily avoided because it would, invariably, involve one or even two copies of the object being created and potentially costly calls to a copy-constructor and destructor. A…
The viewer will learn additional member functions of the vector class. Specifically, the capacity and swap member functions will be introduced.
The viewer will learn how to clear a vector as well as how to detect empty vectors in C++.

776 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question