SDL  2.0
controller_type.h File Reference
+ This graph shows which files directly or indirectly include this file:

Go to the source code of this file.

Data Structures

struct  ControllerDescription_t
 

Macros

#define MAKE_CONTROLLER_ID(nVID, nPID)   (unsigned int)( (unsigned int)nVID << 16 | (unsigned int)nPID )
 

Enumerations

enum  EControllerType {
  k_eControllerType_None = -1,
  k_eControllerType_Unknown = 0,
  k_eControllerType_UnknownSteamController = 1,
  k_eControllerType_SteamController = 2,
  k_eControllerType_SteamControllerV2 = 3,
  k_eControllerType_UnknownNonSteamController = 30,
  k_eControllerType_XBox360Controller = 31,
  k_eControllerType_XBoxOneController = 32,
  k_eControllerType_PS3Controller = 33,
  k_eControllerType_PS4Controller = 34,
  k_eControllerType_WiiController = 35,
  k_eControllerType_AppleController = 36,
  k_eControllerType_AndroidController = 37,
  k_eControllerType_SwitchProController = 38,
  k_eControllerType_SwitchJoyConLeft = 39,
  k_eControllerType_SwitchJoyConRight = 40,
  k_eControllerType_SwitchJoyConPair = 41,
  k_eControllerType_SwitchInputOnlyController = 42,
  k_eControllerType_MobileTouch = 43,
  k_eControllerType_XInputSwitchController = 44,
  k_eControllerType_LastController,
  k_eControllertype_GenericKeyboard = 400,
  k_eControllertype_GenericMouse = 800
}
 

Functions

static SDL_INLINE const char * GetControllerTypeOverride (int nVID, int nPID)
 
static SDL_INLINE EControllerType GuessControllerType (int nVID, int nPID)
 
static SDL_INLINE const char * GuessControllerName (int nVID, int nPID)
 

Variables

static const ControllerDescription_t arrControllers []
 

Macro Definition Documentation

◆ MAKE_CONTROLLER_ID

#define MAKE_CONTROLLER_ID (   nVID,
  nPID 
)    (unsigned int)( (unsigned int)nVID << 16 | (unsigned int)nPID )

Definition at line 65 of file controller_type.h.

Enumeration Type Documentation

◆ EControllerType

Enumerator
k_eControllerType_None 
k_eControllerType_Unknown 
k_eControllerType_UnknownSteamController 
k_eControllerType_SteamController 
k_eControllerType_SteamControllerV2 
k_eControllerType_UnknownNonSteamController 
k_eControllerType_XBox360Controller 
k_eControllerType_XBoxOneController 
k_eControllerType_PS3Controller 
k_eControllerType_PS4Controller 
k_eControllerType_WiiController 
k_eControllerType_AppleController 
k_eControllerType_AndroidController 
k_eControllerType_SwitchProController 
k_eControllerType_SwitchJoyConLeft 
k_eControllerType_SwitchJoyConRight 
k_eControllerType_SwitchJoyConPair 
k_eControllerType_SwitchInputOnlyController 
k_eControllerType_MobileTouch 
k_eControllerType_XInputSwitchController 
k_eControllerType_LastController 
k_eControllertype_GenericKeyboard 
k_eControllertype_GenericMouse 

Definition at line 31 of file controller_type.h.

