Extracted some common code to a subroutine, in glutMainLoopEvent().

(The common code was a snippet to compute X keyboard modifiers as a
bit-mask of GLUT symbols.)


git-svn-id: https://svn.code.sf.net/p/freeglut/code/trunk@288 7f0cb862-5218-0410-a997-914c9d46530a
This commit is contained in:
rkrolib 2003-11-03 10:51:26 +00:00
parent 9b944ec457
commit cced36cf2b

View File

@ -431,6 +431,24 @@ static void fgSleepForEvents( void )
#endif #endif
} }
/*
* Returns GLUT modifier mask for an XEvent.
*/
int fgGetXModifiers(XEvent *event)
{
int ret = 0;
if( event->xkey.state & ( ShiftMask | LockMask ) )
ret |= GLUT_ACTIVE_SHIFT;
if( event->xkey.state & ControlMask )
ret |= GLUT_ACTIVE_CTRL;
if( event->xkey.state & Mod1Mask )
ret |= GLUT_ACTIVE_ALT;
return ret;
}
/* -- INTERFACE FUNCTIONS -------------------------------------------------- */ /* -- INTERFACE FUNCTIONS -------------------------------------------------- */
/* /*
@ -441,7 +459,6 @@ void FGAPIENTRY glutMainLoopEvent( void )
#if TARGET_HOST_UNIX_X11 #if TARGET_HOST_UNIX_X11
SFG_Window* window; SFG_Window* window;
XEvent event; XEvent event;
int modifiers;
/* /*
* This code was repeated constantly, so here it goes into a definition: * This code was repeated constantly, so here it goes into a definition:
@ -759,14 +776,10 @@ void FGAPIENTRY glutMainLoopEvent( void )
fgSetWindow( window ); fgSetWindow( window );
modifiers = 0; /*
if( event.xbutton.state & ( ShiftMask | LockMask ) ) * XXX Why don't we use {window}? Other code here does...
modifiers |= GLUT_ACTIVE_SHIFT; */
if( event.xbutton.state & ControlMask ) fgStructure.Window->State.Modifiers = fgGetXModifiers( &event );
modifiers |= GLUT_ACTIVE_CTRL;
if( event.xbutton.state & Mod1Mask )
modifiers |= GLUT_ACTIVE_ALT;
fgStructure.Window->State.Modifiers = modifiers;
/* /*
* Finally execute the mouse or mouse wheel callback * Finally execute the mouse or mouse wheel callback
@ -863,25 +876,9 @@ void FGAPIENTRY glutMainLoopEvent( void )
if( keyboard_cb ) if( keyboard_cb )
{ {
fgSetWindow( window ); fgSetWindow( window );
window->State.Modifiers = fgGetXModifiers( &event );
/*
* Remember the current modifiers state
*/
modifiers = 0;
if( event.xkey.state & ( ShiftMask | LockMask ) )
modifiers |= GLUT_ACTIVE_SHIFT;
if( event.xkey.state & ControlMask )
modifiers |= GLUT_ACTIVE_CTRL;
if( event.xkey.state & Mod1Mask )
modifiers |= GLUT_ACTIVE_ALT;
window->State.Modifiers = modifiers;
keyboard_cb( asciiCode[ 0 ], keyboard_cb( asciiCode[ 0 ],
event.xkey.x, event.xkey.y ); event.xkey.x, event.xkey.y );
/*
* Trash the modifiers state
*/
window->State.Modifiers = 0xffffffff; window->State.Modifiers = 0xffffffff;
} }
} }
@ -932,24 +929,8 @@ void FGAPIENTRY glutMainLoopEvent( void )
if( special_cb && (special != -1) ) if( special_cb && (special != -1) )
{ {
fgSetWindow( window ); fgSetWindow( window );
window->State.Modifiers = fgGetXModifiers( &event );
/*
* Remember the current modifiers state
*/
modifiers = 0;
if( event.xkey.state & ( ShiftMask | LockMask ) )
modifiers |= GLUT_ACTIVE_SHIFT;
if( event.xkey.state & ControlMask )
modifiers |= GLUT_ACTIVE_CTRL;
if( event.xkey.state & Mod1Mask )
modifiers |= GLUT_ACTIVE_ALT;
window->State.Modifiers = modifiers;
special_cb( special, event.xkey.x, event.xkey.y ); special_cb( special, event.xkey.x, event.xkey.y );
/*
* Trash the modifiers state
*/
window->State.Modifiers = 0xffffffff; window->State.Modifiers = 0xffffffff;
} }
} }