Fixes [#21791] Toggle Fullscreen (Alt + F11) returns to non-maximized window
authorNathan Letwory <nathan@letworyinteractive.com>
Tue, 1 Jun 2010 06:18:17 +0000 (06:18 +0000)
committerNathan Letwory <nathan@letworyinteractive.com>
Tue, 1 Jun 2010 06:18:17 +0000 (06:18 +0000)
Applied patch provided by Elia Sarti

intern/ghost/intern/GHOST_WindowWin32.cpp
intern/ghost/intern/GHOST_WindowWin32.h
intern/ghost/intern/GHOST_WindowX11.cpp
intern/ghost/intern/GHOST_WindowX11.h

index 1da6485019875b3849b846a54b0bc43ef56e3d9a..bbfa84dbae0353f3929b3f3b037cbc5c8197af20 100644 (file)
@@ -64,6 +64,7 @@
 LPCSTR GHOST_WindowWin32::s_windowClassName = "GHOST_WindowClass";
 const int GHOST_WindowWin32::s_maxTitleLength = 128;
 HGLRC GHOST_WindowWin32::s_firsthGLRc = NULL;
+HDC GHOST_WindowWin32::s_firstHDC = NULL;
 
 static int WeightPixelFormat(PIXELFORMATDESCRIPTOR& pfd);
 static int EnumPixelFormats(HDC hdc);
@@ -134,6 +135,7 @@ GHOST_WindowWin32::GHOST_WindowWin32(
        m_top(top),
        m_width(width),
        m_height(height),
+       m_normal_state(GHOST_kWindowStateNormal),
        m_stereo(stereoVisual),
        m_nextWindow(NULL)
 {
@@ -202,6 +204,10 @@ GHOST_WindowWin32::GHOST_WindowWin32(
                // Store the device context
                m_hDC = ::GetDC(m_hWnd);
 
+               if(!s_firstHDC) {
+                       s_firstHDC = m_hDC;
+               }
+
                // Show the window
                int nCmdShow;
                switch (state) {
@@ -308,10 +314,11 @@ GHOST_WindowWin32::~GHOST_WindowWin32()
                m_customCursor = NULL;
        }
 
+       ::wglMakeCurrent(NULL, NULL);
        m_multisampleEnabled = GHOST_kFailure;
        m_multisample = 0;
        setDrawingContextType(GHOST_kDrawingContextTypeNone);
-       if (m_hDC) {
+       if (m_hDC && m_hDC != s_firstHDC) {
                ::ReleaseDC(m_hWnd, m_hDC);
                m_hDC = 0;
        }
@@ -482,9 +489,13 @@ void GHOST_WindowWin32::clientToScreen(GHOST_TInt32 inX, GHOST_TInt32 inY, GHOST
 
 GHOST_TSuccess GHOST_WindowWin32::setState(GHOST_TWindowState state)
 {
+       GHOST_TWindowState curstate = getState();
        WINDOWPLACEMENT wp;
        wp.length = sizeof(WINDOWPLACEMENT);
        ::GetWindowPlacement(m_hWnd, &wp);
+
+       if (state == GHOST_kWindowStateNormal)
+               state = m_normal_state;
        switch (state) {
        case GHOST_kWindowStateMinimized:
                wp.showCmd = SW_SHOWMINIMIZED;
@@ -495,6 +506,8 @@ GHOST_TSuccess GHOST_WindowWin32::setState(GHOST_TWindowState state)
                SetWindowLongPtr(m_hWnd, GWL_STYLE, WS_OVERLAPPEDWINDOW);
                break;
        case GHOST_kWindowStateFullScreen:
+               if (curstate != state && curstate != GHOST_kWindowStateMinimized)
+                       m_normal_state = curstate;
                wp.showCmd = SW_SHOWMAXIMIZED;
                wp.ptMaxPosition.x = 0;
                wp.ptMaxPosition.y = 0;
@@ -637,6 +650,7 @@ GHOST_TSuccess GHOST_WindowWin32::installDrawingContext(GHOST_TDrawingContextTyp
                        m_hGlRc = ::wglCreateContext(m_hDC);
                        if (m_hGlRc) {
                                if (s_firsthGLRc) {
+                                       ::wglCopyContext(s_firsthGLRc, m_hGlRc, GL_ALL_ATTRIB_BITS);
                                        wglShareLists(s_firsthGLRc, m_hGlRc);
                                } else {
                                        s_firsthGLRc = m_hGlRc;
index 5e1f708f61ca38b4c0adb59af59cb4d782b72e08..a4d31f87ffa3e454ec93c2f877a98eadc58312cc 100644 (file)
@@ -315,6 +315,8 @@ protected:
        HGLRC m_hGlRc;
        /** The first created OpenGL context (for sharing display lists) */
        static HGLRC s_firsthGLRc;
+       /** The first created device context handle. */
+       static HDC s_firstHDC;
        /** Flag for if window has captured the mouse */
        bool m_hasMouseCaptured;
        /** Count of number of pressed buttons */
@@ -351,6 +353,7 @@ protected:
        GHOST_TInt32 m_top;
        GHOST_TUns32 m_width;
        GHOST_TUns32 m_height;
+       GHOST_TWindowState m_normal_state;
        bool m_stereo;
 
        /** The GHOST_System passes this to wm if this window is being replaced */
index 9be278706a83db18c8de2ecc52e0ec654f10ba07..b3b1c8ae0f77c18192b96224ece6662088908f19 100644 (file)
@@ -159,6 +159,7 @@ GHOST_WindowX11(
        GHOST_Window(title,left,top,width,height,state,type,stereoVisual,numOfAASamples),
        m_context(NULL),
        m_display(display),
+       m_normal_state(GHOST_kWindowStateNormal),
        m_system (system),
        m_valid_setup (false),
        m_invalid_window(false),
@@ -1036,6 +1037,9 @@ GHOST_TSuccess GHOST_WindowX11::setState(GHOST_TWindowState state)
 
        is_motif_full = motifIsFullScreen();
 
+       if (state == GHOST_kWindowStateNormal)
+               state = m_normal_state;
+
        if (state == GHOST_kWindowStateNormal) {
                if (is_max == True)
                        netwmMaximized(False);
@@ -1055,6 +1059,8 @@ GHOST_TSuccess GHOST_WindowX11::setState(GHOST_TWindowState state)
                if (cur_state == GHOST_kWindowStateMinimized)
                        return (GHOST_kFailure);
 
+               m_normal_state = cur_state;
+
                if (is_max == True)
                        netwmMaximized(False);
                if (is_full == False)
index f2420c4c4931a1e46947c3ae1895badf72a17376..2f45378117de4fe2ce0add53dc9785597567572b 100644 (file)
@@ -327,6 +327,7 @@ private :
        Window  m_window;
        Display         *m_display;
        XVisualInfo     *m_visual;
+       GHOST_TWindowState m_normal_state;
 
        /** The first created OpenGL context (for sharing display lists) */
        static GLXContext s_firstContext;