From: John F. Fay Date: Wed, 16 Mar 2011 03:22:49 +0000 (+0000) Subject: Implementing John Tsiombikas' game mode patch per e-mail dated 3/15/11 8:04 PM X-Git-Url: http://git.mutantstargoat.com/user/nuclear/?a=commitdiff_plain;h=d4846df601fa224353c65fa332f603a85735b5d8;p=freeglut Implementing John Tsiombikas' game mode patch per e-mail dated 3/15/11 8:04 PM git-svn-id: svn+ssh://svn.code.sf.net/p/freeglut/code/trunk/freeglut/freeglut@897 7f0cb862-5218-0410-a997-914c9d46530a --- diff --git a/configure.ac b/configure.ac index 5c47541..ce6cd9b 100644 --- a/configure.ac +++ b/configure.ac @@ -29,9 +29,8 @@ if test "x$no_x" = xyes; then EXPORT_FLAGS="-DFREEGLUT_EXPORTS" else GL_LIBS="-lGL -lXext -lX11" - AC_CHECK_LIB([Xxf86vm], [XF86VidModeSwitchToMode], - [LIBXXF86VM=-lXxf86vm], [LIBXXF86VM=], - [$X_LIBS -lXext -lX11]) + AC_CHECK_LIB([Xxf86vm], [XF86VidModeSwitchToMode]) + AC_CHECK_LIB([Xrandr], [XRRQueryExtension]) LIBXI=-lXi VERSION_INFO="-version-info 12:0:9" EXPORT_FLAGS= @@ -49,6 +48,7 @@ CPPFLAGS="$CPPFLAGS $X_CFLAGS" AC_CHECK_HEADERS([usbhid.h errno.h GL/gl.h GL/glu.h GL/glx.h fcntl.h limits.h sys/ioctl.h sys/param.h sys/time.h]) AC_HEADER_TIME AC_CHECK_HEADERS([X11/extensions/xf86vmode.h], [], [], [#include ]) +AC_CHECK_HEADERS([X11/extensions/Xrandr.h]) AC_CHECK_HEADERS([X11/extensions/XI.h X11/extensions/XInput.h]) CPPFLAGS="$save_CPPFLAGS" diff --git a/src/freeglut_gamemode.c b/src/freeglut_gamemode.c index 01086b3..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; i # include # include -# ifdef HAVE_XXF86VM +# ifdef HAVE_X11_EXTENSIONS_XF86VMODE_H # include # endif +# ifdef HAVE_X11_EXTENSIONS_XRANDR_H +# include +# endif /* If GLX is too old, we will fail during runtime when multisampling is requested, but at least freeglut compiles. */ # ifndef GLX_SAMPLE_BUFFERS @@ -355,7 +358,12 @@ struct tagSFG_Display Atom State; /* The state atom */ Atom StateFullScreen; /* The full screen atom */ -#ifdef X_XF86VidModeGetModeLine +#ifdef HAVE_X11_EXTENSIONS_XRANDR_H + int prev_xsz, prev_ysz; + int prev_size_valid; +#endif /* HAVE_X11_EXTENSIONS_XRANDR_H */ + +#ifdef HAVE_X11_EXTENSIONS_XF86VMODE_H /* * XF86VidMode may be compilable even if it fails at runtime. Therefore, * the validity of the VidMode has to be tracked @@ -368,7 +376,7 @@ struct tagSFG_Display int DisplayPointerX; /* saved X location of the pointer */ int DisplayPointerY; /* saved Y location of the pointer */ -#endif /* X_XF86VidModeGetModeLine */ +#endif /* HAVE_X11_EXTENSIONS_XF86VMODE_H */ #elif TARGET_HOST_MS_WINDOWS HINSTANCE Instance; /* The application's instance */ diff --git a/src/freeglut_window.c b/src/freeglut_window.c index 800342d..fc9fc55 100644 --- a/src/freeglut_window.c +++ b/src/freeglut_window.c @@ -1316,6 +1316,12 @@ void fgOpenWindow( SFG_Window* window, const char* title, */ void fgCloseWindow( SFG_Window* window ) { + /* if we're in gamemode, call glutLeaveGameMode first to make sure the + * gamemode is properly closed before closing the window + */ + if (fgStructure.GameModeWindow != NULL) + glutLeaveGameMode(); + #if TARGET_HOST_POSIX_X11 if( window->Window.Context )