From adc00bcace9b7728c5849210605dbf930443c432 Mon Sep 17 00:00:00 2001 From: Barinade Date: Fri, 4 Aug 2023 00:17:10 -0500 Subject: [PATCH] add preference in advanced input options to try to force US layout scuffed solution for international keyboardists --- Themes/_fallback/Languages/en.ini | 2 ++ Themes/_fallback/Scripts/02 ThemePrefs.lua | 31 ++++++++++++++++++- Themes/_fallback/metrics.ini | 1 + src/Etterna/Globals/GameLoop.cpp | 36 ++++++++++++++-------- 4 files changed, 56 insertions(+), 14 deletions(-) diff --git a/Themes/_fallback/Languages/en.ini b/Themes/_fallback/Languages/en.ini index 72dfc95e8a..17862fb45f 100644 --- a/Themes/_fallback/Languages/en.ini +++ b/Themes/_fallback/Languages/en.ini @@ -298,6 +298,7 @@ DisplayColorDepth=Choose the color depth of the window. This option may not take DisplayResolution=Choose the output resolution. A higher resolution will show more detail, but requires a faster video card. FullscreenType=Change the Fullscreen type between borderless window and traditional fullscreen. Display Options=BGFit, Appearance and UI options. +FixKeyboardLayout=Turn this on to have the game force your keyboard layout to US (00000409) while focused on the game. Requires game restart. ScrollDir=Set the scroll direction of the notes. EasterEggs=Enable or disable some special easter eggs. Edit Songs/Steps=Edit Songs/Steps @@ -924,6 +925,7 @@ File2 Song Movie=File1 Song Movie File2 Song Still=File1 Song Still File2 Type=File1 Type Fill Machine Stats=Fill Machine Stats +FixKeyboardLayout=Fix Keyboard Layout Force Color 1=Force Color 1 Force Color 2=Force Color 2 Force Effect=Force Effect diff --git a/Themes/_fallback/Scripts/02 ThemePrefs.lua b/Themes/_fallback/Scripts/02 ThemePrefs.lua index 359008239a..89ebb2f603 100644 --- a/Themes/_fallback/Scripts/02 ThemePrefs.lua +++ b/Themes/_fallback/Scripts/02 ThemePrefs.lua @@ -172,7 +172,7 @@ end function getScreenOptionsInputLines() if HOOKS.GetArchName():upper():find("^WINDOWS") ~= nil then -- windows - return "1,2,3,AH,AS,5,6,8,7,WindowsKey" + return "1,2,3,AH,AS,5,6,8,7,WindowsKey,KeyboardLayout" else -- mac and linux return "1,2,3,AH,AS,5,6,8,7" @@ -693,3 +693,32 @@ function DisableWindowsKeyInGameplay() return t end +function FixKeyboardLayout() + + local t = { + Name = "FixKeyboardLayout", + LayoutType = "ShowAllInRow", + SelectType = "SelectOne", + OneChoiceForAllPlayers = false, + ExportOnChange = true, + Choices = {THEME:GetString("OptionNames", "Off"), THEME:GetString("OptionNames", "On")}, + LoadSelections = function(self, list, pn) + local pref = PREFSMAN:GetPreference("FixKeyboardLayout") + if pref then + list[2] = true + else + list[1] = true + end + end, + SaveSelections = function(self, list, pn) + local value + value = list[2] + PREFSMAN:SetPreference("FixKeyboardLayout", value) + + return 0 + end + } + setmetatable(t, t) + return t +end + diff --git a/Themes/_fallback/metrics.ini b/Themes/_fallback/metrics.ini index ec78bbcd24..ff27986964 100644 --- a/Themes/_fallback/metrics.ini +++ b/Themes/_fallback/metrics.ini @@ -2273,6 +2273,7 @@ LineNames=getScreenOptionsInputLines() # old line names, now moved to /_fallback/scripts/02 themeprefs.lua # LineNames="1,2,3,AH,AS,5,6,7,8" LineWindowsKey="lua,DisableWindowsKeyInGameplay()" +LineKeyboardLayout="lua,FixKeyboardLayout()" Line1="conf,AutoMapOnJoyChange" Line2="conf,OnlyDedicatedMenuButtons" Line3="conf,DelayedBack" diff --git a/src/Etterna/Globals/GameLoop.cpp b/src/Etterna/Globals/GameLoop.cpp index 084028bf3a..a8d0c31ada 100644 --- a/src/Etterna/Globals/GameLoop.cpp +++ b/src/Etterna/Globals/GameLoop.cpp @@ -39,28 +39,43 @@ static float g_fUpdateRate = 1; static Preference g_bNeverBoostAppPriority("NeverBoostAppPriority",false); /* experimental: force a specific update rate. This prevents big animation jumps on frame skips. 0 to disable. */ static Preference g_fConstantUpdateDeltaSeconds("ConstantUpdateDeltaSeconds",0); +static Preference g_prefFixKeyboardLayout("FixKeyboardLayout", false); static std::string g_previousLayoutName; +static bool g_bNeverFixKeyboardLayout = false; static void setEnglishLayout() { - #ifdef _WIN32 +#ifdef _WIN32 char buffer2[KL_NAMELENGTH]; GetKeyboardLayoutName(buffer2); std::string layout2(buffer2); g_previousLayoutName = layout2; + + // to require a game restart if it is turned on midgame + if (!g_prefFixKeyboardLayout.Get()) { + g_bNeverFixKeyboardLayout = true; + } + if (g_bNeverFixKeyboardLayout) { + return; + } + Locator::getLogger()->info( - "Keyboard layout is switching from {} to english 00000409", layout2); + "Keyboard layout is switching from {} to English 00000409", layout2); // 00000409 is US standard LoadKeyboardLayoutA("00000409", KLF_ACTIVATE | KLF_SETFORPROCESS); - #endif +#endif } static void loadPreviousLayout() { - #ifdef _WIN32 + + // this is unguarded because it should Just Work + // but if peoples layouts start breaking, this is why + +#ifdef _WIN32 LoadKeyboardLayoutA(g_previousLayoutName.c_str(), KLF_ACTIVATE | KLF_SETFORPROCESS); @@ -68,7 +83,7 @@ loadPreviousLayout() GetKeyboardLayoutName(buffer1); std::string layout1(buffer1); Locator::getLogger()->info("Loaded external keyboard layout {}", layout1); - #endif +#endif } // Static Functions @@ -302,14 +317,9 @@ namespace GameLoop { void RunGameLoop() { Core::Platform::boostPriority(); - if (hasFocus) { - Locator::getLogger()->info( - "Game already focused, setting to english layout"); - setEnglishLayout(); - } else { - Locator::getLogger()->info( - "Game not yet focused, not switching layout"); - } + // set to the english layout if applicable + // this saves the system layout for the first time + setEnglishLayout(); while (!GameLoop::hasUserQuit()) { if (!g_NewGame.empty()) {