wrap the mouse within the region while grabbing so on release the current view never...
[blender-staging.git] / intern / ghost / intern / GHOST_WindowX11.cpp
index 060e9ca6f6cf275bf23845d6b9a4c42b738fa03b..dba1be1b86275b8521e73bfcfc236e3557f74794 100644 (file)
@@ -1400,12 +1400,30 @@ setWindowCursorVisibility(
        GHOST_TSuccess
 GHOST_WindowX11::
 setWindowCursorGrab(
-       bool grab
+       GHOST_TGrabCursorMode mode
 ){
-       if(grab)
+       if(mode != GHOST_kGrabDisable) {
+               if(mode != GHOST_kGrabNormal) {
+                       m_system->getCursorPosition(m_cursorGrabInitPos[0], m_cursorGrabInitPos[1]);
+                       setCursorGrabAccum(0, 0);
+
+                       if(mode == GHOST_kGrabHide)
+                               setWindowCursorVisibility(false);
+
+               }
                XGrabPointer(m_display, m_window, True, ButtonPressMask| ButtonReleaseMask|PointerMotionMask, GrabModeAsync, GrabModeAsync, None, None, CurrentTime);
-       else
+       }
+       else {
+               if (m_cursorGrab==GHOST_kGrabHide) {
+                       m_system->setCursorPosition(m_cursorGrabInitPos[0], m_cursorGrabInitPos[1]);
+                       setWindowCursorVisibility(true);
+               }
+
+               /* Almost works without but important otherwise the mouse GHOST location can be incorrect on exit */
+               setCursorGrabAccum(0, 0);
+               m_cursorGrabBounds.m_l= m_cursorGrabBounds.m_r= -1; /* disable */
                XUngrabPointer(m_display, CurrentTime);
+       }
 
        XFlush(m_display);