win: improve blur mode
This commit is contained in:
parent
786926e7ab
commit
ba7aab0276
|
@ -780,19 +780,13 @@ using ACCENT_FLAG = enum ACCENT_FLAG
|
||||||
{
|
{
|
||||||
ACCENT_NONE = 0,
|
ACCENT_NONE = 0,
|
||||||
ACCENT_ENABLE_ACRYLIC = 1,
|
ACCENT_ENABLE_ACRYLIC = 1,
|
||||||
ACCENT_ENABLE_MICA = 1 << 1,
|
ACCENT_ENABLE_ACRYLIC_WITH_LUMINOSITY = 482
|
||||||
ACCENT_ENABLE_BORDER_LEFT = 1 << 5,
|
|
||||||
ACCENT_ENABLE_BORDER_TOP = 1 << 6,
|
|
||||||
ACCENT_ENABLE_BORDER_RIGHT = 1 << 7,
|
|
||||||
ACCENT_ENABLE_BORDER_BOTTOM = 1 << 8,
|
|
||||||
ACCENT_ENABLE_BORDER = ACCENT_ENABLE_BORDER_LEFT | ACCENT_ENABLE_BORDER_TOP | ACCENT_ENABLE_BORDER_RIGHT | ACCENT_ENABLE_BORDER_BOTTOM,
|
|
||||||
ACCENT_ENABLE_ALL = ACCENT_ENABLE_BORDER
|
|
||||||
};
|
};
|
||||||
|
|
||||||
using ACCENT_POLICY = struct ACCENT_POLICY
|
using ACCENT_POLICY = struct ACCENT_POLICY
|
||||||
{
|
{
|
||||||
DWORD AccentState;
|
DWORD dwAccentState;
|
||||||
DWORD AccentFlags;
|
DWORD dwAccentFlags;
|
||||||
DWORD dwGradientColor; // #AABBGGRR
|
DWORD dwGradientColor; // #AABBGGRR
|
||||||
DWORD dwAnimationId;
|
DWORD dwAnimationId;
|
||||||
};
|
};
|
||||||
|
|
|
@ -2334,8 +2334,40 @@ bool Utils::setBlurBehindWindowEnabled(const WId windowId, const BlurMode mode,
|
||||||
g_win32UtilsData()->micaWindowIds.removeAll(windowId);
|
g_win32UtilsData()->micaWindowIds.removeAll(windowId);
|
||||||
std::ignore = updateWindowFrameMargins(windowId, false);
|
std::ignore = updateWindowFrameMargins(windowId, false);
|
||||||
};
|
};
|
||||||
|
static const auto userPreferredBlurMode = []() -> std::optional<BlurMode> {
|
||||||
|
const QString option = qEnvironmentVariable("FRAMELESSHELPER_BLUR_MODE");
|
||||||
|
if (option.isEmpty()) {
|
||||||
|
return std::nullopt;
|
||||||
|
}
|
||||||
|
if (option.contains(FRAMELESSHELPER_STRING_LITERAL("MICAALT"), Qt::CaseInsensitive)) {
|
||||||
|
return BlurMode::Windows_MicaAlt;
|
||||||
|
}
|
||||||
|
if (option.contains(FRAMELESSHELPER_STRING_LITERAL("MICA"), Qt::CaseInsensitive)) {
|
||||||
|
return BlurMode::Windows_Mica;
|
||||||
|
}
|
||||||
|
if (option.contains(FRAMELESSHELPER_STRING_LITERAL("ACRYLIC"), Qt::CaseInsensitive)) {
|
||||||
|
return BlurMode::Windows_Acrylic;
|
||||||
|
}
|
||||||
|
if (option.contains(FRAMELESSHELPER_STRING_LITERAL("AERO"), Qt::CaseInsensitive)) {
|
||||||
|
return BlurMode::Windows_Aero;
|
||||||
|
}
|
||||||
|
return std::nullopt;
|
||||||
|
}();
|
||||||
|
static constexpr const auto kDefaultAcrylicOpacity = 0.8f;
|
||||||
|
static const auto acrylicOpacity = []() -> float {
|
||||||
|
const QString option = qEnvironmentVariable("FRAMELESSHELPER_ACRYLIC_OPACITY");
|
||||||
|
if (option.isEmpty()) {
|
||||||
|
return kDefaultAcrylicOpacity;
|
||||||
|
}
|
||||||
|
bool ok = false;
|
||||||
|
const float num = option.toFloat(&ok);
|
||||||
|
if (ok && !qIsNaN(num) && (num > float(0)) && (num < float(1))) {
|
||||||
|
return num;
|
||||||
|
}
|
||||||
|
return kDefaultAcrylicOpacity;
|
||||||
|
}();
|
||||||
static const bool preferMicaAlt = (qEnvironmentVariableIntValue("FRAMELESSHELPER_PREFER_MICA_ALT") != 0);
|
static const bool preferMicaAlt = (qEnvironmentVariableIntValue("FRAMELESSHELPER_PREFER_MICA_ALT") != 0);
|
||||||
const auto blurMode = [mode]() -> BlurMode {
|
const auto recommendedBlurMode = [mode]() -> BlurMode {
|
||||||
if ((mode == BlurMode::Disable) || (mode == BlurMode::Windows_Aero)) {
|
if ((mode == BlurMode::Disable) || (mode == BlurMode::Windows_Aero)) {
|
||||||
return mode;
|
return mode;
|
||||||
}
|
}
|
||||||
|
@ -2366,6 +2398,7 @@ bool Utils::setBlurBehindWindowEnabled(const WId windowId, const BlurMode mode,
|
||||||
Q_UNREACHABLE_RETURN(BlurMode::Default);
|
Q_UNREACHABLE_RETURN(BlurMode::Default);
|
||||||
QT_WARNING_POP
|
QT_WARNING_POP
|
||||||
}();
|
}();
|
||||||
|
const BlurMode blurMode = ((recommendedBlurMode == BlurMode::Disable) ? BlurMode::Disable : userPreferredBlurMode.value_or(recommendedBlurMode));
|
||||||
if (blurMode == BlurMode::Disable) {
|
if (blurMode == BlurMode::Disable) {
|
||||||
bool result = true;
|
bool result = true;
|
||||||
if (WindowsVersionHelper::isWin1122H2OrGreater()) {
|
if (WindowsVersionHelper::isWin1122H2OrGreater()) {
|
||||||
|
@ -2387,8 +2420,8 @@ bool Utils::setBlurBehindWindowEnabled(const WId windowId, const BlurMode mode,
|
||||||
} else {
|
} else {
|
||||||
ACCENT_POLICY policy;
|
ACCENT_POLICY policy;
|
||||||
SecureZeroMemory(&policy, sizeof(policy));
|
SecureZeroMemory(&policy, sizeof(policy));
|
||||||
policy.AccentState = ACCENT_DISABLED;
|
policy.dwAccentState = ACCENT_DISABLED;
|
||||||
policy.AccentFlags = ACCENT_NONE;
|
policy.dwAccentFlags = ACCENT_NONE;
|
||||||
WINDOWCOMPOSITIONATTRIBDATA wcad;
|
WINDOWCOMPOSITIONATTRIBDATA wcad;
|
||||||
SecureZeroMemory(&wcad, sizeof(wcad));
|
SecureZeroMemory(&wcad, sizeof(wcad));
|
||||||
wcad.Attrib = WCA_ACCENT_POLICY;
|
wcad.Attrib = WCA_ACCENT_POLICY;
|
||||||
|
@ -2453,22 +2486,22 @@ bool Utils::setBlurBehindWindowEnabled(const WId windowId, const BlurMode mode,
|
||||||
ACCENT_POLICY policy;
|
ACCENT_POLICY policy;
|
||||||
SecureZeroMemory(&policy, sizeof(policy));
|
SecureZeroMemory(&policy, sizeof(policy));
|
||||||
if (blurMode == BlurMode::Windows_Acrylic) {
|
if (blurMode == BlurMode::Windows_Acrylic) {
|
||||||
policy.AccentState = ACCENT_ENABLE_ACRYLICBLURBEHIND;
|
policy.dwAccentState = ACCENT_ENABLE_ACRYLICBLURBEHIND;
|
||||||
policy.AccentFlags = ACCENT_ENABLE_ACRYLIC; // Mica: ACCENT_ENABLE_MICA | ACCENT_ENABLE_BORDER
|
policy.dwAccentFlags = ACCENT_ENABLE_ACRYLIC_WITH_LUMINOSITY;
|
||||||
const auto gradientColor = [&color]() -> QColor {
|
const auto gradientColor = [&color]() -> QColor {
|
||||||
if (color.isValid()) {
|
if (color.isValid()) {
|
||||||
return color;
|
return color;
|
||||||
}
|
}
|
||||||
QColor clr = ((FramelessManager::instance()->systemTheme() == SystemTheme::Dark) ? kDefaultSystemDarkColor : kDefaultSystemLightColor);
|
QColor clr = ((FramelessManager::instance()->systemTheme() == SystemTheme::Dark) ? kDefaultSystemDarkColor : kDefaultSystemLightColor);
|
||||||
clr.setAlphaF(0.5f);
|
clr.setAlphaF(acrylicOpacity);
|
||||||
return clr;
|
return clr;
|
||||||
}();
|
}();
|
||||||
// This API expects the #AABBGGRR format.
|
// This API expects the #AABBGGRR format.
|
||||||
policy.dwGradientColor = DWORD(qRgba(gradientColor.blue(),
|
policy.dwGradientColor = DWORD(qRgba(gradientColor.blue(),
|
||||||
gradientColor.green(), gradientColor.red(), gradientColor.alpha()));
|
gradientColor.green(), gradientColor.red(), gradientColor.alpha()));
|
||||||
} else if (blurMode == BlurMode::Windows_Aero) {
|
} else if (blurMode == BlurMode::Windows_Aero) {
|
||||||
policy.AccentState = ACCENT_ENABLE_BLURBEHIND;
|
policy.dwAccentState = ACCENT_ENABLE_BLURBEHIND;
|
||||||
policy.AccentFlags = ACCENT_NONE;
|
policy.dwAccentFlags = ACCENT_NONE;
|
||||||
} else {
|
} else {
|
||||||
QT_WARNING_PUSH
|
QT_WARNING_PUSH
|
||||||
QT_WARNING_DISABLE_MSVC(4702)
|
QT_WARNING_DISABLE_MSVC(4702)
|
||||||
|
@ -2597,7 +2630,10 @@ bool Utils::isBlurBehindWindowSupported()
|
||||||
if (FramelessConfig::instance()->isSet(Option::ForceNonNativeBackgroundBlur)) {
|
if (FramelessConfig::instance()->isSet(Option::ForceNonNativeBackgroundBlur)) {
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
return WindowsVersionHelper::isWin11OrGreater();
|
// Enabling Mica on Win11 make it very hard to hide the original three caption buttons,
|
||||||
|
// and enabling Acrylic on Win10 makes the window very laggy during moving and resizing.
|
||||||
|
//return WindowsVersionHelper::isWin10OrGreater();
|
||||||
|
return false;
|
||||||
}();
|
}();
|
||||||
return result;
|
return result;
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in New Issue