From dd4d239bcb151b08eb81b38486515a3e1222e1f5 Mon Sep 17 00:00:00 2001 From: der richter Date: Sat, 24 Apr 2021 20:17:07 +0200 Subject: mac: add support for display-width/display-height property also merge back a helper function that was introduced in commit d3b7732 and for the purpose to be used with the new display res voctrl event. --- video/out/mac/common.swift | 33 ++++++++++++++++++++------------- 1 file changed, 20 insertions(+), 13 deletions(-) (limited to 'video') diff --git a/video/out/mac/common.swift b/video/out/mac/common.swift index f439088642..6289c6bf6a 100644 --- a/video/out/mac/common.swift +++ b/video/out/mac/common.swift @@ -438,27 +438,23 @@ class Common: NSObject { NSScreen.main } - func calculateRect(forScreen screen: NSScreen, visible: Bool) -> mp_rect { + func getWindowGeometry(forScreen screen: NSScreen, + videoOut vo: UnsafeMutablePointer) -> NSRect { let r = screen.convertRectToBacking(screen.frame) - let targetFrame = visible ? screen.visibleFrame : screen.frame + let targetFrame = (mpv?.macOpts.macos_geometry_calculation ?? Int32(FRAME_VISIBLE)) == FRAME_VISIBLE + ? screen.visibleFrame : screen.frame let rv = screen.convertRectToBacking(targetFrame) // convert origin to be relative to target screen var originY = rv.origin.y - r.origin.y - var originX = rv.origin.x - r.origin.x + let originX = rv.origin.x - r.origin.x // flip the y origin, mp_rect expects the origin at the top-left // macOS' windowing system operates from the bottom-left originY = -(originY + rv.size.height) - return mp_rect(x0: Int32(originX), - y0: Int32(originY), - x1: Int32(originX + rv.size.width), - y1: Int32(originY + rv.size.height)) - } - - func getWindowGeometry(forScreen screen: NSScreen, - videoOut vo: UnsafeMutablePointer) -> NSRect { - let visible: Bool = (mpv?.macOpts.macos_geometry_calculation ?? Int32(FRAME_VISIBLE)) == FRAME_VISIBLE - var screenRC: mp_rect = calculateRect(forScreen: screen, visible: visible) + var screenRC: mp_rect = mp_rect(x0: Int32(originX), + y0: Int32(originY), + x1: Int32(originX + rv.size.width), + y1: Int32(originY + rv.size.height)) var geo: vo_win_geometry = vo_win_geometry() vo_calc_window_geometry2(vo, &screenRC, Double(screen.backingScaleFactor), &geo) @@ -653,6 +649,17 @@ class Common: NSObject { SWIFT_TARRAY_STRING_APPEND(nil, &array, &count, nil) dnames.pointee = array return VO_TRUE + case VOCTRL_GET_DISPLAY_RES: + guard let screen = getCurrentScreen() else { + log.sendWarning("No Screen available to retrieve frame") + return VO_NOTAVAIL + } + let sizeData = data.assumingMemoryBound(to: Int32.self) + let size = UnsafeMutableBufferPointer(start: sizeData, count: 2) + let frame = screen.convertRectToBacking(screen.frame) + size[0] = Int32(frame.size.width) + size[1] = Int32(frame.size.height) + return VO_TRUE case VOCTRL_GET_FOCUSED: let focus = data.assumingMemoryBound(to: CBool.self) focus.pointee = NSApp.isActive -- cgit v1.2.3