diff options
| author | Tor Arne Vestbø <[email protected]> | 2019-10-15 14:18:40 +0200 |
|---|---|---|
| committer | Tor Arne Vestbø <[email protected]> | 2020-09-14 12:41:00 +0200 |
| commit | 0c02f133f3daee146b805149e69bba8cee6727b2 (patch) | |
| tree | c013e3a10a6ae804f33c05e077dcf8b346a4eea7 /src | |
| parent | cc570ce2fe22e6314d378d3f2d6e4ae1a08df3a2 (diff) | |
Plumb application quit through platform plugin
If we have a platform plugin we ask the platform to quit, and if
not we fall back to the base implementation of QCoreApplication
that sends Quit events directly.
This allows the platform to involve the rest of the system in the
process. The platform will then come back with a spontaneous quit
via QWSI::handleApplicationTermination(), which will then send
the corresponding Quit even from QGuiApplication like normal.
Task-number: QTBUG-45262
Task-number: QTBUG-33235
Task-number: QTBUG-72013
Task-number: QTBUG-59782
Change-Id: I0000aaf7192e4b905933c5da0e53901c6c88f26a
Reviewed-by: Lars Knoll <[email protected]>
Diffstat (limited to 'src')
| -rw-r--r-- | src/corelib/kernel/qcoreapplication.cpp | 13 | ||||
| -rw-r--r-- | src/corelib/kernel/qcoreapplication_p.h | 2 | ||||
| -rw-r--r-- | src/gui/kernel/qguiapplication.cpp | 8 | ||||
| -rw-r--r-- | src/gui/kernel/qguiapplication_p.h | 1 | ||||
| -rw-r--r-- | src/gui/kernel/qplatformintegration.cpp | 14 | ||||
| -rw-r--r-- | src/gui/kernel/qplatformintegration.h | 1 | ||||
| -rw-r--r-- | src/plugins/platforms/cocoa/qcocoaapplicationdelegate.mm | 4 | ||||
| -rw-r--r-- | src/plugins/platforms/cocoa/qcocoahelpers.h | 1 | ||||
| -rw-r--r-- | src/plugins/platforms/cocoa/qcocoahelpers.mm | 1 | ||||
| -rw-r--r-- | src/plugins/platforms/cocoa/qcocoaintegration.h | 1 | ||||
| -rw-r--r-- | src/plugins/platforms/cocoa/qcocoaintegration.mm | 6 |
11 files changed, 45 insertions, 7 deletions
diff --git a/src/corelib/kernel/qcoreapplication.cpp b/src/corelib/kernel/qcoreapplication.cpp index dd52242c6f0..86530f0cfc3 100644 --- a/src/corelib/kernel/qcoreapplication.cpp +++ b/src/corelib/kernel/qcoreapplication.cpp @@ -1975,11 +1975,18 @@ void QCoreApplication::quit() if (!self) return; - if (QThread::currentThread() == self->d_func()->mainThread()) { + self->d_func()->quit(); +} + +void QCoreApplicationPrivate::quit() +{ + Q_Q(QCoreApplication); + + if (QThread::currentThread() == mainThread()) { QEvent quitEvent(QEvent::Quit); - QCoreApplication::sendEvent(self, &quitEvent); + QCoreApplication::sendEvent(q, &quitEvent); } else { - QCoreApplication::postEvent(self, new QEvent(QEvent::Quit)); + QCoreApplication::postEvent(q, new QEvent(QEvent::Quit)); } } diff --git a/src/corelib/kernel/qcoreapplication_p.h b/src/corelib/kernel/qcoreapplication_p.h index 08a7e974ea2..04a740caf19 100644 --- a/src/corelib/kernel/qcoreapplication_p.h +++ b/src/corelib/kernel/qcoreapplication_p.h @@ -135,6 +135,8 @@ public: virtual bool shouldQuit() { return true; } + + virtual void quit(); void maybeQuit(); static QBasicAtomicPointer<QThread> theMainThread; diff --git a/src/gui/kernel/qguiapplication.cpp b/src/gui/kernel/qguiapplication.cpp index 37e8edb6f7e..15955e22873 100644 --- a/src/gui/kernel/qguiapplication.cpp +++ b/src/gui/kernel/qguiapplication.cpp @@ -3641,6 +3641,14 @@ bool QGuiApplicationPrivate::shouldQuitInternal(const QWindowList &processedWind return true; } +void QGuiApplicationPrivate::quit() +{ + if (auto *platformIntegration = QGuiApplicationPrivate::platformIntegration()) + platformIntegration->quit(); + else + QCoreApplicationPrivate::quit(); +} + void QGuiApplicationPrivate::processApplicationTermination(QWindowSystemInterfacePrivate::WindowSystemEvent *windowSystemEvent) { QEvent event(QEvent::Quit); diff --git a/src/gui/kernel/qguiapplication_p.h b/src/gui/kernel/qguiapplication_p.h index 2bbb5ae9a68..7e3c2931f32 100644 --- a/src/gui/kernel/qguiapplication_p.h +++ b/src/gui/kernel/qguiapplication_p.h @@ -105,6 +105,7 @@ public: void addQtOptions(QList<QCommandLineOption> *options) override; #endif virtual bool shouldQuit() override; + void quit() override; bool shouldQuitInternal(const QWindowList &processedWindows); diff --git a/src/gui/kernel/qplatformintegration.cpp b/src/gui/kernel/qplatformintegration.cpp index 1127ab43d23..634a04b791b 100644 --- a/src/gui/kernel/qplatformintegration.cpp +++ b/src/gui/kernel/qplatformintegration.cpp @@ -529,6 +529,20 @@ void QPlatformIntegration::beep() const { } +/*! + \since 6.0 + + Asks the platform to terminate the application. + + Overrides should ensure there's a callback into the QWSI + function handleApplicationTermination so that the quit can + be propagated to QtGui and the application. +*/ +void QPlatformIntegration::quit() const +{ + QWindowSystemInterface::handleApplicationTermination<QWindowSystemInterface::SynchronousDelivery>(); +} + #ifndef QT_NO_OPENGL /*! Platform integration function for querying the OpenGL implementation type. diff --git a/src/gui/kernel/qplatformintegration.h b/src/gui/kernel/qplatformintegration.h index 638d373c3c4..5083542e122 100644 --- a/src/gui/kernel/qplatformintegration.h +++ b/src/gui/kernel/qplatformintegration.h @@ -220,6 +220,7 @@ public: virtual void setApplicationIcon(const QIcon &icon) const; virtual void beep() const; + virtual void quit() const; #if QT_CONFIG(vulkan) || defined(Q_CLANG_QDOC) virtual QPlatformVulkanInstance *createPlatformVulkanInstance(QVulkanInstance *instance) const; diff --git a/src/plugins/platforms/cocoa/qcocoaapplicationdelegate.mm b/src/plugins/platforms/cocoa/qcocoaapplicationdelegate.mm index 62f2cc30e0d..e6e46cda812 100644 --- a/src/plugins/platforms/cocoa/qcocoaapplicationdelegate.mm +++ b/src/plugins/platforms/cocoa/qcocoaapplicationdelegate.mm @@ -92,10 +92,6 @@ #include <qpa/qwindowsysteminterface.h> #include <qwindowdefs.h> -QT_BEGIN_NAMESPACE -Q_LOGGING_CATEGORY(lcQpaApplication, "qt.qpa.application"); -QT_END_NAMESPACE - QT_USE_NAMESPACE @implementation QCocoaApplicationDelegate { diff --git a/src/plugins/platforms/cocoa/qcocoahelpers.h b/src/plugins/platforms/cocoa/qcocoahelpers.h index d78aaadd4e5..883c4099242 100644 --- a/src/plugins/platforms/cocoa/qcocoahelpers.h +++ b/src/plugins/platforms/cocoa/qcocoahelpers.h @@ -72,6 +72,7 @@ Q_DECLARE_LOGGING_CATEGORY(lcQpaWindow) Q_DECLARE_LOGGING_CATEGORY(lcQpaDrawing) Q_DECLARE_LOGGING_CATEGORY(lcQpaMouse) Q_DECLARE_LOGGING_CATEGORY(lcQpaScreen) +Q_DECLARE_LOGGING_CATEGORY(lcQpaApplication) class QPixmap; class QString; diff --git a/src/plugins/platforms/cocoa/qcocoahelpers.mm b/src/plugins/platforms/cocoa/qcocoahelpers.mm index 3e370104979..389766fdc72 100644 --- a/src/plugins/platforms/cocoa/qcocoahelpers.mm +++ b/src/plugins/platforms/cocoa/qcocoahelpers.mm @@ -59,6 +59,7 @@ Q_LOGGING_CATEGORY(lcQpaWindow, "qt.qpa.window"); Q_LOGGING_CATEGORY(lcQpaDrawing, "qt.qpa.drawing"); Q_LOGGING_CATEGORY(lcQpaMouse, "qt.qpa.input.mouse", QtCriticalMsg); Q_LOGGING_CATEGORY(lcQpaScreen, "qt.qpa.screen", QtCriticalMsg); +Q_LOGGING_CATEGORY(lcQpaApplication, "qt.qpa.application"); // // Conversion Functions diff --git a/src/plugins/platforms/cocoa/qcocoaintegration.h b/src/plugins/platforms/cocoa/qcocoaintegration.h index f8b9e9fc124..1e330344afd 100644 --- a/src/plugins/platforms/cocoa/qcocoaintegration.h +++ b/src/plugins/platforms/cocoa/qcocoaintegration.h @@ -132,6 +132,7 @@ public: void setApplicationIcon(const QIcon &icon) const override; void beep() const override; + void quit() const override; void closePopups(QWindow *forWindow = nullptr); diff --git a/src/plugins/platforms/cocoa/qcocoaintegration.mm b/src/plugins/platforms/cocoa/qcocoaintegration.mm index 250d9fc6e52..872d9bb7f16 100644 --- a/src/plugins/platforms/cocoa/qcocoaintegration.mm +++ b/src/plugins/platforms/cocoa/qcocoaintegration.mm @@ -488,6 +488,12 @@ void QCocoaIntegration::beep() const NSBeep(); } +void QCocoaIntegration::quit() const +{ + qCDebug(lcQpaApplication) << "Terminating application"; + [NSApp terminate:nil]; +} + void QCocoaIntegration::closePopups(QWindow *forWindow) { for (auto it = m_popupWindowStack.begin(); it != m_popupWindowStack.end();) { |
