summaryrefslogtreecommitdiffstats
path: root/osdep/macosx_events.m
diff options
context:
space:
mode:
authorder richter <der.richter@gmx.de>2020-02-15 16:13:37 +0100
committerder richter <der.richter@gmx.de>2020-02-22 13:56:31 +0100
commitb8f2811f8d180d4c2a39aabc046440c900652bb4 (patch)
tree6be8c67b9a0a1c5a172f561ceab389e55eb19791 /osdep/macosx_events.m
parentc1d744328e737fe80ecfdc0cbb6260d7699f4328 (diff)
downloadmpv-b8f2811f8d180d4c2a39aabc046440c900652bb4.tar.bz2
mpv-b8f2811f8d180d4c2a39aabc046440c900652bb4.tar.xz
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
Diffstat (limited to 'osdep/macosx_events.m')
-rw-r--r--osdep/macosx_events.m23
1 files changed, 16 insertions, 7 deletions
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