early-access version 1667
This commit is contained in:
@@ -1,6 +1,6 @@
|
||||
/*
|
||||
Simple DirectMedia Layer
|
||||
Copyright (C) 1997-2020 Sam Lantinga <slouken@libsdl.org>
|
||||
Copyright (C) 1997-2021 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
|
||||
@@ -56,18 +56,6 @@
|
||||
#ifndef SYN_DROPPED
|
||||
#define SYN_DROPPED 3
|
||||
#endif
|
||||
#ifndef BTN_SOUTH
|
||||
#define BTN_SOUTH 0x130
|
||||
#endif
|
||||
#ifndef BTN_EAST
|
||||
#define BTN_EAST 0x131
|
||||
#endif
|
||||
#ifndef BTN_NORTH
|
||||
#define BTN_NORTH 0x133
|
||||
#endif
|
||||
#ifndef BTN_WEST
|
||||
#define BTN_WEST 0x134
|
||||
#endif
|
||||
#ifndef BTN_DPAD_UP
|
||||
#define BTN_DPAD_UP 0x220
|
||||
#endif
|
||||
@@ -113,6 +101,8 @@ typedef struct SDL_joylist_item
|
||||
|
||||
/* Steam Controller support */
|
||||
SDL_bool m_bSteamController;
|
||||
|
||||
SDL_GamepadMapping *mapping;
|
||||
} SDL_joylist_item;
|
||||
|
||||
static SDL_joylist_item *SDL_joylist = NULL;
|
||||
@@ -376,6 +366,9 @@ MaybeRemoveDevice(const char *path)
|
||||
|
||||
SDL_PrivateJoystickRemoved(item->device_instance);
|
||||
|
||||
if (item->mapping) {
|
||||
SDL_free(item->mapping);
|
||||
}
|
||||
SDL_free(item->path);
|
||||
SDL_free(item->name);
|
||||
SDL_free(item);
|
||||
@@ -658,7 +651,10 @@ LINUX_JoystickInit(void)
|
||||
enumeration_method = ENUMERATION_FALLBACK;
|
||||
}
|
||||
else if (access("/.flatpak-info", F_OK) == 0
|
||||
|| access("/run/pressure-vessel", F_OK) == 0) {
|
||||
|| access("/run/host/container-manager", F_OK) == 0) {
|
||||
/* Explicitly check `/.flatpak-info` because, for old versions of
|
||||
* Flatpak, this was the only available way to tell if we were in
|
||||
* a Flatpak container. */
|
||||
SDL_LogDebug(SDL_LOG_CATEGORY_INPUT,
|
||||
"Container detected, disabling udev integration");
|
||||
enumeration_method = ENUMERATION_FALLBACK;
|
||||
@@ -1400,6 +1396,12 @@ static SDL_bool
|
||||
LINUX_JoystickGetGamepadMapping(int device_index, SDL_GamepadMapping *out)
|
||||
{
|
||||
SDL_Joystick *joystick;
|
||||
SDL_joylist_item *item = JoystickByDevIndex(device_index);
|
||||
|
||||
if (item->mapping) {
|
||||
SDL_memcpy(out, item->mapping, sizeof(*out));
|
||||
return SDL_TRUE;
|
||||
}
|
||||
|
||||
joystick = (SDL_Joystick *) SDL_calloc(sizeof(*joystick), 1);
|
||||
if (joystick == NULL) {
|
||||
@@ -1422,24 +1424,24 @@ LINUX_JoystickGetGamepadMapping(int device_index, SDL_GamepadMapping *out)
|
||||
|
||||
/* We have a gamepad, start filling out the mappings */
|
||||
|
||||
if (joystick->hwdata->has_key[BTN_SOUTH]) {
|
||||
if (joystick->hwdata->has_key[BTN_A]) {
|
||||
out->a.kind = EMappingKind_Button;
|
||||
out->a.target = joystick->hwdata->key_map[BTN_SOUTH];
|
||||
out->a.target = joystick->hwdata->key_map[BTN_A];
|
||||
}
|
||||
|
||||
if (joystick->hwdata->has_key[BTN_EAST]) {
|
||||
if (joystick->hwdata->has_key[BTN_B]) {
|
||||
out->b.kind = EMappingKind_Button;
|
||||
out->b.target = joystick->hwdata->key_map[BTN_EAST];
|
||||
out->b.target = joystick->hwdata->key_map[BTN_B];
|
||||
}
|
||||
|
||||
if (joystick->hwdata->has_key[BTN_NORTH]) {
|
||||
out->y.kind = EMappingKind_Button;
|
||||
out->y.target = joystick->hwdata->key_map[BTN_NORTH];
|
||||
}
|
||||
|
||||
if (joystick->hwdata->has_key[BTN_WEST]) {
|
||||
if (joystick->hwdata->has_key[BTN_X]) {
|
||||
out->x.kind = EMappingKind_Button;
|
||||
out->x.target = joystick->hwdata->key_map[BTN_WEST];
|
||||
out->x.target = joystick->hwdata->key_map[BTN_X];
|
||||
}
|
||||
|
||||
if (joystick->hwdata->has_key[BTN_Y]) {
|
||||
out->y.kind = EMappingKind_Button;
|
||||
out->y.target = joystick->hwdata->key_map[BTN_Y];
|
||||
}
|
||||
|
||||
if (joystick->hwdata->has_key[BTN_SELECT]) {
|
||||
@@ -1503,11 +1505,17 @@ LINUX_JoystickGetGamepadMapping(int device_index, SDL_GamepadMapping *out)
|
||||
if (joystick->hwdata->has_key[BTN_TL2]) {
|
||||
out->lefttrigger.kind = EMappingKind_Button;
|
||||
out->lefttrigger.target = joystick->hwdata->key_map[BTN_TL2];
|
||||
} else if (joystick->hwdata->has_abs[ABS_Z]) {
|
||||
out->lefttrigger.kind = EMappingKind_Axis;
|
||||
out->lefttrigger.target = joystick->hwdata->abs_map[ABS_Z];
|
||||
}
|
||||
|
||||
if (joystick->hwdata->has_key[BTN_TR2]) {
|
||||
out->righttrigger.kind = EMappingKind_Button;
|
||||
out->righttrigger.target = joystick->hwdata->key_map[BTN_TR2];
|
||||
} else if (joystick->hwdata->has_abs[ABS_RZ]) {
|
||||
out->righttrigger.kind = EMappingKind_Axis;
|
||||
out->righttrigger.target = joystick->hwdata->abs_map[ABS_RZ];
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1563,6 +1571,12 @@ LINUX_JoystickGetGamepadMapping(int device_index, SDL_GamepadMapping *out)
|
||||
LINUX_JoystickClose(joystick);
|
||||
SDL_free(joystick);
|
||||
|
||||
/* Cache the mapping for later */
|
||||
item->mapping = (SDL_GamepadMapping *)SDL_malloc(sizeof(*item->mapping));
|
||||
if (item->mapping) {
|
||||
SDL_memcpy(item->mapping, out, sizeof(*out));
|
||||
}
|
||||
|
||||
return SDL_TRUE;
|
||||
}
|
||||
|
||||
|
@@ -1,6 +1,6 @@
|
||||
/*
|
||||
Simple DirectMedia Layer
|
||||
Copyright (C) 1997-2020 Sam Lantinga <slouken@libsdl.org>
|
||||
Copyright (C) 1997-2021 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
|
||||
@@ -74,6 +74,7 @@ struct joystick_hwdata
|
||||
|
||||
/* Steam Controller support */
|
||||
SDL_bool m_bSteamController;
|
||||
|
||||
/* 4 = (ABS_HAT3X-ABS_HAT0X)/2 (see input-event-codes.h in kernel) */
|
||||
int hats_indices[4];
|
||||
SDL_bool has_hat[4];
|
||||
|
Reference in New Issue
Block a user