Solved

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

Posted on 1998-10-01
1
553 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

What Is Threat Intelligence?

Threat intelligence is often discussed, but rarely understood. Starting with a precise definition, along with clear business goals, is essential.

Join & Write a Comment

Often, when implementing a feature, you won't know how certain events should be handled at the point where they occur and you'd rather defer to the user of your function or class. For example, a XML parser will extract a tag from the source code, wh…
C++ Properties One feature missing from standard C++ that you will find in many other Object Oriented Programming languages is something called a Property (http://www.experts-exchange.com/Programming/Languages/CPP/A_3912-Object-Properties-in-C.ht…
The viewer will learn how to use the return statement in functions in C++. The video will also teach the user how to pass data to a function and have the function return data back for further processing.
The viewer will be introduced to the member functions push_back and pop_back of the vector class. The video will teach the difference between the two as well as how to use each one along with its functionality.

760 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

Need Help in Real-Time?

Connect with top rated Experts

20 Experts available now in Live!

Get 1:1 Help Now