Skip to content

Commit 273b4c8

Browse files
committed
[WIN32SS:NTUSER] Minor code cleanup in hotkey code (reactos#8084)
- Remove duplicated code in NtUserRegisterHotKey() and in NtUserUnregisterHotKey() by directly calling UserRegisterHotKey() and UserUnregisterHotKey() after the usual user-validation steps. - In UserRegisterHotKey(), ignore hotkeys with virtual key VK_PACKET since this is not a real keyboard input, but is instead used in conjunction with unicode characters to simulate keystrokes for non-keyboard input methods. - s/StartDebugHotKeys/SetDebugHotKeys/ - Remove duplicate code between NtUserCallMsgFilter() and IntCallMsgFilter().
1 parent 7c3a119 commit 273b4c8

File tree

4 files changed

+41
-97
lines changed

4 files changed

+41
-97
lines changed

win32ss/user/ntuser/hotkey.c

Lines changed: 32 additions & 75 deletions
Original file line numberDiff line numberDiff line change
@@ -43,18 +43,18 @@ UINT gfsModOnlyCandidate;
4343
#define IsWindowHotKey(pHK) ( (pHK)->pti == NULL && (pHK)->id == IDHK_WNDKEY )
4444

4545
VOID FASTCALL
46-
StartDebugHotKeys(VOID)
46+
SetDebugHotKeys(VOID)
4747
{
4848
UINT vk = VK_F12;
49-
UserUnregisterHotKey(PWND_BOTTOM, IDHK_F12);
50-
UserUnregisterHotKey(PWND_BOTTOM, IDHK_SHIFTF12);
5149
if (!ENHANCED_KEYBOARD(gKeyboardInfo.KeyboardIdentifier))
52-
{
5350
vk = VK_SUBTRACT;
54-
}
51+
52+
UserUnregisterHotKey(PWND_BOTTOM, IDHK_F12);
53+
UserUnregisterHotKey(PWND_BOTTOM, IDHK_SHIFTF12);
5554
UserRegisterHotKey(PWND_BOTTOM, IDHK_SHIFTF12, MOD_SHIFT, vk);
5655
UserRegisterHotKey(PWND_BOTTOM, IDHK_F12, 0, vk);
57-
TRACE("Start up the debugger hotkeys!! If you see this you enabled debugprints. Congrats!\n");
56+
57+
TRACE("Debugger hotkeys set up! If you see this you enabled Debug Prints. Congrats!\n");
5858
}
5959

6060
/*
@@ -456,25 +456,29 @@ UserRegisterHotKey(PWND pWnd,
456456
PHOT_KEY pHotKey;
457457
PTHREADINFO pHotKeyThread;
458458

459-
/* Find hotkey thread */
459+
/* Find the hotkey thread */
460460
if (pWnd == NULL || pWnd == PWND_BOTTOM)
461461
{
462-
pHotKeyThread = PsGetCurrentThreadWin32Thread();
462+
pHotKeyThread = PsGetCurrentThreadWin32Thread(); // gptiCurrent;
463463
}
464464
else
465465
{
466466
pHotKeyThread = pWnd->head.pti;
467467
}
468468

469-
/* Check for existing hotkey */
469+
/* Ignore the VK_PACKET key since it is not a real keyboard input */
470+
if (vk == VK_PACKET)
471+
return FALSE;
472+
473+
/* Check whether we modify an existing hotkey */
470474
if (IsHotKey(fsModifiers, vk))
471475
{
472476
EngSetLastError(ERROR_HOTKEY_ALREADY_REGISTERED);
473477
WARN("Hotkey already exists\n");
474478
return FALSE;
475479
}
476480

477-
/* Create new hotkey */
481+
/* Create a new hotkey */
478482
pHotKey = ExAllocatePoolWithTag(PagedPool, sizeof(HOT_KEY), USERTAG_HOTKEY);
479483
if (pHotKey == NULL)
480484
{
@@ -488,7 +492,7 @@ UserRegisterHotKey(PWND pWnd,
488492
pHotKey->vk = vk;
489493
pHotKey->id = id;
490494

491-
/* Insert hotkey to the global list */
495+
/* Insert the hotkey into the global list */
492496
pHotKey->pNext = gphkFirst;
493497
gphkFirst = pHotKey;
494498

@@ -515,132 +519,85 @@ UserUnregisterHotKey(PWND pWnd, int id)
515519

516520
bRet = TRUE;
517521
}
518-
else /* This hotkey will stay, use its next ptr */
522+
else
523+
{
524+
/* This hotkey will stay, use its next ptr */
519525
pLink = &pHotKey->pNext;
526+
}
520527

521528
/* Move to the next entry */
522529
pHotKey = phkNext;
523530
}
531+
524532
return bRet;
525533
}
526534

