SDL  2.0
SDL_joystick_c.h File Reference
#include "../SDL_internal.h"
#include "SDL_joystick.h"
+ Include dependency graph for SDL_joystick_c.h:
+ This graph shows which files directly or indirectly include this file:

Go to the source code of this file.

Functions

int SDL_JoystickInit (void)
 
void SDL_JoystickQuit (void)
 
int SDL_GameControllerInitMappings (void)
 
void SDL_GameControllerQuitMappings (void)
 
int SDL_GameControllerInit (void)
 
void SDL_GameControllerQuit (void)
 
void SDL_GetJoystickGUIDInfo (SDL_JoystickGUID guid, Uint16 *vendor, Uint16 *product, Uint16 *version)
 
SDL_bool SDL_IsGameControllerNameAndGUID (const char *name, SDL_JoystickGUID guid)
 
SDL_bool SDL_ShouldIgnoreGameController (const char *name, SDL_JoystickGUID guid)
 
void SDL_PrivateJoystickAdded (int device_index)
 
void SDL_PrivateJoystickRemoved (SDL_JoystickID device_instance)
 
int SDL_PrivateJoystickAxis (SDL_Joystick *joystick, Uint8 axis, Sint16 value)
 
int SDL_PrivateJoystickBall (SDL_Joystick *joystick, Uint8 ball, Sint16 xrel, Sint16 yrel)
 
int SDL_PrivateJoystickHat (SDL_Joystick *joystick, Uint8 hat, Uint8 value)
 
int SDL_PrivateJoystickButton (SDL_Joystick *joystick, Uint8 button, Uint8 state)
 
void SDL_PrivateJoystickBatteryLevel (SDL_Joystick *joystick, SDL_JoystickPowerLevel ePowerLevel)
 
int SDL_PrivateJoystickValid (SDL_Joystick *joystick)
 

Function Documentation

◆ SDL_GameControllerInit()

int SDL_GameControllerInit ( void  )

Definition at line 1237 of file SDL_gamecontroller.c.

References SDL_Event::cdevice, i, NULL, SDL_AddEventWatch, SDL_CONTROLLERDEVICEADDED, SDL_GameControllerEventWatcher(), SDL_IsGameController(), SDL_NumJoysticks, SDL_PushEvent, SDL_Event::type, and SDL_ControllerDeviceEvent::which.

Referenced by SDL_InitSubSystem().

1238 {
1239  int i;
1240 
1241  /* watch for joy events and fire controller ones if needed */
1243 
1244  /* Send added events for controllers currently attached */
1245  for (i = 0; i < SDL_NumJoysticks(); ++i) {
1246  if (SDL_IsGameController(i)) {
1247  SDL_Event deviceevent;
1248  deviceevent.type = SDL_CONTROLLERDEVICEADDED;
1249  deviceevent.cdevice.which = i;
1250  SDL_PushEvent(&deviceevent);
1251  }
1252  }
1253 
1254  return (0);
1255 }
static int SDL_GameControllerEventWatcher(void *userdata, SDL_Event *event)
SDL_ControllerDeviceEvent cdevice
Definition: SDL_events.h:543
#define SDL_NumJoysticks
#define SDL_PushEvent
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
SDL_bool SDL_IsGameController(int device_index)
#define NULL
Definition: begin_code.h:164
#define SDL_AddEventWatch
General event structure.
Definition: SDL_events.h:525
Uint32 type
Definition: SDL_events.h:527

◆ SDL_GameControllerInitMappings()

int SDL_GameControllerInitMappings ( void  )

Definition at line 1208 of file SDL_gamecontroller.c.

References i, NULL, s_ControllerMappings, SDL_AddHintCallback, SDL_CONTROLLER_MAPPING_PRIORITY_DEFAULT, SDL_GameControllerAddMappingsFromFile, SDL_GameControllerIgnoreDevicesChanged(), SDL_GameControllerIgnoreDevicesExceptChanged(), SDL_GameControllerLoadHints(), SDL_GetControllerMappingFilePath(), SDL_HINT_GAMECONTROLLER_IGNORE_DEVICES, SDL_HINT_GAMECONTROLLER_IGNORE_DEVICES_EXCEPT, and SDL_PrivateGameControllerAddMapping().

