From a5dba7d3ab2bcdefb2dc9e590767bf345a81dfa5 Mon Sep 17 00:00:00 2001 From: Sam Lantinga Date: Fri, 8 Jan 2021 09:54:52 -0800 Subject: [PATCH] Fixed Xbox One Series X share button incorrectly triggering on newer firmware --- build-scripts/config.guess | 0 build-scripts/config.sub | 0 src/joystick/hidapi/SDL_hidapi_xboxone.c | 20 ++++++++++++-------- 3 files changed, 12 insertions(+), 8 deletions(-) mode change 100755 => 100644 build-scripts/config.guess mode change 100755 => 100644 build-scripts/config.sub diff --git a/build-scripts/config.guess b/build-scripts/config.guess old mode 100755 new mode 100644 diff --git a/build-scripts/config.sub b/build-scripts/config.sub old mode 100755 new mode 100644 diff --git a/src/joystick/hidapi/SDL_hidapi_xboxone.c b/src/joystick/hidapi/SDL_hidapi_xboxone.c index 22a89c2eb..0b467dfd8 100644 --- a/src/joystick/hidapi/SDL_hidapi_xboxone.c +++ b/src/joystick/hidapi/SDL_hidapi_xboxone.c @@ -488,14 +488,18 @@ HIDAPI_DriverXboxOne_HandleStatePacket(SDL_Joystick *joystick, SDL_DriverXboxOne } if (ctx->has_share_button) { - /* Version 1 of the firmware for Xbox One Series X */ - if (ctx->last_state[18] != data[18]) { - SDL_PrivateJoystickButton(joystick, SDL_CONTROLLER_BUTTON_MISC1, (data[18] & 0x01) ? SDL_PRESSED : SDL_RELEASED); - } - - /* Version 2 of the firmware for Xbox One Series X */ - if (ctx->last_state[22] != data[22]) { - SDL_PrivateJoystickButton(joystick, SDL_CONTROLLER_BUTTON_MISC1, (data[22] & 0x01) ? SDL_PRESSED : SDL_RELEASED); + /* Xbox Series X firmware version 5.0, report is 36 bytes, share button is in byte 18 + * Xbox Series X firmware version 5.1, report is 44 bytes, share button is in byte 18 + * Xbox Series X firmware version 5.5, report is 48 bytes, share button is in byte 22 + */ + if (size < 48) { + if (ctx->last_state[18] != data[18]) { + SDL_PrivateJoystickButton(joystick, SDL_CONTROLLER_BUTTON_MISC1, (data[18] & 0x01) ? SDL_PRESSED : SDL_RELEASED); + } + } else { + if (ctx->last_state[22] != data[22]) { + SDL_PrivateJoystickButton(joystick, SDL_CONTROLLER_BUTTON_MISC1, (data[22] & 0x01) ? SDL_PRESSED : SDL_RELEASED); + } } }