SDL: Fixed PlayStation detection interrupting input for the Logitech K400 keyboard

From b6d7adfec11c355cdbb5ebde26ed5a5c958ce489 Mon Sep 17 00:00:00 2001
From: Sam Lantinga <[EMAIL REDACTED]>
Date: Wed, 5 Jun 2024 19:11:10 -0700
Subject: [PATCH] Fixed PlayStation detection interrupting input for the
 Logitech K400 keyboard

Also added the Logitech Chillstream to the list of PS3 controllers and fixed the right shoulder axis.
---
 src/joystick/controller_list.h           |  1 +
 src/joystick/hidapi/SDL_hidapi_ps3.c     |  7 ++++++-
 src/joystick/hidapi/SDL_hidapijoystick.c | 24 ++++++++++--------------
 3 files changed, 17 insertions(+), 15 deletions(-)

diff --git a/src/joystick/controller_list.h b/src/joystick/controller_list.h
index 59421a728487f..c620837846998 100644
--- a/src/joystick/controller_list.h
+++ b/src/joystick/controller_list.h
@@ -24,6 +24,7 @@ static const ControllerDescription_t arrControllers[] = {
 	{ MAKE_CONTROLLER_ID( 0x0079, 0x1844 ), k_eControllerType_PS3Controller, NULL },	// From SDL
 	{ MAKE_CONTROLLER_ID( 0x044f, 0xb315 ), k_eControllerType_PS3Controller, NULL },	// Firestorm Dual Analog 3
 	{ MAKE_CONTROLLER_ID( 0x044f, 0xd007 ), k_eControllerType_PS3Controller, NULL },	// Thrustmaster wireless 3-1
+	{ MAKE_CONTROLLER_ID( 0x046d, 0xcad1 ), k_eControllerType_PS3Controller, NULL },	// Logitech Chillstream
 	//{ MAKE_CONTROLLER_ID( 0x046d, 0xc24f ), k_eControllerType_PS3Controller, NULL },	// Logitech G29 (PS3)
 	{ MAKE_CONTROLLER_ID( 0x054c, 0x0268 ), k_eControllerType_PS3Controller, NULL },	// Sony PS3 Controller
 	{ MAKE_CONTROLLER_ID( 0x056e, 0x200f ), k_eControllerType_PS3Controller, NULL },	// From SDL
diff --git a/src/joystick/hidapi/SDL_hidapi_ps3.c b/src/joystick/hidapi/SDL_hidapi_ps3.c
index 77440f60d5a24..b3550ab73126b 100644
--- a/src/joystick/hidapi/SDL_hidapi_ps3.c
+++ b/src/joystick/hidapi/SDL_hidapi_ps3.c
@@ -619,6 +619,11 @@ static SDL_bool HIDAPI_DriverPS3ThirdParty_IsSupportedDevice(SDL_HIDAPI_Device *
     Uint8 data[USB_PACKET_LENGTH];
     int size;
 
+    if (vendor_id == USB_VENDOR_LOGITECH &&
+        product_id == USB_PRODUCT_LOGITECH_CHILLSTREAM) {
+        return SDL_TRUE;
+    }
+
     if ((type == SDL_GAMEPAD_TYPE_PS3 && vendor_id != USB_VENDOR_SONY) ||
         HIDAPI_SupportsPlaystationDetection(vendor_id, product_id)) {
         if (device && device->dev) {
@@ -795,7 +800,7 @@ static void HIDAPI_DriverPS3ThirdParty_HandleStatePacket18(SDL_Joystick *joystic
             0,  /* SDL_GAMEPAD_BUTTON_LEFT_STICK */
             0,  /* SDL_GAMEPAD_BUTTON_RIGHT_STICK */
             14, /* SDL_GAMEPAD_BUTTON_LEFT_SHOULDER */
-            16, /* SDL_GAMEPAD_BUTTON_RIGHT_SHOULDER */
+            15, /* SDL_GAMEPAD_BUTTON_RIGHT_SHOULDER */
             8,  /* SDL_GAMEPAD_BUTTON_DPAD_UP */
             9,  /* SDL_GAMEPAD_BUTTON_DPAD_DOWN */
             7,  /* SDL_GAMEPAD_BUTTON_DPAD_LEFT */
diff --git a/src/joystick/hidapi/SDL_hidapijoystick.c b/src/joystick/hidapi/SDL_hidapijoystick.c
index cdd6de9883279..0606b1a558083 100644
--- a/src/joystick/hidapi/SDL_hidapijoystick.c
+++ b/src/joystick/hidapi/SDL_hidapijoystick.c
@@ -152,16 +152,12 @@ SDL_bool HIDAPI_SupportsPlaystationDetection(Uint16 vendor, Uint16 product)
     case USB_VENDOR_HORI:
         return SDL_TRUE;
     case USB_VENDOR_LOGITECH:
-        /* Most Logitech devices are fine with this, but there are a few exceptions */
-        if (product == USB_PRODUCT_LOGITECH_F310) {
-            /* The Logitech F310 gamepad will lock up */
-            return SDL_FALSE;
-        }
-        if (product == 0xc33f) {
-            /* The Logitech G815 keyboard will reset the LEDs */
-            return SDL_FALSE;
-        }
-        return SDL_TRUE;
+        /* Most Logitech devices are not PlayStation controllers, and some of them
+         * lock up or reset when we send them the Sony third-party query feature
+         * report, so don't include that vendor here. Instead add devices as
+         * appropriate to controller_list.h
+         */
+        return SDL_FALSE;
     case USB_VENDOR_MADCATZ:
         if (product == USB_PRODUCT_MADCATZ_SAITEK_SIDE_PANEL_CONTROL_DECK) {
             /* This is not a Playstation compatible device */
@@ -182,10 +178,10 @@ SDL_bool HIDAPI_SupportsPlaystationDetection(Uint16 vendor, Uint16 product)
     case USB_VENDOR_QANBA:
         return SDL_TRUE;
     case USB_VENDOR_RAZER:
-        /* Most Razer devices are not game controllers, and some of them lock up
-         * or reset when we send them the Sony third-party query feature report,
-         * so don't include that vendor here. Instead add devices as appropriate
-         * to controller_list.h
+        /* Most Razer devices are not PlayStation controllers, and some of them
+         * lock up or reset when we send them the Sony third-party query feature
+         * report, so don't include that vendor here. Instead add devices as
+         * appropriate to controller_list.h
          *
          * Reference: https://github.com/libsdl-org/SDL/issues/6733
          *            https://github.com/libsdl-org/SDL/issues/6799