SDL  2.0
SDL_gamecontroller.h File Reference
#include "SDL_stdinc.h"
#include "SDL_error.h"
#include "SDL_rwops.h"
#include "SDL_sensor.h"
#include "SDL_joystick.h"
#include "begin_code.h"
#include "close_code.h"
+ Include dependency graph for SDL_gamecontroller.h:
+ This graph shows which files directly or indirectly include this file:

Go to the source code of this file.

Data Structures

struct  SDL_GameControllerButtonBind
 

Macros

#define SDL_GameControllerAddMappingsFromFile(file)   SDL_GameControllerAddMappingsFromRW(SDL_RWFromFile(file, "rb"), 1)
 

Enumerations

enum  SDL_GameControllerType {
  SDL_CONTROLLER_TYPE_UNKNOWN = 0 ,
  SDL_CONTROLLER_TYPE_XBOX360 ,
  SDL_CONTROLLER_TYPE_XBOXONE ,
  SDL_CONTROLLER_TYPE_PS3 ,
  SDL_CONTROLLER_TYPE_PS4 ,
  SDL_CONTROLLER_TYPE_NINTENDO_SWITCH_PRO ,
  SDL_CONTROLLER_TYPE_VIRTUAL ,
  SDL_CONTROLLER_TYPE_PS5
}
 
enum  SDL_GameControllerBindType {
  SDL_CONTROLLER_BINDTYPE_NONE = 0 ,
  SDL_CONTROLLER_BINDTYPE_BUTTON ,
  SDL_CONTROLLER_BINDTYPE_AXIS ,
  SDL_CONTROLLER_BINDTYPE_HAT
}
 
enum  SDL_GameControllerAxis {
  SDL_CONTROLLER_AXIS_INVALID = -1 ,
  SDL_CONTROLLER_AXIS_LEFTX ,
  SDL_CONTROLLER_AXIS_LEFTY ,
  SDL_CONTROLLER_AXIS_RIGHTX ,
  SDL_CONTROLLER_AXIS_RIGHTY ,
  SDL_CONTROLLER_AXIS_TRIGGERLEFT ,
  SDL_CONTROLLER_AXIS_TRIGGERRIGHT ,
  SDL_CONTROLLER_AXIS_MAX
}
 
enum  SDL_GameControllerButton {
  SDL_CONTROLLER_BUTTON_INVALID = -1 ,
  SDL_CONTROLLER_BUTTON_A ,
  SDL_CONTROLLER_BUTTON_B ,
  SDL_CONTROLLER_BUTTON_X ,
  SDL_CONTROLLER_BUTTON_Y ,
  SDL_CONTROLLER_BUTTON_BACK ,
  SDL_CONTROLLER_BUTTON_GUIDE ,
  SDL_CONTROLLER_BUTTON_START ,
  SDL_CONTROLLER_BUTTON_LEFTSTICK ,
  SDL_CONTROLLER_BUTTON_RIGHTSTICK ,
  SDL_CONTROLLER_BUTTON_LEFTSHOULDER ,
  SDL_CONTROLLER_BUTTON_RIGHTSHOULDER ,
  SDL_CONTROLLER_BUTTON_DPAD_UP ,
  SDL_CONTROLLER_BUTTON_DPAD_DOWN ,
  SDL_CONTROLLER_BUTTON_DPAD_LEFT ,
  SDL_CONTROLLER_BUTTON_DPAD_RIGHT ,
  SDL_CONTROLLER_BUTTON_MISC1 ,
  SDL_CONTROLLER_BUTTON_PADDLE1 ,
  SDL_CONTROLLER_BUTTON_PADDLE2 ,
  SDL_CONTROLLER_BUTTON_PADDLE3 ,
  SDL_CONTROLLER_BUTTON_PADDLE4 ,
  SDL_CONTROLLER_BUTTON_TOUCHPAD ,
  SDL_CONTROLLER_BUTTON_MAX
}
 

Functions

int SDL_GameControllerAddMappingsFromRW (SDL_RWops *rw, int freerw)
 
int SDL_GameControllerAddMapping (const char *mappingString)
 
int SDL_GameControllerNumMappings (void)
 
char * SDL_GameControllerMappingForIndex (int mapping_index)
 
char * SDL_GameControllerMappingForGUID (SDL_JoystickGUID guid)
 
char * SDL_GameControllerMapping (SDL_GameController *gamecontroller)
 
SDL_bool SDL_IsGameController (int joystick_index)
 
const char * SDL_GameControllerNameForIndex (int joystick_index)
 
SDL_GameControllerType SDL_GameControllerTypeForIndex (int joystick_index)
 
char * SDL_GameControllerMappingForDeviceIndex (int joystick_index)
 
SDL_GameController * SDL_GameControllerOpen (int joystick_index)
 
SDL_GameController * SDL_GameControllerFromInstanceID (SDL_JoystickID joyid)
 
SDL_GameController * SDL_GameControllerFromPlayerIndex (int player_index)
 
const char * SDL_GameControllerName (SDL_GameController *gamecontroller)
 
SDL_GameControllerType SDL_GameControllerGetType (SDL_GameController *gamecontroller)
 
int SDL_GameControllerGetPlayerIndex (SDL_GameController *gamecontroller)
 
void SDL_GameControllerSetPlayerIndex (SDL_GameController *gamecontroller, int player_index)
 
Uint16 SDL_GameControllerGetVendor (SDL_GameController *gamecontroller)
 
Uint16 SDL_GameControllerGetProduct (SDL_GameController *gamecontroller)
 
Uint16 SDL_GameControllerGetProductVersion (SDL_GameController *gamecontroller)
 
const char * SDL_GameControllerGetSerial (SDL_GameController *gamecontroller)
 
SDL_bool SDL_GameControllerGetAttached (SDL_GameController *gamecontroller)
 
SDL_Joystick * SDL_GameControllerGetJoystick (SDL_GameController *gamecontroller)
 
int SDL_GameControllerEventState (int state)
 
void SDL_GameControllerUpdate (void)
 
SDL_GameControllerAxis SDL_GameControllerGetAxisFromString (const char *pchString)
 
const char * SDL_GameControllerGetStringForAxis (SDL_GameControllerAxis axis)
 
SDL_GameControllerButtonBind SDL_GameControllerGetBindForAxis (SDL_GameController *gamecontroller, SDL_GameControllerAxis axis)
 
SDL_bool SDL_GameControllerHasAxis (SDL_GameController *gamecontroller, SDL_GameControllerAxis axis)
 
Sint16 SDL_GameControllerGetAxis (SDL_GameController *gamecontroller, SDL_GameControllerAxis axis)
 
SDL_GameControllerButton SDL_GameControllerGetButtonFromString (const char *pchString)
 
const char * SDL_GameControllerGetStringForButton (SDL_GameControllerButton button)
 
SDL_GameControllerButtonBind SDL_GameControllerGetBindForButton (SDL_GameController *gamecontroller, SDL_GameControllerButton button)
 
SDL_bool SDL_GameControllerHasButton (SDL_GameController *gamecontroller, SDL_GameControllerButton button)
 
Uint8 SDL_GameControllerGetButton (SDL_GameController *gamecontroller, SDL_GameControllerButton button)
 
int SDL_GameControllerGetNumTouchpads (SDL_GameController *gamecontroller)
 
int SDL_GameControllerGetNumTouchpadFingers (SDL_GameController *gamecontroller, int touchpad)
 
int SDL_GameControllerGetTouchpadFinger (SDL_GameController *gamecontroller, int touchpad, int finger, Uint8 *state, float *x, float *y, float *pressure)
 
SDL_bool SDL_GameControllerHasSensor (SDL_GameController *gamecontroller, SDL_SensorType type)
 
int SDL_GameControllerSetSensorEnabled (SDL_GameController *gamecontroller, SDL_SensorType type, SDL_bool enabled)
 
SDL_bool SDL_GameControllerIsSensorEnabled (SDL_GameController *gamecontroller, SDL_SensorType type)
 
int SDL_GameControllerGetSensorData (SDL_GameController *gamecontroller, SDL_SensorType type, float *data, int num_values)
 
int SDL_GameControllerRumble (SDL_GameController *gamecontroller, Uint16 low_frequency_rumble, Uint16 high_frequency_rumble, Uint32 duration_ms)
 
int SDL_GameControllerRumbleTriggers (SDL_GameController *gamecontroller, Uint16 left_rumble, Uint16 right_rumble, Uint32 duration_ms)
 
SDL_bool SDL_GameControllerHasLED (SDL_GameController *gamecontroller)
 
int SDL_GameControllerSetLED (SDL_GameController *gamecontroller, Uint8 red, Uint8 green, Uint8 blue)
 
void SDL_GameControllerClose (SDL_GameController *gamecontroller)
 

Detailed Description

Include file for SDL game controller event handling

In order to use these functions, SDL_Init() must have been called with the SDL_INIT_GAMECONTROLLER flag. This causes SDL to scan the system for game controllers, and load appropriate drivers.

If you would like to receive controller updates while the application is in the background, you should set the following hint before calling SDL_Init(): SDL_HINT_JOYSTICK_ALLOW_BACKGROUND_EVENTS

Definition in file SDL_gamecontroller.h.

Macro Definition Documentation

◆ SDL_GameControllerAddMappingsFromFile

#define SDL_GameControllerAddMappingsFromFile (   file)    SDL_GameControllerAddMappingsFromRW(SDL_RWFromFile(file, "rb"), 1)

Load a set of mappings from a file, filtered by the current SDL_GetPlatform()

Convenience macro.

Definition at line 141 of file SDL_gamecontroller.h.

Enumeration Type Documentation

◆ SDL_GameControllerAxis

enum SDL_PRINTF_FORMAT_STRING const char int SDL_PRINTF_FORMAT_STRING const char int SDL_PRINTF_FORMAT_STRING const char int SDL_PRINTF_FORMAT_STRING const char const char SDL_SCANF_FORMAT_STRING const char return SDL_ThreadFunction const char void return Uint32 return Uint32 SDL_AssertionHandler void SDL_SpinLock SDL_atomic_t int int return SDL_atomic_t return void void void return void return int return SDL_AudioSpec SDL_AudioSpec return int int return return int SDL_RWops int SDL_AudioSpec Uint8 Uint32 return SDL_AudioCVT SDL_AudioFormat Uint8 int SDL_AudioFormat Uint8 int return Uint8 const Uint8 Uint32 int const char return return return return return return return return Uint32 return Uint32 SDL_Event return SDL_Event int return SDL_EventFilter void SDL_EventFilter void SDL_EventFilter void int return const char const char return SDL_JoystickGUID return int return int return SDL_GameController return int return const char return SDL_GameController SDL_GameControllerAxis return const char return SDL_GameController SDL_GameControllerButton return SDL_GameController SDL_RWops return SDL_TouchID SDL_RWops return int return int return return SDL_Joystick return SDL_Haptic SDL_Haptic return SDL_Haptic return SDL_Haptic SDL_HapticEffect return SDL_Haptic int Uint32 return SDL_Haptic int SDL_Haptic int return SDL_Haptic return SDL_Haptic return SDL_Haptic return SDL_Haptic return const char const char return const char SDL_HintCallback void int return SDL_Joystick return SDL_Joystick return const char return SDL_Joystick return SDL_Joystick return SDL_Joystick return int return SDL_Joystick int return SDL_Joystick int return return return SDL_Scancode return SDL_Scancode return SDL_Keycode return return const char return void int SDL_LogPriority SDL_LogOutputFunction void Uint32 const char const char SDL_Window return int int return SDL_Window int int return SDL_Surface int int return SDL_Cursor return int return SDL_mutex return SDL_mutex return Uint32 return SDL_sem return SDL_sem Uint32 return SDL_sem return SDL_cond SDL_cond return SDL_cond SDL_mutex Uint32 return Uint32 int Uint32 Uint32 Uint32 Uint32 return Uint32 return int return SDL_Palette const SDL_Color int int return const SDL_PixelFormat Uint8 Uint8 Uint8 return Uint32 const SDL_PixelFormat Uint8 Uint8 Uint8 float Uint16 int int return const SDL_Rect const SDL_Rect SDL_Rect return const SDL_Point int const SDL_Rect SDL_Rect return return int int Uint32 SDL_Window SDL_Renderer return SDL_Surface return SDL_Renderer SDL_RendererInfo return SDL_Renderer Uint32 int int int return SDL_Texture Uint32 int int int return SDL_Texture Uint8 Uint8 Uint8 return SDL_Texture Uint8 return SDL_Texture SDL_BlendMode return SDL_Texture const SDL_Rect const Uint8 int const Uint8 int const Uint8 int return SDL_Texture SDL_Renderer SDL_Texture return SDL_Renderer int int return SDL_Renderer const SDL_Rect return SDL_Renderer const SDL_Rect return SDL_Renderer float float return SDL_Renderer Uint8 Uint8 Uint8 Uint8 return SDL_Renderer SDL_BlendMode return SDL_Renderer return SDL_Renderer const SDL_Point int return SDL_Renderer const SDL_Point int return SDL_Renderer const SDL_Rect int return SDL_Renderer const SDL_Rect int return SDL_Renderer SDL_Texture const SDL_Rect const SDL_Rect const double const SDL_Point const SDL_RendererFlip return SDL_Renderer SDL_Renderer SDL_Texture return void int return return SDL_RWops return SDL_RWops return SDL_RWops return SDL_RWops return SDL_RWops Uint16 return SDL_RWops Uint32 return SDL_RWops Uint64 return const char unsigned int unsigned int unsigned int unsigned int Uint32 return SDL_Window SDL_Surface SDL_WindowShapeMode return size_t return void size_t return const char return void size_t size_t int(*) b int return int return int size_t return size_t return const wchar_t return const wchar_t size_t return const char size_t return const char size_t return char return char return const char int return int char int return long char int return Sint64 char int return const char return const char char int return const char char int return const char char return const char const char size_t return const char const char size_t return double return double return double return double return double return double return double int return float return const char const char return SDL_iconv_t const char size_t char size_t return Uint32 int int int Uint32 Uint32 Uint32 Uint32 return SDL_Surface SDL_Surface return SDL_RWops int return SDL_Surface int return SDL_Surface Uint32 return SDL_Surface Uint8 Uint8 Uint8 return SDL_Surface Uint8 return SDL_Surface SDL_BlendMode return SDL_Surface SDL_Rect SDL_Surface Uint32 Uint32 return SDL_Surface const SDL_Rect Uint32 return SDL_Surface const SDL_Rect SDL_Surface SDL_Rect return SDL_Surface const SDL_Rect SDL_Surface const SDL_Rect return SDL_Surface SDL_Rect SDL_Surface SDL_Rect return SDL_Thread return SDL_Thread return SDL_Thread int return SDL_TLSID const void void(*) return return Uint32 SDL_TimerID return int return SDL_TouchID int return return return const char return return int return int return int SDL_DisplayMode return int const SDL_DisplayMode SDL_DisplayMode return SDL_Window const SDL_DisplayMode return SDL_Window return const void return Uint32 return SDL_Window const char SDL_Window SDL_Surface SDL_Window const char return SDL_Window int int SDL_Window int int SDL_Window int int SDL_Window int int SDL_Window SDL_Window SDL_Window SDL_Window Uint32 return SDL_Window return SDL_Window SDL_bool SDL_Window float return SDL_Window const Uint16 const Uint16 const Uint16 return SDL_Window const char return SDL_GLattr int return SDL_Window return return SDL_Window int int return SDL_GLContext SDL_RWops int return return void return int int return double return SDL_bool return int int return SDL_AudioDeviceID const void Uint32 return SDL_AudioDeviceID int float float float return SDL_JoystickID return int SDL_Rect return SDL_Window float return SDL_Window return SDL_Renderer SDL_bool return SDL_AudioDeviceID void Uint32 return Uint32 int int int Uint32 return const char SDL_bool return int return SDL_Joystick return SDL_Joystick return SDL_GameController return return int return int return int return SDL_RWops size_t int return SDL_BlendFactor SDL_BlendFactor SDL_BlendOperation SDL_BlendFactor SDL_BlendFactor SDL_BlendOperation return const char return SDL_Window VkInstance VkSurfaceKHR return SDL_malloc_func SDL_calloc_func SDL_realloc_func SDL_free_func return SDL_AudioStream const void int return SDL_AudioStream SDL_AudioStream float return float return float return float return float return float int return float float return return SDL_Renderer return double return int return double return const wchar_t return SDL_Joystick Uint16 Uint16 Uint32 return int return int return int return SDL_Sensor return SDL_Sensor return SDL_Sensor float int return int return SDL_ThreadFunction const char const size_t void return SDL_Joystick return SDL_Renderer return SDL_Renderer const SDL_FPoint int return SDL_Renderer const SDL_FPoint int return SDL_Renderer const SDL_FRect int return SDL_Renderer const SDL_FRect int return SDL_Renderer SDL_Texture const SDL_Rect const SDL_FRect const double const SDL_FPoint const SDL_RendererFlip return return void SDL_RWops Sint64 int return SDL_RWops void size_t size_t return SDL_RWops return SDL_Window return SDL_Texture const SDL_Rect SDL_Surface return char const char char return const wchar_t const wchar_t size_t return SDL_GameController return SDL_GameController int SDL_Joystick int SDL_Texture SDL_ScaleMode return int return int return SDL_Joystick int Sint16 return SDL_Joystick int Uint8 return SDL_MetalView return double return return const char return SDL_GameController return SDL_Joystick return SDL_GameController Uint16 Uint16 Uint32 return SDL_GameController SDL_GameControllerAxis

The list of axes available from a controller

Thumbstick axis values range from SDL_JOYSTICK_AXIS_MIN to SDL_JOYSTICK_AXIS_MAX, and are centered within ~8000 of zero, though advanced UI will allow users to set or autodetect the dead zone, which varies between controllers.

Trigger axis values range from 0 to SDL_JOYSTICK_AXIS_MAX.

Enumerator
SDL_CONTROLLER_AXIS_INVALID 
SDL_CONTROLLER_AXIS_LEFTX 
SDL_CONTROLLER_AXIS_LEFTY 
SDL_CONTROLLER_AXIS_RIGHTX 
SDL_CONTROLLER_AXIS_RIGHTY 
SDL_CONTROLLER_AXIS_TRIGGERLEFT 
SDL_CONTROLLER_AXIS_TRIGGERRIGHT 
SDL_CONTROLLER_AXIS_MAX 

Definition at line 312 of file SDL_gamecontroller.h.

◆ SDL_GameControllerBindType

Enumerator
SDL_CONTROLLER_BINDTYPE_NONE 
SDL_CONTROLLER_BINDTYPE_BUTTON 
SDL_CONTROLLER_BINDTYPE_AXIS 
SDL_CONTROLLER_BINDTYPE_HAT 

Definition at line 73 of file SDL_gamecontroller.h.

◆ SDL_GameControllerButton

The list of buttons available from a controller

Enumerator
SDL_CONTROLLER_BUTTON_INVALID 
SDL_CONTROLLER_BUTTON_A 
SDL_CONTROLLER_BUTTON_B 
SDL_CONTROLLER_BUTTON_X 
SDL_CONTROLLER_BUTTON_Y 
SDL_CONTROLLER_BUTTON_BACK 
SDL_CONTROLLER_BUTTON_GUIDE 
SDL_CONTROLLER_BUTTON_START 
SDL_CONTROLLER_BUTTON_LEFTSTICK 
SDL_CONTROLLER_BUTTON_RIGHTSTICK 
SDL_CONTROLLER_BUTTON_LEFTSHOULDER 
SDL_CONTROLLER_BUTTON_RIGHTSHOULDER 
SDL_CONTROLLER_BUTTON_DPAD_UP 
SDL_CONTROLLER_BUTTON_DPAD_DOWN 
SDL_CONTROLLER_BUTTON_DPAD_LEFT 
SDL_CONTROLLER_BUTTON_DPAD_RIGHT 
SDL_CONTROLLER_BUTTON_MISC1 
SDL_CONTROLLER_BUTTON_PADDLE1 
SDL_CONTROLLER_BUTTON_PADDLE2 
SDL_CONTROLLER_BUTTON_PADDLE3 
SDL_CONTROLLER_BUTTON_PADDLE4 
SDL_CONTROLLER_BUTTON_TOUCHPAD 
SDL_CONTROLLER_BUTTON_MAX 