Referenced by SDL_JoystickInit().

1209 {
1210  char szControllerMapPath[1024];
1211  int i = 0;
1212  const char *pMappingString = NULL;
1213  pMappingString = s_ControllerMappings[i];
1214  while (pMappingString) {
1216 
1217  i++;
1218  pMappingString = s_ControllerMappings[i];
1219  }
1220 
1221  if (SDL_GetControllerMappingFilePath(szControllerMapPath, sizeof(szControllerMapPath))) {
1222  SDL_GameControllerAddMappingsFromFile(szControllerMapPath);
1223  }
1224 
1225  /* load in any user supplied config */
1227 
1232 
1233  return (0);
1234 }
static SDL_bool SDL_GetControllerMappingFilePath(char *path, size_t size)
static void SDL_GameControllerLoadHints()
static int SDL_PrivateGameControllerAddMapping(const char *mappingString, SDL_ControllerMappingPriority priority)
#define SDL_HINT_GAMECONTROLLER_IGNORE_DEVICES_EXCEPT
Definition: SDL_hints.h:453
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
#define NULL
Definition: begin_code.h:164
static void SDL_GameControllerIgnoreDevicesExceptChanged(void *userdata, const char *name, const char *oldValue, const char *hint)
static const char * s_ControllerMappings[]
#define SDL_AddHintCallback
#define SDL_GameControllerAddMappingsFromFile(file)
#define SDL_HINT_GAMECONTROLLER_IGNORE_DEVICES
Definition: SDL_hints.h:440
static void SDL_GameControllerIgnoreDevicesChanged(void *userdata, const char *name, const char *oldValue, const char *hint)

◆ SDL_GameControllerQuit()

void SDL_GameControllerQuit ( void  )

Definition at line 1733 of file SDL_gamecontroller.c.

References SDL_GameControllerClose(), SDL_gamecontrollers, SDL_LockJoysticks, and SDL_UnlockJoysticks.

Referenced by SDL_QuitSubSystem().

1734 {
1736  while (SDL_gamecontrollers) {
1737  SDL_gamecontrollers->ref_count = 1;
1739  }
1741 }
#define SDL_UnlockJoysticks
void SDL_GameControllerClose(SDL_GameController *gamecontroller)
static SDL_GameController * SDL_gamecontrollers
#define SDL_LockJoysticks

◆ SDL_GameControllerQuitMappings()

void SDL_GameControllerQuitMappings ( void  )

Definition at line 1744 of file SDL_gamecontroller.c.

References SDL_vidpid_list::entries, ControllerMapping_t::mapping, ControllerMapping_t::name, ControllerMapping_t::next, NULL, s_pSupportedControllers, SDL_DelEventWatch, SDL_DelHintCallback, SDL_free, SDL_GameControllerEventWatcher(), SDL_GameControllerIgnoreDevicesChanged(), SDL_GameControllerIgnoreDevicesExceptChanged(), SDL_HINT_GAMECONTROLLER_IGNORE_DEVICES, SDL_HINT_GAMECONTROLLER_IGNORE_DEVICES_EXCEPT, and SDL_zero.

Referenced by SDL_JoystickQuit().

1745 {
1746  ControllerMapping_t *pControllerMap;
1747 
1748  while (s_pSupportedControllers) {
1749  pControllerMap = s_pSupportedControllers;
1751  SDL_free(pControllerMap->name);
1752  SDL_free(pControllerMap->mapping);
1753  SDL_free(pControllerMap);
1754  }
1755 
1757 
1762 
1766  }
1770  }
1771 }
#define SDL_DelEventWatch
static int SDL_GameControllerEventWatcher(void *userdata, SDL_Event *event)
struct _ControllerMapping_t * next
static SDL_vidpid_list SDL_ignored_controllers
static ControllerMapping_t * s_pSupportedControllers
#define SDL_free
#define SDL_HINT_GAMECONTROLLER_IGNORE_DEVICES_EXCEPT
Definition: SDL_hints.h:453
#define SDL_zero(x)
Definition: SDL_stdinc.h:416
#define NULL
Definition: begin_code.h:164
static void SDL_GameControllerIgnoreDevicesExceptChanged(void *userdata, const char *name, const char *oldValue, const char *hint)
static SDL_vidpid_list SDL_allowed_controllers
#define SDL_DelHintCallback
#define SDL_HINT_GAMECONTROLLER_IGNORE_DEVICES
Definition: SDL_hints.h:440
static void SDL_GameControllerIgnoreDevicesChanged(void *userdata, const char *name, const char *oldValue, const char *hint)

