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:
Sam Lantinga
2022-11-30 12:51:59 -08:00
committed by GitHub
parent 14b902faca
commit 5750bcb174
781 changed files with 51659 additions and 55763 deletions

View File

@@ -45,9 +45,8 @@
#include "SDL_xinputjoystick_c.h"
#include "SDL_rawinputjoystick_c.h"
#include "../../haptic/windows/SDL_dinputhaptic_c.h" /* For haptic hot plugging */
#include "../../haptic/windows/SDL_xinputhaptic_c.h" /* For haptic hot plugging */
#include "../../haptic/windows/SDL_dinputhaptic_c.h" /* For haptic hot plugging */
#include "../../haptic/windows/SDL_xinputhaptic_c.h" /* For haptic hot plugging */
#ifndef DEVICE_NOTIFY_WINDOW_HANDLE
#define DEVICE_NOTIFY_WINDOW_HANDLE 0x00000000
@@ -63,34 +62,42 @@ extern "C" {
#endif
DECLARE_HANDLE(HCMNOTIFICATION);
typedef HCMNOTIFICATION* PHCMNOTIFICATION;
typedef HCMNOTIFICATION *PHCMNOTIFICATION;
typedef enum _CM_NOTIFY_FILTER_TYPE {
typedef enum _CM_NOTIFY_FILTER_TYPE
{
CM_NOTIFY_FILTER_TYPE_DEVICEINTERFACE = 0,
CM_NOTIFY_FILTER_TYPE_DEVICEHANDLE,
CM_NOTIFY_FILTER_TYPE_DEVICEINSTANCE,
CM_NOTIFY_FILTER_TYPE_MAX
} CM_NOTIFY_FILTER_TYPE, * PCM_NOTIFY_FILTER_TYPE;
} CM_NOTIFY_FILTER_TYPE,
*PCM_NOTIFY_FILTER_TYPE;
typedef struct _CM_NOTIFY_FILTER {
typedef struct _CM_NOTIFY_FILTER
{
DWORD cbSize;
DWORD Flags;
CM_NOTIFY_FILTER_TYPE FilterType;
DWORD Reserved;
union {
struct {
union
{
struct
{
GUID ClassGuid;
} DeviceInterface;
struct {
HANDLE hTarget;
struct
{
HANDLE hTarget;
} DeviceHandle;
struct {
struct
{
WCHAR InstanceId[200];
} DeviceInstance;
} u;
} CM_NOTIFY_FILTER, * PCM_NOTIFY_FILTER;
} CM_NOTIFY_FILTER, *PCM_NOTIFY_FILTER;
typedef enum _CM_NOTIFY_ACTION {
typedef enum _CM_NOTIFY_ACTION
{
CM_NOTIFY_ACTION_DEVICEINTERFACEARRIVAL = 0,
CM_NOTIFY_ACTION_DEVICEINTERFACEREMOVAL,
CM_NOTIFY_ACTION_DEVICEQUERYREMOVE,
@@ -102,32 +109,38 @@ typedef enum _CM_NOTIFY_ACTION {
CM_NOTIFY_ACTION_DEVICEINSTANCESTARTED,
CM_NOTIFY_ACTION_DEVICEINSTANCEREMOVED,
CM_NOTIFY_ACTION_MAX
} CM_NOTIFY_ACTION, * PCM_NOTIFY_ACTION;
} CM_NOTIFY_ACTION,
*PCM_NOTIFY_ACTION;
typedef struct _CM_NOTIFY_EVENT_DATA {
typedef struct _CM_NOTIFY_EVENT_DATA
{
CM_NOTIFY_FILTER_TYPE FilterType;
DWORD Reserved;
union {
struct {
union
{
struct
{
GUID ClassGuid;
WCHAR SymbolicLink[ANYSIZE_ARRAY];
} DeviceInterface;
struct {
struct
{
GUID EventGuid;
LONG NameOffset;
DWORD DataSize;
BYTE Data[ANYSIZE_ARRAY];
} DeviceHandle;
struct {
struct
{
WCHAR InstanceId[ANYSIZE_ARRAY];
} DeviceInstance;
} u;
} CM_NOTIFY_EVENT_DATA, * PCM_NOTIFY_EVENT_DATA;
} CM_NOTIFY_EVENT_DATA, *PCM_NOTIFY_EVENT_DATA;
typedef DWORD (CALLBACK *PCM_NOTIFY_CALLBACK)(HCMNOTIFICATION hNotify, PVOID Context, CM_NOTIFY_ACTION Action, PCM_NOTIFY_EVENT_DATA EventData, DWORD EventDataSize);
typedef DWORD(CALLBACK *PCM_NOTIFY_CALLBACK)(HCMNOTIFICATION hNotify, PVOID Context, CM_NOTIFY_ACTION Action, PCM_NOTIFY_EVENT_DATA EventData, DWORD EventDataSize);
typedef DWORD (WINAPI *CM_Register_NotificationFunc)(PCM_NOTIFY_FILTER pFilter, PVOID pContext, PCM_NOTIFY_CALLBACK pCallback, PHCMNOTIFICATION pNotifyContext);
typedef DWORD (WINAPI *CM_Unregister_NotificationFunc)(HCMNOTIFICATION NotifyContext);
typedef DWORD(WINAPI *CM_Register_NotificationFunc)(PCM_NOTIFY_FILTER pFilter, PVOID pContext, PCM_NOTIFY_CALLBACK pCallback, PHCMNOTIFICATION pNotifyContext);
typedef DWORD(WINAPI *CM_Unregister_NotificationFunc)(HCMNOTIFICATION NotifyContext);
/* local variables */
static SDL_bool s_bJoystickThread = SDL_FALSE;
@@ -138,7 +151,7 @@ static SDL_Thread *s_joystickThread = NULL;
static SDL_bool s_bJoystickThreadQuit = SDL_FALSE;
static GUID GUID_DEVINTERFACE_HID = { 0x4D1E55B2L, 0xF16F, 0x11CF, { 0x88, 0xCB, 0x00, 0x11, 0x11, 0x00, 0x00, 0x30 } };
JoyStick_DeviceData *SYS_Joystick; /* array to hold joystick ID values */
JoyStick_DeviceData *SYS_Joystick; /* array to hold joystick ID values */
#if !defined(__WINRT__) && !defined(__XBOXONE__) && !defined(__XBOXSERIES__)
static HMODULE cfgmgr32_lib_handle;
@@ -146,8 +159,7 @@ static CM_Register_NotificationFunc CM_Register_Notification;
static CM_Unregister_NotificationFunc CM_Unregister_Notification;
static HCMNOTIFICATION s_DeviceNotificationFuncHandle;
static DWORD CALLBACK
SDL_DeviceNotificationFunc(HCMNOTIFICATION hNotify, PVOID context, CM_NOTIFY_ACTION action, PCM_NOTIFY_EVENT_DATA eventData, DWORD event_data_size)
static DWORD CALLBACK SDL_DeviceNotificationFunc(HCMNOTIFICATION hNotify, PVOID context, CM_NOTIFY_ACTION action, PCM_NOTIFY_EVENT_DATA eventData, DWORD event_data_size)
{
if (action == CM_NOTIFY_ACTION_DEVICEINTERFACEARRIVAL ||
action == CM_NOTIFY_ACTION_DEVICEINTERFACEREMOVAL) {
@@ -156,8 +168,7 @@ SDL_DeviceNotificationFunc(HCMNOTIFICATION hNotify, PVOID context, CM_NOTIFY_ACT
return ERROR_SUCCESS;
}
static void
SDL_CleanupDeviceNotificationFunc(void)
static void SDL_CleanupDeviceNotificationFunc(void)
{
if (cfgmgr32_lib_handle) {
if (s_DeviceNotificationFuncHandle) {
@@ -170,8 +181,7 @@ SDL_CleanupDeviceNotificationFunc(void)
}
}
static SDL_bool
SDL_CreateDeviceNotificationFunc(void)
static SDL_bool SDL_CreateDeviceNotificationFunc(void)
{
cfgmgr32_lib_handle = LoadLibraryA("cfgmgr32.dll");
if (cfgmgr32_lib_handle) {
@@ -206,15 +216,14 @@ typedef struct
#define IDT_SDL_DEVICE_CHANGE_TIMER_2 1201
/* windowproc for our joystick detect thread message only window, to detect any USB device addition/removal */
static LRESULT CALLBACK
SDL_PrivateJoystickDetectProc(HWND hwnd, UINT msg, WPARAM wParam, LPARAM lParam)
static LRESULT CALLBACK SDL_PrivateJoystickDetectProc(HWND hwnd, UINT msg, WPARAM wParam, LPARAM lParam)
{
switch (msg) {
case WM_DEVICECHANGE:
switch (wParam) {
case DBT_DEVICEARRIVAL:
case DBT_DEVICEREMOVECOMPLETE:
if (((DEV_BROADCAST_HDR*)lParam)->dbch_devicetype == DBT_DEVTYP_DEVICEINTERFACE) {
if (((DEV_BROADCAST_HDR *)lParam)->dbch_devicetype == DBT_DEVTYP_DEVICEINTERFACE) {
/* notify 300ms and 2 seconds later to ensure all APIs have updated status */
SetTimer(hwnd, IDT_SDL_DEVICE_CHANGE_TIMER_1, 300, NULL);
SetTimer(hwnd, IDT_SDL_DEVICE_CHANGE_TIMER_2, 2000, NULL);
@@ -239,8 +248,7 @@ SDL_PrivateJoystickDetectProc(HWND hwnd, UINT msg, WPARAM wParam, LPARAM lParam)
#endif
}
static void
SDL_CleanupDeviceNotification(SDL_DeviceNotificationData *data)
static void SDL_CleanupDeviceNotification(SDL_DeviceNotificationData *data)
{
#if SDL_JOYSTICK_RAWINPUT
RAWINPUT_UnregisterNotifications();
@@ -261,8 +269,7 @@ SDL_CleanupDeviceNotification(SDL_DeviceNotificationData *data)
}
}
static int
SDL_CreateDeviceNotification(SDL_DeviceNotificationData *data)
static int SDL_CreateDeviceNotification(SDL_DeviceNotificationData *data)
{
DEV_BROADCAST_DEVICEINTERFACE dbh;
@@ -272,8 +279,8 @@ SDL_CreateDeviceNotification(SDL_DeviceNotificationData *data)
data->wincl.hInstance = GetModuleHandle(NULL);
data->wincl.lpszClassName = TEXT("Message");
data->wincl.lpfnWndProc = SDL_PrivateJoystickDetectProc; /* This function is called by windows */
data->wincl.cbSize = sizeof (WNDCLASSEX);
data->wincl.lpfnWndProc = SDL_PrivateJoystickDetectProc; /* This function is called by windows */
data->wincl.cbSize = sizeof(WNDCLASSEX);
if (!RegisterClassEx(&data->wincl)) {
WIN_SetError("Failed to create register class for joystick autodetect");
@@ -281,7 +288,7 @@ SDL_CreateDeviceNotification(SDL_DeviceNotificationData *data)
return -1;
}
data->messageWindow = (HWND)CreateWindowEx(0, TEXT("Message"), NULL, 0, 0, 0, 0, 0, HWND_MESSAGE, NULL, NULL, NULL);
data->messageWindow = (HWND)CreateWindowEx(0, TEXT("Message"), NULL, 0, 0, 0, 0, 0, HWND_MESSAGE, NULL, NULL, NULL);
if (!data->messageWindow) {
WIN_SetError("Failed to create message window for joystick autodetect");
SDL_CleanupDeviceNotification(data);
@@ -306,8 +313,7 @@ SDL_CreateDeviceNotification(SDL_DeviceNotificationData *data)
return 0;
}
static SDL_bool
SDL_WaitForDeviceNotification(SDL_DeviceNotificationData *data, SDL_mutex *mutex)
static SDL_bool SDL_WaitForDeviceNotification(SDL_DeviceNotificationData *data, SDL_mutex *mutex)
{
MSG msg;
int lastret = 1;
@@ -330,7 +336,6 @@ SDL_WaitForDeviceNotification(SDL_DeviceNotificationData *data, SDL_mutex *mutex
#endif /* !defined(__WINRT__) && !defined(__XBOXONE__) && !defined(__XBOXSERIES__) */
#if !defined(__WINRT__)
#if !defined(__XBOXONE__) && !defined(__XBOXSERIES__)
@@ -338,8 +343,7 @@ static SDL_DeviceNotificationData s_notification_data;
#endif
/* Function/thread to scan the system for joysticks. */
static int SDLCALL
SDL_JoystickThread(void *_data)
static int SDLCALL SDL_JoystickThread(void *_data)
{
#if SDL_JOYSTICK_XINPUT
SDL_bool bOpenedXInputDevices[XUSER_MAX_COUNT];
@@ -392,8 +396,7 @@ SDL_JoystickThread(void *_data)
}
/* spin up the thread to detect hotplug of devices */
static int
SDL_StartJoystickThread(void)
static int SDL_StartJoystickThread(void)
{
s_mutexJoyStickEnum = SDL_CreateMutex();
if (s_mutexJoyStickEnum == NULL) {
@@ -413,8 +416,7 @@ SDL_StartJoystickThread(void)
return 0;
}
static void
SDL_StopJoystickThread(void)
static void SDL_StopJoystickThread(void)
{
if (s_joystickThread == NULL) {
return;
@@ -458,8 +460,7 @@ static void WINDOWS_JoystickQuit(void);
* Joystick 0 should be the system default joystick.
* It should return 0, or -1 on an unrecoverable fatal error.
*/
static int
WINDOWS_JoystickInit(void)
static int WINDOWS_JoystickInit(void)
{
if (SDL_DINPUT_JoystickInit() < 0) {
WINDOWS_JoystickQuit();
@@ -501,8 +502,7 @@ WINDOWS_JoystickInit(void)
}
/* return the number of joysticks that are connected right now */
static int
WINDOWS_JoystickGetCount(void)
static int WINDOWS_JoystickGetCount(void)
{
int nJoysticks = 0;
JoyStick_DeviceData *device = SYS_Joystick;
@@ -515,14 +515,13 @@ WINDOWS_JoystickGetCount(void)
}
/* detect any new joysticks being inserted into the system */
static void
WINDOWS_JoystickDetect(void)
static void WINDOWS_JoystickDetect(void)
{
JoyStick_DeviceData *pCurList = NULL;
/* only enum the devices if the joystick thread told us something changed */
if (!s_bWindowsDeviceChanged) {
return; /* thread hasn't signaled, nothing to do right now. */
return; /* thread hasn't signaled, nothing to do right now. */
}
if (s_mutexJoyStickEnum) {
@@ -584,8 +583,7 @@ WINDOWS_JoystickDetect(void)
}
}
static const char *
WINDOWS_JoystickGetDeviceName(int device_index)
static const char *WINDOWS_JoystickGetDeviceName(int device_index)
{
JoyStick_DeviceData *device = SYS_Joystick;
int index;
@@ -597,8 +595,7 @@ WINDOWS_JoystickGetDeviceName(int device_index)
return device->joystickname;
}
static const char *
WINDOWS_JoystickGetDevicePath(int device_index)
static const char *WINDOWS_JoystickGetDevicePath(int device_index)
{
JoyStick_DeviceData *device = SYS_Joystick;
int index;
@@ -610,8 +607,7 @@ WINDOWS_JoystickGetDevicePath(int device_index)
return device->path;
}
static int
WINDOWS_JoystickGetDevicePlayerIndex(int device_index)
static int WINDOWS_JoystickGetDevicePlayerIndex(int device_index)
{
JoyStick_DeviceData *device = SYS_Joystick;
int index;
@@ -623,14 +619,12 @@ WINDOWS_JoystickGetDevicePlayerIndex(int device_index)
return device->bXInputDevice ? (int)device->XInputUserId : -1;
}
static void
WINDOWS_JoystickSetDevicePlayerIndex(int device_index, int player_index)
static void WINDOWS_JoystickSetDevicePlayerIndex(int device_index, int player_index)
{
}
/* return the stable device guid for this device index */
static SDL_JoystickGUID
WINDOWS_JoystickGetDeviceGUID(int device_index)
static SDL_JoystickGUID WINDOWS_JoystickGetDeviceGUID(int device_index)
{
JoyStick_DeviceData *device = SYS_Joystick;
int index;
@@ -643,8 +637,7 @@ WINDOWS_JoystickGetDeviceGUID(int device_index)
}
/* Function to perform the mapping between current device instance and this joysticks instance id */
static SDL_JoystickID
WINDOWS_JoystickGetDeviceInstanceID(int device_index)
static SDL_JoystickID WINDOWS_JoystickGetDeviceInstanceID(int device_index)
{
JoyStick_DeviceData *device = SYS_Joystick;
int index;
@@ -661,8 +654,7 @@ WINDOWS_JoystickGetDeviceInstanceID(int device_index)
This should fill the nbuttons and naxes fields of the joystick structure.
It returns 0, or -1 if there is an error.
*/
static int
WINDOWS_JoystickOpen(SDL_Joystick *joystick, int device_index)
static int WINDOWS_JoystickOpen(SDL_Joystick *joystick, int device_index)
{
JoyStick_DeviceData *device = SYS_Joystick;
int index;
@@ -674,7 +666,7 @@ WINDOWS_JoystickOpen(SDL_Joystick *joystick, int device_index)
/* allocate memory for system specific hardware data */
joystick->instance_id = device->nInstanceID;
joystick->hwdata =
(struct joystick_hwdata *) SDL_malloc(sizeof(struct joystick_hwdata));
(struct joystick_hwdata *)SDL_malloc(sizeof(struct joystick_hwdata));
if (joystick->hwdata == NULL) {
return SDL_OutOfMemory();
}
@@ -688,8 +680,7 @@ WINDOWS_JoystickOpen(SDL_Joystick *joystick, int device_index)
}
}
static int
WINDOWS_JoystickRumble(SDL_Joystick *joystick, Uint16 low_frequency_rumble, Uint16 high_frequency_rumble)
static int WINDOWS_JoystickRumble(SDL_Joystick *joystick, Uint16 low_frequency_rumble, Uint16 high_frequency_rumble)
{
if (joystick->hwdata->bXInputDevice) {
return SDL_XINPUT_JoystickRumble(joystick, low_frequency_rumble, high_frequency_rumble);
@@ -698,14 +689,12 @@ WINDOWS_JoystickRumble(SDL_Joystick *joystick, Uint16 low_frequency_rumble, Uint
}
}
static int
WINDOWS_JoystickRumbleTriggers(SDL_Joystick *joystick, Uint16 left_rumble, Uint16 right_rumble)
static int WINDOWS_JoystickRumbleTriggers(SDL_Joystick *joystick, Uint16 left_rumble, Uint16 right_rumble)
{
return SDL_Unsupported();
}
static Uint32
WINDOWS_JoystickGetCapabilities(SDL_Joystick *joystick)
static Uint32 WINDOWS_JoystickGetCapabilities(SDL_Joystick *joystick)
{
if (joystick->hwdata->bXInputDevice) {
return SDL_XINPUT_JoystickGetCapabilities(joystick);
@@ -714,26 +703,22 @@ WINDOWS_JoystickGetCapabilities(SDL_Joystick *joystick)
}
}
static int
WINDOWS_JoystickSetLED(SDL_Joystick *joystick, Uint8 red, Uint8 green, Uint8 blue)
static int WINDOWS_JoystickSetLED(SDL_Joystick *joystick, Uint8 red, Uint8 green, Uint8 blue)
{
return SDL_Unsupported();
}
static int
WINDOWS_JoystickSendEffect(SDL_Joystick *joystick, const void *data, int size)
static int WINDOWS_JoystickSendEffect(SDL_Joystick *joystick, const void *data, int size)
{
return SDL_Unsupported();
}
static int
WINDOWS_JoystickSetSensorsEnabled(SDL_Joystick *joystick, SDL_bool enabled)
static int WINDOWS_JoystickSetSensorsEnabled(SDL_Joystick *joystick, SDL_bool enabled)
{
return SDL_Unsupported();
}
static void
WINDOWS_JoystickUpdate(SDL_Joystick *joystick)
static void WINDOWS_JoystickUpdate(SDL_Joystick *joystick)
{
if (!joystick->hwdata) {
return;
@@ -747,8 +732,7 @@ WINDOWS_JoystickUpdate(SDL_Joystick *joystick)
}
/* Function to close a joystick after use */
static void
WINDOWS_JoystickClose(SDL_Joystick *joystick)
static void WINDOWS_JoystickClose(SDL_Joystick *joystick)
{
if (joystick->hwdata->bXInputDevice) {
SDL_XINPUT_JoystickClose(joystick);
@@ -760,8 +744,7 @@ WINDOWS_JoystickClose(SDL_Joystick *joystick)
}
/* Function to perform any system-specific joystick related cleanup */
static void
WINDOWS_JoystickQuit(void)
static void WINDOWS_JoystickQuit(void)
{
JoyStick_DeviceData *device = SYS_Joystick;
@@ -795,14 +778,12 @@ WINDOWS_JoystickQuit(void)
s_bWindowsDeviceChanged = SDL_FALSE;
}
static SDL_bool
WINDOWS_JoystickGetGamepadMapping(int device_index, SDL_GamepadMapping *out)
static SDL_bool WINDOWS_JoystickGetGamepadMapping(int device_index, SDL_GamepadMapping *out)
{
return SDL_FALSE;
}
SDL_JoystickDriver SDL_WINDOWS_JoystickDriver =
{
SDL_JoystickDriver SDL_WINDOWS_JoystickDriver = {
WINDOWS_JoystickInit,
WINDOWS_JoystickGetCount,
WINDOWS_JoystickDetect,