From f099d3c737153d95ca0b0e94cf908dfdf4061d8f Mon Sep 17 00:00:00 2001 From: jeffrey0326 <547913081@qq.com> Date: Wed, 21 Aug 2024 17:16:39 +0800 Subject: [PATCH] =?UTF-8?q?=E8=B0=83=E6=95=B4=E6=94=AF=E6=8C=81mingw?= =?UTF-8?q?=E7=BC=96=E8=AF=91?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- example/example_en_US.ts | 5 +++ example/example_zh_CN.ts | 5 +++ src/FluFrameless.cpp | 31 +++++++++---------- src/FluFrameless.h | 12 ++++++- .../imports/FluentUI/Controls/FluWindow.qml | 26 +++++++++++++--- 5 files changed, 58 insertions(+), 21 deletions(-) diff --git a/example/example_en_US.ts b/example/example_en_US.ts index a1edb73f..70fa49cb 100644 --- a/example/example_en_US.ts +++ b/example/example_en_US.ts @@ -2279,6 +2279,11 @@ Some contents... window effect + + + + + T_TimePicker diff --git a/example/example_zh_CN.ts b/example/example_zh_CN.ts index a5086d73..6214065e 100644 --- a/example/example_zh_CN.ts +++ b/example/example_zh_CN.ts @@ -2461,6 +2461,11 @@ Some contents... window effect + + + + + T_TimePicker diff --git a/src/FluFrameless.cpp b/src/FluFrameless.cpp index 76a75f37..ed76cad9 100644 --- a/src/FluFrameless.cpp +++ b/src/FluFrameless.cpp @@ -107,8 +107,7 @@ static inline void setShadow(HWND hwnd) { } static inline bool setWindowDarkMode(HWND hwnd, const BOOL enable) { - return bool(DwmSetWindowAttribute(hwnd, DWMWINDOWATTRIBUTE::DWMWA_USE_IMMERSIVE_DARK_MODE, - &enable, sizeof(BOOL))); + return bool(DwmSetWindowAttribute(hwnd, 20, &enable, sizeof(BOOL))); } static inline bool setWindowEffect(HWND hwnd, const QString &key, const bool &enable) { @@ -120,8 +119,8 @@ static inline bool setWindowEffect(HWND hwnd, const QString &key, const bool &en if (enable) { DwmExtendFrameIntoClientArea(hwnd, &extendedMargins); if (isWin1122H2OrGreater()) { - const DWM_SYSTEMBACKDROP_TYPE backdropType = DWMSBT_MAINWINDOW; - DwmSetWindowAttribute(hwnd, DWMWA_SYSTEMBACKDROP_TYPE, &backdropType, + const DWORD backdropType = _DWMSBT_MAINWINDOW; + DwmSetWindowAttribute(hwnd, 38, &backdropType, sizeof(backdropType)); } else { const BOOL enable = TRUE; @@ -129,8 +128,8 @@ static inline bool setWindowEffect(HWND hwnd, const QString &key, const bool &en } } else { if (isWin1122H2OrGreater()) { - const DWM_SYSTEMBACKDROP_TYPE backdropType = DWMSBT_AUTO; - DwmSetWindowAttribute(hwnd, DWMWA_SYSTEMBACKDROP_TYPE, &backdropType, + const DWORD backdropType = _DWMSBT_AUTO; + DwmSetWindowAttribute(hwnd, 38, &backdropType, sizeof(backdropType)); } else { const BOOL enable = FALSE; @@ -148,12 +147,12 @@ static inline bool setWindowEffect(HWND hwnd, const QString &key, const bool &en } if (enable) { DwmExtendFrameIntoClientArea(hwnd, &extendedMargins); - const DWM_SYSTEMBACKDROP_TYPE backdropType = DWMSBT_TABBEDWINDOW; - DwmSetWindowAttribute(hwnd, DWMWA_SYSTEMBACKDROP_TYPE, &backdropType, + const DWORD backdropType = _DWMSBT_TABBEDWINDOW; + DwmSetWindowAttribute(hwnd, 38, &backdropType, sizeof(backdropType)); } else { - const DWM_SYSTEMBACKDROP_TYPE backdropType = DWMSBT_AUTO; - DwmSetWindowAttribute(hwnd, DWMWA_SYSTEMBACKDROP_TYPE, &backdropType, + const DWORD backdropType = _DWMSBT_AUTO; + DwmSetWindowAttribute(hwnd, 38, &backdropType, sizeof(backdropType)); } BOOL isDark = FluTheme::getInstance()->dark(); @@ -168,13 +167,13 @@ static inline bool setWindowEffect(HWND hwnd, const QString &key, const bool &en if (enable) { MARGINS margins{-1, -1, -1, -1}; DwmExtendFrameIntoClientArea(hwnd, &margins); - DWM_SYSTEMBACKDROP_TYPE system_backdrop_type = - DWM_SYSTEMBACKDROP_TYPE::DWMSBT_TRANSIENTWINDOW; - DwmSetWindowAttribute(hwnd, DWMWINDOWATTRIBUTE::DWMWA_SYSTEMBACKDROP_TYPE, - &system_backdrop_type, sizeof(DWM_SYSTEMBACKDROP_TYPE)); + DWORD system_backdrop_type = + _DWMSBT_TRANSIENTWINDOW; + DwmSetWindowAttribute(hwnd, 38, + &system_backdrop_type, sizeof(DWORD)); } else { - const DWM_SYSTEMBACKDROP_TYPE backdropType = DWMSBT_AUTO; - DwmSetWindowAttribute(hwnd, DWMWA_SYSTEMBACKDROP_TYPE, &backdropType, + const DWORD backdropType = _DWMSBT_AUTO; + DwmSetWindowAttribute(hwnd, 38, &backdropType, sizeof(backdropType)); } BOOL isDark = FluTheme::getInstance()->dark(); diff --git a/src/FluFrameless.h b/src/FluFrameless.h index db095210..1179ff95 100644 --- a/src/FluFrameless.h +++ b/src/FluFrameless.h @@ -14,7 +14,17 @@ #include #include #include - +enum _DWM_SYSTEMBACKDROP_TYPE { + _DWMSBT_AUTO, // [Default] Let DWM automatically decide the system-drawn backdrop for this + // window. + _DWMSBT_NONE, // [Disable] Do not draw any system backdrop. + _DWMSBT_MAINWINDOW, // [Mica] Draw the backdrop material effect corresponding to a + // long-lived window. + _DWMSBT_TRANSIENTWINDOW, // [Acrylic] Draw the backdrop material effect corresponding to a + // transient window. + _DWMSBT_TABBEDWINDOW, // [Mica Alt] Draw the backdrop material effect corresponding to a + // window with a tabbed title bar. +}; enum WINDOWCOMPOSITIONATTRIB { WCA_UNDEFINED = 0, WCA_NCRENDERING_ENABLED = 1, diff --git a/src/Qt6/imports/FluentUI/Controls/FluWindow.qml b/src/Qt6/imports/FluentUI/Controls/FluWindow.qml index 4dd9aed5..ba9bdf5b 100644 --- a/src/Qt6/imports/FluentUI/Controls/FluWindow.qml +++ b/src/Qt6/imports/FluentUI/Controls/FluWindow.qml @@ -12,6 +12,11 @@ Window { property bool fixSize: false property Component loadingItem: com_loading property bool fitsAppBarWindows: false + property var tintOpacity: FluTheme.dark ? 0.80 : 0.75 + property int blurRadius: 60 + property alias effect: frameless.effect + readonly property alias effective: frameless.effective + readonly property var availableEffects: frameless.availableEffects property Item appBar: FluAppBar { title: window.title height: 30 @@ -23,6 +28,15 @@ Window { icon: window.windowIcon } property color backgroundColor: { + if(frameless.effective && active){ + var backcolor + if(frameless.effect==="dwm-blur"){ + backcolor = FluTools.withOpacity(FluTheme.windowActiveBackgroundColor, window.tintOpacity) + }else{ + backcolor = "transparent" + } + return backcolor + } if(active){ return FluTheme.windowActiveBackgroundColor } @@ -106,6 +120,11 @@ Window { Component.onDestruction: { frameless.onDestruction() } + onEffectiveChanged: { + if(effective){ + FluTheme.blurBehindWindowEnabled = false + } + } } Component{ id:com_background @@ -161,8 +180,8 @@ Window { FluAcrylic{ anchors.fill: parent target: img_back - tintOpacity: FluTheme.dark ? 0.80 : 0.75 - blurRadius: 64 + tintOpacity: window.tintOpacity + blurRadius: window.blurRadius visible: window.active && FluTheme.blurBehindWindowEnabled tintColor: FluTheme.dark ? Qt.rgba(0, 0, 0, 1) : Qt.rgba(1, 1, 1, 1) targetRect: Qt.rect(window.x-window.screen.virtualX,window.y-window.screen.virtualY,window.width,window.height) @@ -274,7 +293,7 @@ Window { sourceComponent: window.useSystemAppBar ? undefined : com_app_bar } Item{ - id:layout_content + id: layout_content anchors{ top: loader_app_bar.bottom left: parent.left @@ -293,7 +312,6 @@ Window { id:info_bar root: layout_container } - FluLoader{ id:loader_border anchors.fill: parent