◆ SDL_GetJoystickGUIDInfo()

void SDL_GetJoystickGUIDInfo ( SDL_JoystickGUID  guid,
Uint16 vendor,
Uint16 product,
Uint16 version 
)

Definition at line 933 of file SDL_joystick.c.

References SDL_JoystickGUID::data.

Referenced by SDL_GetJoystickGUIDType(), SDL_JoystickGetDeviceProduct(), SDL_JoystickGetDeviceProductVersion(), SDL_JoystickGetDeviceVendor(), SDL_JoystickGetProduct(), SDL_JoystickGetProductVersion(), SDL_JoystickGetVendor(), and SDL_ShouldIgnoreGameController().

934 {
935  Uint16 *guid16 = (Uint16 *)guid.data;
936 
937  /* If the GUID fits the form of BUS 0000 VENDOR 0000 PRODUCT 0000, return the data */
938  if (/* guid16[0] is device bus type */
939  guid16[1] == 0x0000 &&
940  /* guid16[2] is vendor ID */
941  guid16[3] == 0x0000 &&
942  /* guid16[4] is product ID */
943  guid16[5] == 0x0000
944  /* guid16[6] is product version */
945  ) {
946  if (vendor) {
947  *vendor = guid16[2];
948  }
949  if (product) {
950  *product = guid16[4];
951  }
952  if (version) {
953  *version = guid16[6];
954  }
955  } else {
956  if (vendor) {
957  *vendor = 0;
958  }
959  if (product) {
960  *product = 0;
961  }
962  if (version) {
963  *version = 0;
964  }
965  }
966 }
Uint8 data[16]
Definition: SDL_joystick.h:71
uint16_t Uint16
Definition: SDL_stdinc.h:169

◆ SDL_IsGameControllerNameAndGUID()

SDL_bool SDL_IsGameControllerNameAndGUID ( const char *  name,
SDL_JoystickGUID  guid 
)

Definition at line 1276 of file SDL_gamecontroller.c.

References SDL_FALSE, SDL_PrivateGetControllerMappingForNameAndGUID(), and SDL_TRUE.

1277 {
1279  if (pSupportedController) {
1280  return SDL_TRUE;
1281  }
1282  return SDL_FALSE;
1283 }
static ControllerMapping_t * SDL_PrivateGetControllerMappingForNameAndGUID(const char *name, SDL_JoystickGUID guid)
GLuint const GLchar * name

◆ SDL_JoystickInit()

int SDL_JoystickInit ( void  )

Definition at line 70 of file SDL_joystick.c.

References NULL, SDL_AddHintCallback, SDL_CreateMutex, SDL_GameControllerInitMappings(), SDL_HINT_JOYSTICK_ALLOW_BACKGROUND_EVENTS, SDL_INIT_EVENTS, SDL_InitSubSystem, SDL_JoystickAllowBackgroundEventsChanged(), and SDL_SYS_JoystickInit().

Referenced by SDL_InitSubSystem().

