Skip to content
CppCooperProgramming Portfolio

Article

Mapping Linux Joystick Events in Gainput

ArchitectureGames

A joystick event number is not enough to tell an input library which control moved. On Linux, the event’s slot needs to be interpreted through the device’s axis and button maps. This small Gainput fork changes that translation for controllers that do not have a recognized dialect, and tightens what happens when a device disappears.

Translate the slot before assigning the control

The Linux pad path maps event slots through kernel button and axis codes, then translates supported codes into Gainput controls. Unsupported controls are ignored. This gives the fallback a concrete mapping route instead of assuming that a particular slot has the same meaning on every unknown controller.

The distinction is between the device’s event numbering and the application’s input vocabulary. A library can expose one set of gamepad controls while still needing device-specific information to interpret the events arriving underneath it. This change addresses that boundary; Gainput’s broader input API and controller support remain inherited library work.

A disconnect must clear the old state

Losing the descriptor also means losing the source of future release events. The changed path clears held input state, closes the lost descriptor, and then allows reconnection. Otherwise the application can retain a button or axis value from a device that is no longer producing events.

Keep the HID experiment separate

The default cheryl-main branch contains the joystick mapping work. A separate commit on cheryl-linux-joystick-mapping changes HID enumeration and tracker cleanup, failed-open/read handling, and notification lifetime. The inherited Sony HID parsers predate these changes. Normal HID-to-pad bridging and adaptive-trigger work remain unfinished.

The default branch built on Linux with HID disabled, and its existing suite passed 408 assertions in 17 cases. That check covers the selected library configuration. Physical devices, the separate HID branch, haptics, USB/Bluetooth behavior, and Cheryl’s consumer integration were not exercised by that run. The mapping change and the hardware acceptance work therefore retain separate evidence.