32 {
35 
36  // Steam Controllers
40 
41  // Other Controllers
56  k_eControllerType_XInputSwitchController = 44, // Client-side only, used to mark Switch-compatible controllers as not supporting Switch controller protocol
57  k_eControllerType_LastController, // Don't add game controllers below this enumeration - this enumeration can change value
58 
59  // Keyboards and Mice

Function Documentation

◆ GetControllerTypeOverride()

static SDL_INLINE const char* GetControllerTypeOverride ( int  nVID,
int  nPID 
)
static

Definition at line 543 of file controller_type.h.

544 {
545  const char *hint = SDL_GetHint(SDL_HINT_GAMECONTROLLERTYPE);
546  if (hint) {
547  char key[32];
548  const char *spot = NULL;
549 
550  SDL_snprintf(key, sizeof(key), "0x%.4x/0x%.4x=", nVID, nPID);
551  spot = SDL_strstr(hint, key);
552  if (!spot) {
553  SDL_snprintf(key, sizeof(key), "0x%.4X/0x%.4X=", nVID, nPID);
554  spot = SDL_strstr(hint, key);
555  }
556  if (spot) {
557  spot += SDL_strlen(key);
558  if (SDL_strncmp(spot, "k_eControllerType_", 18) == 0) {
559  spot += 18;
560  }
561  return spot;
562  }
563  }
564  return NULL;
565 }

References NULL, SDL_GetHint, SDL_HINT_GAMECONTROLLERTYPE, SDL_snprintf, SDL_strlen, SDL_strncmp, and SDL_strstr.

Referenced by GuessControllerType().

◆ GuessControllerName()

static SDL_INLINE const char* GuessControllerName ( int  nVID,
int  nPID 
)
static

Definition at line 635 of file controller_type.h.

636 {
637  unsigned int unDeviceID = MAKE_CONTROLLER_ID( nVID, nPID );
638  int iIndex;
639  for ( iIndex = 0; iIndex < sizeof( arrControllers ) / sizeof( arrControllers[0] ); ++iIndex )
640  {
641  if ( unDeviceID == arrControllers[ iIndex ].m_unDeviceID )
642  {
643  return arrControllers[ iIndex ].m_pszName;
644  }
645  }
646 
647  return NULL;
648 
649 }

References arrControllers, ControllerDescription_t::m_pszName, MAKE_CONTROLLER_ID, and NULL.

Referenced by SDL_GetCustomJoystickName().

◆ GuessControllerType()

static SDL_INLINE EControllerType GuessControllerType ( int  nVID,
int  nPID 
)
static

Definition at line 567 of file controller_type.h.

568 {
569 #if 0//def _DEBUG
570  // Verify that there are no duplicates in the controller list
571  // If the list were sorted, we could do this much more efficiently, as well as improve lookup speed.
572  static bool s_bCheckedForDuplicates;
573  if ( !s_bCheckedForDuplicates )
574  {
575  s_bCheckedForDuplicates = true;
576 
577  for ( int i = 0; i < sizeof( arrControllers ) / sizeof( arrControllers[ 0 ] ); ++i )
578  {
579  for ( int j = i + 1; j < sizeof( arrControllers ) / sizeof( arrControllers[ 0 ] ); ++j )
580  {
581  if ( arrControllers[ i ].m_unDeviceID == arrControllers[ j ].m_unDeviceID )
582  {
583  Log( "Duplicate controller entry found for VID 0x%.4x PID 0x%.4x\n", ( arrControllers[ i ].m_unDeviceID >> 16 ), arrControllers[ i ].m_unDeviceID & 0xFFFF );
584  }
585  }
586  }
587  }
588 #endif // _DEBUG
589 
590  unsigned int unDeviceID = MAKE_CONTROLLER_ID( nVID, nPID );
591  int iIndex;
592 
593  const char *pszOverride = GetControllerTypeOverride( nVID, nPID );
594  if ( pszOverride )
595  {
596  if ( SDL_strncasecmp( pszOverride, "Xbox360", 7 ) == 0 )
597  {
599  }
600  if ( SDL_strncasecmp( pszOverride, "XboxOne", 7 ) == 0 )
601  {
603  }
604  if ( SDL_strncasecmp( pszOverride, "PS3", 3 ) == 0 )
605  {
607  }
608  if ( SDL_strncasecmp( pszOverride, "PS4", 3 ) == 0 )
609  {
611  }
612  if ( SDL_strncasecmp( pszOverride, "SwitchPro", 9 ) == 0 )
613  {
615  }
616  if ( SDL_strncasecmp( pszOverride, "Steam", 5 ) == 0 )
617  {
619  }
621  }
622 
623  for ( iIndex = 0; iIndex < sizeof( arrControllers ) / sizeof( arrControllers[0] ); ++iIndex )
624  {
625  if ( unDeviceID == arrControllers[ iIndex ].m_unDeviceID )
626  {
627  return arrControllers[ iIndex ].m_eControllerType;
628  }
629  }
630 
632 
633 }

References arrControllers, GetControllerTypeOverride(), i, j, k_eControllerType_PS3Controller, k_eControllerType_PS4Controller, k_eControllerType_SteamController, k_eControllerType_SwitchProController, k_eControllerType_UnknownNonSteamController, k_eControllerType_XBox360Controller, k_eControllerType_XBoxOneController, ControllerDescription_t::m_eControllerType, MAKE_CONTROLLER_ID, and SDL_strncasecmp.

Referenced by SDL_GetJoystickGameControllerType(), SDL_GetJoystickGUIDType(), SDL_IsJoystickNintendoSwitchProInputOnly(), and SDL_IsJoystickSteamController().

Variable Documentation

◆ arrControllers

const ControllerDescription_t arrControllers[]
static

Definition at line 72 of file controller_type.h.

Referenced by GuessControllerName(), and GuessControllerType().

GetControllerTypeOverride
static SDL_INLINE const char * GetControllerTypeOverride(int nVID, int nPID)
Definition: controller_type.h:543
k_eControllerType_SteamController
@ k_eControllerType_SteamController
Definition: controller_type.h:38
k_eControllerType_SwitchInputOnlyController
@ k_eControllerType_SwitchInputOnlyController
Definition: controller_type.h:54
ControllerDescription_t::m_eControllerType
EControllerType m_eControllerType
Definition: controller_type.h:68
k_eControllertype_GenericKeyboard
@ k_eControllertype_GenericKeyboard
Definition: controller_type.h:60
k_eControllerType_MobileTouch
@ k_eControllerType_MobileTouch
Definition: controller_type.h:55
SDL_HINT_GAMECONTROLLERTYPE
#define SDL_HINT_GAMECONTROLLERTYPE
A variable that overrides the automatic controller type detection.
Definition: SDL_hints.h:487
k_eControllerType_None
@ k_eControllerType_None
Definition: controller_type.h:33
NULL
#define NULL
Definition: begin_code.h:167
k_eControllerType_SwitchJoyConRight
@ k_eControllerType_SwitchJoyConRight
Definition: controller_type.h:52
k_eControllerType_SwitchProController
@ k_eControllerType_SwitchProController
Definition: controller_type.h:50
k_eControllerType_WiiController
@ k_eControllerType_WiiController
Definition: controller_type.h:47
arrControllers
static const ControllerDescription_t arrControllers[]
Definition: controller_type.h:72
SDL_strncmp
#define SDL_strncmp
Definition: SDL_dynapi_overrides.h:418
SDL_GetHint
#define SDL_GetHint
Definition: SDL_dynapi_overrides.h:191
k_eControllerType_SwitchJoyConPair
@ k_eControllerType_SwitchJoyConPair
Definition: controller_type.h:53
MAKE_CONTROLLER_ID
#define MAKE_CONTROLLER_ID(nVID, nPID)
Definition: controller_type.h:64
k_eControllerType_LastController
@ k_eControllerType_LastController
Definition: controller_type.h:57
k_eControllerType_AndroidController
@ k_eControllerType_AndroidController
Definition: controller_type.h:49
k_eControllerType_PS4Controller
@ k_eControllerType_PS4Controller
Definition: controller_type.h:46
SDL_strncasecmp
#define SDL_strncasecmp
Definition: SDL_dynapi_overrides.h:420
k_eControllerType_XBox360Controller
@ k_eControllerType_XBox360Controller
Definition: controller_type.h:43
k_eControllerType_SteamControllerV2
@ k_eControllerType_SteamControllerV2
Definition: controller_type.h:39
key
GLuint64 key
Definition: gl2ext.h:2192
k_eControllerType_UnknownNonSteamController
@ k_eControllerType_UnknownNonSteamController
Definition: controller_type.h:42
k_eControllerType_Unknown
@ k_eControllerType_Unknown
Definition: controller_type.h:34
k_eControllertype_GenericMouse
@ k_eControllertype_GenericMouse
Definition: controller_type.h:61
k_eControllerType_SwitchJoyConLeft
@ k_eControllerType_SwitchJoyConLeft
Definition: controller_type.h:51
k_eControllerType_AppleController
@ k_eControllerType_AppleController
Definition: controller_type.h:48
k_eControllerType_PS3Controller
@ k_eControllerType_PS3Controller
Definition: controller_type.h:45
SDL_snprintf
#define SDL_snprintf
Definition: SDL_dynapi_overrides.h:40
ControllerDescription_t::m_pszName
const char * m_pszName
Definition: controller_type.h:69
k_eControllerType_XInputSwitchController
@ k_eControllerType_XInputSwitchController
Definition: controller_type.h:56
EControllerType
EControllerType
Definition: controller_type.h:32
SDL_strlen
#define SDL_strlen
Definition: SDL_dynapi_overrides.h:393
j
return Display return Display Bool Bool int int int return Display XEvent Bool(*) XPointer return Display return Display Drawable _Xconst char unsigned int unsigned int return Display Pixmap Pixmap XColor XColor unsigned int unsigned int return Display _Xconst char char int char return Display Visual unsigned int int int char unsigned int unsigned int int in j)
Definition: SDL_x11sym.h:50
SDL_strstr
#define SDL_strstr
Definition: SDL_dynapi_overrides.h:403
k_eControllerType_UnknownSteamController
@ k_eControllerType_UnknownSteamController
Definition: controller_type.h:37
k_eControllerType_XBoxOneController
@ k_eControllerType_XBoxOneController
Definition: controller_type.h:44
i
return Display return Display Bool Bool int int int return Display XEvent Bool(*) XPointer return Display return Display Drawable _Xconst char unsigned int unsigned int return Display Pixmap Pixmap XColor XColor unsigned int unsigned int return Display _Xconst char char int char return Display Visual unsigned int int int char unsigned int unsigned int in i)
Definition: SDL_x11sym.h:50