joystick updates from John Fay
[freeglut] / src / freeglut_gamemode.c
index 1d5397e..5f93431 100644 (file)
@@ -29,7 +29,7 @@
 #include "config.h"
 #endif
 
-#include "../include/GL/freeglut.h"
+#include <GL/freeglut.h>
 #include "freeglut_internal.h"
 
 /*
@@ -86,10 +86,8 @@ void fghRememberState( void )
         );
     }
 
-    /*
-     * Query the current display settings:
-     */
-    fgDisplay.DisplayModeValid = 
+    /* Query the current display settings: */
+    fgDisplay.DisplayModeValid =
       XF86VidModeGetModeLine(
         fgDisplay.Display,
         fgDisplay.Screen,
@@ -97,20 +95,21 @@ void fghRememberState( void )
         &fgDisplay.DisplayMode
     );
 
-    if (!fgDisplay.DisplayModeValid)
+    if( !fgDisplay.DisplayModeValid )
             fgWarning( "Runtime use of XF86VidModeGetModeLine failed.\n" );
 
 #   else
-#       warning fghRememberState: missing XFree86 video mode extensions, game mode will not change screen resolution when activated
+    /*
+     * XXX warning fghRememberState: missing XFree86 video mode extensions,
+     * XXX game mode will not change screen resolution when activated
+     */
 #   endif
 
-#elif TARGET_HOST_WIN32
+#elif TARGET_HOST_WIN32 || TARGET_HOST_WINCE
 
 /*    DEVMODE devMode; */
-    
-    /*
-     * Grab the current desktop settings...
-     */
+
+    /* Grab the current desktop settings... */
 
 /* hack to get around my stupid cross-gcc headers */
 #define FREEGLUT_ENUM_CURRENT_SETTINGS -1
@@ -118,9 +117,7 @@ void fghRememberState( void )
     EnumDisplaySettings( NULL, FREEGLUT_ENUM_CURRENT_SETTINGS,
                          &fgDisplay.DisplayMode );
 
-    /*
-     * Make sure we will be restoring all settings needed
-     */
+    /* Make sure we will be restoring all settings needed */
     fgDisplay.DisplayMode.dmFields |=
         DM_PELSWIDTH | DM_PELSHEIGHT | DM_BITSPERPEL | DM_DISPLAYFREQUENCY;
 
@@ -135,9 +132,7 @@ void fghRestoreState( void )
 #if TARGET_HOST_UNIX_X11
 
 #   ifdef X_XF86VidModeGetAllModeLines
-    /*
-     * Restore the remembered pointer position:
-     */
+    /* Restore the remembered pointer position: */
     XWarpPointer(
         fgDisplay.Display, None, fgDisplay.RootWindow, 0, 0, 0, 0,
         fgDisplay.DisplayPointerX, fgDisplay.DisplayPointerY
@@ -148,7 +143,7 @@ void fghRestoreState( void )
      * not approved as X Consortium standards
      */
 
-    if (fgDisplay.DisplayModeValid)
+    if( fgDisplay.DisplayModeValid )
     {
         XF86VidModeModeInfo** displayModes;
         int i, displayModesCount;
@@ -195,14 +190,15 @@ void fghRestoreState( void )
     }
 
 #   else
-#       warning fghRestoreState: missing XFree86 video mode extensions, game mode will not change screen resolution when activated
+    /*
+     * XXX warning fghRestoreState: missing XFree86 video mode extensions,
+     * XXX game mode will not change screen resolution when activated
+     */
 #   endif
 
-#elif TARGET_HOST_WIN32
+#elif TARGET_HOST_WIN32 || TARGET_HOST_WINCE
 
-    /*
-     * Restore the previously rememebered desktop display settings
-     */
+    /* Restore the previously rememebered desktop display settings */
     ChangeDisplaySettings( &fgDisplay.DisplayMode, 0 );
 
 #endif
@@ -213,13 +209,11 @@ void fghRestoreState( void )
  */
 GLboolean fghCheckDisplayMode( int width, int height, int depth, int refresh )
 {
-    /*
-     * The desired values should be stored in fgState structure...
-     */
-    return( (width == fgState.GameModeSize.X) &&
-            (height == fgState.GameModeSize.Y) &&
-            (depth == fgState.GameModeDepth) &&
-            (refresh == fgState.GameModeRefresh) );
+    /* The desired values should be stored in fgState structure... */
+    return ( width == fgState.GameModeSize.X ) &&
+           ( height == fgState.GameModeSize.Y ) &&
+           ( depth == fgState.GameModeDepth ) &&
+           (refresh == fgState.GameModeRefresh );
 }
 
 /*
@@ -239,7 +233,7 @@ GLboolean fghChangeDisplayMode( GLboolean haveToTest )
      * This is also used by applcations which check modes by calling
      * glutGameModeGet(GLUT_GAME_MODE_POSSIBLE), so allow the check:
      */
-    if (haveToTest || fgDisplay.DisplayModeValid)
+    if( haveToTest || fgDisplay.DisplayModeValid )
     {
         XF86VidModeModeInfo** displayModes;
         int i, displayModesCount;
@@ -251,9 +245,7 @@ GLboolean fghChangeDisplayMode( GLboolean haveToTest )
             &displayModes
         );
 
-        /*
-         * Check every of the modes looking for one that matches our demands
-         */
+        /* Check every of the modes looking for one that matches our demands */
         for( i = 0; i < displayModesCount; i++ )
         {
             if( fghCheckDisplayMode( displayModes[ i ]->hdisplay,
@@ -262,33 +254,32 @@ GLboolean fghChangeDisplayMode( GLboolean haveToTest )
                                      fgState.GameModeRefresh ) )
             {
                 if( haveToTest )
-                    return TRUE;
-                /*
-                 * OKi, this is the display mode we have been looking for...
-                 */
+                    return GL_TRUE;
+                /* OKi, this is the display mode we have been looking for... */
                 XF86VidModeSwitchToMode(
                     fgDisplay.Display,
                     fgDisplay.Screen,
                     displayModes[ i ]
                 );
-                return TRUE;
+                return GL_TRUE;
             }
         }
     }
 