Definition at line 361 of file SDL_gamecontroller.h.

362 {
379  SDL_CONTROLLER_BUTTON_MISC1, /* Xbox Series X share button, PS5 microphone button, Nintendo Switch Pro capture button */
380  SDL_CONTROLLER_BUTTON_PADDLE1, /* Xbox Elite paddle P1 */
381  SDL_CONTROLLER_BUTTON_PADDLE2, /* Xbox Elite paddle P3 */
382  SDL_CONTROLLER_BUTTON_PADDLE3, /* Xbox Elite paddle P2 */
383  SDL_CONTROLLER_BUTTON_PADDLE4, /* Xbox Elite paddle P4 */
384  SDL_CONTROLLER_BUTTON_TOUCHPAD, /* PS4/PS5 touchpad button */
SDL_GameControllerButton
@ SDL_CONTROLLER_BUTTON_B
@ SDL_CONTROLLER_BUTTON_BACK
@ SDL_CONTROLLER_BUTTON_LEFTSTICK
@ SDL_CONTROLLER_BUTTON_START
@ SDL_CONTROLLER_BUTTON_PADDLE2
@ SDL_CONTROLLER_BUTTON_PADDLE1
@ SDL_CONTROLLER_BUTTON_DPAD_LEFT
@ SDL_CONTROLLER_BUTTON_RIGHTSHOULDER
@ SDL_CONTROLLER_BUTTON_INVALID
@ SDL_CONTROLLER_BUTTON_DPAD_DOWN
@ SDL_CONTROLLER_BUTTON_TOUCHPAD
@ SDL_CONTROLLER_BUTTON_DPAD_UP
@ SDL_CONTROLLER_BUTTON_MAX
@ SDL_CONTROLLER_BUTTON_LEFTSHOULDER
@ SDL_CONTROLLER_BUTTON_GUIDE
@ SDL_CONTROLLER_BUTTON_DPAD_RIGHT
@ SDL_CONTROLLER_BUTTON_MISC1
@ SDL_CONTROLLER_BUTTON_X
@ SDL_CONTROLLER_BUTTON_RIGHTSTICK
@ SDL_CONTROLLER_BUTTON_PADDLE3
@ SDL_CONTROLLER_BUTTON_Y
@ SDL_CONTROLLER_BUTTON_A
@ SDL_CONTROLLER_BUTTON_PADDLE4

◆ SDL_GameControllerType

Enumerator
SDL_CONTROLLER_TYPE_UNKNOWN 
SDL_CONTROLLER_TYPE_XBOX360 
SDL_CONTROLLER_TYPE_XBOXONE 
SDL_CONTROLLER_TYPE_PS3 
SDL_CONTROLLER_TYPE_PS4 
SDL_CONTROLLER_TYPE_NINTENDO_SWITCH_PRO 
SDL_CONTROLLER_TYPE_VIRTUAL 
SDL_CONTROLLER_TYPE_PS5 

Definition at line 61 of file SDL_gamecontroller.h.

Function Documentation

◆ SDL_GameControllerAddMapping()

int SDL_GameControllerAddMapping ( const char *  mappingString)

Add or update an existing mapping configuration

Returns
1 if mapping is added, 0 if updated, -1 on error

Definition at line 1455 of file SDL_gamecontroller.c.

1456 {
1458 }
@ SDL_CONTROLLER_MAPPING_PRIORITY_API
static int SDL_PrivateGameControllerAddMapping(const char *mappingString, SDL_ControllerMappingPriority priority)

References SDL_CONTROLLER_MAPPING_PRIORITY_API, and SDL_PrivateGameControllerAddMapping().

Referenced by SDL_GameControllerAddMappingsFromRW().

◆ SDL_GameControllerAddMappingsFromRW()

int SDL_GameControllerAddMappingsFromRW ( SDL_RWops rw,
int  freerw 
)

To count the number of game controllers in the system for the following: int nJoysticks = SDL_NumJoysticks(); int nGameControllers = 0; for (int i = 0; i < nJoysticks; i++) { if (SDL_IsGameController(i)) { nGameControllers++; } }

Using the SDL_HINT_GAMECONTROLLERCONFIG hint or the SDL_GameControllerAddMapping() you can add support for controllers SDL is unaware of or cause an existing controller to have a different binding. The format is: guid,name,mappings

Where GUID is the string value from SDL_JoystickGetGUIDString(), name is the human readable string for the device and mappings are controller mappings to joystick ones. Under Windows there is a reserved GUID of "xinput" that covers any XInput devices. The mapping format for joystick is: bX - a joystick button, index X hX.Y - hat X with value Y aX - axis X of the joystick Buttons can be used as a controller axis and vice versa.

This string shows an example of a valid mapping for a controller "03000000341a00003608000000000000,PS3 Controller,a:b1,b:b2,y:b3,x:b0,start:b9,guide:b12,back:b8,dpup:h0.1,dpleft:h0.8,dpdown:h0.4,dpright:h0.2,leftshoulder:b4,rightshoulder:b5,leftstick:b10,rightstick:b11,leftx:a0,lefty:a1,rightx:a2,righty:a3,lefttrigger:b6,righttrigger:b7", Load a set of mappings from a seekable SDL data stream (memory or file), filtered by the current SDL_GetPlatform() A community sourced database of controllers is available at https://raw.github.com/gabomdq/SDL_GameControllerDB/master/gamecontrollerdb.txt

If freerw is non-zero, the stream will be closed after being read.

Returns
number of mappings added, -1 on error

Definition at line 1276 of file SDL_gamecontroller.c.

1277 {
1278  const char *platform = SDL_GetPlatform();
1279  int controllers = 0;
1280  char *buf, *line, *line_end, *tmp, *comma, line_platform[64];
1281  size_t db_size, platform_len;
1282 
1283  if (rw == NULL) {
1284  return SDL_SetError("Invalid RWops");
1285  }
1286  db_size = (size_t)SDL_RWsize(rw);
1287 
1288  buf = (char *)SDL_malloc(db_size + 1);
1289  if (buf == NULL) {
1290  if (freerw) {
1291  SDL_RWclose(rw);
1292  }
1293  return SDL_SetError("Could not allocate space to read DB into memory");
1294  }
1295 
1296  if (SDL_RWread(rw, buf, db_size, 1) != 1) {
1297  if (freerw) {
1298  SDL_RWclose(rw);
1299  }
1300  SDL_free(buf);
1301  return SDL_SetError("Could not read DB");
1302  }
1303 
1304  if (freerw) {
1305  SDL_RWclose(rw);
1306  }
1307 
1308  buf[db_size] = '\0';
1309  line = buf;
1310 
1311  while (line < buf + db_size) {
1312  line_end = SDL_strchr(line, '\n');
1313  if (line_end != NULL) {
1314  *line_end = '\0';
1315  } else {
1316  line_end = buf + db_size;
1317  }
1318 
1319  /* Extract and verify the platform */
1321  if (tmp != NULL) {
1323  comma = SDL_strchr(tmp, ',');
1324  if (comma != NULL) {
1325  platform_len = comma - tmp + 1;
1326  if (platform_len + 1 < SDL_arraysize(line_platform)) {
1327  SDL_strlcpy(line_platform, tmp, platform_len);
1328  if (SDL_strncasecmp(line_platform, platform, platform_len) == 0 &&
1329  SDL_GameControllerAddMapping(line) > 0) {
1330  controllers++;
1331  }
1332  }
1333  }
1334  }
1335 
1336  line = line_end + 1;
1337  }
1338 
1339  SDL_free(buf);
1340  return controllers;
1341 }
unsigned int size_t
#define SDL_SetError
#define SDL_strchr
#define SDL_RWread
#define SDL_malloc
#define SDL_strlen
#define SDL_strlcpy
#define SDL_GetPlatform
#define SDL_free
#define SDL_strstr
#define SDL_RWsize
#define SDL_RWclose
#define SDL_strncasecmp
int SDL_GameControllerAddMapping(const char *mappingString)
#define SDL_CONTROLLER_PLATFORM_FIELD
GLenum GLuint GLenum GLsizei const GLchar * buf
#define SDL_arraysize(array)
Definition: SDL_stdinc.h:121
#define NULL
Definition: begin_code.h:163

References sort_controllers::controllers, NULL, SDL_arraysize, SDL_CONTROLLER_PLATFORM_FIELD, SDL_free, SDL_GameControllerAddMapping(), SDL_GetPlatform, SDL_malloc, SDL_RWclose, SDL_RWread, SDL_RWsize, SDL_SetError, SDL_strchr, SDL_strlcpy, SDL_strlen, SDL_strncasecmp, and SDL_strstr.

◆ SDL_GameControllerClose()

void SDL_GameControllerClose ( SDL_GameController *  gamecontroller)

Close a controller previously opened with SDL_GameControllerOpen().

Definition at line 2393 of file SDL_gamecontroller.c.

2394 {
2395  SDL_GameController *gamecontrollerlist, *gamecontrollerlistprev;
2396 
2397  if (!gamecontroller)
2398  return;
2399 
2401 
2402  /* First decrement ref count */
2403  if (--gamecontroller->ref_count > 0) {
2405  return;
2406  }
2407 
2408  SDL_JoystickClose(gamecontroller->joystick);
2409 
2410  gamecontrollerlist = SDL_gamecontrollers;
2411  gamecontrollerlistprev = NULL;
2412  while (gamecontrollerlist) {
2413  if (gamecontroller == gamecontrollerlist) {
2414  if (gamecontrollerlistprev) {
2415  /* unlink this entry */
2416  gamecontrollerlistprev->next = gamecontrollerlist->next;
2417  } else {
2419  }
2420  break;
2421  }
2422  gamecontrollerlistprev = gamecontrollerlist;
2423  gamecontrollerlist = gamecontrollerlist->next;
2424  }
2425 
2426  SDL_free(gamecontroller->bindings);
2427  SDL_free(gamecontroller->last_match_axis);
2428  SDL_free(gamecontroller->last_hat_mask);
2430 
2432 }
#define SDL_LockJoysticks
#define SDL_JoystickClose
#define SDL_UnlockJoysticks
static SDL_GameController * SDL_gamecontrollers
SDL_GameController * gamecontroller

References gamecontroller, NULL, SDL_free, SDL_gamecontrollers, SDL_JoystickClose, SDL_LockJoysticks, and SDL_UnlockJoysticks.

Referenced by SDL_GameControllerQuit().

◆ SDL_GameControllerEventState()

int SDL_GameControllerEventState ( int  state)

Enable/disable controller event polling.

If controller events are disabled, you must call SDL_GameControllerUpdate() yourself and check the state of the controller when you want controller information.

The state can be one of SDL_QUERY, SDL_ENABLE or SDL_IGNORE.

Definition at line 2564 of file SDL_gamecontroller.c.

2565 {
2566 #if SDL_EVENTS_DISABLED
2567  return SDL_IGNORE;
2568 #else
2569  const Uint32 event_list[] = {
2572  };
2573  unsigned int i;
2574 
2575  switch (state) {
2576  case SDL_QUERY:
2577  state = SDL_IGNORE;
2578  for (i = 0; i < SDL_arraysize(event_list); ++i) {
2579  state = SDL_EventState(event_list[i], SDL_QUERY);
2580  if (state == SDL_ENABLE) {
2581  break;
2582  }
2583  }
2584  break;
2585  default:
2586  for (i = 0; i < SDL_arraysize(event_list); ++i) {
2587  SDL_EventState(event_list[i], state);
2588  }
2589  break;
2590  }
2591  return (state);
2592 #endif /* SDL_EVENTS_DISABLED */
2593 }
#define SDL_EventState
@ SDL_CONTROLLERBUTTONUP
Definition: SDL_events.h:124
@ SDL_CONTROLLERDEVICEADDED
Definition: SDL_events.h:125
@ SDL_CONTROLLERBUTTONDOWN
Definition: SDL_events.h:123
@ SDL_CONTROLLERAXISMOTION
Definition: SDL_events.h:122
@ SDL_CONTROLLERDEVICEREMOVED
Definition: SDL_events.h:126
@ SDL_CONTROLLERDEVICEREMAPPED
Definition: SDL_events.h:127
#define SDL_QUERY
Definition: SDL_events.h:792
#define SDL_ENABLE
Definition: SDL_events.h:795
#define SDL_IGNORE
Definition: SDL_events.h:793
uint32_t Uint32
Definition: SDL_stdinc.h:209
struct xkb_state * state
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

References i, SDL_arraysize, SDL_CONTROLLERAXISMOTION, SDL_CONTROLLERBUTTONDOWN, SDL_CONTROLLERBUTTONUP, SDL_CONTROLLERDEVICEADDED, SDL_CONTROLLERDEVICEREMAPPED, SDL_CONTROLLERDEVICEREMOVED, SDL_ENABLE, SDL_EventState, SDL_IGNORE, SDL_QUERY, and state.

◆ SDL_GameControllerFromInstanceID()

SDL_GameController* SDL_GameControllerFromInstanceID ( SDL_JoystickID  joyid)

Return the SDL_GameController associated with an instance id.

Definition at line 2274 of file SDL_gamecontroller.c.

2275 {
2276  SDL_GameController *gamecontroller;
2277 
2280  while (gamecontroller) {
2281  if (gamecontroller->joystick->instance_id == joyid) {
2283  return gamecontroller;
2284  }
2286  }
2288  return NULL;
2289 }

References gamecontroller, NULL, SDL_gamecontrollers, SDL_LockJoysticks, and SDL_UnlockJoysticks.

Referenced by SDL_GameControllerFromPlayerIndex().

◆ SDL_GameControllerFromPlayerIndex()

SDL_GameController* SDL_GameControllerFromPlayerIndex ( int  player_index)

Return the SDL_GameController associated with a player index.

Definition at line 2295 of file SDL_gamecontroller.c.

2296 {
2297  SDL_Joystick *joystick = SDL_JoystickFromPlayerIndex(player_index);
2298  if (joystick) {
2299  return SDL_GameControllerFromInstanceID(joystick->instance_id);
2300  }
2301  return NULL;
2302 }
#define SDL_JoystickFromPlayerIndex
SDL_GameController * SDL_GameControllerFromInstanceID(SDL_JoystickID joyid)
static SDL_Joystick * joystick
Definition: testjoystick.c:37

References joystick, NULL, SDL_GameControllerFromInstanceID(), and SDL_JoystickFromPlayerIndex.

◆ SDL_GameControllerGetAttached()

SDL_bool SDL_GameControllerGetAttached ( SDL_GameController *  gamecontroller)

Returns SDL_TRUE if the controller has been opened and currently connected, or SDL_FALSE if it has not.

Definition at line 2249 of file SDL_gamecontroller.c.

2250 {
2251  if (!gamecontroller)
2252  return SDL_FALSE;
2253 
2254  return SDL_JoystickGetAttached(gamecontroller->joystick);
2255 }
#define SDL_JoystickGetAttached
@ SDL_FALSE
Definition: SDL_stdinc.h:169

References gamecontroller, SDL_FALSE, and SDL_JoystickGetAttached.

◆ SDL_GameControllerGetAxis()

Sint16 SDL_GameControllerGetAxis ( SDL_GameController *  gamecontroller,
SDL_GameControllerAxis  axis 
)

Get the current state of an axis control on a game controller.

The state is a value ranging from -32768 to 32767 (except for the triggers, which range from 0 to 32767).

The axis indices start at index 0.

Definition at line 1910 of file SDL_gamecontroller.c.

1911 {
1912  int i;
1913 
1914  if (!gamecontroller)
1915  return 0;
1916 
1917  for (i = 0; i < gamecontroller->num_bindings; ++i) {
1918  SDL_ExtendedGameControllerBind *binding = &gamecontroller->bindings[i];
1919  if (binding->outputType == SDL_CONTROLLER_BINDTYPE_AXIS && binding->output.axis.axis == axis) {
1920  int value = 0;
1921  SDL_bool valid_input_range;
1922  SDL_bool valid_output_range;
1923 
1924  if (binding->inputType == SDL_CONTROLLER_BINDTYPE_AXIS) {
1925  value = SDL_JoystickGetAxis(gamecontroller->joystick, binding->input.axis.axis);
1926  if (binding->input.axis.axis_min < binding->input.axis.axis_max) {
1927  valid_input_range = (value >= binding->input.axis.axis_min && value <= binding->input.axis.axis_max);
1928  } else {
1929  valid_input_range = (value >= binding->input.axis.axis_max && value <= binding->input.axis.axis_min);
1930  }
1931  if (valid_input_range) {
1932  if (binding->input.axis.axis_min != binding->output.axis.axis_min || binding->input.axis.axis_max != binding->output.axis.axis_max) {
1933  float normalized_value = (float)(value - binding->input.axis.axis_min) / (binding->input.axis.axis_max - binding->input.axis.axis_min);
1934  value = binding->output.axis.axis_min + (int)(normalized_value * (binding->output.axis.axis_max - binding->output.axis.axis_min));
1935  }
1936  } else {
1937  value = 0;
1938  }
1939  } else if (binding->inputType == SDL_CONTROLLER_BINDTYPE_BUTTON) {
1940  value = SDL_JoystickGetButton(gamecontroller->joystick, binding->input.button);
1941  if (value == SDL_PRESSED) {
1942  value = binding->output.axis.axis_max;
1943  }
1944  } else if (binding->inputType == SDL_CONTROLLER_BINDTYPE_HAT) {
1945  int hat_mask = SDL_JoystickGetHat(gamecontroller->joystick, binding->input.hat.hat);
1946  if (hat_mask & binding->input.hat.hat_mask) {
1947  value = binding->output.axis.axis_max;
1948  }
1949  }
1950 
1951  if (binding->output.axis.axis_min < binding->output.axis.axis_max) {
1952  valid_output_range = (value >= binding->output.axis.axis_min && value <= binding->output.axis.axis_max);
1953  } else {
1954  valid_output_range = (value >= binding->output.axis.axis_max && value <= binding->output.axis.axis_min);
1955  }
1956  /* If the value is zero, there might be another binding that makes it non-zero */
1957  if (value != 0 && valid_output_range) {
1958  return (Sint16)value;
1959  }
1960  }
1961  }
1962  return 0;
1963 }
#define SDL_JoystickGetAxis
#define SDL_JoystickGetHat
#define SDL_JoystickGetButton
#define SDL_PRESSED
Definition: SDL_events.h:50
GLsizei const GLfloat * value
int16_t Sint16
Definition: SDL_stdinc.h:191
SDL_bool
Definition: SDL_stdinc.h:168
union SDL_ExtendedGameControllerBind::@32 input
SDL_GameControllerBindType outputType
SDL_GameControllerBindType inputType
union SDL_ExtendedGameControllerBind::@33 output
SDL_Texture * axis
typedef int(__stdcall *FARPROC)()

References SDL_ExtendedGameControllerBind::axis, axis, SDL_ExtendedGameControllerBind::button, gamecontroller, SDL_ExtendedGameControllerBind::hat, i, SDL_ExtendedGameControllerBind::input, SDL_ExtendedGameControllerBind::inputType, int(), SDL_ExtendedGameControllerBind::output, SDL_ExtendedGameControllerBind::outputType, SDL_CONTROLLER_BINDTYPE_AXIS, SDL_CONTROLLER_BINDTYPE_BUTTON, SDL_CONTROLLER_BINDTYPE_HAT, SDL_JoystickGetAxis, SDL_JoystickGetButton, SDL_JoystickGetHat, and SDL_PRESSED.

Referenced by RecenterGameController().

◆ SDL_GameControllerGetAxisFromString()

SDL_GameControllerAxis SDL_GameControllerGetAxisFromString ( const char *  pchString)

turn this string into a axis mapping

Definition at line 687 of file SDL_gamecontroller.c.

688 {
689  int entry;
690 
691  if (pchString && (*pchString == '+' || *pchString == '-')) {
692  ++pchString;
693  }
694 
695  if (!pchString || !pchString[0]) {
697  }
698 
699  for (entry = 0; map_StringForControllerAxis[entry]; ++entry) {
700  if (!SDL_strcasecmp(pchString, map_StringForControllerAxis[entry]))
701  return (SDL_GameControllerAxis) entry;
702  }
704 }
#define SDL_strcasecmp
static const char * map_StringForControllerAxis[]

References map_StringForControllerAxis, SDL_CONTROLLER_AXIS_INVALID, and SDL_strcasecmp.

Referenced by SDL_PrivateGameControllerParseElement().

◆ SDL_GameControllerGetBindForAxis()

SDL_GameControllerButtonBind SDL_GameControllerGetBindForAxis ( SDL_GameController *  gamecontroller,
SDL_GameControllerAxis  axis 
)

Get the SDL joystick layer binding for this controller button mapping

Definition at line 2308 of file SDL_gamecontroller.c.

2309 {
2310  int i;
2312  SDL_zero(bind);
2313 
2315  return bind;
2316 
2317  for (i = 0; i < gamecontroller->num_bindings; ++i) {
2318  SDL_ExtendedGameControllerBind *binding = &gamecontroller->bindings[i];
2319  if (binding->outputType == SDL_CONTROLLER_BINDTYPE_AXIS && binding->output.axis.axis == axis) {
2320  bind.bindType = binding->inputType;
2321  if (binding->inputType == SDL_CONTROLLER_BINDTYPE_AXIS) {
2322  /* FIXME: There might be multiple axes bound now that we have axis ranges... */
2323  bind.value.axis = binding->input.axis.axis;
2324  } else if (binding->inputType == SDL_CONTROLLER_BINDTYPE_BUTTON) {
2325  bind.value.button = binding->input.button;
2326  } else if (binding->inputType == SDL_CONTROLLER_BINDTYPE_HAT) {
2327  bind.value.hat.hat = binding->input.hat.hat;
2328  bind.value.hat.hat_mask = binding->input.hat.hat_mask;
2329  }
2330  break;
2331  }
2332  }
2333  return bind;
2334 }
#define SDL_zero(x)
Definition: SDL_stdinc.h:426
SDL_GameControllerBindType bindType
union SDL_GameControllerButtonBind::@0 value

References SDL_GameControllerButtonBind::axis, SDL_ExtendedGameControllerBind::axis, axis, SDL_GameControllerButtonBind::bindType, SDL_GameControllerButtonBind::button, SDL_ExtendedGameControllerBind::button, gamecontroller, SDL_GameControllerButtonBind::hat, SDL_ExtendedGameControllerBind::hat, i, SDL_ExtendedGameControllerBind::input, SDL_ExtendedGameControllerBind::inputType, SDL_ExtendedGameControllerBind::output, SDL_ExtendedGameControllerBind::outputType, SDL_CONTROLLER_AXIS_INVALID, SDL_CONTROLLER_BINDTYPE_AXIS, SDL_CONTROLLER_BINDTYPE_BUTTON, SDL_CONTROLLER_BINDTYPE_HAT, SDL_zero, and SDL_GameControllerButtonBind::value.

Referenced by SDL_GameControllerHasAxis().

◆ SDL_GameControllerGetBindForButton()

SDL_GameControllerButtonBind SDL_GameControllerGetBindForButton ( SDL_GameController *  gamecontroller,
SDL_GameControllerButton  button 
)

Get the SDL joystick layer binding for this controller button mapping

Definition at line 2340 of file SDL_gamecontroller.c.

2341 {
2342  int i;
2344  SDL_zero(bind);
2345 
2347  return bind;
2348 
2349  for (i = 0; i < gamecontroller->num_bindings; ++i) {
2350  SDL_ExtendedGameControllerBind *binding = &gamecontroller->bindings[i];
2351  if (binding->outputType == SDL_CONTROLLER_BINDTYPE_BUTTON && binding->output.button == button) {
2352  bind.bindType = binding->inputType;
2353  if (binding->inputType == SDL_CONTROLLER_BINDTYPE_AXIS) {
2354  bind.value.axis = binding->input.axis.axis;
2355  } else if (binding->inputType == SDL_CONTROLLER_BINDTYPE_BUTTON) {
2356  bind.value.button = binding->input.button;
2357  } else if (binding->inputType == SDL_CONTROLLER_BINDTYPE_HAT) {
2358  bind.value.hat.hat = binding->input.hat.hat;
2359  bind.value.hat.hat_mask = binding->input.hat.hat_mask;
2360  }
2361  break;
2362  }
2363  }
2364  return bind;
2365 }
SDL_Texture * button

References SDL_GameControllerButtonBind::axis, SDL_ExtendedGameControllerBind::axis, SDL_GameControllerButtonBind::bindType, SDL_GameControllerButtonBind::button, SDL_ExtendedGameControllerBind::button, button, gamecontroller, SDL_GameControllerButtonBind::hat, SDL_ExtendedGameControllerBind::hat, i, SDL_ExtendedGameControllerBind::input, SDL_ExtendedGameControllerBind::inputType, SDL_ExtendedGameControllerBind::output, SDL_ExtendedGameControllerBind::outputType, SDL_CONTROLLER_BINDTYPE_AXIS, SDL_CONTROLLER_BINDTYPE_BUTTON, SDL_CONTROLLER_BINDTYPE_HAT, SDL_CONTROLLER_BUTTON_INVALID, SDL_zero, and SDL_GameControllerButtonBind::value.

Referenced by SDL_GameControllerHasButton().

◆ SDL_GameControllerGetButton()

Uint8 SDL_GameControllerGetButton ( SDL_GameController *  gamecontroller,
SDL_GameControllerButton  button 
)

Get the current state of a button on a game controller.

The button indices start at index 0.

Definition at line 1979 of file SDL_gamecontroller.c.

1980 {
1981  int i;
1982 
1983  if (!gamecontroller)
1984  return 0;
1985 
1986  for (i = 0; i < gamecontroller->num_bindings; ++i) {
1987  SDL_ExtendedGameControllerBind *binding = &gamecontroller->bindings[i];
1988  if (binding->outputType == SDL_CONTROLLER_BINDTYPE_BUTTON && binding->output.button == button) {
1989  if (binding->inputType == SDL_CONTROLLER_BINDTYPE_AXIS) {
1990  SDL_bool valid_input_range;
1991 
1992  int value = SDL_JoystickGetAxis(gamecontroller->joystick, binding->input.axis.axis);
1993  int threshold = binding->input.axis.axis_min + (binding->input.axis.axis_max - binding->input.axis.axis_min) / 2;
1994  if (binding->input.axis.axis_min < binding->input.axis.axis_max) {
1995  valid_input_range = (value >= binding->input.axis.axis_min && value <= binding->input.axis.axis_max);
1996  if (valid_input_range) {
1997  return (value >= threshold) ? SDL_PRESSED : SDL_RELEASED;
1998  }
1999  } else {
2000  valid_input_range = (value >= binding->input.axis.axis_max && value <= binding->input.axis.axis_min);
2001  if (valid_input_range) {
2002  return (value <= threshold) ? SDL_PRESSED : SDL_RELEASED;
2003  }
2004  }
2005  } else if (binding->inputType == SDL_CONTROLLER_BINDTYPE_BUTTON) {
2006  return SDL_JoystickGetButton(gamecontroller->joystick, binding->input.button);
2007  } else if (binding->inputType == SDL_CONTROLLER_BINDTYPE_HAT) {
2008  int hat_mask = SDL_JoystickGetHat(gamecontroller->joystick, binding->input.hat.hat);
2009  return (hat_mask & binding->input.hat.hat_mask) ? SDL_PRESSED : SDL_RELEASED;
2010  }
2011  }
2012  }
2013  return SDL_RELEASED;
2014 }
#define SDL_RELEASED
Definition: SDL_events.h:49

References SDL_ExtendedGameControllerBind::axis, SDL_ExtendedGameControllerBind::button, button, gamecontroller, SDL_ExtendedGameControllerBind::hat, i, SDL_ExtendedGameControllerBind::input, SDL_ExtendedGameControllerBind::inputType, SDL_ExtendedGameControllerBind::output, SDL_ExtendedGameControllerBind::outputType, SDL_CONTROLLER_BINDTYPE_AXIS, SDL_CONTROLLER_BINDTYPE_BUTTON, SDL_CONTROLLER_BINDTYPE_HAT, SDL_JoystickGetAxis, SDL_JoystickGetButton, SDL_JoystickGetHat, SDL_PRESSED, and SDL_RELEASED.

Referenced by RecenterGameController().

◆ SDL_GameControllerGetButtonFromString()

SDL_GameControllerButton SDL_GameControllerGetButtonFromString ( const char *  pchString)

turn this string into a button mapping

Definition at line 745 of file SDL_gamecontroller.c.

746 {
747  int entry;
748  if (!pchString || !pchString[0])
750 
751  for (entry = 0; map_StringForControllerButton[entry]; ++entry) {
752  if (SDL_strcasecmp(pchString, map_StringForControllerButton[entry]) == 0)
753  return (SDL_GameControllerButton) entry;
754  }
756 }
static const char * map_StringForControllerButton[]

References map_StringForControllerButton, SDL_CONTROLLER_BUTTON_INVALID, and SDL_strcasecmp.

Referenced by SDL_PrivateGameControllerParseElement().

◆ SDL_GameControllerGetJoystick()

◆ SDL_GameControllerGetNumTouchpadFingers()

int SDL_GameControllerGetNumTouchpadFingers ( SDL_GameController *  gamecontroller,
int  touchpad 
)

Get the number of supported simultaneous fingers on a touchpad on a game controller.

Definition at line 2033 of file SDL_gamecontroller.c.

2034 {
2036 
2037  if (joystick && touchpad >= 0 && touchpad < joystick->ntouchpads) {
2038  return joystick->touchpads[touchpad].nfingers;
2039  }
2040  return 0;
2041 }
SDL_Joystick * SDL_GameControllerGetJoystick(SDL_GameController *gamecontroller)

References gamecontroller, joystick, and SDL_GameControllerGetJoystick().

◆ SDL_GameControllerGetNumTouchpads()

int SDL_GameControllerGetNumTouchpads ( SDL_GameController *  gamecontroller)

Get the number of touchpads on a game controller.

Definition at line 2020 of file SDL_gamecontroller.c.

2021 {
2023 
2024  if (joystick) {
2025  return joystick->ntouchpads;
2026  }
2027  return 0;
2028 }

References gamecontroller, joystick, and SDL_GameControllerGetJoystick().

◆ SDL_GameControllerGetPlayerIndex()

int SDL_GameControllerGetPlayerIndex ( SDL_GameController *  gamecontroller)

Get the player index of an opened game controller, or -1 if it's not available

For XInput controllers this returns the XInput user index.

Definition at line 2206 of file SDL_gamecontroller.c.

2207 {
2209 }
#define SDL_JoystickGetPlayerIndex

References gamecontroller, SDL_GameControllerGetJoystick(), and SDL_JoystickGetPlayerIndex.

◆ SDL_GameControllerGetProduct()

Uint16 SDL_GameControllerGetProduct ( SDL_GameController *  gamecontroller)

Get the USB product ID of an opened controller, if available. If the product ID isn't available this function returns 0.

Definition at line 2227 of file SDL_gamecontroller.c.

2228 {
2230 }
#define SDL_JoystickGetProduct

References gamecontroller, SDL_GameControllerGetJoystick(), and SDL_JoystickGetProduct.

◆ SDL_GameControllerGetProductVersion()

Uint16 SDL_GameControllerGetProductVersion ( SDL_GameController *  gamecontroller)

Get the product version of an opened controller, if available. If the product version isn't available this function returns 0.

Definition at line 2233 of file SDL_gamecontroller.c.

2234 {
2236 }
#define SDL_JoystickGetProductVersion

References gamecontroller, SDL_GameControllerGetJoystick(), and SDL_JoystickGetProductVersion.

◆ SDL_GameControllerGetSensorData()

int SDL_GameControllerGetSensorData ( SDL_GameController *  gamecontroller,
SDL_SensorType  type,
float *  data,
int  num_values 
)

Get the current state of a game controller sensor.

The number of values and interpretation of the data is sensor dependent. See SDL_sensor.h for the details for each type of sensor.

Parameters
gamecontrollerThe controller to query
typeThe type of sensor to query
dataA pointer filled with the current sensor state
num_valuesThe number of values to write to data
Returns
0 or -1 if an error occurred.

Definition at line 2165 of file SDL_gamecontroller.c.

2166 {
2168  int i;
2169 
2170  if (!joystick) {
2171  return SDL_InvalidParamError("gamecontroller");
2172  }
2173 
2174  for (i = 0; i < joystick->nsensors; ++i) {
2175  SDL_JoystickSensorInfo *sensor = &joystick->sensors[i];
2176 
2177  if (sensor->type == type) {
2178  num_values = SDL_min(num_values, SDL_arraysize(sensor->data));
2179  SDL_memcpy(data, sensor->data, num_values*sizeof(*data));
2180  return 0;
2181  }
2182  }
2183  return SDL_Unsupported();
2184 }
#define SDL_memcpy
#define SDL_Unsupported()
Definition: SDL_error.h:89
#define SDL_InvalidParamError(param)
Definition: SDL_error.h:90
GLint GLenum GLsizei GLsizei GLsizei GLint GLsizei const GLvoid * data
Definition: SDL_opengl.h:1974
GLuint GLuint GLsizei GLenum type
Definition: SDL_opengl.h:1571
#define SDL_min(x, y)
Definition: SDL_stdinc.h:412

References SDL_JoystickSensorInfo::data, gamecontroller, i, joystick, SDL_arraysize, SDL_GameControllerGetJoystick(), SDL_InvalidParamError, SDL_memcpy, SDL_min, SDL_Unsupported, and SDL_JoystickSensorInfo::type.

◆ SDL_GameControllerGetSerial()

const char* SDL_GameControllerGetSerial ( SDL_GameController *  gamecontroller)

Get the serial number of an opened controller, if available.

Returns the serial number of the controller, or NULL if it is not available.

Definition at line 2239 of file SDL_gamecontroller.c.

2240 {
2242 }
#define SDL_JoystickGetSerial

References gamecontroller, SDL_GameControllerGetJoystick(), and SDL_JoystickGetSerial.

◆ SDL_GameControllerGetStringForAxis()

const char* SDL_GameControllerGetStringForAxis ( SDL_GameControllerAxis  axis)

turn this axis enum into a string mapping

Definition at line 709 of file SDL_gamecontroller.c.

710 {
713  }
714  return NULL;
715 }

