From 9cd04ec4368b746719cd6fab50d32a08ff3c3d40 Mon Sep 17 00:00:00 2001 From: rti Date: Sun, 13 Jun 2010 15:40:59 +0200 Subject: [PATCH] Changed: #947 fixed mouse position setting on non main monitor --- .../src/3d/driver/opengl/mac/cocoa_adapter.mm | 42 +++++-------------- 1 file changed, 11 insertions(+), 31 deletions(-) diff --git a/code/nel/src/3d/driver/opengl/mac/cocoa_adapter.mm b/code/nel/src/3d/driver/opengl/mac/cocoa_adapter.mm index 37eb203f1..c236cc9d2 100644 --- a/code/nel/src/3d/driver/opengl/mac/cocoa_adapter.mm +++ b/code/nel/src/3d/driver/opengl/mac/cocoa_adapter.mm @@ -388,43 +388,23 @@ void showCursor(bool b) void setMousePos(float x, float y) { - /* - TODO FIXME for windows placed on non primary monitor - */ + // CG wants absolute coordinates related to first screen's top left - // CG wants absolute coordinates related to screen top left - CGFloat fromScreenLeft = 0.0; - CGFloat fromScreenTop = 0.0; + // get the first screen's (conaints menubar) rect (this is not mainScreen) + NSRect firstScreenRect = [[[NSScreen screens] objectAtIndex:0] frame]; + + // get the rect (position, size) of the window + NSRect windowRect = [g_window frame]; // get the gl view's rect for height and width NSRect viewRect = [g_glview frame]; - // if the view is not fullscreen, window top left is needed as offset - if(![g_glview isInFullScreenMode]) - { - // get the rect (position, size) of the screen - NSRect screenRect = [[g_window screen] frame]; - - // get the rect (position, size) of the window - NSRect windowRect = [g_window frame]; - - // window's x is ok - fromScreenLeft = windowRect.origin.x; - - // TODO this code assumes, that the view fills the window - - // map window bottom to view top - fromScreenTop = screenRect.size.height - - viewRect.size.height - windowRect.origin.y; - } - - // position inside the view - fromScreenLeft += (viewRect.size.width * x); - fromScreenTop += (viewRect.size.height * (1 - y)); - - // actually set the mouse position + // set the cursor position CGDisplayErr error = CGDisplayMoveCursorToPoint( - kCGDirectMainDisplay, CGPointMake(fromScreenLeft, fromScreenTop)); + kCGDirectMainDisplay, CGPointMake( + windowRect.origin.x + (viewRect.size.width * x), + firstScreenRect.size.height - windowRect.origin.y - + viewRect.size.height + ((1.0 - y) * viewRect.size.height))); if(error != kCGErrorSuccess) nlerror("cannot set mouse position");