summaryrefslogtreecommitdiffstats
path: root/osdep
diff options
context:
space:
mode:
authorStefano Pigozzi <stefano.pigozzi@gmail.com>2013-07-21 10:33:18 +0200
committerStefano Pigozzi <stefano.pigozzi@gmail.com>2013-07-21 10:49:27 +0200
commit5f265d5930588a4a1b065e18a84b25a15b4b1d66 (patch)
tree52680907ce4e6d9521fc7062638d791fe3e96073 /osdep
parent03fd2fe61c71ae8ebfca3db246694ae293ce7c30 (diff)
downloadmpv-5f265d5930588a4a1b065e18a84b25a15b4b1d66.tar.bz2
mpv-5f265d5930588a4a1b065e18a84b25a15b4b1d66.tar.xz
cocoa_common: handle keyboard modifiers for mouse events
Diffstat (limited to 'osdep')
-rw-r--r--osdep/macosx_application_objc.h2
-rw-r--r--osdep/macosx_events.h1
-rw-r--r--osdep/macosx_events.m34
3 files changed, 24 insertions, 13 deletions
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];