(98) src/Makefile.am:34 Added mwmborder.c
[freeglut] / freeglut-1.3 / freeglut_gamemode.c
index 297f80c..d6c6a25 100644 (file)
@@ -32,7 +32,7 @@
 #define  G_LOG_DOMAIN  "freeglut-gamemode"
 
 #include "../include/GL/freeglut.h"
-#include "../include/GL/freeglut_internal.h"
+#include "freeglut_internal.h"
 
 /*
  * TODO BEFORE THE STABLE RELEASE:
@@ -75,12 +75,16 @@ void fghRememberState( void )
 
 #elif TARGET_HOST_WIN32
 
-    DEVMODE devMode;
+/*    DEVMODE devMode; */
 
     /*
      * Grab the current desktop settings...
      */
-    EnumDisplaySettings( NULL, ENUM_CURRENT_SETTINGS, &fgDisplay.DisplayMode );
+
+/* hack to get around my stupid cross-gcc headers */
+#define FREEGLUT_ENUM_CURRENT_SETTINGS -1
+
+    EnumDisplaySettings( NULL, FREEGLUT_ENUM_CURRENT_SETTINGS, &fgDisplay.DisplayMode );
 
     /*
      * Make sure we will be restoring all settings needed
@@ -103,7 +107,7 @@ void fghRestoreState( void )
 #   ifdef X_XF86VidModeGetAllModeLines
 
     XF86VidModeModeInfo** displayModes;
-    gint i, displayModesCount;
+    int i, displayModesCount;
 
     /*
      * Query for all the display available...
@@ -133,6 +137,15 @@ void fghRestoreState( void )
                 displayModes[ i ]
             );
 
+           /*
+            * In case this will be the last X11 call we do before exit,
+            * we've to flush the X11 output queue to be sure the command
+            * is really brought onto it's way to the X server.
+            * The application should not do this because it
+            * would not be platform independent then.
+            */
+           XFlush(fgDisplay.Display);
+
             return;
         }
     }
@@ -154,7 +167,7 @@ void fghRestoreState( void )
 /*
  * Checks the display mode settings against user's preferences
  */
