Skip to content
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10 changes: 5 additions & 5 deletions src/joystick/SDL_gamecontroller.c
Original file line number Diff line number Diff line change
Expand Up @@ -1034,11 +1034,11 @@ static ControllerMapping_t *SDL_PrivateGetControllerMappingForNameAndGUID(const
}
#endif /* __LINUX__ */
#ifdef SDL_JOYSTICK_XBOX
if (!mapping) {
SDL_bool existing;
mapping = SDL_PrivateAddMappingForGUID(guid,
"default,Original Xbox Controller,a:b0,b:b1,back:b6,dpdown:h0.4,dpleft:h0.8,dpright:h0.2,dpup:h0.1,guide:b10,leftshoulder:b4,leftstick:b8,lefttrigger:a2,leftx:a0,lefty:a1,rightshoulder:b5,rightstick:b9,righttrigger:a5,rightx:a3,righty:a4,start:b7,x:b2,y:b3,",
&existing, SDL_CONTROLLER_MAPPING_PRIORITY_DEFAULT);
if (!mapping && SDL_IsJoystickXID(guid)
&& (guid.data[10] != 0x01 || (guid.data[11] != 0x01 && guid.data[11] != 0x02))) {
// This device is not an XID Gamepad Style Controller and thus should not use the default mapping
// You can define an explicit mapping for this device inside SDL_gamecontrollerdb.h
return NULL;
}
#endif /* SDL_JOYSTICK_XBOX */
if (!mapping && name) {
Expand Down
10 changes: 9 additions & 1 deletion src/joystick/SDL_gamecontrollerdb.h
Original file line number Diff line number Diff line change
Expand Up @@ -595,7 +595,15 @@ static const char *s_ControllerMappings [] =
#if defined(SDL_JOYSTICK_EMSCRIPTEN)
"default,Standard Gamepad,a:b0,b:b1,back:b8,dpdown:b13,dpleft:b14,dpright:b15,dpup:b12,guide:b16,leftshoulder:b4,leftstick:b10,lefttrigger:b6,leftx:a0,lefty:a1,rightshoulder:b5,rightstick:b11,righttrigger:b7,rightx:a2,righty:a3,start:b9,x:b2,y:b3,",
#endif
"hidapi,*,a:b0,b:b1,back:b4,dpdown:b12,dpleft:b13,dpright:b14,dpup:b11,guide:b5,leftshoulder:b9,leftstick:b7,lefttrigger:a4,leftx:a0,lefty:a1,rightshoulder:b10,rightstick:b8,righttrigger:a5,rightx:a2,righty:a3,start:b6,x:b2,y:b3,",
#if defined(SDL_JOYSTICK_XBOX)
// Compiled from https://xboxdevwiki.net/Xbox_Input_Devices
"default,Original Xbox Controller (Generic),a:b0,b:b1,back:b6,dpdown:h0.4,dpleft:h0.8,dpright:h0.2,dpup:h0.1,guide:b10,leftshoulder:b4,leftstick:b8,lefttrigger:a2,leftx:a0,lefty:a1,rightshoulder:b5,rightstick:b9,righttrigger:a5,rightx:a3,righty:a4,start:b7,x:b2,y:b3,",
"030000005e0400000202010100014200,Original Xbox Duke Controller,a:b0,b:b1,back:b6,dpdown:h0.4,dpleft:h0.8,dpright:h0.2,dpup:h0.1,guide:b10,leftshoulder:b4,leftstick:b8,lefttrigger:a2,leftx:a0,lefty:a1,rightshoulder:b5,rightstick:b9,righttrigger:a5,rightx:a3,righty:a4,start:b7,x:b2,y:b3,",
"030000005e0400008502010200014200,Original Xbox Controller-S (Japan),a:b0,b:b1,back:b6,dpdown:h0.4,dpleft:h0.8,dpright:h0.2,dpup:h0.1,guide:b10,leftshoulder:b4,leftstick:b8,lefttrigger:a2,leftx:a0,lefty:a1,rightshoulder:b5,rightstick:b9,righttrigger:a5,rightx:a3,righty:a4,start:b7,x:b2,y:b3,",
"030000005e0400008702010200014200,Original Xbox Controller-S (v1),a:b0,b:b1,back:b6,dpdown:h0.4,dpleft:h0.8,dpright:h0.2,dpup:h0.1,guide:b10,leftshoulder:b4,leftstick:b8,lefttrigger:a2,leftx:a0,lefty:a1,rightshoulder:b5,rightstick:b9,righttrigger:a5,rightx:a3,righty:a4,start:b7,x:b2,y:b3,",
"030000005e0400008902010200014200,Original Xbox Controller-S (v2),a:b0,b:b1,back:b6,dpdown:h0.4,dpleft:h0.8,dpright:h0.2,dpup:h0.1,guide:b10,leftshoulder:b4,leftstick:b8,lefttrigger:a2,leftx:a0,lefty:a1,rightshoulder:b5,rightstick:b9,righttrigger:a5,rightx:a3,righty:a4,start:b7,x:b2,y:b3,",
#endif
"hidapi,*,a:b0,b:b1,back:b4,dpdown:b12,dpleft:b13,dpright:b14,dpup:b11,guide:b5,leftshoulder:b9,leftstick:b7,lefttrigger:a4,leftx:a0,lefty:a1,rightshoulder:b10,rightstick:b8,righttrigger:a5,rightx:a2,righty:a3,start:b6,x:b2,y:b3,",
NULL
};

Expand Down
34 changes: 32 additions & 2 deletions src/joystick/SDL_joystick.c
Original file line number Diff line number Diff line change
Expand Up @@ -1132,14 +1132,15 @@ void SDL_GetJoystickGUIDInfo(SDL_JoystickGUID guid, Uint16 *vendor, Uint16 *prod
Uint16 *guid16 = (Uint16 *)guid.data;

/* If the GUID fits the form of BUS 0000 VENDOR 0000 PRODUCT 0000, return the data */
if (/* guid16[0] is device bus type */
if (SDL_IsJoystickXID(guid) || (
/* guid16[0] is device bus type */
guid16[1] == 0x0000 &&
/* guid16[2] is vendor ID */
guid16[3] == 0x0000 &&
/* guid16[4] is product ID */
guid16[5] == 0x0000
/* guid16[6] is product version */
) {
)) {
if (vendor) {
*vendor = guid16[2];
}
Expand Down Expand Up @@ -1217,6 +1218,13 @@ SDL_IsJoystickHIDAPI(SDL_JoystickGUID guid)
return (guid.data[14] == 'h') ? SDL_TRUE : SDL_FALSE;
}

SDL_bool
SDL_IsJoystickXID(SDL_JoystickGUID guid)
{
// For XID devices guid.data[14] contains XID_DESC.bDescriptorType which is always 0x42
return (guid.data[14] == 0x42) ? SDL_TRUE : SDL_FALSE;
}

static SDL_bool SDL_IsJoystickProductWheel(Uint32 vidpid)
{
static Uint32 wheel_joysticks[] = {
Expand Down Expand Up @@ -1281,6 +1289,28 @@ static SDL_JoystickType SDL_GetJoystickGUIDType(SDL_JoystickGUID guid)
Uint16 vendor;
Uint16 product;
Uint32 vidpid;

https://xboxdevwiki.net/Xbox_Input_Devices#bType_.3D_1:_Xbox_Gamecontroller
if (SDL_IsJoystickXID(guid)) {
if (guid.data[10] != 0x01) { // XID_DESC.bType
// Non Game-Controller device
return SDL_JOYSTICK_TYPE_UNKNOWN;
}

switch (guid.data[11]) { // XID_DESC.bSubType
case 0x01: // Duke
case 0x02: // S-Controller
return SDL_JOYSTICK_TYPE_GAMECONTROLLER;
case 0x10: // Steering Wheel
return SDL_JOYSTICK_TYPE_WHEEL;
case 0x20: // Arcade Stick
return SDL_JOYSTICK_TYPE_ARCADE_STICK;
case 0x50: // Light Gun
return SDL_JOYSTICK_TYPE_UNKNOWN;
default:
return SDL_JOYSTICK_TYPE_UNKNOWN;
}
}

if (SDL_IsJoystickXInput(guid)) {
/* XInput GUID, get the type based on the XInput device subtype */
Expand Down
3 changes: 3 additions & 0 deletions src/joystick/SDL_joystick_c.h
Original file line number Diff line number Diff line change
Expand Up @@ -75,6 +75,9 @@ extern SDL_bool SDL_IsJoystickXInput(SDL_JoystickGUID guid);
/* Function to return whether a joystick guid comes from the HIDAPI driver */
extern SDL_bool SDL_IsJoystickHIDAPI(SDL_JoystickGUID guid);

/* Function to return whether a joystick guid comes from the XBOX XID driver */
extern SDL_bool SDL_IsJoystickXID(SDL_JoystickGUID guid);

/* Function to return whether a joystick should be ignored */
extern SDL_bool SDL_ShouldIgnoreJoystick(const char *name, SDL_JoystickGUID guid);

Expand Down
Loading