From be703385249bafd679a125efc1477ff166e2c9e2 Mon Sep 17 00:00:00 2001 From: Sine Striker <trueful@163.com> Date: ćšć, 21 12æ 2023 17:08:40 +0800 Subject: [PATCH] minor tweaks --- src/core/contexts/abstractwindowcontext.cpp | 14 +++++-- src/core/contexts/cocoawindowcontext.mm | 2 + src/core/contexts/abstractwindowcontext_p.h | 2 src/core/windowagentbase.h | 2 src/core/windowagentbase.cpp | 4 +- src/core/contexts/win32windowcontext.cpp | 50 +++++++++++++++++-------- 6 files changed, 50 insertions(+), 24 deletions(-) diff --git a/src/core/contexts/abstractwindowcontext.cpp b/src/core/contexts/abstractwindowcontext.cpp index ca51be2..d110fff 100644 --- a/src/core/contexts/abstractwindowcontext.cpp +++ b/src/core/contexts/abstractwindowcontext.cpp @@ -25,19 +25,25 @@ } } - void AbstractWindowContext::setWindowAttribute(const QString &key, const QVariant &var) { + bool AbstractWindowContext::setWindowAttribute(const QString &key, const QVariant &attribute) { auto it = m_windowAttributes.find(key); - if (it.value() == var) - return; + if (it.value() == attribute) + return true; - auto newVar = var; + auto newVar = attribute; auto oldVar = it.value(); + bool res = false; void *args[] = { &const_cast<QString &>(key), &newVar, &oldVar, + &res, }; virtual_hook(WindowAttributeChangedHook, args); + if (res) { + it.value() = newVar; + } + return res; } bool AbstractWindowContext::setHitTestVisible(const QObject *obj, bool visible) { diff --git a/src/core/contexts/abstractwindowcontext_p.h b/src/core/contexts/abstractwindowcontext_p.h index e2a6c3f..753e8ee 100644 --- a/src/core/contexts/abstractwindowcontext_p.h +++ b/src/core/contexts/abstractwindowcontext_p.h @@ -38,7 +38,7 @@ inline WindowItemDelegate *delegate() const; inline QVariant windowAttribute(const QString &key) const; - void setWindowAttribute(const QString &key, const QVariant &var); + bool setWindowAttribute(const QString &key, const QVariant &attribute); inline bool isHitTestVisible(const QObject *obj) const; bool setHitTestVisible(const QObject *obj, bool visible); diff --git a/src/core/contexts/cocoawindowcontext.mm b/src/core/contexts/cocoawindowcontext.mm index d438001..560e2b5 100644 --- a/src/core/contexts/cocoawindowcontext.mm +++ b/src/core/contexts/cocoawindowcontext.mm @@ -381,6 +381,7 @@ const auto &key = *static_cast<const QString *>(args[0]); const auto &newVar = *static_cast<const QVariant *>(args[1]); const auto &oldVar = *static_cast<const QVariant *>(args[2]); + auto &res = *static_cast<bool *>(args[3]); if (key == QStringLiteral("no-system-buttons")) { if (newVar.toBool()) { @@ -388,6 +389,7 @@ } else { // TODO: set on } + res = true; } return; } diff --git a/src/core/contexts/win32windowcontext.cpp b/src/core/contexts/win32windowcontext.cpp index 76510ee..953186c 100644 --- a/src/core/contexts/win32windowcontext.cpp +++ b/src/core/contexts/win32windowcontext.cpp @@ -109,10 +109,10 @@ ACCENT_DISABLED = 0, ACCENT_ENABLE_GRADIENT = 1, ACCENT_ENABLE_TRANSPARENTGRADIENT = 2, - ACCENT_ENABLE_BLURBEHIND = 3, // Traditional DWM blur + ACCENT_ENABLE_BLURBEHIND = 3, // Traditional DWM blur ACCENT_ENABLE_ACRYLICBLURBEHIND = 4, // RS4 1803 - ACCENT_ENABLE_HOST_BACKDROP = 5, // RS5 1809 - ACCENT_INVALID_STATE = 6 // Using this value will remove the window background + ACCENT_ENABLE_HOST_BACKDROP = 5, // RS5 1809 + ACCENT_INVALID_STATE = 6 // Using this value will remove the window background }; enum ACCENT_FLAG { @@ -998,6 +998,7 @@ const auto &key = *static_cast<const QString *>(args[0]); const auto &newVar = *static_cast<const QVariant *>(args[1]); const auto &oldVar = *static_cast<const QVariant *>(args[2]); + auto &res = *static_cast<bool *>(args[3]); if (!windowId) return; @@ -1021,21 +1022,27 @@ static constexpr const MARGINS margins = {-1, -1, -1, -1}; apis.pDwmExtendFrameIntoClientArea(hwnd, &margins); if (isWin1122H2OrGreater()) { - // Use official DWM API to enable Mica, available since Windows 11 22H2 (10.0.22621). + // Use official DWM API to enable Mica, available since Windows 11 22H2 + // (10.0.22621). const _DWM_SYSTEMBACKDROP_TYPE backdropType = _DWMSBT_MAINWINDOW; - apis.pDwmSetWindowAttribute(hwnd, _DWMWA_SYSTEMBACKDROP_TYPE, &backdropType, sizeof(backdropType)); + apis.pDwmSetWindowAttribute(hwnd, _DWMWA_SYSTEMBACKDROP_TYPE, + &backdropType, sizeof(backdropType)); } else { - // Use undocumented DWM API to enable Mica, available since Windows 11 (10.0.22000). + // Use undocumented DWM API to enable Mica, available since Windows 11 + // (10.0.22000). const BOOL enable = TRUE; - apis.pDwmSetWindowAttribute(hwnd, _DWMWA_MICA_EFFECT, &enable, sizeof(enable)); + apis.pDwmSetWindowAttribute(hwnd, _DWMWA_MICA_EFFECT, &enable, + sizeof(enable)); } } else { if (isWin1122H2OrGreater()) { const _DWM_SYSTEMBACKDROP_TYPE backdropType = _DWMSBT_AUTO; - apis.pDwmSetWindowAttribute(hwnd, _DWMWA_SYSTEMBACKDROP_TYPE, &backdropType, sizeof(backdropType)); + apis.pDwmSetWindowAttribute(hwnd, _DWMWA_SYSTEMBACKDROP_TYPE, + &backdropType, sizeof(backdropType)); } else { const BOOL enable = FALSE; - apis.pDwmSetWindowAttribute(hwnd, _DWMWA_MICA_EFFECT, &enable, sizeof(enable)); + apis.pDwmSetWindowAttribute(hwnd, _DWMWA_MICA_EFFECT, &enable, + sizeof(enable)); } static constexpr const MARGINS margins = {0, 0, 0, 0}; apis.pDwmExtendFrameIntoClientArea(hwnd, &margins); @@ -1049,30 +1056,39 @@ // to see the blurred window background. static constexpr const MARGINS margins = {-1, -1, -1, -1}; apis.pDwmExtendFrameIntoClientArea(hwnd, &margins); - // Use official DWM API to enable Mica Alt, available since Windows 11 22H2 (10.0.22621). + // Use official DWM API to enable Mica Alt, available since Windows 11 22H2 + // (10.0.22621). const _DWM_SYSTEMBACKDROP_TYPE backdropType = _DWMSBT_TABBEDWINDOW; - apis.pDwmSetWindowAttribute(hwnd, _DWMWA_SYSTEMBACKDROP_TYPE, &backdropType, sizeof(backdropType)); + apis.pDwmSetWindowAttribute(hwnd, _DWMWA_SYSTEMBACKDROP_TYPE, &backdropType, + sizeof(backdropType)); } else { const _DWM_SYSTEMBACKDROP_TYPE backdropType = _DWMSBT_AUTO; - apis.pDwmSetWindowAttribute(hwnd, _DWMWA_SYSTEMBACKDROP_TYPE, &backdropType, sizeof(backdropType)); + apis.pDwmSetWindowAttribute(hwnd, _DWMWA_SYSTEMBACKDROP_TYPE, &backdropType, + sizeof(backdropType)); static constexpr const MARGINS margins = {0, 0, 0, 0}; apis.pDwmExtendFrameIntoClientArea(hwnd, &margins); } + res = true; } else if (key == QStringLiteral("acrylic-material")) { - if (newVar.toBool()) { + if (newVar.type() == QVariant::Color) { // We need to extend the window frame into the whole client area to be able // to see the blurred window background. static constexpr const MARGINS margins = {-1, -1, -1, -1}; apis.pDwmExtendFrameIntoClientArea(hwnd, &margins); if (isWin11OrGreater()) { const _DWM_SYSTEMBACKDROP_TYPE backdropType = _DWMSBT_TRANSIENTWINDOW; - apis.pDwmSetWindowAttribute(hwnd, _DWMWA_SYSTEMBACKDROP_TYPE, &backdropType, sizeof(backdropType)); + apis.pDwmSetWindowAttribute(hwnd, _DWMWA_SYSTEMBACKDROP_TYPE, + &backdropType, sizeof(backdropType)); } else { + auto gradientColor = newVar.value<QColor>(); + ACCENT_POLICY policy{}; policy.dwAccentState = ACCENT_ENABLE_ACRYLICBLURBEHIND; policy.dwAccentFlags = ACCENT_ENABLE_ACRYLIC_WITH_LUMINOSITY; // This API expects the #AABBGGRR format. - //policy.dwGradientColor = DWORD(qRgba(gradientColor.blue(), gradientColor.green(), gradientColor.red(), gradientColor.alpha())); + policy.dwGradientColor = + DWORD(qRgba(gradientColor.blue(), gradientColor.green(), + gradientColor.red(), gradientColor.alpha())); WINDOWCOMPOSITIONATTRIBDATA wcad{}; wcad.Attrib = WCA_ACCENT_POLICY; wcad.pvData = &policy; @@ -1082,7 +1098,8 @@ } else { if (isWin11OrGreater()) { const _DWM_SYSTEMBACKDROP_TYPE backdropType = _DWMSBT_AUTO; - apis.pDwmSetWindowAttribute(hwnd, _DWMWA_SYSTEMBACKDROP_TYPE, &backdropType, sizeof(backdropType)); + apis.pDwmSetWindowAttribute(hwnd, _DWMWA_SYSTEMBACKDROP_TYPE, + &backdropType, sizeof(backdropType)); } else { ACCENT_POLICY policy{}; policy.dwAccentState = ACCENT_DISABLED; @@ -1096,6 +1113,7 @@ static constexpr const MARGINS margins = {0, 0, 0, 0}; apis.pDwmExtendFrameIntoClientArea(hwnd, &margins); } + res = true; } return; } diff --git a/src/core/windowagentbase.cpp b/src/core/windowagentbase.cpp index c043838..819dfb2 100644 --- a/src/core/windowagentbase.cpp +++ b/src/core/windowagentbase.cpp @@ -55,9 +55,9 @@ return d->context->windowAttribute(key); } - void WindowAgentBase::setWindowAttribute(const QString &key, const QVariant &var) { + bool WindowAgentBase::setWindowAttribute(const QString &key, const QVariant &attribute) { Q_D(WindowAgentBase); - d->context->setWindowAttribute(key, var); + return d->context->setWindowAttribute(key, attribute); } void WindowAgentBase::showSystemMenu(const QPoint &pos) { diff --git a/src/core/windowagentbase.h b/src/core/windowagentbase.h index 6ac3dc3..6e684bd 100644 --- a/src/core/windowagentbase.h +++ b/src/core/windowagentbase.h @@ -29,7 +29,7 @@ Q_ENUM(SystemButton) QVariant windowAttribute(const QString &key) const; - void setWindowAttribute(const QString &key, const QVariant &var); + bool setWindowAttribute(const QString &key, const QVariant &attribute); public Q_SLOTS: void showSystemMenu(const QPoint &pos); // Only available on Windows now -- Gitblit v1.9.1