diff options
-rw-r--r-- | osdep/macosx_application.m | 5 | ||||
-rw-r--r-- | osdep/macosx_events.m | 20 | ||||
-rw-r--r-- | osdep/macosx_events_objc.h | 2 |
3 files changed, 27 insertions, 0 deletions
diff --git a/osdep/macosx_application.m b/osdep/macosx_application.m index 702292908a..0379491d79 100644 --- a/osdep/macosx_application.m +++ b/osdep/macosx_application.m @@ -139,6 +139,11 @@ static void terminate_cocoa_application(void) andEventID:kAEQuitApplication]; } +- (void)applicationWillBecomeActive:(NSNotification *)notification +{ + [_eventsResponder setHighestPriotityMediaKeysTap]; +} + - (void)handleQuitEvent:(NSAppleEventDescriptor *)event withReplyEvent:(NSAppleEventDescriptor *)replyEvent { diff --git a/osdep/macosx_events.m b/osdep/macosx_events.m index 25c9948a98..e94718c3d1 100644 --- a/osdep/macosx_events.m +++ b/osdep/macosx_events.m @@ -372,6 +372,25 @@ void cocoa_set_mpv_handle(struct mpv_handle *ctx) CGEventTapEnable(self->_mk_tap_port, true); } +- (void)setHighestPriotityMediaKeysTap +{ + if (self->_mk_tap_port == nil) + return; + + CGEventTapInformation *taps = ta_alloc_size(nil, sizeof(CGEventTapInformation)); + uint32_t numTaps = 0; + CGError err = CGGetEventTapList(1, taps, &numTaps); + + if (err == kCGErrorSuccess && numTaps > 0) { + pid_t processID = [NSProcessInfo processInfo].processIdentifier; + if (taps[0].tappingProcess != processID) { + [self stopMediaKeys]; + [self startMediaKeys]; + } + } + talloc_free(taps); +} + - (void)startMediaKeys { dispatch_async(dispatch_get_main_queue(), ^{ @@ -396,6 +415,7 @@ void cocoa_set_mpv_handle(struct mpv_handle *ctx) { dispatch_async(dispatch_get_main_queue(), ^{ NSMachPort *port = (NSMachPort *)self->_mk_tap_port; + CGEventTapEnable(self->_mk_tap_port, false); [[NSRunLoop mainRunLoop] removePort:port forMode:NSRunLoopCommonModes]; CFRelease(self->_mk_tap_port); self->_mk_tap_port = nil; diff --git a/osdep/macosx_events_objc.h b/osdep/macosx_events_objc.h index 36de66dc88..f3210f2580 100644 --- a/osdep/macosx_events_objc.h +++ b/osdep/macosx_events_objc.h @@ -40,6 +40,8 @@ struct input_ctx; - (void)putKey:(int)keycode; +- (void)setHighestPriotityMediaKeysTap; + - (void)handleFilesArray:(NSArray *)files; - (bool)processKeyEvent:(NSEvent *)event; |