summaryrefslogtreecommitdiffstats
path: root/osdep
diff options
context:
space:
mode:
authorStefano Pigozzi <stefano.pigozzi@gmail.com>2013-09-02 21:11:05 +0200
committerStefano Pigozzi <stefano.pigozzi@gmail.com>2013-09-02 21:11:05 +0200
commitadd7c2955df7a0c3ee2c0889193b21007113fc3e (patch)
treea962dae8664f9c402fcbabc76ca5e60446411b7e /osdep
parent39a69aeb890c2e0afc1daa73cfd19a13c6dcc1af (diff)
downloadmpv-add7c2955df7a0c3ee2c0889193b21007113fc3e.tar.bz2
mpv-add7c2955df7a0c3ee2c0889193b21007113fc3e.tar.xz
macosx_events: remove duplication
refactoring: extract method `handleMPKey:withMask:`
Diffstat (limited to 'osdep')
-rw-r--r--osdep/macosx_events.m62
1 files changed, 33 insertions, 29 deletions
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