diff --git a/src/frontend-common/common_host_interface.cpp b/src/frontend-common/common_host_interface.cpp index 0923db00b..c55d1662e 100644 --- a/src/frontend-common/common_host_interface.cpp +++ b/src/frontend-common/common_host_interface.cpp @@ -424,9 +424,20 @@ bool CommonHostInterface::HandleHostKeyEvent(HostKeyCode key, bool pressed) return true; } +bool CommonHostInterface::HandleHostMouseEvent(HostMouseButton button, bool pressed) +{ + const auto iter = m_mouse_input_handlers.find(button); + if (iter == m_mouse_input_handlers.end()) + return false; + + iter->second(pressed); + return true; +} + void CommonHostInterface::UpdateInputMap(SettingsInterface& si) { m_keyboard_input_handlers.clear(); + m_mouse_input_handlers.clear(); if (m_controller_interface) m_controller_interface->ClearBindings(); @@ -601,6 +612,25 @@ bool CommonHostInterface::AddButtonToInputMap(const std::string& binding, const return true; } + if (device == "Mouse") + { + if (StringUtil::StartsWith(button, "Button")) + { + const std::optional button_index = StringUtil::FromChars(button.substr(6)); + if (!button_index.has_value()) + { + Log_WarningPrintf("Invalid button in mouse binding '%s'", binding.c_str()); + return false; + } + + m_mouse_input_handlers.emplace(static_cast(button_index.value()), std::move(handler)); + return true; + } + + Log_WarningPrintf("Malformed mouse binding '%s'", binding.c_str()); + return false; + } + if (StringUtil::StartsWith(device, "Controller")) { if (!m_controller_interface) diff --git a/src/frontend-common/common_host_interface.h b/src/frontend-common/common_host_interface.h index 4ff21b943..1d72d5f4d 100644 --- a/src/frontend-common/common_host_interface.h +++ b/src/frontend-common/common_host_interface.h @@ -23,6 +23,7 @@ public: friend ControllerInterface; using HostKeyCode = s32; + using HostMouseButton = s32; using InputButtonHandler = std::function; using InputAxisHandler = std::function; @@ -102,6 +103,7 @@ protected: void RegisterHotkey(String category, String name, String display_name, InputButtonHandler handler); bool HandleHostKeyEvent(HostKeyCode code, bool pressed); + bool HandleHostMouseEvent(HostMouseButton button, bool pressed); void UpdateInputMap(SettingsInterface& si); void AddControllerRumble(u32 controller_index, u32 num_motors, ControllerRumbleCallback callback); @@ -124,6 +126,7 @@ private: // input key maps std::map m_keyboard_input_handlers; + std::map m_mouse_input_handlers; // controller vibration motors/rumble struct ControllerRumbleState