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
This commit is contained in:
Václav Slavík
2013-11-27 15:34:49 +00:00
parent aa63554745
commit 40b6009d56

View File

@@ -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 )