From 1e85dfacf3479ebbe5a4502895b8b8d93fbe1477 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Morten=20S=C3=B8rvig?= Date: Wed, 14 Apr 2021 21:46:30 +0200 Subject: Make resizeMaximizedWindows() preserve native geometry MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Previously, resizeMaximizedWindows() would use the device independent screen size as the source of truth when setting window sizes. However this size may have been rounded, which means that e.g. a fullscreen window may fail to cover the entire screen. Instead, use the native screen size as the true screen size. Set QPlatformWindow geometry, and let the platform update QWindow geometry via geometry change events. Pick-to: 6.1 Fixes: QTBUG-87334 Change-Id: If6e4852dea46ab03c83e469808c0047bc933ee47 Reviewed-by: Tor Arne Vestbø --- src/gui/kernel/qplatformscreen.cpp | 19 +++++++++++++------ 1 file changed, 13 insertions(+), 6 deletions(-) diff --git a/src/gui/kernel/qplatformscreen.cpp b/src/gui/kernel/qplatformscreen.cpp index f1fe942b9c..0649139455 100644 --- a/src/gui/kernel/qplatformscreen.cpp +++ b/src/gui/kernel/qplatformscreen.cpp @@ -47,6 +47,7 @@ #include #include #include +#include QT_BEGIN_NAMESPACE @@ -353,11 +354,12 @@ QPlatformCursor *QPlatformScreen::cursor() const */ void QPlatformScreen::resizeMaximizedWindows() { - // 'screen()' still has the old geometry info while 'this' has the new geometry info + // 'screen()' still has the old geometry (in device independent pixels), + // while 'this' has the new geometry (in native pixels) const QRect oldGeometry = screen()->geometry(); const QRect oldAvailableGeometry = screen()->availableGeometry(); - const QRect newGeometry = deviceIndependentGeometry(); - const QRect newAvailableGeometry = QHighDpi::fromNative(availableGeometry(), QHighDpiScaling::factor(this), newGeometry.topLeft()); + const QRect newNativeGeometry = this->geometry(); + const QRect newNativeAvailableGeometry = this->availableGeometry(); const bool supportsMaximizeUsingFullscreen = QGuiApplicationPrivate::platformIntegration()->hasCapability(QPlatformIntegration::MaximizeUsingFullscreenGeometry); @@ -366,14 +368,19 @@ void QPlatformScreen::resizeMaximizedWindows() if (!w->handle()) continue; + // Set QPlatformWindow size in native pixels, and let the platform's geometry + // change signals update the QWindow geomeyry. This way we make sure that the + // platform window geometry covers the entire (available) platform screen geometry, + // also when fractional DPRs introduce rounding errors in the device independent + // QWindow and QScreen sizes. if (supportsMaximizeUsingFullscreen && w->windowState() & Qt::WindowMaximized && w->flags() & Qt::MaximizeUsingFullscreenGeometryHint) { - w->setGeometry(newGeometry); + w->handle()->setGeometry(newNativeGeometry); } else if (w->windowState() & Qt::WindowMaximized || w->geometry() == oldAvailableGeometry) { - w->setGeometry(newAvailableGeometry); + w->handle()->setGeometry(newNativeAvailableGeometry); } else if (w->windowState() & Qt::WindowFullScreen || w->geometry() == oldGeometry) { - w->setGeometry(newGeometry); + w->handle()->setGeometry(newNativeGeometry); } } } -- cgit v1.2.3