From 7b5610f5727f36d770c2f03adefd039905acbb26 Mon Sep 17 00:00:00 2001 From: Daniele Bartolini Date: Fri, 6 Mar 2026 01:24:55 +0100 Subject: [PATCH] device: linux: fix DPAD --- docs/changelog.rst | 1 + src/device/main_linux.cpp | 64 +++++++++++++++++++++++++++------------ 2 files changed, 45 insertions(+), 20 deletions(-) diff --git a/docs/changelog.rst b/docs/changelog.rst index 5213643d7..39dd60ab3 100644 --- a/docs/changelog.rst +++ b/docs/changelog.rst @@ -19,6 +19,7 @@ Changelog * Runtime: added missing keyboard punctuation and special keys on HTML5, Linux and Windows platforms. * Runtime: fixed a crash in the Graph subsystem. * Runtime: fixed ``smoothed`` timestep policy not honoring average_cap during the very first frames. +* Runtime: Linux: fixed joypad D-pad. * Data Compiler: fixed an issue that caused misdetected file changes before compilation. .. _v0.61.0: diff --git a/src/device/main_linux.cpp b/src/device/main_linux.cpp index d7af8efa6..ca10e2c70 100644 --- a/src/device/main_linux.cpp +++ b/src/device/main_linux.cpp @@ -423,29 +423,53 @@ struct Joypad JoypadAxis::TRIGGER_RIGHT }; - // Remap triggers to [0, INT16_MAX] - s16 value = ev.value; - if (ev.number == 2 || ev.number == 5) - value = (ev.value + INT16_MAX) >> 1; - - s16 *values = ev.number > 2 ? _axis[joypad_id].right : _axis[joypad_id].left; - values[axis_idx[ev.number]] = value; - - if (ev.number == 2 || ev.number == 5) { - _queue->push_axis_event(InputDeviceType::JOYPAD + if (ev.number < countof(axis_map)) { + // Remap triggers to [0, INT16_MAX]. + s16 value = ev.value; + if (ev.number == 2 || ev.number == 5) + value = (ev.value + INT16_MAX) >> 1; + + s16 *values = ev.number > 2 ? _axis[joypad_id].right : _axis[joypad_id].left; + values[axis_idx[ev.number]] = value; + + if (ev.number == 2 || ev.number == 5) { + _queue->push_axis_event(InputDeviceType::JOYPAD + , joypad_id + , axis_map[ev.number] + , 0 + , 0 + , values[2] + ); + } else { + _queue->push_axis_event(InputDeviceType::JOYPAD + , joypad_id + , axis_map[ev.number] + , values[0] + , -values[1] + , 0 + ); + } + } else if (ev.number == 6) { // DPAD X axis. + _queue->push_button_event(InputDeviceType::JOYPAD , joypad_id - , axis_map[ev.number] - , 0 - , 0 - , values[2] + , JoypadButton::LEFT + , ev.value < 0 ); - } else if (ev.number < countof(axis_map)) { - _queue->push_axis_event(InputDeviceType::JOYPAD + _queue->push_button_event(InputDeviceType::JOYPAD , joypad_id - , axis_map[ev.number] - , values[0] - , -values[1] - , 0 + , JoypadButton::RIGHT + , ev.value > 0 + ); + } else if (ev.number == 7) { // DPAD Y axis. + _queue->push_button_event(InputDeviceType::JOYPAD + , joypad_id + , JoypadButton::UP + , ev.value < 0 + ); + _queue->push_button_event(InputDeviceType::JOYPAD + , joypad_id + , JoypadButton::DOWN + , ev.value > 0 ); } break;