Handle modifiers in MotionNotify events, too. This fixes bug #1227920
authorSven Panne <sven.panne@aedion.de>
Sat, 2 Jul 2005 13:50:02 +0000 (13:50 +0000)
committerSven Panne <sven.panne@aedion.de>
Sat, 2 Jul 2005 13:50:02 +0000 (13:50 +0000)
(glutGetModifiers not set/allowed in mouse callbacks). In addition, some related
cleanup has been done.

git-svn-id: svn+ssh://svn.code.sf.net/p/freeglut/code/trunk/freeglut/freeglut@661 7f0cb862-5218-0410-a997-914c9d46530a

ChangeLog
src/freeglut_init.c
src/freeglut_internal.h
src/freeglut_main.c
src/freeglut_state.c

index 48e51d5..73d94f6 100644 (file)
--- a/ChangeLog
+++ b/ChangeLog
@@ -1092,3 +1092,7 @@ linking troubles for the examples.
 fixes bug #961938 (Executable bit set on non exe files).
 
 (283) Partial fixes for bug #1218900 (freeglut-2.4.0 on FreeBSD).
+
+(284) Handle modifiers in MotionNotify events, too. This fixes bug
+#1227920 (glutGetModifiers not set/allowed in mouse callbacks). In
+addition, some related cleanup has been done.
index 13310f7..a8a59d4 100644 (file)
@@ -61,7 +61,7 @@ SFG_State fgState = { { -1, -1, GL_FALSE },  /* Position */
                       GL_FALSE,              /* GLDebugSwitch */
                       GL_FALSE,              /* XSyncSwitch */
                       GLUT_KEY_REPEAT_ON,    /* KeyRepeat */
-                      0xffffffff,            /* Modifiers */
+                      INVALID_MODIFIERS,     /* Modifiers */
                       0,                     /* FPSInterval */
                       0,                     /* SwapCount */
                       0,                     /* SwapTime */
@@ -274,7 +274,7 @@ void fgDeinitialize( void )
     fgState.ExecState           = GLUT_EXEC_STATE_INIT;
 
     fgState.KeyRepeat       = GLUT_KEY_REPEAT_ON;
-    fgState.Modifiers       = 0xffffffff;
+    fgState.Modifiers       = INVALID_MODIFIERS;
 
     fgState.GameModeSize.X  = 640;
     fgState.GameModeSize.Y  = 480;
index 9353ad9..80e88b3 100644 (file)
@@ -126,6 +126,8 @@ LONG WINAPI ChangeDisplaySettingsExW(LPCWSTR,LPDEVMODEW,HWND,DWORD,LPVOID);
 #    define  FALSE  0
 #endif
 
+#define INVALID_MODIFIERS 0xffffffff
+
 /* -- GLOBAL TYPE DEFINITIONS ---------------------------------------------- */
 
 /* Freeglut callbacks type definitions */
index 7b53ea4..2fb73aa 100644 (file)
@@ -495,17 +495,17 @@ static void fghSleepForEvents( void )
 
 #if TARGET_HOST_UNIX_X11
 /*
- * Returns GLUT modifier mask for an XEvent.
+ * Returns GLUT modifier mask for the state field of an X11 event.
  */
-static int fghGetXModifiers( XEvent *event )
+static int fghGetXModifiers( int state )
 {
     int ret = 0;
 
-    if( event->xkey.state & ( ShiftMask | LockMask ) )
+    if( state & ( ShiftMask | LockMask ) )
         ret |= GLUT_ACTIVE_SHIFT;
-    if( event->xkey.state & ControlMask )
+    if( state & ControlMask )
         ret |= GLUT_ACTIVE_CTRL;
-    if( event->xkey.state & Mod1Mask )
+    if( state & Mod1Mask )
         ret |= GLUT_ACTIVE_ALT;
 
     return ret;
@@ -1181,14 +1181,15 @@ void FGAPIENTRY glutMainLoopEvent( void )
              * XXX track ButtonPress/ButtonRelease events in our own
              * XXX bit-mask?
              */
-#define BUTTON_MASK \
-  ( Button1Mask | Button2Mask | Button3Mask | Button4Mask | Button5Mask )
-            if ( event.xmotion.state & BUTTON_MASK )
+           fgState.Modifiers = fghGetXModifiers( event.xmotion.state );
+            if ( event.xmotion.state & ( Button1Mask | Button2Mask | Button3Mask | Button4Mask | Button5Mask ) ) {
                 INVOKE_WCB( *window, Motion, ( event.xmotion.x,
                                                event.xmotion.y ) );
-            else
+            } else {
                 INVOKE_WCB( *window, Passive, ( event.xmotion.x,
                                                 event.xmotion.y ) );
+           }
+           fgState.Modifiers = INVALID_MODIFIERS;
         }
         break;
 
@@ -1234,7 +1235,7 @@ void FGAPIENTRY glutMainLoopEvent( void )
                 ! FETCH_WCB( *window, MouseWheel ) )
                 break;
 
