From 914c2ef4fb926c16e8874c9c3691401f7e22ae22 Mon Sep 17 00:00:00 2001 From: Oliver Eftevaag Date: Tue, 20 Aug 2024 14:30:54 +0200 Subject: [PATCH] Close popups on window deactivation and orientation changes in qGuiApp MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit With the introduction of QQuickPopupWindow in 6.8, much of our popup management had to be moved from QApplication to QGuiApplication. Most of this was done in e4ef0f03e6f1fddc397980fd7fbf6f6b829f16d9, but closing popups on window deactivation and orientation changes, were left in QApplication. This code path was used to close popups when the user clicks outside of a window, on platforms suchs as wayland, were QWindow::setMouseGrabEnabled(true) doesn't work properly. As it turns out QApplication::notify() never calls QGuiapplication::notify(), which is why I'm duplicating the code from QApplication into QGuiApplication, instead of simply moving it. Task-number: QTBUG-121363 Pick-to: 6.8 Change-Id: I36bebd029a2f8e3ec0cdbab40971682cf948d438 Reviewed-by: Jan Arve Sæther --- src/gui/kernel/qguiapplication.cpp | 15 +++++++++++++++ 1 file changed, 15 insertions(+) diff --git a/src/gui/kernel/qguiapplication.cpp b/src/gui/kernel/qguiapplication.cpp index fc1a697d2ae..286382ae898 100644 --- a/src/gui/kernel/qguiapplication.cpp +++ b/src/gui/kernel/qguiapplication.cpp @@ -2033,11 +2033,26 @@ void QGuiApplicationPrivate::captureGlobalModifierState(QEvent *e) */ bool QGuiApplication::notify(QObject *object, QEvent *event) { + Q_D(QGuiApplication); if (object->isWindowType()) { if (QGuiApplicationPrivate::sendQWindowEventToQPlatformWindow(static_cast(object), event)) return true; // Platform plugin ate the event } + switch (event->type()) { + case QEvent::ApplicationDeactivate: + case QEvent::OrientationChange: + // Close all popups (triggers when switching applications + // by pressing ALT-TAB on Windows, which is not received as a key event. + // triggers when the screen rotates.) + // This is also necessary on Wayland, and platforms where + // QWindow::setMouseGrabEnabled(true) doesn't work. + d->closeAllPopups(); + break; + default: + break; + } + QGuiApplicationPrivate::captureGlobalModifierState(event); return QCoreApplication::notify(object, event);