From 955ce9b9737c4f163ada4d419854521aa1e9ebd0 Mon Sep 17 00:00:00 2001 From: oltolm Date: Wed, 23 Jul 2025 01:05:56 +0200 Subject: [PATCH] UI: Fix static initialization in regards to hotkey map (#1643) --- src/gui/wxgui/input/HotkeySettings.cpp | 35 ++++++++++++++++++-------- src/gui/wxgui/input/HotkeySettings.h | 2 +- 2 files changed, 25 insertions(+), 12 deletions(-) diff --git a/src/gui/wxgui/input/HotkeySettings.cpp b/src/gui/wxgui/input/HotkeySettings.cpp index 626bdcd1..15b05fc6 100644 --- a/src/gui/wxgui/input/HotkeySettings.cpp +++ b/src/gui/wxgui/input/HotkeySettings.cpp @@ -112,13 +112,7 @@ std::optional SaveScreenshot(std::vector data, int width, in } extern WindowSystem::WindowInfo g_window_info; -const std::unordered_map> HotkeySettings::s_cfgHotkeyToFuncMap{ - {&s_cfgHotkeys.toggleFullscreen, [](void) { s_mainWindow->ShowFullScreen(!s_mainWindow->IsFullScreen()); }}, - {&s_cfgHotkeys.toggleFullscreenAlt, [](void) { s_mainWindow->ShowFullScreen(!s_mainWindow->IsFullScreen()); }}, - {&s_cfgHotkeys.exitFullscreen, [](void) { s_mainWindow->ShowFullScreen(false); }}, - {&s_cfgHotkeys.takeScreenshot, [](void) { if(g_renderer) g_renderer->RequestScreenshot(SaveScreenshot); }}, - {&s_cfgHotkeys.toggleFastForward, [](void) { ActiveSettings::SetTimerShiftFactor((ActiveSettings::GetTimerShiftFactor() < 3) ? 3 : 1); }}, -}; +std::unordered_map> HotkeySettings::s_cfgHotkeyToFuncMap; struct HotkeyEntry { @@ -180,6 +174,25 @@ HotkeySettings::~HotkeySettings() void HotkeySettings::Init(wxFrame* mainWindowFrame) { + s_cfgHotkeyToFuncMap.insert({ + {&s_cfgHotkeys.toggleFullscreen, [](void) { + s_mainWindow->ShowFullScreen(!s_mainWindow->IsFullScreen()); + }}, + {&s_cfgHotkeys.toggleFullscreenAlt, [](void) { + s_mainWindow->ShowFullScreen(!s_mainWindow->IsFullScreen()); + }}, + {&s_cfgHotkeys.exitFullscreen, [](void) { + s_mainWindow->ShowFullScreen(false); + }}, + {&s_cfgHotkeys.takeScreenshot, [](void) { + if (g_renderer) + g_renderer->RequestScreenshot(SaveScreenshot); + }}, + {&s_cfgHotkeys.toggleFastForward, [](void) { + ActiveSettings::SetTimerShiftFactor((ActiveSettings::GetTimerShiftFactor() < 3) ? 3 : 1); + }}, + }); + s_keyboardHotkeyToFuncMap.reserve(s_cfgHotkeyToFuncMap.size()); for (const auto& [cfgHotkey, func] : s_cfgHotkeyToFuncMap) { @@ -325,7 +338,7 @@ void HotkeySettings::OnKeyboardHotkeyInputRightClick(wxMouseEvent& event) } auto* inputButton = static_cast(event.GetEventObject()); auto& cfgHotkey = *static_cast(inputButton->GetClientData()); - uKeyboardHotkey newHotkey{ sHotkeyCfg::keyboardNone }; + uKeyboardHotkey newHotkey{sHotkeyCfg::keyboardNone}; if (cfgHotkey.keyboard.raw != newHotkey.raw) { m_needToSave |= true; @@ -344,7 +357,7 @@ void HotkeySettings::OnControllerHotkeyInputRightClick(wxMouseEvent& event) } auto* inputButton = static_cast(event.GetEventObject()); auto& cfgHotkey = *static_cast(inputButton->GetClientData()); - ControllerHotkey_t newHotkey{ sHotkeyCfg::controllerNone }; + ControllerHotkey_t newHotkey{sHotkeyCfg::controllerNone}; if (cfgHotkey.controller != newHotkey) { m_needToSave |= true; @@ -394,7 +407,7 @@ void HotkeySettings::OnKeyUp(wxKeyEvent& event) FinalizeInput(inputButton); } -template +template void HotkeySettings::FinalizeInput(wxButton* inputButton) { auto& cfgHotkey = *static_cast(inputButton->GetClientData()); @@ -409,7 +422,7 @@ void HotkeySettings::FinalizeInput(wxButton* inputButton) m_activeInputButton = nullptr; } -template +template void HotkeySettings::RestoreInputButton(void) { FinalizeInput(m_activeInputButton); diff --git a/src/gui/wxgui/input/HotkeySettings.h b/src/gui/wxgui/input/HotkeySettings.h index c9395b5a..52181968 100644 --- a/src/gui/wxgui/input/HotkeySettings.h +++ b/src/gui/wxgui/input/HotkeySettings.h @@ -19,7 +19,7 @@ public: private: inline static wxFrame* s_mainWindow = nullptr; - static const std::unordered_map> s_cfgHotkeyToFuncMap; + static std::unordered_map> s_cfgHotkeyToFuncMap; inline static std::unordered_map> s_keyboardHotkeyToFuncMap{}; inline static std::unordered_map> s_controllerHotkeyToFuncMap{}; inline static auto& s_cfgHotkeys = GetWxGUIConfig().hotkeys;