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_LockJoystickList (void)
 
void SDL_UnlockJoystickList (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

int SDL_GameControllerInit ( void  )

Definition at line 1188 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().

1189 {
1190  int i;
1191 
1192  /* watch for joy events and fire controller ones if needed */
1194 
1195  /* Send added events for controllers currently attached */
1196  for (i = 0; i < SDL_NumJoysticks(); ++i) {
1197  if (SDL_IsGameController(i)) {
1198  SDL_Event deviceevent;
1199  deviceevent.type = SDL_CONTROLLERDEVICEADDED;
1200  deviceevent.cdevice.which = i;
1201  SDL_PushEvent(&deviceevent);
1202  }
1203  }
1204 
1205  return (0);
1206 }
static int SDL_GameControllerEventWatcher(void *userdata, SDL_Event *event)
SDL_ControllerDeviceEvent cdevice
Definition: SDL_events.h:543
#define SDL_NumJoysticks
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 SDL_PushEvent
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
int SDL_GameControllerInitMappings ( void  )

Definition at line 1164 of file SDL_gamecontroller.c.

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

Referenced by SDL_JoystickInit().

1165 {
1166  int i = 0;
1167  const char *pMappingString = NULL;
1168  pMappingString = s_ControllerMappings[i];
1169  while (pMappingString) {
1171 
1172  i++;
1173  pMappingString = s_ControllerMappings[i];
1174  }
1175 
1176  /* load in any user supplied config */
1178 
1183 
1184  return (0);
1185 }
static void SDL_GameControllerLoadHints()
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
static int SDL_PrivateGameControllerAddMapping(const char *mappingString, SDL_ControllerMappingPriority priority)
#define SDL_HINT_GAMECONTROLLER_IGNORE_DEVICES_EXCEPT
Definition: SDL_hints.h:420
#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_HINT_GAMECONTROLLER_IGNORE_DEVICES
Definition: SDL_hints.h:407
static void SDL_GameControllerIgnoreDevicesChanged(void *userdata, const char *name, const char *oldValue, const char *hint)
void SDL_GameControllerQuit ( void  )

Definition at line 1683 of file SDL_gamecontroller.c.

References SDL_GameControllerClose(), SDL_gamecontrollers, SDL_LockJoystickList(), and SDL_UnlockJoystickList().

Referenced by SDL_QuitSubSystem().

1684 {
1686  while (SDL_gamecontrollers) {
1687  SDL_gamecontrollers->ref_count = 1;
1689  }
1691 }
void SDL_UnlockJoystickList(void)
Definition: SDL_joystick.c:51
void SDL_LockJoystickList(void)
Definition: SDL_joystick.c:43
void SDL_GameControllerClose(SDL_GameController *gamecontroller)
static SDL_GameController * SDL_gamecontrollers
void SDL_GameControllerQuitMappings ( void  )

Definition at line 1694 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().

1695 {
1696  ControllerMapping_t *pControllerMap;
1697 
1698  while (s_pSupportedControllers) {
1699  pControllerMap = s_pSupportedControllers;
1701  SDL_free(pControllerMap->name);
1702  SDL_free(pControllerMap->mapping);
1703  SDL_free(pControllerMap);
1704  }
1705 
1707 
1712 
1716  }
1720  }
1721 }
#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
void SDL_free(void *mem)
#define SDL_HINT_GAMECONTROLLER_IGNORE_DEVICES_EXCEPT
Definition: SDL_hints.h:420
#define SDL_zero(x)
Definition: SDL_stdinc.h:385
#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:407
static void SDL_GameControllerIgnoreDevicesChanged(void *userdata, const char *name, const char *oldValue, const char *hint)
void SDL_GetJoystickGUIDInfo ( SDL_JoystickGUID  guid,
Uint16 vendor,
Uint16 product,
Uint16 version 
)

Definition at line 939 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().

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

Definition at line 1227 of file SDL_gamecontroller.c.

