Skip to content

Basic Linux gamepad support#25

Merged
Atrix256 merged 1 commit intoAtrix256:mainfrom
BabakSamimi:LinuxGamepad
Mar 29, 2026
Merged

Basic Linux gamepad support#25
Atrix256 merged 1 commit intoAtrix256:mainfrom
BabakSamimi:LinuxGamepad

Conversation

@BabakSamimi
Copy link
Copy Markdown
Contributor

@BabakSamimi BabakSamimi commented Mar 25, 2026

This PR implements very basic gamepad support for Linux by using libudev and evdev. Just like the X11 and OpenGL implementation, the code dynamically loads libudev, given that they have the library on the system, which all systemd-based distributions should have, as far as I understand. If they don't then the application will run without gamepad support and without notifying the user of missing libudev.

The controllers that support BTN_GAMEPAD should work out of the box, given that they follow the Linux Gamepad specificiation. So far, a PS3 controller and a PS5 controller worked.

What is not handled:

  • When reading event packets from a gamepad, SYN_DROPPED will be sent to us whenever there is a "buffer overrun in the evdev client’s event queue". Not 100% sure how you handle this.
  • The values used for normalization of sticks/triggers could be zero, which is problematic since we don't handle divide by zero. Furthermore, according to this post, the kernel might not clip current values to the reported min/max of the sticks/triggers.

What is not tested:

  • Plugging in 4 or more controllers.
  • Controllers besides PS3 and PS5.

I would recommend that the above gets tested before a merge.

The controller example was also changed to run through all four controllers instead of only the first one.

@Atrix256 Atrix256 merged commit 4f817f0 into Atrix256:main Mar 29, 2026
20 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants