SDL: capture g27 shifter r input

From 15c6acf74f1f5885f52142c9405a5173476d1c6f Mon Sep 17 00:00:00 2001
From: Katharine Chui <[EMAIL REDACTED]>
Date: Sat, 3 May 2025 15:36:17 +0200
Subject: [PATCH] capture g27 shifter r input

ref: https://github.com/sonik-br/lgff_wheel_adapter/blob/d97f7823154818e1b3edff6d51498a122c302728/pico_lgff_wheel_adapter/reports.h#L265-L310
---
 src/joystick/hidapi/SDL_hidapi_lg4ff.c | 15 ++++++++++++++-
 1 file changed, 14 insertions(+), 1 deletion(-)

diff --git a/src/joystick/hidapi/SDL_hidapi_lg4ff.c b/src/joystick/hidapi/SDL_hidapi_lg4ff.c
index 84378d795fb67..901911985f510 100644
--- a/src/joystick/hidapi/SDL_hidapi_lg4ff.c
+++ b/src/joystick/hidapi/SDL_hidapi_lg4ff.c
@@ -75,7 +75,7 @@ static int HIDAPI_DriverLg4ff_GetNumberOfButtons(Uint32 device_id)
         case USB_DEVICE_ID_LOGITECH_G29_WHEEL:
             return 25;
         case USB_DEVICE_ID_LOGITECH_G27_WHEEL:
-            return 22;
+            return 23;
         case USB_DEVICE_ID_LOGITECH_G25_WHEEL:
             return 19;
         case USB_DEVICE_ID_LOGITECH_DFGT_WHEEL:
@@ -647,6 +647,19 @@ static bool HIDAPI_DriverLg4ff_HandleState(SDL_HIDAPI_Device *device,
             SDL_assert(0);
     }
 
+    if (device->product_id == USB_DEVICE_ID_LOGITECH_G27_WHEEL) {
+        // ref https://github.com/sonik-br/lgff_wheel_adapter/blob/d97f7823154818e1b3edff6d51498a122c302728/pico_lgff_wheel_adapter/reports.h#L265-L310
+        // shifter_r is outside of the main button bit field for this particular wheel
+        num_buttons--;
+
+        bool button_on = HIDAPI_DriverLg4ff_GetBit(report_buf, 80, report_size);
+        bool button_was_on = HIDAPI_DriverLg4ff_GetBit(ctx->last_report_buf, 80, report_size);
+        if (button_on != button_was_on) {
+            state_changed = true;
+            SDL_SendJoystickButton(timestamp, joystick, (Uint8)(SDL_GAMEPAD_BUTTON_SOUTH + num_buttons), button_on);
+        }
+    }
+
     for (int i = 0;i < num_buttons;i++) {
         int bit_num = bit_offset + i;
         bool button_on = HIDAPI_DriverLg4ff_GetBit(report_buf, bit_num, report_size);