The XBox One S controller sends keys outside the standard joystick button range
authorSam Lantinga <slouken@libsdl.org>
Tue, 22 Nov 2016 22:14:28 -0800
changeset 10641ae818421bb1f
parent 10640 2e0704a41e5a
child 10642 8a420b80310a
The XBox One S controller sends keys outside the standard joystick button range
src/joystick/SDL_gamecontrollerdb.h
src/joystick/linux/SDL_sysjoystick.c
src/joystick/linux/SDL_sysjoystick_c.h
     1.1 --- a/src/joystick/SDL_gamecontrollerdb.h	Tue Nov 22 04:42:07 2016 -0800
     1.2 +++ b/src/joystick/SDL_gamecontrollerdb.h	Tue Nov 22 22:14:28 2016 -0800
     1.3 @@ -104,7 +104,6 @@
     1.4      "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,",
     1.5      "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,",
     1.6      "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,",
     1.7 -    "050000005e040000fd02000003090000,Xbox One Wireless Controller,a:b0,b:b1,dpdown:h0.4,dpleft:h0.8,dpright:h0.2,dpup:h0.1,leftshoulder:b6,leftstick:b13,lefttrigger:a5,leftx:a0,lefty:a1,rightshoulder:b7,rightstick:b14,righttrigger:a4,rightx:a2,righty:a3,start:b11,x:b3,y:b4,",
     1.8      "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,",
     1.9  #endif
    1.10  #if defined(__ANDROID__)
     2.1 --- a/src/joystick/linux/SDL_sysjoystick.c	Tue Nov 22 04:42:07 2016 -0800
     2.2 +++ b/src/joystick/linux/SDL_sysjoystick.c	Tue Nov 22 22:14:28 2016 -0800
     2.3 @@ -449,16 +449,16 @@
     2.4  #ifdef DEBUG_INPUT_EVENTS
     2.5                  printf("Joystick has button: 0x%x\n", i);
     2.6  #endif
     2.7 -                joystick->hwdata->key_map[i - BTN_MISC] = joystick->nbuttons;
     2.8 +                joystick->hwdata->key_map[i] = joystick->nbuttons;
     2.9                  ++joystick->nbuttons;
    2.10              }
    2.11          }
    2.12 -        for (i = BTN_MISC; i < BTN_JOYSTICK; ++i) {
    2.13 +        for (i = 0; i < BTN_JOYSTICK; ++i) {
    2.14              if (test_bit(i, keybit)) {
    2.15  #ifdef DEBUG_INPUT_EVENTS
    2.16                  printf("Joystick has button: 0x%x\n", i);
    2.17  #endif
    2.18 -                joystick->hwdata->key_map[i - BTN_MISC] = joystick->nbuttons;
    2.19 +                joystick->hwdata->key_map[i] = joystick->nbuttons;
    2.20                  ++joystick->nbuttons;
    2.21              }
    2.22          }
    2.23 @@ -715,12 +715,9 @@
    2.24              code = events[i].code;
    2.25              switch (events[i].type) {
    2.26              case EV_KEY:
    2.27 -                if (code >= BTN_MISC) {
    2.28 -                    code -= BTN_MISC;
    2.29 -                    SDL_PrivateJoystickButton(joystick,
    2.30 -                                              joystick->hwdata->key_map[code],
    2.31 -                                              events[i].value);
    2.32 -                }
    2.33 +                SDL_PrivateJoystickButton(joystick,
    2.34 +                                          joystick->hwdata->key_map[code],
    2.35 +                                          events[i].value);
    2.36                  break;
    2.37              case EV_ABS:
    2.38                  switch (code) {
     3.1 --- a/src/joystick/linux/SDL_sysjoystick_c.h	Tue Nov 22 04:42:07 2016 -0800
     3.2 +++ b/src/joystick/linux/SDL_sysjoystick_c.h	Tue Nov 22 22:14:28 2016 -0800
     3.3 @@ -43,7 +43,7 @@
     3.4      } *balls;
     3.5  
     3.6      /* Support for the Linux 2.4 unified input interface */
     3.7 -    Uint8 key_map[KEY_MAX - BTN_MISC];
     3.8 +    Uint8 key_map[KEY_MAX];
     3.9      Uint8 abs_map[ABS_MAX];
    3.10      struct axis_correct
    3.11      {