فهرست منبع

gameinput: only add the share button for known Xbox Series X controllers

The HID descriptor for the latest firmware always includes the share button, and GameInput will report it as always available, so double check against our list of classic Xbox One controllers and don't include the button on controllers that don't have it.
Sam Lantinga 3 روز پیش
والد
کامیت
aeacf42e06
1فایلهای تغییر یافته به همراه12 افزوده شده و 3 حذف شده
  1. 12 3
      src/joystick/gdk/SDL_gameinputjoystick.cpp

+ 12 - 3
src/joystick/gdk/SDL_gameinputjoystick.cpp

@@ -49,6 +49,8 @@ typedef struct GAMEINPUT_InternalDevice
     SDL_GUID guid;          // generated by SDL
     SDL_GUID guid;          // generated by SDL
     SDL_JoystickID device_instance; // generated by SDL
     SDL_JoystickID device_instance; // generated by SDL
     const GameInputDeviceInfo *info;
     const GameInputDeviceInfo *info;
+    Uint16 vendor;
+    Uint16 product;
     int raw_type;
     int raw_type;
     int steam_virtual_gamepad_slot;
     int steam_virtual_gamepad_slot;
     bool isAdded;
     bool isAdded;
@@ -279,6 +281,8 @@ static bool GAMEINPUT_InternalAddOrFind(IGameInputDevice *pDevice)
     elem->guid = SDL_CreateJoystickGUID(bus, vendor, product, version, NULL, product_string, driver_signature, subtype);
     elem->guid = SDL_CreateJoystickGUID(bus, vendor, product, version, NULL, product_string, driver_signature, subtype);
     elem->device_instance = SDL_GetNextObjectID();
     elem->device_instance = SDL_GetNextObjectID();
     elem->info = info;
     elem->info = info;
+    elem->vendor = vendor;
+    elem->product = product;
     elem->raw_type = raw_type;
     elem->raw_type = raw_type;
 #if GAMEINPUT_API_VERSION >= 1
 #if GAMEINPUT_API_VERSION >= 1
     elem->steam_virtual_gamepad_slot = GetSteamVirtualGamepadSlot(info->pnpPath);
     elem->steam_virtual_gamepad_slot = GetSteamVirtualGamepadSlot(info->pnpPath);
@@ -609,11 +613,15 @@ static bool GAMEINPUT_JoystickOpen(SDL_Joystick *joystick, int device_index)
 
 
 #if GAMEINPUT_API_VERSION >= 1
 #if GAMEINPUT_API_VERSION >= 1
         if (info->supportedSystemButtons != GameInputSystemButtonNone) {
         if (info->supportedSystemButtons != GameInputSystemButtonNone) {
-            if (info->supportedSystemButtons & GameInputSystemButtonShare) {
+            GameInputSystemButtons buttons = GameInputSystemButtonGuide;
+
+            if (SDL_IsJoystickXboxSeriesX(elem->vendor, elem->product) &&
+                (info->supportedSystemButtons & GameInputSystemButtonShare)) {
                 ++joystick->nbuttons;
                 ++joystick->nbuttons;
+                buttons |= GameInputSystemButtonShare;
             }
             }
 
 
-            g_pGameInput->RegisterSystemButtonCallback(elem->device, (GameInputSystemButtonGuide | GameInputSystemButtonShare), joystick, GAMEINPUT_InternalSystemButtonCallback, &hwdata->system_button_callback_token);
+            g_pGameInput->RegisterSystemButtonCallback(elem->device, buttons, joystick, GAMEINPUT_InternalSystemButtonCallback, &hwdata->system_button_callback_token);
         }
         }
 #endif // GAMEINPUT_API_VERSION >= 1
 #endif // GAMEINPUT_API_VERSION >= 1
     } else {
     } else {
@@ -990,7 +998,8 @@ static bool GAMEINPUT_JoystickGetGamepadMapping(int device_index, SDL_GamepadMap
         out->guide.target = SDL_GAMEPAD_BUTTON_GUIDE;
         out->guide.target = SDL_GAMEPAD_BUTTON_GUIDE;
     }
     }
 
 
-    if (elem->info->supportedSystemButtons & GameInputSystemButtonShare) {
+    if (SDL_IsJoystickXboxSeriesX(elem->vendor, elem->product) &&
+        (elem->info->supportedSystemButtons & GameInputSystemButtonShare)) {
         out->misc1.kind = EMappingKind_Button;
         out->misc1.kind = EMappingKind_Button;
         out->misc1.target = SDL_GAMEPAD_BUTTON_GAMEINPUT_SHARE;
         out->misc1.target = SDL_GAMEPAD_BUTTON_GAMEINPUT_SHARE;
     }
     }