summaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
Diffstat (limited to 'src')
-rw-r--r--src/Fl_Native_File_Chooser_MAC.mm9
-rw-r--r--src/Fl_cocoa.mm104
2 files changed, 57 insertions, 56 deletions
diff --git a/src/Fl_Native_File_Chooser_MAC.mm b/src/Fl_Native_File_Chooser_MAC.mm
index 5d8741460..5c424cb24 100644
--- a/src/Fl_Native_File_Chooser_MAC.mm
+++ b/src/Fl_Native_File_Chooser_MAC.mm
@@ -532,11 +532,10 @@ static char *prepareMacFilter(int count, const char *filter, char **patterns) {
- (void)control_allowed_types:(const char *)p
{
NSString *ext = [NSString stringWithUTF8String:p];
-#if MAC_OS_X_VERSION_MAX_ALLOWED >= MAC_OS_VERSION_11_0 && \
- MAC_OS_X_VERSION_MIN_REQUIRED >= MAC_OS_VERSION_11_0
- if (fl_mac_os_version >= 110000) {
- UTType *type = [UTType typeWithFilenameExtension:ext]; // 11.0 + framework UniformTypeIdentifiers
- [dialog setAllowedContentTypes:[NSArray arrayWithObject:type]]; // 11.0
+#if MAC_OS_X_VERSION_MAX_ALLOWED >= MAC_OS_VERSION_11_0
+ if (@available(macOS 11.0, *)) {
+ UTType *type = [UTType typeWithFilenameExtension:ext]; // 11.0 + framework UniformTypeIdentifiers
+ [dialog setAllowedContentTypes:[NSArray arrayWithObject:type]]; // 11.0
}
else
#endif
diff --git a/src/Fl_cocoa.mm b/src/Fl_cocoa.mm
index 08be3aef7..37f321795 100644
--- a/src/Fl_cocoa.mm
+++ b/src/Fl_cocoa.mm
@@ -49,7 +49,7 @@ extern "C" {
#include <pwd.h>
#import <Cocoa/Cocoa.h>
-#if MAC_OS_X_VERSION_MIN_REQUIRED >= MAC_OS_VERSION_15_0
+#if MAC_OS_X_VERSION_MAX_ALLOWED >= MAC_OS_VERSION_15_0
# import <ScreenCaptureKit/ScreenCaptureKit.h>
#endif
@@ -4610,63 +4610,65 @@ int Fl_Cocoa_Window_Driver::decorated_h()
return h() + bt/s;
}
-#if MAC_OS_X_VERSION_MIN_REQUIRED >= MAC_OS_VERSION_15_0
+#if MAC_OS_X_VERSION_MAX_ALLOWED >= MAC_OS_VERSION_15_0
-// Requires -framework ScreenCaptureKit and used by FLTK for macOS ≥ 15.0
+// Requires -weak_framework ScreenCaptureKit and used by FLTK for macOS ≥ 15.0
static CGImageRef capture_titlebar_macOS15(NSWindow *nswin) {
- __block CGImageRef capture = NULL;
- __block BOOL capture_err = NO;
- void (^block_to_stop_main_loop)(void) = ^{ CFRunLoopStop(CFRunLoopGetMain()); };
- CGWindowID target_id = [nswin windowNumber];
- NSRect r = [nswin frame];
- int W = r.size.width, H = r.size.height;
- [SCShareableContent getCurrentProcessShareableContentWithCompletionHandler: // macOS 14.4
- ^(SCShareableContent *shareableContent, NSError *error) {
- SCWindow *scwin = nil;
- if (!error) {
- NSEnumerator *enumerator = [[shareableContent windows] objectEnumerator];
- while ((scwin = (SCWindow*)[enumerator nextObject]) != nil) {
- if ([scwin windowID] == target_id) {
- break;
+ if (@available(macOS 15.0, *)) {
+ __block CGImageRef capture = NULL;
+ __block BOOL capture_err = NO;
+ void (^block_to_stop_main_loop)(void) = ^{ CFRunLoopStop(CFRunLoopGetMain()); };
+ CGWindowID target_id = [nswin windowNumber];
+ NSRect r = [nswin frame];
+ int W = r.size.width, H = r.size.height;
+ [SCShareableContent getCurrentProcessShareableContentWithCompletionHandler: // macOS 14.4
+ ^(SCShareableContent *shareableContent, NSError *error) {
+ SCWindow *scwin = nil;
+ if (!error) {
+ NSEnumerator *enumerator = [[shareableContent windows] objectEnumerator];
+ while ((scwin = (SCWindow*)[enumerator nextObject]) != nil) {
+ if ([scwin windowID] == target_id) {
+ break;
+ }
}
}
- }
- if (!scwin) {
- capture_err = YES;
- dispatch_async(dispatch_get_main_queue(), block_to_stop_main_loop);
- return;
- }
- SCContentFilter *filter = [[[SCContentFilter alloc] initWithDesktopIndependentWindow:scwin] autorelease];
- int s = (int)[filter pointPixelScale];
- SCStreamConfiguration *config = [[[SCStreamConfiguration alloc] init] autorelease];
- [config setIgnoreShadowsSingleWindow:YES];
- [config setWidth:W*s];
- [config setHeight:H*s];
- [config setIncludeChildWindows:NO]; // macOS 14.2
- [SCScreenshotManager captureImageWithFilter:filter
- configuration:config
- completionHandler:^(CGImageRef sampleBuffer, NSError *error) {
- if (error) capture_err = YES;
- else {
- capture = sampleBuffer;
- CGImageRetain(capture);
+ if (!scwin) {
+ capture_err = YES;
+ dispatch_async(dispatch_get_main_queue(), block_to_stop_main_loop);
+ return;
}
- dispatch_async(dispatch_get_main_queue(), block_to_stop_main_loop);
+ SCContentFilter *filter = [[[SCContentFilter alloc] initWithDesktopIndependentWindow:scwin] autorelease];
+ int s = (int)[filter pointPixelScale];
+ SCStreamConfiguration *config = [[[SCStreamConfiguration alloc] init] autorelease];
+ [config setIgnoreShadowsSingleWindow:YES];
+ [config setWidth:W*s];
+ [config setHeight:H*s];
+ [config setIncludeChildWindows:NO]; // macOS 14.2
+ [SCScreenshotManager captureImageWithFilter:filter
+ configuration:config
+ completionHandler:^(CGImageRef sampleBuffer, NSError *error) {
+ if (error) capture_err = YES;
+ else {
+ capture = sampleBuffer;
+ CGImageRetain(capture);
+ }
+ dispatch_async(dispatch_get_main_queue(), block_to_stop_main_loop);
+ }
+ ];
}
];
- }
- ];
- // run the main loop until the 1 or 2 blocks above have finished and have stopped the loop
- while (!capture_err && !capture) CFRunLoopRun();
- if (capture_err) return NULL;
- int bt = [nswin frame].size.height - [[nswin contentView] frame].size.height;
- int s = CGImageGetWidth(capture) / W;
- CGRect cgr = CGRectMake(0, 0, W * s, bt * s);
- CGImageRef title_bar = CGImageCreateWithImageInRect(capture, cgr);
- CGImageRelease(capture);
- return title_bar;
+ // run the main loop until the 1 or 2 blocks above have finished and have stopped the loop
+ while (!capture_err && !capture) CFRunLoopRun();
+ if (capture_err) return NULL;
+ int bt = [nswin frame].size.height - [[nswin contentView] frame].size.height;
+ int s = CGImageGetWidth(capture) / W;
+ CGRect cgr = CGRectMake(0, 0, W * s, bt * s);
+ CGImageRef title_bar = CGImageCreateWithImageInRect(capture, cgr);
+ CGImageRelease(capture);
+ return title_bar;
+ } else return NULL;
}
-#endif // MAC_OS_X_VERSION_MIN_REQUIRED >= MAC_OS_VERSION_15_0
+#endif //MAC_OS_X_VERSION_MAX_ALLOWED >= MAC_OS_VERSION_15_0
void Fl_Cocoa_Window_Driver::draw_titlebar_to_context(CGContextRef gc, int w, int h)
@@ -4676,7 +4678,7 @@ void Fl_Cocoa_Window_Driver::draw_titlebar_to_context(CGContextRef gc, int w, in
[NSApp nextEventMatchingMask:NSEventMaskAny untilDate:nil inMode:NSDefaultRunLoopMode dequeue:NO];
CGImageRef img = NULL;
#if MAC_OS_X_VERSION_MAX_ALLOWED >= MAC_OS_X_VERSION_10_5
-# if MAC_OS_X_VERSION_MIN_REQUIRED >= MAC_OS_VERSION_15_0
+# if MAC_OS_X_VERSION_MAX_ALLOWED >= MAC_OS_VERSION_15_0
if (fl_mac_os_version >= 150000) img = capture_titlebar_macOS15(nswin);
else
# endif