mirror of https://github.com/encounter/SDL.git
Cleanup Linux joystick code
This commit is contained in:
parent
5c78df9c23
commit
499d31e9cd
|
@ -56,18 +56,6 @@
|
||||||
#ifndef SYN_DROPPED
|
#ifndef SYN_DROPPED
|
||||||
#define SYN_DROPPED 3
|
#define SYN_DROPPED 3
|
||||||
#endif
|
#endif
|
||||||
#ifndef BTN_SOUTH
|
|
||||||
#define BTN_SOUTH 0x130
|
|
||||||
#endif
|
|
||||||
#ifndef BTN_EAST
|
|
||||||
#define BTN_EAST 0x131
|
|
||||||
#endif
|
|
||||||
#ifndef BTN_NORTH
|
|
||||||
#define BTN_NORTH 0x133
|
|
||||||
#endif
|
|
||||||
#ifndef BTN_WEST
|
|
||||||
#define BTN_WEST 0x134
|
|
||||||
#endif
|
|
||||||
#ifndef BTN_DPAD_UP
|
#ifndef BTN_DPAD_UP
|
||||||
#define BTN_DPAD_UP 0x220
|
#define BTN_DPAD_UP 0x220
|
||||||
#endif
|
#endif
|
||||||
|
@ -115,7 +103,6 @@ typedef struct SDL_joylist_item
|
||||||
SDL_bool m_bSteamController;
|
SDL_bool m_bSteamController;
|
||||||
|
|
||||||
SDL_GamepadMapping *mapping;
|
SDL_GamepadMapping *mapping;
|
||||||
SDL_bool has_gamepad_mapping;
|
|
||||||
} SDL_joylist_item;
|
} SDL_joylist_item;
|
||||||
|
|
||||||
static SDL_joylist_item *SDL_joylist = NULL;
|
static SDL_joylist_item *SDL_joylist = NULL;
|
||||||
|
@ -379,7 +366,9 @@ MaybeRemoveDevice(const char *path)
|
||||||
|
|
||||||
SDL_PrivateJoystickRemoved(item->device_instance);
|
SDL_PrivateJoystickRemoved(item->device_instance);
|
||||||
|
|
||||||
SDL_free(item->mapping);
|
if (item->mapping) {
|
||||||
|
SDL_free(item->mapping);
|
||||||
|
}
|
||||||
SDL_free(item->path);
|
SDL_free(item->path);
|
||||||
SDL_free(item->name);
|
SDL_free(item->name);
|
||||||
SDL_free(item);
|
SDL_free(item);
|
||||||
|
@ -1409,20 +1398,11 @@ LINUX_JoystickGetGamepadMapping(int device_index, SDL_GamepadMapping *out)
|
||||||
SDL_Joystick *joystick;
|
SDL_Joystick *joystick;
|
||||||
SDL_joylist_item *item = JoystickByDevIndex(device_index);
|
SDL_joylist_item *item = JoystickByDevIndex(device_index);
|
||||||
|
|
||||||
if (item->has_gamepad_mapping) {
|
if (item->mapping) {
|
||||||
SDL_memcpy(out, item->mapping, sizeof(*out));
|
SDL_memcpy(out, item->mapping, sizeof(*out));
|
||||||
return SDL_TRUE;
|
return SDL_TRUE;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (item->mapping)
|
|
||||||
return SDL_FALSE;
|
|
||||||
|
|
||||||
item->mapping = (SDL_GamepadMapping *) SDL_calloc(sizeof(*item->mapping), 1);
|
|
||||||
if (item->mapping == NULL) {
|
|
||||||
SDL_OutOfMemory();
|
|
||||||
return SDL_FALSE;
|
|
||||||
}
|
|
||||||
|
|
||||||
joystick = (SDL_Joystick *) SDL_calloc(sizeof(*joystick), 1);
|
joystick = (SDL_Joystick *) SDL_calloc(sizeof(*joystick), 1);
|
||||||
if (joystick == NULL) {
|
if (joystick == NULL) {
|
||||||
SDL_OutOfMemory();
|
SDL_OutOfMemory();
|
||||||
|
@ -1591,8 +1571,11 @@ LINUX_JoystickGetGamepadMapping(int device_index, SDL_GamepadMapping *out)
|
||||||
LINUX_JoystickClose(joystick);
|
LINUX_JoystickClose(joystick);
|
||||||
SDL_free(joystick);
|
SDL_free(joystick);
|
||||||
|
|
||||||
SDL_memcpy(item->mapping, out, sizeof(*out));
|
/* Cache the mapping for later */
|
||||||
item->has_gamepad_mapping = SDL_TRUE;
|
item->mapping = (SDL_GamepadMapping *)SDL_malloc(sizeof(*item->mapping));
|
||||||
|
if (item->mapping) {
|
||||||
|
SDL_memcpy(item->mapping, out, sizeof(*out));
|
||||||
|
}
|
||||||
|
|
||||||
return SDL_TRUE;
|
return SDL_TRUE;
|
||||||
}
|
}
|
||||||
|
|
|
@ -74,6 +74,7 @@ struct joystick_hwdata
|
||||||
|
|
||||||
/* Steam Controller support */
|
/* Steam Controller support */
|
||||||
SDL_bool m_bSteamController;
|
SDL_bool m_bSteamController;
|
||||||
|
|
||||||
/* 4 = (ABS_HAT3X-ABS_HAT0X)/2 (see input-event-codes.h in kernel) */
|
/* 4 = (ABS_HAT3X-ABS_HAT0X)/2 (see input-event-codes.h in kernel) */
|
||||||
int hats_indices[4];
|
int hats_indices[4];
|
||||||
SDL_bool has_hat[4];
|
SDL_bool has_hat[4];
|
||||||
|
|
Loading…
Reference in New Issue