瀏覽代碼

Cocoa: Hide cursor instead of using blank image

When cursor isn't in normal mode and should be hidden, use [NSCursor hide]
method instead of setting it to blank image. This should prevent
situations when hidden cursor becomes visible after system notification
was shown.

Fixes #971.
Closes #1028.
Sergey Tikhomirov 8 年之前
父節點
當前提交
80e4922b5e
共有 3 個文件被更改,包括 23 次插入19 次删除
  1. 0 3
      src/cocoa_init.m
  2. 0 1
      src/cocoa_platform.h
  3. 23 15
      src/cocoa_window.m

+ 0 - 3
src/cocoa_init.m

@@ -352,9 +352,6 @@ void _glfwPlatformTerminate(void)
         _glfw.ns.listener = nil;
     }
 
-    [_glfw.ns.cursor release];
-    _glfw.ns.cursor = nil;
-
     free(_glfw.ns.clipboardString);
 
     _glfwTerminateNSGL();

+ 0 - 1
src/cocoa_platform.h

@@ -102,7 +102,6 @@ typedef struct _GLFWlibraryNS
     CGEventSourceRef    eventSource;
     id                  delegate;
     id                  autoreleasePool;
-    id                  cursor;
     TISInputSourceRef   inputSource;
     IOHIDManagerRef     hidManager;
     id                  unicodeData;

+ 23 - 15
src/cocoa_window.m

@@ -88,19 +88,35 @@ static GLFWbool cursorInClientArea(_GLFWwindow* window)
     return [window->ns.view mouse:pos inRect:[window->ns.view frame]];
 }
 
+// Updates cursor visibility
+//
+static void setCursorVisibility(_GLFWwindow* window, BOOL makeVisible)
+{
+    static BOOL isCursorVisible = YES;
+
+    if (makeVisible && !isCursorVisible)
+        [NSCursor unhide];
+    else if (!makeVisible && isCursorVisible)
+        [NSCursor hide];
+
+    isCursorVisible = makeVisible;
+}
+
 // Updates the cursor image according to its cursor mode
 //
 static void updateCursorImage(_GLFWwindow* window)
 {
     if (window->cursorMode == GLFW_CURSOR_NORMAL)
     {
+        setCursorVisibility(window, YES);
+
         if (window->cursor)
             [(NSCursor*) window->cursor->ns.object set];
         else
             [[NSCursor arrowCursor] set];
     }
     else
-        [(NSCursor*) _glfw.ns.cursor set];
+        setCursorVisibility(window, NO);
 }
 
 // Transforms the specified y-coordinate between the CG display and NS screen
@@ -363,20 +379,6 @@ static const NSRange kEmptyRange = { NSNotFound, 0 };
 
 @implementation GLFWContentView
 
-+ (void)initialize
-{
-    if (self == [GLFWContentView class])
-    {
-        if (_glfw.ns.cursor == nil)
-        {
-            NSImage* data = [[NSImage alloc] initWithSize:NSMakeSize(16, 16)];
-            _glfw.ns.cursor = [[NSCursor alloc] initWithImage:data
-                                                      hotSpot:NSZeroPoint];
-            [data release];
-        }
-    }
-}
-
 - (id)initWithGlfwWindow:(_GLFWwindow *)initWindow
 {
     self = [super init];
@@ -522,11 +524,17 @@ static const NSRange kEmptyRange = { NSNotFound, 0 };
 
 - (void)mouseExited:(NSEvent *)event
 {
+    if (window->cursorMode == GLFW_CURSOR_HIDDEN)
+        setCursorVisibility(window, YES);
+
     _glfwInputCursorEnter(window, GLFW_FALSE);
 }
 
 - (void)mouseEntered:(NSEvent *)event
 {
+    if (window->cursorMode == GLFW_CURSOR_HIDDEN)
+        setCursorVisibility(window, NO);
+
     _glfwInputCursorEnter(window, GLFW_TRUE);
 }