-gboolean fghCheckDisplayMode( gint width, gint height, gint depth, gint refresh )
+GLboolean fghCheckDisplayMode( int width, int height, int depth, int refresh )
 {
     /*
      * The desired values should be stored in fgState structure...
@@ -166,7 +179,7 @@ gboolean fghCheckDisplayMode( gint width, gint height, gint depth, gint refresh
 /*
  * Changes the current display mode to match user's settings
  */
-gboolean fghChangeDisplayMode( gboolean haveToTest )
+GLboolean fghChangeDisplayMode( GLboolean haveToTest )
 {
 #if TARGET_HOST_UNIX_X11
 
@@ -176,7 +189,7 @@ gboolean fghChangeDisplayMode( gboolean haveToTest )
 #   ifdef X_XF86VidModeGetAllModeLines
 
     XF86VidModeModeInfo** displayModes;
-    gint i, displayModesCount;
+    int i, displayModesCount;
 
     /*
      * Query for all the display available...
@@ -196,6 +209,8 @@ gboolean fghChangeDisplayMode( gboolean haveToTest )
         if( fghCheckDisplayMode( displayModes[ i ]->hdisplay, displayModes[ i ]->vdisplay,
                                  fgState.GameModeDepth, fgState.GameModeRefresh ) )
         {
+           if( haveToTest )
+               return( TRUE );
             /*
              * OKi, this is the display mode we have been looking for...
              */
@@ -233,13 +248,14 @@ gboolean fghChangeDisplayMode( gboolean haveToTest )
 
 #elif TARGET_HOST_WIN32
 
-    guint    displayModes = 0, mode = 0xffffffff;
-    gboolean success = FALSE;
-    HDC      desktopDC;
+    unsigned int    displayModes = 0, mode = 0xffffffff;
+    GLboolean success = FALSE;
+/*    HDC      desktopDC; */
     DEVMODE  devMode;
 
     /*
      * Enumerate the available display modes
+     * Try to get a complete match
      */
     while( EnumDisplaySettings( NULL, displayModes, &devMode ) == TRUE )
     {
@@ -247,10 +263,10 @@ gboolean fghChangeDisplayMode( gboolean haveToTest )
          * Does the enumerated display mode match the user's preferences?
          */
         if( fghCheckDisplayMode( devMode.dmPelsWidth,  devMode.dmPelsHeight,
-                                 devMode.dmBitsPerPel, fgState.GameModeRefresh ) )
+                                 devMode.dmBitsPerPel, devMode.dmDisplayFrequency ) )
         {
             /*
-             * OKi, we've found a matching display mode, remember it's number and break
+             * OKi, we've found a matching display mode, remember its number and break
              */
             mode = displayModes;
             break;
@@ -262,12 +278,41 @@ gboolean fghChangeDisplayMode( gboolean haveToTest )
         displayModes++;
     }
 
+    if ( mode == 0xffffffff )
+    {
+      /* then try without Display Frequency */
+      displayModes = 0;
+
+      /*
+       * Enumerate the available display modes
+       */
+      while( EnumDisplaySettings( NULL, displayModes, &devMode ) == TRUE )
+      {
+        /* then try without Display Frequency */
+
+        if( fghCheckDisplayMode( devMode.dmPelsWidth,  devMode.dmPelsHeight,
+                                 devMode.dmBitsPerPel, fgState.GameModeRefresh))
+        {
+          /*
+           * OKi, we've found a matching display mode, remember its number and break
+           */
+          mode = displayModes;
+          break;
+        }
+       
+        /*
+         * Switch to the next display mode, if any
+         */
+        displayModes++;
+      }
+    }
+
     /*
      * Did we find a matching display mode?
      */
     if( mode != 0xffffffff )
     {
-        gint retVal = DISP_CHANGE_SUCCESSFUL;
+        int retVal = DISP_CHANGE_SUCCESSFUL;
 
         /*
          * Mark the values we want to modify in the display change call
@@ -310,9 +355,9 @@ gboolean fghChangeDisplayMode( gboolean haveToTest )
 /*
  * Sets the game mode display string
  */
-void FGAPIENTRY glutGameModeString( const gchar* string )
+void FGAPIENTRY glutGameModeString( const char* string )
 {
-    gint width = 640, height = 480, depth = 16, refresh = 72;
+    int width = 640, height = 480, depth = 16, refresh = 72;
 
     /*
      * This one seems a bit easier than glutInitDisplayString. The bad thing
@@ -327,7 +372,7 @@ void FGAPIENTRY glutGameModeString( const gchar* string )
                     if( sscanf( string, ":%i@%i", &depth, &refresh ) != 2 )
                         if( sscanf( string, ":%i", &depth ) != 1 )
                             if( sscanf( string, "@%i", &refresh ) != 1 )
-                                g_warning( "unable to parse game mode string `%s'", string );
+                                fgWarning( "unable to parse game mode string `%s'", string );
 
     /*
      * Hopefully it worked, and if not, we still have the default values
@@ -351,7 +396,7 @@ int FGAPIENTRY glutEnterGameMode( void )
         /*
          * ...if so, delete it before proceeding...
          */
-        fgDestroyWindow( fgStructure.GameMode, TRUE );
+        fgAddToWindowDestroyList( fgStructure.GameMode, TRUE );
     }
     else
     {
@@ -366,7 +411,7 @@ int FGAPIENTRY glutEnterGameMode( void )
      */
     if( fghChangeDisplayMode( FALSE ) == FALSE )
     {
-        g_warning( "failed to change screen settings" );
+             fgWarning( "failed to change screen settings" );
         return( FALSE );
     }
 
@@ -430,9 +475,9 @@ void FGAPIENTRY glutLeaveGameMode( void )
     freeglut_return_if_fail( fgStructure.GameMode != NULL );
 
     /*
-     * First of all, have the game mode window created
+     * First of all, have the game mode window destroyed
      */
-    fgDestroyWindow( fgStructure.GameMode, TRUE );
+    fgAddToWindowDestroyList( fgStructure.GameMode, TRUE );
 
 #if TARGET_HOST_UNIX_X11
 
@@ -502,6 +547,8 @@ int FGAPIENTRY glutGameModeGet( GLenum eWhat )
          */
         return( fgStructure.GameMode != NULL );
     }
+
+    return( -1 );
 }
 
 /*** END OF FILE ***/