References axis, map_StringForControllerAxis, NULL, SDL_CONTROLLER_AXIS_INVALID, and SDL_CONTROLLER_AXIS_MAX.

◆ SDL_GameControllerGetStringForButton()

const char* SDL_GameControllerGetStringForButton ( SDL_GameControllerButton  button)

turn this button enum into a string mapping

Definition at line 761 of file SDL_gamecontroller.c.

762 {
765  }
766  return NULL;
767 }

References axis, map_StringForControllerButton, NULL, SDL_CONTROLLER_BUTTON_INVALID, and SDL_CONTROLLER_BUTTON_MAX.

◆ SDL_GameControllerGetTouchpadFinger()

int SDL_GameControllerGetTouchpadFinger ( SDL_GameController *  gamecontroller,
int  touchpad,
int  finger,
Uint8 state,
float *  x,
float *  y,
float *  pressure 
)

Get the current state of a finger on a touchpad on a game controller.

Definition at line 2047 of file SDL_gamecontroller.c.

2048 {
2050 
2051  if (joystick ) {
2052  if (touchpad >= 0 && touchpad < joystick->ntouchpads) {
2053  SDL_JoystickTouchpadInfo *touchpad_info = &joystick->touchpads[touchpad];
2054  if (finger >= 0 && finger < touchpad_info->nfingers) {
2055  SDL_JoystickTouchpadFingerInfo *info = &touchpad_info->fingers[finger];
2056 
2057  if (state) {
2058  *state = info->state;
2059  }
2060  if (x) {
2061  *x = info->x;
2062  }
2063  if (y) {
2064  *y = info->y;
2065  }
2066  if (pressure) {
2067  *pressure = info->pressure;
2068  }
2069  return 0;
2070  } else {
2071  return SDL_InvalidParamError("finger");
2072  }
2073  } else {
2074  return SDL_InvalidParamError("touchpad");
2075  }
2076  } else {
2077  return SDL_InvalidParamError("gamecontroller");
2078  }
2079 }
GLint GLint GLint GLint GLint GLint y
Definition: SDL_opengl.h:1574
GLint GLint GLint GLint GLint x
Definition: SDL_opengl.h:1574
SDL_JoystickTouchpadFingerInfo * fingers

