Windows QPA: don't take dpi rounding policy into account when fullscreen

With some HighDpiScaleFactorRoundingPolicy, going fullscreen can end up
not filling the whole screen. In this case, ignore the rounding (only for
the window size, not its content).

Fixes: QTBUG-115954
Pick-to: 6.6
Change-Id: Ie87196358ef28dbe2fcbc180b1740ed9f784b4a0
Reviewed-by: Oliver Wolff <oliver.wolff@qt.io>
(cherry picked from commit da473f3a80798d84d0f1bd9175158024a548ec68)
Reviewed-by: Qt Cherry-pick Bot <cherrypick_bot@qt-project.org>
This commit is contained in:
Timothée Keller 2023-08-14 16:11:35 +02:00 committed by Qt Cherry-pick Bot
parent 2a18c00c2a
commit 073340a6d8

View File

@ -2579,26 +2579,26 @@ void QWindowsWindow::setWindowState_sys(Qt::WindowStates newState)
if (testFlag(HasBorderInFullScreen)) if (testFlag(HasBorderInFullScreen))
newStyle |= WS_BORDER; newStyle |= WS_BORDER;
setStyle(newStyle); setStyle(newStyle);
// Use geometry of QWindow::screen() within creation or the virtual screen the const HMONITOR monitor = MonitorFromWindow(m_data.hwnd, MONITOR_DEFAULTTONEAREST);
// window is in (QTBUG-31166, QTBUG-30724). MONITORINFO monitorInfo = {};
const QScreen *screen = window()->screen(); monitorInfo.cbSize = sizeof(MONITORINFO);
if (!screen) GetMonitorInfoW(monitor, &monitorInfo);
screen = QGuiApplication::primaryScreen(); const QRect screenGeometry(monitorInfo.rcMonitor.left, monitorInfo.rcMonitor.top,
const QRect r = screen ? QHighDpi::toNativePixels(screen->geometry(), window()) : m_savedFrameGeometry; monitorInfo.rcMonitor.right - monitorInfo.rcMonitor.left,
monitorInfo.rcMonitor.bottom - monitorInfo.rcMonitor.top);
if (newState & Qt::WindowMinimized) { if (newState & Qt::WindowMinimized) {
setMinimizedGeometry(m_data.hwnd, r); setMinimizedGeometry(m_data.hwnd, screenGeometry);
if (stateChange & Qt::WindowMaximized) if (stateChange & Qt::WindowMaximized)
setRestoreMaximizedFlag(m_data.hwnd, newState & Qt::WindowMaximized); setRestoreMaximizedFlag(m_data.hwnd, newState & Qt::WindowMaximized);
} else { } else {
const UINT swpf = SWP_FRAMECHANGED | SWP_NOACTIVATE; const UINT swpf = SWP_FRAMECHANGED | SWP_NOACTIVATE;
const bool wasSync = testFlag(SynchronousGeometryChangeEvent); const bool wasSync = testFlag(SynchronousGeometryChangeEvent);
setFlag(SynchronousGeometryChangeEvent); setFlag(SynchronousGeometryChangeEvent);
SetWindowPos(m_data.hwnd, HWND_TOP, r.left(), r.top(), r.width(), r.height(), swpf); SetWindowPos(m_data.hwnd, HWND_TOP, screenGeometry.left(), screenGeometry.top(), screenGeometry.width(), screenGeometry.height(), swpf);
if (!wasSync) if (!wasSync)
clearFlag(SynchronousGeometryChangeEvent); clearFlag(SynchronousGeometryChangeEvent);
clearFlag(MaximizeToFullScreen); clearFlag(MaximizeToFullScreen);
QWindowSystemInterface::handleGeometryChange(window(), r); QWindowSystemInterface::handleGeometryChange(window(), screenGeometry);
QWindowSystemInterface::flushWindowSystemEvents(QEventLoop::ExcludeUserInputEvents); QWindowSystemInterface::flushWindowSystemEvents(QEventLoop::ExcludeUserInputEvents);
} }
} else { } else {