X-Git-Url: http://git.mutantstargoat.com/user/nuclear/?a=blobdiff_plain;f=src%2Ffreeglut_gamemode.c;h=137f1ea54e6bb5a6e5553ff76d7bdda657689043;hb=d4846df601fa224353c65fa332f603a85735b5d8;hp=24a8be153e875e97ec31e204bacba25871eda792;hpb=577caff92e03ec8cbe4ca36448697939ed5d7dfc;p=freeglut diff --git a/src/freeglut_gamemode.c b/src/freeglut_gamemode.c index 24a8be1..137f1ea 100644 --- a/src/freeglut_gamemode.c +++ b/src/freeglut_gamemode.c @@ -40,6 +40,65 @@ /* -- 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; } } @@ -259,11 +349,19 @@ static GLboolean fghChangeDisplayMode( GLboolean haveToTest ) GLboolean success = GL_FALSE; #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 @@ -419,10 +517,10 @@ 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; } @@ -501,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 ) {