References SDL_FALSE, SDL_PrivateGetControllerMappingForNameAndGUID(), and SDL_TRUE.

1228 {
1230  if (pSupportedController) {
1231  return SDL_TRUE;
1232  }
1233  return SDL_FALSE;
1234 }
static ControllerMapping_t * SDL_PrivateGetControllerMappingForNameAndGUID(const char *name, SDL_JoystickGUID guid)
GLuint const GLchar * name
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:433
#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
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_LockJoystickList(), SDL_QuitSubSystem, SDL_SYS_JoystickQuit(), SDL_UnlockJoystickList(), 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 }
void SDL_UnlockJoystickList(void)
Definition: SDL_joystick.c:51
#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:433
#define SDL_INIT_EVENTS
Definition: SDL.h:82
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_LockJoystickList(void)
Definition: SDL_joystick.c:43
void SDL_SYS_JoystickQuit(void)
#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
void SDL_PrivateJoystickAdded ( int  device_index)

Definition at line 595 of file SDL_joystick.c.

References NULL, SDL_ENABLE, SDL_EventOK, SDL_EventOKParam, SDL_GetEventState, SDL_JOYDEVICEADDED, SDL_PushEvent, and SDL_Event::type.

Referenced by SDL_SYS_AddJoystickDevice().

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  if ((SDL_EventOK == NULL) ||
605  (*SDL_EventOK) (SDL_EventOKParam, &event)) {
606  SDL_PushEvent(&event);
607  }
608  }
609 #endif /* !SDL_EVENTS_DISABLED */
610 }
#define SDL_ENABLE
Definition: SDL_events.h:722
#define SDL_GetEventState(type)
Definition: SDL_events.h:735
struct _cl_event * event
SDL_EventFilter SDL_EventOK
Definition: SDL_events.c:42
#define SDL_PushEvent
void * SDL_EventOKParam
Definition: SDL_events.c:43
#define NULL
Definition: begin_code.h:164
General event structure.
Definition: SDL_events.h:525
Uint32 type
Definition: SDL_events.h:527
int SDL_PrivateJoystickAxis ( SDL_Joystick *  joystick,
Uint8  axis,
Sint16  value 
)

Definition at line 661 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().

662 {
663  int posted;
664 
665  /* Make sure we're not getting garbage or duplicate events */
666  if (axis >= joystick->naxes) {
667  return 0;
668  }
669  if (!joystick->axes[axis].has_initial_value) {
670  joystick->axes[axis].initial_value = value;
671  joystick->axes[axis].value = value;
672  joystick->axes[axis].zero = value;
673  joystick->axes[axis].has_initial_value = SDL_TRUE;
674  }
675  if (value == joystick->axes[axis].value) {
676  return 0;
677  }
678  if (!joystick->axes[axis].sent_initial_value) {
679  /* Make sure we don't send motion until there's real activity on this axis */
680  const int MAX_ALLOWED_JITTER = SDL_JOYSTICK_AXIS_MAX / 80; /* ShanWan PS3 controller needed 96 */
681  if (SDL_abs(value - joystick->axes[axis].value) <= MAX_ALLOWED_JITTER) {
682  return 0;
683  }
684  joystick->axes[axis].sent_initial_value = SDL_TRUE;
685  joystick->axes[axis].value = value; /* Just so we pass the check above */
686  SDL_PrivateJoystickAxis(joystick, axis, joystick->axes[axis].initial_value);
687  }
688 
689  /* We ignore events if we don't have keyboard focus, except for centering
690  * events.
691  */
693  if ((value > joystick->axes[axis].zero && value >= joystick->axes[axis].value) ||
694  (value < joystick->axes[axis].zero && value <= joystick->axes[axis].value)) {
695  return 0;
696  }
697  }
698 
699  /* Update internal joystick state */
700  joystick->axes[axis].value = value;
701 
702  /* Post the event, if desired */
703  posted = 0;
704 #if !SDL_EVENTS_DISABLED
707  event.type = SDL_JOYAXISMOTION;
708  event.jaxis.which = joystick->instance_id;
709  event.jaxis.axis = axis;
710  event.jaxis.value = value;
711  posted = SDL_PushEvent(&event) == 1;
712  }
713 #endif /* !SDL_EVENTS_DISABLED */
714  return (posted);
715 }
#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:661
#define SDL_JOYSTICK_AXIS_MAX
Definition: SDL_joystick.h:274
#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
int SDL_PrivateJoystickBall ( SDL_Joystick *  joystick,
Uint8  ball,
Sint16  xrel,
Sint16  yrel 
)

