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 ab46c050fa38924b56082f5da638d78fc07cdac8..dba1be1b86275b8521e73bfcfc236e3557f74794 100644 (file)
@@ -450,7 +450,7 @@ static bool match_token(const char *haystack, const char *needle)
 **  Wacoms x11 config "cursor" refers to its device slot (which we mirror with
 **  our gSysCursors) for puck like devices (tablet mice essentially).
 */
-
+#if 0 // unused
 static BOOL is_tablet_cursor(const char *name, const char *type)
 {
        int i;
@@ -474,7 +474,7 @@ static BOOL is_tablet_cursor(const char *name, const char *type)
        }
        return FALSE;
 }
-
+#endif
 static BOOL is_stylus(const char *name, const char *type)
 {
        int i;
@@ -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);