From a51fc5a1492f1b9e3b360518a2b5690c18a25607 Mon Sep 17 00:00:00 2001 From: Connor McLaughlin Date: Sat, 3 Jul 2021 15:04:02 +1000 Subject: [PATCH] XInputControllerInterface: Support half axis bindings --- .../xinput_controller_interface.cpp | 24 ++++++++++++------- 1 file changed, 15 insertions(+), 9 deletions(-) diff --git a/src/frontend-common/xinput_controller_interface.cpp b/src/frontend-common/xinput_controller_interface.cpp index 9b6c80a54..aa4059246 100644 --- a/src/frontend-common/xinput_controller_interface.cpp +++ b/src/frontend-common/xinput_controller_interface.cpp @@ -237,17 +237,23 @@ bool XInputControllerInterface::HandleAxisEvent(u32 index, Axis axis, s32 value) const AxisCallback& cb = m_controllers[index].axis_mapping[static_cast(axis)][AxisSide::Full]; if (cb) { - // Extend triggers from a 0 - 1 range to a -1 - 1 range for consistency with other inputs - if (axis == Axis::LeftTrigger || axis == Axis::RightTrigger) - { - cb((f_value * 2.0f) - 1.0f); - } - else - { - cb(f_value); - } + cb(f_value); return true; } + else + { + const AxisCallback& positive_cb = m_controllers[index].axis_mapping[static_cast(axis)][AxisSide::Positive]; + const AxisCallback& negative_cb = m_controllers[index].axis_mapping[static_cast(axis)][AxisSide::Negative]; + if (positive_cb || negative_cb) + { + if (positive_cb) + positive_cb((f_value < 0.0f) ? 0.0f : f_value); + if (negative_cb) + negative_cb((f_value >= 0.0f) ? 0.0f : -f_value); + + return true; + } + } // set the other direction to false so large movements don't leave the opposite on const bool outside_deadzone = (std::abs(f_value) >= m_controllers[index].deadzone);