Solved

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

Posted on 1998-10-01
1
571 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
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

Announcing the Most Valuable Experts of 2016

MVEs are more concerned with the satisfaction of those they help than with the considerable points they can earn. They are the types of people you feel privileged to call colleagues. Join us in honoring this amazing group of Experts.

Question has a verified solution.

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

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…
This article shows you how to optimize memory allocations in C++ using placement new. Applicable especially to usecases dealing with creation of large number of objects. A brief on problem: Lets take example problem for simplicity: - I have a G…
The goal of the video will be to teach the user the concept of local variables and scope. An example of a locally defined variable will be given as well as an explanation of what scope is in C++. The local variable and concept of scope will be relat…
The viewer will be introduced to the technique of using vectors in C++. The video will cover how to define a vector, store values in the vector and retrieve data from the values stored in the vector.

729 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