From 533e151febe798e0449e26f8544194a66ec6e92b Mon Sep 17 00:00:00 2001 From: Rodger Combs Date: Mon, 10 Aug 2015 15:14:39 -0500 Subject: cocoa: hide cursor using a blank image instead of a system-wide API Fixes #503 --- video/out/cocoa_common.m | 18 ++++++++++++++---- 1 file changed, 14 insertions(+), 4 deletions(-) diff --git a/video/out/cocoa_common.m b/video/out/cocoa_common.m index 234e032ab1..f16f7aef0d 100644 --- a/video/out/cocoa_common.m +++ b/video/out/cocoa_common.m @@ -18,9 +18,9 @@ */ #import -#import // for CGDisplayHideCursor #import #import +#import #include #import "cocoa_common.h" @@ -104,6 +104,8 @@ struct vo_cocoa_state { bool vo_ready; // the VO is in a state in which it can // render frames int frame_w, frame_h; // dimensions of the frame rendered + + NSCursor *blankCursor; }; static void run_on_main_thread(struct vo *vo, void(^block)(void)) @@ -254,6 +256,11 @@ int vo_cocoa_init(struct vo *vo) .log = mp_log_new(s, vo->log, "cocoa"), .embedded = vo->opts->WinID >= 0, }; + if (!s->embedded) { + NSImage* blankImage = [[NSImage alloc] initWithSize:NSMakeSize(1, 1)]; + s->blankCursor = [[NSCursor alloc] initWithImage:blankImage hotSpot:NSZeroPoint]; + [blankImage release]; + } pthread_mutex_init(&s->lock, NULL); pthread_cond_init(&s->wakeup, NULL); vo->cocoa = s; @@ -271,9 +278,9 @@ static int vo_cocoa_set_cursor_visibility(struct vo *vo, bool *visible) MpvEventsView *v = (MpvEventsView *) s->view; if (*visible) { - CGDisplayShowCursor(kCGDirectMainDisplay); - } else if ([v canHideCursor]) { - CGDisplayHideCursor(kCGDirectMainDisplay); + [[NSCursor arrowCursor] set]; + } else if ([v canHideCursor] && s->blankCursor) { + [s->blankCursor set]; } else { *visible = true; } @@ -310,6 +317,9 @@ void vo_cocoa_uninit(struct vo *vo) if (s->window) [s->window release]; + if (!s->embedded) + [s->blankCursor release]; + pthread_cond_destroy(&s->wakeup); pthread_mutex_destroy(&s->lock); talloc_free(s); -- cgit v1.2.3