We are currently migrating Bugzilla to GitHub issues.
Any changes made to the bug tracker now will be lost, so please do not post new bugs or make changes to them.
When we're done, all bug URLs will redirect to their equivalent location on the new bug tracker.

Bug 1870 - Mac: dropping a file onto the app to launch it doesn't pass the filepath to argv
Summary: Mac: dropping a file onto the app to launch it doesn't pass the filepath to argv
Status: RESOLVED WONTFIX
Alias: None
Product: SDL
Classification: Unclassified
Component: events (show other bugs)
Version: HG 2.0
Hardware: x86_64 Mac OS X 10.8
: P2 minor
Assignee: (disabled) Jørgen Tjernø
QA Contact: (disabled) Jørgen Tjernø
URL:
Keywords:
Depends on:
Blocks:
 
Reported: 2013-05-27 19:02 UTC by Alex Szpakowski
Modified: 2013-07-12 17:36 UTC (History)
1 user (show)

See Also:


Attachments

Note You need to log in before you can comment on or make changes to this bug.
Description Alex Szpakowski 2013-05-27 19:02:49 UTC
In Windows and Linux, dropping a file/folder onto a program's icon will launch the program and pass the filepath through to argv in the main function.
In OS X / Cocoa, all drop-file behaviour is event-based (even on program startup), and SDL2 passes the events through to SDL_DROPFILE.

The SDL_DROPFILE event is disabled by default, so unless SDL_EventState(SDL_DROPFILE, SDL_ENABLE) is called *before* the program's main function, the information that a file got dropped onto the program to open it will get completely lost in OS X (whereas in Linux/Windows it will always be in argv.)

In SDL 1.2 on OS X, the filepath from the file drop event is passed to main's argv by using a custom main function in the SDLmain.m file, which no longer exists in SDL 2.

Despite the different open-program-with-drop-file design philosophy of OS X versus Windows and Linux, I would expect SDL 2 to make it behave the same on all three platforms, especially since the behaviour was consistent across platforms in SDL 1.2, and the filepath is not easily accessible with the SDL_DROPFILE event in OS X.
Comment 1 Sam Lantinga 2013-07-12 02:26:03 UTC
FYI, SDL_DROPFILE should be enabled by default now.  Can you confirm in the latest snapshot?
http://www.libsdl.org/tmp/SDL-2.0.zip
Comment 2 Alex Szpakowski 2013-07-12 02:58:21 UTC
Indeed, it is enabled by default now - drop-to-open for an SDL2 application now successfully puts the SDL_DROPFILE event in the queue. :)

Now that SDL_DROPFILE is enabled by default, I guess developers using SDL 2 have to be more careful to either always handle the heap memory allocated by SDL_DROPFILE or disable the event, if they don't want potential (small) memory leaks.
Comment 3 Sam Lantinga 2013-07-12 04:39:20 UTC
Yep. :)

Since we are no longer wrapping main() on OS X, we can't pass the initial dropped file into the command line.

Ideally on Windows and Linux we would be able to detect that an argument was generated via a file drop and convert them into a SDL_DROPFILE event, but I don't know of any way to do that.

Portable applications that want to handle file drops should handle command line parameters as well as the SDL_DROPFILE event.
Comment 4 Alex Szpakowski 2013-07-12 11:20:42 UTC
Fair enough. Thanks!
Comment 5 Alex Szpakowski 2013-07-12 17:36:35 UTC
Just a quick note - the comments for the SDL_DropEvent struct in SDL_events.h haven't been updated to reflect the new changes, they still say the event is disabled by default.