[WIN32SS:NTUSER] Minor code cleanup in hotkey code (#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().
This commit is contained in:
Hermès Bélusca-Maïto
2019-06-16 19:29:17 +02:00
parent 7c3a119d6d
commit 273b4c8702
4 changed files with 41 additions and 97 deletions

View File

@@ -43,18 +43,18 @@ UINT gfsModOnlyCandidate;
#define IsWindowHotKey(pHK) ( (pHK)->pti == NULL && (pHK)->id == IDHK_WNDKEY )
VOID FASTCALL
StartDebugHotKeys(VOID)
SetDebugHotKeys(VOID)
{
UINT vk = VK_F12;
if (!ENHANCED_KEYBOARD(gKeyboardInfo.KeyboardIdentifier))
vk = VK_SUBTRACT;
UserUnregisterHotKey(PWND_BOTTOM, IDHK_F12);
UserUnregisterHotKey(PWND_BOTTOM, IDHK_SHIFTF12);
if (!ENHANCED_KEYBOARD(gKeyboardInfo.KeyboardIdentifier))
{
vk = VK_SUBTRACT;
}
UserRegisterHotKey(PWND_BOTTOM, IDHK_SHIFTF12, MOD_SHIFT, vk);
UserRegisterHotKey(PWND_BOTTOM, IDHK_F12, 0, vk);
TRACE("Start up the debugger hotkeys!! If you see this you enabled debugprints. Congrats!\n");
TRACE("Debugger hotkeys set up! If you see this you enabled Debug Prints. Congrats!\n");
}
/*
@@ -456,17 +456,21 @@ UserRegisterHotKey(PWND pWnd,
PHOT_KEY pHotKey;
PTHREADINFO pHotKeyThread;
/* Find hotkey thread */
/* Find the hotkey thread */
if (pWnd == NULL || pWnd == PWND_BOTTOM)
{
pHotKeyThread = PsGetCurrentThreadWin32Thread();
pHotKeyThread = PsGetCurrentThreadWin32Thread(); // gptiCurrent;
}
else
{
pHotKeyThread = pWnd->head.pti;
}
/* Check for existing hotkey */
/* Ignore the VK_PACKET key since it is not a real keyboard input */
if (vk == VK_PACKET)
return FALSE;
/* Check whether we modify an existing hotkey */
if (IsHotKey(fsModifiers, vk))
{
EngSetLastError(ERROR_HOTKEY_ALREADY_REGISTERED);
@@ -474,7 +478,7 @@ UserRegisterHotKey(PWND pWnd,
return FALSE;
}
/* Create new hotkey */
/* Create a new hotkey */
pHotKey = ExAllocatePoolWithTag(PagedPool, sizeof(HOT_KEY), USERTAG_HOTKEY);
if (pHotKey == NULL)
{
@@ -488,7 +492,7 @@ UserRegisterHotKey(PWND pWnd,
pHotKey->vk = vk;
pHotKey->id = id;
/* Insert hotkey to the global list */
/* Insert the hotkey into the global list */
pHotKey->pNext = gphkFirst;
gphkFirst = pHotKey;
@@ -515,45 +519,47 @@ UserUnregisterHotKey(PWND pWnd, int id)
bRet = TRUE;
}
else /* This hotkey will stay, use its next ptr */
else
{
/* This hotkey will stay, use its next ptr */
pLink = &pHotKey->pNext;
}
/* Move to the next entry */
pHotKey = phkNext;
}
return bRet;
}
/* SYSCALLS *****************************************************************/
BOOL APIENTRY
NtUserRegisterHotKey(HWND hWnd,
int id,
UINT fsModifiers,
UINT vk)
{
PHOT_KEY pHotKey;
PWND pWnd = NULL;
PTHREADINFO pHotKeyThread;
BOOL bRet = FALSE;
TRACE("Enter NtUserRegisterHotKey\n");
if (fsModifiers & ~(MOD_ALT|MOD_CONTROL|MOD_SHIFT|MOD_WIN)) // FIXME: Does Win2k3 support MOD_NOREPEAT?
// FIXME: Does Win2k3 support MOD_NOREPEAT?
if (fsModifiers & ~(MOD_ALT | MOD_CONTROL | MOD_SHIFT | MOD_WIN))
{
WARN("Invalid modifiers: %x\n", fsModifiers);
EngSetLastError(ERROR_INVALID_FLAGS);
return 0;
return FALSE;
}
UserEnterExclusive();
/* Find hotkey thread */
/* Check the hotkey thread */
if (hWnd == NULL)
{
pHotKeyThread = gptiCurrent;
pWnd = NULL;
}
else
{
@@ -561,44 +567,16 @@ NtUserRegisterHotKey(HWND hWnd,
if (!pWnd)
goto cleanup;
pHotKeyThread = pWnd->head.pti;
/* Fix wine msg "Window on another thread" test_hotkey */
/* FIXME?? "Fix" wine msg "Window on another thread" test_hotkey */
if (pWnd->head.pti != gptiCurrent)
{
EngSetLastError(ERROR_WINDOW_OF_OTHER_THREAD);
WARN("Must be from the same Thread.\n");
goto cleanup;
EngSetLastError(ERROR_WINDOW_OF_OTHER_THREAD);
WARN("Must be from the same Thread.\n");
goto cleanup;
}
}
/* Check for existing hotkey */
if (IsHotKey(fsModifiers, vk))
{
EngSetLastError(ERROR_HOTKEY_ALREADY_REGISTERED);
WARN("Hotkey already exists\n");
goto cleanup;
}
/* Create new hotkey */
pHotKey = ExAllocatePoolWithTag(PagedPool, sizeof(HOT_KEY), USERTAG_HOTKEY);
if (pHotKey == NULL)
{
EngSetLastError(ERROR_NOT_ENOUGH_MEMORY);
goto cleanup;
}
pHotKey->pti = pHotKeyThread;
pHotKey->pWnd = pWnd;
pHotKey->fsModifiers = fsModifiers;
pHotKey->vk = vk;
pHotKey->id = id;
/* Insert hotkey to the global list */
pHotKey->pNext = gphkFirst;
gphkFirst = pHotKey;
bRet = TRUE;
bRet = UserRegisterHotKey(pWnd, id, fsModifiers, vk);
cleanup:
TRACE("Leave NtUserRegisterHotKey, ret=%i\n", bRet);
@@ -606,41 +584,20 @@ cleanup:
return bRet;
}
BOOL APIENTRY
NtUserUnregisterHotKey(HWND hWnd, int id)
{
PHOT_KEY pHotKey = gphkFirst, phkNext, *pLink = &gphkFirst;
BOOL bRet = FALSE;
PWND pWnd = NULL;
TRACE("Enter NtUserUnregisterHotKey\n");
UserEnterExclusive();
/* Fail if given window is invalid */
/* Fail if the given window is invalid */
if (hWnd && !(pWnd = UserGetWindowObject(hWnd)))
goto cleanup;
while (pHotKey)
{
/* Save next ptr for later use */
phkNext = pHotKey->pNext;
/* Should we delete this hotkey? */
if (pHotKey->pWnd == pWnd && pHotKey->id == id)
{
/* Update next ptr for previous hotkey and free memory */
*pLink = phkNext;
ExFreePoolWithTag(pHotKey, USERTAG_HOTKEY);
bRet = TRUE;
}
else /* This hotkey will stay, use its next ptr */
pLink = &pHotKey->pNext;
/* Move to the next entry */
pHotKey = phkNext;
}
bRet = UserUnregisterHotKey(pWnd, id);
cleanup:
TRACE("Leave NtUserUnregisterHotKey, ret=%i\n", bRet);

View File

@@ -27,7 +27,7 @@ VOID FASTCALL UnregisterThreadHotKeys(PTHREADINFO pti);
BOOL NTAPI co_UserProcessHotKeys(WORD wVk, BOOL bIsDown);
UINT FASTCALL DefWndGetHotKey(PWND pWnd);
INT FASTCALL DefWndSetHotKey(PWND pWnd, WPARAM wParam);
VOID FASTCALL StartDebugHotKeys(VOID);
VOID FASTCALL SetDebugHotKeys(VOID);
BOOL FASTCALL UserRegisterHotKey(PWND pWnd,int id,UINT fsModifiers,UINT vk);
BOOL FASTCALL UserUnregisterHotKey(PWND pWnd, int id);

View File

@@ -204,7 +204,7 @@ RawInputThreadMain(VOID)
UserRegisterHotKey(PWND_BOTTOM, IDHK_SNAP_UP, MOD_WIN, VK_UP);
UserRegisterHotKey(PWND_BOTTOM, IDHK_SNAP_DOWN, MOD_WIN, VK_DOWN);
// Register the debug hotkeys.
StartDebugHotKeys();
SetDebugHotKeys();
UserLeave();
}
}

View File

@@ -2187,18 +2187,14 @@ IntUninitMessagePumpHook(VOID)
}
BOOL FASTCALL
IntCallMsgFilter( LPMSG lpmsg, INT code)
IntCallMsgFilter(LPMSG lpmsg, INT code)
{
BOOL Ret = FALSE;
BOOL Ret;
Ret = co_HOOK_CallHooks(WH_SYSMSGFILTER, code, 0, (LPARAM)lpmsg);
if (!Ret)
Ret = co_HOOK_CallHooks(WH_MSGFILTER, code, 0, (LPARAM)lpmsg);
if ( co_HOOK_CallHooks( WH_SYSMSGFILTER, code, 0, (LPARAM)lpmsg))
{
Ret = TRUE;
}
else
{
Ret = co_HOOK_CallHooks( WH_MSGFILTER, code, 0, (LPARAM)lpmsg);
}
return Ret;
}
@@ -2447,16 +2443,7 @@ NtUserCallMsgFilter( LPMSG lpmsg, INT code)
_SEH2_END;
UserEnterExclusive();
if ( co_HOOK_CallHooks( WH_SYSMSGFILTER, code, 0, (LPARAM)&Msg))
{
Ret = TRUE;
}
else
{
Ret = co_HOOK_CallHooks( WH_MSGFILTER, code, 0, (LPARAM)&Msg);
}
Ret = IntCallMsgFilter(&Msg, code);
UserLeave();
_SEH2_TRY