Added support for the Steam Virtual Gamepad on macOS Sequoia
This commit is contained in:
parent
3ebfdb04be
commit
d7b1ba1bfc
6 changed files with 43 additions and 3 deletions
|
@ -3090,6 +3090,15 @@ bool SDL_IsJoystickNVIDIASHIELDController(Uint16 vendor_id, Uint16 product_id)
|
||||||
product_id == USB_PRODUCT_NVIDIA_SHIELD_CONTROLLER_V104));
|
product_id == USB_PRODUCT_NVIDIA_SHIELD_CONTROLLER_V104));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
bool SDL_IsJoystickSteamVirtualGamepad(Uint16 vendor_id, Uint16 product_id, Uint16 version)
|
||||||
|
{
|
||||||
|
#ifdef SDL_PLATFORM_MACOS
|
||||||
|
return (vendor_id == USB_VENDOR_MICROSOFT && product_id == USB_PRODUCT_XBOX360_WIRED_CONTROLLER && version == 0);
|
||||||
|
#else
|
||||||
|
return (vendor_id == USB_VENDOR_VALVE && product_id == USB_PRODUCT_STEAM_VIRTUAL_GAMEPAD);
|
||||||
|
#endif
|
||||||
|
}
|
||||||
|
|
||||||
bool SDL_IsJoystickSteamController(Uint16 vendor_id, Uint16 product_id)
|
bool SDL_IsJoystickSteamController(Uint16 vendor_id, Uint16 product_id)
|
||||||
{
|
{
|
||||||
EControllerType eType = GuessControllerType(vendor_id, product_id);
|
EControllerType eType = GuessControllerType(vendor_id, product_id);
|
||||||
|
|
|
@ -126,6 +126,9 @@ extern bool SDL_IsJoystickGoogleStadiaController(Uint16 vendor_id, Uint16 produc
|
||||||
// Function to return whether a joystick is an NVIDIA SHIELD controller
|
// Function to return whether a joystick is an NVIDIA SHIELD controller
|
||||||
extern bool SDL_IsJoystickNVIDIASHIELDController(Uint16 vendor_id, Uint16 product_id);
|
extern bool SDL_IsJoystickNVIDIASHIELDController(Uint16 vendor_id, Uint16 product_id);
|
||||||
|
|
||||||
|
// Function to return whether a joystick is a Steam Virtual Gamepad
|
||||||
|
extern bool SDL_IsJoystickSteamVirtualGamepad(Uint16 vendor_id, Uint16 product_id, Uint16 version);
|
||||||
|
|
||||||
// Function to return whether a joystick is a Steam Controller
|
// Function to return whether a joystick is a Steam Controller
|
||||||
extern bool SDL_IsJoystickSteamController(Uint16 vendor_id, Uint16 product_id);
|
extern bool SDL_IsJoystickSteamController(Uint16 vendor_id, Uint16 product_id);
|
||||||
|
|
||||||
|
|
|
@ -405,6 +405,10 @@ static bool IOS_AddMFIJoystickDevice(SDL_JoystickDeviceItem *device, GCControlle
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
#endif
|
#endif
|
||||||
|
if (device->is_xbox && SDL_strncmp(name, "GamePad-", 8) == 0) {
|
||||||
|
// This is a Steam Virtual Gamepad, which isn't supported by GCController
|
||||||
|
return false;
|
||||||
|
}
|
||||||
CheckControllerSiriRemote(controller, &device->is_siri_remote);
|
CheckControllerSiriRemote(controller, &device->is_siri_remote);
|
||||||
|
|
||||||
if (device->is_siri_remote && !SDL_GetHintBoolean(SDL_HINT_TV_REMOTE_AS_JOYSTICK, true)) {
|
if (device->is_siri_remote && !SDL_GetHintBoolean(SDL_HINT_TV_REMOTE_AS_JOYSTICK, true)) {
|
||||||
|
|
|
@ -81,9 +81,14 @@ static bool HIDAPI_DriverXbox360_IsSupportedDevice(SDL_HIDAPI_Device *device, co
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
#if defined(SDL_PLATFORM_MACOS) && defined(SDL_JOYSTICK_MFI)
|
#if defined(SDL_PLATFORM_MACOS) && defined(SDL_JOYSTICK_MFI)
|
||||||
// On macOS you can't write output reports to wired XBox controllers,
|
if (SDL_IsJoystickSteamVirtualGamepad(vendor_id, product_id, version)) {
|
||||||
// so we'll just use the GCController support instead.
|
// GCController support doesn't work with the Steam Virtual Gamepad
|
||||||
return false;
|
return true;
|
||||||
|
} else {
|
||||||
|
// On macOS you can't write output reports to wired XBox controllers,
|
||||||
|
// so we'll just use the GCController support instead.
|
||||||
|
return false;
|
||||||
|
}
|
||||||
#else
|
#else
|
||||||
return (type == SDL_GAMEPAD_TYPE_XBOX360);
|
return (type == SDL_GAMEPAD_TYPE_XBOX360);
|
||||||
#endif
|
#endif
|
||||||
|
@ -138,6 +143,13 @@ static bool HIDAPI_DriverXbox360_InitDevice(SDL_HIDAPI_Device *device)
|
||||||
|
|
||||||
device->type = SDL_GAMEPAD_TYPE_XBOX360;
|
device->type = SDL_GAMEPAD_TYPE_XBOX360;
|
||||||
|
|
||||||
|
if (SDL_IsJoystickSteamVirtualGamepad(device->vendor_id, device->product_id, device->version) &&
|
||||||
|
device->product_string && SDL_strncmp(device->product_string, "GamePad-", 8) == 0) {
|
||||||
|
int slot = 0;
|
||||||
|
SDL_sscanf(device->product_string, "GamePad-%d", &slot);
|
||||||
|
device->steam_virtual_gamepad_slot = (slot - 1);
|
||||||
|
}
|
||||||
|
|
||||||
return HIDAPI_JoystickConnected(device, NULL);
|
return HIDAPI_JoystickConnected(device, NULL);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -231,7 +243,11 @@ static bool HIDAPI_DriverXbox360_SetJoystickSensorsEnabled(SDL_HIDAPI_Device *de
|
||||||
static void HIDAPI_DriverXbox360_HandleStatePacket(SDL_Joystick *joystick, SDL_DriverXbox360_Context *ctx, Uint8 *data, int size)
|
static void HIDAPI_DriverXbox360_HandleStatePacket(SDL_Joystick *joystick, SDL_DriverXbox360_Context *ctx, Uint8 *data, int size)
|
||||||
{
|
{
|
||||||
Sint16 axis;
|
Sint16 axis;
|
||||||
|
#ifdef SDL_PLATFORM_MACOS
|
||||||
|
const bool invert_y_axes = false;
|
||||||
|
#else
|
||||||
const bool invert_y_axes = true;
|
const bool invert_y_axes = true;
|
||||||
|
#endif
|
||||||
Uint64 timestamp = SDL_GetTicksNS();
|
Uint64 timestamp = SDL_GetTicksNS();
|
||||||
|
|
||||||
if (ctx->last_state[2] != data[2]) {
|
if (ctx->last_state[2] != data[2]) {
|
||||||
|
|
|
@ -983,6 +983,7 @@ static SDL_HIDAPI_Device *HIDAPI_AddDevice(const struct SDL_hid_device_info *inf
|
||||||
device->guid = SDL_CreateJoystickGUID(bus, device->vendor_id, device->product_id, device->version, device->manufacturer_string, device->product_string, 'h', 0);
|
device->guid = SDL_CreateJoystickGUID(bus, device->vendor_id, device->product_id, device->version, device->manufacturer_string, device->product_string, 'h', 0);
|
||||||
device->joystick_type = SDL_JOYSTICK_TYPE_GAMEPAD;
|
device->joystick_type = SDL_JOYSTICK_TYPE_GAMEPAD;
|
||||||
device->type = SDL_GetJoystickGameControllerProtocol(device->name, device->vendor_id, device->product_id, device->interface_number, device->interface_class, device->interface_subclass, device->interface_protocol);
|
device->type = SDL_GetJoystickGameControllerProtocol(device->name, device->vendor_id, device->product_id, device->interface_number, device->interface_class, device->interface_subclass, device->interface_protocol);
|
||||||
|
device->steam_virtual_gamepad_slot = -1;
|
||||||
|
|
||||||
if (num_children > 0) {
|
if (num_children > 0) {
|
||||||
int i;
|
int i;
|
||||||
|
@ -1440,6 +1441,12 @@ static const char *HIDAPI_JoystickGetDevicePath(int device_index)
|
||||||
|
|
||||||
static int HIDAPI_JoystickGetDeviceSteamVirtualGamepadSlot(int device_index)
|
static int HIDAPI_JoystickGetDeviceSteamVirtualGamepadSlot(int device_index)
|
||||||
{
|
{
|
||||||
|
SDL_HIDAPI_Device *device;
|
||||||
|
|
||||||
|
device = HIDAPI_GetDeviceByIndex(device_index, NULL);
|
||||||
|
if (device) {
|
||||||
|
return device->steam_virtual_gamepad_slot;
|
||||||
|
}
|
||||||
return -1;
|
return -1;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -85,6 +85,7 @@ typedef struct SDL_HIDAPI_Device
|
||||||
bool is_bluetooth;
|
bool is_bluetooth;
|
||||||
SDL_JoystickType joystick_type;
|
SDL_JoystickType joystick_type;
|
||||||
SDL_GamepadType type;
|
SDL_GamepadType type;
|
||||||
|
int steam_virtual_gamepad_slot;
|
||||||
|
|
||||||
struct SDL_HIDAPI_DeviceDriver *driver;
|
struct SDL_HIDAPI_DeviceDriver *driver;
|
||||||
void *context;
|
void *context;
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue