summaryrefslogtreecommitdiffstatshomepage
path: root/3rdparty/SDL2/src/joystick
diff options
context:
space:
mode:
Diffstat (limited to '3rdparty/SDL2/src/joystick')
-rw-r--r--3rdparty/SDL2/src/joystick/SDL_gamecontroller.c1372
-rw-r--r--3rdparty/SDL2/src/joystick/SDL_gamecontrollerdb.h116
-rw-r--r--3rdparty/SDL2/src/joystick/SDL_joystick.c929
-rw-r--r--3rdparty/SDL2/src/joystick/SDL_joystick_c.h52
-rw-r--r--3rdparty/SDL2/src/joystick/SDL_sysjoystick.h119
-rw-r--r--3rdparty/SDL2/src/joystick/android/SDL_sysjoystick.c553
-rw-r--r--3rdparty/SDL2/src/joystick/android/SDL_sysjoystick_c.h52
-rw-r--r--3rdparty/SDL2/src/joystick/bsd/SDL_sysjoystick.c697
-rw-r--r--3rdparty/SDL2/src/joystick/darwin/SDL_sysjoystick.c798
-rw-r--r--3rdparty/SDL2/src/joystick/darwin/SDL_sysjoystick_c.h72
-rw-r--r--3rdparty/SDL2/src/joystick/dummy/SDL_sysjoystick.c125
-rw-r--r--3rdparty/SDL2/src/joystick/emscripten/SDL_sysjoystick.c402
-rw-r--r--3rdparty/SDL2/src/joystick/emscripten/SDL_sysjoystick_c.h52
-rw-r--r--3rdparty/SDL2/src/joystick/haiku/SDL_haikujoystick.cc274
-rw-r--r--3rdparty/SDL2/src/joystick/iphoneos/SDL_sysjoystick.m725
-rw-r--r--3rdparty/SDL2/src/joystick/iphoneos/SDL_sysjoystick_c.h55
-rw-r--r--3rdparty/SDL2/src/joystick/linux/SDL_sysjoystick.c847
-rw-r--r--3rdparty/SDL2/src/joystick/linux/SDL_sysjoystick_c.h57
-rw-r--r--3rdparty/SDL2/src/joystick/psp/SDL_sysjoystick.c270
-rw-r--r--3rdparty/SDL2/src/joystick/sort_controllers.py65
-rw-r--r--3rdparty/SDL2/src/joystick/windows/SDL_dinputjoystick.c918
-rw-r--r--3rdparty/SDL2/src/joystick/windows/SDL_dinputjoystick_c.h30
-rw-r--r--3rdparty/SDL2/src/joystick/windows/SDL_mmjoystick.c467
-rw-r--r--3rdparty/SDL2/src/joystick/windows/SDL_windowsjoystick.c538
-rw-r--r--3rdparty/SDL2/src/joystick/windows/SDL_windowsjoystick_c.h92
-rw-r--r--3rdparty/SDL2/src/joystick/windows/SDL_xinputjoystick.c421
-rw-r--r--3rdparty/SDL2/src/joystick/windows/SDL_xinputjoystick_c.h33
27 files changed, 0 insertions, 10131 deletions
diff --git a/3rdparty/SDL2/src/joystick/SDL_gamecontroller.c b/3rdparty/SDL2/src/joystick/SDL_gamecontroller.c
deleted file mode 100644
index 1d3a4c203ca..00000000000
--- a/3rdparty/SDL2/src/joystick/SDL_gamecontroller.c
+++ /dev/null
@@ -1,1372 +0,0 @@
-/*
- Simple DirectMedia Layer
- Copyright (C) 1997-2016 Sam Lantinga <slouken@libsdl.org>
-
- This software is provided 'as-is', without any express or implied
- warranty. In no event will the authors be held liable for any damages
- arising from the use of this software.
-
- Permission is granted to anyone to use this software for any purpose,
- including commercial applications, and to alter it and redistribute it
- freely, subject to the following restrictions:
-
- 1. The origin of this software must not be misrepresented; you must not
- claim that you wrote the original software. If you use this software
- in a product, an acknowledgment in the product documentation would be
- appreciated but is not required.
- 2. Altered source versions must be plainly marked as such, and must not be
- misrepresented as being the original software.
- 3. This notice may not be removed or altered from any source distribution.
-*/
-#include "../SDL_internal.h"
-
-/* This is the game controller API for Simple DirectMedia Layer */
-
-#include "SDL_events.h"
-#include "SDL_assert.h"
-#include "SDL_sysjoystick.h"
-#include "SDL_hints.h"
-#include "SDL_gamecontrollerdb.h"
-
-#if !SDL_EVENTS_DISABLED
-#include "../events/SDL_events_c.h"
-#endif
-#define ABS(_x) ((_x) < 0 ? -(_x) : (_x))
-
-#define SDL_CONTROLLER_PLATFORM_FIELD "platform:"
-
-/* a list of currently opened game controllers */
-static SDL_GameController *SDL_gamecontrollers = NULL;
-
-/* keep track of the hat and mask value that transforms this hat movement into a button/axis press */
-struct _SDL_HatMapping
-{
- int hat;
- Uint8 mask;
-};
-
-/* We need 36 entries for Android (as of SDL v2.0.4) */
-#define k_nMaxReverseEntries 48
-
-/**
- * We are encoding the "HAT" as 0xhm. where h == hat ID and m == mask
- * MAX 4 hats supported
- */
-#define k_nMaxHatEntries 0x3f + 1
-
-/* our in memory mapping db between joystick objects and controller mappings */
-struct _SDL_ControllerMapping
-{
- SDL_JoystickGUID guid;
- const char *name;
-
- /* mapping of axis/button id to controller version */
- int axes[SDL_CONTROLLER_AXIS_MAX];
- int buttonasaxis[SDL_CONTROLLER_AXIS_MAX];
-
- int buttons[SDL_CONTROLLER_BUTTON_MAX];
- int axesasbutton[SDL_CONTROLLER_BUTTON_MAX];
- struct _SDL_HatMapping hatasbutton[SDL_CONTROLLER_BUTTON_MAX];
-
- /* reverse mapping, joystick indices to buttons */
- SDL_GameControllerAxis raxes[k_nMaxReverseEntries];
- SDL_GameControllerAxis rbuttonasaxis[k_nMaxReverseEntries];
-
- SDL_GameControllerButton rbuttons[k_nMaxReverseEntries];
- SDL_GameControllerButton raxesasbutton[k_nMaxReverseEntries];
- SDL_GameControllerButton rhatasbutton[k_nMaxHatEntries];
-
-};
-
-
-/* our hard coded list of mapping support */
-typedef struct _ControllerMapping_t
-{
- SDL_JoystickGUID guid;
- char *name;
- char *mapping;
- struct _ControllerMapping_t *next;
-} ControllerMapping_t;
-
-static ControllerMapping_t *s_pSupportedControllers = NULL;
-static ControllerMapping_t *s_pXInputMapping = NULL;
-static ControllerMapping_t *s_pEmscriptenMapping = NULL;
-
-/* The SDL game controller structure */
-struct _SDL_GameController
-{
- SDL_Joystick *joystick; /* underlying joystick device */
- int ref_count;
- Uint8 hatState[4]; /* the current hat state for this controller */
- struct _SDL_ControllerMapping mapping; /* the mapping object for this controller */
- struct _SDL_GameController *next; /* pointer to next game controller we have allocated */
-};
-
-
-int SDL_PrivateGameControllerAxis(SDL_GameController * gamecontroller, SDL_GameControllerAxis axis, Sint16 value);
-int SDL_PrivateGameControllerButton(SDL_GameController * gamecontroller, SDL_GameControllerButton button, Uint8 state);
-
-/*
- * If there is an existing add event in the queue, it needs to be modified
- * to have the right value for which, because the number of controllers in
- * the system is now one less.
- */
-static void UpdateEventsForDeviceRemoval()
-{
- int i, num_events;
- SDL_Event *events;
-
- num_events = SDL_PeepEvents(NULL, 0, SDL_PEEKEVENT, SDL_CONTROLLERDEVICEADDED, SDL_CONTROLLERDEVICEADDED);
- if (num_events <= 0) {
- return;
- }
-
- events = SDL_stack_alloc(SDL_Event, num_events);
- if (!events) {
- return;
- }
-
- num_events = SDL_PeepEvents(events, num_events, SDL_GETEVENT, SDL_CONTROLLERDEVICEADDED, SDL_CONTROLLERDEVICEADDED);
- for (i = 0; i < num_events; ++i) {
- --events[i].cdevice.which;
- }
- SDL_PeepEvents(events, num_events, SDL_ADDEVENT, 0, 0);
-
- SDL_stack_free(events);
-}
-
-/*
- * Event filter to fire controller events from joystick ones
- */
-int SDL_GameControllerEventWatcher(void *userdata, SDL_Event * event)
-{
- switch(event->type) {
- case SDL_JOYAXISMOTION:
- {
- SDL_GameController *controllerlist;
-
- if (event->jaxis.axis >= k_nMaxReverseEntries)
- {
- SDL_SetError("SDL_GameControllerEventWatcher: Axis index %d too large, ignoring motion", (int)event->jaxis.axis);
- break;
- }
-
- controllerlist = SDL_gamecontrollers;
- while (controllerlist) {
- if (controllerlist->joystick->instance_id == event->jaxis.which) {
- if (controllerlist->mapping.raxes[event->jaxis.axis] >= 0) /* simple axis to axis, send it through */ {
- SDL_GameControllerAxis axis = controllerlist->mapping.raxes[event->jaxis.axis];
- Sint16 value = event->jaxis.value;
- switch (axis) {
- case SDL_CONTROLLER_AXIS_TRIGGERLEFT:
- case SDL_CONTROLLER_AXIS_TRIGGERRIGHT:
- value = value / 2 + 16384;
- break;
- default:
- break;
- }
- SDL_PrivateGameControllerAxis(controllerlist, axis, value);
- } else if (controllerlist->mapping.raxesasbutton[event->jaxis.axis] >= 0) { /* simulate an axis as a button */
- SDL_PrivateGameControllerButton(controllerlist, controllerlist->mapping.raxesasbutton[event->jaxis.axis], ABS(event->jaxis.value) > 32768/2 ? SDL_PRESSED : SDL_RELEASED);
- }
- break;
- }
- controllerlist = controllerlist->next;
- }
- }
- break;
- case SDL_JOYBUTTONDOWN:
- case SDL_JOYBUTTONUP:
- {
- SDL_GameController *controllerlist;
-
- if (event->jbutton.button >= k_nMaxReverseEntries)
- {
- SDL_SetError("SDL_GameControllerEventWatcher: Button index %d too large, ignoring update", (int)event->jbutton.button);
- break;
- }
-
- controllerlist = SDL_gamecontrollers;
- while (controllerlist) {
- if (controllerlist->joystick->instance_id == event->jbutton.which) {
- if (controllerlist->mapping.rbuttons[event->jbutton.button] >= 0) { /* simple button as button */
- SDL_PrivateGameControllerButton(controllerlist, controllerlist->mapping.rbuttons[event->jbutton.button], event->jbutton.state);
- } else if (controllerlist->mapping.rbuttonasaxis[event->jbutton.button] >= 0) { /* an button pretending to be an axis */
- SDL_PrivateGameControllerAxis(controllerlist, controllerlist->mapping.rbuttonasaxis[event->jbutton.button], event->jbutton.state > 0 ? 32767 : 0);
- }
- break;
- }
- controllerlist = controllerlist->next;
- }
- }
- break;
- case SDL_JOYHATMOTION:
- {
- SDL_GameController *controllerlist;
-
- if (event->jhat.hat >= 4) break;
-
- controllerlist = SDL_gamecontrollers;
- while (controllerlist) {
- if (controllerlist->joystick->instance_id == event->jhat.which) {
- Uint8 bSame = controllerlist->hatState[event->jhat.hat] & event->jhat.value;
- /* Get list of removed bits (button release) */
- Uint8 bChanged = controllerlist->hatState[event->jhat.hat] ^ bSame;
- /* the hat idx in the high nibble */
- int bHighHat = event->jhat.hat << 4;
-
- if (bChanged & SDL_HAT_DOWN)
- SDL_PrivateGameControllerButton(controllerlist, controllerlist->mapping.rhatasbutton[bHighHat | SDL_HAT_DOWN], SDL_RELEASED);
- if (bChanged & SDL_HAT_UP)
- SDL_PrivateGameControllerButton(controllerlist, controllerlist->mapping.rhatasbutton[bHighHat | SDL_HAT_UP], SDL_RELEASED);
- if (bChanged & SDL_HAT_LEFT)
- SDL_PrivateGameControllerButton(controllerlist, controllerlist->mapping.rhatasbutton[bHighHat | SDL_HAT_LEFT], SDL_RELEASED);
- if (bChanged & SDL_HAT_RIGHT)
- SDL_PrivateGameControllerButton(controllerlist, controllerlist->mapping.rhatasbutton[bHighHat | SDL_HAT_RIGHT], SDL_RELEASED);
-
- /* Get list of added bits (button press) */
- bChanged = event->jhat.value ^ bSame;
-
- if (bChanged & SDL_HAT_DOWN)
- SDL_PrivateGameControllerButton(controllerlist, controllerlist->mapping.rhatasbutton[bHighHat | SDL_HAT_DOWN], SDL_PRESSED);
- if (bChanged & SDL_HAT_UP)
- SDL_PrivateGameControllerButton(controllerlist, controllerlist->mapping.rhatasbutton[bHighHat | SDL_HAT_UP], SDL_PRESSED);
- if (bChanged & SDL_HAT_LEFT)
- SDL_PrivateGameControllerButton(controllerlist, controllerlist->mapping.rhatasbutton[bHighHat | SDL_HAT_LEFT], SDL_PRESSED);
- if (bChanged & SDL_HAT_RIGHT)
- SDL_PrivateGameControllerButton(controllerlist, controllerlist->mapping.rhatasbutton[bHighHat | SDL_HAT_RIGHT], SDL_PRESSED);
-
- /* update our state cache */
- controllerlist->hatState[event->jhat.hat] = event->jhat.value;
-
- break;
- }
- controllerlist = controllerlist->next;
- }
- }
- break;
- case SDL_JOYDEVICEADDED:
- {
- if (SDL_IsGameController(event->jdevice.which)) {
- SDL_Event deviceevent;
- deviceevent.type = SDL_CONTROLLERDEVICEADDED;
- deviceevent.cdevice.which = event->jdevice.which;
- SDL_PushEvent(&deviceevent);
- }
- }
- break;
- case SDL_JOYDEVICEREMOVED:
- {
- SDL_GameController *controllerlist = SDL_gamecontrollers;
- while (controllerlist) {
- if (controllerlist->joystick->instance_id == event->jdevice.which) {
- SDL_Event deviceevent;
-
- deviceevent.type = SDL_CONTROLLERDEVICEREMOVED;
- deviceevent.cdevice.which = event->jdevice.which;
- SDL_PushEvent(&deviceevent);
-
- UpdateEventsForDeviceRemoval();
- break;
- }
- controllerlist = controllerlist->next;
- }
- }
- break;
- default:
- break;
- }
-
- return 1;
-}
-
-/*
- * Helper function to scan the mappings database for a controller with the specified GUID
- */
-ControllerMapping_t *SDL_PrivateGetControllerMappingForGUID(SDL_JoystickGUID *guid)
-{
- ControllerMapping_t *pSupportedController = s_pSupportedControllers;
- while (pSupportedController) {
- if (SDL_memcmp(guid, &pSupportedController->guid, sizeof(*guid)) == 0) {
- return pSupportedController;
- }
- pSupportedController = pSupportedController->next;
- }
- return NULL;
-}
-
-static const char* map_StringForControllerAxis[] = {
- "leftx",
- "lefty",
- "rightx",
- "righty",
- "lefttrigger",
- "righttrigger",
- NULL
-};
-
-/*
- * convert a string to its enum equivalent
- */
-SDL_GameControllerAxis SDL_GameControllerGetAxisFromString(const char *pchString)
-{
- int entry;
- if (!pchString || !pchString[0])
- return SDL_CONTROLLER_AXIS_INVALID;
-
- for (entry = 0; map_StringForControllerAxis[entry]; ++entry) {
- if (!SDL_strcasecmp(pchString, map_StringForControllerAxis[entry]))
- return entry;
- }
- return SDL_CONTROLLER_AXIS_INVALID;
-}
-
-/*
- * convert an enum to its string equivalent
- */
-const char* SDL_GameControllerGetStringForAxis(SDL_GameControllerAxis axis)
-{
- if (axis > SDL_CONTROLLER_AXIS_INVALID && axis < SDL_CONTROLLER_AXIS_MAX) {
- return map_StringForControllerAxis[axis];
- }
- return NULL;
-}
-
-static const char* map_StringForControllerButton[] = {
- "a",
- "b",
- "x",
- "y",
- "back",
- "guide",
- "start",
- "leftstick",
- "rightstick",
- "leftshoulder",
- "rightshoulder",
- "dpup",
- "dpdown",
- "dpleft",
- "dpright",
- NULL
-};
-
-/*
- * convert a string to its enum equivalent
- */
-SDL_GameControllerButton SDL_GameControllerGetButtonFromString(const char *pchString)
-{
- int entry;
- if (!pchString || !pchString[0])
- return SDL_CONTROLLER_BUTTON_INVALID;
-
- for (entry = 0; map_StringForControllerButton[entry]; ++entry) {
- if (SDL_strcasecmp(pchString, map_StringForControllerButton[entry]) == 0)
- return entry;
- }
- return SDL_CONTROLLER_BUTTON_INVALID;
-}
-
-/*
- * convert an enum to its string equivalent
- */
-const char* SDL_GameControllerGetStringForButton(SDL_GameControllerButton axis)
-{
- if (axis > SDL_CONTROLLER_BUTTON_INVALID && axis < SDL_CONTROLLER_BUTTON_MAX) {
- return map_StringForControllerButton[axis];
- }
- return NULL;
-}
-
-/*
- * given a controller button name and a joystick name update our mapping structure with it
- */
-void SDL_PrivateGameControllerParseButton(const char *szGameButton, const char *szJoystickButton, struct _SDL_ControllerMapping *pMapping)
-{
- int iSDLButton = 0;
- SDL_GameControllerButton button;
- SDL_GameControllerAxis axis;
- button = SDL_GameControllerGetButtonFromString(szGameButton);
- axis = SDL_GameControllerGetAxisFromString(szGameButton);
- iSDLButton = SDL_atoi(&szJoystickButton[1]);
-
- if (szJoystickButton[0] == 'a') {
- if (iSDLButton >= k_nMaxReverseEntries) {
- SDL_SetError("Axis index too large: %d", iSDLButton);
- return;
- }
- if (axis != SDL_CONTROLLER_AXIS_INVALID) {
- pMapping->axes[ axis ] = iSDLButton;
- pMapping->raxes[ iSDLButton ] = axis;
- } else if (button != SDL_CONTROLLER_BUTTON_INVALID) {
- pMapping->axesasbutton[ button ] = iSDLButton;
- pMapping->raxesasbutton[ iSDLButton ] = button;
- } else {
- SDL_assert(!"How did we get here?");
- }
-
- } else if (szJoystickButton[0] == 'b') {
- if (iSDLButton >= k_nMaxReverseEntries) {
- SDL_SetError("Button index too large: %d", iSDLButton);
- return;
- }
- if (button != SDL_CONTROLLER_BUTTON_INVALID) {
- pMapping->buttons[ button ] = iSDLButton;
- pMapping->rbuttons[ iSDLButton ] = button;
- } else if (axis != SDL_CONTROLLER_AXIS_INVALID) {
- pMapping->buttonasaxis[ axis ] = iSDLButton;
- pMapping->rbuttonasaxis[ iSDLButton ] = axis;
- } else {
- SDL_assert(!"How did we get here?");
- }
- } else if (szJoystickButton[0] == 'h') {
- int hat = SDL_atoi(&szJoystickButton[1]);
- int mask = SDL_atoi(&szJoystickButton[3]);
- if (hat >= 4) {
- SDL_SetError("Hat index too large: %d", iSDLButton);
- }
-
- if (button != SDL_CONTROLLER_BUTTON_INVALID) {
- int ridx;
- pMapping->hatasbutton[ button ].hat = hat;
- pMapping->hatasbutton[ button ].mask = mask;
- ridx = (hat << 4) | mask;
- pMapping->rhatasbutton[ ridx ] = button;
- } else if (axis != SDL_CONTROLLER_AXIS_INVALID) {
- SDL_assert(!"Support hat as axis");
- } else {
- SDL_assert(!"How did we get here?");
- }
- }
-}
-
-
-/*
- * given a controller mapping string update our mapping object
- */
-static void
-SDL_PrivateGameControllerParseControllerConfigString(struct _SDL_ControllerMapping *pMapping, const char *pchString)
-{
- char szGameButton[20];
- char szJoystickButton[20];
- SDL_bool bGameButton = SDL_TRUE;
- int i = 0;
- const char *pchPos = pchString;
-
- SDL_memset(szGameButton, 0x0, sizeof(szGameButton));
- SDL_memset(szJoystickButton, 0x0, sizeof(szJoystickButton));
-
- while (pchPos && *pchPos) {
- if (*pchPos == ':') {
- i = 0;
- bGameButton = SDL_FALSE;
- } else if (*pchPos == ' ') {
-
- } else if (*pchPos == ',') {
- i = 0;
- bGameButton = SDL_TRUE;
- SDL_PrivateGameControllerParseButton(szGameButton, szJoystickButton, pMapping);
- SDL_memset(szGameButton, 0x0, sizeof(szGameButton));
- SDL_memset(szJoystickButton, 0x0, sizeof(szJoystickButton));
-
- } else if (bGameButton) {
- if (i >= sizeof(szGameButton)) {
- SDL_SetError("Button name too large: %s", szGameButton);
- return;
- }
- szGameButton[i] = *pchPos;
- i++;
- } else {
- if (i >= sizeof(szJoystickButton)) {
- SDL_SetError("Joystick button name too large: %s", szJoystickButton);
- return;
- }
- szJoystickButton[i] = *pchPos;
- i++;
- }
- pchPos++;
- }
-
- SDL_PrivateGameControllerParseButton(szGameButton, szJoystickButton, pMapping);
-
-}
-
-/*
- * Make a new button mapping struct
- */
-void SDL_PrivateLoadButtonMapping(struct _SDL_ControllerMapping *pMapping, SDL_JoystickGUID guid, const char *pchName, const char *pchMapping)
-{
- int j;
-
- pMapping->guid = guid;
- pMapping->name = pchName;
-
- /* set all the button mappings to non defaults */
- for (j = 0; j < SDL_CONTROLLER_AXIS_MAX; j++) {
- pMapping->axes[j] = -1;
- pMapping->buttonasaxis[j] = -1;
- }
- for (j = 0; j < SDL_CONTROLLER_BUTTON_MAX; j++) {
- pMapping->buttons[j] = -1;
- pMapping->axesasbutton[j] = -1;
- pMapping->hatasbutton[j].hat = -1;
- }
-
- for (j = 0; j < k_nMaxReverseEntries; j++) {
- pMapping->raxes[j] = SDL_CONTROLLER_AXIS_INVALID;
- pMapping->rbuttonasaxis[j] = SDL_CONTROLLER_AXIS_INVALID;
- pMapping->rbuttons[j] = SDL_CONTROLLER_BUTTON_INVALID;
- pMapping->raxesasbutton[j] = SDL_CONTROLLER_BUTTON_INVALID;
- }
-
- for (j = 0; j < k_nMaxHatEntries; j++) {
- pMapping->rhatasbutton[j] = SDL_CONTROLLER_BUTTON_INVALID;
- }
-
- SDL_PrivateGameControllerParseControllerConfigString(pMapping, pchMapping);
-}
-
-
-/*
- * grab the guid string from a mapping string
- */
-char *SDL_PrivateGetControllerGUIDFromMappingString(const char *pMapping)
-{
- const char *pFirstComma = SDL_strchr(pMapping, ',');
- if (pFirstComma) {
- char *pchGUID = SDL_malloc(pFirstComma - pMapping + 1);
- if (!pchGUID) {
- SDL_OutOfMemory();
- return NULL;
- }
- SDL_memcpy(pchGUID, pMapping, pFirstComma - pMapping);
- pchGUID[ pFirstComma - pMapping ] = 0;
- return pchGUID;
- }
- return NULL;
-}
-
-
-/*
- * grab the name string from a mapping string
- */
-char *SDL_PrivateGetControllerNameFromMappingString(const char *pMapping)
-{
- const char *pFirstComma, *pSecondComma;
- char *pchName;
-
- pFirstComma = SDL_strchr(pMapping, ',');
- if (!pFirstComma)
- return NULL;
-
- pSecondComma = SDL_strchr(pFirstComma + 1, ',');
- if (!pSecondComma)
- return NULL;
-
- pchName = SDL_malloc(pSecondComma - pFirstComma);
- if (!pchName) {
- SDL_OutOfMemory();
- return NULL;
- }
- SDL_memcpy(pchName, pFirstComma + 1, pSecondComma - pFirstComma);
- pchName[ pSecondComma - pFirstComma - 1 ] = 0;
- return pchName;
-}
-
-
-/*
- * grab the button mapping string from a mapping string
- */
-char *SDL_PrivateGetControllerMappingFromMappingString(const char *pMapping)
-{
- const char *pFirstComma, *pSecondComma;
-
- pFirstComma = SDL_strchr(pMapping, ',');
- if (!pFirstComma)
- return NULL;
-
- pSecondComma = SDL_strchr(pFirstComma + 1, ',');
- if (!pSecondComma)
- return NULL;
-
- return SDL_strdup(pSecondComma + 1); /* mapping is everything after the 3rd comma */
-}
-
-/*
- * Helper function to refresh a mapping
- */
-void SDL_PrivateGameControllerRefreshMapping(ControllerMapping_t *pControllerMapping)
-{
- SDL_GameController *gamecontrollerlist = SDL_gamecontrollers;
- while (gamecontrollerlist) {
- if (!SDL_memcmp(&gamecontrollerlist->mapping.guid, &pControllerMapping->guid, sizeof(pControllerMapping->guid))) {
- SDL_Event event;
- event.type = SDL_CONTROLLERDEVICEREMAPPED;
- event.cdevice.which = gamecontrollerlist->joystick->instance_id;
- SDL_PushEvent(&event);
-
- /* Not really threadsafe. Should this lock access within SDL_GameControllerEventWatcher? */
- SDL_PrivateLoadButtonMapping(&gamecontrollerlist->mapping, pControllerMapping->guid, pControllerMapping->name, pControllerMapping->mapping);
- }
-
- gamecontrollerlist = gamecontrollerlist->next;
- }
-}
-
-/*
- * Helper function to add a mapping for a guid
- */
-static ControllerMapping_t *
-SDL_PrivateAddMappingForGUID(SDL_JoystickGUID jGUID, const char *mappingString, SDL_bool *existing)
-{
- char *pchName;
- char *pchMapping;
- ControllerMapping_t *pControllerMapping;
-
- pchName = SDL_PrivateGetControllerNameFromMappingString(mappingString);
- if (!pchName) {
- SDL_SetError("Couldn't parse name from %s", mappingString);
- return NULL;
- }
-
- pchMapping = SDL_PrivateGetControllerMappingFromMappingString(mappingString);
- if (!pchMapping) {
- SDL_free(pchName);
- SDL_SetError("Couldn't parse %s", mappingString);
- return NULL;
- }
-
- pControllerMapping = SDL_PrivateGetControllerMappingForGUID(&jGUID);
- if (pControllerMapping) {
- /* Update existing mapping */
- SDL_free(pControllerMapping->name);
- pControllerMapping->name = pchName;
- SDL_free(pControllerMapping->mapping);
- pControllerMapping->mapping = pchMapping;
- /* refresh open controllers */
- SDL_PrivateGameControllerRefreshMapping(pControllerMapping);
- *existing = SDL_TRUE;
- } else {
- pControllerMapping = SDL_malloc(sizeof(*pControllerMapping));
- if (!pControllerMapping) {
- SDL_free(pchName);
- SDL_free(pchMapping);
- SDL_OutOfMemory();
- return NULL;
- }
- pControllerMapping->guid = jGUID;
- pControllerMapping->name = pchName;
- pControllerMapping->mapping = pchMapping;
- pControllerMapping->next = s_pSupportedControllers;
- s_pSupportedControllers = pControllerMapping;
- *existing = SDL_FALSE;
- }
- return pControllerMapping;
-}
-
-/*
- * Helper function to determine pre-calculated offset to certain joystick mappings
- */
-ControllerMapping_t *SDL_PrivateGetControllerMapping(int device_index)
-{
- SDL_JoystickGUID jGUID = SDL_JoystickGetDeviceGUID(device_index);
- ControllerMapping_t *mapping;
-
- mapping = SDL_PrivateGetControllerMappingForGUID(&jGUID);
-#if SDL_JOYSTICK_XINPUT
- if (!mapping && SDL_SYS_IsXInputGamepad_DeviceIndex(device_index)) {
- mapping = s_pXInputMapping;
- }
-#endif
-#if defined(SDL_JOYSTICK_EMSCRIPTEN)
- if (!mapping && s_pEmscriptenMapping) {
- mapping = s_pEmscriptenMapping;
- }
-#endif
-#ifdef __LINUX__
- if (!mapping) {
- const char *name = SDL_JoystickNameForIndex(device_index);
- if (name) {
- if (SDL_strstr(name, "Xbox 360 Wireless Receiver")) {
- /* The Linux driver xpad.c maps the wireless dpad to buttons */
- SDL_bool existing;
- mapping = SDL_PrivateAddMappingForGUID(jGUID,
-"none,X360 Wireless Controller,a:b0,b:b1,back:b6,dpdown:b14,dpleft:b11,dpright:b12,dpup:b13,guide:b8,leftshoulder:b4,leftstick:b9,lefttrigger:a2,leftx:a0,lefty:a1,rightshoulder:b5,rightstick:b10,righttrigger:a5,rightx:a3,righty:a4,start:b7,x:b2,y:b3,",
- &existing);
- }
- }
- }
-#endif /* __LINUX__ */
-
- if (!mapping) {
- const char *name = SDL_JoystickNameForIndex(device_index);
- if (name) {
- if (SDL_strstr(name, "Xbox") || SDL_strstr(name, "X-Box")) {
- mapping = s_pXInputMapping;
- }
- }
- }
- return mapping;
-}
-
-/*
- * Add or update an entry into the Mappings Database
- */
-int
-SDL_GameControllerAddMappingsFromRW(SDL_RWops * rw, int freerw)
-{
- const char *platform = SDL_GetPlatform();
- int controllers = 0;
- char *buf, *line, *line_end, *tmp, *comma, line_platform[64];
- size_t db_size, platform_len;
-
- if (rw == NULL) {
- return SDL_SetError("Invalid RWops");
- }
- db_size = (size_t)SDL_RWsize(rw);
-
- buf = (char *)SDL_malloc(db_size + 1);
- if (buf == NULL) {
- if (freerw) {
- SDL_RWclose(rw);
- }
- return SDL_SetError("Could not allocate space to read DB into memory");
- }
-
- if (SDL_RWread(rw, buf, db_size, 1) != 1) {
- if (freerw) {
- SDL_RWclose(rw);
- }
- SDL_free(buf);
- return SDL_SetError("Could not read DB");
- }
-
- if (freerw) {
- SDL_RWclose(rw);
- }
-
- buf[db_size] = '\0';
- line = buf;
-
- while (line < buf + db_size) {
- line_end = SDL_strchr(line, '\n');
- if (line_end != NULL) {
- *line_end = '\0';
- } else {
- line_end = buf + db_size;
- }
-
- /* Extract and verify the platform */
- tmp = SDL_strstr(line, SDL_CONTROLLER_PLATFORM_FIELD);
- if (tmp != NULL) {
- tmp += SDL_strlen(SDL_CONTROLLER_PLATFORM_FIELD);
- comma = SDL_strchr(tmp, ',');
- if (comma != NULL) {
- platform_len = comma - tmp + 1;
- if (platform_len + 1 < SDL_arraysize(line_platform)) {
- SDL_strlcpy(line_platform, tmp, platform_len);
- if (SDL_strncasecmp(line_platform, platform, platform_len) == 0 &&
- SDL_GameControllerAddMapping(line) > 0) {
- controllers++;
- }
- }
- }
- }
-
- line = line_end + 1;
- }
-
- SDL_free(buf);
- return controllers;
-}
-
-/*
- * Add or update an entry into the Mappings Database
- */
-int
-SDL_GameControllerAddMapping(const char *mappingString)
-{
- char *pchGUID;
- SDL_JoystickGUID jGUID;
- SDL_bool is_xinput_mapping = SDL_FALSE;
- SDL_bool is_emscripten_mapping = SDL_FALSE;
- SDL_bool existing = SDL_FALSE;
- ControllerMapping_t *pControllerMapping;
-
- if (!mappingString) {
- return SDL_InvalidParamError("mappingString");
- }
-
- pchGUID = SDL_PrivateGetControllerGUIDFromMappingString(mappingString);
- if (!pchGUID) {
- return SDL_SetError("Couldn't parse GUID from %s", mappingString);
- }
- if (!SDL_strcasecmp(pchGUID, "xinput")) {
- is_xinput_mapping = SDL_TRUE;
- }
- if (!SDL_strcasecmp(pchGUID, "emscripten")) {
- is_emscripten_mapping = SDL_TRUE;
- }
- jGUID = SDL_JoystickGetGUIDFromString(pchGUID);
- SDL_free(pchGUID);
-
- pControllerMapping = SDL_PrivateAddMappingForGUID(jGUID, mappingString, &existing);
- if (!pControllerMapping) {
- return -1;
- }
-
- if (existing) {
- return 0;
- } else {
- if (is_xinput_mapping) {
- s_pXInputMapping = pControllerMapping;
- }
- if (is_emscripten_mapping) {
- s_pEmscriptenMapping = pControllerMapping;
- }
- return 1;
- }
-}
-
-/*
- * Get the mapping string for this GUID
- */
-char *
-SDL_GameControllerMappingForGUID(SDL_JoystickGUID guid)
-{
- char *pMappingString = NULL;
- ControllerMapping_t *mapping = SDL_PrivateGetControllerMappingForGUID(&guid);
- if (mapping) {
- char pchGUID[33];
- size_t needed;
- SDL_JoystickGetGUIDString(guid, pchGUID, sizeof(pchGUID));
- /* allocate enough memory for GUID + ',' + name + ',' + mapping + \0 */
- needed = SDL_strlen(pchGUID) + 1 + SDL_strlen(mapping->name) + 1 + SDL_strlen(mapping->mapping) + 1;
- pMappingString = SDL_malloc(needed);
- if (!pMappingString) {
- SDL_OutOfMemory();
- return NULL;
- }
- SDL_snprintf(pMappingString, needed, "%s,%s,%s", pchGUID, mapping->name, mapping->mapping);
- }
- return pMappingString;
-}
-
-/*
- * Get the mapping string for this device
- */
-char *
-SDL_GameControllerMapping(SDL_GameController * gamecontroller)
-{
- if (!gamecontroller) {
- return NULL;
- }
-
- return SDL_GameControllerMappingForGUID(gamecontroller->mapping.guid);
-}
-
-static void
-SDL_GameControllerLoadHints()
-{
- const char *hint = SDL_GetHint(SDL_HINT_GAMECONTROLLERCONFIG);
- if (hint && hint[0]) {
- size_t nchHints = SDL_strlen(hint);
- char *pUserMappings = SDL_malloc(nchHints + 1);
- char *pTempMappings = pUserMappings;
- SDL_memcpy(pUserMappings, hint, nchHints);
- pUserMappings[nchHints] = '\0';
- while (pUserMappings) {
- char *pchNewLine = NULL;
-
- pchNewLine = SDL_strchr(pUserMappings, '\n');
- if (pchNewLine)
- *pchNewLine = '\0';
-
- SDL_GameControllerAddMapping(pUserMappings);
-
- if (pchNewLine) {
- pUserMappings = pchNewLine + 1;
- } else {
- pUserMappings = NULL;
- }
- }
- SDL_free(pTempMappings);
- }
-}
-
-/*
- * Initialize the game controller system, mostly load our DB of controller config mappings
- */
-int
-SDL_GameControllerInit(void)
-{
- int i = 0;
- const char *pMappingString = NULL;
- pMappingString = s_ControllerMappings[i];
- while (pMappingString) {
- SDL_GameControllerAddMapping(pMappingString);
-
- i++;
- pMappingString = s_ControllerMappings[i];
- }
-
- /* load in any user supplied config */
- SDL_GameControllerLoadHints();
-
- /* watch for joy events and fire controller ones if needed */
- SDL_AddEventWatch(SDL_GameControllerEventWatcher, NULL);
-
- /* Send added events for controllers currently attached */
- for (i = 0; i < SDL_NumJoysticks(); ++i) {
- if (SDL_IsGameController(i)) {
- SDL_Event deviceevent;
- deviceevent.type = SDL_CONTROLLERDEVICEADDED;
- deviceevent.cdevice.which = i;
- SDL_PushEvent(&deviceevent);
- }
- }
-
- return (0);
-}
-
-
-/*
- * Get the implementation dependent name of a controller
- */
-const char *
-SDL_GameControllerNameForIndex(int device_index)
-{
- ControllerMapping_t *pSupportedController = SDL_PrivateGetControllerMapping(device_index);
- if (pSupportedController) {
- return pSupportedController->name;
- }
- return NULL;
-}
-
-
-/*
- * Return 1 if the joystick at this device index is a supported controller
- */
-SDL_bool
-SDL_IsGameController(int device_index)
-{
- ControllerMapping_t *pSupportedController = SDL_PrivateGetControllerMapping(device_index);
- if (pSupportedController) {
- return SDL_TRUE;
- }
-
- return SDL_FALSE;
-}
-
-/*
- * Open a controller for use - the index passed as an argument refers to
- * the N'th controller on the system. This index is the value which will
- * identify this controller in future controller events.
- *
- * This function returns a controller identifier, or NULL if an error occurred.
- */
-SDL_GameController *
-SDL_GameControllerOpen(int device_index)
-{
- SDL_GameController *gamecontroller;
- SDL_GameController *gamecontrollerlist;
- ControllerMapping_t *pSupportedController = NULL;
-
- if ((device_index < 0) || (device_index >= SDL_NumJoysticks())) {
- SDL_SetError("There are %d joysticks available", SDL_NumJoysticks());
- return (NULL);
- }
-
- gamecontrollerlist = SDL_gamecontrollers;
- /* If the controller is already open, return it */
- while (gamecontrollerlist) {
- if (SDL_SYS_GetInstanceIdOfDeviceIndex(device_index) == gamecontrollerlist->joystick->instance_id) {
- gamecontroller = gamecontrollerlist;
- ++gamecontroller->ref_count;
- return (gamecontroller);
- }
- gamecontrollerlist = gamecontrollerlist->next;
- }
-
- /* Find a controller mapping */
- pSupportedController = SDL_PrivateGetControllerMapping(device_index);
- if (!pSupportedController) {
- SDL_SetError("Couldn't find mapping for device (%d)", device_index);
- return (NULL);
- }
-
- /* Create and initialize the joystick */
- gamecontroller = (SDL_GameController *) SDL_malloc((sizeof *gamecontroller));
- if (gamecontroller == NULL) {
- SDL_OutOfMemory();
- return NULL;
- }
-
- SDL_memset(gamecontroller, 0, (sizeof *gamecontroller));
- gamecontroller->joystick = SDL_JoystickOpen(device_index);
- if (!gamecontroller->joystick) {
- SDL_free(gamecontroller);
- return NULL;
- }
-
- SDL_PrivateLoadButtonMapping(&gamecontroller->mapping, pSupportedController->guid, pSupportedController->name, pSupportedController->mapping);
-
- /* The triggers are mapped from -32768 to 32767, where -32768 is the 'unpressed' value */
- {
- int leftTriggerMapping = gamecontroller->mapping.axes[SDL_CONTROLLER_AXIS_TRIGGERLEFT];
- int rightTriggerMapping = gamecontroller->mapping.axes[SDL_CONTROLLER_AXIS_TRIGGERRIGHT];
- if (leftTriggerMapping >= 0) {
- gamecontroller->joystick->axes[leftTriggerMapping] =
- gamecontroller->joystick->axes_zero[leftTriggerMapping] = (Sint16)-32768;
- }
- if (rightTriggerMapping >= 0) {
- gamecontroller->joystick->axes[rightTriggerMapping] =
- gamecontroller->joystick->axes_zero[rightTriggerMapping] = (Sint16)-32768;
- }
- }
-
- /* Add joystick to list */
- ++gamecontroller->ref_count;
- /* Link the joystick in the list */
- gamecontroller->next = SDL_gamecontrollers;
- SDL_gamecontrollers = gamecontroller;
-
- SDL_SYS_JoystickUpdate(gamecontroller->joystick);
-
- return (gamecontroller);
-}
-
-/*
- * Manually pump for controller updates.
- */
-void
-SDL_GameControllerUpdate(void)
-{
- /* Just for API completeness; the joystick API does all the work. */
- SDL_JoystickUpdate();
-}
-
-
-/*
- * Get the current state of an axis control on a controller
- */
-Sint16
-SDL_GameControllerGetAxis(SDL_GameController * gamecontroller, SDL_GameControllerAxis axis)
-{
- if (!gamecontroller)
- return 0;
-
- if (gamecontroller->mapping.axes[axis] >= 0) {
- Sint16 value = (SDL_JoystickGetAxis(gamecontroller->joystick, gamecontroller->mapping.axes[axis]));
- switch (axis) {
- case SDL_CONTROLLER_AXIS_TRIGGERLEFT:
- case SDL_CONTROLLER_AXIS_TRIGGERRIGHT:
- /* Shift it to be 0 - 32767 */
- value = value / 2 + 16384;
- default:
- break;
- }
- return value;
- } else if (gamecontroller->mapping.buttonasaxis[axis] >= 0) {
- Uint8 value;
- value = SDL_JoystickGetButton(gamecontroller->joystick, gamecontroller->mapping.buttonasaxis[axis]);
- if (value > 0)
- return 32767;
- return 0;
- }
- return 0;
-}
-
-
-/*
- * Get the current state of a button on a controller
- */
-Uint8
-SDL_GameControllerGetButton(SDL_GameController * gamecontroller, SDL_GameControllerButton button)
-{
- if (!gamecontroller)
- return 0;
-
- if (gamecontroller->mapping.buttons[button] >= 0) {
- return (SDL_JoystickGetButton(gamecontroller->joystick, gamecontroller->mapping.buttons[button]));
- } else if (gamecontroller->mapping.axesasbutton[button] >= 0) {
- Sint16 value;
- value = SDL_JoystickGetAxis(gamecontroller->joystick, gamecontroller->mapping.axesasbutton[button]);
- if (ABS(value) > 32768/2)
- return 1;
- return 0;
- } else if (gamecontroller->mapping.hatasbutton[button].hat >= 0) {
- Uint8 value;
- value = SDL_JoystickGetHat(gamecontroller->joystick, gamecontroller->mapping.hatasbutton[button].hat);
-
- if (value & gamecontroller->mapping.hatasbutton[button].mask)
- return 1;
- return 0;
- }
-
- return 0;
-}
-
-/*
- * Return if the joystick in question is currently attached to the system,
- * \return 0 if not plugged in, 1 if still present.
- */
-SDL_bool
-SDL_GameControllerGetAttached(SDL_GameController * gamecontroller)
-{
- if (!gamecontroller)
- return SDL_FALSE;
-
- return SDL_JoystickGetAttached(gamecontroller->joystick);
-}
-
-
-const char *
-SDL_GameControllerName(SDL_GameController * gamecontroller)
-{
- if (!gamecontroller)
- return NULL;
-
- return (gamecontroller->mapping.name);
-}
-
-
-/*
- * Get the joystick for this controller
- */
-SDL_Joystick *SDL_GameControllerGetJoystick(SDL_GameController * gamecontroller)
-{
- if (!gamecontroller)
- return NULL;
-
- return gamecontroller->joystick;
-}
-
-
-/*
- * Find the SDL_GameController that owns this instance id
- */
-SDL_GameController *
-SDL_GameControllerFromInstanceID(SDL_JoystickID joyid)
-{
- SDL_GameController *gamecontroller = SDL_gamecontrollers;
- while (gamecontroller) {
- if (gamecontroller->joystick->instance_id == joyid) {
- return gamecontroller;
- }
- gamecontroller = gamecontroller->next;
- }
-
- return NULL;
-}
-
-
-/**
- * Get the SDL joystick layer binding for this controller axis mapping
- */
-SDL_GameControllerButtonBind SDL_GameControllerGetBindForAxis(SDL_GameController * gamecontroller, SDL_GameControllerAxis axis)
-{
- SDL_GameControllerButtonBind bind;
- SDL_memset(&bind, 0x0, sizeof(bind));
-
- if (!gamecontroller || axis == SDL_CONTROLLER_AXIS_INVALID)
- return bind;
-
- if (gamecontroller->mapping.axes[axis] >= 0) {
- bind.bindType = SDL_CONTROLLER_BINDTYPE_AXIS;
- bind.value.button = gamecontroller->mapping.axes[axis];
- } else if (gamecontroller->mapping.buttonasaxis[axis] >= 0) {
- bind.bindType = SDL_CONTROLLER_BINDTYPE_BUTTON;
- bind.value.button = gamecontroller->mapping.buttonasaxis[axis];
- }
-
- return bind;
-}
-
-
-/**
- * Get the SDL joystick layer binding for this controller button mapping
- */
-SDL_GameControllerButtonBind SDL_GameControllerGetBindForButton(SDL_GameController * gamecontroller, SDL_GameControllerButton button)
-{
- SDL_GameControllerButtonBind bind;
- SDL_memset(&bind, 0x0, sizeof(bind));
-
- if (!gamecontroller || button == SDL_CONTROLLER_BUTTON_INVALID)
- return bind;
-
- if (gamecontroller->mapping.buttons[button] >= 0) {
- bind.bindType = SDL_CONTROLLER_BINDTYPE_BUTTON;
- bind.value.button = gamecontroller->mapping.buttons[button];
- } else if (gamecontroller->mapping.axesasbutton[button] >= 0) {
- bind.bindType = SDL_CONTROLLER_BINDTYPE_AXIS;
- bind.value.axis = gamecontroller->mapping.axesasbutton[button];
- } else if (gamecontroller->mapping.hatasbutton[button].hat >= 0) {
- bind.bindType = SDL_CONTROLLER_BINDTYPE_HAT;
- bind.value.hat.hat = gamecontroller->mapping.hatasbutton[button].hat;
- bind.value.hat.hat_mask = gamecontroller->mapping.hatasbutton[button].mask;
- }
-
- return bind;
-}
-
-
-void
-SDL_GameControllerClose(SDL_GameController * gamecontroller)
-{
- SDL_GameController *gamecontrollerlist, *gamecontrollerlistprev;
-
- if (!gamecontroller)
- return;
-
- /* First decrement ref count */
- if (--gamecontroller->ref_count > 0) {
- return;
- }
-
- SDL_JoystickClose(gamecontroller->joystick);
-
- gamecontrollerlist = SDL_gamecontrollers;
- gamecontrollerlistprev = NULL;
- while (gamecontrollerlist) {
- if (gamecontroller == gamecontrollerlist) {
- if (gamecontrollerlistprev) {
- /* unlink this entry */
- gamecontrollerlistprev->next = gamecontrollerlist->next;
- } else {
- SDL_gamecontrollers = gamecontroller->next;
- }
-
- break;
- }
- gamecontrollerlistprev = gamecontrollerlist;
- gamecontrollerlist = gamecontrollerlist->next;
- }
-
- SDL_free(gamecontroller);
-}
-
-
-/*
- * Quit the controller subsystem
- */
-void
-SDL_GameControllerQuit(void)
-{
- ControllerMapping_t *pControllerMap;
- while (SDL_gamecontrollers) {
- SDL_gamecontrollers->ref_count = 1;
- SDL_GameControllerClose(SDL_gamecontrollers);
- }
-
- while (s_pSupportedControllers) {
- pControllerMap = s_pSupportedControllers;
- s_pSupportedControllers = s_pSupportedControllers->next;
- SDL_free(pControllerMap->name);
- SDL_free(pControllerMap->mapping);
- SDL_free(pControllerMap);
- }
-
- SDL_DelEventWatch(SDL_GameControllerEventWatcher, NULL);
-
-}
-
-/*
- * Event filter to transform joystick events into appropriate game controller ones
- */
-int
-SDL_PrivateGameControllerAxis(SDL_GameController * gamecontroller, SDL_GameControllerAxis axis, Sint16 value)
-{
- int posted;
-
- /* translate the event, if desired */
- posted = 0;
-#if !SDL_EVENTS_DISABLED
- if (SDL_GetEventState(SDL_CONTROLLERAXISMOTION) == SDL_ENABLE) {
- SDL_Event event;
- event.type = SDL_CONTROLLERAXISMOTION;
- event.caxis.which = gamecontroller->joystick->instance_id;
- event.caxis.axis = axis;
- event.caxis.value = value;
- posted = SDL_PushEvent(&event) == 1;
- }
-#endif /* !SDL_EVENTS_DISABLED */
- return (posted);
-}
-
-
-/*
- * Event filter to transform joystick events into appropriate game controller ones
- */
-int
-SDL_PrivateGameControllerButton(SDL_GameController * gamecontroller, SDL_GameControllerButton button, Uint8 state)
-{
- int posted;
-#if !SDL_EVENTS_DISABLED
- SDL_Event event;
-
- if (button == SDL_CONTROLLER_BUTTON_INVALID)
- return (0);
-
- switch (state) {
- case SDL_PRESSED:
- event.type = SDL_CONTROLLERBUTTONDOWN;
- break;
- case SDL_RELEASED:
- event.type = SDL_CONTROLLERBUTTONUP;
- break;
- default:
- /* Invalid state -- bail */
- return (0);
- }
-#endif /* !SDL_EVENTS_DISABLED */
-
- /* translate the event, if desired */
- posted = 0;
-#if !SDL_EVENTS_DISABLED
- if (SDL_GetEventState(event.type) == SDL_ENABLE) {
- event.cbutton.which = gamecontroller->joystick->instance_id;
- event.cbutton.button = button;
- event.cbutton.state = state;
- posted = SDL_PushEvent(&event) == 1;
- }
-#endif /* !SDL_EVENTS_DISABLED */
- return (posted);
-}
-
-/*
- * Turn off controller events
- */
-int
-SDL_GameControllerEventState(int state)
-{
-#if SDL_EVENTS_DISABLED
- return SDL_IGNORE;
-#else
- const Uint32 event_list[] = {
- SDL_CONTROLLERAXISMOTION, SDL_CONTROLLERBUTTONDOWN, SDL_CONTROLLERBUTTONUP,
- SDL_CONTROLLERDEVICEADDED, SDL_CONTROLLERDEVICEREMOVED, SDL_CONTROLLERDEVICEREMAPPED,
- };
- unsigned int i;
-
- switch (state) {
- case SDL_QUERY:
- state = SDL_IGNORE;
- for (i = 0; i < SDL_arraysize(event_list); ++i) {
- state = SDL_EventState(event_list[i], SDL_QUERY);
- if (state == SDL_ENABLE) {
- break;
- }
- }
- break;
- default:
- for (i = 0; i < SDL_arraysize(event_list); ++i) {
- SDL_EventState(event_list[i], state);
- }
- break;
- }
- return (state);
-#endif /* SDL_EVENTS_DISABLED */
-}
-
-/* vi: set ts=4 sw=4 expandtab: */
diff --git a/3rdparty/SDL2/src/joystick/SDL_gamecontrollerdb.h b/3rdparty/SDL2/src/joystick/SDL_gamecontrollerdb.h
deleted file mode 100644
index 1e623cbb86f..00000000000
--- a/3rdparty/SDL2/src/joystick/SDL_gamecontrollerdb.h
+++ /dev/null
@@ -1,116 +0,0 @@
-/*
- Simple DirectMedia Layer
- Copyright (C) 1997-2016 Sam Lantinga <slouken@libsdl.org>
-
- This software is provided 'as-is', without any express or implied
- warranty. In no event will the authors be held liable for any damages
- arising from the use of this software.
-
- Permission is granted to anyone to use this software for any purpose,
- including commercial applications, and to alter it and redistribute it
- freely, subject to the following restrictions:
-
- 1. The origin of this software must not be misrepresented; you must not
- claim that you wrote the original software. If you use this software
- in a product, an acknowledgment in the product documentation would be
- appreciated but is not required.
- 2. Altered source versions must be plainly marked as such, and must not be
- misrepresented as being the original software.
- 3. This notice may not be removed or altered from any source distribution.
-*/
-#include "../SDL_internal.h"
-
-
-/* Default mappings we support
-
- The easiest way to generate a new mapping is to start Steam in Big Picture
- mode, configure your joystick and then look in config/config.vdf in your
- Steam installation directory for the "SDL_GamepadBind" entry.
-
- Alternatively, you can use the app located in test/controllermap
- */
-static const char *s_ControllerMappings [] =
-{
-#if SDL_JOYSTICK_XINPUT
- "xinput,XInput Controller,a:b0,b:b1,back:b6,dpdown:h0.4,dpleft:h0.8,dpright:h0.2,dpup:h0.1,guide:b10,leftshoulder:b4,leftstick:b8,lefttrigger:a2,leftx:a0,lefty:a1,rightshoulder:b5,rightstick:b9,righttrigger:a5,rightx:a3,righty:a4,start:b7,x:b2,y:b3,",
-#endif
-#if SDL_JOYSTICK_DINPUT
- "10280900000000000000504944564944,8Bitdo SFC30 GamePad,a:b1,b:b0,back:b10,leftshoulder:b6,leftx:a0,lefty:a1,rightshoulder:b7,start:b11,x:b4,y:b3,",
- "341a3608000000000000504944564944,Afterglow PS3 Controller,a:b1,b:b2,back:b8,dpdown:h0.4,dpleft:h0.8,dpright:h0.2,dpup:h0.1,guide:b12,leftshoulder:b4,leftstick:b10,lefttrigger:b6,leftx:a0,lefty:a1,rightshoulder:b5,rightstick:b11,righttrigger:b7,rightx:a2,righty:a3,start:b9,x:b0,y:b3,",
- "e8206058000000000000504944564944,Cideko AK08b,a:b2,b:b1,back:b8,dpdown:h0.4,dpleft:h0.8,dpright:h0.2,dpup:h0.1,leftshoulder:b4,leftstick:b10,lefttrigger:b6,leftx:a0,lefty:a1,rightshoulder:b5,rightstick:b11,righttrigger:b7,rightx:a2,righty:a3,start:b9,x:b3,y:b0,",
- "ffff0000000000000000504944564944,GameStop Gamepad,a:b0,b:b1,back:b8,dpdown:h0.4,dpleft:h0.8,dpright:h0.2,dpup:h0.1,guide:,leftshoulder:b4,leftstick:b10,lefttrigger:b6,leftx:a0,lefty:a1,rightshoulder:b5,rightstick:b11,righttrigger:b7,rightx:a2,righty:a3,start:b9,x:b2,y:b3,",
- "6d0416c2000000000000504944564944,Generic DirectInput Controller,a:b1,b:b2,back:b8,dpdown:h0.4,dpleft:h0.8,dpright:h0.2,dpup:h0.1,leftshoulder:b4,leftstick:b10,lefttrigger:b6,leftx:a0,lefty:a1,rightshoulder:b5,rightstick:b11,righttrigger:b7,rightx:a2,righty:a3,start:b9,x:b0,y:b3,",
- "6d0418c2000000000000504944564944,Logitech F510 Gamepad,a:b1,b:b2,back:b8,dpdown:h0.4,dpleft:h0.8,dpright:h0.2,dpup:h0.1,leftshoulder:b4,leftstick:b10,lefttrigger:b6,leftx:a0,lefty:a1,rightshoulder:b5,rightstick:b11,righttrigger:b7,rightx:a2,righty:a3,start:b9,x:b0,y:b3,",
- "6d0419c2000000000000504944564944,Logitech F710 Gamepad,a:b1,b:b2,back:b8,dpdown:h0.4,dpleft:h0.8,dpright:h0.2,dpup:h0.1,leftshoulder:b4,leftstick:b10,lefttrigger:b6,leftx:a0,lefty:a1,rightshoulder:b5,rightstick:b11,righttrigger:b7,rightx:a2,righty:a3,start:b9,x:b0,y:b3,", /* Guide button doesn't seem to be sent in DInput mode. */
- "4d6963726f736f66742050432d6a6f79,OUYA Controller,a:b0,b:b3,dpdown:b9,dpleft:b10,dpright:b11,dpup:b8,guide:b14,leftshoulder:b4,leftstick:b6,lefttrigger:b12,leftx:a0,lefty:a1,rightshoulder:b5,rightstick:b7,righttrigger:b13,rightx:a5,righty:a4,x:b1,y:b2,",
- "88880803000000000000504944564944,PS3 Controller,a:b2,b:b1,back:b8,dpdown:h0.8,dpleft:h0.4,dpright:h0.2,dpup:h0.1,guide:b12,leftshoulder:b4,leftstick:b9,lefttrigger:b6,leftx:a0,lefty:a1,rightshoulder:b5,rightstick:b10,righttrigger:b7,rightx:a3,righty:a4,start:b11,x:b0,y:b3,",
- "4c056802000000000000504944564944,PS3 Controller,a:b14,b:b13,back:b0,dpdown:b6,dpleft:b7,dpright:b5,dpup:b4,guide:b16,leftshoulder:b10,leftstick:b1,lefttrigger:b8,leftx:a0,lefty:a1,rightshoulder:b11,rightstick:b2,righttrigger:b9,rightx:a2,righty:a3,start:b3,x:b15,y:b12,",
- "25090500000000000000504944564944,PS3 DualShock,a:b2,b:b1,back:b9,dpdown:h0.8,dpleft:h0.4,dpright:h0.2,dpup:h0.1,guide:,leftshoulder:b6,leftstick:b10,lefttrigger:b4,leftx:a0,lefty:a1,rightshoulder:b7,rightstick:b11,righttrigger:b5,rightx:a2,righty:a3,start:b8,x:b0,y:b3,",
- "4c05c405000000000000504944564944,PS4 Controller,a:b1,b:b2,back:b8,dpdown:h0.4,dpleft:h0.8,dpright:h0.2,dpup:h0.1,guide:b12,leftshoulder:b4,leftstick:b10,lefttrigger:a3,leftx:a0,lefty:a1,rightshoulder:b5,rightstick:b11,righttrigger:a4,rightx:a2,righty:a5,start:b9,x:b0,y:b3,",
-#endif
-#if defined(__MACOSX__)
- "10280000000000000900000000000000,8Bitdo SFC30 GamePad Joystick,a:b1,b:b0,back:b10,leftshoulder:b6,leftx:a0,lefty:a1,rightshoulder:b7,start:b11,x:b4,y:b3,",
- "830500000000000031b0000000000000,Cideko AK08b,a:b1,b:b2,back:b8,dpdown:h0.4,dpleft:h0.8,dpright:h0.2,dpup:h0.1,leftshoulder:b4,leftstick:b10,lefttrigger:b6,leftx:a0,lefty:a1,rightshoulder:b5,rightstick:b11,righttrigger:b7,rightx:a2,righty:a3,start:b9,x:b0,y:b3,",
- "0500000047532047616d657061640000,GameStop Gamepad,a:b0,b:b1,back:b8,dpdown:h0.4,dpleft:h0.8,dpright:h0.2,dpup:h0.1,guide:,leftshoulder:b4,leftstick:b10,lefttrigger:b6,leftx:a0,lefty:a1,rightshoulder:b5,rightstick:b11,righttrigger:b7,rightx:a2,righty:a3,start:b9,x:b2,y:b3,",
- "6d0400000000000016c2000000000000,Logitech F310 Gamepad (DInput),a:b1,b:b2,back:b8,dpdown:h0.4,dpleft:h0.8,dpright:h0.2,dpup:h0.1,leftshoulder:b4,leftstick:b10,lefttrigger:b6,leftx:a0,lefty:a1,rightshoulder:b5,rightstick:b11,righttrigger:b7,rightx:a2,righty:a3,start:b9,x:b0,y:b3,", /* Guide button doesn't seem to be sent in DInput mode. */
- "6d0400000000000018c2000000000000,Logitech F510 Gamepad (DInput),a:b1,b:b2,back:b8,dpdown:h0.4,dpleft:h0.8,dpright:h0.2,dpup:h0.1,leftshoulder:b4,leftstick:b10,lefttrigger:b6,leftx:a0,lefty:a1,rightshoulder:b5,rightstick:b11,righttrigger:b7,rightx:a2,righty:a3,start:b9,x:b0,y:b3,",
- "6d040000000000001fc2000000000000,Logitech F710 Gamepad (XInput),a:b0,b:b1,back:b9,dpdown:b12,dpleft:b13,dpright:b14,dpup:b11,guide:b10,leftshoulder:b4,leftstick:b6,lefttrigger:a2,leftx:a0,lefty:a1,rightshoulder:b5,rightstick:b7,righttrigger:a5,rightx:a3,righty:a4,start:b8,x:b2,y:b3,",
- "6d0400000000000019c2000000000000,Logitech Wireless Gamepad (DInput),a:b1,b:b2,back:b8,dpdown:h0.4,dpleft:h0.8,dpright:h0.2,dpup:h0.1,leftshoulder:b4,leftstick:b10,lefttrigger:b6,leftx:a0,lefty:a1,rightshoulder:b5,rightstick:b11,righttrigger:b7,rightx:a2,righty:a3,start:b9,x:b0,y:b3,", /* This includes F710 in DInput mode and the "Logitech Cordless RumblePad 2", at the very least. */
- "4c050000000000006802000000000000,PS3 Controller,a:b14,b:b13,back:b0,dpdown:b6,dpleft:b7,dpright:b5,dpup:b4,guide:b16,leftshoulder:b10,leftstick:b1,lefttrigger:b8,leftx:a0,lefty:a1,rightshoulder:b11,rightstick:b2,righttrigger:b9,rightx:a2,righty:a3,start:b3,x:b15,y:b12,",
- "4c05000000000000c405000000000000,PS4 Controller,a:b1,b:b2,back:b8,dpdown:h0.4,dpleft:h0.8,dpright:h0.2,dpup:h0.1,guide:b12,leftshoulder:b4,leftstick:b10,lefttrigger:a3,leftx:a0,lefty:a1,rightshoulder:b5,rightstick:b11,righttrigger:a4,rightx:a2,righty:a5,start:b9,x:b0,y:b3,",
- "351200000000000021ab000000000000,SFC30 Joystick,a:b1,b:b0,back:b10,leftshoulder:b6,leftx:a0,lefty:a1,rightshoulder:b7,start:b11,x:b4,y:b3,",
- "11010000000000002014000000000000,SteelSeries Nimbus,a:b0,b:b1,dpdown:b9,dpleft:b11,dpright:b10,dpup:b8,leftshoulder:b4,lefttrigger:b6,leftx:a0,lefty:a1,rightshoulder:b5,righttrigger:b7,rightx:a2,righty:a3,start:b12,x:b2,y:b3,",
- "11010000000000001714000000000000,SteelSeries Stratus XL,a:b0,b:b1,dpdown:b9,dpleft:b11,dpright:b10,dpup:b8,leftshoulder:b4,lefttrigger:b6,leftx:a0,lefty:a1,rightshoulder:b5,righttrigger:b7,rightx:a2,righty:a3,start:b12,x:b2,y:b3,",
- "5e040000000000008e02000000000000,X360 Controller,a:b0,b:b1,back:b9,dpdown:b12,dpleft:b13,dpright:b14,dpup:b11,guide:b10,leftshoulder:b4,leftstick:b6,lefttrigger:a2,leftx:a0,lefty:a1,rightshoulder:b5,rightstick:b7,righttrigger:a5,rightx:a3,righty:a4,start:b8,x:b2,y:b3,",
-#endif
-#if defined(__LINUX__)
- "05000000102800000900000000010000,8Bitdo SFC30 GamePad,a:b1,b:b0,back:b10,leftshoulder:b6,leftx:a0,lefty:a1,rightshoulder:b7,start:b11,x:b4,y:b3,",
- "03000000100000008200000011010000,Akishop Customs PS360+ v1.66,a:b1,b:b2,back:b12,dpdown:h0.4,dpleft:h0.8,dpright:h0.2,dpup:h0.1,guide:b8,leftshoulder:b4,lefttrigger:b6,rightshoulder:b5,righttrigger:b7,start:b9,x:b0,y:b3,",
- "03000000e82000006058000001010000,Cideko AK08b,a:b2,b:b1,back:b8,dpdown:h0.4,dpleft:h0.8,dpright:h0.2,dpup:h0.1,leftshoulder:b4,leftstick:b10,lefttrigger:b6,leftx:a0,lefty:a1,rightshoulder:b5,rightstick:b11,righttrigger:b7,rightx:a2,righty:a3,start:b9,x:b3,y:b0,",
- "0500000047532047616d657061640000,GameStop Gamepad,a:b0,b:b1,back:b8,dpdown:h0.4,dpleft:h0.8,dpright:h0.2,dpup:h0.1,guide:,leftshoulder:b4,leftstick:b10,lefttrigger:b6,leftx:a0,lefty:a1,rightshoulder:b5,rightstick:b11,righttrigger:b7,rightx:a2,righty:a3,start:b9,x:b2,y:b3,",
- "030000006f0e00000104000000010000,Gamestop Logic3 Controller,a:b0,b:b1,back:b6,dpdown:h0.4,dpleft:h0.8,dpright:h0.2,dpup:h0.1,guide:b8,leftshoulder:b4,leftstick:b9,lefttrigger:a2,leftx:a0,lefty:a1,rightshoulder:b5,rightstick:b10,righttrigger:a5,rightx:a3,righty:a4,start:b7,x:b2,y:b3,",
- "03000000ba2200002010000001010000,Jess Technology USB Game Controller,a:b2,b:b1,back:b8,dpdown:h0.4,dpleft:h0.8,dpright:h0.2,dpup:h0.1,guide:,leftshoulder:b4,lefttrigger:b6,leftx:a0,lefty:a1,rightshoulder:b5,righttrigger:b7,rightx:a3,righty:a2,start:b9,x:b3,y:b0,",
- "030000006d04000019c2000010010000,Logitech Cordless RumblePad 2,a:b1,b:b2,back:b8,dpdown:h0.4,dpleft:h0.8,dpright:h0.2,dpup:h0.1,guide:,leftshoulder:b4,leftstick:b10,lefttrigger:b6,leftx:a0,lefty:a1,rightshoulder:b5,rightstick:b11,righttrigger:b7,rightx:a2,righty:a3,start:b9,x:b0,y:b3,",
- "030000006d0400001dc2000014400000,Logitech F310 Gamepad (XInput),a:b0,b:b1,back:b6,dpdown:h0.4,dpleft:h0.8,dpright:h0.2,dpup:h0.1,guide:b8,leftshoulder:b4,leftstick:b9,lefttrigger:a2,leftx:a0,lefty:a1,rightshoulder:b5,rightstick:b10,righttrigger:a5,rightx:a3,righty:a4,start:b7,x:b2,y:b3,",
- "030000006d0400001ec2000020200000,Logitech F510 Gamepad (XInput),a:b0,b:b1,back:b6,dpdown:h0.4,dpleft:h0.8,dpright:h0.2,dpup:h0.1,guide:b8,leftshoulder:b4,leftstick:b9,lefttrigger:a2,leftx:a0,lefty:a1,rightshoulder:b5,rightstick:b10,righttrigger:a5,rightx:a3,righty:a4,start:b7,x:b2,y:b3,",
- "030000006d04000019c2000011010000,Logitech F710 Gamepad (DInput),a:b1,b:b2,back:b8,dpdown:h0.4,dpleft:h0.8,dpright:h0.2,dpup:h0.1,leftshoulder:b4,leftstick:b10,lefttrigger:b6,leftx:a0,lefty:a1,rightshoulder:b5,rightstick:b11,righttrigger:b7,rightx:a2,righty:a3,start:b9,x:b0,y:b3,", /* Guide button doesn't seem to be sent in DInput mode. */
- "030000006d0400001fc2000005030000,Logitech F710 Gamepad (XInput),a:b0,b:b1,back:b6,dpdown:h0.4,dpleft:h0.8,dpright:h0.2,dpup:h0.1,guide:b8,leftshoulder:b4,leftstick:b9,lefttrigger:a2,leftx:a0,lefty:a1,rightshoulder:b5,rightstick:b10,righttrigger:a5,rightx:a3,righty:a4,start:b7,x:b2,y:b3,",
- "030000006d04000018c2000010010000,Logitech RumblePad 2,a:b1,b:b2,back:b8,dpdown:h0.4,dpleft:h0.8,dpright:h0.2,dpup:h0.1,leftshoulder:b4,leftstick:b10,lefttrigger:b6,leftx:a0,lefty:a1,rightshoulder:b5,rightstick:b11,righttrigger:b7,rightx:a2,righty:a3,start:b9,x:b0,y:b3,",
- "03000000380700008433000011010000,Mad Catz FightStick TE S+ PS3,a:b1,b:b2,back:b8,dpdown:h0.4,dpleft:h0.8,dpright:h0.2,dpup:h0.1,guide:b12,leftshoulder:b4,lefttrigger:b6,leftx:a0,lefty:a1,rightshoulder:b5,righttrigger:b7,rightx:a2,righty:a3,start:b9,x:b0,y:b3,",
- "03000000380700008483000011010000,Mad Catz FightStick TE S+ PS4,a:b1,b:b2,back:b8,dpdown:h0.4,dpleft:h0.8,dpright:h0.2,dpup:h0.1,guide:b12,leftshoulder:b4,lefttrigger:a3,leftx:a0,lefty:a1,rightshoulder:b5,righttrigger:a4,rightx:a2,righty:a5,start:b9,x:b0,y:b3,",
- "03000000380700003847000090040000,Mad Catz Wired Xbox 360 Controller (SFIV),a:b0,b:b1,back:b8,dpdown:h0.4,dpleft:h0.8,dpright:h0.2,dpup:h0.1,guide:b10,leftshoulder:b4,lefttrigger:b6,leftx:a0,lefty:a1,rightshoulder:b5,righttrigger:b7,rightx:a2,righty:a3,start:b9,x:b2,y:b3,",
- "03000000380700008034000011010000,Mad Catz fightstick (PS3),a:b1,b:b2,back:b8,dpdown:h0.4,dpleft:h0.8,dpright:h0.2,dpup:h0.1,guide:b12,leftshoulder:b4,lefttrigger:b6,leftx:a0,lefty:a1,rightshoulder:b5,righttrigger:b7,rightx:a2,righty:a3,start:b9,x:b0,y:b3,",
- "03000000380700008084000011010000,Mad Catz fightstick (PS4),a:b1,b:b2,back:b8,dpdown:h0.4,dpleft:h0.8,dpright:h0.2,dpup:h0.1,guide:b12,leftshoulder:b4,lefttrigger:a3,leftx:a0,lefty:a1,rightshoulder:b5,righttrigger:a4,rightx:a2,righty:a5,start:b9,x:b0,y:b3,",
- "03000000380700001888000010010000,MadCatz PC USB Wired Stick 8818,a:b1,b:b2,back:b8,dpdown:h0.4,dpleft:h0.8,dpright:h0.2,dpup:h0.1,guide:b12,leftshoulder:b4,lefttrigger:b6,leftx:a0,lefty:a1,rightshoulder:b5,righttrigger:b7,rightx:a2,righty:a3,start:b9,x:b0,y:b3,",
- "03000000550900001072000011010000,NVIDIA Controller,a:b0,b:b1,dpdown:h0.4,dpleft:h0.8,dpright:h0.2,dpup:h0.1,leftshoulder:b4,leftstick:b8,lefttrigger:a5,leftx:a0,lefty:a1,rightshoulder:b5,rightstick:b9,righttrigger:a4,rightx:a2,righty:a3,start:b7,x:b2,y:b3,",
- "050000007e0500003003000001000000,Nintendo Wii Remote Pro Controller,a:b1,b:b0,back:b8,dpdown:b14,dpleft:b15,dpright:b16,dpup:b13,guide:b10,leftshoulder:b4,leftstick:b11,lefttrigger:b6,leftx:a0,lefty:a1,rightshoulder:b5,rightstick:b12,righttrigger:b7,rightx:a2,righty:a3,start:b9,x:b2,y:b3,",
- "050000003620000100000002010000,OUYA Game Controller,a:b0,b:b3,dpdown:b9,dpleft:b10,dpright:b11,dpup:b8,guide:b14,leftshoulder:b4,leftstick:b6,lefttrigger:a2,leftx:a0,lefty:a1,rightshoulder:b5,rightstick:b7,righttrigger:a5,rightx:a3,righty:a4,x:b1,y:b2,",
- "030000004c0500006802000011010000,PS3 Controller,a:b14,b:b13,back:b0,dpdown:b6,dpleft:b7,dpright:b5,dpup:b4,guide:b16,leftshoulder:b10,leftstick:b1,lefttrigger:b8,leftx:a0,lefty:a1,rightshoulder:b11,rightstick:b2,righttrigger:b9,rightx:a2,righty:a3,start:b3,x:b15,y:b12,",
- "03000000341a00003608000011010000,PS3 Controller,a:b1,b:b2,back:b8,dpdown:h0.4,dpleft:h0.8,dpright:h0.2,dpup:h0.1,guide:b12,leftshoulder:b4,leftstick:b10,lefttrigger:b6,leftx:a0,lefty:a1,rightshoulder:b5,rightstick:b11,righttrigger:b7,rightx:a2,righty:a3,start:b9,x:b0,y:b3,",
- "030000004c050000c405000011010000,PS4 Controller,a:b1,b:b2,back:b8,dpdown:h0.4,dpleft:h0.8,dpright:h0.2,dpup:h0.1,guide:b12,leftshoulder:b4,leftstick:b10,lefttrigger:a3,leftx:a0,lefty:a1,rightshoulder:b5,rightstick:b11,righttrigger:a4,rightx:a2,righty:a5,start:b9,x:b0,y:b3,",
- "050000004c050000c405000000010000,PS4 Controller,a:b1,b:b2,back:b8,dpdown:h0.4,dpleft:h0.8,dpright:h0.2,dpup:h0.1,guide:b12,leftshoulder:b4,leftstick:b10,lefttrigger:a3,leftx:a0,lefty:a1,rightshoulder:b5,rightstick:b11,righttrigger:a4,rightx:a2,righty:a5,start:b9,x:b0,y:b3,",
- "030000004c050000cc09000011010000,PS4 Controller,a:b1,b:b2,back:b8,dpdown:h0.4,dpleft:h0.8,dpright:h0.2,dpup:h0.1,guide:b12,leftshoulder:b4,leftstick:b10,lefttrigger:a3,leftx:a0,lefty:a1,rightshoulder:b5,rightstick:b11,righttrigger:a4,rightx:a2,righty:a5,start:b9,x:b0,y:b3,",
- "050000004c050000cc09000000010000,PS4 Controller,a:b1,b:b2,back:b8,dpdown:h0.4,dpleft:h0.8,dpright:h0.2,dpup:h0.1,guide:b12,leftshoulder:b4,leftstick:b10,lefttrigger:a3,leftx:a0,lefty:a1,rightshoulder:b5,rightstick:b11,righttrigger:a4,rightx:a2,righty:a5,start:b9,x:b0,y:b3,",
- "03000000c6240000045d000025010000,Razer Sabertooth,a:b0,b:b1,back:b6,dpdown:h0.4,dpleft:h0.8,dpright:h0.2,dpup:h0.1,guide:b8,leftshoulder:b4,leftstick:b9,lefttrigger:a2,leftx:a0,lefty:a1,rightshoulder:b5,rightstick:b10,righttrigger:a5,rightx:a3,righty:a4,start:b7,x:b2,y:b3,",
- "03000000321500000009000011010000,Razer Serval,a:b0,b:b1,back:b6,dpdown:h0.4,dpleft:h0.8,dpright:h0.2,dpup:h0.1,guide:b8,leftshoulder:b4,leftstick:b9,lefttrigger:a5,leftx:a0,lefty:a1,rightshoulder:b5,rightstick:b10,righttrigger:a4,rightx:a2,righty:a3,start:b7,x:b2,y:b3,",
- "050000003215000000090000163a0000,Razer Serval,a:b0,b:b1,back:b6,dpdown:h0.4,dpleft:h0.8,dpright:h0.2,dpup:h0.1,guide:b8,leftshoulder:b4,leftstick:b9,lefttrigger:a5,leftx:a0,lefty:a1,rightshoulder:b5,rightstick:b10,righttrigger:a4,rightx:a2,righty:a3,start:b7,x:b2,y:b3,",
- "03000000de280000fc11000001000000,Steam Controller,a:b0,b:b1,back:b6,dpdown:h0.4,dpleft:h0.8,dpright:h0.2,dpup:h0.1,guide:b8,leftshoulder:b4,leftstick:b9,lefttrigger:a2,leftx:a0,lefty:a1,rightshoulder:b5,rightstick:b10,righttrigger:a5,rightx:a3,righty:a4,start:b7,x:b2,y:b3,",
- "03000000de280000ff11000001000000,Valve Streaming Gamepad,a:b0,b:b1,back:b6,dpdown:h0.4,dpleft:h0.8,dpright:h0.2,dpup:h0.1,guide:b8,leftshoulder:b4,leftstick:b9,lefttrigger:a2,leftx:a0,lefty:a1,rightshoulder:b5,rightstick:b10,righttrigger:a5,rightx:a3,righty:a4,start:b7,x:b2,y:b3,",
- "xinput,XInput Controller,a:b0,b:b1,back:b6,dpdown:h0.4,dpleft:h0.8,dpright:h0.2,dpup:h0.1,guide:b8,leftshoulder:b4,leftstick:b9,lefttrigger:a2,leftx:a0,lefty:a1,rightshoulder:b5,rightstick:b10,righttrigger:a5,rightx:a3,righty:a4,start:b7,x:b2,y:b3,",
- "050000005e040000e002000003090000,Xbox One Wireless Controller,a:b0,b:b1,back:b6,dpdown:h0.4,dpleft:h0.8,dpright:h0.2,dpup:h0.1,guide:b10,leftshoulder:b4,leftstick:b8,lefttrigger:a2,leftx:a0,lefty:a1,rightshoulder:b5,rightstick:b9,righttrigger:a5,rightx:a3,righty:a4,start:b7,x:b2,y:b3,",
- "030000005e040000d102000001010000,Xbox One Wireless Controller,a:b0,b:b1,back:b6,dpdown:h0.4,dpleft:h0.8,dpright:h0.2,dpup:h0.1,guide:b8,leftshoulder:b4,leftstick:b9,lefttrigger:a2,leftx:a0,lefty:a1,rightshoulder:b5,rightstick:b10,righttrigger:a5,rightx:a3,righty:a4,start:b7,x:b2,y:b3,",
-#endif
-#if defined(__ANDROID__)
- "4e564944494120436f72706f72617469,NVIDIA Controller,a:b0,b:b1,dpdown:h0.4,dpleft:h0.8,dpright:h0.2,dpup:h0.1,leftshoulder:b9,leftstick:b7,lefttrigger:a4,leftx:a0,lefty:a1,rightshoulder:b10,rightstick:b8,righttrigger:a5,rightx:a2,righty:a3,start:b6,x:b2,y:b3,",
-#endif
-#if defined(SDL_JOYSTICK_MFI)
- "4d466947616d65706164010000000000,MFi Extended Gamepad,a:b0,b:b1,dpdown:h0.4,dpleft:h0.8,dpright:h0.2,dpup:h0.1,leftshoulder:b4,lefttrigger:a2,leftx:a0,lefty:a1,rightshoulder:b5,righttrigger:a5,rightx:a3,righty:a4,start:b6,x:b2,y:b3,",
- "4d466947616d65706164020000000000,MFi Gamepad,a:b0,b:b1,dpdown:h0.4,dpleft:h0.8,dpright:h0.2,dpup:h0.1,leftshoulder:b4,rightshoulder:b5,start:b6,x:b2,y:b3,",
-#endif
-#if defined(SDL_JOYSTICK_EMSCRIPTEN)
- "emscripten,Standard Gamepad,a:b0,b:b1,back:b8,dpdown:b13,dpleft:b14,dpright:b15,dpup:b12,guide:b16,leftshoulder:b4,leftstick:b10,lefttrigger:b6,leftx:a0,lefty:a1,rightshoulder:b5,rightstick:b11,righttrigger:b7,rightx:a2,righty:a3,start:b9,x:b2,y:b3,",
-#endif
- NULL
-};
-
-/* vi: set ts=4 sw=4 expandtab: */
diff --git a/3rdparty/SDL2/src/joystick/SDL_joystick.c b/3rdparty/SDL2/src/joystick/SDL_joystick.c
deleted file mode 100644
index c426a39e516..00000000000
--- a/3rdparty/SDL2/src/joystick/SDL_joystick.c
+++ /dev/null
@@ -1,929 +0,0 @@
-/*
- Simple DirectMedia Layer
- Copyright (C) 1997-2016 Sam Lantinga <slouken@libsdl.org>
-
- This software is provided 'as-is', without any express or implied
- warranty. In no event will the authors be held liable for any damages
- arising from the use of this software.
-
- Permission is granted to anyone to use this software for any purpose,
- including commercial applications, and to alter it and redistribute it
- freely, subject to the following restrictions:
-
- 1. The origin of this software must not be misrepresented; you must not
- claim that you wrote the original software. If you use this software
- in a product, an acknowledgment in the product documentation would be
- appreciated but is not required.
- 2. Altered source versions must be plainly marked as such, and must not be
- misrepresented as being the original software.
- 3. This notice may not be removed or altered from any source distribution.
-*/
-#include "../SDL_internal.h"
-
-/* This is the joystick API for Simple DirectMedia Layer */
-
-#include "SDL.h"
-#include "SDL_events.h"
-#include "SDL_sysjoystick.h"
-#include "SDL_assert.h"
-#include "SDL_hints.h"
-
-#if !SDL_EVENTS_DISABLED
-#include "../events/SDL_events_c.h"
-#endif
-
-static SDL_bool SDL_joystick_allows_background_events = SDL_FALSE;
-static SDL_Joystick *SDL_joysticks = NULL;
-static SDL_Joystick *SDL_updating_joystick = NULL;
-
-static void
-SDL_JoystickAllowBackgroundEventsChanged(void *userdata, const char *name, const char *oldValue, const char *hint)
-{
- if (hint && *hint == '1') {
- SDL_joystick_allows_background_events = SDL_TRUE;
- } else {
- SDL_joystick_allows_background_events = SDL_FALSE;
- }
-}
-
-int
-SDL_JoystickInit(void)
-{
- int status;
-
- /* See if we should allow joystick events while in the background */
- SDL_AddHintCallback(SDL_HINT_JOYSTICK_ALLOW_BACKGROUND_EVENTS,
- SDL_JoystickAllowBackgroundEventsChanged, NULL);
-
-#if !SDL_EVENTS_DISABLED
- if (SDL_InitSubSystem(SDL_INIT_EVENTS) < 0) {
- return -1;
- }
-#endif /* !SDL_EVENTS_DISABLED */
-
- status = SDL_SYS_JoystickInit();
- if (status >= 0) {
- status = 0;
- }
- return (status);
-}
-
-/*
- * Count the number of joysticks attached to the system
- */
-int
-SDL_NumJoysticks(void)
-{
- return SDL_SYS_NumJoysticks();
-}
-
-/*
- * Get the implementation dependent name of a joystick
- */
-const char *
-SDL_JoystickNameForIndex(int device_index)
-{
- if ((device_index < 0) || (device_index >= SDL_NumJoysticks())) {
- SDL_SetError("There are %d joysticks available", SDL_NumJoysticks());
- return (NULL);
- }
- return (SDL_SYS_JoystickNameForDeviceIndex(device_index));
-}
-
-/*
- * Open a joystick for use - the index passed as an argument refers to
- * the N'th joystick on the system. This index is the value which will
- * identify this joystick in future joystick events.
- *
- * This function returns a joystick identifier, or NULL if an error occurred.
- */
-SDL_Joystick *
-SDL_JoystickOpen(int device_index)
-{
- SDL_Joystick *joystick;
- SDL_Joystick *joysticklist;
- const char *joystickname = NULL;
-
- if ((device_index < 0) || (device_index >= SDL_NumJoysticks())) {
- SDL_SetError("There are %d joysticks available", SDL_NumJoysticks());
- return (NULL);
- }
-
- joysticklist = SDL_joysticks;
- /* If the joystick is already open, return it
- * it is important that we have a single joystick * for each instance id
- */
- while (joysticklist) {
- if (SDL_SYS_GetInstanceIdOfDeviceIndex(device_index) == joysticklist->instance_id) {
- joystick = joysticklist;
- ++joystick->ref_count;
- return (joystick);
- }
- joysticklist = joysticklist->next;
- }
-
- /* Create and initialize the joystick */
- joystick = (SDL_Joystick *) SDL_malloc((sizeof *joystick));
- if (joystick == NULL) {
- SDL_OutOfMemory();
- return NULL;
- }
-
- SDL_memset(joystick, 0, (sizeof *joystick));
- if (SDL_SYS_JoystickOpen(joystick, device_index) < 0) {
- SDL_free(joystick);
- return NULL;
- }
-
- joystickname = SDL_SYS_JoystickNameForDeviceIndex(device_index);
- if (joystickname)
- joystick->name = SDL_strdup(joystickname);
- else
- joystick->name = NULL;
-
- if (joystick->naxes > 0) {
- joystick->axes = (Sint16 *) SDL_malloc(joystick->naxes * sizeof(Sint16));
- joystick->axes_zero = (Sint16 *) SDL_malloc(joystick->naxes * sizeof(Sint16));
- }
- if (joystick->nhats > 0) {
- joystick->hats = (Uint8 *) SDL_malloc
- (joystick->nhats * sizeof(Uint8));
- }
- if (joystick->nballs > 0) {
- joystick->balls = (struct balldelta *) SDL_malloc
- (joystick->nballs * sizeof(*joystick->balls));
- }
- if (joystick->nbuttons > 0) {
- joystick->buttons = (Uint8 *) SDL_malloc
- (joystick->nbuttons * sizeof(Uint8));
- }
- if (((joystick->naxes > 0) && !joystick->axes)
- || ((joystick->nhats > 0) && !joystick->hats)
- || ((joystick->nballs > 0) && !joystick->balls)
- || ((joystick->nbuttons > 0) && !joystick->buttons)) {
- SDL_OutOfMemory();
- SDL_JoystickClose(joystick);
- return NULL;
- }
- if (joystick->axes) {
- SDL_memset(joystick->axes, 0, joystick->naxes * sizeof(Sint16));
- SDL_memset(joystick->axes_zero, 0, joystick->naxes * sizeof(Sint16));
- }
- if (joystick->hats) {
- SDL_memset(joystick->hats, 0, joystick->nhats * sizeof(Uint8));
- }
- if (joystick->balls) {
- SDL_memset(joystick->balls, 0,
- joystick->nballs * sizeof(*joystick->balls));
- }
- if (joystick->buttons) {
- SDL_memset(joystick->buttons, 0, joystick->nbuttons * sizeof(Uint8));
- }
- joystick->epowerlevel = SDL_JOYSTICK_POWER_UNKNOWN;
-
- /* Add joystick to list */
- ++joystick->ref_count;
- /* Link the joystick in the list */
- joystick->next = SDL_joysticks;
- SDL_joysticks = joystick;
-
- SDL_SYS_JoystickUpdate(joystick);
-
- return (joystick);
-}
-
-
-/*
- * Checks to make sure the joystick is valid.
- */
-int
-SDL_PrivateJoystickValid(SDL_Joystick * joystick)
-{
- int valid;
-
- if (joystick == NULL) {
- SDL_SetError("Joystick hasn't been opened yet");
- valid = 0;
- } else {
- valid = 1;
- }
-
- return valid;
-}
-
-/*
- * Get the number of multi-dimensional axis controls on a joystick
- */
-int
-SDL_JoystickNumAxes(SDL_Joystick * joystick)
-{
- if (!SDL_PrivateJoystickValid(joystick)) {
- return (-1);
- }
- return (joystick->naxes);
-}
-
-/*
- * Get the number of hats on a joystick
- */
-int
-SDL_JoystickNumHats(SDL_Joystick * joystick)
-{
- if (!SDL_PrivateJoystickValid(joystick)) {
- return (-1);
- }
- return (joystick->nhats);
-}
-
-/*
- * Get the number of trackballs on a joystick
- */
-int
-SDL_JoystickNumBalls(SDL_Joystick * joystick)
-{
- if (!SDL_PrivateJoystickValid(joystick)) {
- return (-1);
- }
- return (joystick->nballs);
-}
-
-/*
- * Get the number of buttons on a joystick
- */
-int
-SDL_JoystickNumButtons(SDL_Joystick * joystick)
-{
- if (!SDL_PrivateJoystickValid(joystick)) {
- return (-1);
- }
- return (joystick->nbuttons);
-}
-
-/*
- * Get the current state of an axis control on a joystick
- */
-Sint16
-SDL_JoystickGetAxis(SDL_Joystick * joystick, int axis)
-{
- Sint16 state;
-
- if (!SDL_PrivateJoystickValid(joystick)) {
- return (0);
- }
- if (axis < joystick->naxes) {
- state = joystick->axes[axis];
- } else {
- SDL_SetError("Joystick only has %d axes", joystick->naxes);
- state = 0;
- }
- return (state);
-}
-
-/*
- * Get the current state of a hat on a joystick
- */
-Uint8
-SDL_JoystickGetHat(SDL_Joystick * joystick, int hat)
-{
- Uint8 state;
-
- if (!SDL_PrivateJoystickValid(joystick)) {
- return (0);
- }
- if (hat < joystick->nhats) {
- state = joystick->hats[hat];
- } else {
- SDL_SetError("Joystick only has %d hats", joystick->nhats);
- state = 0;
- }
- return (state);
-}
-
-/*
- * Get the ball axis change since the last poll
- */
-int
-SDL_JoystickGetBall(SDL_Joystick * joystick, int ball, int *dx, int *dy)
-{
- int retval;
-
- if (!SDL_PrivateJoystickValid(joystick)) {
- return (-1);
- }
-
- retval = 0;
- if (ball < joystick->nballs) {
- if (dx) {
- *dx = joystick->balls[ball].dx;
- }
- if (dy) {
- *dy = joystick->balls[ball].dy;
- }
- joystick->balls[ball].dx = 0;
- joystick->balls[ball].dy = 0;
- } else {
- return SDL_SetError("Joystick only has %d balls", joystick->nballs);
- }
- return (retval);
-}
-
-/*
- * Get the current state of a button on a joystick
- */
-Uint8
-SDL_JoystickGetButton(SDL_Joystick * joystick, int button)
-{
- Uint8 state;
-
- if (!SDL_PrivateJoystickValid(joystick)) {
- return (0);
- }
- if (button < joystick->nbuttons) {
- state = joystick->buttons[button];
- } else {
- SDL_SetError("Joystick only has %d buttons", joystick->nbuttons);
- state = 0;
- }
- return (state);
-}
-
-/*
- * Return if the joystick in question is currently attached to the system,
- * \return SDL_FALSE if not plugged in, SDL_TRUE if still present.
- */
-SDL_bool
-SDL_JoystickGetAttached(SDL_Joystick * joystick)
-{
- if (!SDL_PrivateJoystickValid(joystick)) {
- return SDL_FALSE;
- }
-
- return SDL_SYS_JoystickAttached(joystick);
-}
-
-/*
- * Get the instance id for this opened joystick
- */
-SDL_JoystickID
-SDL_JoystickInstanceID(SDL_Joystick * joystick)
-{
- if (!SDL_PrivateJoystickValid(joystick)) {
- return (-1);
- }
-
- return (joystick->instance_id);
-}
-
-/*
- * Find the SDL_Joystick that owns this instance id
- */
-SDL_Joystick *
-SDL_JoystickFromInstanceID(SDL_JoystickID joyid)
-{
- SDL_Joystick *joystick = SDL_joysticks;
- while (joystick) {
- if (joystick->instance_id == joyid) {
- return joystick;
- }
- joystick = joystick->next;
- }
-
- return NULL;
-}
-
-/*
- * Get the friendly name of this joystick
- */
-const char *
-SDL_JoystickName(SDL_Joystick * joystick)
-{
- if (!SDL_PrivateJoystickValid(joystick)) {
- return (NULL);
- }
-
- return (joystick->name);
-}
-
-/*
- * Close a joystick previously opened with SDL_JoystickOpen()
- */
-void
-SDL_JoystickClose(SDL_Joystick * joystick)
-{
- SDL_Joystick *joysticklist;
- SDL_Joystick *joysticklistprev;
-
- if (!joystick) {
- return;
- }
-
- /* First decrement ref count */
- if (--joystick->ref_count > 0) {
- return;
- }
-
- if (joystick == SDL_updating_joystick) {
- return;
- }
-
- SDL_SYS_JoystickClose(joystick);
- joystick->hwdata = NULL;
-
- joysticklist = SDL_joysticks;
- joysticklistprev = NULL;
- while (joysticklist) {
- if (joystick == joysticklist) {
- if (joysticklistprev) {
- /* unlink this entry */
- joysticklistprev->next = joysticklist->next;
- } else {
- SDL_joysticks = joystick->next;
- }
- break;
- }
- joysticklistprev = joysticklist;
- joysticklist = joysticklist->next;
- }
-
- SDL_free(joystick->name);
-
- /* Free the data associated with this joystick */
- SDL_free(joystick->axes);
- SDL_free(joystick->hats);
- SDL_free(joystick->balls);
- SDL_free(joystick->buttons);
- SDL_free(joystick);
-}
-
-void
-SDL_JoystickQuit(void)
-{
- /* Make sure we're not getting called in the middle of updating joysticks */
- SDL_assert(!SDL_updating_joystick);
-
- /* Stop the event polling */
- while (SDL_joysticks) {
- SDL_joysticks->ref_count = 1;
- SDL_JoystickClose(SDL_joysticks);
- }
-
- /* Quit the joystick setup */
- SDL_SYS_JoystickQuit();
-
-#if !SDL_EVENTS_DISABLED
- SDL_QuitSubSystem(SDL_INIT_EVENTS);
-#endif
-}
-
-
-static SDL_bool
-SDL_PrivateJoystickShouldIgnoreEvent()
-{
- if (SDL_joystick_allows_background_events) {
- return SDL_FALSE;
- }
-
- if (SDL_WasInit(SDL_INIT_VIDEO)) {
- if (SDL_GetKeyboardFocus() == NULL) {
- /* Video is initialized and we don't have focus, ignore the event. */
- return SDL_TRUE;
- } else {
- return SDL_FALSE;
- }
- }
-
- /* Video subsystem wasn't initialized, always allow the event */
- return SDL_FALSE;
-}
-
-/* These are global for SDL_sysjoystick.c and SDL_events.c */
-
-void SDL_PrivateJoystickAdded(int device_index)
-{
-#if !SDL_EVENTS_DISABLED
- SDL_Event event;
-
- event.type = SDL_JOYDEVICEADDED;
-
- if (SDL_GetEventState(event.type) == SDL_ENABLE) {
- event.jdevice.which = device_index;
- if ( (SDL_EventOK == NULL) ||
- (*SDL_EventOK) (SDL_EventOKParam, &event) ) {
- SDL_PushEvent(&event);
- }
- }
-#endif /* !SDL_EVENTS_DISABLED */
-}
-
-/*
- * If there is an existing add event in the queue, it needs to be modified
- * to have the right value for which, because the number of controllers in
- * the system is now one less.
- */
-static void UpdateEventsForDeviceRemoval()
-{
- int i, num_events;
- SDL_Event *events;
-
- num_events = SDL_PeepEvents(NULL, 0, SDL_PEEKEVENT, SDL_JOYDEVICEADDED, SDL_JOYDEVICEADDED);
- if (num_events <= 0) {
- return;
- }
-
- events = SDL_stack_alloc(SDL_Event, num_events);
- if (!events) {
- return;
- }
-
- num_events = SDL_PeepEvents(events, num_events, SDL_GETEVENT, SDL_JOYDEVICEADDED, SDL_JOYDEVICEADDED);
- for (i = 0; i < num_events; ++i) {
- --events[i].jdevice.which;
- }
- SDL_PeepEvents(events, num_events, SDL_ADDEVENT, 0, 0);
-
- SDL_stack_free(events);
-}
-
-void SDL_PrivateJoystickRemoved(SDL_JoystickID device_instance)
-{
-#if !SDL_EVENTS_DISABLED
- SDL_Event event;
-
- event.type = SDL_JOYDEVICEREMOVED;
-
- if (SDL_GetEventState(event.type) == SDL_ENABLE) {
- event.jdevice.which = device_instance;
- if ( (SDL_EventOK == NULL) ||
- (*SDL_EventOK) (SDL_EventOKParam, &event) ) {
- SDL_PushEvent(&event);
- }
- }
-
- UpdateEventsForDeviceRemoval();
-#endif /* !SDL_EVENTS_DISABLED */
-}
-
-int
-SDL_PrivateJoystickAxis(SDL_Joystick * joystick, Uint8 axis, Sint16 value)
-{
- int posted;
-
- /* Make sure we're not getting garbage or duplicate events */
- if (axis >= joystick->naxes) {
- return 0;
- }
- if (value == joystick->axes[axis]) {
- return 0;
- }
-
- /* We ignore events if we don't have keyboard focus, except for centering
- * events.
- */
- if (SDL_PrivateJoystickShouldIgnoreEvent()) {
- if ((value > joystick->axes_zero[axis] && value >= joystick->axes[axis]) ||
- (value < joystick->axes_zero[axis] && value <= joystick->axes[axis])) {
- return 0;
- }
- }
-
- /* Update internal joystick state */
- joystick->axes[axis] = value;
-
- /* Post the event, if desired */
- posted = 0;
-#if !SDL_EVENTS_DISABLED
- if (SDL_GetEventState(SDL_JOYAXISMOTION) == SDL_ENABLE) {
- SDL_Event event;
- event.type = SDL_JOYAXISMOTION;
- event.jaxis.which = joystick->instance_id;
- event.jaxis.axis = axis;
- event.jaxis.value = value;
- posted = SDL_PushEvent(&event) == 1;
- }
-#endif /* !SDL_EVENTS_DISABLED */
- return (posted);
-}
-
-int
-SDL_PrivateJoystickHat(SDL_Joystick * joystick, Uint8 hat, Uint8 value)
-{
- int posted;
-
- /* Make sure we're not getting garbage or duplicate events */
- if (hat >= joystick->nhats) {
- return 0;
- }
- if (value == joystick->hats[hat]) {
- return 0;
- }
-
- /* We ignore events if we don't have keyboard focus, except for centering
- * events.
- */
- if (SDL_PrivateJoystickShouldIgnoreEvent()) {
- if (value != SDL_HAT_CENTERED) {
- return 0;
- }
- }
-
- /* Update internal joystick state */
- joystick->hats[hat] = value;
-
- /* Post the event, if desired */
- posted = 0;
-#if !SDL_EVENTS_DISABLED
- if (SDL_GetEventState(SDL_JOYHATMOTION) == SDL_ENABLE) {
- SDL_Event event;
- event.jhat.type = SDL_JOYHATMOTION;
- event.jhat.which = joystick->instance_id;
- event.jhat.hat = hat;
- event.jhat.value = value;
- posted = SDL_PushEvent(&event) == 1;
- }
-#endif /* !SDL_EVENTS_DISABLED */
- return (posted);
-}
-
-int
-SDL_PrivateJoystickBall(SDL_Joystick * joystick, Uint8 ball,
- Sint16 xrel, Sint16 yrel)
-{
- int posted;
-
- /* Make sure we're not getting garbage events */
- if (ball >= joystick->nballs) {
- return 0;
- }
-
- /* We ignore events if we don't have keyboard focus. */
- if (SDL_PrivateJoystickShouldIgnoreEvent()) {
- return 0;
- }
-
- /* Update internal mouse state */
- joystick->balls[ball].dx += xrel;
- joystick->balls[ball].dy += yrel;
-
- /* Post the event, if desired */
- posted = 0;
-#if !SDL_EVENTS_DISABLED
- if (SDL_GetEventState(SDL_JOYBALLMOTION) == SDL_ENABLE) {
- SDL_Event event;
- event.jball.type = SDL_JOYBALLMOTION;
- event.jball.which = joystick->instance_id;
- event.jball.ball = ball;
- event.jball.xrel = xrel;
- event.jball.yrel = yrel;
- posted = SDL_PushEvent(&event) == 1;
- }
-#endif /* !SDL_EVENTS_DISABLED */
- return (posted);
-}
-
-int
-SDL_PrivateJoystickButton(SDL_Joystick * joystick, Uint8 button, Uint8 state)
-{
- int posted;
-#if !SDL_EVENTS_DISABLED
- SDL_Event event;
-
- switch (state) {
- case SDL_PRESSED:
- event.type = SDL_JOYBUTTONDOWN;
- break;
- case SDL_RELEASED:
- event.type = SDL_JOYBUTTONUP;
- break;
- default:
- /* Invalid state -- bail */
- return (0);
- }
-#endif /* !SDL_EVENTS_DISABLED */
-
- /* Make sure we're not getting garbage or duplicate events */
- if (button >= joystick->nbuttons) {
- return 0;
- }
- if (state == joystick->buttons[button]) {
- return 0;
- }
-
- /* We ignore events if we don't have keyboard focus, except for button
- * release. */
- if (SDL_PrivateJoystickShouldIgnoreEvent()) {
- if (state == SDL_PRESSED) {
- return 0;
- }
- }
-
- /* Update internal joystick state */
- joystick->buttons[button] = state;
-
- /* Post the event, if desired */
- posted = 0;
-#if !SDL_EVENTS_DISABLED
- if (SDL_GetEventState(event.type) == SDL_ENABLE) {
- event.jbutton.which = joystick->instance_id;
- event.jbutton.button = button;
- event.jbutton.state = state;
- posted = SDL_PushEvent(&event) == 1;
- }
-#endif /* !SDL_EVENTS_DISABLED */
- return (posted);
-}
-
-void
-SDL_JoystickUpdate(void)
-{
- SDL_Joystick *joystick;
-
- joystick = SDL_joysticks;
- while (joystick) {
- SDL_Joystick *joysticknext;
- /* save off the next pointer, the Update call may cause a joystick removed event
- * and cause our joystick pointer to be freed
- */
- joysticknext = joystick->next;
-
- SDL_updating_joystick = joystick;
-
- SDL_SYS_JoystickUpdate(joystick);
-
- if (joystick->force_recentering) {
- int i;
-
- /* Tell the app that everything is centered/unpressed... */
- for (i = 0; i < joystick->naxes; i++) {
- SDL_PrivateJoystickAxis(joystick, i, joystick->axes_zero[i]);
- }
-
- for (i = 0; i < joystick->nbuttons; i++) {
- SDL_PrivateJoystickButton(joystick, i, 0);
- }
-
- for (i = 0; i < joystick->nhats; i++) {
- SDL_PrivateJoystickHat(joystick, i, SDL_HAT_CENTERED);
- }
-
- joystick->force_recentering = SDL_FALSE;
- }
-
- SDL_updating_joystick = NULL;
-
- /* If the joystick was closed while updating, free it here */
- if (joystick->ref_count <= 0) {
- SDL_JoystickClose(joystick);
- }
-
- joystick = joysticknext;
- }
-
- /* this needs to happen AFTER walking the joystick list above, so that any
- dangling hardware data from removed devices can be free'd
- */
- SDL_SYS_JoystickDetect();
-}
-
-int
-SDL_JoystickEventState(int state)
-{
-#if SDL_EVENTS_DISABLED
- return SDL_DISABLE;
-#else
- const Uint32 event_list[] = {
- SDL_JOYAXISMOTION, SDL_JOYBALLMOTION, SDL_JOYHATMOTION,
- SDL_JOYBUTTONDOWN, SDL_JOYBUTTONUP, SDL_JOYDEVICEADDED, SDL_JOYDEVICEREMOVED
- };
- unsigned int i;
-
- switch (state) {
- case SDL_QUERY:
- state = SDL_DISABLE;
- for (i = 0; i < SDL_arraysize(event_list); ++i) {
- state = SDL_EventState(event_list[i], SDL_QUERY);
- if (state == SDL_ENABLE) {
- break;
- }
- }
- break;
- default:
- for (i = 0; i < SDL_arraysize(event_list); ++i) {
- SDL_EventState(event_list[i], state);
- }
- break;
- }
- return (state);
-#endif /* SDL_EVENTS_DISABLED */
-}
-
-/* return the guid for this index */
-SDL_JoystickGUID SDL_JoystickGetDeviceGUID(int device_index)
-{
- if ((device_index < 0) || (device_index >= SDL_NumJoysticks())) {
- SDL_JoystickGUID emptyGUID;
- SDL_SetError("There are %d joysticks available", SDL_NumJoysticks());
- SDL_zero(emptyGUID);
- return emptyGUID;
- }
- return SDL_SYS_JoystickGetDeviceGUID(device_index);
-}
-
-/* return the guid for this opened device */
-SDL_JoystickGUID SDL_JoystickGetGUID(SDL_Joystick * joystick)
-{
- if (!SDL_PrivateJoystickValid(joystick)) {
- SDL_JoystickGUID emptyGUID;
- SDL_zero(emptyGUID);
- return emptyGUID;
- }
- return SDL_SYS_JoystickGetGUID(joystick);
-}
-
-/* convert the guid to a printable string */
-void SDL_JoystickGetGUIDString(SDL_JoystickGUID guid, char *pszGUID, int cbGUID)
-{
- static const char k_rgchHexToASCII[] = "0123456789abcdef";
- int i;
-
- if ((pszGUID == NULL) || (cbGUID <= 0)) {
- return;
- }
-
- for (i = 0; i < sizeof(guid.data) && i < (cbGUID-1)/2; i++) {
- /* each input byte writes 2 ascii chars, and might write a null byte. */
- /* If we don't have room for next input byte, stop */
- unsigned char c = guid.data[i];
-
- *pszGUID++ = k_rgchHexToASCII[c >> 4];
- *pszGUID++ = k_rgchHexToASCII[c & 0x0F];
- }
- *pszGUID = '\0';
-}
-
-
-/*-----------------------------------------------------------------------------
- * Purpose: Returns the 4 bit nibble for a hex character
- * Input : c -
- * Output : unsigned char
- *-----------------------------------------------------------------------------*/
-static unsigned char nibble(char c)
-{
- if ((c >= '0') && (c <= '9')) {
- return (unsigned char)(c - '0');
- }
-
- if ((c >= 'A') && (c <= 'F')) {
- return (unsigned char)(c - 'A' + 0x0a);
- }
-
- if ((c >= 'a') && (c <= 'f')) {
- return (unsigned char)(c - 'a' + 0x0a);
- }
-
- /* received an invalid character, and no real way to return an error */
- /* AssertMsg1(false, "Q_nibble invalid hex character '%c' ", c); */
- return 0;
-}
-
-
-/* convert the string version of a joystick guid to the struct */
-SDL_JoystickGUID SDL_JoystickGetGUIDFromString(const char *pchGUID)
-{
- SDL_JoystickGUID guid;
- int maxoutputbytes= sizeof(guid);
- size_t len = SDL_strlen(pchGUID);
- Uint8 *p;
- size_t i;
-
- /* Make sure it's even */
- len = (len) & ~0x1;
-
- SDL_memset(&guid, 0x00, sizeof(guid));
-
- p = (Uint8 *)&guid;
- for (i = 0; (i < len) && ((p - (Uint8 *)&guid) < maxoutputbytes); i+=2, p++) {
- *p = (nibble(pchGUID[i]) << 4) | nibble(pchGUID[i+1]);
- }
-
- return guid;
-}
-
-
-/* update the power level for this joystick */
-void SDL_PrivateJoystickBatteryLevel(SDL_Joystick * joystick, SDL_JoystickPowerLevel ePowerLevel)
-{
- joystick->epowerlevel = ePowerLevel;
-}
-
-
-/* return its power level */
-SDL_JoystickPowerLevel SDL_JoystickCurrentPowerLevel(SDL_Joystick * joystick)
-{
- if (!SDL_PrivateJoystickValid(joystick)) {
- return (SDL_JOYSTICK_POWER_UNKNOWN);
- }
- return joystick->epowerlevel;
-}
-
-
-/* vi: set ts=4 sw=4 expandtab: */
diff --git a/3rdparty/SDL2/src/joystick/SDL_joystick_c.h b/3rdparty/SDL2/src/joystick/SDL_joystick_c.h
deleted file mode 100644
index cb9c92544cb..00000000000
--- a/3rdparty/SDL2/src/joystick/SDL_joystick_c.h
+++ /dev/null
@@ -1,52 +0,0 @@
-/*
- Simple DirectMedia Layer
- Copyright (C) 1997-2016 Sam Lantinga <slouken@libsdl.org>
-
- This software is provided 'as-is', without any express or implied
- warranty. In no event will the authors be held liable for any damages
- arising from the use of this software.
-
- Permission is granted to anyone to use this software for any purpose,
- including commercial applications, and to alter it and redistribute it
- freely, subject to the following restrictions:
-
- 1. The origin of this software must not be misrepresented; you must not
- claim that you wrote the original software. If you use this software
- in a product, an acknowledgment in the product documentation would be
- appreciated but is not required.
- 2. Altered source versions must be plainly marked as such, and must not be
- misrepresented as being the original software.
- 3. This notice may not be removed or altered from any source distribution.
-*/
-#include "../SDL_internal.h"
-
-/* Useful functions and variables from SDL_joystick.c */
-#include "SDL_joystick.h"
-
-/* Initialization and shutdown functions */
-extern int SDL_JoystickInit(void);
-extern void SDL_JoystickQuit(void);
-
-/* Initialization and shutdown functions */
-extern int SDL_GameControllerInit(void);
-extern void SDL_GameControllerQuit(void);
-
-
-/* Internal event queueing functions */
-extern void SDL_PrivateJoystickAdded(int device_index);
-extern void SDL_PrivateJoystickRemoved(SDL_JoystickID device_instance);
-extern int SDL_PrivateJoystickAxis(SDL_Joystick * joystick,
- Uint8 axis, Sint16 value);
-extern int SDL_PrivateJoystickBall(SDL_Joystick * joystick,
- Uint8 ball, Sint16 xrel, Sint16 yrel);
-extern int SDL_PrivateJoystickHat(SDL_Joystick * joystick,
- Uint8 hat, Uint8 value);
-extern int SDL_PrivateJoystickButton(SDL_Joystick * joystick,
- Uint8 button, Uint8 state);
-extern void SDL_PrivateJoystickBatteryLevel(SDL_Joystick * joystick,
- SDL_JoystickPowerLevel ePowerLevel);
-
-/* Internal sanity checking functions */
-extern int SDL_PrivateJoystickValid(SDL_Joystick * joystick);
-
-/* vi: set ts=4 sw=4 expandtab: */
diff --git a/3rdparty/SDL2/src/joystick/SDL_sysjoystick.h b/3rdparty/SDL2/src/joystick/SDL_sysjoystick.h
deleted file mode 100644
index f4cad05ec44..00000000000
--- a/3rdparty/SDL2/src/joystick/SDL_sysjoystick.h
+++ /dev/null
@@ -1,119 +0,0 @@
-/*
- Simple DirectMedia Layer
- Copyright (C) 1997-2016 Sam Lantinga <slouken@libsdl.org>
-
- This software is provided 'as-is', without any express or implied
- warranty. In no event will the authors be held liable for any damages
- arising from the use of this software.
-
- Permission is granted to anyone to use this software for any purpose,
- including commercial applications, and to alter it and redistribute it
- freely, subject to the following restrictions:
-
- 1. The origin of this software must not be misrepresented; you must not
- claim that you wrote the original software. If you use this software
- in a product, an acknowledgment in the product documentation would be
- appreciated but is not required.
- 2. Altered source versions must be plainly marked as such, and must not be
- misrepresented as being the original software.
- 3. This notice may not be removed or altered from any source distribution.
-*/
-#include "../SDL_internal.h"
-
-#ifndef _SDL_sysjoystick_h
-#define _SDL_sysjoystick_h
-
-/* This is the system specific header for the SDL joystick API */
-
-#include "SDL_joystick.h"
-#include "SDL_joystick_c.h"
-
-/* The SDL joystick structure */
-struct _SDL_Joystick
-{
- SDL_JoystickID instance_id; /* Device instance, monotonically increasing from 0 */
- char *name; /* Joystick name - system dependent */
-
- int naxes; /* Number of axis controls on the joystick */
- Sint16 *axes; /* Current axis states */
- Sint16 *axes_zero; /* Zero point on the axis (-32768 for triggers) */
-
- int nhats; /* Number of hats on the joystick */
- Uint8 *hats; /* Current hat states */
-
- int nballs; /* Number of trackballs on the joystick */
- struct balldelta {
- int dx;
- int dy;
- } *balls; /* Current ball motion deltas */
-
- int nbuttons; /* Number of buttons on the joystick */
- Uint8 *buttons; /* Current button states */
-
- struct joystick_hwdata *hwdata; /* Driver dependent information */
-
- int ref_count; /* Reference count for multiple opens */
-
- SDL_bool force_recentering; /* SDL_TRUE if this device needs to have its state reset to 0 */
- SDL_JoystickPowerLevel epowerlevel; /* power level of this joystick, SDL_JOYSTICK_POWER_UNKNOWN if not supported */
- struct _SDL_Joystick *next; /* pointer to next joystick we have allocated */
-};
-
-/* Function to scan the system for joysticks.
- * Joystick 0 should be the system default joystick.
- * This function should return the number of available joysticks, or -1
- * on an unrecoverable fatal error.
- */
-extern int SDL_SYS_JoystickInit(void);
-
-/* Function to return the number of joystick devices plugged in right now */
-extern int SDL_SYS_NumJoysticks();
-
-/* Function to cause any queued joystick insertions to be processed */
-extern void SDL_SYS_JoystickDetect();
-
-/* Function to get the device-dependent name of a joystick */
-extern const char *SDL_SYS_JoystickNameForDeviceIndex(int device_index);
-
-/* Function to get the current instance id of the joystick located at device_index */
-extern SDL_JoystickID SDL_SYS_GetInstanceIdOfDeviceIndex(int device_index);
-
-/* Function to open a joystick for use.
- The joystick to open is specified by the device index.
- This should fill the nbuttons and naxes fields of the joystick structure.
- It returns 0, or -1 if there is an error.
- */
-extern int SDL_SYS_JoystickOpen(SDL_Joystick * joystick, int device_index);
-
-/* Function to query if the joystick is currently attached
- * It returns SDL_TRUE if attached, SDL_FALSE otherwise.
- */
-extern SDL_bool SDL_SYS_JoystickAttached(SDL_Joystick * joystick);
-
-/* Function to update the state of a joystick - called as a device poll.
- * This function shouldn't update the joystick structure directly,
- * but instead should call SDL_PrivateJoystick*() to deliver events
- * and update joystick device state.
- */
-extern void SDL_SYS_JoystickUpdate(SDL_Joystick * joystick);
-
-/* Function to close a joystick after use */
-extern void SDL_SYS_JoystickClose(SDL_Joystick * joystick);
-
-/* Function to perform any system-specific joystick related cleanup */
-extern void SDL_SYS_JoystickQuit(void);
-
-/* Function to return the stable GUID for a plugged in device */
-extern SDL_JoystickGUID SDL_SYS_JoystickGetDeviceGUID(int device_index);
-
-/* Function to return the stable GUID for a opened joystick */
-extern SDL_JoystickGUID SDL_SYS_JoystickGetGUID(SDL_Joystick * joystick);
-
-#if SDL_JOYSTICK_XINPUT
-/* Function returns SDL_TRUE if this device is an XInput gamepad */
-extern SDL_bool SDL_SYS_IsXInputGamepad_DeviceIndex(int device_index);
-#endif
-
-#endif /* _SDL_sysjoystick_h */
-
-/* vi: set ts=4 sw=4 expandtab: */
diff --git a/3rdparty/SDL2/src/joystick/android/SDL_sysjoystick.c b/3rdparty/SDL2/src/joystick/android/SDL_sysjoystick.c
deleted file mode 100644
index a09e9a12c10..00000000000
--- a/3rdparty/SDL2/src/joystick/android/SDL_sysjoystick.c
+++ /dev/null
@@ -1,553 +0,0 @@
-/*
- Simple DirectMedia Layer
- Copyright (C) 1997-2016 Sam Lantinga <slouken@libsdl.org>
-
- This software is provided 'as-is', without any express or implied
- warranty. In no event will the authors be held liable for any damages
- arising from the use of this software.
-
- Permission is granted to anyone to use this software for any purpose,
- including commercial applications, and to alter it and redistribute it
- freely, subject to the following restrictions:
-
- 1. The origin of this software must not be misrepresented; you must not
- claim that you wrote the original software. If you use this software
- in a product, an acknowledgment in the product documentation would be
- appreciated but is not required.
- 2. Altered source versions must be plainly marked as such, and must not be
- misrepresented as being the original software.
- 3. This notice may not be removed or altered from any source distribution.
-*/
-
-#include "../../SDL_internal.h"
-
-#ifdef SDL_JOYSTICK_ANDROID
-
-#include <stdio.h> /* For the definition of NULL */
-#include "SDL_error.h"
-#include "SDL_events.h"
-
-#include "SDL_joystick.h"
-#include "SDL_hints.h"
-#include "SDL_assert.h"
-#include "SDL_timer.h"
-#include "SDL_log.h"
-#include "SDL_sysjoystick_c.h"
-#include "../SDL_joystick_c.h"
-#include "../../core/android/SDL_android.h"
-
-#include "android/keycodes.h"
-
-/* As of platform android-14, android/keycodes.h is missing these defines */
-#ifndef AKEYCODE_BUTTON_1
-#define AKEYCODE_BUTTON_1 188
-#define AKEYCODE_BUTTON_2 189
-#define AKEYCODE_BUTTON_3 190
-#define AKEYCODE_BUTTON_4 191
-#define AKEYCODE_BUTTON_5 192
-#define AKEYCODE_BUTTON_6 193
-#define AKEYCODE_BUTTON_7 194
-#define AKEYCODE_BUTTON_8 195
-#define AKEYCODE_BUTTON_9 196
-#define AKEYCODE_BUTTON_10 197
-#define AKEYCODE_BUTTON_11 198
-#define AKEYCODE_BUTTON_12 199
-#define AKEYCODE_BUTTON_13 200
-#define AKEYCODE_BUTTON_14 201
-#define AKEYCODE_BUTTON_15 202
-#define AKEYCODE_BUTTON_16 203
-#endif
-
-#define ANDROID_ACCELEROMETER_NAME "Android Accelerometer"
-#define ANDROID_ACCELEROMETER_DEVICE_ID INT_MIN
-#define ANDROID_MAX_NBUTTONS 36
-
-static SDL_joylist_item * JoystickByDeviceId(int device_id);
-
-static SDL_joylist_item *SDL_joylist = NULL;
-static SDL_joylist_item *SDL_joylist_tail = NULL;
-static int numjoysticks = 0;
-static int instance_counter = 0;
-
-
-/* Function to convert Android keyCodes into SDL ones.
- * This code manipulation is done to get a sequential list of codes.
- * FIXME: This is only suited for the case where we use a fixed number of buttons determined by ANDROID_MAX_NBUTTONS
- */
-static int
-keycode_to_SDL(int keycode)
-{
- /* FIXME: If this function gets too unwiedly in the future, replace with a lookup table */
- int button = 0;
- switch(keycode)
- {
- /* Some gamepad buttons (API 9) */
- case AKEYCODE_BUTTON_A:
- button = SDL_CONTROLLER_BUTTON_A;
- break;
- case AKEYCODE_BUTTON_B:
- button = SDL_CONTROLLER_BUTTON_B;
- break;
- case AKEYCODE_BUTTON_X:
- button = SDL_CONTROLLER_BUTTON_X;
- break;
- case AKEYCODE_BUTTON_Y:
- button = SDL_CONTROLLER_BUTTON_Y;
- break;
- case AKEYCODE_BUTTON_L1:
- button = SDL_CONTROLLER_BUTTON_LEFTSHOULDER;
- break;
- case AKEYCODE_BUTTON_R1:
- button = SDL_CONTROLLER_BUTTON_RIGHTSHOULDER;
- break;
- case AKEYCODE_BUTTON_THUMBL:
- button = SDL_CONTROLLER_BUTTON_LEFTSTICK;
- break;
- case AKEYCODE_BUTTON_THUMBR:
- button = SDL_CONTROLLER_BUTTON_RIGHTSTICK;
- break;
- case AKEYCODE_BUTTON_START:
- button = SDL_CONTROLLER_BUTTON_START;
- break;
- case AKEYCODE_BUTTON_SELECT:
- button = SDL_CONTROLLER_BUTTON_BACK;
- break;
- case AKEYCODE_BUTTON_MODE:
- button = SDL_CONTROLLER_BUTTON_GUIDE;
- break;
- case AKEYCODE_BUTTON_L2:
- button = SDL_CONTROLLER_BUTTON_MAX; /* Not supported by GameController */
- break;
- case AKEYCODE_BUTTON_R2:
- button = SDL_CONTROLLER_BUTTON_MAX+1; /* Not supported by GameController */
- break;
- case AKEYCODE_BUTTON_C:
- button = SDL_CONTROLLER_BUTTON_MAX+2; /* Not supported by GameController */
- break;
- case AKEYCODE_BUTTON_Z:
- button = SDL_CONTROLLER_BUTTON_MAX+3; /* Not supported by GameController */
- break;
-
- /* D-Pad key codes (API 1) */
- case AKEYCODE_DPAD_UP:
- button = SDL_CONTROLLER_BUTTON_DPAD_UP;
- break;
- case AKEYCODE_DPAD_DOWN:
- button = SDL_CONTROLLER_BUTTON_DPAD_DOWN;
- break;
- case AKEYCODE_DPAD_LEFT:
- button = SDL_CONTROLLER_BUTTON_DPAD_LEFT;
- break;
- case AKEYCODE_DPAD_RIGHT:
- button = SDL_CONTROLLER_BUTTON_DPAD_RIGHT;
- break;
- case AKEYCODE_DPAD_CENTER:
- button = SDL_CONTROLLER_BUTTON_MAX+4; /* Not supported by GameController */
- break;
-
- /* More gamepad buttons (API 12), these get mapped to 20...35*/
- case AKEYCODE_BUTTON_1:
- case AKEYCODE_BUTTON_2:
- case AKEYCODE_BUTTON_3:
- case AKEYCODE_BUTTON_4:
- case AKEYCODE_BUTTON_5:
- case AKEYCODE_BUTTON_6:
- case AKEYCODE_BUTTON_7:
- case AKEYCODE_BUTTON_8:
- case AKEYCODE_BUTTON_9:
- case AKEYCODE_BUTTON_10:
- case AKEYCODE_BUTTON_11:
- case AKEYCODE_BUTTON_12:
- case AKEYCODE_BUTTON_13:
- case AKEYCODE_BUTTON_14:
- case AKEYCODE_BUTTON_15:
- case AKEYCODE_BUTTON_16:
- button = keycode - AKEYCODE_BUTTON_1 + SDL_CONTROLLER_BUTTON_MAX + 5;
- break;
-
- default:
- return -1;
- break;
- }
-
- /* This is here in case future generations, probably with six fingers per hand,
- * happily add new cases up above and forget to update the max number of buttons.
- */
- SDL_assert(button < ANDROID_MAX_NBUTTONS);
- return button;
-
-}
-
-int
-Android_OnPadDown(int device_id, int keycode)
-{
- SDL_joylist_item *item;
- int button = keycode_to_SDL(keycode);
- if (button >= 0) {
- item = JoystickByDeviceId(device_id);
- if (item && item->joystick) {
- SDL_PrivateJoystickButton(item->joystick, button , SDL_PRESSED);
- }
- return 0;
- }
-
- return -1;
-}
-
-int
-Android_OnPadUp(int device_id, int keycode)
-{
- SDL_joylist_item *item;
- int button = keycode_to_SDL(keycode);
- if (button >= 0) {
- item = JoystickByDeviceId(device_id);
- if (item && item->joystick) {
- SDL_PrivateJoystickButton(item->joystick, button, SDL_RELEASED);
- }
- return 0;
- }
-
- return -1;
-}
-
-int
-Android_OnJoy(int device_id, int axis, float value)
-{
- /* Android gives joy info normalized as [-1.0, 1.0] or [0.0, 1.0] */
- SDL_joylist_item *item = JoystickByDeviceId(device_id);
- if (item && item->joystick) {
- SDL_PrivateJoystickAxis(item->joystick, axis, (Sint16) (32767.*value) );
- }
-
- return 0;
-}
-
-int
-Android_OnHat(int device_id, int hat_id, int x, int y)
-{
- const Uint8 position_map[3][3] = {
- {SDL_HAT_LEFTUP, SDL_HAT_UP, SDL_HAT_RIGHTUP},
- {SDL_HAT_LEFT, SDL_HAT_CENTERED, SDL_HAT_RIGHT},
- {SDL_HAT_LEFTDOWN, SDL_HAT_DOWN, SDL_HAT_RIGHTDOWN}
- };
-
- if (x >= -1 && x <=1 && y >= -1 && y <= 1) {
- SDL_joylist_item *item = JoystickByDeviceId(device_id);
- if (item && item->joystick) {
- SDL_PrivateJoystickHat(item->joystick, hat_id, position_map[y+1][x+1] );
- }
- return 0;
- }
-
- return -1;
-}
-
-
-int
-Android_AddJoystick(int device_id, const char *name, SDL_bool is_accelerometer, int nbuttons, int naxes, int nhats, int nballs)
-{
- SDL_JoystickGUID guid;
- SDL_joylist_item *item;
-
- if(JoystickByDeviceId(device_id) != NULL || name == NULL) {
- return -1;
- }
-
- /* the GUID is just the first 16 chars of the name for now */
- SDL_zero( guid );
- SDL_memcpy( &guid, name, SDL_min( sizeof(guid), SDL_strlen( name ) ) );
-
- item = (SDL_joylist_item *) SDL_malloc(sizeof (SDL_joylist_item));
- if (item == NULL) {
- return -1;
- }
-
- SDL_zerop(item);
- item->guid = guid;
- item->device_id = device_id;
- item->name = SDL_strdup(name);
- if ( item->name == NULL ) {
- SDL_free(item);
- return -1;
- }
-
- item->is_accelerometer = is_accelerometer;
- if (nbuttons > -1) {
- item->nbuttons = nbuttons;
- }
- else {
- item->nbuttons = ANDROID_MAX_NBUTTONS;
- }
- item->naxes = naxes;
- item->nhats = nhats;
- item->nballs = nballs;
- item->device_instance = instance_counter++;
- if (SDL_joylist_tail == NULL) {
- SDL_joylist = SDL_joylist_tail = item;
- } else {
- SDL_joylist_tail->next = item;
- SDL_joylist_tail = item;
- }
-
- /* Need to increment the joystick count before we post the event */
- ++numjoysticks;
-
- SDL_PrivateJoystickAdded(numjoysticks - 1);
-
-#ifdef DEBUG_JOYSTICK
- SDL_Log("Added joystick %s with device_id %d", name, device_id);
-#endif
-
- return numjoysticks;
-}
-
-int
-Android_RemoveJoystick(int device_id)
-{
- SDL_joylist_item *item = SDL_joylist;
- SDL_joylist_item *prev = NULL;
-
- /* Don't call JoystickByDeviceId here or there'll be an infinite loop! */
- while (item != NULL) {
- if (item->device_id == device_id) {
- break;
- }
- prev = item;
- item = item->next;
- }
-
- if (item == NULL) {
- return -1;
- }
-
- if (item->joystick) {
- item->joystick->hwdata = NULL;
- }
-
- if (prev != NULL) {
- prev->next = item->next;
- } else {
- SDL_assert(SDL_joylist == item);
- SDL_joylist = item->next;
- }
- if (item == SDL_joylist_tail) {
- SDL_joylist_tail = prev;
- }
-
- /* Need to decrement the joystick count before we post the event */
- --numjoysticks;
-
- SDL_PrivateJoystickRemoved(item->device_instance);
-
-#ifdef DEBUG_JOYSTICK
- SDL_Log("Removed joystick with device_id %d", device_id);
-#endif
-
- SDL_free(item->name);
- SDL_free(item);
- return numjoysticks;
-}
-
-
-int
-SDL_SYS_JoystickInit(void)
-{
- SDL_SYS_JoystickDetect();
-
- if (SDL_GetHintBoolean(SDL_HINT_ACCELEROMETER_AS_JOYSTICK, SDL_TRUE)) {
- /* Default behavior, accelerometer as joystick */
- Android_AddJoystick(ANDROID_ACCELEROMETER_DEVICE_ID, ANDROID_ACCELEROMETER_NAME, SDL_TRUE, 0, 3, 0, 0);
- }
-
- return (numjoysticks);
-
-}
-
-int SDL_SYS_NumJoysticks()
-{
- return numjoysticks;
-}
-
-void SDL_SYS_JoystickDetect()
-{
- /* Support for device connect/disconnect is API >= 16 only,
- * so we poll every three seconds
- * Ref: http://developer.android.com/reference/android/hardware/input/InputManager.InputDeviceListener.html
- */
- static Uint32 timeout = 0;
- if (SDL_TICKS_PASSED(SDL_GetTicks(), timeout)) {
- timeout = SDL_GetTicks() + 3000;
- Android_JNI_PollInputDevices();
- }
-}
-
-static SDL_joylist_item *
-JoystickByDevIndex(int device_index)
-{
- SDL_joylist_item *item = SDL_joylist;
-
- if ((device_index < 0) || (device_index >= numjoysticks)) {
- return NULL;
- }
-
- while (device_index > 0) {
- SDL_assert(item != NULL);
- device_index--;
- item = item->next;
- }
-
- return item;
-}
-
-static SDL_joylist_item *
-JoystickByDeviceId(int device_id)
-{
- SDL_joylist_item *item = SDL_joylist;
-
- while (item != NULL) {
- if (item->device_id == device_id) {
- return item;
- }
- item = item->next;
- }
-
- /* Joystick not found, try adding it */
- SDL_SYS_JoystickDetect();
-
- while (item != NULL) {
- if (item->device_id == device_id) {
- return item;
- }
- item = item->next;
- }
-
- return NULL;
-}
-
-/* Function to get the device-dependent name of a joystick */
-const char *
-SDL_SYS_JoystickNameForDeviceIndex(int device_index)
-{
- return JoystickByDevIndex(device_index)->name;
-}
-
-/* Function to perform the mapping from device index to the instance id for this index */
-SDL_JoystickID SDL_SYS_GetInstanceIdOfDeviceIndex(int device_index)
-{
- return JoystickByDevIndex(device_index)->device_instance;
-}
-
-/* Function to open a joystick for use.
- The joystick to open is specified by the device index.
- This should fill the nbuttons and naxes fields of the joystick structure.
- It returns 0, or -1 if there is an error.
- */
-int
-SDL_SYS_JoystickOpen(SDL_Joystick * joystick, int device_index)
-{
- SDL_joylist_item *item = JoystickByDevIndex(device_index);
-
- if (item == NULL ) {
- return SDL_SetError("No such device");
- }
-
- if (item->joystick != NULL) {
- return SDL_SetError("Joystick already opened");
- }
-
- joystick->instance_id = item->device_instance;
- joystick->hwdata = (struct joystick_hwdata *) item;
- item->joystick = joystick;
- joystick->nhats = item->nhats;
- joystick->nballs = item->nballs;
- joystick->nbuttons = item->nbuttons;
- joystick->naxes = item->naxes;
-
- return (0);
-}
-
-/* Function to determine if this joystick is attached to the system right now */
-SDL_bool SDL_SYS_JoystickAttached(SDL_Joystick *joystick)
-{
- return joystick->hwdata != NULL;
-}
-
-void
-SDL_SYS_JoystickUpdate(SDL_Joystick * joystick)
-{
- int i;
- Sint16 value;
- float values[3];
- SDL_joylist_item *item = SDL_joylist;
-
- while (item) {
- if (item->is_accelerometer) {
- if (item->joystick) {
- if (Android_JNI_GetAccelerometerValues(values)) {
- for ( i = 0; i < 3; i++ ) {
- if (values[i] > 1.0f) {
- values[i] = 1.0f;
- } else if (values[i] < -1.0f) {
- values[i] = -1.0f;
- }
-
- value = (Sint16)(values[i] * 32767.0f);
- SDL_PrivateJoystickAxis(item->joystick, i, value);
- }
- }
- }
- break;
- }
- item = item->next;
- }
-}
-
-/* Function to close a joystick after use */
-void
-SDL_SYS_JoystickClose(SDL_Joystick * joystick)
-{
- SDL_joylist_item *item = (SDL_joylist_item *) joystick->hwdata;
- if (item) {
- item->joystick = NULL;
- }
-}
-
-/* Function to perform any system-specific joystick related cleanup */
-void
-SDL_SYS_JoystickQuit(void)
-{
- SDL_joylist_item *item = NULL;
- SDL_joylist_item *next = NULL;
-
- for (item = SDL_joylist; item; item = next) {
- next = item->next;
- SDL_free(item->name);
- SDL_free(item);
- }
-
- SDL_joylist = SDL_joylist_tail = NULL;
-
- numjoysticks = 0;
- instance_counter = 0;
-}
-
-SDL_JoystickGUID SDL_SYS_JoystickGetDeviceGUID( int device_index )
-{
- return JoystickByDevIndex(device_index)->guid;
-}
-
-SDL_JoystickGUID SDL_SYS_JoystickGetGUID(SDL_Joystick * joystick)
-{
- SDL_JoystickGUID guid;
-
- if (joystick->hwdata != NULL) {
- return ((SDL_joylist_item*)joystick->hwdata)->guid;
- }
-
- SDL_zero(guid);
- return guid;
-}
-
-#endif /* SDL_JOYSTICK_ANDROID */
-
-/* vi: set ts=4 sw=4 expandtab: */
diff --git a/3rdparty/SDL2/src/joystick/android/SDL_sysjoystick_c.h b/3rdparty/SDL2/src/joystick/android/SDL_sysjoystick_c.h
deleted file mode 100644
index 51803db35a3..00000000000
--- a/3rdparty/SDL2/src/joystick/android/SDL_sysjoystick_c.h
+++ /dev/null
@@ -1,52 +0,0 @@
-/*
- Simple DirectMedia Layer
- Copyright (C) 1997-2016 Sam Lantinga <slouken@libsdl.org>
-
- This software is provided 'as-is', without any express or implied
- warranty. In no event will the authors be held liable for any damages
- arising from the use of this software.
-
- Permission is granted to anyone to use this software for any purpose,
- including commercial applications, and to alter it and redistribute it
- freely, subject to the following restrictions:
-
- 1. The origin of this software must not be misrepresented; you must not
- claim that you wrote the original software. If you use this software
- in a product, an acknowledgment in the product documentation would be
- appreciated but is not required.
- 2. Altered source versions must be plainly marked as such, and must not be
- misrepresented as being the original software.
- 3. This notice may not be removed or altered from any source distribution.
-*/
-
-#include "../../SDL_internal.h"
-
-#ifdef SDL_JOYSTICK_ANDROID
-#include "../SDL_sysjoystick.h"
-
-extern int Android_OnPadDown(int device_id, int keycode);
-extern int Android_OnPadUp(int device_id, int keycode);
-extern int Android_OnJoy(int device_id, int axisnum, float value);
-extern int Android_OnHat(int device_id, int hat_id, int x, int y);
-extern int Android_AddJoystick(int device_id, const char *name, SDL_bool is_accelerometer, int nbuttons, int naxes, int nhats, int nballs);
-extern int Android_RemoveJoystick(int device_id);
-
-/* A linked list of available joysticks */
-typedef struct SDL_joylist_item
-{
- int device_instance;
- int device_id; /* Android's device id */
- char *name; /* "SideWinder 3D Pro" or whatever */
- SDL_JoystickGUID guid;
- SDL_bool is_accelerometer;
- SDL_Joystick *joystick;
- int nbuttons, naxes, nhats, nballs;
-
- struct SDL_joylist_item *next;
-} SDL_joylist_item;
-
-typedef SDL_joylist_item joystick_hwdata;
-
-#endif /* SDL_JOYSTICK_ANDROID */
-
-/* vi: set ts=4 sw=4 expandtab: */
diff --git a/3rdparty/SDL2/src/joystick/bsd/SDL_sysjoystick.c b/3rdparty/SDL2/src/joystick/bsd/SDL_sysjoystick.c
deleted file mode 100644
index ddc899f6e55..00000000000
--- a/3rdparty/SDL2/src/joystick/bsd/SDL_sysjoystick.c
+++ /dev/null
@@ -1,697 +0,0 @@
-/*
- Simple DirectMedia Layer
- Copyright (C) 1997-2016 Sam Lantinga <slouken@libsdl.org>
-
- This software is provided 'as-is', without any express or implied
- warranty. In no event will the authors be held liable for any damages
- arising from the use of this software.
-
- Permission is granted to anyone to use this software for any purpose,
- including commercial applications, and to alter it and redistribute it
- freely, subject to the following restrictions:
-
- 1. The origin of this software must not be misrepresented; you must not
- claim that you wrote the original software. If you use this software
- in a product, an acknowledgment in the product documentation would be
- appreciated but is not required.
- 2. Altered source versions must be plainly marked as such, and must not be
- misrepresented as being the original software.
- 3. This notice may not be removed or altered from any source distribution.
-*/
-#include "../../SDL_internal.h"
-
-#ifdef SDL_JOYSTICK_USBHID
-
-/*
- * Joystick driver for the uhid(4) interface found in OpenBSD,
- * NetBSD and FreeBSD.
- *
- * Maintainer: <vedge at csoft.org>
- */
-
-#include <sys/param.h>
-
-#include <unistd.h>
-#include <fcntl.h>
-#include <errno.h>
-
-#ifndef __FreeBSD_kernel_version
-#define __FreeBSD_kernel_version __FreeBSD_version
-#endif
-
-#if defined(HAVE_USB_H)
-#include <usb.h>
-#endif
-#ifdef __DragonFly__
-#include <bus/usb/usb.h>
-#include <bus/usb/usbhid.h>
-#else
-#include <dev/usb/usb.h>
-#include <dev/usb/usbhid.h>
-#endif
-
-#if defined(HAVE_USBHID_H)
-#include <usbhid.h>
-#elif defined(HAVE_LIBUSB_H)
-#include <libusb.h>
-#elif defined(HAVE_LIBUSBHID_H)
-#include <libusbhid.h>
-#endif
-
-#if defined(__FREEBSD__) || defined(__FreeBSD_kernel__)
-#ifndef __DragonFly__
-#include <osreldate.h>
-#endif
-#if __FreeBSD_kernel_version > 800063
-#include <dev/usb/usb_ioctl.h>
-#endif
-#include <sys/joystick.h>
-#endif
-
-#if SDL_JOYSTICK_USBHID_MACHINE_JOYSTICK_H
-#include <machine/joystick.h>
-#endif
-
-#include "SDL_joystick.h"
-#include "../SDL_sysjoystick.h"
-#include "../SDL_joystick_c.h"
-
-#define MAX_UHID_JOYS 64
-#define MAX_JOY_JOYS 2
-#define MAX_JOYS (MAX_UHID_JOYS + MAX_JOY_JOYS)
-
-
-struct report
-{
-#if defined(__FREEBSD__) && (__FreeBSD_kernel_version > 900000)
- void *buf; /* Buffer */
-#elif defined(__FREEBSD__) && (__FreeBSD_kernel_version > 800063)
- struct usb_gen_descriptor *buf; /* Buffer */
-#else
- struct usb_ctl_report *buf; /* Buffer */
-#endif
- size_t size; /* Buffer size */
- int rid; /* Report ID */
- enum
- {
- SREPORT_UNINIT,
- SREPORT_CLEAN,
- SREPORT_DIRTY
- } status;
-};
-
-static struct
-{
- int uhid_report;
- hid_kind_t kind;
- const char *name;
-} const repinfo[] = {
- {UHID_INPUT_REPORT, hid_input, "input"},
- {UHID_OUTPUT_REPORT, hid_output, "output"},
- {UHID_FEATURE_REPORT, hid_feature, "feature"}
-};
-
-enum
-{
- REPORT_INPUT = 0,
- REPORT_OUTPUT = 1,
- REPORT_FEATURE = 2
-};
-
-enum
-{
- JOYAXE_X,
- JOYAXE_Y,
- JOYAXE_Z,
- JOYAXE_SLIDER,
- JOYAXE_WHEEL,
- JOYAXE_RX,
- JOYAXE_RY,
- JOYAXE_RZ,
- JOYAXE_count
-};
-
-struct joystick_hwdata
-{
- int fd;
- char *path;
- enum
- {
- BSDJOY_UHID, /* uhid(4) */
- BSDJOY_JOY /* joy(4) */
- } type;
- struct report_desc *repdesc;
- struct report inreport;
- int axis_map[JOYAXE_count]; /* map present JOYAXE_* to 0,1,.. */
-};
-
-static char *joynames[MAX_JOYS];
-static char *joydevnames[MAX_JOYS];
-
-static int report_alloc(struct report *, struct report_desc *, int);
-static void report_free(struct report *);
-
-#if defined(USBHID_UCR_DATA) || (defined(__FreeBSD_kernel__) && __FreeBSD_kernel_version <= 800063)
-#define REP_BUF_DATA(rep) ((rep)->buf->ucr_data)
-#elif (defined(__FREEBSD__) && (__FreeBSD_kernel_version > 900000))
-#define REP_BUF_DATA(rep) ((rep)->buf)
-#elif (defined(__FREEBSD__) && (__FreeBSD_kernel_version > 800063))
-#define REP_BUF_DATA(rep) ((rep)->buf->ugd_data)
-#else
-#define REP_BUF_DATA(rep) ((rep)->buf->data)
-#endif
-
-static int SDL_SYS_numjoysticks = 0;
-
-int
-SDL_SYS_JoystickInit(void)
-{
- char s[16];
- int i, fd;
-
- SDL_SYS_numjoysticks = 0;
-
- SDL_memset(joynames, 0, sizeof(joynames));
- SDL_memset(joydevnames, 0, sizeof(joydevnames));
-
- for (i = 0; i < MAX_UHID_JOYS; i++) {
- SDL_Joystick nj;
-
- SDL_snprintf(s, SDL_arraysize(s), "/dev/uhid%d", i);
-
- joynames[SDL_SYS_numjoysticks] = SDL_strdup(s);
-
- if (SDL_SYS_JoystickOpen(&nj, SDL_SYS_numjoysticks) == 0) {
- SDL_SYS_JoystickClose(&nj);
- SDL_SYS_numjoysticks++;
- } else {
- SDL_free(joynames[SDL_SYS_numjoysticks]);
- joynames[SDL_SYS_numjoysticks] = NULL;
- }
- }
- for (i = 0; i < MAX_JOY_JOYS; i++) {
- SDL_snprintf(s, SDL_arraysize(s), "/dev/joy%d", i);
- fd = open(s, O_RDONLY);
- if (fd != -1) {
- joynames[SDL_SYS_numjoysticks++] = SDL_strdup(s);
- close(fd);
- }
- }
-
- /* Read the default USB HID usage table. */
- hid_init(NULL);
-
- return (SDL_SYS_numjoysticks);
-}
-
-int SDL_SYS_NumJoysticks()
-{
- return SDL_SYS_numjoysticks;
-}
-
-void SDL_SYS_JoystickDetect()
-{
-}
-
-const char *
-SDL_SYS_JoystickNameForDeviceIndex(int device_index)
-{
- if (joydevnames[device_index] != NULL) {
- return (joydevnames[device_index]);
- }
- return (joynames[device_index]);
-}
-
-/* Function to perform the mapping from device index to the instance id for this index */
-SDL_JoystickID SDL_SYS_GetInstanceIdOfDeviceIndex(int device_index)
-{
- return device_index;
-}
-
-static int
-usage_to_joyaxe(unsigned usage)
-{
- int joyaxe;
- switch (usage) {
- case HUG_X:
- joyaxe = JOYAXE_X;
- break;
- case HUG_Y:
- joyaxe = JOYAXE_Y;
- break;
- case HUG_Z:
- joyaxe = JOYAXE_Z;
- break;
- case HUG_SLIDER:
- joyaxe = JOYAXE_SLIDER;
- break;
- case HUG_WHEEL:
- joyaxe = JOYAXE_WHEEL;
- break;
- case HUG_RX:
- joyaxe = JOYAXE_RX;
- break;
- case HUG_RY:
- joyaxe = JOYAXE_RY;
- break;
- case HUG_RZ:
- joyaxe = JOYAXE_RZ;
- break;
- default:
- joyaxe = -1;
- }
- return joyaxe;
-}
-
-static unsigned
-hatval_to_sdl(Sint32 hatval)
-{
- static const unsigned hat_dir_map[8] = {
- SDL_HAT_UP, SDL_HAT_RIGHTUP, SDL_HAT_RIGHT, SDL_HAT_RIGHTDOWN,
- SDL_HAT_DOWN, SDL_HAT_LEFTDOWN, SDL_HAT_LEFT, SDL_HAT_LEFTUP
- };
- unsigned result;
- if ((hatval & 7) == hatval)
- result = hat_dir_map[hatval];
- else
- result = SDL_HAT_CENTERED;
- return result;
-}
-
-
-int
-SDL_SYS_JoystickOpen(SDL_Joystick * joy, int device_index)
-{
- char *path = joynames[device_index];
- struct joystick_hwdata *hw;
- struct hid_item hitem;
- struct hid_data *hdata;
- struct report *rep = NULL;
- int fd;
- int i;
-
- fd = open(path, O_RDONLY);
- if (fd == -1) {
- return SDL_SetError("%s: %s", path, strerror(errno));
- }
-
- joy->instance_id = device_index;
- hw = (struct joystick_hwdata *)
- SDL_malloc(sizeof(struct joystick_hwdata));
- if (hw == NULL) {
- close(fd);
- return SDL_OutOfMemory();
- }
- joy->hwdata = hw;
- hw->fd = fd;
- hw->path = SDL_strdup(path);
- if (!SDL_strncmp(path, "/dev/joy", 8)) {
- hw->type = BSDJOY_JOY;
- joy->naxes = 2;
- joy->nbuttons = 2;
- joy->nhats = 0;
- joy->nballs = 0;
- joydevnames[device_index] = SDL_strdup("Gameport joystick");
- goto usbend;
- } else {
- hw->type = BSDJOY_UHID;
- }
-
- {
- int ax;
- for (ax = 0; ax < JOYAXE_count; ax++)
- hw->axis_map[ax] = -1;
- }
- hw->repdesc = hid_get_report_desc(fd);
- if (hw->repdesc == NULL) {
- SDL_SetError("%s: USB_GET_REPORT_DESC: %s", hw->path,
- strerror(errno));
- goto usberr;
- }
- rep = &hw->inreport;
-#if defined(__FREEBSD__) && (__FreeBSD_kernel_version > 800063) || defined(__FreeBSD_kernel__)
- rep->rid = hid_get_report_id(fd);
- if (rep->rid < 0) {
-#else
- if (ioctl(fd, USB_GET_REPORT_ID, &rep->rid) < 0) {
-#endif
- rep->rid = -1; /* XXX */
- }
-#if defined(__NetBSD__)
- usb_device_descriptor_t udd;
- struct usb_string_desc usd;
- if (ioctl(fd, USB_GET_DEVICE_DESC, &udd) == -1)
- goto desc_failed;
-
- /* Get default language */
- usd.usd_string_index = USB_LANGUAGE_TABLE;
- usd.usd_language_id = 0;
- if (ioctl(fd, USB_GET_STRING_DESC, &usd) == -1 || usd.usd_desc.bLength < 4) {
- usd.usd_language_id = 0;
- } else {
- usd.usd_language_id = UGETW(usd.usd_desc.bString[0]);
- }
-
- usd.usd_string_index = udd.iProduct;
- if (ioctl(fd, USB_GET_STRING_DESC, &usd) == 0) {
- char str[128];
- char *new_name = NULL;
- int i;
- for (i = 0; i < (usd.usd_desc.bLength >> 1) - 1 && i < sizeof(str) - 1; i++) {
- str[i] = UGETW(usd.usd_desc.bString[i]);
- }
- str[i] = '\0';
- asprintf(&new_name, "%s @ %s", str, path);
- if (new_name != NULL) {
- SDL_free(joydevnames[SDL_SYS_numjoysticks]);
- joydevnames[SDL_SYS_numjoysticks] = new_name;
- }
- }
-desc_failed:
-#endif
- if (report_alloc(rep, hw->repdesc, REPORT_INPUT) < 0) {
- goto usberr;
- }
- if (rep->size <= 0) {
- SDL_SetError("%s: Input report descriptor has invalid length",
- hw->path);
- goto usberr;
- }
-#if defined(USBHID_NEW) || (defined(__FREEBSD__) && __FreeBSD_kernel_version >= 500111) || defined(__FreeBSD_kernel__)
- hdata = hid_start_parse(hw->repdesc, 1 << hid_input, rep->rid);
-#else
- hdata = hid_start_parse(hw->repdesc, 1 << hid_input);
-#endif
- if (hdata == NULL) {
- SDL_SetError("%s: Cannot start HID parser", hw->path);
- goto usberr;
- }
- joy->naxes = 0;
- joy->nbuttons = 0;
- joy->nhats = 0;
- joy->nballs = 0;
- for (i = 0; i < JOYAXE_count; i++)
- hw->axis_map[i] = -1;
-
- while (hid_get_item(hdata, &hitem) > 0) {
- char *sp;
- const char *s;
-
- switch (hitem.kind) {
- case hid_collection:
- switch (HID_PAGE(hitem.usage)) {
- case HUP_GENERIC_DESKTOP:
- switch (HID_USAGE(hitem.usage)) {
- case HUG_JOYSTICK:
- case HUG_GAME_PAD:
- s = hid_usage_in_page(hitem.usage);
- sp = SDL_malloc(SDL_strlen(s) + 5);
- SDL_snprintf(sp, SDL_strlen(s) + 5, "%s (%d)",
- s, device_index);
- joydevnames[device_index] = sp;
- }
- }
- break;
- case hid_input:
- switch (HID_PAGE(hitem.usage)) {
- case HUP_GENERIC_DESKTOP:
- {
- unsigned usage = HID_USAGE(hitem.usage);
- int joyaxe = usage_to_joyaxe(usage);
- if (joyaxe >= 0) {
- hw->axis_map[joyaxe] = 1;
- } else if (usage == HUG_HAT_SWITCH) {
- joy->nhats++;
- }
- break;
- }
- case HUP_BUTTON:
- joy->nbuttons++;
- break;
- default:
- break;
- }
- break;
- default:
- break;
- }
- }
- hid_end_parse(hdata);
- for (i = 0; i < JOYAXE_count; i++)
- if (hw->axis_map[i] > 0)
- hw->axis_map[i] = joy->naxes++;
-
- if (joy->naxes == 0 && joy->nbuttons == 0 && joy->nhats == 0 && joy->nballs == 0) {
- SDL_SetError("%s: Not a joystick, ignoring", hw->path);
- goto usberr;
- }
-
- usbend:
- /* The poll blocks the event thread. */
- fcntl(fd, F_SETFL, O_NONBLOCK);
-#ifdef __NetBSD__
- /* Flush pending events */
- if (rep) {
- while (read(joy->hwdata->fd, REP_BUF_DATA(rep), rep->size) == rep->size)
- ;
- }
-#endif
-
- return (0);
- usberr:
- close(hw->fd);
- SDL_free(hw->path);
- SDL_free(hw);
- return (-1);
-}
-
-/* Function to determine if this joystick is attached to the system right now */
-SDL_bool SDL_SYS_JoystickAttached(SDL_Joystick *joystick)
-{
- return SDL_TRUE;
-}
-
-void
-SDL_SYS_JoystickUpdate(SDL_Joystick * joy)
-{
- struct hid_item hitem;
- struct hid_data *hdata;
- struct report *rep;
- int nbutton, naxe = -1;
- Sint32 v;
-
-#if defined(__FREEBSD__) || SDL_JOYSTICK_USBHID_MACHINE_JOYSTICK_H || defined(__FreeBSD_kernel__)
- struct joystick gameport;
- static int x, y, xmin = 0xffff, ymin = 0xffff, xmax = 0, ymax = 0;
-
- if (joy->hwdata->type == BSDJOY_JOY) {
- while (read(joy->hwdata->fd, &gameport, sizeof gameport) == sizeof gameport) {
- if (abs(x - gameport.x) > 8) {
- x = gameport.x;
- if (x < xmin) {
- xmin = x;
- }
- if (x > xmax) {
- xmax = x;
- }
- if (xmin == xmax) {
- xmin--;
- xmax++;
- }
- v = (Sint32) x;
- v -= (xmax + xmin + 1) / 2;
- v *= 32768 / ((xmax - xmin + 1) / 2);
- SDL_PrivateJoystickAxis(joy, 0, v);
- }
- if (abs(y - gameport.y) > 8) {
- y = gameport.y;
- if (y < ymin) {
- ymin = y;
- }
- if (y > ymax) {
- ymax = y;
- }
- if (ymin == ymax) {
- ymin--;
- ymax++;
- }
- v = (Sint32) y;
- v -= (ymax + ymin + 1) / 2;
- v *= 32768 / ((ymax - ymin + 1) / 2);
- SDL_PrivateJoystickAxis(joy, 1, v);
- }
- if (gameport.b1 != joy->buttons[0]) {
- SDL_PrivateJoystickButton(joy, 0, gameport.b1);
- }
- if (gameport.b2 != joy->buttons[1]) {
- SDL_PrivateJoystickButton(joy, 1, gameport.b2);
- }
- }
- return;
- }
-#endif /* defined(__FREEBSD__) || SDL_JOYSTICK_USBHID_MACHINE_JOYSTICK_H */
-
- rep = &joy->hwdata->inreport;
-
- while (read(joy->hwdata->fd, REP_BUF_DATA(rep), rep->size) == rep->size) {
-#if defined(USBHID_NEW) || (defined(__FREEBSD__) && __FreeBSD_kernel_version >= 500111) || defined(__FreeBSD_kernel__)
- hdata = hid_start_parse(joy->hwdata->repdesc, 1 << hid_input, rep->rid);
-#else
- hdata = hid_start_parse(joy->hwdata->repdesc, 1 << hid_input);
-#endif
- if (hdata == NULL) {
- /*fprintf(stderr, "%s: Cannot start HID parser\n", joy->hwdata->path);*/
- continue;
- }
-
- for (nbutton = 0; hid_get_item(hdata, &hitem) > 0;) {
- switch (hitem.kind) {
- case hid_input:
- switch (HID_PAGE(hitem.usage)) {
- case HUP_GENERIC_DESKTOP:
- {
- unsigned usage = HID_USAGE(hitem.usage);
- int joyaxe = usage_to_joyaxe(usage);
- if (joyaxe >= 0) {
- naxe = joy->hwdata->axis_map[joyaxe];
- /* scaleaxe */
- v = (Sint32) hid_get_data(REP_BUF_DATA(rep), &hitem);
- v -= (hitem.logical_maximum +
- hitem.logical_minimum + 1) / 2;
- v *= 32768 /
- ((hitem.logical_maximum -
- hitem.logical_minimum + 1) / 2);
- if (v != joy->axes[naxe]) {
- SDL_PrivateJoystickAxis(joy, naxe, v);
- }
- } else if (usage == HUG_HAT_SWITCH) {
- v = (Sint32) hid_get_data(REP_BUF_DATA(rep), &hitem);
- SDL_PrivateJoystickHat(joy, 0,
- hatval_to_sdl(v) -
- hitem.logical_minimum);
- }
- break;
- }
- case HUP_BUTTON:
- v = (Sint32) hid_get_data(REP_BUF_DATA(rep), &hitem);
- if (joy->buttons[nbutton] != v) {
- SDL_PrivateJoystickButton(joy, nbutton, v);
- }
- nbutton++;
- break;
- default:
- continue;
- }
- break;
- default:
- break;
- }
- }
- hid_end_parse(hdata);
- }
-}
-
-/* Function to close a joystick after use */
-void
-SDL_SYS_JoystickClose(SDL_Joystick * joy)
-{
- if (SDL_strncmp(joy->hwdata->path, "/dev/joy", 8)) {
- report_free(&joy->hwdata->inreport);
- hid_dispose_report_desc(joy->hwdata->repdesc);
- }
- close(joy->hwdata->fd);
- SDL_free(joy->hwdata->path);
- SDL_free(joy->hwdata);
-}
-
-void
-SDL_SYS_JoystickQuit(void)
-{
- int i;
-
- for (i = 0; i < MAX_JOYS; i++) {
- SDL_free(joynames[i]);
- SDL_free(joydevnames[i]);
- }
-
- return;
-}
-
-SDL_JoystickGUID SDL_SYS_JoystickGetDeviceGUID( int device_index )
-{
- SDL_JoystickGUID guid;
- /* the GUID is just the first 16 chars of the name for now */
- const char *name = SDL_SYS_JoystickNameForDeviceIndex( device_index );
- SDL_zero( guid );
- SDL_memcpy( &guid, name, SDL_min( sizeof(guid), SDL_strlen( name ) ) );
- return guid;
-}
-
-SDL_JoystickGUID SDL_SYS_JoystickGetGUID(SDL_Joystick * joystick)
-{
- SDL_JoystickGUID guid;
- /* the GUID is just the first 16 chars of the name for now */
- const char *name = joystick->name;
- SDL_zero( guid );
- SDL_memcpy( &guid, name, SDL_min( sizeof(guid), SDL_strlen( name ) ) );
- return guid;
-}
-
-static int
-report_alloc(struct report *r, struct report_desc *rd, int repind)
-{
- int len;
-
-#ifdef __DragonFly__
- len = hid_report_size(rd, r->rid, repinfo[repind].kind);
-#elif __FREEBSD__
-# if (__FreeBSD_kernel_version >= 460000) || defined(__FreeBSD_kernel__)
-# if (__FreeBSD_kernel_version <= 500111)
- len = hid_report_size(rd, r->rid, repinfo[repind].kind);
-# else
- len = hid_report_size(rd, repinfo[repind].kind, r->rid);
-# endif
-# else
- len = hid_report_size(rd, repinfo[repind].kind, &r->rid);
-# endif
-#else
-# ifdef USBHID_NEW
- len = hid_report_size(rd, repinfo[repind].kind, r->rid);
-# else
- len = hid_report_size(rd, repinfo[repind].kind, &r->rid);
-# endif
-#endif
-
- if (len < 0) {
- return SDL_SetError("Negative HID report size");
- }
- r->size = len;
-
- if (r->size > 0) {
-#if defined(__FREEBSD__) && (__FreeBSD_kernel_version > 900000)
- r->buf = SDL_malloc(r->size);
-#else
- r->buf = SDL_malloc(sizeof(*r->buf) - sizeof(REP_BUF_DATA(r)) +
- r->size);
-#endif
- if (r->buf == NULL) {
- return SDL_OutOfMemory();
- }
- } else {
- r->buf = NULL;
- }
-
- r->status = SREPORT_CLEAN;
- return 0;
-}
-
-static void
-report_free(struct report *r)
-{
- SDL_free(r->buf);
- r->status = SREPORT_UNINIT;
-}
-
-#endif /* SDL_JOYSTICK_USBHID */
-
-/* vi: set ts=4 sw=4 expandtab: */
diff --git a/3rdparty/SDL2/src/joystick/darwin/SDL_sysjoystick.c b/3rdparty/SDL2/src/joystick/darwin/SDL_sysjoystick.c
deleted file mode 100644
index da10fbac5c9..00000000000
--- a/3rdparty/SDL2/src/joystick/darwin/SDL_sysjoystick.c
+++ /dev/null
@@ -1,798 +0,0 @@
-/*
- Simple DirectMedia Layer
- Copyright (C) 1997-2016 Sam Lantinga <slouken@libsdl.org>
-
- This software is provided 'as-is', without any express or implied
- warranty. In no event will the authors be held liable for any damages
- arising from the use of this software.
-
- Permission is granted to anyone to use this software for any purpose,
- including commercial applications, and to alter it and redistribute it
- freely, subject to the following restrictions:
-
- 1. The origin of this software must not be misrepresented; you must not
- claim that you wrote the original software. If you use this software
- in a product, an acknowledgment in the product documentation would be
- appreciated but is not required.
- 2. Altered source versions must be plainly marked as such, and must not be
- misrepresented as being the original software.
- 3. This notice may not be removed or altered from any source distribution.
-*/
-#include "../../SDL_internal.h"
-
-#ifdef SDL_JOYSTICK_IOKIT
-
-#include <IOKit/hid/IOHIDLib.h>
-
-/* For force feedback testing. */
-#include <ForceFeedback/ForceFeedback.h>
-#include <ForceFeedback/ForceFeedbackConstants.h>
-
-#include "SDL_joystick.h"
-#include "../SDL_sysjoystick.h"
-#include "../SDL_joystick_c.h"
-#include "SDL_sysjoystick_c.h"
-#include "SDL_events.h"
-#include "../../haptic/darwin/SDL_syshaptic_c.h" /* For haptic hot plugging */
-
-#define SDL_JOYSTICK_RUNLOOP_MODE CFSTR("SDLJoystick")
-
-/* The base object of the HID Manager API */
-static IOHIDManagerRef hidman = NULL;
-
-/* Linked list of all available devices */
-static recDevice *gpDeviceList = NULL;
-
-/* static incrementing counter for new joystick devices seen on the system. Devices should start with index 0 */
-static int s_joystick_instance_id = -1;
-
-static recDevice *GetDeviceForIndex(int device_index)
-{
- recDevice *device = gpDeviceList;
- while (device) {
- if (!device->removed) {
- if (device_index == 0)
- break;
-
- --device_index;
- }
- device = device->pNext;
- }
- return device;
-}
-
-static void
-FreeElementList(recElement *pElement)
-{
- while (pElement) {
- recElement *pElementNext = pElement->pNext;
- SDL_free(pElement);
- pElement = pElementNext;
- }
-}
-
-static recDevice *
-FreeDevice(recDevice *removeDevice)
-{
- recDevice *pDeviceNext = NULL;
- if (removeDevice) {
- if (removeDevice->deviceRef) {
- IOHIDDeviceUnscheduleFromRunLoop(removeDevice->deviceRef, CFRunLoopGetCurrent(), SDL_JOYSTICK_RUNLOOP_MODE);
- removeDevice->deviceRef = NULL;
- }
-
- /* save next device prior to disposing of this device */
- pDeviceNext = removeDevice->pNext;
-
- if ( gpDeviceList == removeDevice ) {
- gpDeviceList = pDeviceNext;
- } else {
- recDevice *device = gpDeviceList;
- while (device->pNext != removeDevice) {
- device = device->pNext;
- }
- device->pNext = pDeviceNext;
- }
- removeDevice->pNext = NULL;
-
- /* free element lists */
- FreeElementList(removeDevice->firstAxis);
- FreeElementList(removeDevice->firstButton);
- FreeElementList(removeDevice->firstHat);
-
- SDL_free(removeDevice);
- }
- return pDeviceNext;
-}
-
-static SInt32
-GetHIDElementState(recDevice *pDevice, recElement *pElement)
-{
- SInt32 value = 0;
-
- if (pDevice && pElement) {
- IOHIDValueRef valueRef;
- if (IOHIDDeviceGetValue(pDevice->deviceRef, pElement->elementRef, &valueRef) == kIOReturnSuccess) {
- value = (SInt32) IOHIDValueGetIntegerValue(valueRef);
-
- /* record min and max for auto calibration */
- if (value < pElement->minReport) {
- pElement->minReport = value;
- }
- if (value > pElement->maxReport) {
- pElement->maxReport = value;
- }
- }
- }
-
- return value;
-}
-
-static SInt32
-GetHIDScaledCalibratedState(recDevice * pDevice, recElement * pElement, SInt32 min, SInt32 max)
-{
- const float deviceScale = max - min;
- const float readScale = pElement->maxReport - pElement->minReport;
- const SInt32 value = GetHIDElementState(pDevice, pElement);
- if (readScale == 0) {
- return value; /* no scaling at all */
- }
- return ((value - pElement->minReport) * deviceScale / readScale) + min;
-}
-
-
-static void
-JoystickDeviceWasRemovedCallback(void *ctx, IOReturn result, void *sender)
-{
- recDevice *device = (recDevice *) ctx;
- device->removed = SDL_TRUE;
- device->deviceRef = NULL; // deviceRef was invalidated due to the remove
-#if SDL_HAPTIC_IOKIT
- MacHaptic_MaybeRemoveDevice(device->ffservice);
-#endif
-
- SDL_PrivateJoystickRemoved(device->instance_id);
-}
-
-
-static void AddHIDElement(const void *value, void *parameter);
-
-/* Call AddHIDElement() on all elements in an array of IOHIDElementRefs */
-static void
-AddHIDElements(CFArrayRef array, recDevice *pDevice)
-{
- const CFRange range = { 0, CFArrayGetCount(array) };
- CFArrayApplyFunction(array, range, AddHIDElement, pDevice);
-}
-
-static SDL_bool
-ElementAlreadyAdded(const IOHIDElementCookie cookie, const recElement *listitem) {
- while (listitem) {
- if (listitem->cookie == cookie) {
- return SDL_TRUE;
- }
- listitem = listitem->pNext;
- }
- return SDL_FALSE;
-}
-
-/* See if we care about this HID element, and if so, note it in our recDevice. */
-static void
-AddHIDElement(const void *value, void *parameter)
-{
- recDevice *pDevice = (recDevice *) parameter;
- IOHIDElementRef refElement = (IOHIDElementRef) value;
- const CFTypeID elementTypeID = refElement ? CFGetTypeID(refElement) : 0;
-
- if (refElement && (elementTypeID == IOHIDElementGetTypeID())) {
- const IOHIDElementCookie cookie = IOHIDElementGetCookie(refElement);
- const uint32_t usagePage = IOHIDElementGetUsagePage(refElement);
- const uint32_t usage = IOHIDElementGetUsage(refElement);
- recElement *element = NULL;
- recElement **headElement = NULL;
-
- /* look at types of interest */
- switch (IOHIDElementGetType(refElement)) {
- case kIOHIDElementTypeInput_Misc:
- case kIOHIDElementTypeInput_Button:
- case kIOHIDElementTypeInput_Axis: {
- switch (usagePage) { /* only interested in kHIDPage_GenericDesktop and kHIDPage_Button */
- case kHIDPage_GenericDesktop:
- switch (usage) {
- case kHIDUsage_GD_X:
- case kHIDUsage_GD_Y:
- case kHIDUsage_GD_Z:
- case kHIDUsage_GD_Rx:
- case kHIDUsage_GD_Ry:
- case kHIDUsage_GD_Rz:
- case kHIDUsage_GD_Slider:
- case kHIDUsage_GD_Dial:
- case kHIDUsage_GD_Wheel:
- if (!ElementAlreadyAdded(cookie, pDevice->firstAxis)) {
- element = (recElement *) SDL_calloc(1, sizeof (recElement));
- if (element) {
- pDevice->axes++;
- headElement = &(pDevice->firstAxis);
- }
- }
- break;
-
- case kHIDUsage_GD_Hatswitch:
- if (!ElementAlreadyAdded(cookie, pDevice->firstHat)) {
- element = (recElement *) SDL_calloc(1, sizeof (recElement));
- if (element) {
- pDevice->hats++;
- headElement = &(pDevice->firstHat);
- }
- }
- break;
- case kHIDUsage_GD_DPadUp:
- case kHIDUsage_GD_DPadDown:
- case kHIDUsage_GD_DPadRight:
- case kHIDUsage_GD_DPadLeft:
- case kHIDUsage_GD_Start:
- case kHIDUsage_GD_Select:
- case kHIDUsage_GD_SystemMainMenu:
- if (!ElementAlreadyAdded(cookie, pDevice->firstButton)) {
- element = (recElement *) SDL_calloc(1, sizeof (recElement));
- if (element) {
- pDevice->buttons++;
- headElement = &(pDevice->firstButton);
- }
- }
- break;
- }
- break;
-
- case kHIDPage_Simulation:
- switch (usage) {
- case kHIDUsage_Sim_Rudder:
- case kHIDUsage_Sim_Throttle:
- if (!ElementAlreadyAdded(cookie, pDevice->firstAxis)) {
- element = (recElement *) SDL_calloc(1, sizeof (recElement));
- if (element) {
- pDevice->axes++;
- headElement = &(pDevice->firstAxis);
- }
- }
- break;
-
- default:
- break;
- }
- break;
-
- case kHIDPage_Button:
- case kHIDPage_Consumer: /* e.g. 'pause' button on Steelseries MFi gamepads. */
- if (!ElementAlreadyAdded(cookie, pDevice->firstButton)) {
- element = (recElement *) SDL_calloc(1, sizeof (recElement));
- if (element) {
- pDevice->buttons++;
- headElement = &(pDevice->firstButton);
- }
- }
- break;
-
- default:
- break;
- }
- }
- break;
-
- case kIOHIDElementTypeCollection: {
- CFArrayRef array = IOHIDElementGetChildren(refElement);
- if (array) {
- AddHIDElements(array, pDevice);
- }
- }
- break;
-
- default:
- break;
- }
-
- if (element && headElement) { /* add to list */
- recElement *elementPrevious = NULL;
- recElement *elementCurrent = *headElement;
- while (elementCurrent && usage >= elementCurrent->usage) {
- elementPrevious = elementCurrent;
- elementCurrent = elementCurrent->pNext;
- }
- if (elementPrevious) {
- elementPrevious->pNext = element;
- } else {
- *headElement = element;
- }
-
- element->elementRef = refElement;
- element->usagePage = usagePage;
- element->usage = usage;
- element->pNext = elementCurrent;
-
- element->minReport = element->min = (SInt32) IOHIDElementGetLogicalMin(refElement);
- element->maxReport = element->max = (SInt32) IOHIDElementGetLogicalMax(refElement);
- element->cookie = IOHIDElementGetCookie(refElement);
-
- pDevice->elements++;
- }
- }
-}
-
-static SDL_bool
-GetDeviceInfo(IOHIDDeviceRef hidDevice, recDevice *pDevice)
-{
- Uint32 *guid32 = NULL;
- CFTypeRef refCF = NULL;
- CFArrayRef array = NULL;
-
- /* get usage page and usage */
- refCF = IOHIDDeviceGetProperty(hidDevice, CFSTR(kIOHIDPrimaryUsagePageKey));
- if (refCF) {
- CFNumberGetValue(refCF, kCFNumberSInt32Type, &pDevice->usagePage);
- }
- if (pDevice->usagePage != kHIDPage_GenericDesktop) {
- return SDL_FALSE; /* Filter device list to non-keyboard/mouse stuff */
- }
-
- refCF = IOHIDDeviceGetProperty(hidDevice, CFSTR(kIOHIDPrimaryUsageKey));
- if (refCF) {
- CFNumberGetValue(refCF, kCFNumberSInt32Type, &pDevice->usage);
- }
-
- if ((pDevice->usage != kHIDUsage_GD_Joystick &&
- pDevice->usage != kHIDUsage_GD_GamePad &&
- pDevice->usage != kHIDUsage_GD_MultiAxisController)) {
- return SDL_FALSE; /* Filter device list to non-keyboard/mouse stuff */
- }
-
- pDevice->deviceRef = hidDevice;
-
- /* get device name */
- refCF = IOHIDDeviceGetProperty(hidDevice, CFSTR(kIOHIDProductKey));
- if (!refCF) {
- /* Maybe we can't get "AwesomeJoystick2000", but we can get "Logitech"? */
- refCF = IOHIDDeviceGetProperty(hidDevice, CFSTR(kIOHIDManufacturerKey));
- }
- if ((!refCF) || (!CFStringGetCString(refCF, pDevice->product, sizeof (pDevice->product), kCFStringEncodingUTF8))) {
- SDL_strlcpy(pDevice->product, "Unidentified joystick", sizeof (pDevice->product));
- }
-
- refCF = IOHIDDeviceGetProperty(hidDevice, CFSTR(kIOHIDVendorIDKey));
- if (refCF) {
- CFNumberGetValue(refCF, kCFNumberSInt32Type, &pDevice->guid.data[0]);
- }
-
- refCF = IOHIDDeviceGetProperty(hidDevice, CFSTR(kIOHIDProductIDKey));
- if (refCF) {
- CFNumberGetValue(refCF, kCFNumberSInt32Type, &pDevice->guid.data[8]);
- }
-
- /* Check to make sure we have a vendor and product ID
- If we don't, use the same algorithm as the Linux code for Bluetooth devices */
- guid32 = (Uint32*)pDevice->guid.data;
- if (!guid32[0] && !guid32[1]) {
- /* If we don't have a vendor and product ID this is probably a Bluetooth device */
- const Uint16 BUS_BLUETOOTH = 0x05;
- Uint16 *guid16 = (Uint16 *)guid32;
- *guid16++ = BUS_BLUETOOTH;
- *guid16++ = 0;
- SDL_strlcpy((char*)guid16, pDevice->product, sizeof(pDevice->guid.data) - 4);
- }
-
- array = IOHIDDeviceCopyMatchingElements(hidDevice, NULL, kIOHIDOptionsTypeNone);
- if (array) {
- AddHIDElements(array, pDevice);
- CFRelease(array);
- }
-
- return SDL_TRUE;
-}
-
-static SDL_bool
-JoystickAlreadyKnown(IOHIDDeviceRef ioHIDDeviceObject)
-{
- recDevice *i;
- for (i = gpDeviceList; i != NULL; i = i->pNext) {
- if (i->deviceRef == ioHIDDeviceObject) {
- return SDL_TRUE;
- }
- }
- return SDL_FALSE;
-}
-
-
-static void
-JoystickDeviceWasAddedCallback(void *ctx, IOReturn res, void *sender, IOHIDDeviceRef ioHIDDeviceObject)
-{
- recDevice *device;
- int device_index = 0;
- io_service_t ioservice;
-
- if (res != kIOReturnSuccess) {
- return;
- }
-
- if (JoystickAlreadyKnown(ioHIDDeviceObject)) {
- return; /* IOKit sent us a duplicate. */
- }
-
- device = (recDevice *) SDL_calloc(1, sizeof(recDevice));
-
- if (!device) {
- SDL_OutOfMemory();
- return;
- }
-
- if (!GetDeviceInfo(ioHIDDeviceObject, device)) {
- SDL_free(device);
- return; /* not a device we care about, probably. */
- }
-
- /* Get notified when this device is disconnected. */
- IOHIDDeviceRegisterRemovalCallback(ioHIDDeviceObject, JoystickDeviceWasRemovedCallback, device);
- IOHIDDeviceScheduleWithRunLoop(ioHIDDeviceObject, CFRunLoopGetCurrent(), SDL_JOYSTICK_RUNLOOP_MODE);
-
- /* Allocate an instance ID for this device */
- device->instance_id = ++s_joystick_instance_id;
-
- /* We have to do some storage of the io_service_t for SDL_HapticOpenFromJoystick */
- ioservice = IOHIDDeviceGetService(ioHIDDeviceObject);
-#if SDL_HAPTIC_IOKIT
- if ((ioservice) && (FFIsForceFeedback(ioservice) == FF_OK)) {
- device->ffservice = ioservice;
- MacHaptic_MaybeAddDevice(ioservice);
- }
-#endif
-
- /* Add device to the end of the list */
- if ( !gpDeviceList ) {
- gpDeviceList = device;
- } else {
- recDevice *curdevice;
-
- curdevice = gpDeviceList;
- while ( curdevice->pNext ) {
- ++device_index;
- curdevice = curdevice->pNext;
- }
- curdevice->pNext = device;
- ++device_index; /* bump by one since we counted by pNext. */
- }
-
- SDL_PrivateJoystickAdded(device_index);
-}
-
-static SDL_bool
-ConfigHIDManager(CFArrayRef matchingArray)
-{
- CFRunLoopRef runloop = CFRunLoopGetCurrent();
-
- if (IOHIDManagerOpen(hidman, kIOHIDOptionsTypeNone) != kIOReturnSuccess) {
- return SDL_FALSE;
- }
-
- IOHIDManagerSetDeviceMatchingMultiple(hidman, matchingArray);
- IOHIDManagerRegisterDeviceMatchingCallback(hidman, JoystickDeviceWasAddedCallback, NULL);
- IOHIDManagerScheduleWithRunLoop(hidman, runloop, SDL_JOYSTICK_RUNLOOP_MODE);
-
- while (CFRunLoopRunInMode(SDL_JOYSTICK_RUNLOOP_MODE,0,TRUE) == kCFRunLoopRunHandledSource) {
- /* no-op. Callback fires once per existing device. */
- }
-
- /* future hotplug events will come through SDL_JOYSTICK_RUNLOOP_MODE now. */
-
- return SDL_TRUE; /* good to go. */
-}
-
-
-static CFDictionaryRef
-CreateHIDDeviceMatchDictionary(const UInt32 page, const UInt32 usage, int *okay)
-{
- CFDictionaryRef retval = NULL;
- CFNumberRef pageNumRef = CFNumberCreate(kCFAllocatorDefault, kCFNumberIntType, &page);
- CFNumberRef usageNumRef = CFNumberCreate(kCFAllocatorDefault, kCFNumberIntType, &usage);
- const void *keys[2] = { (void *) CFSTR(kIOHIDDeviceUsagePageKey), (void *) CFSTR(kIOHIDDeviceUsageKey) };
- const void *vals[2] = { (void *) pageNumRef, (void *) usageNumRef };
-
- if (pageNumRef && usageNumRef) {
- retval = CFDictionaryCreate(kCFAllocatorDefault, keys, vals, 2, &kCFTypeDictionaryKeyCallBacks, &kCFTypeDictionaryValueCallBacks);
- }
-
- if (pageNumRef) {
- CFRelease(pageNumRef);
- }
- if (usageNumRef) {
- CFRelease(usageNumRef);
- }
-
- if (!retval) {
- *okay = 0;
- }
-
- return retval;
-}
-
-static SDL_bool
-CreateHIDManager(void)
-{
- SDL_bool retval = SDL_FALSE;
- int okay = 1;
- const void *vals[] = {
- (void *) CreateHIDDeviceMatchDictionary(kHIDPage_GenericDesktop, kHIDUsage_GD_Joystick, &okay),
- (void *) CreateHIDDeviceMatchDictionary(kHIDPage_GenericDesktop, kHIDUsage_GD_GamePad, &okay),
- (void *) CreateHIDDeviceMatchDictionary(kHIDPage_GenericDesktop, kHIDUsage_GD_MultiAxisController, &okay),
- };
- const size_t numElements = SDL_arraysize(vals);
- CFArrayRef array = okay ? CFArrayCreate(kCFAllocatorDefault, vals, numElements, &kCFTypeArrayCallBacks) : NULL;
- size_t i;
-
- for (i = 0; i < numElements; i++) {
- if (vals[i]) {
- CFRelease((CFTypeRef) vals[i]);
- }
- }
-
- if (array) {
- hidman = IOHIDManagerCreate(kCFAllocatorDefault, kIOHIDOptionsTypeNone);
- if (hidman != NULL) {
- retval = ConfigHIDManager(array);
- }
- CFRelease(array);
- }
-
- return retval;
-}
-
-
-/* Function to scan the system for joysticks.
- * Joystick 0 should be the system default joystick.
- * This function should return the number of available joysticks, or -1
- * on an unrecoverable fatal error.
- */
-int
-SDL_SYS_JoystickInit(void)
-{
- if (gpDeviceList) {
- return SDL_SetError("Joystick: Device list already inited.");
- }
-
- if (!CreateHIDManager()) {
- return SDL_SetError("Joystick: Couldn't initialize HID Manager");
- }
-
- return SDL_SYS_NumJoysticks();
-}
-
-/* Function to return the number of joystick devices plugged in right now */
-int
-SDL_SYS_NumJoysticks()
-{
- recDevice *device = gpDeviceList;
- int nJoySticks = 0;
-
- while (device) {
- if (!device->removed) {
- nJoySticks++;
- }
- device = device->pNext;
- }
-
- return nJoySticks;
-}
-
-/* Function to cause any queued joystick insertions to be processed
- */
-void
-SDL_SYS_JoystickDetect()
-{
- recDevice *device = gpDeviceList;
- while (device) {
- if (device->removed) {
- device = FreeDevice(device);
- } else {
- device = device->pNext;
- }
- }
-
- // run this after the checks above so we don't set device->removed and delete the device before
- // SDL_SYS_JoystickUpdate can run to clean up the SDL_Joystick object that owns this device
- while (CFRunLoopRunInMode(SDL_JOYSTICK_RUNLOOP_MODE,0,TRUE) == kCFRunLoopRunHandledSource) {
- /* no-op. Pending callbacks will fire in CFRunLoopRunInMode(). */
- }
-}
-
-/* Function to get the device-dependent name of a joystick */
-const char *
-SDL_SYS_JoystickNameForDeviceIndex(int device_index)
-{
- recDevice *device = GetDeviceForIndex(device_index);
- return device ? device->product : "UNKNOWN";
-}
-
-/* Function to return the instance id of the joystick at device_index
- */
-SDL_JoystickID
-SDL_SYS_GetInstanceIdOfDeviceIndex(int device_index)
-{
- recDevice *device = GetDeviceForIndex(device_index);
- return device ? device->instance_id : 0;
-}
-
-/* Function to open a joystick for use.
- * The joystick to open is specified by the device index.
- * This should fill the nbuttons and naxes fields of the joystick structure.
- * It returns 0, or -1 if there is an error.
- */
-int
-SDL_SYS_JoystickOpen(SDL_Joystick * joystick, int device_index)
-{
- recDevice *device = GetDeviceForIndex(device_index);
-
- joystick->instance_id = device->instance_id;
- joystick->hwdata = device;
- joystick->name = device->product;
-
- joystick->naxes = device->axes;
- joystick->nhats = device->hats;
- joystick->nballs = 0;
- joystick->nbuttons = device->buttons;
- return 0;
-}
-
-/* Function to query if the joystick is currently attached
- * It returns SDL_TRUE if attached, SDL_FALSE otherwise.
- */
-SDL_bool
-SDL_SYS_JoystickAttached(SDL_Joystick * joystick)
-{
- return joystick->hwdata != NULL;
-}
-
-/* Function to update the state of a joystick - called as a device poll.
- * This function shouldn't update the joystick structure directly,
- * but instead should call SDL_PrivateJoystick*() to deliver events
- * and update joystick device state.
- */
-void
-SDL_SYS_JoystickUpdate(SDL_Joystick * joystick)
-{
- recDevice *device = joystick->hwdata;
- recElement *element;
- SInt32 value, range;
- int i;
-
- if (!device) {
- return;
- }
-
- if (device->removed) { /* device was unplugged; ignore it. */
- if (joystick->hwdata) {
- joystick->force_recentering = SDL_TRUE;
- joystick->hwdata = NULL;
- }
- return;
- }
-
- element = device->firstAxis;
- i = 0;
- while (element) {
- value = GetHIDScaledCalibratedState(device, element, -32768, 32767);
- if (value != joystick->axes[i]) {
- SDL_PrivateJoystickAxis(joystick, i, value);
- }
- element = element->pNext;
- ++i;
- }
-
- element = device->firstButton;
- i = 0;
- while (element) {
- value = GetHIDElementState(device, element);
- if (value > 1) { /* handle pressure-sensitive buttons */
- value = 1;
- }
- if (value != joystick->buttons[i]) {
- SDL_PrivateJoystickButton(joystick, i, value);
- }
- element = element->pNext;
- ++i;
- }
-
- element = device->firstHat;
- i = 0;
- while (element) {
- Uint8 pos = 0;
-
- range = (element->max - element->min + 1);
- value = GetHIDElementState(device, element) - element->min;
- if (range == 4) { /* 4 position hatswitch - scale up value */
- value *= 2;
- } else if (range != 8) { /* Neither a 4 nor 8 positions - fall back to default position (centered) */
- value = -1;
- }
- switch (value) {
- case 0:
- pos = SDL_HAT_UP;
- break;
- case 1:
- pos = SDL_HAT_RIGHTUP;
- break;
- case 2:
- pos = SDL_HAT_RIGHT;
- break;
- case 3:
- pos = SDL_HAT_RIGHTDOWN;
- break;
- case 4:
- pos = SDL_HAT_DOWN;
- break;
- case 5:
- pos = SDL_HAT_LEFTDOWN;
- break;
- case 6:
- pos = SDL_HAT_LEFT;
- break;
- case 7:
- pos = SDL_HAT_LEFTUP;
- break;
- default:
- /* Every other value is mapped to center. We do that because some
- * joysticks use 8 and some 15 for this value, and apparently
- * there are even more variants out there - so we try to be generous.
- */
- pos = SDL_HAT_CENTERED;
- break;
- }
-
- if (pos != joystick->hats[i]) {
- SDL_PrivateJoystickHat(joystick, i, pos);
- }
-
- element = element->pNext;
- ++i;
- }
-}
-
-/* Function to close a joystick after use */
-void
-SDL_SYS_JoystickClose(SDL_Joystick * joystick)
-{
-}
-
-/* Function to perform any system-specific joystick related cleanup */
-void
-SDL_SYS_JoystickQuit(void)
-{
- while (FreeDevice(gpDeviceList)) {
- /* spin */
- }
-
- if (hidman) {
- IOHIDManagerUnscheduleFromRunLoop(hidman, CFRunLoopGetCurrent(), SDL_JOYSTICK_RUNLOOP_MODE);
- IOHIDManagerClose(hidman, kIOHIDOptionsTypeNone);
- CFRelease(hidman);
- hidman = NULL;
- }
-}
-
-
-SDL_JoystickGUID SDL_SYS_JoystickGetDeviceGUID( int device_index )
-{
- recDevice *device = GetDeviceForIndex(device_index);
- SDL_JoystickGUID guid;
- if (device) {
- guid = device->guid;
- } else {
- SDL_zero(guid);
- }
- return guid;
-}
-
-SDL_JoystickGUID SDL_SYS_JoystickGetGUID(SDL_Joystick *joystick)
-{
- return joystick->hwdata->guid;
-}
-
-#endif /* SDL_JOYSTICK_IOKIT */
-
-/* vi: set ts=4 sw=4 expandtab: */
diff --git a/3rdparty/SDL2/src/joystick/darwin/SDL_sysjoystick_c.h b/3rdparty/SDL2/src/joystick/darwin/SDL_sysjoystick_c.h
deleted file mode 100644
index 1c317eca7ae..00000000000
--- a/3rdparty/SDL2/src/joystick/darwin/SDL_sysjoystick_c.h
+++ /dev/null
@@ -1,72 +0,0 @@
-/*
- Simple DirectMedia Layer
- Copyright (C) 1997-2016 Sam Lantinga <slouken@libsdl.org>
-
- This software is provided 'as-is', without any express or implied
- warranty. In no event will the authors be held liable for any damages
- arising from the use of this software.
-
- Permission is granted to anyone to use this software for any purpose,
- including commercial applications, and to alter it and redistribute it
- freely, subject to the following restrictions:
-
- 1. The origin of this software must not be misrepresented; you must not
- claim that you wrote the original software. If you use this software
- in a product, an acknowledgment in the product documentation would be
- appreciated but is not required.
- 2. Altered source versions must be plainly marked as such, and must not be
- misrepresented as being the original software.
- 3. This notice may not be removed or altered from any source distribution.
-*/
-#include "../../SDL_internal.h"
-
-#ifndef SDL_JOYSTICK_IOKIT_H
-#define SDL_JOYSTICK_IOKIT_H
-
-#include <IOKit/hid/IOHIDLib.h>
-
-struct recElement
-{
- IOHIDElementRef elementRef;
- IOHIDElementCookie cookie;
- uint32_t usagePage, usage; /* HID usage */
- SInt32 min; /* reported min value possible */
- SInt32 max; /* reported max value possible */
-
- /* runtime variables used for auto-calibration */
- SInt32 minReport; /* min returned value */
- SInt32 maxReport; /* max returned value */
-
- struct recElement *pNext; /* next element in list */
-};
-typedef struct recElement recElement;
-
-struct joystick_hwdata
-{
- IOHIDDeviceRef deviceRef; /* HIDManager device handle */
- io_service_t ffservice; /* Interface for force feedback, 0 = no ff */
-
- char product[256]; /* name of product */
- uint32_t usage; /* usage page from IOUSBHID Parser.h which defines general usage */
- uint32_t usagePage; /* usage within above page from IOUSBHID Parser.h which defines specific usage */
-
- int axes; /* number of axis (calculated, not reported by device) */
- int buttons; /* number of buttons (calculated, not reported by device) */
- int hats; /* number of hat switches (calculated, not reported by device) */
- int elements; /* number of total elements (should be total of above) (calculated, not reported by device) */
-
- recElement *firstAxis;
- recElement *firstButton;
- recElement *firstHat;
-
- SDL_bool removed;
-
- int instance_id;
- SDL_JoystickGUID guid;
-
- struct joystick_hwdata *pNext; /* next device */
-};
-typedef struct joystick_hwdata recDevice;
-
-
-#endif /* SDL_JOYSTICK_IOKIT_H */
diff --git a/3rdparty/SDL2/src/joystick/dummy/SDL_sysjoystick.c b/3rdparty/SDL2/src/joystick/dummy/SDL_sysjoystick.c
deleted file mode 100644
index 10fda10da2a..00000000000
--- a/3rdparty/SDL2/src/joystick/dummy/SDL_sysjoystick.c
+++ /dev/null
@@ -1,125 +0,0 @@
-/*
- Simple DirectMedia Layer
- Copyright (C) 1997-2016 Sam Lantinga <slouken@libsdl.org>
-
- This software is provided 'as-is', without any express or implied
- warranty. In no event will the authors be held liable for any damages
- arising from the use of this software.
-
- Permission is granted to anyone to use this software for any purpose,
- including commercial applications, and to alter it and redistribute it
- freely, subject to the following restrictions:
-
- 1. The origin of this software must not be misrepresented; you must not
- claim that you wrote the original software. If you use this software
- in a product, an acknowledgment in the product documentation would be
- appreciated but is not required.
- 2. Altered source versions must be plainly marked as such, and must not be
- misrepresented as being the original software.
- 3. This notice may not be removed or altered from any source distribution.
-*/
-#include "../../SDL_internal.h"
-
-#if defined(SDL_JOYSTICK_DUMMY) || defined(SDL_JOYSTICK_DISABLED)
-
-/* This is the dummy implementation of the SDL joystick API */
-
-#include "SDL_joystick.h"
-#include "../SDL_sysjoystick.h"
-#include "../SDL_joystick_c.h"
-
-/* Function to scan the system for joysticks.
- * It should return 0, or -1 on an unrecoverable fatal error.
- */
-int
-SDL_SYS_JoystickInit(void)
-{
- return 0;
-}
-
-int SDL_SYS_NumJoysticks()
-{
- return 0;
-}
-
-void SDL_SYS_JoystickDetect()
-{
-}
-
-/* Function to get the device-dependent name of a joystick */
-const char *
-SDL_SYS_JoystickNameForDeviceIndex(int device_index)
-{
- SDL_SetError("Logic error: No joysticks available");
- return (NULL);
-}
-
-/* Function to perform the mapping from device index to the instance id for this index */
-SDL_JoystickID SDL_SYS_GetInstanceIdOfDeviceIndex(int device_index)
-{
- return device_index;
-}
-
-/* Function to open a joystick for use.
- The joystick to open is specified by the device index.
- This should fill the nbuttons and naxes fields of the joystick structure.
- It returns 0, or -1 if there is an error.
- */
-int
-SDL_SYS_JoystickOpen(SDL_Joystick * joystick, int device_index)
-{
- return SDL_SetError("Logic error: No joysticks available");
-}
-
-/* Function to determine if this joystick is attached to the system right now */
-SDL_bool SDL_SYS_JoystickAttached(SDL_Joystick *joystick)
-{
- return SDL_TRUE;
-}
-
-/* Function to update the state of a joystick - called as a device poll.
- * This function shouldn't update the joystick structure directly,
- * but instead should call SDL_PrivateJoystick*() to deliver events
- * and update joystick device state.
- */
-void
-SDL_SYS_JoystickUpdate(SDL_Joystick * joystick)
-{
-}
-
-/* Function to close a joystick after use */
-void
-SDL_SYS_JoystickClose(SDL_Joystick * joystick)
-{
-}
-
-/* Function to perform any system-specific joystick related cleanup */
-void
-SDL_SYS_JoystickQuit(void)
-{
-}
-
-SDL_JoystickGUID SDL_SYS_JoystickGetDeviceGUID( int device_index )
-{
- SDL_JoystickGUID guid;
- /* the GUID is just the first 16 chars of the name for now */
- const char *name = SDL_SYS_JoystickNameForDeviceIndex( device_index );
- SDL_zero( guid );
- SDL_memcpy( &guid, name, SDL_min( sizeof(guid), SDL_strlen( name ) ) );
- return guid;
-}
-
-
-SDL_JoystickGUID SDL_SYS_JoystickGetGUID(SDL_Joystick * joystick)
-{
- SDL_JoystickGUID guid;
- /* the GUID is just the first 16 chars of the name for now */
- const char *name = joystick->name;
- SDL_zero( guid );
- SDL_memcpy( &guid, name, SDL_min( sizeof(guid), SDL_strlen( name ) ) );
- return guid;
-}
-
-#endif /* SDL_JOYSTICK_DUMMY || SDL_JOYSTICK_DISABLED */
-
-/* vi: set ts=4 sw=4 expandtab: */
diff --git a/3rdparty/SDL2/src/joystick/emscripten/SDL_sysjoystick.c b/3rdparty/SDL2/src/joystick/emscripten/SDL_sysjoystick.c
deleted file mode 100644
index 6b203667aca..00000000000
--- a/3rdparty/SDL2/src/joystick/emscripten/SDL_sysjoystick.c
+++ /dev/null
@@ -1,402 +0,0 @@
-/*
- Simple DirectMedia Layer
- Copyright (C) 1997-2016 Sam Lantinga <slouken@libsdl.org>
-
- This software is provided 'as-is', without any express or implied
- warranty. In no event will the authors be held liable for any damages
- arising from the use of this software.
-
- Permission is granted to anyone to use this software for any purpose,
- including commercial applications, and to alter it and redistribute it
- freely, subject to the following restrictions:
-
- 1. The origin of this software must not be misrepresented; you must not
- claim that you wrote the original software. If you use this software
- in a product, an acknowledgment in the product documentation would be
- appreciated but is not required.
- 2. Altered source versions must be plainly marked as such, and must not be
- misrepresented as being the original software.
- 3. This notice may not be removed or altered from any source distribution.
-*/
-
-#include "../../SDL_internal.h"
-
-#ifdef SDL_JOYSTICK_EMSCRIPTEN
-
-#include <stdio.h> /* For the definition of NULL */
-#include "SDL_error.h"
-#include "SDL_events.h"
-
-#include "SDL_joystick.h"
-#include "SDL_hints.h"
-#include "SDL_assert.h"
-#include "SDL_timer.h"
-#include "SDL_log.h"
-#include "SDL_sysjoystick_c.h"
-#include "../SDL_joystick_c.h"
-
-static SDL_joylist_item * JoystickByIndex(int index);
-
-static SDL_joylist_item *SDL_joylist = NULL;
-static SDL_joylist_item *SDL_joylist_tail = NULL;
-static int numjoysticks = 0;
-static int instance_counter = 0;
-
-EM_BOOL
-Emscripten_JoyStickConnected(int eventType, const EmscriptenGamepadEvent *gamepadEvent, void *userData)
-{
- int i;
-
- SDL_joylist_item *item;
-
- if (JoystickByIndex(gamepadEvent->index) != NULL) {
- return 1;
- }
-
- item = (SDL_joylist_item *) SDL_malloc(sizeof (SDL_joylist_item));
- if (item == NULL) {
- return 1;
- }
-
- SDL_zerop(item);
- item->index = gamepadEvent->index;
-
- item->name = SDL_strdup(gamepadEvent->id);
- if ( item->name == NULL ) {
- SDL_free(item);
- return 1;
- }
-
- item->mapping = SDL_strdup(gamepadEvent->mapping);
- if ( item->mapping == NULL ) {
- SDL_free(item->name);
- SDL_free(item);
- return 1;
- }
-
- item->naxes = gamepadEvent->numAxes;
- item->nbuttons = gamepadEvent->numButtons;
- item->device_instance = instance_counter++;
-
- item->timestamp = gamepadEvent->timestamp;
-
- for( i = 0; i < item->naxes; i++) {
- item->axis[i] = gamepadEvent->axis[i];
- }
-
- for( i = 0; i < item->nbuttons; i++) {
- item->analogButton[i] = gamepadEvent->analogButton[i];
- item->digitalButton[i] = gamepadEvent->digitalButton[i];
- }
-
- if (SDL_joylist_tail == NULL) {
- SDL_joylist = SDL_joylist_tail = item;
- } else {
- SDL_joylist_tail->next = item;
- SDL_joylist_tail = item;
- }
-
- ++numjoysticks;
-
- SDL_PrivateJoystickAdded(numjoysticks - 1);
-
-#ifdef DEBUG_JOYSTICK
- SDL_Log("Number of joysticks is %d", numjoysticks);
-#endif
-
-#ifdef DEBUG_JOYSTICK
- SDL_Log("Added joystick with index %d", item->index);
-#endif
-
- return 1;
-}
-
-EM_BOOL
-Emscripten_JoyStickDisconnected(int eventType, const EmscriptenGamepadEvent *gamepadEvent, void *userData)
-{
- SDL_joylist_item *item = SDL_joylist;
- SDL_joylist_item *prev = NULL;
-
- while (item != NULL) {
- if (item->index == gamepadEvent->index) {
- break;
- }
- prev = item;
- item = item->next;
- }
-
- if (item == NULL) {
- return 1;
- }
-
- if (item->joystick) {
- item->joystick->hwdata = NULL;
- }
-
- if (prev != NULL) {
- prev->next = item->next;
- } else {
- SDL_assert(SDL_joylist == item);
- SDL_joylist = item->next;
- }
- if (item == SDL_joylist_tail) {
- SDL_joylist_tail = prev;
- }
-
- /* Need to decrement the joystick count before we post the event */
- --numjoysticks;
-
- SDL_PrivateJoystickRemoved(item->device_instance);
-
-#ifdef DEBUG_JOYSTICK
- SDL_Log("Removed joystick with id %d", item->device_instance);
-#endif
- SDL_free(item->name);
- SDL_free(item->mapping);
- SDL_free(item);
- return 1;
-}
-
-/* Function to scan the system for joysticks.
- * It should return 0, or -1 on an unrecoverable fatal error.
- */
-int
-SDL_SYS_JoystickInit(void)
-{
- int retval, i, numjs;
- EmscriptenGamepadEvent gamepadState;
-
- numjoysticks = 0;
- numjs = emscripten_get_num_gamepads();
-
- /* Check if gamepad is supported by browser */
- if (numjs == EMSCRIPTEN_RESULT_NOT_SUPPORTED) {
- return SDL_SetError("Gamepads not supported");
- }
-
- /* handle already connected gamepads */
- if (numjs > 0) {
- for(i = 0; i < numjs; i++) {
- retval = emscripten_get_gamepad_status(i, &gamepadState);
- if (retval == EMSCRIPTEN_RESULT_SUCCESS) {
- Emscripten_JoyStickConnected(EMSCRIPTEN_EVENT_GAMEPADCONNECTED,
- &gamepadState,
- NULL);
- }
- }
- }
-
- retval = emscripten_set_gamepadconnected_callback(NULL,
- 0,
- Emscripten_JoyStickConnected);
-
- if(retval != EMSCRIPTEN_RESULT_SUCCESS) {
- SDL_SYS_JoystickQuit();
- return SDL_SetError("Could not set gamepad connect callback");
- }
-
- retval = emscripten_set_gamepaddisconnected_callback(NULL,
- 0,
- Emscripten_JoyStickDisconnected);
- if(retval != EMSCRIPTEN_RESULT_SUCCESS) {
- SDL_SYS_JoystickQuit();
- return SDL_SetError("Could not set gamepad disconnect callback");
- }
-
- return 0;
-}
-
-/* Returns item matching given SDL device index. */
-static SDL_joylist_item *
-JoystickByDeviceIndex(int device_index)
-{
- SDL_joylist_item *item = SDL_joylist;
-
- while (0 < device_index) {
- --device_index;
- item = item->next;
- }
-
- return item;
-}
-
-/* Returns item matching given HTML gamepad index. */
-static SDL_joylist_item *
-JoystickByIndex(int index)
-{
- SDL_joylist_item *item = SDL_joylist;
-
- if (index < 0) {
- return NULL;
- }
-
- while (item != NULL) {
- if (item->index == index) {
- break;
- }
- item = item->next;
- }
-
- return item;
-}
-
-int SDL_SYS_NumJoysticks()
-{
- return numjoysticks;
-}
-
-void SDL_SYS_JoystickDetect()
-{
-}
-
-/* Function to get the device-dependent name of a joystick */
-const char *
-SDL_SYS_JoystickNameForDeviceIndex(int device_index)
-{
- return JoystickByDeviceIndex(device_index)->name;
-}
-
-/* Function to perform the mapping from device index to the instance id for this index */
-SDL_JoystickID SDL_SYS_GetInstanceIdOfDeviceIndex(int device_index)
-{
- return JoystickByDeviceIndex(device_index)->device_instance;
-}
-
-/* Function to open a joystick for use.
- The joystick to open is specified by the device index.
- This should fill the nbuttons and naxes fields of the joystick structure.
- It returns 0, or -1 if there is an error.
- */
-int
-SDL_SYS_JoystickOpen(SDL_Joystick * joystick, int device_index)
-{
- SDL_joylist_item *item = JoystickByDeviceIndex(device_index);
-
- if (item == NULL ) {
- return SDL_SetError("No such device");
- }
-
- if (item->joystick != NULL) {
- return SDL_SetError("Joystick already opened");
- }
-
- joystick->instance_id = item->device_instance;
- joystick->hwdata = (struct joystick_hwdata *) item;
- item->joystick = joystick;
-
- /* HTML5 Gamepad API doesn't say anything about these */
- joystick->nhats = 0;
- joystick->nballs = 0;
-
- joystick->nbuttons = item->nbuttons;
- joystick->naxes = item->naxes;
-
- return (0);
-}
-
-/* Function to determine if this joystick is attached to the system right now */
-SDL_bool SDL_SYS_JoystickAttached(SDL_Joystick *joystick)
-{
- return joystick->hwdata != NULL;
-}
-
-/* Function to update the state of a joystick - called as a device poll.
- * This function shouldn't update the joystick structure directly,
- * but instead should call SDL_PrivateJoystick*() to deliver events
- * and update joystick device state.
- */
-void
-SDL_SYS_JoystickUpdate(SDL_Joystick * joystick)
-{
- EmscriptenGamepadEvent gamepadState;
- SDL_joylist_item *item = (SDL_joylist_item *) joystick->hwdata;
- int i, result, buttonState;
-
- if (item) {
- result = emscripten_get_gamepad_status(item->index, &gamepadState);
- if( result == EMSCRIPTEN_RESULT_SUCCESS) {
- if(gamepadState.timestamp == 0 || gamepadState.timestamp != item->timestamp) {
- for(i = 0; i < item->nbuttons; i++) {
- if(item->digitalButton[i] != gamepadState.digitalButton[i]) {
- buttonState = gamepadState.digitalButton[i]? SDL_PRESSED: SDL_RELEASED;
- SDL_PrivateJoystickButton(item->joystick, i, buttonState);
- }
-
- /* store values to compare them in the next update */
- item->analogButton[i] = gamepadState.analogButton[i];
- item->digitalButton[i] = gamepadState.digitalButton[i];
- }
-
- for(i = 0; i < item->naxes; i++) {
- if(item->axis[i] != gamepadState.axis[i]) {
- // do we need to do conversion?
- SDL_PrivateJoystickAxis(item->joystick, i,
- (Sint16) (32767.*gamepadState.axis[i]));
- }
-
- /* store to compare in next update */
- item->axis[i] = gamepadState.axis[i];
- }
-
- item->timestamp = gamepadState.timestamp;
- }
- }
- }
-}
-
-/* Function to close a joystick after use */
-void
-SDL_SYS_JoystickClose(SDL_Joystick * joystick)
-{
- SDL_joylist_item *item = (SDL_joylist_item *) joystick->hwdata;
- if (item) {
- item->joystick = NULL;
- }
-}
-
-/* Function to perform any system-specific joystick related cleanup */
-void
-SDL_SYS_JoystickQuit(void)
-{
- SDL_joylist_item *item = NULL;
- SDL_joylist_item *next = NULL;
-
- for (item = SDL_joylist; item; item = next) {
- next = item->next;
- SDL_free(item->mapping);
- SDL_free(item->name);
- SDL_free(item);
- }
-
- SDL_joylist = SDL_joylist_tail = NULL;
-
- numjoysticks = 0;
- instance_counter = 0;
-
- emscripten_set_gamepadconnected_callback(NULL, 0, NULL);
- emscripten_set_gamepaddisconnected_callback(NULL, 0, NULL);
-}
-
-SDL_JoystickGUID
-SDL_SYS_JoystickGetDeviceGUID(int device_index)
-{
- SDL_JoystickGUID guid;
- /* the GUID is just the first 16 chars of the name for now */
- const char *name = SDL_SYS_JoystickNameForDeviceIndex(device_index);
- SDL_zero(guid);
- SDL_memcpy(&guid, name, SDL_min(sizeof(guid), SDL_strlen(name)));
- return guid;
-}
-
-SDL_JoystickGUID
-SDL_SYS_JoystickGetGUID(SDL_Joystick * joystick)
-{
- SDL_JoystickGUID guid;
- /* the GUID is just the first 16 chars of the name for now */
- const char *name = joystick->name;
- SDL_zero(guid);
- SDL_memcpy(&guid, name, SDL_min(sizeof(guid), SDL_strlen(name)));
- return guid;
-}
-
-#endif /* SDL_JOYSTICK_EMSCRIPTEN */
diff --git a/3rdparty/SDL2/src/joystick/emscripten/SDL_sysjoystick_c.h b/3rdparty/SDL2/src/joystick/emscripten/SDL_sysjoystick_c.h
deleted file mode 100644
index 41f613e115c..00000000000
--- a/3rdparty/SDL2/src/joystick/emscripten/SDL_sysjoystick_c.h
+++ /dev/null
@@ -1,52 +0,0 @@
-/*
- Simple DirectMedia Layer
- Copyright (C) 1997-2016 Sam Lantinga <slouken@libsdl.org>
-
- This software is provided 'as-is', without any express or implied
- warranty. In no event will the authors be held liable for any damages
- arising from the use of this software.
-
- Permission is granted to anyone to use this software for any purpose,
- including commercial applications, and to alter it and redistribute it
- freely, subject to the following restrictions:
-
- 1. The origin of this software must not be misrepresented; you must not
- claim that you wrote the original software. If you use this software
- in a product, an acknowledgment in the product documentation would be
- appreciated but is not required.
- 2. Altered source versions must be plainly marked as such, and must not be
- misrepresented as being the original software.
- 3. This notice may not be removed or altered from any source distribution.
-*/
-
-#include "../../SDL_internal.h"
-
-#ifdef SDL_JOYSTICK_EMSCRIPTEN
-#include "../SDL_sysjoystick.h"
-
-
-#include <emscripten/html5.h>
-
-/* A linked list of available joysticks */
-typedef struct SDL_joylist_item
-{
- int index;
- char *name;
- char *mapping;
- SDL_JoystickID device_instance;
- SDL_Joystick *joystick;
- int nbuttons;
- int naxes;
- double timestamp;
- double axis[64];
- double analogButton[64];
- EM_BOOL digitalButton[64];
-
- struct SDL_joylist_item *next;
-} SDL_joylist_item;
-
-typedef SDL_joylist_item joystick_hwdata;
-
-#endif /* SDL_JOYSTICK_EMSCRIPTEN */
-
-/* vi: set ts=4 sw=4 expandtab: */
diff --git a/3rdparty/SDL2/src/joystick/haiku/SDL_haikujoystick.cc b/3rdparty/SDL2/src/joystick/haiku/SDL_haikujoystick.cc
deleted file mode 100644
index a680189c737..00000000000
--- a/3rdparty/SDL2/src/joystick/haiku/SDL_haikujoystick.cc
+++ /dev/null
@@ -1,274 +0,0 @@
-/*
- Simple DirectMedia Layer
- Copyright (C) 1997-2016 Sam Lantinga <slouken@libsdl.org>
-
- This software is provided 'as-is', without any express or implied
- warranty. In no event will the authors be held liable for any damages
- arising from the use of this software.
-
- Permission is granted to anyone to use this software for any purpose,
- including commercial applications, and to alter it and redistribute it
- freely, subject to the following restrictions:
-
- 1. The origin of this software must not be misrepresented; you must not
- claim that you wrote the original software. If you use this software
- in a product, an acknowledgment in the product documentation would be
- appreciated but is not required.
- 2. Altered source versions must be plainly marked as such, and must not be
- misrepresented as being the original software.
- 3. This notice may not be removed or altered from any source distribution.
-*/
-#include "../../SDL_internal.h"
-
-#ifdef SDL_JOYSTICK_HAIKU
-
-/* This is the Haiku implementation of the SDL joystick API */
-
-#include <os/support/String.h>
-#include <os/device/Joystick.h>
-
-extern "C"
-{
-
-#include "SDL_joystick.h"
-#include "../SDL_sysjoystick.h"
-#include "../SDL_joystick_c.h"
-
-
-/* The maximum number of joysticks we'll detect */
-#define MAX_JOYSTICKS 16
-
-/* A list of available joysticks */
- static char *SDL_joyport[MAX_JOYSTICKS];
- static char *SDL_joyname[MAX_JOYSTICKS];
-
-/* The private structure used to keep track of a joystick */
- struct joystick_hwdata
- {
- BJoystick *stick;
- uint8 *new_hats;
- int16 *new_axes;
- };
-
- static int SDL_SYS_numjoysticks = 0;
-
-/* Function to scan the system for joysticks.
- * Joystick 0 should be the system default joystick.
- * It should return 0, or -1 on an unrecoverable fatal error.
- */
- int SDL_SYS_JoystickInit(void)
- {
- BJoystick joystick;
- int i;
- int32 nports;
- char name[B_OS_NAME_LENGTH];
-
- /* Search for attached joysticks */
- nports = joystick.CountDevices();
- SDL_SYS_numjoysticks = 0;
- SDL_memset(SDL_joyport, 0, (sizeof SDL_joyport));
- SDL_memset(SDL_joyname, 0, (sizeof SDL_joyname));
- for (i = 0; (SDL_SYS_numjoysticks < MAX_JOYSTICKS) && (i < nports); ++i)
- {
- if (joystick.GetDeviceName(i, name) == B_OK) {
- if (joystick.Open(name) != B_ERROR) {
- BString stick_name;
- joystick.GetControllerName(&stick_name);
- SDL_joyport[SDL_SYS_numjoysticks] = SDL_strdup(name);
- SDL_joyname[SDL_SYS_numjoysticks] = SDL_strdup(stick_name.String());
- SDL_SYS_numjoysticks++;
- joystick.Close();
- }
- }
- }
- return (SDL_SYS_numjoysticks);
- }
-
- int SDL_SYS_NumJoysticks()
- {
- return SDL_SYS_numjoysticks;
- }
-
- void SDL_SYS_JoystickDetect()
- {
- }
-
-/* Function to get the device-dependent name of a joystick */
- const char *SDL_SYS_JoystickNameForDeviceIndex(int device_index)
- {
- return SDL_joyname[device_index];
- }
-
-/* Function to perform the mapping from device index to the instance id for this index */
- SDL_JoystickID SDL_SYS_GetInstanceIdOfDeviceIndex(int device_index)
- {
- return device_index;
- }
-
-/* Function to open a joystick for use.
- The joystick to open is specified by the device index.
- This should fill the nbuttons and naxes fields of the joystick structure.
- It returns 0, or -1 if there is an error.
- */
- int SDL_SYS_JoystickOpen(SDL_Joystick * joystick, int device_index)
- {
- BJoystick *stick;
-
- /* Create the joystick data structure */
- joystick->instance_id = device_index;
- joystick->hwdata = (struct joystick_hwdata *)
- SDL_malloc(sizeof(*joystick->hwdata));
- if (joystick->hwdata == NULL) {
- return SDL_OutOfMemory();
- }
- SDL_memset(joystick->hwdata, 0, sizeof(*joystick->hwdata));
- stick = new BJoystick;
- joystick->hwdata->stick = stick;
-
- /* Open the requested joystick for use */
- if (stick->Open(SDL_joyport[device_index]) == B_ERROR) {
- SDL_SYS_JoystickClose(joystick);
- return SDL_SetError("Unable to open joystick");
- }
-
- /* Set the joystick to calibrated mode */
- stick->EnableCalibration();
-
- /* Get the number of buttons, hats, and axes on the joystick */
- joystick->nbuttons = stick->CountButtons();
- joystick->naxes = stick->CountAxes();
- joystick->nhats = stick->CountHats();
-
- joystick->hwdata->new_axes = (int16 *)
- SDL_malloc(joystick->naxes * sizeof(int16));
- joystick->hwdata->new_hats = (uint8 *)
- SDL_malloc(joystick->nhats * sizeof(uint8));
- if (!joystick->hwdata->new_hats || !joystick->hwdata->new_axes) {
- SDL_SYS_JoystickClose(joystick);
- return SDL_OutOfMemory();
- }
-
- /* We're done! */
- return (0);
- }
-
-/* Function to determine if this joystick is attached to the system right now */
- SDL_bool SDL_SYS_JoystickAttached(SDL_Joystick *joystick)
- {
- return SDL_TRUE;
- }
-
-/* Function to update the state of a joystick - called as a device poll.
- * This function shouldn't update the joystick structure directly,
- * but instead should call SDL_PrivateJoystick*() to deliver events
- * and update joystick device state.
- */
- void SDL_SYS_JoystickUpdate(SDL_Joystick * joystick)
- {
- static const Uint8 hat_map[9] = {
- SDL_HAT_CENTERED,
- SDL_HAT_UP,
- SDL_HAT_RIGHTUP,
- SDL_HAT_RIGHT,
- SDL_HAT_RIGHTDOWN,
- SDL_HAT_DOWN,
- SDL_HAT_LEFTDOWN,
- SDL_HAT_LEFT,
- SDL_HAT_LEFTUP
- };
- const int JITTER = (32768 / 10); /* 10% jitter threshold (ok?) */
-
- BJoystick *stick;
- int i, change;
- int16 *axes;
- uint8 *hats;
- uint32 buttons;
-
- /* Set up data pointers */
- stick = joystick->hwdata->stick;
- axes = joystick->hwdata->new_axes;
- hats = joystick->hwdata->new_hats;
-
- /* Get the new joystick state */
- stick->Update();
- stick->GetAxisValues(axes);
- stick->GetHatValues(hats);
- buttons = stick->ButtonValues();
-
- /* Generate axis motion events */
- for (i = 0; i < joystick->naxes; ++i) {
- change = ((int32) axes[i] - joystick->axes[i]);
- if ((change > JITTER) || (change < -JITTER)) {
- SDL_PrivateJoystickAxis(joystick, i, axes[i]);
- }
- }
-
- /* Generate hat change events */
- for (i = 0; i < joystick->nhats; ++i) {
- if (hats[i] != joystick->hats[i]) {
- SDL_PrivateJoystickHat(joystick, i, hat_map[hats[i]]);
- }
- }
-
- /* Generate button events */
- for (i = 0; i < joystick->nbuttons; ++i) {
- if ((buttons & 0x01) != joystick->buttons[i]) {
- SDL_PrivateJoystickButton(joystick, i, (buttons & 0x01));
- }
- buttons >>= 1;
- }
- }
-
-/* Function to close a joystick after use */
- void SDL_SYS_JoystickClose(SDL_Joystick * joystick)
- {
- if (joystick->hwdata) {
- joystick->hwdata->stick->Close();
- delete joystick->hwdata->stick;
- SDL_free(joystick->hwdata->new_hats);
- SDL_free(joystick->hwdata->new_axes);
- SDL_free(joystick->hwdata);
- }
- }
-
-/* Function to perform any system-specific joystick related cleanup */
- void SDL_SYS_JoystickQuit(void)
- {
- int i;
-
- for (i = 0; SDL_joyport[i]; ++i) {
- SDL_free(SDL_joyport[i]);
- }
- SDL_joyport[0] = NULL;
-
- for (i = 0; SDL_joyname[i]; ++i) {
- SDL_free(SDL_joyname[i]);
- }
- SDL_joyname[0] = NULL;
- }
-
- SDL_JoystickGUID SDL_SYS_JoystickGetDeviceGUID( int device_index )
- {
- SDL_JoystickGUID guid;
- /* the GUID is just the first 16 chars of the name for now */
- const char *name = SDL_SYS_JoystickNameForDeviceIndex( device_index );
- SDL_zero( guid );
- SDL_memcpy( &guid, name, SDL_min( sizeof(guid), SDL_strlen( name ) ) );
- return guid;
- }
-
- SDL_JoystickGUID SDL_SYS_JoystickGetGUID(SDL_Joystick * joystick)
- {
- SDL_JoystickGUID guid;
- /* the GUID is just the first 16 chars of the name for now */
- const char *name = joystick->name;
- SDL_zero( guid );
- SDL_memcpy( &guid, name, SDL_min( sizeof(guid), SDL_strlen( name ) ) );
- return guid;
- }
-
-}; // extern "C"
-
-#endif /* SDL_JOYSTICK_HAIKU */
-
-/* vi: set ts=4 sw=4 expandtab: */
diff --git a/3rdparty/SDL2/src/joystick/iphoneos/SDL_sysjoystick.m b/3rdparty/SDL2/src/joystick/iphoneos/SDL_sysjoystick.m
deleted file mode 100644
index eb7e000321e..00000000000
--- a/3rdparty/SDL2/src/joystick/iphoneos/SDL_sysjoystick.m
+++ /dev/null
@@ -1,725 +0,0 @@
-/*
- Simple DirectMedia Layer
- Copyright (C) 1997-2016 Sam Lantinga <slouken@libsdl.org>
-
- This software is provided 'as-is', without any express or implied
- warranty. In no event will the authors be held liable for any damages
- arising from the use of this software.
-
- Permission is granted to anyone to use this software for any purpose,
- including commercial applications, and to alter it and redistribute it
- freely, subject to the following restrictions:
-
- 1. The origin of this software must not be misrepresented; you must not
- claim that you wrote the original software. If you use this software
- in a product, an acknowledgment in the product documentation would be
- appreciated but is not required.
- 2. Altered source versions must be plainly marked as such, and must not be
- misrepresented as being the original software.
- 3. This notice may not be removed or altered from any source distribution.
-*/
-#include "../../SDL_internal.h"
-
-/* This is the iOS implementation of the SDL joystick API */
-#include "SDL_sysjoystick_c.h"
-
-/* needed for SDL_IPHONE_MAX_GFORCE macro */
-#include "SDL_config_iphoneos.h"
-
-#include "SDL_events.h"
-#include "SDL_joystick.h"
-#include "SDL_hints.h"
-#include "SDL_stdinc.h"
-#include "../SDL_sysjoystick.h"
-#include "../SDL_joystick_c.h"
-
-#if !SDL_EVENTS_DISABLED
-#include "../../events/SDL_events_c.h"
-#endif
-
-#if !TARGET_OS_TV
-#import <CoreMotion/CoreMotion.h>
-#endif
-
-#ifdef SDL_JOYSTICK_MFI
-#import <GameController/GameController.h>
-
-static id connectObserver = nil;
-static id disconnectObserver = nil;
-#endif /* SDL_JOYSTICK_MFI */
-
-#if !TARGET_OS_TV
-static const char *accelerometerName = "iOS Accelerometer";
-static CMMotionManager *motionManager = nil;
-#endif /* !TARGET_OS_TV */
-
-static SDL_JoystickDeviceItem *deviceList = NULL;
-
-static int numjoysticks = 0;
-static SDL_JoystickID instancecounter = 0;
-
-static SDL_JoystickDeviceItem *
-GetDeviceForIndex(int device_index)
-{
- SDL_JoystickDeviceItem *device = deviceList;
- int i = 0;
-
- while (i < device_index) {
- if (device == NULL) {
- return NULL;
- }
- device = device->next;
- i++;
- }
-
- return device;
-}
-
-static void
-SDL_SYS_AddMFIJoystickDevice(SDL_JoystickDeviceItem *device, GCController *controller)
-{
-#ifdef SDL_JOYSTICK_MFI
- const char *name = NULL;
- /* Explicitly retain the controller because SDL_JoystickDeviceItem is a
- * struct, and ARC doesn't work with structs. */
- device->controller = (__bridge GCController *) CFBridgingRetain(controller);
-
- if (controller.vendorName) {
- name = controller.vendorName.UTF8String;
- }
-
- if (!name) {
- name = "MFi Gamepad";
- }
-
- device->name = SDL_strdup(name);
-
- device->guid.data[0] = 'M';
- device->guid.data[1] = 'F';
- device->guid.data[2] = 'i';
- device->guid.data[3] = 'G';
- device->guid.data[4] = 'a';
- device->guid.data[5] = 'm';
- device->guid.data[6] = 'e';
- device->guid.data[7] = 'p';
- device->guid.data[8] = 'a';
- device->guid.data[9] = 'd';
-
- if (controller.extendedGamepad) {
- device->guid.data[10] = 1;
- } else if (controller.gamepad) {
- device->guid.data[10] = 2;
- }
-#if TARGET_OS_TV
- else if (controller.microGamepad) {
- device->guid.data[10] = 3;
- }
-#endif /* TARGET_OS_TV */
-
- if (controller.extendedGamepad) {
- device->naxes = 6; /* 2 thumbsticks and 2 triggers */
- device->nhats = 1; /* d-pad */
- device->nbuttons = 7; /* ABXY, shoulder buttons, pause button */
- } else if (controller.gamepad) {
- device->naxes = 0; /* no traditional analog inputs */
- device->nhats = 1; /* d-pad */
- device->nbuttons = 7; /* ABXY, shoulder buttons, pause button */
- }
-#if TARGET_OS_TV
- else if (controller.microGamepad) {
- device->naxes = 2; /* treat the touch surface as two axes */
- device->nhats = 0; /* apparently the touch surface-as-dpad is buggy */
- device->nbuttons = 3; /* AX, pause button */
-
- controller.microGamepad.allowsRotation = SDL_GetHintBoolean(SDL_HINT_APPLE_TV_REMOTE_ALLOW_ROTATION, SDL_FALSE);
- }
-#endif /* TARGET_OS_TV */
-
- /* This will be set when the first button press of the controller is
- * detected. */
- controller.playerIndex = -1;
-
-#endif /* SDL_JOYSTICK_MFI */
-}
-
-static void
-SDL_SYS_AddJoystickDevice(GCController *controller, SDL_bool accelerometer)
-{
- SDL_JoystickDeviceItem *device = deviceList;
-
- while (device != NULL) {
- if (device->controller == controller) {
- return;
- }
- device = device->next;
- }
-
- device = (SDL_JoystickDeviceItem *) SDL_malloc(sizeof(SDL_JoystickDeviceItem));
- if (device == NULL) {
- return;
- }
-
- SDL_zerop(device);
-
- device->accelerometer = accelerometer;
- device->instance_id = instancecounter++;
-
- if (accelerometer) {
-#if TARGET_OS_TV
- SDL_free(device);
- return;
-#else
- device->name = SDL_strdup(accelerometerName);
- device->naxes = 3; /* Device acceleration in the x, y, and z axes. */
- device->nhats = 0;
- device->nbuttons = 0;
-
- /* Use the accelerometer name as a GUID. */
- SDL_memcpy(&device->guid.data, device->name, SDL_min(sizeof(SDL_JoystickGUID), SDL_strlen(device->name)));
-#endif /* TARGET_OS_TV */
- } else if (controller) {
- SDL_SYS_AddMFIJoystickDevice(device, controller);
- }
-
- if (deviceList == NULL) {
- deviceList = device;
- } else {
- SDL_JoystickDeviceItem *lastdevice = deviceList;
- while (lastdevice->next != NULL) {
- lastdevice = lastdevice->next;
- }
- lastdevice->next = device;
- }
-
- ++numjoysticks;
-
- SDL_PrivateJoystickAdded(numjoysticks - 1);
-}
-
-static SDL_JoystickDeviceItem *
-SDL_SYS_RemoveJoystickDevice(SDL_JoystickDeviceItem *device)
-{
- SDL_JoystickDeviceItem *prev = NULL;
- SDL_JoystickDeviceItem *next = NULL;
- SDL_JoystickDeviceItem *item = deviceList;
-
- if (device == NULL) {
- return NULL;
- }
-
- next = device->next;
-
- while (item != NULL) {
- if (item == device) {
- break;
- }
- prev = item;
- item = item->next;
- }
-
- /* Unlink the device item from the device list. */
- if (prev) {
- prev->next = device->next;
- } else if (device == deviceList) {
- deviceList = device->next;
- }
-
- if (device->joystick) {
- device->joystick->hwdata = NULL;
- }
-
-#ifdef SDL_JOYSTICK_MFI
- @autoreleasepool {
- if (device->controller) {
- /* The controller was explicitly retained in the struct, so it
- * should be explicitly released before freeing the struct. */
- GCController *controller = CFBridgingRelease((__bridge CFTypeRef)(device->controller));
- controller.controllerPausedHandler = nil;
- device->controller = nil;
- }
- }
-#endif /* SDL_JOYSTICK_MFI */
-
- --numjoysticks;
-
- SDL_PrivateJoystickRemoved(device->instance_id);
-
- SDL_free(device->name);
- SDL_free(device);
-
- return next;
-}
-
-#if TARGET_OS_TV
-static void
-SDL_AppleTVRemoteRotationHintChanged(void *udata, const char *name, const char *oldValue, const char *newValue)
-{
- BOOL allowRotation = newValue != NULL && *newValue != '0';
-
- @autoreleasepool {
- for (GCController *controller in [GCController controllers]) {
- if (controller.microGamepad) {
- controller.microGamepad.allowsRotation = allowRotation;
- }
- }
- }
-}
-#endif /* TARGET_OS_TV */
-
-/* Function to scan the system for joysticks.
- * Joystick 0 should be the system default joystick.
- * It should return 0, or -1 on an unrecoverable fatal error.
- */
-int
-SDL_SYS_JoystickInit(void)
-{
- @autoreleasepool {
- NSNotificationCenter *center = [NSNotificationCenter defaultCenter];
-
-#if !TARGET_OS_TV
- if (SDL_GetHintBoolean(SDL_HINT_ACCELEROMETER_AS_JOYSTICK, SDL_TRUE)) {
- /* Default behavior, accelerometer as joystick */
- SDL_SYS_AddJoystickDevice(nil, SDL_TRUE);
- }
-#endif /* !TARGET_OS_TV */
-
-#ifdef SDL_JOYSTICK_MFI
- /* GameController.framework was added in iOS 7. */
- if (![GCController class]) {
- return numjoysticks;
- }
-
- for (GCController *controller in [GCController controllers]) {
- SDL_SYS_AddJoystickDevice(controller, SDL_FALSE);
- }
-
-#if TARGET_OS_TV
- SDL_AddHintCallback(SDL_HINT_APPLE_TV_REMOTE_ALLOW_ROTATION,
- SDL_AppleTVRemoteRotationHintChanged, NULL);
-#endif /* TARGET_OS_TV */
-
- connectObserver = [center addObserverForName:GCControllerDidConnectNotification
- object:nil
- queue:nil
- usingBlock:^(NSNotification *note) {
- GCController *controller = note.object;
- SDL_SYS_AddJoystickDevice(controller, SDL_FALSE);
- }];
-
- disconnectObserver = [center addObserverForName:GCControllerDidDisconnectNotification
- object:nil
- queue:nil
- usingBlock:^(NSNotification *note) {
- GCController *controller = note.object;
- SDL_JoystickDeviceItem *device = deviceList;
- while (device != NULL) {
- if (device->controller == controller) {
- SDL_SYS_RemoveJoystickDevice(device);
- break;
- }
- device = device->next;
- }
- }];
-#endif /* SDL_JOYSTICK_MFI */
- }
-
- return numjoysticks;
-}
-
-int SDL_SYS_NumJoysticks()
-{
- return numjoysticks;
-}
-
-void SDL_SYS_JoystickDetect()
-{
-}
-
-/* Function to get the device-dependent name of a joystick */
-const char *
-SDL_SYS_JoystickNameForDeviceIndex(int device_index)
-{
- SDL_JoystickDeviceItem *device = GetDeviceForIndex(device_index);
- return device ? device->name : "Unknown";
-}
-
-/* Function to perform the mapping from device index to the instance id for this index */
-SDL_JoystickID SDL_SYS_GetInstanceIdOfDeviceIndex(int device_index)
-{
- SDL_JoystickDeviceItem *device = GetDeviceForIndex(device_index);
- return device ? device->instance_id : 0;
-}
-
-/* Function to open a joystick for use.
- The joystick to open is specified by the device index.
- This should fill the nbuttons and naxes fields of the joystick structure.
- It returns 0, or -1 if there is an error.
- */
-int
-SDL_SYS_JoystickOpen(SDL_Joystick * joystick, int device_index)
-{
- SDL_JoystickDeviceItem *device = GetDeviceForIndex(device_index);
- if (device == NULL) {
- return SDL_SetError("Could not open Joystick: no hardware device for the specified index");
- }
-
- joystick->hwdata = device;
- joystick->instance_id = device->instance_id;
-
- joystick->naxes = device->naxes;
- joystick->nhats = device->nhats;
- joystick->nbuttons = device->nbuttons;
- joystick->nballs = 0;
-
- device->joystick = joystick;
-
- @autoreleasepool {
- if (device->accelerometer) {
-#if !TARGET_OS_TV
- if (motionManager == nil) {
- motionManager = [[CMMotionManager alloc] init];
- }
-
- /* Shorter times between updates can significantly increase CPU usage. */
- motionManager.accelerometerUpdateInterval = 0.1;
- [motionManager startAccelerometerUpdates];
-#endif /* !TARGET_OS_TV */
- } else {
-#ifdef SDL_JOYSTICK_MFI
- GCController *controller = device->controller;
- controller.controllerPausedHandler = ^(GCController *c) {
- if (joystick->hwdata) {
- ++joystick->hwdata->num_pause_presses;
- }
- };
-#endif /* SDL_JOYSTICK_MFI */
- }
- }
-
- return 0;
-}
-
-/* Function to determine if this joystick is attached to the system right now */
-SDL_bool
-SDL_SYS_JoystickAttached(SDL_Joystick *joystick)
-{
- return joystick->hwdata != NULL;
-}
-
-static void
-SDL_SYS_AccelerometerUpdate(SDL_Joystick * joystick)
-{
-#if !TARGET_OS_TV
- const float maxgforce = SDL_IPHONE_MAX_GFORCE;
- const SInt16 maxsint16 = 0x7FFF;
- CMAcceleration accel;
-
- @autoreleasepool {
- if (!motionManager.isAccelerometerActive) {
- return;
- }
-
- accel = motionManager.accelerometerData.acceleration;
- }
-
- /*
- Convert accelerometer data from floating point to Sint16, which is what
- the joystick system expects.
-
- To do the conversion, the data is first clamped onto the interval
- [-SDL_IPHONE_MAX_G_FORCE, SDL_IPHONE_MAX_G_FORCE], then the data is multiplied
- by MAX_SINT16 so that it is mapped to the full range of an Sint16.
-
- You can customize the clamped range of this function by modifying the
- SDL_IPHONE_MAX_GFORCE macro in SDL_config_iphoneos.h.
-
- Once converted to Sint16, the accelerometer data no longer has coherent
- units. You can convert the data back to units of g-force by multiplying
- it in your application's code by SDL_IPHONE_MAX_GFORCE / 0x7FFF.
- */
-
- /* clamp the data */
- accel.x = SDL_min(SDL_max(accel.x, -maxgforce), maxgforce);
- accel.y = SDL_min(SDL_max(accel.y, -maxgforce), maxgforce);
- accel.z = SDL_min(SDL_max(accel.z, -maxgforce), maxgforce);
-
- /* pass in data mapped to range of SInt16 */
- SDL_PrivateJoystickAxis(joystick, 0, (accel.x / maxgforce) * maxsint16);
- SDL_PrivateJoystickAxis(joystick, 1, -(accel.y / maxgforce) * maxsint16);
- SDL_PrivateJoystickAxis(joystick, 2, (accel.z / maxgforce) * maxsint16);
-#endif /* !TARGET_OS_TV */
-}
-
-#ifdef SDL_JOYSTICK_MFI
-static Uint8
-SDL_SYS_MFIJoystickHatStateForDPad(GCControllerDirectionPad *dpad)
-{
- Uint8 hat = 0;
-
- if (dpad.up.isPressed) {
- hat |= SDL_HAT_UP;
- } else if (dpad.down.isPressed) {
- hat |= SDL_HAT_DOWN;
- }
-
- if (dpad.left.isPressed) {
- hat |= SDL_HAT_LEFT;
- } else if (dpad.right.isPressed) {
- hat |= SDL_HAT_RIGHT;
- }
-
- if (hat == 0) {
- return SDL_HAT_CENTERED;
- }
-
- return hat;
-}
-#endif
-
-static void
-SDL_SYS_MFIJoystickUpdate(SDL_Joystick * joystick)
-{
-#if SDL_JOYSTICK_MFI
- @autoreleasepool {
- GCController *controller = joystick->hwdata->controller;
- Uint8 hatstate = SDL_HAT_CENTERED;
- int i;
- int updateplayerindex = 0;
-
- if (controller.extendedGamepad) {
- GCExtendedGamepad *gamepad = controller.extendedGamepad;
-
- /* Axis order matches the XInput Windows mappings. */
- Sint16 axes[] = {
- (Sint16) (gamepad.leftThumbstick.xAxis.value * 32767),
- (Sint16) (gamepad.leftThumbstick.yAxis.value * -32767),
- (Sint16) ((gamepad.leftTrigger.value * 65535) - 32768),
- (Sint16) (gamepad.rightThumbstick.xAxis.value * 32767),
- (Sint16) (gamepad.rightThumbstick.yAxis.value * -32767),
- (Sint16) ((gamepad.rightTrigger.value * 65535) - 32768),
- };
-
- /* Button order matches the XInput Windows mappings. */
- Uint8 buttons[] = {
- gamepad.buttonA.isPressed, gamepad.buttonB.isPressed,
- gamepad.buttonX.isPressed, gamepad.buttonY.isPressed,
- gamepad.leftShoulder.isPressed,
- gamepad.rightShoulder.isPressed,
- };
-
- hatstate = SDL_SYS_MFIJoystickHatStateForDPad(gamepad.dpad);
-
- for (i = 0; i < SDL_arraysize(axes); i++) {
- /* The triggers (axes 2 and 5) are resting at -32768 but SDL
- * initializes its values to 0. We only want to make sure the
- * player index is up to date if the user actually moves an axis. */
- if ((i != 2 && i != 5) || axes[i] != -32768) {
- updateplayerindex |= (joystick->axes[i] != axes[i]);
- }
- SDL_PrivateJoystickAxis(joystick, i, axes[i]);
- }
-
- for (i = 0; i < SDL_arraysize(buttons); i++) {
- updateplayerindex |= (joystick->buttons[i] != buttons[i]);
- SDL_PrivateJoystickButton(joystick, i, buttons[i]);
- }
- } else if (controller.gamepad) {
- GCGamepad *gamepad = controller.gamepad;
-
- /* Button order matches the XInput Windows mappings. */
- Uint8 buttons[] = {
- gamepad.buttonA.isPressed, gamepad.buttonB.isPressed,
- gamepad.buttonX.isPressed, gamepad.buttonY.isPressed,
- gamepad.leftShoulder.isPressed,
- gamepad.rightShoulder.isPressed,
- };
-
- hatstate = SDL_SYS_MFIJoystickHatStateForDPad(gamepad.dpad);
-
- for (i = 0; i < SDL_arraysize(buttons); i++) {
- updateplayerindex |= (joystick->buttons[i] != buttons[i]);
- SDL_PrivateJoystickButton(joystick, i, buttons[i]);
- }
- }
-#if TARGET_OS_TV
- else if (controller.microGamepad) {
- GCMicroGamepad *gamepad = controller.microGamepad;
-
- Sint16 axes[] = {
- (Sint16) (gamepad.dpad.xAxis.value * 32767),
- (Sint16) (gamepad.dpad.yAxis.value * -32767),
- };
-
- for (i = 0; i < SDL_arraysize(axes); i++) {
- updateplayerindex |= (joystick->axes[i] != axes[i]);
- SDL_PrivateJoystickAxis(joystick, i, axes[i]);
- }
-
- /* Apparently the dpad values are not accurate enough to be useful. */
- /* hatstate = SDL_SYS_MFIJoystickHatStateForDPad(gamepad.dpad); */
-
- Uint8 buttons[] = {
- gamepad.buttonA.isPressed,
- gamepad.buttonX.isPressed,
- };
-
- for (i = 0; i < SDL_arraysize(buttons); i++) {
- updateplayerindex |= (joystick->buttons[i] != buttons[i]);
- SDL_PrivateJoystickButton(joystick, i, buttons[i]);
- }
-
- /* TODO: Figure out what to do with reportsAbsoluteDpadValues */
- }
-#endif /* TARGET_OS_TV */
-
- if (joystick->nhats > 0) {
- updateplayerindex |= (joystick->hats[0] != hatstate);
- SDL_PrivateJoystickHat(joystick, 0, hatstate);
- }
-
- for (i = 0; i < joystick->hwdata->num_pause_presses; i++) {
- /* The pause button is always last. */
- Uint8 pausebutton = joystick->nbuttons - 1;
-
- SDL_PrivateJoystickButton(joystick, pausebutton, SDL_PRESSED);
- SDL_PrivateJoystickButton(joystick, pausebutton, SDL_RELEASED);
-
- updateplayerindex = YES;
- }
-
- joystick->hwdata->num_pause_presses = 0;
-
- if (updateplayerindex && controller.playerIndex == -1) {
- BOOL usedPlayerIndexSlots[4] = {NO, NO, NO, NO};
-
- /* Find the player index of all other connected controllers. */
- for (GCController *c in [GCController controllers]) {
- if (c != controller && c.playerIndex >= 0) {
- usedPlayerIndexSlots[c.playerIndex] = YES;
- }
- }
-
- /* Set this controller's player index to the first unused index.
- * FIXME: This logic isn't great... but SDL doesn't expose this
- * concept in its external API, so we don't have much to go on. */
- for (i = 0; i < SDL_arraysize(usedPlayerIndexSlots); i++) {
- if (!usedPlayerIndexSlots[i]) {
- controller.playerIndex = i;
- break;
- }
- }
- }
- }
-#endif /* SDL_JOYSTICK_MFI */
-}
-
-/* Function to update the state of a joystick - called as a device poll.
- * This function shouldn't update the joystick structure directly,
- * but instead should call SDL_PrivateJoystick*() to deliver events
- * and update joystick device state.
- */
-void
-SDL_SYS_JoystickUpdate(SDL_Joystick * joystick)
-{
- SDL_JoystickDeviceItem *device = joystick->hwdata;
-
- if (device == NULL) {
- return;
- }
-
- if (device->accelerometer) {
- SDL_SYS_AccelerometerUpdate(joystick);
- } else if (device->controller) {
- SDL_SYS_MFIJoystickUpdate(joystick);
- }
-}
-
-/* Function to close a joystick after use */
-void
-SDL_SYS_JoystickClose(SDL_Joystick * joystick)
-{
- SDL_JoystickDeviceItem *device = joystick->hwdata;
-
- if (device == NULL) {
- return;
- }
-
- device->joystick = NULL;
-
- @autoreleasepool {
- if (device->accelerometer) {
-#if !TARGET_OS_TV
- [motionManager stopAccelerometerUpdates];
-#endif /* !TARGET_OS_TV */
- } else if (device->controller) {
-#ifdef SDL_JOYSTICK_MFI
- GCController *controller = device->controller;
- controller.controllerPausedHandler = nil;
- controller.playerIndex = -1;
-#endif
- }
- }
-}
-
-/* Function to perform any system-specific joystick related cleanup */
-void
-SDL_SYS_JoystickQuit(void)
-{
- @autoreleasepool {
-#ifdef SDL_JOYSTICK_MFI
- NSNotificationCenter *center = [NSNotificationCenter defaultCenter];
-
- if (connectObserver) {
- [center removeObserver:connectObserver name:GCControllerDidConnectNotification object:nil];
- connectObserver = nil;
- }
-
- if (disconnectObserver) {
- [center removeObserver:disconnectObserver name:GCControllerDidDisconnectNotification object:nil];
- disconnectObserver = nil;
- }
-
-#if TARGET_OS_TV
- SDL_DelHintCallback(SDL_HINT_APPLE_TV_REMOTE_ALLOW_ROTATION,
- SDL_AppleTVRemoteRotationHintChanged, NULL);
-#endif /* TARGET_OS_TV */
-#endif /* SDL_JOYSTICK_MFI */
-
- while (deviceList != NULL) {
- SDL_SYS_RemoveJoystickDevice(deviceList);
- }
-
-#if !TARGET_OS_TV
- motionManager = nil;
-#endif /* !TARGET_OS_TV */
- }
-
- numjoysticks = 0;
-}
-
-SDL_JoystickGUID
-SDL_SYS_JoystickGetDeviceGUID( int device_index )
-{
- SDL_JoystickDeviceItem *device = GetDeviceForIndex(device_index);
- SDL_JoystickGUID guid;
- if (device) {
- guid = device->guid;
- } else {
- SDL_zero(guid);
- }
- return guid;
-}
-
-SDL_JoystickGUID
-SDL_SYS_JoystickGetGUID(SDL_Joystick * joystick)
-{
- SDL_JoystickGUID guid;
- if (joystick->hwdata) {
- guid = joystick->hwdata->guid;
- } else {
- SDL_zero(guid);
- }
- return guid;
-}
-
-/* vi: set ts=4 sw=4 expandtab: */
diff --git a/3rdparty/SDL2/src/joystick/iphoneos/SDL_sysjoystick_c.h b/3rdparty/SDL2/src/joystick/iphoneos/SDL_sysjoystick_c.h
deleted file mode 100644
index be0ddf068af..00000000000
--- a/3rdparty/SDL2/src/joystick/iphoneos/SDL_sysjoystick_c.h
+++ /dev/null
@@ -1,55 +0,0 @@
-/*
- Simple DirectMedia Layer
- Copyright (C) 1997-2016 Sam Lantinga <slouken@libsdl.org>
-
- This software is provided 'as-is', without any express or implied
- warranty. In no event will the authors be held liable for any damages
- arising from the use of this software.
-
- Permission is granted to anyone to use this software for any purpose,
- including commercial applications, and to alter it and redistribute it
- freely, subject to the following restrictions:
-
- 1. The origin of this software must not be misrepresented; you must not
- claim that you wrote the original software. If you use this software
- in a product, an acknowledgment in the product documentation would be
- appreciated but is not required.
- 2. Altered source versions must be plainly marked as such, and must not be
- misrepresented as being the original software.
- 3. This notice may not be removed or altered from any source distribution.
-*/
-#include "../../SDL_internal.h"
-
-#ifndef SDL_JOYSTICK_IOS_H
-#define SDL_JOYSTICK_IOS_H
-
-#include "SDL_stdinc.h"
-#include "../SDL_sysjoystick.h"
-
-@class GCController;
-
-typedef struct joystick_hwdata
-{
- SDL_bool accelerometer;
-
- GCController __unsafe_unretained *controller;
- int num_pause_presses;
-
- char *name;
- SDL_Joystick *joystick;
- SDL_JoystickID instance_id;
- SDL_JoystickGUID guid;
-
- int naxes;
- int nbuttons;
- int nhats;
-
- struct joystick_hwdata *next;
-} joystick_hwdata;
-
-typedef joystick_hwdata SDL_JoystickDeviceItem;
-
-#endif /* SDL_JOYSTICK_IOS_H */
-
-
-/* vi: set ts=4 sw=4 expandtab: */
diff --git a/3rdparty/SDL2/src/joystick/linux/SDL_sysjoystick.c b/3rdparty/SDL2/src/joystick/linux/SDL_sysjoystick.c
deleted file mode 100644
index bd52b18080b..00000000000
--- a/3rdparty/SDL2/src/joystick/linux/SDL_sysjoystick.c
+++ /dev/null
@@ -1,847 +0,0 @@
-/*
- Simple DirectMedia Layer
- Copyright (C) 1997-2016 Sam Lantinga <slouken@libsdl.org>
-
- This software is provided 'as-is', without any express or implied
- warranty. In no event will the authors be held liable for any damages
- arising from the use of this software.
-
- Permission is granted to anyone to use this software for any purpose,
- including commercial applications, and to alter it and redistribute it
- freely, subject to the following restrictions:
-
- 1. The origin of this software must not be misrepresented; you must not
- claim that you wrote the original software. If you use this software
- in a product, an acknowledgment in the product documentation would be
- appreciated but is not required.
- 2. Altered source versions must be plainly marked as such, and must not be
- misrepresented as being the original software.
- 3. This notice may not be removed or altered from any source distribution.
-*/
-#include "../../SDL_internal.h"
-
-#ifdef SDL_JOYSTICK_LINUX
-
-#ifndef SDL_INPUT_LINUXEV
-#error SDL now requires a Linux 2.4+ kernel with /dev/input/event support.
-#endif
-
-/* This is the Linux implementation of the SDL joystick API */
-
-#include <sys/stat.h>
-#include <unistd.h>
-#include <fcntl.h>
-#include <sys/ioctl.h>
-#include <limits.h> /* For the definition of PATH_MAX */
-#include <linux/joystick.h>
-
-#include "SDL_assert.h"
-#include "SDL_joystick.h"
-#include "SDL_endian.h"
-#include "../SDL_sysjoystick.h"
-#include "../SDL_joystick_c.h"
-#include "SDL_sysjoystick_c.h"
-
-/* This isn't defined in older Linux kernel headers */
-#ifndef SYN_DROPPED
-#define SYN_DROPPED 3
-#endif
-
-#include "../../core/linux/SDL_udev.h"
-
-static int MaybeAddDevice(const char *path);
-#if SDL_USE_LIBUDEV
-static int MaybeRemoveDevice(const char *path);
-void joystick_udev_callback(SDL_UDEV_deviceevent udev_type, int udev_class, const char *devpath);
-#endif /* SDL_USE_LIBUDEV */
-
-
-/* A linked list of available joysticks */
-typedef struct SDL_joylist_item
-{
- int device_instance;
- char *path; /* "/dev/input/event2" or whatever */
- char *name; /* "SideWinder 3D Pro" or whatever */
- SDL_JoystickGUID guid;
- dev_t devnum;
- struct joystick_hwdata *hwdata;
- struct SDL_joylist_item *next;
-} SDL_joylist_item;
-
-static SDL_joylist_item *SDL_joylist = NULL;
-static SDL_joylist_item *SDL_joylist_tail = NULL;
-static int numjoysticks = 0;
-static int instance_counter = 0;
-
-#define test_bit(nr, addr) \
- (((1UL << ((nr) % (sizeof(long) * 8))) & ((addr)[(nr) / (sizeof(long) * 8)])) != 0)
-#define NBITS(x) ((((x)-1)/(sizeof(long) * 8))+1)
-
-static int
-IsJoystick(int fd, char *namebuf, const size_t namebuflen, SDL_JoystickGUID *guid)
-{
- struct input_id inpid;
- Uint16 *guid16 = (Uint16 *) ((char *) &guid->data);
-
-#if !SDL_USE_LIBUDEV
- /* When udev is enabled we only get joystick devices here, so there's no need to test them */
- unsigned long evbit[NBITS(EV_MAX)] = { 0 };
- unsigned long keybit[NBITS(KEY_MAX)] = { 0 };
- unsigned long absbit[NBITS(ABS_MAX)] = { 0 };
-
- if ((ioctl(fd, EVIOCGBIT(0, sizeof(evbit)), evbit) < 0) ||
- (ioctl(fd, EVIOCGBIT(EV_KEY, sizeof(keybit)), keybit) < 0) ||
- (ioctl(fd, EVIOCGBIT(EV_ABS, sizeof(absbit)), absbit) < 0)) {
- return (0);
- }
-
- if (!(test_bit(EV_KEY, evbit) && test_bit(EV_ABS, evbit) &&
- test_bit(ABS_X, absbit) && test_bit(ABS_Y, absbit))) {
- return 0;
- }
-#endif
-
- if (ioctl(fd, EVIOCGNAME(namebuflen), namebuf) < 0) {
- return 0;
- }
-
- if (ioctl(fd, EVIOCGID, &inpid) < 0) {
- return 0;
- }
-
-#ifdef DEBUG_JOYSTICK
- printf("Joystick: %s, bustype = %d, vendor = 0x%x, product = 0x%x, version = %d\n", namebuf, inpid.bustype, inpid.vendor, inpid.product, inpid.version);
-#endif
-
- SDL_memset(guid->data, 0, sizeof(guid->data));
-
- /* We only need 16 bits for each of these; space them out to fill 128. */
- /* Byteswap so devices get same GUID on little/big endian platforms. */
- *(guid16++) = SDL_SwapLE16(inpid.bustype);
- *(guid16++) = 0;
-
- if (inpid.vendor && inpid.product && inpid.version) {
- *(guid16++) = SDL_SwapLE16(inpid.vendor);
- *(guid16++) = 0;
- *(guid16++) = SDL_SwapLE16(inpid.product);
- *(guid16++) = 0;
- *(guid16++) = SDL_SwapLE16(inpid.version);
- *(guid16++) = 0;
- } else {
- SDL_strlcpy((char*)guid16, namebuf, sizeof(guid->data) - 4);
- }
-
- return 1;
-}
-
-#if SDL_USE_LIBUDEV
-void joystick_udev_callback(SDL_UDEV_deviceevent udev_type, int udev_class, const char *devpath)
-{
- if (devpath == NULL) {
- return;
- }
-
- switch (udev_type) {
- case SDL_UDEV_DEVICEADDED:
- if (!(udev_class & SDL_UDEV_DEVICE_JOYSTICK)) {
- return;
- }
- MaybeAddDevice(devpath);
- break;
-
- case SDL_UDEV_DEVICEREMOVED:
- MaybeRemoveDevice(devpath);
- break;
-
- default:
- break;
- }
-
-}
-#endif /* SDL_USE_LIBUDEV */
-
-
-/* !!! FIXME: I would love to dump this code and use libudev instead. */
-static int
-MaybeAddDevice(const char *path)
-{
- struct stat sb;
- int fd = -1;
- int isstick = 0;
- char namebuf[128];
- SDL_JoystickGUID guid;
- SDL_joylist_item *item;
-
- if (path == NULL) {
- return -1;
- }
-
- if (stat(path, &sb) == -1) {
- return -1;
- }
-
- /* Check to make sure it's not already in list. */
- for (item = SDL_joylist; item != NULL; item = item->next) {
- if (sb.st_rdev == item->devnum) {
- return -1; /* already have this one */
- }
- }
-
- fd = open(path, O_RDONLY, 0);
- if (fd < 0) {
- return -1;
- }
-
-#ifdef DEBUG_INPUT_EVENTS
- printf("Checking %s\n", path);
-#endif
-
- isstick = IsJoystick(fd, namebuf, sizeof (namebuf), &guid);
- close(fd);
- if (!isstick) {
- return -1;
- }
-
- item = (SDL_joylist_item *) SDL_malloc(sizeof (SDL_joylist_item));
- if (item == NULL) {
- return -1;
- }
-
- SDL_zerop(item);
- item->devnum = sb.st_rdev;
- item->path = SDL_strdup(path);
- item->name = SDL_strdup(namebuf);
- item->guid = guid;
-
- if ( (item->path == NULL) || (item->name == NULL) ) {
- SDL_free(item->path);
- SDL_free(item->name);
- SDL_free(item);
- return -1;
- }
-
- item->device_instance = instance_counter++;
- if (SDL_joylist_tail == NULL) {
- SDL_joylist = SDL_joylist_tail = item;
- } else {
- SDL_joylist_tail->next = item;
- SDL_joylist_tail = item;
- }
-
- /* Need to increment the joystick count before we post the event */
- ++numjoysticks;
-
- SDL_PrivateJoystickAdded(numjoysticks - 1);
-
- return numjoysticks;
-}
-
-#if SDL_USE_LIBUDEV
-/* !!! FIXME: I would love to dump this code and use libudev instead. */
-static int
-MaybeRemoveDevice(const char *path)
-{
- SDL_joylist_item *item;
- SDL_joylist_item *prev = NULL;
-
- if (path == NULL) {
- return -1;
- }
-
- for (item = SDL_joylist; item != NULL; item = item->next) {
- /* found it, remove it. */
- if (SDL_strcmp(path, item->path) == 0) {
- const int retval = item->device_instance;
- if (item->hwdata) {
- item->hwdata->item = NULL;
- }
- if (prev != NULL) {
- prev->next = item->next;
- } else {
- SDL_assert(SDL_joylist == item);
- SDL_joylist = item->next;
- }
- if (item == SDL_joylist_tail) {
- SDL_joylist_tail = prev;
- }
-
- /* Need to decrement the joystick count before we post the event */
- --numjoysticks;
-
- SDL_PrivateJoystickRemoved(item->device_instance);
-
- SDL_free(item->path);
- SDL_free(item->name);
- SDL_free(item);
- return retval;
- }
- prev = item;
- }
-
- return -1;
-}
-#endif
-
-static int
-JoystickInitWithoutUdev(void)
-{
- int i;
- char path[PATH_MAX];
-
- /* !!! FIXME: only finds sticks if they're called /dev/input/event[0..31] */
- /* !!! FIXME: we could at least readdir() through /dev/input...? */
- /* !!! FIXME: (or delete this and rely on libudev?) */
- for (i = 0; i < 32; i++) {
- SDL_snprintf(path, SDL_arraysize(path), "/dev/input/event%d", i);
- MaybeAddDevice(path);
- }
-
- return numjoysticks;
-}
-
-
-#if SDL_USE_LIBUDEV
-static int
-JoystickInitWithUdev(void)
-{
- if (SDL_UDEV_Init() < 0) {
- return SDL_SetError("Could not initialize UDEV");
- }
-
- /* Set up the udev callback */
- if (SDL_UDEV_AddCallback(joystick_udev_callback) < 0) {
- SDL_UDEV_Quit();
- return SDL_SetError("Could not set up joystick <-> udev callback");
- }
-
- /* Force a scan to build the initial device list */
- SDL_UDEV_Scan();
-
- return numjoysticks;
-}
-#endif
-
-int
-SDL_SYS_JoystickInit(void)
-{
- /* First see if the user specified one or more joysticks to use */
- if (SDL_getenv("SDL_JOYSTICK_DEVICE") != NULL) {
- char *envcopy, *envpath, *delim;
- envcopy = SDL_strdup(SDL_getenv("SDL_JOYSTICK_DEVICE"));
- envpath = envcopy;
- while (envpath != NULL) {
- delim = SDL_strchr(envpath, ':');
- if (delim != NULL) {
- *delim++ = '\0';
- }
- MaybeAddDevice(envpath);
- envpath = delim;
- }
- SDL_free(envcopy);
- }
-
-#if SDL_USE_LIBUDEV
- return JoystickInitWithUdev();
-#endif
-
- return JoystickInitWithoutUdev();
-}
-
-int SDL_SYS_NumJoysticks()
-{
- return numjoysticks;
-}
-
-void SDL_SYS_JoystickDetect()
-{
-#if SDL_USE_LIBUDEV
- SDL_UDEV_Poll();
-#endif
-
-}
-
-static SDL_joylist_item *
-JoystickByDevIndex(int device_index)
-{
- SDL_joylist_item *item = SDL_joylist;
-
- if ((device_index < 0) || (device_index >= numjoysticks)) {
- return NULL;
- }
-
- while (device_index > 0) {
- SDL_assert(item != NULL);
- device_index--;
- item = item->next;
- }
-
- return item;
-}
-
-/* Function to get the device-dependent name of a joystick */
-const char *
-SDL_SYS_JoystickNameForDeviceIndex(int device_index)
-{
- return JoystickByDevIndex(device_index)->name;
-}
-
-/* Function to perform the mapping from device index to the instance id for this index */
-SDL_JoystickID SDL_SYS_GetInstanceIdOfDeviceIndex(int device_index)
-{
- return JoystickByDevIndex(device_index)->device_instance;
-}
-
-static int
-allocate_hatdata(SDL_Joystick * joystick)
-{
- int i;
-
- joystick->hwdata->hats =
- (struct hwdata_hat *) SDL_malloc(joystick->nhats *
- sizeof(struct hwdata_hat));
- if (joystick->hwdata->hats == NULL) {
- return (-1);
- }
- for (i = 0; i < joystick->nhats; ++i) {
- joystick->hwdata->hats[i].axis[0] = 1;
- joystick->hwdata->hats[i].axis[1] = 1;
- }
- return (0);
-}
-
-static int
-allocate_balldata(SDL_Joystick * joystick)
-{
- int i;
-
- joystick->hwdata->balls =
- (struct hwdata_ball *) SDL_malloc(joystick->nballs *
- sizeof(struct hwdata_ball));
- if (joystick->hwdata->balls == NULL) {
- return (-1);
- }
- for (i = 0; i < joystick->nballs; ++i) {
- joystick->hwdata->balls[i].axis[0] = 0;
- joystick->hwdata->balls[i].axis[1] = 0;
- }
- return (0);
-}
-
-static void
-ConfigJoystick(SDL_Joystick * joystick, int fd)
-{
- int i, t;
- unsigned long keybit[NBITS(KEY_MAX)] = { 0 };
- unsigned long absbit[NBITS(ABS_MAX)] = { 0 };
- unsigned long relbit[NBITS(REL_MAX)] = { 0 };
-
- /* See if this device uses the new unified event API */
- if ((ioctl(fd, EVIOCGBIT(EV_KEY, sizeof(keybit)), keybit) >= 0) &&
- (ioctl(fd, EVIOCGBIT(EV_ABS, sizeof(absbit)), absbit) >= 0) &&
- (ioctl(fd, EVIOCGBIT(EV_REL, sizeof(relbit)), relbit) >= 0)) {
-
- /* Get the number of buttons, axes, and other thingamajigs */
- for (i = BTN_JOYSTICK; i < KEY_MAX; ++i) {
- if (test_bit(i, keybit)) {
-#ifdef DEBUG_INPUT_EVENTS
- printf("Joystick has button: 0x%x\n", i);
-#endif
- joystick->hwdata->key_map[i - BTN_MISC] = joystick->nbuttons;
- ++joystick->nbuttons;
- }
- }
- for (i = BTN_MISC; i < BTN_JOYSTICK; ++i) {
- if (test_bit(i, keybit)) {
-#ifdef DEBUG_INPUT_EVENTS
- printf("Joystick has button: 0x%x\n", i);
-#endif
- joystick->hwdata->key_map[i - BTN_MISC] = joystick->nbuttons;
- ++joystick->nbuttons;
- }
- }
- for (i = 0; i < ABS_MAX; ++i) {
- /* Skip hats */
- if (i == ABS_HAT0X) {
- i = ABS_HAT3Y;
- continue;
- }
- if (test_bit(i, absbit)) {
- struct input_absinfo absinfo;
-
- if (ioctl(fd, EVIOCGABS(i), &absinfo) < 0) {
- continue;
- }
-#ifdef DEBUG_INPUT_EVENTS
- printf("Joystick has absolute axis: 0x%.2x\n", i);
- printf("Values = { %d, %d, %d, %d, %d }\n",
- absinfo.value, absinfo.minimum, absinfo.maximum,
- absinfo.fuzz, absinfo.flat);
-#endif /* DEBUG_INPUT_EVENTS */
- joystick->hwdata->abs_map[i] = joystick->naxes;
- if (absinfo.minimum == absinfo.maximum) {
- joystick->hwdata->abs_correct[i].used = 0;
- } else {
- joystick->hwdata->abs_correct[i].used = 1;
- joystick->hwdata->abs_correct[i].coef[0] =
- (absinfo.maximum + absinfo.minimum) - 2 * absinfo.flat;
- joystick->hwdata->abs_correct[i].coef[1] =
- (absinfo.maximum + absinfo.minimum) + 2 * absinfo.flat;
- t = ((absinfo.maximum - absinfo.minimum) - 4 * absinfo.flat);
- if (t != 0) {
- joystick->hwdata->abs_correct[i].coef[2] =
- (1 << 28) / t;
- } else {
- joystick->hwdata->abs_correct[i].coef[2] = 0;
- }
- }
- ++joystick->naxes;
- }
- }
- for (i = ABS_HAT0X; i <= ABS_HAT3Y; i += 2) {
- if (test_bit(i, absbit) || test_bit(i + 1, absbit)) {
- struct input_absinfo absinfo;
-
- if (ioctl(fd, EVIOCGABS(i), &absinfo) < 0) {
- continue;
- }
-#ifdef DEBUG_INPUT_EVENTS
- printf("Joystick has hat %d\n", (i - ABS_HAT0X) / 2);
- printf("Values = { %d, %d, %d, %d, %d }\n",
- absinfo.value, absinfo.minimum, absinfo.maximum,
- absinfo.fuzz, absinfo.flat);
-#endif /* DEBUG_INPUT_EVENTS */
- ++joystick->nhats;
- }
- }
- if (test_bit(REL_X, relbit) || test_bit(REL_Y, relbit)) {
- ++joystick->nballs;
- }
-
- /* Allocate data to keep track of these thingamajigs */
- if (joystick->nhats > 0) {
- if (allocate_hatdata(joystick) < 0) {
- joystick->nhats = 0;
- }
- }
- if (joystick->nballs > 0) {
- if (allocate_balldata(joystick) < 0) {
- joystick->nballs = 0;
- }
- }
- }
-}
-
-
-/* Function to open a joystick for use.
- The joystick to open is specified by the device index.
- This should fill the nbuttons and naxes fields of the joystick structure.
- It returns 0, or -1 if there is an error.
- */
-int
-SDL_SYS_JoystickOpen(SDL_Joystick * joystick, int device_index)
-{
- SDL_joylist_item *item = JoystickByDevIndex(device_index);
- char *fname = NULL;
- int fd = -1;
-
- if (item == NULL) {
- return SDL_SetError("No such device");
- }
-
- fname = item->path;
- fd = open(fname, O_RDONLY, 0);
- if (fd < 0) {
- return SDL_SetError("Unable to open %s", fname);
- }
-
- joystick->instance_id = item->device_instance;
- joystick->hwdata = (struct joystick_hwdata *)
- SDL_malloc(sizeof(*joystick->hwdata));
- if (joystick->hwdata == NULL) {
- close(fd);
- return SDL_OutOfMemory();
- }
- SDL_memset(joystick->hwdata, 0, sizeof(*joystick->hwdata));
- joystick->hwdata->item = item;
- joystick->hwdata->guid = item->guid;
- joystick->hwdata->fd = fd;
- joystick->hwdata->fname = SDL_strdup(item->path);
- if (joystick->hwdata->fname == NULL) {
- SDL_free(joystick->hwdata);
- joystick->hwdata = NULL;
- close(fd);
- return SDL_OutOfMemory();
- }
-
- SDL_assert(item->hwdata == NULL);
- item->hwdata = joystick->hwdata;
-
- /* Set the joystick to non-blocking read mode */
- fcntl(fd, F_SETFL, O_NONBLOCK);
-
- /* Get the number of buttons and axes on the joystick */
- ConfigJoystick(joystick, fd);
-
- /* mark joystick as fresh and ready */
- joystick->hwdata->fresh = 1;
-
- return (0);
-}
-
-/* Function to determine if this joystick is attached to the system right now */
-SDL_bool SDL_SYS_JoystickAttached(SDL_Joystick *joystick)
-{
- return joystick->hwdata->item != NULL;
-}
-
-static SDL_INLINE void
-HandleHat(SDL_Joystick * stick, Uint8 hat, int axis, int value)
-{
- struct hwdata_hat *the_hat;
- const Uint8 position_map[3][3] = {
- {SDL_HAT_LEFTUP, SDL_HAT_UP, SDL_HAT_RIGHTUP},
- {SDL_HAT_LEFT, SDL_HAT_CENTERED, SDL_HAT_RIGHT},
- {SDL_HAT_LEFTDOWN, SDL_HAT_DOWN, SDL_HAT_RIGHTDOWN}
- };
-
- the_hat = &stick->hwdata->hats[hat];
- if (value < 0) {
- value = 0;
- } else if (value == 0) {
- value = 1;
- } else if (value > 0) {
- value = 2;
- }
- if (value != the_hat->axis[axis]) {
- the_hat->axis[axis] = value;
- SDL_PrivateJoystickHat(stick, hat,
- position_map[the_hat->
- axis[1]][the_hat->axis[0]]);
- }
-}
-
-static SDL_INLINE void
-HandleBall(SDL_Joystick * stick, Uint8 ball, int axis, int value)
-{
- stick->hwdata->balls[ball].axis[axis] += value;
-}
-
-
-static SDL_INLINE int
-AxisCorrect(SDL_Joystick * joystick, int which, int value)
-{
- struct axis_correct *correct;
-
- correct = &joystick->hwdata->abs_correct[which];
- if (correct->used) {
- value *= 2;
- if (value > correct->coef[0]) {
- if (value < correct->coef[1]) {
- return 0;
- }
- value -= correct->coef[1];
- } else {
- value -= correct->coef[0];
- }
- value *= correct->coef[2];
- value >>= 13;
- }
-
- /* Clamp and return */
- if (value < -32768)
- return -32768;
- if (value > 32767)
- return 32767;
-
- return value;
-}
-
-static SDL_INLINE void
-PollAllValues(SDL_Joystick * joystick)
-{
- struct input_absinfo absinfo;
- int a, b = 0;
-
- /* Poll all axis */
- for (a = ABS_X; b < ABS_MAX; a++) {
- switch (a) {
- case ABS_HAT0X:
- case ABS_HAT0Y:
- case ABS_HAT1X:
- case ABS_HAT1Y:
- case ABS_HAT2X:
- case ABS_HAT2Y:
- case ABS_HAT3X:
- case ABS_HAT3Y:
- /* ingore hats */
- break;
- default:
- if (joystick->hwdata->abs_correct[b].used) {
- if (ioctl(joystick->hwdata->fd, EVIOCGABS(a), &absinfo) >= 0) {
- absinfo.value = AxisCorrect(joystick, b, absinfo.value);
-
-#ifdef DEBUG_INPUT_EVENTS
- printf("Joystick : Re-read Axis %d (%d) val= %d\n",
- joystick->hwdata->abs_map[b], a, absinfo.value);
-#endif
- SDL_PrivateJoystickAxis(joystick,
- joystick->hwdata->abs_map[b],
- absinfo.value);
- }
- }
- b++;
- }
- }
-}
-
-static SDL_INLINE void
-HandleInputEvents(SDL_Joystick * joystick)
-{
- struct input_event events[32];
- int i, len;
- int code;
-
- if (joystick->hwdata->fresh) {
- PollAllValues(joystick);
- joystick->hwdata->fresh = 0;
- }
-
- while ((len = read(joystick->hwdata->fd, events, (sizeof events))) > 0) {
- len /= sizeof(events[0]);
- for (i = 0; i < len; ++i) {
- code = events[i].code;
- switch (events[i].type) {
- case EV_KEY:
- if (code >= BTN_MISC) {
- code -= BTN_MISC;
- SDL_PrivateJoystickButton(joystick,
- joystick->hwdata->key_map[code],
- events[i].value);
- }
- break;
- case EV_ABS:
- switch (code) {
- case ABS_HAT0X:
- case ABS_HAT0Y:
- case ABS_HAT1X:
- case ABS_HAT1Y:
- case ABS_HAT2X:
- case ABS_HAT2Y:
- case ABS_HAT3X:
- case ABS_HAT3Y:
- code -= ABS_HAT0X;
- HandleHat(joystick, code / 2, code % 2, events[i].value);
- break;
- default:
- events[i].value =
- AxisCorrect(joystick, code, events[i].value);
- SDL_PrivateJoystickAxis(joystick,
- joystick->hwdata->abs_map[code],
- events[i].value);
- break;
- }
- break;
- case EV_REL:
- switch (code) {
- case REL_X:
- case REL_Y:
- code -= REL_X;
- HandleBall(joystick, code / 2, code % 2, events[i].value);
- break;
- default:
- break;
- }
- break;
- case EV_SYN:
- switch (code) {
- case SYN_DROPPED :
-#ifdef DEBUG_INPUT_EVENTS
- printf("Event SYN_DROPPED detected\n");
-#endif
- PollAllValues(joystick);
- break;
- default:
- break;
- }
- default:
- break;
- }
- }
- }
-}
-
-void
-SDL_SYS_JoystickUpdate(SDL_Joystick * joystick)
-{
- int i;
-
- HandleInputEvents(joystick);
-
- /* Deliver ball motion updates */
- for (i = 0; i < joystick->nballs; ++i) {
- int xrel, yrel;
-
- xrel = joystick->hwdata->balls[i].axis[0];
- yrel = joystick->hwdata->balls[i].axis[1];
- if (xrel || yrel) {
- joystick->hwdata->balls[i].axis[0] = 0;
- joystick->hwdata->balls[i].axis[1] = 0;
- SDL_PrivateJoystickBall(joystick, (Uint8) i, xrel, yrel);
- }
- }
-}
-
-/* Function to close a joystick after use */
-void
-SDL_SYS_JoystickClose(SDL_Joystick * joystick)
-{
- if (joystick->hwdata) {
- close(joystick->hwdata->fd);
- if (joystick->hwdata->item) {
- joystick->hwdata->item->hwdata = NULL;
- }
- SDL_free(joystick->hwdata->hats);
- SDL_free(joystick->hwdata->balls);
- SDL_free(joystick->hwdata->fname);
- SDL_free(joystick->hwdata);
- }
-}
-
-/* Function to perform any system-specific joystick related cleanup */
-void
-SDL_SYS_JoystickQuit(void)
-{
- SDL_joylist_item *item = NULL;
- SDL_joylist_item *next = NULL;
-
- for (item = SDL_joylist; item; item = next) {
- next = item->next;
- SDL_free(item->path);
- SDL_free(item->name);
- SDL_free(item);
- }
-
- SDL_joylist = SDL_joylist_tail = NULL;
-
- numjoysticks = 0;
- instance_counter = 0;
-
-#if SDL_USE_LIBUDEV
- SDL_UDEV_DelCallback(joystick_udev_callback);
- SDL_UDEV_Quit();
-#endif
-}
-
-SDL_JoystickGUID SDL_SYS_JoystickGetDeviceGUID( int device_index )
-{
- return JoystickByDevIndex(device_index)->guid;
-}
-
-SDL_JoystickGUID SDL_SYS_JoystickGetGUID(SDL_Joystick * joystick)
-{
- return joystick->hwdata->guid;
-}
-
-#endif /* SDL_JOYSTICK_LINUX */
-
-/* vi: set ts=4 sw=4 expandtab: */
diff --git a/3rdparty/SDL2/src/joystick/linux/SDL_sysjoystick_c.h b/3rdparty/SDL2/src/joystick/linux/SDL_sysjoystick_c.h
deleted file mode 100644
index ee771783993..00000000000
--- a/3rdparty/SDL2/src/joystick/linux/SDL_sysjoystick_c.h
+++ /dev/null
@@ -1,57 +0,0 @@
-/*
- Simple DirectMedia Layer
- Copyright (C) 1997-2016 Sam Lantinga <slouken@libsdl.org>
-
- This software is provided 'as-is', without any express or implied
- warranty. In no event will the authors be held liable for any damages
- arising from the use of this software.
-
- Permission is granted to anyone to use this software for any purpose,
- including commercial applications, and to alter it and redistribute it
- freely, subject to the following restrictions:
-
- 1. The origin of this software must not be misrepresented; you must not
- claim that you wrote the original software. If you use this software
- in a product, an acknowledgment in the product documentation would be
- appreciated but is not required.
- 2. Altered source versions must be plainly marked as such, and must not be
- misrepresented as being the original software.
- 3. This notice may not be removed or altered from any source distribution.
-*/
-
-#include <linux/input.h>
-
-struct SDL_joylist_item;
-
-/* The private structure used to keep track of a joystick */
-struct joystick_hwdata
-{
- int fd;
- struct SDL_joylist_item *item;
- SDL_JoystickGUID guid;
- char *fname; /* Used in haptic subsystem */
-
- /* The current Linux joystick driver maps hats to two axes */
- struct hwdata_hat
- {
- int axis[2];
- } *hats;
- /* The current Linux joystick driver maps balls to two axes */
- struct hwdata_ball
- {
- int axis[2];
- } *balls;
-
- /* Support for the Linux 2.4 unified input interface */
- Uint8 key_map[KEY_MAX - BTN_MISC];
- Uint8 abs_map[ABS_MAX];
- struct axis_correct
- {
- int used;
- int coef[3];
- } abs_correct[ABS_MAX];
-
- int fresh;
-};
-
-/* vi: set ts=4 sw=4 expandtab: */
diff --git a/3rdparty/SDL2/src/joystick/psp/SDL_sysjoystick.c b/3rdparty/SDL2/src/joystick/psp/SDL_sysjoystick.c
deleted file mode 100644
index 352960edfaa..00000000000
--- a/3rdparty/SDL2/src/joystick/psp/SDL_sysjoystick.c
+++ /dev/null
@@ -1,270 +0,0 @@
-/*
- Simple DirectMedia Layer
- Copyright (C) 1997-2016 Sam Lantinga <slouken@libsdl.org>
-
- This software is provided 'as-is', without any express or implied
- warranty. In no event will the authors be held liable for any damages
- arising from the use of this software.
-
- Permission is granted to anyone to use this software for any purpose,
- including commercial applications, and to alter it and redistribute it
- freely, subject to the following restrictions:
-
- 1. The origin of this software must not be misrepresented; you must not
- claim that you wrote the original software. If you use this software
- in a product, an acknowledgment in the product documentation would be
- appreciated but is not required.
- 2. Altered source versions must be plainly marked as such, and must not be
- misrepresented as being the original software.
- 3. This notice may not be removed or altered from any source distribution.
-*/
-#include "../../SDL_internal.h"
-
-#if SDL_JOYSTICK_PSP
-
-/* This is the PSP implementation of the SDL joystick API */
-#include <pspctrl.h>
-#include <pspkernel.h>
-
-#include <stdio.h> /* For the definition of NULL */
-#include <stdlib.h>
-
-#include "../SDL_sysjoystick.h"
-#include "../SDL_joystick_c.h"
-
-#include "SDL_events.h"
-#include "SDL_error.h"
-#include "SDL_mutex.h"
-#include "SDL_timer.h"
-#include "../../thread/SDL_systhread.h"
-
-/* Current pad state */
-static SceCtrlData pad = { .Lx = 0, .Ly = 0, .Buttons = 0 };
-static SDL_sem *pad_sem = NULL;
-static SDL_Thread *thread = NULL;
-static int running = 0;
-static const enum PspCtrlButtons button_map[] = {
- PSP_CTRL_TRIANGLE, PSP_CTRL_CIRCLE, PSP_CTRL_CROSS, PSP_CTRL_SQUARE,
- PSP_CTRL_LTRIGGER, PSP_CTRL_RTRIGGER,
- PSP_CTRL_DOWN, PSP_CTRL_LEFT, PSP_CTRL_UP, PSP_CTRL_RIGHT,
- PSP_CTRL_SELECT, PSP_CTRL_START, PSP_CTRL_HOME, PSP_CTRL_HOLD };
-static int analog_map[256]; /* Map analog inputs to -32768 -> 32767 */
-
-typedef struct
-{
- int x;
- int y;
-} point;
-
-/* 4 points define the bezier-curve. */
-static point a = { 0, 0 };
-static point b = { 50, 0 };
-static point c = { 78, 32767 };
-static point d = { 128, 32767 };
-
-/* simple linear interpolation between two points */
-static SDL_INLINE void lerp (point *dest, point *a, point *b, float t)
-{
- dest->x = a->x + (b->x - a->x)*t;
- dest->y = a->y + (b->y - a->y)*t;
-}
-
-/* evaluate a point on a bezier-curve. t goes from 0 to 1.0 */
-static int calc_bezier_y(float t)
-{
- point ab, bc, cd, abbc, bccd, dest;
- lerp (&ab, &a, &b, t); /* point between a and b */
- lerp (&bc, &b, &c, t); /* point between b and c */
- lerp (&cd, &c, &d, t); /* point between c and d */
- lerp (&abbc, &ab, &bc, t); /* point between ab and bc */
- lerp (&bccd, &bc, &cd, t); /* point between bc and cd */
- lerp (&dest, &abbc, &bccd, t); /* point on the bezier-curve */
- return dest.y;
-}
-
-/*
- * Collect pad data about once per frame
- */
-int JoystickUpdate(void *data)
-{
- while (running) {
- SDL_SemWait(pad_sem);
- sceCtrlPeekBufferPositive(&pad, 1);
- SDL_SemPost(pad_sem);
- /* Delay 1/60th of a second */
- sceKernelDelayThread(1000000 / 60);
- }
- return 0;
-}
-
-
-
-/* Function to scan the system for joysticks.
- * Joystick 0 should be the system default joystick.
- * It should return number of joysticks, or -1 on an unrecoverable fatal error.
- */
-int SDL_SYS_JoystickInit(void)
-{
- int i;
-
- /* Setup input */
- sceCtrlSetSamplingCycle(0);
- sceCtrlSetSamplingMode(PSP_CTRL_MODE_ANALOG);
-
- /* Start thread to read data */
- if((pad_sem = SDL_CreateSemaphore(1)) == NULL) {
- return SDL_SetError("Can't create input semaphore");
- }
- running = 1;
- if((thread = SDL_CreateThreadInternal(JoystickUpdate, "JoystickThread", 4096, NULL)) == NULL) {
- return SDL_SetError("Can't create input thread");
- }
-
- /* Create an accurate map from analog inputs (0 to 255)
- to SDL joystick positions (-32768 to 32767) */
- for (i = 0; i < 128; i++)
- {
- float t = (float)i/127.0f;
- analog_map[i+128] = calc_bezier_y(t);
- analog_map[127-i] = -1 * analog_map[i+128];
- }
-
- return 1;
-}
-
-int SDL_SYS_NumJoysticks()
-{
- return 1;
-}
-
-void SDL_SYS_JoystickDetect()
-{
-}
-
-/* Function to get the device-dependent name of a joystick */
-const char * SDL_SYS_JoystickNameForDeviceIndex(int device_index)
-{
- return "PSP builtin joypad";
-}
-
-/* Function to perform the mapping from device index to the instance id for this index */
-SDL_JoystickID SDL_SYS_GetInstanceIdOfDeviceIndex(int device_index)
-{
- return device_index;
-}
-
-/* Function to get the device-dependent name of a joystick */
-const char *SDL_SYS_JoystickName(int index)
-{
- if (index == 0)
- return "PSP controller";
-
- SDL_SetError("No joystick available with that index");
- return(NULL);
-}
-
-/* Function to open a joystick for use.
- The joystick to open is specified by the device index.
- This should fill the nbuttons and naxes fields of the joystick structure.
- It returns 0, or -1 if there is an error.
- */
-int SDL_SYS_JoystickOpen(SDL_Joystick *joystick, int device_index)
-{
- joystick->nbuttons = 14;
- joystick->naxes = 2;
- joystick->nhats = 0;
-
- return 0;
-}
-
-/* Function to determine if this joystick is attached to the system right now */
-SDL_bool SDL_SYS_JoystickAttached(SDL_Joystick *joystick)
-{
- return SDL_TRUE;
-}
-
-/* Function to update the state of a joystick - called as a device poll.
- * This function shouldn't update the joystick structure directly,
- * but instead should call SDL_PrivateJoystick*() to deliver events
- * and update joystick device state.
- */
-void SDL_SYS_JoystickUpdate(SDL_Joystick *joystick)
-{
- int i;
- enum PspCtrlButtons buttons;
- enum PspCtrlButtons changed;
- unsigned char x, y;
- static enum PspCtrlButtons old_buttons = 0;
- static unsigned char old_x = 0, old_y = 0;
-
- SDL_SemWait(pad_sem);
- buttons = pad.Buttons;
- x = pad.Lx;
- y = pad.Ly;
- SDL_SemPost(pad_sem);
-
- /* Axes */
- if(old_x != x) {
- SDL_PrivateJoystickAxis(joystick, 0, analog_map[x]);
- old_x = x;
- }
- if(old_y != y) {
- SDL_PrivateJoystickAxis(joystick, 1, analog_map[y]);
- old_y = y;
- }
-
- /* Buttons */
- changed = old_buttons ^ buttons;
- old_buttons = buttons;
- if(changed) {
- for(i=0; i<sizeof(button_map)/sizeof(button_map[0]); i++) {
- if(changed & button_map[i]) {
- SDL_PrivateJoystickButton(
- joystick, i,
- (buttons & button_map[i]) ?
- SDL_PRESSED : SDL_RELEASED);
- }
- }
- }
-
- sceKernelDelayThread(0);
-}
-
-/* Function to close a joystick after use */
-void SDL_SYS_JoystickClose(SDL_Joystick *joystick)
-{
-}
-
-/* Function to perform any system-specific joystick related cleanup */
-void SDL_SYS_JoystickQuit(void)
-{
- /* Cleanup Threads and Semaphore. */
- running = 0;
- SDL_WaitThread(thread, NULL);
- SDL_DestroySemaphore(pad_sem);
-}
-
-SDL_JoystickGUID SDL_SYS_JoystickGetDeviceGUID( int device_index )
-{
- SDL_JoystickGUID guid;
- /* the GUID is just the first 16 chars of the name for now */
- const char *name = SDL_SYS_JoystickNameForDeviceIndex( device_index );
- SDL_zero( guid );
- SDL_memcpy( &guid, name, SDL_min( sizeof(guid), SDL_strlen( name ) ) );
- return guid;
-}
-
-SDL_JoystickGUID SDL_SYS_JoystickGetGUID(SDL_Joystick * joystick)
-{
- SDL_JoystickGUID guid;
- /* the GUID is just the first 16 chars of the name for now */
- const char *name = joystick->name;
- SDL_zero( guid );
- SDL_memcpy( &guid, name, SDL_min( sizeof(guid), SDL_strlen( name ) ) );
- return guid;
-}
-
-#endif /* SDL_JOYSTICK_PSP */
-
-/* vim: ts=4 sw=4
- */
diff --git a/3rdparty/SDL2/src/joystick/sort_controllers.py b/3rdparty/SDL2/src/joystick/sort_controllers.py
deleted file mode 100644
index af95d651340..00000000000
--- a/3rdparty/SDL2/src/joystick/sort_controllers.py
+++ /dev/null
@@ -1,65 +0,0 @@
-#!/usr/bin/env python
-#
-# Script to sort the game controller database entries in SDL_gamecontroller.c
-
-import re
-
-
-filename = "SDL_gamecontrollerdb.h"
-input = open(filename)
-output = open(filename + ".new", "w")
-parsing_controllers = False
-controllers = []
-controller_guids = {}
-split_pattern = re.compile(r'([^"]*")([^,]*,)([^,]*,)([^"]*)(".*)')
-
-def save_controller(line):
- global controllers
- match = split_pattern.match(line)
- entry = [ match.group(1), match.group(2), match.group(3) ]
- bindings = sorted(match.group(4).split(","))
- if (bindings[0] == ""):
- bindings.pop(0)
- entry.extend(",".join(bindings) + ",")
- entry.append(match.group(5))
- controllers.append(entry)
-
-def write_controllers():
- global controllers
- global controller_guids
- for entry in sorted(controllers, key=lambda entry: entry[2]):
- line = "".join(entry) + "\n"
- if not line.endswith(",\n") and not line.endswith("*/\n"):
- print("Warning: '%s' is missing a comma at the end of the line" % (line))
- if (entry[1] in controller_guids):
- print("Warning: entry '%s' is duplicate of entry '%s'" % (entry[2], controller_guids[entry[1]][2]))
- controller_guids[entry[1]] = entry
-
- output.write(line)
- controllers = []
- controller_guids = {}
-
-for line in input:
- if (parsing_controllers):
- if (line.startswith("{")):
- output.write(line)
- elif (line.startswith(" NULL")):
- parsing_controllers = False
- write_controllers()
- output.write(line)
- elif (line.startswith("#if")):
- print("Parsing " + line.strip())
- output.write(line)
- elif (line.startswith("#endif")):
- write_controllers()
- output.write(line)
- else:
- save_controller(line)
- else:
- if (line.startswith("static const char *s_ControllerMappings")):
- parsing_controllers = True
-
- output.write(line)
-
-output.close()
-print("Finished writing %s.new" % filename)
diff --git a/3rdparty/SDL2/src/joystick/windows/SDL_dinputjoystick.c b/3rdparty/SDL2/src/joystick/windows/SDL_dinputjoystick.c
deleted file mode 100644
index 7166075b153..00000000000
--- a/3rdparty/SDL2/src/joystick/windows/SDL_dinputjoystick.c
+++ /dev/null
@@ -1,918 +0,0 @@
-/*
- Simple DirectMedia Layer
- Copyright (C) 1997-2016 Sam Lantinga <slouken@libsdl.org>
-
- This software is provided 'as-is', without any express or implied
- warranty. In no event will the authors be held liable for any damages
- arising from the use of this software.
-
- Permission is granted to anyone to use this software for any purpose,
- including commercial applications, and to alter it and redistribute it
- freely, subject to the following restrictions:
-
- 1. The origin of this software must not be misrepresented; you must not
- claim that you wrote the original software. If you use this software
- in a product, an acknowledgment in the product documentation would be
- appreciated but is not required.
- 2. Altered source versions must be plainly marked as such, and must not be
- misrepresented as being the original software.
- 3. This notice may not be removed or altered from any source distribution.
-*/
-#include "../../SDL_internal.h"
-
-#include "../SDL_sysjoystick.h"
-
-#if SDL_JOYSTICK_DINPUT
-
-#include "SDL_windowsjoystick_c.h"
-#include "SDL_dinputjoystick_c.h"
-#include "SDL_xinputjoystick_c.h"
-
-#ifndef DIDFT_OPTIONAL
-#define DIDFT_OPTIONAL 0x80000000
-#endif
-
-#define INPUT_QSIZE 32 /* Buffer up to 32 input messages */
-#define AXIS_MIN -32768 /* minimum value for axis coordinate */
-#define AXIS_MAX 32767 /* maximum value for axis coordinate */
-#define JOY_AXIS_THRESHOLD (((AXIS_MAX)-(AXIS_MIN))/100) /* 1% motion */
-
-/* external variables referenced. */
-extern HWND SDL_HelperWindow;
-
-/* local variables */
-static SDL_bool coinitialized = SDL_FALSE;
-static LPDIRECTINPUT8 dinput = NULL;
-static PRAWINPUTDEVICELIST SDL_RawDevList = NULL;
-static UINT SDL_RawDevListCount = 0;
-
-/* Taken from Wine - Thanks! */
-static DIOBJECTDATAFORMAT dfDIJoystick2[] = {
- { &GUID_XAxis, DIJOFS_X, DIDFT_OPTIONAL | DIDFT_AXIS | DIDFT_ANYINSTANCE, 0 },
- { &GUID_YAxis, DIJOFS_Y, DIDFT_OPTIONAL | DIDFT_AXIS | DIDFT_ANYINSTANCE, 0 },
- { &GUID_ZAxis, DIJOFS_Z, DIDFT_OPTIONAL | DIDFT_AXIS | DIDFT_ANYINSTANCE, 0 },
- { &GUID_RxAxis, DIJOFS_RX, DIDFT_OPTIONAL | DIDFT_AXIS | DIDFT_ANYINSTANCE, 0 },
- { &GUID_RyAxis, DIJOFS_RY, DIDFT_OPTIONAL | DIDFT_AXIS | DIDFT_ANYINSTANCE, 0 },
- { &GUID_RzAxis, DIJOFS_RZ, DIDFT_OPTIONAL | DIDFT_AXIS | DIDFT_ANYINSTANCE, 0 },
- { &GUID_Slider, DIJOFS_SLIDER(0), DIDFT_OPTIONAL | DIDFT_AXIS | DIDFT_ANYINSTANCE, 0 },
- { &GUID_Slider, DIJOFS_SLIDER(1), DIDFT_OPTIONAL | DIDFT_AXIS | DIDFT_ANYINSTANCE, 0 },
- { &GUID_POV, DIJOFS_POV(0), DIDFT_OPTIONAL | DIDFT_POV | DIDFT_ANYINSTANCE, 0 },
- { &GUID_POV, DIJOFS_POV(1), DIDFT_OPTIONAL | DIDFT_POV | DIDFT_ANYINSTANCE, 0 },
- { &GUID_POV, DIJOFS_POV(2), DIDFT_OPTIONAL | DIDFT_POV | DIDFT_ANYINSTANCE, 0 },
- { &GUID_POV, DIJOFS_POV(3), DIDFT_OPTIONAL | DIDFT_POV | DIDFT_ANYINSTANCE, 0 },
- { NULL, DIJOFS_BUTTON(0), DIDFT_OPTIONAL | DIDFT_BUTTON | DIDFT_ANYINSTANCE, 0 },
- { NULL, DIJOFS_BUTTON(1), DIDFT_OPTIONAL | DIDFT_BUTTON | DIDFT_ANYINSTANCE, 0 },
- { NULL, DIJOFS_BUTTON(2), DIDFT_OPTIONAL | DIDFT_BUTTON | DIDFT_ANYINSTANCE, 0 },
- { NULL, DIJOFS_BUTTON(3), DIDFT_OPTIONAL | DIDFT_BUTTON | DIDFT_ANYINSTANCE, 0 },
- { NULL, DIJOFS_BUTTON(4), DIDFT_OPTIONAL | DIDFT_BUTTON | DIDFT_ANYINSTANCE, 0 },
- { NULL, DIJOFS_BUTTON(5), DIDFT_OPTIONAL | DIDFT_BUTTON | DIDFT_ANYINSTANCE, 0 },
- { NULL, DIJOFS_BUTTON(6), DIDFT_OPTIONAL | DIDFT_BUTTON | DIDFT_ANYINSTANCE, 0 },
- { NULL, DIJOFS_BUTTON(7), DIDFT_OPTIONAL | DIDFT_BUTTON | DIDFT_ANYINSTANCE, 0 },
- { NULL, DIJOFS_BUTTON(8), DIDFT_OPTIONAL | DIDFT_BUTTON | DIDFT_ANYINSTANCE, 0 },
- { NULL, DIJOFS_BUTTON(9), DIDFT_OPTIONAL | DIDFT_BUTTON | DIDFT_ANYINSTANCE, 0 },
- { NULL, DIJOFS_BUTTON(10), DIDFT_OPTIONAL | DIDFT_BUTTON | DIDFT_ANYINSTANCE, 0 },
- { NULL, DIJOFS_BUTTON(11), DIDFT_OPTIONAL | DIDFT_BUTTON | DIDFT_ANYINSTANCE, 0 },
- { NULL, DIJOFS_BUTTON(12), DIDFT_OPTIONAL | DIDFT_BUTTON | DIDFT_ANYINSTANCE, 0 },
- { NULL, DIJOFS_BUTTON(13), DIDFT_OPTIONAL | DIDFT_BUTTON | DIDFT_ANYINSTANCE, 0 },
- { NULL, DIJOFS_BUTTON(14), DIDFT_OPTIONAL | DIDFT_BUTTON | DIDFT_ANYINSTANCE, 0 },
- { NULL, DIJOFS_BUTTON(15), DIDFT_OPTIONAL | DIDFT_BUTTON | DIDFT_ANYINSTANCE, 0 },
- { NULL, DIJOFS_BUTTON(16), DIDFT_OPTIONAL | DIDFT_BUTTON | DIDFT_ANYINSTANCE, 0 },
- { NULL, DIJOFS_BUTTON(17), DIDFT_OPTIONAL | DIDFT_BUTTON | DIDFT_ANYINSTANCE, 0 },
- { NULL, DIJOFS_BUTTON(18), DIDFT_OPTIONAL | DIDFT_BUTTON | DIDFT_ANYINSTANCE, 0 },
- { NULL, DIJOFS_BUTTON(19), DIDFT_OPTIONAL | DIDFT_BUTTON | DIDFT_ANYINSTANCE, 0 },
- { NULL, DIJOFS_BUTTON(20), DIDFT_OPTIONAL | DIDFT_BUTTON | DIDFT_ANYINSTANCE, 0 },
- { NULL, DIJOFS_BUTTON(21), DIDFT_OPTIONAL | DIDFT_BUTTON | DIDFT_ANYINSTANCE, 0 },
- { NULL, DIJOFS_BUTTON(22), DIDFT_OPTIONAL | DIDFT_BUTTON | DIDFT_ANYINSTANCE, 0 },
- { NULL, DIJOFS_BUTTON(23), DIDFT_OPTIONAL | DIDFT_BUTTON | DIDFT_ANYINSTANCE, 0 },
- { NULL, DIJOFS_BUTTON(24), DIDFT_OPTIONAL | DIDFT_BUTTON | DIDFT_ANYINSTANCE, 0 },
- { NULL, DIJOFS_BUTTON(25), DIDFT_OPTIONAL | DIDFT_BUTTON | DIDFT_ANYINSTANCE, 0 },
- { NULL, DIJOFS_BUTTON(26), DIDFT_OPTIONAL | DIDFT_BUTTON | DIDFT_ANYINSTANCE, 0 },
- { NULL, DIJOFS_BUTTON(27), DIDFT_OPTIONAL | DIDFT_BUTTON | DIDFT_ANYINSTANCE, 0 },
- { NULL, DIJOFS_BUTTON(28), DIDFT_OPTIONAL | DIDFT_BUTTON | DIDFT_ANYINSTANCE, 0 },
- { NULL, DIJOFS_BUTTON(29), DIDFT_OPTIONAL | DIDFT_BUTTON | DIDFT_ANYINSTANCE, 0 },
- { NULL, DIJOFS_BUTTON(30), DIDFT_OPTIONAL | DIDFT_BUTTON | DIDFT_ANYINSTANCE, 0 },
- { NULL, DIJOFS_BUTTON(31), DIDFT_OPTIONAL | DIDFT_BUTTON | DIDFT_ANYINSTANCE, 0 },
- { NULL, DIJOFS_BUTTON(32), DIDFT_OPTIONAL | DIDFT_BUTTON | DIDFT_ANYINSTANCE, 0 },
- { NULL, DIJOFS_BUTTON(33), DIDFT_OPTIONAL | DIDFT_BUTTON | DIDFT_ANYINSTANCE, 0 },
- { NULL, DIJOFS_BUTTON(34), DIDFT_OPTIONAL | DIDFT_BUTTON | DIDFT_ANYINSTANCE, 0 },
- { NULL, DIJOFS_BUTTON(35), DIDFT_OPTIONAL | DIDFT_BUTTON | DIDFT_ANYINSTANCE, 0 },
- { NULL, DIJOFS_BUTTON(36), DIDFT_OPTIONAL | DIDFT_BUTTON | DIDFT_ANYINSTANCE, 0 },
- { NULL, DIJOFS_BUTTON(37), DIDFT_OPTIONAL | DIDFT_BUTTON | DIDFT_ANYINSTANCE, 0 },
- { NULL, DIJOFS_BUTTON(38), DIDFT_OPTIONAL | DIDFT_BUTTON | DIDFT_ANYINSTANCE, 0 },
- { NULL, DIJOFS_BUTTON(39), DIDFT_OPTIONAL | DIDFT_BUTTON | DIDFT_ANYINSTANCE, 0 },
- { NULL, DIJOFS_BUTTON(40), DIDFT_OPTIONAL | DIDFT_BUTTON | DIDFT_ANYINSTANCE, 0 },
- { NULL, DIJOFS_BUTTON(41), DIDFT_OPTIONAL | DIDFT_BUTTON | DIDFT_ANYINSTANCE, 0 },
- { NULL, DIJOFS_BUTTON(42), DIDFT_OPTIONAL | DIDFT_BUTTON | DIDFT_ANYINSTANCE, 0 },
- { NULL, DIJOFS_BUTTON(43), DIDFT_OPTIONAL | DIDFT_BUTTON | DIDFT_ANYINSTANCE, 0 },
- { NULL, DIJOFS_BUTTON(44), DIDFT_OPTIONAL | DIDFT_BUTTON | DIDFT_ANYINSTANCE, 0 },
- { NULL, DIJOFS_BUTTON(45), DIDFT_OPTIONAL | DIDFT_BUTTON | DIDFT_ANYINSTANCE, 0 },
- { NULL, DIJOFS_BUTTON(46), DIDFT_OPTIONAL | DIDFT_BUTTON | DIDFT_ANYINSTANCE, 0 },
- { NULL, DIJOFS_BUTTON(47), DIDFT_OPTIONAL | DIDFT_BUTTON | DIDFT_ANYINSTANCE, 0 },
- { NULL, DIJOFS_BUTTON(48), DIDFT_OPTIONAL | DIDFT_BUTTON | DIDFT_ANYINSTANCE, 0 },
- { NULL, DIJOFS_BUTTON(49), DIDFT_OPTIONAL | DIDFT_BUTTON | DIDFT_ANYINSTANCE, 0 },
- { NULL, DIJOFS_BUTTON(50), DIDFT_OPTIONAL | DIDFT_BUTTON | DIDFT_ANYINSTANCE, 0 },
- { NULL, DIJOFS_BUTTON(51), DIDFT_OPTIONAL | DIDFT_BUTTON | DIDFT_ANYINSTANCE, 0 },
- { NULL, DIJOFS_BUTTON(52), DIDFT_OPTIONAL | DIDFT_BUTTON | DIDFT_ANYINSTANCE, 0 },
- { NULL, DIJOFS_BUTTON(53), DIDFT_OPTIONAL | DIDFT_BUTTON | DIDFT_ANYINSTANCE, 0 },
- { NULL, DIJOFS_BUTTON(54), DIDFT_OPTIONAL | DIDFT_BUTTON | DIDFT_ANYINSTANCE, 0 },
- { NULL, DIJOFS_BUTTON(55), DIDFT_OPTIONAL | DIDFT_BUTTON | DIDFT_ANYINSTANCE, 0 },
- { NULL, DIJOFS_BUTTON(56), DIDFT_OPTIONAL | DIDFT_BUTTON | DIDFT_ANYINSTANCE, 0 },
- { NULL, DIJOFS_BUTTON(57), DIDFT_OPTIONAL | DIDFT_BUTTON | DIDFT_ANYINSTANCE, 0 },
- { NULL, DIJOFS_BUTTON(58), DIDFT_OPTIONAL | DIDFT_BUTTON | DIDFT_ANYINSTANCE, 0 },
- { NULL, DIJOFS_BUTTON(59), DIDFT_OPTIONAL | DIDFT_BUTTON | DIDFT_ANYINSTANCE, 0 },
- { NULL, DIJOFS_BUTTON(60), DIDFT_OPTIONAL | DIDFT_BUTTON | DIDFT_ANYINSTANCE, 0 },
- { NULL, DIJOFS_BUTTON(61), DIDFT_OPTIONAL | DIDFT_BUTTON | DIDFT_ANYINSTANCE, 0 },
- { NULL, DIJOFS_BUTTON(62), DIDFT_OPTIONAL | DIDFT_BUTTON | DIDFT_ANYINSTANCE, 0 },
- { NULL, DIJOFS_BUTTON(63), DIDFT_OPTIONAL | DIDFT_BUTTON | DIDFT_ANYINSTANCE, 0 },
- { NULL, DIJOFS_BUTTON(64), DIDFT_OPTIONAL | DIDFT_BUTTON | DIDFT_ANYINSTANCE, 0 },
- { NULL, DIJOFS_BUTTON(65), DIDFT_OPTIONAL | DIDFT_BUTTON | DIDFT_ANYINSTANCE, 0 },
- { NULL, DIJOFS_BUTTON(66), DIDFT_OPTIONAL | DIDFT_BUTTON | DIDFT_ANYINSTANCE, 0 },
- { NULL, DIJOFS_BUTTON(67), DIDFT_OPTIONAL | DIDFT_BUTTON | DIDFT_ANYINSTANCE, 0 },
- { NULL, DIJOFS_BUTTON(68), DIDFT_OPTIONAL | DIDFT_BUTTON | DIDFT_ANYINSTANCE, 0 },
- { NULL, DIJOFS_BUTTON(69), DIDFT_OPTIONAL | DIDFT_BUTTON | DIDFT_ANYINSTANCE, 0 },
- { NULL, DIJOFS_BUTTON(70), DIDFT_OPTIONAL | DIDFT_BUTTON | DIDFT_ANYINSTANCE, 0 },
- { NULL, DIJOFS_BUTTON(71), DIDFT_OPTIONAL | DIDFT_BUTTON | DIDFT_ANYINSTANCE, 0 },
- { NULL, DIJOFS_BUTTON(72), DIDFT_OPTIONAL | DIDFT_BUTTON | DIDFT_ANYINSTANCE, 0 },
- { NULL, DIJOFS_BUTTON(73), DIDFT_OPTIONAL | DIDFT_BUTTON | DIDFT_ANYINSTANCE, 0 },
- { NULL, DIJOFS_BUTTON(74), DIDFT_OPTIONAL | DIDFT_BUTTON | DIDFT_ANYINSTANCE, 0 },
- { NULL, DIJOFS_BUTTON(75), DIDFT_OPTIONAL | DIDFT_BUTTON | DIDFT_ANYINSTANCE, 0 },
- { NULL, DIJOFS_BUTTON(76), DIDFT_OPTIONAL | DIDFT_BUTTON | DIDFT_ANYINSTANCE, 0 },
- { NULL, DIJOFS_BUTTON(77), DIDFT_OPTIONAL | DIDFT_BUTTON | DIDFT_ANYINSTANCE, 0 },
- { NULL, DIJOFS_BUTTON(78), DIDFT_OPTIONAL | DIDFT_BUTTON | DIDFT_ANYINSTANCE, 0 },
- { NULL, DIJOFS_BUTTON(79), DIDFT_OPTIONAL | DIDFT_BUTTON | DIDFT_ANYINSTANCE, 0 },
- { NULL, DIJOFS_BUTTON(80), DIDFT_OPTIONAL | DIDFT_BUTTON | DIDFT_ANYINSTANCE, 0 },
- { NULL, DIJOFS_BUTTON(81), DIDFT_OPTIONAL | DIDFT_BUTTON | DIDFT_ANYINSTANCE, 0 },
- { NULL, DIJOFS_BUTTON(82), DIDFT_OPTIONAL | DIDFT_BUTTON | DIDFT_ANYINSTANCE, 0 },
- { NULL, DIJOFS_BUTTON(83), DIDFT_OPTIONAL | DIDFT_BUTTON | DIDFT_ANYINSTANCE, 0 },
- { NULL, DIJOFS_BUTTON(84), DIDFT_OPTIONAL | DIDFT_BUTTON | DIDFT_ANYINSTANCE, 0 },
- { NULL, DIJOFS_BUTTON(85), DIDFT_OPTIONAL | DIDFT_BUTTON | DIDFT_ANYINSTANCE, 0 },
- { NULL, DIJOFS_BUTTON(86), DIDFT_OPTIONAL | DIDFT_BUTTON | DIDFT_ANYINSTANCE, 0 },
- { NULL, DIJOFS_BUTTON(87), DIDFT_OPTIONAL | DIDFT_BUTTON | DIDFT_ANYINSTANCE, 0 },
- { NULL, DIJOFS_BUTTON(88), DIDFT_OPTIONAL | DIDFT_BUTTON | DIDFT_ANYINSTANCE, 0 },
- { NULL, DIJOFS_BUTTON(89), DIDFT_OPTIONAL | DIDFT_BUTTON | DIDFT_ANYINSTANCE, 0 },
- { NULL, DIJOFS_BUTTON(90), DIDFT_OPTIONAL | DIDFT_BUTTON | DIDFT_ANYINSTANCE, 0 },
- { NULL, DIJOFS_BUTTON(91), DIDFT_OPTIONAL | DIDFT_BUTTON | DIDFT_ANYINSTANCE, 0 },
- { NULL, DIJOFS_BUTTON(92), DIDFT_OPTIONAL | DIDFT_BUTTON | DIDFT_ANYINSTANCE, 0 },
- { NULL, DIJOFS_BUTTON(93), DIDFT_OPTIONAL | DIDFT_BUTTON | DIDFT_ANYINSTANCE, 0 },
- { NULL, DIJOFS_BUTTON(94), DIDFT_OPTIONAL | DIDFT_BUTTON | DIDFT_ANYINSTANCE, 0 },
- { NULL, DIJOFS_BUTTON(95), DIDFT_OPTIONAL | DIDFT_BUTTON | DIDFT_ANYINSTANCE, 0 },
- { NULL, DIJOFS_BUTTON(96), DIDFT_OPTIONAL | DIDFT_BUTTON | DIDFT_ANYINSTANCE, 0 },
- { NULL, DIJOFS_BUTTON(97), DIDFT_OPTIONAL | DIDFT_BUTTON | DIDFT_ANYINSTANCE, 0 },
- { NULL, DIJOFS_BUTTON(98), DIDFT_OPTIONAL | DIDFT_BUTTON | DIDFT_ANYINSTANCE, 0 },
- { NULL, DIJOFS_BUTTON(99), DIDFT_OPTIONAL | DIDFT_BUTTON | DIDFT_ANYINSTANCE, 0 },
- { NULL, DIJOFS_BUTTON(100), DIDFT_OPTIONAL | DIDFT_BUTTON | DIDFT_ANYINSTANCE, 0 },
- { NULL, DIJOFS_BUTTON(101), DIDFT_OPTIONAL | DIDFT_BUTTON | DIDFT_ANYINSTANCE, 0 },
- { NULL, DIJOFS_BUTTON(102), DIDFT_OPTIONAL | DIDFT_BUTTON | DIDFT_ANYINSTANCE, 0 },
- { NULL, DIJOFS_BUTTON(103), DIDFT_OPTIONAL | DIDFT_BUTTON | DIDFT_ANYINSTANCE, 0 },
- { NULL, DIJOFS_BUTTON(104), DIDFT_OPTIONAL | DIDFT_BUTTON | DIDFT_ANYINSTANCE, 0 },
- { NULL, DIJOFS_BUTTON(105), DIDFT_OPTIONAL | DIDFT_BUTTON | DIDFT_ANYINSTANCE, 0 },
- { NULL, DIJOFS_BUTTON(106), DIDFT_OPTIONAL | DIDFT_BUTTON | DIDFT_ANYINSTANCE, 0 },
- { NULL, DIJOFS_BUTTON(107), DIDFT_OPTIONAL | DIDFT_BUTTON | DIDFT_ANYINSTANCE, 0 },
- { NULL, DIJOFS_BUTTON(108), DIDFT_OPTIONAL | DIDFT_BUTTON | DIDFT_ANYINSTANCE, 0 },
- { NULL, DIJOFS_BUTTON(109), DIDFT_OPTIONAL | DIDFT_BUTTON | DIDFT_ANYINSTANCE, 0 },
- { NULL, DIJOFS_BUTTON(110), DIDFT_OPTIONAL | DIDFT_BUTTON | DIDFT_ANYINSTANCE, 0 },
- { NULL, DIJOFS_BUTTON(111), DIDFT_OPTIONAL | DIDFT_BUTTON | DIDFT_ANYINSTANCE, 0 },
- { NULL, DIJOFS_BUTTON(112), DIDFT_OPTIONAL | DIDFT_BUTTON | DIDFT_ANYINSTANCE, 0 },
- { NULL, DIJOFS_BUTTON(113), DIDFT_OPTIONAL | DIDFT_BUTTON | DIDFT_ANYINSTANCE, 0 },
- { NULL, DIJOFS_BUTTON(114), DIDFT_OPTIONAL | DIDFT_BUTTON | DIDFT_ANYINSTANCE, 0 },
- { NULL, DIJOFS_BUTTON(115), DIDFT_OPTIONAL | DIDFT_BUTTON | DIDFT_ANYINSTANCE, 0 },
- { NULL, DIJOFS_BUTTON(116), DIDFT_OPTIONAL | DIDFT_BUTTON | DIDFT_ANYINSTANCE, 0 },
- { NULL, DIJOFS_BUTTON(117), DIDFT_OPTIONAL | DIDFT_BUTTON | DIDFT_ANYINSTANCE, 0 },
- { NULL, DIJOFS_BUTTON(118), DIDFT_OPTIONAL | DIDFT_BUTTON | DIDFT_ANYINSTANCE, 0 },
- { NULL, DIJOFS_BUTTON(119), DIDFT_OPTIONAL | DIDFT_BUTTON | DIDFT_ANYINSTANCE, 0 },
- { NULL, DIJOFS_BUTTON(120), DIDFT_OPTIONAL | DIDFT_BUTTON | DIDFT_ANYINSTANCE, 0 },
- { NULL, DIJOFS_BUTTON(121), DIDFT_OPTIONAL | DIDFT_BUTTON | DIDFT_ANYINSTANCE, 0 },
- { NULL, DIJOFS_BUTTON(122), DIDFT_OPTIONAL | DIDFT_BUTTON | DIDFT_ANYINSTANCE, 0 },
- { NULL, DIJOFS_BUTTON(123), DIDFT_OPTIONAL | DIDFT_BUTTON | DIDFT_ANYINSTANCE, 0 },
- { NULL, DIJOFS_BUTTON(124), DIDFT_OPTIONAL | DIDFT_BUTTON | DIDFT_ANYINSTANCE, 0 },
- { NULL, DIJOFS_BUTTON(125), DIDFT_OPTIONAL | DIDFT_BUTTON | DIDFT_ANYINSTANCE, 0 },
- { NULL, DIJOFS_BUTTON(126), DIDFT_OPTIONAL | DIDFT_BUTTON | DIDFT_ANYINSTANCE, 0 },
- { NULL, DIJOFS_BUTTON(127), DIDFT_OPTIONAL | DIDFT_BUTTON | DIDFT_ANYINSTANCE, 0 },
- { &GUID_XAxis, FIELD_OFFSET(DIJOYSTATE2, lVX), DIDFT_OPTIONAL | DIDFT_AXIS | DIDFT_ANYINSTANCE, 0 },
- { &GUID_YAxis, FIELD_OFFSET(DIJOYSTATE2, lVY), DIDFT_OPTIONAL | DIDFT_AXIS | DIDFT_ANYINSTANCE, 0 },
- { &GUID_ZAxis, FIELD_OFFSET(DIJOYSTATE2, lVZ), DIDFT_OPTIONAL | DIDFT_AXIS | DIDFT_ANYINSTANCE, 0 },
- { &GUID_RxAxis, FIELD_OFFSET(DIJOYSTATE2, lVRx), DIDFT_OPTIONAL | DIDFT_AXIS | DIDFT_ANYINSTANCE, 0 },
- { &GUID_RyAxis, FIELD_OFFSET(DIJOYSTATE2, lVRy), DIDFT_OPTIONAL | DIDFT_AXIS | DIDFT_ANYINSTANCE, 0 },
- { &GUID_RzAxis, FIELD_OFFSET(DIJOYSTATE2, lVRz), DIDFT_OPTIONAL | DIDFT_AXIS | DIDFT_ANYINSTANCE, 0 },
- { &GUID_Slider, FIELD_OFFSET(DIJOYSTATE2, rglVSlider[0]), DIDFT_OPTIONAL | DIDFT_AXIS | DIDFT_ANYINSTANCE, 0 },
- { &GUID_Slider, FIELD_OFFSET(DIJOYSTATE2, rglVSlider[1]), DIDFT_OPTIONAL | DIDFT_AXIS | DIDFT_ANYINSTANCE, 0 },
- { &GUID_XAxis, FIELD_OFFSET(DIJOYSTATE2, lAX), DIDFT_OPTIONAL | DIDFT_AXIS | DIDFT_ANYINSTANCE, 0 },
- { &GUID_YAxis, FIELD_OFFSET(DIJOYSTATE2, lAY), DIDFT_OPTIONAL | DIDFT_AXIS | DIDFT_ANYINSTANCE, 0 },
- { &GUID_ZAxis, FIELD_OFFSET(DIJOYSTATE2, lAZ), DIDFT_OPTIONAL | DIDFT_AXIS | DIDFT_ANYINSTANCE, 0 },
- { &GUID_RxAxis, FIELD_OFFSET(DIJOYSTATE2, lARx), DIDFT_OPTIONAL | DIDFT_AXIS | DIDFT_ANYINSTANCE, 0 },
- { &GUID_RyAxis, FIELD_OFFSET(DIJOYSTATE2, lARy), DIDFT_OPTIONAL | DIDFT_AXIS | DIDFT_ANYINSTANCE, 0 },
- { &GUID_RzAxis, FIELD_OFFSET(DIJOYSTATE2, lARz), DIDFT_OPTIONAL | DIDFT_AXIS | DIDFT_ANYINSTANCE, 0 },
- { &GUID_Slider, FIELD_OFFSET(DIJOYSTATE2, rglASlider[0]), DIDFT_OPTIONAL | DIDFT_AXIS | DIDFT_ANYINSTANCE, 0 },
- { &GUID_Slider, FIELD_OFFSET(DIJOYSTATE2, rglASlider[1]), DIDFT_OPTIONAL | DIDFT_AXIS | DIDFT_ANYINSTANCE, 0 },
- { &GUID_XAxis, FIELD_OFFSET(DIJOYSTATE2, lFX), DIDFT_OPTIONAL | DIDFT_AXIS | DIDFT_ANYINSTANCE, 0 },
- { &GUID_YAxis, FIELD_OFFSET(DIJOYSTATE2, lFY), DIDFT_OPTIONAL | DIDFT_AXIS | DIDFT_ANYINSTANCE, 0 },
- { &GUID_ZAxis, FIELD_OFFSET(DIJOYSTATE2, lFZ), DIDFT_OPTIONAL | DIDFT_AXIS | DIDFT_ANYINSTANCE, 0 },
- { &GUID_RxAxis, FIELD_OFFSET(DIJOYSTATE2, lFRx), DIDFT_OPTIONAL | DIDFT_AXIS | DIDFT_ANYINSTANCE, 0 },
- { &GUID_RyAxis, FIELD_OFFSET(DIJOYSTATE2, lFRy), DIDFT_OPTIONAL | DIDFT_AXIS | DIDFT_ANYINSTANCE, 0 },
- { &GUID_RzAxis, FIELD_OFFSET(DIJOYSTATE2, lFRz), DIDFT_OPTIONAL | DIDFT_AXIS | DIDFT_ANYINSTANCE, 0 },
- { &GUID_Slider, FIELD_OFFSET(DIJOYSTATE2, rglFSlider[0]), DIDFT_OPTIONAL | DIDFT_AXIS | DIDFT_ANYINSTANCE, 0 },
- { &GUID_Slider, FIELD_OFFSET(DIJOYSTATE2, rglFSlider[1]), DIDFT_OPTIONAL | DIDFT_AXIS | DIDFT_ANYINSTANCE, 0 },
-};
-
-const DIDATAFORMAT SDL_c_dfDIJoystick2 = {
- sizeof(DIDATAFORMAT),
- sizeof(DIOBJECTDATAFORMAT),
- DIDF_ABSAXIS,
- sizeof(DIJOYSTATE2),
- SDL_arraysize(dfDIJoystick2),
- dfDIJoystick2
-};
-
-/* Convert a DirectInput return code to a text message */
-static int
-SetDIerror(const char *function, HRESULT code)
-{
- /*
- return SDL_SetError("%s() [%s]: %s", function,
- DXGetErrorString9A(code), DXGetErrorDescription9A(code));
- */
- return SDL_SetError("%s() DirectX error 0x%8.8lx", function, code);
-}
-
-static SDL_bool
-SDL_IsXInputDevice(const GUID* pGuidProductFromDirectInput)
-{
- static GUID IID_ValveStreamingGamepad = { MAKELONG(0x28DE, 0x11FF), 0x0000, 0x0000, { 0x00, 0x00, 0x50, 0x49, 0x44, 0x56, 0x49, 0x44 } };
- static GUID IID_X360WiredGamepad = { MAKELONG(0x045E, 0x02A1), 0x0000, 0x0000, { 0x00, 0x00, 0x50, 0x49, 0x44, 0x56, 0x49, 0x44 } };
- static GUID IID_X360WirelessGamepad = { MAKELONG(0x045E, 0x028E), 0x0000, 0x0000, { 0x00, 0x00, 0x50, 0x49, 0x44, 0x56, 0x49, 0x44 } };
- static GUID IID_XOneWiredGamepad = { MAKELONG(0x045E, 0x02FF), 0x0000, 0x0000, { 0x00, 0x00, 0x50, 0x49, 0x44, 0x56, 0x49, 0x44 } };
- static GUID IID_XOneWirelessGamepad = { MAKELONG(0x045E, 0x02DD), 0x0000, 0x0000, { 0x00, 0x00, 0x50, 0x49, 0x44, 0x56, 0x49, 0x44 } };
- static GUID IID_XOneNewWirelessGamepad = { MAKELONG(0x045E, 0x02D1), 0x0000, 0x0000, { 0x00, 0x00, 0x50, 0x49, 0x44, 0x56, 0x49, 0x44 } };
- static GUID IID_XOneSWirelessGamepad = { MAKELONG(0x045E, 0x02EA), 0x0000, 0x0000, { 0x00, 0x00, 0x50, 0x49, 0x44, 0x56, 0x49, 0x44 } };
- static GUID IID_XOneSBluetoothGamepad = { MAKELONG(0x045E, 0x02E0), 0x0000, 0x0000, { 0x00, 0x00, 0x50, 0x49, 0x44, 0x56, 0x49, 0x44 } };
- static GUID IID_XOneEliteWirelessGamepad = { MAKELONG(0x045E, 0x02E3), 0x0000, 0x0000, { 0x00, 0x00, 0x50, 0x49, 0x44, 0x56, 0x49, 0x44 } };
-
- static const GUID *s_XInputProductGUID[] = {
- &IID_ValveStreamingGamepad,
- &IID_X360WiredGamepad, /* Microsoft's wired X360 controller for Windows. */
- &IID_X360WirelessGamepad, /* Microsoft's wireless X360 controller for Windows. */
- &IID_XOneWiredGamepad, /* Microsoft's wired Xbox One controller for Windows. */
- &IID_XOneWirelessGamepad, /* Microsoft's wireless Xbox One controller for Windows. */
- &IID_XOneNewWirelessGamepad, /* Microsoft's updated wireless Xbox One controller (w/ 3.5 mm jack) for Windows. */
- &IID_XOneSWirelessGamepad, /* Microsoft's wireless Xbox One S controller for Windows. */
- &IID_XOneSBluetoothGamepad, /* Microsoft's Bluetooth Xbox One S controller for Windows. */
- &IID_XOneEliteWirelessGamepad /* Microsoft's wireless Xbox One Elite controller for Windows. */
- };
-
- size_t iDevice;
- UINT i;
-
- if (!SDL_XINPUT_Enabled()) {
- return SDL_FALSE;
- }
-
- /* Check for well known XInput device GUIDs */
- /* This lets us skip RAWINPUT for popular devices. Also, we need to do this for the Valve Streaming Gamepad because it's virtualized and doesn't show up in the device list. */
- for (iDevice = 0; iDevice < SDL_arraysize(s_XInputProductGUID); ++iDevice) {
- if (SDL_memcmp(pGuidProductFromDirectInput, s_XInputProductGUID[iDevice], sizeof(GUID)) == 0) {
- return SDL_TRUE;
- }
- }
-
- /* Go through RAWINPUT (WinXP and later) to find HID devices. */
- /* Cache this if we end up using it. */
- if (SDL_RawDevList == NULL) {
- if ((GetRawInputDeviceList(NULL, &SDL_RawDevListCount, sizeof(RAWINPUTDEVICELIST)) == -1) || (!SDL_RawDevListCount)) {
- return SDL_FALSE; /* oh well. */
- }
-
- SDL_RawDevList = (PRAWINPUTDEVICELIST)SDL_malloc(sizeof(RAWINPUTDEVICELIST) * SDL_RawDevListCount);
- if (SDL_RawDevList == NULL) {
- SDL_OutOfMemory();
- return SDL_FALSE;
- }
-
- if (GetRawInputDeviceList(SDL_RawDevList, &SDL_RawDevListCount, sizeof(RAWINPUTDEVICELIST)) == -1) {
- SDL_free(SDL_RawDevList);
- SDL_RawDevList = NULL;
- return SDL_FALSE; /* oh well. */
- }
- }
-
- for (i = 0; i < SDL_RawDevListCount; i++) {
- RID_DEVICE_INFO rdi;
- char devName[128];
- UINT rdiSize = sizeof(rdi);
- UINT nameSize = SDL_arraysize(devName);
-
- rdi.cbSize = sizeof(rdi);
- if ((SDL_RawDevList[i].dwType == RIM_TYPEHID) &&
- (GetRawInputDeviceInfoA(SDL_RawDevList[i].hDevice, RIDI_DEVICEINFO, &rdi, &rdiSize) != ((UINT)-1)) &&
- (MAKELONG(rdi.hid.dwVendorId, rdi.hid.dwProductId) == ((LONG)pGuidProductFromDirectInput->Data1)) &&
- (GetRawInputDeviceInfoA(SDL_RawDevList[i].hDevice, RIDI_DEVICENAME, devName, &nameSize) != ((UINT)-1)) &&
- (SDL_strstr(devName, "IG_") != NULL)) {
- return SDL_TRUE;
- }
- }
-
- return SDL_FALSE;
-}
-
-int
-SDL_DINPUT_JoystickInit(void)
-{
- HRESULT result;
- HINSTANCE instance;
-
- result = WIN_CoInitialize();
- if (FAILED(result)) {
- return SetDIerror("CoInitialize", result);
- }
-
- coinitialized = SDL_TRUE;
-
- result = CoCreateInstance(&CLSID_DirectInput8, NULL, CLSCTX_INPROC_SERVER,
- &IID_IDirectInput8, (LPVOID)&dinput);
-
- if (FAILED(result)) {
- return SetDIerror("CoCreateInstance", result);
- }
-
- /* Because we used CoCreateInstance, we need to Initialize it, first. */
- instance = GetModuleHandle(NULL);
- if (instance == NULL) {
- return SDL_SetError("GetModuleHandle() failed with error code %lu.", GetLastError());
- }
- result = IDirectInput8_Initialize(dinput, instance, DIRECTINPUT_VERSION);
-
- if (FAILED(result)) {
- return SetDIerror("IDirectInput::Initialize", result);
- }
- return 0;
-}
-
-/* helper function for direct input, gets called for each connected joystick */
-static BOOL CALLBACK
-EnumJoysticksCallback(const DIDEVICEINSTANCE * pdidInstance, VOID * pContext)
-{
- JoyStick_DeviceData *pNewJoystick;
- JoyStick_DeviceData *pPrevJoystick = NULL;
- const DWORD devtype = (pdidInstance->dwDevType & 0xFF);
-
- if (devtype == DI8DEVTYPE_SUPPLEMENTAL) {
- return DIENUM_CONTINUE; /* Ignore touchpads, etc. */
- }
-
- if (SDL_IsXInputDevice(&pdidInstance->guidProduct)) {
- return DIENUM_CONTINUE; /* ignore XInput devices here, keep going. */
- }
-
- pNewJoystick = *(JoyStick_DeviceData **)pContext;
- while (pNewJoystick) {
- if (!SDL_memcmp(&pNewJoystick->dxdevice.guidInstance, &pdidInstance->guidInstance, sizeof(pNewJoystick->dxdevice.guidInstance))) {
- /* if we are replacing the front of the list then update it */
- if (pNewJoystick == *(JoyStick_DeviceData **)pContext) {
- *(JoyStick_DeviceData **)pContext = pNewJoystick->pNext;
- } else if (pPrevJoystick) {
- pPrevJoystick->pNext = pNewJoystick->pNext;
- }
-
- pNewJoystick->pNext = SYS_Joystick;
- SYS_Joystick = pNewJoystick;
-
- return DIENUM_CONTINUE; /* already have this joystick loaded, just keep going */
- }
-
- pPrevJoystick = pNewJoystick;
- pNewJoystick = pNewJoystick->pNext;
- }
-
- pNewJoystick = (JoyStick_DeviceData *)SDL_malloc(sizeof(JoyStick_DeviceData));
- if (!pNewJoystick) {
- return DIENUM_CONTINUE; /* better luck next time? */
- }
-
- SDL_zerop(pNewJoystick);
- pNewJoystick->joystickname = WIN_StringToUTF8(pdidInstance->tszProductName);
- if (!pNewJoystick->joystickname) {
- SDL_free(pNewJoystick);
- return DIENUM_CONTINUE; /* better luck next time? */
- }
-
- SDL_memcpy(&(pNewJoystick->dxdevice), pdidInstance,
- sizeof(DIDEVICEINSTANCE));
-
- SDL_memcpy(&pNewJoystick->guid, &pdidInstance->guidProduct, sizeof(pNewJoystick->guid));
- SDL_SYS_AddJoystickDevice(pNewJoystick);
-
- return DIENUM_CONTINUE; /* get next device, please */
-}
-
-void
-SDL_DINPUT_JoystickDetect(JoyStick_DeviceData **pContext)
-{
- IDirectInput8_EnumDevices(dinput, DI8DEVCLASS_GAMECTRL, EnumJoysticksCallback, pContext, DIEDFL_ATTACHEDONLY);
-
- if (SDL_RawDevList) {
- SDL_free(SDL_RawDevList); /* in case we used this in DirectInput detection */
- SDL_RawDevList = NULL;
- }
- SDL_RawDevListCount = 0;
-}
-
-static BOOL CALLBACK
-EnumDevObjectsCallback(LPCDIDEVICEOBJECTINSTANCE dev, LPVOID pvRef)
-{
- SDL_Joystick *joystick = (SDL_Joystick *)pvRef;
- HRESULT result;
- input_t *in = &joystick->hwdata->Inputs[joystick->hwdata->NumInputs];
-
- if (dev->dwType & DIDFT_BUTTON) {
- in->type = BUTTON;
- in->num = joystick->nbuttons;
- in->ofs = DIJOFS_BUTTON(in->num);
- joystick->nbuttons++;
- } else if (dev->dwType & DIDFT_POV) {
- in->type = HAT;
- in->num = joystick->nhats;
- in->ofs = DIJOFS_POV(in->num);
- joystick->nhats++;
- } else if (dev->dwType & DIDFT_AXIS) {
- DIPROPRANGE diprg;
- DIPROPDWORD dilong;
-
- in->type = AXIS;
- in->num = joystick->naxes;
- if (!SDL_memcmp(&dev->guidType, &GUID_XAxis, sizeof(dev->guidType)))
- in->ofs = DIJOFS_X;
- else if (!SDL_memcmp(&dev->guidType, &GUID_YAxis, sizeof(dev->guidType)))
- in->ofs = DIJOFS_Y;
- else if (!SDL_memcmp(&dev->guidType, &GUID_ZAxis, sizeof(dev->guidType)))
- in->ofs = DIJOFS_Z;
- else if (!SDL_memcmp(&dev->guidType, &GUID_RxAxis, sizeof(dev->guidType)))
- in->ofs = DIJOFS_RX;
- else if (!SDL_memcmp(&dev->guidType, &GUID_RyAxis, sizeof(dev->guidType)))
- in->ofs = DIJOFS_RY;
- else if (!SDL_memcmp(&dev->guidType, &GUID_RzAxis, sizeof(dev->guidType)))
- in->ofs = DIJOFS_RZ;
- else if (!SDL_memcmp(&dev->guidType, &GUID_Slider, sizeof(dev->guidType))) {
- in->ofs = DIJOFS_SLIDER(joystick->hwdata->NumSliders);
- ++joystick->hwdata->NumSliders;
- } else {
- return DIENUM_CONTINUE; /* not an axis we can grok */
- }
-
- diprg.diph.dwSize = sizeof(diprg);
- diprg.diph.dwHeaderSize = sizeof(diprg.diph);
- diprg.diph.dwObj = dev->dwType;
- diprg.diph.dwHow = DIPH_BYID;
- diprg.lMin = AXIS_MIN;
- diprg.lMax = AXIS_MAX;
-
- result =
- IDirectInputDevice8_SetProperty(joystick->hwdata->InputDevice,
- DIPROP_RANGE, &diprg.diph);
- if (FAILED(result)) {
- return DIENUM_CONTINUE; /* don't use this axis */
- }
-
- /* Set dead zone to 0. */
- dilong.diph.dwSize = sizeof(dilong);
- dilong.diph.dwHeaderSize = sizeof(dilong.diph);
- dilong.diph.dwObj = dev->dwType;
- dilong.diph.dwHow = DIPH_BYID;
- dilong.dwData = 0;
- result =
- IDirectInputDevice8_SetProperty(joystick->hwdata->InputDevice,
- DIPROP_DEADZONE, &dilong.diph);
- if (FAILED(result)) {
- return DIENUM_CONTINUE; /* don't use this axis */
- }
-
- joystick->naxes++;
- } else {
- /* not supported at this time */
- return DIENUM_CONTINUE;
- }
-
- joystick->hwdata->NumInputs++;
-
- if (joystick->hwdata->NumInputs == MAX_INPUTS) {
- return DIENUM_STOP; /* too many */
- }
-
- return DIENUM_CONTINUE;
-}
-
-/* Sort using the data offset into the DInput struct.
- * This gives a reasonable ordering for the inputs.
- */
-static int
-SortDevFunc(const void *a, const void *b)
-{
- const input_t *inputA = (const input_t*)a;
- const input_t *inputB = (const input_t*)b;
-
- if (inputA->ofs < inputB->ofs)
- return -1;
- if (inputA->ofs > inputB->ofs)
- return 1;
- return 0;
-}
-
-/* Sort the input objects and recalculate the indices for each input. */
-static void
-SortDevObjects(SDL_Joystick *joystick)
-{
- input_t *inputs = joystick->hwdata->Inputs;
- int nButtons = 0;
- int nHats = 0;
- int nAxis = 0;
- int n;
-
- SDL_qsort(inputs, joystick->hwdata->NumInputs, sizeof(input_t), SortDevFunc);
-
- for (n = 0; n < joystick->hwdata->NumInputs; n++) {
- switch (inputs[n].type) {
- case BUTTON:
- inputs[n].num = nButtons;
- nButtons++;
- break;
-
- case HAT:
- inputs[n].num = nHats;
- nHats++;
- break;
-
- case AXIS:
- inputs[n].num = nAxis;
- nAxis++;
- break;
- }
- }
-}
-
-int
-SDL_DINPUT_JoystickOpen(SDL_Joystick * joystick, JoyStick_DeviceData *joystickdevice)
-{
- HRESULT result;
- LPDIRECTINPUTDEVICE8 device;
- DIPROPDWORD dipdw;
-
- joystick->hwdata->buffered = SDL_TRUE;
- joystick->hwdata->Capabilities.dwSize = sizeof(DIDEVCAPS);
-
- SDL_zero(dipdw);
- dipdw.diph.dwSize = sizeof(DIPROPDWORD);
- dipdw.diph.dwHeaderSize = sizeof(DIPROPHEADER);
-
- result =
- IDirectInput8_CreateDevice(dinput,
- &(joystickdevice->dxdevice.guidInstance), &device, NULL);
- if (FAILED(result)) {
- return SetDIerror("IDirectInput::CreateDevice", result);
- }
-
- /* Now get the IDirectInputDevice8 interface, instead. */
- result = IDirectInputDevice8_QueryInterface(device,
- &IID_IDirectInputDevice8,
- (LPVOID *)& joystick->
- hwdata->InputDevice);
- /* We are done with this object. Use the stored one from now on. */
- IDirectInputDevice8_Release(device);
-
- if (FAILED(result)) {
- return SetDIerror("IDirectInputDevice8::QueryInterface", result);
- }
-
- /* Acquire shared access. Exclusive access is required for forces,
- * though. */
- result =
- IDirectInputDevice8_SetCooperativeLevel(joystick->hwdata->
- InputDevice, SDL_HelperWindow,
- DISCL_EXCLUSIVE |
- DISCL_BACKGROUND);
- if (FAILED(result)) {
- return SetDIerror("IDirectInputDevice8::SetCooperativeLevel", result);
- }
-
- /* Use the extended data structure: DIJOYSTATE2. */
- result =
- IDirectInputDevice8_SetDataFormat(joystick->hwdata->InputDevice,
- &SDL_c_dfDIJoystick2);
- if (FAILED(result)) {
- return SetDIerror("IDirectInputDevice8::SetDataFormat", result);
- }
-
- /* Get device capabilities */
- result =
- IDirectInputDevice8_GetCapabilities(joystick->hwdata->InputDevice,
- &joystick->hwdata->Capabilities);
- if (FAILED(result)) {
- return SetDIerror("IDirectInputDevice8::GetCapabilities", result);
- }
-
- /* Force capable? */
- if (joystick->hwdata->Capabilities.dwFlags & DIDC_FORCEFEEDBACK) {
-
- result = IDirectInputDevice8_Acquire(joystick->hwdata->InputDevice);
- if (FAILED(result)) {
- return SetDIerror("IDirectInputDevice8::Acquire", result);
- }
-
- /* reset all actuators. */
- result =
- IDirectInputDevice8_SendForceFeedbackCommand(joystick->hwdata->
- InputDevice,
- DISFFC_RESET);
-
- /* Not necessarily supported, ignore if not supported.
- if (FAILED(result)) {
- return SetDIerror("IDirectInputDevice8::SendForceFeedbackCommand", result);
- }
- */
-
- result = IDirectInputDevice8_Unacquire(joystick->hwdata->InputDevice);
-
- if (FAILED(result)) {
- return SetDIerror("IDirectInputDevice8::Unacquire", result);
- }
-
- /* Turn on auto-centering for a ForceFeedback device (until told
- * otherwise). */
- dipdw.diph.dwObj = 0;
- dipdw.diph.dwHow = DIPH_DEVICE;
- dipdw.dwData = DIPROPAUTOCENTER_ON;
-
- result =
- IDirectInputDevice8_SetProperty(joystick->hwdata->InputDevice,
- DIPROP_AUTOCENTER, &dipdw.diph);
-
- /* Not necessarily supported, ignore if not supported.
- if (FAILED(result)) {
- return SetDIerror("IDirectInputDevice8::SetProperty", result);
- }
- */
- }
-
- /* What buttons and axes does it have? */
- IDirectInputDevice8_EnumObjects(joystick->hwdata->InputDevice,
- EnumDevObjectsCallback, joystick,
- DIDFT_BUTTON | DIDFT_AXIS | DIDFT_POV);
-
- /* Reorder the input objects. Some devices do not report the X axis as
- * the first axis, for example. */
- SortDevObjects(joystick);
-
- dipdw.diph.dwObj = 0;
- dipdw.diph.dwHow = DIPH_DEVICE;
- dipdw.dwData = INPUT_QSIZE;
-
- /* Set the buffer size */
- result =
- IDirectInputDevice8_SetProperty(joystick->hwdata->InputDevice,
- DIPROP_BUFFERSIZE, &dipdw.diph);
-
- if (result == DI_POLLEDDEVICE) {
- /* This device doesn't support buffering, so we're forced
- * to use less reliable polling. */
- joystick->hwdata->buffered = SDL_FALSE;
- } else if (FAILED(result)) {
- return SetDIerror("IDirectInputDevice8::SetProperty", result);
- }
- return 0;
-}
-
-static Uint8
-TranslatePOV(DWORD value)
-{
- const int HAT_VALS[] = {
- SDL_HAT_UP,
- SDL_HAT_UP | SDL_HAT_RIGHT,
- SDL_HAT_RIGHT,
- SDL_HAT_DOWN | SDL_HAT_RIGHT,
- SDL_HAT_DOWN,
- SDL_HAT_DOWN | SDL_HAT_LEFT,
- SDL_HAT_LEFT,
- SDL_HAT_UP | SDL_HAT_LEFT
- };
-
- if (LOWORD(value) == 0xFFFF)
- return SDL_HAT_CENTERED;
-
- /* Round the value up: */
- value += 4500 / 2;
- value %= 36000;
- value /= 4500;
-
- if (value >= 8)
- return SDL_HAT_CENTERED; /* shouldn't happen */
-
- return HAT_VALS[value];
-}
-
-static void
-UpdateDINPUTJoystickState_Buffered(SDL_Joystick * joystick)
-{
- int i;
- HRESULT result;
- DWORD numevents;
- DIDEVICEOBJECTDATA evtbuf[INPUT_QSIZE];
-
- numevents = INPUT_QSIZE;
- result =
- IDirectInputDevice8_GetDeviceData(joystick->hwdata->InputDevice,
- sizeof(DIDEVICEOBJECTDATA), evtbuf,
- &numevents, 0);
- if (result == DIERR_INPUTLOST || result == DIERR_NOTACQUIRED) {
- IDirectInputDevice8_Acquire(joystick->hwdata->InputDevice);
- result =
- IDirectInputDevice8_GetDeviceData(joystick->hwdata->InputDevice,
- sizeof(DIDEVICEOBJECTDATA),
- evtbuf, &numevents, 0);
- }
-
- /* Handle the events or punt */
- if (FAILED(result)) {
- joystick->hwdata->send_remove_event = SDL_TRUE;
- joystick->hwdata->removed = SDL_TRUE;
- return;
- }
-
- for (i = 0; i < (int)numevents; ++i) {
- int j;
-
- for (j = 0; j < joystick->hwdata->NumInputs; ++j) {
- const input_t *in = &joystick->hwdata->Inputs[j];
-
- if (evtbuf[i].dwOfs != in->ofs)
- continue;
-
- switch (in->type) {
- case AXIS:
- SDL_PrivateJoystickAxis(joystick, in->num, (Sint16)evtbuf[i].dwData);
- break;
- case BUTTON:
- SDL_PrivateJoystickButton(joystick, in->num,
- (Uint8)(evtbuf[i].dwData ? SDL_PRESSED : SDL_RELEASED));
- break;
- case HAT:
- {
- Uint8 pos = TranslatePOV(evtbuf[i].dwData);
- SDL_PrivateJoystickHat(joystick, in->num, pos);
- }
- break;
- }
- }
- }
-}
-
-/* Function to update the state of a joystick - called as a device poll.
- * This function shouldn't update the joystick structure directly,
- * but instead should call SDL_PrivateJoystick*() to deliver events
- * and update joystick device state.
- */
-static void
-UpdateDINPUTJoystickState_Polled(SDL_Joystick * joystick)
-{
- DIJOYSTATE2 state;
- HRESULT result;
- int i;
-
- result =
- IDirectInputDevice8_GetDeviceState(joystick->hwdata->InputDevice,
- sizeof(DIJOYSTATE2), &state);
- if (result == DIERR_INPUTLOST || result == DIERR_NOTACQUIRED) {
- IDirectInputDevice8_Acquire(joystick->hwdata->InputDevice);
- result =
- IDirectInputDevice8_GetDeviceState(joystick->hwdata->InputDevice,
- sizeof(DIJOYSTATE2), &state);
- }
-
- if (result != DI_OK) {
- joystick->hwdata->send_remove_event = SDL_TRUE;
- joystick->hwdata->removed = SDL_TRUE;
- return;
- }
-
- /* Set each known axis, button and POV. */
- for (i = 0; i < joystick->hwdata->NumInputs; ++i) {
- const input_t *in = &joystick->hwdata->Inputs[i];
-
- switch (in->type) {
- case AXIS:
- switch (in->ofs) {
- case DIJOFS_X:
- SDL_PrivateJoystickAxis(joystick, in->num, (Sint16)state.lX);
- break;
- case DIJOFS_Y:
- SDL_PrivateJoystickAxis(joystick, in->num, (Sint16)state.lY);
- break;
- case DIJOFS_Z:
- SDL_PrivateJoystickAxis(joystick, in->num, (Sint16)state.lZ);
- break;
- case DIJOFS_RX:
- SDL_PrivateJoystickAxis(joystick, in->num, (Sint16)state.lRx);
- break;
- case DIJOFS_RY:
- SDL_PrivateJoystickAxis(joystick, in->num, (Sint16)state.lRy);
- break;
- case DIJOFS_RZ:
- SDL_PrivateJoystickAxis(joystick, in->num, (Sint16)state.lRz);
- break;
- case DIJOFS_SLIDER(0):
- SDL_PrivateJoystickAxis(joystick, in->num, (Sint16)state.rglSlider[0]);
- break;
- case DIJOFS_SLIDER(1):
- SDL_PrivateJoystickAxis(joystick, in->num, (Sint16)state.rglSlider[1]);
- break;
- }
- break;
-
- case BUTTON:
- SDL_PrivateJoystickButton(joystick, in->num,
- (Uint8)(state.rgbButtons[in->ofs - DIJOFS_BUTTON0] ? SDL_PRESSED : SDL_RELEASED));
- break;
- case HAT:
- {
- Uint8 pos = TranslatePOV(state.rgdwPOV[in->ofs - DIJOFS_POV(0)]);
- SDL_PrivateJoystickHat(joystick, in->num, pos);
- break;
- }
- }
- }
-}
-
-void
-SDL_DINPUT_JoystickUpdate(SDL_Joystick * joystick)
-{
- HRESULT result;
-
- result = IDirectInputDevice8_Poll(joystick->hwdata->InputDevice);
- if (result == DIERR_INPUTLOST || result == DIERR_NOTACQUIRED) {
- IDirectInputDevice8_Acquire(joystick->hwdata->InputDevice);
- IDirectInputDevice8_Poll(joystick->hwdata->InputDevice);
- }
-
- if (joystick->hwdata->buffered) {
- UpdateDINPUTJoystickState_Buffered(joystick);
- } else {
- UpdateDINPUTJoystickState_Polled(joystick);
- }
-}
-
-void
-SDL_DINPUT_JoystickClose(SDL_Joystick * joystick)
-{
- IDirectInputDevice8_Unacquire(joystick->hwdata->InputDevice);
- IDirectInputDevice8_Release(joystick->hwdata->InputDevice);
-}
-
-void
-SDL_DINPUT_JoystickQuit(void)
-{
- if (dinput != NULL) {
- IDirectInput8_Release(dinput);
- dinput = NULL;
- }
-
- if (coinitialized) {
- WIN_CoUninitialize();
- coinitialized = SDL_FALSE;
- }
-}
-
-#else /* !SDL_JOYSTICK_DINPUT */
-
-typedef struct JoyStick_DeviceData JoyStick_DeviceData;
-
-int
-SDL_DINPUT_JoystickInit(void)
-{
- return 0;
-}
-
-void
-SDL_DINPUT_JoystickDetect(JoyStick_DeviceData **pContext)
-{
-}
-
-int
-SDL_DINPUT_JoystickOpen(SDL_Joystick * joystick, JoyStick_DeviceData *joystickdevice)
-{
- return SDL_Unsupported();
-}
-
-void
-SDL_DINPUT_JoystickUpdate(SDL_Joystick * joystick)
-{
-}
-
-void
-SDL_DINPUT_JoystickClose(SDL_Joystick * joystick)
-{
-}
-
-void
-SDL_DINPUT_JoystickQuit(void)
-{
-}
-
-#endif /* SDL_JOYSTICK_DINPUT */
-
-/* vi: set ts=4 sw=4 expandtab: */
diff --git a/3rdparty/SDL2/src/joystick/windows/SDL_dinputjoystick_c.h b/3rdparty/SDL2/src/joystick/windows/SDL_dinputjoystick_c.h
deleted file mode 100644
index 7e4ff3e1946..00000000000
--- a/3rdparty/SDL2/src/joystick/windows/SDL_dinputjoystick_c.h
+++ /dev/null
@@ -1,30 +0,0 @@
-/*
- Simple DirectMedia Layer
- Copyright (C) 1997-2016 Sam Lantinga <slouken@libsdl.org>
-
- This software is provided 'as-is', without any express or implied
- warranty. In no event will the authors be held liable for any damages
- arising from the use of this software.
-
- Permission is granted to anyone to use this software for any purpose,
- including commercial applications, and to alter it and redistribute it
- freely, subject to the following restrictions:
-
- 1. The origin of this software must not be misrepresented; you must not
- claim that you wrote the original software. If you use this software
- in a product, an acknowledgment in the product documentation would be
- appreciated but is not required.
- 2. Altered source versions must be plainly marked as such, and must not be
- misrepresented as being the original software.
- 3. This notice may not be removed or altered from any source distribution.
-*/
-#include "../../SDL_internal.h"
-
-extern int SDL_DINPUT_JoystickInit(void);
-extern void SDL_DINPUT_JoystickDetect(JoyStick_DeviceData **pContext);
-extern int SDL_DINPUT_JoystickOpen(SDL_Joystick * joystick, JoyStick_DeviceData *joystickdevice);
-extern void SDL_DINPUT_JoystickUpdate(SDL_Joystick * joystick);
-extern void SDL_DINPUT_JoystickClose(SDL_Joystick * joystick);
-extern void SDL_DINPUT_JoystickQuit(void);
-
-/* vi: set ts=4 sw=4 expandtab: */
diff --git a/3rdparty/SDL2/src/joystick/windows/SDL_mmjoystick.c b/3rdparty/SDL2/src/joystick/windows/SDL_mmjoystick.c
deleted file mode 100644
index 37461818112..00000000000
--- a/3rdparty/SDL2/src/joystick/windows/SDL_mmjoystick.c
+++ /dev/null
@@ -1,467 +0,0 @@
-/*
- Simple DirectMedia Layer
- Copyright (C) 1997-2016 Sam Lantinga <slouken@libsdl.org>
-
- This software is provided 'as-is', without any express or implied
- warranty. In no event will the authors be held liable for any damages
- arising from the use of this software.
-
- Permission is granted to anyone to use this software for any purpose,
- including commercial applications, and to alter it and redistribute it
- freely, subject to the following restrictions:
-
- 1. The origin of this software must not be misrepresented; you must not
- claim that you wrote the original software. If you use this software
- in a product, an acknowledgment in the product documentation would be
- appreciated but is not required.
- 2. Altered source versions must be plainly marked as such, and must not be
- misrepresented as being the original software.
- 3. This notice may not be removed or altered from any source distribution.
-*/
-#include "../../SDL_internal.h"
-
-#ifdef SDL_JOYSTICK_WINMM
-
-/* Win32 MultiMedia Joystick driver, contributed by Andrei de A. Formiga */
-
-#include "../../core/windows/SDL_windows.h"
-#include <mmsystem.h>
-#include <regstr.h>
-
-#include "SDL_events.h"
-#include "SDL_joystick.h"
-#include "../SDL_sysjoystick.h"
-#include "../SDL_joystick_c.h"
-
-#ifdef REGSTR_VAL_JOYOEMNAME
-#undef REGSTR_VAL_JOYOEMNAME
-#endif
-#define REGSTR_VAL_JOYOEMNAME "OEMName"
-
-#define MAX_JOYSTICKS 16
-#define MAX_AXES 6 /* each joystick can have up to 6 axes */
-#define MAX_BUTTONS 32 /* and 32 buttons */
-#define AXIS_MIN -32768 /* minimum value for axis coordinate */
-#define AXIS_MAX 32767 /* maximum value for axis coordinate */
-/* limit axis to 256 possible positions to filter out noise */
-#define JOY_AXIS_THRESHOLD (((AXIS_MAX)-(AXIS_MIN))/256)
-#define JOY_BUTTON_FLAG(n) (1<<n)
-
-
-/* array to hold joystick ID values */
-static UINT SYS_JoystickID[MAX_JOYSTICKS];
-static JOYCAPSA SYS_Joystick[MAX_JOYSTICKS];
-static char *SYS_JoystickName[MAX_JOYSTICKS];
-
-/* The private structure used to keep track of a joystick */
-struct joystick_hwdata
-{
- /* joystick ID */
- UINT id;
-
- /* values used to translate device-specific coordinates into
- SDL-standard ranges */
- struct _transaxis
- {
- int offset;
- float scale;
- } transaxis[6];
-};
-
-/* Convert a Windows Multimedia API return code to a text message */
-static void SetMMerror(char *function, int code);
-
-
-static char *
-GetJoystickName(int index, const char *szRegKey)
-{
- /* added 7/24/2004 by Eckhard Stolberg */
- /*
- see if there is a joystick for the current
- index (1-16) listed in the registry
- */
- char *name = NULL;
- HKEY hTopKey;
- HKEY hKey;
- DWORD regsize;
- LONG regresult;
- char regkey[256];
- char regvalue[256];
- char regname[256];
-
- SDL_snprintf(regkey, SDL_arraysize(regkey), "%s\\%s\\%s",
- REGSTR_PATH_JOYCONFIG, szRegKey, REGSTR_KEY_JOYCURR);
- hTopKey = HKEY_LOCAL_MACHINE;
- regresult = RegOpenKeyExA(hTopKey, regkey, 0, KEY_READ, &hKey);
- if (regresult != ERROR_SUCCESS) {
- hTopKey = HKEY_CURRENT_USER;
- regresult = RegOpenKeyExA(hTopKey, regkey, 0, KEY_READ, &hKey);
- }
- if (regresult != ERROR_SUCCESS) {
- return NULL;
- }
-
- /* find the registry key name for the joystick's properties */
- regsize = sizeof(regname);
- SDL_snprintf(regvalue, SDL_arraysize(regvalue), "Joystick%d%s", index + 1,
- REGSTR_VAL_JOYOEMNAME);
- regresult =
- RegQueryValueExA(hKey, regvalue, 0, 0, (LPBYTE) regname, &regsize);
- RegCloseKey(hKey);
-
- if (regresult != ERROR_SUCCESS) {
- return NULL;
- }
-
- /* open that registry key */
- SDL_snprintf(regkey, SDL_arraysize(regkey), "%s\\%s", REGSTR_PATH_JOYOEM,
- regname);
- regresult = RegOpenKeyExA(hTopKey, regkey, 0, KEY_READ, &hKey);
- if (regresult != ERROR_SUCCESS) {
- return NULL;
- }
-
- /* find the size for the OEM name text */
- regsize = sizeof(regvalue);
- regresult =
- RegQueryValueExA(hKey, REGSTR_VAL_JOYOEMNAME, 0, 0, NULL, &regsize);
- if (regresult == ERROR_SUCCESS) {
- /* allocate enough memory for the OEM name text ... */
- name = (char *) SDL_malloc(regsize);
- if (name) {
- /* ... and read it from the registry */
- regresult = RegQueryValueExA(hKey,
- REGSTR_VAL_JOYOEMNAME, 0, 0,
- (LPBYTE) name, &regsize);
- }
- }
- RegCloseKey(hKey);
-
- return (name);
-}
-
-static int SDL_SYS_numjoysticks = 0;
-
-/* Function to scan the system for joysticks.
- * Joystick 0 should be the system default joystick.
- * It should return 0, or -1 on an unrecoverable fatal error.
- */
-int
-SDL_SYS_JoystickInit(void)
-{
- int i;
- int maxdevs;
- JOYINFOEX joyinfo;
- JOYCAPSA joycaps;
- MMRESULT result;
-
- /* Reset the joystick ID & name mapping tables */
- for (i = 0; i < MAX_JOYSTICKS; ++i) {
- SYS_JoystickID[i] = 0;
- SYS_JoystickName[i] = NULL;
- }
-
- /* Loop over all potential joystick devices */
- SDL_SYS_numjoysticks = 0;
- maxdevs = joyGetNumDevs();
- for (i = JOYSTICKID1; i < maxdevs && SDL_SYS_numjoysticks < MAX_JOYSTICKS; ++i) {
-
- joyinfo.dwSize = sizeof(joyinfo);
- joyinfo.dwFlags = JOY_RETURNALL;
- result = joyGetPosEx(i, &joyinfo);
- if (result == JOYERR_NOERROR) {
- result = joyGetDevCapsA(i, &joycaps, sizeof(joycaps));
- if (result == JOYERR_NOERROR) {
- SYS_JoystickID[SDL_SYS_numjoysticks] = i;
- SYS_Joystick[SDL_SYS_numjoysticks] = joycaps;
- SYS_JoystickName[SDL_SYS_numjoysticks] =
- GetJoystickName(i, joycaps.szRegKey);
- SDL_SYS_numjoysticks++;
- }
- }
- }
- return (SDL_SYS_numjoysticks);
-}
-
-int SDL_SYS_NumJoysticks()
-{
- return SDL_SYS_numjoysticks;
-}
-
-void SDL_SYS_JoystickDetect()
-{
-}
-
-/* Function to get the device-dependent name of a joystick */
-const char *
-SDL_SYS_JoystickNameForDeviceIndex(int device_index)
-{
- if (SYS_JoystickName[device_index] != NULL) {
- return (SYS_JoystickName[device_index]);
- } else {
- return (SYS_Joystick[device_index].szPname);
- }
-}
-
-/* Function to perform the mapping from device index to the instance id for this index */
-SDL_JoystickID SDL_SYS_GetInstanceIdOfDeviceIndex(int device_index)
-{
- return device_index;
-}
-
-/* Function to open a joystick for use.
- The joystick to open is specified by the device index.
- This should fill the nbuttons and naxes fields of the joystick structure.
- It returns 0, or -1 if there is an error.
- */
-int
-SDL_SYS_JoystickOpen(SDL_Joystick * joystick, int device_index)
-{
- int index, i;
- int caps_flags[MAX_AXES - 2] =
- { JOYCAPS_HASZ, JOYCAPS_HASR, JOYCAPS_HASU, JOYCAPS_HASV };
- int axis_min[MAX_AXES], axis_max[MAX_AXES];
-
-
- /* shortcut */
- index = device_index;
- axis_min[0] = SYS_Joystick[index].wXmin;
- axis_max[0] = SYS_Joystick[index].wXmax;
- axis_min[1] = SYS_Joystick[index].wYmin;
- axis_max[1] = SYS_Joystick[index].wYmax;
- axis_min[2] = SYS_Joystick[index].wZmin;
- axis_max[2] = SYS_Joystick[index].wZmax;
- axis_min[3] = SYS_Joystick[index].wRmin;
- axis_max[3] = SYS_Joystick[index].wRmax;
- axis_min[4] = SYS_Joystick[index].wUmin;
- axis_max[4] = SYS_Joystick[index].wUmax;
- axis_min[5] = SYS_Joystick[index].wVmin;
- axis_max[5] = SYS_Joystick[index].wVmax;
-
- /* allocate memory for system specific hardware data */
- joystick->instance_id = device_index;
- joystick->hwdata =
- (struct joystick_hwdata *) SDL_malloc(sizeof(*joystick->hwdata));
- if (joystick->hwdata == NULL) {
- return SDL_OutOfMemory();
- }
- SDL_memset(joystick->hwdata, 0, sizeof(*joystick->hwdata));
-
- /* set hardware data */
- joystick->hwdata->id = SYS_JoystickID[index];
- for (i = 0; i < MAX_AXES; ++i) {
- if ((i < 2) || (SYS_Joystick[index].wCaps & caps_flags[i - 2])) {
- joystick->hwdata->transaxis[i].offset = AXIS_MIN - axis_min[i];
- joystick->hwdata->transaxis[i].scale =
- (float) (AXIS_MAX - AXIS_MIN) / (axis_max[i] - axis_min[i]);
- } else {
- joystick->hwdata->transaxis[i].offset = 0;
- joystick->hwdata->transaxis[i].scale = 1.0; /* Just in case */
- }
- }
-
- /* fill nbuttons, naxes, and nhats fields */
- joystick->nbuttons = SYS_Joystick[index].wNumButtons;
- joystick->naxes = SYS_Joystick[index].wNumAxes;
- if (SYS_Joystick[index].wCaps & JOYCAPS_HASPOV) {
- joystick->nhats = 1;
- } else {
- joystick->nhats = 0;
- }
- return (0);
-}
-
-/* Function to determine if this joystick is attached to the system right now */
-SDL_bool SDL_SYS_JoystickAttached(SDL_Joystick *joystick)
-{
- return SDL_TRUE;
-}
-
-static Uint8
-TranslatePOV(DWORD value)
-{
- Uint8 pos;
-
- pos = SDL_HAT_CENTERED;
- if (value != JOY_POVCENTERED) {
- if ((value > JOY_POVLEFT) || (value < JOY_POVRIGHT)) {
- pos |= SDL_HAT_UP;
- }
- if ((value > JOY_POVFORWARD) && (value < JOY_POVBACKWARD)) {
- pos |= SDL_HAT_RIGHT;
- }
- if ((value > JOY_POVRIGHT) && (value < JOY_POVLEFT)) {
- pos |= SDL_HAT_DOWN;
- }
- if (value > JOY_POVBACKWARD) {
- pos |= SDL_HAT_LEFT;
- }
- }
- return (pos);
-}
-
-/* Function to update the state of a joystick - called as a device poll.
- * This function shouldn't update the joystick structure directly,
- * but instead should call SDL_PrivateJoystick*() to deliver events
- * and update joystick device state.
- */
-void
-SDL_SYS_JoystickUpdate(SDL_Joystick * joystick)
-{
- MMRESULT result;
- int i;
- DWORD flags[MAX_AXES] = { JOY_RETURNX, JOY_RETURNY, JOY_RETURNZ,
- JOY_RETURNR, JOY_RETURNU, JOY_RETURNV
- };
- DWORD pos[MAX_AXES];
- struct _transaxis *transaxis;
- int value, change;
- JOYINFOEX joyinfo;
-
- joyinfo.dwSize = sizeof(joyinfo);
- joyinfo.dwFlags = JOY_RETURNALL | JOY_RETURNPOVCTS;
- if (!joystick->hats) {
- joyinfo.dwFlags &= ~(JOY_RETURNPOV | JOY_RETURNPOVCTS);
- }
- result = joyGetPosEx(joystick->hwdata->id, &joyinfo);
- if (result != JOYERR_NOERROR) {
- SetMMerror("joyGetPosEx", result);
- return;
- }
-
- /* joystick motion events */
- pos[0] = joyinfo.dwXpos;
- pos[1] = joyinfo.dwYpos;
- pos[2] = joyinfo.dwZpos;
- pos[3] = joyinfo.dwRpos;
- pos[4] = joyinfo.dwUpos;
- pos[5] = joyinfo.dwVpos;
-
- transaxis = joystick->hwdata->transaxis;
- for (i = 0; i < joystick->naxes; i++) {
- if (joyinfo.dwFlags & flags[i]) {
- value =
- (int) (((float) pos[i] +
- transaxis[i].offset) * transaxis[i].scale);
- change = (value - joystick->axes[i]);
- if ((change < -JOY_AXIS_THRESHOLD)
- || (change > JOY_AXIS_THRESHOLD)) {
- SDL_PrivateJoystickAxis(joystick, (Uint8) i, (Sint16) value);
- }
- }
- }
-
- /* joystick button events */
- if (joyinfo.dwFlags & JOY_RETURNBUTTONS) {
- for (i = 0; i < joystick->nbuttons; ++i) {
- if (joyinfo.dwButtons & JOY_BUTTON_FLAG(i)) {
- if (!joystick->buttons[i]) {
- SDL_PrivateJoystickButton(joystick, (Uint8) i,
- SDL_PRESSED);
- }
- } else {
- if (joystick->buttons[i]) {
- SDL_PrivateJoystickButton(joystick, (Uint8) i,
- SDL_RELEASED);
- }
- }
- }
- }
-
- /* joystick hat events */
- if (joyinfo.dwFlags & JOY_RETURNPOV) {
- Uint8 pos;
-
- pos = TranslatePOV(joyinfo.dwPOV);
- if (pos != joystick->hats[0]) {
- SDL_PrivateJoystickHat(joystick, 0, pos);
- }
- }
-}
-
-/* Function to close a joystick after use */
-void
-SDL_SYS_JoystickClose(SDL_Joystick * joystick)
-{
- SDL_free(joystick->hwdata);
-}
-
-/* Function to perform any system-specific joystick related cleanup */
-void
-SDL_SYS_JoystickQuit(void)
-{
- int i;
- for (i = 0; i < MAX_JOYSTICKS; i++) {
- SDL_free(SYS_JoystickName[i]);
- SYS_JoystickName[i] = NULL;
- }
-}
-
-SDL_JoystickGUID SDL_SYS_JoystickGetDeviceGUID( int device_index )
-{
- SDL_JoystickGUID guid;
- /* the GUID is just the first 16 chars of the name for now */
- const char *name = SDL_SYS_JoystickNameForDeviceIndex( device_index );
- SDL_zero( guid );
- SDL_memcpy( &guid, name, SDL_min( sizeof(guid), SDL_strlen( name ) ) );
- return guid;
-}
-
-SDL_JoystickGUID SDL_SYS_JoystickGetGUID(SDL_Joystick * joystick)
-{
- SDL_JoystickGUID guid;
- /* the GUID is just the first 16 chars of the name for now */
- const char *name = joystick->name;
- SDL_zero( guid );
- SDL_memcpy( &guid, name, SDL_min( sizeof(guid), SDL_strlen( name ) ) );
- return guid;
-}
-
-
-/* implementation functions */
-void
-SetMMerror(char *function, int code)
-{
- static char *error;
- static char errbuf[1024];
-
- errbuf[0] = 0;
- switch (code) {
- case MMSYSERR_NODRIVER:
- error = "Joystick driver not present";
- break;
-
- case MMSYSERR_INVALPARAM:
- case JOYERR_PARMS:
- error = "Invalid parameter(s)";
- break;
-
- case MMSYSERR_BADDEVICEID:
- error = "Bad device ID";
- break;
-
- case JOYERR_UNPLUGGED:
- error = "Joystick not attached";
- break;
-
- case JOYERR_NOCANDO:
- error = "Can't capture joystick input";
- break;
-
- default:
- SDL_snprintf(errbuf, SDL_arraysize(errbuf),
- "%s: Unknown Multimedia system error: 0x%x",
- function, code);
- break;
- }
-
- if (!errbuf[0]) {
- SDL_snprintf(errbuf, SDL_arraysize(errbuf), "%s: %s", function,
- error);
- }
- SDL_SetError("%s", errbuf);
-}
-
-#endif /* SDL_JOYSTICK_WINMM */
-
-/* vi: set ts=4 sw=4 expandtab: */
diff --git a/3rdparty/SDL2/src/joystick/windows/SDL_windowsjoystick.c b/3rdparty/SDL2/src/joystick/windows/SDL_windowsjoystick.c
deleted file mode 100644
index e528afa7fbf..00000000000
--- a/3rdparty/SDL2/src/joystick/windows/SDL_windowsjoystick.c
+++ /dev/null
@@ -1,538 +0,0 @@
-/*
- Simple DirectMedia Layer
- Copyright (C) 1997-2016 Sam Lantinga <slouken@libsdl.org>
-
- This software is provided 'as-is', without any express or implied
- warranty. In no event will the authors be held liable for any damages
- arising from the use of this software.
-
- Permission is granted to anyone to use this software for any purpose,
- including commercial applications, and to alter it and redistribute it
- freely, subject to the following restrictions:
-
- 1. The origin of this software must not be misrepresented; you must not
- claim that you wrote the original software. If you use this software
- in a product, an acknowledgment in the product documentation would be
- appreciated but is not required.
- 2. Altered source versions must be plainly marked as such, and must not be
- misrepresented as being the original software.
- 3. This notice may not be removed or altered from any source distribution.
-*/
-#include "../../SDL_internal.h"
-
-#if SDL_JOYSTICK_DINPUT || SDL_JOYSTICK_XINPUT
-
-/* DirectInput joystick driver; written by Glenn Maynard, based on Andrei de
- * A. Formiga's WINMM driver.
- *
- * Hats and sliders are completely untested; the app I'm writing this for mostly
- * doesn't use them and I don't own any joysticks with them.
- *
- * We don't bother to use event notification here. It doesn't seem to work
- * with polled devices, and it's fine to call IDirectInputDevice8_GetDeviceData and
- * let it return 0 events. */
-
-#include "SDL_error.h"
-#include "SDL_assert.h"
-#include "SDL_events.h"
-#include "SDL_timer.h"
-#include "SDL_mutex.h"
-#include "SDL_events.h"
-#include "SDL_hints.h"
-#include "SDL_joystick.h"
-#include "../SDL_sysjoystick.h"
-#include "../../thread/SDL_systhread.h"
-#include "../../core/windows/SDL_windows.h"
-#if !defined(__WINRT__)
-#include <dbt.h>
-#endif
-
-#define INITGUID /* Only set here, if set twice will cause mingw32 to break. */
-#include "SDL_windowsjoystick_c.h"
-#include "SDL_dinputjoystick_c.h"
-#include "SDL_xinputjoystick_c.h"
-
-#include "../../haptic/windows/SDL_dinputhaptic_c.h" /* For haptic hot plugging */
-#include "../../haptic/windows/SDL_xinputhaptic_c.h" /* For haptic hot plugging */
-
-
-#ifndef DEVICE_NOTIFY_WINDOW_HANDLE
-#define DEVICE_NOTIFY_WINDOW_HANDLE 0x00000000
-#endif
-
-/* local variables */
-static SDL_bool s_bDeviceAdded = SDL_FALSE;
-static SDL_bool s_bDeviceRemoved = SDL_FALSE;
-static SDL_JoystickID s_nInstanceID = -1;
-static SDL_cond *s_condJoystickThread = NULL;
-static SDL_mutex *s_mutexJoyStickEnum = NULL;
-static SDL_Thread *s_threadJoystick = NULL;
-static SDL_bool s_bJoystickThreadQuit = SDL_FALSE;
-
-JoyStick_DeviceData *SYS_Joystick; /* array to hold joystick ID values */
-
-static SDL_bool s_bWindowsDeviceChanged = SDL_FALSE;
-
-#ifdef __WINRT__
-
-typedef struct
-{
- int unused;
-} SDL_DeviceNotificationData;
-
-static void
-SDL_CleanupDeviceNotification(SDL_DeviceNotificationData *data)
-{
-}
-
-static int
-SDL_CreateDeviceNotification(SDL_DeviceNotificationData *data)
-{
- return 0;
-}
-
-static void
-SDL_CheckDeviceNotification(SDL_DeviceNotificationData *data)
-{
-}
-
-#else /* !__WINRT__ */
-
-typedef struct
-{
- HRESULT coinitialized;
- WNDCLASSEX wincl;
- HWND messageWindow;
- HDEVNOTIFY hNotify;
-} SDL_DeviceNotificationData;
-
-
-/* windowproc for our joystick detect thread message only window, to detect any USB device addition/removal */
-static LRESULT CALLBACK
-SDL_PrivateJoystickDetectProc(HWND hwnd, UINT message, WPARAM wParam, LPARAM lParam)
-{
- switch (message) {
- case WM_DEVICECHANGE:
- switch (wParam) {
- case DBT_DEVICEARRIVAL:
- if (((DEV_BROADCAST_HDR*)lParam)->dbch_devicetype == DBT_DEVTYP_DEVICEINTERFACE) {
- s_bWindowsDeviceChanged = SDL_TRUE;
- }
- break;
- case DBT_DEVICEREMOVECOMPLETE:
- if (((DEV_BROADCAST_HDR*)lParam)->dbch_devicetype == DBT_DEVTYP_DEVICEINTERFACE) {
- s_bWindowsDeviceChanged = SDL_TRUE;
- }
- break;
- }
- return 0;
- }
-
- return DefWindowProc (hwnd, message, wParam, lParam);
-}
-
-static void
-SDL_CleanupDeviceNotification(SDL_DeviceNotificationData *data)
-{
- if (data->hNotify)
- UnregisterDeviceNotification(data->hNotify);
-
- if (data->messageWindow)
- DestroyWindow(data->messageWindow);
-
- UnregisterClass(data->wincl.lpszClassName, data->wincl.hInstance);
-
- if (data->coinitialized == S_OK) {
- WIN_CoUninitialize();
- }
-}
-
-static int
-SDL_CreateDeviceNotification(SDL_DeviceNotificationData *data)
-{
- DEV_BROADCAST_DEVICEINTERFACE dbh;
- GUID GUID_DEVINTERFACE_HID = { 0x4D1E55B2L, 0xF16F, 0x11CF, { 0x88, 0xCB, 0x00, 0x11, 0x11, 0x00, 0x00, 0x30 } };
-
- SDL_zerop(data);
-
- data->coinitialized = WIN_CoInitialize();
-
- data->wincl.hInstance = GetModuleHandle(NULL);
- data->wincl.lpszClassName = L"Message";
- data->wincl.lpfnWndProc = SDL_PrivateJoystickDetectProc; /* This function is called by windows */
- data->wincl.cbSize = sizeof (WNDCLASSEX);
-
- if (!RegisterClassEx(&data->wincl)) {
- WIN_SetError("Failed to create register class for joystick autodetect");
- SDL_CleanupDeviceNotification(data);
- return -1;
- }
-
- data->messageWindow = (HWND)CreateWindowEx(0, L"Message", NULL, 0, 0, 0, 0, 0, HWND_MESSAGE, NULL, NULL, NULL);
- if (!data->messageWindow) {
- WIN_SetError("Failed to create message window for joystick autodetect");
- SDL_CleanupDeviceNotification(data);
- return -1;
- }
-
- SDL_zero(dbh);
- dbh.dbcc_size = sizeof(dbh);
- dbh.dbcc_devicetype = DBT_DEVTYP_DEVICEINTERFACE;
- dbh.dbcc_classguid = GUID_DEVINTERFACE_HID;
-
- data->hNotify = RegisterDeviceNotification(data->messageWindow, &dbh, DEVICE_NOTIFY_WINDOW_HANDLE);
- if (!data->hNotify) {
- WIN_SetError("Failed to create notify device for joystick autodetect");
- SDL_CleanupDeviceNotification(data);
- return -1;
- }
- return 0;
-}
-
-static void
-SDL_CheckDeviceNotification(SDL_DeviceNotificationData *data)
-{
- MSG msg;
-
- if (!data->messageWindow) {
- return;
- }
-
- while (PeekMessage(&msg, data->messageWindow, 0, 0, PM_NOREMOVE)) {
- if (GetMessage(&msg, data->messageWindow, 0, 0) != 0) {
- TranslateMessage(&msg);
- DispatchMessage(&msg);
- }
- }
-}
-
-#endif /* __WINRT__ */
-
-/* Function/thread to scan the system for joysticks. */
-static int
-SDL_JoystickThread(void *_data)
-{
- SDL_DeviceNotificationData notification_data;
-
-#if SDL_JOYSTICK_XINPUT
- SDL_bool bOpenedXInputDevices[XUSER_MAX_COUNT];
- SDL_zero(bOpenedXInputDevices);
-#endif
-
- if (SDL_CreateDeviceNotification(&notification_data) < 0) {
- return -1;
- }
-
- SDL_LockMutex(s_mutexJoyStickEnum);
- while (s_bJoystickThreadQuit == SDL_FALSE) {
- SDL_bool bXInputChanged = SDL_FALSE;
-
- SDL_CondWaitTimeout(s_condJoystickThread, s_mutexJoyStickEnum, 300);
-
- SDL_CheckDeviceNotification(&notification_data);
-
-#if SDL_JOYSTICK_XINPUT
- if (SDL_XINPUT_Enabled() && XINPUTGETCAPABILITIES) {
- /* scan for any change in XInput devices */
- Uint8 userId;
- for (userId = 0; userId < XUSER_MAX_COUNT; userId++) {
- XINPUT_CAPABILITIES capabilities;
- const DWORD result = XINPUTGETCAPABILITIES(userId, XINPUT_FLAG_GAMEPAD, &capabilities);
- const SDL_bool available = (result == ERROR_SUCCESS);
- if (bOpenedXInputDevices[userId] != available) {
- bXInputChanged = SDL_TRUE;
- bOpenedXInputDevices[userId] = available;
- }
- }
- }
-#endif /* SDL_JOYSTICK_XINPUT */
-
- if (s_bWindowsDeviceChanged || bXInputChanged) {
- SDL_UnlockMutex(s_mutexJoyStickEnum); /* let main thread go while we SDL_Delay(). */
- SDL_Delay(300); /* wait for direct input to find out about this device */
- SDL_LockMutex(s_mutexJoyStickEnum);
-
- s_bDeviceRemoved = SDL_TRUE;
- s_bDeviceAdded = SDL_TRUE;
- s_bWindowsDeviceChanged = SDL_FALSE;
- }
- }
- SDL_UnlockMutex(s_mutexJoyStickEnum);
-
- SDL_CleanupDeviceNotification(&notification_data);
-
- return 1;
-}
-
-void SDL_SYS_AddJoystickDevice(JoyStick_DeviceData *device)
-{
- device->send_add_event = SDL_TRUE;
- device->nInstanceID = ++s_nInstanceID;
- device->pNext = SYS_Joystick;
- SYS_Joystick = device;
-
- s_bDeviceAdded = SDL_TRUE;
-}
-
-/* Function to scan the system for joysticks.
- * Joystick 0 should be the system default joystick.
- * It should return 0, or -1 on an unrecoverable fatal error.
- */
-int
-SDL_SYS_JoystickInit(void)
-{
- if (SDL_DINPUT_JoystickInit() < 0) {
- SDL_SYS_JoystickQuit();
- return -1;
- }
-
- if (SDL_XINPUT_JoystickInit() < 0) {
- SDL_SYS_JoystickQuit();
- return -1;
- }
-
- s_mutexJoyStickEnum = SDL_CreateMutex();
- s_condJoystickThread = SDL_CreateCond();
- s_bDeviceAdded = SDL_TRUE; /* force a scan of the system for joysticks this first time */
-
- SDL_SYS_JoystickDetect();
-
- if (!s_threadJoystick) {
- /* spin up the thread to detect hotplug of devices */
- s_bJoystickThreadQuit = SDL_FALSE;
- s_threadJoystick = SDL_CreateThreadInternal(SDL_JoystickThread, "SDL_joystick", 64 * 1024, NULL);
- }
- return SDL_SYS_NumJoysticks();
-}
-
-/* return the number of joysticks that are connected right now */
-int
-SDL_SYS_NumJoysticks()
-{
- int nJoysticks = 0;
- JoyStick_DeviceData *device = SYS_Joystick;
- while (device) {
- nJoysticks++;
- device = device->pNext;
- }
-
- return nJoysticks;
-}
-
-/* detect any new joysticks being inserted into the system */
-void
-SDL_SYS_JoystickDetect()
-{
- JoyStick_DeviceData *pCurList = NULL;
-
- /* only enum the devices if the joystick thread told us something changed */
- if (!s_bDeviceAdded && !s_bDeviceRemoved) {
- return; /* thread hasn't signaled, nothing to do right now. */
- }
-
- SDL_LockMutex(s_mutexJoyStickEnum);
-
- s_bDeviceAdded = SDL_FALSE;
- s_bDeviceRemoved = SDL_FALSE;
-
- pCurList = SYS_Joystick;
- SYS_Joystick = NULL;
-
- /* Look for DirectInput joysticks, wheels, head trackers, gamepads, etc.. */
- SDL_DINPUT_JoystickDetect(&pCurList);
-
- /* Look for XInput devices. Do this last, so they're first in the final list. */
- SDL_XINPUT_JoystickDetect(&pCurList);
-
- SDL_UnlockMutex(s_mutexJoyStickEnum);
-
- while (pCurList) {
- JoyStick_DeviceData *pListNext = NULL;
-
- if (pCurList->bXInputDevice) {
- SDL_XINPUT_MaybeRemoveDevice(pCurList->XInputUserId);
- } else {
- SDL_DINPUT_MaybeRemoveDevice(&pCurList->dxdevice);
- }
-
- SDL_PrivateJoystickRemoved(pCurList->nInstanceID);
-
- pListNext = pCurList->pNext;
- SDL_free(pCurList->joystickname);
- SDL_free(pCurList);
- pCurList = pListNext;
- }
-
- if (s_bDeviceAdded) {
- JoyStick_DeviceData *pNewJoystick;
- int device_index = 0;
- s_bDeviceAdded = SDL_FALSE;
- pNewJoystick = SYS_Joystick;
- while (pNewJoystick) {
- if (pNewJoystick->send_add_event) {
- if (pNewJoystick->bXInputDevice) {
- SDL_XINPUT_MaybeAddDevice(pNewJoystick->XInputUserId);
- } else {
- SDL_DINPUT_MaybeAddDevice(&pNewJoystick->dxdevice);
- }
-
- SDL_PrivateJoystickAdded(device_index);
-
- pNewJoystick->send_add_event = SDL_FALSE;
- }
- device_index++;
- pNewJoystick = pNewJoystick->pNext;
- }
- }
-}
-
-/* Function to get the device-dependent name of a joystick */
-const char *
-SDL_SYS_JoystickNameForDeviceIndex(int device_index)
-{
- JoyStick_DeviceData *device = SYS_Joystick;
-
- for (; device_index > 0; device_index--)
- device = device->pNext;
-
- return device->joystickname;
-}
-
-/* Function to perform the mapping between current device instance and this joysticks instance id */
-SDL_JoystickID
-SDL_SYS_GetInstanceIdOfDeviceIndex(int device_index)
-{
- JoyStick_DeviceData *device = SYS_Joystick;
- int index;
-
- for (index = device_index; index > 0; index--)
- device = device->pNext;
-
- return device->nInstanceID;
-}
-
-/* Function to open a joystick for use.
- The joystick to open is specified by the device index.
- This should fill the nbuttons and naxes fields of the joystick structure.
- It returns 0, or -1 if there is an error.
- */
-int
-SDL_SYS_JoystickOpen(SDL_Joystick * joystick, int device_index)
-{
- JoyStick_DeviceData *joystickdevice = SYS_Joystick;
-
- for (; device_index > 0; device_index--)
- joystickdevice = joystickdevice->pNext;
-
- /* allocate memory for system specific hardware data */
- joystick->instance_id = joystickdevice->nInstanceID;
- joystick->hwdata =
- (struct joystick_hwdata *) SDL_malloc(sizeof(struct joystick_hwdata));
- if (joystick->hwdata == NULL) {
- return SDL_OutOfMemory();
- }
- SDL_zerop(joystick->hwdata);
- joystick->hwdata->guid = joystickdevice->guid;
-
- if (joystickdevice->bXInputDevice) {
- return SDL_XINPUT_JoystickOpen(joystick, joystickdevice);
- } else {
- return SDL_DINPUT_JoystickOpen(joystick, joystickdevice);
- }
-}
-
-/* return true if this joystick is plugged in right now */
-SDL_bool
-SDL_SYS_JoystickAttached(SDL_Joystick * joystick)
-{
- return joystick->hwdata && !joystick->hwdata->removed;
-}
-
-void
-SDL_SYS_JoystickUpdate(SDL_Joystick * joystick)
-{
- if (!joystick->hwdata || joystick->hwdata->removed) {
- return;
- }
-
- if (joystick->hwdata->bXInputDevice) {
- SDL_XINPUT_JoystickUpdate(joystick);
- } else {
- SDL_DINPUT_JoystickUpdate(joystick);
- }
-
- if (joystick->hwdata->removed) {
- joystick->force_recentering = SDL_TRUE;
- }
-}
-
-/* Function to close a joystick after use */
-void
-SDL_SYS_JoystickClose(SDL_Joystick * joystick)
-{
- if (joystick->hwdata->bXInputDevice) {
- SDL_XINPUT_JoystickClose(joystick);
- } else {
- SDL_DINPUT_JoystickClose(joystick);
- }
-
- SDL_free(joystick->hwdata);
-}
-
-/* Function to perform any system-specific joystick related cleanup */
-void
-SDL_SYS_JoystickQuit(void)
-{
- JoyStick_DeviceData *device = SYS_Joystick;
-
- while (device) {
- JoyStick_DeviceData *device_next = device->pNext;
- SDL_free(device->joystickname);
- SDL_free(device);
- device = device_next;
- }
- SYS_Joystick = NULL;
-
- if (s_threadJoystick) {
- SDL_LockMutex(s_mutexJoyStickEnum);
- s_bJoystickThreadQuit = SDL_TRUE;
- SDL_CondBroadcast(s_condJoystickThread); /* signal the joystick thread to quit */
- SDL_UnlockMutex(s_mutexJoyStickEnum);
- SDL_WaitThread(s_threadJoystick, NULL); /* wait for it to bugger off */
-
- SDL_DestroyMutex(s_mutexJoyStickEnum);
- SDL_DestroyCond(s_condJoystickThread);
- s_condJoystickThread= NULL;
- s_mutexJoyStickEnum = NULL;
- s_threadJoystick = NULL;
- }
-
- SDL_DINPUT_JoystickQuit();
- SDL_XINPUT_JoystickQuit();
-
- s_bDeviceAdded = SDL_FALSE;
- s_bDeviceRemoved = SDL_FALSE;
-}
-
-/* return the stable device guid for this device index */
-SDL_JoystickGUID
-SDL_SYS_JoystickGetDeviceGUID(int device_index)
-{
- JoyStick_DeviceData *device = SYS_Joystick;
- int index;
-
- for (index = device_index; index > 0; index--)
- device = device->pNext;
-
- return device->guid;
-}
-
-SDL_JoystickGUID
-SDL_SYS_JoystickGetGUID(SDL_Joystick * joystick)
-{
- return joystick->hwdata->guid;
-}
-
-#endif /* SDL_JOYSTICK_DINPUT || SDL_JOYSTICK_XINPUT */
-
-/* vi: set ts=4 sw=4 expandtab: */
diff --git a/3rdparty/SDL2/src/joystick/windows/SDL_windowsjoystick_c.h b/3rdparty/SDL2/src/joystick/windows/SDL_windowsjoystick_c.h
deleted file mode 100644
index d3c5fcaab19..00000000000
--- a/3rdparty/SDL2/src/joystick/windows/SDL_windowsjoystick_c.h
+++ /dev/null
@@ -1,92 +0,0 @@
-/*
- Simple DirectMedia Layer
- Copyright (C) 1997-2016 Sam Lantinga <slouken@libsdl.org>
-
- This software is provided 'as-is', without any express or implied
- warranty. In no event will the authors be held liable for any damages
- arising from the use of this software.
-
- Permission is granted to anyone to use this software for any purpose,
- including commercial applications, and to alter it and redistribute it
- freely, subject to the following restrictions:
-
- 1. The origin of this software must not be misrepresented; you must not
- claim that you wrote the original software. If you use this software
- in a product, an acknowledgment in the product documentation would be
- appreciated but is not required.
- 2. Altered source versions must be plainly marked as such, and must not be
- misrepresented as being the original software.
- 3. This notice may not be removed or altered from any source distribution.
-*/
-#include "../../SDL_internal.h"
-
-#include "SDL_events.h"
-#include "../SDL_sysjoystick.h"
-#include "../../core/windows/SDL_windows.h"
-#include "../../core/windows/SDL_directx.h"
-
-#define MAX_INPUTS 256 /* each joystick can have up to 256 inputs */
-
-typedef struct JoyStick_DeviceData
-{
- SDL_JoystickGUID guid;
- char *joystickname;
- Uint8 send_add_event;
- SDL_JoystickID nInstanceID;
- SDL_bool bXInputDevice;
- BYTE SubType;
- Uint8 XInputUserId;
- DIDEVICEINSTANCE dxdevice;
- struct JoyStick_DeviceData *pNext;
-} JoyStick_DeviceData;
-
-extern JoyStick_DeviceData *SYS_Joystick; /* array to hold joystick ID values */
-
-typedef enum Type
-{
- BUTTON,
- AXIS,
- HAT
-} Type;
-
-typedef struct input_t
-{
- /* DirectInput offset for this input type: */
- DWORD ofs;
-
- /* Button, axis or hat: */
- Type type;
-
- /* SDL input offset: */
- Uint8 num;
-} input_t;
-
-/* The private structure used to keep track of a joystick */
-struct joystick_hwdata
-{
- SDL_JoystickGUID guid;
- SDL_bool removed;
- SDL_bool send_remove_event;
-
-#if SDL_JOYSTICK_DINPUT
- LPDIRECTINPUTDEVICE8 InputDevice;
- DIDEVCAPS Capabilities;
- SDL_bool buffered;
- input_t Inputs[MAX_INPUTS];
- int NumInputs;
- int NumSliders;
-#endif
-
- SDL_bool bXInputDevice; /* SDL_TRUE if this device supports using the xinput API rather than DirectInput */
- SDL_bool bXInputHaptic; /* Supports force feedback via XInput. */
- Uint8 userid; /* XInput userid index for this joystick */
- DWORD dwPacketNumber;
-};
-
-#if SDL_JOYSTICK_DINPUT
-extern const DIDATAFORMAT SDL_c_dfDIJoystick2;
-#endif
-
-extern void SDL_SYS_AddJoystickDevice(JoyStick_DeviceData *device);
-
-/* vi: set ts=4 sw=4 expandtab: */
diff --git a/3rdparty/SDL2/src/joystick/windows/SDL_xinputjoystick.c b/3rdparty/SDL2/src/joystick/windows/SDL_xinputjoystick.c
deleted file mode 100644
index d581d45b9ca..00000000000
--- a/3rdparty/SDL2/src/joystick/windows/SDL_xinputjoystick.c
+++ /dev/null
@@ -1,421 +0,0 @@
-/*
- Simple DirectMedia Layer
- Copyright (C) 1997-2016 Sam Lantinga <slouken@libsdl.org>
-
- This software is provided 'as-is', without any express or implied
- warranty. In no event will the authors be held liable for any damages
- arising from the use of this software.
-
- Permission is granted to anyone to use this software for any purpose,
- including commercial applications, and to alter it and redistribute it
- freely, subject to the following restrictions:
-
- 1. The origin of this software must not be misrepresented; you must not
- claim that you wrote the original software. If you use this software
- in a product, an acknowledgment in the product documentation would be
- appreciated but is not required.
- 2. Altered source versions must be plainly marked as such, and must not be
- misrepresented as being the original software.
- 3. This notice may not be removed or altered from any source distribution.
-*/
-#include "../../SDL_internal.h"
-
-#include "../SDL_sysjoystick.h"
-
-#if SDL_JOYSTICK_XINPUT
-
-#include "SDL_assert.h"
-#include "SDL_hints.h"
-#include "SDL_windowsjoystick_c.h"
-#include "SDL_xinputjoystick_c.h"
-
-/*
- * Internal stuff.
- */
-static SDL_bool s_bXInputEnabled = SDL_TRUE;
-
-
-static SDL_bool
-SDL_XInputUseOldJoystickMapping()
-{
- static int s_XInputUseOldJoystickMapping = -1;
- if (s_XInputUseOldJoystickMapping < 0) {
- s_XInputUseOldJoystickMapping = SDL_GetHintBoolean(SDL_HINT_XINPUT_USE_OLD_JOYSTICK_MAPPING, SDL_FALSE);
- }
- return (s_XInputUseOldJoystickMapping > 0);
-}
-
-SDL_bool SDL_XINPUT_Enabled(void)
-{
- return s_bXInputEnabled;
-}
-
-int
-SDL_XINPUT_JoystickInit(void)
-{
- s_bXInputEnabled = SDL_GetHintBoolean(SDL_HINT_XINPUT_ENABLED, SDL_TRUE);
-
- if (s_bXInputEnabled && WIN_LoadXInputDLL() < 0) {
- s_bXInputEnabled = SDL_FALSE; /* oh well. */
- }
- return 0;
-}
-
-static char *
-GetXInputName(const Uint8 userid, BYTE SubType)
-{
- char name[32];
-
- if (SDL_XInputUseOldJoystickMapping()) {
- SDL_snprintf(name, sizeof(name), "X360 Controller #%u", 1 + userid);
- } else {
- switch (SubType) {
- case XINPUT_DEVSUBTYPE_GAMEPAD:
- SDL_snprintf(name, sizeof(name), "XInput Controller #%u", 1 + userid);
- break;
- case XINPUT_DEVSUBTYPE_WHEEL:
- SDL_snprintf(name, sizeof(name), "XInput Wheel #%u", 1 + userid);
- break;
- case XINPUT_DEVSUBTYPE_ARCADE_STICK:
- SDL_snprintf(name, sizeof(name), "XInput ArcadeStick #%u", 1 + userid);
- break;
- case XINPUT_DEVSUBTYPE_FLIGHT_STICK:
- SDL_snprintf(name, sizeof(name), "XInput FlightStick #%u", 1 + userid);
- break;
- case XINPUT_DEVSUBTYPE_DANCE_PAD:
- SDL_snprintf(name, sizeof(name), "XInput DancePad #%u", 1 + userid);
- break;
- case XINPUT_DEVSUBTYPE_GUITAR:
- case XINPUT_DEVSUBTYPE_GUITAR_ALTERNATE:
- case XINPUT_DEVSUBTYPE_GUITAR_BASS:
- SDL_snprintf(name, sizeof(name), "XInput Guitar #%u", 1 + userid);
- break;
- case XINPUT_DEVSUBTYPE_DRUM_KIT:
- SDL_snprintf(name, sizeof(name), "XInput DrumKit #%u", 1 + userid);
- break;
- case XINPUT_DEVSUBTYPE_ARCADE_PAD:
- SDL_snprintf(name, sizeof(name), "XInput ArcadePad #%u", 1 + userid);
- break;
- default:
- SDL_snprintf(name, sizeof(name), "XInput Device #%u", 1 + userid);
- break;
- }
- }
- return SDL_strdup(name);
-}
-
-static void
-AddXInputDevice(const Uint8 userid, BYTE SubType, JoyStick_DeviceData **pContext)
-{
- JoyStick_DeviceData *pPrevJoystick = NULL;
- JoyStick_DeviceData *pNewJoystick = *pContext;
-
- if (SDL_XInputUseOldJoystickMapping() && SubType != XINPUT_DEVSUBTYPE_GAMEPAD)
- return;
-
- if (SubType == XINPUT_DEVSUBTYPE_UNKNOWN)
- return;
-
- while (pNewJoystick) {
- if (pNewJoystick->bXInputDevice && (pNewJoystick->XInputUserId == userid) && (pNewJoystick->SubType == SubType)) {
- /* if we are replacing the front of the list then update it */
- if (pNewJoystick == *pContext) {
- *pContext = pNewJoystick->pNext;
- } else if (pPrevJoystick) {
- pPrevJoystick->pNext = pNewJoystick->pNext;
- }
-
- pNewJoystick->pNext = SYS_Joystick;
- SYS_Joystick = pNewJoystick;
- return; /* already in the list. */
- }
-
- pPrevJoystick = pNewJoystick;
- pNewJoystick = pNewJoystick->pNext;
- }
-
- pNewJoystick = (JoyStick_DeviceData *)SDL_malloc(sizeof(JoyStick_DeviceData));
- if (!pNewJoystick) {
- return; /* better luck next time? */
- }
- SDL_zerop(pNewJoystick);
-
- pNewJoystick->joystickname = GetXInputName(userid, SubType);
- if (!pNewJoystick->joystickname) {
- SDL_free(pNewJoystick);
- return; /* better luck next time? */
- }
-
- pNewJoystick->bXInputDevice = SDL_TRUE;
- if (SDL_XInputUseOldJoystickMapping()) {
- SDL_zero(pNewJoystick->guid);
- } else {
- pNewJoystick->guid.data[0] = 'x';
- pNewJoystick->guid.data[1] = 'i';
- pNewJoystick->guid.data[2] = 'n';
- pNewJoystick->guid.data[3] = 'p';
- pNewJoystick->guid.data[4] = 'u';
- pNewJoystick->guid.data[5] = 't';
- pNewJoystick->guid.data[6] = SubType;
- }
- pNewJoystick->SubType = SubType;
- pNewJoystick->XInputUserId = userid;
- SDL_SYS_AddJoystickDevice(pNewJoystick);
-}
-
-void
-SDL_XINPUT_JoystickDetect(JoyStick_DeviceData **pContext)
-{
- int iuserid;
-
- if (!s_bXInputEnabled) {
- return;
- }
-
- /* iterate in reverse, so these are in the final list in ascending numeric order. */
- for (iuserid = XUSER_MAX_COUNT - 1; iuserid >= 0; iuserid--) {
- const Uint8 userid = (Uint8)iuserid;
- XINPUT_CAPABILITIES capabilities;
- if (XINPUTGETCAPABILITIES(userid, XINPUT_FLAG_GAMEPAD, &capabilities) == ERROR_SUCCESS) {
- AddXInputDevice(userid, capabilities.SubType, pContext);
- }
- }
-}
-
-int
-SDL_XINPUT_JoystickOpen(SDL_Joystick * joystick, JoyStick_DeviceData *joystickdevice)
-{
- const Uint8 userId = joystickdevice->XInputUserId;
- XINPUT_CAPABILITIES capabilities;
- XINPUT_VIBRATION state;
-
- SDL_assert(s_bXInputEnabled);
- SDL_assert(XINPUTGETCAPABILITIES);
- SDL_assert(XINPUTSETSTATE);
- SDL_assert(userId < XUSER_MAX_COUNT);
-
- joystick->hwdata->bXInputDevice = SDL_TRUE;
-
- if (XINPUTGETCAPABILITIES(userId, XINPUT_FLAG_GAMEPAD, &capabilities) != ERROR_SUCCESS) {
- SDL_free(joystick->hwdata);
- joystick->hwdata = NULL;
- return SDL_SetError("Failed to obtain XInput device capabilities. Device disconnected?");
- }
- SDL_zero(state);
- joystick->hwdata->bXInputHaptic = (XINPUTSETSTATE(userId, &state) == ERROR_SUCCESS);
- joystick->hwdata->userid = userId;
-
- /* The XInput API has a hard coded button/axis mapping, so we just match it */
- if (SDL_XInputUseOldJoystickMapping()) {
- joystick->naxes = 6;
- joystick->nbuttons = 15;
- } else {
- joystick->naxes = 6;
- joystick->nbuttons = 11;
- joystick->nhats = 1;
- }
- return 0;
-}
-
-static void
-UpdateXInputJoystickBatteryInformation(SDL_Joystick * joystick, XINPUT_BATTERY_INFORMATION_EX *pBatteryInformation)
-{
- if ( pBatteryInformation->BatteryType != BATTERY_TYPE_UNKNOWN )
- {
- SDL_JoystickPowerLevel ePowerLevel = SDL_JOYSTICK_POWER_UNKNOWN;
- if (pBatteryInformation->BatteryType == BATTERY_TYPE_WIRED) {
- ePowerLevel = SDL_JOYSTICK_POWER_WIRED;
- } else {
- switch ( pBatteryInformation->BatteryLevel )
- {
- case BATTERY_LEVEL_EMPTY:
- ePowerLevel = SDL_JOYSTICK_POWER_EMPTY;
- break;
- case BATTERY_LEVEL_LOW:
- ePowerLevel = SDL_JOYSTICK_POWER_LOW;
- break;
- case BATTERY_LEVEL_MEDIUM:
- ePowerLevel = SDL_JOYSTICK_POWER_MEDIUM;
- break;
- default:
- case BATTERY_LEVEL_FULL:
- ePowerLevel = SDL_JOYSTICK_POWER_FULL;
- break;
- }
- }
-
- SDL_PrivateJoystickBatteryLevel( joystick, ePowerLevel );
- }
-}
-
-static void
-UpdateXInputJoystickState_OLD(SDL_Joystick * joystick, XINPUT_STATE_EX *pXInputState, XINPUT_BATTERY_INFORMATION_EX *pBatteryInformation)
-{
- static WORD s_XInputButtons[] = {
- XINPUT_GAMEPAD_DPAD_UP, XINPUT_GAMEPAD_DPAD_DOWN, XINPUT_GAMEPAD_DPAD_LEFT, XINPUT_GAMEPAD_DPAD_RIGHT,
- XINPUT_GAMEPAD_START, XINPUT_GAMEPAD_BACK, XINPUT_GAMEPAD_LEFT_THUMB, XINPUT_GAMEPAD_RIGHT_THUMB,
- XINPUT_GAMEPAD_LEFT_SHOULDER, XINPUT_GAMEPAD_RIGHT_SHOULDER,
- XINPUT_GAMEPAD_A, XINPUT_GAMEPAD_B, XINPUT_GAMEPAD_X, XINPUT_GAMEPAD_Y,
- XINPUT_GAMEPAD_GUIDE
- };
- WORD wButtons = pXInputState->Gamepad.wButtons;
- Uint8 button;
-
- SDL_PrivateJoystickAxis(joystick, 0, (Sint16)pXInputState->Gamepad.sThumbLX);
- SDL_PrivateJoystickAxis(joystick, 1, (Sint16)(-SDL_max(-32767, pXInputState->Gamepad.sThumbLY)));
- SDL_PrivateJoystickAxis(joystick, 2, (Sint16)pXInputState->Gamepad.sThumbRX);
- SDL_PrivateJoystickAxis(joystick, 3, (Sint16)(-SDL_max(-32767, pXInputState->Gamepad.sThumbRY)));
- SDL_PrivateJoystickAxis(joystick, 4, (Sint16)(((int)pXInputState->Gamepad.bLeftTrigger * 65535 / 255) - 32768));
- SDL_PrivateJoystickAxis(joystick, 5, (Sint16)(((int)pXInputState->Gamepad.bRightTrigger * 65535 / 255) - 32768));
-
- for (button = 0; button < SDL_arraysize(s_XInputButtons); ++button) {
- SDL_PrivateJoystickButton(joystick, button, (wButtons & s_XInputButtons[button]) ? SDL_PRESSED : SDL_RELEASED);
- }
-
- UpdateXInputJoystickBatteryInformation( joystick, pBatteryInformation );
-}
-
-static void
-UpdateXInputJoystickState(SDL_Joystick * joystick, XINPUT_STATE_EX *pXInputState, XINPUT_BATTERY_INFORMATION_EX *pBatteryInformation)
-{
- static WORD s_XInputButtons[] = {
- XINPUT_GAMEPAD_A, XINPUT_GAMEPAD_B, XINPUT_GAMEPAD_X, XINPUT_GAMEPAD_Y,
- XINPUT_GAMEPAD_LEFT_SHOULDER, XINPUT_GAMEPAD_RIGHT_SHOULDER, XINPUT_GAMEPAD_BACK, XINPUT_GAMEPAD_START,
- XINPUT_GAMEPAD_LEFT_THUMB, XINPUT_GAMEPAD_RIGHT_THUMB,
- XINPUT_GAMEPAD_GUIDE
- };
- WORD wButtons = pXInputState->Gamepad.wButtons;
- Uint8 button;
- Uint8 hat = SDL_HAT_CENTERED;
-
- SDL_PrivateJoystickAxis(joystick, 0, (Sint16)pXInputState->Gamepad.sThumbLX);
- SDL_PrivateJoystickAxis(joystick, 1, (Sint16)(-SDL_max(-32767, pXInputState->Gamepad.sThumbLY)));
- SDL_PrivateJoystickAxis(joystick, 2, (Sint16)(((int)pXInputState->Gamepad.bLeftTrigger * 65535 / 255) - 32768));
- SDL_PrivateJoystickAxis(joystick, 3, (Sint16)pXInputState->Gamepad.sThumbRX);
- SDL_PrivateJoystickAxis(joystick, 4, (Sint16)(-SDL_max(-32767, pXInputState->Gamepad.sThumbRY)));
- SDL_PrivateJoystickAxis(joystick, 5, (Sint16)(((int)pXInputState->Gamepad.bRightTrigger * 65535 / 255) - 32768));
-
- for (button = 0; button < SDL_arraysize(s_XInputButtons); ++button) {
- SDL_PrivateJoystickButton(joystick, button, (wButtons & s_XInputButtons[button]) ? SDL_PRESSED : SDL_RELEASED);
- }
-
- if (wButtons & XINPUT_GAMEPAD_DPAD_UP) {
- hat |= SDL_HAT_UP;
- }
- if (wButtons & XINPUT_GAMEPAD_DPAD_DOWN) {
- hat |= SDL_HAT_DOWN;
- }
- if (wButtons & XINPUT_GAMEPAD_DPAD_LEFT) {
- hat |= SDL_HAT_LEFT;
- }
- if (wButtons & XINPUT_GAMEPAD_DPAD_RIGHT) {
- hat |= SDL_HAT_RIGHT;
- }
- SDL_PrivateJoystickHat(joystick, 0, hat);
-
- UpdateXInputJoystickBatteryInformation( joystick, pBatteryInformation );
-}
-
-void
-SDL_XINPUT_JoystickUpdate(SDL_Joystick * joystick)
-{
- HRESULT result;
- XINPUT_STATE_EX XInputState;
- XINPUT_BATTERY_INFORMATION_EX XBatteryInformation;
-
- if (!XINPUTGETSTATE)
- return;
-
- result = XINPUTGETSTATE(joystick->hwdata->userid, &XInputState);
- if (result == ERROR_DEVICE_NOT_CONNECTED) {
- joystick->hwdata->send_remove_event = SDL_TRUE;
- joystick->hwdata->removed = SDL_TRUE;
- return;
- }
-
- SDL_zero( XBatteryInformation );
- if ( XINPUTGETBATTERYINFORMATION )
- {
- result = XINPUTGETBATTERYINFORMATION( joystick->hwdata->userid, BATTERY_DEVTYPE_GAMEPAD, &XBatteryInformation );
- }
-
- /* only fire events if the data changed from last time */
- if (XInputState.dwPacketNumber && XInputState.dwPacketNumber != joystick->hwdata->dwPacketNumber) {
- if (SDL_XInputUseOldJoystickMapping()) {
- UpdateXInputJoystickState_OLD(joystick, &XInputState, &XBatteryInformation);
- } else {
- UpdateXInputJoystickState(joystick, &XInputState, &XBatteryInformation);
- }
- joystick->hwdata->dwPacketNumber = XInputState.dwPacketNumber;
- }
-}
-
-void
-SDL_XINPUT_JoystickClose(SDL_Joystick * joystick)
-{
-}
-
-void
-SDL_XINPUT_JoystickQuit(void)
-{
- if (s_bXInputEnabled) {
- WIN_UnloadXInputDLL();
- }
-}
-
-SDL_bool
-SDL_SYS_IsXInputGamepad_DeviceIndex(int device_index)
-{
- JoyStick_DeviceData *device = SYS_Joystick;
- int index;
-
- for (index = device_index; index > 0; index--)
- device = device->pNext;
-
- return device->bXInputDevice;
-}
-
-#else /* !SDL_JOYSTICK_XINPUT */
-
-typedef struct JoyStick_DeviceData JoyStick_DeviceData;
-
-SDL_bool SDL_XINPUT_Enabled(void)
-{
- return SDL_FALSE;
-}
-
-int
-SDL_XINPUT_JoystickInit(void)
-{
- return 0;
-}
-
-void
-SDL_XINPUT_JoystickDetect(JoyStick_DeviceData **pContext)
-{
-}
-
-int
-SDL_XINPUT_JoystickOpen(SDL_Joystick * joystick, JoyStick_DeviceData *joystickdevice)
-{
- return SDL_Unsupported();
-}
-
-void
-SDL_XINPUT_JoystickUpdate(SDL_Joystick * joystick)
-{
-}
-
-void
-SDL_XINPUT_JoystickClose(SDL_Joystick * joystick)
-{
-}
-
-void
-SDL_XINPUT_JoystickQuit(void)
-{
-}
-
-#endif /* SDL_JOYSTICK_XINPUT */
-
-/* vi: set ts=4 sw=4 expandtab: */
diff --git a/3rdparty/SDL2/src/joystick/windows/SDL_xinputjoystick_c.h b/3rdparty/SDL2/src/joystick/windows/SDL_xinputjoystick_c.h
deleted file mode 100644
index b3ba8c02e5e..00000000000
--- a/3rdparty/SDL2/src/joystick/windows/SDL_xinputjoystick_c.h
+++ /dev/null
@@ -1,33 +0,0 @@
-/*
- Simple DirectMedia Layer
- Copyright (C) 1997-2016 Sam Lantinga <slouken@libsdl.org>
-
- This software is provided 'as-is', without any express or implied
- warranty. In no event will the authors be held liable for any damages
- arising from the use of this software.
-
- Permission is granted to anyone to use this software for any purpose,
- including commercial applications, and to alter it and redistribute it
- freely, subject to the following restrictions:
-
- 1. The origin of this software must not be misrepresented; you must not
- claim that you wrote the original software. If you use this software
- in a product, an acknowledgment in the product documentation would be
- appreciated but is not required.
- 2. Altered source versions must be plainly marked as such, and must not be
- misrepresented as being the original software.
- 3. This notice may not be removed or altered from any source distribution.
-*/
-#include "../../SDL_internal.h"
-
-#include "../../core/windows/SDL_xinput.h"
-
-extern SDL_bool SDL_XINPUT_Enabled(void);
-extern int SDL_XINPUT_JoystickInit(void);
-extern void SDL_XINPUT_JoystickDetect(JoyStick_DeviceData **pContext);
-extern int SDL_XINPUT_JoystickOpen(SDL_Joystick * joystick, JoyStick_DeviceData *joystickdevice);
-extern void SDL_XINPUT_JoystickUpdate(SDL_Joystick * joystick);
-extern void SDL_XINPUT_JoystickClose(SDL_Joystick * joystick);
-extern void SDL_XINPUT_JoystickQuit(void);
-
-/* vi: set ts=4 sw=4 expandtab: */