From 40b6009d564e0e926fb0ffbe3424b3013052fd91 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?V=C3=A1clav=20Slav=C3=ADk?= Date: Wed, 27 Nov 2013 15:34:49 +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/branches/WX_3_0_BRANCH@75303 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 456523f5f9..9538e02bf9 100644 --- a/src/osx/cocoa/utils.mm +++ b/src/osx/cocoa/utils.mm @@ -364,7 +364,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 )