From af264029483656e04458a678849165f0340433ab Mon Sep 17 00:00:00 2001 From: der richter Date: Sun, 13 Dec 2020 17:13:18 +0100 Subject: mac: use visible frame rectangle for window geometry calculation currently we use the whole screen rectangle to calculate the window geometry. this doesn't take the menu bar or the Dock into account. by default use the visible screen rectangle instead. this is also a change in behaviour, since the window can't be placed outside of this rectangle anymore. also add an option to change to the old behaviour, because it can still be useful in certain cases, like placing the window directly underneath the menu bar when used a desktop background. Fixes #8272 --- video/out/mac/common.swift | 30 ++++++++++++++++++------------ 1 file changed, 18 insertions(+), 12 deletions(-) (limited to 'video/out') diff --git a/video/out/mac/common.swift b/video/out/mac/common.swift index e3f1405c02..e27d17d621 100644 --- a/video/out/mac/common.swift +++ b/video/out/mac/common.swift @@ -440,21 +440,27 @@ class Common: NSObject { func getWindowGeometry(forScreen targetScreen: NSScreen, videoOut vo: UnsafeMutablePointer) -> NSRect { let r = targetScreen.convertRectToBacking(targetScreen.frame) - var screenRC: mp_rect = mp_rect(x0: Int32(0), - y0: Int32(0), - x1: Int32(r.size.width), - y1: Int32(r.size.height)) - + let targetFrame = + (mpv?.macOpts.macos_geometry_calculation ?? FRAME_VISIBLE) == FRAME_VISIBLE ? + targetScreen.visibleFrame : targetScreen.frame + let rv = targetScreen.convertRectToBacking(targetFrame) + + // flip the y origin, mp_rect expects the origin at the top-left + // macOS' windowing system operates from the bottom-left + var originY = r.size.height - rv.origin.y - rv.size.height + var screenRC: mp_rect = mp_rect(x0: Int32(rv.origin.x), + y0: Int32(originY), + x1: Int32(rv.origin.x + rv.size.width), + y1: Int32(originY + rv.size.height)) var geo: vo_win_geometry = vo_win_geometry() vo_calc_window_geometry2(vo, &screenRC, Double(targetScreen.backingScaleFactor), &geo) + vo_apply_window_geometry(vo, &geo) - // flip y coordinates - geo.win.y1 = Int32(r.size.height) - geo.win.y1 - geo.win.y0 = Int32(r.size.height) - geo.win.y0 - - let wr = NSMakeRect(CGFloat(geo.win.x0), CGFloat(geo.win.y1), - CGFloat(geo.win.x1 - geo.win.x0), - CGFloat(geo.win.y0 - geo.win.y1)) + // flip the y origin again + let height = CGFloat(geo.win.y1 - geo.win.y0) + originY = r.size.height - CGFloat(geo.win.y0) - height + let wr = NSMakeRect(CGFloat(geo.win.x0), originY, + CGFloat(geo.win.x1 - geo.win.x0), height) return targetScreen.convertRectFromBacking(wr) } -- cgit v1.2.3