Skip to content

Commit

Permalink
Fixed bug 5449 - SDL_DROPFILE update mouse location of drop in Cocoa
Browse files Browse the repository at this point in the history
Dominik Reichardt

Exult (http://exult.info) has an editor app that uses GTK+2. Up to now we were using X's drag'n'drop to allow dropping of assets from the editor onto Exult.
There is now an experimental branch that makes use of SDL_DROPFILE. That works under X, dropping in Exult's SDL2 window puts the asset right at the spot you dropped at.
On macOS with native Exult and Quartz GTK+2 this doesn't work, the location of the drop is where the mouse was last tracked before you left the window (usually one of the edges, unless you tabbed out).
All we tried out pointed to the fact that the location update needs to be done by the dropfile event in SDL2, not by our own (which always only worked after the Exult window getting focus).

This patch adds this to SDL_cocoawindow.m and it works perfectly, passing the correct coordinates to our code (SDL_GetMouseState()).
  • Loading branch information
slouken committed Jan 7, 2021
1 parent c8a64ad commit e778881
Showing 1 changed file with 10 additions and 0 deletions.
10 changes: 10 additions & 0 deletions src/video/cocoa/SDL_cocoawindow.m
Expand Up @@ -161,6 +161,16 @@ - (BOOL)performDragOperation:(id <NSDraggingInfo>)sender
SDL_assert([desiredType isEqualToString:NSFilenamesPboardType]);
NSArray *array = [pasteboard propertyListForType:@"NSFilenamesPboardType"];

/* Code addon to update the mouse location */
NSPoint point = [sender draggingLocation];
SDL_Mouse *mouse = SDL_GetMouse();
int x = (int)point.x;
int y = (int)(sdlwindow->h - point.y);
if (x >= 0 && x < sdlwindow->w && y >= 0 && y < sdlwindow->h) {
SDL_SendMouseMotion(sdlwindow, mouse->mouseID, 0, x, y);
}
/* Code addon to update the mouse location */

for (NSString *path in array) {
NSURL *fileURL = [NSURL fileURLWithPath:path];
NSNumber *isAlias = nil;
Expand Down

0 comments on commit e778881

Please sign in to comment.