Commit 80e4922b authored by Sergey Tikhomirov's avatar Sergey Tikhomirov
Browse files

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.
parent c23fca63
......@@ -352,9 +352,6 @@ void _glfwPlatformTerminate(void)
_glfw.ns.listener = nil;
}
[_glfw.ns.cursor release];
_glfw.ns.cursor = nil;
free(_glfw.ns.clipboardString);
_glfwTerminateNSGL();
......
......@@ -102,7 +102,6 @@ typedef struct _GLFWlibraryNS
CGEventSourceRef eventSource;
id delegate;
id autoreleasePool;
id cursor;
TISInputSourceRef inputSource;
IOHIDManagerRef hidManager;
id unicodeData;
......
......@@ -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);
}
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment