From bf5c722058702e6e311bb5e42687fa3746e28c81 Mon Sep 17 00:00:00 2001 From: zhuzichu Date: Fri, 29 Dec 2023 11:04:54 +0800 Subject: [PATCH] update --- src/FluFramelessHelper.cpp | 23 ++++--------------- src/FluTools.cpp | 2 +- .../imports/FluentUI/Controls/FluWindow.qml | 20 +++++++++++++++- .../imports/FluentUI/Controls/FluWindow.qml | 20 +++++++++++++++- 4 files changed, 43 insertions(+), 22 deletions(-) diff --git a/src/FluFramelessHelper.cpp b/src/FluFramelessHelper.cpp index 131a770c..87dbaea7 100644 --- a/src/FluFramelessHelper.cpp +++ b/src/FluFramelessHelper.cpp @@ -22,7 +22,7 @@ static inline bool isWindows11OrGreater() { if (dwVersion < 0x80000000) dwBuild = (DWORD)(HIWORD(dwVersion)); #pragma warning(pop) - return dwBuild < 22000; + return dwBuild >= 22000; } @@ -54,7 +54,7 @@ static inline bool isCompositionEnabled(){ static inline void showShadow(HWND hwnd){ if(isCompositionEnabled()){ - const MARGINS shadow = { 1, 0, 0, 0 }; + const MARGINS shadow = { 0, 0, 1, 0 }; typedef HRESULT (WINAPI* DwmExtendFrameIntoClientAreaPtr)(HWND hWnd, const MARGINS *pMarInset); HMODULE module = LoadLibraryW(L"dwmapi.dll"); if (module) @@ -110,20 +110,6 @@ bool FramelessEventFilter::nativeEventFilter(const QByteArray &eventType, void * } return false; }else if(uMsg == WM_NCCALCSIZE){ - NCCALCSIZE_PARAMS* sz = reinterpret_cast(lParam); - if(IsZoomed(hwnd)){ - sz->rgrc[0].left += 8; - sz->rgrc[0].top += 8; - sz->rgrc[0].right -= 8; - sz->rgrc[0].bottom -= isTaskbarAutoHide() ? 9 : 8; - }else{ - sz->rgrc[0].top += isWindows11OrGreater() ? 0 : 1; - if(isCompositionEnabled()){ - sz->rgrc[0].right -= 8; - sz->rgrc[0].bottom -= 8; - sz->rgrc[0].left -= -8; - } - } *result = WVR_REDRAW; return true; }else if(uMsg == WM_NCPAINT){ @@ -269,9 +255,7 @@ void FluFramelessHelper::componentComplete(){ } if(!window.isNull()){ #ifdef Q_OS_WIN - if(!isCompositionEnabled()){ - window->setFlag(Qt::FramelessWindowHint,true); - } + window->setFlags(window->flags() | Qt::FramelessWindowHint | Qt::WindowMinimizeButtonHint); _nativeEvent =new FramelessEventFilter(this); qApp->installNativeEventFilter(_nativeEvent); HWND hwnd = reinterpret_cast(window->winId()); @@ -282,6 +266,7 @@ void FluFramelessHelper::componentComplete(){ SetWindowLongPtr(hwnd, GWL_STYLE, style | WS_THICKFRAME | WS_CAPTION); } 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/FluTools.cpp b/src/FluTools.cpp index 42bf203e..63e91376 100644 --- a/src/FluTools.cpp +++ b/src/FluTools.cpp @@ -208,7 +208,7 @@ bool FluTools::isWindows11OrGreater(){ if (dwVersion < 0x80000000) dwBuild = (DWORD)(HIWORD(dwVersion)); #pragma warning(pop) - return dwBuild < 22000; + return dwBuild >= 22000; #endif var = QVariant::fromValue(false); return false; diff --git a/src/Qt5/imports/FluentUI/Controls/FluWindow.qml b/src/Qt5/imports/FluentUI/Controls/FluWindow.qml index 5defad10..f97de0ca 100644 --- a/src/Qt5/imports/FluentUI/Controls/FluWindow.qml +++ b/src/Qt5/imports/FluentUI/Controls/FluWindow.qml @@ -53,6 +53,7 @@ Window { signal showSystemMenu signal initArgument(var argument) signal firstVisible() + property point _offsetXY : Qt.point(0,0) id:window color:"transparent" Component.onCompleted: { @@ -72,6 +73,19 @@ Window { Component.onDestruction: { lifecycle.onDestruction() } + onVisibilityChanged: { + if(visibility === Window.Maximized || visibility === Window.FullScreen){ + var dx = window.x-Screen.virtualX + var dy = window.y-Screen.virtualY + if(dx<0 && dy<0){ + _offsetXY = Qt.point(Math.abs(dx+1),Math.abs(dy+1)) + }else{ + _offsetXY = Qt.point(0,0) + } + }else{ + _offsetXY = Qt.point(0,0) + } + } onShowSystemMenu: { if(loader_frameless_helper.item){ loader_frameless_helper.item.showSystemMenu() @@ -177,6 +191,10 @@ Window { id:layout_container anchors{ fill:parent + leftMargin: _offsetXY.x + rightMargin: _offsetXY.x + topMargin: _offsetXY.y + bottomMargin: _offsetXY.y } onWidthChanged: { window.appBar.width = width @@ -229,7 +247,7 @@ Window { border.width: window.resizeBorderWidth border.color: window.resizeBorderColor visible: { - if(window.useSystemAppBar || FluTools.isWin()){ + if(window.useSystemAppBar){ return false } if(window.visibility == Window.Maximized || window.visibility == Window.FullScreen){ diff --git a/src/Qt6/imports/FluentUI/Controls/FluWindow.qml b/src/Qt6/imports/FluentUI/Controls/FluWindow.qml index c7bbdf1c..ecc18978 100644 --- a/src/Qt6/imports/FluentUI/Controls/FluWindow.qml +++ b/src/Qt6/imports/FluentUI/Controls/FluWindow.qml @@ -52,6 +52,7 @@ Window { signal showSystemMenu signal initArgument(var argument) signal firstVisible() + property point _offsetXY : Qt.point(0,0) id:window color:"transparent" Component.onCompleted: { @@ -71,6 +72,19 @@ Window { Component.onDestruction: { lifecycle.onDestruction() } + onVisibilityChanged: { + if(visibility === Window.Maximized || visibility === Window.FullScreen){ + var dx = window.x-Screen.virtualX + var dy = window.y-Screen.virtualY + if(dx<0 && dy<0){ + _offsetXY = Qt.point(Math.abs(dx+1),Math.abs(dy+1)) + }else{ + _offsetXY = Qt.point(0,0) + } + }else{ + _offsetXY = Qt.point(0,0) + } + } onShowSystemMenu: { if(loader_frameless_helper.item){ loader_frameless_helper.item.showSystemMenu() @@ -176,6 +190,10 @@ Window { id:layout_container anchors{ fill:parent + leftMargin: _offsetXY.x + rightMargin: _offsetXY.x + topMargin: _offsetXY.y + bottomMargin: _offsetXY.y } onWidthChanged: { window.appBar.width = width @@ -228,7 +246,7 @@ Window { border.width: window.resizeBorderWidth border.color: window.resizeBorderColor visible: { - if(window.useSystemAppBar || FluTools.isWin()){ + if(window.useSystemAppBar){ return false } if(window.visibility == Window.Maximized || window.visibility == Window.FullScreen){