From 9a9568212c2dfd17fe46845eaa68ec0731de6173 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Camilla=20L=C3=B6wy?= Date: Thu, 3 Jan 2019 19:32:45 +0100 Subject: [PATCH] Cocoa: Move slightly towards modern Objective-C --- README.md | 2 +- src/cocoa_monitor.m | 10 +++------- src/cocoa_window.m | 18 ++++++++---------- 3 files changed, 12 insertions(+), 18 deletions(-) diff --git a/README.md b/README.md index 44216559..80059c95 100644 --- a/README.md +++ b/README.md @@ -75,7 +75,7 @@ more information. ## System requirements -GLFW supports Windows XP and later and macOS 10.7 and later. Linux and other +GLFW supports Windows XP and later and macOS 10.8 and later. Linux and other Unix-like systems running the X Window System are supported even without a desktop environment or modern extensions, although some features require a running window or clipboard manager. The OSMesa backend requires Mesa 6.3. diff --git a/src/cocoa_monitor.m b/src/cocoa_monitor.m index 39fff6f7..955d52d1 100644 --- a/src/cocoa_monitor.m +++ b/src/cocoa_monitor.m @@ -374,14 +374,10 @@ void _glfwPlatformGetMonitorContentScale(_GLFWmonitor* monitor, { if (!monitor->ns.screen) { - NSUInteger i; - NSArray* screens = [NSScreen screens]; - - for (i = 0; i < [screens count]; i++) + for (NSScreen* screen in [NSScreen screens]) { - NSScreen* screen = [screens objectAtIndex:i]; NSNumber* displayID = - [[screen deviceDescription] objectForKey:@"NSScreenNumber"]; + [screen deviceDescription][@"NSScreenNumber"]; // HACK: Compare unit numbers instead of display IDs to work around // display replacement on machines with automatic graphics @@ -394,7 +390,7 @@ void _glfwPlatformGetMonitorContentScale(_GLFWmonitor* monitor, } } - if (i == [screens count]) + if (!monitor->ns.screen) { _glfwInputError(GLFW_PLATFORM_ERROR, "Cocoa: Failed to find a screen for monitor"); diff --git a/src/cocoa_window.m b/src/cocoa_window.m index db9935ce..92b110dd 100644 --- a/src/cocoa_window.m +++ b/src/cocoa_window.m @@ -737,7 +737,7 @@ static const NSRange kEmptyRange = { NSNotFound, 0 }; char** paths = calloc(count, sizeof(char*)); for (NSUInteger i = 0; i < count; i++) - paths[i] = _glfw_strdup([[urls objectAtIndex:i] fileSystemRepresentation]); + paths[i] = _glfw_strdup([urls[i] fileSystemRepresentation]); _glfwInputDrop(window, (int) count, (const char**) paths); @@ -883,7 +883,7 @@ static void createMenuBar(void) for (i = 0; i < sizeof(nameKeys) / sizeof(nameKeys[0]); i++) { - id name = [bundleInfo objectForKey:nameKeys[i]]; + id name = bundleInfo[nameKeys[i]]; if (name && [name isKindOfClass:[NSString class]] && ![name isEqualToString:@""]) @@ -897,7 +897,7 @@ static void createMenuBar(void) { char** progname = _NSGetProgname(); if (progname && *progname) - appName = [NSString stringWithUTF8String:*progname]; + appName = @(*progname); else appName = @"GLFW Application"; } @@ -1084,7 +1084,7 @@ static GLFWbool createNativeWindow(_GLFWwindow* window, } if (strlen(wndconfig->ns.frameName)) - [window->ns.object setFrameAutosaveName:[NSString stringWithUTF8String:wndconfig->ns.frameName]]; + [window->ns.object setFrameAutosaveName:@(wndconfig->ns.frameName)]; window->ns.view = [[GLFWContentView alloc] initWithGlfwWindow:window]; @@ -1099,7 +1099,7 @@ static GLFWbool createNativeWindow(_GLFWwindow* window, [window->ns.object setContentView:window->ns.view]; [window->ns.object makeFirstResponder:window->ns.view]; - [window->ns.object setTitle:[NSString stringWithUTF8String:wndconfig->title]]; + [window->ns.object setTitle:@(wndconfig->title)]; [window->ns.object setDelegate:window->ns.delegate]; [window->ns.object setAcceptsMouseMovedEvents:YES]; [window->ns.object setRestorable:NO]; @@ -1190,11 +1190,10 @@ void _glfwPlatformDestroyWindow(_GLFWwindow* window) void _glfwPlatformSetWindowTitle(_GLFWwindow* window, const char *title) { - NSString* string = [NSString stringWithUTF8String:title]; - [window->ns.object setTitle:string]; + [window->ns.object setTitle:@(title)]; // HACK: Set the miniwindow title explicitly as setTitle: doesn't update it // if the window lacks NSWindowStyleMaskTitled - [window->ns.object setMiniwindowTitle:string]; + [window->ns.object setMiniwindowTitle:@(title)]; } void _glfwPlatformSetWindowIcon(_GLFWwindow* window, @@ -1737,8 +1736,7 @@ void _glfwPlatformSetClipboardString(const char* string) { NSPasteboard* pasteboard = [NSPasteboard generalPasteboard]; [pasteboard declareTypes:@[NSPasteboardTypeString] owner:nil]; - [pasteboard setString:[NSString stringWithUTF8String:string] - forType:NSPasteboardTypeString]; + [pasteboard setString:@(string) forType:NSPasteboardTypeString]; } const char* _glfwPlatformGetClipboardString(void)