From 1f148f2bd6a57f4b64cb6d82d53c30599646b379 Mon Sep 17 00:00:00 2001 From: Noel Cower Date: Tue, 16 Apr 2013 16:35:14 -0600 Subject: [PATCH] Keep cursor centered in window while captured. Previously, cmd-tabbing out would result in the cursor position maybe ending up outside the window, so if one cmd-tabbed back in with the cursor still outside, any click would go outside the window and cause it to lose focus. Not really a good thing. So, this is a bit of a hack, but it works. --- src/cocoa_window.m | 16 ++++++++++++++++ 1 file changed, 16 insertions(+) diff --git a/src/cocoa_window.m b/src/cocoa_window.m index 6e781723..76f0811d 100644 --- a/src/cocoa_window.m +++ b/src/cocoa_window.m @@ -48,6 +48,16 @@ @implementation GLFWWindowDelegate +static void resetMouseCursor(_GLFWwindow *window) +{ + if (window->cursorMode == GLFW_CURSOR_CAPTURED) + { + int width, height; + _glfwPlatformGetWindowSize(window, &width, &height); + _glfwPlatformSetCursorPos(window, width / 2, height / 2); + } +} + - (id)initWithGlfwWindow:(_GLFWwindow *)initWindow { self = [super init]; @@ -70,6 +80,8 @@ int width, height; _glfwPlatformGetWindowSize(window, &width, &height); _glfwInputWindowSize(window, width, height); + + resetMouseCursor(window); } - (void)windowDidMove:(NSNotification *)notification @@ -79,6 +91,8 @@ int x, y; _glfwPlatformGetWindowPos(window, &x, &y); _glfwInputWindowPos(window, x, y); + + resetMouseCursor(window); } - (void)windowDidMiniaturize:(NSNotification *)notification @@ -94,6 +108,8 @@ - (void)windowDidBecomeKey:(NSNotification *)notification { _glfwInputWindowFocus(window, GL_TRUE); + + resetMouseCursor(window); } - (void)windowDidResignKey:(NSNotification *)notification