Skip to content

Commit

Permalink
winemac.drv: Call CGWindowListCreateImageFromArray through a dlsym-ob…
Browse files Browse the repository at this point in the history
…tained pointer.

The macOS Sequoia SDK has "obsoleted" this function: calling it
triggers a build error when targeting macOS Sequoia.
It can still be used though, either by targeting pre-Sequoia or by
getting a pointer to the function through dlsym().

This is intended to be temporary until ScreenCaptureKit.framework or
some other approach can be used.
  • Loading branch information
mrpippy authored and julliard committed Aug 30, 2024
1 parent caab2a9 commit 15eae87
Showing 1 changed file with 13 additions and 1 deletion.
14 changes: 13 additions & 1 deletion dlls/winemac.drv/cocoa_window.m
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@
#import <CoreVideo/CoreVideo.h>
#import <Metal/Metal.h>
#import <QuartzCore/QuartzCore.h>
#include <dlfcn.h>

#import "cocoa_window.h"

Expand Down Expand Up @@ -2369,9 +2370,20 @@ - (void) grabDockIconSnapshotFromWindow:(WineWindow*)window force:(BOOL)force
return;
}

static CGImageRef __nullable (*pCGWindowListCreateImageFromArray)(CGRect, CFArrayRef, CGWindowImageOption);
static dispatch_once_t once;
dispatch_once(&once, ^{
void *h = dlopen("/System/Library/Frameworks/CoreGraphics.framework/CoreGraphics", RTLD_LAZY | RTLD_LOCAL);
if (h)
pCGWindowListCreateImageFromArray = dlsym(h, "CGWindowListCreateImageFromArray");
});

if (!pCGWindowListCreateImageFromArray)
return;

const void* windowID = (const void*)(uintptr_t)(CGWindowID)window.windowNumber;
CFArrayRef windowIDs = CFArrayCreate(NULL, &windowID, 1, NULL);
CGImageRef windowImage = CGWindowListCreateImageFromArray(CGRectNull, windowIDs, kCGWindowImageBoundsIgnoreFraming);
CGImageRef windowImage = pCGWindowListCreateImageFromArray(CGRectNull, windowIDs, kCGWindowImageBoundsIgnoreFraming);
CFRelease(windowIDs);
if (!windowImage)
return;
Expand Down

0 comments on commit 15eae87

Please sign in to comment.