Some drag'and'drop improvements.

First: disable d'n'd events by default; most apps don't need these at all, and
if an app doesn't explicitly handle these, each drop on the window will cause
a memory leak if the events are enabled. This follows the guidelines we have
for SDL_TEXTINPUT events already.

Second: when events are enabled or disabled, signal the video layer, as it
might be able to inform the OS, causing UI changes or optimizations (for
example, dropping a file icon on a Cocoa app that isn't accepting drops will
cause macOS to show a rejection animation instead of the drop operation just
vanishing into the ether, X11 might show a different cursor when dragging
onto an accepting window, etc).

Third: fill in the drop event details in the test library and enable the
events in testwm.c for making sure this all works as expected.
This commit is contained in:
Ryan C. Gordon
2018-08-02 16:03:47 -04:00
parent 8f0cc4a4b7
commit e061a92dc9
14 changed files with 116 additions and 13 deletions

View File

@@ -1349,7 +1349,18 @@ SDLTest_PrintEvent(SDL_Event * event)
case SDL_APP_DIDENTERFOREGROUND:
SDL_Log("SDL EVENT: App entered the foreground");
break;
case SDL_DROPBEGIN:
SDL_Log("SDL EVENT: Drag and drop beginning");
break;
case SDL_DROPFILE:
SDL_Log("SDL EVENT: Drag and drop file: '%s'", event->drop.file);
break;
case SDL_DROPTEXT:
SDL_Log("SDL EVENT: Drag and drop text: '%s'", event->drop.file);
break;
case SDL_DROPCOMPLETE:
SDL_Log("SDL EVENT: Drag and drop ending");
break;
case SDL_QUIT:
SDL_Log("SDL EVENT: Quit requested");
break;
@@ -1744,6 +1755,11 @@ SDLTest_CommonEvent(SDLTest_CommonState * state, SDL_Event * event, int *done)
case SDL_MOUSEMOTION:
lastEvent = event->motion;
break;
case SDL_DROPFILE:
case SDL_DROPTEXT:
SDL_free(event->drop.file);
break;
}
}