added an option (GLUT_SKIP_STALE_MOTION_EVENTS) to ignore all but the last

MotionNotify event in the queue.



git-svn-id: https://svn.code.sf.net/p/freeglut/code/trunk@1218 7f0cb862-5218-0410-a997-914c9d46530a
This commit is contained in:
jtsiomb 2012-03-31 13:34:32 +00:00
parent 207411c39b
commit 4c7a212acb
5 changed files with 28 additions and 1 deletions

View File

@ -83,6 +83,8 @@
#define GLUT_FULL_SCREEN 0x01FF #define GLUT_FULL_SCREEN 0x01FF
#define GLUT_SKIP_STALE_MOTION_EVENTS 0x0204
/* /*
* New tokens for glutInitDisplayMode. * New tokens for glutInitDisplayMode.
* Only one GLUT_AUXn bit may be used at a time. * Only one GLUT_AUXn bit may be used at a time.

View File

@ -85,6 +85,7 @@ SFG_State fgState = { { -1, -1, GL_FALSE }, /* Position */
0, /* MouseWheelTicks */ 0, /* MouseWheelTicks */
1, /* AuxiliaryBufferNumber */ 1, /* AuxiliaryBufferNumber */
4, /* SampleNumber */ 4, /* SampleNumber */
GL_FALSE, /* SkipStaleMotion */
1, /* OpenGL context MajorVersion */ 1, /* OpenGL context MajorVersion */
0, /* OpenGL context MinorVersion */ 0, /* OpenGL context MinorVersion */
0, /* OpenGL ContextFlags */ 0, /* OpenGL ContextFlags */

View File

@ -314,6 +314,8 @@ struct tagSFG_State
int AuxiliaryBufferNumber; /* Number of auxiliary buffers */ int AuxiliaryBufferNumber; /* Number of auxiliary buffers */
int SampleNumber; /* Number of samples per pixel */ int SampleNumber; /* Number of samples per pixel */
GLboolean SkipStaleMotion; /* skip stale motion events */
int MajorVersion; /* Major OpenGL context version */ int MajorVersion; /* Major OpenGL context version */
int MinorVersion; /* Minor OpenGL context version */ int MinorVersion; /* Minor OpenGL context version */
int ContextFlags; /* OpenGL context flags */ int ContextFlags; /* OpenGL context flags */

View File

@ -111,6 +111,10 @@ void FGAPIENTRY glutSetOption( GLenum eWhat, int value )
fgState.SampleNumber = value; fgState.SampleNumber = value;
break; break;
case GLUT_SKIP_STALE_MOTION_EVENTS:
fgState.SkipStaleMotion = value;
break;
default: default:
fgWarning( "glutSetOption(): missing enum handle %d", eWhat ); fgWarning( "glutSetOption(): missing enum handle %d", eWhat );
break; break;
@ -198,6 +202,9 @@ int FGAPIENTRY glutGet( GLenum eWhat )
case GLUT_MULTISAMPLE: case GLUT_MULTISAMPLE:
return fgState.SampleNumber; return fgState.SampleNumber;
case GLUT_SKIP_STALE_MOTION_EVENTS:
return fgState.SkipStaleMotion;
default: default:
return fgPlatformGlutGet ( eWhat ); return fgPlatformGlutGet ( eWhat );
break; break;

View File

@ -55,6 +55,9 @@
# define MIN(a,b) (((a)<(b)) ? (a) : (b)) # define MIN(a,b) (((a)<(b)) ? (a) : (b))
#endif #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: * TODO BEFORE THE STABLE RELEASE:
* *
@ -788,6 +791,13 @@ void fgPlatformProcessSingleEvent ( void )
case MotionNotify: 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 ); GETWINDOW( xmotion );
GETMOUSE( 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 ) void fgPlatformMainLoopPreliminaryWork ( void )
{ {
} }