summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--CMake/setup.cmake27
-rw-r--r--configure.ac4
-rw-r--r--src/Fl_Native_File_Chooser_MAC.mm9
-rw-r--r--src/Fl_cocoa.mm104
4 files changed, 64 insertions, 80 deletions
diff --git a/CMake/setup.cmake b/CMake/setup.cmake
index 04cc5d90a..332b92931 100644
--- a/CMake/setup.cmake
+++ b/CMake/setup.cmake
@@ -123,31 +123,14 @@ if(APPLE)
endif(NOT(${CMAKE_SYSTEM_VERSION} VERSION_LESS 17.0.0))
else()
set(FLTK_COCOA_FRAMEWORKS "-framework Cocoa")
- set(UTI_CONDITION FALSE) # TRUE when framework UniformTypeIdentifiers is used
- set(SCK_CONDITION FALSE) # TRUE when framework ScreenCaptureKit is used
- string(LENGTH "${CMAKE_OSX_DEPLOYMENT_TARGET}" TARGET_LEN)
- string(LENGTH "${CMAKE_SYSTEM_VERSION}" SDK_LEN)
- if(TARGET_LEN GREATER 0)
- if( ${CMAKE_OSX_DEPLOYMENT_TARGET} VERSION_GREATER_EQUAL 11.0)
- set(UTI_CONDITION TRUE)
+ if (NOT (CMAKE_OSX_ARCHITECTURES STREQUAL "ppc" OR CMAKE_OSX_ARCHITECTURES STREQUAL "i386"))
+ if(${CMAKE_SYSTEM_VERSION} VERSION_GREATER_EQUAL 20.0) # a.k.a. macOS version ≥ 11.0
+ list(APPEND FLTK_COCOA_FRAMEWORKS "-weak_framework UniformTypeIdentifiers")
endif()
- if( ${CMAKE_OSX_DEPLOYMENT_TARGET} VERSION_GREATER_EQUAL 15.0)
- set(SCK_CONDITION TRUE)
- endif()
- elseif(SDK_LEN GREATER 0)
- if( ${CMAKE_SYSTEM_VERSION} VERSION_GREATER_EQUAL 20.0 )
- set(UTI_CONDITION TRUE)
- endif()
- if( ${CMAKE_SYSTEM_VERSION} VERSION_GREATER_EQUAL 24.0 )
- set(SCK_CONDITION TRUE)
+ if(${CMAKE_SYSTEM_VERSION} VERSION_GREATER_EQUAL 24.0) # a.k.a. macOS version ≥ 15.0
+ list(APPEND FLTK_COCOA_FRAMEWORKS "-weak_framework ScreenCaptureKit")
endif()
endif()
- if(UTI_CONDITION) # a.k.a. macOS version ≥ 11.0
- list(APPEND FLTK_COCOA_FRAMEWORKS "-framework UniformTypeIdentifiers")
- if(SCK_CONDITION) # a.k.a. macOS version ≥ 15.0
- list(APPEND FLTK_COCOA_FRAMEWORKS "-framework ScreenCaptureKit")
- endif(SCK_CONDITION)
- endif(UTI_CONDITION)
endif(FLTK_BACKEND_X11)
endif(APPLE)
diff --git a/configure.ac b/configure.ac
index c3089eef5..b508d4573 100644
--- a/configure.ac
+++ b/configure.ac
@@ -1010,10 +1010,10 @@ AS_CASE([$host_os_gui], [cygwin* | mingw*], [
LIBS="$LIBS -framework Cocoa"
macosversion_maj=$(sw_vers -productVersion | cut -d. -f1)
AS_IF([test $macosversion_maj -ge 11], [
- LIBS="$LIBS -framework UniformTypeIdentifiers"
+ LIBS="$LIBS -weak_framework UniformTypeIdentifiers"
])
AS_IF([test $macosversion_maj -ge 15], [
- LIBS="$LIBS -framework ScreenCaptureKit"
+ LIBS="$LIBS -weak_framework ScreenCaptureKit"
])
AS_IF([test x$have_pthread = xyes], [
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