But you can also manually enumerate devices as in the example here: http://wiki.libsdl.org/SDL_GameControllerOpen
https://docs.microsoft.com/en-us/windows/win32/xinput/gettin...
In general, "notifying the program when a new device has become available" seems to be a surprisingly difficult problem. I've encountered trouble with multiple device types across multiple platforms.
It seems like Papers, Please uses a statically linked version of SDL, without udev or inotify support compiled in.
1: https://github.com/libsdl-org/SDL/blob/d0de4c625ad26ef540166...
Edit: though here if it's a problem of file enumeration and access, I'd probably just LD_PRELOAD something to bypass libc file access functions and return the same result than the first time, with no delay.
SDL does have a built-in way to do that trick. A quick web search tells me it's called SDL_DYNAMIC_API.
But even if it wants to do this, why is it doing it on the main thread!? :(
I would imagine that’s what’s done if you’re running udev but maybe SDL doesn’t do that.
Let's say you have /dev/input/event{0,10}, event5 is a USB keyboard, you unplug it, I assume event5 goes away.
But then you plug in a controller, does this get mapped to event11, or does event5 get reused? Is the behaviour reliable in all versions of linux?
You might argue that metadata should do the trick, but in my experience, on device files, anything beyond read/write is a crapshoot, whether metadata makes any sense is basically a roll of the dice.
So if you have to open device files in order to check their identity, you might as well skip the identity bit and just check if you're a gamepad.
edit: per charcircuit's comment below, it looks like the metadata of /dev/input at least are considered reliable, and this was used to mitigate the issue by checking the mtime of /dev/input itself against a stored timestamp: https://github.com/spurious/SDL-mirror/commit/59728f9802c786...
Opening the same file multiple times will yield different fds, and the paths can be modified independently of the fd.
The goal here is to find if:
1. there are new input devices
2. which are joysticks (a category which, for SDL, includes gamepads, so basically "has the user plugged in a new gamepad they might want to use for the game")
How would keeping a bunch of fds around help?