macOS: Let system decide whether modal window should prevent app termination
The logic for preventing application termination when there are modal windows active was a leftover from the Carbon to Cocoa port, and is no longer needed. AppKit will deal with this on its own, by checking the preventsApplicationTerminationWhenModal property of each NSWindow. In some cases AppKit will also ignore this property, such as when quitting the application from the menu entry, which means we now get the default system behavior for this use-case. Change-Id: Iac5d8d8e17eb0974448f7ee6f39c9b7761bf4d90 Reviewed-by: Shawn Rutledge <shawn.rutledge@qt.io> Reviewed-by: Volker Hilsheimer <volker.hilsheimer@qt.io>
This commit is contained in:
parent
2c9bd677ab
commit
ff2ba8b9d2
@ -142,28 +142,9 @@ QT_USE_NAMESPACE
|
||||
|
||||
- (BOOL)canQuit
|
||||
{
|
||||
bool handle_quit = true;
|
||||
NSMenuItem *quitMenuItem = [[QCocoaMenuLoader sharedMenuLoader] quitMenuItem];
|
||||
if (!QGuiApplicationPrivate::instance()->modalWindowList.isEmpty()
|
||||
&& [quitMenuItem isEnabled]) {
|
||||
int visible = 0;
|
||||
const QWindowList tlws = QGuiApplication::topLevelWindows();
|
||||
for (int i = 0; i < tlws.size(); ++i) {
|
||||
if (tlws.at(i)->isVisible())
|
||||
++visible;
|
||||
}
|
||||
handle_quit = (visible <= 1);
|
||||
}
|
||||
|
||||
if (handle_quit) {
|
||||
QCloseEvent ev;
|
||||
QGuiApplication::sendEvent(qGuiApp, &ev);
|
||||
if (ev.isAccepted()) {
|
||||
return YES;
|
||||
}
|
||||
}
|
||||
|
||||
return NO;
|
||||
QCloseEvent ev;
|
||||
QGuiApplication::sendEvent(qGuiApp, &ev);
|
||||
return ev.isAccepted();
|
||||
}
|
||||
|
||||
// This function will only be called when NSApp is actually running.
|
||||
|
Loading…
x
Reference in New Issue
Block a user