-    /*
-     * Something must have went wrong
-     */
-    return FALSE;
+    /* Something must have gone wrong */
+    return GL_FALSE;
 
 #   else
-#       warning fghChangeDisplayMode: missing XFree86 video mode extensions, game mode will not change screen resolution when activated
+    /*
+     * XXX warning fghChangeDisplayMode: missing XFree86 video mode extensions,
+     * XXX game mode will not change screen resolution when activated
+     */
 #   endif
 
-#elif TARGET_HOST_WIN32
+#elif TARGET_HOST_WIN32 || TARGET_HOST_WINCE
 
     unsigned int    displayModes = 0, mode = 0xffffffff;
-    GLboolean success = FALSE;
+    GLboolean success = GL_FALSE;
     /* HDC      desktopDC; */
     DEVMODE  devMode;
 
@@ -296,11 +287,9 @@ GLboolean fghChangeDisplayMode( GLboolean haveToTest )
      * Enumerate the available display modes
      * Try to get a complete match
      */
-    while( EnumDisplaySettings( NULL, displayModes, &devMode ) == TRUE )
+    while( EnumDisplaySettings( NULL, displayModes, &devMode ) )
     {
-        /*
-         * Does the enumerated display mode match the user's preferences?
-         */
+        /* Does the enumerated display mode match the user's preferences? */
         if( fghCheckDisplayMode( devMode.dmPelsWidth,  devMode.dmPelsHeight,
                                  devMode.dmBitsPerPel,
                                  devMode.dmDisplayFrequency ) )
@@ -311,15 +300,13 @@ GLboolean fghChangeDisplayMode( GLboolean haveToTest )
         displayModes++;
     }
 
