diff options
| author | Wladimir Leuschner <[email protected]> | 2024-11-05 14:37:24 +0000 |
|---|---|---|
| committer | The Qt Project <[email protected]> | 2024-11-05 19:06:28 +0000 |
| commit | 7d62b54713720c62dfae3e26041cd688b368c12d (patch) | |
| tree | 6838c45aa28ac1e887c1fce1fb1731334b549e8f | |
| parent | 12b41c3332612eb26b7b8598c0a94a4f0d709787 (diff) | |
Revert "Windows QPA: improve Qt::FramlessWindowHint windows"
This reverts commit 1a6ab689d5858e5997c989ce6c3574fb591438b0.
Reason for revert: Regression: FrameLessWindows have borders now when they should not.
Change-Id: Ia975acf6f63a44e2ff3362aa573b1d9b11f7edd9
Reviewed-by: Tor Arne Vestbø <[email protected]>
Reviewed-by: Oliver Wolff <[email protected]>
| -rw-r--r-- | src/plugins/platforms/windows/qwindowscontext.cpp | 4 | ||||
| -rw-r--r-- | src/plugins/platforms/windows/qwindowswindow.cpp | 112 | ||||
| -rw-r--r-- | src/plugins/platforms/windows/qwindowswindow.h | 2 | ||||
| -rw-r--r-- | tests/auto/widgets/kernel/qwidget/tst_qwidget.cpp | 6 |
4 files changed, 38 insertions, 86 deletions
diff --git a/src/plugins/platforms/windows/qwindowscontext.cpp b/src/plugins/platforms/windows/qwindowscontext.cpp index 96cf60b6657..65ddd4f4e98 100644 --- a/src/plugins/platforms/windows/qwindowscontext.cpp +++ b/src/plugins/platforms/windows/qwindowscontext.cpp @@ -1100,7 +1100,7 @@ bool QWindowsContext::windowsProc(HWND hwnd, UINT message, } return false; case QtWindows::CalculateSize: - return QWindowsGeometryHint::handleCalculateSize(d->m_creationContext->window, d->m_creationContext->customMargins, msg, result); + return QWindowsGeometryHint::handleCalculateSize(d->m_creationContext->customMargins, msg, result); case QtWindows::GeometryChangingEvent: return QWindowsWindow::handleGeometryChangingMessage(&msg, d->m_creationContext->window, d->m_creationContext->margins + d->m_creationContext->customMargins); @@ -1165,7 +1165,7 @@ bool QWindowsContext::windowsProc(HWND hwnd, UINT message, platformWindow->getSizeHints(reinterpret_cast<MINMAXINFO *>(lParam)); return true;// maybe available on some SDKs revisit WM_NCCALCSIZE case QtWindows::CalculateSize: - return QWindowsGeometryHint::handleCalculateSize(platformWindow->window(), platformWindow->customMargins(), msg, result); + return QWindowsGeometryHint::handleCalculateSize(platformWindow->customMargins(), msg, result); case QtWindows::NonClientHitTest: return platformWindow->handleNonClientHitTest(QPoint(msg.pt.x, msg.pt.y), result); case QtWindows::GeometryChangingEvent: diff --git a/src/plugins/platforms/windows/qwindowswindow.cpp b/src/plugins/platforms/windows/qwindowswindow.cpp index 8202ff27e9d..842067da3c5 100644 --- a/src/plugins/platforms/windows/qwindowswindow.cpp +++ b/src/plugins/platforms/windows/qwindowswindow.cpp @@ -772,7 +772,12 @@ void WindowCreationData::fromWindow(const QWindow *w, const Qt::WindowFlags flag if (popup || (type == Qt::ToolTip) || (type == Qt::SplashScreen)) { style = WS_POPUP; } else if (topLevel) { - style = WS_OVERLAPPED; + if (flags & Qt::FramelessWindowHint) + style = WS_POPUP; // no border + else if (flags & Qt::WindowTitleHint) + style = WS_OVERLAPPED; + else + style = 0; } else { style = WS_CHILD; } @@ -781,15 +786,16 @@ void WindowCreationData::fromWindow(const QWindow *w, const Qt::WindowFlags flag if (topLevel) { if ((type == Qt::Window || dialog || tool)) { - if (!(flags & Qt::FramelessWindowHint)) + if (!(flags & Qt::FramelessWindowHint)) { style |= WS_POPUP; - if (flags & Qt::MSWindowsFixedSizeDialogHint) { - style |= WS_DLGFRAME; - } else { - style |= WS_THICKFRAME; + if (flags & Qt::MSWindowsFixedSizeDialogHint) { + style |= WS_DLGFRAME; + } else { + style |= WS_THICKFRAME; + } + if (flags & Qt::WindowTitleHint) + style |= WS_CAPTION; // Contains WS_DLGFRAME } - if (flags & Qt::WindowTitleHint) - style |= WS_CAPTION; // Contains WS_DLGFRAME if (flags & Qt::WindowSystemMenuHint) style |= WS_SYSMENU; else if (dialog && (flags & Qt::WindowCloseButtonHint) && !(flags & Qt::FramelessWindowHint)) { @@ -809,15 +815,8 @@ void WindowCreationData::fromWindow(const QWindow *w, const Qt::WindowFlags flag if ((flags & Qt::WindowContextHelpButtonHint) && !showMinimizeButton && !showMaximizeButton) exStyle |= WS_EX_CONTEXTHELP; - if (flags & Qt::FramelessWindowHint) { - style |= WS_CAPTION; // Needed for aero - style |= WS_SYSMENU; // Needed for taskbar shortcuts - style |= WS_THICKFRAME; - style |= WS_MINIMIZEBOX; // Needed for minimize animations - style |= WS_MAXIMIZEBOX; // Needed for maximize animations - } } else { - exStyle |= WS_EX_TOOLWINDOW; + exStyle |= WS_EX_TOOLWINDOW; } // make mouse events fall through this window @@ -976,13 +975,9 @@ void WindowCreationData::initialize(const QWindow *w, HWND hwnd, bool frameChang if (flags & (Qt::CustomizeWindowHint|Qt::WindowTitleHint)) { HMENU systemMenu = GetSystemMenu(hwnd, FALSE); if (flags & Qt::WindowCloseButtonHint) - EnableMenuItem(systemMenu, SC_CLOSE, MF_BYCOMMAND | MF_ENABLED); + EnableMenuItem(systemMenu, SC_CLOSE, MF_BYCOMMAND|MF_ENABLED); else - EnableMenuItem(systemMenu, SC_CLOSE, MF_BYCOMMAND | MF_GRAYED); - } - if (flags & Qt::FramelessWindowHint) { // Gives us the rounded corners looks and the frame shadow - MARGINS margins = { -1, -1, -1, -1 }; - DwmExtendFrameIntoClientArea(hwnd, &margins); + EnableMenuItem(systemMenu, SC_CLOSE, MF_BYCOMMAND|MF_GRAYED); } updateGLWindowSettings(w, hwnd, flags, opacityLevel); } else { // child. @@ -1111,29 +1106,8 @@ QMargins QWindowsGeometryHint::frame(const QWindow *w, const QRect &geometry, return QWindowsGeometryHint::frame(w, style, exStyle, dpi); } -bool QWindowsGeometryHint::handleCalculateSize(const QWindow *window, const QMargins &customMargins, const MSG &msg, LRESULT *result) -{ - // Return 0 to remove the window's border - QWindowsWindow *w = QWindowsWindow::windowsWindowOf(window); - bool frameless = w ? w->isFrameless() : window->flags() & Qt::FramelessWindowHint; - if (msg.wParam && frameless) { - //Query for fullscreen - QUERY_USER_NOTIFICATION_STATE quns; - SHQueryUserNotificationState(&quns); - - // Prevent content from being cutoff by border for maximized, but not fullscreened windows. - if (IsZoomed(msg.hwnd) && quns == QUNS_ACCEPTS_NOTIFICATIONS) { - auto *ncp = reinterpret_cast<NCCALCSIZE_PARAMS *>(msg.lParam); - RECT *clientArea = &ncp->rgrc[0]; - const int border = getResizeBorderThickness(QWindowsWindow::windowsWindowOf(window)->savedDpi()); - clientArea->top += border; - clientArea->bottom -= border; - clientArea->left += border; - clientArea->right -= border; - } - *result = msg.wParam ? WVR_REDRAW : 0; - return true; - } +bool QWindowsGeometryHint::handleCalculateSize(const QMargins &customMargins, const MSG &msg, LRESULT *result) +{ // NCCALCSIZE_PARAMS structure if wParam==TRUE if (!msg.wParam || customMargins.isNull()) return false; @@ -2203,11 +2177,13 @@ void QWindowsWindow::handleMoved() void QWindowsWindow::handleResized(int wParam, LPARAM lParam) { - /* Prevents windows with no frame from covering the taskbar when maximized. */ - if (m_data.flags.testFlag(Qt::CustomizeWindowHint) && !m_data.flags.testFlag(Qt::WindowTitleHint) + /* 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); @@ -2218,11 +2194,13 @@ void QWindowsWindow::handleResized(int wParam, LPARAM lParam) int correctWidth = monitorInfo.rcWork.right - monitorInfo.rcWork.left; int correctHeight = monitorInfo.rcWork.bottom - monitorInfo.rcWork.top; - const int borderWidth = invisibleMargins(m_data.hwnd).left(); - correctLeft -= borderWidth; - correctTop -= borderWidth; - correctWidth += borderWidth * 2; - correctHeight += borderWidth * 2; + 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" @@ -3161,35 +3139,8 @@ void QWindowsWindow::getSizeHints(MINMAXINFO *mmi) const bool QWindowsWindow::handleNonClientHitTest(const QPoint &globalPos, LRESULT *result) const { - const QWindow *w = window(); - const QPoint localPos = w->mapFromGlobal(QHighDpi::fromNativePixels(globalPos, w)); - - if (m_data.flags & Qt::FramelessWindowHint) { - const int border = (IsZoomed(m_data.hwnd) || isFullScreen_sys()) ? 0 : getResizeBorderThickness(savedDpi()); - if (border == 0) { - *result = HTCLIENT; - return true; - } - - const bool left = (globalPos.x() >= geometry().left()) && (globalPos.x() < geometry().left() + border); - const bool right = (globalPos.x() > geometry().right() - border) && (globalPos.x() <= geometry().right()); - const bool top = (globalPos.y() >= geometry().top()) && (globalPos.y() < geometry().top() + border); - const bool bottom = (globalPos.y() > geometry().bottom() - border) && (globalPos.y() <= geometry().bottom()); - - if (left || right || top || bottom) { - if (left) - *result = top ? HTTOPLEFT : (bottom ? HTBOTTOMLEFT : HTLEFT); - else if (right) - *result = top ? HTTOPRIGHT : (bottom ? HTBOTTOMRIGHT : HTRIGHT); - else - *result = top ? HTTOP : HTBOTTOM; - } else { - *result = HTCLIENT; - } - return true; - } - // QTBUG-32663, suppress resize cursor for fixed size windows. + const QWindow *w = window(); if (!w->isTopLevel() // Task 105852, minimized windows need to respond to user input. || (m_windowState != Qt::WindowNoState) || !isActive() @@ -3204,6 +3155,7 @@ bool QWindowsWindow::handleNonClientHitTest(const QPoint &globalPos, LRESULT *re const bool fixedHeight = minimumSize.height() == maximumSize.height(); if (!fixedWidth && !fixedHeight) return false; + const QPoint localPos = w->mapFromGlobal(QHighDpi::fromNativePixels(globalPos, w)); const QSize size = w->size(); if (fixedHeight) { if (localPos.y() >= size.height()) { diff --git a/src/plugins/platforms/windows/qwindowswindow.h b/src/plugins/platforms/windows/qwindowswindow.h index 3ec3ba55a43..8508392f44a 100644 --- a/src/plugins/platforms/windows/qwindowswindow.h +++ b/src/plugins/platforms/windows/qwindowswindow.h @@ -33,7 +33,7 @@ struct QWindowsGeometryHint static QMargins frame(const QWindow *w, HWND hwnd); static QMargins frame(const QWindow *w, const QRect &geometry, DWORD style, DWORD exStyle); - static bool handleCalculateSize(const QWindow *window, const QMargins &customMargins, const MSG &msg, LRESULT *result); + static bool handleCalculateSize(const QMargins &customMargins, const MSG &msg, LRESULT *result); static void applyToMinMaxInfo(const QWindow *w, const QScreen *screen, const QMargins &margins, MINMAXINFO *mmi); static void applyToMinMaxInfo(const QWindow *w, const QMargins &margins, diff --git a/tests/auto/widgets/kernel/qwidget/tst_qwidget.cpp b/tests/auto/widgets/kernel/qwidget/tst_qwidget.cpp index fee23a73970..f77a63abefb 100644 --- a/tests/auto/widgets/kernel/qwidget/tst_qwidget.cpp +++ b/tests/auto/widgets/kernel/qwidget/tst_qwidget.cpp @@ -646,7 +646,7 @@ void tst_QWidget::getSetCheck() #if defined (Q_OS_WIN) obj1.setWindowFlags(Qt::FramelessWindowHint | Qt::WindowSystemMenuHint); const HWND handle = reinterpret_cast<HWND>(obj1.winId()); // explicitly create window handle - QVERIFY((GetWindowLongPtr(handle, GWL_STYLE) & LONG_PTR(WS_OVERLAPPED)) == 0); + QVERIFY(GetWindowLongPtr(handle, GWL_STYLE) & LONG_PTR(WS_POPUP)); #endif } @@ -9838,7 +9838,7 @@ public: public slots: void resizeMe() { - resize(150, 150); + resize(100, 100); } }; @@ -9850,7 +9850,7 @@ void tst_QWidget::moveInResizeEvent() testWidget.show(); QVERIFY(QTest::qWaitForWindowExposed(&testWidget)); - QRect expectedGeometry(100,100, 150, 150); + QRect expectedGeometry(100,100, 100, 100); QTRY_COMPARE(testWidget.geometry(), expectedGeometry); } |
