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
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
781 changed files with 51659 additions and 55763 deletions

View file

@ -29,9 +29,9 @@
/* This is the Linux implementation of the SDL joystick API */
#include <sys/stat.h>
#include <errno.h> /* errno, strerror */
#include <errno.h> /* errno, strerror */
#include <fcntl.h>
#include <limits.h> /* For the definition of PATH_MAX */
#include <limits.h> /* For the definition of PATH_MAX */
#ifdef HAVE_INOTIFY
#include <sys/inotify.h>
#endif
@ -52,22 +52,22 @@
#define SYN_DROPPED 3
#endif
#ifndef BTN_NORTH
#define BTN_NORTH 0x133
#define BTN_NORTH 0x133
#endif
#ifndef BTN_WEST
#define BTN_WEST 0x134
#define BTN_WEST 0x134
#endif
#ifndef BTN_DPAD_UP
#define BTN_DPAD_UP 0x220
#define BTN_DPAD_UP 0x220
#endif
#ifndef BTN_DPAD_DOWN
#define BTN_DPAD_DOWN 0x221
#define BTN_DPAD_DOWN 0x221
#endif
#ifndef BTN_DPAD_LEFT
#define BTN_DPAD_LEFT 0x222
#define BTN_DPAD_LEFT 0x222
#endif
#ifndef BTN_DPAD_RIGHT
#define BTN_DPAD_RIGHT 0x223
#define BTN_DPAD_RIGHT 0x223
#endif
#include "../../core/linux/SDL_evdev_capabilities.h"
@ -99,8 +99,8 @@ static int MaybeRemoveDevice(const char *path);
typedef struct SDL_joylist_item
{
SDL_JoystickID device_instance;
char *path; /* "/dev/input/event2" or whatever */
char *name; /* "SideWinder 3D Pro" or whatever */
char *path; /* "/dev/input/event2" or whatever */
char *name; /* "SideWinder 3D Pro" or whatever */
SDL_JoystickGUID guid;
dev_t devnum;
struct joystick_hwdata *hwdata;
@ -122,8 +122,7 @@ static int inotify_fd = -1;
static Uint32 last_joy_detect_time;
static time_t last_input_dir_mtime;
static void
FixupDeviceInfoForMapping(int fd, struct input_id *inpid)
static void FixupDeviceInfoForMapping(int fd, struct input_id *inpid)
{
if (inpid->vendor == 0x045e && inpid->product == 0x0b05 && inpid->version == 0x0903) {
/* This is a Microsoft Xbox One Elite Series 2 controller */
@ -140,15 +139,13 @@ FixupDeviceInfoForMapping(int fd, struct input_id *inpid)
/* For Atari vcs modern and classic controllers have the version reflecting
* firmware version, but the mapping stays stable so ignore
* version information */
if (inpid->vendor == 0x3250
&& (inpid->product == 0x1001 || inpid->product == 0x1002)) {
if (inpid->vendor == 0x3250 && (inpid->product == 0x1001 || inpid->product == 0x1002)) {
inpid->version = 0;
}
}
#ifdef SDL_JOYSTICK_HIDAPI
static SDL_bool
IsVirtualJoystick(Uint16 vendor, Uint16 product, Uint16 version, const char *name)
static SDL_bool IsVirtualJoystick(Uint16 vendor, Uint16 product, Uint16 version, const char *name)
{
if (vendor == USB_VENDOR_MICROSOFT && product == USB_PRODUCT_XBOX_ONE_S && version == 0 &&
SDL_strcmp(name, "Xbox One S Controller") == 0) {
@ -159,8 +156,7 @@ IsVirtualJoystick(Uint16 vendor, Uint16 product, Uint16 version, const char *nam
}
#endif /* SDL_JOYSTICK_HIDAPI */
static int
GuessIsJoystick(int fd)
static int GuessIsJoystick(int fd)
{
unsigned long evbit[NBITS(EV_MAX)] = { 0 };
unsigned long keybit[NBITS(KEY_MAX)] = { 0 };
@ -184,8 +180,7 @@ GuessIsJoystick(int fd)
return 0;
}
static int
IsJoystick(const char *path, int fd, char **name_return, SDL_JoystickGUID *guid)
static int IsJoystick(const char *path, int fd, char **name_return, SDL_JoystickGUID *guid)
{
struct input_id inpid;
char *name;
@ -249,39 +244,37 @@ static void joystick_udev_callback(SDL_UDEV_deviceevent udev_type, int udev_clas
}
switch (udev_type) {
case SDL_UDEV_DEVICEADDED:
if (!(udev_class & SDL_UDEV_DEVICE_JOYSTICK)) {
case SDL_UDEV_DEVICEADDED:
if (!(udev_class & SDL_UDEV_DEVICE_JOYSTICK)) {
return;
}
if (SDL_classic_joysticks) {
if (!IsJoystickJSNode(devpath)) {
return;
}
if (SDL_classic_joysticks) {
if (!IsJoystickJSNode(devpath)) {
return;
}
} else {
if (IsJoystickJSNode(devpath)) {
return;
}
} else {
if (IsJoystickJSNode(devpath)) {
return;
}
}
/* Wait a bit for the hidraw udev node to initialize */
SDL_Delay(10);
/* Wait a bit for the hidraw udev node to initialize */
SDL_Delay(10);
MaybeAddDevice(devpath);
break;
case SDL_UDEV_DEVICEREMOVED:
MaybeRemoveDevice(devpath);
break;
default:
break;
MaybeAddDevice(devpath);
break;
case SDL_UDEV_DEVICEREMOVED:
MaybeRemoveDevice(devpath);
break;
default:
break;
}
}
#endif /* SDL_USE_LIBUDEV */
static void
FreeJoylistItem(SDL_joylist_item *item)
static void FreeJoylistItem(SDL_joylist_item *item)
{
SDL_free(item->mapping);
SDL_free(item->path);
@ -289,8 +282,7 @@ FreeJoylistItem(SDL_joylist_item *item)
SDL_free(item);
}
static int
MaybeAddDevice(const char *path)
static int MaybeAddDevice(const char *path)
{
struct stat sb;
int fd = -1;
@ -310,7 +302,7 @@ MaybeAddDevice(const char *path)
/* Check to make sure it's not already in list. */
for (item = SDL_joylist; item != NULL; item = item->next) {
if (sb.st_rdev == item->devnum) {
return -1; /* already have this one */
return -1; /* already have this one */
}
}
@ -329,7 +321,7 @@ MaybeAddDevice(const char *path)
return -1;
}
item = (SDL_joylist_item *) SDL_calloc(1, sizeof (SDL_joylist_item));
item = (SDL_joylist_item *)SDL_calloc(1, sizeof(SDL_joylist_item));
if (item == NULL) {
SDL_free(name);
return -1;
@ -341,8 +333,8 @@ MaybeAddDevice(const char *path)
item->guid = guid;
if ((item->path == NULL) || (item->name == NULL)) {
FreeJoylistItem(item);
return -1;
FreeJoylistItem(item);
return -1;
}
item->device_instance = SDL_GetNextJoystickInstanceID();
@ -361,8 +353,7 @@ MaybeAddDevice(const char *path)
return numjoysticks;
}
static void
RemoveJoylistItem(SDL_joylist_item *item, SDL_joylist_item *prev)
static void RemoveJoylistItem(SDL_joylist_item *item, SDL_joylist_item *prev)
{
if (item->hwdata) {
item->hwdata->item = NULL;
@ -386,8 +377,7 @@ RemoveJoylistItem(SDL_joylist_item *item, SDL_joylist_item *prev)
FreeJoylistItem(item);
}
static int
MaybeRemoveDevice(const char *path)
static int MaybeRemoveDevice(const char *path)
{
SDL_joylist_item *item;
SDL_joylist_item *prev = NULL;
@ -409,8 +399,7 @@ MaybeRemoveDevice(const char *path)
return -1;
}
static void
HandlePendingRemovals(void)
static void HandlePendingRemovals(void)
{
SDL_joylist_item *prev = NULL;
SDL_joylist_item *item = SDL_joylist;
@ -435,7 +424,7 @@ static SDL_bool SteamControllerConnectedCallback(const char *name, SDL_JoystickG
{
SDL_joylist_item *item;
item = (SDL_joylist_item *) SDL_calloc(1, sizeof (SDL_joylist_item));
item = (SDL_joylist_item *)SDL_calloc(1, sizeof(SDL_joylist_item));
if (item == NULL) {
return SDL_FALSE;
}
@ -446,8 +435,8 @@ static SDL_bool SteamControllerConnectedCallback(const char *name, SDL_JoystickG
item->m_bSteamController = SDL_TRUE;
if ((item->path == NULL) || (item->name == NULL)) {
FreeJoylistItem(item);
return SDL_FALSE;
FreeJoylistItem(item);
return SDL_FALSE;
}
*device_instance = item->device_instance = SDL_GetNextJoystickInstanceID();
@ -481,14 +470,12 @@ static void SteamControllerDisconnectedCallback(int device_instance)
}
}
static int
StrHasPrefix(const char *string, const char *prefix)
static int StrHasPrefix(const char *string, const char *prefix)
{
return SDL_strncmp(string, prefix, SDL_strlen(prefix)) == 0;
}
static int
StrIsInteger(const char *string)
static int StrIsInteger(const char *string)
{
const char *p;
@ -505,8 +492,7 @@ StrIsInteger(const char *string)
return 1;
}
static SDL_bool
IsJoystickJSNode(const char *node)
static SDL_bool IsJoystickJSNode(const char *node)
{
const char *last_slash = SDL_strrchr(node, '/');
if (last_slash) {
@ -515,8 +501,7 @@ IsJoystickJSNode(const char *node)
return StrHasPrefix(node, "js") && StrIsInteger(node + 2);
}
static SDL_bool
IsJoystickEventNode(const char *node)
static SDL_bool IsJoystickEventNode(const char *node)
{
const char *last_slash = SDL_strrchr(node, '/');
if (last_slash) {
@ -525,8 +510,7 @@ IsJoystickEventNode(const char *node)
return StrHasPrefix(node, "event") && StrIsInteger(node + 5);
}
static SDL_bool
IsJoystickDeviceNode(const char *node)
static SDL_bool IsJoystickDeviceNode(const char *node)
{
if (SDL_classic_joysticks) {
return IsJoystickJSNode(node);
@ -537,11 +521,13 @@ IsJoystickDeviceNode(const char *node)
#ifdef HAVE_INOTIFY
#ifdef HAVE_INOTIFY_INIT1
static int SDL_inotify_init1(void) {
static int SDL_inotify_init1(void)
{
return inotify_init1(IN_NONBLOCK | IN_CLOEXEC);
}
#else
static int SDL_inotify_init1(void) {
static int SDL_inotify_init1(void)
{
int fd = inotify_init();
if (fd < 0) {
return -1;
@ -552,24 +538,23 @@ static int SDL_inotify_init1(void) {
}
#endif
static void
LINUX_InotifyJoystickDetect(void)
static void LINUX_InotifyJoystickDetect(void)
{
union
{
struct inotify_event event;
char storage[4096];
char enough_for_inotify[sizeof (struct inotify_event) + NAME_MAX + 1];
char enough_for_inotify[sizeof(struct inotify_event) + NAME_MAX + 1];
} buf;
ssize_t bytes;
size_t remain = 0;
size_t len;
char path[PATH_MAX];
bytes = read(inotify_fd, &buf, sizeof (buf));
bytes = read(inotify_fd, &buf, sizeof(buf));
if (bytes > 0) {
remain = (size_t) bytes;
remain = (size_t)bytes;
}
while (remain > 0) {
@ -585,11 +570,11 @@ LINUX_InotifyJoystickDetect(void)
}
}
len = sizeof (struct inotify_event) + buf.event.len;
len = sizeof(struct inotify_event) + buf.event.len;
remain -= len;
if (remain != 0) {
SDL_memmove (&buf.storage[0], &buf.storage[len], remain);
SDL_memmove(&buf.storage[0], &buf.storage[len], remain);
}
}
}
@ -606,7 +591,7 @@ static int get_event_joystick_index(int event)
count = scandir(path, &entries, NULL, alphasort);
for (i = 0; i < count; ++i) {
if (SDL_strncmp(entries[i]->d_name, "js", 2) == 0) {
joystick_index = SDL_atoi(entries[i]->d_name+2);
joystick_index = SDL_atoi(entries[i]->d_name + 2);
}
free(entries[i]); /* This should NOT be SDL_free() */
}
@ -619,13 +604,11 @@ static int get_event_joystick_index(int event)
* have to do this the first time, to detect devices that already existed
* before we started; in the non-inotify code path we do this repeatedly
* (polling). */
static int
filter_entries(const struct dirent *entry)
static int filter_entries(const struct dirent *entry)
{
return IsJoystickDeviceNode(entry->d_name);
}
static int
sort_entries(const void *_a, const void *_b)
static int sort_entries(const void *_a, const void *_b)
{
const struct dirent **a = (const struct dirent **)_a;
const struct dirent **b = (const struct dirent **)_b;
@ -634,12 +617,12 @@ sort_entries(const void *_a, const void *_b)
if (SDL_classic_joysticks) {
offset = 2; /* strlen("js") */
numA = SDL_atoi((*a)->d_name+offset);
numB = SDL_atoi((*b)->d_name+offset);
numA = SDL_atoi((*a)->d_name + offset);
numB = SDL_atoi((*b)->d_name + offset);
} else {
offset = 5; /* strlen("event") */
numA = SDL_atoi((*a)->d_name+offset);
numB = SDL_atoi((*b)->d_name+offset);
numA = SDL_atoi((*a)->d_name + offset);
numB = SDL_atoi((*b)->d_name + offset);
/* See if we can get the joystick ordering */
{
@ -658,10 +641,9 @@ sort_entries(const void *_a, const void *_b)
return numA - numB;
}
static void
LINUX_FallbackJoystickDetect(void)
static void LINUX_FallbackJoystickDetect(void)
{
const Uint32 SDL_JOY_DETECT_INTERVAL_MS = 3000; /* Update every 3 seconds */
const Uint32 SDL_JOY_DETECT_INTERVAL_MS = 3000; /* Update every 3 seconds */
Uint32 now = SDL_GetTicks();
if (!last_joy_detect_time || SDL_TICKS_PASSED(now, last_joy_detect_time + SDL_JOY_DETECT_INTERVAL_MS)) {
@ -692,8 +674,7 @@ LINUX_FallbackJoystickDetect(void)
}
}
static void
LINUX_JoystickDetect(void)
static void LINUX_JoystickDetect(void)
{
#if SDL_USE_LIBUDEV
if (enumeration_method == ENUMERATION_LIBUDEV) {
@ -701,7 +682,7 @@ LINUX_JoystickDetect(void)
} else
#endif
#ifdef HAVE_INOTIFY
if (inotify_fd >= 0 && last_joy_detect_time != 0) {
if (inotify_fd >= 0 && last_joy_detect_time != 0) {
LINUX_InotifyJoystickDetect();
} else
#endif
@ -714,8 +695,7 @@ LINUX_JoystickDetect(void)
SDL_UpdateSteamControllers();
}
static int
LINUX_JoystickInit(void)
static int LINUX_JoystickInit(void)
{
const char *devices = SDL_GetHint(SDL_HINT_JOYSTICK_DEVICE);
@ -789,7 +769,7 @@ LINUX_JoystickInit(void)
if (inotify_fd < 0) {
SDL_LogWarn(SDL_LOG_CATEGORY_INPUT,
"Unable to initialize inotify, falling back to polling: %s",
strerror (errno));
strerror(errno));
} else {
/* We need to watch for attribute changes in addition to
* creation, because when a device is first created, it has
@ -802,7 +782,7 @@ LINUX_JoystickInit(void)
inotify_fd = -1;
SDL_LogWarn(SDL_LOG_CATEGORY_INPUT,
"Unable to add inotify watch, falling back to polling: %s",
strerror (errno));
strerror(errno));
}
}
#endif /* HAVE_INOTIFY */
@ -811,14 +791,12 @@ LINUX_JoystickInit(void)
return 0;
}
static int
LINUX_JoystickGetCount(void)
static int LINUX_JoystickGetCount(void)
{
return numjoysticks;
}
static SDL_joylist_item *
JoystickByDevIndex(int device_index)
static SDL_joylist_item *JoystickByDevIndex(int device_index)
{
SDL_joylist_item *item = SDL_joylist;
@ -835,50 +813,43 @@ JoystickByDevIndex(int device_index)
return item;
}
static const char *
LINUX_JoystickGetDeviceName(int device_index)
static const char *LINUX_JoystickGetDeviceName(int device_index)
{
return JoystickByDevIndex(device_index)->name;
}
static const char *
LINUX_JoystickGetDevicePath(int device_index)
static const char *LINUX_JoystickGetDevicePath(int device_index)
{
return JoystickByDevIndex(device_index)->path;
}
static int
LINUX_JoystickGetDevicePlayerIndex(int device_index)
static int LINUX_JoystickGetDevicePlayerIndex(int device_index)
{
return -1;
}
static void
LINUX_JoystickSetDevicePlayerIndex(int device_index, int player_index)
static void LINUX_JoystickSetDevicePlayerIndex(int device_index, int player_index)
{
}
static SDL_JoystickGUID
LINUX_JoystickGetDeviceGUID( int device_index )
static SDL_JoystickGUID LINUX_JoystickGetDeviceGUID(int device_index)
{
return JoystickByDevIndex(device_index)->guid;
}
/* Function to perform the mapping from device index to the instance id for this index */
static SDL_JoystickID
LINUX_JoystickGetDeviceInstanceID(int device_index)
static SDL_JoystickID LINUX_JoystickGetDeviceInstanceID(int device_index)
{
return JoystickByDevIndex(device_index)->device_instance;
}
static int
allocate_hatdata(SDL_Joystick *joystick)
static int allocate_hatdata(SDL_Joystick *joystick)
{
int i;
joystick->hwdata->hats =
(struct hwdata_hat *) SDL_malloc(joystick->nhats *
sizeof(struct hwdata_hat));
(struct hwdata_hat *)SDL_malloc(joystick->nhats *
sizeof(struct hwdata_hat));
if (joystick->hwdata->hats == NULL) {
return -1;
}
@ -889,14 +860,13 @@ allocate_hatdata(SDL_Joystick *joystick)
return 0;
}
static int
allocate_balldata(SDL_Joystick *joystick)
static int allocate_balldata(SDL_Joystick *joystick)
{
int i;
joystick->hwdata->balls =
(struct hwdata_ball *) SDL_malloc(joystick->nballs *
sizeof(struct hwdata_ball));
(struct hwdata_ball *)SDL_malloc(joystick->nballs *
sizeof(struct hwdata_ball));
if (joystick->hwdata->balls == NULL) {
return -1;
}
@ -907,8 +877,7 @@ allocate_balldata(SDL_Joystick *joystick)
return 0;
}
static SDL_bool
GuessIfAxesAreDigitalHat(struct input_absinfo *absinfo_x, struct input_absinfo *absinfo_y)
static SDL_bool GuessIfAxesAreDigitalHat(struct input_absinfo *absinfo_x, struct input_absinfo *absinfo_y)
{
/* A "hat" is assumed to be a digital input with at most 9 possible states
* (3 per axis: negative/zero/positive), as opposed to a true "axis" which
@ -940,8 +909,7 @@ GuessIfAxesAreDigitalHat(struct input_absinfo *absinfo_x, struct input_absinfo *
return SDL_FALSE;
}
static void
ConfigJoystick(SDL_Joystick *joystick, int fd)
static void ConfigJoystick(SDL_Joystick *joystick, int fd)
{
int i, t;
unsigned long keybit[NBITS(KEY_MAX)] = { 0 };
@ -989,8 +957,8 @@ ConfigJoystick(SDL_Joystick *joystick, int fd)
if (test_bit(i + 1, absbit)) {
hat_y = ioctl(fd, EVIOCGABS(i + 1), &absinfo_y);
}
if (GuessIfAxesAreDigitalHat((hat_x < 0 ? (void*)0 : &absinfo_x),
(hat_y < 0 ? (void*)0 : &absinfo_y))) {
if (GuessIfAxesAreDigitalHat((hat_x < 0 ? (void *)0 : &absinfo_x),
(hat_y < 0 ? (void *)0 : &absinfo_y))) {
const int hat_index = (i - ABS_HAT0X) / 2;
struct hat_axis_correct *correct = &joystick->hwdata->hat_correct[hat_index];
#ifdef DEBUG_INPUT_EVENTS
@ -1010,9 +978,9 @@ ConfigJoystick(SDL_Joystick *joystick, int fd)
joystick->hwdata->has_hat[hat_index] = SDL_TRUE;
correct->use_deadzones = use_hat_deadzones;
correct->minimum[0] = (hat_x < 0) ? -1 : absinfo_x.minimum;
correct->maximum[0] = (hat_x < 0) ? 1 : absinfo_x.maximum;
correct->maximum[0] = (hat_x < 0) ? 1 : absinfo_x.maximum;
correct->minimum[1] = (hat_y < 0) ? -1 : absinfo_y.minimum;
correct->maximum[1] = (hat_y < 0) ? 1 : absinfo_y.maximum;
correct->maximum[1] = (hat_y < 0) ? 1 : absinfo_y.maximum;
++joystick->nhats;
}
}
@ -1115,9 +1083,9 @@ ConfigJoystick(SDL_Joystick *joystick, int fd)
joystick->hwdata->hats_indices[hat_index] = joystick->nhats++;
joystick->hwdata->has_hat[hat_index] = SDL_TRUE;
joystick->hwdata->hat_correct[hat_index].minimum[0] = -1;
joystick->hwdata->hat_correct[hat_index].maximum[0] = 1;
joystick->hwdata->hat_correct[hat_index].maximum[0] = 1;
joystick->hwdata->hat_correct[hat_index].minimum[1] = -1;
joystick->hwdata->hat_correct[hat_index].maximum[1] = 1;
joystick->hwdata->hat_correct[hat_index].maximum[1] = 1;
}
} else {
#ifdef DEBUG_INPUT_EVENTS
@ -1152,14 +1120,12 @@ ConfigJoystick(SDL_Joystick *joystick, int fd)
}
}
/* This is used to do the heavy lifting for LINUX_JoystickOpen and
also LINUX_JoystickGetGamepadMapping, so we can query the hardware
without adding an opened SDL_Joystick object to the system.
This expects `joystick->hwdata` to be allocated and will not free it
on error. Returns -1 on error, 0 on success. */
static int
PrepareJoystickHwdata(SDL_Joystick *joystick, SDL_joylist_item *item)
static int PrepareJoystickHwdata(SDL_Joystick *joystick, SDL_joylist_item *item)
{
joystick->hwdata->item = item;
joystick->hwdata->guid = item->guid;
@ -1200,14 +1166,12 @@ PrepareJoystickHwdata(SDL_Joystick *joystick, SDL_joylist_item *item)
return 0;
}
/* Function to open a joystick for use.
The joystick to open is specified by the 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
LINUX_JoystickOpen(SDL_Joystick *joystick, int device_index)
static int LINUX_JoystickOpen(SDL_Joystick *joystick, int device_index)
{
SDL_joylist_item *item = JoystickByDevIndex(device_index);
@ -1225,7 +1189,7 @@ LINUX_JoystickOpen(SDL_Joystick *joystick, int device_index)
if (PrepareJoystickHwdata(joystick, item) == -1) {
SDL_free(joystick->hwdata);
joystick->hwdata = NULL;
return -1; /* SDL_SetError will already have been called */
return -1; /* SDL_SetError will already have been called */
}
SDL_assert(item->hwdata == NULL);
@ -1237,8 +1201,7 @@ LINUX_JoystickOpen(SDL_Joystick *joystick, int device_index)
return 0;
}
static int
LINUX_JoystickRumble(SDL_Joystick *joystick, Uint16 low_frequency_rumble, Uint16 high_frequency_rumble)
static int LINUX_JoystickRumble(SDL_Joystick *joystick, Uint16 low_frequency_rumble, Uint16 high_frequency_rumble)
{
struct input_event event;
@ -1279,14 +1242,12 @@ LINUX_JoystickRumble(SDL_Joystick *joystick, Uint16 low_frequency_rumble, Uint16
return 0;
}
static int
LINUX_JoystickRumbleTriggers(SDL_Joystick *joystick, Uint16 left_rumble, Uint16 right_rumble)
static int LINUX_JoystickRumbleTriggers(SDL_Joystick *joystick, Uint16 left_rumble, Uint16 right_rumble)
{
return SDL_Unsupported();
}
static Uint32
LINUX_JoystickGetCapabilities(SDL_Joystick *joystick)
static Uint32 LINUX_JoystickGetCapabilities(SDL_Joystick *joystick)
{
Uint32 result = 0;
@ -1297,34 +1258,30 @@ LINUX_JoystickGetCapabilities(SDL_Joystick *joystick)
return result;
}
static int
LINUX_JoystickSetLED(SDL_Joystick *joystick, Uint8 red, Uint8 green, Uint8 blue)
static int LINUX_JoystickSetLED(SDL_Joystick *joystick, Uint8 red, Uint8 green, Uint8 blue)
{
return SDL_Unsupported();
}
static int
LINUX_JoystickSendEffect(SDL_Joystick *joystick, const void *data, int size)
static int LINUX_JoystickSendEffect(SDL_Joystick *joystick, const void *data, int size)
{
return SDL_Unsupported();
}
static int
LINUX_JoystickSetSensorsEnabled(SDL_Joystick *joystick, SDL_bool enabled)
static int LINUX_JoystickSetSensorsEnabled(SDL_Joystick *joystick, SDL_bool enabled)
{
return SDL_Unsupported();
}
static void
HandleHat(SDL_Joystick *stick, int hatidx, int axis, int value)
static void HandleHat(SDL_Joystick *stick, int hatidx, int axis, int value)
{
const int hatnum = stick->hwdata->hats_indices[hatidx];
struct hwdata_hat *the_hat;
struct hat_axis_correct *correct;
const Uint8 position_map[3][3] = {
{SDL_HAT_LEFTUP, SDL_HAT_UP, SDL_HAT_RIGHTUP},
{SDL_HAT_LEFT, SDL_HAT_CENTERED, SDL_HAT_RIGHT},
{SDL_HAT_LEFTDOWN, SDL_HAT_DOWN, SDL_HAT_RIGHTDOWN}
{ SDL_HAT_LEFTUP, SDL_HAT_UP, SDL_HAT_RIGHTUP },
{ SDL_HAT_LEFT, SDL_HAT_CENTERED, SDL_HAT_RIGHT },
{ SDL_HAT_LEFTDOWN, SDL_HAT_DOWN, SDL_HAT_RIGHTDOWN }
};
the_hat = &stick->hwdata->hats[hatnum];
@ -1362,15 +1319,12 @@ HandleHat(SDL_Joystick *stick, int hatidx, int axis, int value)
}
}
static void
HandleBall(SDL_Joystick *stick, Uint8 ball, int axis, int value)
static void HandleBall(SDL_Joystick *stick, Uint8 ball, int axis, int value)
{
stick->hwdata->balls[ball].axis[axis] += value;
}
static int
AxisCorrect(SDL_Joystick *joystick, int which, int value)
static int AxisCorrect(SDL_Joystick *joystick, int which, int value)
{
struct axis_correct *correct;
@ -1403,8 +1357,7 @@ AxisCorrect(SDL_Joystick *joystick, int which, int value)
return value;
}
static void
PollAllValues(SDL_Joystick *joystick)
static void PollAllValues(SDL_Joystick *joystick)
{
struct input_absinfo absinfo;
unsigned long keyinfo[NBITS(KEY_MAX)];
@ -1419,11 +1372,11 @@ PollAllValues(SDL_Joystick *joystick)
#ifdef DEBUG_INPUT_EVENTS
SDL_Log("Joystick : Re-read Axis %d (%d) val= %d\n",
joystick->hwdata->abs_map[i], i, absinfo.value);
joystick->hwdata->abs_map[i], i, absinfo.value);
#endif
SDL_PrivateJoystickAxis(joystick,
joystick->hwdata->abs_map[i],
absinfo.value);
joystick->hwdata->abs_map[i],
absinfo.value);
}
}
}
@ -1444,16 +1397,16 @@ PollAllValues(SDL_Joystick *joystick)
/* Poll all buttons */
SDL_zeroa(keyinfo);
if (ioctl(joystick->hwdata->fd, EVIOCGKEY(sizeof (keyinfo)), keyinfo) >= 0) {
if (ioctl(joystick->hwdata->fd, EVIOCGKEY(sizeof(keyinfo)), keyinfo) >= 0) {
for (i = 0; i < KEY_MAX; i++) {
if (joystick->hwdata->has_key[i]) {
const Uint8 value = test_bit(i, keyinfo) ? SDL_PRESSED : SDL_RELEASED;
#ifdef DEBUG_INPUT_EVENTS
SDL_Log("Joystick : Re-read Button %d (%d) val= %d\n",
joystick->hwdata->key_map[i], i, value);
joystick->hwdata->key_map[i], i, value);
#endif
SDL_PrivateJoystickButton(joystick,
joystick->hwdata->key_map[i], value);
joystick->hwdata->key_map[i], value);
}
}
}
@ -1461,8 +1414,7 @@ PollAllValues(SDL_Joystick *joystick)
/* Joyballs are relative input, so there's no poll state. Events only! */
}
static void
HandleInputEvents(SDL_Joystick *joystick)
static void HandleInputEvents(SDL_Joystick *joystick)
{
struct input_event events[32];
int i, len, code, hat_index;
@ -1479,8 +1431,8 @@ HandleInputEvents(SDL_Joystick *joystick)
/* If the kernel sent a SYN_DROPPED, we are supposed to ignore the
rest of the packet (the end of it signified by a SYN_REPORT) */
if ( joystick->hwdata->recovering_from_dropped &&
((events[i].type != EV_SYN) || (code != SYN_REPORT)) ) {
if (joystick->hwdata->recovering_from_dropped &&
((events[i].type != EV_SYN) || (code != SYN_REPORT))) {
continue;
}
@ -1526,16 +1478,16 @@ HandleInputEvents(SDL_Joystick *joystick)
break;
case EV_SYN:
switch (code) {
case SYN_DROPPED :
case SYN_DROPPED:
#ifdef DEBUG_INPUT_EVENTS
SDL_Log("Event SYN_DROPPED detected\n");
#endif
joystick->hwdata->recovering_from_dropped = SDL_TRUE;
break;
case SYN_REPORT :
case SYN_REPORT:
if (joystick->hwdata->recovering_from_dropped) {
joystick->hwdata->recovering_from_dropped = SDL_FALSE;
PollAllValues(joystick); /* try to sync up to current state now */
PollAllValues(joystick); /* try to sync up to current state now */
}
break;
default:
@ -1553,8 +1505,7 @@ HandleInputEvents(SDL_Joystick *joystick)
}
}
static void
HandleClassicEvents(SDL_Joystick *joystick)
static void HandleClassicEvents(SDL_Joystick *joystick)
{
struct js_event events[32];
int i, len, code, hat_index;
@ -1597,8 +1548,7 @@ HandleClassicEvents(SDL_Joystick *joystick)
}
}
static void
LINUX_JoystickUpdate(SDL_Joystick *joystick)
static void LINUX_JoystickUpdate(SDL_Joystick *joystick)
{
int i;
@ -1622,14 +1572,13 @@ LINUX_JoystickUpdate(SDL_Joystick *joystick)
if (xrel || yrel) {
joystick->hwdata->balls[i].axis[0] = 0;
joystick->hwdata->balls[i].axis[1] = 0;
SDL_PrivateJoystickBall(joystick, (Uint8) i, xrel, yrel);
SDL_PrivateJoystickBall(joystick, (Uint8)i, xrel, yrel);
}
}
}
/* Function to close a joystick after use */
static void
LINUX_JoystickClose(SDL_Joystick *joystick)
static void LINUX_JoystickClose(SDL_Joystick *joystick)
{
if (joystick->hwdata) {
if (joystick->hwdata->effect.id >= 0) {
@ -1652,8 +1601,7 @@ LINUX_JoystickClose(SDL_Joystick *joystick)
}
/* Function to perform any system-specific joystick related cleanup */
static void
LINUX_JoystickQuit(void)
static void LINUX_JoystickQuit(void)
{
SDL_joylist_item *item = NULL;
SDL_joylist_item *next = NULL;
@ -1686,8 +1634,7 @@ LINUX_JoystickQuit(void)
This is based on the Linux Gamepad Specification
available at: https://www.kernel.org/doc/html/v4.15/input/gamepad.html
*/
static SDL_bool
LINUX_JoystickGetGamepadMapping(int device_index, SDL_GamepadMapping *out)
static SDL_bool LINUX_JoystickGetGamepadMapping(int device_index, SDL_GamepadMapping *out)
{
SDL_Joystick *joystick;
SDL_joylist_item *item = JoystickByDevIndex(device_index);
@ -1707,7 +1654,7 @@ LINUX_JoystickGetGamepadMapping(int device_index, SDL_GamepadMapping *out)
/* We temporarily open the device to check how it's configured. Make
a fake SDL_Joystick object to do so. */
joystick = (SDL_Joystick *) SDL_calloc(sizeof(*joystick), 1);
joystick = (SDL_Joystick *)SDL_calloc(sizeof(*joystick), 1);
if (joystick == NULL) {
SDL_OutOfMemory();
return SDL_FALSE;
@ -1727,7 +1674,7 @@ LINUX_JoystickGetGamepadMapping(int device_index, SDL_GamepadMapping *out)
if (PrepareJoystickHwdata(joystick, item) == -1) {
SDL_free(joystick->hwdata);
SDL_free(joystick);
return SDL_FALSE; /* SDL_SetError will already have been called */
return SDL_FALSE; /* SDL_SetError will already have been called */
}
/* don't assign `item->hwdata` so it's not in any global state. */
@ -2007,7 +1954,7 @@ LINUX_JoystickGetGamepadMapping(int device_index, SDL_GamepadMapping *out)
out->dpdown.target = hat | 0x4;
mapped |= 0xF;
#ifdef DEBUG_GAMEPAD_MAPPING
SDL_Log("Mapped DPUP+DOWN+LEFT+RIGHT to hat 0 (ABS_HAT0X, ABS_HAT0Y)");
SDL_Log("Mapped DPUP+DOWN+LEFT+RIGHT to hat 0 (ABS_HAT0X, ABS_HAT0Y)");
#endif
} else if (joystick->hwdata->has_abs[ABS_HAT0X] && joystick->hwdata->has_abs[ABS_HAT0Y]) {
out->dpleft.kind = EMappingKind_Axis;
@ -2020,8 +1967,8 @@ LINUX_JoystickGetGamepadMapping(int device_index, SDL_GamepadMapping *out)
out->dpdown.target = joystick->hwdata->abs_map[ABS_HAT0Y];
mapped |= 0xF;
#ifdef DEBUG_GAMEPAD_MAPPING
SDL_Log("Mapped DPUP+DOWN to axis %d (ABS_HAT0Y)", out->dpup.target);
SDL_Log("Mapped DPLEFT+RIGHT to axis %d (ABS_HAT0X)", out->dpleft.target);
SDL_Log("Mapped DPUP+DOWN to axis %d (ABS_HAT0Y)", out->dpup.target);
SDL_Log("Mapped DPLEFT+RIGHT to axis %d (ABS_HAT0X)", out->dpleft.target);
#endif
}
}
@ -2063,8 +2010,7 @@ LINUX_JoystickGetGamepadMapping(int device_index, SDL_GamepadMapping *out)
return SDL_TRUE;
}
SDL_JoystickDriver SDL_LINUX_JoystickDriver =
{
SDL_JoystickDriver SDL_LINUX_JoystickDriver = {
LINUX_JoystickInit,
LINUX_JoystickGetCount,
LINUX_JoystickDetect,