mirror of https://github.com/mpv-player/mpv
macosx_events: DRY up key lookup over dictionary
Two methods duplicated very similar behaviour. Extract method with the common behaviour.
This commit is contained in:
parent
b9607b63a4
commit
6619905902
|
@ -232,13 +232,7 @@ void cocoa_put_key(int keycode)
|
|||
@(NX_KEYTYPE_FAST): @(MP_MK_NEXT),
|
||||
};
|
||||
|
||||
int mpkey = [keymap[@(key)] intValue];
|
||||
if (mpkey > 0) {
|
||||
cocoa_put_key(mpkey);
|
||||
return YES;
|
||||
} else {
|
||||
return NO;
|
||||
}
|
||||
return [self handleKey:key withMapping:keymap];
|
||||
}
|
||||
- (NSEvent*)handleKeyDown:(NSEvent *)event
|
||||
{
|
||||
|
@ -296,8 +290,16 @@ void cocoa_put_key(int keycode)
|
|||
@(kHIDRemoteButtonCodeDownHold): @(MP_AR_VDOWN_HOLD),
|
||||
};
|
||||
|
||||
int key = [keymap[@(buttonCode)] intValue];
|
||||
if (key > 0)
|
||||
cocoa_put_key(key);
|
||||
[self handleKey:buttonCode withMapping:keymap];
|
||||
}
|
||||
-(BOOL)handleKey:(int)key withMapping:(NSDictionary *)mapping
|
||||
{
|
||||
int mpkey = [mapping[@(key)] intValue];
|
||||
if (mpkey > 0) {
|
||||
cocoa_put_key(mpkey);
|
||||
return YES;
|
||||
} else {
|
||||
return NO;
|
||||
}
|
||||
}
|
||||
@end
|
||||
|
|
Loading…
Reference in New Issue