From 9791c6d17849cfb342a1c60a69f7d1119b4dd7c8 Mon Sep 17 00:00:00 2001 From: der richter Date: Sat, 5 Oct 2024 14:16:33 +0200 Subject: [PATCH] mac/common: don't unconditionally move the window on geometry changes --- video/out/cocoa_cb_common.swift | 2 +- video/out/mac/common.swift | 19 ++++++++++--------- video/out/mac_common.swift | 2 +- 3 files changed, 12 insertions(+), 11 deletions(-) diff --git a/video/out/cocoa_cb_common.swift b/video/out/cocoa_cb_common.swift index 4b4250c565..38540a2040 100644 --- a/video/out/cocoa_cb_common.swift +++ b/video/out/cocoa_cb_common.swift @@ -92,7 +92,7 @@ class CocoaCB: Common, EventSubscriber { return } - let wr = getWindowGeometry(forScreen: targetScreen, videoOut: vo) + let (wr, _) = getWindowGeometry(forScreen: targetScreen, videoOut: vo) if !(window?.isVisible ?? false) && !(window?.isMiniaturized ?? false) && !NSApp.isHidden { window?.makeKeyAndOrderFront(nil) } diff --git a/video/out/mac/common.swift b/video/out/mac/common.swift index dcab914f2c..7e3af8bd46 100644 --- a/video/out/mac/common.swift +++ b/video/out/mac/common.swift @@ -75,7 +75,7 @@ class Common: NSObject { } func initWindow(_ vo: UnsafeMutablePointer, _ previousActiveApp: NSRunningApplication?) { - let (targetScreen, wr) = getInitProperties(vo) + let (targetScreen, wr, _) = getInitProperties(vo) guard let view = self.view else { log.error("Something went wrong, no View was initialized") @@ -120,7 +120,7 @@ class Common: NSObject { } func initView(_ vo: UnsafeMutablePointer, _ layer: CALayer) { - let (_, wr) = getInitProperties(vo) + let (_, wr, _) = getInitProperties(vo) view = View(frame: wr, common: self) guard let view = self.view else { @@ -408,7 +408,7 @@ class Common: NSObject { } func getWindowGeometry(forScreen screen: NSScreen, - videoOut vo: UnsafeMutablePointer) -> NSRect { + videoOut vo: UnsafeMutablePointer) -> (NSRect, Bool) { let r = screen.convertRectToBacking(screen.frame) let targetFrame = option.mac.macos_geometry_calculation == FRAME_VISIBLE ? screen.visibleFrame : screen.frame @@ -434,18 +434,19 @@ class Common: NSObject { // flip the y origin again let y = CGFloat(-geo.win.y1) let x = CGFloat(geo.win.x0) - return screen.convertRectFromBacking(NSRect(x: x, y: y, width: width, height: height)) + let wr = screen.convertRectFromBacking(NSRect(x: x, y: y, width: width, height: height)) + return (wr, Bool(geo.flags & Int32(VO_WIN_FORCE_POS))) } - func getInitProperties(_ vo: UnsafeMutablePointer) -> (NSScreen, NSRect) { + func getInitProperties(_ vo: UnsafeMutablePointer) -> (NSScreen, NSRect, Bool) { guard let targetScreen = getTargetScreen(forFullscreen: false) ?? NSScreen.main else { log.error("Something went wrong, no Screen was found") exit(1) } - let wr = getWindowGeometry(forScreen: targetScreen, videoOut: vo) + let (wr, forcePosition) = getWindowGeometry(forScreen: targetScreen, videoOut: vo) - return (targetScreen, wr) + return (targetScreen, wr, forcePosition) } // call before initApp, because on macOS +10.15 it changes the active App @@ -535,8 +536,8 @@ class Common: NSObject { TypeHelper.toPointer(&option.voPtr.pointee.autofit_smaller), TypeHelper.toPointer(&option.voPtr.pointee.autofit_larger): DispatchQueue.main.async { - let (_, wr) = self.getInitProperties(vo) - self.window?.updateFrame(wr) + let (_, wr, forcePosition) = self.getInitProperties(vo) + forcePosition ? self.window?.updateFrame(wr) : self.window?.updateSize(wr.size) } default: break diff --git a/video/out/mac_common.swift b/video/out/mac_common.swift index 3184e31c38..12c499a813 100644 --- a/video/out/mac_common.swift +++ b/video/out/mac_common.swift @@ -47,7 +47,7 @@ class MacCommon: Common { let previousActiveApp = getActiveApp() initApp() - let (_, wr) = getInitProperties(vo) + let (_, wr, _) = getInitProperties(vo) guard let layer = self.layer else { log.error("Something went wrong, no MetalLayer was initialized")