From b8f2811f8d180d4c2a39aabc046440c900652bb4 Mon Sep 17 00:00:00 2001 From: der richter Date: Sat, 15 Feb 2020 16:13:37 +0100 Subject: mac: fix media key support for libmpv users this basically moves the remote command center to our mac events instead of keeping it our Application, which is only available when started from mpv itself. also make it independent of the NSApplication. this also prevents a runtime crash --- osdep/macosx_events.m | 23 ++++++++++++++++------- 1 file changed, 16 insertions(+), 7 deletions(-) (limited to 'osdep/macosx_events.m') diff --git a/osdep/macosx_events.m b/osdep/macosx_events.m index 3f40e41f6c..e2ae7aa162 100644 --- a/osdep/macosx_events.m +++ b/osdep/macosx_events.m @@ -161,6 +161,8 @@ void cocoa_set_mpv_handle(struct mpv_handle *ctx) @implementation EventsResponder +@synthesize remoteCommandCenter = _remoteCommandCenter; + + (EventsResponder *)sharedInstance { static EventsResponder *responder = nil; @@ -272,14 +274,18 @@ void cocoa_set_mpv_handle(struct mpv_handle *ctx) [NSApp processEvent:event]; } + if (_remoteCommandCenter) { + [_remoteCommandCenter processEvent:event]; + } + switch (event->event_id) { case MPV_EVENT_SHUTDOWN: { - #if HAVE_MACOS_COCOA_CB +#if HAVE_MACOS_COCOA_CB if ([(Application *)NSApp cocoaCB].isShuttingDown) { _ctx = nil; return; } - #endif +#endif mpv_destroy(_ctx); _ctx = nil; break; @@ -289,16 +295,19 @@ void cocoa_set_mpv_handle(struct mpv_handle *ctx) - (void)startMediaKeys { - if ([(Application *)NSApp remoteCommandCenter]) { - [[(Application *)NSApp remoteCommandCenter] start]; +#if HAVE_MACOS_MEDIA_PLAYER + // 10.12.2 runtime availability check + if (_remoteCommandCenter == nil && [NSApp respondsToSelector:@selector(touchBar)]) { + _remoteCommandCenter = [[RemoteCommandCenter alloc] init]; } +#endif + + [_remoteCommandCenter start]; } - (void)stopMediaKeys { - if ([(Application *)NSApp remoteCommandCenter]) { - [[(Application *)NSApp remoteCommandCenter] stop]; - } + [_remoteCommandCenter stop]; } - (int)mapKeyModifiers:(int)cocoaModifiers -- cgit v1.2.3