diff --git a/mptrack/CommandSet.cpp b/mptrack/CommandSet.cpp index 4bc4fb8ef38..930556857c3 100644 --- a/mptrack/CommandSet.cpp +++ b/mptrack/CommandSet.cpp @@ -45,6 +45,15 @@ constexpr std::pair NoteRanges[] = {kcCommentsStartNotes, kcCommentsStartNoteStops}, }; +std::vector GetKeyboardLayouts() +{ + std::vector layouts(GetKeyboardLayoutList(0, nullptr)); + GetKeyboardLayoutList(static_cast(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 @@ ctx:UID:Description:Modifier:Key:EventMask "//----------------------------------------------------------------------\n" "version:" << mpt::ToCharset(mpt::Charset::ASCII, Version::Current().ToUString()) << "\n"; - std::vector layouts(GetKeyboardLayoutList(0, nullptr)); - GetKeyboardLayoutList(static_cast(layouts.size()), layouts.data()); + const std::vector layouts = GetKeyboardLayouts(); for(int ctx = 0; ctx < kCtxMaxInputContexts; ctx++) { @@ -1743,8 +1751,7 @@ bool CCommandSet::LoadFile(std::istream &iStrm, const mpt::ustring &filenameDesc CString errText; int errorCount = 0; - std::vector layouts(GetKeyboardLayoutList(0, nullptr)); - GetKeyboardLayoutList(static_cast(layouts.size()), layouts.data()); + const std::vector layouts = GetKeyboardLayouts(); const std::string whitespace(" \n\r\t"); while(iStrm.getline(s, std::size(s))) @@ -1911,8 +1918,7 @@ void CCommandSet::ApplyDefaultKeybindings(KeyboardPreset preset, const Version o QuickChange_SetEffects(*specs); } - std::vector layouts(GetKeyboardLayoutList(0, nullptr)); - GetKeyboardLayoutList(static_cast(layouts.size()), layouts.data()); + const std::vector layouts = GetKeyboardLayouts(); mpt::span defaults; switch(preset) @@ -2172,8 +2178,7 @@ bool CCommandSet::QuickChange_SetEffects(const CModSpecifications &modSpecs) { // 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 layouts(GetKeyboardLayoutList(0, nullptr)); - GetKeyboardLayoutList(static_cast(layouts.size()), layouts.data()); + const std::vector layouts = GetKeyboardLayouts(); SHORT codeNmod = -1; for(auto i = layouts.begin(); i != layouts.end() && codeNmod == -1; i++) {