From c493583f256b66603bb7e20e2355f8958d85036b Mon Sep 17 00:00:00 2001 From: Kovid Goyal Date: Thu, 11 Oct 2018 18:36:24 +0530 Subject: [PATCH] macOS: Fix drag and drop of files not working on mojave Fixes #1058 --- docs/changelog.rst | 2 ++ glfw/cocoa_window.m | 17 ++++++++++++----- 2 files changed, 14 insertions(+), 5 deletions(-) diff --git a/docs/changelog.rst b/docs/changelog.rst index b7b588704..0a918a611 100644 --- a/docs/changelog.rst +++ b/docs/changelog.rst @@ -15,6 +15,8 @@ Changelog - Fix incorrect key repeat rate on wayland (:pull:`1055`) +- macOS: Fix drag and drop of files not working on mojave (:iss:`1058`) + 0.12.3 [2018-09-29] ------------------------------ diff --git a/glfw/cocoa_window.m b/glfw/cocoa_window.m index e14665245..2531308db 100644 --- a/glfw/cocoa_window.m +++ b/glfw/cocoa_window.m @@ -917,17 +917,24 @@ is_ascii_control_char(char x) { return YES; } +- (NSArray *)fileURLWithDraggingInfo:(id )sender +{ + NSPasteboard *pasteboard = [sender draggingPasteboard]; + NSDictionary *options = [NSDictionary dictionaryWithObject:@YES forKey:NSPasteboardURLReadingFileURLsOnlyKey]; + NSArray *results = [pasteboard readObjectsForClasses:[NSArray arrayWithObject:[NSURL class]] options:options]; + return results; +} + - (BOOL)performDragOperation:(id )sender { - NSPasteboard* pasteboard = [sender draggingPasteboard]; - NSArray* files = [pasteboard propertyListForType:NSPasteboardTypeFileURL]; - const NSRect contentRect = [window->ns.view frame]; _glfwInputCursorPos(window, [sender draggingLocation].x, contentRect.size.height - [sender draggingLocation].y); - + const NSArray* files = [self fileURLWithDraggingInfo:sender]; + if (!files) return NO; const NSUInteger count = [files count]; + if (count) { NSEnumerator* e = [files objectEnumerator]; @@ -935,7 +942,7 @@ is_ascii_control_char(char x) { NSUInteger i; for (i = 0; i < count; i++) - paths[i] = _glfw_strdup([[e nextObject] UTF8String]); + paths[i] = _glfw_strdup([[[e nextObject] path] UTF8String]); _glfwInputDrop(window, (int) count, (const char**) paths);