Skip to content

Commit

Permalink
Work in progress
Browse files Browse the repository at this point in the history
  • Loading branch information
slouken committed Dec 17, 2023
1 parent 4d5949d commit c5eea0f
Show file tree
Hide file tree
Showing 21 changed files with 162 additions and 2 deletions.
5 changes: 4 additions & 1 deletion src/joystick/SDL_joystick.c
Original file line number Diff line number Diff line change
Expand Up @@ -1921,7 +1921,10 @@ void SDL_PrivateJoystickAdded(SDL_JoystickID instance_id)
SDL_joystick_being_added = SDL_TRUE;

if (SDL_GetDriverAndJoystickIndex(instance_id, &driver, &device_index)) {
player_index = driver->GetDevicePlayerIndex(device_index);
player_index = driver->GetDeviceSteamVirtualGamepadSlot(device_index);
if (player_index < 0) {
player_index = driver->GetDevicePlayerIndex(device_index);
}
}
if (player_index < 0 && SDL_IsGamepad(instance_id)) {
player_index = SDL_FindFreePlayerIndex();
Expand Down
22 changes: 22 additions & 0 deletions src/joystick/SDL_steam_virtual_gamepad.c
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
/*
Simple DirectMedia Layer
Copyright (C) 1997-2023 Sam Lantinga <[email protected]>
This software is provided 'as-is', without any express or implied
warranty. In no event will the authors be held liable for any damages
arising from the use of this software.
Permission is granted to anyone to use this software for any purpose,
including commercial applications, and to alter it and redistribute it
freely, subject to the following restrictions:
1. The origin of this software must not be misrepresented; you must not
claim that you wrote the original software. If you use this software
in a product, an acknowledgment in the product documentation would be
appreciated but is not required.
2. Altered source versions must be plainly marked as such, and must not be
misrepresented as being the original software.
3. This notice may not be removed or altered from any source distribution.
*/
#include "SDL_internal.h"

26 changes: 26 additions & 0 deletions src/joystick/SDL_steam_virtual_gamepad.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
/*
Simple DirectMedia Layer
Copyright (C) 1997-2023 Sam Lantinga <[email protected]>
This software is provided 'as-is', without any express or implied
warranty. In no event will the authors be held liable for any damages
arising from the use of this software.
Permission is granted to anyone to use this software for any purpose,
including commercial applications, and to alter it and redistribute it
freely, subject to the following restrictions:
1. The origin of this software must not be misrepresented; you must not
claim that you wrote the original software. If you use this software
in a product, an acknowledgment in the product documentation would be
appreciated but is not required.
2. Altered source versions must be plainly marked as such, and must not be
misrepresented as being the original software.
3. This notice may not be removed or altered from any source distribution.
*/
#include "SDL_internal.h"

void SDL_UpdateSteamVirtualGamepadInfo(void);
Uint16 SDL_GetSteamVirtualGamepadVID(int slot);
Uint16 SDL_GetSteamVirtualGamepadPID(int slot);
const char *SDL_GetSteamVirtualGamepadName(int slot);
4 changes: 4 additions & 0 deletions src/joystick/SDL_sysjoystick.h
Original file line number Diff line number Diff line change
Expand Up @@ -77,6 +77,7 @@ struct SDL_Joystick
char *serial _guarded; /* Joystick serial */
SDL_JoystickGUID guid _guarded; /* Joystick guid */
Uint16 firmware_version _guarded; /* Firmware version, if available */
int steam_virtual_gamepad_slot _guarded; /* Steam virtual gamepad slot */

int naxes _guarded; /* Number of axis controls on the joystick */
SDL_JoystickAxisInfo *axes _guarded;
Expand Down Expand Up @@ -168,6 +169,9 @@ typedef struct SDL_JoystickDriver
/* Function to get the device-dependent path of a joystick */
const char *(*GetDevicePath)(int device_index);

/* Function to get the Steam virtual gamepad slot of a joystick */
int (*GetDeviceSteamVirtualGamepadSlot)(int device_index);

/* Function to get the player index of a joystick */
int (*GetDevicePlayerIndex)(int device_index);

Expand Down
6 changes: 6 additions & 0 deletions src/joystick/android/SDL_sysjoystick.c
Original file line number Diff line number Diff line change
Expand Up @@ -541,6 +541,11 @@ static const char *ANDROID_JoystickGetDevicePath(int device_index)
return NULL;
}

