From 47c3637acb42a2fcfed52f39857c29bd2f8f5e45 Mon Sep 17 00:00:00 2001 From: Zach Baylin Date: Wed, 6 May 2020 18:52:25 -0400 Subject: [PATCH 1/7] SDL_DragEvent: Add SDL_DragEvents These closely mirror the Drop events, specifically with BEGIN and COMPLETE. When dragging n files, 1 BEGIN, n FILE and 1 COMPLETE events are sent per mouse movement. --- src/events/SDL_dragevents.c | 64 ++++++++++++++++++++++++++++++ src/events/SDL_dragevents_c.h | 8 ++++ src/events/SDL_events_c.h | 1 + src/video/SDL_sysvideo.h | 5 ++- src/video/cocoa/SDL_cocoawindow.m | 66 +++++++++++++++++++++++++++---- 5 files changed, 135 insertions(+), 9 deletions(-) create mode 100644 src/events/SDL_dragevents.c create mode 100644 src/events/SDL_dragevents_c.h diff --git a/src/events/SDL_dragevents.c b/src/events/SDL_dragevents.c new file mode 100644 index 000000000..0b1b37e71 --- /dev/null +++ b/src/events/SDL_dragevents.c @@ -0,0 +1,64 @@ +#include "../SDL_internal.h" + +#include "SDL_events.h" +#include "SDL_events_c.h" +#include "SDL_dragevents_c.h" + +#include "../video/SDL_sysvideo.h" /* for SDL_Window internals. */ + +const int +SDL_SendDrag(SDL_Window *window, const SDL_EventType evtype, const char *data, int x, int y) +{ + static SDL_bool app_is_dragging = SDL_FALSE; + int posted = 0; + + const SDL_bool need_begin = window ? !window->is_dragging : !app_is_dragging; + SDL_Event event; + + if (need_begin) { + SDL_zero(event); + event.type = SDL_DRAGBEGIN; + event.drag.x = x; + event.drag.y = y; + + if (window) { + event.drag.windowID = window->id; + } + + posted = (SDL_PushEvent(&event) > 0); + if (!posted) { + return 0; + } + if (window) { + window->is_dragging = SDL_TRUE; + } else { + app_is_dragging = SDL_TRUE; + } + } + + SDL_zero(event); + event.type = evtype; + event.drag.file = data ? SDL_strdup(data) : NULL; + event.drag.windowID = window ? window->id : 0; + event.drag.x = x; + event.drag.y = y; + posted = (SDL_PushEvent(&event) > 0); + + if (posted && (evtype == SDL_DRAGCOMPLETE)) { + if (window) { + window->is_dragging = SDL_FALSE; + } else { + app_is_dragging = SDL_FALSE; + } + } + return posted; +} + +int SDL_SendDragFile(SDL_Window *window, const char *file, int x, int y) +{ + return SDL_SendDrag(window, SDL_DRAGFILE, file, x, y); +} + +int SDL_SendDragComplete(SDL_Window *window, int x, int y) { + return SDL_SendDrag(window, SDL_DRAGCOMPLETE, NULL, x, y); +} diff --git a/src/events/SDL_dragevents_c.h b/src/events/SDL_dragevents_c.h new file mode 100644 index 000000000..4b71e0821 --- /dev/null +++ b/src/events/SDL_dragevents_c.h @@ -0,0 +1,8 @@ +#include "../SDL_internal.h" + +#ifndef SDL_dragevents_c_h_ +#define SDL_dragevents_c_h_ + +extern int SDL_SendDragFile(SDL_Window *window, const char *file, int x, int y); +extern int SDL_SendDragComplete(SDL_Window *window, int x, int y); +#endif diff --git a/src/events/SDL_events_c.h b/src/events/SDL_events_c.h index da3984b3e..f798531ec 100644 --- a/src/events/SDL_events_c.h +++ b/src/events/SDL_events_c.h @@ -31,6 +31,7 @@ #include "SDL_clipboardevents_c.h" #include "SDL_displayevents_c.h" +#include "SDL_dragevents_c.h" #include "SDL_dropevents_c.h" #include "SDL_gesture_c.h" #include "SDL_keyboard_c.h" diff --git a/src/video/SDL_sysvideo.h b/src/video/SDL_sysvideo.h index e88a8b60e..a1f379747 100644 --- a/src/video/SDL_sysvideo.h +++ b/src/video/SDL_sysvideo.h @@ -100,6 +100,7 @@ struct SDL_Window SDL_bool is_hiding; SDL_bool is_destroying; SDL_bool is_dropping; /* drag/drop in progress, expecting SDL_SendDropComplete(). */ + SDL_bool is_dragging; SDL_WindowShaper *shaper; @@ -380,11 +381,11 @@ struct SDL_VideoDevice /* Data private to this driver */ void *driverdata; struct SDL_GLDriverData *gl_data; - + #if SDL_VIDEO_OPENGL_EGL struct SDL_EGL_VideoData *egl_data; #endif - + #if SDL_VIDEO_OPENGL_ES || SDL_VIDEO_OPENGL_ES2 struct SDL_PrivateGLESData *gles_data; #endif diff --git a/src/video/cocoa/SDL_cocoawindow.m b/src/video/cocoa/SDL_cocoawindow.m index faee02cfc..bbac9b183 100644 --- a/src/video/cocoa/SDL_cocoawindow.m +++ b/src/video/cocoa/SDL_cocoawindow.m @@ -34,6 +34,7 @@ #include "../../events/SDL_mouse_c.h" #include "../../events/SDL_touch_c.h" #include "../../events/SDL_windowevents_c.h" +#include "../../events/SDL_dragevents_c.h" #include "../../events/SDL_dropevents_c.h" #include "SDL_cocoavideo.h" #include "SDL_cocoashape.h" @@ -139,6 +140,57 @@ - (NSDragOperation)draggingEntered:(id )sender return NSDragOperationNone; /* no idea what to do with this, reject it. */ } +- (NSDragOperation)draggingUpdated:(id)sender +{ + NSPasteboard *pasteboard = [sender draggingPasteboard]; + NSArray *types = [NSArray arrayWithObject:NSFilenamesPboardType]; + NSString *desiredType = [pasteboard availableTypeFromArray:types]; + SDL_Window *sdlwindow = [self findSDLWindow]; + NSPoint point = [sender draggingLocation]; + + if (desiredType == nil) { + return NSDragOperationNone; + } + + NSData *data = [pasteboard dataForType:desiredType]; + if (data == nil) { + return NSDragOperationNone; + } + + SDL_assert([desiredType isEqualToString:NSFilenamesPboardType]); + NSArray *array = [pasteboard propertyListForType:@"NSFilenamesPboardType"]; + + for (NSString *path in array) { + NSURL *fileURL = [NSURL fileURLWithPath:path]; + NSNumber *isAlias = nil; + + [fileURL getResourceValue:&isAlias forKey:NSURLIsAliasFileKey error:nil]; + + if ([isAlias boolValue]) { + NSURLBookmarkResolutionOptions opts = NSURLBookmarkResolutionWithoutMounting | NSURLBookmarkResolutionWithoutUI; + NSData *bookmark = [NSURL bookmarkDataWithContentsOfURL:fileURL error:nil]; + if (bookmark != nil) { + NSURL *resolvedURL = [NSURL URLByResolvingBookmarkData:bookmark + options:opts + relativeToURL:nil + bookmarkDataIsStale:nil + error:nil]; + + if (resolvedURL != nil) { + fileURL = resolvedURL; + } + } + } + + if (!SDL_SendDragFile(sdlwindow, [[fileURL path] UTF8String], point.x, point.y)) { + return NSDragOperationNone; + } + } + + SDL_SendDragComplete(sdlwindow, point.x, point.y); + return NSDragOperationGeneric; +} + - (BOOL)performDragOperation:(id )sender { @autoreleasepool { @@ -711,7 +763,7 @@ - (void)windowDidFailToEnterFullScreen:(NSNotification *)aNotification isFullscreenSpace = NO; inFullscreenTransition = NO; - + [self windowDidExitFullScreen:nil]; } @@ -727,7 +779,7 @@ - (void)windowDidEnterFullScreen:(NSNotification *)aNotification pendingWindowOperation = PENDING_OPERATION_NONE; [self setFullscreenSpace:NO]; } else { - /* Unset the resizable flag. + /* Unset the resizable flag. This is a workaround for https://bugzilla.libsdl.org/show_bug.cgi?id=3697 */ SetWindowStyle(window, [nswindow styleMask] & (~NSWindowStyleMaskResizable)); @@ -763,16 +815,16 @@ - (void)windowWillExitFullScreen:(NSNotification *)aNotification - (void)windowDidFailToExitFullScreen:(NSNotification *)aNotification { SDL_Window *window = _data->window; - + if (window->is_destroying) { return; } SetWindowStyle(window, (NSWindowStyleMaskTitled|NSWindowStyleMaskClosable|NSWindowStyleMaskMiniaturizable|NSWindowStyleMaskResizable)); - + isFullscreenSpace = YES; inFullscreenTransition = NO; - + [self windowDidEnterFullScreen:nil]; } @@ -1474,7 +1526,7 @@ - (BOOL)acceptsFirstMouse:(NSEvent *)theEvent if (!(window->flags & SDL_WINDOW_OPENGL)) { return 0; } - + /* The rest of this macro mess is for OpenGL or OpenGL ES windows */ #if SDL_VIDEO_OPENGL_ES2 if (_this->gl_config.profile_mask == SDL_GL_CONTEXT_PROFILE_ES) { @@ -1894,7 +1946,7 @@ - (BOOL)acceptsFirstMouse:(NSEvent *)theEvent NSArray *contexts = [[data->nscontexts copy] autorelease]; for (SDLOpenGLContext *context in contexts) { - /* Calling setWindow:NULL causes the context to remove itself from the context list. */ + /* Calling setWindow:NULL causes the context to remove itself from the context list. */ [context setWindow:NULL]; } [data->nscontexts release]; From 4d9b1a8472f19aed5437e1b10e2b40c0f13f1950 Mon Sep 17 00:00:00 2001 From: Zach Baylin Date: Wed, 6 May 2020 19:00:22 -0400 Subject: [PATCH 2/7] Oops! Add SDL_events.h --- include/SDL_events.h | 18 +++++++++++++++++- 1 file changed, 17 insertions(+), 1 deletion(-) diff --git a/include/SDL_events.h b/include/SDL_events.h index d35ec36c6..454aa44d7 100644 --- a/include/SDL_events.h +++ b/include/SDL_events.h @@ -157,6 +157,12 @@ typedef enum /* Pan events */ SDL_PANEVENT = 0x2100, + /* Drag events */ + SDL_DRAGFILE = 0x2200, + SDL_DRAGTEXT, + SDL_DRAGBEGIN, + SDL_DRAGCOMPLETE, + /** Events ::SDL_USEREVENT through ::SDL_LASTEVENT are for your use, * and should be allocated with SDL_RegisterEvents() */ @@ -533,6 +539,16 @@ typedef struct SDL_DropEvent } SDL_DropEvent; +typedef struct SDL_DragEvent +{ + Uint32 type; + Uint32 timestamp; + char *file; + Uint32 windowID; + Sint32 x; + Sint32 y; +} SDL_DragEvent; + /** * \brief Sensor event structure (event.sensor.*) */ @@ -624,7 +640,7 @@ typedef union SDL_Event SDL_MultiGestureEvent mgesture; /**< Gesture event data */ SDL_DollarGestureEvent dgesture; /**< Gesture event data */ SDL_DropEvent drop; /**< Drag and drop event data */ - + SDL_DragEvent drag; SDL_PanEvent pan; /**< Obsolesces mouse wheel events */ /* This is necessary for ABI compatibility between Visual C++ and GCC From 5a07d9ec4ae9f0f5635aa0a7ecdf7285bc5eed3a Mon Sep 17 00:00:00 2001 From: Zach Baylin Date: Thu, 7 May 2020 11:04:31 -0400 Subject: [PATCH 3/7] README: add the drag events under Modifications --- README.md | 9 +++++---- 1 file changed, 5 insertions(+), 4 deletions(-) diff --git a/README.md b/README.md index 4400116ce..ea8db60eb 100644 --- a/README.md +++ b/README.md @@ -3,11 +3,12 @@ # esy-sdl2 Esy-enabled build for [SDL2](https://www.libsdl.org/) -# Modifications +## Modifications -A patch by xenotron007 was applied to enable Windows IME candidate list to be shown: -https://bugzilla.libsdl.org/attachment.cgi?id=3604&action=diff +- A patch by xenotron007 was applied to enable Windows IME candidate list to be shown: https://bugzilla.libsdl.org/attachment.cgi?id=3604&action=diff +- A patch by [@zbaylin](/~https://github.com/zbaylin) was made to add drag events that closely mirror the built-in drop events -# License + +## License [SDL License](./LICENSE) From fc65ebd297c2f8a40da44bccaa64ad8ba8f9eb08 Mon Sep 17 00:00:00 2001 From: Zach Baylin Date: Thu, 7 May 2020 13:46:46 -0400 Subject: [PATCH 4/7] Removed formatting changes to make merging easier --- src/video/SDL_sysvideo.h | 4 ++-- src/video/cocoa/SDL_cocoawindow.m | 14 +++++++------- 2 files changed, 9 insertions(+), 9 deletions(-) diff --git a/src/video/SDL_sysvideo.h b/src/video/SDL_sysvideo.h index a1f379747..48225eecc 100644 --- a/src/video/SDL_sysvideo.h +++ b/src/video/SDL_sysvideo.h @@ -381,11 +381,11 @@ struct SDL_VideoDevice /* Data private to this driver */ void *driverdata; struct SDL_GLDriverData *gl_data; - + #if SDL_VIDEO_OPENGL_EGL struct SDL_EGL_VideoData *egl_data; #endif - + #if SDL_VIDEO_OPENGL_ES || SDL_VIDEO_OPENGL_ES2 struct SDL_PrivateGLESData *gles_data; #endif diff --git a/src/video/cocoa/SDL_cocoawindow.m b/src/video/cocoa/SDL_cocoawindow.m index bbac9b183..365556fad 100644 --- a/src/video/cocoa/SDL_cocoawindow.m +++ b/src/video/cocoa/SDL_cocoawindow.m @@ -763,7 +763,7 @@ - (void)windowDidFailToEnterFullScreen:(NSNotification *)aNotification isFullscreenSpace = NO; inFullscreenTransition = NO; - + [self windowDidExitFullScreen:nil]; } @@ -779,7 +779,7 @@ - (void)windowDidEnterFullScreen:(NSNotification *)aNotification pendingWindowOperation = PENDING_OPERATION_NONE; [self setFullscreenSpace:NO]; } else { - /* Unset the resizable flag. + /* Unset the resizable flag. This is a workaround for https://bugzilla.libsdl.org/show_bug.cgi?id=3697 */ SetWindowStyle(window, [nswindow styleMask] & (~NSWindowStyleMaskResizable)); @@ -815,16 +815,16 @@ - (void)windowWillExitFullScreen:(NSNotification *)aNotification - (void)windowDidFailToExitFullScreen:(NSNotification *)aNotification { SDL_Window *window = _data->window; - + if (window->is_destroying) { return; } SetWindowStyle(window, (NSWindowStyleMaskTitled|NSWindowStyleMaskClosable|NSWindowStyleMaskMiniaturizable|NSWindowStyleMaskResizable)); - + isFullscreenSpace = YES; inFullscreenTransition = NO; - + [self windowDidEnterFullScreen:nil]; } @@ -1526,7 +1526,7 @@ - (BOOL)acceptsFirstMouse:(NSEvent *)theEvent if (!(window->flags & SDL_WINDOW_OPENGL)) { return 0; } - + /* The rest of this macro mess is for OpenGL or OpenGL ES windows */ #if SDL_VIDEO_OPENGL_ES2 if (_this->gl_config.profile_mask == SDL_GL_CONTEXT_PROFILE_ES) { @@ -1946,7 +1946,7 @@ - (BOOL)acceptsFirstMouse:(NSEvent *)theEvent NSArray *contexts = [[data->nscontexts copy] autorelease]; for (SDLOpenGLContext *context in contexts) { - /* Calling setWindow:NULL causes the context to remove itself from the context list. */ + /* Calling setWindow:NULL causes the context to remove itself from the context list. */ [context setWindow:NULL]; } [data->nscontexts release]; From ef6017819bb564c2348b19bb636ae808201c2fbe Mon Sep 17 00:00:00 2001 From: Zach Baylin Date: Fri, 8 May 2020 10:51:48 -0700 Subject: [PATCH 5/7] X11: Hooked up drag events to X11 --- src/video/x11/SDL_x11events.c | 68 +++++++++++++++++++++++++++-------- src/video/x11/SDL_x11window.h | 6 ++-- 2 files changed, 57 insertions(+), 17 deletions(-) diff --git a/src/video/x11/SDL_x11events.c b/src/video/x11/SDL_x11events.c index cd46effb7..9f75ce295 100644 --- a/src/video/x11/SDL_x11events.c +++ b/src/video/x11/SDL_x11events.c @@ -43,7 +43,7 @@ #include -/*#define DEBUG_XEVENTS*/ +#define DEBUG_XEVENTS #ifndef _NET_WM_MOVERESIZE_SIZE_TOPLEFT #define _NET_WM_MOVERESIZE_SIZE_TOPLEFT 0 @@ -982,7 +982,7 @@ X11_DispatchEvent(_THIS) &xevent.xconfigure.x, &xevent.xconfigure.y, &ChildReturn); } - + if (xevent.xconfigure.x != data->last_xconfigure.x || xevent.xconfigure.y != data->last_xconfigure.y) { SDL_SendWindowEvent(data->window, SDL_WINDOWEVENT_MOVED, @@ -1057,6 +1057,26 @@ X11_DispatchEvent(_THIS) m.data.l[4] = videodata->XdndActionCopy; /* we only accept copying anyway */ X11_XSendEvent(display, xevent.xclient.data.l[0], False, NoEventMask, (XEvent*)&m); + + if (data->xdnd_req == None) { + memset(&m, 0, sizeof(XClientMessageEvent)); + m.type = ClientMessage; + m.display = xevent.xclient.display; + m.window = xevent.xclient.data.l[0]; + m.message_type = videodata->XdndFinished; + m.format=32; + m.data.l[0] = data->xwindow; + m.data.l[1] = 0; + m.data.l[2] = None; /* fail! */ + X11_XSendEvent(display, xevent.xclient.data.l[0], False, NoEventMask, (XEvent*)&m); + } else { + data->dragging = SDL_TRUE; + if(xdnd_version >= 1) { + X11_XConvertSelection(display, videodata->XdndSelection, data->xdnd_req, videodata->PRIMARY, data->xwindow, xevent.xclient.data.l[2]); + } else { + X11_XConvertSelection(display, videodata->XdndSelection, data->xdnd_req, videodata->PRIMARY, data->xwindow, CurrentTime); + } + } X11_XFlush(display); } else if(xevent.xclient.message_type == videodata->XdndDrop) { @@ -1074,6 +1094,7 @@ X11_DispatchEvent(_THIS) X11_XSendEvent(display, xevent.xclient.data.l[0], False, NoEventMask, (XEvent*)&m); } else { /* convert */ + data->dropping = SDL_TRUE; if(xdnd_version >= 1) { X11_XConvertSelection(display, videodata->XdndSelection, data->xdnd_req, videodata->PRIMARY, data->xwindow, xevent.xclient.data.l[2]); } else { @@ -1343,6 +1364,10 @@ X11_DispatchEvent(_THIS) if (target == data->xdnd_req) { /* read data */ SDL_x11Prop p; + int mouseX = xevent.xmotion.x; + int mouseY = xevent.xmotion.y; + + X11_ReadProperty(&p, display, data->xwindow, videodata->PRIMARY); if (p.format == 8) { @@ -1355,26 +1380,39 @@ X11_DispatchEvent(_THIS) } else if (SDL_strcmp("text/uri-list", name)==0) { char *fn = X11_URIToLocal(token); if (fn) { - SDL_SendDropFile(data->window, fn); + if (data->dropping) { + SDL_SendDropFile(data->window, fn); + } else if (data->dragging) { + SDL_SendDragFile(data->window, fn, mouseX, mouseY); + } } } token = strtok(NULL, "\r\n"); } - SDL_SendDropComplete(data->window); + if (data->dropping) { + SDL_SendDropComplete(data->window); + } else if (data->dragging) { + SDL_SendDragComplete(data->window, mouseX, mouseY); + } } X11_XFree(p.data); - /* send reply */ - SDL_memset(&m, 0, sizeof(XClientMessageEvent)); - m.type = ClientMessage; - m.display = display; - m.window = data->xdnd_source; - m.message_type = videodata->XdndFinished; - m.format = 32; - m.data.l[0] = data->xwindow; - m.data.l[1] = 1; - m.data.l[2] = videodata->XdndActionCopy; - X11_XSendEvent(display, data->xdnd_source, False, NoEventMask, (XEvent*)&m); + if (data->dropping) { + /* send reply */ + SDL_memset(&m, 0, sizeof(XClientMessageEvent)); + m.type = ClientMessage; + m.display = display; + m.window = data->xdnd_source; + m.message_type = videodata->XdndFinished; + m.format = 32; + m.data.l[0] = data->xwindow; + m.data.l[1] = 1; + m.data.l[2] = videodata->XdndActionCopy; + X11_XSendEvent(display, data->xdnd_source, False, NoEventMask, (XEvent*)&m); + } + + data->dragging = SDL_FALSE; + data->dropping = SDL_FALSE; X11_XSync(display, False); } diff --git a/src/video/x11/SDL_x11window.h b/src/video/x11/SDL_x11window.h index d75b4819e..2a7c1f429 100644 --- a/src/video/x11/SDL_x11window.h +++ b/src/video/x11/SDL_x11window.h @@ -29,7 +29,7 @@ */ #define PENDING_FOCUS_TIME 200 -#if SDL_VIDEO_OPENGL_EGL +#if SDL_VIDEO_OPENGL_EGL #include #endif @@ -67,8 +67,10 @@ typedef struct struct SDL_VideoData *videodata; unsigned long user_time; Atom xdnd_req; + SDL_bool dragging; + SDL_bool dropping; Window xdnd_source; -#if SDL_VIDEO_OPENGL_EGL +#if SDL_VIDEO_OPENGL_EGL EGLSurface egl_surface; #endif } SDL_WindowData; From 6a8d6681c4fe6e2d079ca43fcb0a9b019c3debf6 Mon Sep 17 00:00:00 2001 From: Zach Baylin Date: Fri, 8 May 2020 10:59:43 -0700 Subject: [PATCH 6/7] X11: Fix mouse coordinates on drag events --- src/video/x11/SDL_x11events.c | 8 +++----- 1 file changed, 3 insertions(+), 5 deletions(-) diff --git a/src/video/x11/SDL_x11events.c b/src/video/x11/SDL_x11events.c index 9f75ce295..a050b4feb 100644 --- a/src/video/x11/SDL_x11events.c +++ b/src/video/x11/SDL_x11events.c @@ -1364,9 +1364,7 @@ X11_DispatchEvent(_THIS) if (target == data->xdnd_req) { /* read data */ SDL_x11Prop p; - int mouseX = xevent.xmotion.x; - int mouseY = xevent.xmotion.y; - + SDL_Mouse *mouse = SDL_GetMouse(); X11_ReadProperty(&p, display, data->xwindow, videodata->PRIMARY); @@ -1383,7 +1381,7 @@ X11_DispatchEvent(_THIS) if (data->dropping) { SDL_SendDropFile(data->window, fn); } else if (data->dragging) { - SDL_SendDragFile(data->window, fn, mouseX, mouseY); + SDL_SendDragFile(data->window, fn, mouse->x, mouse->y); } } } @@ -1392,7 +1390,7 @@ X11_DispatchEvent(_THIS) if (data->dropping) { SDL_SendDropComplete(data->window); } else if (data->dragging) { - SDL_SendDragComplete(data->window, mouseX, mouseY); + SDL_SendDragComplete(data->window, mouse->x, mouse->y); } } X11_XFree(p.data); From 29c68c603a1d54b9c3b3af7addc6afd0f7b6366a Mon Sep 17 00:00:00 2001 From: Zach Baylin Date: Fri, 8 May 2020 11:19:46 -0700 Subject: [PATCH 7/7] X11: Fix mouse coordinates when window is unfocused --- src/video/x11/SDL_x11events.c | 15 +++++++++++---- 1 file changed, 11 insertions(+), 4 deletions(-) diff --git a/src/video/x11/SDL_x11events.c b/src/video/x11/SDL_x11events.c index a050b4feb..7609c8845 100644 --- a/src/video/x11/SDL_x11events.c +++ b/src/video/x11/SDL_x11events.c @@ -30,6 +30,7 @@ #include "SDL_x11video.h" #include "SDL_x11touch.h" +#include "SDL_x11mouse.h" #include "SDL_x11xinput2.h" #include "../../core/unix/SDL_poll.h" #include "../../events/SDL_events_c.h" @@ -43,7 +44,7 @@ #include -#define DEBUG_XEVENTS +/*#define DEBUG_XEVENTS*/ #ifndef _NET_WM_MOVERESIZE_SIZE_TOPLEFT #define _NET_WM_MOVERESIZE_SIZE_TOPLEFT 0 @@ -1363,8 +1364,9 @@ X11_DispatchEvent(_THIS) #endif if (target == data->xdnd_req) { /* read data */ - SDL_x11Prop p; SDL_Mouse *mouse = SDL_GetMouse(); + SDL_x11Prop p; + int globalMouseX, globalMouseY, localMouseX, localMouseY; X11_ReadProperty(&p, display, data->xwindow, videodata->PRIMARY); @@ -1372,6 +1374,11 @@ X11_DispatchEvent(_THIS) /* !!! FIXME: don't use strtok here. It's not reentrant and not in SDL_stdinc. */ char* name = X11_XGetAtomName(display, target); char *token = strtok((char *) p.data, "\r\n"); + if (data->dragging) { + mouse->GetGlobalMouseState(&globalMouseX, &globalMouseY); + localMouseX = globalMouseX - data->window->x; + localMouseY = globalMouseY - data->window->y; + } while (token != NULL) { if (SDL_strcmp("text/plain", name)==0) { SDL_SendDropText(data->window, token); @@ -1381,7 +1388,7 @@ X11_DispatchEvent(_THIS) if (data->dropping) { SDL_SendDropFile(data->window, fn); } else if (data->dragging) { - SDL_SendDragFile(data->window, fn, mouse->x, mouse->y); + SDL_SendDragFile(data->window, fn, localMouseX, localMouseY); } } } @@ -1390,7 +1397,7 @@ X11_DispatchEvent(_THIS) if (data->dropping) { SDL_SendDropComplete(data->window); } else if (data->dragging) { - SDL_SendDragComplete(data->window, mouse->x, mouse->y); + SDL_SendDragComplete(data->window, localMouseX, localMouseY); } } X11_XFree(p.data);