From 8253fb611f313ea178b3e6b3778cbc63138f07a2 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E6=9C=B1=E5=AD=90=E6=A5=9A=5Czhuzi?= Date: Fri, 29 Dec 2023 00:40:18 +0800 Subject: [PATCH] update --- src/FluFramelessHelper.cpp | 48 ++++++++++++++++--- src/FluTools.cpp | 17 +++---- .../imports/FluentUI/Controls/FluWindow.qml | 20 +------- .../imports/FluentUI/Controls/FluWindow.qml | 20 +------- 4 files changed, 53 insertions(+), 52 deletions(-) diff --git a/src/FluFramelessHelper.cpp b/src/FluFramelessHelper.cpp index db74b522..131a770c 100644 --- a/src/FluFramelessHelper.cpp +++ b/src/FluFramelessHelper.cpp @@ -1,7 +1,6 @@ #include "FluFramelessHelper.h" #include -#include "FluTools.h" #ifdef Q_OS_WIN #pragma comment (lib,"user32.lib") #pragma comment (lib,"dwmapi.lib") @@ -14,6 +13,28 @@ static inline QByteArray qtNativeEventType() return result; } +static inline bool isWindows11OrGreater() { + DWORD dwVersion = 0; + DWORD dwBuild = 0; +#pragma warning(push) +#pragma warning(disable : 4996) + dwVersion = GetVersion(); + if (dwVersion < 0x80000000) + dwBuild = (DWORD)(HIWORD(dwVersion)); +#pragma warning(pop) + return dwBuild < 22000; +} + + +static inline bool isTaskbarAutoHide() { + APPBARDATA appBarData; + memset(&appBarData, 0, sizeof(appBarData)); + appBarData.cbSize = sizeof(appBarData); + appBarData.hWnd = FindWindowW(L"Shell_TrayWnd", NULL); + LPARAM lParam = SHAppBarMessage(ABM_GETSTATE, &appBarData); + return lParam & ABS_AUTOHIDE; +} + static inline bool isCompositionEnabled(){ typedef HRESULT (WINAPI* DwmIsCompositionEnabledPtr)(BOOL *pfEnabled); HMODULE module = LoadLibraryW(L"dwmapi.dll"); @@ -89,6 +110,20 @@ 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){ @@ -104,7 +139,7 @@ bool FramelessEventFilter::nativeEventFilter(const QByteArray &eventType, void * } return false; }else if(uMsg == WM_NCHITTEST){ - if(FluTools::getInstance()->isWindows11OrGreater() && _helper->hoverMaxBtn() && _helper->resizeable()){ + if(isWindows11OrGreater() && _helper->hoverMaxBtn() && _helper->resizeable()){ if (*result == HTNOWHERE) { *result = HTZOOM; } @@ -112,14 +147,14 @@ bool FramelessEventFilter::nativeEventFilter(const QByteArray &eventType, void * } return false; }else if(uMsg == WM_NCLBUTTONDBLCLK || uMsg == WM_NCLBUTTONDOWN){ - if(FluTools::getInstance()->isWindows11OrGreater() && _helper->hoverMaxBtn() && _helper->resizeable()){ + if(isWindows11OrGreater() && _helper->hoverMaxBtn() && _helper->resizeable()){ QMouseEvent event = QMouseEvent(QEvent::MouseButtonPress, QPoint(), QPoint(), Qt::LeftButton, Qt::LeftButton, Qt::NoModifier); QGuiApplication::sendEvent(_helper->maximizeButton(),&event); return true; } return false; }else if(uMsg == WM_NCLBUTTONUP || uMsg == WM_NCRBUTTONUP){ - if(FluTools::getInstance()->isWindows11OrGreater() && _helper->hoverMaxBtn() && _helper->resizeable()){ + if(isWindows11OrGreater() && _helper->hoverMaxBtn() && _helper->resizeable()){ QMouseEvent event = QMouseEvent(QEvent::MouseButtonRelease, QPoint(), QPoint(), Qt::LeftButton, Qt::LeftButton, Qt::NoModifier); QGuiApplication::sendEvent(_helper->maximizeButton(),&event); } @@ -234,7 +269,9 @@ void FluFramelessHelper::componentComplete(){ } if(!window.isNull()){ #ifdef Q_OS_WIN - window->setFlags(window->flags() | Qt::FramelessWindowHint | Qt::WindowMinimizeButtonHint); + if(!isCompositionEnabled()){ + window->setFlag(Qt::FramelessWindowHint,true); + } _nativeEvent =new FramelessEventFilter(this); qApp->installNativeEventFilter(_nativeEvent); HWND hwnd = reinterpret_cast(window->winId()); @@ -244,7 +281,6 @@ void FluFramelessHelper::componentComplete(){ }else{ SetWindowLongPtr(hwnd, GWL_STYLE, style | WS_THICKFRAME | WS_CAPTION); } - showShadow(hwnd); SetWindowPos(hwnd,nullptr,0,0,0,0,SWP_NOZORDER | SWP_NOOWNERZORDER | SWP_NOMOVE | SWP_NOSIZE | SWP_FRAMECHANGED); #else window->setFlags((window->flags() & (~Qt::WindowMinMaxButtonsHint) & (~Qt::Dialog)) | Qt::FramelessWindowHint | Qt::Window); diff --git a/src/FluTools.cpp b/src/FluTools.cpp index 046922e8..42bf203e 100644 --- a/src/FluTools.cpp +++ b/src/FluTools.cpp @@ -200,14 +200,15 @@ bool FluTools::isWindows11OrGreater(){ static QVariant var; if(var.isNull()){ #if defined(Q_OS_WIN) - QSettings regKey {QString::fromUtf8("HKEY_LOCAL_MACHINE\\SOFTWARE\\Microsoft\\Windows NT\\CurrentVersion"), QSettings::NativeFormat}; - if (regKey.contains(QString::fromUtf8("CurrentBuildNumber"))) { - auto buildNumber = regKey.value(QString::fromUtf8("CurrentBuildNumber")).toInt(); - if(buildNumber>=22000){ - var = QVariant::fromValue(true); - return true; - } - } + DWORD dwVersion = 0; + DWORD dwBuild = 0; +#pragma warning(push) +#pragma warning(disable : 4996) + dwVersion = GetVersion(); + if (dwVersion < 0x80000000) + dwBuild = (DWORD)(HIWORD(dwVersion)); +#pragma warning(pop) + 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 f97de0ca..5defad10 100644 --- a/src/Qt5/imports/FluentUI/Controls/FluWindow.qml +++ b/src/Qt5/imports/FluentUI/Controls/FluWindow.qml @@ -53,7 +53,6 @@ Window { signal showSystemMenu signal initArgument(var argument) signal firstVisible() - property point _offsetXY : Qt.point(0,0) id:window color:"transparent" Component.onCompleted: { @@ -73,19 +72,6 @@ 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() @@ -191,10 +177,6 @@ Window { id:layout_container anchors{ fill:parent - leftMargin: _offsetXY.x - rightMargin: _offsetXY.x - topMargin: _offsetXY.y - bottomMargin: _offsetXY.y } onWidthChanged: { window.appBar.width = width @@ -247,7 +229,7 @@ Window { border.width: window.resizeBorderWidth border.color: window.resizeBorderColor visible: { - if(window.useSystemAppBar){ + if(window.useSystemAppBar || FluTools.isWin()){ 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 ecc18978..c7bbdf1c 100644 --- a/src/Qt6/imports/FluentUI/Controls/FluWindow.qml +++ b/src/Qt6/imports/FluentUI/Controls/FluWindow.qml @@ -52,7 +52,6 @@ Window { signal showSystemMenu signal initArgument(var argument) signal firstVisible() - property point _offsetXY : Qt.point(0,0) id:window color:"transparent" Component.onCompleted: { @@ -72,19 +71,6 @@ 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() @@ -190,10 +176,6 @@ Window { id:layout_container anchors{ fill:parent - leftMargin: _offsetXY.x - rightMargin: _offsetXY.x - topMargin: _offsetXY.y - bottomMargin: _offsetXY.y } onWidthChanged: { window.appBar.width = width @@ -246,7 +228,7 @@ Window { border.width: window.resizeBorderWidth border.color: window.resizeBorderColor visible: { - if(window.useSystemAppBar){ + if(window.useSystemAppBar || FluTools.isWin()){ return false } if(window.visibility == Window.Maximized || window.visibility == Window.FullScreen){