static int ANDROID_JoystickGetDeviceSteamVirtualGamepadSlot(int device_index)
{
return -1;
}

static int ANDROID_JoystickGetDevicePlayerIndex(int device_index)
{
return -1;
Expand Down Expand Up @@ -681,6 +686,7 @@ SDL_JoystickDriver SDL_ANDROID_JoystickDriver = {
ANDROID_JoystickDetect,
ANDROID_JoystickGetDeviceName,
ANDROID_JoystickGetDevicePath,
ANDROID_JoystickGetDeviceSteamVirtualGamepadSlot,
ANDROID_JoystickGetDevicePlayerIndex,
ANDROID_JoystickSetDevicePlayerIndex,
ANDROID_JoystickGetDeviceGUID,
Expand Down
6 changes: 6 additions & 0 deletions src/joystick/apple/SDL_mfijoystick.m
Original file line number Diff line number Diff line change
Expand Up @@ -898,6 +898,11 @@ static void IOS_JoystickDetect(void)
return NULL;
}

static int IOS_JoystickGetDeviceSteamVirtualGamepadSlot(int device_index)
{
return -1;
}

static int IOS_JoystickGetDevicePlayerIndex(int device_index)
{
#ifdef SDL_JOYSTICK_MFI
Expand Down Expand Up @@ -2165,6 +2170,7 @@ static void GetAppleSFSymbolsNameForElement(GCControllerElement *element, char *
IOS_JoystickDetect,
IOS_JoystickGetDeviceName,
IOS_JoystickGetDevicePath,
IOS_JoystickGetDeviceSteamVirtualGamepadSlot,
IOS_JoystickGetDevicePlayerIndex,
IOS_JoystickSetDevicePlayerIndex,
IOS_JoystickGetDeviceGUID,
Expand Down
6 changes: 6 additions & 0 deletions src/joystick/bsd/SDL_bsdjoystick.c
Original file line number Diff line number Diff line change
Expand Up @@ -543,6 +543,11 @@ static const char *BSD_JoystickGetDevicePath(int device_index)
return GetJoystickByDevIndex(device_index)->path;
}

static int BSD_JoystickGetDeviceSteamVirtualGamepadSlot(int device_index)
{
return -1;
}

static int BSD_JoystickGetDevicePlayerIndex(int device_index)
{
return -1;
Expand Down Expand Up @@ -850,6 +855,7 @@ SDL_JoystickDriver SDL_BSD_JoystickDriver = {
BSD_JoystickDetect,
BSD_JoystickGetDeviceName,
BSD_JoystickGetDevicePath,
BSD_JoystickGetDeviceSteamVirtualGamepadSlot,
BSD_JoystickGetDevicePlayerIndex,
BSD_JoystickSetDevicePlayerIndex,
BSD_JoystickGetDeviceGUID,
Expand Down
6 changes: 6 additions & 0 deletions src/joystick/darwin/SDL_iokitjoystick.c
Original file line number Diff line number Diff line change
Expand Up @@ -711,6 +711,11 @@ const char *DARWIN_JoystickGetDevicePath(int device_index)
return NULL;
}

static int DARWIN_JoystickGetDeviceSteamVirtualGamepadSlot(int device_index)
{
return -1;
}

static int DARWIN_JoystickGetDevicePlayerIndex(int device_index)
{
return -1;
Expand Down Expand Up @@ -1056,6 +1061,7 @@ SDL_JoystickDriver SDL_DARWIN_JoystickDriver = {
DARWIN_JoystickDetect,
DARWIN_JoystickGetDeviceName,
DARWIN_JoystickGetDevicePath,
DARWIN_JoystickGetDeviceSteamVirtualGamepadSlot,
DARWIN_JoystickGetDevicePlayerIndex,
DARWIN_JoystickSetDevicePlayerIndex,
DARWIN_JoystickGetDeviceGUID,
Expand Down
6 changes: 6 additions & 0 deletions src/joystick/dummy/SDL_sysjoystick.c
Original file line number Diff line number Diff line change
Expand Up @@ -51,6 +51,11 @@ static const char *DUMMY_JoystickGetDevicePath(int device_index)
return NULL;
}

static int DUMMY_JoystickGetDeviceSteamVirtualGamepadSlot(int device_index)
{
return -1;
}

static int DUMMY_JoystickGetDevicePlayerIndex(int device_index)
{
return -1;
Expand Down Expand Up @@ -130,6 +135,7 @@ SDL_JoystickDriver SDL_DUMMY_JoystickDriver = {
DUMMY_JoystickDetect,
DUMMY_JoystickGetDeviceName,
DUMMY_JoystickGetDevicePath,
DUMMY_JoystickGetDeviceSteamVirtualGamepadSlot,
DUMMY_JoystickGetDevicePlayerIndex,
DUMMY_JoystickSetDevicePlayerIndex,
DUMMY_JoystickGetDeviceGUID,
Expand Down
6 changes: 6 additions & 0 deletions src/joystick/emscripten/SDL_sysjoystick.c
Original file line number Diff line number Diff line change
Expand Up @@ -269,6 +269,11 @@ static const char *EMSCRIPTEN_JoystickGetDevicePath(int device_index)
return NULL;
}

static int EMSCRIPTEN_JoystickGetDeviceSteamVirtualGamepadSlot(int device_index)
{
return -1;
}

static int EMSCRIPTEN_JoystickGetDevicePlayerIndex(int device_index)
{
return -1;
Expand Down Expand Up @@ -416,6 +421,7 @@ SDL_JoystickDriver SDL_EMSCRIPTEN_JoystickDriver = {
EMSCRIPTEN_JoystickDetect,
EMSCRIPTEN_JoystickGetDeviceName,
EMSCRIPTEN_JoystickGetDevicePath,
EMSCRIPTEN_JoystickGetDeviceSteamVirtualGamepadSlot,
EMSCRIPTEN_JoystickGetDevicePlayerIndex,
EMSCRIPTEN_JoystickSetDevicePlayerIndex,
EMSCRIPTEN_JoystickGetDeviceGUID,
Expand Down
6 changes: 6 additions & 0 deletions src/joystick/haiku/SDL_haikujoystick.cc
Original file line number Diff line number Diff line change
Expand Up @@ -101,6 +101,11 @@ extern "C"
return SDL_joyport[device_index];
}

static int HAIKU_JoystickGetDeviceSteamVirtualGamepadSlot(int device_index)
{
return -1;
}

static int HAIKU_JoystickGetDevicePlayerIndex(int device_index)
{
return -1;
Expand Down Expand Up @@ -295,6 +300,7 @@ extern "C"
HAIKU_JoystickDetect,
HAIKU_JoystickGetDeviceName,
HAIKU_JoystickGetDevicePath,
HAIKU_JoystickGetDeviceSteamVirtualGamepadSlot,
HAIKU_JoystickGetDevicePlayerIndex,
HAIKU_JoystickSetDevicePlayerIndex,
HAIKU_JoystickGetDeviceGUID,
Expand Down
6 changes: 6 additions & 0 deletions src/joystick/hidapi/SDL_hidapijoystick.c
Original file line number Diff line number Diff line change
Expand Up @@ -1376,6 +1376,11 @@ static const char *HIDAPI_JoystickGetDevicePath(int device_index)
return path;
}

static int HIDAPI_JoystickGetDeviceSteamVirtualGamepadSlot(int device_index)
{
return -1;
}

static int HIDAPI_JoystickGetDevicePlayerIndex(int device_index)
{
SDL_HIDAPI_Device *device;
Expand Down Expand Up @@ -1654,6 +1659,7 @@ SDL_JoystickDriver SDL_HIDAPI_JoystickDriver = {
HIDAPI_JoystickDetect,
HIDAPI_JoystickGetDeviceName,
HIDAPI_JoystickGetDevicePath,
HIDAPI_JoystickGetDeviceSteamVirtualGamepadSlot,
HIDAPI_JoystickGetDevicePlayerIndex,
HIDAPI_JoystickSetDevicePlayerIndex,
HIDAPI_JoystickGetDeviceGUID,
Expand Down
10 changes: 9 additions & 1 deletion src/joystick/linux/SDL_sysjoystick.c
Original file line number Diff line number Diff line change
Expand Up @@ -1116,11 +1116,16 @@ static const char *LINUX_JoystickGetDevicePath(int device_index)
return GetJoystickByDevIndex(device_index)->path;
}

static int LINUX_JoystickGetDevicePlayerIndex(int device_index)
static int LINUX_JoystickGetDeviceSteamVirtualGamepadSlot(int device_index)
{
return GetJoystickByDevIndex(device_index)->steam_virtual_gamepad_slot;
}

static int LINUX_JoystickGetDevicePlayerIndex(int device_index)
{
return -1;
}

static void LINUX_JoystickSetDevicePlayerIndex(int device_index, int player_index)
{
}
Expand Down Expand Up @@ -1600,6 +1605,8 @@ static int LINUX_JoystickOpen(SDL_Joystick *joystick, int device_index)
joystick->hwdata->fd_sensor = -1;
}

joystick->steam_virtual_gamepad_slot = item->steam_virtual_gamepad_slot;

return 0;
}

Expand Down Expand Up @@ -2689,6 +2696,7 @@ SDL_JoystickDriver SDL_LINUX_JoystickDriver = {
LINUX_JoystickDetect,
LINUX_JoystickGetDeviceName,
LINUX_JoystickGetDevicePath,
LINUX_JoystickGetDeviceSteamVirtualGamepadSlot,
LINUX_JoystickGetDevicePlayerIndex,
LINUX_JoystickSetDevicePlayerIndex,
LINUX_JoystickGetDeviceGUID,
Expand Down
6 changes: 6 additions & 0 deletions src/joystick/n3ds/SDL_sysjoystick.c
Original file line number Diff line number Diff line change
Expand Up @@ -231,6 +231,11 @@ static const char *N3DS_JoystickGetDevicePath(int device_index)
return NULL;
}

static int N3DS_JoystickGetDeviceSteamVirtualGamepadSlot(int device_index)
{
return -1;
}

static int N3DS_JoystickGetDevicePlayerIndex(int device_index)
{
return -1;
Expand Down Expand Up @@ -271,6 +276,7 @@ SDL_JoystickDriver SDL_N3DS_JoystickDriver = {
.Detect = N3DS_JoystickDetect,
.GetDeviceName = N3DS_JoystickGetDeviceName,
.GetDevicePath = N3DS_JoystickGetDevicePath,
.GetDeviceSteamVirtualGamepadSlot = N3DS_JoystickGetDeviceSteamVirtualGamepadSlot,
.GetDevicePlayerIndex = N3DS_JoystickGetDevicePlayerIndex,
.SetDevicePlayerIndex = N3DS_JoystickSetDevicePlayerIndex,
.GetDeviceGUID = N3DS_JoystickGetDeviceGUID,
Expand Down
7 changes: 7 additions & 0 deletions src/joystick/ps2/SDL_sysjoystick.c
Original file line number Diff line number Diff line change
Expand Up @@ -157,6 +157,12 @@ static const char *PS2_JoystickGetDevicePath(int index)
return NULL;
}

/* Function to get the Steam virtual gamepad slot of a joystick */
static int PS2_JoystickGetDeviceSteamVirtualGamepadSlot(int device_index)
{
return -1;
}

/* Function to get the player index of a joystick */
static int PS2_JoystickGetDevicePlayerIndex(int device_index)
{
Expand Down Expand Up @@ -341,6 +347,7 @@ SDL_JoystickDriver SDL_PS2_JoystickDriver = {
PS2_JoystickDetect,
PS2_JoystickGetDeviceName,
PS2_JoystickGetDevicePath,
PS2_JoystickGetDeviceSteamVirtualGamepadSlot,
PS2_JoystickGetDevicePlayerIndex,
PS2_JoystickSetDevicePlayerIndex,
PS2_JoystickGetDeviceGUID,
Expand Down
6 changes: 6 additions & 0 deletions src/joystick/psp/SDL_sysjoystick.c
Original file line number Diff line number Diff line change
Expand Up @@ -121,6 +121,11 @@ static const char *PSP_JoystickGetDevicePath(int index)
return NULL;
}

static int PSP_JoystickGetDeviceSteamVirtualGamepadSlot(int device_index)
{
return -1;
}

static int PSP_JoystickGetDevicePlayerIndex(int device_index)
{
return -1;
Expand Down Expand Up @@ -253,6 +258,7 @@ SDL_JoystickDriver SDL_PSP_JoystickDriver = {
PSP_JoystickDetect,
PSP_JoystickGetDeviceName,
PSP_JoystickGetDevicePath,
PSP_JoystickGetDeviceSteamVirtualGamepadSlot,
PSP_JoystickGetDevicePlayerIndex,
PSP_JoystickSetDevicePlayerIndex,
PSP_JoystickGetDeviceGUID,
Expand Down
6 changes: 6 additions & 0 deletions src/joystick/virtual/SDL_virtualjoystick.c
Original file line number Diff line number Diff line change
Expand Up @@ -367,6 +367,11 @@ static const char *VIRTUAL_JoystickGetDevicePath(int device_index)
return NULL;
}

static int VIRTUAL_JoystickGetDeviceSteamVirtualGamepadSlot(int device_index)
{
return -1;
}

static int VIRTUAL_JoystickGetDevicePlayerIndex(int device_index)
{
return -1;
Expand Down Expand Up @@ -728,6 +733,7 @@ SDL_JoystickDriver SDL_VIRTUAL_JoystickDriver = {
VIRTUAL_JoystickDetect,
VIRTUAL_JoystickGetDeviceName,
VIRTUAL_JoystickGetDevicePath,
VIRTUAL_JoystickGetDeviceSteamVirtualGamepadSlot,
VIRTUAL_JoystickGetDevicePlayerIndex,
VIRTUAL_JoystickSetDevicePlayerIndex,
VIRTUAL_JoystickGetDeviceGUID,
Expand Down
6 changes: 6 additions & 0 deletions src/joystick/vita/SDL_sysjoystick.c
Original file line number Diff line number Diff line change
Expand Up @@ -181,6 +181,11 @@ const char *VITA_JoystickGetDevicePath(int index)
return NULL;
}

static int VITA_JoystickGetDeviceSteamVirtualGamepadSlot(int device_index)
{
return -1;
}

static int VITA_JoystickGetDevicePlayerIndex(int device_index)
{
return -1;
Expand Down Expand Up @@ -378,6 +383,7 @@ SDL_JoystickDriver SDL_VITA_JoystickDriver = {
VITA_JoystickDetect,
VITA_JoystickGetDeviceName,
VITA_JoystickGetDevicePath,
VITA_JoystickGetDeviceSteamVirtualGamepadSlot,
VITA_JoystickGetDevicePlayerIndex,
VITA_JoystickSetDevicePlayerIndex,
VITA_JoystickGetDeviceGUID,
Expand Down
6 changes: 6 additions & 0 deletions src/joystick/windows/SDL_rawinputjoystick.c
Original file line number Diff line number Diff line change
Expand Up @@ -1189,6 +1189,11 @@ static const char *RAWINPUT_JoystickGetDevicePath(int device_index)
return RAWINPUT_GetDeviceByIndex(device_index)->path;
}

static int RAWINPUT_JoystickGetDeviceSteamVirtualGamepadSlot(int device_index)
{
return -1;
}

static int RAWINPUT_JoystickGetDevicePlayerIndex(int device_index)
{
return -1;
Expand Down Expand Up @@ -2198,6 +2203,7 @@ SDL_JoystickDriver SDL_RAWINPUT_JoystickDriver = {
RAWINPUT_JoystickDetect,
RAWINPUT_JoystickGetDeviceName,
RAWINPUT_JoystickGetDevicePath,
RAWINPUT_JoystickGetDeviceSteamVirtualGamepadSlot,
RAWINPUT_JoystickGetDevicePlayerIndex,
RAWINPUT_JoystickSetDevicePlayerIndex,
RAWINPUT_JoystickGetDeviceGUID,
Expand Down
Loading

0 comments on commit c5eea0f

Please sign in to comment.