mirror of
https://github.com/glfw/glfw.git
synced 2025-06-14 11:42:16 +00:00
Fix cursor hiding on OS X.
There's probably still an oddity in here to do with having more than one window's cursor disabled, but I don't think there's any sane fix for that. Anyway, the issue with cursors is actually pretty simple and mostly down to a misreading of what I thought disableCursorRects did. Calling it will stop the window from doing anything based on cursor rects, but it will not restore cursor state to whatever it was prior to the window using cursor rects. So, it's just letting you do your thing for as long as they're disabled. The fix for this is to simply not add a cursor rect when the window's cursor is hidden. So, I moved the cursorHidden flag from the library globals for OS X into the window flags, removed use of NSCursor show and hide because that's just trouble waiting to happen, and now the window only adds a cursor rect to hide the cursor if the cursor is supposed to be hidden. Because the cursor is moved into the window for when the cursor is disabled, it functions the same as hiding and showing the cursor. When the cursor is simply hidden, it also functions as expected.
This commit is contained in:
parent
5da6a903f9
commit
1f8ef64b30
@ -70,6 +70,7 @@ typedef struct _GLFWwindowNS
|
|||||||
id delegate;
|
id delegate;
|
||||||
id view;
|
id view;
|
||||||
unsigned int modifierFlags;
|
unsigned int modifierFlags;
|
||||||
|
GLboolean cursorHidden;
|
||||||
} _GLFWwindowNS;
|
} _GLFWwindowNS;
|
||||||
|
|
||||||
|
|
||||||
@ -108,8 +109,6 @@ typedef struct _GLFWlibraryNS
|
|||||||
id autoreleasePool;
|
id autoreleasePool;
|
||||||
id cursor;
|
id cursor;
|
||||||
|
|
||||||
GLboolean cursorHidden;
|
|
||||||
|
|
||||||
char* clipboardString;
|
char* clipboardString;
|
||||||
|
|
||||||
_GLFWjoy joysticks[GLFW_JOYSTICK_LAST + 1];
|
_GLFWjoy joysticks[GLFW_JOYSTICK_LAST + 1];
|
||||||
|
@ -604,7 +604,8 @@ static int translateKey(unsigned int key)
|
|||||||
- (void)resetCursorRects
|
- (void)resetCursorRects
|
||||||
{
|
{
|
||||||
[self discardCursorRects];
|
[self discardCursorRects];
|
||||||
[self addCursorRect:[self bounds] cursor:_glfw.ns.cursor];
|
if (window->ns.cursorHidden)
|
||||||
|
[self addCursorRect:[self bounds] cursor:_glfw.ns.cursor];
|
||||||
}
|
}
|
||||||
|
|
||||||
@end
|
@end
|
||||||
@ -821,7 +822,7 @@ static GLboolean createWindow(_GLFWwindow* window,
|
|||||||
[window->ns.object setContentView:window->ns.view];
|
[window->ns.object setContentView:window->ns.view];
|
||||||
[window->ns.object setDelegate:window->ns.delegate];
|
[window->ns.object setDelegate:window->ns.delegate];
|
||||||
[window->ns.object setAcceptsMouseMovedEvents:YES];
|
[window->ns.object setAcceptsMouseMovedEvents:YES];
|
||||||
[window->ns.object disableCursorRects];
|
[window->ns.object enableCursorRects];
|
||||||
[window->ns.object center];
|
[window->ns.object center];
|
||||||
|
|
||||||
if ([window->ns.object respondsToSelector:@selector(setRestorable:)])
|
if ([window->ns.object respondsToSelector:@selector(setRestorable:)])
|
||||||
@ -1022,37 +1023,17 @@ void _glfwPlatformSetCursorPos(_GLFWwindow* window, double x, double y)
|
|||||||
|
|
||||||
void _glfwPlatformSetCursorMode(_GLFWwindow* window, int mode)
|
void _glfwPlatformSetCursorMode(_GLFWwindow* window, int mode)
|
||||||
{
|
{
|
||||||
if (mode == GLFW_CURSOR_HIDDEN)
|
if (mode == GLFW_CURSOR_NORMAL)
|
||||||
{
|
window->ns.cursorHidden = GL_FALSE;
|
||||||
[window->ns.object enableCursorRects];
|
|
||||||
[window->ns.object invalidateCursorRectsForView:window->ns.view];
|
|
||||||
}
|
|
||||||
else
|
else
|
||||||
{
|
window->ns.cursorHidden = GL_TRUE;
|
||||||
[window->ns.object disableCursorRects];
|
|
||||||
[window->ns.object invalidateCursorRectsForView:window->ns.view];
|
[window->ns.object invalidateCursorRectsForView:window->ns.view];
|
||||||
}
|
|
||||||
|
|
||||||
if (mode == GLFW_CURSOR_DISABLED)
|
if (mode == GLFW_CURSOR_DISABLED)
|
||||||
{
|
|
||||||
CGAssociateMouseAndMouseCursorPosition(false);
|
CGAssociateMouseAndMouseCursorPosition(false);
|
||||||
|
|
||||||
if (!_glfw.ns.cursorHidden)
|
|
||||||
{
|
|
||||||
[NSCursor hide];
|
|
||||||
_glfw.ns.cursorHidden = GL_TRUE;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
else
|
else
|
||||||
{
|
|
||||||
CGAssociateMouseAndMouseCursorPosition(true);
|
CGAssociateMouseAndMouseCursorPosition(true);
|
||||||
|
|
||||||
if (_glfw.ns.cursorHidden)
|
|
||||||
{
|
|
||||||
[NSCursor unhide];
|
|
||||||
_glfw.ns.cursorHidden = GL_FALSE;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user