71 {
72  int status;
73 
75 
76  /* Create the joystick list lock */
77  if (!SDL_joystick_lock) {
79  }
80 
81  /* See if we should allow joystick events while in the background */
84 
85 #if !SDL_EVENTS_DISABLED
87  return -1;
88  }
89 #endif /* !SDL_EVENTS_DISABLED */
90 
91  status = SDL_SYS_JoystickInit();
92  if (status >= 0) {
93  status = 0;
94  }
95  return (status);
96 }
#define SDL_HINT_JOYSTICK_ALLOW_BACKGROUND_EVENTS
A variable that lets you enable joystick (and gamecontroller) events even when your app is in the bac...
Definition: SDL_hints.h:466
#define SDL_INIT_EVENTS
Definition: SDL.h:82
int SDL_GameControllerInitMappings(void)
static SDL_mutex * SDL_joystick_lock
Definition: SDL_joystick.c:40
#define SDL_CreateMutex
#define SDL_InitSubSystem
int SDL_SYS_JoystickInit(void)
#define NULL
Definition: begin_code.h:164
#define SDL_AddHintCallback
static void SDL_JoystickAllowBackgroundEventsChanged(void *userdata, const char *name, const char *oldValue, const char *hint)
Definition: SDL_joystick.c:60

◆ SDL_JoystickQuit()

void SDL_JoystickQuit ( void  )

Definition at line 545 of file SDL_joystick.c.

References NULL, SDL_assert, SDL_DelHintCallback, SDL_DestroyMutex, SDL_GameControllerQuitMappings(), SDL_HINT_JOYSTICK_ALLOW_BACKGROUND_EVENTS, SDL_INIT_EVENTS, SDL_JoystickAllowBackgroundEventsChanged(), SDL_JoystickClose(), SDL_joysticks, SDL_LockJoysticks(), SDL_QuitSubSystem, SDL_SYS_JoystickQuit(), SDL_UnlockJoysticks(), and SDL_updating_joystick.

Referenced by SDL_QuitSubSystem().

546 {
547  /* Make sure we're not getting called in the middle of updating joysticks */
549 
551 
552  /* Stop the event polling */
553  while (SDL_joysticks) {
554  SDL_joysticks->ref_count = 1;
556  }
557 
558  /* Quit the joystick setup */
560 
562 
563 #if !SDL_EVENTS_DISABLED
565 #endif
566 
569 
570  if (SDL_joystick_lock) {
573  }
574 
576 }
#define SDL_HINT_JOYSTICK_ALLOW_BACKGROUND_EVENTS
A variable that lets you enable joystick (and gamecontroller) events even when your app is in the bac...
Definition: SDL_hints.h:466
#define SDL_INIT_EVENTS
Definition: SDL.h:82
void SDL_LockJoysticks(void)
Definition: SDL_joystick.c:43
void SDL_JoystickClose(SDL_Joystick *joystick)
Definition: SDL_joystick.c:491
void SDL_GameControllerQuitMappings(void)
static SDL_mutex * SDL_joystick_lock
Definition: SDL_joystick.c:40
#define SDL_QuitSubSystem
void SDL_SYS_JoystickQuit(void)
void SDL_UnlockJoysticks(void)
Definition: SDL_joystick.c:51
#define SDL_assert(condition)
Definition: SDL_assert.h:169
#define NULL
Definition: begin_code.h:164
#define SDL_DestroyMutex
#define SDL_DelHintCallback
static void SDL_JoystickAllowBackgroundEventsChanged(void *userdata, const char *name, const char *oldValue, const char *hint)
Definition: SDL_joystick.c:60
static SDL_bool SDL_updating_joystick
Definition: SDL_joystick.c:39
static SDL_Joystick * SDL_joysticks
Definition: SDL_joystick.c:38

◆ SDL_PrivateJoystickAdded()

void SDL_PrivateJoystickAdded ( int  device_index)

Definition at line 595 of file SDL_joystick.c.

References SDL_ENABLE, SDL_GetEventState, SDL_JOYDEVICEADDED, SDL_PushEvent, and SDL_Event::type.

Referenced by SDL_SYS_AddJoystickDevice(), and SteamControllerConnectedCallback().

