When processing events without QEventLoop::EventLoopExec we can not rely
on [NSApp run] for running the native run loop. This can happen e.g. when
running a dialog, or when processing events manually via processEvents().
Unfortunately, AppKit relies on at least one call to [NSApp run] for doing
critical initialization of NSApplication, so when we end up spinning the
native runloop via other means, we still need to ensure we pass through
[NSApp run] at least once.
Doing so in a way that relies on our own runloop sources firing and
interrupting the NSApp run is fragile though. For example, the logic
added in bffbfc5b33 to avoid live locks
in CFRunLoop by skipping out event runloop source when processEvents()
is called manually will also result in the [NSApp run] never being
stopped.
To fix this we use a dedicated runloop block instead, where we
explicitly call [NSApp stop:] when first entering the runloop.
In addition we ensure that none of our sources will process
events, so that we don't end up recursing into a runModal
or similar call until after we've initialized NSApp.
Change-Id: I137df46d5fa4105cdc39fe74b6c12275cfd46127
Reviewed-by: Timur Pocheptsov <timur.pocheptsov@qt.io>