summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorAkemi <der.richter@gmx.de>2016-12-30 17:46:50 +0100
committerAkemi <der.richter@gmx.de>2017-01-11 14:15:10 +0100
commita05c5b4ec64da5630a29e9507357e662675e22e4 (patch)
tree4e06ee36f35ceabfe44d129470c0a94ed24ac7c8
parentcbd8abcbff83624c20460cc05bf33d72c5148d67 (diff)
downloadmpv-a05c5b4ec64da5630a29e9507357e662675e22e4.tar.bz2
mpv-a05c5b4ec64da5630a29e9507357e662675e22e4.tar.xz
cocoa: fix handling of geometry option
This flips the y-coordinate to be consistent with other platforms and the manual. furthermore it fixes an unwanted behaviour of the cocoa convertRectFromBacking method, where the x- and y-coordinate was divided by the same factor as the width and height instead of placing the new scaled rectangle at the same relative position as the original unscaled rectangle, by manually calculating the new position. Fixes #3867
-rw-r--r--video/out/cocoa_common.m34
1 files changed, 27 insertions, 7 deletions
diff --git a/video/out/cocoa_common.m b/video/out/cocoa_common.m
index 164663c332..f4d2562acd 100644
--- a/video/out/cocoa_common.m
+++ b/video/out/cocoa_common.m
@@ -113,14 +113,36 @@ static void run_on_main_thread(struct vo *vo, void(^block)(void))
dispatch_sync(dispatch_get_main_queue(), block);
}
+static NSRect calculate_window_geometry(struct vo *vo, NSRect rect)
+{
+ struct vo_cocoa_state *s = vo->cocoa;
+ struct mp_vo_opts *opts = vo->opts;
+
+ NSRect screenFrame = [s->current_screen frame];
+ rect.origin.y = screenFrame.size.height - (rect.origin.y + rect.size.height);
+
+ if(!opts->hidpi_window_scale) {
+ NSRect oldRect = rect;
+ rect = [s->current_screen convertRectFromBacking:rect];
+
+ CGFloat x_per = screenFrame.size.width - oldRect.size.width;
+ CGFloat y_per = screenFrame.size.height - oldRect.size.height;
+ if (x_per > 0) x_per = oldRect.origin.x/x_per;
+ if (y_per > 0) y_per = oldRect.origin.y/y_per;
+
+ rect.origin.x = (screenFrame.size.width - rect.size.width)*x_per;
+ rect.origin.y = (screenFrame.size.height - rect.size.height)*y_per;
+ }
+
+ return rect;
+}
+
static void queue_new_video_size(struct vo *vo, int w, int h)
{
struct vo_cocoa_state *s = vo->cocoa;
struct mp_vo_opts *opts = vo->opts;
id<MpvSizing> win = (id<MpvSizing>) s->window;
- NSRect r = NSMakeRect(0, 0, w, h);
- if(!opts->hidpi_window_scale)
- r = [s->current_screen convertRectFromBacking:r];
+ NSRect r = calculate_window_geometry(vo, NSMakeRect(0, 0, w, h));
[win queueNewVideoSize:NSMakeSize(r.size.width, r.size.height)];
}
@@ -472,10 +494,8 @@ static void create_ui(struct vo *vo, struct mp_rect *win, int geo_flags)
if (s->embedded) {
parent = (NSView *) (intptr_t) opts->WinID;
} else {
- NSRect wr =
- NSMakeRect(win->x0, win->y0, win->x1 - win->x0, win->y1 - win->y0);
- if(!opts->hidpi_window_scale)
- wr = [s->current_screen convertRectFromBacking:wr];
+ NSRect wr = calculate_window_geometry(vo,
+ NSMakeRect(win->x0, win->y0, win->x1 - win->x0, win->y1 - win->y0));
s->window = create_window(wr, s->current_screen, opts->border, adapter);
parent = [s->window contentView];
}