Skip to content

Commit

Permalink
Fix repeated hotkey; delay to help fix taskbars on other displays.
Browse files Browse the repository at this point in the history
  • Loading branch information
danielgjackson committed Feb 9, 2024
1 parent 9b6cbf5 commit 315e08f
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 14 deletions.
24 changes: 11 additions & 13 deletions toggle.c
Original file line number Diff line number Diff line change
Expand Up @@ -66,7 +66,6 @@ BOOL gbQuery = FALSE;
BOOL gbExiting = FALSE;
HANDLE ghStartEvent = NULL; // Event for single instance
int gVersion[4] = { 0, 0, 0, 0 };
DWORD lastHotkey = 0;

NOTIFYICONDATA nid = {0};

Expand Down Expand Up @@ -463,7 +462,8 @@ BOOL SetLightDark(DWORD light)

RegCloseKey(hKey);

//Sleep(500);
// Delay -- this appears to help update taskbars on other displays
Sleep(1000);

// Broadcast WM_SETTINGSCHANGE using SendMessageTimeout with lParam set to "ImmersiveColorSet" -- required by some apps such as explorer.exe (File Explorer)
{
Expand All @@ -474,8 +474,6 @@ BOOL SetLightDark(DWORD light)
SendMessageTimeout(hWnd, msg, wParam, lParam, SMTO_ABORTIFHUNG, 5000, NULL);
}

//Sleep(500);

// Broadcast a second WM_SETTINGSCHANGE using SendMessageTimeout with lParam set to "ImmersiveColorSet" -- this second broadcast fixes Task Manager
{
HWND hWnd = HWND_BROADCAST;
Expand All @@ -485,7 +483,8 @@ BOOL SetLightDark(DWORD light)
SendMessageTimeout(hWnd, msg, wParam, lParam, SMTO_ABORTIFHUNG, 5000, NULL);
}

// Broadcast WM_THEMECHANGED

// // Broadcast WM_THEMECHANGED
// {
// HWND hWnd = HWND_BROADCAST;
// UINT msg = WM_THEMECHANGED;
Expand Down Expand Up @@ -603,14 +602,13 @@ LRESULT CALLBACK WndProc(HWND hwnd, UINT message, WPARAM wParam, LPARAM lParam)
{
if (wParam == HOT_KEY_ID)
{
// Limit the rate of change from the hot key in case many are buffered
DWORD now = GetTickCount();
if (lastHotkey == 0 || (now - lastHotkey) >= 5000)
{
lastHotkey = now;
ToggleDarkLight(TRUE);
return 0;
}
ToggleDarkLight(TRUE);

// Remove any repeated WM_HOTKEY messages from the window queue
MSG m;
while (PeekMessage(&m, hwnd, WM_HOTKEY, WM_HOTKEY, PM_REMOVE)) { ; }

return 0;
}
}

Expand Down
2 changes: 1 addition & 1 deletion toggle.rc
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ MAINICON ICON "icon.ico"
#define STRINGIZE(x) STRINGIZE_HELPER(x)
#define VER_MAJOR 1
#define VER_MINOR 0
#define VER_BUILD 10 // Patch ('build' in MS version order)
#define VER_BUILD 11 // Patch ('build' in MS version order)
#define VER_REVISION 0 // Build ('revision' in MS version order)
#define VER_STRING STRINGIZE(VER_MAJOR) "." STRINGIZE(VER_MINOR) "." STRINGIZE(VER_BUILD) "." STRINGIZE(VER_REVISION)

Expand Down

0 comments on commit 315e08f

Please sign in to comment.