From 6de0216ace8e54ec823458b2cd0df3b6438a0e1f Mon Sep 17 00:00:00 2001 From: John Tsiombikas Date: Sat, 31 Mar 2012 13:34:32 +0000 Subject: [PATCH] added an option (GLUT_SKIP_STALE_MOTION_EVENTS) to ignore all but the last MotionNotify event in the queue. git-svn-id: svn+ssh://svn.code.sf.net/p/freeglut/code/trunk/freeglut/freeglut@1218 7f0cb862-5218-0410-a997-914c9d46530a --- include/GL/freeglut_ext.h | 2 ++ src/fg_init.c | 3 ++- src/fg_internal.h | 2 ++ src/fg_state.c | 7 +++++++ src/x11/fg_main_x11.c | 15 +++++++++++++++ 5 files changed, 28 insertions(+), 1 deletion(-) diff --git a/include/GL/freeglut_ext.h b/include/GL/freeglut_ext.h index 0a91166..0fda0e2 100644 --- a/include/GL/freeglut_ext.h +++ b/include/GL/freeglut_ext.h @@ -83,6 +83,8 @@ #define GLUT_FULL_SCREEN 0x01FF +#define GLUT_SKIP_STALE_MOTION_EVENTS 0x0204 + /* * New tokens for glutInitDisplayMode. * Only one GLUT_AUXn bit may be used at a time. diff --git a/src/fg_init.c b/src/fg_init.c index bf55602..d564e83 100644 --- a/src/fg_init.c +++ b/src/fg_init.c @@ -85,6 +85,7 @@ SFG_State fgState = { { -1, -1, GL_FALSE }, /* Position */ 0, /* MouseWheelTicks */ 1, /* AuxiliaryBufferNumber */ 4, /* SampleNumber */ + GL_FALSE, /* SkipStaleMotion */ 1, /* OpenGL context MajorVersion */ 0, /* OpenGL context MinorVersion */ 0, /* OpenGL ContextFlags */ @@ -682,4 +683,4 @@ void FGAPIENTRY glutInitWarningFunc( void (* vfgWarning) ( const char *fmt, va_l fgState.WarningFunc = vfgWarning; } -/*** END OF FILE ***/ \ No newline at end of file +/*** END OF FILE ***/ diff --git a/src/fg_internal.h b/src/fg_internal.h index 7e0f30c..2119d1a 100644 --- a/src/fg_internal.h +++ b/src/fg_internal.h @@ -314,6 +314,8 @@ struct tagSFG_State int AuxiliaryBufferNumber; /* Number of auxiliary buffers */ int SampleNumber; /* Number of samples per pixel */ + GLboolean SkipStaleMotion; /* skip stale motion events */ + int MajorVersion; /* Major OpenGL context version */ int MinorVersion; /* Minor OpenGL context version */ int ContextFlags; /* OpenGL context flags */ diff --git a/src/fg_state.c b/src/fg_state.c index 208b5e2..734a57c 100644 --- a/src/fg_state.c +++ b/src/fg_state.c @@ -111,6 +111,10 @@ void FGAPIENTRY glutSetOption( GLenum eWhat, int value ) fgState.SampleNumber = value; break; + case GLUT_SKIP_STALE_MOTION_EVENTS: + fgState.SkipStaleMotion = value; + break; + default: fgWarning( "glutSetOption(): missing enum handle %d", eWhat ); break; @@ -198,6 +202,9 @@ int FGAPIENTRY glutGet( GLenum eWhat ) case GLUT_MULTISAMPLE: return fgState.SampleNumber; + case GLUT_SKIP_STALE_MOTION_EVENTS: + return fgState.SkipStaleMotion; + default: return fgPlatformGlutGet ( eWhat ); break; diff --git a/src/x11/fg_main_x11.c b/src/x11/fg_main_x11.c index e72db37..3ecb811 100644 --- a/src/x11/fg_main_x11.c +++ b/src/x11/fg_main_x11.c @@ -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 ) { } -- 1.7.10.4