diff options
author | RĂ©mi Verschelde <remi@verschelde.fr> | 2020-12-23 17:37:42 +0100 |
---|---|---|
committer | GitHub <noreply@github.com> | 2020-12-23 17:37:42 +0100 |
commit | 719e4b115693aa51f53e64ae6ac66ee42741a89c (patch) | |
tree | b294bbdbb24abc2705ce4243796e3d36f88747e2 | |
parent | 35a8ebaa1027545b62b015b44bfc00bd02e165b9 (diff) | |
parent | 39bcc77d6a212ebf0f2cb9691016bc6c0e7e1cc9 (diff) |
Merge pull request #44619 from bruvzg/m1_dragdrop_4
[4.0] Fix file drag-drop on M1 Macs.
-rw-r--r-- | platform/osx/display_server_osx.mm | 38 |
1 files changed, 21 insertions, 17 deletions
diff --git a/platform/osx/display_server_osx.mm b/platform/osx/display_server_osx.mm index c4c2426f1f..8d82119ae2 100644 --- a/platform/osx/display_server_osx.mm +++ b/platform/osx/display_server_osx.mm @@ -751,28 +751,32 @@ static const NSRange kEmptyRange = { NSNotFound, 0 }; ERR_FAIL_COND_V(!DS_OSX->windows.has(window_id), NO); DisplayServerOSX::WindowData &wd = DS_OSX->windows[window_id]; - NSPasteboard *pboard = [sender draggingPasteboard]; -#if MAC_OS_X_VERSION_MIN_REQUIRED >= 101400 - NSArray<NSURL *> *filenames = [pboard propertyListForType:NSPasteboardTypeFileURL]; -#else - NSArray *filenames = [pboard propertyListForType:NSFilenamesPboardType]; -#endif + if (!wd.drop_files_callback.is_null()) { + Vector<String> files; + NSPasteboard *pboard = [sender draggingPasteboard]; - Vector<String> files; - for (NSUInteger i = 0; i < filenames.count; i++) { #if MAC_OS_X_VERSION_MIN_REQUIRED >= 101400 - NSString *ns = [[filenames objectAtIndex:i] path]; + NSArray *items = pboard.pasteboardItems; + for (NSPasteboardItem *item in items) { + NSString *path = [item stringForType:NSPasteboardTypeFileURL]; + NSString *ns = [NSURL URLWithString:path].path; + char *utfs = strdup([ns UTF8String]); + String ret; + ret.parse_utf8(utfs); + free(utfs); + files.push_back(ret); + } #else - NSString *ns = [filenames objectAtIndex:i]; + NSArray *filenames = [pboard propertyListForType:NSFilenamesPboardType]; + for (NSString *ns in filenames) { + char *utfs = strdup([ns UTF8String]); + String ret; + ret.parse_utf8(utfs); + free(utfs); + files.push_back(ret); + } #endif - char *utfs = strdup([ns UTF8String]); - String ret; - ret.parse_utf8(utfs); - free(utfs); - files.push_back(ret); - } - if (!wd.drop_files_callback.is_null()) { Variant v = files; Variant *vp = &v; Variant ret; |