596 {
597 #if !SDL_EVENTS_DISABLED
599 
600  event.type = SDL_JOYDEVICEADDED;
601 
602  if (SDL_GetEventState(event.type) == SDL_ENABLE) {
603  event.jdevice.which = device_index;
604  SDL_PushEvent(&event);
605  }
606 #endif /* !SDL_EVENTS_DISABLED */
607 }
#define SDL_ENABLE
Definition: SDL_events.h:722
#define SDL_GetEventState(type)
Definition: SDL_events.h:735
struct _cl_event * event
#define SDL_PushEvent
General event structure.
Definition: SDL_events.h:525
Uint32 type
Definition: SDL_events.h:527

◆ SDL_PrivateJoystickAxis()

int SDL_PrivateJoystickAxis ( SDL_Joystick *  joystick,
Uint8  axis,
Sint16  value 
)

Definition at line 655 of file SDL_joystick.c.

References axis, SDL_abs, SDL_ENABLE, SDL_GetEventState, SDL_JOYAXISMOTION, SDL_JOYSTICK_AXIS_MAX, SDL_PrivateJoystickAxis(), SDL_PrivateJoystickShouldIgnoreEvent(), SDL_PushEvent, and SDL_TRUE.

Referenced by SDL_JoystickUpdate(), SDL_PrivateJoystickAxis(), SDL_SYS_AccelerometerUpdate(), and SDL_SYS_MFIJoystickUpdate().

656 {
657  int posted;
658 
659  /* Make sure we're not getting garbage or duplicate events */
660  if (axis >= joystick->naxes) {
661  return 0;
662  }
663  if (!joystick->axes[axis].has_initial_value) {
664  joystick->axes[axis].initial_value = value;
665  joystick->axes[axis].value = value;
666  joystick->axes[axis].zero = value;
667  joystick->axes[axis].has_initial_value = SDL_TRUE;
668  }
669  if (value == joystick->axes[axis].value) {
670  return 0;
671  }
672  if (!joystick->axes[axis].sent_initial_value) {
673  /* Make sure we don't send motion until there's real activity on this axis */
674  const int MAX_ALLOWED_JITTER = SDL_JOYSTICK_AXIS_MAX / 80; /* ShanWan PS3 controller needed 96 */
675  if (SDL_abs(value - joystick->axes[axis].value) <= MAX_ALLOWED_JITTER) {
676  return 0;
677  }
678  joystick->axes[axis].sent_initial_value = SDL_TRUE;
679  joystick->axes[axis].value = value; /* Just so we pass the check above */
680  SDL_PrivateJoystickAxis(joystick, axis, joystick->axes[axis].initial_value);
681  }
682 
683  /* We ignore events if we don't have keyboard focus, except for centering
684  * events.
685  */
687  if ((value > joystick->axes[axis].zero && value >= joystick->axes[axis].value) ||
688  (value < joystick->axes[axis].zero && value <= joystick->axes[axis].value)) {
689  return 0;
690  }
691  }
692 
693  /* Update internal joystick state */
694  joystick->axes[axis].value = value;
695 
696  /* Post the event, if desired */
697  posted = 0;
698 #if !SDL_EVENTS_DISABLED
701  event.type = SDL_JOYAXISMOTION;
702  event.jaxis.which = joystick->instance_id;
703  event.jaxis.axis = axis;
704  event.jaxis.value = value;
705  posted = SDL_PushEvent(&event) == 1;
706  }
707 #endif /* !SDL_EVENTS_DISABLED */
708  return (posted);
709 }
#define SDL_abs
#define SDL_ENABLE
Definition: SDL_events.h:722
SDL_Texture * axis
int SDL_PrivateJoystickAxis(SDL_Joystick *joystick, Uint8 axis, Sint16 value)
Definition: SDL_joystick.c:655
#define SDL_JOYSTICK_AXIS_MAX
Definition: SDL_joystick.h:288
#define SDL_GetEventState(type)
Definition: SDL_events.h:735
struct _cl_event * event
#define SDL_PushEvent
GLsizei const GLfloat * value
static SDL_bool SDL_PrivateJoystickShouldIgnoreEvent()
Definition: SDL_joystick.c:580
General event structure.
Definition: SDL_events.h:525

◆ SDL_PrivateJoystickBall()

