From a32db637b5c66c0304147caadf02d7b28083bcee Mon Sep 17 00:00:00 2001 From: der richter Date: Sat, 30 Nov 2019 16:08:32 +0100 Subject: mac: replace old event tap for media key support with MediaPlayer the old event tap has several problems, like no proper priority support or having to set accessibility permissions for mpv or the terminal. it is now replaced by the new MediaPlayer which has proper priority support and isn't as greedy as previously. this only includes Media Key support and not any of the other features included in the MediaPlayer framework, like proper Now Playing data (only set dummy data for now). this is only available on macOS 10.12.2 and higher. also removes some unnecessary redefines. Fixes #6389 --- osdep/macosx_application.m | 15 ++++++++++++++- 1 file changed, 14 insertions(+), 1 deletion(-) (limited to 'osdep/macosx_application.m') diff --git a/osdep/macosx_application.m b/osdep/macosx_application.m index 8b3fac95a4..3d420a3152 100644 --- a/osdep/macosx_application.m +++ b/osdep/macosx_application.m @@ -105,6 +105,7 @@ static void terminate_cocoa_application(void) @synthesize menuBar = _menu_bar; @synthesize openCount = _open_count; @synthesize cocoaCB = _cocoa_cb; +@synthesize remoteCommandCenter = _remoteCommandCenter; - (void)sendEvent:(NSEvent *)event { @@ -199,6 +200,11 @@ static const char macosx_icon[] = [_eventsResponder queueCommand:cmd]; } +- (void)handleMPKey:(int)key withMask:(int)mask +{ + [_eventsResponder handleMPKey:key withMask:mask]; +} + - (void)stopMPV:(char *)cmd { if (![_eventsResponder queueCommand:cmd]) @@ -216,7 +222,7 @@ static const char macosx_icon[] = - (void)applicationWillBecomeActive:(NSNotification *)notification { - [_eventsResponder setHighestPriotityMediaKeysTap]; + [_remoteCommandCenter makeCurrent]; } - (void)handleQuitEvent:(NSAppleEventDescriptor *)event @@ -293,6 +299,13 @@ static void init_cocoa_application(bool regular) [NSApp setDelegate:NSApp]; [NSApp setMenuBar:[[MenuBar alloc] init]]; +#if HAVE_MACOS_10_12_2_FEATURES + // 10.12.2 runtime availability check + if ([NSApp respondsToSelector:@selector(touchBar)]) { + [NSApp setRemoteCommandCenter:[[RemoteCommandCenter alloc] initWithApp:NSApp]]; + } +#endif + // Will be set to Regular from cocoa_common during UI creation so that we // don't create an icon when playing audio only files. [NSApp setActivationPolicy: regular ? -- cgit v1.2.3