Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

sdl2::Event::ControllerDeviceAdded could be made friendlier #713

Closed
ticky opened this issue Oct 9, 2017 · 0 comments · Fixed by #714
Closed

sdl2::Event::ControllerDeviceAdded could be made friendlier #713

ticky opened this issue Oct 9, 2017 · 0 comments · Fixed by #714

Comments

@ticky
Copy link
Contributor

ticky commented Oct 9, 2017

After a long time trying to figure this out, I’ve discovered that SDL2 is using a signed integer for its joystick IDs so it can be both compared to, and used as an error code by SDL_NumJoysticks.

This means that all ControllerDevice events return which as an sint32, while only ControllerDeviceAdded actually intends to be used as a signed integer. Meanwhile, the ControllerAxis and ControllerButton events use the SDL_JoystickID, which is a uint underneath.

Given that the intent is for the “which” returned by ControllerDeviceAdded to be used in SDL_GameControllerOpen (as it is impossible to use it without first opening it!), it currently has an incompatible type with sdl::GameControllerSubsystem#open, where we’re accepting only a u32.

Given that rust-sdl2 converts other SDL2 errors to native Rust errors, and sdl2::GameControllerSubsystem#num_joysticks already does, I'd propose that ControllerDeviceAdded events be updated to supply which as a u32, so it can be used directly with open without requiring a confusing type conversion!

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 a pull request may close this issue.

1 participant