-            fgState.Modifiers = fghGetXModifiers( &event );
+            fgState.Modifiers = fghGetXModifiers( event.xbutton.state );
 
             /* Finally execute the mouse or mouse wheel callback */
             if( ( button < glutDeviceGet ( GLUT_NUM_MOUSE_BUTTONS ) ) || ( ! FETCH_WCB( *window, MouseWheel ) ) )
@@ -1269,9 +1270,7 @@ void FGAPIENTRY glutMainLoopEvent( void )
                                                        event.xbutton.y )
                     );
             }
-
-            /* Trash the modifiers state */
-            fgState.Modifiers = 0xffffffff;
+            fgState.Modifiers = INVALID_MODIFIERS;
         }
         break;
 
@@ -1346,11 +1345,11 @@ void FGAPIENTRY glutMainLoopEvent( void )
                     if( keyboard_cb )
                     {
                         fgSetWindow( window );
-                        fgState.Modifiers = fghGetXModifiers( &event );
+                        fgState.Modifiers = fghGetXModifiers( event.xkey.state );
                         keyboard_cb( asciiCode[ 0 ],
                                      event.xkey.x, event.xkey.y
                         );
-                        fgState.Modifiers = 0xffffffff;
+                        fgState.Modifiers = INVALID_MODIFIERS;
                     }
                 }
                 else
@@ -1400,9 +1399,9 @@ void FGAPIENTRY glutMainLoopEvent( void )
                     if( special_cb && (special != -1) )
                     {
                         fgSetWindow( window );
-                        fgState.Modifiers = fghGetXModifiers( &event );
+                        fgState.Modifiers = fghGetXModifiers( event.xkey.state );
                         special_cb( special, event.xkey.x, event.xkey.y );
-                        fgState.Modifiers = 0xffffffff;
+                        fgState.Modifiers = INVALID_MODIFIERS;
                     }
                 }
             }
@@ -1771,7 +1770,7 @@ LRESULT CALLBACK fgWindowProc( HWND hWnd, UINT uMsg, WPARAM wParam,
             INVOKE_WCB( *window, Passive, ( window->State.MouseX,
                                             window->State.MouseY ) );
 
-        fgState.Modifiers = 0xffffffff;
+        fgState.Modifiers = INVALID_MODIFIERS;
     }
     break;
 
@@ -1881,7 +1880,7 @@ LRESULT CALLBACK fgWindowProc( HWND hWnd, UINT uMsg, WPARAM wParam,
             )
         );
 
-        fgState.Modifiers = 0xffffffff;
+        fgState.Modifiers = INVALID_MODIFIERS;
     }
     break;
 
@@ -1948,7 +1947,7 @@ LRESULT CALLBACK fgWindowProc( HWND hWnd, UINT uMsg, WPARAM wParam,
                 );
             }
 
-        fgState.Modifiers = 0xffffffff;
+        fgState.Modifiers = INVALID_MODIFIERS;
     }
     break ;
 
@@ -2035,7 +2034,7 @@ LRESULT CALLBACK fgWindowProc( HWND hWnd, UINT uMsg, WPARAM wParam,
                           window->State.MouseX, window->State.MouseY )
             );
 
-        fgState.Modifiers = 0xffffffff;
+        fgState.Modifiers = INVALID_MODIFIERS;
     }
     break;
 
@@ -2118,7 +2117,7 @@ LRESULT CALLBACK fgWindowProc( HWND hWnd, UINT uMsg, WPARAM wParam,
                           window->State.MouseX, window->State.MouseY )
             );
 
-        fgState.Modifiers = 0xffffffff;
+        fgState.Modifiers = INVALID_MODIFIERS;
     }
     break;
 
@@ -2133,7 +2132,7 @@ LRESULT CALLBACK fgWindowProc( HWND hWnd, UINT uMsg, WPARAM wParam,
                     ( (char)wParam,
                       window->State.MouseX, window->State.MouseY )
         );
-        fgState.Modifiers = 0xffffffff;
+        fgState.Modifiers = INVALID_MODIFIERS;
     }
     break;
 
index e8d2120..ff375b9 100644 (file)
@@ -579,7 +579,7 @@ int FGAPIENTRY glutDeviceGet( GLenum eWhat )
 int FGAPIENTRY glutGetModifiers( void )
 {
     FREEGLUT_EXIT_IF_NOT_INITIALISED ( "glutGetModifiers" );
-    if( fgState.Modifiers == 0xffffffff )
+    if( fgState.Modifiers == INVALID_MODIFIERS )
     {
         fgWarning( "glutGetModifiers() called outside an input callback" );
         return 0;