mirror of
https://github.com/glfw/glfw.git
synced 2026-09-18 22:55:46 +00:00
Fixed cursor positioning in fullscreen on Cocoa.
This commit is contained in:
+16
-19
@@ -1158,25 +1158,22 @@ void _glfwPlatformWaitEvents( void )
|
||||
|
||||
void _glfwPlatformSetCursorPos(_GLFWwindow* window, int x, int y)
|
||||
{
|
||||
// The library seems to assume that after calling this the cursor won't move,
|
||||
// but obviously it will, and escape the app's window, and activate other apps,
|
||||
// and other badness in pain. I think the API's just silly, but maybe I'm
|
||||
// misunderstanding it...
|
||||
|
||||
// Also, (x, y) are window coords...
|
||||
|
||||
// Also, it doesn't seem possible to write this robustly without
|
||||
// calculating the maximum y coordinate of all screens, since Cocoa's
|
||||
// "global coordinates" are upside down from CG's...
|
||||
|
||||
NSPoint localPoint = NSMakePoint(x, window->height - y - 1);
|
||||
NSPoint globalPoint = [window->NS.object convertBaseToScreen:localPoint];
|
||||
CGPoint mainScreenOrigin = CGDisplayBounds(CGMainDisplayID()).origin;
|
||||
double mainScreenHeight = CGDisplayBounds(CGMainDisplayID()).size.height;
|
||||
CGPoint targetPoint = CGPointMake(globalPoint.x - mainScreenOrigin.x,
|
||||
mainScreenHeight - globalPoint.y -
|
||||
mainScreenOrigin.y);
|
||||
CGDisplayMoveCursorToPoint(CGMainDisplayID(), targetPoint);
|
||||
if (window->mode == GLFW_FULLSCREEN)
|
||||
{
|
||||
NSPoint globalPoint = NSMakePoint(x, y);
|
||||
CGDisplayMoveCursorToPoint(CGMainDisplayID(), globalPoint);
|
||||
}
|
||||
else
|
||||
{
|
||||
NSPoint localPoint = NSMakePoint(x, window->height - y - 1);
|
||||
NSPoint globalPoint = [window->NS.object convertBaseToScreen:localPoint];
|
||||
CGPoint mainScreenOrigin = CGDisplayBounds(CGMainDisplayID()).origin;
|
||||
double mainScreenHeight = CGDisplayBounds(CGMainDisplayID()).size.height;
|
||||
CGPoint targetPoint = CGPointMake(globalPoint.x - mainScreenOrigin.x,
|
||||
mainScreenHeight - globalPoint.y -
|
||||
mainScreenOrigin.y);
|
||||
CGDisplayMoveCursorToPoint(CGMainDisplayID(), targetPoint);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
|
||||
Reference in New Issue
Block a user