References SDL_JoystickTouchpadInfo::fingers, gamecontroller, joystick, SDL_JoystickTouchpadFingerInfo::pressure, SDL_GameControllerGetJoystick(), SDL_InvalidParamError, SDL_JoystickTouchpadFingerInfo::state, state, SDL_JoystickTouchpadFingerInfo::x, and SDL_JoystickTouchpadFingerInfo::y.

◆ SDL_GameControllerGetType()

SDL_GameControllerType SDL_GameControllerGetType ( SDL_GameController *  gamecontroller)

Return the type of this currently opened controller

Definition at line 2200 of file SDL_gamecontroller.c.

2201 {
2203 }
#define SDL_JoystickName
#define SDL_JoystickGetGUID
SDL_GameControllerType SDL_GetJoystickGameControllerTypeFromGUID(SDL_JoystickGUID guid, const char *name)

References gamecontroller, SDL_GameControllerGetJoystick(), SDL_GetJoystickGameControllerTypeFromGUID(), SDL_JoystickGetGUID, and SDL_JoystickName.

◆ SDL_GameControllerGetVendor()

Uint16 SDL_GameControllerGetVendor ( SDL_GameController *  gamecontroller)

Get the USB vendor ID of an opened controller, if available. If the vendor ID isn't available this function returns 0.

