From add7c2955df7a0c3ee2c0889193b21007113fc3e Mon Sep 17 00:00:00 2001 From: Stefano Pigozzi Date: Mon, 2 Sep 2013 21:11:05 +0200 Subject: macosx_events: remove duplication refactoring: extract method `handleMPKey:withMask:` --- osdep/macosx_events.m | 62 +++++++++++++++++++++++++++------------------------ 1 file changed, 33 insertions(+), 29 deletions(-) (limited to 'osdep/macosx_events.m') diff --git a/osdep/macosx_events.m b/osdep/macosx_events.m index 38d723c204..0756de1607 100644 --- a/osdep/macosx_events.m +++ b/osdep/macosx_events.m @@ -253,31 +253,6 @@ void cocoa_put_key_with_modifiers(int keycode, int modifiers) andMapping:keymap]; } -- (NSEvent*)handleKey:(NSEvent *)event -{ - if ([event isARepeat]) return nil; - - NSString *chars; - - if (RightAltPressed([event modifierFlags])) - chars = [event characters]; - else - chars = [event charactersIgnoringModifiers]; - - int key = convert_key([event keyCode], *[chars UTF8String]); - - if (key > -1) { - if ([self isAppKeyEquivalent:chars withEvent:event]) - // propagate the event in case this is a menu key equivalent - return event; - - key |= [self keyModifierMask:event]; - cocoa_put_key(key); - } - - return nil; -} - - (void)hidRemote:(HIDRemote *)remote eventWithButton:(HIDRemoteButtonCode)buttonCode isPressed:(BOOL)isPressed @@ -334,14 +309,43 @@ void cocoa_put_key_with_modifiers(int keycode, int modifiers) [self mapTypeModifiers:[event type]]; } --(BOOL)handleKey:(int)key withMask:(int)mask andMapping:(NSDictionary *)mapping +-(BOOL)handleMPKey:(int)key withMask:(int)mask { - int mpkey = [mapping[@(key)] intValue]; - if (mpkey > 0) { - cocoa_put_key(mpkey | mask); + if (key > 0) { + cocoa_put_key(key | mask); return YES; } else { return NO; } } + +-(BOOL)handleKey:(int)key withMask:(int)mask andMapping:(NSDictionary *)mapping +{ + int mpkey = [mapping[@(key)] intValue]; + return [self handleMPKey:mpkey withMask:mpkey]; +} + +- (NSEvent*)handleKey:(NSEvent *)event +{ + if ([event isARepeat]) return nil; + + NSString *chars; + + if (RightAltPressed([event modifierFlags])) + chars = [event characters]; + else + chars = [event charactersIgnoringModifiers]; + + int key = convert_key([event keyCode], *[chars UTF8String]); + + 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]]; + } + + return nil; +} @end -- cgit v1.2.3