Skip to content

Commit

Permalink
Don't re-apply colorization if the accent color has not been changed
Browse files Browse the repository at this point in the history
Mitigation for Windows bug - since Windows 10 1809+ WM_DWMCOLORIZATIONCOLORCHANGED is sent multiple times
  • Loading branch information
krlvm committed Jul 14, 2022
1 parent 3edb772 commit 1e36f16
Show file tree
Hide file tree
Showing 3 changed files with 29 additions and 5 deletions.
12 changes: 10 additions & 2 deletions AccentColorizer/AccentColorHelper.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -4,12 +4,20 @@

COLORREF accent;

void UpdateAccentColors()
bool UpdateAccentColors()
{
COLORREF dwAccentRGB;
BOOL bIsColorOpaque;

DwmGetColorizationColor(&dwAccentRGB, &bIsColorOpaque);

accent = RGB2BGR(dwAccentRGB);
DWORD dwAccent = RGB2BGR(dwAccentRGB);

if (accent == dwAccent)
{
return false;
}

accent = dwAccent;
return true;
}
2 changes: 1 addition & 1 deletion AccentColorizer/AccentColorHelper.h
Original file line number Diff line number Diff line change
Expand Up @@ -3,4 +3,4 @@

extern COLORREF accent;

void UpdateAccentColors();
bool UpdateAccentColors();
20 changes: 18 additions & 2 deletions AccentColorizer/AccentColorizer.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -9,17 +9,33 @@ const LPCWSTR szWindowClass = L"ACCENTCOLORIZER";
HANDLE hHandle;

void ApplyAccentColorization() {
UpdateAccentColors();
if (!UpdateAccentColors())
{
// Accent Colors have not been changed.
// There's a bug in Windows 10 1809+ because of which
// WM_DWMCOLORIZATIONCOLORCHANGED message is sent multiple times,
// it also affects accent color changing performance in general.
// Apparently it is fixed in Windows 11 version 22H2
return;
}
ModifySysColors(accent);
ModifyStyles(accent);
}

#include <iostream>
LRESULT CALLBACK WndProc(HWND hWnd, UINT message, WPARAM wParam, LPARAM lParam)
{
if (message == WM_DWMCOLORIZATIONCOLORCHANGED ||
message == WM_DPICHANGED ||
(message == WM_WTSSESSION_CHANGE && wParam == WTS_SESSION_UNLOCK))
message == WM_THEMECHANGED ||
(message == WM_WTSSESSION_CHANGE && wParam == WTS_SESSION_UNLOCK)
)
{
if (message == WM_THEMECHANGED)
{
// We need to re-apply colorization if visual styles theme has been changed
accent = NULL;
}
ApplyAccentColorization();
}
return DefWindowProc(hWnd, message, wParam, lParam);
Expand Down

0 comments on commit 1e36f16

Please sign in to comment.