Update for SDL3 coding style (#6717)
I updated .clang-format and ran clang-format 14 over the src and test directories to standardize the code base. In general I let clang-format have it's way, and added markup to prevent formatting of code that would break or be completely unreadable if formatted. The script I ran for the src directory is added as build-scripts/clang-format-src.sh This fixes: #6592 #6593 #6594
This commit is contained in:
parent
14b902faca
commit
5750bcb174
781 changed files with 51659 additions and 55763 deletions
|
@ -73,22 +73,21 @@ typedef struct WindowsGamingInputGamepadState WindowsGamingInputGamepadState;
|
|||
/*#define DEBUG_RAWINPUT*/
|
||||
|
||||
#ifndef RIDEV_EXINPUTSINK
|
||||
#define RIDEV_EXINPUTSINK 0x00001000
|
||||
#define RIDEV_DEVNOTIFY 0x00002000
|
||||
#define RIDEV_EXINPUTSINK 0x00001000
|
||||
#define RIDEV_DEVNOTIFY 0x00002000
|
||||
#endif
|
||||
|
||||
#ifndef WM_INPUT_DEVICE_CHANGE
|
||||
#define WM_INPUT_DEVICE_CHANGE 0x00FE
|
||||
#define WM_INPUT_DEVICE_CHANGE 0x00FE
|
||||
#endif
|
||||
#ifndef WM_INPUT
|
||||
#define WM_INPUT 0x00FF
|
||||
#define WM_INPUT 0x00FF
|
||||
#endif
|
||||
#ifndef GIDC_ARRIVAL
|
||||
#define GIDC_ARRIVAL 1
|
||||
#define GIDC_REMOVAL 2
|
||||
#define GIDC_ARRIVAL 1
|
||||
#define GIDC_REMOVAL 2
|
||||
#endif
|
||||
|
||||
|
||||
static SDL_bool SDL_RAWINPUT_inited = SDL_FALSE;
|
||||
static int SDL_RAWINPUT_numjoysticks = 0;
|
||||
|
||||
|
@ -166,13 +165,15 @@ static const Uint16 subscribed_devices[] = {
|
|||
|
||||
#ifdef SDL_JOYSTICK_RAWINPUT_MATCHING
|
||||
|
||||
static struct {
|
||||
static struct
|
||||
{
|
||||
Uint32 last_state_packet;
|
||||
SDL_Joystick *joystick;
|
||||
SDL_Joystick *last_joystick;
|
||||
} guide_button_candidate;
|
||||
|
||||
typedef struct WindowsMatchState {
|
||||
typedef struct WindowsMatchState
|
||||
{
|
||||
#ifdef SDL_JOYSTICK_RAWINPUT_MATCH_AXES
|
||||
SHORT match_axes[SDL_JOYSTICK_RAWINPUT_MATCH_COUNT];
|
||||
#endif
|
||||
|
@ -215,11 +216,11 @@ static void RAWINPUT_FillMatchState(WindowsMatchState *state, Uint64 match_state
|
|||
|
||||
#ifdef SDL_JOYSTICK_RAWINPUT_XINPUT
|
||||
/* Match axes by checking if the distance between the high 4 bits of axis and the 4 bits from match_state is 1 or less */
|
||||
#define XInputAxesMatch(gamepad) (\
|
||||
(Uint32)(gamepad.sThumbLX - state->match_axes[0] + 0x1000) <= 0x2fff && \
|
||||
(Uint32)(~gamepad.sThumbLY - state->match_axes[1] + 0x1000) <= 0x2fff && \
|
||||
(Uint32)(gamepad.sThumbRX - state->match_axes[2] + 0x1000) <= 0x2fff && \
|
||||
(Uint32)(~gamepad.sThumbRY - state->match_axes[3] + 0x1000) <= 0x2fff)
|
||||
#define XInputAxesMatch(gamepad) ( \
|
||||
(Uint32)(gamepad.sThumbLX - state->match_axes[0] + 0x1000) <= 0x2fff && \
|
||||
(Uint32)(~gamepad.sThumbLY - state->match_axes[1] + 0x1000) <= 0x2fff && \
|
||||
(Uint32)(gamepad.sThumbRX - state->match_axes[2] + 0x1000) <= 0x2fff && \
|
||||
(Uint32)(~gamepad.sThumbRY - state->match_axes[3] + 0x1000) <= 0x2fff)
|
||||
/* Explicit
|
||||
#define XInputAxesMatch(gamepad) (\
|
||||
SDL_abs((Sint8)((gamepad.sThumbLX & 0xF000) >> 8) - ((match_state & 0x000F0000) >> 12)) <= 0x10 && \
|
||||
|
@ -228,9 +229,9 @@ static void RAWINPUT_FillMatchState(WindowsMatchState *state, Uint64 match_state
|
|||
SDL_abs((Sint8)((~gamepad.sThumbRY & 0xF000) >> 8) - ((match_state & 0xF0000000) >> 24)) <= 0x10) */
|
||||
|
||||
/* Can only match trigger values if a single trigger has a value. */
|
||||
#define XInputTriggersMatch(gamepad) ( \
|
||||
((state->match_axes[4] == SDL_MIN_SINT16) && (state->match_axes[5] == SDL_MIN_SINT16)) || \
|
||||
((gamepad.bLeftTrigger != 0) && (gamepad.bRightTrigger != 0)) || \
|
||||
#define XInputTriggersMatch(gamepad) ( \
|
||||
((state->match_axes[4] == SDL_MIN_SINT16) && (state->match_axes[5] == SDL_MIN_SINT16)) || \
|
||||
((gamepad.bLeftTrigger != 0) && (gamepad.bRightTrigger != 0)) || \
|
||||
((Uint32)((((int)gamepad.bLeftTrigger * 257) - 32768) - state->match_axes[4]) <= 0x2fff) || \
|
||||
((Uint32)((((int)gamepad.bRightTrigger * 257) - 32768) - state->match_axes[5]) <= 0x2fff))
|
||||
|
||||
|
@ -261,15 +262,15 @@ static void RAWINPUT_FillMatchState(WindowsMatchState *state, Uint64 match_state
|
|||
|
||||
#ifdef SDL_JOYSTICK_RAWINPUT_WGI
|
||||
/* Match axes by checking if the distance between the high 4 bits of axis and the 4 bits from match_state is 1 or less */
|
||||
#define WindowsGamingInputAxesMatch(gamepad) (\
|
||||
(Uint16)(((Sint16)(gamepad.LeftThumbstickX * SDL_MAX_SINT16) & 0xF000) - state->match_axes[0] + 0x1000) <= 0x2fff && \
|
||||
#define WindowsGamingInputAxesMatch(gamepad) ( \
|
||||
(Uint16)(((Sint16)(gamepad.LeftThumbstickX * SDL_MAX_SINT16) & 0xF000) - state->match_axes[0] + 0x1000) <= 0x2fff && \
|
||||
(Uint16)((~(Sint16)(gamepad.LeftThumbstickY * SDL_MAX_SINT16) & 0xF000) - state->match_axes[1] + 0x1000) <= 0x2fff && \
|
||||
(Uint16)(((Sint16)(gamepad.RightThumbstickX * SDL_MAX_SINT16) & 0xF000) - state->match_axes[2] + 0x1000) <= 0x2fff && \
|
||||
(Uint16)((~(Sint16)(gamepad.RightThumbstickY * SDL_MAX_SINT16) & 0xF000) - state->match_axes[3] + 0x1000) <= 0x2fff)
|
||||
|
||||
#define WindowsGamingInputTriggersMatch(gamepad) ( \
|
||||
((state->match_axes[4] == SDL_MIN_SINT16) && (state->match_axes[5] == SDL_MIN_SINT16)) || \
|
||||
((gamepad.LeftTrigger == 0.0f) && (gamepad.RightTrigger == 0.0f)) || \
|
||||
#define WindowsGamingInputTriggersMatch(gamepad) ( \
|
||||
((state->match_axes[4] == SDL_MIN_SINT16) && (state->match_axes[5] == SDL_MIN_SINT16)) || \
|
||||
((gamepad.LeftTrigger == 0.0f) && (gamepad.RightTrigger == 0.0f)) || \
|
||||
((Uint16)((((int)(gamepad.LeftTrigger * SDL_MAX_UINT16)) - 32768) - state->match_axes[4]) <= 0x2fff) || \
|
||||
((Uint16)((((int)(gamepad.RightTrigger * SDL_MAX_UINT16)) - 32768) - state->match_axes[5]) <= 0x2fff))
|
||||
|
||||
|
@ -297,25 +298,24 @@ static void RAWINPUT_FillMatchState(WindowsMatchState *state, Uint64 match_state
|
|||
state->any_data = SDL_TRUE;
|
||||
}
|
||||
#endif
|
||||
|
||||
}
|
||||
|
||||
#endif /* SDL_JOYSTICK_RAWINPUT_MATCHING */
|
||||
|
||||
#ifdef SDL_JOYSTICK_RAWINPUT_XINPUT
|
||||
|
||||
static struct {
|
||||
static struct
|
||||
{
|
||||
XINPUT_STATE_EX state;
|
||||
XINPUT_BATTERY_INFORMATION_EX battery;
|
||||
SDL_bool connected; /* Currently has an active XInput device */
|
||||
SDL_bool used; /* Is currently mapped to an SDL device */
|
||||
SDL_bool used; /* Is currently mapped to an SDL device */
|
||||
Uint8 correlation_id;
|
||||
} xinput_state[XUSER_MAX_COUNT];
|
||||
static SDL_bool xinput_device_change = SDL_TRUE;
|
||||
static SDL_bool xinput_state_dirty = SDL_TRUE;
|
||||
|
||||
static void
|
||||
RAWINPUT_UpdateXInput()
|
||||
static void RAWINPUT_UpdateXInput()
|
||||
{
|
||||
DWORD user_index;
|
||||
if (xinput_device_change) {
|
||||
|
@ -342,23 +342,20 @@ RAWINPUT_UpdateXInput()
|
|||
}
|
||||
}
|
||||
|
||||
static void
|
||||
RAWINPUT_MarkXInputSlotUsed(Uint8 xinput_slot)
|
||||
static void RAWINPUT_MarkXInputSlotUsed(Uint8 xinput_slot)
|
||||
{
|
||||
if (xinput_slot != XUSER_INDEX_ANY) {
|
||||
xinput_state[xinput_slot].used = SDL_TRUE;
|
||||
}
|
||||
}
|
||||
|
||||
static void
|
||||
RAWINPUT_MarkXInputSlotFree(Uint8 xinput_slot)
|
||||
static void RAWINPUT_MarkXInputSlotFree(Uint8 xinput_slot)
|
||||
{
|
||||
if (xinput_slot != XUSER_INDEX_ANY) {
|
||||
xinput_state[xinput_slot].used = SDL_FALSE;
|
||||
}
|
||||
}
|
||||
static SDL_bool
|
||||
RAWINPUT_MissingXInputSlot()
|
||||
static SDL_bool RAWINPUT_MissingXInputSlot()
|
||||
{
|
||||
int ii;
|
||||
for (ii = 0; ii < SDL_arraysize(xinput_state); ii++) {
|
||||
|
@ -369,8 +366,7 @@ RAWINPUT_MissingXInputSlot()
|
|||
return SDL_FALSE;
|
||||
}
|
||||
|
||||
static SDL_bool
|
||||
RAWINPUT_XInputSlotMatches(const WindowsMatchState *state, Uint8 slot_idx)
|
||||
static SDL_bool RAWINPUT_XInputSlotMatches(const WindowsMatchState *state, Uint8 slot_idx)
|
||||
{
|
||||
if (xinput_state[slot_idx].connected) {
|
||||
WORD xinput_buttons = xinput_state[slot_idx].state.Gamepad.wButtons;
|
||||
|
@ -381,16 +377,14 @@ RAWINPUT_XInputSlotMatches(const WindowsMatchState *state, Uint8 slot_idx)
|
|||
#ifdef SDL_JOYSTICK_RAWINPUT_MATCH_TRIGGERS
|
||||
&& XInputTriggersMatch(xinput_state[slot_idx].state.Gamepad)
|
||||
#endif
|
||||
) {
|
||||
) {
|
||||
return SDL_TRUE;
|
||||
}
|
||||
}
|
||||
return SDL_FALSE;
|
||||
}
|
||||
|
||||
|
||||
static SDL_bool
|
||||
RAWINPUT_GuessXInputSlot(const WindowsMatchState *state, Uint8 *correlation_id, Uint8 *slot_idx)
|
||||
static SDL_bool RAWINPUT_GuessXInputSlot(const WindowsMatchState *state, Uint8 *correlation_id, Uint8 *slot_idx)
|
||||
{
|
||||
int user_index;
|
||||
int match_count;
|
||||
|
@ -419,17 +413,19 @@ RAWINPUT_GuessXInputSlot(const WindowsMatchState *state, Uint8 *correlation_id,
|
|||
|
||||
#ifdef SDL_JOYSTICK_RAWINPUT_WGI
|
||||
|
||||
typedef struct WindowsGamingInputGamepadState {
|
||||
typedef struct WindowsGamingInputGamepadState
|
||||
{
|
||||
__x_ABI_CWindows_CGaming_CInput_CIGamepad *gamepad;
|
||||
struct __x_ABI_CWindows_CGaming_CInput_CGamepadReading state;
|
||||
RAWINPUT_DeviceContext *correlated_context;
|
||||
SDL_bool used; /* Is currently mapped to an SDL device */
|
||||
SDL_bool used; /* Is currently mapped to an SDL device */
|
||||
SDL_bool connected; /* Just used during update to track disconnected */
|
||||
Uint8 correlation_id;
|
||||
struct __x_ABI_CWindows_CGaming_CInput_CGamepadVibration vibration;
|
||||
} WindowsGamingInputGamepadState;
|
||||
|
||||
static struct {
|
||||
static struct
|
||||
{
|
||||
WindowsGamingInputGamepadState **per_gamepad;
|
||||
int per_gamepad_count;
|
||||
SDL_bool initialized;
|
||||
|
@ -439,22 +435,19 @@ static struct {
|
|||
__x_ABI_CWindows_CGaming_CInput_CIGamepadStatics *gamepad_statics;
|
||||
} wgi_state;
|
||||
|
||||
static void
|
||||
RAWINPUT_MarkWindowsGamingInputSlotUsed(WindowsGamingInputGamepadState *wgi_slot, RAWINPUT_DeviceContext *ctx)
|
||||
static void RAWINPUT_MarkWindowsGamingInputSlotUsed(WindowsGamingInputGamepadState *wgi_slot, RAWINPUT_DeviceContext *ctx)
|
||||
{
|
||||
wgi_slot->used = SDL_TRUE;
|
||||
wgi_slot->correlated_context = ctx;
|
||||
}
|
||||
|
||||
static void
|
||||
RAWINPUT_MarkWindowsGamingInputSlotFree(WindowsGamingInputGamepadState *wgi_slot)
|
||||
static void RAWINPUT_MarkWindowsGamingInputSlotFree(WindowsGamingInputGamepadState *wgi_slot)
|
||||
{
|
||||
wgi_slot->used = SDL_FALSE;
|
||||
wgi_slot->correlated_context = NULL;
|
||||
}
|
||||
|
||||
static SDL_bool
|
||||
RAWINPUT_MissingWindowsGamingInputSlot()
|
||||
static SDL_bool RAWINPUT_MissingWindowsGamingInputSlot()
|
||||
{
|
||||
int ii;
|
||||
for (ii = 0; ii < wgi_state.per_gamepad_count; ii++) {
|
||||
|
@ -465,8 +458,7 @@ RAWINPUT_MissingWindowsGamingInputSlot()
|
|||
return SDL_FALSE;
|
||||
}
|
||||
|
||||
static void
|
||||
RAWINPUT_UpdateWindowsGamingInput()
|
||||
static void RAWINPUT_UpdateWindowsGamingInput()
|
||||
{
|
||||
int ii;
|
||||
if (!wgi_state.gamepad_statics) {
|
||||
|
@ -501,7 +493,7 @@ RAWINPUT_UpdateWindowsGamingInput()
|
|||
if (SUCCEEDED(hr)) {
|
||||
SDL_bool found = SDL_FALSE;
|
||||
int jj;
|
||||
for (jj = 0; jj < wgi_state.per_gamepad_count ; jj++) {
|
||||
for (jj = 0; jj < wgi_state.per_gamepad_count; jj++) {
|
||||
if (wgi_state.per_gamepad[jj]->gamepad == gamepad) {
|
||||
found = SDL_TRUE;
|
||||
wgi_state.per_gamepad[jj]->connected = SDL_TRUE;
|
||||
|
@ -558,8 +550,7 @@ RAWINPUT_UpdateWindowsGamingInput()
|
|||
}
|
||||
}
|
||||
}
|
||||
static void
|
||||
RAWINPUT_InitWindowsGamingInput(RAWINPUT_DeviceContext *ctx)
|
||||
static void RAWINPUT_InitWindowsGamingInput(RAWINPUT_DeviceContext *ctx)
|
||||
{
|
||||
wgi_state.need_device_list_update = SDL_TRUE;
|
||||
wgi_state.ref_count++;
|
||||
|
@ -574,8 +565,8 @@ RAWINPUT_InitWindowsGamingInput(RAWINPUT_DeviceContext *ctx)
|
|||
wgi_state.dirty = SDL_TRUE;
|
||||
|
||||
{
|
||||
typedef HRESULT (WINAPI *WindowsCreateStringReference_t)(PCWSTR sourceString, UINT32 length, HSTRING_HEADER *hstringHeader, HSTRING* string);
|
||||
typedef HRESULT (WINAPI *RoGetActivationFactory_t)(HSTRING activatableClassId, REFIID iid, void** factory);
|
||||
typedef HRESULT(WINAPI * WindowsCreateStringReference_t)(PCWSTR sourceString, UINT32 length, HSTRING_HEADER * hstringHeader, HSTRING * string);
|
||||
typedef HRESULT(WINAPI * RoGetActivationFactory_t)(HSTRING activatableClassId, REFIID iid, void **factory);
|
||||
|
||||
#ifdef __WINRT__
|
||||
WindowsCreateStringReference_t WindowsCreateStringReferenceFunc = WindowsCreateStringReference;
|
||||
|
@ -598,26 +589,24 @@ RAWINPUT_InitWindowsGamingInput(RAWINPUT_DeviceContext *ctx)
|
|||
}
|
||||
}
|
||||
|
||||
static SDL_bool
|
||||
RAWINPUT_WindowsGamingInputSlotMatches(const WindowsMatchState *state, WindowsGamingInputGamepadState *slot, SDL_bool xinput_correlated)
|
||||
static SDL_bool RAWINPUT_WindowsGamingInputSlotMatches(const WindowsMatchState *state, WindowsGamingInputGamepadState *slot, SDL_bool xinput_correlated)
|
||||
{
|
||||
Uint32 wgi_buttons = slot->state.Buttons;
|
||||
if ((wgi_buttons & 0x3FFF) == state->wgi_buttons
|
||||
#ifdef SDL_JOYSTICK_RAWINPUT_MATCH_AXES
|
||||
&& WindowsGamingInputAxesMatch(slot->state)
|
||||
&& WindowsGamingInputAxesMatch(slot->state)
|
||||
#endif
|
||||
#ifdef SDL_JOYSTICK_RAWINPUT_MATCH_TRIGGERS
|
||||
// Don't try to match WGI triggers if getting values from XInput
|
||||
&& (xinput_correlated || WindowsGamingInputTriggersMatch(slot->state))
|
||||
// Don't try to match WGI triggers if getting values from XInput
|
||||
&& (xinput_correlated || WindowsGamingInputTriggersMatch(slot->state))
|
||||
#endif
|
||||
) {
|
||||
) {
|
||||
return SDL_TRUE;
|
||||
}
|
||||
return SDL_FALSE;
|
||||
}
|
||||
|
||||
static SDL_bool
|
||||
RAWINPUT_GuessWindowsGamingInputSlot(const WindowsMatchState *state, Uint8 *correlation_id, WindowsGamingInputGamepadState **slot, SDL_bool xinput_correlated)
|
||||
static SDL_bool RAWINPUT_GuessWindowsGamingInputSlot(const WindowsMatchState *state, Uint8 *correlation_id, WindowsGamingInputGamepadState **slot, SDL_bool xinput_correlated)
|
||||
{
|
||||
int match_count, user_index;
|
||||
|
||||
|
@ -640,8 +629,7 @@ RAWINPUT_GuessWindowsGamingInputSlot(const WindowsMatchState *state, Uint8 *corr
|
|||
return SDL_FALSE;
|
||||
}
|
||||
|
||||
static void
|
||||
RAWINPUT_QuitWindowsGamingInput(RAWINPUT_DeviceContext *ctx)
|
||||
static void RAWINPUT_QuitWindowsGamingInput(RAWINPUT_DeviceContext *ctx)
|
||||
{
|
||||
wgi_state.need_device_list_update = SDL_TRUE;
|
||||
--wgi_state.ref_count;
|
||||
|
@ -666,16 +654,13 @@ RAWINPUT_QuitWindowsGamingInput(RAWINPUT_DeviceContext *ctx)
|
|||
|
||||
#endif /* SDL_JOYSTICK_RAWINPUT_WGI */
|
||||
|
||||
|
||||
static SDL_RAWINPUT_Device *
|
||||
RAWINPUT_AcquireDevice(SDL_RAWINPUT_Device *device)
|
||||
static SDL_RAWINPUT_Device *RAWINPUT_AcquireDevice(SDL_RAWINPUT_Device *device)
|
||||
{
|
||||
SDL_AtomicIncRef(&device->refcount);
|
||||
return device;
|
||||
}
|
||||
|
||||
static void
|
||||
RAWINPUT_ReleaseDevice(SDL_RAWINPUT_Device *device)
|
||||
static void RAWINPUT_ReleaseDevice(SDL_RAWINPUT_Device *device)
|
||||
{
|
||||
#ifdef SDL_JOYSTICK_RAWINPUT_XINPUT
|
||||
if (device->joystick) {
|
||||
|
@ -696,8 +681,7 @@ RAWINPUT_ReleaseDevice(SDL_RAWINPUT_Device *device)
|
|||
}
|
||||
}
|
||||
|
||||
static SDL_RAWINPUT_Device *
|
||||
RAWINPUT_DeviceFromHandle(HANDLE hDevice)
|
||||
static SDL_RAWINPUT_Device *RAWINPUT_DeviceFromHandle(HANDLE hDevice)
|
||||
{
|
||||
SDL_RAWINPUT_Device *curr;
|
||||
|
||||
|
@ -709,10 +693,13 @@ RAWINPUT_DeviceFromHandle(HANDLE hDevice)
|
|||
return NULL;
|
||||
}
|
||||
|
||||
static void
|
||||
RAWINPUT_AddDevice(HANDLE hDevice)
|
||||
static void RAWINPUT_AddDevice(HANDLE hDevice)
|
||||
{
|
||||
#define CHECK(expression) { if (!(expression)) goto err; }
|
||||
#define CHECK(expression) \
|
||||
{ \
|
||||
if (!(expression)) \
|
||||
goto err; \
|
||||
}
|
||||
SDL_RAWINPUT_Device *device = NULL;
|
||||
SDL_RAWINPUT_Device *curr, *last;
|
||||
RID_DEVICE_INFO rdi;
|
||||
|
@ -754,7 +741,7 @@ RAWINPUT_AddDevice(HANDLE hDevice)
|
|||
CHECK(device->preparsed_data = (PHIDP_PREPARSED_DATA)SDL_calloc(size, sizeof(BYTE)));
|
||||
CHECK(GetRawInputDeviceInfoA(hDevice, RIDI_PREPARSEDDATA, device->preparsed_data, &size) != (UINT)-1);
|
||||
|
||||
hFile = CreateFileA(dev_name, GENERIC_READ, FILE_SHARE_READ|FILE_SHARE_WRITE, NULL, OPEN_EXISTING, 0, NULL);
|
||||
hFile = CreateFileA(dev_name, GENERIC_READ, FILE_SHARE_READ | FILE_SHARE_WRITE, NULL, OPEN_EXISTING, 0, NULL);
|
||||
CHECK(hFile != INVALID_HANDLE_VALUE);
|
||||
|
||||
{
|
||||
|
@ -825,8 +812,7 @@ err:
|
|||
#undef CHECK
|
||||
}
|
||||
|
||||
static void
|
||||
RAWINPUT_DelDevice(SDL_RAWINPUT_Device *device, SDL_bool send_event)
|
||||
static void RAWINPUT_DelDevice(SDL_RAWINPUT_Device *device, SDL_bool send_event)
|
||||
{
|
||||
SDL_RAWINPUT_Device *curr, *last;
|
||||
for (curr = SDL_RAWINPUT_devices, last = NULL; curr; last = curr, curr = curr->next) {
|
||||
|
@ -849,8 +835,7 @@ RAWINPUT_DelDevice(SDL_RAWINPUT_Device *device, SDL_bool send_event)
|
|||
}
|
||||
}
|
||||
|
||||
static int
|
||||
RAWINPUT_JoystickInit(void)
|
||||
static int RAWINPUT_JoystickInit(void)
|
||||
{
|
||||
UINT device_count = 0;
|
||||
|
||||
|
@ -889,8 +874,7 @@ RAWINPUT_JoystickInit(void)
|
|||
return 0;
|
||||
}
|
||||
|
||||
static int
|
||||
RAWINPUT_JoystickGetCount(void)
|
||||
static int RAWINPUT_JoystickGetCount(void)
|
||||
{
|
||||
return SDL_RAWINPUT_numjoysticks;
|
||||
}
|
||||
|
@ -916,7 +900,7 @@ RAWINPUT_IsDevicePresent(Uint16 vendor_id, Uint16 product_id, Uint16 version, co
|
|||
|
||||
device = SDL_RAWINPUT_devices;
|
||||
while (device) {
|
||||
if (vendor_id == device->vendor_id && product_id == device->product_id ) {
|
||||
if (vendor_id == device->vendor_id && product_id == device->product_id) {
|
||||
return SDL_TRUE;
|
||||
}
|
||||
|
||||
|
@ -941,8 +925,7 @@ RAWINPUT_IsDevicePresent(Uint16 vendor_id, Uint16 product_id, Uint16 version, co
|
|||
return SDL_FALSE;
|
||||
}
|
||||
|
||||
static void
|
||||
RAWINPUT_PostUpdate(void)
|
||||
static void RAWINPUT_PostUpdate(void)
|
||||
{
|
||||
#ifdef SDL_JOYSTICK_RAWINPUT_MATCHING
|
||||
SDL_bool unmapped_guide_pressed = SDL_FALSE;
|
||||
|
@ -1000,14 +983,12 @@ RAWINPUT_PostUpdate(void)
|
|||
#endif /* SDL_JOYSTICK_RAWINPUT_MATCHING */
|
||||
}
|
||||
|
||||
static void
|
||||
RAWINPUT_JoystickDetect(void)
|
||||
static void RAWINPUT_JoystickDetect(void)
|
||||
{
|
||||
RAWINPUT_PostUpdate();
|
||||
}
|
||||
|
||||
static SDL_RAWINPUT_Device *
|
||||
RAWINPUT_GetDeviceByIndex(int device_index)
|
||||
static SDL_RAWINPUT_Device *RAWINPUT_GetDeviceByIndex(int device_index)
|
||||
{
|
||||
SDL_RAWINPUT_Device *device = SDL_RAWINPUT_devices;
|
||||
while (device) {
|
||||
|
@ -1020,44 +1001,36 @@ RAWINPUT_GetDeviceByIndex(int device_index)
|
|||
return device;
|
||||
}
|
||||
|
||||
static const char *
|
||||
RAWINPUT_JoystickGetDeviceName(int device_index)
|
||||
static const char *RAWINPUT_JoystickGetDeviceName(int device_index)
|
||||
{
|
||||
return RAWINPUT_GetDeviceByIndex(device_index)->name;
|
||||
}
|
||||
|
||||
static const char *
|
||||
RAWINPUT_JoystickGetDevicePath(int device_index)
|
||||
static const char *RAWINPUT_JoystickGetDevicePath(int device_index)
|
||||
{
|
||||
return RAWINPUT_GetDeviceByIndex(device_index)->path;
|
||||
}
|
||||
|
||||
static int
|
||||
RAWINPUT_JoystickGetDevicePlayerIndex(int device_index)
|
||||
static int RAWINPUT_JoystickGetDevicePlayerIndex(int device_index)
|
||||
{
|
||||
return -1;
|
||||
}
|
||||
|
||||
static void
|
||||
RAWINPUT_JoystickSetDevicePlayerIndex(int device_index, int player_index)
|
||||
static void RAWINPUT_JoystickSetDevicePlayerIndex(int device_index, int player_index)
|
||||
{
|
||||
}
|
||||
|
||||
|
||||
static SDL_JoystickGUID
|
||||
RAWINPUT_JoystickGetDeviceGUID(int device_index)
|
||||
static SDL_JoystickGUID RAWINPUT_JoystickGetDeviceGUID(int device_index)
|
||||
{
|
||||
return RAWINPUT_GetDeviceByIndex(device_index)->guid;
|
||||
}
|
||||
|
||||
static SDL_JoystickID
|
||||
RAWINPUT_JoystickGetDeviceInstanceID(int device_index)
|
||||
static SDL_JoystickID RAWINPUT_JoystickGetDeviceInstanceID(int device_index)
|
||||
{
|
||||
return RAWINPUT_GetDeviceByIndex(device_index)->joystick_id;
|
||||
}
|
||||
|
||||
static int SDLCALL
|
||||
RAWINPUT_SortValueCaps(const void *A, const void *B)
|
||||
static int SDLCALL RAWINPUT_SortValueCaps(const void *A, const void *B)
|
||||
{
|
||||
HIDP_VALUE_CAPS *capsA = (HIDP_VALUE_CAPS *)A;
|
||||
HIDP_VALUE_CAPS *capsB = (HIDP_VALUE_CAPS *)B;
|
||||
|
@ -1066,8 +1039,7 @@ RAWINPUT_SortValueCaps(const void *A, const void *B)
|
|||
return (int)capsA->NotRange.Usage - capsB->NotRange.Usage;
|
||||
}
|
||||
|
||||
static int
|
||||
RAWINPUT_JoystickOpen(SDL_Joystick *joystick, int device_index)
|
||||
static int RAWINPUT_JoystickOpen(SDL_Joystick *joystick, int device_index)
|
||||
{
|
||||
SDL_RAWINPUT_Device *device = RAWINPUT_GetDeviceByIndex(device_index);
|
||||
RAWINPUT_DeviceContext *ctx;
|
||||
|
@ -1261,8 +1233,7 @@ RAWINPUT_JoystickOpen(SDL_Joystick *joystick, int device_index)
|
|||
return 0;
|
||||
}
|
||||
|
||||
static int
|
||||
RAWINPUT_JoystickRumble(SDL_Joystick *joystick, Uint16 low_frequency_rumble, Uint16 high_frequency_rumble)
|
||||
static int RAWINPUT_JoystickRumble(SDL_Joystick *joystick, Uint16 low_frequency_rumble, Uint16 high_frequency_rumble)
|
||||
{
|
||||
#if defined(SDL_JOYSTICK_RAWINPUT_WGI) || defined(SDL_JOYSTICK_RAWINPUT_XINPUT)
|
||||
RAWINPUT_DeviceContext *ctx = joystick->hwdata;
|
||||
|
@ -1310,8 +1281,7 @@ RAWINPUT_JoystickRumble(SDL_Joystick *joystick, Uint16 low_frequency_rumble, Uin
|
|||
return 0;
|
||||
}
|
||||
|
||||
static int
|
||||
RAWINPUT_JoystickRumbleTriggers(SDL_Joystick *joystick, Uint16 left_rumble, Uint16 right_rumble)
|
||||
static int RAWINPUT_JoystickRumbleTriggers(SDL_Joystick *joystick, Uint16 left_rumble, Uint16 right_rumble)
|
||||
{
|
||||
#if defined(SDL_JOYSTICK_RAWINPUT_WGI)
|
||||
RAWINPUT_DeviceContext *ctx = joystick->hwdata;
|
||||
|
@ -1334,8 +1304,7 @@ RAWINPUT_JoystickRumbleTriggers(SDL_Joystick *joystick, Uint16 left_rumble, Uint
|
|||
#endif
|
||||
}
|
||||
|
||||
static Uint32
|
||||
RAWINPUT_JoystickGetCapabilities(SDL_Joystick *joystick)
|
||||
static Uint32 RAWINPUT_JoystickGetCapabilities(SDL_Joystick *joystick)
|
||||
{
|
||||
Uint32 result = 0;
|
||||
#if defined(SDL_JOYSTICK_RAWINPUT_XINPUT) || defined(SDL_JOYSTICK_RAWINPUT_WGI)
|
||||
|
@ -1360,20 +1329,17 @@ RAWINPUT_JoystickGetCapabilities(SDL_Joystick *joystick)
|
|||
return result;
|
||||
}
|
||||
|
||||
static int
|
||||
RAWINPUT_JoystickSetLED(SDL_Joystick *joystick, Uint8 red, Uint8 green, Uint8 blue)
|
||||
static int RAWINPUT_JoystickSetLED(SDL_Joystick *joystick, Uint8 red, Uint8 green, Uint8 blue)
|
||||
{
|
||||
return SDL_Unsupported();
|
||||
}
|
||||
|
||||
static int
|
||||
RAWINPUT_JoystickSendEffect(SDL_Joystick *joystick, const void *data, int size)
|
||||
static int RAWINPUT_JoystickSendEffect(SDL_Joystick *joystick, const void *data, int size)
|
||||
{
|
||||
return SDL_Unsupported();
|
||||
}
|
||||
|
||||
static int
|
||||
RAWINPUT_JoystickSetSensorsEnabled(SDL_Joystick *joystick, SDL_bool enabled)
|
||||
static int RAWINPUT_JoystickSetSensorsEnabled(SDL_Joystick *joystick, SDL_bool enabled)
|
||||
{
|
||||
return SDL_Unsupported();
|
||||
}
|
||||
|
@ -1402,8 +1368,7 @@ static HIDP_DATA *GetData(USHORT index, HIDP_DATA *data, ULONG length)
|
|||
|
||||
We use XInput and Windows.Gaming.Input to make up for these shortcomings.
|
||||
*/
|
||||
static void
|
||||
RAWINPUT_HandleStatePacket(SDL_Joystick *joystick, Uint8 *data, int size)
|
||||
static void RAWINPUT_HandleStatePacket(SDL_Joystick *joystick, Uint8 *data, int size)
|
||||
{
|
||||
RAWINPUT_DeviceContext *ctx = joystick->hwdata;
|
||||
#ifdef SDL_JOYSTICK_RAWINPUT_MATCHING
|
||||
|
@ -1434,11 +1399,22 @@ RAWINPUT_HandleStatePacket(SDL_Joystick *joystick, Uint8 *data, int size)
|
|||
};
|
||||
Uint64 match_state = ctx->match_state;
|
||||
/* Update match_state with button bit, then fall through */
|
||||
#define SDL_PrivateJoystickButton(joystick, button, state) if (button < SDL_arraysize(button_map)) { Uint64 button_bit = 1ull << button_map[button]; match_state = (match_state & ~button_bit) | (button_bit * (state)); } SDL_PrivateJoystickButton(joystick, button, state)
|
||||
#define SDL_PrivateJoystickButton(joystick, button, state) \
|
||||
if (button < SDL_arraysize(button_map)) { \
|
||||
Uint64 button_bit = 1ull << button_map[button]; \
|
||||
match_state = (match_state & ~button_bit) | (button_bit * (state)); \
|
||||
} \
|
||||
SDL_PrivateJoystickButton(joystick, button, state)
|
||||
#ifdef SDL_JOYSTICK_RAWINPUT_MATCH_AXES
|
||||
/* Grab high 4 bits of value, then fall through */
|
||||
#define AddAxisToMatchState(axis, value) { match_state = (match_state & ~(0xFull << (4 * axis + 16))) | ((value) & 0xF000ull) << (4 * axis + 4); }
|
||||
#define SDL_PrivateJoystickAxis(joystick, axis, value) if (axis < 4) AddAxisToMatchState(axis, value); SDL_PrivateJoystickAxis(joystick, axis, value)
|
||||
#define AddAxisToMatchState(axis, value) \
|
||||
{ \
|
||||
match_state = (match_state & ~(0xFull << (4 * axis + 16))) | ((value)&0xF000ull) << (4 * axis + 4); \
|
||||
}
|
||||
#define SDL_PrivateJoystickAxis(joystick, axis, value) \
|
||||
if (axis < 4) \
|
||||
AddAxisToMatchState(axis, value); \
|
||||
SDL_PrivateJoystickAxis(joystick, axis, value)
|
||||
#endif
|
||||
#endif /* SDL_JOYSTICK_RAWINPUT_MATCHING */
|
||||
|
||||
|
@ -1504,7 +1480,11 @@ RAWINPUT_HandleStatePacket(SDL_Joystick *joystick, Uint8 *data, int size)
|
|||
#endif
|
||||
|
||||
#ifdef SDL_JOYSTICK_RAWINPUT_MATCH_TRIGGERS
|
||||
#define AddTriggerToMatchState(axis, value) { int match_axis = axis + SDL_JOYSTICK_RAWINPUT_MATCH_COUNT - joystick->naxes; AddAxisToMatchState(match_axis, value); }
|
||||
#define AddTriggerToMatchState(axis, value) \
|
||||
{ \
|
||||
int match_axis = axis + SDL_JOYSTICK_RAWINPUT_MATCH_COUNT - joystick->naxes; \
|
||||
AddAxisToMatchState(match_axis, value); \
|
||||
}
|
||||
#endif /* SDL_JOYSTICK_RAWINPUT_MATCH_TRIGGERS */
|
||||
|
||||
if (ctx->trigger_hack) {
|
||||
|
@ -1534,7 +1514,7 @@ RAWINPUT_HandleStatePacket(SDL_Joystick *joystick, Uint8 *data, int size)
|
|||
Sint16 value = (int)(Uint16)item->RawValue - 0x8000;
|
||||
Sint16 left_value = (value > 0) ? (value * 2 - 32767) : SDL_MIN_SINT16;
|
||||
Sint16 right_value = (value < 0) ? (-value * 2 - 32769) : SDL_MIN_SINT16;
|
||||
|
||||
|
||||
#ifdef SDL_JOYSTICK_RAWINPUT_MATCH_TRIGGERS
|
||||
AddTriggerToMatchState(left_trigger, left_value);
|
||||
AddTriggerToMatchState(right_trigger, right_value);
|
||||
|
@ -1563,8 +1543,7 @@ RAWINPUT_HandleStatePacket(SDL_Joystick *joystick, Uint8 *data, int size)
|
|||
#endif
|
||||
}
|
||||
|
||||
static void
|
||||
RAWINPUT_UpdateOtherAPIs(SDL_Joystick *joystick)
|
||||
static void RAWINPUT_UpdateOtherAPIs(SDL_Joystick *joystick)
|
||||
{
|
||||
#ifdef SDL_JOYSTICK_RAWINPUT_MATCHING
|
||||
RAWINPUT_DeviceContext *ctx = joystick->hwdata;
|
||||
|
@ -1581,11 +1560,11 @@ RAWINPUT_UpdateOtherAPIs(SDL_Joystick *joystick)
|
|||
RAWINPUT_FillMatchState(&match_state_xinput, ctx->match_state);
|
||||
|
||||
#ifdef SDL_JOYSTICK_RAWINPUT_WGI
|
||||
#ifdef SDL_JOYSTICK_RAWINPUT_XINPUT
|
||||
#ifdef SDL_JOYSTICK_RAWINPUT_XINPUT
|
||||
xinput_correlated = ctx->xinput_correlated;
|
||||
#else
|
||||
#else
|
||||
xinput_correlated = SDL_FALSE;
|
||||
#endif
|
||||
#endif
|
||||
/* Parallel logic to WINDOWS_XINPUT below */
|
||||
RAWINPUT_UpdateWindowsGamingInput();
|
||||
if (ctx->wgi_correlated &&
|
||||
|
@ -1811,7 +1790,7 @@ RAWINPUT_UpdateOtherAPIs(SDL_Joystick *joystick)
|
|||
#ifdef SDL_JOYSTICK_RAWINPUT_WGI
|
||||
if (!has_trigger_data && ctx->wgi_correlated) {
|
||||
RAWINPUT_UpdateWindowsGamingInput(); /* May detect disconnect / cause uncorrelation */
|
||||
if (ctx->wgi_correlated) { /* Still connected */
|
||||
if (ctx->wgi_correlated) { /* Still connected */
|
||||
struct __x_ABI_CWindows_CGaming_CInput_CGamepadReading *state = &ctx->wgi_slot->state;
|
||||
|
||||
if (ctx->guide_hack) {
|
||||
|
@ -1828,11 +1807,8 @@ RAWINPUT_UpdateOtherAPIs(SDL_Joystick *joystick)
|
|||
|
||||
if (!correlated) {
|
||||
if (!guide_button_candidate.joystick ||
|
||||
(ctx->last_state_packet && (
|
||||
!guide_button_candidate.last_state_packet ||
|
||||
SDL_TICKS_PASSED(ctx->last_state_packet, guide_button_candidate.last_state_packet)
|
||||
))
|
||||
) {
|
||||
(ctx->last_state_packet && (!guide_button_candidate.last_state_packet ||
|
||||
SDL_TICKS_PASSED(ctx->last_state_packet, guide_button_candidate.last_state_packet)))) {
|
||||
guide_button_candidate.joystick = joystick;
|
||||
guide_button_candidate.last_state_packet = ctx->last_state_packet;
|
||||
}
|
||||
|
@ -1840,14 +1816,12 @@ RAWINPUT_UpdateOtherAPIs(SDL_Joystick *joystick)
|
|||
#endif /* SDL_JOYSTICK_RAWINPUT_MATCHING */
|
||||
}
|
||||
|
||||
static void
|
||||
RAWINPUT_JoystickUpdate(SDL_Joystick *joystick)
|
||||
static void RAWINPUT_JoystickUpdate(SDL_Joystick *joystick)
|
||||
{
|
||||
RAWINPUT_UpdateOtherAPIs(joystick);
|
||||
}
|
||||
|
||||
static void
|
||||
RAWINPUT_JoystickClose(SDL_Joystick *joystick)
|
||||
static void RAWINPUT_JoystickClose(SDL_Joystick *joystick)
|
||||
{
|
||||
RAWINPUT_DeviceContext *ctx = joystick->hwdata;
|
||||
|
||||
|
@ -1912,8 +1886,7 @@ RAWINPUT_RegisterNotifications(HWND hWnd)
|
|||
return SDL_TRUE;
|
||||
}
|
||||
|
||||
void
|
||||
RAWINPUT_UnregisterNotifications()
|
||||
void RAWINPUT_UnregisterNotifications()
|
||||
{
|
||||
int i;
|
||||
RAWINPUTDEVICE rid[SDL_arraysize(subscribed_devices)];
|
||||
|
@ -1940,45 +1913,45 @@ RAWINPUT_WindowProc(HWND hWnd, UINT msg, WPARAM wParam, LPARAM lParam)
|
|||
SDL_LockJoysticks();
|
||||
|
||||
switch (msg) {
|
||||
case WM_INPUT_DEVICE_CHANGE:
|
||||
case WM_INPUT_DEVICE_CHANGE:
|
||||
{
|
||||
HANDLE hDevice = (HANDLE)lParam;
|
||||
switch (wParam) {
|
||||
case GIDC_ARRIVAL:
|
||||
RAWINPUT_AddDevice(hDevice);
|
||||
break;
|
||||
case GIDC_REMOVAL:
|
||||
{
|
||||
HANDLE hDevice = (HANDLE)lParam;
|
||||
switch (wParam) {
|
||||
case GIDC_ARRIVAL:
|
||||
RAWINPUT_AddDevice(hDevice);
|
||||
break;
|
||||
case GIDC_REMOVAL:
|
||||
{
|
||||
SDL_RAWINPUT_Device *device;
|
||||
device = RAWINPUT_DeviceFromHandle(hDevice);
|
||||
if (device) {
|
||||
RAWINPUT_DelDevice(device, SDL_TRUE);
|
||||
}
|
||||
break;
|
||||
}
|
||||
default:
|
||||
break;
|
||||
SDL_RAWINPUT_Device *device;
|
||||
device = RAWINPUT_DeviceFromHandle(hDevice);
|
||||
if (device) {
|
||||
RAWINPUT_DelDevice(device, SDL_TRUE);
|
||||
}
|
||||
break;
|
||||
}
|
||||
default:
|
||||
break;
|
||||
}
|
||||
}
|
||||
result = 0;
|
||||
break;
|
||||
|
||||
case WM_INPUT:
|
||||
{
|
||||
Uint8 data[sizeof(RAWINPUTHEADER) + sizeof(RAWHID) + USB_PACKET_LENGTH];
|
||||
UINT buffer_size = SDL_arraysize(data);
|
||||
case WM_INPUT:
|
||||
{
|
||||
Uint8 data[sizeof(RAWINPUTHEADER) + sizeof(RAWHID) + USB_PACKET_LENGTH];
|
||||
UINT buffer_size = SDL_arraysize(data);
|
||||
|
||||
if ((int)GetRawInputData((HRAWINPUT)lParam, RID_INPUT, data, &buffer_size, sizeof(RAWINPUTHEADER)) > 0) {
|
||||
PRAWINPUT raw_input = (PRAWINPUT)data;
|
||||
SDL_RAWINPUT_Device *device = RAWINPUT_DeviceFromHandle(raw_input->header.hDevice);
|
||||
if (device) {
|
||||
SDL_Joystick *joystick = device->joystick;
|
||||
if (joystick) {
|
||||
RAWINPUT_HandleStatePacket(joystick, raw_input->data.hid.bRawData, raw_input->data.hid.dwSizeHid);
|
||||
}
|
||||
if ((int)GetRawInputData((HRAWINPUT)lParam, RID_INPUT, data, &buffer_size, sizeof(RAWINPUTHEADER)) > 0) {
|
||||
PRAWINPUT raw_input = (PRAWINPUT)data;
|
||||
SDL_RAWINPUT_Device *device = RAWINPUT_DeviceFromHandle(raw_input->header.hDevice);
|
||||
if (device) {
|
||||
SDL_Joystick *joystick = device->joystick;
|
||||
if (joystick) {
|
||||
RAWINPUT_HandleStatePacket(joystick, raw_input->data.hid.bRawData, raw_input->data.hid.dwSizeHid);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
result = 0;
|
||||
break;
|
||||
}
|
||||
|
@ -1992,8 +1965,7 @@ RAWINPUT_WindowProc(HWND hWnd, UINT msg, WPARAM wParam, LPARAM lParam)
|
|||
return CallWindowProc(DefWindowProc, hWnd, msg, wParam, lParam);
|
||||
}
|
||||
|
||||
static void
|
||||
RAWINPUT_JoystickQuit(void)
|
||||
static void RAWINPUT_JoystickQuit(void)
|
||||
{
|
||||
if (!SDL_RAWINPUT_inited) {
|
||||
return;
|
||||
|
@ -2010,14 +1982,12 @@ RAWINPUT_JoystickQuit(void)
|
|||
SDL_RAWINPUT_inited = SDL_FALSE;
|
||||
}
|
||||
|
||||
static SDL_bool
|
||||
RAWINPUT_JoystickGetGamepadMapping(int device_index, SDL_GamepadMapping *out)
|
||||
static SDL_bool RAWINPUT_JoystickGetGamepadMapping(int device_index, SDL_GamepadMapping *out)
|
||||
{
|
||||
return SDL_FALSE;
|
||||
}
|
||||
|
||||
SDL_JoystickDriver SDL_RAWINPUT_JoystickDriver =
|
||||
{
|
||||
SDL_JoystickDriver SDL_RAWINPUT_JoystickDriver = {
|
||||
RAWINPUT_JoystickInit,
|
||||
RAWINPUT_JoystickGetCount,
|
||||
RAWINPUT_JoystickDetect,
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue