mirror of
https://github.com/mpv-player/mpv
synced 2025-03-25 04:38:01 +00:00
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
This commit is contained in:
parent
5771f7abf4
commit
9cb7f87b86
@ -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
|
||||
{
|
||||
|
@ -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;
|
||||
|
@ -40,6 +40,8 @@ struct input_ctx;
|
||||
|
||||
- (void)putKey:(int)keycode;
|
||||
|
||||
- (void)setHighestPriotityMediaKeysTap;
|
||||
|
||||
- (void)handleFilesArray:(NSArray *)files;
|
||||
|
||||
- (bool)processKeyEvent:(NSEvent *)event;
|
||||
|
Loading…
Reference in New Issue
Block a user