SDL: Fix Steam Controller 2 touchpad finger detection (#15644) (d147b)

From d147bb2a06c2166bae79e44aed974ee71e6ed99b Mon Sep 17 00:00:00 2001
From: Kuratius <[EMAIL REDACTED]>
Date: Mon, 18 May 2026 16:03:56 +0200
Subject: [PATCH] Fix Steam Controller 2 touchpad finger detection (#15644)

(cherry picked from commit a20530cf15e1edf9d1444263a03e1fe44731c691)
---
 src/joystick/hidapi/SDL_hidapi_steam_triton.c | 45 ++++++++++++++-----
 1 file changed, 34 insertions(+), 11 deletions(-)

diff --git a/src/joystick/hidapi/SDL_hidapi_steam_triton.c b/src/joystick/hidapi/SDL_hidapi_steam_triton.c
index f1c58812291fd..5c64c8e2203c4 100644
--- a/src/joystick/hidapi/SDL_hidapi_steam_triton.c
+++ b/src/joystick/hidapi/SDL_hidapi_steam_triton.c
@@ -107,6 +107,13 @@ typedef struct
     Uint16 low_frequency_rumble;
     Uint16 high_frequency_rumble;
     Uint64 last_rumble_time;
+
+    bool left_touch_down;
+    float left_touch_x;
+    float left_touch_y;
+    bool right_touch_down;
+    float right_touch_x;
+    float right_touch_y;
 } SDL_DriverSteamTriton_Context;
 
 static bool IsProteusDongle(Uint16 product_id)
@@ -247,17 +254,33 @@ static void HIDAPI_DriverSteamTriton_HandleState(SDL_HIDAPI_Device *device,
         ctx->last_sensor_tick = pTritonReport->imu.timestamp;
     }
 
-    SDL_SendJoystickTouchpad(timestamp, joystick, 0, 0,
-                             pTritonReport->sPressureLeft > 0,
-                             pTritonReport->sLeftPadX / 65536.0f + 0.5f,
-                             -(float)pTritonReport->sLeftPadY / 65536.0f + 0.5f,
-                             pTritonReport->sPressureLeft / 32768.0f);
-
-    SDL_SendJoystickTouchpad(timestamp, joystick, 1, 0,
-                             pTritonReport->sPressureRight > 0,
-                             pTritonReport->sRightPadX / 65536.0f + 0.5f,
-                             -(float)pTritonReport->sRightPadY / 65536.0f + 0.5f,
-                             pTritonReport->sPressureRight / 32768.0f);
+    bool left_touch_down = (pTritonReport->buttons & TRITON_LEFT_TOUCHPAD_TOUCH) ? true : false;
+    bool right_touch_down = (pTritonReport->buttons & TRITON_RIGHT_TOUCHPAD_TOUCH) ? true : false;
+    if (left_touch_down || ctx->left_touch_down) {
+        if (left_touch_down) {
+            ctx->left_touch_x = pTritonReport->sLeftPadX / 65536.0f + 0.5f;
+            ctx->left_touch_y = -(float)pTritonReport->sLeftPadY / 65536.0f + 0.5f;
+
+        }
+        SDL_SendJoystickTouchpad(timestamp, joystick, 0, 0,
+                                 left_touch_down,
+                                 ctx->left_touch_x,
+                                 ctx->left_touch_y,
+                                 pTritonReport->sPressureLeft / 32768.0f);
+        ctx->left_touch_down = left_touch_down;
+    }
+    if (right_touch_down || ctx->right_touch_down) {
+        if (right_touch_down) {
+            ctx->right_touch_x = pTritonReport->sRightPadX / 65536.0f + 0.5f;
+            ctx->right_touch_y = -(float)pTritonReport->sRightPadY / 65536.0f + 0.5f;
+        }
+        SDL_SendJoystickTouchpad(timestamp, joystick, 1, 0,
+                                 right_touch_down,
+                                 ctx->right_touch_x,
+                                 ctx->right_touch_y,
+                                 pTritonReport->sPressureRight / 32768.0f);
+        ctx->right_touch_down = right_touch_down;
+    }
 }
 
 static void HIDAPI_DriverSteamTriton_HandleBatteryStatus(SDL_HIDAPI_Device *device,