InputManager: Remove hotkey list indirection

Should also fix GCC link errors in Release builds.
This commit is contained in:
Stenzek
2025-12-31 16:44:33 +10:00
parent 604b7ce73f
commit 8db7cff9d7
8 changed files with 37 additions and 65 deletions

View File

@@ -1566,17 +1566,16 @@ void FullscreenUI::PopulateHotkeyList()
return;
// sort hotkeys by category so we don't duplicate the groups
const auto hotkeys = InputManager::GetHotkeyList();
const auto hotkeys = Core::GetHotkeyList();
s_settings_locals.hotkey_list_cache.reserve(hotkeys.size());
// this mess is needed to preserve the category order
for (size_t i = 0; i < hotkeys.size(); i++)
for (const HotkeyInfo& hk : hotkeys)
{
const HotkeyInfo* hk = hotkeys[i];
size_t j;
for (j = 0; j < s_settings_locals.hotkey_list_cache.size(); j++)
{
if (std::strcmp(hk->category, s_settings_locals.hotkey_list_cache[j]->category) == 0)
if (std::strcmp(hk.category, s_settings_locals.hotkey_list_cache[j]->category) == 0)
break;
}
if (j != s_settings_locals.hotkey_list_cache.size())
@@ -1586,12 +1585,12 @@ void FullscreenUI::PopulateHotkeyList()
}
// add all hotkeys with this category
for (const HotkeyInfo* other_hk : hotkeys)
for (const HotkeyInfo& other_hk : hotkeys)
{
if (std::strcmp(hk->category, other_hk->category) != 0)
if (std::strcmp(hk.category, other_hk.category) != 0)
continue;
s_settings_locals.hotkey_list_cache.push_back(other_hk);
s_settings_locals.hotkey_list_cache.push_back(&other_hk);
}
}
}

View File

@@ -85,6 +85,8 @@ static void HotkeyToggleOSD()
GPUThread::UpdateSettings(true, false, false);
}
#define DEFINE_HOTKEY(name, category, display_name, handler) {(name), (category), (display_name), (handler)},
#ifndef __ANDROID__
#define DEFINE_NON_ANDROID_HOTKEY(name, category, display_name, handler) \
@@ -96,7 +98,7 @@ static void HotkeyToggleOSD()
#endif
BEGIN_HOTKEY_LIST(g_common_hotkeys)
static constexpr const HotkeyInfo s_hotkey_list[] = {
DEFINE_NON_ANDROID_HOTKEY("OpenPauseMenu", TRANSLATE_NOOP("Hotkeys", "Interface"),
TRANSLATE_NOOP("Hotkeys", "Open Pause Menu"), [](s32 pressed) {
@@ -768,5 +770,10 @@ DEFINE_HOTKEY("ToggleVRAMView", TRANSLATE_NOOP("Hotkeys", "Debugging"), TRANSLAT
TRANSLATE_STR("OSDMessage", "Now showing display."));
}
})
};
std::span<const HotkeyInfo> Core::GetHotkeyList()
{
return s_hotkey_list;
}
END_HOTKEY_LIST()

View File

@@ -1490,9 +1490,6 @@ bool Host::ShouldPreferHostFileSelector()
return false;
}
BEGIN_HOTKEY_LIST(g_host_hotkeys)
END_HOTKEY_LIST()
static void SignalHandler(int signal)
{
// First try the normal (graceful) shutdown/exit.

View File

@@ -102,10 +102,9 @@ void HotkeySettingsWidget::createButtons()
const QPalette label_palette = getLabelPalette(QtHost::IsDarkApplicationTheme());
const QPalette row_palette = getRowPalette();
const std::vector<const HotkeyInfo*> hotkeys(InputManager::GetHotkeyList());
for (const HotkeyInfo* hotkey : hotkeys)
for (const HotkeyInfo& hotkey : Core::GetHotkeyList())
{
const QString category(qApp->translate("Hotkeys", hotkey->category));
const QString category(qApp->translate("Hotkeys", hotkey.category));
auto iter = m_categories.find(category);
if (iter == m_categories.end())
@@ -146,10 +145,10 @@ void HotkeySettingsWidget::createButtons()
QHBoxLayout* row_layout = new QHBoxLayout(row);
row_layout->setContentsMargins(LR_MARGIN, TB_MARGIN, LR_MARGIN, TB_MARGIN);
row_layout->addWidget(new QLabel(qApp->translate("Hotkeys", hotkey->display_name), row));
row_layout->addWidget(new QLabel(qApp->translate("Hotkeys", hotkey.display_name), row));
InputBindingWidget* const bind = new InputBindingWidget(row, m_dialog->getEditingSettingsInterface(),
InputBindingInfo::Type::Button, "Hotkeys", hotkey->name);
InputBindingInfo::Type::Button, "Hotkeys", hotkey.name);
bind->setFixedWidth(300);
row_layout->addWidget(bind);
}

View File

