Path: blob/master/thirdparty/sdl/joystick/SDL_joystick_c.h
9903 views
/*1Simple DirectMedia Layer2Copyright (C) 1997-2025 Sam Lantinga <[email protected]>34This software is provided 'as-is', without any express or implied5warranty. In no event will the authors be held liable for any damages6arising from the use of this software.78Permission is granted to anyone to use this software for any purpose,9including commercial applications, and to alter it and redistribute it10freely, subject to the following restrictions:11121. The origin of this software must not be misrepresented; you must not13claim that you wrote the original software. If you use this software14in a product, an acknowledgment in the product documentation would be15appreciated but is not required.162. Altered source versions must be plainly marked as such, and must not be17misrepresented as being the original software.183. This notice may not be removed or altered from any source distribution.19*/2021#ifndef SDL_joystick_c_h_22#define SDL_joystick_c_h_2324#include "SDL_internal.h"2526// Useful functions and variables from SDL_joystick.c2728// Set up for C function definitions, even when using C++29#ifdef __cplusplus30extern "C" {31#endif3233struct SDL_JoystickDriver;34struct SDL_SteamVirtualGamepadInfo;3536// Initialization and shutdown functions37extern bool SDL_InitJoysticks(void);38extern void SDL_QuitJoysticks(void);3940// Return whether the joystick system is currently initialized41extern bool SDL_JoysticksInitialized(void);4243// Return whether the joystick system is shutting down44extern bool SDL_JoysticksQuitting(void);4546// Return whether the joysticks are currently locked47extern bool SDL_JoysticksLocked(void);4849// Make sure we currently have the joysticks locked50extern void SDL_AssertJoysticksLocked(void) SDL_ASSERT_CAPABILITY(SDL_joystick_lock);5152// Function to return whether there are any joysticks opened by the application53extern bool SDL_JoysticksOpened(void);5455// Function to determine whether a device is currently detected by this driver56extern bool SDL_JoystickHandledByAnotherDriver(struct SDL_JoystickDriver *driver, Uint16 vendor_id, Uint16 product_id, Uint16 version, const char *name);5758/* Function to standardize the name for a controller59This should be freed with SDL_free() when no longer needed60*/61extern char *SDL_CreateJoystickName(Uint16 vendor, Uint16 product, const char *vendor_name, const char *product_name);6263// Function to create a GUID for a joystick based on the VID/PID and name64extern SDL_GUID SDL_CreateJoystickGUID(Uint16 bus, Uint16 vendor, Uint16 product, Uint16 version, const char *vendor_name, const char *product_name, Uint8 driver_signature, Uint8 driver_data);6566// Function to create a GUID for a joystick based on the name, with no VID/PID information67extern SDL_GUID SDL_CreateJoystickGUIDForName(const char *name);6869// Function to set the vendor field of a joystick GUID70extern void SDL_SetJoystickGUIDVendor(SDL_GUID *guid, Uint16 vendor);7172// Function to set the product field of a joystick GUID73extern void SDL_SetJoystickGUIDProduct(SDL_GUID *guid, Uint16 product);7475// Function to set the version field of a joystick GUID76extern void SDL_SetJoystickGUIDVersion(SDL_GUID *guid, Uint16 version);7778// Function to set the CRC field of a joystick GUID79extern void SDL_SetJoystickGUIDCRC(SDL_GUID *guid, Uint16 crc);8081// Function to return the type of a controller82extern SDL_GamepadType SDL_GetGamepadTypeFromVIDPID(Uint16 vendor, Uint16 product, const char *name, bool forUI);83extern SDL_GamepadType SDL_GetGamepadTypeFromGUID(SDL_GUID guid, const char *name);8485// Function to return whether a joystick GUID uses the version field86extern bool SDL_JoystickGUIDUsesVersion(SDL_GUID guid);8788// Function to return whether a joystick is an Xbox One controller89extern bool SDL_IsJoystickXboxOne(Uint16 vendor_id, Uint16 product_id);9091// Function to return whether a joystick is an Xbox One Elite controller92extern bool SDL_IsJoystickXboxOneElite(Uint16 vendor_id, Uint16 product_id);9394// Function to return whether a joystick is an Xbox Series X controller95extern bool SDL_IsJoystickXboxSeriesX(Uint16 vendor_id, Uint16 product_id);9697// Function to return whether a joystick is an Xbox One controller connected via Bluetooth98extern bool SDL_IsJoystickBluetoothXboxOne(Uint16 vendor_id, Uint16 product_id);99100// Function to return whether a joystick is a PS4 controller101extern bool SDL_IsJoystickPS4(Uint16 vendor_id, Uint16 product_id);102103// Function to return whether a joystick is a PS5 controller104extern bool SDL_IsJoystickPS5(Uint16 vendor_id, Uint16 product_id);105extern bool SDL_IsJoystickDualSenseEdge(Uint16 vendor_id, Uint16 product_id);106107// Function to return whether a joystick is a Nintendo Switch Pro controller108extern bool SDL_IsJoystickNintendoSwitchPro(Uint16 vendor_id, Uint16 product_id);109extern bool SDL_IsJoystickNintendoSwitchProInputOnly(Uint16 vendor_id, Uint16 product_id);110extern bool SDL_IsJoystickNintendoSwitchJoyCon(Uint16 vendor_id, Uint16 product_id);111extern bool SDL_IsJoystickNintendoSwitchJoyConLeft(Uint16 vendor_id, Uint16 product_id);112extern bool SDL_IsJoystickNintendoSwitchJoyConRight(Uint16 vendor_id, Uint16 product_id);113extern bool SDL_IsJoystickNintendoSwitchJoyConGrip(Uint16 vendor_id, Uint16 product_id);114extern bool SDL_IsJoystickNintendoSwitchJoyConPair(Uint16 vendor_id, Uint16 product_id);115116// Function to return whether a joystick is a Nintendo GameCube style controller117extern bool SDL_IsJoystickGameCube(Uint16 vendor_id, Uint16 product_id);118119// Function to return whether a joystick is an Amazon Luna controller120extern bool SDL_IsJoystickAmazonLunaController(Uint16 vendor_id, Uint16 product_id);121122// Function to return whether a joystick is a Google Stadia controller123extern bool SDL_IsJoystickGoogleStadiaController(Uint16 vendor_id, Uint16 product_id);124125// Function to return whether a joystick is an NVIDIA SHIELD controller126extern bool SDL_IsJoystickNVIDIASHIELDController(Uint16 vendor_id, Uint16 product_id);127128// Function to return whether a joystick is a Steam Virtual Gamepad129extern bool SDL_IsJoystickSteamVirtualGamepad(Uint16 vendor_id, Uint16 product_id, Uint16 version);130131// Function to return whether a joystick is a Steam Controller132extern bool SDL_IsJoystickSteamController(Uint16 vendor_id, Uint16 product_id);133134// Function to return whether a joystick is a HORI Steam controller135extern bool SDL_IsJoystickHoriSteamController(Uint16 vendor_id, Uint16 product_id);136137// Function to return whether a joystick is a Steam Deck138extern bool SDL_IsJoystickSteamDeck(Uint16 vendor_id, Uint16 product_id);139140// Function to return whether a joystick guid comes from the XInput driver141extern bool SDL_IsJoystickXInput(SDL_GUID guid);142143// Function to return whether a joystick guid comes from the WGI driver144extern bool SDL_IsJoystickWGI(SDL_GUID guid);145146// Function to return whether a joystick guid comes from the HIDAPI driver147extern bool SDL_IsJoystickHIDAPI(SDL_GUID guid);148149// Function to return whether a joystick guid comes from the MFI driver150extern bool SDL_IsJoystickMFI(SDL_GUID guid);151152// Function to return whether a joystick guid comes from the RAWINPUT driver153extern bool SDL_IsJoystickRAWINPUT(SDL_GUID guid);154155// Function to return whether a joystick guid comes from the Virtual driver156extern bool SDL_IsJoystickVIRTUAL(SDL_GUID guid);157158// Function to return whether a joystick should be ignored159extern bool SDL_ShouldIgnoreJoystick(Uint16 vendor_id, Uint16 product_id, Uint16 version, const char *name);160161// Internal event queueing functions162extern void SDL_PrivateJoystickAddTouchpad(SDL_Joystick *joystick, int nfingers);163extern void SDL_PrivateJoystickAddSensor(SDL_Joystick *joystick, SDL_SensorType type, float rate);164extern void SDL_PrivateJoystickSensorRate(SDL_Joystick *joystick, SDL_SensorType type, float rate);165extern void SDL_PrivateJoystickAdded(SDL_JoystickID instance_id);166extern bool SDL_IsJoystickBeingAdded(void);167extern void SDL_PrivateJoystickRemoved(SDL_JoystickID instance_id);168extern void SDL_PrivateJoystickForceRecentering(SDL_Joystick *joystick);169extern void SDL_SendJoystickAxis(Uint64 timestamp, SDL_Joystick *joystick, Uint8 axis, Sint16 value);170extern void SDL_SendJoystickBall(Uint64 timestamp, SDL_Joystick *joystick, Uint8 ball, Sint16 xrel, Sint16 yrel);171extern void SDL_SendJoystickHat(Uint64 timestamp, SDL_Joystick *joystick, Uint8 hat, Uint8 value);172extern void SDL_SendJoystickButton(Uint64 timestamp, SDL_Joystick *joystick, Uint8 button, bool down);173extern void SDL_SendJoystickTouchpad(Uint64 timestamp, SDL_Joystick *joystick, int touchpad, int finger, bool down, float x, float y, float pressure);174extern void SDL_SendJoystickSensor(Uint64 timestamp, SDL_Joystick *joystick, SDL_SensorType type, Uint64 sensor_timestamp, const float *data, int num_values);175extern void SDL_SendJoystickPowerInfo(SDL_Joystick *joystick, SDL_PowerState state, int percent);176177// Function to get the Steam virtual gamepad info for a joystick178extern const struct SDL_SteamVirtualGamepadInfo *SDL_GetJoystickVirtualGamepadInfoForID(SDL_JoystickID instance_id);179180// Internal sanity checking functions181extern bool SDL_IsJoystickValid(SDL_Joystick *joystick);182183typedef enum184{185EMappingKind_None,186EMappingKind_Button,187EMappingKind_Axis,188EMappingKind_Hat,189} EMappingKind;190191typedef struct SDL_InputMapping192{193EMappingKind kind;194Uint8 target;195bool axis_reversed;196bool half_axis_positive;197bool half_axis_negative;198} SDL_InputMapping;199200typedef struct SDL_GamepadMapping201{202SDL_InputMapping a;203SDL_InputMapping b;204SDL_InputMapping x;205SDL_InputMapping y;206SDL_InputMapping back;207SDL_InputMapping guide;208SDL_InputMapping start;209SDL_InputMapping leftstick;210SDL_InputMapping rightstick;211SDL_InputMapping leftshoulder;212SDL_InputMapping rightshoulder;213SDL_InputMapping dpup;214SDL_InputMapping dpdown;215SDL_InputMapping dpleft;216SDL_InputMapping dpright;217SDL_InputMapping misc1;218SDL_InputMapping misc2;219SDL_InputMapping misc3;220SDL_InputMapping misc4;221SDL_InputMapping misc5;222SDL_InputMapping misc6;223SDL_InputMapping right_paddle1;224SDL_InputMapping left_paddle1;225SDL_InputMapping right_paddle2;226SDL_InputMapping left_paddle2;227SDL_InputMapping leftx;228SDL_InputMapping lefty;229SDL_InputMapping rightx;230SDL_InputMapping righty;231SDL_InputMapping lefttrigger;232SDL_InputMapping righttrigger;233SDL_InputMapping touchpad;234} SDL_GamepadMapping;235236// Function to get autodetected gamepad controller mapping from the driver237extern bool SDL_PrivateJoystickGetAutoGamepadMapping(SDL_JoystickID instance_id,238SDL_GamepadMapping *out);239240241typedef struct242{243const char *included_hint_name;244int num_included_entries;245int max_included_entries;246Uint32 *included_entries;247248const char *excluded_hint_name;249int num_excluded_entries;250int max_excluded_entries;251Uint32 *excluded_entries;252253int num_initial_entries;254Uint32 *initial_entries;255256bool initialized;257} SDL_vidpid_list;258259extern void SDL_LoadVIDPIDList(SDL_vidpid_list *list);260extern void SDL_LoadVIDPIDListFromHints(SDL_vidpid_list *list, const char *included_list, const char *excluded_list);261extern bool SDL_VIDPIDInList(Uint16 vendor_id, Uint16 product_id, const SDL_vidpid_list *list);262extern void SDL_FreeVIDPIDList(SDL_vidpid_list *list);263264// Ends C function definitions when using C++265#ifdef __cplusplus266}267#endif268269#endif // SDL_joystick_c_h_270271272