Added X11 code for glutGet(GLUT_WINDOW_BORDER_WIDTH) and
[freeglut] / src / freeglut_state.c
index cb40f05..3fadfa6 100644 (file)
@@ -104,6 +104,9 @@ void FGAPIENTRY glutSetOption( GLenum eWhat, int value )
   case GLUT_ACTION_ON_WINDOW_CLOSE: fgState.ActionOnWindowClose = value ;
                                     break ;
 
+  case GLUT_RENDERING_CONTEXT:      fgState.UseCurrentContext   = ( value == GLUT_USE_CURRENT_CONTEXT ) ? TRUE : FALSE ;
+                                    break ;
+
   case GLUT_WINDOW_CURSOR:
       if( fgStructure.Window != NULL ) fgStructure.Window->State.Cursor = value ;
       break ;
@@ -122,11 +125,11 @@ void FGAPIENTRY glutSetOption( GLenum eWhat, int value )
  */
 int FGAPIENTRY glutGet( GLenum eWhat )
 {
-    int returnValue ;
-    GLboolean boolValue ;
+  int returnValue ;
+  GLboolean boolValue ;
 
-    if ( eWhat == GLUT_INIT_STATE )
-       return ( fgState.Time.Set ) ;
+  if ( eWhat == GLUT_INIT_STATE )
+    return ( fgState.Time.Set ) ;
 
     freeglut_assert_ready;
 
@@ -212,10 +215,44 @@ int FGAPIENTRY glutGet( GLenum eWhat )
      */
     case GLUT_WINDOW_X:
     case GLUT_WINDOW_Y:
+    case GLUT_WINDOW_BORDER_WIDTH:
+    case GLUT_WINDOW_HEADER_HEIGHT:
+    {
+        int x, y;
+        Window w;
+
+        if( fgStructure.Window == NULL )
+            return( 0 );
+
+        XTranslateCoordinates(
+            fgDisplay.Display,
+            fgStructure.Window->Window.Handle,
+            fgDisplay.RootWindow,
+            0, 0, &x, &y, &w);
+
+        switch ( eWhat )
+        {
+        case GLUT_WINDOW_X: return x;
+        case GLUT_WINDOW_Y: return y;
+        }
+
+       if ( w == 0 )
+            return( 0 );  /* Just in case */
+
+        XTranslateCoordinates(
+            fgDisplay.Display,
+            fgStructure.Window->Window.Handle,
+            w, 0, 0, &x, &y, &w);
+
+        switch ( eWhat )
+        {
+        case GLUT_WINDOW_BORDER_WIDTH:  return x;
+        case GLUT_WINDOW_HEADER_HEIGHT: return y;
+        }
+    }
+
     case GLUT_WINDOW_WIDTH:
     case GLUT_WINDOW_HEIGHT:
-    case GLUT_WINDOW_BORDER_WIDTH :
-    case GLUT_WINDOW_HEADER_HEIGHT :
     {
         XWindowAttributes winAttributes;
 
@@ -239,12 +276,8 @@ int FGAPIENTRY glutGet( GLenum eWhat )
          */
         switch ( eWhat )
         {
-        case GLUT_WINDOW_X:                return winAttributes.x ;
-        case GLUT_WINDOW_Y:                return winAttributes.y ;
         case GLUT_WINDOW_WIDTH:            return winAttributes.width ;
         case GLUT_WINDOW_HEIGHT:           return winAttributes.height ;
-        case GLUT_WINDOW_BORDER_WIDTH :    return winAttributes.border_width ;
-        case GLUT_WINDOW_HEADER_HEIGHT :   return winAttributes.border_width * 3 ;  /* a kludge for now */
         }
     }
 
@@ -364,8 +397,8 @@ int FGAPIENTRY glutGet( GLenum eWhat )
         /*
          * ...then we've got to correct the results we've just received...
          */
-        if (fgStructure.GameMode != fgStructure.Window &&
-           fgStructure.Window->Parent == NULL )
+        if ( ( fgStructure.GameMode != fgStructure.Window ) && ( fgStructure.Window->Parent == NULL ) &&
+             ( ! fgStructure.Window->IsMenu ) )
         {
           winRect.left   += GetSystemMetrics( SM_CXSIZEFRAME );
           winRect.right  -= GetSystemMetrics( SM_CXSIZEFRAME );
@@ -452,10 +485,13 @@ int FGAPIENTRY glutGet( GLenum eWhat )
         return( fgListLength( &fgStructure.Menu->Entries ) );
 
     case GLUT_ACTION_ON_WINDOW_CLOSE:
-       return fgState.ActionOnWindowClose;
+        return fgState.ActionOnWindowClose ;
+
+    case GLUT_VERSION :
+        return VERSION_MAJOR * 10000 + VERSION_MINOR * 100 + VERSION_PATCH ;
 
-    case GLUT_VERSION:
-       return VERSION_MAJOR * 10000 + VERSION_MINOR * 100 + VERSION_PATCH;
+    case GLUT_RENDERING_CONTEXT:
+        return ( fgState.UseCurrentContext ? GLUT_USE_CURRENT_CONTEXT : GLUT_CREATE_NEW_CONTEXT ) ;
 
     default:
         /*
@@ -654,7 +690,8 @@ int FGAPIENTRY glutLayerGet( GLenum eWhat )
         /*
          * Check if an overlay display mode is possible
          */
-        return( fgSetupPixelFormat( fgStructure.Window, TRUE, PFD_OVERLAY_PLANE ) );
+/*        return( fgSetupPixelFormat( fgStructure.Window, TRUE, PFD_OVERLAY_PLANE ) ); */
+      return FALSE ;
 
     case GLUT_LAYER_IN_USE:
         /*