From 5f6745b630ff5f3511a2ead87fc4b6e90d2d5314 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E6=9C=B1=E5=AD=90=E6=A5=9A=5Czhuzi?= Date: Sun, 28 Apr 2024 13:03:20 +0800 Subject: [PATCH] udpate --- src/FluFrameless.cpp | 117 ++++++++---------- .../imports/FluentUI/Controls/FluWindow.qml | 8 +- .../imports/FluentUI/Controls/FluWindow.qml | 8 +- 3 files changed, 53 insertions(+), 80 deletions(-) diff --git a/src/FluFrameless.cpp b/src/FluFrameless.cpp index 4258b7ef..6f92e2c7 100644 --- a/src/FluFrameless.cpp +++ b/src/FluFrameless.cpp @@ -73,12 +73,7 @@ void FluFrameless::componentComplete() { int w = window()->width(); int h = window()->height(); _current = window()->winId(); - window()->setFlags((window()->flags()) | Qt::CustomizeWindowHint | Qt::WindowMinimizeButtonHint | Qt::WindowCloseButtonHint | Qt::FramelessWindowHint); -#if QT_VERSION < QT_VERSION_CHECK(6, 0, 0) - if (QQuickWindow::sceneGraphBackend() == "software") { - window()->setFlag(Qt::FramelessWindowHint, false); - } -#endif + window()->setFlags((window()->flags()) | Qt::CustomizeWindowHint | Qt::WindowMinimizeButtonHint | Qt::WindowCloseButtonHint); if (!_fixSize) { window()->setFlag(Qt::WindowMaximizeButtonHint); } @@ -97,14 +92,14 @@ void FluFrameless::componentComplete() { HWND hwnd = reinterpret_cast(window()->winId()); DWORD style = ::GetWindowLongPtr(hwnd, GWL_STYLE); if (_fixSize) { - ::SetWindowLongPtr(hwnd, GWL_STYLE, style | WS_THICKFRAME); + ::SetWindowLongPtr(hwnd, GWL_STYLE, style | WS_CAPTION); for (int i = 0; i <= QGuiApplication::screens().count() - 1; ++i) { connect(QGuiApplication::screens().at(i), &QScreen::logicalDotsPerInchChanged, this, [=] { SetWindowPos(hwnd, nullptr, 0, 0, 0, 0, SWP_NOZORDER | SWP_NOOWNERZORDER | SWP_NOMOVE | SWP_FRAMECHANGED); }); } } else { - ::SetWindowLongPtr(hwnd, GWL_STYLE, style | WS_MAXIMIZEBOX | WS_THICKFRAME); + ::SetWindowLongPtr(hwnd, GWL_STYLE, style | WS_MAXIMIZEBOX | WS_CAPTION); } SetWindowPos(hwnd, nullptr, 0, 0, 0, 0, SWP_NOZORDER | SWP_NOOWNERZORDER | SWP_NOMOVE | SWP_NOSIZE | SWP_FRAMECHANGED); connect(window(), &QQuickWindow::screenChanged, this, [hwnd] { @@ -151,29 +146,22 @@ void FluFrameless::componentComplete() { return false; } else if (uMsg == WM_NCCALCSIZE) { const auto clientRect = ((wParam == FALSE) ? reinterpret_cast(lParam) : &(reinterpret_cast(lParam))->rgrc[0]); - const LONG originalTop = clientRect->top; - const LONG originalLeft = clientRect->left; - const LONG originalRight = clientRect->right; - const LONG originalBottom = clientRect->bottom; - const LRESULT hitTestResult = ::DefWindowProcW(hwnd, WM_NCCALCSIZE, wParam, lParam); - if ((hitTestResult != HTERROR) && (hitTestResult != HTNOWHERE)) { - *result = static_cast(hitTestResult); - return true; - } - int offsetSize; bool isMaximum = ::IsZoomed(hwnd); - if (isMaximum || _isFullScreen()) { - offsetSize = 0; - } else { - offsetSize = 1; + if (!isMaximum){ + if (clientRect->top != 0) + { + clientRect->top -= 1; + clientRect->bottom -= 1; + } + } else{ + const LONG originalTop = clientRect->top; + const LRESULT hitTestResult = ::DefWindowProcW(hwnd, WM_NCCALCSIZE, wParam, lParam); + if ((hitTestResult != HTERROR) && (hitTestResult != HTNOWHERE)) { + *result = static_cast(hitTestResult); + return true; + } + clientRect->top = originalTop-originalTop; } - if (!isCompositionEnabled()) { - offsetSize = 0; - } - clientRect->top = originalTop + offsetSize; - clientRect->bottom = originalBottom - offsetSize; - clientRect->left = originalLeft + offsetSize; - clientRect->right = originalRight - offsetSize; _setMaximizeHovered(false); *result = WVR_REDRAW; return true; @@ -230,6 +218,18 @@ void FluFrameless::componentComplete() { } *result = HTCLIENT; return true; + } else if (uMsg == WM_NCPAINT) { + if(isCompositionEnabled()){ + return false; + } + *result = FALSE; + return true; + } else if (uMsg == WM_NCACTIVATE) { + if(isCompositionEnabled()){ + return false; + } + *result = TRUE; + return true; } else if (_isWindows11OrGreater && (uMsg == WM_NCLBUTTONDBLCLK || uMsg == WM_NCLBUTTONDOWN)) { if (_hitMaximizeButton()) { QMouseEvent event = QMouseEvent(QEvent::MouseButtonPress, QPoint(), QPoint(), Qt::LeftButton, Qt::LeftButton, Qt::NoModifier); @@ -244,23 +244,8 @@ void FluFrameless::componentComplete() { _setMaximizePressed(false); return true; } - } else if (uMsg == WM_NCPAINT) { - *result = FALSE; + } else if (uMsg == WM_ERASEBKGND) { return true; - } else if (uMsg == WM_NCACTIVATE) { - *result = static_cast(::DefWindowProcW(hwnd, WM_NCACTIVATE, wParam, -1)); - return true; - } else if (uMsg == WM_GETMINMAXINFO) { - auto *minmaxInfo = reinterpret_cast(lParam); - auto pixelRatio = window()->devicePixelRatio(); - auto geometry = window()->screen()->availableGeometry(); - RECT rect; - SystemParametersInfo(SPI_GETWORKAREA, 0, &rect, 0); - minmaxInfo->ptMaxPosition.x = rect.left; - minmaxInfo->ptMaxPosition.y = rect.top; - minmaxInfo->ptMaxSize.x = qRound(geometry.width() * pixelRatio); - minmaxInfo->ptMaxSize.y = qRound(geometry.height() * pixelRatio); - return false; } else if (uMsg == WM_NCRBUTTONDOWN) { if (wParam == HTCAPTION) { _showSystemMenu(QCursor::pos()); @@ -358,27 +343,27 @@ void FluFrameless::_setMaximizeHovered(bool val) { void FluFrameless::_updateCursor(int edges) { switch (edges) { - case 0: - window()->setCursor(Qt::ArrowCursor); - break; - case Qt::LeftEdge: - case Qt::RightEdge: - window()->setCursor(Qt::SizeHorCursor); - break; - case Qt::TopEdge: - case Qt::BottomEdge: - window()->setCursor(Qt::SizeVerCursor); - break; - case Qt::LeftEdge | Qt::TopEdge: - case Qt::RightEdge | Qt::BottomEdge: - window()->setCursor(Qt::SizeFDiagCursor); - break; - case Qt::RightEdge | Qt::TopEdge: - case Qt::LeftEdge | Qt::BottomEdge: - window()->setCursor(Qt::SizeBDiagCursor); - break; - default: - break; + case 0: + window()->setCursor(Qt::ArrowCursor); + break; + case Qt::LeftEdge: + case Qt::RightEdge: + window()->setCursor(Qt::SizeHorCursor); + break; + case Qt::TopEdge: + case Qt::BottomEdge: + window()->setCursor(Qt::SizeVerCursor); + break; + case Qt::LeftEdge | Qt::TopEdge: + case Qt::RightEdge | Qt::BottomEdge: + window()->setCursor(Qt::SizeFDiagCursor); + break; + case Qt::RightEdge | Qt::TopEdge: + case Qt::LeftEdge | Qt::BottomEdge: + window()->setCursor(Qt::SizeBDiagCursor); + break; + default: + break; } } diff --git a/src/Qt5/imports/FluentUI/Controls/FluWindow.qml b/src/Qt5/imports/FluentUI/Controls/FluWindow.qml index 10a099d5..f850f236 100644 --- a/src/Qt5/imports/FluentUI/Controls/FluWindow.qml +++ b/src/Qt5/imports/FluentUI/Controls/FluWindow.qml @@ -279,13 +279,7 @@ Window { id:loader_border anchors.fill: parent sourceComponent: { - if(window.useSystemAppBar){ - return undefined - } - if(FluTools.isWindows10OrGreater()){ - return undefined - } - if(window.visibility === Window.Maximized || window.visibility === Window.FullScreen){ + if(window.useSystemAppBar || FluTools.isWin() || window.visibility === Window.Maximized || window.visibility === Window.FullScreen){ return undefined } return com_border diff --git a/src/Qt6/imports/FluentUI/Controls/FluWindow.qml b/src/Qt6/imports/FluentUI/Controls/FluWindow.qml index 16dd0a33..e9ad4185 100644 --- a/src/Qt6/imports/FluentUI/Controls/FluWindow.qml +++ b/src/Qt6/imports/FluentUI/Controls/FluWindow.qml @@ -278,13 +278,7 @@ Window { id:loader_border anchors.fill: parent sourceComponent: { - if(window.useSystemAppBar){ - return undefined - } - if(FluTools.isWindows10OrGreater()){ - return undefined - } - if(window.visibility === Window.Maximized || window.visibility === Window.FullScreen){ + if(window.useSystemAppBar || FluTools.isWin() || window.visibility === Window.Maximized || window.visibility === Window.FullScreen){ return undefined } return com_border