mirror of
https://github.com/glfw/glfw.git
synced 2024-11-29 21:37:27 +00:00
Fixed cursor positioning on OS X.
This commit is contained in:
parent
a8a69006ff
commit
0b5de6dd28
@ -60,6 +60,15 @@ static void leaveFullscreenMode(_GLFWwindow* window)
|
|||||||
[window->ns.view exitFullScreenModeWithOptions:nil];
|
[window->ns.view exitFullScreenModeWithOptions:nil];
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// Transforms the specified y-coordinate between the CG display and NS screen
|
||||||
|
// coordinate systems
|
||||||
|
//
|
||||||
|
static float transformY(float y)
|
||||||
|
{
|
||||||
|
const float height = CGDisplayBounds(CGMainDisplayID()).size.height;
|
||||||
|
return height - y;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
//------------------------------------------------------------------------
|
//------------------------------------------------------------------------
|
||||||
// Delegate for window related notifications
|
// Delegate for window related notifications
|
||||||
@ -941,21 +950,18 @@ void _glfwPlatformSetCursorPos(_GLFWwindow* window, double x, double y)
|
|||||||
{
|
{
|
||||||
if (window->monitor)
|
if (window->monitor)
|
||||||
{
|
{
|
||||||
CGPoint globalPoint = CGPointMake(x, y);
|
CGDisplayMoveCursorToPoint(window->monitor->ns.displayID,
|
||||||
CGDisplayMoveCursorToPoint(CGMainDisplayID(), globalPoint);
|
CGPointMake(x, y));
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
const NSRect contentRect =
|
const NSRect contentRect =
|
||||||
[window->ns.object contentRectForFrameRect:[window->ns.object frame]];
|
[window->ns.object contentRectForFrameRect:[window->ns.object frame]];
|
||||||
NSPoint localPoint = NSMakePoint(x, contentRect.size.height - y - 1);
|
const NSPoint localPoint = NSMakePoint(x, contentRect.size.height - y - 1);
|
||||||
NSPoint globalPoint = [window->ns.object convertBaseToScreen:localPoint];
|
const NSPoint globalPoint = [window->ns.object convertBaseToScreen:localPoint];
|
||||||
CGPoint mainScreenOrigin = CGDisplayBounds(CGMainDisplayID()).origin;
|
|
||||||
double mainScreenHeight = CGDisplayBounds(CGMainDisplayID()).size.height;
|
CGWarpMouseCursorPosition(CGPointMake(globalPoint.x,
|
||||||
CGPoint targetPoint = CGPointMake(globalPoint.x - mainScreenOrigin.x,
|
transformY(globalPoint.y)));
|
||||||
mainScreenHeight - globalPoint.y -
|
|
||||||
mainScreenOrigin.y);
|
|
||||||
CGDisplayMoveCursorToPoint(CGMainDisplayID(), targetPoint);
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user