Skip to content

Commit 60d43b8

Browse files
authored
Change notification icon when pressing ScrollLock
1 parent b8aedec commit 60d43b8

9 files changed

+29
-15
lines changed

altdrag.c

+4
Original file line numberDiff line numberDiff line change
@@ -43,6 +43,7 @@ HINSTANCE hinstDLL = NULL;
4343
HHOOK keyhook = NULL;
4444
char elevated = 0;
4545
char WinVer = 0;
46+
char ScrollLockState = 0;
4647

4748
// Include stuff
4849
#include "hooks.h"
@@ -195,6 +196,8 @@ LRESULT CALLBACK WindowProc(HWND hwnd, UINT msg, WPARAM wParam, LPARAM lParam)
195196
} else if (msg == WM_ADDTRAY) {
196197
hide = 0;
197198
UpdateTray();
199+
} else if (msg == WM_UPDATETRAY) {
200+
UpdateTray();
198201
} else if (msg == WM_HIDETRAY) {
199202
hide = 1;
200203
RemoveTray();
@@ -336,6 +339,7 @@ int WINAPI WinMain(HINSTANCE hInst, HINSTANCE hPrevInstance, char *szCmdLine, in
336339
NULL, WS_POPUP, 0, 0, 0, 0, NULL, NULL, hInst, NULL);
337340
LOG("Create main APP Window: %s\n", g_hwnd? "Sucess": "Failed");
338341
// Tray icon
342+
339343
InitTray();
340344
UpdateTray();
341345

altdrag.rc

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
app_icon ICON "media/icon.ico"
22
tray_disabled ICON "media/tray-disabled.ico"
33
tray_enabled ICON "media/tray-enabled.ico"
4-
4+
tray_suspended ICON "media/tray-suspended.ico"
55
#include "window.rc"
66

77
CREATEPROCESS_MANIFEST_RESOURCE_ID RT_MANIFEST "AltDrag.exe.manifest"

config.c

+6-5
Original file line numberDiff line numberDiff line change
@@ -251,7 +251,7 @@ static void WriteOptionBoolW(HWND hwnd, WORD id, wchar_t *section, wchar_t *name
251251
WritePrivateProfileString(section, name,_itow(Button_GetCheck(GetDlgItem(hwnd, id)), txt, 10), inipath);
252252
}
253253
#define WriteOptionBool(id, section, name) WriteOptionBoolW(hwnd, id, section, name)
254-
static void WriteOptionBoolBW(HWND hwnd, WORD id, wchar_t *section, wchar_t *name, int bit)
254+
static int WriteOptionBoolBW(HWND hwnd, WORD id, wchar_t *section, wchar_t *name, int bit)
255255
{
256256
wchar_t txt[8];
257257
int val = GetPrivateProfileInt(section, name, 0, inipath);
@@ -260,7 +260,8 @@ static void WriteOptionBoolBW(HWND hwnd, WORD id, wchar_t *section, wchar_t *nam
260260
else
261261
val = clearBit(val, bit);
262262

263-
WritePrivateProfileString(section, name,_itow(val, txt, 10), inipath);
263+
WritePrivateProfileString(section, name, _itow(val, txt, 10), inipath);
264+
return val;
264265
}
265266
#define WriteOptionBoolB(id, section, name, bit) WriteOptionBoolBW(hwnd, id, section, name, bit)
266267

@@ -718,7 +719,7 @@ INT_PTR CALLBACK KeyboardPageDialogProc(HWND hwnd, UINT msg, WPARAM wParam, LPAR
718719
ReadOptionInt(IDC_AGGRESSIVEPAUSE, L"Input", L"AggressivePause", 0, -1);
719720
Button_Enable(GetDlgItem(hwnd, IDC_AGGRESSIVEPAUSE), HaveProc("NTDLL.DLL", "NtResumeProcess"));
720721
ReadOptionInt(IDC_AGGRESSIVEKILL, L"Input", L"AggressiveKill", 0, -1);
721-
ReadOptionInt(IDC_SCROLLLOCKSTATE, L"Input", L"ScrollLockState",0, -1);
722+
ReadOptionInt(IDC_SCROLLLOCKSTATE, L"Input", L"ScrollLockState",0, 1);
722723
ReadOptionInt(IDC_KEYCOMBO, L"Input", L"KeyCombo", 0, -1);
723724
CheckConfigHotKeys(hotkeys, hwnd, L"Hotkeys", L"A4 A5");
724725
} else if (msg == WM_COMMAND) {
@@ -752,7 +753,7 @@ INT_PTR CALLBACK KeyboardPageDialogProc(HWND hwnd, UINT msg, WPARAM wParam, LPAR
752753
SetDlgItemText(hwnd, IDC_KEYBOARD_BOX, l10n->tab_keyboard);
753754
SetDlgItemText(hwnd, IDC_AGGRESSIVEPAUSE, l10n->input_aggressive_pause);
754755
SetDlgItemText(hwnd, IDC_AGGRESSIVEKILL, l10n->input_aggressive_kill);
755-
SetDlgItemText(hwnd, IDC_SCROLLLOCKSTATE, l10n->input_scrolllockstate);
756+
SetDlgItemText(hwnd, IDC_SCROLLLOCKSTATE, l10n->input_scrolllockstate);
756757
SetDlgItemText(hwnd, IDC_HOTKEYS_BOX, l10n->input_hotkeys_box);
757758
SetDlgItemText(hwnd, IDC_TOGGLERZMVKEY_H, l10n->input_hotkeys_togglerzmvkey);
758759
SetDlgItemText(hwnd, IDC_LEFTALT, l10n->input_hotkeys_leftalt);
@@ -771,7 +772,7 @@ INT_PTR CALLBACK KeyboardPageDialogProc(HWND hwnd, UINT msg, WPARAM wParam, LPAR
771772
WritePrivateProfileString(L"Input", L"GrabWithAlt", kb_actions[i].action, inipath);
772773
WriteOptionBool(IDC_AGGRESSIVEPAUSE, L"Input", L"AggressivePause");
773774
WriteOptionBool(IDC_AGGRESSIVEKILL, L"Input", L"AggressiveKill");
774-
WriteOptionBool(IDC_SCROLLLOCKSTATE, L"Input", L"ScrollLockState");
775+
ScrollLockState=WriteOptionBoolB(IDC_SCROLLLOCKSTATE, L"Input", L"ScrollLockState", 0);
775776
// Invert move/resize key.
776777
i = ComboBox_GetCurSel(GetDlgItem(hwnd, IDC_TOGGLERZMVKEY));
777778
WritePrivateProfileString(L"Input", L"ToggleRzMvKey", togglekeys[i].action, inipath);

hooks.c

+6-5
Original file line numberDiff line numberDiff line change
@@ -1575,17 +1575,18 @@ static void SetForegroundWindowL(HWND hwnd)
15751575
// otherwise it is enabled by Scroll lock.
15761576
static int ScrollLockState()
15771577
{
1578-
return conf.ScrollLockState&1
1579-
&&!( !(GetKeyState(VK_SCROLL)&1) ^ !(conf.ScrollLockState&2) );
1578+
return (conf.ScrollLockState&1) &&
1579+
!( !(GetKeyState(VK_SCROLL)&1) ^ !(conf.ScrollLockState&2) );
15801580
}
15811581
///////////////////////////////////////////////////////////////////////////
15821582
// Keep this one minimalist, it is always on.
15831583
__declspec(dllexport) LRESULT CALLBACK LowLevelKeyboardProc(int nCode, WPARAM wParam, LPARAM lParam)
15841584
{
1585-
if (nCode != HC_ACTION || state.ignorectrl
1586-
|| ScrollLockState()) return CallNextHookEx(NULL, nCode, wParam, lParam);
1585+
if (nCode != HC_ACTION || state.ignorectrl) return CallNextHookEx(NULL, nCode, wParam, lParam);
15871586

15881587
unsigned char vkey = ((PKBDLLHOOKSTRUCT)lParam)->vkCode;
1588+
if (vkey == VK_SCROLL) PostMessage(g_mainhwnd, WM_UPDATETRAY, 0, 0);
1589+
if (ScrollLockState()) return CallNextHookEx(NULL, nCode, wParam, lParam);
15891590

15901591
if (wParam == WM_KEYDOWN || wParam == WM_SYSKEYDOWN) {
15911592
if (!state.alt && (!conf.KeyCombo || (state.alt1 && state.alt1 != vkey)) && IsHotkey(vkey)) {
@@ -2451,7 +2452,7 @@ static int init_movement_and_actions(POINT pt, enum action action, int button)
24512452
state.snap = conf.AutoSnap;
24522453
}
24532454
AddWindowToDB(state.hwnd);
2454-
2455+
24552456
// Set Origin width and height needed for AC_MOVE/RESIZE/CENTER
24562457
if (state.wndentry->restore && !state.origin.maximized) {
24572458
state.origin.width = state.wndentry->width;

hooks.h

+1
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@
44
#define WM_TRAY (WM_USER+1)
55
#define WM_SCLICK (WM_USER+2)
66
#define WM_UPDCFRACTION (WM_USER+3)
7+
#define WM_UPDATETRAY (WM_USER+4)
78

89
enum action { AC_NONE=0, AC_MOVE, AC_RESIZE, AC_MENU, AC_MINIMIZE, AC_MAXIMIZE, AC_CENTER
910
, AC_ALWAYSONTOP, AC_CLOSE, AC_LOWER, AC_BORDERLESS, AC_KILL

languages.h

+1-1
Original file line numberDiff line numberDiff line change
@@ -386,7 +386,7 @@ struct strings en_US = {
386386

387387
/* Aggressive Pause */ L"&Pause process on Alt+Shift+Pause (Alt+Pause to resume)",
388388
/* Aggressive Kill */ L"&Kill process on Ctrl+Alt+F4\nAlso adds the kill option to the action menu",
389-
/* scroll lock state */ L"Enable/Disable AltDrag based on &Scroll lock state",
389+
/* scroll lock state */ L"Suspend/Resume AltDrag based on &Scroll lock state",
390390
/* KeyCombo */ L"Use two keys &combo to activate",
391391
/* GrabWithAlt */ L"&Action without click:",
392392

media/tray-suspended.ico

198 Bytes
Binary file not shown.

media/tray-suspended2.ico

198 Bytes
Binary file not shown.

tray.c

+10-3
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@
77
* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * */
88

99
struct _NOTIFYICONDATAA tray;
10-
HICON icon[2];
10+
HICON icon[3];
1111
int tray_added = 0;
1212
int hide = 0;
1313

@@ -17,6 +17,9 @@ int InitTray()
1717
// Load icons
1818
icon[0] = LoadIconA(g_hinst, "tray_disabled");
1919
icon[1] = LoadIconA(g_hinst, "tray_enabled");
20+
icon[2] = LoadIconA(g_hinst, "tray_suspended");
21+
22+
ScrollLockState = GetPrivateProfileInt(L"Input", L"ScrollLockState", 0, inipath);
2023

2124
if (icon[0] == NULL || icon[1] == NULL) {
2225
LOG("Could not Load Icons for tray\n");
@@ -43,8 +46,12 @@ int InitTray()
4346
/////////////////////////////////////////////////////////////////////////////
4447
int UpdateTray()
4548
{
46-
strcpy(tray.szTip, ENABLED()? "AltDrag (On)": "AltDrag (Off)");
47-
tray.hIcon = icon[!!ENABLED()];
49+
int Index = !!ENABLED();
50+
if (Index && (ScrollLockState&1))
51+
Index += !( !(GetKeyState(VK_SCROLL)&1) ^ !(ScrollLockState&2) );
52+
53+
strcpy(tray.szTip, Index? "AltDrag (On)": "AltDrag (Off)");
54+
tray.hIcon = icon[Index];
4855

4956
// Only add or modify if not hidden or if balloon will be displayed
5057
if (!hide || tray.uFlags&NIF_INFO) {

0 commit comments

Comments
 (0)