diff --git a/include/SDL3/SDL_gamepad.h b/include/SDL3/SDL_gamepad.h index db87495dc2..6bc1662117 100644 --- a/include/SDL3/SDL_gamepad.h +++ b/include/SDL3/SDL_gamepad.h @@ -476,6 +476,20 @@ extern DECLSPEC SDL_Gamepad *SDLCALL SDL_GetGamepadFromInstanceID(SDL_JoystickID */ extern DECLSPEC SDL_Gamepad *SDLCALL SDL_GetGamepadFromPlayerIndex(int player_index); +/** + * Get the instance ID of an opened gamepad. + * + * \param gamepad a gamepad identifier previously returned by + * SDL_OpenGamepad() + * \returns the instance ID of the specified gamepad on success or 0 on + * failure; call SDL_GetError() for more information. + * + * \since This function is available since SDL 3.0.0. + * + * \sa SDL_OpenGamepad + */ +extern DECLSPEC SDL_JoystickID SDLCALL SDL_GetGamepadInstanceID(SDL_Gamepad *gamepad); + /** * Get the implementation-dependent name for an opened gamepad. * diff --git a/src/dynapi/SDL_dynapi.sym b/src/dynapi/SDL_dynapi.sym index 10a0a2f391..972de7d209 100644 --- a/src/dynapi/SDL_dynapi.sym +++ b/src/dynapi/SDL_dynapi.sym @@ -869,6 +869,7 @@ SDL3_0.0.0 { SDL_wcsstr; SDL_wcstol; SDL_ClearClipboardData; + SDL_GetGamepadInstanceID; # extra symbols go here (don't modify this line) local: *; }; diff --git a/src/dynapi/SDL_dynapi_overrides.h b/src/dynapi/SDL_dynapi_overrides.h index f4d14b66a1..3f95ba4cae 100644 --- a/src/dynapi/SDL_dynapi_overrides.h +++ b/src/dynapi/SDL_dynapi_overrides.h @@ -895,3 +895,4 @@ /* New API symbols are added at the end */ #define SDL_ClearClipboardData SDL_ClearClipboardData_REAL +#define SDL_GetGamepadInstanceID SDL_GetGamepadInstanceID_REAL diff --git a/src/dynapi/SDL_dynapi_procs.h b/src/dynapi/SDL_dynapi_procs.h index c5416f33cb..bbd5bec45a 100644 --- a/src/dynapi/SDL_dynapi_procs.h +++ b/src/dynapi/SDL_dynapi_procs.h @@ -940,3 +940,4 @@ SDL_DYNAPI_PROC(long,SDL_wcstol,(const wchar_t *a, wchar_t **b, int c),(a,b,c),r /* New API symbols are added at the end */ SDL_DYNAPI_PROC(int,SDL_ClearClipboardData,(void),(),return) +SDL_DYNAPI_PROC(SDL_JoystickID,SDL_GetGamepadInstanceID,(SDL_Gamepad *a),(a),return) diff --git a/src/joystick/SDL_gamepad.c b/src/joystick/SDL_gamepad.c index 3f4e7eed32..92af5c5867 100644 --- a/src/joystick/SDL_gamepad.c +++ b/src/joystick/SDL_gamepad.c @@ -2655,6 +2655,16 @@ int SDL_GetGamepadSensorData(SDL_Gamepad *gamepad, SDL_SensorType type, float *d return SDL_Unsupported(); } +SDL_JoystickID SDL_GetGamepadInstanceID(SDL_Gamepad *gamepad) +{ + SDL_Joystick *joystick = SDL_GetGamepadJoystick(gamepad); + + if (joystick == NULL) { + return 0; + } + return SDL_GetJoystickInstanceID(joystick); +} + const char *SDL_GetGamepadName(SDL_Gamepad *gamepad) { const char *retval = NULL;