From: <sv...@op...> - 2025-01-09 20:11:45
|
Author: sagamusix Date: Thu Jan 9 21:11:38 2025 New Revision: 22853 URL: https://source.openmpt.org/browse/openmpt/?op=revision&rev=22853 Log: [Fix] If multiple keyboard layouts were installed, scancode conversion could be based on the wrong layout, causing e.g. B-4 and Note-Off keys to be swapped on a setup with active US keyboard layout but also a German layout being present. Modified: trunk/OpenMPT/mptrack/CommandSet.cpp Modified: trunk/OpenMPT/mptrack/CommandSet.cpp ============================================================================== --- trunk/OpenMPT/mptrack/CommandSet.cpp Thu Jan 9 19:35:13 2025 (r22852) +++ trunk/OpenMPT/mptrack/CommandSet.cpp Thu Jan 9 21:11:38 2025 (r22853) @@ -45,6 +45,15 @@ {kcCommentsStartNotes, kcCommentsStartNoteStops}, }; +std::vector<HKL> GetKeyboardLayouts() +{ + std::vector<HKL> layouts(GetKeyboardLayoutList(0, nullptr)); + GetKeyboardLayoutList(static_cast<int>(layouts.size()), layouts.data()); + // GetKeyboardLayoutList appears to return the layouts in no particular order. Always force the active layout to be evaluated first. + layouts.insert(layouts.begin(), GetKeyboardLayout(0)); + return layouts; +} + }; // namespace #ifdef MPT_ALL_LOGGING @@ -1685,8 +1694,7 @@ "//----------------------------------------------------------------------\n" "version:" << mpt::ToCharset(mpt::Charset::ASCII, Version::Current().ToUString()) << "\n"; - std::vector<HKL> layouts(GetKeyboardLayoutList(0, nullptr)); - GetKeyboardLayoutList(static_cast<int>(layouts.size()), layouts.data()); + const std::vector<HKL> layouts = GetKeyboardLayouts(); for(int ctx = 0; ctx < kCtxMaxInputContexts; ctx++) { @@ -1743,8 +1751,7 @@ CString errText; int errorCount = 0; - std::vector<HKL> layouts(GetKeyboardLayoutList(0, nullptr)); - GetKeyboardLayoutList(static_cast<int>(layouts.size()), layouts.data()); + const std::vector<HKL> layouts = GetKeyboardLayouts(); const std::string whitespace(" \n\r\t"); while(iStrm.getline(s, std::size(s))) @@ -1911,8 +1918,7 @@ QuickChange_SetEffects(*specs); } - std::vector<HKL> layouts(GetKeyboardLayoutList(0, nullptr)); - GetKeyboardLayoutList(static_cast<int>(layouts.size()), layouts.data()); + const std::vector<HKL> layouts = GetKeyboardLayouts(); mpt::span<const DefaultKeybinding> defaults; switch(preset) @@ -2172,8 +2178,7 @@ { // Hack for situations where a non-latin keyboard layout without A...Z key code mapping may the current layout (e.g. Russian), // but a latin layout (e.g. EN-US) is installed as well. - std::vector<HKL> layouts(GetKeyboardLayoutList(0, nullptr)); - GetKeyboardLayoutList(static_cast<int>(layouts.size()), layouts.data()); + const std::vector<HKL> layouts = GetKeyboardLayouts(); SHORT codeNmod = -1; for(auto i = layouts.begin(); i != layouts.end() && codeNmod == -1; i++) { |