src/stylesupport/styleagent.cpp | ●●●●● 补丁 | 查看 | 原始文档 | blame | 历史 | |
src/stylesupport/styleagent.h | ●●●●● 补丁 | 查看 | 原始文档 | blame | 历史 | |
src/stylesupport/styleagent_linux.cpp | ●●●●● 补丁 | 查看 | 原始文档 | blame | 历史 | |
src/stylesupport/styleagent_mac.mm | ●●●●● 补丁 | 查看 | 原始文档 | blame | 历史 | |
src/stylesupport/styleagent_p.h | ●●●●● 补丁 | 查看 | 原始文档 | blame | 历史 | |
src/stylesupport/styleagent_win.cpp | ●●●●● 补丁 | 查看 | 原始文档 | blame | 历史 |
src/stylesupport/styleagent.cpp
@@ -8,11 +8,18 @@ StyleAgentPrivate::StyleAgentPrivate() { } StyleAgentPrivate::~StyleAgentPrivate() { } StyleAgentPrivate::~StyleAgentPrivate() = default; void StyleAgentPrivate::init() { setupSystemThemeHook(); } void StyleAgentPrivate::notifyThemeChanged(StyleAgent::SystemTheme theme) { if (theme == systemTheme) return; systemTheme = theme; Q_Q(StyleAgent); Q_EMIT q->systemThemeChanged(); } void StyleAgentPrivate::_q_windowDestroyed() { @@ -20,9 +27,18 @@ } StyleAgent::StyleAgent(QObject *parent) : StyleAgent(*new StyleAgentPrivate(), parent) { Q_D(StyleAgent); d->setupSystemThemeHook(); } StyleAgent::~StyleAgent() { Q_D(StyleAgent); d->removeSystemThemeHook(); } StyleAgent::SystemTheme StyleAgent::systemTheme() const { Q_D(const StyleAgent); return d->systemTheme; } QVariant StyleAgent::windowAttribute(QWindow *window, const QString &key) const { src/stylesupport/styleagent.h
@@ -19,12 +19,22 @@ explicit StyleAgent(QObject *parent = nullptr); ~StyleAgent() override; enum SystemTheme { Unknown, Light, Dark, HighContrast, }; Q_ENUM(SystemTheme) public: SystemTheme systemTheme() const; QVariant windowAttribute(QWindow *window, const QString &key) const; bool setWindowAttribute(QWindow *window, const QString &key, const QVariant &attribute); Q_SIGNALS: void systemThemeChanged(); void systemThemeChanged(); // Do we need wallpaper change notify? protected: StyleAgent(StyleAgentPrivate &d, QObject *parent = nullptr); src/stylesupport/styleagent_linux.cpp
@@ -7,9 +7,13 @@ void StyleAgentPrivate::setupSystemThemeHook() { } void StyleAgentPrivate::removeSystemThemeHook() { } bool StyleAgentPrivate::updateWindowAttribute(QWindow *window, const QString &key, const QVariant &attribute, const QVariant &oldAttribute) { Q_UNUSED(oldAttribute) return false; } src/stylesupport/styleagent_mac.mm
@@ -7,9 +7,14 @@ void StyleAgentPrivate::setupSystemThemeHook() { } void StyleAgentPrivate::removeSystemThemeHook() { } bool StyleAgentPrivate::updateWindowAttribute(QWindow *window, const QString &key, const QVariant &attribute, const QVariant &oldAttribute) { Q_UNUSED(oldAttribute) if (key == QStringLiteral("no-system-buttons")) { if (attribute.toBool()) { // TODO: set off src/stylesupport/styleagent_p.h
@@ -15,12 +15,16 @@ StyleAgent *q_ptr; StyleAgent::SystemTheme systemTheme = StyleAgent::Dark; QHash<QWindow *, QVariantHash> windowAttributes; virtual void setupSystemThemeHook(); virtual void removeSystemThemeHook(); virtual bool updateWindowAttribute(QWindow *window, const QString &key, const QVariant &attribute, const QVariant &oldAttribute); void notifyThemeChanged(StyleAgent::SystemTheme theme); private: void _q_windowDestroyed(); }; 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")) {