user32: Cache current keyboard layout name.

To avoid iterating the registry every time GetKeyboardLayoutNameW is
called.

Signed-off-by: Rémi Bernon <rbernon@codeweavers.com>
Signed-off-by: Alexandre Julliard <julliard@winehq.org>
This commit is contained in:
Rémi Bernon 2021-05-07 10:29:43 +02:00 committed by Alexandre Julliard
parent b943a69c1b
commit 30460460e5
2 changed files with 11 additions and 0 deletions

View File

@ -1129,6 +1129,7 @@ BOOL WINAPI GetKeyboardLayoutNameA(LPSTR pszKLID)
*/
BOOL WINAPI GetKeyboardLayoutNameW( WCHAR *name )
{
struct user_thread_info *info = get_user_thread_info();
WCHAR klid[KL_NAMELENGTH], value[5];
DWORD value_size, tmp, i = 0;
HKEY hkey;
@ -1142,6 +1143,12 @@ BOOL WINAPI GetKeyboardLayoutNameW( WCHAR *name )
return FALSE;
}
if (info->kbd_layout_id)
{
swprintf( name, KL_NAMELENGTH, L"%08X", info->kbd_layout_id );
return TRUE;
}
layout = GetKeyboardLayout( 0 );
tmp = HandleToUlong( layout );
if (HIWORD( tmp ) == LOWORD( tmp )) tmp = LOWORD( tmp );
@ -1166,6 +1173,8 @@ BOOL WINAPI GetKeyboardLayoutNameW( WCHAR *name )
RegCloseKey( hkey );
}
info->kbd_layout_id = wcstoul( name, NULL, 16 );
TRACE_(keyboard)( "ret %s\n", debugstr_w( name ) );
return TRUE;
}
@ -1394,6 +1403,7 @@ HKL WINAPI ActivateKeyboardLayout( HKL layout, UINT flags )
old_layout = info->kbd_layout;
info->kbd_layout = layout;
if (old_layout != layout) info->kbd_layout_id = 0;
if (!old_layout) return get_locale_kbd_layout();
return old_layout;

View File

@ -198,6 +198,7 @@ struct user_thread_info
ULONG_PTR GetMessageExtraInfoVal; /* Value for GetMessageExtraInfo */
struct user_key_state_info *key_state; /* Cache of global key state */
HKL kbd_layout; /* Current keyboard layout */
DWORD kbd_layout_id; /* Current keyboard layout ID */
HWND top_window; /* Desktop window */
HWND msg_window; /* HWND_MESSAGE parent window */
struct rawinput_thread_data *rawinput; /* RawInput thread local data / buffer */