Skip to content

Commit 8db7cff

Browse files
committed
InputManager: Remove hotkey list indirection
Should also fix GCC link errors in Release builds.
1 parent 604b7ce commit 8db7cff

File tree

8 files changed

+37
-65
lines changed

8 files changed

+37
-65
lines changed

src/core/fullscreenui_settings.cpp

Lines changed: 6 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1566,17 +1566,16 @@ void FullscreenUI::PopulateHotkeyList()
15661566
return;
15671567

15681568
// sort hotkeys by category so we don't duplicate the groups
1569-
const auto hotkeys = InputManager::GetHotkeyList();
1569+
const auto hotkeys = Core::GetHotkeyList();
15701570
s_settings_locals.hotkey_list_cache.reserve(hotkeys.size());
15711571

15721572
// this mess is needed to preserve the category order
1573-
for (size_t i = 0; i < hotkeys.size(); i++)
1573+
for (const HotkeyInfo& hk : hotkeys)
15741574
{
1575-
const HotkeyInfo* hk = hotkeys[i];
15761575
size_t j;
15771576
for (j = 0; j < s_settings_locals.hotkey_list_cache.size(); j++)
15781577
{
1579-
if (std::strcmp(hk->category, s_settings_locals.hotkey_list_cache[j]->category) == 0)
1578+
if (std::strcmp(hk.category, s_settings_locals.hotkey_list_cache[j]->category) == 0)
15801579
break;
15811580
}
15821581
if (j != s_settings_locals.hotkey_list_cache.size())
@@ -1586,12 +1585,12 @@ void FullscreenUI::PopulateHotkeyList()
15861585
}
15871586

15881587
// add all hotkeys with this category
1589-
for (const HotkeyInfo* other_hk : hotkeys)
1588+
for (const HotkeyInfo& other_hk : hotkeys)
15901589
{
1591-
if (std::strcmp(hk->category, other_hk->category) != 0)
1590+
if (std::strcmp(hk.category, other_hk.category) != 0)
15921591
continue;
15931592

1594-
s_settings_locals.hotkey_list_cache.push_back(other_hk);
1593+
s_settings_locals.hotkey_list_cache.push_back(&other_hk);
15951594
}
15961595
}
15971596
}

src/core/hotkeys.cpp

Lines changed: 9 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -85,6 +85,8 @@ static void HotkeyToggleOSD()
8585
GPUThread::UpdateSettings(true, false, false);
8686
}
8787

88+
#define DEFINE_HOTKEY(name, category, display_name, handler) {(name), (category), (display_name), (handler)},
89+
8890
#ifndef __ANDROID__
8991

9092
#define DEFINE_NON_ANDROID_HOTKEY(name, category, display_name, handler) \
@@ -96,7 +98,7 @@ static void HotkeyToggleOSD()
9698

9799
#endif
98100

99-
BEGIN_HOTKEY_LIST(g_common_hotkeys)
101+
static constexpr const HotkeyInfo s_hotkey_list[] = {
100102

101103
DEFINE_NON_ANDROID_HOTKEY("OpenPauseMenu", TRANSLATE_NOOP("Hotkeys", "Interface"),
102104
TRANSLATE_NOOP("Hotkeys", "Open Pause Menu"), [](s32 pressed) {
@@ -768,5 +770,10 @@ DEFINE_HOTKEY("ToggleVRAMView", TRANSLATE_NOOP("Hotkeys", "Debugging"), TRANSLAT
768770
TRANSLATE_STR("OSDMessage", "Now showing display."));
769771
}
770772
})
773+
};
774+
775+
std::span<const HotkeyInfo> Core::GetHotkeyList()
776+
{
777+
return s_hotkey_list;
778+
}
771779

772-
END_HOTKEY_LIST()

src/duckstation-mini/mini_host.cpp

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1490,9 +1490,6 @@ bool Host::ShouldPreferHostFileSelector()
14901490
return false;
14911491
}
14921492