Definition at line 758 of file SDL_joystick.c.

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

760 {
761  int posted;
762 
763  /* Make sure we're not getting garbage events */
764  if (ball >= joystick->nballs) {
765  return 0;
766  }
767 
768  /* We ignore events if we don't have keyboard focus. */
770  return 0;
771  }
772 
773  /* Update internal mouse state */
774  joystick->balls[ball].dx += xrel;
775  joystick->balls[ball].dy += yrel;
776 
777  /* Post the event, if desired */
778  posted = 0;
779 #if !SDL_EVENTS_DISABLED
782  event.jball.type = SDL_JOYBALLMOTION;
783  event.jball.which = joystick->instance_id;
784  event.jball.ball = ball;
785  event.jball.xrel = xrel;
786  event.jball.yrel = yrel;
787  posted = SDL_PushEvent(&event) == 1;
788  }
789 #endif /* !SDL_EVENTS_DISABLED */
790  return (posted);
791 }
#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
void SDL_PrivateJoystickBatteryLevel ( SDL_Joystick *  joystick,
SDL_JoystickPowerLevel  ePowerLevel 
)

Definition at line 1267 of file SDL_joystick.c.

1268 {
1269  joystick->epowerlevel = ePowerLevel;
1270 }
int SDL_PrivateJoystickButton ( SDL_Joystick *  joystick,
Uint8  button,
Uint8  state 
)

Definition at line 794 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().

795 {
796  int posted;
797 #if !SDL_EVENTS_DISABLED
799 
800  switch (state) {
801  case SDL_PRESSED:
802  event.type = SDL_JOYBUTTONDOWN;
803  break;
804  case SDL_RELEASED:
805  event.type = SDL_JOYBUTTONUP;
806  break;
807  default:
808  /* Invalid state -- bail */
809  return (0);
810  }
811 #endif /* !SDL_EVENTS_DISABLED */
812 
813  /* Make sure we're not getting garbage or duplicate events */
814  if (button >= joystick->nbuttons) {
815  return 0;
816  }
817  if (state == joystick->buttons[button]) {
818  return 0;
819  }
820 
821  /* We ignore events if we don't have keyboard focus, except for button
822  * release. */
824  if (state == SDL_PRESSED) {
825  return 0;
826  }
827  }
828 
829  /* Update internal joystick state */
830  joystick->buttons[button] = state;
831 
832  /* Post the event, if desired */
833  posted = 0;
834 #if !SDL_EVENTS_DISABLED
835  if (SDL_GetEventState(event.type) == SDL_ENABLE) {
836  event.jbutton.which = joystick->instance_id;
837  event.jbutton.button = button;
838  event.jbutton.state = state;
839  posted = SDL_PushEvent(&event) == 1;
840  }
841 #endif /* !SDL_EVENTS_DISABLED */
842  return (posted);
843 }
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
int SDL_PrivateJoystickHat ( SDL_Joystick *  joystick,
Uint8  hat,
Uint8  value 
)

Definition at line 718 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().

