From ab215e3696b6392266ffdc31b28e83280ae8f9e1 Mon Sep 17 00:00:00 2001 From: JoeyShapiro Date: Sat, 25 Jan 2025 16:48:17 -0600 Subject: [PATCH 1/3] builds on macos 15 --- Makefile | 5 +++++ src/Window_cocoa.m | 43 ++++++++++++++++++++++++++++++++++++++----- src/freetype/ftmac.c | 1 + 3 files changed, 44 insertions(+), 5 deletions(-) diff --git a/Makefile b/Makefile index 03227d223..cc1971f9c 100644 --- a/Makefile +++ b/Makefile @@ -80,6 +80,11 @@ ifeq ($(PLAT),darwin) LDFLAGS = -rdynamic -framework Cocoa -framework OpenGL -framework IOKit -lobjc BUILD_DIR = build-macos TARGET = $(ENAME).app + + MACOS_VERSION = $(shell sw_vers -productVersion | cut -d. -f1) + ifeq ($(shell expr $(MACOS_VERSION) \>= 12), 1) + LDFLAGS += -framework UniformTypeIdentifiers + endif endif ifeq ($(PLAT),freebsd) diff --git a/src/Window_cocoa.m b/src/Window_cocoa.m index 01645ebbe..670eae992 100644 --- a/src/Window_cocoa.m +++ b/src/Window_cocoa.m @@ -27,6 +27,7 @@ static cc_bool scroll_debugging; #define DIALOG_OK NSModalResponseOK #define PASTEBOARD_STRING_TYPE NSPasteboardTypeString + #import #else #define WIN_MASK (NSTitledWindowMask | NSClosableWindowMask | NSResizableWindowMask | NSMiniaturizableWindowMask) #define ANY_EVENT_MASK NSAnyEventMask @@ -260,7 +261,7 @@ static void RefreshWindowBounds(void) { - (void)keyDown:(NSEvent *)event { } @end -@interface CCWindowDelegate : NSObject { } +@interface CCWindowDelegate : NSObject { } @end @implementation CCWindowDelegate - (void)windowDidResize:(NSNotification *)notification { @@ -494,7 +495,7 @@ static void ProcessKeyChars(id ev) { len = String_Length(src); while (len > 0) { - i = Convert_Utf8ToCodepoint(&cp, src, len); + i = Convert_Utf8ToCodepoint(&cp, (const cc_uint8*)src, len); if (!i) break; Event_RaiseInt(&InputEvents.Press, cp); @@ -630,8 +631,14 @@ void ShowDialogCore(const char* title, const char* msg) { alert = [NSAlert alloc]; alert = [alert init]; +#if defined MAC_OS_X_VERSION_10_12 && MAC_OS_X_VERSION_MIN_REQUIRED >= MAC_OS_X_VERSION_10_12 + [alert setMessageText: (__bridge NSString*)titleCF]; + [alert setInformativeText: (__bridge NSString*)msgCF]; +#else [alert setMessageText: titleCF]; [alert setInformativeText: msgCF]; +#endif + [alert addButtonWithTitle: @"OK"]; [alert runModal]; @@ -647,7 +654,14 @@ static NSMutableArray* GetOpenSaveFilters(const char* const* filters) { { NSString* filter = [NSString stringWithUTF8String:filters[i]]; filter = [filter substringFromIndex:1]; - [types addObject:filter]; +#if defined MAC_OS_X_VERSION_10_12 && MAC_OS_X_VERSION_MIN_REQUIRED >= MAC_OS_X_VERSION_10_12 + UTType* uttype = [UTType typeWithFilenameExtension:filter]; + if (uttype) { + [types addObject:uttype]; + } +#else + [types addObject:filter]; +#endif } return types; } @@ -673,7 +687,11 @@ cc_result Window_SaveFileDialog(const struct SaveFileDialogArgs* args) { // TODO: Use args->defaultName, but only macOS 10.6 NSMutableArray* types = GetOpenSaveFilters(args->filters); - [dlg setAllowedFileTypes:types]; +#if defined MAC_OS_X_VERSION_10_12 && MAC_OS_X_VERSION_MIN_REQUIRED >= MAC_OS_X_VERSION_10_12 + [dlg setAllowedContentTypes:types]; +#else + [dlg setAllowedFileTypes:types]; +#endif if ([dlg runModal] != DIALOG_OK) return 0; NSURL* file = [dlg URL]; @@ -686,7 +704,12 @@ cc_result Window_OpenFileDialog(const struct OpenFileDialogArgs* args) { NSMutableArray* types = GetOpenSaveFilters(args->filters); [dlg setCanChooseFiles: YES]; - if ([dlg runModalForTypes:types] != DIALOG_OK) return 0; +#if defined MAC_OS_X_VERSION_10_12 && MAC_OS_X_VERSION_MIN_REQUIRED >= MAC_OS_X_VERSION_10_12 + [dlg setAllowedContentTypes:types]; + if ([dlg runModal] != DIALOG_OK) return 0; +#else + if ([dlg runModalForTypes:types] != DIALOG_OK) return 0; +#endif // unfortunately below code doesn't work when linked against SDK < 10.6 // https://developer.apple.com/documentation/appkit/nssavepanel/1534419-allowedfiletypes // [dlg setAllowedFileTypes:types]; @@ -727,7 +750,11 @@ static void DoDrawFramebuffer(NSRect dirty) { // TODO: Find a better way of doing this in cocoa.. if (!fb_bmp.scan0) return; nsContext = [NSGraphicsContext currentContext]; +#if defined MAC_OS_X_VERSION_10_12 && MAC_OS_X_VERSION_MIN_REQUIRED >= MAC_OS_X_VERSION_10_12 + context = [nsContext CGContext]; +#else context = [nsContext graphicsPort]; +#endif // TODO: Only update changed bit.. rect.origin.x = 0; rect.origin.y = 0; @@ -785,6 +812,9 @@ static int SupportsModernFullscreen(void) { return [winHandle respondsToSelector:@selector(toggleFullScreen:)]; } +#pragma clang diagnostic push +#pragma clang diagnostic ignored "-Wdeprecated-declarations" + static NSOpenGLPixelFormat* MakePixelFormat(cc_bool fullscreen) { // TODO: Is there a penalty for fullscreen contexts in 10.7 and later? // Need to test whether there is a performance penalty or not @@ -968,5 +998,8 @@ cc_result Window_ExitFullscreen(void) { Event_RaiseVoid(&WindowEvents.Resized); return 0; } + +#pragma clang diagnostic pop + #endif #endif diff --git a/src/freetype/ftmac.c b/src/freetype/ftmac.c index 0f2f0c3e3..4549a5df1 100644 --- a/src/freetype/ftmac.c +++ b/src/freetype/ftmac.c @@ -1,3 +1,4 @@ +#pragma GCC diagnostic ignored "-Wdeprecated-declarations" /***************************************************************************/ /* */ /* ftmac.c */ From 1aa1b3588f8da77613182d72b37abb10c056bd98 Mon Sep 17 00:00:00 2001 From: JoeyShapiro Date: Sat, 25 Jan 2025 16:58:53 -0600 Subject: [PATCH 2/3] added proper versions for deprecations --- src/Window_cocoa.m | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/src/Window_cocoa.m b/src/Window_cocoa.m index 670eae992..dad8d8253 100644 --- a/src/Window_cocoa.m +++ b/src/Window_cocoa.m @@ -750,7 +750,7 @@ static void DoDrawFramebuffer(NSRect dirty) { // TODO: Find a better way of doing this in cocoa.. if (!fb_bmp.scan0) return; nsContext = [NSGraphicsContext currentContext]; -#if defined MAC_OS_X_VERSION_10_12 && MAC_OS_X_VERSION_MIN_REQUIRED >= MAC_OS_X_VERSION_10_12 +#if defined MAC_OS_X_VERSION_10_14 && MAC_OS_X_VERSION_MIN_REQUIRED >= MAC_OS_X_VERSION_10_14 context = [nsContext CGContext]; #else context = [nsContext graphicsPort]; @@ -812,8 +812,10 @@ static int SupportsModernFullscreen(void) { return [winHandle respondsToSelector:@selector(toggleFullScreen:)]; } +#if defined MAC_OS_X_VERSION_10_14 && MAC_OS_X_VERSION_MIN_REQUIRED >= MAC_OS_X_VERSION_10_14 #pragma clang diagnostic push #pragma clang diagnostic ignored "-Wdeprecated-declarations" +#endif static NSOpenGLPixelFormat* MakePixelFormat(cc_bool fullscreen) { // TODO: Is there a penalty for fullscreen contexts in 10.7 and later? @@ -999,7 +1001,9 @@ cc_result Window_ExitFullscreen(void) { return 0; } +#if defined MAC_OS_X_VERSION_10_14 && MAC_OS_X_VERSION_MIN_REQUIRED >= MAC_OS_X_VERSION_10_14 #pragma clang diagnostic pop +#endif #endif #endif From 74530f813600bba840afd0a52d15118af340358c Mon Sep 17 00:00:00 2001 From: JoeyShapiro Date: Wed, 29 Jan 2025 10:32:30 -0600 Subject: [PATCH 3/3] use ifdef for CCWindowDelegate Template --- src/Window_cocoa.m | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/src/Window_cocoa.m b/src/Window_cocoa.m index dad8d8253..447d07633 100644 --- a/src/Window_cocoa.m +++ b/src/Window_cocoa.m @@ -261,7 +261,11 @@ static void RefreshWindowBounds(void) { - (void)keyDown:(NSEvent *)event { } @end +#if defined MAC_OS_X_VERSION_10_12 && MAC_OS_X_VERSION_MIN_REQUIRED >= MAC_OS_X_VERSION_10_12 @interface CCWindowDelegate : NSObject { } +#else +@interface CCWindowDelegate : NSObject { } +#endif @end @implementation CCWindowDelegate - (void)windowDidResize:(NSNotification *)notification {