diff options
author | Timothée Keller <[email protected]> | 2023-03-13 17:21:13 +0100 |
---|---|---|
committer | Qt Cherry-pick Bot <[email protected]> | 2023-03-22 14:51:03 +0000 |
commit | 793a1c92599b24982e7eb450ccbfdc6759976fc9 (patch) | |
tree | 4a204d12645f1393907147577d52cbd215763b95 | |
parent | 49d5dad3dd4d8930bd29d86a75dbb12557a8434a (diff) |
Windows QPA: Change handling of maximised frame/title-less windows
So far, the framele/tite-less window maximising has been done by
adjusting the MINMAXINFO to prevent them from covering the taskbar.
It does not work when moving the windows from one screen to another
using keyboard shortcuts, since the MINMAXINFO is that of the old
monitor. This moves the adjustment to the WM_SIZE message that occurs
after the window has been resized.
Change-Id: I0d36fe5d2e8eaa0739414835b8d99a0b2ed44cf6
Reviewed-by: Yuhang Zhao <[email protected]>
Reviewed-by: Oliver Wolff <[email protected]>
(cherry picked from commit eafe57704144af6e14899ea904e5e8cb7431a90b)
Reviewed-by: Qt Cherry-pick Bot <[email protected]>
-rw-r--r-- | src/plugins/platforms/windows/qwindowscontext.cpp | 2 | ||||
-rw-r--r-- | src/plugins/platforms/windows/qwindowswindow.cpp | 67 | ||||
-rw-r--r-- | src/plugins/platforms/windows/qwindowswindow.h | 2 |
3 files changed, 37 insertions, 34 deletions
diff --git a/src/plugins/platforms/windows/qwindowscontext.cpp b/src/plugins/platforms/windows/qwindowscontext.cpp index e8914fb6a2a..ec8e4b9b052 100644 --- a/src/plugins/platforms/windows/qwindowscontext.cpp +++ b/src/plugins/platforms/windows/qwindowscontext.cpp @@ -1127,7 +1127,7 @@ bool QWindowsContext::windowsProc(HWND hwnd, UINT message, platformWindow->handleMoved(); return true; case QtWindows::ResizeEvent: - platformWindow->handleResized(static_cast<int>(wParam)); + platformWindow->handleResized(static_cast<int>(wParam), lParam); return true; case QtWindows::QuerySizeHints: platformWindow->getSizeHints(reinterpret_cast<MINMAXINFO *>(lParam)); diff --git a/src/plugins/platforms/windows/qwindowswindow.cpp b/src/plugins/platforms/windows/qwindowswindow.cpp index 7e3be1c0c3a..1cd4266067f 100644 --- a/src/plugins/platforms/windows/qwindowswindow.cpp +++ b/src/plugins/platforms/windows/qwindowswindow.cpp @@ -2145,8 +2145,41 @@ void QWindowsWindow::handleMoved() handleGeometryChange(); } -void QWindowsWindow::handleResized(int wParam) -{ +void QWindowsWindow::handleResized(int wParam, LPARAM lParam) +{ + /* Prevents borderless windows from covering the taskbar when maximized. */ + if ((m_data.flags.testFlag(Qt::FramelessWindowHint) + || (m_data.flags.testFlag(Qt::CustomizeWindowHint) && !m_data.flags.testFlag(Qt::WindowTitleHint))) + && IsZoomed(m_data.hwnd)) { + const int resizedWidth = LOWORD(lParam); + const int resizedHeight = HIWORD(lParam); + + const HMONITOR monitor = MonitorFromWindow(m_data.hwnd, MONITOR_DEFAULTTOPRIMARY); + MONITORINFO monitorInfo = {}; + monitorInfo.cbSize = sizeof(MONITORINFO); + GetMonitorInfoW(monitor, &monitorInfo); + + int correctLeft = monitorInfo.rcMonitor.left; + int correctTop = monitorInfo.rcMonitor.top; + int correctWidth = monitorInfo.rcWork.right - monitorInfo.rcWork.left; + int correctHeight = monitorInfo.rcWork.bottom - monitorInfo.rcWork.top; + + if (!m_data.flags.testFlag(Qt::FramelessWindowHint)) { + const int borderWidth = invisibleMargins(m_data.hwnd).left(); + correctLeft -= borderWidth; + correctTop -= borderWidth; + correctWidth += borderWidth * 2; + correctHeight += borderWidth * 2; + } + + if (resizedWidth != correctWidth || resizedHeight != correctHeight) { + qCDebug(lcQpaWindow) << __FUNCTION__ << "correcting: " << resizedWidth << "x" + << resizedHeight << " -> " << correctWidth << "x" << correctHeight; + SetWindowPos(m_data.hwnd, nullptr, correctLeft, correctTop, correctWidth, correctHeight, + SWP_NOZORDER | SWP_NOACTIVATE); + } + } + switch (wParam) { case SIZE_MAXHIDE: // Some other window affected. case SIZE_MAXSHOW: @@ -2929,36 +2962,6 @@ void QWindowsWindow::setFrameStrutEventsEnabled(bool enabled) void QWindowsWindow::getSizeHints(MINMAXINFO *mmi) const { QWindowsGeometryHint::applyToMinMaxInfo(window(), fullFrameMargins(), mmi); - - // This block fixes QTBUG-8361, QTBUG-4362: Frameless/title-less windows shouldn't cover the - // taskbar when maximized - if (m_data.flags.testFlag(Qt::FramelessWindowHint) - || (m_data.flags.testFlag(Qt::CustomizeWindowHint) && !m_data.flags.testFlag(Qt::WindowTitleHint))) { - if (QPlatformScreen *currentScreen = screen()) { - const QRect geometry = currentScreen->geometry(); - const QRect availableGeometry = currentScreen->availableGeometry(); - mmi->ptMaxSize.y = availableGeometry.height(); - - // Width, because you can have the taskbar on the sides too. - mmi->ptMaxSize.x = availableGeometry.width(); - - // If you have the taskbar on top, or on the left you don't want it at (0,0): - QPoint availablePositionDiff = availableGeometry.topLeft() - geometry.topLeft(); - mmi->ptMaxPosition.x = availablePositionDiff.x(); - mmi->ptMaxPosition.y = availablePositionDiff.y(); - if (!m_data.flags.testFlag(Qt::FramelessWindowHint)) { - const int borderWidth = invisibleMargins(m_data.hwnd).left(); - mmi->ptMaxSize.x += borderWidth * 2; - mmi->ptMaxSize.y += borderWidth * 2; - mmi->ptMaxTrackSize = mmi->ptMaxSize; - mmi->ptMaxPosition.x -= borderWidth; - mmi->ptMaxPosition.y -= borderWidth; - } - } else { - qWarning("screen() returned a null screen"); - } - } - qCDebug(lcQpaWindow) << __FUNCTION__ << window() << *mmi; } diff --git a/src/plugins/platforms/windows/qwindowswindow.h b/src/plugins/platforms/windows/qwindowswindow.h index 49e80522b46..38e9fb9a5bd 100644 --- a/src/plugins/platforms/windows/qwindowswindow.h +++ b/src/plugins/platforms/windows/qwindowswindow.h @@ -281,7 +281,7 @@ public: bool handleWmPaint(HWND hwnd, UINT message, WPARAM wParam, LPARAM lParam, LRESULT *result); void handleMoved(); - void handleResized(int wParam); + void handleResized(int wParam, LPARAM lParam); void handleHidden(); void handleCompositionSettingsChanged(); void handleDpiScaledSize(WPARAM wParam, LPARAM lParam, LRESULT *result); |