This commit is contained in:
zhuzichu 2023-12-22 12:39:04 +08:00
parent 9dd9d10049
commit d817782526
5 changed files with 31 additions and 9 deletions

View File

@ -1,7 +1,7 @@
#include "FluFramelessHelper.h"
#include <QGuiApplication>
#include <QOperatingSystemVersion>
#include "FluTools.h"
#ifdef Q_OS_WIN
#pragma comment (lib,"user32.lib")
#pragma comment (lib,"dwmapi.lib")
@ -104,7 +104,7 @@ bool FramelessEventFilter::nativeEventFilter(const QByteArray &eventType, void *
}
return false;
}else if(uMsg == WM_NCHITTEST){
if(_helper->hoverMaxBtn() && _helper->resizeable()){
if(FluTools::getInstance()->isWindows11OrGreater() && _helper->hoverMaxBtn() && _helper->resizeable()){
if (*result == HTNOWHERE) {
*result = HTZOOM;
}
@ -112,14 +112,14 @@ bool FramelessEventFilter::nativeEventFilter(const QByteArray &eventType, void *
}
return false;
}else if(uMsg == WM_NCLBUTTONDBLCLK || uMsg == WM_NCLBUTTONDOWN){
if(_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(_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);
}
@ -277,7 +277,7 @@ void FluFramelessHelper::showSystemMenu(){
}else{
EnableMenuItem(hMenu,SC_MAXIMIZE,MFS_DISABLED);
}
const int result = TrackPopupMenu(hMenu, (TPM_RETURNCMD | (QGuiApplication::isRightToLeft() ? TPM_RIGHTALIGN : TPM_LEFTALIGN)), point.x(), point.y(), 0, hwnd, nullptr);
const int result = TrackPopupMenu(hMenu, (TPM_RETURNCMD | (QGuiApplication::isRightToLeft() ? TPM_RIGHTALIGN : TPM_LEFTALIGN)), point.x()*window->devicePixelRatio(), point.y()*window->devicePixelRatio(), 0, hwnd, nullptr);
if (result != FALSE) {
PostMessageW(hwnd, WM_SYSCOMMAND, result, 0);
}

View File

@ -14,6 +14,7 @@
#include <QTextDocument>
#include <QQuickWindow>
#include <QDateTime>
#include <QSettings>
FluTools::FluTools(QObject *parent):QObject{parent}{
@ -194,3 +195,23 @@ int FluTools::cursorScreenIndex(){
}
return screenIndex;
}
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;
}
}
#endif
var = QVariant::fromValue(false);
return false;
}else{
return var.toBool();
}
}

View File

@ -51,6 +51,7 @@ public:
Q_INVOKABLE QPoint cursorPos();
Q_INVOKABLE QIcon windowIcon();
Q_INVOKABLE int cursorScreenIndex();
Q_INVOKABLE bool isWindows11OrGreater();
};
#endif // FLUTOOLS_H

View File

@ -233,7 +233,7 @@ Rectangle{
if(pressed){
return maximizePressColor
}
if(FluTools.isWin() && !FluApp.useSystemAppBar){
if(FluTools.isWindows11OrGreater()){
return d.hoverMaxBtn ? maximizeHoverColor : maximizeNormalColor
}
return hovered ? maximizeHoverColor : maximizeNormalColor
@ -286,7 +286,7 @@ Rectangle{
var pos = btn_maximize.mapToGlobal(0,0)
if(btn_maximize.visible){
var rect = Qt.rect(pos.x,pos.y,btn_maximize.width,btn_maximize.height)
pos = FluTools.cursorPos()
pos = FluTools.cursorPos()
if(pos.x>rect.x && pos.x<(rect.x+rect.width) && pos.y>rect.y && pos.y<(rect.y+rect.height)){
hover = true;
}

View File

@ -233,7 +233,7 @@ Rectangle{
if(pressed){
return maximizePressColor
}
if(FluTools.isWin() && !FluApp.useSystemAppBar){
if(FluTools.isWindows11OrGreater()){
return d.hoverMaxBtn ? maximizeHoverColor : maximizeNormalColor
}
return hovered ? maximizeHoverColor : maximizeNormalColor
@ -286,7 +286,7 @@ Rectangle{
var pos = btn_maximize.mapToGlobal(0,0)
if(btn_maximize.visible){
var rect = Qt.rect(pos.x,pos.y,btn_maximize.width,btn_maximize.height)
pos = FluTools.cursorPos()
pos = FluTools.cursorPos()
if(pos.x>rect.x && pos.x<(rect.x+rect.width) && pos.y>rect.y && pos.y<(rect.y+rect.height)){
hover = true;
}