diff --git a/src/cocoa_init.m b/src/cocoa_init.m index 2491e7eb..508de05f 100644 --- a/src/cocoa_init.m +++ b/src/cocoa_init.m @@ -124,6 +124,9 @@ void _glfwPlatformTerminate(void) [_glfw.ns.autoreleasePool release]; _glfw.ns.autoreleasePool = nil; + [_glfw.ns.cursor release]; + _glfw.ns.cursor = nil; + _glfwTerminateJoysticks(); _glfwTerminateContextAPI(); diff --git a/src/cocoa_platform.h b/src/cocoa_platform.h index da28c7f5..d98bddce 100644 --- a/src/cocoa_platform.h +++ b/src/cocoa_platform.h @@ -107,6 +107,7 @@ typedef struct _GLFWlibraryNS CGEventSourceRef eventSource; id delegate; id autoreleasePool; + id cursor; char* clipboardString; diff --git a/src/cocoa_window.m b/src/cocoa_window.m index c23db7c2..12cb384e 100644 --- a/src/cocoa_window.m +++ b/src/cocoa_window.m @@ -48,14 +48,11 @@ @implementation GLFWWindowDelegate -static void resetMouseCursor(_GLFWwindow *window) +static void centerCursor(_GLFWwindow *window) { - if (window->cursorMode == GLFW_CURSOR_CAPTURED) - { - int width, height; - _glfwPlatformGetWindowSize(window, &width, &height); - _glfwPlatformSetCursorPos(window, width / 2.0, height / 2.0); - } + int width, height; + _glfwPlatformGetWindowSize(window, &width, &height); + _glfwPlatformSetCursorPos(window, width / 2.0, height / 2.0); } - (id)initWithGlfwWindow:(_GLFWwindow *)initWindow @@ -82,7 +79,8 @@ static void resetMouseCursor(_GLFWwindow *window) _glfwInputWindowSize(window, width, height); _glfwInputWindowDamage(window); - resetMouseCursor(window); + if (window->cursorMode == GLFW_CURSOR_CAPTURED) + centerCursor(window); } - (void)windowDidMove:(NSNotification *)notification @@ -93,7 +91,8 @@ static void resetMouseCursor(_GLFWwindow *window) _glfwPlatformGetWindowPos(window, &x, &y); _glfwInputWindowPos(window, x, y); - resetMouseCursor(window); + if (window->cursorMode == GLFW_CURSOR_CAPTURED) + centerCursor(window); } - (void)windowDidMiniaturize:(NSNotification *)notification @@ -110,7 +109,8 @@ static void resetMouseCursor(_GLFWwindow *window) { _glfwInputWindowFocus(window, GL_TRUE); - resetMouseCursor(window); + if (window->cursorMode == GLFW_CURSOR_CAPTURED) + centerCursor(window); } - (void)windowDidResignKey:(NSNotification *)notification @@ -310,8 +310,6 @@ static int convertMacKeyCode(unsigned int macKeyCode) // Content view class for the GLFW window //------------------------------------------------------------------------ -static NSCursor *emptyCursor = nil; - @interface GLFWContentView : NSView { _GLFWwindow* window; @@ -328,9 +326,13 @@ static NSCursor *emptyCursor = nil; { if (self == [GLFWContentView class]) { - NSImage *emptyImage = [[NSImage alloc] initWithSize:NSMakeSize(1, 1)]; - emptyCursor = [[NSCursor alloc] initWithImage:emptyImage hotSpot:NSZeroPoint]; - [emptyImage release]; + if (_glfw.ns.cursor == nil) + { + NSImage* data = [[NSImage alloc] initWithSize:NSMakeSize(1, 1)]; + _glfw.ns.cursor = [[NSCursor alloc] initWithImage:data + hotSpot:NSZeroPoint]; + [data release]; + } } } @@ -509,7 +511,7 @@ static NSCursor *emptyCursor = nil; - (void)resetCursorRects { - [self addCursorRect:[self bounds] cursor:emptyCursor]; + [self addCursorRect:[self bounds] cursor:_glfw.ns.cursor]; } @end