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:
Stefano Pigozzi 2013-06-05 21:39:59 +02:00
parent b9607b63a4
commit 6619905902
1 changed files with 12 additions and 10 deletions

View File

@ -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