@@ -3069,9 +3069,6 @@ std::optional<WindowInfo> Host::GetTopLevelWindowInfo()
return ret;
}
BEGIN_HOTKEY_LIST(g_host_hotkeys)
END_HOTKEY_LIST()
static void SignalHandler(int signal)
{
// First try the normal (graceful) shutdown/exit.

View File

@@ -721,9 +721,6 @@ void Host::OnGameListEntriesChanged(std::span<const u32> changed_indices)
// noop
}
BEGIN_HOTKEY_LIST(g_host_hotkeys)
END_HOTKEY_LIST()
static void SignalHandler(int signal)
{
std::signal(signal, SIG_DFL);

View File

@@ -7,6 +7,7 @@
#include "translation.h"
#include "core/controller.h"
#include "core/core.h"
#include "core/host.h"
#include "core/system.h"
@@ -188,11 +189,6 @@ static constexpr const std::array<const char*, 3> s_pointer_button_names = {
{"LeftButton", "RightButton", "MiddleButton"}};
static constexpr const std::array<const char*, 3> s_sensor_accelerometer_names = {{"Turn", "Tilt", "Rotate"}};
// ------------------------------------------------------------------------
// Hotkeys
// ------------------------------------------------------------------------
static const HotkeyInfo* const s_hotkey_list[] = {g_common_hotkeys, g_host_hotkeys};
// ------------------------------------------------------------------------
// Local Variables
// ------------------------------------------------------------------------
@@ -950,29 +946,15 @@ float InputManager::ApplySingleBindingScale(float scale, float deadzone, float v
return (deadzone > 0.0f && svalue < deadzone) ? 0.0f : svalue;
}
std::vector<const HotkeyInfo*> InputManager::GetHotkeyList()
{
std::vector<const HotkeyInfo*> ret;
for (const HotkeyInfo* hotkey_list : s_hotkey_list)
{
for (const HotkeyInfo* hotkey = hotkey_list; hotkey->name != nullptr; hotkey++)
ret.push_back(hotkey);
}
return ret;
}
void InputManager::AddHotkeyBindings(const SettingsInterface& si)
{
for (const HotkeyInfo* hotkey_list : s_hotkey_list)
for (const HotkeyInfo& hotkey : Core::GetHotkeyList())
{
for (const HotkeyInfo* hotkey = hotkey_list; hotkey->name != nullptr; hotkey++)
{
const std::vector<std::string> bindings(si.GetStringList("Hotkeys", hotkey->name));
if (bindings.empty())
continue;
const std::vector<std::string> bindings(si.GetStringList("Hotkeys", hotkey.name));
if (bindings.empty())
continue;
AddBindings(bindings, InputButtonEventHandler{hotkey->handler});
}
AddBindings(bindings, InputButtonEventHandler{hotkey.handler});
}
}
@@ -1721,9 +1703,8 @@ void InputManager::CopyConfiguration(SettingsInterface* dest_si, const SettingsI
if (copy_hotkey_bindings)
{
std::vector<const HotkeyInfo*> hotkeys(InputManager::GetHotkeyList());
for (const HotkeyInfo* hki : hotkeys)
dest_si->CopyStringListValue(src_si, "Hotkeys", hki->name);
for (const HotkeyInfo& hk : Core::GetHotkeyList())
dest_si->CopyStringListValue(src_si, "Hotkeys", hk.name);
}
}

View File

@@ -142,18 +142,6 @@ struct HotkeyInfo
const char* display_name;
void (*handler)(s32 pressed);
};
#define DECLARE_HOTKEY_LIST(name) extern const HotkeyInfo name[]
#define BEGIN_HOTKEY_LIST(name) const HotkeyInfo name[] = {
#define DEFINE_HOTKEY(name, category, display_name, handler) {(name), (category), (display_name), (handler)},
#define END_HOTKEY_LIST() \
{ \
nullptr, nullptr, nullptr, nullptr \
} \
} \
;
DECLARE_HOTKEY_LIST(g_common_hotkeys);
DECLARE_HOTKEY_LIST(g_host_hotkeys);
/// Generic input bindings. These roughly match a DualShock 4 or XBox One controller.
/// 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,
using BindingIconMappingFunction = std::string_view (*)(std::string_view);
bool PrettifyInputBinding(SmallStringBase& binding, BindingIconMappingFunction mapper = nullptr);
/// Returns a list of all hotkeys.
std::vector<const HotkeyInfo*> GetHotkeyList();
/// Enumerates available devices. Returns a pair of the prefix (e.g. SDL-0) and the device name.
using DeviceList = std::vector<std::tuple<InputBindingKey, std::string, std::string>>;
DeviceList EnumerateDevices();
@@ -414,9 +399,18 @@ void OnInputDeviceDisconnected(InputBindingKey key, std::string_view identifier)
/// Creates a force feedback device interface for the specified source and device.
std::unique_ptr<ForceFeedbackDevice> CreateForceFeedbackDevice(const std::string_view device, Error* error = nullptr);
} // namespace InputManager
namespace Core {
/// Returns a list of all hotkeys.
std::span<const HotkeyInfo> GetHotkeyList();
} // namespace Core
namespace Host {
/// Adds any fixed bindings from the host.
void AddFixedInputBindings(const SettingsInterface& si);
@@ -428,4 +422,5 @@ void OnInputDeviceDisconnected(InputBindingKey key, std::string_view identifier)
/// Enables "relative" mouse mode, locking the cursor position and returning relative coordinates.
void SetMouseMode(bool relative, bool hide_cursor);
} // namespace Host