diff options
author | der richter <der.richter@gmx.de> | 2021-04-24 20:17:07 +0200 |
---|---|---|
committer | Dudemanguy <random342@airmail.cc> | 2021-05-06 17:36:55 +0000 |
commit | dd4d239bcb151b08eb81b38486515a3e1222e1f5 (patch) | |
tree | e3c7ab21378a213bdaab9ea0d1f990aad6103779 | |
parent | a88fdfde0c91c16c84e6057b19bdc2fb9e666e24 (diff) | |
download | mpv-dd4d239bcb151b08eb81b38486515a3e1222e1f5.tar.bz2 mpv-dd4d239bcb151b08eb81b38486515a3e1222e1f5.tar.xz |
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.
-rw-r--r-- | video/out/mac/common.swift | 33 |
1 files changed, 20 insertions, 13 deletions
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<vo>) -> 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<vo>) -> 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 |