X-Git-Url: http://git.mutantstargoat.com/user/nuclear/?a=blobdiff_plain;f=src%2Ffreeglut_gamemode.c;h=313f546fd205fd7590e7620b42fbb5ce54c95250;hb=5288d8e11323c88acdec3af66ddf18c640c363a1;hp=404b6c12c9758b7f9f7d9cffaa26ccf2492a6c36;hpb=f3841b1993425e78f3251567c83ccff338007d7b;p=freeglut diff --git a/src/freeglut_gamemode.c b/src/freeglut_gamemode.c index 404b6c1..313f546 100644 --- a/src/freeglut_gamemode.c +++ b/src/freeglut_gamemode.c @@ -59,12 +59,12 @@ static void fghRememberState( void ) * Remember the current ViewPort location of the screen to be able to * restore the ViewPort on LeaveGameMode(): */ - XF86VidModeGetViewPort( - fgDisplay.Display, - fgDisplay.Screen, - &fgDisplay.DisplayViewPortX, - &fgDisplay.DisplayViewPortY - ); + if( !XF86VidModeGetViewPort( + fgDisplay.Display, + fgDisplay.Screen, + &fgDisplay.DisplayViewPortX, + &fgDisplay.DisplayViewPortY ) ) + fgWarning( "XF86VidModeGetViewPort failed" ); /* * Remember the current pointer location before going fullscreen @@ -92,7 +92,7 @@ static void fghRememberState( void ) ); if( !fgDisplay.DisplayModeValid ) - fgWarning( "Runtime use of XF86VidModeGetModeLine failed." ); + fgWarning( "XF86VidModeGetModeLine failed" ); # else /* @@ -144,12 +144,16 @@ static void fghRestoreState( void ) XF86VidModeModeInfo** displayModes; int i, displayModesCount; - XF86VidModeGetAllModeLines( - fgDisplay.Display, - fgDisplay.Screen, - &displayModesCount, - &displayModes - ); + if( !XF86VidModeGetAllModeLines( + fgDisplay.Display, + fgDisplay.Screen, + &displayModesCount, + &displayModes ) ) + { + fgWarning( "XF86VidModeGetAllModeLines failed" ); + return; + } + /* * Check every of the modes looking for one that matches our demands. @@ -161,17 +165,22 @@ static void fghRestoreState( void ) displayModes[ i ]->vdisplay == fgDisplay.DisplayMode.vdisplay && displayModes[ i ]->dotclock == fgDisplay.DisplayModeClock ) { - XF86VidModeSwitchToMode( - fgDisplay.Display, - fgDisplay.Screen, - displayModes[ i ] - ); - XF86VidModeSetViewPort( - fgDisplay.Display, - fgDisplay.Screen, - fgDisplay.DisplayViewPortX, - fgDisplay.DisplayViewPortY - ); + if( !XF86VidModeSwitchToMode( + fgDisplay.Display, + fgDisplay.Screen, + displayModes[ i ] ) ) + { + fgWarning( "XF86VidModeSwitchToMode failed" ); + break; + } + + if( !XF86VidModeSetViewPort( + fgDisplay.Display, + fgDisplay.Screen, + fgDisplay.DisplayViewPortX, + fgDisplay.DisplayViewPortY ) ) + fgWarning( "XF86VidModeSetViewPort failed" ); + /* * For the case this would be the last X11 call the application @@ -234,43 +243,61 @@ static GLboolean fghChangeDisplayMode( GLboolean haveToTest ) if( haveToTest || fgDisplay.DisplayModeValid ) { XF86VidModeModeInfo** displayModes; - int i, displayModesCount; + int i, ignoreRefreshRate, displayModesCount; - XF86VidModeGetAllModeLines( - fgDisplay.Display, - fgDisplay.Screen, - &displayModesCount, - &displayModes - ); + if( !XF86VidModeGetAllModeLines( + fgDisplay.Display, + fgDisplay.Screen, + &displayModesCount, + &displayModes ) ) + { + fgWarning( "XF86VidModeGetAllModeLines failed" ); + return success; + } - /* Check every of the modes looking for one that matches our demands */ - for( i = 0; i < displayModesCount; i++ ) + + /* + * Check every of the modes looking for one that matches our demands, + * ignoring the refresh rate if no exact match could be found. + */ + for( ignoreRefreshRate = 0; + !success && ( ignoreRefreshRate <= 1 ); + ignoreRefreshRate++) { - if( fghCheckDisplayMode( displayModes[ i ]->hdisplay, - displayModes[ i ]->vdisplay, - fgState.GameModeDepth, - fgState.GameModeRefresh ) ) + for( i = 0; + !success && ( i < displayModesCount ); + i++ ) { - /* OKi, this is the display mode we have been looking for... */ - if( !haveToTest ) { - XF86VidModeSwitchToMode( - fgDisplay.Display, - fgDisplay.Screen, - displayModes[ i ] - ); - } - success = GL_TRUE; - break; + /* Compute the displays refresh rate, dotclock comes in kHz. */ + int refresh = ( displayModes[ i ]->dotclock * 1000 ) / + ( displayModes[ i ]->htotal * displayModes[ i ]->vtotal ); + + success = fghCheckDisplayMode( displayModes[ i ]->hdisplay, + displayModes[ i ]->vdisplay, + fgState.GameModeDepth, + ( ignoreRefreshRate ? fgState.GameModeRefresh : refresh ) ); } } + + if( !haveToTest && success ) { + if( !XF86VidModeSwitchToMode( + fgDisplay.Display, + fgDisplay.Screen, + displayModes[ i ] ) ) + fgWarning( "XF86VidModeSwitchToMode failed" ); + } + XFree( displayModes ); } # else + /* * XXX warning fghChangeDisplayMode: missing XFree86 video mode extensions, * XXX game mode will not change screen resolution when activated */ + success = GL_TRUE; + # endif #elif TARGET_HOST_WIN32 || TARGET_HOST_WINCE @@ -411,24 +438,12 @@ int FGAPIENTRY glutEnterGameMode( void ) #if TARGET_HOST_UNIX_X11 - /* Move the window up to the topleft corner */ - XMoveWindow( fgDisplay.Display, fgStructure.Window->Window.Handle, 0, 0 ); - /* * Sync needed to avoid a real race, the Xserver must have really created * the window before we can grab the pointer into it: */ XSync( fgDisplay.Display, False ); - /* Move the Pointer to the middle of the fullscreen window */ - XWarpPointer( - fgDisplay.Display, - None, - fgDisplay.RootWindow, - 0, 0, 0, 0, - fgState.GameModeSize.X/2, fgState.GameModeSize.Y/2 - ); - /* * Grab the pointer to confine it into the window after the calls to * XWrapPointer() which ensure that the pointer really enters the window. @@ -458,6 +473,15 @@ int FGAPIENTRY glutEnterGameMode( void ) CurrentTime ); + /* Move the Pointer to the middle of the fullscreen window */ + XWarpPointer( + fgDisplay.Display, + None, + fgDisplay.RootWindow, + 0, 0, 0, 0, + fgState.GameModeSize.X/2, fgState.GameModeSize.Y/2 + ); + # ifdef X_XF86VidModeSetViewPort if( fgDisplay.DisplayModeValid ) @@ -466,7 +490,8 @@ int FGAPIENTRY glutEnterGameMode( void ) Window child; /* Change to viewport to the window topleft edge: */ - XF86VidModeSetViewPort( fgDisplay.Display, fgDisplay.Screen, 0, 0 ); + if( !XF86VidModeSetViewPort( fgDisplay.Display, fgDisplay.Screen, 0, 0 ) ) + fgWarning( "XF86VidModeSetViewPort failed" ); /* * Final window repositioning: It could be avoided using an undecorated @@ -477,14 +502,14 @@ int FGAPIENTRY glutEnterGameMode( void ) /* Get the current postion of the drawable area on screen */ XTranslateCoordinates( fgDisplay.Display, - fgStructure.Window->Window.Handle, + fgStructure.CurrentWindow->Window.Handle, fgDisplay.RootWindow, 0, 0, &x, &y, &child ); /* Move the decorataions out of the topleft corner of the display */ - XMoveWindow( fgDisplay.Display, fgStructure.Window->Window.Handle, + XMoveWindow( fgDisplay.Display, fgStructure.CurrentWindow->Window.Handle, -x, -y); }