Close popups on window deactivation and orientation changes in qGuiApp

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 <jan-arve.saether@qt.io>
This commit is contained in:
Oliver Eftevaag 2024-08-20 14:30:54 +02:00
parent fe9d56d2a9
commit 914c2ef4fb

View File

@ -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<QWindow *>(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);