Always run screen change side effects

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.

Pick-to: 6.6
Fixes: QTBUG-116232
Change-Id: I44701fd001ab1fd54efe9c8451c6a58cfc0b285f
Reviewed-by: Tor Arne Vestbø <tor.arne.vestbo@qt.io>
bb10
Morten Sørvig 2023-09-04 13:42:02 +02:00
parent fefb1e18b1
commit 89ce65c2d0
2 changed files with 13 additions and 11 deletions

View File

@ -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)

View File

@ -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();
});
}
/*!