Definition at line 2221 of file SDL_gamecontroller.c.

2222 {
2224 }
#define SDL_JoystickGetVendor

References gamecontroller, SDL_GameControllerGetJoystick(), and SDL_JoystickGetVendor.

◆ SDL_GameControllerHasAxis()

SDL_bool SDL_GameControllerHasAxis ( SDL_GameController *  gamecontroller,
SDL_GameControllerAxis  axis 
)

Return whether a game controller has a given axis

Definition at line 1900 of file SDL_gamecontroller.c.

1901 {
1904 }
SDL_GameControllerButtonBind SDL_GameControllerGetBindForAxis(SDL_GameController *gamecontroller, SDL_GameControllerAxis axis)
@ SDL_TRUE
Definition: SDL_stdinc.h:170

References axis, SDL_GameControllerButtonBind::bindType, gamecontroller, SDL_CONTROLLER_BINDTYPE_NONE, SDL_FALSE, SDL_GameControllerGetBindForAxis(), and SDL_TRUE.

◆ SDL_GameControllerHasButton()

SDL_bool SDL_GameControllerHasButton ( SDL_GameController *  gamecontroller,
SDL_GameControllerButton  button 
)

Return whether a game controller has a given button

Definition at line 1969 of file SDL_gamecontroller.c.

1970 {
1973 }
SDL_GameControllerButtonBind SDL_GameControllerGetBindForButton(SDL_GameController *gamecontroller, SDL_GameControllerButton button)

References SDL_GameControllerButtonBind::bindType, button, gamecontroller, SDL_CONTROLLER_BINDTYPE_NONE, SDL_FALSE, SDL_GameControllerGetBindForButton(), and SDL_TRUE.

◆ SDL_GameControllerHasLED()

SDL_bool SDL_GameControllerHasLED ( SDL_GameController *  gamecontroller)

Return whether a controller has an LED

Parameters
gamecontrollerThe controller to query
Returns
SDL_TRUE, or SDL_FALSE if this controller does not have a modifiable LED

Definition at line 2381 of file SDL_gamecontroller.c.

2382 {
2384 }
#define SDL_JoystickHasLED

References gamecontroller, SDL_GameControllerGetJoystick(), and SDL_JoystickHasLED.

◆ SDL_GameControllerHasSensor()

SDL_bool SDL_GameControllerHasSensor ( SDL_GameController *  gamecontroller,
SDL_SensorType  type 
)

Return whether a game controller has a particular sensor.

Parameters
gamecontrollerThe controller to query
typeThe type of sensor to query
Returns
SDL_TRUE if the sensor exists, SDL_FALSE otherwise.

Return whether a game controller has a particular sensor.

Definition at line 2085 of file SDL_gamecontroller.c.

