don't show window when creating menu (better fix then making it very small and hiding...
[freeglut] / src / x11 / fg_window_x11.c
index 1b90bf5..f9e94a4 100644 (file)
 static int fghResizeFullscrToggle(void)
 {
     XWindowAttributes attributes;
+    SFG_Window *win = fgStructure.CurrentWindow;
 
     if(glutGet(GLUT_FULL_SCREEN)) {
         /* restore original window size */
-        SFG_Window *win = fgStructure.CurrentWindow;
-        fgStructure.CurrentWindow->State.NeedToResize = GL_TRUE;
-        fgStructure.CurrentWindow->State.Width  = win->State.pWState.OldWidth;
-        fgStructure.CurrentWindow->State.Height = win->State.pWState.OldHeight;
+        fgStructure.CurrentWindow->State.WorkMask = GLUT_SIZE_WORK;
+        fgStructure.CurrentWindow->State.DesiredWidth  = win->State.pWState.OldWidth;
+        fgStructure.CurrentWindow->State.DesiredHeight = win->State.pWState.OldHeight;
 
     } else {
+        fgStructure.CurrentWindow->State.pWState.OldWidth  = win->State.Width;
+        fgStructure.CurrentWindow->State.pWState.OldHeight = win->State.Height;
+
         /* resize the window to cover the entire screen */
         XGetWindowAttributes(fgDisplay.pDisplay.Display,
                 fgStructure.CurrentWindow->Window.Handle,
@@ -133,6 +136,7 @@ void fgPlatformOpenWindow( SFG_Window* window, const char* title,
     XEvent eventReturnBuffer; /* return buffer required for a call */
     unsigned long mask;
     unsigned int current_DisplayMode = fgState.DisplayMode ;
+    XConfigureEvent fakeEvent = {0};
 
     /* Save the display mode if we are creating a menu window */
     if( window->IsMenu && ( ! fgStructure.MenuContext ) )
@@ -239,6 +243,18 @@ void fgPlatformOpenWindow( SFG_Window* window, const char* title,
         &winAttr
     );
 
+    /* Fake configure event to force viewport setup
+     * even with no window manager.
+     */
+    fakeEvent.type = ConfigureNotify;
+    fakeEvent.display = fgDisplay.pDisplay.Display;
+    fakeEvent.window = window->Window.Handle;
+    fakeEvent.x = x;
+    fakeEvent.y = y;
+    fakeEvent.width = w;
+    fakeEvent.height = h;
+    XPutBackEvent(fgDisplay.pDisplay.Display, (XEvent*)&fakeEvent);
+
     /*
      * The GLX context creation, possibly trying the direct context rendering
      *  or else use the current context if the user has so specified
@@ -284,12 +300,6 @@ void fgPlatformOpenWindow( SFG_Window* window, const char* title,
     }
 #endif
 
-    /*
-     * XXX Assume the new window is visible by default
-     * XXX Is this a  safe assumption?
-     */
-    window->State.Visible = GL_TRUE;
-
     sizeHints.flags = 0;
     if ( positionUse )
         sizeHints.flags |= USPosition;
@@ -346,7 +356,11 @@ void fgPlatformOpenWindow( SFG_Window* window, const char* title,
        fgRegisterDevices( fgDisplay.pDisplay.Display, &(window->Window.Handle) );
     #endif
 
-    XMapWindow( fgDisplay.pDisplay.Display, window->Window.Handle );
+    if (!window->IsMenu)    /* Don't show window after creation if its a menu */
+    {
+        XMapWindow( fgDisplay.pDisplay.Display, window->Window.Handle );
+        window->State.Visible = GL_TRUE;
+    }
 
     XFree(visualInfo);
 
@@ -357,6 +371,17 @@ void fgPlatformOpenWindow( SFG_Window* window, const char* title,
 
 
 /*
+ * Request a window resize
+ */
+void fgPlatformReshapeWindow ( SFG_Window *window, int width, int height )
+{
+    XResizeWindow( fgDisplay.pDisplay.Display, window->Window.Handle,
+                   width, height );
+    XFlush( fgDisplay.pDisplay.Display ); /* XXX Shouldn't need this */
+}
+
+
+/*
  * Closes a window, destroying the frame and OpenGL context
  */
 void fgPlatformCloseWindow( SFG_Window* window )
@@ -377,37 +402,39 @@ void fgPlatformCloseWindow( SFG_Window* window )
 
 
 /*
- * This function makes the current window visible
+ * This function makes the specified window visible
  */
-void fgPlatformGlutShowWindow( void )
+void fgPlatformShowWindow( SFG_Window *window )
 {
-    XMapWindow( fgDisplay.pDisplay.Display, fgStructure.CurrentWindow->Window.Handle );
+    XMapWindow( fgDisplay.pDisplay.Display, window->Window.Handle );
     XFlush( fgDisplay.pDisplay.Display ); /* XXX Shouldn't need this */
 }
 
 /*
- * This function hides the current window
+ * This function hides the specified window
  */
-void fgPlatformGlutHideWindow( void )
+void fgPlatformHideWindow( SFG_Window *window )
 {
-    if( fgStructure.CurrentWindow->Parent == NULL )
+    if( window->Parent == NULL )
         XWithdrawWindow( fgDisplay.pDisplay.Display,
-                         fgStructure.CurrentWindow->Window.Handle,
+                         window->Window.Handle,
                          fgDisplay.pDisplay.Screen );
     else
         XUnmapWindow( fgDisplay.pDisplay.Display,
-                      fgStructure.CurrentWindow->Window.Handle );
+                      window->Window.Handle );
     XFlush( fgDisplay.pDisplay.Display ); /* XXX Shouldn't need this */
 }
 
 /*
- * Iconify the current window (top-level windows only)
+ * Iconify the specified window (top-level windows only)
  */
-void fgPlatformGlutIconifyWindow( void )
+void fgPlatformIconifyWindow( SFG_Window *window )
 {
-    XIconifyWindow( fgDisplay.pDisplay.Display, fgStructure.CurrentWindow->Window.Handle,
+    XIconifyWindow( fgDisplay.pDisplay.Display, window->Window.Handle,
                     fgDisplay.pDisplay.Screen );
     XFlush( fgDisplay.pDisplay.Display ); /* XXX Shouldn't need this */
+
+    fgStructure.CurrentWindow->State.Visible   = GL_FALSE;
 }
 
 /*
@@ -453,59 +480,35 @@ void fgPlatformGlutSetIconTitle( const char* title )
 }
 
 /*
- * Change the current window's position
+ * Change the specified window's position
  */
-void fgPlatformGlutPositionWindow( int x, int y )
+void fgPlatformPositionWindow( SFG_Window *window, int x, int y )
 {
-    XMoveWindow( fgDisplay.pDisplay.Display, fgStructure.CurrentWindow->Window.Handle,
+    XMoveWindow( fgDisplay.pDisplay.Display, window->Window.Handle,
                  x, y );
     XFlush( fgDisplay.pDisplay.Display ); /* XXX Shouldn't need this */
 }
 
 /*
- * Lowers the current window (by Z order change)
- */
-void fgPlatformGlutPushWindow( void )
-{
-    XLowerWindow( fgDisplay.pDisplay.Display, fgStructure.CurrentWindow->Window.Handle );
-}
-
-/*
- * Raises the current window (by Z order change)
- */
-void fgPlatformGlutPopWindow( void )
-{
-    XRaiseWindow( fgDisplay.pDisplay.Display, fgStructure.CurrentWindow->Window.Handle );
-}
-
-/*
- * Resize the current window so that it fits the whole screen
+ * Lowers the specified window (by Z order change)
  */
-void fgPlatformGlutFullScreen( SFG_Window *win )
+void fgPlatformPushWindow( SFG_Window *window )
 {
-    if(!glutGet(GLUT_FULL_SCREEN)) {
-        if(fghToggleFullscreen() != -1) {
-            win->State.IsFullscreen = GL_TRUE;
-        }
-    }
+    XLowerWindow( fgDisplay.pDisplay.Display, window->Window.Handle );
 }
 
 /*
- * If we are fullscreen, resize the current window back to its original size
+ * Raises the specified window (by Z order change)
  */
-void fgPlatformGlutLeaveFullScreen( SFG_Window *win )
+void fgPlatformPopWindow( SFG_Window *window )
 {
-    if(glutGet(GLUT_FULL_SCREEN)) {
-        if(fghToggleFullscreen() != -1) {
-            win->State.IsFullscreen = GL_FALSE;
-        }
-    }
+    XRaiseWindow( fgDisplay.pDisplay.Display, window->Window.Handle );
 }
 
 /*
  * Toggle the window's full screen state.
  */
-void fgPlatformGlutFullScreenToggle( SFG_Window *win )
+void fgPlatformFullScreenToggle( SFG_Window *win )
 {
     if(fghToggleFullscreen() != -1) {
         win->State.IsFullscreen = !win->State.IsFullscreen;