1493-
BEGIN_HOTKEY_LIST(g_host_hotkeys)
1494-
END_HOTKEY_LIST()
1495-
14961493
static void SignalHandler(int signal)
14971494
{
14981495
// First try the normal (graceful) shutdown/exit.

src/duckstation-qt/hotkeysettingswidget.cpp

Lines changed: 4 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -102,10 +102,9 @@ void HotkeySettingsWidget::createButtons()
102102

103103
const QPalette label_palette = getLabelPalette(QtHost::IsDarkApplicationTheme());
104104
const QPalette row_palette = getRowPalette();
105-
const std::vector<const HotkeyInfo*> hotkeys(InputManager::GetHotkeyList());
106-
for (const HotkeyInfo* hotkey : hotkeys)
105+
for (const HotkeyInfo& hotkey : Core::GetHotkeyList())
107106
{
108-
const QString category(qApp->translate("Hotkeys", hotkey->category));
107+
const QString category(qApp->translate("Hotkeys", hotkey.category));
109108

110109
auto iter = m_categories.find(category);
111110
if (iter == m_categories.end())
@@ -146,10 +145,10 @@ void HotkeySettingsWidget::createButtons()
146145
QHBoxLayout* row_layout = new QHBoxLayout(row);
147146
row_layout->setContentsMargins(LR_MARGIN, TB_MARGIN, LR_MARGIN, TB_MARGIN);
148147

149-
row_layout->addWidget(new QLabel(qApp->translate("Hotkeys", hotkey->display_name), row));
148+
row_layout->addWidget(new QLabel(qApp->translate("Hotkeys", hotkey.display_name), row));
150149

151150
InputBindingWidget* const bind = new InputBindingWidget(row, m_dialog->getEditingSettingsInterface(),
152-
InputBindingInfo::Type::Button, "Hotkeys", hotkey->name);
151+
InputBindingInfo::Type::Button, "Hotkeys", hotkey.name);
153152
bind->setFixedWidth(300);
154153
row_layout->addWidget(bind);
155154
}

src/duckstation-qt/qthost.cpp

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -3069,9 +3069,6 @@ std::optional<WindowInfo> Host::GetTopLevelWindowInfo()
30693069
return ret;
30703070
}
30713071

3072-
BEGIN_HOTKEY_LIST(g_host_hotkeys)
3073-
END_HOTKEY_LIST()
3074-
30753072
static void SignalHandler(int signal)
30763073
{
30773074
// First try the normal (graceful) shutdown/exit.

src/duckstation-regtest/regtest_host.cpp

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -721,9 +721,6 @@ void Host::OnGameListEntriesChanged(std::span<const u32> changed_indices)
721721
// noop
722722
}
723723

