static fgMouseClickHandler MouseClickHandler = 0;
static fgMouseMotionHandler MouseMotionHandler = 0;
+// We need to flush all pending mouse move events past a mouse warp to avoid
+// a race condition ending in warping twice and having huge increments for the
+// second warp.
+// I am not aware of such a flush function in glut. So we emulate that by
+// ignoring mouse move events between a warp mouse and the next frame.
+static bool mouseWarped = false;
+
void fgRegisterIdleHandler(fgIdleHandler func)
{
IdleHandler = func;
static void GLUTmotion (int x, int y)
{
+ if (mouseWarped)
+ return;
if(MouseMotionHandler) (*MouseMotionHandler)(x, y);
}
static void GLUTidle()
{
if(IdleHandler) (*IdleHandler)();
+ mouseWarped = false;
}
static void GLUTdraw()
{
if(DrawHandler) (*DrawHandler)();
glutSwapBuffers();
+ mouseWarped = false;
}
static void GLUTreshape(int w, int h)
void fgWarpMouse(int x, int y)
{
+ mouseWarped = true;
glutWarpPointer(x, y);
}