Skip to content

Commit

Permalink
Add a fallback path if SkyLight SPI disappears
Browse files Browse the repository at this point in the history
Also note the feedback number for why we are using this, in case anyone
stumbles upon this and wants to look it up.
  • Loading branch information
saagarjha committed Jan 28, 2024
1 parent a6ce983 commit 9b77db0
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 4 deletions.
5 changes: 3 additions & 2 deletions macOS/SPI.swift
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ import CoreGraphics

typealias CGSConnectionID = CUnsignedInt

// FB13556001
let skylight = dlopen("/System/Library/PrivateFrameworks/SkyLight.framework/SkyLight", RTLD_LAZY)
let SLSMainConnectionID = unsafeBitCast(dlsym(skylight, "SLSMainConnectionID"), to: (@convention(c) () -> CGSConnectionID)?.self)!
let SLSCopyAssociatedWindows = unsafeBitCast(dlsym(skylight, "SLSCopyAssociatedWindows"), to: (@convention(c) (CGSConnectionID, CGWindowID) -> CFArray)?.self)!
let SLSMainConnectionID = unsafeBitCast(dlsym(skylight, "SLSMainConnectionID"), to: (@convention(c) () -> CGSConnectionID)?.self)
let SLSCopyAssociatedWindows = unsafeBitCast(dlsym(skylight, "SLSCopyAssociatedWindows"), to: (@convention(c) (CGSConnectionID, CGWindowID) -> CFArray)?.self)
11 changes: 9 additions & 2 deletions macOS/ScreenRecorder.swift
Original file line number Diff line number Diff line change
Expand Up @@ -83,7 +83,7 @@ actor ScreenRecorder {
configuration.width = Int(window.frame.width * CGFloat(filter.pointPixelScale))
configuration.height = Int(window.frame.height * CGFloat(filter.pointPixelScale))
if #available(macOS 14.2, *) {
configuration.includeChildWindows = false
configuration.includeChildWindows = SLSCopyAssociatedWindows == nil
}
configuration.showsCursor = false

Expand Down Expand Up @@ -119,7 +119,14 @@ actor ScreenRecorder {
Task {
while childObservers.contains(windowID) {
try await Task.sleep(for: .seconds(1))
var childWindows = Set(SLSCopyAssociatedWindows(SLSMainConnectionID(), windowID) as! [CGWindowID])
var childWindows =
if let SLSCopyAssociatedWindows,
let SLSMainConnectionID
{
Set(SLSCopyAssociatedWindows(SLSMainConnectionID(), windowID) as? [CGWindowID] ?? [])
} else {
Set<CGWindowID>()
}
childWindows.remove(windowID)

let root = try await lookup(windowID: windowID)!
Expand Down

0 comments on commit 9b77db0

Please sign in to comment.