2086 {
2088  int i;
2089 
2090  if (joystick) {
2091  for (i = 0; i < joystick->nsensors; ++i) {
2092  if (joystick->sensors[i].type == type) {
2093  return SDL_TRUE;
2094  }
2095  }
2096  }
2097  return SDL_FALSE;
2098 }

References gamecontroller, i, joystick, SDL_FALSE, SDL_GameControllerGetJoystick(), and SDL_TRUE.

◆ SDL_GameControllerIsSensorEnabled()

SDL_bool SDL_GameControllerIsSensorEnabled ( SDL_GameController *  gamecontroller,
SDL_SensorType  type 
)

Query whether sensor data reporting is enabled for a game controller

Parameters
gamecontrollerThe controller to query
typeThe type of sensor to query
Returns
SDL_TRUE if the sensor is enabled, SDL_FALSE otherwise.

Definition at line 2146 of file SDL_gamecontroller.c.

2147 {
2149  int i;
2150 
2151  if (joystick) {
2152  for (i = 0; i < joystick->nsensors; ++i) {
2153  if (joystick->sensors[i].type == type) {
2154  return joystick->sensors[i].enabled;
2155  }
2156  }
2157  }
2158  return SDL_FALSE;
2159 }

References gamecontroller, i, joystick, SDL_FALSE, and SDL_GameControllerGetJoystick().

◆ SDL_GameControllerMapping()

char* SDL_GameControllerMapping ( SDL_GameController *  gamecontroller)

Get a mapping string for an open GameController

Returns
the mapping string. Must be freed with SDL_free(). Returns NULL if no mapping is available

Definition at line 1539 of file SDL_gamecontroller.c.

1540 {
1541  if (!gamecontroller) {
1542  return NULL;
1543  }
1544 
1545  return SDL_GameControllerMappingForGUID(gamecontroller->joystick->guid);
1546 }
char * SDL_GameControllerMappingForGUID(SDL_JoystickGUID guid)

References gamecontroller, NULL, and SDL_GameControllerMappingForGUID().

◆ SDL_GameControllerMappingForDeviceIndex()

char* SDL_GameControllerMappingForDeviceIndex ( int  joystick_index)

Get the mapping of a game controller. This can be called before any controllers are opened.

Returns
the mapping string. Must be freed with SDL_free(). Returns NULL if no mapping is available

Get the mapping of a game controller. This can be called before any controllers are opened. If no mapping can be found, this function returns NULL.

Definition at line 1684 of file SDL_gamecontroller.c.

1685 {
1686  char *pMappingString = NULL;
1688 
1690  mapping = SDL_PrivateGetControllerMapping(joystick_index);
1691  if (mapping) {
1692  SDL_JoystickGUID guid;
1693  char pchGUID[33];
1694  size_t needed;
1695  guid = SDL_JoystickGetDeviceGUID(joystick_index);
1696  SDL_JoystickGetGUIDString(guid, pchGUID, sizeof(pchGUID));
1697  /* allocate enough memory for GUID + ',' + name + ',' + mapping + \0 */
1698  needed = SDL_strlen(pchGUID) + 1 + SDL_strlen(mapping->name) + 1 + SDL_strlen(mapping->mapping) + 1;
1699  pMappingString = SDL_malloc(needed);
1700  if (!pMappingString) {
1701  SDL_OutOfMemory();
1703  return NULL;
1704  }
1705  SDL_snprintf(pMappingString, needed, "%s,%s,%s", pchGUID, mapping->name, mapping->mapping);
1706  }
1708  return pMappingString;
1709 }
#define SDL_JoystickGetGUIDString
#define SDL_JoystickGetDeviceGUID
#define SDL_snprintf
#define SDL_OutOfMemory()
Definition: SDL_error.h:88
static ControllerMapping_t * SDL_PrivateGetControllerMapping(int device_index)
GLenum GLenum GLenum GLenum mapping

References NULL, SDL_JoystickGetDeviceGUID, SDL_JoystickGetGUIDString, SDL_LockJoysticks, SDL_malloc, SDL_OutOfMemory, SDL_PrivateGetControllerMapping(), SDL_snprintf, SDL_strlen, and SDL_UnlockJoysticks.

◆ SDL_GameControllerMappingForGUID()

char* SDL_GameControllerMappingForGUID ( SDL_JoystickGUID  guid)

Get a mapping string for a GUID

Returns
the mapping string. Must be freed with SDL_free(). Returns NULL if no mapping is available

Definition at line 1515 of file SDL_gamecontroller.c.

1516 {
1517  char *pMappingString = NULL;
1519  if (mapping) {
1520  char pchGUID[33];
1521  size_t needed;
1522  SDL_JoystickGetGUIDString(guid, pchGUID, sizeof(pchGUID));
1523  /* allocate enough memory for GUID + ',' + name + ',' + mapping + \0 */
1524  needed = SDL_strlen(pchGUID) + 1 + SDL_strlen(mapping->name) + 1 + SDL_strlen(mapping->mapping) + 1;
1525  pMappingString = SDL_malloc(needed);
1526  if (!pMappingString) {
1527  SDL_OutOfMemory();
1528  return NULL;
1529  }
1530  SDL_snprintf(pMappingString, needed, "%s,%s,%s", pchGUID, mapping->name, mapping->mapping);
1531  }
1532  return pMappingString;
1533 }
static ControllerMapping_t * SDL_PrivateGetControllerMappingForGUID(SDL_JoystickGUID guid, SDL_bool exact_match)

References NULL, SDL_FALSE, SDL_JoystickGetGUIDString, SDL_malloc, SDL_OutOfMemory, SDL_PrivateGetControllerMappingForGUID(), SDL_snprintf, and SDL_strlen.

Referenced by SDL_GameControllerMapping().

◆ SDL_GameControllerMappingForIndex()

char* SDL_GameControllerMappingForIndex ( int  mapping_index)

Get the mapping at a particular index.

Returns
the mapping string. Must be freed with SDL_free(). Returns NULL if the index is out of range.

Definition at line 1482 of file SDL_gamecontroller.c.

1483 {
1485 
1487  if (SDL_memcmp(&mapping->guid, &s_zeroGUID, sizeof(mapping->guid)) == 0) {
1488  continue;
1489  }
1490  if (mapping_index == 0) {
1491  char *pMappingString;
1492  char pchGUID[33];
1493  size_t needed;
1494 
1495  SDL_JoystickGetGUIDString(mapping->guid, pchGUID, sizeof(pchGUID));
1496  /* allocate enough memory for GUID + ',' + name + ',' + mapping + \0 */
1497  needed = SDL_strlen(pchGUID) + 1 + SDL_strlen(mapping->name) + 1 + SDL_strlen(mapping->mapping) + 1;
1498  pMappingString = SDL_malloc(needed);
1499  if (!pMappingString) {
1500  SDL_OutOfMemory();
1501  return NULL;
1502  }
1503  SDL_snprintf(pMappingString, needed, "%s,%s,%s", pchGUID, mapping->name, mapping->mapping);
1504  return pMappingString;
1505  }
1506  --mapping_index;
1507  }
1508  return NULL;
1509 }
#define SDL_memcmp
static ControllerMapping_t * s_pSupportedControllers
static SDL_JoystickGUID s_zeroGUID

References NULL, s_pSupportedControllers, s_zeroGUID, SDL_JoystickGetGUIDString, SDL_malloc, SDL_memcmp, SDL_OutOfMemory, SDL_snprintf, and SDL_strlen.

◆ SDL_GameControllerName()

const char* SDL_GameControllerName ( SDL_GameController *  gamecontroller)

Return the name for this currently opened controller

Definition at line 2187 of file SDL_gamecontroller.c.

2188 {
2189  if (!gamecontroller)
2190  return NULL;
2191 
2192  if (SDL_strcmp(gamecontroller->name, "*") == 0) {
2194  } else {
2195  return gamecontroller->name;
2196  }
2197 }
#define SDL_strcmp

References gamecontroller, NULL, SDL_GameControllerGetJoystick(), SDL_JoystickName, and SDL_strcmp.

◆ SDL_GameControllerNameForIndex()

const char* SDL_GameControllerNameForIndex ( int  joystick_index)

Get the implementation dependent name of a game controller. This can be called before any controllers are opened. If no name can be found, this function returns NULL.

Definition at line 1654 of file SDL_gamecontroller.c.

1655 {
1656  ControllerMapping_t *pSupportedController = SDL_PrivateGetControllerMapping(device_index);
1657  if (pSupportedController) {
1658  if (SDL_strcmp(pSupportedController->name, "*") == 0) {
1659  return SDL_JoystickNameForIndex(device_index);
1660  } else {
1661  return pSupportedController->name;
1662  }
1663  }
1664  return NULL;
1665 }
#define SDL_JoystickNameForIndex

References ControllerMapping_t::name, NULL, SDL_JoystickNameForIndex, SDL_PrivateGetControllerMapping(), and SDL_strcmp.

◆ SDL_GameControllerNumMappings()

int SDL_GameControllerNumMappings ( void  )

Get the number of mappings installed

Returns
the number of mappings

Definition at line 1464 of file SDL_gamecontroller.c.

1465 {
1466  int num_mappings = 0;
1468 
1470  if (SDL_memcmp(&mapping->guid, &s_zeroGUID, sizeof(mapping->guid)) == 0) {
1471  continue;
1472  }
1473  ++num_mappings;
1474  }
1475  return num_mappings;
1476 }

References s_pSupportedControllers, s_zeroGUID, and SDL_memcmp.

◆ SDL_GameControllerOpen()

SDL_GameController* SDL_GameControllerOpen ( int  joystick_index)

Open a game controller for use. The index passed as an argument refers to the N'th game controller on the system. This index is not the value which will identify this controller in future controller events. The joystick's instance id (SDL_JoystickID) will be used there instead.

Returns
A controller identifier, or NULL if an error occurred.

Definition at line 1806 of file SDL_gamecontroller.c.