719 {
720  int posted;
721 
722  /* Make sure we're not getting garbage or duplicate events */
723  if (hat >= joystick->nhats) {
724  return 0;
725  }
726  if (value == joystick->hats[hat]) {
727  return 0;
728  }
729 
730  /* We ignore events if we don't have keyboard focus, except for centering
731  * events.
732  */
734  if (value != SDL_HAT_CENTERED) {
735  return 0;
736  }
737  }
738 
739  /* Update internal joystick state */
740  joystick->hats[hat] = value;
741 
742  /* Post the event, if desired */
743  posted = 0;
744 #if !SDL_EVENTS_DISABLED
747  event.jhat.type = SDL_JOYHATMOTION;
748  event.jhat.which = joystick->instance_id;
749  event.jhat.hat = hat;
750  event.jhat.value = value;
751  posted = SDL_PushEvent(&event) == 1;
752  }
753 #endif /* !SDL_EVENTS_DISABLED */
754  return (posted);
755 }
#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:302
void SDL_PrivateJoystickRemoved ( SDL_JoystickID  device_instance)

Definition at line 641 of file SDL_joystick.c.

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

Referenced by SDL_SYS_RemoveJoystickDevice().

642 {
643 #if !SDL_EVENTS_DISABLED
645 
646  event.type = SDL_JOYDEVICEREMOVED;
647 
648  if (SDL_GetEventState(event.type) == SDL_ENABLE) {
649  event.jdevice.which = device_instance;
650  if ((SDL_EventOK == NULL) ||
651  (*SDL_EventOK) (SDL_EventOKParam, &event)) {
652  SDL_PushEvent(&event);
653  }
654  }
655 
657 #endif /* !SDL_EVENTS_DISABLED */
658 }
#define SDL_ENABLE
Definition: SDL_events.h:722
static void UpdateEventsForDeviceRemoval()
Definition: SDL_joystick.c:617
#define SDL_GetEventState(type)
Definition: SDL_events.h:735
struct _cl_event * event
SDL_EventFilter SDL_EventOK
Definition: SDL_events.c:42
#define SDL_PushEvent
void * SDL_EventOKParam
Definition: SDL_events.c:43
#define NULL
Definition: begin_code.h:164
General event structure.
Definition: SDL_events.h:525
Uint32 type
Definition: SDL_events.h:527
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_bool SDL_ShouldIgnoreGameController ( const char *  name,
SDL_JoystickGUID  guid 
)

Definition at line 1252 of file SDL_gamecontroller.c.

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

1253 {
1254  int i;
1255  Uint16 vendor;
1256  Uint16 product;
1257  Uint32 vidpid;
1258 
1261  return SDL_FALSE;
1262  }
1263 
1264  SDL_GetJoystickGUIDInfo(guid, &vendor, &product, NULL);
1265  vidpid = MAKE_VIDPID(vendor, product);
1266 
1267  if (SDL_GetHintBoolean("SDL_GAMECONTROLLER_ALLOW_STEAM_VIRTUAL_GAMEPAD", SDL_FALSE)) {
1268  /* 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 */
1269  SDL_bool bSteamVirtualGamepad = SDL_FALSE;
1270 #if defined(__LINUX__)
1271  bSteamVirtualGamepad = (vendor == 0x28DE && product == 0x11FF);
1272 #elif defined(__MACOSX__)
1273  bSteamVirtualGamepad = (SDL_strncmp(name, "GamePad-", 8) == 0);
1274 #elif defined(__WIN32__)
1275  /* We can't tell on Windows, but Steam will block others in input hooks */
1276  bSteamVirtualGamepad = SDL_TRUE;
1277 #endif
1278  if (bSteamVirtualGamepad) {
1279  return SDL_FALSE;
1280  }
1281  }
1282 
1284  for (i = 0; i < SDL_allowed_controllers.num_entries; ++i) {
1285  if (vidpid == SDL_allowed_controllers.entries[i]) {
1286  return SDL_FALSE;
1287  }
1288  }
1289  return SDL_TRUE;
1290  } else {
1291  for (i = 0; i < SDL_ignored_controllers.num_entries; ++i) {
1292  if (vidpid == SDL_ignored_controllers.entries[i]) {
1293  return SDL_TRUE;
1294  }
1295  }
1296  return SDL_FALSE;
1297  }
1298 }
#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:939
uint16_t Uint16
Definition: SDL_stdinc.h:169