Fix #455 - fix command line processing when the app is in a bundle

This commit is contained in:
David Capello 2014-08-22 09:36:40 -03:00
parent e65bbd6105
commit 9135461627
5 changed files with 20 additions and 31 deletions

View File

@ -33,7 +33,6 @@ extern int __crt0_argc;
extern char **__crt0_argv;
extern void *_mangled_main_address;
static char *arg0, *arg1 = NULL;
static int refresh_rate = 70;
static volatile BOOL ready_to_terminate = NO;
@ -56,12 +55,6 @@ static BOOL in_bundle(void)
@implementation AllegroAppDelegate
- (BOOL)application: (NSApplication *)theApplication openFile: (NSString *)filename
{
arg1 = strdup([filename lossyCString]);
return YES;
}
/* applicationDidFinishLaunching:
@ -103,18 +96,6 @@ static BOOL in_bundle(void)
}
/* It doesn't exist - this is unusual for a bundle. Don't chdir */
}
arg0 = strdup([[osx_bundle bundlePath] fileSystemRepresentation]);
if (arg1) {
static char *args[2];
args[0] = arg0;
args[1] = arg1;
__crt0_argv = args;
__crt0_argc = 2;
}
else {
__crt0_argv = &arg0;
__crt0_argc = 1;
}
}
/* else: not in a bundle so don't chdir */

View File

@ -63,6 +63,12 @@ void ProgramOptions::parse(int argc, const char* argv[])
;
size_t len = arg.size()-n;
// Ignore process serial number argument (-psn...) when the app is run from command line
#if __APPLE__
if (arg.size() >= 4 && arg.substr(0, 4) == "-psn")
continue;
#endif
if ((n > 0) && (len > 0)) {
// Use mnemonics
if (n == 1) {

View File

@ -24,15 +24,6 @@
- (BOOL)application: (NSApplication *)theApplication openFile: (NSString *)filename
{
// This case is used when the application wasn't run by the user,
// and a file is double-clicked from Finder. As the she::Display
// (the class that contains the events queue) is not yet created, we
// can use the Allegro implementation which converts this
// application:openFile: message to an argument for the command
// line. So the clicked file will be opened in the application.
if (!she::instance())
return [super application: theApplication openFile: filename];
she::Event ev;
ev.setType(she::Event::DropFiles);
@ -40,7 +31,7 @@
files.push_back([filename lossyCString]);
ev.setFiles(files);
she::queue_event(ev); // If the display is not created yet, we lost this event.
she::queue_event(ev);
return YES;
}

View File

@ -12,7 +12,7 @@ namespace she {
class Event;
void queue_event(Event& ev);
void queue_event(const Event& ev);
} // namespace she

View File

@ -104,14 +104,17 @@ private:
};
base::mutex unique_display_mutex;
base::concurrent_queue<Event> initial_queue; // Events generated when "unique_display" is NULL
Display* unique_display = NULL;
int display_scale;
void queue_event(Event& ev)
void queue_event(const Event& ev)
{
base::scoped_lock hold(unique_display_mutex);
if (unique_display)
static_cast<Alleg4EventQueue*>(unique_display->getEventQueue())->queueEvent(ev);
else
initial_queue.push(ev);
}
namespace {
@ -427,6 +430,14 @@ public:
m_queue = new Alleg4EventQueue();
// Copy the initial queue to the display queue
{
base::scoped_lock hold(unique_display_mutex);
Event ev;
while (initial_queue.try_pop(ev))
m_queue->queueEvent(ev);
}
// Add a hook to display-switch so when the user returns to the
// screen it's completelly refreshed/redrawn.
LOCK_VARIABLE(display_flags);