This commit is contained in:
zhuzichu 2023-12-29 11:13:10 +08:00
parent bf5c722058
commit 99ff310448
2 changed files with 12 additions and 25 deletions

View File

@ -1,6 +1,7 @@
#include "FluFramelessHelper.h"
#include <QGuiApplication>
#include "FluTools.h"
#ifdef Q_OS_WIN
#pragma comment (lib,"user32.lib")
#pragma comment (lib,"dwmapi.lib")
@ -13,19 +14,6 @@ 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));
@ -125,7 +113,7 @@ bool FramelessEventFilter::nativeEventFilter(const QByteArray &eventType, void *
}
return false;
}else if(uMsg == WM_NCHITTEST){
if(isWindows11OrGreater() && _helper->hoverMaxBtn() && _helper->resizeable()){
if(FluTools::getInstance()->isWindows11OrGreater() && _helper->hoverMaxBtn() && _helper->resizeable()){
if (*result == HTNOWHERE) {
*result = HTZOOM;
}
@ -133,14 +121,14 @@ bool FramelessEventFilter::nativeEventFilter(const QByteArray &eventType, void *
}
return false;
}else if(uMsg == WM_NCLBUTTONDBLCLK || uMsg == WM_NCLBUTTONDOWN){
if(isWindows11OrGreater() && _helper->hoverMaxBtn() && _helper->resizeable()){
if(FluTools::getInstance()->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(isWindows11OrGreater() && _helper->hoverMaxBtn() && _helper->resizeable()){
if(FluTools::getInstance()->isWindows11OrGreater() && _helper->hoverMaxBtn() && _helper->resizeable()){
QMouseEvent event = QMouseEvent(QEvent::MouseButtonRelease, QPoint(), QPoint(), Qt::LeftButton, Qt::LeftButton, Qt::NoModifier);
QGuiApplication::sendEvent(_helper->maximizeButton(),&event);
}

View File

@ -200,15 +200,14 @@ bool FluTools::isWindows11OrGreater(){
static QVariant var;
if(var.isNull()){
#if defined(Q_OS_WIN)
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;
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;
}
}
#endif
var = QVariant::fromValue(false);
return false;