int SDL_PrivateJoystickBall ( SDL_Joystick *  joystick,
Uint8  ball,
Sint16  xrel,
Sint16  yrel 
)

Definition at line 752 of file SDL_joystick.c.

References SDL_ENABLE, SDL_GetEventState, SDL_JOYBALLMOTION, SDL_PrivateJoystickShouldIgnoreEvent(), and SDL_PushEvent.

754 {
755  int posted;
756 
757  /* Make sure we're not getting garbage events */
758  if (ball >= joystick->nballs) {
759  return 0;
760  }
761 
762  /* We ignore events if we don't have keyboard focus. */
764  return 0;
765  }
766 
767  /* Update internal mouse state */
768  joystick->balls[ball].dx += xrel;
769  joystick->balls[ball].dy += yrel;
770 
771  /* Post the event, if desired */
772  posted = 0;
773 #if !SDL_EVENTS_DISABLED
776  event.jball.type = SDL_JOYBALLMOTION;
777  event.jball.which = joystick->instance_id;
778  event.jball.ball = ball;
779  event.jball.xrel = xrel;
780  event.jball.yrel = yrel;
781  posted = SDL_PushEvent(&event) == 1;
782  }
783 #endif /* !SDL_EVENTS_DISABLED */
784  return (posted);
785 }
#define SDL_ENABLE
Definition: SDL_events.h:722
#define SDL_GetEventState(type)
Definition: SDL_events.h:735
struct _cl_event * event
#define SDL_PushEvent
static SDL_bool SDL_PrivateJoystickShouldIgnoreEvent()
Definition: SDL_joystick.c:580
General event structure.
Definition: SDL_events.h:525

◆ SDL_PrivateJoystickBatteryLevel()

void SDL_PrivateJoystickBatteryLevel ( SDL_Joystick *  joystick,
SDL_JoystickPowerLevel  ePowerLevel 
)

Definition at line 1261 of file SDL_joystick.c.

1262 {
1263  joystick->epowerlevel = ePowerLevel;
1264 }

◆ SDL_PrivateJoystickButton()

int SDL_PrivateJoystickButton ( SDL_Joystick *  joystick,
Uint8  button,
Uint8  state 
)

Definition at line 788 of file SDL_joystick.c.

References button, SDL_ENABLE, SDL_GetEventState, SDL_JOYBUTTONDOWN, SDL_JOYBUTTONUP, SDL_PRESSED, SDL_PrivateJoystickShouldIgnoreEvent(), SDL_PushEvent, SDL_RELEASED, state, and SDL_Event::type.

Referenced by SDL_JoystickUpdate(), and SDL_SYS_MFIJoystickUpdate().

789 {
790  int posted;
791 #if !SDL_EVENTS_DISABLED
793 
794  switch (state) {
795  case SDL_PRESSED:
796  event.type = SDL_JOYBUTTONDOWN;
797  break;
798  case SDL_RELEASED:
799  event.type = SDL_JOYBUTTONUP;
800  break;
801  default:
802  /* Invalid state -- bail */
803  return (0);
804  }
805 #endif /* !SDL_EVENTS_DISABLED */
806 
807  /* Make sure we're not getting garbage or duplicate events */
808  if (button >= joystick->nbuttons) {
809  return 0;
810  }
811  if (state == joystick->buttons[button]) {
812  return 0;
813  }
814 
815  /* We ignore events if we don't have keyboard focus, except for button
816  * release. */
818  if (state == SDL_PRESSED) {
819  return 0;
820  }
821  }
822 
823  /* Update internal joystick state */
824  joystick->buttons[button] = state;
825 
826  /* Post the event, if desired */
827  posted = 0;
828 #if !SDL_EVENTS_DISABLED
829  if (SDL_GetEventState(event.type) == SDL_ENABLE) {
830  event.jbutton.which = joystick->instance_id;
831  event.jbutton.button = button;
832  event.jbutton.state = state;
833  posted = SDL_PushEvent(&event) == 1;
834  }
835 #endif /* !SDL_EVENTS_DISABLED */
836  return (posted);
837 }
SDL_Texture * button
struct xkb_state * state
#define SDL_ENABLE
Definition: SDL_events.h:722
#define SDL_GetEventState(type)
Definition: SDL_events.h:735
struct _cl_event * event
#define SDL_PushEvent
static SDL_bool SDL_PrivateJoystickShouldIgnoreEvent()
Definition: SDL_joystick.c:580
General event structure.
Definition: SDL_events.h:525
#define SDL_PRESSED
Definition: SDL_events.h:50
#define SDL_RELEASED
Definition: SDL_events.h:49
Uint32 type
Definition: SDL_events.h:527

