From 8ba3ab2a2647576f706c978222e559ce3047c7c7 Mon Sep 17 00:00:00 2001 From: Guillaume Louel <37544189+glouel@users.noreply.github.com> Date: Mon, 5 Feb 2024 16:00:42 +0100 Subject: [PATCH] 3.3.7 --- Aerial.xcodeproj/project.pbxproj | 8 ++--- .../Models/Hardware/DisplayDetection.swift | 12 +++++-- Aerial/Source/Views/AerialView+Player.swift | 18 +++++++++-- Aerial/Source/Views/AerialView.swift | 32 +++++++++++++------ 4 files changed, 52 insertions(+), 18 deletions(-) diff --git a/Aerial.xcodeproj/project.pbxproj b/Aerial.xcodeproj/project.pbxproj index 9bd077ab..897d6a9e 100644 --- a/Aerial.xcodeproj/project.pbxproj +++ b/Aerial.xcodeproj/project.pbxproj @@ -3249,7 +3249,7 @@ CODE_SIGN_IDENTITY = "Developer ID Application"; CODE_SIGN_STYLE = Manual; COMBINE_HIDPI_IMAGES = YES; - CURRENT_PROJECT_VERSION = 3.3.5; + CURRENT_PROJECT_VERSION = 3.3.7; DEFINES_MODULE = YES; DEVELOPMENT_TEAM = 3L54M5L5KK; ENABLE_HARDENED_RUNTIME = YES; @@ -3257,7 +3257,7 @@ INSTALL_PATH = "$(HOME)/Library/Screen Savers"; LD_RUNPATH_SEARCH_PATHS = "$(inherited) @executable_path/../Frameworks @loader_path/../Frameworks"; MACOSX_DEPLOYMENT_TARGET = 10.13; - MARKETING_VERSION = 3.3.5; + MARKETING_VERSION = 3.3.7; PRODUCT_BUNDLE_IDENTIFIER = com.johncoates.Aerial; PRODUCT_NAME = "$(TARGET_NAME)"; PROVISIONING_PROFILE_SPECIFIER = ""; @@ -3278,7 +3278,7 @@ CODE_SIGN_IDENTITY = "Developer ID Application"; CODE_SIGN_STYLE = Manual; COMBINE_HIDPI_IMAGES = YES; - CURRENT_PROJECT_VERSION = 3.3.5; + CURRENT_PROJECT_VERSION = 3.3.7; DEFINES_MODULE = YES; DEVELOPMENT_TEAM = 3L54M5L5KK; ENABLE_HARDENED_RUNTIME = YES; @@ -3286,7 +3286,7 @@ INSTALL_PATH = "$(HOME)/Library/Screen Savers"; LD_RUNPATH_SEARCH_PATHS = "$(inherited) @executable_path/../Frameworks @loader_path/../Frameworks"; MACOSX_DEPLOYMENT_TARGET = 10.13; - MARKETING_VERSION = 3.3.5; + MARKETING_VERSION = 3.3.7; OTHER_CODE_SIGN_FLAGS = "--timestamp"; PRODUCT_BUNDLE_IDENTIFIER = com.johncoates.Aerial; PRODUCT_NAME = "$(TARGET_NAME)"; diff --git a/Aerial/Source/Models/Hardware/DisplayDetection.swift b/Aerial/Source/Models/Hardware/DisplayDetection.swift index d65c5976..7c25874b 100644 --- a/Aerial/Source/Models/Hardware/DisplayDetection.swift +++ b/Aerial/Source/Models/Hardware/DisplayDetection.swift @@ -239,8 +239,8 @@ final class DisplayDetection: NSObject { return nil } - func alternateFindScreenWith(frame: CGRect, backingScaleFactor: CGFloat) -> Screen? { - debugLog("📺☢️ fs : \(frame.size.debugDescription) bsf : \(backingScaleFactor)") + func alternateFindScreenWith(frame: CGRect) -> Screen? { + debugLog("📺☢️ fs : \(frame.size.debugDescription)") // This is a really simple workaround, we look at the size only, and with the screen list in reverse which seems to kindaaaa match ? // We temporarily ignore bsf as we may not be able to access view.window this early it seems @@ -266,6 +266,14 @@ final class DisplayDetection: NSObject { return nil } + + func markScreenAsUsed(id: CGDirectDisplayID) { + // remove the screen from the unused list + debugLog("pre filter \(unusedScreens.count)") + let filteredScreens = unusedScreens.filter { $0.id != id } + unusedScreens = filteredScreens + debugLog("post filter \(unusedScreens.count)") + } // Calculate the size of the global screen (the composite of all the displays attached) func getGlobalScreenRect() -> CGRect { diff --git a/Aerial/Source/Views/AerialView+Player.swift b/Aerial/Source/Views/AerialView+Player.swift index 40bad567..c4897bf7 100644 --- a/Aerial/Source/Views/AerialView+Player.swift +++ b/Aerial/Source/Views/AerialView+Player.swift @@ -40,7 +40,6 @@ extension AerialView { // In case of span mode we need to compute the size of our layer if PrefsDisplays.viewingMode == .spanned && !isPreview { let zRect = displayDetection.getZeroedActiveSpannedRect() - //let screen = displayDetection.findScreenWith(frame: self.frame) debugLog("foundScreen check : \(foundScreen.debugDescription)") if let scr = foundScreen { @@ -48,10 +47,23 @@ extension AerialView { y: zRect.origin.y - scr.zeroedOrigin.y, width: zRect.width, height: zRect.height) + debugLog("tRect : \(tRect)") playerLayer.frame = tRect } else { - errorLog("This is an unknown screen in span mode, this is not good") - playerLayer.frame = layer.bounds + debugLog("This is an unknown screen in span mode, workarounding...") + + if let alternateScreen = DisplayDetection.sharedInstance.alternateFindScreenWith(frame: self.frame) { + foundScreen = alternateScreen + debugLog("📺 alternate screen found : \(alternateScreen.description)") + let tRect = CGRect(x: zRect.origin.x - alternateScreen.zeroedOrigin.x, + y: zRect.origin.y - alternateScreen.zeroedOrigin.y, + width: zRect.width, + height: zRect.height) + playerLayer.frame = tRect + } else { + errorLog("No alternate screen found, reverting to single screen mode") + playerLayer.frame = layer.bounds + } } } else { playerLayer.frame = layer.bounds diff --git a/Aerial/Source/Views/AerialView.swift b/Aerial/Source/Views/AerialView.swift index 9a0508ce..36698e35 100644 --- a/Aerial/Source/Views/AerialView.swift +++ b/Aerial/Source/Views/AerialView.swift @@ -412,15 +412,20 @@ final class AerialView: ScreenSaverView, CAAnimationDelegate { override func viewDidMoveToWindow() { super.viewDidMoveToWindow() - debugLog("🖼️ \(self.description) viewDidMoveToWindow frame: \(self.frame) window: \(self.window)") - debugLog(self.window?.screen.debugDescription ?? "Unknown") - - if let thisScreen = self.window?.screen { - matchScreen(thisScreen: thisScreen) + if foundScreen != nil { + debugLog("🖼️ \(self.description) viewDidMoveToWindow frame: \(self.frame) window: \(String(describing: self.window))") + debugLog(self.window?.screen.debugDescription ?? "Unknown") + + if let thisScreen = self.window?.screen { + matchScreen(thisScreen: thisScreen) + } else { + // For some reason we may not have a screen here! + debugLog("🖼️ no screen attached, will try again later") + } } else { - // For some reason we may not have a screen here! - debugLog("🖼️ no screen attached, will try again later") + debugLog("🖼️ wdmtw after we already have a screen, ignoring") } + } func matchScreen(thisScreen: NSScreen) { @@ -429,10 +434,19 @@ final class AerialView: ScreenSaverView, CAAnimationDelegate { debugLog(screenID.description) foundScreen = DisplayDetection.sharedInstance.findScreenWith(id: screenID) - foundFrame = foundScreen?.bottomLeftFrame - + if let foundScreen = foundScreen { + foundFrame = foundScreen.bottomLeftFrame + if #available(macOS 14, *) { + self.frame = foundFrame! + + // remove it from the list of unused screens + DisplayDetection.sharedInstance.markScreenAsUsed(id: screenID) + } + } + debugLog("🖼️🌾 Using : \(String(describing: foundScreen))") debugLog("🥬🌾 window.screen \(String(describing: self.window?.screen.debugDescription))") + debugLog("🖼️🌾 self.frame : \(String(describing: self.frame))") } // Handle window resize