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_PS5Controller = 45 ,
  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)
 
static SDL_INLINE int GetDefaultDeadzoneSizeForControllerType (EControllerType eControllerType)
 

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_PS5Controller 
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
58  k_eControllerType_LastController, // Don't add game controllers below this enumeration - this enumeration can change value
59 
60  // Keyboards and Mice
EControllerType
@ k_eControllerType_MobileTouch
@ k_eControllerType_AndroidController
@ k_eControllerType_SteamController
@ k_eControllerType_SwitchJoyConLeft
@ k_eControllerType_XInputSwitchController
@ k_eControllerType_AppleController
@ k_eControllerType_PS3Controller
@ k_eControllerType_Unknown
@ k_eControllerType_LastController
@ k_eControllerType_SteamControllerV2
@ k_eControllertype_GenericKeyboard
@ k_eControllerType_PS5Controller
@ k_eControllertype_GenericMouse
@ k_eControllerType_WiiController
@ k_eControllerType_SwitchProController
@ k_eControllerType_PS4Controller
@ k_eControllerType_XBox360Controller
@ k_eControllerType_SwitchJoyConRight
@ k_eControllerType_XBoxOneController
@ k_eControllerType_UnknownSteamController
@ k_eControllerType_SwitchJoyConPair
@ k_eControllerType_UnknownNonSteamController
@ k_eControllerType_SwitchInputOnlyController
@ k_eControllerType_None

Function Documentation

◆ GetControllerTypeOverride()

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

Definition at line 570 of file controller_type.h.

571 {
572  const char *hint = SDL_GetHint(SDL_HINT_GAMECONTROLLERTYPE);
573  if (hint) {
574  char key[32];
575  const char *spot = NULL;
576 
577  SDL_snprintf(key, sizeof(key), "0x%.4x/0x%.4x=", nVID, nPID);
578  spot = SDL_strstr(hint, key);
579  if (!spot) {
580  SDL_snprintf(key, sizeof(key), "0x%.4X/0x%.4X=", nVID, nPID);
581  spot = SDL_strstr(hint, key);
582  }
583  if (spot) {
584  spot += SDL_strlen(key);
585  if (SDL_strncmp(spot, "k_eControllerType_", 18) == 0) {
586  spot += 18;
587  }
588  return spot;
589  }
590  }
591  return NULL;
592 }
#define SDL_strncmp
#define SDL_strlen
#define SDL_strstr
#define SDL_snprintf
#define SDL_GetHint
#define SDL_HINT_GAMECONTROLLERTYPE
A variable that overrides the automatic controller type detection.
Definition: SDL_hints.h:501
#define NULL
Definition: begin_code.h:163
GLuint64 key
Definition: gl2ext.h:2192

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

Referenced by GuessControllerType().

◆ GetDefaultDeadzoneSizeForControllerType()

static SDL_INLINE int GetDefaultDeadzoneSizeForControllerType ( EControllerType  eControllerType)
static

Definition at line 684 of file controller_type.h.

685 {
686  switch ( eControllerType )
687  {
694  return 10000;
696  return 8192;
699  return 4096;
703  return 8192; // Actual dead-zone should be 15% of full-scale, but we use this to account for variances in 3rd-party controllers
705  return 8192; // Actual dead-zone should be closer to 10% of full-scale, but we use this to account for variances in 3rd-party controllers
706  default:
707  return 8192;
708  }
709 }

References k_eControllerType_AndroidController, k_eControllerType_AppleController, k_eControllerType_PS3Controller, k_eControllerType_PS4Controller, k_eControllerType_PS5Controller, k_eControllerType_SteamControllerV2, k_eControllerType_SwitchJoyConLeft, k_eControllerType_SwitchJoyConPair, k_eControllerType_SwitchJoyConRight, k_eControllerType_SwitchProController, k_eControllerType_UnknownNonSteamController, k_eControllerType_XBox360Controller, and k_eControllerType_XBoxOneController.

◆ GuessControllerName()

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

Definition at line 666 of file controller_type.h.

