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

[Patch] add SDL_JoystickIsGameController and SDL_GameControllerOpenFromJoystick #971

Closed
SDLBugzilla opened this issue Feb 10, 2021 · 3 comments
Assignees
Labels
enhancement New feature or request

Comments

@SDLBugzilla
Copy link
Collaborator

This bug report was migrated from our old Bugzilla tracker.

These attachments are available in the static archive:

Reported in version: HG 2.0
Reported for operating system, platform: All, All

Comments on the original bug report:

On 2013-07-15 21:05:26 +0000, Alex Szpakowski wrote:

Created attachment 1237
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.

On 2013-07-27 11:11:34 +0000, Philipp Wiesemann wrote:

(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/

On 2013-07-28 14:29:25 +0000, Sam Lantinga wrote:

Thanks, we'll keep this for review after the SDL 2.0 release.

On 2013-07-29 13:10:37 +0000, Alfred Reynolds wrote:

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.

On 2015-02-19 05:22:17 +0000, Ryan C. Gordon wrote:

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!

On 2015-04-07 04:57:58 +0000, Ryan C. Gordon wrote:

(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.

On 2015-05-28 20:02:06 +0000, Sam Lantinga wrote:

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.

@SDLBugzilla SDLBugzilla added the enhancement New feature or request label Feb 10, 2021
@icculus icculus added this to the 2.0.18 milestone Aug 10, 2021
@slouken
Copy link
Collaborator

slouken commented Nov 7, 2021

Is this still useful?
If so, we probably want to implement those functions in terms of SDL_JoystickGetDeviceIndexFromInstanceID() or maybe even just expose that function so applications can map between open joysticks and the indexed joystick list.

@slouken slouken removed this from the 2.0.18 milestone Nov 7, 2021
@ericoporto
Copy link
Contributor

SDL_JoystickGetDeviceIndexFromInstanceID would be useful for someone who is managing references in a scripting object oriented language and making a glue to SDL in the backend.

@slouken
Copy link
Collaborator

slouken commented Nov 4, 2023

This is a one liner in SDL3:

gamepad = SDL_OpenGamepad(SDL_GetJoystickInstanceID(joystick));

@slouken slouken closed this as not planned Won't fix, can't repro, duplicate, stale Nov 4, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request
Projects
None yet
Development

No branches or pull requests

4 participants