From 3ec843a1da87044cad83a8a77161f7af586680e5 Mon Sep 17 00:00:00 2001 From: Camilla Berglund Date: Mon, 22 Apr 2013 00:38:51 +0200 Subject: [PATCH] Fixed captured cursor mode on OS X. --- src/cocoa_platform.h | 2 ++ src/cocoa_window.m | 44 +++++++++++++++++++++++++++----------------- 2 files changed, 29 insertions(+), 17 deletions(-) diff --git a/src/cocoa_platform.h b/src/cocoa_platform.h index d98bddce..62dc726d 100644 --- a/src/cocoa_platform.h +++ b/src/cocoa_platform.h @@ -109,6 +109,8 @@ typedef struct _GLFWlibraryNS id autoreleasePool; id cursor; + GLboolean cursorHidden; + char* clipboardString; _GLFWjoy joysticks[GLFW_JOYSTICK_LAST + 1]; diff --git a/src/cocoa_window.m b/src/cocoa_window.m index 3a5ee139..762e2a1c 100644 --- a/src/cocoa_window.m +++ b/src/cocoa_window.m @@ -942,26 +942,36 @@ void _glfwPlatformSetCursorPos(_GLFWwindow* window, double x, double y) void _glfwPlatformSetCursorMode(_GLFWwindow* window, int mode) { - // Unhide the cursor if the last mode was CAPTURED. - if (window->cursorMode == GLFW_CURSOR_CAPTURED) { - CGAssociateMouseAndMouseCursorPosition(true); + if (mode == GLFW_CURSOR_HIDDEN) + { + [window->ns.object enableCursorRects]; + [window->ns.object invalidateCursorRectsForView:window->ns.view]; + } + else + { + [window->ns.object disableCursorRects]; + [window->ns.object invalidateCursorRectsForView:window->ns.view]; } - switch (mode) + if (mode == GLFW_CURSOR_CAPTURED) { - case GLFW_CURSOR_NORMAL: - [window->ns.object disableCursorRects]; - [window->ns.object invalidateCursorRectsForView:window->ns.view]; - break; - case GLFW_CURSOR_HIDDEN: - [window->ns.object enableCursorRects]; - [window->ns.object invalidateCursorRectsForView:window->ns.view]; - break; - case GLFW_CURSOR_CAPTURED: - [window->ns.object enableCursorRects]; - [window->ns.object invalidateCursorRectsForView:window->ns.view]; - CGAssociateMouseAndMouseCursorPosition(false); - break; + CGAssociateMouseAndMouseCursorPosition(false); + + if (!_glfw.ns.cursorHidden) + { + [NSCursor hide]; + _glfw.ns.cursorHidden = GL_TRUE; + } + } + else + { + CGAssociateMouseAndMouseCursorPosition(true); + + if (_glfw.ns.cursorHidden) + { + [NSCursor unhide]; + _glfw.ns.cursorHidden = GL_FALSE; + } } }