From 5f265d5930588a4a1b065e18a84b25a15b4b1d66 Mon Sep 17 00:00:00 2001 From: Stefano Pigozzi Date: Sun, 21 Jul 2013 10:33:18 +0200 Subject: cocoa_common: handle keyboard modifiers for mouse events --- osdep/macosx_application_objc.h | 2 ++ osdep/macosx_events.h | 1 + osdep/macosx_events.m | 34 +++++++++++++++++++++------------- 3 files changed, 24 insertions(+), 13 deletions(-) (limited to 'osdep') diff --git a/osdep/macosx_application_objc.h b/osdep/macosx_application_objc.h index cfb3a072b7..5bd05f8d8f 100644 --- a/osdep/macosx_application_objc.h +++ b/osdep/macosx_application_objc.h @@ -35,6 +35,8 @@ struct cocoa_input_queue; - (void)startMediaKeys; - (void)restartMediaKeys; - (void)stopMediaKeys; +- (int)mapKeyModifiers:(int)cocoaModifiers; +- (int)keyModifierMask:(NSEvent *)event; @end @interface Application : NSApplication diff --git a/osdep/macosx_events.h b/osdep/macosx_events.h index b8162dc125..1adb2e809b 100644 --- a/osdep/macosx_events.h +++ b/osdep/macosx_events.h @@ -22,6 +22,7 @@ #include "core/input/keycodes.h" void cocoa_put_key(int keycode); +void cocoa_put_key_with_modifiers(int keycode, int modifiers); void cocoa_check_events(void); void cocoa_init_apple_remote(void); diff --git a/osdep/macosx_events.m b/osdep/macosx_events.m index 09578b0dc7..88a99e798d 100644 --- a/osdep/macosx_events.m +++ b/osdep/macosx_events.m @@ -37,16 +37,14 @@ #define NSLeftAlternateKeyMask (0x000020 | NSAlternateKeyMask) #define NSRightAlternateKeyMask (0x000040 | NSAlternateKeyMask) -static bool LeftAltPressed(NSEvent *event) +static bool LeftAltPressed(int mask) { - return ([event modifierFlags] & NSLeftAlternateKeyMask) == - NSLeftAlternateKeyMask; + return (mask & NSLeftAlternateKeyMask) == NSLeftAlternateKeyMask; } -static bool RightAltPressed(NSEvent *event) +static bool RightAltPressed(int mask) { - return ([event modifierFlags] & NSRightAlternateKeyMask) == - NSRightAlternateKeyMask; + return (mask & NSRightAlternateKeyMask) == NSRightAlternateKeyMask; } static const struct mp_keymap keymap[] = { @@ -174,6 +172,12 @@ void cocoa_put_key(int keycode) [mpv_shared_app().iqueue push:keycode]; } +void cocoa_put_key_with_modifiers(int keycode, int modifiers) +{ + keycode |= [mpv_shared_app().eventsResponder mapKeyModifiers:modifiers]; + cocoa_put_key(keycode); +} + @implementation EventsResponder { CFMachPortRef _mk_tap_port; HIDRemote *_remote; @@ -262,7 +266,7 @@ void cocoa_put_key(int keycode) { NSString *chars; - if (RightAltPressed(event)) + if (RightAltPressed([event modifierFlags])) chars = [event characters]; else chars = [event charactersIgnoringModifiers]; @@ -308,21 +312,25 @@ void cocoa_put_key(int keycode) [self handleKey:buttonCode withMask:0 andMapping:keymap]; } -- (int)keyModifierMask:(NSEvent *)event +- (int)mapKeyModifiers:(int)cocoaModifiers { int mask = 0; - if ([event modifierFlags] & NSShiftKeyMask) + if (cocoaModifiers & NSShiftKeyMask) mask |= MP_KEY_MODIFIER_SHIFT; - if ([event modifierFlags] & NSControlKeyMask) + if (cocoaModifiers & NSControlKeyMask) mask |= MP_KEY_MODIFIER_CTRL; - if (LeftAltPressed(event)) + if (LeftAltPressed(cocoaModifiers)) mask |= MP_KEY_MODIFIER_ALT; - if ([event modifierFlags] & NSCommandKeyMask) + if (cocoaModifiers & NSCommandKeyMask) mask |= MP_KEY_MODIFIER_META; - return mask; } +- (int)keyModifierMask:(NSEvent *)event +{ + return [self mapKeyModifiers:[event modifierFlags]]; +} + -(BOOL)handleKey:(int)key withMask:(int)mask andMapping:(NSDictionary *)mapping { int mpkey = [mapping[@(key)] intValue]; -- cgit v1.2.3