From 2c1a23f3c869a087fb458036f2306e31333ca54d Mon Sep 17 00:00:00 2001 From: Wladimir Leuschner Date: Wed, 6 Nov 2024 10:23:14 +0100 Subject: [PATCH] Windows QPA: Make frameless window respect WORKAREA Windows that have only set the WS_POPUP style do not take the WORKAREA into account and maximize to fullscreen geometry. This patch maximizes a WS_POPUP window to the size of the current working area, which can be smaller than the screen geometry. Fixes: QTBUG-129791 Fixes: QTBUG-130865 Pick-to: 6.5 Change-Id: I4c5beb0cd69c7ea4c585785a579a9d66bab12cc6 Reviewed-by: Oliver Wolff (cherry picked from commit 90be6609bdfc14df6aec52cbbba6adb4a610301e) Reviewed-by: Qt Cherry-pick Bot --- .../platforms/windows/qwindowswindow.cpp | 20 +++++++++++++++++-- 1 file changed, 18 insertions(+), 2 deletions(-) diff --git a/src/plugins/platforms/windows/qwindowswindow.cpp b/src/plugins/platforms/windows/qwindowswindow.cpp index 2b48e920033..1411d5ae43e 100644 --- a/src/plugins/platforms/windows/qwindowswindow.cpp +++ b/src/plugins/platforms/windows/qwindowswindow.cpp @@ -2736,8 +2736,24 @@ void QWindowsWindow::setWindowState_sys(Qt::WindowStates newState) setFlag(WithinMaximize); if (newState & Qt::WindowFullScreen) setFlag(MaximizeToFullScreen); - ShowWindow(m_data.hwnd, - (newState & Qt::WindowMaximized) ? SW_MAXIMIZE : SW_SHOWNOACTIVATE); + if (m_data.flags & Qt::FramelessWindowHint) { + if (newState == Qt::WindowNoState) { + const QRect &rect = m_savedFrameGeometry; + MoveWindow(m_data.hwnd, rect.x(), rect.y(), rect.width(), rect.height(), true); + } else { + HMONITOR monitor = MonitorFromWindow(m_data.hwnd, MONITOR_DEFAULTTONEAREST); + MONITORINFO monitorInfo = {}; + monitorInfo.cbSize = sizeof(MONITORINFO); + GetMonitorInfo(monitor, &monitorInfo); + const RECT &rect = monitorInfo.rcWork; + m_savedFrameGeometry = geometry(); + MoveWindow(m_data.hwnd, rect.left, rect.top, + rect.right - rect.left, rect.bottom - rect.top, true); + } + } else { + ShowWindow(m_data.hwnd, + (newState & Qt::WindowMaximized) ? SW_MAXIMIZE : SW_SHOWNOACTIVATE); + } clearFlag(WithinMaximize); clearFlag(MaximizeToFullScreen); } else if (visible && (oldState & newState & Qt::WindowMinimized)) {