Path: blob/master/thirdparty/sdl/core/windows/SDL_xinput.h
9905 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*/20#include "SDL_internal.h"2122#ifndef SDL_xinput_h_23#define SDL_xinput_h_2425#include "SDL_windows.h"2627#ifdef HAVE_XINPUT_H28#if defined(SDL_PLATFORM_XBOXONE) || defined(SDL_PLATFORM_XBOXSERIES)29// Xbox supports an XInput wrapper which is a C++-only header...30#include <math.h> // Required to compile with recent MSVC...31#include <XInputOnGameInput.h>32using namespace XInputOnGameInput;33#else34#include <xinput.h>35#endif36#endif // HAVE_XINPUT_H3738#ifndef XUSER_MAX_COUNT39#define XUSER_MAX_COUNT 440#endif41#ifndef XUSER_INDEX_ANY42#define XUSER_INDEX_ANY 0x000000FF43#endif44#ifndef XINPUT_CAPS_FFB_SUPPORTED45#define XINPUT_CAPS_FFB_SUPPORTED 0x000146#endif47#ifndef XINPUT_CAPS_WIRELESS48#define XINPUT_CAPS_WIRELESS 0x000249#endif5051#ifndef XINPUT_DEVSUBTYPE_UNKNOWN52#define XINPUT_DEVSUBTYPE_UNKNOWN 0x0053#endif54#ifndef XINPUT_DEVSUBTYPE_GAMEPAD55#define XINPUT_DEVSUBTYPE_GAMEPAD 0x0156#endif57#ifndef XINPUT_DEVSUBTYPE_WHEEL58#define XINPUT_DEVSUBTYPE_WHEEL 0x0259#endif60#ifndef XINPUT_DEVSUBTYPE_ARCADE_STICK61#define XINPUT_DEVSUBTYPE_ARCADE_STICK 0x0362#endif63#ifndef XINPUT_DEVSUBTYPE_FLIGHT_STICK64#define XINPUT_DEVSUBTYPE_FLIGHT_STICK 0x0465#endif66#ifndef XINPUT_DEVSUBTYPE_DANCE_PAD67#define XINPUT_DEVSUBTYPE_DANCE_PAD 0x0568#endif69#ifndef XINPUT_DEVSUBTYPE_GUITAR70#define XINPUT_DEVSUBTYPE_GUITAR 0x0671#endif72#ifndef XINPUT_DEVSUBTYPE_GUITAR_ALTERNATE73#define XINPUT_DEVSUBTYPE_GUITAR_ALTERNATE 0x0774#endif75#ifndef XINPUT_DEVSUBTYPE_DRUM_KIT76#define XINPUT_DEVSUBTYPE_DRUM_KIT 0x0877#endif78#ifndef XINPUT_DEVSUBTYPE_GUITAR_BASS79#define XINPUT_DEVSUBTYPE_GUITAR_BASS 0x0B80#endif81#ifndef XINPUT_DEVSUBTYPE_ARCADE_PAD82#define XINPUT_DEVSUBTYPE_ARCADE_PAD 0x1383#endif8485#ifndef XINPUT_FLAG_GAMEPAD86#define XINPUT_FLAG_GAMEPAD 0x0187#endif8889#ifndef XINPUT_GAMEPAD_DPAD_UP90#define XINPUT_GAMEPAD_DPAD_UP 0x000191#endif92#ifndef XINPUT_GAMEPAD_DPAD_DOWN93#define XINPUT_GAMEPAD_DPAD_DOWN 0x000294#endif95#ifndef XINPUT_GAMEPAD_DPAD_LEFT96#define XINPUT_GAMEPAD_DPAD_LEFT 0x000497#endif98#ifndef XINPUT_GAMEPAD_DPAD_RIGHT99#define XINPUT_GAMEPAD_DPAD_RIGHT 0x0008100#endif101#ifndef XINPUT_GAMEPAD_START102#define XINPUT_GAMEPAD_START 0x0010103#endif104#ifndef XINPUT_GAMEPAD_BACK105#define XINPUT_GAMEPAD_BACK 0x0020106#endif107#ifndef XINPUT_GAMEPAD_LEFT_THUMB108#define XINPUT_GAMEPAD_LEFT_THUMB 0x0040109#endif110#ifndef XINPUT_GAMEPAD_RIGHT_THUMB111#define XINPUT_GAMEPAD_RIGHT_THUMB 0x0080112#endif113#ifndef XINPUT_GAMEPAD_LEFT_SHOULDER114#define XINPUT_GAMEPAD_LEFT_SHOULDER 0x0100115#endif116#ifndef XINPUT_GAMEPAD_RIGHT_SHOULDER117#define XINPUT_GAMEPAD_RIGHT_SHOULDER 0x0200118#endif119#ifndef XINPUT_GAMEPAD_A120#define XINPUT_GAMEPAD_A 0x1000121#endif122#ifndef XINPUT_GAMEPAD_B123#define XINPUT_GAMEPAD_B 0x2000124#endif125#ifndef XINPUT_GAMEPAD_X126#define XINPUT_GAMEPAD_X 0x4000127#endif128#ifndef XINPUT_GAMEPAD_Y129#define XINPUT_GAMEPAD_Y 0x8000130#endif131132#ifndef XINPUT_GAMEPAD_GUIDE133#define XINPUT_GAMEPAD_GUIDE 0x0400134#endif135136#ifndef BATTERY_DEVTYPE_GAMEPAD137#define BATTERY_DEVTYPE_GAMEPAD 0x00138#endif139140#ifndef BATTERY_TYPE_DISCONNECTED141#define BATTERY_TYPE_DISCONNECTED 0x00142#endif143#ifndef BATTERY_TYPE_WIRED144#define BATTERY_TYPE_WIRED 0x01145#endif146#ifndef BATTERY_TYPE_UNKNOWN147#define BATTERY_TYPE_UNKNOWN 0xFF148#endif149#ifndef BATTERY_LEVEL_EMPTY150#define BATTERY_LEVEL_EMPTY 0x00151#endif152#ifndef BATTERY_LEVEL_LOW153#define BATTERY_LEVEL_LOW 0x01154#endif155#ifndef BATTERY_LEVEL_MEDIUM156#define BATTERY_LEVEL_MEDIUM 0x02157#endif158#ifndef BATTERY_LEVEL_FULL159#define BATTERY_LEVEL_FULL 0x03160#endif161162// Set up for C function definitions, even when using C++163#ifdef __cplusplus164extern "C" {165#endif166167// typedef's for XInput structs we use168169170// This is the same as XINPUT_BATTERY_INFORMATION, but always defined instead of just if WIN32_WINNT >= _WIN32_WINNT_WIN8171typedef struct172{173BYTE BatteryType;174BYTE BatteryLevel;175} XINPUT_BATTERY_INFORMATION_EX;176177#ifndef HAVE_XINPUT_H178179typedef struct180{181WORD wButtons;182BYTE bLeftTrigger;183BYTE bRightTrigger;184SHORT sThumbLX;185SHORT sThumbLY;186SHORT sThumbRX;187SHORT sThumbRY;188} XINPUT_GAMEPAD;189190typedef struct191{192DWORD dwPacketNumber;193XINPUT_GAMEPAD Gamepad;194} XINPUT_STATE;195196typedef struct197{198WORD wLeftMotorSpeed;199WORD wRightMotorSpeed;200} XINPUT_VIBRATION;201202typedef struct203{204BYTE Type;205BYTE SubType;206WORD Flags;207XINPUT_GAMEPAD Gamepad;208XINPUT_VIBRATION Vibration;209} XINPUT_CAPABILITIES;210211#endif // HAVE_XINPUT_H212213// This struct is not defined in XInput headers.214typedef struct215{216XINPUT_CAPABILITIES Capabilities;217WORD VendorId;218WORD ProductId;219WORD ProductVersion;220WORD unk1;221DWORD unk2;222} SDL_XINPUT_CAPABILITIES_EX;223224// Forward decl's for XInput API's we load dynamically and use if available225typedef DWORD(WINAPI *XInputGetState_t)(226DWORD dwUserIndex, // [in] Index of the gamer associated with the device227XINPUT_STATE *pState // [out] Receives the current state228);229230typedef DWORD(WINAPI *XInputSetState_t)(231DWORD dwUserIndex, // [in] Index of the gamer associated with the device232XINPUT_VIBRATION *pVibration // [in, out] The vibration information to send to the controller233);234235typedef DWORD(WINAPI *XInputGetCapabilities_t)(236DWORD dwUserIndex, // [in] Index of the gamer associated with the device237DWORD dwFlags, // [in] Input flags that identify the device type238XINPUT_CAPABILITIES *pCapabilities // [out] Receives the capabilities239);240241// Only available in XInput 1.4 that is shipped with Windows 8 and newer.242typedef DWORD(WINAPI *XInputGetCapabilitiesEx_t)(243DWORD dwReserved, // [in] Must be 1244DWORD dwUserIndex, // [in] Index of the gamer associated with the device245DWORD dwFlags, // [in] Input flags that identify the device type246SDL_XINPUT_CAPABILITIES_EX *pCapabilitiesEx // [out] Receives the capabilities247);248249typedef DWORD(WINAPI *XInputGetBatteryInformation_t)(250DWORD dwUserIndex,251BYTE devType,252XINPUT_BATTERY_INFORMATION_EX *pBatteryInformation);253254extern bool WIN_LoadXInputDLL(void);255extern void WIN_UnloadXInputDLL(void);256257extern XInputGetState_t SDL_XInputGetState;258extern XInputSetState_t SDL_XInputSetState;259extern XInputGetCapabilities_t SDL_XInputGetCapabilities;260extern XInputGetCapabilitiesEx_t SDL_XInputGetCapabilitiesEx;261extern XInputGetBatteryInformation_t SDL_XInputGetBatteryInformation;262extern DWORD SDL_XInputVersion; // ((major << 16) & 0xFF00) | (minor & 0xFF)263264// Ends C function definitions when using C++265#ifdef __cplusplus266}267#endif268269#define XINPUTGETSTATE SDL_XInputGetState270#define XINPUTSETSTATE SDL_XInputSetState271#define XINPUTGETCAPABILITIES SDL_XInputGetCapabilities272#define XINPUTGETCAPABILITIESEX SDL_XInputGetCapabilitiesEx273#define XINPUTGETBATTERYINFORMATION SDL_XInputGetBatteryInformation274275#endif // SDL_xinput_h_276277278