From 892ee04344af5d280adba40148b9cc93cb930f60 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?V=C3=A1clav=20Slav=C3=ADk?= Date: Wed, 27 Nov 2013 15:34:19 +0000 Subject: [PATCH] Fix OS X startup to not hang if the application doesn't get focus. If the application launches while the parent process doesn't have an active window, [NSApp run] won't terminate immediately, as was assumed here. Instead, it blocks until some input arrives, e.g. clicking the Dock icon. Work around this by adding a dummy event to the queue. git-svn-id: https://svn.wxwidgets.org/svn/wx/wxWidgets/trunk@75302 c3d73ce0-8a6f-49c7-b76d-6d57e0e08775 --- src/osx/cocoa/utils.mm | 14 ++++++++++++++ 1 file changed, 14 insertions(+) diff --git a/src/osx/cocoa/utils.mm b/src/osx/cocoa/utils.mm index 28437de59d..2fc5ceaf76 100644 --- a/src/osx/cocoa/utils.mm +++ b/src/osx/cocoa/utils.mm @@ -408,7 +408,21 @@ bool wxApp::CallOnInit() wxMacAutoreleasePool autoreleasepool; m_onInitResult = false; m_inited = false; + + // Feed the upcoming event loop with a dummy event. Without this, + // [NSApp run] below wouldn't return, as we expect it to, if the + // application was launched without being activated and would block + // until the dock icon was clicked - delaying OnInit() call too. + NSEvent *event = [NSEvent otherEventWithType:NSApplicationDefined + location:NSMakePoint(0.0, 0.0) + modifierFlags:0 + timestamp:0 + windowNumber:0 + context:nil + subtype:0 data1:0 data2:0]; + [NSApp postEvent:event atStart:FALSE]; [NSApp run]; + m_onInitResult = OnInit(); m_inited = true; if ( m_onInitResult )