From 891e09266970a65ce0d47b923c1ad4139712e6ea Mon Sep 17 00:00:00 2001 From: Stefano Pigozzi Date: Sat, 22 Jun 2013 10:42:50 +0200 Subject: cocoa_common: implement conditional video dragging This was more roundabout than expected, since it looks like the framework caches isMovabileByWindowBackground so in mpv's case it's needed to set it with setMovableByWindowBackground. --- video/out/cocoa_common.m | 44 ++++++++++++++++++++++++++++++-------------- 1 file changed, 30 insertions(+), 14 deletions(-) (limited to 'video') diff --git a/video/out/cocoa_common.m b/video/out/cocoa_common.m index bfa5c768b2..5fc70d0c66 100644 --- a/video/out/cocoa_common.m +++ b/video/out/cocoa_common.m @@ -31,6 +31,7 @@ #include "vo.h" #include "aspect.h" +#include "core/input/input.h" #include "talloc.h" #include "core/mp_msg.h" @@ -52,6 +53,7 @@ @interface GLMPlayerOpenGLView : NSView @property(nonatomic, assign) struct vo *videoOutput; +- (void)recalcDraggableState; - (BOOL)containsCurrentMouseLocation; - (void)mouseEvent:(NSEvent *)theEvent; @property(nonatomic, assign, getter=hasMouseDown) BOOL mouseDown; @@ -399,6 +401,7 @@ static void update_window(struct vo *vo) } } + [s->view recalcDraggableState]; cocoa_set_window_title(vo, vo_get_window_title(vo)); vo_cocoa_fullscreen(vo); @@ -691,6 +694,8 @@ int vo_cocoa_cgl_color_size(struct vo *vo) vo_cocoa_set_cursor_visibility(self.videoOutput, true); } + [s->view recalcDraggableState]; + // Change window size if the core attempted to change it while we were in // fullscreen. For example config() might have been called as a result of // a new file changing the window size. @@ -714,15 +719,6 @@ int vo_cocoa_cgl_color_size(struct vo *vo) return NO; } -- (BOOL)isMovableByWindowBackground -{ - if (self.videoOutput) { - return !self.videoOutput->opts->fullscreen; - } else { - return YES; - } -} - - (void)normalSize { [self mulSize:1.0f]; } - (void)halfSize { [self mulSize:0.5f];} @@ -811,13 +807,19 @@ int vo_cocoa_cgl_color_size(struct vo *vo) - (BOOL)becomeFirstResponder { return YES; } - (BOOL)resignFirstResponder { return YES; } -- (NSPoint) mouseLocation +- (NSPoint)mouseLocation { - NSPoint mLoc = [NSEvent mouseLocation]; - NSPoint wLoc = [self.window convertScreenToBase:mLoc]; + NSPoint wLoc = [self.window mouseLocationOutsideOfEventStream]; return [self convertPoint:wLoc fromView:nil]; } +- (NSPoint)mouseLocationUpperLeft +{ + NSPoint loc = [self mouseLocation]; + loc.y = - loc.y + [self bounds].size.height; + return loc; +} + - (BOOL)containsCurrentMouseLocation { NSRect vF = [[self.window screen] visibleFrame]; @@ -829,12 +831,26 @@ int vo_cocoa_cgl_color_size(struct vo *vo) return CGRectContainsPoint(clippedBounds, [self mouseLocation]); } +- (void)recalcDraggableState +{ + struct vo *vo = self.videoOutput; + BOOL movable = NO; + + if (!vo->opts->fullscreen) { + NSPoint loc = [self mouseLocationUpperLeft]; + movable = !mp_input_test_dragging(vo->input_ctx, loc.x, loc.y); + } + + [self.window setMovableByWindowBackground:movable]; +} + + - (void)signalMouseMovement:(NSEvent *)event { if ([self containsCurrentMouseLocation]) { - NSPoint loc = [self mouseLocation]; - loc.y = - loc.y + [self bounds].size.height; + NSPoint loc = [self mouseLocationUpperLeft]; vo_mouse_movement(self.videoOutput, loc.x, loc.y); + [self recalcDraggableState]; } } -- cgit v1.2.3