From 2f59395b8183b1de62bd0ba83685298d9a7e3271 Mon Sep 17 00:00:00 2001 From: Sine Striker <trueful@163.com> Date: ćšć, 21 12æ 2023 19:56:42 +0800 Subject: [PATCH] minor tweaks --- src/stylesupport/styleagent_win.cpp | 74 ++++++++++++++++++++++++++++++++++++ 1 files changed, 73 insertions(+), 1 deletions(-) diff --git a/src/stylesupport/styleagent_win.cpp b/src/stylesupport/styleagent_win.cpp index 7a910d4..a685586 100644 --- a/src/stylesupport/styleagent_win.cpp +++ b/src/stylesupport/styleagent_win.cpp @@ -1,19 +1,91 @@ #include "styleagent_p.h" +#include <QtCore/QSet> #include <QtCore/QVariant> #include <QWKCore/private/qwkwindowsextra_p.h> +#include <QWKCore/private/nativeeventfilter_p.h> namespace QWK { + using StyleAgentSet = QSet<StyleAgentPrivate *>; + Q_GLOBAL_STATIC(StyleAgentSet, g_styleAgentSet) + + class SystemSettingEventFilter : public AppNativeEventFilter { + public: + bool nativeEventFilter(const QByteArray &eventType, void *message, + QT_NATIVE_EVENT_RESULT_TYPE *result) override { + Q_UNUSED(eventType) + if (!result) { + return false; + } + + const auto msg = static_cast<const MSG *>(message); + switch (msg->message) { + case WM_THEMECHANGED: + case WM_SYSCOLORCHANGE: + case WM_DWMCOLORIZATIONCOLORCHANGED: { + // TODO: walk through `g_styleAgentSet` + break; + } + + case WM_SETTINGCHANGE: { + if (!msg->wParam && msg->lParam && + std::wcscmp(reinterpret_cast<LPCWSTR>(msg->lParam), L"ImmersiveColorSet") == + 0) { + // TODO: walk through `g_styleAgentSet` + } + break; + } + + default: + break; + } + return false; + } + + static SystemSettingEventFilter *instance; + + static inline void install() { + if (instance) { + return; + } + instance = new SystemSettingEventFilter(); + } + + static inline void uninstall() { + if (!instance) { + return; + } + delete instance; + instance = nullptr; + } + }; + + SystemSettingEventFilter *SystemSettingEventFilter::instance = nullptr; + void StyleAgentPrivate::setupSystemThemeHook() { + g_styleAgentSet->insert(this); + SystemSettingEventFilter::install(); + + // Initialize `systemTheme` variable + } + + void StyleAgentPrivate::removeSystemThemeHook() { + if (!g_styleAgentSet->remove(this)) + return; + + if (g_styleAgentSet->isEmpty()) { + SystemSettingEventFilter::uninstall(); + } } bool StyleAgentPrivate::updateWindowAttribute(QWindow *window, const QString &key, const QVariant &attribute, const QVariant &oldAttribute) { - const auto hwnd = reinterpret_cast<HWND>(window->winId()); + Q_UNUSED(oldAttribute) + const auto hwnd = reinterpret_cast<HWND>(window->winId()); const DynamicApis &apis = DynamicApis::instance(); if (key == QStringLiteral("frame-shadow")) { -- Gitblit v1.9.1