Added SDL_JoystickGetXInputUserIndex()

This commit is contained in:
Sam Lantinga 2018-10-25 12:54:42 -07:00
parent 4d4e18c4bb
commit 9987ca69f3
6 changed files with 18 additions and 0 deletions

View File

@ -384,6 +384,11 @@ extern DECLSPEC void SDLCALL SDL_JoystickClose(SDL_Joystick * joystick);
*/
extern DECLSPEC SDL_JoystickPowerLevel SDLCALL SDL_JoystickCurrentPowerLevel(SDL_Joystick * joystick);
/**
* Return the XInput user index for this joystick, or -1 if it's not available
*/
extern DECLSPEC int SDLCALL SDL_JoystickGetXInputUserIndex(SDL_Joystick * joystick);
/* Ends C function definitions when using C++ */
#ifdef __cplusplus
}

View File

@ -698,3 +698,4 @@
#define SDL_GetDisplayOrientation SDL_GetDisplayOrientation_REAL
#define SDL_HasColorKey SDL_HasColorKey_REAL
#define SDL_CreateThreadWithStackSize SDL_CreateThreadWithStackSize_REAL
#define SDL_JoystickGetXInputUserIndex SDL_JoystickGetXInputUserIndex_REAL

View File

@ -752,3 +752,4 @@ SDL_DYNAPI_PROC(SDL_Thread*,SDL_CreateThreadWithStackSize,(SDL_ThreadFunction a,
SDL_DYNAPI_PROC(SDL_Thread*,SDL_CreateThreadWithStackSize,(SDL_ThreadFunction a, const char *b, const size_t c, void *d),(a,b,c,d),return)
#endif
SDL_DYNAPI_PROC(int,SDL_JoystickGetXInputUserIndex,(SDL_Joystick *a),(a),return)

View File

@ -322,6 +322,7 @@ SDL_JoystickOpen(int device_index)
}
joystick->guid = driver->GetDeviceGUID(device_index);
joystick->userid = -1;
if (joystick->naxes > 0) {
joystick->axes = (SDL_JoystickAxisInfo *) SDL_calloc(joystick->naxes, sizeof(SDL_JoystickAxisInfo));
@ -1556,4 +1557,12 @@ SDL_JoystickPowerLevel SDL_JoystickCurrentPowerLevel(SDL_Joystick * joystick)
return joystick->epowerlevel;
}
int SDL_JoystickGetXInputUserIndex(SDL_Joystick * joystick)
{
if (!SDL_PrivateJoystickValid(joystick)) {
return -1;
}
return joystick->userid;
}
/* vi: set ts=4 sw=4 expandtab: */

View File

@ -43,6 +43,7 @@ struct _SDL_Joystick
SDL_JoystickID instance_id; /* Device instance, monotonically increasing from 0 */
char *name; /* Joystick name - system dependent */
SDL_JoystickGUID guid; /* Joystick guid */
int userid; /* XInput user index, if any */
int naxes; /* Number of axis controls on the joystick */
SDL_JoystickAxisInfo *axes;

View File

@ -322,6 +322,7 @@ SDL_XINPUT_JoystickOpen(SDL_Joystick * joystick, JoyStick_DeviceData *joystickde
SDL_zero(state);
joystick->hwdata->bXInputHaptic = (XINPUTSETSTATE(userId, &state) == ERROR_SUCCESS);
joystick->hwdata->userid = userId;
joystick->userid = userId;
/* The XInput API has a hard coded button/axis mapping, so we just match it */
if (SDL_XInputUseOldJoystickMapping()) {