From f03a8bd15211332b129eddfad8a8d5f51f78bd9e Mon Sep 17 00:00:00 2001 From: Dmitri Shuralyov Date: Wed, 24 Jul 2013 23:23:55 -0700 Subject: [PATCH] Support for getting cursor position after window creation and setting window position, before mouse moves. --- src/cocoa_window.m | 19 +++++++++++++++++++ 1 file changed, 19 insertions(+) diff --git a/src/cocoa_window.m b/src/cocoa_window.m index 641b4d4c..4acebd1a 100644 --- a/src/cocoa_window.m +++ b/src/cocoa_window.m @@ -858,6 +858,14 @@ static GLboolean createWindow(_GLFWwindow* window, [window->ns.object disableCursorRects]; [window->ns.object center]; + if (window->cursorMode != GLFW_CURSOR_DISABLED) + { + const NSRect contentRect = [window->ns.view frame]; + const NSPoint p = [window->ns.object mouseLocationOutsideOfEventStream]; + window->cursorPosX = p.x; + window->cursorPosY = contentRect.size.height - p.y; + } + #if MAC_OS_X_VERSION_MAX_ALLOWED >= 1070 if ([window->ns.object respondsToSelector:@selector(setRestorable:)]) [window->ns.object setRestorable:NO]; @@ -960,6 +968,17 @@ void _glfwPlatformSetWindowPos(_GLFWwindow* window, int x, int y) const NSRect dummyRect = NSMakeRect(x, transformY(y + contentRect.size.height), 0, 0); const NSRect frameRect = [window->ns.object frameRectForContentRect:dummyRect]; [window->ns.object setFrameOrigin:frameRect.origin]; + + if (window->cursorMode != GLFW_CURSOR_DISABLED) + { + const NSPoint p = [window->ns.object mouseLocationOutsideOfEventStream]; + // TODO: This should enqueue an event that will result in cursor position callback being called + // during the next glfwPollEvents() + // (But can't call _glfwInputCursorMotion directly here because that'd result in callbacks + // being called outside of glfwPollEvents() timeframe) + window->cursorPosX = p.x; + window->cursorPosY = contentRect.size.height - p.y; + } } void _glfwPlatformGetWindowSize(_GLFWwindow* window, int* width, int* height)