src/joystick/linux/SDL_sysjoystick.c
changeset 13444 3b0ad6c584ac
parent 13442 d885f6cfea3b
child 13479 26fa8708d147
     1.1 --- a/src/joystick/linux/SDL_sysjoystick.c	Thu Jan 23 12:53:41 2020 -0800
     1.2 +++ b/src/joystick/linux/SDL_sysjoystick.c	Thu Jan 23 12:53:43 2020 -0800
     1.3 @@ -102,6 +102,23 @@
     1.4      return matchlen;
     1.5  }
     1.6  
     1.7 +static void
     1.8 +FixupDeviceInfoForMapping(int fd, struct input_id *inpid)
     1.9 +{
    1.10 +    if (inpid->vendor == 0x045e && inpid->product == 0x0b05 && inpid->version == 0x0903) {
    1.11 +        /* This is a Microsoft Xbox One Elite Series 2 controller */
    1.12 +        unsigned long keybit[NBITS(KEY_MAX)] = { 0 };
    1.13 +
    1.14 +        /* The first version of the firmware duplicated all the inputs */
    1.15 +        if ((ioctl(fd, EVIOCGBIT(EV_KEY, sizeof(keybit)), keybit) >= 0) &&
    1.16 +            test_bit(0x2c0, keybit)) {
    1.17 +            /* Change the version to 0x0902, so we can map it differently */
    1.18 +            inpid->version = 0x0902;
    1.19 +        }
    1.20 +    }
    1.21 +}
    1.22 +
    1.23 +
    1.24  static int
    1.25  IsJoystick(int fd, char *namebuf, const size_t namebuflen, SDL_JoystickGUID *guid)
    1.26  {
    1.27 @@ -157,6 +174,8 @@
    1.28      }
    1.29  #endif
    1.30  
    1.31 +    FixupDeviceInfoForMapping(fd, &inpid);
    1.32 +
    1.33  #ifdef DEBUG_JOYSTICK
    1.34      printf("Joystick: %s, bustype = %d, vendor = 0x%.4x, product = 0x%.4x, version = %d\n", namebuf, inpid.bustype, inpid.vendor, inpid.product, inpid.version);
    1.35  #endif
    1.36 @@ -819,6 +838,9 @@
    1.37              joystick->hwdata->effect_expiration = 1;
    1.38          }
    1.39      } else {
    1.40 +        if (!joystick->hwdata->effect_expiration) {
    1.41 +            return 0;
    1.42 +        }
    1.43          joystick->hwdata->effect_expiration = 0;
    1.44      }
    1.45