mirror of
https://github.com/dolphin-emu/dolphin.git
synced 2025-05-06 11:12:40 +00:00
InputCommon: Make hotkeys and input detection aware of Ctrl -> L_Ctrl / R_Ctrl hierarchy.
This commit is contained in:
parent
aae913fbc6
commit
d8ad8c3861
4 changed files with 65 additions and 44 deletions
|
@ -21,6 +21,38 @@ namespace ciface::Core
|
|||
// Note: Detect() logic assumes this is greater than 0.5.
|
||||
constexpr ControlState INPUT_DETECT_THRESHOLD = 0.55;
|
||||
|
||||
class CombinedInput final : public Device::Input
|
||||
{
|
||||
public:
|
||||
using Inputs = std::pair<Device::Input*, Device::Input*>;
|
||||
|
||||
CombinedInput(std::string name, const Inputs& inputs) : m_name(std::move(name)), m_inputs(inputs)
|
||||
{
|
||||
}
|
||||
ControlState GetState() const override
|
||||
{
|
||||
ControlState result = 0;
|
||||
|
||||
if (m_inputs.first)
|
||||
result = m_inputs.first->GetState();
|
||||
|
||||
if (m_inputs.second)
|
||||
result = std::max(result, m_inputs.second->GetState());
|
||||
|
||||
return result;
|
||||
}
|
||||
std::string GetName() const override { return m_name; }
|
||||
bool IsDetectable() const override { return false; }
|
||||
bool IsChild(const Input* input) const override
|
||||
{
|
||||
return m_inputs.first == input || m_inputs.second == input;
|
||||
}
|
||||
|
||||
private:
|
||||
const std::string m_name;
|
||||
const std::pair<Device::Input*, Device::Input*> m_inputs;
|
||||
};
|
||||
|
||||
Device::~Device()
|
||||
{
|
||||
// delete inputs
|
||||
|
@ -52,6 +84,20 @@ std::string Device::GetQualifiedName() const
|
|||
return fmt::format("{}/{}/{}", GetSource(), GetId(), GetName());
|
||||
}
|
||||
|
||||
auto Device::GetParentMostInput(Input* child) const -> Input*
|
||||
{
|
||||
for (auto* input : m_inputs)
|
||||
{
|
||||
if (input->IsChild(child))
|
||||
{
|
||||
// Running recursively is currently unnecessary but it doesn't hurt.
|
||||
return GetParentMostInput(input);
|
||||
}
|
||||
}
|
||||
|
||||
return child;
|
||||
}
|
||||
|
||||
Device::Input* Device::FindInput(std::string_view name) const
|
||||
{
|
||||
for (Input* input : m_inputs)
|
||||
|
@ -103,34 +149,6 @@ bool Device::FullAnalogSurface::IsMatchingName(std::string_view name) const
|
|||
return old_name == name;
|
||||
}
|
||||
|
||||
Device::CombinedInput::CombinedInput(std::string name, const Inputs& inputs)
|
||||
: m_name(std::move(name)), m_inputs(inputs)
|
||||
{
|
||||
}
|
||||
|
||||
ControlState Device::CombinedInput::GetState() const
|
||||
{
|
||||
ControlState result = 0;
|
||||
|
||||
if (m_inputs.first)
|
||||
result = m_inputs.first->GetState();
|
||||
|
||||
if (m_inputs.second)
|
||||
result = std::max(result, m_inputs.second->GetState());
|
||||
|
||||
return result;
|
||||
}
|
||||
|
||||
std::string Device::CombinedInput::GetName() const
|
||||
{
|
||||
return m_name;
|
||||
}
|
||||
|
||||
bool Device::CombinedInput::IsDetectable()
|
||||
{
|
||||
return false;
|
||||
}
|
||||
|
||||
void Device::AddCombinedInput(std::string name, const std::pair<std::string, std::string>& inputs)
|
||||
{
|
||||
AddInput(new CombinedInput(std::move(name), {FindInput(inputs.first), FindInput(inputs.second)}));
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue