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: https://svn.code.sf.net/p/freeglut/code/trunk@661 7f0cb862-5218-0410-a997-914c9d46530a
This commit is contained in:
spanne 2005-07-02 13:50:02 +00:00
parent 4e334977a1
commit c4c3661612
5 changed files with 31 additions and 26 deletions

View File

@ -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.

View 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;

View 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 */

View 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,15 +1181,16 @@ 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;
case ButtonRelease:
@ -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;

View 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;