Skip to content

Commit

Permalink
Improvements for reliable hotkey handling.
Browse files Browse the repository at this point in the history
  • Loading branch information
danielgjackson committed Dec 9, 2021
1 parent 4d7b11e commit f5519dd
Show file tree
Hide file tree
Showing 3 changed files with 20 additions and 11 deletions.
27 changes: 18 additions & 9 deletions toggle.c
Original file line number Diff line number Diff line change
Expand Up @@ -65,6 +65,7 @@ BOOL gbImmediatelyExit = FALSE; // Quit right away (mainly for testing)
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 @@ -452,7 +453,8 @@ BOOL SetLightDark(DWORD light)
UINT msg = WM_THEMECHANGED;
WPARAM wParam = 0;
LPARAM lParam = 0;
SendNotifyMessage(hWnd, msg, wParam, lParam);
//SendNotifyMessage(hWnd, msg, wParam, lParam);
PostMessage(hWnd, msg, wParam, lParam);

return TRUE;
}
Expand Down Expand Up @@ -528,7 +530,14 @@ LRESULT CALLBACK WndProc(HWND hwnd, UINT message, WPARAM wParam, LPARAM lParam)
{
if (wParam == HOT_KEY_ID)
{
ToggleDarkLight();
// 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();
return 0;
}
}
}

Expand Down Expand Up @@ -949,15 +958,15 @@ int run(int argc, TCHAR *argv[], HINSTANCE hInstance, BOOL hasConsole)
if (bHasMessage)
{
// Pre-translate so captured before child controls
if (msg.message == WM_KEYDOWN && msg.wParam == VK_ESCAPE)
{
HideWindow();
}
if (!IsDialogMessage(hWnd, &msg)) // handles tabbing etc (avoid WM_USER=DM_GETDEFID / WM_USER+1=DM_SETDEFID)
{
//if (msg.message == WM_KEYDOWN && msg.wParam == VK_ESCAPE)
//{
// HideWindow();
//}
//if (!IsDialogMessage(hWnd, &msg)) // handles tabbing etc (avoid WM_USER=DM_GETDEFID / WM_USER+1=DM_SETDEFID)
//{
TranslateMessage(&msg);
DispatchMessage(&msg);
}
//}
if (msg.message == WM_QUIT) break;
}
}
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 5 // Patch ('build' in MS version order)
#define VER_BUILD 6 // 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
2 changes: 1 addition & 1 deletion toggle.wxs
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
<?xml version="1.0" encoding="utf-8"?>
<!-- Change the Product/@Id on any installation file changes. Modify the Product Version for any minor changes. -->
<Wix xmlns="http://schemas.microsoft.com/wix/2006/wi" xmlns:util="http://schemas.microsoft.com/wix/UtilExtension">
<Product Name="Toggle Dark-Light Mode" Id="*" UpgradeCode="9bf9dd6a-aced-4905-98db-3572c6699b8d" Language="1033" Version="1.0.5.0" Manufacturer="danielgjackson">
<Product Name="Toggle Dark-Light Mode" Id="*" UpgradeCode="9bf9dd6a-aced-4905-98db-3572c6699b8d" Language="1033" Version="1.0.6.0" Manufacturer="danielgjackson">
<Package Id="*" InstallerVersion="200" Compressed="yes" InstallScope="perUser" /><!-- "perMachine" / "perUser" -->

<MajorUpgrade AllowDowngrades="yes" /><!-- AllowSameVersionUpgrades="yes" -->
Expand Down

0 comments on commit f5519dd

Please sign in to comment.