From 8ffc841a3ae0309ab06d2abfa78d9a3854a7d332 Mon Sep 17 00:00:00 2001 From: Luflosi Date: Fri, 21 Jun 2019 15:50:20 +0200 Subject: [PATCH] Reduce the difference of glfw/cocoa_* to upstream This only changes some formatting, whitespace, etc.. There are no changes to the functionality. Let me know if you don't like some of those changes. --- glfw/cocoa_init.m | 12 +++++++++--- glfw/cocoa_monitor.m | 4 +++- glfw/cocoa_platform.h | 8 +++++--- glfw/cocoa_window.m | 32 +++++++++++++++++--------------- 4 files changed, 34 insertions(+), 22 deletions(-) diff --git a/glfw/cocoa_init.m b/glfw/cocoa_init.m index 4a2e92090..d2537a40b 100644 --- a/glfw/cocoa_init.m +++ b/glfw/cocoa_init.m @@ -287,7 +287,7 @@ static bool initializeTIS(void) { } -@end // GLFWHelper +@end // GLFWHelper @interface GLFWApplication : NSApplication - (void)tick_callback; @@ -307,6 +307,7 @@ static bool initializeTIS(void) } @end + ////////////////////////////////////////////////////////////////////////// ////// GLFW platform API ////// ////////////////////////////////////////////////////////////////////////// @@ -332,6 +333,7 @@ is_cmd_period(NSEvent *event, NSEventModifierFlags modifierFlags) { int _glfwPlatformInit(void) { @autoreleasepool { + _glfw.ns.helper = [[GLFWHelper alloc] init]; [NSThread detachNewThreadSelector:@selector(doNothing:) @@ -374,6 +376,7 @@ int _glfwPlatformInit(void) _glfw.ns.keyDownMonitor = [NSEvent addLocalMonitorForEventsMatchingMask:NSEventMaskKeyDown handler:keydown_block]; + if (_glfw.hints.init.ns.chdir) changeToResourcesDirectory(); @@ -399,8 +402,9 @@ int _glfwPlatformInit(void) _glfwInitJoysticksNS(); _glfwPollMonitorsNS(); - } return true; + + } // autoreleasepool } void _glfwPlatformTerminate(void) @@ -444,6 +448,7 @@ void _glfwPlatformTerminate(void) [_glfw.ns.helper release]; _glfw.ns.helper = nil; } + if (_glfw.ns.keyUpMonitor) [NSEvent removeMonitor:_glfw.ns.keyUpMonitor]; if (_glfw.ns.keyDownMonitor) @@ -453,7 +458,8 @@ void _glfwPlatformTerminate(void) _glfwTerminateNSGL(); _glfwTerminateJoysticksNS(); - } + + } // autoreleasepool } const char* _glfwPlatformGetVersionString(void) diff --git a/glfw/cocoa_monitor.m b/glfw/cocoa_monitor.m index d5967c51e..da1fe925d 100644 --- a/glfw/cocoa_monitor.m +++ b/glfw/cocoa_monitor.m @@ -468,7 +468,9 @@ void _glfwPlatformGetMonitorContentScale(_GLFWmonitor* monitor, *yscale = (float) (pixels.size.height / points.size.height); } -void _glfwPlatformGetMonitorWorkarea(_GLFWmonitor* monitor, int* xpos, int* ypos, int *width, int *height) +void _glfwPlatformGetMonitorWorkarea(_GLFWmonitor* monitor, + int* xpos, int* ypos, + int* width, int* height) { if (!refreshMonitorScreen(monitor)) return; diff --git a/glfw/cocoa_platform.h b/glfw/cocoa_platform.h index 15e500dc4..09ab98531 100644 --- a/glfw/cocoa_platform.h +++ b/glfw/cocoa_platform.h @@ -116,8 +116,8 @@ typedef struct _GLFWwindowNS id view; id layer; - bool maximized; - bool retina; + bool maximized; + bool retina; // Cached window properties to filter out duplicate events int width, height; @@ -154,7 +154,7 @@ typedef struct _GLFWlibraryNS { CGEventSourceRef eventSource; id delegate; - bool cursorHidden; + bool cursorHidden; TISInputSourceRef inputSource; IOHIDManagerRef hidManager; id unicodeData; @@ -222,7 +222,9 @@ void _glfwInitTimerNS(void); void _glfwPollMonitorsNS(void); void _glfwSetVideoModeNS(_GLFWmonitor* monitor, const GLFWvidmode* desired); void _glfwRestoreVideoModeNS(_GLFWmonitor* monitor); + float _glfwTransformYNS(float y); + void _glfwClearDisplayLinks(void); void _glfwRestartDisplayLinks(void); void _glfwCocoaPostEmptyEvent(short subtype, long data1, bool at_start); diff --git a/glfw/cocoa_window.m b/glfw/cocoa_window.m index 2fb322323..ac563b505 100644 --- a/glfw/cocoa_window.m +++ b/glfw/cocoa_window.m @@ -1011,7 +1011,7 @@ is_ascii_control_char(char x) { - (NSDragOperation)draggingEntered:(id )sender { // HACK: We don't know what to say here because we don't know what the - // application wants to do with the paths + // application wants to do with the paths return NSDragOperationGeneric; } @@ -1021,19 +1021,19 @@ is_ascii_control_char(char x) { // NOTE: The returned location uses base 0,1 not 0,0 const NSPoint pos = [sender draggingLocation]; _glfwInputCursorPos(window, pos.x, contentRect.size.height - pos.y); + NSPasteboard* pasteboard = [sender draggingPasteboard]; NSDictionary* options = @{NSPasteboardURLReadingFileURLsOnlyKey:@YES}; NSArray* urls = [pasteboard readObjectsForClasses:@[[NSURL class]] options:options]; if (!urls) return NO; const NSUInteger count = [urls count]; - if (count) { 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); @@ -1213,7 +1213,7 @@ static void createMenuBar(void) { char** progname = _NSGetProgname(); if (progname && *progname) - appName = [NSString stringWithUTF8String:*progname]; + appName = @(*progname); else appName = @"GLFW Application"; } @@ -1393,10 +1393,9 @@ static bool 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]; - window->ns.retina = wndconfig->ns.retina; if (fbconfig->transparent) @@ -1408,7 +1407,7 @@ static bool 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]; @@ -1497,7 +1496,7 @@ void _glfwPlatformDestroyWindow(_GLFWwindow* window) void _glfwPlatformSetWindowTitle(_GLFWwindow* window, const char *title) { - NSString* string = [NSString stringWithUTF8String:title]; + NSString* string = @(title); [window->ns.object setTitle:string]; // HACK: Set the miniwindow title explicitly as setTitle: doesn't update it // if the window lacks NSWindowStyleMaskTitled @@ -1663,11 +1662,10 @@ int _glfwPlatformWindowBell(_GLFWwindow* window) void _glfwPlatformFocusWindow(_GLFWwindow* window) { // Make us the active application - // HACK: This has been moved here from initializeAppKit to prevent - // applications using only hidden windows from being activated, but - // should probably not be done every time any window is shown + // HACK: This is here to prevent applications using only hidden windows from + // being activated, but should probably not be done every time any + // window is shown [NSApp activateIgnoringOtherApps:YES]; - [window->ns.object makeKeyAndOrderFront:nil]; } @@ -1844,6 +1842,7 @@ _glfwDispatchRenderFrame(CGDirectDisplayID displayID) { void _glfwCocoaPostEmptyEvent(short subtype, long data1, bool at_start) { @autoreleasepool { + NSEvent* event = [NSEvent otherEventWithType:NSEventTypeApplicationDefined location:NSMakePoint(0, 0) modifierFlags:0 @@ -1854,7 +1853,8 @@ void _glfwCocoaPostEmptyEvent(short subtype, long data1, bool at_start) data1:data1 data2:0]; [NSApp postEvent:event atStart:at_start ? YES : NO]; - } + + } // autoreleasepool } void _glfwPlatformPostEmptyEvent(void) @@ -1974,6 +1974,7 @@ int _glfwPlatformCreateCursor(_GLFWcursor* cursor, cursor->ns.object = [[NSCursor alloc] initWithImage:native hotSpot:NSMakePoint(xhot, yhot)]; + [native release]; if (cursor->ns.object == nil) return false; @@ -2051,8 +2052,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) @@ -2136,6 +2136,7 @@ VkResult _glfwPlatformCreateWindowSurface(VkInstance instance, if (window->ns.retina) [window->ns.layer setContentsScale:[window->ns.object backingScaleFactor]]; + [window->ns.view setLayer:window->ns.layer]; [window->ns.view setWantsLayer:YES]; @@ -2290,6 +2291,7 @@ GLFWAPI void glfwGetCocoaKeyEquivalent(int glfw_key, int glfw_mods, unsigned sho } } + ////////////////////////////////////////////////////////////////////////// ////// GLFW internal API ////// //////////////////////////////////////////////////////////////////////////