Skip to content

Commit 955ce9b

Browse files
authored
UI: Fix static initialization in regards to hotkey map (#1643)
1 parent 1ec8c71 commit 955ce9b

File tree

2 files changed

+25
-12
lines changed

2 files changed

+25
-12
lines changed

src/gui/wxgui/input/HotkeySettings.cpp

Lines changed: 24 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -112,13 +112,7 @@ std::optional<std::string> SaveScreenshot(std::vector<uint8> data, int width, in
112112
}
113113

114114
extern WindowSystem::WindowInfo g_window_info;
115-
const std::unordered_map<sHotkeyCfg*, std::function<void(void)>> HotkeySettings::s_cfgHotkeyToFuncMap{
116-
{&s_cfgHotkeys.toggleFullscreen, [](void) { s_mainWindow->ShowFullScreen(!s_mainWindow->IsFullScreen()); }},
117-
{&s_cfgHotkeys.toggleFullscreenAlt, [](void) { s_mainWindow->ShowFullScreen(!s_mainWindow->IsFullScreen()); }},
118-
{&s_cfgHotkeys.exitFullscreen, [](void) { s_mainWindow->ShowFullScreen(false); }},
119-
{&s_cfgHotkeys.takeScreenshot, [](void) { if(g_renderer) g_renderer->RequestScreenshot(SaveScreenshot); }},
120-
{&s_cfgHotkeys.toggleFastForward, [](void) { ActiveSettings::SetTimerShiftFactor((ActiveSettings::GetTimerShiftFactor() < 3) ? 3 : 1); }},
121-
};
115+
std::unordered_map<sHotkeyCfg*, std::function<void(void)>> HotkeySettings::s_cfgHotkeyToFuncMap;
122116

123117
struct HotkeyEntry
124118
{
@@ -180,6 +174,25 @@ HotkeySettings::~HotkeySettings()
180174

181175
void HotkeySettings::Init(wxFrame* mainWindowFrame)
182176
{
177+
s_cfgHotkeyToFuncMap.insert({
178+
{&s_cfgHotkeys.toggleFullscreen, [](void) {
179+
s_mainWindow->ShowFullScreen(!s_mainWindow->IsFullScreen());
180+
}},
181+
{&s_cfgHotkeys.toggleFullscreenAlt, [](void) {
182+
s_mainWindow->ShowFullScreen(!s_mainWindow->IsFullScreen());
183+
}},
184+
{&s_cfgHotkeys.exitFullscreen, [](void) {
185+
s_mainWindow->ShowFullScreen(false);
186+
}},
187+
{&s_cfgHotkeys.takeScreenshot, [](void) {
188+
if (g_renderer)
189+
g_renderer->RequestScreenshot(SaveScreenshot);
190+
}},
191+
{&s_cfgHotkeys.toggleFastForward, [](void) {
192+
ActiveSettings::SetTimerShiftFactor((ActiveSettings::GetTimerShiftFactor() < 3) ? 3 : 1);
193+
}},
194+
});
195+
183196
s_keyboardHotkeyToFuncMap.reserve(s_cfgHotkeyToFuncMap.size());
184197
for (const auto& [cfgHotkey, func] : s_cfgHotkeyToFuncMap)
185198
{
@@ -325,7 +338,7 @@ void HotkeySettings::OnKeyboardHotkeyInputRightClick(wxMouseEvent& event)
325338
}
326339
auto* inputButton = static_cast<wxButton*>(event.GetEventObject());
327340
auto& cfgHotkey = *static_cast<sHotkeyCfg*>(inputButton->GetClientData());
328-
uKeyboardHotkey newHotkey{ sHotkeyCfg::keyboardNone };
341+
uKeyboardHotkey newHotkey{sHotkeyCfg::keyboardNone};
329342
if (cfgHotkey.keyboard.raw != newHotkey.raw)
330343
{
331344
m_needToSave |= true;
@@ -344,7 +357,7 @@ void HotkeySettings::OnControllerHotkeyInputRightClick(wxMouseEvent& event)
344357
}
345358
auto* inputButton = static_cast<wxButton*>(event.GetEventObject());
346359
auto& cfgHotkey = *static_cast<sHotkeyCfg*>(inputButton->GetClientData());
347-
ControllerHotkey_t newHotkey{ sHotkeyCfg::controllerNone };
360+
ControllerHotkey_t newHotkey{sHotkeyCfg::controllerNone};
348361
if (cfgHotkey.controller != newHotkey)
349362
{
350363
m_needToSave |= true;
@@ -394,7 +407,7 @@ void HotkeySettings::OnKeyUp(wxKeyEvent& event)
394407
FinalizeInput<uKeyboardHotkey>(inputButton);
395408
}
396409

397-
template <typename T>
410+
template<typename T>
398411
void HotkeySettings::FinalizeInput(wxButton* inputButton)
399412
{
400413
auto& cfgHotkey = *static_cast<sHotkeyCfg*>(inputButton->GetClientData());
@@ -409,7 +422,7 @@ void HotkeySettings::FinalizeInput(wxButton* inputButton)
409422
m_activeInputButton = nullptr;
410423
}
411424

412-
template <typename T>
425+
template<typename T>
413426
void HotkeySettings::RestoreInputButton(void)
414427
{
415428
FinalizeInput<T>(m_activeInputButton);

src/gui/wxgui/input/HotkeySettings.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,7 @@ class HotkeySettings : public wxFrame
1919

2020
private:
2121
inline static wxFrame* s_mainWindow = nullptr;
22-
static const std::unordered_map<sHotkeyCfg*, std::function<void(void)>> s_cfgHotkeyToFuncMap;
22+
static std::unordered_map<sHotkeyCfg*, std::function<void(void)>> s_cfgHotkeyToFuncMap;
2323
inline static std::unordered_map<uint16, std::function<void(void)>> s_keyboardHotkeyToFuncMap{};
2424
inline static std::unordered_map<uint16, std::function<void(void)>> s_controllerHotkeyToFuncMap{};
2525
inline static auto& s_cfgHotkeys = GetWxGUIConfig().hotkeys;

0 commit comments

Comments
 (0)