724-
BEGIN_HOTKEY_LIST(g_host_hotkeys)
725-
END_HOTKEY_LIST()
726-
727724
static void SignalHandler(int signal)
728725
{
729726
std::signal(signal, SIG_DFL);

src/util/input_manager.cpp

Lines changed: 8 additions & 27 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@
77
#include "translation.h"
88

99
#include "core/controller.h"
10+
#include "core/core.h"
1011
#include "core/host.h"
1112
#include "core/system.h"
1213

@@ -188,11 +189,6 @@ static constexpr const std::array<const char*, 3> s_pointer_button_names = {
188189
{"LeftButton", "RightButton", "MiddleButton"}};
189190
static constexpr const std::array<const char*, 3> s_sensor_accelerometer_names = {{"Turn", "Tilt", "Rotate"}};
190191

191-
// ------------------------------------------------------------------------
192-
// Hotkeys
193-
// ------------------------------------------------------------------------
194-
static const HotkeyInfo* const s_hotkey_list[] = {g_common_hotkeys, g_host_hotkeys};
195-
196192
// ------------------------------------------------------------------------
197193
// Local Variables
198194
// ------------------------------------------------------------------------
@@ -950,29 +946,15 @@ float InputManager::ApplySingleBindingScale(float scale, float deadzone, float v
950946
return (deadzone > 0.0f && svalue < deadzone) ? 0.0f : svalue;
951947
}
952948

953-
std::vector<const HotkeyInfo*> InputManager::GetHotkeyList()
954-
{
955-
std::vector<const HotkeyInfo*> ret;
956-
for (const HotkeyInfo* hotkey_list : s_hotkey_list)
957-
{
958-
for (const HotkeyInfo* hotkey = hotkey_list; hotkey->name != nullptr; hotkey++)
959-
ret.push_back(hotkey);
960-
}
961-
return ret;
962-
}
963-
964949
void InputManager::AddHotkeyBindings(const SettingsInterface& si)
965950
{
966-
for (const HotkeyInfo* hotkey_list : s_hotkey_list)
951+
for (const HotkeyInfo& hotkey : Core::GetHotkeyList())
967952
{
968-
for (const HotkeyInfo* hotkey = hotkey_list; hotkey->name != nullptr; hotkey++)
969-
{
970-
const std::vector<std::string> bindings(si.GetStringList("Hotkeys", hotkey->name));
971-
if (bindings.empty())
972-
continue;
953+
const std::vector<std::string> bindings(si.GetStringList("Hotkeys", hotkey.name));
954+
if (bindings.empty())
955+
continue;
973956

974-
AddBindings(bindings, InputButtonEventHandler{hotkey->handler});
975-
}
957+
AddBindings(bindings, InputButtonEventHandler{hotkey.handler});
976958
}
977959
}
978960

@@ -1721,9 +1703,8 @@ void InputManager::CopyConfiguration(SettingsInterface* dest_si, const SettingsI
17211703

17221704
if (copy_hotkey_bindings)
17231705
{
1724-
std::vector<const HotkeyInfo*> hotkeys(InputManager::GetHotkeyList());
1725-
for (const HotkeyInfo* hki : hotkeys)
1726-
dest_si->CopyStringListValue(src_si, "Hotkeys", hki->name);
1706+
for (const HotkeyInfo& hk : Core::GetHotkeyList())
1707+
dest_si->CopyStringListValue(src_si, "Hotkeys", hk.name);
17271708
}
17281709
}
17291710

src/util/input_manager.h

Lines changed: 10 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -142,18 +142,6 @@ struct HotkeyInfo
142142
const char* display_name;
143143
void (*handler)(s32 pressed);
144144
};
145-
#define DECLARE_HOTKEY_LIST(name) extern const HotkeyInfo name[]
146-
#define BEGIN_HOTKEY_LIST(name) const HotkeyInfo name[] = {
147-
#define DEFINE_HOTKEY(name, category, display_name, handler) {(name), (category), (display_name), (handler)},
148-
#define END_HOTKEY_LIST() \
149-
{ \
150-
nullptr, nullptr, nullptr, nullptr \
151-
} \
152-
} \
153-
;
154-
155-
DECLARE_HOTKEY_LIST(g_common_hotkeys);
156-
DECLARE_HOTKEY_LIST(g_host_hotkeys);
157145

158146
/// Generic input bindings. These roughly match a DualShock 4 or XBox One controller.
159147
/// They are used for automatic binding to PS2 controller types, and for big picture mode navigation.
@@ -269,9 +257,6 @@ SmallString ConvertInputBindingKeysToString(InputBindingInfo::Type binding_type,
269257
using BindingIconMappingFunction = std::string_view (*)(std::string_view);
270258
bool PrettifyInputBinding(SmallStringBase& binding, BindingIconMappingFunction mapper = nullptr);
271259

272-
/// Returns a list of all hotkeys.
273-
std::vector<const HotkeyInfo*> GetHotkeyList();
274-
275260
/// Enumerates available devices. Returns a pair of the prefix (e.g. SDL-0) and the device name.
276261
using DeviceList = std::vector<std::tuple<InputBindingKey, std::string, std::string>>;
277262
DeviceList EnumerateDevices();
@@ -414,9 +399,18 @@ void OnInputDeviceDisconnected(InputBindingKey key, std::string_view identifier)
414399

415400
/// Creates a force feedback device interface for the specified source and device.
416401
std::unique_ptr<ForceFeedbackDevice> CreateForceFeedbackDevice(const std::string_view device, Error* error = nullptr);
402+
417403
} // namespace InputManager
418404

405+
namespace Core {
406+
407+
/// Returns a list of all hotkeys.
408+
std::span<const HotkeyInfo> GetHotkeyList();
409+
410+
} // namespace Core
411+
419412
namespace Host {
413+
420414
/// Adds any fixed bindings from the host.
421415
void AddFixedInputBindings(const SettingsInterface& si);
422416

@@ -428,4 +422,5 @@ void OnInputDeviceDisconnected(InputBindingKey key, std::string_view identifier)
428422

429423
/// Enables "relative" mouse mode, locking the cursor position and returning relative coordinates.
430424
void SetMouseMode(bool relative, bool hide_cursor);
425+
431426
} // namespace Host

0 commit comments

Comments
 (0)