Updates SDL to 2.0.12

This commit is contained in:
Areloch 2020-08-12 11:56:18 -05:00
parent 3108a08650
commit a526029f2f
861 changed files with 25596 additions and 8904 deletions

View file

@ -1,6 +1,6 @@
/*
Simple DirectMedia Layer
Copyright (C) 1997-2019 Sam Lantinga <slouken@libsdl.org>
Copyright (C) 1997-2020 Sam Lantinga <slouken@libsdl.org>
This software is provided 'as-is', without any express or implied
warranty. In no event will the authors be held liable for any damages
@ -80,18 +80,52 @@ static SDL_joylist_item *SDL_joylist_tail = NULL;
static int numjoysticks = 0;
#if !SDL_USE_LIBUDEV
static Uint32 last_joy_detect_time = 0;
static Uint32 last_joy_detect_time;
static time_t last_input_dir_mtime;
#endif
#define test_bit(nr, addr) \
(((1UL << ((nr) % (sizeof(long) * 8))) & ((addr)[(nr) / (sizeof(long) * 8)])) != 0)
#define NBITS(x) ((((x)-1)/(sizeof(long) * 8))+1)
static int
PrefixMatch(const char *a, const char *b)
{
int matchlen = 0;
while (*a && *b) {
if (*a++ == *b++) {
++matchlen;
} else {
break;
}
}
return matchlen;
}
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 */
unsigned long keybit[NBITS(KEY_MAX)] = { 0 };
/* The first version of the firmware duplicated all the inputs */
if ((ioctl(fd, EVIOCGBIT(EV_KEY, sizeof(keybit)), keybit) >= 0) &&
test_bit(0x2c0, keybit)) {
/* Change the version to 0x0902, so we can map it differently */
inpid->version = 0x0902;
}
}
}
static int
IsJoystick(int fd, char *namebuf, const size_t namebuflen, SDL_JoystickGUID *guid)
{
struct input_id inpid;
Uint16 *guid16 = (Uint16 *)guid->data;
const char *name;
const char *spot;
#if !SDL_USE_LIBUDEV
/* When udev is enabled we only get joystick devices here, so there's no need to test them */
@ -111,21 +145,37 @@ IsJoystick(int fd, char *namebuf, const size_t namebuflen, SDL_JoystickGUID *gui
}
#endif
if (ioctl(fd, EVIOCGNAME(namebuflen), namebuf) < 0) {
return 0;
}
if (ioctl(fd, EVIOCGID, &inpid) < 0) {
return 0;
}
name = SDL_GetCustomJoystickName(inpid.vendor, inpid.product);
if (name) {
SDL_strlcpy(namebuf, name, namebuflen);
} else {
if (ioctl(fd, EVIOCGNAME(namebuflen), namebuf) < 0) {
return 0;
}
/* Remove duplicate manufacturer in the name */
for (spot = namebuf + 1; *spot; ++spot) {
int matchlen = PrefixMatch(namebuf, spot);
if (matchlen > 0 && spot[matchlen - 1] == ' ') {
SDL_memmove(namebuf, spot, SDL_strlen(spot)+1);
break;
}
}
}
#ifdef SDL_JOYSTICK_HIDAPI
if (HIDAPI_IsDevicePresent(inpid.vendor, inpid.product, inpid.version)) {
if (HIDAPI_IsDevicePresent(inpid.vendor, inpid.product, inpid.version, namebuf)) {
/* The HIDAPI driver is taking care of this device */
return 0;
}
#endif
FixupDeviceInfoForMapping(fd, &inpid);
#ifdef DEBUG_JOYSTICK
printf("Joystick: %s, bustype = %d, vendor = 0x%.4x, product = 0x%.4x, version = %d\n", namebuf, inpid.bustype, inpid.vendor, inpid.product, inpid.version);
#endif
@ -421,21 +471,28 @@ LINUX_JoystickDetect(void)
Uint32 now = SDL_GetTicks();
if (!last_joy_detect_time || SDL_TICKS_PASSED(now, last_joy_detect_time + SDL_JOY_DETECT_INTERVAL_MS)) {
DIR *folder;
struct dirent *dent;
struct stat sb;
folder = opendir("/dev/input");
if (folder) {
while ((dent = readdir(folder))) {
int len = SDL_strlen(dent->d_name);
if (len > 5 && SDL_strncmp(dent->d_name, "event", 5) == 0) {
char path[PATH_MAX];
SDL_snprintf(path, SDL_arraysize(path), "/dev/input/%s", dent->d_name);
MaybeAddDevice(path);
/* Opening input devices can generate synchronous device I/O, so avoid it if we can */
if (stat("/dev/input", &sb) == 0 && sb.st_mtime != last_input_dir_mtime) {
DIR *folder;
struct dirent *dent;
folder = opendir("/dev/input");
if (folder) {
while ((dent = readdir(folder))) {
int len = SDL_strlen(dent->d_name);
if (len > 5 && SDL_strncmp(dent->d_name, "event", 5) == 0) {
char path[PATH_MAX];
SDL_snprintf(path, SDL_arraysize(path), "/dev/input/%s", dent->d_name);
MaybeAddDevice(path);
}
}
closedir(folder);
}
closedir(folder);
last_input_dir_mtime = sb.st_mtime;
}
last_joy_detect_time = now;
@ -483,6 +540,10 @@ LINUX_JoystickInit(void)
/* Force a scan to build the initial device list */
SDL_UDEV_Scan();
#else
/* Force immediate joystick detection */
last_joy_detect_time = 0;
last_input_dir_mtime = 0;
/* Report all devices currently present */
LINUX_JoystickDetect();
#endif
@ -527,6 +588,11 @@ LINUX_JoystickGetDevicePlayerIndex(int device_index)
return -1;
}
static void
LINUX_JoystickSetDevicePlayerIndex(int device_index, int player_index)
{
}
static SDL_JoystickGUID
LINUX_JoystickGetDeviceGUID( int device_index )
{
@ -661,7 +727,7 @@ ConfigJoystick(SDL_Joystick * joystick, int fd)
absinfo.value, absinfo.minimum, absinfo.maximum,
absinfo.fuzz, absinfo.flat);
#endif /* DEBUG_INPUT_EVENTS */
joystick->hwdata->hats_indices[joystick->nhats++] = hat_index;
joystick->hwdata->hats_indices[hat_index] = joystick->nhats++;
}
}
if (test_bit(REL_X, relbit) || test_bit(REL_Y, relbit)) {
@ -757,7 +823,7 @@ LINUX_JoystickOpen(SDL_Joystick * joystick, int device_index)
}
static int
LINUX_JoystickRumble(SDL_Joystick * joystick, Uint16 low_frequency_rumble, Uint16 high_frequency_rumble, Uint32 duration_ms)
LINUX_JoystickRumble(SDL_Joystick * joystick, Uint16 low_frequency_rumble, Uint16 high_frequency_rumble)
{
struct input_event event;
@ -765,7 +831,7 @@ LINUX_JoystickRumble(SDL_Joystick * joystick, Uint16 low_frequency_rumble, Uint1
struct ff_effect *effect = &joystick->hwdata->effect;
effect->type = FF_RUMBLE;
effect->replay.length = SDL_min(duration_ms, 32767);
effect->replay.length = SDL_MAX_RUMBLE_DURATION_MS;
effect->u.rumble.strong_magnitude = low_frequency_rumble;
effect->u.rumble.weak_magnitude = high_frequency_rumble;
} else if (joystick->hwdata->ff_sine) {
@ -774,7 +840,7 @@ LINUX_JoystickRumble(SDL_Joystick * joystick, Uint16 low_frequency_rumble, Uint1
struct ff_effect *effect = &joystick->hwdata->effect;
effect->type = FF_PERIODIC;
effect->replay.length = SDL_min(duration_ms, 32767);
effect->replay.length = SDL_MAX_RUMBLE_DURATION_MS;
effect->u.periodic.waveform = FF_SINE;
effect->u.periodic.magnitude = magnitude;
} else {
@ -782,7 +848,11 @@ LINUX_JoystickRumble(SDL_Joystick * joystick, Uint16 low_frequency_rumble, Uint1
}
if (ioctl(joystick->hwdata->fd, EVIOCSFF, &joystick->hwdata->effect) < 0) {
return SDL_SetError("Couldn't update rumble effect: %s", strerror(errno));
/* The kernel may have lost this effect, try to allocate a new one */
joystick->hwdata->effect.id = -1;
if (ioctl(joystick->hwdata->fd, EVIOCSFF, &joystick->hwdata->effect) < 0) {
return SDL_SetError("Couldn't update rumble effect: %s", strerror(errno));
}
}
event.type = EV_FF;
@ -1044,6 +1114,7 @@ SDL_JoystickDriver SDL_LINUX_JoystickDriver =
LINUX_JoystickDetect,
LINUX_JoystickGetDeviceName,
LINUX_JoystickGetDevicePlayerIndex,
LINUX_JoystickSetDevicePlayerIndex,
LINUX_JoystickGetDeviceGUID,
LINUX_JoystickGetDeviceInstanceID,
LINUX_JoystickOpen,

View file

@ -1,6 +1,6 @@
/*
Simple DirectMedia Layer
Copyright (C) 1997-2019 Sam Lantinga <slouken@libsdl.org>
Copyright (C) 1997-2020 Sam Lantinga <slouken@libsdl.org>
This software is provided 'as-is', without any express or implied
warranty. In no event will the authors be held liable for any damages
@ -37,6 +37,7 @@ struct joystick_hwdata
SDL_bool ff_rumble;
SDL_bool ff_sine;
struct ff_effect effect;
Uint32 effect_expiration;
/* The current Linux joystick driver maps hats to two axes */
struct hwdata_hat