1807 {
1808  SDL_JoystickID instance_id;
1809  SDL_GameController *gamecontroller;
1810  SDL_GameController *gamecontrollerlist;
1811  ControllerMapping_t *pSupportedController = NULL;
1812 
1814 
1815  gamecontrollerlist = SDL_gamecontrollers;
1816  /* If the controller is already open, return it */
1817  instance_id = SDL_JoystickGetDeviceInstanceID(device_index);
1818  while (gamecontrollerlist) {
1819  if (instance_id == gamecontrollerlist->joystick->instance_id) {
1820  gamecontroller = gamecontrollerlist;
1821  ++gamecontroller->ref_count;
1823  return (gamecontroller);
1824  }
1825  gamecontrollerlist = gamecontrollerlist->next;
1826  }
1827 
1828  /* Find a controller mapping */
1829  pSupportedController = SDL_PrivateGetControllerMapping(device_index);
1830  if (!pSupportedController) {
1831  SDL_SetError("Couldn't find mapping for device (%d)", device_index);
1833  return NULL;
1834  }
1835 
1836  /* Create and initialize the controller */
1837  gamecontroller = (SDL_GameController *) SDL_calloc(1, sizeof(*gamecontroller));
1838  if (gamecontroller == NULL) {
1839  SDL_OutOfMemory();
1841  return NULL;
1842  }
1843 
1844  gamecontroller->joystick = SDL_JoystickOpen(device_index);
1845  if (!gamecontroller->joystick) {
1848  return NULL;
1849  }
1850 
1851  if (gamecontroller->joystick->naxes) {
1852  gamecontroller->last_match_axis = (SDL_ExtendedGameControllerBind **)SDL_calloc(gamecontroller->joystick->naxes, sizeof(*gamecontroller->last_match_axis));
1853  if (!gamecontroller->last_match_axis) {
1854  SDL_OutOfMemory();
1855  SDL_JoystickClose(gamecontroller->joystick);
1858  return NULL;
1859  }
1860  }
1861  if (gamecontroller->joystick->nhats) {
1862  gamecontroller->last_hat_mask = (Uint8 *)SDL_calloc(gamecontroller->joystick->nhats, sizeof(*gamecontroller->last_hat_mask));
1863  if (!gamecontroller->last_hat_mask) {
1864  SDL_OutOfMemory();
1865  SDL_JoystickClose(gamecontroller->joystick);
1866  SDL_free(gamecontroller->last_match_axis);
1869  return NULL;
1870  }
1871  }
1872 
1873  SDL_PrivateLoadButtonMapping(gamecontroller, pSupportedController->name, pSupportedController->mapping);
1874 
1875  /* Add the controller to list */
1876  ++gamecontroller->ref_count;
1877  /* Link the controller in the list */
1880 
1882 
1883  return (gamecontroller);
1884 }
#define SDL_JoystickGetDeviceInstanceID
#define SDL_JoystickOpen
#define SDL_calloc
static void SDL_PrivateLoadButtonMapping(SDL_GameController *gamecontroller, const char *pchName, const char *pchMapping)
Sint32 SDL_JoystickID
Definition: SDL_joystick.h:81
uint8_t Uint8
Definition: SDL_stdinc.h:185

References gamecontroller, ControllerMapping_t::mapping, ControllerMapping_t::name, NULL, SDL_calloc, SDL_free, SDL_gamecontrollers, SDL_JoystickClose, SDL_JoystickGetDeviceInstanceID, SDL_JoystickOpen, SDL_LockJoysticks, SDL_OutOfMemory, SDL_PrivateGetControllerMapping(), SDL_PrivateLoadButtonMapping(), SDL_SetError, and SDL_UnlockJoysticks.

◆ SDL_GameControllerRumble()

int SDL_GameControllerRumble ( SDL_GameController *  gamecontroller,
Uint16  low_frequency_rumble,
Uint16  high_frequency_rumble,
Uint32  duration_ms 
)

Start a rumble effect Each call to this function cancels any previous rumble effect, and calling it with 0 intensity stops any rumbling.

Parameters
gamecontrollerThe controller to vibrate
low_frequency_rumbleThe intensity of the low frequency (left) rumble motor, from 0 to 0xFFFF
high_frequency_rumbleThe intensity of the high frequency (right) rumble motor, from 0 to 0xFFFF
duration_msThe duration of the rumble effect, in milliseconds
Returns
0, or -1 if rumble isn't supported on this controller

Definition at line 2369 of file SDL_gamecontroller.c.

2370 {
2371  return SDL_JoystickRumble(SDL_GameControllerGetJoystick(gamecontroller), low_frequency_rumble, high_frequency_rumble, duration_ms);
2372 }
#define SDL_JoystickRumble

References gamecontroller, SDL_GameControllerGetJoystick(), and SDL_JoystickRumble.

◆ SDL_GameControllerRumbleTriggers()

int SDL_GameControllerRumbleTriggers ( SDL_GameController *  gamecontroller,
Uint16  left_rumble,
Uint16  right_rumble,
Uint32  duration_ms 
)

Start a rumble effect in the game controller's triggers Each call to this function cancels any previous trigger rumble effect, and calling it with 0 intensity stops any rumbling.

Parameters
gamecontrollerThe controller to vibrate
left_rumbleThe intensity of the left trigger rumble motor, from 0 to 0xFFFF
right_rumbleThe intensity of the right trigger rumble motor, from 0 to 0xFFFF
duration_msThe duration of the rumble effect, in milliseconds
Returns
0, or -1 if rumble isn't supported on this controller

Definition at line 2375 of file SDL_gamecontroller.c.

2376 {
2377  return SDL_JoystickRumbleTriggers(SDL_GameControllerGetJoystick(gamecontroller), left_rumble, right_rumble, duration_ms);
2378 }
#define SDL_JoystickRumbleTriggers

References gamecontroller, SDL_GameControllerGetJoystick(), and SDL_JoystickRumbleTriggers.

◆ SDL_GameControllerSetLED()

int SDL_GameControllerSetLED ( SDL_GameController *  gamecontroller,
Uint8  red,
Uint8  green,
Uint8  blue 
)

Update a controller's LED color.

Parameters
gamecontrollerThe controller to update
redThe intensity of the red LED
greenThe intensity of the green LED
blueThe intensity of the blue LED
Returns
0, or -1 if this controller does not have a modifiable LED

Definition at line 2387 of file SDL_gamecontroller.c.

2388 {
2390 }
#define SDL_JoystickSetLED
const GLubyte GLuint red
Definition: SDL_glfuncs.h:80
GLbyte GLbyte blue
GLbyte green

References gamecontroller, red, SDL_GameControllerGetJoystick(), and SDL_JoystickSetLED.

◆ SDL_GameControllerSetPlayerIndex()

void SDL_GameControllerSetPlayerIndex ( SDL_GameController *  gamecontroller,
int  player_index 
)

Set the player index of an opened game controller

Definition at line 2215 of file SDL_gamecontroller.c.

2216 {
2218 }
#define SDL_JoystickSetPlayerIndex

References gamecontroller, SDL_GameControllerGetJoystick(), and SDL_JoystickSetPlayerIndex.

◆ SDL_GameControllerSetSensorEnabled()

int SDL_GameControllerSetSensorEnabled ( SDL_GameController *  gamecontroller,
SDL_SensorType  type,
SDL_bool  enabled 
)

Set whether data reporting for a game controller sensor is enabled

Parameters
gamecontrollerThe controller to update
typeThe type of sensor to enable/disable
enabledWhether data reporting should be enabled
Returns
0 or -1 if an error occurred.

Definition at line 2103 of file SDL_gamecontroller.c.

2104 {
2106  int i;
2107 
2108  if (!joystick) {
2109  return SDL_InvalidParamError("gamecontroller");
2110  }
2111 
2112  for (i = 0; i < joystick->nsensors; ++i) {
2113  SDL_JoystickSensorInfo *sensor = &joystick->sensors[i];
2114 
2115  if (sensor->type == type) {
2116  if (sensor->enabled == enabled) {
2117  return 0;
2118  }
2119 
2120  if (enabled) {
2121  if (joystick->nsensors_enabled == 0) {
2122  if (joystick->driver->SetSensorsEnabled(joystick, SDL_TRUE) < 0) {
2123  return -1;
2124  }
2125  }
2126  ++joystick->nsensors_enabled;
2127  } else {
2128  if (joystick->nsensors_enabled == 1) {
2129  if (joystick->driver->SetSensorsEnabled(joystick, SDL_FALSE) < 0) {
2130  return -1;
2131  }
2132  }
2133  --joystick->nsensors_enabled;
2134  }
2135 
2136  sensor->enabled = enabled;
2137  return 0;
2138  }
2139  }
2140  return SDL_Unsupported();
2141 }
GLenum GLenum GLsizei const GLuint GLboolean enabled

References SDL_JoystickSensorInfo::enabled, gamecontroller, i, joystick, SDL_FALSE, SDL_GameControllerGetJoystick(), SDL_InvalidParamError, SDL_TRUE, SDL_Unsupported, and SDL_JoystickSensorInfo::type.

◆ SDL_GameControllerTypeForIndex()

SDL_GameControllerType SDL_GameControllerTypeForIndex ( int  joystick_index)

Get the type of a game controller. This can be called before any controllers are opened.

Get the type of a game controller.

Definition at line 1672 of file SDL_gamecontroller.c.

1673 {
1675 }

References SDL_GetJoystickGameControllerTypeFromGUID(), SDL_JoystickGetDeviceGUID, and SDL_JoystickNameForIndex.

◆ SDL_GameControllerUpdate()

void SDL_GameControllerUpdate ( void  )

Update the current state of the open game controllers.

This is called automatically by the event loop if any game controller events are enabled.

Definition at line 1890 of file SDL_gamecontroller.c.

1891 {
1892  /* Just for API completeness; the joystick API does all the work. */
1894 }
#define SDL_JoystickUpdate

References SDL_JoystickUpdate.

◆ SDL_IsGameController()

SDL_bool SDL_IsGameController ( int  joystick_index)

Is the joystick on this index supported by the game controller interface?

Definition at line 1729 of file SDL_gamecontroller.c.

1730 {
1731  ControllerMapping_t *pSupportedController = SDL_PrivateGetControllerMapping(device_index);
1732  if (pSupportedController) {
1733  return SDL_TRUE;
1734  }
1735  return SDL_FALSE;
1736 }

References SDL_FALSE, SDL_PrivateGetControllerMapping(), and SDL_TRUE.

Referenced by SDL_GameControllerEventWatcher(), and SDL_GameControllerInit().