From 993de241cb91e1b4514f035d3ca1e51ad7ad90c4 Mon Sep 17 00:00:00 2001 From: zhuzichu Date: Mon, 8 Jan 2024 14:07:38 +0800 Subject: [PATCH] fix bug #398 --- src/FluFramelessHelper.cpp | 68 ++++++------------- .../imports/FluentUI/Controls/FluWindow.qml | 3 + 2 files changed, 22 insertions(+), 49 deletions(-) diff --git a/src/FluFramelessHelper.cpp b/src/FluFramelessHelper.cpp index d64a8fc3..efb0d945 100644 --- a/src/FluFramelessHelper.cpp +++ b/src/FluFramelessHelper.cpp @@ -16,24 +16,6 @@ static inline QByteArray qtNativeEventType() return result; } -static inline QColor getAccentColor(){ - typedef HRESULT (WINAPI* DwmGetColorizationColorPtr)(DWORD* pcrColorization,BOOL* pfOpaqueBlend); - HMODULE module = LoadLibraryW(L"dwmapi.dll"); - if (module) - { - DwmGetColorizationColorPtr dwm_get_colorization_color; - dwm_get_colorization_color= reinterpret_cast(GetProcAddress(module, "DwmGetColorizationColor")); - DWORD color = 0; - BOOL bOpaque = FALSE; - if (dwm_get_colorization_color) - { - dwm_get_colorization_color(&color,&bOpaque); - } - return QColor(color); - } - return QColor(); -} - static inline bool isCompositionEnabled(){ typedef HRESULT (WINAPI* DwmIsCompositionEnabledPtr)(BOOL *pfEnabled); HMODULE module = LoadLibraryW(L"dwmapi.dll"); @@ -51,26 +33,6 @@ static inline bool isCompositionEnabled(){ return true; } -static inline void showShadow(HWND hwnd){ - if(isCompositionEnabled()){ - const MARGINS shadow = { 0, 0, 1, 0 }; - typedef HRESULT (WINAPI* DwmExtendFrameIntoClientAreaPtr)(HWND hWnd, const MARGINS *pMarInset); - HMODULE module = LoadLibraryW(L"dwmapi.dll"); - if (module) - { - DwmExtendFrameIntoClientAreaPtr dwm_extendframe_into_client_area_; - dwm_extendframe_into_client_area_= reinterpret_cast(GetProcAddress(module, "DwmExtendFrameIntoClientArea")); - if (dwm_extendframe_into_client_area_) - { - dwm_extendframe_into_client_area_(hwnd, &shadow); - } - } - }else{ - ULONG_PTR cNewStyle = GetClassLongPtr(hwnd, GCL_STYLE) | CS_DROPSHADOW; - SetClassLongPtr(hwnd, GCL_STYLE, cNewStyle); - } -} - #endif FramelessEventFilter::FramelessEventFilter(FluFramelessHelper* helper){ @@ -109,26 +71,35 @@ bool FramelessEventFilter::nativeEventFilter(const QByteArray &eventType, void * const auto clientRect = ((wParam == FALSE) ? reinterpret_cast(lParam) : &(reinterpret_cast(lParam))->rgrc[0]); const LONG originalTop = clientRect->top; const LONG originalLeft = clientRect->left; +#if QT_VERSION < QT_VERSION_CHECK(6,0,0) + const LONG originalRight = clientRect->right; + const LONG originalBottom = clientRect->bottom; +#endif const LRESULT hitTestResult = ::DefWindowProcW(hwnd, WM_NCCALCSIZE, wParam, lParam); if ((hitTestResult != HTERROR) && (hitTestResult != HTNOWHERE)) { *result = hitTestResult; return true; } - int offsetTop = 0; + int offsetSize = 0; bool isMax = IsZoomed(hwnd); offsetXY = QPoint(abs(clientRect->left - originalLeft),abs(clientRect->top - originalTop)); - if(isMax){ - _helper->setOriginalPos(QPoint(originalLeft,originalTop)); - offsetTop = 0; - }else{ - _helper->setOriginalPos({}); - if(FluTools::getInstance()->isWindows11OrGreater()){ - offsetTop = 0; + if(isCompositionEnabled()){ + if(isMax){ + _helper->setOriginalPos(QPoint(originalLeft,originalTop)); + offsetSize = 0; }else{ - offsetTop = 1; + _helper->setOriginalPos({}); + offsetSize = 1; } + }else{ + offsetSize = 0; } - clientRect->top = originalTop+offsetTop; + clientRect->top = originalTop+offsetSize; +#if QT_VERSION < QT_VERSION_CHECK(6,0,0) + clientRect->bottom = originalBottom-offsetSize; + clientRect->left = originalLeft+offsetSize; + clientRect->right = originalRight-offsetSize; +#endif *result = WVR_REDRAW; return true; }if(uMsg == WM_NCHITTEST){ @@ -296,7 +267,6 @@ void FluFramelessHelper::componentComplete(){ SetWindowLongPtr(hwnd, GWL_STYLE, style | WS_THICKFRAME); } SetWindowPos(hwnd,nullptr,0,0,0,0,SWP_NOZORDER | SWP_NOOWNERZORDER | SWP_NOMOVE | SWP_NOSIZE | SWP_FRAMECHANGED); - showShadow(hwnd); #else window->setFlags((window->flags() & (~Qt::WindowMinMaxButtonsHint) & (~Qt::Dialog)) | Qt::FramelessWindowHint | Qt::Window); #endif diff --git a/src/Qt5/imports/FluentUI/Controls/FluWindow.qml b/src/Qt5/imports/FluentUI/Controls/FluWindow.qml index 31f4b7b8..51516d53 100644 --- a/src/Qt5/imports/FluentUI/Controls/FluWindow.qml +++ b/src/Qt5/imports/FluentUI/Controls/FluWindow.qml @@ -209,6 +209,9 @@ Window { anchors{ fill:parent topMargin: _offsetXY.y + bottomMargin: _offsetXY.y + leftMargin: _offsetXY.x + rightMargin: _offsetXY.x } onWidthChanged: { window.appBar.width = width