From eab11543f3c411940744ab2f447a5c222d5a50dd Mon Sep 17 00:00:00 2001 From: Damien Plisson Date: Wed, 21 Oct 2009 15:39:32 +0000 Subject: Cocoa / Mac: - fix set mouse cursor position in case of multi-display setting. Enables continuous grab to work when blender window is on a secondary display --- intern/ghost/intern/GHOST_SystemCocoa.mm | 27 ++++++++++++++++++--------- intern/ghost/intern/GHOST_WindowCocoa.h | 6 ++++++ intern/ghost/intern/GHOST_WindowCocoa.mm | 7 +++++++ 3 files changed, 31 insertions(+), 9 deletions(-) (limited to 'intern') diff --git a/intern/ghost/intern/GHOST_SystemCocoa.mm b/intern/ghost/intern/GHOST_SystemCocoa.mm index 3b2c5ea76a3..2d665012bf1 100644 --- a/intern/ghost/intern/GHOST_SystemCocoa.mm +++ b/intern/ghost/intern/GHOST_SystemCocoa.mm @@ -797,7 +797,9 @@ GHOST_TSuccess GHOST_SystemCocoa::endFullScreen(void) - +/** + * @note : returns coordinates in Cocoa screen coordinates + */ GHOST_TSuccess GHOST_SystemCocoa::getCursorPosition(GHOST_TInt32& x, GHOST_TInt32& y) const { NSPoint mouseLoc = [NSEvent mouseLocation]; @@ -808,17 +810,24 @@ GHOST_TSuccess GHOST_SystemCocoa::getCursorPosition(GHOST_TInt32& x, GHOST_TInt3 return GHOST_kSuccess; } - +/** + * @note : expect Cocoa screen coordinates + */ GHOST_TSuccess GHOST_SystemCocoa::setCursorPosition(GHOST_TInt32 x, GHOST_TInt32 y) const { float xf=(float)x, yf=(float)y; + GHOST_WindowCocoa* window = (GHOST_WindowCocoa*)m_windowManager->getActiveWindow(); + NSScreen *windowScreen = window->getScreen(); + NSRect screenRect = [windowScreen frame]; - //Quartz Display Services uses the old coordinates (top left origin) - yf = [[NSScreen mainScreen] frame].size.height -yf; + //Set position relative to current screen + xf -= screenRect.origin.x; + yf -= screenRect.origin.y; - //CGAssociateMouseAndMouseCursorPosition(false); - CGWarpMouseCursorPosition(CGPointMake(xf, yf)); - //CGAssociateMouseAndMouseCursorPosition(true); + //Quartz Display Services uses the old coordinates (top left origin) + yf = screenRect.size.height -yf; + + CGDisplayMoveCursorToPoint([[[windowScreen deviceDescription] objectForKey:@"NSScreenNumber"] unsignedIntValue], CGPointMake(xf, yf)); return GHOST_kSuccess; } @@ -1174,10 +1183,10 @@ GHOST_TSuccess GHOST_SystemCocoa::handleMouseEvent(void *eventPtr) //Switch back to Cocoa coordinates orientation (y=0 at botton,the same as blender internal btw!), and to client coordinates window->getClientBounds(windowBounds); - bounds.m_b = (windowBounds.m_b - windowBounds.m_t) - bounds.m_b; - bounds.m_t = (windowBounds.m_b - windowBounds.m_t) - bounds.m_t; window->screenToClient(bounds.m_l,bounds.m_b, correctedBounds.m_l, correctedBounds.m_t); window->screenToClient(bounds.m_r, bounds.m_t, correctedBounds.m_r, correctedBounds.m_b); + correctedBounds.m_b = (windowBounds.m_b - windowBounds.m_t) - correctedBounds.m_b; + correctedBounds.m_t = (windowBounds.m_b - windowBounds.m_t) - correctedBounds.m_t; //Update accumulation counts window->getCursorGrabAccum(x_accum, y_accum); diff --git a/intern/ghost/intern/GHOST_WindowCocoa.h b/intern/ghost/intern/GHOST_WindowCocoa.h index 5368d0f1e13..e3479ada5d6 100644 --- a/intern/ghost/intern/GHOST_WindowCocoa.h +++ b/intern/ghost/intern/GHOST_WindowCocoa.h @@ -169,6 +169,12 @@ public: */ virtual void clientToScreen(GHOST_TInt32 inX, GHOST_TInt32 inY, GHOST_TInt32& outX, GHOST_TInt32& outY) const; + /** + * Gets the screen the window is displayed in + * @return The NSScreen object + */ + NSScreen* getScreen(); + /** * Sets the state of the window (normal, minimized, maximized). * @param state The state of the window. diff --git a/intern/ghost/intern/GHOST_WindowCocoa.mm b/intern/ghost/intern/GHOST_WindowCocoa.mm index b9a598cb265..0090d8e1038 100644 --- a/intern/ghost/intern/GHOST_WindowCocoa.mm +++ b/intern/ghost/intern/GHOST_WindowCocoa.mm @@ -515,6 +515,13 @@ void GHOST_WindowCocoa::clientToScreen(GHOST_TInt32 inX, GHOST_TInt32 inY, GHOST outY = screenCoord.y; } + +NSScreen* GHOST_WindowCocoa::getScreen() +{ + return [m_window screen]; +} + + /** * @note Fullscreen switch is not actual fullscreen with display capture. As this capture removes all OS X window manager features. * Instead, the menu bar and the dock are hidden, and the window is made borderless and enlarged. -- cgit v1.2.3