[Commits] SDL: Don't overwrite the default binding when changing the bindi...

libsdl.org revision control commits-owner at libsdl.org
Wed Sep 5 12:17:09 PDT 2018


details:   https://hg.libsdl.org/SDL/rev/8be6b6e98c3c
changeset: 12174:8be6b6e98c3c
user:      Sam Lantinga <slouken at libsdl.org>
date:      Wed Sep 05 12:16:01 2018 -0700
description:
Don't overwrite the default binding when changing the binding for a controller that was using the default.

diffstat:

 src/joystick/SDL_gamecontroller.c |  28 +++++++++++++++-------------
 1 files changed, 15 insertions(+), 13 deletions(-)

diffs (67 lines):

diff -r e26ef3c19774 -r 8be6b6e98c3c src/joystick/SDL_gamecontroller.c
--- a/src/joystick/SDL_gamecontroller.c	Wed Sep 05 11:24:23 2018 -0700
+++ b/src/joystick/SDL_gamecontroller.c	Wed Sep 05 12:16:01 2018 -0700
@@ -422,7 +422,7 @@
 /*
  * Helper function to scan the mappings database for a controller with the specified GUID
  */
-static ControllerMapping_t *SDL_PrivateGetControllerMappingForGUID(SDL_JoystickGUID *guid)
+static ControllerMapping_t *SDL_PrivateGetControllerMappingForGUID(SDL_JoystickGUID *guid, SDL_bool exact_match)
 {
     ControllerMapping_t *pSupportedController = s_pSupportedControllers;
     while (pSupportedController) {
@@ -431,16 +431,18 @@
         }
         pSupportedController = pSupportedController->next;
     }
-    if (guid->data[14] == 'h') {
-        /* This is a HIDAPI device */
-        return s_pHIDAPIMapping;
+    if (!exact_match) {
+        if (guid->data[14] == 'h') {
+            /* This is a HIDAPI device */
+            return s_pHIDAPIMapping;
+        }
+#if SDL_JOYSTICK_XINPUT
+        if (guid->data[14] == 'x') {
+            /* This is an XInput device */
+            return s_pXInputMapping;
+        }
+#endif
     }
-#if SDL_JOYSTICK_XINPUT
-    if (guid->data[14] == 'x') {
-        /* This is an XInput device */
-        return s_pXInputMapping;
-    }
-#endif
     return NULL;
 }
 
@@ -836,7 +838,7 @@
         return NULL;
     }
 
-    pControllerMapping = SDL_PrivateGetControllerMappingForGUID(&jGUID);
+    pControllerMapping = SDL_PrivateGetControllerMappingForGUID(&jGUID, SDL_TRUE);
     if (pControllerMapping) {
         /* Only overwrite the mapping if the priority is the same or higher. */
         if (pControllerMapping->priority <= priority) {
@@ -1005,7 +1007,7 @@
 {
     ControllerMapping_t *mapping;
 
-    mapping = SDL_PrivateGetControllerMappingForGUID(&guid);
+    mapping = SDL_PrivateGetControllerMappingForGUID(&guid, SDL_FALSE);
 #ifdef __LINUX__
     if (!mapping && name) {
         if (SDL_strstr(name, "Xbox 360 Wireless Receiver")) {
@@ -1244,7 +1246,7 @@
 SDL_GameControllerMappingForGUID(SDL_JoystickGUID guid)
 {
     char *pMappingString = NULL;
-    ControllerMapping_t *mapping = SDL_PrivateGetControllerMappingForGUID(&guid);
+    ControllerMapping_t *mapping = SDL_PrivateGetControllerMappingForGUID(&guid, SDL_FALSE);
     if (mapping) {
         char pchGUID[33];
         size_t needed;


More information about the commits mailing list