summaryrefslogtreecommitdiffstats
path: root/osdep
diff options
context:
space:
mode:
authorAkemi <der.richter@gmx.de>2017-09-05 23:29:06 +0200
committerAkemi <der.richter@gmx.de>2017-09-07 20:42:26 +0200
commit9cb7f87b862883f5858315ff641d86703972e8ca (patch)
tree8f2352c16bc1ba595fffc6109455683819821f40 /osdep
parent5771f7abf48282fe847137845f17eec5a5af245f (diff)
downloadmpv-9cb7f87b862883f5858315ff641d86703972e8ca.tar.bz2
mpv-9cb7f87b862883f5858315ff641d86703972e8ca.tar.xz
osx: fix media keys input when other Apps steal the priority
other Apps do the same as mpv and tap into the global event chain. events that are handled are not being propagated down the event chain. that can lead to mpv not getting any media key events anymore when they are held back by other Apps. we will just move mpv back to the top of the event list when mpv is refocused and is not at the top of the list any more. Fixes #4834
Diffstat (limited to 'osdep')
-rw-r--r--osdep/macosx_application.m5
-rw-r--r--osdep/macosx_events.m20
-rw-r--r--osdep/macosx_events_objc.h2
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;