mirror of
https://github.com/libsdl-org/SDL.git
synced 2026-01-07 05:43:18 +00:00
Added Steam Virtual Gamepad support to the GameInput driver
(cherry picked from commit 66dad9c21f)
This commit is contained in:
@@ -46,6 +46,7 @@ typedef struct GAMEINPUT_InternalDevice
|
||||
SDL_GUID guid; // generated by SDL
|
||||
SDL_JoystickID device_instance; // generated by SDL
|
||||
const GameInputDeviceInfo *info;
|
||||
int steam_virtual_gamepad_slot;
|
||||
bool isAdded;
|
||||
bool isDeleteRequested;
|
||||
} GAMEINPUT_InternalDevice;
|
||||
@@ -77,6 +78,16 @@ static bool GAMEINPUT_InternalIsGamepad(const GameInputDeviceInfo *info)
|
||||
return false;
|
||||
}
|
||||
|
||||
static int GetSteamVirtualGamepadSlot(const char *device_path)
|
||||
{
|
||||
int slot = -1;
|
||||
|
||||
// The format for the raw input device path is documented here:
|
||||
// https://partner.steamgames.com/doc/features/steam_controller/steam_input_gamepad_emulation_bestpractices
|
||||
(void)SDL_sscanf(device_path, "\\\\.\\pipe\\HID#VID_045E&PID_028E&IG_00#%*X&%*X&%*X#%d#%*u", &slot);
|
||||
return slot;
|
||||
}
|
||||
|
||||
static bool GAMEINPUT_InternalAddOrFind(IGameInputDevice *pDevice)
|
||||
{
|
||||
GAMEINPUT_InternalDevice **devicelist = NULL;
|
||||
@@ -147,6 +158,7 @@ static bool GAMEINPUT_InternalAddOrFind(IGameInputDevice *pDevice)
|
||||
elem->guid = SDL_CreateJoystickGUID(bus, vendor, product, version, manufacturer_string, product_string, 'g', 0);
|
||||
elem->device_instance = SDL_GetNextObjectID();
|
||||
elem->info = info;
|
||||
elem->steam_virtual_gamepad_slot = GetSteamVirtualGamepadSlot(info->pnpPath);
|
||||
|
||||
g_GameInputList.devices = devicelist;
|
||||
g_GameInputList.devices[g_GameInputList.count++] = elem;
|
||||
@@ -333,7 +345,7 @@ static const char *GAMEINPUT_JoystickGetDevicePath(int device_index)
|
||||
|
||||
static int GAMEINPUT_JoystickGetDeviceSteamVirtualGamepadSlot(int device_index)
|
||||
{
|
||||
return -1;
|
||||
return GAMEINPUT_InternalFindByIndex(device_index)->steam_virtual_gamepad_slot;
|
||||
}
|
||||
|
||||
static int GAMEINPUT_JoystickGetDevicePlayerIndex(int device_index)
|
||||
|
||||
Reference in New Issue
Block a user