hide cursor on OSX

This commit is contained in:
2019-03-10 00:43:33 +01:00
parent 65872cf253
commit 5cd80f41fa
3 changed files with 23 additions and 0 deletions

View File

@@ -124,6 +124,11 @@ std::mutex task_mutex;
self = [super initWithFrame:frameRect pixelFormat:pf];
[self setPixelFormat:pf];
[self setOpenGLContext:context];
NSTrackingArea* trackingArea = [[NSTrackingArea alloc] initWithRect:frameRect
options: (NSTrackingMouseEnteredAndExited | NSTrackingMouseMoved | NSTrackingActiveInKeyWindow )
owner:self userInfo:nil];
[self addTrackingArea:trackingArea];
return self;
}
- (void)prepareOpenGL
@@ -374,6 +379,17 @@ static CVReturn MyDisplayLinkCallback(CVDisplayLinkRef displayLink, const CVTime
App::I.mouse_move(mouseLoc.x, App::I.height - mouseLoc.y - 1, p, kEventSource::Mouse, 0);
});
}
-(void)mouseExited:(NSEvent *)event
{
self->cursor_visible = CGCursorIsVisible();
if (!self->cursor_visible)
[NSCursor unhide];
}
-(void)mouseEntered:(NSEvent *)event
{
if (!self->cursor_visible)
[NSCursor hide];
}
- (void)scrollWheel:(NSEvent *)theEvent
{
auto mouseLoc = [self convertPoint:[theEvent locationInWindow] fromView:nil];

View File

@@ -16,6 +16,7 @@
NSOpenGLContext* glctx;
_CGLContextObject* cgl;
bool gl_ready;
bool cursor_visible;
@public NSString* file2open;
}
- (void)close;

View File

@@ -42,6 +42,9 @@ void App::show_cursor()
{
#ifdef _WIN32
win32_show_cursor(true);
#elif __OSX__
if (!CGCursorIsVisible())
[NSCursor unhide];
#endif
}
@@ -49,6 +52,9 @@ void App::hide_cursor()
{
#ifdef _WIN32
win32_show_cursor(false);
#elif __OSX__
if (CGCursorIsVisible())
[NSCursor hide];
#endif
}