From d9d3a2a5009c76f68fd2e6456db7dac61c4d2e49 Mon Sep 17 00:00:00 2001 From: Brecht Van Lommel Date: Sat, 3 Oct 2015 03:37:41 +0200 Subject: Fix T44605: OS X continuous grab issues. --- intern/ghost/intern/GHOST_C-api.cpp | 19 ++++++------------- intern/ghost/intern/GHOST_SystemCocoa.mm | 2 ++ intern/ghost/intern/GHOST_WindowCocoa.mm | 7 ++----- 3 files changed, 10 insertions(+), 18 deletions(-) (limited to 'intern') diff --git a/intern/ghost/intern/GHOST_C-api.cpp b/intern/ghost/intern/GHOST_C-api.cpp index af992bf5a3c..9baa66abad9 100644 --- a/intern/ghost/intern/GHOST_C-api.cpp +++ b/intern/ghost/intern/GHOST_C-api.cpp @@ -358,27 +358,20 @@ GHOST_TSuccess GHOST_SetCursorGrab(GHOST_WindowHandle windowhandle, int bounds[4], const int mouse_ungrab_xy[2]) { GHOST_IWindow *window = (GHOST_IWindow *) windowhandle; - GHOST_Rect bounds_rect, bounds_win; - GHOST_TInt32 mouse_ungrab_xy_global[2]; + GHOST_Rect bounds_rect; + GHOST_TInt32 mouse_xy[2]; if (bounds) { - /* if this is X11 specific we need a function that converts */ - window->getClientBounds(bounds_win); - window->clientToScreen(bounds[0], bounds_win.getHeight() - bounds[1], bounds_rect.m_l, bounds_rect.m_t); - window->clientToScreen(bounds[2], bounds_win.getHeight() - bounds[3], bounds_rect.m_r, bounds_rect.m_b); - + bounds_rect = GHOST_Rect(bounds[0], bounds[1], bounds[2], bounds[3]); } - if (mouse_ungrab_xy) { - if (bounds == NULL) - window->getClientBounds(bounds_win); - window->clientToScreen(mouse_ungrab_xy[0], bounds_win.getHeight() - mouse_ungrab_xy[1], - mouse_ungrab_xy_global[0], mouse_ungrab_xy_global[1]); + mouse_xy[0] = mouse_ungrab_xy[0]; + mouse_xy[1] = mouse_ungrab_xy[1]; } return window->setCursorGrab(mode, bounds ? &bounds_rect : NULL, - mouse_ungrab_xy ? mouse_ungrab_xy_global : NULL); + mouse_ungrab_xy ? mouse_xy : NULL); } diff --git a/intern/ghost/intern/GHOST_SystemCocoa.mm b/intern/ghost/intern/GHOST_SystemCocoa.mm index b9686e5af9b..37c2ac12315 100644 --- a/intern/ghost/intern/GHOST_SystemCocoa.mm +++ b/intern/ghost/intern/GHOST_SystemCocoa.mm @@ -1317,6 +1317,7 @@ GHOST_TSuccess GHOST_SystemCocoa::handleMouseEvent(void *eventPtr) GHOST_TInt32 x_warp, y_warp, x_accum, y_accum, x, y; window->getCursorGrabInitPos(x_warp, y_warp); + window->screenToClientIntern(x_warp, y_warp, x_warp, y_warp); window->getCursorGrabAccum(x_accum, y_accum); x_accum += [event deltaX]; @@ -1368,6 +1369,7 @@ GHOST_TSuccess GHOST_SystemCocoa::handleMouseEvent(void *eventPtr) //Post event window->getCursorGrabInitPos(x_cur, y_cur); + window->screenToClientIntern(x_cur, y_cur, x_cur, y_cur); window->clientToScreenIntern(x_cur + x_accum, y_cur + y_accum, x, y); pushEvent(new GHOST_EventCursor([event timestamp] * 1000, GHOST_kEventCursorMove, window, x, y)); break; diff --git a/intern/ghost/intern/GHOST_WindowCocoa.mm b/intern/ghost/intern/GHOST_WindowCocoa.mm index 9c7b5c3fee7..204d61de3df 100644 --- a/intern/ghost/intern/GHOST_WindowCocoa.mm +++ b/intern/ghost/intern/GHOST_WindowCocoa.mm @@ -1463,12 +1463,9 @@ GHOST_TSuccess GHOST_WindowCocoa::setWindowCursorGrab(GHOST_TGrabCursorMode mode if (mode != GHOST_kGrabDisable) { //No need to perform grab without warp as it is always on in OS X if (mode != GHOST_kGrabNormal) { - GHOST_TInt32 x_old,y_old; NSAutoreleasePool *pool = [[NSAutoreleasePool alloc] init]; - m_systemCocoa->getCursorPosition(x_old,y_old); - screenToClientIntern(x_old, y_old, m_cursorGrabInitPos[0], m_cursorGrabInitPos[1]); - //Warp position is stored in client (window base) coordinates + m_systemCocoa->getCursorPosition(m_cursorGrabInitPos[0], m_cursorGrabInitPos[1]); setCursorGrabAccum(0, 0); if (mode == GHOST_kGrabHide) { @@ -1486,7 +1483,7 @@ GHOST_TSuccess GHOST_WindowCocoa::setWindowCursorGrab(GHOST_TGrabCursorMode mode } else { if (m_cursorGrab==GHOST_kGrabHide) { - //No need to set again cursor position, as it has not changed for Cocoa + m_systemCocoa->setCursorPosition(m_cursorGrabInitPos[0], m_cursorGrabInitPos[1]); setWindowCursorVisibility(true); } -- cgit v1.2.3