summaryrefslogtreecommitdiffstats
path: root/src
diff options
context:
space:
mode:
authorTor Arne Vestbø <tor.arne.vestbo@qt.io>2021-06-22 11:43:18 +0200
committerQt Cherry-pick Bot <cherrypick_bot@qt-project.org>2021-06-25 15:40:57 +0000
commit668768ade5c7fb119c455417965628a4e50feac6 (patch)
treee26c9ab6b6a1e6f326e067dd4efb5128fdb7114b /src
parent2916b5afc4bb8170b8413a5f1f9475c4aa11ea87 (diff)
macOS: Unregister screen notification handlers on QGuiApplication shutdown
In the case of a plugin, the plugin might be unloaded, and destroy its QGuiApplication. We don't want the screen notification handlers to outlive the application, as that results in crashes. Fixes: QTBUG-91919 Done-with: Yang Yang Change-Id: I3a4c0fcf97b785357516d1dac34489511400f154 Reviewed-by: Alexandru Croitor <alexandru.croitor@qt.io> (cherry picked from commit 96469ae338c3146f4efea3fabaaae5bc6ecd6a59) Reviewed-by: Qt Cherry-pick Bot <cherrypick_bot@qt-project.org>
Diffstat (limited to 'src')
-rw-r--r--src/plugins/platforms/cocoa/qcocoascreen.h4
-rw-r--r--src/plugins/platforms/cocoa/qcocoascreen.mm15
2 files changed, 16 insertions, 3 deletions
diff --git a/src/plugins/platforms/cocoa/qcocoascreen.h b/src/plugins/platforms/cocoa/qcocoascreen.h
index b109c24f63..0eb6d114e2 100644
--- a/src/plugins/platforms/cocoa/qcocoascreen.h
+++ b/src/plugins/platforms/cocoa/qcocoascreen.h
@@ -43,6 +43,7 @@
#include "qcocoacursor.h"
#include <qpa/qplatformintegration.h>
+#include <QtCore/private/qcore_mac_p.h>
#include <CoreGraphics/CoreGraphics.h>
#include <CoreVideo/CoreVideo.h>
@@ -102,6 +103,9 @@ private:
static void updateScreens();
static void cleanupScreens();
+ static QMacNotificationObserver s_screenParameterObserver;
+ static CGDisplayReconfigurationCallBack s_displayReconfigurationCallBack;
+
static bool updateScreensIfNeeded();
static NSArray *s_screenConfigurationBeforeUpdate;
diff --git a/src/plugins/platforms/cocoa/qcocoascreen.mm b/src/plugins/platforms/cocoa/qcocoascreen.mm
index 61f7476159..d326d149f1 100644
--- a/src/plugins/platforms/cocoa/qcocoascreen.mm
+++ b/src/plugins/platforms/cocoa/qcocoascreen.mm
@@ -75,12 +75,14 @@ namespace CoreGraphics {
}
NSArray *QCocoaScreen::s_screenConfigurationBeforeUpdate = nil;
+QMacNotificationObserver QCocoaScreen::s_screenParameterObserver;
+CGDisplayReconfigurationCallBack QCocoaScreen::s_displayReconfigurationCallBack = nullptr;
void QCocoaScreen::initializeScreens()
{
updateScreens();
- CGDisplayRegisterReconfigurationCallback([](CGDirectDisplayID displayId, CGDisplayChangeSummaryFlags flags, void *userInfo) {
+ s_displayReconfigurationCallBack = [](CGDirectDisplayID displayId, CGDisplayChangeSummaryFlags flags, void *userInfo) {
Q_UNUSED(userInfo);
// Displays are reconfigured in batches, and we want to update our screens
@@ -131,9 +133,10 @@ void QCocoaScreen::initializeScreens()
updateScreensIfNeeded();
}
}
- }, nullptr);
+ };
+ CGDisplayRegisterReconfigurationCallback(s_displayReconfigurationCallBack, nullptr);
- static QMacNotificationObserver screenParameterObserver(NSApplication.sharedApplication,
+ s_screenParameterObserver = QMacNotificationObserver(NSApplication.sharedApplication,
NSApplicationDidChangeScreenParametersNotification, [&]() {
qCDebug(lcQpaScreen) << "Received screen parameter change notification";
updateScreensIfNeeded(); // As a last resort we update screens here
@@ -241,6 +244,12 @@ void QCocoaScreen::cleanupScreens()
// Remove screens in reverse order to avoid crash in case of multiple screens
for (QScreen *screen : backwards(QGuiApplication::screens()))
static_cast<QCocoaScreen*>(screen->handle())->remove();
+
+ Q_ASSERT(s_displayReconfigurationCallBack);
+ CGDisplayRemoveReconfigurationCallback(s_displayReconfigurationCallBack, nullptr);
+ s_displayReconfigurationCallBack = nullptr;
+
+ s_screenParameterObserver.remove();
}
void QCocoaScreen::remove()