[KBSWITCH][NTUSER] Realize Shift+Alt language switch (#4622)

- Fix co_UserProcessHotKeys on modifiers-only hot-keys.
- Add Alt+Shift hot-keys to kbswitch window.
CORE-11737
This commit is contained in:
Katayama Hirofumi MZ 2022-08-24 07:31:46 +09:00 committed by GitHub
parent 372a445ad6
commit b4f73f040f
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
2 changed files with 37 additions and 4 deletions

View file

@ -4,6 +4,7 @@
* PURPOSE: Switching Keyboard Layouts
* PROGRAMMERS: Dmitry Chapyshev (dmitry@reactos.org)
* Colin Finck (mail@colinfinck.de)
* Katayama Hirofumi MZ (katayama.hirofumi.mz@gmail.com)
*/
#include "kbswitch.h"
@ -13,7 +14,7 @@
PKBSWITCHSETHOOKS KbSwitchSetHooks = NULL;
PKBSWITCHDELETEHOOKS KbSwitchDeleteHooks = NULL;
UINT ShellHookMessage = 0;
DWORD dwAltShiftHotKeyId = 0, dwShiftAltHotKeyId = 0;
static BOOL
GetLayoutID(LPTSTR szLayoutNum, LPTSTR szLCID, SIZE_T LCIDLength);
@ -414,6 +415,25 @@ UpdateLanguageDisplayCurrent(HWND hwnd, WPARAM wParam)
return UpdateLanguageDisplay(hwnd, GetKeyboardLayout(GetWindowThreadProcessId((HWND)wParam, 0)));
}
VOID DoRegisterAltShiftHotKeys(HWND hwnd)
{
dwAltShiftHotKeyId = GlobalAddAtom(TEXT("ReactOS Alt+Shift"));
dwShiftAltHotKeyId = GlobalAddAtom(TEXT("ReactOS Shift+Alt"));
RegisterHotKey(hwnd, dwAltShiftHotKeyId, MOD_ALT | MOD_SHIFT, VK_SHIFT);
RegisterHotKey(hwnd, dwShiftAltHotKeyId, MOD_ALT | MOD_SHIFT, VK_MENU);
}
VOID DoUnregisterAltShiftHotKeys(HWND hwnd)
{
UnregisterHotKey(hwnd, dwAltShiftHotKeyId);
UnregisterHotKey(hwnd, dwShiftAltHotKeyId);
GlobalDeleteAtom(dwAltShiftHotKeyId);
GlobalDeleteAtom(dwShiftAltHotKeyId);
dwAltShiftHotKeyId = dwShiftAltHotKeyId = 0;
}
LRESULT CALLBACK
WndProc(HWND hwnd, UINT Message, WPARAM wParam, LPARAM lParam)
{
@ -431,6 +451,7 @@ WndProc(HWND hwnd, UINT Message, WPARAM wParam, LPARAM lParam)
ActivateLayout(hwnd, ulCurrentLayoutNum);
s_uTaskbarRestart = RegisterWindowMessage(TEXT("TaskbarCreated"));
DoRegisterAltShiftHotKeys(hwnd);
return 0;
}
@ -439,10 +460,19 @@ WndProc(HWND hwnd, UINT Message, WPARAM wParam, LPARAM lParam)
return UpdateLanguageDisplay(hwnd, (HKL)lParam);
}
case WM_HOTKEY:
{
if (wParam != dwAltShiftHotKeyId && wParam != dwShiftAltHotKeyId)
break;
/* FALL THROUGH */
}
case WM_LOAD_LAYOUT:
{
ActivateLayout(hwnd, GetNextLayout());
ULONG uNextNum = GetNextLayout();
if (ulCurrentLayoutNum != uNextNum)
ActivateLayout(hwnd, uNextNum);
return 0;
}
@ -526,6 +556,7 @@ WndProc(HWND hwnd, UINT Message, WPARAM wParam, LPARAM lParam)
case WM_DESTROY:
{
DoUnregisterAltShiftHotKeys(hwnd);
DeleteHooks();
DestroyMenu(hRightPopupMenu);
DelTrayIcon(hwnd);

View file

@ -211,7 +211,9 @@ co_UserProcessHotKeys(WORD wVk, BOOL bIsDown)
if (IsModifier)
{
/* Modifier key up -- modifier-only keys are triggered here */
pHotKey = IsHotKey(gfsModOnlyCandidate, 0);
pHotKey = IsHotKey(gfsModOnlyCandidate, wVk);
if (!pHotKey)
pHotKey = IsHotKey(gfsModOnlyCandidate, 0);
gfsModOnlyCandidate = 0;
}
else