X-Git-Url: http://git.mutantstargoat.com/user/nuclear/?a=blobdiff_plain;f=src%2FCommon%2Ffreeglut_gamemode.c;h=d3df2bcd151deedc020e3368a2d6a02cdb6673c4;hb=83a7f1444d1388983a7b756dde26b0cc74101b13;hp=48991a62e24baae8b16fcc902c9e84515f9c188d;hpb=b7cef0f768b51ec26b78e42ad5fdd5ea9bebf45a;p=freeglut diff --git a/src/Common/freeglut_gamemode.c b/src/Common/freeglut_gamemode.c index 48991a6..d3df2bc 100644 --- a/src/Common/freeglut_gamemode.c +++ b/src/Common/freeglut_gamemode.c @@ -39,9 +39,9 @@ /* -- PRIVATE FUNCTIONS ---------------------------------------------------- */ -extern void fghRememberState( void ); -extern void fghRestoreState( void ); -extern GLboolean fghChangeDisplayMode( GLboolean haveToTest ); +extern void fgPlatformRememberState( void ); +extern void fgPlatformRestoreState( void ); +extern GLboolean fgPlatformChangeDisplayMode( GLboolean haveToTest ); #if TARGET_HOST_POSIX_X11 @@ -53,11 +53,11 @@ static int xrandr_resize(int xsz, int ysz, int rate, int just_checking) Status result = -1; /* must check at runtime for the availability of the extension */ - if(!XRRQueryExtension(fgDisplay.Display, &event_base, &error_base)) { + if(!XRRQueryExtension(fgDisplay.pDisplay.Display, &event_base, &error_base)) { return -1; } - XRRQueryVersion(fgDisplay.Display, &ver_major, &ver_minor); + XRRQueryVersion(fgDisplay.pDisplay.Display, &ver_major, &ver_minor); /* we only heed the rate if we CAN actually use it (Xrandr >= 1.1) and * the user actually cares about it (rate > 0) @@ -80,7 +80,7 @@ static int xrandr_resize(int xsz, int ysz, int rate, int just_checking) XRRFreeScreenConfigInfo(xrr_config); } - if(!(xrr_config = XRRGetScreenInfo(fgDisplay.Display, fgDisplay.RootWindow))) { + if(!(xrr_config = XRRGetScreenInfo(fgDisplay.pDisplay.Display, fgDisplay.RootWindow))) { fgWarning("XRRGetScreenInfo failed"); break; } @@ -136,12 +136,12 @@ static int xrandr_resize(int xsz, int ysz, int rate, int just_checking) #if ( RANDR_MAJOR >= 1 ) || ( ( RANDR_MAJOR == 1 ) && ( RANDR_MINOR >= 1 ) ) if(use_rate) - result = XRRSetScreenConfigAndRate(fgDisplay.Display, xrr_config, - fgDisplay.RootWindow, res_idx, rot, rate, timestamp); + result = XRRSetScreenConfigAndRate(fgDisplay.pDisplay.Display, xrr_config, + fgDisplay.pDisplay.RootWindow, res_idx, rot, rate, timestamp); else #endif - result = XRRSetScreenConfig(fgDisplay.Display, xrr_config, - fgDisplay.RootWindow, res_idx, rot, timestamp); + result = XRRSetScreenConfig(fgDisplay.pDisplay.Display, xrr_config, + fgDisplay.pDisplay.RootWindow, res_idx, rot, timestamp); } while(result == RRSetConfigInvalidTime); @@ -163,7 +163,7 @@ static int xrandr_resize(int xsz, int ysz, int rate, int just_checking) * Remembers the current visual settings, so that * we can change them and restore later... */ -static void fghRememberState( void ) +void fgPlatformRememberState( void ) { int event_base, error_base; @@ -174,33 +174,33 @@ static void fghRememberState( void ) Window junk_window; unsigned int junk_mask; - XQueryPointer(fgDisplay.Display, fgDisplay.RootWindow, + XQueryPointer(fgDisplay.pDisplay.Display, fgDisplay.pDisplay.RootWindow, &junk_window, &junk_window, - &fgDisplay.DisplayPointerX, &fgDisplay.DisplayPointerY, - &fgDisplay.DisplayPointerX, &fgDisplay.DisplayPointerY, &junk_mask); + &fgDisplay.pDisplay.DisplayPointerX, &fgDisplay.pDisplay.DisplayPointerY, + &fgDisplay.pDisplay.DisplayPointerX, &fgDisplay.pDisplay.DisplayPointerY, &junk_mask); # ifdef HAVE_X11_EXTENSIONS_XRANDR_H - if(XRRQueryExtension(fgDisplay.Display, &event_base, &error_base)) { + if(XRRQueryExtension(fgDisplay.pDisplay.Display, &event_base, &error_base)) { XRRScreenConfiguration *xrr_config; XRRScreenSize *ssizes; Rotation rot; int ssize_count, curr; - if((xrr_config = XRRGetScreenInfo(fgDisplay.Display, fgDisplay.RootWindow))) { + if((xrr_config = XRRGetScreenInfo(fgDisplay.pDisplay.Display, fgDisplay.pDisplay.RootWindow))) { ssizes = XRRConfigSizes(xrr_config, &ssize_count); curr = XRRConfigCurrentConfiguration(xrr_config, &rot); - fgDisplay.prev_xsz = ssizes[curr].width; - fgDisplay.prev_ysz = ssizes[curr].height; - fgDisplay.prev_refresh = -1; + fgDisplay.pDisplay.prev_xsz = ssizes[curr].width; + fgDisplay.pDisplay.prev_ysz = ssizes[curr].height; + fgDisplay.pDisplay.prev_refresh = -1; # if ( RANDR_MAJOR >= 1 ) || ( ( RANDR_MAJOR == 1 ) && ( RANDR_MINOR >= 1 ) ) if(fgState.GameModeRefresh != -1) { - fgDisplay.prev_refresh = XRRConfigCurrentRate(xrr_config); + fgDisplay.pDisplay.prev_refresh = XRRConfigCurrentRate(xrr_config); } # endif - fgDisplay.prev_size_valid = 1; + fgDisplay.pDisplay.prev_size_valid = 1; XRRFreeScreenConfigInfo(xrr_config); } @@ -212,7 +212,7 @@ static void fghRememberState( void ) * not approved as X Consortium standards */ # ifdef HAVE_X11_EXTENSIONS_XF86VMODE_H - if(!XF86VidModeQueryExtension(fgDisplay.Display, &event_base, &error_base)) { + if(!XF86VidModeQueryExtension(fgDisplay.pDisplay.Display, &event_base, &error_base)) { return; } @@ -221,23 +221,23 @@ static void fghRememberState( void ) * restore the ViewPort on LeaveGameMode(): */ if( !XF86VidModeGetViewPort( - fgDisplay.Display, - fgDisplay.Screen, - &fgDisplay.DisplayViewPortX, - &fgDisplay.DisplayViewPortY ) ) + fgDisplay.pDisplay.Display, + fgDisplay.pDisplay.Screen, + &fgDisplay.pDisplay.DisplayViewPortX, + &fgDisplay.pDisplay.DisplayViewPortY ) ) fgWarning( "XF86VidModeGetViewPort failed" ); /* Query the current display settings: */ - fgDisplay.DisplayModeValid = + fgDisplay.pDisplay.DisplayModeValid = XF86VidModeGetModeLine( - fgDisplay.Display, - fgDisplay.Screen, - &fgDisplay.DisplayModeClock, - &fgDisplay.DisplayMode + fgDisplay.pDisplay.Display, + fgDisplay.pDisplay.Screen, + &fgDisplay.pDisplay.DisplayModeClock, + &fgDisplay.pDisplay.DisplayMode ); - if( !fgDisplay.DisplayModeValid ) + if( !fgDisplay.pDisplay.DisplayModeValid ) fgWarning( "XF86VidModeGetModeLine failed" ); # endif @@ -248,21 +248,21 @@ static void fghRememberState( void ) /* * Restores the previously remembered visual settings */ -static void fghRestoreState( void ) +void fgPlatformRestoreState( void ) { /* Restore the remembered pointer position: */ XWarpPointer( - fgDisplay.Display, None, fgDisplay.RootWindow, 0, 0, 0, 0, - fgDisplay.DisplayPointerX, fgDisplay.DisplayPointerY + fgDisplay.pDisplay.Display, None, fgDisplay.pDisplay.RootWindow, 0, 0, 0, 0, + fgDisplay.pDisplay.DisplayPointerX, fgDisplay.pDisplay.DisplayPointerY ); # ifdef HAVE_X11_EXTENSIONS_XRANDR_H - if(fgDisplay.prev_size_valid) { - if(xrandr_resize(fgDisplay.prev_xsz, fgDisplay.prev_ysz, fgDisplay.prev_refresh, 0) != -1) { - fgDisplay.prev_size_valid = 0; + if(fgDisplay.pDisplay.prev_size_valid) { + if(xrandr_resize(fgDisplay.pDisplay.prev_xsz, fgDisplay.pDisplay.prev_ysz, fgDisplay.pDisplay.prev_refresh, 0) != -1) { + fgDisplay.pDisplay.prev_size_valid = 0; # ifdef HAVE_X11_EXTENSIONS_XF86VMODE_H - fgDisplay.DisplayModeValid = 0; + fgDisplay.pDisplay.DisplayModeValid = 0; # endif return; } @@ -277,14 +277,14 @@ static void fghRestoreState( void ) * not approved as X Consortium standards */ - if( fgDisplay.DisplayModeValid ) + if( fgDisplay.pDisplay.DisplayModeValid ) { XF86VidModeModeInfo** displayModes; int i, displayModesCount; if( !XF86VidModeGetAllModeLines( - fgDisplay.Display, - fgDisplay.Screen, + fgDisplay.pDisplay.Display, + fgDisplay.pDisplay.Screen, &displayModesCount, &displayModes ) ) { @@ -299,13 +299,13 @@ static void fghRestoreState( void ) */ for( i = 0; i < displayModesCount; i++ ) { - if(displayModes[ i ]->hdisplay == fgDisplay.DisplayMode.hdisplay && - displayModes[ i ]->vdisplay == fgDisplay.DisplayMode.vdisplay && - displayModes[ i ]->dotclock == fgDisplay.DisplayModeClock ) + if(displayModes[ i ]->hdisplay == fgDisplay.pDisplay.DisplayMode.hdisplay && + displayModes[ i ]->vdisplay == fgDisplay.pDisplay.DisplayMode.vdisplay && + displayModes[ i ]->dotclock == fgDisplay.pDisplay.DisplayModeClock ) { if( !XF86VidModeSwitchToMode( - fgDisplay.Display, - fgDisplay.Screen, + fgDisplay.pDisplay.Display, + fgDisplay.pDisplay.Screen, displayModes[ i ] ) ) { fgWarning( "XF86VidModeSwitchToMode failed" ); @@ -313,10 +313,10 @@ static void fghRestoreState( void ) } if( !XF86VidModeSetViewPort( - fgDisplay.Display, - fgDisplay.Screen, - fgDisplay.DisplayViewPortX, - fgDisplay.DisplayViewPortY ) ) + fgDisplay.pDisplay.Display, + fgDisplay.pDisplay.Screen, + fgDisplay.pDisplay.DisplayViewPortX, + fgDisplay.pDisplay.DisplayViewPortY ) ) fgWarning( "XF86VidModeSetViewPort failed" ); @@ -325,11 +325,11 @@ static void fghRestoreState( void ) * calls exit() we've to flush the X11 output queue to have the * commands sent to the X server before the application exits. */ - XFlush( fgDisplay.Display ); + XFlush( fgDisplay.pDisplay.Display ); - fgDisplay.DisplayModeValid = 0; + fgDisplay.pDisplay.DisplayModeValid = 0; # ifdef HAVE_X11_EXTENSIONS_XRANDR_H - fgDisplay.prev_size_valid = 0; + fgDisplay.pDisplay.prev_size_valid = 0; # endif break; @@ -398,7 +398,7 @@ static int fghCheckDisplayModes( GLboolean exactMatch, int displayModesCount, XF /* * Changes the current display mode to match user's settings */ -static GLboolean fghChangeDisplayMode( GLboolean haveToTest ) +GLboolean fgPlatformChangeDisplayMode( GLboolean haveToTest ) { GLboolean success = GL_FALSE; /* first try to use XRandR, then fallback to XF86VidMode */ @@ -420,7 +420,7 @@ static GLboolean fghChangeDisplayMode( GLboolean haveToTest ) * This is also used by applications which check modes by calling * glutGameModeGet(GLUT_GAME_MODE_POSSIBLE), so allow the check: */ - if( haveToTest || fgDisplay.DisplayModeValid ) + if( haveToTest || fgDisplay.pDisplay.DisplayModeValid ) { XF86VidModeModeInfo** displayModes; int i, displayModesCount; @@ -430,20 +430,20 @@ static GLboolean fghChangeDisplayMode( GLboolean haveToTest ) * glutEnterGameMode, then we need to query the current mode, to make * unspecified settings to default to their current values. */ - if(!fgDisplay.DisplayModeValid) { - if(!XF86VidModeGetModeLine(fgDisplay.Display, fgDisplay.Screen, - &fgDisplay.DisplayModeClock, &fgDisplay.DisplayMode)) { + if(!fgDisplay.pDisplay.DisplayModeValid) { + if(!XF86VidModeGetModeLine(fgDisplay.pDisplay.Display, fgDisplay.pDisplay.Screen, + &fgDisplay.pDisplay.DisplayModeClock, &fgDisplay.pDisplay.DisplayMode)) { return success; } } if (fgState.GameModeSize.X == -1) { - fgState.GameModeSize.X = fgDisplay.DisplayMode.hdisplay; + fgState.GameModeSize.X = fgDisplay.pDisplay.DisplayMode.hdisplay; } if (fgState.GameModeSize.Y == -1) { - fgState.GameModeSize.Y = fgDisplay.DisplayMode.vdisplay; + fgState.GameModeSize.Y = fgDisplay.pDisplay.DisplayMode.vdisplay; } if (fgState.GameModeDepth == -1) { @@ -454,16 +454,16 @@ static GLboolean fghChangeDisplayMode( GLboolean haveToTest ) if (fgState.GameModeRefresh == -1) { /* Compute the displays refresh rate, dotclock comes in kHz. */ - int refresh = ( fgDisplay.DisplayModeClock * 1000 ) / - ( fgDisplay.DisplayMode.htotal * fgDisplay.DisplayMode.vtotal ); + int refresh = ( fgDisplay.pDisplay.DisplayModeClock * 1000 ) / + ( fgDisplay.pDisplay.DisplayMode.htotal * fgDisplay.pDisplay.DisplayMode.vtotal ); fgState.GameModeRefresh = refresh; } /* query all possible display modes */ if( !XF86VidModeGetAllModeLines( - fgDisplay.Display, - fgDisplay.Screen, + fgDisplay.pDisplay.Display, + fgDisplay.pDisplay.Screen, &displayModesCount, &displayModes ) ) { @@ -484,8 +484,8 @@ static GLboolean fghChangeDisplayMode( GLboolean haveToTest ) if( !haveToTest && success ) { if( !XF86VidModeSwitchToMode( - fgDisplay.Display, - fgDisplay.Screen, + fgDisplay.pDisplay.Display, + fgDisplay.pDisplay.Screen, displayModes[ i ] ) ) fgWarning( "XF86VidModeSwitchToMode failed" ); } @@ -532,7 +532,7 @@ void FGAPIENTRY glutGameModeString( const char* string ) /* All values not specified are now set to -1, which means those * aspects of the current display mode are not changed in - * fghChangeDisplayMode() above. + * fgPlatformChangeDisplayMode() above. */ fgState.GameModeSize.X = width; fgState.GameModeSize.Y = height; @@ -552,9 +552,9 @@ int FGAPIENTRY glutEnterGameMode( void ) if( fgStructure.GameModeWindow ) fgAddToWindowDestroyList( fgStructure.GameModeWindow ); else - fghRememberState( ); + fgPlatformRememberState( ); - if( ! fghChangeDisplayMode( GL_FALSE ) ) + if( ! fgPlatformChangeDisplayMode( GL_FALSE ) ) { fgWarning( "failed to change screen settings" ); return 0; @@ -576,7 +576,7 @@ int FGAPIENTRY glutEnterGameMode( void ) * 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 ); + XSync( fgDisplay.pDisplay.Display, False ); /* * Grab the pointer to confine it into the window after the calls to * XWrapPointer() which ensure that the pointer really enters the window. @@ -587,7 +587,7 @@ int FGAPIENTRY glutEnterGameMode( void ) * the application which we have to aviod, so wait until it's viewable: */ while( GrabSuccess != XGrabPointer( - fgDisplay.Display, fgStructure.GameModeWindow->Window.Handle, + fgDisplay.pDisplay.Display, fgStructure.GameModeWindow->Window.Handle, TRUE, ButtonPressMask | ButtonReleaseMask | ButtonMotionMask | PointerMotionMask, @@ -599,7 +599,7 @@ int FGAPIENTRY glutEnterGameMode( void ) * if the new window is not viewable yet, see the XGrabPointer loop above. */ XSetInputFocus( - fgDisplay.Display, + fgDisplay.pDisplay.Display, fgStructure.GameModeWindow->Window.Handle, RevertToNone, CurrentTime @@ -607,22 +607,22 @@ int FGAPIENTRY glutEnterGameMode( void ) /* Move the Pointer to the middle of the fullscreen window */ XWarpPointer( - fgDisplay.Display, + fgDisplay.pDisplay.Display, None, - fgDisplay.RootWindow, + fgDisplay.pDisplay.RootWindow, 0, 0, 0, 0, fgState.GameModeSize.X/2, fgState.GameModeSize.Y/2 ); # ifdef HAVE_X11_EXTENSIONS_XF86VMODE_H - if( fgDisplay.DisplayModeValid ) + if( fgDisplay.pDisplay.DisplayModeValid ) { int x, y; Window child; /* Change to viewport to the window topleft edge: */ - if( !XF86VidModeSetViewPort( fgDisplay.Display, fgDisplay.Screen, 0, 0 ) ) + if( !XF86VidModeSetViewPort( fgDisplay.pDisplay.Display, fgDisplay.Screen, 0, 0 ) ) fgWarning( "XF86VidModeSetViewPort failed" ); /* @@ -633,15 +633,15 @@ int FGAPIENTRY glutEnterGameMode( void ) /* Get the current postion of the drawable area on screen */ XTranslateCoordinates( - fgDisplay.Display, + fgDisplay.pDisplay.Display, fgStructure.CurrentWindow->Window.Handle, - fgDisplay.RootWindow, + fgDisplay.pDisplay.RootWindow, 0, 0, &x, &y, &child ); /* Move the decorataions out of the topleft corner of the display */ - XMoveWindow( fgDisplay.Display, fgStructure.CurrentWindow->Window.Handle, + XMoveWindow( fgDisplay.pDisplay.Display, fgStructure.CurrentWindow->Window.Handle, -x, -y); } @@ -649,7 +649,7 @@ int FGAPIENTRY glutEnterGameMode( void ) /* Grab the keyboard, too */ XGrabKeyboard( - fgDisplay.Display, + fgDisplay.pDisplay.Display, fgStructure.GameModeWindow->Window.Handle, FALSE, GrabModeAsync, GrabModeAsync, @@ -675,12 +675,12 @@ void FGAPIENTRY glutLeaveGameMode( void ) #if TARGET_HOST_POSIX_X11 - XUngrabPointer( fgDisplay.Display, CurrentTime ); - XUngrabKeyboard( fgDisplay.Display, CurrentTime ); + XUngrabPointer( fgDisplay.pDisplay.Display, CurrentTime ); + XUngrabKeyboard( fgDisplay.pDisplay.Display, CurrentTime ); #endif - fghRestoreState(); + fgPlatformRestoreState(); } /* @@ -696,7 +696,7 @@ int FGAPIENTRY glutGameModeGet( GLenum eWhat ) return !!fgStructure.GameModeWindow; case GLUT_GAME_MODE_POSSIBLE: - return fghChangeDisplayMode( GL_TRUE ); + return fgPlatformChangeDisplayMode( GL_TRUE ); case GLUT_GAME_MODE_WIDTH: return fgState.GameModeSize.X;