• Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 585
  • Last Modified:

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()

   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;
          /* The following implements a fast ring buffer when count reaches buffer size */
          if (count <= BUF_SIZE)
          else {
             count = 0;
   } /* End while */
1 Solution
Use are using Button1MotionMask, so you get the movement events only when you press the mouse button and move. You should use PointerMotionMask instead.
Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.

Join & Write a Comment

Featured Post

7 new features that'll make your work life better

It’s our mission to create a product that solves the huge challenges you face at work every day. In case you missed it, here are 7 delightful things we've added recently to monday to make it even more awesome.

Tackle projects and never again get stuck behind a technical roadblock.
Join Now