Merge remote branch 'origin/master' into gallium_draw_llvm
[mesa.git] / src / glut / glx / glut_event.c
index d2c2c4810ff916fbf181807aebbd24fcfaefc91c..4cdb814d76a40d0b075d13e3a5fe85ee9ae89be1 100644 (file)
@@ -24,7 +24,7 @@
 # ifdef __sgi
 #  include <bstring.h>    /* prototype for bzero used by FD_ZERO */
 # endif
-# if (defined(SVR4) || defined(CRAY) || defined(AIXV3)) && !defined(FD_SETSIZE)
+# if (defined(__FreeBSD__) || defined(SVR4) || defined(CRAY) || defined(AIXV3)) && !defined(FD_SETSIZE)
 #  include <sys/select.h> /* select system call interface */
 #  ifdef luna
 #   include <sysent.h>
@@ -103,13 +103,13 @@ Atom __glutMotifHints = None;
 unsigned int __glutModifierMask = (unsigned int) ~0;
 int __glutWindowDamaged = 0;
 
-void APIENTRY
+void GLUTAPIENTRY
 glutIdleFunc(GLUTidleCB idleFunc)
 {
   __glutIdleFunc = idleFunc;
 }
 
-void APIENTRY
+void GLUTAPIENTRY
 glutTimerFunc(unsigned int interval, GLUTtimerCB timerFunc, int value)
 {
   GLUTtimer *timer, *other;
@@ -172,10 +172,14 @@ handleTimeouts(void)
   GETTIMEOFDAY(&now);
   while (IS_AT_OR_AFTER(__glutTimerList->timeout, now)) {
     timer = __glutTimerList;
+    /* call the timer function */
     timer->func(timer->value);
+    /* remove from the linked list */
     __glutTimerList = timer->next;
+    /* put this timer on the "free" list */
     timer->next = freeTimerList;
     freeTimerList = timer;
+
     if (!__glutTimerList)
       break;
   }
@@ -215,7 +219,7 @@ __glutPostRedisplay(GLUTwindow * window, int layerMask)
 }
 
 /* CENTRY */
-void APIENTRY
+void GLUTAPIENTRY
 glutPostRedisplay(void)
 {
   __glutPostRedisplay(__glutCurrentWindow, GLUT_REDISPLAY_WORK);
@@ -225,7 +229,7 @@ glutPostRedisplay(void)
    glutSetWindow call (entailing an expensive OpenGL context switch),
    particularly useful when multiple windows need redisplays posted at
    the same times.  See also glutPostWindowOverlayRedisplay. */
-void APIENTRY
+void GLUTAPIENTRY
 glutPostWindowRedisplay(int win)
 {
   __glutPostRedisplay(__glutWindowList[win - 1], GLUT_REDISPLAY_WORK);
@@ -438,11 +442,16 @@ processEventsAndTimeouts(void)
           __glutFinishMenu(event.xbutton.window, event.xbutton.x, event.xbutton.y);
         } else {
           window = __glutGetWindow(event.xbutton.window);
+          /* added button check for mice with > 3 buttons */
           if (window) {
             GLUTmenu *menu;
            int menuNum;
 
-            menuNum = window->menu[event.xbutton.button - 1];
+            if (event.xbutton.button <= GLUT_MAX_MENUS)
+              menuNum = window->menu[event.xbutton.button - 1];
+            else
+              menuNum = 0;
+
             /* Make sure that __glutGetMenuByNum is only called if there
               really is a menu present. */
             if ((menuNum > 0) && (menu = __glutGetMenuByNum(menuNum))) {
@@ -655,6 +664,7 @@ processEventsAndTimeouts(void)
          case XK_KP_Delete: /* Introduced in X11R6. */
             /* The Delete character is really an ASCII key. */
             __glutSetWindow(window);
+            assert(keyboard);
             keyboard(127,  /* ASCII Delete character. */
               event.xkey.x, event.xkey.y);
             goto skip;
@@ -1302,6 +1312,7 @@ processWindowWorkList(GLUTwindow * window)
   }
   /* Combine workMask with window->workMask to determine what
      finish and debug work there is. */
+  assert(window);
   workMask |= window->workMask;
 
   if (workMask & GLUT_FINISH_WORK) {
@@ -1312,7 +1323,12 @@ processWindowWorkList(GLUTwindow * window)
        is where the finish works gets queued for indirect
        contexts. */
     __glutSetWindow(window);
-    glFinish();
+#if !defined(_WIN32)
+    if (!window->isDirect)
+#endif
+    {
+       glFinish();
+    }
   }
   if (workMask & GLUT_DEBUG_WORK) {
     __glutSetWindow(window);
@@ -1329,9 +1345,7 @@ processWindowWorkList(GLUTwindow * window)
   }
 }
 
-#ifndef _WIN32
 static  /* X11 implementations do not need this global. */
-#endif
 void
 __glutProcessWindowWorkLists(void)
 {
@@ -1351,7 +1365,7 @@ __glutProcessWindowWorkLists(void)
 }
 
 /* CENTRY */
-void APIENTRY
+void GLUTAPIENTRY
 glutMainLoop(void)
 {
 #if !defined(_WIN32)