added an option (GLUT_SKIP_STALE_MOTION_EVENTS) to ignore all but the last
[freeglut] / src / x11 / fg_main_x11.c
index e72db37..3ecb811 100644 (file)
@@ -55,6 +55,9 @@
 #    define MIN(a,b) (((a)<(b)) ? (a) : (b))
 #endif
 
+/* used in the event handling code to match and discard stale mouse motion events */
+static Bool match_motion(Display *dpy, XEvent *xev, XPointer arg);
+
 /*
  * TODO BEFORE THE STABLE RELEASE:
  *
@@ -788,6 +791,13 @@ void fgPlatformProcessSingleEvent ( void )
 
         case MotionNotify:
         {
+            /* if GLUT_SKIP_STALE_MOTION_EVENTS is true, then discard all but
+             * the last motion event from the queue
+             */
+            if(fgState.SkipStaleMotion) {
+                while(XCheckIfEvent(fgDisplay.pDisplay.Display, &event, match_motion, 0));
+            }
+
             GETWINDOW( xmotion );
             GETMOUSE( xmotion );
 
@@ -1077,6 +1087,11 @@ void fgPlatformProcessSingleEvent ( void )
 }
 
 
+static Bool match_motion(Display *dpy, XEvent *xev, XPointer arg)
+{
+    return xev->type == MotionNotify;
+}
+
 void fgPlatformMainLoopPreliminaryWork ( void )
 {
 }