Changed: #947 fixed mouse position setting on non main monitor
This commit is contained in:
parent
dbb76e53cd
commit
daa6cf3051
1 changed files with 11 additions and 31 deletions
|
@ -388,43 +388,23 @@ void showCursor(bool b)
|
||||||
|
|
||||||
void setMousePos(float x, float y)
|
void setMousePos(float x, float y)
|
||||||
{
|
{
|
||||||
/*
|
// CG wants absolute coordinates related to first screen's top left
|
||||||
TODO FIXME for windows placed on non primary monitor
|
|
||||||
*/
|
|
||||||
|
|
||||||
// CG wants absolute coordinates related to screen top left
|
// get the first screen's (conaints menubar) rect (this is not mainScreen)
|
||||||
CGFloat fromScreenLeft = 0.0;
|
NSRect firstScreenRect = [[[NSScreen screens] objectAtIndex:0] frame];
|
||||||
CGFloat fromScreenTop = 0.0;
|
|
||||||
|
|
||||||
// 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
|
// get the rect (position, size) of the window
|
||||||
NSRect windowRect = [g_window frame];
|
NSRect windowRect = [g_window frame];
|
||||||
|
|
||||||
// window's x is ok
|
// get the gl view's rect for height and width
|
||||||
fromScreenLeft = windowRect.origin.x;
|
NSRect viewRect = [g_glview frame];
|
||||||
|
|
||||||
// TODO this code assumes, that the view fills the window
|
// set the cursor position
|
||||||
|
|
||||||
// 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
|
|
||||||
CGDisplayErr error = CGDisplayMoveCursorToPoint(
|
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)
|
if(error != kCGErrorSuccess)
|
||||||
nlerror("cannot set mouse position");
|
nlerror("cannot set mouse position");
|
||||||
|
|
Loading…
Reference in a new issue