From eb902efb0450b0080688fd210951049579d316b6 Mon Sep 17 00:00:00 2001 From: Stefano Pigozzi Date: Fri, 17 Oct 2014 19:15:17 +0200 Subject: cocoa: allow mouse events to bubble up with no-input-cursor Previously we didn't report events to the core, but still prevented the events to travel on the responder chain. --- DOCS/client_api_examples/cocoabasic.m | 1 + video/out/cocoa/events_view.m | 113 +++++++++++++++++++++++++++++----- video/out/cocoa/mpvadapter.h | 2 + video/out/cocoa_common.m | 23 ++++--- 4 files changed, 115 insertions(+), 24 deletions(-) diff --git a/DOCS/client_api_examples/cocoabasic.m b/DOCS/client_api_examples/cocoabasic.m index 8235f4b323..eed905cdc1 100644 --- a/DOCS/client_api_examples/cocoabasic.m +++ b/DOCS/client_api_examples/cocoabasic.m @@ -93,6 +93,7 @@ static void wakeup(void *); // for testing! check_error(mpv_set_option_string(mpv, "input-media-keys", "yes")); + check_error(mpv_set_option_string(mpv, "input-cursor", "no")); check_error(mpv_set_option_string(mpv, "input-vo-keyboard", "yes")); // request important errors diff --git a/video/out/cocoa/events_view.m b/video/out/cocoa/events_view.m index fd088cb5e6..c3e626b0fe 100644 --- a/video/out/cocoa/events_view.m +++ b/video/out/cocoa/events_view.m @@ -31,6 +31,8 @@ - (BOOL)hasDock:(NSScreen*)screen; - (BOOL)hasMenubar:(NSScreen*)screen; - (int)mpvButtonNumber:(NSEvent*)event; +- (void)mouseDownEvent:(NSEvent *)event; +- (void)mouseUpEvent:(NSEvent *)event; @end @implementation MpvEventsView @@ -94,7 +96,11 @@ - (void)updateTrackingAreas { - if (self.tracker) [self removeTrackingArea:self.tracker]; + if (self.tracker) + [self removeTrackingArea:self.tracker]; + + if (![self.adapter mouseEnabled]) + return; NSTrackingAreaOptions trackingOptions = NSTrackingEnabledDuringMouseDrag | @@ -127,9 +133,18 @@ return CGRectContainsPoint(clippedBounds, pt); } -- (BOOL)acceptsFirstMouse:(NSEvent *)theEvent { return YES; } -- (BOOL)acceptsFirstResponder { return YES; } -- (BOOL)becomeFirstResponder { return YES; } +- (BOOL)acceptsFirstMouse:(NSEvent *)theEvent +{ + return [self.adapter mouseEnabled]; +} +- (BOOL)acceptsFirstResponder { + return [self.adapter keyboardEnabled] || [self.adapter mouseEnabled]; +} + +- (BOOL)becomeFirstResponder { + return [self.adapter keyboardEnabled] || [self.adapter mouseEnabled]; +} + - (BOOL)resignFirstResponder { return YES; } - (void)keyDown:(NSEvent *)event { @@ -147,12 +162,16 @@ - (void)mouseEntered:(NSEvent *)event { - // do nothing! + [super mouseEntered:event]; } - (void)mouseExited:(NSEvent *)event { - [self.adapter putKey:MP_KEY_MOUSE_LEAVE withModifiers:0]; + if ([self.adapter mouseEnabled]) { + [self.adapter putKey:MP_KEY_MOUSE_LEAVE withModifiers:0]; + } else { + [super mouseExited:event]; + } } - (void)setFrameSize:(NSSize)size @@ -183,14 +202,75 @@ [self.adapter signalMouseMovement:p]; } -- (void)mouseMoved:(NSEvent *)event { [self signalMouseMovement:event]; } -- (void)mouseDragged:(NSEvent *)event { [self signalMouseMovement:event]; } -- (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)mouseMoved:(NSEvent *)event +{ + if ([self.adapter mouseEnabled]) { + [self signalMouseMovement:event]; + } else { + [super mouseMoved:event]; + } +} + +- (void)mouseDragged:(NSEvent *)event +{ + if ([self.adapter mouseEnabled]) { + [self signalMouseMovement:event]; + } else { + [super mouseDragged:event]; + } +} + +- (void)mouseDown:(NSEvent *)event +{ + if ([self.adapter mouseEnabled]) { + [self mouseDownEvent:event]; + } else { + [super mouseDown:event]; + } +} +- (void)mouseUp:(NSEvent *)event +{ + if ([self.adapter mouseEnabled]) { + [self mouseUpEvent:event]; + } else { + [super mouseUp:event]; + } +} +- (void)rightMouseDown:(NSEvent *)event +{ + if ([self.adapter mouseEnabled]) { + [self mouseDownEvent:event]; + } else { + [super rightMouseUp:event]; + } +} + +- (void)rightMouseUp:(NSEvent *)event +{ + if ([self.adapter mouseEnabled]) { + [self mouseUpEvent:event]; + } else { + [super rightMouseUp:event]; + } +} + +- (void)otherMouseDown:(NSEvent *)event +{ + if ([self.adapter mouseEnabled]) { + [self mouseDownEvent:event]; + } else { + [super otherMouseDown:event]; + } +} + +- (void)otherMouseUp:(NSEvent *)event +{ + if ([self.adapter mouseEnabled]) { + [self mouseUpEvent:event]; + } else { + [super otherMouseUp:event]; + } +} - (void)preciseScroll:(NSEvent *)event { @@ -210,6 +290,11 @@ - (void)scrollWheel:(NSEvent *)event { + if (![self.adapter mouseEnabled]) { + [super scrollWheel:event]; + return; + } + if ([event hasPreciseScrollingDeltas]) { [self preciseScroll:event]; } else { diff --git a/video/out/cocoa/mpvadapter.h b/video/out/cocoa/mpvadapter.h index 1355a5b345..30e2d572d8 100644 --- a/video/out/cocoa/mpvadapter.h +++ b/video/out/cocoa/mpvadapter.h @@ -31,6 +31,8 @@ - (void)didChangeWindowedScreenProfile:(NSScreen *)screen; - (BOOL)isInFullScreenMode; +- (BOOL)keyboardEnabled; +- (BOOL)mouseEnabled; - (NSScreen *)fsScreen; @property(nonatomic, assign) struct vo *vout; @end diff --git a/video/out/cocoa_common.m b/video/out/cocoa_common.m index 655c740169..0b1acdcce7 100644 --- a/video/out/cocoa_common.m +++ b/video/out/cocoa_common.m @@ -693,6 +693,14 @@ void *vo_cocoa_cgl_pixel_format(struct vo *vo) vo_cocoa_set_current_context(self.vout, false); } +- (BOOL)keyboardEnabled { + return !!mp_input_vo_keyboard_enabled(self.vout->input_ctx); +} + +- (BOOL)mouseEnabled { + return !!mp_input_mouse_enabled(self.vout->input_ctx); +} + - (void)setNeedsResize { struct vo_cocoa_state *s = self.vout->cocoa; s->pending_events |= VO_EVENT_RESIZE; @@ -710,28 +718,23 @@ void *vo_cocoa_cgl_pixel_format(struct vo *vo) } - (void)signalMouseMovement:(NSPoint)point { - if (mp_input_mouse_enabled(self.vout->input_ctx)) { - mp_input_set_mouse_pos(self.vout->input_ctx, point.x, point.y); - [self recalcMovableByWindowBackground:point]; - } + mp_input_set_mouse_pos(self.vout->input_ctx, point.x, point.y); + [self recalcMovableByWindowBackground:point]; } - (void)putKeyEvent:(NSEvent*)event { - if (mp_input_vo_keyboard_enabled(self.vout->input_ctx)) - cocoa_put_key_event(event); + cocoa_put_key_event(event); } - (void)putKey:(int)mpkey withModifiers:(int)modifiers { - if (mp_input_vo_keyboard_enabled(self.vout->input_ctx)) - cocoa_put_key_with_modifiers(mpkey, modifiers); + cocoa_put_key_with_modifiers(mpkey, modifiers); } - (void)putAxis:(int)mpkey delta:(float)delta; { - if (mp_input_mouse_enabled(self.vout->input_ctx)) - mp_input_put_axis(self.vout->input_ctx, mpkey, delta); + mp_input_put_axis(self.vout->input_ctx, mpkey, delta); } - (void)putCommand:(char*)cmd -- cgit v1.2.3