Skip to content

Commit 19d7c4c

Browse files
committed
Handle system theme change
1 parent 24b0014 commit 19d7c4c

File tree

2 files changed

+16
-0
lines changed

2 files changed

+16
-0
lines changed

src/AppContext.cs

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -78,6 +78,15 @@ private void InitializeTrayIcon()
7878
Localization.NotifyIfTestMode();
7979
}
8080

81+
public static void HandleThemeChange()
82+
{
83+
Application.SetColorMode(SystemColorMode.System);
84+
foreach (Form form in Application.OpenForms)
85+
{
86+
form.Invalidate();
87+
}
88+
}
89+
8190
public static void ShowPopup(string message, string title = null)
8291
{
8392
notifyIcon.BalloonTipTitle = title ?? "WinDynamicDesktop";

src/HiddenForm.cs

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,7 @@ internal class HiddenForm : Form
1515
private const int ENDSESSION_CLOSEAPP = 0x1;
1616
private const int WM_QUERYENDSESSION = 0x11;
1717
private const int WM_ENDSESSION = 0x16;
18+
private const int WM_SETTINGCHANGE = 0x1A;
1819
private const int WM_POWERBROADCAST = 0x0218;
1920
private const int PBT_POWERSETTINGCHANGE = 0x8013;
2021

@@ -62,6 +63,12 @@ protected override void WndProc(ref Message m)
6263
}
6364
m.Result = IntPtr.Zero;
6465
break;
66+
case WM_SETTINGCHANGE:
67+
if (Marshal.PtrToStringUni(m.LParam) == "ImmersiveColorSet")
68+
{
69+
AppContext.HandleThemeChange();
70+
}
71+
break;
6572
case WM_POWERBROADCAST:
6673
if (m.WParam.ToInt32() == PBT_POWERSETTINGCHANGE && PowerSetting.IsExitingStandby(m.LParam))
6774
{

0 commit comments

Comments
 (0)