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.
This commit is contained in:
Luflosi 2019-06-21 15:50:20 +02:00
parent 6c478977bb
commit 8ffc841a3a
No known key found for this signature in database
GPG Key ID: 14140F703B7D8362
4 changed files with 34 additions and 22 deletions

View File

@ -307,6 +307,7 @@ static bool initializeTIS(void)
} }
@end @end
////////////////////////////////////////////////////////////////////////// //////////////////////////////////////////////////////////////////////////
////// GLFW platform API ////// ////// GLFW platform API //////
////////////////////////////////////////////////////////////////////////// //////////////////////////////////////////////////////////////////////////
@ -332,6 +333,7 @@ is_cmd_period(NSEvent *event, NSEventModifierFlags modifierFlags) {
int _glfwPlatformInit(void) int _glfwPlatformInit(void)
{ {
@autoreleasepool { @autoreleasepool {
_glfw.ns.helper = [[GLFWHelper alloc] init]; _glfw.ns.helper = [[GLFWHelper alloc] init];
[NSThread detachNewThreadSelector:@selector(doNothing:) [NSThread detachNewThreadSelector:@selector(doNothing:)
@ -374,6 +376,7 @@ int _glfwPlatformInit(void)
_glfw.ns.keyDownMonitor = _glfw.ns.keyDownMonitor =
[NSEvent addLocalMonitorForEventsMatchingMask:NSEventMaskKeyDown [NSEvent addLocalMonitorForEventsMatchingMask:NSEventMaskKeyDown
handler:keydown_block]; handler:keydown_block];
if (_glfw.hints.init.ns.chdir) if (_glfw.hints.init.ns.chdir)
changeToResourcesDirectory(); changeToResourcesDirectory();
@ -399,8 +402,9 @@ int _glfwPlatformInit(void)
_glfwInitJoysticksNS(); _glfwInitJoysticksNS();
_glfwPollMonitorsNS(); _glfwPollMonitorsNS();
}
return true; return true;
} // autoreleasepool
} }
void _glfwPlatformTerminate(void) void _glfwPlatformTerminate(void)
@ -444,6 +448,7 @@ void _glfwPlatformTerminate(void)
[_glfw.ns.helper release]; [_glfw.ns.helper release];
_glfw.ns.helper = nil; _glfw.ns.helper = nil;
} }
if (_glfw.ns.keyUpMonitor) if (_glfw.ns.keyUpMonitor)
[NSEvent removeMonitor:_glfw.ns.keyUpMonitor]; [NSEvent removeMonitor:_glfw.ns.keyUpMonitor];
if (_glfw.ns.keyDownMonitor) if (_glfw.ns.keyDownMonitor)
@ -453,7 +458,8 @@ void _glfwPlatformTerminate(void)
_glfwTerminateNSGL(); _glfwTerminateNSGL();
_glfwTerminateJoysticksNS(); _glfwTerminateJoysticksNS();
}
} // autoreleasepool
} }
const char* _glfwPlatformGetVersionString(void) const char* _glfwPlatformGetVersionString(void)

View File

@ -468,7 +468,9 @@ void _glfwPlatformGetMonitorContentScale(_GLFWmonitor* monitor,
*yscale = (float) (pixels.size.height / points.size.height); *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)) if (!refreshMonitorScreen(monitor))
return; return;

View File

@ -222,7 +222,9 @@ void _glfwInitTimerNS(void);
void _glfwPollMonitorsNS(void); void _glfwPollMonitorsNS(void);
void _glfwSetVideoModeNS(_GLFWmonitor* monitor, const GLFWvidmode* desired); void _glfwSetVideoModeNS(_GLFWmonitor* monitor, const GLFWvidmode* desired);
void _glfwRestoreVideoModeNS(_GLFWmonitor* monitor); void _glfwRestoreVideoModeNS(_GLFWmonitor* monitor);
float _glfwTransformYNS(float y); float _glfwTransformYNS(float y);
void _glfwClearDisplayLinks(void); void _glfwClearDisplayLinks(void);
void _glfwRestartDisplayLinks(void); void _glfwRestartDisplayLinks(void);
void _glfwCocoaPostEmptyEvent(short subtype, long data1, bool at_start); void _glfwCocoaPostEmptyEvent(short subtype, long data1, bool at_start);

