QtCanpool 3.3.0
载入中...
搜索中...
未找到
windowstyleagent_win.cpp
浏览该文件的文档.
4#include <QtCore/QSet>
5#include <QtCore/QVariant>
6#include <QtGui/QColor>
7
9
10using WindowStyleAgentSet = QSet<WindowStyleAgentPrivate *>;
12
13static WindowStyleAgent::SystemTheme getSystemTheme()
14{
15 if (isHighContrastModeEnabled()) {
16 return WindowStyleAgent::HighContrast;
17 } else if (isDarkThemeActive()) {
18 return WindowStyleAgent::Dark;
19 } else {
20 return WindowStyleAgent::Light;
21 }
22}
23
24static void notifyAllWindowStyleAgents()
25{
26 auto theme = getSystemTheme();
27 for (auto &&ap : std::as_const(*g_styleAgentSet())) {
28 ap->notifyThemeChanged(theme);
29 }
30}
31
32class SystemSettingEventFilter : public AppNativeEventFilter
33{
34public:
35 bool nativeEventFilter(const QByteArray &eventType, void *message, QT_NATIVE_EVENT_RESULT_TYPE *result) override
36 {
37 Q_UNUSED(eventType)
38 if (!result) {
39 return false;
40 }
41
42 const auto msg = static_cast<const MSG *>(message);
43 switch (msg->message) {
44 case WM_THEMECHANGED:
45 case WM_SYSCOLORCHANGE:
46 case WM_DWMCOLORIZATIONCOLORCHANGED: {
47 notifyAllWindowStyleAgents();
48 break;
49 }
50
51 case WM_SETTINGCHANGE: {
52 if (isImmersiveColorSetChange(msg->wParam, msg->lParam)) {
53 notifyAllWindowStyleAgents();
54 }
55 break;
56 }
57
58 default:
59 break;
60 }
61 return false;
62 }
63
64 static SystemSettingEventFilter *instance;
65
66 static inline void install()
67 {
68 if (instance) {
69 return;
70 }
71 instance = new SystemSettingEventFilter();
72 }
73
74 static inline void uninstall()
75 {
76 if (!instance) {
77 return;
78 }
79 delete instance;
80 instance = nullptr;
81 }
82};
83
84SystemSettingEventFilter *SystemSettingEventFilter::instance = nullptr;
85
86void WindowStyleAgentPrivate::setupSystemThemeHook()
87{
88 systemTheme = getSystemTheme();
89
90 g_styleAgentSet->insert(this);
91 SystemSettingEventFilter::install();
92}
93
94void WindowStyleAgentPrivate::removeSystemThemeHook()
95{
96 if (!g_styleAgentSet->remove(this))
97 return;
98
99 if (g_styleAgentSet->isEmpty()) {
100 SystemSettingEventFilter::uninstall();
101 }
102}
103
bool isImmersiveColorSetChange(WPARAM wParam, LPARAM lParam)
#define QX_WINDOW_END_NAMESPACE
#define QX_WINDOW_BEGIN_NAMESPACE
QSet< WindowStyleAgentPrivate * > WindowStyleAgentSet
Q_GLOBAL_STATIC(WindowStyleAgentSet, g_styleAgentSet) static WindowStyleAgent