diff options
author | Stefano Pigozzi <stefano.pigozzi@gmail.com> | 2013-06-05 21:39:59 +0200 |
---|---|---|
committer | Stefano Pigozzi <stefano.pigozzi@gmail.com> | 2013-06-05 21:39:59 +0200 |
commit | 66199059024dc014a658d8fcc83f4c432a74b06f (patch) | |
tree | c9fc286e740a4f680ec02faec293dbe65daf0ac6 /osdep | |
parent | b9607b63a45e041ee1cc317a37a737b256c79d41 (diff) | |
download | mpv-66199059024dc014a658d8fcc83f4c432a74b06f.tar.bz2 mpv-66199059024dc014a658d8fcc83f4c432a74b06f.tar.xz |
macosx_events: DRY up key lookup over dictionary
Two methods duplicated very similar behaviour. Extract method with the common
behaviour.
Diffstat (limited to 'osdep')
-rw-r--r-- | osdep/macosx_events.m | 22 |
1 files changed, 12 insertions, 10 deletions
diff --git a/osdep/macosx_events.m b/osdep/macosx_events.m index 661ef638ca..aff83a866f 100644 --- a/osdep/macosx_events.m +++ b/osdep/macosx_events.m @@ -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 |