summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--osdep/macosx_application_objc.h2
-rw-r--r--osdep/macosx_events.h1
-rw-r--r--osdep/macosx_events.m34
-rw-r--r--video/out/cocoa_common.m98
4 files changed, 75 insertions, 60 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];
diff --git a/video/out/cocoa_common.m b/video/out/cocoa_common.m
index 4679eaf4a5..9eab694d0d 100644
--- a/video/out/cocoa_common.m
+++ b/video/out/cocoa_common.m
@@ -56,7 +56,6 @@
@property(nonatomic, assign) struct vo *videoOutput;
- (BOOL)containsMouseLocation;
- (void)recalcDraggableState;
-- (void)mouseEvent:(NSEvent *)theEvent;
@property(nonatomic, assign, getter=hasMouseDown) BOOL mouseDown;
@end
@@ -65,6 +64,10 @@
- (BOOL)hasMenubar;
@end
+@interface NSEvent (mpvadditions)
+- (int)mpvButtonNumber;
+@end
+
struct vo_cocoa_state {
GLMPlayerWindow *window;
GLMPlayerOpenGLView *view;
@@ -888,75 +891,64 @@ int vo_cocoa_cgl_color_size(struct vo *vo)
- (void)mouseMoved:(NSEvent *)event { [self signalMouseMovement:event]; }
- (void)mouseDragged:(NSEvent *)event { [self signalMouseMovement:event]; }
-- (void)mouseDown:(NSEvent *)evt { [self mouseEvent:evt]; }
-- (void)mouseUp:(NSEvent *)evt { [self mouseEvent:evt]; }
-- (void)rightMouseDown:(NSEvent *)evt { [self mouseEvent:evt]; }
-- (void)rightMouseUp:(NSEvent *)evt { [self mouseEvent:evt]; }
-- (void)otherMouseDown:(NSEvent *)evt { [self mouseEvent:evt]; }
-- (void)otherMouseUp:(NSEvent *)evt { [self mouseEvent:evt]; }
+- (void)mouseDown:(NSEvent *)evt { [self mouseDownEvent:evt]; }
+- (void)mouseUp:(NSEvent *)evt { [self mouseUpEvent:evt]; }
+- (void)rightMouseDown:(NSEvent *)evt { [self mouseDownEvent:evt]; }
+- (void)rightMouseUp:(NSEvent *)evt { [self mouseUpEvent:evt]; }
+- (void)otherMouseDown:(NSEvent *)evt { [self mouseDownEvent:evt]; }
+- (void)otherMouseUp:(NSEvent *)evt { [self mouseUpEvent:evt]; }
-- (void)scrollWheel:(NSEvent *)theEvent
+- (void)scrollWheel:(NSEvent *)event
{
struct vo_cocoa_state *s = self.videoOutput->cocoa;
CGFloat delta;
// Use the dimention with the most delta as the scrolling one
- if (FFABS([theEvent deltaY]) > FFABS([theEvent deltaX])) {
- delta = [theEvent deltaY];
+ if (FFABS([event deltaY]) > FFABS([event deltaX])) {
+ delta = [event deltaY];
} else {
- delta = - [theEvent deltaX];
+ delta = - [event deltaX];
}
- if ([theEvent hasPreciseScrollingDeltas]) {
+ if ([event hasPreciseScrollingDeltas]) {
s->accumulated_scroll += delta;
static const CGFloat threshold = 10;
while (s->accumulated_scroll >= threshold) {
s->accumulated_scroll -= threshold;
- cocoa_put_key(MP_MOUSE_BTN3);
+ cocoa_put_key_with_modifiers(MP_MOUSE_BTN3, [event modifierFlags]);
}
while (s->accumulated_scroll <= -threshold) {
s->accumulated_scroll += threshold;
- cocoa_put_key(MP_MOUSE_BTN4);
+ cocoa_put_key_with_modifiers(MP_MOUSE_BTN4, [event modifierFlags]);
}
} else {
if (delta > 0)
- cocoa_put_key(MP_MOUSE_BTN3);
+ cocoa_put_key_with_modifiers(MP_MOUSE_BTN3, [event modifierFlags]);
else
- cocoa_put_key(MP_MOUSE_BTN4);
- }
-}
-
-- (void)mouseEvent:(NSEvent *)theEvent
-{
- if ([theEvent buttonNumber] >= 0 && [theEvent buttonNumber] <= 9) {
- int buttonNumber = [theEvent buttonNumber];
- // Fix to mplayer defined button order: left, middle, right
- if (buttonNumber == 1) buttonNumber = 2;
- else if (buttonNumber == 2) buttonNumber = 1;
- switch ([theEvent type]) {
- case NSLeftMouseDown:
- case NSRightMouseDown:
- case NSOtherMouseDown:
- cocoa_put_key((MP_MOUSE_BTN0 + buttonNumber) | MP_KEY_STATE_DOWN);
- self.mouseDown = YES;
- // Looks like Cocoa doesn't create MouseUp events when we are
- // doing the second click in a double click. Put in the key_fifo
- // the key that would be put from the MouseUp handling code.
- if([theEvent clickCount] == 2) {
- cocoa_put_key((MP_MOUSE_BTN0 + buttonNumber) | MP_KEY_STATE_UP);
- self.mouseDown = NO;
- }
- break;
- case NSLeftMouseUp:
- case NSRightMouseUp:
- case NSOtherMouseUp:
- cocoa_put_key((MP_MOUSE_BTN0 + buttonNumber) | MP_KEY_STATE_UP);
- self.mouseDown = NO;
- break;
- }
+ cocoa_put_key_with_modifiers(MP_MOUSE_BTN4, [event modifierFlags]);
}
}
+- (void)mouseDownEvent:(NSEvent *)event
+{
+ [self putMouseEvent:event withState:MP_KEY_STATE_DOWN];
+
+ if ([event clickCount] > 1)
+ [self putMouseEvent:event withState:MP_KEY_STATE_UP];
+}
+
+- (void)mouseUpEvent:(NSEvent *)event
+{
+ [self putMouseEvent:event withState:MP_KEY_STATE_UP];
+}
+
+- (void)putMouseEvent:(NSEvent *)event withState:(int)state
+{
+ self.mouseDown = (state == MP_KEY_STATE_DOWN);
+ int mp_key = (MP_MOUSE_BTN0 + [event mpvButtonNumber]);
+ cocoa_put_key_with_modifiers(mp_key | state, [event modifierFlags]);
+}
+
- (void)drawRect: (NSRect)rect
{
struct vo *vo = [self videoOutput];
@@ -998,3 +990,15 @@ int vo_cocoa_cgl_color_size(struct vo *vo)
return [self isEqual: [NSScreen screens][0]];
}
@end
+
+@implementation NSEvent (mpvadditions)
+- (int)mpvButtonNumber
+{
+ int buttonNumber = [self buttonNumber];
+ switch (buttonNumber) {
+ case 1: return 2;
+ case 2: return 1;
+ default: return buttonNumber;
+ }
+}
+@end