527535

528536
/* SYSCALLS *****************************************************************/
529537

530-
531538
BOOL APIENTRY
532539
NtUserRegisterHotKey(HWND hWnd,
533540
int id,
534541
UINT fsModifiers,
535542
UINT vk)
536543
{
537-
PHOT_KEY pHotKey;
538544
PWND pWnd = NULL;
539-
PTHREADINFO pHotKeyThread;
540545
BOOL bRet = FALSE;
541546

542547
TRACE("Enter NtUserRegisterHotKey\n");
543548

544-
if (fsModifiers & ~(MOD_ALT|MOD_CONTROL|MOD_SHIFT|MOD_WIN)) // FIXME: Does Win2k3 support MOD_NOREPEAT?
549+
// FIXME: Does Win2k3 support MOD_NOREPEAT?
550+
if (fsModifiers & ~(MOD_ALT | MOD_CONTROL | MOD_SHIFT | MOD_WIN))
545551
{
546552
WARN("Invalid modifiers: %x\n", fsModifiers);
547553
EngSetLastError(ERROR_INVALID_FLAGS);
548-
return 0;
554+
return FALSE;
549555
}
550556

551557
UserEnterExclusive();
552558

553-
/* Find hotkey thread */
559+
/* Check the hotkey thread */
554560
if (hWnd == NULL)
555561
{
556-
pHotKeyThread = gptiCurrent;
562+
pWnd = NULL;
557563
}
558564
else
559565
{
560566
pWnd = UserGetWindowObject(hWnd);
561567
if (!pWnd)
562568
goto cleanup;
563569

564-
pHotKeyThread = pWnd->head.pti;
565-
566-
/* Fix wine msg "Window on another thread" test_hotkey */
570+
/* FIXME?? "Fix" wine msg "Window on another thread" test_hotkey */
567571
if (pWnd->head.pti != gptiCurrent)
568572
{
569-
EngSetLastError(ERROR_WINDOW_OF_OTHER_THREAD);
570-
WARN("Must be from the same Thread.\n");
571-
goto cleanup;
573+
EngSetLastError(ERROR_WINDOW_OF_OTHER_THREAD);
574+
WARN("Must be from the same Thread.\n");
575+
goto cleanup;
572576
}
573577
}
574578

575-
/* Check for existing hotkey */
576-
if (IsHotKey(fsModifiers, vk))
577-
{
578-
EngSetLastError(ERROR_HOTKEY_ALREADY_REGISTERED);
579-
WARN("Hotkey already exists\n");
580-
goto cleanup;
581-
}
582-
583-
/* Create new hotkey */
584-
pHotKey = ExAllocatePoolWithTag(PagedPool, sizeof(HOT_KEY), USERTAG_HOTKEY);
585-
if (pHotKey == NULL)
586-
{
587-
EngSetLastError(ERROR_NOT_ENOUGH_MEMORY);
588-
goto cleanup;
589-
}
590-
591-
pHotKey->pti = pHotKeyThread;
592-
pHotKey->pWnd = pWnd;
593-
pHotKey->fsModifiers = fsModifiers;
594-
pHotKey->vk = vk;
595-
pHotKey->id = id;
596-
597-
/* Insert hotkey to the global list */
598-
pHotKey->pNext = gphkFirst;
599-
gphkFirst = pHotKey;
600-
601-
bRet = TRUE;
579+
bRet = UserRegisterHotKey(pWnd, id, fsModifiers, vk);
602580

603581
cleanup:
604582
TRACE("Leave NtUserRegisterHotKey, ret=%i\n", bRet);
605583
UserLeave();
606584
return bRet;
607585
}
608586

