Skip to content

Commit

Permalink
Merge pull request #44620 from bruvzg/m1_dragdrop_3
Browse files Browse the repository at this point in the history
[3.2] Fix file drag-drop on M1 Macs.
  • Loading branch information
akien-mga authored Dec 23, 2020
2 parents ebe9d61 + 36a6a71 commit 7ef143f
Showing 1 changed file with 14 additions and 10 deletions.
24 changes: 14 additions & 10 deletions platform/osx/os_osx.mm
Original file line number Diff line number Diff line change
Expand Up @@ -638,26 +638,30 @@ - (NSDragOperation)draggingUpdated:(id<NSDraggingInfo>)sender {

- (BOOL)performDragOperation:(id<NSDraggingInfo>)sender {

Vector<String> files;
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

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];
#endif
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

if (files.size()) {
OS_OSX::singleton->main_loop->drop_files(files, 0);
Expand Down

0 comments on commit 7ef143f

Please sign in to comment.