X-Git-Url: http://git.mutantstargoat.com/user/nuclear/?a=blobdiff_plain;f=src%2Ffreeglut_main.c;h=c6d9c73bf273b15e45ab54950afef936ad451b89;hb=9aef0d00666699035d13b4889b9b2ddcbafb9bba;hp=ec86e80069a84155f563ff9ab3b81a3fa2ae630e;hpb=886f4e358243491aa4025222062bfae327d0cc1e;p=freeglut diff --git a/src/freeglut_main.c b/src/freeglut_main.c index ec86e80..c6d9c73 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; @@ -725,31 +725,34 @@ static void fghPrintEvent( XEvent *event ) "%02x", e->key_vector[ i ] ); } buf[ i ] = '\0'; - fgWarning( "%s: %s", fghTypeToString( e->type ), buf ); + fgWarning( "%s: window=0x%x, %s", fghTypeToString( e->type ), e->window, + buf ); break; } case Expose: { XExposeEvent *e = &event->xexpose; - fgWarning( "%s: (x,y)=(%d,%d), (width,height)=(%d,%d), count=%d", - fghTypeToString( e->type ), e->x, e->y, e->width, e->height, - e->count ); + fgWarning( "%s: window=0x%x, (x,y)=(%d,%d), (width,height)=(%d,%d), " + "count=%d", fghTypeToString( e->type ), e->window, e->x, + e->y, e->width, e->height, e->count ); break; } case GraphicsExpose: { XGraphicsExposeEvent *e = &event->xgraphicsexpose; - fgWarning( "%s: (x,y)=(%d,%d), (width,height)=(%d,%d), count=%d, " - "(major_code,minor_code)=(%d,%d)", - fghTypeToString( e->type ), e->x, e->y, e->width, e->height, - e->count, e->major_code, e->minor_code ); + fgWarning( "%s: drawable=0x%x, (x,y)=(%d,%d), (width,height)=(%d,%d), " + "count=%d, (major_code,minor_code)=(%d,%d)", + fghTypeToString( e->type ), e->drawable, e->x, e->y, + e->width, e->height, e->count, e->major_code, + e->minor_code ); break; } case NoExpose: { XNoExposeEvent *e = &event->xnoexpose; - fgWarning( "%s: (major_code,minor_code)=(%d,%d)", - fghTypeToString( e->type ), e->major_code, e->minor_code ); + fgWarning( "%s: drawable=0x%x, (major_code,minor_code)=(%d,%d)", + fghTypeToString( e->type ), e->drawable, e->major_code, + e->minor_code ); break; } @@ -1014,20 +1017,20 @@ void FGAPIENTRY glutMainLoopEvent( void ) * * GLUT presumably does this because it generally tries to treat * sub-windows the same as windows. - * - * XXX Technically, GETWINDOW( xconfigure ) and - * XXX {event.xconfigure} may not be legit ways to get at - * XXX data for CreateNotify events. In practice, the data - * XXX is in a union which is laid out much the same either - * XXX way. But if you want to split hairs, this isn't legit, - * XXX and we should instead duplicate some code. */ case CreateNotify: case ConfigureNotify: - GETWINDOW( xconfigure ); { - int width = event.xconfigure.width; - int height = event.xconfigure.height; + int width, height; + if( event.type == CreateNotify ) { + GETWINDOW( xcreatewindow ); + width = event.xcreatewindow.width; + height = event.xcreatewindow.height; + } else { + GETWINDOW( xconfigure ); + width = event.xconfigure.width; + height = event.xconfigure.height; + } if( ( width != window->State.OldWidth ) || ( height != window->State.OldHeight ) ) @@ -1077,11 +1080,14 @@ void FGAPIENTRY glutMainLoopEvent( void ) break; case MapNotify: + break; + case UnmapNotify: - /* - * If we never do anything with this, can we just not ask to - * get these messages? - */ + /* We get this when iconifying a window. */ + GETWINDOW( xunmap ); + fgSetWindow( window ); + INVOKE_WCB( *window, WindowStatus, ( GLUT_HIDDEN ) ); + window->State.Visible = GL_FALSE; break; case MappingNotify: @@ -1106,7 +1112,9 @@ void FGAPIENTRY glutMainLoopEvent( void ) * Sending this event, the X server can notify us that the window * has just acquired one of the three possible visibility states: * VisibilityUnobscured, VisibilityPartiallyObscured or - * VisibilityFullyObscured + * VisibilityFullyObscured. Note that we DO NOT receive a + * VisibilityNotify event when iconifying a window, we only get an + * UnmapNotify then. */ switch( event.xvisibility.state ) { @@ -1173,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; @@ -1226,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 ) ) ) @@ -1261,9 +1270,7 @@ void FGAPIENTRY glutMainLoopEvent( void ) event.xbutton.y ) ); } - - /* Trash the modifiers state */ - fgState.Modifiers = 0xffffffff; + fgState.Modifiers = INVALID_MODIFIERS; } break; @@ -1338,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 @@ -1392,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; } } } @@ -1592,13 +1599,13 @@ LRESULT CALLBACK fgWindowProc( HWND hWnd, UINT uMsg, WPARAM wParam, if( fgStructure.MenuContext ) wglMakeCurrent( window->Window.Device, - fgStructure.MenuContext->Context + fgStructure.MenuContext->MContext ); else { fgStructure.MenuContext = (SFG_MenuContext *)malloc( sizeof(SFG_MenuContext) ); - fgStructure.MenuContext->Context = + fgStructure.MenuContext->MContext = wglCreateContext( window->Window.Device ); } @@ -1763,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; @@ -1873,7 +1880,7 @@ LRESULT CALLBACK fgWindowProc( HWND hWnd, UINT uMsg, WPARAM wParam, ) ); - fgState.Modifiers = 0xffffffff; + fgState.Modifiers = INVALID_MODIFIERS; } break; @@ -1940,7 +1947,7 @@ LRESULT CALLBACK fgWindowProc( HWND hWnd, UINT uMsg, WPARAM wParam, ); } - fgState.Modifiers = 0xffffffff; + fgState.Modifiers = INVALID_MODIFIERS; } break ; @@ -2027,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; @@ -2110,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; @@ -2125,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;