From 4b21b332ee4388fdd4e9654c6e818e56e09a4f85 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Morten=20S=C3=B8rvig?= Date: Mon, 4 Sep 2023 13:42:02 +0200 Subject: [PATCH] Always run screen change side effects MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit processWindowScreenChangedEvent() returns early if the screen for the (top-level) window has already been updated, for instance by a call to handleScreenRemoved(). This was preventing us from updating the DPR and window geometry. Move the code a slot connected to QWindow::screenChange, which gets emitted for all windows (also child windows), whenever the screen changes. Fixes: QTBUG-116232 Change-Id: I44701fd001ab1fd54efe9c8451c6a58cfc0b285f Reviewed-by: Tor Arne Vestbø (cherry picked from commit 89ce65c2d01e77c1cf49bb8579f63b60480e0186) Reviewed-by: Qt Cherry-pick Bot --- src/gui/kernel/qguiapplication.cpp | 11 ----------- src/gui/kernel/qwindow.cpp | 13 +++++++++++++ 2 files changed, 13 insertions(+), 11 deletions(-) diff --git a/src/gui/kernel/qguiapplication.cpp b/src/gui/kernel/qguiapplication.cpp index 9c09bc2d4ac..c5f03719e4b 100644 --- a/src/gui/kernel/qguiapplication.cpp +++ b/src/gui/kernel/qguiapplication.cpp @@ -2604,17 +2604,6 @@ void QGuiApplicationPrivate::processWindowScreenChangedEvent(QWindowSystemInterf else // Fall back to default behavior, and try to find some appropriate screen topLevelWindow->setScreen(nullptr); } - - // We may have changed scaling; trigger resize event if needed, - // except on Windows, where we send resize events during WM_DPICHANGED - // event handling. FIXME: unify DPI change handling across all platforms. -#ifndef Q_OS_WIN - if (window->handle()) { - QWindowSystemInterfacePrivate::GeometryChangeEvent gce(window, QHighDpi::fromNativePixels(window->handle()->geometry(), window)); - processGeometryChangeEvent(&gce); - } -#endif - QWindowPrivate::get(window)->updateDevicePixelRatio(); } void QGuiApplicationPrivate::processWindowDevicePixelRatioChangedEvent(QWindowSystemInterfacePrivate::WindowDevicePixelRatioChangedEvent *wde) diff --git a/src/gui/kernel/qwindow.cpp b/src/gui/kernel/qwindow.cpp index 7750c70ba1e..0d524b8692b 100644 --- a/src/gui/kernel/qwindow.cpp +++ b/src/gui/kernel/qwindow.cpp @@ -227,6 +227,19 @@ void QWindowPrivate::init(QScreen *targetScreen) requestedFormat = QSurfaceFormat::defaultFormat(); devicePixelRatio = connectScreen->devicePixelRatio(); + + QObject::connect(q, &QWindow::screenChanged, q, [q, this](QScreen *){ + // We may have changed scaling; trigger resize event if needed, + // except on Windows, where we send resize events during WM_DPICHANGED + // event handling. FIXME: unify DPI change handling across all platforms. +#ifndef Q_OS_WIN + if (q->handle()) { + QWindowSystemInterfacePrivate::GeometryChangeEvent gce(q, QHighDpi::fromNativePixels(q->handle()->geometry(), q)); + QGuiApplicationPrivate::processGeometryChangeEvent(&gce); + } +#endif + updateDevicePixelRatio(); + }); } /*!