From e7c4e772141804fd45d922430be5b4f1b32695e9 Mon Sep 17 00:00:00 2001 From: Camilla Berglund Date: Mon, 2 Jul 2012 15:23:36 +0200 Subject: [PATCH] Fixed cursor positioning in fullscreen on Cocoa. --- readme.html | 2 ++ src/cocoa_window.m | 35 ++++++++++++++++------------------- 2 files changed, 18 insertions(+), 19 deletions(-) diff --git a/readme.html b/readme.html index 97a314dd..63334b67 100644 --- a/readme.html +++ b/readme.html @@ -332,6 +332,8 @@ version of GLFW.

  • [Cocoa] Bugfix: The OpenGL framework was not retrieved, making glfwGetProcAddress crash
  • [Cocoa] Bugfix: glfwInit changed the current directory for unbundled executables
  • [Cocoa] Bugfix: The GLFW_WINDOW_NO_RESIZE window parameter was always zero
  • +
  • [Cocoa] Bugfix: The cursor position incorrectly rounded during conversion
  • +
  • [Cocoa] Bugfix: Cursor positioning led to nonsensical results for fullscreen windows
  • [X11] Added support for the GLX_EXT_swap_control extension as an alternative to GLX_SGI_swap_control
  • [X11] Added the POSIX CLOCK_MONOTONIC time source as the preferred method
  • [X11] Added dependency on libm, where present
  • diff --git a/src/cocoa_window.m b/src/cocoa_window.m index 781bfd32..233075a9 100644 --- a/src/cocoa_window.m +++ b/src/cocoa_window.m @@ -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); + } }