-    if ( mode == 0xffffffff )
+    if( mode == 0xffffffff )
     {
         /* then try without Display Frequency */
         displayModes = 0;
 
-        /*
-         * Enumerate the available display modes
-         */
-        while( EnumDisplaySettings( NULL, displayModes, &devMode ) == TRUE )
+        /* Enumerate the available display modes */
+        while( EnumDisplaySettings( NULL, displayModes, &devMode ) )
         {
             /* then try without Display Frequency */
             if( fghCheckDisplayMode( devMode.dmPelsWidth,
@@ -334,24 +321,18 @@ GLboolean fghChangeDisplayMode( GLboolean haveToTest )
         }
     }
 
-    /*
-     * Did we find a matching display mode?
-     */
+    /* Did we find a matching display mode? */
     if( mode != 0xffffffff )
     {
         int retVal = DISP_CHANGE_SUCCESSFUL;
 
-        /*
-         * Mark the values we want to modify in the display change call
-         */
+        /* Mark the values we want to modify in the display change call */
         devMode.dmFields |=
             DM_PELSWIDTH | DM_PELSHEIGHT | DM_BITSPERPEL | DM_DISPLAYFREQUENCY;
 
         retVal = ChangeDisplaySettings( &devMode, haveToTest ? CDS_TEST : 0 );
 
-        /*
-         * I don't know if it's really needed, but looks nice:
-         */
+        /* I don't know if it's really needed, but looks nice: */
         success = (retVal == DISP_CHANGE_SUCCESSFUL) ||
             (retVal == DISP_CHANGE_NOTUPDATED);
 
@@ -398,9 +379,7 @@ void FGAPIENTRY glutGameModeString( const char* string )
                                     string
                                 );
 
-    /*
-     * Hopefully it worked, and if not, we still have the default values
-     */
+    /* Hopefully it worked, and if not, we still have the default values */
     fgState.GameModeSize.X  = width;
     fgState.GameModeSize.Y  = height;
     fgState.GameModeDepth   = depth;
@@ -413,21 +392,23 @@ void FGAPIENTRY glutGameModeString( const char* string )
 int FGAPIENTRY glutEnterGameMode( void )
 {
     if( fgStructure.GameMode )
-        fgAddToWindowDestroyList( fgStructure.GameMode, TRUE );
+        fgAddToWindowDestroyList( fgStructure.GameMode );
     else
         fghRememberState( );
 
-    if( fghChangeDisplayMode( FALSE ) == FALSE )
+    if( ! fghChangeDisplayMode( GL_FALSE ) )
     {
         fgWarning( "failed to change screen settings" );
         return FALSE;
     }
 
-    fgStructure.GameMode = fgCreateWindow( 
+    fgStructure.GameMode = fgCreateWindow(
         NULL, "FREEGLUT", 0, 0,
-        fgState.GameModeSize.X, fgState.GameModeSize.Y, TRUE 
+        fgState.GameModeSize.X, fgState.GameModeSize.Y, GL_TRUE, GL_FALSE
     );
 
+    fgStructure.GameMode->State.IsGameMode = GL_TRUE;
+
 #if TARGET_HOST_UNIX_X11
 
     /* Move the window up to the topleft corner */
@@ -442,7 +423,7 @@ int FGAPIENTRY glutEnterGameMode( void )
     /* Move the Pointer to the middle of the fullscreen window */
     XWarpPointer(
         fgDisplay.Display,
-        None, 
+        None,
         fgDisplay.RootWindow,
         0, 0, 0, 0,
         fgState.GameModeSize.X/2, fgState.GameModeSize.Y/2
@@ -465,7 +446,7 @@ int FGAPIENTRY glutEnterGameMode( void )
                GrabModeAsync, GrabModeAsync,
                fgStructure.GameMode->Window.Handle, None, CurrentTime) )
         usleep( 100 );
-    
+
     /*
      * Change input focus to the new window. This will exit the application
      * if the new window is not viewable yet, see the XGrabPointer loop above.
@@ -479,14 +460,12 @@ int FGAPIENTRY glutEnterGameMode( void )
 
 #   ifdef X_XF86VidModeSetViewPort
 
-    if (fgDisplay.DisplayModeValid)
+    if( fgDisplay.DisplayModeValid )
     {
         int x, y;
         Window child;
 
-        /*
-         * Change to viewport to the window topleft edge:
-         */
+        /* Change to viewport to the window topleft edge: */
         XF86VidModeSetViewPort( fgDisplay.Display, fgDisplay.Screen, 0, 0 );
 
         /*
@@ -511,9 +490,7 @@ int FGAPIENTRY glutEnterGameMode( void )
 
 #endif
 
-    /*
-     * Grab the keyboard, too
-     */
+    /* Grab the keyboard, too */
     XGrabKeyboard(
         fgDisplay.Display,
         fgStructure.GameMode->Window.Handle,
@@ -534,7 +511,11 @@ void FGAPIENTRY glutLeaveGameMode( void )
 {
     freeglut_return_if_fail( fgStructure.GameMode );
 
-    fgAddToWindowDestroyList( fgStructure.GameMode, TRUE );
+    fgStructure.GameMode->State.IsGameMode = GL_FALSE;
+
+    fgAddToWindowDestroyList( fgStructure.GameMode );
+
+    fgStructure.GameMode = NULL;
 
 #if TARGET_HOST_UNIX_X11
 
@@ -557,7 +538,7 @@ int FGAPIENTRY glutGameModeGet( GLenum eWhat )
         return !!fgStructure.GameMode;
 
     case GLUT_GAME_MODE_POSSIBLE:
-        return fghChangeDisplayMode( TRUE );
+        return fghChangeDisplayMode( GL_TRUE );
 
     case GLUT_GAME_MODE_WIDTH:
         return fgState.GameModeSize.X;