fix for fullscreen on X11 (used by the BGE, not blender application),
authorCampbell Barton <ideasman42@gmail.com>
Sun, 24 Feb 2013 05:05:29 +0000 (05:05 +0000)
committerCampbell Barton <ideasman42@gmail.com>
Sun, 24 Feb 2013 05:05:29 +0000 (05:05 +0000)
changing the screen resolution wasn't still allowed for larger virtual desktops.

added an exclusive option to ghost so the fullscreen window is ignored by the window manager and we get all events. (common practice for games on X11).

12 files changed:
intern/ghost/GHOST_ISystem.h
intern/ghost/GHOST_IWindow.h
intern/ghost/intern/GHOST_System.cpp
intern/ghost/intern/GHOST_System.h
intern/ghost/intern/GHOST_SystemX11.cpp
intern/ghost/intern/GHOST_SystemX11.h
intern/ghost/intern/GHOST_Window.cpp
intern/ghost/intern/GHOST_Window.h
intern/ghost/intern/GHOST_WindowManager.cpp
intern/ghost/intern/GHOST_WindowX11.cpp
intern/ghost/intern/GHOST_WindowX11.h
source/gameengine/GamePlayer/ghost/GPG_Application.cpp

index 841293e..e0b483d 100644 (file)
@@ -253,6 +253,7 @@ public:
            GHOST_TInt32 left, GHOST_TInt32 top, GHOST_TUns32 width, GHOST_TUns32 height,
            GHOST_TWindowState state, GHOST_TDrawingContextType type,
            const bool stereoVisual = false,
+           const bool exclusive = false,
            const GHOST_TUns16 numOfAASamples = 0,
            const GHOST_TEmbedderWindowID parentWindow = 0) = 0;
 
index 4cf0dbf..a2d3e9b 100644 (file)
@@ -305,7 +305,10 @@ public:
         */
        virtual GHOST_TSuccess setCursorGrab(GHOST_TGrabCursorMode mode, GHOST_Rect *bounds, GHOST_TInt32 mouse_ungrab_xy[2]) { return GHOST_kSuccess; }
 
-       
+       /** */
+       virtual GHOST_TSuccess beginFullScreen() const = 0;
+       virtual GHOST_TSuccess endFullScreen() const = 0;
+
        virtual float getNativePixelSize(void) = 0;
 
        
