From 913546162725eee135b2b38ecd02789af5547124 Mon Sep 17 00:00:00 2001 From: David Capello Date: Fri, 22 Aug 2014 09:36:40 -0300 Subject: [PATCH] Fix #455 - fix command line processing when the app is in a bundle --- src/allegro/src/macosx/main.m | 19 ------------------- src/base/program_options.cpp | 6 ++++++ src/she/alleg4/app.mm | 11 +---------- src/she/alleg4/internals.h | 2 +- src/she/alleg4/she_alleg4.cpp | 13 ++++++++++++- 5 files changed, 20 insertions(+), 31 deletions(-) diff --git a/src/allegro/src/macosx/main.m b/src/allegro/src/macosx/main.m index 20d5143ff..d55913f2d 100644 --- a/src/allegro/src/macosx/main.m +++ b/src/allegro/src/macosx/main.m @@ -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 */ diff --git a/src/base/program_options.cpp b/src/base/program_options.cpp index ea828f065..55fed81c9 100644 --- a/src/base/program_options.cpp +++ b/src/base/program_options.cpp @@ -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) { diff --git a/src/she/alleg4/app.mm b/src/she/alleg4/app.mm index 7bdbf1bd3..fd951fe60 100644 --- a/src/she/alleg4/app.mm +++ b/src/she/alleg4/app.mm @@ -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; } diff --git a/src/she/alleg4/internals.h b/src/she/alleg4/internals.h index d097d5b67..f19e798d3 100644 --- a/src/she/alleg4/internals.h +++ b/src/she/alleg4/internals.h @@ -12,7 +12,7 @@ namespace she { class Event; - void queue_event(Event& ev); + void queue_event(const Event& ev); } // namespace she diff --git a/src/she/alleg4/she_alleg4.cpp b/src/she/alleg4/she_alleg4.cpp index ba2f89a11..8dca91a98 100644 --- a/src/she/alleg4/she_alleg4.cpp +++ b/src/she/alleg4/she_alleg4.cpp @@ -104,14 +104,17 @@ private: }; base::mutex unique_display_mutex; +base::concurrent_queue 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(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);