Skip to content

armgit / godot

Public Imported from GitHub
0

Godot Engine – Multi-platform 2D and 3D game engine

sdl: Update to 3.4.16

Nintorch6328c1fee8d2
diff --git a/doc/classes/Input.xml b/doc/classes/Input.xml
index 952d00b0a47..92f225c5a57 100644
--- a/doc/classes/Input.xml
+++ b/doc/classes/Input.xml
@@ -130,7 +130,7 @@
+Y ... -Y: bottom ... top;
+Z ... -Z: farther ... closer.
The gravity part value is measured as a vector with length of [code]9.8[/code] away from the center of the Earth, which is a negative Y value.
- [b]Note:[/b] This feature is only supported on Windows, Linux, and macOS. On iOS, joypad accelerometer sensor reading is not supported due to OS limitations.
+ [b]Note:[/b] This feature is only supported on Windows, Linux, macOS, and iOS.
</description>
</method>
<method name="get_joy_axis" qualifiers="const">
@@ -151,7 +151,7 @@
+Y ... -Y: bottom ... top;
+Z ... -Z: farther ... closer.
The gravity part value is measured as a vector with length of [code]9.8[/code] away from the center of the Earth, which is a negative Y value.
- [b]Note:[/b] This feature is only supported on Windows, Linux, and macOS. On iOS, joypad accelerometer sensor reading is not supported due to OS limitations.
+ [b]Note:[/b] This feature is only supported on Windows, Linux, macOS, and iOS.
</description>
</method>
<method name="get_joy_guid" qualifiers="const">
@@ -334,7 +334,6 @@
<param index="0" name="device" type="int" />
<description>
Returns [code]true[/code] if the joypad has motion sensors (gyroscope and/or accelerometer).
- [b]Note:[/b] On iOS, joypad accelerometer sensor reading is not supported due to OS limitations.
[b]Note:[/b] This feature is only supported on Windows, Linux, macOS, and iOS.
</description>
</method>
diff --git a/drivers/sdl/SCsub b/drivers/sdl/SCsub
index 4666edb5bf3..921615acd77 100644
--- a/drivers/sdl/SCsub
+++ b/drivers/sdl/SCsub
@@ -72,6 +72,7 @@ if env["builtin_sdl"]:
"libm/s_scalbn.c",
"libm/s_sin.c",
"libm/s_tan.c",
+ "misc/SDL_libusb.c",
"sensor/SDL_sensor.c",
"sensor/dummy/SDL_dummysensor.c",
"stdlib/SDL_crc16.c",
@@ -95,32 +96,42 @@ if env["builtin_sdl"]:
# HIDAPI
thirdparty_sources += [
+ "haptic/hidapi/SDL_hidapihaptic_lg4ff.c",
+ "haptic/hidapi/SDL_hidapihaptic.c",
"hidapi/SDL_hidapi.c",
+ "joystick/hidapi/SDL_hidapi_8bitdo.c",
"joystick/hidapi/SDL_hidapi_combined.c",
+ "joystick/hidapi/SDL_hidapi_flydigi.c",
"joystick/hidapi/SDL_hidapi_gamecube.c",
- "joystick/hidapi/SDL_hidapijoystick.c",
+ "joystick/hidapi/SDL_hidapi_gip.c",
+ "joystick/hidapi/SDL_hidapi_lg4ff.c",
"joystick/hidapi/SDL_hidapi_luna.c",
"joystick/hidapi/SDL_hidapi_ps3.c",
"joystick/hidapi/SDL_hidapi_ps4.c",
"joystick/hidapi/SDL_hidapi_ps5.c",
"joystick/hidapi/SDL_hidapi_rumble.c",
"joystick/hidapi/SDL_hidapi_shield.c",
+ "joystick/hidapi/SDL_hidapi_sinput.c",
"joystick/hidapi/SDL_hidapi_stadia.c",
"joystick/hidapi/SDL_hidapi_steam.c",
"joystick/hidapi/SDL_hidapi_steamdeck.c",
"joystick/hidapi/SDL_hidapi_steam_hori.c",
+ "joystick/hidapi/SDL_hidapi_steam_triton.c",
"joystick/hidapi/SDL_hidapi_switch.c",
+ "joystick/hidapi/SDL_hidapi_switch2.c",
"joystick/hidapi/SDL_hidapi_wii.c",
"joystick/hidapi/SDL_hidapi_xbox360.c",
"joystick/hidapi/SDL_hidapi_xbox360w.c",
"joystick/hidapi/SDL_hidapi_xboxone.c",
+ "joystick/hidapi/SDL_hidapi_zuiki.c",
+ "joystick/hidapi/SDL_hidapijoystick.c",
+ "joystick/hidapi/SDL_report_descriptor.c",
]
# Platform specific sources.
if env["platform"] == "linuxbsd":
# TODO: Check support for BSD systems.
- env_sdl.Append(CPPDEFINES=["SDL_PLATFORM_LINUX"])
thirdparty_sources += [
"core/linux/SDL_dbus.c",
"core/linux/SDL_evdev.c",
@@ -144,7 +155,6 @@ if env["builtin_sdl"]:
env_sdl.Prepend(CPPPATH=[thirdparty_dir + "core/linux"])
elif env["platform"] == "macos":
- env_sdl.Append(CPPDEFINES=["SDL_PLATFORM_MACOS"])
thirdparty_sources += [
"core/unix/SDL_appid.c",
"core/unix/SDL_poll.c",
@@ -161,14 +171,15 @@ if env["builtin_sdl"]:
]
elif env["platform"] == "windows":
- env_sdl.Append(CPPDEFINES=["SDL_PLATFORM_WINDOWS"])
thirdparty_sources += [
- "core/windows/SDL_gameinput.c",
"core/windows/SDL_hid.c",
"core/windows/SDL_immdevice.c",
"core/windows/SDL_windows.c",
"core/windows/SDL_xinput.c",
"core/windows/pch.c",
+ "filesystem/SDL_filesystem.c", # Only used by Windows joystick driver at the moment.
+ "filesystem/windows/SDL_sysfilesystem.c",
+ "filesystem/windows/SDL_sysfsops.c",
"haptic/windows/SDL_dinputhaptic.c",
"haptic/windows/SDL_windowshaptic.c",
"joystick/windows/SDL_dinputjoystick.c",
@@ -185,15 +196,11 @@ if env["builtin_sdl"]:
"thread/windows/SDL_syssem.c",
"thread/windows/SDL_systhread.c",
"thread/windows/SDL_systls.c",
+ "time/SDL_time.c", # Only used by Windows filesystem driver at the moment.
"timer/windows/SDL_systimer.c",
]
elif env["platform"] in ["ios", "visionos"]:
- if env["platform"] == "ios":
- env_sdl.Append(CPPDEFINES=["SDL_PLATFORM_IOS"])
- else:
- env_sdl.Append(CPPDEFINES=["SDL_PLATFORM_VISIONOS"])
-
thirdparty_sources += [
"core/unix/SDL_appid.c",
"core/unix/SDL_poll.c",
diff --git a/drivers/sdl/SDL_build_config_private.h b/drivers/sdl/SDL_build_config_private.h
index 1a86bb55572..248682d7e71 100644
--- a/drivers/sdl/SDL_build_config_private.h
+++ b/drivers/sdl/SDL_build_config_private.h
@@ -45,15 +45,13 @@
#define SDL_VIDEO_DISABLED 1
#define SDL_CAMERA_DISABLED 1
#define SDL_DIALOG_DISABLED 1
-#define SDL_FILESYSTEM_DUMMY 1
-#define SDL_FSOPS_DUMMY 1
#define SDL_GPU_DISABLED 1
#define SDL_RENDER_DISABLED 1
#define SDL_POWER_DISABLED 1
#define SDL_LEAN_AND_MEAN 1
// Windows defines
-#if defined(SDL_PLATFORM_WINDOWS)
+#if defined(WINDOWS_ENABLED)
#define SDL_PLATFORM_PRIVATE_NAME "Windows"
#define HAVE_LIBC 1
@@ -73,12 +71,13 @@
#define SDL_THREAD_WINDOWS 1
#define SDL_TIMER_WINDOWS 1
#define SDL_SENSOR_WINDOWS 1
+#define SDL_FILESYSTEM_WINDOWS 1 // Used by thirdparty/sdl/joystick/windows/SDL_dinputjoystick.c
+#define SDL_FSOPS_WINDOWS 1
// Linux defines
-#elif defined(SDL_PLATFORM_LINUX)
+#elif defined(LINUXBSD_ENABLED)
#define SDL_PLATFORM_PRIVATE_NAME "Linux"
-#define SDL_PLATFORM_UNIX 1
#define HAVE_STDIO_H 1
#define HAVE_LIBC 1
@@ -116,13 +115,15 @@
#define SDL_JOYSTICK_HIDAPI 1
#define SDL_INPUT_LINUXEV 1
#define SDL_THREAD_PTHREAD 1
+#define SDL_FILESYSTEM_DUMMY 1
+#define SDL_FSOPS_DUMMY 1
// macOS defines
-#elif defined(SDL_PLATFORM_MACOS)
+#elif defined(MACOS_ENABLED)
#define SDL_PLATFORM_PRIVATE_NAME "macOS"
-#define SDL_PLATFORM_UNIX 1
#define HAVE_STDIO_H 1
+#define HAVE_STDLIB_H 1
#define HAVE_LIBC 1
#define SDL_HAPTIC_IOKIT 1
#define SDL_JOYSTICK_IOKIT 1
@@ -131,25 +132,28 @@
#define SDL_TIMER_UNIX 1
#define SDL_THREAD_PTHREAD 1
#define SDL_THREAD_PTHREAD_RECURSIVE_MUTEX 1
+#define SDL_FILESYSTEM_DUMMY 1
+#define SDL_FSOPS_DUMMY 1
// iOS/visionOS defines
-#elif defined(SDL_PLATFORM_IOS) || defined(SDL_PLATFORM_VISIONOS)
+#elif defined(IOS_ENABLED) || defined(VISIONOS_ENABLED)
-#ifdef SDL_PLATFORM_IOS
+#ifdef IOS_ENABLED
#define SDL_PLATFORM_PRIVATE_NAME "iOS"
#else
#define SDL_PLATFORM_PRIVATE_NAME "visionOS"
#endif
-#define SDL_PLATFORM_UNIX 1
-
#define HAVE_STDIO_H 1
+#define HAVE_STDLIB_H 1
#define HAVE_LIBC 1
#define SDL_JOYSTICK_MFI 1
#define SDL_HAPTIC_DUMMY 1
#define SDL_TIMER_UNIX 1
#define SDL_THREAD_PTHREAD 1
+#define SDL_FILESYSTEM_DUMMY 1
+#define SDL_FSOPS_DUMMY 1
#define SDL_MAIN_HANDLED 1
diff --git a/thirdparty/README.md b/thirdparty/README.md
index 311b32c2cb0..0f2f6a2a9e3 100644
--- a/thirdparty/README.md
+++ b/thirdparty/README.md
@@ -1002,7 +1002,7 @@ Files extracted from upstream source:
## sdl
- Upstream: https://github.com/libsdl-org/SDL
-- Version: 3.2.28 (7f3ae3d57459e59943a4ecfefc8f6277ec6bf540, 2025)
+- Version: 3.4.12 (f87239e71e42da91ca317a12eefb82cfbf3393eb, 2026)
- License: Zlib
- Vendored: hidapi 0.14.0, license BSD-3-Clause
@@ -1017,9 +1017,7 @@ Patches:
- `0004-errno-include.patch` ([GH-108354](https://github.com/godotengine/godot/pull/108354))
- `0005-fix-libudev-dbus.patch` ([GH-108373](https://github.com/godotengine/godot/pull/108373))
- `0006-fix-cs-environ.patch` ([GH-109283](https://github.com/godotengine/godot/pull/109283))
-- `0007-shield-duplicate-macos.patch` ([GH-115510](https://github.com/godotengine/godot/pull/115510))
-- `0008-fix-linux-joycon-serial-num.patch` ([GH-113873](https://github.com/godotengine/godot/pull/113873))
-- `0009-update-device-blocklist.patch` ([GH-119403](https://github.com/godotengine/godot/pull/119403))
+- `0007-ios-accelerometer.patch` ([GH-120373](https://github.com/godotengine/godot/pull/120373))
## spirv-cross
diff --git a/thirdparty/sdl/LICENSE.txt b/thirdparty/sdl/LICENSE.txt
index 23abb73f2b6..e9adee44845 100644
--- a/thirdparty/sdl/LICENSE.txt
+++ b/thirdparty/sdl/LICENSE.txt
@@ -1,4 +1,4 @@
-Copyright (C) 1997-2025 Sam Lantinga <[email protected]>
+Copyright (C) 1997-2026 Sam Lantinga <[email protected]>
This software is provided 'as-is', without any express or implied
warranty. In no event will the authors be held liable for any damages
diff --git a/thirdparty/sdl/SDL.c b/thirdparty/sdl/SDL.c
index 3dad7e29ba9..40982f2cfca 100644
--- a/thirdparty/sdl/SDL.c
+++ b/thirdparty/sdl/SDL.c
@@ -1,6 +1,6 @@
/*
Simple DirectMedia Layer
- Copyright (C) 1997-2025 Sam Lantinga <[email protected]>
+ Copyright (C) 1997-2026 Sam Lantinga <[email protected]>
This software is provided 'as-is', without any express or implied
warranty. In no event will the authors be held liable for any damages
@@ -30,6 +30,10 @@
// this checks for HAVE_DBUS_DBUS_H internally.
#include "core/linux/SDL_dbus.h"
+// #if defined(SDL_PLATFORM_UNIX) && !defined(SDL_PLATFORM_ANDROID)
+// #include "core/unix/SDL_gtk.h"
+// #endif
+
#ifdef SDL_PLATFORM_EMSCRIPTEN
#include <emscripten.h>
#endif
@@ -40,19 +44,30 @@
#include "SDL_hints_c.h"
#include "SDL_log_c.h"
#include "SDL_properties_c.h"
-//#include "audio/SDL_sysaudio.h"
+// #include "audio/SDL_sysaudio.h"
+// #include "camera/SDL_camera_c.h"
+// #include "cpuinfo/SDL_cpuinfo_c.h"
#include "events/SDL_events_c.h"
#include "haptic/SDL_haptic_c.h"
#include "joystick/SDL_gamepad_c.h"
#include "joystick/SDL_joystick_c.h"
+// #include "render/SDL_sysrender.h"
#include "sensor/SDL_sensor_c.h"
#include "stdlib/SDL_getenv_c.h"
#include "thread/SDL_thread_c.h"
+// #include "tray/SDL_tray_utils.h"
+// #include "video/SDL_pixels_c.h"
+// #include "video/SDL_surface_c.h"
+// #include "video/SDL_video_c.h"
+#ifndef SDL_FILESYSTEM_DUMMY // Godot change
+#include "filesystem/SDL_filesystem_c.h"
+#endif
+// #include "io/SDL_asyncio_c.h"
#ifdef SDL_PLATFORM_ANDROID
#include "core/android/SDL_android.h"
#endif
-#define SDL_INIT_EVERYTHING ~0U
+#define SDL_ALL_SUBSYSTEM_FLAGS ~0U
// Initialization/Cleanup routines
#include "timer/SDL_timer_c.h"
@@ -135,7 +150,7 @@ static bool SDL_ValidMetadataProperty(const char *name)
bool SDL_SetAppMetadataProperty(const char *name, const char *value)
{
- if (!SDL_ValidMetadataProperty(name)) {
+ CHECK_PARAM(!SDL_ValidMetadataProperty(name)) {
return SDL_InvalidParamError("name");
}
@@ -144,7 +159,7 @@ bool SDL_SetAppMetadataProperty(const char *name, const char *value)
const char *SDL_GetAppMetadataProperty(const char *name)
{
- if (!SDL_ValidMetadataProperty(name)) {
+ CHECK_PARAM(!SDL_ValidMetadataProperty(name)) {
SDL_InvalidParamError("name");
return NULL;
}
@@ -160,7 +175,10 @@ const char *SDL_GetAppMetadataProperty(const char *name)
}
if (!value || !*value) {
if (SDL_strcmp(name, SDL_PROP_APP_METADATA_NAME_STRING) == 0) {
- value = "SDL Application";
+ // value = SDL_GetExeName();
+ if (!value) {
+ value = "SDL Application";
+ }
} else if (SDL_strcmp(name, SDL_PROP_APP_METADATA_TYPE_STRING) == 0) {
value = "application";
}
@@ -176,6 +194,8 @@ static bool SDL_MainIsReady = false;
static bool SDL_MainIsReady = true;
#endif
static SDL_ThreadID SDL_MainThreadID = 0;
+static SDL_ThreadID SDL_EventsThreadID = 0;
+static SDL_ThreadID SDL_VideoThreadID = 0;
static bool SDL_bInMainQuit = false;
static Uint8 SDL_SubsystemRefCount[32];
@@ -224,6 +244,7 @@ static bool SDL_ShouldQuitSubsystem(Uint32 subsystem)
return (((subsystem_index >= 0) && (SDL_SubsystemRefCount[subsystem_index] == 1)) || SDL_bInMainQuit);
}
+#if !defined(SDL_VIDEO_DISABLED) || !defined(SDL_AUDIO_DISABLED) || !defined(SDL_JOYSTICK_DISABLED)
/* Private helper to either increment's existing ref counter,
* or fully init a new subsystem. */
static bool SDL_InitOrIncrementSubsystem(Uint32 subsystem)
@@ -239,6 +260,7 @@ static bool SDL_InitOrIncrementSubsystem(Uint32 subsystem)
}
return SDL_InitSubSystem(subsystem);
}
+#endif // !SDL_VIDEO_DISABLED || !SDL_AUDIO_DISABLED || !SDL_JOYSTICK_DISABLED
void SDL_SetMainReady(void)
{
@@ -251,14 +273,21 @@ void SDL_SetMainReady(void)
bool SDL_IsMainThread(void)
{
- if (SDL_MainThreadID == 0) {
- // Not initialized yet?
- return true;
+ if (SDL_VideoThreadID) {
+ return (SDL_GetCurrentThreadID() == SDL_VideoThreadID);
}
- if (SDL_MainThreadID == SDL_GetCurrentThreadID()) {
- return true;
+ if (SDL_EventsThreadID) {
+ return (SDL_GetCurrentThreadID() == SDL_EventsThreadID);
}
- return false;
+ if (SDL_MainThreadID) {
+ return (SDL_GetCurrentThreadID() == SDL_MainThreadID);
+ }
+ return true;
+}
+
+bool SDL_IsVideoThread(void)
+{
+ return (SDL_GetCurrentThreadID() == SDL_VideoThreadID);
}
// Initialize all the subsystems that require initialization before threads start
@@ -266,10 +295,17 @@ void SDL_InitMainThread(void)
{
static bool done_info = false;
+ // If we haven't done it by now, mark this as the main thread
+ if (SDL_MainThreadID == 0) {
+ SDL_MainThreadID = SDL_GetCurrentThreadID();
+ }
+
SDL_InitTLSData();
SDL_InitEnvironment();
- SDL_InitTicks();
- //SDL_InitFilesystem();
+ SDL_InitTicks();
+#ifndef SDL_FILESYSTEM_DUMMY // Godot change
+ SDL_InitFilesystem();
+#endif
if (!done_info) {
const char *value;
@@ -288,7 +324,9 @@ void SDL_InitMainThread(void)
static void SDL_QuitMainThread(void)
{
- //SDL_QuitFilesystem();
+#ifndef SDL_FILESYSTEM_DUMMY // Godot change
+ SDL_QuitFilesystem();
+#endif
SDL_QuitTicks();
SDL_QuitEnvironment();
SDL_QuitTLSData();
@@ -302,6 +340,26 @@ bool SDL_InitSubSystem(SDL_InitFlags flags)
return SDL_SetError("Application didn't initialize properly, did you include SDL_main.h in the file containing your main() function?");
}
+#ifdef SDL_PLATFORM_EMSCRIPTEN
+ MAIN_THREAD_EM_ASM({
+ // make sure this generic table to hang SDL-specific Javascript stuff is available at init time.
+ if (typeof(Module['SDL3']) === 'undefined') {
+ Module['SDL3'] = {};
+ }
+
+ var SDL3 = Module['SDL3'];
+ #if defined(__wasm32__)
+ if (typeof(SDL3.JSVarToCPtr) === 'undefined') { SDL3.JSVarToCPtr = function(v) { return v; }; }
+ if (typeof(SDL3.CPtrToHeap32Index) === 'undefined') { SDL3.CPtrToHeap32Index = function(ptr) { return ptr >>> 2; }; }
+ #elif defined(__wasm64__)
+ if (typeof(SDL3.JSVarToCPtr) === 'undefined') { SDL3.JSVarToCPtr = function(v) { return BigInt(v); }; }
+ if (typeof(SDL3.CPtrToHeap32Index) === 'undefined') { SDL3.CPtrToHeap32Index = function(ptr) { return Number(ptr / 4n); }; }
+ #else
+ #error Please define your platform.
+ #endif
+ });
+#endif
+
SDL_InitMainThread();
#ifdef SDL_USE_LIBDBUS
@@ -320,6 +378,11 @@ bool SDL_InitSubSystem(SDL_InitFlags flags)
if (flags & SDL_INIT_EVENTS) {
if (SDL_ShouldInitSubsystem(SDL_INIT_EVENTS)) {
SDL_IncrementSubsystemRefCount(SDL_INIT_EVENTS);
+
+ // Note which thread initialized events
+ // This is the thread which should be pumping events
+ SDL_EventsThreadID = SDL_GetCurrentThreadID();
+
if (!SDL_InitEvents()) {
SDL_DecrementSubsystemRefCount(SDL_INIT_EVENTS);
goto quit_and_error;
@@ -339,12 +402,16 @@ bool SDL_InitSubSystem(SDL_InitFlags flags)
goto quit_and_error;
}
+ SDL_IncrementSubsystemRefCount(SDL_INIT_VIDEO);
+
// We initialize video on the main thread
// On Apple platforms this is a requirement.
// On other platforms, this is the definition.
- SDL_MainThreadID = SDL_GetCurrentThreadID();
+ SDL_VideoThreadID = SDL_GetCurrentThreadID();
+#ifdef SDL_PLATFORM_APPLE
+ SDL_assert(SDL_VideoThreadID == SDL_MainThreadID);
+#endif
- SDL_IncrementSubsystemRefCount(SDL_INIT_VIDEO);
if (!SDL_VideoInit(NULL)) {
SDL_DecrementSubsystemRefCount(SDL_INIT_VIDEO);
SDL_PushError();
@@ -594,6 +661,7 @@ void SDL_QuitSubSystem(SDL_InitFlags flags)
if (SDL_ShouldQuitSubsystem(SDL_INIT_VIDEO)) {
SDL_QuitRender();
SDL_VideoQuit();
+ SDL_VideoThreadID = 0;
// video implies events
SDL_QuitSubSystem(SDL_INIT_EVENTS);
}
@@ -604,6 +672,7 @@ void SDL_QuitSubSystem(SDL_InitFlags flags)
if (flags & SDL_INIT_EVENTS) {
if (SDL_ShouldQuitSubsystem(SDL_INIT_EVENTS)) {
SDL_QuitEvents();
+ SDL_EventsThreadID = 0;
}
SDL_DecrementSubsystemRefCount(SDL_INIT_EVENTS);
}
@@ -622,7 +691,7 @@ Uint32 SDL_WasInit(SDL_InitFlags flags)
}
if (!flags) {
- flags = SDL_INIT_EVERYTHING;
+ flags = SDL_ALL_SUBSYSTEM_FLAGS;
}
num_subsystems = SDL_min(num_subsystems, SDL_MostSignificantBitIndex32(flags) + 1);
@@ -647,27 +716,31 @@ void SDL_Quit(void)
#ifdef SDL_PLATFORM_WINDOWS
SDL_HelperWindowDestroy();
#endif
- SDL_QuitSubSystem(SDL_INIT_EVERYTHING);
- //SDL_CleanupTrays();
+ SDL_QuitSubSystem(SDL_ALL_SUBSYSTEM_FLAGS);
+ // SDL_CleanupTrays();
#ifdef SDL_USE_LIBDBUS
SDL_DBus_Quit();
#endif
+#if defined(SDL_PLATFORM_UNIX) && !defined(SDL_PLATFORM_ANDROID) && !defined(SDL_PLATFORM_EMSCRIPTEN) && !defined(SDL_PLATFORM_PRIVATE)
+ SDL_Gtk_Quit();
+#endif
+
SDL_QuitTimers();
- //SDL_QuitAsyncIO();
+ // SDL_QuitAsyncIO();
SDL_SetObjectsInvalid();
SDL_AssertionsQuit();
- //SDL_QuitPixelFormatDetails();
+ // SDL_QuitPixelFormatDetails();
- //SDL_QuitCPUInfo();
+ // SDL_QuitCPUInfo();
/* Now that every subsystem has been quit, we reset the subsystem refcount
* and the list of initialized subsystems.
*/
- SDL_memset(SDL_SubsystemRefCount, 0x0, sizeof(SDL_SubsystemRefCount));
+ SDL_zeroa(SDL_SubsystemRefCount);
SDL_QuitLog();
SDL_QuitHints();
@@ -719,6 +792,8 @@ const char *SDL_GetPlatform(void)
return "macOS";
#elif defined(SDL_PLATFORM_NETBSD)
return "NetBSD";
+#elif defined(SDL_PLATFORM_NGAGE)
+ return "Nokia N-Gage";
#elif defined(SDL_PLATFORM_OPENBSD)
return "OpenBSD";
#elif defined(SDL_PLATFORM_OS2)
@@ -739,6 +814,8 @@ const char *SDL_GetPlatform(void)
return "Xbox One";
#elif defined(SDL_PLATFORM_XBOXSERIES)
return "Xbox Series X|S";
+#elif defined(SDL_PLATFORM_VISIONOS)
+ return "visionOS";
#elif defined(SDL_PLATFORM_IOS)
return "iOS";
#elif defined(SDL_PLATFORM_TVOS)
@@ -751,6 +828,8 @@ const char *SDL_GetPlatform(void)
return "PlayStation Vita";
#elif defined(SDL_PLATFORM_3DS)
return "Nintendo 3DS";
+#elif defined(SDL_PLATFORM_HURD)
+ return "GNU/Hurd";
#elif defined(__managarm__)
return "Managarm";
#else
@@ -822,9 +901,7 @@ SDL_Sandbox SDL_GetSandbox(void)
#ifdef SDL_PLATFORM_WIN32
-#if (!defined(HAVE_LIBC) || defined(__WATCOMC__)) && !defined(SDL_STATIC_LIB)
-// FIXME: Still need to include DllMain() on Watcom C ?
-
+#if !defined(HAVE_LIBC) && !defined(SDL_STATIC_LIB)
BOOL APIENTRY MINGW32_FORCEALIGN _DllMainCRTStartup(HANDLE hModule, DWORD ul_reason_for_call, LPVOID lpReserved)
{
switch (ul_reason_for_call) {
diff --git a/thirdparty/sdl/SDL_assert.c b/thirdparty/sdl/SDL_assert.c
index af904039a49..5b32f08bab9 100644
--- a/thirdparty/sdl/SDL_assert.c
+++ b/thirdparty/sdl/SDL_assert.c
@@ -1,6 +1,6 @@
/*
Simple DirectMedia Layer
- Copyright (C) 1997-2025 Sam Lantinga <[email protected]>
+ Copyright (C) 1997-2026 Sam Lantinga <[email protected]>
This software is provided 'as-is', without any express or implied
warranty. In no event will the authors be held liable for any damages
@@ -25,7 +25,7 @@
#endif
#include "SDL_assert_c.h"
-//#include "video/SDL_sysvideo.h"
+// #include "video/SDL_sysvideo.h"
#if defined(SDL_PLATFORM_WINDOWS)
#ifndef WS_OVERLAPPEDWINDOW
@@ -120,23 +120,10 @@ static void SDL_GenerateAssertionReport(void)
}
}
-/* This is not declared in any header, although it is shared between some
- parts of SDL, because we don't want anything calling it without an
- extremely good reason. */
-#ifdef __WATCOMC__
-extern void SDL_ExitProcess(int exitcode);
-#pragma aux SDL_ExitProcess aborts;
-#endif
-extern SDL_NORETURN void SDL_ExitProcess(int exitcode);
-
-#ifdef __WATCOMC__
-static void SDL_AbortAssertion(void);
-#pragma aux SDL_AbortAssertion aborts;
-#endif
static SDL_NORETURN void SDL_AbortAssertion(void)
{
SDL_Quit();
- SDL_ExitProcess(42);
+ SDL_abort();
}
static SDL_AssertState SDLCALL SDL_PromptAssertion(const SDL_AssertData *data, void *userdata)
@@ -209,6 +196,18 @@ static SDL_AssertState SDLCALL SDL_PromptAssertion(const SDL_AssertData *data, v
}
}
+ // Leave fullscreen mode, if possible (scary!)
+ // window = SDL_GetToplevelForKeyboardFocus();
+ // if (window) {
+ // if (window->fullscreen_exclusive) {
+ // SDL_MinimizeWindow(window);
+ // } else {
+ // // !!! FIXME: ungrab the input if we're not fullscreen?
+ // // No need to mess with the window
+ // window = NULL;
+ // }
+ // }
+
// Show a messagebox if we can, otherwise fall back to stdio
SDL_zero(messagebox);
messagebox.flags = SDL_MESSAGEBOX_WARNING;
@@ -218,7 +217,7 @@ static SDL_AssertState SDLCALL SDL_PromptAssertion(const SDL_AssertData *data, v
messagebox.numbuttons = SDL_arraysize(buttons);
messagebox.buttons = buttons;
- //if (SDL_ShowMessageBox(&messagebox, &selected)) {
+ // if (SDL_ShowMessageBox(&messagebox, &selected)) {
if (false) {
if (selected == -1) {
state = SDL_ASSERTION_IGNORE;
@@ -300,13 +299,13 @@ static SDL_AssertState SDLCALL SDL_PromptAssertion(const SDL_AssertData *data, v
}
}
#else
- //SDL_ShowSimpleMessageBox(SDL_MESSAGEBOX_WARNING, "Assertion Failed", message, window);
-#endif // HAVE_STDIO_H
+ // SDL_ShowSimpleMessageBox(SDL_MESSAGEBOX_WARNING, "Assertion Failed", message, window);
+#endif // SDL_PLATFORM_PRIVATE_ASSERT
}
// Re-enter fullscreen mode
if (window) {
- //SDL_RestoreWindow(window);
+ // SDL_RestoreWindow(window);
}
if (message != stack_buf) {
@@ -350,7 +349,7 @@ SDL_AssertState SDL_ReportAssertion(SDL_AssertData *data, const char *func, cons
if (assertion_running == 2) {
SDL_AbortAssertion();
} else if (assertion_running == 3) { // Abort asserted!
- SDL_ExitProcess(42);
+ SDL_abort();
} else {
while (1) { // do nothing but spin; what else can you do?!
}
diff --git a/thirdparty/sdl/SDL_assert_c.h b/thirdparty/sdl/SDL_assert_c.h
index d892dbef8ae..4d7a1068cef 100644
--- a/thirdparty/sdl/SDL_assert_c.h
+++ b/thirdparty/sdl/SDL_assert_c.h
@@ -1,6 +1,6 @@
/*
Simple DirectMedia Layer
- Copyright (C) 1997-2025 Sam Lantinga <[email protected]>
+ Copyright (C) 1997-2026 Sam Lantinga <[email protected]>
This software is provided 'as-is', without any express or implied
warranty. In no event will the authors be held liable for any damages
diff --git a/thirdparty/sdl/SDL_error.c b/thirdparty/sdl/SDL_error.c
index 3c62c8aff48..64c1bf06eba 100644
--- a/thirdparty/sdl/SDL_error.c
+++ b/thirdparty/sdl/SDL_error.c
@@ -1,6 +1,6 @@
/*
Simple DirectMedia Layer
- Copyright (C) 1997-2025 Sam Lantinga <[email protected]>
+ Copyright (C) 1997-2026 Sam Lantinga <[email protected]>
This software is provided 'as-is', without any express or implied
warranty. In no event will the authors be held liable for any damages
@@ -20,6 +20,8 @@
*/
#include "SDL_internal.h"
+#include "stdlib/SDL_vacopy.h"
+
// Simple error handling in SDL
#include "SDL_error_c.h"
@@ -41,22 +43,28 @@ bool SDL_SetErrorV(SDL_PRINTF_FORMAT_STRING const char *fmt, va_list ap)
if (fmt) {
int result;
SDL_error *error = SDL_GetErrBuf(true);
- va_list ap2;
- error->error = SDL_ErrorCodeGeneric;
+ // use the other slot for the new error, so if this does
+ // SDL_SetError("%s", SDL_GetError()), we don't have a problem.
+ const int current = error->current ? 0 : 1;
+ SDL_ErrorInfo *errinfo = &error->info[current];
+ error->current = current;
+ errinfo->error = SDL_ErrorCodeGeneric;
+
+ va_list ap2;
va_copy(ap2, ap);
- result = SDL_vsnprintf(error->str, error->len, fmt, ap2);
+ result = SDL_vsnprintf(errinfo->str, errinfo->len, fmt, ap2);
va_end(ap2);
- if (result >= 0 && (size_t)result >= error->len && error->realloc_func) {
+ if (result >= 0 && (size_t)result >= errinfo->len && error->realloc_func) {
size_t len = (size_t)result + 1;
- char *str = (char *)error->realloc_func(error->str, len);
+ char *str = (char *)error->realloc_func(errinfo->str, len);
if (str) {
- error->str = str;
- error->len = len;
+ errinfo->str = str;
+ errinfo->len = len;
va_copy(ap2, ap);
- (void)SDL_vsnprintf(error->str, error->len, fmt, ap2);
+ (void)SDL_vsnprintf(errinfo->str, errinfo->len, fmt, ap2);
va_end(ap2);
}
}
@@ -65,7 +73,7 @@ bool SDL_SetErrorV(SDL_PRINTF_FORMAT_STRING const char *fmt, va_list ap)
// Note that there are many recoverable errors that may happen internally and
// can be safely ignored if the public API doesn't return an error code.
#if 0
- SDL_LogError(SDL_LOG_CATEGORY_ERROR, "%s", error->str);
+ SDL_LogError(SDL_LOG_CATEGORY_ERROR, "%s", errinfo->str);
#endif
}
@@ -80,9 +88,10 @@ const char *SDL_GetError(void)
return "";
}
- switch (error->error) {
+ const SDL_ErrorInfo *errinfo = &error->info[error->current];
+ switch (errinfo->error) {
case SDL_ErrorCodeGeneric:
- return error->str;
+ return errinfo->str;
case SDL_ErrorCodeOutOfMemory:
return "Out of memory";
default:
@@ -95,7 +104,8 @@ bool SDL_ClearError(void)
SDL_error *error = SDL_GetErrBuf(false);
if (error) {
- error->error = SDL_ErrorCodeNone;
+ SDL_ErrorInfo *errinfo = &error->info[error->current];
+ errinfo->error = SDL_ErrorCodeNone;
}
return true;
}
@@ -105,7 +115,8 @@ bool SDL_OutOfMemory(void)
SDL_error *error = SDL_GetErrBuf(true);
if (error) {
- error->error = SDL_ErrorCodeOutOfMemory;
+ SDL_ErrorInfo *errinfo = &error->info[error->current];
+ errinfo->error = SDL_ErrorCodeOutOfMemory;
}
return false;
}
diff --git a/thirdparty/sdl/SDL_error_c.h b/thirdparty/sdl/SDL_error_c.h
index ba4550ed029..7d53783d88f 100644
--- a/thirdparty/sdl/SDL_error_c.h
+++ b/thirdparty/sdl/SDL_error_c.h
@@ -1,6 +1,6 @@
/*
Simple DirectMedia Layer
- Copyright (C) 1997-2025 Sam Lantinga <[email protected]>
+ Copyright (C) 1997-2026 Sam Lantinga <[email protected]>
This software is provided 'as-is', without any express or implied
warranty. In no event will the authors be held liable for any damages
@@ -34,11 +34,17 @@ typedef enum
SDL_ErrorCodeOutOfMemory,
} SDL_ErrorCode;
-typedef struct SDL_error
+typedef struct SDL_ErrorInfo
{
SDL_ErrorCode error;
char *str;
size_t len;
+} SDL_ErrorInfo;
+
+typedef struct SDL_error
+{
+ SDL_ErrorInfo info[2]; // there are two, so you can do SDL_SetError("%s", SDL_GetError()) without stomping the buffer.
+ int current;
SDL_realloc_func realloc_func;
SDL_free_func free_func;
} SDL_error;
diff --git a/thirdparty/sdl/SDL_guid.c b/thirdparty/sdl/SDL_guid.c
index 6c355d8dd90..913206a5605 100644
--- a/thirdparty/sdl/SDL_guid.c
+++ b/thirdparty/sdl/SDL_guid.c
@@ -1,6 +1,6 @@
/*
Simple DirectMedia Layer
- Copyright (C) 1997-2025 Sam Lantinga <[email protected]>
+ Copyright (C) 1997-2026 Sam Lantinga <[email protected]>
This software is provided 'as-is', without any express or implied
warranty. In no event will the authors be held liable for any damages
@@ -77,7 +77,7 @@ SDL_GUID SDL_StringToGUID(const char *pchGUID)
// Make sure it's even
len = (len) & ~0x1;
- SDL_memset(&guid, 0x00, sizeof(guid));
+ SDL_zero(guid);
p = (Uint8 *)&guid;
for (i = 0; (i < len) && ((p - (Uint8 *)&guid) < maxoutputbytes); i += 2, p++) {
diff --git a/thirdparty/sdl/SDL_hashtable.c b/thirdparty/sdl/SDL_hashtable.c
index 3124b41a8a9..8bc79f7e31e 100644
--- a/thirdparty/sdl/SDL_hashtable.c
+++ b/thirdparty/sdl/SDL_hashtable.c
@@ -1,6 +1,6 @@
/*
Simple DirectMedia Layer
- Copyright (C) 1997-2025 Sam Lantinga <[email protected]>
+ Copyright (C) 1997-2026 Sam Lantinga <[email protected]>
This software is provided 'as-is', without any express or implied
warranty. In no event will the authors be held liable for any damages
@@ -292,7 +292,7 @@ static bool maybe_resize(SDL_HashTable *ht)
bool SDL_InsertIntoHashTable(SDL_HashTable *table, const void *key, const void *value, bool replace)
{
- if (!table) {
+ CHECK_PARAM(!table) {
return SDL_InvalidParamError("table");
}
@@ -338,7 +338,7 @@ bool SDL_InsertIntoHashTable(SDL_HashTable *table, const void *key, const void *
bool SDL_FindInHashTable(const SDL_HashTable *table, const void *key, const void **value)
{
- if (!table) {
+ CHECK_PARAM(!table) {
if (value) {
*value = NULL;
}
@@ -364,7 +364,7 @@ bool SDL_FindInHashTable(const SDL_HashTable *table, const void *key, const void
bool SDL_RemoveFromHashTable(SDL_HashTable *table, const void *key)
{
- if (!table) {
+ CHECK_PARAM(!table) {
return SDL_InvalidParamError("table");
}
@@ -384,9 +384,10 @@ bool SDL_RemoveFromHashTable(SDL_HashTable *table, const void *key)
bool SDL_IterateHashTable(const SDL_HashTable *table, SDL_HashTableIterateCallback callback, void *userdata)
{
- if (!table) {
+ CHECK_PARAM(!table) {
return SDL_InvalidParamError("table");
- } else if (!callback) {
+ }
+ CHECK_PARAM(!callback) {
return SDL_InvalidParamError("callback");
}
@@ -410,7 +411,7 @@ bool SDL_IterateHashTable(const SDL_HashTable *table, SDL_HashTableIterateCallba
bool SDL_HashTableEmpty(SDL_HashTable *table)
{
- if (!table) {
+ CHECK_PARAM(!table) {
return SDL_InvalidParamError("table");
}
diff --git a/thirdparty/sdl/SDL_hashtable.h b/thirdparty/sdl/SDL_hashtable.h
index 598a6d6be13..e947efc22c8 100644
--- a/thirdparty/sdl/SDL_hashtable.h
+++ b/thirdparty/sdl/SDL_hashtable.h
@@ -1,6 +1,6 @@
/*
Simple DirectMedia Layer
- Copyright (C) 1997-2025 Sam Lantinga <[email protected]>
+ Copyright (C) 1997-2026 Sam Lantinga <[email protected]>
This software is provided 'as-is', without any express or implied
warranty. In no event will the authors be held liable for any damages
@@ -219,10 +219,10 @@ typedef void (SDLCALL *SDL_HashDestroyCallback)(void *userdata, const void *key,
* \returns true to keep iterating, false to stop iteration.
*
* \threadsafety A read lock is held during iteration, so other threads can
- * still access the the hash table, but threads attempting to
- * make changes will be blocked until iteration completes. If
- * this is a concern, do as little in the callback as possible
- * and finish iteration quickly.
+ * still access the hash table, but threads attempting to make
+ * changes will be blocked until iteration completes. If this
+ * is a concern, do as little in the callback as possible and
+ * finish iteration quickly.
*
* \since This datatype is available since SDL 3.4.0.
*
@@ -248,7 +248,7 @@ typedef bool (SDLCALL *SDL_HashTableIterateCallback)(void *userdata, const SDL_H
*
* You can specify an estimate of the number of items expected to be stored
* in the table, which can help make the table run more efficiently. The table
- * will preallocate resources to accomodate this number of items, which is
+ * will preallocate resources to accommodate this number of items, which is
* most useful if you intend to fill the table with a lot of data right after
* creating it. Otherwise, it might make more sense to specify the _minimum_
* you expect the table to hold and let it grow as necessary from there. This
@@ -422,7 +422,7 @@ extern bool SDL_HashTableEmpty(SDL_HashTable *table);
* \param table the hash table to iterate.
* \param callback the function pointer to call for each value.
* \param userdata a pointer that is passed to `callback`.
- * \returns true if iteration happened, false if not (bogus parameter, etc).
+ * \returns true if iteration happened, false if not (bogus parameter, etc.).
*
* \since This function is available since SDL 3.4.0.
*/
diff --git a/thirdparty/sdl/SDL_hints.c b/thirdparty/sdl/SDL_hints.c
index a10598f0ffe..36998c6f229 100644
--- a/thirdparty/sdl/SDL_hints.c
+++ b/thirdparty/sdl/SDL_hints.c
@@ -1,6 +1,6 @@
/*
Simple DirectMedia Layer
- Copyright (C) 1997-2025 Sam Lantinga <[email protected]>
+ Copyright (C) 1997-2026 Sam Lantinga <[email protected]>
This software is provided 'as-is', without any express or implied
warranty. In no event will the authors be held liable for any damages
@@ -87,7 +87,7 @@ static void SDLCALL CleanupHintProperty(void *userdata, void *value)
SDL_free(hint);
}
-static const char* GetHintEnvironmentVariable(const char *name)
+static const char *GetHintEnvironmentVariable(const char *name)
{
const char *result = SDL_getenv(name);
if (!result && name && *name) {
@@ -104,7 +104,7 @@ static const char* GetHintEnvironmentVariable(const char *name)
bool SDL_SetHintWithPriority(const char *name, const char *value, SDL_HintPriority priority)
{
- if (!name || !*name) {
+ CHECK_PARAM(!name || !*name) {
return SDL_InvalidParamError("name");
}
@@ -165,7 +165,7 @@ bool SDL_SetHintWithPriority(const char *name, const char *value, SDL_HintPriori
bool SDL_ResetHint(const char *name)
{
- if (!name || !*name) {
+ CHECK_PARAM(!name || !*name) {
return SDL_InvalidParamError("name");
}
@@ -316,9 +316,10 @@ bool SDL_GetHintBoolean(const char *name, bool default_value)
bool SDL_AddHintCallback(const char *name, SDL_HintCallback callback, void *userdata)
{
- if (!name || !*name) {
+ CHECK_PARAM(!name || !*name) {
return SDL_InvalidParamError("name");
- } else if (!callback) {
+ }
+ CHECK_PARAM(!callback) {
return SDL_InvalidParamError("callback");
}
diff --git a/thirdparty/sdl/SDL_hints_c.h b/thirdparty/sdl/SDL_hints_c.h
index dd54cba6709..d740eb77c63 100644
--- a/thirdparty/sdl/SDL_hints_c.h
+++ b/thirdparty/sdl/SDL_hints_c.h
@@ -1,6 +1,6 @@
/*
Simple DirectMedia Layer
- Copyright (C) 1997-2025 Sam Lantinga <[email protected]>
+ Copyright (C) 1997-2026 Sam Lantinga <[email protected]>
This software is provided 'as-is', without any express or implied
warranty. In no event will the authors be held liable for any damages
diff --git a/thirdparty/sdl/SDL_internal.h b/thirdparty/sdl/SDL_internal.h
index 20ec0fcb913..a7d46db8d7e 100644
--- a/thirdparty/sdl/SDL_internal.h
+++ b/thirdparty/sdl/SDL_internal.h
@@ -1,6 +1,6 @@
/*
Simple DirectMedia Layer
- Copyright (C) 1997-2025 Sam Lantinga <[email protected]>
+ Copyright (C) 1997-2026 Sam Lantinga <[email protected]>
This software is provided 'as-is', without any express or implied
warranty. In no event will the authors be held liable for any damages
@@ -62,7 +62,7 @@
#include "SDL_build_config.h"
-//#include "dynapi/SDL_dynapi.h"
+// #include "dynapi/SDL_dynapi.h"
#if SDL_DYNAMIC_API
#include "dynapi/SDL_dynapi_overrides.h"
@@ -191,11 +191,6 @@
#define SDL_VIDEO_RENDER_SW 1
#endif
-/* STB image conversion */
-#if !defined(SDL_HAVE_STB) && !defined(SDL_LEAN_AND_MEAN)
-#define SDL_HAVE_STB 1
-#endif
-
/* YUV formats
- handling of YUV surfaces
- blitting and conversion functions */
@@ -265,15 +260,55 @@ extern "C" {
#include "SDL_utils_c.h"
#include "SDL_hashtable.h"
+
+/* SDL_ExitProcess is not declared in any public header, although
+ it is shared between some parts of SDL, because we don't want
+ anything calling it without an extremely good reason. */
+extern SDL_NORETURN void SDL_ExitProcess(int exitcode);
+
+// Get just the process's binary name, no path. NULL if it doesn't make sense for a platform.
+// Can be something not a file, like a package ID on Android. Meant to be human-readable, not appended to a path, etc.
+// Calculates and caches the string on first call. String lives until SDL_Quit(). This is not a public API right now!
+extern const char *SDL_GetExeName(void);
+
+#ifdef HAVE_LIBC
+#define SDL_abort() abort()
+#else
+#define SDL_abort() do { \
+ SDL_TriggerBreakpoint(); \
+ SDL_ExitProcess(42); \
+ } while (0)
+#endif
+
#define PUSH_SDL_ERROR() \
{ char *_error = SDL_strdup(SDL_GetError());
#define POP_SDL_ERROR() \
SDL_SetError("%s", _error); SDL_free(_error); }
+#if defined(SDL_DISABLE_INVALID_PARAMS)
+#ifdef DEBUG
+// If you define SDL_DISABLE_INVALID_PARAMS, you're promising that you'll
+// never pass an invalid parameter to SDL, since it may crash or lead to
+// hard to diagnose bugs. Let's assert that this is true in debug builds.
+#define OBJECT_VALIDATION_REQUIRED
+#define CHECK_PARAM(invalid) SDL_assert_always(!(invalid)); if (false)
+#else
+#define CHECK_PARAM(invalid) if (false)
+#endif
+#elif defined(SDL_ASSERT_INVALID_PARAMS)
+#define OBJECT_VALIDATION_REQUIRED
+#define CHECK_PARAM(invalid) SDL_assert_always(!(invalid)); if (invalid)
+#else
+#define CHECK_PARAM(invalid) if (invalid)
+#endif
+
// Do any initialization that needs to happen before threads are started
extern void SDL_InitMainThread(void);
+// Return true if this thread has initialized video
+extern bool SDL_IsVideoThread(void);
+
/* The internal implementations of these functions have up to nanosecond precision.
We can expose these functions as part of the API if we want to later.
*/
diff --git a/thirdparty/sdl/SDL_list.c b/thirdparty/sdl/SDL_list.c
index 04cc0825b44..a17c40787af 100644
--- a/thirdparty/sdl/SDL_list.c
+++ b/thirdparty/sdl/SDL_list.c
@@ -1,6 +1,6 @@
/*
Simple DirectMedia Layer
- Copyright (C) 1997-2025 Sam Lantinga <[email protected]>
+ Copyright (C) 1997-2026 Sam Lantinga <[email protected]>
This software is provided 'as-is', without any express or implied
warranty. In no event will the authors be held liable for any damages
diff --git a/thirdparty/sdl/SDL_list.h b/thirdparty/sdl/SDL_list.h
index 83ec844b018..bdfbc35160d 100644
--- a/thirdparty/sdl/SDL_list.h
+++ b/thirdparty/sdl/SDL_list.h
@@ -1,6 +1,6 @@
/*
Simple DirectMedia Layer
- Copyright (C) 1997-2025 Sam Lantinga <[email protected]>
+ Copyright (C) 1997-2026 Sam Lantinga <[email protected]>
This software is provided 'as-is', without any express or implied
warranty. In no event will the authors be held liable for any damages
diff --git a/thirdparty/sdl/SDL_log.c b/thirdparty/sdl/SDL_log.c
index 10a814ff1b2..0d1ee3f91c3 100644
--- a/thirdparty/sdl/SDL_log.c
+++ b/thirdparty/sdl/SDL_log.c
@@ -1,6 +1,6 @@
/*
Simple DirectMedia Layer
- Copyright (C) 1997-2025 Sam Lantinga <[email protected]>
+ Copyright (C) 1997-2026 Sam Lantinga <[email protected]>
This software is provided 'as-is', without any express or implied
warranty. In no event will the authors be held liable for any damages
@@ -24,6 +24,10 @@
#include "core/windows/SDL_windows.h"
#endif
+#if defined(SDL_PLATFORM_NGAGE)
+#include "core/ngage/SDL_ngage.h"
+#endif
+
// Simple log messages in SDL
#include "SDL_log_c.h"
@@ -375,6 +379,9 @@ void SDL_ResetLogPriorities(void)
SDL_LockMutex(SDL_log_lock);
{
+ const char *env = SDL_getenv("DEBUG_INVOCATION");
+ bool debug = (env && *env && *env != '0');
+
CleanupLogPriorities();
SDL_log_default_priority = SDL_LOG_PRIORITY_INVALID;
@@ -397,7 +404,11 @@ void SDL_ResetLogPriorities(void)
switch (i) {
case SDL_LOG_CATEGORY_APPLICATION:
- SDL_log_priorities[i] = SDL_LOG_PRIORITY_INFO;
+ if (debug) {
+ SDL_log_priorities[i] = SDL_LOG_PRIORITY_DEBUG;
+ } else {
+ SDL_log_priorities[i] = SDL_LOG_PRIORITY_INFO;
+ }
break;
case SDL_LOG_CATEGORY_ASSERT:
SDL_log_priorities[i] = SDL_LOG_PRIORITY_WARN;
@@ -406,7 +417,11 @@ void SDL_ResetLogPriorities(void)
SDL_log_priorities[i] = SDL_LOG_PRIORITY_VERBOSE;
break;
default:
- SDL_log_priorities[i] = SDL_LOG_PRIORITY_ERROR;
+ if (debug) {
+ SDL_log_priorities[i] = SDL_LOG_PRIORITY_DEBUG;
+ } else {
+ SDL_log_priorities[i] = SDL_LOG_PRIORITY_ERROR;
+ }
break;
}
}
@@ -450,7 +465,7 @@ bool SDL_SetLogPriorityPrefix(SDL_LogPriority priority, const char *prefix)
{
char *prefix_copy;
- if (priority <= SDL_LOG_PRIORITY_INVALID || priority >= SDL_LOG_PRIORITY_COUNT) {
+ CHECK_PARAM(priority <= SDL_LOG_PRIORITY_INVALID || priority >= SDL_LOG_PRIORITY_COUNT) {
return SDL_InvalidParamError("priority");
}
@@ -597,15 +612,21 @@ void SDL_LogMessageV(int category, SDL_LogPriority priority, SDL_PRINTF_FORMAT_S
}
// If message truncated, allocate and re-render
- if (len >= sizeof(stack_buf) && SDL_size_add_check_overflow(len, 1, &len_plus_term)) {
- // Allocate exactly what we need, including the zero-terminator
- message = (char *)SDL_malloc(len_plus_term);
- if (!message) {
- return;
+ if (len >= sizeof(stack_buf)) {
+ if (SDL_size_add_check_overflow(len, 1, &len_plus_term)) {
+ // Allocate exactly what we need, including the zero-terminator
+ message = (char *)SDL_malloc(len_plus_term);
+ if (!message) {
+ return;
+ }
+ va_copy(aq, ap);
+ len = SDL_vsnprintf(message, len_plus_term, fmt, aq);
+ va_end(aq);
+ } else {
+ // Allocation would overflow, use truncated message
+ message = stack_buf;
+ len = sizeof(stack_buf);
}
- va_copy(aq, ap);
- len = SDL_vsnprintf(message, len_plus_term, fmt, aq);
- va_end(aq);
} else {
message = stack_buf;
}
@@ -767,9 +788,22 @@ static void SDLCALL SDL_LogOutput(void *userdata, int category, SDL_LogPriority
(void)fclose(pFile);
}
}
+#elif defined(SDL_PLATFORM_NGAGE)
+ {
+ NGAGE_DebugPrintf("%s%s", GetLogPriorityPrefix(priority), message);
+#ifdef ENABLE_FILE_LOG
+ FILE *pFile;
+ pFile = fopen("E:/SDL_Log.txt", "a");
+ if (pFile) {
+ (void)fprintf(pFile, "%s%s\n", GetLogPriorityPrefix(priority), message);
+ (void)fclose(pFile);
+ }
+#endif
+ }
#endif
#if defined(HAVE_STDIO_H) && \
!(defined(SDL_PLATFORM_APPLE) && (defined(SDL_VIDEO_DRIVER_COCOA) || defined(SDL_VIDEO_DRIVER_UIKIT))) && \
+ !(defined(SDL_PLATFORM_NGAGE)) && \
!(defined(SDL_PLATFORM_WIN32))
(void)fprintf(stderr, "%s%s\n", GetLogPriorityPrefix(priority), message);
#endif
diff --git a/thirdparty/sdl/SDL_log_c.h b/thirdparty/sdl/SDL_log_c.h
index 887a3253806..9349c348730 100644
--- a/thirdparty/sdl/SDL_log_c.h
+++ b/thirdparty/sdl/SDL_log_c.h
@@ -1,6 +1,6 @@
/*
Simple DirectMedia Layer
- Copyright (C) 1997-2025 Sam Lantinga <[email protected]>
+ Copyright (C) 1997-2026 Sam Lantinga <[email protected]>
This software is provided 'as-is', without any express or implied
warranty. In no event will the authors be held liable for any damages
diff --git a/thirdparty/sdl/SDL_properties.c b/thirdparty/sdl/SDL_properties.c
index 42d48454580..b3753451ff8 100644
--- a/thirdparty/sdl/SDL_properties.c
+++ b/thirdparty/sdl/SDL_properties.c
@@ -1,6 +1,6 @@
/*
Simple DirectMedia Layer
- Copyright (C) 1997-2025 Sam Lantinga <[email protected]>
+ Copyright (C) 1997-2026 Sam Lantinga <[email protected]>
This software is provided 'as-is', without any express or implied
warranty. In no event will the authors be held liable for any damages
@@ -250,10 +250,10 @@ static bool SDLCALL CopyOneProperty(void *userdata, const SDL_HashTable *table,
bool SDL_CopyProperties(SDL_PropertiesID src, SDL_PropertiesID dst)
{
- if (!src) {
+ CHECK_PARAM(!src) {
return SDL_InvalidParamError("src");
}
- if (!dst) {
+ CHECK_PARAM(!dst) {
return SDL_InvalidParamError("dst");
}
@@ -261,11 +261,11 @@ bool SDL_CopyProperties(SDL_PropertiesID src, SDL_PropertiesID dst)
SDL_Properties *dst_properties = NULL;
SDL_FindInHashTable(SDL_properties, (const void *)(uintptr_t)src, (const void **)&src_properties);
- if (!src_properties) {
+ CHECK_PARAM(!src_properties) {
return SDL_InvalidParamError("src");
}
SDL_FindInHashTable(SDL_properties, (const void *)(uintptr_t)dst, (const void **)&dst_properties);
- if (!dst_properties) {
+ CHECK_PARAM(!dst_properties) {
return SDL_InvalidParamError("dst");
}
@@ -287,12 +287,12 @@ bool SDL_LockProperties(SDL_PropertiesID props)
{
SDL_Properties *properties = NULL;
- if (!props) {
+ CHECK_PARAM(!props) {
return SDL_InvalidParamError("props");
}
SDL_FindInHashTable(SDL_properties, (const void *)(uintptr_t)props, (const void **)&properties);
- if (!properties) {
+ CHECK_PARAM(!properties) {
return SDL_InvalidParamError("props");
}
@@ -321,17 +321,17 @@ static bool SDL_PrivateSetProperty(SDL_PropertiesID props, const char *name, SDL
SDL_Properties *properties = NULL;
bool result = true;
- if (!props) {
+ CHECK_PARAM(!props) {
SDL_FreePropertyWithCleanup(NULL, property, NULL, true);
return SDL_InvalidParamError("props");
}
- if (!name || !*name) {
+ CHECK_PARAM(!name || !*name) {
SDL_FreePropertyWithCleanup(NULL, property, NULL, true);
return SDL_InvalidParamError("name");
}
SDL_FindInHashTable(SDL_properties, (const void *)(uintptr_t)props, (const void **)&properties);
- if (!properties) {
+ CHECK_PARAM(!properties) {
SDL_FreePropertyWithCleanup(NULL, property, NULL, true);
return SDL_InvalidParamError("props");
}
@@ -409,7 +409,7 @@ static void SDLCALL CleanupSurface(void *userdata, void *value)
{
SDL_Surface *surface = (SDL_Surface *)value;
- //SDL_DestroySurface(surface);
+ // SDL_DestroySurface(surface);
}
bool SDL_SetSurfaceProperty(SDL_PropertiesID props, const char *name, SDL_Surface *surface)
@@ -755,15 +755,15 @@ bool SDL_EnumerateProperties(SDL_PropertiesID props, SDL_EnumeratePropertiesCall
{
SDL_Properties *properties = NULL;
- if (!props) {
+ CHECK_PARAM(!props) {
return SDL_InvalidParamError("props");
}
- if (!callback) {
+ CHECK_PARAM(!callback) {
return SDL_InvalidParamError("callback");
}
SDL_FindInHashTable(SDL_properties, (const void *)(uintptr_t)props, (const void **)&properties);
- if (!properties) {
+ CHECK_PARAM(!properties) {
return SDL_InvalidParamError("props");
}
@@ -813,7 +813,7 @@ void SDL_DestroyProperties(SDL_PropertiesID props)
{
if (props) {
// this can't just use RemoveFromHashTable with SDL_FreeProperties as the destructor, because
- // other destructors under this might cause use to attempt a recursive lock on SDL_properties,
+ // other destructors under this might cause us to attempt a recursive lock on SDL_properties,
// which isn't allowed with rwlocks. So manually look it up and remove/free it.
SDL_Properties *properties = NULL;
if (SDL_FindInHashTable(SDL_properties, (const void *)(uintptr_t)props, (const void **)&properties)) {
diff --git a/thirdparty/sdl/SDL_properties_c.h b/thirdparty/sdl/SDL_properties_c.h
index 8d1d39daea3..f48b2de71ca 100644
--- a/thirdparty/sdl/SDL_properties_c.h
+++ b/thirdparty/sdl/SDL_properties_c.h
@@ -1,6 +1,6 @@
/*
Simple DirectMedia Layer
- Copyright (C) 1997-2025 Sam Lantinga <[email protected]>
+ Copyright (C) 1997-2026 Sam Lantinga <[email protected]>
This software is provided 'as-is', without any express or implied
warranty. In no event will the authors be held liable for any damages
diff --git a/thirdparty/sdl/SDL_utils.c b/thirdparty/sdl/SDL_utils.c
index f2090747a8d..146d8163414 100644
--- a/thirdparty/sdl/SDL_utils.c
+++ b/thirdparty/sdl/SDL_utils.c
@@ -1,6 +1,6 @@
/*
Simple DirectMedia Layer
- Copyright (C) 1997-2025 Sam Lantinga <[email protected]>
+ Copyright (C) 1997-2026 Sam Lantinga <[email protected]>
This software is provided 'as-is', without any express or implied
warranty. In no event will the authors be held liable for any damages
@@ -26,6 +26,14 @@
#include "joystick/SDL_joystick_c.h" // For SDL_GetGamepadTypeFromVIDPID()
+#ifdef SDL_PLATFORM_EMSCRIPTEN
+#include <emscripten.h>
+
+EMSCRIPTEN_KEEPALIVE void Emscripten_force_free(void *ptr)
+{
+ free(ptr); // This should NOT be SDL_free()
+}
+#endif
// Common utility functions that aren't in the public API
@@ -103,7 +111,8 @@ void SDL_CalculateFraction(float x, int *numerator, int *denominator)
bool SDL_startswith(const char *string, const char *prefix)
{
- if (SDL_strncmp(string, prefix, SDL_strlen(prefix)) == 0) {
+ if (string && prefix &&
+ SDL_strncmp(string, prefix, SDL_strlen(prefix)) == 0) {
return true;
}
return false;
@@ -137,6 +146,30 @@ Uint32 SDL_GetNextObjectID(void)
static SDL_InitState SDL_objects_init;
static SDL_HashTable *SDL_objects;
+bool SDL_object_validation = true;
+
+static void SDLCALL SDL_InvalidParamChecksChanged(void *userdata, const char *name, const char *oldValue, const char *hint)
+{
+ bool validation_enabled = true;
+
+#ifndef OBJECT_VALIDATION_REQUIRED
+ if (hint) {
+ switch (*hint) {
+ case '0':
+ case '1':
+ validation_enabled = false;
+ break;
+ case '2':
+ validation_enabled = true;
+ break;
+ default:
+ break;
+ }
+ }
+#endif // !OBJECT_VALIDATION_REQUIRED
+
+ SDL_object_validation = validation_enabled;
+}
static Uint32 SDLCALL SDL_HashObject(void *unused, const void *key)
{
@@ -159,6 +192,7 @@ void SDL_SetObjectValid(void *object, SDL_ObjectType type, bool valid)
if (!initialized) {
return;
}
+ SDL_AddHintCallback(SDL_HINT_INVALID_PARAM_CHECKS, SDL_InvalidParamChecksChanged, NULL);
}
if (valid) {
@@ -168,12 +202,8 @@ void SDL_SetObjectValid(void *object, SDL_ObjectType type, bool valid)
}
}
-bool SDL_ObjectValid(void *object, SDL_ObjectType type)
+bool SDL_FindObject(void *object, SDL_ObjectType type)
{
- if (!object) {
- return false;
- }
-
const void *object_type;
if (!SDL_FindInHashTable(SDL_objects, object, &object_type)) {
return false;
@@ -229,7 +259,7 @@ static bool SDLCALL LogOneLeakedObject(void *userdata, const SDL_HashTable *tabl
#undef SDLOBJTYPECASE
default: break;
}
- SDL_Log("Leaked %s (%p)", type, object);
+ SDL_LogDebug(SDL_LOG_CATEGORY_SYSTEM, "Leaked %s (%p)", type, object);
return true; // keep iterating.
}
@@ -238,10 +268,10 @@ void SDL_SetObjectsInvalid(void)
if (SDL_ShouldQuit(&SDL_objects_init)) {
// Log any leaked objects
SDL_IterateHashTable(SDL_objects, LogOneLeakedObject, NULL);
- SDL_assert(SDL_HashTableEmpty(SDL_objects));
SDL_DestroyHashTable(SDL_objects);
SDL_objects = NULL;
SDL_SetInitialized(&SDL_objects_init, false);
+ SDL_RemoveHintCallback(SDL_HINT_INVALID_PARAM_CHECKS, SDL_InvalidParamChecksChanged, NULL);
}
}
@@ -355,6 +385,39 @@ int SDL_URIToLocal(const char *src, char *dst)
return -1;
}
+bool SDL_IsURI(const char *uri)
+{
+ /* A valid URI begins with a letter and is followed by any sequence of
+ * letters, digits, '+', '.', or '-'.
+ */
+ if (!uri) {
+ return false;
+ }
+
+ // The first character of the scheme must be a letter.
+ if (!((*uri >= 'a' && *uri <= 'z') || (*uri >= 'A' && *uri <= 'Z'))) {
+ return false;
+ }
+
+ /* If the colon is found before encountering the end of the string or
+ * any invalid characters, the scheme can be considered valid.
+ */
+ while (*uri) {
+ if (!((*uri >= 'a' && *uri <= 'z') ||
+ (*uri >= 'A' && *uri <= 'Z') ||
+ (*uri >= '0' && *uri <= '9') ||
+ *uri == '+' || *uri == '-' || *uri == '.')) {
+ return false;
+ }
+
+ if (*++uri == ':') {
+ return true;
+ }
+ }
+
+ return false;
+}
+
// This is a set of per-thread persistent strings that we can return from the SDL API.
// This is used for short strings that might persist past the lifetime of the object
// they are related to.
@@ -424,6 +487,7 @@ char *SDL_CreateDeviceName(Uint16 vendor, Uint16 product, const char *vendor_nam
const char *prefix;
const char *replacement;
} replacements[] = {
+ { "(Standard system devices) ", "" },
{ "8BitDo Tech Ltd", "8BitDo" },
{ "ASTRO Gaming", "ASTRO" },
{ "Bensussen Deutsch & Associates,Inc.(BDA)", "BDA" },
@@ -552,3 +616,9 @@ char *SDL_CreateDeviceName(Uint16 vendor, Uint16 product, const char *vendor_nam
return name;
}
+
+
+void SDL_DebugLogBackend(const char *subsystem, const char *backend)
+{
+ SDL_LogDebug(SDL_LOG_CATEGORY_SYSTEM, "SDL chose %s backend '%s'", subsystem, backend);
+}
diff --git a/thirdparty/sdl/SDL_utils_c.h b/thirdparty/sdl/SDL_utils_c.h
index 5e0e8f519eb..a49eaa11b66 100644
--- a/thirdparty/sdl/SDL_utils_c.h
+++ b/thirdparty/sdl/SDL_utils_c.h
@@ -1,6 +1,6 @@
/*
Simple DirectMedia Layer
- Copyright (C) 1997-2025 Sam Lantinga <[email protected]>
+ Copyright (C) 1997-2026 Sam Lantinga <[email protected]>
This software is provided 'as-is', without any express or implied
warranty. In no event will the authors be held liable for any damages
@@ -48,6 +48,9 @@ extern bool SDL_endswith(const char *string, const char *suffix);
*/
extern int SDL_URIToLocal(const char *src, char *dst);
+/// Determine if a URI is valid by validating the scheme.
+extern bool SDL_IsURI(const char *uri);
+
typedef enum
{
SDL_OBJECT_TYPE_UNKNOWN,
@@ -67,12 +70,37 @@ typedef enum
extern Uint32 SDL_GetNextObjectID(void);
extern void SDL_SetObjectValid(void *object, SDL_ObjectType type, bool valid);
-extern bool SDL_ObjectValid(void *object, SDL_ObjectType type);
+extern bool SDL_FindObject(void *object, SDL_ObjectType type);
extern int SDL_GetObjects(SDL_ObjectType type, void **objects, int count);
extern void SDL_SetObjectsInvalid(void);
+extern bool SDL_object_validation;
+
+SDL_FORCE_INLINE bool SDL_ObjectValid(void *object, SDL_ObjectType type)
+{
+ if (!object) {
+ return false;
+ }
+
+ if (!SDL_object_validation) {
+ return true;
+ }
+
+ return SDL_FindObject(object, type);
+}
+
extern const char *SDL_GetPersistentString(const char *string);
extern char *SDL_CreateDeviceName(Uint16 vendor, Uint16 product, const char *vendor_name, const char *product_name, const char *default_name);
+// Log what backend a subsystem chose, if a hint was set to do so. Useful for debugging.
+extern void SDL_DebugLogBackend(const char *subsystem, const char *backend);
+
+#ifdef SDL_PLATFORM_EMSCRIPTEN
+// even though we reference the C runtime's free() in other places, it appears
+// to be inlined more aggressively in Emscripten 4, so we need a reference to
+// it here, too, so inlined Javascript doesn't fail to find it.
+extern void Emscripten_force_free(void *ptr);
+#endif
+
#endif // SDL_utils_h_
diff --git a/thirdparty/sdl/atomic/SDL_atomic.c b/thirdparty/sdl/atomic/SDL_atomic.c
index 5e7774da853..f14bd106dc2 100644
--- a/thirdparty/sdl/atomic/SDL_atomic.c
+++ b/thirdparty/sdl/atomic/SDL_atomic.c
@@ -1,6 +1,6 @@
/*
Simple DirectMedia Layer
- Copyright (C) 1997-2025 Sam Lantinga <[email protected]>
+ Copyright (C) 1997-2026 Sam Lantinga <[email protected]>
This software is provided 'as-is', without any express or implied
warranty. In no event will the authors be held liable for any damages
@@ -33,49 +33,18 @@
#include <atomic.h>
#endif
-// The __atomic_load_n() intrinsic showed up in different times for different compilers.
-#ifdef __clang__
-#if __has_builtin(__atomic_load_n) || defined(HAVE_GCC_ATOMICS)
-/* !!! FIXME: this advertises as available in the NDK but uses an external symbol we don't have.
- It might be in a later NDK or we might need an extra library? --ryan. */
-#ifndef SDL_PLATFORM_ANDROID
+// The __atomic intrinsics showed up in different times for different compilers.
+#if (defined(__GNUC__) && (__GNUC__ >= 5)) || (defined(__clang__) && defined(HAVE_GCC_ATOMICS))
#define HAVE_ATOMIC_LOAD_N 1
-#endif
-#endif
-#elif defined(__GNUC__)
-#if (__GNUC__ >= 5)
+#define HAVE_ATOMIC_EXCHANGE_N 1
+#else
+#if SDL_HAS_BUILTIN(__atomic_load_n)
#define HAVE_ATOMIC_LOAD_N 1
#endif
+#if SDL_HAS_BUILTIN(__atomic_exchange_n)
+#define HAVE_ATOMIC_EXCHANGE_N 1
+#endif
#endif
-
-/* *INDENT-OFF* */ // clang-format off
-#if defined(__WATCOMC__) && defined(__386__)
-SDL_COMPILE_TIME_ASSERT(intsize, 4==sizeof(int));
-#define HAVE_WATCOM_ATOMICS
-extern __inline int _SDL_xchg_watcom(volatile int *a, int v);
-#pragma aux _SDL_xchg_watcom = \
- "lock xchg [ecx], eax" \
- parm [ecx] [eax] \
- value [eax] \
- modify exact [eax];
-
-extern __inline unsigned char _SDL_cmpxchg_watcom(volatile int *a, int newval, int oldval);
-#pragma aux _SDL_cmpxchg_watcom = \
- "lock cmpxchg [edx], ecx" \
- "setz al" \
- parm [edx] [ecx] [eax] \
- value [al] \
- modify exact [eax];
-
-extern __inline int _SDL_xadd_watcom(volatile int *a, int v);
-#pragma aux _SDL_xadd_watcom = \
- "lock xadd [ecx], eax" \
- parm [ecx] [eax] \
- value [eax] \
- modify exact [eax];
-
-#endif // __WATCOMC__ && __386__
-/* *INDENT-ON* */ // clang-format on
/*
If any of the operations are not provided then we must emulate some
@@ -100,7 +69,7 @@ extern __inline int _SDL_xadd_watcom(volatile int *a, int v);
Contributed by Bob Pendleton, [email protected]
*/
-#if !defined(HAVE_MSC_ATOMICS) && !defined(HAVE_GCC_ATOMICS) && !defined(SDL_PLATFORM_MACOS) && !defined(SDL_PLATFORM_SOLARIS) && !defined(HAVE_WATCOM_ATOMICS)
+#if !defined(HAVE_MSC_ATOMICS) && !defined(HAVE_GCC_ATOMICS) && !defined(SDL_PLATFORM_MACOS) && !defined(SDL_PLATFORM_SOLARIS)
#define EMULATE_CAS 1
#endif
@@ -127,8 +96,6 @@ bool SDL_CompareAndSwapAtomicInt(SDL_AtomicInt *a, int oldval, int newval)
#ifdef HAVE_MSC_ATOMICS
SDL_COMPILE_TIME_ASSERT(atomic_cas, sizeof(long) == sizeof(a->value));
return _InterlockedCompareExchange((long *)&a->value, (long)newval, (long)oldval) == (long)oldval;
-#elif defined(HAVE_WATCOM_ATOMICS)
- return _SDL_cmpxchg_watcom((volatile int *)&a->value, newval, oldval);
#elif defined(HAVE_GCC_ATOMICS)
return __sync_bool_compare_and_swap(&a->value, oldval, newval);
#elif defined(SDL_PLATFORM_MACOS) // this is deprecated in 10.12 sdk; favor gcc atomics.
@@ -157,13 +124,10 @@ bool SDL_CompareAndSwapAtomicU32(SDL_AtomicU32 *a, Uint32 oldval, Uint32 newval)
#ifdef HAVE_MSC_ATOMICS
SDL_COMPILE_TIME_ASSERT(atomic_cas, sizeof(long) == sizeof(a->value));
return _InterlockedCompareExchange((long *)&a->value, (long)newval, (long)oldval) == (long)oldval;
-#elif defined(HAVE_WATCOM_ATOMICS)
- SDL_COMPILE_TIME_ASSERT(atomic_cas, sizeof(int) == sizeof(a->value));
- return _SDL_cmpxchg_watcom((volatile int *)&a->value, (int)newval, (int)oldval);
#elif defined(HAVE_GCC_ATOMICS)
return __sync_bool_compare_and_swap(&a->value, oldval, newval);
#elif defined(SDL_PLATFORM_MACOS) // this is deprecated in 10.12 sdk; favor gcc atomics.
- return OSAtomicCompareAndSwap32Barrier((int32_t)oldval, (int32_t)newval, (int32_t*)&a->value);
+ return OSAtomicCompareAndSwap32Barrier((int32_t)oldval, (int32_t)newval, (int32_t *)&a->value);
#elif defined(SDL_PLATFORM_SOLARIS)
SDL_COMPILE_TIME_ASSERT(atomic_cas, sizeof(uint_t) == sizeof(a->value));
return ((Uint32)atomic_cas_uint((volatile uint_t *)&a->value, (uint_t)oldval, (uint_t)newval) == oldval);
@@ -187,8 +151,6 @@ bool SDL_CompareAndSwapAtomicPointer(void **a, void *oldval, void *newval)
{
#ifdef HAVE_MSC_ATOMICS
return _InterlockedCompareExchangePointer(a, newval, oldval) == oldval;
-#elif defined(HAVE_WATCOM_ATOMICS)
- return _SDL_cmpxchg_watcom((int *)a, (long)newval, (long)oldval);
#elif defined(HAVE_GCC_ATOMICS)
return __sync_bool_compare_and_swap(a, oldval, newval);
#elif defined(SDL_PLATFORM_MACOS) && defined(__LP64__) // this is deprecated in 10.12 sdk; favor gcc atomics.
@@ -218,9 +180,14 @@ int SDL_SetAtomicInt(SDL_AtomicInt *a, int v)
#ifdef HAVE_MSC_ATOMICS
SDL_COMPILE_TIME_ASSERT(atomic_set, sizeof(long) == sizeof(a->value));
return _InterlockedExchange((long *)&a->value, v);
-#elif defined(HAVE_WATCOM_ATOMICS)
- return _SDL_xchg_watcom(&a->value, v);
+#elif defined(HAVE_ATOMIC_EXCHANGE_N)
+ return __atomic_exchange_n(&a->value, v, __ATOMIC_SEQ_CST);
#elif defined(HAVE_GCC_ATOMICS)
+ // __sync_lock_test_and_set() is designed for locking rather than a
+ // generic atomic exchange, so it only provides an acquire barrier
+ // and may not store the exact value on all architectures. We prefer
+ // __atomic_exchange_n() instead on all modern compilers.
+ __sync_synchronize();
return __sync_lock_test_and_set(&a->value, v);
#elif defined(SDL_PLATFORM_SOLARIS)
SDL_COMPILE_TIME_ASSERT(atomic_set, sizeof(uint_t) == sizeof(a->value));
@@ -239,9 +206,14 @@ Uint32 SDL_SetAtomicU32(SDL_AtomicU32 *a, Uint32 v)
#ifdef HAVE_MSC_ATOMICS
SDL_COMPILE_TIME_ASSERT(atomic_set, sizeof(long) == sizeof(a->value));
return _InterlockedExchange((long *)&a->value, v);
-#elif defined(HAVE_WATCOM_ATOMICS)
- return _SDL_xchg_watcom(&a->value, v);
+#elif defined(HAVE_ATOMIC_EXCHANGE_N)
+ return __atomic_exchange_n(&a->value, v, __ATOMIC_SEQ_CST);
#elif defined(HAVE_GCC_ATOMICS)
+ // __sync_lock_test_and_set() is designed for locking rather than a
+ // generic atomic exchange, so it only provides an acquire barrier
+ // and may not store the exact value on all architectures. We prefer
+ // __atomic_exchange_n() instead on all modern compilers.
+ __sync_synchronize();
return __sync_lock_test_and_set(&a->value, v);
#elif defined(SDL_PLATFORM_SOLARIS)
SDL_COMPILE_TIME_ASSERT(atomic_set, sizeof(uint_t) == sizeof(a->value));
@@ -259,9 +231,14 @@ void *SDL_SetAtomicPointer(void **a, void *v)
{
#ifdef HAVE_MSC_ATOMICS
return _InterlockedExchangePointer(a, v);
-#elif defined(HAVE_WATCOM_ATOMICS)
- return (void *)_SDL_xchg_watcom((int *)a, (long)v);
+#elif defined(HAVE_ATOMIC_EXCHANGE_N)
+ return __atomic_exchange_n(a, v, __ATOMIC_SEQ_CST);
#elif defined(HAVE_GCC_ATOMICS)
+ // __sync_lock_test_and_set() is designed for locking rather than a
+ // generic atomic exchange, so it only provides an acquire barrier
+ // and may not store the exact value on all architectures. We prefer
+ // __atomic_exchange_n() instead on all modern compilers.
+ __sync_synchronize();
return __sync_lock_test_and_set(a, v);
#elif defined(SDL_PLATFORM_SOLARIS)
return atomic_swap_ptr(a, v);
@@ -279,9 +256,6 @@ int SDL_AddAtomicInt(SDL_AtomicInt *a, int v)
#ifdef HAVE_MSC_ATOMICS
SDL_COMPILE_TIME_ASSERT(atomic_add, sizeof(long) == sizeof(a->value));
return _InterlockedExchangeAdd((long *)&a->value, v);
-#elif defined(HAVE_WATCOM_ATOMICS)
- SDL_COMPILE_TIME_ASSERT(atomic_add, sizeof(int) == sizeof(a->value));
- return _SDL_xadd_watcom((volatile int *)&a->value, v);
#elif defined(HAVE_GCC_ATOMICS)
return __sync_fetch_and_add(&a->value, v);
#elif defined(SDL_PLATFORM_SOLARIS)
@@ -298,15 +272,40 @@ int SDL_AddAtomicInt(SDL_AtomicInt *a, int v)
#endif
}
+Uint32 SDL_AddAtomicU32(SDL_AtomicU32 *a, int v)
+{
+#ifdef HAVE_MSC_ATOMICS
+ SDL_COMPILE_TIME_ASSERT(atomic_add, sizeof(long) == sizeof(a->value));
+ return (Uint32)_InterlockedExchangeAdd((long *)&a->value, v);
+#elif defined(HAVE_GCC_ATOMICS)
+ return __sync_fetch_and_add(&a->value, v);
+#elif defined(SDL_PLATFORM_SOLARIS)
+ Uint32 pv = a->value;
+ membar_consumer();
+ atomic_add_int((volatile uint_t *)&a->value, v);
+ return pv;
+#else
+ Uint32 value;
+ do {
+ value = a->value;
+ } while (!SDL_CompareAndSwapAtomicU32(a, value, (value + v)));
+ return value;
+#endif
+}
+
int SDL_GetAtomicInt(SDL_AtomicInt *a)
{
#ifdef HAVE_ATOMIC_LOAD_N
return __atomic_load_n(&a->value, __ATOMIC_SEQ_CST);
-#elif defined(HAVE_MSC_ATOMICS)
- SDL_COMPILE_TIME_ASSERT(atomic_get, sizeof(long) == sizeof(a->value));
- return _InterlockedOr((long *)&a->value, 0);
-#elif defined(HAVE_WATCOM_ATOMICS)
- return _SDL_xadd_watcom(&a->value, 0);
+#elif defined(HAVE_MSC_ATOMICS) && (defined(_M_ARM64) || defined(_M_ARM64EC))
+ SDL_COMPILE_TIME_ASSERT(atomic_get_int, sizeof(__int32) == sizeof(a->value));
+ return (int)__ldar32((unsigned __int32 *)&a->value);
+#elif defined(HAVE_MSC_ATOMICS) && (defined(_M_X64) || defined(_M_IX86))
+ SDL_COMPILE_TIME_ASSERT(atomic_get_int, sizeof(int) == sizeof(a->value));
+ SDL_CompilerBarrier();
+ int value = *(volatile int *)&a->value;
+ SDL_CompilerBarrier();
+ return value;
#elif defined(HAVE_GCC_ATOMICS)
return __sync_or_and_fetch(&a->value, 0);
#elif defined(SDL_PLATFORM_MACOS) // this is deprecated in 10.12 sdk; favor gcc atomics.
@@ -326,12 +325,15 @@ Uint32 SDL_GetAtomicU32(SDL_AtomicU32 *a)
{
#ifdef HAVE_ATOMIC_LOAD_N
return __atomic_load_n(&a->value, __ATOMIC_SEQ_CST);
-#elif defined(HAVE_MSC_ATOMICS)
- SDL_COMPILE_TIME_ASSERT(atomic_get, sizeof(long) == sizeof(a->value));
- return (Uint32)_InterlockedOr((long *)&a->value, 0);
-#elif defined(HAVE_WATCOM_ATOMICS)
- SDL_COMPILE_TIME_ASSERT(atomic_get, sizeof(int) == sizeof(a->value));
- return (Uint32)_SDL_xadd_watcom((volatile int *)&a->value, 0);
+#elif defined(HAVE_MSC_ATOMICS) && (defined(_M_ARM64) || defined(_M_ARM64EC))
+ SDL_COMPILE_TIME_ASSERT(atomic_get_u32, sizeof(__int32) == sizeof(a->value));
+ return __ldar32((unsigned __int32 *)&a->value);
+#elif defined(HAVE_MSC_ATOMICS) && (defined(_M_X64) || defined(_M_IX86))
+ SDL_COMPILE_TIME_ASSERT(atomic_get_u32, sizeof(Uint32) == sizeof(a->value));
+ SDL_CompilerBarrier();
+ Uint32 value = *(volatile Uint32 *)&a->value;
+ SDL_CompilerBarrier();
+ return value;
#elif defined(HAVE_GCC_ATOMICS)
return __sync_or_and_fetch(&a->value, 0);
#elif defined(SDL_PLATFORM_MACOS) // this is deprecated in 10.12 sdk; favor gcc atomics.
@@ -352,8 +354,14 @@ void *SDL_GetAtomicPointer(void **a)
{
#ifdef HAVE_ATOMIC_LOAD_N
return __atomic_load_n(a, __ATOMIC_SEQ_CST);
-#elif defined(HAVE_MSC_ATOMICS)
- return _InterlockedCompareExchangePointer(a, NULL, NULL);
+#elif defined(HAVE_MSC_ATOMICS) && (defined(_M_ARM64) || defined(_M_ARM64EC))
+ SDL_COMPILE_TIME_ASSERT(atomic_get_ptr, sizeof(__int64) == sizeof(*a));
+ return (void *)__ldar64((unsigned __int64 *)a);
+#elif defined(HAVE_MSC_ATOMICS) && (defined(_M_X64) || defined(_M_IX86))
+ SDL_CompilerBarrier();
+ void *value = *(void * volatile *)a;
+ SDL_CompilerBarrier();
+ return value;
#elif defined(HAVE_GCC_ATOMICS)
return __sync_val_compare_and_swap(a, (void *)0, (void *)0);
#elif defined(SDL_PLATFORM_SOLARIS)
diff --git a/thirdparty/sdl/atomic/SDL_spinlock.c b/thirdparty/sdl/atomic/SDL_spinlock.c
index 8e35c8a74b0..c048866604c 100644
--- a/thirdparty/sdl/atomic/SDL_spinlock.c
+++ b/thirdparty/sdl/atomic/SDL_spinlock.c
@@ -1,6 +1,6 @@
/*
Simple DirectMedia Layer
- Copyright (C) 1997-2025 Sam Lantinga <[email protected]>
+ Copyright (C) 1997-2026 Sam Lantinga <[email protected]>
This software is provided 'as-is', without any express or implied
warranty. In no event will the authors be held liable for any damages
@@ -44,34 +44,20 @@
#include <libkern/OSAtomic.h>
#endif
-/* *INDENT-OFF* */ // clang-format off
-#if defined(__WATCOMC__) && defined(__386__)
-SDL_COMPILE_TIME_ASSERT(locksize, 4==sizeof(SDL_SpinLock));
-extern __inline int _SDL_xchg_watcom(volatile int *a, int v);
-#pragma aux _SDL_xchg_watcom = \
- "lock xchg [ecx], eax" \
- parm [ecx] [eax] \
- value [eax] \
- modify exact [eax];
-#endif // __WATCOMC__ && __386__
-/* *INDENT-ON* */ // clang-format on
-
// This function is where all the magic happens...
bool SDL_TryLockSpinlock(SDL_SpinLock *lock)
{
#if defined(HAVE_GCC_ATOMICS) || defined(HAVE_GCC_SYNC_LOCK_TEST_AND_SET)
return __sync_lock_test_and_set(lock, 1) == 0;
-#elif defined(_MSC_VER) && (defined(_M_ARM) || defined(_M_ARM64))
- return _InterlockedExchange_acq(lock, 1) == 0;
+#elif defined(_MSC_VER) && (defined(_M_ARM) || defined(_M_ARM64) || defined(_M_ARM64EC))
+ SDL_COMPILE_TIME_ASSERT(locksize, sizeof(*lock) == sizeof(long));
+ return _InterlockedExchange_acq((long *)lock, 1) == 0;
#elif defined(_MSC_VER)
SDL_COMPILE_TIME_ASSERT(locksize, sizeof(*lock) == sizeof(long));
return InterlockedExchange((long *)lock, 1) == 0;
-#elif defined(__WATCOMC__) && defined(__386__)
- return _SDL_xchg_watcom(lock, 1) == 0;
-
#elif defined(__GNUC__) && defined(__arm__) && \
(defined(__ARM_ARCH_3__) || defined(__ARM_ARCH_3M__) || \
defined(__ARM_ARCH_4__) || defined(__ARM_ARCH_4T__) || \
@@ -106,7 +92,7 @@ bool SDL_TryLockSpinlock(SDL_SpinLock *lock)
: "cc", "memory");
return result == 0;
-#elif defined(__GNUC__) && (defined(__i386__) || defined(__x86_64__))
+#elif (defined(__GNUC__) || defined(__TINYC__)) && (defined(__i386__) || defined(__x86_64__))
int result;
__asm__ __volatile__(
"lock ; xchgl %0, (%1)\n"
@@ -181,23 +167,17 @@ void SDL_UnlockSpinlock(SDL_SpinLock *lock)
#if defined(HAVE_GCC_ATOMICS) || defined(HAVE_GCC_SYNC_LOCK_TEST_AND_SET)
__sync_lock_release(lock);
-#elif defined(_MSC_VER) && (defined(_M_ARM) || defined(_M_ARM64))
- _InterlockedExchange_rel(lock, 0);
-
-#elif defined(_MSC_VER)
- _ReadWriteBarrier();
- *lock = 0;
-
-#elif defined(__WATCOMC__) && defined(__386__)
- SDL_CompilerBarrier();
- *lock = 0;
+#elif defined(_MSC_VER) && (defined(_M_ARM) || defined(_M_ARM64) || defined(_M_ARM64EC))
+ SDL_COMPILE_TIME_ASSERT(locksize, sizeof(*lock) == sizeof(long));
+ _InterlockedExchange_rel((long *)lock, 0);
#elif defined(SDL_PLATFORM_SOLARIS)
// Used for Solaris when not using gcc.
- *lock = 0;
membar_producer();
+ *lock = 0;
#else
+ SDL_MemoryBarrierRelease();
*lock = 0;
#endif
}
diff --git a/thirdparty/sdl/core/linux/SDL_dbus.c b/thirdparty/sdl/core/linux/SDL_dbus.c
index 9dc5c266732..663e70427ac 100644
--- a/thirdparty/sdl/core/linux/SDL_dbus.c
+++ b/thirdparty/sdl/core/linux/SDL_dbus.c
@@ -1,6 +1,6 @@
/*
Simple DirectMedia Layer
- Copyright (C) 1997-2025 Sam Lantinga <[email protected]>
+ Copyright (C) 1997-2026 Sam Lantinga <[email protected]>
This software is provided 'as-is', without any express or implied
warranty. In no event will the authors be held liable for any damages
@@ -22,14 +22,25 @@
#include "SDL_dbus.h"
#include "../../stdlib/SDL_vacopy.h"
+#include <fcntl.h>
+#include <unistd.h>
+
#ifdef SDL_USE_LIBDBUS
// we never link directly to libdbus.
-static const char *dbus_library = "libdbus-1.so.3";
+#define SDL_DRIVER_DBUS_DYNAMIC "libdbus-1.so.3"
+static const char *dbus_library = SDL_DRIVER_DBUS_DYNAMIC;
static SDL_SharedObject *dbus_handle = NULL;
static char *inhibit_handle = NULL;
static unsigned int screensaver_cookie = 0;
static SDL_DBusContext dbus;
+SDL_ELF_NOTE_DLOPEN(
+ "core-libdbus",
+ "Support for D-Bus IPC",
+ SDL_ELF_NOTE_DLOPEN_PRIORITY_RECOMMENDED,
+ SDL_DRIVER_DBUS_DYNAMIC
+)
+
static bool LoadDBUSSyms(void)
{
#define SDL_DBUS_SYM2_OPTIONAL(TYPE, x, y) \
@@ -48,6 +59,8 @@ static bool LoadDBUSSyms(void)
SDL_DBUS_SYM(DBusConnection *(*)(DBusBusType, DBusError *), bus_get_private);
SDL_DBUS_SYM(dbus_bool_t (*)(DBusConnection *, DBusError *), bus_register);
SDL_DBUS_SYM(void (*)(DBusConnection *, const char *, DBusError *), bus_add_match);
+ SDL_DBUS_SYM(void (*)(DBusConnection *, const char *, DBusError *), bus_remove_match);
+ SDL_DBUS_SYM(const char *(*)(DBusConnection *), bus_get_unique_name);
SDL_DBUS_SYM(DBusConnection *(*)(const char *, DBusError *), connection_open_private);
SDL_DBUS_SYM(void (*)(DBusConnection *, dbus_bool_t), connection_set_exit_on_disconnect);
SDL_DBUS_SYM(dbus_bool_t (*)(DBusConnection *), connection_get_is_connected);
@@ -61,10 +74,14 @@ static bool LoadDBUSSyms(void)
SDL_DBUS_SYM(void (*)(DBusConnection *), connection_unref);
SDL_DBUS_SYM(void (*)(DBusConnection *), connection_flush);
SDL_DBUS_SYM(dbus_bool_t (*)(DBusConnection *, int), connection_read_write);
+ SDL_DBUS_SYM(dbus_bool_t (*)(DBusConnection *, int), connection_read_write_dispatch);
SDL_DBUS_SYM(DBusDispatchStatus (*)(DBusConnection *), connection_dispatch);
+ SDL_DBUS_SYM(dbus_bool_t (*)(int), type_is_fixed);
SDL_DBUS_SYM(dbus_bool_t (*)(DBusMessage *, const char *, const char *), message_is_signal);
SDL_DBUS_SYM(dbus_bool_t (*)(DBusMessage *, const char *), message_has_path);
SDL_DBUS_SYM(DBusMessage *(*)(const char *, const char *, const char *, const char *), message_new_method_call);
+ SDL_DBUS_SYM(DBusMessage *(*)(const char *, const char *, const char *), message_new_signal);
+ SDL_DBUS_SYM(void (*)(DBusMessage *, dbus_bool_t), message_set_no_reply);
SDL_DBUS_SYM(dbus_bool_t (*)(DBusMessage *, int, ...), message_append_args);
SDL_DBUS_SYM(dbus_bool_t (*)(DBusMessage *, int, va_list), message_append_args_valist);
SDL_DBUS_SYM(void (*)(DBusMessage *, DBusMessageIter *), message_iter_init_append);
@@ -82,6 +99,7 @@ static bool LoadDBUSSyms(void)
SDL_DBUS_SYM(dbus_bool_t (*)(void), threads_init_default);
SDL_DBUS_SYM(void (*)(DBusError *), error_init);
SDL_DBUS_SYM(dbus_bool_t (*)(const DBusError *), error_is_set);
+ SDL_DBUS_SYM(dbus_bool_t (*)(const DBusError *, const char *), error_has_name);
SDL_DBUS_SYM(void (*)(DBusError *), error_free);
SDL_DBUS_SYM(char *(*)(void), get_local_machine_id);
SDL_DBUS_SYM_OPTIONAL(char *(*)(DBusError *), try_get_local_machine_id);
@@ -222,7 +240,7 @@ SDL_DBusContext *SDL_DBus_GetContext(void)
return (dbus_handle && dbus.session_conn) ? &dbus : NULL;
}
-static bool SDL_DBus_CallMethodInternal(DBusConnection *conn, const char *node, const char *path, const char *interface, const char *method, va_list ap)
+static bool SDL_DBus_CallMethodInternal(DBusConnection *conn, DBusMessage **save_reply, const char *node, const char *path, const char *interface, const char *method, va_list ap)
{
bool result = false;
@@ -254,7 +272,11 @@ static bool SDL_DBus_CallMethodInternal(DBusConnection *conn, const char *node,
if ((firstarg == DBUS_TYPE_INVALID) || dbus.message_get_args_valist(reply, NULL, firstarg, ap_reply)) {
result = true;
}
- dbus.message_unref(reply);
+ if (save_reply) {
+ *save_reply = reply;
+ } else {
+ dbus.message_unref(reply);
+ }
}
}
va_end(ap_reply);
@@ -265,22 +287,22 @@ static bool SDL_DBus_CallMethodInternal(DBusConnection *conn, const char *node,
return result;
}
-bool SDL_DBus_CallMethodOnConnection(DBusConnection *conn, const char *node, const char *path, const char *interface, const char *method, ...)
+bool SDL_DBus_CallMethodOnConnection(DBusConnection *conn, DBusMessage **save_reply, const char *node, const char *path, const char *interface, const char *method, ...)
{
bool result;
va_list ap;
va_start(ap, method);
- result = SDL_DBus_CallMethodInternal(conn, node, path, interface, method, ap);
+ result = SDL_DBus_CallMethodInternal(conn, save_reply, node, path, interface, method, ap);
va_end(ap);
return result;
}
-bool SDL_DBus_CallMethod(const char *node, const char *path, const char *interface, const char *method, ...)
+bool SDL_DBus_CallMethod(DBusMessage **save_reply, const char *node, const char *path, const char *interface, const char *method, ...)
{
bool result;
va_list ap;
va_start(ap, method);
- result = SDL_DBus_CallMethodInternal(dbus.session_conn, node, path, interface, method, ap);
+ result = SDL_DBus_CallMethodInternal(dbus.session_conn, save_reply, node, path, interface, method, ap);
va_end(ap);
return result;
}
@@ -294,6 +316,7 @@ static bool SDL_DBus_CallVoidMethodInternal(DBusConnection *conn, const char *no
if (msg) {
int firstarg = va_arg(ap, int);
if ((firstarg == DBUS_TYPE_INVALID) || dbus.message_append_args_valist(msg, firstarg, ap)) {
+ dbus.message_set_no_reply(msg, true);
if (dbus.connection_send(conn, msg, NULL)) {
dbus.connection_flush(conn);
result = true;
@@ -307,10 +330,34 @@ static bool SDL_DBus_CallVoidMethodInternal(DBusConnection *conn, const char *no
return result;
}
-static bool SDL_DBus_CallWithBasicReply(DBusConnection *conn, DBusMessage *msg, const int expectedtype, void *result)
+bool SDL_DBus_CallVoidMethodOnConnection(DBusConnection *conn, const char *node, const char *path, const char *interface, const char *method, ...)
+{
+ bool result;
+ va_list ap;
+ va_start(ap, method);
+ result = SDL_DBus_CallVoidMethodInternal(conn, node, path, interface, method, ap);
+ va_end(ap);
+ return result;
+}
+
+bool SDL_DBus_CallVoidMethod(const char *node, const char *path, const char *interface, const char *method, ...)
+{
+ bool result;
+ va_list ap;
+ va_start(ap, method);
+ result = SDL_DBus_CallVoidMethodInternal(dbus.session_conn, node, path, interface, method, ap);
+ va_end(ap);
+ return result;
+}
+
+static bool SDL_DBus_CallWithBasicReply(DBusConnection *conn, DBusMessage **save_reply, DBusMessage *msg, const int expectedtype, void *result)
{
bool retval = false;
+ // Make sure we're not looking up strings here, otherwise we'd have to save and return the reply
+ SDL_assert(save_reply == NULL || *save_reply == NULL);
+ SDL_assert(save_reply != NULL || dbus.type_is_fixed(expectedtype));
+
DBusMessage *reply = dbus.connection_send_with_reply_and_block(conn, msg, 300, NULL);
if (reply) {
DBusMessageIter iter, actual_iter;
@@ -326,33 +373,17 @@ static bool SDL_DBus_CallWithBasicReply(DBusConnection *conn, DBusMessage *msg,
retval = true;
}
- dbus.message_unref(reply);
+ if (save_reply) {
+ *save_reply = reply;
+ } else {
+ dbus.message_unref(reply);
+ }
}
return retval;
}
-bool SDL_DBus_CallVoidMethodOnConnection(DBusConnection *conn, const char *node, const char *path, const char *interface, const char *method, ...)
-{
- bool result;
- va_list ap;
- va_start(ap, method);
- result = SDL_DBus_CallVoidMethodInternal(conn, node, path, interface, method, ap);
- va_end(ap);
- return result;
-}
-
-bool SDL_DBus_CallVoidMethod(const char *node, const char *path, const char *interface, const char *method, ...)
-{
- bool result;
- va_list ap;
- va_start(ap, method);
- result = SDL_DBus_CallVoidMethodInternal(dbus.session_conn, node, path, interface, method, ap);
- va_end(ap);
- return result;
-}
-
-bool SDL_DBus_QueryPropertyOnConnection(DBusConnection *conn, const char *node, const char *path, const char *interface, const char *property, int expectedtype, void *result)
+bool SDL_DBus_QueryPropertyOnConnection(DBusConnection *conn, DBusMessage **save_reply, const char *node, const char *path, const char *interface, const char *property, int expectedtype, void *result)
{
bool retval = false;
@@ -360,7 +391,7 @@ bool SDL_DBus_QueryPropertyOnConnection(DBusConnection *conn, const char *node,
DBusMessage *msg = dbus.message_new_method_call(node, path, "org.freedesktop.DBus.Properties", "Get");
if (msg) {
if (dbus.message_append_args(msg, DBUS_TYPE_STRING, &interface, DBUS_TYPE_STRING, &property, DBUS_TYPE_INVALID)) {
- retval = SDL_DBus_CallWithBasicReply(conn, msg, expectedtype, result);
+ retval = SDL_DBus_CallWithBasicReply(conn, save_reply, msg, expectedtype, result);
}
dbus.message_unref(msg);
}
@@ -369,9 +400,18 @@ bool SDL_DBus_QueryPropertyOnConnection(DBusConnection *conn, const char *node,
return retval;
}
-bool SDL_DBus_QueryProperty(const char *node, const char *path, const char *interface, const char *property, int expectedtype, void *result)
+bool SDL_DBus_QueryProperty(DBusMessage **save_reply, const char *node, const char *path, const char *interface, const char *property, int expectedtype, void *result)
+{
+ return SDL_DBus_QueryPropertyOnConnection(dbus.session_conn, save_reply, node, path, interface, property, expectedtype, result);
+}
+
+void SDL_DBus_FreeReply(DBusMessage **saved_reply)
{
- return SDL_DBus_QueryPropertyOnConnection(dbus.session_conn, node, path, interface, property, expectedtype, result);
+ DBusMessage *reply = *saved_reply;
+ if (reply) {
+ dbus.message_unref(reply);
+ *saved_reply = NULL;
+ }
}
void SDL_DBus_ScreensaverTickle(void)
@@ -440,10 +480,119 @@ static bool SDL_DBus_AppendDictWithKeyValue(DBusMessageIter *iterInit, const cha
return SDL_DBus_AppendDictWithKeysAndValues(iterInit, keys, values, 1);
}
+bool SDL_DBus_OpenURI(const char *uri, const char *window_id, const char *activation_token)
+{
+ static const char *bus_name = "org.freedesktop.portal.Desktop";
+ static const char *path = "/org/freedesktop/portal/desktop";
+ static const char *interface = "org.freedesktop.portal.OpenURI";
+
+ if (!dbus.session_conn) {
+ /* We either lost connection to the session bus or were not able to
+ * load the D-Bus library at all.
+ */
+ return false;
+ }
+
+ DBusMessageIter iterInit;
+ DBusMessage *msg = NULL;
+ int fd = -1;
+ bool ret = false;
+ const bool has_file_scheme = SDL_strncasecmp(uri, "file:/", 6) == 0;
+
+ // The OpenURI method can't open 'file://' URIs or local paths, so OpenFile must be used instead.
+ if (has_file_scheme || !SDL_IsURI(uri)) {
+ char *decoded_path = NULL;
+
+ // Decode the path if it is a URI.
+ if (has_file_scheme) {
+ const size_t len = SDL_strlen(uri) + 1;
+ decoded_path = SDL_malloc(len);
+ if (!decoded_path) {
+ goto done;
+ }
+ if (SDL_URIToLocal(uri, decoded_path) < 0) {
+ SDL_free(decoded_path);
+ goto done;
+ }
+ uri = decoded_path;
+ }
+ fd = open(uri, O_RDWR | O_CLOEXEC);
+ SDL_free(decoded_path);
+ if (fd >= 0) {
+ msg = dbus.message_new_method_call(bus_name, path, interface, "OpenFile");
+ }
+ } else {
+ msg = dbus.message_new_method_call(bus_name, path, interface, "OpenURI");
+ }
+ if (!msg) {
+ goto done;
+ }
+
+ dbus.message_iter_init_append(msg, &iterInit);
+
+ if (!window_id) {
+ window_id = "";
+ }
+ if (!dbus.message_iter_append_basic(&iterInit, DBUS_TYPE_STRING, &window_id)) {
+ goto done;
+ }
+
+ if (fd >= 0) {
+ if (!dbus.message_iter_append_basic(&iterInit, DBUS_TYPE_UNIX_FD, &fd)) {
+ goto done;
+ }
+ } else {
+ if (!dbus.message_iter_append_basic(&iterInit, DBUS_TYPE_STRING, &uri)) {
+ goto done;
+ }
+ }
+
+ if (activation_token) {
+ if (!SDL_DBus_AppendDictWithKeyValue(&iterInit, "activation_token", activation_token)) {
+ goto done;
+ }
+ } else {
+ // The array must be in the parameter list, even if empty.
+ DBusMessageIter iterArray;
+ if (!dbus.message_iter_open_container(&iterInit, DBUS_TYPE_ARRAY, "{sv}", &iterArray)) {
+ goto done;
+ }
+ if (!dbus.message_iter_close_container(&iterInit, &iterArray)) {
+ goto done;
+ }
+ }
+
+ {
+ DBusMessage *reply = dbus.connection_send_with_reply_and_block(dbus.session_conn, msg, -1, NULL);
+ if (reply) {
+ ret = true;
+ dbus.message_unref(reply);
+ }
+ }
+
+done:
+ if (msg) {
+ dbus.message_unref(msg);
+ }
+
+ // The file descriptor is duplicated by D-Bus, so it can be closed on this end.
+ if (fd >= 0) {
+ close(fd);
+ }
+
+ return ret;
+}
+
bool SDL_DBus_ScreensaverInhibit(bool inhibit)
{
+ static bool interface_unavailable = false;
const char *default_inhibit_reason = "Playing a game";
+ // If the interface was previously queried and is unavailable, return false.
+ if (interface_unavailable) {
+ return false;
+ }
+
if ((inhibit && (screensaver_cookie != 0 || inhibit_handle)) || (!inhibit && (screensaver_cookie == 0 && !inhibit_handle))) {
return true;
}
@@ -466,7 +615,7 @@ bool SDL_DBus_ScreensaverInhibit(bool inhibit)
DBusMessage *msg;
bool result = false;
const char *key = "reason";
- const char *reply = NULL;
+ const char *reply_path = NULL;
const char *reason = SDL_GetHint(SDL_HINT_SCREENSAVER_INHIBIT_ACTIVITY_NAME);
if (!reason || !reason[0]) {
reason = default_inhibit_reason;
@@ -490,11 +639,14 @@ bool SDL_DBus_ScreensaverInhibit(bool inhibit)
return false;
}
- if (SDL_DBus_CallWithBasicReply(dbus.session_conn, msg, DBUS_TYPE_OBJECT_PATH, &reply)) {
- inhibit_handle = SDL_strdup(reply);
+ DBusMessage *reply = NULL;
+ if (SDL_DBus_CallWithBasicReply(dbus.session_conn, &reply, msg, DBUS_TYPE_OBJECT_PATH, &reply_path)) {
+ inhibit_handle = SDL_strdup(reply_path);
result = true;
+ } else {
+ interface_unavailable = true;
}
-
+ SDL_DBus_FreeReply(&reply);
dbus.message_unref(msg);
return result;
} else {
@@ -516,9 +668,10 @@ bool SDL_DBus_ScreensaverInhibit(bool inhibit)
reason = default_inhibit_reason;
}
- if (!SDL_DBus_CallMethod(bus_name, path, interface, "Inhibit",
+ if (!SDL_DBus_CallMethod(NULL, bus_name, path, interface, "Inhibit",
DBUS_TYPE_STRING, &app, DBUS_TYPE_STRING, &reason, DBUS_TYPE_INVALID,
DBUS_TYPE_UINT32, &screensaver_cookie, DBUS_TYPE_INVALID)) {
+ interface_unavailable = true;
return false;
}
return (screensaver_cookie != 0);
@@ -644,4 +797,184 @@ failed:
return NULL;
}
+typedef struct SDL_DBus_CameraPortalMessageHandlerData
+{
+ uint32_t response;
+ char *path;
+ DBusError *err;
+ bool done;
+} SDL_DBus_CameraPortalMessageHandlerData;
+
+static DBusHandlerResult SDL_DBus_CameraPortalMessageHandler(DBusConnection *conn, DBusMessage *msg, void *v)
+{
+ SDL_DBus_CameraPortalMessageHandlerData *data = v;
+ const char *name, *old, *new;
+
+ if (dbus.message_is_signal(msg, "org.freedesktop.DBus", "NameOwnerChanged")) {
+ if (!dbus.message_get_args(msg, data->err,
+ DBUS_TYPE_STRING, &name,
+ DBUS_TYPE_STRING, &old,
+ DBUS_TYPE_STRING, &new,
+ DBUS_TYPE_INVALID)) {
+ data->done = true;
+ return DBUS_HANDLER_RESULT_NOT_YET_HANDLED;
+ }
+ if (SDL_strcmp(name, "org.freedesktop.portal.Desktop") != 0 ||
+ SDL_strcmp(new, "") != 0) {
+ return DBUS_HANDLER_RESULT_NOT_YET_HANDLED;
+ }
+ data->done = true;
+ data->response = -1;
+ return DBUS_HANDLER_RESULT_HANDLED;
+ }
+ if (!dbus.message_has_path(msg, data->path) || !dbus.message_is_signal(msg, "org.freedesktop.portal.Request", "Response")) {
+ return DBUS_HANDLER_RESULT_NOT_YET_HANDLED;
+ }
+ dbus.message_get_args(msg, data->err, DBUS_TYPE_UINT32, &data->response, DBUS_TYPE_INVALID);
+ data->done = true;
+ return DBUS_HANDLER_RESULT_HANDLED;
+}
+
+#define SIGNAL_NAMEOWNERCHANGED "type='signal',\
+ sender='org.freedesktop.DBus',\
+ interface='org.freedesktop.DBus',\
+ member='NameOwnerChanged',\
+ arg0='org.freedesktop.portal.Desktop',\
+ arg2=''"
+
+/*
+ * Requests access for the camera. Returns -1 on error, -2 on denied access or
+ * missing portal, otherwise returns a file descriptor to be used by the Pipewire driver.
+ * https://flatpak.github.io/xdg-desktop-portal/docs/doc-org.freedesktop.portal.Camera.html
+ */
+int SDL_DBus_CameraPortalRequestAccess(void)
+{
+ SDL_DBus_CameraPortalMessageHandlerData data;
+ DBusError err;
+ DBusMessageIter iter, iterDict;
+ DBusMessage *reply, *msg;
+ int fd;
+
+ if (SDL_GetSandbox() == SDL_SANDBOX_NONE) {
+ return -2;
+ }
+
+ if (!SDL_DBus_GetContext()) {
+ return -2;
+ }
+
+ dbus.error_init(&err);
+
+ msg = dbus.message_new_method_call("org.freedesktop.portal.Desktop",
+ "/org/freedesktop/portal/desktop",
+ "org.freedesktop.portal.Camera",
+ "AccessCamera");
+
+ dbus.message_iter_init_append(msg, &iter);
+ if (!dbus.message_iter_open_container(&iter, DBUS_TYPE_ARRAY, "{sv}", &iterDict) ||
+ !dbus.message_iter_close_container(&iter, &iterDict)) {
+ SDL_OutOfMemory();
+ dbus.message_unref(msg);
+ goto failed;
+ }
+
+ reply = dbus.connection_send_with_reply_and_block(dbus.session_conn, msg, DBUS_TIMEOUT_USE_DEFAULT, &err);
+ dbus.message_unref(msg);
+
+ if (reply) {
+ dbus.message_get_args(reply, &err, DBUS_TYPE_OBJECT_PATH, &data.path, DBUS_TYPE_INVALID);
+ if (dbus.error_is_set(&err)) {
+ dbus.message_unref(reply);
+ goto failed;
+ }
+ if ((data.path = SDL_strdup(data.path)) == NULL) {
+ dbus.message_unref(reply);
+ SDL_OutOfMemory();
+ goto failed;
+ }
+ dbus.message_unref(reply);
+ } else {
+ if (dbus.error_has_name(&err, DBUS_ERROR_NAME_HAS_NO_OWNER)) {
+ return -2;
+ }
+ goto failed;
+ }
+
+ dbus.bus_add_match(dbus.session_conn, SIGNAL_NAMEOWNERCHANGED, &err);
+ if (dbus.error_is_set(&err)) {
+ SDL_free(data.path);
+ goto failed;
+ }
+ data.err = &err;
+ data.done = false;
+ if (!dbus.connection_add_filter(dbus.session_conn, SDL_DBus_CameraPortalMessageHandler, &data, NULL)) {
+ SDL_free(data.path);
+ SDL_OutOfMemory();
+ goto failed;
+ }
+ while (!data.done && dbus.connection_read_write_dispatch(dbus.session_conn, -1)) {
+ ;
+ }
+
+ dbus.bus_remove_match(dbus.session_conn, SIGNAL_NAMEOWNERCHANGED, &err);
+ if (dbus.error_is_set(&err)) {
+ SDL_free(data.path);
+ goto failed;
+ }
+ dbus.connection_remove_filter(dbus.session_conn, SDL_DBus_CameraPortalMessageHandler, &data);
+ SDL_free(data.path);
+ if (!data.done) {
+ goto failed;
+ }
+ if (dbus.error_is_set(&err)) { // from the message handler
+ goto failed;
+ }
+ if (data.response == 1 || data.response == 2) {
+ return -2;
+ } else if (data.response != 0) {
+ goto failed;
+ }
+
+ msg = dbus.message_new_method_call("org.freedesktop.portal.Desktop",
+ "/org/freedesktop/portal/desktop",
+ "org.freedesktop.portal.Camera",
+ "OpenPipeWireRemote");
+
+ dbus.message_iter_init_append(msg, &iter);
+ if (!dbus.message_iter_open_container(&iter, DBUS_TYPE_ARRAY, "{sv}", &iterDict) ||
+ !dbus.message_iter_close_container(&iter, &iterDict)) {
+ SDL_OutOfMemory();
+ dbus.message_unref(msg);
+ goto failed;
+ }
+
+ reply = dbus.connection_send_with_reply_and_block(dbus.session_conn, msg, DBUS_TIMEOUT_USE_DEFAULT, &err);
+ dbus.message_unref(msg);
+
+ if (reply) {
+ dbus.message_get_args(reply, &err, DBUS_TYPE_UNIX_FD, &fd, DBUS_TYPE_INVALID);
+ dbus.message_unref(reply);
+ if (dbus.error_is_set(&err)) {
+ goto failed;
+ }
+ } else {
+ goto failed;
+ }
+
+ return fd;
+
+failed:
+ if (dbus.error_is_set(&err)) {
+ if (dbus.error_has_name(&err, DBUS_ERROR_NO_MEMORY)) {
+ SDL_OutOfMemory();
+ }
+ SDL_SetError("%s: %s", err.name, err.message);
+ dbus.error_free(&err);
+ } else {
+ SDL_SetError("Error requesting access for the camera");
+ }
+
+ return -1;
+}
+
#endif
diff --git a/thirdparty/sdl/core/linux/SDL_dbus.h b/thirdparty/sdl/core/linux/SDL_dbus.h
index 2073d6cee8b..568dd74bb2c 100644
--- a/thirdparty/sdl/core/linux/SDL_dbus.h
+++ b/thirdparty/sdl/core/linux/SDL_dbus.h
@@ -1,6 +1,6 @@
/*
Simple DirectMedia Layer
- Copyright (C) 1997-2025 Sam Lantinga <[email protected]>
+ Copyright (C) 1997-2026 Sam Lantinga <[email protected]>
This software is provided 'as-is', without any express or implied
warranty. In no event will the authors be held liable for any damages
@@ -34,6 +34,9 @@
#ifndef DBUS_TIMEOUT_INFINITE
#define DBUS_TIMEOUT_INFINITE ((int) 0x7fffffff)
#endif
+#ifndef DBUS_TYPE_UNIX_FD
+#define DBUS_TYPE_UNIX_FD ((int) 'h')
+#endif
typedef struct SDL_DBusContext
{
@@ -43,6 +46,8 @@ typedef struct SDL_DBusContext
DBusConnection *(*bus_get_private)(DBusBusType, DBusError *);
dbus_bool_t (*bus_register)(DBusConnection *, DBusError *);
void (*bus_add_match)(DBusConnection *, const char *, DBusError *);
+ void (*bus_remove_match)(DBusConnection *, const char *, DBusError *);
+ const char *(*bus_get_unique_name)(DBusConnection *);
DBusConnection *(*connection_open_private)(const char *, DBusError *);
void (*connection_set_exit_on_disconnect)(DBusConnection *, dbus_bool_t);
dbus_bool_t (*connection_get_is_connected)(DBusConnection *);
@@ -57,10 +62,14 @@ typedef struct SDL_DBusContext
void (*connection_unref)(DBusConnection *);
void (*connection_flush)(DBusConnection *);
dbus_bool_t (*connection_read_write)(DBusConnection *, int);
+ dbus_bool_t (*connection_read_write_dispatch)(DBusConnection *, int);
DBusDispatchStatus (*connection_dispatch)(DBusConnection *);
+ dbus_bool_t (*type_is_fixed)(int);
dbus_bool_t (*message_is_signal)(DBusMessage *, const char *, const char *);
dbus_bool_t (*message_has_path)(DBusMessage *, const char *);
DBusMessage *(*message_new_method_call)(const char *, const char *, const char *, const char *);
+ DBusMessage *(*message_new_signal)(const char *, const char *, const char *);
+ void (*message_set_no_reply)(DBusMessage *, dbus_bool_t);
dbus_bool_t (*message_append_args)(DBusMessage *, int, ...);
dbus_bool_t (*message_append_args_valist)(DBusMessage *, int, va_list);
void (*message_iter_init_append)(DBusMessage *, DBusMessageIter *);
@@ -78,6 +87,7 @@ typedef struct SDL_DBusContext
dbus_bool_t (*threads_init_default)(void);
void (*error_init)(DBusError *);
dbus_bool_t (*error_is_set)(const DBusError *);
+ dbus_bool_t (*error_has_name)(const DBusError *, const char *);
void (*error_free)(DBusError *);
char *(*get_local_machine_id)(void);
char *(*try_get_local_machine_id)(DBusError *);
@@ -92,23 +102,32 @@ extern void SDL_DBus_Quit(void);
extern SDL_DBusContext *SDL_DBus_GetContext(void);
// These use the built-in Session connection.
-extern bool SDL_DBus_CallMethod(const char *node, const char *path, const char *interface, const char *method, ...);
+extern bool SDL_DBus_CallMethod(DBusMessage **save_reply, const char *node, const char *path, const char *interface, const char *method, ...);
extern bool SDL_DBus_CallVoidMethod(const char *node, const char *path, const char *interface, const char *method, ...);
-extern bool SDL_DBus_QueryProperty(const char *node, const char *path, const char *interface, const char *property, int expectedtype, void *result);
+// save_reply must be non-NULL if it's a string property
+extern bool SDL_DBus_QueryProperty(DBusMessage **save_reply, const char *node, const char *path, const char *interface, const char *property, int expectedtype, void *result);
// These use whatever connection you like.
-extern bool SDL_DBus_CallMethodOnConnection(DBusConnection *conn, const char *node, const char *path, const char *interface, const char *method, ...);
+extern bool SDL_DBus_CallMethodOnConnection(DBusConnection *conn, DBusMessage **save_reply, const char *node, const char *path, const char *interface, const char *method, ...);
extern bool SDL_DBus_CallVoidMethodOnConnection(DBusConnection *conn, const char *node, const char *path, const char *interface, const char *method, ...);
-extern bool SDL_DBus_QueryPropertyOnConnection(DBusConnection *conn, const char *node, const char *path, const char *interface, const char *property, int expectedtype, void *result);
+// save_reply must be non-NULL if it's a string property
+extern bool SDL_DBus_QueryPropertyOnConnection(DBusConnection *conn, DBusMessage **save_reply, const char *node, const char *path, const char *interface, const char *property, int expectedtype, void *result);
+
+// Used to free any reply returned from SDL_DBus_CallMethod() and SDL_DBus_QueryProperty()
+extern void SDL_DBus_FreeReply(DBusMessage **saved_reply);
extern void SDL_DBus_ScreensaverTickle(void);
extern bool SDL_DBus_ScreensaverInhibit(bool inhibit);
+extern bool SDL_DBus_OpenURI(const char *uri, const char *window_id, const char *activation_token);
+
extern void SDL_DBus_PumpEvents(void);
extern char *SDL_DBus_GetLocalMachineId(void);
extern char **SDL_DBus_DocumentsPortalRetrieveFiles(const char *key, int *files_count);
+extern int SDL_DBus_CameraPortalRequestAccess(void);
+
#endif // HAVE_DBUS_DBUS_H
#endif // SDL_dbus_h_
diff --git a/thirdparty/sdl/core/linux/SDL_evdev.c b/thirdparty/sdl/core/linux/SDL_evdev.c
index 04e3e9d6b65..711fe68881d 100644
--- a/thirdparty/sdl/core/linux/SDL_evdev.c
+++ b/thirdparty/sdl/core/linux/SDL_evdev.c
@@ -1,6 +1,6 @@
/*
Simple DirectMedia Layer
- Copyright (C) 1997-2025 Sam Lantinga <[email protected]>
+ Copyright (C) 1997-2026 Sam Lantinga <[email protected]>
This software is provided 'as-is', without any express or implied
warranty. In no event will the authors be held liable for any damages
@@ -32,13 +32,15 @@
#include "SDL_evdev.h"
#include "SDL_evdev_kbd.h"
-#include <sys/stat.h>
-#include <unistd.h>
+#include <errno.h>
#include <fcntl.h>
+#include <unistd.h>
#include <sys/ioctl.h>
+#include <sys/stat.h>
#include <linux/input.h>
#include "../../events/SDL_events_c.h"
+// #include "../../events/SDL_scancode_tables_c.h"
#include "../../core/linux/SDL_evdev_capabilities.h"
#include "../../core/linux/SDL_udev.h"
@@ -220,7 +222,7 @@ bool SDL_EVDEV_Init(void)
SDL_EVDEV_UpdateKeyboardMute();
}
- //SDL_GetMouse()->SetRelativeMouseMode = SDL_EVDEV_SetRelativeMouseMode;
+ // SDL_GetMouse()->SetRelativeMouseMode = SDL_EVDEV_SetRelativeMouseMode;
_this->ref_count += 1;
@@ -286,8 +288,8 @@ static void SDL_EVDEV_udev_callback(SDL_UDEV_deviceevent udev_event, int udev_cl
}
#endif // SDL_USE_LIBUDEV
-void SDL_EVDEV_SetVTSwitchCallbacks(void (*release_callback)(void*), void *release_callback_data,
- void (*acquire_callback)(void*), void *acquire_callback_data)
+void SDL_EVDEV_SetVTSwitchCallbacks(void (*release_callback)(void *), void *release_callback_data,
+ void (*acquire_callback)(void *), void *acquire_callback_data)
{
SDL_EVDEV_kbd_set_vt_switch_callbacks(_this->kbd,
release_callback, release_callback_data,
@@ -321,16 +323,17 @@ void SDL_EVDEV_Poll(void)
return;
}
-#ifdef SDL_USE_LIBUDEV
- SDL_UDEV_Poll();
-#endif
-
SDL_EVDEV_kbd_update(_this->kbd);
mouse = NULL; //SDL_GetMouse();
for (item = _this->first; item; item = item->next) {
while ((len = read(item->fd, events, sizeof(events))) > 0) {
+#ifdef SDL_INPUT_FBSDKBIO
+ if (SDL_GetAtomicInt(&vt_current) == VT_THEIRS) {
+ continue;
+ }
+#endif
len /= sizeof(events[0]);
for (i = 0; i < len; ++i) {
struct input_event *event = &events[i];
@@ -344,11 +347,10 @@ void SDL_EVDEV_Poll(void)
switch (event->type) {
case EV_KEY:
- break;
if (event->code >= BTN_MOUSE && event->code < BTN_MOUSE + SDL_arraysize(EVDEV_MouseButtons)) {
Uint64 timestamp = SDL_EVDEV_GetEventTimestamp(event);
mouse_button = event->code - BTN_MOUSE;
- //SDL_SendMouseButton(timestamp, mouse->focus, (SDL_MouseID)item->fd, EVDEV_MouseButtons[mouse_button], (event->value != 0));
+ // SDL_SendMouseButton(timestamp, mouse->focus, (SDL_MouseID)item->fd, EVDEV_MouseButtons[mouse_button], (event->value != 0));
break;
}
@@ -372,9 +374,9 @@ void SDL_EVDEV_Poll(void)
Uint64 timestamp = SDL_EVDEV_GetEventTimestamp(event);
scancode = SDL_EVDEV_translate_keycode(event->code);
// if (event->value == 0) {
- // SDL_SendKeyboardKey(timestamp, (SDL_KeyboardID)item->fd, event->code, scancode, false);
+ // SDL_SendKeyboardKey(timestamp, (SDL_KeyboardID)item->fd, event->code, scancode, false);
// } else if (event->value == 1 || event->value == 2 /* key repeated */) {
- // SDL_SendKeyboardKey(timestamp, (SDL_KeyboardID)item->fd, event->code, scancode, true);
+ // SDL_SendKeyboardKey(timestamp, (SDL_KeyboardID)item->fd, event->code, scancode, true);
// }
SDL_EVDEV_kbd_keycode(_this->kbd, event->code, event->value);
}
@@ -490,30 +492,35 @@ void SDL_EVDEV_Poll(void)
if (item->relative_mouse) {
if (item->mouse_x != 0 || item->mouse_y != 0) {
Uint64 timestamp = SDL_EVDEV_GetEventTimestamp(event);
- //SDL_SendMouseMotion(timestamp, mouse->focus, (SDL_MouseID)item->fd, item->relative_mouse, (float)item->mouse_x, (float)item->mouse_y);
+ // SDL_SendMouseMotion(timestamp, mouse->focus, (SDL_MouseID)item->fd, item->relative_mouse, (float)item->mouse_x, (float)item->mouse_y);
item->mouse_x = item->mouse_y = 0;
}
} else if (item->range_x > 0 && item->range_y > 0) {
int screen_w = 0, screen_h = 0;
const SDL_DisplayMode *mode = NULL;
+ // if (mouse->focus) {
+ // mode = SDL_GetCurrentDisplayMode(SDL_GetDisplayForWindow(mouse->focus));
+ // }
+ // if (!mode) {
+ // mode = SDL_GetCurrentDisplayMode(SDL_GetPrimaryDisplay());
+ // }
if (mode) {
screen_w = mode->w;
screen_h = mode->h;
}
- //SDL_SendMouseMotion(SDL_EVDEV_GetEventTimestamp(event), mouse->focus, (SDL_MouseID)item->fd, item->relative_mouse,
- // (float)(item->mouse_x - item->min_x) * screen_w / item->range_x,
- // (float)(item->mouse_y - item->min_y) * screen_h / item->range_y);
+ // SDL_SendMouseMotion(SDL_EVDEV_GetEventTimestamp(event), mouse->focus, (SDL_MouseID)item->fd, item->relative_mouse,
+ // (float)(item->mouse_x - item->min_x) * screen_w / item->range_x,
+ // (float)(item->mouse_y - item->min_y) * screen_h / item->range_y);
}
if (item->mouse_wheel != 0 || item->mouse_hwheel != 0) {
Uint64 timestamp = SDL_EVDEV_GetEventTimestamp(event);
- const float denom = (item->high_res_hwheel ? 120.0f : 1.0f);
- //SDL_SendMouseWheel(timestamp,
- // mouse->focus, (SDL_MouseID)item->fd,
- // item->mouse_hwheel / denom,
- // item->mouse_wheel / denom,
- // SDL_MOUSEWHEEL_NORMAL);
+ // SDL_SendMouseWheel(timestamp,
+ // mouse->focus, (SDL_MouseID)item->fd,
+ // item->mouse_hwheel / (item->high_res_hwheel ? 120.0f : 1.0f),
+ // item->mouse_wheel / (item->high_res_wheel ? 120.0f : 1.0f),
+ // SDL_MOUSEWHEEL_NORMAL);
item->mouse_wheel = item->mouse_hwheel = 0;
}
@@ -540,16 +547,16 @@ void SDL_EVDEV_Poll(void)
* be window-relative in that case. */
switch (item->touchscreen_data->slots[j].delta) {
case EVDEV_TOUCH_SLOTDELTA_DOWN:
- //SDL_SendTouch(SDL_EVDEV_GetEventTimestamp(event), item->fd, item->touchscreen_data->slots[j].tracking_id, NULL, SDL_EVENT_FINGER_DOWN, norm_x, norm_y, norm_pressure);
+ // SDL_SendTouch(SDL_EVDEV_GetEventTimestamp(event), item->fd, item->touchscreen_data->slots[j].tracking_id, mouse->focus, SDL_EVENT_FINGER_DOWN, norm_x, norm_y, norm_pressure);
item->touchscreen_data->slots[j].delta = EVDEV_TOUCH_SLOTDELTA_NONE;
break;
case EVDEV_TOUCH_SLOTDELTA_UP:
- //SDL_SendTouch(SDL_EVDEV_GetEventTimestamp(event), item->fd, item->touchscreen_data->slots[j].tracking_id, NULL, SDL_EVENT_FINGER_UP, norm_x, norm_y, norm_pressure);
+ // SDL_SendTouch(SDL_EVDEV_GetEventTimestamp(event), item->fd, item->touchscreen_data->slots[j].tracking_id, mouse->focus, SDL_EVENT_FINGER_UP, norm_x, norm_y, norm_pressure);
item->touchscreen_data->slots[j].tracking_id = 0;
item->touchscreen_data->slots[j].delta = EVDEV_TOUCH_SLOTDELTA_NONE;
break;
case EVDEV_TOUCH_SLOTDELTA_MOVE:
- //SDL_SendTouchMotion(SDL_EVDEV_GetEventTimestamp(event), item->fd, item->touchscreen_data->slots[j].tracking_id, NULL, norm_x, norm_y, norm_pressure);
+ // SDL_SendTouchMotion(SDL_EVDEV_GetEventTimestamp(event), item->fd, item->touchscreen_data->slots[j].tracking_id, mouse->focus, norm_x, norm_y, norm_pressure);
item->touchscreen_data->slots[j].delta = EVDEV_TOUCH_SLOTDELTA_NONE;
break;
default:
@@ -579,7 +586,7 @@ void SDL_EVDEV_Poll(void)
static SDL_Scancode SDL_EVDEV_translate_keycode(int keycode)
{
- //SDL_Scancode scancode = SDL_GetScancodeFromTable(SDL_SCANCODE_TABLE_LINUX, keycode);
+ // SDL_Scancode scancode = SDL_GetScancodeFromTable(SDL_SCANCODE_TABLE_LINUX, keycode);
#ifdef DEBUG_SCANCODES
if (scancode == SDL_SCANCODE_UNKNOWN) {
@@ -596,7 +603,7 @@ static SDL_Scancode SDL_EVDEV_translate_keycode(int keycode)
}
#endif // DEBUG_SCANCODES
- return 0; //scancode;
+ return 0; // scancode;
}
static bool SDL_EVDEV_init_keyboard(SDL_evdevlist_item *item, int udev_class)
@@ -606,14 +613,14 @@ static bool SDL_EVDEV_init_keyboard(SDL_evdevlist_item *item, int udev_class)
name[0] = '\0';
ioctl(item->fd, EVIOCGNAME(sizeof(name)), name);
- //SDL_AddKeyboard((SDL_KeyboardID)item->fd, name, true);
+ // SDL_AddKeyboard((SDL_KeyboardID)item->fd, name);
return true;
}
static void SDL_EVDEV_destroy_keyboard(SDL_evdevlist_item *item)
{
- //SDL_RemoveKeyboard((SDL_KeyboardID)item->fd, true);
+ // SDL_RemoveKeyboard((SDL_KeyboardID)item->fd);
}
static bool SDL_EVDEV_init_mouse(SDL_evdevlist_item *item, int udev_class)
@@ -625,7 +632,7 @@ static bool SDL_EVDEV_init_mouse(SDL_evdevlist_item *item, int udev_class)
name[0] = '\0';
ioctl(item->fd, EVIOCGNAME(sizeof(name)), name);
- //SDL_AddMouse((SDL_MouseID)item->fd, name, true);
+ // SDL_AddMouse((SDL_MouseID)item->fd, name);
ret = ioctl(item->fd, EVIOCGABS(ABS_X), &abs_info);
if (ret < 0) {
@@ -650,7 +657,7 @@ static bool SDL_EVDEV_init_mouse(SDL_evdevlist_item *item, int udev_class)
static void SDL_EVDEV_destroy_mouse(SDL_evdevlist_item *item)
{
- //SDL_RemoveMouse((SDL_MouseID)item->fd, true);
+ // SDL_RemoveMouse((SDL_MouseID)item->fd);
}
static bool SDL_EVDEV_init_touchscreen(SDL_evdevlist_item *item, int udev_class)
@@ -672,7 +679,8 @@ static bool SDL_EVDEV_init_touchscreen(SDL_evdevlist_item *item, int udev_class)
ret = ioctl(item->fd, EVIOCGNAME(sizeof(name)), name);
if (ret < 0) {
SDL_free(item->touchscreen_data);
- return SDL_SetError("Failed to get evdev touchscreen name");
+ SDL_LogError(SDL_LOG_CATEGORY_INPUT, "Failed to get evdev touchscreen name");
+ return false;
}
item->touchscreen_data->name = SDL_strdup(name);
@@ -685,7 +693,8 @@ static bool SDL_EVDEV_init_touchscreen(SDL_evdevlist_item *item, int udev_class)
if (ret < 0) {
SDL_free(item->touchscreen_data->name);
SDL_free(item->touchscreen_data);
- return SDL_SetError("Failed to get evdev touchscreen limits");
+ SDL_LogError(SDL_LOG_CATEGORY_INPUT, "Failed to get evdev touchscreen limits");
+ return false;
}
if (abs_info.maximum == 0) {
@@ -702,7 +711,8 @@ static bool SDL_EVDEV_init_touchscreen(SDL_evdevlist_item *item, int udev_class)
if (ret < 0) {
SDL_free(item->touchscreen_data->name);
SDL_free(item->touchscreen_data);
- return SDL_SetError("Failed to get evdev touchscreen limits");
+ SDL_LogError(SDL_LOG_CATEGORY_INPUT, "Failed to get evdev touchscreen limits");
+ return false;
}
item->touchscreen_data->min_x = abs_info.minimum;
item->touchscreen_data->max_x = abs_info.maximum;
@@ -712,7 +722,8 @@ static bool SDL_EVDEV_init_touchscreen(SDL_evdevlist_item *item, int udev_class)
if (ret < 0) {
SDL_free(item->touchscreen_data->name);
SDL_free(item->touchscreen_data);
- return SDL_SetError("Failed to get evdev touchscreen limits");
+ SDL_LogError(SDL_LOG_CATEGORY_INPUT, "Failed to get evdev touchscreen limits");
+ return false;
}
item->touchscreen_data->min_y = abs_info.minimum;
item->touchscreen_data->max_y = abs_info.maximum;
@@ -722,7 +733,8 @@ static bool SDL_EVDEV_init_touchscreen(SDL_evdevlist_item *item, int udev_class)
if (ret < 0) {
SDL_free(item->touchscreen_data->name);
SDL_free(item->touchscreen_data);
- return SDL_SetError("Failed to get evdev touchscreen limits");
+ SDL_LogError(SDL_LOG_CATEGORY_INPUT, "Failed to get evdev touchscreen limits");
+ return false;
}
item->touchscreen_data->min_pressure = abs_info.minimum;
item->touchscreen_data->max_pressure = abs_info.maximum;
@@ -737,10 +749,10 @@ static bool SDL_EVDEV_init_touchscreen(SDL_evdevlist_item *item, int udev_class)
return false;
}
- //ret = SDL_AddTouch(item->fd, // I guess our fd is unique enough
- // (udev_class & SDL_UDEV_DEVICE_TOUCHPAD) ? SDL_TOUCH_DEVICE_INDIRECT_ABSOLUTE : SDL_TOUCH_DEVICE_DIRECT,
- // item->touchscreen_data->name);
- ret = -1;
+ // ret = SDL_AddTouch(item->fd, // I guess our fd is unique enough
+ // (udev_class & SDL_UDEV_DEVICE_TOUCHPAD) ? SDL_TOUCH_DEVICE_INDIRECT_ABSOLUTE : SDL_TOUCH_DEVICE_DIRECT,
+ // item->touchscreen_data->name);
+ ret = -1;
if (ret < 0) {
SDL_free(item->touchscreen_data->slots);
SDL_free(item->touchscreen_data->name);
@@ -757,7 +769,7 @@ static void SDL_EVDEV_destroy_touchscreen(SDL_evdevlist_item *item)
return;
}
- //SDL_DelTouch(item->fd);
+ // SDL_DelTouch(item->fd);
SDL_free(item->touchscreen_data->slots);
SDL_free(item->touchscreen_data->name);
SDL_free(item->touchscreen_data);
@@ -907,8 +919,9 @@ static bool SDL_EVDEV_device_added(const char *dev_path, int udev_class)
item->fd = open(dev_path, O_RDONLY | O_NONBLOCK | O_CLOEXEC);
if (item->fd < 0) {
+ SDL_LogError(SDL_LOG_CATEGORY_INPUT, "Couldn't open %s: %s", dev_path, strerror(errno));
SDL_free(item);
- return SDL_SetError("Unable to open %s", dev_path);
+ return false;
}
item->path = SDL_strdup(dev_path);
diff --git a/thirdparty/sdl/core/linux/SDL_evdev.h b/thirdparty/sdl/core/linux/SDL_evdev.h
index d3e2fe165e5..8ddf4769b2f 100644
--- a/thirdparty/sdl/core/linux/SDL_evdev.h
+++ b/thirdparty/sdl/core/linux/SDL_evdev.h
@@ -1,6 +1,6 @@
/*
Simple DirectMedia Layer
- Copyright (C) 1997-2025 Sam Lantinga <[email protected]>
+ Copyright (C) 1997-2026 Sam Lantinga <[email protected]>
This software is provided 'as-is', without any express or implied
warranty. In no event will the authors be held liable for any damages
@@ -30,8 +30,8 @@ struct input_event;
extern bool SDL_EVDEV_Init(void);
extern void SDL_EVDEV_Quit(void);
-extern void SDL_EVDEV_SetVTSwitchCallbacks(void (*release_callback)(void*), void *release_callback_data,
- void (*acquire_callback)(void*), void *acquire_callback_data);
+extern void SDL_EVDEV_SetVTSwitchCallbacks(void (*release_callback)(void *), void *release_callback_data,
+ void (*acquire_callback)(void *), void *acquire_callback_data);
extern int SDL_EVDEV_GetDeviceCount(int device_class);
extern void SDL_EVDEV_Poll(void);
extern Uint64 SDL_EVDEV_GetEventTimestamp(struct input_event *event);
diff --git a/thirdparty/sdl/core/linux/SDL_evdev_capabilities.c b/thirdparty/sdl/core/linux/SDL_evdev_capabilities.c
index 61e240e7e12..38c891ce7fd 100644
--- a/thirdparty/sdl/core/linux/SDL_evdev_capabilities.c
+++ b/thirdparty/sdl/core/linux/SDL_evdev_capabilities.c
@@ -1,6 +1,6 @@
/*
Simple DirectMedia Layer
- Copyright (C) 1997-2025 Sam Lantinga <[email protected]>
+ Copyright (C) 1997-2026 Sam Lantinga <[email protected]>
Copyright (C) 2020 Collabora Ltd.
This software is provided 'as-is', without any express or implied
diff --git a/thirdparty/sdl/core/linux/SDL_evdev_capabilities.h b/thirdparty/sdl/core/linux/SDL_evdev_capabilities.h
index 5a70bdd6911..e7f081e5608 100644
--- a/thirdparty/sdl/core/linux/SDL_evdev_capabilities.h
+++ b/thirdparty/sdl/core/linux/SDL_evdev_capabilities.h
@@ -1,6 +1,6 @@
/*
Simple DirectMedia Layer
- Copyright (C) 1997-2025 Sam Lantinga <[email protected]>
+ Copyright (C) 1997-2026 Sam Lantinga <[email protected]>
Copyright (C) 2020 Collabora Ltd.
This software is provided 'as-is', without any express or implied
diff --git a/thirdparty/sdl/core/linux/SDL_evdev_kbd.c b/thirdparty/sdl/core/linux/SDL_evdev_kbd.c
index b1a56644af9..679f901ac0c 100644
--- a/thirdparty/sdl/core/linux/SDL_evdev_kbd.c
+++ b/thirdparty/sdl/core/linux/SDL_evdev_kbd.c
@@ -1,6 +1,6 @@
/*
Simple DirectMedia Layer
- Copyright (C) 1997-2025 Sam Lantinga <[email protected]>
+ Copyright (C) 1997-2026 Sam Lantinga <[email protected]>
This software is provided 'as-is', without any express or implied
warranty. In no event will the authors be held liable for any damages
@@ -224,7 +224,7 @@ static void kbd_unregister_emerg_cleanup(void)
}
kbd_cleanup_sigactions_installed = 0;
- for (tabidx = 0; tabidx < sizeof(fatal_signals) / sizeof(fatal_signals[0]); ++tabidx) {
+ for (tabidx = 0; tabidx < SDL_arraysize(fatal_signals); ++tabidx) {
struct sigaction *old_action_p;
struct sigaction cur_action;
int signum = fatal_signals[tabidx];
@@ -277,7 +277,7 @@ static void kbd_register_emerg_cleanup(SDL_EVDEV_keyboard_state *kbd)
}
kbd_cleanup_sigactions_installed = 1;
- for (tabidx = 0; tabidx < sizeof(fatal_signals) / sizeof(fatal_signals[0]); ++tabidx) {
+ for (tabidx = 0; tabidx < SDL_arraysize(fatal_signals); ++tabidx) {
struct sigaction *old_action_p;
struct sigaction new_action;
int signum = fatal_signals[tabidx];
@@ -495,7 +495,7 @@ void SDL_EVDEV_kbd_set_muted(SDL_EVDEV_keyboard_state *state, bool muted)
state->muted = muted;
}
-void SDL_EVDEV_kbd_set_vt_switch_callbacks(SDL_EVDEV_keyboard_state *state, void (*release_callback)(void*), void *release_callback_data, void (*acquire_callback)(void*), void *acquire_callback_data)
+void SDL_EVDEV_kbd_set_vt_switch_callbacks(SDL_EVDEV_keyboard_state *state, void (*release_callback)(void *), void *release_callback_data, void (*acquire_callback)(void *), void *acquire_callback_data)
{
if (state == NULL) {
return;
@@ -534,9 +534,7 @@ void SDL_EVDEV_kbd_quit(SDL_EVDEV_keyboard_state *state)
if (state->key_maps && state->key_maps != default_key_maps) {
int i;
for (i = 0; i < MAX_NR_KEYMAPS; ++i) {
- if (state->key_maps[i]) {
- SDL_free(state->key_maps[i]);
- }
+ SDL_free(state->key_maps[i]);
}
SDL_free(state->key_maps);
}
@@ -978,7 +976,7 @@ void SDL_EVDEV_kbd_set_muted(SDL_EVDEV_keyboard_state *state, bool muted)
{
}
-void SDL_EVDEV_kbd_set_vt_switch_callbacks(SDL_EVDEV_keyboard_state *state, void (*release_callback)(void*), void *release_callback_data, void (*acquire_callback)(void*), void *acquire_callback_data)
+void SDL_EVDEV_kbd_set_vt_switch_callbacks(SDL_EVDEV_keyboard_state *state, void (*release_callback)(void *), void *release_callback_data, void (*acquire_callback)(void *), void *acquire_callback_data)
{
}
diff --git a/thirdparty/sdl/core/linux/SDL_evdev_kbd.h b/thirdparty/sdl/core/linux/SDL_evdev_kbd.h
index 6ea19fb05a7..488548ae5a6 100644
--- a/thirdparty/sdl/core/linux/SDL_evdev_kbd.h
+++ b/thirdparty/sdl/core/linux/SDL_evdev_kbd.h
@@ -1,6 +1,6 @@
/*
Simple DirectMedia Layer
- Copyright (C) 1997-2025 Sam Lantinga <[email protected]>
+ Copyright (C) 1997-2026 Sam Lantinga <[email protected]>
This software is provided 'as-is', without any express or implied
warranty. In no event will the authors be held liable for any damages
@@ -22,12 +22,20 @@
#ifndef SDL_evdev_kbd_h_
#define SDL_evdev_kbd_h_
+#ifdef SDL_INPUT_FBSDKBIO
+enum {
+ VT_OURS,
+ VT_THEIRS,
+};
+extern SDL_AtomicInt vt_current;
+#endif
+
struct SDL_EVDEV_keyboard_state;
typedef struct SDL_EVDEV_keyboard_state SDL_EVDEV_keyboard_state;
extern SDL_EVDEV_keyboard_state *SDL_EVDEV_kbd_init(void);
extern void SDL_EVDEV_kbd_set_muted(SDL_EVDEV_keyboard_state *state, bool muted);
-extern void SDL_EVDEV_kbd_set_vt_switch_callbacks(SDL_EVDEV_keyboard_state *state, void (*release_callback)(void*), void *release_callback_data, void (*acquire_callback)(void*), void *acquire_callback_data);
+extern void SDL_EVDEV_kbd_set_vt_switch_callbacks(SDL_EVDEV_keyboard_state *state, void (*release_callback)(void *), void *release_callback_data, void (*acquire_callback)(void *), void *acquire_callback_data);
extern void SDL_EVDEV_kbd_update(SDL_EVDEV_keyboard_state *state);
extern void SDL_EVDEV_kbd_keycode(SDL_EVDEV_keyboard_state *state, unsigned int keycode, int down);
extern void SDL_EVDEV_kbd_quit(SDL_EVDEV_keyboard_state *state);
diff --git a/thirdparty/sdl/core/linux/SDL_evdev_kbd_default_accents.h b/thirdparty/sdl/core/linux/SDL_evdev_kbd_default_accents.h
index b6d034c4928..7e3bb29368e 100644
--- a/thirdparty/sdl/core/linux/SDL_evdev_kbd_default_accents.h
+++ b/thirdparty/sdl/core/linux/SDL_evdev_kbd_default_accents.h
@@ -1,6 +1,6 @@
/*
Simple DirectMedia Layer
- Copyright (C) 1997-2025 Sam Lantinga <[email protected]>
+ Copyright (C) 1997-2026 Sam Lantinga <[email protected]>
This software is provided 'as-is', without any express or implied
warranty. In no event will the authors be held liable for any damages
diff --git a/thirdparty/sdl/core/linux/SDL_evdev_kbd_default_keymap.h b/thirdparty/sdl/core/linux/SDL_evdev_kbd_default_keymap.h
index 05294546a29..9a23e52b313 100644
--- a/thirdparty/sdl/core/linux/SDL_evdev_kbd_default_keymap.h
+++ b/thirdparty/sdl/core/linux/SDL_evdev_kbd_default_keymap.h
@@ -1,6 +1,6 @@
/*
Simple DirectMedia Layer
- Copyright (C) 1997-2025 Sam Lantinga <[email protected]>
+ Copyright (C) 1997-2026 Sam Lantinga <[email protected]>
This software is provided 'as-is', without any express or implied
warranty. In no event will the authors be held liable for any damages
diff --git a/thirdparty/sdl/core/linux/SDL_threadprio.c b/thirdparty/sdl/core/linux/SDL_threadprio.c
index 1a3e22faf63..68b11911a19 100644
--- a/thirdparty/sdl/core/linux/SDL_threadprio.c
+++ b/thirdparty/sdl/core/linux/SDL_threadprio.c
@@ -1,6 +1,6 @@
/*
Simple DirectMedia Layer
- Copyright (C) 1997-2025 Sam Lantinga <[email protected]>
+ Copyright (C) 1997-2026 Sam Lantinga <[email protected]>
This software is provided 'as-is', without any express or implied
warranty. In no event will the authors be held liable for any damages
@@ -70,7 +70,7 @@ static Sint64 rtkit_max_rttime_usec = 200000;
static bool realtime_portal_supported(DBusConnection *conn)
{
Sint64 res;
- return SDL_DBus_QueryPropertyOnConnection(conn, XDG_PORTAL_DBUS_NODE, XDG_PORTAL_DBUS_PATH, XDG_PORTAL_DBUS_INTERFACE,
+ return SDL_DBus_QueryPropertyOnConnection(conn, NULL, XDG_PORTAL_DBUS_NODE, XDG_PORTAL_DBUS_PATH, XDG_PORTAL_DBUS_INTERFACE,
"RTTimeUSecMax", DBUS_TYPE_INT64, &res);
}
@@ -111,19 +111,19 @@ static void rtkit_initialize(void)
dbus_conn = get_rtkit_dbus_connection();
// Try getting minimum nice level: this is often greater than PRIO_MIN (-20).
- if (!dbus_conn || !SDL_DBus_QueryPropertyOnConnection(dbus_conn, rtkit_dbus_node, rtkit_dbus_path, rtkit_dbus_interface, "MinNiceLevel",
+ if (!dbus_conn || !SDL_DBus_QueryPropertyOnConnection(dbus_conn, NULL, rtkit_dbus_node, rtkit_dbus_path, rtkit_dbus_interface, "MinNiceLevel",
DBUS_TYPE_INT32, &rtkit_min_nice_level)) {
rtkit_min_nice_level = -20;
}
// Try getting maximum realtime priority: this can be less than the POSIX default (99).
- if (!dbus_conn || !SDL_DBus_QueryPropertyOnConnection(dbus_conn, rtkit_dbus_node, rtkit_dbus_path, rtkit_dbus_interface, "MaxRealtimePriority",
+ if (!dbus_conn || !SDL_DBus_QueryPropertyOnConnection(dbus_conn, NULL, rtkit_dbus_node, rtkit_dbus_path, rtkit_dbus_interface, "MaxRealtimePriority",
DBUS_TYPE_INT32, &rtkit_max_realtime_priority)) {
rtkit_max_realtime_priority = 99;
}
// Try getting maximum rttime allowed by rtkit: exceeding this value will result in SIGKILL
- if (!dbus_conn || !SDL_DBus_QueryPropertyOnConnection(dbus_conn, rtkit_dbus_node, rtkit_dbus_path, rtkit_dbus_interface, "RTTimeUSecMax",
+ if (!dbus_conn || !SDL_DBus_QueryPropertyOnConnection(dbus_conn, NULL, rtkit_dbus_node, rtkit_dbus_path, rtkit_dbus_interface, "RTTimeUSecMax",
DBUS_TYPE_INT64, &rtkit_max_rttime_usec)) {
rtkit_max_rttime_usec = 200000;
}
@@ -202,10 +202,10 @@ static bool rtkit_setpriority_nice(pid_t thread, int nice_level)
nice = rtkit_min_nice_level;
}
- if (!dbus_conn || !SDL_DBus_CallMethodOnConnection(dbus_conn,
- rtkit_dbus_node, rtkit_dbus_path, rtkit_dbus_interface, "MakeThreadHighPriorityWithPID",
- DBUS_TYPE_UINT64, &pid, DBUS_TYPE_UINT64, &tid, DBUS_TYPE_INT32, &nice, DBUS_TYPE_INVALID,
- DBUS_TYPE_INVALID)) {
+ if (!dbus_conn || !SDL_DBus_CallMethodOnConnection(dbus_conn, NULL,
+ rtkit_dbus_node, rtkit_dbus_path, rtkit_dbus_interface, "MakeThreadHighPriorityWithPID",
+ DBUS_TYPE_UINT64, &pid, DBUS_TYPE_UINT64, &tid, DBUS_TYPE_INT32, &nice, DBUS_TYPE_INVALID,
+ DBUS_TYPE_INVALID)) {
return false;
}
return true;
@@ -233,10 +233,10 @@ static bool rtkit_setpriority_realtime(pid_t thread, int rt_priority)
// go through to determine whether it really needs to fail or not.
rtkit_initialize_realtime_thread();
- if (!dbus_conn || !SDL_DBus_CallMethodOnConnection(dbus_conn,
- rtkit_dbus_node, rtkit_dbus_path, rtkit_dbus_interface, "MakeThreadRealtimeWithPID",
- DBUS_TYPE_UINT64, &pid, DBUS_TYPE_UINT64, &tid, DBUS_TYPE_UINT32, &priority, DBUS_TYPE_INVALID,
- DBUS_TYPE_INVALID)) {
+ if (!dbus_conn || !SDL_DBus_CallMethodOnConnection(dbus_conn, NULL,
+ rtkit_dbus_node, rtkit_dbus_path, rtkit_dbus_interface, "MakeThreadRealtimeWithPID",
+ DBUS_TYPE_UINT64, &pid, DBUS_TYPE_UINT64, &tid, DBUS_TYPE_UINT32, &priority, DBUS_TYPE_INVALID,
+ DBUS_TYPE_INVALID)) {
return false;
}
return true;
diff --git a/thirdparty/sdl/core/linux/SDL_udev.c b/thirdparty/sdl/core/linux/SDL_udev.c
index d9e7e118491..f05adeed6db 100644
--- a/thirdparty/sdl/core/linux/SDL_udev.c
+++ b/thirdparty/sdl/core/linux/SDL_udev.c
@@ -1,6 +1,6 @@
/*
Simple DirectMedia Layer
- Copyright (C) 1997-2025 Sam Lantinga <[email protected]>
+ Copyright (C) 1997-2026 Sam Lantinga <[email protected]>
This software is provided 'as-is', without any express or implied
warranty. In no event will the authors be held liable for any damages
@@ -36,8 +36,24 @@
#include "SDL_evdev_capabilities.h"
#include "../unix/SDL_poll.h"
-static const char *SDL_UDEV_LIBS[] = { "libudev.so.1", "libudev.so.0" };
+#define SDL_UDEV_FALLBACK_LIBS "libudev.so.1", "libudev.so.0"
+static const char *SDL_UDEV_LIBS[] = { SDL_UDEV_FALLBACK_LIBS };
+
+#ifdef SDL_UDEV_DYNAMIC
+#define SDL_UDEV_DLNOTE_LIBS SDL_UDEV_DYNAMIC, SDL_UDEV_FALLBACK_LIBS
+#else
+#define SDL_UDEV_DLNOTE_LIBS SDL_UDEV_FALLBACK_LIBS
+#endif
+
+SDL_ELF_NOTE_DLOPEN(
+ "events-udev",
+ "Support for events through libudev",
+ SDL_ELF_NOTE_DLOPEN_PRIORITY_RECOMMENDED,
+ SDL_UDEV_DLNOTE_LIBS
+)
+
+// static SDL_UDEV_PrivateData *_this = NULL;
SDL_UDEV_PrivateData *SDL_UDEV_PrivateData_this = NULL;
#define _this SDL_UDEV_PrivateData_this
@@ -69,6 +85,7 @@ static bool SDL_UDEV_load_syms(void)
SDL_UDEV_SYM(udev_device_get_action);
SDL_UDEV_SYM(udev_device_get_devnode);
+ SDL_UDEV_SYM(udev_device_get_driver);
SDL_UDEV_SYM(udev_device_get_syspath);
SDL_UDEV_SYM(udev_device_get_subsystem);
SDL_UDEV_SYM(udev_device_get_parent_with_subsystem_devtype);
@@ -220,51 +237,58 @@ bool SDL_UDEV_Scan(void)
return true;
}
-bool SDL_UDEV_GetProductInfo(const char *device_path, Uint16 *vendor, Uint16 *product, Uint16 *version, int *class)
+bool SDL_UDEV_GetProductInfo(const char *device_path, struct input_id *inpid, int *class, char **driver)
{
struct stat statbuf;
char type;
struct udev_device *dev;
- const char* val;
+ const char *val;
int class_temp;
if (!_this) {
return false;
}
- if (stat(device_path, &statbuf) == -1) {
+ if (stat(device_path, &statbuf) < 0) {
return false;
}
if (S_ISBLK(statbuf.st_mode)) {
type = 'b';
- }
- else if (S_ISCHR(statbuf.st_mode)) {
+ } else if (S_ISCHR(statbuf.st_mode)) {
type = 'c';
- }
- else {
+ } else {
return false;
}
dev = _this->syms.udev_device_new_from_devnum(_this->udev, type, statbuf.st_rdev);
-
if (!dev) {
return false;
}
val = _this->syms.udev_device_get_property_value(dev, "ID_VENDOR_ID");
if (val) {
- *vendor = (Uint16)SDL_strtol(val, NULL, 16);
+ inpid->vendor = (Uint16)SDL_strtol(val, NULL, 16);
}
val = _this->syms.udev_device_get_property_value(dev, "ID_MODEL_ID");
if (val) {
- *product = (Uint16)SDL_strtol(val, NULL, 16);
+ inpid->product = (Uint16)SDL_strtol(val, NULL, 16);
}
val = _this->syms.udev_device_get_property_value(dev, "ID_REVISION");
if (val) {
- *version = (Uint16)SDL_strtol(val, NULL, 16);
+ inpid->version = (Uint16)SDL_strtol(val, NULL, 16);
+ }
+
+ if (driver) {
+ val = _this->syms.udev_device_get_driver(dev);
+ if (!val) {
+ val = _this->syms.udev_device_get_property_value(dev, "ID_USB_DRIVER");
+ }
+ if (val) {
+ *driver = SDL_strdup(val);
+ }
}
class_temp = device_class(dev);
@@ -277,19 +301,20 @@ bool SDL_UDEV_GetProductInfo(const char *device_path, Uint16 *vendor, Uint16 *pr
return true;
}
-bool SDL_UDEV_GetProductSerial(const char *device_path, const char **serial)
+char *SDL_UDEV_GetProductSerial(const char *device_path)
{
struct stat statbuf;
char type;
struct udev_device *dev;
const char *val;
+ char *result = NULL;
if (!_this) {
- return false;
+ return NULL;
}
if (stat(device_path, &statbuf) < 0) {
- return false;
+ return NULL;
}
if (S_ISBLK(statbuf.st_mode)) {
@@ -297,21 +322,22 @@ bool SDL_UDEV_GetProductSerial(const char *device_path, const char **serial)
} else if (S_ISCHR(statbuf.st_mode)) {
type = 'c';
} else {
- return false;
+ return NULL;
}
dev = _this->syms.udev_device_new_from_devnum(_this->udev, type, statbuf.st_rdev);
if (!dev) {
- return false;
+ return NULL;
}
val = _this->syms.udev_device_get_property_value(dev, "ID_SERIAL_SHORT");
- if (val) {
- *serial = val;
- return true;
+ if (val && *val) {
+ result = SDL_strdup(val);
}
- return false;
+ _this->syms.udev_device_unref(dev);
+
+ return result;
}
void SDL_UDEV_UnloadLibrary(void)
@@ -440,6 +466,7 @@ static int device_class(struct udev_device *dev)
{
const char *subsystem;
const char *val = NULL;
+ const char *attr = NULL;
int devclass = 0;
subsystem = _this->syms.udev_device_get_subsystem(dev);
@@ -451,8 +478,18 @@ static int device_class(struct udev_device *dev)
devclass = SDL_UDEV_DEVICE_SOUND;
} else if (SDL_strcmp(subsystem, "video4linux") == 0) {
val = _this->syms.udev_device_get_property_value(dev, "ID_V4L_CAPABILITIES");
- if (val && SDL_strcasestr(val, "capture")) {
- devclass = SDL_UDEV_DEVICE_VIDEO_CAPTURE;
+ if (val) {
+ if (SDL_strcasestr(val, "capture")) {
+ devclass = SDL_UDEV_DEVICE_VIDEO_CAPTURE;
+ }
+ // v4l2loopback may report output caps before reporting capture caps
+ // and ID_V4L_CAPABILITIES is never updated
+ else if (SDL_strcasestr(val, "video_output")) {
+ attr = _this->syms.udev_device_get_sysattr_value(dev, "state");
+ if (attr && SDL_strcmp(attr, "capture") == 0) {
+ devclass = SDL_UDEV_DEVICE_VIDEO_CAPTURE;
+ }
+ }
}
} else if (SDL_strcmp(subsystem, "input") == 0) {
// udev rules reference: http://cgit.freedesktop.org/systemd/systemd/tree/src/udev/udev-builtin-input_id.c
diff --git a/thirdparty/sdl/core/linux/SDL_udev.h b/thirdparty/sdl/core/linux/SDL_udev.h
index 9b18fa228b2..5958ba4f371 100644
--- a/thirdparty/sdl/core/linux/SDL_udev.h
+++ b/thirdparty/sdl/core/linux/SDL_udev.h
@@ -1,6 +1,6 @@
/*
Simple DirectMedia Layer
- Copyright (C) 1997-2025 Sam Lantinga <[email protected]>
+ Copyright (C) 1997-2026 Sam Lantinga <[email protected]>
This software is provided 'as-is', without any express or implied
warranty. In no event will the authors be held liable for any damages
@@ -30,8 +30,9 @@
#define SDL_USE_LIBUDEV 1
#endif
-//#include <libudev.h>
+// #include <libudev.h>
#include <thirdparty/linuxbsd_headers/udev/libudev.h>
+#include <linux/input.h>
#include <sys/time.h>
#include <sys/types.h>
@@ -57,6 +58,7 @@ typedef struct SDL_UDEV_Symbols
{
const char *(*udev_device_get_action)(struct udev_device *);
const char *(*udev_device_get_devnode)(struct udev_device *);
+ const char *(*udev_device_get_driver)(struct udev_device *);
const char *(*udev_device_get_syspath)(struct udev_device *);
const char *(*udev_device_get_subsystem)(struct udev_device *);
struct udev_device *(*udev_device_get_parent_with_subsystem_devtype)(struct udev_device *udev_device, const char *subsystem, const char *devtype);
@@ -103,8 +105,8 @@ extern void SDL_UDEV_UnloadLibrary(void);
extern bool SDL_UDEV_LoadLibrary(void);
extern void SDL_UDEV_Poll(void);
extern bool SDL_UDEV_Scan(void);
-extern bool SDL_UDEV_GetProductInfo(const char *device_path, Uint16 *vendor, Uint16 *product, Uint16 *version, int *class);
-extern bool SDL_UDEV_GetProductSerial(const char *device_path, const char **serial);
+extern bool SDL_UDEV_GetProductInfo(const char *device_path, struct input_id *inpid, int *class, char **driver);
+extern char *SDL_UDEV_GetProductSerial(const char *device_path);
extern bool SDL_UDEV_AddCallback(SDL_UDEV_Callback cb);
extern void SDL_UDEV_DelCallback(SDL_UDEV_Callback cb);
extern const SDL_UDEV_Symbols *SDL_UDEV_GetUdevSyms(void);
diff --git a/thirdparty/sdl/core/unix/SDL_appid.c b/thirdparty/sdl/core/unix/SDL_appid.c
index 996e216cd54..fd0037eb7e6 100644
--- a/thirdparty/sdl/core/unix/SDL_appid.c
+++ b/thirdparty/sdl/core/unix/SDL_appid.c
@@ -1,6 +1,6 @@
/*
Simple DirectMedia Layer
- Copyright (C) 1997-2025 Sam Lantinga <[email protected]>
+ Copyright (C) 1997-2026 Sam Lantinga <[email protected]>
This software is provided 'as-is', without any express or implied
warranty. In no event will the authors be held liable for any damages
@@ -24,46 +24,13 @@
#include "SDL_appid.h"
#include <unistd.h>
-const char *SDL_GetExeName(void)
-{
- static const char *proc_name = NULL;
-
- // TODO: Use a fallback if BSD has no mounted procfs (OpenBSD has no procfs at all)
- if (!proc_name) {
-#if defined(SDL_PLATFORM_LINUX) || defined(SDL_PLATFORM_FREEBSD) || defined (SDL_PLATFORM_NETBSD)
- static char linkfile[1024];
- int linksize;
-
-#if defined(SDL_PLATFORM_LINUX)
- const char *proc_path = "/proc/self/exe";
-#elif defined(SDL_PLATFORM_FREEBSD)
- const char *proc_path = "/proc/curproc/file";
-#elif defined(SDL_PLATFORM_NETBSD)
- const char *proc_path = "/proc/curproc/exe";
-#endif
- linksize = readlink(proc_path, linkfile, sizeof(linkfile) - 1);
- if (linksize > 0) {
- linkfile[linksize] = '\0';
- proc_name = SDL_strrchr(linkfile, '/');
- if (proc_name) {
- ++proc_name;
- } else {
- proc_name = linkfile;
- }
- }
-#endif
- }
-
- return proc_name;
-}
-
const char *SDL_GetAppID(void)
{
const char *id_str = SDL_GetAppMetadataProperty(SDL_PROP_APP_METADATA_IDENTIFIER_STRING);
if (!id_str) {
// If the hint isn't set, try to use the application's executable name
- id_str = SDL_GetExeName();
+ // id_str = SDL_GetExeName();
}
if (!id_str) {
@@ -73,3 +40,4 @@ const char *SDL_GetAppID(void)
return id_str;
}
+
diff --git a/thirdparty/sdl/core/unix/SDL_appid.h b/thirdparty/sdl/core/unix/SDL_appid.h
index 34825212747..5f8eb932e6c 100644
--- a/thirdparty/sdl/core/unix/SDL_appid.h
+++ b/thirdparty/sdl/core/unix/SDL_appid.h
@@ -1,6 +1,6 @@
/*
Simple DirectMedia Layer
-Copyright (C) 1997-2025 Sam Lantinga <[email protected]>
+Copyright (C) 1997-2026 Sam Lantinga <[email protected]>
This software is provided 'as-is', without any express or implied
warranty. In no event will the authors be held liable for any damages
@@ -24,7 +24,6 @@ freely, subject to the following restrictions:
#ifndef SDL_appid_h_
#define SDL_appid_h_
-extern const char *SDL_GetExeName(void);
extern const char *SDL_GetAppID(void);
#endif // SDL_appid_h_
diff --git a/thirdparty/sdl/core/unix/SDL_poll.c b/thirdparty/sdl/core/unix/SDL_poll.c
index 572ed5a65b8..641fc17c6b1 100644
--- a/thirdparty/sdl/core/unix/SDL_poll.c
+++ b/thirdparty/sdl/core/unix/SDL_poll.c
@@ -1,6 +1,6 @@
/*
Simple DirectMedia Layer
- Copyright (C) 1997-2025 Sam Lantinga <[email protected]>
+ Copyright (C) 1997-2026 Sam Lantinga <[email protected]>
This software is provided 'as-is', without any express or implied
warranty. In no event will the authors be held liable for any damages
@@ -23,15 +23,13 @@
#include "SDL_poll.h"
-#ifdef HAVE_POLL
#include <poll.h>
-#else
-#include <sys/time.h>
-#include <sys/types.h>
-#include <unistd.h>
-#endif
#include <errno.h>
+#ifdef HAVE_PPOLL
+#include <time.h>
+#endif
+
int SDL_IOReady(int fd, int flags, Sint64 timeoutNS)
{
int result;
@@ -40,9 +38,7 @@ int SDL_IOReady(int fd, int flags, Sint64 timeoutNS)
// Note: We don't bother to account for elapsed time if we get EINTR
do {
-#ifdef HAVE_POLL
struct pollfd info;
- int timeoutMS;
info.fd = fd;
info.events = 0;
@@ -52,7 +48,21 @@ int SDL_IOReady(int fd, int flags, Sint64 timeoutNS)
if (flags & SDL_IOR_WRITE) {
info.events |= POLLOUT;
}
- // FIXME: Add support for ppoll() for nanosecond precision
+
+#ifdef HAVE_PPOLL
+ struct timespec *timeout = NULL;
+ struct timespec ts;
+
+ if (timeoutNS >= 0) {
+ ts.tv_sec = SDL_NS_TO_SECONDS(timeoutNS);
+ ts.tv_nsec = timeoutNS - SDL_SECONDS_TO_NS(ts.tv_sec);
+ timeout = &ts;
+ }
+
+ result = ppoll(&info, 1, timeout, NULL);
+#else
+ int timeoutMS;
+
if (timeoutNS > 0) {
timeoutMS = (int)SDL_NS_TO_MS(timeoutNS + (SDL_NS_PER_MS - 1));
} else if (timeoutNS == 0) {
@@ -61,34 +71,7 @@ int SDL_IOReady(int fd, int flags, Sint64 timeoutNS)
timeoutMS = -1;
}
result = poll(&info, 1, timeoutMS);
-#else
- fd_set rfdset, *rfdp = NULL;
- fd_set wfdset, *wfdp = NULL;
- struct timeval tv, *tvp = NULL;
-
- // If this assert triggers we'll corrupt memory here
- SDL_assert(fd >= 0 && fd < FD_SETSIZE);
-
- if (flags & SDL_IOR_READ) {
- FD_ZERO(&rfdset);
- FD_SET(fd, &rfdset);
- rfdp = &rfdset;
- }
- if (flags & SDL_IOR_WRITE) {
- FD_ZERO(&wfdset);
- FD_SET(fd, &wfdset);
- wfdp = &wfdset;
- }
-
- if (timeoutNS >= 0) {
- tv.tv_sec = (timeoutNS / SDL_NS_PER_SECOND);
- tv.tv_usec = SDL_NS_TO_US((timeoutNS % SDL_NS_PER_SECOND) + (SDL_NS_PER_US - 1));
- tvp = &tv;
- }
-
- result = select(fd + 1, rfdp, wfdp, NULL, tvp);
-#endif // HAVE_POLL
-
+#endif
} while (result < 0 && errno == EINTR && !(flags & SDL_IOR_NO_RETRY));
return result;
diff --git a/thirdparty/sdl/core/unix/SDL_poll.h b/thirdparty/sdl/core/unix/SDL_poll.h
index 571619d4fe7..5001c617a84 100644
--- a/thirdparty/sdl/core/unix/SDL_poll.h
+++ b/thirdparty/sdl/core/unix/SDL_poll.h
@@ -1,6 +1,6 @@
/*
Simple DirectMedia Layer
- Copyright (C) 1997-2025 Sam Lantinga <[email protected]>
+ Copyright (C) 1997-2026 Sam Lantinga <[email protected]>
This software is provided 'as-is', without any express or implied
warranty. In no event will the authors be held liable for any damages
diff --git a/thirdparty/sdl/core/windows/SDL_directx.h b/thirdparty/sdl/core/windows/SDL_directx.h
index 6101e922341..77b13dd00dc 100644
--- a/thirdparty/sdl/core/windows/SDL_directx.h
+++ b/thirdparty/sdl/core/windows/SDL_directx.h
@@ -1,6 +1,6 @@
/*
Simple DirectMedia Layer
- Copyright (C) 1997-2025 Sam Lantinga <[email protected]>
+ Copyright (C) 1997-2026 Sam Lantinga <[email protected]>
This software is provided 'as-is', without any express or implied
warranty. In no event will the authors be held liable for any damages
diff --git a/thirdparty/sdl/core/windows/SDL_gameinput.c b/thirdparty/sdl/core/windows/SDL_gameinput.cpp
similarity index 74%
rename from thirdparty/sdl/core/windows/SDL_gameinput.c
rename to thirdparty/sdl/core/windows/SDL_gameinput.cpp
index 9ac5912db9d..baf7ed21654 100644
--- a/thirdparty/sdl/core/windows/SDL_gameinput.c
+++ b/thirdparty/sdl/core/windows/SDL_gameinput.cpp
@@ -1,6 +1,6 @@
/*
Simple DirectMedia Layer
- Copyright (C) 1997-2025 Sam Lantinga <[email protected]>
+ Copyright (C) 1997-2026 Sam Lantinga <[email protected]>
This software is provided 'as-is', without any express or implied
warranty. In no event will the authors be held liable for any damages
@@ -25,16 +25,11 @@
#include "SDL_windows.h"
#include "SDL_gameinput.h"
-#ifdef SDL_PLATFORM_WIN32
-#include <initguid.h>
-// {11BE2A7E-4254-445A-9C09-FFC40F006918}
-DEFINE_GUID(SDL_IID_GameInput, 0x11BE2A7E, 0x4254, 0x445A, 0x9C, 0x09, 0xFF, 0xC4, 0x0F, 0x00, 0x69, 0x18);
-#endif
-
static SDL_SharedObject *g_hGameInputDLL;
static IGameInput *g_pGameInput;
static int g_nGameInputRefCount;
+
bool SDL_InitGameInput(IGameInput **ppGameInput)
{
if (g_nGameInputRefCount == 0) {
@@ -43,30 +38,34 @@ bool SDL_InitGameInput(IGameInput **ppGameInput)
return false;
}
- typedef HRESULT (WINAPI *GameInputCreate_t)(IGameInput * *gameInput);
- GameInputCreate_t GameInputCreateFunc = (GameInputCreate_t)SDL_LoadFunction(g_hGameInputDLL, "GameInputCreate");
- if (!GameInputCreateFunc) {
+ typedef HRESULT (WINAPI *pfnGameInputCreate)(IGameInput **gameInput);
+ pfnGameInputCreate pGameInputCreate = (pfnGameInputCreate)SDL_LoadFunction(g_hGameInputDLL, "GameInputCreate");
+ if (!pGameInputCreate) {
SDL_UnloadObject(g_hGameInputDLL);
return false;
}
IGameInput *pGameInput = NULL;
- HRESULT hr = GameInputCreateFunc(&pGameInput);
+ HRESULT hr = pGameInputCreate(&pGameInput);
if (FAILED(hr)) {
SDL_UnloadObject(g_hGameInputDLL);
return WIN_SetErrorFromHRESULT("GameInputCreate failed", hr);
}
#ifdef SDL_PLATFORM_WIN32
- hr = IGameInput_QueryInterface(pGameInput, &SDL_IID_GameInput, (void **)&g_pGameInput);
- IGameInput_Release(pGameInput);
+#if GAMEINPUT_API_VERSION >= 1
+ hr = pGameInput->QueryInterface(IID_IGameInput, (void **)&g_pGameInput);
+#else
+ // We require GameInput v1.1 or newer
+ hr = E_NOINTERFACE;
+#endif
+ pGameInput->Release();
if (FAILED(hr)) {
SDL_UnloadObject(g_hGameInputDLL);
return WIN_SetErrorFromHRESULT("GameInput QueryInterface failed", hr);
}
#else
// Assume that the version we get is compatible with the current SDK
- // If that isn't the case, define the correct GUID for SDL_IID_GameInput above
g_pGameInput = pGameInput;
#endif
}
@@ -85,7 +84,7 @@ void SDL_QuitGameInput(void)
--g_nGameInputRefCount;
if (g_nGameInputRefCount == 0) {
if (g_pGameInput) {
- IGameInput_Release(g_pGameInput);
+ g_pGameInput->Release();
g_pGameInput = NULL;
}
if (g_hGameInputDLL) {
diff --git a/thirdparty/sdl/core/windows/SDL_gameinput.h b/thirdparty/sdl/core/windows/SDL_gameinput.h
index 0022c0bdde1..0d7b6f85e74 100644
--- a/thirdparty/sdl/core/windows/SDL_gameinput.h
+++ b/thirdparty/sdl/core/windows/SDL_gameinput.h
@@ -1,6 +1,6 @@
/*
Simple DirectMedia Layer
- Copyright (C) 1997-2025 Sam Lantinga <[email protected]>
+ Copyright (C) 1997-2026 Sam Lantinga <[email protected]>
This software is provided 'as-is', without any express or implied
warranty. In no event will the authors be held liable for any damages
@@ -25,9 +25,20 @@
#ifdef HAVE_GAMEINPUT_H
-#define COBJMACROS
#include <gameinput.h>
+#ifndef GAMEINPUT_API_VERSION
+#define GAMEINPUT_API_VERSION 0
+#endif
+
+#if GAMEINPUT_API_VERSION == 3
+using namespace GameInput::v3;
+#elif GAMEINPUT_API_VERSION == 2
+using namespace GameInput::v2;
+#elif GAMEINPUT_API_VERSION == 1
+using namespace GameInput::v1;
+#endif
+
extern bool SDL_InitGameInput(IGameInput **ppGameInput);
extern void SDL_QuitGameInput(void);
diff --git a/thirdparty/sdl/core/windows/SDL_hid.c b/thirdparty/sdl/core/windows/SDL_hid.c
index 87e873544ab..1f629d58d21 100644
--- a/thirdparty/sdl/core/windows/SDL_hid.c
+++ b/thirdparty/sdl/core/windows/SDL_hid.c
@@ -1,6 +1,6 @@
/*
Simple DirectMedia Layer
- Copyright (C) 1997-2025 Sam Lantinga <[email protected]>
+ Copyright (C) 1997-2026 Sam Lantinga <[email protected]>
This software is provided 'as-is', without any express or implied
warranty. In no event will the authors be held liable for any damages
@@ -175,12 +175,39 @@ static CM_Register_NotificationFunc CM_Register_Notification;
static CM_Unregister_NotificationFunc CM_Unregister_Notification;
static HCMNOTIFICATION s_DeviceNotificationFuncHandle;
static Uint64 s_LastDeviceNotification = 1;
+static HANDLE s_HotplugEvent = INVALID_HANDLE_VALUE;
+static SDL_AtomicInt s_HotplugRunning;
+static SDL_Thread *s_HotplugThread;
+
+#ifdef SDL_VIDEO_DRIVER_WINDOWS
+// Defined in SDL_windowsevents.c
+extern void WIN_CheckKeyboardAndMouseHotplug(bool hid_loaded);
+#endif
+
+static int SDLCALL DeviceHotplugThread(void *unused)
+{
+ bool hid_loaded = WIN_LoadHIDDLL();
+
+ // Always run the initial device detection
+ do {
+#ifdef SDL_VIDEO_DRIVER_WINDOWS
+ WIN_CheckKeyboardAndMouseHotplug(hid_loaded);
+#endif
+ WaitForSingleObject(s_HotplugEvent, INFINITE);
+ } while (SDL_GetAtomicInt(&s_HotplugRunning));
+
+ if (hid_loaded) {
+ WIN_UnloadHIDDLL();
+ }
+ return 0;
+}
static DWORD CALLBACK SDL_DeviceNotificationFunc(HCMNOTIFICATION hNotify, PVOID context, CM_NOTIFY_ACTION action, PCM_NOTIFY_EVENT_DATA eventData, DWORD event_data_size)
{
if (action == CM_NOTIFY_ACTION_DEVICEINTERFACEARRIVAL ||
action == CM_NOTIFY_ACTION_DEVICEINTERFACEREMOVAL) {
s_LastDeviceNotification = SDL_GetTicksNS();
+ SetEvent(s_HotplugEvent);
}
return ERROR_SUCCESS;
}
@@ -192,6 +219,11 @@ void WIN_InitDeviceNotification(void)
return;
}
+ // Start the device hotplug thread
+ SDL_SetAtomicInt(&s_HotplugRunning, true);
+ s_HotplugEvent = CreateEvent(NULL, FALSE, FALSE, NULL);
+ s_HotplugThread = SDL_CreateThread(DeviceHotplugThread, "DeviceHotplugThread", NULL);
+
cfgmgr32_lib_handle = LoadLibraryA("cfgmgr32.dll");
if (cfgmgr32_lib_handle) {
CM_Register_Notification = (CM_Register_NotificationFunc)GetProcAddress(cfgmgr32_lib_handle, "CM_Register_Notification");
@@ -225,6 +257,12 @@ void WIN_QuitDeviceNotification(void)
// Make sure we have balanced calls to init/quit
SDL_assert(s_DeviceNotificationsRequested == 0);
+ // Stop the device hotplug thread
+ SDL_SetAtomicInt(&s_HotplugRunning, false);
+ SetEvent(s_HotplugEvent);
+ SDL_WaitThread(s_HotplugThread, NULL);
+ s_HotplugThread = NULL;
+
if (cfgmgr32_lib_handle) {
if (s_DeviceNotificationFuncHandle && CM_Unregister_Notification) {
CM_Unregister_Notification(s_DeviceNotificationFuncHandle);
diff --git a/thirdparty/sdl/core/windows/SDL_hid.h b/thirdparty/sdl/core/windows/SDL_hid.h
index 46c22f243cf..f085f6836ca 100644
--- a/thirdparty/sdl/core/windows/SDL_hid.h
+++ b/thirdparty/sdl/core/windows/SDL_hid.h
@@ -1,6 +1,6 @@
/*
Simple DirectMedia Layer
- Copyright (C) 1997-2025 Sam Lantinga <[email protected]>
+ Copyright (C) 1997-2026 Sam Lantinga <[email protected]>
This software is provided 'as-is', without any express or implied
warranty. In no event will the authors be held liable for any damages
diff --git a/thirdparty/sdl/core/windows/SDL_immdevice.c b/thirdparty/sdl/core/windows/SDL_immdevice.c
index cc6945b1bcb..64cea6d2c97 100644
--- a/thirdparty/sdl/core/windows/SDL_immdevice.c
+++ b/thirdparty/sdl/core/windows/SDL_immdevice.c
@@ -1,6 +1,6 @@
/*
Simple DirectMedia Layer
- Copyright (C) 1997-2025 Sam Lantinga <[email protected]>
+ Copyright (C) 1997-2026 Sam Lantinga <[email protected]>
This software is provided 'as-is', without any express or implied
warranty. In no event will the authors be held liable for any damages
@@ -120,7 +120,7 @@ void SDL_IMMDevice_FreeDeviceHandle(SDL_AudioDevice *device)
}
}
-static SDL_AudioDevice *SDL_IMMDevice_Add(const bool recording, const char *devname, WAVEFORMATEXTENSIBLE *fmt, LPCWSTR devid, GUID *dsoundguid, SDL_AudioFormat force_format)
+static SDL_AudioDevice *SDL_IMMDevice_Add(const bool recording, const char *devname, WAVEFORMATEXTENSIBLE *fmt, LPCWSTR devid, GUID *dsoundguid, SDL_AudioFormat force_format, bool supports_recording_playback_devices)
{
/* You can have multiple endpoints on a device that are mutually exclusive ("Speakers" vs "Line Out" or whatever).
In a perfect world, things that are unplugged won't be in this collection. The only gotcha is probably for
@@ -147,7 +147,7 @@ static SDL_AudioDevice *SDL_IMMDevice_Add(const bool recording, const char *devn
if (!device) {
// handle is freed by SDL_IMMDevice_FreeDeviceHandle!
- SDL_IMMDevice_HandleData *handle = (SDL_IMMDevice_HandleData *)SDL_malloc(sizeof(SDL_IMMDevice_HandleData));
+ SDL_IMMDevice_HandleData *handle = (SDL_IMMDevice_HandleData *)SDL_calloc(1, sizeof(*handle));
if (!handle) {
return NULL;
}
@@ -156,7 +156,7 @@ static SDL_AudioDevice *SDL_IMMDevice_Add(const bool recording, const char *devn
SDL_free(handle);
return NULL;
}
- SDL_memcpy(&handle->directsound_guid, dsoundguid, sizeof(GUID));
+ SDL_copyp(&handle->directsound_guid, dsoundguid);
SDL_AudioSpec spec;
SDL_zero(spec);
@@ -165,6 +165,28 @@ static SDL_AudioDevice *SDL_IMMDevice_Add(const bool recording, const char *devn
spec.format = (force_format != SDL_AUDIO_UNKNOWN) ? force_format : SDL_WaveFormatExToSDLFormat((WAVEFORMATEX *)fmt);
device = SDL_AddAudioDevice(recording, devname, &spec, handle);
+
+ if (!recording && supports_recording_playback_devices) {
+ // handle is freed by SDL_IMMDevice_FreeDeviceHandle!
+ SDL_IMMDevice_HandleData *recording_handle = (SDL_IMMDevice_HandleData *)SDL_malloc(sizeof(*recording_handle));
+ if (!recording_handle) {
+ return NULL;
+ }
+
+ recording_handle->immdevice_id = SDL_wcsdup(devid);
+ if (!recording_handle->immdevice_id) {
+ SDL_free(recording_handle);
+ return NULL;
+ }
+
+ SDL_copyp(&recording_handle->directsound_guid, dsoundguid);
+
+ if (!SDL_AddAudioDevice(true, devname, &spec, recording_handle)) {
+ SDL_free(recording_handle->immdevice_id);
+ SDL_free(recording_handle);
+ }
+ }
+
if (!device) {
SDL_free(handle->immdevice_id);
SDL_free(handle);
@@ -184,6 +206,7 @@ typedef struct SDLMMNotificationClient
const IMMNotificationClientVtbl *lpVtbl;
SDL_AtomicInt refcount;
SDL_AudioFormat force_format;
+ bool supports_recording_playback_devices;
} SDLMMNotificationClient;
static HRESULT STDMETHODCALLTYPE SDLMMNotificationClient_QueryInterface(IMMNotificationClient *client, REFIID iid, void **ppv)
@@ -257,7 +280,7 @@ static HRESULT STDMETHODCALLTYPE SDLMMNotificationClient_OnDeviceStateChanged(IM
GUID dsoundguid;
GetMMDeviceInfo(device, &utf8dev, &fmt, &dsoundguid);
if (utf8dev) {
- SDL_IMMDevice_Add(recording, utf8dev, &fmt, pwstrDeviceId, &dsoundguid, client->force_format);
+ SDL_IMMDevice_Add(recording, utf8dev, &fmt, pwstrDeviceId, &dsoundguid, client->force_format, client->supports_recording_playback_devices);
SDL_free(utf8dev);
}
} else {
@@ -288,7 +311,7 @@ static const IMMNotificationClientVtbl notification_client_vtbl = {
SDLMMNotificationClient_OnPropertyValueChanged
};
-static SDLMMNotificationClient notification_client = { &notification_client_vtbl, { 1 }, SDL_AUDIO_UNKNOWN };
+static SDLMMNotificationClient notification_client = { &notification_client_vtbl, { 1 }, SDL_AUDIO_UNKNOWN, false };
bool SDL_IMMDevice_Init(const SDL_IMMDevice_callbacks *callbacks)
{
@@ -365,7 +388,23 @@ bool SDL_IMMDevice_Get(SDL_AudioDevice *device, IMMDevice **immdevice, bool reco
return true;
}
-static void EnumerateEndpointsForFlow(const bool recording, SDL_AudioDevice **default_device, SDL_AudioFormat force_format)
+bool SDL_IMMDevice_GetIsCapture(IMMDevice *device)
+{
+ bool iscapture = false;
+ IMMEndpoint *endpoint = NULL;
+ if (SUCCEEDED(IMMDevice_QueryInterface(device, &SDL_IID_IMMEndpoint, (void **)&endpoint))) {
+ EDataFlow flow;
+
+ if (SUCCEEDED(IMMEndpoint_GetDataFlow(endpoint, &flow))) {
+ iscapture = (flow == eCapture);
+ }
+ }
+
+ IMMEndpoint_Release(endpoint);
+ return iscapture;
+}
+
+static void EnumerateEndpointsForFlow(const bool recording, SDL_AudioDevice **default_device, SDL_AudioFormat force_format, bool supports_recording_playback_devices)
{
/* Note that WASAPI separates "adapter devices" from "audio endpoint devices"
...one adapter device ("SoundBlaster Pro") might have multiple endpoint devices ("Speakers", "Line-Out"). */
@@ -407,7 +446,7 @@ static void EnumerateEndpointsForFlow(const bool recording, SDL_AudioDevice **de
SDL_zero(dsoundguid);
GetMMDeviceInfo(immdevice, &devname, &fmt, &dsoundguid);
if (devname) {
- SDL_AudioDevice *sdldevice = SDL_IMMDevice_Add(recording, devname, &fmt, devid, &dsoundguid, force_format);
+ SDL_AudioDevice *sdldevice = SDL_IMMDevice_Add(recording, devname, &fmt, devid, &dsoundguid, force_format, supports_recording_playback_devices);
if (default_device && default_devid && SDL_wcscmp(default_devid, devid) == 0) {
*default_device = sdldevice;
}
@@ -424,12 +463,13 @@ static void EnumerateEndpointsForFlow(const bool recording, SDL_AudioDevice **de
IMMDeviceCollection_Release(collection);
}
-void SDL_IMMDevice_EnumerateEndpoints(SDL_AudioDevice **default_playback, SDL_AudioDevice **default_recording, SDL_AudioFormat force_format)
+void SDL_IMMDevice_EnumerateEndpoints(SDL_AudioDevice **default_playback, SDL_AudioDevice **default_recording, SDL_AudioFormat force_format, bool supports_recording_playback_devices)
{
- EnumerateEndpointsForFlow(false, default_playback, force_format);
- EnumerateEndpointsForFlow(true, default_recording, force_format);
+ EnumerateEndpointsForFlow(false, default_playback, force_format, supports_recording_playback_devices);
+ EnumerateEndpointsForFlow(true, default_recording, force_format, supports_recording_playback_devices);
notification_client.force_format = force_format;
+ notification_client.supports_recording_playback_devices = supports_recording_playback_devices;
// if this fails, we just won't get hotplug events. Carry on anyhow.
IMMDeviceEnumerator_RegisterEndpointNotificationCallback(enumerator, (IMMNotificationClient *)&notification_client);
diff --git a/thirdparty/sdl/core/windows/SDL_immdevice.h b/thirdparty/sdl/core/windows/SDL_immdevice.h
index 0582bc0deda..3fc55485831 100644
--- a/thirdparty/sdl/core/windows/SDL_immdevice.h
+++ b/thirdparty/sdl/core/windows/SDL_immdevice.h
@@ -1,6 +1,6 @@
/*
Simple DirectMedia Layer
- Copyright (C) 1997-2025 Sam Lantinga <[email protected]>
+ Copyright (C) 1997-2026 Sam Lantinga <[email protected]>
This software is provided 'as-is', without any express or implied
warranty. In no event will the authors be held liable for any damages
@@ -37,7 +37,8 @@ typedef struct SDL_IMMDevice_callbacks
bool SDL_IMMDevice_Init(const SDL_IMMDevice_callbacks *callbacks);
void SDL_IMMDevice_Quit(void);
bool SDL_IMMDevice_Get(struct SDL_AudioDevice *device, IMMDevice **immdevice, bool recording);
-void SDL_IMMDevice_EnumerateEndpoints(struct SDL_AudioDevice **default_playback, struct SDL_AudioDevice **default_recording, SDL_AudioFormat force_format);
+bool SDL_IMMDevice_GetIsCapture(IMMDevice* device);
+void SDL_IMMDevice_EnumerateEndpoints(struct SDL_AudioDevice **default_playback, struct SDL_AudioDevice **default_recording, SDL_AudioFormat force_format, bool supports_recording_playback_devices);
LPGUID SDL_IMMDevice_GetDirectSoundGUID(struct SDL_AudioDevice *device);
LPCWSTR SDL_IMMDevice_GetDevID(struct SDL_AudioDevice *device);
void SDL_IMMDevice_FreeDeviceHandle(struct SDL_AudioDevice *device);
diff --git a/thirdparty/sdl/core/windows/SDL_windows.c b/thirdparty/sdl/core/windows/SDL_windows.c
index cf53c3c72db..c7924bf934b 100644
--- a/thirdparty/sdl/core/windows/SDL_windows.c
+++ b/thirdparty/sdl/core/windows/SDL_windows.c
@@ -1,6 +1,6 @@
/*
Simple DirectMedia Layer
- Copyright (C) 1997-2025 Sam Lantinga <[email protected]>
+ Copyright (C) 1997-2026 Sam Lantinga <[email protected]>
This software is provided 'as-is', without any express or implied
warranty. In no event will the authors be held liable for any damages
@@ -24,6 +24,10 @@
#include "SDL_windows.h"
+// #include "../../video/SDL_surface_c.h"
+
+#include <shellapi.h> // CommandLineToArgvW()
+
#include <objbase.h> // for CoInitialize/CoUninitialize (Win32 only)
#ifdef HAVE_ROAPI_H
#include <roapi.h> // For RoInitialize/RoUninitialize (Win32 only)
@@ -35,16 +39,6 @@ typedef enum RO_INIT_TYPE
} RO_INIT_TYPE;
#endif
-#ifndef _WIN32_WINNT_VISTA
-#define _WIN32_WINNT_VISTA 0x0600
-#endif
-#ifndef _WIN32_WINNT_WIN7
-#define _WIN32_WINNT_WIN7 0x0601
-#endif
-#ifndef _WIN32_WINNT_WIN8
-#define _WIN32_WINNT_WIN8 0x0602
-#endif
-
#ifndef LOAD_LIBRARY_SEARCH_SYSTEM32
#define LOAD_LIBRARY_SEARCH_SYSTEM32 0x00000800
#endif
@@ -53,6 +47,44 @@ typedef enum RO_INIT_TYPE
#define WC_ERR_INVALID_CHARS 0x00000080
#endif
+// Dark mode support
+typedef enum {
+ UXTHEME_APPMODE_DEFAULT,
+ UXTHEME_APPMODE_ALLOW_DARK,
+ UXTHEME_APPMODE_FORCE_DARK,
+ UXTHEME_APPMODE_FORCE_LIGHT,
+ UXTHEME_APPMODE_MAX
+} UxthemePreferredAppMode;
+
+typedef enum {
+ WCA_UNDEFINED = 0,
+ WCA_USEDARKMODECOLORS = 26,
+ WCA_LAST = 27
+} WINDOWCOMPOSITIONATTRIB;
+
+typedef struct {
+ WINDOWCOMPOSITIONATTRIB Attrib;
+ PVOID pvData;
+ SIZE_T cbData;
+} WINDOWCOMPOSITIONATTRIBDATA;
+
+typedef struct {
+ ULONG dwOSVersionInfoSize;
+ ULONG dwMajorVersion;
+ ULONG dwMinorVersion;
+ ULONG dwBuildNumber;
+ ULONG dwPlatformId;
+ WCHAR szCSDVersion[128];
+} NT_OSVERSIONINFOW;
+
+typedef bool (WINAPI *ShouldAppsUseDarkMode_t)(void);
+typedef void (WINAPI *AllowDarkModeForWindow_t)(HWND, bool);
+typedef void (WINAPI *AllowDarkModeForApp_t)(bool);
+typedef void (WINAPI *RefreshImmersiveColorPolicyState_t)(void);
+typedef UxthemePreferredAppMode (WINAPI *SetPreferredAppMode_t)(UxthemePreferredAppMode);
+typedef BOOL (WINAPI *SetWindowCompositionAttribute_t)(HWND, const WINDOWCOMPOSITIONATTRIBDATA *);
+typedef void (NTAPI *RtlGetVersion_t)(NT_OSVERSIONINFOW *);
+
// Fake window to help with DirectInput events.
HWND SDL_HelperWindow = NULL;
static const TCHAR *SDL_HelperWindowClassName = TEXT("SDLHelperWindowInputCatcher");
@@ -254,6 +286,36 @@ static BOOL IsWindowsVersionOrGreater(WORD wMajorVersion, WORD wMinorVersion, WO
return VerifyVersionInfoW(&osvi, VER_MAJORVERSION | VER_MINORVERSION | VER_SERVICEPACKMAJOR, dwlConditionMask) != FALSE;
}
+
+static DWORD WIN_BuildNumber = 0;
+static BOOL IsWindowsBuildVersionAtLeast(DWORD dwBuildNumber)
+{
+ if (WIN_BuildNumber != 0) {
+ return (WIN_BuildNumber >= dwBuildNumber);
+ }
+
+ HMODULE ntdll = LoadLibrary(TEXT("ntdll.dll"));
+ if (!ntdll) {
+ return false;
+ }
+ // There is no function to get Windows build number, so let's get it here via RtlGetVersion
+ RtlGetVersion_t RtlGetVersionFunc = (RtlGetVersion_t)GetProcAddress(ntdll, "RtlGetVersion");
+ NT_OSVERSIONINFOW os_info;
+ os_info.dwOSVersionInfoSize = sizeof(NT_OSVERSIONINFOW);
+ os_info.dwBuildNumber = 0;
+ if (RtlGetVersionFunc) {
+ RtlGetVersionFunc(&os_info);
+ }
+ FreeLibrary(ntdll);
+
+ WIN_BuildNumber = (os_info.dwBuildNumber & ~0xF0000000);
+ return (WIN_BuildNumber >= dwBuildNumber);
+}
+#else
+static BOOL IsWindowsBuildVersionAtLeast(DWORD dwBuildNumber)
+{
+ return TRUE;
+}
#endif
// apply some static variables so we only call into the Win32 API once per process for each check.
@@ -312,6 +374,16 @@ BOOL WIN_IsWindows8OrGreater(void)
CHECKWINVER(TRUE, IsWindowsVersionOrGreater(HIBYTE(_WIN32_WINNT_WIN8), LOBYTE(_WIN32_WINNT_WIN8), 0));
}
+BOOL WIN_IsWindows81OrGreater(void)
+{
+ CHECKWINVER(TRUE, IsWindowsVersionOrGreater(HIBYTE(_WIN32_WINNT_WINBLUE), LOBYTE(_WIN32_WINNT_WINBLUE), 0));
+}
+
+BOOL WIN_IsWindows11OrGreater(void)
+{
+ return IsWindowsBuildVersionAtLeast(22000);
+}
+
#undef CHECKWINVER
@@ -351,7 +423,7 @@ char *WIN_LookupAudioDeviceName(const WCHAR *name, const GUID *guid)
char *result = NULL;
if (WIN_IsEqualGUID(guid, &nullguid)) {
- return WIN_StringToUTF8(name); // No GUID, go with what we've got.
+ return WIN_StringToUTF8W(name); // No GUID, go with what we've got.
}
ptr = (const unsigned char *)guid;
@@ -360,37 +432,37 @@ char *WIN_LookupAudioDeviceName(const WCHAR *name, const GUID *guid)
ptr[3], ptr[2], ptr[1], ptr[0], ptr[5], ptr[4], ptr[7], ptr[6],
ptr[8], ptr[9], ptr[10], ptr[11], ptr[12], ptr[13], ptr[14], ptr[15]);
- strw = WIN_UTF8ToString(keystr);
+ strw = WIN_UTF8ToStringW(keystr);
rc = (RegOpenKeyExW(HKEY_LOCAL_MACHINE, strw, 0, KEY_QUERY_VALUE, &hkey) == ERROR_SUCCESS);
SDL_free(strw);
if (!rc) {
- return WIN_StringToUTF8(name); // oh well.
+ return WIN_StringToUTF8W(name); // oh well.
}
rc = (RegQueryValueExW(hkey, L"Name", NULL, NULL, NULL, &len) == ERROR_SUCCESS);
if (!rc) {
RegCloseKey(hkey);
- return WIN_StringToUTF8(name); // oh well.
+ return WIN_StringToUTF8W(name); // oh well.
}
strw = (WCHAR *)SDL_malloc(len + sizeof(WCHAR));
if (!strw) {
RegCloseKey(hkey);
- return WIN_StringToUTF8(name); // oh well.
+ return WIN_StringToUTF8W(name); // oh well.
}
rc = (RegQueryValueExW(hkey, L"Name", NULL, NULL, (LPBYTE)strw, &len) == ERROR_SUCCESS);
RegCloseKey(hkey);
if (!rc) {
SDL_free(strw);
- return WIN_StringToUTF8(name); // oh well.
+ return WIN_StringToUTF8W(name); // oh well.
}
strw[len / 2] = 0; // make sure it's null-terminated.
- result = WIN_StringToUTF8(strw);
+ result = WIN_StringToUTF8W(strw);
SDL_free(strw);
- return result ? result : WIN_StringToUTF8(name);
+ return result ? result : WIN_StringToUTF8W(name);
#endif
}
@@ -426,6 +498,134 @@ bool WIN_WindowRectValid(const RECT *rect)
return (rect->right > 0);
}
+void WIN_UpdateDarkModeForHWND(HWND hwnd)
+{
+#if !defined(SDL_PLATFORM_XBOXONE) && !defined(SDL_PLATFORM_XBOXSERIES)
+ if (!IsWindowsBuildVersionAtLeast(17763)) {
+ // Too old to support dark mode
+ return;
+ }
+ HMODULE uxtheme = LoadLibrary(TEXT("uxtheme.dll"));
+ if (!uxtheme) {
+ return;
+ }
+ RefreshImmersiveColorPolicyState_t RefreshImmersiveColorPolicyStateFunc = (RefreshImmersiveColorPolicyState_t)GetProcAddress(uxtheme, MAKEINTRESOURCEA(104));
+ ShouldAppsUseDarkMode_t ShouldAppsUseDarkModeFunc = (ShouldAppsUseDarkMode_t)GetProcAddress(uxtheme, MAKEINTRESOURCEA(132));
+ AllowDarkModeForWindow_t AllowDarkModeForWindowFunc = (AllowDarkModeForWindow_t)GetProcAddress(uxtheme, MAKEINTRESOURCEA(133));
+ if (!IsWindowsBuildVersionAtLeast(18362)) {
+ AllowDarkModeForApp_t AllowDarkModeForAppFunc = (AllowDarkModeForApp_t)GetProcAddress(uxtheme, MAKEINTRESOURCEA(135));
+ if (AllowDarkModeForAppFunc) {
+ AllowDarkModeForAppFunc(true);
+ }
+ } else {
+ SetPreferredAppMode_t SetPreferredAppModeFunc = (SetPreferredAppMode_t)GetProcAddress(uxtheme, MAKEINTRESOURCEA(135));
+ if (SetPreferredAppModeFunc) {
+ SetPreferredAppModeFunc(UXTHEME_APPMODE_ALLOW_DARK);
+ }
+ }
+ if (RefreshImmersiveColorPolicyStateFunc) {
+ RefreshImmersiveColorPolicyStateFunc();
+ }
+ if (AllowDarkModeForWindowFunc) {
+ AllowDarkModeForWindowFunc(hwnd, true);
+ }
+ BOOL value;
+ // Check dark mode using ShouldAppsUseDarkMode, but use SDL_GetSystemTheme as a fallback
+ if (ShouldAppsUseDarkModeFunc) {
+ value = ShouldAppsUseDarkModeFunc() ? TRUE : FALSE;
+ } else {
+ // value = (SDL_GetSystemTheme() == SDL_SYSTEM_THEME_DARK) ? TRUE : FALSE;
+ }
+ FreeLibrary(uxtheme);
+ if (!IsWindowsBuildVersionAtLeast(18362)) {
+ SetProp(hwnd, TEXT("UseImmersiveDarkModeColors"), SDL_reinterpret_cast(HANDLE, SDL_static_cast(INT_PTR, value)));
+ } else {
+ HMODULE user32 = GetModuleHandle(TEXT("user32.dll"));
+ if (user32) {
+ SetWindowCompositionAttribute_t SetWindowCompositionAttributeFunc = (SetWindowCompositionAttribute_t)GetProcAddress(user32, "SetWindowCompositionAttribute");
+ if (SetWindowCompositionAttributeFunc) {
+ WINDOWCOMPOSITIONATTRIBDATA data = { WCA_USEDARKMODECOLORS, &value, sizeof(value) };
+ SetWindowCompositionAttributeFunc(hwnd, &data);
+ }
+ }
+ }
+#endif
+}
+
+// HICON WIN_CreateIconFromSurface(SDL_Surface *surface)
+// {
+// #if !(defined(SDL_PLATFORM_XBOXONE) || defined(SDL_PLATFORM_XBOXSERIES))
+// SDL_Surface *s = SDL_ConvertSurface(surface, SDL_PIXELFORMAT_ARGB8888);
+// if (!s) {
+// return NULL;
+// }
+
+// /* The dimensions will be needed after s is freed */
+// const int width = s->w;
+// const int height = s->h;
+
+// BITMAPINFO bmpInfo;
+// SDL_zero(bmpInfo);
+// bmpInfo.bmiHeader.biSize = sizeof(BITMAPINFOHEADER);
+// bmpInfo.bmiHeader.biWidth = width;
+// bmpInfo.bmiHeader.biHeight = -height; /* Top-down bitmap */
+// bmpInfo.bmiHeader.biPlanes = 1;
+// bmpInfo.bmiHeader.biBitCount = 32;
+// bmpInfo.bmiHeader.biCompression = BI_RGB;
+
+// HDC hdc = GetDC(NULL);
+// void *pBits = NULL;
+// HBITMAP hBitmap = CreateDIBSection(hdc, &bmpInfo, DIB_RGB_COLORS, &pBits, NULL, 0);
+// if (!hBitmap) {
+// ReleaseDC(NULL, hdc);
+// SDL_DestroySurface(s);
+// return NULL;
+// }
+
+// SDL_memcpy(pBits, s->pixels, width * height * 4);
+
+// SDL_DestroySurface(s);
+
+// HBITMAP hMask = CreateBitmap(width, height, 1, 1, NULL);
+// if (!hMask) {
+// DeleteObject(hBitmap);
+// ReleaseDC(NULL, hdc);
+// return NULL;
+// }
+
+// HDC hdcMem = CreateCompatibleDC(hdc);
+// HGDIOBJ oldBitmap = SelectObject(hdcMem, hMask);
+
+// for (int y = 0; y < height; y++) {
+// for (int x = 0; x < width; x++) {
+// BYTE* pixel = (BYTE*)pBits + (y * width + x) * 4;
+// BYTE alpha = pixel[3];
+// COLORREF maskColor = (alpha == 0) ? RGB(255, 255, 255) : RGB(0, 0, 0);
+// SetPixel(hdcMem, x, y, maskColor);
+// }
+// }
+
+// ICONINFO iconInfo;
+// iconInfo.fIcon = TRUE;
+// iconInfo.xHotspot = 0;
+// iconInfo.yHotspot = 0;
+// iconInfo.hbmMask = hMask;
+// iconInfo.hbmColor = hBitmap;
+
+// HICON hIcon = CreateIconIndirect(&iconInfo);
+
+// SelectObject(hdcMem, oldBitmap);
+// DeleteDC(hdcMem);
+// DeleteObject(hBitmap);
+// DeleteObject(hMask);
+// ReleaseDC(NULL, hdc);
+
+// return hIcon;
+// #else
+// return NULL;
+// #endif
+// }
+
// Some GUIDs we need to know without linking to libraries that aren't available before Vista.
/* *INDENT-OFF* */ // clang-format off
static const GUID SDL_KSDATAFORMAT_SUBTYPE_PCM = { 0x00000001, 0x0000, 0x0010,{ 0x80, 0x00, 0x00, 0xaa, 0x00, 0x38, 0x9b, 0x71 } };
@@ -462,4 +662,110 @@ int WIN_WideCharToMultiByte(UINT CodePage, DWORD dwFlags, LPCWCH lpWideCharStr,
return WideCharToMultiByte(CodePage, dwFlags, lpWideCharStr, cchWideChar, lpMultiByteStr, cbMultiByte, lpDefaultChar, lpUsedDefaultChar);
}
+const char *WIN_CheckDefaultArgcArgv(int *pargc, char ***pargv, void **pallocated)
+{
+ // If the provided argv is valid, we pass it to the main function as-is, since it's probably what the user wants.
+ // Otherwise, we take a NULL argv as an instruction for SDL to parse the command line into an argv.
+ // On Windows, when SDL provides the main entry point, argv is always NULL.
+
+ const char *out_of_mem_str = "Out of memory - aborting";
+ const char *proc_err_str = "Error processing command line arguments - aborting";
+
+ *pallocated = NULL;
+
+ if (*pargv) {
+ return NULL; // just go with what was provided, no error message.
+ }
+
+ // We need to be careful about how we allocate/free memory here. We can't use SDL_alloc()/SDL_free()
+ // because the application might have used SDL_SetMemoryFunctions() to change the allocator.
+ LPWSTR *argvw = NULL;
+ char **argv = NULL;
+
+ const LPWSTR command_line = GetCommandLineW();
+
+ // Because of how the Windows command line is structured, we know for sure that the buffer size required to
+ // store all argument strings converted to UTF-8 (with null terminators) is guaranteed to be less than or equal
+ // to the size of the original command line string converted to UTF-8.
+ const int argdata_size = WideCharToMultiByte(CP_UTF8, 0, command_line, -1, NULL, 0, NULL, NULL); // Includes the null terminator
+ if (!argdata_size) {
+ return proc_err_str;
+ }
+
+ int argc = -1;
+ argvw = CommandLineToArgvW(command_line, &argc);
+ if (!argvw || argc < 0) {
+ return out_of_mem_str;
+ }
+
+ // Allocate argv followed by the argument string buffer as one contiguous allocation.
+ argv = (char **)HeapAlloc(GetProcessHeap(), HEAP_ZERO_MEMORY, (argc + 1) * sizeof(*argv) + argdata_size);
+ if (!argv) {
+ LocalFree(argvw);
+ return out_of_mem_str;
+ }
+
+ char *argdata = ((char *)argv) + (argc + 1) * sizeof(*argv);
+ int argdata_index = 0;
+
+ for (int i = 0; i < argc; ++i) {
+ const int bytes_written = WideCharToMultiByte(CP_UTF8, 0, argvw[i], -1, argdata + argdata_index, argdata_size - argdata_index, NULL, NULL);
+ if (!bytes_written) {
+ HeapFree(GetProcessHeap(), 0, argv);
+ LocalFree(argvw);
+ return proc_err_str;
+ }
+ argv[i] = argdata + argdata_index;
+ argdata_index += bytes_written;
+ }
+
+ argv[argc] = NULL;
+
+ LocalFree(argvw);
+
+ *pargc = argc;
+ *pallocated = argv;
+ *pargv = argv;
+
+ return NULL; // no error string.
+}
+
+char *WIN_GetModulePath(HMODULE handle)
+{
+ DWORD buflen = 128;
+ WCHAR *path = NULL;
+ DWORD len = 0;
+
+ while (true) {
+ void *ptr = SDL_realloc(path, buflen * sizeof(WCHAR));
+ if (!ptr) {
+ SDL_free(path);
+ return NULL;
+ }
+
+ path = (WCHAR *)ptr;
+
+ len = GetModuleFileNameW(handle, path, buflen);
+ // if it truncated, then len >= buflen - 1
+ // if there was enough room (or failure), len < buflen - 1
+ if (len < (buflen - 1)) {
+ break;
+ }
+
+ // buffer too small? Try again.
+ buflen *= 2;
+ }
+
+ char *retval = NULL;
+ if (len == 0) {
+ WIN_SetError("Couldn't locate module");
+ } else {
+ retval = WIN_StringToUTF8W(path);
+ }
+
+ SDL_free(path);
+
+ return retval;
+}
+
#endif // defined(SDL_PLATFORM_WINDOWS)
diff --git a/thirdparty/sdl/core/windows/SDL_windows.h b/thirdparty/sdl/core/windows/SDL_windows.h
index fa405ade1a5..54f3f2c96c7 100644
--- a/thirdparty/sdl/core/windows/SDL_windows.h
+++ b/thirdparty/sdl/core/windows/SDL_windows.h
@@ -1,6 +1,6 @@
/*
Simple DirectMedia Layer
- Copyright (C) 1997-2025 Sam Lantinga <[email protected]>
+ Copyright (C) 1997-2026 Sam Lantinga <[email protected]>
This software is provided 'as-is', without any express or implied
warranty. In no event will the authors be held liable for any damages
@@ -21,10 +21,39 @@
// This is an include file for windows.h with the SDL build settings
-#ifndef _INCLUDED_WINDOWS_H
-#define _INCLUDED_WINDOWS_H
+#ifndef SDL_windows_h_
+#define SDL_windows_h_
#ifdef SDL_PLATFORM_WIN32
+
+#ifndef _WIN32_WINNT_NT4
+#define _WIN32_WINNT_NT4 0x0400
+#endif
+#ifndef _WIN32_WINNT_WIN2K
+#define _WIN32_WINNT_WIN2K 0x0500
+#endif
+#ifndef _WIN32_WINNT_WINXP
+#define _WIN32_WINNT_WINXP 0x0501
+#endif
+#ifndef _WIN32_WINNT_WS03
+#define _WIN32_WINNT_WS03 0x0502
+#endif
+#ifndef _WIN32_WINNT_VISTA
+#define _WIN32_WINNT_VISTA 0x0600
+#endif
+#ifndef _WIN32_WINNT_WIN7
+#define _WIN32_WINNT_WIN7 0x0601
+#endif
+#ifndef _WIN32_WINNT_WIN8
+#define _WIN32_WINNT_WIN8 0x0602
+#endif
+#ifndef _WIN32_WINNT_WINBLUE
+#define _WIN32_WINNT_WINBLUE 0x0603
+#endif
+#ifndef _WIN32_WINNT_WIN10
+#define _WIN32_WINNT_WIN10 0x0A00
+#endif
+
#ifndef WIN32_LEAN_AND_MEAN
#define WIN32_LEAN_AND_MEAN 1
#endif
@@ -37,11 +66,17 @@
#undef WINVER
#undef _WIN32_WINNT
#if defined(SDL_VIDEO_RENDER_D3D12) || defined(HAVE_DXGI1_6_H)
-#define _WIN32_WINNT 0xA00 // For D3D12, 0xA00 is required
+#define _WIN32_WINNT _WIN32_WINNT_WIN10 // For D3D12, 0xA00 is required
#elif defined(HAVE_SHELLSCALINGAPI_H)
-#define _WIN32_WINNT 0x603 // For DPI support
+#define _WIN32_WINNT _WIN32_WINNT_WINBLUE // For DPI support
+#elif defined(HAVE_ROAPI_H)
+#define _WIN32_WINNT _WIN32_WINNT_WIN8
+#elif defined(HAVE_SENSORSAPI_H)
+#define _WIN32_WINNT _WIN32_WINNT_WIN7
+#elif defined(HAVE_MMDEVICEAPI_H)
+#define _WIN32_WINNT _WIN32_WINNT_VISTA
#else
-#define _WIN32_WINNT 0x501 // Need 0x410 for AlphaBlend() and 0x500 for EnumDisplayDevices(), 0x501 for raw input
+#define _WIN32_WINNT _WIN32_WINNT_WINXP // Need 0x410 for AlphaBlend() and 0x500 for EnumDisplayDevices(), 0x501 for raw input
#endif
#define WINVER _WIN32_WINNT
@@ -148,6 +183,12 @@ extern BOOL WIN_IsWindows7OrGreater(void);
// Returns true if we're running on Windows 8 and newer
extern BOOL WIN_IsWindows8OrGreater(void);
+// Returns true if we're running on Windows 8.1 and newer
+extern BOOL WIN_IsWindows81OrGreater(void);
+
+// Returns true if we're running on Windows 11 and newer
+extern BOOL WIN_IsWindows11OrGreater(void);
+
// You need to SDL_free() the result of this call.
extern char *WIN_LookupAudioDeviceName(const WCHAR *name, const GUID *guid);
@@ -160,16 +201,26 @@ extern void WIN_RECTToRect(const RECT *winrect, SDL_Rect *sdlrect);
extern void WIN_RectToRECT(const SDL_Rect *sdlrect, RECT *winrect);
// Returns false if a window client rect is not valid
-bool WIN_WindowRectValid(const RECT *rect);
+extern bool WIN_WindowRectValid(const RECT *rect);
+
+extern void WIN_UpdateDarkModeForHWND(HWND hwnd);
+
+extern HICON WIN_CreateIconFromSurface(SDL_Surface *surface);
extern SDL_AudioFormat SDL_WaveFormatExToSDLFormat(WAVEFORMATEX *waveformat);
// WideCharToMultiByte, but with some WinXP management.
extern int WIN_WideCharToMultiByte(UINT CodePage, DWORD dwFlags, LPCWCH lpWideCharStr, int cchWideChar, LPSTR lpMultiByteStr, int cbMultiByte, LPCCH lpDefaultChar, LPBOOL lpUsedDefaultChar);
+// parse out command lines from OS if argv is NULL, otherwise pass through unchanged. `*pallocated` must be HeapFree'd by caller if not NULL on successful return. Returns NULL on success, error string on problems.
+extern const char *WIN_CheckDefaultArgcArgv(int *pargc, char ***pargv, void **pallocated);
+
+// Does all the win32 tapdancing to make GetModuleFileName work. Returns a SDL_malloc'd UTF-8 string, or NULL on failure.
+extern char *WIN_GetModulePath(HMODULE handle);
+
// Ends C function definitions when using C++
#ifdef __cplusplus
}
#endif
-#endif // _INCLUDED_WINDOWS_H
+#endif // SDL_windows_h_
diff --git a/thirdparty/sdl/core/windows/SDL_xinput.c b/thirdparty/sdl/core/windows/SDL_xinput.c
index ba5e4c10786..93132dd32d3 100644
--- a/thirdparty/sdl/core/windows/SDL_xinput.c
+++ b/thirdparty/sdl/core/windows/SDL_xinput.c
@@ -1,6 +1,6 @@
/*
Simple DirectMedia Layer
- Copyright (C) 1997-2025 Sam Lantinga <[email protected]>
+ Copyright (C) 1997-2026 Sam Lantinga <[email protected]>
This software is provided 'as-is', without any express or implied
warranty. In no event will the authors be held liable for any damages
@@ -32,7 +32,6 @@ XInputSetState_t SDL_XInputSetState = NULL;
XInputGetCapabilities_t SDL_XInputGetCapabilities = NULL;
XInputGetCapabilitiesEx_t SDL_XInputGetCapabilitiesEx = NULL;
XInputGetBatteryInformation_t SDL_XInputGetBatteryInformation = NULL;
-DWORD SDL_XInputVersion = 0;
static HMODULE s_pXInputDLL = NULL;
static int s_XInputDLLRefCount = 0;
@@ -54,9 +53,6 @@ bool WIN_LoadXInputDLL(void)
SDL_XInputGetCapabilities = (XInputGetCapabilities_t)XInputGetCapabilities;
SDL_XInputGetBatteryInformation = (XInputGetBatteryInformation_t)XInputGetBatteryInformation;
- // XInput 1.4 ships with Windows 8 and 8.1:
- SDL_XInputVersion = (1 << 16) | 4;
-
return true;
}
@@ -68,8 +64,6 @@ void WIN_UnloadXInputDLL(void)
bool WIN_LoadXInputDLL(void)
{
- DWORD version = 0;
-
if (s_pXInputDLL) {
SDL_assert(s_XInputDLLRefCount > 0);
s_XInputDLLRefCount++;
@@ -80,15 +74,10 @@ bool WIN_LoadXInputDLL(void)
* This is XInput emulation over Windows.Gaming.Input, and has all the
* limitations of that API (no devices at startup, no background input, etc.)
*/
- version = (1 << 16) | 4;
s_pXInputDLL = LoadLibrary(TEXT("XInput1_4.dll")); // 1.4 Ships with Windows 8.
if (!s_pXInputDLL) {
- version = (1 << 16) | 3;
s_pXInputDLL = LoadLibrary(TEXT("XInput1_3.dll")); // 1.3 can be installed as a redistributable component.
}
- if (!s_pXInputDLL) {
- s_pXInputDLL = LoadLibrary(TEXT("bin\\XInput1_3.dll"));
- }
if (!s_pXInputDLL) {
// "9.1.0" Ships with Vista and Win7, and is more limited than 1.3+ (e.g. XInputGetStateEx is not available.)
s_pXInputDLL = LoadLibrary(TEXT("XInput9_1_0.dll"));
@@ -98,7 +87,6 @@ bool WIN_LoadXInputDLL(void)
}
SDL_assert(s_XInputDLLRefCount == 0);
- SDL_XInputVersion = version;
s_XInputDLLRefCount = 1;
// 100 is the ordinal for _XInputGetStateEx, which returns the same struct as XinputGetState, but with extra data in wButtons for the guide button, we think...
diff --git a/thirdparty/sdl/core/windows/SDL_xinput.h b/thirdparty/sdl/core/windows/SDL_xinput.h
index d499cd58c2b..aa2cf99f6f7 100644
--- a/thirdparty/sdl/core/windows/SDL_xinput.h
+++ b/thirdparty/sdl/core/windows/SDL_xinput.h
@@ -1,6 +1,6 @@
/*
Simple DirectMedia Layer
- Copyright (C) 1997-2025 Sam Lantinga <[email protected]>
+ Copyright (C) 1997-2026 Sam Lantinga <[email protected]>
This software is provided 'as-is', without any express or implied
warranty. In no event will the authors be held liable for any damages
@@ -260,7 +260,6 @@ extern XInputSetState_t SDL_XInputSetState;
extern XInputGetCapabilities_t SDL_XInputGetCapabilities;
extern XInputGetCapabilitiesEx_t SDL_XInputGetCapabilitiesEx;
extern XInputGetBatteryInformation_t SDL_XInputGetBatteryInformation;
-extern DWORD SDL_XInputVersion; // ((major << 16) & 0xFF00) | (minor & 0xFF)
// Ends C function definitions when using C++
#ifdef __cplusplus
diff --git a/thirdparty/sdl/core/windows/pch.c b/thirdparty/sdl/core/windows/pch.c
index 4b0c6f8fcc8..b2b446f54ec 100644
--- a/thirdparty/sdl/core/windows/pch.c
+++ b/thirdparty/sdl/core/windows/pch.c
@@ -1,6 +1,6 @@
/*
Simple DirectMedia Layer
- Copyright (C) 1997-2025 Sam Lantinga <[email protected]>
+ Copyright (C) 1997-2026 Sam Lantinga <[email protected]>
This software is provided 'as-is', without any express or implied
warranty. In no event will the authors be held liable for any damages
diff --git a/thirdparty/sdl/core/windows/pch_cpp.cpp b/thirdparty/sdl/core/windows/pch_cpp.cpp
index 4b0c6f8fcc8..b2b446f54ec 100644
--- a/thirdparty/sdl/core/windows/pch_cpp.cpp
+++ b/thirdparty/sdl/core/windows/pch_cpp.cpp
@@ -1,6 +1,6 @@
/*
Simple DirectMedia Layer
- Copyright (C) 1997-2025 Sam Lantinga <[email protected]>
+ Copyright (C) 1997-2026 Sam Lantinga <[email protected]>
This software is provided 'as-is', without any express or implied
warranty. In no event will the authors be held liable for any damages
diff --git a/thirdparty/sdl/events/SDL_events.c b/thirdparty/sdl/events/SDL_events.c
index 7ca683e0eb6..2b17e6c247f 100644
--- a/thirdparty/sdl/events/SDL_events.c
+++ b/thirdparty/sdl/events/SDL_events.c
@@ -1,6 +1,6 @@
/*
Simple DirectMedia Layer
- Copyright (C) 1997-2025 Sam Lantinga <[email protected]>
+ Copyright (C) 1997-2026 Sam Lantinga <[email protected]>
This software is provided 'as-is', without any express or implied
warranty. In no event will the authors be held liable for any damages
@@ -24,21 +24,32 @@
#include "SDL_events_c.h"
#include "SDL_eventwatch_c.h"
+// #include "SDL_windowevents_c.h"
#include "../SDL_hints_c.h"
+// #include "../audio/SDL_audio_c.h"
+// #include "../camera/SDL_camera_c.h"
#include "../timer/SDL_timer_c.h"
+#include "../core/linux/SDL_udev.h"
#ifndef SDL_JOYSTICK_DISABLED
#include "../joystick/SDL_joystick_c.h"
#endif
#ifndef SDL_SENSOR_DISABLED
#include "../sensor/SDL_sensor_c.h"
#endif
-//#include "../video/SDL_sysvideo.h"
+#ifdef HAVE_DBUS_DBUS_H
+#include "core/linux/SDL_dbus.h"
+#endif
+// #include "../video/SDL_sysvideo.h"
#ifdef SDL_PLATFORM_ANDROID
#include "../core/android/SDL_android.h"
#include "../video/android/SDL_androidevents.h"
#endif
+// #ifdef SDL_PLATFORM_UNIX
+// #include "../tray/SDL_tray_utils.h"
+// #endif
+
// An arbitrary limit so we don't have unbounded growth
#define SDL_MAX_QUEUED_EVENTS 65535
@@ -48,6 +59,12 @@
// Determines how often to pump events if joysticks or sensors are actively being read
#define EVENT_POLL_INTERVAL_NS SDL_MS_TO_NS(1)
+// Determines how often to pump events if tray items are active
+#define TRAY_POLL_INTERVAL_NS SDL_MS_TO_NS(50)
+
+// Determines how often to pump events if DBus is active
+#define DBUS_POLL_INTERVAL_NS (3 * SDL_NS_PER_SECOND)
+
// Make sure the type in the SDL_Event aligns properly across the union
SDL_COMPILE_TIME_ASSERT(SDL_Event_type, sizeof(Uint32) == sizeof(SDL_EventType));
@@ -427,26 +444,18 @@ static void SDLCALL SDL_EventLoggingChanged(void *userdata, const char *name, co
SDL_EventLoggingVerbosity = (hint && *hint) ? SDL_clamp(SDL_atoi(hint), 0, 3) : 0;
}
-static void SDL_LogEvent(const SDL_Event *event)
+int SDL_GetEventDescription(const SDL_Event *event, char *buf, int buflen)
{
+ if (!event) {
+ return SDL_snprintf(buf, buflen, "(null)");
+ }
+
static const char *pen_axisnames[] = { "PRESSURE", "XTILT", "YTILT", "DISTANCE", "ROTATION", "SLIDER", "TANGENTIAL_PRESSURE" };
SDL_COMPILE_TIME_ASSERT(pen_axisnames_array_matches, SDL_arraysize(pen_axisnames) == SDL_PEN_AXIS_COUNT);
char name[64];
char details[128];
- // sensor/mouse/pen/finger motion are spammy, ignore these if they aren't demanded.
- if ((SDL_EventLoggingVerbosity < 2) &&
- ((event->type == SDL_EVENT_MOUSE_MOTION) ||
- (event->type == SDL_EVENT_FINGER_MOTION) ||
- (event->type == SDL_EVENT_PEN_AXIS) ||
- (event->type == SDL_EVENT_PEN_MOTION) ||
- (event->type == SDL_EVENT_GAMEPAD_TOUCHPAD_MOTION) ||
- (event->type == SDL_EVENT_GAMEPAD_SENSOR_UPDATE) ||
- (event->type == SDL_EVENT_SENSOR_UPDATE))) {
- return;
- }
-
// this is to make (void)SDL_snprintf() calls cleaner.
#define uint unsigned int
@@ -463,8 +472,8 @@ static void SDL_LogEvent(const SDL_Event *event)
} else {
plusstr[0] = '\0';
}
- (void)SDL_snprintf(details, sizeof(details), "%s (timestamp=%u windowid=%u code=%d data1=%p data2=%p)",
- plusstr, (uint)event->user.timestamp, (uint)event->user.windowID,
+ (void)SDL_snprintf(details, sizeof(details), "%s (timestamp=%" SDL_PRIu64 " windowid=%u code=%d data1=%p data2=%p)",
+ plusstr, event->user.timestamp, (uint)event->user.windowID,
(int)event->user.code, event->user.data1, event->user.data2);
}
@@ -476,7 +485,7 @@ static void SDL_LogEvent(const SDL_Event *event)
SDL_strlcpy(details, " (THIS IS PROBABLY A BUG!)", sizeof(details));
break;
SDL_EVENT_CASE(SDL_EVENT_QUIT)
- (void)SDL_snprintf(details, sizeof(details), " (timestamp=%u)", (uint)event->quit.timestamp);
+ (void)SDL_snprintf(details, sizeof(details), " (timestamp=%" SDL_PRIu64 ")", event->quit.timestamp);
break;
SDL_EVENT_CASE(SDL_EVENT_TERMINATING)
break;
@@ -502,8 +511,8 @@ static void SDL_LogEvent(const SDL_Event *event)
#define SDL_RENDEREVENT_CASE(x) \
case x: \
SDL_strlcpy(name, #x, sizeof(name)); \
- (void)SDL_snprintf(details, sizeof(details), " (timestamp=%u event=%s windowid=%u)", \
- (uint)event->display.timestamp, name, (uint)event->render.windowID); \
+ (void)SDL_snprintf(details, sizeof(details), " (timestamp=%" SDL_PRIu64 " event=%s windowid=%u)", \
+ event->display.timestamp, name, (uint)event->render.windowID); \
break
SDL_RENDEREVENT_CASE(SDL_EVENT_RENDER_TARGETS_RESET);
SDL_RENDEREVENT_CASE(SDL_EVENT_RENDER_DEVICE_RESET);
@@ -512,8 +521,8 @@ static void SDL_LogEvent(const SDL_Event *event)
#define SDL_DISPLAYEVENT_CASE(x) \
case x: \
SDL_strlcpy(name, #x, sizeof(name)); \
- (void)SDL_snprintf(details, sizeof(details), " (timestamp=%u display=%u event=%s data1=%d, data2=%d)", \
- (uint)event->display.timestamp, (uint)event->display.displayID, name, (int)event->display.data1, (int)event->display.data2); \
+ (void)SDL_snprintf(details, sizeof(details), " (timestamp=%" SDL_PRIu64 " display=%u event=%s data1=%d, data2=%d)", \
+ event->display.timestamp, (uint)event->display.displayID, name, (int)event->display.data1, (int)event->display.data2); \
break
SDL_DISPLAYEVENT_CASE(SDL_EVENT_DISPLAY_ORIENTATION);
SDL_DISPLAYEVENT_CASE(SDL_EVENT_DISPLAY_ADDED);
@@ -522,13 +531,14 @@ static void SDL_LogEvent(const SDL_Event *event)
SDL_DISPLAYEVENT_CASE(SDL_EVENT_DISPLAY_DESKTOP_MODE_CHANGED);
SDL_DISPLAYEVENT_CASE(SDL_EVENT_DISPLAY_CURRENT_MODE_CHANGED);
SDL_DISPLAYEVENT_CASE(SDL_EVENT_DISPLAY_CONTENT_SCALE_CHANGED);
+ SDL_DISPLAYEVENT_CASE(SDL_EVENT_DISPLAY_USABLE_BOUNDS_CHANGED);
#undef SDL_DISPLAYEVENT_CASE
#define SDL_WINDOWEVENT_CASE(x) \
case x: \
SDL_strlcpy(name, #x, sizeof(name)); \
- (void)SDL_snprintf(details, sizeof(details), " (timestamp=%u windowid=%u event=%s data1=%d data2=%d)", \
- (uint)event->window.timestamp, (uint)event->window.windowID, name, (int)event->window.data1, (int)event->window.data2); \
+ (void)SDL_snprintf(details, sizeof(details), " (timestamp=%" SDL_PRIu64 " windowid=%u event=%s data1=%d data2=%d)", \
+ event->window.timestamp, (uint)event->window.windowID, name, (int)event->window.data1, (int)event->window.data2); \
break
SDL_WINDOWEVENT_CASE(SDL_EVENT_WINDOW_SHOWN);
SDL_WINDOWEVENT_CASE(SDL_EVENT_WINDOW_HIDDEN);
@@ -537,7 +547,6 @@ static void SDL_LogEvent(const SDL_Event *event)
SDL_WINDOWEVENT_CASE(SDL_EVENT_WINDOW_RESIZED);
SDL_WINDOWEVENT_CASE(SDL_EVENT_WINDOW_PIXEL_SIZE_CHANGED);
SDL_WINDOWEVENT_CASE(SDL_EVENT_WINDOW_METAL_VIEW_RESIZED);
- SDL_WINDOWEVENT_CASE(SDL_EVENT_WINDOW_SAFE_AREA_CHANGED);
SDL_WINDOWEVENT_CASE(SDL_EVENT_WINDOW_MINIMIZED);
SDL_WINDOWEVENT_CASE(SDL_EVENT_WINDOW_MAXIMIZED);
SDL_WINDOWEVENT_CASE(SDL_EVENT_WINDOW_RESTORED);
@@ -550,6 +559,7 @@ static void SDL_LogEvent(const SDL_Event *event)
SDL_WINDOWEVENT_CASE(SDL_EVENT_WINDOW_ICCPROF_CHANGED);
SDL_WINDOWEVENT_CASE(SDL_EVENT_WINDOW_DISPLAY_CHANGED);
SDL_WINDOWEVENT_CASE(SDL_EVENT_WINDOW_DISPLAY_SCALE_CHANGED);
+ SDL_WINDOWEVENT_CASE(SDL_EVENT_WINDOW_SAFE_AREA_CHANGED);
SDL_WINDOWEVENT_CASE(SDL_EVENT_WINDOW_OCCLUDED);
SDL_WINDOWEVENT_CASE(SDL_EVENT_WINDOW_ENTER_FULLSCREEN);
SDL_WINDOWEVENT_CASE(SDL_EVENT_WINDOW_LEAVE_FULLSCREEN);
@@ -557,7 +567,7 @@ static void SDL_LogEvent(const SDL_Event *event)
SDL_WINDOWEVENT_CASE(SDL_EVENT_WINDOW_HDR_STATE_CHANGED);
#undef SDL_WINDOWEVENT_CASE
-#define PRINT_KEYDEV_EVENT(event) (void)SDL_snprintf(details, sizeof(details), " (timestamp=%u which=%u)", (uint)event->kdevice.timestamp, (uint)event->kdevice.which)
+#define PRINT_KEYDEV_EVENT(event) (void)SDL_snprintf(details, sizeof(details), " (timestamp=%" SDL_PRIu64 " which=%u)", event->kdevice.timestamp, (uint)event->kdevice.which)
SDL_EVENT_CASE(SDL_EVENT_KEYBOARD_ADDED)
PRINT_KEYDEV_EVENT(event);
break;
@@ -567,8 +577,8 @@ static void SDL_LogEvent(const SDL_Event *event)
#undef PRINT_KEYDEV_EVENT
#define PRINT_KEY_EVENT(event) \
- (void)SDL_snprintf(details, sizeof(details), " (timestamp=%u windowid=%u which=%u state=%s repeat=%s scancode=%u keycode=%u mod=0x%x)", \
- (uint)event->key.timestamp, (uint)event->key.windowID, (uint)event->key.which, \
+ (void)SDL_snprintf(details, sizeof(details), " (timestamp=%" SDL_PRIu64 " windowid=%u which=%u state=%s repeat=%s scancode=%u keycode=%u mod=0x%x)", \
+ event->key.timestamp, (uint)event->key.windowID, (uint)event->key.which, \
event->key.down ? "pressed" : "released", \
event->key.repeat ? "true" : "false", \
(uint)event->key.scancode, \
@@ -583,22 +593,26 @@ static void SDL_LogEvent(const SDL_Event *event)
#undef PRINT_KEY_EVENT
SDL_EVENT_CASE(SDL_EVENT_TEXT_EDITING)
- (void)SDL_snprintf(details, sizeof(details), " (timestamp=%u windowid=%u text='%s' start=%d length=%d)",
- (uint)event->edit.timestamp, (uint)event->edit.windowID,
+ (void)SDL_snprintf(details, sizeof(details), " (timestamp=%" SDL_PRIu64 " windowid=%u text='%s' start=%d length=%d)",
+ event->edit.timestamp, (uint)event->edit.windowID,
event->edit.text, (int)event->edit.start, (int)event->edit.length);
break;
SDL_EVENT_CASE(SDL_EVENT_TEXT_EDITING_CANDIDATES)
- (void)SDL_snprintf(details, sizeof(details), " (timestamp=%u windowid=%u num_candidates=%d selected_candidate=%d)",
- (uint)event->edit_candidates.timestamp, (uint)event->edit_candidates.windowID,
+ (void)SDL_snprintf(details, sizeof(details), " (timestamp=%" SDL_PRIu64 " windowid=%u num_candidates=%d selected_candidate=%d)",
+ event->edit_candidates.timestamp, (uint)event->edit_candidates.windowID,
(int)event->edit_candidates.num_candidates, (int)event->edit_candidates.selected_candidate);
break;
SDL_EVENT_CASE(SDL_EVENT_TEXT_INPUT)
- (void)SDL_snprintf(details, sizeof(details), " (timestamp=%u windowid=%u text='%s')", (uint)event->text.timestamp, (uint)event->text.windowID, event->text.text);
+ (void)SDL_snprintf(details, sizeof(details), " (timestamp=%" SDL_PRIu64 " windowid=%u text='%s')", event->text.timestamp, (uint)event->text.windowID, event->text.text);
+ break;
+ SDL_EVENT_CASE(SDL_EVENT_SCREEN_KEYBOARD_SHOWN)
+ break;
+ SDL_EVENT_CASE(SDL_EVENT_SCREEN_KEYBOARD_HIDDEN)
break;
-#define PRINT_MOUSEDEV_EVENT(event) (void)SDL_snprintf(details, sizeof(details), " (timestamp=%u which=%u)", (uint)event->mdevice.timestamp, (uint)event->mdevice.which)
+#define PRINT_MOUSEDEV_EVENT(event) (void)SDL_snprintf(details, sizeof(details), " (timestamp=%" SDL_PRIu64 " which=%u)", event->mdevice.timestamp, (uint)event->mdevice.which)
SDL_EVENT_CASE(SDL_EVENT_MOUSE_ADDED)
PRINT_MOUSEDEV_EVENT(event);
break;
@@ -608,16 +622,16 @@ static void SDL_LogEvent(const SDL_Event *event)
#undef PRINT_MOUSEDEV_EVENT
SDL_EVENT_CASE(SDL_EVENT_MOUSE_MOTION)
- (void)SDL_snprintf(details, sizeof(details), " (timestamp=%u windowid=%u which=%u state=%u x=%g y=%g xrel=%g yrel=%g)",
- (uint)event->motion.timestamp, (uint)event->motion.windowID,
+ (void)SDL_snprintf(details, sizeof(details), " (timestamp=%" SDL_PRIu64 " windowid=%u which=%u state=%u x=%g y=%g xrel=%g yrel=%g)",
+ event->motion.timestamp, (uint)event->motion.windowID,
(uint)event->motion.which, (uint)event->motion.state,
event->motion.x, event->motion.y,
event->motion.xrel, event->motion.yrel);
break;
#define PRINT_MBUTTON_EVENT(event) \
- (void)SDL_snprintf(details, sizeof(details), " (timestamp=%u windowid=%u which=%u button=%u state=%s clicks=%u x=%g y=%g)", \
- (uint)event->button.timestamp, (uint)event->button.windowID, \
+ (void)SDL_snprintf(details, sizeof(details), " (timestamp=%" SDL_PRIu64 " windowid=%u which=%u button=%u state=%s clicks=%u x=%g y=%g)", \
+ event->button.timestamp, (uint)event->button.windowID, \
(uint)event->button.which, (uint)event->button.button, \
event->button.down ? "pressed" : "released", \
(uint)event->button.clicks, event->button.x, event->button.y)
@@ -630,34 +644,34 @@ static void SDL_LogEvent(const SDL_Event *event)
#undef PRINT_MBUTTON_EVENT
SDL_EVENT_CASE(SDL_EVENT_MOUSE_WHEEL)
- (void)SDL_snprintf(details, sizeof(details), " (timestamp=%u windowid=%u which=%u x=%g y=%g integer_x=%d integer_y=%d direction=%s)",
- (uint)event->wheel.timestamp, (uint)event->wheel.windowID,
+ (void)SDL_snprintf(details, sizeof(details), " (timestamp=%" SDL_PRIu64 " windowid=%u which=%u x=%g y=%g integer_x=%d integer_y=%d direction=%s)",
+ event->wheel.timestamp, (uint)event->wheel.windowID,
(uint)event->wheel.which, event->wheel.x, event->wheel.y,
(int)event->wheel.integer_x, (int)event->wheel.integer_y,
event->wheel.direction == SDL_MOUSEWHEEL_NORMAL ? "normal" : "flipped");
break;
SDL_EVENT_CASE(SDL_EVENT_JOYSTICK_AXIS_MOTION)
- (void)SDL_snprintf(details, sizeof(details), " (timestamp=%u which=%d axis=%u value=%d)",
- (uint)event->jaxis.timestamp, (int)event->jaxis.which,
+ (void)SDL_snprintf(details, sizeof(details), " (timestamp=%" SDL_PRIu64 " which=%d axis=%u value=%d)",
+ event->jaxis.timestamp, (int)event->jaxis.which,
(uint)event->jaxis.axis, (int)event->jaxis.value);
break;
SDL_EVENT_CASE(SDL_EVENT_JOYSTICK_BALL_MOTION)
- (void)SDL_snprintf(details, sizeof(details), " (timestamp=%u which=%d ball=%u xrel=%d yrel=%d)",
- (uint)event->jball.timestamp, (int)event->jball.which,
+ (void)SDL_snprintf(details, sizeof(details), " (timestamp=%" SDL_PRIu64 " which=%d ball=%u xrel=%d yrel=%d)",
+ event->jball.timestamp, (int)event->jball.which,
(uint)event->jball.ball, (int)event->jball.xrel, (int)event->jball.yrel);
break;
SDL_EVENT_CASE(SDL_EVENT_JOYSTICK_HAT_MOTION)
- (void)SDL_snprintf(details, sizeof(details), " (timestamp=%u which=%d hat=%u value=%u)",
- (uint)event->jhat.timestamp, (int)event->jhat.which,
+ (void)SDL_snprintf(details, sizeof(details), " (timestamp=%" SDL_PRIu64 " which=%d hat=%u value=%u)",
+ event->jhat.timestamp, (int)event->jhat.which,
(uint)event->jhat.hat, (uint)event->jhat.value);
break;
#define PRINT_JBUTTON_EVENT(event) \
- (void)SDL_snprintf(details, sizeof(details), " (timestamp=%u which=%d button=%u state=%s)", \
- (uint)event->jbutton.timestamp, (int)event->jbutton.which, \
+ (void)SDL_snprintf(details, sizeof(details), " (timestamp=%" SDL_PRIu64 " which=%d button=%u state=%s)", \
+ event->jbutton.timestamp, (int)event->jbutton.which, \
(uint)event->jbutton.button, event->jbutton.down ? "pressed" : "released")
SDL_EVENT_CASE(SDL_EVENT_JOYSTICK_BUTTON_DOWN)
PRINT_JBUTTON_EVENT(event);
@@ -668,12 +682,12 @@ static void SDL_LogEvent(const SDL_Event *event)
#undef PRINT_JBUTTON_EVENT
SDL_EVENT_CASE(SDL_EVENT_JOYSTICK_BATTERY_UPDATED)
- (void)SDL_snprintf(details, sizeof(details), " (timestamp=%u which=%d state=%u percent=%d)",
- (uint)event->jbattery.timestamp, (int)event->jbattery.which,
+ (void)SDL_snprintf(details, sizeof(details), " (timestamp=%" SDL_PRIu64 " which=%d state=%u percent=%d)",
+ event->jbattery.timestamp, (int)event->jbattery.which,
event->jbattery.state, event->jbattery.percent);
break;
-#define PRINT_JOYDEV_EVENT(event) (void)SDL_snprintf(details, sizeof(details), " (timestamp=%u which=%d)", (uint)event->jdevice.timestamp, (int)event->jdevice.which)
+#define PRINT_JOYDEV_EVENT(event) (void)SDL_snprintf(details, sizeof(details), " (timestamp=%" SDL_PRIu64 " which=%d)", event->jdevice.timestamp, (int)event->jdevice.which)
SDL_EVENT_CASE(SDL_EVENT_JOYSTICK_ADDED)
PRINT_JOYDEV_EVENT(event);
break;
@@ -686,14 +700,14 @@ static void SDL_LogEvent(const SDL_Event *event)
#undef PRINT_JOYDEV_EVENT
SDL_EVENT_CASE(SDL_EVENT_GAMEPAD_AXIS_MOTION)
- (void)SDL_snprintf(details, sizeof(details), " (timestamp=%u which=%d axis=%u value=%d)",
- (uint)event->gaxis.timestamp, (int)event->gaxis.which,
+ (void)SDL_snprintf(details, sizeof(details), " (timestamp=%" SDL_PRIu64 " which=%d axis=%u value=%d)",
+ event->gaxis.timestamp, (int)event->gaxis.which,
(uint)event->gaxis.axis, (int)event->gaxis.value);
break;
#define PRINT_CBUTTON_EVENT(event) \
- (void)SDL_snprintf(details, sizeof(details), " (timestamp=%u which=%d button=%u state=%s)", \
- (uint)event->gbutton.timestamp, (int)event->gbutton.which, \
+ (void)SDL_snprintf(details, sizeof(details), " (timestamp=%" SDL_PRIu64 " which=%d button=%u state=%s)", \
+ event->gbutton.timestamp, (int)event->gbutton.which, \
(uint)event->gbutton.button, event->gbutton.down ? "pressed" : "released")
SDL_EVENT_CASE(SDL_EVENT_GAMEPAD_BUTTON_DOWN)
PRINT_CBUTTON_EVENT(event);
@@ -703,7 +717,7 @@ static void SDL_LogEvent(const SDL_Event *event)
break;
#undef PRINT_CBUTTON_EVENT
-#define PRINT_GAMEPADDEV_EVENT(event) (void)SDL_snprintf(details, sizeof(details), " (timestamp=%u which=%d)", (uint)event->gdevice.timestamp, (int)event->gdevice.which)
+#define PRINT_GAMEPADDEV_EVENT(event) (void)SDL_snprintf(details, sizeof(details), " (timestamp=%" SDL_PRIu64 " which=%d)", event->gdevice.timestamp, (int)event->gdevice.which)
SDL_EVENT_CASE(SDL_EVENT_GAMEPAD_ADDED)
PRINT_GAMEPADDEV_EVENT(event);
break;
@@ -722,8 +736,8 @@ static void SDL_LogEvent(const SDL_Event *event)
#undef PRINT_GAMEPADDEV_EVENT
#define PRINT_CTOUCHPAD_EVENT(event) \
- (void)SDL_snprintf(details, sizeof(details), " (timestamp=%u which=%d touchpad=%d finger=%d x=%f y=%f pressure=%f)", \
- (uint)event->gtouchpad.timestamp, (int)event->gtouchpad.which, \
+ (void)SDL_snprintf(details, sizeof(details), " (timestamp=%" SDL_PRIu64 " which=%d touchpad=%d finger=%d x=%f y=%f pressure=%f)", \
+ event->gtouchpad.timestamp, (int)event->gtouchpad.which, \
(int)event->gtouchpad.touchpad, (int)event->gtouchpad.finger, \
event->gtouchpad.x, event->gtouchpad.y, event->gtouchpad.pressure)
SDL_EVENT_CASE(SDL_EVENT_GAMEPAD_TOUCHPAD_DOWN)
@@ -738,14 +752,14 @@ static void SDL_LogEvent(const SDL_Event *event)
#undef PRINT_CTOUCHPAD_EVENT
SDL_EVENT_CASE(SDL_EVENT_GAMEPAD_SENSOR_UPDATE)
- (void)SDL_snprintf(details, sizeof(details), " (timestamp=%u which=%d sensor=%d data[0]=%f data[1]=%f data[2]=%f)",
- (uint)event->gsensor.timestamp, (int)event->gsensor.which, (int)event->gsensor.sensor,
+ (void)SDL_snprintf(details, sizeof(details), " (timestamp=%" SDL_PRIu64 " which=%d sensor=%d data[0]=%f data[1]=%f data[2]=%f)",
+ event->gsensor.timestamp, (int)event->gsensor.which, (int)event->gsensor.sensor,
event->gsensor.data[0], event->gsensor.data[1], event->gsensor.data[2]);
break;
#define PRINT_FINGER_EVENT(event) \
- (void)SDL_snprintf(details, sizeof(details), " (timestamp=%u touchid=%" SDL_PRIu64 " fingerid=%" SDL_PRIu64 " x=%f y=%f dx=%f dy=%f pressure=%f)", \
- (uint)event->tfinger.timestamp, event->tfinger.touchID, \
+ (void)SDL_snprintf(details, sizeof(details), " (timestamp=%" SDL_PRIu64 " touchid=%" SDL_PRIu64 " fingerid=%" SDL_PRIu64 " x=%f y=%f dx=%f dy=%f pressure=%f)", \
+ event->tfinger.timestamp, event->tfinger.touchID, \
event->tfinger.fingerID, event->tfinger.x, event->tfinger.y, \
event->tfinger.dx, event->tfinger.dy, event->tfinger.pressure)
SDL_EVENT_CASE(SDL_EVENT_FINGER_DOWN)
@@ -762,9 +776,23 @@ static void SDL_LogEvent(const SDL_Event *event)
break;
#undef PRINT_FINGER_EVENT
+#define PRINT_PINCH_EVENT(event) \
+ (void)SDL_snprintf(details, sizeof(details), " (timestamp=%" SDL_PRIu64 " scale=%f)", \
+ event->pinch.timestamp, event->pinch.scale)
+ SDL_EVENT_CASE(SDL_EVENT_PINCH_BEGIN)
+ PRINT_PINCH_EVENT(event);
+ break;
+ SDL_EVENT_CASE(SDL_EVENT_PINCH_UPDATE)
+ PRINT_PINCH_EVENT(event);
+ break;
+ SDL_EVENT_CASE(SDL_EVENT_PINCH_END)
+ PRINT_PINCH_EVENT(event);
+ break;
+#undef PRINT_PINCH_EVENT
+
#define PRINT_PTOUCH_EVENT(event) \
- (void)SDL_snprintf(details, sizeof(details), " (timestamp=%u windowid=%u which=%u pen_state=%u x=%g y=%g eraser=%s state=%s)", \
- (uint)event->ptouch.timestamp, (uint)event->ptouch.windowID, (uint)event->ptouch.which, (uint)event->ptouch.pen_state, event->ptouch.x, event->ptouch.y, \
+ (void)SDL_snprintf(details, sizeof(details), " (timestamp=%" SDL_PRIu64 " windowid=%u which=%u pen_state=%u x=%g y=%g eraser=%s state=%s)", \
+ event->ptouch.timestamp, (uint)event->ptouch.windowID, (uint)event->ptouch.which, (uint)event->ptouch.pen_state, event->ptouch.x, event->ptouch.y, \
event->ptouch.eraser ? "yes" : "no", event->ptouch.down ? "down" : "up");
SDL_EVENT_CASE(SDL_EVENT_PEN_DOWN)
PRINT_PTOUCH_EVENT(event);
@@ -775,8 +803,8 @@ static void SDL_LogEvent(const SDL_Event *event)
#undef PRINT_PTOUCH_EVENT
#define PRINT_PPROXIMITY_EVENT(event) \
- (void)SDL_snprintf(details, sizeof(details), " (timestamp=%u windowid=%u which=%u)", \
- (uint)event->pproximity.timestamp, (uint)event->pproximity.windowID, (uint)event->pproximity.which);
+ (void)SDL_snprintf(details, sizeof(details), " (timestamp=%" SDL_PRIu64 " windowid=%u which=%u)", \
+ event->pproximity.timestamp, (uint)event->pproximity.windowID, (uint)event->pproximity.which);
SDL_EVENT_CASE(SDL_EVENT_PEN_PROXIMITY_IN)
PRINT_PPROXIMITY_EVENT(event);
break;
@@ -786,19 +814,19 @@ static void SDL_LogEvent(const SDL_Event *event)
#undef PRINT_PPROXIMITY_EVENT
SDL_EVENT_CASE(SDL_EVENT_PEN_AXIS)
- (void)SDL_snprintf(details, sizeof(details), " (timestamp=%u windowid=%u which=%u pen_state=%u x=%g y=%g axis=%s value=%g)",
- (uint)event->paxis.timestamp, (uint)event->paxis.windowID, (uint)event->paxis.which, (uint)event->paxis.pen_state, event->paxis.x, event->paxis.y,
+ (void)SDL_snprintf(details, sizeof(details), " (timestamp=%" SDL_PRIu64 " windowid=%u which=%u pen_state=%u x=%g y=%g axis=%s value=%g)",
+ event->paxis.timestamp, (uint)event->paxis.windowID, (uint)event->paxis.which, (uint)event->paxis.pen_state, event->paxis.x, event->paxis.y,
((((int) event->paxis.axis) >= 0) && (event->paxis.axis < SDL_arraysize(pen_axisnames))) ? pen_axisnames[event->paxis.axis] : "[UNKNOWN]", event->paxis.value);
break;
SDL_EVENT_CASE(SDL_EVENT_PEN_MOTION)
- (void)SDL_snprintf(details, sizeof(details), " (timestamp=%u windowid=%u which=%u pen_state=%u x=%g y=%g)",
- (uint)event->pmotion.timestamp, (uint)event->pmotion.windowID, (uint)event->pmotion.which, (uint)event->pmotion.pen_state, event->pmotion.x, event->pmotion.y);
+ (void)SDL_snprintf(details, sizeof(details), " (timestamp=%" SDL_PRIu64 " windowid=%u which=%u pen_state=%u x=%g y=%g)",
+ event->pmotion.timestamp, (uint)event->pmotion.windowID, (uint)event->pmotion.which, (uint)event->pmotion.pen_state, event->pmotion.x, event->pmotion.y);
break;
#define PRINT_PBUTTON_EVENT(event) \
- (void)SDL_snprintf(details, sizeof(details), " (timestamp=%u windowid=%u which=%u pen_state=%u x=%g y=%g button=%u state=%s)", \
- (uint)event->pbutton.timestamp, (uint)event->pbutton.windowID, (uint)event->pbutton.which, (uint)event->pbutton.pen_state, event->pbutton.x, event->pbutton.y, \
+ (void)SDL_snprintf(details, sizeof(details), " (timestamp=%" SDL_PRIu64 " windowid=%u which=%u pen_state=%u x=%g y=%g button=%u state=%s)", \
+ event->pbutton.timestamp, (uint)event->pbutton.windowID, (uint)event->pbutton.which, (uint)event->pbutton.pen_state, event->pbutton.x, event->pbutton.y, \
(uint)event->pbutton.button, event->pbutton.down ? "down" : "up");
SDL_EVENT_CASE(SDL_EVENT_PEN_BUTTON_DOWN)
PRINT_PBUTTON_EVENT(event);
@@ -808,7 +836,7 @@ static void SDL_LogEvent(const SDL_Event *event)
break;
#undef PRINT_PBUTTON_EVENT
-#define PRINT_DROP_EVENT(event) (void)SDL_snprintf(details, sizeof(details), " (data='%s' timestamp=%u windowid=%u x=%f y=%f)", event->drop.data, (uint)event->drop.timestamp, (uint)event->drop.windowID, event->drop.x, event->drop.y)
+#define PRINT_DROP_EVENT(event) (void)SDL_snprintf(details, sizeof(details), " (data='%s' timestamp=%" SDL_PRIu64 " windowid=%u x=%f y=%f)", event->drop.data, event->drop.timestamp, (uint)event->drop.windowID, event->drop.x, event->drop.y)
SDL_EVENT_CASE(SDL_EVENT_DROP_FILE)
PRINT_DROP_EVENT(event);
break;
@@ -826,7 +854,7 @@ static void SDL_LogEvent(const SDL_Event *event)
break;
#undef PRINT_DROP_EVENT
-#define PRINT_AUDIODEV_EVENT(event) (void)SDL_snprintf(details, sizeof(details), " (timestamp=%u which=%u recording=%s)", (uint)event->adevice.timestamp, (uint)event->adevice.which, event->adevice.recording ? "true" : "false")
+#define PRINT_AUDIODEV_EVENT(event) (void)SDL_snprintf(details, sizeof(details), " (timestamp=%" SDL_PRIu64 " which=%u recording=%s)", event->adevice.timestamp, (uint)event->adevice.which, event->adevice.recording ? "true" : "false")
SDL_EVENT_CASE(SDL_EVENT_AUDIO_DEVICE_ADDED)
PRINT_AUDIODEV_EVENT(event);
break;
@@ -838,7 +866,7 @@ static void SDL_LogEvent(const SDL_Event *event)
break;
#undef PRINT_AUDIODEV_EVENT
-#define PRINT_CAMERADEV_EVENT(event) (void)SDL_snprintf(details, sizeof(details), " (timestamp=%u which=%u)", (uint)event->cdevice.timestamp, (uint)event->cdevice.which)
+#define PRINT_CAMERADEV_EVENT(event) (void)SDL_snprintf(details, sizeof(details), " (timestamp=%" SDL_PRIu64 " which=%u)", event->cdevice.timestamp, (uint)event->cdevice.which)
SDL_EVENT_CASE(SDL_EVENT_CAMERA_DEVICE_ADDED)
PRINT_CAMERADEV_EVENT(event);
break;
@@ -854,8 +882,8 @@ static void SDL_LogEvent(const SDL_Event *event)
#undef PRINT_CAMERADEV_EVENT
SDL_EVENT_CASE(SDL_EVENT_SENSOR_UPDATE)
- (void)SDL_snprintf(details, sizeof(details), " (timestamp=%u which=%d data[0]=%f data[1]=%f data[2]=%f data[3]=%f data[4]=%f data[5]=%f)",
- (uint)event->sensor.timestamp, (int)event->sensor.which,
+ (void)SDL_snprintf(details, sizeof(details), " (timestamp=%" SDL_PRIu64 " which=%d data[0]=%f data[1]=%f data[2]=%f data[3]=%f data[4]=%f data[5]=%f)",
+ event->sensor.timestamp, (int)event->sensor.which,
event->sensor.data[0], event->sensor.data[1], event->sensor.data[2],
event->sensor.data[3], event->sensor.data[4], event->sensor.data[5]);
break;
@@ -877,12 +905,46 @@ static void SDL_LogEvent(const SDL_Event *event)
}
break;
}
+#undef uint
+ int retval = 0;
if (name[0]) {
- SDL_Log("SDL EVENT: %s%s", name, details);
+ retval = SDL_snprintf(buf, buflen, "%s%s", name, details);
+ } else if (buf && (buflen > 0)) {
+ *buf = '\0';
+ }
+ return retval;
+}
+
+static void SDL_LogEvent(const SDL_Event *event)
+{
+ if (!event) {
+ return;
}
-#undef uint
+ // sensor/mouse/pen/finger/pinch motion are spammy, ignore these if they aren't demanded.
+ if ((SDL_EventLoggingVerbosity < 2) &&
+ ((event->type == SDL_EVENT_MOUSE_MOTION) ||
+ (event->type == SDL_EVENT_FINGER_MOTION) ||
+ (event->type == SDL_EVENT_PEN_AXIS) ||
+ (event->type == SDL_EVENT_PEN_MOTION) ||
+ (event->type == SDL_EVENT_PINCH_UPDATE) ||
+ (event->type == SDL_EVENT_GAMEPAD_AXIS_MOTION) ||
+ (event->type == SDL_EVENT_GAMEPAD_SENSOR_UPDATE) ||
+ (event->type == SDL_EVENT_GAMEPAD_TOUCHPAD_MOTION) ||
+ (event->type == SDL_EVENT_GAMEPAD_UPDATE_COMPLETE) ||
+ (event->type == SDL_EVENT_JOYSTICK_AXIS_MOTION) ||
+ (event->type == SDL_EVENT_JOYSTICK_UPDATE_COMPLETE) ||
+ (event->type == SDL_EVENT_SENSOR_UPDATE))) {
+ return;
+ }
+
+ char buf[256];
+ const int rc = SDL_GetEventDescription(event, buf, sizeof (buf));
+ SDL_assert(rc < sizeof (buf)); // if this overflows, we should make `buf` larger, but this is currently larger than the max SDL_GetEventDescription returns.
+ if (buf[0]) {
+ SDL_Log("SDL EVENT: %s", buf);
+ }
}
void SDL_StopEventLoop(void)
@@ -927,7 +989,7 @@ void SDL_StopEventLoop(void)
}
SDL_QuitEventWatchList(&SDL_event_watchers);
- //SDL_QuitWindowEventWatch();
+ // SDL_QuitWindowEventWatch();
SDL_Mutex *lock = NULL;
if (SDL_EventQ.lock) {
@@ -967,7 +1029,7 @@ bool SDL_StartEventLoop(void)
}
#endif // !SDL_THREADS_DISABLED
- //SDL_InitWindowEventWatch();
+ // SDL_InitWindowEventWatch();
SDL_EventQ.active = true;
@@ -1068,6 +1130,17 @@ static void SDL_SendWakeupEvent(void)
{
#ifdef SDL_PLATFORM_ANDROID
Android_SendLifecycleEvent(SDL_ANDROID_LIFECYCLE_WAKE);
+// #else
+// SDL_VideoDevice *_this = SDL_GetVideoDevice();
+// if (_this == NULL || !_this->SendWakeupEvent) {
+// return;
+// }
+
+// // We only want to do this once while waiting for an event, so set it to NULL atomically here
+// SDL_Window *wakeup_window = (SDL_Window *)SDL_SetAtomicPointer(&_this->wakeup_window, NULL);
+// if (wakeup_window) {
+// _this->SendWakeupEvent(_this, wakeup_window);
+// }
#endif
}
@@ -1092,7 +1165,7 @@ static int SDL_PeepEventsInternal(SDL_Event *events, int numevents, SDL_EventAct
return -1;
}
if (action == SDL_ADDEVENT) {
- if (!events) {
+ CHECK_PARAM(!events) {
SDL_UnlockMutex(SDL_EventQ.lock);
SDL_InvalidParamError("events");
return -1;
@@ -1385,6 +1458,10 @@ bool SDL_RunOnMainThread(SDL_MainThreadCallback callback, void *userdata, bool w
void SDL_PumpEventMaintenance(void)
{
+#ifdef SDL_USE_LIBUDEV
+ SDL_UDEV_Poll();
+#endif
+
#ifndef SDL_AUDIO_DISABLED
SDL_UpdateAudio();
#endif
@@ -1407,26 +1484,44 @@ void SDL_PumpEventMaintenance(void)
}
#endif
- //SDL_UpdateTrays();
+ // SDL_SendPendingPenProximity();
+
+ // SDL_UpdateCursorAnimation();
- //SDL_SendPendingSignalEvents(); // in case we had a signal handler fire, etc.
+ // SDL_UpdateTrays();
+
+ // SDL_SendPendingSignalEvents(); // in case we had a signal handler fire, etc.
}
// Run the system dependent event loops
static void SDL_PumpEventsInternal(bool push_sentinel)
{
+ // This should only be called on the main thread, check in debug builds
+ SDL_assert(SDL_IsMainThread());
+
// Free any temporary memory from old events
SDL_FreeTemporaryMemory();
// Release any keys held down from last frame
- //SDL_ReleaseAutoReleaseKeys();
+ // SDL_ReleaseAutoReleaseKeys();
// Run any pending main thread callbacks
SDL_RunMainThreadCallbacks();
+#ifdef SDL_USE_LIBDBUS
+ // DBus event processing is independent of the video subsystem
+ SDL_DBus_PumpEvents();
+#endif
+
#ifdef SDL_PLATFORM_ANDROID
// Android event processing is independent of the video subsystem
Android_PumpEvents(0);
+// #else
+// // Get events from the video subsystem
+// SDL_VideoDevice *_this = SDL_GetVideoDevice();
+// if (_this) {
+// _this->PumpEvents(_this);
+// }
#endif
SDL_PumpEventMaintenance();
@@ -1457,6 +1552,114 @@ bool SDL_PollEvent(SDL_Event *event)
return SDL_WaitEventTimeoutNS(event, 0);
}
+// #ifndef SDL_PLATFORM_ANDROID
+
+// static Sint64 SDL_events_get_polling_interval(void)
+// {
+// Sint64 poll_intervalNS = SDL_MAX_SINT64;
+
+// #ifndef SDL_JOYSTICK_DISABLED
+// if (SDL_WasInit(SDL_INIT_JOYSTICK) && SDL_update_joysticks) {
+// if (SDL_JoysticksOpened()) {
+// // If we have joysticks open, we need to poll rapidly for events
+// poll_intervalNS = SDL_min(poll_intervalNS, EVENT_POLL_INTERVAL_NS);
+// } else {
+// // If not, just poll every few seconds to enumerate new joysticks
+// poll_intervalNS = SDL_min(poll_intervalNS, ENUMERATION_POLL_INTERVAL_NS);
+// }
+// }
+// #endif
+
+// #ifndef SDL_SENSOR_DISABLED
+// if (SDL_WasInit(SDL_INIT_SENSOR) && SDL_update_sensors && SDL_SensorsOpened()) {
+// // If we have sensors open, we need to poll rapidly for events
+// poll_intervalNS = SDL_min(poll_intervalNS, EVENT_POLL_INTERVAL_NS);
+// }
+// #endif
+
+// #ifdef SDL_PLATFORM_UNIX
+// if (SDL_HasActiveTrays()) {
+// // Tray events on *nix platforms run separately from window system events, and need periodic polling
+// poll_intervalNS = SDL_min(poll_intervalNS, TRAY_POLL_INTERVAL_NS);
+// }
+// #endif
+
+// #ifdef SDL_USE_LIBDBUS
+// // Wake periodically to pump DBus events
+// poll_intervalNS = SDL_min(poll_intervalNS, DBUS_POLL_INTERVAL_NS);
+// #endif
+// return poll_intervalNS;
+// }
+
+// static int SDL_WaitEventTimeout_Device(SDL_VideoDevice *_this, SDL_Window *wakeup_window, SDL_Event *event, Uint64 start, Sint64 timeoutNS)
+// {
+// Sint64 loop_timeoutNS = timeoutNS;
+// Sint64 poll_intervalNS = SDL_events_get_polling_interval();
+
+// for (;;) {
+// int status;
+// /* Pump events on entry and each time we wake to ensure:
+// a) All pending events are batch processed after waking up from a wait
+// b) Waiting can be completely skipped if events are already available to be pumped
+// c) Periodic processing that takes place in some platform PumpEvents() functions happens
+// d) Signals received in WaitEventTimeout() are turned into SDL events
+// */
+// SDL_PumpEventsInternal(true);
+
+// status = SDL_PeepEvents(event, 1, SDL_GETEVENT, SDL_EVENT_FIRST, SDL_EVENT_LAST);
+// if (status < 0) {
+// // Got an error: return
+// break;
+// }
+// if (status > 0) {
+// // There is an event, we can return.
+// return 1;
+// }
+// // No events found in the queue, call WaitEventTimeout to wait for an event.
+// if (timeoutNS > 0) {
+// Sint64 elapsed = SDL_GetTicksNS() - start;
+// if (elapsed >= timeoutNS) {
+// return 0;
+// }
+// loop_timeoutNS = (timeoutNS - elapsed);
+// }
+// // Adjust the timeout for any polling requirements we currently have.
+// if (poll_intervalNS != SDL_MAX_SINT64) {
+// if (loop_timeoutNS >= 0) {
+// loop_timeoutNS = SDL_min(loop_timeoutNS, poll_intervalNS);
+// } else {
+// loop_timeoutNS = poll_intervalNS;
+// }
+// }
+// SDL_SetAtomicPointer(&_this->wakeup_window, wakeup_window);
+// status = _this->WaitEventTimeout(_this, loop_timeoutNS);
+// SDL_SetAtomicPointer(&_this->wakeup_window, NULL);
+// if (status == 0 && poll_intervalNS != SDL_MAX_SINT64 && loop_timeoutNS == poll_intervalNS) {
+// // We may have woken up to poll. Try again
+// continue;
+// } else if (status <= 0) {
+// // There is either an error or the timeout is elapsed: return
+// return status;
+// }
+// /* An event was found and pumped into the SDL events queue. Continue the loop
+// to let SDL_PeepEvents pick it up .*/
+// }
+// return 0;
+// }
+
+// static SDL_Window *SDL_find_active_window(SDL_VideoDevice *_this)
+// {
+// SDL_Window *window;
+// for (window = _this->windows; window; window = window->next) {
+// if (!window->is_destroying) {
+// return window;
+// }
+// }
+// return NULL;
+// }
+
+// #endif // !SDL_PLATFORM_ANDROID
+
bool SDL_WaitEvent(SDL_Event *event)
{
return SDL_WaitEventTimeoutNS(event, -1);
@@ -1523,6 +1726,10 @@ bool SDL_WaitEventTimeoutNS(SDL_Event *event, Sint64 timeoutNS)
}
} else {
// Has existing events
+ if (!event) {
+ // The application expects callbacks to run even if events are pending
+ SDL_RunMainThreadCallbacks();
+ }
return true;
}
// We should have completely handled timeoutNS == 0 above
@@ -1548,6 +1755,24 @@ bool SDL_WaitEventTimeoutNS(SDL_Event *event, Sint64 timeoutNS)
Android_PumpEvents(delay);
}
#else
+ // SDL_VideoDevice *_this = SDL_GetVideoDevice();
+ // if (_this && _this->WaitEventTimeout && _this->SendWakeupEvent) {
+ // // Look if a shown window is available to send the wakeup event.
+ // SDL_Window *wakeup_window = SDL_find_active_window(_this);
+ // if (wakeup_window) {
+ // result = SDL_WaitEventTimeout_Device(_this, wakeup_window, event, start, timeoutNS);
+ // if (result > 0) {
+ // return true;
+ // } else if (result == 0) {
+ // return false;
+ // } else {
+ // /* There may be implementation-defined conditions where the backend cannot
+ // * reliably wait for the next event. If that happens, fall back to polling.
+ // */
+ // }
+ // }
+ // }
+
for (;;) {
SDL_PumpEventsInternal(true);
@@ -1720,7 +1945,7 @@ void SDL_SetEventEnabled(Uint32 type, bool enabled)
/* turn off drag'n'drop support if we've disabled the events.
This might change some UI details at the OS level. */
if (type == SDL_EVENT_DROP_FILE || type == SDL_EVENT_DROP_TEXT) {
- //SDL_ToggleDragAndDropSupport();
+ // SDL_ToggleDragAndDropSupport();
}
}
}
@@ -1812,14 +2037,14 @@ bool SDL_InitEvents(void)
return false;
}
- //SDL_InitQuit();
+ // SDL_InitQuit();
return true;
}
void SDL_QuitEvents(void)
{
- //SDL_QuitQuit();
+ // SDL_QuitQuit();
SDL_StopEventLoop();
SDL_QuitMainThreadCallbacks();
SDL_RemoveHintCallback(SDL_HINT_POLL_SENTINEL, SDL_PollSentinelChanged, NULL);
diff --git a/thirdparty/sdl/events/SDL_events_c.h b/thirdparty/sdl/events/SDL_events_c.h
index f3a0744d1cf..8bd09458c13 100644
--- a/thirdparty/sdl/events/SDL_events_c.h
+++ b/thirdparty/sdl/events/SDL_events_c.h
@@ -1,6 +1,6 @@
/*
Simple DirectMedia Layer
- Copyright (C) 1997-2025 Sam Lantinga <[email protected]>
+ Copyright (C) 1997-2026 Sam Lantinga <[email protected]>
This software is provided 'as-is', without any express or implied
warranty. In no event will the authors be held liable for any damages
@@ -25,9 +25,16 @@
#include "SDL_internal.h"
// Useful functions and variables from SDL_events.c
-//#include "../video/SDL_sysvideo.h"
+// #include "../video/SDL_sysvideo.h"
+// #include "SDL_clipboardevents_c.h"
+// #include "SDL_displayevents_c.h"
+// #include "SDL_dropevents_c.h"
+// #include "SDL_keyboard_c.h"
#include "SDL_mouse_c.h"
+// #include "SDL_touch_c.h"
+// #include "SDL_pen_c.h"
+// #include "SDL_windowevents_c.h"
// Start and stop the event processing loop
extern bool SDL_StartEventLoop(void);
diff --git a/thirdparty/sdl/events/SDL_eventwatch.c b/thirdparty/sdl/events/SDL_eventwatch.c
index 08e7248c6a4..5d0ff353175 100644
--- a/thirdparty/sdl/events/SDL_eventwatch.c
+++ b/thirdparty/sdl/events/SDL_eventwatch.c
@@ -1,6 +1,6 @@
/*
Simple DirectMedia Layer
- Copyright (C) 1997-2025 Sam Lantinga <[email protected]>
+ Copyright (C) 1997-2026 Sam Lantinga <[email protected]>
This software is provided 'as-is', without any express or implied
warranty. In no event will the authors be held liable for any damages
diff --git a/thirdparty/sdl/events/SDL_eventwatch_c.h b/thirdparty/sdl/events/SDL_eventwatch_c.h
index c9aea38c0dd..5c382a7cae5 100644
--- a/thirdparty/sdl/events/SDL_eventwatch_c.h
+++ b/thirdparty/sdl/events/SDL_eventwatch_c.h
@@ -1,6 +1,6 @@
/*
Simple DirectMedia Layer
- Copyright (C) 1997-2025 Sam Lantinga <[email protected]>
+ Copyright (C) 1997-2026 Sam Lantinga <[email protected]>
This software is provided 'as-is', without any express or implied
warranty. In no event will the authors be held liable for any damages
diff --git a/thirdparty/sdl/events/SDL_mouse_c.h b/thirdparty/sdl/events/SDL_mouse_c.h
index 5927b8bd75f..36c458df433 100644
--- a/thirdparty/sdl/events/SDL_mouse_c.h
+++ b/thirdparty/sdl/events/SDL_mouse_c.h
@@ -1,6 +1,6 @@
/*
Simple DirectMedia Layer
- Copyright (C) 1997-2025 Sam Lantinga <[email protected]>
+ Copyright (C) 1997-2026 Sam Lantinga <[email protected]>
This software is provided 'as-is', without any express or implied
warranty. In no event will the authors be held liable for any damages
@@ -31,10 +31,24 @@
typedef struct SDL_CursorData SDL_CursorData;
+struct SDL_Cursor;
+
+typedef struct
+{
+ Uint64 last_update;
+ int num_frames;
+ int current_frame;
+ struct SDL_Cursor **frames;
+ Uint32 *durations;
+} SDL_CursorAnimation;
+
struct SDL_Cursor
{
- struct SDL_Cursor *next;
+ SDL_CursorAnimation *animation;
+
SDL_CursorData *internal;
+
+ struct SDL_Cursor *next;
};
typedef struct
@@ -60,6 +74,9 @@ typedef struct
// Create a cursor from a surface
SDL_Cursor *(*CreateCursor)(SDL_Surface *surface, int hot_x, int hot_y);
+ // Create an animated cursor from a sequence of surfaces
+ SDL_Cursor *(*CreateAnimatedCursor)(SDL_CursorFrameInfo *frames, int frame_count, int hot_x, int hot_y);
+
// Create a system cursor
SDL_Cursor *(*CreateSystemCursor)(SDL_SystemCursor id);
@@ -87,10 +104,14 @@ typedef struct
// Get absolute mouse coordinates. (x) and (y) are never NULL and set to zero before call.
SDL_MouseButtonFlags (*GetGlobalMouseState)(float *x, float *y);
- // Platform-specific system mouse transform
- void (*ApplySystemScale)(void *internal, Uint64 timestamp, SDL_Window *window, SDL_MouseID mouseID, float *x, float *y);
+ // Platform-specific system mouse transform applied in relative mode
+ SDL_MouseMotionTransformCallback ApplySystemScale;
void *system_scale_data;
+ // User-defined mouse input transform applied in relative mode
+ SDL_MouseMotionTransformCallback InputTransform;
+ void *input_transform_data;
+
// integer mode data
Uint8 integer_mode_flags; // 1 to enable mouse quantization, 2 to enable wheel quantization
float integer_mode_residual_motion_x;
@@ -110,7 +131,7 @@ typedef struct
bool has_position;
bool relative_mode;
bool relative_mode_warp_motion;
- bool relative_mode_cursor_visible;
+ bool relative_mode_hide_cursor;
bool relative_mode_center;
bool warp_emulation_hint;
bool warp_emulation_active;
@@ -144,7 +165,7 @@ typedef struct
SDL_Cursor *cursors;
SDL_Cursor *def_cursor;
SDL_Cursor *cur_cursor;
- bool cursor_shown;
+ bool cursor_visible;
// Driver-dependent data.
void *internal;
@@ -160,20 +181,26 @@ extern void SDL_PostInitMouse(void);
extern bool SDL_IsMouse(Uint16 vendor, Uint16 product);
// A mouse has been added to the system
-extern void SDL_AddMouse(SDL_MouseID mouseID, const char *name, bool send_event);
+extern void SDL_AddMouse(SDL_MouseID mouseID, const char *name);
// A mouse has been removed from the system
-extern void SDL_RemoveMouse(SDL_MouseID mouseID, bool send_event);
+extern void SDL_RemoveMouse(SDL_MouseID mouseID);
// Get the mouse state structure
extern SDL_Mouse *SDL_GetMouse(void);
+// Set the default mouse cursor
+extern void SDL_RedrawCursor(void);
+
// Set the default mouse cursor
extern void SDL_SetDefaultCursor(SDL_Cursor *cursor);
// Get the preferred default system cursor
extern SDL_SystemCursor SDL_GetDefaultSystemCursor(void);
+// Update the current cursor animation if needed
+extern void SDL_UpdateCursorAnimation(void);
+
// Set the mouse focus window
extern void SDL_SetMouseFocus(SDL_Window *window);
@@ -198,7 +225,7 @@ extern void SDL_PerformWarpMouseInWindow(SDL_Window *window, float x, float y, b
// Relative mouse mode
extern bool SDL_SetRelativeMouseMode(bool enabled);
extern bool SDL_GetRelativeMouseMode(void);
-extern void SDL_UpdateRelativeMouseMode(void);
+extern bool SDL_UpdateRelativeMouseMode(void);
extern void SDL_DisableMouseWarpEmulation(void);
// TODO RECONNECT: Set mouse state to "zero"
diff --git a/thirdparty/sdl/filesystem/SDL_filesystem.c b/thirdparty/sdl/filesystem/SDL_filesystem.c
new file mode 100644
index 00000000000..81c0b41e346
--- /dev/null
+++ b/thirdparty/sdl/filesystem/SDL_filesystem.c
@@ -0,0 +1,561 @@
+/*
+ Simple DirectMedia Layer
+ Copyright (C) 1997-2026 Sam Lantinga <[email protected]>
+
+ 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"
+
+#include "SDL_filesystem_c.h"
+#include "SDL_sysfilesystem.h"
+#include "../stdlib/SDL_sysstdlib.h"
+
+bool SDL_RemovePath(const char *path)
+{
+ CHECK_PARAM(!path) {
+ return SDL_InvalidParamError("path");
+ }
+ return SDL_SYS_RemovePath(path);
+}
+
+bool SDL_RenamePath(const char *oldpath, const char *newpath)
+{
+ CHECK_PARAM(!oldpath) {
+ return SDL_InvalidParamError("oldpath");
+ }
+ CHECK_PARAM(!newpath) {
+ return SDL_InvalidParamError("newpath");
+ }
+ return SDL_SYS_RenamePath(oldpath, newpath);
+}
+
+bool SDL_CopyFile(const char *oldpath, const char *newpath)
+{
+ CHECK_PARAM(!oldpath) {
+ return SDL_InvalidParamError("oldpath");
+ }
+ CHECK_PARAM(!newpath) {
+ return SDL_InvalidParamError("newpath");
+ }
+ return SDL_SYS_CopyFile(oldpath, newpath);
+}
+
+bool SDL_CreateDirectory(const char *path)
+{
+ CHECK_PARAM(!path) {
+ return SDL_InvalidParamError("path");
+ }
+
+ bool retval = SDL_SYS_CreateDirectory(path);
+ if (!retval && *path) { // maybe we're missing parent directories?
+ char *parents = SDL_strdup(path);
+ if (!parents) {
+ return false; // oh well.
+ }
+
+ // in case there was a separator at the end of the path and it was
+ // upsetting something, chop it off.
+ const size_t slen = SDL_strlen(parents);
+ #ifdef SDL_PLATFORM_WINDOWS
+ if ((parents[slen - 1] == '/') || (parents[slen - 1] == '\\'))
+ #else
+ if (parents[slen - 1] == '/')
+ #endif
+ {
+ parents[slen - 1] = '\0';
+ retval = SDL_SYS_CreateDirectory(parents);
+ }
+
+ if (!retval) {
+ for (char *ptr = parents; *ptr; ptr++) {
+ const char ch = *ptr;
+ #ifdef SDL_PLATFORM_WINDOWS
+ const bool issep = (ch == '/') || (ch == '\\');
+ if (issep && ((ptr - parents) == 2) && (parents[1] == ':')) {
+ continue; // it's just the drive letter, skip it.
+ }
+ #else
+ const bool issep = (ch == '/');
+ if (issep && ((ptr - parents) == 0)) {
+ continue; // it's just the root directory, skip it.
+ }
+ #endif
+
+ if (issep) {
+ *ptr = '\0';
+ // (this does not fail if the path already exists as a directory.)
+ retval = SDL_SYS_CreateDirectory(parents);
+ if (!retval) { // still failing when making parents? Give up.
+ break;
+ }
+ *ptr = ch;
+ }
+ }
+
+ // last chance: did it work this time?
+ retval = SDL_SYS_CreateDirectory(parents);
+ }
+
+ SDL_free(parents);
+ }
+ return retval;
+}
+
+bool SDL_EnumerateDirectory(const char *path, SDL_EnumerateDirectoryCallback callback, void *userdata)
+{
+ CHECK_PARAM(!path) {
+ return SDL_InvalidParamError("path");
+ }
+ CHECK_PARAM(!callback) {
+ return SDL_InvalidParamError("callback");
+ }
+ return SDL_SYS_EnumerateDirectory(path, callback, userdata);
+}
+
+bool SDL_GetPathInfo(const char *path, SDL_PathInfo *info)
+{
+ SDL_PathInfo dummy;
+
+ if (!info) {
+ info = &dummy;
+ }
+ SDL_zerop(info);
+
+ CHECK_PARAM(!path) {
+ return SDL_InvalidParamError("path");
+ }
+ return SDL_SYS_GetPathInfo(path, info);
+}
+
+static bool EverythingMatch(const char *pattern, const char *str, bool *matched_to_dir)
+{
+ SDL_assert(pattern == NULL);
+ SDL_assert(str != NULL);
+ SDL_assert(matched_to_dir != NULL);
+
+ *matched_to_dir = true;
+ return true; // everything matches!
+}
+
+// this is just '*' and '?', with '/' matching nothing.
+static bool WildcardMatch(const char *pattern, const char *str, bool *matched_to_dir)
+{
+ SDL_assert(pattern != NULL);
+ SDL_assert(str != NULL);
+ SDL_assert(matched_to_dir != NULL);
+
+ const char *str_backtrack = NULL;
+ const char *pattern_backtrack = NULL;
+ char sch_backtrack = 0;
+ char sch = *str;
+ char pch = *pattern;
+
+ while (sch) {
+ if (pch == '*') {
+ str_backtrack = str;
+ pattern_backtrack = ++pattern;
+ sch_backtrack = sch;
+ pch = *pattern;
+ } else if (pch == sch) {
+ if (pch == '/') {
+ str_backtrack = pattern_backtrack = NULL;
+ }
+ sch = *(++str);
+ pch = *(++pattern);
+ } else if ((pch == '?') && (sch != '/')) { // end of string (checked at `while`) or path separator do not match '?'.
+ sch = *(++str);
+ pch = *(++pattern);
+ } else if (!pattern_backtrack || (sch_backtrack == '/')) { // we didn't have a match. Are we in a '*' and NOT on a path separator? Keep going. Otherwise, fail.
+ *matched_to_dir = false;
+ return false;
+ } else { // still here? Wasn't a match, but we're definitely in a '*' pattern.
+ str = ++str_backtrack;
+ pattern = pattern_backtrack;
+ sch_backtrack = sch;
+ sch = *str;
+ pch = *pattern;
+ }
+
+ #ifdef SDL_PLATFORM_WINDOWS
+ if (sch == '\\') {
+ sch = '/';
+ }
+ #endif
+ }
+
+ // '*' at the end can be ignored, they are allowed to match nothing.
+ while (pch == '*') {
+ pch = *(++pattern);
+ }
+
+ *matched_to_dir = (pch == '/'); // end of string and the pattern failed at a '/'? We should descend into this directory.
+
+ return (pch == '\0'); // survived the whole pattern? That's a match!
+}
+
+
+// Note that this will currently encode illegal codepoints: UTF-16 surrogates, 0xFFFE, and 0xFFFF.
+// and a codepoint > 0x10FFFF will fail the same as if there wasn't enough memory.
+// clean this up if you want to move this to SDL_string.c.
+static size_t EncodeCodepointToUtf8(char *ptr, Uint32 cp, size_t remaining)
+{
+ if (cp < 0x80) { // fits in a single UTF-8 byte.
+ if (remaining) {
+ *ptr = (char) cp;
+ return 1;
+ }
+ } else if (cp < 0x800) { // fits in 2 bytes.
+ if (remaining >= 2) {
+ ptr[0] = (char) ((cp >> 6) | 128 | 64);
+ ptr[1] = (char) (cp & 0x3F) | 128;
+ return 2;
+ }
+ } else if (cp < 0x10000) { // fits in 3 bytes.
+ if (remaining >= 3) {
+ ptr[0] = (char) ((cp >> 12) | 128 | 64 | 32);
+ ptr[1] = (char) ((cp >> 6) & 0x3F) | 128;
+ ptr[2] = (char) (cp & 0x3F) | 128;
+ return 3;
+ }
+ } else if (cp <= 0x10FFFF) { // fits in 4 bytes.
+ if (remaining >= 4) {
+ ptr[0] = (char) ((cp >> 18) | 128 | 64 | 32 | 16);
+ ptr[1] = (char) ((cp >> 12) & 0x3F) | 128;
+ ptr[2] = (char) ((cp >> 6) & 0x3F) | 128;
+ ptr[3] = (char) (cp & 0x3F) | 128;
+ return 4;
+ }
+ }
+
+ return 0;
+}
+
+static char *CaseFoldUtf8String(const char *fname)
+{
+ SDL_assert(fname != NULL);
+ const size_t allocation = (SDL_strlen(fname) + 1) * 3 * 4;
+ char *result = (char *) SDL_malloc(allocation); // lazy: just allocating the max needed.
+ if (!result) {
+ return NULL;
+ }
+
+ Uint32 codepoint;
+ char *ptr = result;
+ size_t remaining = allocation;
+ while ((codepoint = SDL_StepUTF8(&fname, NULL)) != 0) {
+ Uint32 folded[3];
+ const int num_folded = SDL_CaseFoldUnicode(codepoint, folded);
+ SDL_assert(num_folded > 0);
+ SDL_assert(num_folded <= SDL_arraysize(folded));
+ for (int i = 0; i < num_folded; i++) {
+ SDL_assert(remaining > 0);
+ const size_t rc = EncodeCodepointToUtf8(ptr, folded[i], remaining);
+ SDL_assert(rc > 0);
+ SDL_assert(rc < remaining);
+ remaining -= rc;
+ ptr += rc;
+ }
+ }
+
+ SDL_assert(remaining > 0);
+ remaining--;
+ *ptr = '\0';
+
+ if (remaining > 0) {
+ SDL_assert(allocation > remaining);
+ ptr = (char *)SDL_realloc(result, allocation - remaining); // shrink it down.
+ if (ptr) { // shouldn't fail, but if it does, `result` is still valid.
+ result = ptr;
+ }
+ }
+
+ return result;
+}
+
+
+typedef struct GlobDirCallbackData
+{
+ bool (*matcher)(const char *pattern, const char *str, bool *matched_to_dir);
+ const char *pattern;
+ int num_entries;
+ SDL_GlobFlags flags;
+ SDL_GlobEnumeratorFunc enumerator;
+ SDL_GlobGetPathInfoFunc getpathinfo;
+ void *fsuserdata;
+ size_t basedirlen;
+ SDL_IOStream *string_stream;
+} GlobDirCallbackData;
+
+static SDL_EnumerationResult SDLCALL GlobDirectoryCallback(void *userdata, const char *dirname, const char *fname)
+{
+ SDL_assert(userdata != NULL);
+ SDL_assert(dirname != NULL);
+ SDL_assert(fname != NULL);
+
+ //SDL_Log("GlobDirectoryCallback('%s', '%s')", dirname, fname);
+
+ GlobDirCallbackData *data = (GlobDirCallbackData *) userdata;
+
+ // !!! FIXME: if we're careful, we can keep a single buffer in `data` that we push and pop paths off the end of as we walk the tree,
+ // !!! FIXME: and only casefold the new pieces instead of allocating and folding full paths for all of this.
+
+ char *fullpath = NULL;
+ if (SDL_asprintf(&fullpath, "%s%s", dirname, fname) < 0) {
+ return SDL_ENUM_FAILURE;
+ }
+
+ char *folded = NULL;
+ if (data->flags & SDL_GLOB_CASEINSENSITIVE) {
+ folded = CaseFoldUtf8String(fullpath);
+ if (!folded) {
+ return SDL_ENUM_FAILURE;
+ }
+ }
+
+ bool matched_to_dir = false;
+ const bool matched = data->matcher(data->pattern, (folded ? folded : fullpath) + data->basedirlen, &matched_to_dir);
+ //SDL_Log("GlobDirectoryCallback: Considered %spath='%s' vs pattern='%s': %smatched (matched_to_dir=%s)", folded ? "(folded) " : "", (folded ? folded : fullpath) + data->basedirlen, data->pattern, matched ? "" : "NOT ", matched_to_dir ? "TRUE" : "FALSE");
+ SDL_free(folded);
+
+ if (matched) {
+ const char *subpath = fullpath + data->basedirlen;
+ const size_t slen = SDL_strlen(subpath) + 1;
+ if (SDL_WriteIO(data->string_stream, subpath, slen) != slen) {
+ SDL_free(fullpath);
+ return SDL_ENUM_FAILURE; // stop enumerating, return failure to the app.
+ }
+ data->num_entries++;
+ }
+
+ SDL_EnumerationResult result = SDL_ENUM_CONTINUE; // keep enumerating by default.
+ if (matched_to_dir) {
+ SDL_PathInfo info;
+ if (data->getpathinfo(fullpath, &info, data->fsuserdata) && (info.type == SDL_PATHTYPE_DIRECTORY)) {
+ //SDL_Log("GlobDirectoryCallback: Descending into subdir '%s'", fname);
+ if (!data->enumerator(fullpath, GlobDirectoryCallback, data, data->fsuserdata)) {
+ result = SDL_ENUM_FAILURE;
+ }
+ }
+ }
+
+ SDL_free(fullpath);
+
+ return result;
+}
+
+char **SDL_InternalGlobDirectory(const char *path, const char *pattern, SDL_GlobFlags flags, int *count, SDL_GlobEnumeratorFunc enumerator, SDL_GlobGetPathInfoFunc getpathinfo, void *userdata)
+{
+ int dummycount;
+ if (!count) {
+ count = &dummycount;
+ }
+ *count = 0;
+
+ CHECK_PARAM(!path) {
+ SDL_InvalidParamError("path");
+ return NULL;
+ }
+
+ // if path ends with any slash, chop them off, so we don't confuse the pattern matcher later.
+ char *pathcpy = NULL;
+ size_t pathlen = SDL_strlen(path);
+ if ((pathlen > 1) && ((path[pathlen-1] == '/') || (path[pathlen-1] == '\\'))) {
+ pathcpy = SDL_strdup(path);
+ if (!pathcpy) {
+ return NULL;
+ }
+ char *ptr = &pathcpy[pathlen-1];
+ while ((ptr > pathcpy) && ((*ptr == '/') || (*ptr == '\\'))) {
+ *(ptr--) = '\0';
+ --pathlen;
+ }
+ path = pathcpy;
+ }
+
+ if (!pattern) {
+ flags &= ~SDL_GLOB_CASEINSENSITIVE; // avoid some unnecessary allocations and work later.
+ }
+
+ char *folded = NULL;
+ if (flags & SDL_GLOB_CASEINSENSITIVE) {
+ SDL_assert(pattern != NULL);
+ folded = CaseFoldUtf8String(pattern);
+ if (!folded) {
+ SDL_free(pathcpy);
+ return NULL;
+ }
+ }
+
+ GlobDirCallbackData data;
+ SDL_zero(data);
+ data.string_stream = SDL_IOFromDynamicMem();
+ if (!data.string_stream) {
+ SDL_free(folded);
+ SDL_free(pathcpy);
+ return NULL;
+ }
+
+ if (!pattern) {
+ data.matcher = EverythingMatch; // no pattern? Everything matches.
+
+ // !!! FIXME
+ //} else if (flags & SDL_GLOB_GITIGNORE) {
+ // data.matcher = GitIgnoreMatch;
+
+ } else {
+ data.matcher = WildcardMatch;
+ }
+
+ data.pattern = folded ? folded : pattern;
+ data.flags = flags;
+ data.enumerator = enumerator;
+ data.getpathinfo = getpathinfo;
+ data.fsuserdata = userdata;
+
+ data.basedirlen = 0;
+ if (*path) {
+ if (SDL_strcmp(path, "/") == 0 || SDL_strcmp(path, "\\") == 0) {
+ data.basedirlen = 1;
+ } else {
+ data.basedirlen = pathlen + 1; // +1 for the '/' we'll be adding.
+ }
+ }
+
+ char **result = NULL;
+ if (data.enumerator(path, GlobDirectoryCallback, &data, data.fsuserdata)) {
+ const size_t streamlen = (size_t) SDL_GetIOSize(data.string_stream);
+ const size_t buflen = streamlen + ((data.num_entries + 1) * sizeof (char *)); // +1 for NULL terminator at end of array.
+ result = (char **) SDL_malloc(buflen);
+ if (result) {
+ if (data.num_entries > 0) {
+ Sint64 iorc = SDL_SeekIO(data.string_stream, 0, SDL_IO_SEEK_SET);
+ SDL_assert(iorc == 0); // this should never fail for a memory stream!
+ char *ptr = (char *) (result + (data.num_entries + 1));
+ iorc = SDL_ReadIO(data.string_stream, ptr, streamlen);
+ SDL_assert(iorc == (Sint64) streamlen); // this should never fail for a memory stream!
+ for (int i = 0; i < data.num_entries; i++) {
+ result[i] = ptr;
+ ptr += SDL_strlen(ptr) + 1;
+ }
+ }
+ result[data.num_entries] = NULL; // NULL terminate the list.
+ *count = data.num_entries;
+ }
+ }
+
+ SDL_CloseIO(data.string_stream);
+ SDL_free(folded);
+ SDL_free(pathcpy);
+
+ return result;
+}
+
+static bool GlobDirectoryGetPathInfo(const char *path, SDL_PathInfo *info, void *userdata)
+{
+ return SDL_GetPathInfo(path, info);
+}
+
+static bool GlobDirectoryEnumerator(const char *path, SDL_EnumerateDirectoryCallback cb, void *cbuserdata, void *userdata)
+{
+ return SDL_EnumerateDirectory(path, cb, cbuserdata);
+}
+
+char **SDL_GlobDirectory(const char *path, const char *pattern, SDL_GlobFlags flags, int *count)
+{
+ //SDL_Log("SDL_GlobDirectory('%s', '%s') ...", path, pattern);
+ return SDL_InternalGlobDirectory(path, pattern, flags, count, GlobDirectoryEnumerator, GlobDirectoryGetPathInfo, NULL);
+}
+
+
+static char *CachedBasePath = NULL;
+
+const char *SDL_GetBasePath(void)
+{
+ if (!CachedBasePath) {
+ CachedBasePath = SDL_SYS_GetBasePath();
+ }
+ return CachedBasePath;
+}
+
+
+static char *CachedUserFolders[SDL_FOLDER_COUNT];
+
+const char *SDL_GetUserFolder(SDL_Folder folder)
+{
+ const int idx = (int) folder;
+
+ CHECK_PARAM((idx < 0) || (idx >= SDL_arraysize(CachedUserFolders))) {
+ SDL_InvalidParamError("folder");
+ return NULL;
+ }
+
+ if (!CachedUserFolders[idx]) {
+ CachedUserFolders[idx] = SDL_SYS_GetUserFolder(folder);
+ }
+ return CachedUserFolders[idx];
+}
+
+static char *CachedExeName = NULL;
+const char *SDL_GetExeName(void)
+{
+ if (!CachedExeName) {
+ CachedExeName = SDL_SYS_GetExeName();
+ }
+ return CachedExeName;
+}
+
+char *SDL_GetPrefPath(const char *org, const char *app)
+{
+ CHECK_PARAM(!app) {
+ SDL_InvalidParamError("app");
+ return NULL;
+ }
+
+ // if org is NULL, just make it "" so backends don't have to check both.
+ if (!org) {
+ org = "";
+ }
+
+ return SDL_SYS_GetPrefPath(org, app);
+}
+
+char *SDL_GetCurrentDirectory(void)
+{
+ return SDL_SYS_GetCurrentDirectory();
+}
+
+void SDL_InitFilesystem(void)
+{
+}
+
+void SDL_QuitFilesystem(void)
+{
+ SDL_free(CachedBasePath);
+ CachedBasePath = NULL;
+
+ SDL_free(CachedExeName);
+ CachedExeName = NULL;
+
+ for (int i = 0; i < SDL_arraysize(CachedUserFolders); i++) {
+ if (CachedUserFolders[i]) {
+ SDL_free(CachedUserFolders[i]);
+ CachedUserFolders[i] = NULL;
+ }
+ }
+}
+
diff --git a/thirdparty/sdl/filesystem/SDL_filesystem_c.h b/thirdparty/sdl/filesystem/SDL_filesystem_c.h
new file mode 100644
index 00000000000..685cda28224
--- /dev/null
+++ b/thirdparty/sdl/filesystem/SDL_filesystem_c.h
@@ -0,0 +1,29 @@
+/*
+ Simple DirectMedia Layer
+ Copyright (C) 1997-2026 Sam Lantinga <[email protected]>
+
+ 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.
+*/
+
+#ifndef SDL_filesystem_c_h_
+#define SDL_filesystem_c_h_
+
+extern void SDL_InitFilesystem(void);
+extern void SDL_QuitFilesystem(void);
+
+#endif
+
diff --git a/thirdparty/sdl/filesystem/SDL_sysfilesystem.h b/thirdparty/sdl/filesystem/SDL_sysfilesystem.h
new file mode 100644
index 00000000000..4f1cf1d5ccf
--- /dev/null
+++ b/thirdparty/sdl/filesystem/SDL_sysfilesystem.h
@@ -0,0 +1,44 @@
+/*
+ Simple DirectMedia Layer
+ Copyright (C) 1997-2026 Sam Lantinga <[email protected]>
+
+ 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.
+*/
+
+#ifndef SDL_sysfilesystem_h_
+#define SDL_sysfilesystem_h_
+
+// return a string that we can SDL_free(). It will be cached at the higher level.
+extern char *SDL_SYS_GetBasePath(void);
+extern char *SDL_SYS_GetExeName(void);
+extern char *SDL_SYS_GetPrefPath(const char *org, const char *app);
+extern char *SDL_SYS_GetUserFolder(SDL_Folder folder);
+extern char *SDL_SYS_GetCurrentDirectory(void);
+
+extern bool SDL_SYS_EnumerateDirectory(const char *path, SDL_EnumerateDirectoryCallback cb, void *userdata);
+extern bool SDL_SYS_RemovePath(const char *path);
+extern bool SDL_SYS_RenamePath(const char *oldpath, const char *newpath);
+extern bool SDL_SYS_CopyFile(const char *oldpath, const char *newpath);
+extern bool SDL_SYS_CreateDirectory(const char *path);
+extern bool SDL_SYS_GetPathInfo(const char *path, SDL_PathInfo *info);
+
+typedef bool (*SDL_GlobEnumeratorFunc)(const char *path, SDL_EnumerateDirectoryCallback cb, void *cbuserdata, void *userdata);
+typedef bool (*SDL_GlobGetPathInfoFunc)(const char *path, SDL_PathInfo *info, void *userdata);
+extern char **SDL_InternalGlobDirectory(const char *path, const char *pattern, SDL_GlobFlags flags, int *count, SDL_GlobEnumeratorFunc enumerator, SDL_GlobGetPathInfoFunc getpathinfo, void *userdata);
+
+#endif
+
diff --git a/thirdparty/sdl/filesystem/windows/SDL_sysfilesystem.c b/thirdparty/sdl/filesystem/windows/SDL_sysfilesystem.c
new file mode 100644
index 00000000000..dd836e25bc5
--- /dev/null
+++ b/thirdparty/sdl/filesystem/windows/SDL_sysfilesystem.c
@@ -0,0 +1,355 @@
+/*
+ Simple DirectMedia Layer
+ Copyright (C) 1997-2026 Sam Lantinga <[email protected]>
+
+ 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"
+
+#ifdef SDL_FILESYSTEM_WINDOWS
+
+/* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * */
+// System dependent filesystem routines
+
+#include "../SDL_sysfilesystem.h"
+
+#include "../../core/windows/SDL_windows.h"
+#include <shlobj.h>
+#include <initguid.h>
+
+// These aren't all defined in older SDKs, so define them here
+DEFINE_GUID(SDL_FOLDERID_Profile, 0x5E6C858F, 0x0E22, 0x4760, 0x9A, 0xFE, 0xEA, 0x33, 0x17, 0xB6, 0x71, 0x73);
+DEFINE_GUID(SDL_FOLDERID_Desktop, 0xB4BFCC3A, 0xDB2C, 0x424C, 0xB0, 0x29, 0x7F, 0xE9, 0x9A, 0x87, 0xC6, 0x41);
+DEFINE_GUID(SDL_FOLDERID_Documents, 0xFDD39AD0, 0x238F, 0x46AF, 0xAD, 0xB4, 0x6C, 0x85, 0x48, 0x03, 0x69, 0xC7);
+DEFINE_GUID(SDL_FOLDERID_Downloads, 0x374de290, 0x123f, 0x4565, 0x91, 0x64, 0x39, 0xc4, 0x92, 0x5e, 0x46, 0x7b);
+DEFINE_GUID(SDL_FOLDERID_Music, 0x4BD8D571, 0x6D19, 0x48D3, 0xBE, 0x97, 0x42, 0x22, 0x20, 0x08, 0x0E, 0x43);
+DEFINE_GUID(SDL_FOLDERID_Pictures, 0x33E28130, 0x4E1E, 0x4676, 0x83, 0x5A, 0x98, 0x39, 0x5C, 0x3B, 0xC3, 0xBB);
+DEFINE_GUID(SDL_FOLDERID_SavedGames, 0x4c5c32ff, 0xbb9d, 0x43b0, 0xb5, 0xb4, 0x2d, 0x72, 0xe5, 0x4e, 0xaa, 0xa4);
+DEFINE_GUID(SDL_FOLDERID_Screenshots, 0xb7bede81, 0xdf94, 0x4682, 0xa7, 0xd8, 0x57, 0xa5, 0x26, 0x20, 0xb8, 0x6f);
+DEFINE_GUID(SDL_FOLDERID_Templates, 0xA63293E8, 0x664E, 0x48DB, 0xA0, 0x79, 0xDF, 0x75, 0x9E, 0x05, 0x09, 0xF7);
+DEFINE_GUID(SDL_FOLDERID_Videos, 0x18989B1D, 0x99B5, 0x455B, 0x84, 0x1C, 0xAB, 0x7C, 0x74, 0xE4, 0xDD, 0xFC);
+
+char *SDL_SYS_GetBasePath(void)
+{
+ char *path = WIN_GetModulePath(NULL); // look up full path of the current process's EXE file.
+ if (!path) {
+ return NULL; // error message was already set.
+ }
+
+ char *ptr = SDL_strrchr(path, '\\');
+ SDL_assert(ptr != NULL); // Should have been an absolute path.
+
+ ptr[1] = '\0'; // chop off filename, leave '\\'.
+
+ ptr = (char *) SDL_realloc(path, ((size_t) (ptr - path)) + 2); // try to shrink this allocation down a little.
+ return ptr ? ptr : path; // return shrunk buffer if shrink worked out, unchanged original buffer if not.
+}
+
+char *SDL_SYS_GetExeName(void)
+{
+ char *path = WIN_GetModulePath(NULL); // look up full path of the current process's EXE file.
+ if (!path) {
+ return NULL; // error message was already set.
+ }
+
+ char *ptr = SDL_strrchr(path, '\\');
+ const size_t slen = SDL_strlen(ptr); // counts null terminator because we're still sitting on path separator.
+ SDL_memmove(path, ptr + 1, slen); // move filename string to start of SDL_realloc'd region.
+ ptr = (char *) SDL_realloc(path, slen); // try to shrink this allocation down a little.
+ return ptr ? ptr : path; // return shrunk buffer if shrink worked out, unchanged original buffer if not.
+}
+
+char *SDL_SYS_GetPrefPath(const char *org, const char *app)
+{
+ /*
+ * Vista and later has a new API for this, but SHGetFolderPath works there,
+ * and apparently just wraps the new API. This is the new way to do it:
+ *
+ * SHGetKnownFolderPath(SDL_FOLDERID_RoamingAppData, KF_FLAG_CREATE,
+ * NULL, &wszPath);
+ */
+
+ HRESULT hr = E_FAIL;
+ WCHAR path[MAX_PATH];
+ char *result = NULL;
+ WCHAR *worg = NULL;
+ WCHAR *wapp = NULL;
+ size_t new_wpath_len = 0;
+ BOOL api_result = FALSE;
+
+ hr = SHGetFolderPathW(NULL, CSIDL_APPDATA | CSIDL_FLAG_CREATE, NULL, 0, path);
+ if (!SUCCEEDED(hr)) {
+ WIN_SetErrorFromHRESULT("Couldn't locate our prefpath", hr);
+ return NULL;
+ }
+
+ worg = WIN_UTF8ToStringW(org);
+ if (!worg) {
+ return NULL;
+ }
+
+ wapp = WIN_UTF8ToStringW(app);
+ if (!wapp) {
+ SDL_free(worg);
+ return NULL;
+ }
+
+ new_wpath_len = SDL_wcslen(worg) + SDL_wcslen(wapp) + SDL_wcslen(path) + 3;
+
+ if ((new_wpath_len + 1) > MAX_PATH) {
+ SDL_free(worg);
+ SDL_free(wapp);
+ WIN_SetError("Path too long.");
+ return NULL;
+ }
+
+ if (*worg) {
+ SDL_wcslcat(path, L"\\", SDL_arraysize(path));
+ SDL_wcslcat(path, worg, SDL_arraysize(path));
+ }
+ SDL_free(worg);
+
+ api_result = CreateDirectoryW(path, NULL);
+ if (api_result == FALSE) {
+ if (GetLastError() != ERROR_ALREADY_EXISTS) {
+ SDL_free(wapp);
+ WIN_SetError("Couldn't create a prefpath.");
+ return NULL;
+ }
+ }
+
+ SDL_wcslcat(path, L"\\", SDL_arraysize(path));
+ SDL_wcslcat(path, wapp, SDL_arraysize(path));
+ SDL_free(wapp);
+
+ api_result = CreateDirectoryW(path, NULL);
+ if (api_result == FALSE) {
+ if (GetLastError() != ERROR_ALREADY_EXISTS) {
+ WIN_SetError("Couldn't create a prefpath.");
+ return NULL;
+ }
+ }
+
+ SDL_wcslcat(path, L"\\", SDL_arraysize(path));
+
+ result = WIN_StringToUTF8W(path);
+
+ return result;
+}
+
+char *SDL_SYS_GetUserFolder(SDL_Folder folder)
+{
+ typedef HRESULT (WINAPI *pfnSHGetKnownFolderPath)(REFGUID /* REFKNOWNFOLDERID */, DWORD, HANDLE, PWSTR*);
+ HMODULE lib = LoadLibraryW(L"Shell32.dll");
+ pfnSHGetKnownFolderPath pSHGetKnownFolderPath = NULL;
+ char *result = NULL;
+
+ if (lib) {
+ pSHGetKnownFolderPath = (pfnSHGetKnownFolderPath)GetProcAddress(lib, "SHGetKnownFolderPath");
+ }
+
+ if (pSHGetKnownFolderPath) {
+ GUID type; // KNOWNFOLDERID
+ HRESULT hr;
+ wchar_t *path;
+
+ switch (folder) {
+ case SDL_FOLDER_HOME:
+ type = SDL_FOLDERID_Profile;
+ break;
+
+ case SDL_FOLDER_DESKTOP:
+ type = SDL_FOLDERID_Desktop;
+ break;
+
+ case SDL_FOLDER_DOCUMENTS:
+ type = SDL_FOLDERID_Documents;
+ break;
+
+ case SDL_FOLDER_DOWNLOADS:
+ type = SDL_FOLDERID_Downloads;
+ break;
+
+ case SDL_FOLDER_MUSIC:
+ type = SDL_FOLDERID_Music;
+ break;
+
+ case SDL_FOLDER_PICTURES:
+ type = SDL_FOLDERID_Pictures;
+ break;
+
+ case SDL_FOLDER_PUBLICSHARE:
+ SDL_SetError("Public share unavailable on Windows");
+ goto done;
+
+ case SDL_FOLDER_SAVEDGAMES:
+ type = SDL_FOLDERID_SavedGames;
+ break;
+
+ case SDL_FOLDER_SCREENSHOTS:
+ type = SDL_FOLDERID_Screenshots;
+ break;
+
+ case SDL_FOLDER_TEMPLATES:
+ type = SDL_FOLDERID_Templates;
+ break;
+
+ case SDL_FOLDER_VIDEOS:
+ type = SDL_FOLDERID_Videos;
+ break;
+
+ default:
+ SDL_SetError("Invalid SDL_Folder: %d", (int)folder);
+ goto done;
+ };
+
+ hr = pSHGetKnownFolderPath(&type, 0x00008000 /* KF_FLAG_CREATE */, NULL, &path);
+ if (SUCCEEDED(hr)) {
+ result = WIN_StringToUTF8W(path);
+ } else {
+ WIN_SetErrorFromHRESULT("Couldn't get folder", hr);
+ }
+
+ } else {
+ int type;
+ HRESULT hr;
+ wchar_t path[MAX_PATH];
+
+ switch (folder) {
+ case SDL_FOLDER_HOME:
+ type = CSIDL_PROFILE;
+ break;
+
+ case SDL_FOLDER_DESKTOP:
+ type = CSIDL_DESKTOP;
+ break;
+
+ case SDL_FOLDER_DOCUMENTS:
+ type = CSIDL_MYDOCUMENTS;
+ break;
+
+ case SDL_FOLDER_DOWNLOADS:
+ SDL_SetError("Downloads folder unavailable before Vista");
+ goto done;
+
+ case SDL_FOLDER_MUSIC:
+ type = CSIDL_MYMUSIC;
+ break;
+
+ case SDL_FOLDER_PICTURES:
+ type = CSIDL_MYPICTURES;
+ break;
+
+ case SDL_FOLDER_PUBLICSHARE:
+ SDL_SetError("Public share unavailable on Windows");
+ goto done;
+
+ case SDL_FOLDER_SAVEDGAMES:
+ SDL_SetError("Saved games unavailable before Vista");
+ goto done;
+
+ case SDL_FOLDER_SCREENSHOTS:
+ SDL_SetError("Screenshots folder unavailable before Vista");
+ goto done;
+
+ case SDL_FOLDER_TEMPLATES:
+ type = CSIDL_TEMPLATES;
+ break;
+
+ case SDL_FOLDER_VIDEOS:
+ type = CSIDL_MYVIDEO;
+ break;
+
+ default:
+ SDL_SetError("Unsupported SDL_Folder on Windows before Vista: %d", (int)folder);
+ goto done;
+ };
+
+ // Create the OS-specific folder if it doesn't already exist
+ type |= CSIDL_FLAG_CREATE;
+
+#if 0
+ // Apparently the oldest, but not supported in modern Windows
+ HRESULT hr = SHGetSpecialFolderPath(NULL, path, type, TRUE);
+#endif
+
+ /* Windows 2000/XP and later, deprecated as of Windows 10 (still
+ available), available in Wine (tested 6.0.3) */
+ hr = SHGetFolderPathW(NULL, type, NULL, SHGFP_TYPE_CURRENT, path);
+
+ // use `== TRUE` for SHGetSpecialFolderPath
+ if (SUCCEEDED(hr)) {
+ result = WIN_StringToUTF8W(path);
+ } else {
+ WIN_SetErrorFromHRESULT("Couldn't get folder", hr);
+ }
+ }
+
+ if (result) {
+ char *newresult = (char *) SDL_realloc(result, SDL_strlen(result) + 2);
+
+ if (!newresult) {
+ SDL_free(result);
+ result = NULL; // will be returned
+ goto done;
+ }
+
+ result = newresult;
+ SDL_strlcat(result, "\\", SDL_strlen(result) + 2);
+ }
+
+done:
+ if (lib) {
+ FreeLibrary(lib);
+ }
+ return result;
+}
+
+char *SDL_SYS_GetCurrentDirectory(void)
+{
+ WCHAR *wstr = NULL;
+ DWORD buflen = 0;
+ while (true) {
+ const DWORD bw = GetCurrentDirectoryW(buflen, wstr);
+ if (bw == 0) {
+ WIN_SetError("GetCurrentDirectoryW failed");
+ return NULL;
+ } else if (bw < buflen) { // we got it!
+ // make sure there's a path separator at the end.
+ SDL_assert(bw < (buflen + 2));
+ if ((bw == 0) || (wstr[bw-1] != '\\')) {
+ wstr[bw] = '\\';
+ wstr[bw + 1] = '\0';
+ }
+ break;
+ }
+
+ void *ptr = SDL_realloc(wstr, (bw + 1) * sizeof (WCHAR));
+ if (!ptr) {
+ SDL_free(wstr);
+ return NULL;
+ }
+ wstr = (WCHAR *) ptr;
+ buflen = bw;
+ }
+
+ char *retval = WIN_StringToUTF8W(wstr);
+ SDL_free(wstr);
+ return retval;
+}
+
+#endif // SDL_FILESYSTEM_WINDOWS
diff --git a/thirdparty/sdl/filesystem/windows/SDL_sysfsops.c b/thirdparty/sdl/filesystem/windows/SDL_sysfsops.c
new file mode 100644
index 00000000000..f0fc0fd9594
--- /dev/null
+++ b/thirdparty/sdl/filesystem/windows/SDL_sysfsops.c
@@ -0,0 +1,235 @@
+/*
+ Simple DirectMedia Layer
+ Copyright (C) 1997-2026 Sam Lantinga <[email protected]>
+
+ 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"
+
+#if defined(SDL_FSOPS_WINDOWS)
+
+/* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * */
+// System dependent filesystem routines
+
+#include "../../core/windows/SDL_windows.h"
+#include "../SDL_sysfilesystem.h"
+
+#ifndef COPY_FILE_NO_BUFFERING
+#define COPY_FILE_NO_BUFFERING 0x00001000
+#endif
+
+bool SDL_SYS_EnumerateDirectory(const char *path, SDL_EnumerateDirectoryCallback cb, void *userdata)
+{
+ SDL_EnumerationResult result = SDL_ENUM_CONTINUE;
+ if (*path == '\0') { // if empty (completely at the root), we need to enumerate drive letters.
+ const DWORD drives = GetLogicalDrives();
+ char name[] = { 0, ':', '\\', '\0' };
+ for (int i = 'A'; (result == SDL_ENUM_CONTINUE) && (i <= 'Z'); i++) {
+ if (drives & (1 << (i - 'A'))) {
+ name[0] = (char) i;
+ result = cb(userdata, "", name);
+ }
+ }
+ } else {
+ // you need a wildcard to enumerate through FindFirstFileEx(), but the wildcard is only checked in the
+ // filename element at the end of the path string, so always tack on a "\\*" to get everything, and
+ // also prevent any wildcards inserted by the app from being respected.
+ char *pattern = NULL;
+ int patternlen = SDL_asprintf(&pattern, "%s\\\\", path); // we'll replace that second '\\' in the trimdown.
+ if ((patternlen == -1) || (!pattern)) {
+ return false;
+ }
+
+ // trim down to a single path separator at the end, in case the caller added one or more.
+ patternlen--;
+ while ((patternlen > 0) && ((pattern[patternlen] == '\\') || (pattern[patternlen] == '/'))) {
+ pattern[patternlen--] ='\0';
+ }
+ pattern[++patternlen] = '\\';
+ pattern[++patternlen] = '*';
+ pattern[++patternlen] = '\0';
+
+ WCHAR *wpattern = WIN_UTF8ToStringW(pattern);
+ if (!wpattern) {
+ SDL_free(pattern);
+ return false;
+ }
+
+ pattern[--patternlen] = '\0'; // chop off the '*' so we just have the dirname with a path separator.
+
+ WIN32_FIND_DATAW entw;
+ HANDLE dir = FindFirstFileExW(wpattern, FindExInfoStandard, &entw, FindExSearchNameMatch, NULL, 0);
+ SDL_free(wpattern);
+ if (dir == INVALID_HANDLE_VALUE) {
+ SDL_free(pattern);
+ return WIN_SetError("Failed to enumerate directory");
+ }
+
+ do {
+ const WCHAR *fn = entw.cFileName;
+
+ if (fn[0] == '.') { // ignore "." and ".."
+ if ((fn[1] == '\0') || ((fn[1] == '.') && (fn[2] == '\0'))) {
+ continue;
+ }
+ }
+
+ char *utf8fn = WIN_StringToUTF8W(fn);
+ if (!utf8fn) {
+ result = SDL_ENUM_FAILURE;
+ } else {
+ result = cb(userdata, pattern, utf8fn);
+ SDL_free(utf8fn);
+ }
+ } while ((result == SDL_ENUM_CONTINUE) && (FindNextFileW(dir, &entw) != 0));
+
+ FindClose(dir);
+ SDL_free(pattern);
+ }
+
+ return (result != SDL_ENUM_FAILURE);
+}
+
+bool SDL_SYS_RemovePath(const char *path)
+{
+ WCHAR *wpath = WIN_UTF8ToStringW(path);
+ if (!wpath) {
+ return false;
+ }
+
+ WIN32_FILE_ATTRIBUTE_DATA info;
+ if (!GetFileAttributesExW(wpath, GetFileExInfoStandard, &info)) {
+ SDL_free(wpath);
+ if (GetLastError() == ERROR_FILE_NOT_FOUND) {
+ // Note that ERROR_PATH_NOT_FOUND means a parent dir is missing, and we consider that an error.
+ return true; // thing is already gone, call it a success.
+ }
+ return WIN_SetError("Couldn't get path's attributes");
+ }
+
+ const int isdir = (info.dwFileAttributes & FILE_ATTRIBUTE_DIRECTORY);
+ const BOOL rc = isdir ? RemoveDirectoryW(wpath) : DeleteFileW(wpath);
+ SDL_free(wpath);
+ if (!rc) {
+ return WIN_SetError("Couldn't remove path");
+ }
+ return true;
+}
+
+bool SDL_SYS_RenamePath(const char *oldpath, const char *newpath)
+{
+ WCHAR *woldpath = WIN_UTF8ToStringW(oldpath);
+ if (!woldpath) {
+ return false;
+ }
+
+ WCHAR *wnewpath = WIN_UTF8ToStringW(newpath);
+ if (!wnewpath) {
+ SDL_free(woldpath);
+ return false;
+ }
+
+ const BOOL rc = MoveFileExW(woldpath, wnewpath, MOVEFILE_REPLACE_EXISTING);
+ SDL_free(wnewpath);
+ SDL_free(woldpath);
+ if (!rc) {
+ return WIN_SetError("Couldn't rename path");
+ }
+ return true;
+}
+
+bool SDL_SYS_CopyFile(const char *oldpath, const char *newpath)
+{
+ WCHAR *woldpath = WIN_UTF8ToStringW(oldpath);
+ if (!woldpath) {
+ return false;
+ }
+
+ WCHAR *wnewpath = WIN_UTF8ToStringW(newpath);
+ if (!wnewpath) {
+ SDL_free(woldpath);
+ return false;
+ }
+
+ const BOOL rc = CopyFileExW(woldpath, wnewpath, NULL, NULL, NULL, COPY_FILE_ALLOW_DECRYPTED_DESTINATION|COPY_FILE_NO_BUFFERING);
+ SDL_free(wnewpath);
+ SDL_free(woldpath);
+ if (!rc) {
+ return WIN_SetError("Couldn't copy path");
+ }
+ return true;
+}
+
+bool SDL_SYS_CreateDirectory(const char *path)
+{
+ WCHAR *wpath = WIN_UTF8ToStringW(path);
+ if (!wpath) {
+ return false;
+ }
+
+ DWORD rc = CreateDirectoryW(wpath, NULL);
+ if (!rc && (GetLastError() == ERROR_ALREADY_EXISTS)) {
+ WIN32_FILE_ATTRIBUTE_DATA winstat;
+ if (GetFileAttributesExW(wpath, GetFileExInfoStandard, &winstat)) {
+ if (winstat.dwFileAttributes & FILE_ATTRIBUTE_DIRECTORY) {
+ rc = 1; // exists and is already a directory: cool.
+ }
+ }
+ }
+
+ SDL_free(wpath);
+ if (!rc) {
+ return WIN_SetError("Couldn't create directory");
+ }
+ return true;
+}
+
+bool SDL_SYS_GetPathInfo(const char *path, SDL_PathInfo *info)
+{
+ WCHAR *wpath = WIN_UTF8ToStringW(path);
+ if (!wpath) {
+ return false;
+ }
+
+ WIN32_FILE_ATTRIBUTE_DATA winstat;
+ const BOOL rc = GetFileAttributesExW(wpath, GetFileExInfoStandard, &winstat);
+ SDL_free(wpath);
+ if (!rc) {
+ return WIN_SetError("Can't stat");
+ }
+
+ if (winstat.dwFileAttributes & FILE_ATTRIBUTE_DIRECTORY) {
+ info->type = SDL_PATHTYPE_DIRECTORY;
+ info->size = 0;
+ } else if (winstat.dwFileAttributes & (FILE_ATTRIBUTE_OFFLINE | FILE_ATTRIBUTE_DEVICE)) {
+ info->type = SDL_PATHTYPE_OTHER;
+ info->size = ((((Uint64) winstat.nFileSizeHigh) << 32) | winstat.nFileSizeLow);
+ } else {
+ info->type = SDL_PATHTYPE_FILE;
+ info->size = ((((Uint64) winstat.nFileSizeHigh) << 32) | winstat.nFileSizeLow);
+ }
+
+ info->create_time = SDL_TimeFromWindows(winstat.ftCreationTime.dwLowDateTime, winstat.ftCreationTime.dwHighDateTime);
+ info->modify_time = SDL_TimeFromWindows(winstat.ftLastWriteTime.dwLowDateTime, winstat.ftLastWriteTime.dwHighDateTime);
+ info->access_time = SDL_TimeFromWindows(winstat.ftLastAccessTime.dwLowDateTime, winstat.ftLastAccessTime.dwHighDateTime);
+
+ return true;
+}
+
+#endif // SDL_FSOPS_WINDOWS
+
diff --git a/thirdparty/sdl/haptic/SDL_haptic.c b/thirdparty/sdl/haptic/SDL_haptic.c
index 1c11db68643..577502c922c 100644
--- a/thirdparty/sdl/haptic/SDL_haptic.c
+++ b/thirdparty/sdl/haptic/SDL_haptic.c
@@ -1,6 +1,6 @@
/*
Simple DirectMedia Layer
- Copyright (C) 1997-2025 Sam Lantinga <[email protected]>
+ Copyright (C) 1997-2026 Sam Lantinga <[email protected]>
This software is provided 'as-is', without any express or implied
warranty. In no event will the authors be held liable for any damages
@@ -21,6 +21,9 @@
#include "SDL_internal.h"
#include "SDL_syshaptic.h"
+#ifdef SDL_JOYSTICK_HIDAPI
+#include "hidapi/SDL_hidapihaptic.h"
+#endif
#include "SDL_haptic_c.h"
#include "../joystick/SDL_joystick_c.h" // For SDL_IsJoystickValid
#include "../SDL_hints_c.h"
@@ -104,15 +107,25 @@ static int SDL_Haptic_Get_Naxes(Uint16 vid, Uint16 pid)
static SDL_Haptic *SDL_haptics = NULL;
-#define CHECK_HAPTIC_MAGIC(haptic, result) \
- if (!SDL_ObjectValid(haptic, SDL_OBJECT_TYPE_HAPTIC)) { \
- SDL_InvalidParamError("haptic"); \
- return result; \
+#define CHECK_HAPTIC_MAGIC(haptic, result) \
+ CHECK_PARAM(!SDL_ObjectValid(haptic, SDL_OBJECT_TYPE_HAPTIC)) { \
+ SDL_InvalidParamError("haptic"); \
+ return result; \
}
bool SDL_InitHaptics(void)
{
- return SDL_SYS_HapticInit();
+ if (!SDL_SYS_HapticInit()) {
+ return false;
+ }
+ #ifdef SDL_JOYSTICK_HIDAPI
+ if (!SDL_HIDAPI_HapticInit()) {
+ SDL_SYS_HapticQuit();
+ return false;
+ }
+ #endif
+
+ return true;
}
static bool SDL_GetHapticIndex(SDL_HapticID instance_id, int *driver_index)
@@ -205,7 +218,6 @@ SDL_Haptic *SDL_OpenHaptic(SDL_HapticID instance_id)
}
// Initialize the haptic device
- SDL_SetObjectValid(haptic, SDL_OBJECT_TYPE_HAPTIC, true);
haptic->instance_id = instance_id;
haptic->rumble_id = -1;
if (!SDL_SYS_HapticOpen(haptic)) {
@@ -227,6 +239,8 @@ SDL_Haptic *SDL_OpenHaptic(SDL_HapticID instance_id)
haptic->next = SDL_haptics;
SDL_haptics = haptic;
+ SDL_SetObjectValid(haptic, SDL_OBJECT_TYPE_HAPTIC, true);
+
// Disable autocenter and set gain to max.
if (haptic->supported & SDL_HAPTIC_GAIN) {
SDL_SetHapticGain(haptic, 100);
@@ -292,10 +306,14 @@ bool SDL_IsJoystickHaptic(SDL_Joystick *joystick)
SDL_LockJoysticks();
{
- // Must be a valid joystick
+ // Must be a valid joystick, but not a gamepad unless running under sdl2-compat
if (SDL_IsJoystickValid(joystick) &&
- !SDL_IsGamepad(SDL_GetJoystickID(joystick))) {
+ (SDL_GetHintBoolean("SDL2_COMPAT", false) || !SDL_IsGamepad(SDL_GetJoystickID(joystick)))) {
+ #ifdef SDL_JOYSTICK_HIDAPI
+ result = SDL_SYS_JoystickIsHaptic(joystick) || SDL_HIDAPI_JoystickIsHaptic(joystick);
+ #else
result = SDL_SYS_JoystickIsHaptic(joystick);
+ #endif
}
}
SDL_UnlockJoysticks();
@@ -310,16 +328,8 @@ SDL_Haptic *SDL_OpenHapticFromJoystick(SDL_Joystick *joystick)
SDL_LockJoysticks();
{
- // Must be a valid joystick
- if (!SDL_IsJoystickValid(joystick)) {
- SDL_SetError("Haptic: Joystick isn't valid.");
- SDL_UnlockJoysticks();
- return NULL;
- }
-
- // Joystick must be haptic
- if (SDL_IsGamepad(SDL_GetJoystickID(joystick)) ||
- !SDL_SYS_JoystickIsHaptic(joystick)) {
+ // Joystick must be valid and haptic
+ if (!SDL_IsJoystickHaptic(joystick)) {
SDL_SetError("Haptic: Joystick isn't a haptic device.");
SDL_UnlockJoysticks();
return NULL;
@@ -328,7 +338,11 @@ SDL_Haptic *SDL_OpenHapticFromJoystick(SDL_Joystick *joystick)
hapticlist = SDL_haptics;
// Check to see if joystick's haptic is already open
while (hapticlist) {
+ #ifdef SDL_JOYSTICK_HIDAPI
+ if (SDL_SYS_JoystickSameHaptic(hapticlist, joystick) || SDL_HIDAPI_JoystickSameHaptic(hapticlist, joystick)) {
+ #else
if (SDL_SYS_JoystickSameHaptic(hapticlist, joystick)) {
+ #endif
haptic = hapticlist;
++haptic->ref_count;
SDL_UnlockJoysticks();
@@ -349,6 +363,16 @@ SDL_Haptic *SDL_OpenHapticFromJoystick(SDL_Joystick *joystick)
*/
SDL_SetObjectValid(haptic, SDL_OBJECT_TYPE_HAPTIC, true);
haptic->rumble_id = -1;
+ #ifdef SDL_JOYSTICK_HIDAPI
+ if (SDL_HIDAPI_JoystickIsHaptic(joystick)) {
+ if (!SDL_HIDAPI_HapticOpenFromJoystick(haptic, joystick)) {
+ SDL_SetError("Haptic: SDL_HIDAPI_HapticOpenFromJoystick failed.");
+ SDL_free(haptic);
+ SDL_UnlockJoysticks();
+ return NULL;
+ }
+ } else
+ #endif
if (!SDL_SYS_HapticOpenFromJoystick(haptic, joystick)) {
SDL_SetError("Haptic: SDL_SYS_HapticOpenFromJoystick failed.");
SDL_SetObjectValid(haptic, SDL_OBJECT_TYPE_HAPTIC, false);
@@ -379,12 +403,22 @@ SDL_Haptic *SDL_OpenHapticFromJoystick(SDL_Joystick *joystick)
haptic->next = SDL_haptics;
SDL_haptics = haptic;
+ SDL_SetObjectValid(haptic, SDL_OBJECT_TYPE_HAPTIC, true);
+
+ // Disable autocenter and set gain to max.
+ if (haptic->supported & SDL_HAPTIC_GAIN) {
+ SDL_SetHapticGain(haptic, 100);
+ }
+ if (haptic->supported & SDL_HAPTIC_AUTOCENTER) {
+ SDL_SetHapticAutocenter(haptic, 0);
+ }
+
return haptic;
}
void SDL_CloseHaptic(SDL_Haptic *haptic)
{
- int i;
+ SDL_HapticEffectID i;
SDL_Haptic *hapticlist;
SDL_Haptic *hapticlistprev;
@@ -395,13 +429,20 @@ void SDL_CloseHaptic(SDL_Haptic *haptic)
return;
}
- // Close it, properly removing effects if needed
- for (i = 0; i < haptic->neffects; i++) {
- if (haptic->effects[i].hweffect != NULL) {
- SDL_DestroyHapticEffect(haptic, i);
+ #ifdef SDL_JOYSTICK_HIDAPI
+ if (SDL_HIDAPI_HapticIsHidapi(haptic)) {
+ SDL_HIDAPI_HapticClose(haptic);
+ } else
+ #endif
+ {
+ // Close it, properly removing effects if needed
+ for (i = 0; i < haptic->neffects; i++) {
+ if (haptic->effects[i].hweffect != NULL) {
+ SDL_DestroyHapticEffect(haptic, i);
+ }
}
+ SDL_SYS_HapticClose(haptic);
}
- SDL_SYS_HapticClose(haptic);
SDL_SetObjectValid(haptic, SDL_OBJECT_TYPE_HAPTIC, false);
// Remove from the list
@@ -433,6 +474,9 @@ void SDL_QuitHaptics(void)
SDL_CloseHaptic(SDL_haptics);
}
+ #ifdef SDL_JOYSTICK_HIDAPI
+ SDL_HIDAPI_HapticQuit();
+ #endif
SDL_SYS_HapticQuit();
}
@@ -468,7 +512,7 @@ bool SDL_HapticEffectSupported(SDL_Haptic *haptic, const SDL_HapticEffect *effec
{
CHECK_HAPTIC_MAGIC(haptic, false);
- if (!effect) {
+ CHECK_PARAM(!effect) {
return false;
}
@@ -478,13 +522,13 @@ bool SDL_HapticEffectSupported(SDL_Haptic *haptic, const SDL_HapticEffect *effec
return false;
}
-int SDL_CreateHapticEffect(SDL_Haptic *haptic, const SDL_HapticEffect *effect)
+SDL_HapticEffectID SDL_CreateHapticEffect(SDL_Haptic *haptic, const SDL_HapticEffect *effect)
{
- int i;
+ SDL_HapticEffectID i;
CHECK_HAPTIC_MAGIC(haptic, -1);
- if (!effect) {
+ CHECK_PARAM(!effect) {
SDL_InvalidParamError("effect");
return -1;
}
@@ -495,6 +539,12 @@ int SDL_CreateHapticEffect(SDL_Haptic *haptic, const SDL_HapticEffect *effect)
return -1;
}
+ #ifdef SDL_JOYSTICK_HIDAPI
+ if (SDL_HIDAPI_HapticIsHidapi(haptic)) {
+ return SDL_HIDAPI_HapticNewEffect(haptic, effect);
+ }
+ #endif
+
// See if there's a free slot
for (i = 0; i < haptic->neffects; i++) {
if (haptic->effects[i].hweffect == NULL) {
@@ -514,7 +564,7 @@ int SDL_CreateHapticEffect(SDL_Haptic *haptic, const SDL_HapticEffect *effect)
return -1;
}
-static bool ValidEffect(SDL_Haptic *haptic, int effect)
+static bool ValidEffect(SDL_Haptic *haptic, SDL_HapticEffectID effect)
{
if ((effect < 0) || (effect >= haptic->neffects)) {
SDL_SetError("Haptic: Invalid effect identifier.");
@@ -523,23 +573,29 @@ static bool ValidEffect(SDL_Haptic *haptic, int effect)
return true;
}
-bool SDL_UpdateHapticEffect(SDL_Haptic *haptic, int effect, const SDL_HapticEffect *data)
+bool SDL_UpdateHapticEffect(SDL_Haptic *haptic, SDL_HapticEffectID effect, const SDL_HapticEffect *data)
{
CHECK_HAPTIC_MAGIC(haptic, false);
- if (!ValidEffect(haptic, effect)) {
+ CHECK_PARAM(!ValidEffect(haptic, effect)) {
return false;
}
- if (!data) {
+ CHECK_PARAM(!data) {
return SDL_InvalidParamError("data");
}
// Can't change type dynamically.
- if (data->type != haptic->effects[effect].effect.type) {
+ CHECK_PARAM(data->type != haptic->effects[effect].effect.type) {
return SDL_SetError("Haptic: Updating effect type is illegal.");
}
+ #ifdef SDL_JOYSTICK_HIDAPI
+ if (SDL_HIDAPI_HapticIsHidapi(haptic)) {
+ return SDL_HIDAPI_HapticUpdateEffect(haptic, effect, data);
+ }
+ #endif
+
// Updates the effect
if (!SDL_SYS_HapticUpdateEffect(haptic, &haptic->effects[effect], data)) {
return false;
@@ -550,10 +606,16 @@ bool SDL_UpdateHapticEffect(SDL_Haptic *haptic, int effect, const SDL_HapticEffe
return true;
}
-bool SDL_RunHapticEffect(SDL_Haptic *haptic, int effect, Uint32 iterations)
+bool SDL_RunHapticEffect(SDL_Haptic *haptic, SDL_HapticEffectID effect, Uint32 iterations)
{
CHECK_HAPTIC_MAGIC(haptic, false);
+ #ifdef SDL_JOYSTICK_HIDAPI
+ if (SDL_HIDAPI_HapticIsHidapi(haptic)) {
+ return SDL_HIDAPI_HapticRunEffect(haptic, effect, iterations);
+ }
+ #endif
+
if (!ValidEffect(haptic, effect)) {
return false;
}
@@ -566,10 +628,16 @@ bool SDL_RunHapticEffect(SDL_Haptic *haptic, int effect, Uint32 iterations)
return true;
}
-bool SDL_StopHapticEffect(SDL_Haptic *haptic, int effect)
+bool SDL_StopHapticEffect(SDL_Haptic *haptic, SDL_HapticEffectID effect)
{
CHECK_HAPTIC_MAGIC(haptic, false);
+ #ifdef SDL_JOYSTICK_HIDAPI
+ if (SDL_HIDAPI_HapticIsHidapi(haptic)) {
+ return SDL_HIDAPI_HapticStopEffect(haptic, effect);
+ }
+ #endif
+
if (!ValidEffect(haptic, effect)) {
return false;
}
@@ -582,10 +650,17 @@ bool SDL_StopHapticEffect(SDL_Haptic *haptic, int effect)
return true;
}
-void SDL_DestroyHapticEffect(SDL_Haptic *haptic, int effect)
+void SDL_DestroyHapticEffect(SDL_Haptic *haptic, SDL_HapticEffectID effect)
{
CHECK_HAPTIC_MAGIC(haptic,);
+ #ifdef SDL_JOYSTICK_HIDAPI
+ if (SDL_HIDAPI_HapticIsHidapi(haptic)) {
+ SDL_HIDAPI_HapticDestroyEffect(haptic, effect);
+ return;
+ }
+ #endif
+
if (!ValidEffect(haptic, effect)) {
return;
}
@@ -598,10 +673,16 @@ void SDL_DestroyHapticEffect(SDL_Haptic *haptic, int effect)
SDL_SYS_HapticDestroyEffect(haptic, &haptic->effects[effect]);
}
-bool SDL_GetHapticEffectStatus(SDL_Haptic *haptic, int effect)
+bool SDL_GetHapticEffectStatus(SDL_Haptic *haptic, SDL_HapticEffectID effect)
{
CHECK_HAPTIC_MAGIC(haptic, false);
+ #ifdef SDL_JOYSTICK_HIDAPI
+ if (SDL_HIDAPI_HapticIsHidapi(haptic)) {
+ return SDL_HIDAPI_HapticGetEffectStatus(haptic, effect);
+ }
+ #endif
+
if (!ValidEffect(haptic, effect)) {
return false;
}
@@ -648,6 +729,12 @@ bool SDL_SetHapticGain(SDL_Haptic *haptic, int gain)
real_gain = gain;
}
+ #ifdef SDL_JOYSTICK_HIDAPI
+ if (SDL_HIDAPI_HapticIsHidapi(haptic)) {
+ return SDL_HIDAPI_HapticSetGain(haptic, real_gain);
+ }
+ #endif
+
return SDL_SYS_HapticSetGain(haptic, real_gain);
}
@@ -663,6 +750,12 @@ bool SDL_SetHapticAutocenter(SDL_Haptic *haptic, int autocenter)
return SDL_SetError("Haptic: Autocenter must be between 0 and 100.");
}
+ #ifdef SDL_JOYSTICK_HIDAPI
+ if (SDL_HIDAPI_HapticIsHidapi(haptic)) {
+ return SDL_HIDAPI_HapticSetAutocenter(haptic, autocenter);
+ }
+ #endif
+
return SDL_SYS_HapticSetAutocenter(haptic, autocenter);
}
@@ -674,6 +767,12 @@ bool SDL_PauseHaptic(SDL_Haptic *haptic)
return SDL_SetError("Haptic: Device does not support setting pausing.");
}
+ #ifdef SDL_JOYSTICK_HIDAPI
+ if (SDL_HIDAPI_HapticIsHidapi(haptic)) {
+ return SDL_HIDAPI_HapticPause(haptic);
+ }
+ #endif
+
return SDL_SYS_HapticPause(haptic);
}
@@ -685,6 +784,12 @@ bool SDL_ResumeHaptic(SDL_Haptic *haptic)
return true; // Not going to be paused, so we pretend it's unpaused.
}
+ #ifdef SDL_JOYSTICK_HIDAPI
+ if (SDL_HIDAPI_HapticIsHidapi(haptic)) {
+ return SDL_HIDAPI_HapticResume(haptic);
+ }
+ #endif
+
return SDL_SYS_HapticResume(haptic);
}
@@ -692,6 +797,12 @@ bool SDL_StopHapticEffects(SDL_Haptic *haptic)
{
CHECK_HAPTIC_MAGIC(haptic, false);
+ #ifdef SDL_JOYSTICK_HIDAPI
+ if (SDL_HIDAPI_HapticIsHidapi(haptic)) {
+ return SDL_HIDAPI_HapticStopAll(haptic);
+ }
+ #endif
+
return SDL_SYS_HapticStopAll(haptic);
}
diff --git a/thirdparty/sdl/haptic/SDL_haptic_c.h b/thirdparty/sdl/haptic/SDL_haptic_c.h
index 3f5ce873c64..0ccaf86627f 100644
--- a/thirdparty/sdl/haptic/SDL_haptic_c.h
+++ b/thirdparty/sdl/haptic/SDL_haptic_c.h
@@ -1,6 +1,6 @@
/*
Simple DirectMedia Layer
- Copyright (C) 1997-2025 Sam Lantinga <[email protected]>
+ Copyright (C) 1997-2026 Sam Lantinga <[email protected]>
This software is provided 'as-is', without any express or implied
warranty. In no event will the authors be held liable for any damages
diff --git a/thirdparty/sdl/haptic/SDL_syshaptic.h b/thirdparty/sdl/haptic/SDL_syshaptic.h
index ec60a71e78e..74e78f65a13 100644
--- a/thirdparty/sdl/haptic/SDL_syshaptic.h
+++ b/thirdparty/sdl/haptic/SDL_syshaptic.h
@@ -1,6 +1,6 @@
/*
Simple DirectMedia Layer
- Copyright (C) 1997-2025 Sam Lantinga <[email protected]>
+ Copyright (C) 1997-2026 Sam Lantinga <[email protected]>
This software is provided 'as-is', without any express or implied
warranty. In no event will the authors be held liable for any damages
@@ -52,7 +52,7 @@ struct SDL_Haptic
struct haptic_hwdata *hwdata; // Driver dependent
int ref_count; // Count for multiple opens
- int rumble_id; // ID of rumble effect for simple rumble API.
+ SDL_HapticEffectID rumble_id; // ID of rumble effect for simple rumble API.
SDL_HapticEffect rumble_effect; // Rumble effect.
struct SDL_Haptic *next; // pointer to next haptic we have allocated
};
diff --git a/thirdparty/sdl/haptic/darwin/SDL_syshaptic.c b/thirdparty/sdl/haptic/darwin/SDL_syshaptic.c
index b48a3feb71a..4034320686d 100644
--- a/thirdparty/sdl/haptic/darwin/SDL_syshaptic.c
+++ b/thirdparty/sdl/haptic/darwin/SDL_syshaptic.c
@@ -1,6 +1,6 @@
/*
Simple DirectMedia Layer
- Copyright (C) 1997-2025 Sam Lantinga <[email protected]>
+ Copyright (C) 1997-2026 Sam Lantinga <[email protected]>
This software is provided 'as-is', without any express or implied
warranty. In no event will the authors be held liable for any damages
@@ -785,7 +785,7 @@ static bool SDL_SYS_ToFFEFFECT(SDL_Haptic *haptic, FFEFFECT *dest, const SDL_Hap
DWORD *axes = NULL;
// Set global stuff.
- SDL_memset(dest, 0, sizeof(FFEFFECT));
+ SDL_zerop(dest);
dest->dwSize = sizeof(FFEFFECT); // Set the structure size.
dest->dwSamplePeriod = 0; // Not used by us.
dest->dwGain = 10000; // Gain is set globally, not locally.
@@ -1166,7 +1166,7 @@ bool SDL_SYS_HapticUpdateEffect(SDL_Haptic *haptic,
FFEFFECT temp;
// Get the effect.
- SDL_memset(&temp, 0, sizeof(FFEFFECT));
+ SDL_zero(temp);
if (!SDL_SYS_ToFFEFFECT(haptic, &temp, data)) {
goto err_update;
}
diff --git a/thirdparty/sdl/haptic/darwin/SDL_syshaptic_c.h b/thirdparty/sdl/haptic/darwin/SDL_syshaptic_c.h
index 03c67ec7e2c..0465cc2a9e8 100644
--- a/thirdparty/sdl/haptic/darwin/SDL_syshaptic_c.h
+++ b/thirdparty/sdl/haptic/darwin/SDL_syshaptic_c.h
@@ -1,6 +1,6 @@
/*
Simple DirectMedia Layer
- Copyright (C) 1997-2025 Sam Lantinga <[email protected]>
+ Copyright (C) 1997-2026 Sam Lantinga <[email protected]>
This software is provided 'as-is', without any express or implied
warranty. In no event will the authors be held liable for any damages
diff --git a/thirdparty/sdl/haptic/dummy/SDL_syshaptic.c b/thirdparty/sdl/haptic/dummy/SDL_syshaptic.c
index 81f711f0224..d44c05cb18e 100644
--- a/thirdparty/sdl/haptic/dummy/SDL_syshaptic.c
+++ b/thirdparty/sdl/haptic/dummy/SDL_syshaptic.c
@@ -1,6 +1,6 @@
/*
Simple DirectMedia Layer
- Copyright (C) 1997-2025 Sam Lantinga <[email protected]>
+ Copyright (C) 1997-2026 Sam Lantinga <[email protected]>
This software is provided 'as-is', without any express or implied
warranty. In no event will the authors be held liable for any damages
diff --git a/thirdparty/sdl/haptic/hidapi/SDL_hidapihaptic.c b/thirdparty/sdl/haptic/hidapi/SDL_hidapihaptic.c
new file mode 100644
index 00000000000..f9985fc1367
--- /dev/null
+++ b/thirdparty/sdl/haptic/hidapi/SDL_hidapihaptic.c
@@ -0,0 +1,318 @@
+/*
+ Simple DirectMedia Layer
+ Copyright (C) 2025 Katharine Chui <[email protected]>
+
+ 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"
+
+#ifdef SDL_JOYSTICK_HIDAPI
+
+#include "SDL_hidapihaptic.h"
+#include "SDL_hidapihaptic_c.h"
+#include "SDL3/SDL_mutex.h"
+#include "SDL3/SDL_error.h"
+
+typedef struct haptic_list_node
+{
+ SDL_Haptic *haptic;
+ struct haptic_list_node *next;
+} haptic_list_node;
+
+static haptic_list_node *haptic_list_head = NULL;
+static SDL_Mutex *haptic_list_mutex = NULL;
+
+static SDL_HIDAPI_HapticDriver *drivers[] = {
+ #ifdef SDL_HAPTIC_HIDAPI_LG4FF
+ &SDL_HIDAPI_HapticDriverLg4ff,
+ #endif
+ NULL
+};
+
+bool SDL_HIDAPI_HapticInit(void)
+{
+ haptic_list_head = NULL;
+ haptic_list_mutex = SDL_CreateMutex();
+ if (haptic_list_mutex == NULL) {
+ return SDL_OutOfMemory();
+ }
+ return true;
+}
+
+bool SDL_HIDAPI_HapticIsHidapi(SDL_Haptic *haptic)
+{
+ haptic_list_node *cur;
+ bool ret = false;
+
+ SDL_LockMutex(haptic_list_mutex);
+ cur = haptic_list_head;
+ while (cur != NULL) {
+ if (cur->haptic == haptic) {
+ ret = true;
+ break;
+ }
+ cur = cur->next;
+ }
+
+ SDL_UnlockMutex(haptic_list_mutex);
+
+ return ret;
+}
+
+
+bool SDL_HIDAPI_JoystickIsHaptic(SDL_Joystick *joystick)
+{
+ const int numdrivers = SDL_arraysize(drivers) - 1;
+ int i;
+
+ SDL_AssertJoysticksLocked();
+
+ if (joystick->driver != &SDL_HIDAPI_JoystickDriver) {
+ return false;
+ }
+
+ for (i = 0; i < numdrivers; ++i) {
+ if (drivers[i]->JoystickSupported(joystick)) {
+ return true;
+ }
+ }
+ return false;
+}
+
+bool SDL_HIDAPI_HapticOpenFromJoystick(SDL_Haptic *haptic, SDL_Joystick *joystick)
+{
+ const int numdrivers = SDL_arraysize(drivers) - 1;
+ int i;
+
+ SDL_AssertJoysticksLocked();
+
+ if (joystick->driver != &SDL_HIDAPI_JoystickDriver) {
+ return SDL_SetError("Cannot open hidapi haptic from non hidapi joystick");
+ }
+
+ for (i = 0; i < numdrivers; ++i) {
+ if (drivers[i]->JoystickSupported(joystick)) {
+ SDL_HIDAPI_HapticDevice *device;
+ haptic_list_node *list_node;
+ // the driver is responsible for calling SDL_SetError
+ void *ctx = drivers[i]->Open(joystick);
+ if (ctx == NULL) {
+ return false;
+ }
+
+ device = SDL_malloc(sizeof(SDL_HIDAPI_HapticDevice));
+ if (device == NULL) {
+ SDL_HIDAPI_HapticDevice temp;
+ temp.ctx = ctx;
+ temp.driver = drivers[i];
+ temp.joystick = joystick;
+ temp.driver->Close(&temp);
+ return SDL_OutOfMemory();
+ }
+
+ device->driver = drivers[i];
+ device->haptic = haptic;
+ device->joystick = joystick;
+ device->ctx = ctx;
+
+ list_node = SDL_malloc(sizeof(haptic_list_node));
+ if (list_node == NULL) {
+ device->driver->Close(device);
+ SDL_free(device);
+ return SDL_OutOfMemory();
+ }
+
+ haptic->hwdata = (struct haptic_hwdata *)device;
+
+ // this is outside of the syshaptic driver
+
+ haptic->neffects = device->driver->NumEffects(device);
+ haptic->nplaying = device->driver->NumEffectsPlaying(device);
+ haptic->supported = device->driver->GetFeatures(device);
+ haptic->naxes = device->driver->NumAxes(device);
+ haptic->neffects = device->driver->NumEffects(device);
+ haptic->effects = (struct haptic_effect *)SDL_malloc(sizeof(struct haptic_effect) * haptic->neffects);
+ if (haptic->effects == NULL) {
+ SDL_free(list_node);
+ device->driver->Close(device);
+ SDL_free(device);
+ return SDL_OutOfMemory();
+ }
+ SDL_memset(haptic->effects, 0, sizeof(struct haptic_effect) * haptic->neffects);
+
+ // outside of SYS_HAPTIC
+ haptic->instance_id = 255;
+
+ list_node->haptic = haptic;
+ list_node->next = NULL;
+
+ // grab a joystick ref so that it doesn't get fully destroyed before the haptic is closed
+ SDL_OpenJoystick(SDL_GetJoystickID(joystick));
+
+ SDL_LockMutex(haptic_list_mutex);
+ if (haptic_list_head == NULL) {
+ haptic_list_head = list_node;
+ } else {
+ haptic_list_node *cur = haptic_list_head;
+ while(cur->next != NULL) {
+ cur = cur->next;
+ }
+ cur->next = list_node;
+ }
+ SDL_UnlockMutex(haptic_list_mutex);
+
+ return true;
+ }
+ }
+
+ return SDL_SetError("No supported HIDAPI haptic driver found for joystick");
+}
+
+bool SDL_HIDAPI_JoystickSameHaptic(SDL_Haptic *haptic, SDL_Joystick *joystick)
+{
+ SDL_HIDAPI_HapticDevice *device;
+
+ SDL_AssertJoysticksLocked();
+ if (joystick->driver != &SDL_HIDAPI_JoystickDriver) {
+ return false;
+ }
+
+ device = (SDL_HIDAPI_HapticDevice *)haptic->hwdata;
+
+ if (joystick == device->joystick) {
+ return true;
+ }
+ return false;
+}
+
+void SDL_HIDAPI_HapticClose(SDL_Haptic *haptic)
+{
+ haptic_list_node *cur, *last;
+
+ SDL_LockMutex(haptic_list_mutex);
+
+ cur = haptic_list_head;
+ last = NULL;
+ while (cur != NULL) {
+ if (cur->haptic == haptic) {
+ SDL_HIDAPI_HapticDevice *device = (SDL_HIDAPI_HapticDevice *)haptic->hwdata;
+
+ device->driver->Close(device);
+
+ // a reference was grabbed during open, now release it
+ SDL_CloseJoystick(device->joystick);
+
+ if (cur == haptic_list_head) {
+ haptic_list_head = cur->next;
+ } else {
+ last->next = cur->next;
+ }
+
+ SDL_free(device->ctx);
+ SDL_free(device);
+ SDL_free(haptic->effects);
+ SDL_free(cur);
+ SDL_UnlockMutex(haptic_list_mutex);
+ return;
+ }
+ last = cur;
+ cur = cur->next;
+ }
+
+ SDL_UnlockMutex(haptic_list_mutex);
+}
+
+void SDL_HIDAPI_HapticQuit(void)
+{
+ // the list is cleared in SDL_haptic.c
+ if (haptic_list_mutex != NULL) {
+ SDL_DestroyMutex(haptic_list_mutex);
+ haptic_list_mutex = NULL;
+ }
+}
+
+SDL_HapticEffectID SDL_HIDAPI_HapticNewEffect(SDL_Haptic *haptic, const SDL_HapticEffect *base)
+{
+ SDL_HIDAPI_HapticDevice *device = (SDL_HIDAPI_HapticDevice *)haptic->hwdata;
+ SDL_HapticEffectID new_id = device->driver->CreateEffect(device, base);
+ if (new_id >= 0){
+ haptic->effects[new_id].effect = *base;
+ }
+ return new_id;
+}
+
+bool SDL_HIDAPI_HapticUpdateEffect(SDL_Haptic *haptic, SDL_HapticEffectID id, const SDL_HapticEffect *data)
+{
+ SDL_HIDAPI_HapticDevice *device = (SDL_HIDAPI_HapticDevice *)haptic->hwdata;
+ return device->driver->UpdateEffect(device, id, data);
+}
+
+bool SDL_HIDAPI_HapticRunEffect(SDL_Haptic *haptic, SDL_HapticEffectID id, Uint32 iterations)
+{
+ SDL_HIDAPI_HapticDevice *device = (SDL_HIDAPI_HapticDevice *)haptic->hwdata;
+ return device->driver->RunEffect(device, id, iterations);
+}
+
+bool SDL_HIDAPI_HapticStopEffect(SDL_Haptic *haptic, SDL_HapticEffectID id)
+{
+ SDL_HIDAPI_HapticDevice *device = (SDL_HIDAPI_HapticDevice *)haptic->hwdata;
+ return device->driver->StopEffect(device, id);
+}
+
+void SDL_HIDAPI_HapticDestroyEffect(SDL_Haptic *haptic, SDL_HapticEffectID id)
+{
+ SDL_HIDAPI_HapticDevice *device = (SDL_HIDAPI_HapticDevice *)haptic->hwdata;
+ device->driver->DestroyEffect(device, id);
+}
+
+bool SDL_HIDAPI_HapticGetEffectStatus(SDL_Haptic *haptic, SDL_HapticEffectID id)
+{
+ SDL_HIDAPI_HapticDevice *device = (SDL_HIDAPI_HapticDevice *)haptic->hwdata;
+ return device->driver->GetEffectStatus(device, id);
+}
+
+bool SDL_HIDAPI_HapticSetGain(SDL_Haptic *haptic, int gain)
+{
+ SDL_HIDAPI_HapticDevice *device = (SDL_HIDAPI_HapticDevice *)haptic->hwdata;
+ return device->driver->SetGain(device, gain);
+}
+
+bool SDL_HIDAPI_HapticSetAutocenter(SDL_Haptic *haptic, int autocenter)
+{
+ SDL_HIDAPI_HapticDevice *device = (SDL_HIDAPI_HapticDevice *)haptic->hwdata;
+ return device->driver->SetAutocenter(device, autocenter);
+}
+
+bool SDL_HIDAPI_HapticPause(SDL_Haptic *haptic)
+{
+ SDL_HIDAPI_HapticDevice *device = (SDL_HIDAPI_HapticDevice *)haptic->hwdata;
+ return device->driver->Pause(device);
+}
+
+bool SDL_HIDAPI_HapticResume(SDL_Haptic *haptic)
+{
+ SDL_HIDAPI_HapticDevice *device = (SDL_HIDAPI_HapticDevice *)haptic->hwdata;
+ return device->driver->Resume(device);
+}
+
+bool SDL_HIDAPI_HapticStopAll(SDL_Haptic *haptic)
+{
+ SDL_HIDAPI_HapticDevice *device = (SDL_HIDAPI_HapticDevice *)haptic->hwdata;
+ return device->driver->StopEffects(device);
+}
+
+#endif //SDL_JOYSTICK_HIDAPI
diff --git a/thirdparty/sdl/haptic/hidapi/SDL_hidapihaptic.h b/thirdparty/sdl/haptic/hidapi/SDL_hidapihaptic.h
new file mode 100644
index 00000000000..4734bbc5b4f
--- /dev/null
+++ b/thirdparty/sdl/haptic/hidapi/SDL_hidapihaptic.h
@@ -0,0 +1,48 @@
+/*
+ Simple DirectMedia Layer
+ Copyright (C) 2025 Katharine Chui <[email protected]>
+
+ 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.
+*/
+
+/*
+ All hid command sent and effect rendering are ported from https://github.com/berarma/new-lg4ff
+*/
+
+#ifndef SDL_hidapihaptic_h_
+#define SDL_hidapihaptic_h_
+
+bool SDL_HIDAPI_HapticInit(void);
+bool SDL_HIDAPI_HapticIsHidapi(SDL_Haptic *haptic);
+bool SDL_HIDAPI_JoystickIsHaptic(SDL_Joystick *joystick);
+bool SDL_HIDAPI_HapticOpenFromJoystick(SDL_Haptic *haptic, SDL_Joystick *joystick);
+bool SDL_HIDAPI_JoystickSameHaptic(SDL_Haptic *haptic, SDL_Joystick *joystick);
+void SDL_HIDAPI_HapticClose(SDL_Haptic *haptic);
+void SDL_HIDAPI_HapticQuit(void);
+SDL_HapticEffectID SDL_HIDAPI_HapticNewEffect(SDL_Haptic *haptic, const SDL_HapticEffect *base);
+bool SDL_HIDAPI_HapticUpdateEffect(SDL_Haptic *haptic, SDL_HapticEffectID id, const SDL_HapticEffect *data);
+bool SDL_HIDAPI_HapticRunEffect(SDL_Haptic *haptic, SDL_HapticEffectID id, Uint32 iterations);
+bool SDL_HIDAPI_HapticStopEffect(SDL_Haptic *haptic, SDL_HapticEffectID id);
+void SDL_HIDAPI_HapticDestroyEffect(SDL_Haptic *haptic, SDL_HapticEffectID id);
+bool SDL_HIDAPI_HapticGetEffectStatus(SDL_Haptic *haptic, SDL_HapticEffectID id);
+bool SDL_HIDAPI_HapticSetGain(SDL_Haptic *haptic, int gain);
+bool SDL_HIDAPI_HapticSetAutocenter(SDL_Haptic *haptic, int autocenter);
+bool SDL_HIDAPI_HapticPause(SDL_Haptic *haptic);
+bool SDL_HIDAPI_HapticResume(SDL_Haptic *haptic);
+bool SDL_HIDAPI_HapticStopAll(SDL_Haptic *haptic);
+
+#endif //SDL_hidapihaptic_h_
diff --git a/thirdparty/sdl/haptic/hidapi/SDL_hidapihaptic_c.h b/thirdparty/sdl/haptic/hidapi/SDL_hidapihaptic_c.h
new file mode 100644
index 00000000000..3ae4f29baa4
--- /dev/null
+++ b/thirdparty/sdl/haptic/hidapi/SDL_hidapihaptic_c.h
@@ -0,0 +1,70 @@
+/*
+ Simple DirectMedia Layer
+ Copyright (C) 2025 Katharine Chui <[email protected]>
+
+ 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.
+*/
+
+#ifndef SDL_hidapihaptic_c_h_
+#define SDL_hidapihaptic_c_h_
+
+#include "SDL3/SDL_haptic.h"
+#include "SDL3/SDL_joystick.h"
+#include "../SDL_syshaptic.h"
+#include "../../joystick/SDL_joystick_c.h" // accessing _SDL_JoystickDriver
+#include "../../joystick/SDL_sysjoystick.h" // accessing _SDL_Joystick
+
+#define SDL_HAPTIC_HIDAPI_LG4FF
+
+typedef struct SDL_HIDAPI_HapticDriver SDL_HIDAPI_HapticDriver;
+typedef struct SDL_HIDAPI_HapticDevice
+{
+ SDL_Haptic *haptic; /* related haptic ref */
+ SDL_Joystick *joystick; /* related hidapi joystick */
+ SDL_HIDAPI_HapticDriver *driver; /* driver to use */
+ void *ctx; /* driver specific context */
+} SDL_HIDAPI_HapticDevice;
+
+struct SDL_HIDAPI_HapticDriver
+{
+ bool (*JoystickSupported)(SDL_Joystick *joystick); /* return true if haptic can be opened from the joystick */
+ void *(*Open)(SDL_Joystick *joystick); /* returns a driver context allocated with SDL_malloc, or null if it cannot be allocated */
+
+ /* functions below need to handle the possibility of a null joystick instance, indicating the absence of the joystick */
+ void (*Close)(SDL_HIDAPI_HapticDevice *device); /* cleanup resources allocated during Open, do NOT free driver context created in Open */
+
+ /* below mirror SDL_haptic.h effect interfaces */
+ int (*NumEffects)(SDL_HIDAPI_HapticDevice *device); /* returns supported number of effects the device can store */
+ int (*NumEffectsPlaying)(SDL_HIDAPI_HapticDevice *device); /* returns supported number of effects the device can play concurrently */
+ Uint32 (*GetFeatures)(SDL_HIDAPI_HapticDevice *device); /* returns supported effects in a bitmask */
+ int (*NumAxes)(SDL_HIDAPI_HapticDevice *device); /* returns the number of haptic axes */
+ SDL_HapticEffectID (*CreateEffect)(SDL_HIDAPI_HapticDevice *device, const SDL_HapticEffect *data); /* returns effect id if created correctly, negative number on error */
+ bool (*UpdateEffect)(SDL_HIDAPI_HapticDevice *device, SDL_HapticEffectID id, const SDL_HapticEffect *data); /* returns true on success, false on error */
+ bool (*RunEffect)(SDL_HIDAPI_HapticDevice *device, SDL_HapticEffectID id, Uint32 iterations); /* returns true on success, false on error */
+ bool (*StopEffect)(SDL_HIDAPI_HapticDevice *device, SDL_HapticEffectID id); /* returns true on success, false on error */
+ void (*DestroyEffect)(SDL_HIDAPI_HapticDevice *device, SDL_HapticEffectID id);
+ bool (*GetEffectStatus)(SDL_HIDAPI_HapticDevice *device, SDL_HapticEffectID id); /* returns true if playing, false if not playing or on error */
+ bool (*SetGain)(SDL_HIDAPI_HapticDevice *device, int gain); /* gain 0 - 100, returns true on success, false on error */
+ bool (*SetAutocenter)(SDL_HIDAPI_HapticDevice *device, int autocenter); /* autocenter 0 - 100, returns true on success, false on error */
+ bool (*Pause)(SDL_HIDAPI_HapticDevice *device); /* returns true on success, false on error */
+ bool (*Resume)(SDL_HIDAPI_HapticDevice *device); /* returns true on success, false on error */
+ bool (*StopEffects)(SDL_HIDAPI_HapticDevice *device); /* returns true on success, false on error */
+};
+
+extern SDL_HIDAPI_HapticDriver SDL_HIDAPI_HapticDriverLg4ff;
+
+#endif //SDL_hidapihaptic_c_h_
diff --git a/thirdparty/sdl/haptic/hidapi/SDL_hidapihaptic_lg4ff.c b/thirdparty/sdl/haptic/hidapi/SDL_hidapihaptic_lg4ff.c
new file mode 100644
index 00000000000..7e6b3dc482f
--- /dev/null
+++ b/thirdparty/sdl/haptic/hidapi/SDL_hidapihaptic_lg4ff.c
@@ -0,0 +1,1264 @@
+/*
+ Simple DirectMedia Layer
+ Copyright (C) 2025 Simon Wood <[email protected]>
+ Copyright (C) 2025 Michal Malý <[email protected]>
+ Copyright (C) 2025 Bernat Arlandis <[email protected]>
+ Copyright (C) 2025 Katharine Chui <[email protected]>
+
+ 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"
+
+#ifdef SDL_JOYSTICK_HIDAPI
+
+#include "SDL_hidapihaptic_c.h"
+
+#ifdef SDL_HAPTIC_HIDAPI_LG4FF
+
+#include "SDL3/SDL_thread.h"
+#include "SDL3/SDL_mutex.h"
+#include "SDL3/SDL_timer.h"
+
+#include <math.h>
+
+#define USB_VENDOR_ID_LOGITECH 0x046d
+#define USB_DEVICE_ID_LOGITECH_G29_WHEEL 0xc24f
+#define USB_DEVICE_ID_LOGITECH_G27_WHEEL 0xc29b
+#define USB_DEVICE_ID_LOGITECH_G25_WHEEL 0xc299
+#define USB_DEVICE_ID_LOGITECH_DFGT_WHEEL 0xc29a
+#define USB_DEVICE_ID_LOGITECH_DFP_WHEEL 0xc298
+#define USB_DEVICE_ID_LOGITECH_WHEEL 0xc294
+
+static Uint32 supported_device_ids[] = {
+ USB_DEVICE_ID_LOGITECH_G29_WHEEL,
+ USB_DEVICE_ID_LOGITECH_G27_WHEEL,
+ USB_DEVICE_ID_LOGITECH_G25_WHEEL,
+ USB_DEVICE_ID_LOGITECH_DFGT_WHEEL,
+ USB_DEVICE_ID_LOGITECH_DFP_WHEEL,
+ USB_DEVICE_ID_LOGITECH_WHEEL
+};
+
+
+
+#define LG4FF_MAX_EFFECTS 16
+
+#define FF_EFFECT_STARTED 0
+#define FF_EFFECT_ALLSET 1
+#define FF_EFFECT_PLAYING 2
+#define FF_EFFECT_UPDATING 3
+
+struct lg4ff_effect_state {
+ SDL_HapticEffect effect;
+ Uint64 start_at;
+ Uint64 play_at;
+ Uint64 stop_at;
+ Uint32 flags;
+ Uint64 time_playing;
+ Uint64 updated_at;
+ Uint32 phase;
+ Uint32 phase_adj;
+ Uint32 count;
+
+ double direction_gain;
+ Sint32 slope;
+
+ bool allocated;
+};
+
+struct lg4ff_effect_parameters {
+ Sint32 level;
+ Sint32 d1;
+ Sint32 d2;
+ Sint32 k1;
+ Sint32 k2;
+ Uint32 clip;
+};
+
+struct lg4ff_slot {
+ Sint32 id;
+ struct lg4ff_effect_parameters parameters;
+ Uint8 current_cmd[7];
+ Uint32 cmd_op;
+ bool is_updated;
+ Uint32 effect_type;
+};
+
+typedef struct lg4ff_device {
+ Uint16 product_id;
+ Uint16 release_number;
+ struct lg4ff_effect_state states[LG4FF_MAX_EFFECTS];
+ struct lg4ff_slot slots[4];
+ Sint32 effects_used;
+
+ Sint32 gain;
+ Sint32 app_gain;
+
+ Sint32 spring_level;
+ Sint32 damper_level;
+ Sint32 friction_level;
+
+ Sint32 peak_ffb_level;
+
+ SDL_Joystick *hid_handle;
+
+ bool stop_thread;
+ SDL_Thread *thread;
+ char thread_name_buf[256];
+
+ SDL_Mutex *mutex;
+
+ bool is_ffex;
+} lg4ff_device;
+
+static SDL_INLINE Uint64 get_time_ms(void) {
+ return SDL_GetTicks();
+}
+
+#define test_bit(bit, field) (*(field) & (1 << bit))
+#define __set_bit(bit, field) {*(field) = *(field) | (1 << bit);}
+#define __clear_bit(bit, field) {*(field) = *(field) & ~(1 << bit);}
+#define sin_deg(in) (double)(SDL_sin((double)(in) * SDL_PI_D / 180.0))
+
+#define time_after_eq(a, b) (a >= b)
+#define time_before(a, b) (a < b)
+#define time_diff(a, b) (a - b)
+
+#define STOP_EFFECT(state) ((state)->flags = 0)
+
+#define CLAMP_VALUE_U16(x) ((Uint16)((x) > 0xffff ? 0xffff : (x)))
+#define SCALE_VALUE_U16(x, bits) (CLAMP_VALUE_U16(x) >> (16 - bits))
+#define CLAMP_VALUE_S16(x) ((Uint16)((x) <= -0x8000 ? -0x8000 : ((x) > 0x7fff ? 0x7fff : (x))))
+#define TRANSLATE_FORCE(x) ((CLAMP_VALUE_S16(x) + 0x8000) >> 8)
+#define SCALE_COEFF(x, bits) SCALE_VALUE_U16(abs32(x) * 2, bits)
+
+static SDL_INLINE Sint32 abs32(Sint32 x) {
+ return x < 0 ? -x : x;
+}
+static SDL_INLINE Sint64 abs64(Sint64 x) {
+ return x < 0 ? -x : x;
+}
+
+static SDL_INLINE bool effect_is_periodic(const SDL_HapticEffect *effect)
+{
+
+ return effect->type == SDL_HAPTIC_SINE ||
+ effect->type == SDL_HAPTIC_TRIANGLE ||
+ effect->type == SDL_HAPTIC_SAWTOOTHUP ||
+ effect->type == SDL_HAPTIC_SAWTOOTHDOWN ||
+ effect->type == SDL_HAPTIC_SQUARE;
+}
+
+static SDL_INLINE bool effect_is_condition(const SDL_HapticEffect *effect)
+{
+ return effect->type == SDL_HAPTIC_SPRING ||
+ effect->type == SDL_HAPTIC_DAMPER ||
+ effect->type == SDL_HAPTIC_FRICTION;
+}
+
+// linux SDL_syshaptic.c SDL_SYS_ToDirection
+static Uint16 to_linux_direction(SDL_HapticDirection *src)
+{
+ Uint32 tmp;
+
+ switch (src->type) {
+ case SDL_HAPTIC_POLAR:
+ tmp = ((src->dir[0] % 36000) * 0x8000) / 18000; /* convert to range [0,0xFFFF] */
+ return (Uint16)tmp;
+
+ case SDL_HAPTIC_SPHERICAL:
+ /*
+ We convert to polar, because that's the only supported direction on Linux.
+ The first value of a spherical direction is practically the same as a
+ Polar direction, except that we have to add 90 degrees. It is the angle
+ from EAST {1,0} towards SOUTH {0,1}.
+ --> add 9000
+ --> finally convert to [0,0xFFFF] as in case SDL_HAPTIC_POLAR.
+ */
+ tmp = ((src->dir[0]) + 9000) % 36000; /* Convert to polars */
+ tmp = (tmp * 0x8000) / 18000; /* convert to range [0,0xFFFF] */
+ return (Uint16)tmp;
+
+ case SDL_HAPTIC_CARTESIAN:
+ if (!src->dir[1]) {
+ return (Uint16) (src->dir[0] >= 0 ? 0x4000 : 0xC000);
+ } else if (!src->dir[0]) {
+ return (Uint16) (src->dir[1] >= 0 ? 0x8000 : 0);
+ } else {
+ float f = (float)SDL_atan2(src->dir[1], src->dir[0]); /* Ideally we'd use fixed point math instead of floats... */
+ /*
+ SDL_atan2 takes the parameters: Y-axis-value and X-axis-value (in that order)
+ - Y-axis-value is the second coordinate (from center to SOUTH)
+ - X-axis-value is the first coordinate (from center to EAST)
+ We add 36000, because SDL_atan2 also returns negative values. Then we practically
+ have the first spherical value. Therefore we proceed as in case
+ SDL_HAPTIC_SPHERICAL and add another 9000 to get the polar value.
+ --> add 45000 in total
+ --> finally convert to [0,0xFFFF] as in case SDL_HAPTIC_POLAR.
+ */
+ tmp = (((Sint32) (f * 18000. / SDL_PI_D)) + 45000) % 36000;
+ tmp = (tmp * 0x8000) / 18000; /* convert to range [0,0xFFFF] */
+ return (Uint16)tmp;
+ }
+ case SDL_HAPTIC_STEERING_AXIS:
+ return 0x4000;
+ default:
+ SDL_assert(0);
+ }
+
+ return 0;
+}
+
+static Uint16 get_effect_direction(SDL_HapticEffect *effect)
+{
+ Uint16 direction = 0;
+ if (effect_is_periodic(effect)) {
+ direction = to_linux_direction(&effect->periodic.direction);
+ } else if (effect_is_condition(effect)) {
+ direction = to_linux_direction(&effect->condition.direction);
+ } else {
+ switch(effect->type) {
+ case SDL_HAPTIC_CONSTANT:
+ direction = to_linux_direction(&effect->constant.direction);
+ break;
+ case SDL_HAPTIC_RAMP:
+ direction = to_linux_direction(&effect->ramp.direction);
+ break;
+ default:
+ SDL_assert(0);
+ }
+ }
+
+ return direction;
+}
+
+static Uint32 get_effect_replay_length(SDL_HapticEffect *effect)
+{
+ Uint32 length = 0;
+ if (effect_is_periodic(effect)) {
+ length = effect->periodic.length;
+ } else if (effect_is_condition(effect)) {
+ length = effect->condition.length;
+ } else {
+ switch(effect->type) {
+ case SDL_HAPTIC_CONSTANT:
+ length = effect->constant.length;
+ break;
+ case SDL_HAPTIC_RAMP:
+ length = effect->ramp.length;
+ break;
+ default:
+ SDL_assert(0);
+ }
+ }
+
+ if (length == SDL_HAPTIC_INFINITY) {
+ length = 0;
+ }
+
+ return length;
+}
+
+static Uint16 get_effect_replay_delay(SDL_HapticEffect *effect)
+{
+ Uint16 delay = 0;
+ if (effect_is_periodic(effect)) {
+ delay = effect->periodic.delay;
+ } else if (effect_is_condition(effect)) {
+ delay = effect->condition.delay;
+ } else {
+ switch(effect->type) {
+ case SDL_HAPTIC_CONSTANT:
+ delay = effect->constant.delay;
+ break;
+ case SDL_HAPTIC_RAMP:
+ delay = effect->ramp.delay;
+ break;
+ default:
+ SDL_assert(0);
+ }
+ }
+
+ return delay;
+}
+
+/*
+ *Ported*
+ Original function by:
+ Bernat Arlandis <[email protected]>
+ `git blame 1a2d5727876dd7befce23d9695924e9446b31c4b hid-lg4ff.c`, https://github.com/berarma/new-lg4ff.git
+*/
+static int lg4ff_play_effect(struct lg4ff_device *device, SDL_HapticEffectID effect_id, int value)
+{
+ struct lg4ff_effect_state *state;
+ Uint64 now = get_time_ms();
+
+ state = &device->states[effect_id];
+
+ if (value > 0) {
+ if (test_bit(FF_EFFECT_STARTED, &state->flags)) {
+ STOP_EFFECT(state);
+ } else {
+ device->effects_used++;
+ }
+ __set_bit(FF_EFFECT_STARTED, &state->flags);
+ state->start_at = now;
+ state->count = value;
+ } else {
+ if (test_bit(FF_EFFECT_STARTED, &state->flags)) {
+ STOP_EFFECT(state);
+ device->effects_used--;
+ }
+ }
+
+ return 0;
+}
+
+/*
+ *Ported*
+ Original function by:
+ Bernat Arlandis <[email protected]>
+ `git blame 1a2d5727876dd7befce23d9695924e9446b31c4b hid-lg4ff.c`, https://github.com/berarma/new-lg4ff.git
+*/
+static int lg4ff_upload_effect(struct lg4ff_device *device, const SDL_HapticEffect *effect, SDL_HapticEffectID id)
+{
+ struct lg4ff_effect_state *state;
+ Uint64 now = get_time_ms();
+
+ if (effect_is_periodic(effect) && effect->periodic.period == 0) {
+ return -1;
+ }
+
+ state = &device->states[id];
+
+ if (test_bit(FF_EFFECT_STARTED, &state->flags) && effect->type != state->effect.type) {
+ return -1;
+ }
+
+ state->effect = *effect;
+
+ if (test_bit(FF_EFFECT_STARTED, &state->flags)) {
+ __set_bit(FF_EFFECT_UPDATING, &state->flags);
+ state->updated_at = now;
+ }
+
+ return 0;
+}
+
+/*
+ *Ported*
+ Original function by:
+ Bernat Arlandis <[email protected]>
+ `git blame 1a2d5727876dd7befce23d9695924e9446b31c4b hid-lg4ff.c`, https://github.com/berarma/new-lg4ff.git
+*/
+static void lg4ff_update_state(struct lg4ff_effect_state *state, const Uint64 now)
+{
+ SDL_HapticEffect *effect = &state->effect;
+ Uint64 phase_time;
+ Uint16 effect_direction = get_effect_direction(effect);
+
+ if (!test_bit(FF_EFFECT_ALLSET, &state->flags)) {
+ state->play_at = state->start_at + get_effect_replay_delay(effect);
+ if (!test_bit(FF_EFFECT_UPDATING, &state->flags)) {
+ state->updated_at = state->play_at;
+ }
+ state->direction_gain = sin_deg(effect_direction * 360 / 0x10000);
+ if (effect_is_periodic(effect)) {
+ state->phase_adj = effect->periodic.phase * 360 / effect->periodic.period;
+ }
+ if (get_effect_replay_length(effect)) {
+ state->stop_at = state->play_at + get_effect_replay_length(effect);
+ }
+ }
+ __set_bit(FF_EFFECT_ALLSET, &state->flags);
+
+ if (test_bit(FF_EFFECT_UPDATING, &state->flags)) {
+ __clear_bit(FF_EFFECT_PLAYING, &state->flags);
+ state->play_at = state->updated_at + get_effect_replay_delay(effect);
+ state->direction_gain = sin_deg(effect_direction * 360 / 0x10000);
+ if (get_effect_replay_length(effect)) {
+ state->stop_at = state->updated_at + get_effect_replay_length(effect);
+ }
+ if (effect_is_periodic(effect)) {
+ state->phase_adj = state->phase;
+ }
+ }
+ __clear_bit(FF_EFFECT_UPDATING, &state->flags);
+
+ state->slope = 0;
+ if (effect->type == SDL_HAPTIC_RAMP && effect->ramp.length && (effect->ramp.length - effect->ramp.attack_length - effect->ramp.fade_length) != 0) {
+ state->slope = ((effect->ramp.end - effect->ramp.start) << 16) / (effect->ramp.length - effect->ramp.attack_length - effect->ramp.fade_length);
+ }
+
+ if (!test_bit(FF_EFFECT_PLAYING, &state->flags) && time_after_eq(now,
+ state->play_at) && (get_effect_replay_length(effect) == 0 ||
+ time_before(now, state->stop_at))) {
+ __set_bit(FF_EFFECT_PLAYING, &state->flags);
+ }
+
+ if (test_bit(FF_EFFECT_PLAYING, &state->flags)) {
+ state->time_playing = time_diff(now, state->play_at);
+ if (effect_is_periodic(effect)) {
+ phase_time = time_diff(now, state->updated_at);
+ state->phase = (phase_time % effect->periodic.period) * 360 / effect->periodic.period;
+ state->phase += state->phase_adj % 360;
+ }
+ }
+}
+
+/*
+ *Ported*
+ Original function by:
+ Bernat Arlandis <[email protected]>
+ `git blame 1a2d5727876dd7befce23d9695924e9446b31c4b hid-lg4ff.c`, https://github.com/berarma/new-lg4ff.git
+*/
+static Sint32 lg4ff_calculate_constant(struct lg4ff_effect_state *state)
+{
+ SDL_HapticConstant *constant = (SDL_HapticConstant *)&state->effect;
+ Sint32 level_sign;
+ Sint32 level = constant->level;
+ Sint32 d, t;
+
+ if (state->time_playing < constant->attack_length) {
+ level_sign = level < 0 ? -1 : 1;
+ d = level - level_sign * constant->attack_level;
+ level = (Sint32) (level_sign * constant->attack_level + d * state->time_playing / constant->attack_length);
+ } else if (constant->length && constant->fade_length) {
+ t = (Sint32) (state->time_playing - constant->length + constant->fade_length);
+ if (t > 0) {
+ level_sign = level < 0 ? -1 : 1;
+ d = level - level_sign * constant->fade_level;
+ level = level - d * t / constant->fade_length;
+ }
+ }
+
+ return (Sint32)(state->direction_gain * level);
+}
+
+/*
+ *Ported*
+ Original function by:
+ Bernat Arlandis <[email protected]>
+ `git blame 1a2d5727876dd7befce23d9695924e9446b31c4b hid-lg4ff.c`, https://github.com/berarma/new-lg4ff.git
+*/
+static Sint32 lg4ff_calculate_ramp(struct lg4ff_effect_state *state)
+{
+ SDL_HapticRamp *ramp = (SDL_HapticRamp *)&state->effect;
+ Sint32 level_sign;
+ Sint32 level;
+ Sint32 d, t;
+
+ if (state->time_playing < ramp->attack_length) {
+ level = ramp->start;
+ level_sign = level < 0 ? -1 : 1;
+ t = (Sint32) (ramp->attack_length - state->time_playing);
+ d = level - level_sign * ramp->attack_level;
+ level = level_sign * ramp->attack_level + d * t / ramp->attack_length;
+ } else if (ramp->length && state->time_playing >= ramp->length - ramp->fade_length && ramp->fade_length) {
+ level = ramp->end;
+ level_sign = level < 0 ? -1 : 1;
+ t = (Sint32) (state->time_playing - ramp->length + ramp->fade_length);
+ d = level_sign * ramp->fade_level - level;
+ level = level - d * t / ramp->fade_length;
+ } else {
+ t = (Sint32) (state->time_playing - ramp->attack_length);
+ level = ramp->start + ((t * state->slope) >> 16);
+ }
+
+ return (Sint32)(state->direction_gain * level);
+}
+
+/*
+ *Ported*
+ Original function by:
+ Bernat Arlandis <[email protected]>
+ `git blame 1a2d5727876dd7befce23d9695924e9446b31c4b hid-lg4ff.c`, https://github.com/berarma/new-lg4ff.git
+*/
+static Sint32 lg4ff_calculate_periodic(struct lg4ff_effect_state *state)
+{
+ SDL_HapticPeriodic *periodic = (SDL_HapticPeriodic *)&state->effect;
+ Sint32 magnitude = periodic->magnitude;
+ Sint32 magnitude_sign = magnitude < 0 ? -1 : 1;
+ Sint32 level = periodic->offset;
+ Sint32 d, t;
+
+ if (state->time_playing < periodic->attack_length) {
+ d = magnitude - magnitude_sign * periodic->attack_level;
+ magnitude = (Sint32) (magnitude_sign * periodic->attack_level + d * state->time_playing / periodic->attack_length);
+ } else if (periodic->length && periodic->fade_length) {
+ t = (Sint32) (state->time_playing - get_effect_replay_length(&state->effect) + periodic->fade_length);
+ if (t > 0) {
+ d = magnitude - magnitude_sign * periodic->fade_level;
+ magnitude = magnitude - d * t / periodic->fade_length;
+ }
+ }
+
+ switch (periodic->type) {
+ case SDL_HAPTIC_SINE:
+ level += (Sint32)(sin_deg(state->phase) * magnitude);
+ break;
+ case SDL_HAPTIC_SQUARE:
+ level += (state->phase < 180 ? 1 : -1) * magnitude;
+ break;
+ case SDL_HAPTIC_TRIANGLE:
+ level += (Sint32) (abs64((Sint64)state->phase * magnitude * 2 / 360 - magnitude) * 2 - magnitude);
+ break;
+ case SDL_HAPTIC_SAWTOOTHUP:
+ level += state->phase * magnitude * 2 / 360 - magnitude;
+ break;
+ case SDL_HAPTIC_SAWTOOTHDOWN:
+ level += magnitude - state->phase * magnitude * 2 / 360;
+ break;
+ default:
+ SDL_assert(0);
+ }
+
+ return (Sint32)(state->direction_gain * level);
+}
+
+/*
+ *Ported*
+ Original function by:
+ Bernat Arlandis <[email protected]>
+ `git blame 1a2d5727876dd7befce23d9695924e9446b31c4b hid-lg4ff.c`, https://github.com/berarma/new-lg4ff.git
+*/
+static void lg4ff_calculate_spring(struct lg4ff_effect_state *state, struct lg4ff_effect_parameters *parameters)
+{
+ SDL_HapticCondition *condition = (SDL_HapticCondition *)&state->effect;
+
+ parameters->d1 = ((Sint32)condition->center[0]) - condition->deadband[0] / 2;
+ parameters->d2 = ((Sint32)condition->center[0]) + condition->deadband[0] / 2;
+ parameters->k1 = condition->left_coeff[0];
+ parameters->k2 = condition->right_coeff[0];
+ parameters->clip = (Uint16)condition->right_sat[0];
+}
+
+/*
+ *Ported*
+ Original function by:
+ Bernat Arlandis <[email protected]>
+ `git blame 1a2d5727876dd7befce23d9695924e9446b31c4b hid-lg4ff.c`, https://github.com/berarma/new-lg4ff.git
+*/
+static void lg4ff_calculate_resistance(struct lg4ff_effect_state *state, struct lg4ff_effect_parameters *parameters)
+{
+ SDL_HapticCondition *condition = (SDL_HapticCondition *)&state->effect;
+
+ parameters->k1 = condition->left_coeff[0];
+ parameters->k2 = condition->right_coeff[0];
+ parameters->clip = (Uint16)condition->right_sat[0];
+}
+
+/*
+ *Ported*
+ Original function by:
+ Bernat Arlandis <[email protected]>
+ `git blame 1a2d5727876dd7befce23d9695924e9446b31c4b hid-lg4ff.c`, https://github.com/berarma/new-lg4ff.git
+*/
+static void lg4ff_update_slot(struct lg4ff_slot *slot, struct lg4ff_effect_parameters *parameters)
+{
+ Uint8 original_cmd[7];
+ Sint32 d1;
+ Sint32 d2;
+ Sint32 k1;
+ Sint32 k2;
+ Sint32 s1;
+ Sint32 s2;
+
+ SDL_memcpy(original_cmd, slot->current_cmd, sizeof(original_cmd));
+
+ if ((original_cmd[0] & 0xf) == 1) {
+ original_cmd[0] = (original_cmd[0] & 0xf0) + 0xc;
+ }
+
+ if (slot->effect_type == SDL_HAPTIC_CONSTANT) {
+ if (slot->cmd_op == 0) {
+ slot->cmd_op = 1;
+ } else {
+ slot->cmd_op = 0xc;
+ }
+ } else {
+ if (parameters->clip == 0) {
+ slot->cmd_op = 3;
+ } else if (slot->cmd_op == 3) {
+ slot->cmd_op = 1;
+ } else {
+ slot->cmd_op = 0xc;
+ }
+ }
+
+ slot->current_cmd[0] = (Uint8)((0x10 << slot->id) + slot->cmd_op);
+
+ if (slot->cmd_op == 3) {
+ slot->current_cmd[1] = 0;
+ slot->current_cmd[2] = 0;
+ slot->current_cmd[3] = 0;
+ slot->current_cmd[4] = 0;
+ slot->current_cmd[5] = 0;
+ slot->current_cmd[6] = 0;
+ } else {
+ switch (slot->effect_type) {
+ case SDL_HAPTIC_CONSTANT:
+ slot->current_cmd[1] = 0x00;
+ slot->current_cmd[2] = 0;
+ slot->current_cmd[3] = 0;
+ slot->current_cmd[4] = 0;
+ slot->current_cmd[5] = 0;
+ slot->current_cmd[6] = 0;
+ slot->current_cmd[2 + slot->id] = TRANSLATE_FORCE(parameters->level);
+ break;
+ case SDL_HAPTIC_SPRING:
+ d1 = SCALE_VALUE_U16(((parameters->d1) + 0x8000) & 0xffff, 11);
+ d2 = SCALE_VALUE_U16(((parameters->d2) + 0x8000) & 0xffff, 11);
+ s1 = parameters->k1 < 0;
+ s2 = parameters->k2 < 0;
+ k1 = abs32(parameters->k1);
+ k2 = abs32(parameters->k2);
+ if (k1 < 2048) {
+ d1 = 0;
+ } else {
+ k1 -= 2048;
+ }
+ if (k2 < 2048) {
+ d2 = 2047;
+ } else {
+ k2 -= 2048;
+ }
+ slot->current_cmd[1] = 0x0b;
+ slot->current_cmd[2] = (Uint8)(d1 >> 3);
+ slot->current_cmd[3] = (Uint8)(d2 >> 3);
+ slot->current_cmd[4] = (SCALE_COEFF(k2, 4) << 4) + SCALE_COEFF(k1, 4);
+ slot->current_cmd[5] = (Uint8)(((d2 & 7) << 5) + ((d1 & 7) << 1) + (s2 << 4) + s1);
+ slot->current_cmd[6] = SCALE_VALUE_U16(parameters->clip, 8);
+ break;
+ case SDL_HAPTIC_DAMPER:
+ s1 = parameters->k1 < 0;
+ s2 = parameters->k2 < 0;
+ slot->current_cmd[1] = 0x0c;
+ slot->current_cmd[2] = SCALE_COEFF(parameters->k1, 4);
+ slot->current_cmd[3] = (Uint8)s1;
+ slot->current_cmd[4] = SCALE_COEFF(parameters->k2, 4);
+ slot->current_cmd[5] = (Uint8)s2;
+ slot->current_cmd[6] = SCALE_VALUE_U16(parameters->clip, 8);
+ break;
+ case SDL_HAPTIC_FRICTION:
+ s1 = parameters->k1 < 0;
+ s2 = parameters->k2 < 0;
+ slot->current_cmd[1] = 0x0e;
+ slot->current_cmd[2] = SCALE_COEFF(parameters->k1, 8);
+ slot->current_cmd[3] = SCALE_COEFF(parameters->k2, 8);
+ slot->current_cmd[4] = SCALE_VALUE_U16(parameters->clip, 8);
+ slot->current_cmd[5] = (Uint8)((s2 << 4) + s1);
+ slot->current_cmd[6] = 0;
+ break;
+ }
+ }
+
+ if (SDL_memcmp(original_cmd, slot->current_cmd, sizeof(original_cmd))) {
+ slot->is_updated = 1;
+ }
+}
+
+/*
+ *Ported*
+ Original function by:
+ Bernat Arlandis <[email protected]>
+ `git blame 1a2d5727876dd7befce23d9695924e9446b31c4b hid-lg4ff.c`, https://github.com/berarma/new-lg4ff.git
+*/
+static int lg4ff_init_slots(struct lg4ff_device *device)
+{
+ struct lg4ff_effect_parameters parameters;
+ Uint8 cmd[7] = {0};
+ int i;
+ bool ret;
+
+ // Set/unset fixed loop mode
+ cmd[0] = 0x0d;
+ //cmd[1] = fixed_loop ? 1 : 0;
+ cmd[1] = 0;
+ ret = SDL_SendJoystickEffect(device->hid_handle, cmd, 7);
+ if (!ret) {
+ return -1;
+ }
+
+ SDL_zero(device->states);
+ SDL_zero(device->slots);
+ SDL_zero(parameters);
+
+ device->slots[0].effect_type = SDL_HAPTIC_CONSTANT;
+ device->slots[1].effect_type = SDL_HAPTIC_SPRING;
+ device->slots[2].effect_type = SDL_HAPTIC_DAMPER;
+ device->slots[3].effect_type = SDL_HAPTIC_FRICTION;
+
+ for (i = 0; i < 4; i++) {
+ device->slots[i].id = i;
+ lg4ff_update_slot(&device->slots[i], &parameters);
+ ret = SDL_SendJoystickEffect(device->hid_handle, cmd, 7);
+ if (!ret) {
+ return -1;
+ }
+ device->slots[i].is_updated = 0;
+ }
+
+ return 0;
+}
+
+/*
+ *Ported*
+ Original function by:
+ Bernat Arlandis <[email protected]>
+ `git blame 1a2d5727876dd7befce23d9695924e9446b31c4b hid-lg4ff.c`, https://github.com/berarma/new-lg4ff.git
+*/
+static int lg4ff_timer(struct lg4ff_device *device)
+{
+ struct lg4ff_slot *slot;
+ struct lg4ff_effect_state *state;
+ struct lg4ff_effect_parameters parameters[4];
+ Uint64 now = get_time_ms();
+ Uint16 gain;
+ Sint32 count;
+ Sint32 effect_id;
+ int i;
+ Sint32 ffb_level;
+ int status = 0;
+
+ // XXX how to detect stacked up effects here?
+
+ SDL_zeroa(parameters);
+
+ gain = (Uint16)((Uint32)device->gain * device->app_gain / 0xffff);
+
+ count = device->effects_used;
+
+ for (effect_id = 0; effect_id < LG4FF_MAX_EFFECTS; effect_id++) {
+
+ if (!count) {
+ break;
+ }
+
+ state = &device->states[effect_id];
+
+ if (!test_bit(FF_EFFECT_STARTED, &state->flags)) {
+ continue;
+ }
+
+ count--;
+
+ if (test_bit(FF_EFFECT_ALLSET, &state->flags)) {
+ if (get_effect_replay_length(&state->effect) && time_after_eq(now, state->stop_at)) {
+ STOP_EFFECT(state);
+ if (!--state->count) {
+ device->effects_used--;
+ continue;
+ }
+ __set_bit(FF_EFFECT_STARTED, &state->flags);
+ state->start_at = state->stop_at;
+ }
+ }
+
+ lg4ff_update_state(state, now);
+
+ if (!test_bit(FF_EFFECT_PLAYING, &state->flags)) {
+ continue;
+ }
+
+ if (effect_is_periodic(&state->effect)) {
+ parameters[0].level += lg4ff_calculate_periodic(state);
+ } else {
+ switch (state->effect.type) {
+ case SDL_HAPTIC_CONSTANT:
+ parameters[0].level += lg4ff_calculate_constant(state);
+ break;
+ case SDL_HAPTIC_RAMP:
+ parameters[0].level += lg4ff_calculate_ramp(state);
+ break;
+ case SDL_HAPTIC_SPRING:
+ lg4ff_calculate_spring(state, &parameters[1]);
+ break;
+ case SDL_HAPTIC_DAMPER:
+ lg4ff_calculate_resistance(state, &parameters[2]);
+ break;
+ case SDL_HAPTIC_FRICTION:
+ lg4ff_calculate_resistance(state, &parameters[3]);
+ break;
+ }
+ }
+ }
+
+ parameters[0].level = (Sint32)((Sint64)parameters[0].level * gain / 0xffff);
+ parameters[1].clip = parameters[1].clip * device->spring_level / 100;
+ parameters[2].clip = parameters[2].clip * device->damper_level / 100;
+ parameters[3].clip = parameters[3].clip * device->friction_level / 100;
+
+ ffb_level = abs32(parameters[0].level);
+ for (i = 1; i < 4; i++) {
+ parameters[i].k1 = (Sint32)((Sint64)parameters[i].k1 * gain / 0xffff);
+ parameters[i].k2 = (Sint32)((Sint64)parameters[i].k2 * gain / 0xffff);
+ parameters[i].clip = parameters[i].clip * gain / 0xffff;
+ ffb_level = (Sint32)(ffb_level + parameters[i].clip * 0x7fff / 0xffff);
+ }
+ if (ffb_level > device->peak_ffb_level) {
+ device->peak_ffb_level = ffb_level;
+ }
+
+ for (i = 0; i < 4; i++) {
+ slot = &device->slots[i];
+ lg4ff_update_slot(slot, &parameters[i]);
+ if (slot->is_updated) {
+ bool ret = SDL_SendJoystickEffect(device->hid_handle, slot->current_cmd, 7);
+ if (!ret) {
+ status = -1;
+ }
+ slot->is_updated = 0;
+ }
+ }
+
+ return status;
+}
+
+static bool SDL_HIDAPI_HapticDriverLg4ff_JoystickSupported(SDL_Joystick *joystick)
+{
+ Uint16 vendor_id = SDL_GetJoystickVendor(joystick);
+ Uint16 product_id = SDL_GetJoystickProduct(joystick);
+ if (vendor_id != USB_VENDOR_ID_LOGITECH) {
+ return false;
+ }
+ for (int i = 0;i < SDL_arraysize(supported_device_ids);i++) {
+ if (supported_device_ids[i] == product_id) {
+ return true;
+ }
+ }
+ return false;
+}
+
+static int SDLCALL SDL_HIDAPI_HapticDriverLg4ff_ThreadFunction(void *ctx_in)
+{
+ lg4ff_device *ctx = (lg4ff_device *)ctx_in;
+ while (true) {
+ if (ctx->stop_thread) {
+ return 0;
+ }
+ SDL_LockMutex(ctx->mutex);
+ lg4ff_timer(ctx);
+ SDL_UnlockMutex(ctx->mutex);
+ SDL_Delay(2);
+ }
+}
+
+static int SDL_HIDAPI_HapticDriverLg4ff_GetEnvInt(const char *env_name, int min, int max, int def)
+{
+ const char *env = SDL_getenv(env_name);
+ int value = 0;
+ if (env == NULL) {
+ return def;
+ }
+ value = SDL_atoi(env);
+ if (value < min) {
+ value = min;
+ }
+ if (value > max) {
+ value = max;
+ }
+ return value;
+}
+
+/*
+ ffex identification method by:
+ Simon Wood <[email protected]>
+ lg4ff_init
+ `git blame v6.12 drivers/hid/hid-lg4ff.c`, https://github.com/torvalds/linux.git
+*/
+static void *SDL_HIDAPI_HapticDriverLg4ff_Open(SDL_Joystick *joystick)
+{
+ lg4ff_device *ctx;
+ if (!SDL_HIDAPI_HapticDriverLg4ff_JoystickSupported(joystick)) {
+ SDL_SetError("Device not supported by the lg4ff hidapi haptic driver");
+ return NULL;
+ }
+
+ ctx = SDL_malloc(sizeof(lg4ff_device));
+ if (ctx == NULL) {
+ SDL_OutOfMemory();
+ return NULL;
+ }
+ SDL_zerop(ctx);
+
+ ctx->hid_handle = joystick;
+ if (lg4ff_init_slots(ctx) != 0) {
+ SDL_SetError("lg4ff hidapi driver failed initializing effect slots");
+ SDL_free(ctx);
+ return NULL;
+ }
+
+ ctx->mutex = SDL_CreateMutex();
+ if (ctx->mutex == NULL) {
+ SDL_free(ctx);
+ return NULL;
+ }
+
+ ctx->spring_level = SDL_HIDAPI_HapticDriverLg4ff_GetEnvInt("SDL_HAPTIC_LG4FF_SPRING", 0, 100, 30);
+ ctx->damper_level = SDL_HIDAPI_HapticDriverLg4ff_GetEnvInt("SDL_HAPTIC_LG4FF_DAMPER", 0, 100, 30);
+ ctx->friction_level = SDL_HIDAPI_HapticDriverLg4ff_GetEnvInt("SDL_HAPTIC_LG4FF_FRICTION", 0, 100, 30);
+ ctx->gain = SDL_HIDAPI_HapticDriverLg4ff_GetEnvInt("SDL_HAPTIC_LG4FF_GAIN", 0, 65535, 65535);
+ ctx->app_gain = 65535;
+
+ ctx->product_id = SDL_GetJoystickProduct(joystick);
+ ctx->release_number = SDL_GetJoystickProductVersion(joystick);
+
+ SDL_snprintf(ctx->thread_name_buf, sizeof(ctx->thread_name_buf), "SDL_hidapihaptic_lg4ff %d %04x:%04x", SDL_GetJoystickID(joystick), USB_VENDOR_ID_LOGITECH, ctx->product_id);
+ ctx->stop_thread = false;
+ ctx->thread = SDL_CreateThread(SDL_HIDAPI_HapticDriverLg4ff_ThreadFunction, ctx->thread_name_buf, ctx);
+
+ if (ctx->product_id == USB_DEVICE_ID_LOGITECH_WHEEL &&
+ (ctx->release_number >> 8) == 0x21 &&
+ (ctx->release_number & 0xff) == 0x00) {
+ ctx->is_ffex = true;
+ } else {
+ ctx->is_ffex = false;
+ }
+
+ return ctx;
+}
+
+static bool SDL_HIDAPI_HapticDriverLg4ff_StopEffects(SDL_HIDAPI_HapticDevice *device)
+{
+ lg4ff_device *ctx = (lg4ff_device *)device->ctx;
+ int i;
+
+ SDL_LockMutex(ctx->mutex);
+ for (i = 0;i < LG4FF_MAX_EFFECTS;i++) {
+ struct lg4ff_effect_state *state = &ctx->states[i];
+ STOP_EFFECT(state);
+ }
+ SDL_UnlockMutex(ctx->mutex);
+
+ return true;
+}
+
+static void SDL_HIDAPI_HapticDriverLg4ff_Close(SDL_HIDAPI_HapticDevice *device)
+{
+ lg4ff_device *ctx = (lg4ff_device *)device->ctx;
+
+ SDL_HIDAPI_HapticDriverLg4ff_StopEffects(device);
+
+ // let effects finish in lg4ff_timer
+ SDL_Delay(50);
+
+ ctx->stop_thread = true;
+ SDL_WaitThread(ctx->thread, NULL);
+ SDL_DestroyMutex(ctx->mutex);
+}
+
+static int SDL_HIDAPI_HapticDriverLg4ff_NumEffects(SDL_HIDAPI_HapticDevice *device)
+{
+ return LG4FF_MAX_EFFECTS;
+}
+
+static Uint32 SDL_HIDAPI_HapticDriverLg4ff_GetFeatures(SDL_HIDAPI_HapticDevice *device)
+{
+ return SDL_HAPTIC_CONSTANT |
+ SDL_HAPTIC_SPRING |
+ SDL_HAPTIC_DAMPER |
+ SDL_HAPTIC_AUTOCENTER |
+ SDL_HAPTIC_SINE |
+ SDL_HAPTIC_SQUARE |
+ SDL_HAPTIC_TRIANGLE |
+ SDL_HAPTIC_SAWTOOTHUP |
+ SDL_HAPTIC_SAWTOOTHDOWN |
+ SDL_HAPTIC_RAMP |
+ SDL_HAPTIC_FRICTION |
+ SDL_HAPTIC_STATUS |
+ SDL_HAPTIC_GAIN;
+}
+
+static bool SDL_HIDAPI_HapticDriverLg4ff_EffectSupported(SDL_HIDAPI_HapticDevice *device, const SDL_HapticEffect *effect) {
+ Uint32 features = SDL_HIDAPI_HapticDriverLg4ff_GetFeatures(device);
+ return (features & effect->type)? true : false;
+}
+
+static int SDL_HIDAPI_HapticDriverLg4ff_NumAxes(SDL_HIDAPI_HapticDevice *device)
+{
+ return 1;
+}
+
+static SDL_HapticEffectID SDL_HIDAPI_HapticDriverLg4ff_CreateEffect(SDL_HIDAPI_HapticDevice *device, const SDL_HapticEffect *data)
+{
+ lg4ff_device *ctx = (lg4ff_device *)device->ctx;
+ SDL_HapticEffectID i;
+ SDL_HapticEffectID state_slot = -1;
+ int ret;
+ if (!SDL_HIDAPI_HapticDriverLg4ff_EffectSupported(device, data)) {
+ SDL_SetError("Unsupported effect");
+ return -1;
+ }
+
+ SDL_LockMutex(ctx->mutex);
+ for (i = 0;i < LG4FF_MAX_EFFECTS;i++) {
+ if (!ctx->states[i].allocated) {
+ state_slot = i;
+ break;
+ }
+ }
+ if (state_slot == -1) {
+ SDL_UnlockMutex(ctx->mutex);
+ SDL_SetError("All effect slots in-use");
+ return -1;
+ }
+
+ ret = lg4ff_upload_effect(ctx, data, state_slot);
+ SDL_UnlockMutex(ctx->mutex);
+ if (ret == 0) {
+ ctx->states[state_slot].allocated = true;
+ return state_slot;
+ } else {
+ SDL_SetError("Bad effect parameters");
+ return -1;
+ }
+}
+
+// assumes ctx->mutex locked
+static bool lg4ff_effect_slot_valid_active(lg4ff_device *ctx, SDL_HapticEffectID id)
+{
+ if (id >= LG4FF_MAX_EFFECTS || id < 0) {
+ return false;
+ }
+ if (!ctx->states[id].allocated) {
+ return false;
+ }
+ return true;
+}
+
+static bool SDL_HIDAPI_HapticDriverLg4ff_UpdateEffect(SDL_HIDAPI_HapticDevice *device, SDL_HapticEffectID id, const SDL_HapticEffect *data)
+{
+ lg4ff_device *ctx = (lg4ff_device *)device->ctx;
+ int ret;
+
+ SDL_LockMutex(ctx->mutex);
+ if (!lg4ff_effect_slot_valid_active(ctx, id)) {
+ SDL_UnlockMutex(ctx->mutex);
+ SDL_SetError("Bad effect id");
+ return false;
+ }
+
+ ret = lg4ff_upload_effect(ctx, data, id);
+ SDL_UnlockMutex(ctx->mutex);
+
+ return ret == 0;
+}
+
+static bool SDL_HIDAPI_HapticDriverLg4ff_RunEffect(SDL_HIDAPI_HapticDevice *device, SDL_HapticEffectID id, Uint32 iterations)
+{
+ lg4ff_device *ctx = (lg4ff_device *)device->ctx;
+ int ret;
+
+ SDL_LockMutex(ctx->mutex);
+ if (!lg4ff_effect_slot_valid_active(ctx, id)) {
+ SDL_UnlockMutex(ctx->mutex);
+ SDL_SetError("Bad effect id");
+ return false;
+ }
+
+ ret = lg4ff_play_effect(ctx, id, iterations);
+ SDL_UnlockMutex(ctx->mutex);
+
+ return ret == 0;
+}
+
+static bool SDL_HIDAPI_HapticDriverLg4ff_StopEffect(SDL_HIDAPI_HapticDevice *device, SDL_HapticEffectID id)
+{
+ return SDL_HIDAPI_HapticDriverLg4ff_RunEffect(device, id, 0);
+}
+
+static void SDL_HIDAPI_HapticDriverLg4ff_DestroyEffect(SDL_HIDAPI_HapticDevice *device, SDL_HapticEffectID id)
+{
+ lg4ff_device *ctx = (lg4ff_device *)device->ctx;
+ struct lg4ff_effect_state *state;
+
+ SDL_LockMutex(ctx->mutex);
+ if (!lg4ff_effect_slot_valid_active(ctx, id)) {
+ SDL_UnlockMutex(ctx->mutex);
+ return;
+ }
+
+ state = &ctx->states[id];
+ STOP_EFFECT(state);
+ state->allocated = false;
+
+ SDL_UnlockMutex(ctx->mutex);
+}
+
+static bool SDL_HIDAPI_HapticDriverLg4ff_GetEffectStatus(SDL_HIDAPI_HapticDevice *device, SDL_HapticEffectID id)
+{
+ lg4ff_device *ctx = (lg4ff_device *)device->ctx;
+ bool ret = false;
+
+ SDL_LockMutex(ctx->mutex);
+ if (!lg4ff_effect_slot_valid_active(ctx, id)) {
+ SDL_UnlockMutex(ctx->mutex);
+ return false;
+ }
+
+ if (test_bit(FF_EFFECT_STARTED, &ctx->states[id].flags)) {
+ ret = true;
+ }
+ SDL_UnlockMutex(ctx->mutex);
+
+ return ret;
+}
+
+static bool SDL_HIDAPI_HapticDriverLg4ff_SetGain(SDL_HIDAPI_HapticDevice *device, int gain)
+{
+ lg4ff_device *ctx = (lg4ff_device *)device->ctx;
+ if (gain > 100) {
+ gain = 100;
+ }
+ if (gain < 0) {
+ gain = 0;
+ }
+ ctx->app_gain = (65535 * gain) / 100;
+ return true;
+}
+
+/*
+ *Ported*
+ Original functions by:
+ Simon Wood <[email protected]>
+ lg4ff_set_autocenter_default lg4ff_set_autocenter_ffex
+ `git blame v6.12 drivers/hid/hid-lg4ff.c`, https://github.com/torvalds/linux.git
+*/
+static bool SDL_HIDAPI_HapticDriverLg4ff_SetAutocenter(SDL_HIDAPI_HapticDevice *device, int autocenter)
+{
+ lg4ff_device *ctx = (lg4ff_device *)device->ctx;
+ Uint8 cmd[7] = {0};
+ bool ret;
+
+ if (autocenter < 0) {
+ autocenter = 0;
+ }
+ if (autocenter > 100) {
+ autocenter = 100;
+ }
+
+ SDL_LockMutex(ctx->mutex);
+ if (ctx->is_ffex) {
+ int magnitude = (90 * autocenter) / 100;
+
+ cmd[0] = 0xfe;
+ cmd[1] = 0x03;
+ cmd[2] = (Uint8)((Uint16)magnitude >> 14);
+ cmd[3] = (Uint8)((Uint16)magnitude >> 14);
+ cmd[4] = (Uint8)magnitude;
+
+ ret = SDL_SendJoystickEffect(ctx->hid_handle, cmd, sizeof(cmd));
+ if (!ret) {
+ SDL_UnlockMutex(ctx->mutex);
+ SDL_SetError("Failed sending autocenter command");
+ return false;
+ }
+ } else {
+ Uint32 expand_a;
+ Uint32 expand_b;
+ int magnitude = (65535 * autocenter) / 100;
+
+ // first disable
+ cmd[0] = 0xf5;
+
+ ret = SDL_SendJoystickEffect(ctx->hid_handle, cmd, sizeof(cmd));
+ if (!ret) {
+ SDL_UnlockMutex(ctx->mutex);
+ SDL_SetError("Failed sending autocenter disable command");
+ return false;
+ }
+
+ if (magnitude == 0) {
+ SDL_UnlockMutex(ctx->mutex);
+ return true;
+ }
+
+ // set strength
+ if (magnitude <= 0xaaaa) {
+ expand_a = 0x0c * magnitude;
+ expand_b = 0x80 * magnitude;
+ } else {
+ expand_a = (0x0c * 0xaaaa) + 0x06 * (magnitude - 0xaaaa);
+ expand_b = (0x80 * 0xaaaa) + 0xff * (magnitude - 0xaaaa);
+ }
+ expand_a = expand_a >> 1;
+
+ SDL_zeroa(cmd);
+ cmd[0] = 0xfe;
+ cmd[1] = 0x0d;
+ cmd[2] = (Uint8)(expand_a / 0xaaaa);
+ cmd[3] = (Uint8)(expand_a / 0xaaaa);
+ cmd[4] = (Uint8)(expand_b / 0xaaaa);
+
+ ret = SDL_SendJoystickEffect(ctx->hid_handle, cmd, sizeof(cmd));
+ if (!ret) {
+ SDL_UnlockMutex(ctx->mutex);
+ SDL_SetError("Failed sending autocenter magnitude command");
+ return false;
+ }
+
+ // enable
+ SDL_zeroa(cmd);
+ cmd[0] = 0x14;
+
+ ret = SDL_SendJoystickEffect(ctx->hid_handle, cmd, sizeof(cmd));
+ if (!ret) {
+ SDL_UnlockMutex(ctx->mutex);
+ SDL_SetError("Failed sending autocenter enable command");
+ return false;
+ }
+ }
+ SDL_UnlockMutex(ctx->mutex);
+ return true;
+}
+
+static bool SDL_HIDAPI_HapticDriverLg4ff_Pause(SDL_HIDAPI_HapticDevice *device)
+{
+ return SDL_Unsupported();
+}
+
+static bool SDL_HIDAPI_HapticDriverLg4ff_Resume(SDL_HIDAPI_HapticDevice *device)
+{
+ return SDL_Unsupported();
+}
+
+SDL_HIDAPI_HapticDriver SDL_HIDAPI_HapticDriverLg4ff = {
+ SDL_HIDAPI_HapticDriverLg4ff_JoystickSupported,
+ SDL_HIDAPI_HapticDriverLg4ff_Open,
+ SDL_HIDAPI_HapticDriverLg4ff_Close,
+ SDL_HIDAPI_HapticDriverLg4ff_NumEffects,
+ SDL_HIDAPI_HapticDriverLg4ff_NumEffects,
+ SDL_HIDAPI_HapticDriverLg4ff_GetFeatures,
+ SDL_HIDAPI_HapticDriverLg4ff_NumAxes,
+ SDL_HIDAPI_HapticDriverLg4ff_CreateEffect,
+ SDL_HIDAPI_HapticDriverLg4ff_UpdateEffect,
+ SDL_HIDAPI_HapticDriverLg4ff_RunEffect,
+ SDL_HIDAPI_HapticDriverLg4ff_StopEffect,
+ SDL_HIDAPI_HapticDriverLg4ff_DestroyEffect,
+ SDL_HIDAPI_HapticDriverLg4ff_GetEffectStatus,
+ SDL_HIDAPI_HapticDriverLg4ff_SetGain,
+ SDL_HIDAPI_HapticDriverLg4ff_SetAutocenter,
+ SDL_HIDAPI_HapticDriverLg4ff_Pause,
+ SDL_HIDAPI_HapticDriverLg4ff_Resume,
+ SDL_HIDAPI_HapticDriverLg4ff_StopEffects,
+};
+
+#endif //SDL_HAPTIC_HIDAPI_LG4FF
+#endif //SDL_JOYSTICK_HIDAPI
diff --git a/thirdparty/sdl/haptic/linux/SDL_syshaptic.c b/thirdparty/sdl/haptic/linux/SDL_syshaptic.c
index fa49e457bd4..e107562565b 100644
--- a/thirdparty/sdl/haptic/linux/SDL_syshaptic.c
+++ b/thirdparty/sdl/haptic/linux/SDL_syshaptic.c
@@ -1,6 +1,6 @@
/*
Simple DirectMedia Layer
- Copyright (C) 1997-2025 Sam Lantinga <[email protected]>
+ Copyright (C) 1997-2026 Sam Lantinga <[email protected]>
This software is provided 'as-is', without any express or implied
warranty. In no event will the authors be held liable for any damages
@@ -603,7 +603,7 @@ void SDL_SYS_HapticClose(SDL_Haptic *haptic)
}
// Clear the rest.
- SDL_memset(haptic, 0, sizeof(SDL_Haptic));
+ SDL_zerop(haptic);
}
/*
@@ -725,7 +725,7 @@ static bool SDL_SYS_ToFFEffect(struct ff_effect *dest, const SDL_HapticEffect *s
const SDL_HapticLeftRight *leftright;
// Clear up
- SDL_memset(dest, 0, sizeof(struct ff_effect));
+ SDL_zerop(dest);
switch (src->type) {
case SDL_HAPTIC_CONSTANT:
diff --git a/thirdparty/sdl/haptic/windows/SDL_dinputhaptic.c b/thirdparty/sdl/haptic/windows/SDL_dinputhaptic.c
index 79c4b3501f0..fa374e43019 100644
--- a/thirdparty/sdl/haptic/windows/SDL_dinputhaptic.c
+++ b/thirdparty/sdl/haptic/windows/SDL_dinputhaptic.c
@@ -1,6 +1,6 @@
/*
Simple DirectMedia Layer
- Copyright (C) 1997-2025 Sam Lantinga <[email protected]>
+ Copyright (C) 1997-2026 Sam Lantinga <[email protected]>
This software is provided 'as-is', without any express or implied
warranty. In no event will the authors be held liable for any damages
@@ -599,7 +599,7 @@ static bool SDL_SYS_ToDIEFFECT(SDL_Haptic *haptic, DIEFFECT *dest,
DWORD *axes;
// Set global stuff.
- SDL_memset(dest, 0, sizeof(DIEFFECT));
+ SDL_zerop(dest);
dest->dwSize = sizeof(DIEFFECT); // Set the structure size.
dest->dwSamplePeriod = 0; // Not used by us.
dest->dwGain = 10000; // Gain is set globally, not locally.
@@ -946,6 +946,103 @@ err_effectdone:
return false;
}
+BOOL DIGetDirectionUpdateFlag(DIEFFECT *before, DIEFFECT *after)
+{
+ if (before->cAxes != after->cAxes) {
+ return true;
+ }
+ // rglDirection must be non-null for DIEP_DIRECTION to be a valid flag
+ if (after->rglDirection == NULL) {
+ return false;
+ }
+ if (before->rglDirection == NULL) {
+ return true;
+ }
+ return SDL_memcmp(before->rglDirection, after->rglDirection, sizeof(LONG) * before->cAxes) != 0;
+}
+
+BOOL DIGetEnvelopeUpdateFlag(DIEFFECT* before, DIEFFECT* after)
+{
+ if (before->lpEnvelope == NULL && after->lpEnvelope == NULL) {
+ return false;
+ }
+ // A null lpEnvelope is valid for DIEP_ENVELOPE (clears the envelope from the effect)
+ if (before->lpEnvelope == NULL || after->lpEnvelope == NULL) {
+ return true;
+ }
+ return SDL_memcmp(before->lpEnvelope, after->lpEnvelope, sizeof(DIENVELOPE)) != 0;
+}
+
+BOOL DIGetTypeSpecificParamsUpdateFlag(DIEFFECT *before, DIEFFECT *after)
+{
+ // Shouldn't happen since this implies an effect's type somehow changed, but need to check to avoid an out-of-bounds memcmp
+ if (before->cbTypeSpecificParams != after->cbTypeSpecificParams) {
+ return true;
+ }
+ // lpvTypeSpecificParams must be non-null for the DIEP_TYPESPECIFICPARAMS flag.
+ if (after->lpvTypeSpecificParams == NULL) {
+ return false;
+ }
+ if (before->lpvTypeSpecificParams == NULL) {
+ return true;
+ }
+ return SDL_memcmp(before->lpvTypeSpecificParams, after->lpvTypeSpecificParams, before->cbTypeSpecificParams) != 0;
+}
+
+/*
+ Calculate the exact flags needed when updating an existing DirectInput haptic effect.
+*/
+DWORD DICalculateUpdateFlags(DIEFFECT *before, DIEFFECT *after)
+{
+ DWORD flags = 0;
+
+ if (DIGetDirectionUpdateFlag(before, after)) {
+ flags |= DIEP_DIRECTION;
+ }
+
+ if (before->dwDuration != after->dwDuration) {
+ flags |= DIEP_DURATION;
+ }
+
+ if (DIGetEnvelopeUpdateFlag(before, after)) {
+ flags |= DIEP_ENVELOPE;
+ }
+
+ if (before->dwStartDelay != after->dwStartDelay) {
+ flags |= DIEP_STARTDELAY;
+ }
+
+ if (before->dwTriggerButton != after->dwTriggerButton) {
+ flags |= DIEP_TRIGGERBUTTON;
+ }
+
+ if (before->dwTriggerRepeatInterval != after->dwTriggerRepeatInterval) {
+ flags |= DIEP_TRIGGERREPEATINTERVAL;
+ }
+
+ if (DIGetTypeSpecificParamsUpdateFlag(before, after)) {
+ flags |= DIEP_TYPESPECIFICPARAMS;
+ }
+
+ if (flags == 0) {
+ /* Awkward: SDL_UpdateHapticEffect was called, but nothing was changed.
+ * Calling IDirectInputEffect_SetParameters with no flags is nonsense,
+ * so our options are to either send all the flags, or exit early.
+ * Sending all the flags seems like the safer option: The programmer may be trying
+ * to force an update for some reason (e.g. driver bug workaround?). Conversely,
+ * if the programmer doesn't want IDirectInputEffect_SetParameters to be called, they
+ * can just avoid calling SDL_UpdateHapticEffect when there's no changes. */
+ flags = DIEP_DIRECTION |
+ DIEP_DURATION |
+ DIEP_ENVELOPE |
+ DIEP_STARTDELAY |
+ DIEP_TRIGGERBUTTON |
+ DIEP_TRIGGERREPEATINTERVAL | DIEP_TYPESPECIFICPARAMS;
+ }
+
+ return flags;
+}
+
bool SDL_DINPUT_HapticUpdateEffect(SDL_Haptic *haptic, struct haptic_effect *effect, const SDL_HapticEffect *data)
{
HRESULT ret;
@@ -953,19 +1050,12 @@ bool SDL_DINPUT_HapticUpdateEffect(SDL_Haptic *haptic, struct haptic_effect *eff
DIEFFECT temp;
// Get the effect.
- SDL_memset(&temp, 0, sizeof(DIEFFECT));
+ SDL_zero(temp);
if (!SDL_SYS_ToDIEFFECT(haptic, &temp, data)) {
goto err_update;
}
- /* Set the flags. Might be worthwhile to diff temp with loaded effect and
- * only change those parameters. */
- flags = DIEP_DIRECTION |
- DIEP_DURATION |
- DIEP_ENVELOPE |
- DIEP_STARTDELAY |
- DIEP_TRIGGERBUTTON |
- DIEP_TRIGGERREPEATINTERVAL | DIEP_TYPESPECIFICPARAMS;
+ flags = DICalculateUpdateFlags(&effect->hweffect->effect, &temp);
// Create the actual effect.
ret =
diff --git a/thirdparty/sdl/haptic/windows/SDL_dinputhaptic_c.h b/thirdparty/sdl/haptic/windows/SDL_dinputhaptic_c.h
index d6265c926cb..a06c3e4a8e5 100644
--- a/thirdparty/sdl/haptic/windows/SDL_dinputhaptic_c.h
+++ b/thirdparty/sdl/haptic/windows/SDL_dinputhaptic_c.h
@@ -1,6 +1,6 @@
/*
Simple DirectMedia Layer
- Copyright (C) 1997-2025 Sam Lantinga <[email protected]>
+ Copyright (C) 1997-2026 Sam Lantinga <[email protected]>
This software is provided 'as-is', without any express or implied
warranty. In no event will the authors be held liable for any damages
diff --git a/thirdparty/sdl/haptic/windows/SDL_windowshaptic.c b/thirdparty/sdl/haptic/windows/SDL_windowshaptic.c
index e21ab918da0..e58faad410f 100644
--- a/thirdparty/sdl/haptic/windows/SDL_windowshaptic.c
+++ b/thirdparty/sdl/haptic/windows/SDL_windowshaptic.c
@@ -1,6 +1,6 @@
/*
Simple DirectMedia Layer
- Copyright (C) 1997-2025 Sam Lantinga <[email protected]>
+ Copyright (C) 1997-2026 Sam Lantinga <[email protected]>
This software is provided 'as-is', without any express or implied
warranty. In no event will the authors be held liable for any damages
diff --git a/thirdparty/sdl/haptic/windows/SDL_windowshaptic_c.h b/thirdparty/sdl/haptic/windows/SDL_windowshaptic_c.h
index c4b69287ba1..202cb871853 100644
--- a/thirdparty/sdl/haptic/windows/SDL_windowshaptic_c.h
+++ b/thirdparty/sdl/haptic/windows/SDL_windowshaptic_c.h
@@ -1,6 +1,6 @@
/*
Simple DirectMedia Layer
- Copyright (C) 1997-2025 Sam Lantinga <[email protected]>
+ Copyright (C) 1997-2026 Sam Lantinga <[email protected]>
This software is provided 'as-is', without any express or implied
warranty. In no event will the authors be held liable for any damages
diff --git a/thirdparty/sdl/hidapi/SDL_hidapi.c b/thirdparty/sdl/hidapi/SDL_hidapi.c
index 2378db68bd7..abb85676004 100644
--- a/thirdparty/sdl/hidapi/SDL_hidapi.c
+++ b/thirdparty/sdl/hidapi/SDL_hidapi.c
@@ -1,6 +1,6 @@
/*
Simple DirectMedia Layer
- Copyright (C) 1997-2025 Sam Lantinga <[email protected]>
+ Copyright (C) 1997-2026 Sam Lantinga <[email protected]>
This software is provided 'as-is', without any express or implied
warranty. In no event will the authors be held liable for any damages
@@ -32,6 +32,7 @@
#include "SDL_hidapi_c.h"
#include "../joystick/usb_ids.h"
+#include "../joystick/SDL_joystick_c.h"
#include "../SDL_hints_c.h"
// Initial type declarations
@@ -40,6 +41,15 @@
#ifndef SDL_HIDAPI_DISABLED
+#ifdef SDL_LIBUSB_DYNAMIC
+SDL_ELF_NOTE_DLOPEN(
+ "hidabi-libusb",
+ "Support for joysticks through libusb",
+ SDL_ELF_NOTE_DLOPEN_PRIORITY_SUGGESTED,
+ SDL_LIBUSB_DYNAMIC
+)
+#endif
+
#if defined(SDL_PLATFORM_WIN32) || defined(SDL_PLATFORM_WINGDK)
#include "../core/windows/SDL_windows.h"
#endif
@@ -378,18 +388,20 @@ static void HIDAPI_UpdateDiscovery(void)
}
#if defined(SDL_PLATFORM_WIN32) || defined(SDL_PLATFORM_WINGDK)
-#if 0 // just let the usual SDL_PumpEvents loop dispatch these, fixing bug 4286. --ryan.
- // We'll only get messages on the same thread that created the window
- if (SDL_GetCurrentThreadID() == SDL_HIDAPI_discovery.m_nThreadID) {
- MSG msg;
- while (PeekMessage(&msg, SDL_HIDAPI_discovery.m_hwndMsg, 0, 0, PM_NOREMOVE)) {
- if (GetMessageA(&msg, SDL_HIDAPI_discovery.m_hwndMsg, 0, 0) != 0) {
- TranslateMessage(&msg);
- DispatchMessage(&msg);
+ if (SDL_IsVideoThread()) {
+ // just let the usual SDL_PumpEvents loop dispatch these, fixing bug 2998. --ryan.
+ } else {
+ // We'll only get messages on the same thread that created the window
+ if (SDL_GetCurrentThreadID() == SDL_HIDAPI_discovery.m_nThreadID) {
+ MSG msg;
+ while (PeekMessage(&msg, SDL_HIDAPI_discovery.m_hwndMsg, 0, 0, PM_NOREMOVE)) {
+ if (GetMessageA(&msg, SDL_HIDAPI_discovery.m_hwndMsg, 0, 0) != 0) {
+ TranslateMessage(&msg);
+ DispatchMessage(&msg);
+ }
}
}
}
-#endif
#endif // defined(SDL_PLATFORM_WIN32) || defined(SDL_PLATFORM_WINGDK)
#ifdef SDL_PLATFORM_MACOS
@@ -531,8 +543,8 @@ static void HIDAPI_ShutdownDiscovery(void)
// Platform HIDAPI Implementation
#define HIDAPI_USING_SDL_RUNTIME
-#define HIDAPI_IGNORE_DEVICE(BUS, VID, PID, USAGE_PAGE, USAGE) \
- SDL_HIDAPI_ShouldIgnoreDevice(BUS, VID, PID, USAGE_PAGE, USAGE)
+#define HIDAPI_IGNORE_DEVICE(BUS, VID, PID, USAGE_PAGE, USAGE, LIBUSB, LIBUSB_XBOX) \
+ SDL_HIDAPI_ShouldIgnoreDevice(BUS, VID, PID, USAGE_PAGE, USAGE, LIBUSB, LIBUSB_XBOX)
struct PLATFORM_hid_device_;
typedef struct PLATFORM_hid_device_ PLATFORM_hid_device;
@@ -689,131 +701,81 @@ typedef struct DRIVER_hid_device_ DRIVER_hid_device;
#ifdef HAVE_LIBUSB
// libusb HIDAPI Implementation
-// Include this now, for our dynamically-loaded libusb context
-#include <libusb.h>
-
-static struct
-{
- SDL_SharedObject *libhandle;
-
- /* *INDENT-OFF* */ // clang-format off
- int (LIBUSB_CALL *init)(libusb_context **ctx);
- void (LIBUSB_CALL *exit)(libusb_context *ctx);
- ssize_t (LIBUSB_CALL *get_device_list)(libusb_context *ctx, libusb_device ***list);
- void (LIBUSB_CALL *free_device_list)(libusb_device **list, int unref_devices);
- int (LIBUSB_CALL *get_device_descriptor)(libusb_device *dev, struct libusb_device_descriptor *desc);
- int (LIBUSB_CALL *get_active_config_descriptor)(libusb_device *dev, struct libusb_config_descriptor **config);
- int (LIBUSB_CALL *get_config_descriptor)(
- libusb_device *dev,
- uint8_t config_index,
- struct libusb_config_descriptor **config
- );
- void (LIBUSB_CALL *free_config_descriptor)(struct libusb_config_descriptor *config);
- uint8_t (LIBUSB_CALL *get_bus_number)(libusb_device *dev);
- int (LIBUSB_CALL *get_port_numbers)(libusb_device *dev, uint8_t *port_numbers, int port_numbers_len);
- uint8_t (LIBUSB_CALL *get_device_address)(libusb_device *dev);
- int (LIBUSB_CALL *open)(libusb_device *dev, libusb_device_handle **dev_handle);
- void (LIBUSB_CALL *close)(libusb_device_handle *dev_handle);
- libusb_device *(LIBUSB_CALL *get_device)(libusb_device_handle *dev_handle);
- int (LIBUSB_CALL *claim_interface)(libusb_device_handle *dev_handle, int interface_number);
- int (LIBUSB_CALL *release_interface)(libusb_device_handle *dev_handle, int interface_number);
- int (LIBUSB_CALL *kernel_driver_active)(libusb_device_handle *dev_handle, int interface_number);
- int (LIBUSB_CALL *detach_kernel_driver)(libusb_device_handle *dev_handle, int interface_number);
- int (LIBUSB_CALL *attach_kernel_driver)(libusb_device_handle *dev_handle, int interface_number);
- int (LIBUSB_CALL *set_interface_alt_setting)(libusb_device_handle *dev, int interface_number, int alternate_setting);
- struct libusb_transfer * (LIBUSB_CALL *alloc_transfer)(int iso_packets);
- int (LIBUSB_CALL *submit_transfer)(struct libusb_transfer *transfer);
- int (LIBUSB_CALL *cancel_transfer)(struct libusb_transfer *transfer);
- void (LIBUSB_CALL *free_transfer)(struct libusb_transfer *transfer);
- int (LIBUSB_CALL *control_transfer)(
- libusb_device_handle *dev_handle,
- uint8_t request_type,
- uint8_t bRequest,
- uint16_t wValue,
- uint16_t wIndex,
- unsigned char *data,
- uint16_t wLength,
- unsigned int timeout
- );
- int (LIBUSB_CALL *interrupt_transfer)(
- libusb_device_handle *dev_handle,
- unsigned char endpoint,
- unsigned char *data,
- int length,
- int *actual_length,
- unsigned int timeout
- );
- int (LIBUSB_CALL *handle_events)(libusb_context *ctx);
- int (LIBUSB_CALL *handle_events_completed)(libusb_context *ctx, int *completed);
- const char * (LIBUSB_CALL *error_name)(int errcode);
-/* *INDENT-ON* */ // clang-format on
-
-} libusb_ctx;
-
-#define libusb_init libusb_ctx.init
-#define libusb_exit libusb_ctx.exit
-#define libusb_get_device_list libusb_ctx.get_device_list
-#define libusb_free_device_list libusb_ctx.free_device_list
-#define libusb_get_device_descriptor libusb_ctx.get_device_descriptor
-#define libusb_get_active_config_descriptor libusb_ctx.get_active_config_descriptor
-#define libusb_get_config_descriptor libusb_ctx.get_config_descriptor
-#define libusb_free_config_descriptor libusb_ctx.free_config_descriptor
-#define libusb_get_bus_number libusb_ctx.get_bus_number
-#define libusb_get_port_numbers libusb_ctx.get_port_numbers
-#define libusb_get_device_address libusb_ctx.get_device_address
-#define libusb_open libusb_ctx.open
-#define libusb_close libusb_ctx.close
-#define libusb_get_device libusb_ctx.get_device
-#define libusb_claim_interface libusb_ctx.claim_interface
-#define libusb_release_interface libusb_ctx.release_interface
-#define libusb_kernel_driver_active libusb_ctx.kernel_driver_active
-#define libusb_detach_kernel_driver libusb_ctx.detach_kernel_driver
-#define libusb_attach_kernel_driver libusb_ctx.attach_kernel_driver
-#define libusb_set_interface_alt_setting libusb_ctx.set_interface_alt_setting
-#define libusb_alloc_transfer libusb_ctx.alloc_transfer
-#define libusb_submit_transfer libusb_ctx.submit_transfer
-#define libusb_cancel_transfer libusb_ctx.cancel_transfer
-#define libusb_free_transfer libusb_ctx.free_transfer
-#define libusb_control_transfer libusb_ctx.control_transfer
-#define libusb_interrupt_transfer libusb_ctx.interrupt_transfer
-#define libusb_handle_events libusb_ctx.handle_events
-#define libusb_handle_events_completed libusb_ctx.handle_events_completed
-#define libusb_error_name libusb_ctx.error_name
+#include "../misc/SDL_libusb.h"
+
+static SDL_LibUSBContext *libusb_ctx;
+
+#define libusb_init libusb_ctx->init
+#define libusb_exit libusb_ctx->exit
+#define libusb_get_device_list libusb_ctx->get_device_list
+#define libusb_free_device_list libusb_ctx->free_device_list
+#define libusb_get_device_descriptor libusb_ctx->get_device_descriptor
+#define libusb_get_active_config_descriptor libusb_ctx->get_active_config_descriptor
+#define libusb_get_config_descriptor libusb_ctx->get_config_descriptor
+#define libusb_free_config_descriptor libusb_ctx->free_config_descriptor
+#define libusb_get_bus_number libusb_ctx->get_bus_number
+#define libusb_get_port_numbers libusb_ctx->get_port_numbers
+#define libusb_get_device_address libusb_ctx->get_device_address
+#define libusb_open libusb_ctx->open
+#define libusb_close libusb_ctx->close
+#define libusb_get_device libusb_ctx->get_device
+#define libusb_claim_interface libusb_ctx->claim_interface
+#define libusb_release_interface libusb_ctx->release_interface
+#define libusb_kernel_driver_active libusb_ctx->kernel_driver_active
+#define libusb_detach_kernel_driver libusb_ctx->detach_kernel_driver
+#define libusb_attach_kernel_driver libusb_ctx->attach_kernel_driver
+#define libusb_set_interface_alt_setting libusb_ctx->set_interface_alt_setting
+#define libusb_alloc_transfer libusb_ctx->alloc_transfer
+#define libusb_submit_transfer libusb_ctx->submit_transfer
+#define libusb_cancel_transfer libusb_ctx->cancel_transfer
+#define libusb_free_transfer libusb_ctx->free_transfer
+#define libusb_control_transfer libusb_ctx->control_transfer
+#define libusb_interrupt_transfer libusb_ctx->interrupt_transfer
+#define libusb_bulk_transfer libusb_ctx->bulk_transfer
+#define libusb_handle_events libusb_ctx->handle_events
+#define libusb_handle_events_completed libusb_ctx->handle_events_completed
+#define libusb_interrupt_event_handler libusb_ctx->interrupt_event_handler
+#define libusb_has_capability libusb_ctx->has_capability
+#define libusb_hotplug_register_callback libusb_ctx->hotplug_register_callback
+#define libusb_hotplug_deregister_callback libusb_ctx->hotplug_deregister_callback
+#define libusb_error_name libusb_ctx->error_name
struct LIBUSB_hid_device_;
typedef struct LIBUSB_hid_device_ LIBUSB_hid_device;
-#define free_hid_device LIBUSB_free_hid_device
-#define hid_close LIBUSB_hid_close
-#define hid_device LIBUSB_hid_device
-#define hid_device_ LIBUSB_hid_device_
-#define hid_enumerate LIBUSB_hid_enumerate
-#define hid_error LIBUSB_hid_error
-#define hid_exit LIBUSB_hid_exit
-#define hid_free_enumeration LIBUSB_hid_free_enumeration
-#define hid_get_device_info LIBUSB_hid_get_device_info
-#define hid_get_feature_report LIBUSB_hid_get_feature_report
-#define hid_get_indexed_string LIBUSB_hid_get_indexed_string
-#define hid_get_input_report LIBUSB_hid_get_input_report
-#define hid_get_manufacturer_string LIBUSB_hid_get_manufacturer_string
-#define hid_get_product_string LIBUSB_hid_get_product_string
-#define hid_get_report_descriptor LIBUSB_hid_get_report_descriptor
-#define hid_get_serial_number_string LIBUSB_hid_get_serial_number_string
-#define hid_init LIBUSB_hid_init
-#define hid_open LIBUSB_hid_open
-#define hid_open_path LIBUSB_hid_open_path
-#define hid_read LIBUSB_hid_read
-#define hid_read_timeout LIBUSB_hid_read_timeout
-#define hid_send_feature_report LIBUSB_hid_send_feature_report
-#define hid_set_nonblocking LIBUSB_hid_set_nonblocking
-#define hid_write LIBUSB_hid_write
-#define hid_version LIBUSB_hid_version
-#define hid_version_str LIBUSB_hid_version_str
-#define input_report LIBUSB_input_report
-#define make_path LIBUSB_make_path
-#define new_hid_device LIBUSB_new_hid_device
-#define read_thread LIBUSB_read_thread
-#define return_data LIBUSB_return_data
+#define free_hid_device LIBUSB_free_hid_device
+#define get_usb_code_for_current_locale LIBUSB_get_usb_code_for_current_locale
+#define hid_close LIBUSB_hid_close
+#define hid_device LIBUSB_hid_device
+#define hid_device_ LIBUSB_hid_device_
+#define hid_enumerate LIBUSB_hid_enumerate
+#define hid_error LIBUSB_hid_error
+#define hid_exit LIBUSB_hid_exit
+#define hid_free_enumeration LIBUSB_hid_free_enumeration
+#define hid_get_device_info LIBUSB_hid_get_device_info
+#define hid_get_feature_report LIBUSB_hid_get_feature_report
+#define hid_get_indexed_string LIBUSB_hid_get_indexed_string
+#define hid_get_input_report LIBUSB_hid_get_input_report
+#define hid_get_manufacturer_string LIBUSB_hid_get_manufacturer_string
+#define hid_get_product_string LIBUSB_hid_get_product_string
+#define hid_get_report_descriptor LIBUSB_hid_get_report_descriptor
+#define hid_get_serial_number_string LIBUSB_hid_get_serial_number_string
+#define hid_init LIBUSB_hid_init
+#define hid_open LIBUSB_hid_open
+#define hid_open_path LIBUSB_hid_open_path
+#define hid_read LIBUSB_hid_read
+#define hid_read_timeout LIBUSB_hid_read_timeout
+#define hid_send_feature_report LIBUSB_hid_send_feature_report
+#define hid_set_nonblocking LIBUSB_hid_set_nonblocking
+#define hid_write LIBUSB_hid_write
+#define hid_libusb_wrap_sys_device LIBUSB_hid_libusb_wrap_sys_device
+#define hid_version LIBUSB_hid_version
+#define hid_version_str LIBUSB_hid_version_str
+#define input_report LIBUSB_input_report
+#define make_path LIBUSB_make_path
+#define new_hid_device LIBUSB_new_hid_device
+#define read_thread LIBUSB_read_thread
+#define return_data LIBUSB_return_data
#include "SDL_hidapi_libusb.h"
@@ -843,6 +805,7 @@ typedef struct LIBUSB_hid_device_ LIBUSB_hid_device;
#undef libusb_free_transfer
#undef libusb_control_transfer
#undef libusb_interrupt_transfer
+#undef libusb_bulk_transfer
#undef libusb_handle_events
#undef libusb_handle_events_completed
#undef libusb_error_name
@@ -877,6 +840,10 @@ typedef struct LIBUSB_hid_device_ LIBUSB_hid_device;
#undef read_thread
#undef return_data
+#endif // HAVE_LIBUSB
+
+#endif // !SDL_HIDAPI_DISABLED
+
/* If the platform has any backend other than libusb, try to avoid using
* libusb as the main backend for devices, since it detaches drivers and
* therefore makes devices inaccessible to the rest of the OS.
@@ -888,25 +855,35 @@ typedef struct LIBUSB_hid_device_ LIBUSB_hid_device;
static const struct {
Uint16 vendor;
Uint16 product;
-} SDL_libusb_whitelist[] = {
- { 0x057e, 0x0337 } // Nintendo WUP-028, Wii U/Switch GameCube Adapter
+} SDL_libusb_required[] = {
+ { USB_VENDOR_NINTENDO, USB_PRODUCT_NINTENDO_GAMECUBE_ADAPTER },
+ { USB_VENDOR_NINTENDO, USB_PRODUCT_NINTENDO_SWITCH2_GAMECUBE_CONTROLLER },
+ { USB_VENDOR_NINTENDO, USB_PRODUCT_NINTENDO_SWITCH2_JOYCON_LEFT },
+ { USB_VENDOR_NINTENDO, USB_PRODUCT_NINTENDO_SWITCH2_JOYCON_RIGHT },
+ { USB_VENDOR_NINTENDO, USB_PRODUCT_NINTENDO_SWITCH2_PRO },
};
-static bool IsInWhitelist(Uint16 vendor, Uint16 product)
+static bool RequiresLibUSB(Uint16 vendor, Uint16 product, bool libusb_xbox)
{
- int i;
- for (i = 0; i < SDL_arraysize(SDL_libusb_whitelist); i += 1) {
- if (vendor == SDL_libusb_whitelist[i].vendor &&
- product == SDL_libusb_whitelist[i].product) {
+ for (int i = 0; i < SDL_arraysize(SDL_libusb_required); ++i) {
+ if (vendor == SDL_libusb_required[i].vendor &&
+ product == SDL_libusb_required[i].product) {
return true;
}
}
- return false;
-}
-#endif // HAVE_LIBUSB
+#ifdef SDL_PLATFORM_MACOS
+ // On macOS we want to use libusb if possible for Xbox controllers
+ // that are not supported by the OS. Opening the device via libusb
+ // will fail if the device is supported (and opened) by the OS, so
+ // any devices we return here and can open are fair game.
+ if (libusb_xbox) {
+ return true;
+ }
+#endif // SDL_PLATFORM_MACOS
-#endif // !SDL_HIDAPI_DISABLED
+ return false;
+}
#if defined(HAVE_PLATFORM_BACKEND) || defined(HAVE_DRIVER_BACKEND)
// We have another way to get HID devices, so use the whitelist to get devices where libusb is preferred
@@ -917,100 +894,172 @@ static bool IsInWhitelist(Uint16 vendor, Uint16 product)
#endif // HAVE_PLATFORM_BACKEND || HAVE_DRIVER_BACKEND
static bool use_libusb_whitelist = SDL_HINT_HIDAPI_LIBUSB_WHITELIST_DEFAULT;
+static bool use_libusb_gamecube = true;
// Shared HIDAPI Implementation
struct hidapi_backend
{
- int (*hid_write)(void *device, const unsigned char *data, size_t length);
- int (*hid_read_timeout)(void *device, unsigned char *data, size_t length, int milliseconds);
- int (*hid_read)(void *device, unsigned char *data, size_t length);
- int (*hid_set_nonblocking)(void *device, int nonblock);
- int (*hid_send_feature_report)(void *device, const unsigned char *data, size_t length);
- int (*hid_get_feature_report)(void *device, unsigned char *data, size_t length);
- int (*hid_get_input_report)(void *device, unsigned char *data, size_t length);
- void (*hid_close)(void *device);
- int (*hid_get_manufacturer_string)(void *device, wchar_t *string, size_t maxlen);
- int (*hid_get_product_string)(void *device, wchar_t *string, size_t maxlen);
- int (*hid_get_serial_number_string)(void *device, wchar_t *string, size_t maxlen);
- int (*hid_get_indexed_string)(void *device, int string_index, wchar_t *string, size_t maxlen);
- struct hid_device_info *(*hid_get_device_info)(void *device);
- int (*hid_get_report_descriptor)(void *device, unsigned char *buf, size_t buf_size);
- const wchar_t *(*hid_error)(void *device);
+ int (*hid_write)(hid_device *device, const unsigned char *data, size_t length);
+ int (*hid_read_timeout)(hid_device *device, unsigned char *data, size_t length, int milliseconds);
+ int (*hid_read)(hid_device *device, unsigned char *data, size_t length);
+ int (*hid_set_nonblocking)(hid_device *device, int nonblock);
+ int (*hid_send_feature_report)(hid_device *device, const unsigned char *data, size_t length);
+ int (*hid_get_feature_report)(hid_device *device, unsigned char *data, size_t length);
+ int (*hid_get_input_report)(hid_device *device, unsigned char *data, size_t length);
+ void (*hid_close)(hid_device *device);
+ int (*hid_get_manufacturer_string)(hid_device *device, wchar_t *string, size_t maxlen);
+ int (*hid_get_product_string)(hid_device *device, wchar_t *string, size_t maxlen);
+ int (*hid_get_serial_number_string)(hid_device *device, wchar_t *string, size_t maxlen);
+ int (*hid_get_indexed_string)(hid_device *device, int string_index, wchar_t *string, size_t maxlen);
+ struct hid_device_info *(*hid_get_device_info)(hid_device *device);
+ int (*hid_get_report_descriptor)(hid_device *device, unsigned char *buf, size_t buf_size);
+ const wchar_t *(*hid_error)(hid_device *device);
};
+#define HIDAPI_BACKEND_WRAPPERS(PREFIX, DEVICE_TYPE) \
+ static int PREFIX##_hid_write_backend(hid_device *device, const unsigned char *data, size_t length) \
+ { \
+ return PREFIX##_hid_write((DEVICE_TYPE *)device, data, length); \
+ } \
+ static int PREFIX##_hid_read_timeout_backend(hid_device *device, unsigned char *data, size_t length, int milliseconds) \
+ { \
+ return PREFIX##_hid_read_timeout((DEVICE_TYPE *)device, data, length, milliseconds); \
+ } \
+ static int PREFIX##_hid_read_backend(hid_device *device, unsigned char *data, size_t length) \
+ { \
+ return PREFIX##_hid_read((DEVICE_TYPE *)device, data, length); \
+ } \
+ static int PREFIX##_hid_set_nonblocking_backend(hid_device *device, int nonblock) \
+ { \
+ return PREFIX##_hid_set_nonblocking((DEVICE_TYPE *)device, nonblock); \
+ } \
+ static int PREFIX##_hid_send_feature_report_backend(hid_device *device, const unsigned char *data, size_t length) \
+ { \
+ return PREFIX##_hid_send_feature_report((DEVICE_TYPE *)device, data, length); \
+ } \
+ static int PREFIX##_hid_get_feature_report_backend(hid_device *device, unsigned char *data, size_t length) \
+ { \
+ return PREFIX##_hid_get_feature_report((DEVICE_TYPE *)device, data, length); \
+ } \
+ static int PREFIX##_hid_get_input_report_backend(hid_device *device, unsigned char *data, size_t length) \
+ { \
+ return PREFIX##_hid_get_input_report((DEVICE_TYPE *)device, data, length); \
+ } \
+ static void PREFIX##_hid_close_backend(hid_device *device) \
+ { \
+ PREFIX##_hid_close((DEVICE_TYPE *)device); \
+ } \
+ static int PREFIX##_hid_get_manufacturer_string_backend(hid_device *device, wchar_t *string, size_t maxlen) \
+ { \
+ return PREFIX##_hid_get_manufacturer_string((DEVICE_TYPE *)device, string, maxlen); \
+ } \
+ static int PREFIX##_hid_get_product_string_backend(hid_device *device, wchar_t *string, size_t maxlen) \
+ { \
+ return PREFIX##_hid_get_product_string((DEVICE_TYPE *)device, string, maxlen); \
+ } \
+ static int PREFIX##_hid_get_serial_number_string_backend(hid_device *device, wchar_t *string, size_t maxlen) \
+ { \
+ return PREFIX##_hid_get_serial_number_string((DEVICE_TYPE *)device, string, maxlen); \
+ } \
+ static int PREFIX##_hid_get_indexed_string_backend(hid_device *device, int string_index, wchar_t *string, size_t maxlen) \
+ { \
+ return PREFIX##_hid_get_indexed_string((DEVICE_TYPE *)device, string_index, string, maxlen); \
+ } \
+ static struct hid_device_info *PREFIX##_hid_get_device_info_backend(hid_device *device) \
+ { \
+ return PREFIX##_hid_get_device_info((DEVICE_TYPE *)device); \
+ } \
+ static int PREFIX##_hid_get_report_descriptor_backend(hid_device *device, unsigned char *buf, size_t buf_size) \
+ { \
+ return PREFIX##_hid_get_report_descriptor((DEVICE_TYPE *)device, buf, buf_size); \
+ } \
+ static const wchar_t *PREFIX##_hid_error_backend(hid_device *device) \
+ { \
+ return PREFIX##_hid_error((DEVICE_TYPE *)device); \
+ }
+
#ifdef HAVE_PLATFORM_BACKEND
+HIDAPI_BACKEND_WRAPPERS(PLATFORM, PLATFORM_hid_device)
+
static const struct hidapi_backend PLATFORM_Backend = {
- (void *)PLATFORM_hid_write,
- (void *)PLATFORM_hid_read_timeout,
- (void *)PLATFORM_hid_read,
- (void *)PLATFORM_hid_set_nonblocking,
- (void *)PLATFORM_hid_send_feature_report,
- (void *)PLATFORM_hid_get_feature_report,
- (void *)PLATFORM_hid_get_input_report,
- (void *)PLATFORM_hid_close,
- (void *)PLATFORM_hid_get_manufacturer_string,
- (void *)PLATFORM_hid_get_product_string,
- (void *)PLATFORM_hid_get_serial_number_string,
- (void *)PLATFORM_hid_get_indexed_string,
- (void *)PLATFORM_hid_get_device_info,
- (void *)PLATFORM_hid_get_report_descriptor,
- (void *)PLATFORM_hid_error
+ PLATFORM_hid_write_backend,
+ PLATFORM_hid_read_timeout_backend,
+ PLATFORM_hid_read_backend,
+ PLATFORM_hid_set_nonblocking_backend,
+ PLATFORM_hid_send_feature_report_backend,
+ PLATFORM_hid_get_feature_report_backend,
+ PLATFORM_hid_get_input_report_backend,
+ PLATFORM_hid_close_backend,
+ PLATFORM_hid_get_manufacturer_string_backend,
+ PLATFORM_hid_get_product_string_backend,
+ PLATFORM_hid_get_serial_number_string_backend,
+ PLATFORM_hid_get_indexed_string_backend,
+ PLATFORM_hid_get_device_info_backend,
+ PLATFORM_hid_get_report_descriptor_backend,
+ PLATFORM_hid_error_backend
};
#endif // HAVE_PLATFORM_BACKEND
#ifdef HAVE_DRIVER_BACKEND
+HIDAPI_BACKEND_WRAPPERS(DRIVER, DRIVER_hid_device)
+
static const struct hidapi_backend DRIVER_Backend = {
- (void *)DRIVER_hid_write,
- (void *)DRIVER_hid_read_timeout,
- (void *)DRIVER_hid_read,
- (void *)DRIVER_hid_set_nonblocking,
- (void *)DRIVER_hid_send_feature_report,
- (void *)DRIVER_hid_get_feature_report,
- (void *)DRIVER_hid_get_input_report,
- (void *)DRIVER_hid_close,
- (void *)DRIVER_hid_get_manufacturer_string,
- (void *)DRIVER_hid_get_product_string,
- (void *)DRIVER_hid_get_serial_number_string,
- (void *)DRIVER_hid_get_indexed_string,
- (void *)DRIVER_hid_get_device_info,
- (void *)DRIVER_hid_get_report_descriptor,
- (void *)DRIVER_hid_error
+ DRIVER_hid_write_backend,
+ DRIVER_hid_read_timeout_backend,
+ DRIVER_hid_read_backend,
+ DRIVER_hid_set_nonblocking_backend,
+ DRIVER_hid_send_feature_report_backend,
+ DRIVER_hid_get_feature_report_backend,
+ DRIVER_hid_get_input_report_backend,
+ DRIVER_hid_close_backend,
+ DRIVER_hid_get_manufacturer_string_backend,
+ DRIVER_hid_get_product_string_backend,
+ DRIVER_hid_get_serial_number_string_backend,
+ DRIVER_hid_get_indexed_string_backend,
+ DRIVER_hid_get_device_info_backend,
+ DRIVER_hid_get_report_descriptor_backend,
+ DRIVER_hid_error_backend
};
#endif // HAVE_DRIVER_BACKEND
#ifdef HAVE_LIBUSB
+HIDAPI_BACKEND_WRAPPERS(LIBUSB, LIBUSB_hid_device)
+
static const struct hidapi_backend LIBUSB_Backend = {
- (void *)LIBUSB_hid_write,
- (void *)LIBUSB_hid_read_timeout,
- (void *)LIBUSB_hid_read,
- (void *)LIBUSB_hid_set_nonblocking,
- (void *)LIBUSB_hid_send_feature_report,
- (void *)LIBUSB_hid_get_feature_report,
- (void *)LIBUSB_hid_get_input_report,
- (void *)LIBUSB_hid_close,
- (void *)LIBUSB_hid_get_manufacturer_string,
- (void *)LIBUSB_hid_get_product_string,
- (void *)LIBUSB_hid_get_serial_number_string,
- (void *)LIBUSB_hid_get_indexed_string,
- (void *)LIBUSB_hid_get_device_info,
- (void *)LIBUSB_hid_get_report_descriptor,
- (void *)LIBUSB_hid_error
+ LIBUSB_hid_write_backend,
+ LIBUSB_hid_read_timeout_backend,
+ LIBUSB_hid_read_backend,
+ LIBUSB_hid_set_nonblocking_backend,
+ LIBUSB_hid_send_feature_report_backend,
+ LIBUSB_hid_get_feature_report_backend,
+ LIBUSB_hid_get_input_report_backend,
+ LIBUSB_hid_close_backend,
+ LIBUSB_hid_get_manufacturer_string_backend,
+ LIBUSB_hid_get_product_string_backend,
+ LIBUSB_hid_get_serial_number_string_backend,
+ LIBUSB_hid_get_indexed_string_backend,
+ LIBUSB_hid_get_device_info_backend,
+ LIBUSB_hid_get_report_descriptor_backend,
+ LIBUSB_hid_error_backend
};
#endif // HAVE_LIBUSB
+#undef HIDAPI_BACKEND_WRAPPERS
+
struct SDL_hid_device
{
void *device;
const struct hidapi_backend *backend;
SDL_hid_device_info info;
+ SDL_PropertiesID props;
};
#if defined(HAVE_PLATFORM_BACKEND) || defined(HAVE_DRIVER_BACKEND) || defined(HAVE_LIBUSB)
static SDL_hid_device *CreateHIDDeviceWrapper(void *device, const struct hidapi_backend *backend)
{
- SDL_hid_device *wrapper = (SDL_hid_device *)SDL_malloc(sizeof(*wrapper));
+ SDL_hid_device *wrapper = (SDL_hid_device *)SDL_calloc(1, sizeof(*wrapper));
SDL_SetObjectValid(wrapper, SDL_OBJECT_TYPE_HIDAPI_DEVICE, true);
wrapper->device = device;
wrapper->backend = backend;
@@ -1082,9 +1131,7 @@ static void SDLCALL OnlyControllersChanged(void *userdata, const char *name, con
static void SDLCALL IgnoredDevicesChanged(void *userdata, const char *name, const char *oldValue, const char *hint)
{
- if (SDL_hidapi_ignored_devices) {
- SDL_free(SDL_hidapi_ignored_devices);
- }
+ SDL_free(SDL_hidapi_ignored_devices);
if (hint && *hint) {
SDL_hidapi_ignored_devices = SDL_strdup(hint);
} else {
@@ -1092,8 +1139,22 @@ static void SDLCALL IgnoredDevicesChanged(void *userdata, const char *name, cons
}
}
-bool SDL_HIDAPI_ShouldIgnoreDevice(int bus, Uint16 vendor_id, Uint16 product_id, Uint16 usage_page, Uint16 usage)
+bool SDL_HIDAPI_ShouldIgnoreDevice(int bus, Uint16 vendor_id, Uint16 product_id, Uint16 usage_page, Uint16 usage, bool libusb, bool libusb_xbox)
{
+ if (libusb) {
+ if (use_libusb_whitelist && !RequiresLibUSB(vendor_id, product_id, libusb_xbox)) {
+ return true;
+ }
+ if (!use_libusb_gamecube &&
+ vendor_id == USB_VENDOR_NINTENDO && product_id == USB_PRODUCT_NINTENDO_GAMECUBE_ADAPTER) {
+ return true;
+ }
+ } else {
+ if (RequiresLibUSB(vendor_id, product_id, libusb_xbox)) {
+ return true;
+ }
+ }
+
// See if there are any devices we should skip in enumeration
if (SDL_hidapi_only_controllers && usage_page) {
if (vendor_id == USB_VENDOR_VALVE) {
@@ -1109,6 +1170,17 @@ bool SDL_HIDAPI_ShouldIgnoreDevice(int bus, Uint16 vendor_id, Uint16 product_id,
(usage == USB_USAGE_GENERIC_KEYBOARD || usage == USB_USAGE_GENERIC_MOUSE)) {
return true;
}
+ } else if (vendor_id == USB_VENDOR_FLYDIGI_V1 && product_id == USB_PRODUCT_FLYDIGI_V1_GAMEPAD) {
+ if (usage_page == USB_USAGEPAGE_VENDOR_FLYDIGI) {
+ return false;
+ }
+ return true;
+ } else if (vendor_id == USB_VENDOR_FLYDIGI_V2 &&
+ (product_id == USB_PRODUCT_FLYDIGI_V2_APEX || product_id == USB_PRODUCT_FLYDIGI_V2_VADER)) {
+ if (usage_page == USB_USAGEPAGE_VENDOR_FLYDIGI) {
+ return false;
+ }
+ return true;
} else if (usage_page == USB_USAGEPAGE_GENERIC_DESKTOP &&
(usage == USB_USAGE_GENERIC_JOYSTICK || usage == USB_USAGE_GENERIC_GAMEPAD || usage == USB_USAGE_GENERIC_MULTIAXISCONTROLLER)) {
// This is a controller
@@ -1158,74 +1230,20 @@ int SDL_hid_init(void)
use_libusb_whitelist = SDL_GetHintBoolean(SDL_HINT_HIDAPI_LIBUSB_WHITELIST,
SDL_HINT_HIDAPI_LIBUSB_WHITELIST_DEFAULT);
+ use_libusb_gamecube = SDL_GetHintBoolean(SDL_HINT_HIDAPI_LIBUSB_GAMECUBE, true);
#ifdef HAVE_LIBUSB
if (!SDL_GetHintBoolean(SDL_HINT_HIDAPI_LIBUSB, true)) {
SDL_LogDebug(SDL_LOG_CATEGORY_INPUT,
"libusb disabled with SDL_HINT_HIDAPI_LIBUSB");
- libusb_ctx.libhandle = NULL;
} else {
++attempts;
-#ifdef SDL_LIBUSB_DYNAMIC
- libusb_ctx.libhandle = SDL_LoadObject(SDL_LIBUSB_DYNAMIC);
-#else
- libusb_ctx.libhandle = (void *)1;
-#endif
- if (libusb_ctx.libhandle != NULL) {
- bool loaded = true;
-#ifdef SDL_LIBUSB_DYNAMIC
-#define LOAD_LIBUSB_SYMBOL(type, func) \
- if (!(libusb_ctx.func = (type)SDL_LoadFunction(libusb_ctx.libhandle, "libusb_" #func))) { \
- loaded = false; \
- }
-#else
-#define LOAD_LIBUSB_SYMBOL(type, func) \
- libusb_ctx.func = libusb_##func;
-#endif
- LOAD_LIBUSB_SYMBOL(int (LIBUSB_CALL *)(libusb_context **), init)
- LOAD_LIBUSB_SYMBOL(void (LIBUSB_CALL *)(libusb_context *), exit)
- LOAD_LIBUSB_SYMBOL(ssize_t (LIBUSB_CALL *)(libusb_context *, libusb_device ***), get_device_list)
- LOAD_LIBUSB_SYMBOL(void (LIBUSB_CALL *)(libusb_device **, int), free_device_list)
- LOAD_LIBUSB_SYMBOL(int (LIBUSB_CALL *)(libusb_device *, struct libusb_device_descriptor *), get_device_descriptor)
- LOAD_LIBUSB_SYMBOL(int (LIBUSB_CALL *)(libusb_device *, struct libusb_config_descriptor **), get_active_config_descriptor)
- LOAD_LIBUSB_SYMBOL(int (LIBUSB_CALL *)(libusb_device *, uint8_t, struct libusb_config_descriptor **), get_config_descriptor)
- LOAD_LIBUSB_SYMBOL(void (LIBUSB_CALL *)(struct libusb_config_descriptor *), free_config_descriptor)
- LOAD_LIBUSB_SYMBOL(uint8_t (LIBUSB_CALL *)(libusb_device *), get_bus_number)
- LOAD_LIBUSB_SYMBOL(int (LIBUSB_CALL *)(libusb_device *dev, uint8_t *port_numbers, int port_numbers_len), get_port_numbers)
- LOAD_LIBUSB_SYMBOL(uint8_t (LIBUSB_CALL *)(libusb_device *), get_device_address)
- LOAD_LIBUSB_SYMBOL(int (LIBUSB_CALL *)(libusb_device *, libusb_device_handle **), open)
- LOAD_LIBUSB_SYMBOL(void (LIBUSB_CALL *)(libusb_device_handle *), close)
- LOAD_LIBUSB_SYMBOL(libusb_device * (LIBUSB_CALL *)(libusb_device_handle *dev_handle), get_device)
- LOAD_LIBUSB_SYMBOL(int (LIBUSB_CALL *)(libusb_device_handle *, int), claim_interface)
- LOAD_LIBUSB_SYMBOL(int (LIBUSB_CALL *)(libusb_device_handle *, int), release_interface)
- LOAD_LIBUSB_SYMBOL(int (LIBUSB_CALL *)(libusb_device_handle *, int), kernel_driver_active)
- LOAD_LIBUSB_SYMBOL(int (LIBUSB_CALL *)(libusb_device_handle *, int), detach_kernel_driver)
- LOAD_LIBUSB_SYMBOL(int (LIBUSB_CALL *)(libusb_device_handle *, int), attach_kernel_driver)
- LOAD_LIBUSB_SYMBOL(int (LIBUSB_CALL *)(libusb_device_handle *, int, int), set_interface_alt_setting)
- LOAD_LIBUSB_SYMBOL(struct libusb_transfer * (LIBUSB_CALL *)(int), alloc_transfer)
- LOAD_LIBUSB_SYMBOL(int (LIBUSB_CALL *)(struct libusb_transfer *), submit_transfer)
- LOAD_LIBUSB_SYMBOL(int (LIBUSB_CALL *)(struct libusb_transfer *), cancel_transfer)
- LOAD_LIBUSB_SYMBOL(void (LIBUSB_CALL *)(struct libusb_transfer *), free_transfer)
- LOAD_LIBUSB_SYMBOL(int (LIBUSB_CALL *)(libusb_device_handle *, uint8_t, uint8_t, uint16_t, uint16_t, unsigned char *, uint16_t, unsigned int), control_transfer)
- LOAD_LIBUSB_SYMBOL(int (LIBUSB_CALL *)(libusb_device_handle *, unsigned char, unsigned char *, int, int *, unsigned int), interrupt_transfer)
- LOAD_LIBUSB_SYMBOL(int (LIBUSB_CALL *)(libusb_context *), handle_events)
- LOAD_LIBUSB_SYMBOL(int (LIBUSB_CALL *)(libusb_context *, int *), handle_events_completed)
- LOAD_LIBUSB_SYMBOL(const char * (LIBUSB_CALL *)(int), error_name)
-#undef LOAD_LIBUSB_SYMBOL
-
- if (!loaded) {
-#ifdef SDL_LIBUSB_DYNAMIC
- SDL_UnloadObject(libusb_ctx.libhandle);
-#endif
- libusb_ctx.libhandle = NULL;
- // SDL_LogWarn(SDL_LOG_CATEGORY_INPUT, SDL_LIBUSB_DYNAMIC " found but could not load function");
- } else if (LIBUSB_hid_init() < 0) {
-#ifdef SDL_LIBUSB_DYNAMIC
- SDL_UnloadObject(libusb_ctx.libhandle);
-#endif
- libusb_ctx.libhandle = NULL;
- } else {
- ++success;
- }
+ if (!SDL_InitLibUSB(&libusb_ctx)) {
+ SDL_LogDebug(SDL_LOG_CATEGORY_INPUT, "Couldn't load libusb");
+ } else if (LIBUSB_hid_init() < 0) {
+ SDL_QuitLibUSB();
+ libusb_ctx = NULL;
+ } else {
+ ++success;
}
}
#endif // HAVE_LIBUSB
@@ -1279,12 +1297,10 @@ int SDL_hid_exit(void)
#endif // HAVE_PLATFORM_BACKEND
#ifdef HAVE_LIBUSB
- if (libusb_ctx.libhandle) {
+ if (libusb_ctx) {
result |= LIBUSB_hid_exit();
-#ifdef SDL_LIBUSB_DYNAMIC
- SDL_UnloadObject(libusb_ctx.libhandle);
-#endif
- libusb_ctx.libhandle = NULL;
+ SDL_QuitLibUSB();
+ libusb_ctx = NULL;
}
#endif // HAVE_LIBUSB
@@ -1379,34 +1395,6 @@ static void RemoveDeviceFromEnumeration(const char *driver_name, struct hid_devi
}
#endif // HAVE_LIBUSB || HAVE_PLATFORM_BACKEND
-#ifdef HAVE_LIBUSB
-static void RemoveNonWhitelistedDevicesFromEnumeration(struct hid_device_info **devs, void (*free_device_info)(struct hid_device_info *))
-{
- struct hid_device_info *last = NULL, *curr, *next;
-
- for (curr = *devs; curr; curr = next) {
- next = curr->next;
-
- if (!IsInWhitelist(curr->vendor_id, curr->product_id)) {
-#ifdef DEBUG_HIDAPI
- SDL_Log("Device was not in libusb whitelist, skipping: %ls %ls 0x%.4hx/0x%.4hx/%d",
- curr->manufacturer_string, curr->product_string, curr->vendor_id, curr->product_id, curr->interface_number);
-#endif
- if (last) {
- last->next = next;
- } else {
- *devs = next;
- }
-
- curr->next = NULL;
- free_device_info(curr);
- continue;
- }
- last = curr;
- }
-}
-#endif // HAVE_LIBUSB
-
struct SDL_hid_device_info *SDL_hid_enumerate(unsigned short vendor_id, unsigned short product_id)
{
struct hid_device_info *driver_devs = NULL;
@@ -1425,12 +1413,8 @@ struct SDL_hid_device_info *SDL_hid_enumerate(unsigned short vendor_id, unsigned
#endif
#ifdef HAVE_LIBUSB
- if (libusb_ctx.libhandle) {
+ if (libusb_ctx) {
usb_devs = LIBUSB_hid_enumerate(vendor_id, product_id);
-
- if (use_libusb_whitelist) {
- RemoveNonWhitelistedDevicesFromEnumeration(&usb_devs, LIBUSB_hid_free_enumeration);
- }
}
#endif // HAVE_LIBUSB
@@ -1526,10 +1510,12 @@ SDL_hid_device *SDL_hid_open(unsigned short vendor_id, unsigned short product_id
#endif // HAVE_DRIVER_BACKEND
#ifdef HAVE_LIBUSB
- if (libusb_ctx.libhandle != NULL) {
+ if (libusb_ctx) {
pDevice = LIBUSB_hid_open(vendor_id, product_id, serial_number);
if (pDevice != NULL) {
- return CreateHIDDeviceWrapper(pDevice, &LIBUSB_Backend);
+ SDL_hid_device *dev = CreateHIDDeviceWrapper(pDevice, &LIBUSB_Backend);
+ SDL_SetPointerProperty(SDL_hid_get_properties(dev), SDL_PROP_HIDAPI_LIBUSB_DEVICE_HANDLE_POINTER, ((LIBUSB_hid_device *)pDevice)->device_handle);
+ return dev;
}
}
#endif // HAVE_LIBUSB
@@ -1565,10 +1551,12 @@ SDL_hid_device *SDL_hid_open_path(const char *path)
#endif // HAVE_DRIVER_BACKEND
#ifdef HAVE_LIBUSB
- if (libusb_ctx.libhandle != NULL) {
+ if (libusb_ctx) {
pDevice = LIBUSB_hid_open_path(path);
if (pDevice != NULL) {
- return CreateHIDDeviceWrapper(pDevice, &LIBUSB_Backend);
+ SDL_hid_device *dev = CreateHIDDeviceWrapper(pDevice, &LIBUSB_Backend);
+ SDL_SetPointerProperty(SDL_hid_get_properties(dev), SDL_PROP_HIDAPI_LIBUSB_DEVICE_HANDLE_POINTER, ((LIBUSB_hid_device *)pDevice)->device_handle);
+ return dev;
}
}
#endif // HAVE_LIBUSB
@@ -1578,6 +1566,16 @@ SDL_hid_device *SDL_hid_open_path(const char *path)
return NULL;
}
+SDL_PropertiesID SDL_hid_get_properties(SDL_hid_device *device)
+{
+ CHECK_DEVICE_MAGIC(device, 0);
+
+ if (!device->props) {
+ device->props = SDL_CreateProperties();
+ }
+ return device->props;
+}
+
int SDL_hid_write(SDL_hid_device *device, const unsigned char *data, size_t length)
{
CHECK_DEVICE_MAGIC(device, -1);
@@ -1632,6 +1630,7 @@ int SDL_hid_close(SDL_hid_device *device)
CHECK_DEVICE_MAGIC(device, -1);
device->backend->hid_close(device->device);
+ SDL_DestroyProperties(device->props);
DeleteHIDDeviceWrapper(device);
return 0;
}
@@ -1693,60 +1692,3 @@ void SDL_hid_ble_scan(bool active)
hid_ble_scan(active);
#endif
}
-
-#ifdef HAVE_ENABLE_GAMECUBE_ADAPTORS
-// This is needed to enable input for Nyko and EVORETRO GameCube adaptors
-void SDL_EnableGameCubeAdaptors(void)
-{
-#ifdef HAVE_LIBUSB
- libusb_context *context = NULL;
- libusb_device **devs = NULL;
- libusb_device_handle *handle = NULL;
- struct libusb_device_descriptor desc;
- ssize_t i, num_devs;
- int kernel_detached = 0;
-
- if (libusb_ctx.libhandle == NULL) {
- return;
- }
-
- if (libusb_ctx.init(&context) == 0) {
- num_devs = libusb_ctx.get_device_list(context, &devs);
- for (i = 0; i < num_devs; ++i) {
- if (libusb_ctx.get_device_descriptor(devs[i], &desc) != 0) {
- continue;
- }
-
- if (desc.idVendor != 0x057e || desc.idProduct != 0x0337) {
- continue;
- }
-
- if (libusb_ctx.open(devs[i], &handle) != 0) {
- continue;
- }
-
- if (libusb_ctx.kernel_driver_active(handle, 0)) {
- if (libusb_ctx.detach_kernel_driver(handle, 0) == 0) {
- kernel_detached = 1;
- }
- }
-
- if (libusb_ctx.claim_interface(handle, 0) == 0) {
- libusb_ctx.control_transfer(handle, 0x21, 11, 0x0001, 0, NULL, 0, 1000);
- libusb_ctx.release_interface(handle, 0);
- }
-
- if (kernel_detached) {
- libusb_ctx.attach_kernel_driver(handle, 0);
- }
-
- libusb_ctx.close(handle);
- }
-
- libusb_ctx.free_device_list(devs, 1);
-
- libusb_ctx.exit(context);
- }
-#endif // HAVE_LIBUSB
-}
-#endif // HAVE_ENABLE_GAMECUBE_ADAPTORS
diff --git a/thirdparty/sdl/hidapi/SDL_hidapi_android.h b/thirdparty/sdl/hidapi/SDL_hidapi_android.h
index 2f3851f8f54..6d349cb3552 100644
--- a/thirdparty/sdl/hidapi/SDL_hidapi_android.h
+++ b/thirdparty/sdl/hidapi/SDL_hidapi_android.h
@@ -1,6 +1,6 @@
/*
Simple DirectMedia Layer
- Copyright (C) 1997-2025 Sam Lantinga <[email protected]>
+ Copyright (C) 1997-2026 Sam Lantinga <[email protected]>
This software is provided 'as-is', without any express or implied
warranty. In no event will the authors be held liable for any damages
diff --git a/thirdparty/sdl/hidapi/SDL_hidapi_c.h b/thirdparty/sdl/hidapi/SDL_hidapi_c.h
index 6d94f77eb95..706d96a30c7 100644
--- a/thirdparty/sdl/hidapi/SDL_hidapi_c.h
+++ b/thirdparty/sdl/hidapi/SDL_hidapi_c.h
@@ -1,6 +1,6 @@
/*
Simple DirectMedia Layer
- Copyright (C) 1997-2025 Sam Lantinga <[email protected]>
+ Copyright (C) 1997-2026 Sam Lantinga <[email protected]>
This software is provided 'as-is', without any express or implied
warranty. In no event will the authors be held liable for any damages
@@ -22,14 +22,5 @@
/* Return true if the HIDAPI should ignore a device during enumeration */
-extern bool SDL_HIDAPI_ShouldIgnoreDevice(int bus_type, Uint16 vendor_id, Uint16 product_id, Uint16 usage_page, Uint16 usage);
+extern bool SDL_HIDAPI_ShouldIgnoreDevice(int bus_type, Uint16 vendor_id, Uint16 product_id, Uint16 usage_page, Uint16 usage, bool libusb, bool is_xbox);
-#ifdef SDL_JOYSTICK_HIDAPI
-#ifdef HAVE_LIBUSB
-#define HAVE_ENABLE_GAMECUBE_ADAPTORS
-#endif
-
-#ifdef HAVE_ENABLE_GAMECUBE_ADAPTORS
-extern void SDL_EnableGameCubeAdaptors(void);
-#endif
-#endif /* SDL_JOYSTICK_HIDAPI */
diff --git a/thirdparty/sdl/hidapi/SDL_hidapi_ios.h b/thirdparty/sdl/hidapi/SDL_hidapi_ios.h
index f58f10d5a61..6aa71c84977 100644
--- a/thirdparty/sdl/hidapi/SDL_hidapi_ios.h
+++ b/thirdparty/sdl/hidapi/SDL_hidapi_ios.h
@@ -1,6 +1,6 @@
/*
Simple DirectMedia Layer
- Copyright (C) 1997-2025 Sam Lantinga <[email protected]>
+ Copyright (C) 1997-2026 Sam Lantinga <[email protected]>
This software is provided 'as-is', without any express or implied
warranty. In no event will the authors be held liable for any damages
diff --git a/thirdparty/sdl/hidapi/SDL_hidapi_libusb.h b/thirdparty/sdl/hidapi/SDL_hidapi_libusb.h
index ed8b4a35d70..a68ac49d6d0 100644
--- a/thirdparty/sdl/hidapi/SDL_hidapi_libusb.h
+++ b/thirdparty/sdl/hidapi/SDL_hidapi_libusb.h
@@ -1,6 +1,6 @@
/*
Simple DirectMedia Layer
- Copyright (C) 1997-2025 Sam Lantinga <[email protected]>
+ Copyright (C) 1997-2026 Sam Lantinga <[email protected]>
This software is provided 'as-is', without any express or implied
warranty. In no event will the authors be held liable for any damages
@@ -82,7 +82,6 @@
#define wcsncpy SDL_wcslcpy
-#ifndef SDL_PLATFORM_FREEBSD
/* this is awkwardly inlined, so we need to re-implement it here
* so we can override the libusb_control_transfer call */
static int SDL_libusb_get_string_descriptor(libusb_device_handle *dev,
@@ -93,7 +92,23 @@ static int SDL_libusb_get_string_descriptor(libusb_device_handle *dev,
data, (uint16_t)length, 1000); /* Endpoint 0 IN */
}
#define libusb_get_string_descriptor SDL_libusb_get_string_descriptor
-#endif /* SDL_PLATFORM_FREEBSD */
+
+/* this is inlined, except on FreeBSD, so we need to re-implement it here */
+static void SDL_libusb_fill_interrupt_transfer(
+ struct libusb_transfer *transfer, libusb_device_handle *dev_handle,
+ unsigned char endpoint, unsigned char *buffer, int length,
+ libusb_transfer_cb_fn callback, void *user_data, unsigned int timeout)
+{
+ transfer->dev_handle = dev_handle;
+ transfer->endpoint = endpoint;
+ transfer->type = LIBUSB_TRANSFER_TYPE_INTERRUPT;
+ transfer->timeout = timeout;
+ transfer->buffer = buffer;
+ transfer->length = length;
+ transfer->user_data = user_data;
+ transfer->callback = callback;
+}
+#define libusb_fill_interrupt_transfer SDL_libusb_fill_interrupt_transfer
#define HIDAPI_THREAD_MODEL_INCLUDE "hidapi_thread_sdl.h"
#ifndef LIBUSB_API_VERSION
diff --git a/thirdparty/sdl/hidapi/SDL_hidapi_linux.h b/thirdparty/sdl/hidapi/SDL_hidapi_linux.h
index 29723d7501b..8418e2e9288 100644
--- a/thirdparty/sdl/hidapi/SDL_hidapi_linux.h
+++ b/thirdparty/sdl/hidapi/SDL_hidapi_linux.h
@@ -1,6 +1,6 @@
/*
Simple DirectMedia Layer
- Copyright (C) 1997-2025 Sam Lantinga <[email protected]>
+ Copyright (C) 1997-2026 Sam Lantinga <[email protected]>
This software is provided 'as-is', without any express or implied
warranty. In no event will the authors be held liable for any damages
diff --git a/thirdparty/sdl/hidapi/SDL_hidapi_mac.h b/thirdparty/sdl/hidapi/SDL_hidapi_mac.h
index 820b67d6bc9..7ec8e4e141d 100644
--- a/thirdparty/sdl/hidapi/SDL_hidapi_mac.h
+++ b/thirdparty/sdl/hidapi/SDL_hidapi_mac.h
@@ -1,6 +1,6 @@
/*
Simple DirectMedia Layer
- Copyright (C) 1997-2025 Sam Lantinga <[email protected]>
+ Copyright (C) 1997-2026 Sam Lantinga <[email protected]>
This software is provided 'as-is', without any express or implied
warranty. In no event will the authors be held liable for any damages
diff --git a/thirdparty/sdl/hidapi/SDL_hidapi_netbsd.h b/thirdparty/sdl/hidapi/SDL_hidapi_netbsd.h
index 1b39e225c1d..8bd5a8e9e8a 100644
--- a/thirdparty/sdl/hidapi/SDL_hidapi_netbsd.h
+++ b/thirdparty/sdl/hidapi/SDL_hidapi_netbsd.h
@@ -1,6 +1,6 @@
/*
Simple DirectMedia Layer
- Copyright (C) 1997-2025 Sam Lantinga <[email protected]>
+ Copyright (C) 1997-2026 Sam Lantinga <[email protected]>
This software is provided 'as-is', without any express or implied
warranty. In no event will the authors be held liable for any damages
diff --git a/thirdparty/sdl/hidapi/SDL_hidapi_steamxbox.h b/thirdparty/sdl/hidapi/SDL_hidapi_steamxbox.h
index b6294a3b772..41cecb598a6 100644
--- a/thirdparty/sdl/hidapi/SDL_hidapi_steamxbox.h
+++ b/thirdparty/sdl/hidapi/SDL_hidapi_steamxbox.h
@@ -1,6 +1,6 @@
/*
Simple DirectMedia Layer
- Copyright (C) 1997-2025 Sam Lantinga <[email protected]>
+ Copyright (C) 1997-2026 Sam Lantinga <[email protected]>
This software is provided 'as-is', without any express or implied
warranty. In no event will the authors be held liable for any damages
diff --git a/thirdparty/sdl/hidapi/SDL_hidapi_windows.h b/thirdparty/sdl/hidapi/SDL_hidapi_windows.h
index 91f71c20793..0ab9a6a22e6 100644
--- a/thirdparty/sdl/hidapi/SDL_hidapi_windows.h
+++ b/thirdparty/sdl/hidapi/SDL_hidapi_windows.h
@@ -1,6 +1,6 @@
/*
Simple DirectMedia Layer
- Copyright (C) 1997-2025 Sam Lantinga <[email protected]>
+ Copyright (C) 1997-2026 Sam Lantinga <[email protected]>
This software is provided 'as-is', without any express or implied
warranty. In no event will the authors be held liable for any damages
diff --git a/thirdparty/sdl/hidapi/linux/hid.c b/thirdparty/sdl/hidapi/linux/hid.c
index 641477fb23c..411fa170996 100644
--- a/thirdparty/sdl/hidapi/linux/hid.c
+++ b/thirdparty/sdl/hidapi/linux/hid.c
@@ -40,7 +40,7 @@
#include <linux/hidraw.h>
#include <linux/version.h>
#include <linux/input.h>
-//#include <libudev.h>
+// #include <libudev.h>
#include "SDL_udev.h"
extern SDL_UDEV_PrivateData *SDL_UDEV_PrivateData_this;
#define udev_device_get_action (SDL_UDEV_PrivateData_this->syms.udev_device_get_action)
@@ -177,7 +177,7 @@ static void register_error_str(wchar_t **error_str, const char *msg)
#endif
}
-/* Semilar to register_error_str, but allows passing a format string with va_list args into this function. */
+/* Similar to register_error_str, but allows passing a format string with va_list args into this function. */
static void register_error_str_vformat(wchar_t **error_str, const char *format, va_list args)
{
char msg[256];
@@ -936,7 +936,7 @@ static struct hid_device_info * create_device_info_for_device(struct udev_device
cur_dev = root;
while (cur_dev) {
- if (HIDAPI_IGNORE_DEVICE(cur_dev->bus_type, cur_dev->vendor_id, cur_dev->product_id, cur_dev->usage_page, cur_dev->usage)) {
+ if (HIDAPI_IGNORE_DEVICE(cur_dev->bus_type, cur_dev->vendor_id, cur_dev->product_id, cur_dev->usage_page, cur_dev->usage, false, false)) {
struct hid_device_info *tmp = cur_dev;
cur_dev = tmp->next;
diff --git a/thirdparty/sdl/hidapi/mac/hid.c b/thirdparty/sdl/hidapi/mac/hid.c
index 8acb6da7feb..95c387ae435 100644
--- a/thirdparty/sdl/hidapi/mac/hid.c
+++ b/thirdparty/sdl/hidapi/mac/hid.c
@@ -573,6 +573,7 @@ static struct hid_device_info *create_device_info_with_usage(IOHIDDeviceRef dev,
{
unsigned short dev_vid;
unsigned short dev_pid;
+ unsigned short dev_version;
int BUF_LEN = 256;
wchar_t buf[BUF_LEN];
CFTypeRef transport_prop;
@@ -593,15 +594,25 @@ static struct hid_device_info *create_device_info_with_usage(IOHIDDeviceRef dev,
dev_vid = get_vendor_id(dev);
dev_pid = get_product_id(dev);
+ dev_version = get_int_property(dev, CFSTR(kIOHIDVersionNumberKey));
#ifdef HIDAPI_IGNORE_DEVICE
/* See if there are any devices we should skip in enumeration */
- if (HIDAPI_IGNORE_DEVICE(get_bus_type(dev), dev_vid, dev_pid, usage_page, usage)) {
+ if (HIDAPI_IGNORE_DEVICE(get_bus_type(dev), dev_vid, dev_pid, usage_page, usage, false, false)) {
free(cur_dev);
return NULL;
}
#endif
+#ifdef HIDAPI_USING_SDL_RUNTIME
+ if (SDL_IsJoystickSteamVirtualGamepad(dev_vid, dev_pid, dev_version)) {
+ if (IOHIDDeviceGetProperty(dev, CFSTR(kIOHIDVirtualHIDevice)) != kCFBooleanTrue) {
+ /* This is a real Xbox 360 controller, adjust the version so it's not detected as a Steam virtual gamepad */
+ dev_version = 1;
+ }
+ }
+#endif
+
cur_dev->usage_page = usage_page;
cur_dev->usage = usage;
@@ -649,7 +660,7 @@ static struct hid_device_info *create_device_info_with_usage(IOHIDDeviceRef dev,
cur_dev->product_id = dev_pid;
/* Release Number */
- cur_dev->release_number = get_int_property(dev, CFSTR(kIOHIDVersionNumberKey));
+ cur_dev->release_number = dev_version;
/* Interface Number.
* We can only retrieve the interface number for USB HID devices.
@@ -1138,6 +1149,8 @@ return_error:
static int set_report(hid_device *dev, IOHIDReportType type, const unsigned char *data, size_t length)
{
+ const char *pass_through_magic = "MAGIC0";
+ size_t pass_through_magic_length = strlen(pass_through_magic);
const unsigned char *data_to_send = data;
CFIndex length_to_send = length;
IOReturn res;
@@ -1158,6 +1171,11 @@ static int set_report(hid_device *dev, IOHIDReportType type, const unsigned char
data_to_send = data+1;
length_to_send = length-1;
}
+ else if (length > 6 && memcmp(data, pass_through_magic, pass_through_magic_length) == 0) {
+ report_id = data[pass_through_magic_length];
+ data_to_send = data+pass_through_magic_length;
+ length_to_send = length-pass_through_magic_length;
+ }
/* Avoid crash if the device has been unplugged. */
if (dev->disconnected) {
@@ -1424,7 +1442,7 @@ void HID_API_EXPORT hid_close(hid_device *dev)
UPD: The crash part was true in/until some version of macOS.
Starting with macOS 10.15, there is an opposite effect in some environments:
- crash happenes if IOHIDDeviceClose() is not called.
+ crash happens if IOHIDDeviceClose() is not called.
Not leaking a resource in all tested environments.
*/
if (is_macos_10_10_or_greater || !dev->disconnected) {
diff --git a/thirdparty/sdl/hidapi/windows/hid.c b/thirdparty/sdl/hidapi/windows/hid.c
index 8a8224302e7..7e02c635a19 100644
--- a/thirdparty/sdl/hidapi/windows/hid.c
+++ b/thirdparty/sdl/hidapi/windows/hid.c
@@ -991,9 +991,7 @@ struct hid_device_info HID_API_EXPORT * HID_API_CALL hid_enumerate(unsigned shor
break;
}
- if (device_interface_list != NULL) {
- free(device_interface_list);
- }
+ free(device_interface_list); // This should NOT be SDL_free()
device_interface_list = (wchar_t*)calloc(len, sizeof(wchar_t));
if (device_interface_list == NULL) {
@@ -1029,6 +1027,12 @@ struct hid_device_info HID_API_EXPORT * HID_API_CALL hid_enumerate(unsigned shor
continue;
}
+#ifdef HIDAPI_IGNORE_DEVICE
+ hid_bus_type bus_type = HID_API_BUS_UNKNOWN;
+ PHIDP_PREPARSED_DATA pp_data = NULL;
+ HIDP_CAPS caps = { 0 };
+#endif
+
/* Get the Vendor ID and Product ID for this device. */
attrib.Size = sizeof(HIDD_ATTRIBUTES);
if (!HidD_GetAttributes(device_handle, &attrib)) {
@@ -1037,14 +1041,12 @@ struct hid_device_info HID_API_EXPORT * HID_API_CALL hid_enumerate(unsigned shor
#ifdef HIDAPI_IGNORE_DEVICE
/* See if there are any devices we should skip in enumeration */
- hid_bus_type bus_type = get_bus_type(device_interface);
- PHIDP_PREPARSED_DATA pp_data = NULL;
- HIDP_CAPS caps = { 0 };
+ bus_type = get_bus_type(device_interface);
if (HidD_GetPreparsedData(device_handle, &pp_data)) {
HidP_GetCaps(pp_data, &caps);
HidD_FreePreparsedData(pp_data);
}
- if (HIDAPI_IGNORE_DEVICE(bus_type, attrib.VendorID, attrib.ProductID, caps.UsagePage, caps.Usage)) {
+ if (HIDAPI_IGNORE_DEVICE(bus_type, attrib.VendorID, attrib.ProductID, caps.UsagePage, caps.Usage, false, false)) {
goto cont_close;
}
#endif
diff --git a/thirdparty/sdl/include/SDL3/SDL.h b/thirdparty/sdl/include/SDL3/SDL.h
index c99997044be..d9055809c4e 100644
--- a/thirdparty/sdl/include/SDL3/SDL.h
+++ b/thirdparty/sdl/include/SDL3/SDL.h
@@ -1,6 +1,6 @@
/*
Simple DirectMedia Layer
- Copyright (C) 1997-2025 Sam Lantinga <[email protected]>
+ Copyright (C) 1997-2026 Sam Lantinga <[email protected]>
This software is provided 'as-is', without any express or implied
warranty. In no event will the authors be held liable for any damages
@@ -20,7 +20,7 @@
*/
/**
- * Main include header for the SDL library, version 3.2.28
+ * Main include header for the SDL library, version 3.4.16
*
* It is almost always best to include just this one header instead of
* picking out individual headers included here. There are exceptions to
@@ -42,12 +42,13 @@
#include <SDL3/SDL_clipboard.h>
#include <SDL3/SDL_cpuinfo.h>
#include <SDL3/SDL_dialog.h>
+#include <SDL3/SDL_dlopennote.h>
#include <SDL3/SDL_endian.h>
#include <SDL3/SDL_error.h>
#include <SDL3/SDL_events.h>
#include <SDL3/SDL_filesystem.h>
#include <SDL3/SDL_gamepad.h>
-//#include <SDL3/SDL_gpu.h>
+// #include <SDL3/SDL_gpu.h>
#include <SDL3/SDL_guid.h>
#include <SDL3/SDL_haptic.h>
#include <SDL3/SDL_hidapi.h>
@@ -85,6 +86,6 @@
#include <SDL3/SDL_touch.h>
#include <SDL3/SDL_version.h>
#include <SDL3/SDL_video.h>
-//#include <SDL3/SDL_oldnames.h>
+// #include <SDL3/SDL_oldnames.h>
#endif /* SDL_h_ */
diff --git a/thirdparty/sdl/include/SDL3/SDL_assert.h b/thirdparty/sdl/include/SDL3/SDL_assert.h
index 3fa6bdc9366..e65836a0dd6 100644
--- a/thirdparty/sdl/include/SDL3/SDL_assert.h
+++ b/thirdparty/sdl/include/SDL3/SDL_assert.h
@@ -1,6 +1,6 @@
/*
Simple DirectMedia Layer
- Copyright (C) 1997-2025 Sam Lantinga <[email protected]>
+ Copyright (C) 1997-2026 Sam Lantinga <[email protected]>
This software is provided 'as-is', without any express or implied
warranty. In no event will the authors be held liable for any damages
@@ -126,20 +126,20 @@ extern "C" {
*/
#define SDL_TriggerBreakpoint() TriggerABreakpointInAPlatformSpecificManner
-#elif defined(__MINGW32__) || (defined(_MSC_VER) && _MSC_VER >= 1310)
+#elif defined(_MSC_VER) && _MSC_VER >= 1310
/* Don't include intrin.h here because it contains C++ code */
extern void __cdecl __debugbreak(void);
#define SDL_TriggerBreakpoint() __debugbreak()
+#elif defined(__MINGW32__)
+ #include <intrin.h>
+ #define SDL_TriggerBreakpoint() __debugbreak()
#elif defined(_MSC_VER) && defined(_M_IX86)
#define SDL_TriggerBreakpoint() { _asm { int 0x03 } }
-#elif defined(ANDROID)
- #include <assert.h>
- #define SDL_TriggerBreakpoint() assert(0)
#elif SDL_HAS_BUILTIN(__builtin_debugtrap)
#define SDL_TriggerBreakpoint() __builtin_debugtrap()
#elif SDL_HAS_BUILTIN(__builtin_trap)
#define SDL_TriggerBreakpoint() __builtin_trap()
-#elif (defined(__GNUC__) || defined(__clang__)) && (defined(__i386__) || defined(__x86_64__))
+#elif (defined(__GNUC__) || defined(__clang__) || defined(__TINYC__) || defined(__slimcc__)) && (defined(__i386__) || defined(__x86_64__))
#define SDL_TriggerBreakpoint() __asm__ __volatile__ ( "int $3\n\t" )
#elif (defined(__GNUC__) || defined(__clang__)) && defined(__riscv)
#define SDL_TriggerBreakpoint() __asm__ __volatile__ ( "ebreak\n\t" )
@@ -163,7 +163,7 @@ extern "C" {
#ifdef SDL_WIKI_DOCUMENTATION_SECTION
/**
- * A macro that reports the current function being compiled.
+ * A constant that contains the current function being compiled.
*
* If SDL can't figure how the compiler reports this, it will use "???".
*
@@ -171,20 +171,58 @@ extern "C" {
*/
#define SDL_FUNCTION __FUNCTION__
-#elif defined(__STDC_VERSION__) && (__STDC_VERSION__ >= 199901L) /* C99 supports __func__ as a standard. */
+#elif !defined(SDL_FUNCTION)
+#if defined(__STDC_VERSION__) && (__STDC_VERSION__ >= 199901L) /* C99 supports __func__ as a standard. */
# define SDL_FUNCTION __func__
#elif ((defined(__GNUC__) && (__GNUC__ >= 2)) || defined(_MSC_VER) || defined (__WATCOMC__))
# define SDL_FUNCTION __FUNCTION__
#else
# define SDL_FUNCTION "???"
#endif
+#endif
+
+#ifdef SDL_WIKI_DOCUMENTATION_SECTION
/**
* A macro that reports the current file being compiled.
*
+ * This macro is only defined if it isn't already defined, so to override it
+ * (perhaps with something that doesn't provide path information at all, so
+ * build machine information doesn't leak into public binaries), apps can
+ * define this macro before including SDL.h or SDL_assert.h.
+ *
* \since This macro is available since SDL 3.2.0.
*/
+#define SDL_FILE __FILE_NAME__
+
+#elif !defined(SDL_FILE)
+#ifdef __FILE_NAME__
+#define SDL_FILE __FILE_NAME__
+#else
#define SDL_FILE __FILE__
+#endif
+#endif
+
+#ifdef SDL_WIKI_DOCUMENTATION_SECTION
+
+/**
+ * A macro that reports the current file being compiled, for use in
+ * assertions.
+ *
+ * This macro is only defined if it isn't already defined, so to override it
+ * (perhaps with something that doesn't provide path information at all, so
+ * build machine information doesn't leak into public binaries), apps can
+ * define this macro before including SDL_assert.h. For example, defining this
+ * to `""` will make sure no source path information is included in asserts.
+ *
+ * \since This macro is available since SDL 3.4.0.
+ */
+#define SDL_ASSERT_FILE SDL_FILE
+
+#elif !defined(SDL_ASSERT_FILE)
+#define SDL_ASSERT_FILE SDL_FILE
+#endif
+
/**
* A macro that reports the current line number of the file being compiled.
@@ -194,11 +232,16 @@ extern "C" {
#define SDL_LINE __LINE__
/*
-sizeof (x) makes the compiler still parse the expression even without
-assertions enabled, so the code is always checked at compile time, but
+sizeof ((x) ? 1 : 0) makes the compiler still parse the expression even
+without assertions enabled, so the code is always checked at compile time, but
doesn't actually generate code for it, so there are no side effects or
-expensive checks at run time, just the constant size of what x WOULD be,
+expensive checks at run time, just the constant size of what int would be,
which presumably gets optimized out as unused.
+
+(The `? 1 : 0` is so this always dithers down to `sizeof (int)`...otherwise
+you'll have problems when bitfields are used as the condition, since the
+compiler will error out on the sizeof.)
+
This also solves the problem of...
int somevalue = blah();
@@ -230,7 +273,7 @@ disable assertions.
*/
#define SDL_NULL_WHILE_LOOP_CONDITION (0)
-#elif defined(_MSC_VER) /* Avoid /W4 warnings. */
+#elif defined(_MSC_VER) && !defined(__clang__) /* Avoid /W4 warnings. */
/* "while (0,0)" fools Microsoft's compiler's /W4 warning level into thinking
this condition isn't constant. And looks like an owl's face! */
#define SDL_NULL_WHILE_LOOP_CONDITION (0,0)
@@ -246,14 +289,14 @@ disable assertions.
*
* The code does nothing, but wraps `condition` in a sizeof operator, which
* generates no code and has no side effects, but avoid compiler warnings
- * about unused variables.
+ * about unused variables, and still checks syntax even when disabled.
*
* \param condition the condition to assert (but not actually run here).
*
* \since This macro is available since SDL 3.2.0.
*/
#define SDL_disabled_assert(condition) \
- do { (void) sizeof ((condition)); } while (SDL_NULL_WHILE_LOOP_CONDITION)
+ do { (void) sizeof ((condition) ? 1 : 0); } while (SDL_NULL_WHILE_LOOP_CONDITION)
/**
* Possible outcomes from a triggered assertion.
@@ -363,7 +406,7 @@ extern SDL_DECLSPEC SDL_AssertState SDLCALL SDL_ReportAssertion(SDL_AssertData *
do { \
while ( !(condition) ) { \
static struct SDL_AssertData sdl_assert_data = { false, 0, #condition, NULL, 0, NULL, NULL }; \
- const SDL_AssertState sdl_assert_state = SDL_ReportAssertion(&sdl_assert_data, SDL_FUNCTION, SDL_FILE, SDL_LINE); \
+ const SDL_AssertState sdl_assert_state = SDL_ReportAssertion(&sdl_assert_data, SDL_FUNCTION, SDL_ASSERT_FILE, SDL_LINE); \
if (sdl_assert_state == SDL_ASSERTION_RETRY) { \
continue; /* go again. */ \
} else if (sdl_assert_state == SDL_ASSERTION_BREAK) { \
diff --git a/thirdparty/sdl/include/SDL3/SDL_asyncio.h b/thirdparty/sdl/include/SDL3/SDL_asyncio.h
index b36cb071bcf..3c894d6964f 100644
--- a/thirdparty/sdl/include/SDL3/SDL_asyncio.h
+++ b/thirdparty/sdl/include/SDL3/SDL_asyncio.h
@@ -1,6 +1,6 @@
/*
Simple DirectMedia Layer
- Copyright (C) 1997-2025 Sam Lantinga <[email protected]>
+ Copyright (C) 1997-2026 Sam Lantinga <[email protected]>
This software is provided 'as-is', without any express or implied
warranty. In no event will the authors be held liable for any damages
@@ -213,6 +213,8 @@ typedef struct SDL_AsyncIOQueue SDL_AsyncIOQueue;
* \returns a pointer to the SDL_AsyncIO structure that is created or NULL on
* failure; call SDL_GetError() for more information.
*
+ * \threadsafety It is safe to call this function from any thread.
+ *
* \since This function is available since SDL 3.2.0.
*
* \sa SDL_CloseAsyncIO
@@ -531,6 +533,8 @@ extern SDL_DECLSPEC void SDLCALL SDL_SignalAsyncIOQueue(SDL_AsyncIOQueue *queue)
* \returns true on success or false on failure; call SDL_GetError() for more
* information.
*
+ * \threadsafety It is safe to call this function from any thread.
+ *
* \since This function is available since SDL 3.2.0.
*
* \sa SDL_LoadFile_IO
diff --git a/thirdparty/sdl/include/SDL3/SDL_atomic.h b/thirdparty/sdl/include/SDL3/SDL_atomic.h
index 78b5e0fa5bf..40521c1dbae 100644
--- a/thirdparty/sdl/include/SDL3/SDL_atomic.h
+++ b/thirdparty/sdl/include/SDL3/SDL_atomic.h
@@ -1,6 +1,6 @@
/*
Simple DirectMedia Layer
- Copyright (C) 1997-2025 Sam Lantinga <[email protected]>
+ Copyright (C) 1997-2026 Sam Lantinga <[email protected]>
This software is provided 'as-is', without any express or implied
warranty. In no event will the authors be held liable for any damages
@@ -156,6 +156,8 @@ extern SDL_DECLSPEC void SDLCALL SDL_UnlockSpinlock(SDL_SpinLock *lock);
*/
#define SDL_CompilerBarrier() DoCompilerSpecificReadWriteBarrier()
+#elif SDL_HAS_BUILTIN(__atomic_signal_fence) || (defined(__GNUC__) && (__GNUC__ >= 5))
+#define SDL_CompilerBarrier() __atomic_signal_fence(__ATOMIC_SEQ_CST)
#elif defined(_MSC_VER) && (_MSC_VER > 1200) && !defined(__clang__)
void _ReadWriteBarrier(void);
#pragma intrinsic(_ReadWriteBarrier)
@@ -167,8 +169,9 @@ void _ReadWriteBarrier(void);
extern __inline void SDL_CompilerBarrier(void);
#pragma aux SDL_CompilerBarrier = "" parm [] modify exact [];
#else
+/* We don't unlock here to avoid possible infinite recursion */
#define SDL_CompilerBarrier() \
-{ SDL_SpinLock _tmp = 0; SDL_LockSpinlock(&_tmp); SDL_UnlockSpinlock(&_tmp); }
+{ SDL_SpinLock _tmp = 0; SDL_LockSpinlock(&_tmp); }
#endif
/**
@@ -275,12 +278,19 @@ extern SDL_DECLSPEC void SDLCALL SDL_MemoryBarrierAcquireFunction(void);
*/
#define SDL_MemoryBarrierAcquire() SDL_MemoryBarrierAcquireFunction()
+#elif SDL_HAS_BUILTIN(__atomic_thread_fence) || (defined(__GNUC__) && (__GNUC__ >= 5))
+#define SDL_MemoryBarrierRelease() __atomic_thread_fence(__ATOMIC_RELEASE)
+#define SDL_MemoryBarrierAcquire() __atomic_thread_fence(__ATOMIC_ACQUIRE)
#elif defined(__GNUC__) && (defined(__powerpc__) || defined(__ppc__))
#define SDL_MemoryBarrierRelease() __asm__ __volatile__ ("lwsync" : : : "memory")
#define SDL_MemoryBarrierAcquire() __asm__ __volatile__ ("lwsync" : : : "memory")
#elif defined(__GNUC__) && defined(__aarch64__)
#define SDL_MemoryBarrierRelease() __asm__ __volatile__ ("dmb ish" : : : "memory")
-#define SDL_MemoryBarrierAcquire() __asm__ __volatile__ ("dmb ish" : : : "memory")
+#define SDL_MemoryBarrierAcquire() __asm__ __volatile__ ("dmb ishld" : : : "memory")
+#elif defined(_MSC_VER) && (defined(_M_ARM64) || defined(_M_ARM64EC))
+#include <arm64intr.h>
+#define SDL_MemoryBarrierRelease() __dmb(_ARM64_BARRIER_ISH)
+#define SDL_MemoryBarrierAcquire() __dmb(_ARM64_BARRIER_ISHLD)
#elif defined(__GNUC__) && defined(__arm__)
#if 0 /* defined(SDL_PLATFORM_LINUX) || defined(SDL_PLATFORM_ANDROID) */
/* Information from:
@@ -345,7 +355,7 @@ typedef void (*SDL_KernelMemoryBarrierFunc)();
*/
#define SDL_CPUPauseInstruction() DoACPUPauseInACompilerAndArchitectureSpecificWay
-#elif (defined(__GNUC__) || defined(__clang__)) && (defined(__i386__) || defined(__x86_64__))
+#elif (defined(__GNUC__) || defined(__clang__)) && (defined(__i386__) || defined(__x86_64__)) && !defined(__arm64ec__)
#define SDL_CPUPauseInstruction() __asm__ __volatile__("pause\n") /* Some assemblers can't do REP NOP, so go with PAUSE. */
#elif (defined(__arm__) && defined(__ARM_ARCH) && __ARM_ARCH >= 7) || defined(__aarch64__)
#define SDL_CPUPauseInstruction() __asm__ __volatile__("yield" ::: "memory")
@@ -596,6 +606,24 @@ extern SDL_DECLSPEC Uint32 SDLCALL SDL_SetAtomicU32(SDL_AtomicU32 *a, Uint32 v);
*/
extern SDL_DECLSPEC Uint32 SDLCALL SDL_GetAtomicU32(SDL_AtomicU32 *a);
+/**
+ * Add to an atomic variable.
+ *
+ * This function also acts as a full memory barrier.
+ *
+ * ***Note: If you don't know what this function is for, you shouldn't use
+ * it!***
+ *
+ * \param a a pointer to an SDL_AtomicU32 variable to be modified.
+ * \param v the desired value to add or subtract.
+ * \returns the previous value of the atomic variable.
+ *
+ * \threadsafety It is safe to call this function from any thread.
+ *
+ * \since This function is available since SDL 3.4.0.
+ */
+extern SDL_DECLSPEC Uint32 SDLCALL SDL_AddAtomicU32(SDL_AtomicU32 *a, int v);
+
/**
* Set a pointer to a new value if it is currently an old value.
*
diff --git a/thirdparty/sdl/include/SDL3/SDL_audio.h b/thirdparty/sdl/include/SDL3/SDL_audio.h
index 51af40e9552..1e1af26d75f 100644
--- a/thirdparty/sdl/include/SDL3/SDL_audio.h
+++ b/thirdparty/sdl/include/SDL3/SDL_audio.h
@@ -1,6 +1,6 @@
/*
Simple DirectMedia Layer
- Copyright (C) 1997-2025 Sam Lantinga <[email protected]>
+ Copyright (C) 1997-2026 Sam Lantinga <[email protected]>
This software is provided 'as-is', without any express or implied
warranty. In no event will the authors be held liable for any damages
@@ -434,7 +434,8 @@ typedef struct SDL_AudioSpec
* - It can handle incoming data in any variable size.
* - It can handle input/output format changes on the fly.
* - It can remap audio channels between inputs and outputs.
- * - You push data as you have it, and pull it when you need it
+ * - You push data as you have it, and pull it when you need it; the
+ * stream will buffer data as needed.
* - It can also function as a basic audio data queue even if you just have
* sound that needs to pass from one place to another.
* - You can hook callbacks up to them when more data is added or requested,
@@ -577,6 +578,15 @@ extern SDL_DECLSPEC SDL_AudioDeviceID * SDLCALL SDL_GetAudioRecordingDevices(int
/**
* Get the human-readable name of a specific audio device.
*
+ * **WARNING**: this function will work with SDL_AUDIO_DEVICE_DEFAULT_PLAYBACK
+ * and SDL_AUDIO_DEVICE_DEFAULT_RECORDING, returning the current default
+ * physical devices' names. However, as the default device may change at any
+ * time, it is likely better to show a generic name to the user, like "System
+ * default audio device" or perhaps "default [currently %s]". Do not store
+ * this name to disk to reidentify the device in a later run of the program,
+ * as the default might change in general, and the string will be the name of
+ * a specific device and not the abstract system default.
+ *
* \param devid the instance ID of the device to query.
* \returns the name of the audio device, or NULL on failure; call
* SDL_GetError() for more information.
@@ -1024,7 +1034,8 @@ extern SDL_DECLSPEC void SDLCALL SDL_UnbindAudioStream(SDL_AudioStream *stream);
/**
* Query an audio stream for its currently-bound device.
*
- * This reports the logical audio device that an audio stream is currently bound to.
+ * This reports the logical audio device that an audio stream is currently
+ * bound to.
*
* If not bound, or invalid, this returns zero, which is not a valid device
* ID.
@@ -1044,8 +1055,15 @@ extern SDL_DECLSPEC SDL_AudioDeviceID SDLCALL SDL_GetAudioStreamDevice(SDL_Audio
/**
* Create a new audio stream.
*
- * \param src_spec the format details of the input audio.
- * \param dst_spec the format details of the output audio.
+ * Note that `src_spec` or `dst_spec` may be NULL, but any attempts to
+ * put or get data from an audio stream will fail until it has valid
+ * specs assigned to both ends of the stream. Specs can be assigned later
+ * through SDL_SetAudioStreamFormat(), or binding the stream to an audio
+ * device (which will set the format of only the input or output,
+ * depending on what kind of device the stream was bound to).
+ *
+ * \param src_spec the format details of the input audio. May be NULL.
+ * \param dst_spec the format details of the output audio. May be NULL.
* \returns a new audio stream on success or NULL on failure; call
* SDL_GetError() for more information.
*
@@ -1066,6 +1084,17 @@ extern SDL_DECLSPEC SDL_AudioStream * SDLCALL SDL_CreateAudioStream(const SDL_Au
/**
* Get the properties associated with an audio stream.
*
+ * The application can hang any data it wants here, but the following
+ * properties are understood by SDL:
+ *
+ * - `SDL_PROP_AUDIOSTREAM_AUTO_CLEANUP_BOOLEAN`: if true (the default), the
+ * stream be automatically cleaned up when the audio subsystem quits. If set
+ * to false, the streams will persist beyond that. This property is ignored
+ * for streams created through SDL_OpenAudioDeviceStream(), and will always
+ * be cleaned up. Streams that are not cleaned up will still be unbound from
+ * devices when the audio subsystem quits. This property was added in SDL
+ * 3.4.0.
+ *
* \param stream the SDL_AudioStream to query.
* \returns a valid property ID on success or 0 on failure; call
* SDL_GetError() for more information.
@@ -1076,6 +1105,9 @@ extern SDL_DECLSPEC SDL_AudioStream * SDLCALL SDL_CreateAudioStream(const SDL_Au
*/
extern SDL_DECLSPEC SDL_PropertiesID SDLCALL SDL_GetAudioStreamProperties(SDL_AudioStream *stream);
+#define SDL_PROP_AUDIOSTREAM_AUTO_CLEANUP_BOOLEAN "SDL.audiostream.auto_cleanup"
+
+
/**
* Query the current format of an audio stream.
*
@@ -1113,6 +1145,9 @@ extern SDL_DECLSPEC bool SDLCALL SDL_GetAudioStreamFormat(SDL_AudioStream *strea
* be ignored, but this will not report an error. The other side's format can
* be changed.
*
+ * `src_spec` and `dst_spec` may each be NULL; a NULL spec signals not to
+ * change the current format for that side of the stream.
+ *
* \param stream the stream the format is being changed.
* \param src_spec the new format of the audio input; if NULL, it is not
* changed.
@@ -1152,14 +1187,14 @@ extern SDL_DECLSPEC float SDLCALL SDL_GetAudioStreamFrequencyRatio(SDL_AudioStre
*
* The frequency ratio is used to adjust the rate at which input data is
* consumed. Changing this effectively modifies the speed and pitch of the
- * audio. A value greater than 1.0 will play the audio faster, and at a higher
- * pitch. A value less than 1.0 will play the audio slower, and at a lower
- * pitch.
+ * audio. A value greater than 1.0f will play the audio faster, and at a
+ * higher pitch. A value less than 1.0f will play the audio slower, and at a
+ * lower pitch. 1.0f means play at normal speed.
*
* This is applied during SDL_GetAudioStreamData, and can be continuously
* changed to create various effects.
*
- * \param stream the stream the frequency ratio is being changed.
+ * \param stream the stream on which the frequency ratio is being changed.
* \param ratio the frequency ratio. 1.0 is normal speed. Must be between 0.01
* and 100.
* \returns true on success or false on failure; call SDL_GetError() for more
@@ -1321,11 +1356,11 @@ extern SDL_DECLSPEC int * SDLCALL SDL_GetAudioStreamOutputChannelMap(SDL_AudioSt
* \threadsafety It is safe to call this function from any thread, as it holds
* a stream-specific mutex while running. Don't change the
* stream's format to have a different number of channels from a
- * a different thread at the same time, though!
+ * different thread at the same time, though!
*
* \since This function is available since SDL 3.2.0.
*
- * \sa SDL_SetAudioStreamInputChannelMap
+ * \sa SDL_SetAudioStreamOutputChannelMap
*/
extern SDL_DECLSPEC bool SDLCALL SDL_SetAudioStreamInputChannelMap(SDL_AudioStream *stream, const int *chmap, int count);
@@ -1335,7 +1370,7 @@ extern SDL_DECLSPEC bool SDLCALL SDL_SetAudioStreamInputChannelMap(SDL_AudioStre
* Channel maps are optional; most things do not need them, instead passing
* data in the [order that SDL expects](CategoryAudio#channel-layouts).
*
- * The output channel map reorders data that leaving a stream via
+ * The output channel map reorders data that is leaving a stream via
* SDL_GetAudioStreamData.
*
* Each item in the array represents an input channel, and its value is the
@@ -1417,6 +1452,136 @@ extern SDL_DECLSPEC bool SDLCALL SDL_SetAudioStreamOutputChannelMap(SDL_AudioStr
*/
extern SDL_DECLSPEC bool SDLCALL SDL_PutAudioStreamData(SDL_AudioStream *stream, const void *buf, int len);
+/**
+ * A callback that fires for completed SDL_PutAudioStreamDataNoCopy() data.
+ *
+ * When using SDL_PutAudioStreamDataNoCopy() to provide data to an
+ * SDL_AudioStream, it's not safe to dispose of the data until the stream has
+ * completely consumed it. Often times it's difficult to know exactly when
+ * this has happened.
+ *
+ * This callback fires once when the stream no longer needs the buffer,
+ * allowing the app to easily free or reuse it.
+ *
+ * \param userdata an opaque pointer provided by the app for their personal
+ * use.
+ * \param buf the pointer provided to SDL_PutAudioStreamDataNoCopy().
+ * \param buflen the size of buffer, in bytes, provided to
+ * SDL_PutAudioStreamDataNoCopy().
+ *
+ * \threadsafety This callbacks may run from any thread, so if you need to
+ * protect shared data, you should use SDL_LockAudioStream to
+ * serialize access; this lock will be held before your callback
+ * is called, so your callback does not need to manage the lock
+ * explicitly.
+ *
+ * \since This datatype is available since SDL 3.4.0.
+ *
+ * \sa SDL_SetAudioStreamGetCallback
+ * \sa SDL_SetAudioStreamPutCallback
+ */
+typedef void (SDLCALL *SDL_AudioStreamDataCompleteCallback)(void *userdata, const void *buf, int buflen);
+
+/**
+ * Add external data to an audio stream without copying it.
+ *
+ * Unlike SDL_PutAudioStreamData(), this function does not make a copy of the
+ * provided data, instead storing the provided pointer. This means that the
+ * put operation does not need to allocate and copy the data, but the original
+ * data must remain available until the stream is done with it, either by
+ * being read from the stream in its entirety, or a call to
+ * SDL_ClearAudioStream() or SDL_DestroyAudioStream().
+ *
+ * The data must match the format/channels/samplerate specified in the latest
+ * call to SDL_SetAudioStreamFormat, or the format specified when creating the
+ * stream if it hasn't been changed.
+ *
+ * An optional callback may be provided, which is called when the stream no
+ * longer needs the data. Once this callback fires, the stream will not access
+ * the data again. This callback will fire for any reason the data is no
+ * longer needed, including clearing or destroying the stream.
+ *
+ * Note that there is still an allocation to store tracking information, so
+ * this function is more efficient for larger blocks of data. If you're
+ * planning to put a few samples at a time, it will be more efficient to use
+ * SDL_PutAudioStreamData(), which allocates and buffers in blocks.
+ *
+ * \param stream the stream the audio data is being added to.
+ * \param buf a pointer to the audio data to add.
+ * \param len the number of bytes to add to the stream.
+ * \param callback the callback function to call when the data is no longer
+ * needed by the stream. May be NULL.
+ * \param userdata an opaque pointer provided to the callback for its own
+ * personal use.
+ * \returns true on success or false on failure; call SDL_GetError() for more
+ * information.
+ *
+ * \threadsafety It is safe to call this function from any thread, but if the
+ * stream has a callback set, the caller might need to manage
+ * extra locking.
+ *
+ * \since This function is available since SDL 3.4.0.
+ *
+ * \sa SDL_ClearAudioStream
+ * \sa SDL_FlushAudioStream
+ * \sa SDL_GetAudioStreamData
+ * \sa SDL_GetAudioStreamQueued
+ */
+extern SDL_DECLSPEC bool SDLCALL SDL_PutAudioStreamDataNoCopy(SDL_AudioStream *stream, const void *buf, int len, SDL_AudioStreamDataCompleteCallback callback, void *userdata);
+
+/**
+ * Add data to the stream with each channel in a separate array.
+ *
+ * This data must match the format/channels/samplerate specified in the latest
+ * call to SDL_SetAudioStreamFormat, or the format specified when creating the
+ * stream if it hasn't been changed.
+ *
+ * The data will be interleaved and queued. Note that SDL_AudioStream only
+ * operates on interleaved data, so this is simply a convenience function for
+ * easily queueing data from sources that provide separate arrays. There is no
+ * equivalent function to retrieve planar data.
+ *
+ * The arrays in `channel_buffers` are ordered as they are to be interleaved;
+ * the first array will be the first sample in the interleaved data. Any
+ * individual array may be NULL; in this case, silence will be interleaved for
+ * that channel.
+ *
+ * `num_channels` specifies how many arrays are in `channel_buffers`. This can
+ * be used as a safety to prevent overflow, in case the stream format has
+ * changed elsewhere. If more channels are specified than the current input
+ * spec, they are ignored. If less channels are specified, the missing arrays
+ * are treated as if they are NULL (silence is written to those channels). If
+ * the count is -1, SDL will assume the array count matches the current input
+ * spec.
+ *
+ * Note that `num_samples` is the number of _samples per array_. This can also
+ * be thought of as the number of _sample frames_ to be queued. A value of 1
+ * with stereo arrays will queue two samples to the stream. This is different
+ * than SDL_PutAudioStreamData, which wants the size of a single array in
+ * bytes.
+ *
+ * \param stream the stream the audio data is being added to.
+ * \param channel_buffers a pointer to an array of arrays, one array per
+ * channel.
+ * \param num_channels the number of arrays in `channel_buffers` or -1.
+ * \param num_samples the number of _samples_ per array to write to the
+ * stream.
+ * \returns true on success or false on failure; call SDL_GetError() for more
+ * information.
+ *
+ * \threadsafety It is safe to call this function from any thread, but if the
+ * stream has a callback set, the caller might need to manage
+ * extra locking.
+ *
+ * \since This function is available since SDL 3.4.0.
+ *
+ * \sa SDL_ClearAudioStream
+ * \sa SDL_FlushAudioStream
+ * \sa SDL_GetAudioStreamData
+ * \sa SDL_GetAudioStreamQueued
+ */
+extern SDL_DECLSPEC bool SDLCALL SDL_PutAudioStreamPlanarData(SDL_AudioStream *stream, const void * const *channel_buffers, int num_channels, int num_samples);
+
/**
* Get converted/resampled data from the stream.
*
@@ -1586,8 +1751,8 @@ extern SDL_DECLSPEC bool SDLCALL SDL_PauseAudioStreamDevice(SDL_AudioStream *str
* previously been paused. Once unpaused, any bound audio streams will begin
* to progress again, and audio can be generated.
*
- * Remember, SDL_OpenAudioDeviceStream opens device in a paused state, so this
- * function call is required for audio playback to begin on such device.
+ * SDL_OpenAudioDeviceStream opens audio devices in a paused state, so this
+ * function call is required for audio playback to begin on such devices.
*
* \param stream the audio stream associated with the audio device to resume.
* \returns true on success or false on failure; call SDL_GetError() for more
@@ -1689,6 +1854,8 @@ extern SDL_DECLSPEC bool SDLCALL SDL_UnlockAudioStream(SDL_AudioStream *stream);
* appropriate, but the system goes on with the data currently available to it
* if this callback does nothing.
*
+ * Do not call SDL_DestroyAudioStream() on `stream` during this callback.
+ *
* \param stream the SDL audio stream associated with this callback.
* \param additional_amount the amount of data, in bytes, that is needed right
* now.
@@ -1844,7 +2011,7 @@ extern SDL_DECLSPEC void SDLCALL SDL_DestroyAudioStream(SDL_AudioStream *stream)
* Also unlike other functions, the audio device begins paused. This is to map
* more closely to SDL2-style behavior, since there is no extra step here to
* bind a stream to begin audio flowing. The audio device should be resumed
- * with `SDL_ResumeAudioStreamDevice(stream);`
+ * with SDL_ResumeAudioStreamDevice().
*
* This function works with both playback and recording devices.
*
diff --git a/thirdparty/sdl/include/SDL3/SDL_begin_code.h b/thirdparty/sdl/include/SDL3/SDL_begin_code.h
index a6b47cf4b91..4f3fe2d984f 100644
--- a/thirdparty/sdl/include/SDL3/SDL_begin_code.h
+++ b/thirdparty/sdl/include/SDL3/SDL_begin_code.h
@@ -1,6 +1,6 @@
/*
Simple DirectMedia Layer
- Copyright (C) 1997-2025 Sam Lantinga <[email protected]>
+ Copyright (C) 1997-2026 Sam Lantinga <[email protected]>
This software is provided 'as-is', without any express or implied
warranty. In no event will the authors be held liable for any damages
@@ -261,9 +261,9 @@
*
* On compilers without restrict support, this is defined to nothing.
*
- * \since This macro is available since SDL 3.2.0.
+ * \since This macro is available since SDL 3.4.0.
*/
-#define SDL_RESTRICT __restrict__
+#define SDL_RESTRICT __restrict
/**
* Check if the compiler supports a given builtin functionality.
@@ -281,9 +281,61 @@
*/
#define SDL_HAS_BUILTIN(x) __has_builtin(x)
+/**
+ * A macro to specify data alignment.
+ *
+ * This informs the compiler that a given datatype or variable must be aligned
+ * to a specific byte count.
+ *
+ * For example:
+ *
+ * ```c
+ * // make sure this is struct is aligned to 16 bytes for SIMD access.
+ * typedef struct {
+ * float x, y, z, w;
+ * } SDL_ALIGNED(16) MySIMDAlignedData;
+ *
+ * // make sure this one field in a struct is aligned to 16 bytes for SIMD access.
+ * typedef struct {
+ * SomeStuff stuff;
+ * float SDL_ALIGNED(16) position[4];
+ * SomeOtherStuff other_stuff;
+ * } MyStruct;
+ *
+ * // make sure this variable is aligned to 32 bytes.
+ * int SDL_ALIGNED(32) myval = 0;
+ * ```
+ *
+ * Alignment is only guaranteed for things the compiler places: local
+ * variables on the stack and global/static variables. To dynamically allocate
+ * something that respects this alignment, use SDL_aligned_alloc() or some
+ * other mechanism.
+ *
+ * On compilers without alignment support, this macro is defined to an invalid
+ * symbol, to make it clear that the current compiler is likely to generate
+ * incorrect code when it sees this macro.
+ *
+ * \param x the byte count to align to, so the data's address will be a
+ * multiple of this value.
+ *
+ * \since This macro is available since SDL 3.4.0.
+ */
+#define SDL_ALIGNED(x) __attribute__((aligned(x)))
+
/* end of wiki documentation section. */
#endif
+/* `restrict` is from C99, but __restrict works with both Visual Studio and GCC. */
+#ifndef SDL_RESTRICT
+# if defined(restrict) || ((defined(__STDC_VERSION__) && (__STDC_VERSION__ >= 199901L)))
+# define SDL_RESTRICT restrict
+# elif defined(_MSC_VER) || defined(__GNUC__) || defined(__clang__)
+# define SDL_RESTRICT __restrict
+# else
+# define SDL_RESTRICT
+# endif
+#endif
+
#ifndef SDL_HAS_BUILTIN
#ifdef __has_builtin
#define SDL_HAS_BUILTIN(x) __has_builtin(x)
@@ -379,7 +431,7 @@
#endif /* SDL_INLINE not defined */
#ifndef SDL_FORCE_INLINE
-#ifdef _MSC_VER
+#if defined(_MSC_VER) && (_MSC_VER >= 1200)
#define SDL_FORCE_INLINE __forceinline
#elif ( (defined(__GNUC__) && (__GNUC__ >= 4)) || defined(__clang__) )
#define SDL_FORCE_INLINE __attribute__((always_inline)) static __inline__
@@ -389,7 +441,7 @@
#endif /* SDL_FORCE_INLINE not defined */
#ifndef SDL_NORETURN
-#ifdef __GNUC__
+#if defined(__GNUC__)
#define SDL_NORETURN __attribute__((noreturn))
#elif defined(_MSC_VER)
#define SDL_NORETURN __declspec(noreturn)
@@ -417,7 +469,7 @@
#define NULL ((void *)0)
#endif
#endif /* NULL */
-#endif /* ! macOS - breaks precompiled headers */
+#endif /* __MACH__ */
#ifndef SDL_FALLTHROUGH
#if (defined(__cplusplus) && __cplusplus >= 201703L) || \
@@ -484,3 +536,18 @@
#define SDL_ALLOC_SIZE2(p1, p2)
#endif
#endif /* SDL_ALLOC_SIZE2 not defined */
+
+#ifndef SDL_ALIGNED
+#if defined(__clang__) || defined(__GNUC__)
+#define SDL_ALIGNED(x) __attribute__((aligned(x)))
+#elif defined(_MSC_VER)
+#define SDL_ALIGNED(x) __declspec(align(x))
+#elif defined(__cplusplus) && (__cplusplus >= 201103L)
+#define SDL_ALIGNED(x) alignas(x)
+#elif defined(__STDC_VERSION__) && (__STDC_VERSION__ >= 201112L)
+#define SDL_ALIGNED(x) _Alignas(x)
+#else
+#define SDL_ALIGNED(x) PLEASE_DEFINE_SDL_ALIGNED
+#endif
+#endif /* SDL_ALIGNED not defined */
+
diff --git a/thirdparty/sdl/include/SDL3/SDL_bits.h b/thirdparty/sdl/include/SDL3/SDL_bits.h
index 7435ce6d939..d3310ab15ce 100644
--- a/thirdparty/sdl/include/SDL3/SDL_bits.h
+++ b/thirdparty/sdl/include/SDL3/SDL_bits.h
@@ -1,6 +1,6 @@
/*
Simple DirectMedia Layer
- Copyright (C) 1997-2025 Sam Lantinga <[email protected]>
+ Copyright (C) 1997-2026 Sam Lantinga <[email protected]>
This software is provided 'as-is', without any express or implied
warranty. In no event will the authors be held liable for any damages
@@ -48,8 +48,7 @@ extern __inline int _SDL_bsr_watcom(Uint32);
/**
* Get the index of the most significant (set) bit in a 32-bit number.
*
- * Result is undefined when called with 0. This operation can also be stated
- * as "count leading zeroes" and "log base 2".
+ * This operation can also be stated as "count leading zeroes" and "log base 2".
*
* Note that this is a forced-inline function in a header, and not a public
* API function available in the SDL library (which is to say, the code is
diff --git a/thirdparty/sdl/include/SDL3/SDL_blendmode.h b/thirdparty/sdl/include/SDL3/SDL_blendmode.h
index 8f00cbcafb0..84cf622cb7a 100644
--- a/thirdparty/sdl/include/SDL3/SDL_blendmode.h
+++ b/thirdparty/sdl/include/SDL3/SDL_blendmode.h
@@ -1,6 +1,6 @@
/*
Simple DirectMedia Layer
- Copyright (C) 1997-2025 Sam Lantinga <[email protected]>
+ Copyright (C) 1997-2026 Sam Lantinga <[email protected]>
This software is provided 'as-is', without any express or implied
warranty. In no event will the authors be held liable for any damages
diff --git a/thirdparty/sdl/include/SDL3/SDL_camera.h b/thirdparty/sdl/include/SDL3/SDL_camera.h
index c0e2ee0fed4..220acd1bf36 100644
--- a/thirdparty/sdl/include/SDL3/SDL_camera.h
+++ b/thirdparty/sdl/include/SDL3/SDL_camera.h
@@ -1,6 +1,6 @@
/*
Simple DirectMedia Layer
- Copyright (C) 1997-2025 Sam Lantinga <[email protected]>
+ Copyright (C) 1997-2026 Sam Lantinga <[email protected]>
This software is provided 'as-is', without any express or implied
warranty. In no event will the authors be held liable for any damages
@@ -136,6 +136,20 @@ typedef enum SDL_CameraPosition
SDL_CAMERA_POSITION_BACK_FACING
} SDL_CameraPosition;
+/**
+ * The current state of a request for camera access.
+ *
+ * \since This enum is available since SDL 3.4.0.
+ *
+ * \sa SDL_GetCameraPermissionState
+ */
+typedef enum SDL_CameraPermissionState
+{
+ SDL_CAMERA_PERMISSION_STATE_DENIED = -1,
+ SDL_CAMERA_PERMISSION_STATE_PENDING,
+ SDL_CAMERA_PERMISSION_STATE_APPROVED
+} SDL_CameraPermissionState;
+
/**
* Use this function to get the number of built-in camera drivers.
@@ -346,8 +360,9 @@ extern SDL_DECLSPEC SDL_Camera * SDLCALL SDL_OpenCamera(SDL_CameraID instance_id
* on others the approval might be implicit and not alert the user at all.
*
* This function can be used to check the status of that approval. It will
- * return 0 if still waiting for user response, 1 if the camera is approved
- * for use, and -1 if the user denied access.
+ * return SDL_CAMERA_PERMISSION_STATE_PENDING if waiting for user response,
+ * SDL_CAMERA_PERMISSION_STATE_APPROVED if the camera is approved for use, and
+ * SDL_CAMERA_PERMISSION_STATE_DENIED if the user denied access.
*
* Instead of polling with this function, you can wait for a
* SDL_EVENT_CAMERA_DEVICE_APPROVED (or SDL_EVENT_CAMERA_DEVICE_DENIED) event
@@ -358,8 +373,9 @@ extern SDL_DECLSPEC SDL_Camera * SDLCALL SDL_OpenCamera(SDL_CameraID instance_id
* SDL_CloseCamera() to dispose of it.
*
* \param camera the opened camera device to query.
- * \returns -1 if user denied access to the camera, 1 if user approved access,
- * 0 if no decision has been made yet.
+ * \returns an SDL_CameraPermissionState value indicating if access is
+ * granted, or `SDL_CAMERA_PERMISSION_STATE_PENDING` if the decision
+ * is still pending.
*
* \threadsafety It is safe to call this function from any thread.
*
@@ -368,7 +384,7 @@ extern SDL_DECLSPEC SDL_Camera * SDLCALL SDL_OpenCamera(SDL_CameraID instance_id
* \sa SDL_OpenCamera
* \sa SDL_CloseCamera
*/
-extern SDL_DECLSPEC int SDLCALL SDL_GetCameraPermissionState(SDL_Camera *camera);
+extern SDL_DECLSPEC SDL_CameraPermissionState SDLCALL SDL_GetCameraPermissionState(SDL_Camera *camera);
/**
* Get the instance ID of an opened camera.
diff --git a/thirdparty/sdl/include/SDL3/SDL_clipboard.h b/thirdparty/sdl/include/SDL3/SDL_clipboard.h
index a4b4cc9b9ef..487f9746cbe 100644
--- a/thirdparty/sdl/include/SDL3/SDL_clipboard.h
+++ b/thirdparty/sdl/include/SDL3/SDL_clipboard.h
@@ -1,6 +1,6 @@
/*
Simple DirectMedia Layer
- Copyright (C) 1997-2025 Sam Lantinga <[email protected]>
+ Copyright (C) 1997-2026 Sam Lantinga <[email protected]>
This software is provided 'as-is', without any express or implied
warranty. In no event will the authors be held liable for any damages
@@ -210,8 +210,8 @@ extern SDL_DECLSPEC bool SDLCALL SDL_HasPrimarySelectionText(void);
typedef const void *(SDLCALL *SDL_ClipboardDataCallback)(void *userdata, const char *mime_type, size_t *size);
/**
- * Callback function that will be called when the clipboard is cleared, or when new
- * data is set.
+ * Callback function that will be called when the clipboard is cleared, or
+ * when new data is set.
*
* \param userdata a pointer to the provided user data.
*
@@ -238,7 +238,8 @@ typedef void (SDLCALL *SDL_ClipboardCleanupCallback)(void *userdata);
* \param cleanup a function pointer to the function that cleans up the
* clipboard data.
* \param userdata an opaque pointer that will be forwarded to the callbacks.
- * \param mime_types a list of mime-types that are being offered. SDL copies the given list.
+ * \param mime_types a list of mime-types that are being offered. SDL copies
+ * the given list.
* \param num_mime_types the number of mime-types in the mime_types list.
* \returns true on success or false on failure; call SDL_GetError() for more
* information.
@@ -251,7 +252,7 @@ typedef void (SDLCALL *SDL_ClipboardCleanupCallback)(void *userdata);
* \sa SDL_GetClipboardData
* \sa SDL_HasClipboardData
*/
-extern SDL_DECLSPEC bool SDLCALL SDL_SetClipboardData(SDL_ClipboardDataCallback callback, SDL_ClipboardCleanupCallback cleanup, void *userdata, const char **mime_types, size_t num_mime_types);
+extern SDL_DECLSPEC bool SDLCALL SDL_SetClipboardData(SDL_ClipboardDataCallback callback, SDL_ClipboardCleanupCallback cleanup, void *userdata, const char *const *mime_types, size_t num_mime_types);
/**
* Clear the clipboard data.
diff --git a/thirdparty/sdl/include/SDL3/SDL_close_code.h b/thirdparty/sdl/include/SDL3/SDL_close_code.h
index da1dea7fac0..ad9daa6d43e 100644
--- a/thirdparty/sdl/include/SDL3/SDL_close_code.h
+++ b/thirdparty/sdl/include/SDL3/SDL_close_code.h
@@ -1,6 +1,6 @@
/*
Simple DirectMedia Layer
- Copyright (C) 1997-2025 Sam Lantinga <[email protected]>
+ Copyright (C) 1997-2026 Sam Lantinga <[email protected]>
This software is provided 'as-is', without any express or implied
warranty. In no event will the authors be held liable for any damages
diff --git a/thirdparty/sdl/include/SDL3/SDL_copying.h b/thirdparty/sdl/include/SDL3/SDL_copying.h
index 747bd357008..dd9dbc7ee30 100644
--- a/thirdparty/sdl/include/SDL3/SDL_copying.h
+++ b/thirdparty/sdl/include/SDL3/SDL_copying.h
@@ -1,6 +1,6 @@
/*
Simple DirectMedia Layer
- Copyright (C) 1997-2025 Sam Lantinga <[email protected]>
+ Copyright (C) 1997-2026 Sam Lantinga <[email protected]>
This software is provided 'as-is', without any express or implied
warranty. In no event will the authors be held liable for any damages
diff --git a/thirdparty/sdl/include/SDL3/SDL_cpuinfo.h b/thirdparty/sdl/include/SDL3/SDL_cpuinfo.h
index 1745bd93490..5669c2373d9 100644
--- a/thirdparty/sdl/include/SDL3/SDL_cpuinfo.h
+++ b/thirdparty/sdl/include/SDL3/SDL_cpuinfo.h
@@ -1,6 +1,6 @@
/*
Simple DirectMedia Layer
- Copyright (C) 1997-2025 Sam Lantinga <[email protected]>
+ Copyright (C) 1997-2026 Sam Lantinga <[email protected]>
This software is provided 'as-is', without any express or implied
warranty. In no event will the authors be held liable for any damages
@@ -344,6 +344,27 @@ extern SDL_DECLSPEC int SDLCALL SDL_GetSystemRAM(void);
*/
extern SDL_DECLSPEC size_t SDLCALL SDL_GetSIMDAlignment(void);
+/**
+ * Report the size of a page of memory.
+ *
+ * Different platforms might have different memory page sizes. In current
+ * times, 4 kilobytes is not unusual, but newer systems are moving to larger
+ * page sizes, and esoteric platforms might have any unexpected size.
+ *
+ * Note that this function can return 0, which means SDL can't determine the
+ * page size on this platform. It will _not_ set an error string to be
+ * retrieved with SDL_GetError() in this case! In this case, defaulting to
+ * 4096 is often a reasonable option.
+ *
+ * \returns the size of a single page of memory, in bytes, or 0 if SDL can't
+ * determine this information.
+ *
+ * \threadsafety It is safe to call this function from any thread.
+ *
+ * \since This function is available since SDL 3.4.0.
+ */
+extern SDL_DECLSPEC int SDLCALL SDL_GetSystemPageSize(void);
+
/* Ends C function definitions when using C++ */
#ifdef __cplusplus
}
diff --git a/thirdparty/sdl/include/SDL3/SDL_dialog.h b/thirdparty/sdl/include/SDL3/SDL_dialog.h
index ddb9e24d5fe..1e01347bf2c 100644
--- a/thirdparty/sdl/include/SDL3/SDL_dialog.h
+++ b/thirdparty/sdl/include/SDL3/SDL_dialog.h
@@ -1,6 +1,6 @@
/*
Simple DirectMedia Layer
- Copyright (C) 1997-2025 Sam Lantinga <[email protected]>
+ Copyright (C) 1997-2026 Sam Lantinga <[email protected]>
This software is provided 'as-is', without any express or implied
warranty. In no event will the authors be held liable for any damages
@@ -139,10 +139,12 @@ typedef void (SDLCALL *SDL_DialogFileCallback)(void *userdata, const char * cons
* it will be invoked.
* \param window the window that the dialog should be modal for, may be NULL.
* Not all platforms support this option.
- * \param filters a list of filters, may be NULL. Not all platforms support
- * this option, and platforms that do support it may allow the
- * user to ignore the filters. If non-NULL, it must remain
- * valid at least until the callback is invoked.
+ * \param filters a list of filters, may be NULL. See the
+ * [`SDL_DialogFileFilter`](SDL_DialogFileFilter#code-examples)
+ * documentation for examples]. Not all platforms support this
+ * option, and platforms that do support it may allow the user
+ * to ignore the filters. If non-NULL, it must remain valid at
+ * least until the callback is invoked.
* \param nfilters the number of filters. Ignored if filters is NULL.
* \param default_location the default folder or file to start the dialog at,
* may be NULL. Not all platforms support this option.
diff --git a/thirdparty/sdl/include/SDL3/SDL_dlopennote.h b/thirdparty/sdl/include/SDL3/SDL_dlopennote.h
new file mode 100644
index 00000000000..299435a5d1e
--- /dev/null
+++ b/thirdparty/sdl/include/SDL3/SDL_dlopennote.h
@@ -0,0 +1,234 @@
+/*
+ Simple DirectMedia Layer
+ Copyright (C) 1997-2026 Sam Lantinga <[email protected]>
+
+ 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.
+*/
+
+/* WIKI CATEGORY: DlopenNotes */
+
+/**
+ * # CategoryDlopenNotes
+ *
+ * This header allows you to annotate your code so external tools know about
+ * dynamic shared library dependencies.
+ *
+ * If you determine that your toolchain doesn't support dlopen notes, you can
+ * disable this feature by defining `SDL_DISABLE_DLOPEN_NOTES`. You can use
+ * this CMake snippet to check for support:
+ *
+ * ```cmake
+ * include(CheckCSourceCompiles)
+ * find_package(SDL3 REQUIRED CONFIG COMPONENTS Headers)
+ * list(APPEND CMAKE_REQUIRED_LIBRARIES SDL3::Headers)
+ * check_c_source_compiles([==[
+ * #include <SDL3/SDL_dlopennote.h>
+ * SDL_ELF_NOTE_DLOPEN("sdl-video",
+ * "Support for video through SDL",
+ * SDL_ELF_NOTE_DLOPEN_PRIORITY_SUGGESTED,
+ * "libSDL-1.2.so.0", "libSDL-2.0.so.0", "libSDL3.so.0"
+ * )
+ * int main(int argc, char *argv[]) {
+ * return argc + argv[0][1];
+ * }
+ * ]==] COMPILER_SUPPORTS_SDL_ELF_NOTE_DLOPEN)
+ * if(NOT COMPILER_SUPPORTS_SDL_ELF_NOTE_DLOPEN)
+ * add_compile_definitions(-DSDL_DISABLE_DLOPEN_NOTE)
+ * endif()
+ * ```
+ */
+
+#ifndef SDL_dlopennote_h
+#define SDL_dlopennote_h
+
+/**
+ * Use this macro with SDL_ELF_NOTE_DLOPEN() to note that a dynamic shared
+ * library dependency is optional.
+ *
+ * Optional functionality uses the dependency, the binary will work and the
+ * dependency is only needed for full-featured installations.
+ *
+ * \since This macro is available since SDL 3.4.0.
+ *
+ * \sa SDL_ELF_NOTE_DLOPEN
+ * \sa SDL_ELF_NOTE_DLOPEN_PRIORITY_RECOMMENDED
+ * \sa SDL_ELF_NOTE_DLOPEN_PRIORITY_REQUIRED
+ */
+#define SDL_ELF_NOTE_DLOPEN_PRIORITY_SUGGESTED "suggested"
+
+/**
+ * Use this macro with SDL_ELF_NOTE_DLOPEN() to note that a dynamic shared
+ * library dependency is recommended.
+ *
+ * Important functionality needs the dependency, the binary will work but in
+ * most cases the dependency should be provided.
+ *
+ * \since This macro is available since SDL 3.4.0.
+ *
+ * \sa SDL_ELF_NOTE_DLOPEN
+ * \sa SDL_ELF_NOTE_DLOPEN_PRIORITY_SUGGESTED
+ * \sa SDL_ELF_NOTE_DLOPEN_PRIORITY_REQUIRED
+ */
+#define SDL_ELF_NOTE_DLOPEN_PRIORITY_RECOMMENDED "recommended"
+
+/**
+ * Use this macro with SDL_ELF_NOTE_DLOPEN() to note that a dynamic shared
+ * library dependency is required.
+ *
+ * Core functionality needs the dependency, the binary will not work if it
+ * cannot be found.
+ *
+ * \since This macro is available since SDL 3.4.0.
+ *
+ * \sa SDL_ELF_NOTE_DLOPEN
+ * \sa SDL_ELF_NOTE_DLOPEN_PRIORITY_SUGGESTED
+ * \sa SDL_ELF_NOTE_DLOPEN_PRIORITY_RECOMMENDED
+ */
+#define SDL_ELF_NOTE_DLOPEN_PRIORITY_REQUIRED "required"
+
+
+#if !defined(SDL_PLATFORM_UNIX) || defined(SDL_PLATFORM_ANDROID)
+/* The dlopen note functionality isn't used on this platform */
+#ifndef SDL_DISABLE_DLOPEN_NOTES
+#define SDL_DISABLE_DLOPEN_NOTES
+#endif
+#elif defined(__GNUC__) && (__GNUC__ < 3 || (__GNUC__ == 3 && __GNUC_MINOR__ < 1))
+/* gcc < 3.1 too old */
+#ifndef SDL_DISABLE_DLOPEN_NOTES
+#define SDL_DISABLE_DLOPEN_NOTES
+#endif
+#endif /* SDL_PLATFORM_UNIX || SDL_PLATFORM_ANDROID */
+
+#if defined(__ELF__) && !defined(SDL_DISABLE_DLOPEN_NOTES)
+
+#include <SDL3/SDL_stdinc.h>
+
+#define SDL_ELF_NOTE_DLOPEN_VENDOR "FDO"
+#define SDL_ELF_NOTE_DLOPEN_TYPE 0x407c0c0aU
+
+#define SDL_ELF_NOTE_INTERNAL2(json, variable_name) \
+ __attribute__((aligned(4), used, section(".note.dlopen"))) \
+ static const struct { \
+ struct { \
+ Uint32 n_namesz; \
+ Uint32 n_descsz; \
+ Uint32 n_type; \
+ } nhdr; \
+ char name[4]; \
+ __attribute__((aligned(4))) char dlopen_json[sizeof(json)]; \
+ } variable_name = { \
+ { \
+ sizeof(SDL_ELF_NOTE_DLOPEN_VENDOR), \
+ sizeof(json), \
+ SDL_ELF_NOTE_DLOPEN_TYPE \
+ }, \
+ SDL_ELF_NOTE_DLOPEN_VENDOR, \
+ json \
+ }
+
+#define SDL_ELF_NOTE_INTERNAL(json, variable_name) \
+ SDL_ELF_NOTE_INTERNAL2(json, variable_name)
+
+#define SDL_DLNOTE_JSON_ARRAY1(N1) "[\"" N1 "\"]"
+#define SDL_DLNOTE_JSON_ARRAY2(N1,N2) "[\"" N1 "\",\"" N2 "\"]"
+#define SDL_DLNOTE_JSON_ARRAY3(N1,N2,N3) "[\"" N1 "\",\"" N2 "\",\"" N3 "\"]"
+#define SDL_DLNOTE_JSON_ARRAY4(N1,N2,N3,N4) "[\"" N1 "\",\"" N2 "\",\"" N3 "\",\"" N4 "\"]"
+#define SDL_DLNOTE_JSON_ARRAY5(N1,N2,N3,N4,N5) "[\"" N1 "\",\"" N2 "\",\"" N3 "\",\"" N4 "\",\"" N5 "\"]"
+#define SDL_DLNOTE_JSON_ARRAY6(N1,N2,N3,N4,N5,N6) "[\"" N1 "\",\"" N2 "\",\"" N3 "\",\"" N4 "\",\"" N5 "\",\"" N6 "\"]"
+#define SDL_DLNOTE_JSON_ARRAY7(N1,N2,N3,N4,N5,N6,N7) "[\"" N1 "\",\"" N2 "\",\"" N3 "\",\"" N4 "\",\"" N5 "\",\"" N6 "\",\"" N7 "\"]"
+#define SDL_DLNOTE_JSON_ARRAY8(N1,N2,N3,N4,N5,N6,N7,N8) "[\"" N1 "\",\"" N2 "\",\"" N3 "\",\"" N4 "\",\"" N5 "\",\"" N6 "\",\"" N7 "\",\"" N8 "\"]"
+#define SDL_DLNOTE_JSON_ARRAY_GET(N1,N2,N3,N4,N5,N6,N7,N8,NAME,...) NAME
+#define SDL_DLNOTE_JSON_ARRAY(...) \
+ SDL_DLNOTE_JSON_ARRAY_GET( \
+ __VA_ARGS__, \
+ SDL_DLNOTE_JSON_ARRAY8, \
+ SDL_DLNOTE_JSON_ARRAY7, \
+ SDL_DLNOTE_JSON_ARRAY6, \
+ SDL_DLNOTE_JSON_ARRAY5, \
+ SDL_DLNOTE_JSON_ARRAY4, \
+ SDL_DLNOTE_JSON_ARRAY3, \
+ SDL_DLNOTE_JSON_ARRAY2, \
+ SDL_DLNOTE_JSON_ARRAY1 \
+ )(__VA_ARGS__)
+
+/* Create "unique" variable name using __LINE__,
+ * so creating multiple elf notes on the same line is not supported
+ */
+#define SDL_DLNOTE_JOIN2(A,B) A##B
+#define SDL_DLNOTE_JOIN(A,B) SDL_DLNOTE_JOIN2(A,B)
+#define SDL_DLNOTE_UNIQUE_NAME SDL_DLNOTE_JOIN(s_SDL_dlopen_note_, __LINE__)
+
+/**
+ * Add a note that your application has dynamic shared library dependencies.
+ *
+ * You can do this by adding the following to the global scope:
+ *
+ * ```c
+ * SDL_ELF_NOTE_DLOPEN(
+ * "png",
+ * "Support for loading PNG images using libpng (required for APNG)",
+ * SDL_ELF_NOTE_DLOPEN_PRIORITY_RECOMMENDED,
+ * "libpng12.so.0"
+ * )
+ * ```
+ *
+ * A trailing semicolon is not needed.
+ *
+ * Or if you support multiple versions of a library, you can list them:
+ *
+ * ```c
+ * // Our app supports SDL1, SDL2, and SDL3 by dynamically loading them
+ * SDL_ELF_NOTE_DLOPEN(
+ * "SDL",
+ * "Create windows through SDL video backend",
+ * SDL_ELF_NOTE_DLOPEN_PRIORITY_REQUIRED
+ * "libSDL-1.2.so.0", "libSDL2-2.0.so.0", "libSDL3.so.0"
+ * )
+ * ```
+ *
+ * This macro is not available for compilers that do not support variadic
+ * macro's.
+ *
+ * \since This macro is available since SDL 3.4.0.
+ *
+ * \sa SDL_ELF_NOTE_DLOPEN_PRIORITY_SUGGESTED
+ * \sa SDL_ELF_NOTE_DLOPEN_PRIORITY_RECOMMENDED
+ * \sa SDL_ELF_NOTE_DLOPEN_PRIORITY_REQUIRED
+ */
+#define SDL_ELF_NOTE_DLOPEN(feature, description, priority, ...) \
+ SDL_ELF_NOTE_INTERNAL( \
+ "[{\"feature\":\"" feature \
+ "\",\"description\":\"" description \
+ "\",\"priority\":\"" priority \
+ "\",\"soname\":" SDL_DLNOTE_JSON_ARRAY(__VA_ARGS__) "}]", \
+ SDL_DLNOTE_UNIQUE_NAME);
+
+#elif defined(__GNUC__) && __GNUC__ < 3
+
+#define SDL_ELF_NOTE_DLOPEN(args...)
+
+#elif defined(_MSC_VER) && _MSC_VER < 1400
+
+/* Variadic macros are not supported */
+
+#else
+
+#define SDL_ELF_NOTE_DLOPEN(...)
+
+#endif
+
+#endif /* SDL_dlopennote_h */
diff --git a/thirdparty/sdl/include/SDL3/SDL_endian.h b/thirdparty/sdl/include/SDL3/SDL_endian.h
index f3ab18ffdc0..69f097edd88 100644
--- a/thirdparty/sdl/include/SDL3/SDL_endian.h
+++ b/thirdparty/sdl/include/SDL3/SDL_endian.h
@@ -1,6 +1,6 @@
/*
Simple DirectMedia Layer
- Copyright (C) 1997-2025 Sam Lantinga <[email protected]>
+ Copyright (C) 1997-2026 Sam Lantinga <[email protected]>
This software is provided 'as-is', without any express or implied
warranty. In no event will the authors be held liable for any damages
@@ -46,7 +46,7 @@
#if defined(_MSC_VER) && (_MSC_VER >= 1400)
/* As of Clang 11, '_m_prefetchw' is conflicting with the winnt.h's version,
so we define the needed '_m_prefetch' here as a pseudo-header, until the issue is fixed. */
-#if defined(__clang__) && !SDL_HAS_BUILTIN(_m_prefetch)
+#if defined(__clang__) && !SDL_HAS_BUILTIN(_m_prefetch)
#ifndef __PRFCHWINTRIN_H
#define __PRFCHWINTRIN_H
static __inline__ void __attribute__((__always_inline__, __nodebug__))
@@ -208,7 +208,7 @@ _m_prefetch(void *__P)
#else
/* By default, assume that floats words follow the memory system mode. */
#define SDL_FLOATWORDORDER SDL_BYTEORDER
-#endif /* __FLOAT_WORD_ORDER__ */
+#endif /* SDL_WIKI_DOCUMENTATION_SECTION */
#endif /* !SDL_FLOATWORDORDER */
@@ -252,7 +252,7 @@ SDL_FORCE_INLINE Uint16 SDL_Swap16(Uint16 x)
#elif defined(__x86_64__)
SDL_FORCE_INLINE Uint16 SDL_Swap16(Uint16 x)
{
- __asm__("xchgb %b0,%h0": "=Q"(x):"0"(x));
+ __asm__("xchgb %b0,%h0": "=abcd"(x):"0"(x));
return x;
}
#elif (defined(__powerpc__) || defined(__ppc__))
diff --git a/thirdparty/sdl/include/SDL3/SDL_error.h b/thirdparty/sdl/include/SDL3/SDL_error.h
index 934967c1cf0..3453818cb30 100644
--- a/thirdparty/sdl/include/SDL3/SDL_error.h
+++ b/thirdparty/sdl/include/SDL3/SDL_error.h
@@ -1,6 +1,6 @@
/*
Simple DirectMedia Layer
- Copyright (C) 1997-2025 Sam Lantinga <[email protected]>
+ Copyright (C) 1997-2026 Sam Lantinga <[email protected]>
This software is provided 'as-is', without any express or implied
warranty. In no event will the authors be held liable for any damages
diff --git a/thirdparty/sdl/include/SDL3/SDL_events.h b/thirdparty/sdl/include/SDL3/SDL_events.h
index 7dc409a0cc2..4fb6268135f 100644
--- a/thirdparty/sdl/include/SDL3/SDL_events.h
+++ b/thirdparty/sdl/include/SDL3/SDL_events.h
@@ -1,6 +1,6 @@
/*
Simple DirectMedia Layer
- Copyright (C) 1997-2025 Sam Lantinga <[email protected]>
+ Copyright (C) 1997-2026 Sam Lantinga <[email protected]>
This software is provided 'as-is', without any express or implied
warranty. In no event will the authors be held liable for any damages
@@ -30,7 +30,7 @@
* coming and going, the system changing in some way, etc.
*
* An app generally takes a moment, perhaps at the start of a new frame, to
- * examine any events that have occured since the last time and process or
+ * examine any events that have occurred since the last time and process or
* ignore them. This is generally done by calling SDL_PollEvent() in a loop
* until it returns false (or, if using the main callbacks, events are
* provided one at a time in calls to SDL_AppEvent() before the next call to
@@ -127,15 +127,17 @@ typedef enum SDL_EventType
SDL_EVENT_DISPLAY_DESKTOP_MODE_CHANGED, /**< Display has changed desktop mode */
SDL_EVENT_DISPLAY_CURRENT_MODE_CHANGED, /**< Display has changed current mode */
SDL_EVENT_DISPLAY_CONTENT_SCALE_CHANGED, /**< Display has changed content scale */
+ SDL_EVENT_DISPLAY_USABLE_BOUNDS_CHANGED, /**< Display has changed usable bounds */
SDL_EVENT_DISPLAY_FIRST = SDL_EVENT_DISPLAY_ORIENTATION,
- SDL_EVENT_DISPLAY_LAST = SDL_EVENT_DISPLAY_CONTENT_SCALE_CHANGED,
+ SDL_EVENT_DISPLAY_LAST = SDL_EVENT_DISPLAY_USABLE_BOUNDS_CHANGED,
/* Window events */
/* 0x200 was SDL_WINDOWEVENT, reserve the number for sdl2-compat */
/* 0x201 was SDL_SYSWMEVENT, reserve the number for sdl2-compat */
SDL_EVENT_WINDOW_SHOWN = 0x202, /**< Window has been shown */
SDL_EVENT_WINDOW_HIDDEN, /**< Window has been hidden */
- SDL_EVENT_WINDOW_EXPOSED, /**< Window has been exposed and should be redrawn, and can be redrawn directly from event watchers for this event */
+ SDL_EVENT_WINDOW_EXPOSED, /**< Window has been exposed and should be redrawn, and can be redrawn directly from event watchers for this event.
+ data1 is 1 for live-resize expose events, 0 otherwise. */
SDL_EVENT_WINDOW_MOVED, /**< Window has been moved to data1, data2 */
SDL_EVENT_WINDOW_RESIZED, /**< Window has been resized to data1xdata2 */
SDL_EVENT_WINDOW_PIXEL_SIZE_CHANGED,/**< The pixel size of the window has changed to data1xdata2 */
@@ -174,6 +176,8 @@ typedef enum SDL_EventType
SDL_EVENT_KEYBOARD_ADDED, /**< A new keyboard has been inserted into the system */
SDL_EVENT_KEYBOARD_REMOVED, /**< A keyboard has been removed */
SDL_EVENT_TEXT_EDITING_CANDIDATES, /**< Keyboard text editing candidates */
+ SDL_EVENT_SCREEN_KEYBOARD_SHOWN, /**< The on-screen keyboard has been shown */
+ SDL_EVENT_SCREEN_KEYBOARD_HIDDEN, /**< The on-screen keyboard has been hidden */
/* Mouse events */
SDL_EVENT_MOUSE_MOTION = 0x400, /**< Mouse moved */
@@ -214,10 +218,15 @@ typedef enum SDL_EventType
SDL_EVENT_FINGER_MOTION,
SDL_EVENT_FINGER_CANCELED,
+ /* Pinch events */
+ SDL_EVENT_PINCH_BEGIN = 0x710, /**< Pinch gesture started */
+ SDL_EVENT_PINCH_UPDATE, /**< Pinch gesture updated */
+ SDL_EVENT_PINCH_END, /**< Pinch gesture ended */
+
/* 0x800, 0x801, and 0x802 were the Gesture events from SDL2. Do not reuse these values! sdl2-compat needs them! */
/* Clipboard events */
- SDL_EVENT_CLIPBOARD_UPDATE = 0x900, /**< The clipboard or primary selection changed */
+ SDL_EVENT_CLIPBOARD_UPDATE = 0x900, /**< The clipboard changed */
/* Drag and drop events */
SDL_EVENT_DROP_FILE = 0x1000, /**< The system requests a file open */
@@ -298,7 +307,7 @@ typedef struct SDL_CommonEvent
*/
typedef struct SDL_DisplayEvent
{
- SDL_EventType type; /**< SDL_DISPLAYEVENT_* */
+ SDL_EventType type; /**< SDL_EVENT_DISPLAY_* */
Uint32 reserved;
Uint64 timestamp; /**< In nanoseconds, populated using SDL_GetTicksNS() */
SDL_DisplayID displayID;/**< The associated display */
@@ -447,7 +456,7 @@ typedef struct SDL_MouseMotionEvent
Uint32 reserved;
Uint64 timestamp; /**< In nanoseconds, populated using SDL_GetTicksNS() */
SDL_WindowID windowID; /**< The window with mouse focus, if any */
- SDL_MouseID which; /**< The mouse instance id in relative mode, SDL_TOUCH_MOUSEID for touch events, or 0 */
+ SDL_MouseID which; /**< The mouse instance id in relative mode, SDL_TOUCH_MOUSEID for touch events, SDL_PEN_MOUSEID for pen events, or 0 */
SDL_MouseButtonFlags state; /**< The current button state */
float x; /**< X coordinate, relative to window */
float y; /**< Y coordinate, relative to window */
@@ -704,6 +713,10 @@ typedef struct SDL_GamepadSensorEvent
/**
* Audio device event structure (event.adevice.*)
*
+ * Note that SDL will send a SDL_EVENT_AUDIO_DEVICE_ADDED event for every
+ * device it discovers during initialization. After that, this event will only
+ * arrive when a device is hotplugged during the program's run.
+ *
* \since This struct is available since SDL 3.2.0.
*/
typedef struct SDL_AudioDeviceEvent
@@ -781,7 +794,19 @@ typedef struct SDL_TouchFingerEvent
} SDL_TouchFingerEvent;
/**
- * Pressure-sensitive pen proximity event structure (event.pmotion.*)
+ * Pinch event structure (event.pinch.*)
+ */
+typedef struct SDL_PinchFingerEvent
+{
+ SDL_EventType type; /**< ::SDL_EVENT_PINCH_BEGIN or ::SDL_EVENT_PINCH_UPDATE or ::SDL_EVENT_PINCH_END */
+ Uint32 reserved;
+ Uint64 timestamp; /**< In nanoseconds, populated using SDL_GetTicksNS() */
+ float scale; /**< The scale change since the last SDL_EVENT_PINCH_UPDATE. Scale < 1 is "zoom out". Scale > 1 is "zoom in". */
+ SDL_WindowID windowID; /**< The window underneath the finger, if any */
+} SDL_PinchFingerEvent;
+
+/**
+ * Pressure-sensitive pen proximity event structure (event.pproximity.*)
*
* When a pen becomes visible to the system (it is close enough to a tablet,
* etc), SDL will send an SDL_EVENT_PEN_PROXIMITY_IN event with the new pen's
@@ -793,6 +818,9 @@ typedef struct SDL_TouchFingerEvent
* is there." The pen touching and lifting off from the tablet while not
* leaving the area are handled by SDL_EVENT_PEN_DOWN and SDL_EVENT_PEN_UP.
*
+ * Not all platforms have a window associated with the pen during proximity
+ * events. Some wait until motion/button/etc events to offer this info.
+ *
* \since This struct is available since SDL 3.2.0.
*/
typedef struct SDL_PenProximityEvent
@@ -802,6 +830,7 @@ typedef struct SDL_PenProximityEvent
Uint64 timestamp; /**< In nanoseconds, populated using SDL_GetTicksNS() */
SDL_WindowID windowID; /**< The window with pen focus, if any */
SDL_PenID which; /**< The pen instance id */
+ SDL_PenInputFlags pen_state; /**< Complete pen input state at time of event (added in 3.4.16). */
} SDL_PenProximityEvent;
/**
@@ -967,7 +996,7 @@ typedef struct SDL_QuitEvent
*/
typedef struct SDL_UserEvent
{
- Uint32 type; /**< SDL_EVENT_USER through SDL_EVENT_LAST-1, Uint32 because these are not in the SDL_EventType enumeration */
+ Uint32 type; /**< SDL_EVENT_USER through SDL_EVENT_LAST, Uint32 because these are not in the SDL_EventType enumeration */
Uint32 reserved;
Uint64 timestamp; /**< In nanoseconds, populated using SDL_GetTicksNS() */
SDL_WindowID windowID; /**< The associated window if any */
@@ -1017,6 +1046,7 @@ typedef union SDL_Event
SDL_QuitEvent quit; /**< Quit request event data */
SDL_UserEvent user; /**< Custom event data */
SDL_TouchFingerEvent tfinger; /**< Touch finger event data */
+ SDL_PinchFingerEvent pinch; /**< Pinch event data */
SDL_PenProximityEvent pproximity; /**< Pen proximity event data */
SDL_PenTouchEvent ptouch; /**< Pen tip touching event data */
SDL_PenMotionEvent pmotion; /**< Pen motion event data */
@@ -1227,15 +1257,13 @@ extern SDL_DECLSPEC void SDLCALL SDL_FlushEvents(Uint32 minType, Uint32 maxType)
* Poll for currently pending events.
*
* If `event` is not NULL, the next event is removed from the queue and stored
- * in the SDL_Event structure pointed to by `event`. The 1 returned refers to
- * this event, immediately stored in the SDL Event structure -- not an event
- * to follow.
+ * in the SDL_Event structure pointed to by `event`.
*
- * If `event` is NULL, it simply returns 1 if there is an event in the queue,
- * but will not remove it from the queue.
+ * If `event` is NULL, it simply returns true if there is an event in the
+ * queue, but will not remove it from the queue.
*
* As this function may implicitly call SDL_PumpEvents(), you can only call
- * this function in the thread that set the video mode.
+ * this function in the thread that initialized the video subsystem.
*
* SDL_PollEvent() is the favored way of receiving system events since it can
* be done from the main loop and does not suspend the main loop while waiting
@@ -1255,6 +1283,13 @@ extern SDL_DECLSPEC void SDLCALL SDL_FlushEvents(Uint32 minType, Uint32 maxType)
* }
* ```
*
+ * Note that Windows (and possibly other platforms) has a quirk about how it
+ * handles events while dragging/resizing a window, which can cause this
+ * function to block for significant amounts of time. Technical explanations
+ * and solutions are discussed on the wiki:
+ *
+ * https://wiki.libsdl.org/SDL3/AppFreezeDuringDrag
+ *
* \param event the SDL_Event structure to be filled with the next event from
* the queue, or NULL.
* \returns true if this got an event or false if there are none available.
@@ -1391,7 +1426,10 @@ typedef bool (SDLCALL *SDL_EventFilter)(void *userdata, SDL_Event *event);
* allows selective filtering of dynamically arriving events.
*
* **WARNING**: Be very careful of what you do in the event filter function,
- * as it may run in a different thread!
+ * as it may run in a different thread! The exception is handling of
+ * SDL_EVENT_WINDOW_EXPOSED, which is guaranteed to be sent from the OS on the
+ * main thread and you are expected to redraw your window in response to this
+ * event.
*
* On platforms that support it, if the quit event is generated by an
* interrupt signal (e.g. pressing Ctrl-C), it will be delivered to the
@@ -1404,7 +1442,7 @@ typedef bool (SDLCALL *SDL_EventFilter)(void *userdata, SDL_Event *event);
* the event filter, but events pushed onto the queue with SDL_PeepEvents() do
* not.
*
- * \param filter an SDL_EventFilter function to call when an event happens.
+ * \param filter a function to call when an event happens.
* \param userdata a pointer that is passed to `filter`.
*
* \threadsafety It is safe to call this function from any thread.
@@ -1567,6 +1605,38 @@ extern SDL_DECLSPEC Uint32 SDLCALL SDL_RegisterEvents(int numevents);
*/
extern SDL_DECLSPEC SDL_Window * SDLCALL SDL_GetWindowFromEvent(const SDL_Event *event);
+/**
+ * Generate an English description of an event.
+ *
+ * This will fill `buf` with a null-terminated string that might look
+ * something like this:
+ *
+ * ```
+ * SDL_EVENT_MOUSE_MOTION (timestamp=1140256324 windowid=2 which=0 state=0 x=492.99 y=139.09 xrel=52 yrel=6)
+ * ```
+ *
+ * The exact format of the string is not guaranteed; it is intended for
+ * logging purposes, to be read by a human, and not parsed by a computer.
+ *
+ * The returned value follows the same rules as SDL_snprintf(): `buf` will
+ * always be NULL-terminated (unless `buflen` is zero), and will be truncated
+ * if `buflen` is too small. The return code is the number of bytes needed for
+ * the complete string, not counting the NULL-terminator, whether the string
+ * was truncated or not. Unlike SDL_snprintf(), though, this function never
+ * returns -1.
+ *
+ * \param event an event to describe. May be NULL.
+ * \param buf the buffer to fill with the description string. May be NULL.
+ * \param buflen the maximum bytes that can be written to `buf`.
+ * \returns number of bytes needed for the full string, not counting the
+ * null-terminator byte.
+ *
+ * \threadsafety It is safe to call this function from any thread.
+ *
+ * \since This function is available since SDL 3.4.0.
+ */
+extern SDL_DECLSPEC int SDLCALL SDL_GetEventDescription(const SDL_Event *event, char *buf, int buflen);
+
/* Ends C function definitions when using C++ */
#ifdef __cplusplus
}
diff --git a/thirdparty/sdl/include/SDL3/SDL_filesystem.h b/thirdparty/sdl/include/SDL3/SDL_filesystem.h
index af3ca27e021..3a077a09672 100644
--- a/thirdparty/sdl/include/SDL3/SDL_filesystem.h
+++ b/thirdparty/sdl/include/SDL3/SDL_filesystem.h
@@ -1,6 +1,6 @@
/*
Simple DirectMedia Layer
- Copyright (C) 1997-2025 Sam Lantinga <[email protected]>
+ Copyright (C) 1997-2026 Sam Lantinga <[email protected]>
This software is provided 'as-is', without any express or implied
warranty. In no event will the authors be held liable for any damages
@@ -77,6 +77,9 @@ extern "C" {
* - `parent`: the containing directory of the bundle. For example:
* `/Applications/SDLApp/`
*
+ * **Android Specific Functionality**: This function returns "./", which
+ * allows filesystem operations to use internal storage and the asset system.
+ *
* **Nintendo 3DS Specific Functionality**: This function returns "romfs"
* directory of the application as it is uncommon to store resources outside
* the executable. As such it is not a writable directory.
@@ -89,6 +92,8 @@ extern "C" {
* doesn't implement this functionality, call SDL_GetError() for more
* information.
*
+ * \threadsafety It is safe to call this function from any thread.
+ *
* \since This function is available since SDL 3.2.0.
*
* \sa SDL_GetPrefPath
@@ -134,6 +139,12 @@ extern SDL_DECLSPEC const char * SDLCALL SDL_GetBasePath(void);
* - ...only use letters, numbers, and spaces. Avoid punctuation like "Game
* Name 2: Bad Guy's Revenge!" ... "Game Name 2" is sufficient.
*
+ * Due to historical mistakes, `org` is allowed to be NULL or "". In such
+ * cases, SDL will omit the org subdirectory, including on platforms where it
+ * shouldn't, and including on platforms where this would make your app fail
+ * certification for an app store. New apps should definitely specify a real
+ * string for `org`.
+ *
* The returned path is guaranteed to end with a path separator ('\\' on
* Windows, '/' on most other platforms).
*
@@ -144,6 +155,8 @@ extern SDL_DECLSPEC const char * SDLCALL SDL_GetBasePath(void);
* etc.). This should be freed with SDL_free() when it is no longer
* needed.
*
+ * \threadsafety It is safe to call this function from any thread.
+ *
* \since This function is available since SDL 3.2.0.
*
* \sa SDL_GetBasePath
@@ -216,6 +229,8 @@ typedef enum SDL_Folder
* \returns either a null-terminated C string containing the full path to the
* folder, or NULL if an error happened.
*
+ * \threadsafety It is safe to call this function from any thread.
+ *
* \since This function is available since SDL 3.2.0.
*/
extern SDL_DECLSPEC const char * SDLCALL SDL_GetUserFolder(SDL_Folder folder);
@@ -226,9 +241,8 @@ extern SDL_DECLSPEC const char * SDLCALL SDL_GetUserFolder(SDL_Folder folder);
/**
* Types of filesystem entries.
*
- * Note that there may be other sorts of items on a filesystem: devices,
- * symlinks, named pipes, etc. They are currently reported as
- * SDL_PATHTYPE_OTHER.
+ * Note that there may be other sorts of items on a filesystem: devices, named
+ * pipes, etc. They are currently reported as SDL_PATHTYPE_OTHER.
*
* \since This enum is available since SDL 3.2.0.
*
@@ -283,6 +297,8 @@ typedef Uint32 SDL_GlobFlags;
* \returns true on success or false on failure; call SDL_GetError() for more
* information.
*
+ * \threadsafety It is safe to call this function from any thread.
+ *
* \since This function is available since SDL 3.2.0.
*/
extern SDL_DECLSPEC bool SDLCALL SDL_CreateDirectory(const char *path);
@@ -346,6 +362,8 @@ typedef SDL_EnumerationResult (SDLCALL *SDL_EnumerateDirectoryCallback)(void *us
* \returns true on success or false on failure; call SDL_GetError() for more
* information.
*
+ * \threadsafety It is safe to call this function from any thread.
+ *
* \since This function is available since SDL 3.2.0.
*/
extern SDL_DECLSPEC bool SDLCALL SDL_EnumerateDirectory(const char *path, SDL_EnumerateDirectoryCallback callback, void *userdata);
@@ -360,6 +378,8 @@ extern SDL_DECLSPEC bool SDLCALL SDL_EnumerateDirectory(const char *path, SDL_En
* \returns true on success or false on failure; call SDL_GetError() for more
* information.
*
+ * \threadsafety It is safe to call this function from any thread.
+ *
* \since This function is available since SDL 3.2.0.
*/
extern SDL_DECLSPEC bool SDLCALL SDL_RemovePath(const char *path);
@@ -367,7 +387,7 @@ extern SDL_DECLSPEC bool SDLCALL SDL_RemovePath(const char *path);
/**
* Rename a file or directory.
*
- * If the file at `newpath` already exists, it will replaced.
+ * If the file at `newpath` already exists, it will be replaced.
*
* Note that this will not copy files across filesystems/drives/volumes, as
* that is a much more complicated (and possibly time-consuming) operation.
@@ -383,6 +403,8 @@ extern SDL_DECLSPEC bool SDLCALL SDL_RemovePath(const char *path);
* \returns true on success or false on failure; call SDL_GetError() for more
* information.
*
+ * \threadsafety It is safe to call this function from any thread.
+ *
* \since This function is available since SDL 3.2.0.
*/
extern SDL_DECLSPEC bool SDLCALL SDL_RenamePath(const char *oldpath, const char *newpath);
@@ -423,6 +445,10 @@ extern SDL_DECLSPEC bool SDLCALL SDL_RenamePath(const char *oldpath, const char
* \returns true on success or false on failure; call SDL_GetError() for more
* information.
*
+ * \threadsafety It is safe to call this function from any thread, but this
+ * operation is not atomic, so the app might need to protect
+ * access to specific paths from other threads if appropriate.
+ *
* \since This function is available since SDL 3.2.0.
*/
extern SDL_DECLSPEC bool SDLCALL SDL_CopyFile(const char *oldpath, const char *newpath);
@@ -430,12 +456,18 @@ extern SDL_DECLSPEC bool SDLCALL SDL_CopyFile(const char *oldpath, const char *n
/**
* Get information about a filesystem path.
*
+ * Symlinks, on filesystems that support them, are always followed, so you
+ * will always get information on what the symlink eventually points to, and
+ * not the symlink itself.
+ *
* \param path the path to query.
* \param info a pointer filled in with information about the path, or NULL to
* check for the existence of a file.
* \returns true on success or false if the file doesn't exist, or another
* failure; call SDL_GetError() for more information.
*
+ * \threadsafety It is safe to call this function from any thread.
+ *
* \since This function is available since SDL 3.2.0.
*/
extern SDL_DECLSPEC bool SDLCALL SDL_GetPathInfo(const char *path, SDL_PathInfo *info);
@@ -444,10 +476,10 @@ extern SDL_DECLSPEC bool SDLCALL SDL_GetPathInfo(const char *path, SDL_PathInfo
* Enumerate a directory tree, filtered by pattern, and return a list.
*
* Files are filtered out if they don't match the string in `pattern`, which
- * may contain wildcard characters '\*' (match everything) and '?' (match one
+ * may contain wildcard characters `*` (match everything) and `?` (match one
* character). If pattern is NULL, no filtering is done and all results are
* returned. Subdirectories are permitted, and are specified with a path
- * separator of '/'. Wildcard characters '\*' and '?' never match a path
+ * separator of `/`. Wildcard characters `*` and `?` never match a path
* separator.
*
* `flags` may be set to SDL_GLOB_CASEINSENSITIVE to make the pattern matching
@@ -490,6 +522,8 @@ extern SDL_DECLSPEC char ** SDLCALL SDL_GlobDirectory(const char *path, const ch
* platform-dependent notation. NULL if there's a problem. This
* should be freed with SDL_free() when it is no longer needed.
*
+ * \threadsafety It is safe to call this function from any thread.
+ *
* \since This function is available since SDL 3.2.0.
*/
extern SDL_DECLSPEC char * SDLCALL SDL_GetCurrentDirectory(void);
diff --git a/thirdparty/sdl/include/SDL3/SDL_gamepad.h b/thirdparty/sdl/include/SDL3/SDL_gamepad.h
index 99f8b6593fa..9c88a770ae0 100644
--- a/thirdparty/sdl/include/SDL3/SDL_gamepad.h
+++ b/thirdparty/sdl/include/SDL3/SDL_gamepad.h
@@ -1,6 +1,6 @@
/*
Simple DirectMedia Layer
- Copyright (C) 1997-2025 Sam Lantinga <[email protected]>
+ Copyright (C) 1997-2026 Sam Lantinga <[email protected]>
This software is provided 'as-is', without any express or implied
warranty. In no event will the authors be held liable for any damages
@@ -48,6 +48,9 @@
* SDL_INIT_GAMEPAD flag. This causes SDL to scan the system for gamepads, and
* load appropriate drivers.
*
+ * If you're using SDL gamepad support in a Steam game, you must call
+ * SteamAPI_InitEx() before calling SDL_Init().
+ *
* If you would like to receive gamepad updates while the application is in
* the background, you should set the following hint before calling
* SDL_Init(): SDL_HINT_JOYSTICK_ALLOW_BACKGROUND_EVENTS
@@ -118,6 +121,7 @@ typedef enum SDL_GamepadType
SDL_GAMEPAD_TYPE_NINTENDO_SWITCH_JOYCON_LEFT,
SDL_GAMEPAD_TYPE_NINTENDO_SWITCH_JOYCON_RIGHT,
SDL_GAMEPAD_TYPE_NINTENDO_SWITCH_JOYCON_PAIR,
+ SDL_GAMEPAD_TYPE_GAMECUBE,
SDL_GAMEPAD_TYPE_COUNT
} SDL_GamepadType;
@@ -127,8 +131,9 @@ typedef enum SDL_GamepadType
* For controllers that use a diamond pattern for the face buttons, the
* south/east/west/north buttons below correspond to the locations in the
* diamond pattern. For Xbox controllers, this would be A/B/X/Y, for Nintendo
- * Switch controllers, this would be B/A/Y/X, for PlayStation controllers this
- * would be Cross/Circle/Square/Triangle.
+ * Switch controllers, this would be B/A/Y/X, for GameCube controllers this
+ * would be A/X/B/Y, for PlayStation controllers this would be
+ * Cross/Circle/Square/Triangle.
*
* For controllers that don't use a diamond pattern for the face buttons, the
* south/east/west/north buttons indicate the buttons labeled A, B, C, D, or
@@ -162,15 +167,15 @@ typedef enum SDL_GamepadButton
SDL_GAMEPAD_BUTTON_DPAD_DOWN,
SDL_GAMEPAD_BUTTON_DPAD_LEFT,
SDL_GAMEPAD_BUTTON_DPAD_RIGHT,
- SDL_GAMEPAD_BUTTON_MISC1, /**< Additional button (e.g. Xbox Series X share button, PS5 microphone button, Nintendo Switch Pro capture button, Amazon Luna microphone button, Google Stadia capture button) */
- SDL_GAMEPAD_BUTTON_RIGHT_PADDLE1, /**< Upper or primary paddle, under your right hand (e.g. Xbox Elite paddle P1) */
- SDL_GAMEPAD_BUTTON_LEFT_PADDLE1, /**< Upper or primary paddle, under your left hand (e.g. Xbox Elite paddle P3) */
- SDL_GAMEPAD_BUTTON_RIGHT_PADDLE2, /**< Lower or secondary paddle, under your right hand (e.g. Xbox Elite paddle P2) */
- SDL_GAMEPAD_BUTTON_LEFT_PADDLE2, /**< Lower or secondary paddle, under your left hand (e.g. Xbox Elite paddle P4) */
+ SDL_GAMEPAD_BUTTON_MISC1, /**< Additional button (e.g. Xbox Series X share button, PS5 microphone button, Nintendo Switch Pro capture button, Steam Controller QAM button, Amazon Luna microphone button, Google Stadia capture button) */
+ SDL_GAMEPAD_BUTTON_RIGHT_PADDLE1, /**< Upper or primary paddle, under your right hand (e.g. Xbox Elite paddle P1, DualSense Edge RB button, Right Joy-Con SR button, Steam Controller R4 button) */
+ SDL_GAMEPAD_BUTTON_LEFT_PADDLE1, /**< Upper or primary paddle, under your left hand (e.g. Xbox Elite paddle P3, DualSense Edge LB button, Left Joy-Con SL button, Steam Controller L4 button) */
+ SDL_GAMEPAD_BUTTON_RIGHT_PADDLE2, /**< Lower or secondary paddle, under your right hand (e.g. Xbox Elite paddle P2, DualSense Edge right Fn button, Right Joy-Con SL button, Steam Controller R5 button) */
+ SDL_GAMEPAD_BUTTON_LEFT_PADDLE2, /**< Lower or secondary paddle, under your left hand (e.g. Xbox Elite paddle P4, DualSense Edge left Fn button, Left Joy-Con SR button, Steam Controller L5 button) */
SDL_GAMEPAD_BUTTON_TOUCHPAD, /**< PS4/PS5 touchpad button */
SDL_GAMEPAD_BUTTON_MISC2, /**< Additional button */
- SDL_GAMEPAD_BUTTON_MISC3, /**< Additional button */
- SDL_GAMEPAD_BUTTON_MISC4, /**< Additional button */
+ SDL_GAMEPAD_BUTTON_MISC3, /**< Additional button (e.g. Nintendo GameCube left trigger click) */
+ SDL_GAMEPAD_BUTTON_MISC4, /**< Additional button (e.g. Nintendo GameCube right trigger click) */
SDL_GAMEPAD_BUTTON_MISC5, /**< Additional button */
SDL_GAMEPAD_BUTTON_MISC6, /**< Additional button */
SDL_GAMEPAD_BUTTON_COUNT
@@ -422,6 +427,8 @@ extern SDL_DECLSPEC int SDLCALL SDL_AddGamepadMappingsFromFile(const char *file)
* \returns true on success or false on failure; call SDL_GetError() for more
* information.
*
+ * \threadsafety It is safe to call this function from any thread.
+ *
* \since This function is available since SDL 3.2.0.
*/
extern SDL_DECLSPEC bool SDLCALL SDL_ReloadGamepadMappings(void);
@@ -436,6 +443,8 @@ extern SDL_DECLSPEC bool SDLCALL SDL_ReloadGamepadMappings(void);
* single allocation that should be freed with SDL_free() when it is
* no longer needed.
*
+ * \threadsafety It is safe to call this function from any thread.
+ *
* \since This function is available since SDL 3.2.0.
*/
extern SDL_DECLSPEC char ** SDLCALL SDL_GetGamepadMappings(int *count);
@@ -448,6 +457,8 @@ extern SDL_DECLSPEC char ** SDLCALL SDL_GetGamepadMappings(int *count);
* information. This should be freed with SDL_free() when it is no
* longer needed.
*
+ * \threadsafety It is safe to call this function from any thread.
+ *
* \since This function is available since SDL 3.2.0.
*
* \sa SDL_GetJoystickGUIDForID
@@ -465,6 +476,8 @@ extern SDL_DECLSPEC char * SDLCALL SDL_GetGamepadMappingForGUID(SDL_GUID guid);
* available; call SDL_GetError() for more information. This should
* be freed with SDL_free() when it is no longer needed.
*
+ * \threadsafety It is safe to call this function from any thread.
+ *
* \since This function is available since SDL 3.2.0.
*
* \sa SDL_AddGamepadMapping
@@ -485,6 +498,8 @@ extern SDL_DECLSPEC char * SDLCALL SDL_GetGamepadMapping(SDL_Gamepad *gamepad);
* \returns true on success or false on failure; call SDL_GetError() for more
* information.
*
+ * \threadsafety It is safe to call this function from any thread.
+ *
* \since This function is available since SDL 3.2.0.
*
* \sa SDL_AddGamepadMapping
@@ -497,6 +512,8 @@ extern SDL_DECLSPEC bool SDLCALL SDL_SetGamepadMapping(SDL_JoystickID instance_i
*
* \returns true if a gamepad is connected, false otherwise.
*
+ * \threadsafety It is safe to call this function from any thread.
+ *
* \since This function is available since SDL 3.2.0.
*
* \sa SDL_GetGamepads
@@ -512,6 +529,8 @@ extern SDL_DECLSPEC bool SDLCALL SDL_HasGamepad(void);
* call SDL_GetError() for more information. This should be freed
* with SDL_free() when it is no longer needed.
*
+ * \threadsafety It is safe to call this function from any thread.
+ *
* \since This function is available since SDL 3.2.0.
*
* \sa SDL_HasGamepad
@@ -526,6 +545,8 @@ extern SDL_DECLSPEC SDL_JoystickID * SDLCALL SDL_GetGamepads(int *count);
* \returns true if the given joystick is supported by the gamepad interface,
* false if it isn't or it's an invalid index.
*
+ * \threadsafety It is safe to call this function from any thread.
+ *
* \since This function is available since SDL 3.2.0.
*
* \sa SDL_GetJoysticks
@@ -542,6 +563,8 @@ extern SDL_DECLSPEC bool SDLCALL SDL_IsGamepad(SDL_JoystickID instance_id);
* \returns the name of the selected gamepad. If no name can be found, this
* function returns NULL; call SDL_GetError() for more information.
*
+ * \threadsafety It is safe to call this function from any thread.
+ *
* \since This function is available since SDL 3.2.0.
*
* \sa SDL_GetGamepadName
@@ -558,6 +581,8 @@ extern SDL_DECLSPEC const char * SDLCALL SDL_GetGamepadNameForID(SDL_JoystickID
* \returns the path of the selected gamepad. If no path can be found, this
* function returns NULL; call SDL_GetError() for more information.
*
+ * \threadsafety It is safe to call this function from any thread.
+ *
* \since This function is available since SDL 3.2.0.
*
* \sa SDL_GetGamepadPath
@@ -573,6 +598,8 @@ extern SDL_DECLSPEC const char * SDLCALL SDL_GetGamepadPathForID(SDL_JoystickID
* \param instance_id the joystick instance ID.
* \returns the player index of a gamepad, or -1 if it's not available.
*
+ * \threadsafety It is safe to call this function from any thread.
+ *
* \since This function is available since SDL 3.2.0.
*
* \sa SDL_GetGamepadPlayerIndex
@@ -589,6 +616,8 @@ extern SDL_DECLSPEC int SDLCALL SDL_GetGamepadPlayerIndexForID(SDL_JoystickID in
* \returns the GUID of the selected gamepad. If called on an invalid index,
* this function returns a zero GUID.
*
+ * \threadsafety It is safe to call this function from any thread.
+ *
* \since This function is available since SDL 3.2.0.
*
* \sa SDL_GUIDToString
@@ -606,6 +635,8 @@ extern SDL_DECLSPEC SDL_GUID SDLCALL SDL_GetGamepadGUIDForID(SDL_JoystickID inst
* \returns the USB vendor ID of the selected gamepad. If called on an invalid
* index, this function returns zero.
*
+ * \threadsafety It is safe to call this function from any thread.
+ *
* \since This function is available since SDL 3.2.0.
*
* \sa SDL_GetGamepadVendor
@@ -623,6 +654,8 @@ extern SDL_DECLSPEC Uint16 SDLCALL SDL_GetGamepadVendorForID(SDL_JoystickID inst
* \returns the USB product ID of the selected gamepad. If called on an
* invalid index, this function returns zero.
*
+ * \threadsafety It is safe to call this function from any thread.
+ *
* \since This function is available since SDL 3.2.0.
*
* \sa SDL_GetGamepadProduct
@@ -640,6 +673,8 @@ extern SDL_DECLSPEC Uint16 SDLCALL SDL_GetGamepadProductForID(SDL_JoystickID ins
* \returns the product version of the selected gamepad. If called on an
* invalid index, this function returns zero.
*
+ * \threadsafety It is safe to call this function from any thread.
+ *
* \since This function is available since SDL 3.2.0.
*
* \sa SDL_GetGamepadProductVersion
@@ -655,6 +690,8 @@ extern SDL_DECLSPEC Uint16 SDLCALL SDL_GetGamepadProductVersionForID(SDL_Joystic
* \param instance_id the joystick instance ID.
* \returns the gamepad type.
*
+ * \threadsafety It is safe to call this function from any thread.
+ *
* \since This function is available since SDL 3.2.0.
*
* \sa SDL_GetGamepadType
@@ -671,6 +708,8 @@ extern SDL_DECLSPEC SDL_GamepadType SDLCALL SDL_GetGamepadTypeForID(SDL_Joystick
* \param instance_id the joystick instance ID.
* \returns the gamepad type.
*
+ * \threadsafety It is safe to call this function from any thread.
+ *
* \since This function is available since SDL 3.2.0.
*
* \sa SDL_GetGamepadTypeForID
@@ -688,6 +727,8 @@ extern SDL_DECLSPEC SDL_GamepadType SDLCALL SDL_GetRealGamepadTypeForID(SDL_Joys
* \returns the mapping string. Returns NULL if no mapping is available. This
* should be freed with SDL_free() when it is no longer needed.
*
+ * \threadsafety It is safe to call this function from any thread.
+ *
* \since This function is available since SDL 3.2.0.
*
* \sa SDL_GetGamepads
@@ -702,6 +743,8 @@ extern SDL_DECLSPEC char * SDLCALL SDL_GetGamepadMappingForID(SDL_JoystickID ins
* \returns a gamepad identifier or NULL if an error occurred; call
* SDL_GetError() for more information.
*
+ * \threadsafety It is safe to call this function from any thread.
+ *
* \since This function is available since SDL 3.2.0.
*
* \sa SDL_CloseGamepad
@@ -717,6 +760,8 @@ extern SDL_DECLSPEC SDL_Gamepad * SDLCALL SDL_OpenGamepad(SDL_JoystickID instanc
* \returns an SDL_Gamepad on success or NULL on failure or if it hasn't been
* opened yet; call SDL_GetError() for more information.
*
+ * \threadsafety It is safe to call this function from any thread.
+ *
* \since This function is available since SDL 3.2.0.
*/
extern SDL_DECLSPEC SDL_Gamepad * SDLCALL SDL_GetGamepadFromID(SDL_JoystickID instance_id);
@@ -727,6 +772,8 @@ extern SDL_DECLSPEC SDL_Gamepad * SDLCALL SDL_GetGamepadFromID(SDL_JoystickID in
* \param player_index the player index, which different from the instance ID.
* \returns the SDL_Gamepad associated with a player index.
*
+ * \threadsafety It is safe to call this function from any thread.
+ *
* \since This function is available since SDL 3.2.0.
*
* \sa SDL_GetGamepadPlayerIndex
@@ -757,6 +804,8 @@ extern SDL_DECLSPEC SDL_Gamepad * SDLCALL SDL_GetGamepadFromPlayerIndex(int play
* \returns a valid property ID on success or 0 on failure; call
* SDL_GetError() for more information.
*
+ * \threadsafety It is safe to call this function from any thread.
+ *
* \since This function is available since SDL 3.2.0.
*/
extern SDL_DECLSPEC SDL_PropertiesID SDLCALL SDL_GetGamepadProperties(SDL_Gamepad *gamepad);
@@ -775,6 +824,8 @@ extern SDL_DECLSPEC SDL_PropertiesID SDLCALL SDL_GetGamepadProperties(SDL_Gamepa
* \returns the instance ID of the specified gamepad on success or 0 on
* failure; call SDL_GetError() for more information.
*
+ * \threadsafety It is safe to call this function from any thread.
+ *
* \since This function is available since SDL 3.2.0.
*/
extern SDL_DECLSPEC SDL_JoystickID SDLCALL SDL_GetGamepadID(SDL_Gamepad *gamepad);
@@ -787,6 +838,8 @@ extern SDL_DECLSPEC SDL_JoystickID SDLCALL SDL_GetGamepadID(SDL_Gamepad *gamepad
* \returns the implementation dependent name for the gamepad, or NULL if
* there is no name or the identifier passed is invalid.
*
+ * \threadsafety It is safe to call this function from any thread.
+ *
* \since This function is available since SDL 3.2.0.
*
* \sa SDL_GetGamepadNameForID
@@ -801,6 +854,8 @@ extern SDL_DECLSPEC const char * SDLCALL SDL_GetGamepadName(SDL_Gamepad *gamepad
* \returns the implementation dependent path for the gamepad, or NULL if
* there is no path or the identifier passed is invalid.
*
+ * \threadsafety It is safe to call this function from any thread.
+ *
* \since This function is available since SDL 3.2.0.
*
* \sa SDL_GetGamepadPathForID
@@ -814,6 +869,8 @@ extern SDL_DECLSPEC const char * SDLCALL SDL_GetGamepadPath(SDL_Gamepad *gamepad
* \returns the gamepad type, or SDL_GAMEPAD_TYPE_UNKNOWN if it's not
* available.
*
+ * \threadsafety It is safe to call this function from any thread.
+ *
* \since This function is available since SDL 3.2.0.
*
* \sa SDL_GetGamepadTypeForID
@@ -827,6 +884,8 @@ extern SDL_DECLSPEC SDL_GamepadType SDLCALL SDL_GetGamepadType(SDL_Gamepad *game
* \returns the gamepad type, or SDL_GAMEPAD_TYPE_UNKNOWN if it's not
* available.
*
+ * \threadsafety It is safe to call this function from any thread.
+ *
* \since This function is available since SDL 3.2.0.
*
* \sa SDL_GetRealGamepadTypeForID
@@ -841,6 +900,8 @@ extern SDL_DECLSPEC SDL_GamepadType SDLCALL SDL_GetRealGamepadType(SDL_Gamepad *
* \param gamepad the gamepad object to query.
* \returns the player index for gamepad, or -1 if it's not available.
*
+ * \threadsafety It is safe to call this function from any thread.
+ *
* \since This function is available since SDL 3.2.0.
*
* \sa SDL_SetGamepadPlayerIndex
@@ -856,6 +917,8 @@ extern SDL_DECLSPEC int SDLCALL SDL_GetGamepadPlayerIndex(SDL_Gamepad *gamepad);
* \returns true on success or false on failure; call SDL_GetError() for more
* information.
*
+ * \threadsafety It is safe to call this function from any thread.
+ *
* \since This function is available since SDL 3.2.0.
*
* \sa SDL_GetGamepadPlayerIndex
@@ -870,6 +933,8 @@ extern SDL_DECLSPEC bool SDLCALL SDL_SetGamepadPlayerIndex(SDL_Gamepad *gamepad,
* \param gamepad the gamepad object to query.
* \returns the USB vendor ID, or zero if unavailable.
*
+ * \threadsafety It is safe to call this function from any thread.
+ *
* \since This function is available since SDL 3.2.0.
*
* \sa SDL_GetGamepadVendorForID
@@ -884,6 +949,8 @@ extern SDL_DECLSPEC Uint16 SDLCALL SDL_GetGamepadVendor(SDL_Gamepad *gamepad);
* \param gamepad the gamepad object to query.
* \returns the USB product ID, or zero if unavailable.
*
+ * \threadsafety It is safe to call this function from any thread.
+ *
* \since This function is available since SDL 3.2.0.
*
* \sa SDL_GetGamepadProductForID
@@ -898,6 +965,8 @@ extern SDL_DECLSPEC Uint16 SDLCALL SDL_GetGamepadProduct(SDL_Gamepad *gamepad);
* \param gamepad the gamepad object to query.
* \returns the USB product version, or zero if unavailable.
*
+ * \threadsafety It is safe to call this function from any thread.
+ *
* \since This function is available since SDL 3.2.0.
*
* \sa SDL_GetGamepadProductVersionForID
@@ -912,6 +981,8 @@ extern SDL_DECLSPEC Uint16 SDLCALL SDL_GetGamepadProductVersion(SDL_Gamepad *gam
* \param gamepad the gamepad object to query.
* \returns the gamepad firmware version, or zero if unavailable.
*
+ * \threadsafety It is safe to call this function from any thread.
+ *
* \since This function is available since SDL 3.2.0.
*/
extern SDL_DECLSPEC Uint16 SDLCALL SDL_GetGamepadFirmwareVersion(SDL_Gamepad *gamepad);
@@ -924,6 +995,8 @@ extern SDL_DECLSPEC Uint16 SDLCALL SDL_GetGamepadFirmwareVersion(SDL_Gamepad *ga
* \param gamepad the gamepad object to query.
* \returns the serial number, or NULL if unavailable.
*
+ * \threadsafety It is safe to call this function from any thread.
+ *
* \since This function is available since SDL 3.2.0.
*/
extern SDL_DECLSPEC const char * SDLCALL SDL_GetGamepadSerial(SDL_Gamepad *gamepad);
@@ -937,6 +1010,8 @@ extern SDL_DECLSPEC const char * SDLCALL SDL_GetGamepadSerial(SDL_Gamepad *gamep
* \param gamepad the gamepad object to query.
* \returns the gamepad handle, or 0 if unavailable.
*
+ * \threadsafety It is safe to call this function from any thread.
+ *
* \since This function is available since SDL 3.2.0.
*/
extern SDL_DECLSPEC Uint64 SDLCALL SDL_GetGamepadSteamHandle(SDL_Gamepad *gamepad);
@@ -949,6 +1024,8 @@ extern SDL_DECLSPEC Uint64 SDLCALL SDL_GetGamepadSteamHandle(SDL_Gamepad *gamepa
* `SDL_JOYSTICK_CONNECTION_INVALID` on failure; call SDL_GetError()
* for more information.
*
+ * \threadsafety It is safe to call this function from any thread.
+ *
* \since This function is available since SDL 3.2.0.
*/
extern SDL_DECLSPEC SDL_JoystickConnectionState SDLCALL SDL_GetGamepadConnectionState(SDL_Gamepad *gamepad);
@@ -969,6 +1046,8 @@ extern SDL_DECLSPEC SDL_JoystickConnectionState SDLCALL SDL_GetGamepadConnection
* battery.
* \returns the current battery state.
*
+ * \threadsafety It is safe to call this function from any thread.
+ *
* \since This function is available since SDL 3.2.0.
*/
extern SDL_DECLSPEC SDL_PowerState SDLCALL SDL_GetGamepadPowerInfo(SDL_Gamepad *gamepad, int *percent);
@@ -981,6 +1060,8 @@ extern SDL_DECLSPEC SDL_PowerState SDLCALL SDL_GetGamepadPowerInfo(SDL_Gamepad *
* \returns true if the gamepad has been opened and is currently connected, or
* false if not.
*
+ * \threadsafety It is safe to call this function from any thread.
+ *
* \since This function is available since SDL 3.2.0.
*/
extern SDL_DECLSPEC bool SDLCALL SDL_GamepadConnected(SDL_Gamepad *gamepad);
@@ -1001,6 +1082,8 @@ extern SDL_DECLSPEC bool SDLCALL SDL_GamepadConnected(SDL_Gamepad *gamepad);
* \returns an SDL_Joystick object, or NULL on failure; call SDL_GetError()
* for more information.
*
+ * \threadsafety It is safe to call this function from any thread.
+ *
* \since This function is available since SDL 3.2.0.
*/
extern SDL_DECLSPEC SDL_Joystick * SDLCALL SDL_GetGamepadJoystick(SDL_Gamepad *gamepad);
@@ -1013,6 +1096,8 @@ extern SDL_DECLSPEC SDL_Joystick * SDLCALL SDL_GetGamepadJoystick(SDL_Gamepad *g
*
* \param enabled whether to process gamepad events or not.
*
+ * \threadsafety It is safe to call this function from any thread.
+ *
* \since This function is available since SDL 3.2.0.
*
* \sa SDL_GamepadEventsEnabled
@@ -1028,6 +1113,8 @@ extern SDL_DECLSPEC void SDLCALL SDL_SetGamepadEventsEnabled(bool enabled);
*
* \returns true if gamepad events are being processed, false otherwise.
*
+ * \threadsafety It is safe to call this function from any thread.
+ *
* \since This function is available since SDL 3.2.0.
*
* \sa SDL_SetGamepadEventsEnabled
@@ -1044,6 +1131,8 @@ extern SDL_DECLSPEC bool SDLCALL SDL_GamepadEventsEnabled(void);
* single allocation that should be freed with SDL_free() when it is
* no longer needed.
*
+ * \threadsafety It is safe to call this function from any thread.
+ *
* \since This function is available since SDL 3.2.0.
*/
extern SDL_DECLSPEC SDL_GamepadBinding ** SDLCALL SDL_GetGamepadBindings(SDL_Gamepad *gamepad, int *count);
@@ -1055,6 +1144,8 @@ extern SDL_DECLSPEC SDL_GamepadBinding ** SDLCALL SDL_GetGamepadBindings(SDL_Gam
* enabled. Under such circumstances, it will not be necessary to call this
* function.
*
+ * \threadsafety It is safe to call this function from any thread.
+ *
* \since This function is available since SDL 3.2.0.
*/
extern SDL_DECLSPEC void SDLCALL SDL_UpdateGamepads(void);
@@ -1071,6 +1162,8 @@ extern SDL_DECLSPEC void SDLCALL SDL_UpdateGamepads(void);
* \returns the SDL_GamepadType enum corresponding to the input string, or
* `SDL_GAMEPAD_TYPE_UNKNOWN` if no match was found.
*
+ * \threadsafety It is safe to call this function from any thread.
+ *
* \since This function is available since SDL 3.2.0.
*
* \sa SDL_GetGamepadStringForType
@@ -1085,6 +1178,8 @@ extern SDL_DECLSPEC SDL_GamepadType SDLCALL SDL_GetGamepadTypeFromString(const c
* specified. The string returned is of the format used by
* SDL_Gamepad mapping strings.
*
+ * \threadsafety It is safe to call this function from any thread.
+ *
* \since This function is available since SDL 3.2.0.
*
* \sa SDL_GetGamepadTypeFromString
@@ -1107,6 +1202,8 @@ extern SDL_DECLSPEC const char * SDLCALL SDL_GetGamepadStringForType(SDL_Gamepad
* \returns the SDL_GamepadAxis enum corresponding to the input string, or
* `SDL_GAMEPAD_AXIS_INVALID` if no match was found.
*
+ * \threadsafety It is safe to call this function from any thread.
+ *
* \since This function is available since SDL 3.2.0.
*
* \sa SDL_GetGamepadStringForAxis
@@ -1121,6 +1218,8 @@ extern SDL_DECLSPEC SDL_GamepadAxis SDLCALL SDL_GetGamepadAxisFromString(const c
* specified. The string returned is of the format used by
* SDL_Gamepad mapping strings.
*
+ * \threadsafety It is safe to call this function from any thread.
+ *
* \since This function is available since SDL 3.2.0.
*
* \sa SDL_GetGamepadAxisFromString
@@ -1137,6 +1236,8 @@ extern SDL_DECLSPEC const char * SDLCALL SDL_GetGamepadStringForAxis(SDL_Gamepad
* \param axis an axis enum value (an SDL_GamepadAxis value).
* \returns true if the gamepad has this axis, false otherwise.
*
+ * \threadsafety It is safe to call this function from any thread.
+ *
* \since This function is available since SDL 3.2.0.
*
* \sa SDL_GamepadHasButton
@@ -1156,10 +1257,14 @@ extern SDL_DECLSPEC bool SDLCALL SDL_GamepadHasAxis(SDL_Gamepad *gamepad, SDL_Ga
* return a negative value. Note that this differs from the value reported by
* the lower-level SDL_GetJoystickAxis(), which normally uses the full range.
*
+ * Note that for invalid gamepads or axes, this will return 0. Zero is also a
+ * valid value in normal operation; usually it means a centered axis.
+ *
* \param gamepad a gamepad.
* \param axis an axis index (one of the SDL_GamepadAxis values).
- * \returns axis state (including 0) on success or 0 (also) on failure; call
- * SDL_GetError() for more information.
+ * \returns axis state.
+ *
+ * \threadsafety It is safe to call this function from any thread.
*
* \since This function is available since SDL 3.2.0.
*
@@ -1176,10 +1281,12 @@ extern SDL_DECLSPEC Sint16 SDLCALL SDL_GetGamepadAxis(SDL_Gamepad *gamepad, SDL_
* You do not normally need to call this function unless you are parsing
* SDL_Gamepad mappings in your own code.
*
- * \param str string representing a SDL_Gamepad axis.
+ * \param str string representing a SDL_Gamepad button.
* \returns the SDL_GamepadButton enum corresponding to the input string, or
* `SDL_GAMEPAD_BUTTON_INVALID` if no match was found.
*
+ * \threadsafety It is safe to call this function from any thread.
+ *
* \since This function is available since SDL 3.2.0.
*
* \sa SDL_GetGamepadStringForButton
@@ -1194,6 +1301,8 @@ extern SDL_DECLSPEC SDL_GamepadButton SDLCALL SDL_GetGamepadButtonFromString(con
* specified. The string returned is of the format used by
* SDL_Gamepad mapping strings.
*
+ * \threadsafety It is safe to call this function from any thread.
+ *
* \since This function is available since SDL 3.2.0.
*
* \sa SDL_GetGamepadButtonFromString
@@ -1210,6 +1319,8 @@ extern SDL_DECLSPEC const char * SDLCALL SDL_GetGamepadStringForButton(SDL_Gamep
* \param button a button enum value (an SDL_GamepadButton value).
* \returns true if the gamepad has this button, false otherwise.
*
+ * \threadsafety It is safe to call this function from any thread.
+ *
* \since This function is available since SDL 3.2.0.
*
* \sa SDL_GamepadHasAxis
@@ -1223,6 +1334,8 @@ extern SDL_DECLSPEC bool SDLCALL SDL_GamepadHasButton(SDL_Gamepad *gamepad, SDL_
* \param button a button index (one of the SDL_GamepadButton values).
* \returns true if the button is pressed, false otherwise.
*
+ * \threadsafety It is safe to call this function from any thread.
+ *
* \since This function is available since SDL 3.2.0.
*
* \sa SDL_GamepadHasButton
@@ -1237,6 +1350,8 @@ extern SDL_DECLSPEC bool SDLCALL SDL_GetGamepadButton(SDL_Gamepad *gamepad, SDL_
* \param button a button index (one of the SDL_GamepadButton values).
* \returns the SDL_GamepadButtonLabel enum corresponding to the button label.
*
+ * \threadsafety It is safe to call this function from any thread.
+ *
* \since This function is available since SDL 3.2.0.
*
* \sa SDL_GetGamepadButtonLabel
@@ -1250,6 +1365,8 @@ extern SDL_DECLSPEC SDL_GamepadButtonLabel SDLCALL SDL_GetGamepadButtonLabelForT
* \param button a button index (one of the SDL_GamepadButton values).
* \returns the SDL_GamepadButtonLabel enum corresponding to the button label.
*
+ * \threadsafety It is safe to call this function from any thread.
+ *
* \since This function is available since SDL 3.2.0.
*
* \sa SDL_GetGamepadButtonLabelForType
@@ -1262,6 +1379,8 @@ extern SDL_DECLSPEC SDL_GamepadButtonLabel SDLCALL SDL_GetGamepadButtonLabel(SDL
* \param gamepad a gamepad.
* \returns number of touchpads.
*
+ * \threadsafety It is safe to call this function from any thread.
+ *
* \since This function is available since SDL 3.2.0.
*
* \sa SDL_GetNumGamepadTouchpadFingers
@@ -1276,6 +1395,8 @@ extern SDL_DECLSPEC int SDLCALL SDL_GetNumGamepadTouchpads(SDL_Gamepad *gamepad)
* \param touchpad a touchpad.
* \returns number of supported simultaneous fingers.
*
+ * \threadsafety It is safe to call this function from any thread.
+ *
* \since This function is available since SDL 3.2.0.
*
* \sa SDL_GetGamepadTouchpadFinger
@@ -1299,6 +1420,8 @@ extern SDL_DECLSPEC int SDLCALL SDL_GetNumGamepadTouchpadFingers(SDL_Gamepad *ga
* \returns true on success or false on failure; call SDL_GetError() for more
* information.
*
+ * \threadsafety It is safe to call this function from any thread.
+ *
* \since This function is available since SDL 3.2.0.
*
* \sa SDL_GetNumGamepadTouchpadFingers
@@ -1312,6 +1435,8 @@ extern SDL_DECLSPEC bool SDLCALL SDL_GetGamepadTouchpadFinger(SDL_Gamepad *gamep
* \param type the type of sensor to query.
* \returns true if the sensor exists, false otherwise.
*
+ * \threadsafety It is safe to call this function from any thread.
+ *
* \since This function is available since SDL 3.2.0.
*
* \sa SDL_GetGamepadSensorData
@@ -1329,6 +1454,8 @@ extern SDL_DECLSPEC bool SDLCALL SDL_GamepadHasSensor(SDL_Gamepad *gamepad, SDL_
* \returns true on success or false on failure; call SDL_GetError() for more
* information.
*
+ * \threadsafety It is safe to call this function from any thread.
+ *
* \since This function is available since SDL 3.2.0.
*
* \sa SDL_GamepadHasSensor
@@ -1343,6 +1470,8 @@ extern SDL_DECLSPEC bool SDLCALL SDL_SetGamepadSensorEnabled(SDL_Gamepad *gamepa
* \param type the type of sensor to query.
* \returns true if the sensor is enabled, false otherwise.
*
+ * \threadsafety It is safe to call this function from any thread.
+ *
* \since This function is available since SDL 3.2.0.
*
* \sa SDL_SetGamepadSensorEnabled
@@ -1356,6 +1485,8 @@ extern SDL_DECLSPEC bool SDLCALL SDL_GamepadSensorEnabled(SDL_Gamepad *gamepad,
* \param type the type of sensor to query.
* \returns the data rate, or 0.0f if the data rate is not available.
*
+ * \threadsafety It is safe to call this function from any thread.
+ *
* \since This function is available since SDL 3.2.0.
*/
extern SDL_DECLSPEC float SDLCALL SDL_GetGamepadSensorDataRate(SDL_Gamepad *gamepad, SDL_SensorType type);
@@ -1364,7 +1495,7 @@ extern SDL_DECLSPEC float SDLCALL SDL_GetGamepadSensorDataRate(SDL_Gamepad *game
* Get the current state of a gamepad sensor.
*
* The number of values and interpretation of the data is sensor dependent.
- * See SDL_sensor.h for the details for each type of sensor.
+ * See the remarks in SDL_SensorType for details for each type of sensor.
*
* \param gamepad the gamepad to query.
* \param type the type of sensor to query.
@@ -1373,6 +1504,8 @@ extern SDL_DECLSPEC float SDLCALL SDL_GetGamepadSensorDataRate(SDL_Gamepad *game
* \returns true on success or false on failure; call SDL_GetError() for more
* information.
*
+ * \threadsafety It is safe to call this function from any thread.
+ *
* \since This function is available since SDL 3.2.0.
*/
extern SDL_DECLSPEC bool SDLCALL SDL_GetGamepadSensorData(SDL_Gamepad *gamepad, SDL_SensorType type, float *data, int num_values);
@@ -1395,6 +1528,8 @@ extern SDL_DECLSPEC bool SDLCALL SDL_GetGamepadSensorData(SDL_Gamepad *gamepad,
* \returns true on success or false on failure; call SDL_GetError() for more
* information.
*
+ * \threadsafety It is safe to call this function from any thread.
+ *
* \since This function is available since SDL 3.2.0.
*/
extern SDL_DECLSPEC bool SDLCALL SDL_RumbleGamepad(SDL_Gamepad *gamepad, Uint16 low_frequency_rumble, Uint16 high_frequency_rumble, Uint32 duration_ms);
@@ -1421,6 +1556,8 @@ extern SDL_DECLSPEC bool SDLCALL SDL_RumbleGamepad(SDL_Gamepad *gamepad, Uint16
* \returns true on success or false on failure; call SDL_GetError() for more
* information.
*
+ * \threadsafety It is safe to call this function from any thread.
+ *
* \since This function is available since SDL 3.2.0.
*
* \sa SDL_RumbleGamepad
@@ -1443,6 +1580,8 @@ extern SDL_DECLSPEC bool SDLCALL SDL_RumbleGamepadTriggers(SDL_Gamepad *gamepad,
* \returns true on success or false on failure; call SDL_GetError() for more
* information.
*
+ * \threadsafety It is safe to call this function from any thread.
+ *
* \since This function is available since SDL 3.2.0.
*/
extern SDL_DECLSPEC bool SDLCALL SDL_SetGamepadLED(SDL_Gamepad *gamepad, Uint8 red, Uint8 green, Uint8 blue);
@@ -1456,6 +1595,8 @@ extern SDL_DECLSPEC bool SDLCALL SDL_SetGamepadLED(SDL_Gamepad *gamepad, Uint8 r
* \returns true on success or false on failure; call SDL_GetError() for more
* information.
*
+ * \threadsafety It is safe to call this function from any thread.
+ *
* \since This function is available since SDL 3.2.0.
*/
extern SDL_DECLSPEC bool SDLCALL SDL_SendGamepadEffect(SDL_Gamepad *gamepad, const void *data, int size);
@@ -1466,6 +1607,8 @@ extern SDL_DECLSPEC bool SDLCALL SDL_SendGamepadEffect(SDL_Gamepad *gamepad, con
* \param gamepad a gamepad identifier previously returned by
* SDL_OpenGamepad().
*
+ * \threadsafety It is safe to call this function from any thread.
+ *
* \since This function is available since SDL 3.2.0.
*
* \sa SDL_OpenGamepad
@@ -1480,6 +1623,8 @@ extern SDL_DECLSPEC void SDLCALL SDL_CloseGamepad(SDL_Gamepad *gamepad);
* \param button a button on the gamepad.
* \returns the sfSymbolsName or NULL if the name can't be found.
*
+ * \threadsafety It is safe to call this function from any thread.
+ *
* \since This function is available since SDL 3.2.0.
*
* \sa SDL_GetGamepadAppleSFSymbolsNameForAxis
@@ -1493,6 +1638,8 @@ extern SDL_DECLSPEC const char * SDLCALL SDL_GetGamepadAppleSFSymbolsNameForButt
* \param axis an axis on the gamepad.
* \returns the sfSymbolsName or NULL if the name can't be found.
*
+ * \threadsafety It is safe to call this function from any thread.
+ *
* \since This function is available since SDL 3.2.0.
*
* \sa SDL_GetGamepadAppleSFSymbolsNameForButton
diff --git a/thirdparty/sdl/include/SDL3/SDL_guid.h b/thirdparty/sdl/include/SDL3/SDL_guid.h
index 312c42c0316..cf9df31ce14 100644
--- a/thirdparty/sdl/include/SDL3/SDL_guid.h
+++ b/thirdparty/sdl/include/SDL3/SDL_guid.h
@@ -1,6 +1,6 @@
/*
Simple DirectMedia Layer
- Copyright (C) 1997-2025 Sam Lantinga <[email protected]>
+ Copyright (C) 1997-2026 Sam Lantinga <[email protected]>
This software is provided 'as-is', without any express or implied
warranty. In no event will the authors be held liable for any damages
diff --git a/thirdparty/sdl/include/SDL3/SDL_haptic.h b/thirdparty/sdl/include/SDL3/SDL_haptic.h
index a45335b2858..ef91904ae72 100644
--- a/thirdparty/sdl/include/SDL3/SDL_haptic.h
+++ b/thirdparty/sdl/include/SDL3/SDL_haptic.h
@@ -1,6 +1,6 @@
/*
Simple DirectMedia Layer
- Copyright (C) 1997-2025 Sam Lantinga <[email protected]>
+ Copyright (C) 1997-2026 Sam Lantinga <[email protected]>
This software is provided 'as-is', without any express or implied
warranty. In no event will the authors be held liable for any damages
@@ -70,7 +70,7 @@
* {
* SDL_Haptic *haptic;
* SDL_HapticEffect effect;
- * int effect_id;
+ * SDL_HapticEffectID effect_id;
*
* // Open the device
* haptic = SDL_OpenHapticFromJoystick(joystick);
@@ -149,6 +149,19 @@ extern "C" {
*/
typedef struct SDL_Haptic SDL_Haptic;
+/*
+ * Misc defines.
+ */
+
+/**
+ * Used to play a device an infinite number of times.
+ *
+ * \since This macro is available since SDL 3.2.0.
+ *
+ * \sa SDL_RunHapticEffect
+ */
+#define SDL_HAPTIC_INFINITY 4294967295U
+
/**
* \name Haptic features
@@ -162,6 +175,11 @@ typedef struct SDL_Haptic SDL_Haptic;
*/
/* @{ */
+/**
+ * Type of haptic effect.
+ */
+typedef Uint16 SDL_HapticEffectType;
+
/**
* Constant effect supported.
*
@@ -383,6 +401,11 @@ typedef struct SDL_Haptic SDL_Haptic;
*/
/* @{ */
+/**
+ * Type of coordinates used for haptic direction.
+ */
+typedef Uint8 SDL_HapticDirectionType;
+
/**
* Uses polar coordinates for the direction.
*
@@ -426,18 +449,15 @@ typedef struct SDL_Haptic SDL_Haptic;
/* @} *//* Haptic features */
-/*
- * Misc defines.
- */
/**
- * Used to play a device an infinite number of times.
+ * ID for haptic effects.
*
- * \since This macro is available since SDL 3.2.0.
+ * This is -1 if the ID is invalid.
*
- * \sa SDL_RunHapticEffect
+ * \sa SDL_CreateHapticEffect
*/
-#define SDL_HAPTIC_INFINITY 4294967295U
+typedef int SDL_HapticEffectID;
/**
@@ -545,8 +565,8 @@ typedef struct SDL_Haptic SDL_Haptic;
*/
typedef struct SDL_HapticDirection
{
- Uint8 type; /**< The type of encoding. */
- Sint32 dir[3]; /**< The encoded direction. */
+ SDL_HapticDirectionType type; /**< The type of encoding. */
+ Sint32 dir[3]; /**< The encoded direction. */
} SDL_HapticDirection;
@@ -566,7 +586,7 @@ typedef struct SDL_HapticDirection
typedef struct SDL_HapticConstant
{
/* Header */
- Uint16 type; /**< SDL_HAPTIC_CONSTANT */
+ SDL_HapticEffectType type; /**< SDL_HAPTIC_CONSTANT */
SDL_HapticDirection direction; /**< Direction of the effect. */
/* Replay */
@@ -652,9 +672,9 @@ typedef struct SDL_HapticConstant
typedef struct SDL_HapticPeriodic
{
/* Header */
- Uint16 type; /**< SDL_HAPTIC_SINE, SDL_HAPTIC_SQUARE
- SDL_HAPTIC_TRIANGLE, SDL_HAPTIC_SAWTOOTHUP or
- SDL_HAPTIC_SAWTOOTHDOWN */
+ SDL_HapticEffectType type; /**< SDL_HAPTIC_SINE, SDL_HAPTIC_SQUARE
+ SDL_HAPTIC_TRIANGLE, SDL_HAPTIC_SAWTOOTHUP or
+ SDL_HAPTIC_SAWTOOTHDOWN */
SDL_HapticDirection direction; /**< Direction of the effect. */
/* Replay */
@@ -708,8 +728,8 @@ typedef struct SDL_HapticPeriodic
typedef struct SDL_HapticCondition
{
/* Header */
- Uint16 type; /**< SDL_HAPTIC_SPRING, SDL_HAPTIC_DAMPER,
- SDL_HAPTIC_INERTIA or SDL_HAPTIC_FRICTION */
+ SDL_HapticEffectType type; /**< SDL_HAPTIC_SPRING, SDL_HAPTIC_DAMPER,
+ SDL_HAPTIC_INERTIA or SDL_HAPTIC_FRICTION */
SDL_HapticDirection direction; /**< Direction of the effect. */
/* Replay */
@@ -747,7 +767,7 @@ typedef struct SDL_HapticCondition
typedef struct SDL_HapticRamp
{
/* Header */
- Uint16 type; /**< SDL_HAPTIC_RAMP */
+ SDL_HapticEffectType type; /**< SDL_HAPTIC_RAMP */
SDL_HapticDirection direction; /**< Direction of the effect. */
/* Replay */
@@ -786,7 +806,7 @@ typedef struct SDL_HapticRamp
typedef struct SDL_HapticLeftRight
{
/* Header */
- Uint16 type; /**< SDL_HAPTIC_LEFTRIGHT */
+ SDL_HapticEffectType type; /**< SDL_HAPTIC_LEFTRIGHT */
/* Replay */
Uint32 length; /**< Duration of the effect in milliseconds. */
@@ -816,7 +836,7 @@ typedef struct SDL_HapticLeftRight
typedef struct SDL_HapticCustom
{
/* Header */
- Uint16 type; /**< SDL_HAPTIC_CUSTOM */
+ SDL_HapticEffectType type; /**< SDL_HAPTIC_CUSTOM */
SDL_HapticDirection direction; /**< Direction of the effect. */
/* Replay */
@@ -915,7 +935,7 @@ typedef struct SDL_HapticCustom
typedef union SDL_HapticEffect
{
/* Common for all force feedback effects */
- Uint16 type; /**< Effect type. */
+ SDL_HapticEffectType type; /**< Effect type. */
SDL_HapticConstant constant; /**< Constant effect. */
SDL_HapticPeriodic periodic; /**< Periodic effect. */
SDL_HapticCondition condition; /**< Condition effect. */
@@ -1193,7 +1213,7 @@ extern SDL_DECLSPEC bool SDLCALL SDL_HapticEffectSupported(SDL_Haptic *haptic, c
* \sa SDL_RunHapticEffect
* \sa SDL_UpdateHapticEffect
*/
-extern SDL_DECLSPEC int SDLCALL SDL_CreateHapticEffect(SDL_Haptic *haptic, const SDL_HapticEffect *effect);
+extern SDL_DECLSPEC SDL_HapticEffectID SDLCALL SDL_CreateHapticEffect(SDL_Haptic *haptic, const SDL_HapticEffect *effect);
/**
* Update the properties of an effect.
@@ -1215,7 +1235,7 @@ extern SDL_DECLSPEC int SDLCALL SDL_CreateHapticEffect(SDL_Haptic *haptic, const
* \sa SDL_CreateHapticEffect
* \sa SDL_RunHapticEffect
*/
-extern SDL_DECLSPEC bool SDLCALL SDL_UpdateHapticEffect(SDL_Haptic *haptic, int effect, const SDL_HapticEffect *data);
+extern SDL_DECLSPEC bool SDLCALL SDL_UpdateHapticEffect(SDL_Haptic *haptic, SDL_HapticEffectID effect, const SDL_HapticEffect *data);
/**
* Run the haptic effect on its associated haptic device.
@@ -1239,7 +1259,7 @@ extern SDL_DECLSPEC bool SDLCALL SDL_UpdateHapticEffect(SDL_Haptic *haptic, int
* \sa SDL_StopHapticEffect
* \sa SDL_StopHapticEffects
*/
-extern SDL_DECLSPEC bool SDLCALL SDL_RunHapticEffect(SDL_Haptic *haptic, int effect, Uint32 iterations);
+extern SDL_DECLSPEC bool SDLCALL SDL_RunHapticEffect(SDL_Haptic *haptic, SDL_HapticEffectID effect, Uint32 iterations);
/**
* Stop the haptic effect on its associated haptic device.
@@ -1254,7 +1274,7 @@ extern SDL_DECLSPEC bool SDLCALL SDL_RunHapticEffect(SDL_Haptic *haptic, int eff
* \sa SDL_RunHapticEffect
* \sa SDL_StopHapticEffects
*/
-extern SDL_DECLSPEC bool SDLCALL SDL_StopHapticEffect(SDL_Haptic *haptic, int effect);
+extern SDL_DECLSPEC bool SDLCALL SDL_StopHapticEffect(SDL_Haptic *haptic, SDL_HapticEffectID effect);
/**
* Destroy a haptic effect on the device.
@@ -1269,7 +1289,7 @@ extern SDL_DECLSPEC bool SDLCALL SDL_StopHapticEffect(SDL_Haptic *haptic, int ef
*
* \sa SDL_CreateHapticEffect
*/
-extern SDL_DECLSPEC void SDLCALL SDL_DestroyHapticEffect(SDL_Haptic *haptic, int effect);
+extern SDL_DECLSPEC void SDLCALL SDL_DestroyHapticEffect(SDL_Haptic *haptic, SDL_HapticEffectID effect);
/**
* Get the status of the current effect on the specified haptic device.
@@ -1285,7 +1305,7 @@ extern SDL_DECLSPEC void SDLCALL SDL_DestroyHapticEffect(SDL_Haptic *haptic, int
*
* \sa SDL_GetHapticFeatures
*/
-extern SDL_DECLSPEC bool SDLCALL SDL_GetHapticEffectStatus(SDL_Haptic *haptic, int effect);
+extern SDL_DECLSPEC bool SDLCALL SDL_GetHapticEffectStatus(SDL_Haptic *haptic, SDL_HapticEffectID effect);
/**
* Set the global gain of the specified haptic device.
@@ -1372,7 +1392,7 @@ extern SDL_DECLSPEC bool SDLCALL SDL_ResumeHaptic(SDL_Haptic *haptic);
* \since This function is available since SDL 3.2.0.
*
* \sa SDL_RunHapticEffect
- * \sa SDL_StopHapticEffects
+ * \sa SDL_StopHapticEffect
*/
extern SDL_DECLSPEC bool SDLCALL SDL_StopHapticEffects(SDL_Haptic *haptic);
diff --git a/thirdparty/sdl/include/SDL3/SDL_hidapi.h b/thirdparty/sdl/include/SDL3/SDL_hidapi.h
index 131b03723a5..90e574c41d9 100644
--- a/thirdparty/sdl/include/SDL3/SDL_hidapi.h
+++ b/thirdparty/sdl/include/SDL3/SDL_hidapi.h
@@ -1,6 +1,6 @@
/*
Simple DirectMedia Layer
- Copyright (C) 1997-2025 Sam Lantinga <[email protected]>
+ Copyright (C) 1997-2026 Sam Lantinga <[email protected]>
This software is provided 'as-is', without any express or implied
warranty. In no event will the authors be held liable for any damages
@@ -55,6 +55,7 @@
#include <SDL3/SDL_stdinc.h>
#include <SDL3/SDL_error.h>
+#include <SDL3/SDL_properties.h>
#include <SDL3/SDL_begin_code.h>
/* Set up for C function definitions, even when using C++ */
@@ -283,6 +284,24 @@ extern SDL_DECLSPEC SDL_hid_device * SDLCALL SDL_hid_open(unsigned short vendor_
*/
extern SDL_DECLSPEC SDL_hid_device * SDLCALL SDL_hid_open_path(const char *path);
+/**
+ * Get the properties associated with an SDL_hid_device.
+ *
+ * The following read-only properties are provided by SDL:
+ *
+ * - `SDL_PROP_HIDAPI_LIBUSB_DEVICE_HANDLE_POINTER`: the libusb_device_handle
+ * associated with the device, if it was opened using libusb.
+ *
+ * \param dev a device handle returned from SDL_hid_open().
+ * \returns a valid property ID on success or 0 on failure; call
+ * SDL_GetError() for more information.
+ *
+ * \since This function is available since SDL 3.4.0.
+ */
+extern SDL_DECLSPEC SDL_PropertiesID SDLCALL SDL_hid_get_properties(SDL_hid_device *dev);
+
+#define SDL_PROP_HIDAPI_LIBUSB_DEVICE_HANDLE_POINTER "SDL.hidapi.libusb.device.handle"
+
/**
* Write an Output report to a HID device.
*
diff --git a/thirdparty/sdl/include/SDL3/SDL_hints.h b/thirdparty/sdl/include/SDL3/SDL_hints.h
index ecee3d36f17..a38abf02d15 100644
--- a/thirdparty/sdl/include/SDL3/SDL_hints.h
+++ b/thirdparty/sdl/include/SDL3/SDL_hints.h
@@ -1,6 +1,6 @@
/*
Simple DirectMedia Layer
- Copyright (C) 1997-2025 Sam Lantinga <[email protected]>
+ Copyright (C) 1997-2026 Sam Lantinga <[email protected]>
This software is provided 'as-is', without any express or implied
warranty. In no event will the authors be held liable for any damages
@@ -117,6 +117,33 @@ extern "C" {
*/
#define SDL_HINT_ANDROID_LOW_LATENCY_AUDIO "SDL_ANDROID_LOW_LATENCY_AUDIO"
+/**
+ * A variable to control Android's AAudio input preset.
+ *
+ * This hint only applies to SDL's "aaudio" backend on Android 9+ devices.
+ *
+ * Some devices choose the wrong microphone by default (between the one meant
+ * to be spoken in when the phone is held to the user's ear for a phone call,
+ * or an external microphone that's meant to be used when recording video),
+ * or have DSP effects applied to the recorded audio, and changing the input
+ * preset can help control this.
+ *
+ * This can be any number that maps to an `AAUDIO_INPUT_PRESET_*` enum from
+ * the Android NDK headers. The most reasonable choices are 5 ("camcorder",
+ * for external microphones) and 7 ("voice communication", for speaking
+ * directly into the device like a mobile phone). 6 ("voice recognition")
+ * might also be a useful choice.
+ *
+ * If unset (the default), SDL will not specify an input preset at all, which
+ * lets the system choose. This is usually the correct thing to do unless
+ * your app is having problems.
+ *
+ * This hint should be set before a recording audio device is opened.
+ *
+ * \since This hint is available since SDL 3.4.16.
+ */
+#define SDL_HINT_ANDROID_AAUDIO_INPUT_PRESET "SDL_ANDROID_AAUDIO_INPUT_PRESET"
+
/**
* A variable to control whether we trap the Android back button to handle it
* manually.
@@ -391,12 +418,51 @@ extern "C" {
* concept, so it applies to a physical audio device in this case, and not an
* SDL_AudioStream, nor an SDL logical audio device.
*
+ * For Windows WASAPI audio, the following roles are supported, and map to
+ * `AUDIO_STREAM_CATEGORY`:
+ *
+ * - "Other" (default)
+ * - "Communications" - Real-time communications, such as VOIP or chat
+ * - "Game" - Game audio
+ * - "GameChat" - Game chat audio, similar to "Communications" except that
+ * this will not attenuate other audio streams
+ * - "Movie" - Music or sound with dialog
+ * - "Media" - Music or sound without dialog
+ *
+ * Android's AAudio target supports this hint as of SDL 3.4.4. Android does
+ * not support the exact same options as WASAPI, but for portability, will
+ * attempt to map these same strings to the `aaudio_usage_t` constants. For
+ * example, "Movie" and "Media" will both map to `AAUDIO_USAGE_MEDIA`, etc.
+ *
+ * If your application applies its own echo cancellation, gain control, and
+ * noise reduction it should also set SDL_HINT_AUDIO_DEVICE_RAW_STREAM.
+ *
* This hint should be set before an audio device is opened.
*
* \since This hint is available since SDL 3.2.0.
*/
#define SDL_HINT_AUDIO_DEVICE_STREAM_ROLE "SDL_AUDIO_DEVICE_STREAM_ROLE"
+/**
+ * Specify whether this audio device should do audio processing.
+ *
+ * Some operating systems perform echo cancellation, gain control, and noise
+ * reduction as needed. If your application already handles these, you can set
+ * this hint to prevent the OS from doing additional audio processing.
+ *
+ * This corresponds to the WASAPI audio option `AUDCLNT_STREAMOPTIONS_RAW`.
+ *
+ * The variable can be set to the following values:
+ *
+ * - "0": audio processing can be done by the OS. (default)
+ * - "1": audio processing is done by the application.
+ *
+ * This hint should be set before an audio device is opened.
+ *
+ * \since This hint is available since SDL 3.4.0.
+ */
+#define SDL_HINT_AUDIO_DEVICE_RAW_STREAM "SDL_AUDIO_DEVICE_RAW_STREAM"
+
/**
* Specify the input file when recording audio using the disk audio driver.
*
@@ -685,6 +751,21 @@ extern "C" {
*/
#define SDL_HINT_DISPLAY_USABLE_BOUNDS "SDL_DISPLAY_USABLE_BOUNDS"
+/**
+ * Set the level of checking for invalid parameters passed to SDL functions.
+ *
+ * The variable can be set to the following values:
+ *
+ * - "1": Enable fast parameter error checking, e.g. quick NULL checks, etc.
+ * - "2": Enable full parameter error checking, e.g. validating objects are
+ * the correct type, etc. (default)
+ *
+ * This hint can be set anytime.
+ *
+ * \since This hint is available since SDL 3.4.0.
+ */
+#define SDL_HINT_INVALID_PARAM_CHECKS "SDL_INVALID_PARAM_CHECKS"
+
/**
* Disable giving back control to the browser automatically when running with
* asyncify.
@@ -711,8 +792,6 @@ extern "C" {
*
* This hint only applies to the emscripten platform.
*
- * The default value is "#canvas"
- *
* This hint should be set before creating a window.
*
* \since This hint is available since SDL 3.2.0.
@@ -726,7 +805,7 @@ extern "C" {
*
* The variable can be one of:
*
- * - "#window": the javascript window object (default)
+ * - "#window": the javascript window object
* - "#document": the javascript document object
* - "#screen": the javascript window.screen object
* - "#canvas": the WebGL canvas element
@@ -757,6 +836,25 @@ extern "C" {
*/
#define SDL_HINT_ENABLE_SCREEN_KEYBOARD "SDL_ENABLE_SCREEN_KEYBOARD"
+/**
+ * A variable that controls whether the Steam on-screen keyboard should be
+ * shown when text input is active.
+ *
+ * Steam will set this hint via environment variable for games launched in Big
+ * Picture mode. To override this you should call SDL_SetHintWithPriority()
+ * with priority `SDL_HINT_OVERRIDE`.
+ *
+ * The variable can be set to the following values:
+ *
+ * - "0": Do not show the Steam on-screen keyboard.
+ * - "1": Show the Steam on-screen keyboard.
+ *
+ * This hint should be set before SDL is initialized.
+ *
+ * \since This hint is available since SDL 3.4.12.
+ */
+#define SDL_HINT_ENABLE_STEAM_SCREEN_KEYBOARD "SDL_ENABLE_STEAM_SCREEN_KEYBOARD"
+
/**
* A variable containing a list of evdev devices to use if udev is not
* available.
@@ -1037,6 +1135,21 @@ extern "C" {
*/
#define SDL_HINT_HIDAPI_LIBUSB "SDL_HIDAPI_LIBUSB"
+
+/**
+ * A variable to control whether HIDAPI uses libusb for GameCube adapters.
+ *
+ * The variable can be set to the following values:
+ *
+ * - "0": HIDAPI will not use libusb for GameCube adapters.
+ * - "1": HIDAPI will use libusb for GameCube adapters if available. (default)
+ *
+ * This hint should be set before SDL is initialized.
+ *
+ * \since This hint is available since SDL 3.4.0.
+ */
+#define SDL_HINT_HIDAPI_LIBUSB_GAMECUBE "SDL_HIDAPI_LIBUSB_GAMECUBE"
+
/**
* A variable to control whether HIDAPI uses libusb only for whitelisted
* devices.
@@ -1143,8 +1256,8 @@ extern "C" {
#define SDL_HINT_IME_IMPLEMENTED_UI "SDL_IME_IMPLEMENTED_UI"
/**
- * A variable controlling whether the home indicator bar on iPhone X should be
- * hidden.
+ * A variable controlling whether the home indicator bar on iPhone X and later
+ * should be hidden.
*
* The variable can be set to the following values:
*
@@ -1345,6 +1458,26 @@ extern "C" {
*/
#define SDL_HINT_JOYSTICK_GAMEINPUT "SDL_JOYSTICK_GAMEINPUT"
+/**
+ * A variable controlling whether GameInput should be used for handling
+ * GIP devices that require raw report processing, but aren't supported
+ * by HIDRAW, such as Xbox One Guitars.
+ *
+ * Note that this is only supported with GameInput 3 or newer.
+ *
+ * The variable can be set to the following values:
+ *
+ * - "0": GameInput is not used to handle raw GIP devices.
+ * - "1": GameInput is used.
+ *
+ * The default is "1" when using GameInput 3 or newer, and is "0" otherwise.
+ *
+ * This hint should be set before SDL is initialized.
+ *
+ * \since This hint is available since SDL 3.4.4.
+ */
+#define SDL_HINT_JOYSTICK_GAMEINPUT_RAW "SDL_JOYSTICK_GAMEINPUT_RAW"
+
/**
* A variable containing a list of devices known to have a GameCube form
* factor.
@@ -1716,13 +1849,106 @@ extern "C" {
* A variable controlling whether the HIDAPI driver for HORI licensed Steam
* controllers should be used.
*
- * This variable can be set to the following values: "0" - HIDAPI driver is
- * not used "1" - HIDAPI driver is used
+ * The variable can be set to the following values:
*
- * The default is the value of SDL_HINT_JOYSTICK_HIDAPI
+ * - "0": HIDAPI driver is not used.
+ * - "1": HIDAPI driver is used.
+ *
+ * The default is the value of SDL_HINT_JOYSTICK_HIDAPI.
+ *
+ * This hint should be set before initializing joysticks and gamepads.
+ *
+ * \since This hint is available since SDL 3.2.0.
*/
#define SDL_HINT_JOYSTICK_HIDAPI_STEAM_HORI "SDL_JOYSTICK_HIDAPI_STEAM_HORI"
+/**
+ * A variable controlling whether the HIDAPI driver for some Logitech wheels
+ * should be used.
+ *
+ * The variable can be set to the following values:
+ *
+ * - "0": HIDAPI driver is not used.
+ * - "1": HIDAPI driver is used.
+ *
+ * The default is the value of SDL_HINT_JOYSTICK_HIDAPI.
+ *
+ * This hint should be set before initializing joysticks and gamepads.
+ *
+ * \since This hint is available since SDL 3.4.0.
+ */
+#define SDL_HINT_JOYSTICK_HIDAPI_LG4FF "SDL_JOYSTICK_HIDAPI_LG4FF"
+
+/**
+ * A variable controlling whether the HIDAPI driver for 8BitDo controllers
+ * should be used.
+ *
+ * The variable can be set to the following values:
+ *
+ * - "0": HIDAPI driver is not used.
+ * - "1": HIDAPI driver is used.
+ *
+ * The default is the value of SDL_HINT_JOYSTICK_HIDAPI.
+ *
+ * This hint should be set before initializing joysticks and gamepads.
+ *
+ * \since This hint is available since SDL 3.4.0.
+ */
+#define SDL_HINT_JOYSTICK_HIDAPI_8BITDO "SDL_JOYSTICK_HIDAPI_8BITDO"
+
+/**
+ * A variable controlling whether the HIDAPI driver for SInput controllers
+ * should be used.
+ *
+ * More info - https://github.com/HandHeldLegend/SInput-HID
+ *
+ * The variable can be set to the following values:
+ *
+ * - "0": HIDAPI driver is not used.
+ * - "1": HIDAPI driver is used.
+ *
+ * The default is the value of SDL_HINT_JOYSTICK_HIDAPI.
+ *
+ * This hint should be set before initializing joysticks and gamepads.
+ *
+ * \since This hint is available since SDL 3.4.0.
+ */
+#define SDL_HINT_JOYSTICK_HIDAPI_SINPUT "SDL_JOYSTICK_HIDAPI_SINPUT"
+
+/**
+ * A variable controlling whether the HIDAPI driver for ZUIKI controllers
+ * should be used.
+ *
+ * The variable can be set to the following values:
+ *
+ * - "0": HIDAPI driver is not used.
+ * - "1": HIDAPI driver is used.
+ *
+ * The default is the value of SDL_HINT_JOYSTICK_HIDAPI.
+ *
+ * This hint should be set before initializing joysticks and gamepads.
+ *
+ * \since This hint is available since SDL 3.4.0.
+ */
+#define SDL_HINT_JOYSTICK_HIDAPI_ZUIKI "SDL_JOYSTICK_HIDAPI_ZUIKI"
+
+/**
+ * A variable controlling whether the HIDAPI driver for Flydigi controllers
+ * should be used.
+ *
+ * The variable can be set to the following values:
+ *
+ * - "0": HIDAPI driver is not used.
+ * - "1": HIDAPI driver is used.
+ *
+ * The default is the value of SDL_HINT_JOYSTICK_HIDAPI.
+ *
+ * This hint should be set before initializing joysticks and gamepads.
+ *
+ * \since This hint is available since SDL 3.4.0.
+ */
+#define SDL_HINT_JOYSTICK_HIDAPI_FLYDIGI "SDL_JOYSTICK_HIDAPI_FLYDIGI"
+
/**
* A variable controlling whether the HIDAPI driver for Nintendo Switch
* controllers should be used.
@@ -1774,6 +2000,23 @@ extern "C" {
*/
#define SDL_HINT_JOYSTICK_HIDAPI_SWITCH_PLAYER_LED "SDL_JOYSTICK_HIDAPI_SWITCH_PLAYER_LED"
+/**
+ * A variable controlling whether the HIDAPI driver for Nintendo Switch 2
+ * controllers should be used.
+ *
+ * The variable can be set to the following values:
+ *
+ * - "0": HIDAPI driver is not used.
+ * - "1": HIDAPI driver is used.
+ *
+ * The default is the value of SDL_HINT_JOYSTICK_HIDAPI.
+ *
+ * This hint should be set before initializing joysticks and gamepads.
+ *
+ * \since This hint is available since SDL 3.4.0.
+ */
+#define SDL_HINT_JOYSTICK_HIDAPI_SWITCH2 "SDL_JOYSTICK_HIDAPI_SWITCH2"
+
/**
* A variable controlling whether Nintendo Switch Joy-Con controllers will be
* in vertical mode when using the HIDAPI driver.
@@ -1926,6 +2169,42 @@ extern "C" {
*/
#define SDL_HINT_JOYSTICK_HIDAPI_XBOX_ONE_HOME_LED "SDL_JOYSTICK_HIDAPI_XBOX_ONE_HOME_LED"
+/**
+ * A variable controlling whether the new HIDAPI driver for wired Xbox One
+ * (GIP) controllers should be used.
+ *
+ * The variable can be set to the following values:
+ *
+ * - "0": HIDAPI driver is not used.
+ * - "1": HIDAPI driver is used.
+ *
+ * The default is the value of SDL_HINT_JOYSTICK_HIDAPI_XBOX_ONE.
+ *
+ * This hint should be set before initializing joysticks and gamepads.
+ *
+ * \since This hint is available since SDL 3.4.0.
+ */
+#define SDL_HINT_JOYSTICK_HIDAPI_GIP "SDL_JOYSTICK_HIDAPI_GIP"
+
+/**
+ * A variable controlling whether the new HIDAPI driver for wired Xbox One
+ * (GIP) controllers should reset the controller if it can't get the metadata
+ * from the controller.
+ *
+ * The variable can be set to the following values:
+ *
+ * - "0": Assume this is a generic controller.
+ * - "1": Reset the controller to get metadata.
+ *
+ * By default the controller is reset. This is so we can properly detect
+ * the controller type.
+ *
+ * This hint should be set before initializing joysticks and gamepads.
+ *
+ * \since This hint is available since SDL 3.4.0.
+ */
+#define SDL_HINT_JOYSTICK_HIDAPI_GIP_RESET_FOR_METADATA "SDL_JOYSTICK_HIDAPI_GIP_RESET_FOR_METADATA"
+
/**
* A variable controlling whether IOKit should be used for controller
* handling.
@@ -2228,9 +2507,9 @@ extern "C" {
* pressing the 1 key would yield the keycode SDLK_1, or '1', instead of
* SDLK_AMPERSAND, or '&'
* - "latin_letters": For keyboards using non-Latin letters, such as Russian
- * or Thai, the letter keys generate keycodes as though it had an en_US
- * layout. e.g. pressing the key associated with SDL_SCANCODE_A on a Russian
- * keyboard would yield 'a' instead of a Cyrillic letter.
+ * or Thai, the letter keys generate keycodes as though it had an English
+ * QWERTY layout. e.g. pressing the key associated with SDL_SCANCODE_A on a
+ * Russian keyboard would yield 'a' instead of a Cyrillic letter.
*
* The default value for this hint is "french_numbers,latin_letters"
*
@@ -2289,6 +2568,27 @@ extern "C" {
*/
#define SDL_HINT_KMSDRM_REQUIRE_DRM_MASTER "SDL_KMSDRM_REQUIRE_DRM_MASTER"
+/**
+ * A variable that controls whether KMSDRM will use "atomic" functionality.
+ *
+ * The KMSDRM backend can use atomic commits, if both DRM_CLIENT_CAP_ATOMIC
+ * and DRM_CLIENT_CAP_UNIVERSAL_PLANES is supported by the system. As of SDL
+ * 3.4.0, it will favor this functionality, but in case this doesn't work well
+ * on a given system or other surprises, this hint can be used to disable it.
+ *
+ * This hint can not enable the functionality if it isn't available.
+ *
+ * The variable can be set to the following values:
+ *
+ * - "0": SDL will not use the KMSDRM "atomic" functionality.
+ * - "1": SDL will allow usage of the KMSDRM "atomic" functionality. (default)
+ *
+ * This hint should be set before SDL is initialized.
+ *
+ * \since This hint is available since SDL 3.4.0.
+ */
+#define SDL_HINT_KMSDRM_ATOMIC "SDL_KMSDRM_ATOMIC"
+
/**
* A variable controlling the default SDL log levels.
*
@@ -2309,6 +2609,11 @@ extern "C" {
*
* `app=info,assert=warn,test=verbose,*=error`
*
+ * If the `DEBUG_INVOCATION` environment variable is set to "1", the default
+ * log levels are equivalent to:
+ *
+ * `assert=warn,test=verbose,*=debug`
+ *
* This hint can be set anytime.
*
* \since This hint is available since SDL 3.2.0.
@@ -2410,6 +2715,21 @@ extern "C" {
*/
#define SDL_HINT_MAC_SCROLL_MOMENTUM "SDL_MAC_SCROLL_MOMENTUM"
+/**
+ * A variable controlling whether holding down a key will repeat the pressed
+ * key or open the accents menu on macOS.
+ *
+ * The variable can be set to the following values:
+ *
+ * - "0": Holding a key will repeat the pressed key.
+ * - "1": Holding a key will open the accents menu for that key. (default)
+ *
+ * This hint needs to be set before SDL_Init().
+ *
+ * \since This hint is available since SDL 3.4.0.
+ */
+#define SDL_HINT_MAC_PRESS_AND_HOLD "SDL_MAC_PRESS_AND_HOLD"
+
/**
* Request SDL_AppIterate() be called at a specific rate.
*
@@ -2430,6 +2750,10 @@ extern "C" {
* This defaults to 0, and specifying NULL for the hint's value will restore
* the default.
*
+ * This doesn't have to be an integer value. For example, "59.94" won't be
+ * rounded to an integer rate; the digits after the decimal are actually
+ * respected.
+ *
* This hint can be set anytime.
*
* \since This hint is available since SDL 3.2.0.
@@ -2485,6 +2809,24 @@ extern "C" {
*/
#define SDL_HINT_MOUSE_DEFAULT_SYSTEM_CURSOR "SDL_MOUSE_DEFAULT_SYSTEM_CURSOR"
+/**
+ * A variable setting whether we should scale cursors by the current display
+ * scale.
+ *
+ * The variable can be set to the following values:
+ *
+ * - "0": Cursors will not change size based on the display content scale.
+ * (default)
+ * - "1": Cursors will automatically match the display content scale (e.g. a
+ * 2x sized cursor will be used when the window is on a monitor with 200%
+ * scale). This is currently implemented on Windows.
+ *
+ * This hint needs to be set before creating cursors.
+ *
+ * \since This hint is available since SDL 3.4.0.
+ */
+#define SDL_HINT_MOUSE_DPI_SCALE_CURSORS "SDL_MOUSE_DPI_SCALE_CURSORS"
+
/**
* A variable controlling whether warping a hidden mouse cursor will activate
* relative mouse mode.
@@ -2493,7 +2835,7 @@ extern "C" {
* the window center occur within a short time period, SDL will emulate mouse
* warps using relative mouse mode. This can provide smoother and more
* reliable mouse motion for some older games, which continuously calculate
- * the distance travelled by the mouse pointer and warp it back to the center
+ * the distance traveled by the mouse pointer and warp it back to the center
* of the window, rather than using relative mouse motion.
*
* Note that relative mouse mode may have different mouse acceleration
@@ -2736,6 +3078,46 @@ extern "C" {
*/
#define SDL_HINT_OPENGL_ES_DRIVER "SDL_OPENGL_ES_DRIVER"
+/**
+ * A variable controlling whether to force an sRGB-capable OpenGL context.
+ *
+ * At OpenGL context creation time, some platforms can request an sRGB-capable
+ * context. However, sometimes any form of the request can cause surprising
+ * results on some drivers, platforms, and hardware. Usually the surprise is
+ * in the form of rendering that is either a little darker or a little
+ * brighter than intended.
+ *
+ * This hint allows the user to override the app's sRGB requests and either
+ * force a specific value, or avoid requesting anything at all, depending on
+ * what makes things work correctly for their system.
+ *
+ * This is meant as a fail-safe; apps should probably not explicitly set this,
+ * and most users should not, either.
+ *
+ * Note that some platforms cannot make this request at all, and on all
+ * platforms this request can be denied by the operating system.
+ *
+ * In addition to attempting to obtain the type of sRGB-capable OpenGL context
+ * requested by this hint, SDL will try to force the state of
+ * GL_FRAMEBUFFER_SRGB on the new context, if appropriate.
+ *
+ * The variable can be set to the following values:
+ *
+ * - "0": Force a request for an OpenGL context that is _not_ sRGB-capable.
+ * - "1": Force a request for an OpenGL context that _is_ sRGB-capable.
+ * - "skip": Don't make any request for an sRGB-capable context (don't specify
+ * the attribute at all during context creation time).
+ * - any other string is undefined behavior.
+ *
+ * If unset, or set to an empty string, SDL will make a request using the
+ * value the app specified with the SDL_GL_FRAMEBUFFER_SRGB_CAPABLE attribute.
+ *
+ * This hint should be set before an OpenGL context is created.
+ *
+ * \since This hint is available since SDL 3.4.2.
+ */
+#define SDL_HINT_OPENGL_FORCE_SRGB_FRAMEBUFFER "SDL_OPENGL_FORCE_SRGB_FRAMEBUFFER"
+
/**
* Mechanism to specify openvr_api library location
*
@@ -2859,6 +3241,24 @@ extern "C" {
*/
#define SDL_HINT_RENDER_DIRECT3D11_DEBUG "SDL_RENDER_DIRECT3D11_DEBUG"
+/**
+ * A variable controlling whether to use the Direct3D 11 WARP software
+ * rasterizer.
+ *
+ * For more information, see:
+ * https://learn.microsoft.com/en-us/windows/win32/direct3darticles/directx-warp
+ *
+ * The variable can be set to the following values:
+ *
+ * - "0": Disable WARP rasterizer. (default)
+ * - "1": Enable WARP rasterizer.
+ *
+ * This hint should be set before creating a renderer.
+ *
+ * \since This hint is available since SDL 3.4.0.
+ */
+#define SDL_HINT_RENDER_DIRECT3D11_WARP "SDL_RENDER_DIRECT3D11_WARP"
+
/**
* A variable controlling whether to enable Vulkan Validation Layers.
*
@@ -3041,6 +3441,49 @@ extern "C" {
*/
#define SDL_HINT_ROG_GAMEPAD_MICE_EXCLUDED "SDL_ROG_GAMEPAD_MICE_EXCLUDED"
+/**
+ * A variable controlling the width of the PS2's framebuffer in pixels.
+ *
+ * By default, the variable is "640".
+ *
+ * \since This hint is available since SDL 3.4.0.
+ */
+#define SDL_HINT_PS2_GS_WIDTH "SDL_PS2_GS_WIDTH"
+
+/**
+ * A variable controlling the height of the PS2's framebuffer in pixels.
+ *
+ * By default, the variable is "448".
+ *
+ * \since This hint is available since SDL 3.4.0.
+ */
+#define SDL_HINT_PS2_GS_HEIGHT "SDL_PS2_GS_HEIGHT"
+
+/**
+ * A variable controlling whether the signal is interlaced or progressive.
+ *
+ * The variable can be set to the following values:
+ *
+ * - "0": Image is interlaced. (default)
+ * - "1": Image is progressive.
+ *
+ * \since This hint is available since SDL 3.4.0.
+ */
+#define SDL_HINT_PS2_GS_PROGRESSIVE "SDL_PS2_GS_PROGRESSIVE"
+
+/**
+ * A variable controlling the video mode of the console.
+ *
+ * The variable can be set to the following values:
+ *
+ * - "": Console-native. (default)
+ * - "NTSC": 60hz region.
+ * - "PAL": 50hz region.
+ *
+ * \since This hint is available since SDL 3.4.0.
+ */
+#define SDL_HINT_PS2_GS_MODE "SDL_PS2_GS_MODE"
+
/**
* A variable controlling which Dispmanx layer to use on a Raspberry PI.
*
@@ -3267,10 +3710,12 @@ extern "C" {
* prioritized in the list of displays, as exposed by calling
* SDL_GetDisplays(), with the first listed becoming the primary display. The
* naming convention can vary depending on the environment, but it is usually
- * a connector name (e.g. 'DP-1', 'DP-2', 'HDMI-A-1',etc...).
+ * a connector name (e.g. 'DP-1', 'DP-2', 'HDMI-A-1', etc...).
*
- * On Wayland and X11 desktops, the connector names associated with displays
- * can typically be found by using the `xrandr` utility.
+ * On Wayland desktops, the connector names associated with displays can be
+ * found in the `name` property of the info output from `wayland-info -i
+ * wl_output`. On X11 desktops, the `xrandr` utility can be used to retrieve
+ * the connector names associated with displays.
*
* This hint is currently supported on the following drivers:
*
@@ -3407,6 +3852,43 @@ extern "C" {
*/
#define SDL_HINT_VIDEO_MAC_FULLSCREEN_MENU_VISIBILITY "SDL_VIDEO_MAC_FULLSCREEN_MENU_VISIBILITY"
+/**
+ * A variable indicating whether the metal layer drawable size should be
+ * updated for the SDL_EVENT_WINDOW_PIXEL_SIZE_CHANGED event on macOS.
+ *
+ * The variable can be set to the following values:
+ *
+ * - "0": the metal layer drawable size will not be updated on the
+ * SDL_EVENT_WINDOW_PIXEL_SIZE_CHANGED event.
+ * - "1": the metal layer drawable size will be updated on the
+ * SDL_EVENT_WINDOW_PIXEL_SIZE_CHANGED event. (default)
+ *
+ * This hint should be set before SDL_Metal_CreateView called.
+ *
+ * \since This hint is available since SDL 3.4.0.
+ */
+#define SDL_HINT_VIDEO_METAL_AUTO_RESIZE_DRAWABLE "SDL_VIDEO_METAL_AUTO_RESIZE_DRAWABLE"
+
+/**
+ * A variable controlling whether SDL will attempt to automatically set the
+ * destination display to a mode most closely matching that of the previous
+ * display if an exclusive fullscreen window is moved onto it.
+ *
+ * The variable can be set to the following values:
+ *
+ * - "0": SDL will not attempt to automatically set a matching mode on the
+ * destination display. If an exclusive fullscreen window is moved to a new
+ * display, the window will become fullscreen desktop.
+ * - "1": SDL will attempt to automatically set a mode on the destination
+ * display that most closely matches the mode of the display that the
+ * exclusive fullscreen window was previously on. (default)
+ *
+ * This hint can be set anytime.
+ *
+ * \since This hint is available since SDL 3.4.0.
+ */
+#define SDL_HINT_VIDEO_MATCH_EXCLUSIVE_MODE_ON_MOVE "SDL_VIDEO_MATCH_EXCLUSIVE_MODE_ON_MOVE"
+
/**
* A variable controlling whether fullscreen windows are minimized when they
* lose focus.
@@ -3414,8 +3896,10 @@ extern "C" {
* The variable can be set to the following values:
*
* - "0": Fullscreen windows will not be minimized when they lose focus.
- * (default)
* - "1": Fullscreen windows are minimized when they lose focus.
+ * - "auto": Fullscreen windows are minimized when they lose focus if they use
+ * exclusive fullscreen modes, so the desktop video mode is restored.
+ * (default)
*
* This hint can be set anytime.
*
@@ -3607,6 +4091,31 @@ extern "C" {
*/
#define SDL_HINT_VIDEO_WIN_D3DCOMPILER "SDL_VIDEO_WIN_D3DCOMPILER"
+/**
+ * A variable controlling whether the X Synchronization Extension is enabled.
+ *
+ * If set, this can result in smoother window resizing when rendering using
+ * OpenGL, however, there are some conditions:
+ *
+ * - It is only activated on windows created with the `SDL_WINDOW_OPENGL` flag
+ * (windows using an SDL OpenGL renderer have this automatically set).
+ * - When activated, presentation must be done with `SDL_GL_SwapWindow()`
+ * (`SDL_RenderPresent()` calls this internally for OpenGL renderers as well).
+ *
+ * Enabling this and presenting via an external mechanism will result in sync
+ * requests not being acked, and hangs and other odd window behavior may result.
+ *
+ * The variable can be set to the following values:
+ *
+ * - "0": The X Synchronization Extension is disabled. (default)
+ * - "1": The X Synchronization Extension is enabled.
+ *
+ * This hint should be set before creating a window.
+ *
+ * \since This hint is available since SDL 3.4.10.
+ */
+#define SDL_HINT_VIDEO_X11_ENABLE_XSYNC_EXT "SDL_VIDEO_X11_ENABLE_XSYNC_EXT"
+
/**
* A variable controlling whether SDL should call XSelectInput() to enable
* input events on X11 windows wrapped by SDL windows.
@@ -4061,15 +4570,14 @@ extern "C" {
*
* The variable can be set to the following values:
*
- * - "0": GameInput is not used for raw keyboard and mouse events.
+ * - "0": GameInput is not used for raw keyboard and mouse events. (default)
* - "1": GameInput is used for raw keyboard and mouse events, if available.
- * (default)
*
* This hint should be set before SDL is initialized.
*
* \since This hint is available since SDL 3.2.0.
*/
-#define SDL_HINT_WINDOWS_GAMEINPUT "SDL_WINDOWS_GAMEINPUT"
+#define SDL_HINT_WINDOWS_GAMEINPUT "SDL_WINDOWS_GAMEINPUT"
/**
* A variable controlling whether raw keyboard events are used on Windows.
@@ -4085,6 +4593,45 @@ extern "C" {
*/
#define SDL_HINT_WINDOWS_RAW_KEYBOARD "SDL_WINDOWS_RAW_KEYBOARD"
+/**
+ * A variable controlling whether or not the RIDEV_NOHOTKEYS flag is set when
+ * enabling Windows raw keyboard events.
+ *
+ * This blocks any hotkeys that have been registered by applications from
+ * having any effect beyond generating raw WM_INPUT events.
+ *
+ * This flag does not affect system-hotkeys like ALT-TAB or CTRL-ALT-DEL, but
+ * does affect the Windows Logo key since it is a userland hotkey registered
+ * by explorer.exe.
+ *
+ * The variable can be set to the following values:
+ *
+ * - "0": Hotkeys are not excluded. (default)
+ * - "1": Hotkeys are excluded.
+ *
+ * This hint can be set anytime.
+ *
+ * \since This hint is available since SDL 3.4.0.
+ */
+#define SDL_HINT_WINDOWS_RAW_KEYBOARD_EXCLUDE_HOTKEYS "SDL_WINDOWS_RAW_KEYBOARD_EXCLUDE_HOTKEYS"
+
+/**
+ * A variable controlling whether the RIDEV_INPUTSINK flag is set when
+ * enabling Windows raw keyboard events.
+ *
+ * This enables the window to still receive input even if not in foreground.
+ *
+ * Focused windows that receive text input will still prevent input events from triggering.
+ *
+ * - "0": Input is not received when not in focus or foreground. (default)
+ * - "1": Input will be received even when not in focus or foreground.
+ *
+ * This hint can be set anytime.
+ *
+ * \since This hint is available since SDL 3.4.4.
+ */
+#define SDL_HINT_WINDOWS_RAW_KEYBOARD_INPUTSINK "SDL_WINDOWS_RAW_KEYBOARD_INPUTSINK"
+
/**
* A variable controlling whether SDL uses Kernel Semaphores on Windows.
*
@@ -4114,7 +4661,7 @@ extern "C" {
*
* \since This hint is available since SDL 3.2.0.
*/
-#define SDL_HINT_WINDOWS_INTRESOURCE_ICON "SDL_WINDOWS_INTRESOURCE_ICON"
+#define SDL_HINT_WINDOWS_INTRESOURCE_ICON "SDL_WINDOWS_INTRESOURCE_ICON"
/**
* A variable to specify custom icon resource id from RC file on Windows
@@ -4287,7 +4834,6 @@ extern "C" {
*/
#define SDL_HINT_PEN_TOUCH_EVENTS "SDL_PEN_TOUCH_EVENTS"
-
/**
* An enumeration of hint priorities.
*
@@ -4386,19 +4932,14 @@ extern SDL_DECLSPEC void SDLCALL SDL_ResetHints(void);
* \param name the hint to query.
* \returns the string value of a hint or NULL if the hint isn't set.
*
- * \threadsafety It is safe to call this function from any thread, however the
- * return value only remains valid until the hint is changed; if
- * another thread might do so, the app should supply locks
- * and/or make a copy of the string. Note that using a hint
- * callback instead is always thread-safe, as SDL holds a lock
- * on the thread subsystem during the callback.
+ * \threadsafety It is safe to call this function from any thread.
*
* \since This function is available since SDL 3.2.0.
*
* \sa SDL_SetHint
* \sa SDL_SetHintWithPriority
*/
-extern SDL_DECLSPEC const char * SDLCALL SDL_GetHint(const char *name);
+extern SDL_DECLSPEC const char *SDLCALL SDL_GetHint(const char *name);
/**
* Get the boolean value of a hint variable.
@@ -4421,7 +4962,8 @@ extern SDL_DECLSPEC bool SDLCALL SDL_GetHintBoolean(const char *name, bool defau
* A callback used to send notifications of hint value changes.
*
* This is called an initial time during SDL_AddHintCallback with the hint's
- * current value, and then again each time the hint's value changes.
+ * current value, and then again each time the hint's value changes. In the
+ * initial call, the current value is in both `oldValue` and `newValue`.
*
* \param userdata what was passed as `userdata` to SDL_AddHintCallback().
* \param name what was passed as `name` to SDL_AddHintCallback().
@@ -4474,8 +5016,8 @@ extern SDL_DECLSPEC bool SDLCALL SDL_AddHintCallback(const char *name, SDL_HintC
* \sa SDL_AddHintCallback
*/
extern SDL_DECLSPEC void SDLCALL SDL_RemoveHintCallback(const char *name,
- SDL_HintCallback callback,
- void *userdata);
+ SDL_HintCallback callback,
+ void *userdata);
/* Ends C function definitions when using C++ */
#ifdef __cplusplus
diff --git a/thirdparty/sdl/include/SDL3/SDL_init.h b/thirdparty/sdl/include/SDL3/SDL_init.h
index 27ebe4b0ede..d75ccc31d70 100644
--- a/thirdparty/sdl/include/SDL3/SDL_init.h
+++ b/thirdparty/sdl/include/SDL3/SDL_init.h
@@ -1,6 +1,6 @@
/*
Simple DirectMedia Layer
- Copyright (C) 1997-2025 Sam Lantinga <[email protected]>
+ Copyright (C) 1997-2026 Sam Lantinga <[email protected]>
This software is provided 'as-is', without any express or implied
warranty. In no event will the authors be held liable for any damages
@@ -101,7 +101,7 @@ typedef Uint32 SDL_InitFlags;
* to run.
*
* See
- * [Main callbacks in SDL3](https://wiki.libsdl.org/SDL3/README/main-functions#main-callbacks-in-sdl3)
+ * [Main callbacks in SDL3](https://wiki.libsdl.org/SDL3/README-main-functions#main-callbacks-in-sdl3)
* for complete details.
*
* \since This enum is available since SDL 3.2.0.
@@ -224,6 +224,8 @@ typedef void (SDLCALL *SDL_AppQuit_func)(void *appstate, SDL_AppResult result);
* \returns true on success or false on failure; call SDL_GetError() for more
* information.
*
+ * \threadsafety This function should only be called on the main thread.
+ *
* \since This function is available since SDL 3.2.0.
*
* \sa SDL_SetAppMetadata
@@ -244,6 +246,8 @@ extern SDL_DECLSPEC bool SDLCALL SDL_Init(SDL_InitFlags flags);
* \returns true on success or false on failure; call SDL_GetError() for more
* information.
*
+ * \threadsafety This function should only be called on the main thread.
+ *
* \since This function is available since SDL 3.2.0.
*
* \sa SDL_Init
@@ -260,6 +264,8 @@ extern SDL_DECLSPEC bool SDLCALL SDL_InitSubSystem(SDL_InitFlags flags);
*
* \param flags any of the flags used by SDL_Init(); see SDL_Init for details.
*
+ * \threadsafety This function is not thread safe.
+ *
* \since This function is available since SDL 3.2.0.
*
* \sa SDL_InitSubSystem
@@ -274,6 +280,8 @@ extern SDL_DECLSPEC void SDLCALL SDL_QuitSubSystem(SDL_InitFlags flags);
* \returns a mask of all initialized subsystems if `flags` is 0, otherwise it
* returns the initialization status of the specified subsystems.
*
+ * \threadsafety This function is not thread safe.
+ *
* \since This function is available since SDL 3.2.0.
*
* \sa SDL_Init
@@ -292,6 +300,8 @@ extern SDL_DECLSPEC SDL_InitFlags SDLCALL SDL_WasInit(SDL_InitFlags flags);
* application is shutdown, but it is not wise to do this from a library or
* other dynamically loaded code.
*
+ * \threadsafety This function should only be called on the main thread.
+ *
* \since This function is available since SDL 3.2.0.
*
* \sa SDL_Init
diff --git a/thirdparty/sdl/include/SDL3/SDL_intrin.h b/thirdparty/sdl/include/SDL3/SDL_intrin.h
index c7338ee8f5e..a2e968080cf 100644
--- a/thirdparty/sdl/include/SDL3/SDL_intrin.h
+++ b/thirdparty/sdl/include/SDL3/SDL_intrin.h
@@ -1,6 +1,6 @@
/*
Simple DirectMedia Layer
- Copyright (C) 1997-2025 Sam Lantinga <[email protected]>
+ Copyright (C) 1997-2026 Sam Lantinga <[email protected]>
This software is provided 'as-is', without any express or implied
warranty. In no event will the authors be held liable for any damages
@@ -217,9 +217,9 @@
/* Need to do this here because intrin.h has C++ code in it */
/* Visual Studio 2005 has a bug where intrin.h conflicts with winnt.h */
#if defined(_MSC_VER) && (_MSC_VER >= 1500) && (defined(_M_IX86) || defined(_M_X64))
-#ifdef __clang__
/* As of Clang 11, '_m_prefetchw' is conflicting with the winnt.h's version,
so we define the needed '_m_prefetch' here as a pseudo-header, until the issue is fixed. */
+#if defined(__clang__) && !SDL_HAS_BUILTIN(_m_prefetch)
#ifndef __PRFCHWINTRIN_H
#define __PRFCHWINTRIN_H
static __inline__ void __attribute__((__always_inline__, __nodebug__))
@@ -268,6 +268,7 @@ _m_prefetch(void *__P)
#endif /* compiler version */
#ifdef SDL_WIKI_DOCUMENTATION_SECTION
+
/**
* A macro to decide if the compiler supports `__attribute__((target))`.
*
diff --git a/thirdparty/sdl/include/SDL3/SDL_iostream.h b/thirdparty/sdl/include/SDL3/SDL_iostream.h
index 4ca16093e52..f369fde17fd 100644
--- a/thirdparty/sdl/include/SDL3/SDL_iostream.h
+++ b/thirdparty/sdl/include/SDL3/SDL_iostream.h
@@ -1,6 +1,6 @@
/*
Simple DirectMedia Layer
- Copyright (C) 1997-2025 Sam Lantinga <[email protected]>
+ Copyright (C) 1997-2026 Sam Lantinga <[email protected]>
This software is provided 'as-is', without any express or implied
warranty. In no event will the authors be held liable for any damages
@@ -111,7 +111,7 @@ typedef struct SDL_IOStreamInterface
/**
* Read up to `size` bytes from the data stream to the area pointed
- * at by `ptr`.
+ * at by `ptr`. `size` will always be > 0.
*
* On an incomplete read, you should set `*status` to a value from the
* SDL_IOStatus enum. You do not have to explicitly set this on
@@ -123,7 +123,7 @@ typedef struct SDL_IOStreamInterface
/**
* Write exactly `size` bytes from the area pointed at by `ptr`
- * to data stream.
+ * to data stream. `size` will always be > 0.
*
* On an incomplete write, you should set `*status` to a value from the
* SDL_IOStatus enum. You do not have to explicitly set this on
@@ -203,6 +203,8 @@ typedef struct SDL_IOStream SDL_IOStream;
* - "w": Create an empty file for writing. If a file with the same name
* already exists its content is erased and the file is treated as a new
* empty file.
+ * - "wx": Create an empty file for writing. If a file with the same name
+ * already exists, the call fails.
* - "a": Append to a file. Writing operations append data at the end of the
* file. The file is created if it does not exist.
* - "r+": Open a file for update both reading and writing. The file must
@@ -210,6 +212,8 @@ typedef struct SDL_IOStream SDL_IOStream;
* - "w+": Create an empty file for both reading and writing. If a file with
* the same name already exists its content is erased and the file is
* treated as a new empty file.
+ * - "w+x": Create an empty file for both reading and writing. If a file with
+ * the same name already exists, the call fails.
* - "a+": Open a file for reading and appending. All writing operations are
* performed at the end of the file, protecting the previous content to be
* overwritten. You can reposition (fseek, rewind) the internal pointer to
@@ -260,7 +264,7 @@ typedef struct SDL_IOStream SDL_IOStream;
* \returns a pointer to the SDL_IOStream structure that is created or NULL on
* failure; call SDL_GetError() for more information.
*
- * \threadsafety This function is not thread safe.
+ * \threadsafety It is safe to call this function from any thread.
*
* \since This function is available since SDL 3.2.0.
*
@@ -286,8 +290,7 @@ extern SDL_DECLSPEC SDL_IOStream * SDLCALL SDL_IOFromFile(const char *file, cons
* certain size, for both read and write access.
*
* This memory buffer is not copied by the SDL_IOStream; the pointer you
- * provide must remain valid until you close the stream. Closing the stream
- * will not free the original buffer.
+ * provide must remain valid until you close the stream.
*
* If you need to make sure the SDL_IOStream never writes to the memory
* buffer, you should use SDL_IOFromConstMem() with a read-only buffer of
@@ -300,6 +303,13 @@ extern SDL_DECLSPEC SDL_IOStream * SDLCALL SDL_IOFromFile(const char *file, cons
* - `SDL_PROP_IOSTREAM_MEMORY_SIZE_NUMBER`: this will be the `size` parameter
* that was passed to this function.
*
+ * Additionally, the following properties are recognized:
+ *
+ * - `SDL_PROP_IOSTREAM_MEMORY_FREE_FUNC_POINTER`: if this property is set to
+ * a non-NULL value it will be interpreted as a function of SDL_free_func
+ * type and called with the passed `mem` pointer when closing the stream. By
+ * default it is unset, i.e., the memory will not be freed.
+ *
* \param mem a pointer to a buffer to feed an SDL_IOStream stream.
* \param size the buffer size, in bytes.
* \returns a pointer to a new SDL_IOStream structure or NULL on failure; call
@@ -321,6 +331,7 @@ extern SDL_DECLSPEC SDL_IOStream * SDLCALL SDL_IOFromMem(void *mem, size_t size)
#define SDL_PROP_IOSTREAM_MEMORY_POINTER "SDL.iostream.memory.base"
#define SDL_PROP_IOSTREAM_MEMORY_SIZE_NUMBER "SDL.iostream.memory.size"
+#define SDL_PROP_IOSTREAM_MEMORY_FREE_FUNC_POINTER "SDL.iostream.memory.free"
/**
* Use this function to prepare a read-only memory buffer for use with
@@ -333,8 +344,7 @@ extern SDL_DECLSPEC SDL_IOStream * SDLCALL SDL_IOFromMem(void *mem, size_t size)
* without writing to the memory buffer.
*
* This memory buffer is not copied by the SDL_IOStream; the pointer you
- * provide must remain valid until you close the stream. Closing the stream
- * will not free the original buffer.
+ * provide must remain valid until you close the stream.
*
* If you need to write to a memory buffer, you should use SDL_IOFromMem()
* with a writable buffer of memory instead.
@@ -346,6 +356,13 @@ extern SDL_DECLSPEC SDL_IOStream * SDLCALL SDL_IOFromMem(void *mem, size_t size)
* - `SDL_PROP_IOSTREAM_MEMORY_SIZE_NUMBER`: this will be the `size` parameter
* that was passed to this function.
*
+ * Additionally, the following properties are recognized:
+ *
+ * - `SDL_PROP_IOSTREAM_MEMORY_FREE_FUNC_POINTER`: if this property is set to
+ * a non-NULL value it will be interpreted as a function of SDL_free_func
+ * type and called with the passed `mem` pointer when closing the stream. By
+ * default it is unset, i.e., the memory will not be freed.
+ *
* \param mem a pointer to a read-only buffer to feed an SDL_IOStream stream.
* \param size the buffer size, in bytes.
* \returns a pointer to a new SDL_IOStream structure or NULL on failure; call
@@ -452,7 +469,7 @@ extern SDL_DECLSPEC SDL_IOStream * SDLCALL SDL_OpenIO(const SDL_IOStreamInterfac
* \returns true on success or false on failure; call SDL_GetError() for more
* information.
*
- * \threadsafety This function is not thread safe.
+ * \threadsafety Do not use the same SDL_IOStream from two threads at once.
*
* \since This function is available since SDL 3.2.0.
*
@@ -467,7 +484,7 @@ extern SDL_DECLSPEC bool SDLCALL SDL_CloseIO(SDL_IOStream *context);
* \returns a valid property ID on success or 0 on failure; call
* SDL_GetError() for more information.
*
- * \threadsafety This function is not thread safe.
+ * \threadsafety Do not use the same SDL_IOStream from two threads at once.
*
* \since This function is available since SDL 3.2.0.
*/
@@ -487,7 +504,7 @@ extern SDL_DECLSPEC SDL_PropertiesID SDLCALL SDL_GetIOProperties(SDL_IOStream *c
* \param context the SDL_IOStream to query.
* \returns an SDL_IOStatus enum with the current state.
*
- * \threadsafety This function is not thread safe.
+ * \threadsafety Do not use the same SDL_IOStream from two threads at once.
*
* \since This function is available since SDL 3.2.0.
*/
@@ -501,7 +518,7 @@ extern SDL_DECLSPEC SDL_IOStatus SDLCALL SDL_GetIOStatus(SDL_IOStream *context);
* negative error code on failure; call SDL_GetError() for more
* information.
*
- * \threadsafety This function is not thread safe.
+ * \threadsafety Do not use the same SDL_IOStream from two threads at once.
*
* \since This function is available since SDL 3.2.0.
*/
@@ -528,7 +545,7 @@ extern SDL_DECLSPEC Sint64 SDLCALL SDL_GetIOSize(SDL_IOStream *context);
* \returns the final offset in the data stream after the seek or -1 on
* failure; call SDL_GetError() for more information.
*
- * \threadsafety This function is not thread safe.
+ * \threadsafety Do not use the same SDL_IOStream from two threads at once.
*
* \since This function is available since SDL 3.2.0.
*
@@ -548,7 +565,7 @@ extern SDL_DECLSPEC Sint64 SDLCALL SDL_SeekIO(SDL_IOStream *context, Sint64 offs
* \returns the current offset in the stream, or -1 if the information can not
* be determined.
*
- * \threadsafety This function is not thread safe.
+ * \threadsafety Do not use the same SDL_IOStream from two threads at once.
*
* \since This function is available since SDL 3.2.0.
*
@@ -567,13 +584,17 @@ extern SDL_DECLSPEC Sint64 SDLCALL SDL_TellIO(SDL_IOStream *context);
* the stream is not at EOF, SDL_GetIOStatus() will return a different error
* value and SDL_GetError() will offer a human-readable message.
*
+ * A request for zero bytes on a valid stream will return zero immediately
+ * without accessing the stream, so the stream status (EOF, err, etc) will not
+ * change.
+ *
* \param context a pointer to an SDL_IOStream structure.
* \param ptr a pointer to a buffer to read data into.
* \param size the number of bytes to read from the data source.
* \returns the number of bytes read, or 0 on end of file or other failure;
* call SDL_GetError() for more information.
*
- * \threadsafety This function is not thread safe.
+ * \threadsafety Do not use the same SDL_IOStream from two threads at once.
*
* \since This function is available since SDL 3.2.0.
*
@@ -596,13 +617,17 @@ extern SDL_DECLSPEC size_t SDLCALL SDL_ReadIO(SDL_IOStream *context, void *ptr,
* recoverable, such as a non-blocking write that can simply be retried later,
* or a fatal error.
*
+ * A request for zero bytes on a valid stream will return zero immediately
+ * without accessing the stream, so the stream status (EOF, err, etc) will not
+ * change.
+ *
* \param context a pointer to an SDL_IOStream structure.
* \param ptr a pointer to a buffer containing data to write.
* \param size the number of bytes to write.
* \returns the number of bytes written, which will be less than `size` on
* failure; call SDL_GetError() for more information.
*
- * \threadsafety This function is not thread safe.
+ * \threadsafety Do not use the same SDL_IOStream from two threads at once.
*
* \since This function is available since SDL 3.2.0.
*
@@ -626,7 +651,7 @@ extern SDL_DECLSPEC size_t SDLCALL SDL_WriteIO(SDL_IOStream *context, const void
* \returns the number of bytes written or 0 on failure; call SDL_GetError()
* for more information.
*
- * \threadsafety This function is not thread safe.
+ * \threadsafety Do not use the same SDL_IOStream from two threads at once.
*
* \since This function is available since SDL 3.2.0.
*
@@ -646,7 +671,7 @@ extern SDL_DECLSPEC size_t SDLCALL SDL_IOprintf(SDL_IOStream *context, SDL_PRINT
* \returns the number of bytes written or 0 on failure; call SDL_GetError()
* for more information.
*
- * \threadsafety This function is not thread safe.
+ * \threadsafety Do not use the same SDL_IOStream from two threads at once.
*
* \since This function is available since SDL 3.2.0.
*
@@ -666,7 +691,7 @@ extern SDL_DECLSPEC size_t SDLCALL SDL_IOvprintf(SDL_IOStream *context, SDL_PRIN
* \returns true on success or false on failure; call SDL_GetError() for more
* information.
*
- * \threadsafety This function is not thread safe.
+ * \threadsafety Do not use the same SDL_IOStream from two threads at once.
*
* \since This function is available since SDL 3.2.0.
*
@@ -692,7 +717,7 @@ extern SDL_DECLSPEC bool SDLCALL SDL_FlushIO(SDL_IOStream *context);
* \returns the data or NULL on failure; call SDL_GetError() for more
* information.
*
- * \threadsafety This function is not thread safe.
+ * \threadsafety Do not use the same SDL_IOStream from two threads at once.
*
* \since This function is available since SDL 3.2.0.
*
@@ -715,7 +740,7 @@ extern SDL_DECLSPEC void * SDLCALL SDL_LoadFile_IO(SDL_IOStream *src, size_t *da
* \returns the data or NULL on failure; call SDL_GetError() for more
* information.
*
- * \threadsafety This function is not thread safe.
+ * \threadsafety It is safe to call this function from any thread.
*
* \since This function is available since SDL 3.2.0.
*
@@ -736,7 +761,7 @@ extern SDL_DECLSPEC void * SDLCALL SDL_LoadFile(const char *file, size_t *datasi
* \returns true on success or false on failure; call SDL_GetError() for more
* information.
*
- * \threadsafety This function is not thread safe.
+ * \threadsafety Do not use the same SDL_IOStream from two threads at once.
*
* \since This function is available since SDL 3.2.0.
*
@@ -755,7 +780,7 @@ extern SDL_DECLSPEC bool SDLCALL SDL_SaveFile_IO(SDL_IOStream *src, const void *
* \returns true on success or false on failure; call SDL_GetError() for more
* information.
*
- * \threadsafety This function is not thread safe.
+ * \threadsafety It is safe to call this function from any thread.
*
* \since This function is available since SDL 3.2.0.
*
@@ -784,7 +809,7 @@ extern SDL_DECLSPEC bool SDLCALL SDL_SaveFile(const char *file, const void *data
* \returns true on success or false on failure or EOF; call SDL_GetError()
* for more information.
*
- * \threadsafety This function is not thread safe.
+ * \threadsafety Do not use the same SDL_IOStream from two threads at once.
*
* \since This function is available since SDL 3.2.0.
*/
@@ -803,7 +828,7 @@ extern SDL_DECLSPEC bool SDLCALL SDL_ReadU8(SDL_IOStream *src, Uint8 *value);
* \returns true on success or false on failure; call SDL_GetError() for more
* information.
*
- * \threadsafety This function is not thread safe.
+ * \threadsafety Do not use the same SDL_IOStream from two threads at once.
*
* \since This function is available since SDL 3.2.0.
*/
@@ -823,10 +848,10 @@ extern SDL_DECLSPEC bool SDLCALL SDL_ReadS8(SDL_IOStream *src, Sint8 *value);
*
* \param src the stream from which to read data.
* \param value a pointer filled in with the data read.
- * \returns true on successful write or false on failure; call SDL_GetError()
+ * \returns true on successful read or false on failure; call SDL_GetError()
* for more information.
*
- * \threadsafety This function is not thread safe.
+ * \threadsafety Do not use the same SDL_IOStream from two threads at once.
*
* \since This function is available since SDL 3.2.0.
*/
@@ -846,10 +871,10 @@ extern SDL_DECLSPEC bool SDLCALL SDL_ReadU16LE(SDL_IOStream *src, Uint16 *value)
*
* \param src the stream from which to read data.
* \param value a pointer filled in with the data read.
- * \returns true on successful write or false on failure; call SDL_GetError()
+ * \returns true on successful read or false on failure; call SDL_GetError()
* for more information.
*
- * \threadsafety This function is not thread safe.
+ * \threadsafety Do not use the same SDL_IOStream from two threads at once.
*
* \since This function is available since SDL 3.2.0.
*/
@@ -869,10 +894,10 @@ extern SDL_DECLSPEC bool SDLCALL SDL_ReadS16LE(SDL_IOStream *src, Sint16 *value)
*
* \param src the stream from which to read data.
* \param value a pointer filled in with the data read.
- * \returns true on successful write or false on failure; call SDL_GetError()
+ * \returns true on successful read or false on failure; call SDL_GetError()
* for more information.
*
- * \threadsafety This function is not thread safe.
+ * \threadsafety Do not use the same SDL_IOStream from two threads at once.
*
* \since This function is available since SDL 3.2.0.
*/
@@ -892,10 +917,10 @@ extern SDL_DECLSPEC bool SDLCALL SDL_ReadU16BE(SDL_IOStream *src, Uint16 *value)
*
* \param src the stream from which to read data.
* \param value a pointer filled in with the data read.
- * \returns true on successful write or false on failure; call SDL_GetError()
+ * \returns true on successful read or false on failure; call SDL_GetError()
* for more information.
*
- * \threadsafety This function is not thread safe.
+ * \threadsafety Do not use the same SDL_IOStream from two threads at once.
*
* \since This function is available since SDL 3.2.0.
*/
@@ -915,10 +940,10 @@ extern SDL_DECLSPEC bool SDLCALL SDL_ReadS16BE(SDL_IOStream *src, Sint16 *value)
*
* \param src the stream from which to read data.
* \param value a pointer filled in with the data read.
- * \returns true on successful write or false on failure; call SDL_GetError()
+ * \returns true on successful read or false on failure; call SDL_GetError()
* for more information.
*
- * \threadsafety This function is not thread safe.
+ * \threadsafety Do not use the same SDL_IOStream from two threads at once.
*
* \since This function is available since SDL 3.2.0.
*/
@@ -938,10 +963,10 @@ extern SDL_DECLSPEC bool SDLCALL SDL_ReadU32LE(SDL_IOStream *src, Uint32 *value)
*
* \param src the stream from which to read data.
* \param value a pointer filled in with the data read.
- * \returns true on successful write or false on failure; call SDL_GetError()
+ * \returns true on successful read or false on failure; call SDL_GetError()
* for more information.
*
- * \threadsafety This function is not thread safe.
+ * \threadsafety Do not use the same SDL_IOStream from two threads at once.
*
* \since This function is available since SDL 3.2.0.
*/
@@ -961,10 +986,10 @@ extern SDL_DECLSPEC bool SDLCALL SDL_ReadS32LE(SDL_IOStream *src, Sint32 *value)
*
* \param src the stream from which to read data.
* \param value a pointer filled in with the data read.
- * \returns true on successful write or false on failure; call SDL_GetError()
+ * \returns true on successful read or false on failure; call SDL_GetError()
* for more information.
*
- * \threadsafety This function is not thread safe.
+ * \threadsafety Do not use the same SDL_IOStream from two threads at once.
*
* \since This function is available since SDL 3.2.0.
*/
@@ -984,10 +1009,10 @@ extern SDL_DECLSPEC bool SDLCALL SDL_ReadU32BE(SDL_IOStream *src, Uint32 *value)
*
* \param src the stream from which to read data.
* \param value a pointer filled in with the data read.
- * \returns true on successful write or false on failure; call SDL_GetError()
+ * \returns true on successful read or false on failure; call SDL_GetError()
* for more information.
*
- * \threadsafety This function is not thread safe.
+ * \threadsafety Do not use the same SDL_IOStream from two threads at once.
*
* \since This function is available since SDL 3.2.0.
*/
@@ -1007,10 +1032,10 @@ extern SDL_DECLSPEC bool SDLCALL SDL_ReadS32BE(SDL_IOStream *src, Sint32 *value)
*
* \param src the stream from which to read data.
* \param value a pointer filled in with the data read.
- * \returns true on successful write or false on failure; call SDL_GetError()
+ * \returns true on successful read or false on failure; call SDL_GetError()
* for more information.
*
- * \threadsafety This function is not thread safe.
+ * \threadsafety Do not use the same SDL_IOStream from two threads at once.
*
* \since This function is available since SDL 3.2.0.
*/
@@ -1030,10 +1055,10 @@ extern SDL_DECLSPEC bool SDLCALL SDL_ReadU64LE(SDL_IOStream *src, Uint64 *value)
*
* \param src the stream from which to read data.
* \param value a pointer filled in with the data read.
- * \returns true on successful write or false on failure; call SDL_GetError()
+ * \returns true on successful read or false on failure; call SDL_GetError()
* for more information.
*
- * \threadsafety This function is not thread safe.
+ * \threadsafety Do not use the same SDL_IOStream from two threads at once.
*
* \since This function is available since SDL 3.2.0.
*/
@@ -1053,10 +1078,10 @@ extern SDL_DECLSPEC bool SDLCALL SDL_ReadS64LE(SDL_IOStream *src, Sint64 *value)
*
* \param src the stream from which to read data.
* \param value a pointer filled in with the data read.
- * \returns true on successful write or false on failure; call SDL_GetError()
+ * \returns true on successful read or false on failure; call SDL_GetError()
* for more information.
*
- * \threadsafety This function is not thread safe.
+ * \threadsafety Do not use the same SDL_IOStream from two threads at once.
*
* \since This function is available since SDL 3.2.0.
*/
@@ -1076,10 +1101,10 @@ extern SDL_DECLSPEC bool SDLCALL SDL_ReadU64BE(SDL_IOStream *src, Uint64 *value)
*
* \param src the stream from which to read data.
* \param value a pointer filled in with the data read.
- * \returns true on successful write or false on failure; call SDL_GetError()
+ * \returns true on successful read or false on failure; call SDL_GetError()
* for more information.
*
- * \threadsafety This function is not thread safe.
+ * \threadsafety Do not use the same SDL_IOStream from two threads at once.
*
* \since This function is available since SDL 3.2.0.
*/
@@ -1101,7 +1126,7 @@ extern SDL_DECLSPEC bool SDLCALL SDL_ReadS64BE(SDL_IOStream *src, Sint64 *value)
* \returns true on successful write or false on failure; call SDL_GetError()
* for more information.
*
- * \threadsafety This function is not thread safe.
+ * \threadsafety Do not use the same SDL_IOStream from two threads at once.
*
* \since This function is available since SDL 3.2.0.
*/
@@ -1115,7 +1140,7 @@ extern SDL_DECLSPEC bool SDLCALL SDL_WriteU8(SDL_IOStream *dst, Uint8 value);
* \returns true on successful write or false on failure; call SDL_GetError()
* for more information.
*
- * \threadsafety This function is not thread safe.
+ * \threadsafety Do not use the same SDL_IOStream from two threads at once.
*
* \since This function is available since SDL 3.2.0.
*/
@@ -1134,7 +1159,7 @@ extern SDL_DECLSPEC bool SDLCALL SDL_WriteS8(SDL_IOStream *dst, Sint8 value);
* \returns true on successful write or false on failure; call SDL_GetError()
* for more information.
*
- * \threadsafety This function is not thread safe.
+ * \threadsafety Do not use the same SDL_IOStream from two threads at once.
*
* \since This function is available since SDL 3.2.0.
*/
@@ -1153,7 +1178,7 @@ extern SDL_DECLSPEC bool SDLCALL SDL_WriteU16LE(SDL_IOStream *dst, Uint16 value)
* \returns true on successful write or false on failure; call SDL_GetError()
* for more information.
*
- * \threadsafety This function is not thread safe.
+ * \threadsafety Do not use the same SDL_IOStream from two threads at once.
*
* \since This function is available since SDL 3.2.0.
*/
@@ -1171,7 +1196,7 @@ extern SDL_DECLSPEC bool SDLCALL SDL_WriteS16LE(SDL_IOStream *dst, Sint16 value)
* \returns true on successful write or false on failure; call SDL_GetError()
* for more information.
*
- * \threadsafety This function is not thread safe.
+ * \threadsafety Do not use the same SDL_IOStream from two threads at once.
*
* \since This function is available since SDL 3.2.0.
*/
@@ -1189,7 +1214,7 @@ extern SDL_DECLSPEC bool SDLCALL SDL_WriteU16BE(SDL_IOStream *dst, Uint16 value)
* \returns true on successful write or false on failure; call SDL_GetError()
* for more information.
*
- * \threadsafety This function is not thread safe.
+ * \threadsafety Do not use the same SDL_IOStream from two threads at once.
*
* \since This function is available since SDL 3.2.0.
*/
@@ -1208,7 +1233,7 @@ extern SDL_DECLSPEC bool SDLCALL SDL_WriteS16BE(SDL_IOStream *dst, Sint16 value)
* \returns true on successful write or false on failure; call SDL_GetError()
* for more information.
*
- * \threadsafety This function is not thread safe.
+ * \threadsafety Do not use the same SDL_IOStream from two threads at once.
*
* \since This function is available since SDL 3.2.0.
*/
@@ -1227,7 +1252,7 @@ extern SDL_DECLSPEC bool SDLCALL SDL_WriteU32LE(SDL_IOStream *dst, Uint32 value)
* \returns true on successful write or false on failure; call SDL_GetError()
* for more information.
*
- * \threadsafety This function is not thread safe.
+ * \threadsafety Do not use the same SDL_IOStream from two threads at once.
*
* \since This function is available since SDL 3.2.0.
*/
@@ -1245,7 +1270,7 @@ extern SDL_DECLSPEC bool SDLCALL SDL_WriteS32LE(SDL_IOStream *dst, Sint32 value)
* \returns true on successful write or false on failure; call SDL_GetError()
* for more information.
*
- * \threadsafety This function is not thread safe.
+ * \threadsafety Do not use the same SDL_IOStream from two threads at once.
*
* \since This function is available since SDL 3.2.0.
*/
@@ -1263,7 +1288,7 @@ extern SDL_DECLSPEC bool SDLCALL SDL_WriteU32BE(SDL_IOStream *dst, Uint32 value)
* \returns true on successful write or false on failure; call SDL_GetError()
* for more information.
*
- * \threadsafety This function is not thread safe.
+ * \threadsafety Do not use the same SDL_IOStream from two threads at once.
*
* \since This function is available since SDL 3.2.0.
*/
@@ -1282,7 +1307,7 @@ extern SDL_DECLSPEC bool SDLCALL SDL_WriteS32BE(SDL_IOStream *dst, Sint32 value)
* \returns true on successful write or false on failure; call SDL_GetError()
* for more information.
*
- * \threadsafety This function is not thread safe.
+ * \threadsafety Do not use the same SDL_IOStream from two threads at once.
*
* \since This function is available since SDL 3.2.0.
*/
@@ -1301,7 +1326,7 @@ extern SDL_DECLSPEC bool SDLCALL SDL_WriteU64LE(SDL_IOStream *dst, Uint64 value)
* \returns true on successful write or false on failure; call SDL_GetError()
* for more information.
*
- * \threadsafety This function is not thread safe.
+ * \threadsafety Do not use the same SDL_IOStream from two threads at once.
*
* \since This function is available since SDL 3.2.0.
*/
@@ -1319,7 +1344,7 @@ extern SDL_DECLSPEC bool SDLCALL SDL_WriteS64LE(SDL_IOStream *dst, Sint64 value)
* \returns true on successful write or false on failure; call SDL_GetError()
* for more information.
*
- * \threadsafety This function is not thread safe.
+ * \threadsafety Do not use the same SDL_IOStream from two threads at once.
*
* \since This function is available since SDL 3.2.0.
*/
@@ -1337,7 +1362,7 @@ extern SDL_DECLSPEC bool SDLCALL SDL_WriteU64BE(SDL_IOStream *dst, Uint64 value)
* \returns true on successful write or false on failure; call SDL_GetError()
* for more information.
*
- * \threadsafety This function is not thread safe.
+ * \threadsafety Do not use the same SDL_IOStream from two threads at once.
*
* \since This function is available since SDL 3.2.0.
*/
diff --git a/thirdparty/sdl/include/SDL3/SDL_joystick.h b/thirdparty/sdl/include/SDL3/SDL_joystick.h
index d15668b66ac..c93b3521074 100644
--- a/thirdparty/sdl/include/SDL3/SDL_joystick.h
+++ b/thirdparty/sdl/include/SDL3/SDL_joystick.h
@@ -1,6 +1,6 @@
/*
Simple DirectMedia Layer
- Copyright (C) 1997-2025 Sam Lantinga <[email protected]>
+ Copyright (C) 1997-2026 Sam Lantinga <[email protected]>
This software is provided 'as-is', without any express or implied
warranty. In no event will the authors be held liable for any damages
@@ -29,8 +29,8 @@
* instead.
*
* The term "instance_id" is the current instantiation of a joystick device in
- * the system, if the joystick is removed and then re-inserted then it will
- * get a new instance_id, instance_id's are monotonically increasing
+ * the system. If the joystick is removed and then re-inserted then it will
+ * get a new instance_id. instance_id's are monotonically increasing
* identifiers of a joystick plugged in.
*
* The term "player_index" is the number assigned to a player on a specific
@@ -48,6 +48,14 @@
* If you would like to receive joystick updates while the application is in
* the background, you should set the following hint before calling
* SDL_Init(): SDL_HINT_JOYSTICK_ALLOW_BACKGROUND_EVENTS
+ *
+ * SDL can provide virtual joysticks as well: the app defines an imaginary
+ * controller with SDL_AttachVirtualJoystick(), and then can provide inputs
+ * for it via SDL_SetJoystickVirtualAxis(), SDL_SetJoystickVirtualButton(),
+ * etc. As this data is supplied, it will look like a normal joystick to SDL,
+ * just not backed by a hardware driver. This has been used to make unusual
+ * devices, like VR headset controllers, look like normal joysticks, or
+ * provide recording/playback of game inputs, etc.
*/
#ifndef SDL_joystick_h_
@@ -107,6 +115,10 @@ typedef Uint32 SDL_JoystickID;
* This is by no means a complete list of everything that can be plugged into
* a computer.
*
+ * You may refer to
+ * [XInput Controller Types](https://learn.microsoft.com/en-us/windows/win32/xinput/xinput-and-controller-subtypes)
+ * table for a general understanding of each joystick type.
+ *
* \since This enum is available since SDL 3.2.0.
*/
typedef enum SDL_JoystickType
@@ -170,6 +182,8 @@ typedef enum SDL_JoystickConnectionState
* joysticks while processing to guarantee that the joystick list won't change
* and joystick and gamepad events will not be delivered.
*
+ * \threadsafety It is safe to call this function from any thread.
+ *
* \since This function is available since SDL 3.2.0.
*/
extern SDL_DECLSPEC void SDLCALL SDL_LockJoysticks(void) SDL_ACQUIRE(SDL_joystick_lock);
@@ -177,6 +191,9 @@ extern SDL_DECLSPEC void SDLCALL SDL_LockJoysticks(void) SDL_ACQUIRE(SDL_joystic
/**
* Unlocking for atomic access to the joystick API.
*
+ * \threadsafety This should be called from the same thread that called
+ * SDL_LockJoysticks().
+ *
* \since This function is available since SDL 3.2.0.
*/
extern SDL_DECLSPEC void SDLCALL SDL_UnlockJoysticks(void) SDL_RELEASE(SDL_joystick_lock);
@@ -186,6 +203,8 @@ extern SDL_DECLSPEC void SDLCALL SDL_UnlockJoysticks(void) SDL_RELEASE(SDL_joyst
*
* \returns true if a joystick is connected, false otherwise.
*
+ * \threadsafety It is safe to call this function from any thread.
+ *
* \since This function is available since SDL 3.2.0.
*
* \sa SDL_GetJoysticks
@@ -201,6 +220,8 @@ extern SDL_DECLSPEC bool SDLCALL SDL_HasJoystick(void);
* call SDL_GetError() for more information. This should be freed
* with SDL_free() when it is no longer needed.
*
+ * \threadsafety It is safe to call this function from any thread.
+ *
* \since This function is available since SDL 3.2.0.
*
* \sa SDL_HasJoystick
@@ -217,6 +238,8 @@ extern SDL_DECLSPEC SDL_JoystickID * SDLCALL SDL_GetJoysticks(int *count);
* \returns the name of the selected joystick. If no name can be found, this
* function returns NULL; call SDL_GetError() for more information.
*
+ * \threadsafety It is safe to call this function from any thread.
+ *
* \since This function is available since SDL 3.2.0.
*
* \sa SDL_GetJoystickName
@@ -233,6 +256,8 @@ extern SDL_DECLSPEC const char * SDLCALL SDL_GetJoystickNameForID(SDL_JoystickID
* \returns the path of the selected joystick. If no path can be found, this
* function returns NULL; call SDL_GetError() for more information.
*
+ * \threadsafety It is safe to call this function from any thread.
+ *
* \since This function is available since SDL 3.2.0.
*
* \sa SDL_GetJoystickPath
@@ -248,6 +273,8 @@ extern SDL_DECLSPEC const char * SDLCALL SDL_GetJoystickPathForID(SDL_JoystickID
* \param instance_id the joystick instance ID.
* \returns the player index of a joystick, or -1 if it's not available.
*
+ * \threadsafety It is safe to call this function from any thread.
+ *
* \since This function is available since SDL 3.2.0.
*
* \sa SDL_GetJoystickPlayerIndex
@@ -264,6 +291,8 @@ extern SDL_DECLSPEC int SDLCALL SDL_GetJoystickPlayerIndexForID(SDL_JoystickID i
* \returns the GUID of the selected joystick. If called with an invalid
* instance_id, this function returns a zero GUID.
*
+ * \threadsafety It is safe to call this function from any thread.
+ *
* \since This function is available since SDL 3.2.0.
*
* \sa SDL_GetJoystickGUID
@@ -281,6 +310,8 @@ extern SDL_DECLSPEC SDL_GUID SDLCALL SDL_GetJoystickGUIDForID(SDL_JoystickID ins
* \returns the USB vendor ID of the selected joystick. If called with an
* invalid instance_id, this function returns 0.
*
+ * \threadsafety It is safe to call this function from any thread.
+ *
* \since This function is available since SDL 3.2.0.
*
* \sa SDL_GetJoystickVendor
@@ -298,6 +329,8 @@ extern SDL_DECLSPEC Uint16 SDLCALL SDL_GetJoystickVendorForID(SDL_JoystickID ins
* \returns the USB product ID of the selected joystick. If called with an
* invalid instance_id, this function returns 0.
*
+ * \threadsafety It is safe to call this function from any thread.
+ *
* \since This function is available since SDL 3.2.0.
*
* \sa SDL_GetJoystickProduct
@@ -315,6 +348,8 @@ extern SDL_DECLSPEC Uint16 SDLCALL SDL_GetJoystickProductForID(SDL_JoystickID in
* \returns the product version of the selected joystick. If called with an
* invalid instance_id, this function returns 0.
*
+ * \threadsafety It is safe to call this function from any thread.
+ *
* \since This function is available since SDL 3.2.0.
*
* \sa SDL_GetJoystickProductVersion
@@ -332,6 +367,8 @@ extern SDL_DECLSPEC Uint16 SDLCALL SDL_GetJoystickProductVersionForID(SDL_Joysti
* invalid instance_id, this function returns
* `SDL_JOYSTICK_TYPE_UNKNOWN`.
*
+ * \threadsafety It is safe to call this function from any thread.
+ *
* \since This function is available since SDL 3.2.0.
*
* \sa SDL_GetJoystickType
@@ -349,6 +386,8 @@ extern SDL_DECLSPEC SDL_JoystickType SDLCALL SDL_GetJoystickTypeForID(SDL_Joysti
* \returns a joystick identifier or NULL on failure; call SDL_GetError() for
* more information.
*
+ * \threadsafety It is safe to call this function from any thread.
+ *
* \since This function is available since SDL 3.2.0.
*
* \sa SDL_CloseJoystick
@@ -362,6 +401,8 @@ extern SDL_DECLSPEC SDL_Joystick * SDLCALL SDL_OpenJoystick(SDL_JoystickID insta
* \returns an SDL_Joystick on success or NULL on failure or if it hasn't been
* opened yet; call SDL_GetError() for more information.
*
+ * \threadsafety It is safe to call this function from any thread.
+ *
* \since This function is available since SDL 3.2.0.
*/
extern SDL_DECLSPEC SDL_Joystick * SDLCALL SDL_GetJoystickFromID(SDL_JoystickID instance_id);
@@ -373,6 +414,8 @@ extern SDL_DECLSPEC SDL_Joystick * SDLCALL SDL_GetJoystickFromID(SDL_JoystickID
* \returns an SDL_Joystick on success or NULL on failure; call SDL_GetError()
* for more information.
*
+ * \threadsafety It is safe to call this function from any thread.
+ *
* \since This function is available since SDL 3.2.0.
*
* \sa SDL_GetJoystickPlayerIndex
@@ -465,13 +508,33 @@ SDL_COMPILE_TIME_ASSERT(SDL_VirtualJoystickDesc_SIZE,
/**
* Attach a new virtual joystick.
*
+ * Apps can create virtual joysticks, that exist without hardware directly
+ * backing them, and have program-supplied inputs. Once attached, a virtual
+ * joystick looks like any other joystick that SDL can access. These can be
+ * used to make other things look like joysticks, or provide pre-recorded
+ * input, etc.
+ *
+ * Once attached, the app can send joystick inputs to the new virtual joystick
+ * using SDL_SetJoystickVirtualAxis(), etc.
+ *
+ * When no longer needed, the virtual joystick can be removed by calling
+ * SDL_DetachVirtualJoystick().
+ *
* \param desc joystick description, initialized using SDL_INIT_INTERFACE().
* \returns the joystick instance ID, or 0 on failure; call SDL_GetError() for
* more information.
*
+ * \threadsafety It is safe to call this function from any thread.
+ *
* \since This function is available since SDL 3.2.0.
*
* \sa SDL_DetachVirtualJoystick
+ * \sa SDL_SetJoystickVirtualAxis
+ * \sa SDL_SetJoystickVirtualButton
+ * \sa SDL_SetJoystickVirtualBall
+ * \sa SDL_SetJoystickVirtualHat
+ * \sa SDL_SetJoystickVirtualTouchpad
+ * \sa SDL_SetJoystickVirtualSensorData
*/
extern SDL_DECLSPEC SDL_JoystickID SDLCALL SDL_AttachVirtualJoystick(const SDL_VirtualJoystickDesc *desc);
@@ -483,6 +546,8 @@ extern SDL_DECLSPEC SDL_JoystickID SDLCALL SDL_AttachVirtualJoystick(const SDL_V
* \returns true on success or false on failure; call SDL_GetError() for more
* information.
*
+ * \threadsafety It is safe to call this function from any thread.
+ *
* \since This function is available since SDL 3.2.0.
*
* \sa SDL_AttachVirtualJoystick
@@ -495,6 +560,8 @@ extern SDL_DECLSPEC bool SDLCALL SDL_DetachVirtualJoystick(SDL_JoystickID instan
* \param instance_id the joystick instance ID.
* \returns true if the joystick is virtual, false otherwise.
*
+ * \threadsafety It is safe to call this function from any thread.
+ *
* \since This function is available since SDL 3.2.0.
*/
extern SDL_DECLSPEC bool SDLCALL SDL_IsJoystickVirtual(SDL_JoystickID instance_id);
@@ -518,7 +585,15 @@ extern SDL_DECLSPEC bool SDLCALL SDL_IsJoystickVirtual(SDL_JoystickID instance_i
* \returns true on success or false on failure; call SDL_GetError() for more
* information.
*
+ * \threadsafety It is safe to call this function from any thread.
+ *
* \since This function is available since SDL 3.2.0.
+ *
+ * \sa SDL_SetJoystickVirtualButton
+ * \sa SDL_SetJoystickVirtualBall
+ * \sa SDL_SetJoystickVirtualHat
+ * \sa SDL_SetJoystickVirtualTouchpad
+ * \sa SDL_SetJoystickVirtualSensorData
*/
extern SDL_DECLSPEC bool SDLCALL SDL_SetJoystickVirtualAxis(SDL_Joystick *joystick, int axis, Sint16 value);
@@ -538,7 +613,15 @@ extern SDL_DECLSPEC bool SDLCALL SDL_SetJoystickVirtualAxis(SDL_Joystick *joysti
* \returns true on success or false on failure; call SDL_GetError() for more
* information.
*
+ * \threadsafety It is safe to call this function from any thread.
+ *
* \since This function is available since SDL 3.2.0.
+ *
+ * \sa SDL_SetJoystickVirtualAxis
+ * \sa SDL_SetJoystickVirtualButton
+ * \sa SDL_SetJoystickVirtualHat
+ * \sa SDL_SetJoystickVirtualTouchpad
+ * \sa SDL_SetJoystickVirtualSensorData
*/
extern SDL_DECLSPEC bool SDLCALL SDL_SetJoystickVirtualBall(SDL_Joystick *joystick, int ball, Sint16 xrel, Sint16 yrel);
@@ -557,7 +640,15 @@ extern SDL_DECLSPEC bool SDLCALL SDL_SetJoystickVirtualBall(SDL_Joystick *joysti
* \returns true on success or false on failure; call SDL_GetError() for more
* information.
*
+ * \threadsafety It is safe to call this function from any thread.
+ *
* \since This function is available since SDL 3.2.0.
+ *
+ * \sa SDL_SetJoystickVirtualAxis
+ * \sa SDL_SetJoystickVirtualBall
+ * \sa SDL_SetJoystickVirtualHat
+ * \sa SDL_SetJoystickVirtualTouchpad
+ * \sa SDL_SetJoystickVirtualSensorData
*/
extern SDL_DECLSPEC bool SDLCALL SDL_SetJoystickVirtualButton(SDL_Joystick *joystick, int button, bool down);
@@ -576,7 +667,15 @@ extern SDL_DECLSPEC bool SDLCALL SDL_SetJoystickVirtualButton(SDL_Joystick *joys
* \returns true on success or false on failure; call SDL_GetError() for more
* information.
*
+ * \threadsafety It is safe to call this function from any thread.
+ *
* \since This function is available since SDL 3.2.0.
+ *
+ * \sa SDL_SetJoystickVirtualAxis
+ * \sa SDL_SetJoystickVirtualButton
+ * \sa SDL_SetJoystickVirtualBall
+ * \sa SDL_SetJoystickVirtualTouchpad
+ * \sa SDL_SetJoystickVirtualSensorData
*/
extern SDL_DECLSPEC bool SDLCALL SDL_SetJoystickVirtualHat(SDL_Joystick *joystick, int hat, Uint8 value);
@@ -602,7 +701,15 @@ extern SDL_DECLSPEC bool SDLCALL SDL_SetJoystickVirtualHat(SDL_Joystick *joystic
* \returns true on success or false on failure; call SDL_GetError() for more
* information.
*
+ * \threadsafety It is safe to call this function from any thread.
+ *
* \since This function is available since SDL 3.2.0.
+ *
+ * \sa SDL_SetJoystickVirtualAxis
+ * \sa SDL_SetJoystickVirtualButton
+ * \sa SDL_SetJoystickVirtualBall
+ * \sa SDL_SetJoystickVirtualHat
+ * \sa SDL_SetJoystickVirtualSensorData
*/
extern SDL_DECLSPEC bool SDLCALL SDL_SetJoystickVirtualTouchpad(SDL_Joystick *joystick, int touchpad, int finger, bool down, float x, float y, float pressure);
@@ -624,7 +731,15 @@ extern SDL_DECLSPEC bool SDLCALL SDL_SetJoystickVirtualTouchpad(SDL_Joystick *jo
* \returns true on success or false on failure; call SDL_GetError() for more
* information.
*
+ * \threadsafety It is safe to call this function from any thread.
+ *
* \since This function is available since SDL 3.2.0.
+ *
+ * \sa SDL_SetJoystickVirtualAxis
+ * \sa SDL_SetJoystickVirtualButton
+ * \sa SDL_SetJoystickVirtualBall
+ * \sa SDL_SetJoystickVirtualHat
+ * \sa SDL_SetJoystickVirtualTouchpad
*/
extern SDL_DECLSPEC bool SDLCALL SDL_SendJoystickVirtualSensorData(SDL_Joystick *joystick, SDL_SensorType type, Uint64 sensor_timestamp, const float *data, int num_values);
@@ -648,6 +763,8 @@ extern SDL_DECLSPEC bool SDLCALL SDL_SendJoystickVirtualSensorData(SDL_Joystick
* \returns a valid property ID on success or 0 on failure; call
* SDL_GetError() for more information.
*
+ * \threadsafety It is safe to call this function from any thread.
+ *
* \since This function is available since SDL 3.2.0.
*/
extern SDL_DECLSPEC SDL_PropertiesID SDLCALL SDL_GetJoystickProperties(SDL_Joystick *joystick);
@@ -665,6 +782,8 @@ extern SDL_DECLSPEC SDL_PropertiesID SDLCALL SDL_GetJoystickProperties(SDL_Joyst
* \returns the name of the selected joystick. If no name can be found, this
* function returns NULL; call SDL_GetError() for more information.
*
+ * \threadsafety It is safe to call this function from any thread.
+ *
* \since This function is available since SDL 3.2.0.
*
* \sa SDL_GetJoystickNameForID
@@ -678,6 +797,8 @@ extern SDL_DECLSPEC const char * SDLCALL SDL_GetJoystickName(SDL_Joystick *joyst
* \returns the path of the selected joystick. If no path can be found, this
* function returns NULL; call SDL_GetError() for more information.
*
+ * \threadsafety It is safe to call this function from any thread.
+ *
* \since This function is available since SDL 3.2.0.
*
* \sa SDL_GetJoystickPathForID
@@ -693,6 +814,8 @@ extern SDL_DECLSPEC const char * SDLCALL SDL_GetJoystickPath(SDL_Joystick *joyst
* \param joystick the SDL_Joystick obtained from SDL_OpenJoystick().
* \returns the player index, or -1 if it's not available.
*
+ * \threadsafety It is safe to call this function from any thread.
+ *
* \since This function is available since SDL 3.2.0.
*
* \sa SDL_SetJoystickPlayerIndex
@@ -708,6 +831,8 @@ extern SDL_DECLSPEC int SDLCALL SDL_GetJoystickPlayerIndex(SDL_Joystick *joystic
* \returns true on success or false on failure; call SDL_GetError() for more
* information.
*
+ * \threadsafety It is safe to call this function from any thread.
+ *
* \since This function is available since SDL 3.2.0.
*
* \sa SDL_GetJoystickPlayerIndex
@@ -724,6 +849,8 @@ extern SDL_DECLSPEC bool SDLCALL SDL_SetJoystickPlayerIndex(SDL_Joystick *joysti
* this function returns a zero GUID; call SDL_GetError() for more
* information.
*
+ * \threadsafety It is safe to call this function from any thread.
+ *
* \since This function is available since SDL 3.2.0.
*
* \sa SDL_GetJoystickGUIDForID
@@ -739,6 +866,8 @@ extern SDL_DECLSPEC SDL_GUID SDLCALL SDL_GetJoystickGUID(SDL_Joystick *joystick)
* \param joystick the SDL_Joystick obtained from SDL_OpenJoystick().
* \returns the USB vendor ID of the selected joystick, or 0 if unavailable.
*
+ * \threadsafety It is safe to call this function from any thread.
+ *
* \since This function is available since SDL 3.2.0.
*
* \sa SDL_GetJoystickVendorForID
@@ -753,6 +882,8 @@ extern SDL_DECLSPEC Uint16 SDLCALL SDL_GetJoystickVendor(SDL_Joystick *joystick)
* \param joystick the SDL_Joystick obtained from SDL_OpenJoystick().
* \returns the USB product ID of the selected joystick, or 0 if unavailable.
*
+ * \threadsafety It is safe to call this function from any thread.
+ *
* \since This function is available since SDL 3.2.0.
*
* \sa SDL_GetJoystickProductForID
@@ -767,6 +898,8 @@ extern SDL_DECLSPEC Uint16 SDLCALL SDL_GetJoystickProduct(SDL_Joystick *joystick
* \param joystick the SDL_Joystick obtained from SDL_OpenJoystick().
* \returns the product version of the selected joystick, or 0 if unavailable.
*
+ * \threadsafety It is safe to call this function from any thread.
+ *
* \since This function is available since SDL 3.2.0.
*
* \sa SDL_GetJoystickProductVersionForID
@@ -782,6 +915,8 @@ extern SDL_DECLSPEC Uint16 SDLCALL SDL_GetJoystickProductVersion(SDL_Joystick *j
* \returns the firmware version of the selected joystick, or 0 if
* unavailable.
*
+ * \threadsafety It is safe to call this function from any thread.
+ *
* \since This function is available since SDL 3.2.0.
*/
extern SDL_DECLSPEC Uint16 SDLCALL SDL_GetJoystickFirmwareVersion(SDL_Joystick *joystick);
@@ -795,6 +930,8 @@ extern SDL_DECLSPEC Uint16 SDLCALL SDL_GetJoystickFirmwareVersion(SDL_Joystick *
* \returns the serial number of the selected joystick, or NULL if
* unavailable.
*
+ * \threadsafety It is safe to call this function from any thread.
+ *
* \since This function is available since SDL 3.2.0.
*/
extern SDL_DECLSPEC const char * SDLCALL SDL_GetJoystickSerial(SDL_Joystick *joystick);
@@ -805,6 +942,8 @@ extern SDL_DECLSPEC const char * SDLCALL SDL_GetJoystickSerial(SDL_Joystick *joy
* \param joystick the SDL_Joystick obtained from SDL_OpenJoystick().
* \returns the SDL_JoystickType of the selected joystick.
*
+ * \threadsafety It is safe to call this function from any thread.
+ *
* \since This function is available since SDL 3.2.0.
*
* \sa SDL_GetJoystickTypeForID
@@ -824,6 +963,8 @@ extern SDL_DECLSPEC SDL_JoystickType SDLCALL SDL_GetJoystickType(SDL_Joystick *j
* \param crc16 a pointer filled in with a CRC used to distinguish different
* products with the same VID/PID, or 0 if not available.
*
+ * \threadsafety It is safe to call this function from any thread.
+ *
* \since This function is available since SDL 3.2.0.
*
* \sa SDL_GetJoystickGUIDForID
@@ -837,6 +978,8 @@ extern SDL_DECLSPEC void SDLCALL SDL_GetJoystickGUIDInfo(SDL_GUID guid, Uint16 *
* \returns true if the joystick has been opened, false if it has not; call
* SDL_GetError() for more information.
*
+ * \threadsafety It is safe to call this function from any thread.
+ *
* \since This function is available since SDL 3.2.0.
*/
extern SDL_DECLSPEC bool SDLCALL SDL_JoystickConnected(SDL_Joystick *joystick);
@@ -848,6 +991,8 @@ extern SDL_DECLSPEC bool SDLCALL SDL_JoystickConnected(SDL_Joystick *joystick);
* \returns the instance ID of the specified joystick on success or 0 on
* failure; call SDL_GetError() for more information.
*
+ * \threadsafety It is safe to call this function from any thread.
+ *
* \since This function is available since SDL 3.2.0.
*/
extern SDL_DECLSPEC SDL_JoystickID SDLCALL SDL_GetJoystickID(SDL_Joystick *joystick);
@@ -863,6 +1008,8 @@ extern SDL_DECLSPEC SDL_JoystickID SDLCALL SDL_GetJoystickID(SDL_Joystick *joyst
* \returns the number of axis controls/number of axes on success or -1 on
* failure; call SDL_GetError() for more information.
*
+ * \threadsafety It is safe to call this function from any thread.
+ *
* \since This function is available since SDL 3.2.0.
*
* \sa SDL_GetJoystickAxis
@@ -884,6 +1031,8 @@ extern SDL_DECLSPEC int SDLCALL SDL_GetNumJoystickAxes(SDL_Joystick *joystick);
* \returns the number of trackballs on success or -1 on failure; call
* SDL_GetError() for more information.
*
+ * \threadsafety It is safe to call this function from any thread.
+ *
* \since This function is available since SDL 3.2.0.
*
* \sa SDL_GetJoystickBall
@@ -900,6 +1049,8 @@ extern SDL_DECLSPEC int SDLCALL SDL_GetNumJoystickBalls(SDL_Joystick *joystick);
* \returns the number of POV hats on success or -1 on failure; call
* SDL_GetError() for more information.
*
+ * \threadsafety It is safe to call this function from any thread.
+ *
* \since This function is available since SDL 3.2.0.
*
* \sa SDL_GetJoystickHat
@@ -916,6 +1067,8 @@ extern SDL_DECLSPEC int SDLCALL SDL_GetNumJoystickHats(SDL_Joystick *joystick);
* \returns the number of buttons on success or -1 on failure; call
* SDL_GetError() for more information.
*
+ * \threadsafety It is safe to call this function from any thread.
+ *
* \since This function is available since SDL 3.2.0.
*
* \sa SDL_GetJoystickButton
@@ -934,6 +1087,8 @@ extern SDL_DECLSPEC int SDLCALL SDL_GetNumJoystickButtons(SDL_Joystick *joystick
*
* \param enabled whether to process joystick events or not.
*
+ * \threadsafety It is safe to call this function from any thread.
+ *
* \since This function is available since SDL 3.2.0.
*
* \sa SDL_JoystickEventsEnabled
@@ -950,6 +1105,8 @@ extern SDL_DECLSPEC void SDLCALL SDL_SetJoystickEventsEnabled(bool enabled);
*
* \returns true if joystick events are being processed, false otherwise.
*
+ * \threadsafety It is safe to call this function from any thread.
+ *
* \since This function is available since SDL 3.2.0.
*
* \sa SDL_SetJoystickEventsEnabled
@@ -962,6 +1119,8 @@ extern SDL_DECLSPEC bool SDLCALL SDL_JoystickEventsEnabled(void);
* This is called automatically by the event loop if any joystick events are
* enabled.
*
+ * \threadsafety It is safe to call this function from any thread.
+ *
* \since This function is available since SDL 3.2.0.
*/
extern SDL_DECLSPEC void SDLCALL SDL_UpdateJoysticks(void);
@@ -984,6 +1143,8 @@ extern SDL_DECLSPEC void SDLCALL SDL_UpdateJoysticks(void);
* \returns a 16-bit signed integer representing the current position of the
* axis or 0 on failure; call SDL_GetError() for more information.
*
+ * \threadsafety It is safe to call this function from any thread.
+ *
* \since This function is available since SDL 3.2.0.
*
* \sa SDL_GetNumJoystickAxes
@@ -1002,6 +1163,8 @@ extern SDL_DECLSPEC Sint16 SDLCALL SDL_GetJoystickAxis(SDL_Joystick *joystick, i
* \param state upon return, the initial value is supplied here.
* \returns true if this axis has any initial value, or false if not.
*
+ * \threadsafety It is safe to call this function from any thread.
+ *
* \since This function is available since SDL 3.2.0.
*/
extern SDL_DECLSPEC bool SDLCALL SDL_GetJoystickAxisInitialState(SDL_Joystick *joystick, int axis, Sint16 *state);
@@ -1021,6 +1184,8 @@ extern SDL_DECLSPEC bool SDLCALL SDL_GetJoystickAxisInitialState(SDL_Joystick *j
* \returns true on success or false on failure; call SDL_GetError() for more
* information.
*
+ * \threadsafety It is safe to call this function from any thread.
+ *
* \since This function is available since SDL 3.2.0.
*
* \sa SDL_GetNumJoystickBalls
@@ -1036,6 +1201,8 @@ extern SDL_DECLSPEC bool SDLCALL SDL_GetJoystickBall(SDL_Joystick *joystick, int
* \param hat the hat index to get the state from; indices start at index 0.
* \returns the current hat position.
*
+ * \threadsafety It is safe to call this function from any thread.
+ *
* \since This function is available since SDL 3.2.0.
*
* \sa SDL_GetNumJoystickHats
@@ -1060,6 +1227,8 @@ extern SDL_DECLSPEC Uint8 SDLCALL SDL_GetJoystickHat(SDL_Joystick *joystick, int
* index 0.
* \returns true if the button is pressed, false otherwise.
*
+ * \threadsafety It is safe to call this function from any thread.
+ *
* \since This function is available since SDL 3.2.0.
*
* \sa SDL_GetNumJoystickButtons
@@ -1083,6 +1252,8 @@ extern SDL_DECLSPEC bool SDLCALL SDL_GetJoystickButton(SDL_Joystick *joystick, i
* \param duration_ms the duration of the rumble effect, in milliseconds.
* \returns true, or false if rumble isn't supported on this joystick.
*
+ * \threadsafety It is safe to call this function from any thread.
+ *
* \since This function is available since SDL 3.2.0.
*/
extern SDL_DECLSPEC bool SDLCALL SDL_RumbleJoystick(SDL_Joystick *joystick, Uint16 low_frequency_rumble, Uint16 high_frequency_rumble, Uint32 duration_ms);
@@ -1110,6 +1281,8 @@ extern SDL_DECLSPEC bool SDLCALL SDL_RumbleJoystick(SDL_Joystick *joystick, Uint
* \returns true on success or false on failure; call SDL_GetError() for more
* information.
*
+ * \threadsafety It is safe to call this function from any thread.
+ *
* \since This function is available since SDL 3.2.0.
*
* \sa SDL_RumbleJoystick
@@ -1132,6 +1305,8 @@ extern SDL_DECLSPEC bool SDLCALL SDL_RumbleJoystickTriggers(SDL_Joystick *joysti
* \returns true on success or false on failure; call SDL_GetError() for more
* information.
*
+ * \threadsafety It is safe to call this function from any thread.
+ *
* \since This function is available since SDL 3.2.0.
*/
extern SDL_DECLSPEC bool SDLCALL SDL_SetJoystickLED(SDL_Joystick *joystick, Uint8 red, Uint8 green, Uint8 blue);
@@ -1145,6 +1320,8 @@ extern SDL_DECLSPEC bool SDLCALL SDL_SetJoystickLED(SDL_Joystick *joystick, Uint
* \returns true on success or false on failure; call SDL_GetError() for more
* information.
*
+ * \threadsafety It is safe to call this function from any thread.
+ *
* \since This function is available since SDL 3.2.0.
*/
extern SDL_DECLSPEC bool SDLCALL SDL_SendJoystickEffect(SDL_Joystick *joystick, const void *data, int size);
@@ -1154,6 +1331,8 @@ extern SDL_DECLSPEC bool SDLCALL SDL_SendJoystickEffect(SDL_Joystick *joystick,
*
* \param joystick the joystick device to close.
*
+ * \threadsafety It is safe to call this function from any thread.
+ *
* \since This function is available since SDL 3.2.0.
*
* \sa SDL_OpenJoystick
@@ -1168,6 +1347,8 @@ extern SDL_DECLSPEC void SDLCALL SDL_CloseJoystick(SDL_Joystick *joystick);
* `SDL_JOYSTICK_CONNECTION_INVALID` on failure; call SDL_GetError()
* for more information.
*
+ * \threadsafety It is safe to call this function from any thread.
+ *
* \since This function is available since SDL 3.2.0.
*/
extern SDL_DECLSPEC SDL_JoystickConnectionState SDLCALL SDL_GetJoystickConnectionState(SDL_Joystick *joystick);
@@ -1189,6 +1370,8 @@ extern SDL_DECLSPEC SDL_JoystickConnectionState SDLCALL SDL_GetJoystickConnectio
* \returns the current battery state or `SDL_POWERSTATE_ERROR` on failure;
* call SDL_GetError() for more information.
*
+ * \threadsafety It is safe to call this function from any thread.
+ *
* \since This function is available since SDL 3.2.0.
*/
extern SDL_DECLSPEC SDL_PowerState SDLCALL SDL_GetJoystickPowerInfo(SDL_Joystick *joystick, int *percent);
diff --git a/thirdparty/sdl/include/SDL3/SDL_keyboard.h b/thirdparty/sdl/include/SDL3/SDL_keyboard.h
index afa77b6c2c3..d14ab6fb27c 100644
--- a/thirdparty/sdl/include/SDL3/SDL_keyboard.h
+++ b/thirdparty/sdl/include/SDL3/SDL_keyboard.h
@@ -1,6 +1,6 @@
/*
Simple DirectMedia Layer
- Copyright (C) 1997-2025 Sam Lantinga <[email protected]>
+ Copyright (C) 1997-2026 Sam Lantinga <[email protected]>
This software is provided 'as-is', without any express or implied
warranty. In no event will the authors be held liable for any damages
@@ -174,8 +174,7 @@ extern SDL_DECLSPEC void SDLCALL SDL_ResetKeyboard(void);
/**
* Get the current key modifier state for the keyboard.
*
- * \returns an OR'd combination of the modifier keys for the keyboard. See
- * SDL_Keymod for details.
+ * \returns an OR'd combination of the modifier keys for the keyboard.
*
* \threadsafety It is safe to call this function from any thread.
*
diff --git a/thirdparty/sdl/include/SDL3/SDL_keycode.h b/thirdparty/sdl/include/SDL3/SDL_keycode.h
index 61b68e794f8..1818ee3e4c1 100644
--- a/thirdparty/sdl/include/SDL3/SDL_keycode.h
+++ b/thirdparty/sdl/include/SDL3/SDL_keycode.h
@@ -1,6 +1,6 @@
/*
Simple DirectMedia Layer
- Copyright (C) 1997-2025 Sam Lantinga <[email protected]>
+ Copyright (C) 1997-2026 Sam Lantinga <[email protected]>
This software is provided 'as-is', without any express or implied
warranty. In no event will the authors be held liable for any damages
@@ -45,12 +45,16 @@
* `SDLK_*` constant for those keys that do not generate characters.
*
* A special exception is the number keys at the top of the keyboard which map
- * to SDLK_0...SDLK_9 on AZERTY layouts.
+ * by default to SDLK_0...SDLK_9 on AZERTY layouts.
*
* Keys with the `SDLK_EXTENDED_MASK` bit set do not map to a scancode or
- * unicode code point.
+ * Unicode code point.
+ *
+ * Many common keycodes are listed below, but this list is not exhaustive.
*
* \since This datatype is available since SDL 3.2.0.
+ *
+ * \sa SDL_HINT_KEYCODE_OPTIONS
*/
typedef Uint32 SDL_Keycode;
diff --git a/thirdparty/sdl/include/SDL3/SDL_loadso.h b/thirdparty/sdl/include/SDL3/SDL_loadso.h
index f8649d75801..51d0d8811bc 100644
--- a/thirdparty/sdl/include/SDL3/SDL_loadso.h
+++ b/thirdparty/sdl/include/SDL3/SDL_loadso.h
@@ -1,6 +1,6 @@
/*
Simple DirectMedia Layer
- Copyright (C) 1997-2025 Sam Lantinga <[email protected]>
+ Copyright (C) 1997-2026 Sam Lantinga <[email protected]>
This software is provided 'as-is', without any express or implied
warranty. In no event will the authors be held liable for any damages
diff --git a/thirdparty/sdl/include/SDL3/SDL_locale.h b/thirdparty/sdl/include/SDL3/SDL_locale.h
index 902843e81f3..9f03aa90d05 100644
--- a/thirdparty/sdl/include/SDL3/SDL_locale.h
+++ b/thirdparty/sdl/include/SDL3/SDL_locale.h
@@ -1,6 +1,6 @@
/*
Simple DirectMedia Layer
- Copyright (C) 1997-2025 Sam Lantinga <[email protected]>
+ Copyright (C) 1997-2026 Sam Lantinga <[email protected]>
This software is provided 'as-is', without any express or implied
warranty. In no event will the authors be held liable for any damages
@@ -102,6 +102,8 @@ typedef struct SDL_Locale
* allocation that should be freed with SDL_free() when it is no
* longer needed.
*
+ * \threadsafety This function is not thread safe.
+ *
* \since This function is available since SDL 3.2.0.
*/
extern SDL_DECLSPEC SDL_Locale ** SDLCALL SDL_GetPreferredLocales(int *count);
diff --git a/thirdparty/sdl/include/SDL3/SDL_log.h b/thirdparty/sdl/include/SDL3/SDL_log.h
index 3fd7ec2ede6..f193abfb3b3 100644
--- a/thirdparty/sdl/include/SDL3/SDL_log.h
+++ b/thirdparty/sdl/include/SDL3/SDL_log.h
@@ -1,6 +1,6 @@
/*
Simple DirectMedia Layer
- Copyright (C) 1997-2025 Sam Lantinga <[email protected]>
+ Copyright (C) 1997-2026 Sam Lantinga <[email protected]>
This software is provided 'as-is', without any express or implied
warranty. In no event will the authors be held liable for any damages
@@ -206,6 +206,9 @@ extern SDL_DECLSPEC void SDLCALL SDL_ResetLogPriorities(void);
* SDL_LOG_PRIORITY_WARN and higher have a prefix showing their priority, e.g.
* "WARNING: ".
*
+ * This function makes a copy of its string argument, **prefix**, so it is not
+ * necessary to keep the value of **prefix** alive after the call returns.
+ *
* \param priority the SDL_LogPriority to modify.
* \param prefix the prefix to use for that log priority, or NULL to use no
* prefix.
@@ -263,7 +266,6 @@ extern SDL_DECLSPEC void SDLCALL SDL_Log(SDL_PRINTF_FORMAT_STRING const char *fm
* \sa SDL_LogInfo
* \sa SDL_LogMessage
* \sa SDL_LogMessageV
- * \sa SDL_LogTrace
* \sa SDL_LogVerbose
* \sa SDL_LogWarn
*/
@@ -485,7 +487,8 @@ typedef void (SDLCALL *SDL_LogOutputFunction)(void *userdata, int category, SDL_
/**
* Get the default log output function.
*
- * \returns the default log output callback.
+ * \returns the default log output callback. It should be called with NULL for
+ * the userdata argument.
*
* \threadsafety It is safe to call this function from any thread.
*
diff --git a/thirdparty/sdl/include/SDL3/SDL_main.h b/thirdparty/sdl/include/SDL3/SDL_main.h
index 905d78e9641..771572f29f1 100644
--- a/thirdparty/sdl/include/SDL3/SDL_main.h
+++ b/thirdparty/sdl/include/SDL3/SDL_main.h
@@ -1,6 +1,6 @@
/*
Simple DirectMedia Layer
- Copyright (C) 1997-2025 Sam Lantinga <[email protected]>
+ Copyright (C) 1997-2026 Sam Lantinga <[email protected]>
This software is provided 'as-is', without any express or implied
warranty. In no event will the authors be held liable for any damages
@@ -47,7 +47,7 @@
*
* For more information, see:
*
- * https://wiki.libsdl.org/SDL3/README/main-functions
+ * https://wiki.libsdl.org/SDL3/README-main-functions
*/
#ifndef SDL_main_h_
@@ -68,7 +68,7 @@
* proper entry point for the platform, and all the other magic details
* needed, like manually calling SDL_SetMainReady.
*
- * Please see [README/main-functions](README/main-functions), (or
+ * Please see [README-main-functions](README-main-functions), (or
* docs/README-main-functions.md in the source tree) for a more detailed
* explanation.
*
@@ -85,7 +85,7 @@
* SDL_AppQuit. The app should not provide a `main` function in this case, and
* doing so will likely cause the build to fail.
*
- * Please see [README/main-functions](README/main-functions), (or
+ * Please see [README-main-functions](README-main-functions), (or
* docs/README-main-functions.md in the source tree) for a more detailed
* explanation.
*
@@ -110,7 +110,8 @@
* Even if available, an app can define SDL_MAIN_HANDLED and provide their
* own, if they know what they're doing.
*
- * This macro is used internally by SDL, and apps probably shouldn't rely on it.
+ * This macro is used internally by SDL, and apps probably shouldn't rely on
+ * it.
*
* \since This macro is available since SDL 3.2.0.
*/
@@ -125,10 +126,11 @@
* This macro is defined by `SDL_main.h`, which is not automatically included
* by `SDL.h`.
*
- * Even if required, an app can define SDL_MAIN_HANDLED and provide their
- * own, if they know what they're doing.
+ * Even if required, an app can define SDL_MAIN_HANDLED and provide their own,
+ * if they know what they're doing.
*
- * This macro is used internally by SDL, and apps probably shouldn't rely on it.
+ * This macro is used internally by SDL, and apps probably shouldn't rely on
+ * it.
*
* \since This macro is available since SDL 3.2.0.
*/
@@ -165,12 +167,10 @@
*/
#define SDL_MAIN_NEEDED
- #elif defined(SDL_PLATFORM_IOS)
- /* On iOS SDL provides a main function that creates an application delegate
- and starts the iOS application run loop.
+ #elif defined(SDL_PLATFORM_IOS) || defined(SDL_PLATFORM_TVOS)
+ /* On iOS and tvOS SDL provides a main function that creates an application delegate and starts the application run loop.
- To use it, just #include SDL_main.h in the source file that contains your
- main() function.
+ To use it, just #include <SDL3/SDL_main.h> in the source file that contains your main() function.
See src/video/uikit/SDL_uikitappdelegate.m for more details.
*/
@@ -257,7 +257,7 @@
#else
/* usually this is empty */
#define SDLMAIN_DECLSPEC
-#endif /* SDL_MAIN_EXPORTED */
+#endif /* SDL_WIKI_DOCUMENTATION_SECTION */
#if defined(SDL_MAIN_NEEDED) || defined(SDL_MAIN_AVAILABLE) || defined(SDL_MAIN_USE_CALLBACKS)
#define main SDL_main
@@ -333,6 +333,9 @@ extern "C" {
* \returns SDL_APP_FAILURE to terminate with an error, SDL_APP_SUCCESS to
* terminate with success, SDL_APP_CONTINUE to continue.
*
+ * \threadsafety This function is called once by SDL, at startup, on a single
+ * thread.
+ *
* \since This function is available since SDL 3.2.0.
*
* \sa SDL_AppIterate
@@ -347,10 +350,10 @@ extern SDLMAIN_DECLSPEC SDL_AppResult SDLCALL SDL_AppInit(void **appstate, int a
* Apps implement this function when using SDL_MAIN_USE_CALLBACKS. If using a
* standard "main" function, you should not supply this.
*
- * This function is called repeatedly by SDL after SDL_AppInit returns 0. The
- * function should operate as a single iteration the program's primary loop;
- * it should update whatever state it needs and draw a new frame of video,
- * usually.
+ * This function is called repeatedly by SDL after SDL_AppInit returns
+ * SDL_APP_CONTINUE. The function should operate as a single iteration the
+ * program's primary loop; it should update whatever state it needs and draw a
+ * new frame of video, usually.
*
* On some platforms, this function will be called at the refresh rate of the
* display (which might change during the life of your app!). There are no
@@ -449,8 +452,8 @@ extern SDLMAIN_DECLSPEC SDL_AppResult SDLCALL SDL_AppEvent(void *appstate, SDL_E
*
* This function is called once by SDL before terminating the program.
*
- * This function will be called no matter what, even if SDL_AppInit requests
- * termination.
+ * This function will be called in all cases, even if SDL_AppInit requests
+ * termination at startup.
*
* This function should not go into an infinite mainloop; it should
* deinitialize any resources necessary, perform whatever shutdown activities,
@@ -512,7 +515,7 @@ typedef int (SDLCALL *SDL_main_func)(int argc, char *argv[]);
* SDL_MAIN_USE_CALLBACKS.
*
* Program startup is a surprisingly complex topic. Please see
- * [README/main-functions](README/main-functions), (or
+ * [README-main-functions](README-main-functions), (or
* docs/README-main-functions.md in the source tree) for a more detailed
* explanation.
*
@@ -537,6 +540,8 @@ extern SDLMAIN_DECLSPEC int SDLCALL SDL_main(int argc, char *argv[]);
* will not be changed it is necessary to define SDL_MAIN_HANDLED before
* including SDL.h.
*
+ * \threadsafety This function is not thread safe.
+ *
* \since This function is available since SDL 3.2.0.
*
* \sa SDL_Init
@@ -553,6 +558,9 @@ extern SDL_DECLSPEC void SDLCALL SDL_SetMainReady(void);
* using SDL_main (like when using SDL_MAIN_HANDLED). When using this, you do
* *not* need SDL_SetMainReady().
*
+ * If `argv` is NULL, SDL will provide command line arguments, either by
+ * querying the OS for them if possible, or supplying a filler array if not.
+ *
* \param argc the argc parameter from the application's main() function, or 0
* if the platform's main-equivalent has no argc.
* \param argv the argv parameter from the application's main() function, or
@@ -615,16 +623,19 @@ extern SDL_DECLSPEC int SDLCALL SDL_EnterAppMainCallbacks(int argc, char *argv[]
* Most applications do not need to, and should not, call this directly; SDL
* will call it when initializing the video subsystem.
*
+ * If `name` is NULL, SDL currently uses `(CS_BYTEALIGNCLIENT | CS_OWNDC)` for
+ * the style, regardless of what is specified here.
+ *
* \param name the window class name, in UTF-8 encoding. If NULL, SDL
* currently uses "SDL_app" but this isn't guaranteed.
- * \param style the value to use in WNDCLASSEX::style. If `name` is NULL, SDL
- * currently uses `(CS_BYTEALIGNCLIENT | CS_OWNDC)` regardless of
- * what is specified here.
+ * \param style the value to use in WNDCLASSEX::style.
* \param hInst the HINSTANCE to use in WNDCLASSEX::hInstance. If zero, SDL
* will use `GetModuleHandle(NULL)` instead.
* \returns true on success or false on failure; call SDL_GetError() for more
* information.
*
+ * \threadsafety This function is not thread safe.
+ *
* \since This function is available since SDL 3.2.0.
*/
extern SDL_DECLSPEC bool SDLCALL SDL_RegisterApp(const char *name, Uint32 style, void *hInst);
@@ -642,6 +653,8 @@ extern SDL_DECLSPEC bool SDLCALL SDL_RegisterApp(const char *name, Uint32 style,
* deregistered when the registration counter in SDL_RegisterApp decrements to
* zero through calls to this function.
*
+ * \threadsafety This function is not thread safe.
+ *
* \since This function is available since SDL 3.2.0.
*/
extern SDL_DECLSPEC void SDLCALL SDL_UnregisterApp(void);
@@ -651,10 +664,26 @@ extern SDL_DECLSPEC void SDLCALL SDL_UnregisterApp(void);
/**
* Callback from the application to let the suspend continue.
*
+ * This should be called from an event watch in response to an
+ * `SDL_EVENT_DID_ENTER_BACKGROUND` event.
+ *
+ * When using SDL_Render, your event watch should be added _after_ creating
+ * the `SDL_Renderer`; this allows the timing of the D3D12 command queue
+ * suspension to execute in the correct order.
+ *
+ * When using SDL_GPU, this should be called after calling SDL_GDKSuspendGPU.
+ *
+ * If you're writing your own D3D12 renderer, this should be called after
+ * calling `ID3D12CommandQueue::SuspendX`.
+ *
* This function is only needed for Xbox GDK support; all other platforms will
* do nothing and set an "unsupported" error message.
*
+ * \threadsafety This function is not thread safe.
+ *
* \since This function is available since SDL 3.2.0.
+ *
+ * \sa SDL_AddEventWatch
*/
extern SDL_DECLSPEC void SDLCALL SDL_GDKSuspendComplete(void);
diff --git a/thirdparty/sdl/include/SDL3/SDL_main_impl.h b/thirdparty/sdl/include/SDL3/SDL_main_impl.h
index 14ebb429164..bf5f583639c 100644
--- a/thirdparty/sdl/include/SDL3/SDL_main_impl.h
+++ b/thirdparty/sdl/include/SDL3/SDL_main_impl.h
@@ -1,6 +1,6 @@
/*
Simple DirectMedia Layer
- Copyright (C) 1997-2025 Sam Lantinga <[email protected]>
+ Copyright (C) 1997-2026 Sam Lantinga <[email protected]>
This software is provided 'as-is', without any express or implied
warranty. In no event will the authors be held liable for any damages
diff --git a/thirdparty/sdl/include/SDL3/SDL_messagebox.h b/thirdparty/sdl/include/SDL3/SDL_messagebox.h
index 365ae36a5a6..af604e2c7ce 100644
--- a/thirdparty/sdl/include/SDL3/SDL_messagebox.h
+++ b/thirdparty/sdl/include/SDL3/SDL_messagebox.h
@@ -1,6 +1,6 @@
/*
Simple DirectMedia Layer
- Copyright (C) 1997-2025 Sam Lantinga <[email protected]>
+ Copyright (C) 1997-2026 Sam Lantinga <[email protected]>
This software is provided 'as-is', without any express or implied
warranty. In no event will the authors be held liable for any damages
@@ -168,6 +168,8 @@ typedef struct SDL_MessageBoxData
* \returns true on success or false on failure; call SDL_GetError() for more
* information.
*
+ * \threadsafety This function should only be called on the main thread.
+ *
* \since This function is available since SDL 3.2.0.
*
* \sa SDL_ShowSimpleMessageBox
@@ -210,6 +212,8 @@ extern SDL_DECLSPEC bool SDLCALL SDL_ShowMessageBox(const SDL_MessageBoxData *me
* \returns true on success or false on failure; call SDL_GetError() for more
* information.
*
+ * \threadsafety This function should only be called on the main thread.
+ *
* \since This function is available since SDL 3.2.0.
*
* \sa SDL_ShowMessageBox
diff --git a/thirdparty/sdl/include/SDL3/SDL_metal.h b/thirdparty/sdl/include/SDL3/SDL_metal.h
index 14b1bc87a2f..6b0e171b4aa 100644
--- a/thirdparty/sdl/include/SDL3/SDL_metal.h
+++ b/thirdparty/sdl/include/SDL3/SDL_metal.h
@@ -1,6 +1,6 @@
/*
Simple DirectMedia Layer
- Copyright (C) 1997-2025 Sam Lantinga <[email protected]>
+ Copyright (C) 1997-2026 Sam Lantinga <[email protected]>
This software is provided 'as-is', without any express or implied
warranty. In no event will the authors be held liable for any damages
@@ -65,6 +65,8 @@ typedef void *SDL_MetalView;
* \param window the window.
* \returns handle NSView or UIView.
*
+ * \threadsafety This function should only be called on the main thread.
+ *
* \since This function is available since SDL 3.2.0.
*
* \sa SDL_Metal_DestroyView
@@ -80,6 +82,8 @@ extern SDL_DECLSPEC SDL_MetalView SDLCALL SDL_Metal_CreateView(SDL_Window *windo
*
* \param view the SDL_MetalView object.
*
+ * \threadsafety This function should only be called on the main thread.
+ *
* \since This function is available since SDL 3.2.0.
*
* \sa SDL_Metal_CreateView
@@ -92,6 +96,8 @@ extern SDL_DECLSPEC void SDLCALL SDL_Metal_DestroyView(SDL_MetalView view);
* \param view the SDL_MetalView object.
* \returns a pointer.
*
+ * \threadsafety This function should only be called on the main thread.
+ *
* \since This function is available since SDL 3.2.0.
*/
extern SDL_DECLSPEC void * SDLCALL SDL_Metal_GetLayer(SDL_MetalView view);
diff --git a/thirdparty/sdl/include/SDL3/SDL_misc.h b/thirdparty/sdl/include/SDL3/SDL_misc.h
index 3dd6fcddd60..654c0055807 100644
--- a/thirdparty/sdl/include/SDL3/SDL_misc.h
+++ b/thirdparty/sdl/include/SDL3/SDL_misc.h
@@ -1,6 +1,6 @@
/*
Simple DirectMedia Layer
- Copyright (C) 1997-2025 Sam Lantinga <[email protected]>
+ Copyright (C) 1997-2026 Sam Lantinga <[email protected]>
This software is provided 'as-is', without any express or implied
warranty. In no event will the authors be held liable for any damages
@@ -65,6 +65,8 @@ extern "C" {
* \returns true on success or false on failure; call SDL_GetError() for more
* information.
*
+ * \threadsafety This function should only be called on the main thread.
+ *
* \since This function is available since SDL 3.2.0.
*/
extern SDL_DECLSPEC bool SDLCALL SDL_OpenURL(const char *url);
diff --git a/thirdparty/sdl/include/SDL3/SDL_mouse.h b/thirdparty/sdl/include/SDL3/SDL_mouse.h
index 864135d2be0..fb03c0178d3 100644
--- a/thirdparty/sdl/include/SDL3/SDL_mouse.h
+++ b/thirdparty/sdl/include/SDL3/SDL_mouse.h
@@ -1,6 +1,6 @@
/*
Simple DirectMedia Layer
- Copyright (C) 1997-2025 Sam Lantinga <[email protected]>
+ Copyright (C) 1997-2026 Sam Lantinga <[email protected]>
This software is provided 'as-is', without any express or implied
warranty. In no event will the authors be held liable for any damages
@@ -130,6 +130,17 @@ typedef enum SDL_MouseWheelDirection
SDL_MOUSEWHEEL_FLIPPED /**< The scroll direction is flipped / natural */
} SDL_MouseWheelDirection;
+/**
+ * Animated cursor frame info.
+ *
+ * \since This struct is available since SDL 3.4.0.
+ */
+typedef struct SDL_CursorFrameInfo
+{
+ SDL_Surface *surface; /**< The surface data for this frame */
+ Uint32 duration; /**< The frame duration in milliseconds (a duration of 0 is infinite) */
+} SDL_CursorFrameInfo;
+
/**
* A bitmask of pressed mouse buttons, as reported by SDL_GetMouseState, etc.
*
@@ -160,6 +171,44 @@ typedef Uint32 SDL_MouseButtonFlags;
#define SDL_BUTTON_X1MASK SDL_BUTTON_MASK(SDL_BUTTON_X1)
#define SDL_BUTTON_X2MASK SDL_BUTTON_MASK(SDL_BUTTON_X2)
+/**
+ * A callback used to transform mouse motion delta from raw values.
+ *
+ * This is called during SDL's handling of platform mouse events to scale the
+ * values of the resulting motion delta.
+ *
+ * \param userdata what was passed as `userdata` to
+ * SDL_SetRelativeMouseTransform().
+ * \param timestamp the associated time at which this mouse motion event was
+ * received.
+ * \param window the associated window to which this mouse motion event was
+ * addressed.
+ * \param mouseID the associated mouse from which this mouse motion event was
+ * emitted.
+ * \param x pointer to a variable that will be treated as the resulting x-axis
+ * motion.
+ * \param y pointer to a variable that will be treated as the resulting y-axis
+ * motion.
+ *
+ * \threadsafety This callback is called by SDL's internal mouse input
+ * processing procedure, which may be a thread separate from the
+ * main event loop that is run at realtime priority. Stalling
+ * this thread with too much work in the callback can therefore
+ * potentially freeze the entire system. Care should be taken
+ * with proper synchronization practices when adding other side
+ * effects beyond mutation of the x and y values.
+ *
+ * \since This datatype is available since SDL 3.4.0.
+ *
+ * \sa SDL_SetRelativeMouseTransform
+ */
+typedef void (SDLCALL *SDL_MouseMotionTransformCallback)(
+ void *userdata,
+ Uint64 timestamp,
+ SDL_Window *window,
+ SDL_MouseID mouseID,
+ float *x, float *y
+);
/* Function prototypes */
@@ -380,6 +429,24 @@ extern SDL_DECLSPEC void SDLCALL SDL_WarpMouseInWindow(SDL_Window *window,
*/
extern SDL_DECLSPEC bool SDLCALL SDL_WarpMouseGlobal(float x, float y);
+/**
+ * Set a user-defined function by which to transform relative mouse inputs.
+ *
+ * This overrides the relative system scale and relative speed scale hints.
+ * Should be called prior to enabling relative mouse mode, fails otherwise.
+ *
+ * \param callback a callback used to transform relative mouse motion, or NULL
+ * for default behavior.
+ * \param userdata a pointer that will be passed to `callback`.
+ * \returns true on success or false on failure; call SDL_GetError() for more
+ * information.
+ *
+ * \threadsafety This function should only be called on the main thread.
+ *
+ * \since This function is available since SDL 3.4.0.
+ */
+extern SDL_DECLSPEC bool SDLCALL SDL_SetRelativeMouseTransform(SDL_MouseMotionTransformCallback callback, void *userdata);
+
/**
* Set relative mouse mode for a window.
*
@@ -509,6 +576,7 @@ extern SDL_DECLSPEC bool SDLCALL SDL_CaptureMouse(bool enabled);
*
* \since This function is available since SDL 3.2.0.
*
+ * \sa SDL_CreateAnimatedCursor
* \sa SDL_CreateColorCursor
* \sa SDL_CreateSystemCursor
* \sa SDL_DestroyCursor
@@ -522,15 +590,17 @@ extern SDL_DECLSPEC SDL_Cursor * SDLCALL SDL_CreateCursor(const Uint8 *data,
/**
* Create a color cursor.
*
- * If this function is passed a surface with alternate representations, the
- * surface will be interpreted as the content to be used for 100% display
- * scale, and the alternate representations will be used for high DPI
- * situations. For example, if the original surface is 32x32, then on a 2x
- * macOS display or 200% display scale on Windows, a 64x64 version of the
- * image will be used, if available. If a matching version of the image isn't
- * available, the closest larger size image will be downscaled to the
- * appropriate size and be used instead, if available. Otherwise, the closest
- * smaller image will be upscaled and be used instead.
+ * If this function is passed a surface with alternate representations added
+ * with SDL_AddSurfaceAlternateImage(), the surface will be interpreted as the
+ * content to be used for 100% display scale, and the alternate
+ * representations will be used for high DPI situations if
+ * SDL_HINT_MOUSE_DPI_SCALE_CURSORS is enabled. For example, if the original
+ * surface is 32x32, then on a 2x macOS display or 200% display scale on
+ * Windows, a 64x64 version of the image will be used, if available. If a
+ * matching version of the image isn't available, the closest larger size
+ * image will be downscaled to the appropriate size and be used instead, if
+ * available. Otherwise, the closest smaller image will be upscaled and be
+ * used instead.
*
* \param surface an SDL_Surface structure representing the cursor image.
* \param hot_x the x position of the cursor hot spot.
@@ -542,6 +612,8 @@ extern SDL_DECLSPEC SDL_Cursor * SDLCALL SDL_CreateCursor(const Uint8 *data,
*
* \since This function is available since SDL 3.2.0.
*
+ * \sa SDL_AddSurfaceAlternateImage
+ * \sa SDL_CreateAnimatedCursor
* \sa SDL_CreateCursor
* \sa SDL_CreateSystemCursor
* \sa SDL_DestroyCursor
@@ -551,6 +623,57 @@ extern SDL_DECLSPEC SDL_Cursor * SDLCALL SDL_CreateColorCursor(SDL_Surface *surf
int hot_x,
int hot_y);
+/**
+ * Create an animated color cursor.
+ *
+ * Animated cursors are composed of a sequential array of frames, specified as
+ * surfaces and durations in an array of SDL_CursorFrameInfo structs. The hot
+ * spot coordinates are universal to all frames, and all frames must have the
+ * same dimensions.
+ *
+ * Frame durations are specified in milliseconds. A duration of 0 implies an
+ * infinite frame time, and the animation will stop on that frame. To create a
+ * one-shot animation, set the duration of the last frame in the sequence to
+ * 0.
+ *
+ * If this function is passed surfaces with alternate representations added
+ * with SDL_AddSurfaceAlternateImage(), the surfaces will be interpreted as
+ * the content to be used for 100% display scale, and the alternate
+ * representations will be used for high DPI situations. For example, if the
+ * original surfaces are 32x32, then on a 2x macOS display or 200% display
+ * scale on Windows, a 64x64 version of the image will be used, if available.
+ * If a matching version of the image isn't available, the closest larger size
+ * image will be downscaled to the appropriate size and be used instead, if
+ * available. Otherwise, the closest smaller image will be upscaled and be
+ * used instead.
+ *
+ * If the underlying platform does not support animated cursors, this function
+ * will fall back to creating a static color cursor using the first frame in
+ * the sequence.
+ *
+ * \param frames an array of cursor images composing the animation.
+ * \param frame_count the number of frames in the sequence.
+ * \param hot_x the x position of the cursor hot spot.
+ * \param hot_y the y position of the cursor hot spot.
+ * \returns the new cursor on success or NULL on failure; call SDL_GetError()
+ * for more information.
+ *
+ * \threadsafety This function should only be called on the main thread.
+ *
+ * \since This function is available since SDL 3.4.0.
+ *
+ * \sa SDL_AddSurfaceAlternateImage
+ * \sa SDL_CreateCursor
+ * \sa SDL_CreateColorCursor
+ * \sa SDL_CreateSystemCursor
+ * \sa SDL_DestroyCursor
+ * \sa SDL_SetCursor
+ */
+extern SDL_DECLSPEC SDL_Cursor *SDLCALL SDL_CreateAnimatedCursor(SDL_CursorFrameInfo *frames,
+ int frame_count,
+ int hot_x,
+ int hot_y);
+
/**
* Create a system cursor.
*
@@ -608,7 +731,7 @@ extern SDL_DECLSPEC SDL_Cursor * SDLCALL SDL_GetCursor(void);
* You do not have to call SDL_DestroyCursor() on the return value, but it is
* safe to do so.
*
- * \returns the default cursor on success or NULL on failuree; call
+ * \returns the default cursor on success or NULL on failure; call
* SDL_GetError() for more information.
*
* \threadsafety This function should only be called on the main thread.
@@ -629,6 +752,7 @@ extern SDL_DECLSPEC SDL_Cursor * SDLCALL SDL_GetDefaultCursor(void);
*
* \since This function is available since SDL 3.2.0.
*
+ * \sa SDL_CreateAnimatedCursor
* \sa SDL_CreateColorCursor
* \sa SDL_CreateCursor
* \sa SDL_CreateSystemCursor
diff --git a/thirdparty/sdl/include/SDL3/SDL_mutex.h b/thirdparty/sdl/include/SDL3/SDL_mutex.h
index 9ab164078a9..29e8f1a1c7b 100644
--- a/thirdparty/sdl/include/SDL3/SDL_mutex.h
+++ b/thirdparty/sdl/include/SDL3/SDL_mutex.h
@@ -1,6 +1,6 @@
/*
Simple DirectMedia Layer
- Copyright (C) 1997-2025 Sam Lantinga <[email protected]>
+ Copyright (C) 1997-2026 Sam Lantinga <[email protected]>
This software is provided 'as-is', without any express or implied
warranty. In no event will the authors be held liable for any damages
@@ -308,6 +308,8 @@ typedef struct SDL_Mutex SDL_Mutex;
* \returns the initialized and unlocked mutex or NULL on failure; call
* SDL_GetError() for more information.
*
+ * \threadsafety It is safe to call this function from any thread.
+ *
* \since This function is available since SDL 3.2.0.
*
* \sa SDL_DestroyMutex
@@ -334,6 +336,8 @@ extern SDL_DECLSPEC SDL_Mutex * SDLCALL SDL_CreateMutex(void);
*
* \param mutex the mutex to lock.
*
+ * \threadsafety It is safe to call this function from any thread.
+ *
* \since This function is available since SDL 3.2.0.
*
* \sa SDL_TryLockMutex
@@ -355,6 +359,8 @@ extern SDL_DECLSPEC void SDLCALL SDL_LockMutex(SDL_Mutex *mutex) SDL_ACQUIRE(mut
* \param mutex the mutex to try to lock.
* \returns true on success, false if the mutex would block.
*
+ * \threadsafety It is safe to call this function from any thread.
+ *
* \since This function is available since SDL 3.2.0.
*
* \sa SDL_LockMutex
@@ -374,6 +380,9 @@ extern SDL_DECLSPEC bool SDLCALL SDL_TryLockMutex(SDL_Mutex *mutex) SDL_TRY_ACQU
*
* \param mutex the mutex to unlock.
*
+ * \threadsafety This call must be paired with a previous locking call on the
+ * same thread.
+ *
* \since This function is available since SDL 3.2.0.
*
* \sa SDL_LockMutex
@@ -392,6 +401,8 @@ extern SDL_DECLSPEC void SDLCALL SDL_UnlockMutex(SDL_Mutex *mutex) SDL_RELEASE(m
*
* \param mutex the mutex to destroy.
*
+ * \threadsafety It is safe to call this function from any thread.
+ *
* \since This function is available since SDL 3.2.0.
*
* \sa SDL_CreateMutex
@@ -457,6 +468,8 @@ typedef struct SDL_RWLock SDL_RWLock;
* \returns the initialized and unlocked read/write lock or NULL on failure;
* call SDL_GetError() for more information.
*
+ * \threadsafety It is safe to call this function from any thread.
+ *
* \since This function is available since SDL 3.2.0.
*
* \sa SDL_DestroyRWLock
@@ -497,6 +510,8 @@ extern SDL_DECLSPEC SDL_RWLock * SDLCALL SDL_CreateRWLock(void);
*
* \param rwlock the read/write lock to lock.
*
+ * \threadsafety It is safe to call this function from any thread.
+ *
* \since This function is available since SDL 3.2.0.
*
* \sa SDL_LockRWLockForWriting
@@ -528,6 +543,8 @@ extern SDL_DECLSPEC void SDLCALL SDL_LockRWLockForReading(SDL_RWLock *rwlock) SD
*
* \param rwlock the read/write lock to lock.
*
+ * \threadsafety It is safe to call this function from any thread.
+ *
* \since This function is available since SDL 3.2.0.
*
* \sa SDL_LockRWLockForReading
@@ -553,6 +570,8 @@ extern SDL_DECLSPEC void SDLCALL SDL_LockRWLockForWriting(SDL_RWLock *rwlock) SD
* \param rwlock the rwlock to try to lock.
* \returns true on success, false if the lock would block.
*
+ * \threadsafety It is safe to call this function from any thread.
+ *
* \since This function is available since SDL 3.2.0.
*
* \sa SDL_LockRWLockForReading
@@ -583,6 +602,8 @@ extern SDL_DECLSPEC bool SDLCALL SDL_TryLockRWLockForReading(SDL_RWLock *rwlock)
* \param rwlock the rwlock to try to lock.
* \returns true on success, false if the lock would block.
*
+ * \threadsafety It is safe to call this function from any thread.
+ *
* \since This function is available since SDL 3.2.0.
*
* \sa SDL_LockRWLockForWriting
@@ -607,6 +628,9 @@ extern SDL_DECLSPEC bool SDLCALL SDL_TryLockRWLockForWriting(SDL_RWLock *rwlock)
*
* \param rwlock the rwlock to unlock.
*
+ * \threadsafety This call must be paired with a previous locking call on the
+ * same thread.
+ *
* \since This function is available since SDL 3.2.0.
*
* \sa SDL_LockRWLockForReading
@@ -627,6 +651,8 @@ extern SDL_DECLSPEC void SDLCALL SDL_UnlockRWLock(SDL_RWLock *rwlock) SDL_RELEAS
*
* \param rwlock the rwlock to destroy.
*
+ * \threadsafety It is safe to call this function from any thread.
+ *
* \since This function is available since SDL 3.2.0.
*
* \sa SDL_CreateRWLock
@@ -670,6 +696,8 @@ typedef struct SDL_Semaphore SDL_Semaphore;
* \returns a new semaphore or NULL on failure; call SDL_GetError() for more
* information.
*
+ * \threadsafety It is safe to call this function from any thread.
+ *
* \since This function is available since SDL 3.2.0.
*
* \sa SDL_DestroySemaphore
@@ -689,6 +717,8 @@ extern SDL_DECLSPEC SDL_Semaphore * SDLCALL SDL_CreateSemaphore(Uint32 initial_v
*
* \param sem the semaphore to destroy.
*
+ * \threadsafety It is safe to call this function from any thread.
+ *
* \since This function is available since SDL 3.2.0.
*
* \sa SDL_CreateSemaphore
@@ -707,6 +737,8 @@ extern SDL_DECLSPEC void SDLCALL SDL_DestroySemaphore(SDL_Semaphore *sem);
*
* \param sem the semaphore wait on.
*
+ * \threadsafety It is safe to call this function from any thread.
+ *
* \since This function is available since SDL 3.2.0.
*
* \sa SDL_SignalSemaphore
@@ -726,6 +758,8 @@ extern SDL_DECLSPEC void SDLCALL SDL_WaitSemaphore(SDL_Semaphore *sem);
* \param sem the semaphore to wait on.
* \returns true if the wait succeeds, false if the wait would block.
*
+ * \threadsafety It is safe to call this function from any thread.
+ *
* \since This function is available since SDL 3.2.0.
*
* \sa SDL_SignalSemaphore
@@ -746,6 +780,8 @@ extern SDL_DECLSPEC bool SDLCALL SDL_TryWaitSemaphore(SDL_Semaphore *sem);
* indefinitely.
* \returns true if the wait succeeds or false if the wait times out.
*
+ * \threadsafety It is safe to call this function from any thread.
+ *
* \since This function is available since SDL 3.2.0.
*
* \sa SDL_SignalSemaphore
@@ -759,6 +795,8 @@ extern SDL_DECLSPEC bool SDLCALL SDL_WaitSemaphoreTimeout(SDL_Semaphore *sem, Si
*
* \param sem the semaphore to increment.
*
+ * \threadsafety It is safe to call this function from any thread.
+ *
* \since This function is available since SDL 3.2.0.
*
* \sa SDL_TryWaitSemaphore
@@ -773,6 +811,8 @@ extern SDL_DECLSPEC void SDLCALL SDL_SignalSemaphore(SDL_Semaphore *sem);
* \param sem the semaphore to query.
* \returns the current value of the semaphore.
*
+ * \threadsafety It is safe to call this function from any thread.
+ *
* \since This function is available since SDL 3.2.0.
*/
extern SDL_DECLSPEC Uint32 SDLCALL SDL_GetSemaphoreValue(SDL_Semaphore *sem);
@@ -806,6 +846,8 @@ typedef struct SDL_Condition SDL_Condition;
* \returns a new condition variable or NULL on failure; call SDL_GetError()
* for more information.
*
+ * \threadsafety It is safe to call this function from any thread.
+ *
* \since This function is available since SDL 3.2.0.
*
* \sa SDL_BroadcastCondition
@@ -821,6 +863,8 @@ extern SDL_DECLSPEC SDL_Condition * SDLCALL SDL_CreateCondition(void);
*
* \param cond the condition variable to destroy.
*
+ * \threadsafety It is safe to call this function from any thread.
+ *
* \since This function is available since SDL 3.2.0.
*
* \sa SDL_CreateCondition
@@ -942,7 +986,7 @@ typedef enum SDL_InitStatus
* Here is an example of using this:
*
* ```c
- * static SDL_AtomicInitState init;
+ * static SDL_InitState init;
*
* bool InitSystem(void)
* {
diff --git a/thirdparty/sdl/include/SDL3/SDL_pen.h b/thirdparty/sdl/include/SDL3/SDL_pen.h
index 5182eeb0ce1..63f32bb68a2 100644
--- a/thirdparty/sdl/include/SDL3/SDL_pen.h
+++ b/thirdparty/sdl/include/SDL3/SDL_pen.h
@@ -1,6 +1,6 @@
/*
Simple DirectMedia Layer
- Copyright (C) 1997-2025 Sam Lantinga <[email protected]>
+ Copyright (C) 1997-2026 Sam Lantinga <[email protected]>
This software is provided 'as-is', without any express or implied
warranty. In no event will the authors be held liable for any damages
@@ -28,12 +28,37 @@
* handling, e.g., for input and drawing tablets or suitably equipped mobile /
* tablet devices.
*
- * To get started with pens, simply handle SDL_EVENT_PEN_* events. When a pen
- * starts providing input, SDL will assign it a unique SDL_PenID, which will
- * remain for the life of the process, as long as the pen stays connected.
+ * To get started with pens, simply handle pen events:
+ *
+ * - SDL_EVENT_PEN_PROXIMITY_IN, SDL_EVENT_PEN_PROXIMITY_OUT
+ * (SDL_PenProximityEvent)
+ * - SDL_EVENT_PEN_DOWN, SDL_EVENT_PEN_UP (SDL_PenTouchEvent)
+ * - SDL_EVENT_PEN_MOTION (SDL_PenMotionEvent)
+ * - SDL_EVENT_PEN_BUTTON_DOWN, SDL_EVENT_PEN_BUTTON_UP (SDL_PenButtonEvent)
+ * - SDL_EVENT_PEN_AXIS (SDL_PenAxisEvent)
*
* Pens may provide more than simple touch input; they might have other axes,
* such as pressure, tilt, rotation, etc.
+ *
+ * When a pen starts providing input, SDL will assign it a unique SDL_PenID,
+ * which will remain for the life of the process, as long as the pen stays
+ * connected. A pen leaving proximity (being taken far enough away from the
+ * digitizer tablet that it no longer reponds) and then coming back should
+ * fire proximity events, but the SDL_PenID should remain consistent.
+ * Unplugging the digitizer and reconnecting may cause future input to have a
+ * new SDL_PenID, as SDL may not know that this is the same hardware.
+ *
+ * Please note that various platforms vary wildly in how (and how well) they
+ * support pen input. If your pen supports some piece of functionality but SDL
+ * doesn't seem to, it might actually be the operating system's fault. For
+ * example, some platforms can manage multiple devices at the same time, but
+ * others will make any connected pens look like a single logical device, much
+ * how all USB mice connected to a computer will move the same system cursor.
+ * Other platforms might not support pen buttons, or the distance axis, etc.
+ * Very few platforms can even report _what_ functionality the pen supports in
+ * the first place, so best practices is to either build UI to let the user
+ * configure their pens, or be prepared to handle new functionality for a pen
+ * the first time an event is reported.
*/
#ifndef SDL_pen_h_
@@ -43,6 +68,7 @@
#include <SDL3/SDL_mouse.h>
#include <SDL3/SDL_touch.h>
+#include <SDL3/SDL_begin_code.h>
/* Set up for C function definitions, even when using C++ */
#ifdef __cplusplus
extern "C" {
@@ -55,7 +81,12 @@ extern "C" {
*
* These show up in pen events when SDL sees input from them. They remain
* consistent as long as SDL can recognize a tool to be the same pen; but if a
- * pen physically leaves the area and returns, it might get a new ID.
+ * pen's digitizer table is physically detached from the computer, it might
+ * get a new ID when reconnected, as SDL won't know it's the same device.
+ *
+ * These IDs are only stable within a single run of a program; the next time a
+ * program is run, the pen's ID will likely be different, even if the hardware
+ * hasn't been disconnected, etc.
*
* \since This datatype is available since SDL 3.2.0.
*/
@@ -75,7 +106,6 @@ typedef Uint32 SDL_PenID;
*/
#define SDL_PEN_TOUCHID ((SDL_TouchID)-2)
-
/**
* Pen input flags, as reported by various pen events' `pen_state` field.
*
@@ -83,13 +113,14 @@ typedef Uint32 SDL_PenID;
*/
typedef Uint32 SDL_PenInputFlags;
-#define SDL_PEN_INPUT_DOWN (1u << 0) /**< pen is pressed down */
-#define SDL_PEN_INPUT_BUTTON_1 (1u << 1) /**< button 1 is pressed */
-#define SDL_PEN_INPUT_BUTTON_2 (1u << 2) /**< button 2 is pressed */
-#define SDL_PEN_INPUT_BUTTON_3 (1u << 3) /**< button 3 is pressed */
-#define SDL_PEN_INPUT_BUTTON_4 (1u << 4) /**< button 4 is pressed */
-#define SDL_PEN_INPUT_BUTTON_5 (1u << 5) /**< button 5 is pressed */
-#define SDL_PEN_INPUT_ERASER_TIP (1u << 30) /**< eraser tip is used */
+#define SDL_PEN_INPUT_DOWN (1u << 0) /**< pen is pressed down */
+#define SDL_PEN_INPUT_BUTTON_1 (1u << 1) /**< button 1 is pressed */
+#define SDL_PEN_INPUT_BUTTON_2 (1u << 2) /**< button 2 is pressed */
+#define SDL_PEN_INPUT_BUTTON_3 (1u << 3) /**< button 3 is pressed */
+#define SDL_PEN_INPUT_BUTTON_4 (1u << 4) /**< button 4 is pressed */
+#define SDL_PEN_INPUT_BUTTON_5 (1u << 5) /**< button 5 is pressed */
+#define SDL_PEN_INPUT_ERASER_TIP (1u << 30) /**< eraser tip is used */
+#define SDL_PEN_INPUT_IN_PROXIMITY (1u << 31) /**< pen is in proximity (since SDL 3.4.0) */
/**
* Pen axis indices.
@@ -118,10 +149,50 @@ typedef enum SDL_PenAxis
SDL_PEN_AXIS_COUNT /**< Total known pen axis types in this version of SDL. This number may grow in future releases! */
} SDL_PenAxis;
+/**
+ * An enum that describes the type of a pen device.
+ *
+ * A "direct" device is a pen that touches a graphic display (like an Apple
+ * Pencil on an iPad's screen). "Indirect" devices touch an external tablet
+ * surface that is connected to the machine but is not a display (like a
+ * lower-end Wacom tablet connected over USB).
+ *
+ * Apps may use this information to decide if they should draw a cursor; if
+ * the pen is touching the screen directly, a cursor doesn't make sense and
+ * can be in the way, but becomes necessary for indirect devices to know where
+ * on the display they are interacting.
+ *
+ * \since This enum is available since SDL 3.4.0.
+ */
+typedef enum SDL_PenDeviceType
+{
+ SDL_PEN_DEVICE_TYPE_INVALID = -1, /**< Not a valid pen device. */
+ SDL_PEN_DEVICE_TYPE_UNKNOWN, /**< Don't know specifics of this pen. */
+ SDL_PEN_DEVICE_TYPE_DIRECT, /**< Pen touches display. */
+ SDL_PEN_DEVICE_TYPE_INDIRECT /**< Pen touches something that isn't the display. */
+} SDL_PenDeviceType;
+
+/**
+ * Get the device type of the given pen.
+ *
+ * Many platforms do not supply this information, so an app must always be
+ * prepared to get an SDL_PEN_DEVICE_TYPE_UNKNOWN result.
+ *
+ * \param instance_id the pen instance ID.
+ * \returns the device type of the given pen, or SDL_PEN_DEVICE_TYPE_INVALID
+ * on failure; call SDL_GetError() for more information.
+ *
+ * \threadsafety It is safe to call this function from any thread.
+ *
+ * \since This function is available since SDL 3.4.0.
+ */
+extern SDL_DECLSPEC SDL_PenDeviceType SDLCALL SDL_GetPenDeviceType(SDL_PenID instance_id);
+
/* Ends C function definitions when using C++ */
#ifdef __cplusplus
}
#endif
+#include <SDL3/SDL_close_code.h>
#endif /* SDL_pen_h_ */
diff --git a/thirdparty/sdl/include/SDL3/SDL_pixels.h b/thirdparty/sdl/include/SDL3/SDL_pixels.h
index 39596c1c986..475e5f9c383 100644
--- a/thirdparty/sdl/include/SDL3/SDL_pixels.h
+++ b/thirdparty/sdl/include/SDL3/SDL_pixels.h
@@ -1,6 +1,6 @@
/*
Simple DirectMedia Layer
- Copyright (C) 1997-2025 Sam Lantinga <[email protected]>
+ Copyright (C) 1997-2026 Sam Lantinga <[email protected]>
This software is provided 'as-is', without any express or implied
warranty. In no event will the authors be held liable for any damages
@@ -451,7 +451,7 @@ typedef enum SDL_PackedLayout
* expressions with side-effects here.
*
* \param format an SDL_PixelFormat to check.
- * \returns true if the format is 10-bit, false otherwise.
+ * \returns true if the format is a floating point, false otherwise.
*
* \threadsafety It is safe to call this macro from any thread.
*
@@ -1096,7 +1096,7 @@ typedef enum SDL_Colorspace
SDL_CHROMA_LOCATION_LEFT), */
SDL_COLORSPACE_RGB_DEFAULT = SDL_COLORSPACE_SRGB, /**< The default colorspace for RGB surfaces if no colorspace is specified */
- SDL_COLORSPACE_YUV_DEFAULT = SDL_COLORSPACE_JPEG /**< The default colorspace for YUV surfaces if no colorspace is specified */
+ SDL_COLORSPACE_YUV_DEFAULT = SDL_COLORSPACE_BT601_LIMITED /**< The default colorspace for YUV surfaces if no colorspace is specified */
} SDL_Colorspace;
/**
@@ -1379,7 +1379,7 @@ extern SDL_DECLSPEC Uint32 SDLCALL SDL_MapRGBA(const SDL_PixelFormatDetails *for
* (e.g., a completely white pixel in 16-bit RGB565 format would return [0xff,
* 0xff, 0xff] not [0xf8, 0xfc, 0xf8]).
*
- * \param pixel a pixel value.
+ * \param pixelvalue a pixel value.
* \param format a pointer to SDL_PixelFormatDetails describing the pixel
* format.
* \param palette an optional palette for indexed formats, may be NULL.
@@ -1397,7 +1397,7 @@ extern SDL_DECLSPEC Uint32 SDLCALL SDL_MapRGBA(const SDL_PixelFormatDetails *for
* \sa SDL_MapRGB
* \sa SDL_MapRGBA
*/
-extern SDL_DECLSPEC void SDLCALL SDL_GetRGB(Uint32 pixel, const SDL_PixelFormatDetails *format, const SDL_Palette *palette, Uint8 *r, Uint8 *g, Uint8 *b);
+extern SDL_DECLSPEC void SDLCALL SDL_GetRGB(Uint32 pixelvalue, const SDL_PixelFormatDetails *format, const SDL_Palette *palette, Uint8 *r, Uint8 *g, Uint8 *b);
/**
* Get RGBA values from a pixel in the specified format.
@@ -1410,7 +1410,7 @@ extern SDL_DECLSPEC void SDLCALL SDL_GetRGB(Uint32 pixel, const SDL_PixelFormatD
* If the surface has no alpha component, the alpha will be returned as 0xff
* (100% opaque).
*
- * \param pixel a pixel value.
+ * \param pixelvalue a pixel value.
* \param format a pointer to SDL_PixelFormatDetails describing the pixel
* format.
* \param palette an optional palette for indexed formats, may be NULL.
@@ -1429,7 +1429,7 @@ extern SDL_DECLSPEC void SDLCALL SDL_GetRGB(Uint32 pixel, const SDL_PixelFormatD
* \sa SDL_MapRGB
* \sa SDL_MapRGBA
*/
-extern SDL_DECLSPEC void SDLCALL SDL_GetRGBA(Uint32 pixel, const SDL_PixelFormatDetails *format, const SDL_Palette *palette, Uint8 *r, Uint8 *g, Uint8 *b, Uint8 *a);
+extern SDL_DECLSPEC void SDLCALL SDL_GetRGBA(Uint32 pixelvalue, const SDL_PixelFormatDetails *format, const SDL_Palette *palette, Uint8 *r, Uint8 *g, Uint8 *b, Uint8 *a);
/* Ends C function definitions when using C++ */
diff --git a/thirdparty/sdl/include/SDL3/SDL_platform.h b/thirdparty/sdl/include/SDL3/SDL_platform.h
index e40f009bad6..9ad380bab02 100644
--- a/thirdparty/sdl/include/SDL3/SDL_platform.h
+++ b/thirdparty/sdl/include/SDL3/SDL_platform.h
@@ -1,6 +1,6 @@
/*
Simple DirectMedia Layer
- Copyright (C) 1997-2025 Sam Lantinga <[email protected]>
+ Copyright (C) 1997-2026 Sam Lantinga <[email protected]>
This software is provided 'as-is', without any express or implied
warranty. In no event will the authors be held liable for any damages
@@ -51,6 +51,8 @@ extern "C" {
* \returns the name of the platform. If the correct platform name is not
* available, returns a string beginning with the text "Unknown".
*
+ * \threadsafety It is safe to call this function from any thread.
+ *
* \since This function is available since SDL 3.2.0.
*/
extern SDL_DECLSPEC const char * SDLCALL SDL_GetPlatform(void);
diff --git a/thirdparty/sdl/include/SDL3/SDL_platform_defines.h b/thirdparty/sdl/include/SDL3/SDL_platform_defines.h
index 6b240a8be45..79631491de2 100644
--- a/thirdparty/sdl/include/SDL3/SDL_platform_defines.h
+++ b/thirdparty/sdl/include/SDL3/SDL_platform_defines.h
@@ -1,6 +1,6 @@
/*
Simple DirectMedia Layer
- Copyright (C) 1997-2025 Sam Lantinga <[email protected]>
+ Copyright (C) 1997-2026 Sam Lantinga <[email protected]>
This software is provided 'as-is', without any express or implied
warranty. In no event will the authors be held liable for any damages
@@ -190,7 +190,7 @@
#if TARGET_OS_VISION
/**
- * A preprocessor macro that is only defined if compiling for VisionOS.
+ * A preprocessor macro that is only defined if compiling for visionOS.
*
* \since This macro is available since SDL 3.2.0.
*
@@ -202,7 +202,7 @@
#if TARGET_OS_IPHONE
/**
- * A preprocessor macro that is only defined if compiling for iOS.
+ * A preprocessor macro that is only defined if compiling for iOS or visionOS.
*
* \since This macro is available since SDL 3.2.0.
*
@@ -317,7 +317,7 @@
#define SDL_PLATFORM_CYGWIN 1
#endif
-#if defined(_WIN32) || defined(SDL_PLATFORM_CYGWIN)
+#if (defined(_WIN32) || defined(SDL_PLATFORM_CYGWIN)) && !defined(__NGAGE__)
/**
* A preprocessor macro that is only defined if compiling for Windows.
@@ -473,4 +473,25 @@
#define SDL_PLATFORM_3DS 1
#endif
+#ifdef __NGAGE__
+
+/**
+ * A preprocessor macro that is only defined if compiling for the Nokia
+ * N-Gage.
+ *
+ * \since This macro is available since SDL 3.4.0.
+ */
+#define SDL_PLATFORM_NGAGE 1
+#endif
+
+#ifdef __GNU__
+
+/**
+ * A preprocessor macro that is only defined if compiling for GNU/Hurd.
+ *
+ * \since This macro is available since SDL 3.4.0.
+ */
+#define SDL_PLATFORM_HURD 1
+#endif
+
#endif /* SDL_platform_defines_h_ */
diff --git a/thirdparty/sdl/include/SDL3/SDL_power.h b/thirdparty/sdl/include/SDL3/SDL_power.h
index 694fb0924d3..0616cc27588 100644
--- a/thirdparty/sdl/include/SDL3/SDL_power.h
+++ b/thirdparty/sdl/include/SDL3/SDL_power.h
@@ -1,6 +1,6 @@
/*
Simple DirectMedia Layer
- Copyright (C) 1997-2025 Sam Lantinga <[email protected]>
+ Copyright (C) 1997-2026 Sam Lantinga <[email protected]>
This software is provided 'as-is', without any express or implied
warranty. In no event will the authors be held liable for any damages
@@ -88,11 +88,13 @@ typedef enum SDL_PowerState
* can't determine a value or there is no battery.
* \param percent a pointer filled in with the percentage of battery life
* left, between 0 and 100, or NULL to ignore. This will be
- * filled in with -1 we can't determine a value or there is no
- * battery.
+ * filled in with -1 when we can't determine a value or there
+ * is no battery.
* \returns the current battery state or `SDL_POWERSTATE_ERROR` on failure;
* call SDL_GetError() for more information.
*
+ * \threadsafety This function is not thread safe.
+ *
* \since This function is available since SDL 3.2.0.
*/
extern SDL_DECLSPEC SDL_PowerState SDLCALL SDL_GetPowerInfo(int *seconds, int *percent);
diff --git a/thirdparty/sdl/include/SDL3/SDL_process.h b/thirdparty/sdl/include/SDL3/SDL_process.h
index 511b2f9c51f..b797890d8b3 100644
--- a/thirdparty/sdl/include/SDL3/SDL_process.h
+++ b/thirdparty/sdl/include/SDL3/SDL_process.h
@@ -1,6 +1,6 @@
/*
Simple DirectMedia Layer
- Copyright (C) 1997-2025 Sam Lantinga <[email protected]>
+ Copyright (C) 1997-2026 Sam Lantinga <[email protected]>
This software is provided 'as-is', without any express or implied
warranty. In no event will the authors be held liable for any damages
@@ -166,6 +166,9 @@ typedef enum SDL_ProcessIO
* - `SDL_PROP_PROCESS_CREATE_ENVIRONMENT_POINTER`: an SDL_Environment
* pointer. If this property is set, it will be the entire environment for
* the process, otherwise the current environment is used.
+ * - `SDL_PROP_PROCESS_CREATE_WORKING_DIRECTORY_STRING`: a UTF-8 encoded
+ * string representing the working directory for the process, defaults to
+ * the current working directory.
* - `SDL_PROP_PROCESS_CREATE_STDIN_NUMBER`: an SDL_ProcessIO value describing
* where standard input for the process comes from, defaults to
* `SDL_PROCESS_STDIO_NULL`.
@@ -192,6 +195,12 @@ typedef enum SDL_ProcessIO
* run in the background. In this case the default input and output is
* `SDL_PROCESS_STDIO_NULL` and the exitcode of the process is not
* available, and will always be 0.
+ * - `SDL_PROP_PROCESS_CREATE_CMDLINE_STRING`: a string containing the program
+ * to run and any parameters. This string is passed directly to
+ * `CreateProcess` on Windows, and does nothing on other platforms. This
+ * property is only important if you want to start programs that does
+ * non-standard command-line processing, and in most cases using
+ * `SDL_PROP_PROCESS_CREATE_ARGS_POINTER` is sufficient.
*
* On POSIX platforms, wait() and waitpid(-1, ...) should not be called, and
* SIGCHLD should not be ignored or handled because those would prevent SDL
@@ -219,6 +228,7 @@ extern SDL_DECLSPEC SDL_Process * SDLCALL SDL_CreateProcessWithProperties(SDL_Pr
#define SDL_PROP_PROCESS_CREATE_ARGS_POINTER "SDL.process.create.args"
#define SDL_PROP_PROCESS_CREATE_ENVIRONMENT_POINTER "SDL.process.create.environment"
+#define SDL_PROP_PROCESS_CREATE_WORKING_DIRECTORY_STRING "SDL.process.create.working_directory"
#define SDL_PROP_PROCESS_CREATE_STDIN_NUMBER "SDL.process.create.stdin_option"
#define SDL_PROP_PROCESS_CREATE_STDIN_POINTER "SDL.process.create.stdin_source"
#define SDL_PROP_PROCESS_CREATE_STDOUT_NUMBER "SDL.process.create.stdout_option"
@@ -227,6 +237,7 @@ extern SDL_DECLSPEC SDL_Process * SDLCALL SDL_CreateProcessWithProperties(SDL_Pr
#define SDL_PROP_PROCESS_CREATE_STDERR_POINTER "SDL.process.create.stderr_source"
#define SDL_PROP_PROCESS_CREATE_STDERR_TO_STDOUT_BOOLEAN "SDL.process.create.stderr_to_stdout"
#define SDL_PROP_PROCESS_CREATE_BACKGROUND_BOOLEAN "SDL.process.create.background"
+#define SDL_PROP_PROCESS_CREATE_CMDLINE_STRING "SDL.process.create.cmdline"
/**
* Get the properties associated with a process.
diff --git a/thirdparty/sdl/include/SDL3/SDL_properties.h b/thirdparty/sdl/include/SDL3/SDL_properties.h
index 1f47d5f4ad8..abd7b2aa505 100644
--- a/thirdparty/sdl/include/SDL3/SDL_properties.h
+++ b/thirdparty/sdl/include/SDL3/SDL_properties.h
@@ -1,6 +1,6 @@
/*
Simple DirectMedia Layer
- Copyright (C) 1997-2025 Sam Lantinga <[email protected]>
+ Copyright (C) 1997-2026 Sam Lantinga <[email protected]>
This software is provided 'as-is', without any express or implied
warranty. In no event will the authors be held liable for any damages
@@ -59,7 +59,7 @@ extern "C" {
#endif
/**
- * SDL properties ID
+ * An ID that represents a properties set.
*
* \since This datatype is available since SDL 3.2.0.
*/
@@ -80,12 +80,39 @@ typedef enum SDL_PropertyType
SDL_PROPERTY_TYPE_BOOLEAN
} SDL_PropertyType;
+/**
+ * A generic property for naming things.
+ *
+ * This property is intended to be added to any SDL_PropertiesID that needs a
+ * generic name associated with the property set. It is not guaranteed that
+ * any property set will include this key, but it is convenient to have a
+ * standard key that any piece of code could reasonably agree to use.
+ *
+ * For example, the properties associated with an SDL_Texture might have a
+ * name string of "player sprites", or an SDL_AudioStream might have
+ * "background music", etc. This might also be useful for an SDL_IOStream to
+ * list the path to its asset.
+ *
+ * There is no format for the value set with this key; it is expected to be
+ * human-readable and informational in nature, possibly for logging or
+ * debugging purposes.
+ *
+ * SDL does not currently set this property on any objects it creates, but
+ * this may change in later versions; it is currently expected that apps and
+ * external libraries will take advantage of it, when appropriate.
+ *
+ * \since This macro is available since SDL 3.4.0.
+ */
+#define SDL_PROP_NAME_STRING "SDL.name"
+
/**
* Get the global SDL properties.
*
* \returns a valid property ID on success or 0 on failure; call
* SDL_GetError() for more information.
*
+ * \threadsafety It is safe to call this function from any thread.
+ *
* \since This function is available since SDL 3.2.0.
*/
extern SDL_DECLSPEC SDL_PropertiesID SDLCALL SDL_GetGlobalProperties(void);
@@ -119,7 +146,9 @@ extern SDL_DECLSPEC SDL_PropertiesID SDLCALL SDL_CreateProperties(void);
* \returns true on success or false on failure; call SDL_GetError() for more
* information.
*
- * \threadsafety It is safe to call this function from any thread.
+ * \threadsafety It is safe to call this function from any thread. This
+ * function acquires simultaneous mutex locks on both the source
+ * and destination property sets.
*
* \since This function is available since SDL 3.2.0.
*/
diff --git a/thirdparty/sdl/include/SDL3/SDL_rect.h b/thirdparty/sdl/include/SDL3/SDL_rect.h
index 603f7b39046..5f395ec441d 100644
--- a/thirdparty/sdl/include/SDL3/SDL_rect.h
+++ b/thirdparty/sdl/include/SDL3/SDL_rect.h
@@ -1,6 +1,6 @@
/*
Simple DirectMedia Layer
- Copyright (C) 1997-2025 Sam Lantinga <[email protected]>
+ Copyright (C) 1997-2026 Sam Lantinga <[email protected]>
This software is provided 'as-is', without any express or implied
warranty. In no event will the authors be held liable for any damages
@@ -88,8 +88,11 @@ typedef struct SDL_Rect
/**
- * A rectangle, with the origin at the upper left (using floating point
- * values).
+ * A rectangle stored using floating point values.
+ *
+ * The origin of the coordinate space is in the top-left, with increasing
+ * values moving down and right. The properties `x` and `y` represent the
+ * coordinates of the top-left corner of the rectangle.
*
* \since This struct is available since SDL 3.2.0.
*
@@ -234,6 +237,8 @@ extern SDL_DECLSPEC bool SDLCALL SDL_HasRectIntersection(const SDL_Rect *A, cons
* rectangles `A` and `B`.
* \returns true if there is an intersection, false otherwise.
*
+ * \threadsafety It is safe to call this function from any thread.
+ *
* \since This function is available since SDL 3.2.0.
*
* \sa SDL_HasRectIntersection
@@ -250,6 +255,8 @@ extern SDL_DECLSPEC bool SDLCALL SDL_GetRectIntersection(const SDL_Rect *A, cons
* \returns true on success or false on failure; call SDL_GetError() for more
* information.
*
+ * \threadsafety It is safe to call this function from any thread.
+ *
* \since This function is available since SDL 3.2.0.
*/
extern SDL_DECLSPEC bool SDLCALL SDL_GetRectUnion(const SDL_Rect *A, const SDL_Rect *B, SDL_Rect *result);
@@ -269,6 +276,8 @@ extern SDL_DECLSPEC bool SDLCALL SDL_GetRectUnion(const SDL_Rect *A, const SDL_R
* \returns true if any points were enclosed or false if all the points were
* outside of the clipping rectangle.
*
+ * \threadsafety It is safe to call this function from any thread.
+ *
* \since This function is available since SDL 3.2.0.
*/
extern SDL_DECLSPEC bool SDLCALL SDL_GetRectEnclosingPoints(const SDL_Point *points, int count, const SDL_Rect *clip, SDL_Rect *result);
@@ -289,6 +298,8 @@ extern SDL_DECLSPEC bool SDLCALL SDL_GetRectEnclosingPoints(const SDL_Point *poi
* \param Y2 a pointer to the ending Y-coordinate of the line.
* \returns true if there is an intersection, false otherwise.
*
+ * \threadsafety It is safe to call this function from any thread.
+ *
* \since This function is available since SDL 3.2.0.
*/
extern SDL_DECLSPEC bool SDLCALL SDL_GetRectAndLineIntersection(const SDL_Rect *rect, int *X1, int *Y1, int *X2, int *Y2);
@@ -324,7 +335,7 @@ SDL_FORCE_INLINE bool SDL_PointInRectFloat(const SDL_FPoint *p, const SDL_FRect
}
/**
- * Determine whether a floating point rectangle can contain any point.
+ * Determine whether a floating point rectangle takes no space.
*
* A rectangle is considered "empty" for this function if `r` is NULL, or if
* `r`'s width and/or height are < 0.0f.
@@ -420,9 +431,11 @@ SDL_FORCE_INLINE bool SDL_RectsEqualFloat(const SDL_FRect *a, const SDL_FRect *b
* \param B an SDL_FRect structure representing the second rectangle.
* \returns true if there is an intersection, false otherwise.
*
+ * \threadsafety It is safe to call this function from any thread.
+ *
* \since This function is available since SDL 3.2.0.
*
- * \sa SDL_GetRectIntersection
+ * \sa SDL_GetRectIntersectionFloat
*/
extern SDL_DECLSPEC bool SDLCALL SDL_HasRectIntersectionFloat(const SDL_FRect *A, const SDL_FRect *B);
@@ -437,6 +450,8 @@ extern SDL_DECLSPEC bool SDLCALL SDL_HasRectIntersectionFloat(const SDL_FRect *A
* rectangles `A` and `B`.
* \returns true if there is an intersection, false otherwise.
*
+ * \threadsafety It is safe to call this function from any thread.
+ *
* \since This function is available since SDL 3.2.0.
*
* \sa SDL_HasRectIntersectionFloat
@@ -453,6 +468,8 @@ extern SDL_DECLSPEC bool SDLCALL SDL_GetRectIntersectionFloat(const SDL_FRect *A
* \returns true on success or false on failure; call SDL_GetError() for more
* information.
*
+ * \threadsafety It is safe to call this function from any thread.
+ *
* \since This function is available since SDL 3.2.0.
*/
extern SDL_DECLSPEC bool SDLCALL SDL_GetRectUnionFloat(const SDL_FRect *A, const SDL_FRect *B, SDL_FRect *result);
@@ -473,6 +490,8 @@ extern SDL_DECLSPEC bool SDLCALL SDL_GetRectUnionFloat(const SDL_FRect *A, const
* \returns true if any points were enclosed or false if all the points were
* outside of the clipping rectangle.
*
+ * \threadsafety It is safe to call this function from any thread.
+ *
* \since This function is available since SDL 3.2.0.
*/
extern SDL_DECLSPEC bool SDLCALL SDL_GetRectEnclosingPointsFloat(const SDL_FPoint *points, int count, const SDL_FRect *clip, SDL_FRect *result);
@@ -494,6 +513,8 @@ extern SDL_DECLSPEC bool SDLCALL SDL_GetRectEnclosingPointsFloat(const SDL_FPoin
* \param Y2 a pointer to the ending Y-coordinate of the line.
* \returns true if there is an intersection, false otherwise.
*
+ * \threadsafety It is safe to call this function from any thread.
+ *
* \since This function is available since SDL 3.2.0.
*/
extern SDL_DECLSPEC bool SDLCALL SDL_GetRectAndLineIntersectionFloat(const SDL_FRect *rect, float *X1, float *Y1, float *X2, float *Y2);
diff --git a/thirdparty/sdl/include/SDL3/SDL_render.h b/thirdparty/sdl/include/SDL3/SDL_render.h
index e7928118abf..14d37908087 100644
--- a/thirdparty/sdl/include/SDL3/SDL_render.h
+++ b/thirdparty/sdl/include/SDL3/SDL_render.h
@@ -1,6 +1,6 @@
/*
Simple DirectMedia Layer
- Copyright (C) 1997-2025 Sam Lantinga <[email protected]>
+ Copyright (C) 1997-2026 Sam Lantinga <[email protected]>
This software is provided 'as-is', without any express or implied
warranty. In no event will the authors be held liable for any damages
@@ -39,9 +39,9 @@
* may also be stretched with linear interpolation.
*
* This API is designed to accelerate simple 2D operations. You may want more
- * functionality such as polygons and particle effects and in that case you
- * should use SDL's OpenGL/Direct3D support, the SDL3 GPU API, or one of the
- * many good 3D engines.
+ * functionality such as 3D polygons and particle effects, and in that case
+ * you should use SDL's OpenGL/Direct3D support, the SDL3 GPU API, or one of
+ * the many good 3D engines.
*
* These functions must be called from the main thread. See this bug for
* details: https://github.com/libsdl-org/SDL/issues/986
@@ -59,6 +59,7 @@
#include <SDL3/SDL_rect.h>
#include <SDL3/SDL_surface.h>
#include <SDL3/SDL_video.h>
+// #include <SDL3/SDL_gpu.h>
#include <SDL3/SDL_begin_code.h>
/* Set up for C function definitions, even when using C++ */
@@ -73,6 +74,13 @@ extern "C" {
*/
#define SDL_SOFTWARE_RENDERER "software"
+/**
+ * The name of the GPU renderer.
+ *
+ * \since This macro is available since SDL 3.4.0.
+ */
+#define SDL_GPU_RENDERER "gpu"
+
/**
* Vertex structure.
*
@@ -97,6 +105,25 @@ typedef enum SDL_TextureAccess
SDL_TEXTUREACCESS_TARGET /**< Texture can be used as a render target */
} SDL_TextureAccess;
+/**
+ * The addressing mode for a texture when used in SDL_RenderGeometry().
+ *
+ * This affects how texture coordinates are interpreted outside of [0, 1]
+ *
+ * Texture wrapping is always supported for power of two texture sizes, and is
+ * supported for other texture sizes if
+ * SDL_PROP_RENDERER_TEXTURE_WRAPPING_BOOLEAN is set to true.
+ *
+ * \since This enum is available since SDL 3.4.0.
+ */
+typedef enum SDL_TextureAddressMode
+{
+ SDL_TEXTURE_ADDRESS_INVALID = -1,
+ SDL_TEXTURE_ADDRESS_AUTO, /**< Wrapping is enabled if texture coordinates are outside [0, 1], this is the default */
+ SDL_TEXTURE_ADDRESS_CLAMP, /**< Texture coordinates are clamped to the [0, 1] range */
+ SDL_TEXTURE_ADDRESS_WRAP /**< The texture is repeated (tiled) */
+} SDL_TextureAddressMode;
+
/**
* How the logical size is mapped to the output.
*
@@ -106,7 +133,7 @@ typedef enum SDL_RendererLogicalPresentation
{
SDL_LOGICAL_PRESENTATION_DISABLED, /**< There is no logical size in effect */
SDL_LOGICAL_PRESENTATION_STRETCH, /**< The rendered content is stretched to the output resolution */
- SDL_LOGICAL_PRESENTATION_LETTERBOX, /**< The rendered content is fit to the largest dimension and the other dimension is letterboxed with black bars */
+ SDL_LOGICAL_PRESENTATION_LETTERBOX, /**< The rendered content is fit to the largest dimension and the other dimension is letterboxed with the clear color */
SDL_LOGICAL_PRESENTATION_OVERSCAN, /**< The rendered content is fit to the smallest dimension and the other dimension extends beyond the output bounds */
SDL_LOGICAL_PRESENTATION_INTEGER_SCALE /**< The rendered content is scaled up by integer multiples to fit the output resolution */
} SDL_RendererLogicalPresentation;
@@ -267,6 +294,17 @@ extern SDL_DECLSPEC SDL_Renderer * SDLCALL SDL_CreateRenderer(SDL_Window *window
* present synchronized with the refresh rate. This property can take any
* value that is supported by SDL_SetRenderVSync() for the renderer.
*
+ * With the SDL GPU renderer (since SDL 3.4.0):
+ *
+ * - `SDL_PROP_RENDERER_CREATE_GPU_DEVICE_POINTER`: the device to use with the
+ * renderer, optional.
+ * - `SDL_PROP_RENDERER_CREATE_GPU_SHADERS_SPIRV_BOOLEAN`: the app is able to
+ * provide SPIR-V shaders to SDL_GPURenderState, optional.
+ * - `SDL_PROP_RENDERER_CREATE_GPU_SHADERS_DXIL_BOOLEAN`: the app is able to
+ * provide DXIL shaders to SDL_GPURenderState, optional.
+ * - `SDL_PROP_RENDERER_CREATE_GPU_SHADERS_MSL_BOOLEAN`: the app is able to
+ * provide MSL shaders to SDL_GPURenderState, optional.
+ *
* With the vulkan renderer:
*
* - `SDL_PROP_RENDERER_CREATE_VULKAN_INSTANCE_POINTER`: the VkInstance to use
@@ -303,6 +341,10 @@ extern SDL_DECLSPEC SDL_Renderer * SDLCALL SDL_CreateRendererWithProperties(SDL_
#define SDL_PROP_RENDERER_CREATE_SURFACE_POINTER "SDL.renderer.create.surface"
#define SDL_PROP_RENDERER_CREATE_OUTPUT_COLORSPACE_NUMBER "SDL.renderer.create.output_colorspace"
#define SDL_PROP_RENDERER_CREATE_PRESENT_VSYNC_NUMBER "SDL.renderer.create.present_vsync"
+#define SDL_PROP_RENDERER_CREATE_GPU_DEVICE_POINTER "SDL.renderer.create.gpu.device"
+#define SDL_PROP_RENDERER_CREATE_GPU_SHADERS_SPIRV_BOOLEAN "SDL.renderer.create.gpu.shaders_spirv"
+#define SDL_PROP_RENDERER_CREATE_GPU_SHADERS_DXIL_BOOLEAN "SDL.renderer.create.gpu.shaders_dxil"
+#define SDL_PROP_RENDERER_CREATE_GPU_SHADERS_MSL_BOOLEAN "SDL.renderer.create.gpu.shaders_msl"
#define SDL_PROP_RENDERER_CREATE_VULKAN_INSTANCE_POINTER "SDL.renderer.create.vulkan.instance"
#define SDL_PROP_RENDERER_CREATE_VULKAN_SURFACE_NUMBER "SDL.renderer.create.vulkan.surface"
#define SDL_PROP_RENDERER_CREATE_VULKAN_PHYSICAL_DEVICE_POINTER "SDL.renderer.create.vulkan.physical_device"
@@ -310,10 +352,57 @@ extern SDL_DECLSPEC SDL_Renderer * SDLCALL SDL_CreateRendererWithProperties(SDL_
#define SDL_PROP_RENDERER_CREATE_VULKAN_GRAPHICS_QUEUE_FAMILY_INDEX_NUMBER "SDL.renderer.create.vulkan.graphics_queue_family_index"
#define SDL_PROP_RENDERER_CREATE_VULKAN_PRESENT_QUEUE_FAMILY_INDEX_NUMBER "SDL.renderer.create.vulkan.present_queue_family_index"
+/**
+ * Create a 2D GPU rendering context.
+ *
+ * The GPU device to use is passed in as a parameter. If this is NULL, then a
+ * device will be created normally and can be retrieved using
+ * SDL_GetGPURendererDevice().
+ *
+ * The window to use is passed in as a parameter. If this is NULL, then this
+ * will become an offscreen renderer. In that case, you should call
+ * SDL_SetRenderTarget() to setup rendering to a texture, and then call
+ * SDL_RenderPresent() normally to complete drawing a frame.
+ *
+ * \param device the GPU device to use with the renderer, or NULL to create a
+ * device.
+ * \param window the window where rendering is displayed, or NULL to create an
+ * offscreen renderer.
+ * \returns a valid rendering context or NULL if there was an error; call
+ * SDL_GetError() for more information.
+ *
+ * \threadsafety If this function is called with a valid GPU device, it should
+ * be called on the thread that created the device. If this
+ * function is called with a valid window, it should be called
+ * on the thread that created the window.
+ *
+ * \since This function is available since SDL 3.4.0.
+ *
+ * \sa SDL_CreateRendererWithProperties
+ * \sa SDL_GetGPURendererDevice
+ * \sa SDL_CreateGPUShader
+ * \sa SDL_CreateGPURenderState
+ * \sa SDL_SetGPURenderState
+ */
+// extern SDL_DECLSPEC SDL_Renderer * SDLCALL SDL_CreateGPURenderer(SDL_GPUDevice *device, SDL_Window *window);
+
+/**
+ * Return the GPU device used by a renderer.
+ *
+ * \param renderer the rendering context.
+ * \returns the GPU device used by the renderer, or NULL if the renderer is
+ * not a GPU renderer; call SDL_GetError() for more information.
+ *
+ * \threadsafety It is safe to call this function from any thread.
+ *
+ * \since This function is available since SDL 3.4.0.
+ */
+// extern SDL_DECLSPEC SDL_GPUDevice * SDLCALL SDL_GetGPURendererDevice(SDL_Renderer *renderer);
+
/**
* Create a 2D software rendering context for a surface.
*
- * Two other API which can be used to create SDL_Renderer:
+ * Two other APIs which can be used to create SDL_Renderer:
* SDL_CreateRenderer() and SDL_CreateWindowAndRenderer(). These can _also_
* create a software renderer, but they are intended to be used with an
* SDL_Window as the final destination and not an SDL_Surface.
@@ -323,7 +412,7 @@ extern SDL_DECLSPEC SDL_Renderer * SDLCALL SDL_CreateRendererWithProperties(SDL_
* \returns a valid rendering context or NULL if there was an error; call
* SDL_GetError() for more information.
*
- * \threadsafety This function should only be called on the main thread.
+ * \threadsafety It is safe to call this function from any thread.
*
* \since This function is available since SDL 3.2.0.
*
@@ -389,6 +478,8 @@ extern SDL_DECLSPEC const char * SDLCALL SDL_GetRendererName(SDL_Renderer *rende
* - `SDL_PROP_RENDERER_TEXTURE_FORMATS_POINTER`: a (const SDL_PixelFormat *)
* array of pixel formats, terminated with SDL_PIXELFORMAT_UNKNOWN,
* representing the available texture formats for this renderer.
+ * - `SDL_PROP_RENDERER_TEXTURE_WRAPPING_BOOLEAN`: true if the renderer
+ * supports SDL_TEXTURE_ADDRESS_WRAP on non-power-of-two textures.
* - `SDL_PROP_RENDERER_OUTPUT_COLORSPACE_NUMBER`: an SDL_Colorspace value
* describing the colorspace for output to the display, defaults to
* SDL_COLORSPACE_SRGB.
@@ -465,6 +556,7 @@ extern SDL_DECLSPEC SDL_PropertiesID SDLCALL SDL_GetRendererProperties(SDL_Rende
#define SDL_PROP_RENDERER_VSYNC_NUMBER "SDL.renderer.vsync"
#define SDL_PROP_RENDERER_MAX_TEXTURE_SIZE_NUMBER "SDL.renderer.max_texture_size"
#define SDL_PROP_RENDERER_TEXTURE_FORMATS_POINTER "SDL.renderer.texture_formats"
+#define SDL_PROP_RENDERER_TEXTURE_WRAPPING_BOOLEAN "SDL.renderer.texture_wrapping"
#define SDL_PROP_RENDERER_OUTPUT_COLORSPACE_NUMBER "SDL.renderer.output_colorspace"
#define SDL_PROP_RENDERER_HDR_ENABLED_BOOLEAN "SDL.renderer.HDR_enabled"
#define SDL_PROP_RENDERER_SDR_WHITE_POINT_FLOAT "SDL.renderer.SDR_white_point"
@@ -601,6 +693,9 @@ extern SDL_DECLSPEC SDL_Texture * SDLCALL SDL_CreateTextureFromSurface(SDL_Rende
* pixels, required
* - `SDL_PROP_TEXTURE_CREATE_HEIGHT_NUMBER`: the height of the texture in
* pixels, required
+ * - `SDL_PROP_TEXTURE_CREATE_PALETTE_POINTER`: an SDL_Palette to use with
+ * palettized texture formats. This can be set later with
+ * SDL_SetTexturePalette()
* - `SDL_PROP_TEXTURE_CREATE_SDR_WHITE_POINT_FLOAT`: for HDR10 and floating
* point textures, this defines the value of 100% diffuse white, with higher
* values being displayed in the High Dynamic Range headroom. This defaults
@@ -659,8 +754,6 @@ extern SDL_DECLSPEC SDL_Texture * SDLCALL SDL_CreateTextureFromSurface(SDL_Rende
*
* - `SDL_PROP_TEXTURE_CREATE_OPENGLES2_TEXTURE_NUMBER`: the GLuint texture
* associated with the texture, if you want to wrap an existing texture.
- * - `SDL_PROP_TEXTURE_CREATE_OPENGLES2_TEXTURE_NUMBER`: the GLuint texture
- * associated with the texture, if you want to wrap an existing texture.
* - `SDL_PROP_TEXTURE_CREATE_OPENGLES2_TEXTURE_UV_NUMBER`: the GLuint texture
* associated with the UV plane of an NV12 texture, if you want to wrap an
* existing texture.
@@ -673,9 +766,24 @@ extern SDL_DECLSPEC SDL_Texture * SDLCALL SDL_CreateTextureFromSurface(SDL_Rende
*
* With the vulkan renderer:
*
- * - `SDL_PROP_TEXTURE_CREATE_VULKAN_TEXTURE_NUMBER`: the VkImage with layout
- * VK_IMAGE_LAYOUT_SHADER_READ_ONLY_OPTIMAL associated with the texture, if
- * you want to wrap an existing texture.
+ * - `SDL_PROP_TEXTURE_CREATE_VULKAN_TEXTURE_NUMBER`: the VkImage associated
+ * with the texture, if you want to wrap an existing texture.
+ * - `SDL_PROP_TEXTURE_CREATE_VULKAN_LAYOUT_NUMBER`: the VkImageLayout for the
+ * VkImage, defaults to VK_IMAGE_LAYOUT_SHADER_READ_ONLY_OPTIMAL.
+ *
+ * With the GPU renderer:
+ *
+ * - `SDL_PROP_TEXTURE_CREATE_GPU_TEXTURE_POINTER`: the SDL_GPUTexture
+ * associated with the texture, if you want to wrap an existing texture.
+ * - `SDL_PROP_TEXTURE_CREATE_GPU_TEXTURE_UV_NUMBER`: the SDL_GPUTexture
+ * associated with the UV plane of an NV12 texture, if you want to wrap an
+ * existing texture.
+ * - `SDL_PROP_TEXTURE_CREATE_GPU_TEXTURE_U_NUMBER`: the SDL_GPUTexture
+ * associated with the U plane of a YUV texture, if you want to wrap an
+ * existing texture.
+ * - `SDL_PROP_TEXTURE_CREATE_GPU_TEXTURE_V_NUMBER`: the SDL_GPUTexture
+ * associated with the V plane of a YUV texture, if you want to wrap an
+ * existing texture.
*
* \param renderer the rendering context.
* \param props the properties to use.
@@ -695,29 +803,35 @@ extern SDL_DECLSPEC SDL_Texture * SDLCALL SDL_CreateTextureFromSurface(SDL_Rende
*/
extern SDL_DECLSPEC SDL_Texture * SDLCALL SDL_CreateTextureWithProperties(SDL_Renderer *renderer, SDL_PropertiesID props);
-#define SDL_PROP_TEXTURE_CREATE_COLORSPACE_NUMBER "SDL.texture.create.colorspace"
-#define SDL_PROP_TEXTURE_CREATE_FORMAT_NUMBER "SDL.texture.create.format"
-#define SDL_PROP_TEXTURE_CREATE_ACCESS_NUMBER "SDL.texture.create.access"
-#define SDL_PROP_TEXTURE_CREATE_WIDTH_NUMBER "SDL.texture.create.width"
-#define SDL_PROP_TEXTURE_CREATE_HEIGHT_NUMBER "SDL.texture.create.height"
-#define SDL_PROP_TEXTURE_CREATE_SDR_WHITE_POINT_FLOAT "SDL.texture.create.SDR_white_point"
-#define SDL_PROP_TEXTURE_CREATE_HDR_HEADROOM_FLOAT "SDL.texture.create.HDR_headroom"
-#define SDL_PROP_TEXTURE_CREATE_D3D11_TEXTURE_POINTER "SDL.texture.create.d3d11.texture"
-#define SDL_PROP_TEXTURE_CREATE_D3D11_TEXTURE_U_POINTER "SDL.texture.create.d3d11.texture_u"
-#define SDL_PROP_TEXTURE_CREATE_D3D11_TEXTURE_V_POINTER "SDL.texture.create.d3d11.texture_v"
-#define SDL_PROP_TEXTURE_CREATE_D3D12_TEXTURE_POINTER "SDL.texture.create.d3d12.texture"
-#define SDL_PROP_TEXTURE_CREATE_D3D12_TEXTURE_U_POINTER "SDL.texture.create.d3d12.texture_u"
-#define SDL_PROP_TEXTURE_CREATE_D3D12_TEXTURE_V_POINTER "SDL.texture.create.d3d12.texture_v"
-#define SDL_PROP_TEXTURE_CREATE_METAL_PIXELBUFFER_POINTER "SDL.texture.create.metal.pixelbuffer"
-#define SDL_PROP_TEXTURE_CREATE_OPENGL_TEXTURE_NUMBER "SDL.texture.create.opengl.texture"
-#define SDL_PROP_TEXTURE_CREATE_OPENGL_TEXTURE_UV_NUMBER "SDL.texture.create.opengl.texture_uv"
-#define SDL_PROP_TEXTURE_CREATE_OPENGL_TEXTURE_U_NUMBER "SDL.texture.create.opengl.texture_u"
-#define SDL_PROP_TEXTURE_CREATE_OPENGL_TEXTURE_V_NUMBER "SDL.texture.create.opengl.texture_v"
-#define SDL_PROP_TEXTURE_CREATE_OPENGLES2_TEXTURE_NUMBER "SDL.texture.create.opengles2.texture"
-#define SDL_PROP_TEXTURE_CREATE_OPENGLES2_TEXTURE_UV_NUMBER "SDL.texture.create.opengles2.texture_uv"
-#define SDL_PROP_TEXTURE_CREATE_OPENGLES2_TEXTURE_U_NUMBER "SDL.texture.create.opengles2.texture_u"
-#define SDL_PROP_TEXTURE_CREATE_OPENGLES2_TEXTURE_V_NUMBER "SDL.texture.create.opengles2.texture_v"
-#define SDL_PROP_TEXTURE_CREATE_VULKAN_TEXTURE_NUMBER "SDL.texture.create.vulkan.texture"
+#define SDL_PROP_TEXTURE_CREATE_COLORSPACE_NUMBER "SDL.texture.create.colorspace"
+#define SDL_PROP_TEXTURE_CREATE_FORMAT_NUMBER "SDL.texture.create.format"
+#define SDL_PROP_TEXTURE_CREATE_ACCESS_NUMBER "SDL.texture.create.access"
+#define SDL_PROP_TEXTURE_CREATE_WIDTH_NUMBER "SDL.texture.create.width"
+#define SDL_PROP_TEXTURE_CREATE_HEIGHT_NUMBER "SDL.texture.create.height"
+#define SDL_PROP_TEXTURE_CREATE_PALETTE_POINTER "SDL.texture.create.palette"
+#define SDL_PROP_TEXTURE_CREATE_SDR_WHITE_POINT_FLOAT "SDL.texture.create.SDR_white_point"
+#define SDL_PROP_TEXTURE_CREATE_HDR_HEADROOM_FLOAT "SDL.texture.create.HDR_headroom"
+#define SDL_PROP_TEXTURE_CREATE_D3D11_TEXTURE_POINTER "SDL.texture.create.d3d11.texture"
+#define SDL_PROP_TEXTURE_CREATE_D3D11_TEXTURE_U_POINTER "SDL.texture.create.d3d11.texture_u"
+#define SDL_PROP_TEXTURE_CREATE_D3D11_TEXTURE_V_POINTER "SDL.texture.create.d3d11.texture_v"
+#define SDL_PROP_TEXTURE_CREATE_D3D12_TEXTURE_POINTER "SDL.texture.create.d3d12.texture"
+#define SDL_PROP_TEXTURE_CREATE_D3D12_TEXTURE_U_POINTER "SDL.texture.create.d3d12.texture_u"
+#define SDL_PROP_TEXTURE_CREATE_D3D12_TEXTURE_V_POINTER "SDL.texture.create.d3d12.texture_v"
+#define SDL_PROP_TEXTURE_CREATE_METAL_PIXELBUFFER_POINTER "SDL.texture.create.metal.pixelbuffer"
+#define SDL_PROP_TEXTURE_CREATE_OPENGL_TEXTURE_NUMBER "SDL.texture.create.opengl.texture"
+#define SDL_PROP_TEXTURE_CREATE_OPENGL_TEXTURE_UV_NUMBER "SDL.texture.create.opengl.texture_uv"
+#define SDL_PROP_TEXTURE_CREATE_OPENGL_TEXTURE_U_NUMBER "SDL.texture.create.opengl.texture_u"
+#define SDL_PROP_TEXTURE_CREATE_OPENGL_TEXTURE_V_NUMBER "SDL.texture.create.opengl.texture_v"
+#define SDL_PROP_TEXTURE_CREATE_OPENGLES2_TEXTURE_NUMBER "SDL.texture.create.opengles2.texture"
+#define SDL_PROP_TEXTURE_CREATE_OPENGLES2_TEXTURE_UV_NUMBER "SDL.texture.create.opengles2.texture_uv"
+#define SDL_PROP_TEXTURE_CREATE_OPENGLES2_TEXTURE_U_NUMBER "SDL.texture.create.opengles2.texture_u"
+#define SDL_PROP_TEXTURE_CREATE_OPENGLES2_TEXTURE_V_NUMBER "SDL.texture.create.opengles2.texture_v"
+#define SDL_PROP_TEXTURE_CREATE_VULKAN_TEXTURE_NUMBER "SDL.texture.create.vulkan.texture"
+#define SDL_PROP_TEXTURE_CREATE_VULKAN_LAYOUT_NUMBER "SDL.texture.create.vulkan.layout"
+#define SDL_PROP_TEXTURE_CREATE_GPU_TEXTURE_POINTER "SDL.texture.create.gpu.texture"
+#define SDL_PROP_TEXTURE_CREATE_GPU_TEXTURE_UV_POINTER "SDL.texture.create.gpu.texture_uv"
+#define SDL_PROP_TEXTURE_CREATE_GPU_TEXTURE_U_POINTER "SDL.texture.create.gpu.texture_u"
+#define SDL_PROP_TEXTURE_CREATE_GPU_TEXTURE_V_POINTER "SDL.texture.create.gpu.texture_v"
/**
* Get the properties associated with a texture.
@@ -797,6 +911,17 @@ extern SDL_DECLSPEC SDL_Texture * SDLCALL SDL_CreateTextureWithProperties(SDL_Re
* - `SDL_PROP_TEXTURE_OPENGLES2_TEXTURE_TARGET_NUMBER`: the GLenum for the
* texture target (`GL_TEXTURE_2D`, `GL_TEXTURE_EXTERNAL_OES`, etc)
*
+ * With the gpu renderer:
+ *
+ * - `SDL_PROP_TEXTURE_GPU_TEXTURE_POINTER`: the SDL_GPUTexture associated
+ * with the texture
+ * - `SDL_PROP_TEXTURE_GPU_TEXTURE_UV_POINTER`: the SDL_GPUTexture associated
+ * with the UV plane of an NV12 texture
+ * - `SDL_PROP_TEXTURE_GPU_TEXTURE_U_POINTER`: the SDL_GPUTexture associated
+ * with the U plane of a YUV texture
+ * - `SDL_PROP_TEXTURE_GPU_TEXTURE_V_POINTER`: the SDL_GPUTexture associated
+ * with the V plane of a YUV texture
+ *
* \param texture the texture to query.
* \returns a valid property ID on success or 0 on failure; call
* SDL_GetError() for more information.
@@ -833,6 +958,10 @@ extern SDL_DECLSPEC SDL_PropertiesID SDLCALL SDL_GetTextureProperties(SDL_Textur
#define SDL_PROP_TEXTURE_OPENGLES2_TEXTURE_V_NUMBER "SDL.texture.opengles2.texture_v"
#define SDL_PROP_TEXTURE_OPENGLES2_TEXTURE_TARGET_NUMBER "SDL.texture.opengles2.target"
#define SDL_PROP_TEXTURE_VULKAN_TEXTURE_NUMBER "SDL.texture.vulkan.texture"
+#define SDL_PROP_TEXTURE_GPU_TEXTURE_POINTER "SDL.texture.gpu.texture"
+#define SDL_PROP_TEXTURE_GPU_TEXTURE_UV_POINTER "SDL.texture.gpu.texture_uv"
+#define SDL_PROP_TEXTURE_GPU_TEXTURE_U_POINTER "SDL.texture.gpu.texture_u"
+#define SDL_PROP_TEXTURE_GPU_TEXTURE_V_POINTER "SDL.texture.gpu.texture_v"
/**
* Get the renderer that created an SDL_Texture.
@@ -864,6 +993,43 @@ extern SDL_DECLSPEC SDL_Renderer * SDLCALL SDL_GetRendererFromTexture(SDL_Textur
*/
extern SDL_DECLSPEC bool SDLCALL SDL_GetTextureSize(SDL_Texture *texture, float *w, float *h);
+/**
+ * Set the palette used by a texture.
+ *
+ * Setting the palette keeps an internal reference to the palette, which can
+ * be safely destroyed afterwards.
+ *
+ * A single palette can be shared with many textures.
+ *
+ * \param texture the texture to update.
+ * \param palette the SDL_Palette structure to use.
+ * \returns true on success or false on failure; call SDL_GetError() for more
+ * information.
+ *
+ * \threadsafety This function should only be called on the main thread.
+ *
+ * \since This function is available since SDL 3.4.0.
+ *
+ * \sa SDL_CreatePalette
+ * \sa SDL_GetTexturePalette
+ */
+extern SDL_DECLSPEC bool SDLCALL SDL_SetTexturePalette(SDL_Texture *texture, SDL_Palette *palette);
+
+/**
+ * Get the palette used by a texture.
+ *
+ * \param texture the texture to query.
+ * \returns a pointer to the palette used by the texture, or NULL if there is
+ * no palette used.
+ *
+ * \threadsafety This function should only be called on the main thread.
+ *
+ * \since This function is available since SDL 3.4.0.
+ *
+ * \sa SDL_SetTexturePalette
+ */
+extern SDL_DECLSPEC SDL_Palette * SDLCALL SDL_GetTexturePalette(SDL_Texture *texture);
+
/**
* Set an additional color value multiplied into render copy operations.
*
@@ -1055,6 +1221,8 @@ extern SDL_DECLSPEC bool SDLCALL SDL_GetTextureAlphaModFloat(SDL_Texture *textur
/**
* Set the blend mode for a texture, used by SDL_RenderTexture().
*
+ * This blend mode is used for any drawing that involves this texture.
+ *
* If the blend mode is not supported, the closest supported mode is chosen
* and this function returns false.
*
@@ -1068,6 +1236,7 @@ extern SDL_DECLSPEC bool SDLCALL SDL_GetTextureAlphaModFloat(SDL_Texture *textur
* \since This function is available since SDL 3.2.0.
*
* \sa SDL_GetTextureBlendMode
+ * \sa SDL_SetRenderDrawBlendMode
*/
extern SDL_DECLSPEC bool SDLCALL SDL_SetTextureBlendMode(SDL_Texture *texture, SDL_BlendMode blendMode);
@@ -1386,14 +1555,6 @@ extern SDL_DECLSPEC SDL_Texture * SDLCALL SDL_GetRenderTarget(SDL_Renderer *rend
* specific dimensions but to make fonts look sharp, the app turns off logical
* presentation while drawing text, for example.
*
- * For the renderer's window, letterboxing is drawn into the framebuffer if
- * logical presentation is enabled during SDL_RenderPresent; be sure to
- * reenable it before presenting if you were toggling it, otherwise the
- * letterbox areas might have artifacts from previous frames (or artifacts
- * from external overlays, etc). Letterboxing is never drawn into texture
- * render targets; be sure to call SDL_RenderClear() before drawing into the
- * texture so the letterboxing areas are cleared, if appropriate.
- *
* You can convert coordinates in an event into rendering coordinates using
* SDL_ConvertEventToRenderCoordinates().
*
@@ -1418,15 +1579,16 @@ extern SDL_DECLSPEC bool SDLCALL SDL_SetRenderLogicalPresentation(SDL_Renderer *
* Get device independent resolution and presentation mode for rendering.
*
* This function gets the width and height of the logical rendering output, or
- * the output size in pixels if a logical resolution is not enabled.
+ * 0 if a logical resolution is not enabled.
*
* Each render target has its own logical presentation state. This function
* gets the state for the current render target.
*
* \param renderer the rendering context.
- * \param w an int to be filled with the width.
- * \param h an int to be filled with the height.
- * \param mode the presentation mode used.
+ * \param w an int filled with the logical presentation width.
+ * \param h an int filled with the logical presentation height.
+ * \param mode a variable filled with the logical presentation mode being
+ * used.
* \returns true on success or false on failure; call SDL_GetError() for more
* information.
*
@@ -1545,8 +1707,8 @@ extern SDL_DECLSPEC bool SDLCALL SDL_RenderCoordinatesToWindow(SDL_Renderer *ren
*
* \param renderer the rendering context.
* \param event the event to modify.
- * \returns true on success or false on failure; call SDL_GetError() for more
- * information.
+ * \returns true if the event is converted or doesn't need conversion, or
+ * false on failure; call SDL_GetError() for more information.
*
* \threadsafety This function should only be called on the main thread.
*
@@ -1895,7 +2057,9 @@ extern SDL_DECLSPEC bool SDLCALL SDL_SetRenderColorScale(SDL_Renderer *renderer,
extern SDL_DECLSPEC bool SDLCALL SDL_GetRenderColorScale(SDL_Renderer *renderer, float *scale);
/**
- * Set the blend mode used for drawing operations (Fill and Line).
+ * Set the blend mode used for drawing operations.
+ *
+ * This blend mode is used for any drawing that doesn't involve textures.
*
* If the blend mode is not supported, the closest supported mode is chosen.
*
@@ -1909,6 +2073,7 @@ extern SDL_DECLSPEC bool SDLCALL SDL_GetRenderColorScale(SDL_Renderer *renderer,
* \since This function is available since SDL 3.2.0.
*
* \sa SDL_GetRenderDrawBlendMode
+ * \sa SDL_SetTextureBlendMode
*/
extern SDL_DECLSPEC bool SDLCALL SDL_SetRenderDrawBlendMode(SDL_Renderer *renderer, SDL_BlendMode blendMode);
@@ -2231,9 +2396,48 @@ extern SDL_DECLSPEC bool SDLCALL SDL_RenderTextureTiled(SDL_Renderer *renderer,
* \since This function is available since SDL 3.2.0.
*
* \sa SDL_RenderTexture
+ * \sa SDL_RenderTexture9GridTiled
*/
extern SDL_DECLSPEC bool SDLCALL SDL_RenderTexture9Grid(SDL_Renderer *renderer, SDL_Texture *texture, const SDL_FRect *srcrect, float left_width, float right_width, float top_height, float bottom_height, float scale, const SDL_FRect *dstrect);
+/**
+ * Perform a scaled copy using the 9-grid algorithm to the current rendering
+ * target at subpixel precision.
+ *
+ * The pixels in the texture are split into a 3x3 grid, using the different
+ * corner sizes for each corner, and the sides and center making up the
+ * remaining pixels. The corners are then scaled using `scale` and fit into
+ * the corners of the destination rectangle. The sides and center are then
+ * tiled into place to cover the remaining destination rectangle.
+ *
+ * \param renderer the renderer which should copy parts of a texture.
+ * \param texture the source texture.
+ * \param srcrect the SDL_Rect structure representing the rectangle to be used
+ * for the 9-grid, or NULL to use the entire texture.
+ * \param left_width the width, in pixels, of the left corners in `srcrect`.
+ * \param right_width the width, in pixels, of the right corners in `srcrect`.
+ * \param top_height the height, in pixels, of the top corners in `srcrect`.
+ * \param bottom_height the height, in pixels, of the bottom corners in
+ * `srcrect`.
+ * \param scale the scale used to transform the corner of `srcrect` into the
+ * corner of `dstrect`, or 0.0f for an unscaled copy.
+ * \param dstrect a pointer to the destination rectangle, or NULL for the
+ * entire rendering target.
+ * \param tileScale the scale used to transform the borders and center of
+ * `srcrect` into the borders and middle of `dstrect`, or
+ * 1.0f for an unscaled copy.
+ * \returns true on success or false on failure; call SDL_GetError() for more
+ * information.
+ *
+ * \threadsafety This function should only be called on the main thread.
+ *
+ * \since This function is available since SDL 3.4.0.
+ *
+ * \sa SDL_RenderTexture
+ * \sa SDL_RenderTexture9Grid
+ */
+extern SDL_DECLSPEC bool SDLCALL SDL_RenderTexture9GridTiled(SDL_Renderer *renderer, SDL_Texture *texture, const SDL_FRect *srcrect, float left_width, float right_width, float top_height, float bottom_height, float scale, const SDL_FRect *dstrect, float tileScale);
+
/**
* Render a list of triangles, optionally using a texture and indices into the
* vertex array Color and alpha modulation is done per vertex
@@ -2255,6 +2459,7 @@ extern SDL_DECLSPEC bool SDLCALL SDL_RenderTexture9Grid(SDL_Renderer *renderer,
* \since This function is available since SDL 3.2.0.
*
* \sa SDL_RenderGeometryRaw
+ * \sa SDL_SetRenderTextureAddressMode
*/
extern SDL_DECLSPEC bool SDLCALL SDL_RenderGeometry(SDL_Renderer *renderer,
SDL_Texture *texture,
@@ -2287,6 +2492,7 @@ extern SDL_DECLSPEC bool SDLCALL SDL_RenderGeometry(SDL_Renderer *renderer,
* \since This function is available since SDL 3.2.0.
*
* \sa SDL_RenderGeometry
+ * \sa SDL_SetRenderTextureAddressMode
*/
extern SDL_DECLSPEC bool SDLCALL SDL_RenderGeometryRaw(SDL_Renderer *renderer,
SDL_Texture *texture,
@@ -2296,6 +2502,48 @@ extern SDL_DECLSPEC bool SDLCALL SDL_RenderGeometryRaw(SDL_Renderer *renderer,
int num_vertices,
const void *indices, int num_indices, int size_indices);
+/**
+ * Set the texture addressing mode used in SDL_RenderGeometry().
+ *
+ * \param renderer the rendering context.
+ * \param u_mode the SDL_TextureAddressMode to use for horizontal texture
+ * coordinates in SDL_RenderGeometry().
+ * \param v_mode the SDL_TextureAddressMode to use for vertical texture
+ * coordinates in SDL_RenderGeometry().
+ * \returns true on success or false on failure; call SDL_GetError() for more
+ * information.
+ *
+ * \threadsafety This function should only be called on the main thread.
+ *
+ * \since This function is available since SDL 3.4.0.
+ *
+ * \sa SDL_RenderGeometry
+ * \sa SDL_RenderGeometryRaw
+ * \sa SDL_GetRenderTextureAddressMode
+ */
+extern SDL_DECLSPEC bool SDLCALL SDL_SetRenderTextureAddressMode(SDL_Renderer *renderer, SDL_TextureAddressMode u_mode, SDL_TextureAddressMode v_mode);
+
+/**
+ * Get the texture addressing mode used in SDL_RenderGeometry().
+ *
+ * \param renderer the rendering context.
+ * \param u_mode a pointer filled in with the SDL_TextureAddressMode to use
+ * for horizontal texture coordinates in SDL_RenderGeometry(),
+ * may be NULL.
+ * \param v_mode a pointer filled in with the SDL_TextureAddressMode to use
+ * for vertical texture coordinates in SDL_RenderGeometry(), may
+ * be NULL.
+ * \returns true on success or false on failure; call SDL_GetError() for more
+ * information.
+ *
+ * \threadsafety This function should only be called on the main thread.
+ *
+ * \since This function is available since SDL 3.4.0.
+ *
+ * \sa SDL_SetRenderTextureAddressMode
+ */
+extern SDL_DECLSPEC bool SDLCALL SDL_GetRenderTextureAddressMode(SDL_Renderer *renderer, SDL_TextureAddressMode *u_mode, SDL_TextureAddressMode *v_mode);
+
/**
* Read pixels from the current rendering target.
*
@@ -2347,8 +2595,7 @@ extern SDL_DECLSPEC SDL_Surface * SDLCALL SDL_RenderReadPixels(SDL_Renderer *ren
* should not be done; you are only required to change back the rendering
* target to default via `SDL_SetRenderTarget(renderer, NULL)` afterwards, as
* textures by themselves do not have a concept of backbuffers. Calling
- * SDL_RenderPresent while rendering to a texture will still update the screen
- * with any current drawing that has been done _to the window itself_.
+ * SDL_RenderPresent while rendering to a texture will fail.
*
* \param renderer the rendering context.
* \returns true on success or false on failure; call SDL_GetError() for more
@@ -2577,8 +2824,8 @@ extern SDL_DECLSPEC bool SDLCALL SDL_GetRenderVSync(SDL_Renderer *renderer, int
* Among these limitations:
*
* - It accepts UTF-8 strings, but will only renders ASCII characters.
- * - It has a single, tiny size (8x8 pixels). One can use logical presentation
- * or scaling to adjust it, but it will be blurry.
+ * - It has a single, tiny size (8x8 pixels). You can use logical presentation
+ * or SDL_SetRenderScale() to adjust it.
* - It uses a simple, hardcoded bitmap font. It does not allow different font
* selections and it does not support truetype, for proper scaling.
* - It does no word-wrapping and does not treat newline characters as a line
@@ -2636,6 +2883,148 @@ extern SDL_DECLSPEC bool SDLCALL SDL_RenderDebugText(SDL_Renderer *renderer, flo
*/
extern SDL_DECLSPEC bool SDLCALL SDL_RenderDebugTextFormat(SDL_Renderer *renderer, float x, float y, SDL_PRINTF_FORMAT_STRING const char *fmt, ...) SDL_PRINTF_VARARG_FUNC(4);
+/**
+ * Set default scale mode for new textures for given renderer.
+ *
+ * When a renderer is created, scale_mode defaults to SDL_SCALEMODE_LINEAR.
+ *
+ * \param renderer the renderer to update.
+ * \param scale_mode the scale mode to change to for new textures.
+ * \returns true on success or false on failure; call SDL_GetError() for more
+ * information.
+ *
+ * \threadsafety This function should only be called on the main thread.
+ *
+ * \since This function is available since SDL 3.4.0.
+ *
+ * \sa SDL_GetDefaultTextureScaleMode
+ */
+extern SDL_DECLSPEC bool SDLCALL SDL_SetDefaultTextureScaleMode(SDL_Renderer *renderer, SDL_ScaleMode scale_mode);
+
+/**
+ * Get default texture scale mode of the given renderer.
+ *
+ * \param renderer the renderer to get data from.
+ * \param scale_mode a SDL_ScaleMode filled with current default scale mode.
+ * See SDL_SetDefaultTextureScaleMode() for the meaning of
+ * the value.
+ * \returns true on success or false on failure; call SDL_GetError() for more
+ * information.
+ *
+ * \threadsafety This function should only be called on the main thread.
+ *
+ * \since This function is available since SDL 3.4.0.
+ *
+ * \sa SDL_SetDefaultTextureScaleMode
+ */
+extern SDL_DECLSPEC bool SDLCALL SDL_GetDefaultTextureScaleMode(SDL_Renderer *renderer, SDL_ScaleMode *scale_mode);
+
+/**
+ * A structure specifying the parameters of a GPU render state.
+ *
+ * \since This struct is available since SDL 3.4.0.
+ *
+ * \sa SDL_CreateGPURenderState
+ */
+typedef struct SDL_GPURenderStateCreateInfo
+{
+ // SDL_GPUShader *fragment_shader; /**< The fragment shader to use when this render state is active */
+
+ Sint32 num_sampler_bindings; /**< The number of additional fragment samplers to bind when this render state is active */
+ // const SDL_GPUTextureSamplerBinding *sampler_bindings; /**< Additional fragment samplers to bind when this render state is active */
+
+ Sint32 num_storage_textures; /**< The number of storage textures to bind when this render state is active */
+ // SDL_GPUTexture *const *storage_textures; /**< Storage textures to bind when this render state is active */
+
+ Sint32 num_storage_buffers; /**< The number of storage buffers to bind when this render state is active */
+ // SDL_GPUBuffer *const *storage_buffers; /**< Storage buffers to bind when this render state is active */
+
+ SDL_PropertiesID props; /**< A properties ID for extensions. Should be 0 if no extensions are needed. */
+} SDL_GPURenderStateCreateInfo;
+
+/**
+ * A custom GPU render state.
+ *
+ * \since This struct is available since SDL 3.4.0.
+ *
+ * \sa SDL_CreateGPURenderState
+ * \sa SDL_SetGPURenderStateFragmentUniforms
+ * \sa SDL_SetGPURenderState
+ * \sa SDL_DestroyGPURenderState
+ */
+typedef struct SDL_GPURenderState SDL_GPURenderState;
+
+/**
+ * Create custom GPU render state.
+ *
+ * \param renderer the renderer to use.
+ * \param createinfo a struct describing the GPU render state to create.
+ * \returns a custom GPU render state or NULL on failure; call SDL_GetError()
+ * for more information.
+ *
+ * \threadsafety This function should be called on the thread that created the
+ * renderer.
+ *
+ * \since This function is available since SDL 3.4.0.
+ *
+ * \sa SDL_SetGPURenderStateFragmentUniforms
+ * \sa SDL_SetGPURenderState
+ * \sa SDL_DestroyGPURenderState
+ */
+extern SDL_DECLSPEC SDL_GPURenderState * SDLCALL SDL_CreateGPURenderState(SDL_Renderer *renderer, const SDL_GPURenderStateCreateInfo *createinfo);
+
+/**
+ * Set fragment shader uniform variables in a custom GPU render state.
+ *
+ * The data is copied and will be pushed using
+ * SDL_PushGPUFragmentUniformData() during draw call execution.
+ *
+ * \param state the state to modify.
+ * \param slot_index the fragment uniform slot to push data to.
+ * \param data client data to write.
+ * \param length the length of the data to write.
+ * \returns true on success or false on failure; call SDL_GetError() for more
+ * information.
+ *
+ * \threadsafety This function should be called on the thread that created the
+ * renderer.
+ *
+ * \since This function is available since SDL 3.4.0.
+ */
+extern SDL_DECLSPEC bool SDLCALL SDL_SetGPURenderStateFragmentUniforms(SDL_GPURenderState *state, Uint32 slot_index, const void *data, Uint32 length);
+
+/**
+ * Set custom GPU render state.
+ *
+ * This function sets custom GPU render state for subsequent draw calls. This
+ * allows using custom shaders with the GPU renderer.
+ *
+ * \param renderer the renderer to use.
+ * \param state the state to to use, or NULL to clear custom GPU render state.
+ * \returns true on success or false on failure; call SDL_GetError() for more
+ * information.
+ *
+ * \threadsafety This function should be called on the thread that created the
+ * renderer.
+ *
+ * \since This function is available since SDL 3.4.0.
+ */
+extern SDL_DECLSPEC bool SDLCALL SDL_SetGPURenderState(SDL_Renderer *renderer, SDL_GPURenderState *state);
+
+/**
+ * Destroy custom GPU render state.
+ *
+ * \param state the state to destroy.
+ *
+ * \threadsafety This function should be called on the thread that created the
+ * renderer.
+ *
+ * \since This function is available since SDL 3.4.0.
+ *
+ * \sa SDL_CreateGPURenderState
+ */
+extern SDL_DECLSPEC void SDLCALL SDL_DestroyGPURenderState(SDL_GPURenderState *state);
+
/* Ends C function definitions when using C++ */
#ifdef __cplusplus
}
diff --git a/thirdparty/sdl/include/SDL3/SDL_revision.h b/thirdparty/sdl/include/SDL3/SDL_revision.h
index f0f57cd59b6..fc93bcf45a7 100644
--- a/thirdparty/sdl/include/SDL3/SDL_revision.h
+++ b/thirdparty/sdl/include/SDL3/SDL_revision.h
@@ -1,6 +1,6 @@
/*
Simple DirectMedia Layer
- Copyright (C) 1997-2025 Sam Lantinga <[email protected]>
+ Copyright (C) 1997-2026 Sam Lantinga <[email protected]>
This software is provided 'as-is', without any express or implied
warranty. In no event will the authors be held liable for any damages
@@ -44,6 +44,9 @@
* clue in debugging forensics and not something the app will parse in any
* way.
*
+ * SDL_revision.h must be included in your program explicitly if you want
+ * access to the SDL_REVISION constant.
+ *
* \since This macro is available since SDL 3.2.0.
*/
#define SDL_REVISION "Some arbitrary string decided at SDL build time"
diff --git a/thirdparty/sdl/include/SDL3/SDL_scancode.h b/thirdparty/sdl/include/SDL3/SDL_scancode.h
index 6e9be47e6ae..cd5a1376a81 100644
--- a/thirdparty/sdl/include/SDL3/SDL_scancode.h
+++ b/thirdparty/sdl/include/SDL3/SDL_scancode.h
@@ -1,6 +1,6 @@
/*
Simple DirectMedia Layer
- Copyright (C) 1997-2025 Sam Lantinga <[email protected]>
+ Copyright (C) 1997-2026 Sam Lantinga <[email protected]>
This software is provided 'as-is', without any express or implied
warranty. In no event will the authors be held liable for any damages
diff --git a/thirdparty/sdl/include/SDL3/SDL_sensor.h b/thirdparty/sdl/include/SDL3/SDL_sensor.h
index 43366f13570..bf890472f03 100644
--- a/thirdparty/sdl/include/SDL3/SDL_sensor.h
+++ b/thirdparty/sdl/include/SDL3/SDL_sensor.h
@@ -1,6 +1,6 @@
/*
Simple DirectMedia Layer
- Copyright (C) 1997-2025 Sam Lantinga <[email protected]>
+ Copyright (C) 1997-2026 Sam Lantinga <[email protected]>
This software is provided 'as-is', without any express or implied
warranty. In no event will the authors be held liable for any damages
diff --git a/thirdparty/sdl/include/SDL3/SDL_stdinc.h b/thirdparty/sdl/include/SDL3/SDL_stdinc.h
index 5b8dc463408..b6403bea710 100644
--- a/thirdparty/sdl/include/SDL3/SDL_stdinc.h
+++ b/thirdparty/sdl/include/SDL3/SDL_stdinc.h
@@ -1,6 +1,6 @@
/*
Simple DirectMedia Layer
- Copyright (C) 1997-2025 Sam Lantinga <[email protected]>
+ Copyright (C) 1997-2026 Sam Lantinga <[email protected]>
This software is provided 'as-is', without any express or implied
warranty. In no event will the authors be held liable for any damages
@@ -49,10 +49,37 @@
#include <SDL3/SDL_platform_defines.h>
#include <stdarg.h>
-#include <stdint.h>
#include <string.h>
#include <wchar.h>
+/* Most everything except Visual Studio 2008 and earlier has stdint.h now */
+#if defined(_MSC_VER) && (_MSC_VER < 1600)
+typedef signed __int8 int8_t;
+typedef unsigned __int8 uint8_t;
+typedef signed __int16 int16_t;
+typedef unsigned __int16 uint16_t;
+typedef signed __int32 int32_t;
+typedef unsigned __int32 uint32_t;
+typedef signed __int64 int64_t;
+typedef unsigned __int64 uint64_t;
+#ifndef _INTPTR_T_DEFINED
+#ifdef _WIN64
+typedef __int64 intptr_t;
+#else
+typedef int intptr_t;
+#endif
+#endif
+#ifndef _UINTPTR_T_DEFINED
+#ifdef _WIN64
+typedef unsigned __int64 uintptr_t;
+#else
+typedef unsigned int uintptr_t;
+#endif
+#endif
+#else
+#include <stdint.h>
+#endif
+
#if (defined(__STDC_VERSION__) && __STDC_VERSION__ >= 199901L) || \
defined(SDL_INCLUDE_INTTYPES_H)
#include <inttypes.h>
@@ -227,12 +254,6 @@ void *alloca(size_t);
/**
* Macro useful for building other macros with strings in them.
*
- * For example:
- *
- * ```c
- * #define LOG_ERROR(X) OutputDebugString(SDL_STRINGIFY_ARG(__FUNCTION__) ": " X "\n")`
- * ```
- *
* \param arg the text to turn into a string literal.
*
* \since This macro is available since SDL 3.2.0.
@@ -492,7 +513,7 @@ typedef uint64_t Uint64;
* and SDL_SECONDS_TO_NS(), and between Windows FILETIME values with
* SDL_TimeToWindows() and SDL_TimeFromWindows().
*
- * \since This macro is available since SDL 3.2.0.
+ * \since This datatype is available since SDL 3.2.0.
*
* \sa SDL_MAX_SINT64
* \sa SDL_MIN_SINT64
@@ -1269,8 +1290,9 @@ extern "C" {
/**
* Free memory previously allocated with SDL_stack_alloc.
*
- * If SDL used alloca() to allocate this memory, this macro does nothing and
- * the allocated memory will be automatically released when the function that
+ * If SDL used alloca() to allocate this memory, this macro does nothing (other
+ * than insert `((void)(data)` so the compiler sees an expression) and the
+ * allocated memory will be automatically released when the function that
* called SDL_stack_alloc() returns. If SDL used SDL_malloc(), it will
* SDL_free the memory immediately.
*
@@ -1282,10 +1304,10 @@ extern "C" {
*
* \sa SDL_stack_alloc
*/
-#define SDL_stack_free(data)
+#define SDL_stack_free(data) ((void)(data))
#elif !defined(SDL_DISABLE_ALLOCA)
#define SDL_stack_alloc(type, count) (type*)alloca(sizeof(type)*(count))
-#define SDL_stack_free(data)
+#define SDL_stack_free(data) ((void)(data))
#else
#define SDL_stack_alloc(type, count) (type*)SDL_malloc(sizeof(type)*(count))
#define SDL_stack_free(data) SDL_free(data)
@@ -1775,6 +1797,8 @@ extern SDL_DECLSPEC void SDLCALL SDL_DestroyEnvironment(SDL_Environment *env);
/**
* Get the value of a variable in the environment.
*
+ * The name of the variable is case sensitive on all platforms.
+ *
* This function uses SDL's cached copy of the environment and is thread-safe.
*
* \param name the name of the variable to get.
@@ -1793,6 +1817,11 @@ extern SDL_DECLSPEC const char * SDLCALL SDL_getenv(const char *name);
* This function bypasses SDL's cached copy of the environment and is not
* thread-safe.
*
+ * On some platforms, this may make case-insensitive matches, while other
+ * platforms are case-sensitive. It is best to be precise with strings used
+ * for queries through this interface. SDL_getenv is always case-sensitive,
+ * however.
+ *
* \param name the name of the variable to get.
* \returns a pointer to the value of the variable or NULL if it can't be
* found.
@@ -2119,7 +2148,7 @@ extern SDL_DECLSPEC int SDLCALL SDL_abs(int x);
*
* \param x the first value to compare.
* \param y the second value to compare.
- * \returns the lesser of `x` and `y`.
+ * \returns the greater of `x` and `y`.
*
* \threadsafety It is safe to call this macro from any thread.
*
@@ -2640,7 +2669,7 @@ extern SDL_DECLSPEC void * SDLCALL SDL_memset4(void *dst, Uint32 val, size_t dwo
* \since This macro is available since SDL 3.2.0.
*
* \sa SDL_zero
- * \sa SDL_zeroa
+ * \sa SDL_zerop
*/
#define SDL_zeroa(x) SDL_memset((x), 0, sizeof((x)))
@@ -4722,7 +4751,7 @@ extern SDL_DECLSPEC float SDLCALL SDL_atan2f(float y, float x);
/**
* Compute the ceiling of `x`.
*
- * The ceiling of `x` is the smallest integer `y` such that `y > x`, i.e `x`
+ * The ceiling of `x` is the smallest integer `y` such that `y >= x`, i.e `x`
* rounded up to the nearest integer.
*
* Domain: `-INF <= x <= INF`
@@ -4750,7 +4779,7 @@ extern SDL_DECLSPEC double SDLCALL SDL_ceil(double x);
/**
* Compute the ceiling of `x`.
*
- * The ceiling of `x` is the smallest integer `y` such that `y > x`, i.e `x`
+ * The ceiling of `x` is the smallest integer `y` such that `y >= x`, i.e `x`
* rounded up to the nearest integer.
*
* Domain: `-INF <= x <= INF`
@@ -4992,7 +5021,7 @@ extern SDL_DECLSPEC float SDLCALL SDL_fabsf(float x);
/**
* Compute the floor of `x`.
*
- * The floor of `x` is the largest integer `y` such that `y > x`, i.e `x`
+ * The floor of `x` is the largest integer `y` such that `y <= x`, i.e `x`
* rounded down to the nearest integer.
*
* Domain: `-INF <= x <= INF`
@@ -5020,7 +5049,7 @@ extern SDL_DECLSPEC double SDLCALL SDL_floor(double x);
/**
* Compute the floor of `x`.
*
- * The floor of `x` is the largest integer `y` such that `y > x`, i.e `x`
+ * The floor of `x` is the largest integer `y` such that `y <= x`, i.e `x`
* rounded down to the nearest integer.
*
* Domain: `-INF <= x <= INF`
@@ -5794,6 +5823,8 @@ typedef struct SDL_iconv_data_t *SDL_iconv_t;
* \returns a handle that must be freed with SDL_iconv_close, or
* SDL_ICONV_ERROR on failure.
*
+ * \threadsafety It is safe to call this function from any thread.
+ *
* \since This function is available since SDL 3.2.0.
*
* \sa SDL_iconv
@@ -5809,6 +5840,8 @@ extern SDL_DECLSPEC SDL_iconv_t SDLCALL SDL_iconv_open(const char *tocode,
* \param cd The character set conversion handle.
* \returns 0 on success, or -1 on failure.
*
+ * \threadsafety It is safe to call this function from any thread.
+ *
* \since This function is available since SDL 3.2.0.
*
* \sa SDL_iconv
@@ -5847,6 +5880,8 @@ extern SDL_DECLSPEC int SDLCALL SDL_iconv_close(SDL_iconv_t cd);
* \param outbytesleft The number of bytes in the output buffer.
* \returns the number of conversions on success, or a negative error code.
*
+ * \threadsafety Do not use the same SDL_iconv_t from two threads at once.
+ *
* \since This function is available since SDL 3.2.0.
*
* \sa SDL_iconv_open
@@ -5882,6 +5917,8 @@ extern SDL_DECLSPEC size_t SDLCALL SDL_iconv(SDL_iconv_t cd, const char **inbuf,
* \param inbytesleft the size of the input string _in bytes_.
* \returns a new string, converted to the new encoding, or NULL on error.
*
+ * \threadsafety It is safe to call this function from any thread.
+ *
* \since This function is available since SDL 3.2.0.
*
* \sa SDL_iconv_open
@@ -5905,6 +5942,8 @@ extern SDL_DECLSPEC char * SDLCALL SDL_iconv_string(const char *tocode,
* \param S the string to convert.
* \returns a new string, converted to the new encoding, or NULL on error.
*
+ * \threadsafety It is safe to call this macro from any thread.
+ *
* \since This macro is available since SDL 3.2.0.
*/
#define SDL_iconv_utf8_locale(S) SDL_iconv_string("", "UTF-8", S, SDL_strlen(S)+1)
@@ -5919,6 +5958,8 @@ extern SDL_DECLSPEC char * SDLCALL SDL_iconv_string(const char *tocode,
* \param S the string to convert.
* \returns a new string, converted to the new encoding, or NULL on error.
*
+ * \threadsafety It is safe to call this macro from any thread.
+ *
* \since This macro is available since SDL 3.2.0.
*/
#define SDL_iconv_utf8_ucs2(S) SDL_reinterpret_cast(Uint16 *, SDL_iconv_string("UCS-2", "UTF-8", S, SDL_strlen(S)+1))
@@ -5933,6 +5974,8 @@ extern SDL_DECLSPEC char * SDLCALL SDL_iconv_string(const char *tocode,
* \param S the string to convert.
* \returns a new string, converted to the new encoding, or NULL on error.
*
+ * \threadsafety It is safe to call this macro from any thread.
+ *
* \since This macro is available since SDL 3.2.0.
*/
#define SDL_iconv_utf8_ucs4(S) SDL_reinterpret_cast(Uint32 *, SDL_iconv_string("UCS-4", "UTF-8", S, SDL_strlen(S)+1))
@@ -5947,6 +5990,8 @@ extern SDL_DECLSPEC char * SDLCALL SDL_iconv_string(const char *tocode,
* \param S the string to convert.
* \returns a new string, converted to the new encoding, or NULL on error.
*
+ * \threadsafety It is safe to call this macro from any thread.
+ *
* \since This macro is available since SDL 3.2.0.
*/
#define SDL_iconv_wchar_utf8(S) SDL_iconv_string("UTF-8", "WCHAR_T", SDL_reinterpret_cast(const char *, S), (SDL_wcslen(S)+1)*sizeof(wchar_t))
@@ -5974,6 +6019,10 @@ size_t wcslcpy(wchar_t *dst, const wchar_t *src, size_t size);
size_t wcslcat(wchar_t *dst, const wchar_t *src, size_t size);
#endif
+#if !defined(HAVE_STRTOK_R) && !defined(strtok_r)
+char *strtok_r(char *str, const char *delim, char **saveptr);
+#endif
+
#ifndef _WIN32
/* strdup is not ANSI but POSIX, and its prototype might be hidden... */
/* not for windows: might conflict with string.h where strdup may have
diff --git a/thirdparty/sdl/include/SDL3/SDL_storage.h b/thirdparty/sdl/include/SDL3/SDL_storage.h
index 6837ebaacf0..4391daada3d 100644
--- a/thirdparty/sdl/include/SDL3/SDL_storage.h
+++ b/thirdparty/sdl/include/SDL3/SDL_storage.h
@@ -1,6 +1,6 @@
/*
Simple DirectMedia Layer
- Copyright (C) 1997-2025 Sam Lantinga <[email protected]>
+ Copyright (C) 1997-2026 Sam Lantinga <[email protected]>
This software is provided 'as-is', without any express or implied
warranty. In no event will the authors be held liable for any damages
@@ -334,6 +334,10 @@ typedef struct SDL_Storage SDL_Storage;
/**
* Opens up a read-only container for the application's filesystem.
*
+ * By default, SDL_OpenTitleStorage uses the generic storage implementation.
+ * When the path override is not provided, the generic implementation will use
+ * the output of SDL_GetBasePath as the base path.
+ *
* \param override a path to override the backend's default title root.
* \param props a property list that may contain backend-specific information.
* \returns a title storage container on success or NULL on failure; call
@@ -564,7 +568,7 @@ extern SDL_DECLSPEC bool SDLCALL SDL_EnumerateStorageDirectory(SDL_Storage *stor
* Remove a file or an empty directory in a writable storage container.
*
* \param storage a storage container.
- * \param path the path of the directory to enumerate.
+ * \param path the path to remove from the filesystem.
* \returns true on success or false on failure; call SDL_GetError() for more
* information.
*
diff --git a/thirdparty/sdl/include/SDL3/SDL_surface.h b/thirdparty/sdl/include/SDL3/SDL_surface.h
index 15fce042f73..885f8f5d982 100644
--- a/thirdparty/sdl/include/SDL3/SDL_surface.h
+++ b/thirdparty/sdl/include/SDL3/SDL_surface.h
@@ -1,6 +1,6 @@
/*
Simple DirectMedia Layer
- Copyright (C) 1997-2025 Sam Lantinga <[email protected]>
+ Copyright (C) 1997-2026 Sam Lantinga <[email protected]>
This software is provided 'as-is', without any express or implied
warranty. In no event will the authors be held liable for any damages
@@ -29,12 +29,16 @@
* provides a reasonable toolbox for transforming the data, including copying
* between surfaces, filling rectangles in the image data, etc.
*
- * There is also a simple .bmp loader, SDL_LoadBMP(). SDL itself does not
- * provide loaders for various other file formats, but there are several
- * excellent external libraries that do, including its own satellite library,
- * SDL_image:
+ * There is also a simple .bmp loader, SDL_LoadBMP(), and a simple .png
+ * loader, SDL_LoadPNG(). SDL itself does not provide loaders for other file
+ * formats, but there are several excellent external libraries that do,
+ * including its own satellite library,
+ * [SDL_image](https://wiki.libsdl.org/SDL3_image)
+ * .
*
- * https://github.com/libsdl-org/SDL_image
+ * In general these functions are thread-safe in that they can be called on
+ * different threads with different surfaces. You should not try to modify any
+ * surface from two threads simultaneously.
*/
#ifndef SDL_surface_h_
@@ -83,8 +87,9 @@ typedef Uint32 SDL_SurfaceFlags;
typedef enum SDL_ScaleMode
{
SDL_SCALEMODE_INVALID = -1,
- SDL_SCALEMODE_NEAREST, /**< nearest pixel sampling */
- SDL_SCALEMODE_LINEAR /**< linear filtering */
+ SDL_SCALEMODE_NEAREST, /**< nearest pixel sampling */
+ SDL_SCALEMODE_LINEAR, /**< linear filtering */
+ SDL_SCALEMODE_PIXELART /**< nearest pixel sampling with improved scaling for pixel art, available since SDL 3.4.0 */
} SDL_ScaleMode;
/**
@@ -94,9 +99,10 @@ typedef enum SDL_ScaleMode
*/
typedef enum SDL_FlipMode
{
- SDL_FLIP_NONE, /**< Do not flip */
- SDL_FLIP_HORIZONTAL, /**< flip horizontally */
- SDL_FLIP_VERTICAL /**< flip vertically */
+ SDL_FLIP_NONE, /**< Do not flip */
+ SDL_FLIP_HORIZONTAL, /**< flip horizontally */
+ SDL_FLIP_VERTICAL, /**< flip vertically */
+ SDL_FLIP_HORIZONTAL_AND_VERTICAL = (SDL_FLIP_HORIZONTAL | SDL_FLIP_VERTICAL) /**< flip horizontally and vertically (not a diagonal flip) */
} SDL_FlipMode;
#ifndef SDL_INTERNAL
@@ -235,6 +241,12 @@ extern SDL_DECLSPEC void SDLCALL SDL_DestroySurface(SDL_Surface *surface);
* left edge of the image, if this surface is being used as a cursor.
* - `SDL_PROP_SURFACE_HOTSPOT_Y_NUMBER`: the hotspot pixel offset from the
* top edge of the image, if this surface is being used as a cursor.
+ * - `SDL_PROP_SURFACE_ROTATION_FLOAT`: the number of degrees a surface's data
+ * is meant to be rotated clockwise to make the image right-side up. Default
+ * 0. This is used by the camera API, if a mobile device is oriented
+ * differently than what its camera provides (i.e. - the camera always
+ * provides portrait images but the phone is being held in landscape
+ * orientation). Since SDL 3.4.0.
*
* \param surface the SDL_Surface structure to query.
* \returns a valid property ID on success or 0 on failure; call
@@ -251,6 +263,7 @@ extern SDL_DECLSPEC SDL_PropertiesID SDLCALL SDL_GetSurfaceProperties(SDL_Surfac
#define SDL_PROP_SURFACE_TONEMAP_OPERATOR_STRING "SDL.surface.tonemap"
#define SDL_PROP_SURFACE_HOTSPOT_X_NUMBER "SDL.surface.hotspot.x"
#define SDL_PROP_SURFACE_HOTSPOT_Y_NUMBER "SDL.surface.hotspot.y"
+#define SDL_PROP_SURFACE_ROTATION_FLOAT "SDL.surface.rotation"
/**
* Set the colorspace used by a surface.
@@ -264,7 +277,8 @@ extern SDL_DECLSPEC SDL_PropertiesID SDLCALL SDL_GetSurfaceProperties(SDL_Surfac
* \returns true on success or false on failure; call SDL_GetError() for more
* information.
*
- * \threadsafety This function is not thread safe.
+ * \threadsafety This function can be called on different threads with
+ * different surfaces.
*
* \since This function is available since SDL 3.2.0.
*
@@ -283,7 +297,8 @@ extern SDL_DECLSPEC bool SDLCALL SDL_SetSurfaceColorspace(SDL_Surface *surface,
* \returns the colorspace used by the surface, or SDL_COLORSPACE_UNKNOWN if
* the surface is NULL.
*
- * \threadsafety This function is not thread safe.
+ * \threadsafety This function can be called on different threads with
+ * different surfaces.
*
* \since This function is available since SDL 3.2.0.
*
@@ -313,7 +328,8 @@ extern SDL_DECLSPEC SDL_Colorspace SDLCALL SDL_GetSurfaceColorspace(SDL_Surface
* the surface didn't have an index format); call SDL_GetError() for
* more information.
*
- * \threadsafety This function is not thread safe.
+ * \threadsafety This function can be called on different threads with
+ * different surfaces.
*
* \since This function is available since SDL 3.2.0.
*
@@ -324,6 +340,9 @@ extern SDL_DECLSPEC SDL_Palette * SDLCALL SDL_CreateSurfacePalette(SDL_Surface *
/**
* Set the palette used by a surface.
*
+ * Setting the palette keeps an internal reference to the palette, which can
+ * be safely destroyed afterwards.
+ *
* A single palette can be shared with many surfaces.
*
* \param surface the SDL_Surface structure to update.
@@ -331,7 +350,8 @@ extern SDL_DECLSPEC SDL_Palette * SDLCALL SDL_CreateSurfacePalette(SDL_Surface *
* \returns true on success or false on failure; call SDL_GetError() for more
* information.
*
- * \threadsafety This function is not thread safe.
+ * \threadsafety This function can be called on different threads with
+ * different surfaces.
*
* \since This function is available since SDL 3.2.0.
*
@@ -372,7 +392,8 @@ extern SDL_DECLSPEC SDL_Palette * SDLCALL SDL_GetSurfacePalette(SDL_Surface *sur
* \returns true on success or false on failure; call SDL_GetError() for more
* information.
*
- * \threadsafety This function is not thread safe.
+ * \threadsafety This function can be called on different threads with
+ * different surfaces.
*
* \since This function is available since SDL 3.2.0.
*
@@ -415,7 +436,8 @@ extern SDL_DECLSPEC bool SDLCALL SDL_SurfaceHasAlternateImages(SDL_Surface *surf
* failure; call SDL_GetError() for more information. This should be
* freed with SDL_free() when it is no longer needed.
*
- * \threadsafety This function is not thread safe.
+ * \threadsafety This function can be called on different threads with
+ * different surfaces.
*
* \since This function is available since SDL 3.2.0.
*
@@ -433,7 +455,8 @@ extern SDL_DECLSPEC SDL_Surface ** SDLCALL SDL_GetSurfaceImages(SDL_Surface *sur
*
* \param surface the SDL_Surface structure to update.
*
- * \threadsafety This function is not thread safe.
+ * \threadsafety This function can be called on different threads with
+ * different surfaces.
*
* \since This function is available since SDL 3.2.0.
*
@@ -459,9 +482,10 @@ extern SDL_DECLSPEC void SDLCALL SDL_RemoveSurfaceAlternateImages(SDL_Surface *s
* \returns true on success or false on failure; call SDL_GetError() for more
* information.
*
- * \threadsafety This function is not thread safe. The locking referred to by
- * this function is making the pixels available for direct
- * access, not thread-safe locking.
+ * \threadsafety This function can be called on different threads with
+ * different surfaces. The locking referred to by this function
+ * is making the pixels available for direct access, not
+ * thread-safe locking.
*
* \since This function is available since SDL 3.2.0.
*
@@ -485,6 +509,46 @@ extern SDL_DECLSPEC bool SDLCALL SDL_LockSurface(SDL_Surface *surface);
*/
extern SDL_DECLSPEC void SDLCALL SDL_UnlockSurface(SDL_Surface *surface);
+/**
+ * Load a BMP or PNG image from a seekable SDL data stream.
+ *
+ * The new surface should be freed with SDL_DestroySurface(). Not doing so
+ * will result in a memory leak.
+ *
+ * \param src the data stream for the surface.
+ * \param closeio if true, calls SDL_CloseIO() on `src` before returning, even
+ * in the case of an error.
+ * \returns a pointer to a new SDL_Surface structure or NULL on failure; call
+ * SDL_GetError() for more information.
+ *
+ * \threadsafety It is safe to call this function from any thread.
+ *
+ * \since This function is available since SDL 3.4.0.
+ *
+ * \sa SDL_DestroySurface
+ * \sa SDL_LoadSurface
+ */
+extern SDL_DECLSPEC SDL_Surface * SDLCALL SDL_LoadSurface_IO(SDL_IOStream *src, bool closeio);
+
+/**
+ * Load a BMP or PNG image from a file.
+ *
+ * The new surface should be freed with SDL_DestroySurface(). Not doing so
+ * will result in a memory leak.
+ *
+ * \param file the file to load.
+ * \returns a pointer to a new SDL_Surface structure or NULL on failure; call
+ * SDL_GetError() for more information.
+ *
+ * \threadsafety It is safe to call this function from any thread.
+ *
+ * \since This function is available since SDL 3.4.0.
+ *
+ * \sa SDL_DestroySurface
+ * \sa SDL_LoadSurface_IO
+ */
+extern SDL_DECLSPEC SDL_Surface * SDLCALL SDL_LoadSurface(const char *file);
+
/**
* Load a BMP image from a seekable SDL data stream.
*
@@ -543,7 +607,8 @@ extern SDL_DECLSPEC SDL_Surface * SDLCALL SDL_LoadBMP(const char *file);
* \returns true on success or false on failure; call SDL_GetError() for more
* information.
*
- * \threadsafety This function is not thread safe.
+ * \threadsafety This function can be called on different threads with
+ * different surfaces.
*
* \since This function is available since SDL 3.2.0.
*
@@ -553,7 +618,7 @@ extern SDL_DECLSPEC SDL_Surface * SDLCALL SDL_LoadBMP(const char *file);
extern SDL_DECLSPEC bool SDLCALL SDL_SaveBMP_IO(SDL_Surface *surface, SDL_IOStream *dst, bool closeio);
/**
- * Save a surface to a file.
+ * Save a surface to a file in BMP format.
*
* Surfaces with a 24-bit, 32-bit and paletted 8-bit format get saved in the
* BMP directly. Other RGB formats with 8-bit or higher get converted to a
@@ -566,7 +631,8 @@ extern SDL_DECLSPEC bool SDLCALL SDL_SaveBMP_IO(SDL_Surface *surface, SDL_IOStre
* \returns true on success or false on failure; call SDL_GetError() for more
* information.
*
- * \threadsafety This function is not thread safe.
+ * \threadsafety This function can be called on different threads with
+ * different surfaces.
*
* \since This function is available since SDL 3.2.0.
*
@@ -575,6 +641,94 @@ extern SDL_DECLSPEC bool SDLCALL SDL_SaveBMP_IO(SDL_Surface *surface, SDL_IOStre
*/
extern SDL_DECLSPEC bool SDLCALL SDL_SaveBMP(SDL_Surface *surface, const char *file);
+/**
+ * Load a PNG image from a seekable SDL data stream.
+ *
+ * This is intended as a convenience function for loading images from trusted
+ * sources. If you want to load arbitrary images you should use libpng or
+ * another image loading library designed with security in mind.
+ *
+ * The new surface should be freed with SDL_DestroySurface(). Not doing so
+ * will result in a memory leak.
+ *
+ * \param src the data stream for the surface.
+ * \param closeio if true, calls SDL_CloseIO() on `src` before returning, even
+ * in the case of an error.
+ * \returns a pointer to a new SDL_Surface structure or NULL on failure; call
+ * SDL_GetError() for more information.
+ *
+ * \threadsafety It is safe to call this function from any thread.
+ *
+ * \since This function is available since SDL 3.4.0.
+ *
+ * \sa SDL_DestroySurface
+ * \sa SDL_LoadPNG
+ * \sa SDL_SavePNG_IO
+ */
+extern SDL_DECLSPEC SDL_Surface * SDLCALL SDL_LoadPNG_IO(SDL_IOStream *src, bool closeio);
+
+/**
+ * Load a PNG image from a file.
+ *
+ * This is intended as a convenience function for loading images from trusted
+ * sources. If you want to load arbitrary images you should use libpng or
+ * another image loading library designed with security in mind.
+ *
+ * The new surface should be freed with SDL_DestroySurface(). Not doing so
+ * will result in a memory leak.
+ *
+ * \param file the PNG file to load.
+ * \returns a pointer to a new SDL_Surface structure or NULL on failure; call
+ * SDL_GetError() for more information.
+ *
+ * \threadsafety It is safe to call this function from any thread.
+ *
+ * \since This function is available since SDL 3.4.0.
+ *
+ * \sa SDL_DestroySurface
+ * \sa SDL_LoadPNG_IO
+ * \sa SDL_SavePNG
+ */
+extern SDL_DECLSPEC SDL_Surface * SDLCALL SDL_LoadPNG(const char *file);
+
+/**
+ * Save a surface to a seekable SDL data stream in PNG format.
+ *
+ * \param surface the SDL_Surface structure containing the image to be saved.
+ * \param dst a data stream to save to.
+ * \param closeio if true, calls SDL_CloseIO() on `dst` before returning, even
+ * in the case of an error.
+ * \returns true on success or false on failure; call SDL_GetError() for more
+ * information.
+ *
+ * \threadsafety This function can be called on different threads with
+ * different surfaces.
+ *
+ * \since This function is available since SDL 3.4.0.
+ *
+ * \sa SDL_LoadPNG_IO
+ * \sa SDL_SavePNG
+ */
+extern SDL_DECLSPEC bool SDLCALL SDL_SavePNG_IO(SDL_Surface *surface, SDL_IOStream *dst, bool closeio);
+
+/**
+ * Save a surface to a file in PNG format.
+ *
+ * \param surface the SDL_Surface structure containing the image to be saved.
+ * \param file a file to save to.
+ * \returns true on success or false on failure; call SDL_GetError() for more
+ * information.
+ *
+ * \threadsafety This function can be called on different threads with
+ * different surfaces.
+ *
+ * \since This function is available since SDL 3.4.0.
+ *
+ * \sa SDL_LoadPNG
+ * \sa SDL_SavePNG_IO
+ */
+extern SDL_DECLSPEC bool SDLCALL SDL_SavePNG(SDL_Surface *surface, const char *file);
+
/**
* Set the RLE acceleration hint for a surface.
*
@@ -586,7 +740,8 @@ extern SDL_DECLSPEC bool SDLCALL SDL_SaveBMP(SDL_Surface *surface, const char *f
* \returns true on success or false on failure; call SDL_GetError() for more
* information.
*
- * \threadsafety This function is not thread safe.
+ * \threadsafety This function can be called on different threads with
+ * different surfaces.
*
* \since This function is available since SDL 3.2.0.
*
@@ -628,7 +783,8 @@ extern SDL_DECLSPEC bool SDLCALL SDL_SurfaceHasRLE(SDL_Surface *surface);
* \returns true on success or false on failure; call SDL_GetError() for more
* information.
*
- * \threadsafety This function is not thread safe.
+ * \threadsafety This function can be called on different threads with
+ * different surfaces.
*
* \since This function is available since SDL 3.2.0.
*
@@ -693,7 +849,8 @@ extern SDL_DECLSPEC bool SDLCALL SDL_GetSurfaceColorKey(SDL_Surface *surface, Ui
* \returns true on success or false on failure; call SDL_GetError() for more
* information.
*
- * \threadsafety This function is not thread safe.
+ * \threadsafety This function can be called on different threads with
+ * different surfaces.
*
* \since This function is available since SDL 3.2.0.
*
@@ -713,7 +870,8 @@ extern SDL_DECLSPEC bool SDLCALL SDL_SetSurfaceColorMod(SDL_Surface *surface, Ui
* \returns true on success or false on failure; call SDL_GetError() for more
* information.
*
- * \threadsafety This function is not thread safe.
+ * \threadsafety This function can be called on different threads with
+ * different surfaces.
*
* \since This function is available since SDL 3.2.0.
*
@@ -735,7 +893,8 @@ extern SDL_DECLSPEC bool SDLCALL SDL_GetSurfaceColorMod(SDL_Surface *surface, Ui
* \returns true on success or false on failure; call SDL_GetError() for more
* information.
*
- * \threadsafety This function is not thread safe.
+ * \threadsafety This function can be called on different threads with
+ * different surfaces.
*
* \since This function is available since SDL 3.2.0.
*
@@ -773,7 +932,8 @@ extern SDL_DECLSPEC bool SDLCALL SDL_GetSurfaceAlphaMod(SDL_Surface *surface, Ui
* \returns true on success or false on failure; call SDL_GetError() for more
* information.
*
- * \threadsafety This function is not thread safe.
+ * \threadsafety This function can be called on different threads with
+ * different surfaces.
*
* \since This function is available since SDL 3.2.0.
*
@@ -812,7 +972,8 @@ extern SDL_DECLSPEC bool SDLCALL SDL_GetSurfaceBlendMode(SDL_Surface *surface, S
* \returns true if the rectangle intersects the surface, otherwise false and
* blits will be completely clipped.
*
- * \threadsafety This function is not thread safe.
+ * \threadsafety This function can be called on different threads with
+ * different surfaces.
*
* \since This function is available since SDL 3.2.0.
*
@@ -833,7 +994,8 @@ extern SDL_DECLSPEC bool SDLCALL SDL_SetSurfaceClipRect(SDL_Surface *surface, co
* \returns true on success or false on failure; call SDL_GetError() for more
* information.
*
- * \threadsafety This function is not thread safe.
+ * \threadsafety This function can be called on different threads with
+ * different surfaces.
*
* \since This function is available since SDL 3.2.0.
*
@@ -849,12 +1011,42 @@ extern SDL_DECLSPEC bool SDLCALL SDL_GetSurfaceClipRect(SDL_Surface *surface, SD
* \returns true on success or false on failure; call SDL_GetError() for more
* information.
*
- * \threadsafety This function is not thread safe.
+ * \threadsafety This function can be called on different threads with
+ * different surfaces.
*
* \since This function is available since SDL 3.2.0.
*/
extern SDL_DECLSPEC bool SDLCALL SDL_FlipSurface(SDL_Surface *surface, SDL_FlipMode flip);
+/**
+ * Return a copy of a surface rotated clockwise a number of degrees.
+ *
+ * The angle of rotation can be negative for counter-clockwise rotation.
+ *
+ * When the rotation isn't a multiple of 90 degrees, the resulting surface is
+ * larger than the original, with the background filled in with the colorkey,
+ * if available, or RGBA 255/255/255/0 if not.
+ *
+ * If `surface` has the SDL_PROP_SURFACE_ROTATION_FLOAT property set on it,
+ * the new copy will have the adjusted value set: if the rotation property is
+ * 90 and `angle` was 30, the new surface will have a property value of 60
+ * (that is: to be upright vs gravity, this surface needs to rotate 60 more
+ * degrees). However, note that further rotations on the new surface in this
+ * example will produce unexpected results, since the image will have resized
+ * and padded to accommodate the not-90 degree angle.
+ *
+ * \param surface the surface to rotate.
+ * \param angle the rotation angle, in degrees.
+ * \returns a rotated copy of the surface or NULL on failure; call
+ * SDL_GetError() for more information.
+ *
+ * \threadsafety This function can be called on different threads with
+ * different surfaces.
+ *
+ * \since This function is available since SDL 3.4.0.
+ */
+extern SDL_DECLSPEC SDL_Surface * SDLCALL SDL_RotateSurface(SDL_Surface *surface, float angle);
+
/**
* Creates a new surface identical to the existing surface.
*
@@ -867,7 +1059,8 @@ extern SDL_DECLSPEC bool SDLCALL SDL_FlipSurface(SDL_Surface *surface, SDL_FlipM
* \returns a copy of the surface or NULL on failure; call SDL_GetError() for
* more information.
*
- * \threadsafety This function is not thread safe.
+ * \threadsafety This function can be called on different threads with
+ * different surfaces.
*
* \since This function is available since SDL 3.2.0.
*
@@ -888,7 +1081,8 @@ extern SDL_DECLSPEC SDL_Surface * SDLCALL SDL_DuplicateSurface(SDL_Surface *surf
* \returns a copy of the surface or NULL on failure; call SDL_GetError() for
* more information.
*
- * \threadsafety This function is not thread safe.
+ * \threadsafety This function can be called on different threads with
+ * different surfaces.
*
* \since This function is available since SDL 3.2.0.
*
@@ -915,7 +1109,8 @@ extern SDL_DECLSPEC SDL_Surface * SDLCALL SDL_ScaleSurface(SDL_Surface *surface,
* \returns the new SDL_Surface structure that is created or NULL on failure;
* call SDL_GetError() for more information.
*
- * \threadsafety This function is not thread safe.
+ * \threadsafety This function can be called on different threads with
+ * different surfaces.
*
* \since This function is available since SDL 3.2.0.
*
@@ -943,7 +1138,8 @@ extern SDL_DECLSPEC SDL_Surface * SDLCALL SDL_ConvertSurface(SDL_Surface *surfac
* \returns the new SDL_Surface structure that is created or NULL on failure;
* call SDL_GetError() for more information.
*
- * \threadsafety This function is not thread safe.
+ * \threadsafety This function can be called on different threads with
+ * different surfaces.
*
* \since This function is available since SDL 3.2.0.
*
@@ -1046,7 +1242,8 @@ extern SDL_DECLSPEC bool SDLCALL SDL_PremultiplyAlpha(int width, int height, SDL
* \returns true on success or false on failure; call SDL_GetError() for more
* information.
*
- * \threadsafety This function is not thread safe.
+ * \threadsafety This function can be called on different threads with
+ * different surfaces.
*
* \since This function is available since SDL 3.2.0.
*/
@@ -1058,7 +1255,7 @@ extern SDL_DECLSPEC bool SDLCALL SDL_PremultiplySurfaceAlpha(SDL_Surface *surfac
* This function handles all surface formats, and ignores any clip rectangle.
*
* If the surface is YUV, the color is assumed to be in the sRGB colorspace,
- * otherwise the color is assumed to be in the colorspace of the suface.
+ * otherwise the color is assumed to be in the colorspace of the surface.
*
* \param surface the SDL_Surface to clear.
* \param r the red component of the pixel, normally in the range 0-1.
@@ -1068,7 +1265,8 @@ extern SDL_DECLSPEC bool SDLCALL SDL_PremultiplySurfaceAlpha(SDL_Surface *surfac
* \returns true on success or false on failure; call SDL_GetError() for more
* information.
*
- * \threadsafety This function is not thread safe.
+ * \threadsafety This function can be called on different threads with
+ * different surfaces.
*
* \since This function is available since SDL 3.2.0.
*/
@@ -1093,7 +1291,8 @@ extern SDL_DECLSPEC bool SDLCALL SDL_ClearSurface(SDL_Surface *surface, float r,
* \returns true on success or false on failure; call SDL_GetError() for more
* information.
*
- * \threadsafety This function is not thread safe.
+ * \threadsafety This function can be called on different threads with
+ * different surfaces.
*
* \since This function is available since SDL 3.2.0.
*
@@ -1120,7 +1319,8 @@ extern SDL_DECLSPEC bool SDLCALL SDL_FillSurfaceRect(SDL_Surface *dst, const SDL
* \returns true on success or false on failure; call SDL_GetError() for more
* information.
*
- * \threadsafety This function is not thread safe.
+ * \threadsafety This function can be called on different threads with
+ * different surfaces.
*
* \since This function is available since SDL 3.2.0.
*
@@ -1411,7 +1611,8 @@ extern SDL_DECLSPEC bool SDLCALL SDL_BlitSurface9Grid(SDL_Surface *src, const SD
* \param b the blue component of the pixel in the range 0-255.
* \returns a pixel value.
*
- * \threadsafety It is safe to call this function from any thread.
+ * \threadsafety This function can be called on different threads with
+ * different surfaces.
*
* \since This function is available since SDL 3.2.0.
*
@@ -1444,7 +1645,8 @@ extern SDL_DECLSPEC Uint32 SDLCALL SDL_MapSurfaceRGB(SDL_Surface *surface, Uint8
* \param a the alpha component of the pixel in the range 0-255.
* \returns a pixel value.
*
- * \threadsafety It is safe to call this function from any thread.
+ * \threadsafety This function can be called on different threads with
+ * different surfaces.
*
* \since This function is available since SDL 3.2.0.
*
@@ -1475,7 +1677,8 @@ extern SDL_DECLSPEC Uint32 SDLCALL SDL_MapSurfaceRGBA(SDL_Surface *surface, Uint
* \returns true on success or false on failure; call SDL_GetError() for more
* information.
*
- * \threadsafety This function is not thread safe.
+ * \threadsafety This function can be called on different threads with
+ * different surfaces.
*
* \since This function is available since SDL 3.2.0.
*/
@@ -1501,7 +1704,8 @@ extern SDL_DECLSPEC bool SDLCALL SDL_ReadSurfacePixel(SDL_Surface *surface, int
* \returns true on success or false on failure; call SDL_GetError() for more
* information.
*
- * \threadsafety This function is not thread safe.
+ * \threadsafety This function can be called on different threads with
+ * different surfaces.
*
* \since This function is available since SDL 3.2.0.
*/
@@ -1526,7 +1730,8 @@ extern SDL_DECLSPEC bool SDLCALL SDL_ReadSurfacePixelFloat(SDL_Surface *surface,
* \returns true on success or false on failure; call SDL_GetError() for more
* information.
*
- * \threadsafety This function is not thread safe.
+ * \threadsafety This function can be called on different threads with
+ * different surfaces.
*
* \since This function is available since SDL 3.2.0.
*/
@@ -1548,7 +1753,8 @@ extern SDL_DECLSPEC bool SDLCALL SDL_WriteSurfacePixel(SDL_Surface *surface, int
* \returns true on success or false on failure; call SDL_GetError() for more
* information.
*
- * \threadsafety This function is not thread safe.
+ * \threadsafety This function can be called on different threads with
+ * different surfaces.
*
* \since This function is available since SDL 3.2.0.
*/
diff --git a/thirdparty/sdl/include/SDL3/SDL_system.h b/thirdparty/sdl/include/SDL3/SDL_system.h
index 294089ff4a3..ec23a1fe780 100644
--- a/thirdparty/sdl/include/SDL3/SDL_system.h
+++ b/thirdparty/sdl/include/SDL3/SDL_system.h
@@ -1,6 +1,6 @@
/*
Simple DirectMedia Layer
- Copyright (C) 1997-2025 Sam Lantinga <[email protected]>
+ Copyright (C) 1997-2026 Sam Lantinga <[email protected]>
This software is provided 'as-is', without any express or implied
warranty. In no event will the authors be held liable for any damages
@@ -86,6 +86,8 @@ typedef bool (SDLCALL *SDL_WindowsMessageHook)(void *userdata, MSG *msg);
* \param callback the SDL_WindowsMessageHook function to call.
* \param userdata a pointer to pass to every iteration of `callback`.
*
+ * \threadsafety This function should only be called on the main thread.
+ *
* \since This function is available since SDL 3.2.0.
*
* \sa SDL_WindowsMessageHook
@@ -169,6 +171,8 @@ typedef bool (SDLCALL *SDL_X11EventHook)(void *userdata, XEvent *xevent);
* \param callback the SDL_X11EventHook function to call.
* \param userdata a pointer to pass to every iteration of `callback`.
*
+ * \threadsafety This function should only be called on the main thread.
+ *
* \since This function is available since SDL 3.2.0.
*/
extern SDL_DECLSPEC void SDLCALL SDL_SetX11EventHook(SDL_X11EventHook callback, void *userdata);
@@ -186,6 +190,8 @@ extern SDL_DECLSPEC void SDLCALL SDL_SetX11EventHook(SDL_X11EventHook callback,
* \returns true on success or false on failure; call SDL_GetError() for more
* information.
*
+ * \threadsafety It is safe to call this function from any thread.
+ *
* \since This function is available since SDL 3.2.0.
*/
extern SDL_DECLSPEC bool SDLCALL SDL_SetLinuxThreadPriority(Sint64 threadID, int priority);
@@ -202,6 +208,8 @@ extern SDL_DECLSPEC bool SDLCALL SDL_SetLinuxThreadPriority(Sint64 threadID, int
* \returns true on success or false on failure; call SDL_GetError() for more
* information.
*
+ * \threadsafety It is safe to call this function from any thread.
+ *
* \since This function is available since SDL 3.2.0.
*/
extern SDL_DECLSPEC bool SDLCALL SDL_SetLinuxThreadPriorityAndPolicy(Sint64 threadID, int sdlPriority, int schedPolicy);
@@ -247,14 +255,14 @@ typedef void (SDLCALL *SDL_iOSAnimationCallback)(void *userdata);
*
* For more information see:
*
- * https://wiki.libsdl.org/SDL3/README/ios
+ * https://wiki.libsdl.org/SDL3/README-ios
*
* Note that if you use the "main callbacks" instead of a standard C `main`
* function, you don't have to use this API, as SDL will manage this for you.
*
* Details on main callbacks are here:
*
- * https://wiki.libsdl.org/SDL3/README/main-functions
+ * https://wiki.libsdl.org/SDL3/README-main-functions
*
* \param window the window for which the animation callback should be set.
* \param interval the number of frames after which **callback** will be
@@ -264,6 +272,8 @@ typedef void (SDLCALL *SDL_iOSAnimationCallback)(void *userdata);
* \returns true on success or false on failure; call SDL_GetError() for more
* information.
*
+ * \threadsafety This function should only be called on the main thread.
+ *
* \since This function is available since SDL 3.2.0.
*
* \sa SDL_SetiOSEventPump
@@ -277,6 +287,8 @@ extern SDL_DECLSPEC bool SDLCALL SDL_SetiOSAnimationCallback(SDL_Window *window,
*
* \param enabled true to enable the event pump, false to disable it.
*
+ * \threadsafety This function should only be called on the main thread.
+ *
* \since This function is available since SDL 3.2.0.
*
* \sa SDL_SetiOSAnimationCallback
@@ -370,6 +382,8 @@ extern SDL_DECLSPEC void * SDLCALL SDL_GetAndroidActivity(void);
*
* \returns the Android API level.
*
+ * \threadsafety It is safe to call this function from any thread.
+ *
* \since This function is available since SDL 3.2.0.
*/
extern SDL_DECLSPEC int SDLCALL SDL_GetAndroidSDKVersion(void);
@@ -379,6 +393,8 @@ extern SDL_DECLSPEC int SDLCALL SDL_GetAndroidSDKVersion(void);
*
* \returns true if this is a Chromebook, false otherwise.
*
+ * \threadsafety It is safe to call this function from any thread.
+ *
* \since This function is available since SDL 3.2.0.
*/
extern SDL_DECLSPEC bool SDLCALL SDL_IsChromebook(void);
@@ -388,6 +404,8 @@ extern SDL_DECLSPEC bool SDLCALL SDL_IsChromebook(void);
*
* \returns true if this is a DeX docking station, false otherwise.
*
+ * \threadsafety It is safe to call this function from any thread.
+ *
* \since This function is available since SDL 3.2.0.
*/
extern SDL_DECLSPEC bool SDLCALL SDL_IsDeXMode(void);
@@ -605,6 +623,8 @@ extern SDL_DECLSPEC bool SDLCALL SDL_SendAndroidMessage(Uint32 command, int para
*
* \returns true if the device is a tablet, false otherwise.
*
+ * \threadsafety It is safe to call this function from any thread.
+ *
* \since This function is available since SDL 3.2.0.
*/
extern SDL_DECLSPEC bool SDLCALL SDL_IsTablet(void);
@@ -616,6 +636,8 @@ extern SDL_DECLSPEC bool SDLCALL SDL_IsTablet(void);
*
* \returns true if the device is a TV, false otherwise.
*
+ * \threadsafety It is safe to call this function from any thread.
+ *
* \since This function is available since SDL 3.2.0.
*/
extern SDL_DECLSPEC bool SDLCALL SDL_IsTV(void);
diff --git a/thirdparty/sdl/include/SDL3/SDL_thread.h b/thirdparty/sdl/include/SDL3/SDL_thread.h
index e981b542932..1842c035f71 100644
--- a/thirdparty/sdl/include/SDL3/SDL_thread.h
+++ b/thirdparty/sdl/include/SDL3/SDL_thread.h
@@ -1,6 +1,6 @@
/*
Simple DirectMedia Layer
- Copyright (C) 1997-2025 Sam Lantinga <[email protected]>
+ Copyright (C) 1997-2026 Sam Lantinga <[email protected]>
This software is provided 'as-is', without any express or implied
warranty. In no event will the authors be held liable for any damages
@@ -37,7 +37,8 @@
* will report failure without doing anything.
*
* If you're going to work with threads, you almost certainly need to have a
- * good understanding of [CategoryMutex](CategoryMutex) as well.
+ * good understanding of thread safety measures: locking and synchronization
+ * mechanisms are handled by the functions in SDL_mutex.h.
*/
#include <SDL3/SDL_stdinc.h>
@@ -207,6 +208,8 @@ typedef int (SDLCALL *SDL_ThreadFunction) (void *data);
* new thread could not be created; call SDL_GetError() for more
* information.
*
+ * \threadsafety It is safe to call this function from any thread.
+ *
* \since This function is available since SDL 3.2.0.
*
* \sa SDL_CreateThreadWithProperties
@@ -273,6 +276,8 @@ extern SDL_DECLSPEC SDL_Thread * SDLCALL SDL_CreateThread(SDL_ThreadFunction fn,
* new thread could not be created; call SDL_GetError() for more
* information.
*
+ * \threadsafety It is safe to call this function from any thread.
+ *
* \since This function is available since SDL 3.2.0.
*
* \sa SDL_CreateThread
@@ -328,6 +333,8 @@ extern SDL_DECLSPEC SDL_Thread * SDLCALL SDL_CreateThreadWithProperties(SDL_Prop
* new thread could not be created; call SDL_GetError() for more
* information.
*
+ * \threadsafety It is safe to call this function from any thread.
+ *
* \since This function is available since SDL 3.2.0.
*/
extern SDL_DECLSPEC SDL_Thread * SDLCALL SDL_CreateThreadRuntime(SDL_ThreadFunction fn, const char *name, void *data, SDL_FunctionPointer pfnBeginThread, SDL_FunctionPointer pfnEndThread);
@@ -342,6 +349,8 @@ extern SDL_DECLSPEC SDL_Thread * SDLCALL SDL_CreateThreadRuntime(SDL_ThreadFunct
* new thread could not be created; call SDL_GetError() for more
* information.
*
+ * \threadsafety It is safe to call this function from any thread.
+ *
* \since This function is available since SDL 3.2.0.
*/
extern SDL_DECLSPEC SDL_Thread * SDLCALL SDL_CreateThreadWithPropertiesRuntime(SDL_PropertiesID props, SDL_FunctionPointer pfnBeginThread, SDL_FunctionPointer pfnEndThread);
@@ -362,6 +371,8 @@ extern SDL_DECLSPEC SDL_Thread * SDLCALL SDL_CreateThreadWithPropertiesRuntime(S
* \returns a pointer to a UTF-8 string that names the specified thread, or
* NULL if it doesn't have a name.
*
+ * \threadsafety It is safe to call this function from any thread.
+ *
* \since This function is available since SDL 3.2.0.
*/
extern SDL_DECLSPEC const char * SDLCALL SDL_GetThreadName(SDL_Thread *thread);
@@ -378,6 +389,8 @@ extern SDL_DECLSPEC const char * SDLCALL SDL_GetThreadName(SDL_Thread *thread);
*
* \returns the ID of the current thread.
*
+ * \threadsafety It is safe to call this function from any thread.
+ *
* \since This function is available since SDL 3.2.0.
*
* \sa SDL_GetThreadID
@@ -395,6 +408,8 @@ extern SDL_DECLSPEC SDL_ThreadID SDLCALL SDL_GetCurrentThreadID(void);
* \returns the ID of the specified thread, or the ID of the current thread if
* `thread` is NULL.
*
+ * \threadsafety It is safe to call this function from any thread.
+ *
* \since This function is available since SDL 3.2.0.
*
* \sa SDL_GetCurrentThreadID
@@ -412,6 +427,8 @@ extern SDL_DECLSPEC SDL_ThreadID SDLCALL SDL_GetThreadID(SDL_Thread *thread);
* \returns true on success or false on failure; call SDL_GetError() for more
* information.
*
+ * \threadsafety It is safe to call this function from any thread.
+ *
* \since This function is available since SDL 3.2.0.
*/
extern SDL_DECLSPEC bool SDLCALL SDL_SetCurrentThreadPriority(SDL_ThreadPriority priority);
@@ -444,6 +461,9 @@ extern SDL_DECLSPEC bool SDLCALL SDL_SetCurrentThreadPriority(SDL_ThreadPriority
* function by its 'return', or -1 if the thread has been
* detached or isn't valid, may be NULL.
*
+ * \threadsafety It is safe to call this function from any thread, but only a
+ * single thread can wait any specific thread to finish.
+ *
* \since This function is available since SDL 3.2.0.
*
* \sa SDL_CreateThread
@@ -458,6 +478,8 @@ extern SDL_DECLSPEC void SDLCALL SDL_WaitThread(SDL_Thread *thread, int *status)
* \returns the current state of a thread, or SDL_THREAD_UNKNOWN if the thread
* isn't valid.
*
+ * \threadsafety It is safe to call this function from any thread.
+ *
* \since This function is available since SDL 3.2.0.
*
* \sa SDL_ThreadState
@@ -493,6 +515,8 @@ extern SDL_DECLSPEC SDL_ThreadState SDLCALL SDL_GetThreadState(SDL_Thread *threa
* \param thread the SDL_Thread pointer that was returned from the
* SDL_CreateThread() call that started this thread.
*
+ * \threadsafety It is safe to call this function from any thread.
+ *
* \since This function is available since SDL 3.2.0.
*
* \sa SDL_CreateThread
diff --git a/thirdparty/sdl/include/SDL3/SDL_time.h b/thirdparty/sdl/include/SDL3/SDL_time.h
index b6d3f6d0d80..2ae6022f975 100644
--- a/thirdparty/sdl/include/SDL3/SDL_time.h
+++ b/thirdparty/sdl/include/SDL3/SDL_time.h
@@ -1,6 +1,6 @@
/*
Simple DirectMedia Layer
-Copyright (C) 1997-2025 Sam Lantinga <[email protected]>
+Copyright (C) 1997-2026 Sam Lantinga <[email protected]>
This software is provided 'as-is', without any express or implied
warranty. In no event will the authors be held liable for any damages
@@ -106,6 +106,8 @@ typedef enum SDL_TimeFormat
* \returns true on success or false on failure; call SDL_GetError() for more
* information.
*
+ * \threadsafety This function is not thread safe.
+ *
* \since This function is available since SDL 3.2.0.
*/
extern SDL_DECLSPEC bool SDLCALL SDL_GetDateTimeLocalePreferences(SDL_DateFormat *dateFormat, SDL_TimeFormat *timeFormat);
@@ -118,6 +120,8 @@ extern SDL_DECLSPEC bool SDLCALL SDL_GetDateTimeLocalePreferences(SDL_DateFormat
* \returns true on success or false on failure; call SDL_GetError() for more
* information.
*
+ * \threadsafety It is safe to call this function from any thread.
+ *
* \since This function is available since SDL 3.2.0.
*/
extern SDL_DECLSPEC bool SDLCALL SDL_GetCurrentTime(SDL_Time *ticks);
@@ -134,6 +138,8 @@ extern SDL_DECLSPEC bool SDLCALL SDL_GetCurrentTime(SDL_Time *ticks);
* \returns true on success or false on failure; call SDL_GetError() for more
* information.
*
+ * \threadsafety It is safe to call this function from any thread.
+ *
* \since This function is available since SDL 3.2.0.
*/
extern SDL_DECLSPEC bool SDLCALL SDL_TimeToDateTime(SDL_Time ticks, SDL_DateTime *dt, bool localTime);
@@ -149,6 +155,8 @@ extern SDL_DECLSPEC bool SDLCALL SDL_TimeToDateTime(SDL_Time ticks, SDL_DateTime
* \returns true on success or false on failure; call SDL_GetError() for more
* information.
*
+ * \threadsafety It is safe to call this function from any thread.
+ *
* \since This function is available since SDL 3.2.0.
*/
extern SDL_DECLSPEC bool SDLCALL SDL_DateTimeToTime(const SDL_DateTime *dt, SDL_Time *ticks);
@@ -165,6 +173,8 @@ extern SDL_DECLSPEC bool SDLCALL SDL_DateTimeToTime(const SDL_DateTime *dt, SDL_
* \param dwHighDateTime a pointer filled in with the high portion of the
* Windows FILETIME value.
*
+ * \threadsafety It is safe to call this function from any thread.
+ *
* \since This function is available since SDL 3.2.0.
*/
extern SDL_DECLSPEC void SDLCALL SDL_TimeToWindows(SDL_Time ticks, Uint32 *dwLowDateTime, Uint32 *dwHighDateTime);
@@ -180,6 +190,8 @@ extern SDL_DECLSPEC void SDLCALL SDL_TimeToWindows(SDL_Time ticks, Uint32 *dwLow
* \param dwHighDateTime the high portion of the Windows FILETIME value.
* \returns the converted SDL time.
*
+ * \threadsafety It is safe to call this function from any thread.
+ *
* \since This function is available since SDL 3.2.0.
*/
extern SDL_DECLSPEC SDL_Time SDLCALL SDL_TimeFromWindows(Uint32 dwLowDateTime, Uint32 dwHighDateTime);
@@ -192,6 +204,8 @@ extern SDL_DECLSPEC SDL_Time SDLCALL SDL_TimeFromWindows(Uint32 dwLowDateTime, U
* \returns the number of days in the requested month or -1 on failure; call
* SDL_GetError() for more information.
*
+ * \threadsafety It is safe to call this function from any thread.
+ *
* \since This function is available since SDL 3.2.0.
*/
extern SDL_DECLSPEC int SDLCALL SDL_GetDaysInMonth(int year, int month);
@@ -205,6 +219,8 @@ extern SDL_DECLSPEC int SDLCALL SDL_GetDaysInMonth(int year, int month);
* \returns the day of year [0-365] if the date is valid or -1 on failure;
* call SDL_GetError() for more information.
*
+ * \threadsafety It is safe to call this function from any thread.
+ *
* \since This function is available since SDL 3.2.0.
*/
extern SDL_DECLSPEC int SDLCALL SDL_GetDayOfYear(int year, int month, int day);
@@ -218,6 +234,8 @@ extern SDL_DECLSPEC int SDLCALL SDL_GetDayOfYear(int year, int month, int day);
* \returns a value between 0 and 6 (0 being Sunday) if the date is valid or
* -1 on failure; call SDL_GetError() for more information.
*
+ * \threadsafety It is safe to call this function from any thread.
+ *
* \since This function is available since SDL 3.2.0.
*/
extern SDL_DECLSPEC int SDLCALL SDL_GetDayOfWeek(int year, int month, int day);
diff --git a/thirdparty/sdl/include/SDL3/SDL_timer.h b/thirdparty/sdl/include/SDL3/SDL_timer.h
index cf94881d570..dfeec31f202 100644
--- a/thirdparty/sdl/include/SDL3/SDL_timer.h
+++ b/thirdparty/sdl/include/SDL3/SDL_timer.h
@@ -1,6 +1,6 @@
/*
Simple DirectMedia Layer
- Copyright (C) 1997-2025 Sam Lantinga <[email protected]>
+ Copyright (C) 1997-2026 Sam Lantinga <[email protected]>
This software is provided 'as-is', without any express or implied
warranty. In no event will the authors be held liable for any damages
@@ -34,7 +34,7 @@
* This category covers measuring time elapsed (SDL_GetTicks(),
* SDL_GetPerformanceCounter()), putting a thread to sleep for a certain
* amount of time (SDL_Delay(), SDL_DelayNS(), SDL_DelayPrecise()), and firing
- * a callback function after a certain amount of time has elasped
+ * a callback function after a certain amount of time has elapsed
* (SDL_AddTimer(), etc).
*
* There are also useful macros to convert between time units, like
@@ -185,14 +185,18 @@ extern "C" {
#define SDL_NS_TO_US(NS) ((NS) / SDL_NS_PER_US)
/**
- * Get the number of milliseconds since SDL library initialization.
+ * Get the number of milliseconds that have elapsed since the SDL library
+ * initialization.
*
- * \returns an unsigned 64-bit value representing the number of milliseconds
- * since the SDL library initialized.
+ * \returns an unsigned 64‑bit integer that represents the number of
+ * milliseconds that have elapsed since the SDL library was
+ * initialized (typically via a call to SDL_Init).
*
* \threadsafety It is safe to call this function from any thread.
*
* \since This function is available since SDL 3.2.0.
+ *
+ * \sa SDL_GetTicksNS
*/
extern SDL_DECLSPEC Uint64 SDLCALL SDL_GetTicks(void);
diff --git a/thirdparty/sdl/include/SDL3/SDL_touch.h b/thirdparty/sdl/include/SDL3/SDL_touch.h
index 64845a15682..e5576a5bcd1 100644
--- a/thirdparty/sdl/include/SDL3/SDL_touch.h
+++ b/thirdparty/sdl/include/SDL3/SDL_touch.h
@@ -1,6 +1,6 @@
/*
Simple DirectMedia Layer
- Copyright (C) 1997-2025 Sam Lantinga <[email protected]>
+ Copyright (C) 1997-2026 Sam Lantinga <[email protected]>
This software is provided 'as-is', without any express or implied
warranty. In no event will the authors be held liable for any damages
diff --git a/thirdparty/sdl/include/SDL3/SDL_tray.h b/thirdparty/sdl/include/SDL3/SDL_tray.h
index 1780b0ba52b..688278a1d32 100644
--- a/thirdparty/sdl/include/SDL3/SDL_tray.h
+++ b/thirdparty/sdl/include/SDL3/SDL_tray.h
@@ -1,6 +1,6 @@
/*
Simple DirectMedia Layer
- Copyright (C) 1997-2025 Sam Lantinga <[email protected]>
+ Copyright (C) 1997-2026 Sam Lantinga <[email protected]>
This software is provided 'as-is', without any express or implied
warranty. In no event will the authors be held liable for any damages
diff --git a/thirdparty/sdl/include/SDL3/SDL_version.h b/thirdparty/sdl/include/SDL3/SDL_version.h
index 4c3b9b9645f..6b7816e0d4d 100644
--- a/thirdparty/sdl/include/SDL3/SDL_version.h
+++ b/thirdparty/sdl/include/SDL3/SDL_version.h
@@ -1,6 +1,6 @@
/*
Simple DirectMedia Layer
- Copyright (C) 1997-2025 Sam Lantinga <[email protected]>
+ Copyright (C) 1997-2026 Sam Lantinga <[email protected]>
This software is provided 'as-is', without any express or implied
warranty. In no event will the authors be held liable for any damages
@@ -53,7 +53,7 @@ extern "C" {
*
* \since This macro is available since SDL 3.2.0.
*/
-#define SDL_MINOR_VERSION 2
+#define SDL_MINOR_VERSION 4
/**
* The current micro (or patchlevel) version of the SDL headers.
@@ -62,7 +62,7 @@ extern "C" {
*
* \since This macro is available since SDL 3.2.0.
*/
-#define SDL_MICRO_VERSION 28
+#define SDL_MICRO_VERSION 16
/**
* This macro turns the version numbers into a numeric value.
@@ -85,6 +85,8 @@ extern "C" {
*
* \param version the version number.
*
+ * \threadsafety It is safe to call this macro from any thread.
+ *
* \since This macro is available since SDL 3.2.0.
*/
#define SDL_VERSIONNUM_MAJOR(version) ((version) / 1000000)
@@ -96,6 +98,8 @@ extern "C" {
*
* \param version the version number.
*
+ * \threadsafety It is safe to call this macro from any thread.
+ *
* \since This macro is available since SDL 3.2.0.
*/
#define SDL_VERSIONNUM_MINOR(version) (((version) / 1000) % 1000)
@@ -107,6 +111,8 @@ extern "C" {
*
* \param version the version number.
*
+ * \threadsafety It is safe to call this macro from any thread.
+ *
* \since This macro is available since SDL 3.2.0.
*/
#define SDL_VERSIONNUM_MICRO(version) ((version) % 1000)
@@ -114,6 +120,8 @@ extern "C" {
/**
* This is the version number macro for the current SDL version.
*
+ * \threadsafety It is safe to call this macro from any thread.
+ *
* \since This macro is available since SDL 3.2.0.
*
* \sa SDL_GetVersion
@@ -124,6 +132,8 @@ extern "C" {
/**
* This macro will evaluate to true if compiled with SDL at least X.Y.Z.
*
+ * \threadsafety It is safe to call this macro from any thread.
+ *
* \since This macro is available since SDL 3.2.0.
*/
#define SDL_VERSION_ATLEAST(X, Y, Z) \
@@ -141,6 +151,8 @@ extern "C" {
*
* \returns the version of the linked library.
*
+ * \threadsafety It is safe to call this function from any thread.
+ *
* \since This function is available since SDL 3.2.0.
*
* \sa SDL_GetRevision
@@ -148,13 +160,14 @@ extern "C" {
extern SDL_DECLSPEC int SDLCALL SDL_GetVersion(void);
/**
- * Get the code revision of SDL that is linked against your program.
+ * Get the code revision of the SDL library that is linked against your
+ * program.
*
- * This value is the revision of the code you are linked with and may be
+ * This value is the revision of the code you are linking against and may be
* different from the code you are compiling with, which is found in the
- * constant SDL_REVISION.
+ * constant SDL_REVISION if you explicitly include SDL_revision.h
*
- * The revision is arbitrary string (a hash value) uniquely identifying the
+ * The revision is an arbitrary string (a hash value) uniquely identifying the
* exact revision of the SDL library in use, and is only useful in comparing
* against other revisions. It is NOT an incrementing number.
*
@@ -167,6 +180,8 @@ extern SDL_DECLSPEC int SDLCALL SDL_GetVersion(void);
* \returns an arbitrary string, uniquely identifying the exact revision of
* the SDL library in use.
*
+ * \threadsafety It is safe to call this function from any thread.
+ *
* \since This function is available since SDL 3.2.0.
*
* \sa SDL_GetVersion
diff --git a/thirdparty/sdl/include/SDL3/SDL_video.h b/thirdparty/sdl/include/SDL3/SDL_video.h
index ce40fe41777..2f062959fe6 100644
--- a/thirdparty/sdl/include/SDL3/SDL_video.h
+++ b/thirdparty/sdl/include/SDL3/SDL_video.h
@@ -1,6 +1,6 @@
/*
Simple DirectMedia Layer
- Copyright (C) 1997-2025 Sam Lantinga <[email protected]>
+ Copyright (C) 1997-2026 Sam Lantinga <[email protected]>
This software is provided 'as-is', without any express or implied
warranty. In no event will the authors be held liable for any damages
@@ -97,6 +97,8 @@ typedef Uint32 SDL_WindowID;
* uninitialized will either return the user provided value, if one was set
* prior to initialization, or NULL. See docs/README-wayland.md for more
* information.
+ *
+ * \since This macro is available since SDL 3.2.0.
*/
#define SDL_PROP_GLOBAL_VIDEO_WAYLAND_WL_DISPLAY_POINTER "SDL.video.wayland.wl_display"
@@ -180,6 +182,12 @@ typedef struct SDL_Window SDL_Window;
* changed on existing windows by the app, and some of it might be altered by
* the user or system outside of the app's control.
*
+ * When creating windows with `SDL_WINDOW_RESIZABLE`, SDL will constrain
+ * resizable windows to the dimensions recommended by the compositor to fit it
+ * within the usable desktop space, although some compositors will do this
+ * automatically without intervention as well. Use `SDL_SetWindowResizable`
+ * after creation instead if you wish to create a window with a specific size.
+ *
* \since This datatype is available since SDL 3.2.0.
*
* \sa SDL_GetWindowFlags
@@ -207,6 +215,7 @@ typedef Uint64 SDL_WindowFlags;
#define SDL_WINDOW_TOOLTIP SDL_UINT64_C(0x0000000000040000) /**< window should be treated as a tooltip and does not get mouse or keyboard focus, requires a parent window */
#define SDL_WINDOW_POPUP_MENU SDL_UINT64_C(0x0000000000080000) /**< window should be treated as a popup menu, requires a parent window */
#define SDL_WINDOW_KEYBOARD_GRABBED SDL_UINT64_C(0x0000000000100000) /**< window has grabbed keyboard input */
+#define SDL_WINDOW_FILL_DOCUMENT SDL_UINT64_C(0x0000000000200000) /**< window is in fill-document mode (Emscripten only), since SDL 3.4.0 */
#define SDL_WINDOW_VULKAN SDL_UINT64_C(0x0000000010000000) /**< window usable for Vulkan surface */
#define SDL_WINDOW_METAL SDL_UINT64_C(0x0000000020000000) /**< window usable for Metal view */
#define SDL_WINDOW_TRANSPARENT SDL_UINT64_C(0x0000000040000000) /**< window with transparent buffer */
@@ -220,6 +229,8 @@ typedef Uint64 SDL_WindowFlags;
* SDL_WINDOWPOS_UNDEFINED or SDL_WINDOWPOS_UNDEFINED_DISPLAY.
*
* \since This macro is available since SDL 3.2.0.
+ *
+ * \sa SDL_SetWindowPosition
*/
#define SDL_WINDOWPOS_UNDEFINED_MASK 0x1FFF0000u
@@ -232,6 +243,8 @@ typedef Uint64 SDL_WindowFlags;
* \param X the SDL_DisplayID of the display to use.
*
* \since This macro is available since SDL 3.2.0.
+ *
+ * \sa SDL_SetWindowPosition
*/
#define SDL_WINDOWPOS_UNDEFINED_DISPLAY(X) (SDL_WINDOWPOS_UNDEFINED_MASK|(X))
@@ -241,6 +254,8 @@ typedef Uint64 SDL_WindowFlags;
* This always uses the primary display.
*
* \since This macro is available since SDL 3.2.0.
+ *
+ * \sa SDL_SetWindowPosition
*/
#define SDL_WINDOWPOS_UNDEFINED SDL_WINDOWPOS_UNDEFINED_DISPLAY(0)
@@ -250,6 +265,8 @@ typedef Uint64 SDL_WindowFlags;
* \param X the window position value.
*
* \since This macro is available since SDL 3.2.0.
+ *
+ * \sa SDL_SetWindowPosition
*/
#define SDL_WINDOWPOS_ISUNDEFINED(X) (((X)&0xFFFF0000) == SDL_WINDOWPOS_UNDEFINED_MASK)
@@ -260,6 +277,8 @@ typedef Uint64 SDL_WindowFlags;
* SDL_WINDOWPOS_CENTERED or SDL_WINDOWPOS_CENTERED_DISPLAY.
*
* \since This macro is available since SDL 3.2.0.
+ *
+ * \sa SDL_SetWindowPosition
*/
#define SDL_WINDOWPOS_CENTERED_MASK 0x2FFF0000u
@@ -272,6 +291,8 @@ typedef Uint64 SDL_WindowFlags;
* \param X the SDL_DisplayID of the display to use.
*
* \since This macro is available since SDL 3.2.0.
+ *
+ * \sa SDL_SetWindowPosition
*/
#define SDL_WINDOWPOS_CENTERED_DISPLAY(X) (SDL_WINDOWPOS_CENTERED_MASK|(X))
@@ -281,6 +302,8 @@ typedef Uint64 SDL_WindowFlags;
* This always uses the primary display.
*
* \since This macro is available since SDL 3.2.0.
+ *
+ * \sa SDL_SetWindowPosition
*/
#define SDL_WINDOWPOS_CENTERED SDL_WINDOWPOS_CENTERED_DISPLAY(0)
@@ -290,6 +313,8 @@ typedef Uint64 SDL_WindowFlags;
* \param X the window position value.
*
* \since This macro is available since SDL 3.2.0.
+ *
+ * \sa SDL_GetWindowPosition
*/
#define SDL_WINDOWPOS_ISCENTERED(X) \
(((X)&0xFFFF0000) == SDL_WINDOWPOS_CENTERED_MASK)
@@ -307,12 +332,30 @@ typedef enum SDL_FlashOperation
SDL_FLASH_UNTIL_FOCUSED /**< Flash the window until it gets focus */
} SDL_FlashOperation;
+/**
+ * Window progress state
+ *
+ * \since This enum is available since SDL 3.2.8.
+ */
+typedef enum SDL_ProgressState
+{
+ SDL_PROGRESS_STATE_INVALID = -1, /**< An invalid progress state indicating an error; check SDL_GetError() */
+ SDL_PROGRESS_STATE_NONE, /**< No progress bar is shown */
+ SDL_PROGRESS_STATE_INDETERMINATE, /**< The progress bar is shown in a indeterminate state */
+ SDL_PROGRESS_STATE_NORMAL, /**< The progress bar is shown in a normal state */
+ SDL_PROGRESS_STATE_PAUSED, /**< The progress bar is shown in a paused state */
+ SDL_PROGRESS_STATE_ERROR /**< The progress bar is shown in a state indicating the application had an error */
+} SDL_ProgressState;
+
/**
* An opaque handle to an OpenGL context.
*
* \since This datatype is available since SDL 3.2.0.
*
* \sa SDL_GL_CreateContext
+ * \sa SDL_GL_SetAttribute
+ * \sa SDL_GL_MakeCurrent
+ * \sa SDL_GL_DestroyContext
*/
typedef struct SDL_GLContextState *SDL_GLContext;
@@ -448,7 +491,7 @@ typedef enum SDL_GLAttr
SDL_GL_CONTEXT_FLAGS, /**< some combination of 0 or more of elements of the SDL_GLContextFlag enumeration; defaults to 0. */
SDL_GL_CONTEXT_PROFILE_MASK, /**< type of GL context (Core, Compatibility, ES). See SDL_GLProfile; default value depends on platform. */
SDL_GL_SHARE_WITH_CURRENT_CONTEXT, /**< OpenGL context sharing; defaults to 0. */
- SDL_GL_FRAMEBUFFER_SRGB_CAPABLE, /**< requests sRGB capable visual; defaults to 0. */
+ SDL_GL_FRAMEBUFFER_SRGB_CAPABLE, /**< requests sRGB-capable visual if 1. Defaults to -1 ("don't care"). This is a request; GL drivers might not comply! */
SDL_GL_CONTEXT_RELEASE_BEHAVIOR, /**< sets context the release behavior. See SDL_GLContextReleaseFlag; defaults to FLUSH. */
SDL_GL_CONTEXT_RESET_NOTIFICATION, /**< set context reset notification. See SDL_GLContextResetNotification; defaults to NO_NOTIFICATION. */
SDL_GL_CONTEXT_NO_ERROR,
@@ -530,7 +573,8 @@ extern SDL_DECLSPEC int SDLCALL SDL_GetNumVideoDrivers(void);
* to be proper names.
*
* \param index the index of a video driver.
- * \returns the name of the video driver with the given **index**.
+ * \returns the name of the video driver with the given **index**, or NULL if
+ * index is out of bounds.
*
* \threadsafety This function should only be called on the main thread.
*
@@ -617,6 +661,16 @@ extern SDL_DECLSPEC SDL_DisplayID SDLCALL SDL_GetPrimaryDisplay(void);
* responsible for any coordinate transformations needed to conform to the
* requested display orientation.
*
+ * On Wayland:
+ *
+ * - `SDL_PROP_DISPLAY_WAYLAND_WL_OUTPUT_POINTER`: the wl_output associated
+ * with the display
+ *
+ * On Windows:
+ *
+ * - `SDL_PROP_DISPLAY_WINDOWS_HMONITOR_POINTER`: the monitor handle
+ * (HMONITOR) associated with the display
+ *
* \param displayID the instance ID of the display to query.
* \returns a valid property ID on success or 0 on failure; call
* SDL_GetError() for more information.
@@ -629,6 +683,8 @@ extern SDL_DECLSPEC SDL_PropertiesID SDLCALL SDL_GetDisplayProperties(SDL_Displa
#define SDL_PROP_DISPLAY_HDR_ENABLED_BOOLEAN "SDL.display.HDR_enabled"
#define SDL_PROP_DISPLAY_KMSDRM_PANEL_ORIENTATION_NUMBER "SDL.display.KMSDRM.panel_orientation"
+#define SDL_PROP_DISPLAY_WAYLAND_WL_OUTPUT_POINTER "SDL.display.wayland.wl_output"
+#define SDL_PROP_DISPLAY_WINDOWS_HMONITOR_POINTER "SDL.display.windows.hmonitor"
/**
* Get the name of a display in UTF-8 encoding.
@@ -1049,8 +1105,6 @@ extern SDL_DECLSPEC SDL_Window ** SDLCALL SDL_GetWindows(int *count);
*
* - `SDL_WINDOW_FULLSCREEN`: fullscreen window at desktop resolution
* - `SDL_WINDOW_OPENGL`: window usable with an OpenGL context
- * - `SDL_WINDOW_OCCLUDED`: window partially or completely obscured by another
- * window
* - `SDL_WINDOW_HIDDEN`: window is not visible
* - `SDL_WINDOW_BORDERLESS`: no window decoration
* - `SDL_WINDOW_RESIZABLE`: window can be resized
@@ -1078,7 +1132,8 @@ extern SDL_DECLSPEC SDL_Window ** SDLCALL SDL_GetWindows(int *count);
* - `SDL_WINDOW_TRANSPARENT`: window with transparent buffer
* - `SDL_WINDOW_NOT_FOCUSABLE`: window should not be focusable
*
- * The SDL_Window is implicitly shown if SDL_WINDOW_HIDDEN is not set.
+ * The SDL_Window will be shown if SDL_WINDOW_HIDDEN is not set. If hidden at
+ * creation time, SDL_ShowWindow() can be used to show it later.
*
* On Apple's macOS, you **must** set the NSHighResolutionCapable Info.plist
* property to YES, otherwise you will not receive a High-DPI OpenGL canvas.
@@ -1167,14 +1222,15 @@ extern SDL_DECLSPEC SDL_Window * SDLCALL SDL_CreateWindow(const char *title, int
* Popup windows implicitly do not have a border/decorations and do not appear
* on the taskbar/dock or in lists of windows such as alt-tab menus.
*
- * By default, popup window positions will automatically be constrained to keep
- * the entire window within display bounds. This can be overridden with the
- * `SDL_PROP_WINDOW_CREATE_CONSTRAIN_POPUP_BOOLEAN` property.
+ * By default, popup window positions will automatically be constrained to
+ * keep the entire window within display bounds. This can be overridden with
+ * the `SDL_PROP_WINDOW_CREATE_CONSTRAIN_POPUP_BOOLEAN` property.
*
- * By default, popup menus will automatically grab keyboard focus from the parent
- * when shown. This behavior can be overridden by setting the `SDL_WINDOW_NOT_FOCUSABLE`
- * flag, setting the `SDL_PROP_WINDOW_CREATE_FOCUSABLE_BOOLEAN` property to false, or
- * toggling it after creation via the `SDL_SetWindowFocusable()` function.
+ * By default, popup menus will automatically grab keyboard focus from the
+ * parent when shown. This behavior can be overridden by setting the
+ * `SDL_WINDOW_NOT_FOCUSABLE` flag, setting the
+ * `SDL_PROP_WINDOW_CREATE_FOCUSABLE_BOOLEAN` property to false, or toggling
+ * it after creation via the `SDL_SetWindowFocusable()` function.
*
* If a parent window is hidden or destroyed, any child popup windows will be
* recursively hidden or destroyed as well. Child popup windows not explicitly
@@ -1216,9 +1272,10 @@ extern SDL_DECLSPEC SDL_Window * SDLCALL SDL_CreatePopupWindow(SDL_Window *paren
* be always on top
* - `SDL_PROP_WINDOW_CREATE_BORDERLESS_BOOLEAN`: true if the window has no
* window decoration
- * - `SDL_PROP_WINDOW_CREATE_CONSTRAIN_POPUP_BOOLEAN`: true if the "tooltip" and
- * "menu" window types should be automatically constrained to be entirely within
- * display bounds (default), false if no constraints on the position are desired.
+ * - `SDL_PROP_WINDOW_CREATE_CONSTRAIN_POPUP_BOOLEAN`: true if the "tooltip"
+ * and "menu" window types should be automatically constrained to be
+ * entirely within display bounds (default), false if no constraints on the
+ * position are desired.
* - `SDL_PROP_WINDOW_CREATE_EXTERNAL_GRAPHICS_CONTEXT_BOOLEAN`: true if the
* window will be used with an externally managed graphics context.
* - `SDL_PROP_WINDOW_CREATE_FOCUSABLE_BOOLEAN`: true if the window should
@@ -1275,12 +1332,18 @@ extern SDL_DECLSPEC SDL_Window * SDLCALL SDL_CreatePopupWindow(SDL_Window *paren
* - `SDL_PROP_WINDOW_CREATE_COCOA_VIEW_POINTER`: the `(__unsafe_unretained)`
* NSView associated with the window, defaults to `[window contentView]`
*
+ * These are additional supported properties on iOS, tvOS, and visionOS:
+ *
+ * - `SDL_PROP_WINDOW_CREATE_WINDOWSCENE_POINTER`: the `(__unsafe_unretained)`
+ * UIWindowScene associated with the window, defaults to the active window
+ * scene.
+ *
* These are additional supported properties on Wayland:
*
* - `SDL_PROP_WINDOW_CREATE_WAYLAND_SURFACE_ROLE_CUSTOM_BOOLEAN` - true if
* the application wants to use the Wayland surface for a custom role and
* does not want it attached to an XDG toplevel window. See
- * [README/wayland](README/wayland) for more information on using custom
+ * [README-wayland](README-wayland) for more information on using custom
* surfaces.
* - `SDL_PROP_WINDOW_CREATE_WAYLAND_CREATE_EGL_WINDOW_BOOLEAN` - true if the
* application wants an associated `wl_egl_window` object to be created and
@@ -1288,7 +1351,7 @@ extern SDL_DECLSPEC SDL_Window * SDLCALL SDL_CreatePopupWindow(SDL_Window *paren
* property or `SDL_WINDOW_OPENGL` flag set.
* - `SDL_PROP_WINDOW_CREATE_WAYLAND_WL_SURFACE_POINTER` - the wl_surface
* associated with the window, if you want to wrap an existing window. See
- * [README/wayland](README/wayland) for more information.
+ * [README-wayland](README-wayland) for more information.
*
* These are additional supported properties on Windows:
*
@@ -1304,8 +1367,22 @@ extern SDL_DECLSPEC SDL_Window * SDLCALL SDL_CreatePopupWindow(SDL_Window *paren
*
* The window is implicitly shown if the "hidden" property is not set.
*
- * Windows with the "tooltip" and "menu" properties are popup windows and have
- * the behaviors and guidelines outlined in SDL_CreatePopupWindow().
+ * These are additional supported properties with Emscripten:
+ *
+ * - `SDL_PROP_WINDOW_CREATE_EMSCRIPTEN_CANVAS_ID_STRING`: the id given to the
+ * canvas element. This should start with a '#' sign
+ * - `SDL_PROP_WINDOW_CREATE_EMSCRIPTEN_KEYBOARD_ELEMENT_STRING`: override the
+ * binding element for keyboard inputs for this canvas. The variable can be
+ * one of:
+ * - "#window": the javascript window object (default)
+ * - "#document": the javascript document object
+ * - "#screen": the javascript window.screen object
+ * - "#canvas": the WebGL canvas element
+ * - "#none": Don't bind anything at all
+ * - any other string without a leading # sign applies to the element on the
+ * page with that ID. Windows with the "tooltip" and "menu" properties are
+ * popup windows and have the behaviors and guidelines outlined in
+ * SDL_CreatePopupWindow().
*
* If this window is being created to be used with an SDL_Renderer, you should
* not add a graphics API specific property
@@ -1360,12 +1437,15 @@ extern SDL_DECLSPEC SDL_Window * SDLCALL SDL_CreateWindowWithProperties(SDL_Prop
#define SDL_PROP_WINDOW_CREATE_Y_NUMBER "SDL.window.create.y"
#define SDL_PROP_WINDOW_CREATE_COCOA_WINDOW_POINTER "SDL.window.create.cocoa.window"
#define SDL_PROP_WINDOW_CREATE_COCOA_VIEW_POINTER "SDL.window.create.cocoa.view"
+#define SDL_PROP_WINDOW_CREATE_WINDOWSCENE_POINTER "SDL.window.create.uikit.windowscene"
#define SDL_PROP_WINDOW_CREATE_WAYLAND_SURFACE_ROLE_CUSTOM_BOOLEAN "SDL.window.create.wayland.surface_role_custom"
#define SDL_PROP_WINDOW_CREATE_WAYLAND_CREATE_EGL_WINDOW_BOOLEAN "SDL.window.create.wayland.create_egl_window"
#define SDL_PROP_WINDOW_CREATE_WAYLAND_WL_SURFACE_POINTER "SDL.window.create.wayland.wl_surface"
#define SDL_PROP_WINDOW_CREATE_WIN32_HWND_POINTER "SDL.window.create.win32.hwnd"
#define SDL_PROP_WINDOW_CREATE_WIN32_PIXEL_FORMAT_HWND_POINTER "SDL.window.create.win32.pixel_format_hwnd"
#define SDL_PROP_WINDOW_CREATE_X11_WINDOW_NUMBER "SDL.window.create.x11.window"
+#define SDL_PROP_WINDOW_CREATE_EMSCRIPTEN_CANVAS_ID_STRING "SDL.window.create.emscripten.canvas_id"
+#define SDL_PROP_WINDOW_CREATE_EMSCRIPTEN_KEYBOARD_ELEMENT_STRING "SDL.window.create.emscripten.keyboard_element"
/**
* Get the numeric ID of a window.
@@ -1477,8 +1557,8 @@ extern SDL_DECLSPEC SDL_Window * SDLCALL SDL_GetWindowParent(SDL_Window *window)
*
* On OpenVR:
*
- * - `SDL_PROP_WINDOW_OPENVR_OVERLAY_ID`: the OpenVR Overlay Handle ID for the
- * associated overlay window.
+ * - `SDL_PROP_WINDOW_OPENVR_OVERLAY_ID_NUMBER`: the OpenVR Overlay Handle ID
+ * for the associated overlay window.
*
* On Vivante:
*
@@ -1530,6 +1610,13 @@ extern SDL_DECLSPEC SDL_Window * SDLCALL SDL_GetWindowParent(SDL_Window *window)
* - `SDL_PROP_WINDOW_X11_WINDOW_NUMBER`: the X11 Window associated with the
* window
*
+ * On Emscripten:
+ *
+ * - `SDL_PROP_WINDOW_EMSCRIPTEN_CANVAS_ID_STRING`: the id the canvas element
+ * will have
+ * - `SDL_PROP_WINDOW_EMSCRIPTEN_KEYBOARD_ELEMENT_STRING`: the keyboard
+ * element that associates keyboard events to this window
+ *
* \param window the window to query.
* \returns a valid property ID on success or 0 on failure; call
* SDL_GetError() for more information.
@@ -1556,7 +1643,7 @@ extern SDL_DECLSPEC SDL_PropertiesID SDLCALL SDL_GetWindowProperties(SDL_Window
#define SDL_PROP_WINDOW_KMSDRM_GBM_DEVICE_POINTER "SDL.window.kmsdrm.gbm_dev"
#define SDL_PROP_WINDOW_COCOA_WINDOW_POINTER "SDL.window.cocoa.window"
#define SDL_PROP_WINDOW_COCOA_METAL_VIEW_TAG_NUMBER "SDL.window.cocoa.metal_view_tag"
-#define SDL_PROP_WINDOW_OPENVR_OVERLAY_ID "SDL.window.openvr.overlay_id"
+#define SDL_PROP_WINDOW_OPENVR_OVERLAY_ID_NUMBER "SDL.window.openvr.overlay_id"
#define SDL_PROP_WINDOW_VIVANTE_DISPLAY_POINTER "SDL.window.vivante.display"
#define SDL_PROP_WINDOW_VIVANTE_WINDOW_POINTER "SDL.window.vivante.window"
#define SDL_PROP_WINDOW_VIVANTE_SURFACE_POINTER "SDL.window.vivante.surface"
@@ -1575,6 +1662,8 @@ extern SDL_DECLSPEC SDL_PropertiesID SDLCALL SDL_GetWindowProperties(SDL_Window
#define SDL_PROP_WINDOW_X11_DISPLAY_POINTER "SDL.window.x11.display"
#define SDL_PROP_WINDOW_X11_SCREEN_NUMBER "SDL.window.x11.screen"
#define SDL_PROP_WINDOW_X11_WINDOW_NUMBER "SDL.window.x11.window"
+#define SDL_PROP_WINDOW_EMSCRIPTEN_CANVAS_ID_STRING "SDL.window.emscripten.canvas_id"
+#define SDL_PROP_WINDOW_EMSCRIPTEN_KEYBOARD_ELEMENT_STRING "SDL.window.emscripten.keyboard_element"
/**
* Get the window flags.
@@ -1592,6 +1681,7 @@ extern SDL_DECLSPEC SDL_PropertiesID SDLCALL SDL_GetWindowProperties(SDL_Window
* \sa SDL_MinimizeWindow
* \sa SDL_SetWindowFullscreen
* \sa SDL_SetWindowMouseGrab
+ * \sa SDL_SetWindowFillDocument
* \sa SDL_ShowWindow
*/
extern SDL_DECLSPEC SDL_WindowFlags SDLCALL SDL_GetWindowFlags(SDL_Window *window);
@@ -1632,15 +1722,16 @@ extern SDL_DECLSPEC const char * SDLCALL SDL_GetWindowTitle(SDL_Window *window);
/**
* Set the icon for a window.
*
- * If this function is passed a surface with alternate representations, the
- * surface will be interpreted as the content to be used for 100% display
- * scale, and the alternate representations will be used for high DPI
- * situations. For example, if the original surface is 32x32, then on a 2x
- * macOS display or 200% display scale on Windows, a 64x64 version of the
- * image will be used, if available. If a matching version of the image isn't
- * available, the closest larger size image will be downscaled to the
- * appropriate size and be used instead, if available. Otherwise, the closest
- * smaller image will be upscaled and be used instead.
+ * If this function is passed a surface with alternate representations added
+ * using SDL_AddSurfaceAlternateImage(), the surface will be interpreted as
+ * the content to be used for 100% display scale, and the alternate
+ * representations will be used for high DPI situations. For example, if the
+ * original surface is 32x32, then on a 2x macOS display or 200% display scale
+ * on Windows, a 64x64 version of the image will be used, if available. If a
+ * matching version of the image isn't available, the closest larger size
+ * image will be downscaled to the appropriate size and be used instead, if
+ * available. Otherwise, the closest smaller image will be upscaled and be
+ * used instead.
*
* \param window the window to change.
* \param icon an SDL_Surface structure containing the icon for the window.
@@ -1650,6 +1741,8 @@ extern SDL_DECLSPEC const char * SDLCALL SDL_GetWindowTitle(SDL_Window *window);
* \threadsafety This function should only be called on the main thread.
*
* \since This function is available since SDL 3.2.0.
+ *
+ * \sa SDL_AddSurfaceAlternateImage
*/
extern SDL_DECLSPEC bool SDLCALL SDL_SetWindowIcon(SDL_Window *window, SDL_Surface *icon);
@@ -1776,6 +1869,7 @@ extern SDL_DECLSPEC bool SDLCALL SDL_SetWindowSize(SDL_Window *window, int w, in
* \sa SDL_GetRenderOutputSize
* \sa SDL_GetWindowSizeInPixels
* \sa SDL_SetWindowSize
+ * \sa SDL_EVENT_WINDOW_RESIZED
*/
extern SDL_DECLSPEC bool SDLCALL SDL_GetWindowSize(SDL_Window *window, int *w, int *h);
@@ -1787,7 +1881,7 @@ extern SDL_DECLSPEC bool SDLCALL SDL_GetWindowSize(SDL_Window *window, int *w, i
* notches, TV overscan, etc. This function provides the area of the window
* which is safe to have interactable content. You should continue rendering
* into the rest of the window, but it should not contain visually important
- * or interactible content.
+ * or interactable content.
*
* \param window the window to query.
* \param rect a pointer filled in with the client area that is safe for
@@ -1843,7 +1937,7 @@ extern SDL_DECLSPEC bool SDLCALL SDL_GetWindowSafeArea(SDL_Window *window, SDL_R
extern SDL_DECLSPEC bool SDLCALL SDL_SetWindowAspectRatio(SDL_Window *window, float min_aspect, float max_aspect);
/**
- * Get the size of a window's client area.
+ * Get the aspect ratio of a window's client area.
*
* \param window the window to query the width and height from.
* \param min_aspect a pointer filled in with the minimum aspect ratio of the
@@ -2057,6 +2151,37 @@ extern SDL_DECLSPEC bool SDLCALL SDL_SetWindowResizable(SDL_Window *window, bool
*/
extern SDL_DECLSPEC bool SDLCALL SDL_SetWindowAlwaysOnTop(SDL_Window *window, bool on_top);
+/**
+ * Set the window to fill the current document space (Emscripten only).
+ *
+ * This will add or remove the window's `SDL_WINDOW_FILL_DOCUMENT` flag.
+ *
+ * Currently this flag only applies to the Emscripten target.
+ *
+ * When enabled, the canvas element fills the entire document. Resize events
+ * will be generated as the browser window is resized, as that will adjust the
+ * canvas size as well. The canvas will cover anything else on the page,
+ * including any controls provided by Emscripten in its generated HTML file
+ * (in fact, any elements on the page that aren't the canvas will be moved
+ * into a hidden `div` element).
+ *
+ * Often times this is desirable for a browser-based game, but it means
+ * several things that we expect of an SDL window on other platforms might not
+ * work as expected, such as minimum window sizes and aspect ratios.
+ *
+ * \param window the window of which to change the fill-document state.
+ * \param fill true to set the window to fill the document, false to disable.
+ * \returns true on success or false on failure; call SDL_GetError() for more
+ * information.
+ *
+ * \threadsafety This function should only be called on the main thread.
+ *
+ * \since This function is available since SDL 3.4.0.
+ *
+ * \sa SDL_GetWindowFlags
+ */
+extern SDL_DECLSPEC bool SDLCALL SDL_SetWindowFillDocument(SDL_Window *window, bool fill);
+
/**
* Show a window.
*
@@ -2470,7 +2595,6 @@ extern SDL_DECLSPEC bool SDLCALL SDL_SetWindowKeyboardGrab(SDL_Window *window, b
*
* \sa SDL_GetWindowMouseRect
* \sa SDL_SetWindowMouseRect
- * \sa SDL_SetWindowMouseGrab
* \sa SDL_SetWindowKeyboardGrab
*/
extern SDL_DECLSPEC bool SDLCALL SDL_SetWindowMouseGrab(SDL_Window *window, bool grabbed);
@@ -2815,6 +2939,62 @@ extern SDL_DECLSPEC bool SDLCALL SDL_SetWindowShape(SDL_Window *window, SDL_Surf
*/
extern SDL_DECLSPEC bool SDLCALL SDL_FlashWindow(SDL_Window *window, SDL_FlashOperation operation);
+/**
+ * Sets the state of the progress bar for the given window’s taskbar icon.
+ *
+ * \param window the window whose progress state is to be modified.
+ * \param state the progress state. `SDL_PROGRESS_STATE_NONE` stops displaying
+ * the progress bar.
+ * \returns true on success or false on failure; call SDL_GetError() for more
+ * information.
+ *
+ * \threadsafety This function should only be called on the main thread.
+ *
+ * \since This function is available since SDL 3.4.0.
+ */
+extern SDL_DECLSPEC bool SDLCALL SDL_SetWindowProgressState(SDL_Window *window, SDL_ProgressState state);
+
+/**
+ * Get the state of the progress bar for the given window’s taskbar icon.
+ *
+ * \param window the window to get the current progress state from.
+ * \returns the progress state, or `SDL_PROGRESS_STATE_INVALID` on failure;
+ * call SDL_GetError() for more information.
+ *
+ * \threadsafety This function should only be called on the main thread.
+ *
+ * \since This function is available since SDL 3.4.0.
+ */
+extern SDL_DECLSPEC SDL_ProgressState SDLCALL SDL_GetWindowProgressState(SDL_Window *window);
+
+/**
+ * Sets the value of the progress bar for the given window’s taskbar icon.
+ *
+ * \param window the window whose progress value is to be modified.
+ * \param value the progress value in the range of [0.0f - 1.0f]. If the value
+ * is outside the valid range, it gets clamped.
+ * \returns true on success or false on failure; call SDL_GetError() for more
+ * information.
+ *
+ * \threadsafety This function should only be called on the main thread.
+ *
+ * \since This function is available since SDL 3.4.0.
+ */
+extern SDL_DECLSPEC bool SDLCALL SDL_SetWindowProgressValue(SDL_Window *window, float value);
+
+/**
+ * Get the value of the progress bar for the given window’s taskbar icon.
+ *
+ * \param window the window to get the current progress value from.
+ * \returns the progress value in the range of [0.0f - 1.0f], or -1.0f on
+ * failure; call SDL_GetError() for more information.
+ *
+ * \threadsafety This function should only be called on the main thread.
+ *
+ * \since This function is available since SDL 3.4.0.
+ */
+extern SDL_DECLSPEC float SDLCALL SDL_GetWindowProgressValue(SDL_Window *window);
+
/**
* Destroy a window.
*
@@ -3050,8 +3230,7 @@ extern SDL_DECLSPEC void SDLCALL SDL_GL_ResetAttributes(void);
* SDL_GL_GetAttribute() to check the values after creating the OpenGL
* context, since the values obtained can differ from the requested ones.
*
- * \param attr an SDL_GLAttr enum value specifying the OpenGL attribute to
- * set.
+ * \param attr an enum value specifying the OpenGL attribute to set.
* \param value the desired value for the attribute.
* \returns true on success or false on failure; call SDL_GetError() for more
* information.
@@ -3060,6 +3239,7 @@ extern SDL_DECLSPEC void SDLCALL SDL_GL_ResetAttributes(void);
*
* \since This function is available since SDL 3.2.0.
*
+ * \sa SDL_GL_CreateContext
* \sa SDL_GL_GetAttribute
* \sa SDL_GL_ResetAttributes
*/
@@ -3086,6 +3266,12 @@ extern SDL_DECLSPEC bool SDLCALL SDL_GL_GetAttribute(SDL_GLAttr attr, int *value
/**
* Create an OpenGL context for an OpenGL window, and make it current.
*
+ * The OpenGL context will be created with the current states set through
+ * SDL_GL_SetAttribute().
+ *
+ * The SDL_Window specified must have been created with the SDL_WINDOW_OPENGL
+ * flag, or context creation will fail.
+ *
* Windows users new to OpenGL should note that, for historical reasons, GL
* functions added after OpenGL version 1.1 are not available by default.
* Those functions must be loaded at run-time, either with an OpenGL
diff --git a/thirdparty/sdl/include/build_config/SDL_build_config.h b/thirdparty/sdl/include/build_config/SDL_build_config.h
index 83031b70cc0..a1658c2dcd9 100644
--- a/thirdparty/sdl/include/build_config/SDL_build_config.h
+++ b/thirdparty/sdl/include/build_config/SDL_build_config.h
@@ -1,6 +1,6 @@
/*
Simple DirectMedia Layer
- Copyright (C) 1997-2025 Sam Lantinga <[email protected]>
+ Copyright (C) 1997-2026 Sam Lantinga <[email protected]>
This software is provided 'as-is', without any express or implied
warranty. In no event will the authors be held liable for any damages
diff --git a/thirdparty/sdl/io/SDL_iostream.c b/thirdparty/sdl/io/SDL_iostream.c
index 7c982027dee..31c74ab5034 100644
--- a/thirdparty/sdl/io/SDL_iostream.c
+++ b/thirdparty/sdl/io/SDL_iostream.c
@@ -1,6 +1,6 @@
/*
Simple DirectMedia Layer
- Copyright (C) 1997-2025 Sam Lantinga <[email protected]>
+ Copyright (C) 1997-2026 Sam Lantinga <[email protected]>
This software is provided 'as-is', without any express or implied
warranty. In no event will the authors be held liable for any damages
@@ -94,10 +94,12 @@ static HANDLE SDLCALL windows_file_open(const char *filename, const char *mode)
// "r" = reading, file must exist
// "w" = writing, truncate existing, file may not exist
+ // "wx"= writing, file must not exist
// "r+"= reading or writing, file must exist
// "a" = writing, append file may not exist
// "a+"= append + read, file may not exist
// "w+" = read, write, truncate. file may not exist
+ // "w+x"= read, write, file must not exist
must_exist = (SDL_strchr(mode, 'r') != NULL) ? OPEN_EXISTING : 0;
truncate = (SDL_strchr(mode, 'w') != NULL) ? CREATE_ALWAYS : 0;
@@ -105,6 +107,10 @@ static HANDLE SDLCALL windows_file_open(const char *filename, const char *mode)
a_mode = (SDL_strchr(mode, 'a') != NULL) ? OPEN_ALWAYS : 0;
w_right = (a_mode || SDL_strchr(mode, '+') || truncate) ? GENERIC_WRITE : 0;
+ if (truncate && (SDL_strchr(mode, 'x') != NULL)) {
+ truncate = CREATE_NEW;
+ }
+
if (!r_right && !w_right) {
return INVALID_HANDLE_VALUE; // inconsistent mode
}
@@ -219,16 +225,19 @@ static size_t SDLCALL windows_file_read(void *userdata, void *ptr, size_t size,
DWORD error = GetLastError();
switch (error) {
case ERROR_BROKEN_PIPE:
- case ERROR_HANDLE_EOF:
+ *status = SDL_IO_STATUS_EOF;
break;
case ERROR_NO_DATA:
*status = SDL_IO_STATUS_NOT_READY;
break;
default:
+ *status = SDL_IO_STATUS_ERROR;
WIN_SetError("Error reading from datastream");
break;
}
- return 0;
+ return 0; // !!! FIXME: this should return the bytes read from any readahead we finished out before this (the `iodata->left > 0` code above). In that case, fail on the next read.
+ } else if (bytes == 0) {
+ *status = SDL_IO_STATUS_EOF;
}
read_ahead = SDL_min(total_need, bytes);
SDL_memcpy(ptr, iodata->data, read_ahead);
@@ -240,16 +249,19 @@ static size_t SDLCALL windows_file_read(void *userdata, void *ptr, size_t size,
DWORD error = GetLastError();
switch (error) {
case ERROR_BROKEN_PIPE:
- case ERROR_HANDLE_EOF:
+ *status = SDL_IO_STATUS_EOF;
break;
case ERROR_NO_DATA:
*status = SDL_IO_STATUS_NOT_READY;
break;
default:
+ *status = SDL_IO_STATUS_ERROR;
WIN_SetError("Error reading from datastream");
break;
}
- return 0;
+ return 0; // !!! FIXME: this should return the bytes read from any readahead we finished out before this (the `iodata->left > 0` code above). In that case, fail on the next read.
+ } else if (bytes == 0) {
+ *status = SDL_IO_STATUS_EOF;
}
total_read += bytes;
}
@@ -263,6 +275,7 @@ static size_t SDLCALL windows_file_write(void *userdata, const void *ptr, size_t
if (iodata->left) {
if (!SetFilePointer(iodata->h, -(LONG)iodata->left, NULL, FILE_CURRENT)) {
+ *status = SDL_IO_STATUS_ERROR;
WIN_SetError("Error seeking in datastream");
return 0;
}
@@ -274,16 +287,17 @@ static size_t SDLCALL windows_file_write(void *userdata, const void *ptr, size_t
LARGE_INTEGER windowsoffset;
windowsoffset.QuadPart = 0;
if (!SetFilePointerEx(iodata->h, windowsoffset, &windowsoffset, FILE_END)) {
+ *status = SDL_IO_STATUS_ERROR;
WIN_SetError("Error seeking in datastream");
return 0;
}
}
if (!WriteFile(iodata->h, ptr, (DWORD)size, &bytes, NULL)) {
+ *status = SDL_IO_STATUS_ERROR;
WIN_SetError("Error writing to datastream");
return 0;
- }
- if (bytes == 0 && size > 0) {
+ } else if (bytes == 0 && size > 0) {
*status = SDL_IO_STATUS_NOT_READY;
}
return bytes;
@@ -365,7 +379,6 @@ typedef struct IOStreamFDData
{
int fd;
bool autoclose;
- bool regular_file;
} IOStreamFDData;
static int SDL_fdatasync(int fd)
@@ -415,15 +428,36 @@ static size_t SDLCALL fd_read(void *userdata, void *ptr, size_t size, SDL_IOStat
ssize_t bytes;
do {
bytes = read(iodata->fd, ptr, size);
- } while (bytes < 0 && errno == EINTR);
+ } while ((bytes < 0) && (errno == EINTR));
+
+ ssize_t result = bytes;
+ if ((bytes > 0) && (bytes < size)) { // was it a short read, EOF, or error?
+ // try to read the difference, so we can rule out a short read.
+ do {
+ result = read(iodata->fd, ((Uint8 *) ptr) + bytes, size - bytes);
+ } while ((result < 0) && (errno == EINTR));
+
+ if (result > 0) {
+ bytes += result;
+ result = bytes;
+ SDL_assert(bytes <= size);
+ }
+ }
- if (bytes < 0) {
+ if (result < 0) {
if (errno == EAGAIN) {
*status = SDL_IO_STATUS_NOT_READY;
} else {
+ *status = SDL_IO_STATUS_ERROR;
SDL_SetError("Error reading from datastream: %s", strerror(errno));
}
- bytes = 0;
+ if (bytes < 0) {
+ bytes = 0;
+ }
+ } else if (result == 0) {
+ *status = SDL_IO_STATUS_EOF;
+ } else if (result < size) {
+ *status = SDL_IO_STATUS_NOT_READY;
}
return (size_t)bytes;
}
@@ -434,16 +468,36 @@ static size_t SDLCALL fd_write(void *userdata, const void *ptr, size_t size, SDL
ssize_t bytes;
do {
bytes = write(iodata->fd, ptr, size);
- } while (bytes < 0 && errno == EINTR);
+ } while ((bytes < 0) && (errno == EINTR));
+
+ ssize_t result = bytes;
+ if ((bytes > 0) && (bytes < size)) { // was it a short write, or error?
+ // try to write the difference, so we can rule out a short read.
+ do {
+ result = write(iodata->fd, ((Uint8 *) ptr) + bytes, size - bytes);
+ } while ((result < 0) && (errno == EINTR));
+
+ if (result > 0) {
+ bytes += result;
+ result = bytes;
+ SDL_assert(bytes <= size);
+ }
+ }
- if (bytes < 0) {
+ if (result < 0) {
if (errno == EAGAIN) {
*status = SDL_IO_STATUS_NOT_READY;
} else {
+ *status = SDL_IO_STATUS_ERROR;
SDL_SetError("Error writing to datastream: %s", strerror(errno));
}
- bytes = 0;
+ if (bytes < 0) {
+ bytes = 0;
+ }
+ } else if (result < size) {
+ *status = SDL_IO_STATUS_NOT_READY;
}
+
return (size_t)bytes;
}
@@ -497,9 +551,6 @@ SDL_IOStream *SDL_IOFromFD(int fd, bool autoclose)
iodata->fd = fd;
iodata->autoclose = autoclose;
- struct stat st;
- iodata->regular_file = ((fstat(fd, &st) == 0) && S_ISREG(st.st_mode));
-
SDL_IOStream *iostr = SDL_OpenIO(&iface, iodata);
if (!iostr) {
iface.close(iodata);
@@ -522,7 +573,6 @@ typedef struct IOStreamStdioData
{
FILE *fp;
bool autoclose;
- bool regular_file;
} IOStreamStdioData;
#ifdef HAVE_FOPEN64
@@ -607,12 +657,18 @@ static size_t SDLCALL stdio_read(void *userdata, void *ptr, size_t size, SDL_IOS
{
IOStreamStdioData *iodata = (IOStreamStdioData *) userdata;
const size_t bytes = fread(ptr, 1, size, iodata->fp);
- if (bytes == 0 && ferror(iodata->fp)) {
- if (errno == EAGAIN) {
- *status = SDL_IO_STATUS_NOT_READY;
- clearerr(iodata->fp);
+ if (bytes < size) {
+ if (ferror(iodata->fp)) {
+ if (errno == EAGAIN) {
+ *status = SDL_IO_STATUS_NOT_READY;
+ clearerr(iodata->fp);
+ } else {
+ *status = SDL_IO_STATUS_ERROR;
+ SDL_SetError("Error reading from datastream: %s", strerror(errno));
+ }
} else {
- SDL_SetError("Error reading from datastream: %s", strerror(errno));
+ SDL_assert(feof(iodata->fp));
+ *status = SDL_IO_STATUS_EOF;
}
}
return bytes;
@@ -627,6 +683,7 @@ static size_t SDLCALL stdio_write(void *userdata, const void *ptr, size_t size,
*status = SDL_IO_STATUS_NOT_READY;
clearerr(iodata->fp);
} else {
+ *status = SDL_IO_STATUS_ERROR;
SDL_SetError("Error writing to datastream: %s", strerror(errno));
}
}
@@ -692,9 +749,6 @@ SDL_IOStream *SDL_IOFromFP(FILE *fp, bool autoclose)
iodata->fp = fp;
iodata->autoclose = autoclose;
- struct stat st;
- iodata->regular_file = ((fstat(fileno(fp), &st) == 0) && S_ISREG(st.st_mode));
-
SDL_IOStream *iostr = SDL_OpenIO(&iface, iodata);
if (!iostr) {
iface.close(iodata);
@@ -717,6 +771,7 @@ typedef struct IOStreamMemData
Uint8 *base;
Uint8 *here;
Uint8 *stop;
+ SDL_PropertiesID props;
} IOStreamMemData;
static Sint64 SDLCALL mem_size(void *userdata)
@@ -769,46 +824,61 @@ static size_t mem_io(void *userdata, void *dst, const void *src, size_t size)
static size_t SDLCALL mem_read(void *userdata, void *ptr, size_t size, SDL_IOStatus *status)
{
IOStreamMemData *iodata = (IOStreamMemData *) userdata;
- return mem_io(userdata, ptr, iodata->here, size);
+ const size_t retval = mem_io(userdata, ptr, iodata->here, size);
+ if ((retval < size) && (iodata->stop == iodata->here)) {
+ *status = SDL_IO_STATUS_EOF;
+ }
+ return retval;
}
static size_t SDLCALL mem_write(void *userdata, const void *ptr, size_t size, SDL_IOStatus *status)
{
IOStreamMemData *iodata = (IOStreamMemData *) userdata;
- return mem_io(userdata, iodata->here, ptr, size);
+ const size_t retval = mem_io(userdata, iodata->here, ptr, size);
+ if ((retval < size) && (iodata->stop == iodata->here)) {
+ SDL_SetError("Memory buffer is full");
+ *status = SDL_IO_STATUS_ERROR;
+ }
+ return retval;
}
static bool SDLCALL mem_close(void *userdata)
{
+ IOStreamMemData *iodata = (IOStreamMemData *) userdata;
+ SDL_free_func free_func = SDL_GetPointerProperty(iodata->props, SDL_PROP_IOSTREAM_MEMORY_FREE_FUNC_POINTER, NULL);
+ if (free_func) {
+ free_func(iodata->base);
+ }
SDL_free(userdata);
return true;
}
// Functions to create SDL_IOStream structures from various data sources
-#if defined(HAVE_STDIO_H) && !defined(SDL_PLATFORM_WINDOWS)
-static bool IsRegularFileOrPipe(FILE *f)
+// private platforms might define SKIP_STDIO_DIR_TEST in their build configs, too.
+#if defined(SDL_PLATFORM_WINDOWS) || defined(SDL_PLATFORM_EMSCRIPTEN)
+#define SKIP_STDIO_DIR_TEST 1
+#endif
+
+#if defined(HAVE_STDIO_H) && !defined(SKIP_STDIO_DIR_TEST)
+static bool IsStdioFileADirectory(FILE *f)
{
-#ifndef SDL_PLATFORM_EMSCRIPTEN
struct stat st;
- if (fstat(fileno(f), &st) < 0 || !(S_ISREG(st.st_mode) || S_ISFIFO(st.st_mode))) {
- return false;
- }
-#endif // !SDL_PLATFORM_EMSCRIPTEN
-
- return true;
+ return ((fstat(fileno(f), &st) == 0) && (S_ISDIR(st.st_mode)));
}
+#else
+#define IsStdioFileADirectory(f) false
#endif
SDL_IOStream *SDL_IOFromFile(const char *file, const char *mode)
{
SDL_IOStream *iostr = NULL;
- if (!file || !*file) {
+ CHECK_PARAM(!file || !*file) {
SDL_InvalidParamError("file");
return NULL;
}
- if (!mode || !*mode) {
+ CHECK_PARAM(!mode || !*mode) {
SDL_InvalidParamError("mode");
return NULL;
}
@@ -819,9 +889,9 @@ SDL_IOStream *SDL_IOFromFile(const char *file, const char *mode)
if (*file == '/') {
FILE *fp = fopen(file, mode);
if (fp) {
- if (!IsRegularFileOrPipe(fp)) {
+ if (IsStdioFileADirectory(fp)) {
fclose(fp);
- SDL_SetError("%s is not a regular file or pipe", file);
+ SDL_SetError("%s is a directory", file);
return NULL;
}
return SDL_IOFromFP(fp, true);
@@ -850,9 +920,9 @@ SDL_IOStream *SDL_IOFromFile(const char *file, const char *mode)
FILE *fp = fopen(path, mode);
SDL_free(path);
if (fp) {
- if (!IsRegularFileOrPipe(fp)) {
+ if (IsStdioFileADirectory(fp)) {
fclose(fp);
- SDL_SetError("%s is not a regular file or pipe", path);
+ SDL_SetError("%s is a directory", path);
return NULL;
}
return SDL_IOFromFP(fp, true);
@@ -886,6 +956,43 @@ SDL_IOStream *SDL_IOFromFile(const char *file, const char *mode)
}
}
+#elif defined(SDL_PLATFORM_IOS)
+
+ // Try to open the file on the filesystem first
+ FILE *fp = NULL;
+ if (*file == '/') {
+ fp = fopen(file, mode);
+ } else {
+ // We can't write to the current directory, so use a writable path
+ char *base = SDL_GetPrefPath("", "");
+ if (!base) {
+ return NULL;
+ }
+
+ char *path = NULL;
+ SDL_asprintf(&path, "%s%s", base, file);
+ SDL_free(base);
+ if (!path) {
+ return NULL;
+ }
+
+ fp = fopen(path, mode);
+ SDL_free(path);
+
+ if (!fp) {
+ fp = fopen(file, mode);
+ }
+ }
+
+ if (!fp) {
+ SDL_SetError("Couldn't open %s: %s", file, strerror(errno));
+ } else if (IsStdioFileADirectory(fp)) {
+ fclose(fp);
+ SDL_SetError("%s is a directory", file);
+ } else {
+ iostr = SDL_IOFromFP(fp, true);
+ }
+
#elif defined(SDL_PLATFORM_WINDOWS)
HANDLE handle = windows_file_open(file, mode);
if (handle != INVALID_HANDLE_VALUE) {
@@ -902,10 +1009,9 @@ SDL_IOStream *SDL_IOFromFile(const char *file, const char *mode)
if (!fp) {
SDL_SetError("Couldn't open %s: %s", file, strerror(errno));
- } else if (!IsRegularFileOrPipe(fp)) {
+ } else if (IsStdioFileADirectory(fp)) {
fclose(fp);
- fp = NULL;
- SDL_SetError("%s is not a regular file or pipe", file);
+ SDL_SetError("%s is a directory", file);
} else {
iostr = SDL_IOFromFP(fp, true);
}
@@ -913,19 +1019,16 @@ SDL_IOStream *SDL_IOFromFile(const char *file, const char *mode)
#else
SDL_SetError("SDL not compiled with stdio support");
-#endif // !HAVE_STDIO_H
+#endif // SDL_PLATFORM_ANDROID
return iostr;
}
SDL_IOStream *SDL_IOFromMem(void *mem, size_t size)
{
- if (!mem) {
+ CHECK_PARAM(size && !mem) {
SDL_InvalidParamError("mem");
return NULL;
- } else if (!size) {
- SDL_InvalidParamError("size");
- return NULL;
}
IOStreamMemData *iodata = (IOStreamMemData *) SDL_calloc(1, sizeof (*iodata));
@@ -951,6 +1054,7 @@ SDL_IOStream *SDL_IOFromMem(void *mem, size_t size)
} else {
const SDL_PropertiesID props = SDL_GetIOProperties(iostr);
if (props) {
+ iodata->props = props;
SDL_SetPointerProperty(props, SDL_PROP_IOSTREAM_MEMORY_POINTER, mem);
SDL_SetNumberProperty(props, SDL_PROP_IOSTREAM_MEMORY_SIZE_NUMBER, size);
}
@@ -960,12 +1064,9 @@ SDL_IOStream *SDL_IOFromMem(void *mem, size_t size)
SDL_IOStream *SDL_IOFromConstMem(const void *mem, size_t size)
{
- if (!mem) {
+ CHECK_PARAM(size && !mem) {
SDL_InvalidParamError("mem");
return NULL;
- } else if (!size) {
- SDL_InvalidParamError("size");
- return NULL;
}
IOStreamMemData *iodata = (IOStreamMemData *) SDL_calloc(1, sizeof (*iodata));
@@ -991,6 +1092,7 @@ SDL_IOStream *SDL_IOFromConstMem(const void *mem, size_t size)
} else {
const SDL_PropertiesID props = SDL_GetIOProperties(iostr);
if (props) {
+ iodata->props = props;
SDL_SetPointerProperty(props, SDL_PROP_IOSTREAM_MEMORY_POINTER, (void *)mem);
SDL_SetNumberProperty(props, SDL_PROP_IOSTREAM_MEMORY_SIZE_NUMBER, size);
}
@@ -1020,7 +1122,11 @@ static Sint64 SDLCALL dynamic_mem_seek(void *userdata, Sint64 offset, SDL_IOWhen
static size_t SDLCALL dynamic_mem_read(void *userdata, void *ptr, size_t size, SDL_IOStatus *status)
{
IOStreamDynamicMemData *iodata = (IOStreamDynamicMemData *) userdata;
- return mem_io(&iodata->data, ptr, iodata->data.here, size);
+ const size_t retval = mem_io(&iodata->data, ptr, iodata->data.here, size);
+ if ((retval < size) && (iodata->data.stop == iodata->data.here)) {
+ *status = SDL_IO_STATUS_EOF;
+ }
+ return retval;
}
static bool dynamic_mem_realloc(IOStreamDynamicMemData *iodata, size_t size)
@@ -1053,21 +1159,22 @@ static size_t SDLCALL dynamic_mem_write(void *userdata, const void *ptr, size_t
if (size > (size_t)(iodata->data.stop - iodata->data.here)) {
if (size > (size_t)(iodata->end - iodata->data.here)) {
if (!dynamic_mem_realloc(iodata, size)) {
+ *status = SDL_IO_STATUS_ERROR;
return 0;
}
}
iodata->data.stop = iodata->data.here + size;
}
- return mem_io(&iodata->data, iodata->data.here, ptr, size);
+ const size_t retval = mem_io(&iodata->data, iodata->data.here, ptr, size);
+ SDL_assert(retval == size); // we should have allocated enough to cover this!
+ return retval;
}
static bool SDLCALL dynamic_mem_close(void *userdata)
{
const IOStreamDynamicMemData *iodata = (IOStreamDynamicMemData *) userdata;
void *mem = SDL_GetPointerProperty(SDL_GetIOProperties(iodata->stream), SDL_PROP_IOSTREAM_DYNAMIC_MEMORY_POINTER, NULL);
- if (mem) {
- SDL_free(mem);
- }
+ SDL_free(mem);
SDL_free(userdata);
return true;
}
@@ -1098,7 +1205,7 @@ SDL_IOStream *SDL_IOFromDynamicMem(void)
SDL_IOStatus SDL_GetIOStatus(SDL_IOStream *context)
{
- if (!context) {
+ CHECK_PARAM(!context) {
SDL_InvalidParamError("context");
return SDL_IO_STATUS_ERROR;
}
@@ -1107,11 +1214,11 @@ SDL_IOStatus SDL_GetIOStatus(SDL_IOStream *context)
SDL_IOStream *SDL_OpenIO(const SDL_IOStreamInterface *iface, void *userdata)
{
- if (!iface) {
+ CHECK_PARAM(!iface) {
SDL_InvalidParamError("iface");
return NULL;
}
- if (iface->version < sizeof(*iface)) {
+ CHECK_PARAM(iface->version < sizeof(*iface)) {
// Update this to handle older versions of this interface
SDL_SetError("Invalid interface, should be initialized with SDL_INIT_INTERFACE()");
return NULL;
@@ -1147,7 +1254,7 @@ void *SDL_LoadFile_IO(SDL_IOStream *src, size_t *datasize, bool closeio)
char *data = NULL, *newdata;
bool loading_chunks = false;
- if (!src) {
+ CHECK_PARAM(!src) {
SDL_InvalidParamError("src");
goto done;
}
@@ -1228,12 +1335,12 @@ bool SDL_SaveFile_IO(SDL_IOStream *src, const void *data, size_t datasize, bool
size_t size_total = 0;
bool success = true;
- if (!src) {
+ CHECK_PARAM(!src) {
SDL_InvalidParamError("src");
goto done;
}
- if (!data && datasize > 0) {
+ CHECK_PARAM(!data && datasize > 0) {
SDL_InvalidParamError("data");
goto done;
}
@@ -1276,7 +1383,7 @@ bool SDL_SaveFile(const char *file, const void *data, size_t datasize)
SDL_PropertiesID SDL_GetIOProperties(SDL_IOStream *context)
{
- if (!context) {
+ CHECK_PARAM(!context) {
SDL_InvalidParamError("context");
return 0;
}
@@ -1289,9 +1396,11 @@ SDL_PropertiesID SDL_GetIOProperties(SDL_IOStream *context)
Sint64 SDL_GetIOSize(SDL_IOStream *context)
{
- if (!context) {
- return SDL_InvalidParamError("context");
+ CHECK_PARAM(!context) {
+ SDL_InvalidParamError("context");
+ return -1;
}
+
if (!context->iface.size) {
Sint64 pos, size;
@@ -1309,10 +1418,12 @@ Sint64 SDL_GetIOSize(SDL_IOStream *context)
Sint64 SDL_SeekIO(SDL_IOStream *context, Sint64 offset, SDL_IOWhence whence)
{
- if (!context) {
+ CHECK_PARAM(!context) {
SDL_InvalidParamError("context");
return -1;
- } else if (!context->iface.seek) {
+ }
+
+ if (!context->iface.seek) {
SDL_Unsupported();
return -1;
}
@@ -1326,60 +1437,48 @@ Sint64 SDL_TellIO(SDL_IOStream *context)
size_t SDL_ReadIO(SDL_IOStream *context, void *ptr, size_t size)
{
- size_t bytes;
-
- if (!context) {
+ CHECK_PARAM(!context) {
SDL_InvalidParamError("context");
return 0;
- } else if (!context->iface.read) {
+ }
+
+ if (!context->iface.read) {
context->status = SDL_IO_STATUS_WRITEONLY;
SDL_Unsupported();
return 0;
}
- context->status = SDL_IO_STATUS_READY;
- SDL_ClearError();
-
if (size == 0) {
- return 0;
+ return 0; // context->status doesn't change for this.
}
- bytes = context->iface.read(context->userdata, ptr, size, &context->status);
- if (bytes == 0 && context->status == SDL_IO_STATUS_READY) {
- if (*SDL_GetError()) {
- context->status = SDL_IO_STATUS_ERROR;
- } else {
- context->status = SDL_IO_STATUS_EOF;
- }
- }
- return bytes;
+ context->status = SDL_IO_STATUS_READY;
+ SDL_ClearError();
+
+ return context->iface.read(context->userdata, ptr, size, &context->status);
}
size_t SDL_WriteIO(SDL_IOStream *context, const void *ptr, size_t size)
{
- size_t bytes;
-
- if (!context) {
+ CHECK_PARAM(!context) {
SDL_InvalidParamError("context");
return 0;
- } else if (!context->iface.write) {
+ }
+
+ if (!context->iface.write) {
context->status = SDL_IO_STATUS_READONLY;
SDL_Unsupported();
return 0;
}
- context->status = SDL_IO_STATUS_READY;
- SDL_ClearError();
-
if (size == 0) {
- return 0;
+ return 0; // context->status doesn't change for this.
}
- bytes = context->iface.write(context->userdata, ptr, size, &context->status);
- if ((bytes == 0) && (context->status == SDL_IO_STATUS_READY)) {
- context->status = SDL_IO_STATUS_ERROR;
- }
- return bytes;
+ context->status = SDL_IO_STATUS_READY;
+ SDL_ClearError();
+
+ return context->iface.write(context->userdata, ptr, size, &context->status);
}
size_t SDL_IOprintf(SDL_IOStream *context, SDL_PRINTF_FORMAT_STRING const char *fmt, ...)
@@ -1421,7 +1520,7 @@ bool SDL_FlushIO(SDL_IOStream *context)
{
bool result = true;
- if (!context) {
+ CHECK_PARAM(!context) {
return SDL_InvalidParamError("context");
}
diff --git a/thirdparty/sdl/io/SDL_iostream_c.h b/thirdparty/sdl/io/SDL_iostream_c.h
index c04fe203f73..fadb98bcb6d 100644
--- a/thirdparty/sdl/io/SDL_iostream_c.h
+++ b/thirdparty/sdl/io/SDL_iostream_c.h
@@ -1,6 +1,6 @@
/*
Simple DirectMedia Layer
- Copyright (C) 1997-2025 Sam Lantinga <[email protected]>
+ Copyright (C) 1997-2026 Sam Lantinga <[email protected]>
This software is provided 'as-is', without any express or implied
warranty. In no event will the authors be held liable for any damages
diff --git a/thirdparty/sdl/joystick/SDL_gamepad.c b/thirdparty/sdl/joystick/SDL_gamepad.c
index 791ea213c2d..dd5b4166a9a 100644
--- a/thirdparty/sdl/joystick/SDL_gamepad.c
+++ b/thirdparty/sdl/joystick/SDL_gamepad.c
@@ -1,6 +1,6 @@
/*
Simple DirectMedia Layer
- Copyright (C) 1997-2025 Sam Lantinga <[email protected]>
+ Copyright (C) 1997-2026 Sam Lantinga <[email protected]>
This software is provided 'as-is', without any express or implied
warranty. In no event will the authors be held liable for any damages
@@ -29,8 +29,11 @@
#include "SDL_gamepad_db.h"
#include "controller_type.h"
#include "usb_ids.h"
+#include "hidapi/SDL_hidapi_flydigi.h"
#include "hidapi/SDL_hidapi_nintendo.h"
+#include "hidapi/SDL_hidapi_sinput.h"
#include "../events/SDL_events_c.h"
+#include "../SDL_hints_c.h"
#ifdef SDL_PLATFORM_WIN32
#include "../core/windows/SDL_windows.h"
@@ -55,14 +58,32 @@
#define SDL_GAMEPAD_SDKLE_FIELD "sdk<=:"
#define SDL_GAMEPAD_SDKLE_FIELD_SIZE SDL_strlen(SDL_GAMEPAD_SDKLE_FIELD)
+// Helper function to add button mapping
+#define SDL_ADD_BUTTON_MAPPING(sdl_name, button_id, maxlen) \
+ do { \
+ char temp[32]; \
+ (void)SDL_snprintf(temp, sizeof(temp), "%s:b%d,", sdl_name, button_id); \
+ SDL_strlcat(mapping_string, temp, maxlen); \
+ } while (0)
+
+// Helper function to add axis mapping
+#define SDL_ADD_AXIS_MAPPING(sdl_name, axis_id, maxlen) \
+ do { \
+ char temp[32]; \
+ (void)SDL_snprintf(temp, sizeof(temp), "%s:a%d,", sdl_name, axis_id); \
+ SDL_strlcat(mapping_string, temp, maxlen); \
+ } while (0)
+
static bool SDL_gamepads_initialized;
static SDL_Gamepad *SDL_gamepads SDL_GUARDED_BY(SDL_joystick_lock) = NULL;
+static SDL_HashTable *SDL_gamepad_names SDL_GUARDED_BY(SDL_joystick_lock) = NULL;
// The face button style of a gamepad
typedef enum
{
SDL_GAMEPAD_FACE_STYLE_UNKNOWN,
SDL_GAMEPAD_FACE_STYLE_ABXY,
+ SDL_GAMEPAD_FACE_STYLE_AXBY,
SDL_GAMEPAD_FACE_STYLE_BAYX,
SDL_GAMEPAD_FACE_STYLE_SONY,
} SDL_GamepadFaceStyle;
@@ -129,12 +150,12 @@ struct SDL_Gamepad
#undef _guarded
-#define CHECK_GAMEPAD_MAGIC(gamepad, result) \
- if (!SDL_ObjectValid(gamepad, SDL_OBJECT_TYPE_GAMEPAD) || \
- !SDL_IsJoystickValid(gamepad->joystick)) { \
- SDL_InvalidParamError("gamepad"); \
- SDL_UnlockJoysticks(); \
- return result; \
+#define CHECK_GAMEPAD_MAGIC(gamepad, result) \
+ CHECK_PARAM(!SDL_ObjectValid(gamepad, SDL_OBJECT_TYPE_GAMEPAD) || \
+ !SDL_IsJoystickValid(gamepad->joystick)) { \
+ SDL_InvalidParamError("gamepad"); \
+ SDL_UnlockJoysticks(); \
+ return result; \
}
static SDL_vidpid_list SDL_allowed_gamepads = {
@@ -185,7 +206,7 @@ static const struct SDL_GamepadBlacklistWords SDL_gamepad_blacklist_words[] = {
{"Synaptics ", GAMEPAD_BLACKLIST_ANYWHERE}, // "Synaptics TM2768-001", "SynPS/2 Synaptics TouchPad"
{"Trackpad", GAMEPAD_BLACKLIST_ANYWHERE},
{"Clickpad", GAMEPAD_BLACKLIST_ANYWHERE},
- // "PG-90215 Keyboard", "Usb Keyboard Usb Keyboard Consumer Control", "Framework Laptop 16 Keyboard Module - ISO System Control"
+ // "Usb Keyboard Usb Keyboard Consumer Control", "Framework Laptop 16 Keyboard Module - ISO System Control"
{" Keyboard", GAMEPAD_BLACKLIST_ANYWHERE},
{" Laptop ", GAMEPAD_BLACKLIST_ANYWHERE}, // "Framework Laptop 16 Numpad Module System Control"
{"Mouse ", GAMEPAD_BLACKLIST_BEGIN}, // "Mouse passthrough"
@@ -353,6 +374,47 @@ static void RecenterGamepad(SDL_Gamepad *gamepad)
}
}
+static const char *SDL_UpdateGamepadNameForID(SDL_JoystickID instance_id)
+{
+ const char *current_name = NULL;
+
+ SDL_AssertJoysticksLocked();
+
+ GamepadMapping_t *mapping = SDL_PrivateGetGamepadMapping(instance_id, true);
+ if (mapping) {
+ if (SDL_strcmp(mapping->name, "*") == 0) {
+ current_name = SDL_GetJoystickNameForID(instance_id);
+ } else {
+ current_name = mapping->name;
+ }
+ }
+
+ if (!SDL_gamepad_names) {
+ return SDL_GetPersistentString(current_name);
+ }
+
+ char *name = NULL;
+ bool found = SDL_FindInHashTable(SDL_gamepad_names, (const void *)(uintptr_t)instance_id, (const void **)&name);
+ if (!current_name) {
+ if (!found) {
+ SDL_SetError("Gamepad %" SDL_PRIu32 " not found", instance_id);
+ return NULL;
+ }
+ if (!name) {
+ // SDL_strdup() failed during insert
+ SDL_OutOfMemory();
+ return NULL;
+ }
+ return name;
+ }
+
+ if (!name || SDL_strcmp(name, current_name) != 0) {
+ name = SDL_strdup(current_name);
+ SDL_InsertIntoHashTable(SDL_gamepad_names, (const void *)(uintptr_t)instance_id, name, true);
+ }
+ return name;
+}
+
void SDL_PrivateGamepadAdded(SDL_JoystickID instance_id)
{
SDL_Event event;
@@ -361,6 +423,8 @@ void SDL_PrivateGamepadAdded(SDL_JoystickID instance_id)
return;
}
+ SDL_UpdateGamepadNameForID(instance_id);
+
event.type = SDL_EVENT_GAMEPAD_ADDED;
event.common.timestamp = 0;
event.gdevice.which = instance_id;
@@ -610,10 +674,14 @@ static void PopMappingChangeTracking(void)
GamepadMapping_t *old_mapping = gamepad ? gamepad->mapping : tracker->joystick_mappings[i];
if (new_mapping && !old_mapping) {
- SDL_InsertIntoHashTable(s_gamepadInstanceIDs, (void *)(uintptr_t)joystick, (const void *)true, true);
+ if (s_gamepadInstanceIDs) {
+ SDL_InsertIntoHashTable(s_gamepadInstanceIDs, (void *)(uintptr_t)joystick, (const void *)true, true);
+ }
SDL_PrivateGamepadAdded(joystick);
} else if (old_mapping && !new_mapping) {
- SDL_InsertIntoHashTable(s_gamepadInstanceIDs, (void *)(uintptr_t)joystick, (const void *)false, true);
+ if (s_gamepadInstanceIDs) {
+ SDL_InsertIntoHashTable(s_gamepadInstanceIDs, (void *)(uintptr_t)joystick, (const void *)false, true);
+ }
SDL_PrivateGamepadRemoved(joystick);
} else if (old_mapping != new_mapping || HasMappingChangeTracking(tracker, new_mapping)) {
if (gamepad) {
@@ -644,94 +712,389 @@ static GamepadMapping_t *SDL_CreateMappingForAndroidGamepad(SDL_GUID guid)
char mapping_string[1024];
int button_mask;
int axis_mask;
+ Uint16 vendor, product;
+
+ SDL_strlcpy(mapping_string, "none,", sizeof(mapping_string));
- button_mask = SDL_Swap16LE(*(Uint16 *)(&guid.data[sizeof(guid.data) - 4]));
- axis_mask = SDL_Swap16LE(*(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_GetJoystickGUIDInfo(guid, &vendor, &product, NULL, NULL);
+ if (vendor == USB_VENDOR_NINTENDO) {
+ if (product == USB_PRODUCT_NINTENDO_SWITCH_JOYCON_LEFT || product == USB_PRODUCT_NINTENDO_SWITCH_JOYCON_RIGHT) {
+ // FIXME: Should we have a separate hint for non-HIDAPI JoyCon handling?
+ // Android doesn't report JoyCon SL/SR presses for some reason, so no horizontal triggers/vertical paddles
+ if (SDL_GetHintBoolean(SDL_HINT_JOYSTICK_HIDAPI_VERTICAL_JOY_CONS, false)) {
+ // Vertical mode
+ if (product == USB_PRODUCT_NINTENDO_SWITCH_JOYCON_LEFT) {
+ SDL_strlcat(mapping_string, "Nintendo Switch Joy-Con (L),back:b4,dpdown:b12,dpleft:b13,dpright:b14,dpup:b11,leftshoulder:b9,leftstick:b7,lefttrigger:b15,leftx:a0,lefty:a1,misc1:b18,", sizeof(mapping_string));
+ } else {
+ SDL_strlcat(mapping_string, "Nintendo Switch Joy-Con (R),a:b0,b:b1,guide:b5,rightshoulder:b10,rightstick:b8,righttrigger:b16,rightx:a0,righty:a1,start:b6,x:b3,y:b2,", sizeof(mapping_string));
+ }
+ } else {
+ // Mini gamepad mode
+ if (product == USB_PRODUCT_NINTENDO_SWITCH_JOYCON_LEFT) {
+ SDL_strlcat(mapping_string, "Nintendo Switch Joy-Con (L),a:b13,b:b12,guide:b18,leftstick:b7,leftx:a1,lefty:a0~,start:b4,x:b11,y:b14,paddle2:b9,paddle4:b15,", sizeof(mapping_string));
+ } else {
+ SDL_strlcat(mapping_string, "Nintendo Switch Joy-Con (R),a:b1,b:b2,guide:b5,leftstick:b8,leftx:a1~,lefty:a0,start:b6,x:b0,y:b3,paddle1:b10,paddle3:b16,", sizeof(mapping_string));
+ }
+ }
+ }
+ } else {
+ button_mask = SDL_Swap16LE(*(Uint16 *)(&guid.data[sizeof(guid.data) - 4]));
+ axis_mask = SDL_Swap16LE(*(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));
+ SDL_strlcat(mapping_string, "*,", sizeof(mapping_string));
- if (button_mask & (1 << SDL_GAMEPAD_BUTTON_SOUTH)) {
- SDL_strlcat(mapping_string, "a:b0,", sizeof(mapping_string));
- }
- if (button_mask & (1 << SDL_GAMEPAD_BUTTON_EAST)) {
- 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_WEST)) {
- SDL_strlcat(mapping_string, "x:b2,", sizeof(mapping_string));
- }
- if (button_mask & (1 << SDL_GAMEPAD_BUTTON_NORTH)) {
- 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_SOUTH)) {
+ SDL_strlcat(mapping_string, "a:b0,", sizeof(mapping_string));
+ }
+ if (button_mask & (1 << SDL_GAMEPAD_BUTTON_EAST)) {
+ 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_WEST)) {
+ SDL_strlcat(mapping_string, "x:b2,", sizeof(mapping_string));
+ }
+ if (button_mask & (1 << SDL_GAMEPAD_BUTTON_NORTH)) {
+ 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 // SDL_PLATFORM_ANDROID
+
+/*
+* Helper function to apply SInput decoded styles to the mapping string
+*/
+static inline void SDL_SInputStylesMapExtraction(SDL_SInputStyles_t* styles, char* mapping_string, size_t mapping_string_len)
+{
+ int current_button = 0;
+ int current_axis = 0;
+ int misc_buttons = 0;
+ int misc_button, misc_end;
+ bool digital_triggers = false;
+ bool dualstage_triggers = false;
+ int bumpers = 0;
+ bool left_stick = false;
+ bool right_stick = false;
+ int paddle_pairs = 0;
+ char misc_label[32];
+
+ // Determine how many misc buttons are used
+ switch (styles->misc_style) {
+ case SINPUT_MISCSTYLE_1:
+ misc_buttons = 1;
+ break;
+
+ case SINPUT_MISCSTYLE_2:
+ misc_buttons = 2;
+ break;
+
+ case SINPUT_MISCSTYLE_3:
+ misc_buttons = 3;
+ break;
+
+ case SINPUT_MISCSTYLE_4:
+ misc_buttons = 4;
+ break;
+
+ default:
+ break;
}
- if (button_mask & (1 << SDL_GAMEPAD_BUTTON_START)) {
- SDL_strlcat(mapping_string, "start:b6,", sizeof(mapping_string));
+ // The share button is reserved as misc1, additional buttons start at misc2
+ misc_button = 2;
+ misc_end = misc_button + misc_buttons;
+
+ // Analog joysticks (always come first in axis mapping)
+ switch (styles->analog_style) {
+ case SINPUT_ANALOGSTYLE_LEFTONLY:
+ SDL_ADD_AXIS_MAPPING("leftx", current_axis++, mapping_string_len);
+ SDL_ADD_AXIS_MAPPING("lefty", current_axis++, mapping_string_len);
+ left_stick = true;
+ break;
+
+ case SINPUT_ANALOGSTYLE_LEFTRIGHT:
+ SDL_ADD_AXIS_MAPPING("leftx", current_axis++, mapping_string_len);
+ SDL_ADD_AXIS_MAPPING("lefty", current_axis++, mapping_string_len);
+ SDL_ADD_AXIS_MAPPING("rightx", current_axis++, mapping_string_len);
+ SDL_ADD_AXIS_MAPPING("righty", current_axis++, mapping_string_len);
+ left_stick = true;
+ right_stick = true;
+ break;
+
+ case SINPUT_ANALOGSTYLE_RIGHTONLY:
+ SDL_ADD_AXIS_MAPPING("rightx", current_axis++, mapping_string_len);
+ SDL_ADD_AXIS_MAPPING("righty", current_axis++, mapping_string_len);
+ right_stick = true;
+ break;
+
+ default:
+ break;
}
- if (button_mask & (1 << SDL_GAMEPAD_BUTTON_LEFT_STICK)) {
- SDL_strlcat(mapping_string, "leftstick:b7,", sizeof(mapping_string));
+
+ // Bumpers
+ switch (styles->bumper_style) {
+ case SINPUT_BUMPERSTYLE_ONE:
+ bumpers = 1;
+ break;
+
+ case SINPUT_BUMPERSTYLE_TWO:
+ bumpers = 2;
+ break;
+
+ default:
+ break;
}
- if (button_mask & (1 << SDL_GAMEPAD_BUTTON_RIGHT_STICK)) {
- SDL_strlcat(mapping_string, "rightstick:b8,", sizeof(mapping_string));
+
+ // Analog triggers
+ switch (styles->trigger_style) {
+ // Analog triggers
+ case SINPUT_TRIGGERSTYLE_ANALOG:
+ SDL_ADD_AXIS_MAPPING("lefttrigger", current_axis++, mapping_string_len);
+ SDL_ADD_AXIS_MAPPING("righttrigger", current_axis++, mapping_string_len);
+ break;
+
+ // Digital triggers
+ case SINPUT_TRIGGERSTYLE_DIGITAL:
+ digital_triggers = true;
+ break;
+
+ // Analog triggers with digital press
+ case SINPUT_TRIGGERSTYLE_DUALSTAGE:
+ SDL_ADD_AXIS_MAPPING("lefttrigger", current_axis++, mapping_string_len);
+ SDL_ADD_AXIS_MAPPING("righttrigger", current_axis++, mapping_string_len);
+ dualstage_triggers = true;
+ break;
+
+ default:
+ break;
}
- if (button_mask & (1 << SDL_GAMEPAD_BUTTON_LEFT_SHOULDER)) {
- SDL_strlcat(mapping_string, "leftshoulder:b9,", sizeof(mapping_string));
+
+ switch (styles->paddle_style) {
+ case SINPUT_PADDLESTYLE_TWO:
+ paddle_pairs = 1;
+ break;
+
+ case SINPUT_PADDLESTYLE_FOUR:
+ paddle_pairs = 2;
+ break;
+
+ default:
+ break;
}
- if (button_mask & (1 << SDL_GAMEPAD_BUTTON_RIGHT_SHOULDER)) {
- SDL_strlcat(mapping_string, "rightshoulder:b10,", sizeof(mapping_string));
+
+ // Digital button mappings
+ // ABXY buttons (always applied as South, East, West, North)
+ SDL_ADD_BUTTON_MAPPING("a", current_button++, mapping_string_len); // South (typically A on Xbox, X on PlayStation)
+ SDL_ADD_BUTTON_MAPPING("b", current_button++, mapping_string_len); // East (typically B on Xbox, Circle on PlayStation)
+ SDL_ADD_BUTTON_MAPPING("x", current_button++, mapping_string_len); // West (typically X on Xbox, Square on PlayStation)
+ SDL_ADD_BUTTON_MAPPING("y", current_button++, mapping_string_len); // North (typically Y on Xbox, Triangle on PlayStation)
+
+ // D-Pad (always applied)
+ SDL_strlcat(mapping_string, "dpup:h0.1,dpdown:h0.4,dpleft:h0.8,dpright:h0.2,", mapping_string_len);
+
+ // Left and Right stick buttons
+ if (left_stick) {
+ SDL_ADD_BUTTON_MAPPING("leftstick", current_button++, mapping_string_len);
}
- if (button_mask & (1 << SDL_GAMEPAD_BUTTON_DPAD_UP)) {
- SDL_strlcat(mapping_string, "dpup:b11,", sizeof(mapping_string));
+ if (right_stick) {
+ SDL_ADD_BUTTON_MAPPING("rightstick", current_button++, mapping_string_len);
}
- if (button_mask & (1 << SDL_GAMEPAD_BUTTON_DPAD_DOWN)) {
- SDL_strlcat(mapping_string, "dpdown:b12,", sizeof(mapping_string));
+
+ // Digital shoulder buttons (L/R Shoulder)
+ if (bumpers > 0) {
+ SDL_ADD_BUTTON_MAPPING("leftshoulder", current_button++, mapping_string_len);
}
- if (button_mask & (1 << SDL_GAMEPAD_BUTTON_DPAD_LEFT)) {
- SDL_strlcat(mapping_string, "dpleft:b13,", sizeof(mapping_string));
+ if (bumpers > 1) {
+ SDL_ADD_BUTTON_MAPPING("rightshoulder", current_button++, mapping_string_len);
}
- if (button_mask & (1 << SDL_GAMEPAD_BUTTON_DPAD_RIGHT)) {
- SDL_strlcat(mapping_string, "dpright:b14,", sizeof(mapping_string));
+
+ // Digital trigger buttons (capability overrides analog)
+ if (digital_triggers) {
+ SDL_ADD_BUTTON_MAPPING("lefttrigger", current_button++, mapping_string_len);
+ SDL_ADD_BUTTON_MAPPING("righttrigger", current_button++, mapping_string_len);
+ } else if (dualstage_triggers) {
+ // Dual-stage trigger buttons are appended as MISC buttons
+ // By convention the trigger buttons are misc3 and misc4 for GameCube style controllers
+ if (misc_end < 3) {
+ misc_end = 3;
+ }
+ SDL_snprintf(misc_label, sizeof(misc_label), "misc%d", misc_end++);
+ SDL_ADD_BUTTON_MAPPING(misc_label, current_button++, mapping_string_len);
+ SDL_snprintf(misc_label, sizeof(misc_label), "misc%d", misc_end++);
+ SDL_ADD_BUTTON_MAPPING(misc_label, current_button++, mapping_string_len);
}
- if (axis_mask & (1 << SDL_GAMEPAD_AXIS_LEFTX)) {
- SDL_strlcat(mapping_string, "leftx:a0,", sizeof(mapping_string));
+
+ // Paddle 1/2
+ if (paddle_pairs > 0) {
+ // Paddle 2 is first for left/right order of SInput
+ SDL_ADD_BUTTON_MAPPING("paddle2", current_button++, mapping_string_len);
+ SDL_ADD_BUTTON_MAPPING("paddle1", current_button++, mapping_string_len);
}
- if (axis_mask & (1 << SDL_GAMEPAD_AXIS_LEFTY)) {
- SDL_strlcat(mapping_string, "lefty:a1,", sizeof(mapping_string));
+
+ // Start/Plus
+ SDL_ADD_BUTTON_MAPPING("start", current_button++, mapping_string_len);
+
+ // Back/Minus, Guide/Home, Share/Capture
+ switch (styles->meta_style) {
+ case SINPUT_METASTYLE_BACK:
+ SDL_ADD_BUTTON_MAPPING("back", current_button++, mapping_string_len);
+ break;
+
+ case SINPUT_METASTYLE_BACKGUIDE:
+ SDL_ADD_BUTTON_MAPPING("back", current_button++, mapping_string_len);
+ SDL_ADD_BUTTON_MAPPING("guide", current_button++, mapping_string_len);
+ break;
+
+ case SINPUT_METASTYLE_BACKGUIDESHARE:
+ SDL_ADD_BUTTON_MAPPING("back", current_button++, mapping_string_len);
+ SDL_ADD_BUTTON_MAPPING("guide", current_button++, mapping_string_len);
+ SDL_ADD_BUTTON_MAPPING("misc1", current_button++, mapping_string_len);
+ break;
+
+ default:
+ break;
}
- if (axis_mask & (1 << SDL_GAMEPAD_AXIS_RIGHTX)) {
- SDL_strlcat(mapping_string, "rightx:a2,", sizeof(mapping_string));
+
+ // Paddle 3/4
+ if (paddle_pairs > 1) {
+ // Paddle 4 is first for left/right order of SInput
+ SDL_ADD_BUTTON_MAPPING("paddle4", current_button++, mapping_string_len);
+ SDL_ADD_BUTTON_MAPPING("paddle3", current_button++, mapping_string_len);
}
- if (axis_mask & (1 << SDL_GAMEPAD_AXIS_RIGHTY)) {
- SDL_strlcat(mapping_string, "righty:a3,", sizeof(mapping_string));
+
+ // Touchpad buttons
+ switch (styles->touch_style) {
+ case SINPUT_TOUCHSTYLE_SINGLE:
+ SDL_ADD_BUTTON_MAPPING("touchpad", current_button++, mapping_string_len);
+ break;
+
+ case SINPUT_TOUCHSTYLE_DOUBLE:
+ SDL_ADD_BUTTON_MAPPING("touchpad", current_button++, mapping_string_len);
+ // Add the second touchpad button at the end of the misc buttons
+ SDL_snprintf(misc_label, sizeof(misc_label), "misc%d", misc_end++);
+ SDL_ADD_BUTTON_MAPPING(misc_label, current_button++, mapping_string_len);
+ break;
+
+ default:
+ break;
}
- if (axis_mask & (1 << SDL_GAMEPAD_AXIS_LEFT_TRIGGER)) {
- SDL_strlcat(mapping_string, "lefttrigger:a4,", sizeof(mapping_string));
+
+ for (int i = 0; i < misc_buttons; ++i) {
+ SDL_snprintf(misc_label, sizeof(misc_label), "misc%d", misc_button++);
+ SDL_ADD_BUTTON_MAPPING(misc_label, current_button++, mapping_string_len);
}
- if (axis_mask & (1 << SDL_GAMEPAD_AXIS_RIGHT_TRIGGER)) {
- SDL_strlcat(mapping_string, "righttrigger:a5,", sizeof(mapping_string));
+}
+
+/*
+* Helper function to decode SInput features information packed into version
+*/
+static void SDL_CreateMappingStringForSInputGamepad(Uint16 vendor, Uint16 product, Uint8 sub_product, Uint16 version, Uint8 face_style, char* mapping_string, size_t mapping_string_len)
+{
+ SDL_SInputStyles_t decoded = { 0 };
+
+ switch (face_style) {
+ default:
+ SDL_strlcat(mapping_string, "face:abxy,", mapping_string_len);
+ break;
+ case 2:
+ SDL_strlcat(mapping_string, "face:axby,", mapping_string_len);
+ break;
+ case 3:
+ SDL_strlcat(mapping_string, "face:bayx,", mapping_string_len);
+ break;
+ case 4:
+ SDL_strlcat(mapping_string, "face:sony,", mapping_string_len);
+ break;
}
- return SDL_PrivateAddMappingForGUID(guid, mapping_string, &existing, SDL_GAMEPAD_MAPPING_PRIORITY_DEFAULT);
+ // Interpret the mapping string
+ // dynamically based on the feature responses
+ decoded.misc_style = (SInput_MiscStyleType)(version % SINPUT_MISCSTYLE_MAX);
+ version /= SINPUT_MISCSTYLE_MAX;
+
+ decoded.touch_style = (SInput_TouchStyleType)(version % SINPUT_TOUCHSTYLE_MAX);
+ version /= SINPUT_TOUCHSTYLE_MAX;
+
+ decoded.meta_style = (SInput_MetaStyleType)(version % SINPUT_METASTYLE_MAX);
+ version /= SINPUT_METASTYLE_MAX;
+
+ decoded.paddle_style = (SInput_PaddleStyleType)(version % SINPUT_PADDLESTYLE_MAX);
+ version /= SINPUT_PADDLESTYLE_MAX;
+
+ decoded.trigger_style = (SInput_TriggerStyleType)(version % SINPUT_TRIGGERSTYLE_MAX);
+ version /= SINPUT_TRIGGERSTYLE_MAX;
+
+ decoded.bumper_style = (SInput_BumperStyleType)(version % SINPUT_BUMPERSTYLE_MAX);
+ version /= SINPUT_BUMPERSTYLE_MAX;
+
+ decoded.analog_style = (SInput_AnalogStyleType)(version % SINPUT_ANALOGSTYLE_MAX);
+
+ SDL_SInputStylesMapExtraction(&decoded, mapping_string, mapping_string_len);
}
-#endif // SDL_PLATFORM_ANDROID
/*
* Helper function to guess at a mapping for HIDAPI gamepads
@@ -742,17 +1105,52 @@ static GamepadMapping_t *SDL_CreateMappingForHIDAPIGamepad(SDL_GUID guid)
char mapping_string[1024];
Uint16 vendor;
Uint16 product;
+ Uint16 version;
SDL_strlcpy(mapping_string, "none,*,", sizeof(mapping_string));
- SDL_GetJoystickGUIDInfo(guid, &vendor, &product, NULL, NULL);
+ SDL_GetJoystickGUIDInfo(guid, &vendor, &product, &version, NULL);
+
+ if (SDL_IsJoystickWheel(vendor, product)) {
+ // We don't want to pick up Logitech FFB wheels here
+ // Some versions of WINE will also not treat devices that show up as gamepads as wheels
+ return NULL;
+ }
if ((vendor == USB_VENDOR_NINTENDO && product == USB_PRODUCT_NINTENDO_GAMECUBE_ADAPTER) ||
(vendor == USB_VENDOR_DRAGONRISE &&
(product == USB_PRODUCT_EVORETRO_GAMECUBE_ADAPTER1 ||
- product == USB_PRODUCT_EVORETRO_GAMECUBE_ADAPTER2))) {
+ product == USB_PRODUCT_EVORETRO_GAMECUBE_ADAPTER2 ||
+ product == USB_PRODUCT_EVORETRO_GAMECUBE_ADAPTER3))) {
// 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));
+ SDL_strlcat(mapping_string, "a:b0,b:b2,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:b1,y:b3,misc3:b11,misc4:b10,hint:!SDL_GAMECONTROLLER_USE_GAMECUBE_LABELS:=1,", sizeof(mapping_string));
+ } else if (vendor == USB_VENDOR_NINTENDO &&
+ product == USB_PRODUCT_NINTENDO_SWITCH2_GAMECUBE_CONTROLLER) {
+ SDL_strlcat(mapping_string, "a:b1,b:b3,dpdown:h0.4,dpleft:h0.8,dpright:h0.2,dpup:h0.1,guide:b4,leftshoulder:b6,lefttrigger:a4,leftx:a0,lefty:a1,rightshoulder:b7,righttrigger:a5,rightx:a2,righty:a3,start:b5,x:b0,y:b2,misc1:b8,misc2:b9,misc3:b10,misc4:b11,hint:!SDL_GAMECONTROLLER_USE_GAMECUBE_LABELS:=1,", sizeof(mapping_string));
+ } else if (vendor == USB_VENDOR_NINTENDO &&
+ product == USB_PRODUCT_NINTENDO_SWITCH2_PRO) {
+ SDL_strlcat(mapping_string, "a:b0,b:b1,back:b4,dpdown:h0.4,dpleft:h0.8,dpright:h0.2,dpup:h0.1,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,misc1:b11,misc2:b12,paddle1:b13,paddle2:b14,hint:!SDL_GAMECONTROLLER_USE_BUTTON_LABELS:=1,", sizeof(mapping_string));
+ } else if (vendor == USB_VENDOR_NINTENDO &&
+ product == USB_PRODUCT_NINTENDO_SWITCH2_JOYCON_LEFT) {
+ if (SDL_GetHintBoolean(SDL_HINT_JOYSTICK_HIDAPI_VERTICAL_JOY_CONS, false)) {
+ // Vertical mode
+ SDL_strlcat(mapping_string, "back:b4,dpdown:h0.4,dpleft:h0.8,dpright:h0.2,dpup:h0.1,leftshoulder:b9,leftstick:b7,lefttrigger:a4,leftx:a0,lefty:a1,misc1:b11,paddle2:b14,paddle4:b16,", sizeof(mapping_string));
+ } else {
+ // Mini gamepad mode
+ SDL_strlcat(mapping_string, "a:b1,b:b2,guide:b5,leftshoulder:b9,leftstick:b7,leftx:a0,lefty:a1,rightshoulder:b10,start:b6,x:b3,y:b0,paddle2:b14,paddle4:b16,", sizeof(mapping_string));
+ }
+ } else if (vendor == USB_VENDOR_NINTENDO &&
+ product == USB_PRODUCT_NINTENDO_SWITCH2_JOYCON_RIGHT) {
+ if (SDL_GetHintBoolean(SDL_HINT_JOYSTICK_HIDAPI_VERTICAL_JOY_CONS, false)) {
+ // Vertical mode
+ 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,misc2:b12,paddle1:b13,paddle3:b15,hint:!SDL_GAMECONTROLLER_USE_BUTTON_LABELS:=1,", sizeof(mapping_string));
+ } else {
+ // Mini gamepad mode
+ SDL_strlcat(mapping_string, "a:b1,b:b3,guide:b5,leftshoulder:b9,leftstick:b7,leftx:a0,lefty:a1,rightshoulder:b10,start:b6,x:b0,y:b2,misc2:b12,paddle1:b13,paddle3:b15,hint:!SDL_GAMECONTROLLER_USE_BUTTON_LABELS:=1,", sizeof(mapping_string));
+ }
+ } else if (vendor == USB_VENDOR_NINTENDO &&
+ product == USB_PRODUCT_NINTENDO_SWITCH2_JOYCON_PAIR) {
+ SDL_strlcat(mapping_string, "a:b0,b:b1,back:b4,dpdown:h0.4,dpleft:h0.8,dpright:h0.2,dpup:h0.1,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,misc1:b11,misc2:b12,paddle1:b13,paddle2:b14,paddle3:b15,paddle4:b16,hint:!SDL_GAMECONTROLLER_USE_BUTTON_LABELS:=1,", sizeof(mapping_string));
} else if (vendor == USB_VENDOR_NINTENDO &&
(guid.data[15] == k_eSwitchDeviceInfoControllerType_HVCLeft ||
guid.data[15] == k_eSwitchDeviceInfoControllerType_HVCRight ||
@@ -780,7 +1178,7 @@ static GamepadMapping_t *SDL_CreateMappingForHIDAPIGamepad(SDL_GUID guid)
SDL_strlcat(mapping_string, "a:b0,b:b1,back:b4,dpdown:h0.4,dpleft:h0.8,dpright:h0.2,dpup:h0.1,leftshoulder:b9,lefttrigger:a4,rightshoulder:b10,righttrigger:a5,start:b6,x:b2,y:b3,hint:!SDL_GAMECONTROLLER_USE_BUTTON_LABELS:=1,", sizeof(mapping_string));
break;
case k_eSwitchDeviceInfoControllerType_N64:
- SDL_strlcat(mapping_string, "a:b0,b:b1,back:b4,dpdown:h0.4,dpleft:h0.8,dpright:h0.2,dpup:h0.1,guide:b5,leftshoulder:b9,leftstick:b7,lefttrigger:a4,leftx:a0,lefty:a1,rightshoulder:b10,righttrigger:a5,start:b6,x:b2,y:b3,misc1:b11,", sizeof(mapping_string));
+ SDL_strlcat(mapping_string, "a:b0,b:b1,back:b3,dpdown:h0.4,dpleft:h0.8,dpright:h0.2,dpup:h0.1,guide:b5,leftshoulder:b9,lefttrigger:a4,leftx:a0,lefty:a1,misc1:b11,misc2:b4,rightshoulder:b10,righttrigger:b7,start:b6,x:a5,y:b2,", sizeof(mapping_string));
break;
case k_eSwitchDeviceInfoControllerType_SEGA_Genesis:
SDL_strlcat(mapping_string, "a:b0,b:b1,dpdown:h0.4,dpleft:h0.8,dpright:h0.2,dpup:h0.1,guide:b5,leftshoulder:b9,rightshoulder:b10,righttrigger:a5,start:b6,x:b2,y:b3,misc1:b11,", sizeof(mapping_string));
@@ -817,13 +1215,48 @@ static GamepadMapping_t *SDL_CreateMappingForHIDAPIGamepad(SDL_GUID guid)
}
break;
}
+ } else if (vendor == USB_VENDOR_8BITDO &&
+ (product == USB_PRODUCT_8BITDO_SF30_PRO ||
+ product == USB_PRODUCT_8BITDO_SF30_PRO_BT ||
+ product == USB_PRODUCT_8BITDO_SN30_PRO ||
+ product == USB_PRODUCT_8BITDO_SN30_PRO_BT ||
+ product == USB_PRODUCT_8BITDO_PRO_2 ||
+ product == USB_PRODUCT_8BITDO_PRO_2_BT ||
+ product == USB_PRODUCT_8BITDO_PRO_3)) {
+ SDL_strlcat(mapping_string, "a:b1,b:b0,back:b4,dpdown:h0.4,dpleft:h0.8,dpright:h0.2,dpup:h0.1,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:b3,y:b2,hint:!SDL_GAMECONTROLLER_USE_BUTTON_LABELS:=1,", sizeof(mapping_string));
+ if (product == USB_PRODUCT_8BITDO_PRO_2 || product == USB_PRODUCT_8BITDO_PRO_2_BT) {
+ SDL_strlcat(mapping_string, "paddle1:b14,paddle2:b13,", sizeof(mapping_string));
+ } else if (product == USB_PRODUCT_8BITDO_PRO_3) {
+ SDL_strlcat(mapping_string, "paddle1:b12,paddle2:b11,paddle3:b14,paddle4:b13,", sizeof(mapping_string));
+ }
+ } else if (vendor == USB_VENDOR_8BITDO &&
+ (product == USB_PRODUCT_8BITDO_SF30_PRO ||
+ product == USB_PRODUCT_8BITDO_SF30_PRO_BT)) {
+ // This controller has no guide button
+ SDL_strlcat(mapping_string, "a:b1,b:b0,back:b4,dpdown:h0.4,dpleft:h0.8,dpright:h0.2,dpup:h0.1,leftshoulder:b9,leftstick:b7,lefttrigger:a4,leftx:a0,lefty:a1,rightshoulder:b10,rightstick:b8,righttrigger:a5,rightx:a2,righty:a3,start:b6,x:b3,y:b2,hint:!SDL_GAMECONTROLLER_USE_BUTTON_LABELS:=1,", sizeof(mapping_string));
+ } else if (SDL_IsJoystickSInputController(vendor, product)) {
+
+ Uint8 face_style = (guid.data[15] & 0xE0) >> 5;
+ Uint8 sub_product = guid.data[15] & 0x1F;
+
+ SDL_CreateMappingStringForSInputGamepad(vendor, product, sub_product, version, face_style, mapping_string, sizeof(mapping_string));
} 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:h0.4,dpleft:h0.8,dpright:h0.2,dpup:h0.1,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_IsJoystickGameCube(vendor, product)) {
+ SDL_strlcat(mapping_string, "a:b0,b:b2,back:b4,dpdown:h0.4,dpleft:h0.8,dpright:h0.2,dpup:h0.1,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:b1,y:b3,hint:!SDL_GAMECONTROLLER_USE_GAMECUBE_LABELS:=1,", sizeof(mapping_string));
+ } else {
+ SDL_strlcat(mapping_string, "a:b0,b:b1,back:b4,dpdown:h0.4,dpleft:h0.8,dpright:h0.2,dpup:h0.1,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_IsJoystickSteamController(vendor, product)) {
// Steam controllers have 2 back paddle buttons
SDL_strlcat(mapping_string, "paddle1:b11,paddle2:b12,", sizeof(mapping_string));
+ } else if (SDL_IsJoystickSteamDeck(vendor, product)) {
+ // The Steam Deck's built-in controller has QAM, 4 back buttons, L/R trackpads, and L/R capacitive touch sticks
+ SDL_strlcat(mapping_string, "misc1:b11,paddle1:b12,paddle2:b13,paddle3:b14,paddle4:b15,touchpad:b17,misc2:b16,misc3:b19,misc4:b18", sizeof(mapping_string));
+ } else if (SDL_IsJoystickSteamTriton(vendor, product)) {
+ // Second generation Steam controllers have 4 back paddle buttons
+ SDL_strlcat(mapping_string, "misc1:b11,paddle1:b12,paddle2:b13,paddle3:b14,paddle4:b15,touchpad:b17,misc2:b16,misc3:b19,misc4:b18,misc5:b21,misc6:b20", sizeof(mapping_string));
} else if (SDL_IsJoystickNintendoSwitchPro(vendor, product) ||
SDL_IsJoystickNintendoSwitchProInputOnly(vendor, product)) {
// Nintendo Switch Pro controllers have a screenshot button
@@ -836,18 +1269,33 @@ static GamepadMapping_t *SDL_CreateMappingForHIDAPIGamepad(SDL_GUID guid)
SDL_strlcat(mapping_string, "misc1:b11,", 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:b11,misc2:b12", sizeof(mapping_string));
+ SDL_strlcat(mapping_string, "misc1:b11,misc2:b12,", 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:b11,", sizeof(mapping_string));
if (product == USB_PRODUCT_NVIDIA_SHIELD_CONTROLLER_V103) {
// The original SHIELD controller has a touchpad and plus/minus buttons as well
- SDL_strlcat(mapping_string, "touchpad:b12,misc2:b13,misc3:b14", sizeof(mapping_string));
+ SDL_strlcat(mapping_string, "touchpad:b12,misc2:b13,misc3:b14,", sizeof(mapping_string));
}
} else if (SDL_IsJoystickHoriSteamController(vendor, product)) {
/* The Wireless HORIPad for Steam has QAM, Steam, Capsense L/R Sticks, 2 rear buttons, and 2 misc buttons */
- SDL_strlcat(mapping_string, "paddle1:b13,paddle2:b12,paddle3:b15,paddle4:b14,misc2:b11,misc3:b16,misc4:b17", sizeof(mapping_string));
+ SDL_strlcat(mapping_string, "paddle1:b13,paddle2:b12,paddle3:b15,paddle4:b14,misc1:b11,misc3:b16,misc4:b17", sizeof(mapping_string));
+ } else if (SDL_IsJoystickFlydigiController(vendor, product)) {
+ SDL_strlcat(mapping_string, "paddle1:b11,paddle2:b12,paddle3:b13,paddle4:b14,", sizeof(mapping_string));
+ if (guid.data[15] >= SDL_FLYDIGI_VADER2) {
+ // Vader series of controllers have C/Z buttons
+ SDL_strlcat(mapping_string, "misc2:b15,misc3:b16,", sizeof(mapping_string));
+ if (guid.data[15] == SDL_FLYDIGI_VADER5_PRO) {
+ // Vader 5 has additional shoulder macro buttons and a circle button
+ SDL_strlcat(mapping_string, "misc4:b17,misc5:b18,misc6:b19", sizeof(mapping_string));
+ }
+ } else if (guid.data[15] == SDL_FLYDIGI_APEX5) {
+ // Apex 5 has additional shoulder macro buttons
+ SDL_strlcat(mapping_string, "misc2:b15,misc3:b16,", sizeof(mapping_string));
+ }
+ } else if (vendor == USB_VENDOR_8BITDO && product == USB_PRODUCT_8BITDO_ULTIMATE2_WIRELESS) {
+ SDL_strlcat(mapping_string, "paddle1:b12,paddle2:b11,paddle3:b14,paddle4:b13,", sizeof(mapping_string));
} else {
switch (SDL_GetGamepadTypeFromGUID(guid, NULL)) {
case SDL_GAMEPAD_TYPE_PS4:
@@ -977,7 +1425,8 @@ static GamepadMapping_t *SDL_PrivateGetGamepadMappingForGUID(SDL_GUID guid, bool
{
GamepadMapping_t *mapping;
- mapping = SDL_PrivateMatchGamepadMappingForGUID(guid, true, adding_mapping);
+ // Try first with an exact match on version and CRC
+ mapping = SDL_PrivateMatchGamepadMappingForGUID(guid, true, true);
if (mapping) {
return mapping;
}
@@ -987,10 +1436,19 @@ static GamepadMapping_t *SDL_PrivateGetGamepadMappingForGUID(SDL_GUID guid, bool
return NULL;
}
- // Try harder to get the best match, or create a mapping
+ // Try without CRC match
+ mapping = SDL_PrivateMatchGamepadMappingForGUID(guid, true, false);
+ if (mapping) {
+ return mapping;
+ }
+ // Try without version match
if (SDL_JoystickGUIDUsesVersion(guid)) {
- // Try again, ignoring the version
+ mapping = SDL_PrivateMatchGamepadMappingForGUID(guid, false, true);
+ if (mapping) {
+ return mapping;
+ }
+
mapping = SDL_PrivateMatchGamepadMappingForGUID(guid, false, false);
if (mapping) {
return mapping;
@@ -1030,7 +1488,8 @@ static const char *map_StringForGamepadType[] = {
"switchpro",
"joyconleft",
"joyconright",
- "joyconpair"
+ "joyconpair",
+ "gamecube"
};
SDL_COMPILE_TIME_ASSERT(map_StringForGamepadType, SDL_arraysize(map_StringForGamepadType) == SDL_GAMEPAD_TYPE_COUNT);
@@ -1145,7 +1604,7 @@ SDL_COMPILE_TIME_ASSERT(map_StringForGamepadButton, SDL_arraysize(map_StringForG
/*
* convert a string to its enum equivalent
*/
-static SDL_GamepadButton SDL_PrivateGetGamepadButtonFromString(const char *str, bool baxy)
+static SDL_GamepadButton SDL_PrivateGetGamepadButtonFromString(const char *str, bool axby, bool baxy)
{
int i;
@@ -1155,7 +1614,17 @@ static SDL_GamepadButton SDL_PrivateGetGamepadButtonFromString(const char *str,
for (i = 0; i < SDL_arraysize(map_StringForGamepadButton); ++i) {
if (SDL_strcasecmp(str, map_StringForGamepadButton[i]) == 0) {
- if (baxy) {
+ if (axby) {
+ // Need to swap face buttons
+ switch (i) {
+ case SDL_GAMEPAD_BUTTON_EAST:
+ return SDL_GAMEPAD_BUTTON_WEST;
+ case SDL_GAMEPAD_BUTTON_WEST:
+ return SDL_GAMEPAD_BUTTON_EAST;
+ default:
+ break;
+ }
+ } else if (baxy) {
// Need to swap face buttons
switch (i) {
case SDL_GAMEPAD_BUTTON_SOUTH:
@@ -1177,7 +1646,7 @@ static SDL_GamepadButton SDL_PrivateGetGamepadButtonFromString(const char *str,
}
SDL_GamepadButton SDL_GetGamepadButtonFromString(const char *str)
{
- return SDL_PrivateGetGamepadButtonFromString(str, false);
+ return SDL_PrivateGetGamepadButtonFromString(str, false, false);
}
/*
@@ -1204,6 +1673,7 @@ static bool SDL_PrivateParseGamepadElement(SDL_Gamepad *gamepad, const char *szG
char half_axis_output = 0;
int i;
SDL_GamepadBinding *new_bindings;
+ bool axby_mapping = false;
bool baxy_mapping = false;
SDL_AssertJoysticksLocked();
@@ -1214,12 +1684,18 @@ static bool SDL_PrivateParseGamepadElement(SDL_Gamepad *gamepad, const char *szG
half_axis_output = *szGameButton++;
}
+ if (SDL_strstr(gamepad->mapping->mapping, ",hint:SDL_GAMECONTROLLER_USE_GAMECUBE_LABELS:=1") != NULL) {
+ axby_mapping = true;
+ }
if (SDL_strstr(gamepad->mapping->mapping, ",hint:SDL_GAMECONTROLLER_USE_BUTTON_LABELS:=1") != NULL) {
baxy_mapping = true;
}
+ // FIXME: We fix these up when loading the mapping, does this ever get hit?
+ //SDL_assert(!axby_mapping && !baxy_mapping);
+
axis = SDL_GetGamepadAxisFromString(szGameButton);
- button = SDL_PrivateGetGamepadButtonFromString(szGameButton, baxy_mapping);
+ button = SDL_PrivateGetGamepadButtonFromString(szGameButton, axby_mapping, baxy_mapping);
if (axis != SDL_GAMEPAD_AXIS_INVALID) {
bind.output_type = SDL_GAMEPAD_BINDTYPE_AXIS;
bind.output.axis.axis = axis;
@@ -1310,7 +1786,7 @@ static bool SDL_PrivateParseGamepadElement(SDL_Gamepad *gamepad, const char *szG
static bool SDL_PrivateParseGamepadConfigString(SDL_Gamepad *gamepad, const char *pchString)
{
char szGameButton[20];
- char szJoystickButton[20];
+ char szJoystickButton[128];
bool bGameButton = true;
int i = 0;
const char *pchPos = pchString;
@@ -1385,6 +1861,8 @@ static SDL_GamepadFaceStyle SDL_GetGamepadFaceStyleFromString(const char *string
{
if (SDL_strcmp(string, "abxy") == 0) {
return SDL_GAMEPAD_FACE_STYLE_ABXY;
+ } else if (SDL_strcmp(string, "axby") == 0) {
+ return SDL_GAMEPAD_FACE_STYLE_AXBY;
} else if (SDL_strcmp(string, "bayx") == 0) {
return SDL_GAMEPAD_FACE_STYLE_BAYX;
} else if (SDL_strcmp(string, "sony") == 0) {
@@ -1406,6 +1884,8 @@ static SDL_GamepadFaceStyle SDL_GetGamepadFaceStyleForGamepadType(SDL_GamepadTyp
case SDL_GAMEPAD_TYPE_NINTENDO_SWITCH_JOYCON_RIGHT:
case SDL_GAMEPAD_TYPE_NINTENDO_SWITCH_JOYCON_PAIR:
return SDL_GAMEPAD_FACE_STYLE_BAYX;
+ case SDL_GAMEPAD_TYPE_GAMECUBE:
+ return SDL_GAMEPAD_FACE_STYLE_AXBY;
default:
return SDL_GAMEPAD_FACE_STYLE_ABXY;
}
@@ -1432,6 +1912,11 @@ static void SDL_UpdateGamepadFaceStyle(SDL_Gamepad *gamepad)
}
}
+ if (gamepad->face_style == SDL_GAMEPAD_FACE_STYLE_UNKNOWN &&
+ SDL_strstr(gamepad->mapping->mapping, "SDL_GAMECONTROLLER_USE_GAMECUBE_LABELS") != NULL) {
+ // This controller uses GameCube button style
+ gamepad->face_style = SDL_GAMEPAD_FACE_STYLE_AXBY;
+ }
if (gamepad->face_style == SDL_GAMEPAD_FACE_STYLE_UNKNOWN &&
SDL_strstr(gamepad->mapping->mapping, "SDL_GAMECONTROLLER_USE_BUTTON_LABELS") != NULL) {
// This controller uses Nintendo button style
@@ -1444,6 +1929,8 @@ static void SDL_UpdateGamepadFaceStyle(SDL_Gamepad *gamepad)
static void SDL_FixupHIDAPIMapping(SDL_Gamepad *gamepad)
{
+ SDL_AssertJoysticksLocked();
+
// Check to see if we need fixup
bool need_fixup = false;
for (int i = 0; i < gamepad->num_bindings; ++i) {
@@ -1901,14 +2388,25 @@ static GamepadMapping_t *SDL_PrivateGetGamepadMapping(SDL_JoystickID instance_id
return mapping;
}
+static bool SDL_PrivateIsGamepadPlatformMatch(const char *platform, size_t platform_len)
+{
+#ifdef SDL_PLATFORM_MACOS
+ // We also accept the older SDL2 platform name for macOS
+ if (SDL_strncasecmp(platform, "Mac OS X", platform_len) == 0) {
+ return true;
+ }
+#endif
+
+ return SDL_strncasecmp(platform, SDL_GetPlatform(), platform_len) == 0;
+}
+
/*
* Add or update an entry into the Mappings Database
*/
int SDL_AddGamepadMappingsFromIO(SDL_IOStream *src, bool closeio)
{
- const char *platform = SDL_GetPlatform();
int gamepads = 0;
- char *buf, *line, *line_end, *tmp, *comma, line_platform[64];
+ char *buf, *line, *line_end, *tmp, *comma, *platform;
size_t db_size;
size_t platform_len;
@@ -1937,13 +2435,11 @@ int SDL_AddGamepadMappingsFromIO(SDL_IOStream *src, bool closeio)
tmp += SDL_GAMEPAD_PLATFORM_FIELD_SIZE;
comma = SDL_strchr(tmp, ',');
if (comma) {
- 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++;
- }
+ platform = tmp;
+ platform_len = comma - platform;
+ if (SDL_PrivateIsGamepadPlatformMatch(platform, platform_len) &&
+ SDL_AddGamepadMapping(line) > 0) {
+ gamepads++;
}
}
}
@@ -1961,7 +2457,11 @@ int SDL_AddGamepadMappingsFromIO(SDL_IOStream *src, bool closeio)
int SDL_AddGamepadMappingsFromFile(const char *file)
{
- return SDL_AddGamepadMappingsFromIO(SDL_IOFromFile(file, "rb"), true);
+ SDL_IOStream *stream = SDL_IOFromFile(file, "rb");
+ if (!stream) {
+ return -1;
+ }
+ return SDL_AddGamepadMappingsFromIO(stream, true);
}
bool SDL_ReloadGamepadMappings(void)
@@ -1986,7 +2486,37 @@ bool SDL_ReloadGamepadMappings(void)
return true;
}
-static char *SDL_ConvertMappingToPositional(const char *mapping)
+static char *SDL_ConvertMappingToPositionalAXBY(const char *mapping)
+{
+ // Add space for '!' and null terminator
+ size_t length = SDL_strlen(mapping) + 1 + 1;
+ char *remapped = (char *)SDL_malloc(length);
+ if (remapped) {
+ char *button_B;
+ char *button_X;
+ char *hint;
+
+ SDL_strlcpy(remapped, mapping, length);
+ button_B = SDL_strstr(remapped, ",b:");
+ button_X = SDL_strstr(remapped, ",x:");
+ hint = SDL_strstr(remapped, "hint:SDL_GAMECONTROLLER_USE_GAMECUBE_LABELS");
+
+ if (button_B) {
+ button_B[1] = 'x';
+ }
+ if (button_X) {
+ button_X[1] = 'b';
+ }
+ if (hint) {
+ hint += 5;
+ SDL_memmove(hint + 1, hint, SDL_strlen(hint) + 1);
+ *hint = '!';
+ }
+ }
+ return remapped;
+}
+
+static char *SDL_ConvertMappingToPositionalBAXY(const char *mapping)
{
// Add space for '!' and null terminator
size_t length = SDL_strlen(mapping) + 1 + 1;
@@ -1999,23 +2529,23 @@ static char *SDL_ConvertMappingToPositional(const char *mapping)
char *hint;
SDL_strlcpy(remapped, mapping, length);
- button_A = SDL_strstr(remapped, "a:");
- button_B = SDL_strstr(remapped, "b:");
- button_X = SDL_strstr(remapped, "x:");
- button_Y = SDL_strstr(remapped, "y:");
+ button_A = SDL_strstr(remapped, ",a:");
+ button_B = SDL_strstr(remapped, ",b:");
+ button_X = SDL_strstr(remapped, ",x:");
+ button_Y = SDL_strstr(remapped, ",y:");
hint = SDL_strstr(remapped, "hint:SDL_GAMECONTROLLER_USE_BUTTON_LABELS");
if (button_A) {
- *button_A = 'b';
+ button_A[1] = 'b';
}
if (button_B) {
- *button_B = 'a';
+ button_B[1] = 'a';
}
if (button_X) {
- *button_X = 'y';
+ button_X[1] = 'y';
}
if (button_Y) {
- *button_Y = 'x';
+ button_Y[1] = 'x';
}
if (hint) {
hint += 5;
@@ -2031,9 +2561,11 @@ static char *SDL_ConvertMappingToPositional(const char *mapping)
*/
static int SDL_PrivateAddGamepadMapping(const char *mappingString, SDL_GamepadMappingPriority priority)
{
+ char *appended = NULL;
char *remapped = NULL;
char *pchGUID;
- SDL_GUID jGUID;
+ SDL_GUID guid;
+ Uint16 vendor, product;
bool is_default_mapping = false;
bool is_xinput_mapping = false;
bool existing = false;
@@ -2042,11 +2574,33 @@ static int SDL_PrivateAddGamepadMapping(const char *mappingString, SDL_GamepadMa
SDL_AssertJoysticksLocked();
- if (!mappingString) {
+ CHECK_PARAM(!mappingString) {
SDL_InvalidParamError("mappingString");
return -1;
}
+ pchGUID = SDL_PrivateGetGamepadGUIDFromMappingString(mappingString);
+ if (!pchGUID) {
+ SDL_SetError("Couldn't parse GUID from %s", mappingString);
+ return -1;
+ }
+ if (!SDL_strcasecmp(pchGUID, "default")) {
+ is_default_mapping = true;
+ } else if (!SDL_strcasecmp(pchGUID, "xinput")) {
+ is_xinput_mapping = true;
+ }
+ guid = SDL_StringToGUID(pchGUID);
+ SDL_free(pchGUID);
+
+ SDL_GetJoystickGUIDInfo(guid, &vendor, &product, NULL, NULL);
+ if (SDL_IsJoystickGameCube(vendor, product) &&
+ SDL_strstr(mappingString, "SDL_GAMECONTROLLER_USE_GAMECUBE_LABELS") == NULL) {
+ SDL_asprintf(&appended, "%shint:SDL_GAMECONTROLLER_USE_GAMECUBE_LABELS:=1,", mappingString);
+ if (appended) {
+ mappingString = appended;
+ }
+ }
+
{ // Extract and verify the hint field
const char *tmp;
@@ -2078,20 +2632,37 @@ static int SDL_PrivateAddGamepadMapping(const char *mappingString, SDL_GamepadMa
default_value = false;
}
- if (SDL_strcmp(hint, "SDL_GAMECONTROLLER_USE_BUTTON_LABELS") == 0) {
+ if (SDL_strcmp(hint, "SDL_GAMECONTROLLER_USE_GAMECUBE_LABELS") == 0) {
+ // This hint is used to signal whether the mapping uses positional buttons or not
+ if (negate) {
+ // This mapping uses positional buttons, we can use it as-is
+ } else {
+ // This mapping uses labeled buttons, we need to swap them to positional
+ remapped = SDL_ConvertMappingToPositionalAXBY(mappingString);
+ if (!remapped) {
+ goto done;
+ }
+ mappingString = remapped;
+ }
+ } else if (SDL_strcmp(hint, "SDL_GAMECONTROLLER_USE_BUTTON_LABELS") == 0) {
// This hint is used to signal whether the mapping uses positional buttons or not
if (negate) {
// This mapping uses positional buttons, we can use it as-is
} else {
// This mapping uses labeled buttons, we need to swap them to positional
- remapped = SDL_ConvertMappingToPositional(mappingString);
+ remapped = SDL_ConvertMappingToPositionalBAXY(mappingString);
if (!remapped) {
goto done;
}
mappingString = remapped;
}
+
} else {
- value = SDL_GetHintBoolean(hint, default_value);
+ const char *hint_value = SDL_GetHint(hint);
+ if (!hint_value) {
+ hint_value = SDL_getenv_unsafe(hint);
+ }
+ value = SDL_GetStringBoolean(hint_value, default_value);
if (negate) {
value = !value;
}
@@ -2103,7 +2674,7 @@ static int SDL_PrivateAddGamepadMapping(const char *mappingString, SDL_GamepadMa
}
}
-#ifdef ANDROID
+#ifdef SDL_PLATFORM_ANDROID
{ // Extract and verify the SDK version
const char *tmp;
@@ -2126,20 +2697,7 @@ static int SDL_PrivateAddGamepadMapping(const char *mappingString, SDL_GamepadMa
}
#endif
- pchGUID = SDL_PrivateGetGamepadGUIDFromMappingString(mappingString);
- if (!pchGUID) {
- SDL_SetError("Couldn't parse GUID from %s", mappingString);
- goto done;
- }
- if (!SDL_strcasecmp(pchGUID, "default")) {
- is_default_mapping = true;
- } else if (!SDL_strcasecmp(pchGUID, "xinput")) {
- is_xinput_mapping = true;
- }
- jGUID = SDL_StringToGUID(pchGUID);
- SDL_free(pchGUID);
-
- pGamepadMapping = SDL_PrivateAddMappingForGUID(jGUID, mappingString, &existing, priority);
+ pGamepadMapping = SDL_PrivateAddMappingForGUID(guid, mappingString, &existing, priority);
if (!pGamepadMapping) {
goto done;
}
@@ -2155,9 +2713,8 @@ static int SDL_PrivateAddGamepadMapping(const char *mappingString, SDL_GamepadMa
result = 1;
}
done:
- if (remapped) {
- SDL_free(remapped);
- }
+ SDL_free(appended);
+ SDL_free(remapped);
return result;
}
@@ -2356,7 +2913,7 @@ bool SDL_SetGamepadMapping(SDL_JoystickID instance_id, const char *mapping)
SDL_GUID guid = SDL_GetJoystickGUIDForID(instance_id);
bool result = false;
- if (SDL_memcmp(&guid, &s_zeroGUID, sizeof(guid)) == 0) {
+ CHECK_PARAM(SDL_memcmp(&guid, &s_zeroGUID, sizeof(guid)) == 0) {
return SDL_InvalidParamError("instance_id");
}
@@ -2469,6 +3026,10 @@ bool SDL_InitGamepads(void)
SDL_gamepads_initialized = true;
+ SDL_LockJoysticks();
+
+ SDL_gamepad_names = SDL_CreateHashTable(0, false, SDL_HashID, SDL_KeyMatchID, SDL_DestroyHashValue, NULL);
+
// Watch for joystick events and fire gamepad ones if needed
SDL_AddEventWatch(SDL_GamepadEventWatcher, NULL);
@@ -2483,6 +3044,8 @@ bool SDL_InitGamepads(void)
SDL_free(joysticks);
}
+ SDL_UnlockJoysticks();
+
return true;
}
@@ -2529,19 +3092,10 @@ SDL_JoystickID *SDL_GetGamepads(int *count)
const char *SDL_GetGamepadNameForID(SDL_JoystickID instance_id)
{
- const char *result = NULL;
+ const char *result;
SDL_LockJoysticks();
- {
- GamepadMapping_t *mapping = SDL_PrivateGetGamepadMapping(instance_id, true);
- if (mapping) {
- if (SDL_strcmp(mapping->name, "*") == 0) {
- result = SDL_GetJoystickNameForID(instance_id);
- } else {
- result = SDL_GetPersistentString(mapping->name);
- }
- }
- }
+ result = SDL_UpdateGamepadNameForID(instance_id);
SDL_UnlockJoysticks();
return result;
@@ -2646,7 +3200,7 @@ char *SDL_GetGamepadMappingForID(SDL_JoystickID instance_id)
}
/*
- * Return 1 if the joystick with this name and GUID is a supported gamepad
+ * Return true if the joystick with this name and GUID is a supported gamepad
*/
bool SDL_IsGamepadNameAndGUID(const char *name, SDL_GUID guid)
{
@@ -2666,7 +3220,7 @@ bool SDL_IsGamepadNameAndGUID(const char *name, SDL_GUID guid)
}
/*
- * Return 1 if the joystick at this device index is a supported gamepad
+ * Return true if the joystick at this device index is a supported gamepad
*/
bool SDL_IsGamepad(SDL_JoystickID instance_id)
{
@@ -2675,7 +3229,8 @@ bool SDL_IsGamepad(SDL_JoystickID instance_id)
SDL_LockJoysticks();
{
const void *value;
- if (SDL_FindInHashTable(s_gamepadInstanceIDs, (void *)(uintptr_t)instance_id, &value)) {
+ if (s_gamepadInstanceIDs &&
+ SDL_FindInHashTable(s_gamepadInstanceIDs, (void *)(uintptr_t)instance_id, &value)) {
result = (bool)(uintptr_t)value;
} else {
if (SDL_PrivateGetGamepadMapping(instance_id, true) != NULL) {
@@ -2683,11 +3238,12 @@ bool SDL_IsGamepad(SDL_JoystickID instance_id)
} else {
result = false;
}
-
if (!s_gamepadInstanceIDs) {
s_gamepadInstanceIDs = SDL_CreateHashTable(0, false, SDL_HashID, SDL_KeyMatchID, NULL, NULL);
}
- SDL_InsertIntoHashTable(s_gamepadInstanceIDs, (void *)(uintptr_t)instance_id, (void *)(uintptr_t)result, true);
+ if (s_gamepadInstanceIDs) {
+ SDL_InsertIntoHashTable(s_gamepadInstanceIDs, (void *)(uintptr_t)instance_id, (void *)(uintptr_t)result, true);
+ }
}
}
SDL_UnlockJoysticks();
@@ -2696,38 +3252,44 @@ bool SDL_IsGamepad(SDL_JoystickID instance_id)
}
/*
- * Return 1 if the gamepad should be ignored by SDL
+ * Return true if the gamepad should be ignored by SDL
*/
bool SDL_ShouldIgnoreGamepad(Uint16 vendor_id, Uint16 product_id, Uint16 version, const char *name)
{
- int i;
- for (i = 0; i < SDL_arraysize(SDL_gamepad_blacklist_words); i++) {
- const struct SDL_GamepadBlacklistWords *blacklist_word = &SDL_gamepad_blacklist_words[i];
+ if (name) {
+ for (int i = 0; i < SDL_arraysize(SDL_gamepad_blacklist_words); i++) {
+ const struct SDL_GamepadBlacklistWords *blacklist_word = &SDL_gamepad_blacklist_words[i];
- switch (blacklist_word->pos) {
- case GAMEPAD_BLACKLIST_BEGIN:
- if (SDL_startswith(name, blacklist_word->str)) {
- return true;
- }
- break;
-
- case GAMEPAD_BLACKLIST_END:
- if (SDL_endswith(name, blacklist_word->str)) {
- return true;
- }
- break;
+ switch (blacklist_word->pos) {
+ case GAMEPAD_BLACKLIST_BEGIN:
+ if (SDL_startswith(name, blacklist_word->str)) {
+ return true;
+ }
+ break;
- case GAMEPAD_BLACKLIST_ANYWHERE:
- if (SDL_strstr(name, blacklist_word->str) != NULL) {
- return true;
- }
- break;
+ case GAMEPAD_BLACKLIST_END:
+ if (SDL_endswith(name, blacklist_word->str)) {
+ return true;
+ }
+ break;
+
+ case GAMEPAD_BLACKLIST_ANYWHERE:
+ if (SDL_strstr(name, blacklist_word->str) != NULL) {
+ if (SDL_startswith(name, "PG-")) {
+ // Ipega gamepads have modes with keyboard keys in addition to gamepad controls
+ break;
+ }
+ return true;
+ }
+ break;
+ }
}
}
+ const char *hint = SDL_getenv_unsafe("SDL_GAMECONTROLLER_ALLOW_STEAM_VIRTUAL_GAMEPAD");
+ bool allow_steam_virtual_gamepad = SDL_GetStringBoolean(hint, false);
#ifdef SDL_PLATFORM_WIN32
- if (SDL_GetHintBoolean("SDL_GAMECONTROLLER_ALLOW_STEAM_VIRTUAL_GAMEPAD", false) &&
- WIN_IsWine()) {
+ if (allow_steam_virtual_gamepad && WIN_IsWine()) {
// We are launched by Steam and running under Proton or Wine
// We can't tell whether this controller is a Steam Virtual Gamepad,
// so assume that is doing the appropriate filtering of controllers
@@ -2737,7 +3299,7 @@ bool SDL_ShouldIgnoreGamepad(Uint16 vendor_id, Uint16 product_id, Uint16 version
#endif // SDL_PLATFORM_WIN32
if (SDL_IsJoystickSteamVirtualGamepad(vendor_id, product_id, version)) {
- return !SDL_GetHintBoolean("SDL_GAMECONTROLLER_ALLOW_STEAM_VIRTUAL_GAMEPAD", false);
+ return !allow_steam_virtual_gamepad;
}
if (SDL_allowed_gamepads.num_included_entries > 0) {
@@ -3034,6 +3596,24 @@ static SDL_GamepadButtonLabel SDL_GetGamepadButtonLabelForFaceStyle(SDL_GamepadF
break;
}
break;
+ case SDL_GAMEPAD_FACE_STYLE_AXBY:
+ switch (button) {
+ case SDL_GAMEPAD_BUTTON_SOUTH:
+ label = SDL_GAMEPAD_BUTTON_LABEL_A;
+ break;
+ case SDL_GAMEPAD_BUTTON_EAST:
+ label = SDL_GAMEPAD_BUTTON_LABEL_X;
+ break;
+ case SDL_GAMEPAD_BUTTON_WEST:
+ label = SDL_GAMEPAD_BUTTON_LABEL_B;
+ break;
+ case SDL_GAMEPAD_BUTTON_NORTH:
+ label = SDL_GAMEPAD_BUTTON_LABEL_Y;
+ break;
+ default:
+ break;
+ }
+ break;
case SDL_GAMEPAD_FACE_STYLE_BAYX:
switch (button) {
case SDL_GAMEPAD_BUTTON_SOUTH:
@@ -3778,6 +4358,11 @@ void SDL_QuitGamepads(void)
SDL_CloseGamepad(SDL_gamepads);
}
+ if (SDL_gamepad_names) {
+ SDL_DestroyHashTable(SDL_gamepad_names);
+ SDL_gamepad_names = NULL;
+ }
+
SDL_UnlockJoysticks();
}
diff --git a/thirdparty/sdl/joystick/SDL_gamepad_c.h b/thirdparty/sdl/joystick/SDL_gamepad_c.h
index f1b1d10e158..ff6574386ca 100644
--- a/thirdparty/sdl/joystick/SDL_gamepad_c.h
+++ b/thirdparty/sdl/joystick/SDL_gamepad_c.h
@@ -1,6 +1,6 @@
/*
Simple DirectMedia Layer
- Copyright (C) 1997-2025 Sam Lantinga <[email protected]>
+ Copyright (C) 1997-2026 Sam Lantinga <[email protected]>
This software is provided 'as-is', without any express or implied
warranty. In no event will the authors be held liable for any damages
diff --git a/thirdparty/sdl/joystick/SDL_gamepad_db.h b/thirdparty/sdl/joystick/SDL_gamepad_db.h
index d5c04384d72..ab7abf08a86 100644
--- a/thirdparty/sdl/joystick/SDL_gamepad_db.h
+++ b/thirdparty/sdl/joystick/SDL_gamepad_db.h
@@ -1,6 +1,6 @@
/*
Simple DirectMedia Layer
- Copyright (C) 1997-2025 Sam Lantinga <[email protected]>
+ Copyright (C) 1997-2026 Sam Lantinga <[email protected]>
This software is provided 'as-is', without any express or implied
warranty. In no event will the authors be held liable for any damages
@@ -46,6 +46,7 @@ static const char *s_GamepadMappings[] = {
#endif
#ifdef SDL_JOYSTICK_DINPUT
"03000000fa2d00000100000000000000,3DRUDDER,leftx:a0,lefty:a1,rightx:a5,righty:a2,",
+ "03000000c82d00001930000000000000,8BitDo 64 Bluetooth Controller,a:b0,b:b1,back:-a5,back:b10,dpdown:h0.4,dpleft:h0.8,dpright:h0.2,dpup:h0.1,guide:b12,leftshoulder:b6,leftstick:b13,lefttrigger:b8,leftx:a0,lefty:a2,misc1:b17,misc2:+a3,rightshoulder:b7,righttrigger:b9,start:b11,x:+a5,y:-a3,",
"03000000c82d00000090000000000000,8BitDo FC30 Pro,a:b1,b:b0,back:b10,dpdown:h0.4,dpleft:h0.8,dpright:h0.2,dpup:h0.1,leftshoulder:b6,leftstick:b13,lefttrigger:b8,leftx:a0,lefty:a1,rightshoulder:b7,rightstick:b14,righttrigger:b9,rightx:a3,righty:a4,start:b11,x:b4,y:b3,hint:!SDL_GAMECONTROLLER_USE_BUTTON_LABELS:=1,",
"03000000c82d00001038000000000000,8BitDo FC30 Pro,a:b1,b:b0,back:b10,dpdown:h0.4,dpleft:h0.8,dpright:h0.2,dpup:h0.1,leftshoulder:b6,leftstick:b13,lefttrigger:b8,leftx:a0,lefty:a1,rightshoulder:b7,rightstick:b14,righttrigger:b9,rightx:a3,righty:a4,start:b11,x:b4,y:b3,hint:!SDL_GAMECONTROLLER_USE_BUTTON_LABELS:=1,",
"03000000c82d00000650000000000000,8BitDo M30 Gamepad,a:b0,b:b1,back:b10,guide:b2,leftshoulder:b8,lefttrigger:b9,leftx:a0,lefty:a1,rightshoulder:b6,righttrigger:b7,start:b11,x:b3,y:b4,",
@@ -130,6 +131,7 @@ static const char *s_GamepadMappings[] = {
"03000000c01100000140000000000000,GameStop PS4 Fun Controller,a:b1,b:b2,back:b8,dpdown:h0.4,dpleft:h0.8,dpright:h0.2,dpup:h0.1,guide:b12,leftshoulder:b4,leftstick:b10,lefttrigger:a3,leftx:a0,lefty:a1,rightshoulder:b5,rightstick:b11,righttrigger:a4,rightx:a2,righty:a5,start:b9,x:b0,y:b3,",
"03000000260900002625000000000000,Gamecube Controller,a:b0,b:b1,dpdown:h0.4,dpleft:h0.8,dpright:h0.2,dpup:h0.1,guide:b6,lefttrigger:a4,leftx:a0,lefty:a1,righttrigger:a5,rightx:a2,righty:a3,start:b7,x:b2,y:b3,",
"03000000280400000140000000000000,Gamepad Pro USB,a:b1,b:b2,back:b8,leftshoulder:b4,lefttrigger:b6,leftx:a0,lefty:a1,rightshoulder:b5,righttrigger:b7,start:b9,x:b0,y:b3,",
+ "03000000ac0500007a05000000000000,Gamesir-G5,a:b16,b:b19,back:b10,dpdown:h0.4,dpleft:h0.8,dpright:h0.2,dpup:h0.1,guide:b12,leftshoulder:b6,leftstick:b13,lefttrigger:b8,leftx:a0,lefty:a1,misc2:b20,misc3:b21,misc4:b22,misc5:b23,paddle1:b25,paddle2:b24,paddle3:b27,paddle4:b26,rightshoulder:b7,righttrigger:b9,rightx:a3,righty:a4,start:b11,x:b17,y:b18,",
"030000005c1a00003330000000000000,Genius MaxFire Grandias 12V,a:b0,b:b1,back:b8,dpdown:h0.4,dpleft:h0.8,dpright:h0.2,dpup:h0.1,leftshoulder:b6,leftstick:b10,lefttrigger:b7,leftx:a0,lefty:a1,rightshoulder:b4,rightstick:b11,righttrigger:b5,rightx:a3,righty:a2,start:b9,x:b2,y:b3,",
"030000008305000031b0000000000000,Genius Maxfire Blaze 3,a:b0,b:b1,back:b8,dpdown:h0.4,dpleft:h0.8,dpright:h0.2,dpup:h0.1,leftshoulder:b4,leftstick:b10,lefttrigger:b6,leftx:a0,lefty:a1,rightshoulder:b5,rightstick:b11,righttrigger:b7,rightx:a2,righty:a3,start:b9,x:b2,y:b3,",
"03000000451300000010000000000000,Genius Maxfire Grandias 12,a:b0,b:b1,back:b8,dpdown:h0.4,dpleft:h0.8,dpright:h0.2,dpup:h0.1,leftshoulder:b4,leftstick:b10,lefttrigger:b6,leftx:a0,lefty:a1,rightshoulder:b5,rightstick:b11,righttrigger:b7,rightx:a2,righty:a3,start:b9,x:b2,y:b3,",
@@ -197,7 +199,7 @@ static const char *s_GamepadMappings[] = {
"03000000380700003888000000000000,Madcatz Arcade Fightstick TE S+ PS3,a:b1,b:b2,back:b8,dpdown:h0.4,dpleft:h0.8,dpright:h0.2,dpup:h0.1,guide:b12,leftshoulder:b4,lefttrigger:b6,leftx:a0,lefty:a1,rightshoulder:b5,righttrigger:b7,rightx:a2,righty:a3,start:b9,x:b0,y:b3,",
"030000002a0600001024000000000000,Matricom,a:b0,b:b1,back:b8,dpdown:h0.4,dpleft:h0.8,dpright:h0.2,dpup:h0.1,guide:b12,leftshoulder:b4,leftstick:b10,lefttrigger:b6,leftx:a0,lefty:a1,rightshoulder:b5,rightstick:b11,righttrigger:b7,rightx:a3,righty:a4,start:b9,x:b2,y:b3,",
"03000000250900000128000000000000,Mayflash Arcade Stick,a:b1,b:b2,back:b8,leftshoulder:b0,lefttrigger:b4,leftx:a0,lefty:a1,rightshoulder:b3,righttrigger:b7,start:b9,x:b5,y:b6,",
- "03000000790000004418000000000000,Mayflash GameCube Controller,a:b1,b:b2,dpdown:h0.4,dpleft:h0.8,dpright:h0.2,dpup:h0.1,lefttrigger:a3,leftx:a0,lefty:a1,rightshoulder:b7,righttrigger:a4,rightx:a5,righty:a2,start:b9,x:b0,y:b3,",
+ "030000008f0e00001330000000000000,Mayflash N64 Controller Adapter,crc:226d,a:b1,b:b2,back:b8,start:b9,leftshoulder:b6,rightshoulder:b7,dpup:h0.1,dpdown:h0.4,dpleft:h0.8,dpright:h0.2,leftx:a0,lefty:a1,rightx:a3~,righty:a2,",
"030000008f0e00001030000000000000,Mayflash USB Adapter for original Sega Saturn controller,a:b0,b:b1,dpdown:h0.4,dpleft:h0.8,dpright:h0.2,dpup:h0.1,leftshoulder:b6,lefttrigger:b5,rightshoulder:b2,righttrigger:b7,start:b9,x:b3,y:b4,",
"0300000025090000e803000000000000,Mayflash Wii Classic Controller,a:b1,b:b0,back:b8,dpdown:b13,dpleft:b12,dpright:b14,dpup:b11,guide:b10,leftshoulder:b4,lefttrigger:b6,leftx:a0,lefty:a1,rightshoulder:b5,righttrigger:b7,rightx:a2,righty:a3,start:b9,x:b3,y:b2,",
"03000000790000000018000000000000,Mayflash WiiU Pro Game Controller Adapter (DInput),a:b1,b:b2,back:b8,dpdown:h0.4,dpleft:h0.8,dpright:h0.2,dpup:h0.1,leftshoulder:b4,leftstick:b10,lefttrigger:b6,leftx:a0,lefty:a1,rightshoulder:b5,rightstick:b11,righttrigger:b7,rightx:a2,righty:a3,start:b9,x:b0,y:b3,",
@@ -207,7 +209,8 @@ static const char *s_GamepadMappings[] = {
"03000000152000000182000000000000,NGDS,a:b2,b:b1,back:b8,dpdown:h0.4,dpleft:h0.8,dpright:h0.2,dpup:h0.1,leftshoulder:b4,leftstick:b10,lefttrigger:b6,leftx:a0,lefty:a1,rightshoulder:b5,rightstick:b11,righttrigger:b7,rightx:a3,righty:a4,start:b9,x:b3,y:b0,",
"030000005509000000b4000000000000,NVIDIA Virtual Gamepad,a:b0,b:b1,back:b6,dpdown:h0.4,dpleft:h0.8,dpright:h0.2,dpup:h0.1,leftshoulder:b4,leftstick:b8,lefttrigger:+a2,leftx:a0,lefty:a1,rightshoulder:b5,rightstick:b9,righttrigger:-a2,rightx:a3,righty:a4,start:b7,x:b2,y:b3,",
"030000004b120000014d000000000000,NYKO AIRFLO EX,a:b0,b:b1,back:b8,dpdown:h0.4,dpleft:h0.8,dpright:h0.2,dpup:h0.1,guide:b10,leftshoulder:b4,leftstick:b11,lefttrigger:b6,leftx:a0,lefty:a1,rightshoulder:b5,rightstick:b12,righttrigger:b7,rightx:a3,righty:a2,start:b9,x:b2,y:b3,",
- "03000000790000004318000000000000,Nintendo GameCube Controller,a:b1,b:b0,dpdown:h0.4,dpleft:h0.8,dpright:h0.2,dpup:h0.1,lefttrigger:a3,leftx:a0,lefty:a1,rightshoulder:b7,righttrigger:a4,rightx:a5,righty:a2,start:b9,x:b2,y:b3,hint:!SDL_GAMECONTROLLER_USE_BUTTON_LABELS:=1,",
+ "03000000790000004318000000000000,Nintendo GameCube Controller,a:b1,b:b2,dpdown:h0.4,dpleft:h0.8,dpright:h0.2,dpup:h0.1,lefttrigger:a3,leftx:a0,lefty:a1,rightshoulder:b7,righttrigger:a4,rightx:a5,righty:a2,start:b9,x:b0,y:b3,",
+ "03000000790000004418000000000000,Nintendo GameCube Controller,a:b1,b:b2,dpdown:h0.4,dpleft:h0.8,dpright:h0.2,dpup:h0.1,lefttrigger:a3,leftx:a0,lefty:a1,rightshoulder:b7,righttrigger:a4,rightx:a5,righty:a2,start:b9,x:b0,y:b3,",
"03000000bd12000015d0000000000000,Nintendo Retrolink USB Super SNES Classic Controller,a:b2,b:b1,back:b8,leftshoulder:b4,leftx:a0,lefty:a1,rightshoulder:b5,start:b9,x:b3,y:b0,",
"030000007e0500000920000000000000,Nintendo Switch Pro Controller,a:b0,b:b1,back:b8,dpdown:h0.4,dpleft:h0.8,dpright:h0.2,dpup:h0.1,guide:b12,leftshoulder:b4,leftstick:b10,lefttrigger:b6,leftx:a0,lefty:a1,rightshoulder:b5,rightstick:b11,righttrigger:b7,rightx:a2,righty:a3,start:b9,x:b2,y:b3,hint:!SDL_GAMECONTROLLER_USE_BUTTON_LABELS:=1,",
"030000000d0500000308000000000000,Nostromo N45,a:b0,b:b1,back:b8,dpdown:h0.4,dpleft:h0.8,dpright:h0.2,dpup:h0.1,guide:b9,leftshoulder:b4,leftstick:b12,lefttrigger:b5,leftx:a0,lefty:a1,rightshoulder:b6,rightstick:b11,righttrigger:b7,rightx:a3,righty:a2,start:b10,x:b2,y:b3,",
@@ -229,7 +232,7 @@ static const char *s_GamepadMappings[] = {
"030000009d0d00001330000000000000,PS2 Controller,a:b0,b:b1,back:b8,dpdown:h0.4,dpleft:h0.8,dpright:h0.2,dpup:h0.1,leftshoulder:b4,leftstick:b10,lefttrigger:b5,leftx:a0,lefty:a1,rightshoulder:b6,rightstick:b11,righttrigger:b7,rightx:a2,righty:a3,start:b9,x:b2,y:b3,",
"03000000250900000500000000000000,PS3 Controller,a:b2,b:b1,back:b9,dpdown:h0.8,dpleft:h0.4,dpright:h0.2,dpup:h0.1,guide:,leftshoulder:b6,leftstick:b10,lefttrigger:b4,leftx:a0,lefty:a1,rightshoulder:b7,rightstick:b11,righttrigger:b5,rightx:a2,righty:a3,start:b8,x:b0,y:b3,",
"030000004c0500006802000000000000,PS3 Controller,a:b2,b:b1,back:b9,dpdown:h0.4,dpleft:h0.8,dpright:h0.2,dpup:h0.1,guide:b12,leftshoulder:b6,leftstick:b10,lefttrigger:a3~,leftx:a0,lefty:a1,rightshoulder:b7,rightstick:b11,righttrigger:a4~,rightx:a2,righty:a5,start:b8,x:b3,y:b0,",
- "03000000632500007505000000000000,PS3 Controller,a:b2,b:b1,back:b8,dpdown:h0.4,dpleft:h0.8,dpright:h0.2,dpup:h0.1,guide:b12,leftshoulder:b4,leftstick:b10,lefttrigger:b6,leftx:a0,lefty:a1,rightshoulder:b5,rightstick:b11,righttrigger:b7,rightx:a2,righty:a3,start:b9,x:b3,y:b0,",
+ "03000000632500007505000000000000,PS3 Controller,a:b1,b:b2,back:b8,dpdown:h0.4,dpleft:h0.8,dpright:h0.2,dpup:h0.1,guide:b12,leftshoulder:b4,leftstick:b10,lefttrigger:b6,leftx:a0,lefty:a1,rightshoulder:b5,rightstick:b11,righttrigger:b7,rightx:a2,righty:a3,start:b9,x:b0,y:b3,",
"03000000888800000803000000000000,PS3 Controller,a:b2,b:b1,back:b8,dpdown:h0.8,dpleft:h0.4,dpright:h0.2,dpup:h0.1,guide:b12,leftshoulder:b4,leftstick:b9,lefttrigger:b6,leftx:a0,lefty:a1,rightshoulder:b5,rightstick:b10,righttrigger:b7,rightx:a3,righty:a4,start:b11,x:b0,y:b3,",
"030000008f0e00001431000000000000,PS3 Controller,a:b1,b:b2,back:b8,dpdown:h0.4,dpleft:h0.8,dpright:h0.2,dpup:h0.1,guide:b12,leftshoulder:b4,leftstick:b10,lefttrigger:b6,leftx:a0,lefty:a1,rightshoulder:b5,rightstick:b11,righttrigger:b7,rightx:a2,righty:a3,start:b9,x:b0,y:b3,",
"030000003807000056a8000000000000,PS3 RF pad,a:b1,b:b2,back:b8,dpdown:h0.4,dpleft:h0.8,dpright:h0.2,dpup:h0.1,guide:b12,leftshoulder:b4,leftstick:b10,lefttrigger:b6,leftx:a0,lefty:a1,rightshoulder:b5,rightstick:b11,righttrigger:b7,rightx:a2,righty:a3,start:b9,x:b0,y:b3,",
@@ -242,6 +245,7 @@ static const char *s_GamepadMappings[] = {
"03000000d62000002640000000000000,PowerA OPS v1 Wireless Controller,a:b0,b:b1,back:b10,dpdown:h0.4,dpleft:h0.8,dpright:h0.2,dpup:h0.1,guide:b12,leftshoulder:b6,leftstick:b13,lefttrigger:b8,leftx:a0,lefty:a1,rightshoulder:b7,rightstick:b14,righttrigger:b9,rightx:a3,righty:a4,start:b11,x:b3,y:b4,",
"03000000d62000003340000000000000,PowerA OPS v3 Pro Wireless Controller,a:b0,b:b1,back:b10,dpdown:h0.4,dpleft:h0.8,dpright:h0.2,dpup:h0.1,guide:b12,leftshoulder:b6,leftstick:b13,lefttrigger:b8,leftx:a0,lefty:a1,rightshoulder:b7,rightstick:b14,righttrigger:b9,rightx:a3,righty:a4,start:b11,x:b3,y:b4,",
"03000000d62000006dca000000000000,PowerA Pro Ex,a:b1,b:b2,back:b8,dpdown:h0.4,dpleft:h0.8,dpright:h0.2,dpup:h0.1,guide:b12,leftshoulder:b4,leftstick:b10,lefttrigger:b6,leftx:a0,lefty:a1,rightshoulder:b5,rightstick:b11,righttrigger:b7,rightx:a2,righty:a3,start:b9,x:b0,y:b3,",
+ "03000000d620000011a7000000000000,PowerA Wired GameCube Controller,a:b1,b:b2,back:b8,dpdown:h0.4,dpleft:h0.8,dpright:h0.2,dpup:h0.1,guide:b12,leftshoulder:b4,leftstick:b10,lefttrigger:b6,leftx:a0,lefty:a1,rightshoulder:b5,rightstick:b11,righttrigger:b7,rightx:a2,righty:a3,start:b9,x:b0,y:b3,",
"03000000d62000009557000000000000,Pro Elite PS3 Controller,a:b1,b:b2,back:b8,dpdown:h0.4,dpleft:h0.8,dpright:h0.2,dpup:h0.1,guide:b12,leftshoulder:b4,leftstick:b10,lefttrigger:b6,leftx:a0,lefty:a1,rightshoulder:b5,rightstick:b11,righttrigger:b7,rightx:a2,righty:a3,start:b9,x:b0,y:b3,",
"03000000d62000009f31000000000000,Pro Ex mini PS3 Controller,a:b1,b:b2,back:b8,dpdown:h0.4,dpleft:h0.8,dpright:h0.2,dpup:h0.1,guide:b12,leftshoulder:b4,leftstick:b10,lefttrigger:b6,leftx:a0,lefty:a1,rightshoulder:b5,rightstick:b11,righttrigger:b7,rightx:a2,righty:a3,start:b9,x:b0,y:b3,",
"03000000d6200000c757000000000000,Pro Ex mini PS3 Controller,a:b1,b:b2,back:b8,dpdown:h0.4,dpleft:h0.8,dpright:h0.2,dpup:h0.1,guide:b12,leftshoulder:b4,leftstick:b10,lefttrigger:b6,leftx:a0,lefty:a1,rightshoulder:b5,rightstick:b11,righttrigger:b7,rightx:a2,righty:a3,start:b9,x:b0,y:b3,",
@@ -276,6 +280,7 @@ static const char *s_GamepadMappings[] = {
"030000000d0f00008b00000000000000,Real Arcade Pro.4,a:b1,b:b2,back:b8,dpdown:h0.4,dpleft:h0.8,dpright:h0.2,dpup:h0.1,guide:b12,leftshoulder:b4,leftstick:b10,lefttrigger:b6,leftx:a0,lefty:a1,rightshoulder:b5,rightstick:b11,righttrigger:b7,rightx:a2,righty:a3,start:b9,x:b0,y:b3,",
"030000000d0f00005b00000000000000,Real Arcade Pro.V4,a:b1,b:b2,back:b8,dpdown:h0.4,dpleft:h0.8,dpright:h0.2,dpup:h0.1,guide:b12,leftshoulder:b4,leftstick:b10,lefttrigger:b6,leftx:a0,lefty:a1,rightshoulder:b5,rightstick:b11,righttrigger:b7,rightx:a2,righty:a5,start:b9,x:b0,y:b3,",
"030000000d0f00005c00000000000000,Real Arcade Pro.V4,a:b1,b:b2,back:b8,dpdown:h0.4,dpleft:h0.8,dpright:h0.2,dpup:h0.1,guide:b12,leftshoulder:b4,leftstick:b10,lefttrigger:b6,leftx:a0,lefty:a1,rightshoulder:b5,rightstick:b11,righttrigger:b7,rightx:a2,righty:a3,start:b9,x:b0,y:b3,",
+ "03000000632500007805000000000000,Retro Fighters D6,a:b2,b:b1,back:b8,dpdown:h0.4,dpleft:h0.8,dpright:h0.2,dpup:h0.1,guide:b12,leftshoulder:b4,misc1:b10,lefttrigger:b6,leftx:a0,lefty:a1,rightshoulder:b5,rightstick:b11,righttrigger:b7,rightx:a2,righty:a3,start:b9,x:b3,y:b0,",
"0300000000f000000300000000000000,RetroUSB.com RetroPad,a:b1,b:b5,back:b2,leftshoulder:b6,leftx:a0,lefty:a1,rightshoulder:b7,start:b3,x:b0,y:b4,",
"0300000000f00000f100000000000000,RetroUSB.com Super RetroPort,a:b1,b:b5,back:b2,leftshoulder:b6,leftx:a0,lefty:a1,rightshoulder:b7,start:b3,x:b0,y:b4,",
"03000000790000001100000000000000,Retrolink SNES Controller,a:b2,b:b1,back:b8,dpdown:+a4,dpleft:-a3,dpright:+a3,dpup:-a4,leftshoulder:b4,rightshoulder:b5,start:b9,x:b3,y:b0,hint:!SDL_GAMECONTROLLER_USE_BUTTON_LABELS:=1,",
@@ -310,7 +315,6 @@ static const char *s_GamepadMappings[] = {
"03000000110100003114000000000000,SteelSeries Stratus Duo,a:b0,b:b1,back:b10,dpdown:h0.4,dpleft:h0.8,dpright:h0.2,dpup:h0.1,leftshoulder:b6,leftstick:b13,lefttrigger:b8,leftx:a0,lefty:a1,rightshoulder:b7,rightstick:b14,righttrigger:b9,rightx:a3,righty:a4,start:b11,x:b3,y:b4,",
"03000000381000001814000000000000,SteelSeries Stratus XL,a:b0,b:b1,back:b18,dpdown:b13,dpleft:b14,dpright:b15,dpup:b12,guide:b19,leftshoulder:b4,leftstick:b10,lefttrigger:a3,leftx:a0,lefty:a1,rightshoulder:b5,rightstick:b11,righttrigger:a4,rightx:a2,righty:a5,start:b9,x:b2,y:b3,",
"03000000110100001914000000000000,SteelSeries,a:b0,b:b1,dpdown:h0.4,dpleft:h0.8,dpright:h0.2,dpup:h0.1,leftshoulder:,leftstick:b13,lefttrigger:b6,leftx:a0,lefty:a1,rightshoulder:,rightstick:b14,righttrigger:b7,rightx:a3,righty:a4,start:b11,x:b3,y:b4,",
- "03000000d620000011a7000000000000,Switch,a:b1,b:b2,back:b8,dpdown:h0.4,dpleft:h0.8,dpright:h0.2,dpup:h0.1,guide:b12,leftshoulder:b4,leftstick:b10,lefttrigger:b6,leftx:a0,lefty:a1,rightshoulder:b5,rightstick:b11,righttrigger:b7,rightx:a2,righty:a3,start:b9,x:b0,y:b3,",
"030000004f04000007d0000000000000,T Mini Wireless,a:b1,b:b2,back:b8,dpdown:h0.4,dpleft:h0.8,dpright:h0.2,dpup:h0.1,guide:b12,leftshoulder:b4,leftstick:b10,lefttrigger:b6,leftx:a0,lefty:a1,rightshoulder:b5,rightstick:b11,righttrigger:b7,rightx:a2,righty:a3,start:b9,x:b0,y:b3,",
"03000000fa1900000706000000000000,Team 5,a:b2,b:b1,back:b8,dpdown:h0.4,dpleft:h0.8,dpright:h0.2,dpup:h0.1,leftshoulder:b4,leftstick:b10,lefttrigger:b6,leftx:a0,lefty:a1,rightshoulder:b5,rightstick:b11,righttrigger:b7,rightx:a2,righty:a3,start:b9,x:b3,y:b0,",
"03000000b50700001203000000000000,Techmobility X6-38V,a:b2,b:b3,back:b8,dpdown:h0.4,dpleft:h0.8,dpright:h0.2,dpup:h0.1,leftshoulder:b4,leftstick:b10,lefttrigger:b5,leftx:a0,lefty:a1,rightshoulder:b6,rightstick:b11,righttrigger:b7,rightx:a3,righty:a2,start:b9,x:b0,y:b1,",
@@ -334,6 +338,8 @@ static const char *s_GamepadMappings[] = {
"03000000790000001b18000000000000,Venom Arcade Joystick,a:b1,b:b2,back:b8,dpdown:h0.4,dpleft:h0.8,dpright:h0.2,dpup:h0.1,guide:b12,leftshoulder:b4,lefttrigger:b6,rightshoulder:b5,righttrigger:b7,start:b9,x:b0,y:b3,",
"030000006f0e00000302000000000000,Victrix Pro Fight Stick for PS4,a:b1,b:b2,back:b8,dpdown:h0.4,dpleft:h0.8,dpright:h0.2,dpup:h0.1,guide:b12,leftshoulder:b4,lefttrigger:b6,rightshoulder:b5,righttrigger:b7,start:b9,x:b0,y:b3,",
"030000006f0e00000702000000000000,Victrix Pro Fight Stick for PS4,a:b1,b:b2,back:b8,dpdown:h0.4,dpleft:h0.8,dpright:h0.2,dpup:h0.1,guide:b12,leftshoulder:b4,leftstick:b10,lefttrigger:b6,rightshoulder:b5,righttrigger:b7,start:b9,x:b0,y:b3,",
+ "03000000d23800001010000000000000,Void Gaming Void GENESIS,a:b0,b:b1,back:b16,dpdown:h0.4,dpleft:h0.8,dpright:h0.2,dpup:h0.1,guide:b6,leftshoulder:b2,leftstick:b9,lefttrigger:a3,leftx:a0,lefty:a1,misc1:b18,misc2:b21,misc3:b20,paddle1:b22,paddle2:b15,paddle3:b23,paddle4:b17,rightshoulder:b5,rightstick:b10,righttrigger:a4,rightx:a2,righty:a5,start:b19,x:b3,y:b4,",
+ "03000000d23800001210000000000000,Void Gaming Void GENESIS,a:b0,b:b1,back:b16,dpdown:h0.4,dpleft:h0.8,dpright:h0.2,dpup:h0.1,guide:b6,leftshoulder:b2,leftstick:b9,lefttrigger:a3,leftx:a0,lefty:a1,misc1:b18,misc2:b21,misc3:b20,paddle1:b22,paddle2:b15,paddle3:b23,paddle4:b17,rightshoulder:b5,rightstick:b10,righttrigger:a4,rightx:a2,righty:a5,start:b19,x:b3,y:b4,",
"03000000450c00002043000000000000,XEOX Gamepad SL-6556-BK,a:b0,b:b1,back:b8,dpdown:h0.4,dpleft:h0.8,dpright:h0.2,dpup:h0.1,leftshoulder:b4,leftstick:b10,lefttrigger:b6,leftx:a0,lefty:a1,rightshoulder:b5,rightstick:b11,righttrigger:b7,rightx:a2,righty:a3,start:b9,x:b2,y:b3,",
"03000000341a00000608000000000000,Xeox,a:b0,b:b1,back:b8,dpdown:h0.4,dpleft:h0.8,dpright:h0.2,dpup:h0.1,guide:b12,leftshoulder:b4,leftstick:b10,lefttrigger:b6,leftx:a0,lefty:a1,rightshoulder:b5,rightstick:b11,righttrigger:b7,rightx:a2,righty:a3,start:b9,x:b2,y:b3,",
"03000000172700004431000000000000,XiaoMi Game Controller,a:b0,b:b1,back:b10,dpdown:h0.4,dpleft:h0.8,dpright:h0.2,dpup:h0.1,guide:b20,leftshoulder:b6,leftstick:b13,lefttrigger:b8,leftx:a0,lefty:a1,rightshoulder:b7,rightstick:b14,righttrigger:a7,rightx:a2,righty:a5,start:b11,x:b3,y:b4,",
@@ -348,6 +354,7 @@ static const char *s_GamepadMappings[] = {
"03000000101c0000171c000000000000,uRage Gamepad,a:b2,b:b1,back:b8,dpdown:h0.4,dpleft:h0.8,dpright:h0.2,dpup:h0.1,leftshoulder:b4,leftstick:b10,lefttrigger:b6,leftx:a0,lefty:a1,rightshoulder:b5,rightstick:b11,righttrigger:b7,rightx:a2,righty:a3,start:b9,x:b3,y:b0,",
#endif
#ifdef SDL_PLATFORM_MACOS
+ "03000000c82d00001930000000000000,8BitDo 64 Bluetooth Controller,a:b0,b:b1,back:-a3,dpdown:h0.4,dpleft:h0.8,dpright:h0.2,dpup:h0.1,guide:b12,leftshoulder:b6,leftstick:b13,lefttrigger:b8,leftx:a0,lefty:a1,misc1:b17,misc2:+a2,misc3:b10,rightshoulder:b7,righttrigger:b9,start:b11,x:+a3,y:-a2,",
"03000000c82d00000090000001000000,8BitDo FC30 Pro,a:b1,b:b0,back:b10,dpdown:h0.4,dpleft:h0.8,dpright:h0.2,dpup:h0.1,leftshoulder:b6,leftstick:b13,lefttrigger:a4,leftx:a0,lefty:a1,rightshoulder:b7,rightstick:b14,righttrigger:a5,rightx:a2,righty:a3,start:b11,x:b4,y:b3,hint:!SDL_GAMECONTROLLER_USE_BUTTON_LABELS:=1,",
"03000000c82d00001038000000010000,8BitDo FC30 Pro,a:b1,b:b0,back:b10,dpdown:h0.4,dpleft:h0.8,dpright:h0.2,dpup:h0.1,leftshoulder:b6,leftstick:b13,lefttrigger:a5,leftx:a0,lefty:a1,rightshoulder:b7,rightstick:b14,righttrigger:a4,rightx:a2,righty:a3,start:b11,x:b4,y:b3,hint:!SDL_GAMECONTROLLER_USE_BUTTON_LABELS:=1,",
"03000000c82d00000650000001000000,8BitDo M30 Gamepad,a:b1,b:b0,back:b10,guide:b2,leftshoulder:b6,lefttrigger:a4,leftx:a0,lefty:a1,rightshoulder:b7,righttrigger:a5,start:b11,x:b4,y:b3,hint:!SDL_GAMECONTROLLER_USE_BUTTON_LABELS:=1,",
@@ -414,13 +421,13 @@ static const char *s_GamepadMappings[] = {
"03000000380700005082000000010000,Mad Catz FightPad PRO (PS4),a:b1,b:b2,back:b8,dpdown:h0.4,dpleft:h0.8,dpright:h0.2,dpup:h0.1,guide:b12,leftshoulder:b4,leftstick:b10,lefttrigger:a3,leftx:a0,lefty:a1,rightshoulder:b5,rightstick:b11,righttrigger:a4,rightx:a2,righty:a5,start:b9,x:b0,y:b3,",
"03000000380700008433000000010000,Mad Catz FightStick TE S+ (PS3),a:b1,b:b2,back:b8,dpdown:h0.4,dpleft:h0.8,dpright:h0.2,dpup:h0.1,guide:b12,leftshoulder:b4,leftstick:b10,lefttrigger:b6,leftx:a0,lefty:a1,rightshoulder:b5,rightstick:b11,righttrigger:b7,rightx:a2,righty:a3,start:b9,x:b0,y:b3,",
"03000000380700008483000000010000,Mad Catz FightStick TE S+ (PS4),a:b1,b:b2,back:b8,dpdown:h0.4,dpleft:h0.8,dpright:h0.2,dpup:h0.1,guide:b12,leftshoulder:b4,leftstick:b10,lefttrigger:a3,leftx:a0,lefty:a1,rightshoulder:b5,rightstick:b11,righttrigger:a4,rightx:a2,righty:a5,start:b9,x:b0,y:b3,",
- "03000000790000004418000000010000,Mayflash GameCube Controller,a:b1,b:b2,dpdown:b14,dpleft:b15,dpright:b13,dpup:b12,lefttrigger:a3,leftx:a0,lefty:a1,rightshoulder:b7,righttrigger:a4,rightx:a5,righty:a2,start:b9,x:b0,y:b3,",
"0300000025090000e803000000000000,Mayflash Wii Classic Controller,a:b1,b:b0,back:b8,dpdown:b13,dpleft:b12,dpright:b14,dpup:b11,guide:b10,leftshoulder:b4,lefttrigger:b6,leftx:a0,lefty:a1,rightshoulder:b5,righttrigger:b7,rightx:a2,righty:a3,start:b9,x:b3,y:b2,",
"03000000790000000018000000000000,Mayflash WiiU Pro Game Controller Adapter (DInput),a:b4,b:b8,back:b32,dpdown:h0.4,dpleft:h0.8,dpright:h0.2,dpup:h0.1,leftshoulder:b16,leftstick:b40,lefttrigger:b24,leftx:a0,lefty:a4,rightshoulder:b20,rightstick:b44,righttrigger:b28,rightx:a8,righty:a12,start:b36,x:b0,y:b12,",
"03000000853200008906000000010000,NACON Revolution X Unlimited,a:b0,b:b1,back:b10,dpdown:h0.4,dpleft:h0.8,dpright:h0.2,dpup:h0.1,guide:b12,leftshoulder:b6,leftstick:b13,lefttrigger:a5,leftx:a0,lefty:a1,rightshoulder:b7,rightstick:b14,righttrigger:a4,rightx:a2,righty:a3,start:b11,x:b3,y:b4,",
"030000001008000001e5000006010000,NEXT SNES Controller,a:b2,b:b1,back:b8,dpdown:+a1,dpleft:-a0,dpright:+a0,dpup:-a1,leftshoulder:b4,rightshoulder:b6,start:b9,x:b3,y:b0,",
"03000000550900001472000025050000,NVIDIA Controller v01.04,a:b0,b:b1,back:b17,dpdown:h0.4,dpleft:h0.8,dpright:h0.2,dpup:h0.1,guide:b15,leftshoulder:b4,leftstick:b7,lefttrigger:a3,leftx:a0,lefty:a1,rightshoulder:b5,rightstick:b8,righttrigger:a4,rightx:a2,righty:a5,start:b6,x:b2,y:b3,",
"030000004b120000014d000000010000,NYKO AIRFLO EX,a:b0,b:b1,back:b8,dpdown:h0.4,dpleft:h0.8,dpright:h0.2,dpup:h0.1,guide:b10,leftshoulder:b4,leftstick:b11,lefttrigger:b6,leftx:a0,lefty:a1,rightshoulder:b5,rightstick:b12,righttrigger:b7,rightx:a3,righty:a2,start:b9,x:b2,y:b3,",
+ "03000000790000004418000000010000,Nintendo GameCube Controller,a:b1,b:b2,dpdown:b14,dpleft:b15,dpright:b13,dpup:b12,lefttrigger:a3,leftx:a0,lefty:a1,rightshoulder:b7,righttrigger:a4,rightx:a5,righty:a2,start:b9,x:b0,y:b3,",
"030000007e0500000920000000000000,Nintendo Switch Pro Controller,a:b0,b:b1,back:b8,dpdown:h0.4,dpleft:h0.8,dpright:h0.2,dpup:h0.1,guide:b12,leftshoulder:b4,leftstick:b10,lefttrigger:b6,leftx:a0,lefty:a1,rightshoulder:b5,rightstick:b11,righttrigger:b7,rightx:a2,righty:a3,start:b9,x:b2,y:b3,",
"050000007e05000009200000ff070000,Nintendo Switch Pro Controller,a:b1,b:b0,back:b8,dpdown:h0.4,dpleft:h0.8,dpright:h0.2,dpup:h0.1,guide:b9,leftshoulder:b4,leftstick:b6,lefttrigger:a2,leftx:a0,lefty:a1,rightshoulder:b5,rightstick:b7,righttrigger:a5,rightx:a3,righty:a4,start:b10,x:b3,y:b2,hint:!SDL_GAMECONTROLLER_USE_BUTTON_LABELS:=1,",
"0300000009120000072f000000010000,OrangeFox86 DreamPicoPort,a:b0,b:b1,dpdown:h0.4,dpleft:h0.8,dpright:h0.2,dpup:h0.1,lefttrigger:a2,leftx:a0,lefty:a1,righttrigger:a5,rightx:a3,righty:a4,start:b11,x:b3,y:b4,",
@@ -452,7 +459,6 @@ static const char *s_GamepadMappings[] = {
"03000000811700007e05000000000000,Sega Saturn,a:b2,b:b4,dpdown:b16,dpleft:b15,dpright:b14,dpup:b17,leftshoulder:b8,lefttrigger:a5,leftx:a0,lefty:a2,rightshoulder:b9,righttrigger:a4,start:b13,x:b0,y:b6,",
"030000004c050000cc09000000000000,Sony DualShock 4 V2,a:b1,b:b2,back:b13,dpdown:h0.4,dpleft:h0.8,dpright:h0.2,dpup:h0.1,guide:b12,leftshoulder:b4,leftstick:b10,lefttrigger:a3,leftx:a0,lefty:a1,rightshoulder:b5,rightstick:b11,righttrigger:a4,rightx:a2,righty:a5,start:b9,x:b0,y:b3,",
"030000004c050000a00b000000000000,Sony DualShock 4 Wireless Adaptor,a:b1,b:b2,back:b13,dpdown:h0.4,dpleft:h0.8,dpright:h0.2,dpup:h0.1,guide:b12,leftshoulder:b4,leftstick:b10,lefttrigger:a3,leftx:a0,lefty:a1,rightshoulder:b5,rightstick:b11,righttrigger:a4,rightx:a2,righty:a5,start:b9,x:b0,y:b3,",
- "030000005e0400008e02000001000000,Steam Virtual Gamepad,a:b0,b:b1,back:b9,dpdown:b12,dpleft:b13,dpright:b14,dpup:b11,leftshoulder:b4,leftstick:b6,lefttrigger:a2,leftx:a0,lefty:a1,rightshoulder:b5,rightstick:b7,righttrigger:a5,rightx:a3,righty:a4,start:b8,x:b2,y:b3,",
"050000004e696d6275732b0000000000,SteelSeries Nimbus+,a:b0,b:b1,back:b15,dpdown:b11,dpleft:b13,dpright:b12,dpup:b10,guide:b16,leftshoulder:b4,leftstick:b8,lefttrigger:b6,leftx:a0,lefty:a1~,rightshoulder:b5,rightstick:b9,righttrigger:b7,rightx:a2,righty:a3~,start:b14,x:b2,y:b3,",
"03000000110100002014000000000000,SteelSeries Nimbus,a:b0,b:b1,dpdown:b9,dpleft:b11,dpright:b10,dpup:b8,leftshoulder:b4,lefttrigger:b6,leftx:a0,lefty:a1,rightshoulder:b5,righttrigger:b7,rightx:a2,righty:a3,start:b12,x:b2,y:b3,",
"03000000110100002014000001000000,SteelSeries Nimbus,a:b0,b:b1,dpdown:b9,dpleft:b11,dpright:b10,dpup:b8,guide:b12,leftshoulder:b4,lefttrigger:b6,leftx:a0,lefty:a1~,rightshoulder:b5,righttrigger:b7,rightx:a2,righty:a3~,x:b2,y:b3,",
@@ -469,7 +475,7 @@ static const char *s_GamepadMappings[] = {
"030000006f0e00000702000003060000,Victrix Pro Fight Stick for PS4,a:b1,b:b2,back:b8,dpdown:h0.4,dpleft:h0.8,dpright:h0.2,dpup:h0.1,guide:b12,leftshoulder:b4,leftstick:b10,lefttrigger:b6,rightshoulder:b5,righttrigger:b7,start:b9,x:b0,y:b3,",
"050000005769696d6f74652028303000,Wii Remote,a:b4,b:b5,back:b7,dpdown:b3,dpleft:b0,dpright:b1,dpup:b2,guide:b8,leftshoulder:b11,lefttrigger:b12,leftx:a0,lefty:a1,start:b6,x:b10,y:b9,",
"050000005769696d6f74652028313800,Wii U Pro Controller,a:b16,b:b15,back:b7,dpdown:b12,dpleft:b13,dpright:b14,dpup:b11,guide:b8,leftshoulder:b19,leftstick:b23,lefttrigger:b21,leftx:a0,lefty:a1,rightshoulder:b20,rightstick:b24,righttrigger:b22,rightx:a2,righty:a3,start:b6,x:b18,y:b17,",
- "030000005e0400008e02000000000000,X360 Controller,a:b0,b:b1,back:b9,dpdown:b12,dpleft:b13,dpright:b14,dpup:b11,guide:b10,leftshoulder:b4,leftstick:b6,lefttrigger:a2,leftx:a0,lefty:a1,rightshoulder:b5,rightstick:b7,righttrigger:a5,rightx:a3,righty:a4,start:b8,x:b2,y:b3,",
+ "030000005e0400008e02000014010000,Xbox 360 Controller,a:b0,b:b1,back:b9,dpdown:b12,dpleft:b13,dpright:b14,dpup:b11,guide:b10,leftshoulder:b4,leftstick:b6,lefttrigger:+a2,leftx:a0,lefty:a1~,rightshoulder:b5,rightstick:b7,righttrigger:a5,rightx:a3,righty:a4~,start:b8,x:b2,y:b3,",
"03000000c6240000045d000000000000,Xbox 360 Wired Controller,a:b0,b:b1,back:b9,dpdown:b12,dpleft:b13,dpright:b14,dpup:b11,guide:b10,leftshoulder:b4,leftstick:b6,lefttrigger:a2,leftx:a0,lefty:a1,rightshoulder:b5,rightstick:b7,righttrigger:a5,rightx:a3,righty:a4,start:b8,x:b2,y:b3,",
"030000005e040000050b000003090000,Xbox Elite Wireless Controller,a:b0,b:b1,back:b38,dpdown:h0.4,dpleft:h0.8,dpright:h0.2,dpup:h0.1,guide:b12,leftshoulder:b6,leftstick:b13,lefttrigger:a5,leftx:a0,lefty:a1,rightshoulder:b7,rightstick:b14,righttrigger:a4,rightx:a2,righty:a3,start:b11,x:b3,y:b4,",
"030000005e040000d102000000000000,Xbox One Wired Controller,a:b0,b:b1,back:b9,dpdown:b12,dpleft:b13,dpright:b14,dpup:b11,guide:b10,leftshoulder:b4,leftstick:b6,lefttrigger:a2,leftx:a0,lefty:a1,rightshoulder:b5,rightstick:b7,righttrigger:a5,rightx:a3,righty:a4,start:b8,x:b2,y:b3,",
@@ -489,6 +495,8 @@ static const char *s_GamepadMappings[] = {
"03000000830500006020000000000000,iBuffalo USB 2-axis 8-button Gamepad,a:b1,b:b0,back:b6,leftshoulder:b4,leftx:a0,lefty:a1,rightshoulder:b5,start:b7,x:b3,y:b2,",
#endif
#if defined(SDL_JOYSTICK_LINUX) || defined(SDL_PLATFORM_OPENBSD)
+ "03000000c82d00001930000011010000,8BitDo 64 Bluetooth Controller,a:b0,b:b1,back:-a3,dpdown:h0.4,dpleft:h0.8,dpright:h0.2,dpup:h0.1,guide:b12,leftshoulder:b6,leftstick:b13,lefttrigger:a5,leftx:a0,lefty:a1,misc1:b17,misc2:+a2,misc3:b10,rightshoulder:b7,righttrigger:a4,start:b11,x:+a3,y:-a2,",
+ "05000000c82d00001930000001000000,8BitDo 64 Bluetooth Controller,a:b0,b:b1,back:-a3,dpdown:h0.4,dpleft:h0.8,dpright:h0.2,dpup:h0.1,guide:b12,leftshoulder:b6,leftstick:b13,lefttrigger:a5,leftx:a0,lefty:a1,misc1:b17,misc2:+a2,misc3:b10,rightshoulder:b7,righttrigger:a4,start:b11,x:+a3,y:-a2,",
"03000000c82d00000090000011010000,8BitDo FC30 Pro,a:b1,b:b0,back:b10,dpdown:h0.4,dpleft:h0.8,dpright:h0.2,dpup:h0.1,leftshoulder:b6,leftstick:b13,lefttrigger:a4,leftx:a0,lefty:a1,rightshoulder:b7,rightstick:b14,righttrigger:a5,rightx:a2,righty:a3,start:b11,x:b4,y:b3,hint:!SDL_GAMECONTROLLER_USE_BUTTON_LABELS:=1,",
"05000000c82d00001038000000010000,8BitDo FC30 Pro,a:b1,b:b0,back:b10,dpdown:h0.4,dpleft:h0.8,dpright:h0.2,dpup:h0.1,leftshoulder:b6,leftstick:b13,lefttrigger:a5,leftx:a0,lefty:a1,rightshoulder:b7,rightstick:b14,righttrigger:a4,rightx:a2,righty:a3,start:b11,x:b4,y:b3,hint:!SDL_GAMECONTROLLER_USE_BUTTON_LABELS:=1,",
"05000000c82d00005106000000010000,8BitDo M30 Gamepad,a:b1,b:b0,back:b10,guide:b2,leftshoulder:b6,lefttrigger:a5,leftx:a0,lefty:a1,rightshoulder:b7,righttrigger:a4,start:b11,x:b4,y:b3,hint:!SDL_GAMECONTROLLER_USE_BUTTON_LABELS:=1,",
@@ -500,8 +508,6 @@ static const char *s_GamepadMappings[] = {
"03000000c82d00000190000011010000,8BitDo NES30 Pro,a:b1,b:b0,back:b10,dpdown:h0.4,dpleft:h0.8,dpright:h0.2,dpup:h0.1,leftshoulder:b6,leftstick:b13,lefttrigger:a4,leftx:a0,lefty:a1,rightshoulder:b7,rightstick:b14,righttrigger:a5,rightx:a2,righty:a3,start:b11,x:b4,y:b3,hint:!SDL_GAMECONTROLLER_USE_BUTTON_LABELS:=1,",
"05000000203800000900000000010000,8BitDo NES30 Pro,a:b1,b:b0,back:b10,dpdown:h0.4,dpleft:h0.8,dpright:h0.2,dpup:h0.1,leftshoulder:b6,leftstick:b13,lefttrigger:b8,leftx:a0,lefty:a1,rightshoulder:b7,rightstick:b14,righttrigger:b9,rightx:a2,righty:a3,start:b11,x:b4,y:b3,hint:!SDL_GAMECONTROLLER_USE_BUTTON_LABELS:=1,",
"05000000c82d00002038000000010000,8BitDo NES30 Pro,a:b1,b:b0,back:b10,dpdown:h0.4,dpleft:h0.8,dpright:h0.2,dpup:h0.1,guide:b2,leftshoulder:b6,leftstick:b13,lefttrigger:a5,leftx:a0,lefty:a1,rightshoulder:b7,rightstick:b14,righttrigger:a4,rightx:a2,righty:a3,start:b11,x:b4,y:b3,hint:!SDL_GAMECONTROLLER_USE_BUTTON_LABELS:=1,",
- "03000000c82d00000020000000000000,8BitDo Pro 2 Wired Controller for Xbox,a:b0,b:b1,back:b6,dpdown:h0.4,dpleft:h0.8,dpright:h0.2,dpup:h0.1,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,",
- "06000000c82d00000020000006010000,8BitDo Pro 2 Wired Controller for Xbox,a:b0,b:b1,back:b6,dpdown:h0.4,dpleft:h0.8,dpright:h0.2,dpup:h0.1,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,",
"03000000c82d00000660000011010000,8BitDo Pro 2,a:b1,b:b0,back:b10,dpdown:h0.4,dpleft:h0.8,dpright:h0.2,dpup:h0.1,guide:b12,leftshoulder:b6,leftstick:b13,lefttrigger:a5,leftx:a0,lefty:a1,rightshoulder:b7,rightstick:b14,righttrigger:a4,rightx:a2,righty:a3,start:b11,x:b4,y:b3,hint:!SDL_GAMECONTROLLER_USE_BUTTON_LABELS:=1,",
"05000000c82d00000660000000010000,8BitDo Pro 2,a:b1,b:b0,back:b10,dpdown:h0.4,dpleft:h0.8,dpright:h0.2,dpup:h0.1,guide:b12,leftshoulder:b6,leftstick:b13,lefttrigger:a5,leftx:a0,lefty:a1,rightshoulder:b7,rightstick:b14,righttrigger:a4,rightx:a2,righty:a3,start:b11,x:b4,y:b3,hint:!SDL_GAMECONTROLLER_USE_BUTTON_LABELS:=1,",
"03000000c82d00000960000011010000,8BitDo Pro 3,a:b1,b:b0,back:b10,dpdown:h0.4,dpleft:h0.8,dpright:h0.2,dpup:h0.1,guide:b12,leftshoulder:b6,leftstick:b13,lefttrigger:a5,leftx:a0,lefty:a1,paddle1:b17,paddle2:b16,paddle3:b2,paddle4:b5,rightshoulder:b7,rightstick:b14,righttrigger:a4,rightx:a2,righty:a3,start:b11,x:b4,y:b3,hint:!SDL_GAMECONTROLLER_USE_BUTTON_LABELS:=1,",
@@ -510,7 +516,6 @@ static const char *s_GamepadMappings[] = {
"05000000c82d00003028000000010000,8BitDo SFC30 Gamepad,a:b1,b:b0,back:b10,leftshoulder:b6,leftx:a0,lefty:a1,rightshoulder:b7,start:b11,x:b4,y:b3,hint:!SDL_GAMECONTROLLER_USE_BUTTON_LABELS:=1,",
"03000000c82d00000260000011010000,8BitDo SN30 Pro+,a:b1,b:b0,back:b10,dpdown:h0.4,dpleft:h0.8,dpright:h0.2,dpup:h0.1,guide:b2,leftshoulder:b6,leftstick:b13,lefttrigger:b8,leftx:a0,lefty:a1,rightshoulder:b7,rightstick:b14,righttrigger:b9,rightx:a2,righty:a3,start:b11,x:b4,y:b3,hint:!SDL_GAMECONTROLLER_USE_BUTTON_LABELS:=1,",
"05000000c82d00000261000000010000,8BitDo SN30 Pro+,a:b1,b:b0,back:b10,dpdown:h0.4,dpleft:h0.8,dpright:h0.2,dpup:h0.1,guide:b2,leftshoulder:b6,leftstick:b13,lefttrigger:b8,leftx:a0,lefty:a1,rightshoulder:b7,rightstick:b14,righttrigger:b9,rightx:a2,righty:a3,start:b11,x:b4,y:b3,hint:!SDL_GAMECONTROLLER_USE_BUTTON_LABELS:=1,",
- "03000000c82d00000160000011010000,8BitDo SN30 Pro,a:b1,b:b0,back:b10,dpdown:h0.4,dpleft:h0.8,dpright:h0.2,dpup:h0.1,leftshoulder:b6,leftstick:b13,lefttrigger:a4,leftx:a0,lefty:a1,rightshoulder:b7,rightstick:b14,righttrigger:a5,rightx:a2,righty:a3,start:b11,x:b4,y:b3,hint:!SDL_GAMECONTROLLER_USE_BUTTON_LABELS:=1,",
"030000003512000020ab000010010000,8BitDo SNES30 Gamepad,a:b1,b:b0,back:b10,dpdown:+a1,dpleft:-a0,dpright:+a0,dpup:-a1,leftshoulder:b6,rightshoulder:b7,start:b11,x:b4,y:b3,hint:!SDL_GAMECONTROLLER_USE_BUTTON_LABELS:=1,",
"05000000202800000900000000010000,8BitDo SNES30 Gamepad,a:b1,b:b0,back:b10,dpdown:b122,dpleft:b119,dpright:b120,dpup:b117,leftshoulder:b6,rightshoulder:b7,start:b11,x:b4,y:b3,hint:!SDL_GAMECONTROLLER_USE_BUTTON_LABELS:=1,",
"05000000c82d00001b30000001000000,8BitDo Ultimate 2C Wireless,a:b0,b:b1,back:b10,dpdown:h0.4,dpleft:h0.8,dpright:h0.2,dpup:h0.1,guide:b12,leftshoulder:b6,leftstick:b13,lefttrigger:a5,leftx:a0,lefty:a1,paddle1:b5,paddle2:b2,rightshoulder:b7,rightstick:b14,righttrigger:a4,rightx:a2,righty:a3,start:b11,x:b3,y:b4,", /* Bluetooth */
@@ -527,9 +532,6 @@ static const char *s_GamepadMappings[] = {
"05000000050b00000045000040000000,ASUS Gamepad,a:b0,b:b1,back:b9,dpdown:h0.4,dpleft:h0.8,dpright:h0.2,dpup:h0.1,guide:b6,leftshoulder:b4,leftstick:b7,lefttrigger:a5,leftx:a0,lefty:a1,rightshoulder:b5,rightstick:b8,righttrigger:a4,rightx:a2,righty:a3,start:b10,x:b2,y:b3,",
"03000000050b00000579000011010000,ASUS ROG Kunai 3 Gamepad,a:b0,b:b1,back:b10,dpdown:h0.4,dpleft:h0.8,dpright:h0.2,dpup:h0.1,guide:b12,leftshoulder:b6,leftstick:b13,lefttrigger:a5,leftx:a0,lefty:a1,misc1:b36,paddle1:b52,paddle2:b53,rightshoulder:b7,rightstick:b14,righttrigger:a4,rightx:a2,righty:a3,start:b11,x:b3,y:b4,",
"05000000050b00000679000000010000,ASUS ROG Kunai 3 Gamepad,a:b0,b:b1,back:b10,dpdown:h0.4,dpleft:h0.8,dpright:h0.2,dpup:h0.1,guide:b12,leftshoulder:b6,leftstick:b13,lefttrigger:a5,leftx:a0,lefty:a1,misc1:b21,paddle1:b22,paddle2:b23,rightshoulder:b7,rightstick:b14,righttrigger:a4,rightx:a2,righty:a3,start:b11,x:b3,y:b4,",
- "030000006f0e00003901000020060000,Afterglow Controller for Xbox One,a:b0,b:b1,back:b6,dpdown:h0.4,dpleft:h0.8,dpright:h0.2,dpup:h0.1,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,",
- "030000006f0e00003901000000430000,Afterglow Prismatic Controller,a:b0,b:b1,back:b6,dpdown:h0.4,dpleft:h0.8,dpright:h0.2,dpup:h0.1,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,",
- "030000006f0e00001302000000010000,Afterglow,a:b0,b:b1,back:b6,dpdown:h0.4,dpleft:h0.8,dpright:h0.2,dpup:h0.1,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,",
"03000000100000008200000011010000,Akishop Customs PS360+ v1.66,a:b1,b:b2,back:b12,dpdown:h0.4,dpleft:h0.8,dpright:h0.2,dpup:h0.1,guide:b8,leftshoulder:b4,lefttrigger:b6,rightshoulder:b5,righttrigger:b7,start:b9,x:b0,y:b3,",
"05000000491900000204000021000000,Amazon Fire Game Controller,a:b0,b:b1,back:b10,dpdown:h0.4,dpleft:h0.8,dpright:h0.2,dpup:h0.1,guide:b17,leftshoulder:b6,leftstick:b13,lefttrigger:a5,leftx:a0,lefty:a1,misc1:b12,rightshoulder:b7,rightstick:b14,righttrigger:a4,rightx:a2,righty:a3,start:b11,x:b3,y:b4,",
"03000000491900001904000011010000,Amazon Luna Controller,a:b0,b:b1,back:b6,dpdown:h0.4,dpleft:h0.8,dpright:h0.2,dpup:h0.1,guide:b8,leftshoulder:b4,leftstick:b10,lefttrigger:a3,leftx:a0,lefty:a1,misc1:b9,rightshoulder:b5,rightstick:b11,righttrigger:a4,rightx:a2,righty:a5,start:b7,x:b2,y:b3,",
@@ -551,25 +553,21 @@ static const char *s_GamepadMappings[] = {
"050000004c050000f20d000000010000,DualSense Edge Wireless Controller,a:b1,b:b2,back:b8,dpdown:h0.4,dpleft:h0.8,dpright:h0.2,dpup:h0.1,guide:b12,leftshoulder:b4,leftstick:b10,lefttrigger:a3,leftx:a0,lefty:a1,rightshoulder:b5,rightstick:b11,righttrigger:a4,rightx:a2,righty:a5,start:b9,x:b0,y:b3,",
"030000006f0e00003001000001010000,EA Sports PS3 Controller,a:b1,b:b2,back:b8,dpdown:h0.4,dpleft:h0.8,dpright:h0.2,dpup:h0.1,guide:b12,leftshoulder:b4,leftstick:b10,lefttrigger:b6,leftx:a0,lefty:a1,rightshoulder:b5,rightstick:b11,righttrigger:b7,rightx:a2,righty:a3,start:b9,x:b0,y:b3,",
"03000000790000001100000010010000,Elecom Gamepad,crc:e86c,a:b2,b:b3,back:b6,dpdown:+a1,dpleft:-a0,dpright:+a0,dpup:-a1,leftshoulder:b4,rightshoulder:b5,start:b7,x:b0,y:b1,",
- "0300000079000000d418000000010000,GPD Win 2 Controller,a:b0,b:b1,back:b6,dpdown:h0.4,dpleft:h0.8,dpright:h0.2,dpup:h0.1,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,",
"0500000047532067616d657061640000,GS Gamepad,a:b0,b:b1,dpdown:h0.4,dpleft:h0.8,dpright:h0.2,dpup:h0.1,guide:b8,leftshoulder:b4,leftstick:b10,lefttrigger:b6,leftx:a0,lefty:a1,rightshoulder:b5,rightstick:b11,righttrigger:b7,rightx:a2,righty:a3,start:b9,x:b2,y:b3,",
- "03000000341a000005f7000010010000,GameCube {HuiJia USB box},a:b1,b:b2,dpdown:b14,dpleft:b15,dpright:b13,dpup:b12,lefttrigger:a3,leftx:a0,lefty:a1,rightshoulder:b7,righttrigger:a4,rightx:a5,righty:a2,start:b9,x:b0,y:b3,",
+ "03000000341a000005f7000010010000,GameCube {HuiJia USB box},a:b1,b:b0,dpdown:b14,dpleft:b15,dpright:b13,dpup:b12,lefttrigger:a3,leftx:a0,lefty:a1,rightshoulder:b7,righttrigger:a4,rightx:a5,righty:a2,start:b9,x:b2,y:b3,",
"03000000bc2000000055000011010000,GameSir G3w,a:b0,b:b1,back:b10,dpdown:h0.4,dpleft:h0.8,dpright:h0.2,dpup:h0.1,leftshoulder:b6,leftstick:b13,lefttrigger:a5,leftx:a0,lefty:a1,rightshoulder:b7,rightstick:b14,righttrigger:a4,rightx:a2,righty:a3,start:b11,x:b3,y:b4,",
"0500000049190000020400001b010000,GameSir T4 Pro,crc:8283,a:b0,b:b1,back:b10,dpdown:h0.4,dpleft:h0.8,dpright:h0.2,dpup:h0.1,guide:b23,leftshoulder:b6,leftstick:b13,lefttrigger:a5,leftx:a0,lefty:a1,rightshoulder:b7,rightstick:b14,righttrigger:a4,rightx:a2,righty:a3,start:b11,x:b3,y:b4,",
"03000000373500009710000001020000,GameSir-K1 FLUX,a:b0,b:b1,back:b10,dpdown:h0.4,dpleft:h0.8,dpright:h0.2,dpup:h0.1,guide:b12,leftshoulder:b6,leftstick:b13,lefttrigger:a5,leftx:a0,lefty:a1,misc1:b15,rightshoulder:b7,rightstick:b14,righttrigger:a4,rightx:a2,righty:a3,start:b11,x:b3,y:b4,",
"03000000ac0500001a06000011010000,GameSir-T3 2.02,a:b0,b:b1,back:b10,dpdown:h0.4,dpleft:h0.8,dpright:h0.2,dpup:h0.1,guide:b15,leftshoulder:b6,leftstick:b13,lefttrigger:a5,leftx:a0,lefty:a1,rightshoulder:b7,rightstick:b14,righttrigger:a4,rightx:a2,righty:a3,start:b11,x:b3,y:b4,",
"0500000047532047616d657061640000,GameStop Gamepad,a:b0,b:b1,back:b8,dpdown:h0.4,dpleft:h0.8,dpright:h0.2,dpup:h0.1,leftshoulder:b4,leftstick:b10,lefttrigger:b6,leftx:a0,lefty:a1,rightshoulder:b5,rightstick:b11,righttrigger:b7,rightx:a2,righty:a3,start:b9,x:b2,y:b3,",
"03000000c01100000140000011010000,GameStop PS4 Fun Controller,a:b1,b:b2,back:b8,dpdown:h0.4,dpleft:h0.8,dpright:h0.2,dpup:h0.1,guide:b12,leftshoulder:b4,leftstick:b10,lefttrigger:a3,leftx:a0,lefty:a1,rightshoulder:b5,rightstick:b11,righttrigger:a4,rightx:a2,righty:a5,start:b9,x:b0,y:b3,",
- "030000006f0e00000104000000010000,Gamestop Logic3 Controller,a:b0,b:b1,back:b6,dpdown:h0.4,dpleft:h0.8,dpright:h0.2,dpup:h0.1,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,",
"030000008f0e00000800000010010000,Gasia Co. Ltd PS(R) Gamepad,a:b2,b:b1,back:b8,dpdown:h0.4,dpleft:h0.8,dpright:h0.2,dpup:h0.1,leftshoulder:b4,leftstick:b10,lefttrigger:b6,leftx:a0,lefty:a1,rightshoulder:b5,rightstick:b11,righttrigger:b7,rightx:a2,righty:a3,start:b9,x:b3,y:b0,",
- "030000006f0e00001304000000010000,Generic X-Box pad,a:b0,b:b1,back:b6,dpdown:h0.4,dpleft:h0.8,dpright:h0.2,dpup:h0.1,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,",
"03000000f0250000c183000010010000,Goodbetterbest Ltd USB Controller,a:b1,b:b2,back:b8,dpdown:h0.4,dpleft:h0.8,dpright:h0.2,dpup:h0.1,guide:b12,leftshoulder:b4,leftstick:b10,lefttrigger:b6,leftx:a0,lefty:a1,rightshoulder:b5,rightstick:b11,righttrigger:b7,rightx:a2,righty:a3,start:b9,x:b0,y:b3,",
"03000000d11800000094000011010000,Google Stadia Controller,a:b0,b:b1,back:b6,dpdown:h0.4,dpleft:h0.8,dpright:h0.2,dpup:h0.1,guide:b8,leftshoulder:b4,leftstick:b9,lefttrigger:a5,leftx:a0,lefty:a1,rightshoulder:b5,rightstick:b10,righttrigger:a4,rightx:a2,righty:a3,start:b7,x:b2,y:b3,",
"05000000d11800000094000000010000,Google Stadia Controller,a:b0,b:b1,back:b6,dpdown:h0.4,dpleft:h0.8,dpright:h0.2,dpup:h0.1,guide:b8,leftshoulder:b4,leftstick:b9,lefttrigger:a5,leftx:a0,lefty:a1,rightshoulder:b5,rightstick:b10,righttrigger:a4,rightx:a2,righty:a3,start:b7,x:b2,y:b3,",
"03000000280400000140000000010000,Gravis Gamepad Pro USB ,a:b1,b:b2,back:b8,leftshoulder:b4,lefttrigger:b6,leftx:a0,lefty:a1,rightshoulder:b5,righttrigger:b7,start:b9,x:b0,y:b3,",
"030000008f0e00000610000000010000,GreenAsia Electronics 4Axes 12Keys Gamepad,a:b2,b:b1,back:b8,dpdown:h0.4,dpleft:h0.8,dpright:h0.2,dpup:h0.1,leftshoulder:b6,leftstick:b9,lefttrigger:b4,leftx:a0,lefty:a1,rightshoulder:b7,rightstick:b10,righttrigger:b5,rightx:a3,righty:a2,start:b11,x:b3,y:b0,",
"030000008f0e00001200000010010000,GreenAsia Inc. USB Joystick,a:b0,b:b1,back:b8,dpdown:h0.4,dpleft:h0.8,dpright:h0.2,dpup:h0.1,leftshoulder:b4,leftstick:b10,lefttrigger:b5,leftx:a0,lefty:a1,rightshoulder:b6,rightstick:b11,righttrigger:b7,rightx:a3,righty:a2,start:b9,x:b2,y:b3,",
- "03000000c9110000f055000011010000,HJC Game GAMEPAD,a:b0,b:b1,back:b8,dpdown:h0.4,dpleft:h0.8,dpright:h0.2,dpup:h0.1,leftshoulder:b4,leftstick:b10,lefttrigger:b6,leftx:a0,lefty:a1,rightshoulder:b5,rightstick:b11,righttrigger:b7,rightx:a2,righty:a3,start:b9,x:b2,y:b3,",
"030000000d0f00001000000011010000,HORI CO. LTD. FIGHTING STICK 3,a:b1,b:b2,back:b8,dpdown:h0.4,dpleft:h0.8,dpright:h0.2,dpup:h0.1,guide:b12,leftshoulder:b4,lefttrigger:b6,rightshoulder:b5,righttrigger:b7,start:b9,x:b0,y:b3,",
"030000000d0f00002200000011010000,HORI CO. LTD. REAL ARCADE Pro.V3,a:b1,b:b2,back:b8,dpdown:h0.4,dpleft:h0.8,dpright:h0.2,dpup:h0.1,guide:b12,leftshoulder:b4,lefttrigger:b6,rightshoulder:b5,righttrigger:b7,start:b9,x:b0,y:b3,",
"030000000d0f00006a00000011010000,HORI CO. LTD. Real Arcade Pro.4,a:b1,b:b2,back:b8,dpdown:h0.4,dpleft:h0.8,dpright:h0.2,dpup:h0.1,guide:b12,leftshoulder:b4,leftstick:b10,lefttrigger:a3,leftx:a0,lefty:a1,rightshoulder:b5,rightstick:b11,righttrigger:a4,rightx:a2,righty:a5,start:b9,x:b0,y:b3,",
@@ -583,30 +581,23 @@ static const char *s_GamepadMappings[] = {
"030000000d0f0000aa00000011010000,HORI Real Arcade Pro,a:b2,b:b1,back:b8,dpdown:h0.4,dpleft:h0.8,dpright:h0.2,dpup:h0.1,guide:b12,leftshoulder:b4,leftstick:b10,lefttrigger:b6,leftx:a0,lefty:a1,rightshoulder:b5,rightstick:b11,righttrigger:b7,rightx:a2,righty:a3,start:b9,x:b3,y:b0,",
"030000000d0f00006e00000011010000,HORIPAD 4 (PS3),a:b1,b:b2,back:b8,dpdown:h0.4,dpleft:h0.8,dpright:h0.2,dpup:h0.1,guide:b12,leftshoulder:b4,leftstick:b10,lefttrigger:b6,leftx:a0,lefty:a1,rightshoulder:b5,rightstick:b11,righttrigger:b7,rightx:a2,righty:a3,start:b9,x:b0,y:b3,",
"030000000d0f00006600000011010000,HORIPAD 4 (PS4),a:b1,b:b2,back:b8,dpdown:h0.4,dpleft:h0.8,dpright:h0.2,dpup:h0.1,guide:b12,leftshoulder:b4,leftstick:b10,lefttrigger:a3,leftx:a0,lefty:a1,rightshoulder:b5,rightstick:b11,righttrigger:a4,rightx:a2,righty:a5,start:b9,x:b0,y:b3,",
- "030000000d0f00006700000001010000,HORIPAD ONE,a:b0,b:b1,back:b6,dpdown:h0.4,dpleft:h0.8,dpright:h0.2,dpup:h0.1,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,",
"06000000adde0000efbe000002010000,Hidromancer Game Controller,a:b0,b:b1,back:b6,dpdown:h0.4,dpleft:h0.8,dpright:h0.2,dpup:h0.1,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,",
"03000000d81400000862000011010000,HitBox (PS3/PC) Analog Mode,a:b1,b:b2,back:b8,guide:b9,leftshoulder:b4,lefttrigger:b6,leftx:a0,lefty:a1,rightshoulder:b5,righttrigger:b7,start:b12,x:b0,y:b3,",
"030000000d0f00005f00000011010000,Hori Fighting Commander 4 (PS3),a:b1,b:b2,back:b8,dpdown:h0.4,dpleft:h0.8,dpright:h0.2,dpup:h0.1,guide:b12,leftshoulder:b4,lefttrigger:b6,leftx:a0,lefty:a1,rightshoulder:b5,righttrigger:b7,rightx:a2,righty:a3,start:b9,x:b0,y:b3,",
"030000000d0f00005e00000011010000,Hori Fighting Commander 4 (PS4),a:b1,b:b2,back:b8,dpdown:h0.4,dpleft:h0.8,dpright:h0.2,dpup:h0.1,guide:b12,leftshoulder:b4,lefttrigger:a3,leftx:a0,lefty:a1,rightshoulder:b5,righttrigger:a4,rightx:a2,righty:a5,start:b9,x:b0,y:b3,",
"030000000d0f00008600000002010000,Hori Fighting Commander,a:b0,b:b1,back:b8,dpdown:h0.4,dpleft:h0.8,dpright:h0.2,dpup:h0.1,guide:b10,leftshoulder:b4,leftstick:b11,lefttrigger:b6,leftx:a0,lefty:a1,rightshoulder:b5,rightstick:b12,righttrigger:b7,rightx:a2,righty:a3,start:b9,x:b2,y:b3,",
- "03000000ad1b000001f5000033050000,Hori Pad EX Turbo 2,a:b0,b:b1,back:b6,dpdown:h0.4,dpleft:h0.8,dpright:h0.2,dpup:h0.1,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,",
"030000008f0e00001330000010010000,HuiJia SNES Controller,a:b2,b:b1,back:b8,dpdown:+a1,dpleft:-a0,dpright:+a0,dpup:-a1,leftshoulder:b6,rightshoulder:b7,start:b9,x:b3,y:b0,",
- "03000000242e00008816000001010000,Hyperkin X91,a:b0,b:b1,back:b6,dpdown:h0.4,dpleft:h0.8,dpright:h0.2,dpup:h0.1,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,",
"03000000d80400008200000003000000,IMS PCU#0 Gamepad Interface,a:b1,b:b0,back:b4,dpdown:+a1,dpleft:-a0,dpright:+a0,dpup:-a1,start:b5,x:b3,y:b2,",
"03000000fd0500000030000000010000,InterAct GoPad I-73000 (Fighting Game Layout),a:b3,b:b4,back:b6,leftx:a0,lefty:a1,rightshoulder:b2,righttrigger:b5,start:b7,x:b0,y:b1,",
"05000000491900000204000000000000,Ipega PG-9087S,a:b0,b:b1,back:b10,dpdown:h0.4,dpleft:h0.8,dpright:h0.2,dpup:h0.1,leftshoulder:b6,leftstick:b13,lefttrigger:b8,leftx:a0,lefty:a1,rightshoulder:b7,rightstick:b14,righttrigger:b9,rightx:a2,righty:a3,start:b11,x:b3,y:b4,",
"030000006e0500000320000010010000,JC-U3613M - DirectInput Mode,a:b2,b:b3,back:b10,dpdown:h0.4,dpleft:h0.8,dpright:h0.2,dpup:h0.1,guide:b12,leftshoulder:b4,leftstick:b8,lefttrigger:b6,leftx:a0,lefty:a1,rightshoulder:b5,rightstick:b9,righttrigger:b7,rightx:a2,righty:a3,start:b11,x:b0,y:b1,",
"03000000300f00001001000010010000,Jess Tech Dual Analog Rumble Pad,a:b2,b:b3,back:b8,dpdown:h0.4,dpleft:h0.8,dpright:h0.2,dpup:h0.1,leftshoulder:b4,leftstick:b10,lefttrigger:b5,leftx:a0,lefty:a1,rightshoulder:b6,rightstick:b11,righttrigger:b7,rightx:a3,righty:a2,start:b9,x:b0,y:b1,",
"03000000ba2200002010000001010000,Jess Technology USB Game Controller,a:b2,b:b1,back:b8,dpdown:h0.4,dpleft:h0.8,dpright:h0.2,dpup:h0.1,leftshoulder:b4,lefttrigger:b6,leftx:a0,lefty:a1,rightshoulder:b5,righttrigger:b7,rightx:a3,righty:a2,start:b9,x:b3,y:b0,",
- "030000006f0e00000103000000020000,Logic3 Controller,a:b0,b:b1,back:b6,dpdown:h0.4,dpleft:h0.8,dpright:h0.2,dpup:h0.1,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,",
"030000006d040000d1ca000011010000,Logitech Chillstream,a:b1,b:b2,back:b8,dpdown:h0.4,dpleft:h0.8,dpright:h0.2,dpup:h0.1,leftshoulder:b4,leftstick:b10,lefttrigger:b6,leftx:a0,lefty:a1,rightshoulder:b5,rightstick:b11,righttrigger:b7,rightx:a2,righty:a3,start:b9,x:b0,y:b3,",
"030000006d04000019c2000010010000,Logitech Cordless RumblePad 2,a:b1,b:b2,back:b8,dpdown:h0.4,dpleft:h0.8,dpright:h0.2,dpup:h0.1,leftshoulder:b4,leftstick:b10,lefttrigger:b6,leftx:a0,lefty:a1,rightshoulder:b5,rightstick:b11,righttrigger:b7,rightx:a2,righty:a3,start:b9,x:b0,y:b3,",
"030000006d04000016c2000010010000,Logitech Dual Action,a:b1,b:b2,back:b8,dpdown:h0.4,dpleft:h0.8,dpright:h0.2,dpup:h0.1,leftshoulder:b4,leftstick:b10,lefttrigger:b6,leftx:a0,lefty:a1,rightshoulder:b5,rightstick:b11,righttrigger:b7,rightx:a2,righty:a3,start:b9,x:b0,y:b3,",
"030000006d04000016c2000011010000,Logitech Dual Action,a:b1,b:b2,back:b8,dpdown:h0.4,dpleft:h0.8,dpright:h0.2,dpup:h0.1,leftshoulder:b4,leftstick:b10,lefttrigger:b6,leftx:a0,lefty:a1,rightshoulder:b5,rightstick:b11,righttrigger:b7,rightx:a2,righty:a3,start:b9,x:b0,y:b3,",
- "030000006d0400001dc2000014400000,Logitech F310 Gamepad (XInput),a:b0,b:b1,back:b6,dpdown:h0.4,dpleft:h0.8,dpright:h0.2,dpup:h0.1,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,",
- "030000006d0400001ec2000020200000,Logitech F510 Gamepad (XInput),a:b0,b:b1,back:b6,dpdown:h0.4,dpleft:h0.8,dpright:h0.2,dpup:h0.1,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,",
"030000006d04000019c2000011010000,Logitech F710 Gamepad (DInput),a:b1,b:b2,back:b8,dpdown:h0.4,dpleft:h0.8,dpright:h0.2,dpup:h0.1,leftshoulder:b4,leftstick:b10,lefttrigger:b6,leftx:a0,lefty:a1,rightshoulder:b5,rightstick:b11,righttrigger:b7,rightx:a2,righty:a3,start:b9,x:b0,y:b3,", /* Guide button doesn't seem to be sent in DInput mode. */
- "030000006d0400001fc2000005030000,Logitech F710 Gamepad (XInput),a:b0,b:b1,back:b6,dpdown:h0.4,dpleft:h0.8,dpright:h0.2,dpup:h0.1,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,",
"030000006d04000018c2000010010000,Logitech RumblePad 2,a:b1,b:b2,back:b8,dpdown:h0.4,dpleft:h0.8,dpright:h0.2,dpup:h0.1,leftshoulder:b4,leftstick:b10,lefttrigger:b6,leftx:a0,lefty:a1,rightshoulder:b5,rightstick:b11,righttrigger:b7,rightx:a2,righty:a3,start:b9,x:b0,y:b3,",
"030000006d04000011c2000010010000,Logitech WingMan Cordless RumblePad,a:b0,b:b1,back:b2,dpdown:h0.4,dpleft:h0.8,dpright:h0.2,dpup:h0.1,guide:b5,leftshoulder:b6,lefttrigger:b9,leftx:a0,lefty:a1,rightshoulder:b7,righttrigger:b10,rightx:a3,righty:a4,start:b8,x:b3,y:b4,",
"03000000c62400002b89000011010000,MOGA XP5-A Plus,a:b0,b:b1,back:b10,dpdown:h0.4,dpleft:h0.8,dpright:h0.2,dpup:h0.1,guide:b12,leftshoulder:b6,leftstick:b13,lefttrigger:a5,leftx:a0,lefty:a1,rightshoulder:b7,rightstick:b14,righttrigger:a4,rightx:a2,righty:a3,start:b11,x:b3,y:b4,",
@@ -618,22 +609,12 @@ static const char *s_GamepadMappings[] = {
"03000000380700005082000011010000,Mad Catz FightPad PRO (PS4),a:b1,b:b2,back:b8,dpdown:h0.4,dpleft:h0.8,dpright:h0.2,dpup:h0.1,guide:b12,leftshoulder:b4,leftstick:b10,lefttrigger:a3,leftx:a0,lefty:a1,rightshoulder:b5,rightstick:b11,righttrigger:a4,rightx:a2,righty:a5,start:b9,x:b0,y:b3,",
"03000000380700008433000011010000,Mad Catz FightStick TE S+ (PS3),a:b1,b:b2,back:b8,dpdown:h0.4,dpleft:h0.8,dpright:h0.2,dpup:h0.1,guide:b12,leftshoulder:b4,leftstick:b10,lefttrigger:b6,leftx:a0,lefty:a1,rightshoulder:b5,rightstick:b11,righttrigger:b7,rightx:a2,righty:a3,start:b9,x:b0,y:b3,",
"03000000380700008483000011010000,Mad Catz FightStick TE S+ (PS4),a:b1,b:b2,back:b8,dpdown:h0.4,dpleft:h0.8,dpright:h0.2,dpup:h0.1,guide:b12,leftshoulder:b4,leftstick:b10,lefttrigger:a3,leftx:a0,lefty:a1,rightshoulder:b5,rightstick:b11,righttrigger:a4,rightx:a2,righty:a5,start:b9,x:b0,y:b3,",
- "03000000ad1b00002ef0000090040000,Mad Catz Fightpad SFxT,a:b0,b:b1,back:b6,dpdown:h0.4,dpleft:h0.8,dpright:h0.2,dpup:h0.1,guide:b8,leftshoulder:b4,lefttrigger:a2,rightshoulder:b5,righttrigger:a5,start:b7,x:b2,y:b3,",
- "03000000380700003847000090040000,Mad Catz Wired Xbox 360 Controller (SFIV),a:b0,b:b1,back:b8,dpdown:h0.4,dpleft:h0.8,dpright:h0.2,dpup:h0.1,guide:b10,leftshoulder:b4,lefttrigger:b6,leftx:a0,lefty:a1,rightshoulder:b5,righttrigger:b7,rightx:a2,righty:a3,start:b9,x:b2,y:b3,",
- "03000000380700001647000010040000,Mad Catz Wired Xbox 360 Controller,a:b0,b:b1,back:b6,dpdown:h0.4,dpleft:h0.8,dpright:h0.2,dpup:h0.1,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,",
- "03000000ad1b000016f0000090040000,Mad Catz Xbox 360 Controller,a:b0,b:b1,back:b6,dpdown:h0.4,dpleft:h0.8,dpright:h0.2,dpup:h0.1,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,",
"03000000380700008034000011010000,Mad Catz fightstick (PS3),a:b1,b:b2,back:b8,dpdown:h0.4,dpleft:h0.8,dpright:h0.2,dpup:h0.1,guide:b12,leftshoulder:b4,lefttrigger:b6,leftx:a0,lefty:a1,rightshoulder:b5,righttrigger:b7,rightx:a2,righty:a3,start:b9,x:b0,y:b3,",
"03000000380700008084000011010000,Mad Catz fightstick (PS4),a:b1,b:b2,back:b8,dpdown:h0.4,dpleft:h0.8,dpright:h0.2,dpup:h0.1,guide:b12,leftshoulder:b4,lefttrigger:a3,leftx:a0,lefty:a1,rightshoulder:b5,righttrigger:a4,rightx:a2,righty:a5,start:b9,x:b0,y:b3,",
"03000000380700001888000010010000,MadCatz PC USB Wired Stick 8818,a:b1,b:b2,back:b8,dpdown:h0.4,dpleft:h0.8,dpright:h0.2,dpup:h0.1,guide:b12,leftshoulder:b4,lefttrigger:b6,leftx:a0,lefty:a1,rightshoulder:b5,righttrigger:b7,rightx:a2,righty:a3,start:b9,x:b0,y:b3,",
"03000000380700003888000010010000,MadCatz PC USB Wired Stick 8838,a:b1,b:b2,back:b8,dpdown:h0.4,dpleft:h0.8,dpright:h0.2,dpup:h0.1,guide:b12,leftshoulder:b4,leftstick:a0,lefttrigger:b6,leftx:a0,lefty:a1,rightshoulder:b5,righttrigger:b7,rightx:a2,righty:a3,start:b9,x:b0,y:b3,",
- "03000000790000004418000010010000,Mayflash GameCube Controller,a:b1,b:b2,dpdown:b14,dpleft:b15,dpright:b13,dpup:b12,lefttrigger:a3,leftx:a0,lefty:a1,rightshoulder:b7,righttrigger:a4,rightx:a5,righty:a2,start:b9,x:b0,y:b3,",
"03000000780000000600000010010000,Microntek USB Joystick,a:b2,b:b1,back:b8,leftshoulder:b6,lefttrigger:b4,leftx:a0,lefty:a1,rightshoulder:b7,righttrigger:b5,start:b9,x:b3,y:b0,",
"030000005e0400000e00000000010000,Microsoft SideWinder,a:b0,b:b1,back:b9,dpdown:h0.4,dpleft:h0.8,dpright:h0.2,dpup:h0.1,leftshoulder:b6,rightshoulder:b7,start:b8,x:b3,y:b4,",
- "030000005e040000d102000003020000,Microsoft X-Box One pad v2,a:b0,b:b1,back:b6,dpdown:h0.4,dpleft:h0.8,dpright:h0.2,dpup:h0.1,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,",
- "030000005e040000d102000001010000,Microsoft X-Box One pad,a:b0,b:b1,back:b6,dpdown:h0.4,dpleft:h0.8,dpright:h0.2,dpup:h0.1,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,",
- "030000005e0400008502000000010000,Microsoft X-Box pad (Japan),a:b0,b:b1,back:b6,dpdown:h0.4,dpleft:h0.8,dpright:h0.2,dpup:h0.1,leftshoulder:b5,leftstick:b8,lefttrigger:a2,leftx:a0,lefty:a1,rightshoulder:b2,rightstick:b9,righttrigger:a5,rightx:a3,righty:a4,start:b7,x:b3,y:b4,",
- "030000005e0400008902000021010000,Microsoft X-Box pad v2 (US),a:b0,b:b1,back:b6,dpdown:h0.4,dpleft:h0.8,dpright:h0.2,dpup:h0.1,leftshoulder:b5,leftstick:b8,lefttrigger:a2,leftx:a0,lefty:a1,rightshoulder:b2,rightstick:b9,righttrigger:a5,rightx:a3,righty:a4,start:b7,x:b3,y:b4,",
- "030000005e0400008902000020010000,Microsoft Xbox Controller S,a:b0,b:b1,back:b6,dpdown:h0.4,dpleft:h0.8,dpright:h0.2,dpup:h0.1,leftshoulder:b5,leftstick:b8,lefttrigger:a2,leftx:a0,lefty:a1,rightshoulder:b2,rightstick:b9,righttrigger:a5,rightx:a3,righty:a4,start:b7,x:b3,y:b4,",
"05000000d6200000ad0d000001000000,Moga Pro,a:b0,b:b1,dpdown:h0.4,dpleft:h0.8,dpright:h0.2,dpup:h0.1,leftshoulder:b4,leftstick:b7,lefttrigger:a5,leftx:a0,lefty:a1,rightshoulder:b5,rightstick:b8,righttrigger:a4,rightx:a2,righty:a3,start:b6,x:b2,y:b3,",
"030000006b140000010c000010010000,NACON GC-400ES,a:b0,b:b1,back:b8,dpdown:h0.4,dpleft:h0.8,dpright:h0.2,dpup:h0.1,guide:b12,leftshoulder:b4,leftstick:b10,lefttrigger:b6,leftx:a0,lefty:a1,rightshoulder:b5,rightstick:b11,righttrigger:b7,rightx:a2,righty:a3,start:b9,x:b2,y:b3,",
"030000001008000001e5000010010000,NEXT SNES Controller,a:b2,b:b1,back:b8,dpdown:+a1,dpleft:-a0,dpright:+a0,dpup:-a1,leftshoulder:b4,rightshoulder:b6,start:b9,x:b3,y:b0,",
@@ -642,19 +623,22 @@ static const char *s_GamepadMappings[] = {
"05000000550900001472000001000000,NVIDIA Controller v01.04,a:b0,b:b1,back:b14,dpdown:h0.4,dpleft:h0.8,dpright:h0.2,dpup:h0.1,guide:b16,leftshoulder:b4,leftstick:b7,lefttrigger:a3,leftx:a0,lefty:a1,rightshoulder:b5,rightstick:b8,righttrigger:a4,rightx:a2,righty:a5,start:b6,x:b2,y:b3,",
"030000004b120000014d000000010000,NYKO AIRFLO EX,a:b0,b:b1,back:b8,dpdown:h0.4,dpleft:h0.8,dpright:h0.2,dpup:h0.1,guide:b10,leftshoulder:b4,leftstick:b11,lefttrigger:b6,leftx:a0,lefty:a1,rightshoulder:b5,rightstick:b12,righttrigger:b7,rightx:a3,righty:a2,start:b9,x:b2,y:b3,",
"03000000451300000830000010010000,NYKO CORE,a:b1,b:b2,back:b8,dpdown:h0.4,dpleft:h0.8,dpright:h0.2,dpup:h0.1,guide:b12,leftshoulder:b4,leftstick:b10,lefttrigger:b6,leftx:a0,lefty:a1,rightshoulder:b5,rightstick:b11,righttrigger:b7,rightx:a2,righty:a5,start:b9,x:b0,y:b3,",
- "03000000790000004318000010010000,Nintendo GameCube Controller,a:b1,b:b0,dpdown:b14,dpleft:b15,dpright:b13,dpup:b12,lefttrigger:a3,leftx:a0,lefty:a1,rightshoulder:b7,righttrigger:a4,rightx:a5,righty:a2,start:b9,x:b2,y:b3,hint:!SDL_GAMECONTROLLER_USE_BUTTON_LABELS:=1,",
+ "0300000085320000030c000011010000,Nacon GC100,a:b2,b:b1,back:b8,dpdown:h0.4,dpleft:h0.8,dpright:h0.2,dpup:h0.1,guide:b12,leftshoulder:b4,leftstick:b10,lefttrigger:b6,leftx:a0,lefty:a1,rightshoulder:b5,rightstick:b11,righttrigger:b7,rightx:a2,righty:a3,start:b9,x:b3,y:b0,",
+ "03000000790000004318000010010000,Nintendo GameCube Controller,a:b1,b:b2,dpdown:b14,dpleft:b15,dpright:b13,dpup:b12,lefttrigger:a3,leftx:a0,lefty:a1,rightshoulder:b7,righttrigger:a4,rightx:a5,righty:a2,start:b9,x:b0,y:b3,",
+ "03000000790000004418000010010000,Nintendo GameCube Controller,a:b1,b:b2,dpdown:b14,dpleft:b15,dpright:b13,dpup:b12,lefttrigger:a3,leftx:a0,lefty:a1,rightshoulder:b7,righttrigger:a4,rightx:a5,righty:a2,start:b9,x:b0,y:b3,",
"030000007e0500001920000011810000,Nintendo N64 Controller,crc:d670,a:b0,b:b1,back:b2,dpdown:h0.4,dpleft:h0.8,dpright:h0.2,dpup:h0.1,guide:b12,leftshoulder:b6,leftstick:b9,lefttrigger:b8,leftx:a0,lefty:a1,misc1:b5,rightshoulder:b7,righttrigger:b3,start:b11,x:b4,y:b10,",
"050000007e0500001920000001800000,Nintendo N64 Controller,crc:5e1c,a:b0,b:b1,back:b2,dpdown:h0.4,dpleft:h0.8,dpright:h0.2,dpup:h0.1,guide:b12,leftshoulder:b6,leftstick:b9,lefttrigger:b8,leftx:a0,lefty:a1,misc1:b5,rightshoulder:b7,righttrigger:b3,start:b11,x:b4,y:b10,",
"030000007e0500001e20000011810000,Nintendo SEGA Genesis Controller,crc:bb22,a:b0,b:b1,dpdown:h0.4,dpleft:h0.8,dpright:h0.2,dpup:h0.1,guide:b6,misc1:b3,rightshoulder:b2,righttrigger:b4,start:b5,",
"050000007e0500001720000001800000,Nintendo SEGA Genesis Controller,crc:c1bf,a:b0,b:b1,dpdown:h0.4,dpleft:h0.8,dpright:h0.2,dpup:h0.1,guide:b6,misc1:b3,rightshoulder:b2,righttrigger:b4,start:b5,",
"030000007e0500001720000011810000,Nintendo SNES Controller,crc:f648,a:b0,b:b1,back:b8,dpdown:h0.4,dpleft:h0.8,dpright:h0.2,dpup:h0.1,leftshoulder:b4,lefttrigger:b6,rightshoulder:b5,righttrigger:b7,start:b9,x:b3,y:b2,hint:!SDL_GAMECONTROLLER_USE_BUTTON_LABELS:=1,",
"050000007e0500001720000001800000,Nintendo SNES Controller,crc:dbc0,a:b0,b:b1,back:b8,dpdown:h0.4,dpleft:h0.8,dpright:h0.2,dpup:h0.1,leftshoulder:b4,lefttrigger:b6,rightshoulder:b5,righttrigger:b7,start:b9,x:b3,y:b2,hint:!SDL_GAMECONTROLLER_USE_BUTTON_LABELS:=1,",
- "050000007e0500000620000001800000,Nintendo Switch Joy-Con (L),a:b16,b:b15,guide:b4,leftshoulder:b6,leftstick:b12,leftx:a1,lefty:a0~,rightshoulder:b8,start:b9,x:b14,y:b17,hint:!SDL_GAMECONTROLLER_USE_BUTTON_LABELS:=1,",
+ "050000007e0500000720000001800000,Nintendo NES Controller (L),crc:a5a7,a:b1,b:b0,back:b4,dpdown:h0.4,dpleft:h0.8,dpright:h0.2,dpup:h0.1,leftshoulder:b2,rightshoulder:b3,start:b5,hint:!SDL_GAMECONTROLLER_USE_BUTTON_LABELS:=1,",
+ "050000007e0500000720000001800000,Nintendo NES Controller (R),crc:05ae,a:b1,b:b0,back:b4,dpdown:h0.4,dpleft:h0.8,dpright:h0.2,dpup:h0.1,leftshoulder:b2,rightshoulder:b3,start:b5,hint:!SDL_GAMECONTROLLER_USE_BUTTON_LABELS:=1,",
+ "050067007e0500000620000001800000,Nintendo Switch Joy-Con (L),crc:0067,a:b9,b:b8,guide:b0,leftshoulder:b2,leftstick:b6,leftx:a1,lefty:a0~,paddle2:b1,paddle4:b3,rightshoulder:b4,start:b5,x:b7,y:b10,hint:!SDL_GAMECONTROLLER_USE_BUTTON_LABELS:=1,",
"060000007e0500000620000000000000,Nintendo Switch Joy-Con (L/R),a:b0,b:b1,back:b9,dpdown:b15,dpleft:b16,dpright:b17,dpup:b14,leftshoulder:b5,leftstick:b12,lefttrigger:b7,leftx:a0,lefty:a1,rightshoulder:b6,rightstick:b13,righttrigger:b8,rightx:a2,righty:a3,start:b10,x:b3,y:b2,hint:!SDL_GAMECONTROLLER_USE_BUTTON_LABELS:=1,",
"060000007e0500000820000000000000,Nintendo Switch Joy-Con (L/R),a:b0,b:b1,back:b9,dpdown:b15,dpleft:b16,dpright:b17,dpup:b14,guide:b11,leftshoulder:b5,leftstick:b12,lefttrigger:b7,leftx:a0,lefty:a1,rightshoulder:b6,rightstick:b13,righttrigger:b8,rightx:a2,righty:a3,start:b10,x:b3,y:b2,hint:!SDL_GAMECONTROLLER_USE_BUTTON_LABELS:=1,",
- "050000007e0500000720000001800000,Nintendo Switch Joy-Con (R),a:b1,b:b2,guide:b9,leftshoulder:b4,leftstick:b10,leftx:a1~,lefty:a0,rightshoulder:b6,start:b8,x:b0,y:b3,hint:!SDL_GAMECONTROLLER_USE_BUTTON_LABELS:=1,",
+ "05006ea07e0500000720000001800000,Nintendo Switch Joy-Con (R),crc:a06e,a:b1,b:b2,guide:b9,leftshoulder:b4,leftstick:b10,leftx:a1~,lefty:a0,paddle1:b5,paddle3:b7,rightshoulder:b6,start:b8,x:b0,y:b3,hint:!SDL_GAMECONTROLLER_USE_BUTTON_LABELS:=1,",
"03000000d620000013a7000011010000,Nintendo Switch PowerA Controller,a:b1,b:b2,back:b8,dpdown:h0.4,dpleft:h0.8,dpright:h0.2,dpup:h0.1,guide:b12,leftshoulder:b4,leftstick:b10,lefttrigger:b6,leftx:a0,lefty:a1,rightshoulder:b5,rightstick:b11,righttrigger:b7,rightx:a2,righty:a3,start:b9,x:b0,y:b3,hint:!SDL_GAMECONTROLLER_USE_BUTTON_LABELS:=1,",
- "03000000d620000011a7000011010000,Nintendo Switch PowerA Core Plus Controller,a:b1,b:b2,back:b8,dpdown:h0.4,dpleft:h0.8,dpright:h0.2,dpup:h0.1,guide:b12,leftshoulder:b4,leftstick:b10,lefttrigger:b6,leftx:a0,lefty:a1,rightshoulder:b5,rightstick:b11,righttrigger:b7,rightx:a2,righty:a3,start:b9,x:b0,y:b3,hint:!SDL_GAMECONTROLLER_USE_BUTTON_LABELS:=1,",
"030000007e0500000920000011810000,Nintendo Switch Pro Controller,a:b0,b:b1,back:b9,dpdown:h0.4,dpleft:h0.8,dpright:h0.2,dpup:h0.1,guide:b11,leftshoulder:b5,leftstick:b12,lefttrigger:b7,leftx:a0,lefty:a1,misc1:b4,rightshoulder:b6,rightstick:b13,righttrigger:b8,rightx:a2,righty:a3,start:b10,x:b3,y:b2,hint:!SDL_GAMECONTROLLER_USE_BUTTON_LABELS:=1,",
"050000004c69632050726f20436f6e00,Nintendo Switch Pro Controller,crc:15b7,a:b0,b:b1,back:b8,dpdown:h0.4,dpleft:h0.8,dpright:h0.2,dpup:h0.1,guide:b12,leftshoulder:b4,leftstick:b10,lefttrigger:b6,leftx:a0,lefty:a1,misc1:b13,rightshoulder:b5,rightstick:b11,righttrigger:b7,rightx:a2,righty:a3,start:b9,x:b2,y:b3,hint:!SDL_GAMECONTROLLER_USE_BUTTON_LABELS:=1,",
"050000007e0500000920000001000000,Nintendo Switch Pro Controller,a:b1,b:b0,back:b8,dpdown:h0.4,dpleft:h0.8,dpright:h0.2,dpup:h0.1,guide:b12,leftshoulder:b4,leftstick:b10,lefttrigger:b6,leftx:a0,lefty:a1,rightshoulder:b5,rightstick:b11,righttrigger:b7,rightx:a2,righty:a3,start:b9,x:b3,y:b2,hint:!SDL_GAMECONTROLLER_USE_BUTTON_LABELS:=1,",
@@ -666,9 +650,7 @@ static const char *s_GamepadMappings[] = {
"030000000d0500000308000010010000,Nostromo n45 Dual Analog Gamepad,a:b0,b:b1,back:b8,dpdown:h0.4,dpleft:h0.8,dpright:h0.2,dpup:h0.1,guide:b9,leftshoulder:b4,leftstick:b12,lefttrigger:b5,leftx:a0,lefty:a1,rightshoulder:b6,rightstick:b11,righttrigger:b7,rightx:a3,righty:a2,start:b10,x:b2,y:b3,",
"05000000362800000100000002010000,OUYA Game Controller,a:b0,b:b3,dpdown:b9,dpleft:b10,dpright:b11,dpup:b8,guide:b14,leftshoulder:b4,leftstick:b6,lefttrigger:a2,leftx:a0,lefty:a1,rightshoulder:b5,rightstick:b7,righttrigger:a5,rightx:a3,righty:a4,x:b1,y:b2,",
"05000000362800000100000003010000,OUYA Game Controller,a:b0,b:b3,dpdown:b9,dpleft:b10,dpright:b11,dpup:b8,guide:b14,leftshoulder:b4,leftstick:b6,lefttrigger:a2,leftx:a0,lefty:a1,rightshoulder:b5,rightstick:b7,righttrigger:a5,rightx:a3,righty:a4,x:b1,y:b2,",
- "030000005e0400000202000000010000,Old Xbox pad,a:b0,b:b1,back:b6,dpdown:h0.4,dpleft:h0.8,dpright:h0.2,dpup:h0.1,leftshoulder:b5,leftstick:b8,lefttrigger:a2,leftx:a0,lefty:a1,rightshoulder:b2,rightstick:b9,righttrigger:a5,rightx:a3,righty:a4,start:b7,x:b3,y:b4,",
"03000000ff1100003133000010010000,PC Game Controller,a:b2,b:b1,back:b8,dpdown:h0.4,dpleft:h0.8,dpright:h0.2,dpup:h0.1,leftshoulder:b4,leftstick:b10,lefttrigger:b6,leftx:a0,lefty:a1,rightshoulder:b5,rightstick:b11,righttrigger:b7,rightx:a2,righty:a3,start:b9,x:b3,y:b0,",
- "030000006f0e00006401000001010000,PDP Battlefield One,a:b0,b:b1,back:b6,dpdown:h0.4,dpleft:h0.8,dpright:h0.2,dpup:h0.1,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,",
"030000006f0e00000901000011010000,PDP Versus Fighting Pad,a:b1,b:b2,back:b8,dpdown:h0.4,dpleft:h0.8,dpright:h0.2,dpup:h0.1,guide:b12,leftshoulder:b4,lefttrigger:b6,rightshoulder:b5,righttrigger:b7,start:b9,x:b0,y:b3,",
"03000000ff1100004133000010010000,PS2 Controller,a:b2,b:b1,back:b8,leftshoulder:b6,lefttrigger:b4,leftx:a0,lefty:a1,rightshoulder:b7,righttrigger:b5,start:b9,x:b3,y:b0,",
"03000000341a00003608000011010000,PS3 Controller,a:b1,b:b2,back:b8,dpdown:h0.4,dpleft:h0.8,dpright:h0.2,dpup:h0.1,guide:b12,leftshoulder:b4,leftstick:b10,lefttrigger:b6,leftx:a0,lefty:a1,rightshoulder:b5,rightstick:b11,righttrigger:b7,rightx:a2,righty:a3,start:b9,x:b0,y:b3,",
@@ -701,8 +683,7 @@ static const char *s_GamepadMappings[] = {
"050000004c050000e60c000000010000,PS5 Controller,a:b1,b:b2,back:b8,dpdown:h0.4,dpleft:h0.8,dpright:h0.2,dpup:h0.1,guide:b12,leftshoulder:b4,leftstick:b10,lefttrigger:a3,leftx:a0,lefty:a1,misc1:b13,rightshoulder:b5,rightstick:b11,righttrigger:a4,rightx:a2,righty:a5,start:b9,x:b0,y:b3,",
"050000004c050000e60c000000810000,PS5 Controller,a:b0,b:b1,back:b8,dpdown:h0.4,dpleft:h0.8,dpright:h0.2,dpup:h0.1,guide:b10,leftshoulder:b4,leftstick:b11,lefttrigger:a2,leftx:a0,lefty:a1,rightshoulder:b5,rightstick:b12,righttrigger:a5,rightx:a3,righty:a4,start:b9,x:b3,y:b2,",
"030000004c050000da0c000011010000,Playstation Controller,a:b2,b:b1,back:b8,leftshoulder:b6,lefttrigger:b4,leftx:a0,lefty:a1,rightshoulder:b7,righttrigger:b5,start:b9,x:b3,y:b0,",
- "03000000c62400003a54000001010000,PowerA XBox One Controller,a:b0,b:b1,back:b6,dpdown:h0.7,dpleft:h0.8,dpright:h0.2,dpup:h0.1,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,",
- "03000000c62400000053000000010000,PowerA,a:b0,b:b1,back:b6,dpdown:h0.4,dpleft:h0.8,dpright:h0.2,dpup:h0.1,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,",
+ "03000000d620000011a7000011010000,PowerA Wired GameCube Controller,a:b1,b:b2,back:b8,dpdown:h0.4,dpleft:h0.8,dpright:h0.2,dpup:h0.1,guide:b12,leftshoulder:b4,leftstick:b10,lefttrigger:b6,leftx:a0,lefty:a1,rightshoulder:b5,rightstick:b11,righttrigger:b7,rightx:a2,righty:a3,start:b9,x:b0,y:b3,",
"03000000300f00001211000011010000,QanBa Arcade JoyStick,a:b2,b:b0,back:b10,dpdown:h0.4,dpleft:h0.8,dpright:h0.2,dpup:h0.1,guide:b8,leftshoulder:b5,lefttrigger:b4,leftx:a0,lefty:a1,rightshoulder:b7,righttrigger:b6,start:b9,x:b1,y:b3,",
"03000000222c00000225000011010000,Qanba Dragon Arcade Joystick (PS3),a:b1,b:b2,back:b8,dpdown:h0.4,dpleft:h0.8,dpright:h0.2,dpup:h0.1,guide:b12,leftshoulder:b4,leftstick:b10,lefttrigger:b6,leftx:a0,lefty:a1,rightshoulder:b5,rightstick:b11,righttrigger:b7,rightx:a2,righty:a3,start:b9,x:b0,y:b3,",
"03000000222c00000025000011010000,Qanba Dragon Arcade Joystick (PS4),a:b1,b:b2,back:b8,dpdown:h0.4,dpleft:h0.8,dpright:h0.2,dpup:h0.1,guide:b12,leftshoulder:b4,leftstick:b10,lefttrigger:a3,leftx:a0,lefty:a1,rightshoulder:b5,rightstick:b11,righttrigger:a4,rightx:a2,righty:a5,start:b9,x:b0,y:b3,",
@@ -711,25 +692,21 @@ static const char *s_GamepadMappings[] = {
"03000000222c00000020000011010000,Qanba Drone Arcade Joystick (PS4),a:b1,b:b2,back:b8,dpdown:h0.4,dpleft:h0.8,dpright:h0.2,dpup:h0.1,guide:b12,leftshoulder:b4,leftstick:b10,lefttrigger:a3,rightshoulder:b5,righttrigger:a4,start:b9,x:b0,y:b3,",
"03000000222c00000223000011010000,Qanba Obsidian Arcade Joystick (PS3),a:b1,b:b2,back:b8,dpdown:h0.4,dpleft:h0.8,dpright:h0.2,dpup:h0.1,guide:b12,leftshoulder:b4,leftstick:b10,lefttrigger:b6,leftx:a0,lefty:a1,rightshoulder:b5,rightstick:b11,righttrigger:b7,rightx:a2,righty:a3,start:b9,x:b0,y:b3,",
"03000000222c00000023000011010000,Qanba Obsidian Arcade Joystick (PS4),a:b1,b:b2,back:b8,dpdown:h0.4,dpleft:h0.8,dpright:h0.2,dpup:h0.1,guide:b12,leftshoulder:b4,leftstick:b10,lefttrigger:a3,leftx:a0,lefty:a1,rightshoulder:b5,rightstick:b11,righttrigger:a4,rightx:a2,righty:a5,start:b9,x:b0,y:b3,",
- "030000008916000001fd000024010000,Razer Onza Classic Edition,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,",
"03000000321500000204000011010000,Razer Panthera (PS3),a:b1,b:b2,back:b8,dpdown:h0.4,dpleft:h0.8,dpright:h0.2,dpup:h0.1,guide:b12,leftshoulder:b4,leftstick:b10,lefttrigger:b6,leftx:a0,lefty:a1,rightshoulder:b5,rightstick:b11,righttrigger:b7,rightx:a2,righty:a3,start:b9,x:b0,y:b3,",
"03000000321500000104000011010000,Razer Panthera (PS4),a:b1,b:b2,back:b8,dpdown:h0.4,dpleft:h0.8,dpright:h0.2,dpup:h0.1,guide:b12,leftshoulder:b4,leftstick:b10,lefttrigger:a3,leftx:a0,lefty:a1,rightshoulder:b5,rightstick:b11,righttrigger:a4,rightx:a2,righty:a5,start:b9,x:b0,y:b3,",
"03000000321500000010000011010000,Razer RAIJU,a:b1,b:b2,back:b8,dpdown:h0.4,dpleft:h0.8,dpright:h0.2,dpup:h0.1,guide:b12,leftshoulder:b4,leftstick:b10,lefttrigger:a3,leftx:a0,lefty:a1,rightshoulder:b5,rightstick:b11,righttrigger:a4,rightx:a2,righty:a5,start:b9,x:b0,y:b3,",
"03000000321500000507000000010000,Razer Raiju Mobile,a:b0,b:b1,back:b10,dpdown:h0.4,dpleft:h0.8,dpright:h0.2,dpup:h0.1,guide:b21,leftshoulder:b6,leftstick:b13,lefttrigger:a5,leftx:a0,lefty:a1,rightshoulder:b7,rightstick:b14,righttrigger:a4,rightx:a2,righty:a3,start:b11,x:b3,y:b4,",
"03000000321500000011000011010000,Razer Raion Fightpad for PS4,a:b1,b:b2,back:b8,dpdown:h0.4,dpleft:h0.8,dpright:h0.2,dpup:h0.1,guide:b12,leftshoulder:b4,leftstick:b10,lefttrigger:a3,leftx:a0,lefty:a1,rightshoulder:b5,rightstick:b11,righttrigger:a4,rightx:a2,righty:a5,start:b9,x:b0,y:b3,",
- "030000008916000000fe000024010000,Razer Sabertooth,a:b0,b:b1,back:b6,dpdown:h0.4,dpleft:h0.8,dpright:h0.2,dpup:h0.1,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,",
- "03000000c6240000045d000024010000,Razer Sabertooth,a:b0,b:b1,back:b6,dpdown:h0.4,dpleft:h0.8,dpright:h0.2,dpup:h0.1,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,",
- "03000000c6240000045d000025010000,Razer Sabertooth,a:b0,b:b1,back:b6,dpdown:h0.4,dpleft:h0.8,dpright:h0.2,dpup:h0.1,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,",
"03000000321500000009000011010000,Razer Serval,a:b0,b:b1,back:b6,dpdown:h0.4,dpleft:h0.8,dpright:h0.2,dpup:h0.1,guide:b8,leftshoulder:b4,leftstick:b9,lefttrigger:a5,leftx:a0,lefty:a1,rightshoulder:b5,rightstick:b10,righttrigger:a4,rightx:a2,righty:a3,start:b7,x:b2,y:b3,",
"050000003215000000090000163a0000,Razer Serval,a:b0,b:b1,back:b6,dpdown:h0.4,dpleft:h0.8,dpright:h0.2,dpup:h0.1,guide:b8,leftshoulder:b4,leftstick:b9,lefttrigger:a5,leftx:a0,lefty:a1,rightshoulder:b5,rightstick:b10,righttrigger:a4,rightx:a2,righty:a3,start:b7,x:b2,y:b3,",
- "0300000032150000030a000001010000,Razer Wildcat,a:b0,b:b1,back:b6,dpdown:h0.4,dpleft:h0.8,dpright:h0.2,dpup:h0.1,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,",
+ "03000000632500007805000011010000,Retro Fighters D6,a:b2,b:b1,back:b8,crc:80d7,dpdown:h0.4,dpleft:h0.8,dpright:h0.2,dpup:h0.1,guide:b12,leftshoulder:b4,lefttrigger:b6,leftx:a0,lefty:a1,misc1:b10,rightshoulder:b5,righttrigger:b7,rightx:a2,righty:a3,start:b9,x:b3,y:b0"
+ "03000000790000001600000011010000,Retro Fighters D6,a:b1,b:b2,back:b8,crc:80d7,leftshoulder:b4,lefttrigger:b6,leftx:a0,lefty:a1,rightshoulder:b5,righttrigger:b7,start:b9,x:b0,y:b3"
+ "03000000632500007505000011010000,Retro Fighters Defender Pro,crc:430b,a:b1,b:b2,back:b8,dpdown:h0.4,dpleft:h0.8,dpright:h0.2,dpup:h0.1,leftshoulder:b4,leftstick:b10,lefttrigger:b6,leftx:a0,lefty:a1,rightshoulder:b5,rightstick:b11,righttrigger:b7,rightx:a2,righty:a3,start:b9,x:b0,y:b3,",
"0300000000f000000300000000010000,RetroPad,a:b1,b:b5,back:b2,leftshoulder:b6,leftx:a0,lefty:a1,rightshoulder:b7,start:b3,x:b0,y:b4,",
"03000000790000001100000010010000,Retrolink SNES Controller,a:b2,b:b1,back:b8,dpdown:+a1,dpleft:-a0,dpright:+a0,dpup:-a1,leftshoulder:b4,rightshoulder:b5,start:b9,x:b3,y:b0,hint:!SDL_GAMECONTROLLER_USE_BUTTON_LABELS:=1,",
"030000006b140000130d000011010000,Revolution Pro Controller 3,a:b1,b:b2,back:b8,dpdown:h0.4,dpleft:h0.8,dpright:h0.2,dpup:h0.1,guide:b12,leftshoulder:b4,leftstick:b10,lefttrigger:a3,leftx:a0,lefty:a1,rightshoulder:b5,rightstick:b11,righttrigger:a4,rightx:a2,righty:a5,start:b9,x:b0,y:b3,",
"030000006b140000010d000011010000,Revolution Pro Controller,a:b1,b:b2,back:b8,dpdown:h0.4,dpleft:h0.8,dpright:h0.2,dpup:h0.1,guide:b12,leftshoulder:b4,leftstick:b10,lefttrigger:a3,leftx:a0,lefty:a1,rightshoulder:b5,rightstick:b11,righttrigger:a4,rightx:a2,righty:a5,start:b9,x:b0,y:b3,",
"030000006f0e00001e01000011010000,Rock Candy PS3 Controller,a:b1,b:b2,back:b8,dpdown:h0.4,dpleft:h0.8,dpright:h0.2,dpup:h0.1,guide:b12,leftshoulder:b4,leftstick:b10,lefttrigger:b6,leftx:a0,lefty:a1,rightshoulder:b5,rightstick:b11,righttrigger:b7,rightx:a2,righty:a3,start:b9,x:b0,y:b3,",
- "030000006f0e00004601000001010000,Rock Candy Xbox One Controller,a:b0,b:b1,back:b6,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,",
- "030000006f0e00001f01000000010000,Rock Candy,a:b0,b:b1,back:b6,dpdown:h0.4,dpleft:h0.8,dpright:h0.2,dpup:h0.1,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,",
"03000000632500007505000010010000,SHANWAN PS3/PC Gamepad,a:b2,b:b1,back:b8,dpdown:h0.4,dpleft:h0.8,dpright:h0.2,dpup:h0.1,guide:b12,leftshoulder:b4,leftstick:b10,lefttrigger:b6,leftx:a0,lefty:a1,rightshoulder:b5,rightstick:b11,righttrigger:b7,rightx:a2,righty:a3,start:b9,x:b3,y:b0,",
"03000000341a00000908000010010000,SL-6566,a:b0,b:b1,back:b8,dpdown:h0.4,dpleft:h0.8,dpright:h0.2,dpup:h0.1,guide:,leftshoulder:b4,leftstick:b10,lefttrigger:b6,leftx:a0,lefty:a1,rightshoulder:b5,rightstick:b11,righttrigger:b7,rightx:a2,righty:a3,start:b9,x:b2,y:b3,",
"03000000457500002211000010010000,SZMY-POWER PC Gamepad,a:b1,b:b2,back:b8,dpdown:h0.4,dpleft:h0.8,dpright:h0.2,dpup:h0.1,guide:b12,leftshoulder:b4,leftstick:b10,lefttrigger:b6,leftx:a0,lefty:a1,rightshoulder:b5,rightstick:b11,righttrigger:b7,rightx:a2,righty:a3,start:b9,x:b0,y:b3,",
@@ -753,12 +730,11 @@ static const char *s_GamepadMappings[] = {
"05000000de2800000212000001000000,Steam Controller,a:b0,b:b1,back:b6,dpdown:b14,dpleft:b15,dpright:b13,dpup:b12,guide:b8,leftshoulder:b4,leftstick:b9,lefttrigger:a2,leftx:a0,lefty:a1,paddle1:b11,paddle2:b10,rightshoulder:b5,righttrigger:a3,start:b7,x:b2,y:b3,",
"05000000de2800000511000001000000,Steam Controller,a:b0,b:b1,back:b6,dpdown:b14,dpleft:b15,dpright:b13,dpup:b12,guide:b8,leftshoulder:b4,leftstick:b9,lefttrigger:a2,leftx:a0,lefty:a1,paddle1:b11,paddle2:b10,rightshoulder:b5,righttrigger:a3,start:b7,x:b2,y:b3,",
"05000000de2800000611000001000000,Steam Controller,a:b0,b:b1,back:b6,dpdown:b14,dpleft:b15,dpright:b13,dpup:b12,guide:b8,leftshoulder:b4,leftstick:b9,lefttrigger:a2,leftx:a0,lefty:a1,paddle1:b11,paddle2:b10,rightshoulder:b5,righttrigger:a3,start:b7,x:b2,y:b3,",
- "03000000de2800000512000000016800,Steam Deck Controller,a:b0,b:b1,back:b4,dpdown:h0.4,dpleft:h0.8,dpright:h0.2,dpup:h0.1,guide:b5,leftshoulder:b9,leftstick:b7,lefttrigger:a4,leftx:a0,lefty:a1,misc1:b11,paddle1:b12,paddle2:b13,paddle3:b14,paddle4:b15,rightshoulder:b10,rightstick:b8,righttrigger:a5,rightx:a2,righty:a3,start:b6,x:b2,y:b3,",
+ "03000000de2800000512000000016800,Steam Deck Controller,a:b0,b:b1,back:b4,dpdown:h0.4,dpleft:h0.8,dpright:h0.2,dpup:h0.1,guide:b5,leftshoulder:b9,leftstick:b7,lefttrigger:a4,leftx:a0,lefty:a1,misc1:b11,paddle1:b12,paddle2:b13,paddle3:b14,paddle4:b15,touchpad:b17,misc2:b16,misc3:b19,misc4:b18,rightshoulder:b10,rightstick:b8,righttrigger:a5,rightx:a2,righty:a3,start:b6,x:b2,y:b3,",
"03000000de2800000512000011010000,Steam Deck,a:b3,b:b4,back:b11,dpdown:b17,dpleft:b18,dpright:b19,dpup:b16,guide:b13,leftshoulder:b7,leftstick:b14,lefttrigger:a9,leftx:a0,lefty:a1,misc1:b2,paddle1:b21,paddle2:b20,paddle3:b23,paddle4:b22,rightshoulder:b8,rightstick:b15,righttrigger:a8,rightx:a2,righty:a3,start:b12,x:b5,y:b6,",
"03000000de280000ff11000001000000,Steam Virtual Gamepad,a:b0,b:b1,back:b6,dpdown:h0.4,dpleft:h0.8,dpright:h0.2,dpup:h0.1,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,",
"0500000011010000311400001b010000,SteelSeries Stratus Duo,a:b0,b:b1,back:b10,dpdown:h0.4,dpleft:h0.8,dpright:h0.2,dpup:h0.1,guide:b32,leftshoulder:b6,leftstick:b13,lefttrigger:a5,leftx:a0,lefty:a1,rightshoulder:b7,rightstick:b14,righttrigger:a4,rightx:a2,righty:a3,start:b11,x:b3,y:b4,",
"05000000110100001914000009010000,SteelSeries Stratus XL,a:b0,b:b1,back:b17,dpdown:h0.4,dpleft:h0.8,dpright:h0.2,dpup:h0.1,guide:b18,leftshoulder:b6,leftstick:b13,lefttrigger:+a5,leftx:a0,lefty:a1,rightshoulder:b7,rightstick:b14,righttrigger:+a4,rightx:a2,righty:a3,start:b11,x:b3,y:b4,",
- "03000000ad1b000038f0000090040000,Street Fighter IV FightStick TE,a:b0,b:b1,back:b6,dpdown:h0.4,dpleft:h0.8,dpright:h0.2,dpup:h0.1,guide:b8,leftshoulder:b4,lefttrigger:a2,leftx:a0,lefty:a1,rightshoulder:b5,righttrigger:a5,rightx:a3,righty:a4,start:b7,x:b2,y:b3,",
"03000000666600000488000000010000,Super Joy Box 5 Pro,a:b2,b:b1,back:b9,dpdown:b14,dpleft:b15,dpright:b13,dpup:b12,leftshoulder:b6,leftstick:b10,lefttrigger:b4,leftx:a0,lefty:a1,rightshoulder:b7,rightstick:b11,righttrigger:b5,rightx:a2,righty:a3,start:b8,x:b3,y:b0,",
"0300000000f00000f100000000010000,Super RetroPort,a:b1,b:b5,back:b2,leftshoulder:b6,leftx:a0,lefty:a1,rightshoulder:b7,start:b3,x:b0,y:b4,",
"030000004f0400000ed0000011010000,ThrustMaster eSwap PRO Controller,a:b1,b:b2,back:b8,dpdown:h0.4,dpleft:h0.8,dpright:h0.2,dpup:h0.1,guide:b12,leftshoulder:b4,leftstick:b10,lefttrigger:a3,leftx:a0,lefty:a1,rightshoulder:b5,rightstick:b11,righttrigger:a4,rightx:a2,righty:a5,start:b9,x:b0,y:b3,",
@@ -790,6 +766,7 @@ static const char *s_GamepadMappings[] = {
"03000000120c0000100e000011010000,ZEROPLUS P4 Gamepad,a:b1,b:b2,back:b8,dpdown:h0.4,dpleft:h0.8,dpright:h0.2,dpup:h0.1,guide:b12,leftshoulder:b4,leftstick:b10,lefttrigger:a3,leftx:a0,lefty:a1,rightshoulder:b5,rightstick:b11,righttrigger:a4,rightx:a2,righty:a5,start:b9,x:b0,y:b3,",
"03000000120c0000101e000011010000,ZEROPLUS P4 Wired Gamepad,a:b1,b:b2,back:b8,dpdown:h0.4,dpleft:h0.8,dpright:h0.2,dpup:h0.1,guide:b12,leftshoulder:b4,leftstick:b10,lefttrigger:a3,leftx:a0,lefty:a1,rightshoulder:b5,rightstick:b11,righttrigger:a4,rightx:a2,righty:a5,start:b9,x:b0,y:b3,",
"03000000120c0000182e000011010000,ZEROPLUS P4 Wired Gamepad,a:b1,b:b2,back:b8,dpdown:h0.4,dpleft:h0.8,dpright:h0.2,dpup:h0.1,guide:b12,leftshoulder:b4,leftstick:b10,lefttrigger:a3,leftx:a0,lefty:a1,rightshoulder:b5,rightstick:b11,righttrigger:a4,rightx:a2,righty:a5,start:b9,x:b0,y:b3,",
+ "03000000790000002201000011010000,ZhiXu GuliKit Controller D,a:b0,b:b1,back:b8,dpdown:h0.4,dpleft:h0.8,dpright:h0.2,dpup:h0.1,leftshoulder:b4,leftstick:b10,lefttrigger:b6,leftx:a0,lefty:a1,rightshoulder:b5,rightstick:b11,righttrigger:b7,rightx:a2,righty:a3,start:b9,x:b2,y:b3,",
"03000000666600006706000000010000,boom PSX to PC Converter,a:b2,b:b1,back:b8,dpdown:b14,dpleft:b15,dpright:b13,dpup:b12,leftshoulder:b6,leftstick:b9,lefttrigger:b4,leftx:a0,lefty:a1,rightshoulder:b7,rightstick:b10,righttrigger:b5,rightx:a2,righty:a3,start:b11,x:b3,y:b0,",
"03000000830500006020000010010000,iBuffalo SNES Controller,a:b1,b:b0,back:b6,dpdown:+a1,dpleft:-a0,dpright:+a0,dpup:-a1,leftshoulder:b4,rightshoulder:b5,start:b7,x:b3,y:b2,hint:!SDL_GAMECONTROLLER_USE_BUTTON_LABELS:=1,",
"050000006964726f69643a636f6e0000,idroid:con,a:b1,b:b2,back:b8,dpdown:h0.4,dpleft:h0.8,dpright:h0.2,dpup:h0.1,leftshoulder:b4,leftstick:b10,lefttrigger:b6,leftx:a0,lefty:a1,rightshoulder:b5,rightstick:b11,righttrigger:b7,rightx:a2,righty:a3,start:b9,x:b0,y:b3,",
@@ -849,8 +826,8 @@ static const char *s_GamepadMappings[] = {
"050000005e040000fd020000ff7f3f00,Xbox One S Controller,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,",
"050000005e040000e00200000ffe3f80,Xbox One Wireless Controller,a:b0,b:b1,back:b9,dpdown:b12,dpleft:b13,dpright:b14,dpup:b11,leftshoulder:b3,leftstick:b15,lefttrigger:a4,leftx:a0,lefty:a1,rightshoulder:b18,rightstick:b16,righttrigger:a5,rightx:a2,righty:a3,start:b10,x:b17,y:b2,",
"050000005e040000fd020000ffff3f00,Xbox One Wireless Controller,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,",
- "050000005e040000120b000000783f80,Xbox Series X Controller,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,",
- "050000005e040000130b0000ffff3f00,Xbox Series X Controller,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,",
+ "050000005e040000120b000000783f80,Xbox Series X Controller,a:b0,b:b1,back:b4,misc1:b15,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,",
+ "050000005e040000130b0000ffff3f00,Xbox Series X Controller,a:b0,b:b1,back:b4,misc1:b15,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,",
"050000005e04000091020000ff073f80,Xbox Wireless Controller,a:b0,b:b1,back:b4,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,", /* The DPAD doesn't seem to work on this controller on Android TV? */
"050000001727000044310000ffff3f80,XiaoMi Game Controller,a:b0,b:b1,back:b4,dpdown:b12,dpleft:b13,dpright:b14,dpup:b11,leftshoulder:b9,leftstick:b7,lefttrigger:a7,leftx:a0,lefty:a1,rightshoulder:b10,rightstick:b8,righttrigger:a6,rightx:a4,righty:a5,start:b6,x:b2,y:b3,",
"0500000083050000602000000ffe0000,iBuffalo SNES Controller,a:b1,b:b0,back:b9,dpdown:b12,dpleft:b13,dpright:b14,dpup:b11,leftshoulder:b15,rightshoulder:b16,start:b10,x:b3,y:b2,hint:!SDL_GAMECONTROLLER_USE_BUTTON_LABELS:=1,",
@@ -880,6 +857,8 @@ static const char *s_GamepadMappings[] = {
"050000004c050000cc090000ff870001,PS4 Controller,a:b0,b:b1,back:b8,dpdown:h0.4,dpleft:h0.8,dpright:h0.2,dpup:h0.1,guide:b9,leftshoulder:b4,leftstick:b6,lefttrigger:a2,leftx:a0,lefty:a1,rightshoulder:b5,rightstick:b7,righttrigger:a5,rightx:a3,righty:a4,start:b10,touchpad:b11,x:b2,y:b3,",
"050000004c050000e60c0000df870000,PS5 Controller,a:b0,b:b1,back:b8,dpdown:h0.4,dpleft:h0.8,dpright:h0.2,dpup:h0.1,leftshoulder:b4,leftstick:b6,lefttrigger:a2,leftx:a0,lefty:a1,rightshoulder:b5,rightstick:b7,righttrigger:a5,rightx:a3,righty:a4,start:b9,touchpad:b10,x:b2,y:b3,",
"050000004c050000e60c0000ff870000,PS5 Controller,a:b0,b:b1,back:b8,dpdown:h0.4,dpleft:h0.8,dpright:h0.2,dpup:h0.1,guide:b9,leftshoulder:b4,leftstick:b6,lefttrigger:a2,leftx:a0,lefty:a1,rightshoulder:b5,rightstick:b7,righttrigger:a5,rightx:a3,righty:a4,start:b10,touchpad:b11,x:b2,y:b3,",
+ "05000000ac050000040000008e586d04,PlayStation VR2 Sense Controller (L),crc:9342,+leftx:+a3,+lefty:+a1,-leftx:+a2,-lefty:+a4,back:b2,leftstick:b4,lefttrigger:+a7,paddle2:b3,x:b0,y:b1,",
+ "05000000ac050000040000000eb86d04,PlayStation VR2 Sense Controller (R),crc:334b,+rightx:+a3,+righty:+a1,-rightx:+a2,-righty:+a4,a:b0,b:b1,paddle1:b3,rightstick:b4,righttrigger:+a7,start:b2,",
"05000000ac0500000300000043006d03,Remote,a:b0,b:b2,leftx:a0,lefty:a1,",
"050000005e040000050b0000df070001,Xbox Elite Wireless Controller,a:b0,b:b1,back:b8,dpdown:h0.4,dpleft:h0.8,dpright:h0.2,dpup:h0.1,leftshoulder:b4,leftstick:b6,lefttrigger:a2,leftx:a0,lefty:a1,paddle1:b10,paddle2:b12,paddle3:b11,paddle4:b13,rightshoulder:b5,rightstick:b7,righttrigger:a5,rightx:a3,righty:a4,start:b9,x:b2,y:b3,",
"050000005e040000050b0000ff070001,Xbox Elite Wireless Controller,a:b0,b:b1,back:b8,dpdown:h0.4,dpleft:h0.8,dpright:h0.2,dpup:h0.1,guide:b9,leftshoulder:b4,leftstick:b6,lefttrigger:a2,leftx:a0,lefty:a1,paddle1:b11,paddle2:b13,paddle3:b12,paddle4:b14,rightshoulder:b5,rightstick:b7,righttrigger:a5,rightx:a3,righty:a4,start:b10,x:b2,y:b3,",
@@ -889,7 +868,7 @@ static const char *s_GamepadMappings[] = {
"050000005e040000e0020000ff070000,Xbox Wireless Controller,a:b0,b:b1,back:b8,dpdown:h0.4,dpleft:h0.8,dpright:h0.2,dpup:h0.1,guide:b9,leftshoulder:b4,leftstick:b6,lefttrigger:a2,leftx:a0,lefty:a1,rightshoulder:b5,rightstick:b7,righttrigger:a5,rightx:a3,righty:a4,start:b10,x:b2,y:b3,",
#endif
#ifdef SDL_JOYSTICK_EMSCRIPTEN
- "default,Standard Gamepad,a:b0,b:b1,back:b8,dpdown:b13,dpleft:b14,dpright:b15,dpup:b12,guide:b16,leftshoulder:b4,leftstick:b10,lefttrigger:b6,leftx:a0,lefty:a1,rightshoulder:b5,rightstick:b11,righttrigger:b7,rightx:a2,righty:a3,start:b9,x:b2,y:b3,",
+ "default,*,a:b0,b:b1,back:b6,dpdown:h0.4,dpleft:h0.8,dpright:h0.2,dpup:h0.1,guide:b10,leftshoulder:b4,leftstick:b8,lefttrigger:a4,leftx:a0,lefty:a1,rightshoulder:b5,rightstick:b9,righttrigger:a5,rightx:a2,righty:a3,start:b7,x:b2,y:b3,",
#endif
#ifdef SDL_JOYSTICK_PS2
"0000000050533220436f6e74726f6c00,PS2 Controller,crc:ed87,a:b14,b:b13,back:b0,dpdown:b6,dpleft:b7,dpright:b5,dpup:b4,leftshoulder:b10,leftstick:b1,lefttrigger:b8,leftx:a0,lefty:a1,rightshoulder:b11,rightstick:b2,righttrigger:b9,rightx:a2,righty:a3,start:b3,x:b15,y:b12,",
diff --git a/thirdparty/sdl/joystick/SDL_joystick.c b/thirdparty/sdl/joystick/SDL_joystick.c
index 768f8f9025b..cf08c30b861 100644
--- a/thirdparty/sdl/joystick/SDL_joystick.c
+++ b/thirdparty/sdl/joystick/SDL_joystick.c
@@ -1,6 +1,6 @@
/*
Simple DirectMedia Layer
- Copyright (C) 1997-2025 Sam Lantinga <[email protected]>
+ Copyright (C) 1997-2026 Sam Lantinga <[email protected]>
This software is provided 'as-is', without any express or implied
warranty. In no event will the authors be held liable for any damages
@@ -29,7 +29,7 @@
#include "SDL_steam_virtual_gamepad.h"
#include "../events/SDL_events_c.h"
-//#include "../video/SDL_sysvideo.h"
+// #include "../video/SDL_sysvideo.h"
#include "../sensor/SDL_sensor_c.h"
#include "hidapi/SDL_hidapijoystick_c.h"
@@ -123,8 +123,175 @@ static bool SDL_joystick_being_added;
static SDL_Joystick *SDL_joysticks SDL_GUARDED_BY(SDL_joystick_lock) = NULL;
static int SDL_joystick_player_count SDL_GUARDED_BY(SDL_joystick_lock) = 0;
static SDL_JoystickID *SDL_joystick_players SDL_GUARDED_BY(SDL_joystick_lock) = NULL;
+static SDL_HashTable *SDL_joystick_names SDL_GUARDED_BY(SDL_joystick_lock) = NULL;
static bool SDL_joystick_allows_background_events = false;
+static Uint32 initial_old_xboxone_controllers[] = {
+ MAKE_VIDPID(0x0000, 0x6686),
+ MAKE_VIDPID(0x0079, 0x18a1),
+ MAKE_VIDPID(0x0079, 0x18c2),
+ MAKE_VIDPID(0x0079, 0x18c8),
+ MAKE_VIDPID(0x0079, 0x18cf),
+ MAKE_VIDPID(0x03f0, 0x0495),
+ MAKE_VIDPID(0x045e, 0x02d1),
+ MAKE_VIDPID(0x045e, 0x02dd),
+ MAKE_VIDPID(0x045e, 0x02e0),
+ MAKE_VIDPID(0x045e, 0x02e3),
+ MAKE_VIDPID(0x045e, 0x02ea),
+ MAKE_VIDPID(0x045e, 0x02fd),
+ MAKE_VIDPID(0x045e, 0x02ff),
+ MAKE_VIDPID(0x045e, 0x0867),
+ MAKE_VIDPID(0x045e, 0x0b00),
+ MAKE_VIDPID(0x045e, 0x0b05),
+ MAKE_VIDPID(0x045e, 0x0b0a),
+ MAKE_VIDPID(0x045e, 0x0b0c),
+ MAKE_VIDPID(0x045e, 0x0b20),
+ MAKE_VIDPID(0x045e, 0x0b21),
+ MAKE_VIDPID(0x045e, 0x0b22),
+ MAKE_VIDPID(0x046d, 0x0000),
+ MAKE_VIDPID(0x046d, 0x1004),
+ MAKE_VIDPID(0x046d, 0x1007),
+ MAKE_VIDPID(0x046d, 0x1008),
+ MAKE_VIDPID(0x046d, 0xf301),
+ MAKE_VIDPID(0x0738, 0x02a0),
+ MAKE_VIDPID(0x0738, 0x4a01),
+ MAKE_VIDPID(0x0738, 0x7263),
+ MAKE_VIDPID(0x0738, 0xb738),
+ MAKE_VIDPID(0x0738, 0xcb29),
+ MAKE_VIDPID(0x0738, 0xf401),
+ MAKE_VIDPID(0x0c12, 0x0e17),
+ MAKE_VIDPID(0x0c12, 0x0e1c),
+ MAKE_VIDPID(0x0c12, 0x0e22),
+ MAKE_VIDPID(0x0c12, 0x0e30),
+ MAKE_VIDPID(0x0d62, 0x9a1a),
+ MAKE_VIDPID(0x0d62, 0x9a1b),
+ MAKE_VIDPID(0x0e00, 0x0e00),
+ MAKE_VIDPID(0x0e6f, 0x012a),
+ MAKE_VIDPID(0x0e6f, 0x0139),
+ MAKE_VIDPID(0x0e6f, 0x013B),
+ MAKE_VIDPID(0x0e6f, 0x013a),
+ MAKE_VIDPID(0x0e6f, 0x0145),
+ MAKE_VIDPID(0x0e6f, 0x0146),
+ MAKE_VIDPID(0x0e6f, 0x0152),
+ MAKE_VIDPID(0x0e6f, 0x015b),
+ MAKE_VIDPID(0x0e6f, 0x015c),
+ MAKE_VIDPID(0x0e6f, 0x015d),
+ MAKE_VIDPID(0x0e6f, 0x015f),
+ MAKE_VIDPID(0x0e6f, 0x0160),
+ MAKE_VIDPID(0x0e6f, 0x0161),
+ MAKE_VIDPID(0x0e6f, 0x0162),
+ MAKE_VIDPID(0x0e6f, 0x0163),
+ MAKE_VIDPID(0x0e6f, 0x0164),
+ MAKE_VIDPID(0x0e6f, 0x0165),
+ MAKE_VIDPID(0x0e6f, 0x0166),
+ MAKE_VIDPID(0x0e6f, 0x0167),
+ MAKE_VIDPID(0x0e6f, 0x0205),
+ MAKE_VIDPID(0x0e6f, 0x0206),
+ MAKE_VIDPID(0x0e6f, 0x0246),
+ MAKE_VIDPID(0x0e6f, 0x0261),
+ MAKE_VIDPID(0x0e6f, 0x0262),
+ MAKE_VIDPID(0x0e6f, 0x02a0),
+ MAKE_VIDPID(0x0e6f, 0x02a1),
+ MAKE_VIDPID(0x0e6f, 0x02a2),
+ MAKE_VIDPID(0x0e6f, 0x02a3),
+ MAKE_VIDPID(0x0e6f, 0x02a4),
+ MAKE_VIDPID(0x0e6f, 0x02a5),
+ MAKE_VIDPID(0x0e6f, 0x02a6),
+ MAKE_VIDPID(0x0e6f, 0x02a7),
+ MAKE_VIDPID(0x0e6f, 0x02a8),
+ MAKE_VIDPID(0x0e6f, 0x02a9),
+ MAKE_VIDPID(0x0e6f, 0x02aa),
+ MAKE_VIDPID(0x0e6f, 0x02ab),
+ MAKE_VIDPID(0x0e6f, 0x02ac),
+ MAKE_VIDPID(0x0e6f, 0x02ad),
+ MAKE_VIDPID(0x0e6f, 0x02ae),
+ MAKE_VIDPID(0x0e6f, 0x02af),
+ MAKE_VIDPID(0x0e6f, 0x02b0),
+ MAKE_VIDPID(0x0e6f, 0x02b1),
+ MAKE_VIDPID(0x0e6f, 0x02b2),
+ MAKE_VIDPID(0x0e6f, 0x02b3),
+ MAKE_VIDPID(0x0e6f, 0x02b5),
+ MAKE_VIDPID(0x0e6f, 0x02b6),
+ MAKE_VIDPID(0x0e6f, 0x02b8),
+ MAKE_VIDPID(0x0e6f, 0x02bd),
+ MAKE_VIDPID(0x0e6f, 0x02be),
+ MAKE_VIDPID(0x0e6f, 0x02bf),
+ MAKE_VIDPID(0x0e6f, 0x02c0),
+ MAKE_VIDPID(0x0e6f, 0x02c1),
+ MAKE_VIDPID(0x0e6f, 0x02c2),
+ MAKE_VIDPID(0x0e6f, 0x02c3),
+ MAKE_VIDPID(0x0e6f, 0x02c4),
+ MAKE_VIDPID(0x0e6f, 0x02c5),
+ MAKE_VIDPID(0x0e6f, 0x02c6),
+ MAKE_VIDPID(0x0e6f, 0x02c7),
+ MAKE_VIDPID(0x0e6f, 0x02c8),
+ MAKE_VIDPID(0x0e6f, 0x02c9),
+ MAKE_VIDPID(0x0e6f, 0x02ca),
+ MAKE_VIDPID(0x0e6f, 0x02cb),
+ MAKE_VIDPID(0x0e6f, 0x02cd),
+ MAKE_VIDPID(0x0e6f, 0x02ce),
+ MAKE_VIDPID(0x0e6f, 0x02cf),
+ MAKE_VIDPID(0x0e6f, 0x02d5),
+ MAKE_VIDPID(0x0e6f, 0x0346),
+ MAKE_VIDPID(0x0e6f, 0x0446),
+ MAKE_VIDPID(0x0e6f, 0xf501),
+ MAKE_VIDPID(0x0f0d, 0x0063),
+ MAKE_VIDPID(0x0f0d, 0x0067),
+ MAKE_VIDPID(0x0f0d, 0x0078),
+ MAKE_VIDPID(0x0f0d, 0x0097),
+ MAKE_VIDPID(0x0f0d, 0x00ba),
+ MAKE_VIDPID(0x0f0d, 0x00c0),
+ MAKE_VIDPID(0x0f0d, 0x00c5),
+ MAKE_VIDPID(0x0f0d, 0x00d8),
+ MAKE_VIDPID(0x0f0d, 0x00ed),
+ MAKE_VIDPID(0x0fff, 0x02a1),
+ MAKE_VIDPID(0x12ab, 0x0304),
+ MAKE_VIDPID(0x1430, 0x0291),
+ MAKE_VIDPID(0x1430, 0x02a9),
+ MAKE_VIDPID(0x1430, 0x070b),
+ MAKE_VIDPID(0x1430, 0x0719),
+ MAKE_VIDPID(0x146b, 0x0611),
+ MAKE_VIDPID(0x1532, 0x0a00),
+ MAKE_VIDPID(0x1532, 0x0a03),
+ MAKE_VIDPID(0x1532, 0x0a14),
+ MAKE_VIDPID(0x1532, 0x0a15),
+ MAKE_VIDPID(0x16d0, 0x0f3f),
+ MAKE_VIDPID(0x1bad, 0x028e),
+ MAKE_VIDPID(0x1bad, 0x02a0),
+ MAKE_VIDPID(0x1bad, 0x5500),
+ MAKE_VIDPID(0x20ab, 0x55ef),
+ MAKE_VIDPID(0x24c6, 0x541a),
+ MAKE_VIDPID(0x24c6, 0x542a),
+ MAKE_VIDPID(0x24c6, 0x543a),
+ MAKE_VIDPID(0x24c6, 0x5509),
+ MAKE_VIDPID(0x24c6, 0x551a),
+ MAKE_VIDPID(0x24c6, 0x561a),
+ MAKE_VIDPID(0x24c6, 0x581a),
+ MAKE_VIDPID(0x24c6, 0x591a),
+ MAKE_VIDPID(0x24c6, 0x592a),
+ MAKE_VIDPID(0x24c6, 0x791a),
+ MAKE_VIDPID(0x2516, 0x0069),
+ MAKE_VIDPID(0x25b1, 0x0360),
+ MAKE_VIDPID(0x2c22, 0x2203),
+ MAKE_VIDPID(0x2e24, 0x0652),
+ MAKE_VIDPID(0x2e24, 0x1618),
+ MAKE_VIDPID(0x2e24, 0x1688),
+ MAKE_VIDPID(0x2f24, 0x0011),
+ MAKE_VIDPID(0x2f24, 0x002e),
+ MAKE_VIDPID(0x2f24, 0x0050),
+ MAKE_VIDPID(0x2f24, 0x0053),
+ MAKE_VIDPID(0x2f24, 0x008f),
+ MAKE_VIDPID(0x2f24, 0x0091),
+ MAKE_VIDPID(0x2f24, 0x00b7),
+ MAKE_VIDPID(0xd2d2, 0xd2d2),
+};
+static SDL_vidpid_list old_xboxone_controllers = {
+ "SDL_JOYSTICK_OLD_XBOXONE_CONTROLLERS", 0, 0, NULL,
+ "SDL_JOYSTICK_OLD_XBOXONE_CONTROLLERS_EXCLUDED", 0, 0, NULL,
+ SDL_arraysize(initial_old_xboxone_controllers), initial_old_xboxone_controllers,
+ false
+};
+
static Uint32 initial_arcadestick_devices[] = {
MAKE_VIDPID(0x0079, 0x181a), // Venom Arcade Stick
MAKE_VIDPID(0x0079, 0x181b), // Venom Arcade Stick
@@ -279,8 +446,8 @@ static Uint32 initial_blacklist_devices[] = {
MAKE_VIDPID(0x1532, 0x0282), // Razer Huntsman Mini Analog, non-functional DInput device
MAKE_VIDPID(0x20d6, 0x0002), // PowerA Enhanced Wireless Controller for Nintendo Switch (charging port only)
MAKE_VIDPID(0x256c, 0x006d), // Huion Tablet_GS1331, Huion Tablet_GS1331 Touch Strip
+ MAKE_VIDPID(0x256c, 0x006e), // Huion Tablet Kamvas Pro 22, Huion Tablet Kamvas Pro 22 Touch Strip
MAKE_VIDPID(0x26ce, 0x01a2), // ASRock LED Controller
- MAKE_VIDPID(0x31e3, 0x1310), // Wooting 60HE (ARM)
MAKE_VIDPID(0x3297, 0x1969), // Moonlander MK1 Keyboard
MAKE_VIDPID(0x3434, 0x0121), // Keychron Q3 System Control
MAKE_VIDPID(0x3434, 0x0211), // Keychron K1 Pro System Control
@@ -312,6 +479,9 @@ static Uint32 initial_flightstick_devices[] = {
MAKE_VIDPID(0x10f5, 0x7084), // Turtle Beach VelocityOne
MAKE_VIDPID(0x231d, 0x0126), // Gunfighter Mk.III 'Space Combat Edition' (right)
MAKE_VIDPID(0x231d, 0x0127), // Gunfighter Mk.III 'Space Combat Edition' (left)
+ MAKE_VIDPID(0x231d, 0x0200), // VKB Gladiator NXT Evo (grip)
+ MAKE_VIDPID(0x3344, 0x4391), // VIRPIL Controls R-VPC Stick MT-50CM3
+ MAKE_VIDPID(0x3344, 0x8390), // VIRPIL Controls L-VPC Stick MT-50CM3
MAKE_VIDPID(0x362c, 0x0001), // Yawman Arrow
};
static SDL_vidpid_list flightstick_devices = {
@@ -322,7 +492,15 @@ static SDL_vidpid_list flightstick_devices = {
};
static Uint32 initial_gamecube_devices[] = {
+ MAKE_VIDPID(0x0079, 0x1843), // DragonRise GameCube Controller Adapter
+ MAKE_VIDPID(0x0079, 0x1844), // DragonRise GameCube Controller Adapter
+ MAKE_VIDPID(0x0079, 0x1846), // DragonRise GameCube Controller Adapter
+ MAKE_VIDPID(0x057e, 0x0337), // Nintendo Wii U GameCube Controller Adapter
+ MAKE_VIDPID(0x057e, 0x2073), // Nintendo Switch 2 NSO GameCube Controller
+ MAKE_VIDPID(0x05e3, 0x0681), // Austgame GameCube to USB convertor
+ MAKE_VIDPID(0x0926, 0x8888), // Cyber Gadget GameCube Controller
MAKE_VIDPID(0x0e6f, 0x0185), // PDP Wired Fight Pad Pro for Nintendo Switch
+ MAKE_VIDPID(0x1a34, 0xf705), // GameCube {HuiJia USB box}
MAKE_VIDPID(0x20d6, 0xa711), // PowerA Wired Controller Nintendo GameCube Style
};
static SDL_vidpid_list gamecube_devices = {
@@ -352,6 +530,7 @@ static Uint32 initial_throttle_devices[] = {
MAKE_VIDPID(0x044f, 0x0404), // HOTAS Warthog Throttle
MAKE_VIDPID(0x0738, 0xa221), // Saitek Pro Flight X-56 Rhino Throttle
MAKE_VIDPID(0x10f5, 0x7085), // Turtle Beach VelocityOne Throttle
+ MAKE_VIDPID(0x3344, 0x0196), // VIRPIL Controls VPC VMAX Prime Throttle
};
static SDL_vidpid_list throttle_devices = {
SDL_HINT_JOYSTICK_THROTTLE_DEVICES, 0, 0, NULL,
@@ -430,6 +609,7 @@ static Uint32 initial_wheel_devices[] = {
MAKE_VIDPID(0x346e, 0x0004), // Moza R5 Wheelbase
MAKE_VIDPID(0x346e, 0x0005), // Moza R3 Wheelbase
MAKE_VIDPID(0x346e, 0x0006), // Moza R12 Wheelbase
+ MAKE_VIDPID(0x36e6, 0x400f), // PXN VD6 Wheelbase
};
static SDL_vidpid_list wheel_devices = {
SDL_HINT_JOYSTICK_WHEEL_DEVICES, 0, 0, NULL,
@@ -449,18 +629,18 @@ static SDL_vidpid_list zero_centered_devices = {
false
};
-#define CHECK_JOYSTICK_MAGIC(joystick, result) \
- if (!SDL_ObjectValid(joystick, SDL_OBJECT_TYPE_JOYSTICK)) { \
- SDL_InvalidParamError("joystick"); \
- SDL_UnlockJoysticks(); \
- return result; \
+#define CHECK_JOYSTICK_MAGIC(joystick, result) \
+ CHECK_PARAM(!SDL_ObjectValid(joystick, SDL_OBJECT_TYPE_JOYSTICK)) { \
+ SDL_InvalidParamError("joystick"); \
+ SDL_UnlockJoysticks(); \
+ return result; \
}
-#define CHECK_JOYSTICK_VIRTUAL(joystick, result) \
- if (!joystick->is_virtual) { \
- SDL_SetError("joystick isn't virtual"); \
- SDL_UnlockJoysticks(); \
- return result; \
+#define CHECK_JOYSTICK_VIRTUAL(joystick, result) \
+ CHECK_PARAM(!joystick->is_virtual) { \
+ SDL_SetError("joystick isn't virtual"); \
+ SDL_UnlockJoysticks(); \
+ return result; \
}
bool SDL_JoysticksInitialized(void)
@@ -665,8 +845,9 @@ bool SDL_InitJoysticks(void)
SDL_joysticks_initialized = true;
- SDL_InitGamepadMappings();
+ SDL_joystick_names = SDL_CreateHashTable(0, false, SDL_HashID, SDL_KeyMatchID, SDL_DestroyHashValue, NULL);
+ SDL_LoadVIDPIDList(&old_xboxone_controllers);
SDL_LoadVIDPIDList(&arcadestick_devices);
SDL_LoadVIDPIDList(&blacklist_devices);
SDL_LoadVIDPIDList(&flightstick_devices);
@@ -676,6 +857,8 @@ bool SDL_InitJoysticks(void)
SDL_LoadVIDPIDList(&wheel_devices);
SDL_LoadVIDPIDList(&zero_centered_devices);
+ SDL_InitGamepadMappings();
+
// See if we should allow joystick events while in the background
SDL_AddHintCallback(SDL_HINT_JOYSTICK_ALLOW_BACKGROUND_EVENTS,
SDL_JoystickAllowBackgroundEventsChanged, NULL);
@@ -811,20 +994,54 @@ const SDL_SteamVirtualGamepadInfo *SDL_GetJoystickVirtualGamepadInfoForID(SDL_Jo
/*
* Get the implementation dependent name of a joystick
*/
-const char *SDL_GetJoystickNameForID(SDL_JoystickID instance_id)
+static const char *SDL_UpdateJoystickNameForID(SDL_JoystickID instance_id)
{
SDL_JoystickDriver *driver;
int device_index;
- const char *name = NULL;
+ const char *current_name = NULL;
const SDL_SteamVirtualGamepadInfo *info;
- SDL_LockJoysticks();
+ SDL_AssertJoysticksLocked();
+
info = SDL_GetJoystickVirtualGamepadInfoForID(instance_id);
if (info) {
- name = SDL_GetPersistentString(info->name);
+ current_name = info->name;
} else if (SDL_GetDriverAndJoystickIndex(instance_id, &driver, &device_index)) {
- name = SDL_GetPersistentString(driver->GetDeviceName(device_index));
+ current_name = driver->GetDeviceName(device_index);
}
+
+ if (!SDL_joystick_names) {
+ return SDL_GetPersistentString(current_name);
+ }
+
+ char *name = NULL;
+ bool found = SDL_FindInHashTable(SDL_joystick_names, (const void *)(uintptr_t)instance_id, (const void **)&name);
+ if (!current_name) {
+ if (!found) {
+ SDL_SetError("Joystick %" SDL_PRIu32 " not found", instance_id);
+ return NULL;
+ }
+ if (!name) {
+ // SDL_strdup() failed during insert
+ SDL_OutOfMemory();
+ return NULL;
+ }
+ return name;
+ }
+
+ if (!name || SDL_strcmp(name, current_name) != 0) {
+ name = SDL_strdup(current_name);
+ SDL_InsertIntoHashTable(SDL_joystick_names, (const void *)(uintptr_t)instance_id, name, true);
+ }
+ return name;
+}
+
+const char *SDL_GetJoystickNameForID(SDL_JoystickID instance_id)
+{
+ const char *name;
+
+ SDL_LockJoysticks();
+ name = SDL_UpdateJoystickNameForID(instance_id);
SDL_UnlockJoysticks();
return name;
@@ -874,6 +1091,8 @@ static bool SDL_JoystickAxesCenteredAtZero(SDL_Joystick *joystick)
{
// printf("JOYSTICK '%s' VID/PID 0x%.4x/0x%.4x AXES: %d\n", joystick->name, vendor, product, joystick->naxes);
+ SDL_AssertJoysticksLocked();
+
if (joystick->naxes == 2) {
// Assume D-pad or thumbstick style axes are centered at 0
return true;
@@ -1020,7 +1239,7 @@ static void AttemptSensorFusion(SDL_Joystick *joystick, bool invert_sensors)
When a phone is being used as a gamepad, its orientation changes,
so adjust sensor axes to match.
*/
- //if (SDL_GetNaturalDisplayOrientation(SDL_GetPrimaryDisplay()) == SDL_ORIENTATION_LANDSCAPE) {
+ // if (SDL_GetNaturalDisplayOrientation(SDL_GetPrimaryDisplay()) == SDL_ORIENTATION_LANDSCAPE) {
if (true) {
/* When a device in landscape orientation is laid flat, the axes change
orientation as follows:
@@ -1154,8 +1373,6 @@ SDL_Joystick *SDL_OpenJoystick(SDL_JoystickID instance_id)
joystick->battery_percent = -1;
#ifdef SDL_JOYSTICK_VIRTUAL
joystick->is_virtual = (driver == &SDL_VIRTUAL_JoystickDriver);
-#else
- joystick->is_virtual = false;
#endif
if (!driver->Open(joystick, device_index)) {
@@ -1493,9 +1710,17 @@ int SDL_GetNumJoystickHats(SDL_Joystick *joystick)
*/
int SDL_GetNumJoystickBalls(SDL_Joystick *joystick)
{
- CHECK_JOYSTICK_MAGIC(joystick, -1);
+ int result;
+
+ SDL_LockJoysticks();
+ {
+ CHECK_JOYSTICK_MAGIC(joystick, -1);
+
+ result = joystick->nballs;
+ }
+ SDL_UnlockJoysticks();
- return joystick->nballs;
+ return result;
}
/*
@@ -2056,6 +2281,7 @@ void SDL_QuitJoysticks(void)
SDL_RemoveHintCallback(SDL_HINT_JOYSTICK_ALLOW_BACKGROUND_EVENTS,
SDL_JoystickAllowBackgroundEventsChanged, NULL);
+ SDL_FreeVIDPIDList(&old_xboxone_controllers);
SDL_FreeVIDPIDList(&arcadestick_devices);
SDL_FreeVIDPIDList(&blacklist_devices);
SDL_FreeVIDPIDList(&flightstick_devices);
@@ -2067,6 +2293,11 @@ void SDL_QuitJoysticks(void)
SDL_QuitGamepadMappings();
+ if (SDL_joystick_names) {
+ SDL_DestroyHashTable(SDL_joystick_names);
+ SDL_joystick_names = NULL;
+ }
+
SDL_joysticks_quitting = false;
SDL_joysticks_initialized = false;
@@ -2078,6 +2309,11 @@ static bool SDL_PrivateJoystickShouldIgnoreEvent(void)
if (SDL_joystick_allows_background_events) {
return false;
}
+
+ // if (SDL_HasWindows() && SDL_GetKeyboardFocus() == NULL) {
+ // // We have windows but we don't have focus, ignore the event.
+ // return true;
+ // }
return false;
}
@@ -2171,6 +2407,8 @@ void SDL_PrivateJoystickAdded(SDL_JoystickID instance_id)
SDL_SetJoystickIDForPlayerIndex(player_index, instance_id);
}
+ SDL_UpdateJoystickNameForID(instance_id);
+
{
SDL_Event event;
@@ -2200,7 +2438,7 @@ bool SDL_IsJoystickBeingAdded(void)
void SDL_PrivateJoystickForceRecentering(SDL_Joystick *joystick)
{
- Uint8 i, j;
+ int i, j;
Uint64 timestamp = SDL_GetTicksNS();
SDL_AssertJoysticksLocked();
@@ -2464,6 +2702,8 @@ static void SendSteamHandleUpdateEvents(void)
SDL_Joystick *joystick;
const SDL_SteamVirtualGamepadInfo *info;
+ SDL_AssertJoysticksLocked();
+
// Check to see if any Steam handles changed
for (joystick = SDL_joysticks; joystick; joystick = joystick->next) {
bool changed = false;
@@ -2784,10 +3024,14 @@ SDL_GamepadType SDL_GetGamepadTypeFromVIDPID(Uint16 vendor, Uint16 product, cons
} else if (vendor == 0x0001 && product == 0x0001) {
type = SDL_GAMEPAD_TYPE_STANDARD;
- } else if (vendor == USB_VENDOR_NINTENDO && product == USB_PRODUCT_NINTENDO_SWITCH_JOYCON_LEFT) {
+ } else if (vendor == USB_VENDOR_NINTENDO &&
+ (product == USB_PRODUCT_NINTENDO_SWITCH_JOYCON_LEFT ||
+ product == USB_PRODUCT_NINTENDO_SWITCH2_JOYCON_LEFT)) {
type = SDL_GAMEPAD_TYPE_NINTENDO_SWITCH_JOYCON_LEFT;
- } else if (vendor == USB_VENDOR_NINTENDO && product == USB_PRODUCT_NINTENDO_SWITCH_JOYCON_RIGHT) {
+ } else if (vendor == USB_VENDOR_NINTENDO &&
+ (product == USB_PRODUCT_NINTENDO_SWITCH_JOYCON_RIGHT ||
+ product == USB_PRODUCT_NINTENDO_SWITCH2_JOYCON_RIGHT)) {
if (name && SDL_strstr(name, "NES Controller") != NULL) {
// We don't have a type for the Nintendo Online NES Controller
type = SDL_GAMEPAD_TYPE_STANDARD;
@@ -2798,16 +3042,19 @@ SDL_GamepadType SDL_GetGamepadTypeFromVIDPID(Uint16 vendor, Uint16 product, cons
} else if (vendor == USB_VENDOR_NINTENDO && product == USB_PRODUCT_NINTENDO_SWITCH_JOYCON_GRIP) {
if (name && SDL_strstr(name, "(L)") != NULL) {
type = SDL_GAMEPAD_TYPE_NINTENDO_SWITCH_JOYCON_LEFT;
+ } else if (name && SDL_strstr(name, "L+R") != NULL) {
+ type = SDL_GAMEPAD_TYPE_NINTENDO_SWITCH_JOYCON_PAIR;
} else {
type = SDL_GAMEPAD_TYPE_NINTENDO_SWITCH_JOYCON_RIGHT;
}
- } else if (vendor == USB_VENDOR_NINTENDO && product == USB_PRODUCT_NINTENDO_SWITCH_JOYCON_PAIR) {
+ } else if (vendor == USB_VENDOR_NINTENDO &&
+ (product == USB_PRODUCT_NINTENDO_SWITCH_JOYCON_PAIR ||
+ product == USB_PRODUCT_NINTENDO_SWITCH2_JOYCON_PAIR)) {
type = SDL_GAMEPAD_TYPE_NINTENDO_SWITCH_JOYCON_PAIR;
} else if (forUI && SDL_IsJoystickGameCube(vendor, product)) {
- // We don't have a type for the Nintendo GameCube controller
- type = SDL_GAMEPAD_TYPE_STANDARD;
+ type = SDL_GAMEPAD_TYPE_GAMECUBE;
} else {
switch (GuessControllerType(vendor, product)) {
@@ -2841,7 +3088,7 @@ SDL_GamepadType SDL_GetGamepadTypeFromVIDPID(Uint16 vendor, Uint16 product, cons
if (forUI) {
type = SDL_GAMEPAD_TYPE_NINTENDO_SWITCH_PRO;
} else {
- type = SDL_GAMEPAD_TYPE_STANDARD;
+ type = SDL_GAMEPAD_TYPE_XBOX360;
}
break;
default:
@@ -2909,78 +3156,12 @@ bool SDL_IsJoystickXboxOneElite(Uint16 vendor_id, Uint16 product_id)
bool SDL_IsJoystickXboxSeriesX(Uint16 vendor_id, Uint16 product_id)
{
- if (vendor_id == USB_VENDOR_MICROSOFT) {
- if (product_id == USB_PRODUCT_XBOX_SERIES_X ||
- product_id == USB_PRODUCT_XBOX_SERIES_X_BLE) {
- return true;
- }
- }
- if (vendor_id == USB_VENDOR_PDP) {
- if (product_id == USB_PRODUCT_XBOX_SERIES_X_VICTRIX_GAMBIT ||
- product_id == USB_PRODUCT_XBOX_SERIES_X_PDP_BLUE ||
- product_id == USB_PRODUCT_XBOX_SERIES_X_PDP_AFTERGLOW) {
- return true;
- }
- }
- if (vendor_id == USB_VENDOR_POWERA_ALT) {
- if ((product_id >= 0x2001 && product_id <= 0x201a) ||
- product_id == USB_PRODUCT_XBOX_SERIES_X_POWERA_FUSION_PRO2 ||
- product_id == USB_PRODUCT_XBOX_SERIES_X_POWERA_FUSION_PRO4 ||
- product_id == USB_PRODUCT_XBOX_SERIES_X_POWERA_FUSION_PRO_WIRELESS_USB ||
- product_id == USB_PRODUCT_XBOX_SERIES_X_POWERA_FUSION_PRO_WIRELESS_DONGLE ||
- product_id == USB_PRODUCT_XBOX_SERIES_X_POWERA_MOGA_XP_ULTRA ||
- product_id == USB_PRODUCT_XBOX_SERIES_X_POWERA_SPECTRA) {
- return true;
- }
- }
- if (vendor_id == USB_VENDOR_HORI) {
- if (product_id == USB_PRODUCT_HORI_FIGHTING_COMMANDER_OCTA_SERIES_X ||
- product_id == USB_PRODUCT_HORI_HORIPAD_PRO_SERIES_X ||
- product_id == USB_PRODUCT_HORI_TAIKO_DRUM_CONTROLLER) {
- return true;
- }
- }
- if (vendor_id == USB_VENDOR_HP) {
- if (product_id == USB_PRODUCT_XBOX_SERIES_X_HP_HYPERX ||
- product_id == USB_PRODUCT_XBOX_SERIES_X_HP_HYPERX_RGB) {
- return true;
- }
- }
- if (vendor_id == USB_VENDOR_RAZER) {
- if (product_id == USB_PRODUCT_RAZER_WOLVERINE_V2 ||
- product_id == USB_PRODUCT_RAZER_WOLVERINE_V2_CHROMA ||
- product_id == USB_PRODUCT_RAZER_WOLVERINE_V3_PRO) {
- return true;
- }
- }
- if (vendor_id == USB_VENDOR_THRUSTMASTER) {
- if (product_id == USB_PRODUCT_THRUSTMASTER_ESWAPX_PRO_SERIES_X) {
- return true;
- }
- }
- if (vendor_id == USB_VENDOR_TURTLE_BEACH) {
- if (product_id == USB_PRODUCT_TURTLE_BEACH_SERIES_X_REACT_R ||
- product_id == USB_PRODUCT_TURTLE_BEACH_SERIES_X_RECON) {
- return true;
- }
- }
- if (vendor_id == USB_VENDOR_8BITDO) {
- if (product_id == USB_PRODUCT_8BITDO_XBOX_CONTROLLER1 ||
- product_id == USB_PRODUCT_8BITDO_XBOX_CONTROLLER2) {
- return true;
- }
- }
- if (vendor_id == USB_VENDOR_GAMESIR) {
- if (product_id == USB_PRODUCT_GAMESIR_G7) {
- return true;
- }
- }
- if (vendor_id == USB_VENDOR_ASUS) {
- if (product_id == USB_PRODUCT_ROG_RAIKIRI) {
- return true;
- }
+ // Most new controllers have the share button, so we'll default to true and
+ // have a list of older XBox One controllers that are known not to have it.
+ if (SDL_VIDPIDInList(vendor_id, product_id, &old_xboxone_controllers)) {
+ return false;
}
- return false;
+ return true;
}
bool SDL_IsJoystickBluetoothXboxOne(Uint16 vendor_id, Uint16 product_id)
@@ -3059,7 +3240,9 @@ bool SDL_IsJoystickNintendoSwitchJoyConGrip(Uint16 vendor_id, Uint16 product_id)
bool SDL_IsJoystickNintendoSwitchJoyConPair(Uint16 vendor_id, Uint16 product_id)
{
- return vendor_id == USB_VENDOR_NINTENDO && product_id == USB_PRODUCT_NINTENDO_SWITCH_JOYCON_PAIR;
+ return vendor_id == USB_VENDOR_NINTENDO &&
+ (product_id == USB_PRODUCT_NINTENDO_SWITCH_JOYCON_PAIR ||
+ product_id == USB_PRODUCT_NINTENDO_SWITCH2_JOYCON_PAIR);
}
bool SDL_IsJoystickGameCube(Uint16 vendor_id, Uint16 product_id)
@@ -3105,12 +3288,52 @@ bool SDL_IsJoystickHoriSteamController(Uint16 vendor_id, Uint16 product_id)
return vendor_id == USB_VENDOR_HORI && (product_id == USB_PRODUCT_HORI_STEAM_CONTROLLER || product_id == USB_PRODUCT_HORI_STEAM_CONTROLLER_BT);
}
+bool SDL_IsJoystickSInputController(Uint16 vendor_id, Uint16 product_id)
+{
+ if (vendor_id == USB_VENDOR_RASPBERRYPI) {
+ if (product_id == USB_PRODUCT_HANDHELDLEGEND_SINPUT_GENERIC ||
+ product_id == USB_PRODUCT_HANDHELDLEGEND_PROGCC ||
+ product_id == USB_PRODUCT_HANDHELDLEGEND_GCULTIMATE ||
+ product_id == USB_PRODUCT_BONZIRICHANNEL_FIREBIRD ||
+ product_id == USB_PRODUCT_VOIDGAMING_PS4FIREBIRD) {
+ return true;
+ }
+ }
+ if (vendor_id == USB_VENDOR_ANDGAMER) {
+ if (product_id == USB_PRODUCT_VOIDGAMING_GENESIS_SINPUT) {
+ return true;
+ }
+ }
+ return false;
+}
+
+bool SDL_IsJoystickFlydigiController(Uint16 vendor_id, Uint16 product_id)
+{
+ if (vendor_id == USB_VENDOR_FLYDIGI_V1) {
+ if (product_id == USB_PRODUCT_FLYDIGI_V1_GAMEPAD) {
+ return true;
+ }
+ }
+ if (vendor_id == USB_VENDOR_FLYDIGI_V2) {
+ if (product_id == USB_PRODUCT_FLYDIGI_V2_APEX || product_id == USB_PRODUCT_FLYDIGI_V2_VADER) {
+ return true;
+ }
+ }
+ return false;
+}
+
bool SDL_IsJoystickSteamDeck(Uint16 vendor_id, Uint16 product_id)
{
EControllerType eType = GuessControllerType(vendor_id, product_id);
return eType == k_eControllerType_SteamControllerNeptune;
}
+bool SDL_IsJoystickSteamTriton(Uint16 vendor_id, Uint16 product_id)
+{
+ EControllerType eType = GuessControllerType(vendor_id, product_id);
+ return eType == k_eControllerType_SteamControllerTriton;
+}
+
bool SDL_IsJoystickXInput(SDL_GUID guid)
{
return (guid.data[14] == 'x') ? true : false;
@@ -3121,6 +3344,11 @@ bool SDL_IsJoystickWGI(SDL_GUID guid)
return (guid.data[14] == 'w') ? true : false;
}
+bool SDL_IsJoystickGameInput(SDL_GUID guid)
+{
+ return (guid.data[14] == 'g') ? true : false;
+}
+
bool SDL_IsJoystickHIDAPI(SDL_GUID guid)
{
return (guid.data[14] == 'h') ? true : false;
@@ -3141,7 +3369,7 @@ bool SDL_IsJoystickVIRTUAL(SDL_GUID guid)
return (guid.data[14] == 'v') ? true : false;
}
-static bool SDL_IsJoystickWheel(Uint16 vendor_id, Uint16 product_id)
+bool SDL_IsJoystickWheel(Uint16 vendor_id, Uint16 product_id)
{
return SDL_VIDPIDInList(vendor_id, product_id, &wheel_devices);
}
@@ -3214,6 +3442,10 @@ static SDL_JoystickType SDL_GetJoystickGUIDType(SDL_GUID guid)
return (SDL_JoystickType)guid.data[15];
}
+ if (SDL_IsJoystickGameInput(guid)) {
+ return (SDL_JoystickType)guid.data[15];
+ }
+
if (SDL_IsJoystickVIRTUAL(guid)) {
return (SDL_JoystickType)guid.data[15];
}
@@ -3677,9 +3909,7 @@ static void SDL_LoadVIDPIDListFromHint(const char *hint, int *num_entries, int *
(*entries)[(*num_entries)++] = entry;
}
- if (file) {
- SDL_free(file);
- }
+ SDL_free(file);
}
void SDL_LoadVIDPIDListFromHints(SDL_vidpid_list *list, const char *included_list, const char *excluded_list)
@@ -3757,9 +3987,15 @@ void SDL_LoadVIDPIDList(SDL_vidpid_list *list)
if (list->included_hint_name) {
included_list = SDL_GetHint(list->included_hint_name);
+ if (!included_list) {
+ included_list = SDL_getenv_unsafe(list->included_hint_name);
+ }
}
if (list->excluded_hint_name) {
excluded_list = SDL_GetHint(list->excluded_hint_name);
+ if (!excluded_list) {
+ excluded_list = SDL_getenv_unsafe(list->excluded_hint_name);
+ }
}
SDL_LoadVIDPIDListFromHints(list, included_list, excluded_list);
}
diff --git a/thirdparty/sdl/joystick/SDL_joystick_c.h b/thirdparty/sdl/joystick/SDL_joystick_c.h
index d931cf7ed73..55665db6daf 100644
--- a/thirdparty/sdl/joystick/SDL_joystick_c.h
+++ b/thirdparty/sdl/joystick/SDL_joystick_c.h
@@ -1,6 +1,6 @@
/*
Simple DirectMedia Layer
- Copyright (C) 1997-2025 Sam Lantinga <[email protected]>
+ Copyright (C) 1997-2026 Sam Lantinga <[email protected]>
This software is provided 'as-is', without any express or implied
warranty. In no event will the authors be held liable for any damages
@@ -135,9 +135,18 @@ extern bool SDL_IsJoystickSteamController(Uint16 vendor_id, Uint16 product_id);
// Function to return whether a joystick is a HORI Steam controller
extern bool SDL_IsJoystickHoriSteamController(Uint16 vendor_id, Uint16 product_id);
+// Function to return whether a joystick is an SInput (Open Format) controller
+extern bool SDL_IsJoystickSInputController(Uint16 vendor_id, Uint16 product_id);
+
+// Function to return whether a joystick is a Flydigi controller
+extern bool SDL_IsJoystickFlydigiController(Uint16 vendor_id, Uint16 product_id);
+
// Function to return whether a joystick is a Steam Deck
extern bool SDL_IsJoystickSteamDeck(Uint16 vendor_id, Uint16 product_id);
+// Function to return whether a joystick is a Steam Triton
+extern bool SDL_IsJoystickSteamTriton(Uint16 vendor_id, Uint16 product_id);
+
// Function to return whether a joystick guid comes from the XInput driver
extern bool SDL_IsJoystickXInput(SDL_GUID guid);
@@ -156,6 +165,9 @@ extern bool SDL_IsJoystickRAWINPUT(SDL_GUID guid);
// Function to return whether a joystick guid comes from the Virtual driver
extern bool SDL_IsJoystickVIRTUAL(SDL_GUID guid);
+// Function to return whether a joystick is a wheel
+bool SDL_IsJoystickWheel(Uint16 vendor_id, Uint16 product_id);
+
// Function to return whether a joystick should be ignored
extern bool SDL_ShouldIgnoreJoystick(Uint16 vendor_id, Uint16 product_id, Uint16 version, const char *name);
diff --git a/thirdparty/sdl/joystick/SDL_steam_virtual_gamepad.c b/thirdparty/sdl/joystick/SDL_steam_virtual_gamepad.c
index e4461066400..23deb54a75c 100644
--- a/thirdparty/sdl/joystick/SDL_steam_virtual_gamepad.c
+++ b/thirdparty/sdl/joystick/SDL_steam_virtual_gamepad.c
@@ -1,6 +1,6 @@
/*
Simple DirectMedia Layer
- Copyright (C) 1997-2025 Sam Lantinga <[email protected]>
+ Copyright (C) 1997-2026 Sam Lantinga <[email protected]>
This software is provided 'as-is', without any express or implied
warranty. In no event will the authors be held liable for any damages
@@ -33,8 +33,6 @@
#include <sys/stat.h>
#endif
-#define SDL_HINT_STEAM_VIRTUAL_GAMEPAD_INFO_FILE "SteamVirtualGamepadInfo"
-
static char *SDL_steam_virtual_gamepad_info_file SDL_GUARDED_BY(SDL_joystick_lock) = NULL;
static Uint64 SDL_steam_virtual_gamepad_info_file_mtime SDL_GUARDED_BY(SDL_joystick_lock) = 0;
static Uint64 SDL_steam_virtual_gamepad_info_check_time SDL_GUARDED_BY(SDL_joystick_lock) = 0;
@@ -135,16 +133,16 @@ void SDL_InitSteamVirtualGamepadInfo(void)
return;
}
- file = SDL_GetHint(SDL_HINT_STEAM_VIRTUAL_GAMEPAD_INFO_FILE);
+ file = SDL_getenv_unsafe("SteamVirtualGamepadInfo");
if (file && *file) {
#ifdef SDL_PLATFORM_LINUX
// Older versions of Wine will blacklist the Steam Virtual Gamepad if
// it appears to have the real controller's VID/PID, so ignore this.
- const char *exe = SDL_GetExeName();
- if (exe && SDL_strcmp(exe, "wine64-preloader") == 0) {
- SDL_LogDebug(SDL_LOG_CATEGORY_INPUT, "Wine launched by Steam, ignoring %s", SDL_HINT_STEAM_VIRTUAL_GAMEPAD_INFO_FILE);
- return;
- }
+ // const char *exe = SDL_GetExeName();
+ // if (exe && SDL_strcmp(exe, "wine64-preloader") == 0) {
+ // SDL_LogDebug(SDL_LOG_CATEGORY_INPUT, "Wine launched by Steam, ignoring SteamVirtualGamepadInfo");
+ // return;
+ // }
#endif
SDL_steam_virtual_gamepad_info_file = SDL_strdup(file);
}
diff --git a/thirdparty/sdl/joystick/SDL_steam_virtual_gamepad.h b/thirdparty/sdl/joystick/SDL_steam_virtual_gamepad.h
index 65696ea2876..35135f5bd04 100644
--- a/thirdparty/sdl/joystick/SDL_steam_virtual_gamepad.h
+++ b/thirdparty/sdl/joystick/SDL_steam_virtual_gamepad.h
@@ -1,6 +1,6 @@
/*
Simple DirectMedia Layer
- Copyright (C) 1997-2025 Sam Lantinga <[email protected]>
+ Copyright (C) 1997-2026 Sam Lantinga <[email protected]>
This software is provided 'as-is', without any express or implied
warranty. In no event will the authors be held liable for any damages
diff --git a/thirdparty/sdl/joystick/SDL_sysjoystick.h b/thirdparty/sdl/joystick/SDL_sysjoystick.h
index 9b6ea65e9c1..888ef82a790 100644
--- a/thirdparty/sdl/joystick/SDL_sysjoystick.h
+++ b/thirdparty/sdl/joystick/SDL_sysjoystick.h
@@ -1,6 +1,6 @@
/*
Simple DirectMedia Layer
- Copyright (C) 1997-2025 Sam Lantinga <[email protected]>
+ Copyright (C) 1997-2026 Sam Lantinga <[email protected]>
This software is provided 'as-is', without any express or implied
warranty. In no event will the authors be held liable for any damages
diff --git a/thirdparty/sdl/joystick/apple/SDL_mfijoystick.m b/thirdparty/sdl/joystick/apple/SDL_mfijoystick.m
index 3e8f4a8bab9..b4b31704d0b 100644
--- a/thirdparty/sdl/joystick/apple/SDL_mfijoystick.m
+++ b/thirdparty/sdl/joystick/apple/SDL_mfijoystick.m
@@ -1,6 +1,6 @@
/*
Simple DirectMedia Layer
- Copyright (C) 1997-2025 Sam Lantinga <[email protected]>
+ Copyright (C) 1997-2026 Sam Lantinga <[email protected]>
This software is provided 'as-is', without any express or implied
warranty. In no event will the authors be held liable for any damages
@@ -27,6 +27,10 @@
#include "../usb_ids.h"
#include "../../events/SDL_events_c.h"
+#ifdef SDL_VIDEO_DRIVER_UIKIT
+#include "../../video/uikit/SDL_uikitvideo.h"
+#endif
+
#include "SDL_mfijoystick_c.h"
@@ -297,6 +301,21 @@ static bool IOS_AddMFIJoystickDevice(SDL_JoystickDeviceItem *device, GCControlle
Uint8 subtype = 0;
const char *name = NULL;
+ // Technically we only want to do this when the controller is opened, but we ALSO
+ // want to do this when the controller is opened via HIDAPI or IOKit, and we don't
+ // have an easy way to know if those devices correspond to a specific GCController.
+ //
+ // Since the fact that we're initializing means that the application is likely to
+ // be opening available controllers, this is probably the right thing to do for now.
+ if (@available(macOS 11.0, iOS 14.0, tvOS 14.0, *)) {
+ for (id key in controller.physicalInputProfile.buttons) {
+ GCControllerButtonInput *button = controller.physicalInputProfile.buttons[key];
+ if ([button isBoundToSystemGesture]) {
+ button.preferredSystemGestureState = GCSystemGestureStateDisabled;
+ }
+ }
+ }
+
if (@available(macOS 11.3, iOS 14.5, tvOS 14.5, *)) {
if (!GCController.shouldMonitorBackgroundEvents) {
GCController.shouldMonitorBackgroundEvents = YES;
@@ -307,13 +326,13 @@ static bool IOS_AddMFIJoystickDevice(SDL_JoystickDeviceItem *device, GCControlle
* struct, and ARC doesn't work with structs. */
device->controller = (__bridge GCController *)CFBridgingRetain(controller);
- if (@available(macOS 10.15, iOS 13.0, tvOS 13.0, *)) {
- if (controller.productCategory) {
- name = controller.productCategory.UTF8String;
- }
+ if (controller.vendorName) {
+ name = controller.vendorName.UTF8String;
} else {
- if (controller.vendorName) {
- name = controller.vendorName.UTF8String;
+ if (@available(macOS 10.15, iOS 13.0, tvOS 13.0, *)) {
+ if (controller.productCategory) {
+ name = controller.productCategory.UTF8String;
+ }
}
}
@@ -321,13 +340,11 @@ static bool IOS_AddMFIJoystickDevice(SDL_JoystickDeviceItem *device, GCControlle
name = "MFi Gamepad";
}
- device->name = SDL_CreateJoystickName(0, 0, NULL, name);
-
#ifdef DEBUG_CONTROLLER_PROFILE
NSLog(@"Product name: %@\n", controller.vendorName);
NSLog(@"Product category: %@\n", controller.productCategory);
NSLog(@"Elements available:\n");
- if (@available(macOS 10.16, iOS 14.0, tvOS 14.0, *)) {
+ if (@available(macOS 11.0, iOS 14.0, tvOS 14.0, *)) {
NSDictionary<NSString *, GCControllerElement *> *elements = controller.physicalInputProfile.elements;
for (id key in controller.physicalInputProfile.buttons) {
NSLog(@"\tButton: %@ (%s)\n", key, elements[key].analog ? "analog" : "digital");
@@ -361,7 +378,16 @@ static bool IOS_AddMFIJoystickDevice(SDL_JoystickDeviceItem *device, GCControlle
(device->is_shield && HIDAPI_IsDevicePresent(USB_VENDOR_NVIDIA, USB_PRODUCT_NVIDIA_SHIELD_CONTROLLER_V104, 0, "")) ||
(device->is_stadia && HIDAPI_IsDevicePresent(USB_VENDOR_GOOGLE, USB_PRODUCT_GOOGLE_STADIA_CONTROLLER, 0, "")) ||
(device->is_switch_joyconL && HIDAPI_IsDevicePresent(USB_VENDOR_NINTENDO, USB_PRODUCT_NINTENDO_SWITCH_JOYCON_LEFT, 0, "")) ||
- (device->is_switch_joyconR && HIDAPI_IsDevicePresent(USB_VENDOR_NINTENDO, USB_PRODUCT_NINTENDO_SWITCH_JOYCON_RIGHT, 0, ""))) {
+ (device->is_switch_joyconR && HIDAPI_IsDevicePresent(USB_VENDOR_NINTENDO, USB_PRODUCT_NINTENDO_SWITCH_JOYCON_RIGHT, 0, "")) ||
+ (SDL_strstr(name, "GameCube Controller Adapter") &&
+ (HIDAPI_IsDevicePresent(USB_VENDOR_NINTENDO, USB_PRODUCT_NINTENDO_GAMECUBE_ADAPTER, 0, "") ||
+ HIDAPI_IsDevicePresent(USB_VENDOR_DRAGONRISE, USB_PRODUCT_EVORETRO_GAMECUBE_ADAPTER1, 0, "") ||
+ HIDAPI_IsDevicePresent(USB_VENDOR_DRAGONRISE, USB_PRODUCT_EVORETRO_GAMECUBE_ADAPTER2, 0, "") ||
+ HIDAPI_IsDevicePresent(USB_VENDOR_DRAGONRISE, USB_PRODUCT_EVORETRO_GAMECUBE_ADAPTER3, 0, ""))) ||
+ (SDL_strcmp(name, "8Bitdo SN30 Pro") == 0 && (HIDAPI_IsDevicePresent(USB_VENDOR_8BITDO, USB_PRODUCT_8BITDO_SN30_PRO, 0, "") || HIDAPI_IsDevicePresent(USB_VENDOR_8BITDO, USB_PRODUCT_8BITDO_SN30_PRO_BT, 0, ""))) ||
+ (SDL_strcmp(name, "8BitDo Pro 2") == 0 && (HIDAPI_IsDevicePresent(USB_VENDOR_8BITDO, USB_PRODUCT_8BITDO_PRO_2, 0, "") || HIDAPI_IsDevicePresent(USB_VENDOR_8BITDO, USB_PRODUCT_8BITDO_PRO_2_BT, 0, ""))) ||
+ (SDL_strcmp(name, "8BitDo Pro 3") == 0 && (HIDAPI_IsDevicePresent(USB_VENDOR_8BITDO, USB_PRODUCT_8BITDO_PRO_3, 0, ""))) ||
+ (SDL_startswith(name, "8BitDo Ultimate 2 Wireless") && HIDAPI_IsDevicePresent(USB_VENDOR_8BITDO, USB_PRODUCT_8BITDO_ULTIMATE2_WIRELESS, 0, ""))) {
// The HIDAPI driver is taking care of this device
return false;
}
@@ -377,7 +403,7 @@ static bool IOS_AddMFIJoystickDevice(SDL_JoystickDeviceItem *device, GCControlle
return false;
}
- if (@available(macOS 10.16, iOS 14.0, tvOS 14.0, *)) {
+ if (@available(macOS 11.0, iOS 14.0, tvOS 14.0, *)) {
if (controller.physicalInputProfile.buttons[GCInputDualShockTouchpadButton] != nil) {
device->has_dualshock_touchpad = TRUE;
}
@@ -401,12 +427,19 @@ static bool IOS_AddMFIJoystickDevice(SDL_JoystickDeviceItem *device, GCControlle
if (device->has_xbox_paddles) {
// Assume Xbox One Elite Series 2 Controller unless/until GCController flows VID/PID
product = USB_PRODUCT_XBOX_ONE_ELITE_SERIES_2_BLUETOOTH;
+
+ // controller.vendorName returns a generic name for Xbox controllers ("Controller"),
+ // and controller.productCategory only returns "Xbox One" for those controllers,
+ // so we give them proper names based on the ones from SDL_gamepad_db.h
+ name = "Xbox One Elite 2 Controller";
} else if (device->has_xbox_share_button) {
// Assume Xbox Series X Controller unless/until GCController flows VID/PID
product = USB_PRODUCT_XBOX_SERIES_X_BLE;
+ name = "Xbox Series X Controller";
} else {
// Assume Xbox One S Bluetooth Controller unless/until GCController flows VID/PID
product = USB_PRODUCT_XBOX_ONE_S_REV1_BLUETOOTH;
+ name = "Xbox One Wireless Controller";
}
} else if (device->is_ps4) {
// Assume DS4 Slim unless/until GCController flows VID/PID
@@ -432,7 +465,7 @@ static bool IOS_AddMFIJoystickDevice(SDL_JoystickDeviceItem *device, GCControlle
} else if (device->is_switch_joyconR) {
vendor = USB_VENDOR_NINTENDO;
product = USB_PRODUCT_NINTENDO_SWITCH_JOYCON_RIGHT;
- } else if (@available(macOS 10.16, iOS 14.0, tvOS 14.0, *)) {
+ } else if (@available(macOS 11.0, iOS 14.0, tvOS 14.0, *)) {
vendor = USB_VENDOR_APPLE;
product = 4;
subtype = 4;
@@ -455,7 +488,7 @@ static bool IOS_AddMFIJoystickDevice(SDL_JoystickDeviceItem *device, GCControlle
return false;
}
- if (@available(macOS 10.16, iOS 14.0, tvOS 14.0, *)) {
+ if (@available(macOS 11.0, iOS 14.0, tvOS 14.0, *)) {
NSDictionary<NSString *, GCControllerElement *> *elements = controller.physicalInputProfile.elements;
// Provide both axes and analog buttons as SDL axes
@@ -584,9 +617,11 @@ static bool IOS_AddMFIJoystickDevice(SDL_JoystickDeviceItem *device, GCControlle
// We don't know how to get input events from this device
return false;
}
+
+ device->name = SDL_CreateJoystickName(0, 0, NULL, name);
Uint16 signature;
- if (@available(macOS 10.16, iOS 14.0, tvOS 14.0, *)) {
+ if (@available(macOS 11.0, iOS 14.0, tvOS 14.0, *)) {
signature = 0;
signature = SDL_crc16(signature, device->name, SDL_strlen(device->name));
for (id key in device->axes) {
@@ -740,7 +775,7 @@ static bool IOS_JoystickInit(void)
}
#ifdef SDL_PLATFORM_MACOS
- if (@available(macOS 10.16, *)) {
+ if (@available(macOS 11.0, *)) {
// Continue with initialization on macOS 11+
} else {
return true;
@@ -797,6 +832,10 @@ static bool IOS_JoystickInit(void)
SDL_UnlockJoysticks();
}];
#endif // SDL_JOYSTICK_MFI
+
+#ifdef SDL_VIDEO_DRIVER_UIKIT
+ UIKit_SetGameControllerInteraction(true);
+#endif
}
return true;
@@ -902,18 +941,16 @@ static bool IOS_JoystickOpen(SDL_Joystick *joystick, int device_index)
};
}
- if (@available(macOS 10.16, iOS 14.0, tvOS 14.0, *)) {
+ if (@available(macOS 11.0, iOS 14.0, tvOS 14.0, *)) {
GCController *controller = joystick->hwdata->controller;
GCMotion *motion = controller.motion;
if (motion && motion.hasRotationRate) {
SDL_PrivateJoystickAddSensor(joystick, SDL_SENSOR_GYRO, 0.0f);
- }
- if (motion && motion.hasGravityAndUserAcceleration) {
SDL_PrivateJoystickAddSensor(joystick, SDL_SENSOR_ACCEL, 0.0f);
}
}
- if (@available(macOS 10.16, iOS 14.0, tvOS 14.0, *)) {
+ if (@available(macOS 11.0, iOS 14.0, tvOS 14.0, *)) {
GCController *controller = joystick->hwdata->controller;
for (id key in controller.physicalInputProfile.buttons) {
GCControllerButtonInput *button = controller.physicalInputProfile.buttons[key];
@@ -923,7 +960,7 @@ static bool IOS_JoystickOpen(SDL_Joystick *joystick, int device_index)
}
}
- if (@available(macOS 10.16, iOS 14.0, tvOS 14.0, *)) {
+ if (@available(macOS 11.0, iOS 14.0, tvOS 14.0, *)) {
GCController *controller = device->controller;
if (controller.light) {
SDL_SetBooleanProperty(SDL_GetJoystickProperties(joystick), SDL_PROP_JOYSTICK_CAP_RGB_LED_BOOLEAN, true);
@@ -984,7 +1021,7 @@ static void IOS_MFIJoystickUpdate(SDL_Joystick *joystick)
Uint64 timestamp = SDL_GetTicksNS();
#ifdef DEBUG_CONTROLLER_STATE
- if (@available(macOS 10.16, iOS 14.0, tvOS 14.0, *)) {
+ if (@available(macOS 11.0, iOS 14.0, tvOS 14.0, *)) {
if (controller.physicalInputProfile) {
for (id key in controller.physicalInputProfile.buttons) {
GCControllerButtonInput *button = controller.physicalInputProfile.buttons[key];
@@ -1010,7 +1047,7 @@ static void IOS_MFIJoystickUpdate(SDL_Joystick *joystick)
}
#endif // DEBUG_CONTROLLER_STATE
- if (@available(macOS 10.16, iOS 14.0, tvOS 14.0, *)) {
+ if (@available(macOS 11.0, iOS 14.0, tvOS 14.0, *)) {
NSDictionary<NSString *, GCControllerElement *> *elements = controller.physicalInputProfile.elements;
NSDictionary<NSString *, GCControllerButtonInput *> *buttons = controller.physicalInputProfile.buttons;
@@ -1028,13 +1065,7 @@ static void IOS_MFIJoystickUpdate(SDL_Joystick *joystick)
int button = 0;
for (id key in device->buttons) {
- bool down;
- if (button == device->pause_button_index) {
- down = (device->pause_button_pressed > 0);
- } else {
- down = buttons[key].isPressed;
- }
- SDL_SendJoystickButton(timestamp, joystick, button++, down);
+ SDL_SendJoystickButton(timestamp, joystick, button++, buttons[key].isPressed);
}
} else if (controller.extendedGamepad) {
bool isstack;
@@ -1140,7 +1171,7 @@ static void IOS_MFIJoystickUpdate(SDL_Joystick *joystick)
}
}
- if (@available(macOS 10.16, iOS 14.0, tvOS 14.0, *)) {
+ if (@available(macOS 11.0, iOS 14.0, tvOS 14.0, *)) {
if (device->has_dualshock_touchpad) {
GCControllerDirectionPad *dpad;
@@ -1160,29 +1191,26 @@ static void IOS_MFIJoystickUpdate(SDL_Joystick *joystick)
}
}
- if (@available(macOS 10.16, iOS 14.0, tvOS 14.0, *)) {
+ if (@available(macOS 11.0, iOS 14.0, tvOS 14.0, *)) {
GCMotion *motion = controller.motion;
if (motion && motion.sensorsActive) {
float data[3];
- if (motion.hasRotationRate) {
- GCRotationRate rate = motion.rotationRate;
- data[0] = rate.x;
- data[1] = rate.z;
- data[2] = -rate.y;
- SDL_SendJoystickSensor(timestamp, joystick, SDL_SENSOR_GYRO, timestamp, data, 3);
- }
- if (motion.hasGravityAndUserAcceleration) {
- GCAcceleration accel = motion.acceleration;
- data[0] = -accel.x * SDL_STANDARD_GRAVITY;
- data[1] = -accel.y * SDL_STANDARD_GRAVITY;
- data[2] = -accel.z * SDL_STANDARD_GRAVITY;
- SDL_SendJoystickSensor(timestamp, joystick, SDL_SENSOR_ACCEL, timestamp, data, 3);
- }
+ GCRotationRate rate = motion.rotationRate;
+ data[0] = rate.x;
+ data[1] = rate.z;
+ data[2] = -rate.y;
+ SDL_SendJoystickSensor(timestamp, joystick, SDL_SENSOR_GYRO, timestamp, data, 3);
+
+ GCAcceleration accel = motion.acceleration;
+ data[0] = -accel.x * SDL_STANDARD_GRAVITY;
+ data[1] = -accel.y * SDL_STANDARD_GRAVITY;
+ data[2] = -accel.z * SDL_STANDARD_GRAVITY;
+ SDL_SendJoystickSensor(timestamp, joystick, SDL_SENSOR_ACCEL, timestamp, data, 3);
}
}
- if (@available(macOS 10.16, iOS 14.0, tvOS 14.0, *)) {
+ if (@available(macOS 11.0, iOS 14.0, tvOS 14.0, *)) {
GCDeviceBattery *battery = controller.battery;
if (battery) {
SDL_PowerState state = SDL_POWERSTATE_UNKNOWN;
@@ -1211,8 +1239,8 @@ static void IOS_MFIJoystickUpdate(SDL_Joystick *joystick)
#ifdef SDL_JOYSTICK_MFI
@interface SDL3_RumbleMotor : NSObject
-@property(nonatomic, strong) CHHapticEngine *engine API_AVAILABLE(macos(10.16), ios(13.0), tvos(14.0));
-@property(nonatomic, strong) id<CHHapticPatternPlayer> player API_AVAILABLE(macos(10.16), ios(13.0), tvos(14.0));
+@property(nonatomic, strong) CHHapticEngine *engine API_AVAILABLE(macos(11.0), ios(13.0), tvos(14.0));
+@property(nonatomic, strong) id<CHHapticPatternPlayer> player API_AVAILABLE(macos(11.0), ios(13.0), tvos(14.0));
@property bool active;
@end
@@ -1223,7 +1251,7 @@ static void IOS_MFIJoystickUpdate(SDL_Joystick *joystick)
- (void)cleanup
{
@autoreleasepool {
- if (@available(macOS 10.16, iOS 14.0, tvOS 14.0, *)) {
+ if (@available(macOS 11.0, iOS 14.0, tvOS 14.0, *)) {
if (self.player != nil) {
[self.player cancelAndReturnError:nil];
self.player = nil;
@@ -1239,7 +1267,7 @@ static void IOS_MFIJoystickUpdate(SDL_Joystick *joystick)
- (bool)setIntensity:(float)intensity
{
@autoreleasepool {
- if (@available(macOS 10.16, iOS 14.0, tvOS 14.0, *)) {
+ if (@available(macOS 11.0, iOS 14.0, tvOS 14.0, *)) {
NSError *error = nil;
CHHapticDynamicParameter *param;
@@ -1286,7 +1314,7 @@ static void IOS_MFIJoystickUpdate(SDL_Joystick *joystick)
}
}
-- (id)initWithController:(GCController *)controller locality:(GCHapticsLocality)locality API_AVAILABLE(macos(10.16), ios(14.0), tvos(14.0))
+- (id)initWithController:(GCController *)controller locality:(GCHapticsLocality)locality API_AVAILABLE(macos(11.0), ios(14.0), tvos(14.0))
{
@autoreleasepool {
NSError *error;
@@ -1388,7 +1416,7 @@ static void IOS_MFIJoystickUpdate(SDL_Joystick *joystick)
static SDL3_RumbleContext *IOS_JoystickInitRumble(GCController *controller)
{
@autoreleasepool {
- if (@available(macOS 10.16, iOS 14.0, tvOS 14.0, *)) {
+ if (@available(macOS 11.0, iOS 14.0, tvOS 14.0, *)) {
SDL3_RumbleMotor *low_frequency_motor = [[SDL3_RumbleMotor alloc] initWithController:controller locality:GCHapticsLocalityLeftHandle];
SDL3_RumbleMotor *high_frequency_motor = [[SDL3_RumbleMotor alloc] initWithController:controller locality:GCHapticsLocalityRightHandle];
SDL3_RumbleMotor *left_trigger_motor = [[SDL3_RumbleMotor alloc] initWithController:controller locality:GCHapticsLocalityLeftTrigger];
@@ -1415,7 +1443,7 @@ static bool IOS_JoystickRumble(SDL_Joystick *joystick, Uint16 low_frequency_rumb
return SDL_SetError("Controller is no longer connected");
}
- if (@available(macOS 10.16, iOS 14.0, tvOS 14.0, *)) {
+ if (@available(macOS 11.0, iOS 14.0, tvOS 14.0, *)) {
if (!device->rumble && device->controller && device->controller.haptics) {
SDL3_RumbleContext *rumble = IOS_JoystickInitRumble(device->controller);
if (rumble) {
@@ -1441,7 +1469,7 @@ static bool IOS_JoystickRumbleTriggers(SDL_Joystick *joystick, Uint16 left_rumbl
return SDL_SetError("Controller is no longer connected");
}
- if (@available(macOS 10.16, iOS 14.0, tvOS 14.0, *)) {
+ if (@available(macOS 11.0, iOS 14.0, tvOS 14.0, *)) {
if (!device->rumble && device->controller && device->controller.haptics) {
SDL3_RumbleContext *rumble = IOS_JoystickInitRumble(device->controller);
if (rumble) {
@@ -1467,7 +1495,7 @@ static bool IOS_JoystickSetLED(SDL_Joystick *joystick, Uint8 red, Uint8 green, U
return SDL_SetError("Controller is no longer connected");
}
- if (@available(macOS 10.16, iOS 14.0, tvOS 14.0, *)) {
+ if (@available(macOS 11.0, iOS 14.0, tvOS 14.0, *)) {
GCController *controller = device->controller;
GCDeviceLight *light = controller.light;
if (light) {
@@ -1495,7 +1523,7 @@ static bool IOS_JoystickSetSensorsEnabled(SDL_Joystick *joystick, bool enabled)
return SDL_SetError("Controller is no longer connected");
}
- if (@available(macOS 10.16, iOS 14.0, tvOS 14.0, *)) {
+ if (@available(macOS 11.0, iOS 14.0, tvOS 14.0, *)) {
GCController *controller = device->controller;
GCMotion *motion = controller.motion;
if (motion) {
@@ -1546,7 +1574,7 @@ static void IOS_JoystickClose(SDL_Joystick *joystick)
controller.controllerPausedHandler = nil;
controller.playerIndex = -1;
- if (@available(macOS 10.16, iOS 14.0, tvOS 14.0, *)) {
+ if (@available(macOS 11.0, iOS 14.0, tvOS 14.0, *)) {
for (id key in controller.physicalInputProfile.buttons) {
GCControllerButtonInput *button = controller.physicalInputProfile.buttons[key];
if ([button isBoundToSystemGesture]) {
@@ -1588,6 +1616,10 @@ static void IOS_JoystickQuit(void)
while (deviceList != NULL) {
IOS_RemoveJoystickDevice(deviceList);
}
+
+#ifdef SDL_VIDEO_DRIVER_UIKIT
+ UIKit_SetGameControllerInteraction(false);
+#endif
}
numjoysticks = 0;
@@ -1600,7 +1632,7 @@ static bool IOS_JoystickGetGamepadMapping(int device_index, SDL_GamepadMapping *
return false;
}
- if (@available(macOS 10.16, iOS 14.0, tvOS 14.0, *)) {
+ if (@available(macOS 11.0, iOS 14.0, tvOS 14.0, *)) {
int axis = 0;
for (id key in device->axes) {
if ([(NSString *)key isEqualToString:@"Left Thumbstick X Axis"] ||
@@ -1737,7 +1769,12 @@ bool IOS_SupportedHIDDevice(IOHIDDeviceRef device)
return false;
}
- if (@available(macOS 10.16, *)) {
+ if (IOHIDDeviceGetProperty(device, CFSTR(kIOHIDVirtualHIDevice)) == kCFBooleanTrue) {
+ // Steam virtual gamepads always have kIOHIDVirtualHIDevice property unlike real devices, and are also not supported as GCController
+ return false;
+ }
+
+ if (@available(macOS 11.0, *)) {
const int MAX_ATTEMPTS = 3;
for (int attempt = 0; attempt < MAX_ATTEMPTS; ++attempt) {
if ([GCController supportsHIDDevice:device]) {
@@ -1756,7 +1793,7 @@ bool IOS_SupportedHIDDevice(IOHIDDeviceRef device)
/* NOLINTNEXTLINE(readability-non-const-parameter): getCString takes a non-const char* */
static void GetAppleSFSymbolsNameForElement(GCControllerElement *element, char *name)
{
- if (@available(macOS 10.16, iOS 14.0, tvOS 14.0, *)) {
+ if (@available(macOS 11.0, iOS 14.0, tvOS 14.0, *)) {
if (element) {
[element.sfSymbolsName getCString:name maxLength:255 encoding:NSASCIIStringEncoding];
}
@@ -1765,7 +1802,7 @@ static void GetAppleSFSymbolsNameForElement(GCControllerElement *element, char *
static GCControllerDirectionPad *GetDirectionalPadForController(GCController *controller)
{
- if (@available(macOS 10.16, iOS 14.0, tvOS 14.0, *)) {
+ if (@available(macOS 11.0, iOS 14.0, tvOS 14.0, *)) {
return controller.physicalInputProfile.dpads[GCInputDirectionPad];
}
@@ -1788,7 +1825,7 @@ const char *IOS_GetAppleSFSymbolsNameForButton(SDL_Gamepad *gamepad, SDL_Gamepad
#ifdef SDL_JOYSTICK_MFI
if (gamepad && SDL_GetGamepadJoystick(gamepad)->driver == &SDL_IOS_JoystickDriver) {
- if (@available(macOS 10.16, iOS 14.0, tvOS 14.0, *)) {
+ if (@available(macOS 11.0, iOS 14.0, tvOS 14.0, *)) {
GCController *controller = SDL_GetGamepadJoystick(gamepad)->hwdata->controller;
NSDictionary<NSString *, GCControllerElement *> *elements = controller.physicalInputProfile.elements;
switch (button) {
@@ -1904,7 +1941,7 @@ const char *IOS_GetAppleSFSymbolsNameForAxis(SDL_Gamepad *gamepad, SDL_GamepadAx
#ifdef SDL_JOYSTICK_MFI
if (gamepad && SDL_GetGamepadJoystick(gamepad)->driver == &SDL_IOS_JoystickDriver) {
- if (@available(macOS 10.16, iOS 14.0, tvOS 14.0, *)) {
+ if (@available(macOS 11.0, iOS 14.0, tvOS 14.0, *)) {
GCController *controller = SDL_GetGamepadJoystick(gamepad)->hwdata->controller;
NSDictionary<NSString *, GCControllerElement *> *elements = controller.physicalInputProfile.elements;
switch (axis) {
diff --git a/thirdparty/sdl/joystick/apple/SDL_mfijoystick_c.h b/thirdparty/sdl/joystick/apple/SDL_mfijoystick_c.h
index dfa7615964e..6e275c00a24 100644
--- a/thirdparty/sdl/joystick/apple/SDL_mfijoystick_c.h
+++ b/thirdparty/sdl/joystick/apple/SDL_mfijoystick_c.h
@@ -1,6 +1,6 @@
/*
Simple DirectMedia Layer
- Copyright (C) 1997-2025 Sam Lantinga <[email protected]>
+ Copyright (C) 1997-2026 Sam Lantinga <[email protected]>
This software is provided 'as-is', without any express or implied
warranty. In no event will the authors be held liable for any damages
diff --git a/thirdparty/sdl/joystick/controller_list.h b/thirdparty/sdl/joystick/controller_list.h
index 0fedb651aa9..df491fbcdab 100644
--- a/thirdparty/sdl/joystick/controller_list.h
+++ b/thirdparty/sdl/joystick/controller_list.h
@@ -60,15 +60,39 @@ static const ControllerDescription_t arrControllers[] = {
{ MAKE_CONTROLLER_ID( 0x0f0d, 0x0088 ), k_eControllerType_PS3Controller, NULL }, // HORI Fighting Stick mini 4
{ MAKE_CONTROLLER_ID( 0x0f30, 0x1100 ), k_eControllerType_PS3Controller, NULL }, // Qanba Q1 fight stick
{ MAKE_CONTROLLER_ID( 0x11ff, 0x3331 ), k_eControllerType_PS3Controller, NULL }, // SRXJ-PH2400
+ { MAKE_CONTROLLER_ID( 0x12ba, 0x0100 ), k_eControllerType_PS3Controller, NULL }, // PS3 Guitar Hero Guitar
+ { MAKE_CONTROLLER_ID( 0x12ba, 0x0120 ), k_eControllerType_PS3Controller, NULL }, // PS3 Guitar Hero Drums
+ { MAKE_CONTROLLER_ID( 0x12ba, 0x0140 ), k_eControllerType_PS3Controller, NULL }, // PS3 DJ Hero Turntable
+ { MAKE_CONTROLLER_ID( 0x12ba, 0x0200 ), k_eControllerType_PS3Controller, NULL }, // PS3 Rock Band Guitar
+ { MAKE_CONTROLLER_ID( 0x12ba, 0x0210 ), k_eControllerType_PS3Controller, NULL }, // PS3 Rock Band Drums
+ { MAKE_CONTROLLER_ID( 0x12ba, 0x0218 ), k_eControllerType_PS3Controller, NULL }, // PS3 Midi Pro Adapter - Drums Mode
+ { MAKE_CONTROLLER_ID( 0x12ba, 0x074b ), k_eControllerType_PS3Controller, NULL }, // PS3 / Wii U Guitar Hero Live Guitar
+ { MAKE_CONTROLLER_ID( 0x12ba, 0x2330 ), k_eControllerType_PS3Controller, NULL }, // PS3 Rock Band Keyboard
+ { MAKE_CONTROLLER_ID( 0x12ba, 0x2338 ), k_eControllerType_PS3Controller, NULL }, // PS3 Midi Pro Adapter - Keyboard Mode
+ { MAKE_CONTROLLER_ID( 0x12ba, 0x2430 ), k_eControllerType_PS3Controller, NULL }, // PS3 Mustang Guitar
+ { MAKE_CONTROLLER_ID( 0x12ba, 0x2438 ), k_eControllerType_PS3Controller, NULL }, // PS3 Midi Pro Adapter - Mustang Guitar Mode
+ { MAKE_CONTROLLER_ID( 0x12ba, 0x2530 ), k_eControllerType_PS3Controller, NULL }, // PS3 Squire Guitar
+ { MAKE_CONTROLLER_ID( 0x12ba, 0x2538 ), k_eControllerType_PS3Controller, NULL }, // PS3 Midi Pro Adapter - Squire Guitar Mode
{ MAKE_CONTROLLER_ID( 0x1345, 0x1000 ), k_eControllerType_PS3Controller, NULL }, // PS2 ACME GA-D5
{ MAKE_CONTROLLER_ID( 0x1345, 0x6005 ), k_eControllerType_PS3Controller, NULL }, // ps2 maybe break out later
{ MAKE_CONTROLLER_ID( 0x146b, 0x5500 ), k_eControllerType_PS3Controller, NULL }, // From SDL
{ MAKE_CONTROLLER_ID( 0x1a34, 0x0836 ), k_eControllerType_PS3Controller, NULL }, // Afterglow PS3
+ { MAKE_CONTROLLER_ID( 0x1BAD, 0x0004 ), k_eControllerType_PS3Controller, NULL }, // Wii RB1 Guitar (Uses PS3 protocol)
+ { MAKE_CONTROLLER_ID( 0x1BAD, 0x0005 ), k_eControllerType_PS3Controller, NULL }, // Wii RB1 Drums (Uses PS3 protocol)
+ { MAKE_CONTROLLER_ID( 0x1BAD, 0x3010 ), k_eControllerType_PS3Controller, NULL }, // Wii RB2 Guitar (Uses PS3 protocol)
+ { MAKE_CONTROLLER_ID( 0x1BAD, 0x3110 ), k_eControllerType_PS3Controller, NULL }, // Wii RB2 Drums (Uses PS3 protocol)
+ { MAKE_CONTROLLER_ID( 0x1BAD, 0x3138 ), k_eControllerType_PS3Controller, NULL }, // Wii RB3 Midi Pro Adapter - Drums Mode (Uses PS3 protocol)
+ { MAKE_CONTROLLER_ID( 0x1BAD, 0x3330 ), k_eControllerType_PS3Controller, NULL }, // Wii RB3 Keyboard (Uses PS3 protocol)
+ { MAKE_CONTROLLER_ID( 0x1BAD, 0x3338 ), k_eControllerType_PS3Controller, NULL }, // Wii RB3 Midi Pro Adapter - Keyboard Mode (Uses PS3 protocol)
+ { MAKE_CONTROLLER_ID( 0x1BAD, 0x3430 ), k_eControllerType_PS3Controller, NULL }, // Wii RB3 Mustang Guitar (Uses PS3 protocol)
+ { MAKE_CONTROLLER_ID( 0x1BAD, 0x3438 ), k_eControllerType_PS3Controller, NULL }, // Wii RB3 Midi Pro Adapter - Mustang Guitar Mode (Uses PS3 protocol)
+ { MAKE_CONTROLLER_ID( 0x1BAD, 0x3530 ), k_eControllerType_PS3Controller, NULL }, // Wii RB3 Squire Guitar (Uses PS3 protocol)
+ { MAKE_CONTROLLER_ID( 0x1BAD, 0x3538 ), k_eControllerType_PS3Controller, NULL }, // Wii RB3 Midi Pro Adapter - Squire Guitar Mode (Uses PS3 protocol)
{ MAKE_CONTROLLER_ID( 0x20bc, 0x5500 ), k_eControllerType_PS3Controller, NULL }, // ShanWan PS3
{ MAKE_CONTROLLER_ID( 0x20d6, 0x576d ), k_eControllerType_PS3Controller, NULL }, // Power A PS3
{ MAKE_CONTROLLER_ID( 0x20d6, 0xca6d ), k_eControllerType_PS3Controller, NULL }, // BDA Pro Ex
{ MAKE_CONTROLLER_ID( 0x2563, 0x0523 ), k_eControllerType_PS3Controller, NULL }, // Digiflip GP006
- { MAKE_CONTROLLER_ID( 0x2563, 0x0575 ), k_eControllerType_PS3Controller, "Retro-bit Controller" }, // SWITCH CO., LTD. Retro-bit Controller
+ { MAKE_CONTROLLER_ID( 0x2563, 0x0575 ), k_eControllerType_PS3Controller, "Retro Controller" }, // SWITCH CO., LTD. Retro-bit, Retro Fighters Controllers
{ MAKE_CONTROLLER_ID( 0x25f0, 0x83c3 ), k_eControllerType_PS3Controller, NULL }, // gioteck vx2
{ MAKE_CONTROLLER_ID( 0x25f0, 0xc121 ), k_eControllerType_PS3Controller, NULL }, //
{ MAKE_CONTROLLER_ID( 0x2c22, 0x2003 ), k_eControllerType_PS3Controller, NULL }, // Qanba Drone
@@ -159,9 +183,12 @@ static const ControllerDescription_t arrControllers[] = {
{ MAKE_CONTROLLER_ID( 0x1532, 0x100b ), k_eControllerType_PS5Controller, NULL }, // Razer Wolverine V2 Pro (Wired)
{ MAKE_CONTROLLER_ID( 0x1532, 0x100c ), k_eControllerType_PS5Controller, NULL }, // Razer Wolverine V2 Pro (Wireless)
{ MAKE_CONTROLLER_ID( 0x1532, 0x1012 ), k_eControllerType_PS5Controller, NULL }, // Razer Kitsune
+ { MAKE_CONTROLLER_ID( 0x1532, 0x1024 ), k_eControllerType_PS5Controller, NULL }, // Razer Raiju V3 Pro (PS5 mode wired)
+ { MAKE_CONTROLLER_ID( 0x1532, 0x1026 ), k_eControllerType_PS5Controller, NULL }, // Razer Raiju V3 Pro (PS5 mode with dongle)
{ MAKE_CONTROLLER_ID( 0x3285, 0x0d18 ), k_eControllerType_PS5Controller, NULL }, // NACON Revolution 5 Pro (PS5 mode with dongle)
{ MAKE_CONTROLLER_ID( 0x3285, 0x0d19 ), k_eControllerType_PS5Controller, NULL }, // NACON Revolution 5 Pro (PS5 mode wired)
{ MAKE_CONTROLLER_ID( 0x358a, 0x0104 ), k_eControllerType_PS5Controller, NULL }, // Backbone One PlayStation Edition for iOS
+ { MAKE_CONTROLLER_ID( 0x358a, 0x0304 ), k_eControllerType_PS5Controller, NULL }, // Backbone One PlayStation Edition Gen 2
{ MAKE_CONTROLLER_ID( 0x0079, 0x0006 ), k_eControllerType_UnknownNonSteamController, NULL }, // DragonRise Generic USB PCB, sometimes configured as a PC Twin Shock Controller - looks like a DS3 but the face buttons are 1-4 instead of symbols
@@ -302,6 +329,7 @@ static const ControllerDescription_t arrControllers[] = {
{ MAKE_CONTROLLER_ID( 0x24c6, 0xfafb ), k_eControllerType_XBox360Controller, NULL }, // Aplay Controller
{ MAKE_CONTROLLER_ID( 0x24c6, 0xfafc ), k_eControllerType_XBox360Controller, NULL }, // Afterglow Gamepad 1
{ MAKE_CONTROLLER_ID( 0x24c6, 0xfafd ), k_eControllerType_XBox360Controller, NULL }, // Afterglow Gamepad 3
+ { MAKE_CONTROLLER_ID( 0x3537, 0x103e ), k_eControllerType_XBox360Controller, "Gamesir Xbox Controller" }, // Gamesir dongle for Supernova (and maybe others) in Xinput mode
{ MAKE_CONTROLLER_ID( 0x24c6, 0xfafe ), k_eControllerType_XBox360Controller, NULL }, // Rock Candy Gamepad for Xbox 360
{ MAKE_CONTROLLER_ID( 0x03f0, 0x0495 ), k_eControllerType_XBoxOneController, NULL }, // HP HyperX Clutch Gladiate
@@ -418,7 +446,7 @@ static const ControllerDescription_t arrControllers[] = {
{ MAKE_CONTROLLER_ID( 0x20d6, 0x2012 ), k_eControllerType_XBoxOneController, "PowerA Xbox Series X Controller" }, // PowerA Xbox Series X Cuphead EnWired Controller - Mugman
{ MAKE_CONTROLLER_ID( 0x20d6, 0x2015 ), k_eControllerType_XBoxOneController, "PowerA Xbox Series X Controller" }, // PowerA Xbox Series X EnWired Controller - Blue Hint
{ MAKE_CONTROLLER_ID( 0x20d6, 0x2016 ), k_eControllerType_XBoxOneController, "PowerA Xbox Series X Controller" }, // PowerA Xbox Series X EnWired Controller - Green Hint
- { MAKE_CONTROLLER_ID( 0x20d6, 0x2017 ), k_eControllerType_XBoxOneController, "PowerA Xbox Series X Controller" }, // PowerA Xbox Series X EnWired Cntroller - Arctic Camo
+ { MAKE_CONTROLLER_ID( 0x20d6, 0x2017 ), k_eControllerType_XBoxOneController, "PowerA Xbox Series X Controller" }, // PowerA Xbox Series X EnWired Controller - Arctic Camo
{ MAKE_CONTROLLER_ID( 0x20d6, 0x2018 ), k_eControllerType_XBoxOneController, "PowerA Xbox Series X Controller" }, // PowerA Xbox Series X EnWired Controller Arc Lightning
{ MAKE_CONTROLLER_ID( 0x20d6, 0x2019 ), k_eControllerType_XBoxOneController, "PowerA Xbox Series X Controller" }, // PowerA Xbox Series X EnWired Controller Royal Purple
{ MAKE_CONTROLLER_ID( 0x20d6, 0x201a ), k_eControllerType_XBoxOneController, "PowerA Xbox Series X Controller" }, // PowerA Xbox Series X EnWired Controller Nebula
@@ -443,7 +471,6 @@ static const ControllerDescription_t arrControllers[] = {
{ MAKE_CONTROLLER_ID( 0x146b, 0x0611 ), k_eControllerType_XBoxOneController, NULL }, // Xbox Controller Mode for NACON Revolution 3
// These have been added via Minidump for unrecognized Xinput controller assert
- { MAKE_CONTROLLER_ID( 0x0000, 0x0000 ), k_eControllerType_XBox360Controller, NULL }, // Unknown Controller
{ MAKE_CONTROLLER_ID( 0x045e, 0x02a2 ), k_eControllerType_XBox360Controller, NULL }, // Unknown Controller - Microsoft VID
{ MAKE_CONTROLLER_ID( 0x0e6f, 0x1414 ), k_eControllerType_XBox360Controller, NULL }, // Unknown Controller
{ MAKE_CONTROLLER_ID( 0x0e6f, 0x0159 ), k_eControllerType_XBox360Controller, NULL }, // Unknown Controller
@@ -469,7 +496,6 @@ static const ControllerDescription_t arrControllers[] = {
{ MAKE_CONTROLLER_ID( 0x046d, 0x0291 ), k_eControllerType_XBox360Controller, NULL }, // logitech xinput
{ MAKE_CONTROLLER_ID( 0x0079, 0x18d3 ), k_eControllerType_XBox360Controller, NULL }, // Unknown Controller
{ MAKE_CONTROLLER_ID( 0x0f0d, 0x00b1 ), k_eControllerType_XBox360Controller, NULL }, // Unknown Controller
- { MAKE_CONTROLLER_ID( 0x0001, 0x0001 ), k_eControllerType_XBox360Controller, NULL }, // Unknown Controller
{ MAKE_CONTROLLER_ID( 0x0079, 0x188e ), k_eControllerType_XBox360Controller, NULL }, // Unknown Controller
{ MAKE_CONTROLLER_ID( 0x0079, 0x187c ), k_eControllerType_XBox360Controller, NULL }, // Unknown Controller
{ MAKE_CONTROLLER_ID( 0x0079, 0x189c ), k_eControllerType_XBox360Controller, NULL }, // Unknown Controller
@@ -482,10 +508,8 @@ static const ControllerDescription_t arrControllers[] = {
{ MAKE_CONTROLLER_ID( 0xf0d, 0xed ), k_eControllerType_XBoxOneController, NULL }, // Unknown Controller
{ MAKE_CONTROLLER_ID( 0xf0d, 0xc0 ), k_eControllerType_XBoxOneController, NULL }, // Unknown Controller
{ MAKE_CONTROLLER_ID( 0xe6f, 0x152 ), k_eControllerType_XBoxOneController, NULL }, // Unknown Controller
- { MAKE_CONTROLLER_ID( 0xe6f, 0x2a7 ), k_eControllerType_XBoxOneController, NULL }, // Unknown Controller
{ MAKE_CONTROLLER_ID( 0x46d, 0x1007 ), k_eControllerType_XBoxOneController, NULL }, // Unknown Controller
{ MAKE_CONTROLLER_ID( 0xe6f, 0x2b8 ), k_eControllerType_XBoxOneController, NULL }, // Unknown Controller
- { MAKE_CONTROLLER_ID( 0xe6f, 0x2a8 ), k_eControllerType_XBoxOneController, NULL }, // Unknown Controller
{ MAKE_CONTROLLER_ID( 0x79, 0x18a1 ), k_eControllerType_XBoxOneController, NULL }, // Unknown Controller
// Added from Minidumps 10-9-19
@@ -526,14 +550,7 @@ static const ControllerDescription_t arrControllers[] = {
{ MAKE_CONTROLLER_ID( 0xd62, 0x9a1b ), k_eControllerType_XBoxOneController, NULL }, // Unknown Controller
{ MAKE_CONTROLLER_ID( 0xe00, 0xe00 ), k_eControllerType_XBoxOneController, NULL }, // Unknown Controller
{ MAKE_CONTROLLER_ID( 0xe6f, 0x12a ), k_eControllerType_XBoxOneController, NULL }, // Unknown Controller
- { MAKE_CONTROLLER_ID( 0xe6f, 0x2a1 ), k_eControllerType_XBoxOneController, NULL }, // Unknown Controller
- { MAKE_CONTROLLER_ID( 0xe6f, 0x2a2 ), k_eControllerType_XBoxOneController, NULL }, // Unknown Controller
- { MAKE_CONTROLLER_ID( 0xe6f, 0x2a5 ), k_eControllerType_XBoxOneController, NULL }, // Unknown Controller
{ MAKE_CONTROLLER_ID( 0xe6f, 0x2b2 ), k_eControllerType_XBoxOneController, NULL }, // Unknown Controller
- { MAKE_CONTROLLER_ID( 0xe6f, 0x2bd ), k_eControllerType_XBoxOneController, NULL }, // Unknown Controller
- { MAKE_CONTROLLER_ID( 0xe6f, 0x2bf ), k_eControllerType_XBoxOneController, NULL }, // Unknown Controller
- { MAKE_CONTROLLER_ID( 0xe6f, 0x2c0 ), k_eControllerType_XBoxOneController, NULL }, // Unknown Controller
- { MAKE_CONTROLLER_ID( 0xe6f, 0x2c6 ), k_eControllerType_XBoxOneController, NULL }, // Unknown Controller
{ MAKE_CONTROLLER_ID( 0xf0d, 0x97 ), k_eControllerType_XBoxOneController, NULL }, // Unknown Controller
{ MAKE_CONTROLLER_ID( 0xf0d, 0xba ), k_eControllerType_XBoxOneController, NULL }, // Unknown Controller
{ MAKE_CONTROLLER_ID( 0xf0d, 0xd8 ), k_eControllerType_XBoxOneController, NULL }, // Unknown Controller
@@ -550,8 +567,11 @@ static const ControllerDescription_t arrControllers[] = {
{ MAKE_CONTROLLER_ID( 0x05ac, 0x0002 ), k_eControllerType_AppleController, NULL }, // MFI Standard Gamepad (generic entry for iOS/tvOS)
{ MAKE_CONTROLLER_ID( 0x057e, 0x2006 ), k_eControllerType_SwitchJoyConLeft, NULL }, // Nintendo Switch Joy-Con (Left)
+ { MAKE_CONTROLLER_ID( 0x057e, 0x2067 ), k_eControllerType_SwitchJoyConLeft, NULL }, // Nintendo Switch 2 Joy-Con (Left)
{ MAKE_CONTROLLER_ID( 0x057e, 0x2007 ), k_eControllerType_SwitchJoyConRight, NULL }, // Nintendo Switch Joy-Con (Right)
+ { MAKE_CONTROLLER_ID( 0x057e, 0x2066 ), k_eControllerType_SwitchJoyConRight, NULL }, // Nintendo Switch 2 Joy-Con (Right)
{ MAKE_CONTROLLER_ID( 0x057e, 0x2008 ), k_eControllerType_SwitchJoyConPair, NULL }, // Nintendo Switch Joy-Con (Left+Right Combined)
+ { MAKE_CONTROLLER_ID( 0x057e, 0x2068 ), k_eControllerType_SwitchJoyConPair, NULL }, // Nintendo Switch 2 Joy-Con (Left+Right Combined)
// This same controller ID is spoofed by many 3rd-party Switch controllers.
// The ones we currently know of are:
@@ -560,6 +580,7 @@ static const ControllerDescription_t arrControllers[] = {
// * ZhiXu Gamepad Wireless
// * Sunwaytek Wireless Motion Controller for Nintendo Switch
{ MAKE_CONTROLLER_ID( 0x057e, 0x2009 ), k_eControllerType_SwitchProController, NULL }, // Nintendo Switch Pro Controller
+ { MAKE_CONTROLLER_ID( 0x057e, 0x2069 ), k_eControllerType_SwitchProController, NULL }, // Nintendo Switch 2 Pro Controller
//{ MAKE_CONTROLLER_ID( 0x057e, 0x2017 ), k_eControllerType_SwitchProController, NULL }, // Nintendo Online SNES Controller
//{ MAKE_CONTROLLER_ID( 0x057e, 0x2019 ), k_eControllerType_SwitchProController, NULL }, // Nintendo Online N64 Controller
//{ MAKE_CONTROLLER_ID( 0x057e, 0x201e ), k_eControllerType_SwitchProController, NULL }, // Nintendo Online SEGA Genesis Controller
@@ -584,6 +605,8 @@ static const ControllerDescription_t arrControllers[] = {
{ MAKE_CONTROLLER_ID( 0x0e6f, 0x0186 ), k_eControllerType_SwitchProController, NULL }, // PDP Afterglow Wireless Switch Controller - working gyro. USB is for charging only. Many later "Wireless" line devices w/ gyro also use this vid/pid
{ MAKE_CONTROLLER_ID( 0x0e6f, 0x0187 ), k_eControllerType_SwitchInputOnlyController, NULL }, // PDP Rockcandy Wired Controller
{ MAKE_CONTROLLER_ID( 0x0e6f, 0x0188 ), k_eControllerType_SwitchInputOnlyController, NULL }, // PDP Afterglow Wired Deluxe+ Audio Controller
+ { MAKE_CONTROLLER_ID( 0x0e6f, 0x018b ), k_eControllerType_SwitchProController, NULL }, // PDP Afterglow Wave Wireless Controller for Switch
+ { MAKE_CONTROLLER_ID( 0x0e6f, 0x018c ), k_eControllerType_SwitchProController, "PDP REALMz Wireless Controller" }, // PDP REALMz Wireless Controller for Switch
{ MAKE_CONTROLLER_ID( 0x0f0d, 0x00aa ), k_eControllerType_SwitchInputOnlyController, NULL }, // HORI Real Arcade Pro V Hayabusa in Switch Mode
{ MAKE_CONTROLLER_ID( 0x20d6, 0xa711 ), k_eControllerType_SwitchInputOnlyController, NULL }, // PowerA Wired Controller Plus/PowerA Wired Controller Nintendo GameCube Style
{ MAKE_CONTROLLER_ID( 0x20d6, 0xa712 ), k_eControllerType_SwitchInputOnlyController, NULL }, // PowerA Nintendo Switch Fusion Fight Pad
@@ -592,9 +615,10 @@ static const ControllerDescription_t arrControllers[] = {
{ MAKE_CONTROLLER_ID( 0x20d6, 0xa715 ), k_eControllerType_SwitchInputOnlyController, NULL }, // Power A Fusion Wireless Arcade Stick (USB Mode) Over BT is shows up as 057e 2009
{ MAKE_CONTROLLER_ID( 0x20d6, 0xa716 ), k_eControllerType_SwitchInputOnlyController, NULL }, // PowerA Nintendo Switch Fusion Pro Controller - USB requires toggling switch on back of device
{ MAKE_CONTROLLER_ID( 0x20d6, 0xa718 ), k_eControllerType_SwitchInputOnlyController, NULL }, // PowerA Nintendo Switch Nano Wired Controller
- { MAKE_CONTROLLER_ID( 0x33dd, 0x0001 ), k_eControllerType_SwitchInputOnlyController, NULL }, // ZUIKI MasCon for Nintendo Switch Black
- { MAKE_CONTROLLER_ID( 0x33dd, 0x0002 ), k_eControllerType_SwitchInputOnlyController, NULL }, // ZUIKI MasCon for Nintendo Switch ??
- { MAKE_CONTROLLER_ID( 0x33dd, 0x0003 ), k_eControllerType_SwitchInputOnlyController, NULL }, // ZUIKI MasCon for Nintendo Switch Red
+ { MAKE_CONTROLLER_ID( 0x33dd, 0x0001 ), k_eControllerType_SwitchInputOnlyController, NULL }, // ZUIKI MasCon for Nintendo Switch Black
+ { MAKE_CONTROLLER_ID( 0x33dd, 0x0002 ), k_eControllerType_SwitchInputOnlyController, NULL }, // ZUIKI MasCon for Nintendo Switch ??
+ { MAKE_CONTROLLER_ID( 0x33dd, 0x0003 ), k_eControllerType_SwitchInputOnlyController, NULL }, // ZUIKI MasCon for Nintendo Switch Red
+ { MAKE_CONTROLLER_ID( 0x0f0d, 0x00f0 ), k_eControllerType_SwitchInputOnlyController, NULL }, // HORI Taiko Controller For Switch
// Valve products
{ MAKE_CONTROLLER_ID( 0x0000, 0x11fb ), k_eControllerType_MobileTouch, NULL }, // Streaming mobile touch virtual controls
@@ -607,4 +631,8 @@ static const ControllerDescription_t arrControllers[] = {
{ MAKE_CONTROLLER_ID( 0x28de, 0x1201 ), k_eControllerType_SteamControllerV2, NULL }, // Valve wired Steam Controller (HEADCRAB)
{ MAKE_CONTROLLER_ID( 0x28de, 0x1202 ), k_eControllerType_SteamControllerV2, NULL }, // Valve Bluetooth Steam Controller (HEADCRAB)
{ MAKE_CONTROLLER_ID( 0x28de, 0x1205 ), k_eControllerType_SteamControllerNeptune, NULL }, // Valve Steam Deck Builtin Controller
+ { MAKE_CONTROLLER_ID( 0x28de, 0x1302 ), k_eControllerType_SteamControllerTriton, NULL }, // Valve Steam Triton Controller
+ { MAKE_CONTROLLER_ID( 0x28de, 0x1303 ), k_eControllerType_SteamControllerTriton, NULL }, // Valve Steam Triton Controller (BLE)
+ { MAKE_CONTROLLER_ID( 0x28de, 0x1304 ), k_eControllerType_SteamControllerTriton, NULL }, // Valve Steam Proteus Dongle (Proprietary)
+ { MAKE_CONTROLLER_ID( 0x28de, 0x1305 ), k_eControllerType_SteamControllerTriton, NULL }, // Valve Steam Nereid Dongle (Proprietary)
};
diff --git a/thirdparty/sdl/joystick/controller_type.h b/thirdparty/sdl/joystick/controller_type.h
index 155c8ad11e1..bb94840affb 100644
--- a/thirdparty/sdl/joystick/controller_type.h
+++ b/thirdparty/sdl/joystick/controller_type.h
@@ -39,6 +39,8 @@ typedef enum
k_eControllerType_SteamControllerV2 = 3,
k_eControllerType_SteamControllerNeptune = 4,
+ k_eControllerType_SteamControllerTriton = 10,
+
// Other Controllers
k_eControllerType_UnknownNonSteamController = 30,
k_eControllerType_XBox360Controller = 31,
diff --git a/thirdparty/sdl/joystick/darwin/SDL_iokitjoystick.c b/thirdparty/sdl/joystick/darwin/SDL_iokitjoystick.c
index e87ab8243ca..b88258f18da 100644
--- a/thirdparty/sdl/joystick/darwin/SDL_iokitjoystick.c
+++ b/thirdparty/sdl/joystick/darwin/SDL_iokitjoystick.c
@@ -1,6 +1,6 @@
/*
Simple DirectMedia Layer
- Copyright (C) 1997-2025 Sam Lantinga <[email protected]>
+ Copyright (C) 1997-2026 Sam Lantinga <[email protected]>
This software is provided 'as-is', without any express or implied
warranty. In no event will the authors be held liable for any damages
@@ -28,6 +28,8 @@
#include "../hidapi/SDL_hidapijoystick_c.h"
#include "../../haptic/darwin/SDL_syshaptic_c.h" // For haptic hot plugging
#include "../usb_ids.h"
+#include "../../SDL_hints_c.h"
+#include <IOKit/IOKitLib.h>
#define SDL_JOYSTICK_RUNLOOP_MODE CFSTR("SDLJoystick")
@@ -442,6 +444,16 @@ static int GetSteamVirtualGamepadSlot(Uint16 vendor_id, Uint16 product_id, const
return slot;
}
+static bool IsControlledBy360ControllerDriver(IOHIDDeviceRef hidDevice)
+{
+ bool controlled_by_360controller = false;
+ io_service_t service = IOHIDDeviceGetService(hidDevice);
+ if (service != MACH_PORT_NULL) {
+ controlled_by_360controller = IOObjectConformsTo(service, "Xbox360ControllerClass");
+ }
+ return controlled_by_360controller;
+}
+
static bool GetDeviceInfo(IOHIDDeviceRef hidDevice, recDevice *pDevice)
{
Sint32 vendor = 0;
@@ -499,11 +511,18 @@ static bool GetDeviceInfo(IOHIDDeviceRef hidDevice, recDevice *pDevice)
CFNumberGetValue(refCF, kCFNumberSInt32Type, &version);
}
- if (SDL_IsJoystickXboxOne(vendor, product)) {
- // We can't actually use this API for Xbox controllers
+ if (!IsControlledBy360ControllerDriver(hidDevice) && SDL_IsJoystickXboxOne(vendor, product)) {
+ // We can't actually use this API for Xbox controllers without the 360Controller driver
return false;
}
+ if (SDL_IsJoystickSteamVirtualGamepad(vendor, product, version)) {
+ if (IOHIDDeviceGetProperty(hidDevice, CFSTR(kIOHIDVirtualHIDevice)) != kCFBooleanTrue) {
+ // This is a real Xbox 360 controller, adjust the version so it's not detected as a Steam virtual gamepad
+ version = 1;
+ }
+ }
+
// get device name
refCF = IOHIDDeviceGetProperty(hidDevice, CFSTR(kIOHIDManufacturerKey));
if ((!refCF) || (!CFStringGetCString(refCF, manufacturer_string, sizeof(manufacturer_string), kCFStringEncodingUTF8))) {
@@ -550,7 +569,7 @@ static bool JoystickAlreadyKnown(IOHIDDeviceRef ioHIDDeviceObject)
#ifdef SDL_JOYSTICK_MFI
extern bool IOS_SupportedHIDDevice(IOHIDDeviceRef device);
- if (IOS_SupportedHIDDevice(ioHIDDeviceObject)) {
+ if (!IsControlledBy360ControllerDriver(ioHIDDeviceObject) && IOS_SupportedHIDDevice(ioHIDDeviceObject)) {
return true;
}
#endif
diff --git a/thirdparty/sdl/joystick/darwin/SDL_iokitjoystick_c.h b/thirdparty/sdl/joystick/darwin/SDL_iokitjoystick_c.h
index 3a70d2bde1d..ec017eabe73 100644
--- a/thirdparty/sdl/joystick/darwin/SDL_iokitjoystick_c.h
+++ b/thirdparty/sdl/joystick/darwin/SDL_iokitjoystick_c.h
@@ -1,6 +1,6 @@
/*
Simple DirectMedia Layer
- Copyright (C) 1997-2025 Sam Lantinga <[email protected]>
+ Copyright (C) 1997-2026 Sam Lantinga <[email protected]>
This software is provided 'as-is', without any express or implied
warranty. In no event will the authors be held liable for any damages
diff --git a/thirdparty/sdl/joystick/hidapi/SDL_hidapi_8bitdo.c b/thirdparty/sdl/joystick/hidapi/SDL_hidapi_8bitdo.c
new file mode 100644
index 00000000000..8c607c2fb3a
--- /dev/null
+++ b/thirdparty/sdl/joystick/hidapi/SDL_hidapi_8bitdo.c
@@ -0,0 +1,789 @@
+/*
+ Simple DirectMedia Layer
+ Copyright (C) 1997-2026 Sam Lantinga <[email protected]>
+
+ 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"
+
+#ifdef SDL_JOYSTICK_HIDAPI
+
+#include "../SDL_sysjoystick.h"
+#include "SDL_hidapijoystick_c.h"
+#include "SDL_hidapi_rumble.h"
+
+#ifdef SDL_JOYSTICK_HIDAPI_8BITDO
+
+// Define this if you want to log all packets from the controller
+#if 0
+#define DEBUG_8BITDO_PROTOCOL
+#endif
+
+enum
+{
+ SDL_GAMEPAD_BUTTON_8BITDO_L4 = 11,
+ SDL_GAMEPAD_BUTTON_8BITDO_R4,
+ SDL_GAMEPAD_BUTTON_8BITDO_PL,
+ SDL_GAMEPAD_BUTTON_8BITDO_PR,
+ SDL_GAMEPAD_NUM_8BITDO_BUTTONS,
+};
+
+enum
+{
+ SDL_GAMEPAD_BUTTON_8BITDO_SHARE = 15,
+ SDL_GAMEPAD_NUM_8BITDO_ULTIMATE3_BUTTONS,
+};
+
+#define SDL_8BITDO_FEATURE_REPORTID 0x30
+#define SDL_8BITDO_FEATURE_REPORTID_ENABLE_SDL_REPORTID 0x06
+#define SDL_8BITDO_REPORTID_SDL_REPORTID 0x04
+#define SDL_8BITDO_REPORTID_NOT_SUPPORTED_SDL_REPORTID 0x03
+#define SDL_8BITDO_BT_REPORTID_SDL_REPORTID 0x01
+
+#define SDL_8BITDO_SENSOR_TIMESTAMP_ENABLE 0xAA
+#define ABITDO_ACCEL_SCALE 4096.f
+#define ABITDO_GYRO_MAX_DEGREES_PER_SECOND 2000.f
+
+
+#define LOAD32(A, B, C, D) ((((Uint32)(A)) << 0) | \
+ (((Uint32)(B)) << 8) | \
+ (((Uint32)(C)) << 16) | \
+ (((Uint32)(D)) << 24))
+
+
+typedef struct
+{
+ bool sensors_supported;
+ bool sensors_enabled;
+ bool touchpad_01_supported;
+ bool touchpad_02_supported;
+ bool rumble_supported;
+ bool trigger_rumble_supported;
+ bool rumble_type;
+ bool rgb_supported;
+ bool player_led_supported;
+ bool powerstate_supported;
+ bool sensor_timestamp_supported;
+ Uint8 serial[6];
+ Uint16 version;
+ Uint16 version_beta;
+ float accelScale;
+ float gyroScale;
+ Uint8 last_state[USB_PACKET_LENGTH];
+ Uint64 sensor_timestamp; // Nanoseconds. Simulate onboard clock. Different models have different rates vs different connection styles.
+ Uint64 sensor_timestamp_interval;
+ Uint8 rumble_left_value;
+ Uint8 rumble_right_value;
+ Uint8 trigger_rumble_left_value;
+ Uint8 trigger_rumble_right_value;
+ Uint32 last_tick;
+} SDL_Driver8BitDo_Context;
+
+#pragma pack(push,1)
+typedef struct
+{
+ bool sensors_supported;
+ bool touchpad_01_supported;
+ bool touchpad_02_supported;
+ bool rumble_supported;
+ bool rumble_type;
+ bool rgb_supported;
+ Uint8 device_type;
+ Uint8 serial[6];
+ Uint16 version;
+ Uint16 version_beta;
+ Uint16 pid;
+} ABITDO_DEVICE_INFO;
+
+typedef struct
+{
+ // Accelerometer values
+ short sAccelX;
+ short sAccelY;
+ short sAccelZ;
+
+ // Gyroscope values
+ short sGyroX;
+ short sGyroY;
+ short sGyroZ;
+} ABITDO_SENSORS;
+
+#pragma pack(pop)
+
+
+static void HIDAPI_Driver8BitDo_RegisterHints(SDL_HintCallback callback, void *userdata)
+{
+ SDL_AddHintCallback(SDL_HINT_JOYSTICK_HIDAPI_8BITDO, callback, userdata);
+}
+
+static void HIDAPI_Driver8BitDo_UnregisterHints(SDL_HintCallback callback, void *userdata)
+{
+ SDL_RemoveHintCallback(SDL_HINT_JOYSTICK_HIDAPI_8BITDO, callback, userdata);
+}
+
+static bool HIDAPI_Driver8BitDo_IsEnabled(void)
+{
+ return SDL_GetHintBoolean(SDL_HINT_JOYSTICK_HIDAPI_8BITDO, SDL_GetHintBoolean(SDL_HINT_JOYSTICK_HIDAPI, SDL_HIDAPI_DEFAULT));
+}
+
+static int ReadFeatureReport(SDL_hid_device *dev, Uint8 report_id, Uint8 *report, size_t length)
+{
+ SDL_memset(report, 0, length);
+ report[0] = report_id;
+ return SDL_hid_get_feature_report(dev, report, length);
+}
+
+static bool HIDAPI_Driver8BitDo_IsSupportedDevice(SDL_HIDAPI_Device *device, const char *name, SDL_GamepadType type, Uint16 vendor_id, Uint16 product_id, Uint16 version, int interface_number, int interface_class, int interface_subclass, int interface_protocol)
+{
+ if (vendor_id == USB_VENDOR_8BITDO) {
+ switch (product_id) {
+ case USB_PRODUCT_8BITDO_SF30_PRO:
+ case USB_PRODUCT_8BITDO_SF30_PRO_BT:
+ case USB_PRODUCT_8BITDO_SN30_PRO:
+ case USB_PRODUCT_8BITDO_SN30_PRO_BT:
+ case USB_PRODUCT_8BITDO_PRO_2:
+ case USB_PRODUCT_8BITDO_PRO_2_BT:
+ case USB_PRODUCT_8BITDO_PRO_3:
+ case USB_PRODUCT_8BITDO_ULTIMATE2_WIRELESS:
+ case USB_PRODUCT_8BITDO_ULTIMATE3:
+ return true;
+ default:
+ break;
+ }
+ }
+ return false;
+}
+
+static bool HIDAPI_Driver8BitDo_InitDevice(SDL_HIDAPI_Device *device)
+{
+ SDL_Driver8BitDo_Context *ctx = (SDL_Driver8BitDo_Context *)SDL_calloc(1, sizeof(*ctx));
+ if (!ctx) {
+ return false;
+ }
+ device->context = ctx;
+
+ if (device->product_id == USB_PRODUCT_8BITDO_ULTIMATE2_WIRELESS) {
+ // The Ultimate 2 Wireless v1.02 firmware has 12 byte reports, v1.03 firmware has 34 byte reports
+ const int ULTIMATE2_WIRELESS_V103_REPORT_SIZE = 34;
+ const int MAX_ATTEMPTS = 3;
+
+ for (int attempt = 0; attempt < MAX_ATTEMPTS; ++attempt) {
+ Uint8 data[USB_PACKET_LENGTH];
+ int size = SDL_hid_read_timeout(device->dev, data, sizeof(data), 80);
+ if (size == 0) {
+ // Try again
+ continue;
+ }
+ if (size >= ULTIMATE2_WIRELESS_V103_REPORT_SIZE) {
+ ctx->sensors_supported = true;
+ ctx->rumble_supported = true;
+ ctx->powerstate_supported = true;
+ }
+ break;
+ }
+ } else if (device->product_id == USB_PRODUCT_8BITDO_ULTIMATE3) {
+ // Supported by default
+ ctx->sensors_supported = true;
+ ctx->rumble_supported = true;
+ ctx->powerstate_supported = true;
+ ctx->sensor_timestamp_supported = true;
+ Uint8 data[USB_PACKET_LENGTH];
+ const int MAX_ATTEMPTS = 5;
+ for (int attempt = 0; attempt < MAX_ATTEMPTS; ++attempt) {
+ int size = ReadFeatureReport(device->dev, SDL_8BITDO_FEATURE_REPORTID, data, sizeof(data));
+ if (size > 0) {
+ if (data[3] == 0) {
+ ctx->rumble_supported = false;
+ ctx->trigger_rumble_supported = false;
+ }
+ if (data[3] & 0x02) {
+ ctx->trigger_rumble_supported = true;
+ }
+
+ if (data[4] == 0) {
+ ctx->sensors_supported = false;
+ ctx->sensor_timestamp_supported = false;
+ }
+ if (size >= 17 && data[11] != 0) {
+ char serial[18];
+ (void)SDL_snprintf(serial, sizeof(serial), "%.2x-%.2x-%.2x-%.2x-%.2x-%.2x",
+ data[16], data[15], data[14], data[13], data[12], data[11]);
+ HIDAPI_SetDeviceSerial(device, serial);
+ }
+ break;
+ }
+ SDL_Delay(10);
+ }
+ }
+ else {
+ Uint8 data[USB_PACKET_LENGTH];
+ const int MAX_ATTEMPTS = 5;
+ for (int attempt = 0; attempt < MAX_ATTEMPTS; ++attempt) {
+ int size = ReadFeatureReport(device->dev, SDL_8BITDO_FEATURE_REPORTID_ENABLE_SDL_REPORTID, data, sizeof(data));
+ if (size > 0) {
+#ifdef DEBUG_8BITDO_PROTOCOL
+ HIDAPI_DumpPacket("8BitDo features packet: size = %d", data, size);
+#endif
+ ctx->sensors_supported = true;
+ ctx->rumble_supported = true;
+ ctx->powerstate_supported = true;
+
+ if (size >= 14 && data[13] == SDL_8BITDO_SENSOR_TIMESTAMP_ENABLE) {
+ ctx->sensor_timestamp_supported = true;
+ }
+
+ // Set the serial number to the Bluetooth MAC address
+ if (size >= 12 && data[10] != 0) {
+ char serial[18];
+ (void)SDL_snprintf(serial, sizeof(serial), "%.2x-%.2x-%.2x-%.2x-%.2x-%.2x",
+ data[10], data[9], data[8], data[7], data[6], data[5]);
+ HIDAPI_SetDeviceSerial(device, serial);
+ }
+ break;
+ }
+
+ // Try again
+ SDL_Delay(10);
+ }
+ }
+
+ if (device->product_id == USB_PRODUCT_8BITDO_SF30_PRO || device->product_id == USB_PRODUCT_8BITDO_SF30_PRO_BT) {
+ HIDAPI_SetDeviceName(device, "8BitDo SF30 Pro");
+ } else if (device->product_id == USB_PRODUCT_8BITDO_SN30_PRO || device->product_id == USB_PRODUCT_8BITDO_SN30_PRO_BT) {
+ HIDAPI_SetDeviceName(device, "8BitDo SN30 Pro");
+ } else if (device->product_id == USB_PRODUCT_8BITDO_PRO_2 || device->product_id == USB_PRODUCT_8BITDO_PRO_2_BT) {
+ HIDAPI_SetDeviceName(device, "8BitDo Pro 2");
+ } else if (device->product_id == USB_PRODUCT_8BITDO_PRO_3) {
+ HIDAPI_SetDeviceName(device, "8BitDo Pro 3");
+ }
+
+ return HIDAPI_JoystickConnected(device, NULL);
+}
+
+static int HIDAPI_Driver8BitDo_GetDevicePlayerIndex(SDL_HIDAPI_Device *device, SDL_JoystickID instance_id)
+{
+ return -1;
+}
+
+static void HIDAPI_Driver8BitDo_SetDevicePlayerIndex(SDL_HIDAPI_Device *device, SDL_JoystickID instance_id, int player_index)
+{
+}
+
+static Uint64 HIDAPI_Driver8BitDo_GetIMURateForProductID(SDL_HIDAPI_Device *device)
+{
+ SDL_Driver8BitDo_Context *ctx = (SDL_Driver8BitDo_Context *)device->context;
+
+ // TODO: If sensor time stamp is sent, these fixed settings from observation can be replaced
+ switch (device->product_id) {
+ case USB_PRODUCT_8BITDO_SF30_PRO:
+ case USB_PRODUCT_8BITDO_SF30_PRO_BT:
+ case USB_PRODUCT_8BITDO_SN30_PRO:
+ case USB_PRODUCT_8BITDO_SN30_PRO_BT:
+ if (device->is_bluetooth) {
+ // Note, This is estimated by observation of Bluetooth packets received in the testcontroller tool
+ return 70; // Observed to be anywhere between 60-90 hz. Possibly lossy in current state
+ } else if (ctx->sensor_timestamp_supported) {
+ // This firmware appears to update at 200 Hz over USB
+ return 200;
+ } else {
+ // This firmware appears to update at 100 Hz over USB
+ return 100;
+ }
+ case USB_PRODUCT_8BITDO_PRO_2:
+ case USB_PRODUCT_8BITDO_PRO_2_BT: // Note, labeled as "BT" but appears this way when wired.
+ case USB_PRODUCT_8BITDO_PRO_3:
+ if (device->is_bluetooth) {
+ // Note, This is estimated by observation of Bluetooth packets received in the testcontroller tool
+ return 85; // Observed Bluetooth packet rate seems to be 80-90hz
+ } else if (ctx->sensor_timestamp_supported) {
+ // This firmware appears to update at 200 Hz over USB
+ return 200;
+ } else {
+ // This firmware appears to update at 100 Hz over USB
+ return 100;
+ }
+ case USB_PRODUCT_8BITDO_ULTIMATE2_WIRELESS:
+ if (device->is_bluetooth) {
+ // Note, This is estimated by observation of Bluetooth packets received in the testcontroller tool
+ return 120; // Observed Bluetooth packet rate seems to be 120hz
+ } else {
+ // This firmware appears to update at 1000 Hz over USB dongle
+ return 1000;
+ }
+ case USB_PRODUCT_8BITDO_ULTIMATE3:
+ return 120;
+ default:
+ return 120;
+ }
+}
+
+#ifndef DEG2RAD
+#define DEG2RAD(x) ((float)(x) * (float)(SDL_PI_F / 180.f))
+#endif
+
+static bool HIDAPI_Driver8BitDo_OpenJoystick(SDL_HIDAPI_Device *device, SDL_Joystick *joystick)
+{
+ SDL_Driver8BitDo_Context *ctx = (SDL_Driver8BitDo_Context *)device->context;
+
+ SDL_AssertJoysticksLocked();
+
+ SDL_zeroa(ctx->last_state);
+
+ // Initialize the joystick capabilities
+ if (device->product_id == USB_PRODUCT_8BITDO_PRO_2 ||
+ device->product_id == USB_PRODUCT_8BITDO_PRO_2_BT ||
+ device->product_id == USB_PRODUCT_8BITDO_PRO_3 ||
+ device->product_id == USB_PRODUCT_8BITDO_ULTIMATE2_WIRELESS) {
+ // This controller has additional buttons
+ joystick->nbuttons = SDL_GAMEPAD_NUM_8BITDO_BUTTONS;
+ } else if (device->product_id == USB_PRODUCT_8BITDO_ULTIMATE3) {
+ joystick->nbuttons = SDL_GAMEPAD_NUM_8BITDO_ULTIMATE3_BUTTONS;
+ } else {
+ joystick->nbuttons = 11;
+ }
+ joystick->naxes = SDL_GAMEPAD_AXIS_COUNT;
+ joystick->nhats = 1;
+
+ if (ctx->sensors_supported) {
+
+ // Different 8Bitdo controllers in different connection modes have different polling rates.
+ const Uint64 imu_polling_rate = HIDAPI_Driver8BitDo_GetIMURateForProductID(device);
+ ctx->sensor_timestamp_interval = SDL_NS_PER_SECOND / imu_polling_rate;
+
+ SDL_PrivateJoystickAddSensor(joystick, SDL_SENSOR_GYRO, (float)imu_polling_rate);
+ SDL_PrivateJoystickAddSensor(joystick, SDL_SENSOR_ACCEL, (float)imu_polling_rate);
+
+ ctx->accelScale = SDL_STANDARD_GRAVITY / ABITDO_ACCEL_SCALE;
+ // Hardware senses +/- N Degrees per second mapped to +/- INT16_MAX
+ ctx->gyroScale = DEG2RAD(ABITDO_GYRO_MAX_DEGREES_PER_SECOND) / INT16_MAX;
+ }
+
+ return true;
+}
+
+static bool HIDAPI_Driver8BitDo_RumbleJoystick(SDL_HIDAPI_Device *device, SDL_Joystick *joystick, Uint16 low_frequency_rumble, Uint16 high_frequency_rumble)
+{
+ SDL_Driver8BitDo_Context *ctx = (SDL_Driver8BitDo_Context *)device->context;
+ if (ctx->rumble_supported) {
+ Uint8 rumble_packet[5] = { 0x05, 0x00, 0x00, 0x00, 0x00 };
+ rumble_packet[1] = low_frequency_rumble >> 8;
+ rumble_packet[2] = high_frequency_rumble >> 8;
+ if (ctx->trigger_rumble_supported) {
+ rumble_packet[3] = ctx->trigger_rumble_left_value;
+ rumble_packet[4] = ctx->trigger_rumble_right_value;
+ ctx->rumble_left_value = rumble_packet[1];
+ ctx->rumble_right_value = rumble_packet[2];
+ }
+
+ if (SDL_HIDAPI_SendRumble(device, rumble_packet, sizeof(rumble_packet)) != sizeof(rumble_packet)) {
+ return SDL_SetError("Couldn't send rumble packet");
+ }
+ return true;
+ } else {
+ return SDL_Unsupported();
+ }
+}
+
+static bool HIDAPI_Driver8BitDo_RumbleJoystickTriggers(SDL_HIDAPI_Device *device, SDL_Joystick *joystick, Uint16 left_rumble, Uint16 right_rumble)
+{
+ SDL_Driver8BitDo_Context* ctx = (SDL_Driver8BitDo_Context*)device->context;
+ if (ctx->trigger_rumble_supported) {
+ Uint8 rumble_packet[5] = { 0x05, 0x00, 0x00, 0x00, 0x00 };
+ rumble_packet[3] = left_rumble >> 8;
+ rumble_packet[4] = right_rumble >> 8;
+ if (ctx->rumble_supported) {
+ rumble_packet[1] = ctx->rumble_left_value;
+ rumble_packet[2] = ctx->rumble_right_value;
+ ctx->trigger_rumble_left_value = rumble_packet[3];
+ ctx->trigger_rumble_right_value = rumble_packet[4];
+ }
+
+ if (SDL_HIDAPI_SendRumble(device, rumble_packet, sizeof(rumble_packet)) != sizeof(rumble_packet)) {
+ return SDL_SetError("Couldn't send rumble packet");
+ }
+ return true;
+ } else {
+ return SDL_Unsupported();
+ }
+}
+
+static Uint32 HIDAPI_Driver8BitDo_GetJoystickCapabilities(SDL_HIDAPI_Device *device, SDL_Joystick *joystick)
+{
+ SDL_Driver8BitDo_Context *ctx = (SDL_Driver8BitDo_Context *)device->context;
+ Uint32 caps = 0;
+ if (ctx->rumble_supported) {
+ caps |= SDL_JOYSTICK_CAP_RUMBLE;
+ }
+ if (ctx->rgb_supported) {
+ caps |= SDL_JOYSTICK_CAP_RGB_LED;
+ }
+ return caps;
+}
+
+static bool HIDAPI_Driver8BitDo_SetJoystickLED(SDL_HIDAPI_Device *device, SDL_Joystick *joystick, Uint8 red, Uint8 green, Uint8 blue)
+{
+ return SDL_Unsupported();
+}
+
+static bool HIDAPI_Driver8BitDo_SendJoystickEffect(SDL_HIDAPI_Device *device, SDL_Joystick *joystick, const void *data, int size)
+{
+ return SDL_Unsupported();
+}
+
+static bool HIDAPI_Driver8BitDo_SetJoystickSensorsEnabled(SDL_HIDAPI_Device *device, SDL_Joystick *joystick, bool enabled)
+{
+ SDL_Driver8BitDo_Context *ctx = (SDL_Driver8BitDo_Context *)device->context;
+ if (ctx->sensors_supported) {
+ ctx->sensors_enabled = enabled;
+ return true;
+ }
+ return SDL_Unsupported();
+}
+
+static void HIDAPI_Driver8BitDo_HandleOldStatePacket(SDL_Joystick *joystick, SDL_Driver8BitDo_Context *ctx, Uint8 *data, int size)
+{
+ Sint16 axis;
+ Uint64 timestamp = SDL_GetTicksNS();
+
+ if (ctx->last_state[2] != data[2]) {
+ Uint8 hat;
+
+ switch (data[2]) {
+ case 0:
+ hat = SDL_HAT_UP;
+ break;
+ case 1:
+ hat = SDL_HAT_RIGHTUP;
+ break;
+ case 2:
+ hat = SDL_HAT_RIGHT;
+ break;
+ case 3:
+ hat = SDL_HAT_RIGHTDOWN;
+ break;
+ case 4:
+ hat = SDL_HAT_DOWN;
+ break;
+ case 5:
+ hat = SDL_HAT_LEFTDOWN;
+ break;
+ case 6:
+ hat = SDL_HAT_LEFT;
+ break;
+ case 7:
+ hat = SDL_HAT_LEFTUP;
+ break;
+ default:
+ hat = SDL_HAT_CENTERED;
+ break;
+ }
+ SDL_SendJoystickHat(timestamp, joystick, 0, hat);
+ }
+
+ if (ctx->last_state[0] != data[0]) {
+ SDL_SendJoystickButton(timestamp, joystick, SDL_GAMEPAD_BUTTON_SOUTH, ((data[0] & 0x01) != 0));
+ SDL_SendJoystickButton(timestamp, joystick, SDL_GAMEPAD_BUTTON_EAST, ((data[0] & 0x02) != 0));
+ SDL_SendJoystickButton(timestamp, joystick, SDL_GAMEPAD_BUTTON_WEST, ((data[0] & 0x08) != 0));
+ SDL_SendJoystickButton(timestamp, joystick, SDL_GAMEPAD_BUTTON_NORTH, ((data[0] & 0x10) != 0));
+ SDL_SendJoystickButton(timestamp, joystick, SDL_GAMEPAD_BUTTON_LEFT_SHOULDER, ((data[0] & 0x40) != 0));
+ SDL_SendJoystickButton(timestamp, joystick, SDL_GAMEPAD_BUTTON_RIGHT_SHOULDER, ((data[0] & 0x80) != 0));
+ }
+
+ if (ctx->last_state[1] != data[1]) {
+ SDL_SendJoystickButton(timestamp, joystick, SDL_GAMEPAD_BUTTON_GUIDE, ((data[1] & 0x10) != 0));
+ SDL_SendJoystickButton(timestamp, joystick, SDL_GAMEPAD_BUTTON_BACK, ((data[1] & 0x04) != 0));
+ SDL_SendJoystickButton(timestamp, joystick, SDL_GAMEPAD_BUTTON_START, ((data[1] & 0x08) != 0));
+ SDL_SendJoystickButton(timestamp, joystick, SDL_GAMEPAD_BUTTON_LEFT_STICK, ((data[1] & 0x20) != 0));
+ SDL_SendJoystickButton(timestamp, joystick, SDL_GAMEPAD_BUTTON_RIGHT_STICK, ((data[1] & 0x40) != 0));
+
+ SDL_SendJoystickAxis(timestamp, joystick, SDL_GAMEPAD_AXIS_LEFT_TRIGGER, (data[1] & 0x01) ? SDL_MAX_SINT16 : SDL_MIN_SINT16);
+ SDL_SendJoystickAxis(timestamp, joystick, SDL_GAMEPAD_AXIS_RIGHT_TRIGGER, (data[1] & 0x02) ? SDL_MAX_SINT16 : SDL_MIN_SINT16);
+ }
+
+#define READ_STICK_AXIS(offset) \
+ (data[offset] == 0x7f ? 0 : (Sint16)HIDAPI_RemapVal((float)((int)data[offset] - 0x7f), -0x7f, 0xff - 0x7f, SDL_MIN_SINT16, SDL_MAX_SINT16))
+ {
+ axis = READ_STICK_AXIS(3);
+ SDL_SendJoystickAxis(timestamp, joystick, SDL_GAMEPAD_AXIS_LEFTX, axis);
+ axis = READ_STICK_AXIS(4);
+ SDL_SendJoystickAxis(timestamp, joystick, SDL_GAMEPAD_AXIS_LEFTY, axis);
+ axis = READ_STICK_AXIS(5);
+ SDL_SendJoystickAxis(timestamp, joystick, SDL_GAMEPAD_AXIS_RIGHTX, axis);
+ axis = READ_STICK_AXIS(6);
+ SDL_SendJoystickAxis(timestamp, joystick, SDL_GAMEPAD_AXIS_RIGHTY, axis);
+ }
+#undef READ_STICK_AXIS
+
+ SDL_memcpy(ctx->last_state, data, SDL_min(size, sizeof(ctx->last_state)));
+}
+
+static void HIDAPI_Driver8BitDo_HandleStatePacket(SDL_Joystick *joystick, SDL_Driver8BitDo_Context *ctx, Uint8 *data, int size)
+{
+ Sint16 axis;
+ Uint64 timestamp = SDL_GetTicksNS();
+
+ switch (data[0]) {
+ case SDL_8BITDO_REPORTID_NOT_SUPPORTED_SDL_REPORTID: // Firmware without enhanced mode
+ case SDL_8BITDO_REPORTID_SDL_REPORTID: // Enhanced mode USB report
+ case SDL_8BITDO_BT_REPORTID_SDL_REPORTID: // Enhanced mode Bluetooth report
+ break;
+ default:
+ // We don't know how to handle this report
+ return;
+ }
+
+ if (ctx->last_state[1] != data[1]) {
+ Uint8 hat;
+
+ switch (data[1]) {
+ case 0:
+ hat = SDL_HAT_UP;
+ break;
+ case 1:
+ hat = SDL_HAT_RIGHTUP;
+ break;
+ case 2:
+ hat = SDL_HAT_RIGHT;
+ break;
+ case 3:
+ hat = SDL_HAT_RIGHTDOWN;
+ break;
+ case 4:
+ hat = SDL_HAT_DOWN;
+ break;
+ case 5:
+ hat = SDL_HAT_LEFTDOWN;
+ break;
+ case 6:
+ hat = SDL_HAT_LEFT;
+ break;
+ case 7:
+ hat = SDL_HAT_LEFTUP;
+ break;
+ default:
+ hat = SDL_HAT_CENTERED;
+ break;
+ }
+ SDL_SendJoystickHat(timestamp, joystick, 0, hat);
+ }
+
+
+ if (ctx->last_state[8] != data[8]) {
+ SDL_SendJoystickButton(timestamp, joystick, SDL_GAMEPAD_BUTTON_SOUTH, ((data[8] & 0x01) != 0));
+ SDL_SendJoystickButton(timestamp, joystick, SDL_GAMEPAD_BUTTON_EAST, ((data[8] & 0x02) != 0));
+ SDL_SendJoystickButton(timestamp, joystick, SDL_GAMEPAD_BUTTON_WEST, ((data[8] & 0x08) != 0));
+ SDL_SendJoystickButton(timestamp, joystick, SDL_GAMEPAD_BUTTON_NORTH, ((data[8] & 0x10) != 0));
+ SDL_SendJoystickButton(timestamp, joystick, SDL_GAMEPAD_BUTTON_LEFT_SHOULDER, ((data[8] & 0x40) != 0));
+ SDL_SendJoystickButton(timestamp, joystick, SDL_GAMEPAD_BUTTON_RIGHT_SHOULDER, ((data[8] & 0x80) != 0));
+
+ SDL_SendJoystickButton(timestamp, joystick, SDL_GAMEPAD_BUTTON_8BITDO_PL, ((data[8] & 0x20) != 0));
+ SDL_SendJoystickButton(timestamp, joystick, SDL_GAMEPAD_BUTTON_8BITDO_PR, ((data[8] & 0x04) != 0));
+ }
+
+ if (ctx->last_state[9] != data[9]) {
+ SDL_SendJoystickButton(timestamp, joystick, SDL_GAMEPAD_BUTTON_GUIDE, ((data[9] & 0x10) != 0));
+ SDL_SendJoystickButton(timestamp, joystick, SDL_GAMEPAD_BUTTON_BACK, ((data[9] & 0x04) != 0));
+ SDL_SendJoystickButton(timestamp, joystick, SDL_GAMEPAD_BUTTON_START, ((data[9] & 0x08) != 0));
+ SDL_SendJoystickButton(timestamp, joystick, SDL_GAMEPAD_BUTTON_LEFT_STICK, ((data[9] & 0x20) != 0));
+ SDL_SendJoystickButton(timestamp, joystick, SDL_GAMEPAD_BUTTON_RIGHT_STICK, ((data[9] & 0x40) != 0));
+ if (joystick->nbuttons >= SDL_GAMEPAD_NUM_8BITDO_ULTIMATE3_BUTTONS) {
+ SDL_SendJoystickButton(timestamp, joystick, SDL_GAMEPAD_BUTTON_8BITDO_SHARE, ((data[9] & 0x80) != 0));
+ }
+ }
+
+ if (size > 10 && ctx->last_state[10] != data[10]) {
+ SDL_SendJoystickButton(timestamp, joystick, SDL_GAMEPAD_BUTTON_8BITDO_L4, ((data[10] & 0x01) != 0));
+ SDL_SendJoystickButton(timestamp, joystick, SDL_GAMEPAD_BUTTON_8BITDO_R4, ((data[10] & 0x02) != 0));
+ }
+
+#define READ_STICK_AXIS(offset) \
+ (data[offset] == 0x7f ? 0 : (Sint16)HIDAPI_RemapVal((float)((int)data[offset] - 0x7f), -0x7f, 0xff - 0x7f, SDL_MIN_SINT16, SDL_MAX_SINT16))
+ {
+ axis = READ_STICK_AXIS(2);
+ SDL_SendJoystickAxis(timestamp, joystick, SDL_GAMEPAD_AXIS_LEFTX, axis);
+ axis = READ_STICK_AXIS(3);
+ SDL_SendJoystickAxis(timestamp, joystick, SDL_GAMEPAD_AXIS_LEFTY, axis);
+ axis = READ_STICK_AXIS(4);
+ SDL_SendJoystickAxis(timestamp, joystick, SDL_GAMEPAD_AXIS_RIGHTX, axis);
+ axis = READ_STICK_AXIS(5);
+ SDL_SendJoystickAxis(timestamp, joystick, SDL_GAMEPAD_AXIS_RIGHTY, axis);
+ }
+#undef READ_STICK_AXIS
+
+#define READ_TRIGGER_AXIS(offset) \
+ (Sint16)(((int)data[offset] * 257) - 32768)
+ {
+ axis = READ_TRIGGER_AXIS(7);
+ SDL_SendJoystickAxis(timestamp, joystick, SDL_GAMEPAD_AXIS_LEFT_TRIGGER, axis);
+ axis = READ_TRIGGER_AXIS(6);
+ SDL_SendJoystickAxis(timestamp, joystick, SDL_GAMEPAD_AXIS_RIGHT_TRIGGER, axis);
+ }
+#undef READ_TRIGGER_AXIS
+
+ if (ctx->powerstate_supported) {
+ SDL_PowerState state;
+ int percent;
+ Uint8 status = data[14] >> 7;
+ Uint8 level = (data[14] & 0x7f);
+ if (level == 100) {
+ status = 2;
+ }
+ switch (status) {
+ case 0:
+ state = SDL_POWERSTATE_ON_BATTERY;
+ percent = level;
+ break;
+ case 1:
+ state = SDL_POWERSTATE_CHARGING;
+ percent = level;
+ break;
+ case 2:
+ state = SDL_POWERSTATE_CHARGED;
+ percent = 100;
+ break;
+ default:
+ state = SDL_POWERSTATE_UNKNOWN;
+ percent = 0;
+ break;
+ }
+ SDL_SendJoystickPowerInfo(joystick, state, percent);
+ }
+
+ if (ctx->sensors_enabled) {
+ Uint64 sensor_timestamp;
+ float values[3];
+ ABITDO_SENSORS *sensors = (ABITDO_SENSORS *)&data[15];
+
+ if (ctx->sensor_timestamp_supported) {
+ Uint32 delta;
+ Uint32 tick = LOAD32(data[27], data[28], data[29], data[30]);
+
+ if (ctx->last_tick) {
+ if (ctx->last_tick <= tick) {
+ delta = (tick - ctx->last_tick);
+ } else {
+ delta = (SDL_MAX_UINT32 - ctx->last_tick + tick + 1);
+ }
+ // Sanity check the delta value
+ if (delta < 100000) {
+ ctx->sensor_timestamp_interval = SDL_US_TO_NS(delta);
+ }
+ }
+ ctx->last_tick = tick;
+ }
+
+ // Note: we cannot use the time stamp of the receiving computer due to packet delay creating "spiky" timings.
+ // The imu time stamp is intended to be the sample time of the on-board hardware.
+ // In the absence of time stamp data from the data[], we can simulate that by
+ // advancing a time stamp by the observed/known imu clock rate. This is 8ms = 125 Hz
+ sensor_timestamp = ctx->sensor_timestamp;
+ ctx->sensor_timestamp += ctx->sensor_timestamp_interval;
+
+ // This device's IMU values are reported differently from SDL
+ // Thus we perform a rotation of the coordinate system to match the SDL standard.
+
+ // By observation of this device:
+ // Hardware x is reporting roll (rotation about the power jack's axis)
+ // Hardware y is reporting pitch (rotation about the horizontal axis)
+ // Hardware z is reporting yaw (rotation about the joysticks' center axis)
+ values[0] = -sensors->sGyroY * ctx->gyroScale; // Rotation around pitch axis
+ values[1] = sensors->sGyroZ * ctx->gyroScale; // Rotation around yaw axis
+ values[2] = -sensors->sGyroX * ctx->gyroScale; // Rotation around roll axis
+ SDL_SendJoystickSensor(timestamp, joystick, SDL_SENSOR_GYRO, sensor_timestamp, values, 3);
+
+ // By observation of this device:
+ // Accelerometer X is positive when front of the controller points toward the sky.
+ // Accelerometer y is positive when left side of the controller points toward the sky.
+ // Accelerometer Z is positive when sticks point toward the sky.
+ values[0] = -sensors->sAccelY * ctx->accelScale; // Acceleration along pitch axis
+ values[1] = sensors->sAccelZ * ctx->accelScale; // Acceleration along yaw axis
+ values[2] = -sensors->sAccelX * ctx->accelScale; // Acceleration along roll axis
+ SDL_SendJoystickSensor(timestamp, joystick, SDL_SENSOR_ACCEL, sensor_timestamp, values, 3);
+ }
+
+ SDL_memcpy(ctx->last_state, data, SDL_min(size, sizeof(ctx->last_state)));
+}
+
+static bool HIDAPI_Driver8BitDo_UpdateDevice(SDL_HIDAPI_Device *device)
+{
+ SDL_Driver8BitDo_Context *ctx = (SDL_Driver8BitDo_Context *)device->context;
+ SDL_Joystick *joystick = NULL;
+ Uint8 data[USB_PACKET_LENGTH];
+ int size = 0;
+
+ if (device->num_joysticks > 0) {
+ joystick = SDL_GetJoystickFromID(device->joysticks[0]);
+ } else {
+ return false;
+ }
+
+ while ((size = SDL_hid_read_timeout(device->dev, data, sizeof(data), 0)) > 0) {
+#ifdef DEBUG_8BITDO_PROTOCOL
+ HIDAPI_DumpPacket("8BitDo packet: size = %d", data, size);
+#endif
+ if (!joystick) {
+ continue;
+ }
+
+ if (size == 9) {
+ // Old firmware USB report for the SF30 Pro and SN30 Pro controllers
+ HIDAPI_Driver8BitDo_HandleOldStatePacket(joystick, ctx, data, size);
+ } else {
+ HIDAPI_Driver8BitDo_HandleStatePacket(joystick, ctx, data, size);
+ }
+ }
+
+ if (size < 0) {
+ // Read error, device is disconnected
+ HIDAPI_JoystickDisconnected(device, device->joysticks[0]);
+ }
+ return (size >= 0);
+}
+
+static void HIDAPI_Driver8BitDo_CloseJoystick(SDL_HIDAPI_Device *device, SDL_Joystick *joystick)
+{
+}
+
+static void HIDAPI_Driver8BitDo_FreeDevice(SDL_HIDAPI_Device *device)
+{
+}
+
+SDL_HIDAPI_DeviceDriver SDL_HIDAPI_Driver8BitDo = {
+ SDL_HINT_JOYSTICK_HIDAPI_8BITDO,
+ true,
+ HIDAPI_Driver8BitDo_RegisterHints,
+ HIDAPI_Driver8BitDo_UnregisterHints,
+ HIDAPI_Driver8BitDo_IsEnabled,
+ HIDAPI_Driver8BitDo_IsSupportedDevice,
+ HIDAPI_Driver8BitDo_InitDevice,
+ HIDAPI_Driver8BitDo_GetDevicePlayerIndex,
+ HIDAPI_Driver8BitDo_SetDevicePlayerIndex,
+ HIDAPI_Driver8BitDo_UpdateDevice,
+ HIDAPI_Driver8BitDo_OpenJoystick,
+ HIDAPI_Driver8BitDo_RumbleJoystick,
+ HIDAPI_Driver8BitDo_RumbleJoystickTriggers,
+ HIDAPI_Driver8BitDo_GetJoystickCapabilities,
+ HIDAPI_Driver8BitDo_SetJoystickLED,
+ HIDAPI_Driver8BitDo_SendJoystickEffect,
+ HIDAPI_Driver8BitDo_SetJoystickSensorsEnabled,
+ HIDAPI_Driver8BitDo_CloseJoystick,
+ HIDAPI_Driver8BitDo_FreeDevice,
+};
+
+#endif // SDL_JOYSTICK_HIDAPI_8BITDO
+
+#endif // SDL_JOYSTICK_HIDAPI
diff --git a/thirdparty/sdl/joystick/hidapi/SDL_hidapi_combined.c b/thirdparty/sdl/joystick/hidapi/SDL_hidapi_combined.c
index 5426edbd71e..e9bbfd9ce24 100644
--- a/thirdparty/sdl/joystick/hidapi/SDL_hidapi_combined.c
+++ b/thirdparty/sdl/joystick/hidapi/SDL_hidapi_combined.c
@@ -1,6 +1,6 @@
/*
Simple DirectMedia Layer
- Copyright (C) 1997-2025 Sam Lantinga <[email protected]>
+ Copyright (C) 1997-2026 Sam Lantinga <[email protected]>
This software is provided 'as-is', without any express or implied
warranty. In no event will the authors be held liable for any damages
@@ -76,9 +76,7 @@ static bool HIDAPI_DriverCombined_OpenJoystick(SDL_HIDAPI_Device *device, SDL_Jo
child = device->children[i];
child->driver->CloseJoystick(child, joystick);
}
- if (serial) {
- SDL_free(serial);
- }
+ SDL_free(serial);
return false;
}
@@ -102,9 +100,7 @@ static bool HIDAPI_DriverCombined_OpenJoystick(SDL_HIDAPI_Device *device, SDL_Jo
}
// Update the joystick with the combined serial numbers
- if (joystick->serial) {
- SDL_free(joystick->serial);
- }
+ SDL_free(joystick->serial);
joystick->serial = serial;
return true;
diff --git a/thirdparty/sdl/joystick/hidapi/SDL_hidapi_flydigi.c b/thirdparty/sdl/joystick/hidapi/SDL_hidapi_flydigi.c
new file mode 100644
index 00000000000..989609ca53c
--- /dev/null
+++ b/thirdparty/sdl/joystick/hidapi/SDL_hidapi_flydigi.c
@@ -0,0 +1,1076 @@
+/*
+ Simple DirectMedia Layer
+ Copyright (C) 1997-2026 Sam Lantinga <[email protected]>
+
+ 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"
+
+#ifdef SDL_JOYSTICK_HIDAPI
+
+#include "../SDL_sysjoystick.h"
+#include "SDL_hidapijoystick_c.h"
+#include "SDL_hidapi_rumble.h"
+#include "SDL_hidapi_flydigi.h"
+
+#ifdef SDL_JOYSTICK_HIDAPI_FLYDIGI
+
+// Define this if you want to log all packets from the controller
+#if 0
+#define DEBUG_FLYDIGI_PROTOCOL
+#endif
+
+#ifndef DEG2RAD
+#define DEG2RAD(x) ((float)(x) * (float)(SDL_PI_F / 180.f))
+#endif
+
+enum
+{
+ SDL_GAMEPAD_BUTTON_FLYDIGI_M1 = 11,
+ SDL_GAMEPAD_BUTTON_FLYDIGI_M2,
+ SDL_GAMEPAD_BUTTON_FLYDIGI_M3,
+ SDL_GAMEPAD_BUTTON_FLYDIGI_M4,
+ SDL_GAMEPAD_NUM_BASE_FLYDIGI_BUTTONS
+};
+
+/* Rate of IMU Sensor Packets over wireless dongle observed in testcontroller at 1000hz */
+#define SENSOR_INTERVAL_VADER4_PRO_DONGLE_RATE_HZ 1000
+#define SENSOR_INTERVAL_VADER4_PRO_DONGLE_NS (SDL_NS_PER_SECOND / SENSOR_INTERVAL_VADER4_PRO_DONGLE_RATE_HZ)
+/* Rate of IMU Sensor Packets over wired connection observed in testcontroller at 500hz */
+#define SENSOR_INTERVAL_VADER4_PRO_WIRED_RATE_HZ 500
+#define SENSOR_INTERVAL_VADER4_PRO_WIRED_NS (SDL_NS_PER_SECOND / SENSOR_INTERVAL_VADER4_PRO_WIRED_RATE_HZ)
+/* Rate of IMU Sensor Packets over wired connection observed in testcontroller at 500hz */
+#define SENSOR_INTERVAL_VADER5_PRO_RATE_HZ 500
+#define SENSOR_INTERVAL_VADER5_PRO_NS (SDL_NS_PER_SECOND / SENSOR_INTERVAL_VADER5_PRO_RATE_HZ)
+
+/* Rate of IMU Sensor Packets over wireless dongle observed in testcontroller at 295hz */
+#define SENSOR_INTERVAL_APEX5_DONGLE_RATE_HZ 295
+#define SENSOR_INTERVAL_APEX5_DONGLE_NS (SDL_NS_PER_SECOND / SENSOR_INTERVAL_APEX5_DONGLE_RATE_HZ)
+/* Rate of IMU Sensor Packets over wired connection observed in testcontroller at 970hz */
+#define SENSOR_INTERVAL_APEX5_WIRED_RATE_HZ 970
+#define SENSOR_INTERVAL_APEX5_WIRED_NS (SDL_NS_PER_SECOND / SENSOR_INTERVAL_APEX5_WIRED_RATE_HZ)
+
+#define FLYDIGI_ACQUIRE_CONTROLLER_HEARTBEAT_TIME 1000 * 30
+
+#define FLYDIGI_V1_CMD_REPORT_ID 0x05
+#define FLYDIGI_V1_HAPTIC_COMMAND 0x0F
+#define FLYDIGI_V1_GET_INFO_COMMAND 0xEC
+
+#define FLYDIGI_V2_CMD_REPORT_ID 0x03
+#define FLYDIGI_V2_MAGIC1 0x5A
+#define FLYDIGI_V2_MAGIC2 0xA5
+#define FLYDIGI_V2_GET_INFO_COMMAND 0x01
+#define FLYDIGI_V2_GET_STATUS_COMMAND 0x10
+#define FLYDIGI_V2_SET_STATUS_COMMAND 0x11
+#define FLYDIGI_V2_HAPTIC_COMMAND 0x12
+#define FLYDIGI_V2_ACQUIRE_CONTROLLER_COMMAND 0x1C
+#define FLYDIGI_V2_INPUT_REPORT 0xEF
+
+typedef struct
+{
+ SDL_HIDAPI_Device *device;
+ Uint8 deviceID;
+ bool available;
+ bool has_cz;
+ bool has_lmrm;
+ bool has_circle;
+ bool wireless;
+ bool sensors_supported;
+ bool sensors_enabled;
+ Uint16 firmware_version;
+ Uint64 sensor_timestamp_ns; // Simulate onboard clock. Advance by known time step. Nanoseconds.
+ Uint64 sensor_timestamp_step_ns; // Based on observed rate of receipt of IMU sensor packets.
+ float accelScale;
+ float gyroScale;
+ Uint64 next_heartbeat;
+ Uint64 last_packet;
+ Uint8 last_state[USB_PACKET_LENGTH];
+} SDL_DriverFlydigi_Context;
+
+
+static void HIDAPI_DriverFlydigi_RegisterHints(SDL_HintCallback callback, void *userdata)
+{
+ SDL_AddHintCallback(SDL_HINT_JOYSTICK_HIDAPI_FLYDIGI, callback, userdata);
+}
+
+static void HIDAPI_DriverFlydigi_UnregisterHints(SDL_HintCallback callback, void *userdata)
+{
+ SDL_RemoveHintCallback(SDL_HINT_JOYSTICK_HIDAPI_FLYDIGI, callback, userdata);
+}
+
+static bool HIDAPI_DriverFlydigi_IsEnabled(void)
+{
+ return SDL_GetHintBoolean(SDL_HINT_JOYSTICK_HIDAPI_FLYDIGI, SDL_GetHintBoolean(SDL_HINT_JOYSTICK_HIDAPI, SDL_HIDAPI_DEFAULT));
+}
+
+static bool HIDAPI_DriverFlydigi_IsSupportedDevice(SDL_HIDAPI_Device *device, const char *name, SDL_GamepadType type, Uint16 vendor_id, Uint16 product_id, Uint16 version, int interface_number, int interface_class, int interface_subclass, int interface_protocol)
+{
+ if (SDL_IsJoystickFlydigiController(vendor_id, product_id)) {
+ if (vendor_id == USB_VENDOR_FLYDIGI_V1) {
+ if (interface_number == 2) {
+ // Early controllers have their custom protocol on interface 2
+ return true;
+ }
+ } else {
+ // Newer controllers have their custom protocol on interface 1 or 2, but
+ // only expose one HID interface, so we'll accept any interface we see.
+ return true;
+ }
+ }
+ return false;
+}
+
+static void HIDAPI_DriverFlydigi_UpdateDeviceIdentity(SDL_HIDAPI_Device *device)
+{
+ SDL_DriverFlydigi_Context *ctx = (SDL_DriverFlydigi_Context *)device->context;
+
+ Uint8 controller_type = SDL_FLYDIGI_UNKNOWN;
+ switch (ctx->deviceID) {
+ case 19:
+ controller_type = SDL_FLYDIGI_APEX2;
+ break;
+ case 24:
+ case 26:
+ case 29:
+ controller_type = SDL_FLYDIGI_APEX3;
+ break;
+ case 84:
+ controller_type = SDL_FLYDIGI_APEX4;
+ break;
+ case 20:
+ case 21:
+ case 23:
+ controller_type = SDL_FLYDIGI_VADER2;
+ break;
+ case 22:
+ controller_type = SDL_FLYDIGI_VADER2_PRO;
+ break;
+ case 28:
+ controller_type = SDL_FLYDIGI_VADER3;
+ break;
+ case 80:
+ case 81:
+ controller_type = SDL_FLYDIGI_VADER3_PRO;
+ break;
+ case 85:
+ case 91:
+ case 105:
+ controller_type = SDL_FLYDIGI_VADER4_PRO;
+ break;
+ case 128:
+ case 129:
+ controller_type = SDL_FLYDIGI_APEX5;
+ break;
+ case 130:
+ controller_type = SDL_FLYDIGI_VADER5_PRO;
+ break;
+ case 133:
+ case 134:
+ controller_type = SDL_FLYDIGI_APEX5;
+ break;
+ default:
+ // Try to guess from the name of the controller
+ if (SDL_strcasestr(device->name, "VADER") != NULL) {
+ if (SDL_strstr(device->name, "VADER2") != NULL) {
+ controller_type = SDL_FLYDIGI_VADER2;
+ } else if (SDL_strstr(device->name, "VADER3") != NULL) {
+ controller_type = SDL_FLYDIGI_VADER3;
+ } else if (SDL_strstr(device->name, "VADER4") != NULL) {
+ controller_type = SDL_FLYDIGI_VADER4_PRO;
+ } else if (SDL_strstr(device->name, "Vader 5") != NULL) {
+ controller_type = SDL_FLYDIGI_VADER5_PRO;
+ }
+ } else if (SDL_strstr(device->name, "APEX") != NULL) {
+ if (SDL_strstr(device->name, "APEX2") != NULL) {
+ controller_type = SDL_FLYDIGI_APEX2;
+ } else if (SDL_strstr(device->name, "APEX3") != NULL) {
+ controller_type = SDL_FLYDIGI_APEX3;
+ } else if (SDL_strstr(device->name, "APEX4") != NULL) {
+ controller_type = SDL_FLYDIGI_APEX4;
+ } else if (SDL_strstr(device->name, "APEX5") != NULL) {
+ controller_type = SDL_FLYDIGI_APEX5;
+ }
+ }
+ break;
+ }
+ device->guid.data[15] = controller_type;
+
+ // This is the previous sensor default of 125hz.
+ // Override this in the switch statement below based on observed sensor packet rate.
+ ctx->sensor_timestamp_step_ns = SDL_NS_PER_SECOND / 125;
+
+ switch (controller_type) {
+ case SDL_FLYDIGI_APEX2:
+ HIDAPI_SetDeviceName(device, "Flydigi Apex 2");
+ break;
+ case SDL_FLYDIGI_APEX3:
+ HIDAPI_SetDeviceName(device, "Flydigi Apex 3");
+ break;
+ case SDL_FLYDIGI_APEX4:
+ // The Apex 4 controller has sensors, but they're only reported when gyro mouse is enabled
+ HIDAPI_SetDeviceName(device, "Flydigi Apex 4");
+ break;
+ case SDL_FLYDIGI_APEX5:
+ HIDAPI_SetDeviceName(device, "Flydigi Apex 5");
+ ctx->has_lmrm = true;
+ ctx->sensors_supported = true;
+ ctx->accelScale = SDL_STANDARD_GRAVITY / 4096.0f;
+ ctx->gyroScale = DEG2RAD(2000.0f);
+ ctx->sensor_timestamp_step_ns = ctx->wireless ? SENSOR_INTERVAL_APEX5_DONGLE_NS : SENSOR_INTERVAL_APEX5_WIRED_NS;
+ break;
+ case SDL_FLYDIGI_VADER2:
+ // The Vader 2 controller has sensors, but they're only reported when gyro mouse is enabled
+ HIDAPI_SetDeviceName(device, "Flydigi Vader 2");
+ ctx->has_cz = true;
+ break;
+ case SDL_FLYDIGI_VADER2_PRO:
+ HIDAPI_SetDeviceName(device, "Flydigi Vader 2 Pro");
+ ctx->has_cz = true;
+ break;
+ case SDL_FLYDIGI_VADER3:
+ HIDAPI_SetDeviceName(device, "Flydigi Vader 3");
+ ctx->has_cz = true;
+ break;
+ case SDL_FLYDIGI_VADER3_PRO:
+ HIDAPI_SetDeviceName(device, "Flydigi Vader 3 Pro");
+ ctx->has_cz = true;
+ ctx->sensors_supported = true;
+ ctx->accelScale = SDL_STANDARD_GRAVITY / 256.0f;
+ ctx->sensor_timestamp_step_ns = ctx->wireless ? SENSOR_INTERVAL_VADER4_PRO_DONGLE_NS : SENSOR_INTERVAL_VADER4_PRO_WIRED_NS;
+ break;
+ case SDL_FLYDIGI_VADER4_PRO:
+ HIDAPI_SetDeviceName(device, "Flydigi Vader 4 Pro");
+ ctx->has_cz = true;
+ ctx->sensors_supported = true;
+ ctx->accelScale = SDL_STANDARD_GRAVITY / 256.0f;
+ ctx->sensor_timestamp_step_ns = ctx->wireless ? SENSOR_INTERVAL_VADER4_PRO_DONGLE_NS : SENSOR_INTERVAL_VADER4_PRO_WIRED_NS;
+ break;
+ case SDL_FLYDIGI_VADER5_PRO:
+ HIDAPI_SetDeviceName(device, "Flydigi Vader 5 Pro");
+ ctx->has_cz = true;
+ ctx->has_lmrm = true;
+ ctx->has_circle = true;
+ ctx->sensors_supported = true;
+ ctx->accelScale = SDL_STANDARD_GRAVITY / 4096.0f;
+ ctx->gyroScale = DEG2RAD(2000.0f);
+ ctx->sensor_timestamp_step_ns = SENSOR_INTERVAL_VADER5_PRO_NS;
+ break;
+ default:
+ SDL_LogDebug(SDL_LOG_CATEGORY_INPUT, "Unknown FlyDigi controller with ID %d, name '%s'", ctx->deviceID, device->name);
+ break;
+ }
+}
+
+static void HIDAPI_DriverFlydigi_SetAvailable(SDL_HIDAPI_Device *device, bool available)
+{
+ SDL_DriverFlydigi_Context *ctx = (SDL_DriverFlydigi_Context *)device->context;
+
+ if (available == ctx->available) {
+ return;
+ }
+
+ if (available) {
+ if (device->num_joysticks == 0) {
+ HIDAPI_JoystickConnected(device, NULL);
+ }
+ } else {
+ if (device->num_joysticks > 0) {
+ HIDAPI_JoystickDisconnected(device, device->joysticks[0]);
+ }
+ }
+ ctx->available = available;
+}
+
+static int HIDAPI_DriverFlydigi_WritePacket(SDL_HIDAPI_Device *device, const Uint8 *data, size_t size)
+{
+ // We know that at the very least the Vader 5 now uses unnumbered reports for commands instead of FLYDIGI_V2_CMD_REPORT_ID.
+ // If other Flydigi things prove to do the same, we can tweak this check to be more general.
+ bool bUsesUnnumberedReports = (device->vendor_id == USB_VENDOR_FLYDIGI_V2 && device->product_id == USB_PRODUCT_FLYDIGI_V2_VADER);
+
+ if (bUsesUnnumberedReports && data[0] == FLYDIGI_V2_CMD_REPORT_ID) {
+ // Zero out the report byte.
+ Uint8 output[USB_PACKET_LENGTH];
+ SDL_memcpy(output, data, SDL_min(size, USB_PACKET_LENGTH));
+ output[0] = 0;
+ return SDL_hid_write(device->dev, output, SDL_min(size, USB_PACKET_LENGTH));
+ }
+
+ return SDL_hid_write(device->dev, data, size);
+}
+
+
+static bool HIDAPI_DriverFlydigi_InitControllerV1(SDL_HIDAPI_Device *device)
+{
+ SDL_DriverFlydigi_Context *ctx = (SDL_DriverFlydigi_Context *)device->context;
+
+ // Detecting the Vader 2 can take over 1000 read retries, so be generous here
+ for (int attempt = 0; ctx->deviceID == 0 && attempt < 30; ++attempt) {
+ const Uint8 request[] = { FLYDIGI_V1_CMD_REPORT_ID, FLYDIGI_V1_GET_INFO_COMMAND, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0 };
+ // This write will occasionally return -1, so ignore failure here and try again
+ (void)HIDAPI_DriverFlydigi_WritePacket(device, request, sizeof(request));
+
+ // Read the reply
+ for (int i = 0; i < 100; ++i) {
+ SDL_Delay(1);
+
+ Uint8 data[USB_PACKET_LENGTH];
+ int size = SDL_hid_read_timeout(device->dev, data, sizeof(data), 0);
+ if (size < 0) {
+ break;
+ }
+ if (size == 0) {
+ continue;
+ }
+
+#ifdef DEBUG_FLYDIGI_PROTOCOL
+ HIDAPI_DumpPacket("Flydigi packet: size = %d", data, size);
+#endif
+ if (size == 32 && data[15] == 236) {
+ ctx->deviceID = data[3];
+ ctx->firmware_version = LOAD16(data[9], data[10]);
+
+ char serial[9];
+ (void)SDL_snprintf(serial, sizeof(serial), "%.2x%.2x%.2x%.2x", data[5], data[6], data[7], data[8]);
+ HIDAPI_SetDeviceSerial(device, serial);
+
+ // The Vader 2 with firmware 6.0.4.9 doesn't report the connection state
+ if (ctx->firmware_version >= 0x6400) {
+ switch (data[13]) {
+ case 0:
+ // Wireless connection
+ ctx->wireless = true;
+ break;
+ case 1:
+ // Wired connection
+ ctx->wireless = false;
+ break;
+ default:
+ break;
+ }
+ }
+
+ // Done!
+ break;
+ }
+ }
+ }
+
+ HIDAPI_DriverFlydigi_UpdateDeviceIdentity(device);
+
+ HIDAPI_DriverFlydigi_SetAvailable(device, true);
+
+ return true;
+}
+
+static bool GetReply(SDL_HIDAPI_Device* device, Uint8 command, Uint8* data, size_t length)
+{
+ for (int i = 0; i < 100; ++i) {
+ SDL_Delay(1);
+
+ int size = SDL_hid_read_timeout(device->dev, data, length, 0);
+ if (size < 0) {
+ break;
+ }
+ if (size == 0) {
+ continue;
+ }
+
+#ifdef DEBUG_FLYDIGI_PROTOCOL
+ HIDAPI_DumpPacket("Flydigi packet: size = %d", data, size);
+#endif
+
+ if (size == 32) {
+ if (data[1] == FLYDIGI_V2_MAGIC1 && data[2] == FLYDIGI_V2_MAGIC2) {
+ // Skip the report ID
+ SDL_memmove(&data[0], &data[1], size - 1);
+ data[size - 1] = 0;
+ }
+ if (data[0] == FLYDIGI_V2_MAGIC1 && data[1] == FLYDIGI_V2_MAGIC2 && data[2] == command) {
+ return true;
+ }
+ }
+ }
+ return false;
+}
+
+static bool SDL_HIDAPI_Flydigi_SendInfoRequest(SDL_HIDAPI_Device *device)
+{
+ const Uint8 cmd[] = {
+ FLYDIGI_V2_CMD_REPORT_ID,
+ FLYDIGI_V2_MAGIC1,
+ FLYDIGI_V2_MAGIC2,
+ FLYDIGI_V2_GET_INFO_COMMAND,
+ 2,
+ 0
+ };
+
+ if (HIDAPI_DriverFlydigi_WritePacket(device, cmd, sizeof(cmd)) < 0) {
+ return SDL_SetError("Couldn't query controller info");
+ }
+ return true;
+}
+
+static void HIDAPI_DriverFlydigi_HandleInfoResponse(SDL_Joystick *joystick, SDL_DriverFlydigi_Context *ctx, Uint8 *data, int size)
+{
+ SDL_PowerState state;
+ int percent;
+ Uint8 status = (data[11] >> 4) & 0x0F;
+ Uint8 level = (data[11] & 0x0F);
+
+ switch (status) {
+ case 0:
+ state = SDL_POWERSTATE_ON_BATTERY;
+ percent = level * 20;
+ break;
+ case 1:
+ state = SDL_POWERSTATE_CHARGING;
+ percent = level * 20;
+ break;
+ case 2:
+ state = SDL_POWERSTATE_CHARGED;
+ percent = 100;
+ break;
+ default:
+ state = SDL_POWERSTATE_UNKNOWN;
+ percent = 0;
+ break;
+ }
+ SDL_SendJoystickPowerInfo(joystick, state, percent);
+}
+
+static bool SDL_HIDAPI_Flydigi_SendStatusRequest(SDL_HIDAPI_Device *device)
+{
+ const Uint8 cmd[] = {
+ FLYDIGI_V2_CMD_REPORT_ID,
+ FLYDIGI_V2_MAGIC1,
+ FLYDIGI_V2_MAGIC2,
+ FLYDIGI_V2_GET_STATUS_COMMAND
+ };
+
+ if (HIDAPI_DriverFlydigi_WritePacket(device, cmd, sizeof(cmd)) < 0) {
+ return SDL_SetError("Couldn't query controller status");
+ }
+ return true;
+}
+
+static void HIDAPI_DriverFlydigi_HandleStatusResponse(SDL_HIDAPI_Device *device, Uint8 *data, int size)
+{
+ if (data[9] == 1) {
+ HIDAPI_DriverFlydigi_SetAvailable(device, true);
+ } else {
+ // Click "Allow third-party apps to take over mappings" in the FlyDigi Space Station app
+ HIDAPI_DriverFlydigi_SetAvailable(device, false);
+ }
+}
+
+static bool SDL_HIDAPI_Flydigi_SendAcquireRequest(SDL_HIDAPI_Device *device, bool acquire)
+{
+ const Uint8 cmd[32] = {
+ FLYDIGI_V2_CMD_REPORT_ID,
+ FLYDIGI_V2_MAGIC1,
+ FLYDIGI_V2_MAGIC2,
+ FLYDIGI_V2_ACQUIRE_CONTROLLER_COMMAND,
+ 23,
+ acquire ? 1 : 0,
+ 'S', 'D', 'L', 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0
+ };
+
+ if (HIDAPI_DriverFlydigi_WritePacket(device, cmd, sizeof(cmd)) < 0) {
+ return SDL_SetError("Couldn't send acquire command");
+ }
+ return true;
+}
+
+static void HIDAPI_DriverFlydigi_HandleAcquireResponse(SDL_HIDAPI_Device *device, Uint8 *data, int size)
+{
+ if (data[5] != 1 && data[6] == 0) {
+ // Controller acquiring failed or has been disabled
+ HIDAPI_DriverFlydigi_SetAvailable(device, false);
+ }
+}
+
+static bool HIDAPI_DriverFlydigi_InitControllerV2(SDL_HIDAPI_Device *device)
+{
+ SDL_DriverFlydigi_Context *ctx = (SDL_DriverFlydigi_Context *)device->context;
+
+ Uint8 data[USB_PACKET_LENGTH];
+ if (!SDL_HIDAPI_Flydigi_SendInfoRequest(device)) {
+ return false;
+ }
+ if (!GetReply(device, FLYDIGI_V2_GET_INFO_COMMAND, data, sizeof(data))) {
+ return SDL_SetError("Couldn't get controller info");
+ }
+
+ // Check the firmware version
+ Uint16 min_firmware_version;
+ ctx->firmware_version = LOAD16(data[16], data[15]);
+ switch (device->product_id) {
+ case USB_PRODUCT_FLYDIGI_V2_APEX:
+ // Minimum supported firmware version, Apex 5
+ min_firmware_version = 0x7031;
+ break;
+ case USB_PRODUCT_FLYDIGI_V2_VADER:
+ // Minimum supported firmware version, Vader 5 Pro
+ min_firmware_version = 0x7141;
+ break;
+ default:
+ // Unknown product, presumably this version is okay?
+ min_firmware_version = 0;
+ break;
+ }
+ if (ctx->firmware_version < min_firmware_version) {
+ return SDL_SetError("Unsupported firmware version");
+ }
+
+ switch (data[6]) {
+ case 1:
+ // Wired connection
+ ctx->wireless = false;
+ break;
+ case 2:
+ // Wireless connection
+ ctx->wireless = true;
+ break;
+ default:
+ break;
+ }
+ ctx->deviceID = data[5];
+
+ HIDAPI_DriverFlydigi_UpdateDeviceIdentity(device);
+
+ // See whether we can acquire the controller
+ SDL_HIDAPI_Flydigi_SendStatusRequest(device);
+
+ return true;
+}
+
+static bool HIDAPI_DriverFlydigi_InitDevice(SDL_HIDAPI_Device *device)
+{
+ SDL_DriverFlydigi_Context *ctx = (SDL_DriverFlydigi_Context *)SDL_calloc(1, sizeof(*ctx));
+ if (!ctx) {
+ return false;
+ }
+ ctx->device = device;
+
+ device->context = ctx;
+
+ if (device->vendor_id == USB_VENDOR_FLYDIGI_V1) {
+ return HIDAPI_DriverFlydigi_InitControllerV1(device);
+ } else {
+ return HIDAPI_DriverFlydigi_InitControllerV2(device);
+ }
+}
+
+static int HIDAPI_DriverFlydigi_GetDevicePlayerIndex(SDL_HIDAPI_Device *device, SDL_JoystickID instance_id)
+{
+ return -1;
+}
+
+static void HIDAPI_DriverFlydigi_SetDevicePlayerIndex(SDL_HIDAPI_Device *device, SDL_JoystickID instance_id, int player_index)
+{
+}
+
+static bool HIDAPI_DriverFlydigi_OpenJoystick(SDL_HIDAPI_Device *device, SDL_Joystick *joystick)
+{
+ SDL_DriverFlydigi_Context *ctx = (SDL_DriverFlydigi_Context *)device->context;
+
+ SDL_AssertJoysticksLocked();
+
+ SDL_zeroa(ctx->last_state);
+
+ // Initialize the joystick capabilities
+ joystick->nbuttons = SDL_GAMEPAD_NUM_BASE_FLYDIGI_BUTTONS;
+ if (ctx->has_cz) {
+ joystick->nbuttons += 2;
+ }
+ if (ctx->has_lmrm) {
+ joystick->nbuttons += 2;
+ }
+ if (ctx->has_circle) {
+ joystick->nbuttons += 1;
+ }
+ joystick->naxes = SDL_GAMEPAD_AXIS_COUNT;
+ joystick->nhats = 1;
+
+ if (ctx->wireless) {
+ joystick->connection_state = SDL_JOYSTICK_CONNECTION_WIRELESS;
+ }
+
+ if (ctx->sensors_supported) {
+ const float flSensorRate = ctx->wireless ? (float)SENSOR_INTERVAL_VADER4_PRO_DONGLE_RATE_HZ : (float)SENSOR_INTERVAL_VADER4_PRO_WIRED_RATE_HZ;
+ SDL_PrivateJoystickAddSensor(joystick, SDL_SENSOR_GYRO, flSensorRate);
+ SDL_PrivateJoystickAddSensor(joystick, SDL_SENSOR_ACCEL, flSensorRate);
+ }
+ return true;
+}
+
+static bool HIDAPI_DriverFlydigi_RumbleJoystick(SDL_HIDAPI_Device *device, SDL_Joystick *joystick, Uint16 low_frequency_rumble, Uint16 high_frequency_rumble)
+{
+ if (device->vendor_id == USB_VENDOR_FLYDIGI_V1) {
+ Uint8 rumble_packet[] = { FLYDIGI_V1_CMD_REPORT_ID, FLYDIGI_V1_HAPTIC_COMMAND, 0x00, 0x00 };
+ rumble_packet[2] = low_frequency_rumble >> 8;
+ rumble_packet[3] = high_frequency_rumble >> 8;
+
+ if (SDL_HIDAPI_SendRumble(device, rumble_packet, sizeof(rumble_packet)) != sizeof(rumble_packet)) {
+ return SDL_SetError("Couldn't send rumble packet");
+ }
+ } else {
+ Uint8 rumble_packet[] = { FLYDIGI_V2_CMD_REPORT_ID, FLYDIGI_V2_MAGIC1, FLYDIGI_V2_MAGIC2, FLYDIGI_V2_HAPTIC_COMMAND, 6, 0, 0, 0, 0, 0 };
+ rumble_packet[5] = low_frequency_rumble >> 8;
+ rumble_packet[6] = high_frequency_rumble >> 8;
+
+ if (SDL_HIDAPI_SendRumble(device, rumble_packet, sizeof(rumble_packet)) != sizeof(rumble_packet)) {
+ return SDL_SetError("Couldn't send rumble packet");
+ }
+ }
+ return true;
+}
+
+static bool HIDAPI_DriverFlydigi_RumbleJoystickTriggers(SDL_HIDAPI_Device *device, SDL_Joystick *joystick, Uint16 left_rumble, Uint16 right_rumble)
+{
+ return SDL_Unsupported();
+}
+
+static Uint32 HIDAPI_DriverFlydigi_GetJoystickCapabilities(SDL_HIDAPI_Device *device, SDL_Joystick *joystick)
+{
+ return SDL_JOYSTICK_CAP_RUMBLE;
+}
+
+static bool HIDAPI_DriverFlydigi_SetJoystickLED(SDL_HIDAPI_Device *device, SDL_Joystick *joystick, Uint8 red, Uint8 green, Uint8 blue)
+{
+ return SDL_Unsupported();
+}
+
+static bool HIDAPI_DriverFlydigi_SendJoystickEffect(SDL_HIDAPI_Device *device, SDL_Joystick *joystick, const void *data, int size)
+{
+ return SDL_Unsupported();
+}
+
+static bool HIDAPI_DriverFlydigi_SetJoystickSensorsEnabled(SDL_HIDAPI_Device *device, SDL_Joystick *joystick, bool enabled)
+{
+ SDL_DriverFlydigi_Context *ctx = (SDL_DriverFlydigi_Context *)device->context;
+ if (ctx->sensors_supported) {
+ ctx->sensors_enabled = enabled;
+ return true;
+ }
+ return SDL_Unsupported();
+}
+
+static void HIDAPI_DriverFlydigi_HandleStatePacketV1(SDL_Joystick *joystick, SDL_DriverFlydigi_Context *ctx, Uint8 *data, int size)
+{
+ Sint16 axis;
+ Uint64 timestamp = SDL_GetTicksNS();
+
+ Uint8 extra_button_index = SDL_GAMEPAD_NUM_BASE_FLYDIGI_BUTTONS;
+
+ if (ctx->last_state[9] != data[9]) {
+ Uint8 hat;
+
+ switch (data[9] & 0x0F) {
+ case 0x01u:
+ hat = SDL_HAT_UP;
+ break;
+ case 0x02u | 0x01u:
+ hat = SDL_HAT_RIGHTUP;
+ break;
+ case 0x02u:
+ hat = SDL_HAT_RIGHT;
+ break;
+ case 0x02u | 0x04u:
+ hat = SDL_HAT_RIGHTDOWN;
+ break;
+ case 0x04u:
+ hat = SDL_HAT_DOWN;
+ break;
+ case 0x08u | 0x04u:
+ hat = SDL_HAT_LEFTDOWN;
+ break;
+ case 0x08u:
+ hat = SDL_HAT_LEFT;
+ break;
+ case 0x08u | 0x01u:
+ hat = SDL_HAT_LEFTUP;
+ break;
+ default:
+ hat = SDL_HAT_CENTERED;
+ break;
+ }
+ SDL_SendJoystickHat(timestamp, joystick, 0, hat);
+
+ SDL_SendJoystickButton(timestamp, joystick, SDL_GAMEPAD_BUTTON_SOUTH, ((data[9] & 0x10) != 0));
+ SDL_SendJoystickButton(timestamp, joystick, SDL_GAMEPAD_BUTTON_EAST, ((data[9] & 0x20) != 0));
+ SDL_SendJoystickButton(timestamp, joystick, SDL_GAMEPAD_BUTTON_BACK, ((data[9] & 0x40) != 0));
+ SDL_SendJoystickButton(timestamp, joystick, SDL_GAMEPAD_BUTTON_WEST, ((data[9] & 0x80) != 0));
+ }
+
+ if (ctx->last_state[10] != data[10]) {
+ SDL_SendJoystickButton(timestamp, joystick, SDL_GAMEPAD_BUTTON_NORTH, ((data[10] & 0x01) != 0));
+ SDL_SendJoystickButton(timestamp, joystick, SDL_GAMEPAD_BUTTON_START, ((data[10] & 0x02) != 0));
+ SDL_SendJoystickButton(timestamp, joystick, SDL_GAMEPAD_BUTTON_LEFT_SHOULDER, ((data[10] & 0x04) != 0));
+ SDL_SendJoystickButton(timestamp, joystick, SDL_GAMEPAD_BUTTON_RIGHT_SHOULDER, ((data[10] & 0x08) != 0));
+ SDL_SendJoystickButton(timestamp, joystick, SDL_GAMEPAD_BUTTON_LEFT_STICK, ((data[10] & 0x40) != 0));
+ SDL_SendJoystickButton(timestamp, joystick, SDL_GAMEPAD_BUTTON_RIGHT_STICK, ((data[10] & 0x80) != 0));
+ }
+
+ if (ctx->last_state[7] != data[7]) {
+ SDL_SendJoystickButton(timestamp, joystick, SDL_GAMEPAD_BUTTON_FLYDIGI_M1, ((data[7] & 0x04) != 0));
+ SDL_SendJoystickButton(timestamp, joystick, SDL_GAMEPAD_BUTTON_FLYDIGI_M2, ((data[7] & 0x08) != 0));
+ SDL_SendJoystickButton(timestamp, joystick, SDL_GAMEPAD_BUTTON_FLYDIGI_M3, ((data[7] & 0x10) != 0));
+ SDL_SendJoystickButton(timestamp, joystick, SDL_GAMEPAD_BUTTON_FLYDIGI_M4, ((data[7] & 0x20) != 0));
+ if (ctx->has_cz) {
+ SDL_SendJoystickButton(timestamp, joystick, extra_button_index++, ((data[7] & 0x01) != 0));
+ SDL_SendJoystickButton(timestamp, joystick, extra_button_index++, ((data[7] & 0x02) != 0));
+ }
+ }
+
+ if (ctx->last_state[8] != data[8]) {
+ SDL_SendJoystickButton(timestamp, joystick, SDL_GAMEPAD_BUTTON_GUIDE, ((data[8] & 0x08) != 0));
+ // The '+' button is used to toggle gyro mouse mode, so don't pass that to the application
+ // SDL_SendJoystickButton(timestamp, joystick, extra_button_index++, ((data[8] & 0x01) != 0));
+ // The '-' button is only available on the Vader 2, for simplicity let's ignore that
+ // SDL_SendJoystickButton(timestamp, joystick, extra_button_index++, ((data[8] & 0x10) != 0));
+ }
+
+#define READ_STICK_AXIS(offset) \
+ (data[offset] == 0x7f ? 0 : (Sint16)HIDAPI_RemapVal((float)((int)data[offset] - 0x7f), -0x7f, 0xff - 0x7f, SDL_MIN_SINT16, SDL_MAX_SINT16))
+ {
+ axis = READ_STICK_AXIS(17);
+ SDL_SendJoystickAxis(timestamp, joystick, SDL_GAMEPAD_AXIS_LEFTX, axis);
+ axis = READ_STICK_AXIS(19);
+ SDL_SendJoystickAxis(timestamp, joystick, SDL_GAMEPAD_AXIS_LEFTY, axis);
+ axis = READ_STICK_AXIS(21);
+ SDL_SendJoystickAxis(timestamp, joystick, SDL_GAMEPAD_AXIS_RIGHTX, axis);
+ axis = READ_STICK_AXIS(22);
+ SDL_SendJoystickAxis(timestamp, joystick, SDL_GAMEPAD_AXIS_RIGHTY, axis);
+ }
+#undef READ_STICK_AXIS
+
+#define READ_TRIGGER_AXIS(offset) \
+ (Sint16)(((int)data[offset] * 257) - 32768)
+ {
+ axis = READ_TRIGGER_AXIS(23);
+ SDL_SendJoystickAxis(timestamp, joystick, SDL_GAMEPAD_AXIS_LEFT_TRIGGER, axis);
+ axis = READ_TRIGGER_AXIS(24);
+ SDL_SendJoystickAxis(timestamp, joystick, SDL_GAMEPAD_AXIS_RIGHT_TRIGGER, axis);
+ }
+#undef READ_TRIGGER_AXIS
+
+ if (ctx->sensors_enabled) {
+ Uint64 sensor_timestamp;
+ float values[3];
+
+ // Advance the imu sensor time stamp based on the observed rate of receipt of packets in the testcontroller app.
+ // This varies between Product ID and connection type.
+ sensor_timestamp = ctx->sensor_timestamp_ns;
+ ctx->sensor_timestamp_ns += ctx->sensor_timestamp_step_ns;
+
+ // Pitch and yaw scales may be receiving extra filtering for the sake of bespoke direct mouse output.
+ // As result, roll has a different scaling factor than pitch and yaw.
+ // These values were estimated using the testcontroller tool in lieux of hard data sheet references.
+ const float flPitchAndYawScale = DEG2RAD(72000.0f);
+ const float flRollScale = DEG2RAD(1200.0f);
+
+ values[0] = HIDAPI_RemapVal(-1.0f * LOAD16(data[26], data[27]), INT16_MIN, INT16_MAX, -flPitchAndYawScale, flPitchAndYawScale);
+ values[1] = HIDAPI_RemapVal(-1.0f * LOAD16(data[18], data[20]), INT16_MIN, INT16_MAX, -flPitchAndYawScale, flPitchAndYawScale);
+ values[2] = HIDAPI_RemapVal(-1.0f * LOAD16(data[29], data[30]), INT16_MIN, INT16_MAX, -flRollScale, flRollScale);
+ SDL_SendJoystickSensor(timestamp, joystick, SDL_SENSOR_GYRO, sensor_timestamp, values, 3);
+
+ const float flAccelScale = ctx->accelScale;
+ values[0] = -LOAD16(data[11], data[12]) * flAccelScale; // Acceleration along pitch axis
+ values[1] = LOAD16(data[15], data[16]) * flAccelScale; // Acceleration along yaw axis
+ values[2] = LOAD16(data[13], data[14]) * flAccelScale; // Acceleration along roll axis
+ SDL_SendJoystickSensor(timestamp, joystick, SDL_SENSOR_ACCEL, sensor_timestamp, values, 3);
+ }
+
+ SDL_memcpy(ctx->last_state, data, SDL_min(size, sizeof(ctx->last_state)));
+}
+
+static void HIDAPI_DriverFlydigi_HandlePacketV1(SDL_Joystick *joystick, SDL_DriverFlydigi_Context *ctx, Uint8 *data, int size)
+{
+ if (data[0] != 0x04 || data[1] != 0xFE) {
+ // We don't know how to handle this report, ignore it
+ return;
+ }
+
+ if (joystick) {
+ HIDAPI_DriverFlydigi_HandleStatePacketV1(joystick, ctx, data, size);
+ }
+}
+
+static void HIDAPI_DriverFlydigi_HandleStatePacketV2(SDL_Joystick *joystick, SDL_DriverFlydigi_Context *ctx, Uint8 *data, int size)
+{
+ Sint16 axis;
+ Uint64 timestamp = SDL_GetTicksNS();
+
+ Uint8 extra_button_index = SDL_GAMEPAD_NUM_BASE_FLYDIGI_BUTTONS;
+
+ if (ctx->last_state[11] != data[11]) {
+ Uint8 hat;
+
+ switch (data[11] & 0x0F) {
+ case 0x01u:
+ hat = SDL_HAT_UP;
+ break;
+ case 0x02u | 0x01u:
+ hat = SDL_HAT_RIGHTUP;
+ break;
+ case 0x02u:
+ hat = SDL_HAT_RIGHT;
+ break;
+ case 0x02u | 0x04u:
+ hat = SDL_HAT_RIGHTDOWN;
+ break;
+ case 0x04u:
+ hat = SDL_HAT_DOWN;
+ break;
+ case 0x08u | 0x04u:
+ hat = SDL_HAT_LEFTDOWN;
+ break;
+ case 0x08u:
+ hat = SDL_HAT_LEFT;
+ break;
+ case 0x08u | 0x01u:
+ hat = SDL_HAT_LEFTUP;
+ break;
+ default:
+ hat = SDL_HAT_CENTERED;
+ break;
+ }
+ SDL_SendJoystickHat(timestamp, joystick, 0, hat);
+
+ SDL_SendJoystickButton(timestamp, joystick, SDL_GAMEPAD_BUTTON_SOUTH, ((data[11] & 0x10) != 0));
+ SDL_SendJoystickButton(timestamp, joystick, SDL_GAMEPAD_BUTTON_EAST, ((data[11] & 0x20) != 0));
+ SDL_SendJoystickButton(timestamp, joystick, SDL_GAMEPAD_BUTTON_BACK, ((data[11] & 0x40) != 0));
+ SDL_SendJoystickButton(timestamp, joystick, SDL_GAMEPAD_BUTTON_WEST, ((data[11] & 0x80) != 0));
+ }
+
+ if (ctx->last_state[12] != data[12]) {
+ SDL_SendJoystickButton(timestamp, joystick, SDL_GAMEPAD_BUTTON_NORTH, ((data[12] & 0x01) != 0));
+ SDL_SendJoystickButton(timestamp, joystick, SDL_GAMEPAD_BUTTON_START, ((data[12] & 0x02) != 0));
+ SDL_SendJoystickButton(timestamp, joystick, SDL_GAMEPAD_BUTTON_LEFT_SHOULDER, ((data[12] & 0x04) != 0));
+ SDL_SendJoystickButton(timestamp, joystick, SDL_GAMEPAD_BUTTON_RIGHT_SHOULDER, ((data[12] & 0x08) != 0));
+ SDL_SendJoystickButton(timestamp, joystick, SDL_GAMEPAD_BUTTON_LEFT_STICK, ((data[12] & 0x40) != 0));
+ SDL_SendJoystickButton(timestamp, joystick, SDL_GAMEPAD_BUTTON_RIGHT_STICK, ((data[12] & 0x80) != 0));
+ }
+
+ if (ctx->last_state[13] != data[13]) {
+ SDL_SendJoystickButton(timestamp, joystick, SDL_GAMEPAD_BUTTON_FLYDIGI_M1, ((data[13] & 0x04) != 0));
+ SDL_SendJoystickButton(timestamp, joystick, SDL_GAMEPAD_BUTTON_FLYDIGI_M2, ((data[13] & 0x08) != 0));
+ SDL_SendJoystickButton(timestamp, joystick, SDL_GAMEPAD_BUTTON_FLYDIGI_M3, ((data[13] & 0x10) != 0));
+ SDL_SendJoystickButton(timestamp, joystick, SDL_GAMEPAD_BUTTON_FLYDIGI_M4, ((data[13] & 0x20) != 0));
+ if (ctx->has_cz) {
+ SDL_SendJoystickButton(timestamp, joystick, extra_button_index++, ((data[13] & 0x01) != 0));
+ SDL_SendJoystickButton(timestamp, joystick, extra_button_index++, ((data[13] & 0x02) != 0));
+ }
+ if (ctx->has_lmrm) {
+ SDL_SendJoystickButton(timestamp, joystick, extra_button_index++, ((data[13] & 0x40) != 0));
+ SDL_SendJoystickButton(timestamp, joystick, extra_button_index++, ((data[13] & 0x80) != 0));
+ }
+ } else {
+ if (ctx->has_cz) {
+ extra_button_index += 2;
+ }
+ if (ctx->has_lmrm) {
+ extra_button_index += 2;
+ }
+ }
+
+ if (ctx->last_state[14] != data[14]) {
+ SDL_SendJoystickButton(timestamp, joystick, SDL_GAMEPAD_BUTTON_GUIDE, ((data[14] & 0x08) != 0));
+ if (ctx->has_circle) {
+ SDL_SendJoystickButton(timestamp, joystick, extra_button_index++, ((data[14] & 0x01) != 0));
+ }
+ }
+
+ axis = LOAD16(data[3], data[4]);
+ SDL_SendJoystickAxis(timestamp, joystick, SDL_GAMEPAD_AXIS_LEFTX, axis);
+ axis = -LOAD16(data[5], data[6]);
+ if (axis <= -32768) {
+ axis = 32767;
+ }
+ SDL_SendJoystickAxis(timestamp, joystick, SDL_GAMEPAD_AXIS_LEFTY, axis);
+ axis = LOAD16(data[7], data[8]);
+ SDL_SendJoystickAxis(timestamp, joystick, SDL_GAMEPAD_AXIS_RIGHTX, axis);
+ axis = -LOAD16(data[9], data[10]);
+ if (axis <= -32768) {
+ axis = 32767;
+ }
+ SDL_SendJoystickAxis(timestamp, joystick, SDL_GAMEPAD_AXIS_RIGHTY, axis);
+
+#define READ_TRIGGER_AXIS(offset) \
+ (Sint16)(((int)data[offset] * 257) - 32768)
+ {
+ axis = READ_TRIGGER_AXIS(15);
+ SDL_SendJoystickAxis(timestamp, joystick, SDL_GAMEPAD_AXIS_LEFT_TRIGGER, axis);
+ axis = READ_TRIGGER_AXIS(16);
+ SDL_SendJoystickAxis(timestamp, joystick, SDL_GAMEPAD_AXIS_RIGHT_TRIGGER, axis);
+ }
+#undef READ_TRIGGER_AXIS
+
+ if (ctx->sensors_enabled) {
+ Uint64 sensor_timestamp;
+ float values[3];
+
+ // Advance the imu sensor time stamp based on the observed rate of receipt of packets in the testcontroller app.
+ // This varies between Product ID and connection type.
+ sensor_timestamp = ctx->sensor_timestamp_ns;
+ ctx->sensor_timestamp_ns += ctx->sensor_timestamp_step_ns;
+
+ const float flGyroScale = ctx->gyroScale;
+ values[0] = HIDAPI_RemapVal((float)LOAD16(data[17], data[18]), INT16_MIN, INT16_MAX, -flGyroScale, flGyroScale);
+ values[1] = HIDAPI_RemapVal((float)LOAD16(data[21], data[22]), INT16_MIN, INT16_MAX, -flGyroScale, flGyroScale);
+ values[2] = HIDAPI_RemapVal(-(float)LOAD16(data[19], data[20]), INT16_MIN, INT16_MAX, -flGyroScale, flGyroScale);
+ SDL_SendJoystickSensor(timestamp, joystick, SDL_SENSOR_GYRO, sensor_timestamp, values, 3);
+
+ const float flAccelScale = ctx->accelScale;
+ values[0] = LOAD16(data[23], data[24]) * flAccelScale; // Acceleration along pitch axis
+ values[1] = LOAD16(data[27], data[28]) * flAccelScale; // Acceleration along yaw axis
+ values[2] = -LOAD16(data[25], data[26]) * flAccelScale; // Acceleration along roll axis
+ SDL_SendJoystickSensor(timestamp, joystick, SDL_SENSOR_ACCEL, sensor_timestamp, values, 3);
+ }
+
+ SDL_memcpy(ctx->last_state, data, SDL_min(size, sizeof(ctx->last_state)));
+}
+
+static void HIDAPI_DriverFlydigi_HandleStatusUpdate(SDL_HIDAPI_Device *device, Uint8 *data, int size)
+{
+ // The status changed, see if we can acquire the controller now
+ SDL_HIDAPI_Flydigi_SendStatusRequest(device);
+}
+
+static void HIDAPI_DriverFlydigi_HandlePacketV2(SDL_Joystick *joystick, SDL_DriverFlydigi_Context *ctx, Uint8 *data, int size)
+{
+ if (size > 0 && data[0] != 0x5A) {
+ // If first byte is not 0x5A, it must be REPORT_ID, we need to remove it.
+ ++data;
+ --size;
+ }
+ if (size < 31 || data[0] != FLYDIGI_V2_MAGIC1 || data[1] != FLYDIGI_V2_MAGIC2) {
+ // We don't know how to handle this report, ignore it
+ return;
+ }
+
+ switch (data[2]) {
+ case FLYDIGI_V2_GET_INFO_COMMAND:
+ if (joystick) {
+ HIDAPI_DriverFlydigi_HandleInfoResponse(joystick, ctx, data, size);
+ }
+ break;
+ case FLYDIGI_V2_SET_STATUS_COMMAND:
+ HIDAPI_DriverFlydigi_HandleStatusUpdate(ctx->device, data, size);
+ break;
+ case FLYDIGI_V2_GET_STATUS_COMMAND:
+ HIDAPI_DriverFlydigi_HandleStatusResponse(ctx->device, data, size);
+ break;
+ case FLYDIGI_V2_ACQUIRE_CONTROLLER_COMMAND:
+ HIDAPI_DriverFlydigi_HandleAcquireResponse(ctx->device, data, size);
+ break;
+ case FLYDIGI_V2_INPUT_REPORT:
+ if (joystick) {
+ HIDAPI_DriverFlydigi_HandleStatePacketV2(joystick, ctx, data, size);
+ }
+ break;
+ default:
+ // We don't recognize this command, ignore it
+ break;
+ }
+}
+
+static bool HIDAPI_DriverFlydigi_UpdateDevice(SDL_HIDAPI_Device *device)
+{
+ SDL_DriverFlydigi_Context *ctx = (SDL_DriverFlydigi_Context *)device->context;
+ SDL_Joystick *joystick = NULL;
+ Uint8 data[USB_PACKET_LENGTH];
+ int size = 0;
+ Uint64 now = SDL_GetTicks();
+
+ if (device->num_joysticks > 0) {
+ joystick = SDL_GetJoystickFromID(device->joysticks[0]);
+ }
+
+ if (device->vendor_id == USB_VENDOR_FLYDIGI_V2 && joystick) {
+ if (!ctx->next_heartbeat || now >= ctx->next_heartbeat) {
+ SDL_HIDAPI_Flydigi_SendAcquireRequest(device, true);
+ SDL_HIDAPI_Flydigi_SendInfoRequest(device);
+ ctx->next_heartbeat = now + FLYDIGI_ACQUIRE_CONTROLLER_HEARTBEAT_TIME;
+ }
+ }
+
+ while ((size = SDL_hid_read_timeout(device->dev, data, sizeof(data), 0)) > 0) {
+#ifdef DEBUG_FLYDIGI_PROTOCOL
+ HIDAPI_DumpPacket("Flydigi packet: size = %d", data, size);
+#endif
+ ctx->last_packet = now;
+
+ if (device->vendor_id == USB_VENDOR_FLYDIGI_V1) {
+ HIDAPI_DriverFlydigi_HandlePacketV1(joystick, ctx, data, size);
+ } else {
+ HIDAPI_DriverFlydigi_HandlePacketV2(joystick, ctx, data, size);
+ }
+ }
+
+ if (device->vendor_id == USB_VENDOR_FLYDIGI_V2) {
+ // If we haven't gotten a packet in a while, check to make sure we can still acquire it
+ const int INPUT_TIMEOUT_MS = 100;
+ if (now >= (ctx->last_packet + INPUT_TIMEOUT_MS)) {
+ ctx->next_heartbeat = now;
+ }
+ }
+
+ if (size < 0 && device->num_joysticks > 0) {
+ // Read error, device is disconnected
+ HIDAPI_JoystickDisconnected(device, device->joysticks[0]);
+ }
+ return (size >= 0);
+}
+
+static void HIDAPI_DriverFlydigi_CloseJoystick(SDL_HIDAPI_Device *device, SDL_Joystick *joystick)
+{
+ // Don't unacquire the controller, someone else might be using it too.
+ // The controller will automatically unacquire itself after a little while
+ //SDL_HIDAPI_Flydigi_SendAcquireRequest(device, false);
+}
+
+static void HIDAPI_DriverFlydigi_FreeDevice(SDL_HIDAPI_Device *device)
+{
+}
+
+SDL_HIDAPI_DeviceDriver SDL_HIDAPI_DriverFlydigi = {
+ SDL_HINT_JOYSTICK_HIDAPI_FLYDIGI,
+ true,
+ HIDAPI_DriverFlydigi_RegisterHints,
+ HIDAPI_DriverFlydigi_UnregisterHints,
+ HIDAPI_DriverFlydigi_IsEnabled,
+ HIDAPI_DriverFlydigi_IsSupportedDevice,
+ HIDAPI_DriverFlydigi_InitDevice,
+ HIDAPI_DriverFlydigi_GetDevicePlayerIndex,
+ HIDAPI_DriverFlydigi_SetDevicePlayerIndex,
+ HIDAPI_DriverFlydigi_UpdateDevice,
+ HIDAPI_DriverFlydigi_OpenJoystick,
+ HIDAPI_DriverFlydigi_RumbleJoystick,
+ HIDAPI_DriverFlydigi_RumbleJoystickTriggers,
+ HIDAPI_DriverFlydigi_GetJoystickCapabilities,
+ HIDAPI_DriverFlydigi_SetJoystickLED,
+ HIDAPI_DriverFlydigi_SendJoystickEffect,
+ HIDAPI_DriverFlydigi_SetJoystickSensorsEnabled,
+ HIDAPI_DriverFlydigi_CloseJoystick,
+ HIDAPI_DriverFlydigi_FreeDevice,
+};
+
+#endif // SDL_JOYSTICK_HIDAPI_FLYDIGI
+
+#endif // SDL_JOYSTICK_HIDAPI
diff --git a/thirdparty/sdl/joystick/hidapi/SDL_hidapi_flydigi.h b/thirdparty/sdl/joystick/hidapi/SDL_hidapi_flydigi.h
new file mode 100644
index 00000000000..cf60bed0f2d
--- /dev/null
+++ b/thirdparty/sdl/joystick/hidapi/SDL_hidapi_flydigi.h
@@ -0,0 +1,38 @@
+/*
+ Simple DirectMedia Layer
+ Copyright (C) 1997-2026 Sam Lantinga <[email protected]>
+
+ 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.
+*/
+
+// These are values used in the controller type byte of the controller GUID
+
+typedef enum
+{
+ SDL_FLYDIGI_UNKNOWN,
+ SDL_FLYDIGI_APEX2 = (1 << 0),
+ SDL_FLYDIGI_APEX3,
+ SDL_FLYDIGI_APEX4,
+ SDL_FLYDIGI_APEX5,
+ SDL_FLYDIGI_VADER2 = (1 << 4),
+ SDL_FLYDIGI_VADER2_PRO,
+ SDL_FLYDIGI_VADER3,
+ SDL_FLYDIGI_VADER3_PRO,
+ SDL_FLYDIGI_VADER4_PRO,
+ SDL_FLYDIGI_VADER5_PRO,
+} SDL_FlyDigiControllerType;
+
diff --git a/thirdparty/sdl/joystick/hidapi/SDL_hidapi_gamecube.c b/thirdparty/sdl/joystick/hidapi/SDL_hidapi_gamecube.c
index c03d92702eb..3b41e82334e 100644
--- a/thirdparty/sdl/joystick/hidapi/SDL_hidapi_gamecube.c
+++ b/thirdparty/sdl/joystick/hidapi/SDL_hidapi_gamecube.c
@@ -1,6 +1,6 @@
/*
Simple DirectMedia Layer
- Copyright (C) 1997-2025 Sam Lantinga <[email protected]>
+ Copyright (C) 1997-2026 Sam Lantinga <[email protected]>
This software is provided 'as-is', without any express or implied
warranty. In no event will the authors be held liable for any damages
@@ -23,6 +23,7 @@
#ifdef SDL_JOYSTICK_HIDAPI
#include "../../SDL_hints_c.h"
+#include "../../misc/SDL_libusb.h"
#include "../SDL_sysjoystick.h"
#include "SDL_hidapijoystick_c.h"
#include "SDL_hidapi_rumble.h"
@@ -36,6 +37,7 @@
#endif
#define MAX_CONTROLLERS 4
+#define PC_RUMBLE_REFRESH 16
typedef struct
{
@@ -49,6 +51,8 @@ typedef struct
// Without this variable, hid_write starts to lag a TON
bool rumbleUpdate;
bool useRumbleBrake;
+ bool rumbleActive;
+ Uint64 pc_rumble_sent;
} SDL_DriverGameCube_Context;
static void HIDAPI_DriverGameCube_RegisterHints(SDL_HintCallback callback, void *userdata)
@@ -76,7 +80,8 @@ static bool HIDAPI_DriverGameCube_IsSupportedDevice(SDL_HIDAPI_Device *device, c
}
if (vendor_id == USB_VENDOR_DRAGONRISE &&
(product_id == USB_PRODUCT_EVORETRO_GAMECUBE_ADAPTER1 ||
- product_id == USB_PRODUCT_EVORETRO_GAMECUBE_ADAPTER2)) {
+ product_id == USB_PRODUCT_EVORETRO_GAMECUBE_ADAPTER2 ||
+ product_id == USB_PRODUCT_EVORETRO_GAMECUBE_ADAPTER3)) {
// EVORETRO GameCube Controller Adapter
return true;
}
@@ -101,6 +106,83 @@ static void SDLCALL SDL_JoystickGameCubeRumbleBrakeHintChanged(void *userdata, c
}
}
+static bool HIDAPI_DriverGameCube_EnableAdapter(SDL_HIDAPI_Device *device)
+{
+#ifdef HAVE_LIBUSB
+ // Need to close the device while sending USB commands to it
+ SDL_hid_close(device->dev);
+
+ // This is needed to enable input for Nyko and EVORETRO GameCube adapters
+ SDL_LibUSBContext *libusb_ctx;
+ if (SDL_InitLibUSB(&libusb_ctx)) {
+ libusb_context *context = NULL;
+ libusb_device **devs = NULL;
+ libusb_device_handle *handle = NULL;
+ struct libusb_device_descriptor desc;
+ ssize_t i, num_devs;
+ bool kernel_detached = false;
+
+ if (libusb_ctx->init(&context) == 0) {
+ num_devs = libusb_ctx->get_device_list(context, &devs);
+ for (i = 0; i < num_devs; ++i) {
+ if (libusb_ctx->get_device_descriptor(devs[i], &desc) != 0) {
+ continue;
+ }
+
+ if (desc.idVendor != USB_VENDOR_NINTENDO ||
+ desc.idProduct != USB_PRODUCT_NINTENDO_GAMECUBE_ADAPTER) {
+ continue;
+ }
+
+ if (libusb_ctx->open(devs[i], &handle) != 0) {
+ continue;
+ }
+
+ if (libusb_ctx->kernel_driver_active(handle, 0)) {
+ if (libusb_ctx->detach_kernel_driver(handle, 0) == 0) {
+ kernel_detached = true;
+ }
+ }
+
+ if (libusb_ctx->claim_interface(handle, 0) == 0) {
+ libusb_ctx->control_transfer(handle, 0x21, 11, 0x0001, 0, NULL, 0, 1000);
+ libusb_ctx->release_interface(handle, 0);
+ }
+
+ if (kernel_detached) {
+ libusb_ctx->attach_kernel_driver(handle, 0);
+ }
+
+ libusb_ctx->close(handle);
+ }
+
+ libusb_ctx->free_device_list(devs, 1);
+
+ libusb_ctx->exit(context);
+ }
+ SDL_QuitLibUSB();
+ }
+
+ // Reopen the device now that we're done
+ device->dev = SDL_hid_open_path(device->path);
+ if (!device->dev) {
+ return false;
+ }
+#endif // HAVE_LIBUSB
+
+ Uint8 initMagic = 0x13;
+ if (SDL_hid_write(device->dev, &initMagic, sizeof(initMagic)) != sizeof(initMagic)) {
+ SDL_LogDebug(SDL_LOG_CATEGORY_INPUT,
+ "HIDAPI_DriverGameCube_InitDevice(): Couldn't initialize WUP-028");
+ return false;
+ }
+
+ // Wait for the adapter to initialize
+ SDL_Delay(10);
+
+ return true;
+}
+
static bool HIDAPI_DriverGameCube_InitDevice(SDL_HIDAPI_Device *device)
{
SDL_DriverGameCube_Context *ctx;
@@ -108,13 +190,8 @@ static bool HIDAPI_DriverGameCube_InitDevice(SDL_HIDAPI_Device *device)
Uint8 *curSlot;
Uint8 i;
int size;
- Uint8 initMagic = 0x13;
Uint8 rumbleMagic = 0x11;
-#ifdef HAVE_ENABLE_GAMECUBE_ADAPTORS
- SDL_EnableGameCubeAdaptors();
-#endif
-
ctx = (SDL_DriverGameCube_Context *)SDL_calloc(1, sizeof(*ctx));
if (!ctx) {
return false;
@@ -128,19 +205,35 @@ static bool HIDAPI_DriverGameCube_InitDevice(SDL_HIDAPI_Device *device)
}
if (ctx->pc_mode) {
+ // Check to see if this firmware supports rumble
+ bool rumbleAllowed = false;
+ if ((size = SDL_hid_read_timeout(device->dev, packet, sizeof(packet), 0)) > 0) {
+#ifdef DEBUG_GAMECUBE_PROTOCOL
+ HIDAPI_DumpPacket("Nintendo GameCube packet: size = %d", packet, size);
+#endif
+ if (size == 9) {
+ // This is firmware version 0x7 or newer
+ // Rumble is supported if the second USB cable is plugged in
+ rumbleAllowed = true;
+ }
+ }
+#ifdef SDL_PLATFORM_WIN32
+ // We get a separate device for each slot
+ ctx->rumbleAllowed[0] = rumbleAllowed;
ResetAxisRange(ctx, 0);
HIDAPI_JoystickConnected(device, &ctx->joysticks[0]);
+#else
+ for (i = 0; i < MAX_CONTROLLERS; ++i) {
+ ctx->rumbleAllowed[i] = rumbleAllowed;
+ ResetAxisRange(ctx, i);
+ HIDAPI_JoystickConnected(device, &ctx->joysticks[i]);
+ }
+#endif
} else {
- // This is all that's needed to initialize the device. Really!
- if (SDL_hid_write(device->dev, &initMagic, sizeof(initMagic)) != sizeof(initMagic)) {
- SDL_LogDebug(SDL_LOG_CATEGORY_INPUT,
- "HIDAPI_DriverGameCube_InitDevice(): Couldn't initialize WUP-028");
+ if (!HIDAPI_DriverGameCube_EnableAdapter(device)) {
return false;
}
- // Wait for the adapter to initialize
- SDL_Delay(10);
-
// Add all the applicable joysticks
while ((size = SDL_hid_read_timeout(device->dev, packet, sizeof(packet), 0)) > 0) {
#ifdef DEBUG_GAMECUBE_PROTOCOL
@@ -199,14 +292,25 @@ static void HIDAPI_DriverGameCube_SetDevicePlayerIndex(SDL_HIDAPI_Device *device
{
}
-static void HIDAPI_DriverGameCube_HandleJoystickPacket(SDL_HIDAPI_Device *device, SDL_DriverGameCube_Context *ctx, const Uint8 *packet, bool invert_c_stick)
+static void HIDAPI_DriverGameCube_HandleJoystickPacket(SDL_HIDAPI_Device *device, SDL_DriverGameCube_Context *ctx, Uint8 slot, const Uint8 *packet, bool invert_c_stick)
{
SDL_Joystick *joystick;
- const Uint8 i = 0; // We have a separate context for each connected controller in PC mode, just use the first index
+ Uint8 i;
Uint8 v;
Sint16 axis_value;
Uint64 timestamp = SDL_GetTicksNS();
+#ifdef SDL_PLATFORM_WIN32
+ // We get a separate device for each slot
+ i = 0;
+#else
+ i = slot;
+ if (i >= MAX_CONTROLLERS) {
+ // Invalid packet?
+ return;
+ }
+#endif
+
joystick = SDL_GetJoystickFromID(ctx->joysticks[i]);
if (!joystick) {
// Hasn't been opened yet, skip
@@ -340,6 +444,14 @@ static void HIDAPI_DriverGameCube_HandleNintendoPacket(SDL_HIDAPI_Device *device
}
}
+static void HIDAPI_DriverGameCube_SendPCRumble(SDL_HIDAPI_Device *device, SDL_DriverGameCube_Context *ctx)
+{
+ Uint8 rumblepkt[3] = { 0x00, 0x00, 0x00 };
+ rumblepkt[1] = rumblepkt[2] = ctx->rumbleActive ? 0xFF : 0x00;
+ SDL_HIDAPI_SendRumble(device, rumblepkt, sizeof(rumblepkt));
+ ctx->pc_rumble_sent = SDL_GetTicks();
+}
+
static bool HIDAPI_DriverGameCube_UpdateDevice(SDL_HIDAPI_Device *device)
{
SDL_DriverGameCube_Context *ctx = (SDL_DriverGameCube_Context *)device->context;
@@ -356,11 +468,11 @@ static bool HIDAPI_DriverGameCube_UpdateDevice(SDL_HIDAPI_Device *device)
// This is the older firmware
// The first byte is the index of the connected controller
// The C stick has an inverted value range compared to the left stick
- HIDAPI_DriverGameCube_HandleJoystickPacket(device, ctx, &packet[1], true);
+ HIDAPI_DriverGameCube_HandleJoystickPacket(device, ctx, packet[0] - 1, &packet[1], true);
} else if (size == 9) {
// This is the newer firmware (version 0x7)
// The C stick has the same value range compared to the left stick
- HIDAPI_DriverGameCube_HandleJoystickPacket(device, ctx, packet, false);
+ HIDAPI_DriverGameCube_HandleJoystickPacket(device, ctx, 0, packet, false);
} else {
// How do we handle this packet?
}
@@ -369,6 +481,11 @@ static bool HIDAPI_DriverGameCube_UpdateDevice(SDL_HIDAPI_Device *device)
}
}
+ // PC_Mode rumble needs constant packets in order to keep rumble going
+ if (ctx->pc_mode && ctx->rumbleActive && SDL_GetTicks() >= (ctx->pc_rumble_sent + PC_RUMBLE_REFRESH)) {
+ HIDAPI_DriverGameCube_SendPCRumble(device, ctx);
+ }
+
// Write rumble packet
if (ctx->rumbleUpdate) {
SDL_HIDAPI_SendRumble(device, ctx->rumble, sizeof(ctx->rumble));
@@ -409,33 +526,51 @@ static bool HIDAPI_DriverGameCube_RumbleJoystick(SDL_HIDAPI_Device *device, SDL_
SDL_AssertJoysticksLocked();
if (ctx->pc_mode) {
- return SDL_Unsupported();
- }
-
- for (i = 0; i < MAX_CONTROLLERS; i += 1) {
- if (joystick->instance_id == ctx->joysticks[i]) {
- if (ctx->wireless[i]) {
- return SDL_SetError("Nintendo GameCube WaveBird controllers do not support rumble");
- }
- if (!ctx->rumbleAllowed[i]) {
- return SDL_SetError("Second USB cable for WUP-028 not connected");
+ for (i = 0; i < MAX_CONTROLLERS; i += 1) {
+ if (joystick->instance_id == ctx->joysticks[i]) {
+ if (!ctx->rumbleAllowed[i]) {
+ return SDL_SetError("Rumble is disabled because the adapter is not at least of firmware 0x7");
+ }
+ bool shouldrumble = false, coast = false;
+ if (ctx->useRumbleBrake) {
+ coast = (low_frequency_rumble == 0 && high_frequency_rumble > 0);
+ }
+ shouldrumble = (low_frequency_rumble > 0 || high_frequency_rumble > 0);
+ if (coast) {
+ ctx->rumbleActive = false;
+ } else if (shouldrumble != ctx->rumbleActive) {
+ ctx->rumbleActive = shouldrumble;
+ HIDAPI_DriverGameCube_SendPCRumble(device, ctx);
+ }
+ return true;
}
- if (ctx->useRumbleBrake) {
- if (low_frequency_rumble == 0 && high_frequency_rumble > 0) {
- val = 0; // if only low is 0 we want to do a regular stop
- } else if (low_frequency_rumble == 0 && high_frequency_rumble == 0) {
- val = 2; // if both frequencies are 0 we want to do a hard stop
+ }
+ } else {
+ for (i = 0; i < MAX_CONTROLLERS; i += 1) {
+ if (joystick->instance_id == ctx->joysticks[i]) {
+ if (ctx->wireless[i]) {
+ return SDL_SetError("Nintendo GameCube WaveBird controllers do not support rumble");
+ }
+ if (!ctx->rumbleAllowed[i]) {
+ return SDL_SetError("Second USB cable for WUP-028 not connected");
+ }
+ if (ctx->useRumbleBrake) {
+ if (low_frequency_rumble == 0 && high_frequency_rumble > 0) {
+ val = 0; // if only low is 0 we want to do a regular stop
+ } else if (low_frequency_rumble == 0 && high_frequency_rumble == 0) {
+ val = 2; // if both frequencies are 0 we want to do a hard stop
+ } else {
+ val = 1; // normal rumble
+ }
} else {
- val = 1; // normal rumble
+ val = (low_frequency_rumble > 0 || high_frequency_rumble > 0);
}
- } else {
- val = (low_frequency_rumble > 0 || high_frequency_rumble > 0);
- }
- if (val != ctx->rumble[i + 1]) {
- ctx->rumble[i + 1] = val;
- ctx->rumbleUpdate = true;
+ if (val != ctx->rumble[i + 1]) {
+ ctx->rumble[i + 1] = val;
+ ctx->rumbleUpdate = true;
+ }
+ return true;
}
- return true;
}
}
@@ -454,10 +589,17 @@ static Uint32 HIDAPI_DriverGameCube_GetJoystickCapabilities(SDL_HIDAPI_Device *d
Uint32 result = 0;
SDL_AssertJoysticksLocked();
-
- if (!ctx->pc_mode) {
- Uint8 i;
-
+ Uint8 i;
+ if (ctx->pc_mode) {
+ for (i = 0; i < MAX_CONTROLLERS; i += 1) {
+ if (joystick->instance_id == ctx->joysticks[i]) {
+ if (ctx->rumbleAllowed[i]) {
+ result |= SDL_JOYSTICK_CAP_RUMBLE;
+ break;
+ }
+ }
+ }
+ } else {
for (i = 0; i < MAX_CONTROLLERS; i += 1) {
if (joystick->instance_id == ctx->joysticks[i]) {
if (!ctx->wireless[i] && ctx->rumbleAllowed[i]) {
@@ -495,6 +637,11 @@ static void HIDAPI_DriverGameCube_CloseJoystick(SDL_HIDAPI_Device *device, SDL_J
SDL_HIDAPI_SendRumble(device, ctx->rumble, sizeof(ctx->rumble));
ctx->rumbleUpdate = false;
}
+
+ if (ctx->pc_mode && ctx->rumbleActive) {
+ ctx->rumbleActive = false;
+ HIDAPI_DriverGameCube_SendPCRumble(device, ctx);
+ }
}
static void HIDAPI_DriverGameCube_FreeDevice(SDL_HIDAPI_Device *device)
diff --git a/thirdparty/sdl/joystick/hidapi/SDL_hidapi_gip.c b/thirdparty/sdl/joystick/hidapi/SDL_hidapi_gip.c
new file mode 100644
index 00000000000..e9da9e21c73
--- /dev/null
+++ b/thirdparty/sdl/joystick/hidapi/SDL_hidapi_gip.c
@@ -0,0 +1,3105 @@
+/*
+ Simple DirectMedia Layer
+ Copyright (C) 1997-2026 Sam Lantinga <[email protected]>
+
+ 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"
+
+#ifdef SDL_JOYSTICK_HIDAPI
+
+// #include "../../events/SDL_keyboard_c.h"
+#include "../SDL_sysjoystick.h"
+#include "SDL_hidapijoystick_c.h"
+#include "SDL_hidapi_rumble.h"
+
+#ifdef SDL_JOYSTICK_HIDAPI_GIP
+
+// This driver is based on the Microsoft GIP spec at:
+// https://aka.ms/gipdocs
+// https://learn.microsoft.com/en-us/openspecs/windows_protocols/ms-gipusb/e7c90904-5e21-426e-b9ad-d82adeee0dbc
+
+// Define this if you want to log all packets from the controller
+#if 0
+#define DEBUG_XBOX_PROTOCOL
+#endif
+
+#define MAX_MESSAGE_LENGTH 0x4000
+#define MAX_ATTACHMENTS 8
+
+#define GIP_DATA_CLASS_COMMAND (0u << 5)
+#define GIP_DATA_CLASS_LOW_LATENCY (1u << 5)
+#define GIP_DATA_CLASS_STANDARD_LATENCY (2u << 5)
+#define GIP_DATA_CLASS_AUDIO (3u << 5)
+
+#define GIP_DATA_CLASS_SHIFT 5
+#define GIP_DATA_CLASS_MASK (7u << 5)
+
+/* System messages */
+#define GIP_CMD_PROTO_CONTROL 0x01
+#define GIP_CMD_HELLO_DEVICE 0x02
+#define GIP_CMD_STATUS_DEVICE 0x03
+#define GIP_CMD_METADATA 0x04
+#define GIP_CMD_SET_DEVICE_STATE 0x05
+#define GIP_CMD_SECURITY 0x06
+#define GIP_CMD_GUIDE_BUTTON 0x07
+#define GIP_CMD_AUDIO_CONTROL 0x08
+#define GIP_CMD_LED 0x0a
+#define GIP_CMD_HID_REPORT 0x0b
+#define GIP_CMD_FIRMWARE 0x0c
+#define GIP_CMD_EXTENDED 0x1e
+#define GIP_CMD_DEBUG 0x1f
+#define GIP_AUDIO_DATA 0x60
+
+/* Navigation vendor messages */
+#define GIP_CMD_DIRECT_MOTOR 0x09
+#define GIP_LL_INPUT_REPORT 0x20
+#define GIP_LL_OVERFLOW_INPUT_REPORT 0x26
+
+/* Wheel and ArcadeStick vendor messages */
+#define GIP_CMD_INITIAL_REPORTS_REQUEST 0x0a
+#define GIP_LL_STATIC_CONFIGURATION 0x21
+#define GIP_LL_BUTTON_INFO_REPORT 0x22
+
+/* Wheel vendor messages */
+#define GIP_CMD_SET_APPLICATION_MEMORY 0x0b
+#define GIP_CMD_SET_EQUATIONS_STATES 0x0c
+#define GIP_CMD_SET_EQUATION 0x0d
+
+/* FlightStick vendor messages */
+#define GIP_CMD_DEVICE_CAPABILITIES 0x00
+#define GIP_CMD_LED_CAPABILITIES 0x01
+#define GIP_CMD_SET_LED_STATE 0x02
+
+/* Undocumented Elite 2 vendor messages */
+#define GIP_CMD_RAW_REPORT 0x0c
+#define GIP_CMD_GUIDE_COLOR 0x0e
+#define GIP_SL_ELITE_CONFIG 0x4d
+
+#define GIP_BTN_OFFSET_XBE1 28
+#define GIP_BTN_OFFSET_XBE2 14
+
+#define GIP_FLAG_FRAGMENT (1u << 7)
+#define GIP_FLAG_INIT_FRAG (1u << 6)
+#define GIP_FLAG_SYSTEM (1u << 5)
+#define GIP_FLAG_ACME (1u << 4)
+#define GIP_FLAG_ATTACHMENT_MASK 0x7
+
+#define GIP_AUDIO_FORMAT_NULL 0
+#define GIP_AUDIO_FORMAT_8000HZ_1CH 1
+#define GIP_AUDIO_FORMAT_8000HZ_2CH 2
+#define GIP_AUDIO_FORMAT_12000HZ_1CH 3
+#define GIP_AUDIO_FORMAT_12000HZ_2CH 4
+#define GIP_AUDIO_FORMAT_16000HZ_1CH 5
+#define GIP_AUDIO_FORMAT_16000HZ_2CH 6
+#define GIP_AUDIO_FORMAT_20000HZ_1CH 7
+#define GIP_AUDIO_FORMAT_20000HZ_2CH 8
+#define GIP_AUDIO_FORMAT_24000HZ_1CH 9
+#define GIP_AUDIO_FORMAT_24000HZ_2CH 10
+#define GIP_AUDIO_FORMAT_32000HZ_1CH 11
+#define GIP_AUDIO_FORMAT_32000HZ_2CH 12
+#define GIP_AUDIO_FORMAT_40000HZ_1CH 13
+#define GIP_AUDIO_FORMAT_40000HZ_2CH 14
+#define GIP_AUDIO_FORMAT_48000HZ_1CH 15
+#define GIP_AUDIO_FORMAT_48000HZ_2CH 16
+#define GIP_AUDIO_FORMAT_48000HZ_6CH 32
+#define GIP_AUDIO_FORMAT_48000HZ_8CH 33
+
+/* Protocol Control constants */
+#define GIP_CONTROL_CODE_ACK 0
+#define GIP_CONTROL_CODE_NACK 1 /* obsolete */
+#define GIP_CONTROL_CODE_UNK 2 /* obsolete */
+#define GIP_CONTROL_CODE_AB 3 /* obsolete */
+#define GIP_CONTROL_CODE_MPER 4 /* obsolete */
+#define GIP_CONTROL_CODE_STOP 5 /* obsolete */
+#define GIP_CONTROL_CODE_START 6 /* obsolete */
+#define GIP_CONTROL_CODE_ERR 7 /* obsolete */
+
+/* Status Device constants */
+#define GIP_POWER_LEVEL_OFF 0
+#define GIP_POWER_LEVEL_STANDBY 1 /* obsolete */
+#define GIP_POWER_LEVEL_FULL 2
+
+#define GIP_NOT_CHARGING 0
+#define GIP_CHARGING 1
+#define GIP_CHARGE_ERROR 2
+
+#define GIP_BATTERY_ABSENT 0
+#define GIP_BATTERY_STANDARD 1
+#define GIP_BATTERY_RECHARGEABLE 2
+
+#define GIP_BATTERY_CRITICAL 0
+#define GIP_BATTERY_LOW 1
+#define GIP_BATTERY_MEDIUM 2
+#define GIP_BATTERY_FULL 3
+
+#define GIP_EVENT_FAULT 0x0002
+
+#define GIP_FAULT_UNKNOWN 0
+#define GIP_FAULT_HARD 1
+#define GIP_FAULT_NMI 2
+#define GIP_FAULT_SVC 3
+#define GIP_FAULT_PEND_SV 4
+#define GIP_FAULT_SMART_PTR 5
+#define GIP_FAULT_MCU 6
+#define GIP_FAULT_BUS 7
+#define GIP_FAULT_USAGE 8
+#define GIP_FAULT_RADIO_HANG 9
+#define GIP_FAULT_WATCHDOG 10
+#define GIP_FAULT_LINK_STALL 11
+#define GIP_FAULT_ASSERTION 12
+
+/* Metadata constants */
+#define GIP_MESSAGE_FLAG_BIG_ENDIAN (1u << 0)
+#define GIP_MESSAGE_FLAG_RELIABLE (1u << 1)
+#define GIP_MESSAGE_FLAG_SEQUENCED (1u << 2)
+#define GIP_MESSAGE_FLAG_DOWNSTREAM (1u << 3)
+#define GIP_MESSAGE_FLAG_UPSTREAM (1u << 4)
+#define GIP_MESSAGE_FLAG_DS_REQUEST_RESPONSE (1u << 5)
+
+#define GIP_DATA_TYPE_CUSTOM 1
+#define GIP_DATA_TYPE_AUDIO 2
+#define GIP_DATA_TYPE_SECURITY 3
+#define GIP_DATA_TYPE_GIP 4
+
+/* Set Device State constants */
+#define GIP_STATE_START 0
+#define GIP_STATE_STOP 1
+#define GIP_STATE_STANDBY 2 /* obsolete */
+#define GIP_STATE_FULL_POWER 3
+#define GIP_STATE_OFF 4
+#define GIP_STATE_QUIESCE 5
+#define GIP_STATE_UNK6 6
+#define GIP_STATE_RESET 7
+
+/* Guide Button Status constants */
+#define GIP_LED_GUIDE 0
+#define GIP_LID_IR 1 /* deprecated */
+
+#define GIP_LED_GUIDE_OFF 0
+#define GIP_LED_GUIDE_ON 1
+#define GIP_LED_GUIDE_FAST_BLINK 2
+#define GIP_LED_GUIDE_SLOW_BLINK 3
+#define GIP_LED_GUIDE_CHARGING_BLINK 4
+#define GIP_LED_GUIDE_RAMP_TO_LEVEL 0xd
+
+#define GIP_LED_IR_OFF 0
+#define GIP_LED_IR_ON_100MS 1
+#define GIP_LED_IR_PATTERN 4
+
+/* Direct Motor Command constants */
+#define GIP_MOTOR_RIGHT_VIBRATION (1u << 0)
+#define GIP_MOTOR_LEFT_VIBRATION (1u << 1)
+#define GIP_MOTOR_RIGHT_IMPULSE (1u << 2)
+#define GIP_MOTOR_LEFT_IMPULSE (1u << 3)
+#define GIP_MOTOR_ALL 0xF
+
+/* Extended Command constants */
+#define GIP_EXTCMD_GET_CAPABILITIES 0x00
+#define GIP_EXTCMD_GET_TELEMETRY_DATA 0x01
+#define GIP_EXTCMD_GET_SERIAL_NUMBER 0x04
+
+#define GIP_EXTENDED_STATUS_OK 0
+#define GIP_EXTENDED_STATUS_NOT_SUPPORTED 1
+#define GIP_EXTENDED_STATUS_NOT_READY 2
+#define GIP_EXTENDED_STATUS_ACCESS_DENIED 3
+#define GIP_EXTENDED_STATUS_FAILED 4
+
+/* Internal constants, not part of protocol */
+#define GIP_HELLO_TIMEOUT 2000
+#define GIP_ACME_TIMEOUT 10
+
+#define GIP_DEFAULT_IN_SYSTEM_MESSAGES 0x5e
+#define GIP_DEFAULT_OUT_SYSTEM_MESSAGES 0x472
+
+#define GIP_FEATURE_CONSOLE_FUNCTION_MAP (1u << 0)
+#define GIP_FEATURE_CONSOLE_FUNCTION_MAP_OVERFLOW (1u << 1)
+#define GIP_FEATURE_ELITE_BUTTONS (1u << 2)
+#define GIP_FEATURE_DYNAMIC_LATENCY_INPUT (1u << 3)
+#define GIP_FEATURE_SECURITY_OPT_OUT (1u << 4)
+#define GIP_FEATURE_MOTOR_CONTROL (1u << 5)
+#define GIP_FEATURE_GUIDE_COLOR (1u << 6)
+#define GIP_FEATURE_EXTENDED_SET_DEVICE_STATE (1u << 7)
+
+#define GIP_QUIRK_NO_HELLO (1u << 0)
+#define GIP_QUIRK_BROKEN_METADATA (1u << 1)
+#define GIP_QUIRK_NO_IMPULSE_VIBRATION (1u << 2)
+
+typedef enum
+{
+ GIP_METADATA_NONE = 0,
+ GIP_METADATA_GOT = 1,
+ GIP_METADATA_FAKED = 2,
+ GIP_METADATA_PENDING = 3,
+} GIP_MetadataStatus;
+
+#ifndef VK_LWIN
+#define VK_LWIN 0x5b
+#endif
+
+typedef enum
+{
+ GIP_TYPE_UNKNOWN = -1,
+ GIP_TYPE_GAMEPAD = 0,
+ GIP_TYPE_ARCADE_STICK = 1,
+ GIP_TYPE_WHEEL = 2,
+ GIP_TYPE_FLIGHT_STICK = 3,
+ GIP_TYPE_NAVIGATION_CONTROLLER = 4,
+ GIP_TYPE_CHATPAD = 5,
+ GIP_TYPE_HEADSET = 6,
+ GIP_TYPE_GUITAR = 7,
+ GIP_TYPE_DRUM_KIT = 8,
+ GIP_TYPE_LIVE_GUITAR = 9,
+} GIP_AttachmentType;
+
+typedef enum
+{
+ GIP_RUMBLE_STATE_IDLE,
+ GIP_RUMBLE_STATE_QUEUED,
+ GIP_RUMBLE_STATE_BUSY,
+} GIP_RumbleState;
+
+typedef enum
+{
+ GIP_BTN_FMT_UNKNOWN,
+ GIP_BTN_FMT_XBE1,
+ GIP_BTN_FMT_XBE2_RAW,
+ GIP_BTN_FMT_XBE2_4,
+ GIP_BTN_FMT_XBE2_5,
+} GIP_EliteButtonFormat;
+
+/* These come across the wire as little-endian, so let's store them in-memory as such so we can memcmp */
+#define MAKE_GUID(NAME, A, B, C, D0, D1, D2, D3, D4, D5, D6, D7) \
+ static const GUID NAME = { SDL_Swap32LE(A), SDL_Swap16LE(B), SDL_Swap16LE(C), { D0, D1, D2, D3, D4, D5, D6, D7 } }
+
+typedef struct GUID
+{
+ Uint32 a;
+ Uint16 b;
+ Uint16 c;
+ Uint8 d[8];
+} GUID;
+SDL_COMPILE_TIME_ASSERT(GUID, sizeof(GUID) == 16);
+
+MAKE_GUID(GUID_ArcadeStick, 0x332054cc, 0xa34b, 0x41d5, 0xa3, 0x4a, 0xa6, 0xa6, 0x71, 0x1e, 0xc4, 0xb3);
+MAKE_GUID(GUID_DynamicLatencyInput, 0x87f2e56b, 0xc3bb, 0x49b1, 0x82, 0x65, 0xff, 0xff, 0xf3, 0x77, 0x99, 0xee);
+MAKE_GUID(GUID_FlightStick, 0x03f1a011, 0xefe9, 0x4cc1, 0x96, 0x9c, 0x38, 0xdc, 0x55, 0xf4, 0x04, 0xd0);
+MAKE_GUID(GUID_IHeadset, 0xbc25d1a3, 0xc24e, 0x4992, 0x9d, 0xda, 0xef, 0x4f, 0x12, 0x3e, 0xf5, 0xdc);
+MAKE_GUID(GUID_IConsoleFunctionMap_InputReport, 0xecddd2fe, 0xd387, 0x4294, 0xbd, 0x96, 0x1a, 0x71, 0x2e, 0x3d, 0xc7, 0x7d);
+MAKE_GUID(GUID_IConsoleFunctionMap_OverflowInputReport, 0x137d4bd0, 0x9347, 0x4472, 0xaa, 0x26, 0x8c, 0x34, 0xa0, 0x8f, 0xf9, 0xbd);
+MAKE_GUID(GUID_IController, 0x9776ff56, 0x9bfd, 0x4581, 0xad, 0x45, 0xb6, 0x45, 0xbb, 0xa5, 0x26, 0xd6);
+MAKE_GUID(GUID_IDevAuthPCOptOut, 0x7a34ce77, 0x7de2, 0x45c6, 0x8c, 0xa4, 0x00, 0x42, 0xc0, 0x8b, 0xd9, 0x4a);
+MAKE_GUID(GUID_IEliteButtons, 0x37d19ff7, 0xb5c6, 0x49d1, 0xa7, 0x5e, 0x03, 0xb2, 0x4b, 0xef, 0x8c, 0x89);
+MAKE_GUID(GUID_IGamepad, 0x082e402c, 0x07df, 0x45e1, 0xa5, 0xab, 0xa3, 0x12, 0x7a, 0xf1, 0x97, 0xb5);
+MAKE_GUID(GUID_NavigationController, 0xb8f31fe7, 0x7386, 0x40e9, 0xa9, 0xf8, 0x2f, 0x21, 0x26, 0x3a, 0xcf, 0xb7);
+MAKE_GUID(GUID_Wheel, 0x646979cf, 0x6b71, 0x4e96, 0x8d, 0xf9, 0x59, 0xe3, 0x98, 0xd7, 0x42, 0x0c);
+MAKE_GUID(GUID_PDP_Guitar, 0x1a266af6, 0x3a46, 0x45e3, 0xb9, 0xb6, 0x0f, 0x2c, 0x0b, 0x2c, 0x1e, 0xbe);
+MAKE_GUID(GUID_Madcatz_Guitar, 0x0d2ae438, 0x7f7d, 0x4933, 0x86, 0x93, 0x30, 0xfc, 0x55, 0x01, 0x8e, 0x77);
+MAKE_GUID(GUID_PDP_DrumKit, 0xa503f9b0, 0x955e, 0x47c4, 0xa2, 0xed, 0xb1, 0x33, 0x6f, 0xa7, 0x70, 0x3e);
+MAKE_GUID(GUID_Madcatz_DrumKit, 0x06182893, 0xCCE0, 0x4B85, 0x92, 0x71, 0x0A, 0x10, 0xDB, 0xAB, 0x7E, 0x07);
+MAKE_GUID(GUID_GuitarHero_Live_Guitar, 0xfd12fdd9, 0x8e73, 0x47c7, 0xa2, 0x31, 0x96, 0x26, 0x8c, 0x38, 0x00, 0x9a);
+
+/*
+ * The following GUIDs are observed, but the exact meanings aren't known, so
+ * for now we document them but don't use them anywhere.
+ *
+ * MAKE_GUID(GUID_GamepadEmu, 0xe2e5f1bc, 0xa6e6, 0x41a2, 0x8f, 0x43, 0x33, 0xcf, 0xa2, 0x51, 0x09, 0x81);
+ * MAKE_GUID(GUID_IAudioOnly, 0x92844cd1, 0xf7c8, 0x49ef, 0x97, 0x77, 0x46, 0x7d, 0xa7, 0x08, 0xad, 0x10);
+ * MAKE_GUID(GUID_IControllerProfileModeState, 0xf758dc66, 0x022c, 0x48b8, 0xa4, 0xf6, 0x45, 0x7b, 0xa8, 0x0e, 0x2a, 0x5b);
+ * MAKE_GUID(GUID_ICustomAudio, 0x63fd9cc9, 0x94ee, 0x4b5d, 0x9c, 0x4d, 0x8b, 0x86, 0x4c, 0x14, 0x9c, 0xac);
+ * MAKE_GUID(GUID_IExtendedDeviceFlags, 0x34ad9b1e, 0x36ad, 0x4fb5, 0x8a, 0xc7, 0x17, 0x23, 0x4c, 0x9f, 0x54, 0x6f);
+ * MAKE_GUID(GUID_IProgrammableGamepad, 0x31c1034d, 0xb5b7, 0x4551, 0x98, 0x13, 0x87, 0x69, 0xd4, 0xa0, 0xe4, 0xf9);
+ * MAKE_GUID(GUID_IVirtualDevice, 0xdfd26825, 0x110a, 0x4e94, 0xb9, 0x37, 0xb2, 0x7c, 0xe4, 0x7b, 0x25, 0x40);
+ * MAKE_GUID(GUID_OnlineDevAuth, 0x632b1fd1, 0xa3e9, 0x44f9, 0x84, 0x20, 0x5c, 0xe3, 0x44, 0xa0, 0x64, 0x04);
+ *
+ * Seen on Elite Controller, Adaptive Controller: 9ebd00a3-b5e6-4c08-a33b-673126459ec4
+ * Seen on Adaptive Controller: ce1e58c5-221c-4bdb-9c24-bf3941601320
+ * Seen on Elite 2 Controller: f758dc66-022c-48b8-a4f6-457ba80e2a5b (IControllerProfileModeState)
+ * Seen on Elite 2 Controller: 31c1034d-b5b7-4551-9813-8769d4a0e4f9 (IProgrammableGamepad)
+ * Seen on Elite 2 Controller: 34ad9b1e-36ad-4fb5-8ac7-17234c9f546f (IExtendedDeviceFlags)
+ * Seen on Elite 2 Controller: 88e0b694-6bd9-4416-a560-e7fafdfa528f
+ * Seen on Elite 2 Controller: ea96c8c0-b216-448b-be80-7e5deb0698e2
+ */
+
+static const int GIP_DataClassMtu[8] = { 64, 64, 64, 2048, 0, 0, 0, 0 };
+
+typedef struct GIP_Quirks
+{
+ Uint16 vendor_id;
+ Uint16 product_id;
+ Uint8 attachment_index;
+ Uint32 added_features;
+ Uint32 filtered_features;
+ Uint32 quirks;
+ Uint32 extra_in_system[8];
+ Uint32 extra_out_system[8];
+ GIP_AttachmentType device_type;
+ Uint8 extra_buttons;
+ Uint8 extra_axes;
+} GIP_Quirks;
+
+static const GIP_Quirks quirks[] = {
+ { USB_VENDOR_MICROSOFT, USB_PRODUCT_XBOX_ONE_ELITE_SERIES_1, 0,
+ .added_features = GIP_FEATURE_ELITE_BUTTONS,
+ .filtered_features = GIP_FEATURE_CONSOLE_FUNCTION_MAP },
+
+ { USB_VENDOR_MICROSOFT, USB_PRODUCT_XBOX_ONE_ELITE_SERIES_2, 0,
+ .added_features = GIP_FEATURE_ELITE_BUTTONS | GIP_FEATURE_DYNAMIC_LATENCY_INPUT | GIP_FEATURE_CONSOLE_FUNCTION_MAP | GIP_FEATURE_GUIDE_COLOR | GIP_FEATURE_EXTENDED_SET_DEVICE_STATE,
+ .extra_in_system = { 1 << GIP_CMD_FIRMWARE },
+ .extra_out_system = { 1 << GIP_CMD_FIRMWARE } },
+
+ { USB_VENDOR_MICROSOFT, USB_PRODUCT_XBOX_SERIES_X, 0,
+ .added_features = GIP_FEATURE_DYNAMIC_LATENCY_INPUT },
+
+ { USB_VENDOR_PDP, USB_PRODUCT_PDP_ROCK_CANDY, 0,
+ .quirks = GIP_QUIRK_NO_HELLO },
+
+ { USB_VENDOR_POWERA, USB_PRODUCT_BDA_XB1_FIGHTPAD, 0,
+ .filtered_features = GIP_FEATURE_MOTOR_CONTROL },
+
+ { USB_VENDOR_POWERA, USB_PRODUCT_BDA_XB1_CLASSIC, 0,
+ .quirks = GIP_QUIRK_NO_IMPULSE_VIBRATION },
+
+ { USB_VENDOR_POWERA, USB_PRODUCT_BDA_XB1_SPECTRA_PRO, 0,
+ .quirks = GIP_QUIRK_NO_IMPULSE_VIBRATION },
+
+ { USB_VENDOR_RAZER, USB_PRODUCT_RAZER_ATROX, 0,
+ .filtered_features = GIP_FEATURE_MOTOR_CONTROL,
+ .device_type = GIP_TYPE_ARCADE_STICK },
+
+ { USB_VENDOR_THRUSTMASTER, USB_PRODUCT_THRUSTMASTER_T_FLIGHT_HOTAS_ONE, 0,
+ .filtered_features = GIP_FEATURE_MOTOR_CONTROL,
+ .device_type = GIP_TYPE_FLIGHT_STICK,
+ .extra_buttons = 5,
+ .extra_axes = 3 },
+
+ {0},
+};
+
+typedef struct GIP_Header
+{
+ Uint8 message_type;
+ Uint8 flags;
+ Uint8 sequence_id;
+ Uint64 length;
+} GIP_Header;
+
+typedef struct GIP_AudioFormat
+{
+ Uint8 inbound;
+ Uint8 outbound;
+} GIP_AudioFormat;
+
+typedef struct GIP_DeviceMetadata
+{
+ Uint8 num_audio_formats;
+ Uint8 num_preferred_types;
+ Uint8 num_supported_interfaces;
+ Uint8 hid_descriptor_size;
+
+ Uint32 in_system_messages[8];
+ Uint32 out_system_messages[8];
+
+ GIP_AudioFormat *audio_formats;
+ char **preferred_types;
+ GUID *supported_interfaces;
+ Uint8 *hid_descriptor;
+
+ GIP_AttachmentType device_type;
+} GIP_DeviceMetadata;
+
+typedef struct GIP_MessageMetadata
+{
+ Uint8 type;
+ Uint16 length;
+ Uint16 data_type;
+ Uint32 flags;
+ Uint16 period;
+ Uint16 persistence_timeout;
+} GIP_MessageMetadata;
+
+typedef struct GIP_Metadata
+{
+ Uint16 version_major;
+ Uint16 version_minor;
+
+ GIP_DeviceMetadata device;
+
+ Uint8 num_messages;
+ GIP_MessageMetadata *message_metadata;
+} GIP_Metadata;
+
+struct GIP_Device;
+typedef struct GIP_Attachment
+{
+ struct GIP_Device *device;
+ Uint8 attachment_index;
+ SDL_JoystickID joystick;
+ // SDL_KeyboardID keyboard;
+
+ Uint8 fragment_message;
+ Uint16 total_length;
+ Uint8 *fragment_data;
+ Uint32 fragment_offset;
+ Uint64 fragment_timer;
+ int fragment_retries;
+
+ Uint16 firmware_major_version;
+ Uint16 firmware_minor_version;
+
+ GIP_MetadataStatus got_metadata;
+ Uint64 metadata_next;
+ int metadata_retries;
+ GIP_Metadata metadata;
+
+ Uint8 seq_system;
+ Uint8 seq_security;
+ Uint8 seq_extended;
+ Uint8 seq_audio;
+ Uint8 seq_vendor;
+
+ int device_state;
+
+ GIP_RumbleState rumble_state;
+ Uint64 rumble_time;
+ bool rumble_pending;
+ Uint8 left_impulse_level;
+ Uint8 right_impulse_level;
+ Uint8 left_vibration_level;
+ Uint8 right_vibration_level;
+
+ Uint8 last_input[64];
+
+ Uint8 last_modifiers;
+ bool capslock;
+ SDL_Keycode last_key;
+ Uint32 altcode;
+ int altcode_digit;
+
+ GIP_AttachmentType attachment_type;
+ GIP_EliteButtonFormat xbe_format;
+ Uint32 features;
+ Uint32 quirks;
+ Uint8 share_button_idx;
+ Uint8 paddle_idx;
+
+ Uint8 extra_button_idx;
+ int extra_buttons;
+ int extra_axes;
+} GIP_Attachment;
+
+typedef struct GIP_Device
+{
+ SDL_HIDAPI_Device *device;
+
+ Uint64 hello_deadline;
+ bool got_hello;
+ bool reset_for_metadata;
+ int timeout;
+
+ GIP_Attachment *attachments[MAX_ATTACHMENTS];
+} GIP_Device;
+
+typedef struct GIP_HelloDevice
+{
+ Uint64 device_id;
+ Uint16 vendor_id;
+ Uint16 product_id;
+ Uint16 firmware_major_version;
+ Uint16 firmware_minor_version;
+ Uint16 firmware_build_version;
+ Uint16 firmware_revision;
+ Uint8 hardware_major_version;
+ Uint8 hardware_minor_version;
+ Uint8 rf_proto_major_version;
+ Uint8 rf_proto_minor_version;
+ Uint8 security_major_version;
+ Uint8 security_minor_version;
+ Uint8 gip_major_version;
+ Uint8 gip_minor_version;
+} GIP_HelloDevice;
+
+typedef struct GIP_Status
+{
+ int power_level;
+ int charge;
+ int battery_type;
+ int battery_level;
+} GIP_Status;
+
+typedef struct GIP_StatusEvent
+{
+ Uint16 event_type;
+ Uint32 fault_tag;
+ Uint32 fault_address;
+} GIP_StatusEvent;
+
+typedef struct GIP_ExtendedStatus
+{
+ GIP_Status base;
+ bool device_active;
+
+ int num_events;
+ GIP_StatusEvent events[5];
+} GIP_ExtendedStatus;
+
+typedef struct GIP_DirectMotor
+{
+ Uint8 motor_bitmap;
+ Uint8 left_impulse_level;
+ Uint8 right_impulse_level;
+ Uint8 left_vibration_level;
+ Uint8 right_vibration_level;
+ Uint8 duration;
+ Uint8 delay;
+ Uint8 repeat;
+} GIP_DirectMotor;
+
+typedef struct GIP_InitialReportsRequest
+{
+ Uint8 type;
+ Uint8 data[2];
+} GIP_InitialReportsRequest;
+
+static bool GIP_SetMetadataDefaults(GIP_Attachment *attachment);
+
+static int GIP_DecodeLength(Uint64 *length, const Uint8 *bytes, int num_bytes)
+{
+ *length = 0;
+ int offset;
+
+ for (offset = 0; offset < num_bytes; offset++) {
+ Uint8 byte = bytes[offset];
+ *length |= (byte & 0x7full) << (offset * 7);
+ if (!(byte & 0x80)) {
+ offset++;
+ break;
+ }
+ }
+ return offset;
+}
+
+static int GIP_EncodeLength(Uint64 length, Uint8 *bytes, int num_bytes)
+{
+ int offset;
+
+ for (offset = 0; offset < num_bytes; offset++) {
+ Uint8 byte = length & 0x7f;
+ length >>= 7;
+ if (length) {
+ byte |= 0x80;
+ }
+ bytes[offset] = byte;
+ if (!length) {
+ offset++;
+ break;
+ }
+ }
+ return offset;
+}
+
+static bool GIP_SupportsSystemMessage(GIP_Attachment *attachment, Uint8 command, bool upstream)
+{
+ if (upstream) {
+ return attachment->metadata.device.in_system_messages[command >> 5] & (1u << command);
+ } else {
+ return attachment->metadata.device.out_system_messages[command >> 5] & (1u << command);
+ }
+}
+
+static bool GIP_SupportsVendorMessage(GIP_Attachment *attachment, Uint8 command, bool upstream)
+{
+ size_t i;
+ for (i = 0; i < attachment->metadata.num_messages; i++) {
+ GIP_MessageMetadata *metadata = &attachment->metadata.message_metadata[i];
+ if (metadata->type != command) {
+ continue;
+ }
+ if (metadata->flags & GIP_MESSAGE_FLAG_DS_REQUEST_RESPONSE) {
+ return true;
+ }
+ if (upstream) {
+ return metadata->flags & GIP_MESSAGE_FLAG_UPSTREAM;
+ } else {
+ return metadata->flags & GIP_MESSAGE_FLAG_DOWNSTREAM;
+ }
+ }
+ return false;
+}
+
+static Uint8 GIP_SequenceNext(GIP_Attachment *attachment, Uint8 command, bool system)
+{
+ Uint8 seq;
+
+ if (system) {
+ switch (command) {
+ case GIP_CMD_SECURITY:
+ seq = attachment->seq_security++;
+ if (!seq) {
+ seq = attachment->seq_security++;
+ }
+ break;
+ case GIP_CMD_EXTENDED:
+ seq = attachment->seq_extended++;
+ if (!seq) {
+ seq = attachment->seq_extended++;
+ }
+ break;
+ case GIP_AUDIO_DATA:
+ seq = attachment->seq_audio++;
+ if (!seq) {
+ seq = attachment->seq_audio++;
+ }
+ break;
+ default:
+ seq = attachment->seq_system++;
+ if (!seq) {
+ seq = attachment->seq_system++;
+ }
+ break;
+ }
+ } else {
+ if (command == GIP_CMD_DIRECT_MOTOR) {
+ // The motor sequence number is optional and always works with 0
+ return 0;
+ }
+
+ seq = attachment->seq_vendor++;
+ if (!seq) {
+ seq = attachment->seq_vendor++;
+ }
+ }
+ return seq;
+}
+
+static void GIP_HandleQuirks(GIP_Attachment *attachment)
+{
+ size_t i, j;
+ for (i = 0; quirks[i].vendor_id; i++) {
+ if (quirks[i].vendor_id != attachment->device->device->vendor_id) {
+ continue;
+ }
+ if (quirks[i].product_id != attachment->device->device->product_id) {
+ continue;
+ }
+ if (quirks[i].attachment_index != attachment->attachment_index) {
+ continue;
+ }
+ attachment->features |= quirks[i].added_features;
+ attachment->features &= ~quirks[i].filtered_features;
+ attachment->quirks = quirks[i].quirks;
+ attachment->attachment_type = quirks[i].device_type;
+
+ for (j = 0; j < 8; ++j) {
+ attachment->metadata.device.in_system_messages[j] |= quirks[i].extra_in_system[j];
+ attachment->metadata.device.out_system_messages[j] |= quirks[i].extra_out_system[j];
+ }
+
+ attachment->extra_buttons = quirks[i].extra_buttons;
+ attachment->extra_axes = quirks[i].extra_axes;
+ break;
+ }
+}
+
+static bool GIP_SendRawMessage(
+ GIP_Device *device,
+ Uint8 message_type,
+ Uint8 flags,
+ Uint8 seq,
+ const Uint8 *bytes,
+ int num_bytes,
+ bool async,
+ SDL_HIDAPI_RumbleSentCallback callback,
+ void *userdata)
+{
+ Uint8 buffer[2054] = { message_type, flags, seq };
+ int offset = 3;
+
+ if (num_bytes < 0) {
+ SDL_LogWarn(SDL_LOG_CATEGORY_INPUT, "GIP: Invalid message length %d", num_bytes);
+ return false;
+ }
+
+ if (num_bytes > GIP_DataClassMtu[message_type >> GIP_DATA_CLASS_SHIFT]) {
+ SDL_LogError(SDL_LOG_CATEGORY_INPUT,
+ "Attempted to send a message that requires fragmenting, which is not yet supported.");
+ return false;
+ }
+
+ offset += GIP_EncodeLength(num_bytes, &buffer[offset], sizeof(buffer) - offset);
+
+ if (num_bytes > 0) {
+ SDL_memcpy(&buffer[offset], bytes, num_bytes);
+ }
+ num_bytes += offset;
+#ifdef DEBUG_XBOX_PROTOCOL
+ HIDAPI_DumpPacket("GIP sending message: size = %d", buffer, num_bytes);
+#endif
+
+ if (async) {
+ if (!SDL_HIDAPI_LockRumble()) {
+ return false;
+ }
+
+ return SDL_HIDAPI_SendRumbleWithCallbackAndUnlock(device->device, buffer, num_bytes, callback, userdata) == num_bytes;
+ } else {
+ return SDL_hid_write(device->device->dev, buffer, num_bytes) == num_bytes;
+ }
+}
+
+static bool GIP_SendSystemMessage(
+ GIP_Attachment *attachment,
+ Uint8 message_type,
+ Uint8 flags,
+ const Uint8 *bytes,
+ int num_bytes)
+{
+ return GIP_SendRawMessage(attachment->device,
+ message_type,
+ GIP_FLAG_SYSTEM | attachment->attachment_index | flags,
+ GIP_SequenceNext(attachment, message_type, true),
+ bytes,
+ num_bytes,
+ false,
+ NULL,
+ NULL);
+}
+
+static bool GIP_SendVendorMessage(
+ GIP_Attachment *attachment,
+ Uint8 message_type,
+ Uint8 flags,
+ const Uint8 *bytes,
+ int num_bytes)
+{
+ return GIP_SendRawMessage(attachment->device,
+ message_type,
+ flags,
+ GIP_SequenceNext(attachment, message_type, false),
+ bytes,
+ num_bytes,
+ true,
+ NULL,
+ NULL);
+}
+
+static bool GIP_AttachmentIsController(GIP_Attachment *attachment)
+{
+ return attachment->attachment_type != GIP_TYPE_CHATPAD &&
+ attachment->attachment_type != GIP_TYPE_HEADSET;
+}
+
+static void GIP_MetadataFree(GIP_Metadata *metadata)
+{
+ SDL_free(metadata->device.audio_formats);
+ if (metadata->device.preferred_types) {
+ int i;
+ for (i = 0; i < metadata->device.num_preferred_types; i++) {
+ SDL_free(metadata->device.preferred_types[i]);
+ }
+ SDL_free(metadata->device.preferred_types);
+ }
+ SDL_free(metadata->device.supported_interfaces);
+ SDL_free(metadata->device.hid_descriptor);
+
+ SDL_free(metadata->message_metadata);
+ SDL_zerop(metadata);
+}
+
+static bool GIP_ParseDeviceMetadata(GIP_Metadata *metadata, const Uint8 *bytes, int num_bytes, int *offset)
+{
+ GIP_DeviceMetadata *device = &metadata->device;
+ int buffer_offset;
+ int count;
+ int length;
+ int i;
+
+ bytes = &bytes[*offset];
+ num_bytes -= *offset;
+ if (num_bytes < 16) {
+ return false;
+ }
+
+ length = bytes[0];
+ length |= bytes[1] << 8;
+ if (num_bytes < length) {
+ return false;
+ }
+
+ /* Skip supported firmware versions for now */
+
+ buffer_offset = bytes[4];
+ buffer_offset |= bytes[5] << 8;
+ if (buffer_offset >= length) {
+ return false;
+ }
+ if (buffer_offset > 0) {
+ device->num_audio_formats = bytes[buffer_offset];
+ if (buffer_offset + device->num_audio_formats + 1 > length) {
+ return false;
+ }
+ device->audio_formats = SDL_malloc(device->num_audio_formats);
+ SDL_memcpy(device->audio_formats, &bytes[buffer_offset + 1], device->num_audio_formats);
+ }
+
+ buffer_offset = bytes[6];
+ buffer_offset |= bytes[7] << 8;
+ if (buffer_offset >= length) {
+ return false;
+ }
+ if (buffer_offset > 0) {
+ count = bytes[buffer_offset];
+ if (buffer_offset + count + 1 > length) {
+ return false;
+ }
+
+ for (i = 0; i < count; i++) {
+ Uint8 message = bytes[buffer_offset + 1 + i];
+#ifdef DEBUG_XBOX_PROTOCOL
+ SDL_LogDebug(SDL_LOG_CATEGORY_INPUT,
+ "GIP: Supported upstream system message %02x",
+ message);
+#endif
+ device->in_system_messages[message >> 5] |= 1u << (message & 0x1F);
+ }
+ }
+
+ buffer_offset = bytes[8];
+ buffer_offset |= bytes[9] << 8;
+ if (buffer_offset >= length) {
+ return false;
+ }
+ if (buffer_offset > 0) {
+ count = bytes[buffer_offset];
+ if (buffer_offset + count + 1 > length) {
+ return false;
+ }
+
+ for (i = 0; i < count; i++) {
+ Uint8 message = bytes[buffer_offset + 1 + i];
+#ifdef DEBUG_XBOX_PROTOCOL
+ SDL_LogDebug(SDL_LOG_CATEGORY_INPUT,
+ "GIP: Supported downstream system message %02x",
+ message);
+#endif
+ device->out_system_messages[message >> 5] |= 1u << (message & 0x1F);
+ }
+ }
+
+ buffer_offset = bytes[10];
+ buffer_offset |= bytes[11] << 8;
+ if (buffer_offset >= length) {
+ return false;
+ }
+ if (buffer_offset > 0) {
+ device->num_preferred_types = bytes[buffer_offset];
+ device->preferred_types = SDL_calloc(device->num_preferred_types, sizeof(char *));
+ buffer_offset++;
+ for (i = 0; i < device->num_preferred_types; i++) {
+ if (buffer_offset + 2 >= length) {
+ return false;
+ }
+
+ count = bytes[buffer_offset];
+ count |= bytes[buffer_offset];
+ buffer_offset += 2;
+ if (buffer_offset + count > length) {
+ return false;
+ }
+
+ device->preferred_types[i] = SDL_calloc(count + 1, sizeof(char));
+ SDL_memcpy(device->preferred_types[i], &bytes[buffer_offset], count);
+ buffer_offset += count;
+ }
+ }
+
+ buffer_offset = bytes[12];
+ buffer_offset |= bytes[13] << 8;
+ if (buffer_offset >= length) {
+ return false;
+ }
+ if (buffer_offset > 0) {
+ device->num_supported_interfaces = bytes[buffer_offset];
+ if (buffer_offset + 1 + (Sint32) (device->num_supported_interfaces * sizeof(GUID)) > length) {
+ return false;
+ }
+ device->supported_interfaces = SDL_calloc(device->num_supported_interfaces, sizeof(GUID));
+ SDL_memcpy(device->supported_interfaces,
+ &bytes[buffer_offset + 1],
+ sizeof(GUID) * device->num_supported_interfaces);
+ }
+
+ if (metadata->version_major > 1 || metadata->version_minor >= 1) {
+ /* HID descriptor support added in metadata version 1.1 */
+ buffer_offset = bytes[14];
+ buffer_offset |= bytes[15] << 8;
+ if (buffer_offset >= length) {
+ return false;
+ }
+ if (buffer_offset > 0) {
+ device->hid_descriptor_size = bytes[buffer_offset];
+ if (buffer_offset + 1 + device->hid_descriptor_size > length) {
+ return false;
+ }
+ device->hid_descriptor = SDL_malloc(device->hid_descriptor_size);
+ SDL_memcpy(device->hid_descriptor, &bytes[buffer_offset + 1], device->hid_descriptor_size);
+#ifdef DEBUG_XBOX_PROTOCOL
+ HIDAPI_DumpPacket("GIP received HID descriptor: size = %d", device->hid_descriptor, device->hid_descriptor_size);
+#endif
+ }
+ }
+
+ *offset += length;
+ return true;
+}
+
+static bool GIP_ParseMessageMetadata(GIP_MessageMetadata *metadata, const Uint8 *bytes, int num_bytes, int *offset)
+{
+ Uint16 length;
+
+ bytes = &bytes[*offset];
+ num_bytes -= *offset;
+
+ if (num_bytes < 2) {
+ return false;
+ }
+ length = bytes[0];
+ length |= bytes[1] << 8;
+ if (num_bytes < length) {
+ return false;
+ }
+
+ if (length < 15) {
+ return false;
+ }
+
+ metadata->type = bytes[2];
+ metadata->length = bytes[3];
+ metadata->length |= bytes[4] << 8;
+ metadata->data_type = bytes[5];
+ metadata->data_type |= bytes[6] << 8;
+ metadata->flags = bytes[7];
+ metadata->flags |= bytes[8] << 8;
+ metadata->flags |= bytes[9] << 16;
+ metadata->flags |= bytes[10] << 24;
+ metadata->period = bytes[11];
+ metadata->period |= bytes[12] << 8;
+ metadata->persistence_timeout = bytes[13];
+ metadata->persistence_timeout |= bytes[14] << 8;
+
+#ifdef DEBUG_XBOX_PROTOCOL
+ SDL_LogDebug(SDL_LOG_CATEGORY_INPUT,
+ "GIP: Supported vendor message type %02x of length %d, %s, %s, %s",
+ metadata->type,
+ metadata->length,
+ metadata->flags & GIP_MESSAGE_FLAG_UPSTREAM ?
+ (metadata->flags & GIP_MESSAGE_FLAG_DOWNSTREAM ? "bidirectional" : "upstream") :
+ metadata->flags & GIP_MESSAGE_FLAG_DOWNSTREAM ? "downstream" :
+ metadata->flags & GIP_MESSAGE_FLAG_DS_REQUEST_RESPONSE ? "downstream request response" :
+ "unknown direction",
+ metadata->flags & GIP_MESSAGE_FLAG_SEQUENCED ? "sequenced" : "not sequenced",
+ metadata->flags & GIP_MESSAGE_FLAG_RELIABLE ? "reliable" : "unreliable");
+#endif
+
+ *offset += length;
+ return true;
+}
+
+static bool GIP_ParseMetadata(GIP_Metadata *metadata, const Uint8 *bytes, int num_bytes)
+{
+ int header_size;
+ int metadata_size;
+ int offset = 0;
+ int i;
+
+ if (num_bytes < 16) {
+ return false;
+ }
+
+#ifdef DEBUG_XBOX_PROTOCOL
+ HIDAPI_DumpPacket("GIP received metadata: size = %d", bytes, num_bytes);
+#endif
+
+ header_size = bytes[0];
+ header_size |= bytes[1] << 8;
+ if (num_bytes < header_size || header_size < 16) {
+ return false;
+ }
+ metadata->version_major = bytes[2];
+ metadata->version_major |= bytes[3] << 8;
+ metadata->version_minor = bytes[4];
+ metadata->version_minor |= bytes[5] << 8;
+ /* Middle bytes are reserved */
+ metadata_size = bytes[14];
+ metadata_size |= bytes[15] << 8;
+
+ if (num_bytes < metadata_size || metadata_size < header_size) {
+ return false;
+ }
+ offset = header_size;
+
+ if (!GIP_ParseDeviceMetadata(metadata, bytes, num_bytes, &offset)) {
+ goto err;
+ }
+
+ if (offset >= num_bytes) {
+ goto err;
+ }
+ metadata->num_messages = bytes[offset];
+ offset++;
+ if (metadata->num_messages > 0) {
+ metadata->message_metadata = SDL_calloc(metadata->num_messages, sizeof(*metadata->message_metadata));
+ for (i = 0; i < metadata->num_messages; i++) {
+ if (!GIP_ParseMessageMetadata(&metadata->message_metadata[i], bytes, num_bytes, &offset)) {
+ goto err;
+ }
+ }
+ }
+
+ return true;
+
+err:
+ GIP_MetadataFree(metadata);
+ return false;
+}
+
+static bool GIP_Acknowledge(
+ GIP_Device *device,
+ const GIP_Header *header,
+ Uint32 fragment_offset,
+ Uint16 bytes_remaining)
+{
+ Uint8 buffer[] = {
+ GIP_CONTROL_CODE_ACK,
+ header->message_type,
+ header->flags & GIP_FLAG_SYSTEM,
+ (Uint8) fragment_offset,
+ (Uint8) (fragment_offset >> 8),
+ (Uint8) (fragment_offset >> 16),
+ fragment_offset >> 24,
+ (Uint8) bytes_remaining,
+ bytes_remaining >> 8,
+ };
+
+ return GIP_SendRawMessage(device,
+ GIP_CMD_PROTO_CONTROL,
+ GIP_FLAG_SYSTEM | (header->flags & GIP_FLAG_ATTACHMENT_MASK),
+ header->sequence_id,
+ buffer,
+ sizeof(buffer),
+ false,
+ NULL,
+ NULL);
+}
+
+static bool GIP_FragmentFailed(GIP_Attachment *attachment, const GIP_Header *header)
+{
+ attachment->fragment_retries++;
+ if (attachment->fragment_retries > 8) {
+ if (attachment->fragment_data) {
+ SDL_free(attachment->fragment_data);
+ attachment->fragment_data = NULL;
+ }
+ attachment->fragment_message = 0;
+ }
+ return GIP_Acknowledge(attachment->device,
+ header,
+ attachment->fragment_offset,
+ (Uint16) (attachment->total_length - attachment->fragment_offset));
+}
+
+static bool GIP_EnableEliteButtons(GIP_Attachment *attachment) {
+ if (attachment->device->device->vendor_id == USB_VENDOR_MICROSOFT) {
+ if (attachment->device->device->product_id == USB_PRODUCT_XBOX_ONE_ELITE_SERIES_1) {
+ attachment->xbe_format = GIP_BTN_FMT_XBE1;
+ } else if (attachment->device->device->product_id == USB_PRODUCT_XBOX_ONE_ELITE_SERIES_2) {
+ if (attachment->firmware_major_version == 4) {
+ attachment->xbe_format = GIP_BTN_FMT_XBE2_4;
+ } else if (attachment->firmware_major_version == 5) {
+ /*
+ * The exact range for this being necessary is unknown, but it
+ * starts at 5.11 and at either 5.16 or 5.17. This approach
+ * still works on 5.21, even if it's not necessary, so having
+ * a loose upper limit is fine.
+ */
+ if (attachment->firmware_minor_version >= 11 &&
+ attachment->firmware_minor_version < 17)
+ {
+ attachment->xbe_format = GIP_BTN_FMT_XBE2_RAW;
+ } else {
+ attachment->xbe_format = GIP_BTN_FMT_XBE2_5;
+ }
+ }
+ }
+ }
+ if (attachment->xbe_format == GIP_BTN_FMT_XBE2_RAW) {
+ /*
+ * The meaning of this packet is unknown and not documented, but it's
+ * needed for the Elite 2 controller to send raw reports
+ */
+ static const Uint8 enable_raw_report[] = { 7, 0 };
+
+ return GIP_SendVendorMessage(attachment,
+ GIP_SL_ELITE_CONFIG,
+ 0,
+ enable_raw_report,
+ sizeof(enable_raw_report));
+ }
+
+ return true;
+}
+
+static bool GIP_SendGuideButtonLED(GIP_Attachment *attachment, Uint8 pattern, Uint8 intensity)
+{
+ Uint8 buffer[] = {
+ GIP_LED_GUIDE,
+ pattern,
+ intensity,
+ };
+
+ if (!GIP_SupportsSystemMessage(attachment, GIP_CMD_LED, false)) {
+ return true;
+ }
+ return GIP_SendSystemMessage(attachment, GIP_CMD_LED, 0, buffer, sizeof(buffer));
+}
+
+static bool GIP_SendQueryFirmware(GIP_Attachment *attachment, Uint8 slot)
+{
+ /* The "slot" variable might not be correct; the packet format is still unclear */
+ Uint8 buffer[] = { 0x1, slot, 0, 0, 0 };
+
+ return GIP_SendSystemMessage(attachment, GIP_CMD_FIRMWARE, 0, buffer, sizeof(buffer));
+}
+
+static bool GIP_SendSetDeviceState(GIP_Attachment *attachment, Uint8 state)
+{
+ Uint8 buffer[] = { state };
+ return GIP_SendSystemMessage(attachment,
+ GIP_CMD_SET_DEVICE_STATE,
+ attachment->attachment_index,
+ buffer,
+ sizeof(buffer));
+}
+
+static bool GIP_SendInitSequence(GIP_Attachment *attachment)
+{
+ if (attachment->features & GIP_FEATURE_EXTENDED_SET_DEVICE_STATE) {
+ /*
+ * The meaning of this packet is unknown and not documented, but it's
+ * needed for the Elite 2 controller to start up on older firmwares
+ */
+ static const Uint8 set_device_state[] = { GIP_STATE_UNK6, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x55, 0x53, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0 };
+
+ if (!GIP_SendSystemMessage(attachment,
+ GIP_CMD_SET_DEVICE_STATE,
+ 0,
+ set_device_state,
+ sizeof(set_device_state)))
+ {
+ return false;
+ }
+ }
+ if (!GIP_EnableEliteButtons(attachment)) {
+ return false;
+ }
+ if (!GIP_SendSetDeviceState(attachment, GIP_STATE_START)) {
+ return false;
+ }
+ attachment->device_state = GIP_STATE_START;
+
+ if (!GIP_SendGuideButtonLED(attachment, GIP_LED_GUIDE_ON, 20)) {
+ return false;
+ }
+
+ if (GIP_SupportsSystemMessage(attachment, GIP_CMD_SECURITY, false) &&
+ !(attachment->features & GIP_FEATURE_SECURITY_OPT_OUT))
+ {
+ /* TODO: Implement Security command property */
+ Uint8 buffer[] = { 0x1, 0x0 };
+ GIP_SendSystemMessage(attachment, GIP_CMD_SECURITY, 0, buffer, sizeof(buffer));
+ }
+
+ if (GIP_SupportsVendorMessage(attachment, GIP_CMD_INITIAL_REPORTS_REQUEST, false)) {
+ GIP_InitialReportsRequest request = { 0 };
+ GIP_SendVendorMessage(attachment, GIP_CMD_INITIAL_REPORTS_REQUEST, 0, (const Uint8 *)&request, sizeof(request));
+ }
+
+ if (GIP_SupportsVendorMessage(attachment, GIP_CMD_DEVICE_CAPABILITIES, false)) {
+ GIP_SendVendorMessage(attachment, GIP_CMD_DEVICE_CAPABILITIES, 0, NULL, 0);
+ }
+
+ if ((!attachment->attachment_index || GIP_AttachmentIsController(attachment)) && !attachment->joystick) {
+ return HIDAPI_JoystickConnected(attachment->device->device, &attachment->joystick);
+ }
+ // if (attachment->attachment_type == GIP_TYPE_CHATPAD && !attachment->keyboard) {
+ // attachment->keyboard = (SDL_KeyboardID)(uintptr_t) attachment;
+ // SDL_AddKeyboard(attachment->keyboard, "Xbox One Chatpad");
+ // }
+ return true;
+}
+
+static bool GIP_EnsureMetadata(GIP_Attachment *attachment)
+{
+ switch (attachment->got_metadata) {
+ case GIP_METADATA_GOT:
+ case GIP_METADATA_FAKED:
+ return true;
+ case GIP_METADATA_NONE:
+ if (attachment->device->got_hello) {
+ attachment->device->timeout = GIP_ACME_TIMEOUT;
+ attachment->got_metadata = GIP_METADATA_PENDING;
+ attachment->metadata_next = SDL_GetTicks() + 500;
+ attachment->metadata_retries = 0;
+ return GIP_SendSystemMessage(attachment, GIP_CMD_METADATA, 0, NULL, 0);
+ } else {
+ if (attachment->device->reset_for_metadata) {
+ return true;
+ }
+ return GIP_SetMetadataDefaults(attachment);
+ }
+ default:
+ return true;
+ }
+}
+
+static bool GIP_SetMetadataDefaults(GIP_Attachment *attachment)
+{
+ if (attachment->attachment_index == 0) {
+ /* Some decent default settings */
+ attachment->features |= GIP_FEATURE_MOTOR_CONTROL;
+ attachment->attachment_type = GIP_TYPE_GAMEPAD;
+ attachment->metadata.device.in_system_messages[0] |= (1u << GIP_CMD_GUIDE_BUTTON);
+
+ if (SDL_IsJoystickXboxSeriesX(attachment->device->device->vendor_id, attachment->device->device->product_id)) {
+ attachment->features |= GIP_FEATURE_CONSOLE_FUNCTION_MAP;
+ }
+ }
+
+ GIP_HandleQuirks(attachment);
+
+ if (GIP_SupportsSystemMessage(attachment, GIP_CMD_FIRMWARE, false)) {
+ GIP_SendQueryFirmware(attachment, 2);
+ }
+
+ attachment->got_metadata = GIP_METADATA_FAKED;
+ attachment->device->hello_deadline = 0;
+ if (!attachment->joystick) {
+ return HIDAPI_JoystickConnected(attachment->device->device, &attachment->joystick);
+ }
+ return true;
+}
+
+static bool GIP_HandleCommandProtocolControl(
+ GIP_Attachment *attachment,
+ const GIP_Header *header,
+ const Uint8 *bytes,
+ int num_bytes)
+{
+ // TODO
+ SDL_LogDebug(SDL_LOG_CATEGORY_INPUT, "GIP: Unimplemented Protocol Control message");
+ return false;
+}
+
+static bool GIP_HandleCommandHelloDevice(
+ GIP_Attachment *attachment,
+ const GIP_Header *header,
+ const Uint8 *bytes,
+ int num_bytes)
+{
+ GIP_HelloDevice message = {0};
+
+ if (num_bytes != 28) {
+ return false;
+ }
+
+ message.device_id = (Uint64) bytes[0];
+ message.device_id |= (Uint64) bytes[1] << 8;
+ message.device_id |= (Uint64) bytes[2] << 16;
+ message.device_id |= (Uint64) bytes[3] << 24;
+ message.device_id |= (Uint64) bytes[4] << 32;
+ message.device_id |= (Uint64) bytes[5] << 40;
+ message.device_id |= (Uint64) bytes[6] << 48;
+ message.device_id |= (Uint64) bytes[7] << 56;
+
+ message.vendor_id = bytes[8];
+ message.vendor_id |= bytes[9] << 8;
+
+ message.product_id = bytes[10];
+ message.product_id |= bytes[11] << 8;
+
+ message.firmware_major_version = bytes[12];
+ message.firmware_major_version |= bytes[13] << 8;
+
+ message.firmware_minor_version = bytes[14];
+ message.firmware_minor_version |= bytes[15] << 8;
+
+ message.firmware_build_version = bytes[16];
+ message.firmware_build_version |= bytes[17] << 8;
+
+ message.firmware_revision = bytes[18];
+ message.firmware_revision |= bytes[19] << 8;
+
+ message.hardware_major_version = bytes[20];
+ message.hardware_minor_version = bytes[21];
+
+ message.rf_proto_major_version = bytes[22];
+ message.rf_proto_minor_version = bytes[23];
+
+ message.security_major_version = bytes[24];
+ message.security_minor_version = bytes[25];
+
+ message.gip_major_version = bytes[26];
+ message.gip_minor_version = bytes[27];
+
+ SDL_LogInfo(SDL_LOG_CATEGORY_INPUT,
+ "GIP: Device hello from %" SDL_PRIx64 " (%04x:%04x)",
+ message.device_id, message.vendor_id, message.product_id);
+ SDL_LogInfo(SDL_LOG_CATEGORY_INPUT,
+ "GIP: Firmware version %d.%d.%d rev %d",
+ message.firmware_major_version,
+ message.firmware_minor_version,
+ message.firmware_build_version,
+ message.firmware_revision);
+
+ /*
+ * The GIP spec specifies that the host should reject the device if any of these are wrong.
+ * I don't know if Windows or an Xbox do, however, so let's just log warnings instead.
+ */
+ if (message.rf_proto_major_version != 1 && message.rf_proto_minor_version != 0) {
+ SDL_LogWarn(SDL_LOG_CATEGORY_INPUT,
+ "GIP: Invalid RF protocol version %d.%d, expected 1.0",
+ message.rf_proto_major_version, message.rf_proto_minor_version);
+ }
+
+ if (message.security_major_version != 1 && message.security_minor_version != 0) {
+ SDL_LogWarn(SDL_LOG_CATEGORY_INPUT,
+ "GIP: Invalid security protocol version %d.%d, expected 1.0",
+ message.security_major_version, message.security_minor_version);
+ }
+
+ if (message.gip_major_version != 1 && message.gip_minor_version != 0) {
+ SDL_LogWarn(SDL_LOG_CATEGORY_INPUT,
+ "GIP: Invalid GIP version %d.%d, expected 1.0",
+ message.gip_major_version, message.gip_minor_version);
+ }
+
+ if (header->flags & GIP_FLAG_ATTACHMENT_MASK) {
+ return GIP_SendSystemMessage(attachment, GIP_CMD_METADATA, 0, NULL, 0);
+ } else {
+ attachment->firmware_major_version = message.firmware_major_version;
+ attachment->firmware_minor_version = message.firmware_minor_version;
+
+ if (attachment->attachment_index == 0) {
+ attachment->device->hello_deadline = 0;
+ attachment->device->got_hello = true;
+ }
+ if (attachment->got_metadata == GIP_METADATA_FAKED) {
+ attachment->got_metadata = GIP_METADATA_NONE;
+ }
+ GIP_EnsureMetadata(attachment);
+ }
+ return true;
+}
+
+static bool GIP_HandleCommandStatusDevice(
+ GIP_Attachment *attachment,
+ const GIP_Header *header,
+ const Uint8 *bytes,
+ int num_bytes)
+{
+ GIP_ExtendedStatus status;
+ SDL_Joystick *joystick = NULL;
+ SDL_PowerState power_state;
+ int power_percent = 0;
+ int i;
+
+ if (num_bytes < 1) {
+ return false;
+ }
+ SDL_zero(status);
+ status.base.battery_level = bytes[0] & 3;
+ status.base.battery_type = (bytes[0] >> 2) & 3;
+ status.base.charge = (bytes[0] >> 4) & 3;
+ status.base.power_level = (bytes[0] >> 6) & 3;
+
+ if (attachment->joystick) {
+ joystick = SDL_GetJoystickFromID(attachment->joystick);
+ }
+ if (joystick) {
+ switch (status.base.battery_level) {
+ case GIP_BATTERY_CRITICAL:
+ power_percent = 1;
+ break;
+ case GIP_BATTERY_LOW:
+ power_percent = 25;
+ break;
+ case GIP_BATTERY_MEDIUM:
+ power_percent = 50;
+ break;
+ case GIP_BATTERY_FULL:
+ power_percent = 100;
+ break;
+ }
+ switch (status.base.charge) {
+ case GIP_CHARGING:
+ if (status.base.battery_level == GIP_BATTERY_FULL) {
+ power_state = SDL_POWERSTATE_CHARGED;
+ } else {
+ power_state = SDL_POWERSTATE_CHARGING;
+ }
+ break;
+ case GIP_NOT_CHARGING:
+ power_state = SDL_POWERSTATE_ON_BATTERY;
+ break;
+ case GIP_CHARGE_ERROR:
+ default:
+ power_state = SDL_POWERSTATE_UNKNOWN;
+ break;
+ }
+
+ switch (status.base.battery_type) {
+ case GIP_BATTERY_ABSENT:
+ power_state = SDL_POWERSTATE_NO_BATTERY;
+ break;
+ case GIP_BATTERY_STANDARD:
+ case GIP_BATTERY_RECHARGEABLE:
+ break;
+ default:
+ power_state = SDL_POWERSTATE_UNKNOWN;
+ break;
+ }
+
+ SDL_SendJoystickPowerInfo(joystick, power_state, power_percent);
+ }
+
+ if (num_bytes >= 4) {
+ status.device_active = bytes[1] & 1;
+ if (bytes[1] & 2) {
+ /* Events present */
+ if (num_bytes < 5) {
+ return false;
+ }
+ status.num_events = bytes[4];
+ if (status.num_events > 5) {
+ SDL_LogWarn(SDL_LOG_CATEGORY_INPUT,
+ "GIP: Device reported too many events, %d > 5",
+ status.num_events);
+ return false;
+ }
+ if (5 + status.num_events * 10 > num_bytes) {
+ return false;
+ }
+ for (i = 0; i < status.num_events; i++) {
+ status.events[i].event_type = bytes[i * 10 + 5];
+ status.events[i].event_type |= bytes[i * 10 + 6] << 8;
+ status.events[i].fault_tag = bytes[i * 10 + 7];
+ status.events[i].fault_tag |= bytes[i * 10 + 8] << 8;
+ status.events[i].fault_tag |= bytes[i * 10 + 9] << 16;
+ status.events[i].fault_tag |= bytes[i * 10 + 10] << 24;
+ status.events[i].fault_tag = bytes[i * 10 + 11];
+ status.events[i].fault_tag |= bytes[i * 10 + 12] << 8;
+ status.events[i].fault_tag |= bytes[i * 10 + 13] << 16;
+ status.events[i].fault_tag |= bytes[i * 10 + 14] << 24;
+ }
+ }
+ }
+
+ GIP_EnsureMetadata(attachment);
+ return true;
+}
+
+static bool GIP_HandleCommandMetadataRespose(
+ GIP_Attachment *attachment,
+ const GIP_Header *header,
+ const Uint8 *bytes,
+ int num_bytes)
+{
+ GIP_Metadata metadata = {0};
+ const GUID *expected_guid = NULL;
+ bool found_expected_guid;
+ bool found_controller_guid = false;
+ int i;
+
+ if (!GIP_ParseMetadata(&metadata, bytes, num_bytes)) {
+ return false;
+ }
+
+ if (attachment->got_metadata == GIP_METADATA_GOT) {
+ GIP_MetadataFree(&attachment->metadata);
+ }
+ attachment->metadata = metadata;
+ attachment->got_metadata = GIP_METADATA_GOT;
+ attachment->features = 0;
+
+ attachment->attachment_type = GIP_TYPE_UNKNOWN;
+#ifdef DEBUG_XBOX_PROTOCOL
+ for (i = 0; i < metadata.device.num_preferred_types; i++) {
+ const char *type = metadata.device.preferred_types[i];
+ SDL_LogDebug(SDL_LOG_CATEGORY_INPUT, "GIP: Device preferred type: %s", type);
+ }
+#endif
+ for (i = 0; i < metadata.device.num_preferred_types; i++) {
+ const char *type = metadata.device.preferred_types[i];
+ if (SDL_strcmp(type, "Windows.Xbox.Input.Gamepad") == 0) {
+ attachment->attachment_type = GIP_TYPE_GAMEPAD;
+ expected_guid = &GUID_IGamepad;
+ break;
+ }
+ if (SDL_strcmp(type, "Microsoft.Xbox.Input.ArcadeStick") == 0) {
+ attachment->attachment_type = GIP_TYPE_ARCADE_STICK;
+ expected_guid = &GUID_ArcadeStick;
+ break;
+ }
+ if (SDL_strcmp(type, "Windows.Xbox.Input.ArcadeStick") == 0) {
+ attachment->attachment_type = GIP_TYPE_ARCADE_STICK;
+ expected_guid = &GUID_ArcadeStick;
+ break;
+ }
+ if (SDL_strcmp(type, "Microsoft.Xbox.Input.FlightStick") == 0) {
+ attachment->attachment_type = GIP_TYPE_FLIGHT_STICK;
+ expected_guid = &GUID_FlightStick;
+ break;
+ }
+ if (SDL_strcmp(type, "Windows.Xbox.Input.FlightStick") == 0) {
+ attachment->attachment_type = GIP_TYPE_FLIGHT_STICK;
+ expected_guid = &GUID_FlightStick;
+ break;
+ }
+ if (SDL_strcmp(type, "Microsoft.Xbox.Input.Wheel") == 0) {
+ attachment->attachment_type = GIP_TYPE_WHEEL;
+ expected_guid = &GUID_Wheel;
+ break;
+ }
+ if (SDL_strcmp(type, "Windows.Xbox.Input.Wheel") == 0) {
+ attachment->attachment_type = GIP_TYPE_WHEEL;
+ expected_guid = &GUID_Wheel;
+ break;
+ }
+ if (SDL_strcmp(type, "Windows.Xbox.Input.NavigationController") == 0) {
+ attachment->attachment_type = GIP_TYPE_NAVIGATION_CONTROLLER;
+ expected_guid = &GUID_NavigationController;
+ break;
+ }
+ if (SDL_strcmp(type, "Windows.Xbox.Input.Chatpad") == 0) {
+ attachment->attachment_type = GIP_TYPE_CHATPAD;
+ break;
+ }
+ if (SDL_strcmp(type, "Windows.Xbox.Input.Headset") == 0) {
+ attachment->attachment_type = GIP_TYPE_HEADSET;
+ expected_guid = &GUID_IHeadset;
+ break;
+ }
+ if (SDL_strcmp(type, "Activision.Xbox.Input.GH7") == 0) {
+ attachment->attachment_type = GIP_TYPE_LIVE_GUITAR;
+ expected_guid = &GUID_GuitarHero_Live_Guitar;
+ break;
+ }
+ if (SDL_strcmp(type, "MadCatz.Xbox.Guitar.Stratocaster") == 0) {
+ attachment->attachment_type = GIP_TYPE_GUITAR;
+ expected_guid = &GUID_Madcatz_Guitar;
+ break;
+ }
+ if (SDL_strcmp(type, "PDP.Xbox.Guitar.Jaguar") == 0) {
+ attachment->attachment_type = GIP_TYPE_GUITAR;
+ expected_guid = &GUID_PDP_Guitar;
+ break;
+ }
+ if (SDL_strcmp(type, "MadCatz.Xbox.Drums.Glam") == 0) {
+ attachment->attachment_type = GIP_TYPE_DRUM_KIT;
+ expected_guid = &GUID_Madcatz_DrumKit;
+ break;
+ }
+ if (SDL_strcmp(type, "PDP.Xbox.Drums.Tablah") == 0) {
+ attachment->attachment_type = GIP_TYPE_DRUM_KIT;
+ expected_guid = &GUID_PDP_DrumKit;
+ break;
+ }
+ }
+
+ found_expected_guid = !expected_guid;
+ for (i = 0; i < metadata.device.num_supported_interfaces; i++) {
+ const GUID* guid = &metadata.device.supported_interfaces[i];
+#ifdef DEBUG_XBOX_PROTOCOL
+ SDL_LogDebug(SDL_LOG_CATEGORY_INPUT,
+ "GIP: Supported interface: %08x-%04x-%04x-%02x%02x-%02x%02x%02x%02x%02x%02x",
+ guid->a, guid->b, guid->c, guid->d[0], guid->d[1],
+ guid->d[2], guid->d[3], guid->d[4], guid->d[5], guid->d[6], guid->d[7]);
+#endif
+ if (expected_guid && SDL_memcmp(expected_guid, guid, sizeof(GUID)) == 0) {
+ found_expected_guid = true;
+ }
+ if (SDL_memcmp(&GUID_IController, guid, sizeof(GUID)) == 0) {
+ found_controller_guid = true;
+ continue;
+ }
+ if (SDL_memcmp(&GUID_IDevAuthPCOptOut, guid, sizeof(GUID)) == 0) {
+ attachment->features |= GIP_FEATURE_SECURITY_OPT_OUT;
+ continue;
+ }
+ if (SDL_memcmp(&GUID_IConsoleFunctionMap_InputReport, guid, sizeof(GUID)) == 0) {
+ attachment->features |= GIP_FEATURE_CONSOLE_FUNCTION_MAP;
+ continue;
+ }
+ if (SDL_memcmp(&GUID_IConsoleFunctionMap_OverflowInputReport, guid, sizeof(GUID)) == 0) {
+ attachment->features |= GIP_FEATURE_CONSOLE_FUNCTION_MAP_OVERFLOW;
+ continue;
+ }
+ if (SDL_memcmp(&GUID_IEliteButtons, guid, sizeof(GUID)) == 0) {
+ attachment->features |= GIP_FEATURE_ELITE_BUTTONS;
+ continue;
+ }
+ if (SDL_memcmp(&GUID_DynamicLatencyInput, guid, sizeof(GUID)) == 0) {
+ attachment->features |= GIP_FEATURE_DYNAMIC_LATENCY_INPUT;
+ continue;
+ }
+ }
+
+ for (i = 0; i < metadata.num_messages; i++) {
+ GIP_MessageMetadata *message = &metadata.message_metadata[i];
+ if (message->type == GIP_CMD_DIRECT_MOTOR && message->length >= 9 &&
+ (message->flags & GIP_MESSAGE_FLAG_DOWNSTREAM)) {
+ attachment->features |= GIP_FEATURE_MOTOR_CONTROL;
+ }
+ }
+
+ if (!found_expected_guid || (GIP_AttachmentIsController(attachment) && !found_controller_guid)) {
+ SDL_LogDebug(SDL_LOG_CATEGORY_INPUT,
+ "GIP: Controller was missing expected GUID. This controller probably won't work on an actual Xbox.");
+ }
+
+ if ((attachment->features & GIP_FEATURE_GUIDE_COLOR) &&
+ !GIP_SupportsVendorMessage(attachment, GIP_CMD_GUIDE_COLOR, false))
+ {
+ attachment->features &= ~GIP_FEATURE_GUIDE_COLOR;
+ }
+
+ GIP_HandleQuirks(attachment);
+
+ return GIP_SendInitSequence(attachment);
+}
+
+static bool GIP_HandleCommandSecurity(
+ GIP_Attachment *attachment,
+ const GIP_Header *header,
+ const Uint8 *bytes,
+ int num_bytes)
+{
+ // TODO
+ SDL_LogDebug(SDL_LOG_CATEGORY_INPUT, "GIP: Unimplemented Security message");
+ return false;
+}
+
+static bool GIP_HandleCommandGuideButtonStatus(
+ GIP_Attachment *attachment,
+ const GIP_Header *header,
+ const Uint8 *bytes,
+ int num_bytes)
+{
+ Uint64 timestamp = SDL_GetTicksNS();
+ SDL_Joystick *joystick = NULL;
+
+ if (attachment->device->device->num_joysticks < 1) {
+ return true;
+ }
+
+ joystick = SDL_GetJoystickFromID(attachment->joystick);
+ if (!joystick) {
+ return false;
+ }
+ if (bytes[1] == VK_LWIN) {
+ SDL_SendJoystickButton(timestamp, joystick, SDL_GAMEPAD_BUTTON_GUIDE, (bytes[0] & 0x03) != 0);
+ }
+
+ return true;
+}
+
+static bool GIP_HandleCommandAudioControl(
+ GIP_Attachment *attachment,
+ const GIP_Header *header,
+ const Uint8 *bytes,
+ int num_bytes)
+{
+ // TODO
+ SDL_LogDebug(SDL_LOG_CATEGORY_INPUT, "GIP: Unimplemented Audio Control message");
+ return false;
+}
+
+static bool GIP_HandleCommandFirmware(
+ GIP_Attachment *attachment,
+ const GIP_Header *header,
+ const Uint8 *bytes,
+ int num_bytes)
+{
+ if (num_bytes < 1) {
+ return false;
+ }
+ if (bytes[0] == 1) {
+ Uint16 major, minor, build, rev;
+
+ if (num_bytes < 14) {
+ SDL_LogDebug(SDL_LOG_CATEGORY_INPUT, "GIP: Discarding too-short firmware message");
+
+ return false;
+ }
+ major = bytes[6];
+ major |= bytes[7] << 8;
+ minor = bytes[8];
+ minor |= bytes[9] << 8;
+ build = bytes[10];
+ build |= bytes[11] << 8;
+ rev = bytes[12];
+ rev |= bytes[13] << 8;
+
+ SDL_LogDebug(SDL_LOG_CATEGORY_INPUT, "GIP: Firmware version: %d.%d.%d rev %d", major, minor, build, rev);
+
+ attachment->firmware_major_version = major;
+ attachment->firmware_minor_version = minor;
+
+ if (attachment->device->device->vendor_id == USB_VENDOR_MICROSOFT &&
+ attachment->device->device->product_id == USB_PRODUCT_XBOX_ONE_ELITE_SERIES_2)
+ {
+ return GIP_EnableEliteButtons(attachment);
+ }
+ return true;
+ } else {
+ SDL_LogDebug(SDL_LOG_CATEGORY_INPUT, "GIP: Unimplemented Firmware message");
+
+ return false;
+ }
+}
+
+static bool GIP_HandleCommandRawReport(
+ GIP_Attachment *attachment,
+ const GIP_Header *header,
+ const Uint8 *bytes,
+ int num_bytes)
+{
+ Uint64 timestamp = SDL_GetTicksNS();
+ SDL_Joystick *joystick = NULL;
+
+ if (attachment->device->device->num_joysticks < 1) {
+ return true;
+ }
+
+ joystick = SDL_GetJoystickFromID(attachment->joystick);
+ if (!joystick) {
+ return true;
+ }
+
+ if (num_bytes < 17) {
+ SDL_LogDebug(SDL_LOG_CATEGORY_INPUT, "GIP: Discarding too-short raw report");
+ return false;
+ }
+
+ if ((attachment->features & GIP_FEATURE_ELITE_BUTTONS) && attachment->xbe_format == GIP_BTN_FMT_XBE2_RAW) {
+ if (bytes[15] & 3) {
+ SDL_SendJoystickButton(timestamp,
+ joystick,
+ attachment->paddle_idx,
+ 0);
+ SDL_SendJoystickButton(timestamp,
+ joystick,
+ attachment->paddle_idx + 1,
+ 0);
+ SDL_SendJoystickButton(timestamp,
+ joystick,
+ attachment->paddle_idx + 2,
+ 0);
+ SDL_SendJoystickButton(timestamp,
+ joystick,
+ attachment->paddle_idx + 3,
+ 0);
+ } else {
+ SDL_SendJoystickButton(timestamp,
+ joystick,
+ attachment->paddle_idx,
+ (bytes[GIP_BTN_OFFSET_XBE2] & 0x01) != 0);
+ SDL_SendJoystickButton(timestamp,
+ joystick,
+ attachment->paddle_idx + 1,
+ (bytes[GIP_BTN_OFFSET_XBE2] & 0x02) != 0);
+ SDL_SendJoystickButton(timestamp,
+ joystick,
+ attachment->paddle_idx + 2,
+ (bytes[GIP_BTN_OFFSET_XBE2] & 0x04) != 0);
+ SDL_SendJoystickButton(timestamp,
+ joystick,
+ attachment->paddle_idx + 3,
+ (bytes[GIP_BTN_OFFSET_XBE2] & 0x08) != 0);
+ }
+ }
+ return true;
+}
+
+static bool GIP_HandleCommandHidReport(
+ GIP_Attachment *attachment,
+ const GIP_Header *header,
+ const Uint8 *bytes,
+ int num_bytes)
+{
+ // Uint64 timestamp = SDL_GetTicksNS();
+ // SDL doesn't have HID descriptor parsing, so we have to hardcode for the Chatpad descriptor instead.
+ // I don't know of any other devices that emit HID reports, so this should be safe.
+ // if (attachment->attachment_type != GIP_TYPE_CHATPAD || !attachment->keyboard || num_bytes != 8) {
+ // SDL_LogDebug(SDL_LOG_CATEGORY_INPUT, "GIP: Unimplemented HID Report message");
+ // return false;
+ // }
+
+ // Uint8 modifiers = bytes[0];
+ // Uint8 changed_modifiers = modifiers ^ attachment->last_modifiers;
+ // if (changed_modifiers & 0x02) {
+ // if (modifiers & 0x02) {
+ // SDL_SendKeyboardKey(timestamp, attachment->keyboard, 0, SDL_SCANCODE_LSHIFT, true);
+ // } else {
+ // SDL_SendKeyboardKey(timestamp, attachment->keyboard, 0, SDL_SCANCODE_LSHIFT, false);
+ // }
+ // }
+ // The chatpad has several non-ASCII characters that it sends as Alt codes
+ // if (changed_modifiers & 0x04) {
+ // if (modifiers & 0x04) {
+ // attachment->altcode_digit = 0;
+ // attachment->altcode = 0;
+ // } else {
+ // if (attachment->altcode_digit == 4) {
+ // char utf8[4] = {0};
+ // // Some Alt codes don't match their Unicode codepoint for some reason
+ // switch (attachment->altcode) {
+ // case 128:
+ // SDL_UCS4ToUTF8(0x20AC, utf8);
+ // break;
+ // case 138:
+ // SDL_UCS4ToUTF8(0x0160, utf8);
+ // break;
+ // case 140:
+ // SDL_UCS4ToUTF8(0x0152, utf8);
+ // break;
+ // case 154:
+ // SDL_UCS4ToUTF8(0x0161, utf8);
+ // break;
+ // case 156:
+ // SDL_UCS4ToUTF8(0x0153, utf8);
+ // break;
+ // default:
+ // SDL_UCS4ToUTF8(attachment->altcode, utf8);
+ // break;
+ // }
+ // SDL_SendKeyboardText(utf8);
+ // }
+ // attachment->altcode_digit = -1;
+ // SDL_SendKeyboardKey(timestamp, attachment->keyboard, 0, SDL_SCANCODE_NUMLOCKCLEAR, true);
+ // SDL_SendKeyboardKey(timestamp, attachment->keyboard, 0, SDL_SCANCODE_NUMLOCKCLEAR, false);
+ // }
+ // }
+
+ // if (!bytes[2] && attachment->last_key) {
+ // if (attachment->last_key == SDL_SCANCODE_CAPSLOCK) {
+ // attachment->capslock = !attachment->capslock;
+ // }
+ // SDL_SendKeyboardKey(timestamp, attachment->keyboard, 0, attachment->last_key, false);
+ // if (!(attachment->last_modifiers & 0xfd)) {
+ // SDL_Keycode keycode = SDL_GetKeymapKeycode(NULL,
+ // attachment->last_key,
+ // ((attachment->last_modifiers & 0x02) || attachment->capslock) ? SDL_KMOD_SHIFT : 0);
+ // if (keycode && keycode < 0x80) {
+ // char text[2] = { (char)keycode };
+ // SDL_SendKeyboardText(text);
+ // }
+ // }
+ // attachment->last_key = 0;
+ // } else {
+ // SDL_SendKeyboardKey(timestamp, attachment->keyboard, 0, bytes[2], true);
+ // attachment->last_key = bytes[2];
+
+ // if ((modifiers & 0x04) && attachment->altcode_digit >= 0) {
+ // int digit = bytes[2] - SDL_SCANCODE_KP_1 + 1;
+ // if (digit < 1 || digit > 10) {
+ // attachment->altcode_digit = -1;
+ // } else {
+ // attachment->altcode_digit++;
+ // attachment->altcode *= 10;
+ // if (digit < 10) {
+ // attachment->altcode += digit;
+ // }
+ // }
+ // }
+ // }
+
+ // attachment->last_modifiers = modifiers;
+ return true;
+}
+
+static bool GIP_HandleCommandExtended(
+ GIP_Attachment *attachment,
+ const GIP_Header *header,
+ const Uint8 *bytes,
+ int num_bytes)
+{
+ char serial[33] = {0};
+
+ if (num_bytes < 2) {
+ return false;
+ }
+
+ switch (bytes[0]) {
+ case GIP_EXTCMD_GET_SERIAL_NUMBER:
+ if (bytes[1] != GIP_EXTENDED_STATUS_OK) {
+ return true;
+ }
+ if (header->flags & GIP_FLAG_ATTACHMENT_MASK) {
+ return true;
+ }
+ SDL_memcpy(serial, &bytes[2], SDL_min(sizeof(serial) - 1, num_bytes - 2));
+ HIDAPI_SetDeviceSerial(attachment->device->device, serial);
+ break;
+ default:
+ // TODO
+ SDL_LogDebug(SDL_LOG_CATEGORY_INPUT, "GIP: Extended message type %02x", bytes[0]);
+ return false;
+ }
+
+ return true;
+}
+
+static void GIP_HandleNavigationReport(
+ GIP_Attachment *attachment,
+ SDL_Joystick *joystick,
+ Uint64 timestamp,
+ const Uint8 *bytes,
+ int num_bytes)
+{
+ if (attachment->last_input[0] != bytes[0]) {
+ SDL_SendJoystickButton(timestamp, joystick, SDL_GAMEPAD_BUTTON_START, ((bytes[0] & 0x04) != 0));
+ SDL_SendJoystickButton(timestamp, joystick, SDL_GAMEPAD_BUTTON_BACK, ((bytes[0] & 0x08) != 0));
+ SDL_SendJoystickButton(timestamp, joystick, SDL_GAMEPAD_BUTTON_SOUTH, ((bytes[0] & 0x10) != 0));
+ SDL_SendJoystickButton(timestamp, joystick, SDL_GAMEPAD_BUTTON_EAST, ((bytes[0] & 0x20) != 0));
+ SDL_SendJoystickButton(timestamp, joystick, SDL_GAMEPAD_BUTTON_WEST, ((bytes[0] & 0x40) != 0));
+ SDL_SendJoystickButton(timestamp, joystick, SDL_GAMEPAD_BUTTON_NORTH, ((bytes[0] & 0x80) != 0));
+ }
+
+ if (attachment->last_input[1] != bytes[1]) {
+ Uint8 hat = 0;
+
+ if (bytes[1] & 0x01) {
+ hat |= SDL_HAT_UP;
+ }
+ if (bytes[1] & 0x02) {
+ hat |= SDL_HAT_DOWN;
+ }
+ if (bytes[1] & 0x04) {
+ hat |= SDL_HAT_LEFT;
+ }
+ if (bytes[1] & 0x08) {
+ hat |= SDL_HAT_RIGHT;
+ }
+ SDL_SendJoystickHat(timestamp, joystick, 0, hat);
+
+ if (attachment->attachment_type == GIP_TYPE_ARCADE_STICK) {
+ /* Previous */
+ SDL_SendJoystickButton(timestamp, joystick, SDL_GAMEPAD_BUTTON_RIGHT_SHOULDER, ((bytes[1] & 0x10) != 0));
+ /* Next */
+ SDL_SendJoystickButton(timestamp, joystick, SDL_GAMEPAD_BUTTON_LEFT_SHOULDER, ((bytes[1] & 0x20) != 0));
+ } else {
+ SDL_SendJoystickButton(timestamp, joystick, SDL_GAMEPAD_BUTTON_LEFT_SHOULDER, ((bytes[1] & 0x10) != 0));
+ SDL_SendJoystickButton(timestamp, joystick, SDL_GAMEPAD_BUTTON_RIGHT_SHOULDER, ((bytes[1] & 0x20) != 0));
+ }
+ }
+}
+
+static void GIP_HandleGamepadReport(
+ GIP_Attachment *attachment,
+ SDL_Joystick *joystick,
+ Uint64 timestamp,
+ const Uint8 *bytes,
+ int num_bytes)
+{
+ Sint16 axis;
+
+ SDL_SendJoystickButton(timestamp, joystick, SDL_GAMEPAD_BUTTON_LEFT_STICK, ((bytes[1] & 0x40) != 0));
+ SDL_SendJoystickButton(timestamp, joystick, SDL_GAMEPAD_BUTTON_RIGHT_STICK, ((bytes[1] & 0x80) != 0));
+
+ axis = bytes[2];
+ axis |= bytes[3] << 8;
+ axis = SDL_clamp(axis, 0, 1023);
+ axis = (axis - 512) * 64;
+ if (axis == 32704) {
+ axis = 32767;
+ }
+ SDL_SendJoystickAxis(timestamp, joystick, SDL_GAMEPAD_AXIS_LEFT_TRIGGER, axis);
+
+ axis = bytes[4];
+ axis |= bytes[5] << 8;
+ axis = SDL_clamp(axis, 0, 1023);
+ axis = (axis - 512) * 64;
+ if (axis == 32704) {
+ axis = 32767;
+ }
+ SDL_SendJoystickAxis(timestamp, joystick, SDL_GAMEPAD_AXIS_RIGHT_TRIGGER, axis);
+
+ axis = bytes[6];
+ axis |= bytes[7] << 8;
+ SDL_SendJoystickAxis(timestamp, joystick, SDL_GAMEPAD_AXIS_LEFTX, axis);
+ axis = bytes[8];
+ axis |= bytes[9] << 8;
+ SDL_SendJoystickAxis(timestamp, joystick, SDL_GAMEPAD_AXIS_LEFTY, ~axis);
+ axis = bytes[10];
+ axis |= bytes[11] << 8;
+ SDL_SendJoystickAxis(timestamp, joystick, SDL_GAMEPAD_AXIS_RIGHTX, axis);
+ axis = bytes[12];
+ axis |= bytes[13] << 8;
+ SDL_SendJoystickAxis(timestamp, joystick, SDL_GAMEPAD_AXIS_RIGHTY, ~axis);
+}
+
+static void GIP_HandleGuitarReport(
+ GIP_Attachment *attachment,
+ SDL_Joystick *joystick,
+ Uint64 timestamp,
+ const Uint8 *bytes,
+ int num_bytes)
+{
+ static uint16_t s_GuitarButtons[] = {
+ 0x0010, // SDL_GAMEPAD_BUTTON_SOUTH
+ 0x0020, // SDL_GAMEPAD_BUTTON_EAST
+ 0x0040, // SDL_GAMEPAD_BUTTON_WEST
+ 0x0080, // SDL_GAMEPAD_BUTTON_NORTH
+ 0x0008, // SDL_GAMEPAD_BUTTON_BACK
+ 0, // The guide button is not available
+ 0x0004, // SDL_GAMEPAD_BUTTON_START
+ 0, // right joystick click unavailable
+ 0x4000, // SDL_GAMEPAD_BUTTON_RIGHT_STICK
+ 0x1000, // SDL_GAMEPAD_BUTTON_LEFT_SHOULDER
+ 0, // right shoulder unavailable
+ };
+ Uint8 btnidx = 0, hat = 0;
+ uint16_t buttons = bytes[0] | bytes[1] << 8;
+ if (num_bytes >= 10) {
+ for (btnidx = 0; btnidx < SDL_arraysize(s_GuitarButtons); ++btnidx) {
+ uint16_t button_mask = s_GuitarButtons[btnidx];
+ if (!button_mask) {
+ continue;
+ }
+ bool down = ((buttons & button_mask) != 0);
+ SDL_SendJoystickButton(timestamp, joystick, btnidx, down);
+ }
+ if (buttons & 0x0100) {
+ hat |= SDL_HAT_UP;
+ }
+ if (buttons & 0x0200) {
+ hat |= SDL_HAT_DOWN;
+ }
+ if (buttons & 0x0400) {
+ hat |= SDL_HAT_LEFT;
+ }
+ if (buttons & 0x0800) {
+ hat |= SDL_HAT_RIGHT;
+ }
+ SDL_SendJoystickHat(timestamp, joystick, 0, hat);
+ SDL_SendJoystickAxis(timestamp, joystick, SDL_GAMEPAD_AXIS_RIGHTX, (bytes[3] * 257) - 32768);
+ // PS3 RB guitars had tilt on right shoulder
+ SDL_SendJoystickButton(timestamp, joystick, SDL_GAMEPAD_BUTTON_RIGHT_SHOULDER, bytes[2] >= 0xD0);
+ // PS3 RB guitars send L2 when using solo buttons
+ SDL_SendJoystickAxis(timestamp, joystick, SDL_GAMEPAD_AXIS_LEFT_TRIGGER, (bytes[6]) ? 32767 : -32768);
+ // Align pickup selector mappings with PS3 instruments
+ static const Sint16 effects_mappings[] = {-26880, -13568, -1792, 11008, 24576};
+ SDL_SendJoystickAxis(timestamp, joystick, SDL_GAMEPAD_AXIS_RIGHTY, effects_mappings[bytes[4] >> 4]);
+ }
+}
+
+static void GIP_HandleDrumKitReport(
+ GIP_Attachment *attachment,
+ SDL_Joystick *joystick,
+ Uint64 timestamp,
+ const Uint8 *bytes,
+ int num_bytes)
+{
+ Uint8 hat = 0;
+ uint16_t buttons = bytes[0] | bytes[1] << 8;
+ if (num_bytes >= 6) {
+ if ((buttons & 0x0100) || (bytes[4] & 0xf0)) {
+ hat |= SDL_HAT_UP;
+ }
+ if ((buttons & 0x0200) || (bytes[4] & 0x0f)) {
+ hat |= SDL_HAT_DOWN;
+ }
+ if (buttons & 0x0400) {
+ hat |= SDL_HAT_LEFT;
+ }
+ if (buttons & 0x0800) {
+ hat |= SDL_HAT_RIGHT;
+ }
+ SDL_SendJoystickHat(timestamp, joystick, 0, hat);
+ // The rest of the instruments are mapped to PS3 style inputs
+ // The PS3 used flags for dictating if a pad or a cymbal was hit, so we emulate that here
+ SDL_SendJoystickButton(timestamp, joystick, SDL_GAMEPAD_BUTTON_BACK, (buttons & 0x0008));
+ SDL_SendJoystickButton(timestamp, joystick, SDL_GAMEPAD_BUTTON_START, (buttons & 0x0004));
+ SDL_SendJoystickButton(timestamp, joystick, SDL_GAMEPAD_BUTTON_LEFT_SHOULDER, (buttons & 0x1000));
+ SDL_SendJoystickButton(timestamp, joystick, SDL_GAMEPAD_BUTTON_RIGHT_SHOULDER, (buttons & 0x2000));
+ SDL_SendJoystickButton(timestamp, joystick, SDL_GAMEPAD_BUTTON_SOUTH, (bytes[3] & 0x0f) || (bytes[5] & 0xf0) || (buttons & 0x0010));
+ SDL_SendJoystickButton(timestamp, joystick, SDL_GAMEPAD_BUTTON_EAST, (bytes[2] & 0xf0) || (buttons & 0x0020));
+ SDL_SendJoystickButton(timestamp, joystick, SDL_GAMEPAD_BUTTON_WEST, (bytes[3] & 0xf0) || (bytes[4] & 0x0f) || (buttons & 0x0040));
+ SDL_SendJoystickButton(timestamp, joystick, SDL_GAMEPAD_BUTTON_NORTH, (bytes[2] & 0x0f) || (bytes[4] & 0xf0) || (buttons & 0x0080));
+ SDL_SendJoystickButton(timestamp, joystick, SDL_GAMEPAD_BUTTON_LEFT_STICK, bytes[2] || bytes[3]);
+ SDL_SendJoystickButton(timestamp, joystick, SDL_GAMEPAD_BUTTON_RIGHT_STICK, bytes[4] || bytes[5]);
+ }
+}
+
+static void GIP_HandleArcadeStickReport(
+ GIP_Attachment *attachment,
+ SDL_Joystick *joystick,
+ Uint64 timestamp,
+ const Uint8 *bytes,
+ int num_bytes)
+{
+ Sint16 axis;
+ axis = bytes[2];
+ axis |= bytes[3] << 8;
+ axis = SDL_clamp(axis, 0, 1023);
+ axis = (axis - 512) * 64;
+ if (axis == 32704) {
+ axis = 32767;
+ }
+ SDL_SendJoystickAxis(timestamp, joystick, SDL_GAMEPAD_AXIS_LEFT_TRIGGER, axis);
+
+ axis = bytes[4];
+ axis |= bytes[5] << 8;
+ axis = SDL_clamp(axis, 0, 1023);
+ axis = (axis - 512) * 64;
+ if (axis == 32704) {
+ axis = 32767;
+ }
+ SDL_SendJoystickAxis(timestamp, joystick, SDL_GAMEPAD_AXIS_RIGHT_TRIGGER, axis);
+
+ if (num_bytes >= 19) {
+ /* Extra button 6 */
+ SDL_SendJoystickAxis(timestamp, joystick, SDL_GAMEPAD_AXIS_RIGHT_TRIGGER, (bytes[18] & 0x40) ? 32767 : -32768);
+ /* Extra button 7 */
+ SDL_SendJoystickAxis(timestamp, joystick, SDL_GAMEPAD_AXIS_LEFT_TRIGGER, (bytes[18] & 0x80) ? 32767 : -32768);
+ }
+}
+
+static void GIP_HandleFlightStickReport(
+ GIP_Attachment *attachment,
+ SDL_Joystick *joystick,
+ Uint64 timestamp,
+ const Uint8 *bytes,
+ int num_bytes)
+{
+ Sint16 axis;
+ int i;
+
+ if (num_bytes < 19) {
+ return;
+ }
+
+ if (attachment->last_input[2] != bytes[2]) {
+ /* Fire 1 and 2 */
+ SDL_SendJoystickButton(timestamp, joystick, SDL_GAMEPAD_BUTTON_LEFT_STICK, ((bytes[2] & 0x01) != 0));
+ SDL_SendJoystickButton(timestamp, joystick, SDL_GAMEPAD_BUTTON_RIGHT_STICK, ((bytes[2] & 0x02) != 0));
+ }
+ for (i = 0; i < attachment->extra_buttons;) {
+ if (attachment->last_input[i / 8 + 3] != bytes[i / 8 + 3]) {
+ for (; i < attachment->extra_buttons; i++) {
+ SDL_SendJoystickButton(timestamp,
+ joystick,
+ (Uint8) (attachment->extra_button_idx + i),
+ ((bytes[i / 8 + 3] & (1u << i)) != 0));
+ }
+ } else {
+ i += 8;
+ }
+ }
+
+ /* Roll, pitch and yaw are signed. Throttle and any extra axes are unsigned. All values are full-range. */
+ axis = bytes[11];
+ axis |= bytes[12] << 8;
+ SDL_SendJoystickAxis(timestamp, joystick, SDL_GAMEPAD_AXIS_LEFTX, axis);
+
+ axis = bytes[13];
+ axis |= bytes[14] << 8;
+ SDL_SendJoystickAxis(timestamp, joystick, SDL_GAMEPAD_AXIS_LEFTY, axis);
+
+ axis = bytes[15];
+ axis |= bytes[16] << 8;
+ SDL_SendJoystickAxis(timestamp, joystick, SDL_GAMEPAD_AXIS_RIGHTX, axis);
+
+ /* There are no more signed values, so skip RIGHTY */
+
+ axis = (bytes[18] << 8) - 0x8000;
+ axis |= bytes[17];
+ SDL_SendJoystickAxis(timestamp, joystick, SDL_GAMEPAD_AXIS_LEFT_TRIGGER, axis);
+
+ for (i = 0; i < attachment->extra_axes; i++) {
+ if (20 + i * 2 >= num_bytes) {
+ return;
+ }
+ axis = (bytes[20 + i * 2] << 8) - 0x8000;
+ axis |= bytes[19 + i * 2];
+ SDL_SendJoystickAxis(timestamp, joystick, (Uint8) (SDL_GAMEPAD_AXIS_RIGHT_TRIGGER + i), axis);
+ }
+}
+
+static bool GIP_HandleLLInputReport(
+ GIP_Attachment *attachment,
+ const GIP_Header *header,
+ const Uint8 *bytes,
+ int num_bytes)
+{
+ Uint64 timestamp = SDL_GetTicksNS();
+ SDL_Joystick *joystick = NULL;
+
+ if (attachment->device->device->num_joysticks < 1) {
+ GIP_EnsureMetadata(attachment);
+ if (attachment->got_metadata != GIP_METADATA_GOT && attachment->got_metadata != GIP_METADATA_FAKED) {
+ return true;
+ }
+ }
+
+ joystick = SDL_GetJoystickFromID(attachment->joystick);
+ if (!joystick) {
+ return false;
+ }
+
+ if (attachment->device_state != GIP_STATE_START) {
+ SDL_LogDebug(SDL_LOG_CATEGORY_INPUT, "GIP: Discarding early input report");
+ attachment->device_state = GIP_STATE_START;
+ return true;
+ }
+
+ if (num_bytes < 6) {
+ SDL_LogDebug(SDL_LOG_CATEGORY_INPUT, "GIP: Discarding too-short input report");
+ return false;
+ }
+
+ GIP_HandleNavigationReport(attachment, joystick, timestamp, bytes, num_bytes);
+
+ switch (attachment->attachment_type) {
+ case GIP_TYPE_GAMEPAD:
+ default:
+ GIP_HandleGamepadReport(attachment, joystick, timestamp, bytes, num_bytes);
+ break;
+ case GIP_TYPE_ARCADE_STICK:
+ GIP_HandleArcadeStickReport(attachment, joystick, timestamp, bytes, num_bytes);
+ break;
+ case GIP_TYPE_FLIGHT_STICK:
+ GIP_HandleFlightStickReport(attachment, joystick, timestamp, bytes, num_bytes);
+ break;
+ case GIP_TYPE_GUITAR:
+ GIP_HandleGuitarReport(attachment, joystick, timestamp, bytes, num_bytes);
+ break;
+ case GIP_TYPE_DRUM_KIT:
+ GIP_HandleDrumKitReport(attachment, joystick, timestamp, bytes, num_bytes);
+ break;
+ }
+
+ if (attachment->features & GIP_FEATURE_ELITE_BUTTONS) {
+ bool clear = false;
+ if (attachment->xbe_format == GIP_BTN_FMT_XBE1 &&
+ num_bytes > GIP_BTN_OFFSET_XBE1 &&
+ attachment->last_input[GIP_BTN_OFFSET_XBE1] != bytes[GIP_BTN_OFFSET_XBE1] &&
+ (bytes[GIP_BTN_OFFSET_XBE1] & 0x10))
+ {
+ SDL_SendJoystickButton(timestamp,
+ joystick,
+ attachment->paddle_idx,
+ (bytes[GIP_BTN_OFFSET_XBE1] & 0x02) != 0);
+ SDL_SendJoystickButton(timestamp,
+ joystick,
+ attachment->paddle_idx + 1,
+ (bytes[GIP_BTN_OFFSET_XBE1] & 0x08) != 0);
+ SDL_SendJoystickButton(timestamp,
+ joystick,
+ attachment->paddle_idx + 2,
+ (bytes[GIP_BTN_OFFSET_XBE1] & 0x01) != 0);
+ SDL_SendJoystickButton(timestamp,
+ joystick,
+ attachment->paddle_idx + 3,
+ (bytes[GIP_BTN_OFFSET_XBE1] & 0x04) != 0);
+ } else if ((attachment->xbe_format == GIP_BTN_FMT_XBE2_4 ||
+ attachment->xbe_format == GIP_BTN_FMT_XBE2_5) &&
+ num_bytes > GIP_BTN_OFFSET_XBE2)
+ {
+ int profile_offset = attachment->xbe_format == GIP_BTN_FMT_XBE2_4 ? 15 : 20;
+ if (attachment->last_input[GIP_BTN_OFFSET_XBE2] != bytes[GIP_BTN_OFFSET_XBE2] ||
+ attachment->last_input[profile_offset] != bytes[profile_offset])
+ {
+ if (bytes[profile_offset] & 3) {
+ clear = true;
+ } else {
+ SDL_SendJoystickButton(timestamp,
+ joystick,
+ attachment->paddle_idx,
+ (bytes[GIP_BTN_OFFSET_XBE2] & 0x01) != 0);
+ SDL_SendJoystickButton(timestamp,
+ joystick,
+ attachment->paddle_idx + 1,
+ (bytes[GIP_BTN_OFFSET_XBE2] & 0x02) != 0);
+ SDL_SendJoystickButton(timestamp,
+ joystick,
+ attachment->paddle_idx + 2,
+ (bytes[GIP_BTN_OFFSET_XBE2] & 0x04) != 0);
+ SDL_SendJoystickButton(timestamp,
+ joystick,
+ attachment->paddle_idx + 3,
+ (bytes[GIP_BTN_OFFSET_XBE2] & 0x08) != 0);
+ }
+ }
+ } else {
+ clear = true;
+ }
+ if (clear) {
+ SDL_SendJoystickButton(timestamp,
+ joystick,
+ attachment->paddle_idx,
+ 0);
+ SDL_SendJoystickButton(timestamp,
+ joystick,
+ attachment->paddle_idx + 1,
+ 0);
+ SDL_SendJoystickButton(timestamp,
+ joystick,
+ attachment->paddle_idx + 2,
+ 0);
+ SDL_SendJoystickButton(timestamp,
+ joystick,
+ attachment->paddle_idx + 3,
+ 0);
+ }
+ }
+ // Input reports are at a minimum 5 bytes, and the console function map is always 18 bytes
+ if ((attachment->features & GIP_FEATURE_CONSOLE_FUNCTION_MAP) && num_bytes >= 23) {
+ int function_map_offset = -1;
+ if (attachment->features & GIP_FEATURE_DYNAMIC_LATENCY_INPUT) {
+ /* The dynamic latency input bytes are after the console function map */
+ if (num_bytes >= 40) {
+ function_map_offset = num_bytes - 26;
+ }
+ } else {
+ function_map_offset = num_bytes - 18;
+ }
+ if (function_map_offset >= 5) {
+ if (attachment->last_input[function_map_offset] != bytes[function_map_offset]) {
+ SDL_SendJoystickButton(timestamp,
+ joystick,
+ attachment->share_button_idx,
+ (bytes[function_map_offset] & 0x01) != 0);
+ }
+ }
+ }
+
+ SDL_memcpy(attachment->last_input, bytes, SDL_min(num_bytes, sizeof(attachment->last_input)));
+
+ return true;
+}
+
+static bool GIP_HandleLLStaticConfiguration(
+ GIP_Attachment *attachment,
+ const GIP_Header *header,
+ const Uint8 *bytes,
+ int num_bytes)
+{
+ // TODO
+ SDL_LogDebug(SDL_LOG_CATEGORY_INPUT, "GIP: Unimplemented Static Configuration message");
+ return false;
+}
+
+static bool GIP_HandleLLButtonInfoReport(
+ GIP_Attachment *attachment,
+ const GIP_Header *header,
+ const Uint8 *bytes,
+ int num_bytes)
+{
+ // TODO
+ SDL_LogDebug(SDL_LOG_CATEGORY_INPUT, "GIP: Unimplemented Button Info Report message");
+ return false;
+}
+
+static bool GIP_HandleLLOverflowInputReport(
+ GIP_Attachment *attachment,
+ const GIP_Header *header,
+ const Uint8 *bytes,
+ int num_bytes)
+{
+ // TODO
+ SDL_LogDebug(SDL_LOG_CATEGORY_INPUT, "GIP: Unimplemented Overflow Input Report message");
+ return false;
+}
+
+static bool GIP_HandleAudioData(
+ GIP_Attachment *attachment,
+ const GIP_Header *header,
+ const Uint8 *bytes,
+ int num_bytes)
+{
+ // TODO
+ SDL_LogDebug(SDL_LOG_CATEGORY_INPUT, "GIP: Unimplemented Audio Data message");
+ return false;
+}
+
+static bool GIP_HandleSystemMessage(
+ GIP_Attachment *attachment,
+ const GIP_Header *header,
+ const Uint8 *bytes,
+ int num_bytes)
+{
+ if (attachment->attachment_index > 0 && attachment->attachment_type == GIP_TYPE_UNKNOWN) {
+ // XXX If we reattach to a controller after it's been initialized, it might have
+ // attachments we don't know about. Try to figure out what this one is.
+ if (header->message_type == GIP_CMD_HID_REPORT && num_bytes == 8) {
+ // if (!attachment->keyboard) {
+ // attachment->keyboard = (SDL_KeyboardID)(uintptr_t) attachment;
+ // SDL_AddKeyboard(attachment->keyboard, "Xbox One Chatpad");
+ // }
+ attachment->attachment_type = GIP_TYPE_CHATPAD;
+ attachment->metadata.device.in_system_messages[0] |= (1u << GIP_CMD_HID_REPORT);
+ }
+ }
+ if (!GIP_SupportsSystemMessage(attachment, header->message_type, true)) {
+ SDL_LogWarn(SDL_LOG_CATEGORY_INPUT,
+ "GIP: Received claimed-unsupported system message type %02x",
+ header->message_type);
+ return false;
+ }
+ switch (header->message_type) {
+ case GIP_CMD_PROTO_CONTROL:
+ return GIP_HandleCommandProtocolControl(attachment, header, bytes, num_bytes);
+ case GIP_CMD_HELLO_DEVICE:
+ return GIP_HandleCommandHelloDevice(attachment, header, bytes, num_bytes);
+ case GIP_CMD_STATUS_DEVICE:
+ return GIP_HandleCommandStatusDevice(attachment, header, bytes, num_bytes);
+ case GIP_CMD_METADATA:
+ return GIP_HandleCommandMetadataRespose(attachment, header, bytes, num_bytes);
+ case GIP_CMD_SECURITY:
+ return GIP_HandleCommandSecurity(attachment, header, bytes, num_bytes);
+ case GIP_CMD_GUIDE_BUTTON:
+ return GIP_HandleCommandGuideButtonStatus(attachment, header, bytes, num_bytes);
+ case GIP_CMD_AUDIO_CONTROL:
+ return GIP_HandleCommandAudioControl(attachment, header, bytes, num_bytes);
+ case GIP_CMD_FIRMWARE:
+ return GIP_HandleCommandFirmware(attachment, header, bytes, num_bytes);
+ case GIP_CMD_HID_REPORT:
+ return GIP_HandleCommandHidReport(attachment, header, bytes, num_bytes);
+ case GIP_CMD_EXTENDED:
+ return GIP_HandleCommandExtended(attachment, header, bytes, num_bytes);
+ case GIP_AUDIO_DATA:
+ return GIP_HandleAudioData(attachment, header, bytes, num_bytes);
+ default:
+ SDL_LogWarn(SDL_LOG_CATEGORY_INPUT,
+ "GIP: Received unknown system message type %02x",
+ header->message_type);
+ return false;
+ }
+}
+
+static GIP_Attachment *GIP_EnsureAttachment(GIP_Device *device, Uint8 attachment_index)
+{
+ GIP_Attachment *attachment = device->attachments[attachment_index];
+ if (!attachment) {
+ attachment = SDL_calloc(1, sizeof(*attachment));
+ attachment->attachment_index = attachment_index;
+ if (attachment_index > 0) {
+ attachment->attachment_type = GIP_TYPE_UNKNOWN;
+ }
+ attachment->device = device;
+ attachment->metadata.device.in_system_messages[0] = GIP_DEFAULT_IN_SYSTEM_MESSAGES;
+ attachment->metadata.device.out_system_messages[0] = GIP_DEFAULT_OUT_SYSTEM_MESSAGES;
+ device->attachments[attachment_index] = attachment;
+ }
+ return attachment;
+}
+
+static bool GIP_HandleMessage(
+ GIP_Attachment *attachment,
+ const GIP_Header *header,
+ const Uint8 *bytes,
+ int num_bytes)
+{
+ if (header->flags & GIP_FLAG_SYSTEM) {
+ return GIP_HandleSystemMessage(attachment, header, bytes, num_bytes);
+ } else {
+ switch (header->message_type) {
+ case GIP_CMD_RAW_REPORT:
+ if (attachment->features & GIP_FEATURE_ELITE_BUTTONS) {
+ return GIP_HandleCommandRawReport(attachment, header, bytes, num_bytes);
+ }
+ break;
+ case GIP_LL_INPUT_REPORT:
+ return GIP_HandleLLInputReport(attachment, header, bytes, num_bytes);
+ case GIP_LL_STATIC_CONFIGURATION:
+ return GIP_HandleLLStaticConfiguration(attachment, header, bytes, num_bytes);
+ case GIP_LL_BUTTON_INFO_REPORT:
+ return GIP_HandleLLButtonInfoReport(attachment, header, bytes, num_bytes);
+ case GIP_LL_OVERFLOW_INPUT_REPORT:
+ return GIP_HandleLLOverflowInputReport(attachment, header, bytes, num_bytes);
+ }
+ }
+ SDL_LogWarn(SDL_LOG_CATEGORY_INPUT,
+ "GIP: Received unknown vendor message type %02x",
+ header->message_type);
+ return false;
+}
+
+static void GIP_ReceivePacket(GIP_Device *device, const Uint8 *bytes, int num_bytes)
+{
+ GIP_Header header;
+ int offset = 3;
+ bool ok = true;
+ Uint64 fragment_offset = 0;
+ Uint16 bytes_remaining = 0;
+ bool is_fragment;
+ Uint8 attachment_index;
+ GIP_Attachment *attachment;
+
+ if (num_bytes < 5) {
+ return;
+ }
+
+ header.message_type = bytes[0];
+ header.flags = bytes[1];
+ header.sequence_id = bytes[2];
+ offset += GIP_DecodeLength(&header.length, &bytes[offset], num_bytes - offset);
+
+ is_fragment = header.flags & GIP_FLAG_FRAGMENT;
+ attachment_index = header.flags & GIP_FLAG_ATTACHMENT_MASK;
+ attachment = GIP_EnsureAttachment(device, attachment_index);
+
+#ifdef DEBUG_XBOX_PROTOCOL
+ HIDAPI_DumpPacket("GIP received message: size = %d", bytes, num_bytes);
+#endif
+
+ /* Handle coalescing fragmented messages */
+ if (is_fragment) {
+ if (header.flags & GIP_FLAG_INIT_FRAG) {
+ Uint64 total_length;
+ if (attachment->fragment_message) {
+ /*
+ * Reset fragment buffer if we get a new initial
+ * fragment before finishing the last message.
+ * TODO: Is this the correct behavior?
+ */
+ if (attachment->fragment_data) {
+ SDL_free(attachment->fragment_data);
+ attachment->fragment_data = NULL;
+ }
+ }
+ offset += GIP_DecodeLength(&total_length, &bytes[offset], num_bytes - offset);
+ if (total_length > MAX_MESSAGE_LENGTH) {
+ return;
+ }
+ attachment->total_length = (Uint16) total_length;
+ attachment->fragment_message = header.message_type;
+ if (header.length > num_bytes - offset) {
+ SDL_LogWarn(SDL_LOG_CATEGORY_INPUT,
+ "GIP: Received fragment that claims to be %" SDL_PRIu64 " bytes, expected %i",
+ header.length, num_bytes - offset);
+ return;
+ }
+ if (header.length > total_length) {
+ SDL_LogWarn(SDL_LOG_CATEGORY_INPUT,
+ "GIP: Received too long fragment, %" SDL_PRIu64 " bytes, exceeds %d",
+ header.length, attachment->total_length);
+ return;
+ }
+ attachment->fragment_data = SDL_malloc(attachment->total_length);
+ SDL_memcpy(attachment->fragment_data, &bytes[offset], (size_t) header.length);
+ fragment_offset = header.length;
+ attachment->fragment_offset = (Uint32) fragment_offset;
+ bytes_remaining = (Uint16) (attachment->total_length - fragment_offset);
+ } else {
+ if (header.message_type != attachment->fragment_message) {
+ SDL_LogWarn(SDL_LOG_CATEGORY_INPUT,
+ "GIP: Received out of sequence message type %02x, expected %02x",
+ header.message_type, attachment->fragment_message);
+ GIP_FragmentFailed(attachment, &header);
+ return;
+ }
+
+ offset += GIP_DecodeLength(&fragment_offset, &bytes[offset], num_bytes - offset);
+ if (fragment_offset != attachment->fragment_offset) {
+ SDL_LogWarn(SDL_LOG_CATEGORY_INPUT,
+ "GIP: Received out of sequence fragment, (claimed %" SDL_PRIu64 ", expected %d)",
+ fragment_offset, attachment->fragment_offset);
+ GIP_Acknowledge(device,
+ &header,
+ attachment->fragment_offset,
+ (Uint16) (attachment->total_length - attachment->fragment_offset));
+ return;
+ } else if (fragment_offset + header.length > attachment->total_length) {
+ SDL_LogWarn(SDL_LOG_CATEGORY_INPUT,
+ "GIP: Received too long fragment, %" SDL_PRIu64 " exceeds %d",
+ fragment_offset + header.length, attachment->total_length);
+ GIP_FragmentFailed(attachment, &header);
+ return;
+ }
+
+ bytes_remaining = attachment->total_length - (Uint16) (fragment_offset + header.length);
+ if (header.length != 0) {
+ SDL_memcpy(&attachment->fragment_data[fragment_offset], &bytes[offset], (size_t) header.length);
+ } else {
+ ok = GIP_HandleMessage(attachment, &header, attachment->fragment_data, attachment->total_length);
+ if (attachment->fragment_data) {
+ SDL_free(attachment->fragment_data);
+ attachment->fragment_data = NULL;
+ }
+ attachment->fragment_message = 0;
+ }
+ fragment_offset += header.length;
+ attachment->fragment_offset = (Uint16) fragment_offset;
+ }
+ attachment->fragment_timer = SDL_GetTicks();
+ } else if (header.length + offset > num_bytes) {
+ SDL_LogWarn(SDL_LOG_CATEGORY_INPUT,
+ "GIP: Received message with erroneous length (claimed %" SDL_PRIu64 ", actual %d), discarding",
+ header.length + offset, num_bytes);
+ return;
+ } else {
+ num_bytes -= offset;
+ bytes += offset;
+ fragment_offset = header.length;
+ ok = GIP_HandleMessage(attachment, &header, bytes, num_bytes);
+ }
+
+ if (ok && (header.flags & GIP_FLAG_ACME)) {
+ GIP_Acknowledge(device, &header, (Uint32) fragment_offset, bytes_remaining);
+ }
+}
+
+static void HIDAPI_DriverGIP_RumbleSent(void *userdata)
+{
+ GIP_Attachment *ctx = (GIP_Attachment *)userdata;
+ ctx->rumble_time = SDL_GetTicks();
+}
+
+static bool HIDAPI_DriverGIP_UpdateRumble(GIP_Attachment *attachment)
+{
+ GIP_DirectMotor motor;
+
+ if (!(attachment->features & GIP_FEATURE_MOTOR_CONTROL)) {
+ return true;
+ }
+
+ if (attachment->rumble_state == GIP_RUMBLE_STATE_QUEUED && attachment->rumble_time) {
+ attachment->rumble_state = GIP_RUMBLE_STATE_BUSY;
+ }
+
+ if (attachment->rumble_state == GIP_RUMBLE_STATE_BUSY) {
+ const int RUMBLE_BUSY_TIME_MS = 10;
+ if (SDL_GetTicks() >= (attachment->rumble_time + RUMBLE_BUSY_TIME_MS)) {
+ attachment->rumble_time = 0;
+ attachment->rumble_state = GIP_RUMBLE_STATE_IDLE;
+ }
+ }
+
+ if (!attachment->rumble_pending) {
+ return true;
+ }
+
+ if (attachment->rumble_state != GIP_RUMBLE_STATE_IDLE) {
+ return true;
+ }
+
+ // We're no longer pending, even if we fail to send the rumble below
+ attachment->rumble_pending = false;
+
+ motor.motor_bitmap = GIP_MOTOR_ALL;
+ motor.left_impulse_level = attachment->left_impulse_level;
+ motor.right_impulse_level = attachment->right_impulse_level;
+ motor.left_vibration_level = attachment->left_vibration_level;
+ motor.right_vibration_level = attachment->right_vibration_level;
+ motor.duration = SDL_RUMBLE_RESEND_MS / 10 + 5; // Add a 50ms leniency, just in case
+ motor.delay = 0;
+ motor.repeat = 0;
+
+ Uint8 message[9] = {0};
+ SDL_memcpy(&message[1], &motor, sizeof(motor));
+ if (!GIP_SendRawMessage(attachment->device,
+ GIP_CMD_DIRECT_MOTOR,
+ attachment->attachment_index,
+ GIP_SequenceNext(attachment, GIP_CMD_DIRECT_MOTOR, false),
+ message,
+ sizeof(message),
+ true,
+ HIDAPI_DriverGIP_RumbleSent,
+ attachment))
+ {
+ return SDL_SetError("Couldn't send rumble packet");
+ }
+
+ attachment->rumble_state = GIP_RUMBLE_STATE_QUEUED;
+
+ return true;
+}
+
+static void HIDAPI_DriverGIP_RegisterHints(SDL_HintCallback callback, void *userdata)
+{
+ SDL_AddHintCallback(SDL_HINT_JOYSTICK_HIDAPI_GIP, callback, userdata);
+ SDL_AddHintCallback(SDL_HINT_JOYSTICK_HIDAPI_GIP_RESET_FOR_METADATA, callback, userdata);
+}
+
+static void HIDAPI_DriverGIP_UnregisterHints(SDL_HintCallback callback, void *userdata)
+{
+ SDL_RemoveHintCallback(SDL_HINT_JOYSTICK_HIDAPI_GIP, callback, userdata);
+ SDL_RemoveHintCallback(SDL_HINT_JOYSTICK_HIDAPI_GIP_RESET_FOR_METADATA, callback, userdata);
+}
+
+static bool HIDAPI_DriverGIP_IsEnabled(void)
+{
+ return SDL_GetHintBoolean(SDL_HINT_JOYSTICK_HIDAPI_GIP,
+ SDL_GetHintBoolean(SDL_HINT_JOYSTICK_HIDAPI_XBOX_ONE,
+ SDL_GetHintBoolean(SDL_HINT_JOYSTICK_HIDAPI_XBOX,
+ SDL_GetHintBoolean(SDL_HINT_JOYSTICK_HIDAPI, SDL_HIDAPI_DEFAULT))));
+}
+
+static bool HIDAPI_DriverGIP_IsSupportedDevice(SDL_HIDAPI_Device *device, const char *name, SDL_GamepadType type, Uint16 vendor_id, Uint16 product_id, Uint16 version, int interface_number, int interface_class, int interface_subclass, int interface_protocol)
+{
+ // Xbox One controllers speak HID over bluetooth instead of GIP
+ if (device && device->is_bluetooth) {
+ return false;
+ }
+#if defined(SDL_PLATFORM_MACOS) && defined(SDL_JOYSTICK_MFI)
+ if (!SDL_IsJoystickBluetoothXboxOne(vendor_id, product_id)) {
+ // On macOS we get a shortened version of the real report and
+ // you can't write output reports for wired controllers, so
+ // we'll just use the GCController support instead.
+ return false;
+ }
+#endif
+ return (type == SDL_GAMEPAD_TYPE_XBOXONE);
+}
+
+static bool HIDAPI_DriverGIP_InitDevice(SDL_HIDAPI_Device *device)
+{
+ GIP_Device *ctx;
+ GIP_Attachment *attachment;
+
+ ctx = (GIP_Device *)SDL_calloc(1, sizeof(*ctx));
+ if (!ctx) {
+ return false;
+ }
+ ctx->device = device;
+ ctx->reset_for_metadata = SDL_GetHintBoolean(SDL_HINT_JOYSTICK_HIDAPI_GIP_RESET_FOR_METADATA, false);
+
+ attachment = GIP_EnsureAttachment(ctx, 0);
+ GIP_HandleQuirks(attachment);
+
+ if (attachment->quirks & GIP_QUIRK_NO_HELLO) {
+ ctx->got_hello = true;
+ GIP_EnsureMetadata(attachment);
+ } else {
+ ctx->hello_deadline = SDL_GetTicks() + GIP_HELLO_TIMEOUT;
+ }
+
+ device->context = ctx;
+ device->type = SDL_GAMEPAD_TYPE_XBOXONE;
+
+ return true;
+}
+
+static int HIDAPI_DriverGIP_GetDevicePlayerIndex(SDL_HIDAPI_Device *device, SDL_JoystickID instance_id)
+{
+ return -1;
+}
+
+static void HIDAPI_DriverGIP_SetDevicePlayerIndex(SDL_HIDAPI_Device *device, SDL_JoystickID instance_id, int player_index)
+{
+}
+
+static GIP_Attachment * HIDAPI_DriverGIP_FindAttachment(SDL_HIDAPI_Device *device, SDL_Joystick *joystick)
+{
+ GIP_Device *ctx = (GIP_Device *)device->context;
+ int i;
+
+ SDL_AssertJoysticksLocked();
+
+ for (i = 0; i < MAX_ATTACHMENTS; i++) {
+ if (ctx->attachments[i] && ctx->attachments[i]->joystick == joystick->instance_id) {
+ return ctx->attachments[i];
+ }
+ }
+ return NULL;
+}
+
+static bool HIDAPI_DriverGIP_OpenJoystick(SDL_HIDAPI_Device *device, SDL_Joystick *joystick)
+{
+ GIP_Attachment *attachment = HIDAPI_DriverGIP_FindAttachment(device, joystick);
+ if (!attachment) {
+ return SDL_SetError("Invalid joystick");
+ }
+
+ SDL_AssertJoysticksLocked();
+
+ attachment->left_impulse_level = 0;
+ attachment->right_impulse_level = 0;
+ attachment->left_vibration_level = 0;
+ attachment->right_vibration_level = 0;
+ attachment->rumble_state = GIP_RUMBLE_STATE_IDLE;
+ attachment->rumble_time = 0;
+ attachment->rumble_pending = false;
+ SDL_zeroa(attachment->last_input);
+
+ // Initialize the joystick capabilities
+ joystick->nbuttons = 11;
+ GIP_EnableEliteButtons(attachment);
+ if (attachment->xbe_format != GIP_BTN_FMT_UNKNOWN ||
+ (device->vendor_id == USB_VENDOR_MICROSOFT &&
+ device->product_id == USB_PRODUCT_XBOX_ONE_ELITE_SERIES_2))
+ {
+ attachment->paddle_idx = (Uint8) joystick->nbuttons;
+ joystick->nbuttons += 4;
+ }
+ if (attachment->features & GIP_FEATURE_CONSOLE_FUNCTION_MAP) {
+ attachment->share_button_idx = (Uint8) joystick->nbuttons;
+ joystick->nbuttons++;
+ }
+ if (attachment->extra_buttons > 0) {
+ attachment->extra_button_idx = (Uint8) joystick->nbuttons;
+ joystick->nbuttons += attachment->extra_buttons;
+ }
+
+ joystick->naxes = SDL_GAMEPAD_AXIS_COUNT;
+ if (attachment->attachment_type == GIP_TYPE_FLIGHT_STICK) {
+ /* Flight sticks have at least 4 axes, but only 3 are signed values, so we leave RIGHTY unused */
+ joystick->naxes += attachment->extra_axes - 1;
+ }
+
+ if (attachment->attachment_type == GIP_TYPE_GUITAR) {
+ device->joystick_type = SDL_JOYSTICK_TYPE_GUITAR;
+ }
+
+ if (attachment->attachment_type == GIP_TYPE_DRUM_KIT) {
+ device->joystick_type = SDL_JOYSTICK_TYPE_DRUM_KIT;
+ }
+
+ if (attachment->attachment_type == GIP_TYPE_LIVE_GUITAR) {
+ device->joystick_type = SDL_JOYSTICK_TYPE_GUITAR;
+ }
+
+ joystick->nhats = 1;
+
+ return true;
+}
+
+static bool HIDAPI_DriverGIP_RumbleJoystick(SDL_HIDAPI_Device *device, SDL_Joystick *joystick, Uint16 low_frequency_rumble, Uint16 high_frequency_rumble)
+{
+ GIP_Attachment *attachment = HIDAPI_DriverGIP_FindAttachment(device, joystick);
+ if (!attachment) {
+ return SDL_SetError("Invalid joystick");
+ }
+
+ if (!(attachment->features & GIP_FEATURE_MOTOR_CONTROL)) {
+ return SDL_Unsupported();
+ }
+
+ // Magnitude is 1..100 so scale the 16-bit input here
+ attachment->left_vibration_level = (Uint8)(low_frequency_rumble / 655);
+ attachment->right_vibration_level = (Uint8)(high_frequency_rumble / 655);
+ attachment->rumble_pending = true;
+
+ return HIDAPI_DriverGIP_UpdateRumble(attachment);
+}
+
+static bool HIDAPI_DriverGIP_RumbleJoystickTriggers(SDL_HIDAPI_Device *device, SDL_Joystick *joystick, Uint16 left_rumble, Uint16 right_rumble)
+{
+ GIP_Attachment *attachment = HIDAPI_DriverGIP_FindAttachment(device, joystick);
+ if (!attachment) {
+ return SDL_SetError("Invalid joystick");
+ }
+
+ if (!(attachment->features & GIP_FEATURE_MOTOR_CONTROL) || (attachment->quirks & GIP_QUIRK_NO_IMPULSE_VIBRATION)) {
+ return SDL_Unsupported();
+ }
+
+ // Magnitude is 1..100 so scale the 16-bit input here
+ attachment->left_impulse_level = (Uint8)(left_rumble / 655);
+ attachment->right_impulse_level = (Uint8)(right_rumble / 655);
+ attachment->rumble_pending = true;
+
+ return HIDAPI_DriverGIP_UpdateRumble(attachment);
+}
+
+static Uint32 HIDAPI_DriverGIP_GetJoystickCapabilities(SDL_HIDAPI_Device *device, SDL_Joystick *joystick)
+{
+ GIP_Attachment *attachment = HIDAPI_DriverGIP_FindAttachment(device, joystick);
+ Uint32 result = 0;
+ if (!attachment) {
+ return 0;
+ }
+
+ if (attachment->features & GIP_FEATURE_MOTOR_CONTROL) {
+ result |= SDL_JOYSTICK_CAP_RUMBLE;
+ if (!(attachment->quirks & GIP_QUIRK_NO_IMPULSE_VIBRATION)) {
+ result |= SDL_JOYSTICK_CAP_TRIGGER_RUMBLE;
+ }
+ }
+
+ if (attachment->features & GIP_FEATURE_GUIDE_COLOR) {
+ result |= SDL_JOYSTICK_CAP_RGB_LED;
+ }
+
+ return result;
+}
+
+static bool HIDAPI_DriverGIP_SetJoystickLED(SDL_HIDAPI_Device *device, SDL_Joystick *joystick, Uint8 red, Uint8 green, Uint8 blue)
+{
+ GIP_Attachment *attachment = HIDAPI_DriverGIP_FindAttachment(device, joystick);
+ Uint8 buffer[] = { 0x00, 0x00, 0x00, 0x00, 0x00 };
+
+ if (!attachment) {
+ return SDL_SetError("Invalid joystick");
+ }
+
+ if (!(attachment->features & GIP_FEATURE_GUIDE_COLOR)) {
+ return SDL_Unsupported();
+ }
+
+ buffer[1] = 0x00; // Whiteness? Sets white intensity when RGB is 0, seems additive
+ buffer[2] = red;
+ buffer[3] = green;
+ buffer[4] = blue;
+
+ if (!GIP_SendVendorMessage(attachment, GIP_CMD_GUIDE_COLOR, 0, buffer, sizeof(buffer))) {
+ return SDL_SetError("Couldn't send LED packet");
+ }
+ return true;
+}
+
+static bool HIDAPI_DriverGIP_SendJoystickEffect(SDL_HIDAPI_Device *device, SDL_Joystick *joystick, const void *data, int size)
+{
+ return SDL_Unsupported();
+}
+
+
+static bool HIDAPI_DriverGIP_SetJoystickSensorsEnabled(SDL_HIDAPI_Device *device, SDL_Joystick *joystick, bool enabled)
+{
+ return SDL_Unsupported();
+}
+
+static bool HIDAPI_DriverGIP_UpdateDevice(SDL_HIDAPI_Device *device)
+{
+ GIP_Device *ctx = (GIP_Device *)device->context;
+ Uint8 bytes[USB_PACKET_LENGTH];
+ int i;
+ int num_bytes;
+ bool perform_reset = false;
+ Uint64 timestamp;
+
+ while ((num_bytes = SDL_hid_read_timeout(device->dev, bytes, sizeof(bytes), ctx->timeout)) > 0) {
+ ctx->timeout = 0;
+ GIP_ReceivePacket(ctx, bytes, num_bytes);
+ }
+
+ timestamp = SDL_GetTicks();
+ if (ctx->hello_deadline && timestamp >= ctx->hello_deadline) {
+ ctx->hello_deadline = 0;
+ perform_reset = true;
+ }
+ for (i = 0; i < MAX_ATTACHMENTS; i++) {
+ GIP_Attachment *attachment = ctx->attachments[i];
+ if (!attachment) {
+ continue;
+ }
+ if (attachment->fragment_message && timestamp >= attachment->fragment_timer + 1000) {
+ SDL_LogWarn(SDL_LOG_CATEGORY_INPUT, "GIP: Reliable message transfer failed");
+ attachment->fragment_message = 0;
+ }
+ if (!perform_reset &&
+ attachment->got_metadata == GIP_METADATA_PENDING &&
+ timestamp >= attachment->metadata_next &&
+ attachment->fragment_message != GIP_CMD_METADATA)
+ {
+ if (attachment->metadata_retries < 3) {
+ SDL_LogWarn(SDL_LOG_CATEGORY_INPUT, "GIP: Retrying metadata request");
+ attachment->metadata_retries++;
+ attachment->metadata_next = timestamp + 500;
+ GIP_SendSystemMessage(attachment, GIP_CMD_METADATA, 0, NULL, 0);
+ } else {
+ perform_reset = true;
+ }
+ }
+ if (perform_reset) {
+ if (ctx->reset_for_metadata) {
+ GIP_SendSetDeviceState(attachment, GIP_STATE_RESET);
+ } else {
+ GIP_SetMetadataDefaults(attachment);
+ GIP_SendInitSequence(attachment);
+ }
+ perform_reset = false;
+ }
+ HIDAPI_DriverGIP_UpdateRumble(attachment);
+ }
+
+ if (num_bytes < 0 && device->num_joysticks > 0) {
+ // Read error, device is disconnected
+ for (i = 0; i < MAX_ATTACHMENTS; i++) {
+ GIP_Attachment *attachment = ctx->attachments[i];
+ if (attachment) {
+ HIDAPI_JoystickDisconnected(device, attachment->joystick);
+ }
+ }
+ }
+ return (num_bytes >= 0);
+}
+static void HIDAPI_DriverGIP_CloseJoystick(SDL_HIDAPI_Device *device, SDL_Joystick *joystick)
+{
+}
+
+static void HIDAPI_DriverGIP_FreeDevice(SDL_HIDAPI_Device *device)
+{
+ GIP_Device *context = (GIP_Device *)device->context;
+ int i;
+
+ for (i = 0; i < MAX_ATTACHMENTS; i++) {
+ GIP_Attachment *attachment = context->attachments[i];
+ if (!attachment) {
+ continue;
+ }
+ if (attachment->fragment_data) {
+ SDL_free(attachment->fragment_data);
+ attachment->fragment_data = NULL;
+ }
+ // if (attachment->keyboard) {
+ // SDL_RemoveKeyboard(attachment->keyboard);
+ // }
+ GIP_MetadataFree(&attachment->metadata);
+ SDL_free(attachment);
+ context->attachments[i] = NULL;
+ }
+}
+
+SDL_HIDAPI_DeviceDriver SDL_HIDAPI_DriverGIP = {
+ SDL_HINT_JOYSTICK_HIDAPI_GIP,
+ true,
+ HIDAPI_DriverGIP_RegisterHints,
+ HIDAPI_DriverGIP_UnregisterHints,
+ HIDAPI_DriverGIP_IsEnabled,
+ HIDAPI_DriverGIP_IsSupportedDevice,
+ HIDAPI_DriverGIP_InitDevice,
+ HIDAPI_DriverGIP_GetDevicePlayerIndex,
+ HIDAPI_DriverGIP_SetDevicePlayerIndex,
+ HIDAPI_DriverGIP_UpdateDevice,
+ HIDAPI_DriverGIP_OpenJoystick,
+ HIDAPI_DriverGIP_RumbleJoystick,
+ HIDAPI_DriverGIP_RumbleJoystickTriggers,
+ HIDAPI_DriverGIP_GetJoystickCapabilities,
+ HIDAPI_DriverGIP_SetJoystickLED,
+ HIDAPI_DriverGIP_SendJoystickEffect,
+ HIDAPI_DriverGIP_SetJoystickSensorsEnabled,
+ HIDAPI_DriverGIP_CloseJoystick,
+ HIDAPI_DriverGIP_FreeDevice,
+};
+
+#endif // SDL_JOYSTICK_HIDAPI_GIP
+
+#endif // SDL_JOYSTICK_HIDAPI
diff --git a/thirdparty/sdl/joystick/hidapi/SDL_hidapi_lg4ff.c b/thirdparty/sdl/joystick/hidapi/SDL_hidapi_lg4ff.c
new file mode 100644
index 00000000000..fdf5b11a48a
--- /dev/null
+++ b/thirdparty/sdl/joystick/hidapi/SDL_hidapi_lg4ff.c
@@ -0,0 +1,1011 @@
+/*
+ Simple DirectMedia Layer
+ Copyright (C) 2025 Simon Wood <[email protected]>
+ Copyright (C) 2025 Michal Malý <[email protected]>
+ Copyright (C) 2025 Katharine Chui <[email protected]>
+
+ 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"
+
+#ifdef SDL_JOYSTICK_HIDAPI
+
+#include "../SDL_sysjoystick.h"
+#include "SDL3/SDL_events.h"
+#include "SDL_hidapijoystick_c.h"
+
+#ifdef SDL_JOYSTICK_HIDAPI_LG4FF
+
+#define USB_VENDOR_ID_LOGITECH 0x046d
+#define USB_DEVICE_ID_LOGITECH_G29_WHEEL 0xc24f
+#define USB_DEVICE_ID_LOGITECH_G27_WHEEL 0xc29b
+#define USB_DEVICE_ID_LOGITECH_G25_WHEEL 0xc299
+#define USB_DEVICE_ID_LOGITECH_DFGT_WHEEL 0xc29a
+#define USB_DEVICE_ID_LOGITECH_DFP_WHEEL 0xc298
+#define USB_DEVICE_ID_LOGITECH_WHEEL 0xc294
+
+static Uint32 supported_device_ids[] = {
+ USB_DEVICE_ID_LOGITECH_G29_WHEEL,
+ USB_DEVICE_ID_LOGITECH_G27_WHEEL,
+ USB_DEVICE_ID_LOGITECH_G25_WHEEL,
+ USB_DEVICE_ID_LOGITECH_DFGT_WHEEL,
+ USB_DEVICE_ID_LOGITECH_DFP_WHEEL,
+ USB_DEVICE_ID_LOGITECH_WHEEL
+};
+
+// keep the same order as the supported_ids array
+static const char *supported_device_names[] = {
+ "Logitech G29",
+ "Logitech G27",
+ "Logitech G25",
+ "Logitech Driving Force GT",
+ "Logitech Driving Force Pro",
+ "Driving Force EX"
+};
+
+static const char *HIDAPI_DriverLg4ff_GetDeviceName(Uint32 device_id)
+{
+ for (int i = 0;i < (sizeof supported_device_ids) / sizeof(Uint32);i++) {
+ if (supported_device_ids[i] == device_id) {
+ return supported_device_names[i];
+ }
+ }
+ SDL_assert(0);
+ return "";
+}
+
+static int HIDAPI_DriverLg4ff_GetNumberOfButtons(Uint32 device_id)
+{
+ switch (device_id) {
+ case USB_DEVICE_ID_LOGITECH_G29_WHEEL:
+ return 25;
+ case USB_DEVICE_ID_LOGITECH_G27_WHEEL:
+ return 23;
+ case USB_DEVICE_ID_LOGITECH_G25_WHEEL:
+ return 19;
+ case USB_DEVICE_ID_LOGITECH_DFGT_WHEEL:
+ return 21;
+ case USB_DEVICE_ID_LOGITECH_DFP_WHEEL:
+ return 14;
+ case USB_DEVICE_ID_LOGITECH_WHEEL:
+ return 13;
+ default:
+ SDL_assert(0);
+ return 0;
+ }
+}
+
+typedef struct
+{
+ Uint8 last_report_buf[32];
+ bool initialized;
+ bool is_ffex;
+ Uint16 range;
+} SDL_DriverLg4ff_Context;
+
+static void HIDAPI_DriverLg4ff_RegisterHints(SDL_HintCallback callback, void *userdata)
+{
+ SDL_AddHintCallback(SDL_HINT_JOYSTICK_HIDAPI_LG4FF, callback, userdata);
+}
+
+static void HIDAPI_DriverLg4ff_UnregisterHints(SDL_HintCallback callback, void *userdata)
+{
+ SDL_RemoveHintCallback(SDL_HINT_JOYSTICK_HIDAPI_LG4FF, callback, userdata);
+}
+
+static bool HIDAPI_DriverLg4ff_IsEnabled(void)
+{
+ #if defined(SDL_PLATFORM_WIN32) || defined(SDL_PLATFORM_WINGDK)
+ /*
+ * hid.dll simply cannot send 7 bytes reports unlike other platforms
+ * it enforces full length repots of 17 from the device's descriptor, which does not work on the device
+ * this breaks ffb and led control, so we disable this by default
+ */
+ bool hint_default = false;
+ #else
+ bool hint_default = SDL_GetHintBoolean(SDL_HINT_JOYSTICK_HIDAPI, SDL_HIDAPI_DEFAULT);
+ #endif
+ bool enabled = SDL_GetHintBoolean(SDL_HINT_JOYSTICK_HIDAPI_LG4FF, hint_default);
+
+ return enabled;
+}
+
+/*
+ Wheel id information by:
+ Simon Wood <[email protected]>
+ `git blame v6.12 drivers/hid/hid-lg4ff.c`, https://github.com/torvalds/linux.git
+*/
+static Uint16 HIDAPI_DriverLg4ff_IdentifyWheel(Uint16 device_id, Uint16 release_number)
+{
+ #define is_device(ret, m, r) { \
+ if ((release_number & m) == r) { \
+ return ret; \
+ } \
+ }
+ #define is_dfp { \
+ is_device(USB_DEVICE_ID_LOGITECH_DFP_WHEEL, 0xf000, 0x1000); \
+ }
+ #define is_dfgt { \
+ is_device(USB_DEVICE_ID_LOGITECH_DFGT_WHEEL, 0xff00, 0x1300); \
+ }
+ #define is_g25 { \
+ is_device(USB_DEVICE_ID_LOGITECH_G25_WHEEL, 0xff00, 0x1200); \
+ }
+ #define is_g27 { \
+ is_device(USB_DEVICE_ID_LOGITECH_G27_WHEEL, 0xfff0, 0x1230); \
+ }
+ #define is_g29 { \
+ is_device(USB_DEVICE_ID_LOGITECH_G29_WHEEL, 0xfff8, 0x1350); \
+ is_device(USB_DEVICE_ID_LOGITECH_G29_WHEEL, 0xff00, 0x8900); \
+ }
+ switch(device_id){
+ case USB_DEVICE_ID_LOGITECH_DFP_WHEEL:
+ case USB_DEVICE_ID_LOGITECH_WHEEL:
+ is_g29;
+ is_g27;
+ is_g25;
+ is_dfgt;
+ is_dfp;
+ break;
+ case USB_DEVICE_ID_LOGITECH_DFGT_WHEEL:
+ is_g29;
+ is_dfgt;
+ break;
+ case USB_DEVICE_ID_LOGITECH_G25_WHEEL:
+ is_g29;
+ is_g27;
+ is_g25;
+ break;
+ case USB_DEVICE_ID_LOGITECH_G27_WHEEL:
+ is_g29;
+ is_g27;
+ break;
+ case USB_DEVICE_ID_LOGITECH_G29_WHEEL:
+ is_g29;
+ break;
+ }
+ return 0;
+ #undef is_device
+ #undef is_dfp
+ #undef is_dfgt
+ #undef is_g25
+ #undef is_g27
+ #undef is_g29
+}
+
+static int SDL_HIDAPI_DriverLg4ff_GetEnvInt(const char *env_name, int min, int max, int def)
+{
+ const char *env = SDL_getenv(env_name);
+ int value = 0;
+ if(env == NULL) {
+ return def;
+ }
+ value = SDL_atoi(env);
+ if (value < min) {
+ value = min;
+ }
+ if (value > max) {
+ value = max;
+ }
+ return value;
+}
+
+/*
+ Commands by:
+ Simon Wood <[email protected]>
+ `git blame v6.12 drivers/hid/hid-lg4ff.c`, https://github.com/torvalds/linux.git
+*/
+static bool HIDAPI_DriverLg4ff_SwitchMode(SDL_HIDAPI_Device *device, Uint16 target_product_id){
+ int ret = 0;
+
+ switch(target_product_id){
+ case USB_DEVICE_ID_LOGITECH_G29_WHEEL:{
+ Uint8 cmd[] = {0xf8, 0x09, 0x05, 0x01, 0x01, 0x00, 0x00};
+ ret = SDL_hid_write(device->dev, cmd, sizeof(cmd));
+ break;
+ }
+ case USB_DEVICE_ID_LOGITECH_G27_WHEEL:{
+ Uint8 cmd[] = {0xf8, 0x09, 0x04, 0x01, 0x00, 0x00, 0x00};
+ ret = SDL_hid_write(device->dev, cmd, sizeof(cmd));
+ break;
+ }
+ case USB_DEVICE_ID_LOGITECH_G25_WHEEL:{
+ Uint8 cmd[] = {0xf8, 0x10, 0x00, 0x00, 0x00, 0x00, 0x00};
+ ret = SDL_hid_write(device->dev, cmd, sizeof(cmd));
+ break;
+ }
+ case USB_DEVICE_ID_LOGITECH_DFGT_WHEEL:{
+ Uint8 cmd[] = {0xf8, 0x09, 0x03, 0x01, 0x00, 0x00, 0x00};
+ ret = SDL_hid_write(device->dev, cmd, sizeof(cmd));
+ break;
+ }
+ case USB_DEVICE_ID_LOGITECH_DFP_WHEEL:{
+ Uint8 cmd[] = {0xf8, 0x01, 0x00, 0x00, 0x00, 0x00, 0x00};
+ ret = SDL_hid_write(device->dev, cmd, sizeof(cmd));
+ break;
+ }
+ case USB_DEVICE_ID_LOGITECH_WHEEL:{
+ Uint8 cmd[] = {0xf8, 0x09, 0x00, 0x01, 0x00, 0x00, 0x00};
+ ret = SDL_hid_write(device->dev, cmd, sizeof(cmd));
+ break;
+ }
+ default:{
+ SDL_assert(0);
+ }
+ }
+ if(ret == -1){
+ return false;
+ }
+ return true;
+}
+
+static bool HIDAPI_DriverLg4ff_IsSupportedDevice(
+ SDL_HIDAPI_Device *device,
+ const char *name,
+ SDL_GamepadType type,
+ Uint16 vendor_id,
+ Uint16 product_id,
+ Uint16 version,
+ int interface_number,
+ int interface_class,
+ int interface_subclass,
+ int interface_protocol)
+{
+ int i;
+ if (vendor_id != USB_VENDOR_ID_LOGITECH) {
+ return false;
+ }
+ for (i = 0;i < SDL_arraysize(supported_device_ids);i++) {
+ if (supported_device_ids[i] == product_id) {
+ break;
+ }
+ }
+ if (i == SDL_arraysize(supported_device_ids)) {
+ return false;
+ }
+ Uint16 real_id = HIDAPI_DriverLg4ff_IdentifyWheel(product_id, version);
+ if (real_id == product_id || real_id == 0) {
+ // either it is already in native mode, or we don't know what the native mode is
+ return true;
+ }
+ // a supported native mode is found, send mode change command, then still state that we support the device
+ if (device && SDL_HIDAPI_DriverLg4ff_GetEnvInt("SDL_HIDAPI_LG4FF_NO_MODE_SWITCH", 0, 1, 0) == 0) {
+ HIDAPI_DriverLg4ff_SwitchMode(device, real_id);
+ }
+ return true;
+}
+
+/*
+ *Ported*
+ Original functions by:
+ lg4ff_set_range_g25 lg4ff_set_range_dfp
+ `git blame v6.12 drivers/hid/hid-lg4ff.c`, https://github.com/torvalds/linux.git
+*/
+static bool HIDAPI_DriverLg4ff_SetRange(SDL_HIDAPI_Device *device, int range)
+{
+ Uint8 cmd[7] = {0};
+ int ret = 0;
+ SDL_DriverLg4ff_Context *ctx = (SDL_DriverLg4ff_Context *)device->context;
+
+ if (range < 40) {
+ range = 40;
+ }
+ if (range > 900) {
+ range = 900;
+ }
+
+ ctx->range = (Uint16)range;
+ switch (device->product_id) {
+ case USB_DEVICE_ID_LOGITECH_G29_WHEEL:
+ case USB_DEVICE_ID_LOGITECH_G27_WHEEL:
+ case USB_DEVICE_ID_LOGITECH_G25_WHEEL:
+ case USB_DEVICE_ID_LOGITECH_DFGT_WHEEL:{
+ cmd[0] = 0xf8;
+ cmd[1] = 0x81;
+ cmd[2] = range & 0x00ff;
+ cmd[3] = (range & 0xff00) >> 8;
+ ret = SDL_hid_write(device->dev, cmd, sizeof(cmd));
+ if (ret == -1) {
+ return false;
+ }
+ break;
+ }
+ case USB_DEVICE_ID_LOGITECH_DFP_WHEEL:{
+ int start_left, start_right, full_range;
+
+ /* Prepare "coarse" limit command */
+ cmd[0] = 0xf8;
+ cmd[1] = 0x00; /* Set later */
+ cmd[2] = 0x00;
+ cmd[3] = 0x00;
+ cmd[4] = 0x00;
+ cmd[5] = 0x00;
+ cmd[6] = 0x00;
+
+ if (range > 200) {
+ cmd[1] = 0x03;
+ full_range = 900;
+ } else {
+ cmd[1] = 0x02;
+ full_range = 200;
+ }
+ ret = SDL_hid_write(device->dev, cmd, 7);
+ if(ret == -1){
+ return false;
+ }
+
+ /* Prepare "fine" limit command */
+ cmd[0] = 0x81;
+ cmd[1] = 0x0b;
+ cmd[2] = 0x00;
+ cmd[3] = 0x00;
+ cmd[4] = 0x00;
+ cmd[5] = 0x00;
+ cmd[6] = 0x00;
+
+ if (range != 200 && range != 900) {
+ /* Construct fine limit command */
+ start_left = (((full_range - range + 1) * 2047) / full_range);
+ start_right = 0xfff - start_left;
+
+ cmd[2] = (Uint8)(start_left >> 4);
+ cmd[3] = (Uint8)(start_right >> 4);
+ cmd[4] = 0xff;
+ cmd[5] = (start_right & 0xe) << 4 | (start_left & 0xe);
+ cmd[6] = 0xff;
+ }
+
+ ret = SDL_hid_write(device->dev, cmd, 7);
+ if (ret == -1) {
+ return false;
+ }
+ break;
+ }
+ case USB_DEVICE_ID_LOGITECH_WHEEL:
+ // no range setting for ffex/dfex
+ break;
+ default:
+ SDL_assert(0);
+ }
+
+ return true;
+}
+
+/*
+ *Ported*
+ Original functions by:
+ Simon Wood <[email protected]>
+ lg4ff_set_autocenter_default lg4ff_set_autocenter_ffex
+ `git blame v6.12 drivers/hid/hid-lg4ff.c`, https://github.com/torvalds/linux.git
+*/
+static bool HIDAPI_DriverLg4ff_SetAutoCenter(SDL_HIDAPI_Device *device, int magnitude)
+{
+ SDL_DriverLg4ff_Context *ctx = (SDL_DriverLg4ff_Context *)device->context;
+ Uint8 cmd[7] = {0};
+ int ret;
+
+ if (magnitude < 0) {
+ magnitude = 0;
+ }
+ if (magnitude > 65535) {
+ magnitude = 65535;
+ }
+
+ if (ctx->is_ffex) {
+ magnitude = magnitude * 90 / 65535;
+
+ cmd[0] = 0xfe;
+ cmd[1] = 0x03;
+ cmd[2] = (Uint8)((Uint16)magnitude >> 14);
+ cmd[3] = (Uint8)((Uint16)magnitude >> 14);
+ cmd[4] = (Uint8)magnitude;
+
+ ret = SDL_hid_write(device->dev, cmd, sizeof(cmd));
+ if(ret == -1){
+ return false;
+ }
+ } else {
+ Uint32 expand_a;
+ Uint32 expand_b;
+ // first disable
+ cmd[0] = 0xf5;
+
+ ret = SDL_hid_write(device->dev, cmd, sizeof(cmd));
+ if (ret == -1) {
+ return false;
+ }
+
+ if (magnitude == 0) {
+ return true;
+ }
+
+ // set strength
+
+ if (magnitude <= 0xaaaa) {
+ expand_a = 0x0c * magnitude;
+ expand_b = 0x80 * magnitude;
+ } else {
+ expand_a = (0x0c * 0xaaaa) + 0x06 * (magnitude - 0xaaaa);
+ expand_b = (0x80 * 0xaaaa) + 0xff * (magnitude - 0xaaaa);
+ }
+ // TODO do not adjust for MOMO wheels, when support is added
+ expand_a = expand_a >> 1;
+
+ SDL_zeroa(cmd);
+ cmd[0] = 0xfe;
+ cmd[1] = 0x0d;
+ cmd[2] = (Uint8)(expand_a / 0xaaaa);
+ cmd[3] = (Uint8)(expand_a / 0xaaaa);
+ cmd[4] = (Uint8)(expand_b / 0xaaaa);
+
+ ret = SDL_hid_write(device->dev, cmd, sizeof(cmd));
+ if (ret == -1) {
+ return false;
+ }
+
+ // enable
+ SDL_zeroa(cmd);
+ cmd[0] = 0x14;
+
+ ret = SDL_hid_write(device->dev, cmd, sizeof(cmd));
+ if (ret == -1) {
+ return false;
+ }
+ }
+ return true;
+}
+
+/*
+ ffex identification method by:
+ Simon Wood <[email protected]>
+ lg4ff_init
+ `git blame v6.12 drivers/hid/hid-lg4ff.c`, https://github.com/torvalds/linux.git
+*/
+static bool HIDAPI_DriverLg4ff_InitDevice(SDL_HIDAPI_Device *device)
+{
+ SDL_DriverLg4ff_Context *ctx;
+
+ ctx = (SDL_DriverLg4ff_Context *)SDL_malloc(sizeof(SDL_DriverLg4ff_Context));
+ if (ctx == NULL) {
+ SDL_OutOfMemory();
+ return false;
+ }
+ SDL_zerop(ctx);
+
+ device->context = ctx;
+ device->joystick_type = SDL_JOYSTICK_TYPE_WHEEL;
+
+ HIDAPI_SetDeviceName(device, HIDAPI_DriverLg4ff_GetDeviceName(device->product_id));
+
+ if (SDL_hid_set_nonblocking(device->dev, 1) != 0) {
+ return false;
+ }
+
+ if (!HIDAPI_DriverLg4ff_SetAutoCenter(device, 0)) {
+ return false;
+ }
+
+ if (device->product_id == USB_DEVICE_ID_LOGITECH_WHEEL &&
+ (device->version >> 8) == 0x21 &&
+ (device->version & 0xff) == 0x00) {
+ ctx->is_ffex = true;
+ } else {
+ ctx->is_ffex = false;
+ }
+
+ ctx->range = 900;
+
+ return HIDAPI_JoystickConnected(device, NULL);
+}
+
+static int HIDAPI_DriverLg4ff_GetDevicePlayerIndex(SDL_HIDAPI_Device *device, SDL_JoystickID instance_id)
+{
+ return -1;
+}
+
+static void HIDAPI_DriverLg4ff_SetDevicePlayerIndex(SDL_HIDAPI_Device *device, SDL_JoystickID instance_id, int player_index)
+{
+}
+
+
+static bool HIDAPI_DriverLg4ff_GetBit(const Uint8 *buf, int bit_num, size_t buf_len)
+{
+ int byte_offset = bit_num / 8;
+ int local_bit = bit_num % 8;
+ Uint8 mask = 1 << local_bit;
+ if ((size_t)byte_offset >= buf_len) {
+ SDL_assert(0);
+ }
+ return (buf[byte_offset] & mask) ? true : false;
+}
+
+/*
+ *Ported*
+ Original functions by:
+ lg4ff_adjust_dfp_x_axis
+ `git blame v6.12 drivers/hid/hid-lg4ff.c`, https://github.com/torvalds/linux.git
+*/
+static Uint16 lg4ff_adjust_dfp_x_axis(Uint16 value, Uint16 range)
+{
+ Uint16 max_range;
+ Sint32 new_value;
+
+ if (range == 900)
+ return value;
+ else if (range == 200)
+ return value;
+ else if (range < 200)
+ max_range = 200;
+ else
+ max_range = 900;
+
+ new_value = 8192 + ((value - 8192) * max_range / range);
+ if (new_value < 0)
+ return 0;
+ else if (new_value > 16383)
+ return 16383;
+ else
+ return (Uint16)new_value;
+}
+
+static bool HIDAPI_DriverLg4ff_HandleState(SDL_HIDAPI_Device *device,
+ SDL_Joystick *joystick,
+ Uint8 *report_buf,
+ size_t report_size)
+{
+ SDL_DriverLg4ff_Context *ctx = (SDL_DriverLg4ff_Context *)device->context;
+ Uint8 hat = 0;
+ Uint8 last_hat = 0;
+ int num_buttons = HIDAPI_DriverLg4ff_GetNumberOfButtons(device->product_id);
+ int bit_offset = 0;
+ Uint64 timestamp = SDL_GetTicksNS();
+
+ bool state_changed = false;
+
+ switch (device->product_id) {
+ case USB_DEVICE_ID_LOGITECH_G29_WHEEL:
+ case USB_DEVICE_ID_LOGITECH_G27_WHEEL:
+ case USB_DEVICE_ID_LOGITECH_G25_WHEEL:
+ case USB_DEVICE_ID_LOGITECH_DFGT_WHEEL:
+ hat = report_buf[0] & 0x0f;
+ last_hat = ctx->last_report_buf[0] & 0x0f;
+ break;
+ case USB_DEVICE_ID_LOGITECH_DFP_WHEEL:
+ hat = report_buf[3] >> 4;
+ last_hat = ctx->last_report_buf[3] >> 4;
+ break;
+ case USB_DEVICE_ID_LOGITECH_WHEEL:
+ hat = report_buf[2] & 0x0F;
+ last_hat = ctx->last_report_buf[2] & 0x0F;
+ break;
+ default:
+ SDL_assert(0);
+ }
+
+ if (hat != last_hat) {
+ Uint8 sdl_hat = 0;
+ state_changed = true;
+ switch (hat) {
+ case 0:
+ sdl_hat = SDL_HAT_UP;
+ break;
+ case 1:
+ sdl_hat = SDL_HAT_RIGHTUP;
+ break;
+ case 2:
+ sdl_hat = SDL_HAT_RIGHT;
+ break;
+ case 3:
+ sdl_hat = SDL_HAT_RIGHTDOWN;
+ break;
+ case 4:
+ sdl_hat = SDL_HAT_DOWN;
+ break;
+ case 5:
+ sdl_hat = SDL_HAT_LEFTDOWN;
+ break;
+ case 6:
+ sdl_hat = SDL_HAT_LEFT;
+ break;
+ case 7:
+ sdl_hat = SDL_HAT_LEFTUP;
+ break;
+ case 8:
+ sdl_hat = SDL_HAT_CENTERED;
+ break;
+ // do not assert out, in case hardware can report weird hat values
+ }
+ SDL_SendJoystickHat(timestamp, joystick, 0, sdl_hat);
+ }
+
+ switch (device->product_id) {
+ case USB_DEVICE_ID_LOGITECH_G29_WHEEL:
+ case USB_DEVICE_ID_LOGITECH_G27_WHEEL:
+ case USB_DEVICE_ID_LOGITECH_G25_WHEEL:
+ case USB_DEVICE_ID_LOGITECH_DFGT_WHEEL:
+ bit_offset = 4;
+ break;
+ case USB_DEVICE_ID_LOGITECH_DFP_WHEEL:
+ bit_offset = 14;
+ break;
+ case USB_DEVICE_ID_LOGITECH_WHEEL:
+ bit_offset = 0;
+ break;
+ default:
+ SDL_assert(0);
+ }
+
+ if (device->product_id == USB_DEVICE_ID_LOGITECH_G27_WHEEL) {
+ // ref https://github.com/sonik-br/lgff_wheel_adapter/blob/d97f7823154818e1b3edff6d51498a122c302728/pico_lgff_wheel_adapter/reports.h#L265-L310
+ // shifter_r is outside of the main button bit field for this particular wheel
+ num_buttons--;
+
+ bool button_on = HIDAPI_DriverLg4ff_GetBit(report_buf, 80, report_size);
+ bool button_was_on = HIDAPI_DriverLg4ff_GetBit(ctx->last_report_buf, 80, report_size);
+ if (button_on != button_was_on) {
+ state_changed = true;
+ SDL_SendJoystickButton(timestamp, joystick, (Uint8)(SDL_GAMEPAD_BUTTON_SOUTH + num_buttons), button_on);
+ }
+ }
+
+ for (int i = 0;i < num_buttons;i++) {
+ int bit_num = bit_offset + i;
+ bool button_on = HIDAPI_DriverLg4ff_GetBit(report_buf, bit_num, report_size);
+ bool button_was_on = HIDAPI_DriverLg4ff_GetBit(ctx->last_report_buf, bit_num, report_size);
+ if(button_on != button_was_on){
+ state_changed = true;
+ SDL_SendJoystickButton(timestamp, joystick, (Uint8)(SDL_GAMEPAD_BUTTON_SOUTH + i), button_on);
+ }
+ }
+
+ switch (device->product_id) {
+ case USB_DEVICE_ID_LOGITECH_G29_WHEEL:{
+ Uint16 x = *(Uint16 *)&report_buf[4];
+ Uint16 last_x = *(Uint16 *)&ctx->last_report_buf[4];
+ if (x != last_x) {
+ state_changed = true;
+ SDL_SendJoystickAxis(timestamp, joystick, SDL_GAMEPAD_AXIS_LEFTX, x - 32768);
+ }
+ if (report_buf[6] != ctx->last_report_buf[6]) {
+ state_changed = true;
+ SDL_SendJoystickAxis(timestamp, joystick, SDL_GAMEPAD_AXIS_RIGHTX, report_buf[6] * 257 - 32768);
+ }
+ if (report_buf[7] != ctx->last_report_buf[7]) {
+ state_changed = true;
+ SDL_SendJoystickAxis(timestamp, joystick, SDL_GAMEPAD_AXIS_RIGHTY, report_buf[7] * 257 - 32768);
+ }
+ if (report_buf[8] != ctx->last_report_buf[8]) {
+ state_changed = true;
+ SDL_SendJoystickAxis(timestamp, joystick, SDL_GAMEPAD_AXIS_LEFTY, report_buf[8] * 257 - 32768);
+ }
+ break;
+ }
+ case USB_DEVICE_ID_LOGITECH_G27_WHEEL:
+ case USB_DEVICE_ID_LOGITECH_G25_WHEEL:{
+ Uint16 x = report_buf[4] << 6;
+ Uint16 last_x = ctx->last_report_buf[4] << 6;
+ x = x | report_buf[3] >> 2;
+ last_x = last_x | ctx->last_report_buf[3] >> 2;
+ if (x != last_x) {
+ state_changed = true;
+ SDL_SendJoystickAxis(timestamp, joystick, SDL_GAMEPAD_AXIS_LEFTX, x * 4 - 32768);
+ }
+ if (report_buf[5] != ctx->last_report_buf[5]) {
+ state_changed = true;
+ SDL_SendJoystickAxis(timestamp, joystick, SDL_GAMEPAD_AXIS_RIGHTX, report_buf[5] * 257 - 32768);
+ }
+ if (report_buf[6] != ctx->last_report_buf[6]) {
+ state_changed = true;
+ SDL_SendJoystickAxis(timestamp, joystick, SDL_GAMEPAD_AXIS_RIGHTY, report_buf[6] * 257 - 32768);
+ }
+ if (report_buf[7] != ctx->last_report_buf[7]) {
+ state_changed = true;
+ SDL_SendJoystickAxis(timestamp, joystick, SDL_GAMEPAD_AXIS_LEFTY, report_buf[7] * 257 - 32768);
+ }
+ break;
+ }
+ case USB_DEVICE_ID_LOGITECH_DFGT_WHEEL:{
+ Uint16 x = report_buf[4];
+ Uint16 last_x = ctx->last_report_buf[4];
+ x = x | (report_buf[5] & 0x3F) << 8;
+ last_x = last_x | (ctx->last_report_buf[5] & 0x3F) << 8;
+ if (x != last_x) {
+ state_changed = true;
+ SDL_SendJoystickAxis(timestamp, joystick, SDL_GAMEPAD_AXIS_LEFTX, x * 4 - 32768);
+ }
+ if (report_buf[6] != ctx->last_report_buf[6]) {
+ state_changed = true;
+ SDL_SendJoystickAxis(timestamp, joystick, SDL_GAMEPAD_AXIS_LEFTY, report_buf[6] * 257 - 32768);
+ }
+ if (report_buf[7] != ctx->last_report_buf[7]) {
+ state_changed = true;
+ SDL_SendJoystickAxis(timestamp, joystick, SDL_GAMEPAD_AXIS_RIGHTX, report_buf[7] * 257 - 32768);
+ }
+ break;
+ }
+ case USB_DEVICE_ID_LOGITECH_DFP_WHEEL:{
+ Uint16 x = report_buf[0];
+ Uint16 last_x = ctx->last_report_buf[0];
+ x = x | (report_buf[1] & 0x3F) << 8;
+ last_x = last_x | (ctx->last_report_buf[1] & 0x3F) << 8;
+ if (x != last_x) {
+ state_changed = true;
+ SDL_SendJoystickAxis(timestamp, joystick, SDL_GAMEPAD_AXIS_LEFTX, lg4ff_adjust_dfp_x_axis(x, ctx->range) * 4 - 32768);
+ }
+ if (report_buf[5] != ctx->last_report_buf[5]) {
+ state_changed = true;
+ SDL_SendJoystickAxis(timestamp, joystick, SDL_GAMEPAD_AXIS_LEFTY, report_buf[5] * 257 - 32768);
+ }
+ if (report_buf[6] != ctx->last_report_buf[6]) {
+ state_changed = true;
+ SDL_SendJoystickAxis(timestamp, joystick, SDL_GAMEPAD_AXIS_RIGHTX, report_buf[6] * 257 - 32768);
+ }
+ break;
+ }
+ case USB_DEVICE_ID_LOGITECH_WHEEL:{
+ if (report_buf[3] != ctx->last_report_buf[3]) {
+ state_changed = true;
+ SDL_SendJoystickAxis(timestamp, joystick, SDL_GAMEPAD_AXIS_LEFTX, report_buf[3] * 257 - 32768);
+ }
+ if (report_buf[4] != ctx->last_report_buf[4]) {
+ state_changed = true;
+ SDL_SendJoystickAxis(timestamp, joystick, SDL_GAMEPAD_AXIS_LEFTY, report_buf[4] * 257 - 32768);
+ }
+ if (report_buf[5] != ctx->last_report_buf[5]) {
+ state_changed = true;
+ SDL_SendJoystickAxis(timestamp, joystick, SDL_GAMEPAD_AXIS_RIGHTX, report_buf[5] * 257 - 32768);
+ }
+ if (report_buf[6] != ctx->last_report_buf[6]) {
+ state_changed = true;
+ SDL_SendJoystickAxis(timestamp, joystick, SDL_GAMEPAD_AXIS_RIGHTY, report_buf[7] * 257 - 32768);
+ }
+ break;
+ }
+ default:
+ SDL_assert(0);
+ }
+
+ SDL_memcpy(ctx->last_report_buf, report_buf, report_size);
+ return state_changed;
+}
+
+static bool HIDAPI_DriverLg4ff_UpdateDevice(SDL_HIDAPI_Device *device)
+{
+ SDL_Joystick *joystick = NULL;
+ int r;
+ Uint8 report_buf[32] = {0};
+ size_t report_size = 0;
+ SDL_DriverLg4ff_Context *ctx = (SDL_DriverLg4ff_Context *)device->context;
+
+ if (device->num_joysticks > 0) {
+ joystick = SDL_GetJoystickFromID(device->joysticks[0]);
+ if (joystick == NULL) {
+ return false;
+ }
+ } else {
+ return false;
+ }
+
+ switch (device->product_id) {
+ case USB_DEVICE_ID_LOGITECH_G29_WHEEL:
+ report_size = 12;
+ break;
+ case USB_DEVICE_ID_LOGITECH_G27_WHEEL:
+ case USB_DEVICE_ID_LOGITECH_G25_WHEEL:
+ report_size = 11;
+ break;
+ case USB_DEVICE_ID_LOGITECH_DFGT_WHEEL:
+ case USB_DEVICE_ID_LOGITECH_DFP_WHEEL:
+ report_size = 8;
+ break;
+ case USB_DEVICE_ID_LOGITECH_WHEEL:
+ report_size = 27;
+ break;
+ default:
+ SDL_assert(0);
+ }
+
+ do {
+ r = SDL_hid_read(device->dev, report_buf, report_size);
+ if (r < 0) {
+ /* Failed to read from controller */
+ HIDAPI_JoystickDisconnected(device, device->joysticks[0]);
+ return false;
+ } else if ((size_t)r == report_size) {
+ bool state_changed = HIDAPI_DriverLg4ff_HandleState(device, joystick, report_buf, report_size);
+ if(state_changed && !ctx->initialized) {
+ ctx->initialized = true;
+ HIDAPI_DriverLg4ff_SetRange(device, SDL_HIDAPI_DriverLg4ff_GetEnvInt("SDL_HIDAPI_LG4FF_RANGE", 40, 900, 900));
+ HIDAPI_DriverLg4ff_SetAutoCenter(device, 0);
+ }
+ }
+ } while (r > 0);
+
+ return true;
+}
+
+static bool HIDAPI_DriverLg4ff_OpenJoystick(SDL_HIDAPI_Device *device, SDL_Joystick *joystick)
+{
+ SDL_AssertJoysticksLocked();
+
+ // Initialize the joystick capabilities
+ joystick->nhats = 1;
+ joystick->nbuttons = HIDAPI_DriverLg4ff_GetNumberOfButtons(device->product_id);
+ switch(device->product_id){
+ case USB_DEVICE_ID_LOGITECH_G29_WHEEL:
+ case USB_DEVICE_ID_LOGITECH_G27_WHEEL:
+ case USB_DEVICE_ID_LOGITECH_G25_WHEEL:
+ case USB_DEVICE_ID_LOGITECH_WHEEL:
+ joystick->naxes = 4;
+ break;
+ case USB_DEVICE_ID_LOGITECH_DFGT_WHEEL:
+ joystick->naxes = 3;
+ break;
+ case USB_DEVICE_ID_LOGITECH_DFP_WHEEL:
+ joystick->naxes = 3;
+ break;
+ default:
+ SDL_assert(0);
+ }
+
+ return true;
+}
+
+static bool HIDAPI_DriverLg4ff_RumbleJoystick(SDL_HIDAPI_Device *device, SDL_Joystick *joystick, Uint16 low_frequency_rumble, Uint16 high_frequency_rumble)
+{
+ return SDL_Unsupported();
+}
+
+static bool HIDAPI_DriverLg4ff_RumbleJoystickTriggers(SDL_HIDAPI_Device *device, SDL_Joystick *joystick, Uint16 left_rumble, Uint16 right_rumble)
+{
+ return SDL_Unsupported();
+}
+
+static Uint32 HIDAPI_DriverLg4ff_GetJoystickCapabilities(SDL_HIDAPI_Device *device, SDL_Joystick *joystick)
+{
+ switch(device->product_id) {
+ case USB_DEVICE_ID_LOGITECH_G29_WHEEL:
+ case USB_DEVICE_ID_LOGITECH_G27_WHEEL:
+ return SDL_JOYSTICK_CAP_MONO_LED;
+ default:
+ return 0;
+ }
+}
+
+/*
+ Commands by:
+ Simon Wood <[email protected]>
+ lg4ff_led_set_brightness lg4ff_set_leds
+ `git blame v6.12 drivers/hid/hid-lg4ff.c`, https://github.com/torvalds/linux.git
+*/
+static bool HIDAPI_DriverLg4ff_SendLedCommand(SDL_HIDAPI_Device *device, Uint8 state)
+{
+ Uint8 cmd[7];
+ Uint8 led_state = 0;
+
+ switch (state) {
+ case 0:
+ led_state = 0;
+ break;
+ case 1:
+ led_state = 1;
+ break;
+ case 2:
+ led_state = 3;
+ break;
+ case 3:
+ led_state = 7;
+ break;
+ case 4:
+ led_state = 15;
+ break;
+ case 5:
+ led_state = 31;
+ break;
+ default:
+ SDL_assert(0);
+ }
+
+ cmd[0] = 0xf8;
+ cmd[1] = 0x12;
+ cmd[2] = led_state;
+ cmd[3] = 0x00;
+ cmd[4] = 0x00;
+ cmd[5] = 0x00;
+ cmd[6] = 0x00;
+
+ return SDL_hid_write(device->dev, cmd, sizeof(cmd)) == sizeof(cmd);
+}
+
+static bool HIDAPI_DriverLg4ff_SetJoystickLED(SDL_HIDAPI_Device *device, SDL_Joystick *joystick, Uint8 red, Uint8 green, Uint8 blue)
+{
+ int max_led = red;
+
+ // only g27/g29, and g923 when supported is added
+ if (device->product_id != USB_DEVICE_ID_LOGITECH_G29_WHEEL &&
+ device->product_id != USB_DEVICE_ID_LOGITECH_G27_WHEEL) {
+ return SDL_Unsupported();
+ }
+
+ if (green > max_led) {
+ max_led = green;
+ }
+ if (blue > max_led) {
+ max_led = blue;
+ }
+
+ return HIDAPI_DriverLg4ff_SendLedCommand(device, (Uint8)((5 * max_led) / 255));
+}
+
+static bool HIDAPI_DriverLg4ff_SendJoystickEffect(SDL_HIDAPI_Device *device, SDL_Joystick *joystick, const void *data, int size)
+{
+ // allow programs to send raw commands
+ return SDL_hid_write(device->dev, data, size) == size;
+}
+
+static bool HIDAPI_DriverLg4ff_SetSensorsEnabled(SDL_HIDAPI_Device *device, SDL_Joystick *joystick, bool enabled)
+{
+ // On steam deck, sensors are enabled by default. Nothing to do here.
+ return SDL_Unsupported();
+}
+
+static void HIDAPI_DriverLg4ff_CloseJoystick(SDL_HIDAPI_Device *device, SDL_Joystick *joystick)
+{
+ // remember to stop effects on haptics close, when implemented
+ HIDAPI_DriverLg4ff_SetJoystickLED(device, joystick, 0, 0, 0);
+}
+
+static void HIDAPI_DriverLg4ff_FreeDevice(SDL_HIDAPI_Device *device)
+{
+ // device context is freed in SDL_hidapijoystick.c
+}
+
+
+SDL_HIDAPI_DeviceDriver SDL_HIDAPI_DriverLg4ff = {
+ SDL_HINT_JOYSTICK_HIDAPI_LG4FF,
+ true,
+ HIDAPI_DriverLg4ff_RegisterHints,
+ HIDAPI_DriverLg4ff_UnregisterHints,
+ HIDAPI_DriverLg4ff_IsEnabled,
+ HIDAPI_DriverLg4ff_IsSupportedDevice,
+ HIDAPI_DriverLg4ff_InitDevice,
+ HIDAPI_DriverLg4ff_GetDevicePlayerIndex,
+ HIDAPI_DriverLg4ff_SetDevicePlayerIndex,
+ HIDAPI_DriverLg4ff_UpdateDevice,
+ HIDAPI_DriverLg4ff_OpenJoystick,
+ HIDAPI_DriverLg4ff_RumbleJoystick,
+ HIDAPI_DriverLg4ff_RumbleJoystickTriggers,
+ HIDAPI_DriverLg4ff_GetJoystickCapabilities,
+ HIDAPI_DriverLg4ff_SetJoystickLED,
+ HIDAPI_DriverLg4ff_SendJoystickEffect,
+ HIDAPI_DriverLg4ff_SetSensorsEnabled,
+ HIDAPI_DriverLg4ff_CloseJoystick,
+ HIDAPI_DriverLg4ff_FreeDevice,
+};
+
+
+#endif /* SDL_JOYSTICK_HIDAPI_LG4FF */
+
+#endif /* SDL_JOYSTICK_HIDAPI */
diff --git a/thirdparty/sdl/joystick/hidapi/SDL_hidapi_luna.c b/thirdparty/sdl/joystick/hidapi/SDL_hidapi_luna.c
index 7c889a668fe..b560f789b45 100644
--- a/thirdparty/sdl/joystick/hidapi/SDL_hidapi_luna.c
+++ b/thirdparty/sdl/joystick/hidapi/SDL_hidapi_luna.c
@@ -1,6 +1,6 @@
/*
Simple DirectMedia Layer
- Copyright (C) 1997-2025 Sam Lantinga <[email protected]>
+ Copyright (C) 1997-2026 Sam Lantinga <[email protected]>
This software is provided 'as-is', without any express or implied
warranty. In no event will the authors be held liable for any damages
diff --git a/thirdparty/sdl/joystick/hidapi/SDL_hidapi_nintendo.h b/thirdparty/sdl/joystick/hidapi/SDL_hidapi_nintendo.h
index 0a5836fbbb1..dc7622f8c0d 100644
--- a/thirdparty/sdl/joystick/hidapi/SDL_hidapi_nintendo.h
+++ b/thirdparty/sdl/joystick/hidapi/SDL_hidapi_nintendo.h
@@ -1,6 +1,6 @@
/*
Simple DirectMedia Layer
- Copyright (C) 1997-2025 Sam Lantinga <[email protected]>
+ Copyright (C) 1997-2026 Sam Lantinga <[email protected]>
This software is provided 'as-is', without any express or implied
warranty. In no event will the authors be held liable for any damages
diff --git a/thirdparty/sdl/joystick/hidapi/SDL_hidapi_ps3.c b/thirdparty/sdl/joystick/hidapi/SDL_hidapi_ps3.c
index 6c82647c0bc..44fa08a6f7a 100644
--- a/thirdparty/sdl/joystick/hidapi/SDL_hidapi_ps3.c
+++ b/thirdparty/sdl/joystick/hidapi/SDL_hidapi_ps3.c
@@ -1,6 +1,6 @@
/*
Simple DirectMedia Layer
- Copyright (C) 1997-2025 Sam Lantinga <[email protected]>
+ Copyright (C) 1997-2026 Sam Lantinga <[email protected]>
This software is provided 'as-is', without any express or implied
warranty. In no event will the authors be held liable for any damages
@@ -32,8 +32,6 @@
// Define this if you want to log all packets from the controller
// #define DEBUG_PS3_PROTOCOL
-#define LOAD16(A, B) (Sint16)((Uint16)(A) | (((Uint16)(B)) << 8))
-
typedef enum
{
k_EPS3ReportIdState = 1,
@@ -349,6 +347,11 @@ static float HIDAPI_DriverPS3_ScaleAccel(Sint16 value)
return ((float)(value - 511) / 113.0f) * SDL_STANDARD_GRAVITY;
}
+static float HIDAPI_DriverPS3ThirdParty_ScaleAccel(Sint16 value)
+{
+ return ((float)(value - 512) / 113.0f) * SDL_STANDARD_GRAVITY;
+}
+
static void HIDAPI_DriverPS3_HandleMiniStatePacket(SDL_Joystick *joystick, SDL_DriverPS3_Context *ctx, Uint8 *data, int size)
{
Sint16 axis;
@@ -637,7 +640,14 @@ static bool HIDAPI_DriverPS3ThirdParty_IsSupportedDevice(SDL_HIDAPI_Device *devi
// Supported third party controller
return true;
} else {
- return false;
+ // Some third party controllers don't have report ids
+ size = ReadFeatureReport(device->dev, 0x00, data, sizeof(data));
+ if (size == 9 && data[2] == 0x26) {
+ // Supported third party controller
+ return true;
+ } else {
+ return false;
+ }
}
} else {
// Might be supported by this driver, enumerate and find out
@@ -656,7 +666,7 @@ static bool HIDAPI_DriverPS3ThirdParty_InitDevice(SDL_HIDAPI_Device *device)
return false;
}
ctx->device = device;
- if (device->vendor_id == USB_VENDOR_SWITCH && device->product_id == USB_PRODUCT_SWITCH_RETROBIT_CONTROLLER) {
+ if (device->vendor_id == USB_VENDOR_SWITCH && device->product_id == USB_PRODUCT_SWITCH_RETRO_CONTROLLER) {
ctx->has_analog_buttons = false;
} else {
ctx->has_analog_buttons = true;
@@ -671,6 +681,39 @@ static bool HIDAPI_DriverPS3ThirdParty_InitDevice(SDL_HIDAPI_Device *device)
HIDAPI_SetDeviceName(device, "Logitech ChillStream");
}
+ if (device->vendor_id == USB_VENDOR_HARMONIX) {
+ switch (device->product_id) {
+ case USB_PRODUCT_HARMONIX_WII_RB1_GUITAR:
+ case USB_PRODUCT_HARMONIX_WII_RB2_GUITAR:
+ device->joystick_type = SDL_JOYSTICK_TYPE_GUITAR;
+ break;
+ case USB_PRODUCT_HARMONIX_WII_RB1_DRUMS:
+ case USB_PRODUCT_HARMONIX_WII_RB2_DRUMS:
+ case USB_PRODUCT_HARMONIX_WII_RB3_MPA_DRUMS_MODE:
+ device->joystick_type = SDL_JOYSTICK_TYPE_DRUM_KIT;
+ break;
+ default:
+ break;
+ }
+ }
+
+ if (device->vendor_id == USB_VENDOR_SCEA) {
+ switch (device->product_id) {
+ case USB_PRODUCT_SCEA_PS3_GH_GUITAR:
+ case USB_PRODUCT_SCEA_PS3_RB_GUITAR:
+ case USB_PRODUCT_SCEA_PS3WIIU_GHLIVE:
+ device->joystick_type = SDL_JOYSTICK_TYPE_GUITAR;
+ break;
+ case USB_PRODUCT_SCEA_PS3_GH_DRUMS:
+ case USB_PRODUCT_SCEA_PS3_RB_DRUMS:
+ case USB_PRODUCT_SCEA_PS3_RB3_MPA_DRUMS_MODE:
+ device->joystick_type = SDL_JOYSTICK_TYPE_DRUM_KIT;
+ break;
+ default:
+ break;
+ }
+ }
+
return HIDAPI_JoystickConnected(device, NULL);
}
@@ -700,11 +743,13 @@ static bool HIDAPI_DriverPS3ThirdParty_OpenJoystick(SDL_HIDAPI_Device *device, S
}
joystick->nhats = 1;
- if (device->vendor_id == USB_VENDOR_SWITCH && device->product_id == USB_PRODUCT_SWITCH_RETROBIT_CONTROLLER) {
+ if (device->vendor_id == USB_VENDOR_SWITCH && device->product_id == USB_PRODUCT_SWITCH_RETRO_CONTROLLER) {
// This is a wireless controller using a USB dongle
joystick->connection_state = SDL_JOYSTICK_CONNECTION_WIRELESS;
}
+ SDL_PrivateJoystickAddSensor(joystick, SDL_SENSOR_ACCEL, 100.0f);
+
return true;
}
@@ -735,7 +780,11 @@ static bool HIDAPI_DriverPS3ThirdParty_SendJoystickEffect(SDL_HIDAPI_Device *dev
static bool HIDAPI_DriverPS3ThirdParty_SetJoystickSensorsEnabled(SDL_HIDAPI_Device *device, SDL_Joystick *joystick, bool enabled)
{
- return SDL_Unsupported();
+ SDL_DriverPS3_Context *ctx = (SDL_DriverPS3_Context *)device->context;
+
+ ctx->report_sensors = enabled;
+
+ return true;
}
static void HIDAPI_DriverPS3ThirdParty_HandleStatePacket18(SDL_Joystick *joystick, SDL_DriverPS3_Context *ctx, Uint8 *data, int size)
@@ -973,6 +1022,15 @@ static void HIDAPI_DriverPS3ThirdParty_HandleStatePacket19(SDL_Joystick *joystic
}
}
+ if (ctx->report_sensors) {
+ float sensor_data[3];
+
+ sensor_data[0] = -HIDAPI_DriverPS3ThirdParty_ScaleAccel(LOAD16(data[19], data[20]));
+ sensor_data[1] = -HIDAPI_DriverPS3ThirdParty_ScaleAccel(LOAD16(data[21], data[22]));
+ sensor_data[2] = -HIDAPI_DriverPS3ThirdParty_ScaleAccel(LOAD16(data[23], data[24]));
+ SDL_SendJoystickSensor(timestamp, joystick, SDL_SENSOR_ACCEL, timestamp, sensor_data, SDL_arraysize(sensor_data));
+ }
+
SDL_memcpy(ctx->last_state, data, SDL_min(size, sizeof(ctx->last_state)));
}
diff --git a/thirdparty/sdl/joystick/hidapi/SDL_hidapi_ps4.c b/thirdparty/sdl/joystick/hidapi/SDL_hidapi_ps4.c
index d4332df7b3b..188a40cb1b5 100644
--- a/thirdparty/sdl/joystick/hidapi/SDL_hidapi_ps4.c
+++ b/thirdparty/sdl/joystick/hidapi/SDL_hidapi_ps4.c
@@ -1,6 +1,6 @@
/*
Simple DirectMedia Layer
- Copyright (C) 1997-2025 Sam Lantinga <[email protected]>
+ Copyright (C) 1997-2026 Sam Lantinga <[email protected]>
This software is provided 'as-is', without any express or implied
warranty. In no event will the authors be held liable for any damages
@@ -44,12 +44,6 @@
#define BLUETOOTH_DISCONNECT_TIMEOUT_MS 500
-#define LOAD16(A, B) (Sint16)((Uint16)(A) | (((Uint16)(B)) << 8))
-#define LOAD32(A, B, C, D) ((((Uint32)(A)) << 0) | \
- (((Uint32)(B)) << 8) | \
- (((Uint32)(C)) << 16) | \
- (((Uint32)(D)) << 24))
-
enum
{
SDL_GAMEPAD_BUTTON_PS4_TOUCHPAD = 11
@@ -104,6 +98,7 @@ typedef struct
Uint8 rgucTouchpadData1[3];
Uint8 ucTouchpadCounter2;
Uint8 rgucTouchpadData2[3];
+ Uint8 rgucDeviceSpecific[12];
} PS4StatePacket_t;
typedef struct
@@ -122,6 +117,14 @@ typedef struct
Uint8 ucVolumeSpeaker;
} DS4EffectsState_t;
+// These enum values match with the validity flags in the PS4 output report
+typedef enum
+{
+ k_EPS4EffectRumble = (1 << 0),
+ k_EPS4EffectLED = (1 << 1),
+ k_EPS4EffectLEDBlink = (1 << 2),
+} EPS4Effect;
+
typedef struct
{
Sint16 bias;
@@ -152,6 +155,9 @@ typedef struct
bool vibration_supported;
bool touchpad_supported;
bool effects_supported;
+ bool guitar_whammy_supported;
+ bool guitar_tilt_supported;
+ bool guitar_effects_selector_supported;
HIDAPI_PS4_EnhancedReportHint enhanced_report_hint;
bool enhanced_reports;
bool enhanced_mode;
@@ -180,7 +186,7 @@ typedef struct
PS4StatePacket_t last_state;
} SDL_DriverPS4_Context;
-static bool HIDAPI_DriverPS4_InternalSendJoystickEffect(SDL_DriverPS4_Context *ctx, const void *effect, int size, bool application_usage);
+static bool HIDAPI_DriverPS4_InternalSendJoystickEffect(SDL_DriverPS4_Context *ctx, const void *effect, int size, EPS4Effect mask, bool application_usage);
static void HIDAPI_DriverPS4_RegisterHints(SDL_HintCallback callback, void *userdata)
{
@@ -353,6 +359,7 @@ static bool HIDAPI_DriverPS4_InitDevice(SDL_HIDAPI_Device *device)
if (size == 48 && data[2] == 0x27) {
Uint8 capabilities = data[4];
Uint8 device_type = data[5];
+ Uint8 device_specific_capabilities = data[24];
Uint16 gyro_numerator = LOAD16(data[10], data[11]);
Uint16 gyro_denominator = LOAD16(data[12], data[13]);
Uint16 accel_numerator = LOAD16(data[14], data[15]);
@@ -380,6 +387,15 @@ static bool HIDAPI_DriverPS4_InitDevice(SDL_HIDAPI_Device *device)
break;
case 0x01:
joystick_type = SDL_JOYSTICK_TYPE_GUITAR;
+ if (device_specific_capabilities & 0x01) {
+ ctx->guitar_effects_selector_supported = true;
+ }
+ if (device_specific_capabilities & 0x02) {
+ ctx->guitar_tilt_supported = true;
+ }
+ if (device_specific_capabilities & 0x04) {
+ ctx->guitar_whammy_supported = true;
+ }
break;
case 0x02:
joystick_type = SDL_JOYSTICK_TYPE_DRUM_KIT;
@@ -653,7 +669,7 @@ static float HIDAPI_DriverPS4_ApplyCalibrationData(SDL_DriverPS4_Context *ctx, i
return ((float)value - calibration->bias) * calibration->scale;
}
-static bool HIDAPI_DriverPS4_UpdateEffects(SDL_DriverPS4_Context *ctx, bool application_usage)
+static bool HIDAPI_DriverPS4_UpdateEffects(SDL_DriverPS4_Context *ctx, EPS4Effect mask, bool application_usage)
{
DS4EffectsState_t effects;
@@ -674,7 +690,7 @@ static bool HIDAPI_DriverPS4_UpdateEffects(SDL_DriverPS4_Context *ctx, bool appl
SetLedsForPlayerIndex(&effects, ctx->player_index);
}
}
- return HIDAPI_DriverPS4_InternalSendJoystickEffect(ctx, &effects, sizeof(effects), application_usage);
+ return HIDAPI_DriverPS4_InternalSendJoystickEffect(ctx, &effects, sizeof(effects), mask, application_usage);
}
static void HIDAPI_DriverPS4_TickleBluetooth(SDL_HIDAPI_Device *device)
@@ -722,6 +738,10 @@ static void HIDAPI_DriverPS4_SetEnhancedModeAvailable(SDL_DriverPS4_Context *ctx
SDL_PrivateJoystickAddSensor(ctx->joystick, SDL_SENSOR_ACCEL, (float)(1000 / ctx->report_interval));
}
+ if (ctx->guitar_tilt_supported) {
+ SDL_PrivateJoystickAddSensor(ctx->joystick, SDL_SENSOR_ACCEL, (float)(1000 / ctx->report_interval));
+ }
+
if (ctx->official_controller) {
ctx->report_battery = true;
}
@@ -737,7 +757,7 @@ static void HIDAPI_DriverPS4_SetEnhancedMode(SDL_DriverPS4_Context *ctx)
ctx->enhanced_mode = true;
// Switch into enhanced report mode
- HIDAPI_DriverPS4_UpdateEffects(ctx, false);
+ HIDAPI_DriverPS4_UpdateEffects(ctx, 0, false);
}
}
@@ -813,7 +833,7 @@ static void SDLCALL SDL_PS4ReportIntervalHintChanged(void *userdata, const char
if (new_report_interval != ctx->report_interval) {
ctx->report_interval = (Uint8)new_report_interval;
- HIDAPI_DriverPS4_UpdateEffects(ctx, false);
+ HIDAPI_DriverPS4_UpdateEffects(ctx, 0, false);
SDL_LockJoysticks();
SDL_PrivateJoystickSensorRate(ctx->joystick, SDL_SENSOR_GYRO, (float)(1000 / ctx->report_interval));
SDL_PrivateJoystickSensorRate(ctx->joystick, SDL_SENSOR_ACCEL, (float)(1000 / ctx->report_interval));
@@ -833,7 +853,7 @@ static void HIDAPI_DriverPS4_SetDevicePlayerIndex(SDL_HIDAPI_Device *device, SDL
// This will set the new LED state based on the new player index
// SDL automatically calls this, so it doesn't count as an application action to enable enhanced mode
- HIDAPI_DriverPS4_UpdateEffects(ctx, false);
+ HIDAPI_DriverPS4_UpdateEffects(ctx, k_EPS4EffectLED, false);
}
static bool HIDAPI_DriverPS4_OpenJoystick(SDL_HIDAPI_Device *device, SDL_Joystick *joystick)
@@ -880,7 +900,7 @@ static bool HIDAPI_DriverPS4_RumbleJoystick(SDL_HIDAPI_Device *device, SDL_Joyst
ctx->rumble_left = (low_frequency_rumble >> 8);
ctx->rumble_right = (high_frequency_rumble >> 8);
- return HIDAPI_DriverPS4_UpdateEffects(ctx, true);
+ return HIDAPI_DriverPS4_UpdateEffects(ctx, k_EPS4EffectRumble, true);
}
static bool HIDAPI_DriverPS4_RumbleJoystickTriggers(SDL_HIDAPI_Device *device, SDL_Joystick *joystick, Uint16 left_rumble, Uint16 right_rumble)
@@ -918,10 +938,10 @@ static bool HIDAPI_DriverPS4_SetJoystickLED(SDL_HIDAPI_Device *device, SDL_Joyst
ctx->led_green = green;
ctx->led_blue = blue;
- return HIDAPI_DriverPS4_UpdateEffects(ctx, true);
+ return HIDAPI_DriverPS4_UpdateEffects(ctx, k_EPS4EffectLED, true);
}
-static bool HIDAPI_DriverPS4_InternalSendJoystickEffect(SDL_DriverPS4_Context *ctx, const void *effect, int size, bool application_usage)
+static bool HIDAPI_DriverPS4_InternalSendJoystickEffect(SDL_DriverPS4_Context *ctx, const void *effect, int size, EPS4Effect mask, bool application_usage)
{
Uint8 data[78];
int report_size, offset;
@@ -947,13 +967,21 @@ static bool HIDAPI_DriverPS4_InternalSendJoystickEffect(SDL_DriverPS4_Context *c
if (ctx->device->is_bluetooth && ctx->official_controller) {
data[0] = k_EPS4ReportIdBluetoothEffects;
data[1] = 0xC0 | ctx->report_interval; // Magic value HID + CRC, also sets update interval
- data[3] = 0x03; // 0x1 is rumble, 0x2 is lightbar, 0x4 is the blink interval
+
+ // Some third-party PS4 gamepads expect to receive both rumble and LED together,
+ // so we will only send them separately to official Sony gamepads. Unfortunately,
+ // this means that we'll fight with other apps that might be controlling one or
+ // the other separately for third-party PS4 gamepads. We can add a whitelist for
+ // compatible third-party gamepads later if we want.
+ data[3] = (Uint8)(ctx->official_controller ? mask : (k_EPS4EffectRumble | k_EPS4EffectLED));
report_size = 78;
offset = 6;
} else {
data[0] = k_EPS4ReportIdUsbEffects;
- data[1] = 0x07; // Magic value
+
+ // FIXME: Should we send a consistent default effect mask between BT and USB?
+ data[1] = (Uint8)(ctx->official_controller ? mask : (k_EPS4EffectRumble | k_EPS4EffectLED | k_EPS4EffectLEDBlink));
report_size = 32;
offset = 4;
@@ -979,8 +1007,18 @@ static bool HIDAPI_DriverPS4_InternalSendJoystickEffect(SDL_DriverPS4_Context *c
static bool HIDAPI_DriverPS4_SendJoystickEffect(SDL_HIDAPI_Device *device, SDL_Joystick *joystick, const void *effect, int size)
{
SDL_DriverPS4_Context *ctx = (SDL_DriverPS4_Context *)device->context;
+ EPS4Effect mask;
- return HIDAPI_DriverPS4_InternalSendJoystickEffect(ctx, effect, size, true);
+ // Unlike the PS5 driver, the PS4 driver does not expect the validity bits as part of
+ // the provided effect data. The default values we provide also diverge for different
+ // gamepads and connection mediums. We should probably clean this up eventually.
+ if (ctx->device->is_bluetooth && ctx->official_controller) {
+ mask = k_EPS4EffectRumble | k_EPS4EffectLED;
+ } else {
+ mask = k_EPS4EffectRumble | k_EPS4EffectLED | k_EPS4EffectLEDBlink;
+ }
+
+ return HIDAPI_DriverPS4_InternalSendJoystickEffect(ctx, effect, size, mask, true);
}
static bool HIDAPI_DriverPS4_SetJoystickSensorsEnabled(SDL_HIDAPI_Device *device, SDL_Joystick *joystick, bool enabled)
@@ -989,7 +1027,7 @@ static bool HIDAPI_DriverPS4_SetJoystickSensorsEnabled(SDL_HIDAPI_Device *device
HIDAPI_DriverPS4_UpdateEnhancedModeOnApplicationUsage(ctx);
- if (!ctx->sensors_supported || (enabled && !ctx->enhanced_mode)) {
+ if ((!ctx->sensors_supported || (enabled && !ctx->enhanced_mode)) && !ctx->guitar_tilt_supported) {
return SDL_Unsupported();
}
@@ -1138,7 +1176,7 @@ static void HIDAPI_DriverPS4_HandleStatePacket(SDL_Joystick *joystick, SDL_hid_d
float data[3];
tick = LOAD16(packet->rgucTimestamp[0], packet->rgucTimestamp[1]);
- if (ctx->last_tick < tick) {
+ if (ctx->last_tick <= tick) {
delta = (tick - ctx->last_tick);
} else {
delta = (SDL_MAX_UINT16 - ctx->last_tick + tick + 1);
@@ -1160,6 +1198,30 @@ static void HIDAPI_DriverPS4_HandleStatePacket(SDL_Joystick *joystick, SDL_hid_d
SDL_SendJoystickSensor(timestamp, joystick, SDL_SENSOR_ACCEL, sensor_timestamp, data, 3);
}
+ if (ctx->guitar_whammy_supported) {
+ axis = ((int)packet->rgucDeviceSpecific[1] * 257) - 32768;
+ SDL_SendJoystickAxis(timestamp, joystick, SDL_GAMEPAD_AXIS_RIGHTX, axis);
+ }
+
+ if (ctx->guitar_effects_selector_supported) {
+ // Align pickup selector mappings with PS3 instruments
+ static const Sint16 effects_mappings[] = {24576, 11008, -1792, -13568, -26880};
+ if (packet->rgucDeviceSpecific[0] < SDL_arraysize(effects_mappings)) {
+ SDL_SendJoystickAxis(timestamp, joystick, SDL_GAMEPAD_AXIS_RIGHTY, effects_mappings[packet->rgucDeviceSpecific[0]]);
+ }
+ }
+
+ if (ctx->guitar_tilt_supported) {
+ float sensor_data[3];
+ sensor_data[0] = ((float)packet->rgucDeviceSpecific[2] / 255) * SDL_STANDARD_GRAVITY;
+ sensor_data[1] = 0;
+ sensor_data[2] = 0;
+ SDL_SendJoystickSensor(timestamp, joystick, SDL_SENSOR_ACCEL, timestamp, sensor_data, SDL_arraysize(sensor_data));
+
+ // Align tilt mappings with PS3 instruments
+ SDL_SendJoystickButton(timestamp, joystick, SDL_GAMEPAD_BUTTON_RIGHT_SHOULDER, packet->rgucDeviceSpecific[2] > 0xF0);
+ }
+
SDL_memcpy(&ctx->last_state, packet, sizeof(ctx->last_state));
}
diff --git a/thirdparty/sdl/joystick/hidapi/SDL_hidapi_ps5.c b/thirdparty/sdl/joystick/hidapi/SDL_hidapi_ps5.c
index 1abde084949..bc5d4d53fc2 100644
--- a/thirdparty/sdl/joystick/hidapi/SDL_hidapi_ps5.c
+++ b/thirdparty/sdl/joystick/hidapi/SDL_hidapi_ps5.c
@@ -1,6 +1,6 @@
/*
Simple DirectMedia Layer
- Copyright (C) 1997-2025 Sam Lantinga <[email protected]>
+ Copyright (C) 1997-2026 Sam Lantinga <[email protected]>
This software is provided 'as-is', without any express or implied
warranty. In no event will the authors be held liable for any damages
@@ -43,12 +43,6 @@
#define ACCEL_RES_PER_G 8192.0f
#define BLUETOOTH_DISCONNECT_TIMEOUT_MS 500
-#define LOAD16(A, B) (Sint16)((Uint16)(A) | (((Uint16)(B)) << 8))
-#define LOAD32(A, B, C, D) ((((Uint32)(A)) << 0) | \
- (((Uint32)(B)) << 8) | \
- (((Uint32)(C)) << 16) | \
- (((Uint32)(D)) << 24))
-
enum
{
SDL_GAMEPAD_BUTTON_PS5_TOUCHPAD = 11,
@@ -162,6 +156,7 @@ typedef struct
Uint8 rgucTouchpadData1[3]; // 32 - X/Y, 12 bits per axis
Uint8 ucTouchpadCounter2; // 35 - high bit clear + counter
Uint8 rgucTouchpadData2[3]; // 36 - X/Y, 12 bits per axis
+ Uint8 rgucDeviceSpecific[8]; // 40
// There's more unknown data at the end, and a 32-bit CRC on Bluetooth
} PS5StatePacketAlt_t;
@@ -230,7 +225,7 @@ typedef struct
{
SDL_HIDAPI_Device *device;
SDL_Joystick *joystick;
- bool is_nacon_dongle;
+ bool is_dongle;
bool use_alternate_report;
bool sensors_supported;
bool lightbar_supported;
@@ -238,6 +233,9 @@ typedef struct
bool playerled_supported;
bool touchpad_supported;
bool effects_supported;
+ bool guitar_whammy_supported;
+ bool guitar_tilt_supported;
+ bool guitar_effects_selector_supported;
HIDAPI_PS5_EnhancedReportHint enhanced_report_hint;
bool enhanced_reports;
bool enhanced_mode;
@@ -300,6 +298,12 @@ static bool HIDAPI_DriverPS5_IsSupportedDevice(SDL_HIDAPI_Device *device, const
Uint8 data[USB_PACKET_LENGTH];
int size;
+ if (vendor_id == USB_VENDOR_BACKBONE &&
+ product_id == USB_PRODUCT_BACKBONE_ONE_PS5_V2) {
+ // This product doesn't appear to use the DualSense protocol
+ return false;
+ }
+
if (type == SDL_GAMEPAD_TYPE_PS5) {
return true;
}
@@ -354,7 +358,9 @@ static void SetLightsForPlayerIndex(DS5EffectsState_t *effects, int player_index
0x0A,
0x15,
0x1B,
- 0x1F
+ 0x1F,
+ 0x11,
+ 0x0E
};
if (player_index >= 0) {
@@ -454,6 +460,7 @@ static bool HIDAPI_DriverPS5_InitDevice(SDL_HIDAPI_Device *device)
if (size == 48 && data[2] == 0x28) {
Uint8 capabilities = data[4];
Uint8 capabilities2 = data[20];
+ Uint8 device_specific_capabilities = data[24];
Uint8 device_type = data[5];
#ifdef DEBUG_PS5_PROTOCOL
@@ -475,12 +482,25 @@ static bool HIDAPI_DriverPS5_InitDevice(SDL_HIDAPI_Device *device)
ctx->playerled_supported = true;
}
+ if (capabilities2 & 0x01) {
+ ctx->report_battery = true;
+ }
+
switch (device_type) {
case 0x00:
joystick_type = SDL_JOYSTICK_TYPE_GAMEPAD;
break;
case 0x01:
joystick_type = SDL_JOYSTICK_TYPE_GUITAR;
+ if (device_specific_capabilities & 0x01) {
+ ctx->guitar_effects_selector_supported = true;
+ }
+ if (device_specific_capabilities & 0x02) {
+ ctx->guitar_tilt_supported = true;
+ }
+ if (device_specific_capabilities & 0x04) {
+ ctx->guitar_whammy_supported = true;
+ }
break;
case 0x02:
joystick_type = SDL_JOYSTICK_TYPE_DRUM_KIT;
@@ -500,6 +520,7 @@ static bool HIDAPI_DriverPS5_InitDevice(SDL_HIDAPI_Device *device)
}
ctx->use_alternate_report = true;
+ ctx->report_battery = true;
if (device->vendor_id == USB_VENDOR_NACON_ALT &&
(device->product_id == USB_PRODUCT_NACON_REVOLUTION_5_PRO_PS5_WIRED ||
@@ -515,8 +536,10 @@ static bool HIDAPI_DriverPS5_InitDevice(SDL_HIDAPI_Device *device)
ctx->touchpad_supported = true;
ctx->use_alternate_report = true;
} else if (device->vendor_id == USB_VENDOR_RAZER &&
- device->product_id == USB_PRODUCT_RAZER_KITSUNE) {
- // The Razer Kitsune doesn't respond to the detection protocol, but has a touchpad
+ (device->product_id == USB_PRODUCT_RAZER_KITSUNE ||
+ device->product_id == USB_PRODUCT_RAZER_RAIJU_V3_PRO_PS5_WIRED ||
+ device->product_id == USB_PRODUCT_RAZER_RAIJU_V3_PRO_PS5_WIRELESS)) {
+ // The Razer Kitsune and Raiju don't respond to the detection protocol, but have a touchpad
joystick_type = SDL_JOYSTICK_TYPE_ARCADE_STICK;
ctx->touchpad_supported = true;
ctx->use_alternate_report = true;
@@ -524,9 +547,13 @@ static bool HIDAPI_DriverPS5_InitDevice(SDL_HIDAPI_Device *device)
}
ctx->effects_supported = (ctx->lightbar_supported || ctx->vibration_supported || ctx->playerled_supported);
- if (device->vendor_id == USB_VENDOR_NACON_ALT &&
- device->product_id == USB_PRODUCT_NACON_REVOLUTION_5_PRO_PS5_WIRELESS) {
- ctx->is_nacon_dongle = true;
+ if ((device->vendor_id == USB_VENDOR_NACON_ALT &&
+ device->product_id == USB_PRODUCT_NACON_REVOLUTION_5_PRO_PS5_WIRELESS) ||
+ (device->vendor_id == USB_VENDOR_RAZER &&
+ (device->product_id == USB_PRODUCT_NACON_REVOLUTION_5_PRO_PS5_WIRELESS ||
+ device->product_id == USB_PRODUCT_RAZER_WOLVERINE_V2_PRO_PS5_WIRELESS ||
+ device->product_id == USB_PRODUCT_RAZER_RAIJU_V3_PRO_PS5_WIRELESS))) {
+ ctx->is_dongle = true;
}
device->joystick_type = joystick_type;
@@ -540,7 +567,7 @@ static bool HIDAPI_DriverPS5_InitDevice(SDL_HIDAPI_Device *device)
}
HIDAPI_SetDeviceSerial(device, serial);
- if (ctx->is_nacon_dongle) {
+ if (ctx->is_dongle) {
// We don't know if this is connected yet, wait for reports
return true;
}
@@ -823,7 +850,7 @@ static void HIDAPI_DriverPS5_SetEnhancedModeAvailable(SDL_DriverPS5_Context *ctx
if (ctx->sensors_supported) {
// Standard DualSense sensor update rate is 250 Hz over USB
float update_rate = 250.0f;
-
+
if (ctx->device->is_bluetooth) {
// Bluetooth sensor update rate appears to be 1000 Hz
update_rate = 1000.0f;
@@ -836,6 +863,11 @@ static void HIDAPI_DriverPS5_SetEnhancedModeAvailable(SDL_DriverPS5_Context *ctx
SDL_PrivateJoystickAddSensor(ctx->joystick, SDL_SENSOR_ACCEL, update_rate);
}
+ if (ctx->guitar_tilt_supported) {
+ float update_rate = 250.0f;
+ SDL_PrivateJoystickAddSensor(ctx->joystick, SDL_SENSOR_ACCEL, update_rate);
+ }
+
ctx->report_battery = true;
HIDAPI_UpdateDeviceProperties(ctx->device);
@@ -964,6 +996,10 @@ static bool HIDAPI_DriverPS5_OpenJoystick(SDL_HIDAPI_Device *device, SDL_Joystic
joystick->nhats = 1;
joystick->firmware_version = ctx->firmware_version;
+ if (ctx->is_dongle) {
+ joystick->connection_state = SDL_JOYSTICK_CONNECTION_WIRELESS;
+ }
+
SDL_AddHintCallback(SDL_HINT_JOYSTICK_ENHANCED_REPORTS,
SDL_PS5EnhancedReportsChanged, ctx);
SDL_AddHintCallback(SDL_HINT_JOYSTICK_HIDAPI_PS5_PLAYER_LED,
@@ -1062,10 +1098,11 @@ static bool HIDAPI_DriverPS5_InternalSendJoystickEffect(SDL_DriverPS5_Context *c
if (ctx->device->is_bluetooth) {
data[0] = k_EPS5ReportIdBluetoothEffects;
- data[1] = 0x02; // Magic value
+ data[1] = 0x00; // Tag and sequence
+ data[2] = 0x10; // Magic value
report_size = 78;
- offset = 2;
+ offset = 3;
} else {
data[0] = k_EPS5ReportIdUsbEffects;
@@ -1122,7 +1159,7 @@ static bool HIDAPI_DriverPS5_SetJoystickSensorsEnabled(SDL_HIDAPI_Device *device
HIDAPI_DriverPS5_UpdateEnhancedModeOnApplicationUsage(ctx);
- if (!ctx->sensors_supported || (enabled && !ctx->enhanced_mode)) {
+ if ((!ctx->sensors_supported || (enabled && !ctx->enhanced_mode)) && !ctx->guitar_tilt_supported) {
return SDL_Unsupported();
}
@@ -1329,7 +1366,7 @@ static void HIDAPI_DriverPS5_HandleStatePacketCommon(SDL_Joystick *joystick, SDL
Uint32 delta;
Uint16 tick = LOAD16(packet->rgucSensorTimestamp[0],
packet->rgucSensorTimestamp[1]);
- if (ctx->last_tick < tick) {
+ if (ctx->last_tick <= tick) {
delta = (tick - ctx->last_tick);
} else {
delta = (SDL_MAX_UINT16 - ctx->last_tick + tick + 1);
@@ -1427,6 +1464,7 @@ static void HIDAPI_DriverPS5_HandleStatePacketAlt(SDL_Joystick *joystick, SDL_hi
static const float TOUCHPAD_SCALEY = 9.34579439e-4f; // 1.0f / 1070
bool touchpad_down;
int touchpad_x, touchpad_y;
+ Sint16 axis;
if (ctx->report_touchpad) {
touchpad_down = ((packet->ucTouchpadCounter1 & 0x80) == 0);
@@ -1440,8 +1478,62 @@ static void HIDAPI_DriverPS5_HandleStatePacketAlt(SDL_Joystick *joystick, SDL_hi
SDL_SendJoystickTouchpad(timestamp, joystick, 0, 1, touchpad_down, touchpad_x * TOUCHPAD_SCALEX, touchpad_y * TOUCHPAD_SCALEY, touchpad_down ? 1.0f : 0.0f);
}
+ if (ctx->report_battery) {
+ SDL_PowerState state;
+ int percent;
+ Uint8 status = (packet->ucBatteryLevel >> 4) & 0x0F;
+ Uint8 level = (packet->ucBatteryLevel & 0x0F);
+
+ // 0x0C means a controller isn't reporting battery levels
+ if (level != 0x0C) {
+ switch (status) {
+ case 0:
+ state = SDL_POWERSTATE_ON_BATTERY;
+ percent = SDL_min(level * 10 + 5, 100);
+ break;
+ case 1:
+ state = SDL_POWERSTATE_CHARGING;
+ percent = SDL_min(level * 10 + 5, 100);
+ break;
+ case 2:
+ state = SDL_POWERSTATE_CHARGED;
+ percent = 100;
+ break;
+ default:
+ state = SDL_POWERSTATE_UNKNOWN;
+ percent = 0;
+ break;
+ }
+ SDL_SendJoystickPowerInfo(joystick, state, percent);
+ }
+ }
+
HIDAPI_DriverPS5_HandleStatePacketCommon(joystick, dev, ctx, (PS5StatePacketCommon_t *)packet, timestamp);
+ if (ctx->guitar_whammy_supported) {
+ axis = ((int)packet->rgucDeviceSpecific[1] * 257) - 32768;
+ SDL_SendJoystickAxis(timestamp, joystick, SDL_GAMEPAD_AXIS_RIGHTX, axis);
+ }
+
+ if (ctx->guitar_effects_selector_supported) {
+ // Align pickup selector mappings with PS3 instruments
+ static const Sint16 effects_mappings[] = {24576, 11008, -1792, -13568, -26880};
+ if (packet->rgucDeviceSpecific[0] < SDL_arraysize(effects_mappings)) {
+ SDL_SendJoystickAxis(timestamp, joystick, SDL_GAMEPAD_AXIS_RIGHTY, effects_mappings[packet->rgucDeviceSpecific[0]]);
+ }
+ }
+
+ if (ctx->guitar_tilt_supported) {
+ float sensor_data[3];
+ sensor_data[0] = ((float)packet->rgucDeviceSpecific[2] / 255) * SDL_STANDARD_GRAVITY;
+ sensor_data[1] = 0;
+ sensor_data[2] = 0;
+ SDL_SendJoystickSensor(timestamp, joystick, SDL_SENSOR_ACCEL, timestamp, sensor_data, SDL_arraysize(sensor_data));
+
+ // Align tilt mappings with PS3 instruments
+ SDL_SendJoystickButton(timestamp, joystick, SDL_GAMEPAD_BUTTON_RIGHT_SHOULDER, packet->rgucDeviceSpecific[2] > 0xF0);
+ }
+
SDL_memcpy(&ctx->last_state, packet, sizeof(ctx->last_state));
}
@@ -1464,15 +1556,16 @@ static bool HIDAPI_DriverPS5_IsPacketValid(SDL_DriverPS5_Context *ctx, Uint8 *da
{
switch (data[0]) {
case k_EPS5ReportIdState:
- if (ctx->is_nacon_dongle && size >= (1 + sizeof(PS5StatePacketAlt_t))) {
+ if (ctx->is_dongle && size >= (1 + sizeof(PS5StatePacketAlt_t))) {
// The report timestamp doesn't change when the controller isn't connected
PS5StatePacketAlt_t *packet = (PS5StatePacketAlt_t *)&data[1];
if (SDL_memcmp(packet->rgucPacketSequence, ctx->last_state.state.rgucPacketSequence, sizeof(packet->rgucPacketSequence)) == 0) {
return false;
}
- if (ctx->last_state.alt_state.rgucAccelX[0] == 0 && ctx->last_state.alt_state.rgucAccelX[1] == 0 &&
- ctx->last_state.alt_state.rgucAccelY[0] == 0 && ctx->last_state.alt_state.rgucAccelY[1] == 0 &&
- ctx->last_state.alt_state.rgucAccelZ[0] == 0 && ctx->last_state.alt_state.rgucAccelZ[1] == 0) {
+ if (ctx->last_state.state.rgucPacketSequence[0] == 0 &&
+ ctx->last_state.state.rgucPacketSequence[1] == 0 &&
+ ctx->last_state.state.rgucPacketSequence[2] == 0 &&
+ ctx->last_state.state.rgucPacketSequence[3] == 0) {
// We don't have any state to compare yet, go ahead and copy it
SDL_memcpy(&ctx->last_state, &data[1], sizeof(PS5StatePacketAlt_t));
return false;
@@ -1571,7 +1664,7 @@ static bool HIDAPI_DriverPS5_UpdateDevice(SDL_HIDAPI_Device *device)
}
}
- if (ctx->is_nacon_dongle) {
+ if (ctx->is_dongle) {
if (packet_count == 0) {
if (device->num_joysticks > 0) {
// Check to see if it looks like the device disconnected
diff --git a/thirdparty/sdl/joystick/hidapi/SDL_hidapi_rumble.c b/thirdparty/sdl/joystick/hidapi/SDL_hidapi_rumble.c
index 5fd93dc0b5a..ef3fede5231 100644
--- a/thirdparty/sdl/joystick/hidapi/SDL_hidapi_rumble.c
+++ b/thirdparty/sdl/joystick/hidapi/SDL_hidapi_rumble.c
@@ -1,6 +1,6 @@
/*
Simple DirectMedia Layer
- Copyright (C) 1997-2025 Sam Lantinga <[email protected]>
+ Copyright (C) 1997-2026 Sam Lantinga <[email protected]>
This software is provided 'as-is', without any express or implied
warranty. In no event will the authors be held liable for any damages
diff --git a/thirdparty/sdl/joystick/hidapi/SDL_hidapi_rumble.h b/thirdparty/sdl/joystick/hidapi/SDL_hidapi_rumble.h
index 0442448dcd9..bcd4a790dcd 100644
--- a/thirdparty/sdl/joystick/hidapi/SDL_hidapi_rumble.h
+++ b/thirdparty/sdl/joystick/hidapi/SDL_hidapi_rumble.h
@@ -1,6 +1,6 @@
/*
Simple DirectMedia Layer
- Copyright (C) 1997-2025 Sam Lantinga <[email protected]>
+ Copyright (C) 1997-2026 Sam Lantinga <[email protected]>
This software is provided 'as-is', without any express or implied
warranty. In no event will the authors be held liable for any damages
diff --git a/thirdparty/sdl/joystick/hidapi/SDL_hidapi_shield.c b/thirdparty/sdl/joystick/hidapi/SDL_hidapi_shield.c
index 10dcea36d93..2b3df213cc0 100644
--- a/thirdparty/sdl/joystick/hidapi/SDL_hidapi_shield.c
+++ b/thirdparty/sdl/joystick/hidapi/SDL_hidapi_shield.c
@@ -1,6 +1,6 @@
/*
Simple DirectMedia Layer
- Copyright (C) 1997-2025 Sam Lantinga <[email protected]>
+ Copyright (C) 1997-2026 Sam Lantinga <[email protected]>
This software is provided 'as-is', without any express or implied
warranty. In no event will the authors be held liable for any damages
@@ -29,7 +29,9 @@
#ifdef SDL_JOYSTICK_HIDAPI_SHIELD
// Define this if you want to log all packets from the controller
-// #define DEBUG_SHIELD_PROTOCOL
+#if 0
+#define DEBUG_SHIELD_PROTOCOL
+#endif
#define CMD_BATTERY_STATE 0x07
#define CMD_RUMBLE 0x39
@@ -138,6 +140,11 @@ static void HIDAPI_DriverShield_SetDevicePlayerIndex(SDL_HIDAPI_Device *device,
static bool HIDAPI_DriverShield_SendCommand(SDL_HIDAPI_Device *device, Uint8 cmd, const void *data, int size)
{
+#ifdef SDL_PLATFORM_MACOS
+ // We hang for several seconds when trying to send output reports on macOS
+ return SDL_Unsupported();
+
+#else
SDL_DriverShield_Context *ctx = (SDL_DriverShield_Context *)device->context;
ShieldCommandReport_t cmd_pkt;
@@ -166,6 +173,8 @@ static bool HIDAPI_DriverShield_SendCommand(SDL_HIDAPI_Device *device, Uint8 cmd
}
return true;
+
+#endif // MACOS
}
static bool HIDAPI_DriverShield_OpenJoystick(SDL_HIDAPI_Device *device, SDL_Joystick *joystick)
@@ -289,6 +298,7 @@ static bool HIDAPI_DriverShield_SetJoystickSensorsEnabled(SDL_HIDAPI_Device *dev
static void HIDAPI_DriverShield_HandleStatePacketV103(SDL_Joystick *joystick, SDL_DriverShield_Context *ctx, Uint8 *data, int size)
{
Uint64 timestamp = SDL_GetTicksNS();
+ Sint16 axis;
if (ctx->last_state[3] != data[3]) {
Uint8 hat;
@@ -346,14 +356,20 @@ static void HIDAPI_DriverShield_HandleStatePacketV103(SDL_Joystick *joystick, SD
SDL_SendJoystickButton(timestamp, joystick, SDL_GAMEPAD_BUTTON_GUIDE, ((data[2] & 0x80) != 0));
}
- SDL_SendJoystickAxis(timestamp, joystick, SDL_GAMEPAD_AXIS_LEFTX, SDL_Swap16LE(*(Sint16 *)&data[4]) - 0x8000);
- SDL_SendJoystickAxis(timestamp, joystick, SDL_GAMEPAD_AXIS_LEFTY, SDL_Swap16LE(*(Sint16 *)&data[6]) - 0x8000);
+ axis = LOAD16(data[4], data[5]) - 0x8000;
+ SDL_SendJoystickAxis(timestamp, joystick, SDL_GAMEPAD_AXIS_LEFTX, axis);
+ axis = LOAD16(data[6], data[7]) - 0x8000;
+ SDL_SendJoystickAxis(timestamp, joystick, SDL_GAMEPAD_AXIS_LEFTY, axis);
- SDL_SendJoystickAxis(timestamp, joystick, SDL_GAMEPAD_AXIS_RIGHTX, SDL_Swap16LE(*(Sint16 *)&data[8]) - 0x8000);
- SDL_SendJoystickAxis(timestamp, joystick, SDL_GAMEPAD_AXIS_RIGHTY, SDL_Swap16LE(*(Sint16 *)&data[10]) - 0x8000);
+ axis = LOAD16(data[8], data[9]) - 0x8000;
+ SDL_SendJoystickAxis(timestamp, joystick, SDL_GAMEPAD_AXIS_RIGHTX, axis);
+ axis = LOAD16(data[10], data[11]) - 0x8000;
+ SDL_SendJoystickAxis(timestamp, joystick, SDL_GAMEPAD_AXIS_RIGHTY, axis);
- SDL_SendJoystickAxis(timestamp, joystick, SDL_GAMEPAD_AXIS_LEFT_TRIGGER, SDL_Swap16LE(*(Sint16 *)&data[12]) - 0x8000);
- SDL_SendJoystickAxis(timestamp, joystick, SDL_GAMEPAD_AXIS_RIGHT_TRIGGER, SDL_Swap16LE(*(Sint16 *)&data[14]) - 0x8000);
+ axis = LOAD16(data[12], data[13]) - 0x8000;
+ SDL_SendJoystickAxis(timestamp, joystick, SDL_GAMEPAD_AXIS_LEFT_TRIGGER, axis);
+ axis = LOAD16(data[14], data[15]) - 0x8000;
+ SDL_SendJoystickAxis(timestamp, joystick, SDL_GAMEPAD_AXIS_RIGHT_TRIGGER, axis);
SDL_memcpy(ctx->last_state, data, SDL_min(size, sizeof(ctx->last_state)));
}
@@ -379,6 +395,7 @@ static void HIDAPI_DriverShield_HandleTouchPacketV103(SDL_Joystick *joystick, SD
static void HIDAPI_DriverShield_HandleStatePacketV104(SDL_Joystick *joystick, SDL_DriverShield_Context *ctx, Uint8 *data, int size)
{
Uint64 timestamp = SDL_GetTicksNS();
+ Sint16 axis;
if (size < 23) {
return;
@@ -434,14 +451,20 @@ static void HIDAPI_DriverShield_HandleStatePacketV104(SDL_Joystick *joystick, SD
SDL_SendJoystickButton(timestamp, joystick, SDL_GAMEPAD_BUTTON_START, ((data[4] & 0x01) != 0));
}
- SDL_SendJoystickAxis(timestamp, joystick, SDL_GAMEPAD_AXIS_LEFTX, SDL_Swap16LE(*(Sint16 *)&data[9]) - 0x8000);
- SDL_SendJoystickAxis(timestamp, joystick, SDL_GAMEPAD_AXIS_LEFTY, SDL_Swap16LE(*(Sint16 *)&data[11]) - 0x8000);
+ axis = LOAD16(data[9], data[10]) - 0x8000;
+ SDL_SendJoystickAxis(timestamp, joystick, SDL_GAMEPAD_AXIS_LEFTX, axis);
+ axis = LOAD16(data[11], data[12]) - 0x8000;
+ SDL_SendJoystickAxis(timestamp, joystick, SDL_GAMEPAD_AXIS_LEFTY, axis);
- SDL_SendJoystickAxis(timestamp, joystick, SDL_GAMEPAD_AXIS_RIGHTX, SDL_Swap16LE(*(Sint16 *)&data[13]) - 0x8000);
- SDL_SendJoystickAxis(timestamp, joystick, SDL_GAMEPAD_AXIS_RIGHTY, SDL_Swap16LE(*(Sint16 *)&data[15]) - 0x8000);
+ axis = LOAD16(data[13], data[14]) - 0x8000;
+ SDL_SendJoystickAxis(timestamp, joystick, SDL_GAMEPAD_AXIS_RIGHTX, axis);
+ axis = LOAD16(data[15], data[16]) - 0x8000;
+ SDL_SendJoystickAxis(timestamp, joystick, SDL_GAMEPAD_AXIS_RIGHTY, axis);
- SDL_SendJoystickAxis(timestamp, joystick, SDL_GAMEPAD_AXIS_LEFT_TRIGGER, SDL_Swap16LE(*(Sint16 *)&data[19]) - 0x8000);
- SDL_SendJoystickAxis(timestamp, joystick, SDL_GAMEPAD_AXIS_RIGHT_TRIGGER, SDL_Swap16LE(*(Sint16 *)&data[21]) - 0x8000);
+ axis = LOAD16(data[19], data[20]) - 0x8000;
+ SDL_SendJoystickAxis(timestamp, joystick, SDL_GAMEPAD_AXIS_LEFT_TRIGGER, axis);
+ axis = LOAD16(data[21], data[22]) - 0x8000;
+ SDL_SendJoystickAxis(timestamp, joystick, SDL_GAMEPAD_AXIS_RIGHT_TRIGGER, axis);
if (ctx->last_state[17] != data[17]) {
//SDL_SendJoystickButton(timestamp, joystick, SDL_GAMEPAD_BUTTON_SHIELD_SHARE, ((data[17] & 0x01) != 0));
@@ -482,13 +505,13 @@ static bool HIDAPI_DriverShield_UpdateDevice(SDL_HIDAPI_Device *device)
#ifdef DEBUG_SHIELD_PROTOCOL
HIDAPI_DumpPacket("NVIDIA SHIELD packet: size = %d", data, size);
#endif
+ if (!joystick) {
+ continue;
+ }
// Byte 0 is HID report ID
switch (data[0]) {
case k_ShieldReportIdControllerState:
- if (!joystick) {
- break;
- }
if (size == 16) {
HIDAPI_DriverShield_HandleStatePacketV103(joystick, ctx, data, size);
} else {
@@ -496,9 +519,6 @@ static bool HIDAPI_DriverShield_UpdateDevice(SDL_HIDAPI_Device *device)
}
break;
case k_ShieldReportIdControllerTouch:
- if (!joystick) {
- break;
- }
HIDAPI_DriverShield_HandleTouchPacketV103(joystick, ctx, data, size);
break;
case k_ShieldReportIdCommandResponse:
diff --git a/thirdparty/sdl/joystick/hidapi/SDL_hidapi_sinput.c b/thirdparty/sdl/joystick/hidapi/SDL_hidapi_sinput.c
new file mode 100644
index 00000000000..6cef12a33b6
--- /dev/null
+++ b/thirdparty/sdl/joystick/hidapi/SDL_hidapi_sinput.c
@@ -0,0 +1,1134 @@
+/*
+ Simple DirectMedia Layer
+ Copyright (C) 2025 Mitchell Cairns <[email protected]>
+
+ 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"
+
+#ifdef SDL_JOYSTICK_HIDAPI
+
+#include "../../SDL_hints_c.h"
+#include "../SDL_sysjoystick.h"
+
+#include "SDL_hidapijoystick_c.h"
+#include "SDL_hidapi_rumble.h"
+#include "SDL_hidapi_sinput.h"
+
+#ifdef SDL_JOYSTICK_HIDAPI_SINPUT
+
+/*****************************************************************************************************/
+// This protocol is documented at:
+// https://docs.handheldlegend.com/s/sinput
+/*****************************************************************************************************/
+
+// Define this if you want to log all packets from the controller
+#if 0
+#define DEBUG_SINPUT_PROTOCOL
+#endif
+
+#if 0
+#define DEBUG_SINPUT_INIT
+#endif
+
+#define SINPUT_DEVICE_REPORT_SIZE 64 // Size of input reports (And CMD Input reports)
+#define SINPUT_DEVICE_REPORT_COMMAND_SIZE 48 // Size of command OUTPUT reports
+
+#define SINPUT_DEVICE_REPORT_ID_JOYSTICK_INPUT 0x01
+#define SINPUT_DEVICE_REPORT_ID_INPUT_CMDDAT 0x02
+#define SINPUT_DEVICE_REPORT_ID_OUTPUT_CMDDAT 0x03
+
+#define SINPUT_DEVICE_COMMAND_HAPTIC 0x01
+#define SINPUT_DEVICE_COMMAND_FEATURES 0x02
+#define SINPUT_DEVICE_COMMAND_PLAYERLED 0x03
+#define SINPUT_DEVICE_COMMAND_JOYSTICKRGB 0x04
+
+#define SINPUT_HAPTIC_TYPE_PRECISE 0x01
+#define SINPUT_HAPTIC_TYPE_ERMSIMULATION 0x02
+
+#define SINPUT_DEFAULT_GYRO_SENS 2000
+#define SINPUT_DEFAULT_ACCEL_SENS 8
+
+#define SINPUT_REPORT_IDX_BUTTONS_0 3
+#define SINPUT_REPORT_IDX_BUTTONS_1 4
+#define SINPUT_REPORT_IDX_BUTTONS_2 5
+#define SINPUT_REPORT_IDX_BUTTONS_3 6
+#define SINPUT_REPORT_IDX_LEFT_X 7
+#define SINPUT_REPORT_IDX_LEFT_Y 9
+#define SINPUT_REPORT_IDX_RIGHT_X 11
+#define SINPUT_REPORT_IDX_RIGHT_Y 13
+#define SINPUT_REPORT_IDX_LEFT_TRIGGER 15
+#define SINPUT_REPORT_IDX_RIGHT_TRIGGER 17
+#define SINPUT_REPORT_IDX_IMU_TIMESTAMP 19
+#define SINPUT_REPORT_IDX_IMU_ACCEL_X 23
+#define SINPUT_REPORT_IDX_IMU_ACCEL_Y 25
+#define SINPUT_REPORT_IDX_IMU_ACCEL_Z 27
+#define SINPUT_REPORT_IDX_IMU_GYRO_X 29
+#define SINPUT_REPORT_IDX_IMU_GYRO_Y 31
+#define SINPUT_REPORT_IDX_IMU_GYRO_Z 33
+#define SINPUT_REPORT_IDX_TOUCH1_X 35
+#define SINPUT_REPORT_IDX_TOUCH1_Y 37
+#define SINPUT_REPORT_IDX_TOUCH1_P 39
+#define SINPUT_REPORT_IDX_TOUCH2_X 41
+#define SINPUT_REPORT_IDX_TOUCH2_Y 43
+#define SINPUT_REPORT_IDX_TOUCH2_P 45
+
+#define SINPUT_BUTTON_IDX_EAST 0
+#define SINPUT_BUTTON_IDX_SOUTH 1
+#define SINPUT_BUTTON_IDX_NORTH 2
+#define SINPUT_BUTTON_IDX_WEST 3
+#define SINPUT_BUTTON_IDX_DPAD_UP 4
+#define SINPUT_BUTTON_IDX_DPAD_DOWN 5
+#define SINPUT_BUTTON_IDX_DPAD_LEFT 6
+#define SINPUT_BUTTON_IDX_DPAD_RIGHT 7
+#define SINPUT_BUTTON_IDX_LEFT_STICK 8
+#define SINPUT_BUTTON_IDX_RIGHT_STICK 9
+#define SINPUT_BUTTON_IDX_LEFT_BUMPER 10
+#define SINPUT_BUTTON_IDX_RIGHT_BUMPER 11
+#define SINPUT_BUTTON_IDX_LEFT_TRIGGER 12
+#define SINPUT_BUTTON_IDX_RIGHT_TRIGGER 13
+#define SINPUT_BUTTON_IDX_LEFT_PADDLE1 14
+#define SINPUT_BUTTON_IDX_RIGHT_PADDLE1 15
+#define SINPUT_BUTTON_IDX_START 16
+#define SINPUT_BUTTON_IDX_BACK 17
+#define SINPUT_BUTTON_IDX_GUIDE 18
+#define SINPUT_BUTTON_IDX_CAPTURE 19
+#define SINPUT_BUTTON_IDX_LEFT_PADDLE2 20
+#define SINPUT_BUTTON_IDX_RIGHT_PADDLE2 21
+#define SINPUT_BUTTON_IDX_TOUCHPAD1 22
+#define SINPUT_BUTTON_IDX_TOUCHPAD2 23
+#define SINPUT_BUTTON_IDX_POWER 24
+#define SINPUT_BUTTON_IDX_MISC4 25
+#define SINPUT_BUTTON_IDX_MISC5 26
+#define SINPUT_BUTTON_IDX_MISC6 27
+#define SINPUT_BUTTON_IDX_MISC7 28
+#define SINPUT_BUTTON_IDX_MISC8 29
+#define SINPUT_BUTTON_IDX_MISC9 30
+#define SINPUT_BUTTON_IDX_MISC10 31
+
+#define SINPUT_BUTTONMASK_EAST 0x01
+#define SINPUT_BUTTONMASK_SOUTH 0x02
+#define SINPUT_BUTTONMASK_NORTH 0x04
+#define SINPUT_BUTTONMASK_WEST 0x08
+#define SINPUT_BUTTONMASK_DPAD_UP 0x10
+#define SINPUT_BUTTONMASK_DPAD_DOWN 0x20
+#define SINPUT_BUTTONMASK_DPAD_LEFT 0x40
+#define SINPUT_BUTTONMASK_DPAD_RIGHT 0x80
+#define SINPUT_BUTTONMASK_LEFT_STICK 0x01
+#define SINPUT_BUTTONMASK_RIGHT_STICK 0x02
+#define SINPUT_BUTTONMASK_LEFT_BUMPER 0x04
+#define SINPUT_BUTTONMASK_RIGHT_BUMPER 0x08
+#define SINPUT_BUTTONMASK_LEFT_TRIGGER 0x10
+#define SINPUT_BUTTONMASK_RIGHT_TRIGGER 0x20
+#define SINPUT_BUTTONMASK_LEFT_PADDLE1 0x40
+#define SINPUT_BUTTONMASK_RIGHT_PADDLE1 0x80
+#define SINPUT_BUTTONMASK_START 0x01
+#define SINPUT_BUTTONMASK_BACK 0x02
+#define SINPUT_BUTTONMASK_GUIDE 0x04
+#define SINPUT_BUTTONMASK_CAPTURE 0x08
+#define SINPUT_BUTTONMASK_LEFT_PADDLE2 0x10
+#define SINPUT_BUTTONMASK_RIGHT_PADDLE2 0x20
+#define SINPUT_BUTTONMASK_TOUCHPAD1 0x40
+#define SINPUT_BUTTONMASK_TOUCHPAD2 0x80
+#define SINPUT_BUTTONMASK_POWER 0x01
+#define SINPUT_BUTTONMASK_MISC4 0x02
+#define SINPUT_BUTTONMASK_MISC5 0x04
+#define SINPUT_BUTTONMASK_MISC6 0x08
+#define SINPUT_BUTTONMASK_MISC7 0x10
+#define SINPUT_BUTTONMASK_MISC8 0x20
+#define SINPUT_BUTTONMASK_MISC9 0x40
+#define SINPUT_BUTTONMASK_MISC10 0x80
+
+#define SINPUT_REPORT_IDX_COMMAND_RESPONSE_ID 1
+#define SINPUT_REPORT_IDX_COMMAND_RESPONSE_BULK 2
+
+#define SINPUT_REPORT_IDX_PLUG_STATUS 1
+#define SINPUT_REPORT_IDX_CHARGE_LEVEL 2
+
+#define SINPUT_MAX_ALLOWED_TOUCHPADS 2
+
+#ifndef EXTRACTSINT16
+#define EXTRACTSINT16(data, idx) ((Sint16)((data)[(idx)] | ((data)[(idx) + 1] << 8)))
+#endif
+
+#ifndef EXTRACTUINT16
+#define EXTRACTUINT16(data, idx) ((Uint16)((data)[(idx)] | ((data)[(idx) + 1] << 8)))
+#endif
+
+#ifndef EXTRACTUINT32
+#define EXTRACTUINT32(data, idx) ((Uint32)((data)[(idx)] | ((data)[(idx) + 1] << 8) | ((data)[(idx) + 2] << 16) | ((data)[(idx) + 3] << 24)))
+#endif
+
+typedef struct
+{
+ uint8_t type;
+
+ union {
+ // Frequency Amplitude pairs
+ struct {
+ struct {
+ uint16_t frequency_1;
+ uint16_t amplitude_1;
+ uint16_t frequency_2;
+ uint16_t amplitude_2;
+ } left;
+
+ struct {
+ uint16_t frequency_1;
+ uint16_t amplitude_1;
+ uint16_t frequency_2;
+ uint16_t amplitude_2;
+ } right;
+
+ } type_1;
+
+ // Basic ERM simulation model
+ struct {
+ struct {
+ uint8_t amplitude;
+ bool brake;
+ } left;
+
+ struct {
+ uint8_t amplitude;
+ bool brake;
+ } right;
+
+ } type_2;
+ };
+} SINPUT_HAPTIC_S;
+
+typedef struct
+{
+ SDL_HIDAPI_Device *device;
+ Uint16 protocol_version;
+ Uint16 usb_device_version;
+ bool sensors_enabled;
+
+ Uint8 player_idx;
+
+ bool player_leds_supported;
+ bool joystick_rgb_supported;
+ bool rumble_supported;
+ bool accelerometer_supported;
+ bool gyroscope_supported;
+ bool left_analog_stick_supported;
+ bool right_analog_stick_supported;
+ bool left_analog_trigger_supported;
+ bool right_analog_trigger_supported;
+ bool dpad_supported;
+ bool touchpad_supported;
+ bool is_handheld;
+
+ Uint8 touchpad_count; // 2 touchpads maximum
+ Uint8 touchpad_finger_count; // 2 fingers for one touchpad, or 1 per touchpad (2 max)
+
+ Uint16 polling_rate_us;
+ Uint8 sub_product; // Subtype of the device, 0 in most cases
+
+ Uint16 accelRange; // Example would be 2,4,8,16 +/- (g-force)
+ Uint16 gyroRange; // Example would be 1000,2000,4000 +/- (degrees per second)
+
+ float accelScale; // Scale factor for accelerometer values
+ float gyroScale; // Scale factor for gyroscope values
+ Uint8 last_state[USB_PACKET_LENGTH];
+
+ Uint8 axes_count;
+ Uint8 buttons_count;
+ Uint8 usage_masks[4];
+
+ Uint32 last_imu_timestamp_us;
+
+ Uint64 imu_timestamp_ns; // Nanoseconds. We accumulate with received deltas
+} SDL_DriverSInput_Context;
+
+// Converts raw int16_t gyro scale setting
+static inline float CalculateGyroScale(uint16_t dps_range)
+{
+ return SDL_PI_F / 180.0f / (32768.0f / (float)dps_range);
+}
+
+// Converts raw int16_t accel scale setting
+static inline float CalculateAccelScale(uint16_t g_range)
+{
+ return SDL_STANDARD_GRAVITY / (32768.0f / (float)g_range);
+}
+
+// This function uses base-n encoding to encode features into the version GUID bytes
+// that properly represents the supported device features
+// This also sets the driver context button mask correctly based on the features
+static void DeviceDynamicEncodingSetup(SDL_HIDAPI_Device *device)
+{
+ SDL_DriverSInput_Context *ctx = device->context;
+
+ // A new button mask is generated to provide
+ // SDL with a mapping string that is sane. In case of
+ // an unconventional gamepad setup, the closest sane
+ // mapping is provided to the driver.
+ Uint8 mask[4] = { 0 };
+
+ // For all gamepads, there is a minimum SInput expectation
+ // to have dpad, abxy, and start buttons
+
+ // ABXY + D-Pad
+ mask[0] = 0xFF;
+ ctx->dpad_supported = true;
+
+ // Start button
+ mask[2] |= SINPUT_BUTTONMASK_START;
+
+ // Bumpers
+ bool left_bumper = (ctx->usage_masks[1] & SINPUT_BUTTONMASK_LEFT_BUMPER) != 0;
+ bool right_bumper = (ctx->usage_masks[1] & SINPUT_BUTTONMASK_RIGHT_BUMPER) != 0;
+
+ int bumperStyle = SINPUT_BUMPERSTYLE_NONE;
+ if (left_bumper && right_bumper) {
+ bumperStyle = SINPUT_BUMPERSTYLE_TWO;
+ mask[1] |= (SINPUT_BUTTONMASK_LEFT_BUMPER | SINPUT_BUTTONMASK_RIGHT_BUMPER);
+ } else if (left_bumper || right_bumper) {
+ bumperStyle = SINPUT_BUMPERSTYLE_ONE;
+
+ if (left_bumper) {
+ mask[1] |= SINPUT_BUTTONMASK_LEFT_BUMPER;
+ } else if (right_bumper) {
+ mask[1] |= SINPUT_BUTTONMASK_RIGHT_BUMPER;
+ }
+ }
+
+ // Trigger bits live in mask[1]
+ bool digital_triggers = (ctx->usage_masks[1] & (SINPUT_BUTTONMASK_LEFT_TRIGGER | SINPUT_BUTTONMASK_RIGHT_TRIGGER)) != 0;
+
+ bool analog_triggers = ctx->left_analog_trigger_supported || ctx->right_analog_trigger_supported;
+
+ // Touchpads
+ bool t1 = (ctx->usage_masks[2] & SINPUT_BUTTONMASK_TOUCHPAD1) != 0;
+ bool t2 = (ctx->usage_masks[2] & SINPUT_BUTTONMASK_TOUCHPAD2) != 0;
+
+ int analogStyle = SINPUT_ANALOGSTYLE_NONE;
+ if (ctx->left_analog_stick_supported && ctx->right_analog_stick_supported) {
+ analogStyle = SINPUT_ANALOGSTYLE_LEFTRIGHT;
+ mask[1] |= (SINPUT_BUTTONMASK_LEFT_STICK | SINPUT_BUTTONMASK_RIGHT_STICK);
+ } else if (ctx->left_analog_stick_supported) {
+ analogStyle = SINPUT_ANALOGSTYLE_LEFTONLY;
+ mask[1] |= SINPUT_BUTTONMASK_LEFT_STICK;
+ } else if (ctx->right_analog_stick_supported) {
+ analogStyle = SINPUT_ANALOGSTYLE_RIGHTONLY;
+ mask[1] |= SINPUT_BUTTONMASK_RIGHT_STICK;
+ }
+
+ int triggerStyle = SINPUT_TRIGGERSTYLE_NONE;
+
+ if (analog_triggers && digital_triggers) {
+ // When we have both analog triggers and digital triggers
+ // this is interpreted as having dual-stage triggers
+ triggerStyle = SINPUT_TRIGGERSTYLE_DUALSTAGE;
+ mask[1] |= (SINPUT_BUTTONMASK_LEFT_TRIGGER | SINPUT_BUTTONMASK_RIGHT_TRIGGER);
+ } else if (analog_triggers) {
+ triggerStyle = SINPUT_TRIGGERSTYLE_ANALOG;
+ } else if (digital_triggers) {
+ triggerStyle = SINPUT_TRIGGERSTYLE_DIGITAL;
+ mask[1] |= (SINPUT_BUTTONMASK_LEFT_TRIGGER | SINPUT_BUTTONMASK_RIGHT_TRIGGER);
+ }
+
+ // Paddle bits may touch mask[1] and mask[2]
+ bool pg1 = (ctx->usage_masks[1] & (SINPUT_BUTTONMASK_LEFT_PADDLE1 | SINPUT_BUTTONMASK_RIGHT_PADDLE1)) != 0;
+ bool pg2 = (ctx->usage_masks[2] & (SINPUT_BUTTONMASK_LEFT_PADDLE2 | SINPUT_BUTTONMASK_RIGHT_PADDLE2)) != 0;
+
+ int paddleStyle = SINPUT_PADDLESTYLE_NONE;
+ if (pg1 && pg2) {
+ paddleStyle = SINPUT_PADDLESTYLE_FOUR;
+ mask[1] |= (SINPUT_BUTTONMASK_LEFT_PADDLE1 | SINPUT_BUTTONMASK_RIGHT_PADDLE1);
+ mask[2] |= (SINPUT_BUTTONMASK_LEFT_PADDLE2 | SINPUT_BUTTONMASK_RIGHT_PADDLE2);
+ } else if (pg1) {
+ paddleStyle = SINPUT_PADDLESTYLE_TWO;
+ mask[1] |= (SINPUT_BUTTONMASK_LEFT_PADDLE1 | SINPUT_BUTTONMASK_RIGHT_PADDLE1);
+ }
+
+
+ // Meta Buttons (Back, Guide, Share)
+ bool back = (ctx->usage_masks[2] & SINPUT_BUTTONMASK_BACK) != 0;
+ bool guide = (ctx->usage_masks[2] & SINPUT_BUTTONMASK_GUIDE) != 0;
+ bool share = (ctx->usage_masks[2] & SINPUT_BUTTONMASK_CAPTURE) != 0;
+
+ int metaStyle = SINPUT_METASTYLE_NONE;
+ if (share) {
+ metaStyle = SINPUT_METASTYLE_BACKGUIDESHARE;
+ mask[2] |= (SINPUT_BUTTONMASK_BACK | SINPUT_BUTTONMASK_GUIDE | SINPUT_BUTTONMASK_CAPTURE);
+ } else if (guide) {
+ metaStyle = SINPUT_METASTYLE_BACKGUIDE;
+ mask[2] |= (SINPUT_BUTTONMASK_BACK | SINPUT_BUTTONMASK_GUIDE);
+ } else if (back) {
+ metaStyle = SINPUT_METASTYLE_BACK;
+ mask[2] |= (SINPUT_BUTTONMASK_BACK);
+ }
+
+ int touchStyle = SINPUT_TOUCHSTYLE_NONE;
+ if (t1 && t2) {
+ touchStyle = SINPUT_TOUCHSTYLE_DOUBLE;
+ mask[2] |= (SINPUT_BUTTONMASK_TOUCHPAD1 | SINPUT_BUTTONMASK_TOUCHPAD2);
+ } else if (t1) {
+ touchStyle = SINPUT_TOUCHSTYLE_SINGLE;
+ mask[2] |= SINPUT_BUTTONMASK_TOUCHPAD1;
+ }
+
+ // Misc Buttons
+ int miscStyle = SINPUT_MISCSTYLE_NONE;
+ Uint8 extra_misc = ctx->usage_masks[3] & 0x0F;
+ switch (extra_misc) {
+ case 0x0F:
+ miscStyle = SINPUT_MISCSTYLE_4;
+ mask[3] = 0x0F;
+ break;
+ case 0x07:
+ miscStyle = SINPUT_MISCSTYLE_3;
+ mask[3] = 0x07;
+ break;
+ case 0x03:
+ miscStyle = SINPUT_MISCSTYLE_2;
+ mask[3] = 0x03;
+ break;
+ case 0x01:
+ miscStyle = SINPUT_MISCSTYLE_1;
+ mask[3] = 0x01;
+ break;
+ default:
+ miscStyle = SINPUT_MISCSTYLE_NONE;
+ mask[3] = 0x00;
+ break;
+ }
+
+ int version = analogStyle;
+ version = (version * (int)SINPUT_BUMPERSTYLE_MAX) + bumperStyle;
+ version = (version * (int)SINPUT_TRIGGERSTYLE_MAX) + triggerStyle;
+ version = (version * (int)SINPUT_PADDLESTYLE_MAX) + paddleStyle;
+ version = (version * (int)SINPUT_METASTYLE_MAX) + metaStyle;
+ version = (version * (int)SINPUT_TOUCHSTYLE_MAX) + touchStyle;
+ version = (version * (int)SINPUT_MISCSTYLE_MAX) + miscStyle;
+
+ // Overwrite our button usage masks
+ // with our sanitized masks
+ ctx->usage_masks[0] = mask[0];
+ ctx->usage_masks[1] = mask[1];
+ ctx->usage_masks[2] = mask[2];
+ ctx->usage_masks[3] = mask[3];
+
+ version = SDL_clamp(version, 0, UINT16_MAX);
+
+ // Overwrite 'Version' field of the GUID data
+ device->guid.data[12] = (Uint8)(version & 0xFF);
+ device->guid.data[13] = (Uint8)(version >> 8);
+}
+
+
+static void ProcessSDLFeaturesResponse(SDL_HIDAPI_Device *device, Uint8 *data)
+{
+ SDL_DriverSInput_Context *ctx = (SDL_DriverSInput_Context *)device->context;
+
+ // Obtain protocol version
+ ctx->protocol_version = EXTRACTUINT16(data, 0);
+
+ // Bitfields are not portable, so we unpack them into a struct value
+ ctx->rumble_supported = (data[2] & 0x01) != 0;
+ ctx->player_leds_supported = (data[2] & 0x02) != 0;
+ ctx->accelerometer_supported = (data[2] & 0x04) != 0;
+ ctx->gyroscope_supported = (data[2] & 0x08) != 0;
+
+ ctx->left_analog_stick_supported = (data[2] & 0x10) != 0;
+ ctx->right_analog_stick_supported = (data[2] & 0x20) != 0;
+ ctx->left_analog_trigger_supported = (data[2] & 0x40) != 0;
+ ctx->right_analog_trigger_supported = (data[2] & 0x80) != 0;
+
+ ctx->touchpad_supported = (data[3] & 0x01) != 0;
+ ctx->joystick_rgb_supported = (data[3] & 0x02) != 0;
+
+ ctx->is_handheld = (data[3] & 0x04) != 0;
+
+ // The gamepad type represents a style of gamepad that most closely
+ // resembles the gamepad in question (Button style, button layout)
+ SDL_GamepadType type = SDL_GAMEPAD_TYPE_UNKNOWN;
+ type = (SDL_GamepadType)SDL_clamp(data[4], SDL_GAMEPAD_TYPE_UNKNOWN, SDL_GAMEPAD_TYPE_COUNT);
+ device->type = type;
+
+ // The 3 MSB represent a button layout style SDL_GamepadFaceStyle
+ // The 5 LSB represent a device sub-type
+ device->guid.data[15] = data[5];
+
+ ctx->sub_product = (data[5] & 0x1F);
+
+#if defined(DEBUG_SINPUT_INIT)
+ SDL_Log("SInput Face Style: %d", (data[5] & 0xE0) >> 5);
+ SDL_Log("SInput Sub-product: %d", (data[5] & 0x1F));
+#endif
+
+ ctx->polling_rate_us = EXTRACTUINT16(data, 6);
+
+#if defined(DEBUG_SINPUT_INIT)
+ SDL_Log("SInput polling interval (microseconds): %d", ctx->polling_rate_us);
+#endif
+
+ ctx->accelRange = EXTRACTUINT16(data, 8);
+ ctx->gyroRange = EXTRACTUINT16(data, 10);
+
+ ctx->usage_masks[0] = data[12];
+ ctx->usage_masks[1] = data[13];
+ ctx->usage_masks[2] = data[14];
+ ctx->usage_masks[3] = data[15];
+
+ // Get and validate touchpad parameters
+ ctx->touchpad_count = data[16];
+ ctx->touchpad_finger_count = data[17];
+
+ // Get device Serial - MAC address
+ char serial[18];
+ (void)SDL_snprintf(serial, sizeof(serial), "%.2x-%.2x-%.2x-%.2x-%.2x-%.2x",
+ data[18], data[19], data[20], data[21], data[22], data[23]);
+
+#if defined(DEBUG_SINPUT_INIT)
+ SDL_Log("Serial num: %s", serial);
+#endif
+ HIDAPI_SetDeviceSerial(device, serial);
+
+#if defined(DEBUG_SINPUT_INIT)
+ SDL_Log("Accelerometer Range: %d", ctx->accelRange);
+#endif
+
+#if defined(DEBUG_SINPUT_INIT)
+ SDL_Log("Gyro Range: %d", ctx->gyroRange);
+#endif
+
+ ctx->accelScale = CalculateAccelScale(ctx->accelRange);
+ ctx->gyroScale = CalculateGyroScale(ctx->gyroRange);
+
+ Uint8 axes = 0;
+ if (ctx->left_analog_stick_supported) {
+ axes += 2;
+ }
+
+ if (ctx->right_analog_stick_supported) {
+ axes += 2;
+ }
+
+ if (ctx->left_analog_trigger_supported || ctx->right_analog_trigger_supported) {
+ // Always add both analog trigger axes if one is present
+ axes += 2;
+ }
+
+ ctx->axes_count = axes;
+
+ DeviceDynamicEncodingSetup(device);
+
+ // Derive button count from mask
+ for (Uint8 byte = 0; byte < 4; ++byte) {
+ for (Uint8 bit = 0; bit < 8; ++bit) {
+ if ((ctx->usage_masks[byte] & (1 << bit)) != 0) {
+ ++ctx->buttons_count;
+ }
+ }
+ }
+
+ // Convert DPAD to hat
+ const int DPAD_MASK = (1 << SINPUT_BUTTON_IDX_DPAD_UP) |
+ (1 << SINPUT_BUTTON_IDX_DPAD_DOWN) |
+ (1 << SINPUT_BUTTON_IDX_DPAD_LEFT) |
+ (1 << SINPUT_BUTTON_IDX_DPAD_RIGHT);
+ if ((ctx->usage_masks[0] & DPAD_MASK) == DPAD_MASK) {
+ ctx->dpad_supported = true;
+ ctx->usage_masks[0] &= ~DPAD_MASK;
+ ctx->buttons_count -= 4;
+ }
+
+#if defined(DEBUG_SINPUT_INIT)
+ SDL_Log("Buttons count: %d", ctx->buttons_count);
+#endif
+}
+
+static bool RetrieveSDLFeatures(SDL_HIDAPI_Device *device)
+{
+ int written = 0;
+
+ // Attempt to send the SDL features get command.
+ for (int attempt = 0; attempt < 8; ++attempt) {
+ const Uint8 featuresGetCommand[SINPUT_DEVICE_REPORT_COMMAND_SIZE] = { SINPUT_DEVICE_REPORT_ID_OUTPUT_CMDDAT, SINPUT_DEVICE_COMMAND_FEATURES };
+ // This write will occasionally return -1, so ignore failure here and try again
+ written = SDL_hid_write(device->dev, featuresGetCommand, sizeof(featuresGetCommand));
+
+ if (written == SINPUT_DEVICE_REPORT_COMMAND_SIZE) {
+ break;
+ }
+ }
+
+ if (written < SINPUT_DEVICE_REPORT_COMMAND_SIZE) {
+ SDL_SetError("SInput device SDL Features GET command could not write");
+ return false;
+ }
+
+ int read = 0;
+
+ // Read the reply
+ for (int i = 0; i < 100; ++i) {
+ SDL_Delay(1);
+
+ Uint8 data[USB_PACKET_LENGTH];
+ read = SDL_hid_read_timeout(device->dev, data, sizeof(data), 0);
+ if (read < 0) {
+ SDL_SetError("SInput device SDL Features GET command could not read");
+ return false;
+ }
+ if (read == 0) {
+ continue;
+ }
+
+#ifdef DEBUG_SINPUT_PROTOCOL
+ HIDAPI_DumpPacket("SInput packet: size = %d", data, read);
+#endif
+
+ if ((read == USB_PACKET_LENGTH) && (data[0] == SINPUT_DEVICE_REPORT_ID_INPUT_CMDDAT) && (data[1] == SINPUT_DEVICE_COMMAND_FEATURES)) {
+ ProcessSDLFeaturesResponse(device, &(data[SINPUT_REPORT_IDX_COMMAND_RESPONSE_BULK]));
+#if defined(DEBUG_SINPUT_INIT)
+ SDL_Log("Received SInput SDL Features command response");
+#endif
+ return true;
+ }
+ }
+
+ return false;
+}
+
+// Type 2 haptics are for more traditional rumble such as
+// ERM motors or simulated ERM motors
+static inline void HapticsType2Pack(SINPUT_HAPTIC_S *in, Uint8 *out)
+{
+ // Type of haptics
+ out[0] = 2;
+
+ out[1] = in->type_2.left.amplitude;
+ out[2] = in->type_2.left.brake;
+
+ out[3] = in->type_2.right.amplitude;
+ out[4] = in->type_2.right.brake;
+}
+
+static void HIDAPI_DriverSInput_RegisterHints(SDL_HintCallback callback, void *userdata)
+{
+ SDL_AddHintCallback(SDL_HINT_JOYSTICK_HIDAPI_SINPUT, callback, userdata);
+}
+
+static void HIDAPI_DriverSInput_UnregisterHints(SDL_HintCallback callback, void *userdata)
+{
+ SDL_RemoveHintCallback(SDL_HINT_JOYSTICK_HIDAPI_SINPUT, callback, userdata);
+}
+
+static bool HIDAPI_DriverSInput_IsEnabled(void)
+{
+ return SDL_GetHintBoolean(SDL_HINT_JOYSTICK_HIDAPI_SINPUT, SDL_GetHintBoolean(SDL_HINT_JOYSTICK_HIDAPI, SDL_HIDAPI_DEFAULT));
+}
+
+static bool HIDAPI_DriverSInput_IsSupportedDevice(SDL_HIDAPI_Device *device, const char *name, SDL_GamepadType type, Uint16 vendor_id, Uint16 product_id, Uint16 version, int interface_number, int interface_class, int interface_subclass, int interface_protocol)
+{
+ return SDL_IsJoystickSInputController(vendor_id, product_id);
+}
+
+static bool HIDAPI_DriverSInput_InitDevice(SDL_HIDAPI_Device *device)
+{
+#if defined(DEBUG_SINPUT_INIT)
+ SDL_Log("SInput device Init");
+#endif
+
+ SDL_DriverSInput_Context *ctx = (SDL_DriverSInput_Context *)SDL_calloc(1, sizeof(*ctx));
+ if (!ctx) {
+ return false;
+ }
+
+ ctx->device = device;
+ device->context = ctx;
+
+ if (!RetrieveSDLFeatures(device)) {
+ return false;
+ }
+
+ // Store the USB Device Version because we will overwrite this data
+ ctx->usb_device_version = device->version;
+
+ switch (device->product_id) {
+ case USB_PRODUCT_HANDHELDLEGEND_GCULTIMATE:
+ HIDAPI_SetDeviceName(device, "HHL GC Ultimate");
+ break;
+ case USB_PRODUCT_HANDHELDLEGEND_PROGCC:
+ HIDAPI_SetDeviceName(device, "HHL ProGCC");
+ break;
+ case USB_PRODUCT_VOIDGAMING_PS4FIREBIRD:
+ HIDAPI_SetDeviceName(device, "Void Gaming PS4 FireBird");
+ break;
+ case USB_PRODUCT_VOIDGAMING_GENESIS_SINPUT:
+ HIDAPI_SetDeviceName(device, "Void Gaming Void GENESIS");
+ break;
+ case USB_PRODUCT_BONZIRICHANNEL_FIREBIRD:
+ HIDAPI_SetDeviceName(device, "Bonziri FireBird");
+ break;
+ case USB_PRODUCT_HANDHELDLEGEND_SINPUT_GENERIC:
+ default:
+ // Use the USB product name
+ break;
+ }
+
+ return HIDAPI_JoystickConnected(device, NULL);
+}
+
+static int HIDAPI_DriverSInput_GetDevicePlayerIndex(SDL_HIDAPI_Device *device, SDL_JoystickID instance_id)
+{
+ return -1;
+}
+
+static void HIDAPI_DriverSInput_SetDevicePlayerIndex(SDL_HIDAPI_Device *device, SDL_JoystickID instance_id, int player_index)
+{
+ SDL_DriverSInput_Context *ctx = (SDL_DriverSInput_Context *)device->context;
+
+ if (ctx->player_leds_supported) {
+ player_index = SDL_clamp(player_index + 1, 0, 255);
+ Uint8 player_num = (Uint8)player_index;
+
+ ctx->player_idx = player_num;
+
+ // Set player number, finalizing the setup
+ Uint8 playerLedCommand[SINPUT_DEVICE_REPORT_COMMAND_SIZE] = { SINPUT_DEVICE_REPORT_ID_OUTPUT_CMDDAT, SINPUT_DEVICE_COMMAND_PLAYERLED, ctx->player_idx };
+ int playerNumBytesWritten = SDL_hid_write(device->dev, playerLedCommand, SINPUT_DEVICE_REPORT_COMMAND_SIZE);
+
+ if (playerNumBytesWritten < 0) {
+ SDL_SetError("SInput device player led command could not write");
+ }
+ }
+}
+
+#ifndef DEG2RAD
+#define DEG2RAD(x) ((float)(x) * (float)(SDL_PI_F / 180.f))
+#endif
+
+
+static bool HIDAPI_DriverSInput_OpenJoystick(SDL_HIDAPI_Device *device, SDL_Joystick *joystick)
+{
+#if defined(DEBUG_SINPUT_INIT)
+ SDL_Log("SInput device Open");
+#endif
+
+ SDL_DriverSInput_Context *ctx = (SDL_DriverSInput_Context *)device->context;
+
+ SDL_AssertJoysticksLocked();
+
+ joystick->nbuttons = ctx->buttons_count;
+
+ SDL_zeroa(ctx->last_state);
+
+ joystick->naxes = ctx->axes_count;
+
+ if (ctx->dpad_supported) {
+ joystick->nhats = 1;
+ }
+
+ if (ctx->gyroscope_supported) {
+ SDL_PrivateJoystickAddSensor(joystick, SDL_SENSOR_GYRO, 1000000.0f / ctx->polling_rate_us);
+ }
+
+ if (ctx->accelerometer_supported) {
+ SDL_PrivateJoystickAddSensor(joystick, SDL_SENSOR_ACCEL, 1000000.0f / ctx->polling_rate_us);
+ }
+
+ if (ctx->touchpad_supported) {
+ // If touchpad is supported, minimum 1, max is capped
+ ctx->touchpad_count = SDL_clamp(ctx->touchpad_count, 1, SINPUT_MAX_ALLOWED_TOUCHPADS);
+
+ if (ctx->touchpad_count > 1) {
+ // Support two separate touchpads with 1 finger each
+ // or support one touchpad with 2 fingers max
+ ctx->touchpad_finger_count = 1;
+ }
+
+ if (ctx->touchpad_count > 0) {
+ SDL_PrivateJoystickAddTouchpad(joystick, ctx->touchpad_finger_count);
+ }
+
+ if (ctx->touchpad_count > 1) {
+ SDL_PrivateJoystickAddTouchpad(joystick, ctx->touchpad_finger_count);
+ }
+ }
+
+ return true;
+}
+
+static bool HIDAPI_DriverSInput_RumbleJoystick(SDL_HIDAPI_Device *device, SDL_Joystick *joystick, Uint16 low_frequency_rumble, Uint16 high_frequency_rumble)
+{
+
+ SDL_DriverSInput_Context *ctx = (SDL_DriverSInput_Context *)device->context;
+
+ if (ctx->rumble_supported) {
+ SINPUT_HAPTIC_S hapticData = { 0 };
+ Uint8 hapticReport[SINPUT_DEVICE_REPORT_COMMAND_SIZE] = { SINPUT_DEVICE_REPORT_ID_OUTPUT_CMDDAT, SINPUT_DEVICE_COMMAND_HAPTIC };
+
+ // Low Frequency = Left
+ // High Frequency = Right
+ hapticData.type_2.left.amplitude = (Uint8) (low_frequency_rumble >> 8);
+ hapticData.type_2.right.amplitude = (Uint8)(high_frequency_rumble >> 8);
+
+ HapticsType2Pack(&hapticData, &(hapticReport[2]));
+
+ SDL_HIDAPI_SendRumble(device, hapticReport, SINPUT_DEVICE_REPORT_COMMAND_SIZE);
+
+ return true;
+ }
+
+ return SDL_Unsupported();
+}
+
+static bool HIDAPI_DriverSInput_RumbleJoystickTriggers(SDL_HIDAPI_Device *device, SDL_Joystick *joystick, Uint16 left_rumble, Uint16 right_rumble)
+{
+ return SDL_Unsupported();
+}
+
+static Uint32 HIDAPI_DriverSInput_GetJoystickCapabilities(SDL_HIDAPI_Device *device, SDL_Joystick *joystick)
+{
+ SDL_DriverSInput_Context *ctx = (SDL_DriverSInput_Context *)device->context;
+
+ Uint32 caps = 0;
+ if (ctx->rumble_supported) {
+ caps |= SDL_JOYSTICK_CAP_RUMBLE;
+ }
+
+ if (ctx->player_leds_supported) {
+ caps |= SDL_JOYSTICK_CAP_PLAYER_LED;
+ }
+
+ if (ctx->joystick_rgb_supported) {
+ caps |= SDL_JOYSTICK_CAP_RGB_LED;
+ }
+
+ return caps;
+}
+
+static bool HIDAPI_DriverSInput_SetJoystickLED(SDL_HIDAPI_Device *device, SDL_Joystick *joystick, Uint8 red, Uint8 green, Uint8 blue)
+{
+ SDL_DriverSInput_Context *ctx = (SDL_DriverSInput_Context *)device->context;
+
+ if (ctx->joystick_rgb_supported) {
+ Uint8 joystickRGBCommand[SINPUT_DEVICE_REPORT_COMMAND_SIZE] = { SINPUT_DEVICE_REPORT_ID_OUTPUT_CMDDAT, SINPUT_DEVICE_COMMAND_JOYSTICKRGB, red, green, blue };
+ int joystickRGBBytesWritten = SDL_hid_write(device->dev, joystickRGBCommand, SINPUT_DEVICE_REPORT_COMMAND_SIZE);
+
+ if (joystickRGBBytesWritten < 0) {
+ SDL_SetError("SInput device joystick rgb command could not write");
+ return false;
+ }
+
+ return true;
+ }
+ return SDL_Unsupported();
+}
+
+static bool HIDAPI_DriverSInput_SendJoystickEffect(SDL_HIDAPI_Device *device, SDL_Joystick *joystick, const void *data, int size)
+{
+ return SDL_Unsupported();
+}
+
+static bool HIDAPI_DriverSInput_SetJoystickSensorsEnabled(SDL_HIDAPI_Device *device, SDL_Joystick *joystick, bool enabled)
+{
+ SDL_DriverSInput_Context *ctx = (SDL_DriverSInput_Context *)device->context;
+
+ if (ctx->accelerometer_supported || ctx->gyroscope_supported) {
+ ctx->sensors_enabled = enabled;
+ return true;
+ }
+ return SDL_Unsupported();
+}
+
+static void HIDAPI_DriverSInput_HandleStatePacket(SDL_Joystick *joystick, SDL_DriverSInput_Context *ctx, Uint8 *data, int size)
+{
+ Sint16 axis = 0;
+ Sint16 accel = 0;
+ Sint16 gyro = 0;
+ Uint64 timestamp = SDL_GetTicksNS();
+ float imu_values[3] = { 0 };
+ Uint8 output_idx = 0;
+
+ // Process digital buttons according to the supplied
+ // button mask to create a contiguous button input set
+ for (Uint8 processes = 0; processes < 4; ++processes) {
+
+ Uint8 button_idx = SINPUT_REPORT_IDX_BUTTONS_0 + processes;
+
+ for (Uint8 buttons = 0; buttons < 8; ++buttons) {
+
+ // If a button is enabled by our usage mask
+ const Uint8 mask = (0x01 << buttons);
+ if ((ctx->usage_masks[processes] & mask) != 0) {
+
+ bool down = (data[button_idx] & mask) != 0;
+
+ if ( (output_idx < SDL_GAMEPAD_BUTTON_COUNT) && (ctx->last_state[button_idx] != data[button_idx]) ) {
+ SDL_SendJoystickButton(timestamp, joystick, output_idx, down);
+ }
+
+ ++output_idx;
+ }
+ }
+ }
+
+ if (ctx->dpad_supported) {
+ Uint8 hat = SDL_HAT_CENTERED;
+
+ if (data[SINPUT_REPORT_IDX_BUTTONS_0] & (1 << SINPUT_BUTTON_IDX_DPAD_UP)) {
+ hat |= SDL_HAT_UP;
+ }
+ if (data[SINPUT_REPORT_IDX_BUTTONS_0] & (1 << SINPUT_BUTTON_IDX_DPAD_DOWN)) {
+ hat |= SDL_HAT_DOWN;
+ }
+ if (data[SINPUT_REPORT_IDX_BUTTONS_0] & (1 << SINPUT_BUTTON_IDX_DPAD_LEFT)) {
+ hat |= SDL_HAT_LEFT;
+ }
+ if (data[SINPUT_REPORT_IDX_BUTTONS_0] & (1 << SINPUT_BUTTON_IDX_DPAD_RIGHT)) {
+ hat |= SDL_HAT_RIGHT;
+ }
+ SDL_SendJoystickHat(timestamp, joystick, 0, hat);
+ }
+
+ // Analog inputs map to a signed Sint16 range of -32768 to 32767 from the device.
+ // Use an axis index because not all gamepads will have the same axis inputs.
+ Uint8 axis_idx = 0;
+
+ // Left Analog Stick
+ axis = 0; // Reset axis value for joystick
+ if (ctx->left_analog_stick_supported) {
+ axis = EXTRACTSINT16(data, SINPUT_REPORT_IDX_LEFT_X);
+ SDL_SendJoystickAxis(timestamp, joystick, axis_idx, axis);
+ ++axis_idx;
+
+ axis = EXTRACTSINT16(data, SINPUT_REPORT_IDX_LEFT_Y);
+ SDL_SendJoystickAxis(timestamp, joystick, axis_idx, axis);
+ ++axis_idx;
+ }
+
+ // Right Analog Stick
+ axis = 0; // Reset axis value for joystick
+ if (ctx->right_analog_stick_supported) {
+ axis = EXTRACTSINT16(data, SINPUT_REPORT_IDX_RIGHT_X);
+ SDL_SendJoystickAxis(timestamp, joystick, axis_idx, axis);
+ ++axis_idx;
+
+ axis = EXTRACTSINT16(data, SINPUT_REPORT_IDX_RIGHT_Y);
+ SDL_SendJoystickAxis(timestamp, joystick, axis_idx, axis);
+ ++axis_idx;
+ }
+
+ // Left Analog Trigger
+ axis = SDL_MIN_SINT16; // Reset axis value for trigger
+ if (ctx->left_analog_trigger_supported) {
+ axis = EXTRACTSINT16(data, SINPUT_REPORT_IDX_LEFT_TRIGGER);
+ SDL_SendJoystickAxis(timestamp, joystick, axis_idx, axis);
+ ++axis_idx;
+ }
+
+ // Right Analog Trigger
+ axis = SDL_MIN_SINT16; // Reset axis value for trigger
+ if (ctx->right_analog_trigger_supported) {
+ axis = EXTRACTSINT16(data, SINPUT_REPORT_IDX_RIGHT_TRIGGER);
+ SDL_SendJoystickAxis(timestamp, joystick, axis_idx, axis);
+ }
+
+ // Battery/Power state handling
+ if (ctx->last_state[SINPUT_REPORT_IDX_PLUG_STATUS] != data[SINPUT_REPORT_IDX_PLUG_STATUS] ||
+ ctx->last_state[SINPUT_REPORT_IDX_CHARGE_LEVEL] != data[SINPUT_REPORT_IDX_CHARGE_LEVEL]) {
+
+ SDL_PowerState state = SDL_POWERSTATE_UNKNOWN;
+ Uint8 status = data[SINPUT_REPORT_IDX_PLUG_STATUS];
+ int percent = data[SINPUT_REPORT_IDX_CHARGE_LEVEL];
+
+ percent = SDL_clamp(percent, 0, 100); // Ensure percent is within valid range
+
+ switch (status) {
+ case 1:
+ state = SDL_POWERSTATE_NO_BATTERY;
+ percent = 0;
+ break;
+ case 2:
+ state = SDL_POWERSTATE_CHARGING;
+ break;
+ case 3:
+ state = SDL_POWERSTATE_CHARGED;
+ percent = 100;
+ break;
+ case 4:
+ state = SDL_POWERSTATE_ON_BATTERY;
+ break;
+ default:
+ break;
+ }
+
+ if (state != SDL_POWERSTATE_UNKNOWN) {
+ SDL_SendJoystickPowerInfo(joystick, state, percent);
+ }
+ }
+
+ // Extract the IMU timestamp delta (in microseconds)
+ Uint32 imu_timestamp_us = EXTRACTUINT32(data, SINPUT_REPORT_IDX_IMU_TIMESTAMP);
+ Uint32 imu_time_delta_us = 0;
+
+ // Check if we should process IMU data and if sensors are enabled
+ if (ctx->sensors_enabled) {
+
+ if (imu_timestamp_us >= ctx->last_imu_timestamp_us) {
+ imu_time_delta_us = (imu_timestamp_us - ctx->last_imu_timestamp_us);
+ } else {
+ // Handle rollover case
+ imu_time_delta_us = (UINT32_MAX - ctx->last_imu_timestamp_us) + imu_timestamp_us + 1;
+ }
+
+ // Convert delta to nanoseconds and update running timestamp
+ ctx->imu_timestamp_ns += (Uint64)imu_time_delta_us * 1000;
+
+ // Update last timestamp
+ ctx->last_imu_timestamp_us = imu_timestamp_us;
+
+ // Process Gyroscope
+ if (ctx->gyroscope_supported) {
+
+ gyro = EXTRACTSINT16(data, SINPUT_REPORT_IDX_IMU_GYRO_Y);
+ imu_values[2] = -(float)gyro * ctx->gyroScale; // Y-axis rotation
+
+ gyro = EXTRACTSINT16(data, SINPUT_REPORT_IDX_IMU_GYRO_Z);
+ imu_values[1] = (float)gyro * ctx->gyroScale; // Z-axis rotation
+
+ gyro = EXTRACTSINT16(data, SINPUT_REPORT_IDX_IMU_GYRO_X);
+ imu_values[0] = -(float)gyro * ctx->gyroScale; // X-axis rotation
+
+ SDL_SendJoystickSensor(timestamp, joystick, SDL_SENSOR_GYRO, ctx->imu_timestamp_ns, imu_values, 3);
+ }
+
+ // Process Accelerometer
+ if (ctx->accelerometer_supported) {
+
+ accel = EXTRACTSINT16(data, SINPUT_REPORT_IDX_IMU_ACCEL_Y);
+ imu_values[2] = -(float)accel * ctx->accelScale; // Y-axis acceleration
+
+ accel = EXTRACTSINT16(data, SINPUT_REPORT_IDX_IMU_ACCEL_Z);
+ imu_values[1] = (float)accel * ctx->accelScale; // Z-axis acceleration
+
+ accel = EXTRACTSINT16(data, SINPUT_REPORT_IDX_IMU_ACCEL_X);
+ imu_values[0] = -(float)accel * ctx->accelScale; // X-axis acceleration
+
+ SDL_SendJoystickSensor(timestamp, joystick, SDL_SENSOR_ACCEL, ctx->imu_timestamp_ns, imu_values, 3);
+ }
+ }
+
+ // Check if we should process touchpad
+ if (ctx->touchpad_supported && ctx->touchpad_count > 0) {
+ Uint8 touchpad = 0;
+ Uint8 finger = 0;
+
+ Sint16 touch1X = EXTRACTSINT16(data, SINPUT_REPORT_IDX_TOUCH1_X);
+ Sint16 touch1Y = EXTRACTSINT16(data, SINPUT_REPORT_IDX_TOUCH1_Y);
+ Uint16 touch1P = EXTRACTUINT16(data, SINPUT_REPORT_IDX_TOUCH1_P);
+
+ Sint16 touch2X = EXTRACTSINT16(data, SINPUT_REPORT_IDX_TOUCH2_X);
+ Sint16 touch2Y = EXTRACTSINT16(data, SINPUT_REPORT_IDX_TOUCH2_Y);
+ Uint16 touch2P = EXTRACTUINT16(data, SINPUT_REPORT_IDX_TOUCH2_P);
+
+ SDL_SendJoystickTouchpad(timestamp, joystick, touchpad, finger,
+ touch1P > 0,
+ touch1X / 65536.0f + 0.5f,
+ touch1Y / 65536.0f + 0.5f,
+ touch1P / 32768.0f);
+
+ if (ctx->touchpad_count > 1) {
+ ++touchpad;
+ } else if (ctx->touchpad_finger_count > 1) {
+ ++finger;
+ }
+
+ if ((touchpad > 0) || (finger > 0)) {
+ SDL_SendJoystickTouchpad(timestamp, joystick, touchpad, finger,
+ touch2P > 0,
+ touch2X / 65536.0f + 0.5f,
+ touch2Y / 65536.0f + 0.5f,
+ touch2P / 32768.0f);
+ }
+ }
+
+ SDL_memcpy(ctx->last_state, data, SDL_min(size, sizeof(ctx->last_state)));
+}
+
+static bool HIDAPI_DriverSInput_UpdateDevice(SDL_HIDAPI_Device *device)
+{
+ SDL_DriverSInput_Context *ctx = (SDL_DriverSInput_Context *)device->context;
+ SDL_Joystick *joystick = NULL;
+ Uint8 data[USB_PACKET_LENGTH];
+ int size = 0;
+
+ if (device->num_joysticks > 0) {
+ joystick = SDL_GetJoystickFromID(device->joysticks[0]);
+ } else {
+ return false;
+ }
+
+ while ((size = SDL_hid_read_timeout(device->dev, data, sizeof(data), 0)) > 0) {
+#ifdef DEBUG_SINPUT_PROTOCOL
+ HIDAPI_DumpPacket("SInput packet: size = %d", data, size);
+#endif
+ if (!joystick) {
+ continue;
+ }
+
+ if (data[0] == SINPUT_DEVICE_REPORT_ID_JOYSTICK_INPUT) {
+ HIDAPI_DriverSInput_HandleStatePacket(joystick, ctx, data, size);
+ }
+ }
+
+ if (size < 0) {
+ // Read error, device is disconnected
+ HIDAPI_JoystickDisconnected(device, device->joysticks[0]);
+ }
+ return (size >= 0);
+}
+
+static void HIDAPI_DriverSInput_CloseJoystick(SDL_HIDAPI_Device *device, SDL_Joystick *joystick)
+{
+}
+
+static void HIDAPI_DriverSInput_FreeDevice(SDL_HIDAPI_Device *device)
+{
+}
+
+SDL_HIDAPI_DeviceDriver SDL_HIDAPI_DriverSInput = {
+ SDL_HINT_JOYSTICK_HIDAPI_SINPUT,
+ true,
+ HIDAPI_DriverSInput_RegisterHints,
+ HIDAPI_DriverSInput_UnregisterHints,
+ HIDAPI_DriverSInput_IsEnabled,
+ HIDAPI_DriverSInput_IsSupportedDevice,
+ HIDAPI_DriverSInput_InitDevice,
+ HIDAPI_DriverSInput_GetDevicePlayerIndex,
+ HIDAPI_DriverSInput_SetDevicePlayerIndex,
+ HIDAPI_DriverSInput_UpdateDevice,
+ HIDAPI_DriverSInput_OpenJoystick,
+ HIDAPI_DriverSInput_RumbleJoystick,
+ HIDAPI_DriverSInput_RumbleJoystickTriggers,
+ HIDAPI_DriverSInput_GetJoystickCapabilities,
+ HIDAPI_DriverSInput_SetJoystickLED,
+ HIDAPI_DriverSInput_SendJoystickEffect,
+ HIDAPI_DriverSInput_SetJoystickSensorsEnabled,
+ HIDAPI_DriverSInput_CloseJoystick,
+ HIDAPI_DriverSInput_FreeDevice,
+};
+
+#endif // SDL_JOYSTICK_HIDAPI_SINPUT
+
+#endif // SDL_JOYSTICK_HIDAPI
diff --git a/thirdparty/sdl/joystick/hidapi/SDL_hidapi_sinput.h b/thirdparty/sdl/joystick/hidapi/SDL_hidapi_sinput.h
new file mode 100644
index 00000000000..8bcc70d7fcb
--- /dev/null
+++ b/thirdparty/sdl/joystick/hidapi/SDL_hidapi_sinput.h
@@ -0,0 +1,92 @@
+/*
+ Simple DirectMedia Layer
+ Copyright (C) 2025 Mitchell Cairns <[email protected]>
+
+ 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.
+*/
+
+typedef enum
+{
+ SINPUT_ANALOGSTYLE_NONE,
+ SINPUT_ANALOGSTYLE_LEFTONLY,
+ SINPUT_ANALOGSTYLE_RIGHTONLY,
+ SINPUT_ANALOGSTYLE_LEFTRIGHT,
+ SINPUT_ANALOGSTYLE_MAX,
+} SInput_AnalogStyleType;
+
+typedef enum
+{
+ SINPUT_BUMPERSTYLE_NONE,
+ SINPUT_BUMPERSTYLE_ONE,
+ SINPUT_BUMPERSTYLE_TWO,
+ SINPUT_BUMPERSTYLE_MAX,
+} SInput_BumperStyleType;
+
+typedef enum
+{
+ SINPUT_TRIGGERSTYLE_NONE,
+ SINPUT_TRIGGERSTYLE_ANALOG,
+ SINPUT_TRIGGERSTYLE_DIGITAL,
+ SINPUT_TRIGGERSTYLE_DUALSTAGE,
+ SINPUT_TRIGGERSTYLE_MAX,
+} SInput_TriggerStyleType;
+
+typedef enum
+{
+ SINPUT_PADDLESTYLE_NONE,
+ SINPUT_PADDLESTYLE_TWO,
+ SINPUT_PADDLESTYLE_FOUR,
+ SINPUT_PADDLESTYLE_MAX,
+} SInput_PaddleStyleType;
+
+typedef enum
+{
+ SINPUT_METASTYLE_NONE,
+ SINPUT_METASTYLE_BACK,
+ SINPUT_METASTYLE_BACKGUIDE,
+ SINPUT_METASTYLE_BACKGUIDESHARE,
+ SINPUT_METASTYLE_MAX,
+} SInput_MetaStyleType;
+
+typedef enum
+{
+ SINPUT_TOUCHSTYLE_NONE,
+ SINPUT_TOUCHSTYLE_SINGLE,
+ SINPUT_TOUCHSTYLE_DOUBLE,
+ SINPUT_TOUCHSTYLE_MAX,
+} SInput_TouchStyleType;
+
+typedef enum
+{
+ SINPUT_MISCSTYLE_NONE,
+ SINPUT_MISCSTYLE_1,
+ SINPUT_MISCSTYLE_2,
+ SINPUT_MISCSTYLE_3,
+ SINPUT_MISCSTYLE_4,
+ SINPUT_MISCSTYLE_MAX,
+} SInput_MiscStyleType;
+
+typedef struct
+{
+ Uint16 analog_style;
+ Uint16 bumper_style;
+ Uint16 trigger_style;
+ Uint16 paddle_style;
+ Uint16 meta_style;
+ Uint16 touch_style;
+ Uint16 misc_style;
+} SDL_SInputStyles_t;
diff --git a/thirdparty/sdl/joystick/hidapi/SDL_hidapi_stadia.c b/thirdparty/sdl/joystick/hidapi/SDL_hidapi_stadia.c
index 487bf41b2e8..5c5e7490982 100644
--- a/thirdparty/sdl/joystick/hidapi/SDL_hidapi_stadia.c
+++ b/thirdparty/sdl/joystick/hidapi/SDL_hidapi_stadia.c
@@ -1,6 +1,6 @@
/*
Simple DirectMedia Layer
- Copyright (C) 1997-2025 Sam Lantinga <[email protected]>
+ Copyright (C) 1997-2026 Sam Lantinga <[email protected]>
This software is provided 'as-is', without any express or implied
warranty. In no event will the authors be held liable for any damages
diff --git a/thirdparty/sdl/joystick/hidapi/SDL_hidapi_steam.c b/thirdparty/sdl/joystick/hidapi/SDL_hidapi_steam.c
index 38180189d95..cb6add70d20 100644
--- a/thirdparty/sdl/joystick/hidapi/SDL_hidapi_steam.c
+++ b/thirdparty/sdl/joystick/hidapi/SDL_hidapi_steam.c
@@ -1,6 +1,6 @@
/*
Simple DirectMedia Layer
- Copyright (C) 1997-2025 Sam Lantinga <[email protected]>
+ Copyright (C) 1997-2026 Sam Lantinga <[email protected]>
This software is provided 'as-is', without any express or implied
warranty. In no event will the authors be held liable for any damages
@@ -29,7 +29,9 @@
#ifdef SDL_JOYSTICK_HIDAPI_STEAM
// Define this if you want to log all packets from the controller
-// #define DEBUG_STEAM_PROTOCOL
+#if 0
+#define DEBUG_STEAM_PROTOCOL
+#endif
#define SDL_HINT_JOYSTICK_HIDAPI_STEAM_PAIRING_ENABLED "SDL_JOYSTICK_HIDAPI_STEAM_PAIRING_ENABLED"
@@ -221,7 +223,7 @@ static void hexdump(const uint8_t *ptr, int len)
static void ResetSteamControllerPacketAssembler(SteamControllerPacketAssembler *pAssembler)
{
- SDL_memset(pAssembler->uBuffer, 0, sizeof(pAssembler->uBuffer));
+ SDL_zeroa(pAssembler->uBuffer);
pAssembler->nExpectedSegmentNumber = 0;
}
@@ -320,7 +322,7 @@ static int SetFeatureReport(SDL_HIDAPI_Device *dev, const unsigned char uBuffer[
nActualDataLen -= nBytesInPacket;
// Construct packet
- SDL_memset(uPacketBuffer, 0, sizeof(uPacketBuffer));
+ SDL_zeroa(uPacketBuffer);
uPacketBuffer[0] = BLE_REPORT_NUMBER;
uPacketBuffer[1] = GetSegmentHeader(nSegmentNumber, nActualDataLen == 0);
SDL_memcpy(&uPacketBuffer[2], pBufferPtr, nBytesInPacket);
@@ -370,7 +372,7 @@ static int GetFeatureReport(SDL_HIDAPI_Device *dev, unsigned char uBuffer[65])
#endif
while (nRetries < BLE_MAX_READ_RETRIES) {
- SDL_memset(uSegmentBuffer, 0, sizeof(uSegmentBuffer));
+ SDL_zeroa(uSegmentBuffer);
uSegmentBuffer[0] = BLE_REPORT_NUMBER;
nRet = SDL_hid_get_feature_report(dev->dev, uSegmentBuffer, ucBytesToRead);
@@ -457,6 +459,7 @@ static bool ResetSteamController(SDL_HIDAPI_Device *dev, bool bSuppressErrorSpew
DPRINTF("ResetSteamController hid=%p\n", dev);
+ SDL_zero(buf);
buf[0] = 0;
buf[1] = ID_GET_ATTRIBUTES_VALUES;
res = SetFeatureReport(dev, buf, 2);
@@ -510,6 +513,7 @@ static bool ResetSteamController(SDL_HIDAPI_Device *dev, bool bSuppressErrorSpew
}
// Clear digital button mappings
+ SDL_zero(buf);
buf[0] = 0;
buf[1] = ID_CLEAR_DIGITAL_MAPPINGS;
res = SetFeatureReport(dev, buf, 2);
@@ -521,7 +525,7 @@ static bool ResetSteamController(SDL_HIDAPI_Device *dev, bool bSuppressErrorSpew
}
// Reset the default settings
- SDL_memset(buf, 0, 65);
+ SDL_zero(buf);
buf[1] = ID_LOAD_DEFAULT_SETTINGS;
buf[2] = 0;
res = SetFeatureReport(dev, buf, 3);
@@ -539,7 +543,7 @@ static bool ResetSteamController(SDL_HIDAPI_Device *dev, bool bSuppressErrorSpew
buf[3 + nSettings * 3 + 2] = ((uint16_t)VALUE) >> 8; \
++nSettings;
- SDL_memset(buf, 0, 65);
+ SDL_zero(buf);
buf[1] = ID_SET_SETTINGS_VALUES;
ADD_SETTING(SETTING_WIRELESS_PACKET_VERSION, 2);
ADD_SETTING(SETTING_LEFT_TRACKPAD_MODE, TRACKPAD_NONE);
@@ -567,7 +571,7 @@ static bool ResetSteamController(SDL_HIDAPI_Device *dev, bool bSuppressErrorSpew
bool bMappingsCleared = false;
int iRetry;
for (iRetry = 0; iRetry < 2; ++iRetry) {
- SDL_memset(buf, 0, 65);
+ SDL_zero(buf);
buf[1] = ID_GET_DIGITAL_MAPPINGS;
buf[2] = 1; // one byte - requesting from index 0
buf[3] = 0;
@@ -596,7 +600,7 @@ static bool ResetSteamController(SDL_HIDAPI_Device *dev, bool bSuppressErrorSpew
}
// Set our new mappings
- SDL_memset(buf, 0, 65);
+ SDL_zero(buf);
buf[1] = ID_SET_DIGITAL_MAPPINGS;
buf[2] = 6; // 2 settings x 3 bytes
buf[3] = IO_DIGITAL_BUTTON_RIGHT_TRIGGER;
@@ -634,7 +638,7 @@ static int ReadSteamController(SDL_hid_device *dev, uint8_t *pData, int nDataSiz
static void SetPairingState(SDL_HIDAPI_Device *dev, bool bEnablePairing)
{
unsigned char buf[65];
- SDL_memset(buf, 0, 65);
+ SDL_zero(buf);
buf[1] = ID_ENABLE_PAIRING;
buf[2] = 2; // 2 payload bytes: bool + timeout
buf[3] = bEnablePairing ? 1 : 0;
@@ -648,7 +652,7 @@ static void SetPairingState(SDL_HIDAPI_Device *dev, bool bEnablePairing)
static void CommitPairing(SDL_HIDAPI_Device *dev)
{
unsigned char buf[65];
- SDL_memset(buf, 0, 65);
+ SDL_zero(buf);
buf[1] = ID_DONGLE_COMMIT_DEVICE;
SetFeatureReport(dev, buf, 2);
}
@@ -663,18 +667,18 @@ static void CloseSteamController(SDL_HIDAPI_Device *dev)
int nSettings = 0;
// Reset digital button mappings
- SDL_memset(buf, 0, 65);
+ SDL_zero(buf);
buf[1] = ID_SET_DEFAULT_DIGITAL_MAPPINGS;
SetFeatureReport(dev, buf, 2);
// Reset the default settings
- SDL_memset(buf, 0, 65);
+ SDL_zero(buf);
buf[1] = ID_LOAD_DEFAULT_SETTINGS;
buf[2] = 0;
SetFeatureReport(dev, buf, 3);
// Reset mouse mode for lizard mode
- SDL_memset(buf, 0, 65);
+ SDL_zero(buf);
buf[1] = ID_SET_SETTINGS_VALUES;
ADD_SETTING(SETTING_RIGHT_TRACKPAD_MODE, TRACKPAD_ABSOLUTE_MOUSE);
buf[2] = (unsigned char)(nSettings * 3);
@@ -1140,6 +1144,7 @@ static bool HIDAPI_DriverSteam_InitDevice(SDL_HIDAPI_Device *device)
unsigned char buf[65];
int res;
+ SDL_zero(buf);
buf[0] = 0;
buf[1] = ID_DONGLE_GET_WIRELESS_STATE;
res = SetFeatureReport(device, buf, 2);
@@ -1201,7 +1206,7 @@ static bool SetHomeLED(SDL_HIDAPI_Device *device, Uint8 value)
unsigned char buf[65];
int nSettings = 0;
- SDL_memset(buf, 0, 65);
+ SDL_zero(buf);
buf[1] = ID_SET_SETTINGS_VALUES;
ADD_SETTING(SETTING_LED_USER_BRIGHTNESS, value);
buf[2] = (unsigned char)(nSettings * 3);
@@ -1312,7 +1317,7 @@ static bool HIDAPI_DriverSteam_SetSensorsEnabled(SDL_HIDAPI_Device *device, SDL_
unsigned char buf[65];
int nSettings = 0;
- SDL_memset(buf, 0, 65);
+ SDL_zero(buf);
buf[1] = ID_SET_SETTINGS_VALUES;
if (enabled) {
ADD_SETTING(SETTING_IMU_MODE, SETTING_GYRO_MODE_SEND_RAW_ACCEL | SETTING_GYRO_MODE_SEND_RAW_GYRO);
diff --git a/thirdparty/sdl/joystick/hidapi/SDL_hidapi_steam_hori.c b/thirdparty/sdl/joystick/hidapi/SDL_hidapi_steam_hori.c
index 0cd192d018c..a480ff2b7de 100644
--- a/thirdparty/sdl/joystick/hidapi/SDL_hidapi_steam_hori.c
+++ b/thirdparty/sdl/joystick/hidapi/SDL_hidapi_steam_hori.c
@@ -1,6 +1,6 @@
/*
Simple DirectMedia Layer
- Copyright (C) 1997-2025 Sam Lantinga <[email protected]>
+ Copyright (C) 1997-2026 Sam Lantinga <[email protected]>
This software is provided 'as-is', without any express or implied
warranty. In no event will the authors be held liable for any damages
@@ -32,8 +32,6 @@
/* Define this if you want to log all packets from the controller */
/*#define DEBUG_HORI_PROTOCOL*/
-#define LOAD16(A, B) (Sint16)((Uint16)(A) | (((Uint16)(B)) << 8))
-
enum
{
SDL_GAMEPAD_BUTTON_HORI_QAM = 11,
@@ -51,6 +49,8 @@ typedef struct
Uint8 last_state[USB_PACKET_LENGTH];
Uint64 sensor_ticks;
Uint32 last_tick;
+ Uint64 simulated_sensor_step_ns;
+ Uint64 simulated_sensor_time_stamp;
bool wireless;
bool serial_needs_init;
} SDL_DriverSteamHori_Context;
@@ -114,21 +114,25 @@ static bool HIDAPI_DriverSteamHori_OpenJoystick(SDL_HIDAPI_Device *device, SDL_J
/* Initialize the joystick capabilities */
joystick->nbuttons = SDL_GAMEPAD_NUM_HORI_BUTTONS;
joystick->naxes = SDL_GAMEPAD_AXIS_COUNT;
- joystick->nhats = 1;
+ joystick->nhats = 1;
+
+ ctx->wireless = device->product_id == USB_PRODUCT_HORI_STEAM_CONTROLLER_BT;
- ctx->wireless = device->product_id == USB_PRODUCT_HORI_STEAM_CONTROLLER_BT;
+ if (ctx->wireless && device->serial) {
+ joystick->serial = SDL_strdup(device->serial);
+ ctx->serial_needs_init = false;
+ } else if (!ctx->wireless) {
+ // Need to actual read from the device to init the serial
+ HIDAPI_DriverSteamHori_UpdateDevice(device);
+ }
- if (ctx->wireless && device->serial) {
- joystick->serial = SDL_strdup(device->serial);
- ctx->serial_needs_init = false;
- } else if (!ctx->wireless) {
- // Need to actual read from the device to init the serial
- HIDAPI_DriverSteamHori_UpdateDevice(device);
- }
-
- SDL_PrivateJoystickAddSensor(joystick, SDL_SENSOR_GYRO, 250.0f);
- SDL_PrivateJoystickAddSensor(joystick, SDL_SENSOR_ACCEL, 250.0f);
+ const float sensorupdaterate = ctx->wireless ? 120.0f : 250.0f;
+ SDL_PrivateJoystickAddSensor(joystick, SDL_SENSOR_GYRO, sensorupdaterate);
+ SDL_PrivateJoystickAddSensor(joystick, SDL_SENSOR_ACCEL, sensorupdaterate);
+
+ const Uint64 sensorupdatestep_ms = ctx->wireless ? 8333 : 4000; // Equivalent to 120hz / 250hz respectively
+ ctx->simulated_sensor_step_ns = SDL_US_TO_NS(sensorupdatestep_ms);
return true;
}
@@ -275,12 +279,13 @@ static void HIDAPI_DriverSteamHori_HandleStatePacket(SDL_Joystick *joystick, SDL
SDL_SendJoystickButton(timestamp, joystick, SDL_GAMEPAD_BUTTON_HORI_FL, ((data[7] & 0x80) != 0));
}
- if (!ctx->wireless && ctx->serial_needs_init) {
+ if (!ctx->wireless && ctx->serial_needs_init) {
char serial[18];
- (void)SDL_snprintf(serial, sizeof(serial), "%.2x-%.2x-%.2x-%.2x-%.2x-%.2x",
- data[38], data[39], data[40], data[41], data[42], data[43]);
+ (void)SDL_snprintf(serial, sizeof(serial), "%.2x-%.2x-%.2x-%.2x-%.2x-%.2x",
+ data[38], data[39], data[40], data[41], data[42], data[43]);
- joystick->serial = SDL_strdup(serial);
+ SDL_AssertJoysticksLocked();
+ joystick->serial = SDL_strdup(serial);
ctx->serial_needs_init = false;
}
@@ -302,7 +307,7 @@ static void HIDAPI_DriverSteamHori_HandleStatePacket(SDL_Joystick *joystick, SDL
Uint32 delta;
Uint16 tick = LOAD16(data[10],
data[11]);
- if (ctx->last_tick < tick) {
+ if (ctx->last_tick <= tick) {
delta = (tick - ctx->last_tick);
} else {
delta = (SDL_MAX_UINT16 - ctx->last_tick + tick + 1);
@@ -312,7 +317,11 @@ static void HIDAPI_DriverSteamHori_HandleStatePacket(SDL_Joystick *joystick, SDL
ctx->sensor_ticks += delta;
/* Sensor timestamp is in 1us units, but there seems to be some issues with the values reported from the device */
- sensor_timestamp = timestamp; // if the values were good we woudl call SDL_US_TO_NS(ctx->sensor_ticks);
+ // sensor_timestamp = timestamp; // if the values were good we would call SDL_US_TO_NS(ctx->sensor_ticks);
+
+ /* New approach - simulate a fixed rate of 250hz (from observation). This reduces stutter from dropped/racing bluetooth packets.*/
+ ctx->simulated_sensor_time_stamp += ctx->simulated_sensor_step_ns;
+ sensor_timestamp = ctx->simulated_sensor_time_stamp;
const float accelScale = SDL_STANDARD_GRAVITY * 8 / 32768.0f;
const float gyroScale = DEG2RAD(2048);
@@ -320,7 +329,6 @@ static void HIDAPI_DriverSteamHori_HandleStatePacket(SDL_Joystick *joystick, SDL
imu_data[1] = RemapValClamped(-1.0f * LOAD16(data[12], data[13]), INT16_MIN, INT16_MAX, -gyroScale, gyroScale);
imu_data[2] = RemapValClamped(-1.0f * LOAD16(data[14], data[15]), INT16_MIN, INT16_MAX, -gyroScale, gyroScale);
imu_data[0] = RemapValClamped(-1.0f * LOAD16(data[16], data[17]), INT16_MIN, INT16_MAX, -gyroScale, gyroScale);
-
SDL_SendJoystickSensor(timestamp, joystick, SDL_SENSOR_GYRO, sensor_timestamp, imu_data, 3);
@@ -334,8 +342,9 @@ static void HIDAPI_DriverSteamHori_HandleStatePacket(SDL_Joystick *joystick, SDL
if (ctx->last_state[24] != data[24]) {
bool bCharging = (data[24] & 0x10) != 0;
int percent = (data[24] & 0xF) * 10;
- SDL_PowerState state;
- if (bCharging) {
+ SDL_PowerState state;
+
+ if (bCharging) {
state = SDL_POWERSTATE_CHARGING;
} else if (ctx->wireless) {
state = SDL_POWERSTATE_ON_BATTERY;
diff --git a/thirdparty/sdl/joystick/hidapi/SDL_hidapi_steam_triton.c b/thirdparty/sdl/joystick/hidapi/SDL_hidapi_steam_triton.c
new file mode 100644
index 00000000000..01e4efff96e
--- /dev/null
+++ b/thirdparty/sdl/joystick/hidapi/SDL_hidapi_steam_triton.c
@@ -0,0 +1,711 @@
+/*
+ Simple DirectMedia Layer
+ Copyright (C) 1997-2026 Sam Lantinga <[email protected]>
+
+ 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"
+
+#ifdef SDL_JOYSTICK_HIDAPI
+
+#include "../SDL_sysjoystick.h"
+#include "SDL_hidapijoystick_c.h"
+
+#ifdef SDL_JOYSTICK_HIDAPI_STEAM_TRITON
+
+// Define this if you want to log all packets from the controller
+#if 0
+#define DEBUG_STEAM_PROTOCOL
+#endif
+
+/*****************************************************************************************************/
+
+#include "steam/controller_constants.h"
+#include "steam/controller_structs.h"
+
+// Always 1kHz according to USB descriptor, but actually about 4 ms.
+#define TRITON_SENSOR_UPDATE_INTERVAL_US 4032
+
+// Steam Controller hardware safety timeout is around 50ms, so we resend rumble every 40ms
+#define TRITON_RUMBLE_RESEND_INTERVAL_MS 40
+
+enum
+{
+ SDL_GAMEPAD_BUTTON_TRITON_QAM = 11,
+ SDL_GAMEPAD_BUTTON_TRITON_RIGHT_PADDLE1,
+ SDL_GAMEPAD_BUTTON_TRITON_LEFT_PADDLE1,
+ SDL_GAMEPAD_BUTTON_TRITON_RIGHT_PADDLE2,
+ SDL_GAMEPAD_BUTTON_TRITON_LEFT_PADDLE2,
+ SDL_GAMEPAD_BUTTON_TRITON_RIGHT_TOUCHPAD,
+ SDL_GAMEPAD_BUTTON_TRITON_LEFT_TOUCHPAD,
+ SDL_GAMEPAD_BUTTON_TRITON_RIGHT_JOYSTICK_TOUCH,
+ SDL_GAMEPAD_BUTTON_TRITON_LEFT_JOYSTICK_TOUCH,
+ SDL_GAMEPAD_BUTTON_TRITON_RIGHT_GRIP_TOUCH,
+ SDL_GAMEPAD_BUTTON_TRITON_LEFT_GRIP_TOUCH,
+ SDL_GAMEPAD_NUM_TRITON_BUTTONS,
+};
+
+typedef enum
+{
+
+ TRITON_LBUTTON_A = 0x00000001,
+ TRITON_LBUTTON_B = 0x00000002,
+ TRITON_LBUTTON_X = 0x00000004,
+ TRITON_LBUTTON_Y = 0x00000008,
+
+ TRITON_HBUTTON_QAM = 0x00000010,
+ TRITON_LBUTTON_R3 = 0x00000020,
+ TRITON_LBUTTON_VIEW = 0x00000040,
+ TRITON_HBUTTON_R4 = 0x00000080,
+
+ TRITON_LBUTTON_R5 = 0x00000100,
+ TRITON_LBUTTON_R = 0x00000200,
+ TRITON_LBUTTON_DPAD_DOWN = 0x00000400,
+ TRITON_LBUTTON_DPAD_RIGHT = 0x00000800,
+
+ TRITON_LBUTTON_DPAD_LEFT = 0x00001000,
+ TRITON_LBUTTON_DPAD_UP = 0x00002000,
+ TRITON_LBUTTON_MENU = 0x00004000,
+ TRITON_LBUTTON_L3 = 0x00008000,
+
+ TRITON_LBUTTON_STEAM = 0x00010000,
+ TRITON_HBUTTON_L4 = 0x00020000,
+ TRITON_LBUTTON_L5 = 0x00040000,
+ TRITON_LBUTTON_L = 0x00080000,
+
+ TRITON_RIGHT_JOYSTICK_TOUCH = 0x00100000,
+ TRITON_RIGHT_TOUCHPAD_TOUCH = 0x00200000,
+ TRITON_RIGHT_TOUCHPAD_CLICK = 0x00400000,
+ TRITON_RIGHT_TRIGGER_CLICK = 0x00800000,
+
+ TRITON_LEFT_JOYSTICK_TOUCH = 0x01000000,
+ TRITON_LEFT_TOUCHPAD_TOUCH = 0x02000000,
+ TRITON_LEFT_TOUCHPAD_CLICK = 0x04000000,
+ TRITON_LEFT_TRIGGER_CLICK = 0x08000000,
+
+ TRITON_RIGHT_GRIP_TOUCH = 0x10000000,
+ TRITON_LEFT_GRIP_TOUCH = 0x20000000,
+} TritonButtons;
+
+typedef struct
+{
+ bool connected;
+ bool report_sensors;
+ Uint16 last_sensor_tick16;
+ Uint32 last_sensor_tick32;
+ Uint64 sensor_timestamp_ns;
+ Uint64 last_button_state;
+ Uint64 last_lizard_update;
+ Uint16 low_frequency_rumble;
+ Uint16 high_frequency_rumble;
+ Uint64 last_rumble_time;
+
+ bool left_touch_down;
+ float left_touch_x;
+ float left_touch_y;
+ bool right_touch_down;
+ float right_touch_x;
+ float right_touch_y;
+} SDL_DriverSteamTriton_Context;
+
+static bool IsProteusDongle(Uint16 product_id)
+{
+ return (product_id == USB_PRODUCT_VALVE_STEAM_PROTEUS_DONGLE ||
+ product_id == USB_PRODUCT_VALVE_STEAM_NEREID_DONGLE);
+}
+
+static bool DisableSteamTritonLizardMode(SDL_hid_device *dev)
+{
+ int rc;
+ Uint8 buffer[HID_FEATURE_REPORT_BYTES] = { 1 };
+ FeatureReportMsg *msg = (FeatureReportMsg *)(buffer + 1);
+
+ msg->header.type = ID_SET_SETTINGS_VALUES;
+ msg->header.length = 1 * sizeof(ControllerSetting);
+ msg->payload.setSettingsValues.settings[0].settingNum = SETTING_LIZARD_MODE;
+ msg->payload.setSettingsValues.settings[0].settingValue = LIZARD_MODE_OFF;
+
+ rc = SDL_hid_send_feature_report(dev, buffer, sizeof(buffer));
+ if (rc != sizeof(buffer)) {
+ return false;
+ }
+
+ return true;
+}
+
+// Triton newer state MTUs are identical until touchpads. Parse them using this routine.
+// Expects report to be a TritonMTUNoQuat_t, so cast as needed
+static void HIDAPI_DriverSteamTriton_HandleGenericState(SDL_DriverSteamTriton_Context *ctx, SDL_Joystick *joystick, Uint64 timestamp, TritonMTUNoQuat_t *pTritonReport)
+{
+ if (pTritonReport->buttons != ctx->last_button_state) {
+ Uint8 hat = 0;
+
+ SDL_SendJoystickButton(timestamp, joystick, SDL_GAMEPAD_BUTTON_SOUTH,
+ ((pTritonReport->buttons & TRITON_LBUTTON_A) != 0));
+ SDL_SendJoystickButton(timestamp, joystick, SDL_GAMEPAD_BUTTON_EAST,
+ ((pTritonReport->buttons & TRITON_LBUTTON_B) != 0));
+ SDL_SendJoystickButton(timestamp, joystick, SDL_GAMEPAD_BUTTON_WEST,
+ ((pTritonReport->buttons & TRITON_LBUTTON_X) != 0));
+ SDL_SendJoystickButton(timestamp, joystick, SDL_GAMEPAD_BUTTON_NORTH,
+ ((pTritonReport->buttons & TRITON_LBUTTON_Y) != 0));
+
+ SDL_SendJoystickButton(timestamp, joystick, SDL_GAMEPAD_BUTTON_LEFT_SHOULDER,
+ ((pTritonReport->buttons & TRITON_LBUTTON_L) != 0));
+ SDL_SendJoystickButton(timestamp, joystick, SDL_GAMEPAD_BUTTON_RIGHT_SHOULDER,
+ ((pTritonReport->buttons & TRITON_LBUTTON_R) != 0));
+
+ SDL_SendJoystickButton(timestamp, joystick, SDL_GAMEPAD_BUTTON_BACK,
+ ((pTritonReport->buttons & TRITON_LBUTTON_MENU) != 0));
+ SDL_SendJoystickButton(timestamp, joystick, SDL_GAMEPAD_BUTTON_START,
+ ((pTritonReport->buttons & TRITON_LBUTTON_VIEW) != 0));
+ SDL_SendJoystickButton(timestamp, joystick, SDL_GAMEPAD_BUTTON_GUIDE,
+ ((pTritonReport->buttons & TRITON_LBUTTON_STEAM) != 0));
+ SDL_SendJoystickButton(timestamp, joystick, SDL_GAMEPAD_BUTTON_TRITON_QAM,
+ ((pTritonReport->buttons & TRITON_HBUTTON_QAM) != 0));
+
+ SDL_SendJoystickButton(timestamp, joystick, SDL_GAMEPAD_BUTTON_LEFT_STICK,
+ ((pTritonReport->buttons & TRITON_LBUTTON_L3) != 0));
+ SDL_SendJoystickButton(timestamp, joystick, SDL_GAMEPAD_BUTTON_RIGHT_STICK,
+ ((pTritonReport->buttons & TRITON_LBUTTON_R3) != 0));
+
+ SDL_SendJoystickButton(timestamp, joystick, SDL_GAMEPAD_BUTTON_TRITON_RIGHT_PADDLE1,
+ ((pTritonReport->buttons & TRITON_HBUTTON_R4) != 0));
+ SDL_SendJoystickButton(timestamp, joystick, SDL_GAMEPAD_BUTTON_TRITON_LEFT_PADDLE1,
+ ((pTritonReport->buttons & TRITON_HBUTTON_L4) != 0));
+ SDL_SendJoystickButton(timestamp, joystick, SDL_GAMEPAD_BUTTON_TRITON_RIGHT_PADDLE2,
+ ((pTritonReport->buttons & TRITON_LBUTTON_R5) != 0));
+ SDL_SendJoystickButton(timestamp, joystick, SDL_GAMEPAD_BUTTON_TRITON_LEFT_PADDLE2,
+ ((pTritonReport->buttons & TRITON_LBUTTON_L5) != 0));
+
+ SDL_SendJoystickButton(timestamp, joystick, SDL_GAMEPAD_BUTTON_TRITON_RIGHT_TOUCHPAD,
+ ((pTritonReport->buttons & TRITON_RIGHT_TOUCHPAD_CLICK) != 0));
+ SDL_SendJoystickButton(timestamp, joystick, SDL_GAMEPAD_BUTTON_TRITON_LEFT_TOUCHPAD,
+ ((pTritonReport->buttons & TRITON_LEFT_TOUCHPAD_CLICK) != 0));
+
+ SDL_SendJoystickButton(timestamp, joystick, SDL_GAMEPAD_BUTTON_TRITON_RIGHT_JOYSTICK_TOUCH,
+ ((pTritonReport->buttons & TRITON_RIGHT_JOYSTICK_TOUCH) != 0));
+ SDL_SendJoystickButton(timestamp, joystick, SDL_GAMEPAD_BUTTON_TRITON_LEFT_JOYSTICK_TOUCH,
+ ((pTritonReport->buttons & TRITON_LEFT_JOYSTICK_TOUCH) != 0));
+
+ SDL_SendJoystickButton(timestamp, joystick, SDL_GAMEPAD_BUTTON_TRITON_RIGHT_GRIP_TOUCH,
+ ((pTritonReport->buttons & TRITON_RIGHT_GRIP_TOUCH) != 0));
+ SDL_SendJoystickButton(timestamp, joystick, SDL_GAMEPAD_BUTTON_TRITON_LEFT_GRIP_TOUCH,
+ ((pTritonReport->buttons & TRITON_LEFT_GRIP_TOUCH) != 0));
+
+ if (pTritonReport->buttons & TRITON_LBUTTON_DPAD_UP) {
+ hat |= SDL_HAT_UP;
+ }
+ if (pTritonReport->buttons & TRITON_LBUTTON_DPAD_DOWN) {
+ hat |= SDL_HAT_DOWN;
+ }
+ if (pTritonReport->buttons & TRITON_LBUTTON_DPAD_LEFT) {
+ hat |= SDL_HAT_LEFT;
+ }
+ if (pTritonReport->buttons & TRITON_LBUTTON_DPAD_RIGHT) {
+ hat |= SDL_HAT_RIGHT;
+ }
+ SDL_SendJoystickHat(timestamp, joystick, 0, hat);
+
+ ctx->last_button_state = pTritonReport->buttons;
+ }
+
+ SDL_SendJoystickAxis(timestamp, joystick, SDL_GAMEPAD_AXIS_LEFT_TRIGGER,
+ (int)pTritonReport->sTriggerLeft * 2 - 32768);
+ SDL_SendJoystickAxis(timestamp, joystick, SDL_GAMEPAD_AXIS_RIGHT_TRIGGER,
+ (int)pTritonReport->sTriggerRight * 2 - 32768);
+ SDL_SendJoystickAxis(timestamp, joystick, SDL_GAMEPAD_AXIS_LEFTX,
+ pTritonReport->sLeftStickX);
+ SDL_SendJoystickAxis(timestamp, joystick, SDL_GAMEPAD_AXIS_LEFTY,
+ -pTritonReport->sLeftStickY);
+ SDL_SendJoystickAxis(timestamp, joystick, SDL_GAMEPAD_AXIS_RIGHTX,
+ pTritonReport->sRightStickX);
+ SDL_SendJoystickAxis(timestamp, joystick, SDL_GAMEPAD_AXIS_RIGHTY,
+ -pTritonReport->sRightStickY);
+}
+
+static void HIDAPI_DriverSteamTriton_HandleState(SDL_HIDAPI_Device *device,
+ SDL_Joystick *joystick,
+ TritonMTUNoQuat_t *pTritonReport)
+{
+ float values[3];
+ SDL_DriverSteamTriton_Context *ctx = (SDL_DriverSteamTriton_Context *)device->context;
+ Uint64 timestamp = SDL_GetTicksNS();
+
+ HIDAPI_DriverSteamTriton_HandleGenericState(ctx, joystick, timestamp, pTritonReport);
+
+ bool left_touch_down = (pTritonReport->buttons & TRITON_LEFT_TOUCHPAD_TOUCH) ? true : false;
+ bool right_touch_down = (pTritonReport->buttons & TRITON_RIGHT_TOUCHPAD_TOUCH) ? true : false;
+
+ if (left_touch_down || ctx->left_touch_down) {
+ if (left_touch_down) {
+ ctx->left_touch_x = pTritonReport->sLeftPadX / 65536.0f + 0.5f;
+ ctx->left_touch_y = -(float)pTritonReport->sLeftPadY / 65536.0f + 0.5f;
+ }
+ SDL_SendJoystickTouchpad(timestamp, joystick, 0, 0,
+ left_touch_down,
+ ctx->left_touch_x,
+ ctx->left_touch_y,
+ pTritonReport->unPressureLeft / 32768.0f);
+ ctx->left_touch_down = left_touch_down;
+ }
+ if (right_touch_down || ctx->right_touch_down) {
+ if (right_touch_down) {
+ ctx->right_touch_x = pTritonReport->sRightPadX / 65536.0f + 0.5f;
+ ctx->right_touch_y = -(float)pTritonReport->sRightPadY / 65536.0f + 0.5f;
+ }
+ SDL_SendJoystickTouchpad(timestamp, joystick, 1, 0,
+ right_touch_down,
+ ctx->right_touch_x,
+ ctx->right_touch_y,
+ pTritonReport->unPressureRight / 32768.0f);
+ ctx->right_touch_down = right_touch_down;
+ }
+
+ if (ctx->report_sensors && pTritonReport->imu.timestamp != ctx->last_sensor_tick32) {
+ Uint32 delta_us = (pTritonReport->imu.timestamp - ctx->last_sensor_tick32);
+
+ ctx->sensor_timestamp_ns += SDL_US_TO_NS(delta_us);
+
+ values[0] = (pTritonReport->imu.sGyroX / 32768.0f) * (2000.0f * (SDL_PI_F / 180.0f));
+ values[1] = (pTritonReport->imu.sGyroZ / 32768.0f) * (2000.0f * (SDL_PI_F / 180.0f));
+ values[2] = (-pTritonReport->imu.sGyroY / 32768.0f) * (2000.0f * (SDL_PI_F / 180.0f));
+ SDL_SendJoystickSensor(timestamp, joystick, SDL_SENSOR_GYRO, ctx->sensor_timestamp_ns, values, 3);
+
+ values[0] = (pTritonReport->imu.sAccelX / 32768.0f) * 2.0f * SDL_STANDARD_GRAVITY;
+ values[1] = (pTritonReport->imu.sAccelZ / 32768.0f) * 2.0f * SDL_STANDARD_GRAVITY;
+ values[2] = (-pTritonReport->imu.sAccelY / 32768.0f) * 2.0f * SDL_STANDARD_GRAVITY;
+ SDL_SendJoystickSensor(timestamp, joystick, SDL_SENSOR_ACCEL, ctx->sensor_timestamp_ns, values, 3);
+
+ ctx->last_sensor_tick32 = pTritonReport->imu.timestamp;
+ }
+}
+
+static void HIDAPI_DriverSteamTriton_HandleState_Timestamp(SDL_HIDAPI_Device *device,
+ SDL_Joystick *joystick,
+ TritonMTUNoQuat32TS_t *pTritonReport)
+{
+ float values[3];
+ SDL_DriverSteamTriton_Context *ctx = (SDL_DriverSteamTriton_Context *)device->context;
+ Uint64 timestamp = SDL_GetTicksNS();
+
+ HIDAPI_DriverSteamTriton_HandleGenericState(ctx, joystick, timestamp, (TritonMTUNoQuat_t *) pTritonReport);
+
+ bool left_touch_down = (pTritonReport->buttons & TRITON_LEFT_TOUCHPAD_TOUCH) ? true : false;
+ bool right_touch_down = (pTritonReport->buttons & TRITON_RIGHT_TOUCHPAD_TOUCH) ? true : false;
+
+ if (left_touch_down || ctx->left_touch_down) {
+ if (left_touch_down) {
+ ctx->left_touch_x = pTritonReport->sLeftPadX / 65536.0f + 0.5f;
+ ctx->left_touch_y = -(float)pTritonReport->sLeftPadY / 65536.0f + 0.5f;
+ }
+ SDL_SendJoystickTouchpad(timestamp, joystick, 0, 0,
+ left_touch_down,
+ ctx->left_touch_x,
+ ctx->left_touch_y,
+ pTritonReport->unPressureLeft / 32768.0f);
+ ctx->left_touch_down = left_touch_down;
+ }
+ if (right_touch_down || ctx->right_touch_down) {
+ if (right_touch_down) {
+ ctx->right_touch_x = pTritonReport->sRightPadX / 65536.0f + 0.5f;
+ ctx->right_touch_y = -(float)pTritonReport->sRightPadY / 65536.0f + 0.5f;
+ }
+ SDL_SendJoystickTouchpad(timestamp, joystick, 1, 0,
+ right_touch_down,
+ ctx->right_touch_x,
+ ctx->right_touch_y,
+ pTritonReport->unPressureRight / 32768.0f);
+ ctx->right_touch_down = right_touch_down;
+ }
+
+ if (ctx->report_sensors && pTritonReport->imu.timestamp != ctx->last_sensor_tick16) {
+ // The timestamp is in units of 32 microseconds
+ Uint32 delta_us = (Uint32)(pTritonReport->imu.timestamp - ctx->last_sensor_tick16) * 32;
+
+ ctx->sensor_timestamp_ns += SDL_US_TO_NS(delta_us);
+
+ values[0] = (pTritonReport->imu.sGyroX / 32768.0f) * (2000.0f * (SDL_PI_F / 180.0f));
+ values[1] = (pTritonReport->imu.sGyroZ / 32768.0f) * (2000.0f * (SDL_PI_F / 180.0f));
+ values[2] = (-pTritonReport->imu.sGyroY / 32768.0f) * (2000.0f * (SDL_PI_F / 180.0f));
+ SDL_SendJoystickSensor(timestamp, joystick, SDL_SENSOR_GYRO, ctx->sensor_timestamp_ns, values, 3);
+
+ values[0] = (pTritonReport->imu.sAccelX / 32768.0f) * 2.0f * SDL_STANDARD_GRAVITY;
+ values[1] = (pTritonReport->imu.sAccelZ / 32768.0f) * 2.0f * SDL_STANDARD_GRAVITY;
+ values[2] = (-pTritonReport->imu.sAccelY / 32768.0f) * 2.0f * SDL_STANDARD_GRAVITY;
+ SDL_SendJoystickSensor(timestamp, joystick, SDL_SENSOR_ACCEL, ctx->sensor_timestamp_ns, values, 3);
+
+ ctx->last_sensor_tick16 = pTritonReport->imu.timestamp;
+ }
+}
+
+static void HIDAPI_DriverSteamTriton_HandleBatteryStatus(SDL_HIDAPI_Device *device,
+ SDL_Joystick *joystick,
+ TritonBatteryStatus_t *pTritonBatteryStatus)
+{
+ SDL_PowerState state;
+
+ switch (pTritonBatteryStatus->ucChargeState) {
+ case k_EChargeStateDischarging:
+ state = SDL_POWERSTATE_ON_BATTERY;
+ break;
+ case k_EChargeStateCharging:
+ state = SDL_POWERSTATE_CHARGING;
+ break;
+ case k_EChargeStateChargingDone:
+ state = SDL_POWERSTATE_CHARGED;
+ break;
+ default:
+ // Error state?
+ state = SDL_POWERSTATE_UNKNOWN;
+ break;
+ }
+ SDL_SendJoystickPowerInfo(joystick, state, pTritonBatteryStatus->ucBatteryLevel);
+}
+
+static bool HIDAPI_DriverSteamTriton_SetControllerConnected(SDL_HIDAPI_Device *device, bool connected)
+{
+ SDL_DriverSteamTriton_Context *ctx = (SDL_DriverSteamTriton_Context *)device->context;
+
+ if (ctx->connected != connected) {
+ ctx->connected = connected;
+
+ if (connected) {
+ SDL_JoystickID joystickID;
+ if (!HIDAPI_JoystickConnected(device, &joystickID)) {
+ return false;
+ }
+ } else {
+ if (device->num_joysticks > 0) {
+ HIDAPI_JoystickDisconnected(device, device->joysticks[0]);
+ }
+ }
+ }
+ return true;
+}
+
+static void HIDAPI_DriverSteamTriton_HandleWirelessStatus(SDL_HIDAPI_Device *device,
+ TritonWirelessStatus_t *pTritonWirelessStatus)
+{
+ switch (pTritonWirelessStatus->state) {
+ case k_ETritonWirelessStateConnect:
+ HIDAPI_DriverSteamTriton_SetControllerConnected(device, true);
+ break;
+ case k_ETritonWirelessStateDisconnect:
+ HIDAPI_DriverSteamTriton_SetControllerConnected(device, false);
+ break;
+ default:
+ break;
+ }
+}
+
+/*****************************************************************************************************/
+
+static void HIDAPI_DriverSteamTriton_RegisterHints(SDL_HintCallback callback, void *userdata)
+{
+ SDL_AddHintCallback(SDL_HINT_JOYSTICK_HIDAPI_STEAM, callback, userdata);
+}
+
+static void HIDAPI_DriverSteamTriton_UnregisterHints(SDL_HintCallback callback, void *userdata)
+{
+ SDL_RemoveHintCallback(SDL_HINT_JOYSTICK_HIDAPI_STEAM, callback, userdata);
+}
+
+static bool HIDAPI_DriverSteamTriton_IsEnabled(void)
+{
+ return SDL_GetHintBoolean(SDL_HINT_JOYSTICK_HIDAPI_STEAM,
+ SDL_GetHintBoolean(SDL_HINT_JOYSTICK_HIDAPI, SDL_HIDAPI_DEFAULT));
+}
+
+static bool HIDAPI_DriverSteamTriton_IsSupportedDevice(
+ SDL_HIDAPI_Device *device,
+ const char *name,
+ SDL_GamepadType type,
+ Uint16 vendor_id,
+ Uint16 product_id,
+ Uint16 version,
+ int interface_number,
+ int interface_class,
+ int interface_subclass,
+ int interface_protocol)
+{
+
+ if (IsProteusDongle(product_id)) {
+ if (interface_number >= 2 && interface_number <= 5) {
+ // The set of controller interfaces for Proteus & Nereid...currently
+ return true;
+ }
+ } else if (SDL_IsJoystickSteamTriton(vendor_id, product_id)) {
+ return true;
+ }
+ return false;
+}
+
+static bool HIDAPI_DriverSteamTriton_InitDevice(SDL_HIDAPI_Device *device)
+{
+ SDL_DriverSteamTriton_Context *ctx;
+
+ ctx = (SDL_DriverSteamTriton_Context *)SDL_calloc(1, sizeof(*ctx));
+ if (ctx == NULL) {
+ return false;
+ }
+
+ device->context = ctx;
+
+ HIDAPI_SetDeviceName(device, "Steam Controller");
+
+ if (IsProteusDongle(device->product_id)) {
+ return true;
+ }
+
+ // Wired controller, connected!
+ return HIDAPI_DriverSteamTriton_SetControllerConnected(device, true);
+}
+
+static int HIDAPI_DriverSteamTriton_GetDevicePlayerIndex(SDL_HIDAPI_Device *device, SDL_JoystickID instance_id)
+{
+ return -1;
+}
+
+static void HIDAPI_DriverSteamTriton_SetDevicePlayerIndex(SDL_HIDAPI_Device *device, SDL_JoystickID instance_id, int player_index)
+{
+}
+
+static bool HIDAPI_DriverSteamTriton_RumbleJoystick(SDL_HIDAPI_Device *device, SDL_Joystick *joystick, Uint16 low_frequency_rumble, Uint16 high_frequency_rumble);
+
+static bool HIDAPI_DriverSteamTriton_UpdateDevice(SDL_HIDAPI_Device *device)
+{
+ SDL_DriverSteamTriton_Context *ctx = (SDL_DriverSteamTriton_Context *)device->context;
+ SDL_Joystick *joystick = NULL;
+
+ if (device->num_joysticks > 0) {
+ joystick = SDL_GetJoystickFromID(device->joysticks[0]);
+ }
+
+ if (ctx->connected && joystick) {
+ Uint64 now = SDL_GetTicks();
+ if (!ctx->last_lizard_update || (now - ctx->last_lizard_update) >= 3000) {
+ DisableSteamTritonLizardMode(device->dev);
+ ctx->last_lizard_update = now;
+ }
+
+ if (ctx->low_frequency_rumble || ctx->high_frequency_rumble) {
+ if ((now - ctx->last_rumble_time) >= TRITON_RUMBLE_RESEND_INTERVAL_MS) {
+ HIDAPI_DriverSteamTriton_RumbleJoystick(device, joystick, ctx->low_frequency_rumble, ctx->high_frequency_rumble);
+ }
+ }
+ }
+
+ for (;;) {
+ uint8_t data[64];
+ int r = SDL_hid_read(device->dev, data, sizeof(data));
+
+ if (r == 0) {
+ return true;
+ }
+ if (r < 0) {
+ // Failed to read from controller
+ HIDAPI_DriverSteamTriton_SetControllerConnected(device, false);
+ return false;
+ }
+
+#ifdef DEBUG_STEAM_PROTOCOL
+ HIDAPI_DumpPacket("Steam Controller packet: size = %d", data, r);
+#endif
+
+ switch (data[0]) {
+ case ID_TRITON_CONTROLLER_STATE:
+ case ID_TRITON_CONTROLLER_STATE_BLE:
+ if (!joystick) {
+ HIDAPI_DriverSteamTriton_SetControllerConnected(device, true);
+ if (device->num_joysticks > 0) {
+ joystick = SDL_GetJoystickFromID(device->joysticks[0]);
+ }
+ }
+ if (joystick && r >= (1 + sizeof(TritonMTUNoQuat_t))) {
+ TritonMTUNoQuat_t *pTritonReport = (TritonMTUNoQuat_t *)&data[1];
+ HIDAPI_DriverSteamTriton_HandleState(device, joystick, pTritonReport);
+ }
+ break;
+ case ID_TRITON_CONTROLLER_STATE_TIMESTAMP:
+ if (!joystick) {
+ HIDAPI_DriverSteamTriton_SetControllerConnected(device, true);
+ if (device->num_joysticks > 0) {
+ joystick = SDL_GetJoystickFromID(device->joysticks[0]);
+ }
+ }
+ if (joystick && r >= (1 + sizeof(TritonMTUNoQuat32TS_t))) {
+ TritonMTUNoQuat32TS_t *pTritonReport = (TritonMTUNoQuat32TS_t *)&data[1];
+ HIDAPI_DriverSteamTriton_HandleState_Timestamp(device, joystick, pTritonReport);
+ }
+ break;
+ case ID_TRITON_BATTERY_STATUS:
+ if (joystick && r >= (1 + sizeof(TritonBatteryStatus_t))) {
+ TritonBatteryStatus_t *pTritonBatteryStatus = (TritonBatteryStatus_t *)&data[1];
+ HIDAPI_DriverSteamTriton_HandleBatteryStatus(device, joystick, pTritonBatteryStatus);
+ }
+ break;
+ case ID_TRITON_WIRELESS_STATUS_X:
+ case ID_TRITON_WIRELESS_STATUS:
+ if (r >= (1 + sizeof(TritonWirelessStatus_t))) {
+ TritonWirelessStatus_t *pTritonWirelessStatus = (TritonWirelessStatus_t *)&data[1];
+ HIDAPI_DriverSteamTriton_HandleWirelessStatus(device, pTritonWirelessStatus);
+ }
+ break;
+ default:
+ break;
+ }
+ }
+}
+
+static bool HIDAPI_DriverSteamTriton_OpenJoystick(SDL_HIDAPI_Device *device, SDL_Joystick *joystick)
+{
+ float update_rate_in_hz = 1000000.0f / TRITON_SENSOR_UPDATE_INTERVAL_US;
+
+ SDL_AssertJoysticksLocked();
+
+ // Initialize the joystick capabilities
+ joystick->nbuttons = SDL_GAMEPAD_NUM_TRITON_BUTTONS;
+ joystick->naxes = SDL_GAMEPAD_AXIS_COUNT;
+ joystick->nhats = 1;
+
+ SDL_PrivateJoystickAddSensor(joystick, SDL_SENSOR_GYRO, update_rate_in_hz);
+ SDL_PrivateJoystickAddSensor(joystick, SDL_SENSOR_ACCEL, update_rate_in_hz);
+
+ SDL_PrivateJoystickAddTouchpad(joystick, 1);
+ SDL_PrivateJoystickAddTouchpad(joystick, 1);
+
+ return true;
+}
+
+static bool HIDAPI_DriverSteamTriton_RumbleJoystick(SDL_HIDAPI_Device *device, SDL_Joystick *joystick, Uint16 low_frequency_rumble, Uint16 high_frequency_rumble)
+{
+ SDL_DriverSteamTriton_Context *ctx = (SDL_DriverSteamTriton_Context *)device->context;
+ int rc;
+
+ ctx->low_frequency_rumble = low_frequency_rumble;
+ ctx->high_frequency_rumble = high_frequency_rumble;
+ ctx->last_rumble_time = SDL_GetTicks();
+
+ Uint8 buffer[HID_RUMBLE_OUTPUT_REPORT_BYTES] = { 0 };
+ OutputReportMsg *msg = (OutputReportMsg *)(buffer);
+
+ msg->report_id = ID_OUT_REPORT_HAPTIC_RUMBLE;
+ msg->payload.hapticRumble.type = 0;
+ msg->payload.hapticRumble.intensity = 0;
+ msg->payload.hapticRumble.left.speed = low_frequency_rumble;
+ msg->payload.hapticRumble.left.gain = 0;
+ msg->payload.hapticRumble.right.speed = high_frequency_rumble;
+ msg->payload.hapticRumble.right.gain = 0;
+
+ rc = SDL_hid_write(device->dev, buffer, sizeof(buffer));
+ if (rc < 0) {
+ SDL_LogError(SDL_LOG_CATEGORY_INPUT,
+ "Steam Controller HID Write FAILED! rc: %d. SDL_Error: %s",
+ rc, SDL_GetError());
+
+ return false;
+ }
+ return true;
+}
+
+static bool HIDAPI_DriverSteamTriton_RumbleJoystickTriggers(SDL_HIDAPI_Device *device, SDL_Joystick *joystick, Uint16 left_rumble, Uint16 right_rumble)
+{
+ return SDL_Unsupported();
+}
+
+static Uint32 HIDAPI_DriverSteamTriton_GetJoystickCapabilities(SDL_HIDAPI_Device *device, SDL_Joystick *joystick)
+{
+ return SDL_JOYSTICK_CAP_RUMBLE;
+}
+
+static bool HIDAPI_DriverSteamTriton_SetJoystickLED(SDL_HIDAPI_Device *device, SDL_Joystick *joystick, Uint8 red, Uint8 green, Uint8 blue)
+{
+ return SDL_Unsupported();
+}
+
+static bool HIDAPI_DriverSteamTriton_SendJoystickEffect(SDL_HIDAPI_Device *device, SDL_Joystick *joystick, const void *data, int size)
+{
+ if (size == HID_FEATURE_REPORT_BYTES) {
+ int rc = SDL_hid_send_feature_report(device->dev, data, size);
+ if (rc != size) {
+ return false;
+ }
+ return true;
+ }
+ return SDL_Unsupported();
+}
+
+static bool HIDAPI_DriverSteamTriton_SetSensorsEnabled(SDL_HIDAPI_Device *device, SDL_Joystick *joystick, bool enabled)
+{
+ SDL_DriverSteamTriton_Context *ctx = (SDL_DriverSteamTriton_Context *)device->context;
+ int rc;
+ Uint8 buffer[HID_FEATURE_REPORT_BYTES] = { 1 };
+ FeatureReportMsg *msg = (FeatureReportMsg *)(buffer + 1);
+
+ msg->header.type = ID_SET_SETTINGS_VALUES;
+ msg->header.length = 1 * sizeof(ControllerSetting);
+ msg->payload.setSettingsValues.settings[0].settingNum = SETTING_IMU_MODE;
+ if (enabled) {
+ msg->payload.setSettingsValues.settings[0].settingValue = (SETTING_GYRO_MODE_SEND_RAW_ACCEL | SETTING_GYRO_MODE_SEND_RAW_GYRO);
+ } else {
+ msg->payload.setSettingsValues.settings[0].settingValue = SETTING_GYRO_MODE_OFF;
+ }
+
+ rc = SDL_hid_send_feature_report(device->dev, buffer, sizeof(buffer));
+ if (rc != sizeof(buffer)) {
+ return false;
+ }
+
+ ctx->report_sensors = enabled;
+
+ return true;
+}
+
+static void HIDAPI_DriverSteamTriton_CloseJoystick(SDL_HIDAPI_Device *device, SDL_Joystick *joystick)
+{
+ // Lizard mode id automatically re-enabled by watchdog. Nothing to do here.
+}
+
+static void HIDAPI_DriverSteamTriton_FreeDevice(SDL_HIDAPI_Device *device)
+{
+}
+
+SDL_HIDAPI_DeviceDriver SDL_HIDAPI_DriverSteamTriton = {
+ SDL_HINT_JOYSTICK_HIDAPI_STEAM,
+ true,
+ HIDAPI_DriverSteamTriton_RegisterHints,
+ HIDAPI_DriverSteamTriton_UnregisterHints,
+ HIDAPI_DriverSteamTriton_IsEnabled,
+ HIDAPI_DriverSteamTriton_IsSupportedDevice,
+ HIDAPI_DriverSteamTriton_InitDevice,
+ HIDAPI_DriverSteamTriton_GetDevicePlayerIndex,
+ HIDAPI_DriverSteamTriton_SetDevicePlayerIndex,
+ HIDAPI_DriverSteamTriton_UpdateDevice,
+ HIDAPI_DriverSteamTriton_OpenJoystick,
+ HIDAPI_DriverSteamTriton_RumbleJoystick,
+ HIDAPI_DriverSteamTriton_RumbleJoystickTriggers,
+ HIDAPI_DriverSteamTriton_GetJoystickCapabilities,
+ HIDAPI_DriverSteamTriton_SetJoystickLED,
+ HIDAPI_DriverSteamTriton_SendJoystickEffect,
+ HIDAPI_DriverSteamTriton_SetSensorsEnabled,
+ HIDAPI_DriverSteamTriton_CloseJoystick,
+ HIDAPI_DriverSteamTriton_FreeDevice,
+};
+
+#endif // SDL_JOYSTICK_HIDAPI_STEAM_TRITON
+
+#endif // SDL_JOYSTICK_HIDAPI
diff --git a/thirdparty/sdl/joystick/hidapi/SDL_hidapi_steamdeck.c b/thirdparty/sdl/joystick/hidapi/SDL_hidapi_steamdeck.c
index 75a13cc1b92..8bfb64dfd61 100644
--- a/thirdparty/sdl/joystick/hidapi/SDL_hidapi_steamdeck.c
+++ b/thirdparty/sdl/joystick/hidapi/SDL_hidapi_steamdeck.c
@@ -39,6 +39,10 @@ enum
SDL_GAMEPAD_BUTTON_STEAM_DECK_LEFT_PADDLE1,
SDL_GAMEPAD_BUTTON_STEAM_DECK_RIGHT_PADDLE2,
SDL_GAMEPAD_BUTTON_STEAM_DECK_LEFT_PADDLE2,
+ SDL_GAMEPAD_BUTTON_STEAM_DECK_RIGHT_TOUCHPAD,
+ SDL_GAMEPAD_BUTTON_STEAM_DECK_LEFT_TOUCHPAD,
+ SDL_GAMEPAD_BUTTON_STEAM_DECK_RIGHT_JOYSTICK_TOUCH,
+ SDL_GAMEPAD_BUTTON_STEAM_DECK_LEFT_JOYSTICK_TOUCH,
SDL_GAMEPAD_NUM_STEAM_DECK_BUTTONS,
};
@@ -63,20 +67,31 @@ typedef enum
STEAMDECK_LBUTTON_R5 = 0x00010000,
STEAMDECK_LBUTTON_LEFT_PAD = 0x00020000,
STEAMDECK_LBUTTON_RIGHT_PAD = 0x00040000,
+ STEAMDECK_LBUTTON_LEFT_TOUCHPAD_TOUCH = 0x00080000,
+ STEAMDECK_LBUTTON_RIGHT_TOUCHPAD_TOUCH = 0x00100000,
STEAMDECK_LBUTTON_L3 = 0x00400000,
STEAMDECK_LBUTTON_R3 = 0x04000000,
STEAMDECK_HBUTTON_L4 = 0x00000200,
STEAMDECK_HBUTTON_R4 = 0x00000400,
+ STEAMDECK_HBUTTON_LSTICK_TOUCH = 0x00004000,
+ STEAMDECK_HBUTTON_RSTICK_TOUCH = 0x00008000,
STEAMDECK_HBUTTON_QAM = 0x00040000,
} SteamDeckButtons;
typedef struct
{
Uint32 update_rate_us;
- Uint32 sensor_timestamp_us;
+ Uint64 sensor_timestamp_ns;
Uint64 last_button_state;
Uint8 watchdog_counter;
+
+ bool left_touch_down;
+ float left_touch_x;
+ float left_touch_y;
+ bool right_touch_down;
+ float right_touch_x;
+ float right_touch_y;
} SDL_DriverSteamDeck_Context;
static bool DisableDeckLizardMode(SDL_hid_device *dev)
@@ -191,6 +206,16 @@ static void HIDAPI_DriverSteamDeck_HandleState(SDL_HIDAPI_Device *device,
SDL_SendJoystickButton(timestamp, joystick, SDL_GAMEPAD_BUTTON_STEAM_DECK_LEFT_PADDLE2,
((pInReport->payload.deckState.ulButtonsL & STEAMDECK_LBUTTON_L5) != 0));
+ SDL_SendJoystickButton(timestamp, joystick, SDL_GAMEPAD_BUTTON_STEAM_DECK_RIGHT_TOUCHPAD,
+ ((pInReport->payload.deckState.ulButtonsL & STEAMDECK_LBUTTON_RIGHT_PAD) != 0));
+ SDL_SendJoystickButton(timestamp, joystick, SDL_GAMEPAD_BUTTON_STEAM_DECK_LEFT_TOUCHPAD,
+ ((pInReport->payload.deckState.ulButtonsL & STEAMDECK_LBUTTON_LEFT_PAD) != 0));
+
+ SDL_SendJoystickButton(timestamp, joystick, SDL_GAMEPAD_BUTTON_STEAM_DECK_RIGHT_JOYSTICK_TOUCH,
+ ((pInReport->payload.deckState.ulButtonsH & STEAMDECK_HBUTTON_RSTICK_TOUCH) != 0));
+ SDL_SendJoystickButton(timestamp, joystick, SDL_GAMEPAD_BUTTON_STEAM_DECK_LEFT_JOYSTICK_TOUCH,
+ ((pInReport->payload.deckState.ulButtonsH & STEAMDECK_HBUTTON_LSTICK_TOUCH) != 0));
+
if (pInReport->payload.deckState.ulButtonsL & STEAMDECK_LBUTTON_DPAD_UP) {
hat |= SDL_HAT_UP;
}
@@ -222,17 +247,45 @@ static void HIDAPI_DriverSteamDeck_HandleState(SDL_HIDAPI_Device *device,
SDL_SendJoystickAxis(timestamp, joystick, SDL_GAMEPAD_AXIS_RIGHTY,
-pInReport->payload.deckState.sRightStickY);
- ctx->sensor_timestamp_us += ctx->update_rate_us;
+ ctx->sensor_timestamp_ns += SDL_US_TO_NS(ctx->update_rate_us);
values[0] = (pInReport->payload.deckState.sGyroX / 32768.0f) * (2000.0f * (SDL_PI_F / 180.0f));
values[1] = (pInReport->payload.deckState.sGyroZ / 32768.0f) * (2000.0f * (SDL_PI_F / 180.0f));
values[2] = (-pInReport->payload.deckState.sGyroY / 32768.0f) * (2000.0f * (SDL_PI_F / 180.0f));
- SDL_SendJoystickSensor(timestamp, joystick, SDL_SENSOR_GYRO, ctx->sensor_timestamp_us, values, 3);
+ SDL_SendJoystickSensor(timestamp, joystick, SDL_SENSOR_GYRO, ctx->sensor_timestamp_ns, values, 3);
values[0] = (pInReport->payload.deckState.sAccelX / 32768.0f) * 2.0f * SDL_STANDARD_GRAVITY;
values[1] = (pInReport->payload.deckState.sAccelZ / 32768.0f) * 2.0f * SDL_STANDARD_GRAVITY;
values[2] = (-pInReport->payload.deckState.sAccelY / 32768.0f) * 2.0f * SDL_STANDARD_GRAVITY;
- SDL_SendJoystickSensor(timestamp, joystick, SDL_SENSOR_ACCEL, ctx->sensor_timestamp_us, values, 3);
+ SDL_SendJoystickSensor(timestamp, joystick, SDL_SENSOR_ACCEL, ctx->sensor_timestamp_ns, values, 3);
+
+ bool left_touch_down = (pInReport->payload.deckState.ulButtonsL & STEAMDECK_LBUTTON_LEFT_TOUCHPAD_TOUCH) ? true : false;
+ bool right_touch_down = (pInReport->payload.deckState.ulButtonsL & STEAMDECK_LBUTTON_RIGHT_TOUCHPAD_TOUCH) ? true : false;
+ if (left_touch_down || ctx->left_touch_down) {
+ if (left_touch_down) {
+ ctx->left_touch_x = pInReport->payload.deckState.sLeftPadX / 65536.0f + 0.5f;
+ ctx->left_touch_y = -(float)pInReport->payload.deckState.sLeftPadY / 65536.0f + 0.5f;
+
+ }
+ SDL_SendJoystickTouchpad(timestamp, joystick, 0, 0,
+ left_touch_down,
+ ctx->left_touch_x,
+ ctx->left_touch_y,
+ pInReport->payload.deckState.sPressurePadLeft / 32768.0f);
+ ctx->left_touch_down = left_touch_down;
+ }
+ if (right_touch_down || ctx->right_touch_down) {
+ if (right_touch_down) {
+ ctx->right_touch_x = pInReport->payload.deckState.sRightPadX / 65536.0f + 0.5f;
+ ctx->right_touch_y = -(float)pInReport->payload.deckState.sRightPadY / 65536.0f + 0.5f;
+ }
+ SDL_SendJoystickTouchpad(timestamp, joystick, 1, 0,
+ right_touch_down,
+ ctx->right_touch_x,
+ ctx->right_touch_y,
+ pInReport->payload.deckState.sPressurePadRight / 32768.0f);
+ ctx->right_touch_down = right_touch_down;
+ }
}
/*****************************************************************************************************/
@@ -331,7 +384,7 @@ static bool HIDAPI_DriverSteamDeck_UpdateDevice(SDL_HIDAPI_Device *device)
return false;
}
- SDL_memset(data, 0, sizeof(data));
+ SDL_zeroa(data);
do {
r = SDL_hid_read(device->dev, data, sizeof(data));
@@ -366,6 +419,9 @@ static bool HIDAPI_DriverSteamDeck_OpenJoystick(SDL_HIDAPI_Device *device, SDL_J
SDL_PrivateJoystickAddSensor(joystick, SDL_SENSOR_GYRO, update_rate_in_hz);
SDL_PrivateJoystickAddSensor(joystick, SDL_SENSOR_ACCEL, update_rate_in_hz);
+ SDL_PrivateJoystickAddTouchpad(joystick, 1);
+ SDL_PrivateJoystickAddTouchpad(joystick, 1);
+
return true;
}
diff --git a/thirdparty/sdl/joystick/hidapi/SDL_hidapi_switch.c b/thirdparty/sdl/joystick/hidapi/SDL_hidapi_switch.c
index 580a6bd2dca..7580385af0e 100644
--- a/thirdparty/sdl/joystick/hidapi/SDL_hidapi_switch.c
+++ b/thirdparty/sdl/joystick/hidapi/SDL_hidapi_switch.c
@@ -1,6 +1,6 @@
/*
Simple DirectMedia Layer
- Copyright (C) 1997-2025 Sam Lantinga <[email protected]>
+ Copyright (C) 1997-2026 Sam Lantinga <[email protected]>
This software is provided 'as-is', without any express or implied
warranty. In no event will the authors be held liable for any damages
@@ -34,7 +34,9 @@
#ifdef SDL_JOYSTICK_HIDAPI_SWITCH
// Define this if you want to log all packets from the controller
-// #define DEBUG_SWITCH_PROTOCOL
+#if 0
+#define DEBUG_SWITCH_PROTOCOL
+#endif
// Define this to get log output for rumble logic
// #define DEBUG_RUMBLE
@@ -314,6 +316,8 @@ typedef struct
Uint64 m_ulIMUUpdateIntervalNS;
Uint64 m_ulTimestampNS;
bool m_bVerticalMode;
+ SDL_PowerState m_ePowerState;
+ int m_nPowerPercent;
SwitchInputOnlyControllerStatePacket_t m_lastInputOnlyState;
SwitchSimpleStatePacket_t m_lastSimpleState;
@@ -446,7 +450,7 @@ static bool ReadProprietaryReply(SDL_DriverSwitch_Context *ctx, ESwitchProprieta
static void ConstructSubcommand(SDL_DriverSwitch_Context *ctx, ESwitchSubcommandIDs ucCommandID, const Uint8 *pBuf, Uint8 ucLen, SwitchSubcommandOutputPacket_t *outPacket)
{
- SDL_memset(outPacket, 0, sizeof(*outPacket));
+ SDL_zerop(outPacket);
outPacket->commonData.ucPacketType = k_eSwitchOutputReportIDs_RumbleAndSubcommand;
outPacket->commonData.ucPacketNumber = ctx->m_nCommandNumber;
@@ -566,15 +570,33 @@ static Uint16 EncodeRumbleLowAmplitude(Uint16 amplitude)
return lfa[100][1];
}
-static void SetNeutralRumble(SwitchRumbleData_t *pRumble)
+static void SetNeutralRumble(SDL_HIDAPI_Device *device, SwitchRumbleData_t *pRumble)
{
- pRumble->rgucData[0] = 0x00;
- pRumble->rgucData[1] = 0x01;
- pRumble->rgucData[2] = 0x40;
- pRumble->rgucData[3] = 0x40;
+ bool bStandardNeutralValue;
+ if (device->vendor_id == USB_VENDOR_NINTENDO &&
+ device->product_id == USB_PRODUCT_NINTENDO_N64_CONTROLLER) {
+ // The 8BitDo 64 Bluetooth Controller rumbles at startup with the standard neutral value,
+ // so we'll use a 0 amplitude value instead.
+ bStandardNeutralValue = false;
+ } else {
+ // The KingKong2 PRO Controller doesn't initialize correctly with a 0 amplitude value
+ // over Bluetooth, so we'll use the standard value in all other cases.
+ bStandardNeutralValue = true;
+ }
+ if (bStandardNeutralValue) {
+ pRumble->rgucData[0] = 0x00;
+ pRumble->rgucData[1] = 0x01;
+ pRumble->rgucData[2] = 0x40;
+ pRumble->rgucData[3] = 0x40;
+ } else {
+ pRumble->rgucData[0] = 0x00;
+ pRumble->rgucData[1] = 0x00;
+ pRumble->rgucData[2] = 0x01;
+ pRumble->rgucData[3] = 0x40;
+ }
}
-static void EncodeRumble(SwitchRumbleData_t *pRumble, Uint16 usHighFreq, Uint8 ucHighFreqAmp, Uint8 ucLowFreq, Uint16 usLowFreqAmp)
+static void EncodeRumble(SDL_HIDAPI_Device *device, SwitchRumbleData_t *pRumble, Uint16 usHighFreq, Uint8 ucHighFreqAmp, Uint8 ucLowFreq, Uint16 usLowFreqAmp)
{
if (ucHighFreqAmp > 0 || usLowFreqAmp > 0) {
// High-band frequency and low-band amplitude are actually nine-bits each so they
@@ -591,7 +613,7 @@ static void EncodeRumble(SwitchRumbleData_t *pRumble, Uint16 usHighFreq, Uint8 u
ucHighFreqAmp, ((usLowFreqAmp >> 8) & 0x80), usLowFreqAmp & 0xFF);
#endif
} else {
- SetNeutralRumble(pRumble);
+ SetNeutralRumble(device, pRumble);
}
}
@@ -756,9 +778,10 @@ static void UpdateSlotLED(SDL_DriverSwitch_Context *ctx)
{
if (!ctx->m_bInputOnly) {
Uint8 led_data = 0;
+ const Uint8 player_pattern[] = { 0x1, 0x3, 0x7, 0xf, 0x9, 0x5, 0xd, 0x6 };
if (ctx->m_bPlayerLights && ctx->m_nPlayerIndex >= 0) {
- led_data = (1 << (ctx->m_nPlayerIndex % 4));
+ led_data = player_pattern[ctx->m_nPlayerIndex % 8];
}
WriteSubcommand(ctx, k_eSwitchSubcommandIDs_SetPlayerLights, &led_data, sizeof(led_data), NULL);
}
@@ -937,14 +960,14 @@ static bool SetIMUEnabled(SDL_DriverSwitch_Context *ctx, bool enabled)
static bool LoadStickCalibration(SDL_DriverSwitch_Context *ctx)
{
- Uint8 *pLeftStickCal = NULL;
- Uint8 *pRightStickCal = NULL;
+ Uint8 pLeftStickCal[9];
+ Uint8 pRightStickCal[9];
+ bool have_left_stick_cal = false, have_right_stick_cal = false;
size_t stick, axis;
SwitchSubcommandInputPacket_t *user_reply = NULL;
SwitchSubcommandInputPacket_t *factory_reply = NULL;
SwitchSPIOpData_t readUserParams;
SwitchSPIOpData_t readFactoryParams;
- Uint8 userParamsReadSuccessCount = 0;
// Read User Calibration Info
readUserParams.unAddress = k_unSPIStickUserCalibrationStartOffset;
@@ -959,17 +982,17 @@ static bool LoadStickCalibration(SDL_DriverSwitch_Context *ctx)
// Automatically select the user calibration if magic bytes are set
if (user_reply && user_reply->stickUserCalibration.rgucLeftMagic[0] == 0xB2 && user_reply->stickUserCalibration.rgucLeftMagic[1] == 0xA1) {
- userParamsReadSuccessCount += 1;
- pLeftStickCal = user_reply->stickUserCalibration.rgucLeftCalibration;
+ have_left_stick_cal = true;
+ SDL_memcpy(pLeftStickCal, user_reply->stickUserCalibration.rgucLeftCalibration, sizeof(pLeftStickCal));
}
if (user_reply && user_reply->stickUserCalibration.rgucRightMagic[0] == 0xB2 && user_reply->stickUserCalibration.rgucRightMagic[1] == 0xA1) {
- userParamsReadSuccessCount += 1;
- pRightStickCal = user_reply->stickUserCalibration.rgucRightCalibration;
- }
+ have_right_stick_cal = true;
+ SDL_memcpy(pRightStickCal, user_reply->stickUserCalibration.rgucRightCalibration, sizeof(pRightStickCal));
+ }
// Only read the factory calibration info if we failed to receive the correct magic bytes
- if (userParamsReadSuccessCount < 2) {
+ if (!have_left_stick_cal || !have_right_stick_cal) {
// Read Factory Calibration Info
readFactoryParams.unAddress = k_unSPIStickFactoryCalibrationStartOffset;
readFactoryParams.ucLength = k_unSPIStickFactoryCalibrationLength;
@@ -982,8 +1005,17 @@ static bool LoadStickCalibration(SDL_DriverSwitch_Context *ctx)
if (factory_reply->stickFactoryCalibration.opData.unAddress == k_unSPIStickFactoryCalibrationStartOffset) {
// We successfully read the calibration data
- pLeftStickCal = factory_reply->stickFactoryCalibration.rgucLeftCalibration;
- pRightStickCal = factory_reply->stickFactoryCalibration.rgucRightCalibration;
+ // Avoid overriding user calibration if it's present for only one stick (known to happen on JoyCons)
+ if (!have_left_stick_cal) {
+ have_left_stick_cal = true;
+ SDL_memcpy(pLeftStickCal, factory_reply->stickFactoryCalibration.rgucLeftCalibration, sizeof(pLeftStickCal));
+ }
+
+ if (!have_right_stick_cal) {
+ have_right_stick_cal = true;
+ SDL_memcpy(pRightStickCal, factory_reply->stickFactoryCalibration.rgucRightCalibration, sizeof(pRightStickCal));
+ }
+
break;
}
@@ -994,7 +1026,7 @@ static bool LoadStickCalibration(SDL_DriverSwitch_Context *ctx)
}
// If we still don't have calibration data, return false
- if (pLeftStickCal == NULL || pRightStickCal == NULL)
+ if (!have_left_stick_cal || !have_right_stick_cal)
{
return false;
}
@@ -1395,7 +1427,15 @@ static bool HIDAPI_DriverSwitch_IsSupportedDevice(SDL_HIDAPI_Device *device, con
return false;
}
- return (type == SDL_GAMEPAD_TYPE_NINTENDO_SWITCH_PRO);
+ if (type != SDL_GAMEPAD_TYPE_NINTENDO_SWITCH_PRO) {
+ return false;
+ }
+
+ // The Nintendo Switch 2 Pro uses another driver
+ if (vendor_id == USB_VENDOR_NINTENDO && product_id == USB_PRODUCT_NINTENDO_SWITCH2_PRO) {
+ return false;
+ }
+ return true;
}
static void UpdateDeviceIdentity(SDL_HIDAPI_Device *device)
@@ -1404,7 +1444,7 @@ static void UpdateDeviceIdentity(SDL_HIDAPI_Device *device)
if (ctx->m_bInputOnly) {
if (SDL_IsJoystickGameCube(device->vendor_id, device->product_id)) {
- device->type = SDL_GAMEPAD_TYPE_STANDARD;
+ device->type = SDL_GAMEPAD_TYPE_GAMECUBE;
}
} else {
char serial[18];
@@ -1427,11 +1467,11 @@ static void UpdateDeviceIdentity(SDL_HIDAPI_Device *device)
device->type = SDL_GAMEPAD_TYPE_NINTENDO_SWITCH_PRO;
break;
case k_eSwitchDeviceInfoControllerType_HVCLeft:
- HIDAPI_SetDeviceName(device, "Nintendo HVC Controller (1)");
+ HIDAPI_SetDeviceName(device, "Nintendo Family Computer Controller (1)");
device->type = SDL_GAMEPAD_TYPE_STANDARD;
break;
case k_eSwitchDeviceInfoControllerType_HVCRight:
- HIDAPI_SetDeviceName(device, "Nintendo HVC Controller (2)");
+ HIDAPI_SetDeviceName(device, "Nintendo Family Computer Controller (2)");
device->type = SDL_GAMEPAD_TYPE_STANDARD;
break;
case k_eSwitchDeviceInfoControllerType_NESLeft:
@@ -1516,8 +1556,8 @@ static bool HIDAPI_DriverSwitch_InitDevice(SDL_HIDAPI_Device *device)
ctx->m_bInputOnly = SDL_IsJoystickNintendoSwitchProInputOnly(device->vendor_id, device->product_id);
if (!ctx->m_bInputOnly) {
// Initialize rumble data, important for reading device info on the MOBAPAD M073
- SetNeutralRumble(&ctx->m_RumblePacket.rumbleData[0]);
- SetNeutralRumble(&ctx->m_RumblePacket.rumbleData[1]);
+ SetNeutralRumble(device, &ctx->m_RumblePacket.rumbleData[0]);
+ SetNeutralRumble(device, &ctx->m_RumblePacket.rumbleData[1]);
BReadDeviceInfo(ctx);
}
@@ -1571,8 +1611,8 @@ static bool HIDAPI_DriverSwitch_OpenJoystick(SDL_HIDAPI_Device *device, SDL_Joys
ctx->m_nCurrentInputMode = ctx->m_nInitialInputMode;
// Initialize rumble data
- SetNeutralRumble(&ctx->m_RumblePacket.rumbleData[0]);
- SetNeutralRumble(&ctx->m_RumblePacket.rumbleData[1]);
+ SetNeutralRumble(device, &ctx->m_RumblePacket.rumbleData[0]);
+ SetNeutralRumble(device, &ctx->m_RumblePacket.rumbleData[1]);
if (!device->is_bluetooth) {
if (!BTrySetupUSB(ctx)) {
@@ -1592,7 +1632,8 @@ static bool HIDAPI_DriverSwitch_OpenJoystick(SDL_HIDAPI_Device *device, SDL_Joys
ctx->m_eControllerType != k_eSwitchDeviceInfoControllerType_NESRight &&
ctx->m_eControllerType != k_eSwitchDeviceInfoControllerType_SNES &&
ctx->m_eControllerType != k_eSwitchDeviceInfoControllerType_N64 &&
- ctx->m_eControllerType != k_eSwitchDeviceInfoControllerType_SEGA_Genesis) {
+ ctx->m_eControllerType != k_eSwitchDeviceInfoControllerType_SEGA_Genesis &&
+ !(device->vendor_id == USB_VENDOR_PDP && device->product_id == USB_PRODUCT_PDP_REALMZ_WIRELESS)) {
if (LoadIMUCalibration(ctx)) {
ctx->m_bSensorsSupported = true;
}
@@ -1669,11 +1710,11 @@ static bool HIDAPI_DriverSwitch_ActuallyRumbleJoystick(SDL_DriverSwitch_Context
const Uint16 k_usLowFreqAmp = EncodeRumbleLowAmplitude(low_frequency_rumble);
if (low_frequency_rumble || high_frequency_rumble) {
- EncodeRumble(&ctx->m_RumblePacket.rumbleData[0], k_usHighFreq, k_ucHighFreqAmp, k_ucLowFreq, k_usLowFreqAmp);
- EncodeRumble(&ctx->m_RumblePacket.rumbleData[1], k_usHighFreq, k_ucHighFreqAmp, k_ucLowFreq, k_usLowFreqAmp);
+ EncodeRumble(ctx->device, &ctx->m_RumblePacket.rumbleData[0], k_usHighFreq, k_ucHighFreqAmp, k_ucLowFreq, k_usLowFreqAmp);
+ EncodeRumble(ctx->device, &ctx->m_RumblePacket.rumbleData[1], k_usHighFreq, k_ucHighFreqAmp, k_ucLowFreq, k_usLowFreqAmp);
} else {
- SetNeutralRumble(&ctx->m_RumblePacket.rumbleData[0]);
- SetNeutralRumble(&ctx->m_RumblePacket.rumbleData[1]);
+ SetNeutralRumble(ctx->device, &ctx->m_RumblePacket.rumbleData[0]);
+ SetNeutralRumble(ctx->device, &ctx->m_RumblePacket.rumbleData[1]);
}
ctx->m_bRumbleActive = (low_frequency_rumble || high_frequency_rumble);
@@ -1780,24 +1821,29 @@ static Uint32 HIDAPI_DriverSwitch_GetJoystickCapabilities(SDL_HIDAPI_Device *dev
if (ctx->m_eControllerType == k_eSwitchDeviceInfoControllerType_ProController && !ctx->m_bInputOnly) {
// Doesn't have an RGB LED, so don't return SDL_JOYSTICK_CAP_RGB_LED here
result |= SDL_JOYSTICK_CAP_RUMBLE;
- // But has the HOME LED, so
- result |= SDL_JOYSTICK_CAP_MONO_LED;
+ // But has the HOME LED, so treat it like a mono LED
+ result |= SDL_JOYSTICK_CAP_MONO_LED;
} else if (ctx->m_eControllerType == k_eSwitchDeviceInfoControllerType_JoyConLeft ||
ctx->m_eControllerType == k_eSwitchDeviceInfoControllerType_JoyConRight) {
result |= SDL_JOYSTICK_CAP_RUMBLE;
- if (ctx->m_eControllerType == k_eSwitchDeviceInfoControllerType_JoyConRight) {
- result |= SDL_JOYSTICK_CAP_MONO_LED; // Those types of controllers also have the Home LED.
- }
+ if (ctx->m_eControllerType == k_eSwitchDeviceInfoControllerType_JoyConRight) {
+ result |= SDL_JOYSTICK_CAP_MONO_LED; // Right JoyCon also have the HOME LED
+ }
}
-
return result;
}
static bool HIDAPI_DriverSwitch_SetJoystickLED(SDL_HIDAPI_Device *device, SDL_Joystick *joystick, Uint8 red, Uint8 green, Uint8 blue)
{
- SDL_DriverSwitch_Context *ctx = (SDL_DriverSwitch_Context *)device->context;
- int value = (int)((SDL_max(red, SDL_max(green, blue)) / 255.0f) * 100.0f); // The colors are received between 0-255 and we need them to be 0-100.
- return SetHomeLED(ctx, (Uint8)value);
+ SDL_DriverSwitch_Context *ctx = (SDL_DriverSwitch_Context *)device->context;
+
+ if (!(ctx->m_eControllerType == k_eSwitchDeviceInfoControllerType_ProController && !ctx->m_bInputOnly) &&
+ ctx->m_eControllerType != k_eSwitchDeviceInfoControllerType_JoyConRight) {
+ return SDL_Unsupported();
+ }
+
+ int value = (int)((SDL_max(red, SDL_max(green, blue)) / 255.0f) * 100.0f); // The colors are received between 0-255 and we need them to be 0-100
+ return SetHomeLED(ctx, (Uint8)value);
}
static bool HIDAPI_DriverSwitch_SendJoystickEffect(SDL_HIDAPI_Device *device, SDL_Joystick *joystick, const void *data, int size)
@@ -2589,27 +2635,35 @@ static void HandleFullControllerState(SDL_Joystick *joystick, SDL_DriverSwitch_C
* LSB of the battery nibble is used to report charging.
* The battery level is reported from 0(empty)-8(full)
*/
- SDL_PowerState state;
int charging = (packet->controllerState.ucBatteryAndConnection & 0x10);
int level = (packet->controllerState.ucBatteryAndConnection & 0xE0) >> 4;
- int percent = (int)SDL_roundf((level / 8.0f) * 100.0f);
-
if (charging) {
if (level == 8) {
- state = SDL_POWERSTATE_CHARGED;
+ ctx->m_ePowerState = SDL_POWERSTATE_CHARGED;
} else {
- state = SDL_POWERSTATE_CHARGING;
+ ctx->m_ePowerState = SDL_POWERSTATE_CHARGING;
}
} else {
- state = SDL_POWERSTATE_ON_BATTERY;
+ ctx->m_ePowerState = SDL_POWERSTATE_ON_BATTERY;
+ }
+ ctx->m_nPowerPercent = (int)SDL_roundf((level / 8.0f) * 100.0f);
+
+ if (!ctx->device->parent) {
+ SDL_PowerState state = ctx->m_ePowerState;
+ int percent = ctx->m_nPowerPercent;
+ SDL_SendJoystickPowerInfo(joystick, state, percent);
+ } else if (ctx->m_eControllerType == k_eSwitchDeviceInfoControllerType_JoyConRight) {
+ SDL_DriverSwitch_Context *other = (SDL_DriverSwitch_Context *)ctx->device->parent->children[0]->context;
+ SDL_PowerState state = (SDL_PowerState)SDL_min(ctx->m_ePowerState, other->m_ePowerState);
+ int percent = SDL_min(ctx->m_nPowerPercent, other->m_nPowerPercent);
+ SDL_SendJoystickPowerInfo(joystick, state, percent);
}
- SDL_SendJoystickPowerInfo(joystick, state, percent);
if (ctx->m_bReportSensors) {
// Need to copy the imuState to an aligned variable
SwitchControllerIMUState_t imuState[3];
- SDL_assert(sizeof(imuState) == sizeof(packet->imuState));
- SDL_memcpy(imuState, packet->imuState, sizeof(imuState));
+ SDL_COMPILE_TIME_ASSERT(imuState_size, sizeof(imuState) == sizeof(packet->imuState));
+ SDL_memcpy(imuState, packet->imuState, sizeof(packet->imuState));
bool bHasSensorData = (imuState[0].sAccelZ != 0 ||
imuState[0].sAccelY != 0 ||
diff --git a/thirdparty/sdl/joystick/hidapi/SDL_hidapi_switch2.c b/thirdparty/sdl/joystick/hidapi/SDL_hidapi_switch2.c
new file mode 100644
index 00000000000..773405c5132
--- /dev/null
+++ b/thirdparty/sdl/joystick/hidapi/SDL_hidapi_switch2.c
@@ -0,0 +1,1335 @@
+/*
+ Simple DirectMedia Layer
+ Copyright (C) 1997-2026 Sam Lantinga <[email protected]>
+
+ 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.
+*/
+/* This driver supports the Nintendo Switch Pro controller.
+ Code and logic contributed by Valve Corporation under the SDL zlib license.
+*/
+#include "SDL_internal.h"
+
+#ifdef SDL_JOYSTICK_HIDAPI
+
+#include "../../SDL_hints_c.h"
+#include "../../misc/SDL_libusb.h"
+#include "../SDL_sysjoystick.h"
+#include "SDL_hidapijoystick_c.h"
+#include "SDL_hidapi_rumble.h"
+
+#ifdef SDL_JOYSTICK_HIDAPI_SWITCH2
+
+#define RUMBLE_INTERVAL 12
+#define RUMBLE_MAX 29000
+
+// Define this if you want to log all packets from the controller
+#if 0
+#define DEBUG_SWITCH2_PROTOCOL
+#endif
+
+enum
+{
+ SDL_GAMEPAD_BUTTON_SWITCH2_PRO_SHARE = 11,
+ SDL_GAMEPAD_BUTTON_SWITCH2_PRO_C,
+ SDL_GAMEPAD_BUTTON_SWITCH2_PRO_RIGHT_PADDLE,
+ SDL_GAMEPAD_BUTTON_SWITCH2_PRO_LEFT_PADDLE,
+ SDL_GAMEPAD_NUM_SWITCH2_PRO_BUTTONS
+};
+
+enum
+{
+ SDL_GAMEPAD_BUTTON_SWITCH2_JOYCON_SHARE = 11,
+ SDL_GAMEPAD_BUTTON_SWITCH2_JOYCON_C,
+ SDL_GAMEPAD_BUTTON_SWITCH2_JOYCON_RIGHT_PADDLE1,
+ SDL_GAMEPAD_BUTTON_SWITCH2_JOYCON_LEFT_PADDLE1,
+ SDL_GAMEPAD_BUTTON_SWITCH2_JOYCON_RIGHT_PADDLE2,
+ SDL_GAMEPAD_BUTTON_SWITCH2_JOYCON_LEFT_PADDLE2,
+ SDL_GAMEPAD_NUM_SWITCH2_JOYCON_BUTTONS
+};
+
+enum
+{
+ SDL_GAMEPAD_BUTTON_SWITCH2_GAMECUBE_GUIDE = 4,
+ SDL_GAMEPAD_BUTTON_SWITCH2_GAMECUBE_START,
+ SDL_GAMEPAD_BUTTON_SWITCH2_GAMECUBE_LEFT_SHOULDER,
+ SDL_GAMEPAD_BUTTON_SWITCH2_GAMECUBE_RIGHT_SHOULDER,
+ SDL_GAMEPAD_BUTTON_SWITCH2_GAMECUBE_SHARE,
+ SDL_GAMEPAD_BUTTON_SWITCH2_GAMECUBE_C,
+ SDL_GAMEPAD_BUTTON_SWITCH2_GAMECUBE_LEFT_TRIGGER, // Full trigger pull click
+ SDL_GAMEPAD_BUTTON_SWITCH2_GAMECUBE_RIGHT_TRIGGER, // Full trigger pull click
+ SDL_GAMEPAD_NUM_SWITCH2_GAMECUBE_BUTTONS
+};
+
+typedef struct
+{
+ Uint16 neutral;
+ Uint16 max;
+ Uint16 min;
+} Switch2_AxisCalibration;
+
+typedef struct
+{
+ Switch2_AxisCalibration x;
+ Switch2_AxisCalibration y;
+} Switch2_StickCalibration;
+
+typedef struct
+{
+ SDL_HIDAPI_Device *device;
+ SDL_Joystick *joystick;
+
+ SDL_LibUSBContext *libusb;
+ libusb_device_handle *device_handle;
+ bool interface_claimed;
+ Uint8 interface_number;
+ Uint8 out_endpoint;
+ Uint8 in_endpoint;
+
+ Uint64 rumble_timestamp;
+ Uint32 rumble_seq;
+ Uint16 rumble_hi_amp;
+ Uint16 rumble_hi_freq;
+ Uint16 rumble_lo_amp;
+ Uint16 rumble_lo_freq;
+ Uint32 rumble_error;
+ bool rumble_updated;
+
+ Switch2_StickCalibration left_stick;
+ Switch2_StickCalibration right_stick;
+ Uint8 left_trigger_zero;
+ Uint8 right_trigger_zero;
+
+ float gyro_bias_x;
+ float gyro_bias_y;
+ float gyro_bias_z;
+ float accel_bias_x;
+ float accel_bias_y;
+ float accel_bias_z;
+ bool sensors_enabled;
+ bool sensors_ready;
+ int sample_count;
+ Uint64 first_sensor_timestamp;
+ Uint64 sensor_ts_coeff;
+ float gyro_coeff;
+
+ bool player_lights;
+ int player_index;
+
+ bool vertical_mode;
+ Uint8 last_state[USB_PACKET_LENGTH];
+} SDL_DriverSwitch2_Context;
+
+static void ParseStickCalibration(Switch2_StickCalibration *stick_data, const Uint8 *data)
+{
+ stick_data->x.neutral = data[0];
+ stick_data->x.neutral |= (data[1] & 0x0F) << 8;
+
+ stick_data->y.neutral = data[1] >> 4;
+ stick_data->y.neutral |= data[2] << 4;
+
+ stick_data->x.max = data[3];
+ stick_data->x.max |= (data[4] & 0x0F) << 8;
+
+ stick_data->y.max = data[4] >> 4;
+ stick_data->y.max |= data[5] << 4;
+
+ stick_data->x.min = data[6];
+ stick_data->x.min |= (data[7] & 0x0F) << 8;
+
+ stick_data->y.min = data[7] >> 4;
+ stick_data->y.min |= data[8] << 4;
+}
+
+static int SendBulkData(SDL_DriverSwitch2_Context *ctx, const Uint8 *data, unsigned size)
+{
+ int transferred;
+ int res = ctx->libusb->bulk_transfer(ctx->device_handle,
+ ctx->out_endpoint,
+ (Uint8 *)data,
+ size,
+ &transferred,
+ 1000);
+ if (res < 0) {
+ return res;
+ }
+ return transferred;
+}
+
+static int RecvBulkData(SDL_DriverSwitch2_Context *ctx, Uint8 *data, unsigned size)
+{
+ int transferred;
+ int total_transferred = 0;
+ int res;
+
+ while (size > 0) {
+ unsigned current_read = size;
+ if (current_read > 64) {
+ current_read = 64;
+ }
+ res = ctx->libusb->bulk_transfer(ctx->device_handle,
+ ctx->in_endpoint,
+ data,
+ current_read,
+ &transferred,
+ 100);
+ if (res < 0) {
+ return res;
+ }
+ total_transferred += transferred;
+ size -= transferred;
+ data += current_read;
+ if ((unsigned) transferred < current_read) {
+ break;
+ }
+ }
+
+ return total_transferred;
+}
+
+static void MapJoystickAxis(Uint64 timestamp, SDL_Joystick *joystick, Uint8 axis, const Switch2_AxisCalibration *calib, float value, bool invert)
+{
+ Sint16 mapped_value;
+ if (calib && calib->neutral && calib->min && calib->max) {
+ value -= calib->neutral;
+ if (value < 0) {
+ value /= calib->min;
+ } else {
+ value /= calib->max;
+ }
+ mapped_value = (Sint16) SDL_clamp(value * SDL_MAX_SINT16, SDL_MIN_SINT16, SDL_MAX_SINT16);
+ } else {
+ mapped_value = (Sint16) HIDAPI_RemapVal(value, 0, 4096, SDL_MIN_SINT16, SDL_MAX_SINT16);
+ }
+ if (invert) {
+ mapped_value = ~mapped_value;
+ }
+ SDL_SendJoystickAxis(timestamp, joystick, axis, mapped_value);
+}
+
+static void MapTriggerAxis(Uint64 timestamp, SDL_Joystick *joystick, Uint8 axis, Uint8 max, float value)
+{
+ Sint16 mapped_value = (Sint16) HIDAPI_RemapVal(
+ SDL_clamp((value - max) / (232.f - max), 0, 1),
+ 0, 1,
+ SDL_MIN_SINT16, SDL_MAX_SINT16
+ );
+ SDL_SendJoystickAxis(timestamp, joystick, axis, mapped_value);
+}
+
+static bool UpdateSlotLED(SDL_DriverSwitch2_Context *ctx)
+{
+ Uint8 set_led_data[] = {
+ 0x09, 0x91, 0x00, 0x07, 0x00, 0x08, 0x00, 0x00,
+ 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00
+ };
+ Uint8 reply[8] = {0};
+ const Uint8 player_pattern[] = { 0x1, 0x3, 0x7, 0xf, 0x9, 0x5, 0xd, 0x6 };
+
+ if (ctx->player_lights && ctx->player_index >= 0) {
+ set_led_data[8] = player_pattern[ctx->player_index % 8];
+ }
+ int res = SendBulkData(ctx, set_led_data, sizeof(set_led_data));
+ if (res < 0) {
+ return SDL_SetError("Couldn't set LED data: %d\n", res);
+ }
+ return (RecvBulkData(ctx, reply, sizeof(reply)) > 0);
+}
+
+static int ReadFlashBlock(SDL_DriverSwitch2_Context *ctx, Uint32 address, Uint8 *out)
+{
+ Uint8 flash_read_command[] = {
+ 0x02, 0x91, 0x00, 0x01, 0x00, 0x08, 0x00, 0x00,
+ 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00
+ };
+ Uint8 buffer[0x50] = {0};
+ int res;
+
+ flash_read_command[12] = (Uint8)address;
+ flash_read_command[13] = (Uint8)(address >> 8);
+ flash_read_command[14] = (Uint8)(address >> 16);
+ flash_read_command[15] = (Uint8)(address >> 24);
+
+ res = SendBulkData(ctx, flash_read_command, sizeof(flash_read_command));
+ if (res < 0) {
+ return res;
+ }
+
+ res = RecvBulkData(ctx, buffer, sizeof(buffer));
+ if (res < 0) {
+ return res;
+ }
+
+ SDL_memcpy(out, &buffer[0x10], 0x40);
+ return 0;
+}
+
+static void SDLCALL SDL_PlayerLEDHintChanged(void *userdata, const char *name, const char *oldValue, const char *hint)
+{
+ SDL_DriverSwitch2_Context *ctx = (SDL_DriverSwitch2_Context *)userdata;
+ bool player_lights = SDL_GetStringBoolean(hint, true);
+
+ if (player_lights != ctx->player_lights) {
+ ctx->player_lights = player_lights;
+
+ UpdateSlotLED(ctx);
+ HIDAPI_UpdateDeviceProperties(ctx->device);
+ }
+}
+
+static void HIDAPI_DriverSwitch2_RegisterHints(SDL_HintCallback callback, void *userdata)
+{
+ SDL_AddHintCallback(SDL_HINT_JOYSTICK_HIDAPI_SWITCH2, callback, userdata);
+}
+
+static void HIDAPI_DriverSwitch2_UnregisterHints(SDL_HintCallback callback, void *userdata)
+{
+ SDL_RemoveHintCallback(SDL_HINT_JOYSTICK_HIDAPI_SWITCH2, callback, userdata);
+}
+
+static bool HIDAPI_DriverSwitch2_IsEnabled(void)
+{
+ return SDL_GetHintBoolean(SDL_HINT_JOYSTICK_HIDAPI_SWITCH2, SDL_GetHintBoolean(SDL_HINT_JOYSTICK_HIDAPI, SDL_HIDAPI_DEFAULT));
+}
+
+static bool HIDAPI_DriverSwitch2_IsSupportedDevice(SDL_HIDAPI_Device *device, const char *name, SDL_GamepadType type, Uint16 vendor_id, Uint16 product_id, Uint16 version, int interface_number, int interface_class, int interface_subclass, int interface_protocol)
+{
+ if (vendor_id == USB_VENDOR_NINTENDO) {
+ switch (product_id) {
+ case USB_PRODUCT_NINTENDO_SWITCH2_GAMECUBE_CONTROLLER:
+ case USB_PRODUCT_NINTENDO_SWITCH2_JOYCON_LEFT:
+ case USB_PRODUCT_NINTENDO_SWITCH2_JOYCON_RIGHT:
+ case USB_PRODUCT_NINTENDO_SWITCH2_PRO:
+ return true;
+ }
+ }
+
+ return false;
+}
+
+static bool HIDAPI_DriverSwitch2_InitBluetooth(SDL_HIDAPI_Device *device)
+{
+ // FIXME: Need to add Bluetooth support
+ return SDL_SetError("Nintendo Switch2 controllers not supported over Bluetooth");
+}
+
+static bool FindBulkEndpoints(SDL_LibUSBContext *libusb, libusb_device_handle *handle, Uint8 *bInterfaceNumber, Uint8 *out_endpoint, Uint8 *in_endpoint)
+{
+ struct libusb_config_descriptor *config;
+ int found = 0;
+
+ if (libusb->get_config_descriptor(libusb->get_device(handle), 0, &config) != 0) {
+ return false;
+ }
+
+ for (int i = 0; i < config->bNumInterfaces; i++) {
+ const struct libusb_interface *iface = &config->interface[i];
+ for (int j = 0; j < iface->num_altsetting; j++) {
+ const struct libusb_interface_descriptor *altsetting = &iface->altsetting[j];
+ if (altsetting->bInterfaceNumber == 1) {
+ for (int k = 0; k < altsetting->bNumEndpoints; k++) {
+ const struct libusb_endpoint_descriptor *ep = &altsetting->endpoint[k];
+ if ((ep->bmAttributes & LIBUSB_TRANSFER_TYPE_MASK) == LIBUSB_TRANSFER_TYPE_BULK) {
+ *bInterfaceNumber = altsetting->bInterfaceNumber;
+ if ((ep->bEndpointAddress & LIBUSB_ENDPOINT_DIR_MASK) == LIBUSB_ENDPOINT_OUT) {
+ *out_endpoint = ep->bEndpointAddress;
+ found |= 1;
+ }
+ if ((ep->bEndpointAddress & LIBUSB_ENDPOINT_DIR_MASK) == LIBUSB_ENDPOINT_IN) {
+ *in_endpoint = ep->bEndpointAddress;
+ found |= 2;
+ }
+ if (found == 3) {
+ libusb->free_config_descriptor(config);
+ return true;
+ }
+ }
+ }
+ }
+ }
+ }
+ libusb->free_config_descriptor(config);
+ return false;
+}
+
+static bool HIDAPI_DriverSwitch2_InitUSB(SDL_HIDAPI_Device *device)
+{
+ SDL_DriverSwitch2_Context *ctx = (SDL_DriverSwitch2_Context *)device->context;
+
+ if (!SDL_InitLibUSB(&ctx->libusb)) {
+ return false;
+ }
+
+ ctx->device_handle = (libusb_device_handle *)SDL_GetPointerProperty(SDL_hid_get_properties(device->dev), SDL_PROP_HIDAPI_LIBUSB_DEVICE_HANDLE_POINTER, NULL);
+ if (!ctx->device_handle) {
+ return SDL_SetError("Couldn't get libusb device handle");
+ }
+
+ if (!FindBulkEndpoints(ctx->libusb, ctx->device_handle, &ctx->interface_number, &ctx->out_endpoint, &ctx->in_endpoint)) {
+ return SDL_SetError("Couldn't find bulk endpoints");
+ }
+
+ ctx->libusb->set_auto_detach_kernel_driver(ctx->device_handle, true);
+ int res = ctx->libusb->claim_interface(ctx->device_handle, ctx->interface_number);
+ if (res < 0) {
+ return SDL_SetError("Couldn't claim interface %d: %d\n", ctx->interface_number, res);
+ }
+ ctx->interface_claimed = true;
+
+ const Uint8 *init_sequence[] = {
+ (Uint8[]) { // Unknown purpose
+ 0x7, 0x91, 0x0, 0x1, 0x0, 0x0, 0x0, 0x0,
+ },
+ (Uint8[]) { // Set feature output bit mask
+ 0x0c, 0x91, 0x00, 0x02, 0x00, 0x04, 0x00, 0x00, 0x27, 0x00, 0x00, 0x00
+ },
+ (Uint8[]) { // Unknown purpose
+ 0x11, 0x91, 0x0, 0x1, 0x0, 0x0, 0x0, 0x0,
+ },
+ (Uint8[]) { // Set rumble data?
+ 0x0a, 0x91, 0x00, 0x08, 0x00, 0x14, 0x00, 0x00,
+ 0x01, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff,
+ 0xff, 0x35, 0x00, 0x46, 0x00, 0x00, 0x00, 0x00,
+ 0x00, 0x00, 0x00, 0x00
+ },
+ (Uint8[]) { // Enable feature output bits
+ 0x0c, 0x91, 0x00, 0x04, 0x00, 0x04, 0x00, 0x00, 0x27, 0x00, 0x00, 0x00
+ },
+ (Uint8[]) { // Unknown purpose
+ 0x01, 0x91, 0x0, 0xc, 0x0, 0x0, 0x0, 0x0,
+ },
+ (Uint8[]) { // Enable rumble
+ 0x01, 0x91, 0x0, 0x1, 0x0, 0x0, 0x0, 0x0,
+ },
+ (Uint8[]) { // Enable grip buttons on charging grip
+ 0x8, 0x91, 0x0, 0x2, 0x0, 0x4, 0x0, 0x0, 0x01, 0x0, 0x0, 0x0,
+ },
+ (Uint8[]) { // Set report format
+ 0x03, 0x91, 0x00, 0x0a, 0x00, 0x04, 0x00, 0x00,
+ 0x05, 0x00, 0x00, 0x00
+ },
+ (Uint8[]) { // Start output
+ 0x03, 0x91, 0x00, 0x0d, 0x00, 0x08, 0x00, 0x00,
+ 0x01, 0x00, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff,
+ },
+ NULL, // Sentinel
+ };
+
+ unsigned char calibration_data[0x40] = {0};
+
+ res = ReadFlashBlock(ctx, 0x13000, calibration_data);
+ if (res < 0) {
+ SDL_LogWarn(SDL_LOG_CATEGORY_INPUT, "Couldn't read serial number: %d", res);
+ } else {
+ char serial[0x11] = {0};
+ SDL_strlcpy(serial, (char*)&calibration_data[2], sizeof(serial));
+ HIDAPI_SetDeviceSerial(device, serial);
+ }
+
+ res = ReadFlashBlock(ctx, 0x13040, calibration_data);
+ if (res < 0) {
+ SDL_LogWarn(SDL_LOG_CATEGORY_INPUT, "Couldn't read factory calibration data: %d", res);
+ } else {
+ ctx->gyro_bias_x = *(float*)&calibration_data[4];
+ ctx->gyro_bias_y = *(float*)&calibration_data[8];
+ ctx->gyro_bias_z = *(float*)&calibration_data[12];
+ }
+
+ res = ReadFlashBlock(ctx, 0x13080, calibration_data);
+ if (res < 0) {
+ SDL_LogWarn(SDL_LOG_CATEGORY_INPUT, "Couldn't read factory calibration data: %d", res);
+ } else {
+ ParseStickCalibration(&ctx->left_stick, &calibration_data[0x28]);
+ }
+
+ res = ReadFlashBlock(ctx, 0x130C0, calibration_data);
+ if (res < 0) {
+ SDL_LogWarn(SDL_LOG_CATEGORY_INPUT, "Couldn't read factory calibration data: %d", res);
+ } else {
+ ParseStickCalibration(&ctx->right_stick, &calibration_data[0x28]);
+ }
+
+ res = ReadFlashBlock(ctx, 0x13100, calibration_data);
+ if (res < 0) {
+ SDL_LogWarn(SDL_LOG_CATEGORY_INPUT, "Couldn't read factory calibration data: %d", res);
+ } else {
+ ctx->accel_bias_x = *(float*)&calibration_data[12];
+ ctx->accel_bias_y = *(float*)&calibration_data[16];
+ ctx->accel_bias_z = *(float*)&calibration_data[20];
+ }
+
+ if (device->product_id == USB_PRODUCT_NINTENDO_SWITCH2_GAMECUBE_CONTROLLER) {
+ res = ReadFlashBlock(ctx, 0x13140, calibration_data);
+ if (res < 0) {
+ SDL_LogWarn(SDL_LOG_CATEGORY_INPUT, "Couldn't read factory calibration data: %d", res);
+ } else {
+ ctx->left_trigger_zero = calibration_data[0];
+ ctx->right_trigger_zero = calibration_data[1];
+ }
+ }
+
+ res = ReadFlashBlock(ctx, 0x1FC040, calibration_data);
+ if (res < 0) {
+ SDL_LogWarn(SDL_LOG_CATEGORY_INPUT, "Couldn't read user calibration data: %d", res);
+ } else if (calibration_data[0] == 0xb2 && calibration_data[1] == 0xa1) {
+ ParseStickCalibration(&ctx->left_stick, &calibration_data[2]);
+ }
+
+ res = ReadFlashBlock(ctx, 0x1FC080, calibration_data);
+ if (res < 0) {
+ SDL_LogWarn(SDL_LOG_CATEGORY_INPUT, "Couldn't read user calibration data: %d", res);
+ } else if (calibration_data[0] == 0xb2 && calibration_data[1] == 0xa1) {
+ ParseStickCalibration(&ctx->right_stick, &calibration_data[2]);
+ }
+
+ for (int i = 0; init_sequence[i]; i++) {
+ res = SendBulkData(ctx, init_sequence[i], init_sequence[i][5] + 8);
+ if (res < 0) {
+ return SDL_SetError("Couldn't send initialization data: %d\n", res);
+ }
+ RecvBulkData(ctx, calibration_data, 0x40);
+ }
+
+ return true;
+}
+
+static bool HIDAPI_DriverSwitch2_InitDevice(SDL_HIDAPI_Device *device)
+{
+ SDL_DriverSwitch2_Context *ctx;
+
+ ctx = (SDL_DriverSwitch2_Context *)SDL_calloc(1, sizeof(*ctx));
+ if (!ctx) {
+ return false;
+ }
+ ctx->device = device;
+ device->context = ctx;
+
+ if (device->is_bluetooth) {
+ if (!HIDAPI_DriverSwitch2_InitBluetooth(device)) {
+ return false;
+ }
+ } else {
+ if (!HIDAPI_DriverSwitch2_InitUSB(device)) {
+ return false;
+ }
+ }
+
+ ctx->sensor_ts_coeff = 10000;
+ ctx->gyro_coeff = 34.8f;
+
+ // Sometimes the device handle isn't available during enumeration so we don't get the device name, so set it explicitly
+ switch (device->product_id) {
+ case USB_PRODUCT_NINTENDO_SWITCH2_GAMECUBE_CONTROLLER:
+ HIDAPI_SetDeviceName(device, "Nintendo GameCube Controller");
+ break;
+ case USB_PRODUCT_NINTENDO_SWITCH2_PRO:
+ HIDAPI_SetDeviceName(device, "Nintendo Switch Pro Controller");
+ break;
+ default:
+ break;
+ }
+ return HIDAPI_JoystickConnected(device, NULL);
+}
+
+static int HIDAPI_DriverSwitch2_GetDevicePlayerIndex(SDL_HIDAPI_Device *device, SDL_JoystickID instance_id)
+{
+ return -1;
+}
+
+static void HIDAPI_DriverSwitch2_SetDevicePlayerIndex(SDL_HIDAPI_Device *device, SDL_JoystickID instance_id, int player_index)
+{
+ SDL_DriverSwitch2_Context *ctx = (SDL_DriverSwitch2_Context *)device->context;
+
+ if (!ctx->joystick) {
+ return;
+ }
+
+ ctx->player_index = player_index;
+
+ UpdateSlotLED(ctx);
+}
+
+static bool HIDAPI_DriverSwitch2_OpenJoystick(SDL_HIDAPI_Device *device, SDL_Joystick *joystick)
+{
+ SDL_DriverSwitch2_Context *ctx = (SDL_DriverSwitch2_Context *)device->context;
+
+ ctx->joystick = joystick;
+
+ // Initialize player index (needed for setting LEDs)
+ ctx->player_index = SDL_GetJoystickPlayerIndex(joystick);
+ ctx->player_lights = SDL_GetHintBoolean(SDL_HINT_JOYSTICK_HIDAPI_SWITCH_PLAYER_LED, true);
+ UpdateSlotLED(ctx);
+
+ SDL_AddHintCallback(SDL_HINT_JOYSTICK_HIDAPI_SWITCH_PLAYER_LED,
+ SDL_PlayerLEDHintChanged, ctx);
+
+ // Initialize the joystick capabilities
+ if (!ctx->device->parent) {
+ SDL_PrivateJoystickAddSensor(joystick, SDL_SENSOR_GYRO, 250.0f);
+ SDL_PrivateJoystickAddSensor(joystick, SDL_SENSOR_ACCEL, 250.0f);
+ }
+ switch (device->product_id) {
+ case USB_PRODUCT_NINTENDO_SWITCH2_GAMECUBE_CONTROLLER:
+ joystick->nbuttons = SDL_GAMEPAD_NUM_SWITCH2_GAMECUBE_BUTTONS;
+ break;
+ case USB_PRODUCT_NINTENDO_SWITCH2_JOYCON_LEFT:
+ if (ctx->device->parent) {
+ SDL_PrivateJoystickAddSensor(joystick, SDL_SENSOR_GYRO_L, 250.0f);
+ SDL_PrivateJoystickAddSensor(joystick, SDL_SENSOR_ACCEL_L, 250.0f);
+ }
+ joystick->nbuttons = SDL_GAMEPAD_NUM_SWITCH2_JOYCON_BUTTONS;
+ break;
+ case USB_PRODUCT_NINTENDO_SWITCH2_JOYCON_RIGHT:
+ if (ctx->device->parent) {
+ SDL_PrivateJoystickAddSensor(joystick, SDL_SENSOR_GYRO, 250.0f);
+ SDL_PrivateJoystickAddSensor(joystick, SDL_SENSOR_ACCEL, 250.0f);
+ SDL_PrivateJoystickAddSensor(joystick, SDL_SENSOR_GYRO_R, 250.0f);
+ SDL_PrivateJoystickAddSensor(joystick, SDL_SENSOR_ACCEL_R, 250.0f);
+ }
+ joystick->nbuttons = SDL_GAMEPAD_NUM_SWITCH2_JOYCON_BUTTONS;
+ break;
+ case USB_PRODUCT_NINTENDO_SWITCH2_PRO:
+ joystick->nbuttons = SDL_GAMEPAD_NUM_SWITCH2_PRO_BUTTONS;
+ break;
+ default:
+ // FIXME: How many buttons does this have?
+ break;
+ }
+ joystick->naxes = SDL_GAMEPAD_AXIS_COUNT;
+ joystick->nhats = 1;
+
+ ctx->rumble_hi_freq = 0x187;
+ ctx->rumble_lo_freq = 0x112;
+
+ // Set up for vertical mode
+ ctx->vertical_mode = SDL_GetHintBoolean(SDL_HINT_JOYSTICK_HIDAPI_VERTICAL_JOY_CONS, false);
+
+ return true;
+}
+
+static bool HIDAPI_DriverSwitch2_RumbleJoystick(SDL_HIDAPI_Device *device, SDL_Joystick *joystick, Uint16 low_frequency_rumble, Uint16 high_frequency_rumble)
+{
+ SDL_DriverSwitch2_Context *ctx = (SDL_DriverSwitch2_Context *)device->context;
+
+ if (low_frequency_rumble != ctx->rumble_lo_amp || high_frequency_rumble != ctx->rumble_hi_amp) {
+ ctx->rumble_lo_amp = low_frequency_rumble;
+ ctx->rumble_hi_amp = high_frequency_rumble;
+ ctx->rumble_updated = true;
+ }
+
+ return true;
+}
+
+static bool HIDAPI_DriverSwitch2_RumbleJoystickTriggers(SDL_HIDAPI_Device *device, SDL_Joystick *joystick, Uint16 left_rumble, Uint16 right_rumble)
+{
+ return SDL_Unsupported();
+}
+
+static Uint32 HIDAPI_DriverSwitch2_GetJoystickCapabilities(SDL_HIDAPI_Device *device, SDL_Joystick *joystick)
+{
+ SDL_DriverSwitch2_Context *ctx = (SDL_DriverSwitch2_Context *)device->context;
+ Uint32 result = SDL_JOYSTICK_CAP_RUMBLE;
+
+ if (ctx->player_lights) {
+ result |= SDL_JOYSTICK_CAP_PLAYER_LED;
+ }
+ return result;
+}
+
+static bool HIDAPI_DriverSwitch2_SetJoystickLED(SDL_HIDAPI_Device *device, SDL_Joystick *joystick, Uint8 red, Uint8 green, Uint8 blue)
+{
+ return SDL_Unsupported();
+}
+
+static bool HIDAPI_DriverSwitch2_SendJoystickEffect(SDL_HIDAPI_Device *device, SDL_Joystick *joystick, const void *data, int size)
+{
+ return SDL_Unsupported();
+}
+
+static bool HIDAPI_DriverSwitch2_SetJoystickSensorsEnabled(SDL_HIDAPI_Device *device, SDL_Joystick *joystick, bool enabled)
+{
+ SDL_DriverSwitch2_Context *ctx = (SDL_DriverSwitch2_Context *)device->context;
+ if (ctx->sensors_ready) {
+ Uint8 data[] = {
+ 0x0c, 0x91, 0x00, 0x04, 0x00, 0x04, 0x00, 0x00, 0x23, 0x00, 0x00, 0x00
+ };
+ unsigned char reply[12] = {0};
+
+ if (enabled) {
+ data[8] |= 4;
+ }
+ int res = SendBulkData(ctx, data, sizeof(data));
+ if (res < 0) {
+ return SDL_SetError("Couldn't set sensors enabled: %d\n", res);
+ }
+ RecvBulkData(ctx, reply, sizeof(reply));
+ }
+ ctx->sensors_enabled = true;
+ return true;
+}
+
+static void HandleGameCubeState(Uint64 timestamp, SDL_Joystick *joystick, SDL_DriverSwitch2_Context *ctx, Uint8 *data, int size)
+{
+
+ if (data[5] != ctx->last_state[5]) {
+ SDL_SendJoystickButton(timestamp, joystick, SDL_GAMEPAD_BUTTON_WEST, ((data[5] & 0x01) != 0));
+ SDL_SendJoystickButton(timestamp, joystick, SDL_GAMEPAD_BUTTON_NORTH, ((data[5] & 0x02) != 0));
+ SDL_SendJoystickButton(timestamp, joystick, SDL_GAMEPAD_BUTTON_SOUTH, ((data[5] & 0x04) != 0));
+ SDL_SendJoystickButton(timestamp, joystick, SDL_GAMEPAD_BUTTON_EAST, ((data[5] & 0x08) != 0));
+ SDL_SendJoystickButton(timestamp, joystick, SDL_GAMEPAD_BUTTON_SWITCH2_GAMECUBE_RIGHT_TRIGGER, ((data[5] & 0x40) != 0));
+ SDL_SendJoystickButton(timestamp, joystick, SDL_GAMEPAD_BUTTON_SWITCH2_GAMECUBE_RIGHT_SHOULDER, ((data[5] & 0x80) != 0));
+ }
+
+ if (data[6] != ctx->last_state[6]) {
+ SDL_SendJoystickButton(timestamp, joystick, SDL_GAMEPAD_BUTTON_SWITCH2_GAMECUBE_START, ((data[6] & 0x02) != 0));
+ SDL_SendJoystickButton(timestamp, joystick, SDL_GAMEPAD_BUTTON_SWITCH2_GAMECUBE_GUIDE, ((data[6] & 0x10) != 0));
+ SDL_SendJoystickButton(timestamp, joystick, SDL_GAMEPAD_BUTTON_SWITCH2_GAMECUBE_SHARE, ((data[6] & 0x20) != 0));
+ SDL_SendJoystickButton(timestamp, joystick, SDL_GAMEPAD_BUTTON_SWITCH2_GAMECUBE_C, ((data[6] & 0x40) != 0));
+ }
+
+ if (data[7] != ctx->last_state[7]) {
+ Uint8 hat = 0;
+
+ if (data[7] & 0x01) {
+ hat |= SDL_HAT_DOWN;
+ }
+ if (data[7] & 0x02) {
+ hat |= SDL_HAT_UP;
+ }
+ if (data[7] & 0x04) {
+ hat |= SDL_HAT_RIGHT;
+ }
+ if (data[7] & 0x08) {
+ hat |= SDL_HAT_LEFT;
+ }
+ SDL_SendJoystickHat(timestamp, joystick, 0, hat);
+
+ SDL_SendJoystickButton(timestamp, joystick, SDL_GAMEPAD_BUTTON_SWITCH2_GAMECUBE_LEFT_TRIGGER, ((data[7] & 0x40) != 0));
+ SDL_SendJoystickButton(timestamp, joystick, SDL_GAMEPAD_BUTTON_SWITCH2_GAMECUBE_LEFT_SHOULDER, ((data[7] & 0x80) != 0));
+ }
+
+ MapTriggerAxis(
+ timestamp,
+ joystick,
+ SDL_GAMEPAD_AXIS_LEFT_TRIGGER,
+ ctx->left_trigger_zero,
+ data[61]
+ );
+ MapTriggerAxis(
+ timestamp,
+ joystick,
+ SDL_GAMEPAD_AXIS_RIGHT_TRIGGER,
+ ctx->right_trigger_zero,
+ data[62]
+ );
+
+ MapJoystickAxis(
+ timestamp,
+ joystick,
+ SDL_GAMEPAD_AXIS_LEFTX,
+ &ctx->left_stick.x,
+ (float) (data[11] | ((data[12] & 0x0F) << 8)),
+ false
+ );
+ MapJoystickAxis(
+ timestamp,
+ joystick,
+ SDL_GAMEPAD_AXIS_LEFTY,
+ &ctx->left_stick.y,
+ (float) ((data[12] >> 4) | (data[13] << 4)),
+ true
+ );
+ MapJoystickAxis(
+ timestamp,
+ joystick,
+ SDL_GAMEPAD_AXIS_RIGHTX,
+ &ctx->right_stick.x,
+ (float) (data[14] | ((data[15] & 0x0F) << 8)),
+ false
+ );
+ MapJoystickAxis(
+ timestamp,
+ joystick,
+ SDL_GAMEPAD_AXIS_RIGHTY,
+ &ctx->right_stick.y,
+ (float)((data[15] >> 4) | (data[16] << 4)),
+ true
+ );
+}
+
+static void HandleCombinedControllerStateL(Uint64 timestamp, SDL_Joystick *joystick, SDL_DriverSwitch2_Context *ctx, Uint8 *data, int size)
+{
+ if (data[6] != ctx->last_state[6]) {
+ SDL_SendJoystickButton(timestamp, joystick, SDL_GAMEPAD_BUTTON_BACK, ((data[6] & 0x01) != 0));
+ SDL_SendJoystickButton(timestamp, joystick, SDL_GAMEPAD_BUTTON_LEFT_STICK, ((data[6] & 0x08) != 0));
+ SDL_SendJoystickButton(timestamp, joystick, SDL_GAMEPAD_BUTTON_SWITCH2_JOYCON_SHARE, ((data[6] & 0x20) != 0));
+ }
+
+ if (data[7] != ctx->last_state[7]) {
+ Uint8 hat = 0;
+
+ if (data[7] & 0x01) {
+ hat |= SDL_HAT_DOWN;
+ }
+ if (data[7] & 0x02) {
+ hat |= SDL_HAT_UP;
+ }
+ if (data[7] & 0x04) {
+ hat |= SDL_HAT_RIGHT;
+ }
+ if (data[7] & 0x08) {
+ hat |= SDL_HAT_LEFT;
+ }
+ SDL_SendJoystickHat(timestamp, joystick, 0, hat);
+
+ SDL_SendJoystickButton(timestamp, joystick, SDL_GAMEPAD_BUTTON_LEFT_SHOULDER, ((data[7] & 0x40) != 0));
+ }
+
+ if (data[8] != ctx->last_state[8]) {
+ SDL_SendJoystickButton(timestamp, joystick, SDL_GAMEPAD_BUTTON_SWITCH2_JOYCON_LEFT_PADDLE1, ((data[8] & 0x02) != 0));
+ }
+
+ Sint16 axis = (data[7] & 0x80) ? 32767 : -32768;
+ SDL_SendJoystickAxis(timestamp, joystick, SDL_GAMEPAD_AXIS_LEFT_TRIGGER, axis);
+
+ MapJoystickAxis(
+ timestamp,
+ joystick,
+ SDL_GAMEPAD_AXIS_LEFTX,
+ &ctx->left_stick.x,
+ (float) (data[11] | ((data[12] & 0x0F) << 8)),
+ false
+ );
+ MapJoystickAxis(
+ timestamp,
+ joystick,
+ SDL_GAMEPAD_AXIS_LEFTY,
+ &ctx->left_stick.y,
+ (float) ((data[12] >> 4) | (data[13] << 4)),
+ true
+ );
+}
+
+static void HandleMiniControllerStateL(Uint64 timestamp, SDL_Joystick *joystick, SDL_DriverSwitch2_Context *ctx, Uint8 *data, int size)
+{
+ if (data[6] != ctx->last_state[6]) {
+ SDL_SendJoystickButton(timestamp, joystick, SDL_GAMEPAD_BUTTON_START, ((data[6] & 0x01) != 0));
+ SDL_SendJoystickButton(timestamp, joystick, SDL_GAMEPAD_BUTTON_LEFT_STICK, ((data[6] & 0x08) != 0));
+ SDL_SendJoystickButton(timestamp, joystick, SDL_GAMEPAD_BUTTON_GUIDE, ((data[6] & 0x20) != 0));
+ SDL_SendJoystickButton(timestamp, joystick, SDL_GAMEPAD_BUTTON_SWITCH2_JOYCON_SHARE, ((data[6] & 0x10) != 0));
+ }
+
+ if (data[7] != ctx->last_state[7]) {
+ SDL_SendJoystickButton(timestamp, joystick, SDL_GAMEPAD_BUTTON_WEST, ((data[7] & 0x01) != 0));
+ SDL_SendJoystickButton(timestamp, joystick, SDL_GAMEPAD_BUTTON_NORTH, ((data[7] & 0x02) != 0));
+ SDL_SendJoystickButton(timestamp, joystick, SDL_GAMEPAD_BUTTON_SOUTH, ((data[7] & 0x04) != 0));
+ SDL_SendJoystickButton(timestamp, joystick, SDL_GAMEPAD_BUTTON_EAST, ((data[7] & 0x08) != 0));
+ SDL_SendJoystickButton(timestamp, joystick, SDL_GAMEPAD_BUTTON_RIGHT_SHOULDER, ((data[7] & 0x10) != 0));
+ SDL_SendJoystickButton(timestamp, joystick, SDL_GAMEPAD_BUTTON_LEFT_SHOULDER, ((data[7] & 0x20) != 0));
+ SDL_SendJoystickButton(timestamp, joystick, SDL_GAMEPAD_BUTTON_SWITCH2_JOYCON_LEFT_PADDLE1, ((data[7] & 0x40) != 0));
+ SDL_SendJoystickButton(timestamp, joystick, SDL_GAMEPAD_BUTTON_SWITCH2_JOYCON_LEFT_PADDLE2, ((data[7] & 0x80) != 0));
+ }
+
+ MapJoystickAxis(
+ timestamp,
+ joystick,
+ SDL_GAMEPAD_AXIS_LEFTX,
+ &ctx->left_stick.y,
+ (float) ((data[12] >> 4) | (data[13] << 4)),
+ true
+ );
+ MapJoystickAxis(
+ timestamp,
+ joystick,
+ SDL_GAMEPAD_AXIS_LEFTY,
+ &ctx->left_stick.x,
+ (float) (data[11] | ((data[12] & 0x0F) << 8)),
+ true
+ );
+}
+
+static void HandleCombinedControllerStateR(Uint64 timestamp, SDL_Joystick *joystick, SDL_DriverSwitch2_Context *ctx, Uint8 *data, int size)
+{
+ if (data[5] != ctx->last_state[5]) {
+ SDL_SendJoystickButton(timestamp, joystick, SDL_GAMEPAD_BUTTON_WEST, ((data[5] & 0x01) != 0));
+ SDL_SendJoystickButton(timestamp, joystick, SDL_GAMEPAD_BUTTON_NORTH, ((data[5] & 0x02) != 0));
+ SDL_SendJoystickButton(timestamp, joystick, SDL_GAMEPAD_BUTTON_SOUTH, ((data[5] & 0x04) != 0));
+ SDL_SendJoystickButton(timestamp, joystick, SDL_GAMEPAD_BUTTON_EAST, ((data[5] & 0x08) != 0));
+ SDL_SendJoystickButton(timestamp, joystick, SDL_GAMEPAD_BUTTON_RIGHT_SHOULDER, ((data[5] & 0x40) != 0));
+ }
+
+ if (data[6] != ctx->last_state[6]) {
+ SDL_SendJoystickButton(timestamp, joystick, SDL_GAMEPAD_BUTTON_START, ((data[6] & 0x02) != 0));
+ SDL_SendJoystickButton(timestamp, joystick, SDL_GAMEPAD_BUTTON_RIGHT_STICK, ((data[6] & 0x04) != 0));
+ SDL_SendJoystickButton(timestamp, joystick, SDL_GAMEPAD_BUTTON_GUIDE, ((data[6] & 0x10) != 0));
+ SDL_SendJoystickButton(timestamp, joystick, SDL_GAMEPAD_BUTTON_SWITCH2_JOYCON_C, ((data[6] & 0x40) != 0));
+ }
+
+ if (data[8] != ctx->last_state[8]) {
+ SDL_SendJoystickButton(timestamp, joystick, SDL_GAMEPAD_BUTTON_SWITCH2_JOYCON_RIGHT_PADDLE1, ((data[8] & 0x01) != 0));
+ }
+
+ Sint16 axis = (data[5] & 0x80) ? 32767 : -32768;
+ SDL_SendJoystickAxis(timestamp, joystick, SDL_GAMEPAD_AXIS_RIGHT_TRIGGER, axis);
+
+ MapJoystickAxis(
+ timestamp,
+ joystick,
+ SDL_GAMEPAD_AXIS_RIGHTX,
+ &ctx->left_stick.x,
+ (float) (data[14] | ((data[15] & 0x0F) << 8)),
+ false
+ );
+ MapJoystickAxis(
+ timestamp,
+ joystick,
+ SDL_GAMEPAD_AXIS_RIGHTY,
+ &ctx->left_stick.y,
+ (float)((data[15] >> 4) | (data[16] << 4)),
+ true
+ );
+}
+
+static void HandleMiniControllerStateR(Uint64 timestamp, SDL_Joystick *joystick, SDL_DriverSwitch2_Context *ctx, Uint8 *data, int size)
+{
+ if (data[5] != ctx->last_state[5]) {
+ SDL_SendJoystickButton(timestamp, joystick, SDL_GAMEPAD_BUTTON_WEST, ((data[5] & 0x01) != 0));
+ SDL_SendJoystickButton(timestamp, joystick, SDL_GAMEPAD_BUTTON_NORTH, ((data[5] & 0x02) != 0));
+ SDL_SendJoystickButton(timestamp, joystick, SDL_GAMEPAD_BUTTON_SOUTH, ((data[5] & 0x04) != 0));
+ SDL_SendJoystickButton(timestamp, joystick, SDL_GAMEPAD_BUTTON_EAST, ((data[5] & 0x08) != 0));
+ SDL_SendJoystickButton(timestamp, joystick, SDL_GAMEPAD_BUTTON_RIGHT_SHOULDER, ((data[5] & 0x10) != 0));
+ SDL_SendJoystickButton(timestamp, joystick, SDL_GAMEPAD_BUTTON_LEFT_SHOULDER, ((data[5] & 0x20) != 0));
+ SDL_SendJoystickButton(timestamp, joystick, SDL_GAMEPAD_BUTTON_SWITCH2_JOYCON_RIGHT_PADDLE1, ((data[5] & 0x40) != 0));
+ SDL_SendJoystickButton(timestamp, joystick, SDL_GAMEPAD_BUTTON_SWITCH2_JOYCON_RIGHT_PADDLE2, ((data[5] & 0x80) != 0));
+ }
+
+ if (data[6] != ctx->last_state[6]) {
+ SDL_SendJoystickButton(timestamp, joystick, SDL_GAMEPAD_BUTTON_START, ((data[6] & 0x02) != 0));
+ SDL_SendJoystickButton(timestamp, joystick, SDL_GAMEPAD_BUTTON_LEFT_STICK, ((data[6] & 0x04) != 0));
+ SDL_SendJoystickButton(timestamp, joystick, SDL_GAMEPAD_BUTTON_GUIDE, ((data[6] & 0x10) != 0));
+ SDL_SendJoystickButton(timestamp, joystick, SDL_GAMEPAD_BUTTON_SWITCH2_JOYCON_C, ((data[6] & 0x40) != 0));
+ }
+
+ MapJoystickAxis(
+ timestamp,
+ joystick,
+ SDL_GAMEPAD_AXIS_LEFTX,
+ &ctx->left_stick.y,
+ (float)((data[15] >> 4) | (data[16] << 4)),
+ false
+ );
+ MapJoystickAxis(
+ timestamp,
+ joystick,
+ SDL_GAMEPAD_AXIS_LEFTY,
+ &ctx->left_stick.x,
+ (float) (data[14] | ((data[15] & 0x0F) << 8)),
+ false
+ );
+}
+
+static void HandleSwitchProState(Uint64 timestamp, SDL_Joystick *joystick, SDL_DriverSwitch2_Context *ctx, Uint8 *data, int size)
+{
+ Sint16 axis;
+
+ if (data[5] != ctx->last_state[5]) {
+ SDL_SendJoystickButton(timestamp, joystick, SDL_GAMEPAD_BUTTON_WEST, ((data[5] & 0x01) != 0));
+ SDL_SendJoystickButton(timestamp, joystick, SDL_GAMEPAD_BUTTON_NORTH, ((data[5] & 0x02) != 0));
+ SDL_SendJoystickButton(timestamp, joystick, SDL_GAMEPAD_BUTTON_SOUTH, ((data[5] & 0x04) != 0));
+ SDL_SendJoystickButton(timestamp, joystick, SDL_GAMEPAD_BUTTON_EAST, ((data[5] & 0x08) != 0));
+ SDL_SendJoystickButton(timestamp, joystick, SDL_GAMEPAD_BUTTON_RIGHT_SHOULDER, ((data[5] & 0x40) != 0));
+ }
+
+ if (data[6] != ctx->last_state[6]) {
+ SDL_SendJoystickButton(timestamp, joystick, SDL_GAMEPAD_BUTTON_BACK, ((data[6] & 0x01) != 0));
+ SDL_SendJoystickButton(timestamp, joystick, SDL_GAMEPAD_BUTTON_START, ((data[6] & 0x02) != 0));
+ SDL_SendJoystickButton(timestamp, joystick, SDL_GAMEPAD_BUTTON_RIGHT_STICK, ((data[6] & 0x04) != 0));
+ SDL_SendJoystickButton(timestamp, joystick, SDL_GAMEPAD_BUTTON_LEFT_STICK, ((data[6] & 0x08) != 0));
+ SDL_SendJoystickButton(timestamp, joystick, SDL_GAMEPAD_BUTTON_GUIDE, ((data[6] & 0x10) != 0));
+ SDL_SendJoystickButton(timestamp, joystick, SDL_GAMEPAD_BUTTON_SWITCH2_PRO_SHARE, ((data[6] & 0x20) != 0));
+ SDL_SendJoystickButton(timestamp, joystick, SDL_GAMEPAD_BUTTON_SWITCH2_PRO_C, ((data[6] & 0x40) != 0));
+ }
+
+ if (data[7] != ctx->last_state[7]) {
+ Uint8 hat = 0;
+
+ if (data[7] & 0x01) {
+ hat |= SDL_HAT_DOWN;
+ }
+ if (data[7] & 0x02) {
+ hat |= SDL_HAT_UP;
+ }
+ if (data[7] & 0x04) {
+ hat |= SDL_HAT_RIGHT;
+ }
+ if (data[7] & 0x08) {
+ hat |= SDL_HAT_LEFT;
+ }
+ SDL_SendJoystickHat(timestamp, joystick, 0, hat);
+
+ SDL_SendJoystickButton(timestamp, joystick, SDL_GAMEPAD_BUTTON_LEFT_SHOULDER, ((data[7] & 0x40) != 0));
+ }
+
+ if (data[8] != ctx->last_state[8]) {
+ SDL_SendJoystickButton(timestamp, joystick, SDL_GAMEPAD_BUTTON_SWITCH2_PRO_RIGHT_PADDLE, ((data[8] & 0x01) != 0));
+ SDL_SendJoystickButton(timestamp, joystick, SDL_GAMEPAD_BUTTON_SWITCH2_PRO_LEFT_PADDLE, ((data[8] & 0x02) != 0));
+ }
+
+ axis = (data[5] & 0x80) ? 32767 : -32768;
+ SDL_SendJoystickAxis(timestamp, joystick, SDL_GAMEPAD_AXIS_RIGHT_TRIGGER, axis);
+
+ axis = (data[7] & 0x80) ? 32767 : -32768;
+ SDL_SendJoystickAxis(timestamp, joystick, SDL_GAMEPAD_AXIS_LEFT_TRIGGER, axis);
+
+ MapJoystickAxis(
+ timestamp,
+ joystick,
+ SDL_GAMEPAD_AXIS_LEFTX,
+ &ctx->left_stick.x,
+ (float) (data[11] | ((data[12] & 0x0F) << 8)),
+ false
+ );
+ MapJoystickAxis(
+ timestamp,
+ joystick,
+ SDL_GAMEPAD_AXIS_LEFTY,
+ &ctx->left_stick.y,
+ (float) ((data[12] >> 4) | (data[13] << 4)),
+ true
+ );
+ MapJoystickAxis(
+ timestamp,
+ joystick,
+ SDL_GAMEPAD_AXIS_RIGHTX,
+ &ctx->right_stick.x,
+ (float) (data[14] | ((data[15] & 0x0F) << 8)),
+ false
+ );
+ MapJoystickAxis(
+ timestamp,
+ joystick,
+ SDL_GAMEPAD_AXIS_RIGHTY,
+ &ctx->right_stick.y,
+ (float)((data[15] >> 4) | (data[16] << 4)),
+ true
+ );
+}
+
+static void EncodeHDRumble(Uint16 high_freq, Uint16 high_amp, Uint16 low_freq, Uint16 low_amp, Uint8 rumble_data[5])
+{
+ rumble_data[0] = (Uint8)(high_freq & 0xFF);
+ rumble_data[1] = (Uint8)(((high_amp >> 4) & 0xfc) | ((high_freq >> 8) & 0x03));
+ rumble_data[2] = (Uint8)((high_amp >> 12) | (low_freq << 4));
+ rumble_data[3] = (Uint8)((low_amp & 0xc0) | ((low_freq >> 4) & 0x3f));
+ rumble_data[4] = (Uint8)(low_amp >> 8);
+}
+
+static bool UpdateRumble(SDL_DriverSwitch2_Context *ctx)
+{
+ if (!ctx->rumble_updated && !ctx->rumble_lo_amp && !ctx->rumble_hi_amp) {
+ return true;
+ }
+
+ Uint64 timestamp = SDL_GetTicks();
+ Uint64 interval = RUMBLE_INTERVAL;
+
+ if (timestamp < ctx->rumble_timestamp) {
+ return true;
+ }
+
+ if (!SDL_HIDAPI_LockRumble()) {
+ return false;
+ }
+
+ unsigned char rumble_data[64] = {0};
+ if (ctx->device->product_id == USB_PRODUCT_NINTENDO_SWITCH2_GAMECUBE_CONTROLLER) {
+ Uint16 rumble_max = SDL_max(ctx->rumble_lo_amp, ctx->rumble_hi_amp);
+ rumble_data[0x00] = 0x3;
+ rumble_data[1] = 0x50 | (ctx->rumble_seq & 0xf);
+ if (rumble_max == 0) {
+ rumble_data[2] = 2;
+ ctx->rumble_error = 0;
+ } else {
+ if (ctx->rumble_error < rumble_max) {
+ rumble_data[2] = 1;
+ ctx->rumble_error += UINT16_MAX - rumble_max;
+ } else {
+ rumble_data[2] = 0;
+ ctx->rumble_error -= rumble_max;
+ }
+ }
+ } else {
+ // Rumble can get so strong that it might be dangerous to the controller...
+ // This is a game controller, not a massage device, so let's clamp it somewhat
+ Uint16 low_amp = (Uint16)((int)ctx->rumble_lo_amp * RUMBLE_MAX / UINT16_MAX);
+ Uint16 high_amp = (Uint16)((int)ctx->rumble_hi_amp * RUMBLE_MAX / UINT16_MAX);
+ rumble_data[0x01] = 0x50 | (ctx->rumble_seq & 0xf);
+ EncodeHDRumble(ctx->rumble_hi_freq, high_amp, ctx->rumble_lo_freq, low_amp, &rumble_data[0x02]);
+ switch (ctx->device->product_id) {
+ case USB_PRODUCT_NINTENDO_SWITCH2_JOYCON_LEFT:
+ case USB_PRODUCT_NINTENDO_SWITCH2_JOYCON_RIGHT:
+ if (ctx->device->parent) {
+ // FIXME: This shouldn't be necessary, but the rumble thread appears to back up if we don't do this
+ interval *= 2;
+ }
+ rumble_data[0] = 0x1;
+ break;
+ case USB_PRODUCT_NINTENDO_SWITCH2_PRO:
+ rumble_data[0] = 0x2;
+ SDL_memcpy(&rumble_data[0x11], &rumble_data[0x01], 6);
+ break;
+ }
+ }
+ ctx->rumble_seq++;
+ ctx->rumble_updated = false;
+ if (!ctx->rumble_lo_amp && !ctx->rumble_hi_amp) {
+ ctx->rumble_timestamp = 0;
+ } else {
+ if (!ctx->rumble_timestamp) {
+ ctx->rumble_timestamp = timestamp;
+ }
+ ctx->rumble_timestamp += interval;
+ }
+
+ if (SDL_HIDAPI_SendRumbleAndUnlock(ctx->device, rumble_data, sizeof(rumble_data)) != sizeof(rumble_data)) {
+ return SDL_SetError("Couldn't send rumble packet");
+ }
+ return true;
+}
+
+static void HIDAPI_DriverSwitch2_HandleStatePacket(SDL_HIDAPI_Device *device, SDL_Joystick *joystick, SDL_DriverSwitch2_Context *ctx, Uint8 *data, int size)
+{
+ Uint64 timestamp = SDL_GetTicksNS();
+
+ if (size < 64) {
+ // We don't know how to handle this report
+ return;
+ }
+
+ switch (device->product_id) {
+ case USB_PRODUCT_NINTENDO_SWITCH2_GAMECUBE_CONTROLLER:
+ HandleGameCubeState(timestamp, joystick, ctx, data, size);
+ break;
+ case USB_PRODUCT_NINTENDO_SWITCH2_JOYCON_LEFT:
+ if (device->parent || ctx->vertical_mode) {
+ HandleCombinedControllerStateL(timestamp, joystick, ctx, data, size);
+ } else {
+ HandleMiniControllerStateL(timestamp, joystick, ctx, data, size);
+ }
+ break;
+ case USB_PRODUCT_NINTENDO_SWITCH2_JOYCON_RIGHT:
+ if (device->parent || ctx->vertical_mode) {
+ HandleCombinedControllerStateR(timestamp, joystick, ctx, data, size);
+ } else {
+ HandleMiniControllerStateR(timestamp, joystick, ctx, data, size);
+ }
+ break;
+ case USB_PRODUCT_NINTENDO_SWITCH2_PRO:
+ HandleSwitchProState(timestamp, joystick, ctx, data, size);
+ break;
+ default:
+ // FIXME: Need state handling implementation
+ break;
+ }
+
+ Uint64 sensor_timestamp = (Uint32) (data[0x2b] | (data[0x2c] << 8U) | (data[0x2d] << 16U) | (data[0x2e] << 24U));
+ if (sensor_timestamp && !ctx->sensors_ready) {
+ ctx->sample_count++;
+ if (ctx->sample_count >= 5 && !ctx->first_sensor_timestamp) {
+ ctx->first_sensor_timestamp = sensor_timestamp;
+ ctx->sample_count = 0;
+ } else if (ctx->sample_count == 100) {
+ // Calculate timestamp coefficient
+ // Timestamp are normally microseconds but sometimes it's something else for no apparent reason
+ Uint64 coeff = 1000 * (sensor_timestamp - ctx->first_sensor_timestamp) / (ctx->sample_count * 4);
+ if ((coeff + 100000) / 200000 == 5) {
+ // Within 10% of 1000
+ ctx->sensor_ts_coeff = 10000;
+ ctx->gyro_coeff = 34.8f;
+ ctx->sensors_ready = true;
+ } else if (coeff != 0) {
+ ctx->sensor_ts_coeff = 10000000000 / coeff;
+ ctx->gyro_coeff = 40.0f;
+ ctx->sensors_ready = true;
+ } else {
+ // Didn't get a valid reading, try again
+ ctx->first_sensor_timestamp = 0;
+ ctx->sample_count = 0;
+ }
+
+ if (ctx->sensors_ready && !ctx->sensors_enabled) {
+ Uint8 set_features[] = {
+ 0x0c, 0x91, 0x00, 0x04, 0x00, 0x04, 0x00, 0x00, 0x23, 0x00, 0x00, 0x00
+ };
+ unsigned char reply[12] = {0};
+
+ SendBulkData(ctx, set_features, sizeof(set_features));
+ RecvBulkData(ctx, reply, sizeof(reply));
+ }
+ }
+ }
+ if (ctx->sensors_enabled && sensor_timestamp && ctx->sensors_ready) {
+ sensor_timestamp = sensor_timestamp * ctx->sensor_ts_coeff / 10;
+ float accel_data[3];
+ float gyro_data[3];
+ const float g = 9.80665f;
+ const float accel_scale = g * 8.f / INT16_MAX;
+
+ accel_data[0] = (Sint16)(data[0x31] | (data[0x32] << 8)) * accel_scale;
+ accel_data[1] = (Sint16)(data[0x35] | (data[0x36] << 8)) * accel_scale;
+ accel_data[2] = (Sint16)(data[0x33] | (data[0x34] << 8)) * -accel_scale;
+
+ gyro_data[0] = (Sint16)(data[0x37] | (data[0x38] << 8)) * ctx->gyro_coeff / INT16_MAX - ctx->gyro_bias_x;
+ gyro_data[1] = (Sint16)(data[0x3b] | (data[0x3c] << 8)) * ctx->gyro_coeff / INT16_MAX - ctx->gyro_bias_z;
+ gyro_data[2] = (Sint16)(data[0x39] | (data[0x3a] << 8)) * -ctx->gyro_coeff / INT16_MAX + ctx->gyro_bias_y;
+
+ switch (ctx->device->product_id) {
+ case USB_PRODUCT_NINTENDO_SWITCH2_JOYCON_LEFT:
+ if (ctx->device->parent) {
+ SDL_SendJoystickSensor(timestamp, joystick, SDL_SENSOR_GYRO_L, sensor_timestamp, gyro_data, 3);
+ SDL_SendJoystickSensor(timestamp, joystick, SDL_SENSOR_ACCEL_L, sensor_timestamp, accel_data, 3);
+ } else {
+ float tmp = -accel_data[0];
+ accel_data[0] = accel_data[2];
+ accel_data[2] = tmp;
+
+ tmp = -gyro_data[0];
+ gyro_data[0] = gyro_data[2];
+ gyro_data[2] = tmp;
+
+ SDL_SendJoystickSensor(timestamp, joystick, SDL_SENSOR_GYRO, sensor_timestamp, gyro_data, 3);
+ SDL_SendJoystickSensor(timestamp, joystick, SDL_SENSOR_ACCEL, sensor_timestamp, accel_data, 3);
+ }
+ break;
+ case USB_PRODUCT_NINTENDO_SWITCH2_JOYCON_RIGHT:
+ if (ctx->device->parent) {
+ SDL_SendJoystickSensor(timestamp, joystick, SDL_SENSOR_GYRO, sensor_timestamp, gyro_data, 3);
+ SDL_SendJoystickSensor(timestamp, joystick, SDL_SENSOR_ACCEL, sensor_timestamp, accel_data, 3);
+ SDL_SendJoystickSensor(timestamp, joystick, SDL_SENSOR_GYRO_R, sensor_timestamp, gyro_data, 3);
+ SDL_SendJoystickSensor(timestamp, joystick, SDL_SENSOR_ACCEL_R, sensor_timestamp, accel_data, 3);
+ } else {
+ float tmp = accel_data[0];
+ accel_data[0] = -accel_data[2];
+ accel_data[2] = tmp;
+
+ tmp = gyro_data[0];
+ gyro_data[0] = -gyro_data[2];
+ gyro_data[2] = tmp;
+
+ SDL_SendJoystickSensor(timestamp, joystick, SDL_SENSOR_GYRO, sensor_timestamp, gyro_data, 3);
+ SDL_SendJoystickSensor(timestamp, joystick, SDL_SENSOR_ACCEL, sensor_timestamp, accel_data, 3);
+ }
+ break;
+ default:
+ SDL_SendJoystickSensor(timestamp, joystick, SDL_SENSOR_GYRO, sensor_timestamp, gyro_data, 3);
+ SDL_SendJoystickSensor(timestamp, joystick, SDL_SENSOR_ACCEL, sensor_timestamp, accel_data, 3);
+ break;
+ }
+ }
+
+ SDL_memcpy(ctx->last_state, data, SDL_min(size, sizeof(ctx->last_state)));
+}
+
+static bool HIDAPI_DriverSwitch2_UpdateDevice(SDL_HIDAPI_Device *device)
+{
+ SDL_DriverSwitch2_Context *ctx = (SDL_DriverSwitch2_Context *)device->context;
+ SDL_Joystick *joystick = NULL;
+ Uint8 data[USB_PACKET_LENGTH];
+ int size = 0;
+
+ if (device->num_joysticks > 0) {
+ joystick = SDL_GetJoystickFromID(device->joysticks[0]);
+ } else {
+ return false;
+ }
+
+ while ((size = SDL_hid_read_timeout(device->dev, data, sizeof(data), 0)) > 0) {
+#ifdef DEBUG_SWITCH2_PROTOCOL
+ if (device->product_id == USB_PRODUCT_NINTENDO_SWITCH2_JOYCON_LEFT) {
+ HIDAPI_DumpPacket("Nintendo Joy-Con(L) packet: size = %d", data, size);
+ } else if (device->product_id == USB_PRODUCT_NINTENDO_SWITCH2_JOYCON_RIGHT) {
+ HIDAPI_DumpPacket("Nintendo Joy-Con(R) packet: size = %d", data, size);
+ } else {
+ HIDAPI_DumpPacket("Nintendo Switch2 packet: size = %d", data, size);
+ }
+#endif
+ if (!joystick) {
+ continue;
+ }
+
+ HIDAPI_DriverSwitch2_HandleStatePacket(device, joystick, ctx, data, size);
+
+ UpdateRumble(ctx);
+ }
+
+ if (size < 0) {
+ // Read error, device is disconnected
+ HIDAPI_JoystickDisconnected(device, device->joysticks[0]);
+ }
+ return (size >= 0);
+}
+
+static void HIDAPI_DriverSwitch2_CloseJoystick(SDL_HIDAPI_Device *device, SDL_Joystick *joystick)
+{
+ SDL_DriverSwitch2_Context *ctx = (SDL_DriverSwitch2_Context *)device->context;
+
+ SDL_RemoveHintCallback(SDL_HINT_JOYSTICK_HIDAPI_SWITCH_PLAYER_LED,
+ SDL_PlayerLEDHintChanged, ctx);
+
+ ctx->joystick = NULL;
+}
+
+static void HIDAPI_DriverSwitch2_FreeDevice(SDL_HIDAPI_Device *device)
+{
+ SDL_DriverSwitch2_Context *ctx = (SDL_DriverSwitch2_Context *)device->context;
+
+ if (ctx) {
+ if (ctx->interface_claimed) {
+ ctx->libusb->release_interface(ctx->device_handle, ctx->interface_number);
+ ctx->interface_claimed = false;
+ }
+ if (ctx->libusb) {
+ SDL_QuitLibUSB();
+ ctx->libusb = NULL;
+ }
+ }
+}
+
+SDL_HIDAPI_DeviceDriver SDL_HIDAPI_DriverSwitch2 = {
+ SDL_HINT_JOYSTICK_HIDAPI_SWITCH2,
+ true,
+ HIDAPI_DriverSwitch2_RegisterHints,
+ HIDAPI_DriverSwitch2_UnregisterHints,
+ HIDAPI_DriverSwitch2_IsEnabled,
+ HIDAPI_DriverSwitch2_IsSupportedDevice,
+ HIDAPI_DriverSwitch2_InitDevice,
+ HIDAPI_DriverSwitch2_GetDevicePlayerIndex,
+ HIDAPI_DriverSwitch2_SetDevicePlayerIndex,
+ HIDAPI_DriverSwitch2_UpdateDevice,
+ HIDAPI_DriverSwitch2_OpenJoystick,
+ HIDAPI_DriverSwitch2_RumbleJoystick,
+ HIDAPI_DriverSwitch2_RumbleJoystickTriggers,
+ HIDAPI_DriverSwitch2_GetJoystickCapabilities,
+ HIDAPI_DriverSwitch2_SetJoystickLED,
+ HIDAPI_DriverSwitch2_SendJoystickEffect,
+ HIDAPI_DriverSwitch2_SetJoystickSensorsEnabled,
+ HIDAPI_DriverSwitch2_CloseJoystick,
+ HIDAPI_DriverSwitch2_FreeDevice,
+};
+
+#endif // SDL_JOYSTICK_HIDAPI_SWITCH2
+
+#endif // SDL_JOYSTICK_HIDAPI
diff --git a/thirdparty/sdl/joystick/hidapi/SDL_hidapi_wii.c b/thirdparty/sdl/joystick/hidapi/SDL_hidapi_wii.c
index fb3e164a8d0..ac2d7b98572 100644
--- a/thirdparty/sdl/joystick/hidapi/SDL_hidapi_wii.c
+++ b/thirdparty/sdl/joystick/hidapi/SDL_hidapi_wii.c
@@ -1,6 +1,6 @@
/*
Simple DirectMedia Layer
- Copyright (C) 1997-2025 Sam Lantinga <[email protected]>
+ Copyright (C) 1997-2026 Sam Lantinga <[email protected]>
This software is provided 'as-is', without any express or implied
warranty. In no event will the authors be held liable for any damages
@@ -512,6 +512,8 @@ static void UpdatePowerLevelWiiU(SDL_Joystick *joystick, Uint8 extensionBatteryB
bool pluggedIn = !(extensionBatteryByte & 0x04);
Uint8 batteryLevel = extensionBatteryByte >> 4;
+ SDL_AssertJoysticksLocked();
+
if (pluggedIn) {
joystick->connection_state = SDL_JOYSTICK_CONNECTION_WIRED;
} else {
diff --git a/thirdparty/sdl/joystick/hidapi/SDL_hidapi_xbox360.c b/thirdparty/sdl/joystick/hidapi/SDL_hidapi_xbox360.c
index 49be08ab52b..8ada0f9843a 100644
--- a/thirdparty/sdl/joystick/hidapi/SDL_hidapi_xbox360.c
+++ b/thirdparty/sdl/joystick/hidapi/SDL_hidapi_xbox360.c
@@ -1,6 +1,6 @@
/*
Simple DirectMedia Layer
- Copyright (C) 1997-2025 Sam Lantinga <[email protected]>
+ Copyright (C) 1997-2026 Sam Lantinga <[email protected]>
This software is provided 'as-is', without any express or implied
warranty. In no event will the authors be held liable for any damages
@@ -32,6 +32,10 @@
// Define this if you want to log all packets from the controller
// #define DEBUG_XBOX_PROTOCOL
+#ifdef SDL_PLATFORM_MACOS
+#include <IOKit/IOKitLib.h>
+#endif
+
typedef struct
{
SDL_HIDAPI_Device *device;
@@ -39,6 +43,10 @@ typedef struct
int player_index;
bool player_lights;
Uint8 last_state[USB_PACKET_LENGTH];
+#ifdef SDL_PLATFORM_MACOS
+ bool controlled_by_360controller;
+ bool is_steam_virtual_gamepad;
+#endif
} SDL_DriverXbox360_Context;
static void HIDAPI_DriverXbox360_RegisterHints(SDL_HintCallback callback, void *userdata)
@@ -59,6 +67,22 @@ static bool HIDAPI_DriverXbox360_IsEnabled(void)
SDL_GetHintBoolean(SDL_HINT_JOYSTICK_HIDAPI_XBOX, SDL_GetHintBoolean(SDL_HINT_JOYSTICK_HIDAPI, SDL_HIDAPI_DEFAULT)));
}
+#ifdef SDL_PLATFORM_MACOS
+static bool IsControlledBy360ControllerDriverMacOS(SDL_HIDAPI_Device *device)
+{
+ bool controlled_by_360controller = false;
+ if (device && device->path && SDL_strncmp("DevSrvsID:", device->path, 10) == 0) {
+ uint64_t entry_id = SDL_strtoull(device->path + 10, NULL, 10);
+ io_service_t service = IOServiceGetMatchingService(0, IORegistryEntryIDMatching(entry_id));
+ if (service != MACH_PORT_NULL) {
+ controlled_by_360controller = IOObjectConformsTo(service, "Xbox360ControllerClass");
+ IOObjectRelease(service);
+ }
+ }
+ return controlled_by_360controller;
+}
+#endif
+
static bool HIDAPI_DriverXbox360_IsSupportedDevice(SDL_HIDAPI_Device *device, const char *name, SDL_GamepadType type, Uint16 vendor_id, Uint16 product_id, Uint16 version, int interface_number, int interface_class, int interface_subclass, int interface_protocol)
{
const int XB360W_IFACE_PROTOCOL = 129; // Wireless
@@ -80,18 +104,29 @@ static bool HIDAPI_DriverXbox360_IsSupportedDevice(SDL_HIDAPI_Device *device, co
// This is the chatpad or other input interface, not the Xbox 360 interface
return false;
}
-#if defined(SDL_PLATFORM_MACOS) && defined(SDL_JOYSTICK_MFI)
- if (SDL_IsJoystickSteamVirtualGamepad(vendor_id, product_id, version)) {
- // GCController support doesn't work with the Steam Virtual Gamepad
+#ifdef SDL_PLATFORM_MACOS
+ if (IsControlledBy360ControllerDriverMacOS(device)) {
+ // Wired Xbox controllers are handled by this driver, when they are
+ // controlled by the 360Controller driver available from:
+ // https://github.com/360Controller/360Controller/releases
return true;
- } else {
- // On macOS you can't write output reports to wired XBox controllers,
- // so we'll just use the GCController support instead.
- return false;
}
-#else
- return (type == SDL_GAMEPAD_TYPE_XBOX360);
#endif
+#if defined(SDL_PLATFORM_MACOS) && defined(SDL_JOYSTICK_MFI)
+ if (SDL_GetHintBoolean(SDL_HINT_JOYSTICK_MFI, true)) {
+ if (SDL_IsJoystickSteamVirtualGamepad(vendor_id, product_id, version)) {
+ // GCController support doesn't work with the Steam Virtual Gamepad
+ return true;
+ }
+ if (device && SDL_strncmp(device->path, "DevSrvsID", 9) == 0) {
+ // On macOS when it isn't controlled by the 360Controller driver and
+ // it doesn't look like a Steam virtual gamepad and it's not
+ // available via libusb we should rely on GCController support.
+ return false;
+ }
+ }
+#endif
+ return (type == SDL_GAMEPAD_TYPE_XBOX360);
}
static bool SetSlotLED(SDL_hid_device *dev, Uint8 slot, bool on)
@@ -138,6 +173,10 @@ static bool HIDAPI_DriverXbox360_InitDevice(SDL_HIDAPI_Device *device)
return false;
}
ctx->device = device;
+#ifdef SDL_PLATFORM_MACOS
+ ctx->controlled_by_360controller = IsControlledBy360ControllerDriverMacOS(device);
+ ctx->is_steam_virtual_gamepad = SDL_IsJoystickSteamVirtualGamepad(device->vendor_id, device->product_id, device->version);
+#endif
device->context = ctx;
@@ -198,6 +237,19 @@ static bool HIDAPI_DriverXbox360_OpenJoystick(SDL_HIDAPI_Device *device, SDL_Joy
static bool HIDAPI_DriverXbox360_RumbleJoystick(SDL_HIDAPI_Device *device, SDL_Joystick *joystick, Uint16 low_frequency_rumble, Uint16 high_frequency_rumble)
{
+#ifdef SDL_PLATFORM_MACOS
+ if (((SDL_DriverXbox360_Context *)device->context)->controlled_by_360controller) {
+ // On macOS the 360Controller driver uses this short report,
+ // and we need to prefix it with a magic token so hidapi passes it through untouched
+ Uint8 rumble_packet[] = { 'M', 'A', 'G', 'I', 'C', '0', 0x00, 0x04, 0x00, 0x00 };
+ rumble_packet[6 + 2] = (low_frequency_rumble >> 8);
+ rumble_packet[6 + 3] = (high_frequency_rumble >> 8);
+ if (SDL_HIDAPI_SendRumble(device, rumble_packet, sizeof(rumble_packet)) != sizeof(rumble_packet)) {
+ return SDL_SetError("Couldn't send rumble packet");
+ }
+ return true;
+ }
+#endif
Uint8 rumble_packet[] = { 0x00, 0x08, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00 };
rumble_packet[3] = (low_frequency_rumble >> 8);
@@ -244,7 +296,10 @@ static void HIDAPI_DriverXbox360_HandleStatePacket(SDL_Joystick *joystick, SDL_D
{
Sint16 axis;
#ifdef SDL_PLATFORM_MACOS
- const bool invert_y_axes = false;
+ // For backwards compatibility reasons, the 360Controller driver and the Steam Virtual
+ // Gamepad require opposite Y axis inversion on macOS
+ const bool invert_y_axes = (ctx->controlled_by_360controller ||
+ ctx->is_steam_virtual_gamepad) ? false : true;
#else
const bool invert_y_axes = true;
#endif
diff --git a/thirdparty/sdl/joystick/hidapi/SDL_hidapi_xbox360w.c b/thirdparty/sdl/joystick/hidapi/SDL_hidapi_xbox360w.c
index bf63707a0ac..57206bb8f88 100644
--- a/thirdparty/sdl/joystick/hidapi/SDL_hidapi_xbox360w.c
+++ b/thirdparty/sdl/joystick/hidapi/SDL_hidapi_xbox360w.c
@@ -1,6 +1,6 @@
/*
Simple DirectMedia Layer
- Copyright (C) 1997-2025 Sam Lantinga <[email protected]>
+ Copyright (C) 1997-2026 Sam Lantinga <[email protected]>
This software is provided 'as-is', without any express or implied
warranty. In no event will the authors be held liable for any damages
diff --git a/thirdparty/sdl/joystick/hidapi/SDL_hidapi_xboxone.c b/thirdparty/sdl/joystick/hidapi/SDL_hidapi_xboxone.c
index 342eabdf75c..5d97876f746 100644
--- a/thirdparty/sdl/joystick/hidapi/SDL_hidapi_xboxone.c
+++ b/thirdparty/sdl/joystick/hidapi/SDL_hidapi_xboxone.c
@@ -1,6 +1,6 @@
/*
Simple DirectMedia Layer
- Copyright (C) 1997-2025 Sam Lantinga <[email protected]>
+ Copyright (C) 1997-2026 Sam Lantinga <[email protected]>
This software is provided 'as-is', without any express or implied
warranty. In no event will the authors be held liable for any damages
@@ -26,6 +26,7 @@
#include "../SDL_sysjoystick.h"
#include "SDL_hidapijoystick_c.h"
#include "SDL_hidapi_rumble.h"
+#include "SDL_report_descriptor.h"
#ifdef SDL_JOYSTICK_HIDAPI_XBOXONE
@@ -33,7 +34,9 @@
// #define DEBUG_JOYSTICK
// Define this if you want to log all packets from the controller
-// #define DEBUG_XBOX_PROTOCOL
+#if 0
+#define DEBUG_XBOX_PROTOCOL
+#endif
#if defined(SDL_PLATFORM_WIN32) || defined(SDL_PLATFORM_WINGDK)
#define XBOX_ONE_DRIVER_ACTIVE 1
@@ -132,6 +135,8 @@ typedef struct
bool has_unmapped_state;
bool has_trigger_rumble;
bool has_share_button;
+ bool has_separate_back_button;
+ bool has_separate_guide_button;
Uint8 last_paddle_state;
Uint8 low_frequency_rumble;
Uint8 high_frequency_rumble;
@@ -140,6 +145,8 @@ typedef struct
SDL_XboxOneRumbleState rumble_state;
Uint64 rumble_time;
bool rumble_pending;
+ SDL_ReportDescriptor *descriptor;
+ Uint32 last_buttons;
Uint8 last_state[USB_PACKET_LENGTH];
Uint8 *chunk_buffer;
Uint32 chunk_length;
@@ -266,8 +273,14 @@ static bool SendSerialRequest(SDL_DriverXboxOne_Context *ctx)
static bool ControllerSendsAnnouncement(Uint16 vendor_id, Uint16 product_id)
{
- if (vendor_id == USB_VENDOR_PDP && product_id == 0x0246) {
- // The PDP Rock Candy (PID 0x0246) doesn't send the announce packet on Linux for some reason
+ // The PDP Rock Candy (PID 0x0246) and PowerA Fusion Pro 4 (PID 0x400b)
+ // don't send the announce packet on Linux for some reason.
+ //
+ // Just to be safe and cover future products, we'll always send the startup
+ // protocol sequence for PDP and PowerA controllers
+ if (vendor_id == USB_VENDOR_PDP ||
+ vendor_id == USB_VENDOR_POWERA ||
+ vendor_id == USB_VENDOR_POWERA_ALT) {
return false;
}
return true;
@@ -350,14 +363,33 @@ static bool HIDAPI_DriverXboxOne_IsEnabled(void)
static bool HIDAPI_DriverXboxOne_IsSupportedDevice(SDL_HIDAPI_Device *device, const char *name, SDL_GamepadType type, Uint16 vendor_id, Uint16 product_id, Uint16 version, int interface_number, int interface_class, int interface_subclass, int interface_protocol)
{
+ static const int LIBUSB_CLASS_VENDOR_SPEC = 0xFF;
+ static const int XBONE_IFACE_SUBCLASS = 71;
+ static const int XBONE_IFACE_PROTOCOL = 208;
+
#if defined(SDL_PLATFORM_MACOS) && defined(SDL_JOYSTICK_MFI)
- if (!SDL_IsJoystickBluetoothXboxOne(vendor_id, product_id)) {
+ if (SDL_GetHintBoolean(SDL_HINT_JOYSTICK_MFI, true) &&
+ !SDL_IsJoystickBluetoothXboxOne(vendor_id, product_id) &&
+ (device && SDL_strncmp(device->path, "DevSrvsID", 9) == 0)) {
// On macOS we get a shortened version of the real report and
// you can't write output reports for wired controllers, so
- // we'll just use the GCController support instead.
+ // we'll just use the GCController support instead, if available.
+ return false;
+ }
+#endif
+#ifdef SDL_PLATFORM_WIN32
+ if (device && SDL_strncmp(device->path, "\\\\?\\HID#", 8) == 0) {
+ // Windows provides a fake HID endpoint for XGIP controllers, don't use this
return false;
}
#endif
+ if (interface_class &&
+ (interface_class != LIBUSB_CLASS_VENDOR_SPEC ||
+ interface_subclass != XBONE_IFACE_SUBCLASS ||
+ interface_protocol != XBONE_IFACE_PROTOCOL)) {
+ // This isn't the Xbox gamepad interface
+ return false;
+ }
return (type == SDL_GAMEPAD_TYPE_XBOXONE);
}
@@ -373,6 +405,59 @@ static bool HIDAPI_DriverXboxOne_InitDevice(SDL_HIDAPI_Device *device)
device->context = ctx;
+// The Xbox controller doesn't have real HID report descriptors, but Linux synthesizes them for us
+#ifdef SDL_PLATFORM_LINUX
+ Uint8 descriptor[1024];
+ int descriptor_len = SDL_hid_get_report_descriptor(device->dev, descriptor, sizeof(descriptor));
+ if (descriptor_len > 0) {
+ HIDAPI_DumpPacket("Xbox One report descriptor: size = %d", descriptor, descriptor_len);
+
+ ctx->descriptor = SDL_ParseReportDescriptor(descriptor, descriptor_len);
+ if (ctx->descriptor) {
+ // Collapse the buttons into a single field read
+ int field_count = ctx->descriptor->field_count;
+ DescriptorInputField *fields = ctx->descriptor->fields;
+ int button_count = 0;
+ for (int i = 0; i < field_count; ++i) {
+ DescriptorInputField *field = &fields[i];
+ if (field->usage == MAKE_USAGE(USB_USAGEPAGE_BUTTON, 1)) {
+ Uint32 expected_usage = field->usage;
+ int expected_offset = field->bit_offset;
+ for (int j = i; j < field_count; ++j) {
+ DescriptorInputField *other = &fields[j];
+ if (other->usage != expected_usage ||
+ other->bit_offset != expected_offset) {
+ break;
+ }
+
+ ++button_count;
+ ++expected_usage;
+ ++expected_offset;
+ }
+ field->bit_size = button_count;
+
+ int next_field = i + button_count;
+ int fields_left = (field_count - next_field);
+ SDL_memmove(&fields[i+1], &fields[next_field], (fields_left * sizeof(fields[0])));
+ ctx->descriptor->field_count -= (button_count - 1);
+ break;
+ }
+ }
+ if (!SDL_DescriptorHasUsage(ctx->descriptor, USB_USAGEPAGE_GENERIC_DESKTOP, USB_USAGE_GENERIC_X) ||
+ !SDL_DescriptorHasUsage(ctx->descriptor, USB_USAGEPAGE_GENERIC_DESKTOP, USB_USAGE_GENERIC_Y) ||
+ (button_count != 12 && button_count != 15)) {
+ SDL_LogWarn(SDL_LOG_CATEGORY_INPUT, "Xbox report descriptor missing expected usages, ignoring");
+ SDL_DestroyDescriptor(ctx->descriptor);
+ ctx->descriptor = NULL;
+ }
+ } else {
+ SDL_LogWarn(SDL_LOG_CATEGORY_INPUT, "Couldn't parse Xbox report descriptor: %s", SDL_GetError());
+ }
+ } else {
+ SDL_LogDebug(SDL_LOG_CATEGORY_INPUT, "Xbox report descriptor not available");
+ }
+#endif // SDL_PLATFORM_LINUX
+
ctx->vendor_id = device->vendor_id;
ctx->product_id = device->product_id;
ctx->start_time = SDL_GetTicks();
@@ -581,6 +666,310 @@ static bool HIDAPI_DriverXboxOne_SetJoystickSensorsEnabled(SDL_HIDAPI_Device *de
return SDL_Unsupported();
}
+static void HIDAPI_DriverXboxOne_HandleBatteryState(SDL_Joystick *joystick, Uint32 flags)
+{
+ bool on_usb = (((flags & 0x0C) >> 2) == 0);
+ SDL_PowerState state;
+ int percent = 0;
+
+ // Mapped percentage value from:
+ // https://learn.microsoft.com/en-us/gaming/gdk/_content/gc/reference/input/gameinput/interfaces/igameinputdevice/methods/igameinputdevice_getbatterystate
+ switch (flags & 0x03) {
+ case 0:
+ percent = 10;
+ break;
+ case 1:
+ percent = 40;
+ break;
+ case 2:
+ percent = 70;
+ break;
+ case 3:
+ percent = 100;
+ break;
+ }
+ if (on_usb) {
+ state = SDL_POWERSTATE_CHARGING;
+ } else {
+ state = SDL_POWERSTATE_ON_BATTERY;
+ }
+ SDL_SendJoystickPowerInfo(joystick, state, percent);
+}
+
+static void HandleDescriptorAxis(Uint64 timestamp, SDL_Joystick *joystick, SDL_GamepadAxis axis, Uint32 value)
+{
+ Sint16 axis_value = (Sint16)((int)value - 0x8000);
+ SDL_SendJoystickAxis(timestamp, joystick, axis, axis_value);
+}
+
+static void HandleDescriptorTrigger(Uint64 timestamp, SDL_Joystick *joystick, SDL_GamepadAxis axis, Uint32 value)
+{
+ Sint16 axis_value = (Sint16)(((int)value * 64) - 32768);
+ if (axis_value == 32704) {
+ axis_value = 32767;
+ }
+ SDL_SendJoystickAxis(timestamp, joystick, axis, axis_value);
+}
+
+static bool HIDAPI_DriverXboxOne_HandleDescriptorReport(SDL_Joystick *joystick, SDL_DriverXboxOne_Context *ctx, Uint8 *data, int size)
+{
+ const SDL_ReportDescriptor *descriptor = ctx->descriptor;
+ Uint64 timestamp = SDL_GetTicksNS();
+
+ // Skip the report ID
+ const Uint8 report_id = *data;
+ ++data;
+ --size;
+
+ for (int i = 0; i < descriptor->field_count; ++i) {
+ DescriptorInputField *field = &descriptor->fields[i];
+ if (field->report_id != report_id) {
+ continue;
+ }
+
+ Uint32 value;
+ if (!SDL_ReadReportData(data, size, field->bit_offset, field->bit_size, &value)) {
+ continue;
+ }
+
+ switch (field->usage) {
+ case MAKE_USAGE(USB_USAGEPAGE_GENERIC_DESKTOP, USB_USAGE_GENERIC_X):
+ {
+ HandleDescriptorAxis(timestamp, joystick, SDL_GAMEPAD_AXIS_LEFTX, value);
+ break;
+ }
+ case MAKE_USAGE(USB_USAGEPAGE_GENERIC_DESKTOP, USB_USAGE_GENERIC_Y):
+ {
+ HandleDescriptorAxis(timestamp, joystick, SDL_GAMEPAD_AXIS_LEFTY, value);
+ break;
+ }
+ // Some controllers use Z+RZ for the right thumbstick and BRAKE and ACCEL for the left and right triggers
+ // and others use RX+RY for the right thumbstick and Z and RZ for the left and right triggers
+ case MAKE_USAGE(USB_USAGEPAGE_GENERIC_DESKTOP, USB_USAGE_GENERIC_Z):
+ {
+ if (field->bit_size == 16) {
+ HandleDescriptorAxis(timestamp, joystick, SDL_GAMEPAD_AXIS_RIGHTX, value);
+ } else if (field->bit_size == 10) {
+ HandleDescriptorTrigger(timestamp, joystick, SDL_GAMEPAD_AXIS_LEFT_TRIGGER, value);
+ }
+ break;
+ }
+ case MAKE_USAGE(USB_USAGEPAGE_GENERIC_DESKTOP, USB_USAGE_GENERIC_RX):
+ {
+ HandleDescriptorAxis(timestamp, joystick, SDL_GAMEPAD_AXIS_RIGHTX, value);
+ break;
+ }
+ case MAKE_USAGE(USB_USAGEPAGE_GENERIC_DESKTOP, USB_USAGE_GENERIC_RY):
+ {
+ HandleDescriptorAxis(timestamp, joystick, SDL_GAMEPAD_AXIS_RIGHTY, value);
+ break;
+ }
+ case MAKE_USAGE(USB_USAGEPAGE_GENERIC_DESKTOP, USB_USAGE_GENERIC_RZ):
+ {
+ if (field->bit_size == 16) {
+ HandleDescriptorAxis(timestamp, joystick, SDL_GAMEPAD_AXIS_RIGHTY, value);
+ } else if (field->bit_size == 10) {
+ HandleDescriptorTrigger(timestamp, joystick, SDL_GAMEPAD_AXIS_RIGHT_TRIGGER, value);
+ }
+ break;
+ }
+ case MAKE_USAGE(USB_USAGEPAGE_SIMULATION, USB_USAGE_SIMULATION_BRAKE):
+ {
+ HandleDescriptorTrigger(timestamp, joystick, SDL_GAMEPAD_AXIS_LEFT_TRIGGER, value);
+ break;
+ }
+ case MAKE_USAGE(USB_USAGEPAGE_SIMULATION, USB_USAGE_SIMULATION_ACCELERATOR):
+ {
+ HandleDescriptorTrigger(timestamp, joystick, SDL_GAMEPAD_AXIS_RIGHT_TRIGGER, value);
+ break;
+ }
+ case MAKE_USAGE(USB_USAGEPAGE_GENERIC_DESKTOP, USB_USAGE_GENERIC_HAT):
+ {
+ Uint8 hat;
+
+ switch (value) {
+ case 1:
+ hat = SDL_HAT_UP;
+ break;
+ case 2:
+ hat = SDL_HAT_RIGHTUP;
+ break;
+ case 3:
+ hat = SDL_HAT_RIGHT;
+ break;
+ case 4:
+ hat = SDL_HAT_RIGHTDOWN;
+ break;
+ case 5:
+ hat = SDL_HAT_DOWN;
+ break;
+ case 6:
+ hat = SDL_HAT_LEFTDOWN;
+ break;
+ case 7:
+ hat = SDL_HAT_LEFT;
+ break;
+ case 8:
+ hat = SDL_HAT_LEFTUP;
+ break;
+ default:
+ hat = SDL_HAT_CENTERED;
+ break;
+ }
+ SDL_SendJoystickHat(timestamp, joystick, 0, hat);
+ break;
+ }
+ case MAKE_USAGE(USB_USAGEPAGE_BUTTON, 1):
+ {
+ static const SDL_GamepadButton button_map_12[] = {
+ // 0x0001
+ SDL_GAMEPAD_BUTTON_SOUTH,
+ // 0x0002
+ SDL_GAMEPAD_BUTTON_EAST,
+ // 0x0004
+ SDL_GAMEPAD_BUTTON_WEST,
+ // 0x0008
+ SDL_GAMEPAD_BUTTON_NORTH,
+ // 0x0010
+ SDL_GAMEPAD_BUTTON_LEFT_SHOULDER,
+ // 0x0020
+ SDL_GAMEPAD_BUTTON_RIGHT_SHOULDER,
+ // 0x0040
+ SDL_GAMEPAD_BUTTON_BACK,
+ // 0x0080
+ SDL_GAMEPAD_BUTTON_START,
+ // 0x0100
+ SDL_GAMEPAD_BUTTON_LEFT_STICK,
+ // 0x0200
+ SDL_GAMEPAD_BUTTON_RIGHT_STICK,
+ // 0x0400
+ SDL_GAMEPAD_BUTTON_GUIDE,
+ // 0x0800
+ SDL_GAMEPAD_BUTTON_INVALID,
+ };
+ static const SDL_GamepadButton button_map_15[] = {
+ // 0x0001
+ SDL_GAMEPAD_BUTTON_SOUTH,
+ // 0x0002
+ SDL_GAMEPAD_BUTTON_EAST,
+ // 0x0004
+ SDL_GAMEPAD_BUTTON_INVALID,
+ // 0x0008
+ SDL_GAMEPAD_BUTTON_WEST,
+ // 0x0010
+ SDL_GAMEPAD_BUTTON_NORTH,
+ // 0x0020
+ SDL_GAMEPAD_BUTTON_INVALID,
+ // 0x0040
+ SDL_GAMEPAD_BUTTON_LEFT_SHOULDER,
+ // 0x0080
+ SDL_GAMEPAD_BUTTON_RIGHT_SHOULDER,
+ // 0x0100
+ SDL_GAMEPAD_BUTTON_INVALID,
+ // 0x0200
+ SDL_GAMEPAD_BUTTON_INVALID,
+ // 0x0400
+ SDL_GAMEPAD_BUTTON_BACK,
+ // 0x0800
+ SDL_GAMEPAD_BUTTON_START,
+ // 0x1000
+ SDL_GAMEPAD_BUTTON_GUIDE,
+ // 0x2000
+ SDL_GAMEPAD_BUTTON_LEFT_STICK,
+ // 0x4000
+ SDL_GAMEPAD_BUTTON_RIGHT_STICK,
+ };
+
+ if (value == ctx->last_buttons) {
+ break;
+ }
+ ctx->last_buttons = value;
+
+ const SDL_GamepadButton *button_map;
+ if (field->bit_size == 12) {
+ button_map = button_map_12;
+ } else if (field->bit_size == 15) {
+ button_map = button_map_15;
+ } else {
+ // Should never happen
+ break;
+ }
+ for (int button_index = 0; button_index < field->bit_size; ++button_index, value >>= 1) {
+ SDL_GamepadButton button = button_map[button_index];
+ if (button == SDL_GAMEPAD_BUTTON_INVALID) {
+ continue;
+ }
+ if (button == SDL_GAMEPAD_BUTTON_BACK && ctx->has_separate_back_button) {
+ continue;
+ }
+ if (button == SDL_GAMEPAD_BUTTON_GUIDE && ctx->has_separate_guide_button) {
+ continue;
+ }
+
+ bool pressed = ((value & 1) != 0);
+ SDL_SendJoystickButton(timestamp, joystick, button, pressed);
+ }
+ break;
+ }
+ case MAKE_USAGE(USB_USAGEPAGE_CONSUMER, USB_USAGE_CONSUMER_AC_BACK):
+ {
+ bool pressed = (value != 0);
+ if (pressed) {
+ ctx->has_separate_back_button = true;
+ }
+ SDL_SendJoystickButton(timestamp, joystick, SDL_GAMEPAD_BUTTON_BACK, pressed);
+ break;
+ }
+ case MAKE_USAGE(USB_USAGEPAGE_CONSUMER, USB_USAGE_CONSUMER_AC_HOME):
+ {
+ bool pressed = (value != 0);
+ if (pressed) {
+ ctx->has_separate_guide_button = true;
+ }
+ SDL_SendJoystickButton(timestamp, joystick, SDL_GAMEPAD_BUTTON_GUIDE, pressed);
+ break;
+ }
+ case MAKE_USAGE(USB_USAGEPAGE_CONSUMER, USB_USAGE_CONSUMER_RECORD):
+ {
+ if (ctx->has_share_button) {
+ bool pressed = (value != 0);
+ SDL_SendJoystickButton(timestamp, joystick, SDL_GAMEPAD_BUTTON_XBOX_SHARE_BUTTON, pressed);
+ }
+ break;
+ }
+ case MAKE_USAGE(USB_USAGEPAGE_CONSUMER, USB_USAGE_CONSUMER_ORDER_MOVIE):
+ {
+ // This value is the currently selected profile
+ ctx->has_unmapped_state = (value == 0);
+ break;
+ }
+ case MAKE_USAGE(USB_USAGEPAGE_CONSUMER, USB_USAGE_CONSUMER_ASSIGN_SELECTION):
+ {
+ if (ctx->has_paddles) {
+ if (!ctx->has_unmapped_state) {
+ value = 0;
+ }
+
+ Uint8 button = (Uint8)(SDL_GAMEPAD_BUTTON_XBOX_SHARE_BUTTON + ctx->has_share_button); // Next available button
+ SDL_SendJoystickButton(timestamp, joystick, button++, ((value & 0x1) != 0));
+ SDL_SendJoystickButton(timestamp, joystick, button++, ((value & 0x2) != 0));
+ SDL_SendJoystickButton(timestamp, joystick, button++, ((value & 0x4) != 0));
+ SDL_SendJoystickButton(timestamp, joystick, button++, ((value & 0x8) != 0));
+ }
+ break;
+ }
+ case MAKE_USAGE(USB_USAGEPAGE_DEVICE_CONTROLS, USB_USAGE_DEVICE_CONTROLS_BATTERY_STRENGTH):
+ {
+ HIDAPI_DriverXboxOne_HandleBatteryState(joystick, value);
+ break;
+ }
+ default:
+ break;
+ }
+ }
+ return true;
+}
+
/*
* The Xbox One Elite controller with 5.13+ firmware sends the unmapped state in a separate packet.
* We can use this to send the paddle state when they aren't mapped
@@ -810,7 +1199,7 @@ static void HIDAPI_DriverXboxOne_HandleStatePacket(SDL_Joystick *joystick, SDL_D
}
}
- axis = ((int)SDL_Swap16LE(*(Sint16 *)(&data[2])) * 64) - 32768;
+ axis = ((int)LOAD16(data[2], data[3]) * 64) - 32768;
if (axis == 32704) {
axis = 32767;
}
@@ -819,7 +1208,7 @@ static void HIDAPI_DriverXboxOne_HandleStatePacket(SDL_Joystick *joystick, SDL_D
}
SDL_SendJoystickAxis(timestamp, joystick, SDL_GAMEPAD_AXIS_LEFT_TRIGGER, axis);
- axis = ((int)SDL_Swap16LE(*(Sint16 *)(&data[4])) * 64) - 32768;
+ axis = ((int)LOAD16(data[4], data[5]) * 64) - 32768;
if (axis == -32768 && size == 26 && (data[18] & 0x40)) {
axis = 32767;
}
@@ -828,13 +1217,13 @@ static void HIDAPI_DriverXboxOne_HandleStatePacket(SDL_Joystick *joystick, SDL_D
}
SDL_SendJoystickAxis(timestamp, joystick, SDL_GAMEPAD_AXIS_RIGHT_TRIGGER, axis);
- axis = SDL_Swap16LE(*(Sint16 *)(&data[6]));
+ axis = LOAD16(data[6], data[7]);
SDL_SendJoystickAxis(timestamp, joystick, SDL_GAMEPAD_AXIS_LEFTX, axis);
- axis = SDL_Swap16LE(*(Sint16 *)(&data[8]));
+ axis = LOAD16(data[8], data[9]);
SDL_SendJoystickAxis(timestamp, joystick, SDL_GAMEPAD_AXIS_LEFTY, ~axis);
- axis = SDL_Swap16LE(*(Sint16 *)(&data[10]));
+ axis = LOAD16(data[10], data[11]);
SDL_SendJoystickAxis(timestamp, joystick, SDL_GAMEPAD_AXIS_RIGHTX, axis);
- axis = SDL_Swap16LE(*(Sint16 *)(&data[12]));
+ axis = LOAD16(data[12], data[13]);
SDL_SendJoystickAxis(timestamp, joystick, SDL_GAMEPAD_AXIS_RIGHTY, ~axis);
SDL_memcpy(ctx->last_state, data, SDL_min(size, sizeof(ctx->last_state)));
@@ -1030,25 +1419,25 @@ static void HIDAPI_DriverXboxOneBluetooth_HandleStatePacket(SDL_Joystick *joysti
SDL_SendJoystickHat(timestamp, joystick, 0, hat);
}
- axis = ((int)SDL_Swap16LE(*(Sint16 *)(&data[9])) * 64) - 32768;
+ axis = ((int)LOAD16(data[9], data[10]) * 64) - 32768;
if (axis == 32704) {
axis = 32767;
}
SDL_SendJoystickAxis(timestamp, joystick, SDL_GAMEPAD_AXIS_LEFT_TRIGGER, axis);
- axis = ((int)SDL_Swap16LE(*(Sint16 *)(&data[11])) * 64) - 32768;
+ axis = ((int)LOAD16(data[11], data[12]) * 64) - 32768;
if (axis == 32704) {
axis = 32767;
}
SDL_SendJoystickAxis(timestamp, joystick, SDL_GAMEPAD_AXIS_RIGHT_TRIGGER, axis);
- axis = (int)SDL_Swap16LE(*(Uint16 *)(&data[1])) - 0x8000;
+ axis = (int)(Uint16)LOAD16(data[1], data[2]) - 0x8000;
SDL_SendJoystickAxis(timestamp, joystick, SDL_GAMEPAD_AXIS_LEFTX, axis);
- axis = (int)SDL_Swap16LE(*(Uint16 *)(&data[3])) - 0x8000;
+ axis = (int)(Uint16)LOAD16(data[3], data[4]) - 0x8000;
SDL_SendJoystickAxis(timestamp, joystick, SDL_GAMEPAD_AXIS_LEFTY, axis);
- axis = (int)SDL_Swap16LE(*(Uint16 *)(&data[5])) - 0x8000;
+ axis = (int)(Uint16)LOAD16(data[5], data[6]) - 0x8000;
SDL_SendJoystickAxis(timestamp, joystick, SDL_GAMEPAD_AXIS_RIGHTX, axis);
- axis = (int)SDL_Swap16LE(*(Uint16 *)(&data[7])) - 0x8000;
+ axis = (int)(Uint16)LOAD16(data[7], data[8]) - 0x8000;
SDL_SendJoystickAxis(timestamp, joystick, SDL_GAMEPAD_AXIS_RIGHTY, axis);
SDL_memcpy(ctx->last_state, data, SDL_min(size, sizeof(ctx->last_state)));
@@ -1064,33 +1453,7 @@ static void HIDAPI_DriverXboxOneBluetooth_HandleGuidePacket(SDL_Joystick *joysti
static void HIDAPI_DriverXboxOneBluetooth_HandleBatteryPacket(SDL_Joystick *joystick, SDL_DriverXboxOne_Context *ctx, const Uint8 *data, int size)
{
- Uint8 flags = data[1];
- bool on_usb = (((flags & 0x0C) >> 2) == 0);
- SDL_PowerState state;
- int percent = 0;
-
- // Mapped percentage value from:
- // https://learn.microsoft.com/en-us/gaming/gdk/_content/gc/reference/input/gameinput/interfaces/igameinputdevice/methods/igameinputdevice_getbatterystate
- switch (flags & 0x03) {
- case 0:
- percent = 10;
- break;
- case 1:
- percent = 40;
- break;
- case 2:
- percent = 70;
- break;
- case 3:
- percent = 100;
- break;
- }
- if (on_usb) {
- state = SDL_POWERSTATE_CHARGING;
- } else {
- state = SDL_POWERSTATE_ON_BATTERY;
- }
- SDL_SendJoystickPowerInfo(joystick, state, percent);
+ HIDAPI_DriverXboxOne_HandleBatteryState(joystick, data[1]);
}
static void HIDAPI_DriverXboxOne_HandleSerialIDPacket(SDL_DriverXboxOne_Context *ctx, const Uint8 *data, int size)
@@ -1586,7 +1949,12 @@ static bool HIDAPI_DriverXboxOne_UpdateDevice(SDL_HIDAPI_Device *device)
#ifdef DEBUG_XBOX_PROTOCOL
HIDAPI_DumpPacket("Xbox One packet: size = %d", data, size);
#endif
- if (device->is_bluetooth) {
+ if (ctx->descriptor) {
+ if (!joystick) {
+ break;
+ }
+ HIDAPI_DriverXboxOne_HandleDescriptorReport(joystick, ctx, data, size);
+ } else if (device->is_bluetooth) {
switch (data[0]) {
case 0x01:
if (!joystick) {
@@ -1645,6 +2013,8 @@ static void HIDAPI_DriverXboxOne_FreeDevice(SDL_HIDAPI_Device *device)
{
SDL_DriverXboxOne_Context *ctx = (SDL_DriverXboxOne_Context *)device->context;
+ SDL_DestroyDescriptor(ctx->descriptor);
+
HIDAPI_GIP_DestroyChunkBuffer(ctx);
}
diff --git a/thirdparty/sdl/joystick/hidapi/SDL_hidapi_zuiki.c b/thirdparty/sdl/joystick/hidapi/SDL_hidapi_zuiki.c
new file mode 100644
index 00000000000..72d79fceb30
--- /dev/null
+++ b/thirdparty/sdl/joystick/hidapi/SDL_hidapi_zuiki.c
@@ -0,0 +1,507 @@
+/*
+ Simple DirectMedia Layer
+ Copyright (C) 1997-2026 Sam Lantinga <[email protected]>
+ Copyright (C) 2025 Zuiki Inc.
+
+ 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"
+
+#ifdef SDL_JOYSTICK_HIDAPI
+
+#include "../SDL_sysjoystick.h"
+#include "SDL_hidapijoystick_c.h"
+#include "SDL_hidapi_rumble.h"
+
+#ifdef SDL_JOYSTICK_HIDAPI_ZUIKI
+
+#define GYRO_SCALE (1024.0f / 32768.0f * SDL_PI_F / 180.0f) // Calculate scaling factor based on gyroscope data range and radians
+#define ACCEL_SCALE (8.0f / 32768.0f * SDL_STANDARD_GRAVITY) // Calculate acceleration scaling factor based on gyroscope data range and standard gravity
+#define FILTER_SIZE 11 // Must be an odd number
+#define MAX_RETRY_COUNT 10 // zuiki device initialization retry count
+
+// Define this if you want to log all packets from the controller
+#if 0
+#define DEBUG_ZUIKI_PROTOCOL
+#endif
+
+typedef struct {
+ float buffer[FILTER_SIZE];
+ uint8_t index;
+ uint8_t count;
+} MedianFilter_t;
+
+typedef struct
+{
+ Uint8 last_state[USB_PACKET_LENGTH];
+ bool sensors_supported; // Sensor enabled status flag
+ Uint64 sensor_timestamp_ns; // Sensor timestamp (nanoseconds, cumulative update)
+ float sensor_rate;
+ MedianFilter_t filter_gyro_x;
+ MedianFilter_t filter_gyro_y;
+ MedianFilter_t filter_gyro_z;
+} SDL_DriverZUIKI_Context;
+
+static float median_filter_update(MedianFilter_t* mf, float input) {
+ mf->buffer[mf->index] = input;
+ mf->index = (mf->index + 1) % FILTER_SIZE;
+ if (mf->count < FILTER_SIZE) mf->count++;
+ float temp[FILTER_SIZE];
+ SDL_memcpy(temp, mf->buffer, sizeof(temp));
+ for (uint8_t i = 0; i < mf->count - 1; i++) {
+ for (uint8_t j = i + 1; j < mf->count; j++) {
+ if (temp[i] > temp[j]) {
+ float t = temp[i];
+ temp[i] = temp[j];
+ temp[j] = t;
+ }
+ }
+ }
+ return temp[mf->count / 2];
+}
+
+
+static void HIDAPI_DriverZUIKI_RegisterHints(SDL_HintCallback callback, void *userdata)
+{
+ SDL_AddHintCallback(SDL_HINT_JOYSTICK_HIDAPI_ZUIKI, callback, userdata);
+}
+
+static void HIDAPI_DriverZUIKI_UnregisterHints(SDL_HintCallback callback, void *userdata)
+{
+ SDL_RemoveHintCallback(SDL_HINT_JOYSTICK_HIDAPI_ZUIKI, callback, userdata);
+}
+
+static bool HIDAPI_DriverZUIKI_IsEnabled(void)
+{
+ return SDL_GetHintBoolean(SDL_HINT_JOYSTICK_HIDAPI_ZUIKI, SDL_GetHintBoolean(SDL_HINT_JOYSTICK_HIDAPI, SDL_HIDAPI_DEFAULT));
+}
+
+static bool HIDAPI_DriverZUIKI_IsSupportedDevice(SDL_HIDAPI_Device *device, const char *name, SDL_GamepadType type, Uint16 vendor_id, Uint16 product_id, Uint16 version, int interface_number, int interface_class, int interface_subclass, int interface_protocol)
+{
+ if (vendor_id == USB_VENDOR_ZUIKI) {
+ switch (product_id) {
+ case USB_PRODUCT_ZUIKI_MASCON_PRO:
+ case USB_PRODUCT_ZUIKI_EVOTOP_UWB_DINPUT:
+ case USB_PRODUCT_ZUIKI_EVOTOP_PC_DINPUT:
+ case USB_PRODUCT_ZUIKI_EVOTOP_PC_BT:
+ case USB_PRODUCT_ZUIKI_EVOTOP_AXIS_DINPUT:
+ return true;
+ default:
+ break;
+ }
+ }
+ return false;
+}
+
+static bool HIDAPI_DriverZUIKI_InitDevice(SDL_HIDAPI_Device *device)
+{
+ Uint8 data[USB_PACKET_LENGTH * 2];
+ SDL_DriverZUIKI_Context *ctx = (SDL_DriverZUIKI_Context *)SDL_calloc(1, sizeof(*ctx));
+ if (!ctx) {
+ return false;
+ }
+ device->context = ctx;
+ ctx->sensors_supported = false;
+
+ // Read report data once for device initialization
+ int size = -1;
+ Uint8 retry_count = 0;
+ while (retry_count < MAX_RETRY_COUNT) {
+ size = SDL_hid_read_timeout(device->dev, data, sizeof(data), 10);
+ if (size > 0) {
+ break;
+ }
+ retry_count++;
+ }
+ if (size <= 0) {
+ return false;
+ }
+
+ switch (device->product_id) {
+ case USB_PRODUCT_ZUIKI_MASCON_PRO:
+ HIDAPI_SetDeviceName(device, "ZUIKI MASCON PRO");
+ break;
+ case USB_PRODUCT_ZUIKI_EVOTOP_PC_DINPUT:
+ ctx->sensors_supported = true;
+ ctx->sensor_rate = 200.0f;
+ break;
+ case USB_PRODUCT_ZUIKI_EVOTOP_UWB_DINPUT:
+ ctx->sensors_supported = true;
+ ctx->sensor_rate = 100.0f;
+ break;
+ case USB_PRODUCT_ZUIKI_EVOTOP_PC_BT:
+ if (size > 0 && data[16] != 0) {
+ ctx->sensors_supported = true;
+ ctx->sensor_rate = 50.0f;
+ }
+ HIDAPI_SetDeviceName(device, "ZUIKI EVOTOP");
+ break;
+ case USB_PRODUCT_ZUIKI_EVOTOP_AXIS_DINPUT:
+ HIDAPI_SetDeviceName(device, "ZUIKI EVOTOP AXIS");
+ break;
+ default:
+ break;
+ }
+
+ return HIDAPI_JoystickConnected(device, NULL);
+}
+
+static int HIDAPI_DriverZUIKI_GetDevicePlayerIndex(SDL_HIDAPI_Device *device, SDL_JoystickID instance_id)
+{
+ return -1;
+}
+
+static void HIDAPI_DriverZUIKI_SetDevicePlayerIndex(SDL_HIDAPI_Device *device, SDL_JoystickID instance_id, int player_index)
+{
+}
+
+#ifndef DEG2RAD
+#define DEG2RAD(x) ((float)(x) * (float)(SDL_PI_F / 180.f))
+#endif
+
+static bool HIDAPI_DriverZUIKI_OpenJoystick(SDL_HIDAPI_Device *device, SDL_Joystick *joystick)
+{
+ SDL_DriverZUIKI_Context *ctx = (SDL_DriverZUIKI_Context *)device->context;
+
+ SDL_AssertJoysticksLocked();
+
+ SDL_zeroa(ctx->last_state);
+
+ joystick->nbuttons = 11;
+ joystick->naxes = SDL_GAMEPAD_AXIS_COUNT;
+ joystick->nhats = 1;
+ if (ctx->sensors_supported) {
+ SDL_PrivateJoystickAddSensor(joystick, SDL_SENSOR_GYRO, ctx->sensor_rate);
+ SDL_PrivateJoystickAddSensor(joystick, SDL_SENSOR_ACCEL, ctx->sensor_rate);
+ }
+
+ return true;
+}
+
+static bool HIDAPI_DriverZUIKI_RumbleJoystick(SDL_HIDAPI_Device *device, SDL_Joystick *joystick, Uint16 low_frequency_rumble, Uint16 high_frequency_rumble)
+{
+ Uint8 rumble_packet[] = { 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00 };
+ rumble_packet[4] = low_frequency_rumble >> 8;
+ rumble_packet[5] = high_frequency_rumble >> 8;
+ if (SDL_HIDAPI_SendRumble(device, rumble_packet, sizeof(rumble_packet)) != sizeof(rumble_packet)) {
+ return SDL_SetError("Couldn't send rumble packet");
+ }
+ return true;
+}
+
+static bool HIDAPI_DriverZUIKI_RumbleJoystickTriggers(SDL_HIDAPI_Device *device, SDL_Joystick *joystick, Uint16 left_rumble, Uint16 right_rumble)
+{
+ return SDL_Unsupported();
+}
+
+static Uint32 HIDAPI_DriverZUIKI_GetJoystickCapabilities(SDL_HIDAPI_Device *device, SDL_Joystick *joystick)
+{
+ Uint32 caps = 0;
+ if (device->product_id != USB_PRODUCT_ZUIKI_EVOTOP_AXIS_DINPUT) {
+ caps |= SDL_JOYSTICK_CAP_RUMBLE;
+ }
+ return caps;
+}
+
+static bool HIDAPI_DriverZUIKI_SetJoystickLED(SDL_HIDAPI_Device *device, SDL_Joystick *joystick, Uint8 red, Uint8 green, Uint8 blue)
+{
+ return SDL_Unsupported();
+}
+
+static bool HIDAPI_DriverZUIKI_SendJoystickEffect(SDL_HIDAPI_Device *device, SDL_Joystick *joystick, const void *data, int size)
+{
+ if (SDL_HIDAPI_SendRumble(device, data, size) != size) {
+ return SDL_SetError("Couldn't send rumble packet");
+ }
+ return true;
+}
+
+static bool HIDAPI_DriverZUIKI_SetJoystickSensorsEnabled(SDL_HIDAPI_Device *device, SDL_Joystick *joystick, bool enabled)
+{
+ SDL_DriverZUIKI_Context *ctx = (SDL_DriverZUIKI_Context *)device->context;
+ if (ctx->sensors_supported) {
+ return true;
+ }
+ return SDL_Unsupported();
+}
+
+static void HIDAPI_DriverZUIKI_HandleOldStatePacket(SDL_Joystick *joystick, SDL_DriverZUIKI_Context *ctx, Uint8 *data, int size)
+{
+ Sint16 axis;
+ Uint64 timestamp = SDL_GetTicksNS();
+
+ if (ctx->last_state[2] != data[2]) {
+ Uint8 hat;
+
+ switch (data[2]) {
+ case 0:
+ hat = SDL_HAT_UP;
+ break;
+ case 1:
+ hat = SDL_HAT_RIGHTUP;
+ break;
+ case 2:
+ hat = SDL_HAT_RIGHT;
+ break;
+ case 3:
+ hat = SDL_HAT_RIGHTDOWN;
+ break;
+ case 4:
+ hat = SDL_HAT_DOWN;
+ break;
+ case 5:
+ hat = SDL_HAT_LEFTDOWN;
+ break;
+ case 6:
+ hat = SDL_HAT_LEFT;
+ break;
+ case 7:
+ hat = SDL_HAT_LEFTUP;
+ break;
+ default:
+ hat = SDL_HAT_CENTERED;
+ break;
+ }
+ SDL_SendJoystickHat(timestamp, joystick, 0, hat);
+ }
+
+ if (ctx->last_state[0] != data[0]) {
+ SDL_SendJoystickButton(timestamp, joystick, SDL_GAMEPAD_BUTTON_NORTH, ((data[0] & 0x01) != 0));
+ SDL_SendJoystickButton(timestamp, joystick, SDL_GAMEPAD_BUTTON_EAST, ((data[0] & 0x02) != 0));
+ SDL_SendJoystickButton(timestamp, joystick, SDL_GAMEPAD_BUTTON_SOUTH, ((data[0] & 0x04) != 0));
+ SDL_SendJoystickButton(timestamp, joystick, SDL_GAMEPAD_BUTTON_WEST, ((data[0] & 0x08) != 0));
+ SDL_SendJoystickButton(timestamp, joystick, SDL_GAMEPAD_BUTTON_LEFT_SHOULDER, ((data[0] & 0x10) != 0));
+ SDL_SendJoystickButton(timestamp, joystick, SDL_GAMEPAD_BUTTON_RIGHT_SHOULDER, ((data[0] & 0x20) != 0));
+ SDL_SendJoystickAxis(timestamp, joystick, SDL_GAMEPAD_AXIS_LEFT_TRIGGER, (data[0] & 0x40) ? SDL_MAX_SINT16 : SDL_MIN_SINT16);
+ SDL_SendJoystickAxis(timestamp, joystick, SDL_GAMEPAD_AXIS_RIGHT_TRIGGER, (data[0] & 0x80) ? SDL_MAX_SINT16 : SDL_MIN_SINT16);
+ }
+
+ if (ctx->last_state[1] != data[1]) {
+ SDL_SendJoystickButton(timestamp, joystick, SDL_GAMEPAD_BUTTON_BACK, ((data[1] & 0x01) != 0));
+ SDL_SendJoystickButton(timestamp, joystick, SDL_GAMEPAD_BUTTON_START, ((data[1] & 0x02) != 0));
+ SDL_SendJoystickButton(timestamp, joystick, SDL_GAMEPAD_BUTTON_LEFT_STICK, ((data[1] & 0x04) != 0));
+ SDL_SendJoystickButton(timestamp, joystick, SDL_GAMEPAD_BUTTON_RIGHT_STICK, ((data[1] & 0x08) != 0));
+ SDL_SendJoystickButton(timestamp, joystick, SDL_GAMEPAD_BUTTON_GUIDE, ((data[1] & 0x10) != 0));
+ SDL_SendJoystickButton(timestamp, joystick, SDL_GAMEPAD_BUTTON_MISC1, ((data[1] & 0x20) != 0));
+ /* todo for switch C key */
+ }
+
+#define READ_STICK_AXIS(offset) \
+ (data[offset] == 0x7f ? 0 : (Sint16)HIDAPI_RemapVal((float)((int)data[offset] - 0x7f), -0x7f, 0xff - 0x7f, SDL_MIN_SINT16, SDL_MAX_SINT16))
+ {
+ axis = READ_STICK_AXIS(3);
+ SDL_SendJoystickAxis(timestamp, joystick, SDL_GAMEPAD_AXIS_LEFTX, axis);
+ axis = READ_STICK_AXIS(4);
+ SDL_SendJoystickAxis(timestamp, joystick, SDL_GAMEPAD_AXIS_LEFTY, axis);
+ axis = READ_STICK_AXIS(5);
+ SDL_SendJoystickAxis(timestamp, joystick, SDL_GAMEPAD_AXIS_RIGHTX, axis);
+ axis = READ_STICK_AXIS(6);
+ SDL_SendJoystickAxis(timestamp, joystick, SDL_GAMEPAD_AXIS_RIGHTY, axis);
+ }
+#undef READ_STICK_AXIS
+
+ if (ctx->sensors_supported) {
+ Uint64 sensor_timestamp = timestamp;
+ float gyro_values[3];
+ gyro_values[0] = median_filter_update(&ctx->filter_gyro_x, LOAD16(data[8], data[9]) * GYRO_SCALE);
+ gyro_values[1] = median_filter_update(&ctx->filter_gyro_y, LOAD16(data[12], data[13]) * GYRO_SCALE);
+ gyro_values[2] = median_filter_update(&ctx->filter_gyro_z, -LOAD16(data[10], data[11]) * GYRO_SCALE);
+ float accel_values[3];
+ accel_values[0] = LOAD16(data[14], data[15]) * ACCEL_SCALE;
+ accel_values[2] = -LOAD16(data[16], data[17]) * ACCEL_SCALE;
+ accel_values[1] = LOAD16(data[18], data[19]) * ACCEL_SCALE;
+#ifdef DEBUG_ZUIKI_PROTOCOL
+ SDL_Log("Gyro raw: %d, %d, %d -> scaled: %.2f, %.2f, %.2f rad/s",
+ LOAD16(data[8], data[9]), LOAD16(data[10], data[11]), LOAD16(data[12], data[13]),
+ gyro_values[0], gyro_values[1], gyro_values[2]);
+ SDL_Log("Accel raw: %d, %d, %d -> scaled: %.2f, %.2f, %.2f m/s²",
+ LOAD16(data[14], data[15]), LOAD16(data[16], data[17]), LOAD16(data[18], data[19]),
+ accel_values[0], accel_values[1], accel_values[2]);
+#endif
+
+ SDL_SendJoystickSensor(timestamp, joystick, SDL_SENSOR_GYRO, sensor_timestamp, gyro_values, 3);
+ SDL_SendJoystickSensor(timestamp, joystick, SDL_SENSOR_ACCEL, sensor_timestamp, accel_values, 3);
+ }
+
+ SDL_memcpy(ctx->last_state, data, SDL_min(size, sizeof(ctx->last_state)));
+}
+
+static void HIDAPI_DriverZUIKI_Handle_EVOTOP_PCBT_StatePacket(SDL_Joystick *joystick, SDL_DriverZUIKI_Context *ctx, Uint8 *data, int size)
+{
+ Sint16 axis;
+ Uint64 timestamp = SDL_GetTicksNS();
+
+ axis = (Sint16)HIDAPI_RemapVal((float)(data[2] << 8 | data[1]), 0x0000, 0xffff, SDL_MIN_SINT16, SDL_MAX_SINT16);
+ SDL_SendJoystickAxis(timestamp, joystick, SDL_GAMEPAD_AXIS_LEFTX, axis);
+ axis = (Sint16)HIDAPI_RemapVal((float)(data[4] << 8 | data[3]), 0x0000, 0xffff, SDL_MIN_SINT16, SDL_MAX_SINT16);
+ SDL_SendJoystickAxis(timestamp, joystick, SDL_GAMEPAD_AXIS_LEFTY, axis);
+ axis = (Sint16)HIDAPI_RemapVal((float)(data[6] << 8 | data[5]), 0x0000, 0xffff, SDL_MIN_SINT16, SDL_MAX_SINT16);
+ SDL_SendJoystickAxis(timestamp, joystick, SDL_GAMEPAD_AXIS_RIGHTX, axis);
+ axis = (Sint16)HIDAPI_RemapVal((float)(data[8] << 8 | data[7]), 0x0000, 0xffff, SDL_MIN_SINT16, SDL_MAX_SINT16);
+ SDL_SendJoystickAxis(timestamp, joystick, SDL_GAMEPAD_AXIS_RIGHTY, axis);
+
+ axis = (Sint16)HIDAPI_RemapVal((float)(data[10] << 8 | data[9]), 0x0000, 0x03ff, SDL_MIN_SINT16, SDL_MAX_SINT16);
+ SDL_SendJoystickAxis(timestamp, joystick, SDL_GAMEPAD_AXIS_LEFT_TRIGGER, axis);
+ axis = (Sint16)HIDAPI_RemapVal((float)(data[12] << 8 | data[11]), 0x0000, 0x03ff, SDL_MIN_SINT16, SDL_MAX_SINT16);
+ SDL_SendJoystickAxis(timestamp, joystick, SDL_GAMEPAD_AXIS_RIGHT_TRIGGER, axis);
+
+ if (ctx->last_state[13] != data[13]) {
+ Uint8 hat;
+ switch (data[13]) {
+ case 1:
+ hat = SDL_HAT_UP;
+ break;
+ case 2:
+ hat = SDL_HAT_RIGHTUP;
+ break;
+ case 3:
+ hat = SDL_HAT_RIGHT;
+ break;
+ case 4:
+ hat = SDL_HAT_RIGHTDOWN;
+ break;
+ case 5:
+ hat = SDL_HAT_DOWN;
+ break;
+ case 6:
+ hat = SDL_HAT_LEFTDOWN;
+ break;
+ case 7:
+ hat = SDL_HAT_LEFT;
+ break;
+ case 8:
+ hat = SDL_HAT_LEFTUP;
+ break;
+ default:
+ hat = SDL_HAT_CENTERED;
+ break;
+ }
+ SDL_SendJoystickHat(timestamp, joystick, 0, hat);
+ }
+ if (ctx->last_state[14] != data[14]) {
+ SDL_SendJoystickButton(timestamp, joystick, SDL_GAMEPAD_BUTTON_SOUTH, ((data[14] & 0x01) != 0));
+ SDL_SendJoystickButton(timestamp, joystick, SDL_GAMEPAD_BUTTON_EAST, ((data[14] & 0x02) != 0));
+ SDL_SendJoystickButton(timestamp, joystick, SDL_GAMEPAD_BUTTON_WEST, ((data[14] & 0x08) != 0));
+ SDL_SendJoystickButton(timestamp, joystick, SDL_GAMEPAD_BUTTON_NORTH, ((data[14] & 0x10) != 0));
+ SDL_SendJoystickButton(timestamp, joystick, SDL_GAMEPAD_BUTTON_LEFT_SHOULDER, ((data[14] & 0x40) != 0));
+ SDL_SendJoystickButton(timestamp, joystick, SDL_GAMEPAD_BUTTON_RIGHT_SHOULDER, ((data[14] & 0x80) != 0));
+ }
+
+ if (ctx->last_state[15] != data[15]) {
+ SDL_SendJoystickButton(timestamp, joystick, SDL_GAMEPAD_BUTTON_BACK, ((data[15] & 0x04) != 0));
+ SDL_SendJoystickButton(timestamp, joystick, SDL_GAMEPAD_BUTTON_START, ((data[15] & 0x08) != 0));
+ SDL_SendJoystickButton(timestamp, joystick, SDL_GAMEPAD_BUTTON_GUIDE, ((data[15] & 0x10) != 0));
+ SDL_SendJoystickButton(timestamp, joystick, SDL_GAMEPAD_BUTTON_LEFT_STICK, ((data[15] & 0x20) != 0));
+ SDL_SendJoystickButton(timestamp, joystick, SDL_GAMEPAD_BUTTON_RIGHT_STICK, ((data[15] & 0x40) != 0));
+ }
+
+ if (ctx->sensors_supported) {
+ Uint64 sensor_timestamp = timestamp;
+ float gyro_values[3];
+ gyro_values[0] = median_filter_update(&ctx->filter_gyro_x, LOAD16(data[17], data[18]) * GYRO_SCALE);
+ gyro_values[1] = median_filter_update(&ctx->filter_gyro_y, LOAD16(data[21], data[22]) * GYRO_SCALE);
+ gyro_values[2] = median_filter_update(&ctx->filter_gyro_z, -LOAD16(data[19], data[20]) * GYRO_SCALE);
+ SDL_SendJoystickSensor(timestamp, joystick, SDL_SENSOR_GYRO, sensor_timestamp, gyro_values, 3);
+ float accel_values[3];
+ accel_values[0] = LOAD16(data[23], data[24]) * ACCEL_SCALE;
+ accel_values[2] = -LOAD16(data[25], data[26]) * ACCEL_SCALE;
+ accel_values[1] = LOAD16(data[27], data[28]) * ACCEL_SCALE;
+ SDL_SendJoystickSensor(timestamp, joystick, SDL_SENSOR_ACCEL, sensor_timestamp, accel_values, 3);
+#ifdef DEBUG_ZUIKI_PROTOCOL
+ SDL_Log("Gyro raw: %d, %d, %d -> scaled: %.2f, %.2f, %.2f rad/s",
+ LOAD16(data[17], data[18]), LOAD16(data[19], data[20]), LOAD16(data[21], data[22]),
+ gyro_values[0], gyro_values[1], gyro_values[2]);
+ SDL_Log("Accel raw: %d, %d, %d -> scaled: %.2f, %.2f, %.2f m/s²",
+ LOAD16(data[23], data[24]), LOAD16(data[25], data[26]), LOAD16(data[27], data[28]),
+ accel_values[0], accel_values[1], accel_values[2]);
+#endif
+ }
+
+ SDL_memcpy(ctx->last_state, data, SDL_min(size, sizeof(ctx->last_state)));
+}
+
+static bool HIDAPI_DriverZUIKI_UpdateDevice(SDL_HIDAPI_Device *device)
+{
+ SDL_DriverZUIKI_Context *ctx = (SDL_DriverZUIKI_Context *)device->context;
+ SDL_Joystick *joystick = NULL;
+ Uint8 data[USB_PACKET_LENGTH];
+ int size = 0;
+
+ if (device->num_joysticks > 0) {
+ joystick = SDL_GetJoystickFromID(device->joysticks[0]);
+ } else {
+ return false;
+ }
+
+ while ((size = SDL_hid_read_timeout(device->dev, data, sizeof(data), 0)) > 0) {
+#ifdef DEBUG_ZUIKI_PROTOCOL
+ HIDAPI_DumpPacket("ZUIKI packet: size = %d", data, size);
+#endif
+ if (!joystick) {
+ continue;
+ }
+
+ if (device->product_id == USB_PRODUCT_ZUIKI_EVOTOP_PC_BT) {
+ HIDAPI_DriverZUIKI_Handle_EVOTOP_PCBT_StatePacket(joystick, ctx, data, size);
+ } else if (device->product_id == USB_PRODUCT_ZUIKI_EVOTOP_PC_DINPUT
+ || device->product_id == USB_PRODUCT_ZUIKI_MASCON_PRO
+ || device->product_id == USB_PRODUCT_ZUIKI_EVOTOP_UWB_DINPUT
+ || device->product_id == USB_PRODUCT_ZUIKI_EVOTOP_AXIS_DINPUT) {
+ HIDAPI_DriverZUIKI_HandleOldStatePacket(joystick, ctx, data, size);
+ }
+ }
+
+ if (size < 0) {
+ // Read error, device is disconnected
+ HIDAPI_JoystickDisconnected(device, device->joysticks[0]);
+ }
+ return (size >= 0);
+}
+
+static void HIDAPI_DriverZUIKI_CloseJoystick(SDL_HIDAPI_Device *device, SDL_Joystick *joystick)
+{
+}
+
+static void HIDAPI_DriverZUIKI_FreeDevice(SDL_HIDAPI_Device *device)
+{
+}
+
+SDL_HIDAPI_DeviceDriver SDL_HIDAPI_DriverZUIKI = {
+ SDL_HINT_JOYSTICK_HIDAPI_ZUIKI,
+ true,
+ HIDAPI_DriverZUIKI_RegisterHints,
+ HIDAPI_DriverZUIKI_UnregisterHints,
+ HIDAPI_DriverZUIKI_IsEnabled,
+ HIDAPI_DriverZUIKI_IsSupportedDevice,
+ HIDAPI_DriverZUIKI_InitDevice,
+ HIDAPI_DriverZUIKI_GetDevicePlayerIndex,
+ HIDAPI_DriverZUIKI_SetDevicePlayerIndex,
+ HIDAPI_DriverZUIKI_UpdateDevice,
+ HIDAPI_DriverZUIKI_OpenJoystick,
+ HIDAPI_DriverZUIKI_RumbleJoystick,
+ HIDAPI_DriverZUIKI_RumbleJoystickTriggers,
+ HIDAPI_DriverZUIKI_GetJoystickCapabilities,
+ HIDAPI_DriverZUIKI_SetJoystickLED,
+ HIDAPI_DriverZUIKI_SendJoystickEffect,
+ HIDAPI_DriverZUIKI_SetJoystickSensorsEnabled,
+ HIDAPI_DriverZUIKI_CloseJoystick,
+ HIDAPI_DriverZUIKI_FreeDevice,
+};
+
+#endif // SDL_JOYSTICK_HIDAPI_ZUIKI
+
+#endif // SDL_JOYSTICK_HIDAPI
diff --git a/thirdparty/sdl/joystick/hidapi/SDL_hidapijoystick.c b/thirdparty/sdl/joystick/hidapi/SDL_hidapijoystick.c
index c7607aeadfa..03895034bd1 100644
--- a/thirdparty/sdl/joystick/hidapi/SDL_hidapijoystick.c
+++ b/thirdparty/sdl/joystick/hidapi/SDL_hidapijoystick.c
@@ -1,6 +1,6 @@
/*
Simple DirectMedia Layer
- Copyright (C) 1997-2025 Sam Lantinga <[email protected]>
+ Copyright (C) 1997-2026 Sam Lantinga <[email protected]>
This software is provided 'as-is', without any express or implied
warranty. In no event will the authors be held liable for any damages
@@ -70,11 +70,17 @@ static SDL_HIDAPI_DeviceDriver *SDL_HIDAPI_drivers[] = {
#ifdef SDL_JOYSTICK_HIDAPI_STEAMDECK
&SDL_HIDAPI_DriverSteamDeck,
#endif
+#ifdef SDL_JOYSTICK_HIDAPI_STEAMDECK
+ &SDL_HIDAPI_DriverSteamTriton,
+#endif
#ifdef SDL_JOYSTICK_HIDAPI_SWITCH
&SDL_HIDAPI_DriverNintendoClassic,
&SDL_HIDAPI_DriverJoyCons,
&SDL_HIDAPI_DriverSwitch,
#endif
+#ifdef SDL_JOYSTICK_HIDAPI_SWITCH2
+ &SDL_HIDAPI_DriverSwitch2,
+#endif
#ifdef SDL_JOYSTICK_HIDAPI_WII
&SDL_HIDAPI_DriverWii,
#endif
@@ -82,9 +88,27 @@ static SDL_HIDAPI_DeviceDriver *SDL_HIDAPI_drivers[] = {
&SDL_HIDAPI_DriverXbox360,
&SDL_HIDAPI_DriverXbox360W,
#endif
+#ifdef SDL_JOYSTICK_HIDAPI_GIP
+ &SDL_HIDAPI_DriverGIP,
+#endif
#ifdef SDL_JOYSTICK_HIDAPI_XBOXONE
&SDL_HIDAPI_DriverXboxOne,
#endif
+#ifdef SDL_JOYSTICK_HIDAPI_LG4FF
+ &SDL_HIDAPI_DriverLg4ff,
+#endif
+#ifdef SDL_JOYSTICK_HIDAPI_8BITDO
+ &SDL_HIDAPI_Driver8BitDo,
+#endif
+#ifdef SDL_JOYSTICK_HIDAPI_FLYDIGI
+ &SDL_HIDAPI_DriverFlydigi,
+#endif
+#ifdef SDL_JOYSTICK_HIDAPI_SINPUT
+ &SDL_HIDAPI_DriverSInput,
+#endif
+#ifdef SDL_JOYSTICK_HIDAPI_ZUIKI
+ &SDL_HIDAPI_DriverZUIKI,
+#endif
};
static int SDL_HIDAPI_numdrivers = 0;
static SDL_AtomicInt SDL_HIDAPI_updating_devices;
@@ -133,7 +157,7 @@ void HIDAPI_DumpPacket(const char *prefix, const Uint8 *data, int size)
current_len += SDL_snprintf(&buffer[current_len], length - current_len, " 0x%.2x", data[i]);
}
SDL_strlcat(buffer, "\n", length);
- SDL_Log("%s", buffer);
+ SDL_LogDebug(SDL_LOG_CATEGORY_INPUT, "%s", buffer);
SDL_free(buffer);
}
@@ -147,8 +171,12 @@ bool HIDAPI_SupportsPlaystationDetection(Uint16 vendor, Uint16 product)
}
switch (vendor) {
+ case USB_VENDOR_CRKD:
+ return true;
case USB_VENDOR_DRAGONRISE:
return true;
+ case USB_VENDOR_CORSAIR:
+ return true;
case USB_VENDOR_HORI:
return true;
case USB_VENDOR_LOGITECH:
@@ -187,6 +215,8 @@ bool HIDAPI_SupportsPlaystationDetection(Uint16 vendor, Uint16 product)
* https://github.com/libsdl-org/SDL/issues/6799
*/
return false;
+ case USB_VENDOR_RED_OCTANE_GAMES:
+ return true;
case USB_VENDOR_SHANWAN:
return true;
case USB_VENDOR_SHANWAN_ALT:
@@ -235,6 +265,7 @@ static SDL_GamepadType SDL_GetJoystickGameControllerProtocol(const char *name, U
static const int SUPPORTED_VENDORS[] = {
0x0079, // GPD Win 2
+ 0x0351, // CRKD
0x044f, // Thrustmaster
0x045e, // Microsoft
0x046d, // Logitech
@@ -245,7 +276,9 @@ static SDL_GamepadType SDL_GetJoystickGameControllerProtocol(const char *name, U
0x0e6f, // PDP
0x0f0d, // Hori
0x1038, // SteelSeries
+ 0x10f5, // Turtle Beach
0x11c9, // Nacon
+ 0x1209, // Generic
0x12ab, // Unknown
0x1430, // RedOctane
0x146b, // BigBen
@@ -259,6 +292,10 @@ static SDL_GamepadType SDL_GetJoystickGameControllerProtocol(const char *name, U
0x24c6, // PowerA
0x2c22, // Qanba
0x2dc8, // 8BitDo
+ 0x3537, // GameSir
+ 0x3651, // CRKD
+ 0x37d7, // Flydigi
+ 0x3958, // Red Octane Games
0x9886, // ASTRO Gaming
};
@@ -277,6 +314,7 @@ static SDL_GamepadType SDL_GetJoystickGameControllerProtocol(const char *name, U
interface_protocol == XBONE_IFACE_PROTOCOL) {
static const int SUPPORTED_VENDORS[] = {
+ 0x0351, // CRKD
0x03f0, // HP
0x044f, // Thrustmaster
0x045e, // Microsoft
@@ -285,12 +323,19 @@ static SDL_GamepadType SDL_GetJoystickGameControllerProtocol(const char *name, U
0x0e6f, // PDP
0x0f0d, // Hori
0x10f5, // Turtle Beach
+ 0x1209, // Generic
0x1532, // Razer
0x20d6, // PowerA
0x24c6, // PowerA
+ 0x294b, // Snakebyte
0x2dc8, // 8BitDo
0x2e24, // Hyperkin
+ 0x2e95, // SCUF
+ 0x3285, // Nacon
0x3537, // GameSir
+ 0x3651, // CRKD
+ 0x366c, // ByoWave
+ 0x3958, // Red Octane Games
};
int i;
@@ -338,7 +383,7 @@ static SDL_HIDAPI_DeviceDriver *HIDAPI_GetDeviceDriver(SDL_HIDAPI_Device *device
return NULL;
}
- if (device->vendor_id != USB_VENDOR_VALVE) {
+ if (device->vendor_id != USB_VENDOR_VALVE && device->vendor_id != USB_VENDOR_FLYDIGI_V1 && device->vendor_id != USB_VENDOR_FLYDIGI_V2) {
if (device->usage_page && device->usage_page != USAGE_PAGE_GENERIC_DESKTOP) {
return NULL;
}
@@ -430,7 +475,9 @@ static void HIDAPI_SetupDeviceDriver(SDL_HIDAPI_Device *device, bool *removed) S
if (device->driver) {
bool enabled;
- if (device->vendor_id == USB_VENDOR_NINTENDO && device->product_id == USB_PRODUCT_NINTENDO_SWITCH_JOYCON_PAIR) {
+ if (device->vendor_id == USB_VENDOR_NINTENDO &&
+ (device->product_id == USB_PRODUCT_NINTENDO_SWITCH_JOYCON_PAIR ||
+ device->product_id == USB_PRODUCT_NINTENDO_SWITCH2_JOYCON_PAIR)) {
enabled = SDL_HIDAPI_combine_joycons;
} else {
enabled = device->driver->enabled;
@@ -864,14 +911,19 @@ static SDL_HIDAPI_Device *HIDAPI_AddDevice(const struct SDL_hid_device_info *inf
for (curr = SDL_HIDAPI_devices, last = NULL; curr; last = curr, curr = curr->next) {
}
+ char *path = SDL_strdup(info->path);
+ if (!path) {
+ SDL_OutOfMemory();
+ return NULL;
+ }
+
device = (SDL_HIDAPI_Device *)SDL_calloc(1, sizeof(*device));
if (!device) {
+ SDL_free(path);
return NULL;
}
SDL_SetObjectValid(device, SDL_OBJECT_TYPE_HIDAPI_JOYSTICK, true);
- if (info->path) {
- device->path = SDL_strdup(info->path);
- }
+ device->path = path;
device->seen = true;
device->vendor_id = info->vendor_id;
device->product_id = info->product_id;
@@ -1046,7 +1098,11 @@ static bool HIDAPI_CreateCombinedJoyCons(void)
SDL_zero(info);
info.path = "nintendo_joycons_combined";
info.vendor_id = USB_VENDOR_NINTENDO;
- info.product_id = USB_PRODUCT_NINTENDO_SWITCH_JOYCON_PAIR;
+ if (joycons[0]->product_id == USB_PRODUCT_NINTENDO_SWITCH_JOYCON_LEFT) {
+ info.product_id = USB_PRODUCT_NINTENDO_SWITCH_JOYCON_PAIR;
+ } else {
+ info.product_id = USB_PRODUCT_NINTENDO_SWITCH2_JOYCON_PAIR;
+ }
info.interface_number = -1;
info.usage_page = USB_USAGEPAGE_GENERIC_DESKTOP;
info.usage = USB_USAGE_GENERIC_GAMEPAD;
@@ -1099,6 +1155,11 @@ static void HIDAPI_UpdateDeviceList(void)
devs = SDL_hid_enumerate(0, 0);
if (devs) {
for (info = devs; info; info = info->next) {
+ if (!info->path) {
+ // We can't open this, ignore it
+ continue;
+ }
+
device = HIDAPI_GetJoystickByInfo(info->path, info->vendor_id, info->product_id);
if (device) {
device->seen = true;
@@ -1274,6 +1335,16 @@ bool HIDAPI_IsDevicePresent(Uint16 vendor_id, Uint16 product_id, Uint16 version,
*/
SDL_LockJoysticks();
for (device = SDL_HIDAPI_devices; device; device = device->next) {
+ // The HIDAPI functionality will be available when the FlyDigi Space Station app has
+ // enabled third party controller mapping, so the driver needs to be active to watch
+ // for that change. Since this is dynamic and we don't have a way to re-trigger device
+ // changes when that happens, we'll pretend the driver isn't available so the XInput
+ // interface will always show up (but won't have any input when the controller is in
+ // enhanced mode)
+ if (device->vendor_id == USB_VENDOR_FLYDIGI_V2 && device->driver == &SDL_HIDAPI_DriverFlydigi) {
+ continue;
+ }
+
if (device->driver &&
HIDAPI_IsEquivalentToDevice(vendor_id, product_id, device)) {
result = true;
diff --git a/thirdparty/sdl/joystick/hidapi/SDL_hidapijoystick_c.h b/thirdparty/sdl/joystick/hidapi/SDL_hidapijoystick_c.h
index 9cd9f400651..6129441881a 100644
--- a/thirdparty/sdl/joystick/hidapi/SDL_hidapijoystick_c.h
+++ b/thirdparty/sdl/joystick/hidapi/SDL_hidapijoystick_c.h
@@ -1,6 +1,6 @@
/*
Simple DirectMedia Layer
- Copyright (C) 1997-2025 Sam Lantinga <[email protected]>
+ Copyright (C) 1997-2026 Sam Lantinga <[email protected]>
This software is provided 'as-is', without any express or implied
warranty. In no event will the authors be held liable for any damages
@@ -35,11 +35,21 @@
#define SDL_JOYSTICK_HIDAPI_STEAM
#define SDL_JOYSTICK_HIDAPI_STEAMDECK
#define SDL_JOYSTICK_HIDAPI_SWITCH
+#ifdef HAVE_LIBUSB
+#define SDL_JOYSTICK_HIDAPI_SWITCH2
+#endif
#define SDL_JOYSTICK_HIDAPI_WII
#define SDL_JOYSTICK_HIDAPI_XBOX360
#define SDL_JOYSTICK_HIDAPI_XBOXONE
#define SDL_JOYSTICK_HIDAPI_SHIELD
#define SDL_JOYSTICK_HIDAPI_STEAM_HORI
+#define SDL_JOYSTICK_HIDAPI_STEAM_TRITON
+#define SDL_JOYSTICK_HIDAPI_LG4FF
+#define SDL_JOYSTICK_HIDAPI_8BITDO
+#define SDL_JOYSTICK_HIDAPI_FLYDIGI
+#define SDL_JOYSTICK_HIDAPI_GIP
+#define SDL_JOYSTICK_HIDAPI_SINPUT
+#define SDL_JOYSTICK_HIDAPI_ZUIKI
// Joystick capability definitions
#define SDL_JOYSTICK_CAP_MONO_LED 0x00000001
@@ -139,6 +149,7 @@ typedef struct SDL_HIDAPI_DeviceDriver
// HIDAPI device support
extern SDL_HIDAPI_DeviceDriver SDL_HIDAPI_DriverCombined;
extern SDL_HIDAPI_DeviceDriver SDL_HIDAPI_DriverGameCube;
+extern SDL_HIDAPI_DeviceDriver SDL_HIDAPI_DriverGIP;
extern SDL_HIDAPI_DeviceDriver SDL_HIDAPI_DriverJoyCons;
extern SDL_HIDAPI_DeviceDriver SDL_HIDAPI_DriverLuna;
extern SDL_HIDAPI_DeviceDriver SDL_HIDAPI_DriverNintendoClassic;
@@ -152,11 +163,24 @@ extern SDL_HIDAPI_DeviceDriver SDL_HIDAPI_DriverStadia;
extern SDL_HIDAPI_DeviceDriver SDL_HIDAPI_DriverSteam;
extern SDL_HIDAPI_DeviceDriver SDL_HIDAPI_DriverSteamDeck;
extern SDL_HIDAPI_DeviceDriver SDL_HIDAPI_DriverSwitch;
+extern SDL_HIDAPI_DeviceDriver SDL_HIDAPI_DriverSwitch2;
extern SDL_HIDAPI_DeviceDriver SDL_HIDAPI_DriverWii;
extern SDL_HIDAPI_DeviceDriver SDL_HIDAPI_DriverXbox360;
extern SDL_HIDAPI_DeviceDriver SDL_HIDAPI_DriverXbox360W;
extern SDL_HIDAPI_DeviceDriver SDL_HIDAPI_DriverXboxOne;
extern SDL_HIDAPI_DeviceDriver SDL_HIDAPI_DriverSteamHori;
+extern SDL_HIDAPI_DeviceDriver SDL_HIDAPI_DriverSteamTriton;
+extern SDL_HIDAPI_DeviceDriver SDL_HIDAPI_DriverLg4ff;
+extern SDL_HIDAPI_DeviceDriver SDL_HIDAPI_Driver8BitDo;
+extern SDL_HIDAPI_DeviceDriver SDL_HIDAPI_DriverFlydigi;
+extern SDL_HIDAPI_DeviceDriver SDL_HIDAPI_DriverSInput;
+extern SDL_HIDAPI_DeviceDriver SDL_HIDAPI_DriverZUIKI;
+
+#define LOAD16(A, B) (Sint16)((Uint16)(A) | (((Uint16)(B)) << 8))
+#define LOAD32(A, B, C, D) ((((Uint32)(A)) << 0) | \
+ (((Uint32)(B)) << 8) | \
+ (((Uint32)(C)) << 16) | \
+ (((Uint32)(D)) << 24))
// Return true if a HID device is present and supported as a joystick of the given type
extern bool HIDAPI_IsDeviceTypePresent(SDL_GamepadType type);
diff --git a/thirdparty/sdl/joystick/hidapi/SDL_report_descriptor.c b/thirdparty/sdl/joystick/hidapi/SDL_report_descriptor.c
new file mode 100644
index 00000000000..f5155832e4a
--- /dev/null
+++ b/thirdparty/sdl/joystick/hidapi/SDL_report_descriptor.c
@@ -0,0 +1,616 @@
+/*
+ Simple DirectMedia Layer
+ Copyright (C) 1997-2026 Sam Lantinga <[email protected]>
+
+ 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"
+
+#include "SDL_report_descriptor.h"
+
+// This is a very simple (and non-compliant!) report descriptor parser
+// used to quickly parse Xbox Bluetooth reports
+
+typedef enum
+{
+ DescriptorItemTypeMain = 0,
+ DescriptorItemTypeGlobal = 1,
+ DescriptorItemTypeLocal = 2,
+ DescriptorItemTypeReserved = 3,
+} ItemType;
+
+typedef enum
+{
+ MainTagInput = 0x8,
+ MainTagOutput = 0x9,
+ MainTagFeature = 0xb,
+ MainTagCollection = 0xa,
+ MainTagEndCollection = 0xc,
+} MainTag;
+
+typedef enum
+{
+ MainFlagConstant = 0x0001,
+ MainFlagVariable = 0x0002,
+ MainFlagRelative = 0x0004,
+ MainFlagWrap = 0x0008,
+ MainFlagNonLinear = 0x0010,
+ MainFlagNoPreferred = 0x0020,
+ MainFlagNullState = 0x0040,
+ MainFlagVolatile = 0x0080,
+ MainFlagBufferedBytes = 0x0100,
+} MainFlag;
+
+typedef enum
+{
+ GlobalTagUsagePage = 0x0,
+ GlobalTagLogicalMinimum = 0x1,
+ GlobalTagLogicalMaximum = 0x2,
+ GlobalTagPhysicalMinimum = 0x3,
+ GlobalTagPhysicalMaximum = 0x4,
+ GlobalTagUnitExponent = 0x5,
+ GlobalTagUnit = 0x6,
+ GlobalTagReportSize = 0x7,
+ GlobalTagReportID = 0x8,
+ GlobalTagReportCount = 0x9,
+ GlobalTagPush = 0xa,
+ GlobalTagPop = 0xb,
+} GlobalTag;
+
+typedef enum
+{
+ LocalTagUsage = 0x0,
+ LocalTagUsageMinimum = 0x1,
+ LocalTagUsageMaximum = 0x2,
+ LocalTagDesignatorIndex = 0x3,
+ LocalTagDesignatorMinimum = 0x4,
+ LocalTagDesignatorMaximum = 0x5,
+ LocalTagStringIndex = 0x7,
+ LocalTagStringMinimum = 0x8,
+ LocalTagStringMaximum = 0x9,
+ LocalTagDelimiter = 0xa,
+} LocalTag;
+
+typedef struct
+{
+ Uint32 usage_page;
+ Uint32 report_size;
+ Uint32 report_count;
+ Uint32 report_id;
+} DescriptorGlobalState;
+
+typedef struct
+{
+ Uint32 usage_minimum;
+ Uint32 usage_maximum;
+ int usage_maxcount;
+ int usage_count;
+ Uint32 *usages;
+} DescriptorLocalState;
+
+typedef struct
+{
+ int collection_depth;
+ DescriptorGlobalState global;
+ DescriptorLocalState local;
+ int field_maxcount;
+ int field_count;
+ int field_offset;
+ DescriptorInputField *fields;
+} DescriptorContext;
+
+static void DebugDescriptor(DescriptorContext *ctx, const char *fmt, ...)
+{
+#ifdef DEBUG_DESCRIPTOR
+ va_list ap;
+ va_start(ap, fmt);
+ char *message = NULL;
+ SDL_vasprintf(&message, fmt, ap);
+ va_end(ap);
+ if (ctx->collection_depth > 0) {
+ size_t len = 4 * ctx->collection_depth + SDL_strlen(message) + 1;
+ char *output = (char *)SDL_malloc(len);
+ if (output) {
+ SDL_memset(output, ' ', 4 * ctx->collection_depth);
+ output[4 * ctx->collection_depth] = '\0';
+ SDL_strlcat(output, message, len);
+ SDL_free(message);
+ message = output;
+ }
+ }
+ SDL_Log("%s", message);
+ SDL_free(message);
+#endif // DEBUG_DESCRIPTOR
+}
+
+static void DebugMainTag(DescriptorContext *ctx, const char *tag, Uint32 flags)
+{
+#ifdef DEBUG_DESCRIPTOR
+ char message[1024] = { 0 };
+
+ SDL_strlcat(message, tag, sizeof(message));
+ SDL_strlcat(message, "(", sizeof(message));
+ if (flags & MainFlagConstant) {
+ SDL_strlcat(message, " Constant", sizeof(message));
+ } else {
+ SDL_strlcat(message, " Data", sizeof(message));
+ }
+ if (flags & MainFlagVariable) {
+ SDL_strlcat(message, " Variable", sizeof(message));
+ } else {
+ SDL_strlcat(message, " Array", sizeof(message));
+ }
+ if (flags & MainFlagRelative) {
+ SDL_strlcat(message, " Relative", sizeof(message));
+ } else {
+ SDL_strlcat(message, " Absolute", sizeof(message));
+ }
+ if (flags & MainFlagWrap) {
+ SDL_strlcat(message, " Wrap", sizeof(message));
+ } else {
+ SDL_strlcat(message, " No Wrap", sizeof(message));
+ }
+ if (flags & MainFlagNonLinear) {
+ SDL_strlcat(message, " Non Linear", sizeof(message));
+ } else {
+ SDL_strlcat(message, " Linear", sizeof(message));
+ }
+ if (flags & MainFlagNoPreferred) {
+ SDL_strlcat(message, " No Preferred", sizeof(message));
+ } else {
+ SDL_strlcat(message, " Preferred State", sizeof(message));
+ }
+ if (flags & MainFlagNullState) {
+ SDL_strlcat(message, " Null State", sizeof(message));
+ } else {
+ SDL_strlcat(message, " No Null Position", sizeof(message));
+ }
+ if (flags & MainFlagVolatile) {
+ SDL_strlcat(message, " Volatile", sizeof(message));
+ } else {
+ SDL_strlcat(message, " Non Volatile", sizeof(message));
+ }
+ if (flags & MainFlagBufferedBytes) {
+ SDL_strlcat(message, " Buffered Bytes", sizeof(message));
+ } else {
+ SDL_strlcat(message, " Bit Field", sizeof(message));
+ }
+ SDL_strlcat(message, " )", sizeof(message));
+
+ DebugDescriptor(ctx, "%s", message);
+
+#endif // DEBUG_DESCRIPTOR
+}
+
+static Uint32 ReadValue(const Uint8 *data, int size)
+{
+ Uint32 value = 0;
+
+ int shift = 0;
+ while (size--) {
+ value |= ((Uint32)(*data++)) << shift;
+ shift += 8;
+ }
+ return value;
+}
+
+static void ResetLocalState(DescriptorContext *ctx)
+{
+ ctx->local.usage_minimum = 0;
+ ctx->local.usage_maximum = 0;
+ ctx->local.usage_count = 0;
+}
+
+static bool AddUsage(DescriptorContext *ctx, Uint32 usage)
+{
+ if (ctx->local.usage_count == ctx->local.usage_maxcount) {
+ int usage_maxcount = ctx->local.usage_maxcount + 4;
+ Uint32 *usages = (Uint32 *)SDL_realloc(ctx->local.usages, usage_maxcount * sizeof(*usages));
+ if (!usages) {
+ return false;
+ }
+ ctx->local.usages = usages;
+ ctx->local.usage_maxcount = usage_maxcount;
+ }
+
+ if (usage <= 0xFFFF) {
+ usage |= (ctx->global.usage_page << 16);
+ }
+ ctx->local.usages[ctx->local.usage_count++] = usage;
+ return true;
+}
+
+static bool AddInputField(DescriptorContext *ctx, Uint32 usage, int bit_size)
+{
+ if (ctx->field_count == ctx->field_maxcount) {
+ int field_maxcount = ctx->field_maxcount + 4;
+ DescriptorInputField *fields = (DescriptorInputField *)SDL_realloc(ctx->fields, field_maxcount * sizeof(*fields));
+ if (!fields) {
+ return false;
+ }
+ ctx->fields = fields;
+ ctx->field_maxcount = field_maxcount;
+ }
+
+ DescriptorInputField *field = &ctx->fields[ctx->field_count++];
+ field->report_id = (Uint8)ctx->global.report_id;
+ field->usage = usage;
+ field->bit_offset = ctx->field_offset;
+ field->bit_size = bit_size;
+
+ DebugDescriptor(ctx, "Adding report %d field 0x%.8x size %d bits at bit offset %d", field->report_id, field->usage, field->bit_size, field->bit_offset);
+ return true;
+}
+
+static bool AddInputFields(DescriptorContext *ctx)
+{
+ Uint32 usage = 0;
+
+ if (ctx->global.report_count == 0 || ctx->global.report_size == 0) {
+ return true;
+ }
+
+ if (ctx->local.usage_count == 0 &&
+ ctx->local.usage_minimum > 0 &&
+ ctx->local.usage_maximum >= ctx->local.usage_minimum) {
+ for (usage = ctx->local.usage_minimum; usage <= ctx->local.usage_maximum; ++usage) {
+ if (!AddUsage(ctx, usage)) {
+ return false;
+ }
+ }
+ }
+
+ int usage_index = 0;
+ for (Uint32 i = 0; i < ctx->global.report_count; ++i) {
+ if (usage_index < ctx->local.usage_count) {
+ usage = ctx->local.usages[usage_index];
+ if (usage_index < (ctx->local.usage_count - 1)) {
+ ++usage_index;
+ }
+ }
+
+ int size = (int)ctx->global.report_size;
+ if (usage > 0) {
+ if (!AddInputField(ctx, usage, size)) {
+ return false;
+ }
+ }
+ ctx->field_offset += size;
+ }
+ return true;
+}
+
+static bool ParseMainItem(DescriptorContext *ctx, int tag, int size, const Uint8 *data)
+{
+ Uint32 flags;
+
+ switch (tag) {
+ case MainTagInput:
+ flags = ReadValue(data, size);
+ DebugMainTag(ctx, "MainTagInput", flags);
+ AddInputFields(ctx);
+ break;
+ case MainTagOutput:
+ flags = ReadValue(data, size);
+ DebugMainTag(ctx, "MainTagOutput", flags);
+ break;
+ case MainTagFeature:
+ flags = ReadValue(data, size);
+ DebugMainTag(ctx, "MainTagFeature", flags);
+ break;
+ case MainTagCollection:
+ DebugDescriptor(ctx, "MainTagCollection");
+ switch (*data) {
+ case 0x00:
+ DebugDescriptor(ctx, "Physical");
+ break;
+ case 0x01:
+ DebugDescriptor(ctx, "Application");
+ break;
+ case 0x02:
+ DebugDescriptor(ctx, "Logical");
+ break;
+ case 0x03:
+ DebugDescriptor(ctx, "Report");
+ break;
+ case 0x04:
+ DebugDescriptor(ctx, "Named Array");
+ break;
+ case 0x05:
+ DebugDescriptor(ctx, "Usage Switch");
+ break;
+ case 0x06:
+ DebugDescriptor(ctx, "Usage Modifier");
+ break;
+ default:
+ break;
+ }
+ ++ctx->collection_depth;
+ break;
+ case MainTagEndCollection:
+ if (ctx->collection_depth > 0) {
+ --ctx->collection_depth;
+ }
+ DebugDescriptor(ctx, "MainTagEndCollection");
+ break;
+ default:
+ DebugDescriptor(ctx, "Unknown main tag: %d", tag);
+ break;
+ }
+
+ ResetLocalState(ctx);
+
+ return true;
+}
+
+static bool ParseGlobalItem(DescriptorContext *ctx, int tag, int size, const Uint8 *data)
+{
+ Uint32 value;
+
+ switch (tag) {
+ case GlobalTagUsagePage:
+ ctx->global.usage_page = ReadValue(data, size);
+ DebugDescriptor(ctx, "GlobalTagUsagePage: 0x%.4x", ctx->global.usage_page);
+ break;
+ case GlobalTagLogicalMinimum:
+ value = ReadValue(data, size);
+ DebugDescriptor(ctx, "GlobalTagLogicalMinimum: %u", value);
+ break;
+ case GlobalTagLogicalMaximum:
+ value = ReadValue(data, size);
+ DebugDescriptor(ctx, "GlobalTagLogicalMaximum: %u", value);
+ break;
+ case GlobalTagPhysicalMinimum:
+ value = ReadValue(data, size);
+ DebugDescriptor(ctx, "GlobalTagPhysicalMinimum: %u", value);
+ break;
+ case GlobalTagPhysicalMaximum:
+ value = ReadValue(data, size);
+ DebugDescriptor(ctx, "GlobalTagPhysicalMaximum: %u", value);
+ break;
+ case GlobalTagUnitExponent:
+ DebugDescriptor(ctx, "GlobalTagUnitExponent");
+ break;
+ case GlobalTagUnit:
+ DebugDescriptor(ctx, "GlobalTagUnit");
+ break;
+ case GlobalTagReportSize:
+ ctx->global.report_size = ReadValue(data, size);
+ DebugDescriptor(ctx, "GlobalTagReportSize: %u", ctx->global.report_size);
+ break;
+ case GlobalTagReportID:
+ ctx->global.report_id = ReadValue(data, size);
+ ctx->field_offset = 0;
+ DebugDescriptor(ctx, "GlobalTagReportID: %u", ctx->global.report_id);
+ break;
+ case GlobalTagReportCount:
+ ctx->global.report_count = ReadValue(data, size);
+ DebugDescriptor(ctx, "GlobalTagReportCount: %u", ctx->global.report_count);
+ break;
+ case GlobalTagPush:
+ DebugDescriptor(ctx, "GlobalTagPush");
+ break;
+ case GlobalTagPop:
+ DebugDescriptor(ctx, "GlobalTagPop");
+ break;
+ default:
+ DebugDescriptor(ctx, "Unknown global tag");
+ break;
+ }
+ return true;
+}
+
+static bool ParseLocalItem(DescriptorContext *ctx, int tag, int size, const Uint8 *data)
+{
+ Uint32 value;
+
+ switch (tag) {
+ case LocalTagUsage:
+ value = ReadValue(data, size);
+ AddUsage(ctx, value);
+ DebugDescriptor(ctx, "LocalTagUsage: 0x%.4x", value);
+ break;
+ case LocalTagUsageMinimum:
+ ctx->local.usage_minimum = ReadValue(data, size);
+ DebugDescriptor(ctx, "LocalTagUsageMinimum: 0x%.4x", ctx->local.usage_minimum);
+ break;
+ case LocalTagUsageMaximum:
+ ctx->local.usage_maximum = ReadValue(data, size);
+ DebugDescriptor(ctx, "LocalTagUsageMaximum: 0x%.4x", ctx->local.usage_maximum);
+ break;
+ case LocalTagDesignatorIndex:
+ DebugDescriptor(ctx, "LocalTagDesignatorIndex");
+ break;
+ case LocalTagDesignatorMinimum:
+ DebugDescriptor(ctx, "LocalTagDesignatorMinimum");
+ break;
+ case LocalTagDesignatorMaximum:
+ DebugDescriptor(ctx, "LocalTagDesignatorMaximum");
+ break;
+ case LocalTagStringIndex:
+ DebugDescriptor(ctx, "LocalTagStringIndex");
+ break;
+ case LocalTagStringMinimum:
+ DebugDescriptor(ctx, "LocalTagStringMinimum");
+ break;
+ case LocalTagStringMaximum:
+ DebugDescriptor(ctx, "LocalTagStringMaximum");
+ break;
+ case LocalTagDelimiter:
+ DebugDescriptor(ctx, "LocalTagDelimiter");
+ break;
+ default:
+ DebugDescriptor(ctx, "Unknown local tag");
+ break;
+ }
+ return true;
+}
+
+static bool ParseDescriptor(DescriptorContext *ctx, const Uint8 *descriptor, int descriptor_size)
+{
+ SDL_zerop(ctx);
+
+ for (const Uint8 *here = descriptor; here < descriptor + descriptor_size; ) {
+ static const int sizes[4] = { 0, 1, 2, 4 };
+ Uint8 data = *here++;
+ int size = sizes[(data & 0x3)];
+ int type = ((data >> 2) & 0x3);
+ int tag = (data >> 4);
+
+ if ((here + size) > (descriptor + descriptor_size)) {
+ return SDL_SetError("Invalid descriptor");
+ }
+
+#ifdef DEBUG_DESCRIPTOR
+ SDL_Log("Data: 0x%.2x, size: %d, type: %d, tag: %d", data, size, type, tag);
+#endif
+ switch (type) {
+ case DescriptorItemTypeMain:
+ if (!ParseMainItem(ctx, tag, size, here)) {
+ return false;
+ }
+ break;
+ case DescriptorItemTypeGlobal:
+ if (!ParseGlobalItem(ctx, tag, size, here)) {
+ return false;
+ }
+ break;
+ case DescriptorItemTypeLocal:
+ if (!ParseLocalItem(ctx, tag, size, here)) {
+ return false;
+ }
+ break;
+ case DescriptorItemTypeReserved:
+ // Long items are currently unsupported
+ return SDL_Unsupported();
+ }
+
+ here += size;
+ }
+ return true;
+}
+
+static void CleanupContext(DescriptorContext *ctx)
+{
+ SDL_free(ctx->local.usages);
+ SDL_free(ctx->fields);
+}
+
+SDL_ReportDescriptor *SDL_ParseReportDescriptor(const Uint8 *descriptor, int descriptor_size)
+{
+ SDL_ReportDescriptor *result = NULL;
+
+ DescriptorContext ctx;
+ if (ParseDescriptor(&ctx, descriptor, descriptor_size)) {
+ result = (SDL_ReportDescriptor *)SDL_malloc(sizeof(*result));
+ if (result) {
+ result->field_count = ctx.field_count;
+ result->fields = ctx.fields;
+ ctx.fields = NULL;
+ }
+ }
+ CleanupContext(&ctx);
+
+ return result;
+}
+
+bool SDL_DescriptorHasUsage(SDL_ReportDescriptor *descriptor, Uint16 usage_page, Uint16 usage)
+{
+ if (!descriptor) {
+ return false;
+ }
+
+ Uint32 full_usage = (((Uint32)usage_page << 16) | usage);
+ for (int i = 0; i < descriptor->field_count; ++i) {
+ if (descriptor->fields[i].usage == full_usage) {
+ return true;
+ }
+ }
+ return false;
+}
+
+void SDL_DestroyDescriptor(SDL_ReportDescriptor *descriptor)
+{
+ if (descriptor) {
+ SDL_free(descriptor->fields);
+ SDL_free(descriptor);
+ }
+}
+
+bool SDL_ReadReportData(const Uint8 *data, int size, int bit_offset, int bit_size, Uint32 *value)
+{
+ int offset = (bit_offset / 8);
+ if (offset >= size) {
+ *value = 0;
+ return SDL_SetError("Out of bounds reading report data");
+ }
+
+ *value = ReadValue(data + offset, (bit_size + 7) / 8);
+
+ int shift = (bit_offset % 8);
+ if (shift > 0) {
+ *value >>= shift;
+ }
+
+ switch (bit_size) {
+ case 1:
+ *value &= 0x1;
+ break;
+ case 4:
+ *value &= 0xf;
+ break;
+ case 10:
+ *value &= 0x3ff;
+ break;
+ case 15:
+ *value &= 0x7fff;
+ break;
+ default:
+ SDL_assert((bit_size % 8) == 0);
+ break;
+ }
+ return true;
+}
+
+#ifdef TEST_MAIN
+
+#include <SDL3/SDL_main.h>
+
+int main(int argc, char *argv[])
+{
+ const char *file = argv[1];
+ if (argc < 2) {
+ SDL_Log("Usage: %s file", argv[0]);
+ return 1;
+ }
+
+ size_t descriptor_size = 0;
+ Uint8 *descriptor = SDL_LoadFile(argv[1], &descriptor_size);
+ if (!descriptor) {
+ SDL_Log("Couldn't load %s: %s", argv[1], SDL_GetError());
+ return 2;
+ }
+
+ DescriptorContext ctx;
+ if (!ParseDescriptor(&ctx, descriptor, descriptor_size)) {
+ SDL_Log("Couldn't parse %s: %s", argv[1], SDL_GetError());
+ return 3;
+ }
+ return 0;
+}
+
+#endif // TEST_MAIN
diff --git a/thirdparty/sdl/joystick/hidapi/SDL_report_descriptor.h b/thirdparty/sdl/joystick/hidapi/SDL_report_descriptor.h
new file mode 100644
index 00000000000..3e21f8ba1a3
--- /dev/null
+++ b/thirdparty/sdl/joystick/hidapi/SDL_report_descriptor.h
@@ -0,0 +1,40 @@
+/*
+ Simple DirectMedia Layer
+ Copyright (C) 1997-2026 Sam Lantinga <[email protected]>
+
+ 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"
+
+typedef struct
+{
+ Uint8 report_id;
+ Uint32 usage;
+ int bit_offset;
+ int bit_size;
+} DescriptorInputField;
+
+typedef struct
+{
+ int field_count;
+ DescriptorInputField *fields;
+} SDL_ReportDescriptor;
+
+extern SDL_ReportDescriptor *SDL_ParseReportDescriptor(const Uint8 *descriptor, int descriptor_size);
+extern bool SDL_DescriptorHasUsage(SDL_ReportDescriptor *descriptor, Uint16 usage_page, Uint16 usage);
+extern void SDL_DestroyDescriptor(SDL_ReportDescriptor *descriptor);
+extern bool SDL_ReadReportData(const Uint8 *data, int size, int bit_offset, int bit_size, Uint32 *value);
diff --git a/thirdparty/sdl/joystick/hidapi/steam/controller_constants.h b/thirdparty/sdl/joystick/hidapi/steam/controller_constants.h
index 78af0164b8d..e838a8924ad 100644
--- a/thirdparty/sdl/joystick/hidapi/steam/controller_constants.h
+++ b/thirdparty/sdl/joystick/hidapi/steam/controller_constants.h
@@ -353,7 +353,7 @@ enum GamepadButtons
// Mode adjust
enum ModeAdjustModes
{
- MODE_ADJUST_SENSITITY=1,
+ MODE_ADJUST_SENSITIVITY=1,
MODE_ADJUST_LEFT_PAD_SECONDARY_MODE,
MODE_ADJUST_RIGHT_PAD_SECONDARY_MODE,
MODE_ADJUST_COUNT
@@ -364,8 +364,8 @@ typedef enum
{
ATTRIB_UNIQUE_ID,
ATTRIB_PRODUCT_ID,
- ATTRIB_PRODUCT_REVISON, // deprecated
- ATTRIB_CAPABILITIES = ATTRIB_PRODUCT_REVISON, // intentional aliasing
+ ATTRIB_PRODUCT_REVISION, // deprecated
+ ATTRIB_CAPABILITIES = ATTRIB_PRODUCT_REVISION, // intentional aliasing
ATTRIB_FIRMWARE_VERSION, // deprecated
ATTRIB_FIRMWARE_BUILD_TIME,
ATTRIB_RADIO_FIRMWARE_BUILD_TIME,
@@ -411,6 +411,12 @@ typedef enum {
TRACKPAD_NUM_MODES
} TrackpadDPadMode;
+typedef enum
+{
+ LIZARD_MODE_OFF,
+ LIZARD_MODE_ON,
+} LizardModeState_t;
+
// Read-write controller settings (only add to this enum and never change the order)
typedef enum
{
@@ -423,7 +429,7 @@ typedef enum
SETTING_USB_DEBUG_MODE,
SETTING_LEFT_TRACKPAD_MODE,
SETTING_RIGHT_TRACKPAD_MODE,
- SETTING_MOUSE_POINTER_ENABLED,
+ SETTING_LIZARD_MODE,
// 10
SETTING_DPAD_DEADZONE,
@@ -579,4 +585,4 @@ typedef enum
}
#endif
-#endif // _CONTROLLER_CONSTANTS_H
+#endif // _CONTROLLER_CONSTANTS_
diff --git a/thirdparty/sdl/joystick/hidapi/steam/controller_structs.h b/thirdparty/sdl/joystick/hidapi/steam/controller_structs.h
index ea2a3522509..69c10ed689f 100644
--- a/thirdparty/sdl/joystick/hidapi/steam/controller_structs.h
+++ b/thirdparty/sdl/joystick/hidapi/steam/controller_structs.h
@@ -112,7 +112,7 @@ typedef struct {
int16_t dur_ms; // Duration of tone / rumble (if applicable) (neg = infinite)
uint16_t noise_intensity;
- uint16_t lfo_freq; // Drives both tone and rumble geneators
+ uint16_t lfo_freq; // Drives both tone and rumble generators
uint8_t lfo_depth; // percentage, typically 100
uint8_t rand_tone_gain; // Randomize each LFO cycle's gain
uint8_t script_id; // Used w/ dBgain for scripted haptics
@@ -154,6 +154,99 @@ typedef struct
} FeatureReportMsg;
+// Triton and derivatives utilize output reports for haptic commands. This is a
+// snapshot from Nov 2024 -- things may change.
+
+// Triton Output Report Lengths #defs include +1 for the OR ID
+
+// Output Report Haptic Messages for Triton
+typedef struct
+{
+ uint8_t type;
+ uint16_t intensity;
+ struct
+ {
+ uint16_t speed;
+ int8_t gain;
+ } left, right;
+} MsgHapticRumble;
+#define HID_RUMBLE_OUTPUT_REPORT_BYTES 10
+
+
+typedef struct
+{
+ uint8_t side;
+ uint16_t on_us;
+ uint16_t off_us;
+ uint16_t repeat_count;
+} MsgHapticPulse;
+#define HID_HAPTIC_PULSE_OUTPUT_REPORT_BYTES 8
+
+typedef struct
+{
+ uint8_t side;
+ uint8_t command;
+ int8_t gain_db;
+} MsgHapticCommand;
+#define HID_HAPTIC_COMMAND_REPORT_BYTES 4
+
+typedef struct
+{
+ uint8_t side;
+ int8_t gain_db;
+ uint16_t frequency;
+ uint16_t duration_ms;
+ uint16_t lfo_freq;
+ uint8_t lfo_depth;
+} MsgHapticLfoTone;
+#define HID_HAPTIC_LFO_TONE_REPORT_BYTES 10
+
+typedef struct
+{
+ uint8_t side;
+ int8_t gain_db;
+ uint16_t duration_ms;
+ struct
+ {
+ uint16_t frequency;
+ } start, end;
+} MsgHapticLogSweep;
+#define HID_HAPTIC_LOG_SWEEP_REPORT_BYTES 9
+
+typedef struct m
+{
+ uint8_t side;
+ uint8_t script_id;
+ int8_t gain_db;
+} MsgHapticScript;
+#define HID_HAPTIC_SCRIPT_REPORT_BYTES 4
+
+typedef enum
+{
+ ID_OUT_REPORT_HAPTIC_RUMBLE = 0x80,
+ ID_OUT_REPORT_HAPTIC_PULSE = 0x81,
+ ID_OUT_REPORT_HAPTIC_COMMAND = 0x82,
+ ID_OUT_REPORT_HAPTIC_LFO_TONE = 0x83,
+ ID_OUT_REPORT_HAPTIC_LOG_SWEEP = 0x84,
+ ID_OUT_REPORT_HAPTIC_SCRIPT = 0x85,
+} ValveTritonOutReportMessageIDs;
+
+typedef struct
+{
+ uint8_t report_id;
+ union
+ {
+ MsgHapticRumble hapticRumble;
+ MsgHapticPulse hapticPulse;
+ MsgHapticCommand hapticCommand;
+ MsgHapticLfoTone hapticLfoTone;
+ MsgHapticLogSweep hapticLogSweep;
+ MsgHapticScript hapticScript;
+ } payload;
+
+} OutputReportMsg;
+
+
// Roll this version forward anytime that you are breaking compatibility of existing
// message types within ValveInReport_t or the header itself. Hopefully this should
// be super rare and instead you should just add new message payloads to the union,
@@ -261,7 +354,7 @@ typedef struct
short sRightPadX;
short sRightPadY;
- //This mimcs how the dongle reconstitutes HID packets, there will be 0-4 shorts depending on gyro mode
+ //This mimics how the dongle reconstitutes HID packets, there will be 0-4 shorts depending on gyro mode
unsigned char ucGyroDataType; //TODO could maybe find some unused bits in the button field for this info (is only 2bits)
short sGyro[4];
@@ -413,51 +506,201 @@ typedef struct
unsigned short sPressurePadRight;
} SteamDeckStatePacket_t;
+
typedef struct
{
- ValveInReportHeader_t header;
-
- union
- {
- ValveControllerStatePacket_t controllerState;
- ValveControllerBLEStatePacket_t controllerBLEState;
- ValveControllerDebugPacket_t debugState;
- ValveControllerTrackpadImage_t padImage;
- ValveControllerRawTrackpadImage_t rawPadImage;
- SteamControllerWirelessEvent_t wirelessEvent;
- SteamControllerStatusEvent_t statusEvent;
- SteamDeckStatePacket_t deckState;
- } payload;
-
-} ValveInReport_t;
+ ValveInReportHeader_t header;
+
+ union
+ {
+ ValveControllerStatePacket_t controllerState;
+ ValveControllerBLEStatePacket_t controllerBLEState;
+ ValveControllerDebugPacket_t debugState;
+ ValveControllerTrackpadImage_t padImage;
+ ValveControllerRawTrackpadImage_t rawPadImage;
+ SteamControllerWirelessEvent_t wirelessEvent;
+ SteamControllerStatusEvent_t statusEvent;
+ SteamDeckStatePacket_t deckState;
+ } payload;
+} ValveInReport_t;
-// Enumeration for BLE packet protocol
enum EBLEPacketReportNums
{
- // Skipping past 2-3 because they are escape characters in Uart protocol
- k_EBLEReportState = 4,
- k_EBLEReportStatus = 5,
+ k_EBLEReportState = 4,
+ k_EBLEReportStatus = 5,
};
-
-
// Enumeration of data chunks in BLE state packets
enum EBLEOptionDataChunksBitmask
{
- // First byte upper nibble
- k_EBLEButtonChunk1 = 0x10,
- k_EBLEButtonChunk2 = 0x20,
- k_EBLEButtonChunk3 = 0x40,
- k_EBLELeftJoystickChunk = 0x80,
-
- // Second full byte
- k_EBLELeftTrackpadChunk = 0x100,
- k_EBLERightTrackpadChunk = 0x200,
- k_EBLEIMUAccelChunk = 0x400,
- k_EBLEIMUGyroChunk = 0x800,
- k_EBLEIMUQuatChunk = 0x1000,
+ // First byte upper nibble
+ k_EBLEButtonChunk1 = 0x10,
+ k_EBLEButtonChunk2 = 0x20,
+ k_EBLEButtonChunk3 = 0x40,
+ k_EBLELeftJoystickChunk = 0x80,
+
+ // Second full byte
+ k_EBLELeftTrackpadChunk = 0x100,
+ k_EBLERightTrackpadChunk = 0x200,
+ k_EBLEIMUAccelChunk = 0x400,
+ k_EBLEIMUGyroChunk = 0x800,
+ k_EBLEIMUQuatChunk = 0x1000,
+};
+
+// Triton and derivatives do not use the ValveInReport_t structure
+
+enum ETritonReportIDTypes
+{
+ ID_TRITON_CONTROLLER_STATE = 0x42,
+ ID_TRITON_BATTERY_STATUS = 0x43,
+ ID_TRITON_CONTROLLER_STATE_BLE = 0x45,
+ ID_TRITON_WIRELESS_STATUS_X = 0x46,
+ ID_TRITON_CONTROLLER_STATE_TIMESTAMP = 0x47,
+
+ ID_TRITON_WIRELESS_STATUS = 0x79,
+};
+
+enum ETritonWirelessState
+{
+ k_ETritonWirelessStateDisconnect = 1,
+ k_ETritonWirelessStateConnect = 2,
+};
+
+typedef struct
+{
+ uint32_t timestamp;
+ short sAccelX;
+ short sAccelY;
+ short sAccelZ;
+
+ short sGyroX;
+ short sGyroY;
+ short sGyroZ;
+
+ short sGyroQuatW;
+ short sGyroQuatX;
+ short sGyroQuatY;
+ short sGyroQuatZ;
+} TritonMTUIMU_t;
+
+typedef struct {
+ uint32_t timestamp;
+ short sAccelX;
+ short sAccelY;
+ short sAccelZ;
+
+ short sGyroX;
+ short sGyroY;
+ short sGyroZ;
+} TritonMTUIMUNoQuat_t;
+
+typedef struct
+{
+ uint16_t timestamp;
+ short sAccelX;
+ short sAccelY;
+ short sAccelZ;
+
+ short sGyroX;
+ short sGyroY;
+ short sGyroZ;
+} TritonMTUIMUNoQuat32usTS_t;
+
+typedef struct
+{
+ uint8_t seq_num;
+ uint32_t buttons;
+ short sTriggerLeft;
+ short sTriggerRight;
+
+ short sLeftStickX;
+ short sLeftStickY;
+ short sRightStickX;
+ short sRightStickY;
+
+ short sLeftPadX;
+ short sLeftPadY;
+ unsigned short unPressureLeft;
+
+ short sRightPadX;
+ short sRightPadY;
+ unsigned short unPressureRight;
+ TritonMTUIMU_t imu;
+} TritonMTUFull_t;
+
+typedef struct {
+ uint8_t seq_num;
+ uint32_t buttons;
+ short sTriggerLeft;
+ short sTriggerRight;
+
+ short sLeftStickX;
+ short sLeftStickY;
+ short sRightStickX;
+ short sRightStickY;
+
+ short sLeftPadX;
+ short sLeftPadY;
+ unsigned short unPressureLeft;
+
+ short sRightPadX;
+ short sRightPadY;
+ unsigned short unPressureRight;
+ TritonMTUIMUNoQuat_t imu;
+} TritonMTUNoQuat_t;
+
+// New Ibex packet that adds a timestamp to the trackpad sampling
+// and reduces the size of the IMU timestamp. Timestamps are now 16 bits
+typedef struct
+{
+ uint8_t seq_num;
+ uint32_t buttons;
+ short sTriggerLeft;
+ short sTriggerRight;
+
+ short sLeftStickX;
+ short sLeftStickY;
+ short sRightStickX;
+ short sRightStickY;
+
+ unsigned short unTrackpadTimestamp;
+ short sLeftPadX;
+ short sLeftPadY;
+ unsigned short unPressureLeft;
+
+ short sRightPadX;
+ short sRightPadY;
+ unsigned short unPressureRight;
+
+ TritonMTUIMUNoQuat32usTS_t imu;
+} TritonMTUNoQuat32TS_t;
+
+enum EChargeState
+{
+ k_EChargeStateReset,
+ k_EChargeStateDischarging,
+ k_EChargeStateCharging,
+ k_EChargeStateSrcValidate,
+ k_EChargeStateChargingDone,
};
+typedef struct
+{
+ unsigned char ucChargeState; // EChargeState
+ unsigned char ucBatteryLevel;
+ unsigned short sBatteryVoltage;
+ unsigned short sSystemVoltage;
+ unsigned short sInputVoltage;
+ unsigned short sCurrent;
+ unsigned short sInputCurrent;
+ unsigned short sTemperature;
+} TritonBatteryStatus_t;
+
+typedef struct
+{
+ unsigned char state;
+} TritonWirelessStatus_t;
+
#pragma pack()
-#endif // _CONTROLLER_STRUCTS
+#endif // _CONTROLLER_STRUCTS_
diff --git a/thirdparty/sdl/joystick/linux/SDL_sysjoystick.c b/thirdparty/sdl/joystick/linux/SDL_sysjoystick.c
index 4f86bc8a858..ede0d5efdc9 100644
--- a/thirdparty/sdl/joystick/linux/SDL_sysjoystick.c
+++ b/thirdparty/sdl/joystick/linux/SDL_sysjoystick.c
@@ -1,6 +1,6 @@
/*
Simple DirectMedia Layer
- Copyright (C) 1997-2025 Sam Lantinga <[email protected]>
+ Copyright (C) 1997-2026 Sam Lantinga <[email protected]>
This software is provided 'as-is', without any express or implied
warranty. In no event will the authors be held liable for any damages
@@ -75,6 +75,18 @@
#ifndef BTN_DPAD_RIGHT
#define BTN_DPAD_RIGHT 0x223
#endif
+#ifndef BTN_GRIPL
+#define BTN_GRIPL 0x224
+#endif
+#ifndef BTN_GRIPR
+#define BTN_GRIPR 0x225
+#endif
+#ifndef BTN_GRIPL2
+#define BTN_GRIPL2 0x226
+#endif
+#ifndef BTN_GRIPR2
+#define BTN_GRIPR2 0x227
+#endif
#ifndef BTN_TRIGGER_HAPPY
#define BTN_TRIGGER_HAPPY 0x2c0
@@ -153,6 +165,7 @@ typedef struct SDL_joylist_item
Uint16 vendor;
Uint16 product;
char *name; // "SideWinder 3D Pro" or whatever
+ char *driver; // "xpad" or whatever
SDL_GUID guid;
dev_t devnum;
int steam_virtual_gamepad_slot;
@@ -276,19 +289,20 @@ static bool GuessIsSensor(int fd)
return false;
}
-static bool IsJoystick(const char *path, int *fd, char **name_return, Uint16 *vendor_return, Uint16 *product_return, SDL_GUID *guid)
+static bool IsJoystick(const char *path, int *fd, char **name_return, Uint16 *vendor_return, Uint16 *product_return, SDL_GUID *guid, char **driver_return)
{
struct input_id inpid;
- char *name;
+ char *name = NULL;
+ char *driver = NULL;
char product_string[128];
int class = 0;
SDL_zero(inpid);
#ifdef SDL_USE_LIBUDEV
// Opening input devices can generate synchronous device I/O, so avoid it if we can
- if (SDL_UDEV_GetProductInfo(path, &inpid.vendor, &inpid.product, &inpid.version, &class) &&
+ if (SDL_UDEV_GetProductInfo(path, &inpid, &class, &driver) &&
!(class & SDL_UDEV_DEVICE_JOYSTICK)) {
- return false;
+ goto error;
}
#endif
@@ -296,34 +310,33 @@ static bool IsJoystick(const char *path, int *fd, char **name_return, Uint16 *ve
*fd = open(path, O_RDONLY | O_CLOEXEC, 0);
}
if (!fd || *fd < 0) {
- return false;
+ goto error;
}
if (ioctl(*fd, JSIOCGNAME(sizeof(product_string)), product_string) <= 0) {
// When udev enumeration or classification, we only got joysticks here, so no need to test
if (enumeration_method != ENUMERATION_LIBUDEV && !class && !GuessIsJoystick(*fd)) {
- return false;
+ goto error;
}
// Could have vendor and product already from udev, but should agree with evdev
if (ioctl(*fd, EVIOCGID, &inpid) < 0) {
- return false;
+ goto error;
}
if (ioctl(*fd, EVIOCGNAME(sizeof(product_string)), product_string) < 0) {
- return false;
+ goto error;
}
}
name = SDL_CreateJoystickName(inpid.vendor, inpid.product, NULL, product_string);
if (!name) {
- return false;
+ goto error;
}
if (!IsVirtualJoystick(inpid.vendor, inpid.product, inpid.version, name) &&
SDL_JoystickHandledByAnotherDriver(&SDL_LINUX_JoystickDriver, inpid.vendor, inpid.product, inpid.version, name)) {
- SDL_free(name);
- return false;
+ goto error;
}
FixupDeviceInfoForMapping(*fd, &inpid);
@@ -333,14 +346,19 @@ static bool IsJoystick(const char *path, int *fd, char **name_return, Uint16 *ve
#endif
if (SDL_ShouldIgnoreJoystick(inpid.vendor, inpid.product, inpid.version, name)) {
- SDL_free(name);
- return false;
+ goto error;
}
*name_return = name;
+ *driver_return = driver;
*vendor_return = inpid.vendor;
*product_return = inpid.product;
*guid = SDL_CreateJoystickGUID(inpid.bustype, inpid.vendor, inpid.product, inpid.version, NULL, product_string, 0, 0);
return true;
+
+error:
+ SDL_free(driver);
+ SDL_free(name);
+ return false;
}
static bool IsSensor(const char *path, int *fd)
@@ -351,7 +369,7 @@ static bool IsSensor(const char *path, int *fd)
SDL_zero(inpid);
#ifdef SDL_USE_LIBUDEV
// Opening input devices can generate synchronous device I/O, so avoid it if we can
- if (SDL_UDEV_GetProductInfo(path, &inpid.vendor, &inpid.product, &inpid.version, &class) &&
+ if (SDL_UDEV_GetProductInfo(path, &inpid, &class, NULL) &&
!(class & SDL_UDEV_DEVICE_ACCELEROMETER)) {
return false;
}
@@ -424,6 +442,7 @@ static void FreeJoylistItem(SDL_joylist_item *item)
SDL_free(item->mapping);
SDL_free(item->path);
SDL_free(item->name);
+ SDL_free(item->driver);
SDL_free(item);
}
@@ -438,6 +457,7 @@ static void MaybeAddDevice(const char *path)
struct stat sb;
int fd = -1;
char *name = NULL;
+ char *driver = NULL;
Uint16 vendor, product;
SDL_GUID guid;
SDL_joylist_item *item;
@@ -475,7 +495,7 @@ static void MaybeAddDevice(const char *path)
SDL_Log("Checking %s", path);
#endif
- if (IsJoystick(path, &fd, &name, &vendor, &product, &guid)) {
+ if (IsJoystick(path, &fd, &name, &vendor, &product, &guid, &driver)) {
#ifdef DEBUG_INPUT_EVENTS
SDL_Log("found joystick: %s", path);
#endif
@@ -492,6 +512,7 @@ static void MaybeAddDevice(const char *path)
item->product = product;
item->name = name;
item->guid = guid;
+ item->driver = driver;
if (vendor == USB_VENDOR_VALVE &&
product == USB_PRODUCT_STEAM_VIRTUAL_GAMEPAD) {
@@ -865,7 +886,7 @@ static void LINUX_ScanSteamVirtualGamepads(void)
// Opening input devices can generate synchronous device I/O, so avoid it if we can
class = 0;
SDL_zero(inpid);
- if (SDL_UDEV_GetProductInfo(path, &inpid.vendor, &inpid.product, &inpid.version, &class) &&
+ if (SDL_UDEV_GetProductInfo(path, &inpid, &class, NULL) &&
(inpid.vendor != USB_VENDOR_VALVE || inpid.product != USB_PRODUCT_STEAM_VIRTUAL_GAMEPAD)) {
free(entries[i]); // This should NOT be SDL_free()
continue;
@@ -952,7 +973,7 @@ static void LINUX_JoystickDetect(void)
{
#ifdef SDL_USE_LIBUDEV
if (enumeration_method == ENUMERATION_LIBUDEV) {
- SDL_UDEV_Poll();
+ // Polling will happen in the main event loop
} else
#endif
#ifdef HAVE_INOTIFY
@@ -1140,6 +1161,8 @@ static SDL_JoystickID LINUX_JoystickGetDeviceInstanceID(int device_index)
static bool allocate_balldata(SDL_Joystick *joystick)
{
+ SDL_AssertJoysticksLocked();
+
joystick->hwdata->balls =
(struct hwdata_ball *)SDL_calloc(joystick->nballs, sizeof(struct hwdata_ball));
if (joystick->hwdata->balls == NULL) {
@@ -1516,7 +1539,7 @@ static SDL_sensorlist_item *GetSensor(SDL_joylist_item *item)
return NULL;
}
- SDL_memset(uniq_item, 0, sizeof(uniq_item));
+ SDL_zeroa(uniq_item);
fd_item = open(item->path, O_RDONLY | O_CLOEXEC, 0);
if (fd_item < 0) {
return NULL;
@@ -1538,7 +1561,7 @@ static SDL_sensorlist_item *GetSensor(SDL_joylist_item *item)
continue;
}
- SDL_memset(uniq_sensor, 0, sizeof(uniq_sensor));
+ SDL_zeroa(uniq_sensor);
fd_sensor = open(item_sensor->path, O_RDONLY | O_CLOEXEC, 0);
if (fd_sensor < 0) {
continue;
@@ -1591,12 +1614,9 @@ static bool LINUX_JoystickOpen(SDL_Joystick *joystick, int device_index)
item_sensor->hwdata = joystick->hwdata;
}
- #ifdef SDL_USE_LIBUDEV
- const char *serial = NULL;
- if (SDL_UDEV_GetProductSerial(item->path, &serial)) {
- joystick->serial = SDL_strdup(serial);
- }
- #endif
+#ifdef SDL_USE_LIBUDEV
+ joystick->serial = SDL_UDEV_GetProductSerial(item->path);
+#endif
// mark joystick as fresh and ready
joystick->hwdata->fresh = true;
@@ -1758,6 +1778,8 @@ static void HandleHat(Uint64 timestamp, SDL_Joystick *stick, int hatidx, int axi
static void HandleBall(SDL_Joystick *stick, Uint8 ball, int axis, int value)
{
+ SDL_AssertJoysticksLocked();
+
stick->hwdata->balls[ball].axis[axis] += value;
}
@@ -2064,7 +2086,7 @@ static void HandleInputEvents(SDL_Joystick *joystick)
if (code == MSC_TIMESTAMP) {
Sint32 tick = event->value;
Sint32 delta;
- if (joystick->hwdata->last_tick < tick) {
+ if (joystick->hwdata->last_tick <= tick) {
delta = (tick - joystick->hwdata->last_tick);
} else {
delta = (SDL_MAX_SINT32 - joystick->hwdata->last_tick + tick + 1);
@@ -2276,6 +2298,12 @@ static bool LINUX_JoystickGetGamepadMapping(int device_index, SDL_GamepadMapping
MAPPED_DPAD_LEFT = 0x4,
MAPPED_DPAD_RIGHT = 0x8,
MAPPED_DPAD_ALL = 0xF,
+
+ MAPPED_LEFT_PADDLE1 = 0x1,
+ MAPPED_RIGHT_PADDLE1 = 0x2,
+ MAPPED_LEFT_PADDLE2 = 0x4,
+ MAPPED_RIGHT_PADDLE2 = 0x8,
+ MAPPED_PADDLE_ALL = 0xF,
};
unsigned int mapped;
bool result = false;
@@ -2641,6 +2669,27 @@ static bool LINUX_JoystickGetGamepadMapping(int device_index, SDL_GamepadMapping
SDL_Log("Mapped DPUP+DOWN to axis %d (ABS_HAT0Y)", out->dpup.target);
SDL_Log("Mapped DPLEFT+RIGHT to axis %d (ABS_HAT0X)", out->dpleft.target);
#endif
+ } else if (item->driver && SDL_strcmp(item->driver, "xpad") == 0) {
+ // xpad will sometimes map the D-Pad as BTN_TRIGGER_HAPPY1 - BTN_TRIGGER_HAPPY4
+ if (joystick->hwdata->has_key[BTN_TRIGGER_HAPPY1] &&
+ joystick->hwdata->has_key[BTN_TRIGGER_HAPPY2] &&
+ joystick->hwdata->has_key[BTN_TRIGGER_HAPPY3] &&
+ joystick->hwdata->has_key[BTN_TRIGGER_HAPPY4]) {
+ out->dpleft.kind = EMappingKind_Button;
+ out->dpright.kind = EMappingKind_Button;
+ out->dpup.kind = EMappingKind_Button;
+ out->dpdown.kind = EMappingKind_Button;
+ out->dpleft.target = joystick->hwdata->key_map[BTN_TRIGGER_HAPPY1];
+ out->dpright.target = joystick->hwdata->key_map[BTN_TRIGGER_HAPPY2];
+ out->dpup.target = joystick->hwdata->key_map[BTN_TRIGGER_HAPPY3];
+ out->dpdown.target = joystick->hwdata->key_map[BTN_TRIGGER_HAPPY4];
+#ifdef DEBUG_GAMEPAD_MAPPING
+ SDL_Log("Mapped DPLEFT to button %d (BTN_TRIGGER_HAPPY1)", out->dpleft.target);
+ SDL_Log("Mapped DPRIGHT to button %d (BTN_TRIGGER_HAPPY2)", out->dpright.target);
+ SDL_Log("Mapped DPUP to button %d (BTN_TRIGGER_HAPPY3)", out->dpup.target);
+ SDL_Log("Mapped DPDOWN to button %d (BTN_TRIGGER_HAPPY4)", out->dpdown.target);
+#endif
+ }
}
}
@@ -2685,8 +2734,44 @@ static bool LINUX_JoystickGetGamepadMapping(int device_index, SDL_GamepadMapping
#endif
}
- if (SDL_GetJoystickVendor(joystick) == USB_VENDOR_MICROSOFT) {
+ mapped = 0;
+
+ if (joystick->hwdata->has_key[BTN_GRIPR]) {
+ out->right_paddle1.kind = EMappingKind_Button;
+ out->right_paddle1.target = joystick->hwdata->key_map[BTN_GRIPR];
+ mapped |= MAPPED_RIGHT_PADDLE1;
+#ifdef DEBUG_GAMEPAD_MAPPING
+ SDL_Log("Mapped RIGHT_PADDLE1 to button %d (BTN_GRIPR)", out->right_paddle1.target);
+#endif
+ }
+ if (joystick->hwdata->has_key[BTN_GRIPL]) {
+ out->left_paddle1.kind = EMappingKind_Button;
+ out->left_paddle1.target = joystick->hwdata->key_map[BTN_GRIPL];
+ mapped |= MAPPED_LEFT_PADDLE1;
+#ifdef DEBUG_GAMEPAD_MAPPING
+ SDL_Log("Mapped LEFT_PADDLE1 to button %d (BTN_GRIPL)", out->left_paddle1.target);
+#endif
+ }
+ if (joystick->hwdata->has_key[BTN_GRIPR2]) {
+ out->right_paddle2.kind = EMappingKind_Button;
+ out->right_paddle2.target = joystick->hwdata->key_map[BTN_GRIPR2];
+ mapped |= MAPPED_RIGHT_PADDLE2;
+#ifdef DEBUG_GAMEPAD_MAPPING
+ SDL_Log("Mapped RIGHT_PADDLE2 to button %d (BTN_GRIPR)", out->right_paddle2.target);
+#endif
+ }
+ if (joystick->hwdata->has_key[BTN_GRIPL2]) {
+ out->left_paddle2.kind = EMappingKind_Button;
+ out->left_paddle2.target = joystick->hwdata->key_map[BTN_GRIPL2];
+ mapped |= MAPPED_LEFT_PADDLE2;
+#ifdef DEBUG_GAMEPAD_MAPPING
+ SDL_Log("Mapped LEFT_PADDLE2 to button %d (BTN_GRIPL2)", out->left_paddle2.target);
+#endif
+ }
+
+ if (mapped != MAPPED_PADDLE_ALL && SDL_GetJoystickVendor(joystick) == USB_VENDOR_MICROSOFT) {
// The Xbox Elite controllers have the paddles as BTN_TRIGGER_HAPPY5 - BTN_TRIGGER_HAPPY8
+ // in older drivers
if (joystick->hwdata->has_key[BTN_TRIGGER_HAPPY5] &&
joystick->hwdata->has_key[BTN_TRIGGER_HAPPY6] &&
joystick->hwdata->has_key[BTN_TRIGGER_HAPPY7] &&
@@ -2699,6 +2784,7 @@ static bool LINUX_JoystickGetGamepadMapping(int device_index, SDL_GamepadMapping
out->right_paddle2.target = joystick->hwdata->key_map[BTN_TRIGGER_HAPPY6];
out->left_paddle2.kind = EMappingKind_Button;
out->left_paddle2.target = joystick->hwdata->key_map[BTN_TRIGGER_HAPPY8];
+ mapped = MAPPED_PADDLE_ALL;
#ifdef DEBUG_GAMEPAD_MAPPING
SDL_Log("Mapped RIGHT_PADDLE1 to button %d (BTN_TRIGGER_HAPPY5)", out->right_paddle1.target);
SDL_Log("Mapped LEFT_PADDLE1 to button %d (BTN_TRIGGER_HAPPY7)", out->left_paddle1.target);
@@ -2706,15 +2792,15 @@ static bool LINUX_JoystickGetGamepadMapping(int device_index, SDL_GamepadMapping
SDL_Log("Mapped LEFT_PADDLE2 to button %d (BTN_TRIGGER_HAPPY8)", out->left_paddle2.target);
#endif
}
+ }
- // The Xbox Series X controllers have the Share button as KEY_RECORD
- if (joystick->hwdata->has_key[KEY_RECORD]) {
- out->misc1.kind = EMappingKind_Button;
- out->misc1.target = joystick->hwdata->key_map[KEY_RECORD];
+ // Xbox Series controllers have the Share button as KEY_RECORD
+ if (joystick->hwdata->has_key[KEY_RECORD]) {
+ out->misc1.kind = EMappingKind_Button;
+ out->misc1.target = joystick->hwdata->key_map[KEY_RECORD];
#ifdef DEBUG_GAMEPAD_MAPPING
- SDL_Log("Mapped MISC1 to button %d (KEY_RECORD)", out->misc1.target);
+ SDL_Log("Mapped MISC1 to button %d (KEY_RECORD)", out->misc1.target);
#endif
- }
}
// Cache the mapping for later
diff --git a/thirdparty/sdl/joystick/linux/SDL_sysjoystick_c.h b/thirdparty/sdl/joystick/linux/SDL_sysjoystick_c.h
index ae5384f1d41..d149948c8e5 100644
--- a/thirdparty/sdl/joystick/linux/SDL_sysjoystick_c.h
+++ b/thirdparty/sdl/joystick/linux/SDL_sysjoystick_c.h
@@ -1,6 +1,6 @@
/*
Simple DirectMedia Layer
- Copyright (C) 1997-2025 Sam Lantinga <[email protected]>
+ Copyright (C) 1997-2026 Sam Lantinga <[email protected]>
This software is provided 'as-is', without any express or implied
warranty. In no event will the authors be held liable for any damages
diff --git a/thirdparty/sdl/joystick/usb_ids.h b/thirdparty/sdl/joystick/usb_ids.h
index 4c85b6dad3b..ee0d8683fef 100644
--- a/thirdparty/sdl/joystick/usb_ids.h
+++ b/thirdparty/sdl/joystick/usb_ids.h
@@ -1,6 +1,6 @@
/*
Simple DirectMedia Layer
- Copyright (C) 1997-2025 Sam Lantinga <[email protected]>
+ Copyright (C) 1997-2026 Sam Lantinga <[email protected]>
This software is provided 'as-is', without any express or implied
warranty. In no event will the authors be held liable for any damages
@@ -26,13 +26,19 @@
#define USB_VENDOR_8BITDO 0x2dc8
#define USB_VENDOR_AMAZON 0x1949
+#define USB_VENDOR_ANDGAMER 0x38d2
#define USB_VENDOR_APPLE 0x05ac
#define USB_VENDOR_ASTRO 0x9886
#define USB_VENDOR_ASUS 0x0b05
#define USB_VENDOR_BACKBONE 0x358a
+#define USB_VENDOR_CRKD 0x3651
+#define USB_VENDOR_CORSAIR 0x1b1c
#define USB_VENDOR_GAMESIR 0x3537
#define USB_VENDOR_DRAGONRISE 0x0079
+#define USB_VENDOR_FLYDIGI_V1 0x04b4
+#define USB_VENDOR_FLYDIGI_V2 0x37d7
#define USB_VENDOR_GOOGLE 0x18d1
+#define USB_VENDOR_HARMONIX 0x1bad
#define USB_VENDOR_HORI 0x0f0d
#define USB_VENDOR_HP 0x03f0
#define USB_VENDOR_HYPERKIN 0x2e24
@@ -49,7 +55,10 @@
#define USB_VENDOR_POWERA_ALT 0x20d6
#define USB_VENDOR_QANBA 0x2c22
#define USB_VENDOR_RAZER 0x1532
+#define USB_VENDOR_RED_OCTANE 0x1430
+#define USB_VENDOR_RED_OCTANE_GAMES 0x3958
#define USB_VENDOR_SAITEK 0x06a3
+#define USB_VENDOR_SCEA 0x12ba
#define USB_VENDOR_SHANWAN 0x2563
#define USB_VENDOR_SHANWAN_ALT 0x20bc
#define USB_VENDOR_SONY 0x054c
@@ -58,28 +67,49 @@
#define USB_VENDOR_SWITCH 0x2563
#define USB_VENDOR_VALVE 0x28de
#define USB_VENDOR_ZEROPLUS 0x0c12
+#define USB_VENDOR_RASPBERRYPI 0x2e8a // Commercial hardware from various companies are registered under this VID
+#define USB_VENDOR_ZUIKI 0x33dd
-#define USB_PRODUCT_8BITDO_XBOX_CONTROLLER1 0x2002 // Ultimate Wired Controller for Xbox
-#define USB_PRODUCT_8BITDO_XBOX_CONTROLLER2 0x3106 // Ultimate Wireless / Pro 2 Wired Controller
+#define USB_PRODUCT_8BITDO_SF30_PRO 0x6000 // B + START
+#define USB_PRODUCT_8BITDO_SF30_PRO_BT 0x6100 // B + START
+#define USB_PRODUCT_8BITDO_SN30_PRO 0x6001 // B + START
+#define USB_PRODUCT_8BITDO_SN30_PRO_BT 0x6101 // B + START
+#define USB_PRODUCT_8BITDO_PRO_2 0x6003 // mode switch to D
+#define USB_PRODUCT_8BITDO_PRO_2_BT 0x6006 // mode switch to D
+#define USB_PRODUCT_8BITDO_PRO_3 0x6009 // mode switch to D
+#define USB_PRODUCT_8BITDO_ULTIMATE2_WIRELESS 0x6012 // mode switch to BT
+#define USB_PRODUCT_8BITDO_ULTIMATE3 0x202f // mode switch to BT
#define USB_PRODUCT_AMAZON_LUNA_CONTROLLER 0x0419
#define USB_PRODUCT_ASTRO_C40_XBOX360 0x0024
#define USB_PRODUCT_BACKBONE_ONE_IOS 0x0103
#define USB_PRODUCT_BACKBONE_ONE_IOS_PS5 0x0104
-#define USB_PRODUCT_GAMESIR_G7 0x1001
+#define USB_PRODUCT_BACKBONE_ONE_PS5_V2 0x0304
+#define USB_PRODUCT_BDA_XB1_CLASSIC 0x581a
+#define USB_PRODUCT_BDA_XB1_FIGHTPAD 0x791a
+#define USB_PRODUCT_BDA_XB1_SPECTRA_PRO 0x592a
#define USB_PRODUCT_GOOGLE_STADIA_CONTROLLER 0x9400
#define USB_PRODUCT_EVORETRO_GAMECUBE_ADAPTER1 0x1843
-#define USB_PRODUCT_EVORETRO_GAMECUBE_ADAPTER2 0x1846
-#define USB_PRODUCT_HORI_FIGHTING_COMMANDER_OCTA_SERIES_X 0x0150
-#define USB_PRODUCT_HORI_HORIPAD_PRO_SERIES_X 0x014f
+#define USB_PRODUCT_EVORETRO_GAMECUBE_ADAPTER2 0x1844
+#define USB_PRODUCT_EVORETRO_GAMECUBE_ADAPTER3 0x1846
+#define USB_PRODUCT_FLYDIGI_V1_GAMEPAD 0x2412
+#define USB_PRODUCT_FLYDIGI_V2_APEX 0x2501
+#define USB_PRODUCT_FLYDIGI_V2_VADER 0x2401
+#define USB_PRODUCT_HARMONIX_WII_RB1_GUITAR 0x0004
+#define USB_PRODUCT_HARMONIX_WII_RB1_DRUMS 0x0005
+#define USB_PRODUCT_HARMONIX_WII_RB2_GUITAR 0x3010
+#define USB_PRODUCT_HARMONIX_WII_RB2_DRUMS 0x3110
+#define USB_PRODUCT_HARMONIX_WII_RB3_MPA_DRUMS_MODE 0x3138
#define USB_PRODUCT_HORI_FIGHTING_STICK_ALPHA_PS4 0x011c
#define USB_PRODUCT_HORI_FIGHTING_STICK_ALPHA_PS5 0x0184
#define USB_PRODUCT_HORI_FIGHTING_STICK_ALPHA_PS5 0x0184
#define USB_PRODUCT_HORI_STEAM_CONTROLLER 0x01AB
#define USB_PRODUCT_HORI_STEAM_CONTROLLER_BT 0x0196
-#define USB_PRODUCT_HORI_TAIKO_DRUM_CONTROLLER 0x01b2
#define USB_PRODUCT_LOGITECH_F310 0xc216
#define USB_PRODUCT_LOGITECH_CHILLSTREAM 0xcad1
#define USB_PRODUCT_MADCATZ_SAITEK_SIDE_PANEL_CONTROL_DECK 0x2218
+#define USB_PRODUCT_MADCATZ_XB1_STRATOCASTER_GUITAR 0x4161
+#define USB_PRODUCT_MADCATZ_XB1_DRUM_KIT 0x4262
+#define USB_PRODUCT_MADCATZ_XB1_LEGACY_ADAPTER 0x4164
#define USB_PRODUCT_NACON_REVOLUTION_5_PRO_PS4_WIRELESS 0x0d16
#define USB_PRODUCT_NACON_REVOLUTION_5_PRO_PS4_WIRED 0x0d17
#define USB_PRODUCT_NACON_REVOLUTION_5_PRO_PS5_WIRELESS 0x0d18
@@ -94,15 +124,28 @@
#define USB_PRODUCT_NINTENDO_SWITCH_JOYCON_PAIR 0x2008 // Used by joycond
#define USB_PRODUCT_NINTENDO_SWITCH_JOYCON_RIGHT 0x2007
#define USB_PRODUCT_NINTENDO_SWITCH_PRO 0x2009
+#define USB_PRODUCT_NINTENDO_SWITCH2_GAMECUBE_CONTROLLER 0x2073
+#define USB_PRODUCT_NINTENDO_SWITCH2_JOYCON_LEFT 0x2067
+#define USB_PRODUCT_NINTENDO_SWITCH2_JOYCON_PAIR 0x2068
+#define USB_PRODUCT_NINTENDO_SWITCH2_JOYCON_RIGHT 0x2066
+#define USB_PRODUCT_NINTENDO_SWITCH2_PRO 0x2069
#define USB_PRODUCT_NINTENDO_WII_REMOTE 0x0306
#define USB_PRODUCT_NINTENDO_WII_REMOTE2 0x0330
#define USB_PRODUCT_NVIDIA_SHIELD_CONTROLLER_V103 0x7210
#define USB_PRODUCT_NVIDIA_SHIELD_CONTROLLER_V104 0x7214
+#define USB_PRODUCT_PDP_ROCK_CANDY 0x0246
+#define USB_PRODUCT_PDP_REALMZ_WIRELESS 0x018c
+#define USB_PRODUCT_PDP_XB1_DRUM_KIT 0x0171
+#define USB_PRODUCT_PDP_XB1_JAGUAR_GUITAR 0x0170
+#define USB_PRODUCT_PDP_XB1_RIFFMASTER_GUITAR 0x0248
+#define USB_PRODUCT_POWERA_MINI 0x541a
#define USB_PRODUCT_RAZER_ATROX 0x0a00
#define USB_PRODUCT_RAZER_KITSUNE 0x1012
#define USB_PRODUCT_RAZER_PANTHERA 0x0401
#define USB_PRODUCT_RAZER_PANTHERA_EVO 0x1008
#define USB_PRODUCT_RAZER_RAIJU 0x1000
+#define USB_PRODUCT_RAZER_RAIJU_V3_PRO_PS5_WIRED 0x1024
+#define USB_PRODUCT_RAZER_RAIJU_V3_PRO_PS5_WIRELESS 0x1026
#define USB_PRODUCT_RAZER_TOURNAMENT_EDITION_USB 0x1007
#define USB_PRODUCT_RAZER_TOURNAMENT_EDITION_BLUETOOTH 0x100a
#define USB_PRODUCT_RAZER_ULTIMATE_EDITION_USB 0x1004
@@ -114,8 +157,16 @@
#define USB_PRODUCT_RAZER_WOLVERINE_V2_PRO_XBOX_WIRED 0x1010
#define USB_PRODUCT_RAZER_WOLVERINE_V2_PRO_XBOX_WIRELESS 0x1011
#define USB_PRODUCT_RAZER_WOLVERINE_V3_PRO 0x0a3f
-#define USB_PRODUCT_ROG_RAIKIRI 0x1a38
+#define USB_PRODUCT_RED_OCTANE_XB1_GUITAR_HERO_LIVE_GUITAR 0x0170
+#define USB_PRODUCT_RED_OCTANE_XB1_STAGE_TOUR_GUITAR 0x4161
+#define USB_PRODUCT_RED_OCTANE_XB1_STAGE_TOUR_DRUMS 0xD300
#define USB_PRODUCT_SAITEK_CYBORG_V3 0xf622
+#define USB_PRODUCT_SCEA_PS3_GH_GUITAR 0x0100
+#define USB_PRODUCT_SCEA_PS3_GH_DRUMS 0x0120
+#define USB_PRODUCT_SCEA_PS3_RB_GUITAR 0x0200
+#define USB_PRODUCT_SCEA_PS3_RB_DRUMS 0x0210
+#define USB_PRODUCT_SCEA_PS3_RB3_MPA_DRUMS_MODE 0x0218
+#define USB_PRODUCT_SCEA_PS3WIIU_GHLIVE 0x074b
#define USB_PRODUCT_SHANWAN_DS3 0x0523
#define USB_PRODUCT_SONY_DS3 0x0268
#define USB_PRODUCT_SONY_DS4 0x05c4
@@ -124,12 +175,13 @@
#define USB_PRODUCT_SONY_DS4_STRIKEPAD 0x05c5
#define USB_PRODUCT_SONY_DS5 0x0ce6
#define USB_PRODUCT_SONY_DS5_EDGE 0x0df2
-#define USB_PRODUCT_SWITCH_RETROBIT_CONTROLLER 0x0575
+#define USB_PRODUCT_STEALTH_ULTRA_WIRED 0x7073
+#define USB_PRODUCT_SWITCH_RETRO_CONTROLLER 0x0575
#define USB_PRODUCT_THRUSTMASTER_ESWAPX_PRO_PS4 0xd00e
-#define USB_PRODUCT_THRUSTMASTER_ESWAPX_PRO_SERIES_X 0xd012
-#define USB_PRODUCT_TURTLE_BEACH_SERIES_X_REACT_R 0x7013
-#define USB_PRODUCT_TURTLE_BEACH_SERIES_X_RECON 0x7009
+#define USB_PRODUCT_THRUSTMASTER_T_FLIGHT_HOTAS_ONE 0xb68c
#define USB_PRODUCT_VALVE_STEAM_CONTROLLER_DONGLE 0x1142
+#define USB_PRODUCT_VALVE_STEAM_PROTEUS_DONGLE 0x1304
+#define USB_PRODUCT_VALVE_STEAM_NEREID_DONGLE 0x1305
#define USB_PRODUCT_VICTRIX_FS_PRO 0x0203
#define USB_PRODUCT_VICTRIX_FS_PRO_V2 0x0207
#define USB_PRODUCT_XBOX360_XUSB_CONTROLLER 0x02a1 // XUSB driver software PID
@@ -150,23 +202,27 @@
#define USB_PRODUCT_XBOX_ONE_S_REV2_BLE 0x0b20
#define USB_PRODUCT_XBOX_SERIES_X 0x0b12
#define USB_PRODUCT_XBOX_SERIES_X_BLE 0x0b13
-#define USB_PRODUCT_XBOX_SERIES_X_HP_HYPERX 0x08b6
-#define USB_PRODUCT_XBOX_SERIES_X_HP_HYPERX_RGB 0x07a0
-#define USB_PRODUCT_XBOX_SERIES_X_PDP_AFTERGLOW 0x02da
-#define USB_PRODUCT_XBOX_SERIES_X_PDP_BLUE 0x02d9
-#define USB_PRODUCT_XBOX_SERIES_X_POWERA_FUSION_PRO2 0x4001
-#define USB_PRODUCT_XBOX_SERIES_X_POWERA_FUSION_PRO4 0x400b
-#define USB_PRODUCT_XBOX_SERIES_X_POWERA_FUSION_PRO_WIRELESS_USB 0x4014
-#define USB_PRODUCT_XBOX_SERIES_X_POWERA_FUSION_PRO_WIRELESS_DONGLE 0x4016
-#define USB_PRODUCT_XBOX_SERIES_X_POWERA_MOGA_XP_ULTRA 0x890b
-#define USB_PRODUCT_XBOX_SERIES_X_POWERA_SPECTRA 0x4002
-#define USB_PRODUCT_XBOX_SERIES_X_VICTRIX_GAMBIT 0x02d6
#define USB_PRODUCT_XBOX_ONE_XBOXGIP_CONTROLLER 0x02ff // XBOXGIP driver software PID
#define USB_PRODUCT_STEAM_VIRTUAL_GAMEPAD 0x11ff
+#define USB_PRODUCT_HANDHELDLEGEND_SINPUT_GENERIC 0x10c6
+#define USB_PRODUCT_HANDHELDLEGEND_PROGCC 0x10df
+#define USB_PRODUCT_HANDHELDLEGEND_GCULTIMATE 0x10dd
+#define USB_PRODUCT_BONZIRICHANNEL_FIREBIRD 0x10e0
+#define USB_PRODUCT_ZUIKI_MASCON_PRO 0x0006
+#define USB_PRODUCT_ZUIKI_EVOTOP_UWB_DINPUT 0X001c
+#define USB_PRODUCT_ZUIKI_EVOTOP_PC_DINPUT 0X001d
+#define USB_PRODUCT_ZUIKI_EVOTOP_PC_BT 0X0017
+#define USB_PRODUCT_ZUIKI_EVOTOP_AXIS_DINPUT 0X0020
+#define USB_PRODUCT_VOIDGAMING_PS4FIREBIRD 0x10e5
+#define USB_PRODUCT_VOIDGAMING_GENESIS_SINPUT 0x1014
// USB usage pages
#define USB_USAGEPAGE_GENERIC_DESKTOP 0x0001
+#define USB_USAGEPAGE_SIMULATION 0x0002
+#define USB_USAGEPAGE_DEVICE_CONTROLS 0x0006
#define USB_USAGEPAGE_BUTTON 0x0009
+#define USB_USAGEPAGE_CONSUMER 0x000C
+#define USB_USAGEPAGE_VENDOR_FLYDIGI 0xFFA0
// USB usages for USAGE_PAGE_GENERIC_DESKTOP
#define USB_USAGE_GENERIC_POINTER 0x0001
@@ -187,6 +243,22 @@
#define USB_USAGE_GENERIC_WHEEL 0x0038
#define USB_USAGE_GENERIC_HAT 0x0039
+// USB usages for USB_USAGEPAGE_SIMULATION
+#define USB_USAGE_SIMULATION_ACCELERATOR 0x00C4
+#define USB_USAGE_SIMULATION_BRAKE 0x00C5
+
+// USB usages for USB_USAGEPAGE_DEVICE_CONTROLS
+#define USB_USAGE_DEVICE_CONTROLS_BATTERY_STRENGTH 0x0020
+
+// USB usages for USB_USAGEPAGE_CONSUMER
+#define USB_USAGE_CONSUMER_ASSIGN_SELECTION 0x0081
+#define USB_USAGE_CONSUMER_ORDER_MOVIE 0x0085
+#define USB_USAGE_CONSUMER_RECORD 0x00B2
+#define USB_USAGE_CONSUMER_AC_HOME 0x0223
+#define USB_USAGE_CONSUMER_AC_BACK 0x0224
+
+#define MAKE_USAGE(PAGE, USAGE) (((Uint32)PAGE) << 16 | USAGE)
+
/* Bluetooth SIG assigned Company Identifiers
https://www.bluetooth.com/specifications/assigned-numbers/company-identifiers/ */
#define BLUETOOTH_VENDOR_AMAZON 0x0171
diff --git a/thirdparty/sdl/joystick/windows/SDL_dinputjoystick.c b/thirdparty/sdl/joystick/windows/SDL_dinputjoystick.c
index 5b4b6fc0bb1..c6712600f8d 100644
--- a/thirdparty/sdl/joystick/windows/SDL_dinputjoystick.c
+++ b/thirdparty/sdl/joystick/windows/SDL_dinputjoystick.c
@@ -1,6 +1,6 @@
/*
Simple DirectMedia Layer
- Copyright (C) 1997-2025 Sam Lantinga <[email protected]>
+ Copyright (C) 1997-2026 Sam Lantinga <[email protected]>
This software is provided 'as-is', without any express or implied
warranty. In no event will the authors be held liable for any damages
@@ -45,6 +45,7 @@ extern HWND SDL_HelperWindow;
// local variables
static bool coinitialized = false;
static LPDIRECTINPUT8 dinput = NULL;
+static bool has_broken_EZFRD64DLL = false;
// Taken from Wine - Thanks!
static DIOBJECTDATAFORMAT dfDIJoystick2[] = {
@@ -289,7 +290,7 @@ static bool QueryDeviceName(LPDIRECTINPUTDEVICE8 device, Uint16 vendor_id, Uint1
}
*manufacturer_string = NULL;
- *product_string = WIN_StringToUTF8(dipstr.wsz);
+ *product_string = WIN_StringToUTF8W(dipstr.wsz);
return true;
}
@@ -437,6 +438,29 @@ bool SDL_DINPUT_JoystickInit(void)
dinput = NULL;
return SetDIerror("IDirectInput::Initialize", result);
}
+
+#ifdef _WIN64
+ if (SDL_GetHintBoolean("SDL_JOYSTICK_CHECK_EZFRD64", true)) {
+ // The 64-bit version of EZFRD64.DLL crashes after being loaded,
+ // which happens implicitly when querying the device capabilities,
+ // so make sure we don't do that if there's a possibility of crashing
+ static const char *directories[] = {
+ "C:/Windows/USB_Vibration",
+ "C:/Windows/USB Vibration"
+ };
+ for (int i = 0; i < SDL_arraysize(directories) && !has_broken_EZFRD64DLL; ++i) {
+ int count = 0;
+ char **files = SDL_GlobDirectory(directories[i], "*/EZFRD64.DLL", SDL_GLOB_CASEINSENSITIVE, &count);
+ if (count > 0) {
+ has_broken_EZFRD64DLL = true;
+ }
+ SDL_free(files);
+ }
+ if (has_broken_EZFRD64DLL) {
+ SDL_LogWarn(SDL_LOG_CATEGORY_INPUT, "Broken EZFRD64.DLL detected, disabling DirectInput force feedback");
+ }
+ }
+#endif
return true;
}
@@ -620,6 +644,10 @@ static BOOL CALLBACK EnumDevObjectsCallback(LPCDIDEVICEOBJECTINSTANCE pDeviceObj
in->ofs = DIJOFS_BUTTON(in->num);
joystick->nbuttons++;
} else if (pDeviceObject->dwType & DIDFT_POV) {
+ // DIJOYSTATE2.rgdwPOV only has room for 4 POVs, ignore any beyond that.
+ if (joystick->nhats >= 4) {
+ return DIENUM_CONTINUE;
+ }
in->type = HAT;
in->num = (Uint8)joystick->nhats;
in->ofs = DIJOFS_POV(in->num);
@@ -778,12 +806,14 @@ bool SDL_DINPUT_JoystickOpen(SDL_Joystick *joystick, JoyStick_DeviceData *joysti
return SetDIerror("IDirectInputDevice8::SetDataFormat", result);
}
- // Get device capabilities
- result =
- IDirectInputDevice8_GetCapabilities(joystick->hwdata->InputDevice,
- &joystick->hwdata->Capabilities);
- if (FAILED(result)) {
- return SetDIerror("IDirectInputDevice8::GetCapabilities", result);
+ if (!has_broken_EZFRD64DLL) {
+ // Get device capabilities to see if we are force feedback capable
+ result =
+ IDirectInputDevice8_GetCapabilities(joystick->hwdata->InputDevice,
+ &joystick->hwdata->Capabilities);
+ if (FAILED(result)) {
+ return SetDIerror("IDirectInputDevice8::GetCapabilities", result);
+ }
}
// Force capable?
@@ -1042,7 +1072,7 @@ static void UpdateDINPUTJoystickState_Polled(SDL_Joystick *joystick)
break;
case HAT:
{
- Uint8 pos = TranslatePOV(state.rgdwPOV[in->ofs - DIJOFS_POV(0)]);
+ Uint8 pos = TranslatePOV(state.rgdwPOV[in->num]);
SDL_SendJoystickHat(timestamp, joystick, in->num, pos);
break;
}
diff --git a/thirdparty/sdl/joystick/windows/SDL_dinputjoystick_c.h b/thirdparty/sdl/joystick/windows/SDL_dinputjoystick_c.h
index 0643ce10244..6f89f72b0f4 100644
--- a/thirdparty/sdl/joystick/windows/SDL_dinputjoystick_c.h
+++ b/thirdparty/sdl/joystick/windows/SDL_dinputjoystick_c.h
@@ -1,6 +1,6 @@
/*
Simple DirectMedia Layer
- Copyright (C) 1997-2025 Sam Lantinga <[email protected]>
+ Copyright (C) 1997-2026 Sam Lantinga <[email protected]>
This software is provided 'as-is', without any express or implied
warranty. In no event will the authors be held liable for any damages
diff --git a/thirdparty/sdl/joystick/windows/SDL_rawinputjoystick.c b/thirdparty/sdl/joystick/windows/SDL_rawinputjoystick.c
index 8590d9a8361..6846288aa75 100644
--- a/thirdparty/sdl/joystick/windows/SDL_rawinputjoystick.c
+++ b/thirdparty/sdl/joystick/windows/SDL_rawinputjoystick.c
@@ -1,6 +1,6 @@
/*
Simple DirectMedia Layer
- Copyright (C) 2025 Sam Lantinga <[email protected]>
+ Copyright (C) 2026 Sam Lantinga <[email protected]>
This software is provided 'as-is', without any express or implied
warranty. In no event will the authors be held liable for any damages
@@ -56,7 +56,7 @@
#ifdef SDL_JOYSTICK_RAWINPUT_WGI
#include "../../core/windows/SDL_windows.h"
-typedef struct WindowsGamingInputGamepadState WindowsGamingInputGamepadState;
+struct WindowsGamingInputGamepadState;
#define GamepadButtons_GUIDE 0x40000000
#define COBJMACROS
#include "windows.gaming.input.h"
@@ -157,7 +157,7 @@ struct joystick_hwdata
Uint8 wgi_correlation_id;
Uint8 wgi_correlation_count;
Uint8 wgi_uncorrelate_count;
- WindowsGamingInputGamepadState *wgi_slot;
+ struct WindowsGamingInputGamepadState *wgi_slot;
struct __x_ABI_CWindows_CGaming_CInput_CGamepadVibration vibration;
#endif
@@ -923,12 +923,8 @@ static void RAWINPUT_AddDevice(HANDLE hDevice)
device->name = SDL_CreateJoystickName(device->vendor_id, device->product_id, manufacturer_string, product_string);
device->guid = SDL_CreateJoystickGUID(SDL_HARDWARE_BUS_USB, device->vendor_id, device->product_id, device->version, manufacturer_string, product_string, 'r', 0);
- if (manufacturer_string) {
- SDL_free(manufacturer_string);
- }
- if (product_string) {
- SDL_free(product_string);
- }
+ SDL_free(manufacturer_string);
+ SDL_free(product_string);
}
device->path = SDL_strdup(dev_name);
@@ -963,12 +959,8 @@ err:
CloseHandle(hFile);
}
if (device) {
- if (device->name) {
- SDL_free(device->name);
- }
- if (device->path) {
- SDL_free(device->path);
- }
+ SDL_free(device->name);
+ SDL_free(device->path);
SDL_free(device);
}
#undef CHECK
@@ -1984,20 +1976,24 @@ static void RAWINPUT_UpdateOtherAPIs(SDL_Joystick *joystick)
state = SDL_POWERSTATE_ON_BATTERY;
break;
}
- switch (battery_info->BatteryLevel) {
- case BATTERY_LEVEL_EMPTY:
- percent = 10;
- break;
- case BATTERY_LEVEL_LOW:
- percent = 40;
- break;
- case BATTERY_LEVEL_MEDIUM:
- percent = 70;
- break;
- default:
- case BATTERY_LEVEL_FULL:
- percent = 100;
- break;
+ if (state == SDL_POWERSTATE_ON_BATTERY || state == SDL_POWERSTATE_CHARGING) {
+ switch (battery_info->BatteryLevel) {
+ case BATTERY_LEVEL_EMPTY:
+ percent = 10;
+ break;
+ case BATTERY_LEVEL_LOW:
+ percent = 40;
+ break;
+ case BATTERY_LEVEL_MEDIUM:
+ percent = 70;
+ break;
+ default:
+ case BATTERY_LEVEL_FULL:
+ percent = 100;
+ break;
+ }
+ } else {
+ percent = -1;
}
SDL_SendJoystickPowerInfo(joystick, state, percent);
}
diff --git a/thirdparty/sdl/joystick/windows/SDL_rawinputjoystick_c.h b/thirdparty/sdl/joystick/windows/SDL_rawinputjoystick_c.h
index b67544bd717..dc6e5ff86e8 100644
--- a/thirdparty/sdl/joystick/windows/SDL_rawinputjoystick_c.h
+++ b/thirdparty/sdl/joystick/windows/SDL_rawinputjoystick_c.h
@@ -1,6 +1,6 @@
/*
Simple DirectMedia Layer
- Copyright (C) 1997-2025 Sam Lantinga <[email protected]>
+ Copyright (C) 1997-2026 Sam Lantinga <[email protected]>
This software is provided 'as-is', without any express or implied
warranty. In no event will the authors be held liable for any damages
@@ -25,8 +25,8 @@
extern bool RAWINPUT_IsEnabled(void);
// Registers for input events
-extern int RAWINPUT_RegisterNotifications(HWND hWnd);
-extern int RAWINPUT_UnregisterNotifications(void);
+extern bool RAWINPUT_RegisterNotifications(HWND hWnd);
+extern bool RAWINPUT_UnregisterNotifications(void);
// Returns 0 if message was handled
extern LRESULT CALLBACK RAWINPUT_WindowProc(HWND hWnd, UINT msg, WPARAM wParam, LPARAM lParam);
diff --git a/thirdparty/sdl/joystick/windows/SDL_windows_gaming_input.c b/thirdparty/sdl/joystick/windows/SDL_windows_gaming_input.c
index 5f9435e34a5..f9076740ac2 100644
--- a/thirdparty/sdl/joystick/windows/SDL_windows_gaming_input.c
+++ b/thirdparty/sdl/joystick/windows/SDL_windows_gaming_input.c
@@ -1,6 +1,6 @@
/*
Simple DirectMedia Layer
- Copyright (C) 1997-2025 Sam Lantinga <[email protected]>
+ Copyright (C) 1997-2026 Sam Lantinga <[email protected]>
This software is provided 'as-is', without any express or implied
warranty. In no event will the authors be held liable for any damages
@@ -61,7 +61,7 @@ typedef struct WindowsGamingInputControllerState
int steam_virtual_gamepad_slot;
} WindowsGamingInputControllerState;
-typedef HRESULT(WINAPI *CoIncrementMTAUsage_t)(CO_MTA_USAGE_COOKIE *pCookie);
+typedef HRESULT(WINAPI *CoIncrementMTAUsage_t)(HANDLE* pCookie); // CO_MTA_USAGE_COOKIE*
typedef HRESULT(WINAPI *RoGetActivationFactory_t)(HSTRING activatableClassId, REFIID iid, void **factory);
typedef HRESULT(WINAPI *WindowsCreateStringReference_t)(PCWSTR sourceString, UINT32 length, HSTRING_HEADER *hstringHeader, HSTRING *string);
typedef HRESULT(WINAPI *WindowsDeleteString_t)(HSTRING string);
@@ -609,7 +609,7 @@ static bool WGI_JoystickInit(void)
* As a workaround, we will keep a reference to the MTA to prevent COM from unloading DLLs later.
* See https://github.com/libsdl-org/SDL/issues/5552 for more details.
*/
- static CO_MTA_USAGE_COOKIE cookie = NULL;
+ static HANDLE cookie = NULL; // CO_MTA_USAGE_COOKIE
if (!cookie) {
hr = wgi.CoIncrementMTAUsage(&cookie);
if (FAILED(hr)) {
@@ -973,9 +973,7 @@ static void WGI_JoystickQuit(void)
while (wgi.controller_count > 0) {
IEventHandler_CRawGameControllerVtbl_InvokeRemoved(&controller_removed.iface, NULL, wgi.controllers[wgi.controller_count - 1].controller);
}
- if (wgi.controllers) {
- SDL_free(wgi.controllers);
- }
+ SDL_free(wgi.controllers);
if (wgi.arcade_stick_statics) {
__x_ABI_CWindows_CGaming_CInput_CIArcadeStickStatics_Release(wgi.arcade_stick_statics);
diff --git a/thirdparty/sdl/joystick/windows/SDL_windowsjoystick.c b/thirdparty/sdl/joystick/windows/SDL_windowsjoystick.c
index e7fbfcb3462..a7ed293a956 100644
--- a/thirdparty/sdl/joystick/windows/SDL_windowsjoystick.c
+++ b/thirdparty/sdl/joystick/windows/SDL_windowsjoystick.c
@@ -1,6 +1,6 @@
/*
Simple DirectMedia Layer
- Copyright (C) 1997-2025 Sam Lantinga <[email protected]>
+ Copyright (C) 1997-2026 Sam Lantinga <[email protected]>
This software is provided 'as-is', without any express or implied
warranty. In no event will the authors be held liable for any damages
@@ -416,11 +416,15 @@ void WINDOWS_JoystickDetect(void)
while (pCurList) {
JoyStick_DeviceData *pListNext = NULL;
- if (!pCurList->bXInputDevice) {
#ifdef SDL_HAPTIC_DINPUT
+#ifdef SDL_JOYSTICK_XINPUT
+ if (!pCurList->bXInputDevice) {
SDL_DINPUT_HapticMaybeRemoveDevice(&pCurList->dxdevice);
-#endif
}
+#else
+ SDL_DINPUT_HapticMaybeRemoveDevice(&pCurList->dxdevice);
+#endif
+#endif
SDL_PrivateJoystickRemoved(pCurList->nInstanceID);
@@ -432,11 +436,15 @@ void WINDOWS_JoystickDetect(void)
for (pCurList = SYS_Joystick; pCurList; pCurList = pCurList->pNext) {
if (pCurList->send_add_event) {
- if (!pCurList->bXInputDevice) {
#ifdef SDL_HAPTIC_DINPUT
+#ifdef SDL_JOYSTICK_XINPUT
+ if (!pCurList->bXInputDevice) {
SDL_DINPUT_HapticMaybeAddDevice(&pCurList->dxdevice);
-#endif
}
+#else
+ SDL_DINPUT_HapticMaybeAddDevice(&pCurList->dxdevice);
+#endif
+#endif
SDL_PrivateJoystickAdded(pCurList->nInstanceID);
@@ -489,16 +497,18 @@ static int WINDOWS_JoystickGetDeviceSteamVirtualGamepadSlot(int device_index)
device = device->pNext;
}
+#ifdef SDL_JOYSTICK_XINPUT
if (device->bXInputDevice) {
// The slot for XInput devices can change as controllers are seated
return SDL_XINPUT_GetSteamVirtualGamepadSlot(device->XInputUserId);
- } else {
- return device->steam_virtual_gamepad_slot;
}
+#endif
+ return device->steam_virtual_gamepad_slot;
}
static int WINDOWS_JoystickGetDevicePlayerIndex(int device_index)
{
+#ifdef SDL_JOYSTICK_XINPUT
JoyStick_DeviceData *device = SYS_Joystick;
int index;
@@ -507,6 +517,9 @@ static int WINDOWS_JoystickGetDevicePlayerIndex(int device_index)
}
return device->bXInputDevice ? (int)device->XInputUserId : -1;
+#else
+ return -1;
+#endif
}
static void WINDOWS_JoystickSetDevicePlayerIndex(int device_index, int player_index)
@@ -560,20 +573,22 @@ static bool WINDOWS_JoystickOpen(SDL_Joystick *joystick, int device_index)
}
joystick->hwdata->guid = device->guid;
+#ifdef SDL_JOYSTICK_XINPUT
if (device->bXInputDevice) {
return SDL_XINPUT_JoystickOpen(joystick, device);
- } else {
- return SDL_DINPUT_JoystickOpen(joystick, device);
}
+#endif
+ return SDL_DINPUT_JoystickOpen(joystick, device);
}
static bool WINDOWS_JoystickRumble(SDL_Joystick *joystick, Uint16 low_frequency_rumble, Uint16 high_frequency_rumble)
{
+#ifdef SDL_JOYSTICK_XINPUT
if (joystick->hwdata->bXInputDevice) {
return SDL_XINPUT_JoystickRumble(joystick, low_frequency_rumble, high_frequency_rumble);
- } else {
- return SDL_DINPUT_JoystickRumble(joystick, low_frequency_rumble, high_frequency_rumble);
}
+#endif
+ return SDL_DINPUT_JoystickRumble(joystick, low_frequency_rumble, high_frequency_rumble);
}
static bool WINDOWS_JoystickRumbleTriggers(SDL_Joystick *joystick, Uint16 left_rumble, Uint16 right_rumble)
@@ -602,21 +617,27 @@ static void WINDOWS_JoystickUpdate(SDL_Joystick *joystick)
return;
}
+#ifdef SDL_JOYSTICK_XINPUT
if (joystick->hwdata->bXInputDevice) {
SDL_XINPUT_JoystickUpdate(joystick);
- } else {
- SDL_DINPUT_JoystickUpdate(joystick);
+ return;
}
+#endif
+ SDL_DINPUT_JoystickUpdate(joystick);
}
// Function to close a joystick after use
static void WINDOWS_JoystickClose(SDL_Joystick *joystick)
{
+#ifdef SDL_JOYSTICK_XINPUT
if (joystick->hwdata->bXInputDevice) {
SDL_XINPUT_JoystickClose(joystick);
} else {
SDL_DINPUT_JoystickClose(joystick);
}
+#else
+ SDL_DINPUT_JoystickClose(joystick);
+#endif
SDL_free(joystick->hwdata);
}
diff --git a/thirdparty/sdl/joystick/windows/SDL_windowsjoystick_c.h b/thirdparty/sdl/joystick/windows/SDL_windowsjoystick_c.h
index 16b91848dbf..d0ce9fdab12 100644
--- a/thirdparty/sdl/joystick/windows/SDL_windowsjoystick_c.h
+++ b/thirdparty/sdl/joystick/windows/SDL_windowsjoystick_c.h
@@ -1,6 +1,6 @@
/*
Simple DirectMedia Layer
- Copyright (C) 1997-2025 Sam Lantinga <[email protected]>
+ Copyright (C) 1997-2026 Sam Lantinga <[email protected]>
This software is provided 'as-is', without any express or implied
warranty. In no event will the authors be held liable for any damages
@@ -37,9 +37,11 @@ typedef struct JoyStick_DeviceData
char *joystickname;
Uint8 send_add_event;
SDL_JoystickID nInstanceID;
+#ifdef SDL_JOYSTICK_XINPUT
bool bXInputDevice;
BYTE SubType;
Uint8 XInputUserId;
+#endif
DIDEVICEINSTANCE dxdevice;
char path[MAX_PATH];
int steam_virtual_gamepad_slot;
@@ -85,10 +87,12 @@ struct joystick_hwdata
LPDIRECTINPUTEFFECT ffeffect_ref;
#endif
+#ifdef SDL_JOYSTICK_XINPUT
bool bXInputDevice; // true if this device supports using the xinput API rather than DirectInput
bool bXInputHaptic; // Supports force feedback via XInput.
Uint8 userid; // XInput userid index for this joystick
DWORD dwPacketNumber;
+#endif
};
#ifdef SDL_JOYSTICK_DINPUT
diff --git a/thirdparty/sdl/joystick/windows/SDL_xinputjoystick.c b/thirdparty/sdl/joystick/windows/SDL_xinputjoystick.c
index 9f6ce103d13..d7a132e1d15 100644
--- a/thirdparty/sdl/joystick/windows/SDL_xinputjoystick.c
+++ b/thirdparty/sdl/joystick/windows/SDL_xinputjoystick.c
@@ -1,6 +1,6 @@
/*
Simple DirectMedia Layer
- Copyright (C) 1997-2025 Sam Lantinga <[email protected]>
+ Copyright (C) 1997-2026 Sam Lantinga <[email protected]>
This software is provided 'as-is', without any express or implied
warranty. In no event will the authors be held liable for any damages
@@ -300,20 +300,24 @@ static void UpdateXInputJoystickBatteryInformation(SDL_Joystick *joystick, XINPU
state = SDL_POWERSTATE_ON_BATTERY;
break;
}
- switch (pBatteryInformation->BatteryLevel) {
- case BATTERY_LEVEL_EMPTY:
- percent = 10;
- break;
- case BATTERY_LEVEL_LOW:
- percent = 40;
- break;
- case BATTERY_LEVEL_MEDIUM:
- percent = 70;
- break;
- default:
- case BATTERY_LEVEL_FULL:
- percent = 100;
- break;
+ if (state == SDL_POWERSTATE_ON_BATTERY || state == SDL_POWERSTATE_CHARGING) {
+ switch (pBatteryInformation->BatteryLevel) {
+ case BATTERY_LEVEL_EMPTY:
+ percent = 10;
+ break;
+ case BATTERY_LEVEL_LOW:
+ percent = 40;
+ break;
+ case BATTERY_LEVEL_MEDIUM:
+ percent = 70;
+ break;
+ default:
+ case BATTERY_LEVEL_FULL:
+ percent = 100;
+ break;
+ }
+ } else {
+ percent = -1;
}
SDL_SendJoystickPowerInfo(joystick, state, percent);
}
@@ -391,6 +395,7 @@ void SDL_XINPUT_JoystickUpdate(SDL_Joystick *joystick)
return;
}
+ // FIXME: This does end up making a device ioctl() to query data, we shouldn't do this every update.
SDL_zero(XBatteryInformation);
if (XINPUTGETBATTERYINFORMATION) {
result = XINPUTGETBATTERYINFORMATION(joystick->hwdata->userid, BATTERY_DEVTYPE_GAMEPAD, &XBatteryInformation);
diff --git a/thirdparty/sdl/joystick/windows/SDL_xinputjoystick_c.h b/thirdparty/sdl/joystick/windows/SDL_xinputjoystick_c.h
index 305b0909af6..9ac12245081 100644
--- a/thirdparty/sdl/joystick/windows/SDL_xinputjoystick_c.h
+++ b/thirdparty/sdl/joystick/windows/SDL_xinputjoystick_c.h
@@ -1,6 +1,6 @@
/*
Simple DirectMedia Layer
- Copyright (C) 1997-2025 Sam Lantinga <[email protected]>
+ Copyright (C) 1997-2026 Sam Lantinga <[email protected]>
This software is provided 'as-is', without any express or implied
warranty. In no event will the authors be held liable for any damages
diff --git a/thirdparty/sdl/libm/e_exp.c b/thirdparty/sdl/libm/e_exp.c
index f39bb5c5394..413e3609d04 100644
--- a/thirdparty/sdl/libm/e_exp.c
+++ b/thirdparty/sdl/libm/e_exp.c
@@ -27,7 +27,7 @@
* the interval [0,0.34658]:
* Write
* R(r**2) = r*(exp(r)+1)/(exp(r)-1) = 2 + r*r/6 - r**4/360 + ...
- * We use a special Reme algorithm on [0,0.34658] to generate
+ * We use a special Remez algorithm on [0,0.34658] to generate
* a polynomial of degree 5 to approximate R. The maximum error
* of this polynomial approximation is bounded by 2**-59. In
* other words,
@@ -76,10 +76,6 @@
#include "math_libm.h"
#include "math_private.h"
-#ifdef __WATCOMC__ /* Watcom defines huge=__huge */
-#undef huge
-#endif
-
static const double
one = 1.0,
halF[2] = {0.5,-0.5,},
diff --git a/thirdparty/sdl/libm/e_log.c b/thirdparty/sdl/libm/e_log.c
index f935fa70f40..e6eaf3d596d 100644
--- a/thirdparty/sdl/libm/e_log.c
+++ b/thirdparty/sdl/libm/e_log.c
@@ -16,7 +16,7 @@
#endif
/* __ieee754_log(x)
- * Return the logrithm of x
+ * Return the logarithm of x
*
* Method :
* 1. Argument Reduction: find k and f such that
@@ -27,7 +27,7 @@
* Let s = f/(2+f) ; based on log(1+f) = log(1+s) - log(1-s)
* = 2s + 2/3 s**3 + 2/5 s**5 + .....,
* = 2s + s*R
- * We use a special Reme algorithm on [0,0.1716] to generate
+ * We use a special Remez algorithm on [0,0.1716] to generate
* a polynomial of degree 14 to approximate R The maximum error
* of this polynomial approximation is bounded by 2**-58.45. In
* other words,
diff --git a/thirdparty/sdl/libm/e_pow.c b/thirdparty/sdl/libm/e_pow.c
index d1a141ec4be..dc393e1f0c9 100644
--- a/thirdparty/sdl/libm/e_pow.c
+++ b/thirdparty/sdl/libm/e_pow.c
@@ -64,10 +64,6 @@
#pragma warning ( disable : 4756 )
#endif
-#ifdef __WATCOMC__ /* Watcom defines huge=__huge */
-#undef huge
-#endif
-
static const double
bp[] = {1.0, 1.5,},
dp_h[] = { 0.0, 5.84962487220764160156e-01,}, /* 0x3FE2B803, 0x40000000 */
diff --git a/thirdparty/sdl/libm/e_sqrt.c b/thirdparty/sdl/libm/e_sqrt.c
index 8ac58c62ac5..f0add579530 100644
--- a/thirdparty/sdl/libm/e_sqrt.c
+++ b/thirdparty/sdl/libm/e_sqrt.c
@@ -331,7 +331,7 @@ B. sqrt(x) by Reciproot Iteration
Let x0 and x1 be the leading and the trailing 32-bit words of
a floating point number x (in IEEE double format) respectively
- (see section A). By performing shifs and subtracts on x0 and y0,
+ (see section A). By performing shifts and subtracts on x0 and y0,
we obtain a 7.8-bit approximation of 1/sqrt(x) as follows.
k := 0x5fe80000 - (x0>>1);
diff --git a/thirdparty/sdl/libm/k_rem_pio2.c b/thirdparty/sdl/libm/k_rem_pio2.c
index 3dd5b2bf1dd..29dd9f37532 100644
--- a/thirdparty/sdl/libm/k_rem_pio2.c
+++ b/thirdparty/sdl/libm/k_rem_pio2.c
@@ -48,7 +48,7 @@
* 64-bit precision 2
* 113-bit precision 3
* The actual value is the sum of them. Thus for 113-bit
- * precison, one may have to do something like:
+ * precision, one may have to do something like:
*
* long double t,w,r_head, r_tail;
* t = (long double)y[2] + (long double)y[1];
diff --git a/thirdparty/sdl/libm/math_libm.h b/thirdparty/sdl/libm/math_libm.h
index b7b1614045c..43f2e5b6812 100644
--- a/thirdparty/sdl/libm/math_libm.h
+++ b/thirdparty/sdl/libm/math_libm.h
@@ -1,6 +1,6 @@
/*
Simple DirectMedia Layer
- Copyright (C) 1997-2025 Sam Lantinga <[email protected]>
+ Copyright (C) 1997-2026 Sam Lantinga <[email protected]>
This software is provided 'as-is', without any express or implied
warranty. In no event will the authors be held liable for any damages
diff --git a/thirdparty/sdl/libm/s_atan.c b/thirdparty/sdl/libm/s_atan.c
index ce429d22698..c8a0d015435 100644
--- a/thirdparty/sdl/libm/s_atan.c
+++ b/thirdparty/sdl/libm/s_atan.c
@@ -61,10 +61,6 @@ static const double aT[] = {
1.62858201153657823623e-02, /* 0x3F90AD3A, 0xE322DA11 */
};
-#ifdef __WATCOMC__ /* Watcom defines huge=__huge */
-#undef huge
-#endif
-
static const double
one = 1.0,
huge = 1.0e300;
diff --git a/thirdparty/sdl/libm/s_floor.c b/thirdparty/sdl/libm/s_floor.c
index 4809af1551e..a3f4f2fa550 100644
--- a/thirdparty/sdl/libm/s_floor.c
+++ b/thirdparty/sdl/libm/s_floor.c
@@ -25,10 +25,6 @@
#include "math_libm.h"
#include "math_private.h"
-#ifdef __WATCOMC__ /* Watcom defines huge=__huge */
-#undef huge
-#endif
-
static const double huge = 1.0e300;
double floor(double x)
diff --git a/thirdparty/sdl/libm/s_scalbn.c b/thirdparty/sdl/libm/s_scalbn.c
index b3a06044ab2..799e7fc5782 100644
--- a/thirdparty/sdl/libm/s_scalbn.c
+++ b/thirdparty/sdl/libm/s_scalbn.c
@@ -21,10 +21,6 @@
#include "math_private.h"
#include <limits.h>
-#ifdef __WATCOMC__ /* Watcom defines huge=__huge */
-#undef huge
-#endif
-
static const double
two54 = 1.80143985094819840000e+16, /* 0x43500000, 0x00000000 */
twom54 = 5.55111512312578270212e-17, /* 0x3C900000, 0x00000000 */
diff --git a/thirdparty/sdl/loadso/dlopen/SDL_sysloadso.c b/thirdparty/sdl/loadso/dlopen/SDL_sysloadso.c
index e09c09080cd..e45b5093f83 100644
--- a/thirdparty/sdl/loadso/dlopen/SDL_sysloadso.c
+++ b/thirdparty/sdl/loadso/dlopen/SDL_sysloadso.c
@@ -1,6 +1,6 @@
/*
Simple DirectMedia Layer
- Copyright (C) 1997-2025 Sam Lantinga <[email protected]>
+ Copyright (C) 1997-2026 Sam Lantinga <[email protected]>
This software is provided 'as-is', without any express or implied
warranty. In no event will the authors be held liable for any damages
@@ -65,8 +65,8 @@ SDL_FunctionPointer SDL_LoadFunction(SDL_SharedObject *handle, const char *name)
symbol = dlsym(handle, _name);
SDL_small_free(_name, isstack);
if (!symbol) {
- //SDL_SetError("Failed loading %s: %s", name,
- // (const char *)dlerror());
+ // SDL_SetError("Failed loading %s: %s", name,
+ // (const char *)dlerror());
}
}
return symbol;
diff --git a/thirdparty/sdl/loadso/dummy/SDL_sysloadso.c b/thirdparty/sdl/loadso/dummy/SDL_sysloadso.c
index 733386baf4c..ff7db420154 100644
--- a/thirdparty/sdl/loadso/dummy/SDL_sysloadso.c
+++ b/thirdparty/sdl/loadso/dummy/SDL_sysloadso.c
@@ -1,6 +1,6 @@
/*
Simple DirectMedia Layer
- Copyright (C) 1997-2025 Sam Lantinga <[email protected]>
+ Copyright (C) 1997-2026 Sam Lantinga <[email protected]>
This software is provided 'as-is', without any express or implied
warranty. In no event will the authors be held liable for any damages
diff --git a/thirdparty/sdl/misc/SDL_libusb.c b/thirdparty/sdl/misc/SDL_libusb.c
new file mode 100644
index 00000000000..2a5aff44aea
--- /dev/null
+++ b/thirdparty/sdl/misc/SDL_libusb.c
@@ -0,0 +1,123 @@
+/*
+ Simple DirectMedia Layer
+ Copyright (C) 1997-2026 Sam Lantinga <[email protected]>
+
+ 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"
+
+#include "SDL_libusb.h"
+
+#ifdef HAVE_LIBUSB
+
+#ifdef SDL_LIBUSB_DYNAMIC
+SDL_ELF_NOTE_DLOPEN(
+ "libusb",
+ "Support for joysticks through libusb",
+ SDL_ELF_NOTE_DLOPEN_PRIORITY_SUGGESTED,
+ SDL_LIBUSB_DYNAMIC
+)
+#endif
+
+static SDL_AtomicInt SDL_libusb_refcount;
+static bool SDL_libusb_loaded;
+static SDL_SharedObject *SDL_libusb_handle;
+static SDL_LibUSBContext SDL_libusb_context;
+
+bool SDL_InitLibUSB(SDL_LibUSBContext **ctx)
+{
+ if (SDL_AtomicIncRef(&SDL_libusb_refcount) == 0) {
+#ifdef SDL_LIBUSB_DYNAMIC
+ SDL_libusb_handle = SDL_LoadObject(SDL_LIBUSB_DYNAMIC);
+ if (SDL_libusb_handle)
+#endif
+ {
+ SDL_libusb_loaded = true;
+#ifdef SDL_LIBUSB_DYNAMIC
+#define LOAD_LIBUSB_SYMBOL(type, func) \
+ if ((SDL_libusb_context.func = (type)SDL_LoadFunction(SDL_libusb_handle, "libusb_" #func)) == NULL) { \
+ SDL_libusb_loaded = false; \
+ }
+#else
+#define LOAD_LIBUSB_SYMBOL(type, func) \
+ SDL_libusb_context.func = libusb_##func;
+#endif
+ LOAD_LIBUSB_SYMBOL(int (LIBUSB_CALL *)(libusb_context **), init)
+ LOAD_LIBUSB_SYMBOL(void (LIBUSB_CALL *)(libusb_context *), exit)
+ LOAD_LIBUSB_SYMBOL(ssize_t (LIBUSB_CALL *)(libusb_context *, libusb_device ***), get_device_list)
+ LOAD_LIBUSB_SYMBOL(void (LIBUSB_CALL *)(libusb_device **, int), free_device_list)
+ LOAD_LIBUSB_SYMBOL(int (LIBUSB_CALL *)(libusb_device *, struct libusb_device_descriptor *), get_device_descriptor)
+ LOAD_LIBUSB_SYMBOL(int (LIBUSB_CALL *)(libusb_device *, struct libusb_config_descriptor **), get_active_config_descriptor)
+ LOAD_LIBUSB_SYMBOL(int (LIBUSB_CALL *)(libusb_device *, uint8_t, struct libusb_config_descriptor **), get_config_descriptor)
+ LOAD_LIBUSB_SYMBOL(void (LIBUSB_CALL *)(struct libusb_config_descriptor *), free_config_descriptor)
+ LOAD_LIBUSB_SYMBOL(uint8_t (LIBUSB_CALL *)(libusb_device *), get_bus_number)
+#ifdef SDL_PLATFORM_FREEBSD
+ LOAD_LIBUSB_SYMBOL(int (LIBUSB_CALL *)(libusb_device *dev, uint8_t *port_numbers, uint8_t port_numbers_len), get_port_numbers)
+#else
+ LOAD_LIBUSB_SYMBOL(int (LIBUSB_CALL *)(libusb_device *dev, uint8_t *port_numbers, int port_numbers_len), get_port_numbers)
+#endif
+ LOAD_LIBUSB_SYMBOL(uint8_t (LIBUSB_CALL *)(libusb_device *), get_device_address)
+ LOAD_LIBUSB_SYMBOL(int (LIBUSB_CALL *)(libusb_device *, libusb_device_handle **), open)
+ LOAD_LIBUSB_SYMBOL(void (LIBUSB_CALL *)(libusb_device_handle *), close)
+ LOAD_LIBUSB_SYMBOL(libusb_device * (LIBUSB_CALL *)(libusb_device_handle *dev_handle), get_device)
+ LOAD_LIBUSB_SYMBOL(int (LIBUSB_CALL *)(libusb_device_handle *, int), claim_interface)
+ LOAD_LIBUSB_SYMBOL(int (LIBUSB_CALL *)(libusb_device_handle *, int), release_interface)
+ LOAD_LIBUSB_SYMBOL(int (LIBUSB_CALL *)(libusb_device_handle *, int), kernel_driver_active)
+ LOAD_LIBUSB_SYMBOL(int (LIBUSB_CALL *)(libusb_device_handle *, int), detach_kernel_driver)
+ LOAD_LIBUSB_SYMBOL(int (LIBUSB_CALL *)(libusb_device_handle *, int), attach_kernel_driver)
+ LOAD_LIBUSB_SYMBOL(int (LIBUSB_CALL *)(libusb_device_handle *, int), set_auto_detach_kernel_driver)
+ LOAD_LIBUSB_SYMBOL(int (LIBUSB_CALL *)(libusb_device_handle *, int, int), set_interface_alt_setting)
+ LOAD_LIBUSB_SYMBOL(struct libusb_transfer * (LIBUSB_CALL *)(int), alloc_transfer)
+ LOAD_LIBUSB_SYMBOL(int (LIBUSB_CALL *)(struct libusb_transfer *), submit_transfer)
+ LOAD_LIBUSB_SYMBOL(int (LIBUSB_CALL *)(struct libusb_transfer *), cancel_transfer)
+ LOAD_LIBUSB_SYMBOL(void (LIBUSB_CALL *)(struct libusb_transfer *), free_transfer)
+ LOAD_LIBUSB_SYMBOL(int (LIBUSB_CALL *)(libusb_device_handle *, uint8_t, uint8_t, uint16_t, uint16_t, unsigned char *, uint16_t, unsigned int), control_transfer)
+ LOAD_LIBUSB_SYMBOL(int (LIBUSB_CALL *)(libusb_device_handle *, unsigned char, unsigned char *, int, int *, unsigned int), interrupt_transfer)
+ LOAD_LIBUSB_SYMBOL(int (LIBUSB_CALL *)(libusb_device_handle *, unsigned char, unsigned char *, int, int *, unsigned int), bulk_transfer)
+ LOAD_LIBUSB_SYMBOL(int (LIBUSB_CALL *)(libusb_context *), handle_events)
+ LOAD_LIBUSB_SYMBOL(int (LIBUSB_CALL *)(libusb_context *, int *), handle_events_completed)
+ LOAD_LIBUSB_SYMBOL(void (LIBUSB_CALL *)(libusb_context *ctx), interrupt_event_handler)
+ LOAD_LIBUSB_SYMBOL(int (LIBUSB_CALL *)(uint32_t), has_capability)
+ LOAD_LIBUSB_SYMBOL(int (LIBUSB_CALL *)(libusb_context *, int, int, int, int, int, libusb_hotplug_callback_fn, void *, libusb_hotplug_callback_handle *), hotplug_register_callback)
+ LOAD_LIBUSB_SYMBOL(void (LIBUSB_CALL *)(libusb_context *, libusb_hotplug_callback_handle), hotplug_deregister_callback)
+ LOAD_LIBUSB_SYMBOL(const char * (LIBUSB_CALL *)(int), error_name)
+#undef LOAD_LIBUSB_SYMBOL
+ }
+ }
+
+ if (SDL_libusb_loaded) {
+ *ctx = &SDL_libusb_context;
+ return true;
+ } else {
+ SDL_QuitLibUSB();
+ *ctx = NULL;
+ return false;
+ }
+}
+
+void SDL_QuitLibUSB(void)
+{
+ if (SDL_AtomicDecRef(&SDL_libusb_refcount)) {
+ if (SDL_libusb_handle) {
+ SDL_UnloadObject(SDL_libusb_handle);
+ SDL_libusb_handle = NULL;
+ }
+ SDL_libusb_loaded = false;
+ }
+}
+
+#endif // HAVE_LIBUSB
diff --git a/thirdparty/sdl/misc/SDL_libusb.h b/thirdparty/sdl/misc/SDL_libusb.h
new file mode 100644
index 00000000000..cddbf6fd5fa
--- /dev/null
+++ b/thirdparty/sdl/misc/SDL_libusb.h
@@ -0,0 +1,106 @@
+/*
+ Simple DirectMedia Layer
+ Copyright (C) 1997-2026 Sam Lantinga <[email protected]>
+
+ 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"
+
+#ifdef HAVE_LIBUSB
+// libusb HIDAPI Implementation
+
+// Include this now, for our dynamically-loaded libusb context
+#include <libusb.h>
+
+typedef struct SDL_LibUSBContext
+{
+/* *INDENT-OFF* */ // clang-format off
+ int (LIBUSB_CALL *init)(libusb_context **ctx);
+ void (LIBUSB_CALL *exit)(libusb_context *ctx);
+ ssize_t (LIBUSB_CALL *get_device_list)(libusb_context *ctx, libusb_device ***list);
+ void (LIBUSB_CALL *free_device_list)(libusb_device **list, int unref_devices);
+ int (LIBUSB_CALL *get_device_descriptor)(libusb_device *dev, struct libusb_device_descriptor *desc);
+ int (LIBUSB_CALL *get_active_config_descriptor)(libusb_device *dev, struct libusb_config_descriptor **config);
+ int (LIBUSB_CALL *get_config_descriptor)(
+ libusb_device *dev,
+ uint8_t config_index,
+ struct libusb_config_descriptor **config
+ );
+ void (LIBUSB_CALL *free_config_descriptor)(struct libusb_config_descriptor *config);
+ uint8_t (LIBUSB_CALL *get_bus_number)(libusb_device *dev);
+#ifdef SDL_PLATFORM_FREEBSD
+ int (LIBUSB_CALL *get_port_numbers)(libusb_device *dev, uint8_t *port_numbers, uint8_t port_numbers_len);
+#else
+ int (LIBUSB_CALL *get_port_numbers)(libusb_device *dev, uint8_t *port_numbers, int port_numbers_len);
+#endif
+ uint8_t (LIBUSB_CALL *get_device_address)(libusb_device *dev);
+ int (LIBUSB_CALL *open)(libusb_device *dev, libusb_device_handle **dev_handle);
+ void (LIBUSB_CALL *close)(libusb_device_handle *dev_handle);
+ libusb_device *(LIBUSB_CALL *get_device)(libusb_device_handle *dev_handle);
+ int (LIBUSB_CALL *claim_interface)(libusb_device_handle *dev_handle, int interface_number);
+ int (LIBUSB_CALL *release_interface)(libusb_device_handle *dev_handle, int interface_number);
+ int (LIBUSB_CALL *kernel_driver_active)(libusb_device_handle *dev_handle, int interface_number);
+ int (LIBUSB_CALL *detach_kernel_driver)(libusb_device_handle *dev_handle, int interface_number);
+ int (LIBUSB_CALL *attach_kernel_driver)(libusb_device_handle *dev_handle, int interface_number);
+ int (LIBUSB_CALL *set_auto_detach_kernel_driver)(libusb_device_handle *dev_handle, int enable);
+ int (LIBUSB_CALL *set_interface_alt_setting)(libusb_device_handle *dev, int interface_number, int alternate_setting);
+ struct libusb_transfer * (LIBUSB_CALL *alloc_transfer)(int iso_packets);
+ int (LIBUSB_CALL *submit_transfer)(struct libusb_transfer *transfer);
+ int (LIBUSB_CALL *cancel_transfer)(struct libusb_transfer *transfer);
+ void (LIBUSB_CALL *free_transfer)(struct libusb_transfer *transfer);
+ int (LIBUSB_CALL *control_transfer)(
+ libusb_device_handle *dev_handle,
+ uint8_t request_type,
+ uint8_t bRequest,
+ uint16_t wValue,
+ uint16_t wIndex,
+ unsigned char *data,
+ uint16_t wLength,
+ unsigned int timeout
+ );
+ int (LIBUSB_CALL *interrupt_transfer)(
+ libusb_device_handle *dev_handle,
+ unsigned char endpoint,
+ unsigned char *data,
+ int length,
+ int *actual_length,
+ unsigned int timeout
+ );
+ int (LIBUSB_CALL *bulk_transfer)(
+ libusb_device_handle *dev_handle,
+ unsigned char endpoint,
+ unsigned char *data,
+ int length,
+ int *transferred,
+ unsigned int timeout
+ );
+ int (LIBUSB_CALL *handle_events)(libusb_context *ctx);
+ int (LIBUSB_CALL *handle_events_completed)(libusb_context *ctx, int *completed);
+ void (LIBUSB_CALL *interrupt_event_handler)(libusb_context *ctx);
+ int (LIBUSB_CALL *has_capability)(uint32_t capability);
+ int (LIBUSB_CALL *hotplug_register_callback)(libusb_context *ctx, int events, int flags, int vendor_id, int product_id, int dev_class, libusb_hotplug_callback_fn cb_fn, void *user_data, libusb_hotplug_callback_handle *callback_handle);
+ void (LIBUSB_CALL *hotplug_deregister_callback)(libusb_context *ctx, libusb_hotplug_callback_handle callback_handle);
+ const char * (LIBUSB_CALL *error_name)(int errcode);
+/* *INDENT-ON* */ // clang-format on
+
+} SDL_LibUSBContext;
+
+extern bool SDL_InitLibUSB(SDL_LibUSBContext **ctx);
+extern void SDL_QuitLibUSB(void);
+
+#endif // HAVE_LIBUSB
diff --git a/thirdparty/sdl/patches/0001-remove-unnecessary-subsystems.patch b/thirdparty/sdl/patches/0001-remove-unnecessary-subsystems.patch
index f98e90b02cc..03db8714cab 100644
--- a/thirdparty/sdl/patches/0001-remove-unnecessary-subsystems.patch
+++ b/thirdparty/sdl/patches/0001-remove-unnecessary-subsystems.patch
@@ -1,20 +1,23 @@
diff --git a/thirdparty/sdl/SDL.c b/thirdparty/sdl/SDL.c
-index 46a74aafdb..3dad7e29ba 100644
+index 3e61b8ad4a..d8e845057a 100644
--- a/thirdparty/sdl/SDL.c
+++ b/thirdparty/sdl/SDL.c
-@@ -40,23 +40,14 @@
+@@ -44,23 +44,23 @@
#include "SDL_hints_c.h"
#include "SDL_log_c.h"
#include "SDL_properties_c.h"
-#include "audio/SDL_sysaudio.h"
-#include "camera/SDL_camera_c.h"
-#include "cpuinfo/SDL_cpuinfo_c.h"
-+//#include "audio/SDL_sysaudio.h"
++// #include "audio/SDL_sysaudio.h"
++// #include "camera/SDL_camera_c.h"
++// #include "cpuinfo/SDL_cpuinfo_c.h"
#include "events/SDL_events_c.h"
#include "haptic/SDL_haptic_c.h"
#include "joystick/SDL_gamepad_c.h"
#include "joystick/SDL_joystick_c.h"
-#include "render/SDL_sysrender.h"
++// #include "render/SDL_sysrender.h"
#include "sensor/SDL_sensor_c.h"
#include "stdlib/SDL_getenv_c.h"
#include "thread/SDL_thread_c.h"
@@ -24,55 +27,62 @@ index 46a74aafdb..3dad7e29ba 100644
-#include "video/SDL_video_c.h"
-#include "filesystem/SDL_filesystem_c.h"
-#include "io/SDL_asyncio_c.h"
++// #include "tray/SDL_tray_utils.h"
++// #include "video/SDL_pixels_c.h"
++// #include "video/SDL_surface_c.h"
++// #include "video/SDL_video_c.h"
++// #include "filesystem/SDL_filesystem_c.h"
++// #include "io/SDL_asyncio_c.h"
#ifdef SDL_PLATFORM_ANDROID
#include "core/android/SDL_android.h"
#endif
-@@ -278,7 +269,7 @@ void SDL_InitMainThread(void)
+@@ -301,7 +301,7 @@ void SDL_InitMainThread(void)
SDL_InitTLSData();
SDL_InitEnvironment();
SDL_InitTicks();
- SDL_InitFilesystem();
-+ //SDL_InitFilesystem();
++ // SDL_InitFilesystem();
if (!done_info) {
const char *value;
-@@ -297,7 +288,7 @@ void SDL_InitMainThread(void)
+@@ -320,7 +320,7 @@ void SDL_InitMainThread(void)
static void SDL_QuitMainThread(void)
{
- SDL_QuitFilesystem();
-+ //SDL_QuitFilesystem();
++ // SDL_QuitFilesystem();
SDL_QuitTicks();
SDL_QuitEnvironment();
SDL_QuitTLSData();
-@@ -657,21 +648,21 @@ void SDL_Quit(void)
+@@ -711,7 +711,7 @@ void SDL_Quit(void)
SDL_HelperWindowDestroy();
#endif
- SDL_QuitSubSystem(SDL_INIT_EVERYTHING);
+ SDL_QuitSubSystem(SDL_ALL_SUBSYSTEM_FLAGS);
- SDL_CleanupTrays();
-+ //SDL_CleanupTrays();
++ // SDL_CleanupTrays();
#ifdef SDL_USE_LIBDBUS
SDL_DBus_Quit();
+@@ -722,14 +722,14 @@ void SDL_Quit(void)
#endif
SDL_QuitTimers();
- SDL_QuitAsyncIO();
-+ //SDL_QuitAsyncIO();
++ // SDL_QuitAsyncIO();
SDL_SetObjectsInvalid();
SDL_AssertionsQuit();
- SDL_QuitPixelFormatDetails();
-+ //SDL_QuitPixelFormatDetails();
++ // SDL_QuitPixelFormatDetails();
- SDL_QuitCPUInfo();
-+ //SDL_QuitCPUInfo();
++ // SDL_QuitCPUInfo();
/* Now that every subsystem has been quit, we reset the subsystem refcount
* and the list of initialized subsystems.
diff --git a/thirdparty/sdl/SDL_assert.c b/thirdparty/sdl/SDL_assert.c
-index 2440d04b1e..af904039a4 100644
+index f1f3da33ec..5b32f08bab 100644
--- a/thirdparty/sdl/SDL_assert.c
+++ b/thirdparty/sdl/SDL_assert.c
@@ -25,7 +25,7 @@
@@ -80,15 +90,14 @@ index 2440d04b1e..af904039a4 100644
#include "SDL_assert_c.h"
-#include "video/SDL_sysvideo.h"
-+//#include "video/SDL_sysvideo.h"
++// #include "video/SDL_sysvideo.h"
#if defined(SDL_PLATFORM_WINDOWS)
#ifndef WS_OVERLAPPEDWINDOW
-@@ -209,18 +209,6 @@ static SDL_AssertState SDLCALL SDL_PromptAssertion(const SDL_AssertData *data, v
- }
+@@ -197,16 +197,16 @@ static SDL_AssertState SDLCALL SDL_PromptAssertion(const SDL_AssertData *data, v
}
-- // Leave fullscreen mode, if possible (scary!)
+ // Leave fullscreen mode, if possible (scary!)
- window = SDL_GetToplevelForKeyboardFocus();
- if (window) {
- if (window->fullscreen_exclusive) {
@@ -99,38 +108,47 @@ index 2440d04b1e..af904039a4 100644
- window = NULL;
- }
- }
--
++ // window = SDL_GetToplevelForKeyboardFocus();
++ // if (window) {
++ // if (window->fullscreen_exclusive) {
++ // SDL_MinimizeWindow(window);
++ // } else {
++ // // !!! FIXME: ungrab the input if we're not fullscreen?
++ // // No need to mess with the window
++ // window = NULL;
++ // }
++ // }
+
// Show a messagebox if we can, otherwise fall back to stdio
SDL_zero(messagebox);
- messagebox.flags = SDL_MESSAGEBOX_WARNING;
-@@ -230,7 +218,8 @@ static SDL_AssertState SDLCALL SDL_PromptAssertion(const SDL_AssertData *data, v
+@@ -217,7 +217,8 @@ static SDL_AssertState SDLCALL SDL_PromptAssertion(const SDL_AssertData *data, v
messagebox.numbuttons = SDL_arraysize(buttons);
messagebox.buttons = buttons;
- if (SDL_ShowMessageBox(&messagebox, &selected)) {
-+ //if (SDL_ShowMessageBox(&messagebox, &selected)) {
++ // if (SDL_ShowMessageBox(&messagebox, &selected)) {
+ if (false) {
if (selected == -1) {
state = SDL_ASSERTION_IGNORE;
} else {
-@@ -311,13 +300,13 @@ static SDL_AssertState SDLCALL SDL_PromptAssertion(const SDL_AssertData *data, v
+@@ -298,13 +299,13 @@ static SDL_AssertState SDLCALL SDL_PromptAssertion(const SDL_AssertData *data, v
}
}
#else
- SDL_ShowSimpleMessageBox(SDL_MESSAGEBOX_WARNING, "Assertion Failed", message, window);
-+ //SDL_ShowSimpleMessageBox(SDL_MESSAGEBOX_WARNING, "Assertion Failed", message, window);
- #endif // HAVE_STDIO_H
++ // SDL_ShowSimpleMessageBox(SDL_MESSAGEBOX_WARNING, "Assertion Failed", message, window);
+ #endif // SDL_PLATFORM_PRIVATE_ASSERT
}
// Re-enter fullscreen mode
if (window) {
- SDL_RestoreWindow(window);
-+ //SDL_RestoreWindow(window);
++ // SDL_RestoreWindow(window);
}
if (message != stack_buf) {
diff --git a/thirdparty/sdl/SDL_internal.h b/thirdparty/sdl/SDL_internal.h
-index 8fcd96a7fa..20ec0fcb91 100644
+index 475009366e..a7d46db8d7 100644
--- a/thirdparty/sdl/SDL_internal.h
+++ b/thirdparty/sdl/SDL_internal.h
@@ -62,7 +62,7 @@
@@ -138,12 +156,12 @@ index 8fcd96a7fa..20ec0fcb91 100644
#include "SDL_build_config.h"
-#include "dynapi/SDL_dynapi.h"
-+//#include "dynapi/SDL_dynapi.h"
++// #include "dynapi/SDL_dynapi.h"
#if SDL_DYNAMIC_API
#include "dynapi/SDL_dynapi_overrides.h"
diff --git a/thirdparty/sdl/SDL_properties.c b/thirdparty/sdl/SDL_properties.c
-index 166ea0f918..42d4845458 100644
+index 6302de4dcb..b3753451ff 100644
--- a/thirdparty/sdl/SDL_properties.c
+++ b/thirdparty/sdl/SDL_properties.c
@@ -409,7 +409,7 @@ static void SDLCALL CleanupSurface(void *userdata, void *value)
@@ -151,32 +169,33 @@ index 166ea0f918..42d4845458 100644
SDL_Surface *surface = (SDL_Surface *)value;
- SDL_DestroySurface(surface);
-+ //SDL_DestroySurface(surface);
++ // SDL_DestroySurface(surface);
}
bool SDL_SetSurfaceProperty(SDL_PropertiesID props, const char *name, SDL_Surface *surface)
diff --git a/thirdparty/sdl/core/linux/SDL_evdev.c b/thirdparty/sdl/core/linux/SDL_evdev.c
-index 5746e2ef98..04e3e9d6b6 100644
+index fa43ee6c57..711fe68881 100644
--- a/thirdparty/sdl/core/linux/SDL_evdev.c
+++ b/thirdparty/sdl/core/linux/SDL_evdev.c
-@@ -39,7 +39,6 @@
+@@ -40,7 +40,7 @@
#include <linux/input.h>
#include "../../events/SDL_events_c.h"
-#include "../../events/SDL_scancode_tables_c.h"
++// #include "../../events/SDL_scancode_tables_c.h"
#include "../../core/linux/SDL_evdev_capabilities.h"
#include "../../core/linux/SDL_udev.h"
-@@ -221,7 +220,7 @@ bool SDL_EVDEV_Init(void)
+@@ -222,7 +222,7 @@ bool SDL_EVDEV_Init(void)
SDL_EVDEV_UpdateKeyboardMute();
}
- SDL_GetMouse()->SetRelativeMouseMode = SDL_EVDEV_SetRelativeMouseMode;
-+ //SDL_GetMouse()->SetRelativeMouseMode = SDL_EVDEV_SetRelativeMouseMode;
++ // SDL_GetMouse()->SetRelativeMouseMode = SDL_EVDEV_SetRelativeMouseMode;
_this->ref_count += 1;
-@@ -328,7 +327,7 @@ void SDL_EVDEV_Poll(void)
+@@ -325,7 +325,7 @@ void SDL_EVDEV_Poll(void)
SDL_EVDEV_kbd_update(_this->kbd);
@@ -185,20 +204,16 @@ index 5746e2ef98..04e3e9d6b6 100644
for (item = _this->first; item; item = item->next) {
while ((len = read(item->fd, events, sizeof(events))) > 0) {
-@@ -345,10 +344,11 @@ void SDL_EVDEV_Poll(void)
-
- switch (event->type) {
- case EV_KEY:
-+ break;
+@@ -350,7 +350,7 @@ void SDL_EVDEV_Poll(void)
if (event->code >= BTN_MOUSE && event->code < BTN_MOUSE + SDL_arraysize(EVDEV_MouseButtons)) {
Uint64 timestamp = SDL_EVDEV_GetEventTimestamp(event);
mouse_button = event->code - BTN_MOUSE;
- SDL_SendMouseButton(timestamp, mouse->focus, (SDL_MouseID)item->fd, EVDEV_MouseButtons[mouse_button], (event->value != 0));
-+ //SDL_SendMouseButton(timestamp, mouse->focus, (SDL_MouseID)item->fd, EVDEV_MouseButtons[mouse_button], (event->value != 0));
++ // SDL_SendMouseButton(timestamp, mouse->focus, (SDL_MouseID)item->fd, EVDEV_MouseButtons[mouse_button], (event->value != 0));
break;
}
-@@ -371,11 +371,11 @@ void SDL_EVDEV_Poll(void)
+@@ -373,11 +373,11 @@ void SDL_EVDEV_Poll(void)
{
Uint64 timestamp = SDL_EVDEV_GetEventTimestamp(event);
scancode = SDL_EVDEV_translate_keycode(event->code);
@@ -208,19 +223,19 @@ index 5746e2ef98..04e3e9d6b6 100644
- SDL_SendKeyboardKey(timestamp, (SDL_KeyboardID)item->fd, event->code, scancode, true);
- }
+ // if (event->value == 0) {
-+ // SDL_SendKeyboardKey(timestamp, (SDL_KeyboardID)item->fd, event->code, scancode, false);
++ // SDL_SendKeyboardKey(timestamp, (SDL_KeyboardID)item->fd, event->code, scancode, false);
+ // } else if (event->value == 1 || event->value == 2 /* key repeated */) {
-+ // SDL_SendKeyboardKey(timestamp, (SDL_KeyboardID)item->fd, event->code, scancode, true);
++ // SDL_SendKeyboardKey(timestamp, (SDL_KeyboardID)item->fd, event->code, scancode, true);
+ // }
SDL_EVDEV_kbd_keycode(_this->kbd, event->code, event->value);
}
break;
-@@ -490,36 +490,30 @@ void SDL_EVDEV_Poll(void)
+@@ -492,35 +492,35 @@ void SDL_EVDEV_Poll(void)
if (item->relative_mouse) {
if (item->mouse_x != 0 || item->mouse_y != 0) {
Uint64 timestamp = SDL_EVDEV_GetEventTimestamp(event);
- SDL_SendMouseMotion(timestamp, mouse->focus, (SDL_MouseID)item->fd, item->relative_mouse, (float)item->mouse_x, (float)item->mouse_y);
-+ //SDL_SendMouseMotion(timestamp, mouse->focus, (SDL_MouseID)item->fd, item->relative_mouse, (float)item->mouse_x, (float)item->mouse_y);
++ // SDL_SendMouseMotion(timestamp, mouse->focus, (SDL_MouseID)item->fd, item->relative_mouse, (float)item->mouse_x, (float)item->mouse_y);
item->mouse_x = item->mouse_y = 0;
}
} else if (item->range_x > 0 && item->range_y > 0) {
@@ -233,6 +248,12 @@ index 5746e2ef98..04e3e9d6b6 100644
- if (!mode) {
- mode = SDL_GetCurrentDisplayMode(SDL_GetPrimaryDisplay());
- }
++ // if (mouse->focus) {
++ // mode = SDL_GetCurrentDisplayMode(SDL_GetDisplayForWindow(mouse->focus));
++ // }
++ // if (!mode) {
++ // mode = SDL_GetCurrentDisplayMode(SDL_GetPrimaryDisplay());
++ // }
if (mode) {
screen_w = mode->w;
screen_h = mode->h;
@@ -240,166 +261,168 @@ index 5746e2ef98..04e3e9d6b6 100644
- SDL_SendMouseMotion(SDL_EVDEV_GetEventTimestamp(event), mouse->focus, (SDL_MouseID)item->fd, item->relative_mouse,
- (float)(item->mouse_x - item->min_x) * screen_w / item->range_x,
- (float)(item->mouse_y - item->min_y) * screen_h / item->range_y);
-+ //SDL_SendMouseMotion(SDL_EVDEV_GetEventTimestamp(event), mouse->focus, (SDL_MouseID)item->fd, item->relative_mouse,
-+ // (float)(item->mouse_x - item->min_x) * screen_w / item->range_x,
-+ // (float)(item->mouse_y - item->min_y) * screen_h / item->range_y);
++ // SDL_SendMouseMotion(SDL_EVDEV_GetEventTimestamp(event), mouse->focus, (SDL_MouseID)item->fd, item->relative_mouse,
++ // (float)(item->mouse_x - item->min_x) * screen_w / item->range_x,
++ // (float)(item->mouse_y - item->min_y) * screen_h / item->range_y);
}
if (item->mouse_wheel != 0 || item->mouse_hwheel != 0) {
Uint64 timestamp = SDL_EVDEV_GetEventTimestamp(event);
- const float denom = (item->high_res_hwheel ? 120.0f : 1.0f);
- SDL_SendMouseWheel(timestamp,
- mouse->focus, (SDL_MouseID)item->fd,
-- item->mouse_hwheel / denom,
-- item->mouse_wheel / denom,
+- item->mouse_hwheel / (item->high_res_hwheel ? 120.0f : 1.0f),
+- item->mouse_wheel / (item->high_res_wheel ? 120.0f : 1.0f),
- SDL_MOUSEWHEEL_NORMAL);
-+ //SDL_SendMouseWheel(timestamp,
-+ // mouse->focus, (SDL_MouseID)item->fd,
-+ // item->mouse_hwheel / denom,
-+ // item->mouse_wheel / denom,
-+ // SDL_MOUSEWHEEL_NORMAL);
++ // SDL_SendMouseWheel(timestamp,
++ // mouse->focus, (SDL_MouseID)item->fd,
++ // item->mouse_hwheel / (item->high_res_hwheel ? 120.0f : 1.0f),
++ // item->mouse_wheel / (item->high_res_wheel ? 120.0f : 1.0f),
++ // SDL_MOUSEWHEEL_NORMAL);
item->mouse_wheel = item->mouse_hwheel = 0;
}
-@@ -546,16 +540,16 @@ void SDL_EVDEV_Poll(void)
+@@ -547,16 +547,16 @@ void SDL_EVDEV_Poll(void)
* be window-relative in that case. */
switch (item->touchscreen_data->slots[j].delta) {
case EVDEV_TOUCH_SLOTDELTA_DOWN:
-- SDL_SendTouch(SDL_EVDEV_GetEventTimestamp(event), item->fd, item->touchscreen_data->slots[j].tracking_id, NULL, SDL_EVENT_FINGER_DOWN, norm_x, norm_y, norm_pressure);
-+ //SDL_SendTouch(SDL_EVDEV_GetEventTimestamp(event), item->fd, item->touchscreen_data->slots[j].tracking_id, NULL, SDL_EVENT_FINGER_DOWN, norm_x, norm_y, norm_pressure);
+- SDL_SendTouch(SDL_EVDEV_GetEventTimestamp(event), item->fd, item->touchscreen_data->slots[j].tracking_id, mouse->focus, SDL_EVENT_FINGER_DOWN, norm_x, norm_y, norm_pressure);
++ // SDL_SendTouch(SDL_EVDEV_GetEventTimestamp(event), item->fd, item->touchscreen_data->slots[j].tracking_id, mouse->focus, SDL_EVENT_FINGER_DOWN, norm_x, norm_y, norm_pressure);
item->touchscreen_data->slots[j].delta = EVDEV_TOUCH_SLOTDELTA_NONE;
break;
case EVDEV_TOUCH_SLOTDELTA_UP:
-- SDL_SendTouch(SDL_EVDEV_GetEventTimestamp(event), item->fd, item->touchscreen_data->slots[j].tracking_id, NULL, SDL_EVENT_FINGER_UP, norm_x, norm_y, norm_pressure);
-+ //SDL_SendTouch(SDL_EVDEV_GetEventTimestamp(event), item->fd, item->touchscreen_data->slots[j].tracking_id, NULL, SDL_EVENT_FINGER_UP, norm_x, norm_y, norm_pressure);
+- SDL_SendTouch(SDL_EVDEV_GetEventTimestamp(event), item->fd, item->touchscreen_data->slots[j].tracking_id, mouse->focus, SDL_EVENT_FINGER_UP, norm_x, norm_y, norm_pressure);
++ // SDL_SendTouch(SDL_EVDEV_GetEventTimestamp(event), item->fd, item->touchscreen_data->slots[j].tracking_id, mouse->focus, SDL_EVENT_FINGER_UP, norm_x, norm_y, norm_pressure);
item->touchscreen_data->slots[j].tracking_id = 0;
item->touchscreen_data->slots[j].delta = EVDEV_TOUCH_SLOTDELTA_NONE;
break;
case EVDEV_TOUCH_SLOTDELTA_MOVE:
-- SDL_SendTouchMotion(SDL_EVDEV_GetEventTimestamp(event), item->fd, item->touchscreen_data->slots[j].tracking_id, NULL, norm_x, norm_y, norm_pressure);
-+ //SDL_SendTouchMotion(SDL_EVDEV_GetEventTimestamp(event), item->fd, item->touchscreen_data->slots[j].tracking_id, NULL, norm_x, norm_y, norm_pressure);
+- SDL_SendTouchMotion(SDL_EVDEV_GetEventTimestamp(event), item->fd, item->touchscreen_data->slots[j].tracking_id, mouse->focus, norm_x, norm_y, norm_pressure);
++ // SDL_SendTouchMotion(SDL_EVDEV_GetEventTimestamp(event), item->fd, item->touchscreen_data->slots[j].tracking_id, mouse->focus, norm_x, norm_y, norm_pressure);
item->touchscreen_data->slots[j].delta = EVDEV_TOUCH_SLOTDELTA_NONE;
break;
default:
-@@ -585,7 +579,7 @@ void SDL_EVDEV_Poll(void)
+@@ -586,7 +586,7 @@ void SDL_EVDEV_Poll(void)
static SDL_Scancode SDL_EVDEV_translate_keycode(int keycode)
{
- SDL_Scancode scancode = SDL_GetScancodeFromTable(SDL_SCANCODE_TABLE_LINUX, keycode);
-+ //SDL_Scancode scancode = SDL_GetScancodeFromTable(SDL_SCANCODE_TABLE_LINUX, keycode);
++ // SDL_Scancode scancode = SDL_GetScancodeFromTable(SDL_SCANCODE_TABLE_LINUX, keycode);
#ifdef DEBUG_SCANCODES
if (scancode == SDL_SCANCODE_UNKNOWN) {
-@@ -602,7 +596,7 @@ static SDL_Scancode SDL_EVDEV_translate_keycode(int keycode)
+@@ -603,7 +603,7 @@ static SDL_Scancode SDL_EVDEV_translate_keycode(int keycode)
}
#endif // DEBUG_SCANCODES
- return scancode;
-+ return 0; //scancode;
++ return 0; // scancode;
}
static bool SDL_EVDEV_init_keyboard(SDL_evdevlist_item *item, int udev_class)
-@@ -612,14 +606,14 @@ static bool SDL_EVDEV_init_keyboard(SDL_evdevlist_item *item, int udev_class)
+@@ -613,14 +613,14 @@ static bool SDL_EVDEV_init_keyboard(SDL_evdevlist_item *item, int udev_class)
name[0] = '\0';
ioctl(item->fd, EVIOCGNAME(sizeof(name)), name);
-- SDL_AddKeyboard((SDL_KeyboardID)item->fd, name, true);
-+ //SDL_AddKeyboard((SDL_KeyboardID)item->fd, name, true);
+- SDL_AddKeyboard((SDL_KeyboardID)item->fd, name);
++ // SDL_AddKeyboard((SDL_KeyboardID)item->fd, name);
return true;
}
static void SDL_EVDEV_destroy_keyboard(SDL_evdevlist_item *item)
{
-- SDL_RemoveKeyboard((SDL_KeyboardID)item->fd, true);
-+ //SDL_RemoveKeyboard((SDL_KeyboardID)item->fd, true);
+- SDL_RemoveKeyboard((SDL_KeyboardID)item->fd);
++ // SDL_RemoveKeyboard((SDL_KeyboardID)item->fd);
}
static bool SDL_EVDEV_init_mouse(SDL_evdevlist_item *item, int udev_class)
-@@ -631,7 +625,7 @@ static bool SDL_EVDEV_init_mouse(SDL_evdevlist_item *item, int udev_class)
+@@ -632,7 +632,7 @@ static bool SDL_EVDEV_init_mouse(SDL_evdevlist_item *item, int udev_class)
name[0] = '\0';
ioctl(item->fd, EVIOCGNAME(sizeof(name)), name);
-- SDL_AddMouse((SDL_MouseID)item->fd, name, true);
-+ //SDL_AddMouse((SDL_MouseID)item->fd, name, true);
+- SDL_AddMouse((SDL_MouseID)item->fd, name);
++ // SDL_AddMouse((SDL_MouseID)item->fd, name);
ret = ioctl(item->fd, EVIOCGABS(ABS_X), &abs_info);
if (ret < 0) {
-@@ -656,7 +650,7 @@ static bool SDL_EVDEV_init_mouse(SDL_evdevlist_item *item, int udev_class)
+@@ -657,7 +657,7 @@ static bool SDL_EVDEV_init_mouse(SDL_evdevlist_item *item, int udev_class)
static void SDL_EVDEV_destroy_mouse(SDL_evdevlist_item *item)
{
-- SDL_RemoveMouse((SDL_MouseID)item->fd, true);
-+ //SDL_RemoveMouse((SDL_MouseID)item->fd, true);
+- SDL_RemoveMouse((SDL_MouseID)item->fd);
++ // SDL_RemoveMouse((SDL_MouseID)item->fd);
}
static bool SDL_EVDEV_init_touchscreen(SDL_evdevlist_item *item, int udev_class)
-@@ -743,9 +737,10 @@ static bool SDL_EVDEV_init_touchscreen(SDL_evdevlist_item *item, int udev_class)
+@@ -749,9 +749,10 @@ static bool SDL_EVDEV_init_touchscreen(SDL_evdevlist_item *item, int udev_class)
return false;
}
- ret = SDL_AddTouch(item->fd, // I guess our fd is unique enough
- (udev_class & SDL_UDEV_DEVICE_TOUCHPAD) ? SDL_TOUCH_DEVICE_INDIRECT_ABSOLUTE : SDL_TOUCH_DEVICE_DIRECT,
- item->touchscreen_data->name);
-+ //ret = SDL_AddTouch(item->fd, // I guess our fd is unique enough
-+ // (udev_class & SDL_UDEV_DEVICE_TOUCHPAD) ? SDL_TOUCH_DEVICE_INDIRECT_ABSOLUTE : SDL_TOUCH_DEVICE_DIRECT,
-+ // item->touchscreen_data->name);
-+ ret = -1;
++ // ret = SDL_AddTouch(item->fd, // I guess our fd is unique enough
++ // (udev_class & SDL_UDEV_DEVICE_TOUCHPAD) ? SDL_TOUCH_DEVICE_INDIRECT_ABSOLUTE : SDL_TOUCH_DEVICE_DIRECT,
++ // item->touchscreen_data->name);
++ ret = -1;
if (ret < 0) {
SDL_free(item->touchscreen_data->slots);
SDL_free(item->touchscreen_data->name);
-@@ -762,7 +757,7 @@ static void SDL_EVDEV_destroy_touchscreen(SDL_evdevlist_item *item)
+@@ -768,7 +769,7 @@ static void SDL_EVDEV_destroy_touchscreen(SDL_evdevlist_item *item)
return;
}
- SDL_DelTouch(item->fd);
-+ //SDL_DelTouch(item->fd);
++ // SDL_DelTouch(item->fd);
SDL_free(item->touchscreen_data->slots);
SDL_free(item->touchscreen_data->name);
SDL_free(item->touchscreen_data);
diff --git a/thirdparty/sdl/events/SDL_events.c b/thirdparty/sdl/events/SDL_events.c
-index 81220a1787..7ca683e0eb 100644
+index 06f1053cf6..43e75e1c36 100644
--- a/thirdparty/sdl/events/SDL_events.c
+++ b/thirdparty/sdl/events/SDL_events.c
-@@ -24,10 +24,7 @@
+@@ -24,10 +24,10 @@
#include "SDL_events_c.h"
#include "SDL_eventwatch_c.h"
-#include "SDL_windowevents_c.h"
++// #include "SDL_windowevents_c.h"
#include "../SDL_hints_c.h"
-#include "../audio/SDL_audio_c.h"
-#include "../camera/SDL_camera_c.h"
++// #include "../audio/SDL_audio_c.h"
++// #include "../camera/SDL_camera_c.h"
#include "../timer/SDL_timer_c.h"
+ #include "../core/linux/SDL_udev.h"
#ifndef SDL_JOYSTICK_DISABLED
- #include "../joystick/SDL_joystick_c.h"
-@@ -35,7 +32,7 @@
- #ifndef SDL_SENSOR_DISABLED
- #include "../sensor/SDL_sensor_c.h"
+@@ -39,7 +39,7 @@
+ #ifdef HAVE_DBUS_DBUS_H
+ #include "core/linux/SDL_dbus.h"
#endif
-#include "../video/SDL_sysvideo.h"
-+//#include "../video/SDL_sysvideo.h"
++// #include "../video/SDL_sysvideo.h"
#ifdef SDL_PLATFORM_ANDROID
#include "../core/android/SDL_android.h"
-@@ -930,7 +927,7 @@ void SDL_StopEventLoop(void)
+@@ -989,7 +989,7 @@ void SDL_StopEventLoop(void)
}
SDL_QuitEventWatchList(&SDL_event_watchers);
- SDL_QuitWindowEventWatch();
-+ //SDL_QuitWindowEventWatch();
++ // SDL_QuitWindowEventWatch();
SDL_Mutex *lock = NULL;
if (SDL_EventQ.lock) {
-@@ -970,7 +967,7 @@ bool SDL_StartEventLoop(void)
+@@ -1029,7 +1029,7 @@ bool SDL_StartEventLoop(void)
}
#endif // !SDL_THREADS_DISABLED
- SDL_InitWindowEventWatch();
-+ //SDL_InitWindowEventWatch();
++ // SDL_InitWindowEventWatch();
SDL_EventQ.active = true;
-@@ -1071,17 +1068,6 @@ static void SDL_SendWakeupEvent(void)
+@@ -1130,17 +1130,17 @@ static void SDL_SendWakeupEvent(void)
{
#ifdef SDL_PLATFORM_ANDROID
Android_SendLifecycleEvent(SDL_ANDROID_LIFECYCLE_WAKE);
@@ -414,31 +437,42 @@ index 81220a1787..7ca683e0eb 100644
- if (wakeup_window) {
- _this->SendWakeupEvent(_this, wakeup_window);
- }
++// #else
++// SDL_VideoDevice *_this = SDL_GetVideoDevice();
++// if (_this == NULL || !_this->SendWakeupEvent) {
++// return;
++// }
++
++// // We only want to do this once while waiting for an event, so set it to NULL atomically here
++// SDL_Window *wakeup_window = (SDL_Window *)SDL_SetAtomicPointer(&_this->wakeup_window, NULL);
++// if (wakeup_window) {
++// _this->SendWakeupEvent(_this, wakeup_window);
++// }
#endif
}
-@@ -1421,9 +1407,9 @@ void SDL_PumpEventMaintenance(void)
- }
- #endif
+@@ -1488,9 +1488,9 @@ void SDL_PumpEventMaintenance(void)
+
+ SDL_UpdateCursorAnimation();
- SDL_UpdateTrays();
-+ //SDL_UpdateTrays();
++ // SDL_UpdateTrays();
- SDL_SendPendingSignalEvents(); // in case we had a signal handler fire, etc.
-+ //SDL_SendPendingSignalEvents(); // in case we had a signal handler fire, etc.
++ // SDL_SendPendingSignalEvents(); // in case we had a signal handler fire, etc.
}
// Run the system dependent event loops
-@@ -1433,7 +1419,7 @@ static void SDL_PumpEventsInternal(bool push_sentinel)
+@@ -1503,7 +1503,7 @@ static void SDL_PumpEventsInternal(bool push_sentinel)
SDL_FreeTemporaryMemory();
// Release any keys held down from last frame
- SDL_ReleaseAutoReleaseKeys();
-+ //SDL_ReleaseAutoReleaseKeys();
++ // SDL_ReleaseAutoReleaseKeys();
// Run any pending main thread callbacks
SDL_RunMainThreadCallbacks();
-@@ -1441,12 +1427,6 @@ static void SDL_PumpEventsInternal(bool push_sentinel)
+@@ -1516,12 +1516,12 @@ static void SDL_PumpEventsInternal(bool push_sentinel)
#ifdef SDL_PLATFORM_ANDROID
// Android event processing is independent of the video subsystem
Android_PumpEvents(0);
@@ -448,10 +482,16 @@ index 81220a1787..7ca683e0eb 100644
- if (_this) {
- _this->PumpEvents(_this);
- }
++// #else
++// // Get events from the video subsystem
++// SDL_VideoDevice *_this = SDL_GetVideoDevice();
++// if (_this) {
++// _this->PumpEvents(_this);
++// }
#endif
SDL_PumpEventMaintenance();
-@@ -1477,103 +1457,6 @@ bool SDL_PollEvent(SDL_Event *event)
+@@ -1552,113 +1552,113 @@ bool SDL_PollEvent(SDL_Event *event)
return SDL_WaitEventTimeoutNS(event, 0);
}
@@ -480,6 +520,17 @@ index 81220a1787..7ca683e0eb 100644
- }
-#endif
-
+-#ifdef SDL_PLATFORM_UNIX
+- if (SDL_HasActiveTrays()) {
+- // Tray events on *nix platforms run separately from window system events, and need periodic polling
+- poll_intervalNS = SDL_min(poll_intervalNS, TRAY_POLL_INTERVAL_NS);
+- }
+-#endif
+-
+-#ifdef SDL_USE_LIBDBUS
+- // Wake periodically to pump DBus events
+- poll_intervalNS = SDL_min(poll_intervalNS, DBUS_POLL_INTERVAL_NS);
+-#endif
- return poll_intervalNS;
-}
-
@@ -551,11 +602,117 @@ index 81220a1787..7ca683e0eb 100644
-}
-
-#endif // !SDL_PLATFORM_ANDROID
--
++// #ifndef SDL_PLATFORM_ANDROID
++
++// static Sint64 SDL_events_get_polling_interval(void)
++// {
++// Sint64 poll_intervalNS = SDL_MAX_SINT64;
++
++// #ifndef SDL_JOYSTICK_DISABLED
++// if (SDL_WasInit(SDL_INIT_JOYSTICK) && SDL_update_joysticks) {
++// if (SDL_JoysticksOpened()) {
++// // If we have joysticks open, we need to poll rapidly for events
++// poll_intervalNS = SDL_min(poll_intervalNS, EVENT_POLL_INTERVAL_NS);
++// } else {
++// // If not, just poll every few seconds to enumerate new joysticks
++// poll_intervalNS = SDL_min(poll_intervalNS, ENUMERATION_POLL_INTERVAL_NS);
++// }
++// }
++// #endif
++
++// #ifndef SDL_SENSOR_DISABLED
++// if (SDL_WasInit(SDL_INIT_SENSOR) && SDL_update_sensors && SDL_SensorsOpened()) {
++// // If we have sensors open, we need to poll rapidly for events
++// poll_intervalNS = SDL_min(poll_intervalNS, EVENT_POLL_INTERVAL_NS);
++// }
++// #endif
++
++// #ifdef SDL_PLATFORM_UNIX
++// if (SDL_HasActiveTrays()) {
++// // Tray events on *nix platforms run separately from window system events, and need periodic polling
++// poll_intervalNS = SDL_min(poll_intervalNS, TRAY_POLL_INTERVAL_NS);
++// }
++// #endif
++
++// #ifdef SDL_USE_LIBDBUS
++// // Wake periodically to pump DBus events
++// poll_intervalNS = SDL_min(poll_intervalNS, DBUS_POLL_INTERVAL_NS);
++// #endif
++// return poll_intervalNS;
++// }
++
++// static int SDL_WaitEventTimeout_Device(SDL_VideoDevice *_this, SDL_Window *wakeup_window, SDL_Event *event, Uint64 start, Sint64 timeoutNS)
++// {
++// Sint64 loop_timeoutNS = timeoutNS;
++// Sint64 poll_intervalNS = SDL_events_get_polling_interval();
++
++// for (;;) {
++// int status;
++// /* Pump events on entry and each time we wake to ensure:
++// a) All pending events are batch processed after waking up from a wait
++// b) Waiting can be completely skipped if events are already available to be pumped
++// c) Periodic processing that takes place in some platform PumpEvents() functions happens
++// d) Signals received in WaitEventTimeout() are turned into SDL events
++// */
++// SDL_PumpEventsInternal(true);
++
++// status = SDL_PeepEvents(event, 1, SDL_GETEVENT, SDL_EVENT_FIRST, SDL_EVENT_LAST);
++// if (status < 0) {
++// // Got an error: return
++// break;
++// }
++// if (status > 0) {
++// // There is an event, we can return.
++// return 1;
++// }
++// // No events found in the queue, call WaitEventTimeout to wait for an event.
++// if (timeoutNS > 0) {
++// Sint64 elapsed = SDL_GetTicksNS() - start;
++// if (elapsed >= timeoutNS) {
++// return 0;
++// }
++// loop_timeoutNS = (timeoutNS - elapsed);
++// }
++// // Adjust the timeout for any polling requirements we currently have.
++// if (poll_intervalNS != SDL_MAX_SINT64) {
++// if (loop_timeoutNS >= 0) {
++// loop_timeoutNS = SDL_min(loop_timeoutNS, poll_intervalNS);
++// } else {
++// loop_timeoutNS = poll_intervalNS;
++// }
++// }
++// SDL_SetAtomicPointer(&_this->wakeup_window, wakeup_window);
++// status = _this->WaitEventTimeout(_this, loop_timeoutNS);
++// SDL_SetAtomicPointer(&_this->wakeup_window, NULL);
++// if (status == 0 && poll_intervalNS != SDL_MAX_SINT64 && loop_timeoutNS == poll_intervalNS) {
++// // We may have woken up to poll. Try again
++// continue;
++// } else if (status <= 0) {
++// // There is either an error or the timeout is elapsed: return
++// return status;
++// }
++// /* An event was found and pumped into the SDL events queue. Continue the loop
++// to let SDL_PeepEvents pick it up .*/
++// }
++// return 0;
++// }
++
++// static SDL_Window *SDL_find_active_window(SDL_VideoDevice *_this)
++// {
++// SDL_Window *window;
++// for (window = _this->windows; window; window = window->next) {
++// if (!window->is_destroying) {
++// return window;
++// }
++// }
++// return NULL;
++// }
++
++// #endif // !SDL_PLATFORM_ANDROID
+
bool SDL_WaitEvent(SDL_Event *event)
{
- return SDL_WaitEventTimeoutNS(event, -1);
-@@ -1665,24 +1548,6 @@ bool SDL_WaitEventTimeoutNS(SDL_Event *event, Sint64 timeoutNS)
+@@ -1755,23 +1755,23 @@ bool SDL_WaitEventTimeoutNS(SDL_Event *event, Sint64 timeoutNS)
Android_PumpEvents(delay);
}
#else
@@ -576,25 +733,41 @@ index 81220a1787..7ca683e0eb 100644
- }
- }
- }
--
++ // SDL_VideoDevice *_this = SDL_GetVideoDevice();
++ // if (_this && _this->WaitEventTimeout && _this->SendWakeupEvent) {
++ // // Look if a shown window is available to send the wakeup event.
++ // SDL_Window *wakeup_window = SDL_find_active_window(_this);
++ // if (wakeup_window) {
++ // result = SDL_WaitEventTimeout_Device(_this, wakeup_window, event, start, timeoutNS);
++ // if (result > 0) {
++ // return true;
++ // } else if (result == 0) {
++ // return false;
++ // } else {
++ // /* There may be implementation-defined conditions where the backend cannot
++ // * reliably wait for the next event. If that happens, fall back to polling.
++ // */
++ // }
++ // }
++ // }
+
for (;;) {
SDL_PumpEventsInternal(true);
-
-@@ -1855,7 +1720,7 @@ void SDL_SetEventEnabled(Uint32 type, bool enabled)
+@@ -1945,7 +1945,7 @@ void SDL_SetEventEnabled(Uint32 type, bool enabled)
/* turn off drag'n'drop support if we've disabled the events.
This might change some UI details at the OS level. */
if (type == SDL_EVENT_DROP_FILE || type == SDL_EVENT_DROP_TEXT) {
- SDL_ToggleDragAndDropSupport();
-+ //SDL_ToggleDragAndDropSupport();
++ // SDL_ToggleDragAndDropSupport();
}
}
}
-@@ -1947,14 +1812,14 @@ bool SDL_InitEvents(void)
+@@ -2037,14 +2037,14 @@ bool SDL_InitEvents(void)
return false;
}
- SDL_InitQuit();
-+ //SDL_InitQuit();
++ // SDL_InitQuit();
return true;
}
@@ -602,55 +775,62 @@ index 81220a1787..7ca683e0eb 100644
void SDL_QuitEvents(void)
{
- SDL_QuitQuit();
-+ //SDL_QuitQuit();
++ // SDL_QuitQuit();
SDL_StopEventLoop();
SDL_QuitMainThreadCallbacks();
SDL_RemoveHintCallback(SDL_HINT_POLL_SENTINEL, SDL_PollSentinelChanged, NULL);
diff --git a/thirdparty/sdl/events/SDL_events_c.h b/thirdparty/sdl/events/SDL_events_c.h
-index e56ac475e5..f3a0744d1c 100644
+index 377b04ec17..8bd09458c1 100644
--- a/thirdparty/sdl/events/SDL_events_c.h
+++ b/thirdparty/sdl/events/SDL_events_c.h
-@@ -25,16 +25,9 @@
+@@ -25,16 +25,16 @@
#include "SDL_internal.h"
// Useful functions and variables from SDL_events.c
-#include "../video/SDL_sysvideo.h"
-+//#include "../video/SDL_sysvideo.h"
++// #include "../video/SDL_sysvideo.h"
-#include "SDL_clipboardevents_c.h"
-#include "SDL_displayevents_c.h"
-#include "SDL_dropevents_c.h"
-#include "SDL_keyboard_c.h"
++// #include "SDL_clipboardevents_c.h"
++// #include "SDL_displayevents_c.h"
++// #include "SDL_dropevents_c.h"
++// #include "SDL_keyboard_c.h"
#include "SDL_mouse_c.h"
-#include "SDL_touch_c.h"
-#include "SDL_pen_c.h"
-#include "SDL_windowevents_c.h"
++// #include "SDL_touch_c.h"
++// #include "SDL_pen_c.h"
++// #include "SDL_windowevents_c.h"
// Start and stop the event processing loop
extern bool SDL_StartEventLoop(void);
diff --git a/thirdparty/sdl/include/SDL3/SDL.h b/thirdparty/sdl/include/SDL3/SDL.h
-index 7ec527b6d0..c99997044b 100644
+index 51848b51be..d9055809c4 100644
--- a/thirdparty/sdl/include/SDL3/SDL.h
+++ b/thirdparty/sdl/include/SDL3/SDL.h
-@@ -47,7 +47,7 @@
+@@ -48,7 +48,7 @@
#include <SDL3/SDL_events.h>
#include <SDL3/SDL_filesystem.h>
#include <SDL3/SDL_gamepad.h>
-#include <SDL3/SDL_gpu.h>
-+//#include <SDL3/SDL_gpu.h>
++// #include <SDL3/SDL_gpu.h>
#include <SDL3/SDL_guid.h>
#include <SDL3/SDL_haptic.h>
#include <SDL3/SDL_hidapi.h>
-@@ -85,6 +85,6 @@
+@@ -86,6 +86,6 @@
#include <SDL3/SDL_touch.h>
#include <SDL3/SDL_version.h>
#include <SDL3/SDL_video.h>
-#include <SDL3/SDL_oldnames.h>
-+//#include <SDL3/SDL_oldnames.h>
++// #include <SDL3/SDL_oldnames.h>
#endif /* SDL_h_ */
diff --git a/thirdparty/sdl/joystick/SDL_joystick.c b/thirdparty/sdl/joystick/SDL_joystick.c
-index 5ce36de867..090dc07303 100644
+index ccf6572f50..cf08c30b86 100644
--- a/thirdparty/sdl/joystick/SDL_joystick.c
+++ b/thirdparty/sdl/joystick/SDL_joystick.c
@@ -29,7 +29,7 @@
@@ -658,29 +838,645 @@ index 5ce36de867..090dc07303 100644
#include "../events/SDL_events_c.h"
-#include "../video/SDL_sysvideo.h"
-+//#include "../video/SDL_sysvideo.h"
++// #include "../video/SDL_sysvideo.h"
#include "../sensor/SDL_sensor_c.h"
#include "hidapi/SDL_hidapijoystick_c.h"
-@@ -1014,7 +1014,8 @@ static void AttemptSensorFusion(SDL_Joystick *joystick, bool invert_sensors)
+@@ -1239,7 +1239,8 @@ static void AttemptSensorFusion(SDL_Joystick *joystick, bool invert_sensors)
When a phone is being used as a gamepad, its orientation changes,
so adjust sensor axes to match.
*/
- if (SDL_GetNaturalDisplayOrientation(SDL_GetPrimaryDisplay()) == SDL_ORIENTATION_LANDSCAPE) {
-+ //if (SDL_GetNaturalDisplayOrientation(SDL_GetPrimaryDisplay()) == SDL_ORIENTATION_LANDSCAPE) {
++ // if (SDL_GetNaturalDisplayOrientation(SDL_GetPrimaryDisplay()) == SDL_ORIENTATION_LANDSCAPE) {
+ if (true) {
/* When a device in landscape orientation is laid flat, the axes change
orientation as follows:
-X to +X becomes -X to +X
-@@ -2071,11 +2072,6 @@ static bool SDL_PrivateJoystickShouldIgnoreEvent(void)
- if (SDL_joystick_allows_background_events) {
+@@ -2309,10 +2310,10 @@ static bool SDL_PrivateJoystickShouldIgnoreEvent(void)
return false;
}
--
+
- if (SDL_HasWindows() && SDL_GetKeyboardFocus() == NULL) {
- // We have windows but we don't have focus, ignore the event.
- return true;
- }
++ // if (SDL_HasWindows() && SDL_GetKeyboardFocus() == NULL) {
++ // // We have windows but we don't have focus, ignore the event.
++ // return true;
++ // }
return false;
}
+diff --git a/thirdparty/sdl/SDL.c b/thirdparty/sdl/SDL.c
+index d8e845057a..41216d3fd7 100644
+--- a/thirdparty/sdl/SDL.c
++++ b/thirdparty/sdl/SDL.c
+@@ -30,9 +30,9 @@
+ // this checks for HAVE_DBUS_DBUS_H internally.
+ #include "core/linux/SDL_dbus.h"
+
+-#if defined(SDL_PLATFORM_UNIX) && !defined(SDL_PLATFORM_ANDROID)
+-#include "core/unix/SDL_gtk.h"
+-#endif
++// #if defined(SDL_PLATFORM_UNIX) && !defined(SDL_PLATFORM_ANDROID)
++// #include "core/unix/SDL_gtk.h"
++// #endif
+
+ #ifdef SDL_PLATFORM_EMSCRIPTEN
+ #include <emscripten.h>
+@@ -173,7 +173,7 @@ const char *SDL_GetAppMetadataProperty(const char *name)
+ }
+ if (!value || !*value) {
+ if (SDL_strcmp(name, SDL_PROP_APP_METADATA_NAME_STRING) == 0) {
+- value = SDL_GetExeName();
++ // value = SDL_GetExeName();
+ if (!value) {
+ value = "SDL Application";
+ }
+diff --git a/thirdparty/sdl/core/unix/SDL_appid.c b/thirdparty/sdl/core/unix/SDL_appid.c
+index 95c5dc1a6b..fd0037eb7e 100644
+--- a/thirdparty/sdl/core/unix/SDL_appid.c
++++ b/thirdparty/sdl/core/unix/SDL_appid.c
+@@ -30,7 +30,7 @@ const char *SDL_GetAppID(void)
+
+ if (!id_str) {
+ // If the hint isn't set, try to use the application's executable name
+- id_str = SDL_GetExeName();
++ // id_str = SDL_GetExeName();
+ }
+
+ if (!id_str) {
+diff --git a/thirdparty/sdl/core/windows/SDL_windows.c b/thirdparty/sdl/core/windows/SDL_windows.c
+index b8b27e5ced..c7924bf934 100644
+--- a/thirdparty/sdl/core/windows/SDL_windows.c
++++ b/thirdparty/sdl/core/windows/SDL_windows.c
+@@ -24,7 +24,7 @@
+
+ #include "SDL_windows.h"
+
+-#include "../../video/SDL_surface_c.h"
++// #include "../../video/SDL_surface_c.h"
+
+ #include <shellapi.h> // CommandLineToArgvW()
+
+@@ -534,7 +534,7 @@ void WIN_UpdateDarkModeForHWND(HWND hwnd)
+ if (ShouldAppsUseDarkModeFunc) {
+ value = ShouldAppsUseDarkModeFunc() ? TRUE : FALSE;
+ } else {
+- value = (SDL_GetSystemTheme() == SDL_SYSTEM_THEME_DARK) ? TRUE : FALSE;
++ // value = (SDL_GetSystemTheme() == SDL_SYSTEM_THEME_DARK) ? TRUE : FALSE;
+ }
+ FreeLibrary(uxtheme);
+ if (!IsWindowsBuildVersionAtLeast(18362)) {
+@@ -552,79 +552,79 @@ void WIN_UpdateDarkModeForHWND(HWND hwnd)
+ #endif
+ }
+
+-HICON WIN_CreateIconFromSurface(SDL_Surface *surface)
+-{
+-#if !(defined(SDL_PLATFORM_XBOXONE) || defined(SDL_PLATFORM_XBOXSERIES))
+- SDL_Surface *s = SDL_ConvertSurface(surface, SDL_PIXELFORMAT_ARGB8888);
+- if (!s) {
+- return NULL;
+- }
+-
+- /* The dimensions will be needed after s is freed */
+- const int width = s->w;
+- const int height = s->h;
+-
+- BITMAPINFO bmpInfo;
+- SDL_zero(bmpInfo);
+- bmpInfo.bmiHeader.biSize = sizeof(BITMAPINFOHEADER);
+- bmpInfo.bmiHeader.biWidth = width;
+- bmpInfo.bmiHeader.biHeight = -height; /* Top-down bitmap */
+- bmpInfo.bmiHeader.biPlanes = 1;
+- bmpInfo.bmiHeader.biBitCount = 32;
+- bmpInfo.bmiHeader.biCompression = BI_RGB;
+-
+- HDC hdc = GetDC(NULL);
+- void *pBits = NULL;
+- HBITMAP hBitmap = CreateDIBSection(hdc, &bmpInfo, DIB_RGB_COLORS, &pBits, NULL, 0);
+- if (!hBitmap) {
+- ReleaseDC(NULL, hdc);
+- SDL_DestroySurface(s);
+- return NULL;
+- }
+-
+- SDL_memcpy(pBits, s->pixels, width * height * 4);
+-
+- SDL_DestroySurface(s);
+-
+- HBITMAP hMask = CreateBitmap(width, height, 1, 1, NULL);
+- if (!hMask) {
+- DeleteObject(hBitmap);
+- ReleaseDC(NULL, hdc);
+- return NULL;
+- }
+-
+- HDC hdcMem = CreateCompatibleDC(hdc);
+- HGDIOBJ oldBitmap = SelectObject(hdcMem, hMask);
+-
+- for (int y = 0; y < height; y++) {
+- for (int x = 0; x < width; x++) {
+- BYTE* pixel = (BYTE*)pBits + (y * width + x) * 4;
+- BYTE alpha = pixel[3];
+- COLORREF maskColor = (alpha == 0) ? RGB(255, 255, 255) : RGB(0, 0, 0);
+- SetPixel(hdcMem, x, y, maskColor);
+- }
+- }
+-
+- ICONINFO iconInfo;
+- iconInfo.fIcon = TRUE;
+- iconInfo.xHotspot = 0;
+- iconInfo.yHotspot = 0;
+- iconInfo.hbmMask = hMask;
+- iconInfo.hbmColor = hBitmap;
+-
+- HICON hIcon = CreateIconIndirect(&iconInfo);
+-
+- SelectObject(hdcMem, oldBitmap);
+- DeleteDC(hdcMem);
+- DeleteObject(hBitmap);
+- DeleteObject(hMask);
+- ReleaseDC(NULL, hdc);
+-
+- return hIcon;
+-#else
+- return NULL;
+-#endif
+-}
++// HICON WIN_CreateIconFromSurface(SDL_Surface *surface)
++// {
++// #if !(defined(SDL_PLATFORM_XBOXONE) || defined(SDL_PLATFORM_XBOXSERIES))
++// SDL_Surface *s = SDL_ConvertSurface(surface, SDL_PIXELFORMAT_ARGB8888);
++// if (!s) {
++// return NULL;
++// }
++
++// /* The dimensions will be needed after s is freed */
++// const int width = s->w;
++// const int height = s->h;
++
++// BITMAPINFO bmpInfo;
++// SDL_zero(bmpInfo);
++// bmpInfo.bmiHeader.biSize = sizeof(BITMAPINFOHEADER);
++// bmpInfo.bmiHeader.biWidth = width;
++// bmpInfo.bmiHeader.biHeight = -height; /* Top-down bitmap */
++// bmpInfo.bmiHeader.biPlanes = 1;
++// bmpInfo.bmiHeader.biBitCount = 32;
++// bmpInfo.bmiHeader.biCompression = BI_RGB;
++
++// HDC hdc = GetDC(NULL);
++// void *pBits = NULL;
++// HBITMAP hBitmap = CreateDIBSection(hdc, &bmpInfo, DIB_RGB_COLORS, &pBits, NULL, 0);
++// if (!hBitmap) {
++// ReleaseDC(NULL, hdc);
++// SDL_DestroySurface(s);
++// return NULL;
++// }
++
++// SDL_memcpy(pBits, s->pixels, width * height * 4);
++
++// SDL_DestroySurface(s);
++
++// HBITMAP hMask = CreateBitmap(width, height, 1, 1, NULL);
++// if (!hMask) {
++// DeleteObject(hBitmap);
++// ReleaseDC(NULL, hdc);
++// return NULL;
++// }
++
++// HDC hdcMem = CreateCompatibleDC(hdc);
++// HGDIOBJ oldBitmap = SelectObject(hdcMem, hMask);
++
++// for (int y = 0; y < height; y++) {
++// for (int x = 0; x < width; x++) {
++// BYTE* pixel = (BYTE*)pBits + (y * width + x) * 4;
++// BYTE alpha = pixel[3];
++// COLORREF maskColor = (alpha == 0) ? RGB(255, 255, 255) : RGB(0, 0, 0);
++// SetPixel(hdcMem, x, y, maskColor);
++// }
++// }
++
++// ICONINFO iconInfo;
++// iconInfo.fIcon = TRUE;
++// iconInfo.xHotspot = 0;
++// iconInfo.yHotspot = 0;
++// iconInfo.hbmMask = hMask;
++// iconInfo.hbmColor = hBitmap;
++
++// HICON hIcon = CreateIconIndirect(&iconInfo);
++
++// SelectObject(hdcMem, oldBitmap);
++// DeleteDC(hdcMem);
++// DeleteObject(hBitmap);
++// DeleteObject(hMask);
++// ReleaseDC(NULL, hdc);
++
++// return hIcon;
++// #else
++// return NULL;
++// #endif
++// }
+
+ // Some GUIDs we need to know without linking to libraries that aren't available before Vista.
+ /* *INDENT-OFF* */ // clang-format off
+diff --git a/thirdparty/sdl/events/SDL_events.c b/thirdparty/sdl/events/SDL_events.c
+index 43e75e1c36..2b17e6c247 100644
+--- a/thirdparty/sdl/events/SDL_events.c
++++ b/thirdparty/sdl/events/SDL_events.c
+@@ -46,9 +46,9 @@
+ #include "../video/android/SDL_androidevents.h"
+ #endif
+
+-#ifdef SDL_PLATFORM_UNIX
+-#include "../tray/SDL_tray_utils.h"
+-#endif
++// #ifdef SDL_PLATFORM_UNIX
++// #include "../tray/SDL_tray_utils.h"
++// #endif
+
+ // An arbitrary limit so we don't have unbounded growth
+ #define SDL_MAX_QUEUED_EVENTS 65535
+@@ -1484,9 +1484,9 @@ void SDL_PumpEventMaintenance(void)
+ }
+ #endif
+
+- SDL_SendPendingPenProximity();
++ // SDL_SendPendingPenProximity();
+
+- SDL_UpdateCursorAnimation();
++ // SDL_UpdateCursorAnimation();
+
+ // SDL_UpdateTrays();
+
+diff --git a/thirdparty/sdl/include/SDL3/SDL_render.h b/thirdparty/sdl/include/SDL3/SDL_render.h
+index a4ea58025e..14d3790808 100644
+--- a/thirdparty/sdl/include/SDL3/SDL_render.h
++++ b/thirdparty/sdl/include/SDL3/SDL_render.h
+@@ -59,7 +59,7 @@
+ #include <SDL3/SDL_rect.h>
+ #include <SDL3/SDL_surface.h>
+ #include <SDL3/SDL_video.h>
+-#include <SDL3/SDL_gpu.h>
++// #include <SDL3/SDL_gpu.h>
+
+ #include <SDL3/SDL_begin_code.h>
+ /* Set up for C function definitions, even when using C++ */
+@@ -384,7 +384,7 @@ extern SDL_DECLSPEC SDL_Renderer * SDLCALL SDL_CreateRendererWithProperties(SDL_
+ * \sa SDL_CreateGPURenderState
+ * \sa SDL_SetGPURenderState
+ */
+-extern SDL_DECLSPEC SDL_Renderer * SDLCALL SDL_CreateGPURenderer(SDL_GPUDevice *device, SDL_Window *window);
++// extern SDL_DECLSPEC SDL_Renderer * SDLCALL SDL_CreateGPURenderer(SDL_GPUDevice *device, SDL_Window *window);
+
+ /**
+ * Return the GPU device used by a renderer.
+@@ -397,7 +397,7 @@ extern SDL_DECLSPEC SDL_Renderer * SDLCALL SDL_CreateGPURenderer(SDL_GPUDevice *
+ *
+ * \since This function is available since SDL 3.4.0.
+ */
+-extern SDL_DECLSPEC SDL_GPUDevice * SDLCALL SDL_GetGPURendererDevice(SDL_Renderer *renderer);
++// extern SDL_DECLSPEC SDL_GPUDevice * SDLCALL SDL_GetGPURendererDevice(SDL_Renderer *renderer);
+
+ /**
+ * Create a 2D software rendering context for a surface.
+@@ -2928,16 +2928,16 @@ extern SDL_DECLSPEC bool SDLCALL SDL_GetDefaultTextureScaleMode(SDL_Renderer *re
+ */
+ typedef struct SDL_GPURenderStateCreateInfo
+ {
+- SDL_GPUShader *fragment_shader; /**< The fragment shader to use when this render state is active */
++ // SDL_GPUShader *fragment_shader; /**< The fragment shader to use when this render state is active */
+
+ Sint32 num_sampler_bindings; /**< The number of additional fragment samplers to bind when this render state is active */
+- const SDL_GPUTextureSamplerBinding *sampler_bindings; /**< Additional fragment samplers to bind when this render state is active */
++ // const SDL_GPUTextureSamplerBinding *sampler_bindings; /**< Additional fragment samplers to bind when this render state is active */
+
+ Sint32 num_storage_textures; /**< The number of storage textures to bind when this render state is active */
+- SDL_GPUTexture *const *storage_textures; /**< Storage textures to bind when this render state is active */
++ // SDL_GPUTexture *const *storage_textures; /**< Storage textures to bind when this render state is active */
+
+ Sint32 num_storage_buffers; /**< The number of storage buffers to bind when this render state is active */
+- SDL_GPUBuffer *const *storage_buffers; /**< Storage buffers to bind when this render state is active */
++ // SDL_GPUBuffer *const *storage_buffers; /**< Storage buffers to bind when this render state is active */
+
+ SDL_PropertiesID props; /**< A properties ID for extensions. Should be 0 if no extensions are needed. */
+ } SDL_GPURenderStateCreateInfo;
+diff --git a/thirdparty/sdl/joystick/SDL_steam_virtual_gamepad.c b/thirdparty/sdl/joystick/SDL_steam_virtual_gamepad.c
+index 7d1ef1a890..23deb54a75 100644
+--- a/thirdparty/sdl/joystick/SDL_steam_virtual_gamepad.c
++++ b/thirdparty/sdl/joystick/SDL_steam_virtual_gamepad.c
+@@ -138,11 +138,11 @@ void SDL_InitSteamVirtualGamepadInfo(void)
+ #ifdef SDL_PLATFORM_LINUX
+ // Older versions of Wine will blacklist the Steam Virtual Gamepad if
+ // it appears to have the real controller's VID/PID, so ignore this.
+- const char *exe = SDL_GetExeName();
+- if (exe && SDL_strcmp(exe, "wine64-preloader") == 0) {
+- SDL_LogDebug(SDL_LOG_CATEGORY_INPUT, "Wine launched by Steam, ignoring SteamVirtualGamepadInfo");
+- return;
+- }
++ // const char *exe = SDL_GetExeName();
++ // if (exe && SDL_strcmp(exe, "wine64-preloader") == 0) {
++ // SDL_LogDebug(SDL_LOG_CATEGORY_INPUT, "Wine launched by Steam, ignoring SteamVirtualGamepadInfo");
++ // return;
++ // }
+ #endif
+ SDL_steam_virtual_gamepad_info_file = SDL_strdup(file);
+ }
+diff --git a/thirdparty/sdl/joystick/hidapi/SDL_hidapi_gip.c b/thirdparty/sdl/joystick/hidapi/SDL_hidapi_gip.c
+index 826e45b13c..e9da9e21c7 100644
+--- a/thirdparty/sdl/joystick/hidapi/SDL_hidapi_gip.c
++++ b/thirdparty/sdl/joystick/hidapi/SDL_hidapi_gip.c
+@@ -22,7 +22,7 @@
+
+ #ifdef SDL_JOYSTICK_HIDAPI
+
+-#include "../../events/SDL_keyboard_c.h"
++// #include "../../events/SDL_keyboard_c.h"
+ #include "../SDL_sysjoystick.h"
+ #include "SDL_hidapijoystick_c.h"
+ #include "SDL_hidapi_rumble.h"
+@@ -449,7 +449,7 @@ typedef struct GIP_Attachment
+ struct GIP_Device *device;
+ Uint8 attachment_index;
+ SDL_JoystickID joystick;
+- SDL_KeyboardID keyboard;
++ // SDL_KeyboardID keyboard;
+
+ Uint8 fragment_message;
+ Uint16 total_length;
+@@ -1245,10 +1245,10 @@ static bool GIP_SendInitSequence(GIP_Attachment *attachment)
+ if ((!attachment->attachment_index || GIP_AttachmentIsController(attachment)) && !attachment->joystick) {
+ return HIDAPI_JoystickConnected(attachment->device->device, &attachment->joystick);
+ }
+- if (attachment->attachment_type == GIP_TYPE_CHATPAD && !attachment->keyboard) {
+- attachment->keyboard = (SDL_KeyboardID)(uintptr_t) attachment;
+- SDL_AddKeyboard(attachment->keyboard, "Xbox One Chatpad");
+- }
++ // if (attachment->attachment_type == GIP_TYPE_CHATPAD && !attachment->keyboard) {
++ // attachment->keyboard = (SDL_KeyboardID)(uintptr_t) attachment;
++ // SDL_AddKeyboard(attachment->keyboard, "Xbox One Chatpad");
++ // }
+ return true;
+ }
+
+@@ -1851,94 +1851,94 @@ static bool GIP_HandleCommandHidReport(
+ const Uint8 *bytes,
+ int num_bytes)
+ {
+- Uint64 timestamp = SDL_GetTicksNS();
++ // Uint64 timestamp = SDL_GetTicksNS();
+ // SDL doesn't have HID descriptor parsing, so we have to hardcode for the Chatpad descriptor instead.
+ // I don't know of any other devices that emit HID reports, so this should be safe.
+- if (attachment->attachment_type != GIP_TYPE_CHATPAD || !attachment->keyboard || num_bytes != 8) {
+- SDL_LogDebug(SDL_LOG_CATEGORY_INPUT, "GIP: Unimplemented HID Report message");
+- return false;
+- }
+-
+- Uint8 modifiers = bytes[0];
+- Uint8 changed_modifiers = modifiers ^ attachment->last_modifiers;
+- if (changed_modifiers & 0x02) {
+- if (modifiers & 0x02) {
+- SDL_SendKeyboardKey(timestamp, attachment->keyboard, 0, SDL_SCANCODE_LSHIFT, true);
+- } else {
+- SDL_SendKeyboardKey(timestamp, attachment->keyboard, 0, SDL_SCANCODE_LSHIFT, false);
+- }
+- }
++ // if (attachment->attachment_type != GIP_TYPE_CHATPAD || !attachment->keyboard || num_bytes != 8) {
++ // SDL_LogDebug(SDL_LOG_CATEGORY_INPUT, "GIP: Unimplemented HID Report message");
++ // return false;
++ // }
++
++ // Uint8 modifiers = bytes[0];
++ // Uint8 changed_modifiers = modifiers ^ attachment->last_modifiers;
++ // if (changed_modifiers & 0x02) {
++ // if (modifiers & 0x02) {
++ // SDL_SendKeyboardKey(timestamp, attachment->keyboard, 0, SDL_SCANCODE_LSHIFT, true);
++ // } else {
++ // SDL_SendKeyboardKey(timestamp, attachment->keyboard, 0, SDL_SCANCODE_LSHIFT, false);
++ // }
++ // }
+ // The chatpad has several non-ASCII characters that it sends as Alt codes
+- if (changed_modifiers & 0x04) {
+- if (modifiers & 0x04) {
+- attachment->altcode_digit = 0;
+- attachment->altcode = 0;
+- } else {
+- if (attachment->altcode_digit == 4) {
+- char utf8[4] = {0};
+- // Some Alt codes don't match their Unicode codepoint for some reason
+- switch (attachment->altcode) {
+- case 128:
+- SDL_UCS4ToUTF8(0x20AC, utf8);
+- break;
+- case 138:
+- SDL_UCS4ToUTF8(0x0160, utf8);
+- break;
+- case 140:
+- SDL_UCS4ToUTF8(0x0152, utf8);
+- break;
+- case 154:
+- SDL_UCS4ToUTF8(0x0161, utf8);
+- break;
+- case 156:
+- SDL_UCS4ToUTF8(0x0153, utf8);
+- break;
+- default:
+- SDL_UCS4ToUTF8(attachment->altcode, utf8);
+- break;
+- }
+- SDL_SendKeyboardText(utf8);
+- }
+- attachment->altcode_digit = -1;
+- SDL_SendKeyboardKey(timestamp, attachment->keyboard, 0, SDL_SCANCODE_NUMLOCKCLEAR, true);
+- SDL_SendKeyboardKey(timestamp, attachment->keyboard, 0, SDL_SCANCODE_NUMLOCKCLEAR, false);
+- }
+- }
+-
+- if (!bytes[2] && attachment->last_key) {
+- if (attachment->last_key == SDL_SCANCODE_CAPSLOCK) {
+- attachment->capslock = !attachment->capslock;
+- }
+- SDL_SendKeyboardKey(timestamp, attachment->keyboard, 0, attachment->last_key, false);
+- if (!(attachment->last_modifiers & 0xfd)) {
+- SDL_Keycode keycode = SDL_GetKeymapKeycode(NULL,
+- attachment->last_key,
+- ((attachment->last_modifiers & 0x02) || attachment->capslock) ? SDL_KMOD_SHIFT : 0);
+- if (keycode && keycode < 0x80) {
+- char text[2] = { (char)keycode };
+- SDL_SendKeyboardText(text);
+- }
+- }
+- attachment->last_key = 0;
+- } else {
+- SDL_SendKeyboardKey(timestamp, attachment->keyboard, 0, bytes[2], true);
+- attachment->last_key = bytes[2];
+-
+- if ((modifiers & 0x04) && attachment->altcode_digit >= 0) {
+- int digit = bytes[2] - SDL_SCANCODE_KP_1 + 1;
+- if (digit < 1 || digit > 10) {
+- attachment->altcode_digit = -1;
+- } else {
+- attachment->altcode_digit++;
+- attachment->altcode *= 10;
+- if (digit < 10) {
+- attachment->altcode += digit;
+- }
+- }
+- }
+- }
+-
+- attachment->last_modifiers = modifiers;
++ // if (changed_modifiers & 0x04) {
++ // if (modifiers & 0x04) {
++ // attachment->altcode_digit = 0;
++ // attachment->altcode = 0;
++ // } else {
++ // if (attachment->altcode_digit == 4) {
++ // char utf8[4] = {0};
++ // // Some Alt codes don't match their Unicode codepoint for some reason
++ // switch (attachment->altcode) {
++ // case 128:
++ // SDL_UCS4ToUTF8(0x20AC, utf8);
++ // break;
++ // case 138:
++ // SDL_UCS4ToUTF8(0x0160, utf8);
++ // break;
++ // case 140:
++ // SDL_UCS4ToUTF8(0x0152, utf8);
++ // break;
++ // case 154:
++ // SDL_UCS4ToUTF8(0x0161, utf8);
++ // break;
++ // case 156:
++ // SDL_UCS4ToUTF8(0x0153, utf8);
++ // break;
++ // default:
++ // SDL_UCS4ToUTF8(attachment->altcode, utf8);
++ // break;
++ // }
++ // SDL_SendKeyboardText(utf8);
++ // }
++ // attachment->altcode_digit = -1;
++ // SDL_SendKeyboardKey(timestamp, attachment->keyboard, 0, SDL_SCANCODE_NUMLOCKCLEAR, true);
++ // SDL_SendKeyboardKey(timestamp, attachment->keyboard, 0, SDL_SCANCODE_NUMLOCKCLEAR, false);
++ // }
++ // }
++
++ // if (!bytes[2] && attachment->last_key) {
++ // if (attachment->last_key == SDL_SCANCODE_CAPSLOCK) {
++ // attachment->capslock = !attachment->capslock;
++ // }
++ // SDL_SendKeyboardKey(timestamp, attachment->keyboard, 0, attachment->last_key, false);
++ // if (!(attachment->last_modifiers & 0xfd)) {
++ // SDL_Keycode keycode = SDL_GetKeymapKeycode(NULL,
++ // attachment->last_key,
++ // ((attachment->last_modifiers & 0x02) || attachment->capslock) ? SDL_KMOD_SHIFT : 0);
++ // if (keycode && keycode < 0x80) {
++ // char text[2] = { (char)keycode };
++ // SDL_SendKeyboardText(text);
++ // }
++ // }
++ // attachment->last_key = 0;
++ // } else {
++ // SDL_SendKeyboardKey(timestamp, attachment->keyboard, 0, bytes[2], true);
++ // attachment->last_key = bytes[2];
++
++ // if ((modifiers & 0x04) && attachment->altcode_digit >= 0) {
++ // int digit = bytes[2] - SDL_SCANCODE_KP_1 + 1;
++ // if (digit < 1 || digit > 10) {
++ // attachment->altcode_digit = -1;
++ // } else {
++ // attachment->altcode_digit++;
++ // attachment->altcode *= 10;
++ // if (digit < 10) {
++ // attachment->altcode += digit;
++ // }
++ // }
++ // }
++ // }
++
++ // attachment->last_modifiers = modifiers;
+ return true;
+ }
+
+@@ -2458,10 +2458,10 @@ static bool GIP_HandleSystemMessage(
+ // XXX If we reattach to a controller after it's been initialized, it might have
+ // attachments we don't know about. Try to figure out what this one is.
+ if (header->message_type == GIP_CMD_HID_REPORT && num_bytes == 8) {
+- if (!attachment->keyboard) {
+- attachment->keyboard = (SDL_KeyboardID)(uintptr_t) attachment;
+- SDL_AddKeyboard(attachment->keyboard, "Xbox One Chatpad");
+- }
++ // if (!attachment->keyboard) {
++ // attachment->keyboard = (SDL_KeyboardID)(uintptr_t) attachment;
++ // SDL_AddKeyboard(attachment->keyboard, "Xbox One Chatpad");
++ // }
+ attachment->attachment_type = GIP_TYPE_CHATPAD;
+ attachment->metadata.device.in_system_messages[0] |= (1u << GIP_CMD_HID_REPORT);
+ }
+@@ -3069,9 +3069,9 @@ static void HIDAPI_DriverGIP_FreeDevice(SDL_HIDAPI_Device *device)
+ SDL_free(attachment->fragment_data);
+ attachment->fragment_data = NULL;
+ }
+- if (attachment->keyboard) {
+- SDL_RemoveKeyboard(attachment->keyboard);
+- }
++ // if (attachment->keyboard) {
++ // SDL_RemoveKeyboard(attachment->keyboard);
++ // }
+ GIP_MetadataFree(&attachment->metadata);
+ SDL_free(attachment);
+ context->attachments[i] = NULL;
+diff --git a/thirdparty/sdl/SDL.c b/thirdparty/sdl/SDL.c
+index 41216d3fd7..40982f2cfc 100644
+--- a/thirdparty/sdl/SDL.c
++++ b/thirdparty/sdl/SDL.c
+@@ -59,7 +59,9 @@
+ // #include "video/SDL_pixels_c.h"
+ // #include "video/SDL_surface_c.h"
+ // #include "video/SDL_video_c.h"
+-// #include "filesystem/SDL_filesystem_c.h"
++#ifndef SDL_FILESYSTEM_DUMMY // Godot change
++#include "filesystem/SDL_filesystem_c.h"
++#endif
+ // #include "io/SDL_asyncio_c.h"
+ #ifdef SDL_PLATFORM_ANDROID
+ #include "core/android/SDL_android.h"
+@@ -300,8 +302,10 @@ void SDL_InitMainThread(void)
+
+ SDL_InitTLSData();
+ SDL_InitEnvironment();
+- SDL_InitTicks();
+- // SDL_InitFilesystem();
++ SDL_InitTicks();
++#ifndef SDL_FILESYSTEM_DUMMY // Godot change
++ SDL_InitFilesystem();
++#endif
+
+ if (!done_info) {
+ const char *value;
+@@ -320,7 +324,9 @@ void SDL_InitMainThread(void)
+
+ static void SDL_QuitMainThread(void)
+ {
+- // SDL_QuitFilesystem();
++#ifndef SDL_FILESYSTEM_DUMMY // Godot change
++ SDL_QuitFilesystem();
++#endif
+ SDL_QuitTicks();
+ SDL_QuitEnvironment();
+ SDL_QuitTLSData();
+diff --git a/thirdparty/sdl/time/SDL_time.c b/thirdparty/sdl/time/SDL_time.c
+index ba0a2cf7fa..8f1492b3df 100644
+--- a/thirdparty/sdl/time/SDL_time.c
++++ b/thirdparty/sdl/time/SDL_time.c
+@@ -66,7 +66,7 @@ bool SDL_GetDateTimeLocalePreferences(SDL_DateFormat *dateFormat, SDL_TimeFormat
+ *timeFormat = SDL_TIME_FORMAT_24HR;
+ }
+
+- SDL_GetSystemTimeLocalePreferences(dateFormat, timeFormat);
++ // SDL_GetSystemTimeLocalePreferences(dateFormat, timeFormat);
+
+ return true;
+ }
diff --git a/thirdparty/sdl/patches/0005-fix-libudev-dbus.patch b/thirdparty/sdl/patches/0005-fix-libudev-dbus.patch
index e3af445a41a..33d2826daae 100644
--- a/thirdparty/sdl/patches/0005-fix-libudev-dbus.patch
+++ b/thirdparty/sdl/patches/0005-fix-libudev-dbus.patch
@@ -1,8 +1,8 @@
diff --git a/thirdparty/sdl/core/linux/SDL_dbus.c b/thirdparty/sdl/core/linux/SDL_dbus.c
-index 9a2fc1ea531..9dc5c266732 100644
+index cd7f77a100..663e70427a 100644
--- a/thirdparty/sdl/core/linux/SDL_dbus.c
+++ b/thirdparty/sdl/core/linux/SDL_dbus.c
-@@ -97,15 +97,18 @@ static bool LoadDBUSSyms(void)
+@@ -115,15 +115,18 @@ static bool LoadDBUSSyms(void)
static void UnloadDBUSLibrary(void)
{
@@ -21,7 +21,7 @@ index 9a2fc1ea531..9dc5c266732 100644
if (!dbus_handle) {
dbus_handle = SDL_LoadObject(dbus_library);
if (!dbus_handle) {
-@@ -118,6 +121,9 @@ static bool LoadDBUSLibrary(void)
+@@ -136,6 +139,9 @@ static bool LoadDBUSLibrary(void)
}
}
}
@@ -32,21 +32,22 @@ index 9a2fc1ea531..9dc5c266732 100644
}
diff --git a/thirdparty/sdl/core/linux/SDL_udev.c b/thirdparty/sdl/core/linux/SDL_udev.c
-index 907c34c7f66..fbf2ff04440 100644
+index 3aaa0fb4e9..58b0b1ed42 100644
--- a/thirdparty/sdl/core/linux/SDL_udev.c
+++ b/thirdparty/sdl/core/linux/SDL_udev.c
-@@ -38,7 +38,8 @@
-
- static const char *SDL_UDEV_LIBS[] = { "libudev.so.1", "libudev.so.0" };
+@@ -53,7 +53,9 @@ SDL_ELF_NOTE_DLOPEN(
+ SDL_UDEV_DLNOTE_LIBS
+ )
-static SDL_UDEV_PrivateData *_this = NULL;
++// static SDL_UDEV_PrivateData *_this = NULL;
+SDL_UDEV_PrivateData *SDL_UDEV_PrivateData_this = NULL;
+#define _this SDL_UDEV_PrivateData_this
static bool SDL_UDEV_load_sym(const char *fn, void **addr);
static bool SDL_UDEV_load_syms(void);
diff --git a/thirdparty/sdl/core/linux/SDL_udev.h b/thirdparty/sdl/core/linux/SDL_udev.h
-index 738f4bafe3f..50bed36248e 100644
+index f2b1ce56e2..5958ba4f37 100644
--- a/thirdparty/sdl/core/linux/SDL_udev.h
+++ b/thirdparty/sdl/core/linux/SDL_udev.h
@@ -30,7 +30,8 @@
@@ -54,13 +55,13 @@ index 738f4bafe3f..50bed36248e 100644
#endif
-#include <libudev.h>
-+//#include <libudev.h>
++// #include <libudev.h>
+#include <thirdparty/linuxbsd_headers/udev/libudev.h>
+ #include <linux/input.h>
#include <sys/time.h>
#include <sys/types.h>
-
diff --git a/thirdparty/sdl/hidapi/linux/hid.c b/thirdparty/sdl/hidapi/linux/hid.c
-index dbbb3277854..51a32ef892f 100644
+index c0cb6a7b0e..367b243830 100644
--- a/thirdparty/sdl/hidapi/linux/hid.c
+++ b/thirdparty/sdl/hidapi/linux/hid.c
@@ -40,7 +40,37 @@
@@ -68,7 +69,7 @@ index dbbb3277854..51a32ef892f 100644
#include <linux/version.h>
#include <linux/input.h>
-#include <libudev.h>
-+//#include <libudev.h>
++// #include <libudev.h>
+#include "SDL_udev.h"
+extern SDL_UDEV_PrivateData *SDL_UDEV_PrivateData_this;
+#define udev_device_get_action (SDL_UDEV_PrivateData_this->syms.udev_device_get_action)
@@ -103,7 +104,7 @@ index dbbb3277854..51a32ef892f 100644
#include "../hidapi/hidapi.h"
diff --git a/thirdparty/sdl/loadso/dlopen/SDL_sysloadso.c b/thirdparty/sdl/loadso/dlopen/SDL_sysloadso.c
-index c84d1a1b5f9..e09c09080cd 100644
+index 7d223ce75e..e45b5093f8 100644
--- a/thirdparty/sdl/loadso/dlopen/SDL_sysloadso.c
+++ b/thirdparty/sdl/loadso/dlopen/SDL_sysloadso.c
@@ -65,8 +65,8 @@ SDL_FunctionPointer SDL_LoadFunction(SDL_SharedObject *handle, const char *name)
@@ -112,8 +113,8 @@ index c84d1a1b5f9..e09c09080cd 100644
if (!symbol) {
- SDL_SetError("Failed loading %s: %s", name,
- (const char *)dlerror());
-+ //SDL_SetError("Failed loading %s: %s", name,
-+ // (const char *)dlerror());
++ // SDL_SetError("Failed loading %s: %s", name,
++ // (const char *)dlerror());
}
}
return symbol;
diff --git a/thirdparty/sdl/patches/0006-fix-cs-environ.patch b/thirdparty/sdl/patches/0006-fix-cs-environ.patch
index 7ed530e58ac..27672cfb61f 100644
--- a/thirdparty/sdl/patches/0006-fix-cs-environ.patch
+++ b/thirdparty/sdl/patches/0006-fix-cs-environ.patch
@@ -1,5 +1,5 @@
diff --git a/thirdparty/sdl/stdlib/SDL_getenv.c b/thirdparty/sdl/stdlib/SDL_getenv.c
-index 54fb6a7b46..d805217b19 100644
+index 1517b5974b..17220c69ae 100644
--- a/thirdparty/sdl/stdlib/SDL_getenv.c
+++ b/thirdparty/sdl/stdlib/SDL_getenv.c
@@ -55,6 +55,9 @@ extern char **environ;
@@ -39,8 +39,8 @@ index 54fb6a7b46..d805217b19 100644
+#else
bool result = false;
- if (!env) {
-@@ -286,10 +296,14 @@ bool SDL_SetEnvironmentVariable(SDL_Environment *env, const char *name, const ch
+ CHECK_PARAM(!env) {
+@@ -288,10 +298,14 @@ bool SDL_SetEnvironmentVariable(SDL_Environment *env, const char *name, const ch
SDL_UnlockMutex(env->lock);
return result;
@@ -54,8 +54,8 @@ index 54fb6a7b46..d805217b19 100644
+#else
bool result = false;
- if (!env) {
-@@ -310,6 +324,7 @@ bool SDL_UnsetEnvironmentVariable(SDL_Environment *env, const char *name)
+ CHECK_PARAM(!env) {
+@@ -313,6 +327,7 @@ bool SDL_UnsetEnvironmentVariable(SDL_Environment *env, const char *name)
SDL_UnlockMutex(env->lock);
return result;
diff --git a/thirdparty/sdl/patches/0007-ios-accelerometer.patch b/thirdparty/sdl/patches/0007-ios-accelerometer.patch
new file mode 100644
index 00000000000..2b045b74589
--- /dev/null
+++ b/thirdparty/sdl/patches/0007-ios-accelerometer.patch
@@ -0,0 +1,45 @@
+diff --git a/thirdparty/sdl/joystick/apple/SDL_mfijoystick.m b/thirdparty/sdl/joystick/apple/SDL_mfijoystick.m
+index 98756f2eab..5f1abf110f 100644
+--- a/thirdparty/sdl/joystick/apple/SDL_mfijoystick.m
++++ b/thirdparty/sdl/joystick/apple/SDL_mfijoystick.m
+@@ -945,8 +945,6 @@ static bool IOS_JoystickOpen(SDL_Joystick *joystick, int device_index)
+ GCMotion *motion = controller.motion;
+ if (motion && motion.hasRotationRate) {
+ SDL_PrivateJoystickAddSensor(joystick, SDL_SENSOR_GYRO, 0.0f);
+- }
+- if (motion && motion.hasGravityAndUserAcceleration) {
+ SDL_PrivateJoystickAddSensor(joystick, SDL_SENSOR_ACCEL, 0.0f);
+ }
+ }
+@@ -1197,20 +1195,17 @@ static void IOS_MFIJoystickUpdate(SDL_Joystick *joystick)
+ if (motion && motion.sensorsActive) {
+ float data[3];
+
+- if (motion.hasRotationRate) {
+- GCRotationRate rate = motion.rotationRate;
+- data[0] = rate.x;
+- data[1] = rate.z;
+- data[2] = -rate.y;
+- SDL_SendJoystickSensor(timestamp, joystick, SDL_SENSOR_GYRO, timestamp, data, 3);
+- }
+- if (motion.hasGravityAndUserAcceleration) {
+- GCAcceleration accel = motion.acceleration;
+- data[0] = -accel.x * SDL_STANDARD_GRAVITY;
+- data[1] = -accel.y * SDL_STANDARD_GRAVITY;
+- data[2] = -accel.z * SDL_STANDARD_GRAVITY;
+- SDL_SendJoystickSensor(timestamp, joystick, SDL_SENSOR_ACCEL, timestamp, data, 3);
+- }
++ GCRotationRate rate = motion.rotationRate;
++ data[0] = rate.x;
++ data[1] = rate.z;
++ data[2] = -rate.y;
++ SDL_SendJoystickSensor(timestamp, joystick, SDL_SENSOR_GYRO, timestamp, data, 3);
++
++ GCAcceleration accel = motion.acceleration;
++ data[0] = -accel.x * SDL_STANDARD_GRAVITY;
++ data[1] = -accel.y * SDL_STANDARD_GRAVITY;
++ data[2] = -accel.z * SDL_STANDARD_GRAVITY;
++ SDL_SendJoystickSensor(timestamp, joystick, SDL_SENSOR_ACCEL, timestamp, data, 3);
+ }
+ }
+
diff --git a/thirdparty/sdl/patches/0007-shield-duplicate-macos.patch b/thirdparty/sdl/patches/0007-shield-duplicate-macos.patch
deleted file mode 100644
index 9795f7bffff..00000000000
--- a/thirdparty/sdl/patches/0007-shield-duplicate-macos.patch
+++ /dev/null
@@ -1,55 +0,0 @@
-diff --git a/thirdparty/sdl/joystick/apple/SDL_mfijoystick.m b/thirdparty/sdl/joystick/apple/SDL_mfijoystick.m
-index 48e9051798..3e8f4a8bab 100644
---- a/thirdparty/sdl/joystick/apple/SDL_mfijoystick.m
-+++ b/thirdparty/sdl/joystick/apple/SDL_mfijoystick.m
-@@ -158,6 +158,13 @@ static bool IsControllerSwitchJoyConPair(GCController *controller)
- }
- return false;
- }
-+static bool IsControllerNVIDIASHIELD(GCController *controller)
-+{
-+ if ([controller.vendorName hasPrefix:@"NVIDIA Controller"]) {
-+ return true;
-+ }
-+ return false;
-+}
- static bool IsControllerStadia(GCController *controller)
- {
- if ([controller.vendorName hasPrefix:@"Stadia"]) {
-@@ -339,6 +346,7 @@ static bool IOS_AddMFIJoystickDevice(SDL_JoystickDeviceItem *device, GCControlle
- device->is_ps5 = IsControllerPS5(controller);
- device->is_switch_pro = IsControllerSwitchPro(controller);
- device->is_switch_joycon_pair = IsControllerSwitchJoyConPair(controller);
-+ device->is_shield = IsControllerNVIDIASHIELD(controller);
- device->is_stadia = IsControllerStadia(controller);
- device->is_backbone_one = IsControllerBackboneOne(controller);
- device->is_switch_joyconL = IsControllerSwitchJoyConL(controller);
-@@ -350,6 +358,7 @@ static bool IOS_AddMFIJoystickDevice(SDL_JoystickDeviceItem *device, GCControlle
- (device->is_ps5 && HIDAPI_IsDeviceTypePresent(SDL_GAMEPAD_TYPE_PS5)) ||
- (device->is_switch_pro && HIDAPI_IsDeviceTypePresent(SDL_GAMEPAD_TYPE_NINTENDO_SWITCH_PRO)) ||
- (device->is_switch_joycon_pair && HIDAPI_IsDevicePresent(USB_VENDOR_NINTENDO, USB_PRODUCT_NINTENDO_SWITCH_JOYCON_PAIR, 0, "")) ||
-+ (device->is_shield && HIDAPI_IsDevicePresent(USB_VENDOR_NVIDIA, USB_PRODUCT_NVIDIA_SHIELD_CONTROLLER_V104, 0, "")) ||
- (device->is_stadia && HIDAPI_IsDevicePresent(USB_VENDOR_GOOGLE, USB_PRODUCT_GOOGLE_STADIA_CONTROLLER, 0, "")) ||
- (device->is_switch_joyconL && HIDAPI_IsDevicePresent(USB_VENDOR_NINTENDO, USB_PRODUCT_NINTENDO_SWITCH_JOYCON_LEFT, 0, "")) ||
- (device->is_switch_joyconR && HIDAPI_IsDevicePresent(USB_VENDOR_NINTENDO, USB_PRODUCT_NINTENDO_SWITCH_JOYCON_RIGHT, 0, ""))) {
-@@ -486,7 +495,7 @@ static bool IOS_AddMFIJoystickDevice(SDL_JoystickDeviceItem *device, GCControlle
- subtype = 4;
-
- #ifdef DEBUG_CONTROLLER_PROFILE
-- NSLog(@"Elements used:\n", controller.vendorName);
-+ NSLog(@"Elements used:\n");
- for (id key in device->buttons) {
- NSLog(@"\tButton: %@ (%s)\n", key, elements[key].analog ? "analog" : "digital");
- }
-diff --git a/thirdparty/sdl/joystick/apple/SDL_mfijoystick_c.h b/thirdparty/sdl/joystick/apple/SDL_mfijoystick_c.h
-index 783b3f488c..dfa7615964 100644
---- a/thirdparty/sdl/joystick/apple/SDL_mfijoystick_c.h
-+++ b/thirdparty/sdl/joystick/apple/SDL_mfijoystick_c.h
-@@ -53,6 +53,7 @@ typedef struct joystick_hwdata
- bool is_switch_joycon_pair;
- bool is_switch_joyconL;
- bool is_switch_joyconR;
-+ bool is_shield;
- bool is_stadia;
- bool is_backbone_one;
- int is_siri_remote;
diff --git a/thirdparty/sdl/patches/0008-fix-linux-joycon-serial-num.patch b/thirdparty/sdl/patches/0008-fix-linux-joycon-serial-num.patch
deleted file mode 100644
index 7491f527777..00000000000
--- a/thirdparty/sdl/patches/0008-fix-linux-joycon-serial-num.patch
+++ /dev/null
@@ -1,78 +0,0 @@
-diff --git a/thirdparty/sdl/core/linux/SDL_udev.c b/thirdparty/sdl/core/linux/SDL_udev.c
-index fbf2ff0444..d9e7e11849 100644
---- a/thirdparty/sdl/core/linux/SDL_udev.c
-+++ b/thirdparty/sdl/core/linux/SDL_udev.c
-@@ -277,6 +277,43 @@ bool SDL_UDEV_GetProductInfo(const char *device_path, Uint16 *vendor, Uint16 *pr
- return true;
- }
-
-+bool SDL_UDEV_GetProductSerial(const char *device_path, const char **serial)
-+{
-+ struct stat statbuf;
-+ char type;
-+ struct udev_device *dev;
-+ const char *val;
-+
-+ if (!_this) {
-+ return false;
-+ }
-+
-+ if (stat(device_path, &statbuf) < 0) {
-+ return false;
-+ }
-+
-+ if (S_ISBLK(statbuf.st_mode)) {
-+ type = 'b';
-+ } else if (S_ISCHR(statbuf.st_mode)) {
-+ type = 'c';
-+ } else {
-+ return false;
-+ }
-+
-+ dev = _this->syms.udev_device_new_from_devnum(_this->udev, type, statbuf.st_rdev);
-+ if (!dev) {
-+ return false;
-+ }
-+
-+ val = _this->syms.udev_device_get_property_value(dev, "ID_SERIAL_SHORT");
-+ if (val) {
-+ *serial = val;
-+ return true;
-+ }
-+
-+ return false;
-+}
-+
- void SDL_UDEV_UnloadLibrary(void)
- {
- if (!_this) {
-diff --git a/thirdparty/sdl/core/linux/SDL_udev.h b/thirdparty/sdl/core/linux/SDL_udev.h
-index 50bed36248..05b79342cd 100644
---- a/thirdparty/sdl/core/linux/SDL_udev.h
-+++ b/thirdparty/sdl/core/linux/SDL_udev.h
-@@ -104,6 +104,7 @@ extern bool SDL_UDEV_LoadLibrary(void);
- extern void SDL_UDEV_Poll(void);
- extern bool SDL_UDEV_Scan(void);
- extern bool SDL_UDEV_GetProductInfo(const char *device_path, Uint16 *vendor, Uint16 *product, Uint16 *version, int *class);
-+extern bool SDL_UDEV_GetProductSerial(const char *device_path, const char **serial);
- extern bool SDL_UDEV_AddCallback(SDL_UDEV_Callback cb);
- extern void SDL_UDEV_DelCallback(SDL_UDEV_Callback cb);
- extern const SDL_UDEV_Symbols *SDL_UDEV_GetUdevSyms(void);
-diff --git a/thirdparty/sdl/joystick/linux/SDL_sysjoystick.c b/thirdparty/sdl/joystick/linux/SDL_sysjoystick.c
-index ea73821c06..70fed1cf57 100644
---- a/thirdparty/sdl/joystick/linux/SDL_sysjoystick.c
-+++ b/thirdparty/sdl/joystick/linux/SDL_sysjoystick.c
-@@ -1587,6 +1587,13 @@ static bool LINUX_JoystickOpen(SDL_Joystick *joystick, int device_index)
- item_sensor->hwdata = joystick->hwdata;
- }
-
-+ #ifdef SDL_USE_LIBUDEV
-+ const char *serial = NULL;
-+ if (SDL_UDEV_GetProductSerial(item->path, &serial)) {
-+ joystick->serial = SDL_strdup(serial);
-+ }
-+ #endif
-+
- // mark joystick as fresh and ready
- joystick->hwdata->fresh = true;
-
diff --git a/thirdparty/sdl/patches/0009-update-device-blocklist.patch b/thirdparty/sdl/patches/0009-update-device-blocklist.patch
deleted file mode 100644
index 6edc2ec8f92..00000000000
--- a/thirdparty/sdl/patches/0009-update-device-blocklist.patch
+++ /dev/null
@@ -1,27 +0,0 @@
-diff --git a/thirdparty/sdl/joystick/SDL_joystick.c b/thirdparty/sdl/joystick/SDL_joystick.c
-index 090dc07303..768f8f9025 100644
---- a/thirdparty/sdl/joystick/SDL_joystick.c
-+++ b/thirdparty/sdl/joystick/SDL_joystick.c
-@@ -273,14 +273,20 @@ static Uint32 initial_blacklist_devices[] = {
- MAKE_VIDPID(0x04d9, 0x8009), // OBINLB USB-HID Keyboard (Anne Pro II)
- MAKE_VIDPID(0x04d9, 0xa292), // OBINLB USB-HID Keyboard (Anne Pro II)
- MAKE_VIDPID(0x04d9, 0xa293), // OBINLB USB-HID Keyboard (Anne Pro II)
-+ MAKE_VIDPID(0x04f2, 0xa13c), // HP Deluxe Webcam KQ246AA
-+ MAKE_VIDPID(0x0e6f, 0x018a), // PDP REALMz Wireless Controller for Switch, USB charging
- MAKE_VIDPID(0x1532, 0x0266), // Razer Huntsman V2 Analog, non-functional DInput device
- MAKE_VIDPID(0x1532, 0x0282), // Razer Huntsman Mini Analog, non-functional DInput device
-- MAKE_VIDPID(0x26ce, 0x01a2), // ASRock LED Controller
- MAKE_VIDPID(0x20d6, 0x0002), // PowerA Enhanced Wireless Controller for Nintendo Switch (charging port only)
-+ MAKE_VIDPID(0x256c, 0x006d), // Huion Tablet_GS1331, Huion Tablet_GS1331 Touch Strip
-+ MAKE_VIDPID(0x26ce, 0x01a2), // ASRock LED Controller
- MAKE_VIDPID(0x31e3, 0x1310), // Wooting 60HE (ARM)
- MAKE_VIDPID(0x3297, 0x1969), // Moonlander MK1 Keyboard
-+ MAKE_VIDPID(0x3434, 0x0121), // Keychron Q3 System Control
- MAKE_VIDPID(0x3434, 0x0211), // Keychron K1 Pro System Control
-- MAKE_VIDPID(0x04f2, 0xa13c), // HP Deluxe Webcam KQ246AA
-+ MAKE_VIDPID(0x3434, 0x02a0), // Keychron K10 Pro System Control
-+ MAKE_VIDPID(0x3434, 0x0353), // Keychron V5 System Control
-+ MAKE_VIDPID(0x3434, 0xd030), // Keychron Link
- };
- static SDL_vidpid_list blacklist_devices = {
- SDL_HINT_JOYSTICK_BLACKLIST_DEVICES, 0, 0, NULL,
diff --git a/thirdparty/sdl/sensor/SDL_sensor.c b/thirdparty/sdl/sensor/SDL_sensor.c
index 60e829a982b..d3eb58fbf43 100644
--- a/thirdparty/sdl/sensor/SDL_sensor.c
+++ b/thirdparty/sdl/sensor/SDL_sensor.c
@@ -1,6 +1,6 @@
/*
Simple DirectMedia Layer
- Copyright (C) 1997-2025 Sam Lantinga <[email protected]>
+ Copyright (C) 1997-2026 Sam Lantinga <[email protected]>
This software is provided 'as-is', without any express or implied
warranty. In no event will the authors be held liable for any damages
@@ -43,6 +43,9 @@ static SDL_SensorDriver *SDL_sensor_drivers[] = {
#ifdef SDL_SENSOR_N3DS
&SDL_N3DS_SensorDriver,
#endif
+#ifdef SDL_SENSOR_EMSCRIPTEN
+ &SDL_EMSCRIPTEN_SensorDriver,
+#endif
#if defined(SDL_SENSOR_DUMMY) || defined(SDL_SENSOR_DISABLED)
&SDL_DUMMY_SensorDriver
#endif
@@ -57,11 +60,11 @@ static int SDL_sensors_locked;
static bool SDL_sensors_initialized;
static SDL_Sensor *SDL_sensors SDL_GUARDED_BY(SDL_sensor_lock) = NULL;
-#define CHECK_SENSOR_MAGIC(sensor, result) \
- if (!SDL_ObjectValid(sensor, SDL_OBJECT_TYPE_SENSOR)) { \
- SDL_InvalidParamError("sensor"); \
- SDL_UnlockSensors(); \
- return result; \
+#define CHECK_SENSOR_MAGIC(sensor, result) \
+ CHECK_PARAM(!SDL_ObjectValid(sensor, SDL_OBJECT_TYPE_SENSOR)) { \
+ SDL_InvalidParamError("sensor"); \
+ SDL_UnlockSensors(); \
+ return result; \
}
bool SDL_SensorsInitialized(void)
diff --git a/thirdparty/sdl/sensor/SDL_sensor_c.h b/thirdparty/sdl/sensor/SDL_sensor_c.h
index 26a988efce2..90c05d4ec63 100644
--- a/thirdparty/sdl/sensor/SDL_sensor_c.h
+++ b/thirdparty/sdl/sensor/SDL_sensor_c.h
@@ -1,6 +1,6 @@
/*
Simple DirectMedia Layer
- Copyright (C) 1997-2025 Sam Lantinga <[email protected]>
+ Copyright (C) 1997-2026 Sam Lantinga <[email protected]>
This software is provided 'as-is', without any express or implied
warranty. In no event will the authors be held liable for any damages
diff --git a/thirdparty/sdl/sensor/SDL_syssensor.h b/thirdparty/sdl/sensor/SDL_syssensor.h
index 1ce63e5d7fa..6c6ccf83c7c 100644
--- a/thirdparty/sdl/sensor/SDL_syssensor.h
+++ b/thirdparty/sdl/sensor/SDL_syssensor.h
@@ -1,6 +1,6 @@
/*
Simple DirectMedia Layer
- Copyright (C) 1997-2025 Sam Lantinga <[email protected]>
+ Copyright (C) 1997-2026 Sam Lantinga <[email protected]>
This software is provided 'as-is', without any express or implied
warranty. In no event will the authors be held liable for any damages
@@ -20,8 +20,8 @@
*/
#include "SDL_internal.h"
-#ifndef SDL_syssensor_c_h_
-#define SDL_syssensor_c_h_
+#ifndef SDL_syssensor_h_
+#define SDL_syssensor_h_
// This is the system specific header for the SDL sensor API
@@ -106,5 +106,6 @@ extern SDL_SensorDriver SDL_WINDOWS_SensorDriver;
extern SDL_SensorDriver SDL_DUMMY_SensorDriver;
extern SDL_SensorDriver SDL_VITA_SensorDriver;
extern SDL_SensorDriver SDL_N3DS_SensorDriver;
+extern SDL_SensorDriver SDL_EMSCRIPTEN_SensorDriver;
#endif // SDL_syssensor_h_
diff --git a/thirdparty/sdl/sensor/dummy/SDL_dummysensor.c b/thirdparty/sdl/sensor/dummy/SDL_dummysensor.c
index ce8145da3e2..41600a60cfd 100644
--- a/thirdparty/sdl/sensor/dummy/SDL_dummysensor.c
+++ b/thirdparty/sdl/sensor/dummy/SDL_dummysensor.c
@@ -1,6 +1,6 @@
/*
Simple DirectMedia Layer
- Copyright (C) 1997-2025 Sam Lantinga <[email protected]>
+ Copyright (C) 1997-2026 Sam Lantinga <[email protected]>
This software is provided 'as-is', without any express or implied
warranty. In no event will the authors be held liable for any damages
diff --git a/thirdparty/sdl/sensor/dummy/SDL_dummysensor.h b/thirdparty/sdl/sensor/dummy/SDL_dummysensor.h
index 4b0c6f8fcc8..b2b446f54ec 100644
--- a/thirdparty/sdl/sensor/dummy/SDL_dummysensor.h
+++ b/thirdparty/sdl/sensor/dummy/SDL_dummysensor.h
@@ -1,6 +1,6 @@
/*
Simple DirectMedia Layer
- Copyright (C) 1997-2025 Sam Lantinga <[email protected]>
+ Copyright (C) 1997-2026 Sam Lantinga <[email protected]>
This software is provided 'as-is', without any express or implied
warranty. In no event will the authors be held liable for any damages
diff --git a/thirdparty/sdl/sensor/windows/SDL_windowssensor.c b/thirdparty/sdl/sensor/windows/SDL_windowssensor.c
index 059747eeb42..e2696b0bbb2 100644
--- a/thirdparty/sdl/sensor/windows/SDL_windowssensor.c
+++ b/thirdparty/sdl/sensor/windows/SDL_windowssensor.c
@@ -1,6 +1,6 @@
/*
Simple DirectMedia Layer
- Copyright (C) 1997-2025 Sam Lantinga <[email protected]>
+ Copyright (C) 1997-2026 Sam Lantinga <[email protected]>
This software is provided 'as-is', without any express or implied
warranty. In no event will the authors be held liable for any damages
diff --git a/thirdparty/sdl/sensor/windows/SDL_windowssensor.h b/thirdparty/sdl/sensor/windows/SDL_windowssensor.h
index 4b0c6f8fcc8..b2b446f54ec 100644
--- a/thirdparty/sdl/sensor/windows/SDL_windowssensor.h
+++ b/thirdparty/sdl/sensor/windows/SDL_windowssensor.h
@@ -1,6 +1,6 @@
/*
Simple DirectMedia Layer
- Copyright (C) 1997-2025 Sam Lantinga <[email protected]>
+ Copyright (C) 1997-2026 Sam Lantinga <[email protected]>
This software is provided 'as-is', without any express or implied
warranty. In no event will the authors be held liable for any damages
diff --git a/thirdparty/sdl/stdlib/SDL_casefolding.h b/thirdparty/sdl/stdlib/SDL_casefolding.h
index 6fbe0a7f7c0..f3a0a317363 100644
--- a/thirdparty/sdl/stdlib/SDL_casefolding.h
+++ b/thirdparty/sdl/stdlib/SDL_casefolding.h
@@ -1,6 +1,6 @@
/*
Simple DirectMedia Layer
- Copyright (C) 1997-2025 Sam Lantinga <[email protected]>
+ Copyright (C) 1997-2026 Sam Lantinga <[email protected]>
This software is provided 'as-is', without any express or implied
warranty. In no event will the authors be held liable for any damages
diff --git a/thirdparty/sdl/stdlib/SDL_crc16.c b/thirdparty/sdl/stdlib/SDL_crc16.c
index 828ce942c67..e525d3119bc 100644
--- a/thirdparty/sdl/stdlib/SDL_crc16.c
+++ b/thirdparty/sdl/stdlib/SDL_crc16.c
@@ -1,6 +1,6 @@
/*
Simple DirectMedia Layer
- Copyright (C) 1997-2025 Sam Lantinga <[email protected]>
+ Copyright (C) 1997-2026 Sam Lantinga <[email protected]>
This software is provided 'as-is', without any express or implied
warranty. In no event will the authors be held liable for any damages
diff --git a/thirdparty/sdl/stdlib/SDL_crc32.c b/thirdparty/sdl/stdlib/SDL_crc32.c
index 9c2d0977db7..8bad67dd762 100644
--- a/thirdparty/sdl/stdlib/SDL_crc32.c
+++ b/thirdparty/sdl/stdlib/SDL_crc32.c
@@ -1,6 +1,6 @@
/*
Simple DirectMedia Layer
- Copyright (C) 1997-2025 Sam Lantinga <[email protected]>
+ Copyright (C) 1997-2026 Sam Lantinga <[email protected]>
This software is provided 'as-is', without any express or implied
warranty. In no event will the authors be held liable for any damages
diff --git a/thirdparty/sdl/stdlib/SDL_getenv.c b/thirdparty/sdl/stdlib/SDL_getenv.c
index d805217b197..17220c69ae6 100644
--- a/thirdparty/sdl/stdlib/SDL_getenv.c
+++ b/thirdparty/sdl/stdlib/SDL_getenv.c
@@ -1,6 +1,6 @@
/*
Simple DirectMedia Layer
- Copyright (C) 1997-2025 Sam Lantinga <[email protected]>
+ Copyright (C) 1997-2026 Sam Lantinga <[email protected]>
This software is provided 'as-is', without any express or implied
warranty. In no event will the authors be held liable for any damages
@@ -229,7 +229,7 @@ char **SDL_GetEnvironmentVariables(SDL_Environment *env)
{
char **result = NULL;
- if (!env) {
+ CHECK_PARAM(!env) {
SDL_InvalidParamError("env");
return NULL;
}
@@ -263,11 +263,13 @@ bool SDL_SetEnvironmentVariable(SDL_Environment *env, const char *name, const ch
#else
bool result = false;
- if (!env) {
+ CHECK_PARAM(!env) {
return SDL_InvalidParamError("env");
- } else if (!name || *name == '\0' || SDL_strchr(name, '=') != NULL) {
+ }
+ CHECK_PARAM(!name || *name == '\0' || SDL_strchr(name, '=') != NULL) {
return SDL_InvalidParamError("name");
- } else if (!value) {
+ }
+ CHECK_PARAM(!value) {
return SDL_InvalidParamError("value");
}
@@ -306,9 +308,10 @@ bool SDL_UnsetEnvironmentVariable(SDL_Environment *env, const char *name)
#else
bool result = false;
- if (!env) {
+ CHECK_PARAM(!env) {
return SDL_InvalidParamError("env");
- } else if (!name || *name == '\0' || SDL_strchr(name, '=') != NULL) {
+ }
+ CHECK_PARAM(!name || *name == '\0' || SDL_strchr(name, '=') != NULL) {
return SDL_InvalidParamError("name");
}
@@ -349,7 +352,9 @@ int SDL_setenv_unsafe(const char *name, const char *value, int overwrite)
return -1;
}
- SDL_SetEnvironmentVariable(SDL_GetEnvironment(), name, value, (overwrite != 0));
+ if (SDL_environment) {
+ SDL_SetEnvironmentVariable(SDL_environment, name, value, (overwrite != 0));
+ }
return setenv(name, value, overwrite);
}
@@ -364,7 +369,9 @@ int SDL_setenv_unsafe(const char *name, const char *value, int overwrite)
return -1;
}
- SDL_SetEnvironmentVariable(SDL_GetEnvironment(), name, value, (overwrite != 0));
+ if (SDL_environment) {
+ SDL_SetEnvironmentVariable(SDL_environment, name, value, (overwrite != 0));
+ }
if (getenv(name) != NULL) {
if (!overwrite) {
@@ -388,7 +395,9 @@ int SDL_setenv_unsafe(const char *name, const char *value, int overwrite)
return -1;
}
- SDL_SetEnvironmentVariable(SDL_GetEnvironment(), name, value, (overwrite != 0));
+ if (SDL_environment) {
+ SDL_SetEnvironmentVariable(SDL_environment, name, value, (overwrite != 0));
+ }
if (!overwrite) {
if (GetEnvironmentVariableA(name, NULL, 0) > 0) {
@@ -419,7 +428,9 @@ int SDL_setenv_unsafe(const char *name, const char *value, int overwrite)
return 0;
}
- SDL_SetEnvironmentVariable(SDL_GetEnvironment(), name, value, (overwrite != 0));
+ if (SDL_environment) {
+ SDL_SetEnvironmentVariable(SDL_environment, name, value, (overwrite != 0));
+ }
// Allocate memory for the variable
len = SDL_strlen(name) + SDL_strlen(value) + 2;
@@ -474,7 +485,9 @@ int SDL_unsetenv_unsafe(const char *name)
return -1;
}
- SDL_UnsetEnvironmentVariable(SDL_GetEnvironment(), name);
+ if (SDL_environment) {
+ SDL_UnsetEnvironmentVariable(SDL_environment, name);
+ }
return unsetenv(name);
}
@@ -487,7 +500,9 @@ int SDL_unsetenv_unsafe(const char *name)
return -1;
}
- SDL_UnsetEnvironmentVariable(SDL_GetEnvironment(), name);
+ if (SDL_environment) {
+ SDL_UnsetEnvironmentVariable(SDL_environment, name);
+ }
// Hope this environment uses the non-standard extension of removing the environment variable if it has no '='
return putenv(name);
@@ -501,7 +516,9 @@ int SDL_unsetenv_unsafe(const char *name)
return -1;
}
- SDL_UnsetEnvironmentVariable(SDL_GetEnvironment(), name);
+ if (SDL_environment) {
+ SDL_UnsetEnvironmentVariable(SDL_environment, name);
+ }
if (!SetEnvironmentVariableA(name, NULL)) {
return -1;
@@ -518,7 +535,9 @@ int SDL_unsetenv_unsafe(const char *name)
return -1;
}
- SDL_UnsetEnvironmentVariable(SDL_GetEnvironment(), name);
+ if (SDL_environment) {
+ SDL_UnsetEnvironmentVariable(SDL_environment, name);
+ }
if (environ) {
len = SDL_strlen(name);
@@ -576,9 +595,7 @@ const char *SDL_getenv_unsafe(const char *name)
maxlen = length;
} else {
if (GetLastError() != ERROR_SUCCESS) {
- if (string) {
- SDL_free(string);
- }
+ SDL_free(string);
return NULL;
}
break;
diff --git a/thirdparty/sdl/stdlib/SDL_getenv_c.h b/thirdparty/sdl/stdlib/SDL_getenv_c.h
index 9cf997da761..544d48f102e 100644
--- a/thirdparty/sdl/stdlib/SDL_getenv_c.h
+++ b/thirdparty/sdl/stdlib/SDL_getenv_c.h
@@ -1,6 +1,6 @@
/*
Simple DirectMedia Layer
- Copyright (C) 1997-2025 Sam Lantinga <[email protected]>
+ Copyright (C) 1997-2026 Sam Lantinga <[email protected]>
This software is provided 'as-is', without any express or implied
warranty. In no event will the authors be held liable for any damages
diff --git a/thirdparty/sdl/stdlib/SDL_iconv.c b/thirdparty/sdl/stdlib/SDL_iconv.c
index fbea0331948..c07f6cf9450 100644
--- a/thirdparty/sdl/stdlib/SDL_iconv.c
+++ b/thirdparty/sdl/stdlib/SDL_iconv.c
@@ -1,6 +1,6 @@
/*
Simple DirectMedia Layer
- Copyright (C) 1997-2025 Sam Lantinga <[email protected]>
+ Copyright (C) 1997-2026 Sam Lantinga <[email protected]>
This software is provided 'as-is', without any express or implied
warranty. In no event will the authors be held liable for any damages
diff --git a/thirdparty/sdl/stdlib/SDL_malloc.c b/thirdparty/sdl/stdlib/SDL_malloc.c
index 0ccdf39a91c..ebbe8ec0f2c 100644
--- a/thirdparty/sdl/stdlib/SDL_malloc.c
+++ b/thirdparty/sdl/stdlib/SDL_malloc.c
@@ -1,6 +1,6 @@
/*
Simple DirectMedia Layer
- Copyright (C) 1997-2025 Sam Lantinga <[email protected]>
+ Copyright (C) 1997-2026 Sam Lantinga <[email protected]>
This software is provided 'as-is', without any express or implied
warranty. In no event will the authors be held liable for any damages
@@ -3042,7 +3042,7 @@ static size_t traverse_and_check(mstate m);
http://www.usenix.org/events/lisa03/tech/robertson.html The footer
of an inuse chunk holds the xor of its mstate and a random seed,
that is checked upon calls to free() and realloc(). This is
- (probabalistically) unguessable from outside the program, but can be
+ (probabilistically) unguessable from outside the program, but can be
computed by any code successfully malloc'ing any chunk, so does not
itself provide protection against code that has already broken
security through some other means. Unlike Robertson et al, we
@@ -6419,16 +6419,16 @@ bool SDL_SetMemoryFunctions(SDL_malloc_func malloc_func,
SDL_realloc_func realloc_func,
SDL_free_func free_func)
{
- if (!malloc_func) {
+ CHECK_PARAM(!malloc_func) {
return SDL_InvalidParamError("malloc_func");
}
- if (!calloc_func) {
+ CHECK_PARAM(!calloc_func) {
return SDL_InvalidParamError("calloc_func");
}
- if (!realloc_func) {
+ CHECK_PARAM(!realloc_func) {
return SDL_InvalidParamError("realloc_func");
}
- if (!free_func) {
+ CHECK_PARAM(!free_func) {
return SDL_InvalidParamError("free_func");
}
diff --git a/thirdparty/sdl/stdlib/SDL_memcpy.c b/thirdparty/sdl/stdlib/SDL_memcpy.c
index 315edf023e3..eb2c1604411 100644
--- a/thirdparty/sdl/stdlib/SDL_memcpy.c
+++ b/thirdparty/sdl/stdlib/SDL_memcpy.c
@@ -1,6 +1,6 @@
/*
Simple DirectMedia Layer
- Copyright (C) 1997-2025 Sam Lantinga <[email protected]>
+ Copyright (C) 1997-2026 Sam Lantinga <[email protected]>
This software is provided 'as-is', without any express or implied
warranty. In no event will the authors be held liable for any damages
diff --git a/thirdparty/sdl/stdlib/SDL_memmove.c b/thirdparty/sdl/stdlib/SDL_memmove.c
index 4e0d26c4bf5..5df0af35686 100644
--- a/thirdparty/sdl/stdlib/SDL_memmove.c
+++ b/thirdparty/sdl/stdlib/SDL_memmove.c
@@ -1,6 +1,6 @@
/*
Simple DirectMedia Layer
- Copyright (C) 1997-2025 Sam Lantinga <[email protected]>
+ Copyright (C) 1997-2026 Sam Lantinga <[email protected]>
This software is provided 'as-is', without any express or implied
warranty. In no event will the authors be held liable for any damages
diff --git a/thirdparty/sdl/stdlib/SDL_memset.c b/thirdparty/sdl/stdlib/SDL_memset.c
index 324f91787d2..d12df67cf13 100644
--- a/thirdparty/sdl/stdlib/SDL_memset.c
+++ b/thirdparty/sdl/stdlib/SDL_memset.c
@@ -1,6 +1,6 @@
/*
Simple DirectMedia Layer
- Copyright (C) 1997-2025 Sam Lantinga <[email protected]>
+ Copyright (C) 1997-2026 Sam Lantinga <[email protected]>
This software is provided 'as-is', without any express or implied
warranty. In no event will the authors be held liable for any damages
diff --git a/thirdparty/sdl/stdlib/SDL_mslibc.c b/thirdparty/sdl/stdlib/SDL_mslibc.c
index 1dfc76166b3..f3b8481453d 100644
--- a/thirdparty/sdl/stdlib/SDL_mslibc.c
+++ b/thirdparty/sdl/stdlib/SDL_mslibc.c
@@ -1,6 +1,6 @@
/*
Simple DirectMedia Layer
- Copyright (C) 1997-2025 Sam Lantinga <[email protected]>
+ Copyright (C) 1997-2026 Sam Lantinga <[email protected]>
This software is provided 'as-is', without any express or implied
warranty. In no event will the authors be held liable for any damages
diff --git a/thirdparty/sdl/stdlib/SDL_murmur3.c b/thirdparty/sdl/stdlib/SDL_murmur3.c
index 6b030bd9509..7f5556696fb 100644
--- a/thirdparty/sdl/stdlib/SDL_murmur3.c
+++ b/thirdparty/sdl/stdlib/SDL_murmur3.c
@@ -1,6 +1,6 @@
/*
Simple DirectMedia Layer
- Copyright (C) 1997-2025 Sam Lantinga <[email protected]>
+ Copyright (C) 1997-2026 Sam Lantinga <[email protected]>
This software is provided 'as-is', without any express or implied
warranty. In no event will the authors be held liable for any damages
diff --git a/thirdparty/sdl/stdlib/SDL_qsort.c b/thirdparty/sdl/stdlib/SDL_qsort.c
index 4ed2863e504..45460f68534 100644
--- a/thirdparty/sdl/stdlib/SDL_qsort.c
+++ b/thirdparty/sdl/stdlib/SDL_qsort.c
@@ -1,6 +1,6 @@
/*
Simple DirectMedia Layer
- Copyright (C) 1997-2025 Sam Lantinga <[email protected]>
+ Copyright (C) 1997-2026 Sam Lantinga <[email protected]>
This software is provided 'as-is', without any express or implied
warranty. In no event will the authors be held liable for any damages
@@ -333,7 +333,7 @@ typedef struct { char * first; char * last; } stack_entry;
char *test; \
/* Find the right place for |first|. \
* My apologies for var reuse. */ \
- for (test=first-size;compare(userdata,test,first)>0;test-=size) ; \
+ for (test=first-size;test>=(char*)base&&compare(userdata,test,first)>0;test-=size) ; \
test+=size; \
if (test!=first) { \
/* Shift everything in [test,first) \
@@ -418,6 +418,7 @@ static void qsort_r_nonaligned(void *base, size_t nmemb, size_t size,
while (1) {
/* Select pivot */
{ char * mid=first+size*((last-first)/size >> 1);
+ if (mid>=last) break;
Pivot(SWAP_nonaligned,size);
memcpy(pivot,mid,size);
}
@@ -449,6 +450,7 @@ static void qsort_r_aligned(void *base, size_t nmemb, size_t size,
while (1) {
/* Select pivot */
{ char * mid=first+size*((last-first)/size >> 1);
+ if (mid>=last) break;
Pivot(SWAP_aligned,size);
memcpy(pivot,mid,size);
}
@@ -484,6 +486,7 @@ fprintf(stderr,"Doing %d:%d: ",
#endif
/* Select pivot */
{ char * mid=first+WORD_BYTES*((last-first) / (2*WORD_BYTES));
+ if (mid>=last) break;
Pivot(SWAP_words,WORD_BYTES);
*(int*)pivot=*(int*)mid;
#ifdef DEBUG_QSORT
@@ -506,7 +509,7 @@ fprintf(stderr, "after partitioning first=#%lu last=#%lu\n", (first-(char*)base)
/* Find the right place for |first|. My apologies for var reuse */
int *pl=(int*)(first-WORD_BYTES),*pr=(int*)first;
*(int*)pivot=*(int*)first;
- for (;compare(userdata,pl,pivot)>0;pr=pl,--pl) {
+ for (;pl>=(int*)base&&compare(userdata,pl,pivot)>0;pr=pl,--pl) {
*pr=*pl; }
if (pr!=(int*)first) *pr=*(int*)pivot;
}
@@ -571,4 +574,3 @@ void *SDL_bsearch(const void *key, const void *base, size_t nmemb, size_t size,
// qsort_non_r_bridge just happens to match calling conventions, so reuse it.
return SDL_bsearch_r(key, base, nmemb, size, qsort_non_r_bridge, compare);
}
-
diff --git a/thirdparty/sdl/stdlib/SDL_random.c b/thirdparty/sdl/stdlib/SDL_random.c
index a774d30c967..747d85413fa 100644
--- a/thirdparty/sdl/stdlib/SDL_random.c
+++ b/thirdparty/sdl/stdlib/SDL_random.c
@@ -1,6 +1,6 @@
/*
Simple DirectMedia Layer
- Copyright (C) 1997-2025 Sam Lantinga <[email protected]>
+ Copyright (C) 1997-2026 Sam Lantinga <[email protected]>
This software is provided 'as-is', without any express or implied
warranty. In no event will the authors be held liable for any damages
@@ -110,6 +110,12 @@ Sint32 SDL_rand_r(Uint64 *state, Sint32 n)
float SDL_randf_r(Uint64 *state)
{
// Note: its using 24 bits because float has 23 bits significand + 1 implicit bit
+#if (defined(_MSC_VER) && (_MSC_VER < 1913)) || (!defined(_MSC_VER) && (!defined(__STDC_VERSION__) || (__STDC_VERSION__ < 199901L)))
+ // no hexidecimal float notation, do it the hard way. MSVC before 15.6 (2017), etc, needs this.
+ const union { Uint32 u32; float f; } float_union = { 0x33800000U };
+ return (SDL_rand_bits_r(state) >> (32 - 24)) * float_union.f;
+#else
return (SDL_rand_bits_r(state) >> (32 - 24)) * 0x1p-24f;
+#endif
}
diff --git a/thirdparty/sdl/stdlib/SDL_stdlib.c b/thirdparty/sdl/stdlib/SDL_stdlib.c
index 093b2bec479..1c55dc984e7 100644
--- a/thirdparty/sdl/stdlib/SDL_stdlib.c
+++ b/thirdparty/sdl/stdlib/SDL_stdlib.c
@@ -1,6 +1,6 @@
/*
Simple DirectMedia Layer
- Copyright (C) 1997-2025 Sam Lantinga <[email protected]>
+ Copyright (C) 1997-2026 Sam Lantinga <[email protected]>
This software is provided 'as-is', without any express or implied
warranty. In no event will the authors be held liable for any damages
@@ -140,12 +140,6 @@ double SDL_copysign(double x, double y)
return copysign(x, y);
#elif defined(HAVE__COPYSIGN)
return _copysign(x, y);
-#elif defined(__WATCOMC__) && defined(__386__)
- // this is nasty as hell, but it works..
- unsigned int *xi = (unsigned int *)&x,
- *yi = (unsigned int *)&y;
- xi[1] = (yi[1] & 0x80000000) | (xi[1] & 0x7fffffff);
- return x;
#else
return SDL_uclibc_copysign(x, y);
#endif // HAVE_COPYSIGN
@@ -535,8 +529,8 @@ void *SDL_aligned_alloc(size_t alignment, size_t size)
Uint8 *result = NULL;
size_t requested_size = size;
- if (alignment < sizeof(void*)) {
- alignment = sizeof(void*);
+ if (alignment < sizeof(void *)) {
+ alignment = sizeof(void *);
}
padding = (alignment - (size % alignment));
diff --git a/thirdparty/sdl/stdlib/SDL_string.c b/thirdparty/sdl/stdlib/SDL_string.c
index 79679a1f444..e0e7d573370 100644
--- a/thirdparty/sdl/stdlib/SDL_string.c
+++ b/thirdparty/sdl/stdlib/SDL_string.c
@@ -1,6 +1,6 @@
/*
Simple DirectMedia Layer
- Copyright (C) 1997-2025 Sam Lantinga <[email protected]>
+ Copyright (C) 1997-2026 Sam Lantinga <[email protected]>
This software is provided 'as-is', without any express or implied
warranty. In no event will the authors be held liable for any damages
@@ -34,6 +34,8 @@
#if defined(__SIZEOF_WCHAR_T__)
#define SDL_SIZEOF_WCHAR_T __SIZEOF_WCHAR_T__
+#elif defined(SDL_PLATFORM_NGAGE)
+#define SDL_SIZEOF_WCHAR_T 2
#elif defined(SDL_PLATFORM_WINDOWS)
#define SDL_SIZEOF_WCHAR_T 2
#else // assume everything else is UTF-32 (add more tests if compiler-assert fails below!)
@@ -716,7 +718,7 @@ int SDL_memcmp(const void *s1, const void *s2, size_t len)
++s2p;
}
return 0;
-#endif // HAVE_MEMCMP
+#endif // SDL_PLATFORM_VITA
}
size_t SDL_strlen(const char *string)
@@ -1117,7 +1119,7 @@ char *SDL_strnstr(const char *haystack, const char *needle, size_t maxlen)
--maxlen;
}
return NULL;
-#endif // HAVE_STRSTR
+#endif // HAVE_STRNSTR
}
char *SDL_strstr(const char *haystack, const char *needle)
@@ -1151,6 +1153,11 @@ static const char ntoa_table[] = {
};
#endif // ntoa() conversion table
+char *SDL_uitoa(unsigned int value, char *string, int radix)
+{
+ return SDL_ultoa((unsigned long)value, string, radix);
+}
+
char *SDL_itoa(int value, char *string, int radix)
{
#ifdef HAVE_ITOA
@@ -1160,15 +1167,6 @@ char *SDL_itoa(int value, char *string, int radix)
#endif // HAVE_ITOA
}
-char *SDL_uitoa(unsigned int value, char *string, int radix)
-{
-#ifdef HAVE__UITOA
- return _uitoa(value, string, radix);
-#else
- return SDL_ultoa((unsigned long)value, string, radix);
-#endif // HAVE__UITOA
-}
-
char *SDL_ltoa(long value, char *string, int radix)
{
#ifdef HAVE__LTOA
@@ -1828,24 +1826,7 @@ int SDL_swprintf(SDL_OUT_Z_CAP(maxlen) wchar_t *text, size_t maxlen, SDL_PRINTF_
return result;
}
-#if defined(HAVE_LIBC) && defined(__WATCOMC__)
-// _vsnprintf() doesn't ensure nul termination
-int SDL_vsnprintf(SDL_OUT_Z_CAP(maxlen) char *text, size_t maxlen, const char *fmt, va_list ap)
-{
- int result;
- if (!fmt) {
- fmt = "";
- }
- result = _vsnprintf(text, maxlen, fmt, ap);
- if (maxlen > 0) {
- text[maxlen - 1] = '\0';
- }
- if (result < 0) {
- result = (int)maxlen;
- }
- return result;
-}
-#elif defined(HAVE_VSNPRINTF)
+#if defined(HAVE_VSNPRINTF)
int SDL_vsnprintf(SDL_OUT_Z_CAP(maxlen) char *text, size_t maxlen, const char *fmt, va_list ap)
{
if (!fmt) {
@@ -2373,6 +2354,10 @@ int SDL_vsnprintf(SDL_OUT_Z_CAP(maxlen) char *text, size_t maxlen, SDL_PRINTF_FO
int SDL_vswprintf(SDL_OUT_Z_CAP(maxlen) wchar_t *text, size_t maxlen, const wchar_t *fmt, va_list ap)
{
+ if (text) {
+ text[0] = 0;
+ }
+
char *fmt_utf8 = NULL;
if (fmt) {
fmt_utf8 = SDL_iconv_string("UTF-8", "WCHAR_T", (const char *)fmt, (SDL_wcslen(fmt) + 1) * sizeof(wchar_t));
@@ -2494,7 +2479,7 @@ int SDL_vasprintf(char **strp, SDL_PRINTF_FORMAT_STRING const char *fmt, va_list
char * SDL_strpbrk(const char *str, const char *breakset)
{
#ifdef HAVE_STRPBRK
- return strpbrk(str, breakset);
+ return SDL_const_cast(char *, strpbrk(str, breakset));
#else
for (; *str; str++) {
diff --git a/thirdparty/sdl/stdlib/SDL_strtokr.c b/thirdparty/sdl/stdlib/SDL_strtokr.c
index e60080895d3..c3be5e9bb68 100644
--- a/thirdparty/sdl/stdlib/SDL_strtokr.c
+++ b/thirdparty/sdl/stdlib/SDL_strtokr.c
@@ -1,6 +1,6 @@
/*
Simple DirectMedia Layer
- Copyright (C) 1997-2025 Sam Lantinga <[email protected]>
+ Copyright (C) 1997-2026 Sam Lantinga <[email protected]>
This software is provided 'as-is', without any express or implied
warranty. In no event will the authors be held liable for any damages
diff --git a/thirdparty/sdl/stdlib/SDL_sysstdlib.h b/thirdparty/sdl/stdlib/SDL_sysstdlib.h
index 7d43ab0d425..bdc49f2a467 100644
--- a/thirdparty/sdl/stdlib/SDL_sysstdlib.h
+++ b/thirdparty/sdl/stdlib/SDL_sysstdlib.h
@@ -1,6 +1,6 @@
/*
Simple DirectMedia Layer
- Copyright (C) 1997-2025 Sam Lantinga <[email protected]>
+ Copyright (C) 1997-2026 Sam Lantinga <[email protected]>
This software is provided 'as-is', without any express or implied
warranty. In no event will the authors be held liable for any damages
diff --git a/thirdparty/sdl/stdlib/SDL_vacopy.h b/thirdparty/sdl/stdlib/SDL_vacopy.h
index fee560e4684..4aa6a8d679d 100644
--- a/thirdparty/sdl/stdlib/SDL_vacopy.h
+++ b/thirdparty/sdl/stdlib/SDL_vacopy.h
@@ -1,6 +1,6 @@
/*
Simple DirectMedia Layer
- Copyright (C) 1997-2025 Sam Lantinga <[email protected]>
+ Copyright (C) 1997-2026 Sam Lantinga <[email protected]>
This software is provided 'as-is', without any express or implied
warranty. In no event will the authors be held liable for any damages
@@ -20,11 +20,12 @@
*/
// Do our best to make sure va_copy is working
-#if defined(_MSC_VER) && _MSC_VER <= 1800
+#if (defined(_MSC_VER) && _MSC_VER <= 1800) || defined(__SYMBIAN32__)
// Visual Studio 2013 tries to link with _vacopy in the C runtime. Newer versions do an inline assignment
#undef va_copy
#define va_copy(dst, src) dst = src
#elif defined(__GNUC__) && (__GNUC__ < 3)
#define va_copy(dst, src) __va_copy(dst, src)
+
#endif
diff --git a/thirdparty/sdl/thread/SDL_systhread.h b/thirdparty/sdl/thread/SDL_systhread.h
index 596b248b650..13d107fc598 100644
--- a/thirdparty/sdl/thread/SDL_systhread.h
+++ b/thirdparty/sdl/thread/SDL_systhread.h
@@ -1,6 +1,6 @@
/*
Simple DirectMedia Layer
- Copyright (C) 1997-2025 Sam Lantinga <[email protected]>
+ Copyright (C) 1997-2026 Sam Lantinga <[email protected]>
This software is provided 'as-is', without any express or implied
warranty. In no event will the authors be held liable for any damages
diff --git a/thirdparty/sdl/thread/SDL_thread.c b/thirdparty/sdl/thread/SDL_thread.c
index f31e670b9d4..639090c4982 100644
--- a/thirdparty/sdl/thread/SDL_thread.c
+++ b/thirdparty/sdl/thread/SDL_thread.c
@@ -1,6 +1,6 @@
/*
Simple DirectMedia Layer
- Copyright (C) 1997-2025 Sam Lantinga <[email protected]>
+ Copyright (C) 1997-2026 Sam Lantinga <[email protected]>
This software is provided 'as-is', without any express or implied
warranty. In no event will the authors be held liable for any damages
@@ -41,7 +41,7 @@ void *SDL_GetTLS(SDL_TLSID *id)
SDL_TLSData *storage;
int storage_index;
- if (id == NULL) {
+ CHECK_PARAM(id == NULL) {
SDL_InvalidParamError("id");
return NULL;
}
@@ -59,7 +59,7 @@ bool SDL_SetTLS(SDL_TLSID *id, const void *value, SDL_TLSDestructorCallback dest
SDL_TLSData *storage;
int storage_index;
- if (id == NULL) {
+ CHECK_PARAM(id == NULL) {
return SDL_InvalidParamError("id");
}
@@ -99,7 +99,7 @@ bool SDL_SetTLS(SDL_TLSID *id, const void *value, SDL_TLSDestructorCallback dest
oldlimit = storage ? storage->limit : 0;
newlimit = (storage_index + TLS_ALLOC_CHUNKSIZE);
- new_storage = (SDL_TLSData *)SDL_realloc(storage, sizeof(*storage) + (newlimit - 1) * sizeof(storage->array[0]));
+ new_storage = (SDL_TLSData *)SDL_realloc(storage, sizeof(*storage) + newlimit * sizeof(storage->array[0]));
if (!new_storage) {
return false;
}
@@ -262,9 +262,12 @@ void SDL_Generic_QuitTLSData(void)
static SDL_error *SDL_GetStaticErrBuf(void)
{
static SDL_error SDL_global_error;
- static char SDL_global_error_str[128];
- SDL_global_error.str = SDL_global_error_str;
- SDL_global_error.len = sizeof(SDL_global_error_str);
+ static char SDL_global_error_str1[128];
+ static char SDL_global_error_str2[128];
+ SDL_global_error.info[0].str = SDL_global_error_str1;
+ SDL_global_error.info[0].len = sizeof(SDL_global_error_str1);
+ SDL_global_error.info[1].str = SDL_global_error_str2;
+ SDL_global_error.info[1].len = sizeof(SDL_global_error_str2);
return &SDL_global_error;
}
@@ -272,9 +275,11 @@ static SDL_error *SDL_GetStaticErrBuf(void)
static void SDLCALL SDL_FreeErrBuf(void *data)
{
SDL_error *errbuf = (SDL_error *)data;
-
- if (errbuf->str) {
- errbuf->free_func(errbuf->str);
+ if (errbuf->info[0].str) {
+ errbuf->free_func(errbuf->info[0].str);
+ }
+ if (errbuf->info[1].str) {
+ errbuf->free_func(errbuf->info[1].str);
}
errbuf->free_func(errbuf);
}
@@ -330,9 +335,6 @@ void SDL_RunThread(SDL_Thread *thread)
// Perform any system-dependent setup - this function may not fail
SDL_SYS_SetupThread(thread->name);
- // Get the thread id
- thread->threadid = SDL_GetCurrentThreadID();
-
// Run the function
*statusloc = userfunc(userdata);
@@ -401,7 +403,7 @@ SDL_Thread *SDL_CreateThreadWithPropertiesRuntime(SDL_PropertiesID props,
SDL_SetObjectValid(thread, SDL_OBJECT_TYPE_THREAD, false);
SDL_free(thread->name);
SDL_free(thread);
- thread = NULL;
+ return NULL;
}
// Everything is running now
diff --git a/thirdparty/sdl/thread/SDL_thread_c.h b/thirdparty/sdl/thread/SDL_thread_c.h
index 3368016a6c9..3659b85cc4a 100644
--- a/thirdparty/sdl/thread/SDL_thread_c.h
+++ b/thirdparty/sdl/thread/SDL_thread_c.h
@@ -1,6 +1,6 @@
/*
Simple DirectMedia Layer
- Copyright (C) 1997-2025 Sam Lantinga <[email protected]>
+ Copyright (C) 1997-2026 Sam Lantinga <[email protected]>
This software is provided 'as-is', without any express or implied
warranty. In no event will the authors be held liable for any damages
@@ -67,11 +67,18 @@ extern void SDL_RunThread(SDL_Thread *thread);
typedef struct
{
int limit;
+#ifdef _MSC_VER
+#pragma warning(push)
+#pragma warning(disable : 4200) // Flexible array members (C99)
+#endif
struct
{
void *data;
void(SDLCALL *destructor)(void *);
- } array[1];
+ } array[];
+#ifdef _MSC_VER
+#pragma warning(pop)
+#endif
} SDL_TLSData;
// This is how many TLS entries we allocate at once
diff --git a/thirdparty/sdl/thread/generic/SDL_syscond.c b/thirdparty/sdl/thread/generic/SDL_syscond.c
index 5fdfe842e39..9db9dab1149 100644
--- a/thirdparty/sdl/thread/generic/SDL_syscond.c
+++ b/thirdparty/sdl/thread/generic/SDL_syscond.c
@@ -1,6 +1,6 @@
/*
Simple DirectMedia Layer
- Copyright (C) 1997-2025 Sam Lantinga <[email protected]>
+ Copyright (C) 1997-2026 Sam Lantinga <[email protected]>
This software is provided 'as-is', without any express or implied
warranty. In no event will the authors be held liable for any damages
diff --git a/thirdparty/sdl/thread/generic/SDL_syscond_c.h b/thirdparty/sdl/thread/generic/SDL_syscond_c.h
index 253c3945bf2..72323a8b11b 100644
--- a/thirdparty/sdl/thread/generic/SDL_syscond_c.h
+++ b/thirdparty/sdl/thread/generic/SDL_syscond_c.h
@@ -1,6 +1,6 @@
/*
Simple DirectMedia Layer
- Copyright (C) 1997-2025 Sam Lantinga <[email protected]>
+ Copyright (C) 1997-2026 Sam Lantinga <[email protected]>
This software is provided 'as-is', without any express or implied
warranty. In no event will the authors be held liable for any damages
diff --git a/thirdparty/sdl/thread/generic/SDL_sysrwlock.c b/thirdparty/sdl/thread/generic/SDL_sysrwlock.c
index 24caf51b2f6..8650c104f08 100644
--- a/thirdparty/sdl/thread/generic/SDL_sysrwlock.c
+++ b/thirdparty/sdl/thread/generic/SDL_sysrwlock.c
@@ -1,6 +1,6 @@
/*
Simple DirectMedia Layer
- Copyright (C) 1997-2025 Sam Lantinga <[email protected]>
+ Copyright (C) 1997-2026 Sam Lantinga <[email protected]>
This software is provided 'as-is', without any express or implied
warranty. In no event will the authors be held liable for any damages
diff --git a/thirdparty/sdl/thread/generic/SDL_sysrwlock_c.h b/thirdparty/sdl/thread/generic/SDL_sysrwlock_c.h
index 9589d253127..b8dbe12d934 100644
--- a/thirdparty/sdl/thread/generic/SDL_sysrwlock_c.h
+++ b/thirdparty/sdl/thread/generic/SDL_sysrwlock_c.h
@@ -1,6 +1,6 @@
/*
Simple DirectMedia Layer
- Copyright (C) 1997-2025 Sam Lantinga <[email protected]>
+ Copyright (C) 1997-2026 Sam Lantinga <[email protected]>
This software is provided 'as-is', without any express or implied
warranty. In no event will the authors be held liable for any damages
diff --git a/thirdparty/sdl/thread/generic/SDL_syssem.c b/thirdparty/sdl/thread/generic/SDL_syssem.c
index dcd6fcc64fe..1cdd0c13a19 100644
--- a/thirdparty/sdl/thread/generic/SDL_syssem.c
+++ b/thirdparty/sdl/thread/generic/SDL_syssem.c
@@ -1,6 +1,6 @@
/*
Simple DirectMedia Layer
- Copyright (C) 1997-2025 Sam Lantinga <[email protected]>
+ Copyright (C) 1997-2026 Sam Lantinga <[email protected]>
This software is provided 'as-is', without any express or implied
warranty. In no event will the authors be held liable for any damages
diff --git a/thirdparty/sdl/thread/generic/SDL_systhread_c.h b/thirdparty/sdl/thread/generic/SDL_systhread_c.h
index 9ba55fd87a9..4348b9cf825 100644
--- a/thirdparty/sdl/thread/generic/SDL_systhread_c.h
+++ b/thirdparty/sdl/thread/generic/SDL_systhread_c.h
@@ -1,6 +1,6 @@
/*
Simple DirectMedia Layer
- Copyright (C) 1997-2025 Sam Lantinga <[email protected]>
+ Copyright (C) 1997-2026 Sam Lantinga <[email protected]>
This software is provided 'as-is', without any express or implied
warranty. In no event will the authors be held liable for any damages
diff --git a/thirdparty/sdl/thread/pthread/SDL_syscond.c b/thirdparty/sdl/thread/pthread/SDL_syscond.c
index c3e4098f907..9849f5e4f9a 100644
--- a/thirdparty/sdl/thread/pthread/SDL_syscond.c
+++ b/thirdparty/sdl/thread/pthread/SDL_syscond.c
@@ -1,6 +1,6 @@
/*
Simple DirectMedia Layer
- Copyright (C) 1997-2025 Sam Lantinga <[email protected]>
+ Copyright (C) 1997-2026 Sam Lantinga <[email protected]>
This software is provided 'as-is', without any express or implied
warranty. In no event will the authors be held liable for any damages
diff --git a/thirdparty/sdl/thread/pthread/SDL_sysmutex.c b/thirdparty/sdl/thread/pthread/SDL_sysmutex.c
index 7bba286e1ad..7e033423228 100644
--- a/thirdparty/sdl/thread/pthread/SDL_sysmutex.c
+++ b/thirdparty/sdl/thread/pthread/SDL_sysmutex.c
@@ -1,6 +1,6 @@
/*
Simple DirectMedia Layer
- Copyright (C) 1997-2025 Sam Lantinga <[email protected]>
+ Copyright (C) 1997-2026 Sam Lantinga <[email protected]>
This software is provided 'as-is', without any express or implied
warranty. In no event will the authors be held liable for any damages
@@ -46,6 +46,7 @@ SDL_Mutex *SDL_CreateMutex(void)
SDL_free(mutex);
mutex = NULL;
}
+ pthread_mutexattr_destroy(&attr);
}
return mutex;
}
diff --git a/thirdparty/sdl/thread/pthread/SDL_sysmutex_c.h b/thirdparty/sdl/thread/pthread/SDL_sysmutex_c.h
index f69e7b319dd..8ef32bb983d 100644
--- a/thirdparty/sdl/thread/pthread/SDL_sysmutex_c.h
+++ b/thirdparty/sdl/thread/pthread/SDL_sysmutex_c.h
@@ -1,6 +1,6 @@
/*
Simple DirectMedia Layer
- Copyright (C) 1997-2025 Sam Lantinga <[email protected]>
+ Copyright (C) 1997-2026 Sam Lantinga <[email protected]>
This software is provided 'as-is', without any express or implied
warranty. In no event will the authors be held liable for any damages
diff --git a/thirdparty/sdl/thread/pthread/SDL_sysrwlock.c b/thirdparty/sdl/thread/pthread/SDL_sysrwlock.c
index 3cf02e5d133..ed7f5482e13 100644
--- a/thirdparty/sdl/thread/pthread/SDL_sysrwlock.c
+++ b/thirdparty/sdl/thread/pthread/SDL_sysrwlock.c
@@ -1,6 +1,6 @@
/*
Simple DirectMedia Layer
- Copyright (C) 1997-2025 Sam Lantinga <[email protected]>
+ Copyright (C) 1997-2026 Sam Lantinga <[email protected]>
This software is provided 'as-is', without any express or implied
warranty. In no event will the authors be held liable for any damages
diff --git a/thirdparty/sdl/thread/pthread/SDL_syssem.c b/thirdparty/sdl/thread/pthread/SDL_syssem.c
index d5d32982c66..a3a53185dd5 100644
--- a/thirdparty/sdl/thread/pthread/SDL_syssem.c
+++ b/thirdparty/sdl/thread/pthread/SDL_syssem.c
@@ -1,6 +1,6 @@
/*
Simple DirectMedia Layer
- Copyright (C) 1997-2025 Sam Lantinga <[email protected]>
+ Copyright (C) 1997-2026 Sam Lantinga <[email protected]>
This software is provided 'as-is', without any express or implied
warranty. In no event will the authors be held liable for any damages
diff --git a/thirdparty/sdl/thread/pthread/SDL_systhread.c b/thirdparty/sdl/thread/pthread/SDL_systhread.c
index ae4a94c2e27..f4d4c4d872a 100644
--- a/thirdparty/sdl/thread/pthread/SDL_systhread.c
+++ b/thirdparty/sdl/thread/pthread/SDL_systhread.c
@@ -1,6 +1,6 @@
/*
Simple DirectMedia Layer
- Copyright (C) 1997-2025 Sam Lantinga <[email protected]>
+ Copyright (C) 1997-2026 Sam Lantinga <[email protected]>
This software is provided 'as-is', without any express or implied
warranty. In no event will the authors be held liable for any damages
@@ -60,7 +60,7 @@
#ifdef HAVE_SIGNAL_H
// List of signals to mask in the subthreads
static const int sig_list[] = {
- SIGHUP, SIGINT, SIGQUIT, SIGPIPE, SIGALRM, SIGTERM, SIGCHLD, SIGWINCH,
+ SIGHUP, SIGINT, SIGQUIT, SIGPIPE, SIGALRM, SIGTERM, SIGWINCH,
SIGVTALRM, SIGPROF, 0
};
#endif
@@ -116,6 +116,8 @@ bool SDL_SYS_CreateThread(SDL_Thread *thread,
return SDL_SetError("Not enough resources to create thread");
}
+ thread->threadid = (SDL_ThreadID) thread->handle; // the SDL thread ID is just the pthread_t.
+
return true;
}
@@ -166,7 +168,7 @@ void SDL_SYS_SetupThread(const char *name)
for (i = 0; sig_list[i]; ++i) {
sigaddset(&mask, sig_list[i]);
}
- pthread_sigmask(SIG_BLOCK, &mask, 0);
+ pthread_sigmask(SIG_BLOCK, &mask, NULL);
#endif
#ifdef PTHREAD_CANCEL_ASYNCHRONOUS
@@ -284,7 +286,7 @@ bool SDL_SYS_SetThreadPriority(SDL_ThreadPriority priority)
void SDL_SYS_WaitThread(SDL_Thread *thread)
{
- pthread_join(thread->handle, 0);
+ pthread_join(thread->handle, NULL);
}
void SDL_SYS_DetachThread(SDL_Thread *thread)
diff --git a/thirdparty/sdl/thread/pthread/SDL_systhread_c.h b/thirdparty/sdl/thread/pthread/SDL_systhread_c.h
index bdfcd68c21a..3de62635521 100644
--- a/thirdparty/sdl/thread/pthread/SDL_systhread_c.h
+++ b/thirdparty/sdl/thread/pthread/SDL_systhread_c.h
@@ -1,6 +1,6 @@
/*
Simple DirectMedia Layer
- Copyright (C) 1997-2025 Sam Lantinga <[email protected]>
+ Copyright (C) 1997-2026 Sam Lantinga <[email protected]>
This software is provided 'as-is', without any express or implied
warranty. In no event will the authors be held liable for any damages
diff --git a/thirdparty/sdl/thread/pthread/SDL_systls.c b/thirdparty/sdl/thread/pthread/SDL_systls.c
index 18e9a01edf5..f3df542dcdf 100644
--- a/thirdparty/sdl/thread/pthread/SDL_systls.c
+++ b/thirdparty/sdl/thread/pthread/SDL_systls.c
@@ -1,6 +1,6 @@
/*
Simple DirectMedia Layer
- Copyright (C) 1997-2025 Sam Lantinga <[email protected]>
+ Copyright (C) 1997-2026 Sam Lantinga <[email protected]>
This software is provided 'as-is', without any express or implied
warranty. In no event will the authors be held liable for any damages
diff --git a/thirdparty/sdl/thread/windows/SDL_syscond_cv.c b/thirdparty/sdl/thread/windows/SDL_syscond_cv.c
index b29ef634e0b..5b5dcfe75b9 100644
--- a/thirdparty/sdl/thread/windows/SDL_syscond_cv.c
+++ b/thirdparty/sdl/thread/windows/SDL_syscond_cv.c
@@ -1,6 +1,6 @@
/*
Simple DirectMedia Layer
- Copyright (C) 1997-2025 Sam Lantinga <[email protected]>
+ Copyright (C) 1997-2026 Sam Lantinga <[email protected]>
This software is provided 'as-is', without any express or implied
warranty. In no event will the authors be held liable for any damages
@@ -56,10 +56,10 @@ typedef struct CONDITION_VARIABLE
} CONDITION_VARIABLE, *PCONDITION_VARIABLE;
#endif
-typedef VOID(WINAPI *pfnWakeConditionVariable)(PCONDITION_VARIABLE);
-typedef VOID(WINAPI *pfnWakeAllConditionVariable)(PCONDITION_VARIABLE);
-typedef BOOL(WINAPI *pfnSleepConditionVariableSRW)(PCONDITION_VARIABLE, PSRWLOCK, DWORD, ULONG);
-typedef BOOL(WINAPI *pfnSleepConditionVariableCS)(PCONDITION_VARIABLE, PCRITICAL_SECTION, DWORD);
+typedef VOID (WINAPI *pfnWakeConditionVariable)(PCONDITION_VARIABLE);
+typedef VOID (WINAPI *pfnWakeAllConditionVariable)(PCONDITION_VARIABLE);
+typedef BOOL (WINAPI *pfnSleepConditionVariableSRW)(PCONDITION_VARIABLE, PSRWLOCK, DWORD, ULONG);
+typedef BOOL (WINAPI *pfnSleepConditionVariableCS)(PCONDITION_VARIABLE, PCRITICAL_SECTION, DWORD);
static pfnWakeConditionVariable pWakeConditionVariable = NULL;
static pfnWakeAllConditionVariable pWakeAllConditionVariable = NULL;
diff --git a/thirdparty/sdl/thread/windows/SDL_sysmutex.c b/thirdparty/sdl/thread/windows/SDL_sysmutex.c
index 88ec0047c47..ef803a6727b 100644
--- a/thirdparty/sdl/thread/windows/SDL_sysmutex.c
+++ b/thirdparty/sdl/thread/windows/SDL_sysmutex.c
@@ -1,6 +1,6 @@
/*
Simple DirectMedia Layer
- Copyright (C) 1997-2025 Sam Lantinga <[email protected]>
+ Copyright (C) 1997-2026 Sam Lantinga <[email protected]>
This software is provided 'as-is', without any express or implied
warranty. In no event will the authors be held liable for any damages
@@ -39,10 +39,10 @@ SDL_mutex_impl_t SDL_mutex_impl_active = { 0 };
* Implementation based on Slim Reader/Writer (SRW) Locks for Win 7 and newer.
*/
-typedef VOID(WINAPI *pfnInitializeSRWLock)(PSRWLOCK);
-typedef VOID(WINAPI *pfnReleaseSRWLockExclusive)(PSRWLOCK);
-typedef VOID(WINAPI *pfnAcquireSRWLockExclusive)(PSRWLOCK);
-typedef BOOLEAN(WINAPI *pfnTryAcquireSRWLockExclusive)(PSRWLOCK);
+typedef VOID (WINAPI *pfnInitializeSRWLock)(PSRWLOCK);
+typedef VOID (WINAPI *pfnReleaseSRWLockExclusive)(PSRWLOCK);
+typedef VOID (WINAPI *pfnAcquireSRWLockExclusive)(PSRWLOCK);
+typedef BOOLEAN (WINAPI *pfnTryAcquireSRWLockExclusive)(PSRWLOCK);
static pfnInitializeSRWLock pInitializeSRWLock = NULL;
static pfnReleaseSRWLockExclusive pReleaseSRWLockExclusive = NULL;
static pfnAcquireSRWLockExclusive pAcquireSRWLockExclusive = NULL;
diff --git a/thirdparty/sdl/thread/windows/SDL_sysmutex_c.h b/thirdparty/sdl/thread/windows/SDL_sysmutex_c.h
index 762dc7c98cd..ffd96c85605 100644
--- a/thirdparty/sdl/thread/windows/SDL_sysmutex_c.h
+++ b/thirdparty/sdl/thread/windows/SDL_sysmutex_c.h
@@ -1,6 +1,6 @@
/*
Simple DirectMedia Layer
- Copyright (C) 1997-2025 Sam Lantinga <[email protected]>
+ Copyright (C) 1997-2026 Sam Lantinga <[email protected]>
This software is provided 'as-is', without any express or implied
warranty. In no event will the authors be held liable for any damages
diff --git a/thirdparty/sdl/thread/windows/SDL_sysrwlock_srw.c b/thirdparty/sdl/thread/windows/SDL_sysrwlock_srw.c
index ca1a48eb843..04ccf490f34 100644
--- a/thirdparty/sdl/thread/windows/SDL_sysrwlock_srw.c
+++ b/thirdparty/sdl/thread/windows/SDL_sysrwlock_srw.c
@@ -1,6 +1,6 @@
/*
Simple DirectMedia Layer
- Copyright (C) 1997-2025 Sam Lantinga <[email protected]>
+ Copyright (C) 1997-2026 Sam Lantinga <[email protected]>
This software is provided 'as-is', without any express or implied
warranty. In no event will the authors be held liable for any damages
@@ -27,13 +27,13 @@
// This header makes sure SRWLOCK is actually declared, even on ancient WinSDKs.
#include "SDL_sysmutex_c.h"
-typedef VOID(WINAPI *pfnInitializeSRWLock)(PSRWLOCK);
-typedef VOID(WINAPI *pfnReleaseSRWLockShared)(PSRWLOCK);
-typedef VOID(WINAPI *pfnAcquireSRWLockShared)(PSRWLOCK);
-typedef BOOLEAN(WINAPI *pfnTryAcquireSRWLockShared)(PSRWLOCK);
-typedef VOID(WINAPI *pfnReleaseSRWLockExclusive)(PSRWLOCK);
-typedef VOID(WINAPI *pfnAcquireSRWLockExclusive)(PSRWLOCK);
-typedef BOOLEAN(WINAPI *pfnTryAcquireSRWLockExclusive)(PSRWLOCK);
+typedef VOID (WINAPI *pfnInitializeSRWLock)(PSRWLOCK);
+typedef VOID (WINAPI *pfnReleaseSRWLockShared)(PSRWLOCK);
+typedef VOID (WINAPI *pfnAcquireSRWLockShared)(PSRWLOCK);
+typedef BOOLEAN (WINAPI *pfnTryAcquireSRWLockShared)(PSRWLOCK);
+typedef VOID (WINAPI *pfnReleaseSRWLockExclusive)(PSRWLOCK);
+typedef VOID (WINAPI *pfnAcquireSRWLockExclusive)(PSRWLOCK);
+typedef BOOLEAN (WINAPI *pfnTryAcquireSRWLockExclusive)(PSRWLOCK);
static pfnInitializeSRWLock pInitializeSRWLock = NULL;
static pfnReleaseSRWLockShared pReleaseSRWLockShared = NULL;
diff --git a/thirdparty/sdl/thread/windows/SDL_syssem.c b/thirdparty/sdl/thread/windows/SDL_syssem.c
index ba35add7d84..7f6d69f5275 100644
--- a/thirdparty/sdl/thread/windows/SDL_syssem.c
+++ b/thirdparty/sdl/thread/windows/SDL_syssem.c
@@ -1,6 +1,6 @@
/*
Simple DirectMedia Layer
- Copyright (C) 1997-2025 Sam Lantinga <[email protected]>
+ Copyright (C) 1997-2026 Sam Lantinga <[email protected]>
This software is provided 'as-is', without any express or implied
warranty. In no event will the authors be held liable for any damages
@@ -60,8 +60,8 @@ static SDL_sem_impl_t SDL_sem_impl_active = { 0 };
// APIs not available on WinPhone 8.1
// https://www.microsoft.com/en-us/download/details.aspx?id=47328
-typedef BOOL(WINAPI *pfnWaitOnAddress)(volatile VOID *, PVOID, SIZE_T, DWORD);
-typedef VOID(WINAPI *pfnWakeByAddressSingle)(PVOID);
+typedef BOOL (WINAPI *pfnWaitOnAddress)(volatile VOID *, PVOID, SIZE_T, DWORD);
+typedef VOID (WINAPI *pfnWakeByAddressSingle)(PVOID);
static pfnWaitOnAddress pWaitOnAddress = NULL;
static pfnWakeByAddressSingle pWakeByAddressSingle = NULL;
diff --git a/thirdparty/sdl/thread/windows/SDL_systhread.c b/thirdparty/sdl/thread/windows/SDL_systhread.c
index c5bee81f230..1244c344640 100644
--- a/thirdparty/sdl/thread/windows/SDL_systhread.c
+++ b/thirdparty/sdl/thread/windows/SDL_systhread.c
@@ -1,6 +1,6 @@
/*
Simple DirectMedia Layer
- Copyright (C) 1997-2025 Sam Lantinga <[email protected]>
+ Copyright (C) 1997-2026 Sam Lantinga <[email protected]>
This software is provided 'as-is', without any express or implied
warranty. In no event will the authors be held liable for any damages
@@ -77,15 +77,18 @@ bool SDL_SYS_CreateThread(SDL_Thread *thread,
thread->handle = (SYS_ThreadHandle)((size_t)pfnBeginThread(NULL, (unsigned int)thread->stacksize,
RunThreadViaBeginThreadEx,
thread, flags, &threadid));
+ thread->threadid = (SDL_ThreadID) threadid;
} else {
DWORD threadid = 0;
thread->handle = CreateThread(NULL, thread->stacksize,
RunThreadViaCreateThread,
thread, flags, &threadid);
+ thread->threadid = (SDL_ThreadID) threadid;
}
if (!thread->handle) {
return SDL_SetError("Not enough resources to create thread");
}
+
return true;
}
@@ -108,7 +111,7 @@ static LONG NTAPI EmptyVectoredExceptionHandler(EXCEPTION_POINTERS *info)
}
}
-typedef HRESULT(WINAPI *pfnSetThreadDescription)(HANDLE, PCWSTR);
+typedef HRESULT (WINAPI *pfnSetThreadDescription)(HANDLE, PCWSTR);
void SDL_SYS_SetupThread(const char *name)
{
diff --git a/thirdparty/sdl/thread/windows/SDL_systhread_c.h b/thirdparty/sdl/thread/windows/SDL_systhread_c.h
index 5787abb8d6a..d30990c63cb 100644
--- a/thirdparty/sdl/thread/windows/SDL_systhread_c.h
+++ b/thirdparty/sdl/thread/windows/SDL_systhread_c.h
@@ -1,6 +1,6 @@
/*
Simple DirectMedia Layer
- Copyright (C) 1997-2025 Sam Lantinga <[email protected]>
+ Copyright (C) 1997-2026 Sam Lantinga <[email protected]>
This software is provided 'as-is', without any express or implied
warranty. In no event will the authors be held liable for any damages
diff --git a/thirdparty/sdl/thread/windows/SDL_systls.c b/thirdparty/sdl/thread/windows/SDL_systls.c
index 354016a7eb4..dd73a3d8ea7 100644
--- a/thirdparty/sdl/thread/windows/SDL_systls.c
+++ b/thirdparty/sdl/thread/windows/SDL_systls.c
@@ -1,6 +1,6 @@
/*
Simple DirectMedia Layer
- Copyright (C) 1997-2025 Sam Lantinga <[email protected]>
+ Copyright (C) 1997-2026 Sam Lantinga <[email protected]>
This software is provided 'as-is', without any express or implied
warranty. In no event will the authors be held liable for any damages
diff --git a/thirdparty/sdl/time/SDL_time.c b/thirdparty/sdl/time/SDL_time.c
new file mode 100644
index 00000000000..8f1492b3df2
--- /dev/null
+++ b/thirdparty/sdl/time/SDL_time.c
@@ -0,0 +1,221 @@
+/*
+ Simple DirectMedia Layer
+ Copyright (C) 1997-2026 Sam Lantinga <[email protected]>
+
+ 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"
+
+#include "SDL_time_c.h"
+
+/* The following algorithms are based on those of Howard Hinnant and are in the public domain.
+ *
+ * http://howardhinnant.github.io/date_algorithms.html
+ */
+
+/* Given a calendar date, returns days since Jan 1 1970, and optionally
+ * the day of the week [0-6, 0 is Sunday] and day of the year [0-365].
+ */
+Sint64 SDL_CivilToDays(int year, int month, int day, int *day_of_week, int *day_of_year)
+{
+ year -= month <= 2;
+ const int era = (year >= 0 ? year : year - 399) / 400;
+ const unsigned yoe = (unsigned)(year - era * 400); // [0, 399]
+ const unsigned doy = (153 * (month > 2 ? month - 3 : month + 9) + 2) / 5 + day - 1; // [0, 365]
+ const unsigned doe = yoe * 365 + yoe / 4 - yoe / 100 + doy; // [0, 146096]
+ const Sint64 z = (Sint64)(era) * 146097 + (Sint64)(doe)-719468;
+
+ if (day_of_week) {
+ *day_of_week = (int)(z >= -4 ? (z + 4) % 7 : (z + 5) % 7 + 6);
+ }
+ if (day_of_year) {
+ // This algorithm considers March 1 to be the first day of the year, so offset by Jan + Feb.
+ if (doy > 305) {
+ // Day 0 is the first day of the year.
+ *day_of_year = doy - 306;
+ } else {
+ const int doy_offset = 59 + (!(year % 4) && ((year % 100) || !(year % 400)));
+ *day_of_year = doy + doy_offset;
+ }
+ }
+
+ return z;
+}
+
+bool SDL_GetDateTimeLocalePreferences(SDL_DateFormat *dateFormat, SDL_TimeFormat *timeFormat)
+{
+ // Default to ISO 8061 date format, as it is unambiguous, and 24 hour time.
+ if (dateFormat) {
+ *dateFormat = SDL_DATE_FORMAT_YYYYMMDD;
+ }
+ if (timeFormat) {
+ *timeFormat = SDL_TIME_FORMAT_24HR;
+ }
+
+ // SDL_GetSystemTimeLocalePreferences(dateFormat, timeFormat);
+
+ return true;
+}
+
+int SDL_GetDaysInMonth(int year, int month)
+{
+ static const int DAYS_IN_MONTH[] = {
+ 31, 28, 31, 30, 31, 30, 31, 31, 30, 31, 30, 31
+ };
+
+ if (month < 1 || month > 12) {
+ SDL_SetError("Month out of range [1-12], requested: %i", month);
+ return -1;
+ }
+
+ int days = DAYS_IN_MONTH[month - 1];
+
+ /* A leap year occurs every 4 years...
+ * but not every 100 years...
+ * except for every 400 years.
+ */
+ if (month == 2 && (!(year % 4) && ((year % 100) || !(year % 400)))) {
+ ++days;
+ }
+
+ return days;
+}
+
+int SDL_GetDayOfYear(int year, int month, int day)
+{
+ int dayOfYear;
+
+ if (month < 1 || month > 12) {
+ SDL_SetError("Month out of range [1-12], requested: %i", month);
+ return -1;
+ }
+ if (day < 1 || day > SDL_GetDaysInMonth(year, month)) {
+ SDL_SetError("Day out of range [1-%i], requested: %i", SDL_GetDaysInMonth(year, month), month);
+ return -1;
+ }
+
+ SDL_CivilToDays(year, month, day, NULL, &dayOfYear);
+ return dayOfYear;
+}
+
+int SDL_GetDayOfWeek(int year, int month, int day)
+{
+ int dayOfWeek;
+
+ if (month < 1 || month > 12) {
+ SDL_SetError("Month out of range [1-12], requested: %i", month);
+ return -1;
+ }
+ if (day < 1 || day > SDL_GetDaysInMonth(year, month)) {
+ SDL_SetError("Day out of range [1-%i], requested: %i", SDL_GetDaysInMonth(year, month), month);
+ return -1;
+ }
+
+ SDL_CivilToDays(year, month, day, &dayOfWeek, NULL);
+ return dayOfWeek;
+}
+
+static bool SDL_DateTimeIsValid(const SDL_DateTime *dt)
+{
+ if (dt->month < 1 || dt->month > 12) {
+ SDL_SetError("Malformed SDL_DateTime: month out of range [1-12], current: %i", dt->month);
+ return false;
+ }
+
+ const int daysInMonth = SDL_GetDaysInMonth(dt->year, dt->month);
+ if (dt->day < 1 || dt->day > daysInMonth) {
+ SDL_SetError("Malformed SDL_DateTime: day of month out of range [1-%i], current: %i", daysInMonth, dt->month);
+ return false;
+ }
+ if (dt->hour < 0 || dt->hour > 23) {
+ SDL_SetError("Malformed SDL_DateTime: hour out of range [0-23], current: %i", dt->hour);
+ return false;
+ }
+ if (dt->minute < 0 || dt->minute > 59) {
+ SDL_SetError("Malformed SDL_DateTime: minute out of range [0-59], current: %i", dt->minute);
+ return false;
+ }
+ if (dt->second < 0 || dt->second > 60) {
+ SDL_SetError("Malformed SDL_DateTime: second out of range [0-60], current: %i", dt->second);
+ return false; // 60 accounts for a possible leap second.
+ }
+ if (dt->nanosecond < 0 || dt->nanosecond >= SDL_NS_PER_SECOND) {
+ SDL_SetError("Malformed SDL_DateTime: nanosecond out of range [0-999999999], current: %i", dt->nanosecond);
+ return false;
+ }
+
+ return true;
+}
+
+bool SDL_DateTimeToTime(const SDL_DateTime *dt, SDL_Time *ticks)
+{
+ static const Sint64 max_seconds = SDL_NS_TO_SECONDS(SDL_MAX_TIME) - 1;
+ static const Sint64 min_seconds = SDL_NS_TO_SECONDS(SDL_MIN_TIME) + 1;
+ bool result = true;
+
+ CHECK_PARAM(!dt) {
+ return SDL_InvalidParamError("dt");
+ }
+ CHECK_PARAM(!ticks) {
+ return SDL_InvalidParamError("ticks");
+ }
+ CHECK_PARAM(!SDL_DateTimeIsValid(dt)) {
+ // The validation function sets the error string.
+ return false;
+ }
+
+ *ticks = SDL_CivilToDays(dt->year, dt->month, dt->day, NULL, NULL) * SDL_SECONDS_PER_DAY;
+ *ticks += (((dt->hour * 60) + dt->minute) * 60) + dt->second - dt->utc_offset;
+ if (*ticks > max_seconds || *ticks < min_seconds) {
+ *ticks = SDL_clamp(*ticks, min_seconds, max_seconds);
+ result = SDL_SetError("Date out of range for SDL_Time representation; SDL_Time value clamped");
+ }
+ *ticks = SDL_SECONDS_TO_NS(*ticks) + dt->nanosecond;
+
+ return result;
+}
+
+#define DELTA_EPOCH_1601_100NS (11644473600ll * 10000000ll) // [100 ns] (100 ns units between 1601-01-01 and 1970-01-01, 11644473600 seconds)
+
+void SDL_TimeToWindows(SDL_Time ticks, Uint32 *dwLowDateTime, Uint32 *dwHighDateTime)
+{
+ /* Convert nanoseconds to Win32 ticks.
+ * SDL_Time has a range of roughly 292 years, so even SDL_MIN_TIME can't underflow the Win32 epoch.
+ */
+ const Uint64 wtime = (Uint64)((ticks / 100) + DELTA_EPOCH_1601_100NS);
+
+ if (dwLowDateTime) {
+ *dwLowDateTime = (Uint32)wtime;
+ }
+
+ if (dwHighDateTime) {
+ *dwHighDateTime = (Uint32)(wtime >> 32);
+ }
+}
+
+SDL_Time SDL_TimeFromWindows(Uint32 dwLowDateTime, Uint32 dwHighDateTime)
+{
+ static const Uint64 wintime_min = (Uint64)((SDL_MIN_TIME / 100) + DELTA_EPOCH_1601_100NS);
+ static const Uint64 wintime_max = (Uint64)((SDL_MAX_TIME / 100) + DELTA_EPOCH_1601_100NS);
+
+ Uint64 wtime = (((Uint64)dwHighDateTime << 32) | dwLowDateTime);
+
+ // Clamp the windows time range to the SDL_Time min/max
+ wtime = SDL_clamp(wtime, wintime_min, wintime_max);
+
+ return (SDL_Time)(wtime - DELTA_EPOCH_1601_100NS) * 100;
+}
diff --git a/thirdparty/sdl/time/SDL_time_c.h b/thirdparty/sdl/time/SDL_time_c.h
new file mode 100644
index 00000000000..06cd565c090
--- /dev/null
+++ b/thirdparty/sdl/time/SDL_time_c.h
@@ -0,0 +1,36 @@
+/*
+ Simple DirectMedia Layer
+ Copyright (C) 1997-2026 Sam Lantinga <[email protected]>
+
+ 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.
+*/
+
+#ifndef SDL_time_c_h_
+#define SDL_time_c_h_
+
+#include "SDL_internal.h"
+
+#define SDL_SECONDS_PER_DAY 86400
+
+/* Given a calendar date, returns days since Jan 1 1970, and optionally
+ * the day of the week (0-6, 0 is Sunday) and day of the year (0-365).
+ */
+extern Sint64 SDL_CivilToDays(int year, int month, int day, int *day_of_week, int *day_of_year);
+
+extern void SDL_GetSystemTimeLocalePreferences(SDL_DateFormat *df, SDL_TimeFormat *tf);
+
+#endif // SDL_time_c_h_
diff --git a/thirdparty/sdl/timer/SDL_timer.c b/thirdparty/sdl/timer/SDL_timer.c
index 2fa65530377..5fc4573d3a3 100644
--- a/thirdparty/sdl/timer/SDL_timer.c
+++ b/thirdparty/sdl/timer/SDL_timer.c
@@ -1,6 +1,6 @@
/*
Simple DirectMedia Layer
- Copyright (C) 1997-2025 Sam Lantinga <[email protected]>
+ Copyright (C) 1997-2026 Sam Lantinga <[email protected]>
This software is provided 'as-is', without any express or implied
warranty. In no event will the authors be held liable for any damages
@@ -25,7 +25,7 @@
// #define DEBUG_TIMERS
-#if !defined(SDL_PLATFORM_EMSCRIPTEN) || !defined(SDL_THREADS_DISABLED)
+#if !defined(SDL_PLATFORM_EMSCRIPTEN)
typedef struct SDL_Timer
{
@@ -301,7 +301,7 @@ static SDL_TimerID SDL_CreateTimer(Uint64 interval, SDL_TimerCallback callback_m
SDL_Timer *timer;
SDL_TimerMap *entry;
- if (!callback_ms && !callback_ns) {
+ CHECK_PARAM(!callback_ms && !callback_ns) {
SDL_InvalidParamError("callback");
return 0;
}
@@ -374,7 +374,7 @@ bool SDL_RemoveTimer(SDL_TimerID id)
SDL_TimerMap *prev, *entry;
bool canceled = false;
- if (!id) {
+ CHECK_PARAM(!id) {
return SDL_InvalidParamError("id");
}
@@ -407,7 +407,7 @@ bool SDL_RemoveTimer(SDL_TimerID id)
}
}
-#else
+#else // Emscripten-specific implementation.
#include <emscripten/emscripten.h>
#include <emscripten/eventloop.h>
@@ -467,7 +467,7 @@ static SDL_TimerID SDL_CreateTimer(Uint64 interval, SDL_TimerCallback callback_m
SDL_TimerData *data = &SDL_timer_data;
SDL_TimerMap *entry;
- if (!callback_ms && !callback_ns) {
+ CHECK_PARAM(!callback_ms && !callback_ns) {
SDL_InvalidParamError("callback");
return 0;
}
@@ -507,7 +507,7 @@ bool SDL_RemoveTimer(SDL_TimerID id)
SDL_TimerData *data = &SDL_timer_data;
SDL_TimerMap *prev, *entry;
- if (!id) {
+ CHECK_PARAM(!id) {
return SDL_InvalidParamError("id");
}
@@ -533,13 +533,22 @@ bool SDL_RemoveTimer(SDL_TimerID id)
}
}
-#endif // !SDL_PLATFORM_EMSCRIPTEN || !SDL_THREADS_DISABLED
+#endif // !SDL_PLATFORM_EMSCRIPTEN
+
+#ifdef USE_128BIT_MATH
+typedef unsigned __int128 Uint128;
+#endif
static Uint64 tick_start;
+#ifdef USE_128BIT_MATH
+static Uint64 tick_numerator_ns;
+static Uint64 tick_numerator_ms;
+#else
static Uint32 tick_numerator_ns;
static Uint32 tick_denominator_ns;
static Uint32 tick_numerator_ms;
static Uint32 tick_denominator_ms;
+#endif
#if defined(SDL_TIMER_WINDOWS) && !defined(SDL_PLATFORM_XBOXONE) && !defined(SDL_PLATFORM_XBOXSERIES)
#include <mmsystem.h>
@@ -583,7 +592,9 @@ static void SDLCALL SDL_TimerResolutionChanged(void *userdata, const char *name,
void SDL_InitTicks(void)
{
Uint64 tick_freq;
+#ifndef USE_128BIT_MATH
Uint32 gcd;
+#endif
if (tick_start) {
return;
@@ -597,6 +608,10 @@ void SDL_InitTicks(void)
tick_freq = SDL_GetPerformanceFrequency();
SDL_assert(tick_freq > 0 && tick_freq <= (Uint64)SDL_MAX_UINT32);
+#ifdef USE_128BIT_MATH
+ tick_numerator_ns = ((Uint64)SDL_NS_PER_SECOND << 32) / tick_freq;
+ tick_numerator_ms = ((Uint64)SDL_MS_PER_SECOND << 32) / tick_freq;
+#else
gcd = SDL_CalculateGCD(SDL_NS_PER_SECOND, (Uint32)tick_freq);
tick_numerator_ns = (SDL_NS_PER_SECOND / gcd);
tick_denominator_ns = (Uint32)(tick_freq / gcd);
@@ -604,6 +619,7 @@ void SDL_InitTicks(void)
gcd = SDL_CalculateGCD(SDL_MS_PER_SECOND, (Uint32)tick_freq);
tick_numerator_ms = (SDL_MS_PER_SECOND / gcd);
tick_denominator_ms = (Uint32)(tick_freq / gcd);
+#endif
tick_start = SDL_GetPerformanceCounter();
if (!tick_start) {
@@ -630,9 +646,12 @@ Uint64 SDL_GetTicksNS(void)
}
starting_value = (SDL_GetPerformanceCounter() - tick_start);
- value = (starting_value * tick_numerator_ns);
- SDL_assert(value >= starting_value);
- value /= tick_denominator_ns;
+#ifdef USE_128BIT_MATH
+ value = (Uint64)(((Uint128)starting_value * tick_numerator_ns) >> 32);
+#else
+ value = (starting_value / tick_denominator_ns) * tick_numerator_ns +
+ (starting_value % tick_denominator_ns) * tick_numerator_ns / tick_denominator_ns;
+#endif
return value;
}
@@ -645,9 +664,12 @@ Uint64 SDL_GetTicks(void)
}
starting_value = (SDL_GetPerformanceCounter() - tick_start);
- value = (starting_value * tick_numerator_ms);
- SDL_assert(value >= starting_value);
- value /= tick_denominator_ms;
+#ifdef USE_128BIT_MATH
+ value = (Uint64)(((Uint128)starting_value * tick_numerator_ms) >> 32);
+#else
+ value = (starting_value / tick_denominator_ms) * tick_numerator_ms +
+ (starting_value % tick_denominator_ms) * tick_numerator_ms / tick_denominator_ms;
+#endif
return value;
}
diff --git a/thirdparty/sdl/timer/SDL_timer_c.h b/thirdparty/sdl/timer/SDL_timer_c.h
index 18d817167ad..332cc057fd9 100644
--- a/thirdparty/sdl/timer/SDL_timer_c.h
+++ b/thirdparty/sdl/timer/SDL_timer_c.h
@@ -1,6 +1,6 @@
/*
Simple DirectMedia Layer
- Copyright (C) 1997-2025 Sam Lantinga <[email protected]>
+ Copyright (C) 1997-2026 Sam Lantinga <[email protected]>
This software is provided 'as-is', without any express or implied
warranty. In no event will the authors be held liable for any damages
diff --git a/thirdparty/sdl/timer/unix/SDL_systimer.c b/thirdparty/sdl/timer/unix/SDL_systimer.c
index 0f96319af79..8fc87c9ef82 100644
--- a/thirdparty/sdl/timer/unix/SDL_systimer.c
+++ b/thirdparty/sdl/timer/unix/SDL_systimer.c
@@ -1,6 +1,6 @@
/*
Simple DirectMedia Layer
- Copyright (C) 1997-2025 Sam Lantinga <[email protected]>
+ Copyright (C) 1997-2026 Sam Lantinga <[email protected]>
This software is provided 'as-is', without any express or implied
warranty. In no event will the authors be held liable for any damages
@@ -53,7 +53,9 @@
// Use CLOCK_MONOTONIC_RAW, if available, which is not subject to adjustment by NTP
#ifdef HAVE_CLOCK_GETTIME
-#ifdef CLOCK_MONOTONIC_RAW
+// Older Android phones have a buggy CLOCK_MONOTONIC_RAW, use CLOCK_MONOTONIC
+// See fix: https://github.com/torvalds/linux/commit/dbb236c1ceb697a559e0694ac4c9e7b9131d0b16
+#if defined(CLOCK_MONOTONIC_RAW) && !defined(__ANDROID__)
#define SDL_MONOTONIC_CLOCK CLOCK_MONOTONIC_RAW
#else
#define SDL_MONOTONIC_CLOCK CLOCK_MONOTONIC
diff --git a/thirdparty/sdl/timer/windows/SDL_systimer.c b/thirdparty/sdl/timer/windows/SDL_systimer.c
index f6f4b15c72b..ad4761df349 100644
--- a/thirdparty/sdl/timer/windows/SDL_systimer.c
+++ b/thirdparty/sdl/timer/windows/SDL_systimer.c
@@ -1,6 +1,6 @@
/*
Simple DirectMedia Layer
- Copyright (C) 1997-2025 Sam Lantinga <[email protected]>
+ Copyright (C) 1997-2026 Sam Lantinga <[email protected]>
This software is provided 'as-is', without any express or implied
warranty. In no event will the authors be held liable for any damages
@@ -24,47 +24,96 @@
#include "../../core/windows/SDL_windows.h"
+Uint64 SDL_GetPerformanceCounter(void)
+{
+ LARGE_INTEGER counter;
+ const BOOL rc = QueryPerformanceCounter(&counter);
+ SDL_assert(rc != 0); // this should _never_ fail if you're on XP or later.
+ return (Uint64)counter.QuadPart;
+}
+
+Uint64 SDL_GetPerformanceFrequency(void)
+{
+ LARGE_INTEGER frequency;
+ const BOOL rc = QueryPerformanceFrequency(&frequency);
+ SDL_assert(rc != 0); // this should _never_ fail if you're on XP or later.
+ return (Uint64)frequency.QuadPart;
+}
+
+static void SDL_CleanupWaitableHandle(void *handle)
+{
+ CloseHandle(handle);
+}
+
+static HANDLE SDL_GetWaitableEvent(void)
+{
+ static SDL_TLSID TLS_event_handle;
+ HANDLE event;
+
+ event = SDL_GetTLS(&TLS_event_handle);
+ if (!event) {
+ event = CreateEvent(NULL, FALSE, FALSE, NULL);
+ if (event) {
+ SDL_SetTLS(&TLS_event_handle, event, SDL_CleanupWaitableHandle);
+ }
+ }
+ return event;
+}
+
/* CREATE_WAITABLE_TIMER_HIGH_RESOLUTION flag was added in Windows 10 version 1803. */
#ifndef CREATE_WAITABLE_TIMER_HIGH_RESOLUTION
#define CREATE_WAITABLE_TIMER_HIGH_RESOLUTION 0x2
#endif
-typedef HANDLE (WINAPI *CreateWaitableTimerExW_t)(LPSECURITY_ATTRIBUTES lpTimerAttributes, LPCWSTR lpTimerName, DWORD dwFlags, DWORD dwDesiredAccess);
-static CreateWaitableTimerExW_t pCreateWaitableTimerExW;
+typedef HANDLE (WINAPI *pfnCreateWaitableTimerExW)(LPSECURITY_ATTRIBUTES lpTimerAttributes, LPCWSTR lpTimerName, DWORD dwFlags, DWORD dwDesiredAccess);
+static pfnCreateWaitableTimerExW pCreateWaitableTimerExW;
-typedef BOOL (WINAPI *SetWaitableTimerEx_t)(HANDLE hTimer, const LARGE_INTEGER *lpDueTime, LONG lPeriod, PTIMERAPCROUTINE pfnCompletionRoutine, LPVOID lpArgToCompletionRoutine, PREASON_CONTEXT WakeContext, ULONG TolerableDelay);
-static SetWaitableTimerEx_t pSetWaitableTimerEx;
+#if WINVER < _WIN32_WINNT_WIN7
+typedef struct _REASON_CONTEXT REASON_CONTEXT;
+typedef REASON_CONTEXT * PREASON_CONTEXT;
+#endif
+typedef BOOL (WINAPI *pfnSetWaitableTimerEx)(HANDLE hTimer, const LARGE_INTEGER *lpDueTime, LONG lPeriod, PTIMERAPCROUTINE pfnCompletionRoutine, LPVOID lpArgToCompletionRoutine, PREASON_CONTEXT WakeContext, ULONG TolerableDelay);
+static pfnSetWaitableTimerEx pSetWaitableTimerEx;
-static void SDL_CleanupWaitableHandle(void *handle)
-{
- CloseHandle(handle);
-}
+typedef HANDLE (WINAPI *pfnCreateWaitableTimerW)(LPSECURITY_ATTRIBUTES lpTimerAttributes, BOOL bManualReset, LPCWSTR lpTimerName);
+static pfnCreateWaitableTimerW pCreateWaitableTimerW;
+
+typedef BOOL (WINAPI *pfnSetWaitableTimer)(HANDLE hTimer, const LARGE_INTEGER *lpDueTime, LONG lPeriod, PTIMERAPCROUTINE pfnCompletionRoutine, LPVOID lpArgToCompletionRoutine, BOOL fResume);
+static pfnSetWaitableTimer pSetWaitableTimer;
static HANDLE SDL_GetWaitableTimer(void)
{
static SDL_TLSID TLS_timer_handle;
HANDLE timer;
-
- if (!pCreateWaitableTimerExW || !pSetWaitableTimerEx) {
- static bool initialized;
-
- if (!initialized) {
- HMODULE module = GetModuleHandle(TEXT("kernel32.dll"));
- if (module) {
- pCreateWaitableTimerExW = (CreateWaitableTimerExW_t)GetProcAddress(module, "CreateWaitableTimerExW");
- pSetWaitableTimerEx = (SetWaitableTimerEx_t)GetProcAddress(module, "SetWaitableTimerEx");
+ static bool initialized;
+
+ if (!initialized) {
+ HMODULE module = GetModuleHandle(TEXT("kernel32.dll"));
+ if (module) {
+ pCreateWaitableTimerExW = (pfnCreateWaitableTimerExW)GetProcAddress(module, "CreateWaitableTimerExW"); // Windows 7 and up
+ if (!pCreateWaitableTimerExW) {
+ pCreateWaitableTimerW = (pfnCreateWaitableTimerW)GetProcAddress(module, "CreateWaitableTimerW");
}
- initialized = true;
+ pSetWaitableTimerEx = (pfnSetWaitableTimerEx)GetProcAddress(module, "SetWaitableTimerEx"); // Windows Vista and up
+ if (!pSetWaitableTimerEx) {
+ pSetWaitableTimer = (pfnSetWaitableTimer)GetProcAddress(module, "SetWaitableTimer");
+ }
+ initialized =
+ (pCreateWaitableTimerExW || pCreateWaitableTimerW) &&
+ (pSetWaitableTimerEx || pSetWaitableTimer);
}
-
- if (!pCreateWaitableTimerExW || !pSetWaitableTimerEx) {
+ if (!initialized) {
return NULL;
}
}
timer = SDL_GetTLS(&TLS_timer_handle);
if (!timer) {
- timer = pCreateWaitableTimerExW(NULL, NULL, CREATE_WAITABLE_TIMER_HIGH_RESOLUTION, TIMER_ALL_ACCESS);
+ if (pCreateWaitableTimerExW) {
+ timer = pCreateWaitableTimerExW(NULL, NULL, CREATE_WAITABLE_TIMER_HIGH_RESOLUTION, TIMER_ALL_ACCESS);
+ } else {
+ timer = pCreateWaitableTimerW(NULL, TRUE, NULL);
+ }
if (timer) {
SDL_SetTLS(&TLS_timer_handle, timer, SDL_CleanupWaitableHandle);
}
@@ -72,44 +121,13 @@ static HANDLE SDL_GetWaitableTimer(void)
return timer;
}
-static HANDLE SDL_GetWaitableEvent(void)
-{
- static SDL_TLSID TLS_event_handle;
- HANDLE event;
-
- event = SDL_GetTLS(&TLS_event_handle);
- if (!event) {
- event = CreateEvent(NULL, FALSE, FALSE, NULL);
- if (event) {
- SDL_SetTLS(&TLS_event_handle, event, SDL_CleanupWaitableHandle);
- }
- }
- return event;
-}
-
-Uint64 SDL_GetPerformanceCounter(void)
-{
- LARGE_INTEGER counter;
- const BOOL rc = QueryPerformanceCounter(&counter);
- SDL_assert(rc != 0); // this should _never_ fail if you're on XP or later.
- return (Uint64)counter.QuadPart;
-}
-
-Uint64 SDL_GetPerformanceFrequency(void)
-{
- LARGE_INTEGER frequency;
- const BOOL rc = QueryPerformanceFrequency(&frequency);
- SDL_assert(rc != 0); // this should _never_ fail if you're on XP or later.
- return (Uint64)frequency.QuadPart;
-}
-
void SDL_SYS_DelayNS(Uint64 ns)
{
HANDLE timer = SDL_GetWaitableTimer();
if (timer) {
LARGE_INTEGER due_time;
due_time.QuadPart = -((LONGLONG)ns / 100);
- if (pSetWaitableTimerEx(timer, &due_time, 0, NULL, NULL, NULL, 0)) {
+ if ((pSetWaitableTimerEx && pSetWaitableTimerEx(timer, &due_time, 0, NULL, NULL, NULL, 0)) || pSetWaitableTimer(timer, &due_time, 0, NULL, NULL, 0)) {
WaitForSingleObject(timer, INFINITE);
}
return;
diff --git a/thirdparty/sdl/update-sdl.sh b/thirdparty/sdl/update-sdl.sh
index 08d0e32b9be..26c80828271 100755
--- a/thirdparty/sdl/update-sdl.sh
+++ b/thirdparty/sdl/update-sdl.sh
@@ -1,6 +1,6 @@
#!/bin/bash -e
-VERSION=3.2.28
+VERSION=3.4.16
target=$(dirname "$(realpath $0)")
pushd $target
@@ -26,8 +26,8 @@ cp -v CREDITS.md LICENSE.txt $target
# For build config, we use a single private one in the driver.
# We might reconsider as we make more platforms use SDL.
cp -rv include $target
-rm -f $target/include/build_config/{*.cmake,SDL_build_config_*.h} $target
-rm -f $target/include/SDL3/SDL_{egl,gpu,oldnames,opengl*,test*,vulkan}.h $target
+rm -f $target/include/build_config/{*.cmake,SDL_build_config_*.h}
+rm -f $target/include/SDL3/SDL_{egl,gpu,oldnames,opengl*,test*,vulkan}.h
pushd src
@@ -49,10 +49,14 @@ cp -v io/SDL_iostream*.{c,h} $target/io
mkdir $target/core
cp -rv core/{linux,unix,windows} $target/core
rm -f $target/core/windows/version.rc
-rm -f $target/core/linux/SDL_{fcitx,ibus,ime,system_theme}.*
+rm -f $target/core/linux/SDL_{fcitx,ibus,ime,progressbar,system_theme}.*
+rm -f $target/core/unix/SDL_{fribidi,gtk,libthai}.*
+
+mkdir $target/filesystem
+cp -rv filesystem/{*.{c,h},windows} $target/filesystem
mkdir $target/haptic
-cp -rv haptic/{*.{c,h},darwin,dummy,linux,windows} $target/haptic
+cp -rv haptic/{*.{c,h},darwin,dummy,hidapi,linux,windows} $target/haptic
mkdir $target/joystick
cp -rv joystick/{*.{c,h},apple,darwin,hidapi,linux,windows} $target/joystick
@@ -60,6 +64,9 @@ cp -rv joystick/{*.{c,h},apple,darwin,hidapi,linux,windows} $target/joystick
mkdir $target/loadso
cp -rv loadso/{dlopen,dummy} $target/loadso
+mkdir $target/misc
+cp -v misc/SDL_libusb.{c,h} $target/misc
+
mkdir $target/sensor
cp -rv sensor/{*.{c,h},dummy,windows} $target/sensor
@@ -71,6 +78,9 @@ cp -rv thread/{*.{c,h},pthread,windows} $target/thread
mkdir $target/thread/generic
cp -v thread/generic/SDL_{syssem.c,{syscond,sysrwlock}*.{c,h},systhread_c.h} $target/thread/generic
+mkdir $target/time
+cp -v time/*.{c,h} $target/time
+
mkdir $target/timer
cp -rv timer/{*.{c,h},unix,windows} $target/timer
@@ -80,7 +90,7 @@ mkdir -p $target/hidapi
cp -v hidapi/{*.{c,h},AUTHORS.txt,LICENSE.txt,LICENSE-bsd.txt,VERSION} $target/hidapi
for dir in hidapi linux mac windows; do
mkdir $target/hidapi/$dir
- cp -v hidapi/$dir/*.{c,h} $target/hidapi/$dir
+ cp -v hidapi/$dir/*.{c,h} $target/hidapi/$dir 2>/dev/null || :
done
popd