We are currently migrating Bugzilla to GitHub issues.
Any changes made to the bug tracker now will be lost, so please do not post new bugs or make changes to them.
When we're done, all bug URLs will redirect to their equivalent location on the new bug tracker.

Bug 1975

Summary: [Patch] add SDL_JoystickIsGameController and SDL_GameControllerOpenFromJoystick
Product: SDL Reporter: Alex Szpakowski <amaranth72>
Component: joystickAssignee: Sam Lantinga <slouken>
Status: ASSIGNED --- QA Contact: Sam Lantinga <slouken>
Severity: enhancement    
Priority: P2 CC: alfred, philipp.wiesemann
Version: HG 2.0   
Hardware: All   
OS: All   
Attachments: Patch to add SDL_JoystickIsGameController and SDL_GameControllerOpenFromJoystick

Description Alex Szpakowski 2013-07-15 21:05:26 UTC
Created attachment 1237 [details]
Patch to add SDL_JoystickIsGameController and SDL_GameControllerOpenFromJoystick

It is sometimes the case that a developer will want to open a GameController from a particular Joystick when some time has passed since the original Joystick has been opened, for example if SDL_GameControllerAddMapping is called while existing Joysticks are connected.
There is currently no SDL function (aside from the SDL_JOYDEVICEADDED event) to facilitate this, and there is also no API to know whether a Joystick object can be opened as a GameController unless the Joystick's device index (which can change and is not retrievable with an SDL function) is also known.

I have attached a patch to add SDL_JoystickIsGameController(SDL_Joystick*) and SDL_GameControllerOpenFromJoystick(SDL_Joystick*). I've tested it in OS X and Windows with an xbox controller and it works as expected. Most of the code is based on SDL_GameControllerOpen and SDL_IsGameController.

I chose the name SDL_JoystickIsGameController to be consistent with SDL_IsGameController and SDL_JoystickIsHaptic, and I chose the name SDL_GameControllerOpenFromJoystick to be consistent with SDL_GameControllerOpen and SDL_HapticOpenFromJoystick.
Comment 1 Philipp Wiesemann 2013-07-27 11:11:34 UTC
(In reply to comment #0)
> Created attachment 1237 [details]
> Patch to add SDL_JoystickIsGameController and
> SDL_GameControllerOpenFromJoystick

Minor documentation problem in patch: s/suppported/supported/
Comment 2 Sam Lantinga 2013-07-28 14:29:25 UTC
Thanks, we'll keep this for review after the SDL 2.0 release.
Comment 3 Alfred Reynolds 2013-07-29 13:10:37 UTC
Looks good.

I would consider renaming SDL_JoystickIsGameController() to SDL_GameControllerIsJoystickSupported() , just to follow the pattern of the prefix of game controller functions.

I'm also not a fan of reaching into the private guts of sdl joystick for the SDL_PrivateJoystickValid function, but haptic's already does the same thing.
Comment 4 Ryan C. Gordon 2015-02-19 05:22:17 UTC
Marking a large number of bugs with the "triage-2.0.4" keyword at once. Sorry if you got a lot of email from this. This is to help me sort through some bugs in regards to a 2.0.4 release. We may or may not fix this bug for 2.0.4, though!
Comment 5 Ryan C. Gordon 2015-04-07 04:57:58 UTC
(sorry if you get a lot of copies of this email, I'm marking several bugs at once)

Marking bugs for the (mostly) final 2.0.4 TODO list. This means we're hoping to resolve this bug before 2.0.4 ships if possible. In a perfect world, the open bug count with the target-2.0.4 keyword is zero when we ship.

(Note that closing a bug report as WONTFIX, INVALID or WORKSFORME might still happen.)

--ryan.
Comment 6 Sam Lantinga 2015-05-28 20:02:06 UTC
This is a good change, but I want to think it through a little bit more and so will look at it again after 2.0.4 ships.