From aa03b9d7afedefddda4e7f1575d87865ee5f3d93 Mon Sep 17 00:00:00 2001 From: Sam Lantinga Date: Tue, 22 Nov 2016 22:14:28 -0800 Subject: [PATCH] The XBox One S controller sends keys outside the standard joystick button range --- src/joystick/SDL_gamecontrollerdb.h | 1 - src/joystick/linux/SDL_sysjoystick.c | 15 ++++++--------- src/joystick/linux/SDL_sysjoystick_c.h | 2 +- 3 files changed, 7 insertions(+), 11 deletions(-) diff --git a/src/joystick/SDL_gamecontrollerdb.h b/src/joystick/SDL_gamecontrollerdb.h index 927bd3b5910f9..a9fde0dc1eb51 100644 --- a/src/joystick/SDL_gamecontrollerdb.h +++ b/src/joystick/SDL_gamecontrollerdb.h @@ -104,7 +104,6 @@ static const char *s_ControllerMappings [] = "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,", "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,", - "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,", "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__) diff --git a/src/joystick/linux/SDL_sysjoystick.c b/src/joystick/linux/SDL_sysjoystick.c index 1621474d020d2..6d46e1073d609 100644 --- a/src/joystick/linux/SDL_sysjoystick.c +++ b/src/joystick/linux/SDL_sysjoystick.c @@ -449,16 +449,16 @@ ConfigJoystick(SDL_Joystick * joystick, int fd) #ifdef DEBUG_INPUT_EVENTS printf("Joystick has button: 0x%x\n", i); #endif - joystick->hwdata->key_map[i - BTN_MISC] = joystick->nbuttons; + joystick->hwdata->key_map[i] = joystick->nbuttons; ++joystick->nbuttons; } } - for (i = BTN_MISC; i < BTN_JOYSTICK; ++i) { + for (i = 0; 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->hwdata->key_map[i] = joystick->nbuttons; ++joystick->nbuttons; } } @@ -715,12 +715,9 @@ HandleInputEvents(SDL_Joystick * joystick) 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); - } + SDL_PrivateJoystickButton(joystick, + joystick->hwdata->key_map[code], + events[i].value); break; case EV_ABS: switch (code) { diff --git a/src/joystick/linux/SDL_sysjoystick_c.h b/src/joystick/linux/SDL_sysjoystick_c.h index ee77178399356..18fb8fdfc91b0 100644 --- a/src/joystick/linux/SDL_sysjoystick_c.h +++ b/src/joystick/linux/SDL_sysjoystick_c.h @@ -43,7 +43,7 @@ struct joystick_hwdata } *balls; /* Support for the Linux 2.4 unified input interface */ - Uint8 key_map[KEY_MAX - BTN_MISC]; + Uint8 key_map[KEY_MAX]; Uint8 abs_map[ABS_MAX]; struct axis_correct {