View File

@ -1021,19 +1021,19 @@ is_ascii_control_char(char x) {
// NOTE: The returned location uses base 0,1 not 0,0 // NOTE: The returned location uses base 0,1 not 0,0
const NSPoint pos = [sender draggingLocation]; const NSPoint pos = [sender draggingLocation];
_glfwInputCursorPos(window, pos.x, contentRect.size.height - pos.y); _glfwInputCursorPos(window, pos.x, contentRect.size.height - pos.y);
NSPasteboard* pasteboard = [sender draggingPasteboard]; NSPasteboard* pasteboard = [sender draggingPasteboard];
NSDictionary* options = @{NSPasteboardURLReadingFileURLsOnlyKey:@YES}; NSDictionary* options = @{NSPasteboardURLReadingFileURLsOnlyKey:@YES};
NSArray* urls = [pasteboard readObjectsForClasses:@[[NSURL class]] NSArray* urls = [pasteboard readObjectsForClasses:@[[NSURL class]]
options:options]; options:options];
if (!urls) return NO; if (!urls) return NO;
const NSUInteger count = [urls count]; const NSUInteger count = [urls count];
if (count) if (count)
{ {
char** paths = calloc(count, sizeof(char*)); char** paths = calloc(count, sizeof(char*));
for (NSUInteger i = 0; i < count; i++) 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); _glfwInputDrop(window, (int) count, (const char**) paths);
@ -1213,7 +1213,7 @@ static void createMenuBar(void)
{ {
char** progname = _NSGetProgname(); char** progname = _NSGetProgname();
if (progname && *progname) if (progname && *progname)
appName = [NSString stringWithUTF8String:*progname]; appName = @(*progname);
else else
appName = @"GLFW Application"; appName = @"GLFW Application";
} }
@ -1393,10 +1393,9 @@ static bool createNativeWindow(_GLFWwindow* window,
} }
if (strlen(wndconfig->ns.frameName)) 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.view = [[GLFWContentView alloc] initWithGlfwWindow:window];
window->ns.retina = wndconfig->ns.retina; window->ns.retina = wndconfig->ns.retina;
if (fbconfig->transparent) if (fbconfig->transparent)
@ -1408,7 +1407,7 @@ static bool createNativeWindow(_GLFWwindow* window,
[window->ns.object setContentView:window->ns.view]; [window->ns.object setContentView:window->ns.view];
[window->ns.object makeFirstResponder: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 setDelegate:window->ns.delegate];
[window->ns.object setAcceptsMouseMovedEvents:YES]; [window->ns.object setAcceptsMouseMovedEvents:YES];
[window->ns.object setRestorable:NO]; [window->ns.object setRestorable:NO];
@ -1497,7 +1496,7 @@ void _glfwPlatformDestroyWindow(_GLFWwindow* window)
void _glfwPlatformSetWindowTitle(_GLFWwindow* window, const char *title) void _glfwPlatformSetWindowTitle(_GLFWwindow* window, const char *title)
{ {
NSString* string = [NSString stringWithUTF8String:title]; NSString* string = @(title);
[window->ns.object setTitle:string]; [window->ns.object setTitle:string];
// HACK: Set the miniwindow title explicitly as setTitle: doesn't update it // HACK: Set the miniwindow title explicitly as setTitle: doesn't update it
// if the window lacks NSWindowStyleMaskTitled // if the window lacks NSWindowStyleMaskTitled
@ -1663,11 +1662,10 @@ int _glfwPlatformWindowBell(_GLFWwindow* window)
void _glfwPlatformFocusWindow(_GLFWwindow* window) void _glfwPlatformFocusWindow(_GLFWwindow* window)
{ {
// Make us the active application // Make us the active application
// HACK: This has been moved here from initializeAppKit to prevent // HACK: This is here to prevent applications using only hidden windows from
// applications using only hidden windows from being activated, but // being activated, but should probably not be done every time any
// should probably not be done every time any window is shown // window is shown
[NSApp activateIgnoringOtherApps:YES]; [NSApp activateIgnoringOtherApps:YES];
[window->ns.object makeKeyAndOrderFront:nil]; [window->ns.object makeKeyAndOrderFront:nil];
} }
@ -1844,6 +1842,7 @@ _glfwDispatchRenderFrame(CGDirectDisplayID displayID) {
void _glfwCocoaPostEmptyEvent(short subtype, long data1, bool at_start) void _glfwCocoaPostEmptyEvent(short subtype, long data1, bool at_start)
{ {
@autoreleasepool { @autoreleasepool {
NSEvent* event = [NSEvent otherEventWithType:NSEventTypeApplicationDefined NSEvent* event = [NSEvent otherEventWithType:NSEventTypeApplicationDefined
location:NSMakePoint(0, 0) location:NSMakePoint(0, 0)
modifierFlags:0 modifierFlags:0
@ -1854,7 +1853,8 @@ void _glfwCocoaPostEmptyEvent(short subtype, long data1, bool at_start)
data1:data1 data1:data1
data2:0]; data2:0];
[NSApp postEvent:event atStart:at_start ? YES : NO]; [NSApp postEvent:event atStart:at_start ? YES : NO];
}
} // autoreleasepool
} }
void _glfwPlatformPostEmptyEvent(void) void _glfwPlatformPostEmptyEvent(void)
@ -1974,6 +1974,7 @@ int _glfwPlatformCreateCursor(_GLFWcursor* cursor,
cursor->ns.object = [[NSCursor alloc] initWithImage:native cursor->ns.object = [[NSCursor alloc] initWithImage:native
hotSpot:NSMakePoint(xhot, yhot)]; hotSpot:NSMakePoint(xhot, yhot)];
[native release]; [native release];
if (cursor->ns.object == nil) if (cursor->ns.object == nil)
return false; return false;
@ -2051,8 +2052,7 @@ void _glfwPlatformSetClipboardString(const char* string)
{ {
NSPasteboard* pasteboard = [NSPasteboard generalPasteboard]; NSPasteboard* pasteboard = [NSPasteboard generalPasteboard];
[pasteboard declareTypes:@[NSPasteboardTypeString] owner:nil]; [pasteboard declareTypes:@[NSPasteboardTypeString] owner:nil];
[pasteboard setString:[NSString stringWithUTF8String:string] [pasteboard setString:@(string) forType:NSPasteboardTypeString];
forType:NSPasteboardTypeString];
} }
const char* _glfwPlatformGetClipboardString(void) const char* _glfwPlatformGetClipboardString(void)
@ -2136,6 +2136,7 @@ VkResult _glfwPlatformCreateWindowSurface(VkInstance instance,
if (window->ns.retina) if (window->ns.retina)
[window->ns.layer setContentsScale:[window->ns.object backingScaleFactor]]; [window->ns.layer setContentsScale:[window->ns.object backingScaleFactor]];
[window->ns.view setLayer:window->ns.layer]; [window->ns.view setLayer:window->ns.layer];
[window->ns.view setWantsLayer:YES]; [window->ns.view setWantsLayer:YES];
@ -2290,6 +2291,7 @@ GLFWAPI void glfwGetCocoaKeyEquivalent(int glfw_key, int glfw_mods, unsigned sho
} }
} }
////////////////////////////////////////////////////////////////////////// //////////////////////////////////////////////////////////////////////////
////// GLFW internal API ////// ////// GLFW internal API //////
////////////////////////////////////////////////////////////////////////// //////////////////////////////////////////////////////////////////////////