667 {
668  unsigned int unDeviceID = MAKE_CONTROLLER_ID( nVID, nPID );
669  int iIndex;
670  for ( iIndex = 0; iIndex < sizeof( arrControllers ) / sizeof( arrControllers[0] ); ++iIndex )
671  {
672  if ( unDeviceID == arrControllers[ iIndex ].m_unDeviceID )
673  {
674  return arrControllers[ iIndex ].m_pszName;
675  }
676  }
677 
678  return NULL;
679 
680 }
#define MAKE_CONTROLLER_ID(nVID, nPID)
static const ControllerDescription_t arrControllers[]

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

Referenced by SDL_CreateJoystickName().

◆ GuessControllerType()

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

Definition at line 594 of file controller_type.h.

595 {
596 #if 0//def _DEBUG
597  // Verify that there are no duplicates in the controller list
598  // If the list were sorted, we could do this much more efficiently, as well as improve lookup speed.
599  static bool s_bCheckedForDuplicates;
600  if ( !s_bCheckedForDuplicates )
601  {
602  s_bCheckedForDuplicates = true;
603  int i, j;
604  for ( i = 0; i < sizeof( arrControllers ) / sizeof( arrControllers[ 0 ] ); ++i )
605  {
606  for ( j = i + 1; j < sizeof( arrControllers ) / sizeof( arrControllers[ 0 ] ); ++j )
607  {
608  if ( arrControllers[ i ].m_unDeviceID == arrControllers[ j ].m_unDeviceID )
609  {
610  Log( "Duplicate controller entry found for VID 0x%.4x PID 0x%.4x\n", ( arrControllers[ i ].m_unDeviceID >> 16 ), arrControllers[ i ].m_unDeviceID & 0xFFFF );
611  }
612  }
613  }
614  }
615 #endif // _DEBUG
616 
617  unsigned int unDeviceID = MAKE_CONTROLLER_ID( nVID, nPID );
618  int iIndex;
619 
620  const char *pszOverride = GetControllerTypeOverride( nVID, nPID );
621  if ( pszOverride )
622  {
623  if ( SDL_strncasecmp( pszOverride, "Xbox360", 7 ) == 0 )
624  {
626  }
627  if ( SDL_strncasecmp( pszOverride, "XboxOne", 7 ) == 0 )
628  {
630  }
631  if ( SDL_strncasecmp( pszOverride, "PS3", 3 ) == 0 )
632  {
634  }
635  if ( SDL_strncasecmp( pszOverride, "PS4", 3 ) == 0 )
636  {
638  }
639  if ( SDL_strncasecmp( pszOverride, "PS5", 3 ) == 0 )
640  {
642  }
643  if ( SDL_strncasecmp( pszOverride, "SwitchPro", 9 ) == 0 )
644  {
646  }
647  if ( SDL_strncasecmp( pszOverride, "Steam", 5 ) == 0 )
648  {
650  }
652  }
653 
654  for ( iIndex = 0; iIndex < sizeof( arrControllers ) / sizeof( arrControllers[0] ); ++iIndex )
655  {
656  if ( unDeviceID == arrControllers[ iIndex ].m_unDeviceID )
657  {
658  return arrControllers[ iIndex ].m_eControllerType;
659  }
660  }
661 
663 
664 }
#define SDL_strncasecmp
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
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
static SDL_INLINE const char * GetControllerTypeOverride(int nVID, int nPID)
EControllerType m_eControllerType

References arrControllers, GetControllerTypeOverride(), i, j, k_eControllerType_PS3Controller, k_eControllerType_PS4Controller, k_eControllerType_PS5Controller, 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_IsJoystickNintendoSwitchPro(), SDL_IsJoystickNintendoSwitchProInputOnly(), SDL_IsJoystickPS4(), SDL_IsJoystickPS5(), and SDL_IsJoystickSteamController().

Variable Documentation

◆ arrControllers

const ControllerDescription_t arrControllers[]
static

Definition at line 73 of file controller_type.h.

Referenced by GuessControllerName(), and GuessControllerType().