21 #include "../SDL_internal.h" 31 #if !SDL_EVENTS_DISABLED 32 #include "../events/SDL_events_c.h" 42 if (hint && *hint ==
'1') {
58 #if !SDL_EVENTS_DISABLED 104 SDL_Joystick *joysticklist;
105 const char *joystickname =
NULL;
116 while (joysticklist) {
118 joystick = joysticklist;
119 ++joystick->ref_count;
122 joysticklist = joysticklist->next;
126 joystick = (SDL_Joystick *)
SDL_malloc((
sizeof *joystick));
127 if (joystick ==
NULL) {
142 joystick->name =
NULL;
144 if (joystick->naxes > 0) {
148 if (joystick->nhats > 0) {
150 (joystick->nhats *
sizeof(
Uint8));
152 if (joystick->nballs > 0) {
153 joystick->balls = (
struct balldelta *)
SDL_malloc 154 (joystick->nballs *
sizeof(*joystick->balls));
156 if (joystick->nbuttons > 0) {
158 (joystick->nbuttons *
sizeof(
Uint8));
160 if (((joystick->naxes > 0) && !joystick->axes)
161 || ((joystick->nhats > 0) && !joystick->hats)
162 || ((joystick->nballs > 0) && !joystick->balls)
163 || ((joystick->nbuttons > 0) && !joystick->buttons)) {
168 if (joystick->axes) {
172 if (joystick->hats) {
175 if (joystick->balls) {
177 joystick->nballs *
sizeof(*joystick->balls));
179 if (joystick->buttons) {
185 ++joystick->ref_count;
204 if (joystick ==
NULL) {
223 return (joystick->naxes);
235 return (joystick->nhats);
247 return (joystick->nballs);
259 return (joystick->nbuttons);
273 if (axis < joystick->naxes) {
274 state = joystick->axes[
axis];
276 SDL_SetError(
"Joystick only has %d axes", joystick->naxes);
293 if (hat < joystick->nhats) {
294 state = joystick->hats[hat];
296 SDL_SetError(
"Joystick only has %d hats", joystick->nhats);
315 if (ball < joystick->nballs) {
317 *dx = joystick->balls[ball].dx;
320 *dy = joystick->balls[ball].dy;
322 joystick->balls[ball].dx = 0;
323 joystick->balls[ball].dy = 0;
325 return SDL_SetError(
"Joystick only has %d balls", joystick->nballs);
341 if (button < joystick->nbuttons) {
342 state = joystick->buttons[
button];
344 SDL_SetError(
"Joystick only has %d buttons", joystick->nbuttons);
374 return (joystick->instance_id);
385 if (joystick->instance_id == joyid) {
388 joystick = joystick->next;
404 return (joystick->name);
413 SDL_Joystick *joysticklist;
414 SDL_Joystick *joysticklistprev;
421 if (--joystick->ref_count > 0) {
430 joystick->hwdata =
NULL;
433 joysticklistprev =
NULL;
434 while (joysticklist) {
435 if (joystick == joysticklist) {
436 if (joysticklistprev) {
438 joysticklistprev->next = joysticklist->next;
444 joysticklistprev = joysticklist;
445 joysticklist = joysticklist->next;
473 #if !SDL_EVENTS_DISABLED 503 #if !SDL_EVENTS_DISABLED 509 event.jdevice.which = device_index;
529 if (num_events <= 0) {
539 for (i = 0; i < num_events; ++
i) {
549 #if !SDL_EVENTS_DISABLED 555 event.jdevice.which = device_instance;
572 if (axis >= joystick->naxes) {
575 if (value == joystick->axes[axis]) {
583 if ((value > joystick->axes_zero[axis] && value >= joystick->axes[axis]) ||
594 #if !SDL_EVENTS_DISABLED 598 event.jaxis.which = joystick->instance_id;
599 event.jaxis.axis =
axis;
600 event.jaxis.value =
value;
613 if (hat >= joystick->nhats) {
616 if (value == joystick->hats[hat]) {
630 joystick->hats[hat] =
value;
634 #if !SDL_EVENTS_DISABLED 638 event.jhat.which = joystick->instance_id;
639 event.jhat.hat = hat;
640 event.jhat.value =
value;
654 if (ball >= joystick->nballs) {
664 joystick->balls[ball].dx += xrel;
665 joystick->balls[ball].dy += yrel;
669 #if !SDL_EVENTS_DISABLED 673 event.jball.which = joystick->instance_id;
674 event.jball.ball = ball;
675 event.jball.xrel = xrel;
676 event.jball.yrel = yrel;
687 #if !SDL_EVENTS_DISABLED 704 if (button >= joystick->nbuttons) {
707 if (state == joystick->buttons[button]) {
724 #if !SDL_EVENTS_DISABLED 726 event.jbutton.which = joystick->instance_id;
727 event.jbutton.button =
button;
728 event.jbutton.state =
state;
738 SDL_Joystick *joystick;
742 SDL_Joystick *joysticknext;
746 joysticknext = joystick->next;
752 if (joystick->force_recentering) {
756 for (i = 0; i < joystick->naxes; i++) {
760 for (i = 0; i < joystick->nbuttons; i++) {
764 for (i = 0; i < joystick->nhats; i++) {
774 if (joystick->ref_count <= 0) {
778 joystick = joysticknext;
790 #if SDL_EVENTS_DISABLED 793 const Uint32 event_list[] = {
845 static const char k_rgchHexToASCII[] =
"0123456789abcdef";
848 if ((pszGUID ==
NULL) || (cbGUID <= 0)) {
852 for (i = 0; i <
sizeof(guid.
data) && i < (cbGUID-1)/2; i++) {
855 unsigned char c = guid.
data[
i];
857 *pszGUID++ = k_rgchHexToASCII[c >> 4];
858 *pszGUID++ = k_rgchHexToASCII[c & 0x0F];
871 if ((c >=
'0') && (c <=
'9')) {
872 return (
unsigned char)(c -
'0');
875 if ((c >=
'A') && (c <=
'F')) {
876 return (
unsigned char)(c -
'A' + 0x0a);
879 if ((c >=
'a') && (c <=
'f')) {
880 return (
unsigned char)(c -
'a' + 0x0a);
893 int maxoutputbytes=
sizeof(guid);
904 for (i = 0; (i <
len) && ((p - (
Uint8 *)&guid) < maxoutputbytes); i+=2, p++) {
915 joystick->epowerlevel = ePowerLevel;
925 return joystick->epowerlevel;
void SDL_JoystickUpdate(void)
#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...
int SDL_JoystickGetBall(SDL_Joystick *joystick, int ball, int *dx, int *dy)
int SDL_PrivateJoystickValid(SDL_Joystick *joystick)
static SDL_Joystick * SDL_updating_joystick
SDL_JoyDeviceEvent jdevice
GLuint GLfloat GLfloat GLfloat x1
void SDL_JoystickClose(SDL_Joystick *joystick)
void SDL_PrivateJoystickRemoved(SDL_JoystickID device_instance)
int SDL_PrivateJoystickHat(SDL_Joystick *joystick, Uint8 hat, Uint8 value)
int SDL_SYS_NumJoysticks()
#define SDL_QuitSubSystem
int SDL_JoystickInit(void)
static SDL_Event events[EVENT_BUF_SIZE]
int SDL_PrivateJoystickButton(SDL_Joystick *joystick, Uint8 button, Uint8 state)
int SDL_JoystickNumHats(SDL_Joystick *joystick)
#define SDL_InitSubSystem
GLuint const GLchar * name
void SDL_SYS_JoystickQuit(void)
#define SDL_GetKeyboardFocus
uint32_t Uint32
An unsigned 32-bit integer type.
int SDL_PrivateJoystickAxis(SDL_Joystick *joystick, Uint8 axis, Sint16 value)
SDL_JoystickPowerLevel SDL_JoystickCurrentPowerLevel(SDL_Joystick *joystick)
static void UpdateEventsForDeviceRemoval()
const char * SDL_JoystickName(SDL_Joystick *joystick)
int SDL_JoystickEventState(int state)
int SDL_PrivateJoystickBall(SDL_Joystick *joystick, Uint8 ball, Sint16 xrel, Sint16 yrel)
int SDL_NumJoysticks(void)
static SDL_bool SDL_joystick_allows_background_events
#define SDL_GetEventState(type)
GLsizei const GLfloat * value
uint8_t Uint8
An unsigned 8-bit integer type.
#define SDL_stack_alloc(type, count)
SDL_bool SDL_SYS_JoystickAttached(SDL_Joystick *joystick)
SDL_EventFilter SDL_EventOK
SDL_JoystickGUID SDL_JoystickGetGUID(SDL_Joystick *joystick)
void SDL_SYS_JoystickDetect()
void SDL_PrivateJoystickAdded(int device_index)
const char * SDL_SYS_JoystickNameForDeviceIndex(int device_index)
SDL_Joystick * SDL_JoystickOpen(int device_index)
int SDL_JoystickNumAxes(SDL_Joystick *joystick)
void SDL_SYS_JoystickUpdate(SDL_Joystick *joystick)
SDL_JoystickGUID SDL_SYS_JoystickGetGUID(SDL_Joystick *joystick)
SDL_Joystick * SDL_JoystickFromInstanceID(SDL_JoystickID joyid)
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)
#define SDL_assert(condition)
int SDL_SYS_JoystickInit(void)
SDL_JoystickGUID SDL_JoystickGetDeviceGUID(int device_index)
SDL_JoystickGUID SDL_JoystickGetGUIDFromString(const char *pchGUID)
int SDL_JoystickNumBalls(SDL_Joystick *joystick)
#define SDL_OutOfMemory()
static unsigned char nibble(char c)
SDL_JoystickID SDL_JoystickInstanceID(SDL_Joystick *joystick)
void SDL_PrivateJoystickBatteryLevel(SDL_Joystick *joystick, SDL_JoystickPowerLevel ePowerLevel)
#define SDL_AddHintCallback
int SDL_JoystickNumButtons(SDL_Joystick *joystick)
void SDL_JoystickGetGUIDString(SDL_JoystickGUID guid, char *pszGUID, int cbGUID)
SDL_JoystickID SDL_SYS_GetInstanceIdOfDeviceIndex(int device_index)
static SDL_bool SDL_PrivateJoystickShouldIgnoreEvent()
#define SDL_arraysize(array)
int SDL_SYS_JoystickOpen(SDL_Joystick *joystick, int device_index)
Uint8 SDL_JoystickGetButton(SDL_Joystick *joystick, int button)
Uint8 SDL_JoystickGetHat(SDL_Joystick *joystick, int hat)
void SDL_JoystickQuit(void)
static void SDL_JoystickAllowBackgroundEventsChanged(void *userdata, const char *name, const char *oldValue, const char *hint)
#define SDL_stack_free(data)
SDL_bool SDL_JoystickGetAttached(SDL_Joystick *joystick)
void SDL_SYS_JoystickClose(SDL_Joystick *joystick)
SDL_JoystickGUID SDL_SYS_JoystickGetDeviceGUID(int device_index)
const char * SDL_JoystickNameForIndex(int device_index)
int16_t Sint16
A signed 16-bit integer type.
static SDL_Joystick * SDL_joysticks
Sint16 SDL_JoystickGetAxis(SDL_Joystick *joystick, int axis)