From: Sven Panne Date: Sat, 2 Jul 2005 13:50:02 +0000 (+0000) Subject: Handle modifiers in MotionNotify events, too. This fixes bug #1227920 X-Git-Url: http://git.mutantstargoat.com/user/nuclear/?a=commitdiff_plain;h=e9a96a71a2feff9da7ccae395c5f316e67af3bd0;p=freeglut 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. git-svn-id: svn+ssh://svn.code.sf.net/p/freeglut/code/trunk/freeglut/freeglut@661 7f0cb862-5218-0410-a997-914c9d46530a --- diff --git a/ChangeLog b/ChangeLog index 48e51d5..73d94f6 100644 --- 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. diff --git a/src/freeglut_init.c b/src/freeglut_init.c index 13310f7..a8a59d4 100644 --- a/src/freeglut_init.c +++ b/src/freeglut_init.c @@ -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; diff --git a/src/freeglut_internal.h b/src/freeglut_internal.h index 9353ad9..80e88b3 100644 --- a/src/freeglut_internal.h +++ b/src/freeglut_internal.h @@ -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 */ diff --git a/src/freeglut_main.c b/src/freeglut_main.c index 7b53ea4..2fb73aa 100644 --- a/src/freeglut_main.c +++ b/src/freeglut_main.c @@ -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; diff --git a/src/freeglut_state.c b/src/freeglut_state.c index e8d2120..ff375b9 100644 --- a/src/freeglut_state.c +++ b/src/freeglut_state.c @@ -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;