summaryrefslogtreecommitdiffstats
path: root/video
diff options
context:
space:
mode:
Diffstat (limited to 'video')
-rw-r--r--video/out/cocoa_common.m128
-rw-r--r--video/out/vo_direct3d.c3
2 files changed, 90 insertions, 41 deletions
diff --git a/video/out/cocoa_common.m b/video/out/cocoa_common.m
index bfa5c768b2..4679eaf4a5 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"
@@ -51,8 +52,10 @@
@end
@interface GLMPlayerOpenGLView : NSView
+@property(nonatomic, retain) NSTrackingArea *tracker;
@property(nonatomic, assign) struct vo *videoOutput;
-- (BOOL)containsCurrentMouseLocation;
+- (BOOL)containsMouseLocation;
+- (void)recalcDraggableState;
- (void)mouseEvent:(NSEvent *)theEvent;
@property(nonatomic, assign, getter=hasMouseDown) BOOL mouseDown;
@end
@@ -160,13 +163,9 @@ static void vo_cocoa_set_cursor_visibility(struct vo *vo, bool visible)
struct vo_cocoa_state *s = vo->cocoa;
if (visible) {
- // show cursor unconditionally
CGDisplayShowCursor(kCGDirectMainDisplay);
- } else if (vo->opts->fullscreen &&
- [s->view containsCurrentMouseLocation] &&
- ![s->view hasMouseDown]) {
- // only hide cursor if in fullscreen and the video view contains the
- // mouse location
+ } else if (vo->opts->fullscreen && ![s->view hasMouseDown] &&
+ [s->view containsMouseLocation]) {
CGDisplayHideCursor(kCGDirectMainDisplay);
}
}
@@ -320,7 +319,6 @@ static void create_window(struct vo *vo, uint32_t d_width, uint32_t d_height,
[s->window setRestorable:NO];
[s->window setContentView:s->view];
[s->view release];
- [s->window setAcceptsMouseMovedEvents:YES];
[s->glContext setView:s->view];
s->window.videoOutput = vo;
s->view.videoOutput = vo;
@@ -399,6 +397,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);
@@ -622,23 +621,32 @@ int vo_cocoa_cgl_color_size(struct vo *vo)
}
}
+- (BOOL)isInFullScreenMode
+{
+ return (([self styleMask] & NSFullScreenWindowMask) ==
+ NSFullScreenWindowMask);
+}
+
- (void)toggleMissionControlFullScreen:(BOOL)willBeFullscreen
{
struct vo_cocoa_state *s = self.videoOutput->cocoa;
- if (willBeFullscreen) {
+ if (willBeFullscreen && ![self isInFullScreenMode]) {
[self setContentResizeIncrements:NSMakeSize(1, 1)];
- } else {
+ [self toggleFullScreen:nil];
+ }
+
+ if (!willBeFullscreen && [self isInFullScreenMode]) {
[self setContentAspectRatio:s->current_video_size];
+ [self toggleFullScreen:nil];
}
- [self toggleFullScreen:nil];
}
- (void)toggleViewFullscreen:(BOOL)willBeFullscreen
{
struct vo_cocoa_state *s = self.videoOutput->cocoa;
- if (willBeFullscreen) {
+ if (willBeFullscreen && ![s->view isInFullScreenMode]) {
NSApplicationPresentationOptions popts =
NSApplicationPresentationDefault;
@@ -660,7 +668,9 @@ int vo_cocoa_cgl_color_size(struct vo *vo)
// sending the View fullscreen to another screen. Make it go away
// manually.
[s->window orderOut:self];
- } else {
+ }
+
+ if (!willBeFullscreen && [s->view isInFullScreenMode]) {
[s->view exitFullScreenModeWithOptions:nil];
// Show the "windowed" window again.
@@ -691,6 +701,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 +726,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];}
@@ -802,44 +805,89 @@ int vo_cocoa_cgl_color_size(struct vo *vo)
[self setContentSize:ns];
}
}
+
@end
@implementation GLMPlayerOpenGLView
+@synthesize tracker = _tracker;
@synthesize videoOutput = _video_output;
@synthesize mouseDown = _mouse_down;
-- (BOOL)acceptsFirstResponder { return YES; }
-- (BOOL)becomeFirstResponder { return YES; }
-- (BOOL)resignFirstResponder { return YES; }
+// mpv uses flipped coordinates, because X11 uses those. So let's just use them
+// as well without having to do any coordinate conversion of mouse positions.
+- (BOOL) isFlipped { return YES; }
+
+- (id)initWithFrame:(NSRect)frame {
+ if (self = [super initWithFrame:frame]) {
+ NSTrackingAreaOptions trackingOptions =
+ NSTrackingEnabledDuringMouseDrag |
+ NSTrackingMouseEnteredAndExited | NSTrackingMouseMoved |
+ NSTrackingActiveInActiveApp;
+
+ self.tracker =
+ [[[NSTrackingArea alloc] initWithRect:[self bounds]
+ options:trackingOptions
+ owner:self
+ userInfo:nil] autorelease];
-- (NSPoint) mouseLocation
+ [self addTrackingArea:self.tracker];
+ }
+
+ return self;
+}
+
+- (NSPoint)mouseLocation
{
- NSPoint mLoc = [NSEvent mouseLocation];
- NSPoint wLoc = [self.window convertScreenToBase:mLoc];
+ NSPoint wLoc = [self.window mouseLocationOutsideOfEventStream];
return [self convertPoint:wLoc fromView:nil];
}
-- (BOOL)containsCurrentMouseLocation
+- (BOOL)containsMouseLocation
{
- NSRect vF = [[self.window screen] visibleFrame];
- NSRect vFR = [self.window convertRectFromScreen:vF];
- NSRect vFRV = [self convertRect:vFR fromView:nil];
+ NSRect vF = [[self.window screen] visibleFrame];
+ NSRect vFW = [self.window convertRectFromScreen:vF];
+ NSRect vFV = [self convertRect:vFW fromView:nil];
// clip bounds to current visibleFrame
- NSRect clippedBounds = CGRectIntersection([self bounds], vFRV);
+ NSRect clippedBounds = CGRectIntersection([self bounds], vFV);
return CGRectContainsPoint(clippedBounds, [self mouseLocation]);
}
-- (void)signalMouseMovement:(NSEvent *)event
+- (BOOL)acceptsFirstResponder { return YES; }
+- (BOOL)becomeFirstResponder { return YES; }
+- (BOOL)resignFirstResponder { return YES; }
+
+- (void)recalcDraggableState
{
- if ([self containsCurrentMouseLocation]) {
+ struct vo *vo = self.videoOutput;
+ BOOL movable = NO;
+
+ if (!vo->opts->fullscreen) {
NSPoint loc = [self mouseLocation];
- loc.y = - loc.y + [self bounds].size.height;
- vo_mouse_movement(self.videoOutput, loc.x, loc.y);
+ movable = !mp_input_test_dragging(vo->input_ctx, loc.x, loc.y);
}
+
+ [self.window setMovableByWindowBackground:movable];
+}
+
+- (void)mouseEntered:(NSEvent *)event
+{
+ // do nothing!
+}
+
+- (void)mouseExited:(NSEvent *)event
+{
+ cocoa_put_key(MP_KEY_MOUSE_LEAVE);
+ vo_cocoa_set_cursor_visibility(self.videoOutput, true);
+}
+
+- (void)signalMouseMovement:(NSEvent *)event
+{
+ NSPoint p = [self convertPoint:[event locationInWindow] fromView:nil];
+ vo_mouse_movement(self.videoOutput, p.x, p.y);
}
-- (void)mouseMoved:(NSEvent *)evt { [self signalMouseMovement:evt]; }
-- (void)mouseDragged:(NSEvent *)evt { [self signalMouseMovement:evt]; }
+- (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]; }
@@ -940,7 +988,7 @@ int vo_cocoa_cgl_color_size(struct vo *vo)
// The visible frame's width is smaller: dock is on left or right end
// of this method's receiver.
vF.size.width < f.size.width ||
- // The visible frame's veritical origin is bigger is smaller: dock is
+ // The visible frame's veritical origin is bigger: dock is
// on the bottom of this method's receiver.
vF.origin.y > f.origin.y;
diff --git a/video/out/vo_direct3d.c b/video/out/vo_direct3d.c
index 6540177ad0..25d0b8f0da 100644
--- a/video/out/vo_direct3d.c
+++ b/video/out/vo_direct3d.c
@@ -26,6 +26,7 @@
#include <stdbool.h>
#include <assert.h>
#include <d3d9.h>
+#include <inttypes.h>
#include "config.h"
#include "core/options.h"
#include "core/subopt-helper.h"
@@ -290,7 +291,7 @@ static void calc_fs_rect(d3d_priv *priv)
priv->fs_panscan_rect.bottom = src_rect.y1;
mp_msg(MSGT_VO, MSGL_V,
- "<vo_direct3d>Video rectangle: t: %ld, l: %ld, r: %ld, b:%ld\n",
+ "<vo_direct3d>Video rectangle: t: %"PRId32", l: %"PRId32", r: %"PRId32", b:%"PRId32"\n",
priv->fs_movie_rect.top, priv->fs_movie_rect.left,
priv->fs_movie_rect.right, priv->fs_movie_rect.bottom);
}