macOS: Merge [QCocoaApplicationDelegate canQuit] into callsite
The logic for handling termination without any event loops has been moved up as an early exit, and the code has been modernized. Change-Id: I202720b9923e35732cffea656e1ce108ef11953d Reviewed-by: Paul Olav Tvete <paul.tvete@qt.io>
This commit is contained in:
parent
ff2ba8b9d2
commit
2967510213
@ -140,44 +140,38 @@ QT_USE_NAMESPACE
|
|||||||
return [[self.dockMenu retain] autorelease];
|
return [[self.dockMenu retain] autorelease];
|
||||||
}
|
}
|
||||||
|
|
||||||
- (BOOL)canQuit
|
|
||||||
{
|
|
||||||
QCloseEvent ev;
|
|
||||||
QGuiApplication::sendEvent(qGuiApp, &ev);
|
|
||||||
return ev.isAccepted();
|
|
||||||
}
|
|
||||||
|
|
||||||
// This function will only be called when NSApp is actually running.
|
// This function will only be called when NSApp is actually running.
|
||||||
- (NSApplicationTerminateReply)applicationShouldTerminate:(NSApplication *)sender
|
- (NSApplicationTerminateReply)applicationShouldTerminate:(NSApplication *)sender
|
||||||
{
|
{
|
||||||
if ([reflectionDelegate respondsToSelector:_cmd])
|
if ([reflectionDelegate respondsToSelector:_cmd])
|
||||||
return [reflectionDelegate applicationShouldTerminate:sender];
|
return [reflectionDelegate applicationShouldTerminate:sender];
|
||||||
|
|
||||||
if ([self canQuit]) {
|
if (QGuiApplicationPrivate::instance()->threadData->eventLoops.isEmpty()) {
|
||||||
if (!startedQuit) {
|
// No event loop is executing. This probably means that Qt is used as a plugin,
|
||||||
startedQuit = true;
|
// or as a part of a native Cocoa application. In any case it should be fine to
|
||||||
// Close open windows. This is done in order to deliver de-expose
|
// terminate now.
|
||||||
// events while the event loop is still running.
|
return NSTerminateNow;
|
||||||
const QWindowList topLevels = QGuiApplication::topLevelWindows();
|
|
||||||
for (int i = 0; i < topLevels.size(); ++i) {
|
|
||||||
QWindow *topLevelWindow = topLevels.at(i);
|
|
||||||
// Already closed windows will not have a platform window, skip those
|
|
||||||
if (topLevelWindow->handle())
|
|
||||||
QWindowSystemInterface::handleCloseEvent(topLevelWindow);
|
|
||||||
}
|
|
||||||
QWindowSystemInterface::flushWindowSystemEvents();
|
|
||||||
|
|
||||||
QGuiApplication::exit(0);
|
|
||||||
startedQuit = false;
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
if (QGuiApplicationPrivate::instance()->threadData->eventLoops.isEmpty()) {
|
QCloseEvent ev;
|
||||||
// INVARIANT: No event loop is executing. This probably
|
QGuiApplication::sendEvent(qGuiApp, &ev);
|
||||||
// means that Qt is used as a plugin, or as a part of a native
|
if (!ev.isAccepted())
|
||||||
// Cocoa application. In any case it should be fine to
|
return NSTerminateCancel;
|
||||||
// terminate now:
|
|
||||||
return NSTerminateNow;
|
if (!startedQuit) {
|
||||||
|
startedQuit = true;
|
||||||
|
// Close open windows. This is done in order to deliver de-expose
|
||||||
|
// events while the event loop is still running.
|
||||||
|
for (QWindow *topLevelWindow : QGuiApplication::topLevelWindows()) {
|
||||||
|
// Already closed windows will not have a platform window, skip those
|
||||||
|
if (!topLevelWindow->handle())
|
||||||
|
continue;
|
||||||
|
|
||||||
|
QWindowSystemInterface::handleCloseEvent<QWindowSystemInterface::SynchronousDelivery>(topLevelWindow);
|
||||||
|
}
|
||||||
|
|
||||||
|
QGuiApplication::exit(0);
|
||||||
|
startedQuit = false;
|
||||||
}
|
}
|
||||||
|
|
||||||
return NSTerminateCancel;
|
return NSTerminateCancel;
|
||||||
|
Loading…
x
Reference in New Issue
Block a user