X-Git-Url: http://git.mutantstargoat.com/user/nuclear/?a=blobdiff_plain;f=src%2Ffreeglut_gamemode.c;h=137f1ea54e6bb5a6e5553ff76d7bdda657689043;hb=d4846df601fa224353c65fa332f603a85735b5d8;hp=5f8faad1dbd07fbecb409948ed21c3a4d9ec44c6;hpb=6d46097d532c3c09537423f2a701717d390a3f05;p=freeglut diff --git a/src/freeglut_gamemode.c b/src/freeglut_gamemode.c index 5f8faad..137f1ea 100644 --- a/src/freeglut_gamemode.c +++ b/src/freeglut_gamemode.c @@ -40,20 +40,102 @@ /* -- PRIVATE FUNCTIONS ---------------------------------------------------- */ +static int xrandr_resize(int xsz, int ysz, int just_checking) +{ + int res = -1; + +#ifdef HAVE_X11_EXTENSIONS_XRANDR_H + int event_base, error_base; + Status st; + XRRScreenConfiguration *xrr_config; + XRRScreenSize *ssizes; + Rotation rot; + int i, ssizes_count, curr; + Time timestamp, cfg_timestamp; + + /* must check at runtime for the availability of the extension */ + if(!XRRQueryExtension(fgDisplay.Display, &event_base, &error_base)) { + return -1; + } + + if(!(xrr_config = XRRGetScreenInfo(fgDisplay.Display, fgDisplay.RootWindow))) { + fgWarning("XRRGetScreenInfo failed"); + return -1; + } + ssizes = XRRConfigSizes(xrr_config, &ssizes_count); + curr = XRRConfigCurrentConfiguration(xrr_config, &rot); + timestamp = XRRConfigTimes(xrr_config, &cfg_timestamp); + + if(xsz == ssizes[curr].width && ysz == ssizes[curr].height) { + /* no need to switch, we're already in the requested mode */ + res = 0; + goto done; + } + + for(i=0; ivdisplay, fgState.GameModeDepth, ( exactMatch ? refresh : fgState.GameModeRefresh ) ) ) { + if (!exactMatch) + { + /* Update the chosen refresh rate, otherwise a + * glutGameModeGet(GLUT_GAME_MODE_REFRESH_RATE) would not + * return the right values + */ + fgState.GameModeRefresh = refresh; + } + return i; } } @@ -257,13 +347,21 @@ static int fghCheckDisplayModes( GLboolean exactMatch, int displayModesCount, XF static GLboolean fghChangeDisplayMode( GLboolean haveToTest ) { GLboolean success = GL_FALSE; -#if TARGET_HOST_UNIX_X11 +#if TARGET_HOST_POSIX_X11 + + /* first try to use XRandR, then fallback to XF86VidMode */ +# ifdef HAVE_X11_EXTENSIONS_XRANDR_H + if(xrandr_resize(fgState.GameModeSize.X, fgState.GameModeSize.Y, haveToTest) != -1) { + return GL_TRUE; + } +# endif + /* * This highly depends on the XFree86 extensions, * not approved as X Consortium standards */ -# ifdef X_XF86VidModeGetAllModeLines +# ifdef HAVE_X11_EXTENSIONS_XF86VMODE_H /* * This is also used by applcations which check modes by calling @@ -316,29 +414,44 @@ static GLboolean fghChangeDisplayMode( GLboolean haveToTest ) # endif -#elif TARGET_HOST_WIN32 || TARGET_HOST_WINCE +#elif TARGET_HOST_MS_WINDOWS DEVMODE devMode; char *fggmstr = NULL; success = GL_FALSE; - EnumDisplaySettings( NULL, -1, &devMode ); - devMode.dmFields |= DM_PELSWIDTH | DM_PELSHEIGHT | DM_BITSPERPEL | DM_DISPLAYFREQUENCY; + EnumDisplaySettings( fgDisplay.DisplayName, -1, &devMode ); + devMode.dmFields = 0; - devMode.dmPelsWidth = fgState.GameModeSize.X; - devMode.dmPelsHeight = fgState.GameModeSize.Y; - devMode.dmBitsPerPel = fgState.GameModeDepth; - devMode.dmDisplayFrequency = fgState.GameModeRefresh; - devMode.dmFields = DM_PELSWIDTH | DM_PELSHEIGHT | DM_BITSPERPEL | DM_DISPLAYFREQUENCY; + if (fgState.GameModeSize.X!=-1) + { + devMode.dmPelsWidth = fgState.GameModeSize.X; + devMode.dmFields |= DM_PELSWIDTH; + } + if (fgState.GameModeSize.Y!=-1) + { + devMode.dmPelsHeight = fgState.GameModeSize.Y; + devMode.dmFields |= DM_PELSHEIGHT; + } + if (fgState.GameModeDepth!=-1) + { + devMode.dmBitsPerPel = fgState.GameModeDepth; + devMode.dmFields |= DM_BITSPERPEL; + } + if (fgState.GameModeRefresh!=-1) + { + devMode.dmDisplayFrequency = fgState.GameModeRefresh; + devMode.dmFields |= DM_DISPLAYFREQUENCY; + } - switch ( ChangeDisplaySettingsEx(NULL, &devMode, NULL, haveToTest ? CDS_TEST : CDS_FULLSCREEN , NULL) ) + switch ( ChangeDisplaySettingsEx(fgDisplay.DisplayName, &devMode, NULL, haveToTest ? CDS_TEST : CDS_FULLSCREEN , NULL) ) { case DISP_CHANGE_SUCCESSFUL: success = GL_TRUE; /* update vars in case if windows switched to proper mode */ - EnumDisplaySettings( NULL, FREEGLUT_ENUM_CURRENT_SETTINGS, &devMode ); + EnumDisplaySettings( fgDisplay.DisplayName, FREEGLUT_ENUM_CURRENT_SETTINGS, &devMode ); fgState.GameModeSize.X = devMode.dmPelsWidth; fgState.GameModeSize.Y = devMode.dmPelsHeight; fgState.GameModeDepth = devMode.dmBitsPerPel; @@ -380,7 +493,7 @@ static GLboolean fghChangeDisplayMode( GLboolean haveToTest ) */ void FGAPIENTRY glutGameModeString( const char* string ) { - int width = 640, height = 480, depth = 16, refresh = 72; + int width = -1, height = -1, depth = -1, refresh = -1; FREEGLUT_EXIT_IF_NOT_INITIALISED ( "glutGameModeString" ); @@ -404,12 +517,14 @@ void FGAPIENTRY glutGameModeString( const char* string ) ); /* Hopefully it worked, and if not, we still have the default values */ - fgState.GameModeSize.X = width; - fgState.GameModeSize.Y = height; - fgState.GameModeDepth = depth; - fgState.GameModeRefresh = refresh; + if ( width > 0 ) fgState.GameModeSize.X = width; + if ( height > 0 ) fgState.GameModeSize.Y = height; + if ( depth > 0 ) fgState.GameModeDepth = depth; + if ( refresh > 0 ) fgState.GameModeRefresh = refresh; } + + /* * Enters the game mode */ @@ -429,17 +544,16 @@ int FGAPIENTRY glutEnterGameMode( void ) } fgStructure.GameModeWindow = fgCreateWindow( - NULL, "FREEGLUT", 0, 0, - fgState.GameModeSize.X, fgState.GameModeSize.Y, GL_TRUE, GL_FALSE + NULL, "FREEGLUT", GL_TRUE, 0, 0, + GL_TRUE, fgState.GameModeSize.X, fgState.GameModeSize.Y, + GL_TRUE, GL_FALSE ); fgStructure.GameModeWindow->State.Width = fgState.GameModeSize.X; fgStructure.GameModeWindow->State.Height = fgState.GameModeSize.Y; fgStructure.GameModeWindow->State.NeedToResize = GL_TRUE; - fgStructure.GameModeWindow->State.IsGameMode = GL_TRUE; - -#if TARGET_HOST_UNIX_X11 +#if TARGET_HOST_POSIX_X11 /* * Sync needed to avoid a real race, the Xserver must have really created @@ -485,7 +599,7 @@ int FGAPIENTRY glutEnterGameMode( void ) fgState.GameModeSize.X/2, fgState.GameModeSize.Y/2 ); -# ifdef X_XF86VidModeSetViewPort +# ifdef HAVE_X11_EXTENSIONS_XF86VMODE_H if( fgDisplay.DisplayModeValid ) { @@ -541,12 +655,10 @@ void FGAPIENTRY glutLeaveGameMode( void ) freeglut_return_if_fail( fgStructure.GameModeWindow ); - fgStructure.GameModeWindow->State.IsGameMode = GL_FALSE; - fgAddToWindowDestroyList( fgStructure.GameModeWindow ); fgStructure.GameModeWindow = NULL; -#if TARGET_HOST_UNIX_X11 +#if TARGET_HOST_POSIX_X11 XUngrabPointer( fgDisplay.Display, CurrentTime ); XUngrabKeyboard( fgDisplay.Display, CurrentTime );