◆ SDL_PrivateJoystickHat()

int SDL_PrivateJoystickHat ( SDL_Joystick *  joystick,
Uint8  hat,
Uint8  value 
)

Definition at line 712 of file SDL_joystick.c.

References SDL_ENABLE, SDL_GetEventState, SDL_HAT_CENTERED, SDL_JOYHATMOTION, SDL_PrivateJoystickShouldIgnoreEvent(), and SDL_PushEvent.

Referenced by SDL_JoystickUpdate(), and SDL_SYS_MFIJoystickUpdate().

713 {
714  int posted;
715 
716  /* Make sure we're not getting garbage or duplicate events */
717  if (hat >= joystick->nhats) {
718  return 0;
719  }
720  if (value == joystick->hats[hat]) {
721  return 0;
722  }
723 
724  /* We ignore events if we don't have keyboard focus, except for centering
725  * events.
726  */
728  if (value != SDL_HAT_CENTERED) {
729  return 0;
730  }
731  }
732 
733  /* Update internal joystick state */
734  joystick->hats[hat] = value;
735 
736  /* Post the event, if desired */
737  posted = 0;
738 #if !SDL_EVENTS_DISABLED
741  event.jhat.type = SDL_JOYHATMOTION;
742  event.jhat.which = joystick->instance_id;
743  event.jhat.hat = hat;
744  event.jhat.value = value;
745  posted = SDL_PushEvent(&event) == 1;
746  }
747 #endif /* !SDL_EVENTS_DISABLED */
748  return (posted);
749 }
#define SDL_ENABLE
Definition: SDL_events.h:722
#define SDL_GetEventState(type)
Definition: SDL_events.h:735
struct _cl_event * event
#define SDL_PushEvent
GLsizei const GLfloat * value
static SDL_bool SDL_PrivateJoystickShouldIgnoreEvent()
Definition: SDL_joystick.c:580
General event structure.
Definition: SDL_events.h:525
#define SDL_HAT_CENTERED
Definition: SDL_joystick.h:316

◆ SDL_PrivateJoystickRemoved()

void SDL_PrivateJoystickRemoved ( SDL_JoystickID  device_instance)

Definition at line 638 of file SDL_joystick.c.

References SDL_ENABLE, SDL_GetEventState, SDL_JOYDEVICEREMOVED, SDL_PushEvent, SDL_Event::type, and UpdateEventsForDeviceRemoval().

Referenced by SDL_SYS_RemoveJoystickDevice().

639 {
640 #if !SDL_EVENTS_DISABLED
642 
643  event.type = SDL_JOYDEVICEREMOVED;
644 
645  if (SDL_GetEventState(event.type) == SDL_ENABLE) {
646  event.jdevice.which = device_instance;
647  SDL_PushEvent(&event);
648  }
649 
651 #endif /* !SDL_EVENTS_DISABLED */
652 }
#define SDL_ENABLE
Definition: SDL_events.h:722
static void UpdateEventsForDeviceRemoval()
Definition: SDL_joystick.c:614
#define SDL_GetEventState(type)
Definition: SDL_events.h:735
struct _cl_event * event
#define SDL_PushEvent
General event structure.
Definition: SDL_events.h:525
Uint32 type
Definition: SDL_events.h:527

◆ SDL_PrivateJoystickValid()

int SDL_PrivateJoystickValid ( SDL_Joystick *  joystick)

Definition at line 259 of file SDL_joystick.c.

References NULL, and SDL_SetError.

