mirror of https://github.com/mpv-player/mpv
cocoa: fix key equivalent dispatching
Prior to this commit we had a list of key modifiers and checked against that. Actually, the Cocoa framework has a built in way to do it and it involves calling performKeyEquivalent: on the menu instance. Fixes #946 cc @mpv-player/stable: this should apply with no conflicts
This commit is contained in:
parent
471dfba018
commit
c3d15b50b4
|
@ -86,7 +86,12 @@ Application *mpv_shared_app(void)
|
||||||
|
|
||||||
[NSEvent addLocalMonitorForEventsMatchingMask:NSKeyDownMask|NSKeyUpMask
|
[NSEvent addLocalMonitorForEventsMatchingMask:NSKeyDownMask|NSKeyUpMask
|
||||||
handler:^(NSEvent *event) {
|
handler:^(NSEvent *event) {
|
||||||
return [self.eventsResponder handleKey:event];
|
BOOL equivalent = [[NSApp mainMenu] performKeyEquivalent:event];
|
||||||
|
if (equivalent) {
|
||||||
|
return (NSEvent *)nil;
|
||||||
|
} else {
|
||||||
|
return [self.eventsResponder handleKey:event];
|
||||||
|
}
|
||||||
}];
|
}];
|
||||||
|
|
||||||
NSAppleEventManager *em = [NSAppleEventManager sharedAppleEventManager];
|
NSAppleEventManager *em = [NSAppleEventManager sharedAppleEventManager];
|
||||||
|
|
|
@ -233,21 +233,6 @@ void cocoa_put_key_with_modifiers(int keycode, int modifiers)
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
- (NSArray *) keyEquivalents
|
|
||||||
{
|
|
||||||
return @[@"h", @"q", @"Q", @"0", @"1", @"2"];
|
|
||||||
}
|
|
||||||
|
|
||||||
- (BOOL)isAppKeyEquivalent:(NSString *)eq withEvent:(NSEvent *)event
|
|
||||||
{
|
|
||||||
if ([event modifierFlags] & NSCommandKeyMask)
|
|
||||||
for(NSString *c in [self keyEquivalents])
|
|
||||||
if ([eq isEqualToString:c])
|
|
||||||
return YES;
|
|
||||||
|
|
||||||
return NO;
|
|
||||||
}
|
|
||||||
|
|
||||||
- (BOOL)handleMediaKey:(NSEvent *)event
|
- (BOOL)handleMediaKey:(NSEvent *)event
|
||||||
{
|
{
|
||||||
NSDictionary *keymapd = @{
|
NSDictionary *keymapd = @{
|
||||||
|
@ -349,13 +334,8 @@ void cocoa_put_key_with_modifiers(int keycode, int modifiers)
|
||||||
|
|
||||||
int key = convert_key([event keyCode], *[chars UTF8String]);
|
int key = convert_key([event keyCode], *[chars UTF8String]);
|
||||||
|
|
||||||
if (key > -1) {
|
if (key > -1)
|
||||||
if ([self isAppKeyEquivalent:chars withEvent:event])
|
|
||||||
// propagate the event in case this is a menu key equivalent
|
|
||||||
return event;
|
|
||||||
|
|
||||||
[self handleMPKey:key withMask:[self keyModifierMask:event]];
|
[self handleMPKey:key withMask:[self keyModifierMask:event]];
|
||||||
}
|
|
||||||
|
|
||||||
return nil;
|
return nil;
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in New Issue