609-
610587
BOOL APIENTRY
611588
NtUserUnregisterHotKey(HWND hWnd, int id)
612589
{
613-
PHOT_KEY pHotKey = gphkFirst, phkNext, *pLink = &gphkFirst;
614590
BOOL bRet = FALSE;
615591
PWND pWnd = NULL;
616592

617593
TRACE("Enter NtUserUnregisterHotKey\n");
618594
UserEnterExclusive();
619595

620-
/* Fail if given window is invalid */
596+
/* Fail if the given window is invalid */
621597
if (hWnd && !(pWnd = UserGetWindowObject(hWnd)))
622598
goto cleanup;
623599

624-
while (pHotKey)
625-
{
626-
/* Save next ptr for later use */
627-
phkNext = pHotKey->pNext;
628-
629-
/* Should we delete this hotkey? */
630-
if (pHotKey->pWnd == pWnd && pHotKey->id == id)
631-
{
632-
/* Update next ptr for previous hotkey and free memory */
633-
*pLink = phkNext;
634-
ExFreePoolWithTag(pHotKey, USERTAG_HOTKEY);
635-
636-
bRet = TRUE;
637-
}
638-
else /* This hotkey will stay, use its next ptr */
639-
pLink = &pHotKey->pNext;
640-
641-
/* Move to the next entry */
642-
pHotKey = phkNext;
643-
}
600+
bRet = UserUnregisterHotKey(pWnd, id);
644601

645602
cleanup:
646603
TRACE("Leave NtUserUnregisterHotKey, ret=%i\n", bRet);

win32ss/user/ntuser/hotkey.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,7 @@ VOID FASTCALL UnregisterThreadHotKeys(PTHREADINFO pti);
2727
BOOL NTAPI co_UserProcessHotKeys(WORD wVk, BOOL bIsDown);
2828
UINT FASTCALL DefWndGetHotKey(PWND pWnd);
2929
INT FASTCALL DefWndSetHotKey(PWND pWnd, WPARAM wParam);
30-
VOID FASTCALL StartDebugHotKeys(VOID);
30+
VOID FASTCALL SetDebugHotKeys(VOID);
3131
BOOL FASTCALL UserRegisterHotKey(PWND pWnd,int id,UINT fsModifiers,UINT vk);
3232
BOOL FASTCALL UserUnregisterHotKey(PWND pWnd, int id);
3333

win32ss/user/ntuser/input.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -204,7 +204,7 @@ RawInputThreadMain(VOID)
204204
UserRegisterHotKey(PWND_BOTTOM, IDHK_SNAP_UP, MOD_WIN, VK_UP);
205205
UserRegisterHotKey(PWND_BOTTOM, IDHK_SNAP_DOWN, MOD_WIN, VK_DOWN);
206206
// Register the debug hotkeys.
207-
StartDebugHotKeys();
207+
SetDebugHotKeys();
208208
UserLeave();
209209
}
210210
}

win32ss/user/ntuser/message.c

Lines changed: 7 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -2187,18 +2187,14 @@ IntUninitMessagePumpHook(VOID)
21872187
}
21882188

21892189
BOOL FASTCALL
2190-
IntCallMsgFilter( LPMSG lpmsg, INT code)
2190+
IntCallMsgFilter(LPMSG lpmsg, INT code)
21912191
{
2192-
BOOL Ret = FALSE;
2192+
BOOL Ret;
2193+
2194+
Ret = co_HOOK_CallHooks(WH_SYSMSGFILTER, code, 0, (LPARAM)lpmsg);
2195+
if (!Ret)
2196+
Ret = co_HOOK_CallHooks(WH_MSGFILTER, code, 0, (LPARAM)lpmsg);
21932197

2194-
if ( co_HOOK_CallHooks( WH_SYSMSGFILTER, code, 0, (LPARAM)lpmsg))
2195-
{
2196-
Ret = TRUE;
2197-
}
2198-
else
2199-
{
2200-
Ret = co_HOOK_CallHooks( WH_MSGFILTER, code, 0, (LPARAM)lpmsg);
2201-
}
22022198
return Ret;
22032199
}
22042200

@@ -2447,16 +2443,7 @@ NtUserCallMsgFilter( LPMSG lpmsg, INT code)
24472443
_SEH2_END;
24482444

24492445
UserEnterExclusive();
2450-
2451-
if ( co_HOOK_CallHooks( WH_SYSMSGFILTER, code, 0, (LPARAM)&Msg))
2452-
{
2453-
Ret = TRUE;
2454-
}
2455-
else
2456-
{
2457-
Ret = co_HOOK_CallHooks( WH_MSGFILTER, code, 0, (LPARAM)&Msg);
2458-
}
2459-
2446+
Ret = IntCallMsgFilter(&Msg, code);
24602447
UserLeave();
24612448

24622449
_SEH2_TRY

0 commit comments

Comments
 (0)