summaryrefslogtreecommitdiffstats
path: root/video
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 /video
parent03fd2fe61c71ae8ebfca3db246694ae293ce7c30 (diff)
downloadmpv-5f265d5930588a4a1b065e18a84b25a15b4b1d66.tar.bz2
mpv-5f265d5930588a4a1b065e18a84b25a15b4b1d66.tar.xz
cocoa_common: handle keyboard modifiers for mouse events
Diffstat (limited to 'video')
-rw-r--r--video/out/cocoa_common.m98
1 files changed, 51 insertions, 47 deletions
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