From 12300ef08124b0c8328c631df4a1948d0941bbc6 Mon Sep 17 00:00:00 2001
From: jeffrey0326 <547913081@qq.com>
Date: Wed, 28 Aug 2024 14:04:50 +0800
Subject: [PATCH] =?UTF-8?q?=E8=B0=83=E6=95=B4=E6=94=AF=E6=8C=81=E4=BD=BF?=
=?UTF-8?q?=E7=94=A8=E7=B3=BB=E7=BB=9F=E6=A0=87=E9=A2=98=E6=A0=8F?=
MIME-Version: 1.0
Content-Type: text/plain; charset=UTF-8
Content-Transfer-Encoding: 8bit
---
example/example_en_US.ts | 6 +-
example/example_zh_CN.ts | 6 +-
example/qml/page/T_Theme.qml | 44 +++++++-------
src/FluFrameless.cpp | 107 +++++++++++++++++++----------------
4 files changed, 87 insertions(+), 76 deletions(-)
diff --git a/example/example_en_US.ts b/example/example_en_US.ts
index 70fa49cb..c7b29f45 100644
--- a/example/example_en_US.ts
+++ b/example/example_en_US.ts
@@ -2265,17 +2265,17 @@ Some contents...
-
+
-
+
-
+
diff --git a/example/example_zh_CN.ts b/example/example_zh_CN.ts
index 6214065e..cf53d737 100644
--- a/example/example_zh_CN.ts
+++ b/example/example_zh_CN.ts
@@ -2447,17 +2447,17 @@ Some contents...
-
+
-
+
-
+
diff --git a/example/qml/page/T_Theme.qml b/example/qml/page/T_Theme.qml
index 9a01f989..8576750c 100644
--- a/example/qml/page/T_Theme.qml
+++ b/example/qml/page/T_Theme.qml
@@ -131,6 +131,28 @@ FluScrollablePage{
FluTheme.blurBehindWindowEnabled = !FluTheme.blurBehindWindowEnabled
}
}
+ FluText{
+ text: qsTr("window effect")
+ Layout.topMargin: 20
+ }
+ Row{
+ spacing: 10
+ Repeater{
+ model: window.availableEffects
+ delegate: FluRadioButton{
+ checked: window.effect === modelData
+ text: qsTr(`${modelData}`)
+ clickListener:function(){
+ window.effect = modelData
+ if(window.effective){
+ FluTheme.blurBehindWindowEnabled = false
+ toggle_blur.checked = Qt.binding( function() {return FluTheme.blurBehindWindowEnabled})
+ }
+ }
+ }
+
+ }
+ }
FluText{
visible: FluTheme.blurBehindWindowEnabled || window.effect === "dwm-blur"
text: qsTr("window tintOpacity")
@@ -165,28 +187,6 @@ FluScrollablePage{
value = window.blurRadius
}
}
- FluText{
- text: qsTr("window effect")
- Layout.topMargin: 20
- }
- Row{
- spacing: 10
- Repeater{
- model: window.availableEffects
- delegate: FluRadioButton{
- checked: window.effect === modelData
- text: qsTr(`${modelData}`)
- clickListener:function(){
- window.effect = modelData
- if(window.effective){
- FluTheme.blurBehindWindowEnabled = false
- toggle_blur.checked = Qt.binding( function() {return FluTheme.blurBehindWindowEnabled})
- }
- }
- }
-
- }
- }
}
}
CodeExpander{
diff --git a/src/FluFrameless.cpp b/src/FluFrameless.cpp
index be2f239d..0b23ff0b 100644
--- a/src/FluFrameless.cpp
+++ b/src/FluFrameless.cpp
@@ -76,7 +76,7 @@ static inline bool isWin10Only() {
static inline bool isWin7Only() {
RTL_OSVERSIONINFOW rovi = GetRealOSVersion();
- return rovi.dwMajorVersion = 7;
+ return rovi.dwMajorVersion == 7;
}
static inline QByteArray qtNativeEventType() {
@@ -145,6 +145,9 @@ static inline void setShadow(HWND hwnd) {
if (initializeFunctionPointers()) {
pDwmExtendFrameIntoClientArea(hwnd, &shadow);
}
+ if(isWin7Only()){
+ SetClassLong(hwnd, GCL_STYLE, GetClassLong(hwnd, GCL_STYLE) | CS_DROPSHADOW);
+ }
}
static inline bool setWindowDarkMode(HWND hwnd, const BOOL enable) {
@@ -284,6 +287,7 @@ FluFrameless::FluFrameless(QQuickItem *parent) : QQuickItem{parent} {
_topmost = false;
_disabled = false;
_effect = "normal";
+ _effective = false;
_isWindows11OrGreater = FluTools::getInstance()->isWindows11OrGreater();
}
@@ -291,60 +295,16 @@ FluFrameless::~FluFrameless() = default;
[[maybe_unused]] void FluFrameless::onDestruction() {
QGuiApplication::instance()->removeNativeEventFilter(this);
+ disconnect(FluTheme::getInstance(), &FluTheme::darkChanged, this, nullptr);
+ disconnect(window(), &QQuickWindow::screenChanged, this, nullptr);
}
void FluFrameless::componentComplete() {
- if (_disabled) {
- return;
- }
- int w = window()->width();
- int h = window()->height();
- _current = window()->winId();
- window()->setFlags((window()->flags()) | Qt::CustomizeWindowHint | Qt::WindowMinimizeButtonHint | Qt::WindowCloseButtonHint);
- if (!_fixSize) {
- window()->setFlag(Qt::WindowMaximizeButtonHint);
- }
- window()->installEventFilter(this);
- QGuiApplication::instance()->installNativeEventFilter(this);
- if (_maximizeButton) {
- setHitTestVisible(_maximizeButton);
- }
- if (_minimizedButton) {
- setHitTestVisible(_minimizedButton);
- }
- if (_closeButton) {
- setHitTestVisible(_closeButton);
- }
#ifdef Q_OS_WIN
-#if (QT_VERSION == QT_VERSION_CHECK(6, 5, 3))
- qWarning()<<"Qt's own frameless bug, currently only exist in 6.5.3, please use other versions";
-#endif
HWND hwnd = reinterpret_cast(window()->winId());
- DWORD style = ::GetWindowLongPtr(hwnd, GWL_STYLE);
-# if (QT_VERSION == QT_VERSION_CHECK(6, 7, 2))
- style &= ~(WS_MINIMIZEBOX | WS_MAXIMIZEBOX | WS_SYSMENU);
-# endif
- if (_fixSize) {
- ::SetWindowLongPtr(hwnd, GWL_STYLE, style | WS_THICKFRAME | WS_CAPTION);;
- for (int i = 0; i <= QGuiApplication::screens().count() - 1; ++i) {
- connect(QGuiApplication::screens().at(i), &QScreen::logicalDotsPerInchChanged, this, [=] {
- SetWindowPos(hwnd, nullptr, 0, 0, 0, 0, SWP_NOZORDER | SWP_NOOWNERZORDER | SWP_NOMOVE | SWP_FRAMECHANGED);
- });
- }
- } else {
- ::SetWindowLongPtr(hwnd, GWL_STYLE, style | WS_MAXIMIZEBOX | WS_THICKFRAME | WS_CAPTION);
- }
- SetWindowPos(hwnd, nullptr, 0, 0, 0, 0, SWP_NOZORDER | SWP_NOOWNERZORDER | SWP_NOMOVE | SWP_NOSIZE | SWP_FRAMECHANGED);
- connect(window(), &QQuickWindow::screenChanged, this, [hwnd] {
- ::SetWindowPos(hwnd, nullptr, 0, 0, 0, 0, SWP_NOMOVE | SWP_NOSIZE | SWP_NOZORDER | SWP_FRAMECHANGED | SWP_NOOWNERZORDER);
- ::RedrawWindow(hwnd, nullptr, nullptr, RDW_INVALIDATE | RDW_UPDATENOW);
- });
- if (!window()->property("_hideShadow").toBool()) {
- setShadow(hwnd);
- }
if (isWin11OrGreater()) {
availableEffects({"mica", "mica-alt", "acrylic", "dwm-blur", "normal"});
- } else if (isWin7Only()) {
+ } else {
availableEffects({"dwm-blur","normal"});
}
if (!_effect.isEmpty()) {
@@ -378,6 +338,57 @@ void FluFrameless::componentComplete() {
setWindowDarkMode(hwnd, FluTheme::getInstance()->dark());
}
});
+#endif
+ if (_disabled) {
+ return;
+ }
+ int w = window()->width();
+ int h = window()->height();
+ _current = window()->winId();
+ window()->setFlags((window()->flags()) | Qt::CustomizeWindowHint | Qt::WindowMinimizeButtonHint | Qt::WindowCloseButtonHint);
+ if (!_fixSize) {
+ window()->setFlag(Qt::WindowMaximizeButtonHint);
+ }
+ window()->installEventFilter(this);
+ QGuiApplication::instance()->installNativeEventFilter(this);
+ if (_maximizeButton) {
+ setHitTestVisible(_maximizeButton);
+ }
+ if (_minimizedButton) {
+ setHitTestVisible(_minimizedButton);
+ }
+ if (_closeButton) {
+ setHitTestVisible(_closeButton);
+ }
+#ifdef Q_OS_WIN
+#if (QT_VERSION == QT_VERSION_CHECK(6, 5, 3))
+ qWarning()<<"Qt's own frameless bug, currently only exist in 6.5.3, please use other versions";
+#endif
+ if(!hwnd){
+ hwnd = reinterpret_cast(window()->winId());
+ }
+ DWORD style = ::GetWindowLongPtr(hwnd, GWL_STYLE);
+# if (QT_VERSION == QT_VERSION_CHECK(6, 7, 2))
+ style &= ~(WS_MINIMIZEBOX | WS_MAXIMIZEBOX | WS_SYSMENU);
+# endif
+ if (_fixSize) {
+ ::SetWindowLongPtr(hwnd, GWL_STYLE, style | WS_THICKFRAME | WS_CAPTION);;
+ for (int i = 0; i <= QGuiApplication::screens().count() - 1; ++i) {
+ connect(QGuiApplication::screens().at(i), &QScreen::logicalDotsPerInchChanged, this, [=] {
+ SetWindowPos(hwnd, nullptr, 0, 0, 0, 0, SWP_NOZORDER | SWP_NOOWNERZORDER | SWP_NOMOVE | SWP_FRAMECHANGED);
+ });
+ }
+ } else {
+ ::SetWindowLongPtr(hwnd, GWL_STYLE, style | WS_MAXIMIZEBOX | WS_THICKFRAME | WS_CAPTION);
+ }
+ SetWindowPos(hwnd, nullptr, 0, 0, 0, 0, SWP_NOZORDER | SWP_NOOWNERZORDER | SWP_NOMOVE | SWP_NOSIZE | SWP_FRAMECHANGED);
+ connect(window(), &QQuickWindow::screenChanged, this, [hwnd] {
+ ::SetWindowPos(hwnd, nullptr, 0, 0, 0, 0, SWP_NOMOVE | SWP_NOSIZE | SWP_NOZORDER | SWP_FRAMECHANGED | SWP_NOOWNERZORDER);
+ ::RedrawWindow(hwnd, nullptr, nullptr, RDW_INVALIDATE | RDW_UPDATENOW);
+ });
+ if (!window()->property("_hideShadow").toBool()) {
+ setShadow(hwnd);
+ }
#endif
auto appBarHeight = _appbar->height();
h = qRound(h + appBarHeight);