tomato/external/sdl/SDL/src/joystick/SDL_gamepad.c

3525 lines
114 KiB
C
Raw Normal View History

/*
Simple DirectMedia Layer
Copyright (C) 1997-2023 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
arising from the use of this software.
Permission is granted to anyone to use this software for any purpose,
including commercial applications, and to alter it and redistribute it
freely, subject to the following restrictions:
1. The origin of this software must not be misrepresented; you must not
claim that you wrote the original software. If you use this software
in a product, an acknowledgment in the product documentation would be
appreciated but is not required.
2. Altered source versions must be plainly marked as such, and must not be
misrepresented as being the original software.
3. This notice may not be removed or altered from any source distribution.
*/
#include "SDL_internal.h"
/* This is the gamepad API for Simple DirectMedia Layer */
#include "../SDL_utils_c.h"
#include "SDL_sysjoystick.h"
#include "SDL_joystick_c.h"
#include "SDL_gamepad_c.h"
#include "SDL_gamepad_db.h"
#include "controller_type.h"
#include "usb_ids.h"
#include "hidapi/SDL_hidapi_nintendo.h"
#ifndef SDL_EVENTS_DISABLED
#include "../events/SDL_events_c.h"
#endif
#ifdef __ANDROID__
#endif
/* Many gamepads turn the center button into an instantaneous button press */
#define SDL_MINIMUM_GUIDE_BUTTON_DELAY_MS 250
#define SDL_GAMEPAD_CRC_FIELD "crc:"
#define SDL_GAMEPAD_CRC_FIELD_SIZE 4 /* hard-coded for speed */
#define SDL_GAMEPAD_TYPE_FIELD "type:"
#define SDL_GAMEPAD_TYPE_FIELD_SIZE SDL_strlen(SDL_GAMEPAD_TYPE_FIELD)
#define SDL_GAMEPAD_PLATFORM_FIELD "platform:"
#define SDL_GAMEPAD_PLATFORM_FIELD_SIZE SDL_strlen(SDL_GAMEPAD_PLATFORM_FIELD)
#define SDL_GAMEPAD_HINT_FIELD "hint:"
#define SDL_GAMEPAD_HINT_FIELD_SIZE SDL_strlen(SDL_GAMEPAD_HINT_FIELD)
#define SDL_GAMEPAD_SDKGE_FIELD "sdk>=:"
#define SDL_GAMEPAD_SDKGE_FIELD_SIZE SDL_strlen(SDL_GAMEPAD_SDKGE_FIELD)
#define SDL_GAMEPAD_SDKLE_FIELD "sdk<=:"
#define SDL_GAMEPAD_SDKLE_FIELD_SIZE SDL_strlen(SDL_GAMEPAD_SDKLE_FIELD)
static SDL_bool SDL_gamepads_initialized;
static SDL_Gamepad *SDL_gamepads SDL_GUARDED_BY(SDL_joystick_lock) = NULL;
/* our hard coded list of mapping support */
typedef enum
{
SDL_GAMEPAD_MAPPING_PRIORITY_DEFAULT,
SDL_GAMEPAD_MAPPING_PRIORITY_API,
SDL_GAMEPAD_MAPPING_PRIORITY_USER,
} SDL_GamepadMappingPriority;
#define _guarded SDL_GUARDED_BY(SDL_joystick_lock)
typedef struct GamepadMapping_t
{
SDL_JoystickGUID guid _guarded;
char *name _guarded;
char *mapping _guarded;
SDL_GamepadMappingPriority priority _guarded;
struct GamepadMapping_t *next _guarded;
} GamepadMapping_t;
typedef struct
{
int refcount _guarded;
SDL_JoystickID *joysticks _guarded;
GamepadMapping_t **joystick_mappings _guarded;
int num_changed_mappings _guarded;
GamepadMapping_t **changed_mappings _guarded;
} MappingChangeTracker;
#undef _guarded
static SDL_JoystickGUID s_zeroGUID;
static GamepadMapping_t *s_pSupportedGamepads SDL_GUARDED_BY(SDL_joystick_lock) = NULL;
static GamepadMapping_t *s_pDefaultMapping SDL_GUARDED_BY(SDL_joystick_lock) = NULL;
static GamepadMapping_t *s_pXInputMapping SDL_GUARDED_BY(SDL_joystick_lock) = NULL;
static MappingChangeTracker *s_mappingChangeTracker SDL_GUARDED_BY(SDL_joystick_lock) = NULL;
static char gamepad_magic;
#define _guarded SDL_GUARDED_BY(SDL_joystick_lock)
/* The SDL gamepad structure */
struct SDL_Gamepad
{
const void *magic _guarded;
SDL_Joystick *joystick _guarded; /* underlying joystick device */
int ref_count _guarded;
const char *name _guarded;
GamepadMapping_t *mapping _guarded;
int num_bindings _guarded;
SDL_GamepadBinding *bindings _guarded;
SDL_GamepadBinding **last_match_axis _guarded;
Uint8 *last_hat_mask _guarded;
Uint64 guide_button_down _guarded;
struct SDL_Gamepad *next _guarded; /* pointer to next gamepad we have allocated */
};
#undef _guarded
#define CHECK_GAMEPAD_MAGIC(gamepad, retval) \
if (!gamepad || gamepad->magic != &gamepad_magic || \
!SDL_IsJoystickValid(gamepad->joystick)) { \
SDL_InvalidParamError("gamepad"); \
SDL_UnlockJoysticks(); \
return retval; \
}
static SDL_vidpid_list SDL_allowed_gamepads;
static SDL_vidpid_list SDL_ignored_gamepads;
static void SDLCALL SDL_GamepadIgnoreDevicesChanged(void *userdata, const char *name, const char *oldValue, const char *hint)
{
SDL_LoadVIDPIDListFromHint(hint, &SDL_ignored_gamepads);
}
static void SDLCALL SDL_GamepadIgnoreDevicesExceptChanged(void *userdata, const char *name, const char *oldValue, const char *hint)
{
SDL_LoadVIDPIDListFromHint(hint, &SDL_allowed_gamepads);
}
static GamepadMapping_t *SDL_PrivateAddMappingForGUID(SDL_JoystickGUID jGUID, const char *mappingString, SDL_bool *existing, SDL_GamepadMappingPriority priority);
static void SDL_PrivateLoadButtonMapping(SDL_Gamepad *gamepad, GamepadMapping_t *pGamepadMapping);
static GamepadMapping_t *SDL_PrivateGetGamepadMapping(SDL_JoystickID instance_id);
static int SDL_SendGamepadAxis(Uint64 timestamp, SDL_Gamepad *gamepad, SDL_GamepadAxis axis, Sint16 value);
static int SDL_SendGamepadButton(Uint64 timestamp, SDL_Gamepad *gamepad, SDL_GamepadButton button, Uint8 state);
static SDL_bool HasSameOutput(SDL_GamepadBinding *a, SDL_GamepadBinding *b)
{
if (a->outputType != b->outputType) {
return SDL_FALSE;
}
if (a->outputType == SDL_GAMEPAD_BINDTYPE_AXIS) {
return a->output.axis.axis == b->output.axis.axis;
} else {
return a->output.button == b->output.button;
}
}
static void ResetOutput(Uint64 timestamp, SDL_Gamepad *gamepad, SDL_GamepadBinding *bind)
{
if (bind->outputType == SDL_GAMEPAD_BINDTYPE_AXIS) {
SDL_SendGamepadAxis(timestamp, gamepad, bind->output.axis.axis, 0);
} else {
SDL_SendGamepadButton(timestamp, gamepad, bind->output.button, SDL_RELEASED);
}
}
static void HandleJoystickAxis(Uint64 timestamp, SDL_Gamepad *gamepad, int axis, int value)
{
int i;
SDL_GamepadBinding *last_match;
SDL_GamepadBinding *match = NULL;
SDL_AssertJoysticksLocked();
last_match = gamepad->last_match_axis[axis];
for (i = 0; i < gamepad->num_bindings; ++i) {
SDL_GamepadBinding *binding = &gamepad->bindings[i];
if (binding->inputType == SDL_GAMEPAD_BINDTYPE_AXIS &&
axis == binding->input.axis.axis) {
if (binding->input.axis.axis_min < binding->input.axis.axis_max) {
if (value >= binding->input.axis.axis_min &&
value <= binding->input.axis.axis_max) {
match = binding;
break;
}
} else {
if (value >= binding->input.axis.axis_max &&
value <= binding->input.axis.axis_min) {
match = binding;
break;
}
}
}
}
if (last_match && (match == NULL || !HasSameOutput(last_match, match))) {
/* Clear the last input that this axis generated */
ResetOutput(timestamp, gamepad, last_match);
}
if (match) {
if (match->outputType == SDL_GAMEPAD_BINDTYPE_AXIS) {
if (match->input.axis.axis_min != match->output.axis.axis_min || match->input.axis.axis_max != match->output.axis.axis_max) {
float normalized_value = (float)(value - match->input.axis.axis_min) / (match->input.axis.axis_max - match->input.axis.axis_min);
value = match->output.axis.axis_min + (int)(normalized_value * (match->output.axis.axis_max - match->output.axis.axis_min));
}
SDL_SendGamepadAxis(timestamp, gamepad, match->output.axis.axis, (Sint16)value);
} else {
Uint8 state;
int threshold = match->input.axis.axis_min + (match->input.axis.axis_max - match->input.axis.axis_min) / 2;
if (match->input.axis.axis_max < match->input.axis.axis_min) {
state = (value <= threshold) ? SDL_PRESSED : SDL_RELEASED;
} else {
state = (value >= threshold) ? SDL_PRESSED : SDL_RELEASED;
}
SDL_SendGamepadButton(timestamp, gamepad, match->output.button, state);
}
}
gamepad->last_match_axis[axis] = match;
}
static void HandleJoystickButton(Uint64 timestamp, SDL_Gamepad *gamepad, int button, Uint8 state)
{
int i;
SDL_AssertJoysticksLocked();
for (i = 0; i < gamepad->num_bindings; ++i) {
SDL_GamepadBinding *binding = &gamepad->bindings[i];
if (binding->inputType == SDL_GAMEPAD_BINDTYPE_BUTTON &&
button == binding->input.button) {
if (binding->outputType == SDL_GAMEPAD_BINDTYPE_AXIS) {
int value = state ? binding->output.axis.axis_max : binding->output.axis.axis_min;
SDL_SendGamepadAxis(timestamp, gamepad, binding->output.axis.axis, (Sint16)value);
} else {
SDL_SendGamepadButton(timestamp, gamepad, binding->output.button, state);
}
break;
}
}
}
static void HandleJoystickHat(Uint64 timestamp, SDL_Gamepad *gamepad, int hat, Uint8 value)
{
int i;
Uint8 last_mask, changed_mask;
SDL_AssertJoysticksLocked();
last_mask = gamepad->last_hat_mask[hat];
changed_mask = (last_mask ^ value);
for (i = 0; i < gamepad->num_bindings; ++i) {
SDL_GamepadBinding *binding = &gamepad->bindings[i];
if (binding->inputType == SDL_GAMEPAD_BINDTYPE_HAT && hat == binding->input.hat.hat) {
if ((changed_mask & binding->input.hat.hat_mask) != 0) {
if (value & binding->input.hat.hat_mask) {
if (binding->outputType == SDL_GAMEPAD_BINDTYPE_AXIS) {
SDL_SendGamepadAxis(timestamp, gamepad, binding->output.axis.axis, (Sint16)binding->output.axis.axis_max);
} else {
SDL_SendGamepadButton(timestamp, gamepad, binding->output.button, SDL_PRESSED);
}
} else {
ResetOutput(timestamp, gamepad, binding);
}
}
}
}
gamepad->last_hat_mask[hat] = value;
}
/* The joystick layer will _also_ send events to recenter before disconnect,
but it has to make (sometimes incorrect) guesses at what being "centered"
is. The gamepad layer, however, can set a definite logical idle
position, so set them all here. If we happened to already be at the
center thanks to the joystick layer or idle hands, this won't generate
duplicate events. */
static void RecenterGamepad(SDL_Gamepad *gamepad)
{
SDL_GamepadButton button;
SDL_GamepadAxis axis;
Uint64 timestamp = SDL_GetTicksNS();
for (button = (SDL_GamepadButton)0; button < SDL_GAMEPAD_BUTTON_MAX; button++) {
if (SDL_GetGamepadButton(gamepad, button)) {
SDL_SendGamepadButton(timestamp, gamepad, button, SDL_RELEASED);
}
}
for (axis = (SDL_GamepadAxis)0; axis < SDL_GAMEPAD_AXIS_MAX; axis++) {
if (SDL_GetGamepadAxis(gamepad, axis) != 0) {
SDL_SendGamepadAxis(timestamp, gamepad, axis, 0);
}
}
}
void SDL_PrivateGamepadAdded(SDL_JoystickID instance_id)
{
SDL_Event event;
if (!SDL_gamepads_initialized) {
return;
}
event.type = SDL_EVENT_GAMEPAD_ADDED;
event.common.timestamp = 0;
event.gdevice.which = instance_id;
SDL_PushEvent(&event);
}
void SDL_PrivateGamepadRemoved(SDL_JoystickID instance_id)
{
SDL_Event event;
SDL_Gamepad *gamepad;
Squashed 'external/sdl/SDL/' changes from b8d91252c6..ec0042081e ec0042081e Add .gitattributes file a5d9db0cd0 cmake: build tests for UWP b7889a7389 winrt: use windowsio in non-libc mode ea8757a748 Make testaudiostreamdynamicresample compatible with emscripten 1a7a74fb2e cmake: build emscripten tests as html page 64d570f027 Add minimal http server for emscripten test apps 8e898c4a21 SDL_test does not parse --samples argument 91cd5478be audio: Fix resampler overflowing input buffer. f290c85b22 testaudiocapture: Make sure we convert captured audio to output format. b75c751dfc rwlock: Make generic implmentations work on single-threaded platforms. 80850af7ce The controller update complete events are no longer disabled by default 3f486224a9 Fixed refresh rate calculation for KMSDRM 342ec51131 Fix overflow when doing SDL_sscanf("%hd", ...) 9129e1d557 Fixed crash when setting the default cursor twice 8e99a4f4f5 Undo variable rename be67f0de10 Fixed crashes related to the default cursor on WinRT and KMSDRM 94b3f78c44 Fix out of bound read of 'has_hat' array 94f48f19b0 Use more specific build destinations when creating an xcframework dabd45997e Back out change supporting multiple names for binding elements efe15588d5 Relabel back paddles as left or right be884f0c95 ci: disable visionos.yml by renaming the file ac094d00f5 ci: add workflow_dispatch event to visionos workflow 9be9e2292b build: Consistently use pathlib APIs in cmake/xxd.py a9f6950657 Fixed deadlock shutting down Android sensors d9f09e77f2 Actually make the sensors magical! 690eae7d22 Implement visionOS support e385d6da0a Fixed build warning 6b93e788fa Improved sensor thread-safety 4ee0e5a984 Fixed thread-safety warnings 12deed91f8 Added information on how to enable thread-safety analysis 5735d2b03b coreaudio: Fixed assertion when device fails/quits mid-iteration. 1022fd6e04 testaudio: the test framework opens an audio device at startup; close it. 0714da37a4 audio: Fix audio stream callback calculations when future buffer has space. 917e036f6f MSVC has __declspec(deprecated) 279ff8909f Changed example code to avoid potential divide by zero 8a1afc9b10 Fixed Android not sending controller event timestamps 463c456b98 Fill the correct member with the joystick ID in SDL_EVENT_JOYSTICK_UPDATE_COMPLETE 55cf1abaa6 test: Don't flag testsurround as suitable for non-interactive use a2d594269c Fixed pixel format compatibility with SDL2 79a190aa23 Fixed setting invalid bpp for FOURCC formats in SDL_GetMasksForPixelFormatEnum() 8fdebdd3e0 Sync SDL3 wiki -> header b903ccf945 SDL_rwops read/write functions return size_t again c03f5b4b69 Fixed rounding up in SDL_PrintFloat 75a020aa6b Only query serial number and firmware versions from Sony PS5 controllers fa189d302e Added the Victrix Pro FS for PS4/PS5 to the controller list 26205b659d Fixed PS4/PS5 touchpad for third party controllers 6af0448af9 include: fixed a typo in SDL_RenderGetMetalCommandEncoder docs. f3cb46b083 SDL_thread.h: do not conflict with sdl2-compat::sdl3_include_wrapper.h 080b1dfbdb Revert "Improved fallback for SDL_COMPILE_TIME_ASSERT() (thanks @icculus!)" 9d453daa23 Improved fallback for SDL_COMPILE_TIME_ASSERT() (thanks @icculus!) 1fb2419882 Removed reference to renamed function e7d56dd0b2 audio: Renamed new API SDL_UnpauseAudioDevice to SDL_ResumeAudioDevice. 2b0c0f5b6b Don't pass NULL to strncmp 778e8185cd Fix size of memcpy in SDL_AudioDeviceFormatChangedAlreadyLocked And add diagnostic that allows to find this kind of issue in clang-tidy 4bb426abad Sync SDL3 wiki -> header 3a752ce650 Reapply "Changed 'freesrc' parameter from int to SDL_bool" to SDL_wave.c 2ba03b4db0 fix build after previous commit. 0026adffd4 apply force_align_arg_pointer attribute to correct version of SDL_RunApp 77446e2029 Unaligned stacks on i686-w64-mingw32 may lead to crashes d3bcc3f057 Fixed build errors when OpenGL isn't enabled 35ad68e126 Sync SDL3 wiki -> header 70323a8350 Add a function to display the system menu for a window be5f66c84e testaudio: Fixed soundboard icon, which had a colorkey issue. c0a88930bf Sync SDL3 wiki -> header 18c59cc969 Merge the SDL3 audio subsystem redesign! 99b0e31788 The Steam Controller D-Pad is only pressed when the button is pressed down 103073d694 Set NSBluetoothAlwaysUsageDescription for testcontroller ca02bb6c8c We don't need testdropfile-Info.plist e063f662e9 Enable the controller update complete events 06bea1eb55 Added a gamepad mapping for the G-Shark GS-GP702 5ca3c50bf0 testaudio: Fix compiler warning. 1b1f02c5aa testaudio: Apparently compilers don't like this possibly being NULL now...? 2de9253b6c test: Added testaudio fb3ab3f113 SDL_video.c: move ngage video before offscreen. 843572d993 Don't mark autorelease keys as virtual 648de4f9b8 Fixed duplicate key press/release events on iOS a8abe612ed Only pass keypresses up the responder chain when text input is active c3288d113e Synchronize on-screen keyboard state with text input active state 5fb92ef2f7 Fixed whitespace f5ea6ae18d Revert "Stop beep when running iOS apps on ARM-based Macs" 546508b9b4 Allow test programs to run at full resolution on iPads 68a4bb01e0 Allocate displays as an array of pointers instead of an array of objects 07578fde3d Fixed crash if a display is enumerated twice a509771a87 fix ios CI workflow after commit e4460e897f 72ce76905a The scheme isn't always the same as the framework name (e.g. xmp_lite vs xmp-lite) e4460e897f By default Xcode expects the framework target name to be the name of the project. ac683773dc Added missing tests to the "All" target 7dd56eaafe Removed unnecessary reference to testoverlay-Info.plist e1c7f524ef Reduce the number of times SDL3 is duplicated in the xcframework script 65538011ca Make Xcode targets more specific efe114c300 Revert "Renamed the xcframework target from "SDL.xcframework" to "xcframework"" 73ed1d21a9 Renamed the xcframework target from "SDL.xcframework" to "xcframework" 76b4d8a0d8 Build the Framework instead of a static library for iOS and tvOS d1bf979160 Removed unnecessary setting from the "Create DMG" target c94cb3a5d8 Simplified the Xcode project to a single Framework target ea60474c65 cmake: don't build SDL3-static Apple framework 8f00d7856d Sync SDL3 wiki -> header d4a867a256 Rename SDL_GetPath to SDL_GetUserFolder 71099149b8 Fall back to Xlib if XRandR isn't available b7f32f74ce Note the removal of the SDL_RENDERER_TARGETTEXTURE flag 0eda582160 testaudiostreamdynamicresample: Load sample.wav correctly. 87eae9a0a1 aaudio: We need a mixbuf on capture devices, too. fb68e84646 wayland: Fix memory leaks b0edd23c00 testsurround: Log available audio output devices at the start. ae3090c387 androidaudio: Move Init/bootstrap code to bottom of source code. 18fc0db9e5 aaudio: Rearranged source code to match other backends. 2507c1d68b aaudio: Disconnect playing devices if error callback fires. 32a3fc3783 aaudio: Use the callback interface. b49ce86765 audio: Fixed compiler warning on Android NDK. 1c074e8d97 android: Fixed audio device detection. 82ce05ad01 pulseaudio: Be more aggressive with hotplug thread synchronization. 5cbdf1168e androidaudio: Fixed incorrect JNI call (thanks, @madebr!) 660054f3dc include: Correct comment about audio device hotplug events. ab68428a64 aaudio: Fixed for older SDKs and Android releases. 5ff87c6d4a android: Reworked audio backends for SDL3 audio API. 54af687210 testautomation_audio.c: Patched to compile. :/ 5e82090662 testautomation_audio.c: Apparently we aren't updating test code for C99 atm. 7f4488f625 wasapi: More fixes for Clang warnings. 29a0c689c9 wasapi: Patched to compile with Clang. 4aa95c21bc pspaudio: Patched to compile. 9a2a0a1463 ps2audio: Delete errant character that got inserted before previous commit. 2c578bd0d5 qnxaudio: Rewrite for SDL3 audio APIs. 455eef4cd9 audio: Use AtomicAdd for device counts, don't treat as a refcount. 095ea57f94 pspaudio: Patched to compile. d7cf63db67 ps2audio: Patched to compile. 027b9e8787 coreaudio: (maybe) patched to compile on iOS. 4836c2db07 pspaudio: Patched to compile. 86ca412436 n3dsaudio: Patched to compile. 66bcee2ca9 testaudiostreamdynamicresample.c: Fixed MSVC compiler warning. dbf993d358 vitaaudio: patched to compile. 5707e14716 audio: Fix up some things that broke when rebasing the branch against main. 6567285eae SDL_migration.cocci: Fix up SDL_(Pause|Unpause)Audio. 0b6255551e test: Fixed incorrect SDL_OpenAudioDevice call in testautomation. 107fd941cd vitaaudio: Clean up correctly in CloseDevice. 9fa4a6ef87 netbsdaudio: Minor fix. b0d89868c6 n3dsaudio: Updated (but untested!) for SDL3 audio API. ba27176106 vitaaudio: Untested attempt to move Vita audio to SDL3's audio API. 0b58e96d9e wasapi: Patched WinRT to compile. d6b4f48488 visualc: Turn on multiprocessor compilation. c58d95c343 wasapi: Reworked for new SDL3 audio API, other win32 fixes. dc04f85646 audio: whoops, that should be an int. be0dc630b7 audio: Fixed incorrect assertion 77b3fb06ee directsound: First shot at updating for SDL3 audio API. 4399b71715 audio: Generalize how backends can lookup an SDL_AudioDevice. 2fb122fe46 audio: backends now "find" instead of "obtain" devices by handle. c3f5a5fc72 dummyaudio: SDL3ify style 7d65ff86e2 diskaudio: Adjusted for later SDL3 audio API redesign changes. 4ba9c2eade dummyaudio: Configurable delay, other SDL3 API fixes. fb395d3ad7 sndio: Updated to the SDL3 audio API. 1a55282051 dsp: Some minor logic fixes 6bc85577d7 netbsdaudio: Updated for SDL3 audio API. 0f6e59312b netbsdaudio: Removed email address from source code. 51ae78c0af haikuaudio: Updated for SDL3 audio API. fc7ed18ca1 emscriptenaudio: don't forget to finalize the audio thread 4233c41ce2 pulseaudio: Removed unnecessary variable. a0528cd5ed emscriptenaudio: Updated for SDL3 audio API. 79cc29ba35 wave: Don't check if format->channels > INT_MAX, it's a Uint16. 1bfe97c235 pspaudio: Updated for SDL3 audio API. 121a2dce15 audio: Make sure `device->hidden` is NULL after CloseDevice 3d6ba0cafd ps2audio: Removed free of buffer that hasn't been allocated yet. 00ed6f8827 test: Fixed compiler warnings for unused vars. 6f12f68ec9 ps2audio: SDL3ified the style 4993743a02 ps2audio: Renamed `_this` to `device` 74568cdb2b ps2audio: Updated (but untested) for SDL3 audio API. c83b68ef26 jack: renamed `_this` to `device`. 3f4f004794 audio: Remove an assertion that no longer makes sense. 86243b2589 jack: Use ProvidesOwnCallbackThread. 18906a32b8 jack: First shot at updating for SDL3 audio API. a2b488359e dsp: Removed debug logging 6fd71185cd dsp: Updated for new SDL3 audio API. 3482d1215a alsa: Don't ever block in CaptureFromDevice. 65d296ef1a audio: Use SDL_powerof2 instead of reinventing it. 409b544505 alsa: Updated for new SDL3 audio API 0999a090a7 audio: More tweaking of `device->thread_alive` f94ffd6092 audio: Fixed logic error 4deb2970c9 alsa: Renamed `_this` to `device` 0fb9e4baae audio: Remove no-longer-used SupportsNonPow2Samples c653e57768 coreaudio: rewritten for SDL3 audio redesign! 533777eff5 audio: SDL_sysaudio.h comment conversion. 8473e522e0 audio: unify device thread naming. 258bc9efed audio: PlayDevice now passes the buffer, too, for convenience. e518149d14 audio: Fixed locking in SDL_AudioDeviceDisconnected 22afa5735f audio: FreeDeviceHandle should pass the whole device, for convenience. 9e3c5f93e0 coreaudio: Change `_this` to `device` e969160de0 audio: unset a freed variable to NULL 1fc01b0300 audio: Try to definitely have a default device set up. b60a56d368 audio: take first reported device if no default was specified. a8323ebe68 audio: Better handling of ProvidesOwnCallbackThread backends. 1dffb72c1d pipewire: Hooked up default device change notifications. a93fcf2444 audio: fixed flushed stream reporting bytes but not being able to get them. ad6c1781fc pulseaudio: Minor cleanups. cfc8a0d17d pipewire: First shot at moving to the new SDL3 audio interfaces. 13202642a3 aaudio: Fixed capitialization, plus some minor cleanups. 3e9991b535 audio: Make sure we don't write to a NULL pointer. 943351affb pulseaudio: GetDefaultAudioInfo isn't a thing anymore. 11dfc4d737 test: Update testautomation_audio for SDL3 audio API. 29afc2e42b test: Update testresample for SDL3 audio API. 3a02eecced test: Update testsurround for SDL3 audio API. e1c78718d4 test: testaudiocapture is updated for the SDL3 audio API. f48cb716c2 pulseaudio: a couple minor tweaks. dac25fe9eb audio: Seperate audio capture into Wait/Read operations. 3e10c0005d audio: Capture devices should respect logical device pausing. 7e700531c5 audio: Allow SDL_OpenAudioDevice to accept a NULL spec. bb1cbbd33a test: Update testaudioinfo for SDL3 audio API. 883aee32c5 audio: Let default formats differ for output and capture devices. 62cf24eeb9 pulseaudio: Listen for server events in addition to sources and sinks. 924f370bd7 pulseaudio: Fix deadlock in HotplugThread. 5d4e9e5f80 test: Updated testaudiostreamdynamicresample to SDL3 audio API. f883b9fc64 test: Updated testaudiohotplug to SDL3 audio API. 2be5f726d4 audio: Removed debug logging. 323ecce123 docs: Added migration note about SDL_AUDIODEVICEREMOVED. 47b0321ebf test: Removed loopwavequeue.c; obsolete in SDL3. 0e5a1d4f29 pulseaudio: Removed debug logging. f598626e46 test: loopwave shouldn't use an audiostream callback. eee407caf8 docs: migration guide note that SDL_LoadWAV has a different return type. b03c493fc4 test: Updated testmultiaudio to new SDL3 audio API fe1daf6fb5 audio: Mark disconnected default devices as "zombies". cdd2ba81de audio: Fixed adding new physical devices to a double-linked list. db39cbf208 audio: Allow SDL_GetAudioDeviceFormat() to query the default devices. ee10bab3cd audio: An enormous amount of work on managing default devices. c7a44eea83 audio: Fixed logic error. 089cd87cb5 audio: Make sure device count stays correct as hardware disconnects. e50cb72eb6 docs: Note that audio opening doesn't implicitly init SDL now. 97b2f747d0 docs: Corrections to audio section of README-migration.md 464640440f audio: Added SDL_GetAudioStreamBinding. 01f7b53865 audio: Readded (logical) device pausing. fd4c9f4e11 audio: documentation improvements. 4b78b789a7 audio: Switch SDL_audio.c and SDL_audiocvt.c to C99-ish syntax. d96a1db7d7 audio: Opening via a logical device ID should also track default device. b2e020958f audio: Wrap device access in opening of logical devices. 7ee2459927 audio: Check for unlikely failure case in WAV loaded. 3d65a2cefe audio: Made SDL_LoadWAV a real function, not just a macro. 26525f5fd3 audio: Readd SDL_AudioSpec, but just with format/channels/freq fields. e6aaed7d79 include: Audio is not, and has not been, a raw mixing buffer for a long time. 56b1bc2198 audio: SDL_AudioStream now has callbacks for Get and Put operations. 905c4fff5b audio: First shot at the SDL3 audio subsystem redesign! b221b59995 cmake: add SDL_REVISION option 0500fca00c Add missing break d3f2de7f29 fixed typo in prev. patch. 12b35c6a46 test/testnativecocoa.m: fixed deprecation warnings. e24b3e2fa4 cmake: rename SDL_TEST -> SDL_TEST_LIBRARY da5016d336 cmake: use pkg-config + test compile instead of Find module for detecting rpi deec574ff6 cmake: fix SDL_HIDAPI_LIBUSB f2ae00c1ad Sync SDL3 wiki -> header 41a96c8133 doc: document building of SDL tests with CMake 3174d0b970 Sorted controller list 27b8abb056 Add Steam Deck controller mapping to database. 41d436f0fe Use SetWindowPos to show windows when SDL_HINT_WINDOW_ACTIVATE_WHEN_SHOWN is set to avoid activating the parent window when showing a child window 0dc85f3078 Improved the documentation for the gamepad paddle buttons 2fff999a41 Try to create the dummy mouse cursor after video backend initialization d086d9874d Sync SDL3 wiki -> header bce598addd SDL_pixels.c: Fixed compiler warning on Android NDK. ad0c0d3cde Sync SDL3 wiki -> header f8e8dff7ee tests: Fix automated window grab and positioning tests under Wayland/XWayland 4cffbc3644 Add VS code directory to gitignore 666f81bace Add more endian-specific aliases for 32 bit pixelformats 4749df0a63 Just disable the 4214 warning instead of trying to change the structure definition git-subtree-dir: external/sdl/SDL git-subtree-split: ec0042081ea104d5dd0ee291105210e00a4fe3d9
2023-08-12 20:17:29 +02:00
SDL_AssertJoysticksLocked();
if (!SDL_gamepads_initialized) {
return;
}
for (gamepad = SDL_gamepads; gamepad; gamepad = gamepad->next) {
if (gamepad->joystick->instance_id == instance_id) {
RecenterGamepad(gamepad);
break;
}
}
event.type = SDL_EVENT_GAMEPAD_REMOVED;
event.common.timestamp = 0;
event.gdevice.which = instance_id;
SDL_PushEvent(&event);
}
static void SDL_PrivateGamepadRemapped(SDL_JoystickID instance_id)
{
SDL_Event event;
if (!SDL_gamepads_initialized || SDL_IsJoystickBeingAdded()) {
return;
}
event.type = SDL_EVENT_GAMEPAD_REMAPPED;
event.common.timestamp = 0;
event.gdevice.which = instance_id;
SDL_PushEvent(&event);
}
/*
* Event filter to fire gamepad events from joystick ones
*/
static int SDLCALL SDL_GamepadEventWatcher(void *userdata, SDL_Event *event)
{
SDL_Gamepad *gamepad;
switch (event->type) {
case SDL_EVENT_JOYSTICK_AXIS_MOTION:
{
SDL_AssertJoysticksLocked();
for (gamepad = SDL_gamepads; gamepad; gamepad = gamepad->next) {
if (gamepad->joystick->instance_id == event->jaxis.which) {
HandleJoystickAxis(event->common.timestamp, gamepad, event->jaxis.axis, event->jaxis.value);
break;
}
}
} break;
case SDL_EVENT_JOYSTICK_BUTTON_DOWN:
case SDL_EVENT_JOYSTICK_BUTTON_UP:
{
SDL_AssertJoysticksLocked();
for (gamepad = SDL_gamepads; gamepad; gamepad = gamepad->next) {
if (gamepad->joystick->instance_id == event->jbutton.which) {
HandleJoystickButton(event->common.timestamp, gamepad, event->jbutton.button, event->jbutton.state);
break;
}
}
} break;
case SDL_EVENT_JOYSTICK_HAT_MOTION:
{
SDL_AssertJoysticksLocked();
for (gamepad = SDL_gamepads; gamepad; gamepad = gamepad->next) {
if (gamepad->joystick->instance_id == event->jhat.which) {
HandleJoystickHat(event->common.timestamp, gamepad, event->jhat.hat, event->jhat.value);
break;
}
}
} break;
case SDL_EVENT_JOYSTICK_UPDATE_COMPLETE:
{
SDL_AssertJoysticksLocked();
for (gamepad = SDL_gamepads; gamepad; gamepad = gamepad->next) {
if (gamepad->joystick->instance_id == event->jdevice.which) {
SDL_Event deviceevent;
deviceevent.type = SDL_EVENT_GAMEPAD_UPDATE_COMPLETE;
deviceevent.common.timestamp = event->jdevice.timestamp;
deviceevent.gdevice.which = event->jdevice.which;
SDL_PushEvent(&deviceevent);
break;
}
}
} break;
default:
break;
}
return 1;
}
/* SDL defines sensor orientation relative to the device natural
orientation, so when it's changed orientation to be used as a
gamepad, change the sensor orientation to match.
*/
static void AdjustSensorOrientation(SDL_Joystick *joystick, float *src, float *dst)
{
unsigned int i, j;
Squashed 'external/sdl/SDL/' changes from b8d91252c6..ec0042081e ec0042081e Add .gitattributes file a5d9db0cd0 cmake: build tests for UWP b7889a7389 winrt: use windowsio in non-libc mode ea8757a748 Make testaudiostreamdynamicresample compatible with emscripten 1a7a74fb2e cmake: build emscripten tests as html page 64d570f027 Add minimal http server for emscripten test apps 8e898c4a21 SDL_test does not parse --samples argument 91cd5478be audio: Fix resampler overflowing input buffer. f290c85b22 testaudiocapture: Make sure we convert captured audio to output format. b75c751dfc rwlock: Make generic implmentations work on single-threaded platforms. 80850af7ce The controller update complete events are no longer disabled by default 3f486224a9 Fixed refresh rate calculation for KMSDRM 342ec51131 Fix overflow when doing SDL_sscanf("%hd", ...) 9129e1d557 Fixed crash when setting the default cursor twice 8e99a4f4f5 Undo variable rename be67f0de10 Fixed crashes related to the default cursor on WinRT and KMSDRM 94b3f78c44 Fix out of bound read of 'has_hat' array 94f48f19b0 Use more specific build destinations when creating an xcframework dabd45997e Back out change supporting multiple names for binding elements efe15588d5 Relabel back paddles as left or right be884f0c95 ci: disable visionos.yml by renaming the file ac094d00f5 ci: add workflow_dispatch event to visionos workflow 9be9e2292b build: Consistently use pathlib APIs in cmake/xxd.py a9f6950657 Fixed deadlock shutting down Android sensors d9f09e77f2 Actually make the sensors magical! 690eae7d22 Implement visionOS support e385d6da0a Fixed build warning 6b93e788fa Improved sensor thread-safety 4ee0e5a984 Fixed thread-safety warnings 12deed91f8 Added information on how to enable thread-safety analysis 5735d2b03b coreaudio: Fixed assertion when device fails/quits mid-iteration. 1022fd6e04 testaudio: the test framework opens an audio device at startup; close it. 0714da37a4 audio: Fix audio stream callback calculations when future buffer has space. 917e036f6f MSVC has __declspec(deprecated) 279ff8909f Changed example code to avoid potential divide by zero 8a1afc9b10 Fixed Android not sending controller event timestamps 463c456b98 Fill the correct member with the joystick ID in SDL_EVENT_JOYSTICK_UPDATE_COMPLETE 55cf1abaa6 test: Don't flag testsurround as suitable for non-interactive use a2d594269c Fixed pixel format compatibility with SDL2 79a190aa23 Fixed setting invalid bpp for FOURCC formats in SDL_GetMasksForPixelFormatEnum() 8fdebdd3e0 Sync SDL3 wiki -> header b903ccf945 SDL_rwops read/write functions return size_t again c03f5b4b69 Fixed rounding up in SDL_PrintFloat 75a020aa6b Only query serial number and firmware versions from Sony PS5 controllers fa189d302e Added the Victrix Pro FS for PS4/PS5 to the controller list 26205b659d Fixed PS4/PS5 touchpad for third party controllers 6af0448af9 include: fixed a typo in SDL_RenderGetMetalCommandEncoder docs. f3cb46b083 SDL_thread.h: do not conflict with sdl2-compat::sdl3_include_wrapper.h 080b1dfbdb Revert "Improved fallback for SDL_COMPILE_TIME_ASSERT() (thanks @icculus!)" 9d453daa23 Improved fallback for SDL_COMPILE_TIME_ASSERT() (thanks @icculus!) 1fb2419882 Removed reference to renamed function e7d56dd0b2 audio: Renamed new API SDL_UnpauseAudioDevice to SDL_ResumeAudioDevice. 2b0c0f5b6b Don't pass NULL to strncmp 778e8185cd Fix size of memcpy in SDL_AudioDeviceFormatChangedAlreadyLocked And add diagnostic that allows to find this kind of issue in clang-tidy 4bb426abad Sync SDL3 wiki -> header 3a752ce650 Reapply "Changed 'freesrc' parameter from int to SDL_bool" to SDL_wave.c 2ba03b4db0 fix build after previous commit. 0026adffd4 apply force_align_arg_pointer attribute to correct version of SDL_RunApp 77446e2029 Unaligned stacks on i686-w64-mingw32 may lead to crashes d3bcc3f057 Fixed build errors when OpenGL isn't enabled 35ad68e126 Sync SDL3 wiki -> header 70323a8350 Add a function to display the system menu for a window be5f66c84e testaudio: Fixed soundboard icon, which had a colorkey issue. c0a88930bf Sync SDL3 wiki -> header 18c59cc969 Merge the SDL3 audio subsystem redesign! 99b0e31788 The Steam Controller D-Pad is only pressed when the button is pressed down 103073d694 Set NSBluetoothAlwaysUsageDescription for testcontroller ca02bb6c8c We don't need testdropfile-Info.plist e063f662e9 Enable the controller update complete events 06bea1eb55 Added a gamepad mapping for the G-Shark GS-GP702 5ca3c50bf0 testaudio: Fix compiler warning. 1b1f02c5aa testaudio: Apparently compilers don't like this possibly being NULL now...? 2de9253b6c test: Added testaudio fb3ab3f113 SDL_video.c: move ngage video before offscreen. 843572d993 Don't mark autorelease keys as virtual 648de4f9b8 Fixed duplicate key press/release events on iOS a8abe612ed Only pass keypresses up the responder chain when text input is active c3288d113e Synchronize on-screen keyboard state with text input active state 5fb92ef2f7 Fixed whitespace f5ea6ae18d Revert "Stop beep when running iOS apps on ARM-based Macs" 546508b9b4 Allow test programs to run at full resolution on iPads 68a4bb01e0 Allocate displays as an array of pointers instead of an array of objects 07578fde3d Fixed crash if a display is enumerated twice a509771a87 fix ios CI workflow after commit e4460e897f 72ce76905a The scheme isn't always the same as the framework name (e.g. xmp_lite vs xmp-lite) e4460e897f By default Xcode expects the framework target name to be the name of the project. ac683773dc Added missing tests to the "All" target 7dd56eaafe Removed unnecessary reference to testoverlay-Info.plist e1c7f524ef Reduce the number of times SDL3 is duplicated in the xcframework script 65538011ca Make Xcode targets more specific efe114c300 Revert "Renamed the xcframework target from "SDL.xcframework" to "xcframework"" 73ed1d21a9 Renamed the xcframework target from "SDL.xcframework" to "xcframework" 76b4d8a0d8 Build the Framework instead of a static library for iOS and tvOS d1bf979160 Removed unnecessary setting from the "Create DMG" target c94cb3a5d8 Simplified the Xcode project to a single Framework target ea60474c65 cmake: don't build SDL3-static Apple framework 8f00d7856d Sync SDL3 wiki -> header d4a867a256 Rename SDL_GetPath to SDL_GetUserFolder 71099149b8 Fall back to Xlib if XRandR isn't available b7f32f74ce Note the removal of the SDL_RENDERER_TARGETTEXTURE flag 0eda582160 testaudiostreamdynamicresample: Load sample.wav correctly. 87eae9a0a1 aaudio: We need a mixbuf on capture devices, too. fb68e84646 wayland: Fix memory leaks b0edd23c00 testsurround: Log available audio output devices at the start. ae3090c387 androidaudio: Move Init/bootstrap code to bottom of source code. 18fc0db9e5 aaudio: Rearranged source code to match other backends. 2507c1d68b aaudio: Disconnect playing devices if error callback fires. 32a3fc3783 aaudio: Use the callback interface. b49ce86765 audio: Fixed compiler warning on Android NDK. 1c074e8d97 android: Fixed audio device detection. 82ce05ad01 pulseaudio: Be more aggressive with hotplug thread synchronization. 5cbdf1168e androidaudio: Fixed incorrect JNI call (thanks, @madebr!) 660054f3dc include: Correct comment about audio device hotplug events. ab68428a64 aaudio: Fixed for older SDKs and Android releases. 5ff87c6d4a android: Reworked audio backends for SDL3 audio API. 54af687210 testautomation_audio.c: Patched to compile. :/ 5e82090662 testautomation_audio.c: Apparently we aren't updating test code for C99 atm. 7f4488f625 wasapi: More fixes for Clang warnings. 29a0c689c9 wasapi: Patched to compile with Clang. 4aa95c21bc pspaudio: Patched to compile. 9a2a0a1463 ps2audio: Delete errant character that got inserted before previous commit. 2c578bd0d5 qnxaudio: Rewrite for SDL3 audio APIs. 455eef4cd9 audio: Use AtomicAdd for device counts, don't treat as a refcount. 095ea57f94 pspaudio: Patched to compile. d7cf63db67 ps2audio: Patched to compile. 027b9e8787 coreaudio: (maybe) patched to compile on iOS. 4836c2db07 pspaudio: Patched to compile. 86ca412436 n3dsaudio: Patched to compile. 66bcee2ca9 testaudiostreamdynamicresample.c: Fixed MSVC compiler warning. dbf993d358 vitaaudio: patched to compile. 5707e14716 audio: Fix up some things that broke when rebasing the branch against main. 6567285eae SDL_migration.cocci: Fix up SDL_(Pause|Unpause)Audio. 0b6255551e test: Fixed incorrect SDL_OpenAudioDevice call in testautomation. 107fd941cd vitaaudio: Clean up correctly in CloseDevice. 9fa4a6ef87 netbsdaudio: Minor fix. b0d89868c6 n3dsaudio: Updated (but untested!) for SDL3 audio API. ba27176106 vitaaudio: Untested attempt to move Vita audio to SDL3's audio API. 0b58e96d9e wasapi: Patched WinRT to compile. d6b4f48488 visualc: Turn on multiprocessor compilation. c58d95c343 wasapi: Reworked for new SDL3 audio API, other win32 fixes. dc04f85646 audio: whoops, that should be an int. be0dc630b7 audio: Fixed incorrect assertion 77b3fb06ee directsound: First shot at updating for SDL3 audio API. 4399b71715 audio: Generalize how backends can lookup an SDL_AudioDevice. 2fb122fe46 audio: backends now "find" instead of "obtain" devices by handle. c3f5a5fc72 dummyaudio: SDL3ify style 7d65ff86e2 diskaudio: Adjusted for later SDL3 audio API redesign changes. 4ba9c2eade dummyaudio: Configurable delay, other SDL3 API fixes. fb395d3ad7 sndio: Updated to the SDL3 audio API. 1a55282051 dsp: Some minor logic fixes 6bc85577d7 netbsdaudio: Updated for SDL3 audio API. 0f6e59312b netbsdaudio: Removed email address from source code. 51ae78c0af haikuaudio: Updated for SDL3 audio API. fc7ed18ca1 emscriptenaudio: don't forget to finalize the audio thread 4233c41ce2 pulseaudio: Removed unnecessary variable. a0528cd5ed emscriptenaudio: Updated for SDL3 audio API. 79cc29ba35 wave: Don't check if format->channels > INT_MAX, it's a Uint16. 1bfe97c235 pspaudio: Updated for SDL3 audio API. 121a2dce15 audio: Make sure `device->hidden` is NULL after CloseDevice 3d6ba0cafd ps2audio: Removed free of buffer that hasn't been allocated yet. 00ed6f8827 test: Fixed compiler warnings for unused vars. 6f12f68ec9 ps2audio: SDL3ified the style 4993743a02 ps2audio: Renamed `_this` to `device` 74568cdb2b ps2audio: Updated (but untested) for SDL3 audio API. c83b68ef26 jack: renamed `_this` to `device`. 3f4f004794 audio: Remove an assertion that no longer makes sense. 86243b2589 jack: Use ProvidesOwnCallbackThread. 18906a32b8 jack: First shot at updating for SDL3 audio API. a2b488359e dsp: Removed debug logging 6fd71185cd dsp: Updated for new SDL3 audio API. 3482d1215a alsa: Don't ever block in CaptureFromDevice. 65d296ef1a audio: Use SDL_powerof2 instead of reinventing it. 409b544505 alsa: Updated for new SDL3 audio API 0999a090a7 audio: More tweaking of `device->thread_alive` f94ffd6092 audio: Fixed logic error 4deb2970c9 alsa: Renamed `_this` to `device` 0fb9e4baae audio: Remove no-longer-used SupportsNonPow2Samples c653e57768 coreaudio: rewritten for SDL3 audio redesign! 533777eff5 audio: SDL_sysaudio.h comment conversion. 8473e522e0 audio: unify device thread naming. 258bc9efed audio: PlayDevice now passes the buffer, too, for convenience. e518149d14 audio: Fixed locking in SDL_AudioDeviceDisconnected 22afa5735f audio: FreeDeviceHandle should pass the whole device, for convenience. 9e3c5f93e0 coreaudio: Change `_this` to `device` e969160de0 audio: unset a freed variable to NULL 1fc01b0300 audio: Try to definitely have a default device set up. b60a56d368 audio: take first reported device if no default was specified. a8323ebe68 audio: Better handling of ProvidesOwnCallbackThread backends. 1dffb72c1d pipewire: Hooked up default device change notifications. a93fcf2444 audio: fixed flushed stream reporting bytes but not being able to get them. ad6c1781fc pulseaudio: Minor cleanups. cfc8a0d17d pipewire: First shot at moving to the new SDL3 audio interfaces. 13202642a3 aaudio: Fixed capitialization, plus some minor cleanups. 3e9991b535 audio: Make sure we don't write to a NULL pointer. 943351affb pulseaudio: GetDefaultAudioInfo isn't a thing anymore. 11dfc4d737 test: Update testautomation_audio for SDL3 audio API. 29afc2e42b test: Update testresample for SDL3 audio API. 3a02eecced test: Update testsurround for SDL3 audio API. e1c78718d4 test: testaudiocapture is updated for the SDL3 audio API. f48cb716c2 pulseaudio: a couple minor tweaks. dac25fe9eb audio: Seperate audio capture into Wait/Read operations. 3e10c0005d audio: Capture devices should respect logical device pausing. 7e700531c5 audio: Allow SDL_OpenAudioDevice to accept a NULL spec. bb1cbbd33a test: Update testaudioinfo for SDL3 audio API. 883aee32c5 audio: Let default formats differ for output and capture devices. 62cf24eeb9 pulseaudio: Listen for server events in addition to sources and sinks. 924f370bd7 pulseaudio: Fix deadlock in HotplugThread. 5d4e9e5f80 test: Updated testaudiostreamdynamicresample to SDL3 audio API. f883b9fc64 test: Updated testaudiohotplug to SDL3 audio API. 2be5f726d4 audio: Removed debug logging. 323ecce123 docs: Added migration note about SDL_AUDIODEVICEREMOVED. 47b0321ebf test: Removed loopwavequeue.c; obsolete in SDL3. 0e5a1d4f29 pulseaudio: Removed debug logging. f598626e46 test: loopwave shouldn't use an audiostream callback. eee407caf8 docs: migration guide note that SDL_LoadWAV has a different return type. b03c493fc4 test: Updated testmultiaudio to new SDL3 audio API fe1daf6fb5 audio: Mark disconnected default devices as "zombies". cdd2ba81de audio: Fixed adding new physical devices to a double-linked list. db39cbf208 audio: Allow SDL_GetAudioDeviceFormat() to query the default devices. ee10bab3cd audio: An enormous amount of work on managing default devices. c7a44eea83 audio: Fixed logic error. 089cd87cb5 audio: Make sure device count stays correct as hardware disconnects. e50cb72eb6 docs: Note that audio opening doesn't implicitly init SDL now. 97b2f747d0 docs: Corrections to audio section of README-migration.md 464640440f audio: Added SDL_GetAudioStreamBinding. 01f7b53865 audio: Readded (logical) device pausing. fd4c9f4e11 audio: documentation improvements. 4b78b789a7 audio: Switch SDL_audio.c and SDL_audiocvt.c to C99-ish syntax. d96a1db7d7 audio: Opening via a logical device ID should also track default device. b2e020958f audio: Wrap device access in opening of logical devices. 7ee2459927 audio: Check for unlikely failure case in WAV loaded. 3d65a2cefe audio: Made SDL_LoadWAV a real function, not just a macro. 26525f5fd3 audio: Readd SDL_AudioSpec, but just with format/channels/freq fields. e6aaed7d79 include: Audio is not, and has not been, a raw mixing buffer for a long time. 56b1bc2198 audio: SDL_AudioStream now has callbacks for Get and Put operations. 905c4fff5b audio: First shot at the SDL3 audio subsystem redesign! b221b59995 cmake: add SDL_REVISION option 0500fca00c Add missing break d3f2de7f29 fixed typo in prev. patch. 12b35c6a46 test/testnativecocoa.m: fixed deprecation warnings. e24b3e2fa4 cmake: rename SDL_TEST -> SDL_TEST_LIBRARY da5016d336 cmake: use pkg-config + test compile instead of Find module for detecting rpi deec574ff6 cmake: fix SDL_HIDAPI_LIBUSB f2ae00c1ad Sync SDL3 wiki -> header 41a96c8133 doc: document building of SDL tests with CMake 3174d0b970 Sorted controller list 27b8abb056 Add Steam Deck controller mapping to database. 41d436f0fe Use SetWindowPos to show windows when SDL_HINT_WINDOW_ACTIVATE_WHEN_SHOWN is set to avoid activating the parent window when showing a child window 0dc85f3078 Improved the documentation for the gamepad paddle buttons 2fff999a41 Try to create the dummy mouse cursor after video backend initialization d086d9874d Sync SDL3 wiki -> header bce598addd SDL_pixels.c: Fixed compiler warning on Android NDK. ad0c0d3cde Sync SDL3 wiki -> header f8e8dff7ee tests: Fix automated window grab and positioning tests under Wayland/XWayland 4cffbc3644 Add VS code directory to gitignore 666f81bace Add more endian-specific aliases for 32 bit pixelformats 4749df0a63 Just disable the 4214 warning instead of trying to change the structure definition git-subtree-dir: external/sdl/SDL git-subtree-split: ec0042081ea104d5dd0ee291105210e00a4fe3d9
2023-08-12 20:17:29 +02:00
SDL_AssertJoysticksLocked();
for (i = 0; i < 3; ++i) {
dst[i] = 0.0f;
for (j = 0; j < 3; ++j) {
dst[i] += joystick->sensor_transform[i][j] * src[j];
}
}
}
/*
* Event filter to fire gamepad sensor events from system sensor events
*
* We don't use SDL_GamepadEventWatcher() for this because we want to
* deliver gamepad sensor events when system sensor events are disabled,
* and we also need to avoid a potential deadlock where joystick event
* delivery locks the joysticks and then the event queue, but sensor
* event delivery would lock the event queue and then from within the
* event watcher function lock the joysticks.
*/
void SDL_GamepadSensorWatcher(Uint64 timestamp, SDL_SensorID sensor, Uint64 sensor_timestamp, float *data, int num_values)
{
SDL_Gamepad *gamepad;
SDL_LockJoysticks();
for (gamepad = SDL_gamepads; gamepad; gamepad = gamepad->next) {
if (gamepad->joystick->accel && gamepad->joystick->accel_sensor == sensor) {
float gamepad_data[3];
AdjustSensorOrientation(gamepad->joystick, data, gamepad_data);
SDL_SendJoystickSensor(timestamp, gamepad->joystick, SDL_SENSOR_ACCEL, sensor_timestamp, gamepad_data, SDL_arraysize(gamepad_data));
}
if (gamepad->joystick->gyro && gamepad->joystick->gyro_sensor == sensor) {
float gamepad_data[3];
AdjustSensorOrientation(gamepad->joystick, data, gamepad_data);
SDL_SendJoystickSensor(timestamp, gamepad->joystick, SDL_SENSOR_GYRO, sensor_timestamp, gamepad_data, SDL_arraysize(gamepad_data));
}
}
SDL_UnlockJoysticks();
}
static void PushMappingChangeTracking(void)
{
MappingChangeTracker *tracker;
int i, num_joysticks;
SDL_AssertJoysticksLocked();
if (s_mappingChangeTracker) {
++s_mappingChangeTracker->refcount;
return;
}
s_mappingChangeTracker = (MappingChangeTracker *)SDL_calloc(1, sizeof(*tracker));
s_mappingChangeTracker->refcount = 1;
/* Save the list of joysticks and associated mappings */
tracker = s_mappingChangeTracker;
tracker->joysticks = SDL_GetJoysticks(&num_joysticks);
if (!tracker->joysticks) {
return;
}
if (num_joysticks == 0) {
return;
}
tracker->joystick_mappings = (GamepadMapping_t **)SDL_malloc(num_joysticks * sizeof(*tracker->joystick_mappings));
if (!tracker->joystick_mappings) {
return;
}
for (i = 0; i < num_joysticks; ++i) {
tracker->joystick_mappings[i] = SDL_PrivateGetGamepadMapping(tracker->joysticks[i]);
}
}
static void AddMappingChangeTracking(GamepadMapping_t *mapping)
{
MappingChangeTracker *tracker;
int num_mappings;
GamepadMapping_t **new_mappings;
SDL_AssertJoysticksLocked();
SDL_assert(s_mappingChangeTracker != NULL);
tracker = s_mappingChangeTracker;
num_mappings = tracker->num_changed_mappings;
new_mappings = (GamepadMapping_t **)SDL_realloc(tracker->changed_mappings, (num_mappings + 1) * sizeof(*new_mappings));
if (new_mappings) {
tracker->changed_mappings = new_mappings;
tracker->changed_mappings[num_mappings] = mapping;
tracker->num_changed_mappings = (num_mappings + 1);
}
}
static SDL_bool HasMappingChangeTracking(MappingChangeTracker *tracker, GamepadMapping_t *mapping)
{
int i;
Squashed 'external/sdl/SDL/' changes from b8d91252c6..ec0042081e ec0042081e Add .gitattributes file a5d9db0cd0 cmake: build tests for UWP b7889a7389 winrt: use windowsio in non-libc mode ea8757a748 Make testaudiostreamdynamicresample compatible with emscripten 1a7a74fb2e cmake: build emscripten tests as html page 64d570f027 Add minimal http server for emscripten test apps 8e898c4a21 SDL_test does not parse --samples argument 91cd5478be audio: Fix resampler overflowing input buffer. f290c85b22 testaudiocapture: Make sure we convert captured audio to output format. b75c751dfc rwlock: Make generic implmentations work on single-threaded platforms. 80850af7ce The controller update complete events are no longer disabled by default 3f486224a9 Fixed refresh rate calculation for KMSDRM 342ec51131 Fix overflow when doing SDL_sscanf("%hd", ...) 9129e1d557 Fixed crash when setting the default cursor twice 8e99a4f4f5 Undo variable rename be67f0de10 Fixed crashes related to the default cursor on WinRT and KMSDRM 94b3f78c44 Fix out of bound read of 'has_hat' array 94f48f19b0 Use more specific build destinations when creating an xcframework dabd45997e Back out change supporting multiple names for binding elements efe15588d5 Relabel back paddles as left or right be884f0c95 ci: disable visionos.yml by renaming the file ac094d00f5 ci: add workflow_dispatch event to visionos workflow 9be9e2292b build: Consistently use pathlib APIs in cmake/xxd.py a9f6950657 Fixed deadlock shutting down Android sensors d9f09e77f2 Actually make the sensors magical! 690eae7d22 Implement visionOS support e385d6da0a Fixed build warning 6b93e788fa Improved sensor thread-safety 4ee0e5a984 Fixed thread-safety warnings 12deed91f8 Added information on how to enable thread-safety analysis 5735d2b03b coreaudio: Fixed assertion when device fails/quits mid-iteration. 1022fd6e04 testaudio: the test framework opens an audio device at startup; close it. 0714da37a4 audio: Fix audio stream callback calculations when future buffer has space. 917e036f6f MSVC has __declspec(deprecated) 279ff8909f Changed example code to avoid potential divide by zero 8a1afc9b10 Fixed Android not sending controller event timestamps 463c456b98 Fill the correct member with the joystick ID in SDL_EVENT_JOYSTICK_UPDATE_COMPLETE 55cf1abaa6 test: Don't flag testsurround as suitable for non-interactive use a2d594269c Fixed pixel format compatibility with SDL2 79a190aa23 Fixed setting invalid bpp for FOURCC formats in SDL_GetMasksForPixelFormatEnum() 8fdebdd3e0 Sync SDL3 wiki -> header b903ccf945 SDL_rwops read/write functions return size_t again c03f5b4b69 Fixed rounding up in SDL_PrintFloat 75a020aa6b Only query serial number and firmware versions from Sony PS5 controllers fa189d302e Added the Victrix Pro FS for PS4/PS5 to the controller list 26205b659d Fixed PS4/PS5 touchpad for third party controllers 6af0448af9 include: fixed a typo in SDL_RenderGetMetalCommandEncoder docs. f3cb46b083 SDL_thread.h: do not conflict with sdl2-compat::sdl3_include_wrapper.h 080b1dfbdb Revert "Improved fallback for SDL_COMPILE_TIME_ASSERT() (thanks @icculus!)" 9d453daa23 Improved fallback for SDL_COMPILE_TIME_ASSERT() (thanks @icculus!) 1fb2419882 Removed reference to renamed function e7d56dd0b2 audio: Renamed new API SDL_UnpauseAudioDevice to SDL_ResumeAudioDevice. 2b0c0f5b6b Don't pass NULL to strncmp 778e8185cd Fix size of memcpy in SDL_AudioDeviceFormatChangedAlreadyLocked And add diagnostic that allows to find this kind of issue in clang-tidy 4bb426abad Sync SDL3 wiki -> header 3a752ce650 Reapply "Changed 'freesrc' parameter from int to SDL_bool" to SDL_wave.c 2ba03b4db0 fix build after previous commit. 0026adffd4 apply force_align_arg_pointer attribute to correct version of SDL_RunApp 77446e2029 Unaligned stacks on i686-w64-mingw32 may lead to crashes d3bcc3f057 Fixed build errors when OpenGL isn't enabled 35ad68e126 Sync SDL3 wiki -> header 70323a8350 Add a function to display the system menu for a window be5f66c84e testaudio: Fixed soundboard icon, which had a colorkey issue. c0a88930bf Sync SDL3 wiki -> header 18c59cc969 Merge the SDL3 audio subsystem redesign! 99b0e31788 The Steam Controller D-Pad is only pressed when the button is pressed down 103073d694 Set NSBluetoothAlwaysUsageDescription for testcontroller ca02bb6c8c We don't need testdropfile-Info.plist e063f662e9 Enable the controller update complete events 06bea1eb55 Added a gamepad mapping for the G-Shark GS-GP702 5ca3c50bf0 testaudio: Fix compiler warning. 1b1f02c5aa testaudio: Apparently compilers don't like this possibly being NULL now...? 2de9253b6c test: Added testaudio fb3ab3f113 SDL_video.c: move ngage video before offscreen. 843572d993 Don't mark autorelease keys as virtual 648de4f9b8 Fixed duplicate key press/release events on iOS a8abe612ed Only pass keypresses up the responder chain when text input is active c3288d113e Synchronize on-screen keyboard state with text input active state 5fb92ef2f7 Fixed whitespace f5ea6ae18d Revert "Stop beep when running iOS apps on ARM-based Macs" 546508b9b4 Allow test programs to run at full resolution on iPads 68a4bb01e0 Allocate displays as an array of pointers instead of an array of objects 07578fde3d Fixed crash if a display is enumerated twice a509771a87 fix ios CI workflow after commit e4460e897f 72ce76905a The scheme isn't always the same as the framework name (e.g. xmp_lite vs xmp-lite) e4460e897f By default Xcode expects the framework target name to be the name of the project. ac683773dc Added missing tests to the "All" target 7dd56eaafe Removed unnecessary reference to testoverlay-Info.plist e1c7f524ef Reduce the number of times SDL3 is duplicated in the xcframework script 65538011ca Make Xcode targets more specific efe114c300 Revert "Renamed the xcframework target from "SDL.xcframework" to "xcframework"" 73ed1d21a9 Renamed the xcframework target from "SDL.xcframework" to "xcframework" 76b4d8a0d8 Build the Framework instead of a static library for iOS and tvOS d1bf979160 Removed unnecessary setting from the "Create DMG" target c94cb3a5d8 Simplified the Xcode project to a single Framework target ea60474c65 cmake: don't build SDL3-static Apple framework 8f00d7856d Sync SDL3 wiki -> header d4a867a256 Rename SDL_GetPath to SDL_GetUserFolder 71099149b8 Fall back to Xlib if XRandR isn't available b7f32f74ce Note the removal of the SDL_RENDERER_TARGETTEXTURE flag 0eda582160 testaudiostreamdynamicresample: Load sample.wav correctly. 87eae9a0a1 aaudio: We need a mixbuf on capture devices, too. fb68e84646 wayland: Fix memory leaks b0edd23c00 testsurround: Log available audio output devices at the start. ae3090c387 androidaudio: Move Init/bootstrap code to bottom of source code. 18fc0db9e5 aaudio: Rearranged source code to match other backends. 2507c1d68b aaudio: Disconnect playing devices if error callback fires. 32a3fc3783 aaudio: Use the callback interface. b49ce86765 audio: Fixed compiler warning on Android NDK. 1c074e8d97 android: Fixed audio device detection. 82ce05ad01 pulseaudio: Be more aggressive with hotplug thread synchronization. 5cbdf1168e androidaudio: Fixed incorrect JNI call (thanks, @madebr!) 660054f3dc include: Correct comment about audio device hotplug events. ab68428a64 aaudio: Fixed for older SDKs and Android releases. 5ff87c6d4a android: Reworked audio backends for SDL3 audio API. 54af687210 testautomation_audio.c: Patched to compile. :/ 5e82090662 testautomation_audio.c: Apparently we aren't updating test code for C99 atm. 7f4488f625 wasapi: More fixes for Clang warnings. 29a0c689c9 wasapi: Patched to compile with Clang. 4aa95c21bc pspaudio: Patched to compile. 9a2a0a1463 ps2audio: Delete errant character that got inserted before previous commit. 2c578bd0d5 qnxaudio: Rewrite for SDL3 audio APIs. 455eef4cd9 audio: Use AtomicAdd for device counts, don't treat as a refcount. 095ea57f94 pspaudio: Patched to compile. d7cf63db67 ps2audio: Patched to compile. 027b9e8787 coreaudio: (maybe) patched to compile on iOS. 4836c2db07 pspaudio: Patched to compile. 86ca412436 n3dsaudio: Patched to compile. 66bcee2ca9 testaudiostreamdynamicresample.c: Fixed MSVC compiler warning. dbf993d358 vitaaudio: patched to compile. 5707e14716 audio: Fix up some things that broke when rebasing the branch against main. 6567285eae SDL_migration.cocci: Fix up SDL_(Pause|Unpause)Audio. 0b6255551e test: Fixed incorrect SDL_OpenAudioDevice call in testautomation. 107fd941cd vitaaudio: Clean up correctly in CloseDevice. 9fa4a6ef87 netbsdaudio: Minor fix. b0d89868c6 n3dsaudio: Updated (but untested!) for SDL3 audio API. ba27176106 vitaaudio: Untested attempt to move Vita audio to SDL3's audio API. 0b58e96d9e wasapi: Patched WinRT to compile. d6b4f48488 visualc: Turn on multiprocessor compilation. c58d95c343 wasapi: Reworked for new SDL3 audio API, other win32 fixes. dc04f85646 audio: whoops, that should be an int. be0dc630b7 audio: Fixed incorrect assertion 77b3fb06ee directsound: First shot at updating for SDL3 audio API. 4399b71715 audio: Generalize how backends can lookup an SDL_AudioDevice. 2fb122fe46 audio: backends now "find" instead of "obtain" devices by handle. c3f5a5fc72 dummyaudio: SDL3ify style 7d65ff86e2 diskaudio: Adjusted for later SDL3 audio API redesign changes. 4ba9c2eade dummyaudio: Configurable delay, other SDL3 API fixes. fb395d3ad7 sndio: Updated to the SDL3 audio API. 1a55282051 dsp: Some minor logic fixes 6bc85577d7 netbsdaudio: Updated for SDL3 audio API. 0f6e59312b netbsdaudio: Removed email address from source code. 51ae78c0af haikuaudio: Updated for SDL3 audio API. fc7ed18ca1 emscriptenaudio: don't forget to finalize the audio thread 4233c41ce2 pulseaudio: Removed unnecessary variable. a0528cd5ed emscriptenaudio: Updated for SDL3 audio API. 79cc29ba35 wave: Don't check if format->channels > INT_MAX, it's a Uint16. 1bfe97c235 pspaudio: Updated for SDL3 audio API. 121a2dce15 audio: Make sure `device->hidden` is NULL after CloseDevice 3d6ba0cafd ps2audio: Removed free of buffer that hasn't been allocated yet. 00ed6f8827 test: Fixed compiler warnings for unused vars. 6f12f68ec9 ps2audio: SDL3ified the style 4993743a02 ps2audio: Renamed `_this` to `device` 74568cdb2b ps2audio: Updated (but untested) for SDL3 audio API. c83b68ef26 jack: renamed `_this` to `device`. 3f4f004794 audio: Remove an assertion that no longer makes sense. 86243b2589 jack: Use ProvidesOwnCallbackThread. 18906a32b8 jack: First shot at updating for SDL3 audio API. a2b488359e dsp: Removed debug logging 6fd71185cd dsp: Updated for new SDL3 audio API. 3482d1215a alsa: Don't ever block in CaptureFromDevice. 65d296ef1a audio: Use SDL_powerof2 instead of reinventing it. 409b544505 alsa: Updated for new SDL3 audio API 0999a090a7 audio: More tweaking of `device->thread_alive` f94ffd6092 audio: Fixed logic error 4deb2970c9 alsa: Renamed `_this` to `device` 0fb9e4baae audio: Remove no-longer-used SupportsNonPow2Samples c653e57768 coreaudio: rewritten for SDL3 audio redesign! 533777eff5 audio: SDL_sysaudio.h comment conversion. 8473e522e0 audio: unify device thread naming. 258bc9efed audio: PlayDevice now passes the buffer, too, for convenience. e518149d14 audio: Fixed locking in SDL_AudioDeviceDisconnected 22afa5735f audio: FreeDeviceHandle should pass the whole device, for convenience. 9e3c5f93e0 coreaudio: Change `_this` to `device` e969160de0 audio: unset a freed variable to NULL 1fc01b0300 audio: Try to definitely have a default device set up. b60a56d368 audio: take first reported device if no default was specified. a8323ebe68 audio: Better handling of ProvidesOwnCallbackThread backends. 1dffb72c1d pipewire: Hooked up default device change notifications. a93fcf2444 audio: fixed flushed stream reporting bytes but not being able to get them. ad6c1781fc pulseaudio: Minor cleanups. cfc8a0d17d pipewire: First shot at moving to the new SDL3 audio interfaces. 13202642a3 aaudio: Fixed capitialization, plus some minor cleanups. 3e9991b535 audio: Make sure we don't write to a NULL pointer. 943351affb pulseaudio: GetDefaultAudioInfo isn't a thing anymore. 11dfc4d737 test: Update testautomation_audio for SDL3 audio API. 29afc2e42b test: Update testresample for SDL3 audio API. 3a02eecced test: Update testsurround for SDL3 audio API. e1c78718d4 test: testaudiocapture is updated for the SDL3 audio API. f48cb716c2 pulseaudio: a couple minor tweaks. dac25fe9eb audio: Seperate audio capture into Wait/Read operations. 3e10c0005d audio: Capture devices should respect logical device pausing. 7e700531c5 audio: Allow SDL_OpenAudioDevice to accept a NULL spec. bb1cbbd33a test: Update testaudioinfo for SDL3 audio API. 883aee32c5 audio: Let default formats differ for output and capture devices. 62cf24eeb9 pulseaudio: Listen for server events in addition to sources and sinks. 924f370bd7 pulseaudio: Fix deadlock in HotplugThread. 5d4e9e5f80 test: Updated testaudiostreamdynamicresample to SDL3 audio API. f883b9fc64 test: Updated testaudiohotplug to SDL3 audio API. 2be5f726d4 audio: Removed debug logging. 323ecce123 docs: Added migration note about SDL_AUDIODEVICEREMOVED. 47b0321ebf test: Removed loopwavequeue.c; obsolete in SDL3. 0e5a1d4f29 pulseaudio: Removed debug logging. f598626e46 test: loopwave shouldn't use an audiostream callback. eee407caf8 docs: migration guide note that SDL_LoadWAV has a different return type. b03c493fc4 test: Updated testmultiaudio to new SDL3 audio API fe1daf6fb5 audio: Mark disconnected default devices as "zombies". cdd2ba81de audio: Fixed adding new physical devices to a double-linked list. db39cbf208 audio: Allow SDL_GetAudioDeviceFormat() to query the default devices. ee10bab3cd audio: An enormous amount of work on managing default devices. c7a44eea83 audio: Fixed logic error. 089cd87cb5 audio: Make sure device count stays correct as hardware disconnects. e50cb72eb6 docs: Note that audio opening doesn't implicitly init SDL now. 97b2f747d0 docs: Corrections to audio section of README-migration.md 464640440f audio: Added SDL_GetAudioStreamBinding. 01f7b53865 audio: Readded (logical) device pausing. fd4c9f4e11 audio: documentation improvements. 4b78b789a7 audio: Switch SDL_audio.c and SDL_audiocvt.c to C99-ish syntax. d96a1db7d7 audio: Opening via a logical device ID should also track default device. b2e020958f audio: Wrap device access in opening of logical devices. 7ee2459927 audio: Check for unlikely failure case in WAV loaded. 3d65a2cefe audio: Made SDL_LoadWAV a real function, not just a macro. 26525f5fd3 audio: Readd SDL_AudioSpec, but just with format/channels/freq fields. e6aaed7d79 include: Audio is not, and has not been, a raw mixing buffer for a long time. 56b1bc2198 audio: SDL_AudioStream now has callbacks for Get and Put operations. 905c4fff5b audio: First shot at the SDL3 audio subsystem redesign! b221b59995 cmake: add SDL_REVISION option 0500fca00c Add missing break d3f2de7f29 fixed typo in prev. patch. 12b35c6a46 test/testnativecocoa.m: fixed deprecation warnings. e24b3e2fa4 cmake: rename SDL_TEST -> SDL_TEST_LIBRARY da5016d336 cmake: use pkg-config + test compile instead of Find module for detecting rpi deec574ff6 cmake: fix SDL_HIDAPI_LIBUSB f2ae00c1ad Sync SDL3 wiki -> header 41a96c8133 doc: document building of SDL tests with CMake 3174d0b970 Sorted controller list 27b8abb056 Add Steam Deck controller mapping to database. 41d436f0fe Use SetWindowPos to show windows when SDL_HINT_WINDOW_ACTIVATE_WHEN_SHOWN is set to avoid activating the parent window when showing a child window 0dc85f3078 Improved the documentation for the gamepad paddle buttons 2fff999a41 Try to create the dummy mouse cursor after video backend initialization d086d9874d Sync SDL3 wiki -> header bce598addd SDL_pixels.c: Fixed compiler warning on Android NDK. ad0c0d3cde Sync SDL3 wiki -> header f8e8dff7ee tests: Fix automated window grab and positioning tests under Wayland/XWayland 4cffbc3644 Add VS code directory to gitignore 666f81bace Add more endian-specific aliases for 32 bit pixelformats 4749df0a63 Just disable the 4214 warning instead of trying to change the structure definition git-subtree-dir: external/sdl/SDL git-subtree-split: ec0042081ea104d5dd0ee291105210e00a4fe3d9
2023-08-12 20:17:29 +02:00
SDL_AssertJoysticksLocked();
for (i = 0; i < tracker->num_changed_mappings; ++i) {
if (tracker->changed_mappings[i] == mapping) {
return SDL_TRUE;
}
}
return SDL_FALSE;
}
static void PopMappingChangeTracking(void)
{
int i;
MappingChangeTracker *tracker;
SDL_AssertJoysticksLocked();
SDL_assert(s_mappingChangeTracker != NULL);
tracker = s_mappingChangeTracker;
--tracker->refcount;
if (tracker->refcount > 0) {
return;
}
s_mappingChangeTracker = NULL;
/* Now check to see what gamepads changed because of the mapping changes */
if (tracker->joysticks && tracker->joystick_mappings) {
for (i = 0; tracker->joysticks[i]; ++i) {
/* Looking up the new mapping might create one and associate it with the gamepad (and generate events) */
SDL_JoystickID joystick = tracker->joysticks[i];
SDL_Gamepad *gamepad = SDL_GetGamepadFromInstanceID(joystick);
GamepadMapping_t *new_mapping = SDL_PrivateGetGamepadMapping(joystick);
GamepadMapping_t *old_mapping = gamepad ? gamepad->mapping : tracker->joystick_mappings[i];
if (new_mapping && !old_mapping) {
SDL_PrivateGamepadAdded(joystick);
} else if (old_mapping && !new_mapping) {
SDL_PrivateGamepadRemoved(joystick);
} else if (old_mapping != new_mapping || HasMappingChangeTracking(tracker, new_mapping)) {
if (gamepad) {
SDL_PrivateLoadButtonMapping(gamepad, new_mapping);
}
SDL_PrivateGamepadRemapped(joystick);
}
}
}
SDL_free(tracker->joysticks);
SDL_free(tracker->joystick_mappings);
SDL_free(tracker->changed_mappings);
SDL_free(tracker);
}
#ifdef __ANDROID__
/*
* Helper function to guess at a mapping based on the elements reported for this gamepad
*/
static GamepadMapping_t *SDL_CreateMappingForAndroidGamepad(SDL_JoystickGUID guid)
{
const int face_button_mask = ((1 << SDL_GAMEPAD_BUTTON_A) |
(1 << SDL_GAMEPAD_BUTTON_B) |
(1 << SDL_GAMEPAD_BUTTON_X) |
(1 << SDL_GAMEPAD_BUTTON_Y));
SDL_bool existing;
char mapping_string[1024];
int button_mask;
int axis_mask;
button_mask = SDL_SwapLE16(*(Uint16 *)(&guid.data[sizeof(guid.data) - 4]));
axis_mask = SDL_SwapLE16(*(Uint16 *)(&guid.data[sizeof(guid.data) - 2]));
if (!button_mask && !axis_mask) {
/* Accelerometer, shouldn't have a gamepad mapping */
return NULL;
}
if (!(button_mask & face_button_mask)) {
/* We don't know what buttons or axes are supported, don't make up a mapping */
return NULL;
}
SDL_strlcpy(mapping_string, "none,*,", sizeof(mapping_string));
if (button_mask & (1 << SDL_GAMEPAD_BUTTON_A)) {
SDL_strlcat(mapping_string, "a:b0,", sizeof(mapping_string));
}
if (button_mask & (1 << SDL_GAMEPAD_BUTTON_B)) {
SDL_strlcat(mapping_string, "b:b1,", sizeof(mapping_string));
} else if (button_mask & (1 << SDL_GAMEPAD_BUTTON_BACK)) {
/* Use the back button as "B" for easy UI navigation with TV remotes */
SDL_strlcat(mapping_string, "b:b4,", sizeof(mapping_string));
button_mask &= ~(1 << SDL_GAMEPAD_BUTTON_BACK);
}
if (button_mask & (1 << SDL_GAMEPAD_BUTTON_X)) {
SDL_strlcat(mapping_string, "x:b2,", sizeof(mapping_string));
}
if (button_mask & (1 << SDL_GAMEPAD_BUTTON_Y)) {
SDL_strlcat(mapping_string, "y:b3,", sizeof(mapping_string));
}
if (button_mask & (1 << SDL_GAMEPAD_BUTTON_BACK)) {
SDL_strlcat(mapping_string, "back:b4,", sizeof(mapping_string));
}
if (button_mask & (1 << SDL_GAMEPAD_BUTTON_GUIDE)) {
/* The guide button generally isn't functional (or acts as a home button) on most Android gamepads before Android 11 */
if (SDL_GetAndroidSDKVersion() >= 30 /* Android 11 */) {
SDL_strlcat(mapping_string, "guide:b5,", sizeof(mapping_string));
}
}
if (button_mask & (1 << SDL_GAMEPAD_BUTTON_START)) {
SDL_strlcat(mapping_string, "start:b6,", sizeof(mapping_string));
}
if (button_mask & (1 << SDL_GAMEPAD_BUTTON_LEFT_STICK)) {
SDL_strlcat(mapping_string, "leftstick:b7,", sizeof(mapping_string));
}
if (button_mask & (1 << SDL_GAMEPAD_BUTTON_RIGHT_STICK)) {
SDL_strlcat(mapping_string, "rightstick:b8,", sizeof(mapping_string));
}
if (button_mask & (1 << SDL_GAMEPAD_BUTTON_LEFT_SHOULDER)) {
SDL_strlcat(mapping_string, "leftshoulder:b9,", sizeof(mapping_string));
}
if (button_mask & (1 << SDL_GAMEPAD_BUTTON_RIGHT_SHOULDER)) {
SDL_strlcat(mapping_string, "rightshoulder:b10,", sizeof(mapping_string));
}
if (button_mask & (1 << SDL_GAMEPAD_BUTTON_DPAD_UP)) {
SDL_strlcat(mapping_string, "dpup:b11,", sizeof(mapping_string));
}
if (button_mask & (1 << SDL_GAMEPAD_BUTTON_DPAD_DOWN)) {
SDL_strlcat(mapping_string, "dpdown:b12,", sizeof(mapping_string));
}
if (button_mask & (1 << SDL_GAMEPAD_BUTTON_DPAD_LEFT)) {
SDL_strlcat(mapping_string, "dpleft:b13,", sizeof(mapping_string));
}
if (button_mask & (1 << SDL_GAMEPAD_BUTTON_DPAD_RIGHT)) {
SDL_strlcat(mapping_string, "dpright:b14,", sizeof(mapping_string));
}
if (axis_mask & (1 << SDL_GAMEPAD_AXIS_LEFTX)) {
SDL_strlcat(mapping_string, "leftx:a0,", sizeof(mapping_string));
}
if (axis_mask & (1 << SDL_GAMEPAD_AXIS_LEFTY)) {
SDL_strlcat(mapping_string, "lefty:a1,", sizeof(mapping_string));
}
if (axis_mask & (1 << SDL_GAMEPAD_AXIS_RIGHTX)) {
SDL_strlcat(mapping_string, "rightx:a2,", sizeof(mapping_string));
}
if (axis_mask & (1 << SDL_GAMEPAD_AXIS_RIGHTY)) {
SDL_strlcat(mapping_string, "righty:a3,", sizeof(mapping_string));
}
if (axis_mask & (1 << SDL_GAMEPAD_AXIS_LEFT_TRIGGER)) {
SDL_strlcat(mapping_string, "lefttrigger:a4,", sizeof(mapping_string));
}
if (axis_mask & (1 << SDL_GAMEPAD_AXIS_RIGHT_TRIGGER)) {
SDL_strlcat(mapping_string, "righttrigger:a5,", sizeof(mapping_string));
}
return SDL_PrivateAddMappingForGUID(guid, mapping_string, &existing, SDL_GAMEPAD_MAPPING_PRIORITY_DEFAULT);
}
#endif /* __ANDROID__ */
/*
* Helper function to guess at a mapping for HIDAPI gamepads
*/
static GamepadMapping_t *SDL_CreateMappingForHIDAPIGamepad(SDL_JoystickGUID guid)
{
SDL_bool existing;
char mapping_string[1024];
Uint16 vendor;
Uint16 product;
SDL_strlcpy(mapping_string, "none,*,", sizeof(mapping_string));
SDL_GetJoystickGUIDInfo(guid, &vendor, &product, NULL, NULL);
if ((vendor == USB_VENDOR_NINTENDO && product == USB_PRODUCT_NINTENDO_GAMECUBE_ADAPTER) ||
(vendor == USB_VENDOR_DRAGONRISE && product == USB_PRODUCT_EVORETRO_GAMECUBE_ADAPTER)) {
/* GameCube driver has 12 buttons and 6 axes */
SDL_strlcat(mapping_string, "a:b0,b:b1,dpdown:b6,dpleft:b4,dpright:b5,dpup:b7,lefttrigger:a4,leftx:a0,lefty:a1,rightshoulder:b9,righttrigger:a5,rightx:a2,righty:a3,start:b8,x:b2,y:b3,", sizeof(mapping_string));
} else if (vendor == USB_VENDOR_NINTENDO &&
(guid.data[15] == k_eSwitchDeviceInfoControllerType_HVCLeft ||
guid.data[15] == k_eSwitchDeviceInfoControllerType_HVCRight ||
guid.data[15] == k_eSwitchDeviceInfoControllerType_NESLeft ||
guid.data[15] == k_eSwitchDeviceInfoControllerType_NESRight ||
guid.data[15] == k_eSwitchDeviceInfoControllerType_SNES ||
guid.data[15] == k_eSwitchDeviceInfoControllerType_N64 ||
guid.data[15] == k_eSwitchDeviceInfoControllerType_SEGA_Genesis ||
guid.data[15] == k_eWiiExtensionControllerType_None ||
guid.data[15] == k_eWiiExtensionControllerType_Nunchuk ||
guid.data[15] == k_eSwitchDeviceInfoControllerType_JoyConLeft ||
guid.data[15] == k_eSwitchDeviceInfoControllerType_JoyConRight)) {
switch (guid.data[15]) {
case k_eSwitchDeviceInfoControllerType_HVCLeft:
SDL_strlcat(mapping_string, "a:b0,b:b1,back:b4,dpdown:b12,dpleft:b13,dpright:b14,dpup:b11,leftshoulder:b9,rightshoulder:b10,start:b6,", sizeof(mapping_string));
Squashed 'external/sdl/SDL/' changes from b8d91252c6..ec0042081e ec0042081e Add .gitattributes file a5d9db0cd0 cmake: build tests for UWP b7889a7389 winrt: use windowsio in non-libc mode ea8757a748 Make testaudiostreamdynamicresample compatible with emscripten 1a7a74fb2e cmake: build emscripten tests as html page 64d570f027 Add minimal http server for emscripten test apps 8e898c4a21 SDL_test does not parse --samples argument 91cd5478be audio: Fix resampler overflowing input buffer. f290c85b22 testaudiocapture: Make sure we convert captured audio to output format. b75c751dfc rwlock: Make generic implmentations work on single-threaded platforms. 80850af7ce The controller update complete events are no longer disabled by default 3f486224a9 Fixed refresh rate calculation for KMSDRM 342ec51131 Fix overflow when doing SDL_sscanf("%hd", ...) 9129e1d557 Fixed crash when setting the default cursor twice 8e99a4f4f5 Undo variable rename be67f0de10 Fixed crashes related to the default cursor on WinRT and KMSDRM 94b3f78c44 Fix out of bound read of 'has_hat' array 94f48f19b0 Use more specific build destinations when creating an xcframework dabd45997e Back out change supporting multiple names for binding elements efe15588d5 Relabel back paddles as left or right be884f0c95 ci: disable visionos.yml by renaming the file ac094d00f5 ci: add workflow_dispatch event to visionos workflow 9be9e2292b build: Consistently use pathlib APIs in cmake/xxd.py a9f6950657 Fixed deadlock shutting down Android sensors d9f09e77f2 Actually make the sensors magical! 690eae7d22 Implement visionOS support e385d6da0a Fixed build warning 6b93e788fa Improved sensor thread-safety 4ee0e5a984 Fixed thread-safety warnings 12deed91f8 Added information on how to enable thread-safety analysis 5735d2b03b coreaudio: Fixed assertion when device fails/quits mid-iteration. 1022fd6e04 testaudio: the test framework opens an audio device at startup; close it. 0714da37a4 audio: Fix audio stream callback calculations when future buffer has space. 917e036f6f MSVC has __declspec(deprecated) 279ff8909f Changed example code to avoid potential divide by zero 8a1afc9b10 Fixed Android not sending controller event timestamps 463c456b98 Fill the correct member with the joystick ID in SDL_EVENT_JOYSTICK_UPDATE_COMPLETE 55cf1abaa6 test: Don't flag testsurround as suitable for non-interactive use a2d594269c Fixed pixel format compatibility with SDL2 79a190aa23 Fixed setting invalid bpp for FOURCC formats in SDL_GetMasksForPixelFormatEnum() 8fdebdd3e0 Sync SDL3 wiki -> header b903ccf945 SDL_rwops read/write functions return size_t again c03f5b4b69 Fixed rounding up in SDL_PrintFloat 75a020aa6b Only query serial number and firmware versions from Sony PS5 controllers fa189d302e Added the Victrix Pro FS for PS4/PS5 to the controller list 26205b659d Fixed PS4/PS5 touchpad for third party controllers 6af0448af9 include: fixed a typo in SDL_RenderGetMetalCommandEncoder docs. f3cb46b083 SDL_thread.h: do not conflict with sdl2-compat::sdl3_include_wrapper.h 080b1dfbdb Revert "Improved fallback for SDL_COMPILE_TIME_ASSERT() (thanks @icculus!)" 9d453daa23 Improved fallback for SDL_COMPILE_TIME_ASSERT() (thanks @icculus!) 1fb2419882 Removed reference to renamed function e7d56dd0b2 audio: Renamed new API SDL_UnpauseAudioDevice to SDL_ResumeAudioDevice. 2b0c0f5b6b Don't pass NULL to strncmp 778e8185cd Fix size of memcpy in SDL_AudioDeviceFormatChangedAlreadyLocked And add diagnostic that allows to find this kind of issue in clang-tidy 4bb426abad Sync SDL3 wiki -> header 3a752ce650 Reapply "Changed 'freesrc' parameter from int to SDL_bool" to SDL_wave.c 2ba03b4db0 fix build after previous commit. 0026adffd4 apply force_align_arg_pointer attribute to correct version of SDL_RunApp 77446e2029 Unaligned stacks on i686-w64-mingw32 may lead to crashes d3bcc3f057 Fixed build errors when OpenGL isn't enabled 35ad68e126 Sync SDL3 wiki -> header 70323a8350 Add a function to display the system menu for a window be5f66c84e testaudio: Fixed soundboard icon, which had a colorkey issue. c0a88930bf Sync SDL3 wiki -> header 18c59cc969 Merge the SDL3 audio subsystem redesign! 99b0e31788 The Steam Controller D-Pad is only pressed when the button is pressed down 103073d694 Set NSBluetoothAlwaysUsageDescription for testcontroller ca02bb6c8c We don't need testdropfile-Info.plist e063f662e9 Enable the controller update complete events 06bea1eb55 Added a gamepad mapping for the G-Shark GS-GP702 5ca3c50bf0 testaudio: Fix compiler warning. 1b1f02c5aa testaudio: Apparently compilers don't like this possibly being NULL now...? 2de9253b6c test: Added testaudio fb3ab3f113 SDL_video.c: move ngage video before offscreen. 843572d993 Don't mark autorelease keys as virtual 648de4f9b8 Fixed duplicate key press/release events on iOS a8abe612ed Only pass keypresses up the responder chain when text input is active c3288d113e Synchronize on-screen keyboard state with text input active state 5fb92ef2f7 Fixed whitespace f5ea6ae18d Revert "Stop beep when running iOS apps on ARM-based Macs" 546508b9b4 Allow test programs to run at full resolution on iPads 68a4bb01e0 Allocate displays as an array of pointers instead of an array of objects 07578fde3d Fixed crash if a display is enumerated twice a509771a87 fix ios CI workflow after commit e4460e897f 72ce76905a The scheme isn't always the same as the framework name (e.g. xmp_lite vs xmp-lite) e4460e897f By default Xcode expects the framework target name to be the name of the project. ac683773dc Added missing tests to the "All" target 7dd56eaafe Removed unnecessary reference to testoverlay-Info.plist e1c7f524ef Reduce the number of times SDL3 is duplicated in the xcframework script 65538011ca Make Xcode targets more specific efe114c300 Revert "Renamed the xcframework target from "SDL.xcframework" to "xcframework"" 73ed1d21a9 Renamed the xcframework target from "SDL.xcframework" to "xcframework" 76b4d8a0d8 Build the Framework instead of a static library for iOS and tvOS d1bf979160 Removed unnecessary setting from the "Create DMG" target c94cb3a5d8 Simplified the Xcode project to a single Framework target ea60474c65 cmake: don't build SDL3-static Apple framework 8f00d7856d Sync SDL3 wiki -> header d4a867a256 Rename SDL_GetPath to SDL_GetUserFolder 71099149b8 Fall back to Xlib if XRandR isn't available b7f32f74ce Note the removal of the SDL_RENDERER_TARGETTEXTURE flag 0eda582160 testaudiostreamdynamicresample: Load sample.wav correctly. 87eae9a0a1 aaudio: We need a mixbuf on capture devices, too. fb68e84646 wayland: Fix memory leaks b0edd23c00 testsurround: Log available audio output devices at the start. ae3090c387 androidaudio: Move Init/bootstrap code to bottom of source code. 18fc0db9e5 aaudio: Rearranged source code to match other backends. 2507c1d68b aaudio: Disconnect playing devices if error callback fires. 32a3fc3783 aaudio: Use the callback interface. b49ce86765 audio: Fixed compiler warning on Android NDK. 1c074e8d97 android: Fixed audio device detection. 82ce05ad01 pulseaudio: Be more aggressive with hotplug thread synchronization. 5cbdf1168e androidaudio: Fixed incorrect JNI call (thanks, @madebr!) 660054f3dc include: Correct comment about audio device hotplug events. ab68428a64 aaudio: Fixed for older SDKs and Android releases. 5ff87c6d4a android: Reworked audio backends for SDL3 audio API. 54af687210 testautomation_audio.c: Patched to compile. :/ 5e82090662 testautomation_audio.c: Apparently we aren't updating test code for C99 atm. 7f4488f625 wasapi: More fixes for Clang warnings. 29a0c689c9 wasapi: Patched to compile with Clang. 4aa95c21bc pspaudio: Patched to compile. 9a2a0a1463 ps2audio: Delete errant character that got inserted before previous commit. 2c578bd0d5 qnxaudio: Rewrite for SDL3 audio APIs. 455eef4cd9 audio: Use AtomicAdd for device counts, don't treat as a refcount. 095ea57f94 pspaudio: Patched to compile. d7cf63db67 ps2audio: Patched to compile. 027b9e8787 coreaudio: (maybe) patched to compile on iOS. 4836c2db07 pspaudio: Patched to compile. 86ca412436 n3dsaudio: Patched to compile. 66bcee2ca9 testaudiostreamdynamicresample.c: Fixed MSVC compiler warning. dbf993d358 vitaaudio: patched to compile. 5707e14716 audio: Fix up some things that broke when rebasing the branch against main. 6567285eae SDL_migration.cocci: Fix up SDL_(Pause|Unpause)Audio. 0b6255551e test: Fixed incorrect SDL_OpenAudioDevice call in testautomation. 107fd941cd vitaaudio: Clean up correctly in CloseDevice. 9fa4a6ef87 netbsdaudio: Minor fix. b0d89868c6 n3dsaudio: Updated (but untested!) for SDL3 audio API. ba27176106 vitaaudio: Untested attempt to move Vita audio to SDL3's audio API. 0b58e96d9e wasapi: Patched WinRT to compile. d6b4f48488 visualc: Turn on multiprocessor compilation. c58d95c343 wasapi: Reworked for new SDL3 audio API, other win32 fixes. dc04f85646 audio: whoops, that should be an int. be0dc630b7 audio: Fixed incorrect assertion 77b3fb06ee directsound: First shot at updating for SDL3 audio API. 4399b71715 audio: Generalize how backends can lookup an SDL_AudioDevice. 2fb122fe46 audio: backends now "find" instead of "obtain" devices by handle. c3f5a5fc72 dummyaudio: SDL3ify style 7d65ff86e2 diskaudio: Adjusted for later SDL3 audio API redesign changes. 4ba9c2eade dummyaudio: Configurable delay, other SDL3 API fixes. fb395d3ad7 sndio: Updated to the SDL3 audio API. 1a55282051 dsp: Some minor logic fixes 6bc85577d7 netbsdaudio: Updated for SDL3 audio API. 0f6e59312b netbsdaudio: Removed email address from source code. 51ae78c0af haikuaudio: Updated for SDL3 audio API. fc7ed18ca1 emscriptenaudio: don't forget to finalize the audio thread 4233c41ce2 pulseaudio: Removed unnecessary variable. a0528cd5ed emscriptenaudio: Updated for SDL3 audio API. 79cc29ba35 wave: Don't check if format->channels > INT_MAX, it's a Uint16. 1bfe97c235 pspaudio: Updated for SDL3 audio API. 121a2dce15 audio: Make sure `device->hidden` is NULL after CloseDevice 3d6ba0cafd ps2audio: Removed free of buffer that hasn't been allocated yet. 00ed6f8827 test: Fixed compiler warnings for unused vars. 6f12f68ec9 ps2audio: SDL3ified the style 4993743a02 ps2audio: Renamed `_this` to `device` 74568cdb2b ps2audio: Updated (but untested) for SDL3 audio API. c83b68ef26 jack: renamed `_this` to `device`. 3f4f004794 audio: Remove an assertion that no longer makes sense. 86243b2589 jack: Use ProvidesOwnCallbackThread. 18906a32b8 jack: First shot at updating for SDL3 audio API. a2b488359e dsp: Removed debug logging 6fd71185cd dsp: Updated for new SDL3 audio API. 3482d1215a alsa: Don't ever block in CaptureFromDevice. 65d296ef1a audio: Use SDL_powerof2 instead of reinventing it. 409b544505 alsa: Updated for new SDL3 audio API 0999a090a7 audio: More tweaking of `device->thread_alive` f94ffd6092 audio: Fixed logic error 4deb2970c9 alsa: Renamed `_this` to `device` 0fb9e4baae audio: Remove no-longer-used SupportsNonPow2Samples c653e57768 coreaudio: rewritten for SDL3 audio redesign! 533777eff5 audio: SDL_sysaudio.h comment conversion. 8473e522e0 audio: unify device thread naming. 258bc9efed audio: PlayDevice now passes the buffer, too, for convenience. e518149d14 audio: Fixed locking in SDL_AudioDeviceDisconnected 22afa5735f audio: FreeDeviceHandle should pass the whole device, for convenience. 9e3c5f93e0 coreaudio: Change `_this` to `device` e969160de0 audio: unset a freed variable to NULL 1fc01b0300 audio: Try to definitely have a default device set up. b60a56d368 audio: take first reported device if no default was specified. a8323ebe68 audio: Better handling of ProvidesOwnCallbackThread backends. 1dffb72c1d pipewire: Hooked up default device change notifications. a93fcf2444 audio: fixed flushed stream reporting bytes but not being able to get them. ad6c1781fc pulseaudio: Minor cleanups. cfc8a0d17d pipewire: First shot at moving to the new SDL3 audio interfaces. 13202642a3 aaudio: Fixed capitialization, plus some minor cleanups. 3e9991b535 audio: Make sure we don't write to a NULL pointer. 943351affb pulseaudio: GetDefaultAudioInfo isn't a thing anymore. 11dfc4d737 test: Update testautomation_audio for SDL3 audio API. 29afc2e42b test: Update testresample for SDL3 audio API. 3a02eecced test: Update testsurround for SDL3 audio API. e1c78718d4 test: testaudiocapture is updated for the SDL3 audio API. f48cb716c2 pulseaudio: a couple minor tweaks. dac25fe9eb audio: Seperate audio capture into Wait/Read operations. 3e10c0005d audio: Capture devices should respect logical device pausing. 7e700531c5 audio: Allow SDL_OpenAudioDevice to accept a NULL spec. bb1cbbd33a test: Update testaudioinfo for SDL3 audio API. 883aee32c5 audio: Let default formats differ for output and capture devices. 62cf24eeb9 pulseaudio: Listen for server events in addition to sources and sinks. 924f370bd7 pulseaudio: Fix deadlock in HotplugThread. 5d4e9e5f80 test: Updated testaudiostreamdynamicresample to SDL3 audio API. f883b9fc64 test: Updated testaudiohotplug to SDL3 audio API. 2be5f726d4 audio: Removed debug logging. 323ecce123 docs: Added migration note about SDL_AUDIODEVICEREMOVED. 47b0321ebf test: Removed loopwavequeue.c; obsolete in SDL3. 0e5a1d4f29 pulseaudio: Removed debug logging. f598626e46 test: loopwave shouldn't use an audiostream callback. eee407caf8 docs: migration guide note that SDL_LoadWAV has a different return type. b03c493fc4 test: Updated testmultiaudio to new SDL3 audio API fe1daf6fb5 audio: Mark disconnected default devices as "zombies". cdd2ba81de audio: Fixed adding new physical devices to a double-linked list. db39cbf208 audio: Allow SDL_GetAudioDeviceFormat() to query the default devices. ee10bab3cd audio: An enormous amount of work on managing default devices. c7a44eea83 audio: Fixed logic error. 089cd87cb5 audio: Make sure device count stays correct as hardware disconnects. e50cb72eb6 docs: Note that audio opening doesn't implicitly init SDL now. 97b2f747d0 docs: Corrections to audio section of README-migration.md 464640440f audio: Added SDL_GetAudioStreamBinding. 01f7b53865 audio: Readded (logical) device pausing. fd4c9f4e11 audio: documentation improvements. 4b78b789a7 audio: Switch SDL_audio.c and SDL_audiocvt.c to C99-ish syntax. d96a1db7d7 audio: Opening via a logical device ID should also track default device. b2e020958f audio: Wrap device access in opening of logical devices. 7ee2459927 audio: Check for unlikely failure case in WAV loaded. 3d65a2cefe audio: Made SDL_LoadWAV a real function, not just a macro. 26525f5fd3 audio: Readd SDL_AudioSpec, but just with format/channels/freq fields. e6aaed7d79 include: Audio is not, and has not been, a raw mixing buffer for a long time. 56b1bc2198 audio: SDL_AudioStream now has callbacks for Get and Put operations. 905c4fff5b audio: First shot at the SDL3 audio subsystem redesign! b221b59995 cmake: add SDL_REVISION option 0500fca00c Add missing break d3f2de7f29 fixed typo in prev. patch. 12b35c6a46 test/testnativecocoa.m: fixed deprecation warnings. e24b3e2fa4 cmake: rename SDL_TEST -> SDL_TEST_LIBRARY da5016d336 cmake: use pkg-config + test compile instead of Find module for detecting rpi deec574ff6 cmake: fix SDL_HIDAPI_LIBUSB f2ae00c1ad Sync SDL3 wiki -> header 41a96c8133 doc: document building of SDL tests with CMake 3174d0b970 Sorted controller list 27b8abb056 Add Steam Deck controller mapping to database. 41d436f0fe Use SetWindowPos to show windows when SDL_HINT_WINDOW_ACTIVATE_WHEN_SHOWN is set to avoid activating the parent window when showing a child window 0dc85f3078 Improved the documentation for the gamepad paddle buttons 2fff999a41 Try to create the dummy mouse cursor after video backend initialization d086d9874d Sync SDL3 wiki -> header bce598addd SDL_pixels.c: Fixed compiler warning on Android NDK. ad0c0d3cde Sync SDL3 wiki -> header f8e8dff7ee tests: Fix automated window grab and positioning tests under Wayland/XWayland 4cffbc3644 Add VS code directory to gitignore 666f81bace Add more endian-specific aliases for 32 bit pixelformats 4749df0a63 Just disable the 4214 warning instead of trying to change the structure definition git-subtree-dir: external/sdl/SDL git-subtree-split: ec0042081ea104d5dd0ee291105210e00a4fe3d9
2023-08-12 20:17:29 +02:00
break;
case k_eSwitchDeviceInfoControllerType_HVCRight:
SDL_strlcat(mapping_string, "a:b0,b:b1,dpdown:b12,dpleft:b13,dpright:b14,dpup:b11,leftshoulder:b9,rightshoulder:b10,", sizeof(mapping_string));
break;
case k_eSwitchDeviceInfoControllerType_NESLeft:
case k_eSwitchDeviceInfoControllerType_NESRight:
SDL_strlcat(mapping_string, "a:b0,b:b1,back:b4,dpdown:b12,dpleft:b13,dpright:b14,dpup:b11,leftshoulder:b9,rightshoulder:b10,start:b6,", sizeof(mapping_string));
break;
case k_eSwitchDeviceInfoControllerType_SNES:
SDL_strlcat(mapping_string, "a:b0,b:b1,back:b4,dpdown:b12,dpleft:b13,dpright:b14,dpup:b11,leftshoulder:b9,lefttrigger:a4,rightshoulder:b10,righttrigger:a5,start:b6,x:b2,y:b3,", sizeof(mapping_string));
break;
case k_eSwitchDeviceInfoControllerType_N64:
SDL_strlcat(mapping_string, "a:b0,b:b1,back:b4,dpdown:b12,dpleft:b13,dpright:b14,dpup:b11,guide:b5,leftshoulder:b9,leftstick:b7,lefttrigger:a4,leftx:a0,lefty:a1,rightshoulder:b10,righttrigger:a5,start:b6,x:b2,y:b3,misc1:b15,", sizeof(mapping_string));
break;
case k_eSwitchDeviceInfoControllerType_SEGA_Genesis:
SDL_strlcat(mapping_string, "a:b0,b:b1,dpdown:b12,dpleft:b13,dpright:b14,dpup:b11,guide:b5,rightshoulder:b10,righttrigger:a5,start:b6,misc1:b15,", sizeof(mapping_string));
break;
case k_eWiiExtensionControllerType_None:
SDL_strlcat(mapping_string, "a:b0,b:b1,back:b4,dpdown:b12,dpleft:b13,dpright:b14,dpup:b11,guide:b5,start:b6,x:b2,y:b3,", sizeof(mapping_string));
break;
case k_eWiiExtensionControllerType_Nunchuk:
{
/* FIXME: Should we map this to the left or right side? */
const SDL_bool map_nunchuck_left_side = SDL_TRUE;
if (map_nunchuck_left_side) {
SDL_strlcat(mapping_string, "a:b0,b:b1,back:b4,dpdown:b12,dpleft:b13,dpright:b14,dpup:b11,guide:b5,leftshoulder:b9,lefttrigger:a4,leftx:a0,lefty:a1,start:b6,x:b2,y:b3,", sizeof(mapping_string));
} else {
SDL_strlcat(mapping_string, "a:b0,b:b1,back:b4,dpdown:b12,dpleft:b13,dpright:b14,dpup:b11,guide:b5,rightshoulder:b9,righttrigger:a4,rightx:a0,righty:a1,start:b6,x:b2,y:b3,", sizeof(mapping_string));
}
} break;
default:
if (SDL_GetHintBoolean(SDL_HINT_JOYSTICK_HIDAPI_VERTICAL_JOY_CONS, SDL_FALSE)) {
/* Vertical mode */
if (guid.data[15] == k_eSwitchDeviceInfoControllerType_JoyConLeft) {
SDL_strlcat(mapping_string, "back:b4,dpdown:b12,dpleft:b13,dpright:b14,dpup:b11,leftshoulder:b9,leftstick:b7,lefttrigger:a4,leftx:a0,lefty:a1,misc1:b15,paddle2:b17,paddle4:b19,", sizeof(mapping_string));
} else {
SDL_strlcat(mapping_string, "a:b0,b:b1,guide:b5,rightshoulder:b10,rightstick:b8,righttrigger:a5,rightx:a2,righty:a3,start:b6,x:b2,y:b3,paddle1:b16,paddle3:b18,", sizeof(mapping_string));
}
} else {
/* Mini gamepad mode */
if (guid.data[15] == k_eSwitchDeviceInfoControllerType_JoyConLeft) {
SDL_strlcat(mapping_string, "a:b0,b:b1,guide:b5,leftshoulder:b9,leftstick:b7,leftx:a0,lefty:a1,rightshoulder:b10,start:b6,x:b2,y:b3,paddle2:b17,paddle4:b19,", sizeof(mapping_string));
} else {
SDL_strlcat(mapping_string, "a:b0,b:b1,guide:b5,leftshoulder:b9,leftstick:b7,leftx:a0,lefty:a1,rightshoulder:b10,start:b6,x:b2,y:b3,paddle1:b16,paddle3:b18,", sizeof(mapping_string));
}
}
break;
}
} else {
/* All other gamepads have the standard set of 19 buttons and 6 axes */
SDL_strlcat(mapping_string, "a:b0,b:b1,back:b4,dpdown:b12,dpleft:b13,dpright:b14,dpup:b11,guide:b5,leftshoulder:b9,leftstick:b7,lefttrigger:a4,leftx:a0,lefty:a1,rightshoulder:b10,rightstick:b8,righttrigger:a5,rightx:a2,righty:a3,start:b6,x:b2,y:b3,", sizeof(mapping_string));
if (SDL_IsJoystickXboxSeriesX(vendor, product)) {
/* XBox Series X Controllers have a share button under the guide button */
SDL_strlcat(mapping_string, "misc1:b15,", sizeof(mapping_string));
} else if (SDL_IsJoystickXboxOneElite(vendor, product)) {
/* XBox One Elite Controllers have 4 back paddle buttons */
SDL_strlcat(mapping_string, "paddle1:b15,paddle2:b17,paddle3:b16,paddle4:b18,", sizeof(mapping_string));
} else if (SDL_IsJoystickSteamController(vendor, product)) {
/* Steam controllers have 2 back paddle buttons */
SDL_strlcat(mapping_string, "paddle1:b16,paddle2:b15,", sizeof(mapping_string));
} else if (SDL_IsJoystickNintendoSwitchJoyConPair(vendor, product)) {
/* The Nintendo Switch Joy-Con combined controllers has a share button and paddles */
SDL_strlcat(mapping_string, "misc1:b15,paddle1:b16,paddle2:b17,paddle3:b18,paddle4:b19,", sizeof(mapping_string));
} else if (SDL_IsJoystickAmazonLunaController(vendor, product)) {
/* Amazon Luna Controller has a mic button under the guide button */
SDL_strlcat(mapping_string, "misc1:b15,", sizeof(mapping_string));
} else if (SDL_IsJoystickGoogleStadiaController(vendor, product)) {
/* The Google Stadia controller has a share button and a Google Assistant button */
SDL_strlcat(mapping_string, "misc1:b15,", sizeof(mapping_string));
} else if (SDL_IsJoystickNVIDIASHIELDController(vendor, product)) {
/* The NVIDIA SHIELD controller has a share button between back and start buttons */
SDL_strlcat(mapping_string, "misc1:b15,", sizeof(mapping_string));
if (product == USB_PRODUCT_NVIDIA_SHIELD_CONTROLLER_V103) {
/* The original SHIELD controller has a touchpad as well */
SDL_strlcat(mapping_string, "touchpad:b16,", sizeof(mapping_string));
}
} else {
switch (SDL_GetGamepadTypeFromGUID(guid, NULL)) {
case SDL_GAMEPAD_TYPE_PS4:
/* PS4 controllers have an additional touchpad button */
SDL_strlcat(mapping_string, "touchpad:b15,", sizeof(mapping_string));
break;
case SDL_GAMEPAD_TYPE_PS5:
/* PS5 controllers have a microphone button and an additional touchpad button */
SDL_strlcat(mapping_string, "touchpad:b15,misc1:b16,", sizeof(mapping_string));
/* DualSense Edge controllers have paddles */
if (SDL_IsJoystickDualSenseEdge(vendor, product)) {
SDL_strlcat(mapping_string, "paddle1:b20,paddle2:b19,paddle3:b18,paddle4:b17,", sizeof(mapping_string));
}
break;
case SDL_GAMEPAD_TYPE_NINTENDO_SWITCH_PRO:
/* Nintendo Switch Pro controllers have a screenshot button */
SDL_strlcat(mapping_string, "misc1:b15,", sizeof(mapping_string));
break;
default:
if (vendor == 0 && product == 0) {
/* This is a Bluetooth Nintendo Switch Pro controller */
SDL_strlcat(mapping_string, "misc1:b15,", sizeof(mapping_string));
}
break;
}
}
}
return SDL_PrivateAddMappingForGUID(guid, mapping_string, &existing, SDL_GAMEPAD_MAPPING_PRIORITY_DEFAULT);
}
/*
* Helper function to guess at a mapping for RAWINPUT gamepads
*/
static GamepadMapping_t *SDL_CreateMappingForRAWINPUTGamepad(SDL_JoystickGUID guid)
{
SDL_bool existing;
char mapping_string[1024];
SDL_strlcpy(mapping_string, "none,*,", sizeof(mapping_string));
SDL_strlcat(mapping_string, "a:b0,b:b1,x:b2,y:b3,back:b6,guide:b10,start:b7,leftstick:b8,rightstick:b9,leftshoulder:b4,rightshoulder:b5,dpup:h0.1,dpdown:h0.4,dpleft:h0.8,dpright:h0.2,leftx:a0,lefty:a1,rightx:a2,righty:a3,lefttrigger:a4,righttrigger:a5,", sizeof(mapping_string));
return SDL_PrivateAddMappingForGUID(guid, mapping_string, &existing, SDL_GAMEPAD_MAPPING_PRIORITY_DEFAULT);
}
/*
* Helper function to guess at a mapping for WGI gamepads
*/
static GamepadMapping_t *SDL_CreateMappingForWGIGamepad(SDL_JoystickGUID guid)
{
SDL_bool existing;
char mapping_string[1024];
if (guid.data[15] != SDL_JOYSTICK_TYPE_GAMEPAD) {
return NULL;
}
SDL_strlcpy(mapping_string, "none,*,", sizeof(mapping_string));
SDL_strlcat(mapping_string, "a:b0,b:b1,x:b2,y:b3,back:b6,start:b7,leftstick:b8,rightstick:b9,leftshoulder:b4,rightshoulder:b5,dpup:b10,dpdown:b12,dpleft:b13,dpright:b11,leftx:a1,lefty:a0~,rightx:a3,righty:a2~,lefttrigger:a4,righttrigger:a5,", sizeof(mapping_string));
return SDL_PrivateAddMappingForGUID(guid, mapping_string, &existing, SDL_GAMEPAD_MAPPING_PRIORITY_DEFAULT);
}
/*
* Helper function to scan the mappings database for a gamepad with the specified GUID
*/
static GamepadMapping_t *SDL_PrivateMatchGamepadMappingForGUID(SDL_JoystickGUID guid, SDL_bool match_crc, SDL_bool match_version)
{
GamepadMapping_t *mapping;
Uint16 crc = 0;
SDL_AssertJoysticksLocked();
if (match_crc) {
SDL_GetJoystickGUIDInfo(guid, NULL, NULL, NULL, &crc);
}
/* Clear the CRC from the GUID for matching, the mappings never include it in the GUID */
SDL_SetJoystickGUIDCRC(&guid, 0);
if (!match_version) {
SDL_SetJoystickGUIDVersion(&guid, 0);
}
for (mapping = s_pSupportedGamepads; mapping; mapping = mapping->next) {
SDL_JoystickGUID mapping_guid;
if (SDL_memcmp(&mapping->guid, &s_zeroGUID, sizeof(mapping->guid)) == 0) {
continue;
}
SDL_memcpy(&mapping_guid, &mapping->guid, sizeof(mapping_guid));
if (!match_version) {
SDL_SetJoystickGUIDVersion(&mapping_guid, 0);
}
if (SDL_memcmp(&guid, &mapping_guid, sizeof(guid)) == 0) {
Uint16 mapping_crc = 0;
if (match_crc) {
const char *crc_string = SDL_strstr(mapping->mapping, SDL_GAMEPAD_CRC_FIELD);
if (crc_string) {
mapping_crc = (Uint16)SDL_strtol(crc_string + SDL_GAMEPAD_CRC_FIELD_SIZE, NULL, 16);
}
}
if (crc == mapping_crc) {
return mapping;
}
}
}
return NULL;
}
/*
* Helper function to scan the mappings database for a gamepad with the specified GUID
*/
static GamepadMapping_t *SDL_PrivateGetGamepadMappingForGUID(SDL_JoystickGUID guid, SDL_bool adding_mapping)
{
GamepadMapping_t *mapping;
Uint16 vendor, product, crc;
SDL_GetJoystickGUIDInfo(guid, &vendor, &product, NULL, &crc);
if (crc) {
/* First check for exact CRC matching */
mapping = SDL_PrivateMatchGamepadMappingForGUID(guid, SDL_TRUE, SDL_TRUE);
if (mapping) {
return mapping;
}
}
/* Now check for a mapping without CRC */
mapping = SDL_PrivateMatchGamepadMappingForGUID(guid, SDL_FALSE, SDL_TRUE);
if (mapping) {
return mapping;
}
if (adding_mapping) {
/* We didn't find an existing mapping */
return NULL;
}
/* Try harder to get the best match, or create a mapping */
if (vendor && product) {
/* Try again, ignoring the version */
if (crc) {
mapping = SDL_PrivateMatchGamepadMappingForGUID(guid, SDL_TRUE, SDL_FALSE);
if (mapping) {
return mapping;
}
}
mapping = SDL_PrivateMatchGamepadMappingForGUID(guid, SDL_FALSE, SDL_FALSE);
if (mapping) {
return mapping;
}
}
#ifdef SDL_JOYSTICK_XINPUT
if (SDL_IsJoystickXInput(guid)) {
/* This is an XInput device */
return s_pXInputMapping;
}
#endif
if (SDL_IsJoystickHIDAPI(guid)) {
mapping = SDL_CreateMappingForHIDAPIGamepad(guid);
} else if (SDL_IsJoystickRAWINPUT(guid)) {
mapping = SDL_CreateMappingForRAWINPUTGamepad(guid);
} else if (SDL_IsJoystickWGI(guid)) {
mapping = SDL_CreateMappingForWGIGamepad(guid);
} else if (SDL_IsJoystickVIRTUAL(guid)) {
/* We'll pick up a robust mapping in VIRTUAL_JoystickGetGamepadMapping */
#ifdef __ANDROID__
} else {
mapping = SDL_CreateMappingForAndroidGamepad(guid);
#endif
}
return mapping;
}
static const char *map_StringForGamepadType[] = {
"unknown",
"standard",
"xbox360",
"xboxone",
"ps3",
"ps4",
"ps5",
"switchpro",
"joyconleft",
"joyconright",
"joyconpair"
};
SDL_COMPILE_TIME_ASSERT(map_StringForGamepadType, SDL_arraysize(map_StringForGamepadType) == SDL_GAMEPAD_TYPE_MAX);
/*
* convert a string to its enum equivalent
*/
SDL_GamepadType SDL_GetGamepadTypeFromString(const char *str)
{
int i;
if (str == NULL || str[0] == '\0') {
return SDL_GAMEPAD_TYPE_UNKNOWN;
}
if (*str == '+' || *str == '-') {
++str;
}
for (i = 0; i < SDL_arraysize(map_StringForGamepadType); ++i) {
if (SDL_strcasecmp(str, map_StringForGamepadType[i]) == 0) {
return (SDL_GamepadType)i;
}
}
return SDL_GAMEPAD_TYPE_UNKNOWN;
}
/*
* convert an enum to its string equivalent
*/
const char *SDL_GetGamepadStringForType(SDL_GamepadType type)
{
if (type >= SDL_GAMEPAD_TYPE_STANDARD && type < SDL_GAMEPAD_TYPE_MAX) {
return map_StringForGamepadType[type];
}
return NULL;
}
static const char *map_StringForGamepadAxis[] = {
"leftx",
"lefty",
"rightx",
"righty",
"lefttrigger",
"righttrigger"
};
SDL_COMPILE_TIME_ASSERT(map_StringForGamepadAxis, SDL_arraysize(map_StringForGamepadAxis) == SDL_GAMEPAD_AXIS_MAX);
/*
* convert a string to its enum equivalent
*/
SDL_GamepadAxis SDL_GetGamepadAxisFromString(const char *str)
{
int i;
if (str == NULL || str[0] == '\0') {
return SDL_GAMEPAD_AXIS_INVALID;
}
if (*str == '+' || *str == '-') {
++str;
}
for (i = 0; i < SDL_arraysize(map_StringForGamepadAxis); ++i) {
if (SDL_strcasecmp(str, map_StringForGamepadAxis[i]) == 0) {
return (SDL_GamepadAxis)i;
}
}
return SDL_GAMEPAD_AXIS_INVALID;
}
/*
* convert an enum to its string equivalent
*/
const char *SDL_GetGamepadStringForAxis(SDL_GamepadAxis axis)
{
if (axis > SDL_GAMEPAD_AXIS_INVALID && axis < SDL_GAMEPAD_AXIS_MAX) {
return map_StringForGamepadAxis[axis];
}
return NULL;
}
static const char *map_StringForGamepadButton[] = {
"a",
"b",
"x",
"y",
"back",
"guide",
"start",
"leftstick",
"rightstick",
"leftshoulder",
"rightshoulder",
"dpup",
"dpdown",
"dpleft",
"dpright",
"misc1",
"paddle1",
"paddle2",
"paddle3",
"paddle4",
"touchpad"
};
SDL_COMPILE_TIME_ASSERT(map_StringForGamepadButton, SDL_arraysize(map_StringForGamepadButton) == SDL_GAMEPAD_BUTTON_MAX);
/*
* convert a string to its enum equivalent
*/
SDL_GamepadButton SDL_GetGamepadButtonFromString(const char *str)
{
int i;
if (str == NULL || str[0] == '\0') {
return SDL_GAMEPAD_BUTTON_INVALID;
}
for (i = 0; i < SDL_arraysize(map_StringForGamepadButton); ++i) {
if (SDL_strcasecmp(str, map_StringForGamepadButton[i]) == 0) {
return (SDL_GamepadButton)i;
}
}
return SDL_GAMEPAD_BUTTON_INVALID;
}
/*
* convert an enum to its string equivalent
*/
const char *SDL_GetGamepadStringForButton(SDL_GamepadButton button)
{
if (button > SDL_GAMEPAD_BUTTON_INVALID && button < SDL_GAMEPAD_BUTTON_MAX) {
return map_StringForGamepadButton[button];
}
return NULL;
}
/*
* given a gamepad button name and a joystick name update our mapping structure with it
*/
static int SDL_PrivateParseGamepadElement(SDL_Gamepad *gamepad, const char *szGameButton, const char *szJoystickButton)
{
SDL_GamepadBinding bind;
SDL_GamepadButton button;
SDL_GamepadAxis axis;
SDL_bool invert_input = SDL_FALSE;
char half_axis_input = 0;
char half_axis_output = 0;
SDL_AssertJoysticksLocked();
if (*szGameButton == '+' || *szGameButton == '-') {
half_axis_output = *szGameButton++;
}
axis = SDL_GetGamepadAxisFromString(szGameButton);
button = SDL_GetGamepadButtonFromString(szGameButton);
if (axis != SDL_GAMEPAD_AXIS_INVALID) {
bind.outputType = SDL_GAMEPAD_BINDTYPE_AXIS;
bind.output.axis.axis = axis;
if (axis == SDL_GAMEPAD_AXIS_LEFT_TRIGGER || axis == SDL_GAMEPAD_AXIS_RIGHT_TRIGGER) {
bind.output.axis.axis_min = 0;
bind.output.axis.axis_max = SDL_JOYSTICK_AXIS_MAX;
} else {
if (half_axis_output == '+') {
bind.output.axis.axis_min = 0;
bind.output.axis.axis_max = SDL_JOYSTICK_AXIS_MAX;
} else if (half_axis_output == '-') {
bind.output.axis.axis_min = 0;
bind.output.axis.axis_max = SDL_JOYSTICK_AXIS_MIN;
} else {
bind.output.axis.axis_min = SDL_JOYSTICK_AXIS_MIN;
bind.output.axis.axis_max = SDL_JOYSTICK_AXIS_MAX;
}
}
} else if (button != SDL_GAMEPAD_BUTTON_INVALID) {
bind.outputType = SDL_GAMEPAD_BINDTYPE_BUTTON;
bind.output.button = button;
} else {
return SDL_SetError("Unexpected gamepad element %s", szGameButton);
}
if (*szJoystickButton == '+' || *szJoystickButton == '-') {
half_axis_input = *szJoystickButton++;
}
if (szJoystickButton[SDL_strlen(szJoystickButton) - 1] == '~') {
invert_input = SDL_TRUE;
}
if (szJoystickButton[0] == 'a' && SDL_isdigit((unsigned char)szJoystickButton[1])) {
bind.inputType = SDL_GAMEPAD_BINDTYPE_AXIS;
bind.input.axis.axis = SDL_atoi(&szJoystickButton[1]);
if (half_axis_input == '+') {
bind.input.axis.axis_min = 0;
bind.input.axis.axis_max = SDL_JOYSTICK_AXIS_MAX;
} else if (half_axis_input == '-') {
bind.input.axis.axis_min = 0;
bind.input.axis.axis_max = SDL_JOYSTICK_AXIS_MIN;
} else {
bind.input.axis.axis_min = SDL_JOYSTICK_AXIS_MIN;
bind.input.axis.axis_max = SDL_JOYSTICK_AXIS_MAX;
}
if (invert_input) {
int tmp = bind.input.axis.axis_min;
bind.input.axis.axis_min = bind.input.axis.axis_max;
bind.input.axis.axis_max = tmp;
}
} else if (szJoystickButton[0] == 'b' && SDL_isdigit((unsigned char)szJoystickButton[1])) {
bind.inputType = SDL_GAMEPAD_BINDTYPE_BUTTON;
bind.input.button = SDL_atoi(&szJoystickButton[1]);
} else if (szJoystickButton[0] == 'h' && SDL_isdigit((unsigned char)szJoystickButton[1]) &&
szJoystickButton[2] == '.' && SDL_isdigit((unsigned char)szJoystickButton[3])) {
int hat = SDL_atoi(&szJoystickButton[1]);
int mask = SDL_atoi(&szJoystickButton[3]);
bind.inputType = SDL_GAMEPAD_BINDTYPE_HAT;
bind.input.hat.hat = hat;
bind.input.hat.hat_mask = mask;
} else {
return SDL_SetError("Unexpected joystick element: %s", szJoystickButton);
}
++gamepad->num_bindings;
gamepad->bindings = (SDL_GamepadBinding *)SDL_realloc(gamepad->bindings, gamepad->num_bindings * sizeof(*gamepad->bindings));
if (!gamepad->bindings) {
gamepad->num_bindings = 0;
return SDL_OutOfMemory();
}
gamepad->bindings[gamepad->num_bindings - 1] = bind;
return 0;
}
/*
* given a gamepad mapping string update our mapping object
*/
static int SDL_PrivateParseGamepadConfigString(SDL_Gamepad *gamepad, const char *pchString)
{
char szGameButton[20];
char szJoystickButton[20];
SDL_bool bGameButton = SDL_TRUE;
int i = 0;
const char *pchPos = pchString;
SDL_zeroa(szGameButton);
SDL_zeroa(szJoystickButton);
while (pchPos && *pchPos) {
if (*pchPos == ':') {
i = 0;
bGameButton = SDL_FALSE;
} else if (*pchPos == ' ') {
} else if (*pchPos == ',') {
i = 0;
bGameButton = SDL_TRUE;
SDL_PrivateParseGamepadElement(gamepad, szGameButton, szJoystickButton);
SDL_zeroa(szGameButton);
SDL_zeroa(szJoystickButton);
} else if (bGameButton) {
if (i >= sizeof(szGameButton)) {
return SDL_SetError("Button name too large: %s", szGameButton);
}
szGameButton[i] = *pchPos;
i++;
} else {
if (i >= sizeof(szJoystickButton)) {
return SDL_SetError("Joystick button name too large: %s", szJoystickButton);
}
szJoystickButton[i] = *pchPos;
i++;
}
pchPos++;
}
/* No more values if the string was terminated by a comma. Don't report an error. */
if (szGameButton[0] != '\0' || szJoystickButton[0] != '\0') {
SDL_PrivateParseGamepadElement(gamepad, szGameButton, szJoystickButton);
}
return 0;
}
/*
* Make a new button mapping struct
*/
static void SDL_PrivateLoadButtonMapping(SDL_Gamepad *gamepad, GamepadMapping_t *pGamepadMapping)
{
int i;
SDL_AssertJoysticksLocked();
gamepad->name = pGamepadMapping->name;
gamepad->num_bindings = 0;
gamepad->mapping = pGamepadMapping;
if (gamepad->joystick->naxes != 0 && gamepad->last_match_axis != NULL) {
SDL_memset(gamepad->last_match_axis, 0, gamepad->joystick->naxes * sizeof(*gamepad->last_match_axis));
}
SDL_PrivateParseGamepadConfigString(gamepad, pGamepadMapping->mapping);
/* Set the zero point for triggers */
for (i = 0; i < gamepad->num_bindings; ++i) {
SDL_GamepadBinding *binding = &gamepad->bindings[i];
if (binding->inputType == SDL_GAMEPAD_BINDTYPE_AXIS &&
binding->outputType == SDL_GAMEPAD_BINDTYPE_AXIS &&
(binding->output.axis.axis == SDL_GAMEPAD_AXIS_LEFT_TRIGGER ||
binding->output.axis.axis == SDL_GAMEPAD_AXIS_RIGHT_TRIGGER)) {
if (binding->input.axis.axis < gamepad->joystick->naxes) {
gamepad->joystick->axes[binding->input.axis.axis].value =
gamepad->joystick->axes[binding->input.axis.axis].zero = (Sint16)binding->input.axis.axis_min;
}
}
}
}
/*
* grab the guid string from a mapping string
*/
static char *SDL_PrivateGetGamepadGUIDFromMappingString(const char *pMapping)
{
const char *pFirstComma = SDL_strchr(pMapping, ',');
if (pFirstComma) {
char *pchGUID = SDL_malloc(pFirstComma - pMapping + 1);
if (pchGUID == NULL) {
SDL_OutOfMemory();
return NULL;
}
SDL_memcpy(pchGUID, pMapping, pFirstComma - pMapping);
pchGUID[pFirstComma - pMapping] = '\0';
/* Convert old style GUIDs to the new style in 2.0.5 */
#if defined(__WIN32__) || defined(__WINGDK__)
if (SDL_strlen(pchGUID) == 32 &&
SDL_memcmp(&pchGUID[20], "504944564944", 12) == 0) {
SDL_memcpy(&pchGUID[20], "000000000000", 12);
SDL_memcpy(&pchGUID[16], &pchGUID[4], 4);
SDL_memcpy(&pchGUID[8], &pchGUID[0], 4);
SDL_memcpy(&pchGUID[0], "03000000", 8);
}
#elif defined(__MACOS__)
if (SDL_strlen(pchGUID) == 32 &&
SDL_memcmp(&pchGUID[4], "000000000000", 12) == 0 &&
SDL_memcmp(&pchGUID[20], "000000000000", 12) == 0) {
SDL_memcpy(&pchGUID[20], "000000000000", 12);
SDL_memcpy(&pchGUID[8], &pchGUID[0], 4);
SDL_memcpy(&pchGUID[0], "03000000", 8);
}
#endif
return pchGUID;
}
return NULL;
}
/*
* grab the name string from a mapping string
*/
static char *SDL_PrivateGetGamepadNameFromMappingString(const char *pMapping)
{
const char *pFirstComma, *pSecondComma;
char *pchName;
pFirstComma = SDL_strchr(pMapping, ',');
if (pFirstComma == NULL) {
return NULL;
}
pSecondComma = SDL_strchr(pFirstComma + 1, ',');
if (pSecondComma == NULL) {
return NULL;
}
pchName = SDL_malloc(pSecondComma - pFirstComma);
if (pchName == NULL) {
SDL_OutOfMemory();
return NULL;
}
SDL_memcpy(pchName, pFirstComma + 1, pSecondComma - pFirstComma);
pchName[pSecondComma - pFirstComma - 1] = 0;
return pchName;
}
/*
* grab the button mapping string from a mapping string
*/
static char *SDL_PrivateGetGamepadMappingFromMappingString(const char *pMapping)
{
const char *pFirstComma, *pSecondComma;
char *result;
size_t length;
pFirstComma = SDL_strchr(pMapping, ',');
if (pFirstComma == NULL) {
return NULL;
}
pSecondComma = SDL_strchr(pFirstComma + 1, ',');
if (pSecondComma == NULL) {
return NULL;
}
/* Skip whitespace */
while (SDL_isspace(pSecondComma[1])) {
++pSecondComma;
}
result = SDL_strdup(pSecondComma + 1); /* mapping is everything after the 3rd comma */
/* Trim whitespace */
length = SDL_strlen(result);
while (SDL_isspace(result[length - 1])) {
--length;
}
result[length] = '\0';
return result;
}
/*
* Helper function to add a mapping for a guid
*/
static GamepadMapping_t *SDL_PrivateAddMappingForGUID(SDL_JoystickGUID jGUID, const char *mappingString, SDL_bool *existing, SDL_GamepadMappingPriority priority)
{
char *pchName;
char *pchMapping;
GamepadMapping_t *pGamepadMapping;
Uint16 crc;
SDL_AssertJoysticksLocked();
pchName = SDL_PrivateGetGamepadNameFromMappingString(mappingString);
if (pchName == NULL) {
SDL_SetError("Couldn't parse name from %s", mappingString);
return NULL;
}
pchMapping = SDL_PrivateGetGamepadMappingFromMappingString(mappingString);
if (pchMapping == NULL) {
SDL_free(pchName);
SDL_SetError("Couldn't parse %s", mappingString);
return NULL;
}
/* Fix up the GUID and the mapping with the CRC, if needed */
SDL_GetJoystickGUIDInfo(jGUID, NULL, NULL, NULL, &crc);
if (crc) {
/* Make sure the mapping has the CRC */
char *new_mapping;
const char *optional_comma;
size_t mapping_length;
char *crc_end = "";
char *crc_string = SDL_strstr(pchMapping, SDL_GAMEPAD_CRC_FIELD);
if (crc_string) {
crc_end = SDL_strchr(crc_string, ',');
if (crc_end) {
++crc_end;
} else {
crc_end = "";
}
*crc_string = '\0';
}
/* Make sure there's a comma before the CRC */
mapping_length = SDL_strlen(pchMapping);
if (mapping_length == 0 || pchMapping[mapping_length - 1] == ',') {
optional_comma = "";
} else {
optional_comma = ",";
}
if (SDL_asprintf(&new_mapping, "%s%s%s%.4x,%s", pchMapping, optional_comma, SDL_GAMEPAD_CRC_FIELD, crc, crc_end) >= 0) {
SDL_free(pchMapping);
pchMapping = new_mapping;
}
} else {
/* Make sure the GUID has the CRC, for matching purposes */
char *crc_string = SDL_strstr(pchMapping, SDL_GAMEPAD_CRC_FIELD);
if (crc_string) {
crc = (Uint16)SDL_strtol(crc_string + SDL_GAMEPAD_CRC_FIELD_SIZE, NULL, 16);
if (crc) {
SDL_SetJoystickGUIDCRC(&jGUID, crc);
}
}
}
PushMappingChangeTracking();
pGamepadMapping = SDL_PrivateGetGamepadMappingForGUID(jGUID, SDL_TRUE);
if (pGamepadMapping) {
/* Only overwrite the mapping if the priority is the same or higher. */
if (pGamepadMapping->priority <= priority) {
/* Update existing mapping */
SDL_free(pGamepadMapping->name);
pGamepadMapping->name = pchName;
SDL_free(pGamepadMapping->mapping);
pGamepadMapping->mapping = pchMapping;
pGamepadMapping->priority = priority;
} else {
SDL_free(pchName);
SDL_free(pchMapping);
}
if (existing) {
*existing = SDL_TRUE;
}
AddMappingChangeTracking(pGamepadMapping);
} else {
pGamepadMapping = SDL_malloc(sizeof(*pGamepadMapping));
if (pGamepadMapping == NULL) {
PopMappingChangeTracking();
SDL_free(pchName);
SDL_free(pchMapping);
SDL_OutOfMemory();
return NULL;
}
/* Clear the CRC, we've already added it to the mapping */
if (crc) {
SDL_SetJoystickGUIDCRC(&jGUID, 0);
}
pGamepadMapping->guid = jGUID;
pGamepadMapping->name = pchName;
pGamepadMapping->mapping = pchMapping;
pGamepadMapping->next = NULL;
pGamepadMapping->priority = priority;
if (s_pSupportedGamepads) {
/* Add the mapping to the end of the list */
GamepadMapping_t *pCurrMapping, *pPrevMapping;
for (pPrevMapping = s_pSupportedGamepads, pCurrMapping = pPrevMapping->next;
pCurrMapping;
pPrevMapping = pCurrMapping, pCurrMapping = pCurrMapping->next) {
/* continue; */
}
pPrevMapping->next = pGamepadMapping;
} else {
s_pSupportedGamepads = pGamepadMapping;
}
if (existing) {
*existing = SDL_FALSE;
}
}
PopMappingChangeTracking();
return pGamepadMapping;
}
/*
* Helper function to determine pre-calculated offset to certain joystick mappings
*/
static GamepadMapping_t *SDL_PrivateGetGamepadMappingForNameAndGUID(const char *name, SDL_JoystickGUID guid)
{
GamepadMapping_t *mapping;
SDL_AssertJoysticksLocked();
mapping = SDL_PrivateGetGamepadMappingForGUID(guid, SDL_FALSE);
#ifdef __LINUX__
if (mapping == NULL && name) {
if (SDL_strstr(name, "Xbox 360 Wireless Receiver")) {
/* The Linux driver xpad.c maps the wireless dpad to buttons */
SDL_bool existing;
mapping = SDL_PrivateAddMappingForGUID(guid,
"none,X360 Wireless Controller,a:b0,b:b1,back:b6,dpdown:b14,dpleft:b11,dpright:b12,dpup:b13,guide:b8,leftshoulder:b4,leftstick:b9,lefttrigger:a2,leftx:a0,lefty:a1,rightshoulder:b5,rightstick:b10,righttrigger:a5,rightx:a3,righty:a4,start:b7,x:b2,y:b3,",
&existing, SDL_GAMEPAD_MAPPING_PRIORITY_DEFAULT);
}
}
#endif /* __LINUX__ */
if (mapping == NULL) {
mapping = s_pDefaultMapping;
}
return mapping;
}
static void SDL_PrivateAppendToMappingString(char *mapping_string,
size_t mapping_string_len,
const char *input_name,
SDL_InputMapping *mapping)
{
char buffer[16];
if (mapping->kind == EMappingKind_None) {
return;
}
SDL_strlcat(mapping_string, input_name, mapping_string_len);
SDL_strlcat(mapping_string, ":", mapping_string_len);
switch (mapping->kind) {
case EMappingKind_Button:
(void)SDL_snprintf(buffer, sizeof(buffer), "b%i", mapping->target);
break;
case EMappingKind_Axis:
(void)SDL_snprintf(buffer, sizeof(buffer), "a%i", mapping->target);
break;
case EMappingKind_Hat:
(void)SDL_snprintf(buffer, sizeof(buffer), "h%i.%i", mapping->target >> 4, mapping->target & 0x0F);
break;
default:
SDL_assert(SDL_FALSE);
}
SDL_strlcat(mapping_string, buffer, mapping_string_len);
SDL_strlcat(mapping_string, ",", mapping_string_len);
}
static GamepadMapping_t *SDL_PrivateGenerateAutomaticGamepadMapping(const char *name,
SDL_JoystickGUID guid,
SDL_GamepadMapping *raw_map)
{
SDL_bool existing;
char name_string[128];
char mapping[1024];
/* Remove any commas in the name */
SDL_strlcpy(name_string, name, sizeof(name_string));
{
char *spot;
for (spot = name_string; *spot; ++spot) {
if (*spot == ',') {
*spot = ' ';
}
}
}
(void)SDL_snprintf(mapping, sizeof(mapping), "none,%s,", name_string);
SDL_PrivateAppendToMappingString(mapping, sizeof(mapping), "a", &raw_map->a);
SDL_PrivateAppendToMappingString(mapping, sizeof(mapping), "b", &raw_map->b);
SDL_PrivateAppendToMappingString(mapping, sizeof(mapping), "x", &raw_map->x);
SDL_PrivateAppendToMappingString(mapping, sizeof(mapping), "y", &raw_map->y);
SDL_PrivateAppendToMappingString(mapping, sizeof(mapping), "back", &raw_map->back);
SDL_PrivateAppendToMappingString(mapping, sizeof(mapping), "guide", &raw_map->guide);
SDL_PrivateAppendToMappingString(mapping, sizeof(mapping), "start", &raw_map->start);
SDL_PrivateAppendToMappingString(mapping, sizeof(mapping), "leftstick", &raw_map->leftstick);
SDL_PrivateAppendToMappingString(mapping, sizeof(mapping), "rightstick", &raw_map->rightstick);
SDL_PrivateAppendToMappingString(mapping, sizeof(mapping), "leftshoulder", &raw_map->leftshoulder);
SDL_PrivateAppendToMappingString(mapping, sizeof(mapping), "rightshoulder", &raw_map->rightshoulder);
SDL_PrivateAppendToMappingString(mapping, sizeof(mapping), "dpup", &raw_map->dpup);
SDL_PrivateAppendToMappingString(mapping, sizeof(mapping), "dpdown", &raw_map->dpdown);
SDL_PrivateAppendToMappingString(mapping, sizeof(mapping), "dpleft", &raw_map->dpleft);
SDL_PrivateAppendToMappingString(mapping, sizeof(mapping), "dpright", &raw_map->dpright);
SDL_PrivateAppendToMappingString(mapping, sizeof(mapping), "misc1", &raw_map->misc1);
Squashed 'external/sdl/SDL/' changes from b8d91252c6..ec0042081e ec0042081e Add .gitattributes file a5d9db0cd0 cmake: build tests for UWP b7889a7389 winrt: use windowsio in non-libc mode ea8757a748 Make testaudiostreamdynamicresample compatible with emscripten 1a7a74fb2e cmake: build emscripten tests as html page 64d570f027 Add minimal http server for emscripten test apps 8e898c4a21 SDL_test does not parse --samples argument 91cd5478be audio: Fix resampler overflowing input buffer. f290c85b22 testaudiocapture: Make sure we convert captured audio to output format. b75c751dfc rwlock: Make generic implmentations work on single-threaded platforms. 80850af7ce The controller update complete events are no longer disabled by default 3f486224a9 Fixed refresh rate calculation for KMSDRM 342ec51131 Fix overflow when doing SDL_sscanf("%hd", ...) 9129e1d557 Fixed crash when setting the default cursor twice 8e99a4f4f5 Undo variable rename be67f0de10 Fixed crashes related to the default cursor on WinRT and KMSDRM 94b3f78c44 Fix out of bound read of 'has_hat' array 94f48f19b0 Use more specific build destinations when creating an xcframework dabd45997e Back out change supporting multiple names for binding elements efe15588d5 Relabel back paddles as left or right be884f0c95 ci: disable visionos.yml by renaming the file ac094d00f5 ci: add workflow_dispatch event to visionos workflow 9be9e2292b build: Consistently use pathlib APIs in cmake/xxd.py a9f6950657 Fixed deadlock shutting down Android sensors d9f09e77f2 Actually make the sensors magical! 690eae7d22 Implement visionOS support e385d6da0a Fixed build warning 6b93e788fa Improved sensor thread-safety 4ee0e5a984 Fixed thread-safety warnings 12deed91f8 Added information on how to enable thread-safety analysis 5735d2b03b coreaudio: Fixed assertion when device fails/quits mid-iteration. 1022fd6e04 testaudio: the test framework opens an audio device at startup; close it. 0714da37a4 audio: Fix audio stream callback calculations when future buffer has space. 917e036f6f MSVC has __declspec(deprecated) 279ff8909f Changed example code to avoid potential divide by zero 8a1afc9b10 Fixed Android not sending controller event timestamps 463c456b98 Fill the correct member with the joystick ID in SDL_EVENT_JOYSTICK_UPDATE_COMPLETE 55cf1abaa6 test: Don't flag testsurround as suitable for non-interactive use a2d594269c Fixed pixel format compatibility with SDL2 79a190aa23 Fixed setting invalid bpp for FOURCC formats in SDL_GetMasksForPixelFormatEnum() 8fdebdd3e0 Sync SDL3 wiki -> header b903ccf945 SDL_rwops read/write functions return size_t again c03f5b4b69 Fixed rounding up in SDL_PrintFloat 75a020aa6b Only query serial number and firmware versions from Sony PS5 controllers fa189d302e Added the Victrix Pro FS for PS4/PS5 to the controller list 26205b659d Fixed PS4/PS5 touchpad for third party controllers 6af0448af9 include: fixed a typo in SDL_RenderGetMetalCommandEncoder docs. f3cb46b083 SDL_thread.h: do not conflict with sdl2-compat::sdl3_include_wrapper.h 080b1dfbdb Revert "Improved fallback for SDL_COMPILE_TIME_ASSERT() (thanks @icculus!)" 9d453daa23 Improved fallback for SDL_COMPILE_TIME_ASSERT() (thanks @icculus!) 1fb2419882 Removed reference to renamed function e7d56dd0b2 audio: Renamed new API SDL_UnpauseAudioDevice to SDL_ResumeAudioDevice. 2b0c0f5b6b Don't pass NULL to strncmp 778e8185cd Fix size of memcpy in SDL_AudioDeviceFormatChangedAlreadyLocked And add diagnostic that allows to find this kind of issue in clang-tidy 4bb426abad Sync SDL3 wiki -> header 3a752ce650 Reapply "Changed 'freesrc' parameter from int to SDL_bool" to SDL_wave.c 2ba03b4db0 fix build after previous commit. 0026adffd4 apply force_align_arg_pointer attribute to correct version of SDL_RunApp 77446e2029 Unaligned stacks on i686-w64-mingw32 may lead to crashes d3bcc3f057 Fixed build errors when OpenGL isn't enabled 35ad68e126 Sync SDL3 wiki -> header 70323a8350 Add a function to display the system menu for a window be5f66c84e testaudio: Fixed soundboard icon, which had a colorkey issue. c0a88930bf Sync SDL3 wiki -> header 18c59cc969 Merge the SDL3 audio subsystem redesign! 99b0e31788 The Steam Controller D-Pad is only pressed when the button is pressed down 103073d694 Set NSBluetoothAlwaysUsageDescription for testcontroller ca02bb6c8c We don't need testdropfile-Info.plist e063f662e9 Enable the controller update complete events 06bea1eb55 Added a gamepad mapping for the G-Shark GS-GP702 5ca3c50bf0 testaudio: Fix compiler warning. 1b1f02c5aa testaudio: Apparently compilers don't like this possibly being NULL now...? 2de9253b6c test: Added testaudio fb3ab3f113 SDL_video.c: move ngage video before offscreen. 843572d993 Don't mark autorelease keys as virtual 648de4f9b8 Fixed duplicate key press/release events on iOS a8abe612ed Only pass keypresses up the responder chain when text input is active c3288d113e Synchronize on-screen keyboard state with text input active state 5fb92ef2f7 Fixed whitespace f5ea6ae18d Revert "Stop beep when running iOS apps on ARM-based Macs" 546508b9b4 Allow test programs to run at full resolution on iPads 68a4bb01e0 Allocate displays as an array of pointers instead of an array of objects 07578fde3d Fixed crash if a display is enumerated twice a509771a87 fix ios CI workflow after commit e4460e897f 72ce76905a The scheme isn't always the same as the framework name (e.g. xmp_lite vs xmp-lite) e4460e897f By default Xcode expects the framework target name to be the name of the project. ac683773dc Added missing tests to the "All" target 7dd56eaafe Removed unnecessary reference to testoverlay-Info.plist e1c7f524ef Reduce the number of times SDL3 is duplicated in the xcframework script 65538011ca Make Xcode targets more specific efe114c300 Revert "Renamed the xcframework target from "SDL.xcframework" to "xcframework"" 73ed1d21a9 Renamed the xcframework target from "SDL.xcframework" to "xcframework" 76b4d8a0d8 Build the Framework instead of a static library for iOS and tvOS d1bf979160 Removed unnecessary setting from the "Create DMG" target c94cb3a5d8 Simplified the Xcode project to a single Framework target ea60474c65 cmake: don't build SDL3-static Apple framework 8f00d7856d Sync SDL3 wiki -> header d4a867a256 Rename SDL_GetPath to SDL_GetUserFolder 71099149b8 Fall back to Xlib if XRandR isn't available b7f32f74ce Note the removal of the SDL_RENDERER_TARGETTEXTURE flag 0eda582160 testaudiostreamdynamicresample: Load sample.wav correctly. 87eae9a0a1 aaudio: We need a mixbuf on capture devices, too. fb68e84646 wayland: Fix memory leaks b0edd23c00 testsurround: Log available audio output devices at the start. ae3090c387 androidaudio: Move Init/bootstrap code to bottom of source code. 18fc0db9e5 aaudio: Rearranged source code to match other backends. 2507c1d68b aaudio: Disconnect playing devices if error callback fires. 32a3fc3783 aaudio: Use the callback interface. b49ce86765 audio: Fixed compiler warning on Android NDK. 1c074e8d97 android: Fixed audio device detection. 82ce05ad01 pulseaudio: Be more aggressive with hotplug thread synchronization. 5cbdf1168e androidaudio: Fixed incorrect JNI call (thanks, @madebr!) 660054f3dc include: Correct comment about audio device hotplug events. ab68428a64 aaudio: Fixed for older SDKs and Android releases. 5ff87c6d4a android: Reworked audio backends for SDL3 audio API. 54af687210 testautomation_audio.c: Patched to compile. :/ 5e82090662 testautomation_audio.c: Apparently we aren't updating test code for C99 atm. 7f4488f625 wasapi: More fixes for Clang warnings. 29a0c689c9 wasapi: Patched to compile with Clang. 4aa95c21bc pspaudio: Patched to compile. 9a2a0a1463 ps2audio: Delete errant character that got inserted before previous commit. 2c578bd0d5 qnxaudio: Rewrite for SDL3 audio APIs. 455eef4cd9 audio: Use AtomicAdd for device counts, don't treat as a refcount. 095ea57f94 pspaudio: Patched to compile. d7cf63db67 ps2audio: Patched to compile. 027b9e8787 coreaudio: (maybe) patched to compile on iOS. 4836c2db07 pspaudio: Patched to compile. 86ca412436 n3dsaudio: Patched to compile. 66bcee2ca9 testaudiostreamdynamicresample.c: Fixed MSVC compiler warning. dbf993d358 vitaaudio: patched to compile. 5707e14716 audio: Fix up some things that broke when rebasing the branch against main. 6567285eae SDL_migration.cocci: Fix up SDL_(Pause|Unpause)Audio. 0b6255551e test: Fixed incorrect SDL_OpenAudioDevice call in testautomation. 107fd941cd vitaaudio: Clean up correctly in CloseDevice. 9fa4a6ef87 netbsdaudio: Minor fix. b0d89868c6 n3dsaudio: Updated (but untested!) for SDL3 audio API. ba27176106 vitaaudio: Untested attempt to move Vita audio to SDL3's audio API. 0b58e96d9e wasapi: Patched WinRT to compile. d6b4f48488 visualc: Turn on multiprocessor compilation. c58d95c343 wasapi: Reworked for new SDL3 audio API, other win32 fixes. dc04f85646 audio: whoops, that should be an int. be0dc630b7 audio: Fixed incorrect assertion 77b3fb06ee directsound: First shot at updating for SDL3 audio API. 4399b71715 audio: Generalize how backends can lookup an SDL_AudioDevice. 2fb122fe46 audio: backends now "find" instead of "obtain" devices by handle. c3f5a5fc72 dummyaudio: SDL3ify style 7d65ff86e2 diskaudio: Adjusted for later SDL3 audio API redesign changes. 4ba9c2eade dummyaudio: Configurable delay, other SDL3 API fixes. fb395d3ad7 sndio: Updated to the SDL3 audio API. 1a55282051 dsp: Some minor logic fixes 6bc85577d7 netbsdaudio: Updated for SDL3 audio API. 0f6e59312b netbsdaudio: Removed email address from source code. 51ae78c0af haikuaudio: Updated for SDL3 audio API. fc7ed18ca1 emscriptenaudio: don't forget to finalize the audio thread 4233c41ce2 pulseaudio: Removed unnecessary variable. a0528cd5ed emscriptenaudio: Updated for SDL3 audio API. 79cc29ba35 wave: Don't check if format->channels > INT_MAX, it's a Uint16. 1bfe97c235 pspaudio: Updated for SDL3 audio API. 121a2dce15 audio: Make sure `device->hidden` is NULL after CloseDevice 3d6ba0cafd ps2audio: Removed free of buffer that hasn't been allocated yet. 00ed6f8827 test: Fixed compiler warnings for unused vars. 6f12f68ec9 ps2audio: SDL3ified the style 4993743a02 ps2audio: Renamed `_this` to `device` 74568cdb2b ps2audio: Updated (but untested) for SDL3 audio API. c83b68ef26 jack: renamed `_this` to `device`. 3f4f004794 audio: Remove an assertion that no longer makes sense. 86243b2589 jack: Use ProvidesOwnCallbackThread. 18906a32b8 jack: First shot at updating for SDL3 audio API. a2b488359e dsp: Removed debug logging 6fd71185cd dsp: Updated for new SDL3 audio API. 3482d1215a alsa: Don't ever block in CaptureFromDevice. 65d296ef1a audio: Use SDL_powerof2 instead of reinventing it. 409b544505 alsa: Updated for new SDL3 audio API 0999a090a7 audio: More tweaking of `device->thread_alive` f94ffd6092 audio: Fixed logic error 4deb2970c9 alsa: Renamed `_this` to `device` 0fb9e4baae audio: Remove no-longer-used SupportsNonPow2Samples c653e57768 coreaudio: rewritten for SDL3 audio redesign! 533777eff5 audio: SDL_sysaudio.h comment conversion. 8473e522e0 audio: unify device thread naming. 258bc9efed audio: PlayDevice now passes the buffer, too, for convenience. e518149d14 audio: Fixed locking in SDL_AudioDeviceDisconnected 22afa5735f audio: FreeDeviceHandle should pass the whole device, for convenience. 9e3c5f93e0 coreaudio: Change `_this` to `device` e969160de0 audio: unset a freed variable to NULL 1fc01b0300 audio: Try to definitely have a default device set up. b60a56d368 audio: take first reported device if no default was specified. a8323ebe68 audio: Better handling of ProvidesOwnCallbackThread backends. 1dffb72c1d pipewire: Hooked up default device change notifications. a93fcf2444 audio: fixed flushed stream reporting bytes but not being able to get them. ad6c1781fc pulseaudio: Minor cleanups. cfc8a0d17d pipewire: First shot at moving to the new SDL3 audio interfaces. 13202642a3 aaudio: Fixed capitialization, plus some minor cleanups. 3e9991b535 audio: Make sure we don't write to a NULL pointer. 943351affb pulseaudio: GetDefaultAudioInfo isn't a thing anymore. 11dfc4d737 test: Update testautomation_audio for SDL3 audio API. 29afc2e42b test: Update testresample for SDL3 audio API. 3a02eecced test: Update testsurround for SDL3 audio API. e1c78718d4 test: testaudiocapture is updated for the SDL3 audio API. f48cb716c2 pulseaudio: a couple minor tweaks. dac25fe9eb audio: Seperate audio capture into Wait/Read operations. 3e10c0005d audio: Capture devices should respect logical device pausing. 7e700531c5 audio: Allow SDL_OpenAudioDevice to accept a NULL spec. bb1cbbd33a test: Update testaudioinfo for SDL3 audio API. 883aee32c5 audio: Let default formats differ for output and capture devices. 62cf24eeb9 pulseaudio: Listen for server events in addition to sources and sinks. 924f370bd7 pulseaudio: Fix deadlock in HotplugThread. 5d4e9e5f80 test: Updated testaudiostreamdynamicresample to SDL3 audio API. f883b9fc64 test: Updated testaudiohotplug to SDL3 audio API. 2be5f726d4 audio: Removed debug logging. 323ecce123 docs: Added migration note about SDL_AUDIODEVICEREMOVED. 47b0321ebf test: Removed loopwavequeue.c; obsolete in SDL3. 0e5a1d4f29 pulseaudio: Removed debug logging. f598626e46 test: loopwave shouldn't use an audiostream callback. eee407caf8 docs: migration guide note that SDL_LoadWAV has a different return type. b03c493fc4 test: Updated testmultiaudio to new SDL3 audio API fe1daf6fb5 audio: Mark disconnected default devices as "zombies". cdd2ba81de audio: Fixed adding new physical devices to a double-linked list. db39cbf208 audio: Allow SDL_GetAudioDeviceFormat() to query the default devices. ee10bab3cd audio: An enormous amount of work on managing default devices. c7a44eea83 audio: Fixed logic error. 089cd87cb5 audio: Make sure device count stays correct as hardware disconnects. e50cb72eb6 docs: Note that audio opening doesn't implicitly init SDL now. 97b2f747d0 docs: Corrections to audio section of README-migration.md 464640440f audio: Added SDL_GetAudioStreamBinding. 01f7b53865 audio: Readded (logical) device pausing. fd4c9f4e11 audio: documentation improvements. 4b78b789a7 audio: Switch SDL_audio.c and SDL_audiocvt.c to C99-ish syntax. d96a1db7d7 audio: Opening via a logical device ID should also track default device. b2e020958f audio: Wrap device access in opening of logical devices. 7ee2459927 audio: Check for unlikely failure case in WAV loaded. 3d65a2cefe audio: Made SDL_LoadWAV a real function, not just a macro. 26525f5fd3 audio: Readd SDL_AudioSpec, but just with format/channels/freq fields. e6aaed7d79 include: Audio is not, and has not been, a raw mixing buffer for a long time. 56b1bc2198 audio: SDL_AudioStream now has callbacks for Get and Put operations. 905c4fff5b audio: First shot at the SDL3 audio subsystem redesign! b221b59995 cmake: add SDL_REVISION option 0500fca00c Add missing break d3f2de7f29 fixed typo in prev. patch. 12b35c6a46 test/testnativecocoa.m: fixed deprecation warnings. e24b3e2fa4 cmake: rename SDL_TEST -> SDL_TEST_LIBRARY da5016d336 cmake: use pkg-config + test compile instead of Find module for detecting rpi deec574ff6 cmake: fix SDL_HIDAPI_LIBUSB f2ae00c1ad Sync SDL3 wiki -> header 41a96c8133 doc: document building of SDL tests with CMake 3174d0b970 Sorted controller list 27b8abb056 Add Steam Deck controller mapping to database. 41d436f0fe Use SetWindowPos to show windows when SDL_HINT_WINDOW_ACTIVATE_WHEN_SHOWN is set to avoid activating the parent window when showing a child window 0dc85f3078 Improved the documentation for the gamepad paddle buttons 2fff999a41 Try to create the dummy mouse cursor after video backend initialization d086d9874d Sync SDL3 wiki -> header bce598addd SDL_pixels.c: Fixed compiler warning on Android NDK. ad0c0d3cde Sync SDL3 wiki -> header f8e8dff7ee tests: Fix automated window grab and positioning tests under Wayland/XWayland 4cffbc3644 Add VS code directory to gitignore 666f81bace Add more endian-specific aliases for 32 bit pixelformats 4749df0a63 Just disable the 4214 warning instead of trying to change the structure definition git-subtree-dir: external/sdl/SDL git-subtree-split: ec0042081ea104d5dd0ee291105210e00a4fe3d9
2023-08-12 20:17:29 +02:00
/* Keep using paddle1-4 in the generated mapping so that it can be
* reused with SDL2 */
SDL_PrivateAppendToMappingString(mapping, sizeof(mapping), "paddle1", &raw_map->right_paddle1);
SDL_PrivateAppendToMappingString(mapping, sizeof(mapping), "paddle2", &raw_map->left_paddle1);
SDL_PrivateAppendToMappingString(mapping, sizeof(mapping), "paddle3", &raw_map->right_paddle2);
SDL_PrivateAppendToMappingString(mapping, sizeof(mapping), "paddle4", &raw_map->left_paddle2);
SDL_PrivateAppendToMappingString(mapping, sizeof(mapping), "leftx", &raw_map->leftx);
SDL_PrivateAppendToMappingString(mapping, sizeof(mapping), "lefty", &raw_map->lefty);
SDL_PrivateAppendToMappingString(mapping, sizeof(mapping), "rightx", &raw_map->rightx);
SDL_PrivateAppendToMappingString(mapping, sizeof(mapping), "righty", &raw_map->righty);
SDL_PrivateAppendToMappingString(mapping, sizeof(mapping), "lefttrigger", &raw_map->lefttrigger);
SDL_PrivateAppendToMappingString(mapping, sizeof(mapping), "righttrigger", &raw_map->righttrigger);
return SDL_PrivateAddMappingForGUID(guid, mapping, &existing, SDL_GAMEPAD_MAPPING_PRIORITY_DEFAULT);
}
static GamepadMapping_t *SDL_PrivateGetGamepadMapping(SDL_JoystickID instance_id)
{
const char *name;
SDL_JoystickGUID guid;
GamepadMapping_t *mapping;
SDL_AssertJoysticksLocked();
name = SDL_GetJoystickInstanceName(instance_id);
guid = SDL_GetJoystickInstanceGUID(instance_id);
mapping = SDL_PrivateGetGamepadMappingForNameAndGUID(name, guid);
if (mapping == NULL) {
SDL_GamepadMapping raw_map;
SDL_zero(raw_map);
if (SDL_PrivateJoystickGetAutoGamepadMapping(instance_id, &raw_map)) {
mapping = SDL_PrivateGenerateAutomaticGamepadMapping(name, guid, &raw_map);
}
}
return mapping;
}
/*
* Add or update an entry into the Mappings Database
*/
Squashed 'external/sdl/SDL/' changes from b8d91252c6..ec0042081e ec0042081e Add .gitattributes file a5d9db0cd0 cmake: build tests for UWP b7889a7389 winrt: use windowsio in non-libc mode ea8757a748 Make testaudiostreamdynamicresample compatible with emscripten 1a7a74fb2e cmake: build emscripten tests as html page 64d570f027 Add minimal http server for emscripten test apps 8e898c4a21 SDL_test does not parse --samples argument 91cd5478be audio: Fix resampler overflowing input buffer. f290c85b22 testaudiocapture: Make sure we convert captured audio to output format. b75c751dfc rwlock: Make generic implmentations work on single-threaded platforms. 80850af7ce The controller update complete events are no longer disabled by default 3f486224a9 Fixed refresh rate calculation for KMSDRM 342ec51131 Fix overflow when doing SDL_sscanf("%hd", ...) 9129e1d557 Fixed crash when setting the default cursor twice 8e99a4f4f5 Undo variable rename be67f0de10 Fixed crashes related to the default cursor on WinRT and KMSDRM 94b3f78c44 Fix out of bound read of 'has_hat' array 94f48f19b0 Use more specific build destinations when creating an xcframework dabd45997e Back out change supporting multiple names for binding elements efe15588d5 Relabel back paddles as left or right be884f0c95 ci: disable visionos.yml by renaming the file ac094d00f5 ci: add workflow_dispatch event to visionos workflow 9be9e2292b build: Consistently use pathlib APIs in cmake/xxd.py a9f6950657 Fixed deadlock shutting down Android sensors d9f09e77f2 Actually make the sensors magical! 690eae7d22 Implement visionOS support e385d6da0a Fixed build warning 6b93e788fa Improved sensor thread-safety 4ee0e5a984 Fixed thread-safety warnings 12deed91f8 Added information on how to enable thread-safety analysis 5735d2b03b coreaudio: Fixed assertion when device fails/quits mid-iteration. 1022fd6e04 testaudio: the test framework opens an audio device at startup; close it. 0714da37a4 audio: Fix audio stream callback calculations when future buffer has space. 917e036f6f MSVC has __declspec(deprecated) 279ff8909f Changed example code to avoid potential divide by zero 8a1afc9b10 Fixed Android not sending controller event timestamps 463c456b98 Fill the correct member with the joystick ID in SDL_EVENT_JOYSTICK_UPDATE_COMPLETE 55cf1abaa6 test: Don't flag testsurround as suitable for non-interactive use a2d594269c Fixed pixel format compatibility with SDL2 79a190aa23 Fixed setting invalid bpp for FOURCC formats in SDL_GetMasksForPixelFormatEnum() 8fdebdd3e0 Sync SDL3 wiki -> header b903ccf945 SDL_rwops read/write functions return size_t again c03f5b4b69 Fixed rounding up in SDL_PrintFloat 75a020aa6b Only query serial number and firmware versions from Sony PS5 controllers fa189d302e Added the Victrix Pro FS for PS4/PS5 to the controller list 26205b659d Fixed PS4/PS5 touchpad for third party controllers 6af0448af9 include: fixed a typo in SDL_RenderGetMetalCommandEncoder docs. f3cb46b083 SDL_thread.h: do not conflict with sdl2-compat::sdl3_include_wrapper.h 080b1dfbdb Revert "Improved fallback for SDL_COMPILE_TIME_ASSERT() (thanks @icculus!)" 9d453daa23 Improved fallback for SDL_COMPILE_TIME_ASSERT() (thanks @icculus!) 1fb2419882 Removed reference to renamed function e7d56dd0b2 audio: Renamed new API SDL_UnpauseAudioDevice to SDL_ResumeAudioDevice. 2b0c0f5b6b Don't pass NULL to strncmp 778e8185cd Fix size of memcpy in SDL_AudioDeviceFormatChangedAlreadyLocked And add diagnostic that allows to find this kind of issue in clang-tidy 4bb426abad Sync SDL3 wiki -> header 3a752ce650 Reapply "Changed 'freesrc' parameter from int to SDL_bool" to SDL_wave.c 2ba03b4db0 fix build after previous commit. 0026adffd4 apply force_align_arg_pointer attribute to correct version of SDL_RunApp 77446e2029 Unaligned stacks on i686-w64-mingw32 may lead to crashes d3bcc3f057 Fixed build errors when OpenGL isn't enabled 35ad68e126 Sync SDL3 wiki -> header 70323a8350 Add a function to display the system menu for a window be5f66c84e testaudio: Fixed soundboard icon, which had a colorkey issue. c0a88930bf Sync SDL3 wiki -> header 18c59cc969 Merge the SDL3 audio subsystem redesign! 99b0e31788 The Steam Controller D-Pad is only pressed when the button is pressed down 103073d694 Set NSBluetoothAlwaysUsageDescription for testcontroller ca02bb6c8c We don't need testdropfile-Info.plist e063f662e9 Enable the controller update complete events 06bea1eb55 Added a gamepad mapping for the G-Shark GS-GP702 5ca3c50bf0 testaudio: Fix compiler warning. 1b1f02c5aa testaudio: Apparently compilers don't like this possibly being NULL now...? 2de9253b6c test: Added testaudio fb3ab3f113 SDL_video.c: move ngage video before offscreen. 843572d993 Don't mark autorelease keys as virtual 648de4f9b8 Fixed duplicate key press/release events on iOS a8abe612ed Only pass keypresses up the responder chain when text input is active c3288d113e Synchronize on-screen keyboard state with text input active state 5fb92ef2f7 Fixed whitespace f5ea6ae18d Revert "Stop beep when running iOS apps on ARM-based Macs" 546508b9b4 Allow test programs to run at full resolution on iPads 68a4bb01e0 Allocate displays as an array of pointers instead of an array of objects 07578fde3d Fixed crash if a display is enumerated twice a509771a87 fix ios CI workflow after commit e4460e897f 72ce76905a The scheme isn't always the same as the framework name (e.g. xmp_lite vs xmp-lite) e4460e897f By default Xcode expects the framework target name to be the name of the project. ac683773dc Added missing tests to the "All" target 7dd56eaafe Removed unnecessary reference to testoverlay-Info.plist e1c7f524ef Reduce the number of times SDL3 is duplicated in the xcframework script 65538011ca Make Xcode targets more specific efe114c300 Revert "Renamed the xcframework target from "SDL.xcframework" to "xcframework"" 73ed1d21a9 Renamed the xcframework target from "SDL.xcframework" to "xcframework" 76b4d8a0d8 Build the Framework instead of a static library for iOS and tvOS d1bf979160 Removed unnecessary setting from the "Create DMG" target c94cb3a5d8 Simplified the Xcode project to a single Framework target ea60474c65 cmake: don't build SDL3-static Apple framework 8f00d7856d Sync SDL3 wiki -> header d4a867a256 Rename SDL_GetPath to SDL_GetUserFolder 71099149b8 Fall back to Xlib if XRandR isn't available b7f32f74ce Note the removal of the SDL_RENDERER_TARGETTEXTURE flag 0eda582160 testaudiostreamdynamicresample: Load sample.wav correctly. 87eae9a0a1 aaudio: We need a mixbuf on capture devices, too. fb68e84646 wayland: Fix memory leaks b0edd23c00 testsurround: Log available audio output devices at the start. ae3090c387 androidaudio: Move Init/bootstrap code to bottom of source code. 18fc0db9e5 aaudio: Rearranged source code to match other backends. 2507c1d68b aaudio: Disconnect playing devices if error callback fires. 32a3fc3783 aaudio: Use the callback interface. b49ce86765 audio: Fixed compiler warning on Android NDK. 1c074e8d97 android: Fixed audio device detection. 82ce05ad01 pulseaudio: Be more aggressive with hotplug thread synchronization. 5cbdf1168e androidaudio: Fixed incorrect JNI call (thanks, @madebr!) 660054f3dc include: Correct comment about audio device hotplug events. ab68428a64 aaudio: Fixed for older SDKs and Android releases. 5ff87c6d4a android: Reworked audio backends for SDL3 audio API. 54af687210 testautomation_audio.c: Patched to compile. :/ 5e82090662 testautomation_audio.c: Apparently we aren't updating test code for C99 atm. 7f4488f625 wasapi: More fixes for Clang warnings. 29a0c689c9 wasapi: Patched to compile with Clang. 4aa95c21bc pspaudio: Patched to compile. 9a2a0a1463 ps2audio: Delete errant character that got inserted before previous commit. 2c578bd0d5 qnxaudio: Rewrite for SDL3 audio APIs. 455eef4cd9 audio: Use AtomicAdd for device counts, don't treat as a refcount. 095ea57f94 pspaudio: Patched to compile. d7cf63db67 ps2audio: Patched to compile. 027b9e8787 coreaudio: (maybe) patched to compile on iOS. 4836c2db07 pspaudio: Patched to compile. 86ca412436 n3dsaudio: Patched to compile. 66bcee2ca9 testaudiostreamdynamicresample.c: Fixed MSVC compiler warning. dbf993d358 vitaaudio: patched to compile. 5707e14716 audio: Fix up some things that broke when rebasing the branch against main. 6567285eae SDL_migration.cocci: Fix up SDL_(Pause|Unpause)Audio. 0b6255551e test: Fixed incorrect SDL_OpenAudioDevice call in testautomation. 107fd941cd vitaaudio: Clean up correctly in CloseDevice. 9fa4a6ef87 netbsdaudio: Minor fix. b0d89868c6 n3dsaudio: Updated (but untested!) for SDL3 audio API. ba27176106 vitaaudio: Untested attempt to move Vita audio to SDL3's audio API. 0b58e96d9e wasapi: Patched WinRT to compile. d6b4f48488 visualc: Turn on multiprocessor compilation. c58d95c343 wasapi: Reworked for new SDL3 audio API, other win32 fixes. dc04f85646 audio: whoops, that should be an int. be0dc630b7 audio: Fixed incorrect assertion 77b3fb06ee directsound: First shot at updating for SDL3 audio API. 4399b71715 audio: Generalize how backends can lookup an SDL_AudioDevice. 2fb122fe46 audio: backends now "find" instead of "obtain" devices by handle. c3f5a5fc72 dummyaudio: SDL3ify style 7d65ff86e2 diskaudio: Adjusted for later SDL3 audio API redesign changes. 4ba9c2eade dummyaudio: Configurable delay, other SDL3 API fixes. fb395d3ad7 sndio: Updated to the SDL3 audio API. 1a55282051 dsp: Some minor logic fixes 6bc85577d7 netbsdaudio: Updated for SDL3 audio API. 0f6e59312b netbsdaudio: Removed email address from source code. 51ae78c0af haikuaudio: Updated for SDL3 audio API. fc7ed18ca1 emscriptenaudio: don't forget to finalize the audio thread 4233c41ce2 pulseaudio: Removed unnecessary variable. a0528cd5ed emscriptenaudio: Updated for SDL3 audio API. 79cc29ba35 wave: Don't check if format->channels > INT_MAX, it's a Uint16. 1bfe97c235 pspaudio: Updated for SDL3 audio API. 121a2dce15 audio: Make sure `device->hidden` is NULL after CloseDevice 3d6ba0cafd ps2audio: Removed free of buffer that hasn't been allocated yet. 00ed6f8827 test: Fixed compiler warnings for unused vars. 6f12f68ec9 ps2audio: SDL3ified the style 4993743a02 ps2audio: Renamed `_this` to `device` 74568cdb2b ps2audio: Updated (but untested) for SDL3 audio API. c83b68ef26 jack: renamed `_this` to `device`. 3f4f004794 audio: Remove an assertion that no longer makes sense. 86243b2589 jack: Use ProvidesOwnCallbackThread. 18906a32b8 jack: First shot at updating for SDL3 audio API. a2b488359e dsp: Removed debug logging 6fd71185cd dsp: Updated for new SDL3 audio API. 3482d1215a alsa: Don't ever block in CaptureFromDevice. 65d296ef1a audio: Use SDL_powerof2 instead of reinventing it. 409b544505 alsa: Updated for new SDL3 audio API 0999a090a7 audio: More tweaking of `device->thread_alive` f94ffd6092 audio: Fixed logic error 4deb2970c9 alsa: Renamed `_this` to `device` 0fb9e4baae audio: Remove no-longer-used SupportsNonPow2Samples c653e57768 coreaudio: rewritten for SDL3 audio redesign! 533777eff5 audio: SDL_sysaudio.h comment conversion. 8473e522e0 audio: unify device thread naming. 258bc9efed audio: PlayDevice now passes the buffer, too, for convenience. e518149d14 audio: Fixed locking in SDL_AudioDeviceDisconnected 22afa5735f audio: FreeDeviceHandle should pass the whole device, for convenience. 9e3c5f93e0 coreaudio: Change `_this` to `device` e969160de0 audio: unset a freed variable to NULL 1fc01b0300 audio: Try to definitely have a default device set up. b60a56d368 audio: take first reported device if no default was specified. a8323ebe68 audio: Better handling of ProvidesOwnCallbackThread backends. 1dffb72c1d pipewire: Hooked up default device change notifications. a93fcf2444 audio: fixed flushed stream reporting bytes but not being able to get them. ad6c1781fc pulseaudio: Minor cleanups. cfc8a0d17d pipewire: First shot at moving to the new SDL3 audio interfaces. 13202642a3 aaudio: Fixed capitialization, plus some minor cleanups. 3e9991b535 audio: Make sure we don't write to a NULL pointer. 943351affb pulseaudio: GetDefaultAudioInfo isn't a thing anymore. 11dfc4d737 test: Update testautomation_audio for SDL3 audio API. 29afc2e42b test: Update testresample for SDL3 audio API. 3a02eecced test: Update testsurround for SDL3 audio API. e1c78718d4 test: testaudiocapture is updated for the SDL3 audio API. f48cb716c2 pulseaudio: a couple minor tweaks. dac25fe9eb audio: Seperate audio capture into Wait/Read operations. 3e10c0005d audio: Capture devices should respect logical device pausing. 7e700531c5 audio: Allow SDL_OpenAudioDevice to accept a NULL spec. bb1cbbd33a test: Update testaudioinfo for SDL3 audio API. 883aee32c5 audio: Let default formats differ for output and capture devices. 62cf24eeb9 pulseaudio: Listen for server events in addition to sources and sinks. 924f370bd7 pulseaudio: Fix deadlock in HotplugThread. 5d4e9e5f80 test: Updated testaudiostreamdynamicresample to SDL3 audio API. f883b9fc64 test: Updated testaudiohotplug to SDL3 audio API. 2be5f726d4 audio: Removed debug logging. 323ecce123 docs: Added migration note about SDL_AUDIODEVICEREMOVED. 47b0321ebf test: Removed loopwavequeue.c; obsolete in SDL3. 0e5a1d4f29 pulseaudio: Removed debug logging. f598626e46 test: loopwave shouldn't use an audiostream callback. eee407caf8 docs: migration guide note that SDL_LoadWAV has a different return type. b03c493fc4 test: Updated testmultiaudio to new SDL3 audio API fe1daf6fb5 audio: Mark disconnected default devices as "zombies". cdd2ba81de audio: Fixed adding new physical devices to a double-linked list. db39cbf208 audio: Allow SDL_GetAudioDeviceFormat() to query the default devices. ee10bab3cd audio: An enormous amount of work on managing default devices. c7a44eea83 audio: Fixed logic error. 089cd87cb5 audio: Make sure device count stays correct as hardware disconnects. e50cb72eb6 docs: Note that audio opening doesn't implicitly init SDL now. 97b2f747d0 docs: Corrections to audio section of README-migration.md 464640440f audio: Added SDL_GetAudioStreamBinding. 01f7b53865 audio: Readded (logical) device pausing. fd4c9f4e11 audio: documentation improvements. 4b78b789a7 audio: Switch SDL_audio.c and SDL_audiocvt.c to C99-ish syntax. d96a1db7d7 audio: Opening via a logical device ID should also track default device. b2e020958f audio: Wrap device access in opening of logical devices. 7ee2459927 audio: Check for unlikely failure case in WAV loaded. 3d65a2cefe audio: Made SDL_LoadWAV a real function, not just a macro. 26525f5fd3 audio: Readd SDL_AudioSpec, but just with format/channels/freq fields. e6aaed7d79 include: Audio is not, and has not been, a raw mixing buffer for a long time. 56b1bc2198 audio: SDL_AudioStream now has callbacks for Get and Put operations. 905c4fff5b audio: First shot at the SDL3 audio subsystem redesign! b221b59995 cmake: add SDL_REVISION option 0500fca00c Add missing break d3f2de7f29 fixed typo in prev. patch. 12b35c6a46 test/testnativecocoa.m: fixed deprecation warnings. e24b3e2fa4 cmake: rename SDL_TEST -> SDL_TEST_LIBRARY da5016d336 cmake: use pkg-config + test compile instead of Find module for detecting rpi deec574ff6 cmake: fix SDL_HIDAPI_LIBUSB f2ae00c1ad Sync SDL3 wiki -> header 41a96c8133 doc: document building of SDL tests with CMake 3174d0b970 Sorted controller list 27b8abb056 Add Steam Deck controller mapping to database. 41d436f0fe Use SetWindowPos to show windows when SDL_HINT_WINDOW_ACTIVATE_WHEN_SHOWN is set to avoid activating the parent window when showing a child window 0dc85f3078 Improved the documentation for the gamepad paddle buttons 2fff999a41 Try to create the dummy mouse cursor after video backend initialization d086d9874d Sync SDL3 wiki -> header bce598addd SDL_pixels.c: Fixed compiler warning on Android NDK. ad0c0d3cde Sync SDL3 wiki -> header f8e8dff7ee tests: Fix automated window grab and positioning tests under Wayland/XWayland 4cffbc3644 Add VS code directory to gitignore 666f81bace Add more endian-specific aliases for 32 bit pixelformats 4749df0a63 Just disable the 4214 warning instead of trying to change the structure definition git-subtree-dir: external/sdl/SDL git-subtree-split: ec0042081ea104d5dd0ee291105210e00a4fe3d9
2023-08-12 20:17:29 +02:00
int SDL_AddGamepadMappingsFromRW(SDL_RWops *src, SDL_bool freesrc)
{
const char *platform = SDL_GetPlatform();
int gamepads = 0;
char *buf, *line, *line_end, *tmp, *comma, line_platform[64];
Squashed 'external/sdl/SDL/' changes from b8d91252c6..ec0042081e ec0042081e Add .gitattributes file a5d9db0cd0 cmake: build tests for UWP b7889a7389 winrt: use windowsio in non-libc mode ea8757a748 Make testaudiostreamdynamicresample compatible with emscripten 1a7a74fb2e cmake: build emscripten tests as html page 64d570f027 Add minimal http server for emscripten test apps 8e898c4a21 SDL_test does not parse --samples argument 91cd5478be audio: Fix resampler overflowing input buffer. f290c85b22 testaudiocapture: Make sure we convert captured audio to output format. b75c751dfc rwlock: Make generic implmentations work on single-threaded platforms. 80850af7ce The controller update complete events are no longer disabled by default 3f486224a9 Fixed refresh rate calculation for KMSDRM 342ec51131 Fix overflow when doing SDL_sscanf("%hd", ...) 9129e1d557 Fixed crash when setting the default cursor twice 8e99a4f4f5 Undo variable rename be67f0de10 Fixed crashes related to the default cursor on WinRT and KMSDRM 94b3f78c44 Fix out of bound read of 'has_hat' array 94f48f19b0 Use more specific build destinations when creating an xcframework dabd45997e Back out change supporting multiple names for binding elements efe15588d5 Relabel back paddles as left or right be884f0c95 ci: disable visionos.yml by renaming the file ac094d00f5 ci: add workflow_dispatch event to visionos workflow 9be9e2292b build: Consistently use pathlib APIs in cmake/xxd.py a9f6950657 Fixed deadlock shutting down Android sensors d9f09e77f2 Actually make the sensors magical! 690eae7d22 Implement visionOS support e385d6da0a Fixed build warning 6b93e788fa Improved sensor thread-safety 4ee0e5a984 Fixed thread-safety warnings 12deed91f8 Added information on how to enable thread-safety analysis 5735d2b03b coreaudio: Fixed assertion when device fails/quits mid-iteration. 1022fd6e04 testaudio: the test framework opens an audio device at startup; close it. 0714da37a4 audio: Fix audio stream callback calculations when future buffer has space. 917e036f6f MSVC has __declspec(deprecated) 279ff8909f Changed example code to avoid potential divide by zero 8a1afc9b10 Fixed Android not sending controller event timestamps 463c456b98 Fill the correct member with the joystick ID in SDL_EVENT_JOYSTICK_UPDATE_COMPLETE 55cf1abaa6 test: Don't flag testsurround as suitable for non-interactive use a2d594269c Fixed pixel format compatibility with SDL2 79a190aa23 Fixed setting invalid bpp for FOURCC formats in SDL_GetMasksForPixelFormatEnum() 8fdebdd3e0 Sync SDL3 wiki -> header b903ccf945 SDL_rwops read/write functions return size_t again c03f5b4b69 Fixed rounding up in SDL_PrintFloat 75a020aa6b Only query serial number and firmware versions from Sony PS5 controllers fa189d302e Added the Victrix Pro FS for PS4/PS5 to the controller list 26205b659d Fixed PS4/PS5 touchpad for third party controllers 6af0448af9 include: fixed a typo in SDL_RenderGetMetalCommandEncoder docs. f3cb46b083 SDL_thread.h: do not conflict with sdl2-compat::sdl3_include_wrapper.h 080b1dfbdb Revert "Improved fallback for SDL_COMPILE_TIME_ASSERT() (thanks @icculus!)" 9d453daa23 Improved fallback for SDL_COMPILE_TIME_ASSERT() (thanks @icculus!) 1fb2419882 Removed reference to renamed function e7d56dd0b2 audio: Renamed new API SDL_UnpauseAudioDevice to SDL_ResumeAudioDevice. 2b0c0f5b6b Don't pass NULL to strncmp 778e8185cd Fix size of memcpy in SDL_AudioDeviceFormatChangedAlreadyLocked And add diagnostic that allows to find this kind of issue in clang-tidy 4bb426abad Sync SDL3 wiki -> header 3a752ce650 Reapply "Changed 'freesrc' parameter from int to SDL_bool" to SDL_wave.c 2ba03b4db0 fix build after previous commit. 0026adffd4 apply force_align_arg_pointer attribute to correct version of SDL_RunApp 77446e2029 Unaligned stacks on i686-w64-mingw32 may lead to crashes d3bcc3f057 Fixed build errors when OpenGL isn't enabled 35ad68e126 Sync SDL3 wiki -> header 70323a8350 Add a function to display the system menu for a window be5f66c84e testaudio: Fixed soundboard icon, which had a colorkey issue. c0a88930bf Sync SDL3 wiki -> header 18c59cc969 Merge the SDL3 audio subsystem redesign! 99b0e31788 The Steam Controller D-Pad is only pressed when the button is pressed down 103073d694 Set NSBluetoothAlwaysUsageDescription for testcontroller ca02bb6c8c We don't need testdropfile-Info.plist e063f662e9 Enable the controller update complete events 06bea1eb55 Added a gamepad mapping for the G-Shark GS-GP702 5ca3c50bf0 testaudio: Fix compiler warning. 1b1f02c5aa testaudio: Apparently compilers don't like this possibly being NULL now...? 2de9253b6c test: Added testaudio fb3ab3f113 SDL_video.c: move ngage video before offscreen. 843572d993 Don't mark autorelease keys as virtual 648de4f9b8 Fixed duplicate key press/release events on iOS a8abe612ed Only pass keypresses up the responder chain when text input is active c3288d113e Synchronize on-screen keyboard state with text input active state 5fb92ef2f7 Fixed whitespace f5ea6ae18d Revert "Stop beep when running iOS apps on ARM-based Macs" 546508b9b4 Allow test programs to run at full resolution on iPads 68a4bb01e0 Allocate displays as an array of pointers instead of an array of objects 07578fde3d Fixed crash if a display is enumerated twice a509771a87 fix ios CI workflow after commit e4460e897f 72ce76905a The scheme isn't always the same as the framework name (e.g. xmp_lite vs xmp-lite) e4460e897f By default Xcode expects the framework target name to be the name of the project. ac683773dc Added missing tests to the "All" target 7dd56eaafe Removed unnecessary reference to testoverlay-Info.plist e1c7f524ef Reduce the number of times SDL3 is duplicated in the xcframework script 65538011ca Make Xcode targets more specific efe114c300 Revert "Renamed the xcframework target from "SDL.xcframework" to "xcframework"" 73ed1d21a9 Renamed the xcframework target from "SDL.xcframework" to "xcframework" 76b4d8a0d8 Build the Framework instead of a static library for iOS and tvOS d1bf979160 Removed unnecessary setting from the "Create DMG" target c94cb3a5d8 Simplified the Xcode project to a single Framework target ea60474c65 cmake: don't build SDL3-static Apple framework 8f00d7856d Sync SDL3 wiki -> header d4a867a256 Rename SDL_GetPath to SDL_GetUserFolder 71099149b8 Fall back to Xlib if XRandR isn't available b7f32f74ce Note the removal of the SDL_RENDERER_TARGETTEXTURE flag 0eda582160 testaudiostreamdynamicresample: Load sample.wav correctly. 87eae9a0a1 aaudio: We need a mixbuf on capture devices, too. fb68e84646 wayland: Fix memory leaks b0edd23c00 testsurround: Log available audio output devices at the start. ae3090c387 androidaudio: Move Init/bootstrap code to bottom of source code. 18fc0db9e5 aaudio: Rearranged source code to match other backends. 2507c1d68b aaudio: Disconnect playing devices if error callback fires. 32a3fc3783 aaudio: Use the callback interface. b49ce86765 audio: Fixed compiler warning on Android NDK. 1c074e8d97 android: Fixed audio device detection. 82ce05ad01 pulseaudio: Be more aggressive with hotplug thread synchronization. 5cbdf1168e androidaudio: Fixed incorrect JNI call (thanks, @madebr!) 660054f3dc include: Correct comment about audio device hotplug events. ab68428a64 aaudio: Fixed for older SDKs and Android releases. 5ff87c6d4a android: Reworked audio backends for SDL3 audio API. 54af687210 testautomation_audio.c: Patched to compile. :/ 5e82090662 testautomation_audio.c: Apparently we aren't updating test code for C99 atm. 7f4488f625 wasapi: More fixes for Clang warnings. 29a0c689c9 wasapi: Patched to compile with Clang. 4aa95c21bc pspaudio: Patched to compile. 9a2a0a1463 ps2audio: Delete errant character that got inserted before previous commit. 2c578bd0d5 qnxaudio: Rewrite for SDL3 audio APIs. 455eef4cd9 audio: Use AtomicAdd for device counts, don't treat as a refcount. 095ea57f94 pspaudio: Patched to compile. d7cf63db67 ps2audio: Patched to compile. 027b9e8787 coreaudio: (maybe) patched to compile on iOS. 4836c2db07 pspaudio: Patched to compile. 86ca412436 n3dsaudio: Patched to compile. 66bcee2ca9 testaudiostreamdynamicresample.c: Fixed MSVC compiler warning. dbf993d358 vitaaudio: patched to compile. 5707e14716 audio: Fix up some things that broke when rebasing the branch against main. 6567285eae SDL_migration.cocci: Fix up SDL_(Pause|Unpause)Audio. 0b6255551e test: Fixed incorrect SDL_OpenAudioDevice call in testautomation. 107fd941cd vitaaudio: Clean up correctly in CloseDevice. 9fa4a6ef87 netbsdaudio: Minor fix. b0d89868c6 n3dsaudio: Updated (but untested!) for SDL3 audio API. ba27176106 vitaaudio: Untested attempt to move Vita audio to SDL3's audio API. 0b58e96d9e wasapi: Patched WinRT to compile. d6b4f48488 visualc: Turn on multiprocessor compilation. c58d95c343 wasapi: Reworked for new SDL3 audio API, other win32 fixes. dc04f85646 audio: whoops, that should be an int. be0dc630b7 audio: Fixed incorrect assertion 77b3fb06ee directsound: First shot at updating for SDL3 audio API. 4399b71715 audio: Generalize how backends can lookup an SDL_AudioDevice. 2fb122fe46 audio: backends now "find" instead of "obtain" devices by handle. c3f5a5fc72 dummyaudio: SDL3ify style 7d65ff86e2 diskaudio: Adjusted for later SDL3 audio API redesign changes. 4ba9c2eade dummyaudio: Configurable delay, other SDL3 API fixes. fb395d3ad7 sndio: Updated to the SDL3 audio API. 1a55282051 dsp: Some minor logic fixes 6bc85577d7 netbsdaudio: Updated for SDL3 audio API. 0f6e59312b netbsdaudio: Removed email address from source code. 51ae78c0af haikuaudio: Updated for SDL3 audio API. fc7ed18ca1 emscriptenaudio: don't forget to finalize the audio thread 4233c41ce2 pulseaudio: Removed unnecessary variable. a0528cd5ed emscriptenaudio: Updated for SDL3 audio API. 79cc29ba35 wave: Don't check if format->channels > INT_MAX, it's a Uint16. 1bfe97c235 pspaudio: Updated for SDL3 audio API. 121a2dce15 audio: Make sure `device->hidden` is NULL after CloseDevice 3d6ba0cafd ps2audio: Removed free of buffer that hasn't been allocated yet. 00ed6f8827 test: Fixed compiler warnings for unused vars. 6f12f68ec9 ps2audio: SDL3ified the style 4993743a02 ps2audio: Renamed `_this` to `device` 74568cdb2b ps2audio: Updated (but untested) for SDL3 audio API. c83b68ef26 jack: renamed `_this` to `device`. 3f4f004794 audio: Remove an assertion that no longer makes sense. 86243b2589 jack: Use ProvidesOwnCallbackThread. 18906a32b8 jack: First shot at updating for SDL3 audio API. a2b488359e dsp: Removed debug logging 6fd71185cd dsp: Updated for new SDL3 audio API. 3482d1215a alsa: Don't ever block in CaptureFromDevice. 65d296ef1a audio: Use SDL_powerof2 instead of reinventing it. 409b544505 alsa: Updated for new SDL3 audio API 0999a090a7 audio: More tweaking of `device->thread_alive` f94ffd6092 audio: Fixed logic error 4deb2970c9 alsa: Renamed `_this` to `device` 0fb9e4baae audio: Remove no-longer-used SupportsNonPow2Samples c653e57768 coreaudio: rewritten for SDL3 audio redesign! 533777eff5 audio: SDL_sysaudio.h comment conversion. 8473e522e0 audio: unify device thread naming. 258bc9efed audio: PlayDevice now passes the buffer, too, for convenience. e518149d14 audio: Fixed locking in SDL_AudioDeviceDisconnected 22afa5735f audio: FreeDeviceHandle should pass the whole device, for convenience. 9e3c5f93e0 coreaudio: Change `_this` to `device` e969160de0 audio: unset a freed variable to NULL 1fc01b0300 audio: Try to definitely have a default device set up. b60a56d368 audio: take first reported device if no default was specified. a8323ebe68 audio: Better handling of ProvidesOwnCallbackThread backends. 1dffb72c1d pipewire: Hooked up default device change notifications. a93fcf2444 audio: fixed flushed stream reporting bytes but not being able to get them. ad6c1781fc pulseaudio: Minor cleanups. cfc8a0d17d pipewire: First shot at moving to the new SDL3 audio interfaces. 13202642a3 aaudio: Fixed capitialization, plus some minor cleanups. 3e9991b535 audio: Make sure we don't write to a NULL pointer. 943351affb pulseaudio: GetDefaultAudioInfo isn't a thing anymore. 11dfc4d737 test: Update testautomation_audio for SDL3 audio API. 29afc2e42b test: Update testresample for SDL3 audio API. 3a02eecced test: Update testsurround for SDL3 audio API. e1c78718d4 test: testaudiocapture is updated for the SDL3 audio API. f48cb716c2 pulseaudio: a couple minor tweaks. dac25fe9eb audio: Seperate audio capture into Wait/Read operations. 3e10c0005d audio: Capture devices should respect logical device pausing. 7e700531c5 audio: Allow SDL_OpenAudioDevice to accept a NULL spec. bb1cbbd33a test: Update testaudioinfo for SDL3 audio API. 883aee32c5 audio: Let default formats differ for output and capture devices. 62cf24eeb9 pulseaudio: Listen for server events in addition to sources and sinks. 924f370bd7 pulseaudio: Fix deadlock in HotplugThread. 5d4e9e5f80 test: Updated testaudiostreamdynamicresample to SDL3 audio API. f883b9fc64 test: Updated testaudiohotplug to SDL3 audio API. 2be5f726d4 audio: Removed debug logging. 323ecce123 docs: Added migration note about SDL_AUDIODEVICEREMOVED. 47b0321ebf test: Removed loopwavequeue.c; obsolete in SDL3. 0e5a1d4f29 pulseaudio: Removed debug logging. f598626e46 test: loopwave shouldn't use an audiostream callback. eee407caf8 docs: migration guide note that SDL_LoadWAV has a different return type. b03c493fc4 test: Updated testmultiaudio to new SDL3 audio API fe1daf6fb5 audio: Mark disconnected default devices as "zombies". cdd2ba81de audio: Fixed adding new physical devices to a double-linked list. db39cbf208 audio: Allow SDL_GetAudioDeviceFormat() to query the default devices. ee10bab3cd audio: An enormous amount of work on managing default devices. c7a44eea83 audio: Fixed logic error. 089cd87cb5 audio: Make sure device count stays correct as hardware disconnects. e50cb72eb6 docs: Note that audio opening doesn't implicitly init SDL now. 97b2f747d0 docs: Corrections to audio section of README-migration.md 464640440f audio: Added SDL_GetAudioStreamBinding. 01f7b53865 audio: Readded (logical) device pausing. fd4c9f4e11 audio: documentation improvements. 4b78b789a7 audio: Switch SDL_audio.c and SDL_audiocvt.c to C99-ish syntax. d96a1db7d7 audio: Opening via a logical device ID should also track default device. b2e020958f audio: Wrap device access in opening of logical devices. 7ee2459927 audio: Check for unlikely failure case in WAV loaded. 3d65a2cefe audio: Made SDL_LoadWAV a real function, not just a macro. 26525f5fd3 audio: Readd SDL_AudioSpec, but just with format/channels/freq fields. e6aaed7d79 include: Audio is not, and has not been, a raw mixing buffer for a long time. 56b1bc2198 audio: SDL_AudioStream now has callbacks for Get and Put operations. 905c4fff5b audio: First shot at the SDL3 audio subsystem redesign! b221b59995 cmake: add SDL_REVISION option 0500fca00c Add missing break d3f2de7f29 fixed typo in prev. patch. 12b35c6a46 test/testnativecocoa.m: fixed deprecation warnings. e24b3e2fa4 cmake: rename SDL_TEST -> SDL_TEST_LIBRARY da5016d336 cmake: use pkg-config + test compile instead of Find module for detecting rpi deec574ff6 cmake: fix SDL_HIDAPI_LIBUSB f2ae00c1ad Sync SDL3 wiki -> header 41a96c8133 doc: document building of SDL tests with CMake 3174d0b970 Sorted controller list 27b8abb056 Add Steam Deck controller mapping to database. 41d436f0fe Use SetWindowPos to show windows when SDL_HINT_WINDOW_ACTIVATE_WHEN_SHOWN is set to avoid activating the parent window when showing a child window 0dc85f3078 Improved the documentation for the gamepad paddle buttons 2fff999a41 Try to create the dummy mouse cursor after video backend initialization d086d9874d Sync SDL3 wiki -> header bce598addd SDL_pixels.c: Fixed compiler warning on Android NDK. ad0c0d3cde Sync SDL3 wiki -> header f8e8dff7ee tests: Fix automated window grab and positioning tests under Wayland/XWayland 4cffbc3644 Add VS code directory to gitignore 666f81bace Add more endian-specific aliases for 32 bit pixelformats 4749df0a63 Just disable the 4214 warning instead of trying to change the structure definition git-subtree-dir: external/sdl/SDL git-subtree-split: ec0042081ea104d5dd0ee291105210e00a4fe3d9
2023-08-12 20:17:29 +02:00
size_t db_size;
size_t platform_len;
Squashed 'external/sdl/SDL/' changes from b8d91252c6..ec0042081e ec0042081e Add .gitattributes file a5d9db0cd0 cmake: build tests for UWP b7889a7389 winrt: use windowsio in non-libc mode ea8757a748 Make testaudiostreamdynamicresample compatible with emscripten 1a7a74fb2e cmake: build emscripten tests as html page 64d570f027 Add minimal http server for emscripten test apps 8e898c4a21 SDL_test does not parse --samples argument 91cd5478be audio: Fix resampler overflowing input buffer. f290c85b22 testaudiocapture: Make sure we convert captured audio to output format. b75c751dfc rwlock: Make generic implmentations work on single-threaded platforms. 80850af7ce The controller update complete events are no longer disabled by default 3f486224a9 Fixed refresh rate calculation for KMSDRM 342ec51131 Fix overflow when doing SDL_sscanf("%hd", ...) 9129e1d557 Fixed crash when setting the default cursor twice 8e99a4f4f5 Undo variable rename be67f0de10 Fixed crashes related to the default cursor on WinRT and KMSDRM 94b3f78c44 Fix out of bound read of 'has_hat' array 94f48f19b0 Use more specific build destinations when creating an xcframework dabd45997e Back out change supporting multiple names for binding elements efe15588d5 Relabel back paddles as left or right be884f0c95 ci: disable visionos.yml by renaming the file ac094d00f5 ci: add workflow_dispatch event to visionos workflow 9be9e2292b build: Consistently use pathlib APIs in cmake/xxd.py a9f6950657 Fixed deadlock shutting down Android sensors d9f09e77f2 Actually make the sensors magical! 690eae7d22 Implement visionOS support e385d6da0a Fixed build warning 6b93e788fa Improved sensor thread-safety 4ee0e5a984 Fixed thread-safety warnings 12deed91f8 Added information on how to enable thread-safety analysis 5735d2b03b coreaudio: Fixed assertion when device fails/quits mid-iteration. 1022fd6e04 testaudio: the test framework opens an audio device at startup; close it. 0714da37a4 audio: Fix audio stream callback calculations when future buffer has space. 917e036f6f MSVC has __declspec(deprecated) 279ff8909f Changed example code to avoid potential divide by zero 8a1afc9b10 Fixed Android not sending controller event timestamps 463c456b98 Fill the correct member with the joystick ID in SDL_EVENT_JOYSTICK_UPDATE_COMPLETE 55cf1abaa6 test: Don't flag testsurround as suitable for non-interactive use a2d594269c Fixed pixel format compatibility with SDL2 79a190aa23 Fixed setting invalid bpp for FOURCC formats in SDL_GetMasksForPixelFormatEnum() 8fdebdd3e0 Sync SDL3 wiki -> header b903ccf945 SDL_rwops read/write functions return size_t again c03f5b4b69 Fixed rounding up in SDL_PrintFloat 75a020aa6b Only query serial number and firmware versions from Sony PS5 controllers fa189d302e Added the Victrix Pro FS for PS4/PS5 to the controller list 26205b659d Fixed PS4/PS5 touchpad for third party controllers 6af0448af9 include: fixed a typo in SDL_RenderGetMetalCommandEncoder docs. f3cb46b083 SDL_thread.h: do not conflict with sdl2-compat::sdl3_include_wrapper.h 080b1dfbdb Revert "Improved fallback for SDL_COMPILE_TIME_ASSERT() (thanks @icculus!)" 9d453daa23 Improved fallback for SDL_COMPILE_TIME_ASSERT() (thanks @icculus!) 1fb2419882 Removed reference to renamed function e7d56dd0b2 audio: Renamed new API SDL_UnpauseAudioDevice to SDL_ResumeAudioDevice. 2b0c0f5b6b Don't pass NULL to strncmp 778e8185cd Fix size of memcpy in SDL_AudioDeviceFormatChangedAlreadyLocked And add diagnostic that allows to find this kind of issue in clang-tidy 4bb426abad Sync SDL3 wiki -> header 3a752ce650 Reapply "Changed 'freesrc' parameter from int to SDL_bool" to SDL_wave.c 2ba03b4db0 fix build after previous commit. 0026adffd4 apply force_align_arg_pointer attribute to correct version of SDL_RunApp 77446e2029 Unaligned stacks on i686-w64-mingw32 may lead to crashes d3bcc3f057 Fixed build errors when OpenGL isn't enabled 35ad68e126 Sync SDL3 wiki -> header 70323a8350 Add a function to display the system menu for a window be5f66c84e testaudio: Fixed soundboard icon, which had a colorkey issue. c0a88930bf Sync SDL3 wiki -> header 18c59cc969 Merge the SDL3 audio subsystem redesign! 99b0e31788 The Steam Controller D-Pad is only pressed when the button is pressed down 103073d694 Set NSBluetoothAlwaysUsageDescription for testcontroller ca02bb6c8c We don't need testdropfile-Info.plist e063f662e9 Enable the controller update complete events 06bea1eb55 Added a gamepad mapping for the G-Shark GS-GP702 5ca3c50bf0 testaudio: Fix compiler warning. 1b1f02c5aa testaudio: Apparently compilers don't like this possibly being NULL now...? 2de9253b6c test: Added testaudio fb3ab3f113 SDL_video.c: move ngage video before offscreen. 843572d993 Don't mark autorelease keys as virtual 648de4f9b8 Fixed duplicate key press/release events on iOS a8abe612ed Only pass keypresses up the responder chain when text input is active c3288d113e Synchronize on-screen keyboard state with text input active state 5fb92ef2f7 Fixed whitespace f5ea6ae18d Revert "Stop beep when running iOS apps on ARM-based Macs" 546508b9b4 Allow test programs to run at full resolution on iPads 68a4bb01e0 Allocate displays as an array of pointers instead of an array of objects 07578fde3d Fixed crash if a display is enumerated twice a509771a87 fix ios CI workflow after commit e4460e897f 72ce76905a The scheme isn't always the same as the framework name (e.g. xmp_lite vs xmp-lite) e4460e897f By default Xcode expects the framework target name to be the name of the project. ac683773dc Added missing tests to the "All" target 7dd56eaafe Removed unnecessary reference to testoverlay-Info.plist e1c7f524ef Reduce the number of times SDL3 is duplicated in the xcframework script 65538011ca Make Xcode targets more specific efe114c300 Revert "Renamed the xcframework target from "SDL.xcframework" to "xcframework"" 73ed1d21a9 Renamed the xcframework target from "SDL.xcframework" to "xcframework" 76b4d8a0d8 Build the Framework instead of a static library for iOS and tvOS d1bf979160 Removed unnecessary setting from the "Create DMG" target c94cb3a5d8 Simplified the Xcode project to a single Framework target ea60474c65 cmake: don't build SDL3-static Apple framework 8f00d7856d Sync SDL3 wiki -> header d4a867a256 Rename SDL_GetPath to SDL_GetUserFolder 71099149b8 Fall back to Xlib if XRandR isn't available b7f32f74ce Note the removal of the SDL_RENDERER_TARGETTEXTURE flag 0eda582160 testaudiostreamdynamicresample: Load sample.wav correctly. 87eae9a0a1 aaudio: We need a mixbuf on capture devices, too. fb68e84646 wayland: Fix memory leaks b0edd23c00 testsurround: Log available audio output devices at the start. ae3090c387 androidaudio: Move Init/bootstrap code to bottom of source code. 18fc0db9e5 aaudio: Rearranged source code to match other backends. 2507c1d68b aaudio: Disconnect playing devices if error callback fires. 32a3fc3783 aaudio: Use the callback interface. b49ce86765 audio: Fixed compiler warning on Android NDK. 1c074e8d97 android: Fixed audio device detection. 82ce05ad01 pulseaudio: Be more aggressive with hotplug thread synchronization. 5cbdf1168e androidaudio: Fixed incorrect JNI call (thanks, @madebr!) 660054f3dc include: Correct comment about audio device hotplug events. ab68428a64 aaudio: Fixed for older SDKs and Android releases. 5ff87c6d4a android: Reworked audio backends for SDL3 audio API. 54af687210 testautomation_audio.c: Patched to compile. :/ 5e82090662 testautomation_audio.c: Apparently we aren't updating test code for C99 atm. 7f4488f625 wasapi: More fixes for Clang warnings. 29a0c689c9 wasapi: Patched to compile with Clang. 4aa95c21bc pspaudio: Patched to compile. 9a2a0a1463 ps2audio: Delete errant character that got inserted before previous commit. 2c578bd0d5 qnxaudio: Rewrite for SDL3 audio APIs. 455eef4cd9 audio: Use AtomicAdd for device counts, don't treat as a refcount. 095ea57f94 pspaudio: Patched to compile. d7cf63db67 ps2audio: Patched to compile. 027b9e8787 coreaudio: (maybe) patched to compile on iOS. 4836c2db07 pspaudio: Patched to compile. 86ca412436 n3dsaudio: Patched to compile. 66bcee2ca9 testaudiostreamdynamicresample.c: Fixed MSVC compiler warning. dbf993d358 vitaaudio: patched to compile. 5707e14716 audio: Fix up some things that broke when rebasing the branch against main. 6567285eae SDL_migration.cocci: Fix up SDL_(Pause|Unpause)Audio. 0b6255551e test: Fixed incorrect SDL_OpenAudioDevice call in testautomation. 107fd941cd vitaaudio: Clean up correctly in CloseDevice. 9fa4a6ef87 netbsdaudio: Minor fix. b0d89868c6 n3dsaudio: Updated (but untested!) for SDL3 audio API. ba27176106 vitaaudio: Untested attempt to move Vita audio to SDL3's audio API. 0b58e96d9e wasapi: Patched WinRT to compile. d6b4f48488 visualc: Turn on multiprocessor compilation. c58d95c343 wasapi: Reworked for new SDL3 audio API, other win32 fixes. dc04f85646 audio: whoops, that should be an int. be0dc630b7 audio: Fixed incorrect assertion 77b3fb06ee directsound: First shot at updating for SDL3 audio API. 4399b71715 audio: Generalize how backends can lookup an SDL_AudioDevice. 2fb122fe46 audio: backends now "find" instead of "obtain" devices by handle. c3f5a5fc72 dummyaudio: SDL3ify style 7d65ff86e2 diskaudio: Adjusted for later SDL3 audio API redesign changes. 4ba9c2eade dummyaudio: Configurable delay, other SDL3 API fixes. fb395d3ad7 sndio: Updated to the SDL3 audio API. 1a55282051 dsp: Some minor logic fixes 6bc85577d7 netbsdaudio: Updated for SDL3 audio API. 0f6e59312b netbsdaudio: Removed email address from source code. 51ae78c0af haikuaudio: Updated for SDL3 audio API. fc7ed18ca1 emscriptenaudio: don't forget to finalize the audio thread 4233c41ce2 pulseaudio: Removed unnecessary variable. a0528cd5ed emscriptenaudio: Updated for SDL3 audio API. 79cc29ba35 wave: Don't check if format->channels > INT_MAX, it's a Uint16. 1bfe97c235 pspaudio: Updated for SDL3 audio API. 121a2dce15 audio: Make sure `device->hidden` is NULL after CloseDevice 3d6ba0cafd ps2audio: Removed free of buffer that hasn't been allocated yet. 00ed6f8827 test: Fixed compiler warnings for unused vars. 6f12f68ec9 ps2audio: SDL3ified the style 4993743a02 ps2audio: Renamed `_this` to `device` 74568cdb2b ps2audio: Updated (but untested) for SDL3 audio API. c83b68ef26 jack: renamed `_this` to `device`. 3f4f004794 audio: Remove an assertion that no longer makes sense. 86243b2589 jack: Use ProvidesOwnCallbackThread. 18906a32b8 jack: First shot at updating for SDL3 audio API. a2b488359e dsp: Removed debug logging 6fd71185cd dsp: Updated for new SDL3 audio API. 3482d1215a alsa: Don't ever block in CaptureFromDevice. 65d296ef1a audio: Use SDL_powerof2 instead of reinventing it. 409b544505 alsa: Updated for new SDL3 audio API 0999a090a7 audio: More tweaking of `device->thread_alive` f94ffd6092 audio: Fixed logic error 4deb2970c9 alsa: Renamed `_this` to `device` 0fb9e4baae audio: Remove no-longer-used SupportsNonPow2Samples c653e57768 coreaudio: rewritten for SDL3 audio redesign! 533777eff5 audio: SDL_sysaudio.h comment conversion. 8473e522e0 audio: unify device thread naming. 258bc9efed audio: PlayDevice now passes the buffer, too, for convenience. e518149d14 audio: Fixed locking in SDL_AudioDeviceDisconnected 22afa5735f audio: FreeDeviceHandle should pass the whole device, for convenience. 9e3c5f93e0 coreaudio: Change `_this` to `device` e969160de0 audio: unset a freed variable to NULL 1fc01b0300 audio: Try to definitely have a default device set up. b60a56d368 audio: take first reported device if no default was specified. a8323ebe68 audio: Better handling of ProvidesOwnCallbackThread backends. 1dffb72c1d pipewire: Hooked up default device change notifications. a93fcf2444 audio: fixed flushed stream reporting bytes but not being able to get them. ad6c1781fc pulseaudio: Minor cleanups. cfc8a0d17d pipewire: First shot at moving to the new SDL3 audio interfaces. 13202642a3 aaudio: Fixed capitialization, plus some minor cleanups. 3e9991b535 audio: Make sure we don't write to a NULL pointer. 943351affb pulseaudio: GetDefaultAudioInfo isn't a thing anymore. 11dfc4d737 test: Update testautomation_audio for SDL3 audio API. 29afc2e42b test: Update testresample for SDL3 audio API. 3a02eecced test: Update testsurround for SDL3 audio API. e1c78718d4 test: testaudiocapture is updated for the SDL3 audio API. f48cb716c2 pulseaudio: a couple minor tweaks. dac25fe9eb audio: Seperate audio capture into Wait/Read operations. 3e10c0005d audio: Capture devices should respect logical device pausing. 7e700531c5 audio: Allow SDL_OpenAudioDevice to accept a NULL spec. bb1cbbd33a test: Update testaudioinfo for SDL3 audio API. 883aee32c5 audio: Let default formats differ for output and capture devices. 62cf24eeb9 pulseaudio: Listen for server events in addition to sources and sinks. 924f370bd7 pulseaudio: Fix deadlock in HotplugThread. 5d4e9e5f80 test: Updated testaudiostreamdynamicresample to SDL3 audio API. f883b9fc64 test: Updated testaudiohotplug to SDL3 audio API. 2be5f726d4 audio: Removed debug logging. 323ecce123 docs: Added migration note about SDL_AUDIODEVICEREMOVED. 47b0321ebf test: Removed loopwavequeue.c; obsolete in SDL3. 0e5a1d4f29 pulseaudio: Removed debug logging. f598626e46 test: loopwave shouldn't use an audiostream callback. eee407caf8 docs: migration guide note that SDL_LoadWAV has a different return type. b03c493fc4 test: Updated testmultiaudio to new SDL3 audio API fe1daf6fb5 audio: Mark disconnected default devices as "zombies". cdd2ba81de audio: Fixed adding new physical devices to a double-linked list. db39cbf208 audio: Allow SDL_GetAudioDeviceFormat() to query the default devices. ee10bab3cd audio: An enormous amount of work on managing default devices. c7a44eea83 audio: Fixed logic error. 089cd87cb5 audio: Make sure device count stays correct as hardware disconnects. e50cb72eb6 docs: Note that audio opening doesn't implicitly init SDL now. 97b2f747d0 docs: Corrections to audio section of README-migration.md 464640440f audio: Added SDL_GetAudioStreamBinding. 01f7b53865 audio: Readded (logical) device pausing. fd4c9f4e11 audio: documentation improvements. 4b78b789a7 audio: Switch SDL_audio.c and SDL_audiocvt.c to C99-ish syntax. d96a1db7d7 audio: Opening via a logical device ID should also track default device. b2e020958f audio: Wrap device access in opening of logical devices. 7ee2459927 audio: Check for unlikely failure case in WAV loaded. 3d65a2cefe audio: Made SDL_LoadWAV a real function, not just a macro. 26525f5fd3 audio: Readd SDL_AudioSpec, but just with format/channels/freq fields. e6aaed7d79 include: Audio is not, and has not been, a raw mixing buffer for a long time. 56b1bc2198 audio: SDL_AudioStream now has callbacks for Get and Put operations. 905c4fff5b audio: First shot at the SDL3 audio subsystem redesign! b221b59995 cmake: add SDL_REVISION option 0500fca00c Add missing break d3f2de7f29 fixed typo in prev. patch. 12b35c6a46 test/testnativecocoa.m: fixed deprecation warnings. e24b3e2fa4 cmake: rename SDL_TEST -> SDL_TEST_LIBRARY da5016d336 cmake: use pkg-config + test compile instead of Find module for detecting rpi deec574ff6 cmake: fix SDL_HIDAPI_LIBUSB f2ae00c1ad Sync SDL3 wiki -> header 41a96c8133 doc: document building of SDL tests with CMake 3174d0b970 Sorted controller list 27b8abb056 Add Steam Deck controller mapping to database. 41d436f0fe Use SetWindowPos to show windows when SDL_HINT_WINDOW_ACTIVATE_WHEN_SHOWN is set to avoid activating the parent window when showing a child window 0dc85f3078 Improved the documentation for the gamepad paddle buttons 2fff999a41 Try to create the dummy mouse cursor after video backend initialization d086d9874d Sync SDL3 wiki -> header bce598addd SDL_pixels.c: Fixed compiler warning on Android NDK. ad0c0d3cde Sync SDL3 wiki -> header f8e8dff7ee tests: Fix automated window grab and positioning tests under Wayland/XWayland 4cffbc3644 Add VS code directory to gitignore 666f81bace Add more endian-specific aliases for 32 bit pixelformats 4749df0a63 Just disable the 4214 warning instead of trying to change the structure definition git-subtree-dir: external/sdl/SDL git-subtree-split: ec0042081ea104d5dd0ee291105210e00a4fe3d9
2023-08-12 20:17:29 +02:00
buf = (char *)SDL_LoadFile_RW(src, &db_size, freesrc);
if (buf == NULL) {
return SDL_SetError("Could not allocate space to read DB into memory");
}
line = buf;
PushMappingChangeTracking();
while (line < buf + db_size) {
line_end = SDL_strchr(line, '\n');
if (line_end != NULL) {
*line_end = '\0';
} else {
line_end = buf + db_size;
}
/* Extract and verify the platform */
tmp = SDL_strstr(line, SDL_GAMEPAD_PLATFORM_FIELD);
if (tmp != NULL) {
tmp += SDL_GAMEPAD_PLATFORM_FIELD_SIZE;
comma = SDL_strchr(tmp, ',');
if (comma != NULL) {
platform_len = comma - tmp + 1;
if (platform_len + 1 < SDL_arraysize(line_platform)) {
SDL_strlcpy(line_platform, tmp, platform_len);
if (SDL_strncasecmp(line_platform, platform, platform_len) == 0 &&
SDL_AddGamepadMapping(line) > 0) {
gamepads++;
}
}
}
}
line = line_end + 1;
}
PopMappingChangeTracking();
SDL_free(buf);
return gamepads;
}
int SDL_AddGamepadMappingsFromFile(const char *file)
{
return SDL_AddGamepadMappingsFromRW(SDL_RWFromFile(file, "rb"), 1);
}
int SDL_ReloadGamepadMappings(void)
{
SDL_Gamepad *gamepad;
SDL_LockJoysticks();
PushMappingChangeTracking();
for (gamepad = SDL_gamepads; gamepad; gamepad = gamepad->next) {
AddMappingChangeTracking(gamepad->mapping);
}
SDL_QuitGamepadMappings();
SDL_InitGamepadMappings();
PopMappingChangeTracking();
SDL_UnlockJoysticks();
return 0;
}
/*
* Add or update an entry into the Mappings Database with a priority
*/
static int SDL_PrivateAddGamepadMapping(const char *mappingString, SDL_GamepadMappingPriority priority)
{
char *pchGUID;
SDL_JoystickGUID jGUID;
SDL_bool is_default_mapping = SDL_FALSE;
SDL_bool is_xinput_mapping = SDL_FALSE;
SDL_bool existing = SDL_FALSE;
GamepadMapping_t *pGamepadMapping;
SDL_AssertJoysticksLocked();
if (mappingString == NULL) {
return SDL_InvalidParamError("mappingString");
}
{ /* Extract and verify the hint field */
const char *tmp;
tmp = SDL_strstr(mappingString, SDL_GAMEPAD_HINT_FIELD);
if (tmp != NULL) {
SDL_bool default_value, value, negate;
int len;
char hint[128];
tmp += SDL_GAMEPAD_HINT_FIELD_SIZE;
if (*tmp == '!') {
negate = SDL_TRUE;
++tmp;
} else {
negate = SDL_FALSE;
}
len = 0;
while (*tmp && *tmp != ',' && *tmp != ':' && len < (sizeof(hint) - 1)) {
hint[len++] = *tmp++;
}
hint[len] = '\0';
if (tmp[0] == ':' && tmp[1] == '=') {
tmp += 2;
default_value = SDL_atoi(tmp);
} else {
default_value = SDL_FALSE;
}
value = SDL_GetHintBoolean(hint, default_value);
if (negate) {
value = !value;
}
if (!value) {
return 0;
}
}
}
#ifdef ANDROID
{ /* Extract and verify the SDK version */
const char *tmp;
tmp = SDL_strstr(mappingString, SDL_GAMEPAD_SDKGE_FIELD);
if (tmp != NULL) {
tmp += SDL_GAMEPAD_SDKGE_FIELD_SIZE;
if (!(SDL_GetAndroidSDKVersion() >= SDL_atoi(tmp))) {
return SDL_SetError("SDK version %d < minimum version %d", SDL_GetAndroidSDKVersion(), SDL_atoi(tmp));
}
}
tmp = SDL_strstr(mappingString, SDL_GAMEPAD_SDKLE_FIELD);
if (tmp != NULL) {
tmp += SDL_GAMEPAD_SDKLE_FIELD_SIZE;
if (!(SDL_GetAndroidSDKVersion() <= SDL_atoi(tmp))) {
return SDL_SetError("SDK version %d > maximum version %d", SDL_GetAndroidSDKVersion(), SDL_atoi(tmp));
}
}
}
#endif
pchGUID = SDL_PrivateGetGamepadGUIDFromMappingString(mappingString);
if (pchGUID == NULL) {
return SDL_SetError("Couldn't parse GUID from %s", mappingString);
}
if (!SDL_strcasecmp(pchGUID, "default")) {
is_default_mapping = SDL_TRUE;
} else if (!SDL_strcasecmp(pchGUID, "xinput")) {
is_xinput_mapping = SDL_TRUE;
}
jGUID = SDL_GetJoystickGUIDFromString(pchGUID);
SDL_free(pchGUID);
pGamepadMapping = SDL_PrivateAddMappingForGUID(jGUID, mappingString, &existing, priority);
if (pGamepadMapping == NULL) {
return -1;
}
if (existing) {
return 0;
} else {
if (is_default_mapping) {
s_pDefaultMapping = pGamepadMapping;
} else if (is_xinput_mapping) {
s_pXInputMapping = pGamepadMapping;
}
return 1;
}
}
/*
* Add or update an entry into the Mappings Database
*/
int SDL_AddGamepadMapping(const char *mapping)
{
int retval;
SDL_LockJoysticks();
{
retval = SDL_PrivateAddGamepadMapping(mapping, SDL_GAMEPAD_MAPPING_PRIORITY_API);
}
SDL_UnlockJoysticks();
return retval;
}
/*
* Get the number of mappings installed
*/
int SDL_GetNumGamepadMappings(void)
{
int num_mappings = 0;
SDL_LockJoysticks();
{
GamepadMapping_t *mapping;
for (mapping = s_pSupportedGamepads; mapping; mapping = mapping->next) {
if (SDL_memcmp(&mapping->guid, &s_zeroGUID, sizeof(mapping->guid)) == 0) {
continue;
}
++num_mappings;
}
}
SDL_UnlockJoysticks();
return num_mappings;
}
/*
* Create a mapping string for a mapping
*/
static char *CreateMappingString(GamepadMapping_t *mapping, SDL_JoystickGUID guid)
{
char *pMappingString, *pPlatformString;
char pchGUID[33];
size_t needed;
SDL_bool need_platform = SDL_FALSE;
const char *platform = NULL;
SDL_AssertJoysticksLocked();
SDL_GetJoystickGUIDString(guid, pchGUID, sizeof(pchGUID));
/* allocate enough memory for GUID + ',' + name + ',' + mapping + \0 */
needed = SDL_strlen(pchGUID) + 1 + SDL_strlen(mapping->name) + 1 + SDL_strlen(mapping->mapping) + 1;
if (!SDL_strstr(mapping->mapping, SDL_GAMEPAD_PLATFORM_FIELD)) {
/* add memory for ',' + platform:PLATFORM */
need_platform = SDL_TRUE;
if (mapping->mapping[SDL_strlen(mapping->mapping) - 1] != ',') {
needed += 1;
}
platform = SDL_GetPlatform();
needed += SDL_GAMEPAD_PLATFORM_FIELD_SIZE + SDL_strlen(platform) + 1;
}
pMappingString = SDL_malloc(needed);
if (pMappingString == NULL) {
SDL_OutOfMemory();
return NULL;
}
(void)SDL_snprintf(pMappingString, needed, "%s,%s,%s", pchGUID, mapping->name, mapping->mapping);
if (need_platform) {
if (mapping->mapping[SDL_strlen(mapping->mapping) - 1] != ',') {
SDL_strlcat(pMappingString, ",", needed);
}
SDL_strlcat(pMappingString, SDL_GAMEPAD_PLATFORM_FIELD, needed);
SDL_strlcat(pMappingString, platform, needed);
SDL_strlcat(pMappingString, ",", needed);
}
/* Make sure multiple platform strings haven't made their way into the mapping */
pPlatformString = SDL_strstr(pMappingString, SDL_GAMEPAD_PLATFORM_FIELD);
if (pPlatformString) {
pPlatformString = SDL_strstr(pPlatformString + 1, SDL_GAMEPAD_PLATFORM_FIELD);
if (pPlatformString) {
*pPlatformString = '\0';
}
}
return pMappingString;
}
/*
* Get the mapping at a particular index.
*/
char *SDL_GetGamepadMappingForIndex(int mapping_index)
{
char *retval = NULL;
SDL_LockJoysticks();
{
GamepadMapping_t *mapping;
for (mapping = s_pSupportedGamepads; mapping; mapping = mapping->next) {
if (SDL_memcmp(&mapping->guid, &s_zeroGUID, sizeof(mapping->guid)) == 0) {
continue;
}
if (mapping_index == 0) {
retval = CreateMappingString(mapping, mapping->guid);
break;
}
--mapping_index;
}
}
SDL_UnlockJoysticks();
if (retval == NULL) {
SDL_SetError("Mapping not available");
}
return retval;
}
/*
* Get the mapping string for this GUID
*/
char *SDL_GetGamepadMappingForGUID(SDL_JoystickGUID guid)
{
char *retval;
SDL_LockJoysticks();
{
GamepadMapping_t *mapping = SDL_PrivateGetGamepadMappingForGUID(guid, SDL_FALSE);
if (mapping) {
retval = CreateMappingString(mapping, guid);
} else {
SDL_SetError("Mapping not available");
retval = NULL;
}
}
SDL_UnlockJoysticks();
return retval;
}
/*
* Get the mapping string for this device
*/
char *SDL_GetGamepadMapping(SDL_Gamepad *gamepad)
{
char *retval;
SDL_LockJoysticks();
{
CHECK_GAMEPAD_MAGIC(gamepad, NULL);
retval = CreateMappingString(gamepad->mapping, gamepad->joystick->guid);
}
SDL_UnlockJoysticks();
return retval;
}
/*
* Set the mapping string for this device
*/
int SDL_SetGamepadMapping(SDL_JoystickID instance_id, const char *mapping)
{
SDL_JoystickGUID guid = SDL_GetJoystickInstanceGUID(instance_id);
int retval = -1;
if (SDL_memcmp(&guid, &s_zeroGUID, sizeof(guid)) == 0) {
return SDL_InvalidParamError("instance_id");
}
if (!mapping) {
mapping = "*,*,";
}
SDL_LockJoysticks();
{
if (SDL_PrivateAddMappingForGUID(guid, mapping, NULL, SDL_GAMEPAD_MAPPING_PRIORITY_API)) {
retval = 0;
}
}
SDL_UnlockJoysticks();
return retval;
}
static void SDL_LoadGamepadHints(void)
{
const char *hint = SDL_GetHint(SDL_HINT_GAMECONTROLLERCONFIG);
if (hint && hint[0]) {
char *pTempMappings = SDL_strdup(hint);
char *pUserMappings = pTempMappings;
PushMappingChangeTracking();
while (pUserMappings) {
char *pchNewLine = NULL;
pchNewLine = SDL_strchr(pUserMappings, '\n');
if (pchNewLine) {
*pchNewLine = '\0';
}
SDL_PrivateAddGamepadMapping(pUserMappings, SDL_GAMEPAD_MAPPING_PRIORITY_USER);
if (pchNewLine) {
pUserMappings = pchNewLine + 1;
} else {
pUserMappings = NULL;
}
}
PopMappingChangeTracking();
SDL_free(pTempMappings);
}
}
/*
* Fill the given buffer with the expected gamepad mapping filepath.
* Usually this will just be SDL_HINT_GAMECONTROLLERCONFIG_FILE, but for
* Android, we want to get the internal storage path.
*/
static SDL_bool SDL_GetGamepadMappingFilePath(char *path, size_t size)
{
const char *hint = SDL_GetHint(SDL_HINT_GAMECONTROLLERCONFIG_FILE);
if (hint && *hint) {
return SDL_strlcpy(path, hint, size) < size;
}
#ifdef __ANDROID__
return SDL_snprintf(path, size, "%s/gamepad_map.txt", SDL_AndroidGetInternalStoragePath()) < size;
#else
return SDL_FALSE;
#endif
}
/*
* Initialize the gamepad system, mostly load our DB of gamepad config mappings
*/
int SDL_InitGamepadMappings(void)
{
char szGamepadMapPath[1024];
int i = 0;
const char *pMappingString = NULL;
SDL_AssertJoysticksLocked();
PushMappingChangeTracking();
pMappingString = s_GamepadMappings[i];
while (pMappingString) {
SDL_PrivateAddGamepadMapping(pMappingString, SDL_GAMEPAD_MAPPING_PRIORITY_DEFAULT);
i++;
pMappingString = s_GamepadMappings[i];
}
if (SDL_GetGamepadMappingFilePath(szGamepadMapPath, sizeof(szGamepadMapPath))) {
SDL_AddGamepadMappingsFromFile(szGamepadMapPath);
}
/* load in any user supplied config */
SDL_LoadGamepadHints();
SDL_AddHintCallback(SDL_HINT_GAMECONTROLLER_IGNORE_DEVICES,
SDL_GamepadIgnoreDevicesChanged, NULL);
SDL_AddHintCallback(SDL_HINT_GAMECONTROLLER_IGNORE_DEVICES_EXCEPT,
SDL_GamepadIgnoreDevicesExceptChanged, NULL);
PopMappingChangeTracking();
return 0;
}
int SDL_InitGamepads(void)
{
int i;
SDL_JoystickID *joysticks;
SDL_gamepads_initialized = SDL_TRUE;
/* Watch for joystick events and fire gamepad ones if needed */
SDL_AddEventWatch(SDL_GamepadEventWatcher, NULL);
/* Send added events for gamepads currently attached */
joysticks = SDL_GetJoysticks(NULL);
if (joysticks) {
for (i = 0; joysticks[i]; ++i) {
if (SDL_IsGamepad(joysticks[i])) {
SDL_PrivateGamepadAdded(joysticks[i]);
}
}
SDL_free(joysticks);
}
return 0;
}
SDL_JoystickID *SDL_GetGamepads(int *count)
{
int num_joysticks = 0;
int num_gamepads = 0;
SDL_JoystickID *joysticks = SDL_GetJoysticks(&num_joysticks);
if (joysticks) {
int i;
for (i = num_joysticks - 1; i >= 0; --i) {
if (SDL_IsGamepad(joysticks[i])) {
++num_gamepads;
} else {
SDL_memmove(&joysticks[i], &joysticks[i+1], (num_gamepads + 1) * sizeof(joysticks[i]));
}
}
}
if (count) {
*count = num_gamepads;
}
return joysticks;
}
const char *SDL_GetGamepadInstanceName(SDL_JoystickID instance_id)
{
const char *retval = NULL;
SDL_LockJoysticks();
{
GamepadMapping_t *mapping = SDL_PrivateGetGamepadMapping(instance_id);
if (mapping != NULL) {
if (SDL_strcmp(mapping->name, "*") == 0) {
retval = SDL_GetJoystickInstanceName(instance_id);
} else {
retval = mapping->name;
}
}
}
SDL_UnlockJoysticks();
return retval;
}
const char *SDL_GetGamepadInstancePath(SDL_JoystickID instance_id)
{
return SDL_GetJoystickInstancePath(instance_id);
}
int SDL_GetGamepadInstancePlayerIndex(SDL_JoystickID instance_id)
{
return SDL_GetJoystickInstancePlayerIndex(instance_id);
}
SDL_JoystickGUID SDL_GetGamepadInstanceGUID(SDL_JoystickID instance_id)
{
return SDL_GetJoystickInstanceGUID(instance_id);
}
Uint16 SDL_GetGamepadInstanceVendor(SDL_JoystickID instance_id)
{
return SDL_GetJoystickInstanceVendor(instance_id);
}
Uint16 SDL_GetGamepadInstanceProduct(SDL_JoystickID instance_id)
{
return SDL_GetJoystickInstanceProduct(instance_id);
}
Uint16 SDL_GetGamepadInstanceProductVersion(SDL_JoystickID instance_id)
{
return SDL_GetJoystickInstanceProductVersion(instance_id);
}
SDL_GamepadType SDL_GetGamepadInstanceType(SDL_JoystickID instance_id)
{
SDL_GamepadType type = SDL_GAMEPAD_TYPE_UNKNOWN;
SDL_LockJoysticks();
{
GamepadMapping_t *mapping = SDL_PrivateGetGamepadMapping(instance_id);
if (mapping != NULL) {
char *type_string, *comma;
type_string = SDL_strstr(mapping->mapping, SDL_GAMEPAD_TYPE_FIELD);
if (type_string != NULL) {
type_string += SDL_GAMEPAD_TYPE_FIELD_SIZE;
comma = SDL_strchr(type_string, ',');
if (comma != NULL) {
*comma = '\0';
type = SDL_GetGamepadTypeFromString(type_string);
*comma = ',';
}
}
}
}
SDL_UnlockJoysticks();
if (type != SDL_GAMEPAD_TYPE_UNKNOWN) {
return type;
}
return SDL_GetRealGamepadInstanceType(instance_id);
}
SDL_GamepadType SDL_GetRealGamepadInstanceType(SDL_JoystickID instance_id)
{
return SDL_GetGamepadTypeFromGUID(SDL_GetJoystickInstanceGUID(instance_id), SDL_GetJoystickInstanceName(instance_id));
}
char *SDL_GetGamepadInstanceMapping(SDL_JoystickID instance_id)
{
char *retval = NULL;
SDL_LockJoysticks();
{
GamepadMapping_t *mapping = SDL_PrivateGetGamepadMapping(instance_id);
if (mapping != NULL) {
SDL_JoystickGUID guid;
char pchGUID[33];
size_t needed;
guid = SDL_GetJoystickInstanceGUID(instance_id);
SDL_GetJoystickGUIDString(guid, pchGUID, sizeof(pchGUID));
/* allocate enough memory for GUID + ',' + name + ',' + mapping + \0 */
needed = SDL_strlen(pchGUID) + 1 + SDL_strlen(mapping->name) + 1 + SDL_strlen(mapping->mapping) + 1;
retval = (char *)SDL_malloc(needed);
if (retval != NULL) {
(void)SDL_snprintf(retval, needed, "%s,%s,%s", pchGUID, mapping->name, mapping->mapping);
} else {
SDL_OutOfMemory();
}
}
}
SDL_UnlockJoysticks();
return retval;
}
/*
* Return 1 if the joystick with this name and GUID is a supported gamepad
*/
SDL_bool SDL_IsGamepadNameAndGUID(const char *name, SDL_JoystickGUID guid)
{
SDL_bool retval;
SDL_LockJoysticks();
{
if (SDL_PrivateGetGamepadMappingForNameAndGUID(name, guid) != NULL) {
retval = SDL_TRUE;
} else {
retval = SDL_FALSE;
}
}
SDL_UnlockJoysticks();
return retval;
}
/*
* Return 1 if the joystick at this device index is a supported gamepad
*/
SDL_bool SDL_IsGamepad(SDL_JoystickID instance_id)
{
SDL_bool retval;
SDL_LockJoysticks();
{
if (SDL_PrivateGetGamepadMapping(instance_id) != NULL) {
retval = SDL_TRUE;
} else {
retval = SDL_FALSE;
}
}
SDL_UnlockJoysticks();
return retval;
}
/*
* Return 1 if the gamepad should be ignored by SDL
*/
SDL_bool SDL_ShouldIgnoreGamepad(const char *name, SDL_JoystickGUID guid)
{
Uint16 vendor;
Uint16 product;
Uint16 version;
#ifdef __LINUX__
if (SDL_endswith(name, " Motion Sensors")) {
/* Don't treat the PS3 and PS4 motion controls as a separate gamepad */
return SDL_TRUE;
}
if (SDL_strncmp(name, "Nintendo ", 9) == 0 && SDL_strstr(name, " IMU") != NULL) {
/* Don't treat the Nintendo IMU as a separate gamepad */
return SDL_TRUE;
}
if (SDL_endswith(name, " Accelerometer") ||
SDL_endswith(name, " IR") ||
SDL_endswith(name, " Motion Plus") ||
SDL_endswith(name, " Nunchuk")) {
/* Don't treat the Wii extension controls as a separate gamepad */
return SDL_TRUE;
}
#endif
if (name && SDL_strcmp(name, "uinput-fpc") == 0) {
/* The Google Pixel fingerprint sensor reports itself as a joystick */
return SDL_TRUE;
}
if (SDL_allowed_gamepads.num_entries == 0 &&
SDL_ignored_gamepads.num_entries == 0) {
return SDL_FALSE;
}
SDL_GetJoystickGUIDInfo(guid, &vendor, &product, &version, NULL);
if (SDL_GetHintBoolean("SDL_GAMECONTROLLER_ALLOW_STEAM_VIRTUAL_GAMEPAD", SDL_FALSE)) {
/* We shouldn't ignore Steam's virtual gamepad since it's using the hints to filter out the real gamepads so it can remap input for the virtual gamepad */
/* https://partner.steamgames.com/doc/features/steam_gamepad/steam_input_gamepad_emulation_bestpractices */
SDL_bool bSteamVirtualGamepad = SDL_FALSE;
#ifdef __LINUX__
bSteamVirtualGamepad = (vendor == USB_VENDOR_VALVE && product == USB_PRODUCT_STEAM_VIRTUAL_GAMEPAD);
#elif defined(__MACOS__)
bSteamVirtualGamepad = (vendor == USB_VENDOR_MICROSOFT && product == USB_PRODUCT_XBOX360_WIRED_CONTROLLER && version == 1);
#elif defined(__WIN32__)
/* We can't tell on Windows, but Steam will block others in input hooks */
bSteamVirtualGamepad = SDL_TRUE;
#endif
if (bSteamVirtualGamepad) {
return SDL_FALSE;
}
}
if (SDL_allowed_gamepads.num_entries > 0) {
if (SDL_VIDPIDInList(vendor, product, &SDL_allowed_gamepads)) {
return SDL_FALSE;
}
return SDL_TRUE;
} else {
if (SDL_VIDPIDInList(vendor, product, &SDL_ignored_gamepads)) {
return SDL_TRUE;
}
return SDL_FALSE;
}
}
/*
* Open a gamepad for use
*
* This function returns a gamepad identifier, or NULL if an error occurred.
*/
SDL_Gamepad *SDL_OpenGamepad(SDL_JoystickID instance_id)
{
SDL_Gamepad *gamepad;
SDL_Gamepad *gamepadlist;
GamepadMapping_t *pSupportedGamepad = NULL;
SDL_LockJoysticks();
gamepadlist = SDL_gamepads;
/* If the gamepad is already open, return it */
while (gamepadlist != NULL) {
if (instance_id == gamepadlist->joystick->instance_id) {
gamepad = gamepadlist;
++gamepad->ref_count;
SDL_UnlockJoysticks();
return gamepad;
}
gamepadlist = gamepadlist->next;
}
/* Find a gamepad mapping */
pSupportedGamepad = SDL_PrivateGetGamepadMapping(instance_id);
if (pSupportedGamepad == NULL) {
SDL_SetError("Couldn't find mapping for device (%" SDL_PRIu32 ")", instance_id);
SDL_UnlockJoysticks();
return NULL;
}
/* Create and initialize the gamepad */
gamepad = (SDL_Gamepad *)SDL_calloc(1, sizeof(*gamepad));
if (gamepad == NULL) {
SDL_OutOfMemory();
SDL_UnlockJoysticks();
return NULL;
}
gamepad->magic = &gamepad_magic;
gamepad->joystick = SDL_OpenJoystick(instance_id);
if (gamepad->joystick == NULL) {
SDL_free(gamepad);
SDL_UnlockJoysticks();
return NULL;
}
if (gamepad->joystick->naxes) {
gamepad->last_match_axis = (SDL_GamepadBinding **)SDL_calloc(gamepad->joystick->naxes, sizeof(*gamepad->last_match_axis));
if (!gamepad->last_match_axis) {
SDL_OutOfMemory();
SDL_CloseJoystick(gamepad->joystick);
SDL_free(gamepad);
SDL_UnlockJoysticks();
return NULL;
}
}
if (gamepad->joystick->nhats) {
gamepad->last_hat_mask = (Uint8 *)SDL_calloc(gamepad->joystick->nhats, sizeof(*gamepad->last_hat_mask));
if (!gamepad->last_hat_mask) {
SDL_OutOfMemory();
SDL_CloseJoystick(gamepad->joystick);
SDL_free(gamepad->last_match_axis);
SDL_free(gamepad);
SDL_UnlockJoysticks();
return NULL;
}
}
SDL_PrivateLoadButtonMapping(gamepad, pSupportedGamepad);
/* Add the gamepad to list */
++gamepad->ref_count;
/* Link the gamepad in the list */
gamepad->next = SDL_gamepads;
SDL_gamepads = gamepad;
SDL_UnlockJoysticks();
return gamepad;
}
/*
* Manually pump for gamepad updates.
*/
void SDL_UpdateGamepads(void)
{
/* Just for API completeness; the joystick API does all the work. */
SDL_UpdateJoysticks();
}
/**
* Return whether a gamepad has a given axis
*/
SDL_bool SDL_GamepadHasAxis(SDL_Gamepad *gamepad, SDL_GamepadAxis axis)
{
SDL_bool retval = SDL_FALSE;
SDL_LockJoysticks();
{
int i;
CHECK_GAMEPAD_MAGIC(gamepad, SDL_FALSE);
for (i = 0; i < gamepad->num_bindings; ++i) {
SDL_GamepadBinding *binding = &gamepad->bindings[i];
if (binding->outputType == SDL_GAMEPAD_BINDTYPE_AXIS && binding->output.axis.axis == axis) {
retval = SDL_TRUE;
break;
}
}
}
SDL_UnlockJoysticks();
return retval;
}
/*
* Get the current state of an axis control on a gamepad
*/
Sint16 SDL_GetGamepadAxis(SDL_Gamepad *gamepad, SDL_GamepadAxis axis)
{
Sint16 retval = 0;
SDL_LockJoysticks();
{
int i;
CHECK_GAMEPAD_MAGIC(gamepad, 0);
for (i = 0; i < gamepad->num_bindings; ++i) {
SDL_GamepadBinding *binding = &gamepad->bindings[i];
if (binding->outputType == SDL_GAMEPAD_BINDTYPE_AXIS && binding->output.axis.axis == axis) {
int value = 0;
SDL_bool valid_input_range;
SDL_bool valid_output_range;
if (binding->inputType == SDL_GAMEPAD_BINDTYPE_AXIS) {
value = SDL_GetJoystickAxis(gamepad->joystick, binding->input.axis.axis);
if (binding->input.axis.axis_min < binding->input.axis.axis_max) {
valid_input_range = (value >= binding->input.axis.axis_min && value <= binding->input.axis.axis_max);
} else {
valid_input_range = (value >= binding->input.axis.axis_max && value <= binding->input.axis.axis_min);
}
if (valid_input_range) {
if (binding->input.axis.axis_min != binding->output.axis.axis_min || binding->input.axis.axis_max != binding->output.axis.axis_max) {
float normalized_value = (float)(value - binding->input.axis.axis_min) / (binding->input.axis.axis_max - binding->input.axis.axis_min);
value = binding->output.axis.axis_min + (int)(normalized_value * (binding->output.axis.axis_max - binding->output.axis.axis_min));
}
} else {
value = 0;
}
} else if (binding->inputType == SDL_GAMEPAD_BINDTYPE_BUTTON) {
value = SDL_GetJoystickButton(gamepad->joystick, binding->input.button);
if (value == SDL_PRESSED) {
value = binding->output.axis.axis_max;
}
} else if (binding->inputType == SDL_GAMEPAD_BINDTYPE_HAT) {
int hat_mask = SDL_GetJoystickHat(gamepad->joystick, binding->input.hat.hat);
if (hat_mask & binding->input.hat.hat_mask) {
value = binding->output.axis.axis_max;
}
}
if (binding->output.axis.axis_min < binding->output.axis.axis_max) {
valid_output_range = (value >= binding->output.axis.axis_min && value <= binding->output.axis.axis_max);
} else {
valid_output_range = (value >= binding->output.axis.axis_max && value <= binding->output.axis.axis_min);
}
/* If the value is zero, there might be another binding that makes it non-zero */
if (value != 0 && valid_output_range) {
retval = (Sint16)value;
break;
}
}
}
}
SDL_UnlockJoysticks();
return retval;
}
/**
* Return whether a gamepad has a given button
*/
SDL_bool SDL_GamepadHasButton(SDL_Gamepad *gamepad, SDL_GamepadButton button)
{
SDL_bool retval = SDL_FALSE;
SDL_LockJoysticks();
{
int i;
CHECK_GAMEPAD_MAGIC(gamepad, SDL_FALSE);
for (i = 0; i < gamepad->num_bindings; ++i) {
SDL_GamepadBinding *binding = &gamepad->bindings[i];
if (binding->outputType == SDL_GAMEPAD_BINDTYPE_BUTTON && binding->output.button == button) {
retval = SDL_TRUE;
break;
}
}
}
SDL_UnlockJoysticks();
return retval;
}
/*
* Get the current state of a button on a gamepad
*/
Uint8 SDL_GetGamepadButton(SDL_Gamepad *gamepad, SDL_GamepadButton button)
{
Uint8 retval = SDL_RELEASED;
SDL_LockJoysticks();
{
int i;
CHECK_GAMEPAD_MAGIC(gamepad, 0);
for (i = 0; i < gamepad->num_bindings; ++i) {
SDL_GamepadBinding *binding = &gamepad->bindings[i];
if (binding->outputType == SDL_GAMEPAD_BINDTYPE_BUTTON && binding->output.button == button) {
if (binding->inputType == SDL_GAMEPAD_BINDTYPE_AXIS) {
SDL_bool valid_input_range;
int value = SDL_GetJoystickAxis(gamepad->joystick, binding->input.axis.axis);
int threshold = binding->input.axis.axis_min + (binding->input.axis.axis_max - binding->input.axis.axis_min) / 2;
if (binding->input.axis.axis_min < binding->input.axis.axis_max) {
valid_input_range = (value >= binding->input.axis.axis_min && value <= binding->input.axis.axis_max);
if (valid_input_range) {
retval = (value >= threshold) ? SDL_PRESSED : SDL_RELEASED;
break;
}
} else {
valid_input_range = (value >= binding->input.axis.axis_max && value <= binding->input.axis.axis_min);
if (valid_input_range) {
retval = (value <= threshold) ? SDL_PRESSED : SDL_RELEASED;
break;
}
}
} else if (binding->inputType == SDL_GAMEPAD_BINDTYPE_BUTTON) {
retval = SDL_GetJoystickButton(gamepad->joystick, binding->input.button);
break;
} else if (binding->inputType == SDL_GAMEPAD_BINDTYPE_HAT) {
int hat_mask = SDL_GetJoystickHat(gamepad->joystick, binding->input.hat.hat);
retval = (hat_mask & binding->input.hat.hat_mask) ? SDL_PRESSED : SDL_RELEASED;
break;
}
}
}
}
SDL_UnlockJoysticks();
return retval;
}
/**
* Get the number of touchpads on a gamepad.
*/
int SDL_GetNumGamepadTouchpads(SDL_Gamepad *gamepad)
{
int retval = 0;
SDL_LockJoysticks();
{
SDL_Joystick *joystick = SDL_GetGamepadJoystick(gamepad);
if (joystick) {
retval = joystick->ntouchpads;
}
}
SDL_UnlockJoysticks();
return retval;
}
/**
* Get the number of supported simultaneous fingers on a touchpad on a gamepad.
*/
int SDL_GetNumGamepadTouchpadFingers(SDL_Gamepad *gamepad, int touchpad)
{
int retval = 0;
SDL_LockJoysticks();
{
SDL_Joystick *joystick = SDL_GetGamepadJoystick(gamepad);
if (joystick) {
if (touchpad >= 0 && touchpad < joystick->ntouchpads) {
retval = joystick->touchpads[touchpad].nfingers;
} else {
retval = SDL_InvalidParamError("touchpad");
}
}
}
SDL_UnlockJoysticks();
return retval;
}
/**
* Get the current state of a finger on a touchpad on a gamepad.
*/
int SDL_GetGamepadTouchpadFinger(SDL_Gamepad *gamepad, int touchpad, int finger, Uint8 *state, float *x, float *y, float *pressure)
{
int retval = -1;
SDL_LockJoysticks();
{
SDL_Joystick *joystick = SDL_GetGamepadJoystick(gamepad);
if (joystick) {
if (touchpad >= 0 && touchpad < joystick->ntouchpads) {
SDL_JoystickTouchpadInfo *touchpad_info = &joystick->touchpads[touchpad];
if (finger >= 0 && finger < touchpad_info->nfingers) {
SDL_JoystickTouchpadFingerInfo *info = &touchpad_info->fingers[finger];
if (state) {
*state = info->state;
}
if (x) {
*x = info->x;
}
if (y) {
*y = info->y;
}
if (pressure) {
*pressure = info->pressure;
}
retval = 0;
} else {
retval = SDL_InvalidParamError("finger");
}
} else {
retval = SDL_InvalidParamError("touchpad");
}
}
}
SDL_UnlockJoysticks();
return retval;
}
/**
* Return whether a gamepad has a particular sensor.
*/
SDL_bool SDL_GamepadHasSensor(SDL_Gamepad *gamepad, SDL_SensorType type)
{
SDL_bool retval = SDL_FALSE;
SDL_LockJoysticks();
{
SDL_Joystick *joystick = SDL_GetGamepadJoystick(gamepad);
if (joystick) {
int i;
for (i = 0; i < joystick->nsensors; ++i) {
if (joystick->sensors[i].type == type) {
retval = SDL_TRUE;
break;
}
}
}
}
SDL_UnlockJoysticks();
return retval;
}
/*
* Set whether data reporting for a gamepad sensor is enabled
*/
int SDL_SetGamepadSensorEnabled(SDL_Gamepad *gamepad, SDL_SensorType type, SDL_bool enabled)
{
SDL_LockJoysticks();
{
SDL_Joystick *joystick = SDL_GetGamepadJoystick(gamepad);
if (joystick) {
int i;
for (i = 0; i < joystick->nsensors; ++i) {
SDL_JoystickSensorInfo *sensor = &joystick->sensors[i];
if (sensor->type == type) {
if (sensor->enabled == enabled) {
SDL_UnlockJoysticks();
return 0;
}
if (type == SDL_SENSOR_ACCEL && joystick->accel_sensor) {
if (enabled) {
joystick->accel = SDL_OpenSensor(joystick->accel_sensor);
if (!joystick->accel) {
SDL_UnlockJoysticks();
return -1;
}
} else {
if (joystick->accel) {
SDL_CloseSensor(joystick->accel);
joystick->accel = NULL;
}
}
} else if (type == SDL_SENSOR_GYRO && joystick->gyro_sensor) {
if (enabled) {
joystick->gyro = SDL_OpenSensor(joystick->gyro_sensor);
if (!joystick->gyro) {
SDL_UnlockJoysticks();
return -1;
}
} else {
if (joystick->gyro) {
SDL_CloseSensor(joystick->gyro);
joystick->gyro = NULL;
}
}
} else {
if (enabled) {
if (joystick->nsensors_enabled == 0) {
if (joystick->driver->SetSensorsEnabled(joystick, SDL_TRUE) < 0) {
SDL_UnlockJoysticks();
return -1;
}
}
++joystick->nsensors_enabled;
} else {
if (joystick->nsensors_enabled == 1) {
if (joystick->driver->SetSensorsEnabled(joystick, SDL_FALSE) < 0) {
SDL_UnlockJoysticks();
return -1;
}
}
--joystick->nsensors_enabled;
}
}
sensor->enabled = enabled;
SDL_UnlockJoysticks();
return 0;
}
}
}
}
SDL_UnlockJoysticks();
return SDL_Unsupported();
}
/*
* Query whether sensor data reporting is enabled for a gamepad
*/
SDL_bool SDL_GamepadSensorEnabled(SDL_Gamepad *gamepad, SDL_SensorType type)
{
SDL_bool retval = SDL_FALSE;
SDL_LockJoysticks();
{
SDL_Joystick *joystick = SDL_GetGamepadJoystick(gamepad);
if (joystick) {
int i;
for (i = 0; i < joystick->nsensors; ++i) {
if (joystick->sensors[i].type == type) {
retval = joystick->sensors[i].enabled;
break;
}
}
}
}
SDL_UnlockJoysticks();
return retval;
}
/*
* Get the data rate of a gamepad sensor.
*/
float SDL_GetGamepadSensorDataRate(SDL_Gamepad *gamepad, SDL_SensorType type)
{
float retval = 0.0f;
SDL_LockJoysticks();
{
SDL_Joystick *joystick = SDL_GetGamepadJoystick(gamepad);
if (joystick) {
int i;
for (i = 0; i < joystick->nsensors; ++i) {
SDL_JoystickSensorInfo *sensor = &joystick->sensors[i];
if (sensor->type == type) {
retval = sensor->rate;
break;
}
}
}
}
SDL_UnlockJoysticks();
return retval;
}
/*
* Get the current state of a gamepad sensor.
*/
int SDL_GetGamepadSensorData(SDL_Gamepad *gamepad, SDL_SensorType type, float *data, int num_values)
{
SDL_LockJoysticks();
{
SDL_Joystick *joystick = SDL_GetGamepadJoystick(gamepad);
if (joystick) {
int i;
for (i = 0; i < joystick->nsensors; ++i) {
SDL_JoystickSensorInfo *sensor = &joystick->sensors[i];
if (sensor->type == type) {
num_values = SDL_min(num_values, SDL_arraysize(sensor->data));
SDL_memcpy(data, sensor->data, num_values * sizeof(*data));
SDL_UnlockJoysticks();
return 0;
}
}
}
}
SDL_UnlockJoysticks();
return SDL_Unsupported();
}
SDL_JoystickID SDL_GetGamepadInstanceID(SDL_Gamepad *gamepad)
{
SDL_Joystick *joystick = SDL_GetGamepadJoystick(gamepad);
if (joystick == NULL) {
return 0;
}
return SDL_GetJoystickInstanceID(joystick);
}
const char *SDL_GetGamepadName(SDL_Gamepad *gamepad)
{
const char *retval = NULL;
SDL_LockJoysticks();
{
CHECK_GAMEPAD_MAGIC(gamepad, NULL);
if (SDL_strcmp(gamepad->name, "*") == 0) {
retval = SDL_GetJoystickName(gamepad->joystick);
} else {
retval = gamepad->name;
}
}
SDL_UnlockJoysticks();
return retval;
}
const char *SDL_GetGamepadPath(SDL_Gamepad *gamepad)
{
SDL_Joystick *joystick = SDL_GetGamepadJoystick(gamepad);
if (joystick == NULL) {
return NULL;
}
return SDL_GetJoystickPath(joystick);
}
SDL_GamepadType SDL_GetGamepadType(SDL_Gamepad *gamepad)
{
SDL_JoystickID instance_id = 0;
SDL_LockJoysticks();
{
CHECK_GAMEPAD_MAGIC(gamepad, SDL_GAMEPAD_TYPE_UNKNOWN);
instance_id = gamepad->joystick->instance_id;
}
SDL_UnlockJoysticks();
return SDL_GetGamepadInstanceType(instance_id);
}
SDL_GamepadType SDL_GetRealGamepadType(SDL_Gamepad *gamepad)
{
SDL_Joystick *joystick = SDL_GetGamepadJoystick(gamepad);
if (joystick == NULL) {
return SDL_GAMEPAD_TYPE_UNKNOWN;
}
return SDL_GetGamepadTypeFromGUID(SDL_GetJoystickGUID(joystick), SDL_GetJoystickName(joystick));
}
int SDL_GetGamepadPlayerIndex(SDL_Gamepad *gamepad)
{
SDL_Joystick *joystick = SDL_GetGamepadJoystick(gamepad);
if (joystick == NULL) {
return -1;
}
return SDL_GetJoystickPlayerIndex(joystick);
}
/**
* Set the player index of an opened gamepad
*/
int SDL_SetGamepadPlayerIndex(SDL_Gamepad *gamepad, int player_index)
{
SDL_Joystick *joystick = SDL_GetGamepadJoystick(gamepad);
if (joystick == NULL) {
/* SDL_SetError() will have been called already by SDL_GetGamepadJoystick() */
return -1;
}
return SDL_SetJoystickPlayerIndex(joystick, player_index);
}
Uint16 SDL_GetGamepadVendor(SDL_Gamepad *gamepad)
{
SDL_Joystick *joystick = SDL_GetGamepadJoystick(gamepad);
if (joystick == NULL) {
return 0;
}
return SDL_GetJoystickVendor(joystick);
}
Uint16 SDL_GetGamepadProduct(SDL_Gamepad *gamepad)
{
SDL_Joystick *joystick = SDL_GetGamepadJoystick(gamepad);
if (joystick == NULL) {
return 0;
}
return SDL_GetJoystickProduct(joystick);
}
Uint16 SDL_GetGamepadProductVersion(SDL_Gamepad *gamepad)
{
SDL_Joystick *joystick = SDL_GetGamepadJoystick(gamepad);
if (joystick == NULL) {
return 0;
}
return SDL_GetJoystickProductVersion(joystick);
}
Uint16 SDL_GetGamepadFirmwareVersion(SDL_Gamepad *gamepad)
{
SDL_Joystick *joystick = SDL_GetGamepadJoystick(gamepad);
if (joystick == NULL) {
return 0;
}
return SDL_GetJoystickFirmwareVersion(joystick);
}
const char * SDL_GetGamepadSerial(SDL_Gamepad *gamepad)
{
SDL_Joystick *joystick = SDL_GetGamepadJoystick(gamepad);
if (joystick == NULL) {
return NULL;
}
return SDL_GetJoystickSerial(joystick);
}
SDL_JoystickPowerLevel SDL_GetGamepadPowerLevel(SDL_Gamepad *gamepad)
{
SDL_Joystick *joystick = SDL_GetGamepadJoystick(gamepad);
if (joystick == NULL) {
return SDL_JOYSTICK_POWER_UNKNOWN;
}
return SDL_GetJoystickPowerLevel(joystick);
}
/*
* Return if the gamepad in question is currently attached to the system,
* \return 0 if not plugged in, 1 if still present.
*/
SDL_bool SDL_GamepadConnected(SDL_Gamepad *gamepad)
{
SDL_Joystick *joystick = SDL_GetGamepadJoystick(gamepad);
if (joystick == NULL) {
return SDL_FALSE;
}
return SDL_JoystickConnected(joystick);
}
/*
* Get the joystick for this gamepad
*/
SDL_Joystick *SDL_GetGamepadJoystick(SDL_Gamepad *gamepad)
{
SDL_Joystick *joystick;
SDL_LockJoysticks();
{
CHECK_GAMEPAD_MAGIC(gamepad, NULL);
joystick = gamepad->joystick;
}
SDL_UnlockJoysticks();
return joystick;
}
/*
* Return the SDL_Gamepad associated with an instance id.
*/
SDL_Gamepad *SDL_GetGamepadFromInstanceID(SDL_JoystickID joyid)
{
SDL_Gamepad *gamepad;
SDL_LockJoysticks();
gamepad = SDL_gamepads;
while (gamepad) {
if (gamepad->joystick->instance_id == joyid) {
SDL_UnlockJoysticks();
return gamepad;
}
gamepad = gamepad->next;
}
SDL_UnlockJoysticks();
return NULL;
}
/**
* Return the SDL_Gamepad associated with a player index.
*/
SDL_Gamepad *SDL_GetGamepadFromPlayerIndex(int player_index)
{
SDL_Gamepad *retval = NULL;
SDL_LockJoysticks();
{
SDL_Joystick *joystick = SDL_GetJoystickFromPlayerIndex(player_index);
if (joystick) {
retval = SDL_GetGamepadFromInstanceID(joystick->instance_id);
}
}
SDL_UnlockJoysticks();
return retval;
}
Squashed 'external/sdl/SDL/' changes from ec0042081..399bc709b 399bc709b build-scripts.pl: Added add-source-to-projects.pl ac6827187 Visual-WinRT: dos2unix the project files to match other Visual Studio targets. 34719cba9 Fixed crash in hid_init() if the HIDDeviceManager isn't available 2e92e94eb Make sure we update device->sample_frames in SDL_AudioDeviceFormatChangedAlreadyLocked() 9964e5c5b wayland: Don't retrieve the drag offer strings with every pointer motion event bac7eeaaa Added missing include a541e2ac1 audio: Change a few SDL_memcpy calls to SDL_copyp. 54125c140 audio: Only update bound audiostreams' formats when necessary. e0b0f9a36 testaudio: Fix mouseover testing. 2f3deec24 wayland: Don't process drag & drop events from surfaces not owned by SDL 42bdced05 events: Log file drop position events and print the pointer coordinates c10d93d3a wayland: Replace magic constant with define 500852153 emscripten: Restore compatibility with existing emsdk releases. 953b55dd6 Use EM_ASM_PTR when the return value is a pointer a4541a255 audio: SDL_GetAudioStreamQueued now returns bytes, not frames. 703aefbce Sync SDL3 wiki -> header 99421b64d linux: Add portal drag and drop 952c5059b Remove stray  eebd5d18a linux: Handle upower's UP_DEVICE_STATE_PENDING_CHARGE, PENDING_DISCHARGE f8fdb20d8 audio: Destroy all existing SDL_AudioStreams on shutdown. 62d445997 audio: Removed declarations of functions that don't exist anymore. b656720bc loopwave: Use SDL_GetAudioStreamQueued() for more accurate results. 34b931f7e audio: Added SDL_GetAudioStreamQueued 23206b9e3 audio: Added SDL_EVENT_AUDIO_DEVICE_FORMAT_CHANGED c7e6d7a1f audio: Changed debug logging output. 87ec6acf2 audio: Added a FIXME ac88ffb7e audio: don't allocate buffer in SDL_SetAudioPostmixCallback for NULL callback. 2a950f6ae audio: Replace some SDL_memcpy calls with SDL_copyp. 0dc0434a3 audio: Fixed race condition in subsystem shutdown. 23f60203a audio: precalculate if we can use simple copies instead of the full mixer. 36b0f1141 audio: Optimize setting device formats during audio thread iteration. 4c3e84897 testspriteminimal: make standalone by embedding icon.bmp 2a01f9dcb tests: plug leaks when running with --trackmem f42bbeca2 SDL_test: track stack frames of allocations on Windows 12c0be028 SDL_test: clear text cache on exit event b4bfb1831 SDL_test: free state before logging allocations 248b1edd3 SDL_test: destroy windows in SDL_CommonQuit 98da2dd30 SDL_test: don't warn about expected allocations when running with --trackmem 6a381567b Support audio rate conversion up to 384KHz b2b548a1f Don't hang if IAudioRenderClient_GetBuffer() fails indefinitely a3a5e1728 Fixed build warning '=': conversion from 'Uint32' to 'Uint16', possible loss of data 6d3e21c27 Fixed android build warnings fca2f5318 Fixed warning: this function declaration is not a prototype a72dfa6a5 Fixed sensor timestamp units for third-party PS5 controllers f6756047a Fixed error: array subscript 2 is above array bounds of ‘const Uint8[2]’ 7059a55cc Fixed sensor timestamp calculation for third-party PS5 controllers c0443e5d1 Fixed crash in SDL_IMMDevice_FindByDevID() fde8499f6 Use around 20ms for the audio buffer size e5739d7d1 video: Remove SDL_GetFocusWindow() 39c2f9737 Fix NULL dereference in SDL_OpenAudio 9a23d0e3f Added new audio files to the Xcode project a62e62f97 Refactored SDL_audiocvt.c 31229fd47 include: Added a note about SDL's iOS app delegate functions. 65aaf3a9a x11: Always update clipboard owner f622f21e6 Fixed build 5774c9638 Prefer hidraw over libusb when libusb whitelisting is not enabled 9301f7ace hidapi/libusb: only enumerate each interface once 859dc14ad Replaced SDL_GetGamepadBindForAxis() and SDL_GetGamepadBindForButton() with SDL_GetGamepadBindings() 9e50048ab Revert "Removed SDL_GamepadBinding from the API" 9f17d1a9d Don't reference the same function in "see also" 86505ea63 fix SDL_AudioStreamCallback documentation d885d5c31 Sync SDL3 wiki -> header 2f43f7bc5 audio: Allow querying of device buffer size. cf9572113 audio: Added a hint to let apps force device buffer size. 47d8c77c6 audio: Choose better default sample frame counts. 8b26e95f9 audio: Change SDL_AudioStreamCallback 9da34e8fb docs: Updated README-emscripten.md. fd1c54a00 detect fanatec steering wheels cb4414608 docs: Whoops, this got added by the wiki bridge by accident! cd633b9a8 Renamed SDL_IsAudioDevicePaused() to SDL_AudioDevicePaused() c6cad07fa Sync SDL3 wiki -> header a6e52f9e4 Sync SDL3 wiki -> header 2de2e9d03 Fix flickering of window when using desktop-fullscreen and borderless window on multiple monitors on Linux. Closes #8186. 723835d16 Windows: fix for client rect resizing larger each time we came from exclusive fullscreen -> windowed on a monitor with HiDPI set. The problem was we were using the monitor DPI rather than the window DPI so AdjustWindowRectExForDpi was giving us an incorrect size which would be too large for the client rect. Closes #8237. ce27363df wikiheaders: Sort undocumented functions. e22282b09 Added README about transparent windows in Win32 1d1c6e630 Turn off COREAUDIO debug logging by default 52efefca0 wayland: Fix drag offer leak 3a992af44 audio: Added a postmix callback to logical devices. 7207bdce5 render: Enable clipping for zero-sized rectangles 22d81fb3e cmake: use MSVC_RUNTIME_LIBRARY to force MT a2e17852d cmake: make sure SDL_GetPrefPath is run before testfilesystem 2fb266e0a ci: run tests in parallel ad1313e75 testaudio: Patched to compile. 5747ddc01 testaudio: Clean up some messy memory management. fafbea1ce audio: Move internal float32 mixing to a simplified function 116b0ec97 include: minor tweak to audio API documentation fb1377035 include: Replaced old Bugzilla URL. 38c8fc05c audio: Remove ChooseMixStrategy. b00cbd76a wikiheaders.pl: create Unsupported.md file with list of functions undocumented in either the headers or the wiki 37e1fc3b5 wayland: Ensure that the toplevel window is recreated when switching decoration modes f2ca9a615 Added SDL_AUDIO_FRAMESIZE 53122593f Added SDL_AUDIO_BYTESIZE 544351c98 Sync SDL3 wiki -> header 2e7d2b94e Clarify that SDL_BlitSurface() ignores the width and height in dstrect a2c1984d3 Detect Simagic wheel bases as wheels (#8198) 1d8dfbb22 avoid type redefinition errors after PR/8181 266b91d2f Detect Logitech G923 Playstation as wheel G923 have two different versions - Xbox version is already present in the wheel list, but not the PS version. cde67ea49 Detect Logitech PRO Racing Wheel for Xbox (PC mode) as wheel Logitech PRO Racing Wheel have two different versions - for Playstation and Xbox. Vendor + Product ID for Playstation version already present in SDL sources, but not an Xbox version 3a932141e Restore audio format binary compatibility with SDL 2.0 e85206ffd wikiheaders.pl: add --rev= option to pass revision string 233789b0d Audio types have the same naming convention as other SDL endian types, e.g. [S|U][BITS][LE|BE] 36b5f3e35 Sync SDL3 wiki -> header 0e552761b Renamed AudioStreamSpeed to AudioStreamFrequencyRatio 47bcb078f Fixed some incorrect SDL_AUDIO_F32 uses 2833f2e7b Fixed OOB access in audio_convertAccuracy test 8387fae69 Sync SDL3 wiki -> header 832181345 docs: Add note about Wayland application icons 825d34475 Make sure that the same timestamp is used for all PS5 events from the same packet 9c1430324 Removed SDL_dataqueue 28b28bd8f Added audio_formatChange test a59152688 Try and avoid overflow when handling very large audio streams 5394a805f Improved testaudiostreamdynamicresample e55844274 Added SDL_(Get|Set)AudioStreamSpeed 43c3c5736 Track the formats of data in an SDL_AudioStream 337fed3df Tweaked ResampleFrame_SSE Use _mm_unpack(lo|hi)_ps instead of _mm_shuffle_ps fd7cd91dc audio: Mix multiple streams in float32 to prevent clipping. 9097573e3 audio: Choose a mixing strategy on each iteration. bbe2e012a Don't provide the SDL3 header path c17a35f09 Fixed typo 4f72255eb Fixed README.md link e0ab59754 Simplified SDL_main.h migration notes d44bde61e Added SDL migration information to the top level README.md 6ff31e10c metal: Add hint to select low power device instead of the default one (#8182) 8a8aed477 Make sure that we process touch events that position the mouse f84c87f20 Sync SDL3 wiki -> header a7eea9997 macOS: Don't raise the parent top-level window when raising a child window, only raise the child window to the top of the parent a5e721479 Add SDL_WINDOW_NOT_FOCUSABLE flag to set that the window should not be able to gain key focus b385dc3b6 n3dsaudio: Patched to compile. 4e0c7c91f audio: PlayDevice() should return an error code. a94d724f1 wayland: add SDL_VIDEO_DRIVER_WAYLAND_DYNAMIC_EGL da5d93d3d wayland: don't define SDL_VIDEO_DRIVER_WAYLAND_DYNAMIC_* macro's f002f7d12 ci: build emscripten with Debug buid type 3699b12ed audio: Fixed some "is_*" variables to be cleaner and/or more specific. 2471d8cc2 audio: Fixed logic error in SDL_OpenAudioDeviceStream. 1b03a2430 testsurround: fix order of arguments of callback 82db2b58f Renamed audio stream callback and moved the userdata parameter first 5bdad5210 Sync SDL3 wiki -> header 58c859f64 audio: Rename SDL_GetAudioStreamBinding to SDL_GetAudioStreamDevice. efd2023a7 audio: Fixed documentation. 1e775e0ee audio: Replace SDL_CreateAndBindAudioStream with SDL_OpenAudioDeviceStream. bd088c2f9 Revert "Clarify whether an audio function expects a physical or logical device ID" 82e481b52 Added --randmem test parameter ea68bb802 Add some additional checks to audio_convertAudio f8286df16 Fixed ResampleFrame_SSE doing unnecessary work b1d63be53 Fixed audio_resampleLoss test c191d6c30 Better Win32 transparent window support 923d612ca hidapi: sync macOS code with mainstream. 363f4fa9c avoid type redefinition errors after commit ee806597b9. 615824a80 Updated documentation now that SDL_GetAudioDevices() has been split into separate functions for output and capture devices 506a133d8 Clarify whether an audio function expects a physical or logical device ID 3b1d1e4e3 hidapi: sync the hidraw changes with mainstream f617918e0 cmake: check linkage to libusb too, instead of libusb.h presence only. 041dbd6b5 Fixed GetResamplerAvailableOutputFrames Non-euclidean division is a pain b49d0a607 x11: Avoid including full Vulkan headers. 4d2f9f3a3 yuv_rgb: Comment out unused code. 3c3486e2a wayland: Don't include full Vulkan headers when not necessary. f066bbe98 x11: Don't include system headers twice. d86d02bbb updated dynapi after SDL_GDKGetDefaultUser addition 4355f9cec Fixed warning C4389: '!=': signed/unsigned mismatch 5755de07a Fixed build warnings 0f80d47bb Fixed thread-safety warning ee806597b Removed SDL_vulkan_internal.h from SDL_sysvideo.h 34860b932 Fixed testautomation --filter pixels_allocFreeFormat 6f8a6a31c gdk: GetBasePath should be a UTF8 version of Win32 GetBasePath e30e5c77e Sync SDL3 wiki -> header c0cd8c814 gdk: Add SDL_GDKGetDefaultUser, SDL_GetPrefPath implementation 106abce69 Refactored GetAudioStreamDataInternal buffer handling The final conversion step should now always go straight into the output buffer. e44f54ec5 Avoid using hex-floats 5b696996c Added ResampleFrame_SSE 958b3cfae Tweaked and enabled audio_convertAudio test 7dbb9b65b audio_convertAccuracy: Shuffle the data in case of a bad SIMD implementation f6a4080ff audio_resampleLoss: Add support for multiple channels 4f894e748 audio_resampleLoss: SDL_GetAudioStreamData now returns the correct length ab83f75bb Make sure GetAudioStreamDataInternal is called with a valid length 6a73f74b6 Rebuild full ResamplerFilter (left wing + right wing) at runtime 0c15ce006 Add a missing int cast b74ee86b1 Optimized ResampleAudio, with special cases for 1 and 2 channels This would also benefit from some SIMD, since it's just a bunch of multiply-adds fba6e1e3d Removed ResamplerFilterDifference It takes 1 extra multiply to calculate the correct interpolation, but I think the improvement in cache locality (and binary size) outweighs that. 9f7a22fa4 Removed 64-bit handling from AudioConvertByteswap 1f5327a9f Removed future_buffer, left_padding, and right_padding from SDL_AudioStream 71ad52d6d Lowered SDL_GetAudioStreamData to 32 KB No particular reason for this number, but 1 MB was a bit silly 69aec8c91 Fixed the report format for the Razer Wolverine V2 Pro 7c2669c9d Accept key events from any source 1e9d31448 Updated to Android minSdkVersion 19 and targetSdkVersion 34 8924d0d92 Added missing function prototype for SDL_WriteS64BE() 845f3c745 Fixed mismatch between stdlib calloc() and SDL free() fb7921173 emscriptenaudio: Fire the capture silence_callback at an interval. 5191b2054 emscriptenaudio: Don't bother undefining things about to be unreachable. fd75a4ca0 emscriptenaudio: Deal with blocked audio devices better. 981b8a337 emscriptenaudio: Remove unnecessary functions. c7588e426 Transparent window for Win32 + OpenGL (#8143) f9581178d cmake: fixed a typo. e6c878824 Fixed ResampleAudio interpolation factor calculation 498363863 Misc audio tweaks/cleanup 72d9d53de Invert the inner ResampleAudio loops to avoid doing unnecessary work 88123a510 The history buffer should always have the maximum possible padding frames 96e47f165 Clamp results of GetResampler(AvailableOutput|NeededInput)Frames d2b9c8b80 Fixed maths in testaudiostreamdynamicresample (and just show the actual scale) 14e38b17d Removed assertions from inner ResampleAudio loop 9d413dfdc The history buffer doesn't need to be so large 2788e848f Allow resampling less than 1 frame of input 383084e0a Pre-calculate resampling rate, and use it instead of .freq in most places 40a6a445c Update resample_offset inside ResampleAudio 47fea7f06 Used fixed-point arithmetic in ResampleAudio 7bb4e806e Clear resample_offset in SDL_ClearAudioStream, not SetAudioStreamFormat Not entirely sure if ClearAudioStream is the right place, but SetAudioStreamFormat was the wrong place b9541b9ea Improved ResampleAudio * filterindex2 was off-by-one * Generate ResamplerFilter using doubles * Transpose ResamplerFilter to improve access patterns cdaa19869 Track offset within the current sample when resampling d60ebb06d mouse: Ensure that the dummy default cursor is removed from the cursor list e58c2731f mouse: Free the default cursor when destroyed 789ce17e1 audio: Don't resample in chunks for now. cbab33482 audio: Don't call SDL_AudioStream callbacks for empty data sets. 3e1ae0c86 Clearified the libusb whitelist default logic f4520821e Removed some unnecessary integer casts 0989b7e86 Avoid using designated initializers c6c1e673c Optimized SDL_Convert_*_to_*_Scalar f97b920b3 Optimized SDL_Convert_*_to_*_SSE2 Some of the SDL_Convert_F32_to_*_SSE2 do not explicitly clamp the input, but instead rely on saturating casts. Inputs very far outside the valid [-1.0, 1.0] range may produce an incorrect result, but I believe that is an acceptable trade-off. 300d1ec3e Added audio_convertAccuracy test 32cecc2ea Fixed assertion in audio_convertAudio 33f11e21e Removed assertions in AudioConvert(To|From)Float c2f388fd8 cmake: add SDL_HIDAPI_LIBUSB_SHARED option + test on ci 371cc2d17 wayland: Remove unnecessary flag and state settings fe85e6e75 cocoa: Send a maximized event instead of restored if a deminiaturized window is zoomed ddddcb78c cocoa: Use the close method to hide a miniaturized window be8c42cfd Clarify that a window being 'hidden' means that it is unmapped/ordered out a44338cbc Fix typo in SDL_audiocvt.c f464eb2c5 SDL_hidapi.c: change 'use_libusb_whitelist_default' into a macro. 6607a3cfa Disable cache in python http server 181d5d285 hidapi: Enable libusb support by default. f0f15e365 hidapi: Use a whitelist for libusb when other backends are available c3f7a7dc4 Convert audio using SDL_AUDIO_F32SYS format instead of SDL_AUDIO_F32 796713b9d xxd.py: always write \n line endings 723bcd0a8 SDL_TriggerBreakppoint for riscv arch (both 32/64) version. git-subtree-dir: external/sdl/SDL git-subtree-split: 399bc709b7485bab57880f8261f826f29dc0d7b2
2023-09-23 18:45:49 +02:00
/*
* Get the SDL joystick layer bindings for this gamepad
*/
SDL_GamepadBinding **SDL_GetGamepadBindings(SDL_Gamepad *gamepad, int *count)
{
SDL_GamepadBinding **bindings = NULL;
if (count) {
*count = 0;
}
SDL_LockJoysticks();
{
CHECK_GAMEPAD_MAGIC(gamepad, NULL);
size_t pointers_size = ((gamepad->num_bindings + 1) * sizeof(SDL_GamepadBinding *));
size_t elements_size = (gamepad->num_bindings * sizeof(SDL_GamepadBinding));
bindings = (SDL_GamepadBinding **)SDL_malloc(pointers_size + elements_size);
if (bindings) {
SDL_GamepadBinding *binding = (SDL_GamepadBinding *)((Uint8 *)bindings + pointers_size);
int i;
for (i = 0; i < gamepad->num_bindings; ++i, ++binding) {
bindings[i] = binding;
SDL_copyp(binding, &gamepad->bindings[i]);
}
bindings[i] = NULL;
if (count) {
*count = gamepad->num_bindings;
}
} else {
SDL_OutOfMemory();
}
}
SDL_UnlockJoysticks();
return bindings;
}
int SDL_RumbleGamepad(SDL_Gamepad *gamepad, Uint16 low_frequency_rumble, Uint16 high_frequency_rumble, Uint32 duration_ms)
{
SDL_Joystick *joystick = SDL_GetGamepadJoystick(gamepad);
if (joystick == NULL) {
return -1;
}
return SDL_RumbleJoystick(joystick, low_frequency_rumble, high_frequency_rumble, duration_ms);
}
int SDL_RumbleGamepadTriggers(SDL_Gamepad *gamepad, Uint16 left_rumble, Uint16 right_rumble, Uint32 duration_ms)
{
SDL_Joystick *joystick = SDL_GetGamepadJoystick(gamepad);
if (joystick == NULL) {
return -1;
}
return SDL_RumbleJoystickTriggers(joystick, left_rumble, right_rumble, duration_ms);
}
SDL_bool SDL_GamepadHasLED(SDL_Gamepad *gamepad)
{
SDL_Joystick *joystick = SDL_GetGamepadJoystick(gamepad);
if (joystick == NULL) {
return SDL_FALSE;
}
return SDL_JoystickHasLED(joystick);
}
SDL_bool SDL_GamepadHasRumble(SDL_Gamepad *gamepad)
{
SDL_Joystick *joystick = SDL_GetGamepadJoystick(gamepad);
if (joystick == NULL) {
return SDL_FALSE;
}
return SDL_JoystickHasRumble(joystick);
}
SDL_bool SDL_GamepadHasRumbleTriggers(SDL_Gamepad *gamepad)
{
SDL_Joystick *joystick = SDL_GetGamepadJoystick(gamepad);
if (joystick == NULL) {
return SDL_FALSE;
}
return SDL_JoystickHasRumbleTriggers(joystick);
}
int SDL_SetGamepadLED(SDL_Gamepad *gamepad, Uint8 red, Uint8 green, Uint8 blue)
{
SDL_Joystick *joystick = SDL_GetGamepadJoystick(gamepad);
if (joystick == NULL) {
return -1;
}
return SDL_SetJoystickLED(joystick, red, green, blue);
}
int SDL_SendGamepadEffect(SDL_Gamepad *gamepad, const void *data, int size)
{
SDL_Joystick *joystick = SDL_GetGamepadJoystick(gamepad);
if (joystick == NULL) {
return -1;
}
return SDL_SendJoystickEffect(joystick, data, size);
}
void SDL_CloseGamepad(SDL_Gamepad *gamepad)
{
SDL_Gamepad *gamepadlist, *gamepadlistprev;
SDL_LockJoysticks();
if (gamepad == NULL || gamepad->magic != &gamepad_magic) {
SDL_UnlockJoysticks();
return;
}
/* First decrement ref count */
if (--gamepad->ref_count > 0) {
SDL_UnlockJoysticks();
return;
}
SDL_CloseJoystick(gamepad->joystick);
gamepadlist = SDL_gamepads;
gamepadlistprev = NULL;
while (gamepadlist) {
if (gamepad == gamepadlist) {
if (gamepadlistprev) {
/* unlink this entry */
gamepadlistprev->next = gamepadlist->next;
} else {
SDL_gamepads = gamepad->next;
}
break;
}
gamepadlistprev = gamepadlist;
gamepadlist = gamepadlist->next;
}
gamepad->magic = NULL;
SDL_free(gamepad->bindings);
SDL_free(gamepad->last_match_axis);
SDL_free(gamepad->last_hat_mask);
SDL_free(gamepad);
SDL_UnlockJoysticks();
}
/*
* Quit the gamepad subsystem
*/
void SDL_QuitGamepads(void)
{
SDL_Gamepad *gamepad;
SDL_LockJoysticks();
for (gamepad = SDL_gamepads; gamepad; gamepad = gamepad->next) {
SDL_PrivateGamepadRemoved(gamepad->joystick->instance_id);
}
SDL_gamepads_initialized = SDL_FALSE;
SDL_DelEventWatch(SDL_GamepadEventWatcher, NULL);
while (SDL_gamepads) {
SDL_gamepads->ref_count = 1;
SDL_CloseGamepad(SDL_gamepads);
}
SDL_UnlockJoysticks();
}
void SDL_QuitGamepadMappings(void)
{
GamepadMapping_t *pGamepadMap;
SDL_AssertJoysticksLocked();
while (s_pSupportedGamepads) {
pGamepadMap = s_pSupportedGamepads;
s_pSupportedGamepads = s_pSupportedGamepads->next;
SDL_free(pGamepadMap->name);
SDL_free(pGamepadMap->mapping);
SDL_free(pGamepadMap);
}
SDL_DelHintCallback(SDL_HINT_GAMECONTROLLER_IGNORE_DEVICES,
SDL_GamepadIgnoreDevicesChanged, NULL);
SDL_DelHintCallback(SDL_HINT_GAMECONTROLLER_IGNORE_DEVICES_EXCEPT,
SDL_GamepadIgnoreDevicesExceptChanged, NULL);
SDL_FreeVIDPIDList(&SDL_allowed_gamepads);
SDL_FreeVIDPIDList(&SDL_ignored_gamepads);
}
/*
* Event filter to transform joystick events into appropriate gamepad ones
*/
static int SDL_SendGamepadAxis(Uint64 timestamp, SDL_Gamepad *gamepad, SDL_GamepadAxis axis, Sint16 value)
{
int posted;
SDL_AssertJoysticksLocked();
/* translate the event, if desired */
posted = 0;
#ifndef SDL_EVENTS_DISABLED
if (SDL_EventEnabled(SDL_EVENT_GAMEPAD_AXIS_MOTION)) {
SDL_Event event;
event.type = SDL_EVENT_GAMEPAD_AXIS_MOTION;
event.common.timestamp = timestamp;
event.gaxis.which = gamepad->joystick->instance_id;
event.gaxis.axis = axis;
event.gaxis.value = value;
posted = SDL_PushEvent(&event) == 1;
}
#endif /* !SDL_EVENTS_DISABLED */
return posted;
}
/*
* Event filter to transform joystick events into appropriate gamepad ones
*/
static int SDL_SendGamepadButton(Uint64 timestamp, SDL_Gamepad *gamepad, SDL_GamepadButton button, Uint8 state)
{
int posted;
#ifndef SDL_EVENTS_DISABLED
SDL_Event event;
SDL_AssertJoysticksLocked();
if (button == SDL_GAMEPAD_BUTTON_INVALID) {
return 0;
}
switch (state) {
case SDL_PRESSED:
event.type = SDL_EVENT_GAMEPAD_BUTTON_DOWN;
break;
case SDL_RELEASED:
event.type = SDL_EVENT_GAMEPAD_BUTTON_UP;
break;
default:
/* Invalid state -- bail */
return 0;
}
#endif /* !SDL_EVENTS_DISABLED */
if (button == SDL_GAMEPAD_BUTTON_GUIDE) {
Uint64 now = SDL_GetTicks();
if (state == SDL_PRESSED) {
gamepad->guide_button_down = now;
if (gamepad->joystick->delayed_guide_button) {
/* Skip duplicate press */
return 0;
}
} else {
if (now < (gamepad->guide_button_down + SDL_MINIMUM_GUIDE_BUTTON_DELAY_MS)) {
gamepad->joystick->delayed_guide_button = SDL_TRUE;
return 0;
}
gamepad->joystick->delayed_guide_button = SDL_FALSE;
}
}
/* translate the event, if desired */
posted = 0;
#ifndef SDL_EVENTS_DISABLED
if (SDL_EventEnabled(event.type)) {
event.common.timestamp = timestamp;
event.gbutton.which = gamepad->joystick->instance_id;
event.gbutton.button = button;
event.gbutton.state = state;
posted = SDL_PushEvent(&event) == 1;
}
#endif /* !SDL_EVENTS_DISABLED */
return posted;
}
#ifndef SDL_EVENTS_DISABLED
static const Uint32 SDL_gamepad_event_list[] = {
SDL_EVENT_GAMEPAD_AXIS_MOTION,
SDL_EVENT_GAMEPAD_BUTTON_DOWN,
SDL_EVENT_GAMEPAD_BUTTON_UP,
SDL_EVENT_GAMEPAD_ADDED,
SDL_EVENT_GAMEPAD_REMOVED,
SDL_EVENT_GAMEPAD_REMAPPED,
SDL_EVENT_GAMEPAD_TOUCHPAD_DOWN,
SDL_EVENT_GAMEPAD_TOUCHPAD_MOTION,
SDL_EVENT_GAMEPAD_TOUCHPAD_UP,
SDL_EVENT_GAMEPAD_SENSOR_UPDATE,
};
#endif
void SDL_SetGamepadEventsEnabled(SDL_bool enabled)
{
#ifndef SDL_EVENTS_DISABLED
unsigned int i;
for (i = 0; i < SDL_arraysize(SDL_gamepad_event_list); ++i) {
SDL_SetEventEnabled(SDL_gamepad_event_list[i], enabled);
}
#endif /* !SDL_EVENTS_DISABLED */
}
SDL_bool SDL_GamepadEventsEnabled(void)
{
SDL_bool enabled = SDL_FALSE;
#ifndef SDL_EVENTS_DISABLED
unsigned int i;
for (i = 0; i < SDL_arraysize(SDL_gamepad_event_list); ++i) {
enabled = SDL_EventEnabled(SDL_gamepad_event_list[i]);
if (enabled) {
break;
}
}
#endif /* SDL_EVENTS_DISABLED */
return enabled;
}
void SDL_GamepadHandleDelayedGuideButton(SDL_Joystick *joystick)
{
SDL_Gamepad *gamepad;
SDL_AssertJoysticksLocked();
for (gamepad = SDL_gamepads; gamepad; gamepad = gamepad->next) {
if (gamepad->joystick == joystick) {
SDL_SendGamepadButton(0, gamepad, SDL_GAMEPAD_BUTTON_GUIDE, SDL_RELEASED);
/* Make sure we send an update complete event for this change */
if (!gamepad->joystick->update_complete) {
gamepad->joystick->update_complete = SDL_GetTicksNS();
}
break;
}
}
}
const char *SDL_GetGamepadAppleSFSymbolsNameForButton(SDL_Gamepad *gamepad, SDL_GamepadButton button)
{
#ifdef SDL_JOYSTICK_MFI
const char *IOS_GetAppleSFSymbolsNameForButton(SDL_Gamepad *gamepad, SDL_GamepadButton button);
const char *retval;
SDL_LockJoysticks();
{
CHECK_GAMEPAD_MAGIC(gamepad, NULL);
retval = IOS_GetAppleSFSymbolsNameForButton(gamepad, button);
}
SDL_UnlockJoysticks();
return retval;
#else
return NULL;
#endif
}
const char *SDL_GetGamepadAppleSFSymbolsNameForAxis(SDL_Gamepad *gamepad, SDL_GamepadAxis axis)
{
#ifdef SDL_JOYSTICK_MFI
const char *IOS_GetAppleSFSymbolsNameForAxis(SDL_Gamepad *gamepad, SDL_GamepadAxis axis);
const char *retval;
SDL_LockJoysticks();
{
CHECK_GAMEPAD_MAGIC(gamepad, NULL);
retval = IOS_GetAppleSFSymbolsNameForAxis(gamepad, axis);
}
SDL_UnlockJoysticks();
return retval;
#else
return NULL;
#endif
}