diff options
author | Damien Plisson <damien.plisson@yahoo.fr> | 2009-10-21 19:39:32 +0400 |
---|---|---|
committer | Damien Plisson <damien.plisson@yahoo.fr> | 2009-10-21 19:39:32 +0400 |
commit | eab11543f3c411940744ab2f447a5c222d5a50dd (patch) | |
tree | 58ee2183feefe8281fb58860e98265b0c4ebdbce /intern | |
parent | 77ccb5aec1cc53cd6ab85d3cfc5eb3a073b982b0 (diff) |
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
Diffstat (limited to 'intern')
-rw-r--r-- | intern/ghost/intern/GHOST_SystemCocoa.mm | 27 | ||||
-rw-r--r-- | intern/ghost/intern/GHOST_WindowCocoa.h | 6 | ||||
-rw-r--r-- | intern/ghost/intern/GHOST_WindowCocoa.mm | 7 |
3 files changed, 31 insertions, 9 deletions
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 @@ -170,6 +170,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. * @return Indication of success. 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. |