Skip to content

Commit

Permalink
add preference in advanced input options to try to force US layout
Browse files Browse the repository at this point in the history
scuffed solution for international keyboardists
  • Loading branch information
poco0317 committed Aug 4, 2023
1 parent aae64f2 commit adc00bc
Show file tree
Hide file tree
Showing 4 changed files with 56 additions and 14 deletions.
2 changes: 2 additions & 0 deletions Themes/_fallback/Languages/en.ini
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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
Expand Down
31 changes: 30 additions & 1 deletion Themes/_fallback/Scripts/02 ThemePrefs.lua
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand Down Expand Up @@ -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

1 change: 1 addition & 0 deletions Themes/_fallback/metrics.ini
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand Down
36 changes: 23 additions & 13 deletions src/Etterna/Globals/GameLoop.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -39,36 +39,51 @@ static float g_fUpdateRate = 1;
static Preference<bool> g_bNeverBoostAppPriority("NeverBoostAppPriority",false);
/* experimental: force a specific update rate. This prevents big animation jumps on frame skips. 0 to disable. */
static Preference<float> g_fConstantUpdateDeltaSeconds("ConstantUpdateDeltaSeconds",0);
static Preference<bool> 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);

char buffer1[KL_NAMELENGTH];
GetKeyboardLayoutName(buffer1);
std::string layout1(buffer1);
Locator::getLogger()->info("Loaded external keyboard layout {}", layout1);
#endif
#endif
}

// Static Functions
Expand Down Expand Up @@ -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()) {
Expand Down

0 comments on commit adc00bc

Please sign in to comment.