termux-packages/x11-packages/sdl2/SDL2-2.0.9_src_joystick_SDL_gamecontroller.c.patch
2022-04-18 14:08:37 +05:30

156 lines
6.3 KiB
Diff

diff -uNr SDL2-2.0.9/src/joystick/SDL_gamecontroller.c SDL2-2.0.9.mod/src/joystick/SDL_gamecontroller.c
--- SDL2-2.0.9/src/joystick/SDL_gamecontroller.c 2018-10-31 17:07:22.000000000 +0200
+++ SDL2-2.0.9.mod/src/joystick/SDL_gamecontroller.c 2018-11-09 17:03:00.684548640 +0200
@@ -34,10 +34,6 @@
#include "../events/SDL_events_c.h"
#endif
-#if defined(__ANDROID__)
-#include "SDL_system.h"
-#endif
-
/* Many controllers turn the center button into an instantaneous button press */
#define SDL_MINIMUM_GUIDE_BUTTON_DELAY_MS 250
@@ -887,119 +883,6 @@
return pControllerMapping;
}
-#ifdef __ANDROID__
-/*
- * Helper function to guess at a mapping based on the elements reported for this controller
- */
-static ControllerMapping_t *SDL_CreateMappingForAndroidController(const char *name, SDL_JoystickGUID guid)
-{
- SDL_bool existing;
- char name_string[128];
- char mapping_string[1024];
- int button_mask;
- int axis_mask;
-
- button_mask = SDL_SwapLE16(*(Uint16*)(&guid.data[sizeof(guid.data)-4]));
- axis_mask = SDL_SwapLE16(*(Uint16*)(&guid.data[sizeof(guid.data)-2]));
- if (!button_mask && !axis_mask) {
- /* Accelerometer, shouldn't have a game controller mapping */
- return NULL;
- }
-
- /* Remove any commas in the name */
- SDL_strlcpy(name_string, name, sizeof(name_string));
- {
- char *spot;
- for (spot = name_string; *spot; ++spot) {
- if (*spot == ',') {
- *spot = ' ';
- }
- }
- }
- SDL_snprintf(mapping_string, sizeof(mapping_string), "none,%s,", name_string);
- if (button_mask & (1 << SDL_CONTROLLER_BUTTON_A)) {
- SDL_strlcat(mapping_string, "a:b0,", sizeof(mapping_string));
- }
- if (button_mask & (1 << SDL_CONTROLLER_BUTTON_B)) {
- SDL_strlcat(mapping_string, "b:b1,", sizeof(mapping_string));
- } else if (button_mask & (1 << SDL_CONTROLLER_BUTTON_BACK)) {
- /* Use the back button as "B" for easy UI navigation with TV remotes */
- SDL_strlcat(mapping_string, "b:b4,", sizeof(mapping_string));
- button_mask &= ~(1 << SDL_CONTROLLER_BUTTON_BACK);
- }
- if (button_mask & (1 << SDL_CONTROLLER_BUTTON_X)) {
- SDL_strlcat(mapping_string, "x:b2,", sizeof(mapping_string));
- }
- if (button_mask & (1 << SDL_CONTROLLER_BUTTON_Y)) {
- SDL_strlcat(mapping_string, "y:b3,", sizeof(mapping_string));
- }
- if (button_mask & (1 << SDL_CONTROLLER_BUTTON_BACK)) {
- SDL_strlcat(mapping_string, "back:b4,", sizeof(mapping_string));
- }
-#if 0 /* The guide button generally isn't functional (or acts as a home button) on most Android controllers */
- if (button_mask & (1 << SDL_CONTROLLER_BUTTON_GUIDE)) {
- SDL_strlcat(mapping_string, "guide:b5,", sizeof(mapping_string));
-#if 0 /* Actually this will be done in Steam */
- } else if (button_mask & (1 << SDL_CONTROLLER_BUTTON_START)) {
- /* The guide button doesn't exist, use the start button instead,
- so you can do Steam guide button chords and open the Steam overlay.
- */
- SDL_strlcat(mapping_string, "guide:b6,", sizeof(mapping_string));
- button_mask &= ~(1 << SDL_CONTROLLER_BUTTON_START);
-#endif
- }
-#endif
- if (button_mask & (1 << SDL_CONTROLLER_BUTTON_START)) {
- SDL_strlcat(mapping_string, "start:b6,", sizeof(mapping_string));
- }
- if (button_mask & (1 << SDL_CONTROLLER_BUTTON_LEFTSTICK)) {
- SDL_strlcat(mapping_string, "leftstick:b7,", sizeof(mapping_string));
- }
- if (button_mask & (1 << SDL_CONTROLLER_BUTTON_RIGHTSTICK)) {
- SDL_strlcat(mapping_string, "rightstick:b8,", sizeof(mapping_string));
- }
- if (button_mask & (1 << SDL_CONTROLLER_BUTTON_LEFTSHOULDER)) {
- SDL_strlcat(mapping_string, "leftshoulder:b9,", sizeof(mapping_string));
- }
- if (button_mask & (1 << SDL_CONTROLLER_BUTTON_RIGHTSHOULDER)) {
- SDL_strlcat(mapping_string, "rightshoulder:b10,", sizeof(mapping_string));
- }
- if (button_mask & (1 << SDL_CONTROLLER_BUTTON_DPAD_UP)) {
- SDL_strlcat(mapping_string, "dpup:b11,", sizeof(mapping_string));
- }
- if (button_mask & (1 << SDL_CONTROLLER_BUTTON_DPAD_DOWN)) {
- SDL_strlcat(mapping_string, "dpdown:b12,", sizeof(mapping_string));
- }
- if (button_mask & (1 << SDL_CONTROLLER_BUTTON_DPAD_LEFT)) {
- SDL_strlcat(mapping_string, "dpleft:b13,", sizeof(mapping_string));
- }
- if (button_mask & (1 << SDL_CONTROLLER_BUTTON_DPAD_RIGHT)) {
- SDL_strlcat(mapping_string, "dpright:b14,", sizeof(mapping_string));
- }
- if (axis_mask & (1 << SDL_CONTROLLER_AXIS_LEFTX)) {
- SDL_strlcat(mapping_string, "leftx:a0,", sizeof(mapping_string));
- }
- if (axis_mask & (1 << SDL_CONTROLLER_AXIS_LEFTY)) {
- SDL_strlcat(mapping_string, "lefty:a1,", sizeof(mapping_string));
- }
- if (axis_mask & (1 << SDL_CONTROLLER_AXIS_RIGHTX)) {
- SDL_strlcat(mapping_string, "rightx:a2,", sizeof(mapping_string));
- }
- if (axis_mask & (1 << SDL_CONTROLLER_AXIS_RIGHTY)) {
- SDL_strlcat(mapping_string, "righty:a3,", sizeof(mapping_string));
- }
- if (axis_mask & (1 << SDL_CONTROLLER_AXIS_TRIGGERLEFT)) {
- SDL_strlcat(mapping_string, "lefttrigger:a4,", sizeof(mapping_string));
- }
- if (axis_mask & (1 << SDL_CONTROLLER_AXIS_TRIGGERRIGHT)) {
- SDL_strlcat(mapping_string, "righttrigger:a5,", sizeof(mapping_string));
- }
- return SDL_PrivateAddMappingForGUID(guid, mapping_string,
- &existing, SDL_CONTROLLER_MAPPING_PRIORITY_DEFAULT);
-}
-#endif /* __ANDROID__ */
-
-
/*
* Helper function to determine pre-calculated offset to certain joystick mappings
*/
@@ -1025,11 +908,6 @@
mapping = s_pXInputMapping;
}
}
-#ifdef __ANDROID__
- if (!mapping && name && !SDL_IsJoystickHIDAPI(guid)) {
- mapping = SDL_CreateMappingForAndroidController(name, guid);
- }
-#endif
if (!mapping) {
mapping = s_pDefaultMapping;
}
@@ -1315,8 +1193,6 @@
#ifdef CONTROLLER_MAPPING_FILE
#define STRING(X) SDL_STRINGIFY_ARG(X)
return SDL_strlcpy(path, STRING(CONTROLLER_MAPPING_FILE), size) < size;
-#elif defined(__ANDROID__)
- return SDL_snprintf(path, size, "%s/controller_map.txt", SDL_AndroidGetInternalStoragePath()) < size;
#else
return SDL_FALSE;
#endif