From 30460460e52731ef2979c4b528cb4fdc86dacac7 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?R=C3=A9mi=20Bernon?= Date: Fri, 7 May 2021 10:29:43 +0200 Subject: [PATCH] user32: Cache current keyboard layout name. MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit To avoid iterating the registry every time GetKeyboardLayoutNameW is called. Signed-off-by: RĂ©mi Bernon Signed-off-by: Alexandre Julliard --- dlls/user32/input.c | 10 ++++++++++ dlls/user32/user_private.h | 1 + 2 files changed, 11 insertions(+) diff --git a/dlls/user32/input.c b/dlls/user32/input.c index adeb4f66804..1b2360ea083 100644 --- a/dlls/user32/input.c +++ b/dlls/user32/input.c @@ -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; diff --git a/dlls/user32/user_private.h b/dlls/user32/user_private.h index 1c7ac3355bc..1bc41888891 100644 --- a/dlls/user32/user_private.h +++ b/dlls/user32/user_private.h @@ -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 */