Skip to content

Commit

Permalink
Added SDL_JoystickGetXInputUserIndex()
Browse files Browse the repository at this point in the history
  • Loading branch information
slouken committed Oct 25, 2018
1 parent 4d4e18c commit 9987ca6
Show file tree
Hide file tree
Showing 6 changed files with 18 additions and 0 deletions.
5 changes: 5 additions & 0 deletions include/SDL_joystick.h
Expand Up @@ -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
}
Expand Down
1 change: 1 addition & 0 deletions src/dynapi/SDL_dynapi_overrides.h
Expand Up @@ -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
1 change: 1 addition & 0 deletions src/dynapi/SDL_dynapi_procs.h
Expand Up @@ -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)
9 changes: 9 additions & 0 deletions src/joystick/SDL_joystick.c
Expand Up @@ -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));
Expand Down Expand Up @@ -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: */
1 change: 1 addition & 0 deletions src/joystick/SDL_sysjoystick.h
Expand Up @@ -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;
Expand Down
1 change: 1 addition & 0 deletions src/joystick/windows/SDL_xinputjoystick.c
Expand Up @@ -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()) {
Expand Down

0 comments on commit 9987ca6

Please sign in to comment.