From af27e7120d0f8817368940fdc258aa403dc81b9c Mon Sep 17 00:00:00 2001 From: fxliang Date: Sat, 30 Dec 2023 00:20:34 +0800 Subject: [PATCH] WM_SETTINGCHANGE msg handling, for dark/light mode detection in windows 11. --- WeaselIPCServer/WeaselServerImpl.cpp | 8 +++++--- WeaselIPCServer/WeaselServerImpl.h | 1 + 2 files changed, 6 insertions(+), 3 deletions(-) diff --git a/WeaselIPCServer/WeaselServerImpl.cpp b/WeaselIPCServer/WeaselServerImpl.cpp index de950f460..e9688cf2a 100644 --- a/WeaselIPCServer/WeaselServerImpl.cpp +++ b/WeaselIPCServer/WeaselServerImpl.cpp @@ -60,9 +60,11 @@ void ServerImpl::_Finailize() LRESULT ServerImpl::OnColorChange(UINT uMsg, WPARAM wParam, LPARAM lParam, BOOL& bHandled) { - if(IsUserDarkMode() != m_darkMode) { - m_darkMode = IsUserDarkMode(); - m_pRequestHandler->UpdateColorTheme(m_darkMode); + if (uMsg == WM_SETTINGCHANGE && (std::wstring((wchar_t*)lParam) == L"ImmersiveColorSet") || uMsg == WM_DWMCOLORIZATIONCOLORCHANGED) { + if (IsUserDarkMode() != m_darkMode) { + m_darkMode = IsUserDarkMode(); + m_pRequestHandler->UpdateColorTheme(m_darkMode); + } } return 0; } diff --git a/WeaselIPCServer/WeaselServerImpl.h b/WeaselIPCServer/WeaselServerImpl.h index 930780d4c..b07bccd0f 100644 --- a/WeaselIPCServer/WeaselServerImpl.h +++ b/WeaselIPCServer/WeaselServerImpl.h @@ -28,6 +28,7 @@ namespace weasel MESSAGE_HANDLER(WM_QUERYENDSESSION, OnQueryEndSystemSession) MESSAGE_HANDLER(WM_ENDSESSION, OnEndSystemSession) MESSAGE_HANDLER(WM_DWMCOLORIZATIONCOLORCHANGED, OnColorChange) + MESSAGE_HANDLER(WM_SETTINGCHANGE, OnColorChange) MESSAGE_HANDLER(WM_COMMAND, OnCommand) END_MSG_MAP()