index 080619b..5405fe7 100644 (file)
@@ -152,7 +152,7 @@ GHOST_TSuccess GHOST_System::beginFullScreen(const GHOST_DisplaySetting& setting
                        success = m_displayManager->setCurrentDisplaySetting(GHOST_DisplayManager::kMainDisplay, setting);
                        if (success == GHOST_kSuccess) {
                                //GHOST_PRINT("GHOST_System::beginFullScreen(): creating full-screen window\n");
-                               success = createFullScreenWindow((GHOST_Window **)window, stereoVisual, numOfAASamples);
+                               success = createFullScreenWindow((GHOST_Window **)window, setting, stereoVisual, numOfAASamples);
                                if (success == GHOST_kSuccess) {
                                        m_windowManager->beginFullScreen(*window, stereoVisual);
                                }
@@ -347,26 +347,22 @@ GHOST_TSuccess GHOST_System::exit()
        return GHOST_kSuccess;
 }
 
-
-GHOST_TSuccess GHOST_System::createFullScreenWindow(GHOST_Window **window, const bool stereoVisual, const GHOST_TUns16 numOfAASamples)
+GHOST_TSuccess GHOST_System::createFullScreenWindow(GHOST_Window **window, const GHOST_DisplaySetting &settings,
+                                                    const bool stereoVisual, const GHOST_TUns16 numOfAASamples)
 {
-       GHOST_TSuccess success;
+       /* note: don't use getCurrentDisplaySetting() because on X11 we may
+        * be zoomed in and the desktop may be bigger then the viewport. */
        GHOST_ASSERT(m_displayManager, "GHOST_System::createFullScreenWindow(): invalid display manager");
-       GHOST_DisplaySetting settings;
-
-       success = m_displayManager->getCurrentDisplaySetting(GHOST_DisplayManager::kMainDisplay, settings);
-       if (success) {
-               //GHOST_PRINT("GHOST_System::createFullScreenWindow(): creating full-screen window\n");
-               *window = (GHOST_Window *)createWindow(
-                   STR_String(""),
-                   0, 0, settings.xPixels, settings.yPixels,
-                   GHOST_kWindowStateFullScreen,
-                   GHOST_kDrawingContextTypeOpenGL,
-                   stereoVisual,
-                   numOfAASamples);
-               success = *window == 0 ? GHOST_kFailure : GHOST_kSuccess;
-       }
-       return success;
+       //GHOST_PRINT("GHOST_System::createFullScreenWindow(): creating full-screen window\n");
+       *window = (GHOST_Window *)createWindow(
+           STR_String(""),
+           0, 0, settings.xPixels, settings.yPixels,
+           GHOST_kWindowStateNormal,
+           GHOST_kDrawingContextTypeOpenGL,
+           stereoVisual,
+           true,  /* exclusive */
+           numOfAASamples);
+       return (*window == NULL) ? GHOST_kFailure : GHOST_kSuccess;
 }
 
 
index 928bbe6..0d18dfe 100644 (file)
@@ -330,7 +330,7 @@ protected:
         * \param window The window created.
         * \return Indication of success.
         */
-       virtual GHOST_TSuccess createFullScreenWindow(GHOST_Window **window,
+       virtual GHOST_TSuccess createFullScreenWindow(GHOST_Window **window, const GHOST_DisplaySetting &settings,
                                                      const bool stereoVisual, const GHOST_TUns16 numOfAASamples = 0);
 
        /** The display manager (platform dependant). */
index 48fb837..d00265f 100644 (file)
@@ -278,6 +278,8 @@ getAllDisplayDimensions(
  * \param      state   The state of the window when opened.
  * \param      type    The type of drawing context installed in this window.
  * \param      stereoVisual    Stereo visual for quad buffered stereo.
+ * \param      exclusive       Use to show the window ontop and ignore others
+ *                                             (used fullscreen).
  * \param      numOfAASamples  Number of samples used for AA (zero if no AA)
  * \param      parentWindow    Parent (embedder) window
  * \return     The new window (or 0 if creation failed).
@@ -292,7 +294,8 @@ createWindow(
                GHOST_TUns32 height,
                GHOST_TWindowState state,
                GHOST_TDrawingContextType type,
-               bool stereoVisual,
+               const bool stereoVisual,
+               const bool exclusive,
                const GHOST_TUns16 numOfAASamples,
                const GHOST_TEmbedderWindowID parentWindow)
 {
@@ -305,7 +308,9 @@ createWindow(
 
        window = new GHOST_WindowX11(this, m_display, title,
                                     left, top, width, height,
-                                    state, parentWindow, type, stereoVisual, numOfAASamples);
+                                    state, parentWindow, type,
+                                    stereoVisual, exclusive,
+                                    numOfAASamples);
 
        if (window) {
                /* Both are now handle in GHOST_WindowX11.cpp
index a11aea2..6a492f6 100644 (file)
@@ -137,7 +137,9 @@ public:
         * \param       height          The height the window.
         * \param       state           The state of the window when opened.
         * \param       type            The type of drawing context installed in this window.
-        * \param       stereoVisual    Create a stereo visual for quad buffered stereo.
+        * \param       stereoVisual    Create a stereo visual for quad buffered stereo.
+        * \param       exclusive       Use to show the window ontop and ignore others
+        *                                              (used fullscreen).
         * \param       parentWindow    Parent (embedder) window
         * \return      The new window (or 0 if creation failed).
         */
@@ -151,6 +153,7 @@ public:
            GHOST_TWindowState state,
            GHOST_TDrawingContextType type,
            const bool stereoVisual,
+           const bool exclusive = false,
            const GHOST_TUns16 numOfAASamples = 0,
            const GHOST_TEmbedderWindowID parentWindow = 0
            );
index ca12abe..6c2d735 100644 (file)
@@ -45,6 +45,7 @@ GHOST_Window::GHOST_Window(
     GHOST_TWindowState state,
     GHOST_TDrawingContextType type,
     const bool stereoVisual,
+    const bool exclusive,
     const GHOST_TUns16 numOfAASamples)
        :
        m_drawingContextType(type),
index f7c67bf..588de09 100644 (file)
@@ -80,6 +80,8 @@ public:
         * \param state                         The state the window is initially opened with.
         * \param type                          The type of drawing context installed in this window.
         * \param stereoVisual          Stereo visual for quad buffered stereo.
+        * \param exclusive                     Use to show the window ontop and ignore others
+        *                                                      (used fullscreen).
         * \param numOfAASamples        Number of samples used for AA (zero if no AA)
         */
        GHOST_Window(
@@ -88,6 +90,7 @@ public:
            GHOST_TWindowState state,
            GHOST_TDrawingContextType type = GHOST_kDrawingContextTypeNone,
            const bool stereoVisual = false,
+           const bool exclusive = false,
            const GHOST_TUns16 numOfAASamples = 0);
 
        /**
index daf1c2f..1f20e01 100644 (file)
@@ -130,12 +130,12 @@ GHOST_TSuccess GHOST_WindowManager::beginFullScreen(GHOST_IWindow *window,
                m_fullScreenWindow = window;
                m_activeWindowBeforeFullScreen = getActiveWindow();
                setActiveWindow(m_fullScreenWindow);
+               m_fullScreenWindow->beginFullScreen();
                success = GHOST_kSuccess;
        }
        return success;
 }
 
-
 GHOST_TSuccess GHOST_WindowManager::endFullScreen(void)
 {
        GHOST_TSuccess success = GHOST_kFailure;
@@ -143,6 +143,7 @@ GHOST_TSuccess GHOST_WindowManager::endFullScreen(void)
                if (m_fullScreenWindow != 0) {
                        //GHOST_PRINT("GHOST_WindowManager::endFullScreen(): deleting full-screen window\n");
                        setWindowInactive(m_fullScreenWindow);
+                       m_fullScreenWindow->endFullScreen();
                        delete m_fullScreenWindow;
                        //GHOST_PRINT("GHOST_WindowManager::endFullScreen(): done\n");
                        m_fullScreenWindow = 0;
index 8184475..05ab244 100644 (file)
@@ -165,9 +165,10 @@ GHOST_WindowX11(
     const GHOST_TEmbedderWindowID parentWindow,
     GHOST_TDrawingContextType type,
     const bool stereoVisual,
+    const bool exclusive,
     const GHOST_TUns16 numOfAASamples
     ) :
-       GHOST_Window(width, height, state, type, stereoVisual, numOfAASamples),
+       GHOST_Window(width, height, state, type, stereoVisual, exclusive, numOfAASamples),
        m_context(NULL),
        m_display(display),
        m_normal_state(GHOST_kWindowStateNormal),
@@ -254,6 +255,7 @@ GHOST_WindowX11(
         * This seems pretty much a legacy feature as we are in rgba mode anyway. */
 
        XSetWindowAttributes xattributes;
+       unsigned int xattributes_valuemask = (CWBorderPixel | CWColormap | CWEventMask);
        memset(&xattributes, 0, sizeof(xattributes));
 
        xattributes.colormap = XCreateColormap(m_display,
@@ -274,6 +276,11 @@ GHOST_WindowX11(
                PointerMotionMask | FocusChangeMask |
                PropertyChangeMask | KeymapStateMask;
 
+       if (exclusive) {
+               xattributes_valuemask |= CWOverrideRedirect;
+               xattributes.override_redirect = True;
+       }
+
        /* create the window! */
        if (parentWindow == 0) {
                m_window =  XCreateWindow(m_display,
@@ -286,7 +293,7 @@ GHOST_WindowX11(
                                          m_visual->depth,
                                          InputOutput,
                                          m_visual->visual,
-                                         CWBorderPixel | CWColormap | CWEventMask,
+                                         xattributes_valuemask,
                                          &xattributes
                                          );
        }
@@ -315,7 +322,7 @@ GHOST_WindowX11(
                                         m_visual->depth,
                                         InputOutput,
                                         m_visual->visual,
-                                        CWBorderPixel | CWColormap | CWEventMask,
+                                        xattributes_valuemask,
                                         &xattributes
                                         );
 
@@ -486,7 +493,12 @@ GHOST_WindowX11(
                GHOST_PRINT("Created window\n");
        }
 
-       XMapWindow(m_display, m_window);
+       if (exclusive) {
+               XMapRaised(m_display, m_window);
+       }
+       else {
+               XMapWindow(m_display, m_window);
+       }
        GHOST_PRINT("Mapped window\n");
 
        XFlush(m_display);
@@ -1498,3 +1510,44 @@ setWindowCustomCursorShape(
 
        return GHOST_kSuccess;
 }
+
+
+GHOST_TSuccess
+GHOST_WindowX11::
+beginFullScreen() const
+{
+       {
+               Window root_return;
+               int x_return, y_return;
+               unsigned int w_return, h_return, border_w_return, depth_return;
+
+               XGetGeometry(m_display, m_window, &root_return, &x_return, &y_return,
+                            &w_return, &h_return, &border_w_return, &depth_return);
+
+               m_system->setCursorPosition(w_return / 2, h_return / 2);
+       }
+
+
+       /* Grab Keyboard & Mouse */
+       int err;
+
+       err = XGrabKeyboard(m_display, m_window, False,
+                           GrabModeAsync, GrabModeAsync, CurrentTime);
+       if (err != GrabSuccess) printf("XGrabKeyboard failed %d\n", err);
+
+       err = XGrabPointer(m_display, m_window, False,  PointerMotionMask | ButtonPressMask | ButtonReleaseMask,
+                          GrabModeAsync, GrabModeAsync, m_window, None, CurrentTime);
+       if (err != GrabSuccess) printf("XGrabPointer failed %d\n", err);
+
+       return GHOST_kSuccess;
+}
+
+GHOST_TSuccess
+GHOST_WindowX11::
+endFullScreen() const
+{
+       XUngrabKeyboard(m_display, CurrentTime);
+       XUngrabPointer(m_display, CurrentTime);
+
+       return GHOST_kSuccess;
+}
index 10d4498..c009512 100644 (file)
@@ -87,6 +87,7 @@ public:
            const GHOST_TEmbedderWindowID parentWindow,
            GHOST_TDrawingContextType type = GHOST_kDrawingContextTypeNone,
            const bool stereoVisual = false,
+           const bool exclusive = false,
            const GHOST_TUns16 numOfAASamples = 0
            );
 
@@ -308,6 +309,12 @@ protected:
            int bg_color
            );
 
+       GHOST_TSuccess
+       beginFullScreen() const;
+
+       GHOST_TSuccess
+       endFullScreen() const;
+
 private:
 
        /// Force use of public constructor.
index 89d1151..f3f4c31 100644 (file)
@@ -386,6 +386,7 @@ bool GPG_Application::startFullScreen(
 
        fSystem->beginFullScreen(setting, &m_mainWindow, stereoVisual, samples);
        m_mainWindow->setCursorVisibility(false);
+       /* note that X11 ignores this (it uses a window internally for fullscreen) */
        m_mainWindow->setState(GHOST_kWindowStateFullScreen);
 
        success = initEngine(m_mainWindow, stereoMode);