From 6dfc12a43906ad4acf669499e2a25761318a1fb0 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Camilla=20L=C3=B6wy?= Date: Fri, 26 Oct 2018 12:56:02 +0200 Subject: [PATCH] Cocoa: Fix some macOS 10.14 deprecation warnings --- src/cocoa_window.m | 20 ++++++++++++-------- src/nsgl_context.m | 9 +++++++-- 2 files changed, 19 insertions(+), 10 deletions(-) diff --git a/src/cocoa_window.m b/src/cocoa_window.m index 7cf4a593..308b5d84 100644 --- a/src/cocoa_window.m +++ b/src/cocoa_window.m @@ -32,7 +32,6 @@ // Needed for _NSGetProgname #include -// HACK: The 10.12 SDK adds new symbols and immediately deprecates the old ones #if MAC_OS_X_VERSION_MAX_ALLOWED < 101200 #define NSWindowStyleMaskBorderless NSBorderlessWindowMask #define NSWindowStyleMaskClosable NSClosableWindowMask @@ -48,8 +47,13 @@ #define NSEventMaskAny NSAnyEventMask #define NSEventTypeApplicationDefined NSApplicationDefined #define NSEventTypeKeyUp NSKeyUp + #define NSBitmapFormatAlphaNonpremultiplied NSAlphaNonpremultipliedBitmapFormat #endif +#if MAC_OS_X_VERSION_MAX_ALLOWED < 101300 + #define NSPasteboardTypeFileURL NSFilenamesPboardType + #define NSPasteboardTypeString NSStringPboardType +#endif // Returns the style mask corresponding to the window settings // @@ -439,7 +443,7 @@ static const NSRange kEmptyRange = { NSNotFound, 0 }; [self updateTrackingAreas]; [self registerForDraggedTypes:[NSArray arrayWithObjects: - NSFilenamesPboardType, nil]]; + NSPasteboardTypeFileURL, nil]]; } return self; @@ -720,7 +724,7 @@ static const NSRange kEmptyRange = { NSNotFound, 0 }; - (BOOL)performDragOperation:(id )sender { NSPasteboard* pasteboard = [sender draggingPasteboard]; - NSArray* files = [pasteboard propertyListForType:NSFilenamesPboardType]; + NSArray* files = [pasteboard propertyListForType:NSPasteboardTypeFileURL]; const NSRect contentRect = [window->ns.view frame]; _glfwInputCursorPos(window, @@ -1728,7 +1732,7 @@ int _glfwPlatformCreateCursor(_GLFWcursor* cursor, hasAlpha:YES isPlanar:NO colorSpaceName:NSCalibratedRGBColorSpace - bitmapFormat:NSAlphaNonpremultipliedBitmapFormat + bitmapFormat:NSBitmapFormatAlphaNonpremultiplied bytesPerRow:image->width * 4 bitsPerPixel:32]; @@ -1795,26 +1799,26 @@ void _glfwPlatformSetCursor(_GLFWwindow* window, _GLFWcursor* cursor) void _glfwPlatformSetClipboardString(const char* string) { - NSArray* types = [NSArray arrayWithObjects:NSStringPboardType, nil]; + NSArray* types = [NSArray arrayWithObjects:NSPasteboardTypeString, nil]; NSPasteboard* pasteboard = [NSPasteboard generalPasteboard]; [pasteboard declareTypes:types owner:nil]; [pasteboard setString:[NSString stringWithUTF8String:string] - forType:NSStringPboardType]; + forType:NSPasteboardTypeString]; } const char* _glfwPlatformGetClipboardString(void) { NSPasteboard* pasteboard = [NSPasteboard generalPasteboard]; - if (![[pasteboard types] containsObject:NSStringPboardType]) + if (![[pasteboard types] containsObject:NSPasteboardTypeString]) { _glfwInputError(GLFW_FORMAT_UNAVAILABLE, "Cocoa: Failed to retrieve string from pasteboard"); return NULL; } - NSString* object = [pasteboard stringForType:NSStringPboardType]; + NSString* object = [pasteboard stringForType:NSPasteboardTypeString]; if (!object) { _glfwInputError(GLFW_PLATFORM_ERROR, diff --git a/src/nsgl_context.m b/src/nsgl_context.m index 82af9063..ec1012e9 100644 --- a/src/nsgl_context.m +++ b/src/nsgl_context.m @@ -26,6 +26,10 @@ #include "internal.h" +#if MAC_OS_X_VERSION_MAX_ALLOWED < 101400 + #define NSOpenGLContextParameterSwapInterval NSOpenGLCPSwapInterval + #define NSOpenGLContextParameterSurfaceOpacity NSOpenGLCPSurfaceOpacity +#endif static void makeContextCurrentNSGL(_GLFWwindow* window) { @@ -49,7 +53,7 @@ static void swapIntervalNSGL(int interval) GLint sync = interval; [window->context.nsgl.object setValues:&sync - forParameter:NSOpenGLCPSwapInterval]; + forParameter:NSOpenGLContextParameterSwapInterval]; } static int extensionSupportedNSGL(const char* extension) @@ -299,7 +303,8 @@ GLFWbool _glfwCreateContextNSGL(_GLFWwindow* window, if (fbconfig->transparent) { GLint opaque = 0; - [window->context.nsgl.object setValues:&opaque forParameter:NSOpenGLCPSurfaceOpacity]; + [window->context.nsgl.object setValues:&opaque + forParameter:NSOpenGLContextParameterSurfaceOpacity]; } [window->context.nsgl.object setView:window->ns.view];