Referenced by SDL_HapticOpenFromJoystick(), SDL_JoystickCurrentPowerLevel(), SDL_JoystickGetAttached(), SDL_JoystickGetAxis(), SDL_JoystickGetAxisInitialState(), SDL_JoystickGetBall(), SDL_JoystickGetButton(), SDL_JoystickGetGUID(), SDL_JoystickGetHat(), SDL_JoystickInstanceID(), SDL_JoystickIsHaptic(), SDL_JoystickName(), SDL_JoystickNumAxes(), SDL_JoystickNumBalls(), SDL_JoystickNumButtons(), and SDL_JoystickNumHats().

260 {
261  int valid;
262 
263  if (joystick == NULL) {
264  SDL_SetError("Joystick hasn't been opened yet");
265  valid = 0;
266  } else {
267  valid = 1;
268  }
269 
270  return valid;
271 }
#define NULL
Definition: begin_code.h:164
#define SDL_SetError

◆ SDL_ShouldIgnoreGameController()

SDL_bool SDL_ShouldIgnoreGameController ( const char *  name,
SDL_JoystickGUID  guid 
)

Definition at line 1301 of file SDL_gamecontroller.c.

References SDL_vidpid_list::entries, i, MAKE_VIDPID, NULL, SDL_vidpid_list::num_entries, recDevice::product, SDL_FALSE, SDL_GetHintBoolean, SDL_GetJoystickGUIDInfo(), SDL_strncmp, and SDL_TRUE.

1302 {
1303  int i;
1304  Uint16 vendor;
1305  Uint16 product;
1306  Uint32 vidpid;
1307 
1310  return SDL_FALSE;
1311  }
1312 
1313  SDL_GetJoystickGUIDInfo(guid, &vendor, &product, NULL);
1314  vidpid = MAKE_VIDPID(vendor, product);
1315 
1316  if (SDL_GetHintBoolean("SDL_GAMECONTROLLER_ALLOW_STEAM_VIRTUAL_GAMEPAD", SDL_FALSE)) {
1317  /* We shouldn't ignore Steam's virtual gamepad since it's using the hints to filter out the real controllers so it can remap input for the virtual controller */
1318  SDL_bool bSteamVirtualGamepad = SDL_FALSE;
1319 #if defined(__LINUX__)
1320  bSteamVirtualGamepad = (vendor == 0x28DE && product == 0x11FF);
1321 #elif defined(__MACOSX__)
1322  bSteamVirtualGamepad = (SDL_strncmp(name, "GamePad-", 8) == 0);
1323 #elif defined(__WIN32__)
1324  /* We can't tell on Windows, but Steam will block others in input hooks */
1325  bSteamVirtualGamepad = SDL_TRUE;
1326 #endif
1327  if (bSteamVirtualGamepad) {
1328  return SDL_FALSE;
1329  }
1330  }
1331 
1333  for (i = 0; i < SDL_allowed_controllers.num_entries; ++i) {
1334  if (vidpid == SDL_allowed_controllers.entries[i]) {
1335  return SDL_FALSE;
1336  }
1337  }
1338  return SDL_TRUE;
1339  } else {
1340  for (i = 0; i < SDL_ignored_controllers.num_entries; ++i) {
1341  if (vidpid == SDL_ignored_controllers.entries[i]) {
1342  return SDL_TRUE;
1343  }
1344  }
1345  return SDL_FALSE;
1346  }
1347 }
#define MAKE_VIDPID(VID, PID)
static SDL_vidpid_list SDL_ignored_controllers
uint32_t Uint32
Definition: SDL_stdinc.h:181
#define SDL_strncmp
GLuint const GLchar * name
#define SDL_GetHintBoolean
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
#define NULL
Definition: begin_code.h:164
SDL_bool
Definition: SDL_stdinc.h:139
static SDL_vidpid_list SDL_allowed_controllers
void SDL_GetJoystickGUIDInfo(SDL_JoystickGUID guid, Uint16 *vendor, Uint16 *product, Uint16 *version)
Definition: SDL_joystick.c:933
uint16_t Uint16
Definition: SDL_stdinc.h:169