-
Notifications
You must be signed in to change notification settings - Fork 118
Render Snapshot to Disk accelerator from the active keyboard layout #5684
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: develop
Are you sure you want to change the base?
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change | ||||||||||||
|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
|
|
@@ -321,4 +321,46 @@ U16 LLKeyboardWin32::inverseTranslateExtendedKey(const KEY translated_key) | |||||||||||||
| return inverseTranslateKey(converted_key); | ||||||||||||||
| } | ||||||||||||||
|
|
||||||||||||||
| std::string LLKeyboardWin32::stringFromAcceleratorMenuKeyImpl(KEY key, bool translate) | ||||||||||||||
| { | ||||||||||||||
| U16 os_key = inverseTranslateExtendedKey(key); | ||||||||||||||
| if (os_key == 0) | ||||||||||||||
| { | ||||||||||||||
| return LLKeyboard::stringFromAcceleratorMenuKeyImpl(key, translate); | ||||||||||||||
| } | ||||||||||||||
|
|
||||||||||||||
| HKL layout = GetKeyboardLayout(0); | ||||||||||||||
| UINT scan_code = MapVirtualKeyEx(os_key, MAPVK_VK_TO_VSC, layout); | ||||||||||||||
| BYTE keyboard_state[256] = {}; | ||||||||||||||
| wchar_t chars[8] = {}; | ||||||||||||||
| int res = ToUnicodeEx( | ||||||||||||||
| os_key, | ||||||||||||||
| scan_code, | ||||||||||||||
| keyboard_state, | ||||||||||||||
| chars, | ||||||||||||||
| 8, | ||||||||||||||
| 1 << 2, | ||||||||||||||
| layout); | ||||||||||||||
|
|
||||||||||||||
| if ((res == 1 || res == -1) && chars[0] >= 0x20) | ||||||||||||||
| { | ||||||||||||||
| std::string key_string = ll_convert_wide_to_string(std::wstring(chars, 1)); | ||||||||||||||
| if (!key_string.empty()) | ||||||||||||||
| { | ||||||||||||||
|
||||||||||||||
| { | |
| { | |
| if (key_string.size() == 1 && key_string[0] >= 'a' && key_string[0] <= 'z') | |
| { | |
| key_string[0] = static_cast<char>(key_string[0] - 'a' + 'A'); | |
| } |
Copilot
AI
Apr 21, 2026
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
ToUnicodeEx() can have thread-global side effects related to dead-key and keyboard-buffer state on some Windows versions (see the existing cautionary comment around ToUnicodeEx usage in llviewerwindow.cpp). In particular, treating res == -1 (dead key) as success without clearing the dead-key state risks impacting subsequent character translation/WM_CHAR handling on this UI thread. Consider avoiding the res == -1 path (fall back to the base implementation for dead keys) or explicitly clearing the dead-key state after the call (or using an alternative like MapVirtualKeyEx(..., MAPVK_VK_TO_CHAR, ...) that doesn’t mutate dead-key state).
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
LLKeyboard::stringFromAcceleratorMenuKey()checksgKeyboard != NULL, but in thegKeyboard == NULLpath it callsstringFromKey(key, translate), which (whentranslateis true) dereferencesgKeyboard->mStringTranslatorand can still crash. Consider returningstringFromKey(key, /*translate=*/false)here (or otherwise avoiding anygKeyboardaccess) so the NULL-guard is actually effective.