5#include <QtCore/QVariant>
13static WindowStyleAgent::SystemTheme getSystemTheme()
15 if (isHighContrastModeEnabled()) {
16 return WindowStyleAgent::HighContrast;
17 }
else if (isDarkThemeActive()) {
18 return WindowStyleAgent::Dark;
20 return WindowStyleAgent::Light;
24static void notifyAllWindowStyleAgents()
26 auto theme = getSystemTheme();
27 for (
auto &&ap : std::as_const(*g_styleAgentSet())) {
28 ap->notifyThemeChanged(theme);
32class SystemSettingEventFilter :
public AppNativeEventFilter
35 bool nativeEventFilter(
const QByteArray &eventType,
void *message, QT_NATIVE_EVENT_RESULT_TYPE *result)
override
42 const auto msg =
static_cast<const MSG *
>(message);
43 switch (msg->message) {
45 case WM_SYSCOLORCHANGE:
46 case WM_DWMCOLORIZATIONCOLORCHANGED: {
47 notifyAllWindowStyleAgents();
51 case WM_SETTINGCHANGE: {
53 notifyAllWindowStyleAgents();
64 static SystemSettingEventFilter *instance;
66 static inline void install()
71 instance =
new SystemSettingEventFilter();
74 static inline void uninstall()
84SystemSettingEventFilter *SystemSettingEventFilter::instance =
nullptr;
86void WindowStyleAgentPrivate::setupSystemThemeHook()
88 systemTheme = getSystemTheme();
90 g_styleAgentSet->insert(
this);
91 SystemSettingEventFilter::install();
94void WindowStyleAgentPrivate::removeSystemThemeHook()
96 if (!g_styleAgentSet->remove(
this))
99 if (g_styleAgentSet->isEmpty()) {
100 SystemSettingEventFilter::uninstall();
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