SDL upgrade

This commit is contained in:
Alex Zenla 2025-01-26 09:13:40 -05:00
parent 3b2a6ffb6a
commit 31ef295f52
No known key found for this signature in database
GPG Key ID: 067B238899B51269
400 changed files with 92536 additions and 30625 deletions

View File

@ -4,23 +4,6 @@
<dict>
<key>AvailableLibraries</key>
<array>
<dict>
<key>BinaryPath</key>
<string>SDL3.framework/SDL3</string>
<key>LibraryIdentifier</key>
<string>ios-arm64_x86_64-simulator</string>
<key>LibraryPath</key>
<string>SDL3.framework</string>
<key>SupportedArchitectures</key>
<array>
<string>arm64</string>
<string>x86_64</string>
</array>
<key>SupportedPlatform</key>
<string>ios</string>
<key>SupportedPlatformVariant</key>
<string>simulator</string>
</dict>
<dict>
<key>BinaryPath</key>
<string>SDL3.framework/SDL3</string>
@ -35,6 +18,21 @@
<key>SupportedPlatform</key>
<string>ios</string>
</dict>
<dict>
<key>BinaryPath</key>
<string>SDL3.framework/Versions/A/SDL3</string>
<key>LibraryIdentifier</key>
<string>macos-arm64_x86_64</string>
<key>LibraryPath</key>
<string>SDL3.framework</string>
<key>SupportedArchitectures</key>
<array>
<string>arm64</string>
<string>x86_64</string>
</array>
<key>SupportedPlatform</key>
<string>macos</string>
</dict>
<dict>
<key>BinaryPath</key>
<string>SDL3.framework/SDL3</string>
@ -68,9 +66,9 @@
</dict>
<dict>
<key>BinaryPath</key>
<string>SDL3.framework/Versions/A/SDL3</string>
<string>SDL3.framework/SDL3</string>
<key>LibraryIdentifier</key>
<string>macos-arm64_x86_64</string>
<string>ios-arm64_x86_64-simulator</string>
<key>LibraryPath</key>
<string>SDL3.framework</string>
<key>SupportedArchitectures</key>
@ -79,7 +77,9 @@
<string>x86_64</string>
</array>
<key>SupportedPlatform</key>
<string>macos</string>
<string>ios</string>
<key>SupportedPlatformVariant</key>
<string>simulator</string>
</dict>
</array>
<key>CFBundlePackageType</key>

View File

@ -59,7 +59,7 @@ if(NOT TARGET SDL3::SDL3-shared)
set_target_properties(SDL3::SDL3-shared
PROPERTIES
FRAMEWORK "TRUE"
IMPORTED_LOCATION "${_sdl3_framework_path}/SDL3"
IMPORTED_LOCATION "${_sdl3_framework_path}"
INTERFACE_LINK_LIBRARIES "SDL3::Headers"
COMPATIBLE_INTERFACE_BOOL "SDL3_SHARED"
INTERFACE_SDL3_SHARED "ON"

View File

@ -1,6 +1,6 @@
/*
Simple DirectMedia Layer
Copyright (C) 1997-2024 Sam Lantinga <slouken@libsdl.org>
Copyright (C) 1997-2025 Sam Lantinga <slouken@libsdl.org>
This software is provided 'as-is', without any express or implied
warranty. In no event will the authors be held liable for any damages
@ -20,9 +20,12 @@
*/
/**
* \file SDL.h
* Main include header for the SDL library, version 3.2.0
*
* Main include header for the SDL library, version 3.1.2
* It is almost always best to include just this one header instead of
* picking out individual headers included here. There are exceptions to
* this rule--SDL_main.h is special and not included here--but usually
* letting SDL.h include the kitchen sink for you is the correct approach.
*/
#ifndef SDL_h_
@ -30,6 +33,7 @@
#include <SDL3/SDL_stdinc.h>
#include <SDL3/SDL_assert.h>
#include <SDL3/SDL_asyncio.h>
#include <SDL3/SDL_atomic.h>
#include <SDL3/SDL_audio.h>
#include <SDL3/SDL_bits.h>
@ -65,6 +69,7 @@
#include <SDL3/SDL_pixels.h>
#include <SDL3/SDL_platform.h>
#include <SDL3/SDL_power.h>
#include <SDL3/SDL_process.h>
#include <SDL3/SDL_properties.h>
#include <SDL3/SDL_rect.h>
#include <SDL3/SDL_render.h>
@ -76,6 +81,7 @@
#include <SDL3/SDL_thread.h>
#include <SDL3/SDL_time.h>
#include <SDL3/SDL_timer.h>
#include <SDL3/SDL_tray.h>
#include <SDL3/SDL_touch.h>
#include <SDL3/SDL_version.h>
#include <SDL3/SDL_video.h>

View File

@ -1,6 +1,6 @@
/*
Simple DirectMedia Layer
Copyright (C) 1997-2024 Sam Lantinga <slouken@libsdl.org>
Copyright (C) 1997-2025 Sam Lantinga <slouken@libsdl.org>
This software is provided 'as-is', without any express or implied
warranty. In no event will the authors be held liable for any damages
@ -51,9 +51,14 @@
* - It provides statistics and data on all failed assertions to the app.
* - It allows the default assertion handler to be controlled with environment
* variables, in case an automated script needs to control it.
* - It can be used as an aid to Clang's static analysis; it will treat SDL
* assertions as universally true (under the assumption that you are serious
* about the asserted claims and that your debug builds will detect when
* these claims were wrong). This can help the analyzer avoid false
* positives.
*
* To use it: do a debug build and just sprinkle around tests to check your
* code!
* To use it: compile a debug build and just sprinkle around tests to check
* your code!
*/
#ifndef SDL_assert_h_
@ -84,7 +89,7 @@ extern "C" {
* - 3: Paranoid settings: All SDL assertion macros enabled, including
* SDL_assert_paranoid.
*
* \since This macro is available since SDL 3.0.0.
* \since This macro is available since SDL 3.2.0.
*/
#define SDL_ASSERT_LEVEL SomeNumberBasedOnVariousFactors
@ -113,24 +118,27 @@ extern "C" {
*
* If the program is not running under a debugger, SDL_TriggerBreakpoint will
* likely terminate the app, possibly without warning. If the current platform
* isn't supported (SDL doesn't know how to trigger a breakpoint), this macro
* does nothing.
* isn't supported, this macro is left undefined.
*
* \threadsafety It is safe to call this function from any thread.
* \threadsafety It is safe to call this macro from any thread.
*
* \since This macro is available since SDL 3.0.0.
* \since This macro is available since SDL 3.2.0.
*/
#define SDL_TriggerBreakpoint() TriggerABreakpointInAPlatformSpecificManner
#elif defined(_MSC_VER)
#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(_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__))
#define SDL_TriggerBreakpoint() __asm__ __volatile__ ( "int $3\n\t" )
#elif (defined(__GNUC__) || defined(__clang__)) && defined(__riscv)
@ -147,18 +155,40 @@ extern "C" {
#include <signal.h>
#define SDL_TriggerBreakpoint() raise(SIGTRAP)
#else
/* How do we trigger breakpoints on this platform? */
#define SDL_TriggerBreakpoint()
/* SDL_TriggerBreakpoint is intentionally left undefined on unknown platforms. */
#endif
#if defined(__STDC_VERSION__) && (__STDC_VERSION__ >= 199901L) /* C99 supports __func__ as a standard. */
#ifdef SDL_WIKI_DOCUMENTATION_SECTION
/**
* A macro that reports the current function being compiled.
*
* If SDL can't figure how the compiler reports this, it will use "???".
*
* \since This macro is available since SDL 3.2.0.
*/
#define SDL_FUNCTION __FUNCTION__
#elif 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
/**
* A macro that reports the current file being compiled.
*
* \since This macro is available since SDL 3.2.0.
*/
#define SDL_FILE __FILE__
/**
* A macro that reports the current line number of the file being compiled.
*
* \since This macro is available since SDL 3.2.0.
*/
#define SDL_LINE __LINE__
/*
@ -176,14 +206,50 @@ This also solves the problem of...
disable assertions.
*/
#ifdef SDL_WIKI_DOCUMENTATION_SECTION
/**
* A macro for wrapping code in `do {} while (0);` without compiler warnings.
*
* Visual Studio with really aggressive warnings enabled needs this to avoid
* compiler complaints.
*
* the `do {} while (0);` trick is useful for wrapping code in a macro that
* may or may not be a single statement, to avoid various C language
* accidents.
*
* To use:
*
* ```c
* do { SomethingOnce(); } while (SDL_NULL_WHILE_LOOP_CONDITION (0));
* ```
*
* \since This macro is available since SDL 3.2.0.
*/
#define SDL_NULL_WHILE_LOOP_CONDITION (0)
#elif defined(_MSC_VER) /* 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! */
#ifdef _MSC_VER /* stupid /W4 warnings. */
#define SDL_NULL_WHILE_LOOP_CONDITION (0,0)
#else
#define SDL_NULL_WHILE_LOOP_CONDITION (0)
#endif
/**
* The macro used when an assertion is disabled.
*
* This isn't for direct use by apps, but this is the code that is inserted
* when an SDL_assert is disabled (perhaps in a release build).
*
* 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.
*
* \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)
@ -198,7 +264,7 @@ disable assertions.
* condition, try to break in a debugger, kill the program, or ignore the
* problem).
*
* \since This enum is available since SDL 3.0.0.
* \since This enum is available since SDL 3.2.0.
*/
typedef enum SDL_AssertState
{
@ -216,11 +282,11 @@ typedef enum SDL_AssertState
* used by the assertion handler, then added to the assertion report. This is
* returned as a linked list from SDL_GetAssertionReport().
*
* \since This struct is available since SDL 3.0.0.
* \since This struct is available since SDL 3.2.0.
*/
typedef struct SDL_AssertData
{
SDL_bool always_ignore; /**< SDL_TRUE if app should always continue when assertion is triggered. */
bool always_ignore; /**< true if app should always continue when assertion is triggered. */
unsigned int trigger_count; /**< Number of times this assertion has been triggered. */
const char *condition; /**< A string of this assert's test code. */
const char *filename; /**< The source file where this assert lives. */
@ -232,7 +298,7 @@ typedef struct SDL_AssertData
/**
* Never call this directly.
*
* Use the SDL_assert* macros instead.
* Use the SDL_assert macros instead.
*
* \param data assert data structure.
* \param func function name.
@ -240,29 +306,57 @@ typedef struct SDL_AssertData
* \param line line number.
* \returns assert state.
*
* \since This function is available since SDL 3.0.0.
* \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_AssertState SDLCALL SDL_ReportAssertion(SDL_AssertData *data,
const char *func,
const char *file, int line) SDL_ANALYZER_NORETURN;
/* Define the trigger breakpoint call used in asserts */
#ifndef SDL_AssertBreakpoint
#if defined(ANDROID) && defined(assert)
/* Define this as empty in case assert() is defined as SDL_assert */
#define SDL_AssertBreakpoint()
#else
#ifdef SDL_WIKI_DOCUMENTATION_SECTION
/**
* The macro used when an assertion triggers a breakpoint.
*
* This isn't for direct use by apps; use SDL_assert or SDL_TriggerBreakpoint
* instead.
*
* \since This macro is available since SDL 3.2.0.
*/
#define SDL_AssertBreakpoint() SDL_TriggerBreakpoint()
#endif
#elif !defined(SDL_AssertBreakpoint)
# if defined(ANDROID) && defined(assert)
/* Define this as empty in case assert() is defined as SDL_assert */
# define SDL_AssertBreakpoint()
# else
# define SDL_AssertBreakpoint() SDL_TriggerBreakpoint()
# endif
#endif /* !SDL_AssertBreakpoint */
/* the do {} while(0) avoids dangling else problems:
if (x) SDL_assert(y); else blah();
... without the do/while, the "else" could attach to this macro's "if".
We try to handle just the minimum we need here in a macro...the loop,
the static vars, and break points. The heavy lifting is handled in
SDL_ReportAssertion(), in SDL_assert.c.
*/
/**
* The macro used when an assertion is enabled.
*
* This isn't for direct use by apps, but this is the code that is inserted
* when an SDL_assert is enabled.
*
* The `do {} while(0)` avoids dangling else problems:
*
* ```c
* if (x) SDL_assert(y); else blah();
* ```
*
* ... without the do/while, the "else" could attach to this macro's "if". We
* try to handle just the minimum we need here in a macro...the loop, the
* static vars, and break points. The heavy lifting is handled in
* SDL_ReportAssertion().
*
* \param condition the condition to assert.
*
* \since This macro is available since SDL 3.2.0.
*/
#define SDL_enabled_assert(condition) \
do { \
while ( !(condition) ) { \
@ -305,7 +399,9 @@ extern SDL_DECLSPEC SDL_AssertState SDLCALL SDL_ReportAssertion(SDL_AssertData *
*
* \param condition boolean value to test.
*
* \since This macro is available since SDL 3.0.0.
* \threadsafety It is safe to call this macro from any thread.
*
* \since This macro is available since SDL 3.2.0.
*/
#define SDL_assert(condition) if (assertion_enabled && (condition)) { trigger_assertion; }
@ -336,7 +432,9 @@ extern SDL_DECLSPEC SDL_AssertState SDLCALL SDL_ReportAssertion(SDL_AssertData *
*
* \param condition boolean value to test.
*
* \since This macro is available since SDL 3.0.0.
* \threadsafety It is safe to call this macro from any thread.
*
* \since This macro is available since SDL 3.2.0.
*/
#define SDL_assert_release(condition) SDL_disabled_assert(condition)
@ -363,7 +461,9 @@ extern SDL_DECLSPEC SDL_AssertState SDLCALL SDL_ReportAssertion(SDL_AssertData *
*
* \param condition boolean value to test.
*
* \since This macro is available since SDL 3.0.0.
* \threadsafety It is safe to call this macro from any thread.
*
* \since This macro is available since SDL 3.2.0.
*/
#define SDL_assert_paranoid(condition) SDL_disabled_assert(condition)
@ -389,7 +489,7 @@ extern SDL_DECLSPEC SDL_AssertState SDLCALL SDL_ReportAssertion(SDL_AssertData *
#endif
/**
* An assertion test that always performed.
* An assertion test that is always performed.
*
* This macro is always enabled no matter what SDL_ASSERT_LEVEL is set to. You
* almost never want to use this, as it could trigger on an end-user's system,
@ -405,7 +505,9 @@ extern SDL_DECLSPEC SDL_AssertState SDLCALL SDL_ReportAssertion(SDL_AssertData *
*
* \param condition boolean value to test.
*
* \since This macro is available since SDL 3.0.0.
* \threadsafety It is safe to call this macro from any thread.
*
* \since This macro is available since SDL 3.2.0.
*/
#define SDL_assert_always(condition) SDL_enabled_assert(condition)
@ -418,7 +520,10 @@ extern SDL_DECLSPEC SDL_AssertState SDLCALL SDL_ReportAssertion(SDL_AssertData *
* \param userdata what was passed as `userdata` to SDL_SetAssertionHandler().
* \returns an SDL_AssertState value indicating how to handle the failure.
*
* \since This datatype is available since SDL 3.0.0.
* \threadsafety This callback may be called from any thread that triggers an
* assert at any time.
*
* \since This datatype is available since SDL 3.2.0.
*/
typedef SDL_AssertState (SDLCALL *SDL_AssertionHandler)(
const SDL_AssertData *data, void *userdata);
@ -440,7 +545,9 @@ typedef SDL_AssertState (SDLCALL *SDL_AssertionHandler)(
* fails or NULL for the default handler.
* \param userdata a pointer that is passed to `handler`.
*
* \since This function is available since SDL 3.0.0.
* \threadsafety It is safe to call this function from any thread.
*
* \since This function is available since SDL 3.2.0.
*
* \sa SDL_GetAssertionHandler
*/
@ -459,7 +566,9 @@ extern SDL_DECLSPEC void SDLCALL SDL_SetAssertionHandler(
* \returns the default SDL_AssertionHandler that is called when an assert
* triggers.
*
* \since This function is available since SDL 3.0.0.
* \threadsafety It is safe to call this function from any thread.
*
* \since This function is available since SDL 3.2.0.
*
* \sa SDL_GetAssertionHandler
*/
@ -482,7 +591,9 @@ extern SDL_DECLSPEC SDL_AssertionHandler SDLCALL SDL_GetDefaultAssertionHandler(
* was passed to SDL_SetAssertionHandler().
* \returns the SDL_AssertionHandler that is called when an assert triggers.
*
* \since This function is available since SDL 3.0.0.
* \threadsafety It is safe to call this function from any thread.
*
* \since This function is available since SDL 3.2.0.
*
* \sa SDL_SetAssertionHandler
*/
@ -508,9 +619,15 @@ extern SDL_DECLSPEC SDL_AssertionHandler SDLCALL SDL_GetAssertionHandler(void **
* ```
*
* \returns a list of all failed assertions or NULL if the list is empty. This
* memory should not be modified or freed by the application.
* memory should not be modified or freed by the application. This
* pointer remains valid until the next call to SDL_Quit() or
* SDL_ResetAssertionReport().
*
* \since This function is available since SDL 3.0.0.
* \threadsafety This function is not thread safe. Other threads calling
* SDL_ResetAssertionReport() simultaneously, may render the
* returned pointer invalid.
*
* \since This function is available since SDL 3.2.0.
*
* \sa SDL_ResetAssertionReport
*/
@ -524,7 +641,11 @@ extern SDL_DECLSPEC const SDL_AssertData * SDLCALL SDL_GetAssertionReport(void);
* no items. In addition, any previously-triggered assertions will be reset to
* a trigger_count of zero, and their always_ignore state will be false.
*
* \since This function is available since SDL 3.0.0.
* \threadsafety This function is not thread safe. Other threads triggering an
* assertion, or simultaneously calling this function may cause
* memory leaks or crashes.
*
* \since This function is available since SDL 3.2.0.
*
* \sa SDL_GetAssertionReport
*/

View File

@ -0,0 +1,546 @@
/*
Simple DirectMedia Layer
Copyright (C) 1997-2025 Sam Lantinga <slouken@libsdl.org>
This software is provided 'as-is', without any express or implied
warranty. In no event will the authors be held liable for any damages
arising from the use of this software.
Permission is granted to anyone to use this software for any purpose,
including commercial applications, and to alter it and redistribute it
freely, subject to the following restrictions:
1. The origin of this software must not be misrepresented; you must not
claim that you wrote the original software. If you use this software
in a product, an acknowledgment in the product documentation would be
appreciated but is not required.
2. Altered source versions must be plainly marked as such, and must not be
misrepresented as being the original software.
3. This notice may not be removed or altered from any source distribution.
*/
/* WIKI CATEGORY: AsyncIO */
/**
* # CategoryAsyncIO
*
* SDL offers a way to perform I/O asynchronously. This allows an app to read
* or write files without waiting for data to actually transfer; the functions
* that request I/O never block while the request is fulfilled.
*
* Instead, the data moves in the background and the app can check for results
* at their leisure.
*
* This is more complicated than just reading and writing files in a
* synchronous way, but it can allow for more efficiency, and never having
* framerate drops as the hard drive catches up, etc.
*
* The general usage pattern for async I/O is:
*
* - Create one or more SDL_AsyncIOQueue objects.
* - Open files with SDL_AsyncIOFromFile.
* - Start I/O tasks to the files with SDL_ReadAsyncIO or SDL_WriteAsyncIO,
* putting those tasks into one of the queues.
* - Later on, use SDL_GetAsyncIOResult on a queue to see if any task is
* finished without blocking. Tasks might finish in any order with success
* or failure.
* - When all your tasks are done, close the file with SDL_CloseAsyncIO. This
* also generates a task, since it might flush data to disk!
*
* This all works, without blocking, in a single thread, but one can also wait
* on a queue in a background thread, sleeping until new results have arrived:
*
* - Call SDL_WaitAsyncIOResult from one or more threads to efficiently block
* until new tasks complete.
* - When shutting down, call SDL_SignalAsyncIOQueue to unblock any sleeping
* threads despite there being no new tasks completed.
*
* And, of course, to match the synchronous SDL_LoadFile, we offer
* SDL_LoadFileAsync as a convenience function. This will handle allocating a
* buffer, slurping in the file data, and null-terminating it; you still check
* for results later.
*
* Behind the scenes, SDL will use newer, efficient APIs on platforms that
* support them: Linux's io_uring and Windows 11's IoRing, for example. If
* those technologies aren't available, SDL will offload the work to a thread
* pool that will manage otherwise-synchronous loads without blocking the app.
*
* ## Best Practices
*
* Simple non-blocking I/O--for an app that just wants to pick up data
* whenever it's ready without losing framerate waiting on disks to spin--can
* use whatever pattern works well for the program. In this case, simply call
* SDL_ReadAsyncIO, or maybe SDL_LoadFileAsync, as needed. Once a frame, call
* SDL_GetAsyncIOResult to check for any completed tasks and deal with the
* data as it arrives.
*
* If two separate pieces of the same program need their own I/O, it is legal
* for each to create their own queue. This will prevent either piece from
* accidentally consuming the other's completed tasks. Each queue does require
* some amount of resources, but it is not an overwhelming cost. Do not make a
* queue for each task, however. It is better to put many tasks into a single
* queue. They will be reported in order of completion, not in the order they
* were submitted, so it doesn't generally matter what order tasks are
* started.
*
* One async I/O queue can be shared by multiple threads, or one thread can
* have more than one queue, but the most efficient way--if ruthless
* efficiency is the goal--is to have one queue per thread, with multiple
* threads working in parallel, and attempt to keep each queue loaded with
* tasks that are both started by and consumed by the same thread. On modern
* platforms that can use newer interfaces, this can keep data flowing as
* efficiently as possible all the way from storage hardware to the app, with
* no contention between threads for access to the same queue.
*
* Written data is not guaranteed to make it to physical media by the time a
* closing task is completed, unless SDL_CloseAsyncIO is called with its
* `flush` parameter set to true, which is to say that a successful result
* here can still result in lost data during an unfortunately-timed power
* outage if not flushed. However, flushing will take longer and may be
* unnecessary, depending on the app's needs.
*/
#ifndef SDL_asyncio_h_
#define SDL_asyncio_h_
#include <SDL3/SDL_stdinc.h>
#include <SDL3/SDL_begin_code.h>
/* Set up for C function definitions, even when using C++ */
#ifdef __cplusplus
extern "C" {
#endif
/**
* The asynchronous I/O operation structure.
*
* This operates as an opaque handle. One can then request read or write
* operations on it.
*
* \since This struct is available since SDL 3.2.0.
*
* \sa SDL_AsyncIOFromFile
*/
typedef struct SDL_AsyncIO SDL_AsyncIO;
/**
* Types of asynchronous I/O tasks.
*
* \since This enum is available since SDL 3.2.0.
*/
typedef enum SDL_AsyncIOTaskType
{
SDL_ASYNCIO_TASK_READ, /**< A read operation. */
SDL_ASYNCIO_TASK_WRITE, /**< A write operation. */
SDL_ASYNCIO_TASK_CLOSE /**< A close operation. */
} SDL_AsyncIOTaskType;
/**
* Possible outcomes of an asynchronous I/O task.
*
* \since This enum is available since SDL 3.2.0.
*/
typedef enum SDL_AsyncIOResult
{
SDL_ASYNCIO_COMPLETE, /**< request was completed without error */
SDL_ASYNCIO_FAILURE, /**< request failed for some reason; check SDL_GetError()! */
SDL_ASYNCIO_CANCELED /**< request was canceled before completing. */
} SDL_AsyncIOResult;
/**
* Information about a completed asynchronous I/O request.
*
* \since This struct is available since SDL 3.2.0.
*/
typedef struct SDL_AsyncIOOutcome
{
SDL_AsyncIO *asyncio; /**< what generated this task. This pointer will be invalid if it was closed! */
SDL_AsyncIOTaskType type; /**< What sort of task was this? Read, write, etc? */
SDL_AsyncIOResult result; /**< the result of the work (success, failure, cancellation). */
void *buffer; /**< buffer where data was read/written. */
Uint64 offset; /**< offset in the SDL_AsyncIO where data was read/written. */
Uint64 bytes_requested; /**< number of bytes the task was to read/write. */
Uint64 bytes_transferred; /**< actual number of bytes that were read/written. */
void *userdata; /**< pointer provided by the app when starting the task */
} SDL_AsyncIOOutcome;
/**
* A queue of completed asynchronous I/O tasks.
*
* When starting an asynchronous operation, you specify a queue for the new
* task. A queue can be asked later if any tasks in it have completed,
* allowing an app to manage multiple pending tasks in one place, in whatever
* order they complete.
*
* \since This struct is available since SDL 3.2.0.
*
* \sa SDL_CreateAsyncIOQueue
* \sa SDL_ReadAsyncIO
* \sa SDL_WriteAsyncIO
* \sa SDL_GetAsyncIOResult
* \sa SDL_WaitAsyncIOResult
*/
typedef struct SDL_AsyncIOQueue SDL_AsyncIOQueue;
/**
* Use this function to create a new SDL_AsyncIO object for reading from
* and/or writing to a named file.
*
* The `mode` string understands the following values:
*
* - "r": Open a file for reading only. It must exist.
* - "w": Open a file for writing only. It will create missing files or
* truncate existing ones.
* - "r+": Open a file for update both reading and writing. The file must
* exist.
* - "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.
*
* There is no "b" mode, as there is only "binary" style I/O, and no "a" mode
* for appending, since you specify the position when starting a task.
*
* This function supports Unicode filenames, but they must be encoded in UTF-8
* format, regardless of the underlying operating system.
*
* This call is _not_ asynchronous; it will open the file before returning,
* under the assumption that doing so is generally a fast operation. Future
* reads and writes to the opened file will be async, however.
*
* \param file a UTF-8 string representing the filename to open.
* \param mode an ASCII string representing the mode to be used for opening
* the file.
* \returns a pointer to the SDL_AsyncIO structure that is created or NULL on
* failure; call SDL_GetError() for more information.
*
* \since This function is available since SDL 3.2.0.
*
* \sa SDL_CloseAsyncIO
* \sa SDL_ReadAsyncIO
* \sa SDL_WriteAsyncIO
*/
extern SDL_DECLSPEC SDL_AsyncIO * SDLCALL SDL_AsyncIOFromFile(const char *file, const char *mode);
/**
* Use this function to get the size of the data stream in an SDL_AsyncIO.
*
* This call is _not_ asynchronous; it assumes that obtaining this info is a
* non-blocking operation in most reasonable cases.
*
* \param asyncio the SDL_AsyncIO to get the size of the data stream from.
* \returns the size of the data stream in the SDL_IOStream on success or a
* negative error code 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 Sint64 SDLCALL SDL_GetAsyncIOSize(SDL_AsyncIO *asyncio);
/**
* Start an async read.
*
* This function reads up to `size` bytes from `offset` position in the data
* source to the area pointed at by `ptr`. This function may read less bytes
* than requested.
*
* This function returns as quickly as possible; it does not wait for the read
* to complete. On a successful return, this work will continue in the
* background. If the work begins, even failure is asynchronous: a failing
* return value from this function only means the work couldn't start at all.
*
* `ptr` must remain available until the work is done, and may be accessed by
* the system at any time until then. Do not allocate it on the stack, as this
* might take longer than the life of the calling function to complete!
*
* An SDL_AsyncIOQueue must be specified. The newly-created task will be added
* to it when it completes its work.
*
* \param asyncio a pointer to an SDL_AsyncIO structure.
* \param ptr a pointer to a buffer to read data into.
* \param offset the position to start reading in the data source.
* \param size the number of bytes to read from the data source.
* \param queue a queue to add the new SDL_AsyncIO to.
* \param userdata an app-defined pointer that will be provided with the task
* results.
* \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_WriteAsyncIO
* \sa SDL_CreateAsyncIOQueue
*/
extern SDL_DECLSPEC bool SDLCALL SDL_ReadAsyncIO(SDL_AsyncIO *asyncio, void *ptr, Uint64 offset, Uint64 size, SDL_AsyncIOQueue *queue, void *userdata);
/**
* Start an async write.
*
* This function writes `size` bytes from `offset` position in the data source
* to the area pointed at by `ptr`.
*
* This function returns as quickly as possible; it does not wait for the
* write to complete. On a successful return, this work will continue in the
* background. If the work begins, even failure is asynchronous: a failing
* return value from this function only means the work couldn't start at all.
*
* `ptr` must remain available until the work is done, and may be accessed by
* the system at any time until then. Do not allocate it on the stack, as this
* might take longer than the life of the calling function to complete!
*
* An SDL_AsyncIOQueue must be specified. The newly-created task will be added
* to it when it completes its work.
*
* \param asyncio a pointer to an SDL_AsyncIO structure.
* \param ptr a pointer to a buffer to write data from.
* \param offset the position to start writing to the data source.
* \param size the number of bytes to write to the data source.
* \param queue a queue to add the new SDL_AsyncIO to.
* \param userdata an app-defined pointer that will be provided with the task
* results.
* \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_ReadAsyncIO
* \sa SDL_CreateAsyncIOQueue
*/
extern SDL_DECLSPEC bool SDLCALL SDL_WriteAsyncIO(SDL_AsyncIO *asyncio, void *ptr, Uint64 offset, Uint64 size, SDL_AsyncIOQueue *queue, void *userdata);
/**
* Close and free any allocated resources for an async I/O object.
*
* Closing a file is _also_ an asynchronous task! If a write failure were to
* happen during the closing process, for example, the task results will
* report it as usual.
*
* Closing a file that has been written to does not guarantee the data has
* made it to physical media; it may remain in the operating system's file
* cache, for later writing to disk. This means that a successfully-closed
* file can be lost if the system crashes or loses power in this small window.
* To prevent this, call this function with the `flush` parameter set to true.
* This will make the operation take longer, and perhaps increase system load
* in general, but a successful result guarantees that the data has made it to
* physical storage. Don't use this for temporary files, caches, and
* unimportant data, and definitely use it for crucial irreplaceable files,
* like game saves.
*
* This function guarantees that the close will happen after any other pending
* tasks to `asyncio`, so it's safe to open a file, start several operations,
* close the file immediately, then check for all results later. This function
* will not block until the tasks have completed.
*
* Once this function returns true, `asyncio` is no longer valid, regardless
* of any future outcomes. Any completed tasks might still contain this
* pointer in their SDL_AsyncIOOutcome data, in case the app was using this
* value to track information, but it should not be used again.
*
* If this function returns false, the close wasn't started at all, and it's
* safe to attempt to close again later.
*
* An SDL_AsyncIOQueue must be specified. The newly-created task will be added
* to it when it completes its work.
*
* \param asyncio a pointer to an SDL_AsyncIO structure to close.
* \param flush true if data should sync to disk before the task completes.
* \param queue a queue to add the new SDL_AsyncIO to.
* \param userdata an app-defined pointer that will be provided with the task
* results.
* \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 two
* threads should not attempt to close the same object.
*
* \since This function is available since SDL 3.2.0.
*/
extern SDL_DECLSPEC bool SDLCALL SDL_CloseAsyncIO(SDL_AsyncIO *asyncio, bool flush, SDL_AsyncIOQueue *queue, void *userdata);
/**
* Create a task queue for tracking multiple I/O operations.
*
* Async I/O operations are assigned to a queue when started. The queue can be
* checked for completed tasks thereafter.
*
* \returns a new task queue object or NULL if there was an error; 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_DestroyAsyncIOQueue
* \sa SDL_GetAsyncIOResult
* \sa SDL_WaitAsyncIOResult
*/
extern SDL_DECLSPEC SDL_AsyncIOQueue * SDLCALL SDL_CreateAsyncIOQueue(void);
/**
* Destroy a previously-created async I/O task queue.
*
* If there are still tasks pending for this queue, this call will block until
* those tasks are finished. All those tasks will be deallocated. Their
* results will be lost to the app.
*
* Any pending reads from SDL_LoadFileAsync() that are still in this queue
* will have their buffers deallocated by this function, to prevent a memory
* leak.
*
* Once this function is called, the queue is no longer valid and should not
* be used, including by other threads that might access it while destruction
* is blocking on pending tasks.
*
* Do not destroy a queue that still has threads waiting on it through
* SDL_WaitAsyncIOResult(). You can call SDL_SignalAsyncIOQueue() first to
* unblock those threads, and take measures (such as SDL_WaitThread()) to make
* sure they have finished their wait and won't wait on the queue again.
*
* \param queue the task queue to destroy.
*
* \threadsafety It is safe to call this function from any thread, so long as
* no other thread is waiting on the queue with
* SDL_WaitAsyncIOResult.
*
* \since This function is available since SDL 3.2.0.
*/
extern SDL_DECLSPEC void SDLCALL SDL_DestroyAsyncIOQueue(SDL_AsyncIOQueue *queue);
/**
* Query an async I/O task queue for completed tasks.
*
* If a task assigned to this queue has finished, this will return true and
* fill in `outcome` with the details of the task. If no task in the queue has
* finished, this function will return false. This function does not block.
*
* If a task has completed, this function will free its resources and the task
* pointer will no longer be valid. The task will be removed from the queue.
*
* It is safe for multiple threads to call this function on the same queue at
* once; a completed task will only go to one of the threads.
*
* \param queue the async I/O task queue to query.
* \param outcome details of a finished task will be written here. May not be
* NULL.
* \returns true if a task has completed, 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_WaitAsyncIOResult
*/
extern SDL_DECLSPEC bool SDLCALL SDL_GetAsyncIOResult(SDL_AsyncIOQueue *queue, SDL_AsyncIOOutcome *outcome);
/**
* Block until an async I/O task queue has a completed task.
*
* This function puts the calling thread to sleep until there a task assigned
* to the queue that has finished.
*
* If a task assigned to the queue has finished, this will return true and
* fill in `outcome` with the details of the task. If no task in the queue has
* finished, this function will return false.
*
* If a task has completed, this function will free its resources and the task
* pointer will no longer be valid. The task will be removed from the queue.
*
* It is safe for multiple threads to call this function on the same queue at
* once; a completed task will only go to one of the threads.
*
* Note that by the nature of various platforms, more than one waiting thread
* may wake to handle a single task, but only one will obtain it, so
* `timeoutMS` is a _maximum_ wait time, and this function may return false
* sooner.
*
* This function may return false if there was a system error, the OS
* inadvertently awoke multiple threads, or if SDL_SignalAsyncIOQueue() was
* called to wake up all waiting threads without a finished task.
*
* A timeout can be used to specify a maximum wait time, but rather than
* polling, it is possible to have a timeout of -1 to wait forever, and use
* SDL_SignalAsyncIOQueue() to wake up the waiting threads later.
*
* \param queue the async I/O task queue to wait on.
* \param outcome details of a finished task will be written here. May not be
* NULL.
* \param timeoutMS the maximum time to wait, in milliseconds, or -1 to wait
* indefinitely.
* \returns true if task has completed, 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_SignalAsyncIOQueue
*/
extern SDL_DECLSPEC bool SDLCALL SDL_WaitAsyncIOResult(SDL_AsyncIOQueue *queue, SDL_AsyncIOOutcome *outcome, Sint32 timeoutMS);
/**
* Wake up any threads that are blocking in SDL_WaitAsyncIOResult().
*
* This will unblock any threads that are sleeping in a call to
* SDL_WaitAsyncIOResult for the specified queue, and cause them to return
* from that function.
*
* This can be useful when destroying a queue to make sure nothing is touching
* it indefinitely. In this case, once this call completes, the caller should
* take measures to make sure any previously-blocked threads have returned
* from their wait and will not touch the queue again (perhaps by setting a
* flag to tell the threads to terminate and then using SDL_WaitThread() to
* make sure they've done so).
*
* \param queue the async I/O task queue to signal.
*
* \threadsafety It is safe to call this function from any thread.
*
* \since This function is available since SDL 3.2.0.
*
* \sa SDL_WaitAsyncIOResult
*/
extern SDL_DECLSPEC void SDLCALL SDL_SignalAsyncIOQueue(SDL_AsyncIOQueue *queue);
/**
* Load all the data from a file path, asynchronously.
*
* This function returns as quickly as possible; it does not wait for the read
* to complete. On a successful return, this work will continue in the
* background. If the work begins, even failure is asynchronous: a failing
* return value from this function only means the work couldn't start at all.
*
* The data is allocated with a zero byte at the end (null terminated) for
* convenience. This extra byte is not included in SDL_AsyncIOOutcome's
* bytes_transferred value.
*
* This function will allocate the buffer to contain the file. It must be
* deallocated by calling SDL_free() on SDL_AsyncIOOutcome's buffer field
* after completion.
*
* An SDL_AsyncIOQueue must be specified. The newly-created task will be added
* to it when it completes its work.
*
* \param file the path to read all available data from.
* \param queue a queue to add the new SDL_AsyncIO to.
* \param userdata an app-defined pointer that will be provided with the task
* results.
* \returns true on success or false on failure; call SDL_GetError() for more
* information.
*
* \since This function is available since SDL 3.2.0.
*
* \sa SDL_LoadFile_IO
*/
extern SDL_DECLSPEC bool SDLCALL SDL_LoadFileAsync(const char *file, SDL_AsyncIOQueue *queue, void *userdata);
/* Ends C function definitions when using C++ */
#ifdef __cplusplus
}
#endif
#include <SDL3/SDL_close_code.h>
#endif /* SDL_asyncio_h_ */

View File

@ -1,6 +1,6 @@
/*
Simple DirectMedia Layer
Copyright (C) 1997-2024 Sam Lantinga <slouken@libsdl.org>
Copyright (C) 1997-2025 Sam Lantinga <slouken@libsdl.org>
This software is provided 'as-is', without any express or implied
warranty. In no event will the authors be held liable for any damages
@ -88,15 +88,16 @@ typedef int SDL_SpinLock;
* doing. Please be careful using any sort of spinlock!***
*
* \param lock a pointer to a lock variable.
* \returns SDL_TRUE if the lock succeeded, SDL_FALSE if the lock is already
* held.
* \returns true if the lock succeeded, false if the lock is already held.
*
* \since This function is available since SDL 3.0.0.
* \threadsafety It is safe to call this function from any thread.
*
* \since This function is available since SDL 3.2.0.
*
* \sa SDL_LockSpinlock
* \sa SDL_UnlockSpinlock
*/
extern SDL_DECLSPEC SDL_bool SDLCALL SDL_TryLockSpinlock(SDL_SpinLock *lock);
extern SDL_DECLSPEC bool SDLCALL SDL_TryLockSpinlock(SDL_SpinLock *lock);
/**
* Lock a spin lock by setting it to a non-zero value.
@ -106,7 +107,9 @@ extern SDL_DECLSPEC SDL_bool SDLCALL SDL_TryLockSpinlock(SDL_SpinLock *lock);
*
* \param lock a pointer to a lock variable.
*
* \since This function is available since SDL 3.0.0.
* \threadsafety It is safe to call this function from any thread.
*
* \since This function is available since SDL 3.2.0.
*
* \sa SDL_TryLockSpinlock
* \sa SDL_UnlockSpinlock
@ -123,7 +126,9 @@ extern SDL_DECLSPEC void SDLCALL SDL_LockSpinlock(SDL_SpinLock *lock);
*
* \param lock a pointer to a lock variable.
*
* \since This function is available since SDL 3.0.0.
* \threadsafety It is safe to call this function from any thread.
*
* \since This function is available since SDL 3.2.0.
*
* \sa SDL_LockSpinlock
* \sa SDL_TryLockSpinlock
@ -147,9 +152,10 @@ extern SDL_DECLSPEC void SDLCALL SDL_UnlockSpinlock(SDL_SpinLock *lock);
* time, but if you find yourself needing this, you are probably
* dealing with some very sensitive code; be careful!
*
* \since This macro is available since SDL 3.0.0.
* \since This macro is available since SDL 3.2.0.
*/
#define SDL_CompilerBarrier() DoCompilerSpecificReadWriteBarrier()
#elif defined(_MSC_VER) && (_MSC_VER > 1200) && !defined(__clang__)
void _ReadWriteBarrier(void);
#pragma intrinsic(_ReadWriteBarrier)
@ -166,7 +172,50 @@ extern __inline void SDL_CompilerBarrier(void);
#endif
/**
* Insert a memory release barrier.
* Insert a memory release barrier (function version).
*
* Please refer to SDL_MemoryBarrierRelease for details. This is a function
* version, which might be useful if you need to use this functionality from a
* scripting language, etc. Also, some of the macro versions call this
* function behind the scenes, where more heavy lifting can happen inside of
* SDL. Generally, though, an app written in C/C++/etc should use the macro
* version, as it will be more efficient.
*
* \threadsafety Obviously this function is safe to use from any thread at any
* time, but if you find yourself needing this, you are probably
* dealing with some very sensitive code; be careful!
*
* \since This function is available since SDL 3.2.0.
*
* \sa SDL_MemoryBarrierRelease
*/
extern SDL_DECLSPEC void SDLCALL SDL_MemoryBarrierReleaseFunction(void);
/**
* Insert a memory acquire barrier (function version).
*
* Please refer to SDL_MemoryBarrierRelease for details. This is a function
* version, which might be useful if you need to use this functionality from a
* scripting language, etc. Also, some of the macro versions call this
* function behind the scenes, where more heavy lifting can happen inside of
* SDL. Generally, though, an app written in C/C++/etc should use the macro
* version, as it will be more efficient.
*
* \threadsafety Obviously this function is safe to use from any thread at any
* time, but if you find yourself needing this, you are probably
* dealing with some very sensitive code; be careful!
*
* \since This function is available since SDL 3.2.0.
*
* \sa SDL_MemoryBarrierAcquire
*/
extern SDL_DECLSPEC void SDLCALL SDL_MemoryBarrierAcquireFunction(void);
#ifdef SDL_WIKI_DOCUMENTATION_SECTION
/**
* Insert a memory release barrier (macro version).
*
* Memory barriers are designed to prevent reads and writes from being
* reordered by the compiler and being seen out of order on multi-core CPUs.
@ -186,31 +235,47 @@ extern __inline void SDL_CompilerBarrier(void);
* For more information on these semantics, take a look at the blog post:
* http://preshing.com/20120913/acquire-and-release-semantics
*
* This is the macro version of this functionality; if possible, SDL will use
* compiler intrinsics or inline assembly, but some platforms might need to
* call the function version of this, SDL_MemoryBarrierReleaseFunction to do
* the heavy lifting. Apps that can use the macro should favor it over the
* function.
*
* \threadsafety Obviously this macro is safe to use from any thread at any
* time, but if you find yourself needing this, you are probably
* dealing with some very sensitive code; be careful!
*
* \since This function is available since SDL 3.0.0.
* \since This macro is available since SDL 3.2.0.
*
* \sa SDL_MemoryBarrierAcquire
* \sa SDL_MemoryBarrierReleaseFunction
*/
extern SDL_DECLSPEC void SDLCALL SDL_MemoryBarrierReleaseFunction(void);
#define SDL_MemoryBarrierRelease() SDL_MemoryBarrierReleaseFunction()
/**
* Insert a memory acquire barrier.
* Insert a memory acquire barrier (macro version).
*
* Please refer to SDL_MemoryBarrierReleaseFunction for the details!
* Please see SDL_MemoryBarrierRelease for the details on what memory barriers
* are and when to use them.
*
* \threadsafety Obviously this function is safe to use from any thread at any
* This is the macro version of this functionality; if possible, SDL will use
* compiler intrinsics or inline assembly, but some platforms might need to
* call the function version of this, SDL_MemoryBarrierAcquireFunction, to do
* the heavy lifting. Apps that can use the macro should favor it over the
* function.
*
* \threadsafety Obviously this macro is safe to use from any thread at any
* time, but if you find yourself needing this, you are probably
* dealing with some very sensitive code; be careful!
*
* \since This function is available since SDL 3.0.0.
* \since This macro is available since SDL 3.2.0.
*
* \sa SDL_MemoryBarrierReleaseFunction
* \sa SDL_MemoryBarrierRelease
* \sa SDL_MemoryBarrierAcquireFunction
*/
extern SDL_DECLSPEC void SDLCALL SDL_MemoryBarrierAcquireFunction(void);
#define SDL_MemoryBarrierAcquire() SDL_MemoryBarrierAcquireFunction()
/* !!! FIXME: this should have documentation! */
#if defined(__GNUC__) && (defined(__powerpc__) || defined(__ppc__))
#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__)
@ -225,8 +290,8 @@ extern SDL_DECLSPEC void SDLCALL SDL_MemoryBarrierAcquireFunction(void);
hard-coded at address 0xffff0fa0
*/
typedef void (*SDL_KernelMemoryBarrierFunc)();
#define SDL_MemoryBarrierRelease() ((SDL_KernelMemoryBarrierFunc)0xffff0fa0)()
#define SDL_MemoryBarrierAcquire() ((SDL_KernelMemoryBarrierFunc)0xffff0fa0)()
#define SDL_MemoryBarrierRelease() ((SDL_KernelMemoryBarrierFunc)0xffff0fa0)()
#define SDL_MemoryBarrierAcquire() ((SDL_KernelMemoryBarrierFunc)0xffff0fa0)()
#else
#if defined(__ARM_ARCH_7__) || defined(__ARM_ARCH_7A__) || defined(__ARM_ARCH_7EM__) || defined(__ARM_ARCH_7R__) || defined(__ARM_ARCH_7M__) || defined(__ARM_ARCH_7S__) || defined(__ARM_ARCH_8A__)
#define SDL_MemoryBarrierRelease() __asm__ __volatile__ ("dmb ish" : : : "memory")
@ -276,9 +341,10 @@ typedef void (*SDL_KernelMemoryBarrierFunc)();
*
* \threadsafety This macro is safe to use from any thread.
*
* \since This macro is available since SDL 3.0.0.
* \since This macro is available since SDL 3.2.0.
*/
#define SDL_CPUPauseInstruction() DoACPUPauseInACompilerAndArchitectureSpecificWay
#elif (defined(__GNUC__) || defined(__clang__)) && (defined(__i386__) || defined(__x86_64__))
#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__)
@ -303,9 +369,10 @@ typedef void (*SDL_KernelMemoryBarrierFunc)();
* A type representing an atomic integer value.
*
* This can be used to manage a value that is synchronized across multiple
* CPUs without a race condition; when an app sets a value with SDL_AtomicSet
* all other threads, regardless of the CPU it is running on, will see that
* value when retrieved with SDL_AtomicGet, regardless of CPU caches, etc.
* CPUs without a race condition; when an app sets a value with
* SDL_SetAtomicInt all other threads, regardless of the CPU it is running on,
* will see that value when retrieved with SDL_GetAtomicInt, regardless of CPU
* caches, etc.
*
* This is also useful for atomic compare-and-swap operations: a thread can
* change the value as long as its current value matches expectations. When
@ -316,14 +383,14 @@ typedef void (*SDL_KernelMemoryBarrierFunc)();
* this!).
*
* This is a struct so people don't accidentally use numeric operations on it
* directly. You have to use SDL_Atomic* functions.
* directly. You have to use SDL atomic functions.
*
* \since This struct is available since SDL 3.0.0.
* \since This struct is available since SDL 3.2.0.
*
* \sa SDL_AtomicCompareAndSwap
* \sa SDL_AtomicGet
* \sa SDL_AtomicSet
* \sa SDL_AtomicAdd
* \sa SDL_CompareAndSwapAtomicInt
* \sa SDL_GetAtomicInt
* \sa SDL_SetAtomicInt
* \sa SDL_AddAtomicInt
*/
typedef struct SDL_AtomicInt { int value; } SDL_AtomicInt;
@ -336,15 +403,16 @@ typedef struct SDL_AtomicInt { int value; } SDL_AtomicInt;
* \param a a pointer to an SDL_AtomicInt variable to be modified.
* \param oldval the old value.
* \param newval the new value.
* \returns SDL_TRUE if the atomic variable was set, SDL_FALSE otherwise.
* \returns true if the atomic variable was set, false otherwise.
*
* \threadsafety It is safe to call this function from any thread.
*
* \since This function is available since SDL 3.0.0.
* \since This function is available since SDL 3.2.0.
*
* \sa SDL_AtomicCompareAndSwapPointer
* \sa SDL_GetAtomicInt
* \sa SDL_SetAtomicInt
*/
extern SDL_DECLSPEC SDL_bool SDLCALL SDL_AtomicCompareAndSwap(SDL_AtomicInt *a, int oldval, int newval);
extern SDL_DECLSPEC bool SDLCALL SDL_CompareAndSwapAtomicInt(SDL_AtomicInt *a, int oldval, int newval);
/**
* Set an atomic variable to a value.
@ -360,11 +428,11 @@ extern SDL_DECLSPEC SDL_bool SDLCALL SDL_AtomicCompareAndSwap(SDL_AtomicInt *a,
*
* \threadsafety It is safe to call this function from any thread.
*
* \since This function is available since SDL 3.0.0.
* \since This function is available since SDL 3.2.0.
*
* \sa SDL_AtomicGet
* \sa SDL_GetAtomicInt
*/
extern SDL_DECLSPEC int SDLCALL SDL_AtomicSet(SDL_AtomicInt *a, int v);
extern SDL_DECLSPEC int SDLCALL SDL_SetAtomicInt(SDL_AtomicInt *a, int v);
/**
* Get the value of an atomic variable.
@ -377,11 +445,11 @@ extern SDL_DECLSPEC int SDLCALL SDL_AtomicSet(SDL_AtomicInt *a, int v);
*
* \threadsafety It is safe to call this function from any thread.
*
* \since This function is available since SDL 3.0.0.
* \since This function is available since SDL 3.2.0.
*
* \sa SDL_AtomicSet
* \sa SDL_SetAtomicInt
*/
extern SDL_DECLSPEC int SDLCALL SDL_AtomicGet(SDL_AtomicInt *a);
extern SDL_DECLSPEC int SDLCALL SDL_GetAtomicInt(SDL_AtomicInt *a);
/**
* Add to an atomic variable.
@ -397,12 +465,12 @@ extern SDL_DECLSPEC int SDLCALL SDL_AtomicGet(SDL_AtomicInt *a);
*
* \threadsafety It is safe to call this function from any thread.
*
* \since This function is available since SDL 3.0.0.
* \since This function is available since SDL 3.2.0.
*
* \sa SDL_AtomicDecRef
* \sa SDL_AtomicIncRef
*/
extern SDL_DECLSPEC int SDLCALL SDL_AtomicAdd(SDL_AtomicInt *a, int v);
extern SDL_DECLSPEC int SDLCALL SDL_AddAtomicInt(SDL_AtomicInt *a, int v);
#ifndef SDL_AtomicIncRef
@ -414,11 +482,13 @@ extern SDL_DECLSPEC int SDLCALL SDL_AtomicAdd(SDL_AtomicInt *a, int v);
* \param a a pointer to an SDL_AtomicInt to increment.
* \returns the previous value of the atomic variable.
*
* \since This macro is available since SDL 3.0.0.
* \threadsafety It is safe to call this macro from any thread.
*
* \since This macro is available since SDL 3.2.0.
*
* \sa SDL_AtomicDecRef
*/
#define SDL_AtomicIncRef(a) SDL_AtomicAdd(a, 1)
#define SDL_AtomicIncRef(a) SDL_AddAtomicInt(a, 1)
#endif
#ifndef SDL_AtomicDecRef
@ -429,16 +499,103 @@ extern SDL_DECLSPEC int SDLCALL SDL_AtomicAdd(SDL_AtomicInt *a, int v);
* ***Note: If you don't know what this macro is for, you shouldn't use it!***
*
* \param a a pointer to an SDL_AtomicInt to increment.
* \returns SDL_TRUE if the variable reached zero after decrementing,
* SDL_FALSE otherwise.
* \returns true if the variable reached zero after decrementing, false
* otherwise.
*
* \since This macro is available since SDL 3.0.0.
* \threadsafety It is safe to call this macro from any thread.
*
* \since This macro is available since SDL 3.2.0.
*
* \sa SDL_AtomicIncRef
*/
#define SDL_AtomicDecRef(a) (SDL_AtomicAdd(a, -1) == 1)
#define SDL_AtomicDecRef(a) (SDL_AddAtomicInt(a, -1) == 1)
#endif
/**
* A type representing an atomic unsigned 32-bit value.
*
* This can be used to manage a value that is synchronized across multiple
* CPUs without a race condition; when an app sets a value with
* SDL_SetAtomicU32 all other threads, regardless of the CPU it is running on,
* will see that value when retrieved with SDL_GetAtomicU32, regardless of CPU
* caches, etc.
*
* This is also useful for atomic compare-and-swap operations: a thread can
* change the value as long as its current value matches expectations. When
* done in a loop, one can guarantee data consistency across threads without a
* lock (but the usual warnings apply: if you don't know what you're doing, or
* you don't do it carefully, you can confidently cause any number of
* disasters with this, so in most cases, you _should_ use a mutex instead of
* this!).
*
* This is a struct so people don't accidentally use numeric operations on it
* directly. You have to use SDL atomic functions.
*
* \since This struct is available since SDL 3.2.0.
*
* \sa SDL_CompareAndSwapAtomicU32
* \sa SDL_GetAtomicU32
* \sa SDL_SetAtomicU32
*/
typedef struct SDL_AtomicU32 { Uint32 value; } SDL_AtomicU32;
/**
* Set an atomic variable to a new value if it is currently an old value.
*
* ***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 oldval the old value.
* \param newval the new value.
* \returns true if the atomic variable was set, 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_GetAtomicU32
* \sa SDL_SetAtomicU32
*/
extern SDL_DECLSPEC bool SDLCALL SDL_CompareAndSwapAtomicU32(SDL_AtomicU32 *a, Uint32 oldval, Uint32 newval);
/**
* Set an atomic variable to a value.
*
* 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.
* \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.2.0.
*
* \sa SDL_GetAtomicU32
*/
extern SDL_DECLSPEC Uint32 SDLCALL SDL_SetAtomicU32(SDL_AtomicU32 *a, Uint32 v);
/**
* Get the value of an atomic variable.
*
* ***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.
* \returns the current value of an atomic variable.
*
* \threadsafety It is safe to call this function from any thread.
*
* \since This function is available since SDL 3.2.0.
*
* \sa SDL_SetAtomicU32
*/
extern SDL_DECLSPEC Uint32 SDLCALL SDL_GetAtomicU32(SDL_AtomicU32 *a);
/**
* Set a pointer to a new value if it is currently an old value.
*
@ -448,17 +605,17 @@ extern SDL_DECLSPEC int SDLCALL SDL_AtomicAdd(SDL_AtomicInt *a, int v);
* \param a a pointer to a pointer.
* \param oldval the old pointer value.
* \param newval the new pointer value.
* \returns SDL_TRUE if the pointer was set, SDL_FALSE otherwise.
* \returns true if the pointer was set, false otherwise.
*
* \threadsafety It is safe to call this function from any thread.
*
* \since This function is available since SDL 3.0.0.
* \since This function is available since SDL 3.2.0.
*
* \sa SDL_AtomicCompareAndSwap
* \sa SDL_AtomicGetPointer
* \sa SDL_AtomicSetPointer
* \sa SDL_CompareAndSwapAtomicInt
* \sa SDL_GetAtomicPointer
* \sa SDL_SetAtomicPointer
*/
extern SDL_DECLSPEC SDL_bool SDLCALL SDL_AtomicCompareAndSwapPointer(void **a, void *oldval, void *newval);
extern SDL_DECLSPEC bool SDLCALL SDL_CompareAndSwapAtomicPointer(void **a, void *oldval, void *newval);
/**
* Set a pointer to a value atomically.
@ -472,12 +629,12 @@ extern SDL_DECLSPEC SDL_bool SDLCALL SDL_AtomicCompareAndSwapPointer(void **a, v
*
* \threadsafety It is safe to call this function from any thread.
*
* \since This function is available since SDL 3.0.0.
* \since This function is available since SDL 3.2.0.
*
* \sa SDL_AtomicCompareAndSwapPointer
* \sa SDL_AtomicGetPointer
* \sa SDL_CompareAndSwapAtomicPointer
* \sa SDL_GetAtomicPointer
*/
extern SDL_DECLSPEC void * SDLCALL SDL_AtomicSetPointer(void **a, void *v);
extern SDL_DECLSPEC void * SDLCALL SDL_SetAtomicPointer(void **a, void *v);
/**
* Get the value of a pointer atomically.
@ -490,12 +647,12 @@ extern SDL_DECLSPEC void * SDLCALL SDL_AtomicSetPointer(void **a, void *v);
*
* \threadsafety It is safe to call this function from any thread.
*
* \since This function is available since SDL 3.0.0.
* \since This function is available since SDL 3.2.0.
*
* \sa SDL_AtomicCompareAndSwapPointer
* \sa SDL_AtomicSetPointer
* \sa SDL_CompareAndSwapAtomicPointer
* \sa SDL_SetAtomicPointer
*/
extern SDL_DECLSPEC void * SDLCALL SDL_AtomicGetPointer(void **a);
extern SDL_DECLSPEC void * SDLCALL SDL_GetAtomicPointer(void **a);
/* Ends C function definitions when using C++ */
#ifdef __cplusplus

File diff suppressed because it is too large Load Diff

View File

@ -1,6 +1,6 @@
/*
Simple DirectMedia Layer
Copyright (C) 1997-2024 Sam Lantinga <slouken@libsdl.org>
Copyright (C) 1997-2025 Sam Lantinga <slouken@libsdl.org>
This software is provided 'as-is', without any express or implied
warranty. In no event will the authors be held liable for any damages
@ -22,9 +22,15 @@
/* WIKI CATEGORY: BeginCode */
/**
* SDL_begin_code.h sets things up for C dynamic library function definitions,
* static inlined functions, and structures aligned at 4-byte alignment.
* If you don't like ugly C preprocessor code, don't look at this file. :)
* # CategoryBeginCode
*
* `SDL_begin_code.h` sets things up for C dynamic library function
* definitions, static inlined functions, and structures aligned at 4-byte
* alignment. If you don't like ugly C preprocessor code, don't look at this
* file. :)
*
* SDL's headers use this; applications generally should not include this
* header directly.
*/
/* This shouldn't be nested -- included it around code only. */
@ -33,6 +39,259 @@
#endif
#define SDL_begin_code_h
#ifdef SDL_WIKI_DOCUMENTATION_SECTION
/**
* A macro to tag a symbol as deprecated.
*
* A function is marked deprecated by adding this macro to its declaration:
*
* ```c
* extern SDL_DEPRECATED int ThisFunctionWasABadIdea(void);
* ```
*
* Compilers with deprecation support can give a warning when a deprecated
* function is used. This symbol may be used in SDL's headers, but apps are
* welcome to use it for their own interfaces as well.
*
* SDL, on occasion, might deprecate a function for various reasons. However,
* SDL never removes symbols before major versions, so deprecated interfaces
* in SDL3 will remain available until SDL4, where it would be expected an app
* would have to take steps to migrate anyhow.
*
* On compilers without a deprecation mechanism, this is defined to nothing,
* and using a deprecated function will not generate a warning.
*
* \since This macro is available since SDL 3.2.0.
*/
#define SDL_DEPRECATED __attribute__((deprecated))
/**
* A macro to tag a symbol as a public API.
*
* SDL uses this macro for all its public functions. On some targets, it is
* used to signal to the compiler that this function needs to be exported from
* a shared library, but it might have other side effects.
*
* This symbol is used in SDL's headers, but apps and other libraries are
* welcome to use it for their own interfaces as well.
*
* \since This macro is available since SDL 3.2.0.
*/
#define SDL_DECLSPEC __attribute__ ((visibility("default")))
/**
* A macro to set a function's calling conventions.
*
* SDL uses this macro for all its public functions, and any callbacks it
* defines. This macro guarantees that calling conventions match between SDL
* and the app, even if the two were built with different compilers or
* optimization settings.
*
* When writing a callback function, it is very important for it to be
* correctly tagged with SDLCALL, as mismatched calling conventions can cause
* strange behaviors and can be difficult to diagnose. Plus, on many
* platforms, SDLCALL is defined to nothing, so compilers won't be able to
* warn that the tag is missing.
*
* This symbol is used in SDL's headers, but apps and other libraries are
* welcome to use it for their own interfaces as well.
*
* \since This macro is available since SDL 3.2.0.
*/
#define SDLCALL __cdecl
/**
* A macro to request a function be inlined.
*
* This is a hint to the compiler to inline a function. The compiler is free
* to ignore this request. On compilers without inline support, this is
* defined to nothing.
*
* \since This macro is available since SDL 3.2.0.
*/
#define SDL_INLINE __inline
/**
* A macro to demand a function be inlined.
*
* This is a command to the compiler to inline a function. SDL uses this macro
* in its public headers for a handful of simple functions. On compilers
* without forceinline support, this is defined to `static SDL_INLINE`, which
* is often good enough.
*
* This symbol is used in SDL's headers, but apps and other libraries are
* welcome to use it for their own interfaces as well.
*
* \since This macro is available since SDL 3.2.0.
*/
#define SDL_FORCE_INLINE __forceinline
/**
* A macro to tag a function as never-returning.
*
* This is a hint to the compiler that a function does not return. An example
* of a function like this is the C runtime's exit() function.
*
* This hint can lead to code optimizations, and help analyzers understand
* code flow better. On compilers without noreturn support, this is defined to
* nothing.
*
* This symbol is used in SDL's headers, but apps and other libraries are
* welcome to use it for their own interfaces as well.
*
* \since This macro is available since SDL 3.2.0.
*/
#define SDL_NORETURN __attribute__((noreturn))
/**
* A macro to tag a function as never-returning (for analysis purposes).
*
* This is almost identical to SDL_NORETURN, except functions marked with this
* _can_ actually return. The difference is that this isn't used for code
* generation, but rather static analyzers use this information to assume
* truths about program state and available code paths. Specifically, this tag
* is useful for writing an assertion mechanism. Indeed, SDL_assert uses this
* tag behind the scenes. Generally, apps that don't understand the specific
* use-case for this tag should avoid using it directly.
*
* On compilers without analyzer_noreturn support, this is defined to nothing.
*
* This symbol is used in SDL's headers, but apps and other libraries are
* welcome to use it for their own interfaces as well.
*
* \since This macro is available since SDL 3.2.0.
*/
#define SDL_ANALYZER_NORETURN __attribute__((analyzer_noreturn))
/**
* A macro to signal that a case statement without a `break` is intentional.
*
* C compilers have gotten more aggressive about warning when a switch's
* `case` block does not end with a `break` or other flow control statement,
* flowing into the next case's code, as this is a common accident that leads
* to strange bugs. But sometimes falling through to the next case is the
* correct and desired behavior. This symbol lets an app communicate this
* intention to the compiler, so it doesn't generate a warning.
*
* It is used like this:
*
* ```c
* switch (x) {
* case 1:
* DoSomethingOnlyForOne();
* SDL_FALLTHROUGH; // tell the compiler this was intentional.
* case 2:
* DoSomethingForOneAndTwo();
* break;
* }
* ```
*
* \since This macro is available since SDL 3.2.0.
*/
#define SDL_FALLTHROUGH [[fallthrough]]
/**
* A macro to tag a function's return value as critical.
*
* This is a hint to the compiler that a function's return value should not be
* ignored.
*
* If an NODISCARD function's return value is thrown away (the function is
* called as if it returns `void`), the compiler will issue a warning.
*
* While it's generally good practice to check return values for errors, often
* times legitimate programs do not for good reasons. Be careful about what
* functions are tagged as NODISCARD. It operates best when used on a function
* that's failure is surprising and catastrophic; a good example would be a
* program that checks the return values of all its file write function calls
* but not the call to close the file, which it assumes incorrectly never
* fails.
*
* Function callers that want to throw away a NODISCARD return value can call
* the function with a `(void)` cast, which informs the compiler the act is
* intentional.
*
* On compilers without nodiscard support, this is defined to nothing.
*
* \since This macro is available since SDL 3.2.0.
*/
#define SDL_NODISCARD [[nodiscard]]
/**
* A macro to tag a function as an allocator.
*
* This is a hint to the compiler that a function is an allocator, like
* malloc(), with certain rules. A description of how GCC treats this hint is
* here:
*
* https://gcc.gnu.org/onlinedocs/gcc/Common-Function-Attributes.html#index-malloc-function-attribute
*
* On compilers without allocator tag support, this is defined to nothing.
*
* Most apps don't need to, and should not, use this directly.
*
* \since This macro is available since SDL 3.2.0.
*/
#define SDL_MALLOC __declspec(allocator) __desclspec(restrict)
/**
* A macro to tag a function as returning a certain allocation.
*
* This is a hint to the compiler that a function allocates and returns a
* specific amount of memory based on one of its arguments. For example, the C
* runtime's malloc() function could use this macro with an argument of 1
* (first argument to malloc is the size of the allocation).
*
* On compilers without alloc_size support, this is defined to nothing.
*
* Most apps don't need to, and should not, use this directly.
*
* \since This macro is available since SDL 3.2.0.
*/
#define SDL_ALLOC_SIZE(p) __attribute__((alloc_size(p)))
/**
* A macro to tag a pointer variable, to help with pointer aliasing.
*
* A good explanation of the restrict keyword is here:
*
* https://en.wikipedia.org/wiki/Restrict
*
* On compilers without restrict support, this is defined to nothing.
*
* \since This macro is available since SDL 3.2.0.
*/
#define SDL_RESTRICT __restrict__
/**
* Check if the compiler supports a given builtin functionality.
*
* This allows preprocessor checks for things that otherwise might fail to
* compile.
*
* Supported by virtually all clang versions and more-recent GCCs. Use this
* instead of checking the clang version if possible.
*
* On compilers without has_builtin support, this is defined to 0 (always
* false).
*
* \since This macro is available since SDL 3.2.0.
*/
#define SDL_HAS_BUILTIN(x) __has_builtin(x)
/* end of wiki documentation section. */
#endif
#ifndef SDL_HAS_BUILTIN
#ifdef __has_builtin
#define SDL_HAS_BUILTIN(x) __has_builtin(x)
#else
#define SDL_HAS_BUILTIN(x) 0
#endif
#endif
#ifndef SDL_DEPRECATED
# if defined(__GNUC__) && (__GNUC__ >= 4) /* technically, this arrived in gcc 3.1, but oh well. */
# define SDL_DEPRECATED __attribute__((deprecated))
@ -53,7 +312,7 @@
/* Some compilers use a special export keyword */
#ifndef SDL_DECLSPEC
# if defined(SDL_PLATFORM_WIN32) || defined(SDL_PLATFORM_WINRT) || defined(SDL_PLATFORM_CYGWIN) || defined(SDL_PLATFORM_GDK)
# if defined(SDL_PLATFORM_WINDOWS)
# ifdef DLL_EXPORT
# define SDL_DECLSPEC __declspec(dllexport)
# else
@ -70,7 +329,7 @@
/* By default SDL uses the C calling convention */
#ifndef SDLCALL
#if (defined(SDL_PLATFORM_WIN32) || defined(SDL_PLATFORM_WINRT) || defined(SDL_PLATFORM_GDK)) && !defined(__GNUC__)
#if defined(SDL_PLATFORM_WINDOWS) && !defined(__GNUC__)
#define SDLCALL __cdecl
#else
#define SDLCALL

View File

@ -1,6 +1,6 @@
/*
Simple DirectMedia Layer
Copyright (C) 1997-2024 Sam Lantinga <slouken@libsdl.org>
Copyright (C) 1997-2025 Sam Lantinga <slouken@libsdl.org>
This software is provided 'as-is', without any express or implied
warranty. In no event will the authors be held liable for any damages
@ -36,10 +36,6 @@
extern "C" {
#endif
/**
* \file SDL_bits.h
*/
#if defined(__WATCOMC__) && defined(__386__)
extern __inline int _SDL_bsr_watcom(Uint32);
#pragma aux _SDL_bsr_watcom = \
@ -65,7 +61,7 @@ extern __inline int _SDL_bsr_watcom(Uint32);
*
* \threadsafety It is safe to call this function from any thread.
*
* \since This function is available since SDL 3.0.0.
* \since This function is available since SDL 3.2.0.
*/
SDL_FORCE_INLINE int SDL_MostSignificantBitIndex32(Uint32 x)
{
@ -82,10 +78,10 @@ SDL_FORCE_INLINE int SDL_MostSignificantBitIndex32(Uint32 x)
return -1;
}
return _SDL_bsr_watcom(x);
#elif defined(_MSC_VER)
#elif defined(_MSC_VER) && _MSC_VER >= 1400
unsigned long index;
if (_BitScanReverse(&index, x)) {
return index;
return (int)index;
}
return -1;
#else
@ -120,8 +116,7 @@ SDL_FORCE_INLINE int SDL_MostSignificantBitIndex32(Uint32 x)
* Determine if a unsigned 32-bit value has exactly one bit set.
*
* If there are no bits set (`x` is zero), or more than one bit set, this
* returns SDL_FALSE. If any one bit is exclusively set, this returns
* SDL_TRUE.
* returns false. If any one bit is exclusively set, this returns true.
*
* 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
@ -129,18 +124,18 @@ SDL_FORCE_INLINE int SDL_MostSignificantBitIndex32(Uint32 x)
* be able to find this function inside SDL itself).
*
* \param x the 32-bit value to examine.
* \returns SDL_TRUE if exactly one bit is set in `x`, SDL_FALSE otherwise.
* \returns true if exactly one bit is set in `x`, false otherwise.
*
* \threadsafety It is safe to call this function from any thread.
*
* \since This function is available since SDL 3.0.0.
* \since This function is available since SDL 3.2.0.
*/
SDL_FORCE_INLINE SDL_bool SDL_HasExactlyOneBitSet32(Uint32 x)
SDL_FORCE_INLINE bool SDL_HasExactlyOneBitSet32(Uint32 x)
{
if (x && !(x & (x - 1))) {
return SDL_TRUE;
return true;
}
return SDL_FALSE;
return false;
}
/* Ends C function definitions when using C++ */

View File

@ -1,6 +1,6 @@
/*
Simple DirectMedia Layer
Copyright (C) 1997-2024 Sam Lantinga <slouken@libsdl.org>
Copyright (C) 1997-2025 Sam Lantinga <slouken@libsdl.org>
This software is provided 'as-is', without any express or implied
warranty. In no event will the authors be held liable for any damages
@ -24,7 +24,7 @@
*
* Blend modes decide how two colors will mix together. There are both
* standard modes for basic needs and a means to create custom modes,
* dictating what sort of math to do what on what color components.
* dictating what sort of math to do on what color components.
*/
#ifndef SDL_blendmode_h_
@ -45,7 +45,7 @@ extern "C" {
*
* Additional values may be obtained from SDL_ComposeCustomBlendMode.
*
* \since This datatype is available since SDL 3.0.0.
* \since This datatype is available since SDL 3.2.0.
*
* \sa SDL_ComposeCustomBlendMode
*/
@ -64,7 +64,7 @@ typedef Uint32 SDL_BlendMode;
* The blend operation used when combining source and destination pixel
* components.
*
* \since This enum is available since SDL 3.0.0.
* \since This enum is available since SDL 3.2.0.
*/
typedef enum SDL_BlendOperation
{
@ -83,7 +83,7 @@ typedef enum SDL_BlendOperation
* operation. The comma-separated factors listed above are always applied in
* the component order red, green, blue, and alpha.
*
* \since This enum is available since SDL 3.0.0.
* \since This enum is available since SDL 3.2.0.
*/
typedef enum SDL_BlendFactor
{
@ -177,7 +177,9 @@ typedef enum SDL_BlendFactor
* \returns an SDL_BlendMode that represents the chosen factors and
* operations.
*
* \since This function is available since SDL 3.0.0.
* \threadsafety It is safe to call this function from any thread.
*
* \since This function is available since SDL 3.2.0.
*
* \sa SDL_SetRenderDrawBlendMode
* \sa SDL_GetRenderDrawBlendMode

View File

@ -1,6 +1,6 @@
/*
Simple DirectMedia Layer
Copyright (C) 1997-2024 Sam Lantinga <slouken@libsdl.org>
Copyright (C) 1997-2025 Sam Lantinga <slouken@libsdl.org>
This software is provided 'as-is', without any express or implied
warranty. In no event will the authors be held liable for any damages
@ -28,13 +28,51 @@
* devices can be enumerated, queried, and opened. Once opened, it will
* provide SDL_Surface objects as new frames of video come in. These surfaces
* can be uploaded to an SDL_Texture or processed as pixels in memory.
*
* Several platforms will alert the user if an app tries to access a camera,
* and some will present a UI asking the user if your application should be
* allowed to obtain images at all, which they can deny. A successfully opened
* camera will not provide images until permission is granted. Applications,
* after opening a camera device, can see if they were granted access by
* either polling with the SDL_GetCameraPermissionState() function, or waiting
* for an SDL_EVENT_CAMERA_DEVICE_APPROVED or SDL_EVENT_CAMERA_DEVICE_DENIED
* event. Platforms that don't have any user approval process will report
* approval immediately.
*
* Note that SDL cameras only provide video as individual frames; they will
* not provide full-motion video encoded in a movie file format, although an
* app is free to encode the acquired frames into any format it likes. It also
* does not provide audio from the camera hardware through this API; not only
* do many webcams not have microphones at all, many people--from streamers to
* people on Zoom calls--will want to use a separate microphone regardless of
* the camera. In any case, recorded audio will be available through SDL's
* audio API no matter what hardware provides the microphone.
*
* ## Camera gotchas
*
* Consumer-level camera hardware tends to take a little while to warm up,
* once the device has been opened. Generally most camera apps have some sort
* of UI to take a picture (a button to snap a pic while a preview is showing,
* some sort of multi-second countdown for the user to pose, like a photo
* booth), which puts control in the users' hands, or they are intended to
* stay on for long times (Pokemon Go, etc).
*
* It's not uncommon that a newly-opened camera will provide a couple of
* completely black frames, maybe followed by some under-exposed images. If
* taking a single frame automatically, or recording video from a camera's
* input without the user initiating it from a preview, it could be wise to
* drop the first several frames (if not the first several _seconds_ worth of
* frames!) before using images from a camera.
*/
#ifndef SDL_camera_h_
#define SDL_camera_h_
#include <SDL3/SDL_stdinc.h>
#include <SDL3/SDL_error.h>
#include <SDL3/SDL_video.h>
#include <SDL3/SDL_pixels.h>
#include <SDL3/SDL_properties.h>
#include <SDL3/SDL_surface.h>
#include <SDL3/SDL_begin_code.h>
/* Set up for C function definitions, even when using C++ */
@ -50,7 +88,7 @@ extern "C" {
*
* The value 0 is an invalid ID.
*
* \since This datatype is available since SDL 3.0.0.
* \since This datatype is available since SDL 3.2.0.
*
* \sa SDL_GetCameras
*/
@ -59,7 +97,7 @@ typedef Uint32 SDL_CameraID;
/**
* The opaque structure used to identify an opened SDL camera.
*
* \since This struct is available since SDL 3.0.0.
* \since This struct is available since SDL 3.2.0.
*/
typedef struct SDL_Camera SDL_Camera;
@ -69,7 +107,7 @@ typedef struct SDL_Camera SDL_Camera;
* Cameras often support multiple formats; each one will be encapsulated in
* this struct.
*
* \since This struct is available since SDL 3.0.0.
* \since This struct is available since SDL 3.2.0.
*
* \sa SDL_GetCameraSupportedFormats
* \sa SDL_GetCameraFormat
@ -87,7 +125,7 @@ typedef struct SDL_CameraSpec
/**
* The position of camera in relation to system device.
*
* \since This enum is available since SDL 3.0.0.
* \since This enum is available since SDL 3.2.0.
*
* \sa SDL_GetCameraPosition
*/
@ -116,7 +154,7 @@ typedef enum SDL_CameraPosition
*
* \threadsafety It is safe to call this function from any thread.
*
* \since This function is available since SDL 3.0.0.
* \since This function is available since SDL 3.2.0.
*
* \sa SDL_GetCameraDriver
*/
@ -140,7 +178,7 @@ extern SDL_DECLSPEC int SDLCALL SDL_GetNumCameraDrivers(void);
*
* \threadsafety It is safe to call this function from any thread.
*
* \since This function is available since SDL 3.0.0.
* \since This function is available since SDL 3.2.0.
*
* \sa SDL_GetNumCameraDrivers
*/
@ -158,7 +196,7 @@ extern SDL_DECLSPEC const char * SDLCALL SDL_GetCameraDriver(int index);
*
* \threadsafety It is safe to call this function from any thread.
*
* \since This function is available since SDL 3.0.0.
* \since This function is available since SDL 3.2.0.
*/
extern SDL_DECLSPEC const char * SDLCALL SDL_GetCurrentCameraDriver(void);
@ -173,7 +211,7 @@ extern SDL_DECLSPEC const char * SDLCALL SDL_GetCurrentCameraDriver(void);
*
* \threadsafety It is safe to call this function from any thread.
*
* \since This function is available since SDL 3.0.0.
* \since This function is available since SDL 3.2.0.
*
* \sa SDL_OpenCamera
*/
@ -211,7 +249,7 @@ extern SDL_DECLSPEC SDL_CameraID * SDLCALL SDL_GetCameras(int *count);
*
* \threadsafety It is safe to call this function from any thread.
*
* \since This function is available since SDL 3.0.0.
* \since This function is available since SDL 3.2.0.
*
* \sa SDL_GetCameras
* \sa SDL_OpenCamera
@ -227,7 +265,7 @@ extern SDL_DECLSPEC SDL_CameraSpec ** SDLCALL SDL_GetCameraSupportedFormats(SDL_
*
* \threadsafety It is safe to call this function from any thread.
*
* \since This function is available since SDL 3.0.0.
* \since This function is available since SDL 3.2.0.
*
* \sa SDL_GetCameras
*/
@ -246,7 +284,7 @@ extern SDL_DECLSPEC const char * SDLCALL SDL_GetCameraName(SDL_CameraID instance
*
* \threadsafety It is safe to call this function from any thread.
*
* \since This function is available since SDL 3.0.0.
* \since This function is available since SDL 3.2.0.
*
* \sa SDL_GetCameras
*/
@ -265,7 +303,7 @@ extern SDL_DECLSPEC SDL_CameraPosition SDLCALL SDL_GetCameraPosition(SDL_CameraI
*
* You can call SDL_GetCameraFormat() to get the actual data format if passing
* a NULL spec here. You can see the exact specs a device can support without
* conversion with SDL_GetCameraSupportedSpecs().
* conversion with SDL_GetCameraSupportedFormats().
*
* SDL will not attempt to emulate framerate; it will try to set the hardware
* to the rate closest to the requested speed, but it won't attempt to limit
@ -278,10 +316,11 @@ extern SDL_DECLSPEC SDL_CameraPosition SDLCALL SDL_GetCameraPosition(SDL_CameraI
* the camera, and they can choose Yes or No at that point. Until they do, the
* camera will not be usable. The app should either wait for an
* SDL_EVENT_CAMERA_DEVICE_APPROVED (or SDL_EVENT_CAMERA_DEVICE_DENIED) event,
* or poll SDL_IsCameraApproved() occasionally until it returns non-zero. On
* platforms that don't require explicit user approval (and perhaps in places
* where the user previously permitted access), the approval event might come
* immediately, but it might come seconds, minutes, or hours later!
* or poll SDL_GetCameraPermissionState() occasionally until it returns
* non-zero. On platforms that don't require explicit user approval (and
* perhaps in places where the user previously permitted access), the approval
* event might come immediately, but it might come seconds, minutes, or hours
* later!
*
* \param instance_id the camera device instance ID.
* \param spec the desired format for data the device will provide. Can be
@ -291,7 +330,7 @@ extern SDL_DECLSPEC SDL_CameraPosition SDLCALL SDL_GetCameraPosition(SDL_CameraI
*
* \threadsafety It is safe to call this function from any thread.
*
* \since This function is available since SDL 3.0.0.
* \since This function is available since SDL 3.2.0.
*
* \sa SDL_GetCameras
* \sa SDL_GetCameraFormat
@ -324,7 +363,7 @@ extern SDL_DECLSPEC SDL_Camera * SDLCALL SDL_OpenCamera(SDL_CameraID instance_id
*
* \threadsafety It is safe to call this function from any thread.
*
* \since This function is available since SDL 3.0.0.
* \since This function is available since SDL 3.2.0.
*
* \sa SDL_OpenCamera
* \sa SDL_CloseCamera
@ -340,7 +379,7 @@ extern SDL_DECLSPEC int SDLCALL SDL_GetCameraPermissionState(SDL_Camera *camera)
*
* \threadsafety It is safe to call this function from any thread.
*
* \since This function is available since SDL 3.0.0.
* \since This function is available since SDL 3.2.0.
*
* \sa SDL_OpenCamera
*/
@ -355,7 +394,7 @@ extern SDL_DECLSPEC SDL_CameraID SDLCALL SDL_GetCameraID(SDL_Camera *camera);
*
* \threadsafety It is safe to call this function from any thread.
*
* \since This function is available since SDL 3.0.0.
* \since This function is available since SDL 3.2.0.
*/
extern SDL_DECLSPEC SDL_PropertiesID SDLCALL SDL_GetCameraProperties(SDL_Camera *camera);
@ -366,23 +405,24 @@ extern SDL_DECLSPEC SDL_PropertiesID SDLCALL SDL_GetCameraProperties(SDL_Camera
* be converting to this format behind the scenes.
*
* If the system is waiting for the user to approve access to the camera, as
* some platforms require, this will return SDL_FALSE, but this isn't
* necessarily a fatal error; you should either wait for an
* some platforms require, this will return false, but this isn't necessarily
* a fatal error; you should either wait for an
* SDL_EVENT_CAMERA_DEVICE_APPROVED (or SDL_EVENT_CAMERA_DEVICE_DENIED) event,
* or poll SDL_IsCameraApproved() occasionally until it returns non-zero.
* or poll SDL_GetCameraPermissionState() occasionally until it returns
* non-zero.
*
* \param camera opened camera device.
* \param spec the SDL_CameraSpec to be initialized by this function.
* \returns SDL_TRUE on success or SDL_FALSE on failure; call SDL_GetError()
* for more information.
* \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.0.0.
* \since This function is available since SDL 3.2.0.
*
* \sa SDL_OpenCamera
*/
extern SDL_DECLSPEC SDL_bool SDLCALL SDL_GetCameraFormat(SDL_Camera *camera, SDL_CameraSpec *spec);
extern SDL_DECLSPEC bool SDLCALL SDL_GetCameraFormat(SDL_Camera *camera, SDL_CameraSpec *spec);
/**
* Acquire a frame.
@ -404,14 +444,14 @@ extern SDL_DECLSPEC SDL_bool SDLCALL SDL_GetCameraFormat(SDL_Camera *camera, SDL
* After use, the frame should be released with SDL_ReleaseCameraFrame(). If
* you don't do this, the system may stop providing more video!
*
* Do not call SDL_FreeSurface() on the returned surface! It must be given
* Do not call SDL_DestroySurface() on the returned surface! It must be given
* back to the camera subsystem with SDL_ReleaseCameraFrame!
*
* If the system is waiting for the user to approve access to the camera, as
* some platforms require, this will return NULL (no frames available); you
* should either wait for an SDL_EVENT_CAMERA_DEVICE_APPROVED (or
* SDL_EVENT_CAMERA_DEVICE_DENIED) event, or poll SDL_IsCameraApproved()
* occasionally until it returns non-zero.
* SDL_EVENT_CAMERA_DEVICE_DENIED) event, or poll
* SDL_GetCameraPermissionState() occasionally until it returns non-zero.
*
* \param camera opened camera device.
* \param timestampNS a pointer filled in with the frame's timestamp, or 0 on
@ -421,7 +461,7 @@ extern SDL_DECLSPEC SDL_bool SDLCALL SDL_GetCameraFormat(SDL_Camera *camera, SDL
*
* \threadsafety It is safe to call this function from any thread.
*
* \since This function is available since SDL 3.0.0.
* \since This function is available since SDL 3.2.0.
*
* \sa SDL_ReleaseCameraFrame
*/
@ -449,7 +489,7 @@ extern SDL_DECLSPEC SDL_Surface * SDLCALL SDL_AcquireCameraFrame(SDL_Camera *cam
*
* \threadsafety It is safe to call this function from any thread.
*
* \since This function is available since SDL 3.0.0.
* \since This function is available since SDL 3.2.0.
*
* \sa SDL_AcquireCameraFrame
*/
@ -464,9 +504,8 @@ extern SDL_DECLSPEC void SDLCALL SDL_ReleaseCameraFrame(SDL_Camera *camera, SDL_
* \threadsafety It is safe to call this function from any thread, but no
* thread may reference `device` once this function is called.
*
* \since This function is available since SDL 3.0.0.
* \since This function is available since SDL 3.2.0.
*
* \sa SDL_OpenCameraWithSpec
* \sa SDL_OpenCamera
*/
extern SDL_DECLSPEC void SDLCALL SDL_CloseCamera(SDL_Camera *camera);

View File

@ -1,6 +1,6 @@
/*
Simple DirectMedia Layer
Copyright (C) 1997-2024 Sam Lantinga <slouken@libsdl.org>
Copyright (C) 1997-2025 Sam Lantinga <slouken@libsdl.org>
This software is provided 'as-is', without any express or implied
warranty. In no event will the authors be held liable for any damages
@ -26,6 +26,51 @@
* from other processes and publishing information of its own.
*
* This is not just text! SDL apps can access and publish data by mimetype.
*
* ## Basic use (text)
*
* Obtaining and publishing simple text to the system clipboard is as easy as
* calling SDL_GetClipboardText() and SDL_SetClipboardText(), respectively.
* These deal with C strings in UTF-8 encoding. Data transmission and encoding
* conversion is completely managed by SDL.
*
* ## Clipboard callbacks (data other than text)
*
* Things get more complicated when the clipboard contains something other
* than text. Not only can the system clipboard contain data of any type, in
* some cases it can contain the same data in different formats! For example,
* an image painting app might let the user copy a graphic to the clipboard,
* and offers it in .BMP, .JPG, or .PNG format for other apps to consume.
*
* Obtaining clipboard data ("pasting") like this is a matter of calling
* SDL_GetClipboardData() and telling it the mimetype of the data you want.
* But how does one know if that format is available? SDL_HasClipboardData()
* can report if a specific mimetype is offered, and
* SDL_GetClipboardMimeTypes() can provide the entire list of mimetypes
* available, so the app can decide what to do with the data and what formats
* it can support.
*
* Setting the clipboard ("copying") to arbitrary data is done with
* SDL_SetClipboardData. The app does not provide the data in this call, but
* rather the mimetypes it is willing to provide and a callback function.
* During the callback, the app will generate the data. This allows massive
* data sets to be provided to the clipboard, without any data being copied
* before it is explicitly requested. More specifically, it allows an app to
* offer data in multiple formats without providing a copy of all of them
* upfront. If the app has an image that it could provide in PNG or JPG
* format, it doesn't have to encode it to either of those unless and until
* something tries to paste it.
*
* ## Primary Selection
*
* The X11 and Wayland video targets have a concept of the "primary selection"
* in addition to the usual clipboard. This is generally highlighted (but not
* explicitly copied) text from various apps. SDL offers APIs for this through
* SDL_GetPrimarySelectionText() and SDL_SetPrimarySelectionText(). SDL offers
* these APIs on platforms without this concept, too, but only so far that it
* will keep a copy of a string that the app sets for later retrieval; the
* operating system will not ever attempt to change the string externally if
* it doesn't support a primary selection.
*/
#ifndef SDL_clipboard_h_
@ -46,27 +91,31 @@ extern "C" {
* Put UTF-8 text into the clipboard.
*
* \param text the text to store in the clipboard.
* \returns SDL_TRUE on success or SDL_FALSE on failure; call SDL_GetError()
* for more information.
* \returns true on success or false on failure; call SDL_GetError() for more
* information.
*
* \since This function is available since SDL 3.0.0.
* \threadsafety This function should only be called on the main thread.
*
* \since This function is available since SDL 3.2.0.
*
* \sa SDL_GetClipboardText
* \sa SDL_HasClipboardText
*/
extern SDL_DECLSPEC SDL_bool SDLCALL SDL_SetClipboardText(const char *text);
extern SDL_DECLSPEC bool SDLCALL SDL_SetClipboardText(const char *text);
/**
* Get UTF-8 text from the clipboard.
*
* This functions returns empty string if there was not enough memory left for
* a copy of the clipboard's content.
* This functions returns an empty string if there was not enough memory left
* for a copy of the clipboard's content.
*
* \returns the clipboard text on success or an empty string on failure; call
* SDL_GetError() for more information. This should be freed with
* SDL_free() when it is no longer needed.
*
* \since This function is available since SDL 3.0.0.
* \threadsafety This function should only be called on the main thread.
*
* \since This function is available since SDL 3.2.0.
*
* \sa SDL_HasClipboardText
* \sa SDL_SetClipboardText
@ -76,40 +125,46 @@ extern SDL_DECLSPEC char * SDLCALL SDL_GetClipboardText(void);
/**
* Query whether the clipboard exists and contains a non-empty text string.
*
* \returns SDL_TRUE if the clipboard has text, or SDL_FALSE if it does not.
* \returns true if the clipboard has text, or false if it does not.
*
* \since This function is available since SDL 3.0.0.
* \threadsafety This function should only be called on the main thread.
*
* \since This function is available since SDL 3.2.0.
*
* \sa SDL_GetClipboardText
* \sa SDL_SetClipboardText
*/
extern SDL_DECLSPEC SDL_bool SDLCALL SDL_HasClipboardText(void);
extern SDL_DECLSPEC bool SDLCALL SDL_HasClipboardText(void);
/**
* Put UTF-8 text into the primary selection.
*
* \param text the text to store in the primary selection.
* \returns SDL_TRUE on success or SDL_FALSE on failure; call SDL_GetError()
* for more information.
* \returns true on success or false on failure; call SDL_GetError() for more
* information.
*
* \since This function is available since SDL 3.0.0.
* \threadsafety This function should only be called on the main thread.
*
* \since This function is available since SDL 3.2.0.
*
* \sa SDL_GetPrimarySelectionText
* \sa SDL_HasPrimarySelectionText
*/
extern SDL_DECLSPEC SDL_bool SDLCALL SDL_SetPrimarySelectionText(const char *text);
extern SDL_DECLSPEC bool SDLCALL SDL_SetPrimarySelectionText(const char *text);
/**
* Get UTF-8 text from the primary selection.
*
* This functions returns empty string if there was not enough memory left for
* a copy of the primary selection's content.
* This functions returns an empty string if there was not enough memory left
* for a copy of the primary selection's content.
*
* \returns the primary selection text on success or an empty string on
* failure; call SDL_GetError() for more information. This should be
* freed with SDL_free() when it is no longer needed.
*
* \since This function is available since SDL 3.0.0.
* \threadsafety This function should only be called on the main thread.
*
* \since This function is available since SDL 3.2.0.
*
* \sa SDL_HasPrimarySelectionText
* \sa SDL_SetPrimarySelectionText
@ -120,15 +175,16 @@ extern SDL_DECLSPEC char * SDLCALL SDL_GetPrimarySelectionText(void);
* Query whether the primary selection exists and contains a non-empty text
* string.
*
* \returns SDL_TRUE if the primary selection has text, or SDL_FALSE if it
* does not.
* \returns true if the primary selection has text, or false if it does not.
*
* \since This function is available since SDL 3.0.0.
* \threadsafety This function should only be called on the main thread.
*
* \since This function is available since SDL 3.2.0.
*
* \sa SDL_GetPrimarySelectionText
* \sa SDL_SetPrimarySelectionText
*/
extern SDL_DECLSPEC SDL_bool SDLCALL SDL_HasPrimarySelectionText(void);
extern SDL_DECLSPEC bool SDLCALL SDL_HasPrimarySelectionText(void);
/**
* Callback function that will be called when data for the specified mime-type
@ -148,7 +204,7 @@ extern SDL_DECLSPEC SDL_bool SDLCALL SDL_HasPrimarySelectionText(void);
* breakage in receiving applications. The returned data will not be
* freed so it needs to be retained and dealt with internally.
*
* \since This function is available since SDL 3.0.0.
* \since This function is available since SDL 3.2.0.
*
* \sa SDL_SetClipboardData
*/
@ -160,7 +216,7 @@ typedef const void *(SDLCALL *SDL_ClipboardDataCallback)(void *userdata, const c
*
* \param userdata a pointer to provided user data.
*
* \since This function is available since SDL 3.0.0.
* \since This function is available since SDL 3.2.0.
*
* \sa SDL_SetClipboardData
*/
@ -170,13 +226,13 @@ typedef void (SDLCALL *SDL_ClipboardCleanupCallback)(void *userdata);
* Offer clipboard data to the OS.
*
* Tell the operating system that the application is offering clipboard data
* for each of the proivded mime-types. Once another application requests the
* data the callback function will be called allowing it to generate and
* for each of the provided mime-types. Once another application requests the
* data the callback function will be called, allowing it to generate and
* respond with the data for the requested mime-type.
*
* The size of text data does not include any terminator, and the text does
* not need to be null terminated (e.g. you can directly copy a portion of a
* document)
* document).
*
* \param callback a function pointer to the function that provides the
* clipboard data.
@ -185,28 +241,32 @@ typedef void (SDLCALL *SDL_ClipboardCleanupCallback)(void *userdata);
* \param userdata an opaque pointer that will be forwarded to the callbacks.
* \param mime_types a list of mime-types that are being offered.
* \param num_mime_types the number of mime-types in the mime_types list.
* \returns SDL_TRUE on success or SDL_FALSE on failure; call SDL_GetError()
* for more information.
* \returns true on success or false on failure; call SDL_GetError() for more
* information.
*
* \since This function is available since SDL 3.0.0.
* \threadsafety This function should only be called on the main thread.
*
* \since This function is available since SDL 3.2.0.
*
* \sa SDL_ClearClipboardData
* \sa SDL_GetClipboardData
* \sa SDL_HasClipboardData
*/
extern SDL_DECLSPEC SDL_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 **mime_types, size_t num_mime_types);
/**
* Clear the clipboard data.
*
* \returns SDL_TRUE on success or SDL_FALSE on failure; call SDL_GetError()
* for more information.
* \returns true on success or false on failure; call SDL_GetError() for more
* information.
*
* \since This function is available since SDL 3.0.0.
* \threadsafety This function should only be called on the main thread.
*
* \since This function is available since SDL 3.2.0.
*
* \sa SDL_SetClipboardData
*/
extern SDL_DECLSPEC SDL_bool SDLCALL SDL_ClearClipboardData(void);
extern SDL_DECLSPEC bool SDLCALL SDL_ClearClipboardData(void);
/**
* Get the data from clipboard for a given mime type.
@ -220,7 +280,9 @@ extern SDL_DECLSPEC SDL_bool SDLCALL SDL_ClearClipboardData(void);
* for more information. This should be freed with SDL_free() when it
* is no longer needed.
*
* \since This function is available since SDL 3.0.0.
* \threadsafety This function should only be called on the main thread.
*
* \since This function is available since SDL 3.2.0.
*
* \sa SDL_HasClipboardData
* \sa SDL_SetClipboardData
@ -231,15 +293,34 @@ extern SDL_DECLSPEC void * SDLCALL SDL_GetClipboardData(const char *mime_type, s
* Query whether there is data in the clipboard for the provided mime type.
*
* \param mime_type the mime type to check for data for.
* \returns SDL_TRUE if there exists data in clipboard for the provided mime
* type, SDL_FALSE if it does not.
* \returns true if there exists data in clipboard for the provided mime type,
* false if it does not.
*
* \since This function is available since SDL 3.0.0.
* \threadsafety This function should only be called on the main thread.
*
* \since This function is available since SDL 3.2.0.
*
* \sa SDL_SetClipboardData
* \sa SDL_GetClipboardData
*/
extern SDL_DECLSPEC SDL_bool SDLCALL SDL_HasClipboardData(const char *mime_type);
extern SDL_DECLSPEC bool SDLCALL SDL_HasClipboardData(const char *mime_type);
/**
* Retrieve the list of mime types available in the clipboard.
*
* \param num_mime_types a pointer filled with the number of mime types, may
* be NULL.
* \returns a null terminated array of strings with mime types, or NULL on
* failure; call SDL_GetError() for more information. This should be
* freed with SDL_free() when it is no longer needed.
*
* \threadsafety This function should only be called on the main thread.
*
* \since This function is available since SDL 3.2.0.
*
* \sa SDL_SetClipboardData
*/
extern SDL_DECLSPEC char ** SDLCALL SDL_GetClipboardMimeTypes(size_t *num_mime_types);
/* Ends C function definitions when using C++ */
#ifdef __cplusplus

View File

@ -1,6 +1,6 @@
/*
Simple DirectMedia Layer
Copyright (C) 1997-2024 Sam Lantinga <slouken@libsdl.org>
Copyright (C) 1997-2025 Sam Lantinga <slouken@libsdl.org>
This software is provided 'as-is', without any express or implied
warranty. In no event will the authors be held liable for any damages
@ -21,7 +21,10 @@
/*
* This file reverses the effects of SDL_begin_code.h and should be included
* after you finish any function and structure declarations in your headers
* after you finish any function and structure declarations in your headers.
*
* SDL's headers use this; applications generally should not include this
* header directly.
*/
#ifndef SDL_begin_code_h

View File

@ -1,6 +1,6 @@
/*
Simple DirectMedia Layer
Copyright (C) 1997-2024 Sam Lantinga <slouken@libsdl.org>
Copyright (C) 1997-2025 Sam Lantinga <slouken@libsdl.org>
This software is provided 'as-is', without any express or implied
warranty. In no event will the authors be held liable for any damages

View File

@ -1,6 +1,6 @@
/*
Simple DirectMedia Layer
Copyright (C) 1997-2024 Sam Lantinga <slouken@libsdl.org>
Copyright (C) 1997-2025 Sam Lantinga <slouken@libsdl.org>
This software is provided 'as-is', without any express or implied
warranty. In no event will the authors be held liable for any damages
@ -29,6 +29,12 @@
* These functions are largely concerned with reporting if the system has
* access to various SIMD instruction sets, but also has other important info
* to share, such as system RAM size and number of logical CPU cores.
*
* CPU instruction set checks, like SDL_HasSSE() and SDL_HasNEON(), are
* available on all platforms, even if they don't make sense (an ARM processor
* will never have SSE and an x86 processor will never have NEON, for example,
* but these functions still exist and will simply return false in these
* cases).
*/
#ifndef SDL_cpuinfo_h_
@ -49,20 +55,22 @@ extern "C" {
* processors have a 128 byte cache line. We use the larger value to be
* generally safe.
*
* \since This macro is available since SDL 3.0.0.
* \since This macro is available since SDL 3.2.0.
*/
#define SDL_CACHELINE_SIZE 128
/**
* Get the number of CPU cores available.
* Get the number of logical CPU cores available.
*
* \returns the total number of logical CPU cores. On CPUs that include
* technologies such as hyperthreading, the number of logical cores
* may be more than the number of physical cores.
*
* \since This function is available since SDL 3.0.0.
* \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_GetCPUCount(void);
extern SDL_DECLSPEC int SDLCALL SDL_GetNumLogicalCPUCores(void);
/**
* Determine the L1 cache line size of the CPU.
@ -72,7 +80,9 @@ extern SDL_DECLSPEC int SDLCALL SDL_GetCPUCount(void);
*
* \returns the L1 cache line size of the CPU, in bytes.
*
* \since This function is available since SDL 3.0.0.
* \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_GetCPUCacheLineSize(void);
@ -82,144 +92,164 @@ extern SDL_DECLSPEC int SDLCALL SDL_GetCPUCacheLineSize(void);
* This always returns false on CPUs that aren't using PowerPC instruction
* sets.
*
* \returns SDL_TRUE if the CPU has AltiVec features or SDL_FALSE if not.
* \returns true if the CPU has AltiVec features or false if not.
*
* \since This function is available since SDL 3.0.0.
* \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_bool SDLCALL SDL_HasAltiVec(void);
extern SDL_DECLSPEC bool SDLCALL SDL_HasAltiVec(void);
/**
* Determine whether the CPU has MMX features.
*
* This always returns false on CPUs that aren't using Intel instruction sets.
*
* \returns SDL_TRUE if the CPU has MMX features or SDL_FALSE if not.
* \returns true if the CPU has MMX features or false if not.
*
* \since This function is available since SDL 3.0.0.
* \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_bool SDLCALL SDL_HasMMX(void);
extern SDL_DECLSPEC bool SDLCALL SDL_HasMMX(void);
/**
* Determine whether the CPU has SSE features.
*
* This always returns false on CPUs that aren't using Intel instruction sets.
*
* \returns SDL_TRUE if the CPU has SSE features or SDL_FALSE if not.
* \returns true if the CPU has SSE features or false if not.
*
* \since This function is available since SDL 3.0.0.
* \threadsafety It is safe to call this function from any thread.
*
* \since This function is available since SDL 3.2.0.
*
* \sa SDL_HasSSE2
* \sa SDL_HasSSE3
* \sa SDL_HasSSE41
* \sa SDL_HasSSE42
*/
extern SDL_DECLSPEC SDL_bool SDLCALL SDL_HasSSE(void);
extern SDL_DECLSPEC bool SDLCALL SDL_HasSSE(void);
/**
* Determine whether the CPU has SSE2 features.
*
* This always returns false on CPUs that aren't using Intel instruction sets.
*
* \returns SDL_TRUE if the CPU has SSE2 features or SDL_FALSE if not.
* \returns true if the CPU has SSE2 features or false if not.
*
* \since This function is available since SDL 3.0.0.
* \threadsafety It is safe to call this function from any thread.
*
* \since This function is available since SDL 3.2.0.
*
* \sa SDL_HasSSE
* \sa SDL_HasSSE3
* \sa SDL_HasSSE41
* \sa SDL_HasSSE42
*/
extern SDL_DECLSPEC SDL_bool SDLCALL SDL_HasSSE2(void);
extern SDL_DECLSPEC bool SDLCALL SDL_HasSSE2(void);
/**
* Determine whether the CPU has SSE3 features.
*
* This always returns false on CPUs that aren't using Intel instruction sets.
*
* \returns SDL_TRUE if the CPU has SSE3 features or SDL_FALSE if not.
* \returns true if the CPU has SSE3 features or false if not.
*
* \since This function is available since SDL 3.0.0.
* \threadsafety It is safe to call this function from any thread.
*
* \since This function is available since SDL 3.2.0.
*
* \sa SDL_HasSSE
* \sa SDL_HasSSE2
* \sa SDL_HasSSE41
* \sa SDL_HasSSE42
*/
extern SDL_DECLSPEC SDL_bool SDLCALL SDL_HasSSE3(void);
extern SDL_DECLSPEC bool SDLCALL SDL_HasSSE3(void);
/**
* Determine whether the CPU has SSE4.1 features.
*
* This always returns false on CPUs that aren't using Intel instruction sets.
*
* \returns SDL_TRUE if the CPU has SSE4.1 features or SDL_FALSE if not.
* \returns true if the CPU has SSE4.1 features or false if not.
*
* \since This function is available since SDL 3.0.0.
* \threadsafety It is safe to call this function from any thread.
*
* \since This function is available since SDL 3.2.0.
*
* \sa SDL_HasSSE
* \sa SDL_HasSSE2
* \sa SDL_HasSSE3
* \sa SDL_HasSSE42
*/
extern SDL_DECLSPEC SDL_bool SDLCALL SDL_HasSSE41(void);
extern SDL_DECLSPEC bool SDLCALL SDL_HasSSE41(void);
/**
* Determine whether the CPU has SSE4.2 features.
*
* This always returns false on CPUs that aren't using Intel instruction sets.
*
* \returns SDL_TRUE if the CPU has SSE4.2 features or SDL_FALSE if not.
* \returns true if the CPU has SSE4.2 features or false if not.
*
* \since This function is available since SDL 3.0.0.
* \threadsafety It is safe to call this function from any thread.
*
* \since This function is available since SDL 3.2.0.
*
* \sa SDL_HasSSE
* \sa SDL_HasSSE2
* \sa SDL_HasSSE3
* \sa SDL_HasSSE41
*/
extern SDL_DECLSPEC SDL_bool SDLCALL SDL_HasSSE42(void);
extern SDL_DECLSPEC bool SDLCALL SDL_HasSSE42(void);
/**
* Determine whether the CPU has AVX features.
*
* This always returns false on CPUs that aren't using Intel instruction sets.
*
* \returns SDL_TRUE if the CPU has AVX features or SDL_FALSE if not.
* \returns true if the CPU has AVX features or false if not.
*
* \since This function is available since SDL 3.0.0.
* \threadsafety It is safe to call this function from any thread.
*
* \since This function is available since SDL 3.2.0.
*
* \sa SDL_HasAVX2
* \sa SDL_HasAVX512F
*/
extern SDL_DECLSPEC SDL_bool SDLCALL SDL_HasAVX(void);
extern SDL_DECLSPEC bool SDLCALL SDL_HasAVX(void);
/**
* Determine whether the CPU has AVX2 features.
*
* This always returns false on CPUs that aren't using Intel instruction sets.
*
* \returns SDL_TRUE if the CPU has AVX2 features or SDL_FALSE if not.
* \returns true if the CPU has AVX2 features or false if not.
*
* \since This function is available since SDL 3.0.0.
* \threadsafety It is safe to call this function from any thread.
*
* \since This function is available since SDL 3.2.0.
*
* \sa SDL_HasAVX
* \sa SDL_HasAVX512F
*/
extern SDL_DECLSPEC SDL_bool SDLCALL SDL_HasAVX2(void);
extern SDL_DECLSPEC bool SDLCALL SDL_HasAVX2(void);
/**
* Determine whether the CPU has AVX-512F (foundation) features.
*
* This always returns false on CPUs that aren't using Intel instruction sets.
*
* \returns SDL_TRUE if the CPU has AVX-512F features or SDL_FALSE if not.
* \returns true if the CPU has AVX-512F features or false if not.
*
* \since This function is available since SDL 3.0.0.
* \threadsafety It is safe to call this function from any thread.
*
* \since This function is available since SDL 3.2.0.
*
* \sa SDL_HasAVX
* \sa SDL_HasAVX2
*/
extern SDL_DECLSPEC SDL_bool SDLCALL SDL_HasAVX512F(void);
extern SDL_DECLSPEC bool SDLCALL SDL_HasAVX512F(void);
/**
* Determine whether the CPU has ARM SIMD (ARMv6) features.
@ -228,24 +258,28 @@ extern SDL_DECLSPEC SDL_bool SDLCALL SDL_HasAVX512F(void);
*
* This always returns false on CPUs that aren't using ARM instruction sets.
*
* \returns SDL_TRUE if the CPU has ARM SIMD features or SDL_FALSE if not.
* \returns true if the CPU has ARM SIMD features or false if not.
*
* \since This function is available since SDL 3.0.0.
* \threadsafety It is safe to call this function from any thread.
*
* \since This function is available since SDL 3.2.0.
*
* \sa SDL_HasNEON
*/
extern SDL_DECLSPEC SDL_bool SDLCALL SDL_HasARMSIMD(void);
extern SDL_DECLSPEC bool SDLCALL SDL_HasARMSIMD(void);
/**
* Determine whether the CPU has NEON (ARM SIMD) features.
*
* This always returns false on CPUs that aren't using ARM instruction sets.
*
* \returns SDL_TRUE if the CPU has ARM NEON features or SDL_FALSE if not.
* \returns true if the CPU has ARM NEON features or false if not.
*
* \since This function is available since SDL 3.0.0.
* \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_bool SDLCALL SDL_HasNEON(void);
extern SDL_DECLSPEC bool SDLCALL SDL_HasNEON(void);
/**
* Determine whether the CPU has LSX (LOONGARCH SIMD) features.
@ -253,12 +287,13 @@ extern SDL_DECLSPEC SDL_bool SDLCALL SDL_HasNEON(void);
* This always returns false on CPUs that aren't using LOONGARCH instruction
* sets.
*
* \returns SDL_TRUE if the CPU has LOONGARCH LSX features or SDL_FALSE if
* not.
* \returns true if the CPU has LOONGARCH LSX features or false if not.
*
* \since This function is available since SDL 3.0.0.
* \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_bool SDLCALL SDL_HasLSX(void);
extern SDL_DECLSPEC bool SDLCALL SDL_HasLSX(void);
/**
* Determine whether the CPU has LASX (LOONGARCH SIMD) features.
@ -266,19 +301,22 @@ extern SDL_DECLSPEC SDL_bool SDLCALL SDL_HasLSX(void);
* This always returns false on CPUs that aren't using LOONGARCH instruction
* sets.
*
* \returns SDL_TRUE if the CPU has LOONGARCH LASX features or SDL_FALSE if
* not.
* \returns true if the CPU has LOONGARCH LASX features or false if not.
*
* \since This function is available since SDL 3.0.0.
* \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_bool SDLCALL SDL_HasLASX(void);
extern SDL_DECLSPEC bool SDLCALL SDL_HasLASX(void);
/**
* Get the amount of RAM configured in the system.
*
* \returns the amount of RAM configured in the system in MiB.
*
* \since This function is available since SDL 3.0.0.
* \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_GetSystemRAM(void);
@ -297,7 +335,9 @@ extern SDL_DECLSPEC int SDLCALL SDL_GetSystemRAM(void);
* \returns the alignment in bytes needed for available, known SIMD
* instructions.
*
* \since This function is available since SDL 3.0.0.
* \threadsafety It is safe to call this function from any thread.
*
* \since This function is available since SDL 3.2.0.
*
* \sa SDL_aligned_alloc
* \sa SDL_aligned_free

View File

@ -1,6 +1,6 @@
/*
Simple DirectMedia Layer
Copyright (C) 1997-2024 Sam Lantinga <slouken@libsdl.org>
Copyright (C) 1997-2025 Sam Lantinga <slouken@libsdl.org>
This software is provided 'as-is', without any express or implied
warranty. In no event will the authors be held liable for any damages
@ -23,12 +23,23 @@
* # CategoryDialog
*
* File dialog support.
*
* SDL offers file dialogs, to let users select files with native GUI
* interfaces. There are "open" dialogs, "save" dialogs, and folder selection
* dialogs. The app can control some details, such as filtering to specific
* files, or whether multiple files can be selected by the user.
*
* Note that launching a file dialog is a non-blocking operation; control
* returns to the app immediately, and a callback is called later (possibly in
* another thread) when the user makes a choice.
*/
#ifndef SDL_dialog_h_
#define SDL_dialog_h_
#include <SDL3/SDL_stdinc.h>
#include <SDL3/SDL_error.h>
#include <SDL3/SDL_properties.h>
#include <SDL3/SDL_video.h>
#include <SDL3/SDL_begin_code.h>
@ -48,12 +59,13 @@ extern "C" {
* hyphens, underscores and periods. Alternatively, the whole string can be a
* single asterisk ("*"), which serves as an "All files" filter.
*
* \since This struct is available since SDL 3.0.0.
* \since This struct is available since SDL 3.2.0.
*
* \sa SDL_DialogFileCallback
* \sa SDL_ShowOpenFileDialog
* \sa SDL_ShowSaveFileDialog
* \sa SDL_ShowOpenFolderDialog
* \sa SDL_ShowFileDialogWithProperties
*/
typedef struct SDL_DialogFileFilter
{
@ -75,31 +87,34 @@ typedef struct SDL_DialogFileFilter
* is a null-terminated list of pointers to C strings, each containing a
* path.
*
* The filelist argument does not need to be freed; it will automatically be
* freed when the callback returns.
* The filelist argument should not be freed; it will automatically be freed
* when the callback returns.
*
* The filter argument is the index of the filter that was selected, or -1 if
* no filter was selected or if the platform or method doesn't support
* fetching the selected filter.
*
* In Android, the `filelist` are `content://` URIs. They should be opened
* using SDL_IOFromFile() with appropriate modes. This applies both to open
* and save file dialog.
*
* \param userdata an app-provided pointer, for the callback's use.
* \param filelist the file(s) chosen by the user.
* \param filter index of the selected filter.
*
* \since This datatype is available since SDL 3.0.0.
* \since This datatype is available since SDL 3.2.0.
*
* \sa SDL_DialogFileFilter
* \sa SDL_ShowOpenFileDialog
* \sa SDL_ShowSaveFileDialog
* \sa SDL_ShowOpenFolderDialog
* \sa SDL_ShowFileDialogWithProperties
*/
typedef void (SDLCALL *SDL_DialogFileCallback)(void *userdata, const char * const *filelist, int filter);
/**
* Displays a dialog that lets the user select a file on their filesystem.
*
* This function should only be invoked from the main thread.
*
* This is an asynchronous function; it will return immediately, and the
* result will be passed to the callback.
*
@ -117,47 +132,41 @@ typedef void (SDLCALL *SDL_DialogFileCallback)(void *userdata, const char * cons
* requires an event-handling loop. Apps that do not use SDL to handle events
* should add a call to SDL_PumpEvents in their main loop.
*
* \param callback an SDL_DialogFileCallback to be invoked when the user
* selects a file and accepts, or cancels the dialog, or an
* error occurs. The first argument is a null-terminated list
* of C strings, representing the paths chosen by the user.
* The list will be empty if the user canceled the dialog, and
* it will be NULL if an error occurred. If an error occurred,
* it can be fetched with SDL_GetError(). The second argument
* is the userdata pointer passed to the function. The third
* argument is the index of the filter selected by the user,
* or one past the index of the last filter (therefore the
* index of the terminating NULL filter) if no filter was
* chosen, or -1 if the platform does not support detecting
* the selected filter.
* \param callback a function pointer to be invoked when the user selects a
* file and accepts, or cancels the dialog, or an error
* occurs.
* \param userdata an optional pointer to pass extra data to the callback when
* it will be invoked.
* \param window the window that the dialog should be modal for. May be NULL.
* \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 SDL_DialogFileFilter's. May be NULL. Not all
* platforms support this option, and platforms that do support
* it may allow the user to ignore the filters.
* \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 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.
* \param default_location the default folder or file to start the dialog at,
* may be NULL. Not all platforms support this option.
* \param allow_many if non-zero, the user will be allowed to select multiple
* entries. Not all platforms support this option.
*
* \since This function is available since SDL 3.0.0.
* \threadsafety This function should be called only from the main thread. The
* callback may be invoked from the same thread or from a
* different one, depending on the OS's constraints.
*
* \since This function is available since SDL 3.2.0.
*
* \sa SDL_DialogFileCallback
* \sa SDL_DialogFileFilter
* \sa SDL_ShowSaveFileDialog
* \sa SDL_ShowOpenFolderDialog
* \sa SDL_ShowFileDialogWithProperties
*/
extern SDL_DECLSPEC void SDLCALL SDL_ShowOpenFileDialog(SDL_DialogFileCallback callback, void *userdata, SDL_Window *window, const SDL_DialogFileFilter *filters, int nfilters, const char *default_location, SDL_bool allow_many);
extern SDL_DECLSPEC void SDLCALL SDL_ShowOpenFileDialog(SDL_DialogFileCallback callback, void *userdata, SDL_Window *window, const SDL_DialogFileFilter *filters, int nfilters, const char *default_location, bool allow_many);
/**
* Displays a dialog that lets the user choose a new or existing file on their
* filesystem.
*
* This function should only be invoked from the main thread.
*
* This is an asynchronous function; it will return immediately, and the
* result will be passed to the callback.
*
@ -174,44 +183,38 @@ extern SDL_DECLSPEC void SDLCALL SDL_ShowOpenFileDialog(SDL_DialogFileCallback c
* requires an event-handling loop. Apps that do not use SDL to handle events
* should add a call to SDL_PumpEvents in their main loop.
*
* \param callback an SDL_DialogFileCallback to be invoked when the user
* selects a file and accepts, or cancels the dialog, or an
* error occurs. The first argument is a null-terminated list
* of C strings, representing the paths chosen by the user.
* The list will be empty if the user canceled the dialog, and
* it will be NULL if an error occurred. If an error occurred,
* it can be fetched with SDL_GetError(). The second argument
* is the userdata pointer passed to the function. The third
* argument is the index of the filter selected by the user,
* or one past the index of the last filter (therefore the
* index of the terminating NULL filter) if no filter was
* chosen, or -1 if the platform does not support detecting
* the selected filter.
* \param callback a function pointer to be invoked when the user selects a
* file and accepts, or cancels the dialog, or an error
* occurs.
* \param userdata an optional pointer to pass extra data to the callback when
* it will be invoked.
* \param window the window that the dialog should be modal for. May be NULL.
* \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 SDL_DialogFileFilter's. May be NULL. Not all
* platforms support this option, and platforms that do support
* it may allow the user to ignore the filters.
* \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 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.
* \param default_location the default folder or file to start the dialog at,
* may be NULL. Not all platforms support this option.
*
* \since This function is available since SDL 3.0.0.
* \threadsafety This function should be called only from the main thread. The
* callback may be invoked from the same thread or from a
* different one, depending on the OS's constraints.
*
* \since This function is available since SDL 3.2.0.
*
* \sa SDL_DialogFileCallback
* \sa SDL_DialogFileFilter
* \sa SDL_ShowOpenFileDialog
* \sa SDL_ShowOpenFolderDialog
* \sa SDL_ShowFileDialogWithProperties
*/
extern SDL_DECLSPEC void SDLCALL SDL_ShowSaveFileDialog(SDL_DialogFileCallback callback, void *userdata, SDL_Window *window, const SDL_DialogFileFilter *filters, int nfilters, const char *default_location);
/**
* Displays a dialog that lets the user select a folder on their filesystem.
*
* This function should only be invoked from the main thread.
*
* This is an asynchronous function; it will return immediately, and the
* result will be passed to the callback.
*
@ -229,31 +232,105 @@ extern SDL_DECLSPEC void SDLCALL SDL_ShowSaveFileDialog(SDL_DialogFileCallback c
* requires an event-handling loop. Apps that do not use SDL to handle events
* should add a call to SDL_PumpEvents in their main loop.
*
* \param callback an SDL_DialogFileCallback to be invoked when the user
* selects a file and accepts, or cancels the dialog, or an
* error occurs. The first argument is a null-terminated list
* of C strings, representing the paths chosen by the user.
* The list will be empty if the user canceled the dialog, and
* it will be NULL if an error occurred. If an error occurred,
* it can be fetched with SDL_GetError(). The second argument
* is the userdata pointer passed to the function. The third
* argument is always -1 for SDL_ShowOpenFolderDialog.
* \param callback a function pointer to be invoked when the user selects a
* file and accepts, or cancels the dialog, or an error
* occurs.
* \param userdata an optional pointer to pass extra data to the callback when
* it will be invoked.
* \param window the window that the dialog should be modal for. May be NULL.
* \param window the window that the dialog should be modal for, may be NULL.
* Not all platforms support this option.
* \param default_location the default folder or file to start the dialog at.
* May be NULL. Not all platforms support this option.
* \param default_location the default folder or file to start the dialog at,
* may be NULL. Not all platforms support this option.
* \param allow_many if non-zero, the user will be allowed to select multiple
* entries. Not all platforms support this option.
*
* \since This function is available since SDL 3.0.0.
* \threadsafety This function should be called only from the main thread. The
* callback may be invoked from the same thread or from a
* different one, depending on the OS's constraints.
*
* \since This function is available since SDL 3.2.0.
*
* \sa SDL_DialogFileCallback
* \sa SDL_ShowOpenFileDialog
* \sa SDL_ShowSaveFileDialog
* \sa SDL_ShowFileDialogWithProperties
*/
extern SDL_DECLSPEC void SDLCALL SDL_ShowOpenFolderDialog(SDL_DialogFileCallback callback, void *userdata, SDL_Window *window, const char *default_location, SDL_bool allow_many);
extern SDL_DECLSPEC void SDLCALL SDL_ShowOpenFolderDialog(SDL_DialogFileCallback callback, void *userdata, SDL_Window *window, const char *default_location, bool allow_many);
/**
* Various types of file dialogs.
*
* This is used by SDL_ShowFileDialogWithProperties() to decide what kind of
* dialog to present to the user.
*
* \since This enum is available since SDL 3.2.0.
*
* \sa SDL_ShowFileDialogWithProperties
*/
typedef enum SDL_FileDialogType
{
SDL_FILEDIALOG_OPENFILE,
SDL_FILEDIALOG_SAVEFILE,
SDL_FILEDIALOG_OPENFOLDER
} SDL_FileDialogType;
/**
* Create and launch a file dialog with the specified properties.
*
* These are the supported properties:
*
* - `SDL_PROP_FILE_DIALOG_FILTERS_POINTER`: a pointer to a list of
* SDL_DialogFileFilter structs, which will be used as filters for
* file-based selections. Ignored if the dialog is an "Open Folder" dialog.
* If non-NULL, the array of filters must remain valid at least until the
* callback is invoked.
* - `SDL_PROP_FILE_DIALOG_NFILTERS_NUMBER`: the number of filters in the
* array of filters, if it exists.
* - `SDL_PROP_FILE_DIALOG_WINDOW_POINTER`: the window that the dialog should
* be modal for.
* - `SDL_PROP_FILE_DIALOG_LOCATION_STRING`: the default folder or file to
* start the dialog at.
* - `SDL_PROP_FILE_DIALOG_MANY_BOOLEAN`: true to allow the user to select
* more than one entry.
* - `SDL_PROP_FILE_DIALOG_TITLE_STRING`: the title for the dialog.
* - `SDL_PROP_FILE_DIALOG_ACCEPT_STRING`: the label that the accept button
* should have.
* - `SDL_PROP_FILE_DIALOG_CANCEL_STRING`: the label that the cancel button
* should have.
*
* Note that each platform may or may not support any of the properties.
*
* \param type the type of file dialog.
* \param callback a function pointer to be invoked when the user selects a
* file and accepts, or cancels the dialog, or an error
* occurs.
* \param userdata an optional pointer to pass extra data to the callback when
* it will be invoked.
* \param props the properties to use.
*
* \threadsafety This function should be called only from the main thread. The
* callback may be invoked from the same thread or from a
* different one, depending on the OS's constraints.
*
* \since This function is available since SDL 3.2.0.
*
* \sa SDL_FileDialogType
* \sa SDL_DialogFileCallback
* \sa SDL_DialogFileFilter
* \sa SDL_ShowOpenFileDialog
* \sa SDL_ShowSaveFileDialog
* \sa SDL_ShowOpenFolderDialog
*/
extern SDL_DECLSPEC void SDLCALL SDL_ShowFileDialogWithProperties(SDL_FileDialogType type, SDL_DialogFileCallback callback, void *userdata, SDL_PropertiesID props);
#define SDL_PROP_FILE_DIALOG_FILTERS_POINTER "SDL.filedialog.filters"
#define SDL_PROP_FILE_DIALOG_NFILTERS_NUMBER "SDL.filedialog.nfilters"
#define SDL_PROP_FILE_DIALOG_WINDOW_POINTER "SDL.filedialog.window"
#define SDL_PROP_FILE_DIALOG_LOCATION_STRING "SDL.filedialog.location"
#define SDL_PROP_FILE_DIALOG_MANY_BOOLEAN "SDL.filedialog.many"
#define SDL_PROP_FILE_DIALOG_TITLE_STRING "SDL.filedialog.title"
#define SDL_PROP_FILE_DIALOG_ACCEPT_STRING "SDL.filedialog.accept"
#define SDL_PROP_FILE_DIALOG_CANCEL_STRING "SDL.filedialog.cancel"
/* Ends C function definitions when using C++ */
#ifdef __cplusplus
@ -261,4 +338,4 @@ extern SDL_DECLSPEC void SDLCALL SDL_ShowOpenFolderDialog(SDL_DialogFileCallback
#endif
#include <SDL3/SDL_close_code.h>
#endif /* SDL_joystick_h_ */
#endif /* SDL_dialog_h_ */

View File

@ -1,6 +1,6 @@
/*
Simple DirectMedia Layer
Copyright (C) 1997-2024 Sam Lantinga <slouken@libsdl.org>
Copyright (C) 1997-2025 Sam Lantinga <slouken@libsdl.org>
This software is provided 'as-is', without any express or implied
warranty. In no event will the authors be held liable for any damages

View File

@ -1,6 +1,6 @@
/*
Simple DirectMedia Layer
Copyright (C) 1997-2024 Sam Lantinga <slouken@libsdl.org>
Copyright (C) 1997-2025 Sam Lantinga <slouken@libsdl.org>
This software is provided 'as-is', without any express or implied
warranty. In no event will the authors be held liable for any damages
@ -22,7 +22,20 @@
/**
* # CategoryEndian
*
* Functions for reading and writing endian-specific values.
* Functions converting endian-specific values to different byte orders.
*
* These functions either unconditionally swap byte order (SDL_Swap16,
* SDL_Swap32, SDL_Swap64, SDL_SwapFloat), or they swap to/from the system's
* native byte order (SDL_Swap16LE, SDL_Swap16BE, SDL_Swap32LE, SDL_Swap32BE,
* SDL_Swap32LE, SDL_Swap32BE, SDL_SwapFloatLE, SDL_SwapFloatBE). In the
* latter case, the functionality is provided by macros that become no-ops if
* a swap isn't necessary: on an x86 (littleendian) processor, SDL_Swap32LE
* does nothing, but SDL_Swap32BE reverses the bytes of the data. On a PowerPC
* processor (bigendian), the macros behavior is reversed.
*
* The swap routines are inline functions, and attempt to use compiler
* intrinsics, inline assembly, and other magic to make byteswapping
* efficient.
*/
#ifndef SDL_endian_h_
@ -51,12 +64,71 @@ _m_prefetch(void *__P)
* \name The two types of endianness
*/
/* @{ */
/**
* A value to represent littleendian byteorder.
*
* This is used with the preprocessor macro SDL_BYTEORDER, to determine a
* platform's byte ordering:
*
* ```c
* #if SDL_BYTEORDER == SDL_LIL_ENDIAN
* SDL_Log("This system is littleendian.");
* #endif
* ```
*
* \since This macro is available since SDL 3.2.0.
*
* \sa SDL_BYTEORDER
* \sa SDL_BIG_ENDIAN
*/
#define SDL_LIL_ENDIAN 1234
/**
* A value to represent bigendian byteorder.
*
* This is used with the preprocessor macro SDL_BYTEORDER, to determine a
* platform's byte ordering:
*
* ```c
* #if SDL_BYTEORDER == SDL_BIG_ENDIAN
* SDL_Log("This system is bigendian.");
* #endif
* ```
*
* \since This macro is available since SDL 3.2.0.
*
* \sa SDL_BYTEORDER
* \sa SDL_LIL_ENDIAN
*/
#define SDL_BIG_ENDIAN 4321
/* @} */
#ifndef SDL_BYTEORDER
#ifdef SDL_PLATFORM_LINUX
#ifdef SDL_WIKI_DOCUMENTATION_SECTION
/**
* A macro that reports the target system's byte order.
*
* This is set to either SDL_LIL_ENDIAN or SDL_BIG_ENDIAN (and maybe other
* values in the future, if something else becomes popular). This can be
* tested with the preprocessor, so decisions can be made at compile time.
*
* ```c
* #if SDL_BYTEORDER == SDL_BIG_ENDIAN
* SDL_Log("This system is bigendian.");
* #endif
* ```
*
* \since This macro is available since SDL 3.2.0.
*
* \sa SDL_LIL_ENDIAN
* \sa SDL_BIG_ENDIAN
*/
#define SDL_BYTEORDER SDL_LIL_ENDIAN___or_maybe___SDL_BIG_ENDIAN
#elif defined(SDL_PLATFORM_LINUX)
#include <endian.h>
#define SDL_BYTEORDER __BYTE_ORDER
#elif defined(SDL_PLATFORM_SOLARIS)
@ -97,8 +169,29 @@ _m_prefetch(void *__P)
#endif /* !SDL_BYTEORDER */
#ifndef SDL_FLOATWORDORDER
#ifdef SDL_WIKI_DOCUMENTATION_SECTION
/**
* A macro that reports the target system's floating point word order.
*
* This is set to either SDL_LIL_ENDIAN or SDL_BIG_ENDIAN (and maybe other
* values in the future, if something else becomes popular). This can be
* tested with the preprocessor, so decisions can be made at compile time.
*
* ```c
* #if SDL_FLOATWORDORDER == SDL_BIG_ENDIAN
* SDL_Log("This system's floats are bigendian.");
* #endif
* ```
*
* \since This macro is available since SDL 3.2.0.
*
* \sa SDL_LIL_ENDIAN
* \sa SDL_BIG_ENDIAN
*/
#define SDL_FLOATWORDORDER SDL_LIL_ENDIAN___or_maybe___SDL_BIG_ENDIAN
/* predefs from newer gcc versions: */
#if defined(__ORDER_LITTLE_ENDIAN__) && defined(__ORDER_BIG_ENDIAN__) && defined(__FLOAT_WORD_ORDER__)
#elif defined(__ORDER_LITTLE_ENDIAN__) && defined(__ORDER_BIG_ENDIAN__) && defined(__FLOAT_WORD_ORDER__)
#if (__FLOAT_WORD_ORDER__ == __ORDER_LITTLE_ENDIAN__)
#define SDL_FLOATWORDORDER SDL_LIL_ENDIAN
#elif (__FLOAT_WORD_ORDER__ == __ORDER_BIG_ENDIAN__)
@ -125,10 +218,6 @@ _m_prefetch(void *__P)
extern "C" {
#endif
/**
* \file SDL_endian.h
*/
/* various modern compilers may have builtin swap */
#if defined(__GNUC__) || defined(__clang__)
# define HAS_BUILTIN_BSWAP16 (SDL_HAS_BUILTIN(__builtin_bswap16)) || \
@ -148,6 +237,7 @@ extern "C" {
#endif
/* Byte swap 16-bit integer. */
#ifndef SDL_WIKI_DOCUMENTATION_SECTION
#if HAS_BUILTIN_BSWAP16
#define SDL_Swap16(x) __builtin_bswap16(x)
#elif (defined(_MSC_VER) && (_MSC_VER >= 1400)) && !defined(__ICL)
@ -191,8 +281,10 @@ SDL_FORCE_INLINE Uint16 SDL_Swap16(Uint16 x)
return SDL_static_cast(Uint16, ((x << 8) | (x >> 8)));
}
#endif
#endif
/* Byte swap 32-bit integer. */
#ifndef SDL_WIKI_DOCUMENTATION_SECTION
#if HAS_BUILTIN_BSWAP32
#define SDL_Swap32(x) __builtin_bswap32(x)
#elif (defined(_MSC_VER) && (_MSC_VER >= 1400)) && !defined(__ICL)
@ -239,8 +331,10 @@ SDL_FORCE_INLINE Uint32 SDL_Swap32(Uint32 x)
((x >> 8) & 0x0000FF00) | (x >> 24)));
}
#endif
#endif
/* Byte swap 64-bit integer. */
#ifndef SDL_WIKI_DOCUMENTATION_SECTION
#if HAS_BUILTIN_BSWAP64
#define SDL_Swap64(x) __builtin_bswap64(x)
#elif (defined(_MSC_VER) && (_MSC_VER >= 1400)) && !defined(__ICL)
@ -290,7 +384,7 @@ SDL_FORCE_INLINE Uint64 SDL_Swap64(Uint64 x)
return (x);
}
#endif
#endif
/**
* Byte-swap a floating point number.
@ -309,7 +403,7 @@ SDL_FORCE_INLINE Uint64 SDL_Swap64(Uint64 x)
*
* \threadsafety It is safe to call this function from any thread.
*
* \since This function is available since SDL 3.0.0.
* \since This function is available since SDL 3.2.0.
*/
SDL_FORCE_INLINE float SDL_SwapFloat(float x)
{
@ -348,7 +442,7 @@ SDL_FORCE_INLINE float SDL_SwapFloat(float x)
*
* \threadsafety It is safe to call this function from any thread.
*
* \since This function is available since SDL 3.0.0.
* \since This function is available since SDL 3.2.0.
*/
SDL_FORCE_INLINE Uint16 SDL_Swap16(Uint16 x) { return x_but_byteswapped; }
@ -369,7 +463,7 @@ SDL_FORCE_INLINE Uint16 SDL_Swap16(Uint16 x) { return x_but_byteswapped; }
*
* \threadsafety It is safe to call this function from any thread.
*
* \since This function is available since SDL 3.0.0.
* \since This function is available since SDL 3.2.0.
*/
SDL_FORCE_INLINE Uint32 SDL_Swap32(Uint32 x) { return x_but_byteswapped; }
@ -390,7 +484,7 @@ SDL_FORCE_INLINE Uint32 SDL_Swap32(Uint32 x) { return x_but_byteswapped; }
*
* \threadsafety It is safe to call this function from any thread.
*
* \since This function is available since SDL 3.0.0.
* \since This function is available since SDL 3.2.0.
*/
SDL_FORCE_INLINE Uint32 SDL_Swap64(Uint64 x) { return x_but_byteswapped; }
@ -404,7 +498,9 @@ SDL_FORCE_INLINE Uint32 SDL_Swap64(Uint64 x) { return x_but_byteswapped; }
* \param x the value to swap, in littleendian byte order.
* \returns `x` in native byte order.
*
* \since This macro is available since SDL 3.0.0.
* \threadsafety It is safe to call this macro from any thread.
*
* \since This macro is available since SDL 3.2.0.
*/
#define SDL_Swap16LE(x) SwapOnlyIfNecessary(x)
@ -418,7 +514,9 @@ SDL_FORCE_INLINE Uint32 SDL_Swap64(Uint64 x) { return x_but_byteswapped; }
* \param x the value to swap, in littleendian byte order.
* \returns `x` in native byte order.
*
* \since This macro is available since SDL 3.0.0.
* \threadsafety It is safe to call this macro from any thread.
*
* \since This macro is available since SDL 3.2.0.
*/
#define SDL_Swap32LE(x) SwapOnlyIfNecessary(x)
@ -432,7 +530,9 @@ SDL_FORCE_INLINE Uint32 SDL_Swap64(Uint64 x) { return x_but_byteswapped; }
* \param x the value to swap, in littleendian byte order.
* \returns `x` in native byte order.
*
* \since This macro is available since SDL 3.0.0.
* \threadsafety It is safe to call this macro from any thread.
*
* \since This macro is available since SDL 3.2.0.
*/
#define SDL_Swap64LE(x) SwapOnlyIfNecessary(x)
@ -446,7 +546,9 @@ SDL_FORCE_INLINE Uint32 SDL_Swap64(Uint64 x) { return x_but_byteswapped; }
* \param x the value to swap, in littleendian byte order.
* \returns `x` in native byte order.
*
* \since This macro is available since SDL 3.0.0.
* \threadsafety It is safe to call this macro from any thread.
*
* \since This macro is available since SDL 3.2.0.
*/
#define SDL_SwapFloatLE(x) SwapOnlyIfNecessary(x)
@ -460,7 +562,9 @@ SDL_FORCE_INLINE Uint32 SDL_Swap64(Uint64 x) { return x_but_byteswapped; }
* \param x the value to swap, in bigendian byte order.
* \returns `x` in native byte order.
*
* \since This macro is available since SDL 3.0.0.
* \threadsafety It is safe to call this macro from any thread.
*
* \since This macro is available since SDL 3.2.0.
*/
#define SDL_Swap16BE(x) SwapOnlyIfNecessary(x)
@ -474,7 +578,9 @@ SDL_FORCE_INLINE Uint32 SDL_Swap64(Uint64 x) { return x_but_byteswapped; }
* \param x the value to swap, in bigendian byte order.
* \returns `x` in native byte order.
*
* \since This macro is available since SDL 3.0.0.
* \threadsafety It is safe to call this macro from any thread.
*
* \since This macro is available since SDL 3.2.0.
*/
#define SDL_Swap32BE(x) SwapOnlyIfNecessary(x)
@ -488,7 +594,9 @@ SDL_FORCE_INLINE Uint32 SDL_Swap64(Uint64 x) { return x_but_byteswapped; }
* \param x the value to swap, in bigendian byte order.
* \returns `x` in native byte order.
*
* \since This macro is available since SDL 3.0.0.
* \threadsafety It is safe to call this macro from any thread.
*
* \since This macro is available since SDL 3.2.0.
*/
#define SDL_Swap64BE(x) SwapOnlyIfNecessary(x)
@ -502,7 +610,9 @@ SDL_FORCE_INLINE Uint32 SDL_Swap64(Uint64 x) { return x_but_byteswapped; }
* \param x the value to swap, in bigendian byte order.
* \returns `x` in native byte order.
*
* \since This macro is available since SDL 3.0.0.
* \threadsafety It is safe to call this macro from any thread.
*
* \since This macro is available since SDL 3.2.0.
*/
#define SDL_SwapFloatBE(x) SwapOnlyIfNecessary(x)

View File

@ -1,6 +1,6 @@
/*
Simple DirectMedia Layer
Copyright (C) 1997-2024 Sam Lantinga <slouken@libsdl.org>
Copyright (C) 1997-2025 Sam Lantinga <slouken@libsdl.org>
This software is provided 'as-is', without any express or implied
warranty. In no event will the authors be held liable for any damages
@ -23,6 +23,26 @@
* # CategoryError
*
* Simple error message routines for SDL.
*
* Most apps will interface with these APIs in exactly one function: when
* almost any SDL function call reports failure, you can get a human-readable
* string of the problem from SDL_GetError().
*
* These strings are maintained per-thread, and apps are welcome to set their
* own errors, which is popular when building libraries on top of SDL for
* other apps to consume. These strings are set by calling SDL_SetError().
*
* A common usage pattern is to have a function that returns true for success
* and false for failure, and do this when something fails:
*
* ```c
* if (something_went_wrong) {
* return SDL_SetError("The thing broke in this specific way: %d", errcode);
* }
* ```
*
* It's also common to just return `false` in this case if the failing thing
* is known to call SDL_SetError(), so errors simply propagate through.
*/
#ifndef SDL_error_h_
@ -44,8 +64,8 @@ extern "C" {
*
* Calling this function will replace any previous error message that was set.
*
* This function always returns -1, since SDL frequently uses -1 to signify an
* failing result, leading to this idiom:
* This function always returns false, since SDL frequently uses false to
* signify a failing result, leading to this idiom:
*
* ```c
* if (error_code) {
@ -56,25 +76,49 @@ extern "C" {
* \param fmt a printf()-style message format string.
* \param ... additional parameters matching % tokens in the `fmt` string, if
* any.
* \returns SDL_FALSE.
* \returns false.
*
* \since This function is available since SDL 3.0.0.
* \threadsafety It is safe to call this function from any thread.
*
* \since This function is available since SDL 3.2.0.
*
* \sa SDL_ClearError
* \sa SDL_GetError
* \sa SDL_SetErrorV
*/
extern SDL_DECLSPEC SDL_bool SDLCALL SDL_SetError(SDL_PRINTF_FORMAT_STRING const char *fmt, ...) SDL_PRINTF_VARARG_FUNC(1);
extern SDL_DECLSPEC bool SDLCALL SDL_SetError(SDL_PRINTF_FORMAT_STRING const char *fmt, ...) SDL_PRINTF_VARARG_FUNC(1);
/**
* Set the SDL error message for the current thread.
*
* Calling this function will replace any previous error message that was set.
*
* \param fmt a printf()-style message format string.
* \param ap a variable argument list.
* \returns false.
*
* \threadsafety It is safe to call this function from any thread.
*
* \since This function is available since SDL 3.2.0.
*
* \sa SDL_ClearError
* \sa SDL_GetError
* \sa SDL_SetError
*/
extern SDL_DECLSPEC bool SDLCALL SDL_SetErrorV(SDL_PRINTF_FORMAT_STRING const char *fmt, va_list ap) SDL_PRINTF_VARARG_FUNCV(1);
/**
* Set an error indicating that memory allocation failed.
*
* This function does not do any memory allocation.
*
* \returns SDL_FALSE.
* \returns false.
*
* \since This function is available since SDL 3.0.0.
* \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_bool SDLCALL SDL_OutOfMemory(void);
extern SDL_DECLSPEC bool SDLCALL SDL_OutOfMemory(void);
/**
* Retrieve a message about the last error that occurred on the current
@ -104,7 +148,9 @@ extern SDL_DECLSPEC SDL_bool SDLCALL SDL_OutOfMemory(void);
* or an empty string if there hasn't been an error message set since
* the last call to SDL_ClearError().
*
* \since This function is available since SDL 3.0.0.
* \threadsafety It is safe to call this function from any thread.
*
* \since This function is available since SDL 3.2.0.
*
* \sa SDL_ClearError
* \sa SDL_SetError
@ -114,14 +160,16 @@ extern SDL_DECLSPEC const char * SDLCALL SDL_GetError(void);
/**
* Clear any previous error message for this thread.
*
* \returns SDL_TRUE.
* \returns true.
*
* \since This function is available since SDL 3.0.0.
* \threadsafety It is safe to call this function from any thread.
*
* \since This function is available since SDL 3.2.0.
*
* \sa SDL_GetError
* \sa SDL_SetError
*/
extern SDL_DECLSPEC SDL_bool SDLCALL SDL_ClearError(void);
extern SDL_DECLSPEC bool SDLCALL SDL_ClearError(void);
/**
* \name Internal error functions
@ -130,8 +178,43 @@ extern SDL_DECLSPEC SDL_bool SDLCALL SDL_ClearError(void);
* Private error reporting function - used internally.
*/
/* @{ */
/**
* A macro to standardize error reporting on unsupported operations.
*
* This simply calls SDL_SetError() with a standardized error string, for
* convenience, consistency, and clarity.
*
* \threadsafety It is safe to call this macro from any thread.
*
* \since This macro is available since SDL 3.2.0.
*/
#define SDL_Unsupported() SDL_SetError("That operation is not supported")
/**
* A macro to standardize error reporting on unsupported operations.
*
* This simply calls SDL_SetError() with a standardized error string, for
* convenience, consistency, and clarity.
*
* A common usage pattern inside SDL is this:
*
* ```c
* bool MyFunction(const char *str) {
* if (!str) {
* return SDL_InvalidParamError("str"); // returns false.
* }
* DoSomething(str);
* return true;
* }
* ```
*
* \threadsafety It is safe to call this macro from any thread.
*
* \since This macro is available since SDL 3.2.0.
*/
#define SDL_InvalidParamError(param) SDL_SetError("Parameter '%s' is invalid", (param))
/* @} *//* Internal error functions */
/* Ends C function definitions when using C++ */

File diff suppressed because it is too large Load Diff

View File

@ -1,6 +1,6 @@
/*
Simple DirectMedia Layer
Copyright (C) 1997-2024 Sam Lantinga <slouken@libsdl.org>
Copyright (C) 1997-2025 Sam Lantinga <slouken@libsdl.org>
This software is provided 'as-is', without any express or implied
warranty. In no event will the authors be held liable for any damages
@ -22,7 +22,23 @@
/**
* # CategoryFilesystem
*
* SDL Filesystem API.
* SDL offers an API for examining and manipulating the system's filesystem.
* This covers most things one would need to do with directories, except for
* actual file I/O (which is covered by [CategoryIOStream](CategoryIOStream)
* and [CategoryAsyncIO](CategoryAsyncIO) instead).
*
* There are functions to answer necessary path questions:
*
* - Where is my app's data? SDL_GetBasePath().
* - Where can I safely write files? SDL_GetPrefPath().
* - Where are paths like Downloads, Desktop, Music? SDL_GetUserFolder().
* - What is this thing at this location? SDL_GetPathInfo().
* - What items live in this folder? SDL_EnumerateDirectory().
* - What items live in this folder by wildcard? SDL_GlobDirectory().
* - What is my current working directory? SDL_GetCurrentDirectory().
*
* SDL also offers functions to manipulate the directory tree: renaming,
* removing, copying files.
*/
#ifndef SDL_filesystem_h_
@ -73,7 +89,7 @@ extern "C" {
* doesn't implement this functionality, call SDL_GetError() for more
* information.
*
* \since This function is available since SDL 3.0.0.
* \since This function is available since SDL 3.2.0.
*
* \sa SDL_GetPrefPath
*/
@ -128,7 +144,7 @@ extern SDL_DECLSPEC const char * SDLCALL SDL_GetBasePath(void);
* etc.). This should be freed with SDL_free() when it is no longer
* needed.
*
* \since This function is available since SDL 3.0.0.
* \since This function is available since SDL 3.2.0.
*
* \sa SDL_GetBasePath
*/
@ -143,66 +159,40 @@ extern SDL_DECLSPEC char * SDLCALL SDL_GetPrefPath(const char *org, const char *
*
* The folders supported per platform are:
*
* | | Windows | WinRT/UWP |macOS/iOS | tvOS | Unix (XDG) | Haiku | Emscripten |
* | ----------- | ------- | --------- |--------- | ---- | ---------- | ----- | ---------- |
* | HOME | X | X | X | | X | X | X |
* | DESKTOP | X | X | X | | X | X | |
* | DOCUMENTS | X | X | X | | X | | |
* | DOWNLOADS | Vista+ | X | X | | X | | |
* | MUSIC | X | X | X | | X | | |
* | PICTURES | X | X | X | | X | | |
* | PUBLICSHARE | | | X | | X | | |
* | SAVEDGAMES | Vista+ | | | | | | |
* | SCREENSHOTS | Vista+ | X | | | | | |
* | TEMPLATES | X | X | X | | X | | |
* | VIDEOS | X | X | X* | | X | | |
* | | Windows | macOS/iOS | tvOS | Unix (XDG) | Haiku | Emscripten |
* | ----------- | ------- | --------- | ---- | ---------- | ----- | ---------- |
* | HOME | X | X | | X | X | X |
* | DESKTOP | X | X | | X | X | |
* | DOCUMENTS | X | X | | X | | |
* | DOWNLOADS | Vista+ | X | | X | | |
* | MUSIC | X | X | | X | | |
* | PICTURES | X | X | | X | | |
* | PUBLICSHARE | | X | | X | | |
* | SAVEDGAMES | Vista+ | | | | | |
* | SCREENSHOTS | Vista+ | | | | | |
* | TEMPLATES | X | X | | X | | |
* | VIDEOS | X | X* | | X | | |
*
* Note that on macOS/iOS, the Videos folder is called "Movies".
*
* \since This enum is available since SDL 3.0.0.
* \since This enum is available since SDL 3.2.0.
*
* \sa SDL_GetUserFolder
*/
typedef enum SDL_Folder
{
/** The folder which contains all of the current user's data, preferences,
and documents. It usually contains most of the other folders. If a
requested folder does not exist, the home folder can be considered a safe
fallback to store a user's documents. */
SDL_FOLDER_HOME,
/** The folder of files that are displayed on the desktop. Note that the
existence of a desktop folder does not guarantee that the system does
show icons on its desktop; certain GNU/Linux distros with a graphical
environment may not have desktop icons. */
SDL_FOLDER_DESKTOP,
/** User document files, possibly application-specific. This is a good
place to save a user's projects. */
SDL_FOLDER_DOCUMENTS,
/** Standard folder for user files downloaded from the internet. */
SDL_FOLDER_DOWNLOADS,
/** Music files that can be played using a standard music player (mp3,
ogg...). */
SDL_FOLDER_MUSIC,
/** Image files that can be displayed using a standard viewer (png,
jpg...). */
SDL_FOLDER_PICTURES,
/** Files that are meant to be shared with other users on the same
computer. */
SDL_FOLDER_PUBLICSHARE,
/** Save files for games. */
SDL_FOLDER_SAVEDGAMES,
/** Application screenshots. */
SDL_FOLDER_SCREENSHOTS,
/** Template files to be used when the user requests the desktop environment
to create a new file in a certain folder, such as "New Text File.txt".
Any file in the Templates folder can be used as a starting point for a
new file. */
SDL_FOLDER_TEMPLATES,
/** Video files that can be played using a standard video player (mp4,
webm...). */
SDL_FOLDER_VIDEOS,
/** total number of types in this enum, not a folder type by itself. */
SDL_FOLDER_TOTAL
SDL_FOLDER_HOME, /**< The folder which contains all of the current user's data, preferences, and documents. It usually contains most of the other folders. If a requested folder does not exist, the home folder can be considered a safe fallback to store a user's documents. */
SDL_FOLDER_DESKTOP, /**< The folder of files that are displayed on the desktop. Note that the existence of a desktop folder does not guarantee that the system does show icons on its desktop; certain GNU/Linux distros with a graphical environment may not have desktop icons. */
SDL_FOLDER_DOCUMENTS, /**< User document files, possibly application-specific. This is a good place to save a user's projects. */
SDL_FOLDER_DOWNLOADS, /**< Standard folder for user files downloaded from the internet. */
SDL_FOLDER_MUSIC, /**< Music files that can be played using a standard music player (mp3, ogg...). */
SDL_FOLDER_PICTURES, /**< Image files that can be displayed using a standard viewer (png, jpg...). */
SDL_FOLDER_PUBLICSHARE, /**< Files that are meant to be shared with other users on the same computer. */
SDL_FOLDER_SAVEDGAMES, /**< Save files for games. */
SDL_FOLDER_SCREENSHOTS, /**< Application screenshots. */
SDL_FOLDER_TEMPLATES, /**< Template files to be used when the user requests the desktop environment to create a new file in a certain folder, such as "New Text File.txt". Any file in the Templates folder can be used as a starting point for a new file. */
SDL_FOLDER_VIDEOS, /**< Video files that can be played using a standard video player (mp4, webm...). */
SDL_FOLDER_COUNT /**< Total number of types in this enum, not a folder type by itself. */
} SDL_Folder;
/**
@ -226,13 +216,24 @@ typedef enum SDL_Folder
* \returns either a null-terminated C string containing the full path to the
* folder, or NULL if an error happened.
*
* \since This function is available since SDL 3.0.0.
* \since This function is available since SDL 3.2.0.
*/
extern SDL_DECLSPEC const char * SDLCALL SDL_GetUserFolder(SDL_Folder folder);
/* Abstract filesystem interface */
/**
* 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.
*
* \since This enum is available since SDL 3.2.0.
*
* \sa SDL_PathInfo
*/
typedef enum SDL_PathType
{
SDL_PATHTYPE_NONE, /**< path does not exist */
@ -241,19 +242,27 @@ typedef enum SDL_PathType
SDL_PATHTYPE_OTHER /**< something completely different like a device node (not a symlink, those are always followed) */
} SDL_PathType;
/**
* Information about a path on the filesystem.
*
* \since This datatype is available since SDL 3.2.0.
*
* \sa SDL_GetPathInfo
* \sa SDL_GetStoragePathInfo
*/
typedef struct SDL_PathInfo
{
SDL_PathType type; /* the path type */
Uint64 size; /* the file size in bytes */
SDL_Time create_time; /* the time when the path was created */
SDL_Time modify_time; /* the last time the path was modified */
SDL_Time access_time; /* the last time the path was read */
SDL_PathType type; /**< the path type */
Uint64 size; /**< the file size in bytes */
SDL_Time create_time; /**< the time when the path was created */
SDL_Time modify_time; /**< the last time the path was modified */
SDL_Time access_time; /**< the last time the path was read */
} SDL_PathInfo;
/**
* Flags for path matching
* Flags for path matching.
*
* \since This datatype is available since SDL 3.0.0.
* \since This datatype is available since SDL 3.2.0.
*
* \sa SDL_GlobDirectory
* \sa SDL_GlobStorageDirectory
@ -263,73 +272,160 @@ typedef Uint32 SDL_GlobFlags;
#define SDL_GLOB_CASEINSENSITIVE (1u << 0)
/**
* Create a directory.
* Create a directory, and any missing parent directories.
*
* This reports success if `path` already exists as a directory.
*
* If parent directories are missing, it will also create them. Note that if
* this fails, it will not remove any parent directories it already made.
*
* \param path the path of the directory to create.
* \returns SDL_TRUE on success or SDL_FALSE on failure; call SDL_GetError()
* for more information.
* \returns true on success or false on failure; call SDL_GetError() for more
* information.
*
* \since This function is available since SDL 3.0.0.
* \since This function is available since SDL 3.2.0.
*/
extern SDL_DECLSPEC SDL_bool SDLCALL SDL_CreateDirectory(const char *path);
extern SDL_DECLSPEC bool SDLCALL SDL_CreateDirectory(const char *path);
/* Callback for directory enumeration. Return 1 to keep enumerating,
0 to stop enumerating (no error), -1 to stop enumerating and
report an error. `dirname` is the directory being enumerated,
`fname` is the enumerated entry. */
typedef int (SDLCALL *SDL_EnumerateDirectoryCallback)(void *userdata, const char *dirname, const char *fname);
/**
* Possible results from an enumeration callback.
*
* \since This enum is available since SDL 3.2.0.
*
* \sa SDL_EnumerateDirectoryCallback
*/
typedef enum SDL_EnumerationResult
{
SDL_ENUM_CONTINUE, /**< Value that requests that enumeration continue. */
SDL_ENUM_SUCCESS, /**< Value that requests that enumeration stop, successfully. */
SDL_ENUM_FAILURE /**< Value that requests that enumeration stop, as a failure. */
} SDL_EnumerationResult;
/**
* Callback for directory enumeration.
*
* Enumeration of directory entries will continue until either all entries
* have been provided to the callback, or the callback has requested a stop
* through its return value.
*
* Returning SDL_ENUM_CONTINUE will let enumeration proceed, calling the
* callback with further entries. SDL_ENUM_SUCCESS and SDL_ENUM_FAILURE will
* terminate the enumeration early, and dictate the return value of the
* enumeration function itself.
*
* `dirname` is guaranteed to end with a path separator ('\\' on Windows, '/'
* on most other platforms).
*
* \param userdata an app-controlled pointer that is passed to the callback.
* \param dirname the directory that is being enumerated.
* \param fname the next entry in the enumeration.
* \returns how the enumeration should proceed.
*
* \since This datatype is available since SDL 3.2.0.
*
* \sa SDL_EnumerateDirectory
*/
typedef SDL_EnumerationResult (SDLCALL *SDL_EnumerateDirectoryCallback)(void *userdata, const char *dirname, const char *fname);
/**
* Enumerate a directory through a callback function.
*
* This function provides every directory entry through an app-provided
* callback, called once for each directory entry, until all results have been
* provided or the callback returns <= 0.
* provided or the callback returns either SDL_ENUM_SUCCESS or
* SDL_ENUM_FAILURE.
*
* This will return false if there was a system problem in general, or if a
* callback returns SDL_ENUM_FAILURE. A successful return means a callback
* returned SDL_ENUM_SUCCESS to halt enumeration, or all directory entries
* were enumerated.
*
* \param path the path of the directory to enumerate.
* \param callback a function that is called for each entry in the directory.
* \param userdata a pointer that is passed to `callback`.
* \returns SDL_TRUE on success or SDL_FALSE on failure; call SDL_GetError()
* for more information.
* \returns true on success or false on failure; call SDL_GetError() for more
* information.
*
* \since This function is available since SDL 3.0.0.
* \since This function is available since SDL 3.2.0.
*/
extern SDL_DECLSPEC SDL_bool SDLCALL SDL_EnumerateDirectory(const char *path, SDL_EnumerateDirectoryCallback callback, void *userdata);
extern SDL_DECLSPEC bool SDLCALL SDL_EnumerateDirectory(const char *path, SDL_EnumerateDirectoryCallback callback, void *userdata);
/**
* Remove a file or an empty directory.
*
* \param path the path of the directory to enumerate.
* \returns SDL_TRUE on success or SDL_FALSE on failure; call SDL_GetError()
* for more information.
* Directories that are not empty will fail; this function will not recursely
* delete directory trees.
*
* \since This function is available since SDL 3.0.0.
* \param path the path to remove from the filesystem.
* \returns true on success or false on failure; call SDL_GetError() for more
* information.
*
* \since This function is available since SDL 3.2.0.
*/
extern SDL_DECLSPEC SDL_bool SDLCALL SDL_RemovePath(const char *path);
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.
*
* Note that this will not copy files across filesystems/drives/volumes, as
* that is a much more complicated (and possibly time-consuming) operation.
*
* Which is to say, if this function fails, SDL_CopyFile() to a temporary file
* in the same directory as `newpath`, then SDL_RenamePath() from the
* temporary file to `newpath` and SDL_RemovePath() on `oldpath` might work
* for files. Renaming a non-empty directory across filesystems is
* dramatically more complex, however.
*
* \param oldpath the old path.
* \param newpath the new path.
* \returns SDL_TRUE on success or SDL_FALSE on failure; call SDL_GetError()
* for more information.
* \returns true on success or false on failure; call SDL_GetError() for more
* information.
*
* \since This function is available since SDL 3.0.0.
* \since This function is available since SDL 3.2.0.
*/
extern SDL_DECLSPEC SDL_bool SDLCALL SDL_RenamePath(const char *oldpath, const char *newpath);
extern SDL_DECLSPEC bool SDLCALL SDL_RenamePath(const char *oldpath, const char *newpath);
/**
* Copy a file.
*
* If the file at `newpath` already exists, it will be overwritten with the
* contents of the file at `oldpath`.
*
* This function will block until the copy is complete, which might be a
* significant time for large files on slow disks. On some platforms, the copy
* can be handed off to the OS itself, but on others SDL might just open both
* paths, and read from one and write to the other.
*
* Note that this is not an atomic operation! If something tries to read from
* `newpath` while the copy is in progress, it will see an incomplete copy of
* the data, and if the calling thread terminates (or the power goes out)
* during the copy, `newpath`'s previous contents will be gone, replaced with
* an incomplete copy of the data. To avoid this risk, it is recommended that
* the app copy to a temporary file in the same directory as `newpath`, and if
* the copy is successful, use SDL_RenamePath() to replace `newpath` with the
* temporary file. This will ensure that reads of `newpath` will either see a
* complete copy of the data, or it will see the pre-copy state of `newpath`.
*
* This function attempts to synchronize the newly-copied data to disk before
* returning, if the platform allows it, so that the renaming trick will not
* have a problem in a system crash or power failure, where the file could be
* renamed but the contents never made it from the system file cache to the
* physical disk.
*
* If the copy fails for any reason, the state of `newpath` is undefined. It
* might be half a copy, it might be the untouched data of what was already
* there, or it might be a zero-byte file, etc.
*
* \param oldpath the old path.
* \param newpath the new path.
* \returns SDL_TRUE on success or SDL_FALSE on failure; call SDL_GetError()
* for more information.
* \returns true on success or false on failure; call SDL_GetError() for more
* information.
*
* \since This function is available since SDL 3.0.0.
* \since This function is available since SDL 3.2.0.
*/
extern SDL_DECLSPEC SDL_bool SDLCALL SDL_CopyFile(const char *oldpath, const char *newpath);
extern SDL_DECLSPEC bool SDLCALL SDL_CopyFile(const char *oldpath, const char *newpath);
/**
* Get information about a filesystem path.
@ -337,21 +433,21 @@ extern SDL_DECLSPEC SDL_bool SDLCALL SDL_CopyFile(const char *oldpath, const cha
* \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 SDL_TRUE on success or SDL_FALSE if the file doesn't exist, or
* another failure; call SDL_GetError() for more information.
* \returns true on success or false if the file doesn't exist, or another
* failure; call SDL_GetError() for more information.
*
* \since This function is available since SDL 3.0.0.
* \since This function is available since SDL 3.2.0.
*/
extern SDL_DECLSPEC SDL_bool SDLCALL SDL_GetPathInfo(const char *path, SDL_PathInfo *info);
extern SDL_DECLSPEC bool SDLCALL SDL_GetPathInfo(const char *path, SDL_PathInfo *info);
/**
* 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
@ -373,10 +469,31 @@ extern SDL_DECLSPEC SDL_bool SDLCALL SDL_GetPathInfo(const char *path, SDL_PathI
*
* \threadsafety It is safe to call this function from any thread.
*
* \since This function is available since SDL 3.0.0.
* \since This function is available since SDL 3.2.0.
*/
extern SDL_DECLSPEC char ** SDLCALL SDL_GlobDirectory(const char *path, const char *pattern, SDL_GlobFlags flags, int *count);
/**
* Get what the system believes is the "current working directory."
*
* For systems without a concept of a current working directory, this will
* still attempt to provide something reasonable.
*
* SDL does not provide a means to _change_ the current working directory; for
* platforms without this concept, this would cause surprises with file access
* outside of SDL.
*
* The returned path is guaranteed to end with a path separator ('\\' on
* Windows, '/' on most other platforms).
*
* \returns a UTF-8 string of the current working directory in
* platform-dependent notation. NULL if there's a problem. This
* should be freed with SDL_free() when it is no longer needed.
*
* \since This function is available since SDL 3.2.0.
*/
extern SDL_DECLSPEC char * SDLCALL SDL_GetCurrentDirectory(void);
/* Ends C function definitions when using C++ */
#ifdef __cplusplus
}

View File

@ -1,6 +1,6 @@
/*
Simple DirectMedia Layer
Copyright (C) 1997-2024 Sam Lantinga <slouken@libsdl.org>
Copyright (C) 1997-2025 Sam Lantinga <slouken@libsdl.org>
This software is provided 'as-is', without any express or implied
warranty. In no event will the authors be held liable for any damages
@ -51,6 +51,24 @@
* 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
*
* Gamepads support various optional features such as rumble, color LEDs,
* touchpad, gyro, etc. The support for these features varies depending on the
* controller and OS support available. You can check for LED and rumble
* capabilities at runtime by calling SDL_GetGamepadProperties() and checking
* the various capability properties. You can check for touchpad by calling
* SDL_GetNumGamepadTouchpads() and check for gyro and accelerometer by
* calling SDL_GamepadHasSensor().
*
* By default SDL will try to use the most capable driver available, but you
* can tune which OS drivers to use with the various joystick hints in
* SDL_hints.h.
*
* Your application should always support gamepad hotplugging. On some
* platforms like Xbox, Steam Deck, etc., this is a requirement for
* certification. On other platforms, like macOS and Windows when using
* Windows.Gaming.Input, controllers may not be available at startup and will
* come in at some point after you've started processing events.
*/
#ifndef SDL_gamepad_h_
@ -58,9 +76,11 @@
#include <SDL3/SDL_stdinc.h>
#include <SDL3/SDL_error.h>
#include <SDL3/SDL_joystick.h>
#include <SDL3/SDL_properties.h>
#include <SDL3/SDL_guid.h>
#include <SDL3/SDL_iostream.h>
#include <SDL3/SDL_joystick.h>
#include <SDL3/SDL_power.h>
#include <SDL3/SDL_properties.h>
#include <SDL3/SDL_sensor.h>
#include <SDL3/SDL_begin_code.h>
@ -72,7 +92,7 @@ extern "C" {
/**
* The structure used to identify an SDL gamepad
*
* \since This struct is available since SDL 3.0.0.
* \since This struct is available since SDL 3.2.0.
*/
typedef struct SDL_Gamepad SDL_Gamepad;
@ -98,7 +118,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_MAX
SDL_GAMEPAD_TYPE_COUNT
} SDL_GamepadType;
/**
@ -122,15 +142,15 @@ typedef enum SDL_GamepadType
* You can query the labels for the face buttons using
* SDL_GetGamepadButtonLabel()
*
* \since This enum is available since SDL 3.0.0.
* \since This enum is available since SDL 3.2.0.
*/
typedef enum SDL_GamepadButton
{
SDL_GAMEPAD_BUTTON_INVALID = -1,
SDL_GAMEPAD_BUTTON_SOUTH, /* Bottom face button (e.g. Xbox A button) */
SDL_GAMEPAD_BUTTON_EAST, /* Right face button (e.g. Xbox B button) */
SDL_GAMEPAD_BUTTON_WEST, /* Left face button (e.g. Xbox X button) */
SDL_GAMEPAD_BUTTON_NORTH, /* Top face button (e.g. Xbox Y button) */
SDL_GAMEPAD_BUTTON_SOUTH, /**< Bottom face button (e.g. Xbox A button) */
SDL_GAMEPAD_BUTTON_EAST, /**< Right face button (e.g. Xbox B button) */
SDL_GAMEPAD_BUTTON_WEST, /**< Left face button (e.g. Xbox X button) */
SDL_GAMEPAD_BUTTON_NORTH, /**< Top face button (e.g. Xbox Y button) */
SDL_GAMEPAD_BUTTON_BACK,
SDL_GAMEPAD_BUTTON_GUIDE,
SDL_GAMEPAD_BUTTON_START,
@ -142,18 +162,18 @@ 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_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_MISC5, /* Additional button */
SDL_GAMEPAD_BUTTON_MISC6, /* Additional button */
SDL_GAMEPAD_BUTTON_MAX
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_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_MISC5, /**< Additional button */
SDL_GAMEPAD_BUTTON_MISC6, /**< Additional button */
SDL_GAMEPAD_BUTTON_COUNT
} SDL_GamepadButton;
/**
@ -165,7 +185,7 @@ typedef enum SDL_GamepadButton
* For a complete set, you should look at the button and gamepad type and have
* a set of symbols that work well with your art style.
*
* \since This enum is available since SDL 3.0.0.
* \since This enum is available since SDL 3.2.0.
*/
typedef enum SDL_GamepadButtonLabel
{
@ -192,7 +212,7 @@ typedef enum SDL_GamepadButtonLabel
* pressed) when reported by SDL_GetGamepadAxis(). Note that this is not the
* same range that will be reported by the lower-level SDL_GetJoystickAxis().
*
* \since This enum is available since SDL 3.0.0.
* \since This enum is available since SDL 3.2.0.
*/
typedef enum SDL_GamepadAxis
{
@ -203,7 +223,7 @@ typedef enum SDL_GamepadAxis
SDL_GAMEPAD_AXIS_RIGHTY,
SDL_GAMEPAD_AXIS_LEFT_TRIGGER,
SDL_GAMEPAD_AXIS_RIGHT_TRIGGER,
SDL_GAMEPAD_AXIS_MAX
SDL_GAMEPAD_AXIS_COUNT
} SDL_GamepadAxis;
/**
@ -214,7 +234,7 @@ typedef enum SDL_GamepadAxis
* gamepad. This enum is used as part of SDL_GamepadBinding to specify those
* mappings.
*
* \since This enum is available since SDL 3.0.0.
* \since This enum is available since SDL 3.2.0.
*/
typedef enum SDL_GamepadBindingType
{
@ -235,7 +255,7 @@ typedef enum SDL_GamepadBindingType
* more with a simple text string. Those strings are parsed into a collection
* of these structs to make it easier to operate on the data.
*
* \since This struct is available since SDL 3.0.0.
* \since This struct is available since SDL 3.2.0.
*
* \sa SDL_GetGamepadBindings
*/
@ -293,6 +313,9 @@ typedef struct SDL_GamepadBinding
*
* Buttons can be used as a gamepad axes and vice versa.
*
* If a device with this GUID is already plugged in, SDL will generate an
* SDL_EVENT_GAMEPAD_ADDED event.
*
* This string shows an example of a valid mapping for a gamepad:
*
* ```c
@ -305,10 +328,15 @@ typedef struct SDL_GamepadBinding
*
* \threadsafety It is safe to call this function from any thread.
*
* \since This function is available since SDL 3.0.0.
* \since This function is available since SDL 3.2.0.
*
* \sa SDL_AddGamepadMappingsFromFile
* \sa SDL_AddGamepadMappingsFromIO
* \sa SDL_GetGamepadMapping
* \sa SDL_GetGamepadMappingForGUID
* \sa SDL_HINT_GAMECONTROLLERCONFIG
* \sa SDL_HINT_GAMECONTROLLERCONFIG_FILE
* \sa SDL_EVENT_GAMEPAD_ADDED
*/
extern SDL_DECLSPEC int SDLCALL SDL_AddGamepadMapping(const char *mapping);
@ -321,6 +349,9 @@ extern SDL_DECLSPEC int SDLCALL SDL_AddGamepadMapping(const char *mapping);
* If a new mapping is loaded for an already known gamepad GUID, the later
* version will overwrite the one currently loaded.
*
* Any new mappings for already plugged in controllers will generate
* SDL_EVENT_GAMEPAD_ADDED events.
*
* Mappings not belonging to the current platform or with no platform field
* specified will be ignored (i.e. mappings for Linux will be ignored in
* Windows, etc).
@ -330,21 +361,24 @@ extern SDL_DECLSPEC int SDLCALL SDL_AddGamepadMapping(const char *mapping);
* constrained environment.
*
* \param src the data stream for the mappings to be added.
* \param closeio if SDL_TRUE, calls SDL_CloseIO() on `src` before returning,
* even in the case of an error.
* \param closeio if true, calls SDL_CloseIO() on `src` before returning, even
* in the case of an error.
* \returns the number of mappings added 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.0.0.
* \since This function is available since SDL 3.2.0.
*
* \sa SDL_AddGamepadMapping
* \sa SDL_AddGamepadMappingsFromFile
* \sa SDL_GetGamepadMapping
* \sa SDL_GetGamepadMappingForGUID
* \sa SDL_HINT_GAMECONTROLLERCONFIG
* \sa SDL_HINT_GAMECONTROLLERCONFIG_FILE
* \sa SDL_EVENT_GAMEPAD_ADDED
*/
extern SDL_DECLSPEC int SDLCALL SDL_AddGamepadMappingsFromIO(SDL_IOStream *src, SDL_bool closeio);
extern SDL_DECLSPEC int SDLCALL SDL_AddGamepadMappingsFromIO(SDL_IOStream *src, bool closeio);
/**
* Load a set of gamepad mappings from a file.
@ -355,6 +389,9 @@ extern SDL_DECLSPEC int SDLCALL SDL_AddGamepadMappingsFromIO(SDL_IOStream *src,
* If a new mapping is loaded for an already known gamepad GUID, the later
* version will overwrite the one currently loaded.
*
* Any new mappings for already plugged in controllers will generate
* SDL_EVENT_GAMEPAD_ADDED events.
*
* Mappings not belonging to the current platform or with no platform field
* specified will be ignored (i.e. mappings for Linux will be ignored in
* Windows, etc).
@ -365,12 +402,15 @@ extern SDL_DECLSPEC int SDLCALL SDL_AddGamepadMappingsFromIO(SDL_IOStream *src,
*
* \threadsafety It is safe to call this function from any thread.
*
* \since This function is available since SDL 3.0.0.
* \since This function is available since SDL 3.2.0.
*
* \sa SDL_AddGamepadMapping
* \sa SDL_AddGamepadMappingsFromIO
* \sa SDL_GetGamepadMapping
* \sa SDL_GetGamepadMappingForGUID
* \sa SDL_HINT_GAMECONTROLLERCONFIG
* \sa SDL_HINT_GAMECONTROLLERCONFIG_FILE
* \sa SDL_EVENT_GAMEPAD_ADDED
*/
extern SDL_DECLSPEC int SDLCALL SDL_AddGamepadMappingsFromFile(const char *file);
@ -379,12 +419,12 @@ extern SDL_DECLSPEC int SDLCALL SDL_AddGamepadMappingsFromFile(const char *file)
*
* This will generate gamepad events as needed if device mappings change.
*
* \returns SDL_TRUE on success or SDL_FALSE on failure; call SDL_GetError()
* for more information.
* \returns true on success or false on failure; call SDL_GetError() for more
* information.
*
* \since This function is available since SDL 3.0.0.
* \since This function is available since SDL 3.2.0.
*/
extern SDL_DECLSPEC SDL_bool SDLCALL SDL_ReloadGamepadMappings(void);
extern SDL_DECLSPEC bool SDLCALL SDL_ReloadGamepadMappings(void);
/**
* Get the current gamepad mappings.
@ -396,7 +436,7 @@ extern SDL_DECLSPEC SDL_bool SDLCALL SDL_ReloadGamepadMappings(void);
* single allocation that should be freed with SDL_free() when it is
* no longer needed.
*
* \since This function is available since SDL 3.0.0.
* \since This function is available since SDL 3.2.0.
*/
extern SDL_DECLSPEC char ** SDLCALL SDL_GetGamepadMappings(int *count);
@ -408,7 +448,7 @@ extern SDL_DECLSPEC char ** SDLCALL SDL_GetGamepadMappings(int *count);
* information. This should be freed with SDL_free() when it is no
* longer needed.
*
* \since This function is available since SDL 3.0.0.
* \since This function is available since SDL 3.2.0.
*
* \sa SDL_GetJoystickGUIDForID
* \sa SDL_GetJoystickGUID
@ -425,7 +465,7 @@ 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.
*
* \since This function is available since SDL 3.0.0.
* \since This function is available since SDL 3.2.0.
*
* \sa SDL_AddGamepadMapping
* \sa SDL_GetGamepadMappingForID
@ -442,26 +482,26 @@ extern SDL_DECLSPEC char * SDLCALL SDL_GetGamepadMapping(SDL_Gamepad *gamepad);
* \param instance_id the joystick instance ID.
* \param mapping the mapping to use for this device, or NULL to clear the
* mapping.
* \returns SDL_TRUE on success or SDL_FALSE on failure; call SDL_GetError()
* for more information.
* \returns true on success or false on failure; call SDL_GetError() for more
* information.
*
* \since This function is available since SDL 3.0.0.
* \since This function is available since SDL 3.2.0.
*
* \sa SDL_AddGamepadMapping
* \sa SDL_GetGamepadMapping
*/
extern SDL_DECLSPEC SDL_bool SDLCALL SDL_SetGamepadMapping(SDL_JoystickID instance_id, const char *mapping);
extern SDL_DECLSPEC bool SDLCALL SDL_SetGamepadMapping(SDL_JoystickID instance_id, const char *mapping);
/**
* Return whether a gamepad is currently connected.
*
* \returns SDL_TRUE if a gamepad is connected, SDL_FALSE otherwise.
* \returns true if a gamepad is connected, false otherwise.
*
* \since This function is available since SDL 3.0.0.
* \since This function is available since SDL 3.2.0.
*
* \sa SDL_GetGamepads
*/
extern SDL_DECLSPEC SDL_bool SDLCALL SDL_HasGamepad(void);
extern SDL_DECLSPEC bool SDLCALL SDL_HasGamepad(void);
/**
* Get a list of currently connected gamepads.
@ -472,7 +512,7 @@ extern SDL_DECLSPEC SDL_bool SDLCALL SDL_HasGamepad(void);
* call SDL_GetError() for more information. This should be freed
* with SDL_free() when it is no longer needed.
*
* \since This function is available since SDL 3.0.0.
* \since This function is available since SDL 3.2.0.
*
* \sa SDL_HasGamepad
* \sa SDL_OpenGamepad
@ -483,15 +523,15 @@ extern SDL_DECLSPEC SDL_JoystickID * SDLCALL SDL_GetGamepads(int *count);
* Check if the given joystick is supported by the gamepad interface.
*
* \param instance_id the joystick instance ID.
* \returns SDL_TRUE if the given joystick is supported by the gamepad
* interface, SDL_FALSE if it isn't or it's an invalid index.
* \returns true if the given joystick is supported by the gamepad interface,
* false if it isn't or it's an invalid index.
*
* \since This function is available since SDL 3.0.0.
* \since This function is available since SDL 3.2.0.
*
* \sa SDL_GetJoysticks
* \sa SDL_OpenGamepad
*/
extern SDL_DECLSPEC SDL_bool SDLCALL SDL_IsGamepad(SDL_JoystickID instance_id);
extern SDL_DECLSPEC bool SDLCALL SDL_IsGamepad(SDL_JoystickID instance_id);
/**
* Get the implementation dependent name of a gamepad.
@ -502,7 +542,7 @@ extern SDL_DECLSPEC SDL_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.
*
* \since This function is available since SDL 3.0.0.
* \since This function is available since SDL 3.2.0.
*
* \sa SDL_GetGamepadName
* \sa SDL_GetGamepads
@ -518,7 +558,7 @@ 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.
*
* \since This function is available since SDL 3.0.0.
* \since This function is available since SDL 3.2.0.
*
* \sa SDL_GetGamepadPath
* \sa SDL_GetGamepads
@ -533,7 +573,7 @@ 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.
*
* \since This function is available since SDL 3.0.0.
* \since This function is available since SDL 3.2.0.
*
* \sa SDL_GetGamepadPlayerIndex
* \sa SDL_GetGamepads
@ -549,7 +589,7 @@ 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.
*
* \since This function is available since SDL 3.0.0.
* \since This function is available since SDL 3.2.0.
*
* \sa SDL_GUIDToString
* \sa SDL_GetGamepads
@ -566,7 +606,7 @@ 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.
*
* \since This function is available since SDL 3.0.0.
* \since This function is available since SDL 3.2.0.
*
* \sa SDL_GetGamepadVendor
* \sa SDL_GetGamepads
@ -583,7 +623,7 @@ 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.
*
* \since This function is available since SDL 3.0.0.
* \since This function is available since SDL 3.2.0.
*
* \sa SDL_GetGamepadProduct
* \sa SDL_GetGamepads
@ -600,7 +640,7 @@ 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.
*
* \since This function is available since SDL 3.0.0.
* \since This function is available since SDL 3.2.0.
*
* \sa SDL_GetGamepadProductVersion
* \sa SDL_GetGamepads
@ -615,7 +655,7 @@ extern SDL_DECLSPEC Uint16 SDLCALL SDL_GetGamepadProductVersionForID(SDL_Joystic
* \param instance_id the joystick instance ID.
* \returns the gamepad type.
*
* \since This function is available since SDL 3.0.0.
* \since This function is available since SDL 3.2.0.
*
* \sa SDL_GetGamepadType
* \sa SDL_GetGamepads
@ -631,7 +671,7 @@ extern SDL_DECLSPEC SDL_GamepadType SDLCALL SDL_GetGamepadTypeForID(SDL_Joystick
* \param instance_id the joystick instance ID.
* \returns the gamepad type.
*
* \since This function is available since SDL 3.0.0.
* \since This function is available since SDL 3.2.0.
*
* \sa SDL_GetGamepadTypeForID
* \sa SDL_GetGamepads
@ -648,7 +688,7 @@ 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.
*
* \since This function is available since SDL 3.0.0.
* \since This function is available since SDL 3.2.0.
*
* \sa SDL_GetGamepads
* \sa SDL_GetGamepadMapping
@ -662,7 +702,7 @@ 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.
*
* \since This function is available since SDL 3.0.0.
* \since This function is available since SDL 3.2.0.
*
* \sa SDL_CloseGamepad
* \sa SDL_IsGamepad
@ -677,7 +717,7 @@ 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.
*
* \since This function is available since SDL 3.0.0.
* \since This function is available since SDL 3.2.0.
*/
extern SDL_DECLSPEC SDL_Gamepad * SDLCALL SDL_GetGamepadFromID(SDL_JoystickID instance_id);
@ -687,7 +727,7 @@ 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.
*
* \since This function is available since SDL 3.0.0.
* \since This function is available since SDL 3.2.0.
*
* \sa SDL_GetGamepadPlayerIndex
* \sa SDL_SetGamepadPlayerIndex
@ -717,7 +757,7 @@ 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.
*
* \since This function is available since SDL 3.0.0.
* \since This function is available since SDL 3.2.0.
*/
extern SDL_DECLSPEC SDL_PropertiesID SDLCALL SDL_GetGamepadProperties(SDL_Gamepad *gamepad);
@ -735,7 +775,7 @@ 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.
*
* \since This function is available since SDL 3.0.0.
* \since This function is available since SDL 3.2.0.
*/
extern SDL_DECLSPEC SDL_JoystickID SDLCALL SDL_GetGamepadID(SDL_Gamepad *gamepad);
@ -747,7 +787,7 @@ 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.
*
* \since This function is available since SDL 3.0.0.
* \since This function is available since SDL 3.2.0.
*
* \sa SDL_GetGamepadNameForID
*/
@ -761,7 +801,7 @@ 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.
*
* \since This function is available since SDL 3.0.0.
* \since This function is available since SDL 3.2.0.
*
* \sa SDL_GetGamepadPathForID
*/
@ -774,7 +814,7 @@ 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.
*
* \since This function is available since SDL 3.0.0.
* \since This function is available since SDL 3.2.0.
*
* \sa SDL_GetGamepadTypeForID
*/
@ -787,7 +827,7 @@ 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.
*
* \since This function is available since SDL 3.0.0.
* \since This function is available since SDL 3.2.0.
*
* \sa SDL_GetRealGamepadTypeForID
*/
@ -801,7 +841,7 @@ 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.
*
* \since This function is available since SDL 3.0.0.
* \since This function is available since SDL 3.2.0.
*
* \sa SDL_SetGamepadPlayerIndex
*/
@ -813,14 +853,14 @@ extern SDL_DECLSPEC int SDLCALL SDL_GetGamepadPlayerIndex(SDL_Gamepad *gamepad);
* \param gamepad the gamepad object to adjust.
* \param player_index player index to assign to this gamepad, or -1 to clear
* the player index and turn off player LEDs.
* \returns SDL_TRUE on success or SDL_FALSE on failure; call SDL_GetError()
* for more information.
* \returns true on success or false on failure; call SDL_GetError() for more
* information.
*
* \since This function is available since SDL 3.0.0.
* \since This function is available since SDL 3.2.0.
*
* \sa SDL_GetGamepadPlayerIndex
*/
extern SDL_DECLSPEC SDL_bool SDLCALL SDL_SetGamepadPlayerIndex(SDL_Gamepad *gamepad, int player_index);
extern SDL_DECLSPEC bool SDLCALL SDL_SetGamepadPlayerIndex(SDL_Gamepad *gamepad, int player_index);
/**
* Get the USB vendor ID of an opened gamepad, if available.
@ -830,7 +870,7 @@ extern SDL_DECLSPEC SDL_bool SDLCALL SDL_SetGamepadPlayerIndex(SDL_Gamepad *game
* \param gamepad the gamepad object to query.
* \returns the USB vendor ID, or zero if unavailable.
*
* \since This function is available since SDL 3.0.0.
* \since This function is available since SDL 3.2.0.
*
* \sa SDL_GetGamepadVendorForID
*/
@ -844,7 +884,7 @@ 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.
*
* \since This function is available since SDL 3.0.0.
* \since This function is available since SDL 3.2.0.
*
* \sa SDL_GetGamepadProductForID
*/
@ -858,7 +898,7 @@ 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.
*
* \since This function is available since SDL 3.0.0.
* \since This function is available since SDL 3.2.0.
*
* \sa SDL_GetGamepadProductVersionForID
*/
@ -872,7 +912,7 @@ 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.
*
* \since This function is available since SDL 3.0.0.
* \since This function is available since SDL 3.2.0.
*/
extern SDL_DECLSPEC Uint16 SDLCALL SDL_GetGamepadFirmwareVersion(SDL_Gamepad *gamepad);
@ -884,7 +924,7 @@ 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.
*
* \since This function is available since SDL 3.0.0.
* \since This function is available since SDL 3.2.0.
*/
extern SDL_DECLSPEC const char * SDLCALL SDL_GetGamepadSerial(SDL_Gamepad *gamepad);
@ -897,7 +937,7 @@ 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.
*
* \since This function is available since SDL 3.0.0.
* \since This function is available since SDL 3.2.0.
*/
extern SDL_DECLSPEC Uint64 SDLCALL SDL_GetGamepadSteamHandle(SDL_Gamepad *gamepad);
@ -909,7 +949,7 @@ extern SDL_DECLSPEC Uint64 SDLCALL SDL_GetGamepadSteamHandle(SDL_Gamepad *gamepa
* `SDL_JOYSTICK_CONNECTION_INVALID` on failure; call SDL_GetError()
* for more information.
*
* \since This function is available since SDL 3.0.0.
* \since This function is available since SDL 3.2.0.
*/
extern SDL_DECLSPEC SDL_JoystickConnectionState SDLCALL SDL_GetGamepadConnectionState(SDL_Gamepad *gamepad);
@ -929,7 +969,7 @@ extern SDL_DECLSPEC SDL_JoystickConnectionState SDLCALL SDL_GetGamepadConnection
* battery.
* \returns the current battery state.
*
* \since This function is available since SDL 3.0.0.
* \since This function is available since SDL 3.2.0.
*/
extern SDL_DECLSPEC SDL_PowerState SDLCALL SDL_GetGamepadPowerInfo(SDL_Gamepad *gamepad, int *percent);
@ -938,12 +978,12 @@ extern SDL_DECLSPEC SDL_PowerState SDLCALL SDL_GetGamepadPowerInfo(SDL_Gamepad *
*
* \param gamepad a gamepad identifier previously returned by
* SDL_OpenGamepad().
* \returns SDL_TRUE if the gamepad has been opened and is currently
* connected, or SDL_FALSE if not.
* \returns true if the gamepad has been opened and is currently connected, or
* false if not.
*
* \since This function is available since SDL 3.0.0.
* \since This function is available since SDL 3.2.0.
*/
extern SDL_DECLSPEC SDL_bool SDLCALL SDL_GamepadConnected(SDL_Gamepad *gamepad);
extern SDL_DECLSPEC bool SDLCALL SDL_GamepadConnected(SDL_Gamepad *gamepad);
/**
* Get the underlying joystick from a gamepad.
@ -961,7 +1001,7 @@ extern SDL_DECLSPEC SDL_bool SDLCALL SDL_GamepadConnected(SDL_Gamepad *gamepad);
* \returns an SDL_Joystick object, or NULL on failure; call SDL_GetError()
* for more information.
*
* \since This function is available since SDL 3.0.0.
* \since This function is available since SDL 3.2.0.
*/
extern SDL_DECLSPEC SDL_Joystick * SDLCALL SDL_GetGamepadJoystick(SDL_Gamepad *gamepad);
@ -973,12 +1013,12 @@ extern SDL_DECLSPEC SDL_Joystick * SDLCALL SDL_GetGamepadJoystick(SDL_Gamepad *g
*
* \param enabled whether to process gamepad events or not.
*
* \since This function is available since SDL 3.0.0.
* \since This function is available since SDL 3.2.0.
*
* \sa SDL_GamepadEventsEnabled
* \sa SDL_UpdateGamepads
*/
extern SDL_DECLSPEC void SDLCALL SDL_SetGamepadEventsEnabled(SDL_bool enabled);
extern SDL_DECLSPEC void SDLCALL SDL_SetGamepadEventsEnabled(bool enabled);
/**
* Query the state of gamepad event processing.
@ -986,14 +1026,13 @@ extern SDL_DECLSPEC void SDLCALL SDL_SetGamepadEventsEnabled(SDL_bool enabled);
* If gamepad events are disabled, you must call SDL_UpdateGamepads() yourself
* and check the state of the gamepad when you want gamepad information.
*
* \returns SDL_TRUE if gamepad events are being processed, SDL_FALSE
* otherwise.
* \returns true if gamepad events are being processed, false otherwise.
*
* \since This function is available since SDL 3.0.0.
* \since This function is available since SDL 3.2.0.
*
* \sa SDL_SetGamepadEventsEnabled
*/
extern SDL_DECLSPEC SDL_bool SDLCALL SDL_GamepadEventsEnabled(void);
extern SDL_DECLSPEC bool SDLCALL SDL_GamepadEventsEnabled(void);
/**
* Get the SDL joystick layer bindings for a gamepad.
@ -1005,7 +1044,7 @@ extern SDL_DECLSPEC SDL_bool SDLCALL SDL_GamepadEventsEnabled(void);
* single allocation that should be freed with SDL_free() when it is
* no longer needed.
*
* \since This function is available since SDL 3.0.0.
* \since This function is available since SDL 3.2.0.
*/
extern SDL_DECLSPEC SDL_GamepadBinding ** SDLCALL SDL_GetGamepadBindings(SDL_Gamepad *gamepad, int *count);
@ -1016,7 +1055,7 @@ extern SDL_DECLSPEC SDL_GamepadBinding ** SDLCALL SDL_GetGamepadBindings(SDL_Gam
* enabled. Under such circumstances, it will not be necessary to call this
* function.
*
* \since This function is available since SDL 3.0.0.
* \since This function is available since SDL 3.2.0.
*/
extern SDL_DECLSPEC void SDLCALL SDL_UpdateGamepads(void);
@ -1032,7 +1071,7 @@ 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.
*
* \since This function is available since SDL 3.0.0.
* \since This function is available since SDL 3.2.0.
*
* \sa SDL_GetGamepadStringForType
*/
@ -1046,7 +1085,7 @@ extern SDL_DECLSPEC SDL_GamepadType SDLCALL SDL_GetGamepadTypeFromString(const c
* specified. The string returned is of the format used by
* SDL_Gamepad mapping strings.
*
* \since This function is available since SDL 3.0.0.
* \since This function is available since SDL 3.2.0.
*
* \sa SDL_GetGamepadTypeFromString
*/
@ -1068,7 +1107,7 @@ 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.
*
* \since This function is available since SDL 3.0.0.
* \since This function is available since SDL 3.2.0.
*
* \sa SDL_GetGamepadStringForAxis
*/
@ -1082,7 +1121,7 @@ extern SDL_DECLSPEC SDL_GamepadAxis SDLCALL SDL_GetGamepadAxisFromString(const c
* specified. The string returned is of the format used by
* SDL_Gamepad mapping strings.
*
* \since This function is available since SDL 3.0.0.
* \since This function is available since SDL 3.2.0.
*
* \sa SDL_GetGamepadAxisFromString
*/
@ -1096,14 +1135,14 @@ extern SDL_DECLSPEC const char * SDLCALL SDL_GetGamepadStringForAxis(SDL_Gamepad
*
* \param gamepad a gamepad.
* \param axis an axis enum value (an SDL_GamepadAxis value).
* \returns SDL_TRUE if the gamepad has this axis, SDL_FALSE otherwise.
* \returns true if the gamepad has this axis, false otherwise.
*
* \since This function is available since SDL 3.0.0.
* \since This function is available since SDL 3.2.0.
*
* \sa SDL_GamepadHasButton
* \sa SDL_GetGamepadAxis
*/
extern SDL_DECLSPEC SDL_bool SDLCALL SDL_GamepadHasAxis(SDL_Gamepad *gamepad, SDL_GamepadAxis axis);
extern SDL_DECLSPEC bool SDLCALL SDL_GamepadHasAxis(SDL_Gamepad *gamepad, SDL_GamepadAxis axis);
/**
* Get the current state of an axis control on a gamepad.
@ -1122,7 +1161,7 @@ extern SDL_DECLSPEC SDL_bool SDLCALL SDL_GamepadHasAxis(SDL_Gamepad *gamepad, SD
* \returns axis state (including 0) on success or 0 (also) on failure; call
* SDL_GetError() for more information.
*
* \since This function is available since SDL 3.0.0.
* \since This function is available since SDL 3.2.0.
*
* \sa SDL_GamepadHasAxis
* \sa SDL_GetGamepadButton
@ -1141,7 +1180,7 @@ extern SDL_DECLSPEC Sint16 SDLCALL SDL_GetGamepadAxis(SDL_Gamepad *gamepad, SDL_
* \returns the SDL_GamepadButton enum corresponding to the input string, or
* `SDL_GAMEPAD_BUTTON_INVALID` if no match was found.
*
* \since This function is available since SDL 3.0.0.
* \since This function is available since SDL 3.2.0.
*
* \sa SDL_GetGamepadStringForButton
*/
@ -1155,7 +1194,7 @@ extern SDL_DECLSPEC SDL_GamepadButton SDLCALL SDL_GetGamepadButtonFromString(con
* specified. The string returned is of the format used by
* SDL_Gamepad mapping strings.
*
* \since This function is available since SDL 3.0.0.
* \since This function is available since SDL 3.2.0.
*
* \sa SDL_GetGamepadButtonFromString
*/
@ -1169,28 +1208,27 @@ extern SDL_DECLSPEC const char * SDLCALL SDL_GetGamepadStringForButton(SDL_Gamep
*
* \param gamepad a gamepad.
* \param button a button enum value (an SDL_GamepadButton value).
* \returns SDL_TRUE if the gamepad has this button, SDL_FALSE otherwise.
* \returns true if the gamepad has this button, false otherwise.
*
* \since This function is available since SDL 3.0.0.
* \since This function is available since SDL 3.2.0.
*
* \sa SDL_GamepadHasAxis
*/
extern SDL_DECLSPEC SDL_bool SDLCALL SDL_GamepadHasButton(SDL_Gamepad *gamepad, SDL_GamepadButton button);
extern SDL_DECLSPEC bool SDLCALL SDL_GamepadHasButton(SDL_Gamepad *gamepad, SDL_GamepadButton button);
/**
* Get the current state of a button on a gamepad.
*
* \param gamepad a gamepad.
* \param button a button index (one of the SDL_GamepadButton values).
* \returns 1 for pressed state or 0 for not pressed state or failure; call
* SDL_GetError() for more information.
* \returns true if the button is pressed, false otherwise.
*
* \since This function is available since SDL 3.0.0.
* \since This function is available since SDL 3.2.0.
*
* \sa SDL_GamepadHasButton
* \sa SDL_GetGamepadAxis
*/
extern SDL_DECLSPEC Uint8 SDLCALL SDL_GetGamepadButton(SDL_Gamepad *gamepad, SDL_GamepadButton button);
extern SDL_DECLSPEC bool SDLCALL SDL_GetGamepadButton(SDL_Gamepad *gamepad, SDL_GamepadButton button);
/**
* Get the label of a button on a gamepad.
@ -1199,7 +1237,7 @@ extern SDL_DECLSPEC Uint8 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.
*
* \since This function is available since SDL 3.0.0.
* \since This function is available since SDL 3.2.0.
*
* \sa SDL_GetGamepadButtonLabel
*/
@ -1212,7 +1250,7 @@ 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.
*
* \since This function is available since SDL 3.0.0.
* \since This function is available since SDL 3.2.0.
*
* \sa SDL_GetGamepadButtonLabelForType
*/
@ -1224,7 +1262,7 @@ extern SDL_DECLSPEC SDL_GamepadButtonLabel SDLCALL SDL_GetGamepadButtonLabel(SDL
* \param gamepad a gamepad.
* \returns number of touchpads.
*
* \since This function is available since SDL 3.0.0.
* \since This function is available since SDL 3.2.0.
*
* \sa SDL_GetNumGamepadTouchpadFingers
*/
@ -1238,7 +1276,7 @@ extern SDL_DECLSPEC int SDLCALL SDL_GetNumGamepadTouchpads(SDL_Gamepad *gamepad)
* \param touchpad a touchpad.
* \returns number of supported simultaneous fingers.
*
* \since This function is available since SDL 3.0.0.
* \since This function is available since SDL 3.2.0.
*
* \sa SDL_GetGamepadTouchpadFinger
* \sa SDL_GetNumGamepadTouchpads
@ -1251,35 +1289,36 @@ extern SDL_DECLSPEC int SDLCALL SDL_GetNumGamepadTouchpadFingers(SDL_Gamepad *ga
* \param gamepad a gamepad.
* \param touchpad a touchpad.
* \param finger a finger.
* \param state filled with state.
* \param x filled with x position, normalized 0 to 1, with the origin in the
* upper left.
* \param y filled with y position, normalized 0 to 1, with the origin in the
* upper left.
* \param pressure filled with pressure value.
* \returns SDL_TRUE on success or SDL_FALSE on failure; call SDL_GetError()
* for more information.
* \param down a pointer filled with true if the finger is down, false
* otherwise, may be NULL.
* \param x a pointer filled with the x position, normalized 0 to 1, with the
* origin in the upper left, may be NULL.
* \param y a pointer filled with the y position, normalized 0 to 1, with the
* origin in the upper left, may be NULL.
* \param pressure a pointer filled with pressure value, may be NULL.
* \returns true on success or false on failure; call SDL_GetError() for more
* information.
*
* \since This function is available since SDL 3.0.0.
* \since This function is available since SDL 3.2.0.
*
* \sa SDL_GetNumGamepadTouchpadFingers
*/
extern SDL_DECLSPEC SDL_bool SDLCALL SDL_GetGamepadTouchpadFinger(SDL_Gamepad *gamepad, int touchpad, int finger, Uint8 *state, float *x, float *y, float *pressure);
extern SDL_DECLSPEC bool SDLCALL SDL_GetGamepadTouchpadFinger(SDL_Gamepad *gamepad, int touchpad, int finger, bool *down, float *x, float *y, float *pressure);
/**
* Return whether a gamepad has a particular sensor.
*
* \param gamepad the gamepad to query.
* \param type the type of sensor to query.
* \returns SDL_TRUE if the sensor exists, SDL_FALSE otherwise.
* \returns true if the sensor exists, false otherwise.
*
* \since This function is available since SDL 3.0.0.
* \since This function is available since SDL 3.2.0.
*
* \sa SDL_GetGamepadSensorData
* \sa SDL_GetGamepadSensorDataRate
* \sa SDL_SetGamepadSensorEnabled
*/
extern SDL_DECLSPEC SDL_bool SDLCALL SDL_GamepadHasSensor(SDL_Gamepad *gamepad, SDL_SensorType type);
extern SDL_DECLSPEC bool SDLCALL SDL_GamepadHasSensor(SDL_Gamepad *gamepad, SDL_SensorType type);
/**
* Set whether data reporting for a gamepad sensor is enabled.
@ -1287,28 +1326,28 @@ extern SDL_DECLSPEC SDL_bool SDLCALL SDL_GamepadHasSensor(SDL_Gamepad *gamepad,
* \param gamepad the gamepad to update.
* \param type the type of sensor to enable/disable.
* \param enabled whether data reporting should be enabled.
* \returns SDL_TRUE on success or SDL_FALSE on failure; call SDL_GetError()
* for more information.
* \returns true on success or false on failure; call SDL_GetError() for more
* information.
*
* \since This function is available since SDL 3.0.0.
* \since This function is available since SDL 3.2.0.
*
* \sa SDL_GamepadHasSensor
* \sa SDL_GamepadSensorEnabled
*/
extern SDL_DECLSPEC SDL_bool SDLCALL SDL_SetGamepadSensorEnabled(SDL_Gamepad *gamepad, SDL_SensorType type, SDL_bool enabled);
extern SDL_DECLSPEC bool SDLCALL SDL_SetGamepadSensorEnabled(SDL_Gamepad *gamepad, SDL_SensorType type, bool enabled);
/**
* Query whether sensor data reporting is enabled for a gamepad.
*
* \param gamepad the gamepad to query.
* \param type the type of sensor to query.
* \returns SDL_TRUE if the sensor is enabled, SDL_FALSE otherwise.
* \returns true if the sensor is enabled, false otherwise.
*
* \since This function is available since SDL 3.0.0.
* \since This function is available since SDL 3.2.0.
*
* \sa SDL_SetGamepadSensorEnabled
*/
extern SDL_DECLSPEC SDL_bool SDLCALL SDL_GamepadSensorEnabled(SDL_Gamepad *gamepad, SDL_SensorType type);
extern SDL_DECLSPEC bool SDLCALL SDL_GamepadSensorEnabled(SDL_Gamepad *gamepad, SDL_SensorType type);
/**
* Get the data rate (number of events per second) of a gamepad sensor.
@ -1317,7 +1356,7 @@ extern SDL_DECLSPEC SDL_bool SDLCALL SDL_GamepadSensorEnabled(SDL_Gamepad *gamep
* \param type the type of sensor to query.
* \returns the data rate, or 0.0f if the data rate is not available.
*
* \since This function is available since SDL 3.0.0.
* \since This function is available since SDL 3.2.0.
*/
extern SDL_DECLSPEC float SDLCALL SDL_GetGamepadSensorDataRate(SDL_Gamepad *gamepad, SDL_SensorType type);
@ -1331,12 +1370,12 @@ extern SDL_DECLSPEC float SDLCALL SDL_GetGamepadSensorDataRate(SDL_Gamepad *game
* \param type the type of sensor to query.
* \param data a pointer filled with the current sensor state.
* \param num_values the number of values to write to data.
* \returns SDL_TRUE on success or SDL_FALSE on failure; call SDL_GetError()
* for more information.
* \returns true on success or false on failure; call SDL_GetError() for more
* information.
*
* \since This function is available since SDL 3.0.0.
* \since This function is available since SDL 3.2.0.
*/
extern SDL_DECLSPEC SDL_bool SDLCALL SDL_GetGamepadSensorData(SDL_Gamepad *gamepad, SDL_SensorType type, float *data, int num_values);
extern SDL_DECLSPEC bool SDLCALL SDL_GetGamepadSensorData(SDL_Gamepad *gamepad, SDL_SensorType type, float *data, int num_values);
/**
* Start a rumble effect on a gamepad.
@ -1353,12 +1392,12 @@ extern SDL_DECLSPEC SDL_bool SDLCALL SDL_GetGamepadSensorData(SDL_Gamepad *gamep
* \param high_frequency_rumble the intensity of the high frequency (right)
* rumble motor, from 0 to 0xFFFF.
* \param duration_ms the duration of the rumble effect, in milliseconds.
* \returns SDL_TRUE on success or SDL_FALSE on failure; call SDL_GetError()
* for more information.
* \returns true on success or false on failure; call SDL_GetError() for more
* information.
*
* \since This function is available since SDL 3.0.0.
* \since This function is available since SDL 3.2.0.
*/
extern SDL_DECLSPEC SDL_bool SDLCALL SDL_RumbleGamepad(SDL_Gamepad *gamepad, Uint16 low_frequency_rumble, Uint16 high_frequency_rumble, Uint32 duration_ms);
extern SDL_DECLSPEC bool SDLCALL SDL_RumbleGamepad(SDL_Gamepad *gamepad, Uint16 low_frequency_rumble, Uint16 high_frequency_rumble, Uint32 duration_ms);
/**
* Start a rumble effect in the gamepad's triggers.
@ -1379,14 +1418,14 @@ extern SDL_DECLSPEC SDL_bool SDLCALL SDL_RumbleGamepad(SDL_Gamepad *gamepad, Uin
* \param right_rumble the intensity of the right trigger rumble motor, from 0
* to 0xFFFF.
* \param duration_ms the duration of the rumble effect, in milliseconds.
* \returns SDL_TRUE on success or SDL_FALSE on failure; call SDL_GetError()
* for more information.
* \returns true on success or false on failure; call SDL_GetError() for more
* information.
*
* \since This function is available since SDL 3.0.0.
* \since This function is available since SDL 3.2.0.
*
* \sa SDL_RumbleGamepad
*/
extern SDL_DECLSPEC SDL_bool SDLCALL SDL_RumbleGamepadTriggers(SDL_Gamepad *gamepad, Uint16 left_rumble, Uint16 right_rumble, Uint32 duration_ms);
extern SDL_DECLSPEC bool SDLCALL SDL_RumbleGamepadTriggers(SDL_Gamepad *gamepad, Uint16 left_rumble, Uint16 right_rumble, Uint32 duration_ms);
/**
* Update a gamepad's LED color.
@ -1401,12 +1440,12 @@ extern SDL_DECLSPEC SDL_bool SDLCALL SDL_RumbleGamepadTriggers(SDL_Gamepad *game
* \param red the intensity of the red LED.
* \param green the intensity of the green LED.
* \param blue the intensity of the blue LED.
* \returns SDL_TRUE on success or SDL_FALSE on failure; call SDL_GetError()
* for more information.
* \returns true on success or false on failure; call SDL_GetError() for more
* information.
*
* \since This function is available since SDL 3.0.0.
* \since This function is available since SDL 3.2.0.
*/
extern SDL_DECLSPEC SDL_bool SDLCALL SDL_SetGamepadLED(SDL_Gamepad *gamepad, Uint8 red, Uint8 green, Uint8 blue);
extern SDL_DECLSPEC bool SDLCALL SDL_SetGamepadLED(SDL_Gamepad *gamepad, Uint8 red, Uint8 green, Uint8 blue);
/**
* Send a gamepad specific effect packet.
@ -1414,12 +1453,12 @@ extern SDL_DECLSPEC SDL_bool SDLCALL SDL_SetGamepadLED(SDL_Gamepad *gamepad, Uin
* \param gamepad the gamepad to affect.
* \param data the data to send to the gamepad.
* \param size the size of the data to send to the gamepad.
* \returns SDL_TRUE on success or SDL_FALSE on failure; call SDL_GetError()
* for more information.
* \returns true on success or false on failure; call SDL_GetError() for more
* information.
*
* \since This function is available since SDL 3.0.0.
* \since This function is available since SDL 3.2.0.
*/
extern SDL_DECLSPEC SDL_bool SDLCALL SDL_SendGamepadEffect(SDL_Gamepad *gamepad, const void *data, int size);
extern SDL_DECLSPEC bool SDLCALL SDL_SendGamepadEffect(SDL_Gamepad *gamepad, const void *data, int size);
/**
* Close a gamepad previously opened with SDL_OpenGamepad().
@ -1427,7 +1466,7 @@ extern SDL_DECLSPEC SDL_bool SDLCALL SDL_SendGamepadEffect(SDL_Gamepad *gamepad,
* \param gamepad a gamepad identifier previously returned by
* SDL_OpenGamepad().
*
* \since This function is available since SDL 3.0.0.
* \since This function is available since SDL 3.2.0.
*
* \sa SDL_OpenGamepad
*/
@ -1441,7 +1480,7 @@ 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.
*
* \since This function is available since SDL 3.0.0.
* \since This function is available since SDL 3.2.0.
*
* \sa SDL_GetGamepadAppleSFSymbolsNameForAxis
*/
@ -1454,7 +1493,7 @@ 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.
*
* \since This function is available since SDL 3.0.0.
* \since This function is available since SDL 3.2.0.
*
* \sa SDL_GetGamepadAppleSFSymbolsNameForButton
*/

File diff suppressed because it is too large Load Diff

View File

@ -1,6 +1,6 @@
/*
Simple DirectMedia Layer
Copyright (C) 1997-2024 Sam Lantinga <slouken@libsdl.org>
Copyright (C) 1997-2025 Sam Lantinga <slouken@libsdl.org>
This software is provided 'as-is', without any express or implied
warranty. In no event will the authors be held liable for any damages
@ -26,13 +26,14 @@
*
* A GUID is a 128-bit value that represents something that is uniquely
* identifiable by this value: "globally unique."
*
* SDL provides functions to convert a GUID to/from a string.
*/
#ifndef SDL_guid_h_
#define SDL_guid_h_
#include <SDL3/SDL_stdinc.h>
#include <SDL3/SDL_error.h>
#include <SDL3/SDL_begin_code.h>
/* Set up for C function definitions, even when using C++ */
@ -55,7 +56,7 @@ extern "C" {
* GUIDs may be platform-dependent (i.e., the same device may report different
* GUIDs on different operating systems).
*
* \since This struct is available since SDL 3.0.0.
* \since This struct is available since SDL 3.2.0.
*/
typedef struct SDL_GUID {
Uint8 data[16];
@ -70,7 +71,7 @@ typedef struct SDL_GUID {
* \param pszGUID buffer in which to write the ASCII string.
* \param cbGUID the size of pszGUID, should be at least 33 bytes.
*
* \since This function is available since SDL 3.0.0.
* \since This function is available since SDL 3.2.0.
*
* \sa SDL_StringToGUID
*/
@ -86,7 +87,7 @@ extern SDL_DECLSPEC void SDLCALL SDL_GUIDToString(SDL_GUID guid, char *pszGUID,
* \param pchGUID string containing an ASCII representation of a GUID.
* \returns a SDL_GUID structure.
*
* \since This function is available since SDL 3.0.0.
* \since This function is available since SDL 3.2.0.
*
* \sa SDL_GUIDToString
*/

View File

@ -1,6 +1,6 @@
/*
Simple DirectMedia Layer
Copyright (C) 1997-2024 Sam Lantinga <slouken@libsdl.org>
Copyright (C) 1997-2025 Sam Lantinga <slouken@libsdl.org>
This software is provided 'as-is', without any express or implied
warranty. In no event will the authors be held liable for any damages
@ -66,7 +66,7 @@
* Complete example:
*
* ```c
* SDL_bool test_haptic(SDL_Joystick *joystick)
* bool test_haptic(SDL_Joystick *joystick)
* {
* SDL_Haptic *haptic;
* SDL_HapticEffect effect;
@ -74,12 +74,12 @@
*
* // Open the device
* haptic = SDL_OpenHapticFromJoystick(joystick);
* if (haptic == NULL) return SDL_FALSE; // Most likely joystick isn't haptic
* if (haptic == NULL) return false; // Most likely joystick isn't haptic
*
* // See if it can do sine waves
* if ((SDL_GetHapticFeatures(haptic) & SDL_HAPTIC_SINE)==0) {
* SDL_CloseHaptic(haptic); // No sine effect
* return SDL_FALSE;
* return false;
* }
*
* // Create the effect
@ -106,7 +106,7 @@
* // Close the device
* SDL_CloseHaptic(haptic);
*
* return SDL_TRUE; // Success
* return true; // Success
* }
* ```
*
@ -139,15 +139,14 @@ extern "C" {
*/
/**
* \typedef SDL_Haptic
* The haptic structure used to identify an SDL haptic.
*
* The haptic structure used to identify an SDL haptic.
* \since This struct is available since SDL 3.2.0.
*
* \sa SDL_OpenHaptic
* \sa SDL_OpenHapticFromJoystick
* \sa SDL_CloseHaptic
* \sa SDL_OpenHaptic
* \sa SDL_OpenHapticFromJoystick
* \sa SDL_CloseHaptic
*/
struct SDL_Haptic;
typedef struct SDL_Haptic SDL_Haptic;
@ -168,7 +167,7 @@ typedef struct SDL_Haptic SDL_Haptic;
*
* Constant haptic effect.
*
* \since This macro is available since SDL 3.0.0.
* \since This macro is available since SDL 3.2.0.
*
* \sa SDL_HapticCondition
*/
@ -179,7 +178,7 @@ typedef struct SDL_Haptic SDL_Haptic;
*
* Periodic haptic effect that simulates sine waves.
*
* \since This macro is available since SDL 3.0.0.
* \since This macro is available since SDL 3.2.0.
*
* \sa SDL_HapticPeriodic
*/
@ -190,7 +189,7 @@ typedef struct SDL_Haptic SDL_Haptic;
*
* Periodic haptic effect that simulates square waves.
*
* \since This macro is available since SDL 3.0.0.
* \since This macro is available since SDL 3.2.0.
*
* \sa SDL_HapticPeriodic
*/
@ -201,7 +200,7 @@ typedef struct SDL_Haptic SDL_Haptic;
*
* Periodic haptic effect that simulates triangular waves.
*
* \since This macro is available since SDL 3.0.0.
* \since This macro is available since SDL 3.2.0.
*
* \sa SDL_HapticPeriodic
*/
@ -212,7 +211,7 @@ typedef struct SDL_Haptic SDL_Haptic;
*
* Periodic haptic effect that simulates saw tooth up waves.
*
* \since This macro is available since SDL 3.0.0.
* \since This macro is available since SDL 3.2.0.
*
* \sa SDL_HapticPeriodic
*/
@ -223,7 +222,7 @@ typedef struct SDL_Haptic SDL_Haptic;
*
* Periodic haptic effect that simulates saw tooth down waves.
*
* \since This macro is available since SDL 3.0.0.
* \since This macro is available since SDL 3.2.0.
*
* \sa SDL_HapticPeriodic
*/
@ -234,7 +233,7 @@ typedef struct SDL_Haptic SDL_Haptic;
*
* Ramp haptic effect.
*
* \since This macro is available since SDL 3.0.0.
* \since This macro is available since SDL 3.2.0.
*
* \sa SDL_HapticRamp
*/
@ -246,7 +245,7 @@ typedef struct SDL_Haptic SDL_Haptic;
* Condition haptic effect that simulates a spring. Effect is based on the
* axes position.
*
* \since This macro is available since SDL 3.0.0.
* \since This macro is available since SDL 3.2.0.
*
* \sa SDL_HapticCondition
*/
@ -258,7 +257,7 @@ typedef struct SDL_Haptic SDL_Haptic;
* Condition haptic effect that simulates dampening. Effect is based on the
* axes velocity.
*
* \since This macro is available since SDL 3.0.0.
* \since This macro is available since SDL 3.2.0.
*
* \sa SDL_HapticCondition
*/
@ -270,7 +269,7 @@ typedef struct SDL_Haptic SDL_Haptic;
* Condition haptic effect that simulates inertia. Effect is based on the axes
* acceleration.
*
* \since This macro is available since SDL 3.0.0.
* \since This macro is available since SDL 3.2.0.
*
* \sa SDL_HapticCondition
*/
@ -282,7 +281,7 @@ typedef struct SDL_Haptic SDL_Haptic;
* Condition haptic effect that simulates friction. Effect is based on the
* axes movement.
*
* \since This macro is available since SDL 3.0.0.
* \since This macro is available since SDL 3.2.0.
*
* \sa SDL_HapticCondition
*/
@ -293,19 +292,31 @@ typedef struct SDL_Haptic SDL_Haptic;
*
* Haptic effect for direct control over high/low frequency motors.
*
* \since This macro is available since SDL 3.0.0.
* \since This macro is available since SDL 3.2.0.
*
* \sa SDL_HapticLeftRight
*/
#define SDL_HAPTIC_LEFTRIGHT (1u<<11)
/**
* Reserved for future use
* Reserved for future use.
*
* \since This macro is available since SDL 3.0.0.
* \since This macro is available since SDL 3.2.0.
*/
#define SDL_HAPTIC_RESERVED1 (1u<<12)
/**
* Reserved for future use.
*
* \since This macro is available since SDL 3.2.0.
*/
#define SDL_HAPTIC_RESERVED2 (1u<<13)
/**
* Reserved for future use.
*
* \since This macro is available since SDL 3.2.0.
*/
#define SDL_HAPTIC_RESERVED3 (1u<<14)
/**
@ -313,7 +324,7 @@ typedef struct SDL_Haptic SDL_Haptic;
*
* User defined custom haptic effect.
*
* \since This macro is available since SDL 3.0.0.
* \since This macro is available since SDL 3.2.0.
*/
#define SDL_HAPTIC_CUSTOM (1u<<15)
@ -326,7 +337,7 @@ typedef struct SDL_Haptic SDL_Haptic;
*
* Device supports setting the global gain.
*
* \since This macro is available since SDL 3.0.0.
* \since This macro is available since SDL 3.2.0.
*
* \sa SDL_SetHapticGain
*/
@ -337,7 +348,7 @@ typedef struct SDL_Haptic SDL_Haptic;
*
* Device supports setting autocenter.
*
* \since This macro is available since SDL 3.0.0.
* \since This macro is available since SDL 3.2.0.
*
* \sa SDL_SetHapticAutocenter
*/
@ -348,7 +359,7 @@ typedef struct SDL_Haptic SDL_Haptic;
*
* Device supports querying effect status.
*
* \since This macro is available since SDL 3.0.0.
* \since This macro is available since SDL 3.2.0.
*
* \sa SDL_GetHapticEffectStatus
*/
@ -359,7 +370,7 @@ typedef struct SDL_Haptic SDL_Haptic;
*
* Devices supports being paused.
*
* \since This macro is available since SDL 3.0.0.
* \since This macro is available since SDL 3.2.0.
*
* \sa SDL_PauseHaptic
* \sa SDL_ResumeHaptic
@ -375,7 +386,7 @@ typedef struct SDL_Haptic SDL_Haptic;
/**
* Uses polar coordinates for the direction.
*
* \since This macro is available since SDL 3.0.0.
* \since This macro is available since SDL 3.2.0.
*
* \sa SDL_HapticDirection
*/
@ -384,7 +395,7 @@ typedef struct SDL_Haptic SDL_Haptic;
/**
* Uses cartesian coordinates for the direction.
*
* \since This macro is available since SDL 3.0.0.
* \since This macro is available since SDL 3.2.0.
*
* \sa SDL_HapticDirection
*/
@ -393,7 +404,7 @@ typedef struct SDL_Haptic SDL_Haptic;
/**
* Uses spherical coordinates for the direction.
*
* \since This macro is available since SDL 3.0.0.
* \since This macro is available since SDL 3.2.0.
*
* \sa SDL_HapticDirection
*/
@ -405,7 +416,7 @@ typedef struct SDL_Haptic SDL_Haptic;
* This provides better compatibility across platforms and devices as SDL will
* guess the correct axis.
*
* \since This macro is available since SDL 3.0.0.
* \since This macro is available since SDL 3.2.0.
*
* \sa SDL_HapticDirection
*/
@ -422,7 +433,7 @@ typedef struct SDL_Haptic SDL_Haptic;
/**
* Used to play a device an infinite number of times.
*
* \since This macro is available since SDL 3.0.0.
* \since This macro is available since SDL 3.2.0.
*
* \sa SDL_RunHapticEffect
*/
@ -523,7 +534,7 @@ typedef struct SDL_Haptic SDL_Haptic;
* direction.dir[0] = 9000; // Since we only have two axes we don't need more parameters.
* ```
*
* \since This struct is available since SDL 3.0.0.
* \since This struct is available since SDL 3.2.0.
*
* \sa SDL_HAPTIC_POLAR
* \sa SDL_HAPTIC_CARTESIAN
@ -547,7 +558,7 @@ typedef struct SDL_HapticDirection
* A constant effect applies a constant force in the specified direction to
* the joystick.
*
* \since This struct is available since SDL 3.0.0.
* \since This struct is available since SDL 3.2.0.
*
* \sa SDL_HAPTIC_CONSTANT
* \sa SDL_HapticEffect
@ -629,7 +640,7 @@ typedef struct SDL_HapticConstant
* \| \| \| \| \| \| \|
* ```
*
* \since This struct is available since SDL 3.0.0.
* \since This struct is available since SDL 3.2.0.
*
* \sa SDL_HAPTIC_SINE
* \sa SDL_HAPTIC_SQUARE
@ -685,7 +696,7 @@ typedef struct SDL_HapticPeriodic
* SDL_HapticDirection diagram for which side is positive and which is
* negative.
*
* \since This struct is available since SDL 3.0.0.
* \since This struct is available since SDL 3.2.0.
*
* \sa SDL_HapticDirection
* \sa SDL_HAPTIC_SPRING
@ -699,7 +710,7 @@ typedef struct SDL_HapticCondition
/* Header */
Uint16 type; /**< SDL_HAPTIC_SPRING, SDL_HAPTIC_DAMPER,
SDL_HAPTIC_INERTIA or SDL_HAPTIC_FRICTION */
SDL_HapticDirection direction; /**< Direction of the effect - Not used ATM. */
SDL_HapticDirection direction; /**< Direction of the effect. */
/* Replay */
Uint32 length; /**< Duration of the effect. */
@ -728,7 +739,7 @@ typedef struct SDL_HapticCondition
* effects get added to the ramp effect making the effect become quadratic
* instead of linear.
*
* \since This struct is available since SDL 3.0.0.
* \since This struct is available since SDL 3.2.0.
*
* \sa SDL_HAPTIC_RAMP
* \sa SDL_HapticEffect
@ -767,7 +778,7 @@ typedef struct SDL_HapticRamp
* motors, commonly found in modern game controllers. The small (right) motor
* is high frequency, and the large (left) motor is low frequency.
*
* \since This struct is available since SDL 3.0.0.
* \since This struct is available since SDL 3.2.0.
*
* \sa SDL_HAPTIC_LEFTRIGHT
* \sa SDL_HapticEffect
@ -797,7 +808,7 @@ typedef struct SDL_HapticLeftRight
* If channels is one, the effect is rotated using the defined direction.
* Otherwise it uses the samples in data for the different axes.
*
* \since This struct is available since SDL 3.0.0.
* \since This struct is available since SDL 3.2.0.
*
* \sa SDL_HAPTIC_CUSTOM
* \sa SDL_HapticEffect
@ -892,7 +903,7 @@ typedef struct SDL_HapticCustom
* Note either the attack_level or the fade_level may be above the actual
* effect level.
*
* \since This struct is available since SDL 3.0.0.
* \since This struct is available since SDL 3.2.0.
*
* \sa SDL_HapticConstant
* \sa SDL_HapticPeriodic
@ -921,7 +932,7 @@ typedef union SDL_HapticEffect
*
* The value 0 is an invalid ID.
*
* \since This datatype is available since SDL 3.0.0.
* \since This datatype is available since SDL 3.2.0.
*/
typedef Uint32 SDL_HapticID;
@ -937,7 +948,7 @@ typedef Uint32 SDL_HapticID;
* failure; call SDL_GetError() for more information. This should be
* freed with SDL_free() when it is no longer needed.
*
* \since This function is available since SDL 3.0.0.
* \since This function is available since SDL 3.2.0.
*
* \sa SDL_OpenHaptic
*/
@ -953,7 +964,7 @@ extern SDL_DECLSPEC SDL_HapticID * SDLCALL SDL_GetHaptics(int *count);
* this function returns NULL; call SDL_GetError() for more
* information.
*
* \since This function is available since SDL 3.0.0.
* \since This function is available since SDL 3.2.0.
*
* \sa SDL_GetHapticName
* \sa SDL_OpenHaptic
@ -974,7 +985,7 @@ extern SDL_DECLSPEC const char * SDLCALL SDL_GetHapticNameForID(SDL_HapticID ins
* \returns the device identifier or NULL on failure; call SDL_GetError() for
* more information.
*
* \since This function is available since SDL 3.0.0.
* \since This function is available since SDL 3.2.0.
*
* \sa SDL_CloseHaptic
* \sa SDL_GetHaptics
@ -993,7 +1004,7 @@ extern SDL_DECLSPEC SDL_Haptic * SDLCALL SDL_OpenHaptic(SDL_HapticID instance_id
* \returns an SDL_Haptic on success or NULL on failure or if it hasn't been
* opened yet; call SDL_GetError() for more information.
*
* \since This function is available since SDL 3.0.0.
* \since This function is available since SDL 3.2.0.
*/
extern SDL_DECLSPEC SDL_Haptic * SDLCALL SDL_GetHapticFromID(SDL_HapticID instance_id);
@ -1004,7 +1015,7 @@ extern SDL_DECLSPEC SDL_Haptic * SDLCALL SDL_GetHapticFromID(SDL_HapticID instan
* \returns the instance ID of the specified haptic device on success or 0 on
* failure; call SDL_GetError() for more information.
*
* \since This function is available since SDL 3.0.0.
* \since This function is available since SDL 3.2.0.
*/
extern SDL_DECLSPEC SDL_HapticID SDLCALL SDL_GetHapticID(SDL_Haptic *haptic);
@ -1016,7 +1027,7 @@ extern SDL_DECLSPEC SDL_HapticID SDLCALL SDL_GetHapticID(SDL_Haptic *haptic);
* this function returns NULL; call SDL_GetError() for more
* information.
*
* \since This function is available since SDL 3.0.0.
* \since This function is available since SDL 3.2.0.
*
* \sa SDL_GetHapticNameForID
*/
@ -1025,13 +1036,13 @@ extern SDL_DECLSPEC const char * SDLCALL SDL_GetHapticName(SDL_Haptic *haptic);
/**
* Query whether or not the current mouse has haptic capabilities.
*
* \returns SDL_TRUE if the mouse is haptic or SDL_FALSE if it isn't.
* \returns true if the mouse is haptic or false if it isn't.
*
* \since This function is available since SDL 3.0.0.
* \since This function is available since SDL 3.2.0.
*
* \sa SDL_OpenHapticFromMouse
*/
extern SDL_DECLSPEC SDL_bool SDLCALL SDL_IsMouseHaptic(void);
extern SDL_DECLSPEC bool SDLCALL SDL_IsMouseHaptic(void);
/**
* Try to open a haptic device from the current mouse.
@ -1039,7 +1050,7 @@ extern SDL_DECLSPEC SDL_bool SDLCALL SDL_IsMouseHaptic(void);
* \returns the haptic device identifier or NULL on failure; call
* SDL_GetError() for more information.
*
* \since This function is available since SDL 3.0.0.
* \since This function is available since SDL 3.2.0.
*
* \sa SDL_CloseHaptic
* \sa SDL_IsMouseHaptic
@ -1050,13 +1061,13 @@ extern SDL_DECLSPEC SDL_Haptic * SDLCALL SDL_OpenHapticFromMouse(void);
* Query if a joystick has haptic features.
*
* \param joystick the SDL_Joystick to test for haptic capabilities.
* \returns SDL_TRUE if the joystick is haptic or SDL_FALSE if it isn't.
* \returns true if the joystick is haptic or false if it isn't.
*
* \since This function is available since SDL 3.0.0.
* \since This function is available since SDL 3.2.0.
*
* \sa SDL_OpenHapticFromJoystick
*/
extern SDL_DECLSPEC SDL_bool SDLCALL SDL_IsJoystickHaptic(SDL_Joystick *joystick);
extern SDL_DECLSPEC bool SDLCALL SDL_IsJoystickHaptic(SDL_Joystick *joystick);
/**
* Open a haptic device for use from a joystick device.
@ -1073,7 +1084,7 @@ extern SDL_DECLSPEC SDL_bool SDLCALL SDL_IsJoystickHaptic(SDL_Joystick *joystick
* \returns a valid haptic device identifier on success or NULL on failure;
* call SDL_GetError() for more information.
*
* \since This function is available since SDL 3.0.0.
* \since This function is available since SDL 3.2.0.
*
* \sa SDL_CloseHaptic
* \sa SDL_IsJoystickHaptic
@ -1085,7 +1096,7 @@ extern SDL_DECLSPEC SDL_Haptic * SDLCALL SDL_OpenHapticFromJoystick(SDL_Joystick
*
* \param haptic the SDL_Haptic device to close.
*
* \since This function is available since SDL 3.0.0.
* \since This function is available since SDL 3.2.0.
*
* \sa SDL_OpenHaptic
*/
@ -1102,7 +1113,7 @@ extern SDL_DECLSPEC void SDLCALL SDL_CloseHaptic(SDL_Haptic *haptic);
* \returns the number of effects the haptic device can store or a negative
* error code on failure; call SDL_GetError() for more information.
*
* \since This function is available since SDL 3.0.0.
* \since This function is available since SDL 3.2.0.
*
* \sa SDL_GetMaxHapticEffectsPlaying
* \sa SDL_GetHapticFeatures
@ -1118,7 +1129,7 @@ extern SDL_DECLSPEC int SDLCALL SDL_GetMaxHapticEffects(SDL_Haptic *haptic);
* \returns the number of effects the haptic device can play at the same time
* or -1 on failure; call SDL_GetError() for more information.
*
* \since This function is available since SDL 3.0.0.
* \since This function is available since SDL 3.2.0.
*
* \sa SDL_GetMaxHapticEffects
* \sa SDL_GetHapticFeatures
@ -1132,7 +1143,7 @@ extern SDL_DECLSPEC int SDLCALL SDL_GetMaxHapticEffectsPlaying(SDL_Haptic *hapti
* \returns a list of supported haptic features in bitwise manner (OR'd), or 0
* on failure; call SDL_GetError() for more information.
*
* \since This function is available since SDL 3.0.0.
* \since This function is available since SDL 3.2.0.
*
* \sa SDL_HapticEffectSupported
* \sa SDL_GetMaxHapticEffects
@ -1149,7 +1160,7 @@ extern SDL_DECLSPEC Uint32 SDLCALL SDL_GetHapticFeatures(SDL_Haptic *haptic);
* \returns the number of axes on success or -1 on failure; call
* SDL_GetError() for more information.
*
* \since This function is available since SDL 3.0.0.
* \since This function is available since SDL 3.2.0.
*/
extern SDL_DECLSPEC int SDLCALL SDL_GetNumHapticAxes(SDL_Haptic *haptic);
@ -1158,14 +1169,14 @@ extern SDL_DECLSPEC int SDLCALL SDL_GetNumHapticAxes(SDL_Haptic *haptic);
*
* \param haptic the SDL_Haptic device to query.
* \param effect the desired effect to query.
* \returns SDL_TRUE if the effect is supported or SDL_FALSE if it isn't.
* \returns true if the effect is supported or false if it isn't.
*
* \since This function is available since SDL 3.0.0.
* \since This function is available since SDL 3.2.0.
*
* \sa SDL_CreateHapticEffect
* \sa SDL_GetHapticFeatures
*/
extern SDL_DECLSPEC SDL_bool SDLCALL SDL_HapticEffectSupported(SDL_Haptic *haptic, const SDL_HapticEffect *effect);
extern SDL_DECLSPEC bool SDLCALL SDL_HapticEffectSupported(SDL_Haptic *haptic, const SDL_HapticEffect *effect);
/**
* Create a new haptic effect on a specified device.
@ -1176,7 +1187,7 @@ extern SDL_DECLSPEC SDL_bool SDLCALL SDL_HapticEffectSupported(SDL_Haptic *hapti
* \returns the ID of the effect on success or -1 on failure; call
* SDL_GetError() for more information.
*
* \since This function is available since SDL 3.0.0.
* \since This function is available since SDL 3.2.0.
*
* \sa SDL_DestroyHapticEffect
* \sa SDL_RunHapticEffect
@ -1196,15 +1207,15 @@ extern SDL_DECLSPEC int SDLCALL SDL_CreateHapticEffect(SDL_Haptic *haptic, const
* \param effect the identifier of the effect to update.
* \param data an SDL_HapticEffect structure containing the new effect
* properties to use.
* \returns SDL_TRUE on success or SDL_FALSE on failure; call SDL_GetError()
* for more information.
* \returns true on success or false on failure; call SDL_GetError() for more
* information.
*
* \since This function is available since SDL 3.0.0.
* \since This function is available since SDL 3.2.0.
*
* \sa SDL_CreateHapticEffect
* \sa SDL_RunHapticEffect
*/
extern SDL_DECLSPEC SDL_bool SDLCALL SDL_UpdateHapticEffect(SDL_Haptic *haptic, int effect, const SDL_HapticEffect *data);
extern SDL_DECLSPEC bool SDLCALL SDL_UpdateHapticEffect(SDL_Haptic *haptic, int effect, const SDL_HapticEffect *data);
/**
* Run the haptic effect on its associated haptic device.
@ -1219,31 +1230,31 @@ extern SDL_DECLSPEC SDL_bool SDLCALL SDL_UpdateHapticEffect(SDL_Haptic *haptic,
* \param effect the ID of the haptic effect to run.
* \param iterations the number of iterations to run the effect; use
* `SDL_HAPTIC_INFINITY` to repeat forever.
* \returns SDL_TRUE on success or SDL_FALSE on failure; call SDL_GetError()
* for more information.
* \returns true on success or false on failure; call SDL_GetError() for more
* information.
*
* \since This function is available since SDL 3.0.0.
* \since This function is available since SDL 3.2.0.
*
* \sa SDL_GetHapticEffectStatus
* \sa SDL_StopHapticEffect
* \sa SDL_StopHapticEffects
*/
extern SDL_DECLSPEC SDL_bool SDLCALL SDL_RunHapticEffect(SDL_Haptic *haptic, int effect, Uint32 iterations);
extern SDL_DECLSPEC bool SDLCALL SDL_RunHapticEffect(SDL_Haptic *haptic, int effect, Uint32 iterations);
/**
* Stop the haptic effect on its associated haptic device.
*
* \param haptic the SDL_Haptic device to stop the effect on.
* \param effect the ID of the haptic effect to stop.
* \returns SDL_TRUE on success or SDL_FALSE on failure; call SDL_GetError()
* for more information.
* \returns true on success or false on failure; call SDL_GetError() for more
* information.
*
* \since This function is available since SDL 3.0.0.
* \since This function is available since SDL 3.2.0.
*
* \sa SDL_RunHapticEffect
* \sa SDL_StopHapticEffects
*/
extern SDL_DECLSPEC SDL_bool SDLCALL SDL_StopHapticEffect(SDL_Haptic *haptic, int effect);
extern SDL_DECLSPEC bool SDLCALL SDL_StopHapticEffect(SDL_Haptic *haptic, int effect);
/**
* Destroy a haptic effect on the device.
@ -1254,7 +1265,7 @@ extern SDL_DECLSPEC SDL_bool SDLCALL SDL_StopHapticEffect(SDL_Haptic *haptic, in
* \param haptic the SDL_Haptic device to destroy the effect on.
* \param effect the ID of the haptic effect to destroy.
*
* \since This function is available since SDL 3.0.0.
* \since This function is available since SDL 3.2.0.
*
* \sa SDL_CreateHapticEffect
*/
@ -1267,14 +1278,14 @@ extern SDL_DECLSPEC void SDLCALL SDL_DestroyHapticEffect(SDL_Haptic *haptic, int
*
* \param haptic the SDL_Haptic device to query for the effect status on.
* \param effect the ID of the haptic effect to query its status.
* \returns SDL_TRUE if it is playing, SDL_FALSE if it isn't playing or haptic
* status isn't supported.
* \returns true if it is playing, false if it isn't playing or haptic status
* isn't supported.
*
* \since This function is available since SDL 3.0.0.
* \since This function is available since SDL 3.2.0.
*
* \sa SDL_GetHapticFeatures
*/
extern SDL_DECLSPEC SDL_bool SDLCALL SDL_GetHapticEffectStatus(SDL_Haptic *haptic, int effect);
extern SDL_DECLSPEC bool SDLCALL SDL_GetHapticEffectStatus(SDL_Haptic *haptic, int effect);
/**
* Set the global gain of the specified haptic device.
@ -1289,14 +1300,14 @@ extern SDL_DECLSPEC SDL_bool SDLCALL SDL_GetHapticEffectStatus(SDL_Haptic *hapti
* \param haptic the SDL_Haptic device to set the gain on.
* \param gain value to set the gain to, should be between 0 and 100 (0 -
* 100).
* \returns SDL_TRUE on success or SDL_FALSE on failure; call SDL_GetError()
* for more information.
* \returns true on success or false on failure; call SDL_GetError() for more
* information.
*
* \since This function is available since SDL 3.0.0.
* \since This function is available since SDL 3.2.0.
*
* \sa SDL_GetHapticFeatures
*/
extern SDL_DECLSPEC SDL_bool SDLCALL SDL_SetHapticGain(SDL_Haptic *haptic, int gain);
extern SDL_DECLSPEC bool SDLCALL SDL_SetHapticGain(SDL_Haptic *haptic, int gain);
/**
* Set the global autocenter of the device.
@ -1308,14 +1319,14 @@ extern SDL_DECLSPEC SDL_bool SDLCALL SDL_SetHapticGain(SDL_Haptic *haptic, int g
*
* \param haptic the SDL_Haptic device to set autocentering on.
* \param autocenter value to set autocenter to (0-100).
* \returns SDL_TRUE on success or SDL_FALSE on failure; call SDL_GetError()
* for more information.
* \returns true on success or false on failure; call SDL_GetError() for more
* information.
*
* \since This function is available since SDL 3.0.0.
* \since This function is available since SDL 3.2.0.
*
* \sa SDL_GetHapticFeatures
*/
extern SDL_DECLSPEC SDL_bool SDLCALL SDL_SetHapticAutocenter(SDL_Haptic *haptic, int autocenter);
extern SDL_DECLSPEC bool SDLCALL SDL_SetHapticAutocenter(SDL_Haptic *haptic, int autocenter);
/**
* Pause a haptic device.
@ -1327,14 +1338,14 @@ extern SDL_DECLSPEC SDL_bool SDLCALL SDL_SetHapticAutocenter(SDL_Haptic *haptic,
* can cause all sorts of weird errors.
*
* \param haptic the SDL_Haptic device to pause.
* \returns SDL_TRUE on success or SDL_FALSE on failure; call SDL_GetError()
* for more information.
* \returns true on success or false on failure; call SDL_GetError() for more
* information.
*
* \since This function is available since SDL 3.0.0.
* \since This function is available since SDL 3.2.0.
*
* \sa SDL_ResumeHaptic
*/
extern SDL_DECLSPEC SDL_bool SDLCALL SDL_PauseHaptic(SDL_Haptic *haptic);
extern SDL_DECLSPEC bool SDLCALL SDL_PauseHaptic(SDL_Haptic *haptic);
/**
* Resume a haptic device.
@ -1342,55 +1353,55 @@ extern SDL_DECLSPEC SDL_bool SDLCALL SDL_PauseHaptic(SDL_Haptic *haptic);
* Call to unpause after SDL_PauseHaptic().
*
* \param haptic the SDL_Haptic device to unpause.
* \returns SDL_TRUE on success or SDL_FALSE on failure; call SDL_GetError()
* for more information.
* \returns true on success or false on failure; call SDL_GetError() for more
* information.
*
* \since This function is available since SDL 3.0.0.
* \since This function is available since SDL 3.2.0.
*
* \sa SDL_PauseHaptic
*/
extern SDL_DECLSPEC SDL_bool SDLCALL SDL_ResumeHaptic(SDL_Haptic *haptic);
extern SDL_DECLSPEC bool SDLCALL SDL_ResumeHaptic(SDL_Haptic *haptic);
/**
* Stop all the currently playing effects on a haptic device.
*
* \param haptic the SDL_Haptic device to stop.
* \returns SDL_TRUE on success or SDL_FALSE on failure; call SDL_GetError()
* for more information.
* \returns true on success or false on failure; call SDL_GetError() for more
* information.
*
* \since This function is available since SDL 3.0.0.
* \since This function is available since SDL 3.2.0.
*
* \sa SDL_RunHapticEffect
* \sa SDL_StopHapticEffects
*/
extern SDL_DECLSPEC SDL_bool SDLCALL SDL_StopHapticEffects(SDL_Haptic *haptic);
extern SDL_DECLSPEC bool SDLCALL SDL_StopHapticEffects(SDL_Haptic *haptic);
/**
* Check whether rumble is supported on a haptic device.
*
* \param haptic haptic device to check for rumble support.
* \returns SDL_TRUE if the effect is supported or SDL_FALSE if it isn't.
* \returns true if the effect is supported or false if it isn't.
*
* \since This function is available since SDL 3.0.0.
* \since This function is available since SDL 3.2.0.
*
* \sa SDL_InitHapticRumble
*/
extern SDL_DECLSPEC SDL_bool SDLCALL SDL_HapticRumbleSupported(SDL_Haptic *haptic);
extern SDL_DECLSPEC bool SDLCALL SDL_HapticRumbleSupported(SDL_Haptic *haptic);
/**
* Initialize a haptic device for simple rumble playback.
*
* \param haptic the haptic device to initialize for simple rumble playback.
* \returns SDL_TRUE on success or SDL_FALSE on failure; call SDL_GetError()
* for more information.
* \returns true on success or false on failure; call SDL_GetError() for more
* information.
*
* \since This function is available since SDL 3.0.0.
* \since This function is available since SDL 3.2.0.
*
* \sa SDL_PlayHapticRumble
* \sa SDL_StopHapticRumble
* \sa SDL_HapticRumbleSupported
*/
extern SDL_DECLSPEC SDL_bool SDLCALL SDL_InitHapticRumble(SDL_Haptic *haptic);
extern SDL_DECLSPEC bool SDLCALL SDL_InitHapticRumble(SDL_Haptic *haptic);
/**
* Run a simple rumble effect on a haptic device.
@ -1398,28 +1409,28 @@ extern SDL_DECLSPEC SDL_bool SDLCALL SDL_InitHapticRumble(SDL_Haptic *haptic);
* \param haptic the haptic device to play the rumble effect on.
* \param strength strength of the rumble to play as a 0-1 float value.
* \param length length of the rumble to play in milliseconds.
* \returns SDL_TRUE on success or SDL_FALSE on failure; call SDL_GetError()
* for more information.
* \returns true on success or false on failure; call SDL_GetError() for more
* information.
*
* \since This function is available since SDL 3.0.0.
* \since This function is available since SDL 3.2.0.
*
* \sa SDL_InitHapticRumble
* \sa SDL_StopHapticRumble
*/
extern SDL_DECLSPEC SDL_bool SDLCALL SDL_PlayHapticRumble(SDL_Haptic *haptic, float strength, Uint32 length);
extern SDL_DECLSPEC bool SDLCALL SDL_PlayHapticRumble(SDL_Haptic *haptic, float strength, Uint32 length);
/**
* Stop the simple rumble on a haptic device.
*
* \param haptic the haptic device to stop the rumble effect on.
* \returns SDL_TRUE on success or SDL_FALSE on failure; call SDL_GetError()
* for more information.
* \returns true on success or false on failure; call SDL_GetError() for more
* information.
*
* \since This function is available since SDL 3.0.0.
* \since This function is available since SDL 3.2.0.
*
* \sa SDL_PlayHapticRumble
*/
extern SDL_DECLSPEC SDL_bool SDLCALL SDL_StopHapticRumble(SDL_Haptic *haptic);
extern SDL_DECLSPEC bool SDLCALL SDL_StopHapticRumble(SDL_Haptic *haptic);
/* Ends C function definitions when using C++ */
#ifdef __cplusplus

View File

@ -1,6 +1,6 @@
/*
Simple DirectMedia Layer
Copyright (C) 1997-2024 Sam Lantinga <slouken@libsdl.org>
Copyright (C) 1997-2025 Sam Lantinga <slouken@libsdl.org>
This software is provided 'as-is', without any express or implied
warranty. In no event will the authors be held liable for any damages
@ -65,14 +65,14 @@ extern "C" {
/**
* An opaque handle representing an open HID device.
*
* \since This struct is available since SDL 3.0.0.
* \since This struct is available since SDL 3.2.0.
*/
typedef struct SDL_hid_device SDL_hid_device;
/**
* HID underlying bus types.
*
* \since This enum is available since SDL 3.0.0.
* \since This enum is available since SDL 3.2.0.
*/
typedef enum SDL_hid_bus_type {
/** Unknown bus type */
@ -107,7 +107,7 @@ typedef enum SDL_hid_bus_type {
/**
* Information about a connected HID device
*
* \since This struct is available since SDL 3.0.0.
* \since This struct is available since SDL 3.2.0.
*/
typedef struct SDL_hid_device_info
{
@ -169,7 +169,7 @@ typedef struct SDL_hid_device_info
* \returns 0 on success or a negative error code on failure; call
* SDL_GetError() for more information.
*
* \since This function is available since SDL 3.0.0.
* \since This function is available since SDL 3.2.0.
*
* \sa SDL_hid_exit
*/
@ -184,7 +184,7 @@ extern SDL_DECLSPEC int SDLCALL SDL_hid_init(void);
* \returns 0 on success or a negative error code on failure; call
* SDL_GetError() for more information.
*
* \since This function is available since SDL 3.0.0.
* \since This function is available since SDL 3.2.0.
*
* \sa SDL_hid_init
*/
@ -205,7 +205,7 @@ extern SDL_DECLSPEC int SDLCALL SDL_hid_exit(void);
* \returns a change counter that is incremented with each potential device
* change, or 0 if device change detection isn't available.
*
* \since This function is available since SDL 3.0.0.
* \since This function is available since SDL 3.2.0.
*
* \sa SDL_hid_enumerate
*/
@ -233,7 +233,7 @@ extern SDL_DECLSPEC Uint32 SDLCALL SDL_hid_device_change_count(void);
* in the case of failure. Free this linked list by calling
* SDL_hid_free_enumeration().
*
* \since This function is available since SDL 3.0.0.
* \since This function is available since SDL 3.2.0.
*
* \sa SDL_hid_device_change_count
*/
@ -247,7 +247,7 @@ extern SDL_DECLSPEC SDL_hid_device_info * SDLCALL SDL_hid_enumerate(unsigned sho
* \param devs pointer to a list of struct_device returned from
* SDL_hid_enumerate().
*
* \since This function is available since SDL 3.0.0.
* \since This function is available since SDL 3.2.0.
*/
extern SDL_DECLSPEC void SDLCALL SDL_hid_free_enumeration(SDL_hid_device_info *devs);
@ -265,7 +265,7 @@ extern SDL_DECLSPEC void SDLCALL SDL_hid_free_enumeration(SDL_hid_device_info *d
* \returns a pointer to a SDL_hid_device object on success or NULL on
* failure; call SDL_GetError() for more information.
*
* \since This function is available since SDL 3.0.0.
* \since This function is available since SDL 3.2.0.
*/
extern SDL_DECLSPEC SDL_hid_device * SDLCALL SDL_hid_open(unsigned short vendor_id, unsigned short product_id, const wchar_t *serial_number);
@ -279,7 +279,7 @@ extern SDL_DECLSPEC SDL_hid_device * SDLCALL SDL_hid_open(unsigned short vendor_
* \returns a pointer to a SDL_hid_device object on success or NULL on
* failure; call SDL_GetError() for more information.
*
* \since This function is available since SDL 3.0.0.
* \since This function is available since SDL 3.2.0.
*/
extern SDL_DECLSPEC SDL_hid_device * SDLCALL SDL_hid_open_path(const char *path);
@ -306,7 +306,7 @@ extern SDL_DECLSPEC SDL_hid_device * SDLCALL SDL_hid_open_path(const char *path)
* \returns the actual number of bytes written and -1 on on failure; call
* SDL_GetError() for more information.
*
* \since This function is available since SDL 3.0.0.
* \since This function is available since SDL 3.2.0.
*/
extern SDL_DECLSPEC int SDLCALL SDL_hid_write(SDL_hid_device *dev, const unsigned char *data, size_t length);
@ -327,7 +327,7 @@ extern SDL_DECLSPEC int SDLCALL SDL_hid_write(SDL_hid_device *dev, const unsigne
* SDL_GetError() for more information. If no packet was available to
* be read within the timeout period, this function returns 0.
*
* \since This function is available since SDL 3.0.0.
* \since This function is available since SDL 3.2.0.
*/
extern SDL_DECLSPEC int SDLCALL SDL_hid_read_timeout(SDL_hid_device *dev, unsigned char *data, size_t length, int milliseconds);
@ -348,7 +348,7 @@ extern SDL_DECLSPEC int SDLCALL SDL_hid_read_timeout(SDL_hid_device *dev, unsign
* be read and the handle is in non-blocking mode, this function
* returns 0.
*
* \since This function is available since SDL 3.0.0.
* \since This function is available since SDL 3.2.0.
*/
extern SDL_DECLSPEC int SDLCALL SDL_hid_read(SDL_hid_device *dev, unsigned char *data, size_t length);
@ -367,7 +367,7 @@ extern SDL_DECLSPEC int SDLCALL SDL_hid_read(SDL_hid_device *dev, unsigned char
* \returns 0 on success or a negative error code on failure; call
* SDL_GetError() for more information.
*
* \since This function is available since SDL 3.0.0.
* \since This function is available since SDL 3.2.0.
*/
extern SDL_DECLSPEC int SDLCALL SDL_hid_set_nonblocking(SDL_hid_device *dev, int nonblock);
@ -392,7 +392,7 @@ extern SDL_DECLSPEC int SDLCALL SDL_hid_set_nonblocking(SDL_hid_device *dev, int
* \returns the actual number of bytes written and -1 on failure; call
* SDL_GetError() for more information.
*
* \since This function is available since SDL 3.0.0.
* \since This function is available since SDL 3.2.0.
*/
extern SDL_DECLSPEC int SDLCALL SDL_hid_send_feature_report(SDL_hid_device *dev, const unsigned char *data, size_t length);
@ -415,7 +415,7 @@ extern SDL_DECLSPEC int SDLCALL SDL_hid_send_feature_report(SDL_hid_device *dev,
* still in the first byte), or -1 on on failure; call SDL_GetError()
* for more information.
*
* \since This function is available since SDL 3.0.0.
* \since This function is available since SDL 3.2.0.
*/
extern SDL_DECLSPEC int SDLCALL SDL_hid_get_feature_report(SDL_hid_device *dev, unsigned char *data, size_t length);
@ -438,7 +438,7 @@ extern SDL_DECLSPEC int SDLCALL SDL_hid_get_feature_report(SDL_hid_device *dev,
* still in the first byte), or -1 on on failure; call SDL_GetError()
* for more information.
*
* \since This function is available since SDL 3.0.0.
* \since This function is available since SDL 3.2.0.
*/
extern SDL_DECLSPEC int SDLCALL SDL_hid_get_input_report(SDL_hid_device *dev, unsigned char *data, size_t length);
@ -449,7 +449,7 @@ extern SDL_DECLSPEC int SDLCALL SDL_hid_get_input_report(SDL_hid_device *dev, un
* \returns 0 on success or a negative error code on failure; call
* SDL_GetError() for more information.
*
* \since This function is available since SDL 3.0.0.
* \since This function is available since SDL 3.2.0.
*/
extern SDL_DECLSPEC int SDLCALL SDL_hid_close(SDL_hid_device *dev);
@ -462,7 +462,7 @@ extern SDL_DECLSPEC int SDLCALL SDL_hid_close(SDL_hid_device *dev);
* \returns 0 on success or a negative error code on failure; call
* SDL_GetError() for more information.
*
* \since This function is available since SDL 3.0.0.
* \since This function is available since SDL 3.2.0.
*/
extern SDL_DECLSPEC int SDLCALL SDL_hid_get_manufacturer_string(SDL_hid_device *dev, wchar_t *string, size_t maxlen);
@ -475,7 +475,7 @@ extern SDL_DECLSPEC int SDLCALL SDL_hid_get_manufacturer_string(SDL_hid_device *
* \returns 0 on success or a negative error code on failure; call
* SDL_GetError() for more information.
*
* \since This function is available since SDL 3.0.0.
* \since This function is available since SDL 3.2.0.
*/
extern SDL_DECLSPEC int SDLCALL SDL_hid_get_product_string(SDL_hid_device *dev, wchar_t *string, size_t maxlen);
@ -488,7 +488,7 @@ extern SDL_DECLSPEC int SDLCALL SDL_hid_get_product_string(SDL_hid_device *dev,
* \returns 0 on success or a negative error code on failure; call
* SDL_GetError() for more information.
*
* \since This function is available since SDL 3.0.0.
* \since This function is available since SDL 3.2.0.
*/
extern SDL_DECLSPEC int SDLCALL SDL_hid_get_serial_number_string(SDL_hid_device *dev, wchar_t *string, size_t maxlen);
@ -502,7 +502,7 @@ extern SDL_DECLSPEC int SDLCALL SDL_hid_get_serial_number_string(SDL_hid_device
* \returns 0 on success or a negative error code on failure; call
* SDL_GetError() for more information.
*
* \since This function is available since SDL 3.0.0.
* \since This function is available since SDL 3.2.0.
*/
extern SDL_DECLSPEC int SDLCALL SDL_hid_get_indexed_string(SDL_hid_device *dev, int string_index, wchar_t *string, size_t maxlen);
@ -514,7 +514,7 @@ extern SDL_DECLSPEC int SDLCALL SDL_hid_get_indexed_string(SDL_hid_device *dev,
* on failure; call SDL_GetError() for more information. This struct
* is valid until the device is closed with SDL_hid_close().
*
* \since This function is available since SDL 3.0.0.
* \since This function is available since SDL 3.2.0.
*/
extern SDL_DECLSPEC SDL_hid_device_info * SDLCALL SDL_hid_get_device_info(SDL_hid_device *dev);
@ -530,18 +530,18 @@ extern SDL_DECLSPEC SDL_hid_device_info * SDLCALL SDL_hid_get_device_info(SDL_hi
* \returns the number of bytes actually copied or -1 on failure; call
* SDL_GetError() for more information.
*
* \since This function is available since SDL 3.0.0.
* \since This function is available since SDL 3.2.0.
*/
extern SDL_DECLSPEC int SDLCALL SDL_hid_get_report_descriptor(SDL_hid_device *dev, unsigned char *buf, size_t buf_size);
/**
* Start or stop a BLE scan on iOS and tvOS to pair Steam Controllers.
*
* \param active SDL_TRUE to start the scan, SDL_FALSE to stop the scan.
* \param active true to start the scan, false to stop the scan.
*
* \since This function is available since SDL 3.0.0.
* \since This function is available since SDL 3.2.0.
*/
extern SDL_DECLSPEC void SDLCALL SDL_hid_ble_scan(SDL_bool active);
extern SDL_DECLSPEC void SDLCALL SDL_hid_ble_scan(bool active);
/* Ends C function definitions when using C++ */
#ifdef __cplusplus

File diff suppressed because it is too large Load Diff

View File

@ -1,6 +1,6 @@
/*
Simple DirectMedia Layer
Copyright (C) 1997-2024 Sam Lantinga <slouken@libsdl.org>
Copyright (C) 1997-2025 Sam Lantinga <slouken@libsdl.org>
This software is provided 'as-is', without any express or implied
warranty. In no event will the authors be held liable for any damages
@ -22,10 +22,30 @@
/**
* # CategoryInit
*
* SDL subsystem init and quit functions.
* All SDL programs need to initialize the library before starting to work
* with it.
*
* Almost everything can simply call SDL_Init() near startup, with a handful
* of flags to specify subsystems to touch. These are here to make sure SDL
* does not even attempt to touch low-level pieces of the operating system
* that you don't intend to use. For example, you might be using SDL for video
* and input but chose an external library for audio, and in this case you
* would just need to leave off the `SDL_INIT_AUDIO` flag to make sure that
* external library has complete control.
*
* Most apps, when terminating, should call SDL_Quit(). This will clean up
* (nearly) everything that SDL might have allocated, and crucially, it'll
* make sure that the display's resolution is back to what the user expects if
* you had previously changed it for your game.
*
* SDL3 apps are strongly encouraged to call SDL_SetAppMetadata() at startup
* to fill in details about the program. This is completely optional, but it
* helps in small ways (we can provide an About dialog box for the macOS menu,
* we can name the app in the system's audio mixer, etc). Those that want to
* provide a _lot_ of information should look at the more-detailed
* SDL_SetAppMetadataProperty().
*/
#ifndef SDL_init_h_
#define SDL_init_h_
@ -47,7 +67,7 @@ extern "C" {
* These are the flags which may be passed to SDL_Init(). You should specify
* the subsystems which you will be using in your application.
*
* \since This datatype is available since SDL 3.0.0.
* \since This datatype is available since SDL 3.2.0.
*
* \sa SDL_Init
* \sa SDL_Quit
@ -57,9 +77,8 @@ extern "C" {
*/
typedef Uint32 SDL_InitFlags;
#define SDL_INIT_TIMER 0x00000001u
#define SDL_INIT_AUDIO 0x00000010u /**< `SDL_INIT_AUDIO` implies `SDL_INIT_EVENTS` */
#define SDL_INIT_VIDEO 0x00000020u /**< `SDL_INIT_VIDEO` implies `SDL_INIT_EVENTS` */
#define SDL_INIT_VIDEO 0x00000020u /**< `SDL_INIT_VIDEO` implies `SDL_INIT_EVENTS`, should be initialized on the main thread */
#define SDL_INIT_JOYSTICK 0x00000200u /**< `SDL_INIT_JOYSTICK` implies `SDL_INIT_EVENTS`, should be initialized on the same thread as SDL_INIT_VIDEO on Windows if you don't set SDL_HINT_JOYSTICK_THREAD */
#define SDL_INIT_HAPTIC 0x00001000u
#define SDL_INIT_GAMEPAD 0x00002000u /**< `SDL_INIT_GAMEPAD` implies `SDL_INIT_JOYSTICK` */
@ -85,7 +104,7 @@ typedef Uint32 SDL_InitFlags;
* [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.0.0.
* \since This enum is available since SDL 3.2.0.
*/
typedef enum SDL_AppResult
{
@ -94,10 +113,70 @@ typedef enum SDL_AppResult
SDL_APP_FAILURE /**< Value that requests termination with error from the main callbacks. */
} SDL_AppResult;
/**
* Function pointer typedef for SDL_AppInit.
*
* These are used by SDL_EnterAppMainCallbacks. This mechanism operates behind
* the scenes for apps using the optional main callbacks. Apps that want to
* use this should just implement SDL_AppInit directly.
*
* \param appstate a place where the app can optionally store a pointer for
* future use.
* \param argc the standard ANSI C main's argc; number of elements in `argv`.
* \param argv the standard ANSI C main's argv; array of command line
* arguments.
* \returns SDL_APP_FAILURE to terminate with an error, SDL_APP_SUCCESS to
* terminate with success, SDL_APP_CONTINUE to continue.
*
* \since This datatype is available since SDL 3.2.0.
*/
typedef SDL_AppResult (SDLCALL *SDL_AppInit_func)(void **appstate, int argc, char *argv[]);
/**
* Function pointer typedef for SDL_AppIterate.
*
* These are used by SDL_EnterAppMainCallbacks. This mechanism operates behind
* the scenes for apps using the optional main callbacks. Apps that want to
* use this should just implement SDL_AppIterate directly.
*
* \param appstate an optional pointer, provided by the app in SDL_AppInit.
* \returns SDL_APP_FAILURE to terminate with an error, SDL_APP_SUCCESS to
* terminate with success, SDL_APP_CONTINUE to continue.
*
* \since This datatype is available since SDL 3.2.0.
*/
typedef SDL_AppResult (SDLCALL *SDL_AppIterate_func)(void *appstate);
typedef SDL_AppResult (SDLCALL *SDL_AppEvent_func)(void *appstate, const SDL_Event *event);
typedef void (SDLCALL *SDL_AppQuit_func)(void *appstate);
/**
* Function pointer typedef for SDL_AppEvent.
*
* These are used by SDL_EnterAppMainCallbacks. This mechanism operates behind
* the scenes for apps using the optional main callbacks. Apps that want to
* use this should just implement SDL_AppEvent directly.
*
* \param appstate an optional pointer, provided by the app in SDL_AppInit.
* \param event the new event for the app to examine.
* \returns SDL_APP_FAILURE to terminate with an error, SDL_APP_SUCCESS to
* terminate with success, SDL_APP_CONTINUE to continue.
*
* \since This datatype is available since SDL 3.2.0.
*/
typedef SDL_AppResult (SDLCALL *SDL_AppEvent_func)(void *appstate, SDL_Event *event);
/**
* Function pointer typedef for SDL_AppQuit.
*
* These are used by SDL_EnterAppMainCallbacks. This mechanism operates behind
* the scenes for apps using the optional main callbacks. Apps that want to
* use this should just implement SDL_AppEvent directly.
*
* \param appstate an optional pointer, provided by the app in SDL_AppInit.
* \param result the result code that terminated the app (success or failure).
*
* \since This datatype is available since SDL 3.2.0.
*/
typedef void (SDLCALL *SDL_AppQuit_func)(void *appstate, SDL_AppResult result);
/**
* Initialize the SDL library.
@ -117,11 +196,10 @@ typedef void (SDLCALL *SDL_AppQuit_func)(void *appstate);
*
* `flags` may be any of the following OR'd together:
*
* - `SDL_INIT_TIMER`: timer subsystem
* - `SDL_INIT_AUDIO`: audio subsystem; automatically initializes the events
* subsystem
* - `SDL_INIT_VIDEO`: video subsystem; automatically initializes the events
* subsystem
* subsystem, should be initialized on the main thread.
* - `SDL_INIT_JOYSTICK`: joystick subsystem; automatically initializes the
* events subsystem
* - `SDL_INIT_HAPTIC`: haptic (force feedback) subsystem
@ -143,10 +221,10 @@ typedef void (SDLCALL *SDL_AppQuit_func)(void *appstate);
* SDL_SetAppMetadataProperty().
*
* \param flags subsystem initialization flags.
* \returns SDL_TRUE on success or SDL_FALSE on failure; call SDL_GetError()
* for more information.
* \returns true on success or false on failure; call SDL_GetError() for more
* information.
*
* \since This function is available since SDL 3.0.0.
* \since This function is available since SDL 3.2.0.
*
* \sa SDL_SetAppMetadata
* \sa SDL_SetAppMetadataProperty
@ -155,7 +233,7 @@ typedef void (SDLCALL *SDL_AppQuit_func)(void *appstate);
* \sa SDL_SetMainReady
* \sa SDL_WasInit
*/
extern SDL_DECLSPEC SDL_bool SDLCALL SDL_Init(SDL_InitFlags flags);
extern SDL_DECLSPEC bool SDLCALL SDL_Init(SDL_InitFlags flags);
/**
* Compatibility function to initialize the SDL library.
@ -163,16 +241,16 @@ extern SDL_DECLSPEC SDL_bool SDLCALL SDL_Init(SDL_InitFlags flags);
* This function and SDL_Init() are interchangeable.
*
* \param flags any of the flags used by SDL_Init(); see SDL_Init for details.
* \returns SDL_TRUE on success or SDL_FALSE on failure; call SDL_GetError()
* for more information.
* \returns true on success or false on failure; call SDL_GetError() for more
* information.
*
* \since This function is available since SDL 3.0.0.
* \since This function is available since SDL 3.2.0.
*
* \sa SDL_Init
* \sa SDL_Quit
* \sa SDL_QuitSubSystem
*/
extern SDL_DECLSPEC SDL_bool SDLCALL SDL_InitSubSystem(SDL_InitFlags flags);
extern SDL_DECLSPEC bool SDLCALL SDL_InitSubSystem(SDL_InitFlags flags);
/**
* Shut down specific SDL subsystems.
@ -182,7 +260,7 @@ extern SDL_DECLSPEC SDL_bool SDLCALL SDL_InitSubSystem(SDL_InitFlags flags);
*
* \param flags any of the flags used by SDL_Init(); see SDL_Init for details.
*
* \since This function is available since SDL 3.0.0.
* \since This function is available since SDL 3.2.0.
*
* \sa SDL_InitSubSystem
* \sa SDL_Quit
@ -196,7 +274,7 @@ 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.
*
* \since This function is available since SDL 3.0.0.
* \since This function is available since SDL 3.2.0.
*
* \sa SDL_Init
* \sa SDL_InitSubSystem
@ -214,13 +292,70 @@ 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.
*
* \since This function is available since SDL 3.0.0.
* \since This function is available since SDL 3.2.0.
*
* \sa SDL_Init
* \sa SDL_QuitSubSystem
*/
extern SDL_DECLSPEC void SDLCALL SDL_Quit(void);
/**
* Return whether this is the main thread.
*
* On Apple platforms, the main thread is the thread that runs your program's
* main() entry point. On other platforms, the main thread is the one that
* calls SDL_Init(SDL_INIT_VIDEO), which should usually be the one that runs
* your program's main() entry point. If you are using the main callbacks,
* SDL_AppInit(), SDL_AppIterate(), and SDL_AppQuit() are all called on the
* main thread.
*
* \returns true if this thread is the main thread, or 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_RunOnMainThread
*/
extern SDL_DECLSPEC bool SDLCALL SDL_IsMainThread(void);
/**
* Callback run on the main thread.
*
* \param userdata an app-controlled pointer that is passed to the callback.
*
* \since This datatype is available since SDL 3.2.0.
*
* \sa SDL_RunOnMainThread
*/
typedef void (SDLCALL *SDL_MainThreadCallback)(void *userdata);
/**
* Call a function on the main thread during event processing.
*
* If this is called on the main thread, the callback is executed immediately.
* If this is called on another thread, this callback is queued for execution
* on the main thread during event processing.
*
* Be careful of deadlocks when using this functionality. You should not have
* the main thread wait for the current thread while this function is being
* called with `wait_complete` true.
*
* \param callback the callback to call on the main thread.
* \param userdata a pointer that is passed to `callback`.
* \param wait_complete true to wait for the callback to complete, false to
* return immediately.
* \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_IsMainThread
*/
extern SDL_DECLSPEC bool SDLCALL SDL_RunOnMainThread(SDL_MainThreadCallback callback, void *userdata, bool wait_complete);
/**
* Specify basic metadata about your app.
*
@ -248,16 +383,16 @@ extern SDL_DECLSPEC void SDLCALL SDL_Quit(void);
* hash, or whatever makes sense).
* \param appidentifier A unique string in reverse-domain format that
* identifies this app ("com.example.mygame2").
* \returns SDL_TRUE on success or SDL_FALSE on failure; call SDL_GetError()
* for more information.
* \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.0.0.
* \since This function is available since SDL 3.2.0.
*
* \sa SDL_SetAppMetadataProperty
*/
extern SDL_DECLSPEC SDL_bool SDLCALL SDL_SetAppMetadata(const char *appname, const char *appversion, const char *appidentifier);
extern SDL_DECLSPEC bool SDLCALL SDL_SetAppMetadata(const char *appname, const char *appversion, const char *appidentifier);
/**
* Specify metadata about your app through a set of properties.
@ -274,7 +409,7 @@ extern SDL_DECLSPEC SDL_bool SDLCALL SDL_SetAppMetadata(const char *appname, con
* Multiple calls to this function are allowed, but various state might not
* change once it has been set up with a previous call to this function.
*
* Once set, this metadata can be read using SDL_GetMetadataProperty().
* Once set, this metadata can be read using SDL_GetAppMetadataProperty().
*
* These are the supported properties:
*
@ -310,17 +445,17 @@ extern SDL_DECLSPEC SDL_bool SDLCALL SDL_SetAppMetadata(const char *appname, con
*
* \param name the name of the metadata property to set.
* \param value the value of the property, or NULL to remove that property.
* \returns SDL_TRUE on success or SDL_FALSE on failure; call SDL_GetError()
* for more information.
* \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.0.0.
* \since This function is available since SDL 3.2.0.
*
* \sa SDL_GetAppMetadataProperty
* \sa SDL_SetAppMetadata
*/
extern SDL_DECLSPEC SDL_bool SDLCALL SDL_SetAppMetadataProperty(const char *name, const char *value);
extern SDL_DECLSPEC bool SDLCALL SDL_SetAppMetadataProperty(const char *name, const char *value);
#define SDL_PROP_APP_METADATA_NAME_STRING "SDL.app.metadata.name"
#define SDL_PROP_APP_METADATA_VERSION_STRING "SDL.app.metadata.version"
@ -346,7 +481,7 @@ extern SDL_DECLSPEC SDL_bool SDLCALL SDL_SetAppMetadataProperty(const char *name
* freed if you call SDL_SetAppMetadataProperty() to set that
* property from another thread.
*
* \since This function is available since SDL 3.0.0.
* \since This function is available since SDL 3.2.0.
*
* \sa SDL_SetAppMetadata
* \sa SDL_SetAppMetadataProperty

View File

@ -1,6 +1,6 @@
/*
Simple DirectMedia Layer
Copyright (C) 1997-2024 Sam Lantinga <slouken@libsdl.org>
Copyright (C) 1997-2025 Sam Lantinga <slouken@libsdl.org>
This software is provided 'as-is', without any express or implied
warranty. In no event will the authors be held liable for any damages
@ -19,8 +19,31 @@
3. This notice may not be removed or altered from any source distribution.
*/
/*
* Header file for CPU intrinsics for SDL
/* WIKI CATEGORY: Intrinsics */
/**
* # CategoryIntrinsics
*
* SDL does some preprocessor gymnastics to determine if any CPU-specific
* compiler intrinsics are available, as this is not necessarily an easy thing
* to calculate, and sometimes depends on quirks of a system, versions of
* build tools, and other external forces.
*
* Apps including SDL's headers will be able to check consistent preprocessor
* definitions to decide if it's safe to use compiler intrinsics for a
* specific CPU architecture. This check only tells you that the compiler is
* capable of using those intrinsics; at runtime, you should still check if
* they are available on the current system with the
* [CPU info functions](https://wiki.libsdl.org/SDL3/CategoryCPUInfo)
* , such as SDL_HasSSE() or SDL_HasNEON(). Otherwise, the process might crash
* for using an unsupported CPU instruction.
*
* SDL only sets preprocessor defines for CPU intrinsics if they are
* supported, so apps should check with `#ifdef` and not `#if`.
*
* SDL will also include the appropriate instruction-set-specific support
* headers, so if SDL decides to define SDL_SSE2_INTRINSICS, it will also
* `#include <emmintrin.h>` as well.
*/
#ifndef SDL_intrin_h_
@ -28,6 +51,169 @@
#include <SDL3/SDL_stdinc.h>
#ifdef SDL_WIKI_DOCUMENTATION_SECTION
/**
* Defined if (and only if) the compiler supports Loongarch LSX intrinsics.
*
* If this macro is defined, SDL will have already included `<lsxintrin.h>`
*
* \since This macro is available since SDL 3.2.0.
*
* \sa SDL_LASX_INTRINSICS
*/
#define SDL_LSX_INTRINSICS 1
/**
* Defined if (and only if) the compiler supports Loongarch LSX intrinsics.
*
* If this macro is defined, SDL will have already included `<lasxintrin.h>`
*
* \since This macro is available since SDL 3.2.0.
*
* \sa SDL_LASX_INTRINSICS
*/
#define SDL_LASX_INTRINSICS 1
/**
* Defined if (and only if) the compiler supports ARM NEON intrinsics.
*
* If this macro is defined, SDL will have already included `<armintr.h>`
* `<arm_neon.h>`, `<arm64intr.h>`, and `<arm64_neon.h>`, as appropriate.
*
* \since This macro is available since SDL 3.2.0.
*/
#define SDL_NEON_INTRINSICS 1
/**
* Defined if (and only if) the compiler supports PowerPC Altivec intrinsics.
*
* If this macro is defined, SDL will have already included `<altivec.h>`
*
* \since This macro is available since SDL 3.2.0.
*/
#define SDL_ALTIVEC_INTRINSICS 1
/**
* Defined if (and only if) the compiler supports Intel MMX intrinsics.
*
* If this macro is defined, SDL will have already included `<mmintrin.h>`
*
* \since This macro is available since SDL 3.2.0.
*
* \sa SDL_SSE_INTRINSICS
*/
#define SDL_MMX_INTRINSICS 1
/**
* Defined if (and only if) the compiler supports Intel SSE intrinsics.
*
* If this macro is defined, SDL will have already included `<xmmintrin.h>`
*
* \since This macro is available since SDL 3.2.0.
*
* \sa SDL_SSE2_INTRINSICS
* \sa SDL_SSE3_INTRINSICS
* \sa SDL_SSE4_1_INTRINSICS
* \sa SDL_SSE4_2_INTRINSICS
*/
#define SDL_SSE_INTRINSICS 1
/**
* Defined if (and only if) the compiler supports Intel SSE2 intrinsics.
*
* If this macro is defined, SDL will have already included `<emmintrin.h>`
*
* \since This macro is available since SDL 3.2.0.
*
* \sa SDL_SSE_INTRINSICS
* \sa SDL_SSE3_INTRINSICS
* \sa SDL_SSE4_1_INTRINSICS
* \sa SDL_SSE4_2_INTRINSICS
*/
#define SDL_SSE2_INTRINSICS 1
/**
* Defined if (and only if) the compiler supports Intel SSE3 intrinsics.
*
* If this macro is defined, SDL will have already included `<pmmintrin.h>`
*
* \since This macro is available since SDL 3.2.0.
*
* \sa SDL_SSE_INTRINSICS
* \sa SDL_SSE2_INTRINSICS
* \sa SDL_SSE4_1_INTRINSICS
* \sa SDL_SSE4_2_INTRINSICS
*/
#define SDL_SSE3_INTRINSICS 1
/**
* Defined if (and only if) the compiler supports Intel SSE4.1 intrinsics.
*
* If this macro is defined, SDL will have already included `<smmintrin.h>`
*
* \since This macro is available since SDL 3.2.0.
*
* \sa SDL_SSE_INTRINSICS
* \sa SDL_SSE2_INTRINSICS
* \sa SDL_SSE3_INTRINSICS
* \sa SDL_SSE4_2_INTRINSICS
*/
#define SDL_SSE4_1_INTRINSICS 1
/**
* Defined if (and only if) the compiler supports Intel SSE4.2 intrinsics.
*
* If this macro is defined, SDL will have already included `<nmmintrin.h>`
*
* \since This macro is available since SDL 3.2.0.
*
* \sa SDL_SSE_INTRINSICS
* \sa SDL_SSE2_INTRINSICS
* \sa SDL_SSE3_INTRINSICS
* \sa SDL_SSE4_1_INTRINSICS
*/
#define SDL_SSE4_2_INTRINSICS 1
/**
* Defined if (and only if) the compiler supports Intel AVX intrinsics.
*
* If this macro is defined, SDL will have already included `<immintrin.h>`
*
* \since This macro is available since SDL 3.2.0.
*
* \sa SDL_AVX2_INTRINSICS
* \sa SDL_AVX512F_INTRINSICS
*/
#define SDL_AVX_INTRINSICS 1
/**
* Defined if (and only if) the compiler supports Intel AVX2 intrinsics.
*
* If this macro is defined, SDL will have already included `<immintrin.h>`
*
* \since This macro is available since SDL 3.2.0.
*
* \sa SDL_AVX_INTRINSICS
* \sa SDL_AVX512F_INTRINSICS
*/
#define SDL_AVX2_INTRINSICS 1
/**
* Defined if (and only if) the compiler supports Intel AVX-512F intrinsics.
*
* AVX-512F is also sometimes referred to as "AVX-512 Foundation."
*
* If this macro is defined, SDL will have already included `<immintrin.h>`
*
* \since This macro is available since SDL 3.2.0.
*
* \sa SDL_AVX_INTRINSICS
* \sa SDL_AVX2_INTRINSICS
*/
#define SDL_AVX512F_INTRINSICS 1
#endif
/* 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))
@ -81,7 +267,21 @@ _m_prefetch(void *__P)
#endif
#endif /* compiler version */
#if defined(__clang__) && defined(__has_attribute)
#ifdef SDL_WIKI_DOCUMENTATION_SECTION
/**
* A macro to decide if the compiler supports `__attribute__((target))`.
*
* Even though this is defined in SDL's public headers, it is generally not
* used directly by apps. Apps should probably just use SDL_TARGETING
* directly, instead.
*
* \since This macro is available since SDL 3.2.0.
*
* \sa SDL_TARGETING
*/
#define SDL_HAS_TARGET_ATTRIBS
#elif defined(__clang__) && defined(__has_attribute)
# if __has_attribute(target)
# define SDL_HAS_TARGET_ATTRIBS
# endif
@ -91,7 +291,55 @@ _m_prefetch(void *__P)
# define SDL_HAS_TARGET_ATTRIBS
#endif
#ifdef SDL_HAS_TARGET_ATTRIBS
#ifdef SDL_WIKI_DOCUMENTATION_SECTION
/**
* A macro to tag a function as targeting a specific CPU architecture.
*
* This is a hint to the compiler that a function should be built with support
* for a CPU instruction set that might be different than the rest of the
* program.
*
* The particulars of this are explained in the GCC documentation:
*
* https://gcc.gnu.org/onlinedocs/gcc/Common-Function-Attributes.html#index-target-function-attribute
*
* An example of using this feature is to turn on SSE2 support for a specific
* function, even if the rest of the source code is not compiled to use SSE2
* code:
*
* ```c
* #ifdef SDL_SSE2_INTRINSICS
* static void SDL_TARGETING("sse2") DoSomethingWithSSE2(char *x) {
* ...use SSE2 intrinsic functions, etc...
* }
* #endif
*
* // later...
* #ifdef SDL_SSE2_INTRINSICS
* if (SDL_HasSSE2()) {
* DoSomethingWithSSE2(str);
* }
* #endif
* ```
*
* The application is, on a whole, built without SSE2 instructions, so it will
* run on Intel machines that don't support SSE2. But then at runtime, it
* checks if the system supports the instructions, and then calls into a
* function that uses SSE2 opcodes. The ifdefs make sure that this code isn't
* used on platforms that don't have SSE2 at all.
*
* On compilers without target support, this is defined to nothing.
*
* This symbol is used by SDL internally, but apps and other libraries are
* welcome to use it for their own interfaces as well.
*
* \since This macro is available since SDL 3.2.0.
*/
#define SDL_TARGETING(x) __attribute__((target(x)))
#elif defined(SDL_HAS_TARGET_ATTRIBS)
# define SDL_TARGETING(x) __attribute__((target(x)))
#else
# define SDL_TARGETING(x)

File diff suppressed because it is too large Load Diff

View File

@ -1,6 +1,6 @@
/*
Simple DirectMedia Layer
Copyright (C) 1997-2024 Sam Lantinga <slouken@libsdl.org>
Copyright (C) 1997-2025 Sam Lantinga <slouken@libsdl.org>
This software is provided 'as-is', without any express or implied
warranty. In no event will the authors be held liable for any damages
@ -25,8 +25,8 @@
* SDL joystick support.
*
* This is the lower-level joystick handling. If you want the simpler option,
* where what buttons does what is well-defined, you should use the gamepad
* API instead.
* where what each button does is well-defined, you should use the gamepad API
* 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
@ -81,7 +81,7 @@ extern SDL_Mutex *SDL_joystick_lock;
*
* This is opaque data.
*
* \since This struct is available since SDL 3.0.0.
* \since This struct is available since SDL 3.2.0.
*/
typedef struct SDL_Joystick SDL_Joystick;
@ -93,7 +93,7 @@ typedef struct SDL_Joystick SDL_Joystick;
*
* The value 0 is an invalid ID.
*
* \since This datatype is available since SDL 3.0.0.
* \since This datatype is available since SDL 3.2.0.
*/
typedef Uint32 SDL_JoystickID;
@ -107,7 +107,7 @@ typedef Uint32 SDL_JoystickID;
* This is by no means a complete list of everything that can be plugged into
* a computer.
*
* \since This enum is available since SDL 3.0.0.
* \since This enum is available since SDL 3.2.0.
*/
typedef enum SDL_JoystickType
{
@ -120,7 +120,8 @@ typedef enum SDL_JoystickType
SDL_JOYSTICK_TYPE_GUITAR,
SDL_JOYSTICK_TYPE_DRUM_KIT,
SDL_JOYSTICK_TYPE_ARCADE_PAD,
SDL_JOYSTICK_TYPE_THROTTLE
SDL_JOYSTICK_TYPE_THROTTLE,
SDL_JOYSTICK_TYPE_COUNT
} SDL_JoystickType;
/**
@ -129,7 +130,7 @@ typedef enum SDL_JoystickType
* This is used by SDL_GetJoystickConnectionState to report how a device is
* connected to the system.
*
* \since This enum is available since SDL 3.0.0.
* \since This enum is available since SDL 3.2.0.
*/
typedef enum SDL_JoystickConnectionState
{
@ -142,7 +143,7 @@ typedef enum SDL_JoystickConnectionState
/**
* The largest value an SDL_Joystick's axis can report.
*
* \since This macro is available since SDL 3.0.0.
* \since This macro is available since SDL 3.2.0.
*
* \sa SDL_JOYSTICK_AXIS_MIN
*/
@ -153,19 +154,13 @@ typedef enum SDL_JoystickConnectionState
*
* This is a negative number!
*
* \since This macro is available since SDL 3.0.0.
* \since This macro is available since SDL 3.2.0.
*
* \sa SDL_JOYSTICK_AXIS_MAX
*/
#define SDL_JOYSTICK_AXIS_MIN -32768
/* Set max recognized G-force from accelerometer
See src/joystick/uikit/SDL_sysjoystick.m for notes on why this is needed
*/
#define SDL_IPHONE_MAX_GFORCE 5.0
/* Function prototypes */
/**
@ -175,27 +170,27 @@ 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.
*
* \since This function is available since SDL 3.0.0.
* \since This function is available since SDL 3.2.0.
*/
extern SDL_DECLSPEC void SDLCALL SDL_LockJoysticks(void) SDL_ACQUIRE(SDL_joystick_lock);
/**
* Unlocking for atomic access to the joystick API.
*
* \since This function is available since SDL 3.0.0.
* \since This function is available since SDL 3.2.0.
*/
extern SDL_DECLSPEC void SDLCALL SDL_UnlockJoysticks(void) SDL_RELEASE(SDL_joystick_lock);
/**
* Return whether a joystick is currently connected.
*
* \returns SDL_TRUE if a joystick is connected, SDL_FALSE otherwise.
* \returns true if a joystick is connected, false otherwise.
*
* \since This function is available since SDL 3.0.0.
* \since This function is available since SDL 3.2.0.
*
* \sa SDL_GetJoysticks
*/
extern SDL_DECLSPEC SDL_bool SDLCALL SDL_HasJoystick(void);
extern SDL_DECLSPEC bool SDLCALL SDL_HasJoystick(void);
/**
* Get a list of currently connected joysticks.
@ -206,7 +201,7 @@ extern SDL_DECLSPEC SDL_bool SDLCALL SDL_HasJoystick(void);
* call SDL_GetError() for more information. This should be freed
* with SDL_free() when it is no longer needed.
*
* \since This function is available since SDL 3.0.0.
* \since This function is available since SDL 3.2.0.
*
* \sa SDL_HasJoystick
* \sa SDL_OpenJoystick
@ -222,7 +217,7 @@ 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.
*
* \since This function is available since SDL 3.0.0.
* \since This function is available since SDL 3.2.0.
*
* \sa SDL_GetJoystickName
* \sa SDL_GetJoysticks
@ -238,7 +233,7 @@ 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.
*
* \since This function is available since SDL 3.0.0.
* \since This function is available since SDL 3.2.0.
*
* \sa SDL_GetJoystickPath
* \sa SDL_GetJoysticks
@ -253,7 +248,7 @@ 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.
*
* \since This function is available since SDL 3.0.0.
* \since This function is available since SDL 3.2.0.
*
* \sa SDL_GetJoystickPlayerIndex
* \sa SDL_GetJoysticks
@ -269,7 +264,7 @@ 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.
*
* \since This function is available since SDL 3.0.0.
* \since This function is available since SDL 3.2.0.
*
* \sa SDL_GetJoystickGUID
* \sa SDL_GUIDToString
@ -286,7 +281,7 @@ 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.
*
* \since This function is available since SDL 3.0.0.
* \since This function is available since SDL 3.2.0.
*
* \sa SDL_GetJoystickVendor
* \sa SDL_GetJoysticks
@ -303,7 +298,7 @@ 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.
*
* \since This function is available since SDL 3.0.0.
* \since This function is available since SDL 3.2.0.
*
* \sa SDL_GetJoystickProduct
* \sa SDL_GetJoysticks
@ -320,7 +315,7 @@ 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.
*
* \since This function is available since SDL 3.0.0.
* \since This function is available since SDL 3.2.0.
*
* \sa SDL_GetJoystickProductVersion
* \sa SDL_GetJoysticks
@ -337,7 +332,7 @@ extern SDL_DECLSPEC Uint16 SDLCALL SDL_GetJoystickProductVersionForID(SDL_Joysti
* invalid instance_id, this function returns
* `SDL_JOYSTICK_TYPE_UNKNOWN`.
*
* \since This function is available since SDL 3.0.0.
* \since This function is available since SDL 3.2.0.
*
* \sa SDL_GetJoystickType
* \sa SDL_GetJoysticks
@ -354,7 +349,7 @@ extern SDL_DECLSPEC SDL_JoystickType SDLCALL SDL_GetJoystickTypeForID(SDL_Joysti
* \returns a joystick identifier or NULL on failure; call SDL_GetError() for
* more information.
*
* \since This function is available since SDL 3.0.0.
* \since This function is available since SDL 3.2.0.
*
* \sa SDL_CloseJoystick
*/
@ -367,7 +362,7 @@ 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.
*
* \since This function is available since SDL 3.0.0.
* \since This function is available since SDL 3.2.0.
*/
extern SDL_DECLSPEC SDL_Joystick * SDLCALL SDL_GetJoystickFromID(SDL_JoystickID instance_id);
@ -378,7 +373,7 @@ 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.
*
* \since This function is available since SDL 3.0.0.
* \since This function is available since SDL 3.2.0.
*
* \sa SDL_GetJoystickPlayerIndex
* \sa SDL_SetJoystickPlayerIndex
@ -388,7 +383,7 @@ extern SDL_DECLSPEC SDL_Joystick * SDLCALL SDL_GetJoystickFromPlayerIndex(int pl
/**
* The structure that describes a virtual joystick touchpad.
*
* \since This struct is available since SDL 3.0.0.
* \since This struct is available since SDL 3.2.0.
*
* \sa SDL_VirtualJoystickDesc
*/
@ -401,7 +396,7 @@ typedef struct SDL_VirtualJoystickTouchpadDesc
/**
* The structure that describes a virtual joystick sensor.
*
* \since This struct is available since SDL 3.0.0.
* \since This struct is available since SDL 3.2.0.
*
* \sa SDL_VirtualJoystickDesc
*/
@ -414,16 +409,19 @@ typedef struct SDL_VirtualJoystickSensorDesc
/**
* The structure that describes a virtual joystick.
*
* All elements of this structure are optional and can be left 0.
* This structure should be initialized using SDL_INIT_INTERFACE(). All
* elements of this structure are optional.
*
* \since This struct is available since SDL 3.0.0.
* \since This struct is available since SDL 3.2.0.
*
* \sa SDL_AttachVirtualJoystick
* \sa SDL_INIT_INTERFACE
* \sa SDL_VirtualJoystickSensorDesc
* \sa SDL_VirtualJoystickTouchpadDesc
*/
typedef struct SDL_VirtualJoystickDesc
{
Uint32 version; /**< the version of this interface */
Uint16 type; /**< `SDL_JoystickType` */
Uint16 padding; /**< unused */
Uint16 vendor_id; /**< the USB vendor ID of this joystick */
@ -446,22 +444,32 @@ typedef struct SDL_VirtualJoystickDesc
void *userdata; /**< User data pointer passed to callbacks */
void (SDLCALL *Update)(void *userdata); /**< Called when the joystick state should be updated */
void (SDLCALL *SetPlayerIndex)(void *userdata, int player_index); /**< Called when the player index is set */
SDL_bool (SDLCALL *Rumble)(void *userdata, Uint16 low_frequency_rumble, Uint16 high_frequency_rumble); /**< Implements SDL_RumbleJoystick() */
SDL_bool (SDLCALL *RumbleTriggers)(void *userdata, Uint16 left_rumble, Uint16 right_rumble); /**< Implements SDL_RumbleJoystickTriggers() */
SDL_bool (SDLCALL *SetLED)(void *userdata, Uint8 red, Uint8 green, Uint8 blue); /**< Implements SDL_SetJoystickLED() */
SDL_bool (SDLCALL *SendEffect)(void *userdata, const void *data, int size); /**< Implements SDL_SendJoystickEffect() */
SDL_bool (SDLCALL *SetSensorsEnabled)(void *userdata, SDL_bool enabled); /**< Implements SDL_SetGamepadSensorEnabled() */
bool (SDLCALL *Rumble)(void *userdata, Uint16 low_frequency_rumble, Uint16 high_frequency_rumble); /**< Implements SDL_RumbleJoystick() */
bool (SDLCALL *RumbleTriggers)(void *userdata, Uint16 left_rumble, Uint16 right_rumble); /**< Implements SDL_RumbleJoystickTriggers() */
bool (SDLCALL *SetLED)(void *userdata, Uint8 red, Uint8 green, Uint8 blue); /**< Implements SDL_SetJoystickLED() */
bool (SDLCALL *SendEffect)(void *userdata, const void *data, int size); /**< Implements SDL_SendJoystickEffect() */
bool (SDLCALL *SetSensorsEnabled)(void *userdata, bool enabled); /**< Implements SDL_SetGamepadSensorEnabled() */
void (SDLCALL *Cleanup)(void *userdata); /**< Cleans up the userdata when the joystick is detached */
} SDL_VirtualJoystickDesc;
/* Check the size of SDL_VirtualJoystickDesc
*
* If this assert fails, either the compiler is padding to an unexpected size,
* or the interface has been updated and this should be updated to match and
* the code using this interface should be updated to handle the old version.
*/
SDL_COMPILE_TIME_ASSERT(SDL_VirtualJoystickDesc_SIZE,
(sizeof(void *) == 4 && sizeof(SDL_VirtualJoystickDesc) == 84) ||
(sizeof(void *) == 8 && sizeof(SDL_VirtualJoystickDesc) == 136));
/**
* Attach a new virtual joystick.
*
* \param desc joystick description.
* \param desc joystick description, initialized using SDL_INIT_INTERFACE().
* \returns the joystick instance ID, or 0 on failure; call SDL_GetError() for
* more information.
*
* \since This function is available since SDL 3.0.0.
* \since This function is available since SDL 3.2.0.
*
* \sa SDL_DetachVirtualJoystick
*/
@ -472,24 +480,24 @@ extern SDL_DECLSPEC SDL_JoystickID SDLCALL SDL_AttachVirtualJoystick(const SDL_V
*
* \param instance_id the joystick instance ID, previously returned from
* SDL_AttachVirtualJoystick().
* \returns SDL_TRUE on success or SDL_FALSE on failure; call SDL_GetError()
* for more information.
* \returns true on success or false on failure; call SDL_GetError() for more
* information.
*
* \since This function is available since SDL 3.0.0.
* \since This function is available since SDL 3.2.0.
*
* \sa SDL_AttachVirtualJoystick
*/
extern SDL_DECLSPEC SDL_bool SDLCALL SDL_DetachVirtualJoystick(SDL_JoystickID instance_id);
extern SDL_DECLSPEC bool SDLCALL SDL_DetachVirtualJoystick(SDL_JoystickID instance_id);
/**
* Query whether or not a joystick is virtual.
*
* \param instance_id the joystick instance ID.
* \returns SDL_TRUE if the joystick is virtual, SDL_FALSE otherwise.
* \returns true if the joystick is virtual, false otherwise.
*
* \since This function is available since SDL 3.0.0.
* \since This function is available since SDL 3.2.0.
*/
extern SDL_DECLSPEC SDL_bool SDLCALL SDL_IsJoystickVirtual(SDL_JoystickID instance_id);
extern SDL_DECLSPEC bool SDLCALL SDL_IsJoystickVirtual(SDL_JoystickID instance_id);
/**
* Set the state of an axis on an opened virtual joystick.
@ -507,12 +515,12 @@ extern SDL_DECLSPEC SDL_bool SDLCALL SDL_IsJoystickVirtual(SDL_JoystickID instan
* \param joystick the virtual joystick on which to set state.
* \param axis the index of the axis on the virtual joystick to update.
* \param value the new value for the specified axis.
* \returns SDL_TRUE on success or SDL_FALSE on failure; call SDL_GetError()
* for more information.
* \returns true on success or false on failure; call SDL_GetError() for more
* information.
*
* \since This function is available since SDL 3.0.0.
* \since This function is available since SDL 3.2.0.
*/
extern SDL_DECLSPEC SDL_bool SDLCALL SDL_SetJoystickVirtualAxis(SDL_Joystick *joystick, int axis, Sint16 value);
extern SDL_DECLSPEC bool SDLCALL SDL_SetJoystickVirtualAxis(SDL_Joystick *joystick, int axis, Sint16 value);
/**
* Generate ball motion on an opened virtual joystick.
@ -527,12 +535,12 @@ extern SDL_DECLSPEC SDL_bool SDLCALL SDL_SetJoystickVirtualAxis(SDL_Joystick *jo
* \param ball the index of the ball on the virtual joystick to update.
* \param xrel the relative motion on the X axis.
* \param yrel the relative motion on the Y axis.
* \returns SDL_TRUE on success or SDL_FALSE on failure; call SDL_GetError()
* for more information.
* \returns true on success or false on failure; call SDL_GetError() for more
* information.
*
* \since This function is available since SDL 3.0.0.
* \since This function is available since SDL 3.2.0.
*/
extern SDL_DECLSPEC SDL_bool SDLCALL SDL_SetJoystickVirtualBall(SDL_Joystick *joystick, int ball, Sint16 xrel, Sint16 yrel);
extern SDL_DECLSPEC bool SDLCALL SDL_SetJoystickVirtualBall(SDL_Joystick *joystick, int ball, Sint16 xrel, Sint16 yrel);
/**
* Set the state of a button on an opened virtual joystick.
@ -545,13 +553,13 @@ extern SDL_DECLSPEC SDL_bool SDLCALL SDL_SetJoystickVirtualBall(SDL_Joystick *jo
*
* \param joystick the virtual joystick on which to set state.
* \param button the index of the button on the virtual joystick to update.
* \param value the new value for the specified button.
* \returns SDL_TRUE on success or SDL_FALSE on failure; call SDL_GetError()
* for more information.
* \param down true if the button is pressed, false otherwise.
* \returns true on success or false on failure; call SDL_GetError() for more
* information.
*
* \since This function is available since SDL 3.0.0.
* \since This function is available since SDL 3.2.0.
*/
extern SDL_DECLSPEC SDL_bool SDLCALL SDL_SetJoystickVirtualButton(SDL_Joystick *joystick, int button, Uint8 value);
extern SDL_DECLSPEC bool SDLCALL SDL_SetJoystickVirtualButton(SDL_Joystick *joystick, int button, bool down);
/**
* Set the state of a hat on an opened virtual joystick.
@ -565,12 +573,12 @@ extern SDL_DECLSPEC SDL_bool SDLCALL SDL_SetJoystickVirtualButton(SDL_Joystick *
* \param joystick the virtual joystick on which to set state.
* \param hat the index of the hat on the virtual joystick to update.
* \param value the new value for the specified hat.
* \returns SDL_TRUE on success or SDL_FALSE on failure; call SDL_GetError()
* for more information.
* \returns true on success or false on failure; call SDL_GetError() for more
* information.
*
* \since This function is available since SDL 3.0.0.
* \since This function is available since SDL 3.2.0.
*/
extern SDL_DECLSPEC SDL_bool SDLCALL SDL_SetJoystickVirtualHat(SDL_Joystick *joystick, int hat, Uint8 value);
extern SDL_DECLSPEC bool SDLCALL SDL_SetJoystickVirtualHat(SDL_Joystick *joystick, int hat, Uint8 value);
/**
* Set touchpad finger state on an opened virtual joystick.
@ -585,19 +593,18 @@ extern SDL_DECLSPEC SDL_bool SDLCALL SDL_SetJoystickVirtualHat(SDL_Joystick *joy
* \param touchpad the index of the touchpad on the virtual joystick to
* update.
* \param finger the index of the finger on the touchpad to set.
* \param state `SDL_PRESSED` if the finger is pressed, `SDL_RELEASED` if the
* finger is released.
* \param down true if the finger is pressed, false if the finger is released.
* \param x the x coordinate of the finger on the touchpad, normalized 0 to 1,
* with the origin in the upper left.
* \param y the y coordinate of the finger on the touchpad, normalized 0 to 1,
* with the origin in the upper left.
* \param pressure the pressure of the finger.
* \returns SDL_TRUE on success or SDL_FALSE on failure; call SDL_GetError()
* for more information.
* \returns true on success or false on failure; call SDL_GetError() for more
* information.
*
* \since This function is available since SDL 3.0.0.
* \since This function is available since SDL 3.2.0.
*/
extern SDL_DECLSPEC SDL_bool SDLCALL SDL_SetJoystickVirtualTouchpad(SDL_Joystick *joystick, int touchpad, int finger, Uint8 state, float x, float y, float pressure);
extern SDL_DECLSPEC bool SDLCALL SDL_SetJoystickVirtualTouchpad(SDL_Joystick *joystick, int touchpad, int finger, bool down, float x, float y, float pressure);
/**
* Send a sensor update for an opened virtual joystick.
@ -614,12 +621,12 @@ extern SDL_DECLSPEC SDL_bool SDLCALL SDL_SetJoystickVirtualTouchpad(SDL_Joystick
* the sensor reading.
* \param data the data associated with the sensor reading.
* \param num_values the number of values pointed to by `data`.
* \returns SDL_TRUE on success or SDL_FALSE on failure; call SDL_GetError()
* for more information.
* \returns true on success or false on failure; call SDL_GetError() for more
* information.
*
* \since This function is available since SDL 3.0.0.
* \since This function is available since SDL 3.2.0.
*/
extern SDL_DECLSPEC SDL_bool SDLCALL SDL_SendJoystickVirtualSensorData(SDL_Joystick *joystick, SDL_SensorType type, Uint64 sensor_timestamp, const float *data, int num_values);
extern SDL_DECLSPEC bool SDLCALL SDL_SendJoystickVirtualSensorData(SDL_Joystick *joystick, SDL_SensorType type, Uint64 sensor_timestamp, const float *data, int num_values);
/**
* Get the properties associated with a joystick.
@ -641,7 +648,7 @@ extern SDL_DECLSPEC SDL_bool SDLCALL SDL_SendJoystickVirtualSensorData(SDL_Joyst
* \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.0.0.
* \since This function is available since SDL 3.2.0.
*/
extern SDL_DECLSPEC SDL_PropertiesID SDLCALL SDL_GetJoystickProperties(SDL_Joystick *joystick);
@ -658,7 +665,7 @@ 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.
*
* \since This function is available since SDL 3.0.0.
* \since This function is available since SDL 3.2.0.
*
* \sa SDL_GetJoystickNameForID
*/
@ -671,7 +678,7 @@ 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.
*
* \since This function is available since SDL 3.0.0.
* \since This function is available since SDL 3.2.0.
*
* \sa SDL_GetJoystickPathForID
*/
@ -686,7 +693,7 @@ 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.
*
* \since This function is available since SDL 3.0.0.
* \since This function is available since SDL 3.2.0.
*
* \sa SDL_SetJoystickPlayerIndex
*/
@ -698,14 +705,14 @@ extern SDL_DECLSPEC int SDLCALL SDL_GetJoystickPlayerIndex(SDL_Joystick *joystic
* \param joystick the SDL_Joystick obtained from SDL_OpenJoystick().
* \param player_index player index to assign to this joystick, or -1 to clear
* the player index and turn off player LEDs.
* \returns SDL_TRUE on success or SDL_FALSE on failure; call SDL_GetError()
* for more information.
* \returns true on success or false on failure; call SDL_GetError() for more
* information.
*
* \since This function is available since SDL 3.0.0.
* \since This function is available since SDL 3.2.0.
*
* \sa SDL_GetJoystickPlayerIndex
*/
extern SDL_DECLSPEC SDL_bool SDLCALL SDL_SetJoystickPlayerIndex(SDL_Joystick *joystick, int player_index);
extern SDL_DECLSPEC bool SDLCALL SDL_SetJoystickPlayerIndex(SDL_Joystick *joystick, int player_index);
/**
* Get the implementation-dependent GUID for the joystick.
@ -717,7 +724,7 @@ extern SDL_DECLSPEC SDL_bool SDLCALL SDL_SetJoystickPlayerIndex(SDL_Joystick *jo
* this function returns a zero GUID; call SDL_GetError() for more
* information.
*
* \since This function is available since SDL 3.0.0.
* \since This function is available since SDL 3.2.0.
*
* \sa SDL_GetJoystickGUIDForID
* \sa SDL_GUIDToString
@ -732,7 +739,7 @@ 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.
*
* \since This function is available since SDL 3.0.0.
* \since This function is available since SDL 3.2.0.
*
* \sa SDL_GetJoystickVendorForID
*/
@ -746,7 +753,7 @@ 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.
*
* \since This function is available since SDL 3.0.0.
* \since This function is available since SDL 3.2.0.
*
* \sa SDL_GetJoystickProductForID
*/
@ -760,7 +767,7 @@ 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.
*
* \since This function is available since SDL 3.0.0.
* \since This function is available since SDL 3.2.0.
*
* \sa SDL_GetJoystickProductVersionForID
*/
@ -775,7 +782,7 @@ extern SDL_DECLSPEC Uint16 SDLCALL SDL_GetJoystickProductVersion(SDL_Joystick *j
* \returns the firmware version of the selected joystick, or 0 if
* unavailable.
*
* \since This function is available since SDL 3.0.0.
* \since This function is available since SDL 3.2.0.
*/
extern SDL_DECLSPEC Uint16 SDLCALL SDL_GetJoystickFirmwareVersion(SDL_Joystick *joystick);
@ -788,7 +795,7 @@ extern SDL_DECLSPEC Uint16 SDLCALL SDL_GetJoystickFirmwareVersion(SDL_Joystick *
* \returns the serial number of the selected joystick, or NULL if
* unavailable.
*
* \since This function is available since SDL 3.0.0.
* \since This function is available since SDL 3.2.0.
*/
extern SDL_DECLSPEC const char * SDLCALL SDL_GetJoystickSerial(SDL_Joystick *joystick);
@ -798,7 +805,7 @@ 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.
*
* \since This function is available since SDL 3.0.0.
* \since This function is available since SDL 3.2.0.
*
* \sa SDL_GetJoystickTypeForID
*/
@ -817,7 +824,7 @@ 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.
*
* \since This function is available since SDL 3.0.0.
* \since This function is available since SDL 3.2.0.
*
* \sa SDL_GetJoystickGUIDForID
*/
@ -827,12 +834,12 @@ extern SDL_DECLSPEC void SDLCALL SDL_GetJoystickGUIDInfo(SDL_GUID guid, Uint16 *
* Get the status of a specified joystick.
*
* \param joystick the joystick to query.
* \returns SDL_TRUE if the joystick has been opened, SDL_FALSE if it has not;
* call SDL_GetError() for more information.
* \returns true if the joystick has been opened, false if it has not; call
* SDL_GetError() for more information.
*
* \since This function is available since SDL 3.0.0.
* \since This function is available since SDL 3.2.0.
*/
extern SDL_DECLSPEC SDL_bool SDLCALL SDL_JoystickConnected(SDL_Joystick *joystick);
extern SDL_DECLSPEC bool SDLCALL SDL_JoystickConnected(SDL_Joystick *joystick);
/**
* Get the instance ID of an opened joystick.
@ -841,7 +848,7 @@ extern SDL_DECLSPEC SDL_bool SDLCALL SDL_JoystickConnected(SDL_Joystick *joystic
* \returns the instance ID of the specified joystick on success or 0 on
* failure; call SDL_GetError() for more information.
*
* \since This function is available since SDL 3.0.0.
* \since This function is available since SDL 3.2.0.
*/
extern SDL_DECLSPEC SDL_JoystickID SDLCALL SDL_GetJoystickID(SDL_Joystick *joystick);
@ -856,7 +863,7 @@ 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.
*
* \since This function is available since SDL 3.0.0.
* \since This function is available since SDL 3.2.0.
*
* \sa SDL_GetJoystickAxis
* \sa SDL_GetNumJoystickBalls
@ -877,7 +884,7 @@ 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.
*
* \since This function is available since SDL 3.0.0.
* \since This function is available since SDL 3.2.0.
*
* \sa SDL_GetJoystickBall
* \sa SDL_GetNumJoystickAxes
@ -893,7 +900,7 @@ 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.
*
* \since This function is available since SDL 3.0.0.
* \since This function is available since SDL 3.2.0.
*
* \sa SDL_GetJoystickHat
* \sa SDL_GetNumJoystickAxes
@ -909,7 +916,7 @@ 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.
*
* \since This function is available since SDL 3.0.0.
* \since This function is available since SDL 3.2.0.
*
* \sa SDL_GetJoystickButton
* \sa SDL_GetNumJoystickAxes
@ -927,12 +934,12 @@ extern SDL_DECLSPEC int SDLCALL SDL_GetNumJoystickButtons(SDL_Joystick *joystick
*
* \param enabled whether to process joystick events or not.
*
* \since This function is available since SDL 3.0.0.
* \since This function is available since SDL 3.2.0.
*
* \sa SDL_JoystickEventsEnabled
* \sa SDL_UpdateJoysticks
*/
extern SDL_DECLSPEC void SDLCALL SDL_SetJoystickEventsEnabled(SDL_bool enabled);
extern SDL_DECLSPEC void SDLCALL SDL_SetJoystickEventsEnabled(bool enabled);
/**
* Query the state of joystick event processing.
@ -941,14 +948,13 @@ extern SDL_DECLSPEC void SDLCALL SDL_SetJoystickEventsEnabled(SDL_bool enabled);
* yourself and check the state of the joystick when you want joystick
* information.
*
* \returns SDL_TRUE if joystick events are being processed, SDL_FALSE
* otherwise.
* \returns true if joystick events are being processed, false otherwise.
*
* \since This function is available since SDL 3.0.0.
* \since This function is available since SDL 3.2.0.
*
* \sa SDL_SetJoystickEventsEnabled
*/
extern SDL_DECLSPEC SDL_bool SDLCALL SDL_JoystickEventsEnabled(void);
extern SDL_DECLSPEC bool SDLCALL SDL_JoystickEventsEnabled(void);
/**
* Update the current state of the open joysticks.
@ -956,7 +962,7 @@ extern SDL_DECLSPEC SDL_bool SDLCALL SDL_JoystickEventsEnabled(void);
* This is called automatically by the event loop if any joystick events are
* enabled.
*
* \since This function is available since SDL 3.0.0.
* \since This function is available since SDL 3.2.0.
*/
extern SDL_DECLSPEC void SDLCALL SDL_UpdateJoysticks(void);
@ -978,7 +984,7 @@ 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.
*
* \since This function is available since SDL 3.0.0.
* \since This function is available since SDL 3.2.0.
*
* \sa SDL_GetNumJoystickAxes
*/
@ -994,11 +1000,11 @@ extern SDL_DECLSPEC Sint16 SDLCALL SDL_GetJoystickAxis(SDL_Joystick *joystick, i
* \param joystick an SDL_Joystick structure containing joystick information.
* \param axis the axis to query; the axis indices start at index 0.
* \param state upon return, the initial value is supplied here.
* \returns SDL_TRUE if this axis has any initial value, or SDL_FALSE if not.
* \returns true if this axis has any initial value, or false if not.
*
* \since This function is available since SDL 3.0.0.
* \since This function is available since SDL 3.2.0.
*/
extern SDL_DECLSPEC SDL_bool SDLCALL SDL_GetJoystickAxisInitialState(SDL_Joystick *joystick, int axis, Sint16 *state);
extern SDL_DECLSPEC bool SDLCALL SDL_GetJoystickAxisInitialState(SDL_Joystick *joystick, int axis, Sint16 *state);
/**
* Get the ball axis change since the last poll.
@ -1012,14 +1018,14 @@ extern SDL_DECLSPEC SDL_bool SDLCALL SDL_GetJoystickAxisInitialState(SDL_Joystic
* \param ball the ball index to query; ball indices start at index 0.
* \param dx stores the difference in the x axis position since the last poll.
* \param dy stores the difference in the y axis position since the last poll.
* \returns SDL_TRUE on success or SDL_FALSE on failure; call SDL_GetError()
* for more information.
* \returns true on success or false on failure; call SDL_GetError() for more
* information.
*
* \since This function is available since SDL 3.0.0.
* \since This function is available since SDL 3.2.0.
*
* \sa SDL_GetNumJoystickBalls
*/
extern SDL_DECLSPEC SDL_bool SDLCALL SDL_GetJoystickBall(SDL_Joystick *joystick, int ball, int *dx, int *dy);
extern SDL_DECLSPEC bool SDLCALL SDL_GetJoystickBall(SDL_Joystick *joystick, int ball, int *dx, int *dy);
/**
* Get the current state of a POV hat on a joystick.
@ -1030,7 +1036,7 @@ extern SDL_DECLSPEC SDL_bool SDLCALL SDL_GetJoystickBall(SDL_Joystick *joystick,
* \param hat the hat index to get the state from; indices start at index 0.
* \returns the current hat position.
*
* \since This function is available since SDL 3.0.0.
* \since This function is available since SDL 3.2.0.
*
* \sa SDL_GetNumJoystickHats
*/
@ -1052,13 +1058,13 @@ extern SDL_DECLSPEC Uint8 SDLCALL SDL_GetJoystickHat(SDL_Joystick *joystick, int
* \param joystick an SDL_Joystick structure containing joystick information.
* \param button the button index to get the state from; indices start at
* index 0.
* \returns 1 if the specified button is pressed, 0 otherwise.
* \returns true if the button is pressed, false otherwise.
*
* \since This function is available since SDL 3.0.0.
* \since This function is available since SDL 3.2.0.
*
* \sa SDL_GetNumJoystickButtons
*/
extern SDL_DECLSPEC Uint8 SDLCALL SDL_GetJoystickButton(SDL_Joystick *joystick, int button);
extern SDL_DECLSPEC bool SDLCALL SDL_GetJoystickButton(SDL_Joystick *joystick, int button);
/**
* Start a rumble effect.
@ -1075,11 +1081,11 @@ extern SDL_DECLSPEC Uint8 SDLCALL SDL_GetJoystickButton(SDL_Joystick *joystick,
* \param high_frequency_rumble the intensity of the high frequency (right)
* rumble motor, from 0 to 0xFFFF.
* \param duration_ms the duration of the rumble effect, in milliseconds.
* \returns SDL_TRUE, or SDL_FALSE if rumble isn't supported on this joystick.
* \returns true, or false if rumble isn't supported on this joystick.
*
* \since This function is available since SDL 3.0.0.
* \since This function is available since SDL 3.2.0.
*/
extern SDL_DECLSPEC SDL_bool SDLCALL SDL_RumbleJoystick(SDL_Joystick *joystick, Uint16 low_frequency_rumble, Uint16 high_frequency_rumble, Uint32 duration_ms);
extern SDL_DECLSPEC bool SDLCALL SDL_RumbleJoystick(SDL_Joystick *joystick, Uint16 low_frequency_rumble, Uint16 high_frequency_rumble, Uint32 duration_ms);
/**
* Start a rumble effect in the joystick's triggers.
@ -1101,14 +1107,14 @@ extern SDL_DECLSPEC SDL_bool SDLCALL SDL_RumbleJoystick(SDL_Joystick *joystick,
* \param right_rumble the intensity of the right trigger rumble motor, from 0
* to 0xFFFF.
* \param duration_ms the duration of the rumble effect, in milliseconds.
* \returns SDL_TRUE on success or SDL_FALSE on failure; call SDL_GetError()
* for more information.
* \returns true on success or false on failure; call SDL_GetError() for more
* information.
*
* \since This function is available since SDL 3.0.0.
* \since This function is available since SDL 3.2.0.
*
* \sa SDL_RumbleJoystick
*/
extern SDL_DECLSPEC SDL_bool SDLCALL SDL_RumbleJoystickTriggers(SDL_Joystick *joystick, Uint16 left_rumble, Uint16 right_rumble, Uint32 duration_ms);
extern SDL_DECLSPEC bool SDLCALL SDL_RumbleJoystickTriggers(SDL_Joystick *joystick, Uint16 left_rumble, Uint16 right_rumble, Uint32 duration_ms);
/**
* Update a joystick's LED color.
@ -1123,12 +1129,12 @@ extern SDL_DECLSPEC SDL_bool SDLCALL SDL_RumbleJoystickTriggers(SDL_Joystick *jo
* \param red the intensity of the red LED.
* \param green the intensity of the green LED.
* \param blue the intensity of the blue LED.
* \returns SDL_TRUE on success or SDL_FALSE on failure; call SDL_GetError()
* for more information.
* \returns true on success or false on failure; call SDL_GetError() for more
* information.
*
* \since This function is available since SDL 3.0.0.
* \since This function is available since SDL 3.2.0.
*/
extern SDL_DECLSPEC SDL_bool SDLCALL SDL_SetJoystickLED(SDL_Joystick *joystick, Uint8 red, Uint8 green, Uint8 blue);
extern SDL_DECLSPEC bool SDLCALL SDL_SetJoystickLED(SDL_Joystick *joystick, Uint8 red, Uint8 green, Uint8 blue);
/**
* Send a joystick specific effect packet.
@ -1136,19 +1142,19 @@ extern SDL_DECLSPEC SDL_bool SDLCALL SDL_SetJoystickLED(SDL_Joystick *joystick,
* \param joystick the joystick to affect.
* \param data the data to send to the joystick.
* \param size the size of the data to send to the joystick.
* \returns SDL_TRUE on success or SDL_FALSE on failure; call SDL_GetError()
* for more information.
* \returns true on success or false on failure; call SDL_GetError() for more
* information.
*
* \since This function is available since SDL 3.0.0.
* \since This function is available since SDL 3.2.0.
*/
extern SDL_DECLSPEC SDL_bool SDLCALL SDL_SendJoystickEffect(SDL_Joystick *joystick, const void *data, int size);
extern SDL_DECLSPEC bool SDLCALL SDL_SendJoystickEffect(SDL_Joystick *joystick, const void *data, int size);
/**
* Close a joystick previously opened with SDL_OpenJoystick().
*
* \param joystick the joystick device to close.
*
* \since This function is available since SDL 3.0.0.
* \since This function is available since SDL 3.2.0.
*
* \sa SDL_OpenJoystick
*/
@ -1162,7 +1168,7 @@ extern SDL_DECLSPEC void SDLCALL SDL_CloseJoystick(SDL_Joystick *joystick);
* `SDL_JOYSTICK_CONNECTION_INVALID` on failure; call SDL_GetError()
* for more information.
*
* \since This function is available since SDL 3.0.0.
* \since This function is available since SDL 3.2.0.
*/
extern SDL_DECLSPEC SDL_JoystickConnectionState SDLCALL SDL_GetJoystickConnectionState(SDL_Joystick *joystick);
@ -1183,7 +1189,7 @@ 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.
*
* \since This function is available since SDL 3.0.0.
* \since This function is available since SDL 3.2.0.
*/
extern SDL_DECLSPEC SDL_PowerState SDLCALL SDL_GetJoystickPowerInfo(SDL_Joystick *joystick, int *percent);

View File

@ -1,6 +1,6 @@
/*
Simple DirectMedia Layer
Copyright (C) 1997-2024 Sam Lantinga <slouken@libsdl.org>
Copyright (C) 1997-2025 Sam Lantinga <slouken@libsdl.org>
This software is provided 'as-is', without any express or implied
warranty. In no event will the authors be held liable for any damages
@ -23,6 +23,11 @@
* # CategoryKeyboard
*
* SDL keyboard management.
*
* Please refer to the Best Keyboard Practices document for details on how
* best to accept keyboard input in various types of programs:
*
* https://wiki.libsdl.org/SDL3/BestKeyboardPractices
*/
#ifndef SDL_keyboard_h_
@ -31,6 +36,9 @@
#include <SDL3/SDL_stdinc.h>
#include <SDL3/SDL_error.h>
#include <SDL3/SDL_keycode.h>
#include <SDL3/SDL_properties.h>
#include <SDL3/SDL_rect.h>
#include <SDL3/SDL_scancode.h>
#include <SDL3/SDL_video.h>
#include <SDL3/SDL_begin_code.h>
@ -47,7 +55,7 @@ extern "C" {
*
* The value 0 is an invalid ID.
*
* \since This datatype is available since SDL 3.0.0.
* \since This datatype is available since SDL 3.2.0.
*/
typedef Uint32 SDL_KeyboardID;
@ -56,13 +64,15 @@ typedef Uint32 SDL_KeyboardID;
/**
* Return whether a keyboard is currently connected.
*
* \returns SDL_TRUE if a keyboard is connected, SDL_FALSE otherwise.
* \returns true if a keyboard is connected, false otherwise.
*
* \since This function is available since SDL 3.0.0.
* \threadsafety This function should only be called on the main thread.
*
* \since This function is available since SDL 3.2.0.
*
* \sa SDL_GetKeyboards
*/
extern SDL_DECLSPEC SDL_bool SDLCALL SDL_HasKeyboard(void);
extern SDL_DECLSPEC bool SDLCALL SDL_HasKeyboard(void);
/**
* Get a list of currently connected keyboards.
@ -78,7 +88,9 @@ extern SDL_DECLSPEC SDL_bool SDLCALL SDL_HasKeyboard(void);
* call SDL_GetError() for more information. This should be freed
* with SDL_free() when it is no longer needed.
*
* \since This function is available since SDL 3.0.0.
* \threadsafety This function should only be called on the main thread.
*
* \since This function is available since SDL 3.2.0.
*
* \sa SDL_GetKeyboardNameForID
* \sa SDL_HasKeyboard
@ -94,7 +106,9 @@ extern SDL_DECLSPEC SDL_KeyboardID * SDLCALL SDL_GetKeyboards(int *count);
* \returns the name of the selected keyboard or NULL on failure; call
* SDL_GetError() for more information.
*
* \since This function is available since SDL 3.0.0.
* \threadsafety This function should only be called on the main thread.
*
* \since This function is available since SDL 3.2.0.
*
* \sa SDL_GetKeyboards
*/
@ -105,7 +119,9 @@ extern SDL_DECLSPEC const char * SDLCALL SDL_GetKeyboardNameForID(SDL_KeyboardID
*
* \returns the window with keyboard focus.
*
* \since This function is available since SDL 3.0.0.
* \threadsafety This function should only be called on the main thread.
*
* \since This function is available since SDL 3.2.0.
*/
extern SDL_DECLSPEC SDL_Window * SDLCALL SDL_GetKeyboardFocus(void);
@ -116,9 +132,9 @@ extern SDL_DECLSPEC SDL_Window * SDLCALL SDL_GetKeyboardFocus(void);
* valid for the whole lifetime of the application and should not be freed by
* the caller.
*
* A array element with a value of 1 means that the key is pressed and a value
* of 0 means that it is not. Indexes into this array are obtained by using
* SDL_Scancode values.
* A array element with a value of true means that the key is pressed and a
* value of false means that it is not. Indexes into this array are obtained
* by using SDL_Scancode values.
*
* Use SDL_PumpEvents() to update the state array.
*
@ -133,19 +149,23 @@ extern SDL_DECLSPEC SDL_Window * SDLCALL SDL_GetKeyboardFocus(void);
* \param numkeys if non-NULL, receives the length of the returned array.
* \returns a pointer to an array of key states.
*
* \since This function is available since SDL 3.0.0.
* \threadsafety It is safe to call this function from any thread.
*
* \since This function is available since SDL 3.2.0.
*
* \sa SDL_PumpEvents
* \sa SDL_ResetKeyboard
*/
extern SDL_DECLSPEC const Uint8 * SDLCALL SDL_GetKeyboardState(int *numkeys);
extern SDL_DECLSPEC const bool * SDLCALL SDL_GetKeyboardState(int *numkeys);
/**
* Clear the state of the keyboard.
*
* This function will generate key up events for all pressed keys.
*
* \since This function is available since SDL 3.0.0.
* \threadsafety This function should only be called on the main thread.
*
* \since This function is available since SDL 3.2.0.
*
* \sa SDL_GetKeyboardState
*/
@ -157,7 +177,9 @@ extern SDL_DECLSPEC void SDLCALL SDL_ResetKeyboard(void);
* \returns an OR'd combination of the modifier keys for the keyboard. See
* SDL_Keymod for details.
*
* \since This function is available since SDL 3.0.0.
* \threadsafety It is safe to call this function from any thread.
*
* \since This function is available since SDL 3.2.0.
*
* \sa SDL_GetKeyboardState
* \sa SDL_SetModState
@ -177,7 +199,9 @@ extern SDL_DECLSPEC SDL_Keymod SDLCALL SDL_GetModState(void);
*
* \param modstate the desired SDL_Keymod for the keyboard.
*
* \since This function is available since SDL 3.0.0.
* \threadsafety It is safe to call this function from any thread.
*
* \since This function is available since SDL 3.2.0.
*
* \sa SDL_GetModState
*/
@ -189,21 +213,23 @@ extern SDL_DECLSPEC void SDLCALL SDL_SetModState(SDL_Keymod modstate);
*
* If you want to get the keycode as it would be delivered in key events,
* including options specified in SDL_HINT_KEYCODE_OPTIONS, then you should
* pass `key_event` as SDL_TRUE. Otherwise this function simply translates the
* pass `key_event` as true. Otherwise this function simply translates the
* scancode based on the given modifier state.
*
* \param scancode the desired SDL_Scancode to query.
* \param modstate the modifier state to use when translating the scancode to
* a keycode.
* \param key_event SDL_TRUE if the keycode will be used in key events.
* \param key_event true if the keycode will be used in key events.
* \returns the SDL_Keycode that corresponds to the given SDL_Scancode.
*
* \since This function is available since SDL 3.0.0.
* \threadsafety This function is not thread safe.
*
* \since This function is available since SDL 3.2.0.
*
* \sa SDL_GetKeyName
* \sa SDL_GetScancodeFromKey
*/
extern SDL_DECLSPEC SDL_Keycode SDLCALL SDL_GetKeyFromScancode(SDL_Scancode scancode, SDL_Keymod modstate, SDL_bool key_event);
extern SDL_DECLSPEC SDL_Keycode SDLCALL SDL_GetKeyFromScancode(SDL_Scancode scancode, SDL_Keymod modstate, bool key_event);
/**
* Get the scancode corresponding to the given key code according to the
@ -217,7 +243,9 @@ extern SDL_DECLSPEC SDL_Keycode SDLCALL SDL_GetKeyFromScancode(SDL_Scancode scan
* scancode generates this key, may be NULL.
* \returns the SDL_Scancode that corresponds to the given SDL_Keycode.
*
* \since This function is available since SDL 3.0.0.
* \threadsafety This function is not thread safe.
*
* \since This function is available since SDL 3.2.0.
*
* \sa SDL_GetKeyFromScancode
* \sa SDL_GetScancodeName
@ -231,14 +259,16 @@ extern SDL_DECLSPEC SDL_Scancode SDLCALL SDL_GetScancodeFromKey(SDL_Keycode key,
* \param name the name to use for the scancode, encoded as UTF-8. The string
* is not copied, so the pointer given to this function must stay
* valid while SDL is being used.
* \returns SDL_TRUE on success or SDL_FALSE on failure; call SDL_GetError()
* for more information.
* \returns true on success or false on failure; call SDL_GetError() for more
* information.
*
* \since This function is available since SDL 3.0.0.
* \threadsafety This function is not thread safe.
*
* \since This function is available since SDL 3.2.0.
*
* \sa SDL_GetScancodeName
*/
extern SDL_DECLSPEC SDL_bool SDLCALL SDL_SetScancodeName(SDL_Scancode scancode, const char *name);
extern SDL_DECLSPEC bool SDLCALL SDL_SetScancodeName(SDL_Scancode scancode, const char *name);
/**
* Get a human-readable name for a scancode.
@ -256,7 +286,9 @@ extern SDL_DECLSPEC SDL_bool SDLCALL SDL_SetScancodeName(SDL_Scancode scancode,
* \returns a pointer to the name for the scancode. If the scancode doesn't
* have a name this function returns an empty string ("").
*
* \since This function is available since SDL 3.0.0.
* \threadsafety This function is not thread safe.
*
* \since This function is available since SDL 3.2.0.
*
* \sa SDL_GetScancodeFromKey
* \sa SDL_GetScancodeFromName
@ -271,7 +303,9 @@ extern SDL_DECLSPEC const char * SDLCALL SDL_GetScancodeName(SDL_Scancode scanco
* \returns the SDL_Scancode, or `SDL_SCANCODE_UNKNOWN` if the name wasn't
* recognized; call SDL_GetError() for more information.
*
* \since This function is available since SDL 3.0.0.
* \threadsafety This function is not thread safe.
*
* \since This function is available since SDL 3.2.0.
*
* \sa SDL_GetKeyFromName
* \sa SDL_GetScancodeFromKey
@ -284,10 +318,14 @@ extern SDL_DECLSPEC SDL_Scancode SDLCALL SDL_GetScancodeFromName(const char *nam
*
* If the key doesn't have a name, this function returns an empty string ("").
*
* Letters will be presented in their uppercase form, if applicable.
*
* \param key the desired SDL_Keycode to query.
* \returns a UTF-8 encoded string of the key name.
*
* \since This function is available since SDL 3.0.0.
* \threadsafety This function is not thread safe.
*
* \since This function is available since SDL 3.2.0.
*
* \sa SDL_GetKeyFromName
* \sa SDL_GetKeyFromScancode
@ -302,7 +340,9 @@ extern SDL_DECLSPEC const char * SDLCALL SDL_GetKeyName(SDL_Keycode key);
* \returns key code, or `SDLK_UNKNOWN` if the name wasn't recognized; call
* SDL_GetError() for more information.
*
* \since This function is available since SDL 3.0.0.
* \threadsafety This function is not thread safe.
*
* \since This function is available since SDL 3.2.0.
*
* \sa SDL_GetKeyFromScancode
* \sa SDL_GetKeyName
@ -319,20 +359,24 @@ extern SDL_DECLSPEC SDL_Keycode SDLCALL SDL_GetKeyFromName(const char *name);
*
* Text input events are not received by default.
*
* On some platforms using this function shows the screen keyboard.
* On some platforms using this function shows the screen keyboard and/or
* activates an IME, which can prevent some key press events from being passed
* through.
*
* \param window the window to enable text input.
* \returns SDL_TRUE on success or SDL_FALSE on failure; call SDL_GetError()
* for more information.
* \returns true on success or false on failure; call SDL_GetError() for more
* information.
*
* \since This function is available since SDL 3.0.0.
* \threadsafety This function should only be called on the main thread.
*
* \since This function is available since SDL 3.2.0.
*
* \sa SDL_SetTextInputArea
* \sa SDL_StartTextInputWithProperties
* \sa SDL_StopTextInput
* \sa SDL_TextInputActive
*/
extern SDL_DECLSPEC SDL_bool SDLCALL SDL_StartTextInput(SDL_Window *window);
extern SDL_DECLSPEC bool SDLCALL SDL_StartTextInput(SDL_Window *window);
/**
* Text input type.
@ -341,7 +385,7 @@ extern SDL_DECLSPEC SDL_bool SDLCALL SDL_StartTextInput(SDL_Window *window);
* value is valid on every platform, but where a value isn't supported, a
* reasonable fallback will be used.
*
* \since This enum is available since SDL 3.0.0.
* \since This enum is available since SDL 3.2.0.
*
* \sa SDL_StartTextInputWithProperties
*/
@ -361,12 +405,11 @@ typedef enum SDL_TextInputType
/**
* Auto capitalization type.
*
* These are the valid values for
* SDL_PROP_TEXTINPUT_AUTOCAPITALIZATION_NUMBER. Not every value is valid on
* every platform, but where a value isn't supported, a reasonable fallback
* will be used.
* These are the valid values for SDL_PROP_TEXTINPUT_CAPITALIZATION_NUMBER.
* Not every value is valid on every platform, but where a value isn't
* supported, a reasonable fallback will be used.
*
* \since This enum is available since SDL 3.0.0.
* \since This enum is available since SDL 3.2.0.
*
* \sa SDL_StartTextInputWithProperties
*/
@ -388,7 +431,9 @@ typedef enum SDL_Capitalization
*
* Text input events are not received by default.
*
* On some platforms using this function shows the screen keyboard.
* On some platforms using this function shows the screen keyboard and/or
* activates an IME, which can prevent some key press events from being passed
* through.
*
* These are the supported properties:
*
@ -400,11 +445,11 @@ typedef enum SDL_Capitalization
* SDL_TEXTINPUT_TYPE_TEXT_NAME, and SDL_CAPITALIZE_NONE for e-mail
* addresses, usernames, and passwords.
* - `SDL_PROP_TEXTINPUT_AUTOCORRECT_BOOLEAN` - true to enable auto completion
* and auto correction, defaults to SDL_TRUE.
* and auto correction, defaults to true.
* - `SDL_PROP_TEXTINPUT_MULTILINE_BOOLEAN` - true if multiple lines of text
* are allowed. This defaults to SDL_TRUE if SDL_HINT_RETURN_KEY_HIDES_IME
* is "0" or is not set, and defaults to SDL_FALSE if
* SDL_HINT_RETURN_KEY_HIDES_IME is "1".
* are allowed. This defaults to true if SDL_HINT_RETURN_KEY_HIDES_IME is
* "0" or is not set, and defaults to false if SDL_HINT_RETURN_KEY_HIDES_IME
* is "1".
*
* On Android you can directly specify the input type:
*
@ -414,17 +459,19 @@ typedef enum SDL_Capitalization
*
* \param window the window to enable text input.
* \param props the properties to use.
* \returns SDL_TRUE on success or SDL_FALSE on failure; call SDL_GetError()
* for more information.
* \returns true on success or false on failure; call SDL_GetError() for more
* information.
*
* \since This function is available since SDL 3.0.0.
* \threadsafety This function should only be called on the main thread.
*
* \since This function is available since SDL 3.2.0.
*
* \sa SDL_SetTextInputArea
* \sa SDL_StartTextInput
* \sa SDL_StopTextInput
* \sa SDL_TextInputActive
*/
extern SDL_DECLSPEC SDL_bool SDLCALL SDL_StartTextInputWithProperties(SDL_Window *window, SDL_PropertiesID props);
extern SDL_DECLSPEC bool SDLCALL SDL_StartTextInputWithProperties(SDL_Window *window, SDL_PropertiesID props);
#define SDL_PROP_TEXTINPUT_TYPE_NUMBER "SDL.textinput.type"
#define SDL_PROP_TEXTINPUT_CAPITALIZATION_NUMBER "SDL.textinput.capitalization"
@ -436,13 +483,15 @@ extern SDL_DECLSPEC SDL_bool SDLCALL SDL_StartTextInputWithProperties(SDL_Window
* Check whether or not Unicode text input events are enabled for a window.
*
* \param window the window to check.
* \returns SDL_TRUE if text input events are enabled else SDL_FALSE.
* \returns true if text input events are enabled else false.
*
* \since This function is available since SDL 3.0.0.
* \threadsafety This function should only be called on the main thread.
*
* \since This function is available since SDL 3.2.0.
*
* \sa SDL_StartTextInput
*/
extern SDL_DECLSPEC SDL_bool SDLCALL SDL_TextInputActive(SDL_Window *window);
extern SDL_DECLSPEC bool SDLCALL SDL_TextInputActive(SDL_Window *window);
/**
* Stop receiving any text input events in a window.
@ -451,28 +500,32 @@ extern SDL_DECLSPEC SDL_bool SDLCALL SDL_TextInputActive(SDL_Window *window);
* it.
*
* \param window the window to disable text input.
* \returns SDL_TRUE on success or SDL_FALSE on failure; call SDL_GetError()
* for more information.
* \returns true on success or false on failure; call SDL_GetError() for more
* information.
*
* \since This function is available since SDL 3.0.0.
* \threadsafety This function should only be called on the main thread.
*
* \since This function is available since SDL 3.2.0.
*
* \sa SDL_StartTextInput
*/
extern SDL_DECLSPEC SDL_bool SDLCALL SDL_StopTextInput(SDL_Window *window);
extern SDL_DECLSPEC bool SDLCALL SDL_StopTextInput(SDL_Window *window);
/**
* Dismiss the composition window/IME without disabling the subsystem.
*
* \param window the window to affect.
* \returns SDL_TRUE on success or SDL_FALSE on failure; call SDL_GetError()
* for more information.
* \returns true on success or false on failure; call SDL_GetError() for more
* information.
*
* \since This function is available since SDL 3.0.0.
* \threadsafety This function should only be called on the main thread.
*
* \since This function is available since SDL 3.2.0.
*
* \sa SDL_StartTextInput
* \sa SDL_StopTextInput
*/
extern SDL_DECLSPEC SDL_bool SDLCALL SDL_ClearComposition(SDL_Window *window);
extern SDL_DECLSPEC bool SDLCALL SDL_ClearComposition(SDL_Window *window);
/**
* Set the area used to type Unicode text input.
@ -485,15 +538,17 @@ extern SDL_DECLSPEC SDL_bool SDLCALL SDL_ClearComposition(SDL_Window *window);
* coordinates, or NULL to clear it.
* \param cursor the offset of the current cursor location relative to
* `rect->x`, in window coordinates.
* \returns SDL_TRUE on success or SDL_FALSE on failure; call SDL_GetError()
* for more information.
* \returns true on success or false on failure; call SDL_GetError() for more
* information.
*
* \since This function is available since SDL 3.0.0.
* \threadsafety This function should only be called on the main thread.
*
* \since This function is available since SDL 3.2.0.
*
* \sa SDL_GetTextInputArea
* \sa SDL_StartTextInput
*/
extern SDL_DECLSPEC SDL_bool SDLCALL SDL_SetTextInputArea(SDL_Window *window, const SDL_Rect *rect, int cursor);
extern SDL_DECLSPEC bool SDLCALL SDL_SetTextInputArea(SDL_Window *window, const SDL_Rect *rect, int cursor);
/**
* Get the area used to type Unicode text input.
@ -505,39 +560,45 @@ extern SDL_DECLSPEC SDL_bool SDLCALL SDL_SetTextInputArea(SDL_Window *window, co
* may be NULL.
* \param cursor a pointer to the offset of the current cursor location
* relative to `rect->x`, may be NULL.
* \returns SDL_TRUE on success or SDL_FALSE on failure; call SDL_GetError()
* for more information.
* \returns true on success or false on failure; call SDL_GetError() for more
* information.
*
* \since This function is available since SDL 3.0.0.
* \threadsafety This function should only be called on the main thread.
*
* \since This function is available since SDL 3.2.0.
*
* \sa SDL_SetTextInputArea
*/
extern SDL_DECLSPEC SDL_bool SDLCALL SDL_GetTextInputArea(SDL_Window *window, SDL_Rect *rect, int *cursor);
extern SDL_DECLSPEC bool SDLCALL SDL_GetTextInputArea(SDL_Window *window, SDL_Rect *rect, int *cursor);
/**
* Check whether the platform has screen keyboard support.
*
* \returns SDL_TRUE if the platform has some screen keyboard support or
* SDL_FALSE if not.
* \returns true if the platform has some screen keyboard support or false if
* not.
*
* \since This function is available since SDL 3.0.0.
* \threadsafety This function should only be called on the main thread.
*
* \since This function is available since SDL 3.2.0.
*
* \sa SDL_StartTextInput
* \sa SDL_ScreenKeyboardShown
*/
extern SDL_DECLSPEC SDL_bool SDLCALL SDL_HasScreenKeyboardSupport(void);
extern SDL_DECLSPEC bool SDLCALL SDL_HasScreenKeyboardSupport(void);
/**
* Check whether the screen keyboard is shown for given window.
*
* \param window the window for which screen keyboard should be queried.
* \returns SDL_TRUE if screen keyboard is shown or SDL_FALSE if not.
* \returns true if screen keyboard is shown or false if not.
*
* \since This function is available since SDL 3.0.0.
* \threadsafety This function should only be called on the main thread.
*
* \since This function is available since SDL 3.2.0.
*
* \sa SDL_HasScreenKeyboardSupport
*/
extern SDL_DECLSPEC SDL_bool SDLCALL SDL_ScreenKeyboardShown(SDL_Window *window);
extern SDL_DECLSPEC bool SDLCALL SDL_ScreenKeyboardShown(SDL_Window *window);
/* Ends C function definitions when using C++ */
#ifdef __cplusplus

View File

@ -1,6 +1,6 @@
/*
Simple DirectMedia Layer
Copyright (C) 1997-2024 Sam Lantinga <slouken@libsdl.org>
Copyright (C) 1997-2025 Sam Lantinga <slouken@libsdl.org>
This software is provided 'as-is', without any express or implied
warranty. In no event will the authors be held liable for any damages
@ -23,6 +23,11 @@
* # CategoryKeycode
*
* Defines constants which identify keyboard keys and modifiers.
*
* Please refer to the Best Keyboard Practices document for details on what
* this information means and how best to use it.
*
* https://wiki.libsdl.org/SDL3/BestKeyboardPractices
*/
#ifndef SDL_keycode_h_
@ -42,272 +47,284 @@
* A special exception is the number keys at the top of the keyboard which map
* to SDLK_0...SDLK_9 on AZERTY layouts.
*
* \since This datatype is available since SDL 3.0.0.
* Keys with the `SDLK_EXTENDED_MASK` bit set do not map to a scancode or
* unicode code point.
*
* \since This datatype is available since SDL 3.2.0.
*/
typedef Uint32 SDL_Keycode;
#define SDLK_SCANCODE_MASK (1u<<30)
#define SDLK_EXTENDED_MASK (1u << 29)
#define SDLK_SCANCODE_MASK (1u << 30)
#define SDL_SCANCODE_TO_KEYCODE(X) (X | SDLK_SCANCODE_MASK)
#define SDLK_UNKNOWN 0x00000000u /* 0 */
#define SDLK_RETURN 0x0000000du /* '\r' */
#define SDLK_ESCAPE 0x0000001bu /* '\x1B' */
#define SDLK_BACKSPACE 0x00000008u /* '\b' */
#define SDLK_TAB 0x00000009u /* '\t' */
#define SDLK_SPACE 0x00000020u /* ' ' */
#define SDLK_EXCLAIM 0x00000021u /* '!' */
#define SDLK_DBLAPOSTROPHE 0x00000022u /* '"' */
#define SDLK_HASH 0x00000023u /* '#' */
#define SDLK_DOLLAR 0x00000024u /* '$' */
#define SDLK_PERCENT 0x00000025u /* '%' */
#define SDLK_AMPERSAND 0x00000026u /* '&' */
#define SDLK_APOSTROPHE 0x00000027u /* '\'' */
#define SDLK_LEFTPAREN 0x00000028u /* '(' */
#define SDLK_RIGHTPAREN 0x00000029u /* ')' */
#define SDLK_ASTERISK 0x0000002au /* '*' */
#define SDLK_PLUS 0x0000002bu /* '+' */
#define SDLK_COMMA 0x0000002cu /* ',' */
#define SDLK_MINUS 0x0000002du /* '-' */
#define SDLK_PERIOD 0x0000002eu /* '.' */
#define SDLK_SLASH 0x0000002fu /* '/' */
#define SDLK_0 0x00000030u /* '0' */
#define SDLK_1 0x00000031u /* '1' */
#define SDLK_2 0x00000032u /* '2' */
#define SDLK_3 0x00000033u /* '3' */
#define SDLK_4 0x00000034u /* '4' */
#define SDLK_5 0x00000035u /* '5' */
#define SDLK_6 0x00000036u /* '6' */
#define SDLK_7 0x00000037u /* '7' */
#define SDLK_8 0x00000038u /* '8' */
#define SDLK_9 0x00000039u /* '9' */
#define SDLK_COLON 0x0000003au /* ':' */
#define SDLK_SEMICOLON 0x0000003bu /* ';' */
#define SDLK_LESS 0x0000003cu /* '<' */
#define SDLK_EQUALS 0x0000003du /* '=' */
#define SDLK_GREATER 0x0000003eu /* '>' */
#define SDLK_QUESTION 0x0000003fu /* '?' */
#define SDLK_AT 0x00000040u /* '@' */
#define SDLK_LEFTBRACKET 0x0000005bu /* '[' */
#define SDLK_BACKSLASH 0x0000005cu /* '\\' */
#define SDLK_RIGHTBRACKET 0x0000005du /* ']' */
#define SDLK_CARET 0x0000005eu /* '^' */
#define SDLK_UNDERSCORE 0x0000005fu /* '_' */
#define SDLK_GRAVE 0x00000060u /* '`' */
#define SDLK_A 0x00000061u /* 'a' */
#define SDLK_B 0x00000062u /* 'b' */
#define SDLK_C 0x00000063u /* 'c' */
#define SDLK_D 0x00000064u /* 'd' */
#define SDLK_E 0x00000065u /* 'e' */
#define SDLK_F 0x00000066u /* 'f' */
#define SDLK_G 0x00000067u /* 'g' */
#define SDLK_H 0x00000068u /* 'h' */
#define SDLK_I 0x00000069u /* 'i' */
#define SDLK_J 0x0000006au /* 'j' */
#define SDLK_K 0x0000006bu /* 'k' */
#define SDLK_L 0x0000006cu /* 'l' */
#define SDLK_M 0x0000006du /* 'm' */
#define SDLK_N 0x0000006eu /* 'n' */
#define SDLK_O 0x0000006fu /* 'o' */
#define SDLK_P 0x00000070u /* 'p' */
#define SDLK_Q 0x00000071u /* 'q' */
#define SDLK_R 0x00000072u /* 'r' */
#define SDLK_S 0x00000073u /* 's' */
#define SDLK_T 0x00000074u /* 't' */
#define SDLK_U 0x00000075u /* 'u' */
#define SDLK_V 0x00000076u /* 'v' */
#define SDLK_W 0x00000077u /* 'w' */
#define SDLK_X 0x00000078u /* 'x' */
#define SDLK_Y 0x00000079u /* 'y' */
#define SDLK_Z 0x0000007au /* 'z' */
#define SDLK_LEFTBRACE 0x0000007bu /* '{' */
#define SDLK_PIPE 0x0000007cu /* '|' */
#define SDLK_RIGHTBRACE 0x0000007du /* '}' */
#define SDLK_TILDE 0x0000007eu /* '~' */
#define SDLK_DELETE 0x0000007fu /* '\x7F' */
#define SDLK_PLUSMINUS 0x000000b1u /* '±' */
#define SDLK_CAPSLOCK 0x40000039u /* SDL_SCANCODE_TO_KEYCODE(SDL_SCANCODE_CAPSLOCK) */
#define SDLK_F1 0x4000003au /* SDL_SCANCODE_TO_KEYCODE(SDL_SCANCODE_F1) */
#define SDLK_F2 0x4000003bu /* SDL_SCANCODE_TO_KEYCODE(SDL_SCANCODE_F2) */
#define SDLK_F3 0x4000003cu /* SDL_SCANCODE_TO_KEYCODE(SDL_SCANCODE_F3) */
#define SDLK_F4 0x4000003du /* SDL_SCANCODE_TO_KEYCODE(SDL_SCANCODE_F4) */
#define SDLK_F5 0x4000003eu /* SDL_SCANCODE_TO_KEYCODE(SDL_SCANCODE_F5) */
#define SDLK_F6 0x4000003fu /* SDL_SCANCODE_TO_KEYCODE(SDL_SCANCODE_F6) */
#define SDLK_F7 0x40000040u /* SDL_SCANCODE_TO_KEYCODE(SDL_SCANCODE_F7) */
#define SDLK_F8 0x40000041u /* SDL_SCANCODE_TO_KEYCODE(SDL_SCANCODE_F8) */
#define SDLK_F9 0x40000042u /* SDL_SCANCODE_TO_KEYCODE(SDL_SCANCODE_F9) */
#define SDLK_F10 0x40000043u /* SDL_SCANCODE_TO_KEYCODE(SDL_SCANCODE_F10) */
#define SDLK_F11 0x40000044u /* SDL_SCANCODE_TO_KEYCODE(SDL_SCANCODE_F11) */
#define SDLK_F12 0x40000045u /* SDL_SCANCODE_TO_KEYCODE(SDL_SCANCODE_F12) */
#define SDLK_PRINTSCREEN 0x40000046u /* SDL_SCANCODE_TO_KEYCODE(SDL_SCANCODE_PRINTSCREEN) */
#define SDLK_SCROLLLOCK 0x40000047u /* SDL_SCANCODE_TO_KEYCODE(SDL_SCANCODE_SCROLLLOCK) */
#define SDLK_PAUSE 0x40000048u /* SDL_SCANCODE_TO_KEYCODE(SDL_SCANCODE_PAUSE) */
#define SDLK_INSERT 0x40000049u /* SDL_SCANCODE_TO_KEYCODE(SDL_SCANCODE_INSERT) */
#define SDLK_HOME 0x4000004au /* SDL_SCANCODE_TO_KEYCODE(SDL_SCANCODE_HOME) */
#define SDLK_PAGEUP 0x4000004bu /* SDL_SCANCODE_TO_KEYCODE(SDL_SCANCODE_PAGEUP) */
#define SDLK_END 0x4000004du /* SDL_SCANCODE_TO_KEYCODE(SDL_SCANCODE_END) */
#define SDLK_PAGEDOWN 0x4000004eu /* SDL_SCANCODE_TO_KEYCODE(SDL_SCANCODE_PAGEDOWN) */
#define SDLK_RIGHT 0x4000004fu /* SDL_SCANCODE_TO_KEYCODE(SDL_SCANCODE_RIGHT) */
#define SDLK_LEFT 0x40000050u /* SDL_SCANCODE_TO_KEYCODE(SDL_SCANCODE_LEFT) */
#define SDLK_DOWN 0x40000051u /* SDL_SCANCODE_TO_KEYCODE(SDL_SCANCODE_DOWN) */
#define SDLK_UP 0x40000052u /* SDL_SCANCODE_TO_KEYCODE(SDL_SCANCODE_UP) */
#define SDLK_NUMLOCKCLEAR 0x40000053u /* SDL_SCANCODE_TO_KEYCODE(SDL_SCANCODE_NUMLOCKCLEAR) */
#define SDLK_KP_DIVIDE 0x40000054u /* SDL_SCANCODE_TO_KEYCODE(SDL_SCANCODE_KP_DIVIDE) */
#define SDLK_KP_MULTIPLY 0x40000055u /* SDL_SCANCODE_TO_KEYCODE(SDL_SCANCODE_KP_MULTIPLY) */
#define SDLK_KP_MINUS 0x40000056u /* SDL_SCANCODE_TO_KEYCODE(SDL_SCANCODE_KP_MINUS) */
#define SDLK_KP_PLUS 0x40000057u /* SDL_SCANCODE_TO_KEYCODE(SDL_SCANCODE_KP_PLUS) */
#define SDLK_KP_ENTER 0x40000058u /* SDL_SCANCODE_TO_KEYCODE(SDL_SCANCODE_KP_ENTER) */
#define SDLK_KP_1 0x40000059u /* SDL_SCANCODE_TO_KEYCODE(SDL_SCANCODE_KP_1) */
#define SDLK_KP_2 0x4000005au /* SDL_SCANCODE_TO_KEYCODE(SDL_SCANCODE_KP_2) */
#define SDLK_KP_3 0x4000005bu /* SDL_SCANCODE_TO_KEYCODE(SDL_SCANCODE_KP_3) */
#define SDLK_KP_4 0x4000005cu /* SDL_SCANCODE_TO_KEYCODE(SDL_SCANCODE_KP_4) */
#define SDLK_KP_5 0x4000005du /* SDL_SCANCODE_TO_KEYCODE(SDL_SCANCODE_KP_5) */
#define SDLK_KP_6 0x4000005eu /* SDL_SCANCODE_TO_KEYCODE(SDL_SCANCODE_KP_6) */
#define SDLK_KP_7 0x4000005fu /* SDL_SCANCODE_TO_KEYCODE(SDL_SCANCODE_KP_7) */
#define SDLK_KP_8 0x40000060u /* SDL_SCANCODE_TO_KEYCODE(SDL_SCANCODE_KP_8) */
#define SDLK_KP_9 0x40000061u /* SDL_SCANCODE_TO_KEYCODE(SDL_SCANCODE_KP_9) */
#define SDLK_KP_0 0x40000062u /* SDL_SCANCODE_TO_KEYCODE(SDL_SCANCODE_KP_0) */
#define SDLK_KP_PERIOD 0x40000063u /* SDL_SCANCODE_TO_KEYCODE(SDL_SCANCODE_KP_PERIOD) */
#define SDLK_APPLICATION 0x40000065u /* SDL_SCANCODE_TO_KEYCODE(SDL_SCANCODE_APPLICATION) */
#define SDLK_POWER 0x40000066u /* SDL_SCANCODE_TO_KEYCODE(SDL_SCANCODE_POWER) */
#define SDLK_KP_EQUALS 0x40000067u /* SDL_SCANCODE_TO_KEYCODE(SDL_SCANCODE_KP_EQUALS) */
#define SDLK_F13 0x40000068u /* SDL_SCANCODE_TO_KEYCODE(SDL_SCANCODE_F13) */
#define SDLK_F14 0x40000069u /* SDL_SCANCODE_TO_KEYCODE(SDL_SCANCODE_F14) */
#define SDLK_F15 0x4000006au /* SDL_SCANCODE_TO_KEYCODE(SDL_SCANCODE_F15) */
#define SDLK_F16 0x4000006bu /* SDL_SCANCODE_TO_KEYCODE(SDL_SCANCODE_F16) */
#define SDLK_F17 0x4000006cu /* SDL_SCANCODE_TO_KEYCODE(SDL_SCANCODE_F17) */
#define SDLK_F18 0x4000006du /* SDL_SCANCODE_TO_KEYCODE(SDL_SCANCODE_F18) */
#define SDLK_F19 0x4000006eu /* SDL_SCANCODE_TO_KEYCODE(SDL_SCANCODE_F19) */
#define SDLK_F20 0x4000006fu /* SDL_SCANCODE_TO_KEYCODE(SDL_SCANCODE_F20) */
#define SDLK_F21 0x40000070u /* SDL_SCANCODE_TO_KEYCODE(SDL_SCANCODE_F21) */
#define SDLK_F22 0x40000071u /* SDL_SCANCODE_TO_KEYCODE(SDL_SCANCODE_F22) */
#define SDLK_F23 0x40000072u /* SDL_SCANCODE_TO_KEYCODE(SDL_SCANCODE_F23) */
#define SDLK_F24 0x40000073u /* SDL_SCANCODE_TO_KEYCODE(SDL_SCANCODE_F24) */
#define SDLK_EXECUTE 0x40000074u /* SDL_SCANCODE_TO_KEYCODE(SDL_SCANCODE_EXECUTE) */
#define SDLK_HELP 0x40000075u /* SDL_SCANCODE_TO_KEYCODE(SDL_SCANCODE_HELP) */
#define SDLK_MENU 0x40000076u /* SDL_SCANCODE_TO_KEYCODE(SDL_SCANCODE_MENU) */
#define SDLK_SELECT 0x40000077u /* SDL_SCANCODE_TO_KEYCODE(SDL_SCANCODE_SELECT) */
#define SDLK_STOP 0x40000078u /* SDL_SCANCODE_TO_KEYCODE(SDL_SCANCODE_STOP) */
#define SDLK_AGAIN 0x40000079u /* SDL_SCANCODE_TO_KEYCODE(SDL_SCANCODE_AGAIN) */
#define SDLK_UNDO 0x4000007au /* SDL_SCANCODE_TO_KEYCODE(SDL_SCANCODE_UNDO) */
#define SDLK_CUT 0x4000007bu /* SDL_SCANCODE_TO_KEYCODE(SDL_SCANCODE_CUT) */
#define SDLK_COPY 0x4000007cu /* SDL_SCANCODE_TO_KEYCODE(SDL_SCANCODE_COPY) */
#define SDLK_PASTE 0x4000007du /* SDL_SCANCODE_TO_KEYCODE(SDL_SCANCODE_PASTE) */
#define SDLK_FIND 0x4000007eu /* SDL_SCANCODE_TO_KEYCODE(SDL_SCANCODE_FIND) */
#define SDLK_MUTE 0x4000007fu /* SDL_SCANCODE_TO_KEYCODE(SDL_SCANCODE_MUTE) */
#define SDLK_VOLUMEUP 0x40000080u /* SDL_SCANCODE_TO_KEYCODE(SDL_SCANCODE_VOLUMEUP) */
#define SDLK_VOLUMEDOWN 0x40000081u /* SDL_SCANCODE_TO_KEYCODE(SDL_SCANCODE_VOLUMEDOWN) */
#define SDLK_KP_COMMA 0x40000085u /* SDL_SCANCODE_TO_KEYCODE(SDL_SCANCODE_KP_COMMA) */
#define SDLK_KP_EQUALSAS400 0x40000086u /* SDL_SCANCODE_TO_KEYCODE(SDL_SCANCODE_KP_EQUALSAS400) */
#define SDLK_ALTERASE 0x40000099u /* SDL_SCANCODE_TO_KEYCODE(SDL_SCANCODE_ALTERASE) */
#define SDLK_SYSREQ 0x4000009au /* SDL_SCANCODE_TO_KEYCODE(SDL_SCANCODE_SYSREQ) */
#define SDLK_CANCEL 0x4000009bu /* SDL_SCANCODE_TO_KEYCODE(SDL_SCANCODE_CANCEL) */
#define SDLK_CLEAR 0x4000009cu /* SDL_SCANCODE_TO_KEYCODE(SDL_SCANCODE_CLEAR) */
#define SDLK_PRIOR 0x4000009du /* SDL_SCANCODE_TO_KEYCODE(SDL_SCANCODE_PRIOR) */
#define SDLK_RETURN2 0x4000009eu /* SDL_SCANCODE_TO_KEYCODE(SDL_SCANCODE_RETURN2) */
#define SDLK_SEPARATOR 0x4000009fu /* SDL_SCANCODE_TO_KEYCODE(SDL_SCANCODE_SEPARATOR) */
#define SDLK_OUT 0x400000a0u /* SDL_SCANCODE_TO_KEYCODE(SDL_SCANCODE_OUT) */
#define SDLK_OPER 0x400000a1u /* SDL_SCANCODE_TO_KEYCODE(SDL_SCANCODE_OPER) */
#define SDLK_CLEARAGAIN 0x400000a2u /* SDL_SCANCODE_TO_KEYCODE(SDL_SCANCODE_CLEARAGAIN) */
#define SDLK_CRSEL 0x400000a3u /* SDL_SCANCODE_TO_KEYCODE(SDL_SCANCODE_CRSEL) */
#define SDLK_EXSEL 0x400000a4u /* SDL_SCANCODE_TO_KEYCODE(SDL_SCANCODE_EXSEL) */
#define SDLK_KP_00 0x400000b0u /* SDL_SCANCODE_TO_KEYCODE(SDL_SCANCODE_KP_00) */
#define SDLK_KP_000 0x400000b1u /* SDL_SCANCODE_TO_KEYCODE(SDL_SCANCODE_KP_000) */
#define SDLK_THOUSANDSSEPARATOR 0x400000b2u /* SDL_SCANCODE_TO_KEYCODE(SDL_SCANCODE_THOUSANDSSEPARATOR) */
#define SDLK_DECIMALSEPARATOR 0x400000b3u /* SDL_SCANCODE_TO_KEYCODE(SDL_SCANCODE_DECIMALSEPARATOR) */
#define SDLK_CURRENCYUNIT 0x400000b4u /* SDL_SCANCODE_TO_KEYCODE(SDL_SCANCODE_CURRENCYUNIT) */
#define SDLK_CURRENCYSUBUNIT 0x400000b5u /* SDL_SCANCODE_TO_KEYCODE(SDL_SCANCODE_CURRENCYSUBUNIT) */
#define SDLK_KP_LEFTPAREN 0x400000b6u /* SDL_SCANCODE_TO_KEYCODE(SDL_SCANCODE_KP_LEFTPAREN) */
#define SDLK_KP_RIGHTPAREN 0x400000b7u /* SDL_SCANCODE_TO_KEYCODE(SDL_SCANCODE_KP_RIGHTPAREN) */
#define SDLK_KP_LEFTBRACE 0x400000b8u /* SDL_SCANCODE_TO_KEYCODE(SDL_SCANCODE_KP_LEFTBRACE) */
#define SDLK_KP_RIGHTBRACE 0x400000b9u /* SDL_SCANCODE_TO_KEYCODE(SDL_SCANCODE_KP_RIGHTBRACE) */
#define SDLK_KP_TAB 0x400000bau /* SDL_SCANCODE_TO_KEYCODE(SDL_SCANCODE_KP_TAB) */
#define SDLK_KP_BACKSPACE 0x400000bbu /* SDL_SCANCODE_TO_KEYCODE(SDL_SCANCODE_KP_BACKSPACE) */
#define SDLK_KP_A 0x400000bcu /* SDL_SCANCODE_TO_KEYCODE(SDL_SCANCODE_KP_A) */
#define SDLK_KP_B 0x400000bdu /* SDL_SCANCODE_TO_KEYCODE(SDL_SCANCODE_KP_B) */
#define SDLK_KP_C 0x400000beu /* SDL_SCANCODE_TO_KEYCODE(SDL_SCANCODE_KP_C) */
#define SDLK_KP_D 0x400000bfu /* SDL_SCANCODE_TO_KEYCODE(SDL_SCANCODE_KP_D) */
#define SDLK_KP_E 0x400000c0u /* SDL_SCANCODE_TO_KEYCODE(SDL_SCANCODE_KP_E) */
#define SDLK_KP_F 0x400000c1u /* SDL_SCANCODE_TO_KEYCODE(SDL_SCANCODE_KP_F) */
#define SDLK_KP_XOR 0x400000c2u /* SDL_SCANCODE_TO_KEYCODE(SDL_SCANCODE_KP_XOR) */
#define SDLK_KP_POWER 0x400000c3u /* SDL_SCANCODE_TO_KEYCODE(SDL_SCANCODE_KP_POWER) */
#define SDLK_KP_PERCENT 0x400000c4u /* SDL_SCANCODE_TO_KEYCODE(SDL_SCANCODE_KP_PERCENT) */
#define SDLK_KP_LESS 0x400000c5u /* SDL_SCANCODE_TO_KEYCODE(SDL_SCANCODE_KP_LESS) */
#define SDLK_KP_GREATER 0x400000c6u /* SDL_SCANCODE_TO_KEYCODE(SDL_SCANCODE_KP_GREATER) */
#define SDLK_KP_AMPERSAND 0x400000c7u /* SDL_SCANCODE_TO_KEYCODE(SDL_SCANCODE_KP_AMPERSAND) */
#define SDLK_KP_DBLAMPERSAND 0x400000c8u /* SDL_SCANCODE_TO_KEYCODE(SDL_SCANCODE_KP_DBLAMPERSAND) */
#define SDLK_KP_VERTICALBAR 0x400000c9u /* SDL_SCANCODE_TO_KEYCODE(SDL_SCANCODE_KP_VERTICALBAR) */
#define SDLK_KP_DBLVERTICALBAR 0x400000cau /* SDL_SCANCODE_TO_KEYCODE(SDL_SCANCODE_KP_DBLVERTICALBAR) */
#define SDLK_KP_COLON 0x400000cbu /* SDL_SCANCODE_TO_KEYCODE(SDL_SCANCODE_KP_COLON) */
#define SDLK_KP_HASH 0x400000ccu /* SDL_SCANCODE_TO_KEYCODE(SDL_SCANCODE_KP_HASH) */
#define SDLK_KP_SPACE 0x400000cdu /* SDL_SCANCODE_TO_KEYCODE(SDL_SCANCODE_KP_SPACE) */
#define SDLK_KP_AT 0x400000ceu /* SDL_SCANCODE_TO_KEYCODE(SDL_SCANCODE_KP_AT) */
#define SDLK_KP_EXCLAM 0x400000cfu /* SDL_SCANCODE_TO_KEYCODE(SDL_SCANCODE_KP_EXCLAM) */
#define SDLK_KP_MEMSTORE 0x400000d0u /* SDL_SCANCODE_TO_KEYCODE(SDL_SCANCODE_KP_MEMSTORE) */
#define SDLK_KP_MEMRECALL 0x400000d1u /* SDL_SCANCODE_TO_KEYCODE(SDL_SCANCODE_KP_MEMRECALL) */
#define SDLK_KP_MEMCLEAR 0x400000d2u /* SDL_SCANCODE_TO_KEYCODE(SDL_SCANCODE_KP_MEMCLEAR) */
#define SDLK_KP_MEMADD 0x400000d3u /* SDL_SCANCODE_TO_KEYCODE(SDL_SCANCODE_KP_MEMADD) */
#define SDLK_KP_MEMSUBTRACT 0x400000d4u /* SDL_SCANCODE_TO_KEYCODE(SDL_SCANCODE_KP_MEMSUBTRACT) */
#define SDLK_KP_MEMMULTIPLY 0x400000d5u /* SDL_SCANCODE_TO_KEYCODE(SDL_SCANCODE_KP_MEMMULTIPLY) */
#define SDLK_KP_MEMDIVIDE 0x400000d6u /* SDL_SCANCODE_TO_KEYCODE(SDL_SCANCODE_KP_MEMDIVIDE) */
#define SDLK_KP_PLUSMINUS 0x400000d7u /* SDL_SCANCODE_TO_KEYCODE(SDL_SCANCODE_KP_PLUSMINUS) */
#define SDLK_KP_CLEAR 0x400000d8u /* SDL_SCANCODE_TO_KEYCODE(SDL_SCANCODE_KP_CLEAR) */
#define SDLK_KP_CLEARENTRY 0x400000d9u /* SDL_SCANCODE_TO_KEYCODE(SDL_SCANCODE_KP_CLEARENTRY) */
#define SDLK_KP_BINARY 0x400000dau /* SDL_SCANCODE_TO_KEYCODE(SDL_SCANCODE_KP_BINARY) */
#define SDLK_KP_OCTAL 0x400000dbu /* SDL_SCANCODE_TO_KEYCODE(SDL_SCANCODE_KP_OCTAL) */
#define SDLK_KP_DECIMAL 0x400000dcu /* SDL_SCANCODE_TO_KEYCODE(SDL_SCANCODE_KP_DECIMAL) */
#define SDLK_KP_HEXADECIMAL 0x400000ddu /* SDL_SCANCODE_TO_KEYCODE(SDL_SCANCODE_KP_HEXADECIMAL) */
#define SDLK_LCTRL 0x400000e0u /* SDL_SCANCODE_TO_KEYCODE(SDL_SCANCODE_LCTRL) */
#define SDLK_LSHIFT 0x400000e1u /* SDL_SCANCODE_TO_KEYCODE(SDL_SCANCODE_LSHIFT) */
#define SDLK_LALT 0x400000e2u /* SDL_SCANCODE_TO_KEYCODE(SDL_SCANCODE_LALT) */
#define SDLK_LGUI 0x400000e3u /* SDL_SCANCODE_TO_KEYCODE(SDL_SCANCODE_LGUI) */
#define SDLK_RCTRL 0x400000e4u /* SDL_SCANCODE_TO_KEYCODE(SDL_SCANCODE_RCTRL) */
#define SDLK_RSHIFT 0x400000e5u /* SDL_SCANCODE_TO_KEYCODE(SDL_SCANCODE_RSHIFT) */
#define SDLK_RALT 0x400000e6u /* SDL_SCANCODE_TO_KEYCODE(SDL_SCANCODE_RALT) */
#define SDLK_RGUI 0x400000e7u /* SDL_SCANCODE_TO_KEYCODE(SDL_SCANCODE_RGUI) */
#define SDLK_MODE 0x40000101u /* SDL_SCANCODE_TO_KEYCODE(SDL_SCANCODE_MODE) */
#define SDLK_SLEEP 0x40000102u /* SDL_SCANCODE_TO_KEYCODE(SDL_SCANCODE_SLEEP) */
#define SDLK_WAKE 0x40000103u /* SDL_SCANCODE_TO_KEYCODE(SDL_SCANCODE_WAKE) */
#define SDLK_CHANNEL_INCREMENT 0x40000104u /* SDL_SCANCODE_TO_KEYCODE(SDL_SCANCODE_CHANNEL_INCREMENT) */
#define SDLK_CHANNEL_DECREMENT 0x40000105u /* SDL_SCANCODE_TO_KEYCODE(SDL_SCANCODE_CHANNEL_DECREMENT) */
#define SDLK_MEDIA_PLAY 0x40000106u /* SDL_SCANCODE_TO_KEYCODE(SDL_SCANCODE_MEDIA_PLAY) */
#define SDLK_MEDIA_PAUSE 0x40000107u /* SDL_SCANCODE_TO_KEYCODE(SDL_SCANCODE_MEDIA_PAUSE) */
#define SDLK_MEDIA_RECORD 0x40000108u /* SDL_SCANCODE_TO_KEYCODE(SDL_SCANCODE_MEDIA_RECORD) */
#define SDLK_MEDIA_FAST_FORWARD 0x40000109u /* SDL_SCANCODE_TO_KEYCODE(SDL_SCANCODE_MEDIA_FAST_FORWARD) */
#define SDLK_MEDIA_REWIND 0x4000010au /* SDL_SCANCODE_TO_KEYCODE(SDL_SCANCODE_MEDIA_REWIND) */
#define SDLK_MEDIA_NEXT_TRACK 0x4000010bu /* SDL_SCANCODE_TO_KEYCODE(SDL_SCANCODE_MEDIA_NEXT_TRACK) */
#define SDLK_MEDIA_PREVIOUS_TRACK 0x4000010cu /* SDL_SCANCODE_TO_KEYCODE(SDL_SCANCODE_MEDIA_PREVIOUS_TRACK) */
#define SDLK_MEDIA_STOP 0x4000010du /* SDL_SCANCODE_TO_KEYCODE(SDL_SCANCODE_MEDIA_STOP) */
#define SDLK_MEDIA_EJECT 0x4000010eu /* SDL_SCANCODE_TO_KEYCODE(SDL_SCANCODE_MEDIA_EJECT) */
#define SDLK_MEDIA_PLAY_PAUSE 0x4000010fu /* SDL_SCANCODE_TO_KEYCODE(SDL_SCANCODE_MEDIA_PLAY_PAUSE) */
#define SDLK_MEDIA_SELECT 0x40000110u /* SDL_SCANCODE_TO_KEYCODE(SDL_SCANCODE_MEDIA_SELECT) */
#define SDLK_AC_NEW 0x40000111u /* SDL_SCANCODE_TO_KEYCODE(SDL_SCANCODE_AC_NEW) */
#define SDLK_AC_OPEN 0x40000112u /* SDL_SCANCODE_TO_KEYCODE(SDL_SCANCODE_AC_OPEN) */
#define SDLK_AC_CLOSE 0x40000113u /* SDL_SCANCODE_TO_KEYCODE(SDL_SCANCODE_AC_CLOSE) */
#define SDLK_AC_EXIT 0x40000114u /* SDL_SCANCODE_TO_KEYCODE(SDL_SCANCODE_AC_EXIT) */
#define SDLK_AC_SAVE 0x40000115u /* SDL_SCANCODE_TO_KEYCODE(SDL_SCANCODE_AC_SAVE) */
#define SDLK_AC_PRINT 0x40000116u /* SDL_SCANCODE_TO_KEYCODE(SDL_SCANCODE_AC_PRINT) */
#define SDLK_AC_PROPERTIES 0x40000117u /* SDL_SCANCODE_TO_KEYCODE(SDL_SCANCODE_AC_PROPERTIES) */
#define SDLK_AC_SEARCH 0x40000118u /* SDL_SCANCODE_TO_KEYCODE(SDL_SCANCODE_AC_SEARCH) */
#define SDLK_AC_HOME 0x40000119u /* SDL_SCANCODE_TO_KEYCODE(SDL_SCANCODE_AC_HOME) */
#define SDLK_AC_BACK 0x4000011au /* SDL_SCANCODE_TO_KEYCODE(SDL_SCANCODE_AC_BACK) */
#define SDLK_AC_FORWARD 0x4000011bu /* SDL_SCANCODE_TO_KEYCODE(SDL_SCANCODE_AC_FORWARD) */
#define SDLK_AC_STOP 0x4000011cu /* SDL_SCANCODE_TO_KEYCODE(SDL_SCANCODE_AC_STOP) */
#define SDLK_AC_REFRESH 0x4000011du /* SDL_SCANCODE_TO_KEYCODE(SDL_SCANCODE_AC_REFRESH) */
#define SDLK_AC_BOOKMARKS 0x4000011eu /* SDL_SCANCODE_TO_KEYCODE(SDL_SCANCODE_AC_BOOKMARKS) */
#define SDLK_SOFTLEFT 0x4000011fu /* SDL_SCANCODE_TO_KEYCODE(SDL_SCANCODE_SOFTLEFT) */
#define SDLK_SOFTRIGHT 0x40000120u /* SDL_SCANCODE_TO_KEYCODE(SDL_SCANCODE_SOFTRIGHT) */
#define SDLK_CALL 0x40000121u /* SDL_SCANCODE_TO_KEYCODE(SDL_SCANCODE_CALL) */
#define SDLK_ENDCALL 0x40000122u /* SDL_SCANCODE_TO_KEYCODE(SDL_SCANCODE_ENDCALL) */
#define SDLK_UNKNOWN 0x00000000u /**< 0 */
#define SDLK_RETURN 0x0000000du /**< '\r' */
#define SDLK_ESCAPE 0x0000001bu /**< '\x1B' */
#define SDLK_BACKSPACE 0x00000008u /**< '\b' */
#define SDLK_TAB 0x00000009u /**< '\t' */
#define SDLK_SPACE 0x00000020u /**< ' ' */
#define SDLK_EXCLAIM 0x00000021u /**< '!' */
#define SDLK_DBLAPOSTROPHE 0x00000022u /**< '"' */
#define SDLK_HASH 0x00000023u /**< '#' */
#define SDLK_DOLLAR 0x00000024u /**< '$' */
#define SDLK_PERCENT 0x00000025u /**< '%' */
#define SDLK_AMPERSAND 0x00000026u /**< '&' */
#define SDLK_APOSTROPHE 0x00000027u /**< '\'' */
#define SDLK_LEFTPAREN 0x00000028u /**< '(' */
#define SDLK_RIGHTPAREN 0x00000029u /**< ')' */
#define SDLK_ASTERISK 0x0000002au /**< '*' */
#define SDLK_PLUS 0x0000002bu /**< '+' */
#define SDLK_COMMA 0x0000002cu /**< ',' */
#define SDLK_MINUS 0x0000002du /**< '-' */
#define SDLK_PERIOD 0x0000002eu /**< '.' */
#define SDLK_SLASH 0x0000002fu /**< '/' */
#define SDLK_0 0x00000030u /**< '0' */
#define SDLK_1 0x00000031u /**< '1' */
#define SDLK_2 0x00000032u /**< '2' */
#define SDLK_3 0x00000033u /**< '3' */
#define SDLK_4 0x00000034u /**< '4' */
#define SDLK_5 0x00000035u /**< '5' */
#define SDLK_6 0x00000036u /**< '6' */
#define SDLK_7 0x00000037u /**< '7' */
#define SDLK_8 0x00000038u /**< '8' */
#define SDLK_9 0x00000039u /**< '9' */
#define SDLK_COLON 0x0000003au /**< ':' */
#define SDLK_SEMICOLON 0x0000003bu /**< ';' */
#define SDLK_LESS 0x0000003cu /**< '<' */
#define SDLK_EQUALS 0x0000003du /**< '=' */
#define SDLK_GREATER 0x0000003eu /**< '>' */
#define SDLK_QUESTION 0x0000003fu /**< '?' */
#define SDLK_AT 0x00000040u /**< '@' */
#define SDLK_LEFTBRACKET 0x0000005bu /**< '[' */
#define SDLK_BACKSLASH 0x0000005cu /**< '\\' */
#define SDLK_RIGHTBRACKET 0x0000005du /**< ']' */
#define SDLK_CARET 0x0000005eu /**< '^' */
#define SDLK_UNDERSCORE 0x0000005fu /**< '_' */
#define SDLK_GRAVE 0x00000060u /**< '`' */
#define SDLK_A 0x00000061u /**< 'a' */
#define SDLK_B 0x00000062u /**< 'b' */
#define SDLK_C 0x00000063u /**< 'c' */
#define SDLK_D 0x00000064u /**< 'd' */
#define SDLK_E 0x00000065u /**< 'e' */
#define SDLK_F 0x00000066u /**< 'f' */
#define SDLK_G 0x00000067u /**< 'g' */
#define SDLK_H 0x00000068u /**< 'h' */
#define SDLK_I 0x00000069u /**< 'i' */
#define SDLK_J 0x0000006au /**< 'j' */
#define SDLK_K 0x0000006bu /**< 'k' */
#define SDLK_L 0x0000006cu /**< 'l' */
#define SDLK_M 0x0000006du /**< 'm' */
#define SDLK_N 0x0000006eu /**< 'n' */
#define SDLK_O 0x0000006fu /**< 'o' */
#define SDLK_P 0x00000070u /**< 'p' */
#define SDLK_Q 0x00000071u /**< 'q' */
#define SDLK_R 0x00000072u /**< 'r' */
#define SDLK_S 0x00000073u /**< 's' */
#define SDLK_T 0x00000074u /**< 't' */
#define SDLK_U 0x00000075u /**< 'u' */
#define SDLK_V 0x00000076u /**< 'v' */
#define SDLK_W 0x00000077u /**< 'w' */
#define SDLK_X 0x00000078u /**< 'x' */
#define SDLK_Y 0x00000079u /**< 'y' */
#define SDLK_Z 0x0000007au /**< 'z' */
#define SDLK_LEFTBRACE 0x0000007bu /**< '{' */
#define SDLK_PIPE 0x0000007cu /**< '|' */
#define SDLK_RIGHTBRACE 0x0000007du /**< '}' */
#define SDLK_TILDE 0x0000007eu /**< '~' */
#define SDLK_DELETE 0x0000007fu /**< '\x7F' */
#define SDLK_PLUSMINUS 0x000000b1u /**< '\xB1' */
#define SDLK_CAPSLOCK 0x40000039u /**< SDL_SCANCODE_TO_KEYCODE(SDL_SCANCODE_CAPSLOCK) */
#define SDLK_F1 0x4000003au /**< SDL_SCANCODE_TO_KEYCODE(SDL_SCANCODE_F1) */
#define SDLK_F2 0x4000003bu /**< SDL_SCANCODE_TO_KEYCODE(SDL_SCANCODE_F2) */
#define SDLK_F3 0x4000003cu /**< SDL_SCANCODE_TO_KEYCODE(SDL_SCANCODE_F3) */
#define SDLK_F4 0x4000003du /**< SDL_SCANCODE_TO_KEYCODE(SDL_SCANCODE_F4) */
#define SDLK_F5 0x4000003eu /**< SDL_SCANCODE_TO_KEYCODE(SDL_SCANCODE_F5) */
#define SDLK_F6 0x4000003fu /**< SDL_SCANCODE_TO_KEYCODE(SDL_SCANCODE_F6) */
#define SDLK_F7 0x40000040u /**< SDL_SCANCODE_TO_KEYCODE(SDL_SCANCODE_F7) */
#define SDLK_F8 0x40000041u /**< SDL_SCANCODE_TO_KEYCODE(SDL_SCANCODE_F8) */
#define SDLK_F9 0x40000042u /**< SDL_SCANCODE_TO_KEYCODE(SDL_SCANCODE_F9) */
#define SDLK_F10 0x40000043u /**< SDL_SCANCODE_TO_KEYCODE(SDL_SCANCODE_F10) */
#define SDLK_F11 0x40000044u /**< SDL_SCANCODE_TO_KEYCODE(SDL_SCANCODE_F11) */
#define SDLK_F12 0x40000045u /**< SDL_SCANCODE_TO_KEYCODE(SDL_SCANCODE_F12) */
#define SDLK_PRINTSCREEN 0x40000046u /**< SDL_SCANCODE_TO_KEYCODE(SDL_SCANCODE_PRINTSCREEN) */
#define SDLK_SCROLLLOCK 0x40000047u /**< SDL_SCANCODE_TO_KEYCODE(SDL_SCANCODE_SCROLLLOCK) */
#define SDLK_PAUSE 0x40000048u /**< SDL_SCANCODE_TO_KEYCODE(SDL_SCANCODE_PAUSE) */
#define SDLK_INSERT 0x40000049u /**< SDL_SCANCODE_TO_KEYCODE(SDL_SCANCODE_INSERT) */
#define SDLK_HOME 0x4000004au /**< SDL_SCANCODE_TO_KEYCODE(SDL_SCANCODE_HOME) */
#define SDLK_PAGEUP 0x4000004bu /**< SDL_SCANCODE_TO_KEYCODE(SDL_SCANCODE_PAGEUP) */
#define SDLK_END 0x4000004du /**< SDL_SCANCODE_TO_KEYCODE(SDL_SCANCODE_END) */
#define SDLK_PAGEDOWN 0x4000004eu /**< SDL_SCANCODE_TO_KEYCODE(SDL_SCANCODE_PAGEDOWN) */
#define SDLK_RIGHT 0x4000004fu /**< SDL_SCANCODE_TO_KEYCODE(SDL_SCANCODE_RIGHT) */
#define SDLK_LEFT 0x40000050u /**< SDL_SCANCODE_TO_KEYCODE(SDL_SCANCODE_LEFT) */
#define SDLK_DOWN 0x40000051u /**< SDL_SCANCODE_TO_KEYCODE(SDL_SCANCODE_DOWN) */
#define SDLK_UP 0x40000052u /**< SDL_SCANCODE_TO_KEYCODE(SDL_SCANCODE_UP) */
#define SDLK_NUMLOCKCLEAR 0x40000053u /**< SDL_SCANCODE_TO_KEYCODE(SDL_SCANCODE_NUMLOCKCLEAR) */
#define SDLK_KP_DIVIDE 0x40000054u /**< SDL_SCANCODE_TO_KEYCODE(SDL_SCANCODE_KP_DIVIDE) */
#define SDLK_KP_MULTIPLY 0x40000055u /**< SDL_SCANCODE_TO_KEYCODE(SDL_SCANCODE_KP_MULTIPLY) */
#define SDLK_KP_MINUS 0x40000056u /**< SDL_SCANCODE_TO_KEYCODE(SDL_SCANCODE_KP_MINUS) */
#define SDLK_KP_PLUS 0x40000057u /**< SDL_SCANCODE_TO_KEYCODE(SDL_SCANCODE_KP_PLUS) */
#define SDLK_KP_ENTER 0x40000058u /**< SDL_SCANCODE_TO_KEYCODE(SDL_SCANCODE_KP_ENTER) */
#define SDLK_KP_1 0x40000059u /**< SDL_SCANCODE_TO_KEYCODE(SDL_SCANCODE_KP_1) */
#define SDLK_KP_2 0x4000005au /**< SDL_SCANCODE_TO_KEYCODE(SDL_SCANCODE_KP_2) */
#define SDLK_KP_3 0x4000005bu /**< SDL_SCANCODE_TO_KEYCODE(SDL_SCANCODE_KP_3) */
#define SDLK_KP_4 0x4000005cu /**< SDL_SCANCODE_TO_KEYCODE(SDL_SCANCODE_KP_4) */
#define SDLK_KP_5 0x4000005du /**< SDL_SCANCODE_TO_KEYCODE(SDL_SCANCODE_KP_5) */
#define SDLK_KP_6 0x4000005eu /**< SDL_SCANCODE_TO_KEYCODE(SDL_SCANCODE_KP_6) */
#define SDLK_KP_7 0x4000005fu /**< SDL_SCANCODE_TO_KEYCODE(SDL_SCANCODE_KP_7) */
#define SDLK_KP_8 0x40000060u /**< SDL_SCANCODE_TO_KEYCODE(SDL_SCANCODE_KP_8) */
#define SDLK_KP_9 0x40000061u /**< SDL_SCANCODE_TO_KEYCODE(SDL_SCANCODE_KP_9) */
#define SDLK_KP_0 0x40000062u /**< SDL_SCANCODE_TO_KEYCODE(SDL_SCANCODE_KP_0) */
#define SDLK_KP_PERIOD 0x40000063u /**< SDL_SCANCODE_TO_KEYCODE(SDL_SCANCODE_KP_PERIOD) */
#define SDLK_APPLICATION 0x40000065u /**< SDL_SCANCODE_TO_KEYCODE(SDL_SCANCODE_APPLICATION) */
#define SDLK_POWER 0x40000066u /**< SDL_SCANCODE_TO_KEYCODE(SDL_SCANCODE_POWER) */
#define SDLK_KP_EQUALS 0x40000067u /**< SDL_SCANCODE_TO_KEYCODE(SDL_SCANCODE_KP_EQUALS) */
#define SDLK_F13 0x40000068u /**< SDL_SCANCODE_TO_KEYCODE(SDL_SCANCODE_F13) */
#define SDLK_F14 0x40000069u /**< SDL_SCANCODE_TO_KEYCODE(SDL_SCANCODE_F14) */
#define SDLK_F15 0x4000006au /**< SDL_SCANCODE_TO_KEYCODE(SDL_SCANCODE_F15) */
#define SDLK_F16 0x4000006bu /**< SDL_SCANCODE_TO_KEYCODE(SDL_SCANCODE_F16) */
#define SDLK_F17 0x4000006cu /**< SDL_SCANCODE_TO_KEYCODE(SDL_SCANCODE_F17) */
#define SDLK_F18 0x4000006du /**< SDL_SCANCODE_TO_KEYCODE(SDL_SCANCODE_F18) */
#define SDLK_F19 0x4000006eu /**< SDL_SCANCODE_TO_KEYCODE(SDL_SCANCODE_F19) */
#define SDLK_F20 0x4000006fu /**< SDL_SCANCODE_TO_KEYCODE(SDL_SCANCODE_F20) */
#define SDLK_F21 0x40000070u /**< SDL_SCANCODE_TO_KEYCODE(SDL_SCANCODE_F21) */
#define SDLK_F22 0x40000071u /**< SDL_SCANCODE_TO_KEYCODE(SDL_SCANCODE_F22) */
#define SDLK_F23 0x40000072u /**< SDL_SCANCODE_TO_KEYCODE(SDL_SCANCODE_F23) */
#define SDLK_F24 0x40000073u /**< SDL_SCANCODE_TO_KEYCODE(SDL_SCANCODE_F24) */
#define SDLK_EXECUTE 0x40000074u /**< SDL_SCANCODE_TO_KEYCODE(SDL_SCANCODE_EXECUTE) */
#define SDLK_HELP 0x40000075u /**< SDL_SCANCODE_TO_KEYCODE(SDL_SCANCODE_HELP) */
#define SDLK_MENU 0x40000076u /**< SDL_SCANCODE_TO_KEYCODE(SDL_SCANCODE_MENU) */
#define SDLK_SELECT 0x40000077u /**< SDL_SCANCODE_TO_KEYCODE(SDL_SCANCODE_SELECT) */
#define SDLK_STOP 0x40000078u /**< SDL_SCANCODE_TO_KEYCODE(SDL_SCANCODE_STOP) */
#define SDLK_AGAIN 0x40000079u /**< SDL_SCANCODE_TO_KEYCODE(SDL_SCANCODE_AGAIN) */
#define SDLK_UNDO 0x4000007au /**< SDL_SCANCODE_TO_KEYCODE(SDL_SCANCODE_UNDO) */
#define SDLK_CUT 0x4000007bu /**< SDL_SCANCODE_TO_KEYCODE(SDL_SCANCODE_CUT) */
#define SDLK_COPY 0x4000007cu /**< SDL_SCANCODE_TO_KEYCODE(SDL_SCANCODE_COPY) */
#define SDLK_PASTE 0x4000007du /**< SDL_SCANCODE_TO_KEYCODE(SDL_SCANCODE_PASTE) */
#define SDLK_FIND 0x4000007eu /**< SDL_SCANCODE_TO_KEYCODE(SDL_SCANCODE_FIND) */
#define SDLK_MUTE 0x4000007fu /**< SDL_SCANCODE_TO_KEYCODE(SDL_SCANCODE_MUTE) */
#define SDLK_VOLUMEUP 0x40000080u /**< SDL_SCANCODE_TO_KEYCODE(SDL_SCANCODE_VOLUMEUP) */
#define SDLK_VOLUMEDOWN 0x40000081u /**< SDL_SCANCODE_TO_KEYCODE(SDL_SCANCODE_VOLUMEDOWN) */
#define SDLK_KP_COMMA 0x40000085u /**< SDL_SCANCODE_TO_KEYCODE(SDL_SCANCODE_KP_COMMA) */
#define SDLK_KP_EQUALSAS400 0x40000086u /**< SDL_SCANCODE_TO_KEYCODE(SDL_SCANCODE_KP_EQUALSAS400) */
#define SDLK_ALTERASE 0x40000099u /**< SDL_SCANCODE_TO_KEYCODE(SDL_SCANCODE_ALTERASE) */
#define SDLK_SYSREQ 0x4000009au /**< SDL_SCANCODE_TO_KEYCODE(SDL_SCANCODE_SYSREQ) */
#define SDLK_CANCEL 0x4000009bu /**< SDL_SCANCODE_TO_KEYCODE(SDL_SCANCODE_CANCEL) */
#define SDLK_CLEAR 0x4000009cu /**< SDL_SCANCODE_TO_KEYCODE(SDL_SCANCODE_CLEAR) */
#define SDLK_PRIOR 0x4000009du /**< SDL_SCANCODE_TO_KEYCODE(SDL_SCANCODE_PRIOR) */
#define SDLK_RETURN2 0x4000009eu /**< SDL_SCANCODE_TO_KEYCODE(SDL_SCANCODE_RETURN2) */
#define SDLK_SEPARATOR 0x4000009fu /**< SDL_SCANCODE_TO_KEYCODE(SDL_SCANCODE_SEPARATOR) */
#define SDLK_OUT 0x400000a0u /**< SDL_SCANCODE_TO_KEYCODE(SDL_SCANCODE_OUT) */
#define SDLK_OPER 0x400000a1u /**< SDL_SCANCODE_TO_KEYCODE(SDL_SCANCODE_OPER) */
#define SDLK_CLEARAGAIN 0x400000a2u /**< SDL_SCANCODE_TO_KEYCODE(SDL_SCANCODE_CLEARAGAIN) */
#define SDLK_CRSEL 0x400000a3u /**< SDL_SCANCODE_TO_KEYCODE(SDL_SCANCODE_CRSEL) */
#define SDLK_EXSEL 0x400000a4u /**< SDL_SCANCODE_TO_KEYCODE(SDL_SCANCODE_EXSEL) */
#define SDLK_KP_00 0x400000b0u /**< SDL_SCANCODE_TO_KEYCODE(SDL_SCANCODE_KP_00) */
#define SDLK_KP_000 0x400000b1u /**< SDL_SCANCODE_TO_KEYCODE(SDL_SCANCODE_KP_000) */
#define SDLK_THOUSANDSSEPARATOR 0x400000b2u /**< SDL_SCANCODE_TO_KEYCODE(SDL_SCANCODE_THOUSANDSSEPARATOR) */
#define SDLK_DECIMALSEPARATOR 0x400000b3u /**< SDL_SCANCODE_TO_KEYCODE(SDL_SCANCODE_DECIMALSEPARATOR) */
#define SDLK_CURRENCYUNIT 0x400000b4u /**< SDL_SCANCODE_TO_KEYCODE(SDL_SCANCODE_CURRENCYUNIT) */
#define SDLK_CURRENCYSUBUNIT 0x400000b5u /**< SDL_SCANCODE_TO_KEYCODE(SDL_SCANCODE_CURRENCYSUBUNIT) */
#define SDLK_KP_LEFTPAREN 0x400000b6u /**< SDL_SCANCODE_TO_KEYCODE(SDL_SCANCODE_KP_LEFTPAREN) */
#define SDLK_KP_RIGHTPAREN 0x400000b7u /**< SDL_SCANCODE_TO_KEYCODE(SDL_SCANCODE_KP_RIGHTPAREN) */
#define SDLK_KP_LEFTBRACE 0x400000b8u /**< SDL_SCANCODE_TO_KEYCODE(SDL_SCANCODE_KP_LEFTBRACE) */
#define SDLK_KP_RIGHTBRACE 0x400000b9u /**< SDL_SCANCODE_TO_KEYCODE(SDL_SCANCODE_KP_RIGHTBRACE) */
#define SDLK_KP_TAB 0x400000bau /**< SDL_SCANCODE_TO_KEYCODE(SDL_SCANCODE_KP_TAB) */
#define SDLK_KP_BACKSPACE 0x400000bbu /**< SDL_SCANCODE_TO_KEYCODE(SDL_SCANCODE_KP_BACKSPACE) */
#define SDLK_KP_A 0x400000bcu /**< SDL_SCANCODE_TO_KEYCODE(SDL_SCANCODE_KP_A) */
#define SDLK_KP_B 0x400000bdu /**< SDL_SCANCODE_TO_KEYCODE(SDL_SCANCODE_KP_B) */
#define SDLK_KP_C 0x400000beu /**< SDL_SCANCODE_TO_KEYCODE(SDL_SCANCODE_KP_C) */
#define SDLK_KP_D 0x400000bfu /**< SDL_SCANCODE_TO_KEYCODE(SDL_SCANCODE_KP_D) */
#define SDLK_KP_E 0x400000c0u /**< SDL_SCANCODE_TO_KEYCODE(SDL_SCANCODE_KP_E) */
#define SDLK_KP_F 0x400000c1u /**< SDL_SCANCODE_TO_KEYCODE(SDL_SCANCODE_KP_F) */
#define SDLK_KP_XOR 0x400000c2u /**< SDL_SCANCODE_TO_KEYCODE(SDL_SCANCODE_KP_XOR) */
#define SDLK_KP_POWER 0x400000c3u /**< SDL_SCANCODE_TO_KEYCODE(SDL_SCANCODE_KP_POWER) */
#define SDLK_KP_PERCENT 0x400000c4u /**< SDL_SCANCODE_TO_KEYCODE(SDL_SCANCODE_KP_PERCENT) */
#define SDLK_KP_LESS 0x400000c5u /**< SDL_SCANCODE_TO_KEYCODE(SDL_SCANCODE_KP_LESS) */
#define SDLK_KP_GREATER 0x400000c6u /**< SDL_SCANCODE_TO_KEYCODE(SDL_SCANCODE_KP_GREATER) */
#define SDLK_KP_AMPERSAND 0x400000c7u /**< SDL_SCANCODE_TO_KEYCODE(SDL_SCANCODE_KP_AMPERSAND) */
#define SDLK_KP_DBLAMPERSAND 0x400000c8u /**< SDL_SCANCODE_TO_KEYCODE(SDL_SCANCODE_KP_DBLAMPERSAND) */
#define SDLK_KP_VERTICALBAR 0x400000c9u /**< SDL_SCANCODE_TO_KEYCODE(SDL_SCANCODE_KP_VERTICALBAR) */
#define SDLK_KP_DBLVERTICALBAR 0x400000cau /**< SDL_SCANCODE_TO_KEYCODE(SDL_SCANCODE_KP_DBLVERTICALBAR) */
#define SDLK_KP_COLON 0x400000cbu /**< SDL_SCANCODE_TO_KEYCODE(SDL_SCANCODE_KP_COLON) */
#define SDLK_KP_HASH 0x400000ccu /**< SDL_SCANCODE_TO_KEYCODE(SDL_SCANCODE_KP_HASH) */
#define SDLK_KP_SPACE 0x400000cdu /**< SDL_SCANCODE_TO_KEYCODE(SDL_SCANCODE_KP_SPACE) */
#define SDLK_KP_AT 0x400000ceu /**< SDL_SCANCODE_TO_KEYCODE(SDL_SCANCODE_KP_AT) */
#define SDLK_KP_EXCLAM 0x400000cfu /**< SDL_SCANCODE_TO_KEYCODE(SDL_SCANCODE_KP_EXCLAM) */
#define SDLK_KP_MEMSTORE 0x400000d0u /**< SDL_SCANCODE_TO_KEYCODE(SDL_SCANCODE_KP_MEMSTORE) */
#define SDLK_KP_MEMRECALL 0x400000d1u /**< SDL_SCANCODE_TO_KEYCODE(SDL_SCANCODE_KP_MEMRECALL) */
#define SDLK_KP_MEMCLEAR 0x400000d2u /**< SDL_SCANCODE_TO_KEYCODE(SDL_SCANCODE_KP_MEMCLEAR) */
#define SDLK_KP_MEMADD 0x400000d3u /**< SDL_SCANCODE_TO_KEYCODE(SDL_SCANCODE_KP_MEMADD) */
#define SDLK_KP_MEMSUBTRACT 0x400000d4u /**< SDL_SCANCODE_TO_KEYCODE(SDL_SCANCODE_KP_MEMSUBTRACT) */
#define SDLK_KP_MEMMULTIPLY 0x400000d5u /**< SDL_SCANCODE_TO_KEYCODE(SDL_SCANCODE_KP_MEMMULTIPLY) */
#define SDLK_KP_MEMDIVIDE 0x400000d6u /**< SDL_SCANCODE_TO_KEYCODE(SDL_SCANCODE_KP_MEMDIVIDE) */
#define SDLK_KP_PLUSMINUS 0x400000d7u /**< SDL_SCANCODE_TO_KEYCODE(SDL_SCANCODE_KP_PLUSMINUS) */
#define SDLK_KP_CLEAR 0x400000d8u /**< SDL_SCANCODE_TO_KEYCODE(SDL_SCANCODE_KP_CLEAR) */
#define SDLK_KP_CLEARENTRY 0x400000d9u /**< SDL_SCANCODE_TO_KEYCODE(SDL_SCANCODE_KP_CLEARENTRY) */
#define SDLK_KP_BINARY 0x400000dau /**< SDL_SCANCODE_TO_KEYCODE(SDL_SCANCODE_KP_BINARY) */
#define SDLK_KP_OCTAL 0x400000dbu /**< SDL_SCANCODE_TO_KEYCODE(SDL_SCANCODE_KP_OCTAL) */
#define SDLK_KP_DECIMAL 0x400000dcu /**< SDL_SCANCODE_TO_KEYCODE(SDL_SCANCODE_KP_DECIMAL) */
#define SDLK_KP_HEXADECIMAL 0x400000ddu /**< SDL_SCANCODE_TO_KEYCODE(SDL_SCANCODE_KP_HEXADECIMAL) */
#define SDLK_LCTRL 0x400000e0u /**< SDL_SCANCODE_TO_KEYCODE(SDL_SCANCODE_LCTRL) */
#define SDLK_LSHIFT 0x400000e1u /**< SDL_SCANCODE_TO_KEYCODE(SDL_SCANCODE_LSHIFT) */
#define SDLK_LALT 0x400000e2u /**< SDL_SCANCODE_TO_KEYCODE(SDL_SCANCODE_LALT) */
#define SDLK_LGUI 0x400000e3u /**< SDL_SCANCODE_TO_KEYCODE(SDL_SCANCODE_LGUI) */
#define SDLK_RCTRL 0x400000e4u /**< SDL_SCANCODE_TO_KEYCODE(SDL_SCANCODE_RCTRL) */
#define SDLK_RSHIFT 0x400000e5u /**< SDL_SCANCODE_TO_KEYCODE(SDL_SCANCODE_RSHIFT) */
#define SDLK_RALT 0x400000e6u /**< SDL_SCANCODE_TO_KEYCODE(SDL_SCANCODE_RALT) */
#define SDLK_RGUI 0x400000e7u /**< SDL_SCANCODE_TO_KEYCODE(SDL_SCANCODE_RGUI) */
#define SDLK_MODE 0x40000101u /**< SDL_SCANCODE_TO_KEYCODE(SDL_SCANCODE_MODE) */
#define SDLK_SLEEP 0x40000102u /**< SDL_SCANCODE_TO_KEYCODE(SDL_SCANCODE_SLEEP) */
#define SDLK_WAKE 0x40000103u /**< SDL_SCANCODE_TO_KEYCODE(SDL_SCANCODE_WAKE) */
#define SDLK_CHANNEL_INCREMENT 0x40000104u /**< SDL_SCANCODE_TO_KEYCODE(SDL_SCANCODE_CHANNEL_INCREMENT) */
#define SDLK_CHANNEL_DECREMENT 0x40000105u /**< SDL_SCANCODE_TO_KEYCODE(SDL_SCANCODE_CHANNEL_DECREMENT) */
#define SDLK_MEDIA_PLAY 0x40000106u /**< SDL_SCANCODE_TO_KEYCODE(SDL_SCANCODE_MEDIA_PLAY) */
#define SDLK_MEDIA_PAUSE 0x40000107u /**< SDL_SCANCODE_TO_KEYCODE(SDL_SCANCODE_MEDIA_PAUSE) */
#define SDLK_MEDIA_RECORD 0x40000108u /**< SDL_SCANCODE_TO_KEYCODE(SDL_SCANCODE_MEDIA_RECORD) */
#define SDLK_MEDIA_FAST_FORWARD 0x40000109u /**< SDL_SCANCODE_TO_KEYCODE(SDL_SCANCODE_MEDIA_FAST_FORWARD) */
#define SDLK_MEDIA_REWIND 0x4000010au /**< SDL_SCANCODE_TO_KEYCODE(SDL_SCANCODE_MEDIA_REWIND) */
#define SDLK_MEDIA_NEXT_TRACK 0x4000010bu /**< SDL_SCANCODE_TO_KEYCODE(SDL_SCANCODE_MEDIA_NEXT_TRACK) */
#define SDLK_MEDIA_PREVIOUS_TRACK 0x4000010cu /**< SDL_SCANCODE_TO_KEYCODE(SDL_SCANCODE_MEDIA_PREVIOUS_TRACK) */
#define SDLK_MEDIA_STOP 0x4000010du /**< SDL_SCANCODE_TO_KEYCODE(SDL_SCANCODE_MEDIA_STOP) */
#define SDLK_MEDIA_EJECT 0x4000010eu /**< SDL_SCANCODE_TO_KEYCODE(SDL_SCANCODE_MEDIA_EJECT) */
#define SDLK_MEDIA_PLAY_PAUSE 0x4000010fu /**< SDL_SCANCODE_TO_KEYCODE(SDL_SCANCODE_MEDIA_PLAY_PAUSE) */
#define SDLK_MEDIA_SELECT 0x40000110u /**< SDL_SCANCODE_TO_KEYCODE(SDL_SCANCODE_MEDIA_SELECT) */
#define SDLK_AC_NEW 0x40000111u /**< SDL_SCANCODE_TO_KEYCODE(SDL_SCANCODE_AC_NEW) */
#define SDLK_AC_OPEN 0x40000112u /**< SDL_SCANCODE_TO_KEYCODE(SDL_SCANCODE_AC_OPEN) */
#define SDLK_AC_CLOSE 0x40000113u /**< SDL_SCANCODE_TO_KEYCODE(SDL_SCANCODE_AC_CLOSE) */
#define SDLK_AC_EXIT 0x40000114u /**< SDL_SCANCODE_TO_KEYCODE(SDL_SCANCODE_AC_EXIT) */
#define SDLK_AC_SAVE 0x40000115u /**< SDL_SCANCODE_TO_KEYCODE(SDL_SCANCODE_AC_SAVE) */
#define SDLK_AC_PRINT 0x40000116u /**< SDL_SCANCODE_TO_KEYCODE(SDL_SCANCODE_AC_PRINT) */
#define SDLK_AC_PROPERTIES 0x40000117u /**< SDL_SCANCODE_TO_KEYCODE(SDL_SCANCODE_AC_PROPERTIES) */
#define SDLK_AC_SEARCH 0x40000118u /**< SDL_SCANCODE_TO_KEYCODE(SDL_SCANCODE_AC_SEARCH) */
#define SDLK_AC_HOME 0x40000119u /**< SDL_SCANCODE_TO_KEYCODE(SDL_SCANCODE_AC_HOME) */
#define SDLK_AC_BACK 0x4000011au /**< SDL_SCANCODE_TO_KEYCODE(SDL_SCANCODE_AC_BACK) */
#define SDLK_AC_FORWARD 0x4000011bu /**< SDL_SCANCODE_TO_KEYCODE(SDL_SCANCODE_AC_FORWARD) */
#define SDLK_AC_STOP 0x4000011cu /**< SDL_SCANCODE_TO_KEYCODE(SDL_SCANCODE_AC_STOP) */
#define SDLK_AC_REFRESH 0x4000011du /**< SDL_SCANCODE_TO_KEYCODE(SDL_SCANCODE_AC_REFRESH) */
#define SDLK_AC_BOOKMARKS 0x4000011eu /**< SDL_SCANCODE_TO_KEYCODE(SDL_SCANCODE_AC_BOOKMARKS) */
#define SDLK_SOFTLEFT 0x4000011fu /**< SDL_SCANCODE_TO_KEYCODE(SDL_SCANCODE_SOFTLEFT) */
#define SDLK_SOFTRIGHT 0x40000120u /**< SDL_SCANCODE_TO_KEYCODE(SDL_SCANCODE_SOFTRIGHT) */
#define SDLK_CALL 0x40000121u /**< SDL_SCANCODE_TO_KEYCODE(SDL_SCANCODE_CALL) */
#define SDLK_ENDCALL 0x40000122u /**< SDL_SCANCODE_TO_KEYCODE(SDL_SCANCODE_ENDCALL) */
#define SDLK_LEFT_TAB 0x20000001u /**< Extended key Left Tab */
#define SDLK_LEVEL5_SHIFT 0x20000002u /**< Extended key Level 5 Shift */
#define SDLK_MULTI_KEY_COMPOSE 0x20000003u /**< Extended key Multi-key Compose */
#define SDLK_LMETA 0x20000004u /**< Extended key Left Meta */
#define SDLK_RMETA 0x20000005u /**< Extended key Right Meta */
#define SDLK_LHYPER 0x20000006u /**< Extended key Left Hyper */
#define SDLK_RHYPER 0x20000007u /**< Extended key Right Hyper */
/**
* Valid key modifiers (possibly OR'd together).
*
* \since This datatype is available since SDL 3.0.0.
* \since This datatype is available since SDL 3.2.0.
*/
typedef Uint16 SDL_Keymod;
#define SDL_KMOD_NONE 0x0000u /**< no modifier is applicable. */
#define SDL_KMOD_LSHIFT 0x0001u /**< the left Shift key is down. */
#define SDL_KMOD_RSHIFT 0x0002u /**< the right Shift key is down. */
#define SDL_KMOD_LEVEL5 0x0004u /**< the Level 5 Shift key is down. */
#define SDL_KMOD_LCTRL 0x0040u /**< the left Ctrl (Control) key is down. */
#define SDL_KMOD_RCTRL 0x0080u /**< the right Ctrl (Control) key is down. */
#define SDL_KMOD_LALT 0x0100u /**< the left Alt key is down. */

View File

@ -1,6 +1,6 @@
/*
Simple DirectMedia Layer
Copyright (C) 1997-2024 Sam Lantinga <slouken@libsdl.org>
Copyright (C) 1997-2025 Sam Lantinga <slouken@libsdl.org>
This software is provided 'as-is', without any express or implied
warranty. In no event will the authors be held liable for any damages
@ -26,6 +26,14 @@
*
* System-dependent library loading routines.
*
* Shared objects are code that is programmatically loadable at runtime.
* Windows calls these "DLLs", Linux calls them "shared libraries", etc.
*
* To use them, build such a library, then call SDL_LoadObject() on it. Once
* loaded, you can use SDL_LoadFunction() on that object to find the address
* of its exported symbols. When done with the object, call SDL_UnloadObject()
* to dispose of it.
*
* Some things to keep in mind:
*
* - These functions only work on C function names. Other languages may have
@ -38,6 +46,11 @@
* not defined whether or not it goes into the global symbol namespace for
* the application. If it does and it conflicts with symbols in your code or
* other shared libraries, you will not get the results you expect. :)
* - Once a library is unloaded, all pointers into it obtained through
* SDL_LoadFunction() become invalid, even if the library is later reloaded.
* Don't unload a library if you plan to use these pointers in the future.
* Notably: beware of giving one of these pointers to atexit(), since it may
* call that pointer after the library unloads.
*/
#ifndef SDL_loadso_h_
@ -52,6 +65,17 @@
extern "C" {
#endif
/**
* An opaque datatype that represents a loaded shared object.
*
* \since This datatype is available since SDL 3.2.0.
*
* \sa SDL_LoadObject
* \sa SDL_LoadFunction
* \sa SDL_UnloadObject
*/
typedef struct SDL_SharedObject SDL_SharedObject;
/**
* Dynamically load a shared object.
*
@ -59,12 +83,14 @@ extern "C" {
* \returns an opaque pointer to the object handle or NULL on failure; call
* SDL_GetError() for more information.
*
* \since This function is available since SDL 3.0.0.
* \threadsafety It is safe to call this function from any thread.
*
* \since This function is available since SDL 3.2.0.
*
* \sa SDL_LoadFunction
* \sa SDL_UnloadObject
*/
extern SDL_DECLSPEC void * SDLCALL SDL_LoadObject(const char *sofile);
extern SDL_DECLSPEC SDL_SharedObject * SDLCALL SDL_LoadObject(const char *sofile);
/**
* Look up the address of the named function in a shared object.
@ -86,22 +112,29 @@ extern SDL_DECLSPEC void * SDLCALL SDL_LoadObject(const char *sofile);
* \returns a pointer to the function or NULL on failure; call SDL_GetError()
* for more information.
*
* \since This function is available since SDL 3.0.0.
* \threadsafety It is safe to call this function from any thread.
*
* \since This function is available since SDL 3.2.0.
*
* \sa SDL_LoadObject
*/
extern SDL_DECLSPEC SDL_FunctionPointer SDLCALL SDL_LoadFunction(void *handle, const char *name);
extern SDL_DECLSPEC SDL_FunctionPointer SDLCALL SDL_LoadFunction(SDL_SharedObject *handle, const char *name);
/**
* Unload a shared object from memory.
*
* Note that any pointers from this object looked up through
* SDL_LoadFunction() will no longer be valid.
*
* \param handle a valid shared object handle returned by SDL_LoadObject().
*
* \since This function is available since SDL 3.0.0.
* \threadsafety It is safe to call this function from any thread.
*
* \since This function is available since SDL 3.2.0.
*
* \sa SDL_LoadObject
*/
extern SDL_DECLSPEC void SDLCALL SDL_UnloadObject(void *handle);
extern SDL_DECLSPEC void SDLCALL SDL_UnloadObject(SDL_SharedObject *handle);
/* Ends C function definitions when using C++ */
#ifdef __cplusplus

View File

@ -1,6 +1,6 @@
/*
Simple DirectMedia Layer
Copyright (C) 1997-2024 Sam Lantinga <slouken@libsdl.org>
Copyright (C) 1997-2025 Sam Lantinga <slouken@libsdl.org>
This software is provided 'as-is', without any express or implied
warranty. In no event will the authors be held liable for any damages
@ -23,6 +23,12 @@
* # CategoryLocale
*
* SDL locale services.
*
* This provides a way to get a list of preferred locales (language plus
* country) for the user. There is exactly one function:
* SDL_GetPreferredLocales(), which handles all the heavy lifting, and offers
* documentation on all the strange ways humans might have configured their
* language settings.
*/
#ifndef SDL_locale_h
@ -47,7 +53,7 @@ extern "C" {
* would be "en"), and the country, if not NULL, will be an ISO-3166 country
* code (so Canada would be "CA").
*
* \since This function is available since SDL 3.0.0.
* \since This function is available since SDL 3.2.0.
*
* \sa SDL_GetPreferredLocales
*/
@ -96,7 +102,7 @@ typedef struct SDL_Locale
* allocation that should be freed with SDL_free() when it is no
* longer needed.
*
* \since This function is available since SDL 3.0.0.
* \since This function is available since SDL 3.2.0.
*/
extern SDL_DECLSPEC SDL_Locale ** SDLCALL SDL_GetPreferredLocales(int *count);

View File

@ -1,6 +1,6 @@
/*
Simple DirectMedia Layer
Copyright (C) 1997-2024 Sam Lantinga <slouken@libsdl.org>
Copyright (C) 1997-2025 Sam Lantinga <slouken@libsdl.org>
This software is provided 'as-is', without any express or implied
warranty. In no event will the authors be held liable for any damages
@ -22,7 +22,7 @@
/**
* # CategoryLog
*
* Simple log messages with priorities and categories. A messages
* Simple log messages with priorities and categories. A message's
* SDL_LogPriority signifies how important the message is. A message's
* SDL_LogCategory signifies from what domain it belongs to. Every category
* has a minimum priority specified: when a message belongs to that category,
@ -76,7 +76,7 @@ extern "C" {
* level, the assert category is enabled at the WARN level, test is enabled at
* the VERBOSE level and all other categories are enabled at the ERROR level.
*
* \since This enum is available since SDL 3.0.0.
* \since This enum is available since SDL 3.2.0.
*/
typedef enum SDL_LogCategory
{
@ -87,12 +87,11 @@ typedef enum SDL_LogCategory
SDL_LOG_CATEGORY_AUDIO,
SDL_LOG_CATEGORY_VIDEO,
SDL_LOG_CATEGORY_RENDER,
SDL_LOG_CATEGORY_GPU,
SDL_LOG_CATEGORY_INPUT,
SDL_LOG_CATEGORY_TEST,
SDL_LOG_CATEGORY_GPU,
/* Reserved for future SDL library use */
SDL_LOG_CATEGORY_RESERVED1,
SDL_LOG_CATEGORY_RESERVED2,
SDL_LOG_CATEGORY_RESERVED3,
SDL_LOG_CATEGORY_RESERVED4,
@ -117,17 +116,19 @@ typedef enum SDL_LogCategory
/**
* The predefined log priorities
*
* \since This enum is available since SDL 3.0.0.
* \since This enum is available since SDL 3.2.0.
*/
typedef enum SDL_LogPriority
{
SDL_LOG_PRIORITY_VERBOSE = 1,
SDL_LOG_PRIORITY_INVALID,
SDL_LOG_PRIORITY_TRACE,
SDL_LOG_PRIORITY_VERBOSE,
SDL_LOG_PRIORITY_DEBUG,
SDL_LOG_PRIORITY_INFO,
SDL_LOG_PRIORITY_WARN,
SDL_LOG_PRIORITY_ERROR,
SDL_LOG_PRIORITY_CRITICAL,
SDL_NUM_LOG_PRIORITIES
SDL_LOG_PRIORITY_COUNT
} SDL_LogPriority;
@ -136,7 +137,9 @@ typedef enum SDL_LogPriority
*
* \param priority the SDL_LogPriority to assign.
*
* \since This function is available since SDL 3.0.0.
* \threadsafety It is safe to call this function from any thread.
*
* \since This function is available since SDL 3.2.0.
*
* \sa SDL_ResetLogPriorities
* \sa SDL_SetLogPriority
@ -149,14 +152,15 @@ extern SDL_DECLSPEC void SDLCALL SDL_SetLogPriorities(SDL_LogPriority priority);
* \param category the category to assign a priority to.
* \param priority the SDL_LogPriority to assign.
*
* \since This function is available since SDL 3.0.0.
* \threadsafety It is safe to call this function from any thread.
*
* \since This function is available since SDL 3.2.0.
*
* \sa SDL_GetLogPriority
* \sa SDL_ResetLogPriorities
* \sa SDL_SetLogPriorities
*/
extern SDL_DECLSPEC void SDLCALL SDL_SetLogPriority(int category,
SDL_LogPriority priority);
extern SDL_DECLSPEC void SDLCALL SDL_SetLogPriority(int category, SDL_LogPriority priority);
/**
* Get the priority of a particular log category.
@ -164,7 +168,9 @@ extern SDL_DECLSPEC void SDLCALL SDL_SetLogPriority(int category,
* \param category the category to query.
* \returns the SDL_LogPriority for the requested category.
*
* \since This function is available since SDL 3.0.0.
* \threadsafety It is safe to call this function from any thread.
*
* \since This function is available since SDL 3.2.0.
*
* \sa SDL_SetLogPriority
*/
@ -175,7 +181,9 @@ extern SDL_DECLSPEC SDL_LogPriority SDLCALL SDL_GetLogPriority(int category);
*
* This is called by SDL_Quit().
*
* \since This function is available since SDL 3.0.0.
* \threadsafety It is safe to call this function from any thread.
*
* \since This function is available since SDL 3.2.0.
*
* \sa SDL_SetLogPriorities
* \sa SDL_SetLogPriority
@ -192,15 +200,17 @@ extern SDL_DECLSPEC void SDLCALL SDL_ResetLogPriorities(void);
* \param priority the SDL_LogPriority to modify.
* \param prefix the prefix to use for that log priority, or NULL to use no
* prefix.
* \returns SDL_TRUE on success or SDL_FALSE on failure; call SDL_GetError()
* for more information.
* \returns true on success or false on failure; call SDL_GetError() for more
* information.
*
* \since This function is available since SDL 3.0.0.
* \threadsafety It is safe to call this function from any thread.
*
* \since This function is available since SDL 3.2.0.
*
* \sa SDL_SetLogPriorities
* \sa SDL_SetLogPriority
*/
extern SDL_DECLSPEC SDL_bool SDLCALL SDL_SetLogPriorityPrefix(SDL_LogPriority priority, const char *prefix);
extern SDL_DECLSPEC bool SDLCALL SDL_SetLogPriorityPrefix(SDL_LogPriority priority, const char *prefix);
/**
* Log a message with SDL_LOG_CATEGORY_APPLICATION and SDL_LOG_PRIORITY_INFO.
@ -209,7 +219,9 @@ extern SDL_DECLSPEC SDL_bool SDLCALL SDL_SetLogPriorityPrefix(SDL_LogPriority pr
* \param ... additional parameters matching % tokens in the `fmt` string, if
* any.
*
* \since This function is available since SDL 3.0.0.
* \threadsafety It is safe to call this function from any thread.
*
* \since This function is available since SDL 3.2.0.
*
* \sa SDL_LogCritical
* \sa SDL_LogDebug
@ -217,11 +229,37 @@ extern SDL_DECLSPEC SDL_bool SDLCALL SDL_SetLogPriorityPrefix(SDL_LogPriority pr
* \sa SDL_LogInfo
* \sa SDL_LogMessage
* \sa SDL_LogMessageV
* \sa SDL_LogTrace
* \sa SDL_LogVerbose
* \sa SDL_LogWarn
*/
extern SDL_DECLSPEC void SDLCALL SDL_Log(SDL_PRINTF_FORMAT_STRING const char *fmt, ...) SDL_PRINTF_VARARG_FUNC(1);
/**
* Log a message with SDL_LOG_PRIORITY_TRACE.
*
* \param category the category of the message.
* \param fmt a printf() style message format string.
* \param ... additional parameters matching % tokens in the **fmt** string,
* if any.
*
* \threadsafety It is safe to call this function from any thread.
*
* \since This function is available since SDL 3.2.0.
*
* \sa SDL_Log
* \sa SDL_LogCritical
* \sa SDL_LogDebug
* \sa SDL_LogError
* \sa SDL_LogInfo
* \sa SDL_LogMessage
* \sa SDL_LogMessageV
* \sa SDL_LogTrace
* \sa SDL_LogVerbose
* \sa SDL_LogWarn
*/
extern SDL_DECLSPEC void SDLCALL SDL_LogTrace(int category, SDL_PRINTF_FORMAT_STRING const char *fmt, ...) SDL_PRINTF_VARARG_FUNC(2);
/**
* Log a message with SDL_LOG_PRIORITY_VERBOSE.
*
@ -230,7 +268,9 @@ extern SDL_DECLSPEC void SDLCALL SDL_Log(SDL_PRINTF_FORMAT_STRING const char *fm
* \param ... additional parameters matching % tokens in the **fmt** string,
* if any.
*
* \since This function is available since SDL 3.0.0.
* \threadsafety It is safe to call this function from any thread.
*
* \since This function is available since SDL 3.2.0.
*
* \sa SDL_Log
* \sa SDL_LogCritical
@ -251,7 +291,9 @@ extern SDL_DECLSPEC void SDLCALL SDL_LogVerbose(int category, SDL_PRINTF_FORMAT_
* \param ... additional parameters matching % tokens in the **fmt** string,
* if any.
*
* \since This function is available since SDL 3.0.0.
* \threadsafety It is safe to call this function from any thread.
*
* \since This function is available since SDL 3.2.0.
*
* \sa SDL_Log
* \sa SDL_LogCritical
@ -259,6 +301,7 @@ extern SDL_DECLSPEC void SDLCALL SDL_LogVerbose(int category, SDL_PRINTF_FORMAT_
* \sa SDL_LogInfo
* \sa SDL_LogMessage
* \sa SDL_LogMessageV
* \sa SDL_LogTrace
* \sa SDL_LogVerbose
* \sa SDL_LogWarn
*/
@ -272,7 +315,9 @@ extern SDL_DECLSPEC void SDLCALL SDL_LogDebug(int category, SDL_PRINTF_FORMAT_ST
* \param ... additional parameters matching % tokens in the **fmt** string,
* if any.
*
* \since This function is available since SDL 3.0.0.
* \threadsafety It is safe to call this function from any thread.
*
* \since This function is available since SDL 3.2.0.
*
* \sa SDL_Log
* \sa SDL_LogCritical
@ -280,6 +325,7 @@ extern SDL_DECLSPEC void SDLCALL SDL_LogDebug(int category, SDL_PRINTF_FORMAT_ST
* \sa SDL_LogError
* \sa SDL_LogMessage
* \sa SDL_LogMessageV
* \sa SDL_LogTrace
* \sa SDL_LogVerbose
* \sa SDL_LogWarn
*/
@ -293,7 +339,9 @@ extern SDL_DECLSPEC void SDLCALL SDL_LogInfo(int category, SDL_PRINTF_FORMAT_STR
* \param ... additional parameters matching % tokens in the **fmt** string,
* if any.
*
* \since This function is available since SDL 3.0.0.
* \threadsafety It is safe to call this function from any thread.
*
* \since This function is available since SDL 3.2.0.
*
* \sa SDL_Log
* \sa SDL_LogCritical
@ -302,6 +350,7 @@ extern SDL_DECLSPEC void SDLCALL SDL_LogInfo(int category, SDL_PRINTF_FORMAT_STR
* \sa SDL_LogInfo
* \sa SDL_LogMessage
* \sa SDL_LogMessageV
* \sa SDL_LogTrace
* \sa SDL_LogVerbose
*/
extern SDL_DECLSPEC void SDLCALL SDL_LogWarn(int category, SDL_PRINTF_FORMAT_STRING const char *fmt, ...) SDL_PRINTF_VARARG_FUNC(2);
@ -314,7 +363,9 @@ extern SDL_DECLSPEC void SDLCALL SDL_LogWarn(int category, SDL_PRINTF_FORMAT_STR
* \param ... additional parameters matching % tokens in the **fmt** string,
* if any.
*
* \since This function is available since SDL 3.0.0.
* \threadsafety It is safe to call this function from any thread.
*
* \since This function is available since SDL 3.2.0.
*
* \sa SDL_Log
* \sa SDL_LogCritical
@ -322,6 +373,7 @@ extern SDL_DECLSPEC void SDLCALL SDL_LogWarn(int category, SDL_PRINTF_FORMAT_STR
* \sa SDL_LogInfo
* \sa SDL_LogMessage
* \sa SDL_LogMessageV
* \sa SDL_LogTrace
* \sa SDL_LogVerbose
* \sa SDL_LogWarn
*/
@ -335,7 +387,9 @@ extern SDL_DECLSPEC void SDLCALL SDL_LogError(int category, SDL_PRINTF_FORMAT_ST
* \param ... additional parameters matching % tokens in the **fmt** string,
* if any.
*
* \since This function is available since SDL 3.0.0.
* \threadsafety It is safe to call this function from any thread.
*
* \since This function is available since SDL 3.2.0.
*
* \sa SDL_Log
* \sa SDL_LogDebug
@ -343,6 +397,7 @@ extern SDL_DECLSPEC void SDLCALL SDL_LogError(int category, SDL_PRINTF_FORMAT_ST
* \sa SDL_LogInfo
* \sa SDL_LogMessage
* \sa SDL_LogMessageV
* \sa SDL_LogTrace
* \sa SDL_LogVerbose
* \sa SDL_LogWarn
*/
@ -357,7 +412,9 @@ extern SDL_DECLSPEC void SDLCALL SDL_LogCritical(int category, SDL_PRINTF_FORMAT
* \param ... additional parameters matching % tokens in the **fmt** string,
* if any.
*
* \since This function is available since SDL 3.0.0.
* \threadsafety It is safe to call this function from any thread.
*
* \since This function is available since SDL 3.2.0.
*
* \sa SDL_Log
* \sa SDL_LogCritical
@ -365,6 +422,7 @@ extern SDL_DECLSPEC void SDLCALL SDL_LogCritical(int category, SDL_PRINTF_FORMAT
* \sa SDL_LogError
* \sa SDL_LogInfo
* \sa SDL_LogMessageV
* \sa SDL_LogTrace
* \sa SDL_LogVerbose
* \sa SDL_LogWarn
*/
@ -380,7 +438,9 @@ extern SDL_DECLSPEC void SDLCALL SDL_LogMessage(int category,
* \param fmt a printf() style message format string.
* \param ap a variable argument list.
*
* \since This function is available since SDL 3.0.0.
* \threadsafety It is safe to call this function from any thread.
*
* \since This function is available since SDL 3.2.0.
*
* \sa SDL_Log
* \sa SDL_LogCritical
@ -388,6 +448,7 @@ extern SDL_DECLSPEC void SDLCALL SDL_LogMessage(int category,
* \sa SDL_LogError
* \sa SDL_LogInfo
* \sa SDL_LogMessage
* \sa SDL_LogTrace
* \sa SDL_LogVerbose
* \sa SDL_LogWarn
*/
@ -398,7 +459,9 @@ extern SDL_DECLSPEC void SDLCALL SDL_LogMessageV(int category,
/**
* The prototype for the log output callback function.
*
* This function is called by SDL when there is new text to be logged.
* This function is called by SDL when there is new text to be logged. A mutex
* is held so that this function is never called by more than one thread at
* once.
*
* \param userdata what was passed as `userdata` to
* SDL_SetLogOutputFunction().
@ -406,10 +469,24 @@ extern SDL_DECLSPEC void SDLCALL SDL_LogMessageV(int category,
* \param priority the priority of the message.
* \param message the message being output.
*
* \since This datatype is available since SDL 3.0.0.
* \since This datatype is available since SDL 3.2.0.
*/
typedef void (SDLCALL *SDL_LogOutputFunction)(void *userdata, int category, SDL_LogPriority priority, const char *message);
/**
* Get the default log output function.
*
* \returns the default log output callback.
*
* \threadsafety It is safe to call this function from any thread.
*
* \since This function is available since SDL 3.2.0.
*
* \sa SDL_SetLogOutputFunction
* \sa SDL_GetLogOutputFunction
*/
extern SDL_DECLSPEC SDL_LogOutputFunction SDLCALL SDL_GetDefaultLogOutputFunction(void);
/**
* Get the current log output function.
*
@ -418,8 +495,11 @@ typedef void (SDLCALL *SDL_LogOutputFunction)(void *userdata, int category, SDL_
* \param userdata a pointer filled in with the pointer that is passed to
* `callback`.
*
* \since This function is available since SDL 3.0.0.
* \threadsafety It is safe to call this function from any thread.
*
* \since This function is available since SDL 3.2.0.
*
* \sa SDL_GetDefaultLogOutputFunction
* \sa SDL_SetLogOutputFunction
*/
extern SDL_DECLSPEC void SDLCALL SDL_GetLogOutputFunction(SDL_LogOutputFunction *callback, void **userdata);
@ -430,8 +510,11 @@ extern SDL_DECLSPEC void SDLCALL SDL_GetLogOutputFunction(SDL_LogOutputFunction
* \param callback an SDL_LogOutputFunction to call instead of the default.
* \param userdata a pointer that is passed to `callback`.
*
* \since This function is available since SDL 3.0.0.
* \threadsafety It is safe to call this function from any thread.
*
* \since This function is available since SDL 3.2.0.
*
* \sa SDL_GetDefaultLogOutputFunction
* \sa SDL_GetLogOutputFunction
*/
extern SDL_DECLSPEC void SDLCALL SDL_SetLogOutputFunction(SDL_LogOutputFunction callback, void *userdata);

View File

@ -1,6 +1,6 @@
/*
Simple DirectMedia Layer
Copyright (C) 1997-2024 Sam Lantinga <slouken@libsdl.org>
Copyright (C) 1997-2025 Sam Lantinga <slouken@libsdl.org>
This software is provided 'as-is', without any express or implied
warranty. In no event will the authors be held liable for any damages
@ -22,13 +22,29 @@
/**
* # CategoryMain
*
* Redefine main() on some platforms so that it is called by SDL.
* Redefine main() if necessary so that it is called by SDL.
*
* For details on how SDL_main works, and how to use it, please refer to:
* In order to make this consistent on all platforms, the application's main()
* should look like this:
*
* ```c
* int main(int argc, char *argv[])
* {
* }
* ```
*
* SDL will take care of platform specific details on how it gets called.
*
* This is also where an app can be configured to use the main callbacks, via
* the SDL_MAIN_USE_CALLBACKS macro.
*
* This is a "single-header library," which is to say that including this
* header inserts code into your program, and you should only include it once
* in most cases. SDL.h does not include this header automatically.
*
* For more information, see:
*
* https://wiki.libsdl.org/SDL3/README/main-functions
*
* (or docs/README-main-functions.md in the SDL source tree)
*/
#ifndef SDL_main_h_
@ -39,8 +55,96 @@
#include <SDL3/SDL_error.h>
#include <SDL3/SDL_events.h>
#ifdef SDL_WIKI_DOCUMENTATION_SECTION
/**
* Inform SDL that the app is providing an entry point instead of SDL.
*
* SDL does not define this macro, but will check if it is defined when
* including `SDL_main.h`. If defined, SDL will expect the app to provide the
* 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
* docs/README-main-functions.md in the source tree) for a more detailed
* explanation.
*
* \since This macro is used by the headers since SDL 3.2.0.
*/
#define SDL_MAIN_HANDLED 1
/**
* Inform SDL to use the main callbacks instead of main.
*
* SDL does not define this macro, but will check if it is defined when
* including `SDL_main.h`. If defined, SDL will expect the app to provide
* several functions: SDL_AppInit, SDL_AppEvent, SDL_AppIterate, and
* 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
* docs/README-main-functions.md in the source tree) for a more detailed
* explanation.
*
* \since This macro is used by the headers since SDL 3.2.0.
*
* \sa SDL_AppInit
* \sa SDL_AppEvent
* \sa SDL_AppIterate
* \sa SDL_AppQuit
*/
#define SDL_MAIN_USE_CALLBACKS 1
/**
* Defined if the target platform offers a special mainline through SDL.
*
* This won't be defined otherwise. If defined, SDL's headers will redefine
* `main` to `SDL_main`.
*
* This macro is defined by `SDL_main.h`, which is not automatically included
* by `SDL.h`.
*
* 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.
*
* \since This macro is available since SDL 3.2.0.
*/
#define SDL_MAIN_AVAILABLE
/**
* Defined if the target platform _requires_ a special mainline through SDL.
*
* This won't be defined otherwise. If defined, SDL's headers will redefine
* `main` to `SDL_main`.
*
* 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.
*
* 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.
*/
#define SDL_MAIN_NEEDED
#endif
#if defined(__has_include)
#if __has_include("SDL_main_private.h") && __has_include("SDL_main_impl_private.h")
#define SDL_PLATFORM_PRIVATE_MAIN
#endif
#endif
#ifndef SDL_MAIN_HANDLED
#ifdef SDL_PLATFORM_WIN32
#if defined(SDL_PLATFORM_PRIVATE_MAIN)
/* Private platforms may have their own ideas about entry points. */
#include "SDL_main_private.h"
#elif defined(SDL_PLATFORM_WIN32)
/* On Windows SDL provides WinMain(), which parses the command line and passes
the arguments to your main function.
@ -48,20 +152,6 @@
*/
#define SDL_MAIN_AVAILABLE
#elif defined(SDL_PLATFORM_WINRT)
/* On WinRT, SDL provides a main function that initializes CoreApplication,
creating an instance of IFrameworkView in the process.
Ideally, #include'ing SDL_main.h is enough to get a main() function working.
However, that requires the source file your main() is in to be compiled
as C++ *and* with the /ZW compiler flag. If that's not feasible, add an
otherwise empty .cpp file that only contains `#include <SDL3/SDL_main.h>`
and build that with /ZW (still include SDL_main.h in your other file with main()!).
In XAML apps, instead the function SDL_RunApp() must be called with a pointer
to the Direct3D-hosted XAML control passed in as the "reserved" argument.
*/
#define SDL_MAIN_NEEDED
#elif defined(SDL_PLATFORM_GDK)
/* On GDK, SDL provides a main function that initializes the game runtime.
@ -91,8 +181,14 @@
*/
#define SDL_MAIN_NEEDED
/* We need to export SDL_main so it can be launched from Java */
#define SDLMAIN_DECLSPEC SDL_DECLSPEC
/* As this is launched from Java, the real entry point (main() function)
is outside of the the binary built from this code.
This define makes sure that, unlike on other platforms, SDL_main.h
and SDL_main_impl.h export an `SDL_main()` function (to be called
from Java), but don't implement a native `int main(int argc, char* argv[])`
or similar.
*/
#define SDL_MAIN_EXPORTED
#elif defined(SDL_PLATFORM_EMSCRIPTEN)
/* On Emscripten, SDL provides a main function that converts URL
@ -129,60 +225,36 @@
*/
#define SDL_MAIN_AVAILABLE
#elif defined(SDL_PLATFORM_NGAGE)
/*
TODO: not sure if it should be SDL_MAIN_NEEDED, in SDL2 ngage had a
main implementation, but wasn't mentioned in SDL_main.h
*/
#define SDL_MAIN_AVAILABLE
#endif
#endif /* SDL_MAIN_HANDLED */
#ifndef SDLMAIN_DECLSPEC
#define SDLMAIN_DECLSPEC
#endif
/**
* \file SDL_main.h
*
* The application's main() function must be called with C linkage,
* and should be declared like this:
*
* ```c
* #ifdef __cplusplus
* extern "C"
* #endif
* int main(int argc, char *argv[])
* {
* }
* ```
*/
#ifdef SDL_WIKI_DOCUMENTATION_SECTION
/**
* Inform SDL to use the main callbacks instead of main.
* A macro to tag a main entry point function as exported.
*
* SDL does not define this macro, but will check if it is defined when
* including `SDL_main.h`. If defined, SDL will expect the app to provide
* several functions: SDL_AppInit, SDL_AppEvent, SDL_AppIterate, and
* SDL_AppQuit. The app should not provide a `main` function in this case, and
* doing so will likely cause the build to fail.
* Most platforms don't need this, and the macro will be defined to nothing.
* Some, like Android, keep the entry points in a shared library and need to
* explicitly export the symbols.
*
* Please see [README/main-functions](README/main-functions), (or
* docs/README-main-functions.md in the source tree) for a more detailed
* explanation.
* External code rarely needs this, and if it needs something, it's almost
* always SDL_DECLSPEC instead.
*
* \since This macro is used by the headers since SDL 3.0.0.
* \since This macro is available since SDL 3.2.0.
*
* \sa SDL_AppInit
* \sa SDL_AppEvent
* \sa SDL_AppIterate
* \sa SDL_AppQuit
* \sa SDL_DECLSPEC
*/
#define SDL_MAIN_USE_CALLBACKS 1
#endif
#define SDLMAIN_DECLSPEC
#elif defined(SDL_MAIN_EXPORTED)
/* We need to export SDL_main so it can be launched from external code,
like SDLActivity.java on Android */
#define SDLMAIN_DECLSPEC SDL_DECLSPEC
#else
/* usually this is empty */
#define SDLMAIN_DECLSPEC
#endif /* SDL_MAIN_EXPORTED */
#if defined(SDL_MAIN_NEEDED) || defined(SDL_MAIN_AVAILABLE) || defined(SDL_MAIN_USE_CALLBACKS)
#define main SDL_main
@ -248,6 +320,8 @@ extern "C" {
* SDL_APP_SUCCESS, SDL calls SDL_AppQuit and terminates with an exit code
* that reports success to the platform.
*
* This function is called by SDL on the main thread.
*
* \param appstate a place where the app can optionally store a pointer for
* future use.
* \param argc the standard ANSI C main's argc; number of elements in `argv`.
@ -256,9 +330,7 @@ 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 not thread safe.
*
* \since This function is available since SDL 3.0.0.
* \since This function is available since SDL 3.2.0.
*
* \sa SDL_AppIterate
* \sa SDL_AppEvent
@ -301,13 +373,16 @@ extern SDLMAIN_DECLSPEC SDL_AppResult SDLCALL SDL_AppInit(void **appstate, int a
* SDL_AppQuit and terminates with an exit code that reports success to the
* platform.
*
* This function is called by SDL on the main thread.
*
* \param appstate an optional pointer, provided by the app in SDL_AppInit.
* \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 not thread safe.
* \threadsafety This function may get called concurrently with SDL_AppEvent()
* for events not pushed on the main thread.
*
* \since This function is available since SDL 3.0.0.
* \since This function is available since SDL 3.2.0.
*
* \sa SDL_AppInit
* \sa SDL_AppEvent
@ -320,15 +395,15 @@ extern SDLMAIN_DECLSPEC SDL_AppResult SDLCALL SDL_AppIterate(void *appstate);
* 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 as needed by SDL after SDL_AppInit returns 0; It is
* called once for each new event.
* This function is called as needed by SDL after SDL_AppInit returns
* SDL_APP_CONTINUE. It is called once for each new event.
*
* There is (currently) no guarantee about what thread this will be called
* from; whatever thread pushes an event onto SDL's queue will trigger this
* function. SDL is responsible for pumping the event queue between each call
* to SDL_AppIterate, so in normal operation one should only get events in a
* serial fashion, but be careful if you have a thread that explicitly calls
* SDL_PushEvent.
* SDL_PushEvent. SDL itself will push events to the queue on the main thread.
*
* Events sent to this function are not owned by the app; if you need to save
* the data, you should copy it.
@ -352,14 +427,16 @@ extern SDLMAIN_DECLSPEC SDL_AppResult SDLCALL SDL_AppIterate(void *appstate);
* \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 not thread safe.
* \threadsafety This function may get called concurrently with
* SDL_AppIterate() or SDL_AppQuit() for events not pushed from
* the main thread.
*
* \since This function is available since SDL 3.0.0.
* \since This function is available since SDL 3.2.0.
*
* \sa SDL_AppInit
* \sa SDL_AppIterate
*/
extern SDLMAIN_DECLSPEC SDL_AppResult SDLCALL SDL_AppEvent(void *appstate, const SDL_Event *event);
extern SDLMAIN_DECLSPEC SDL_AppResult SDLCALL SDL_AppEvent(void *appstate, SDL_Event *event);
/**
* App-implemented deinit entry point for SDL_MAIN_USE_CALLBACKS apps.
@ -385,15 +462,19 @@ extern SDLMAIN_DECLSPEC SDL_AppResult SDLCALL SDL_AppEvent(void *appstate, const
* function call is the last time this pointer will be provided, so any
* resources to it should be cleaned up here.
*
* This function is called by SDL on the main thread.
*
* \param appstate an optional pointer, provided by the app in SDL_AppInit.
* \param result the result code that terminated the app (success or failure).
*
* \threadsafety This function is not thread safe.
* \threadsafety SDL_AppEvent() may get called concurrently with this function
* if other threads that push events are still active.
*
* \since This function is available since SDL 3.0.0.
* \since This function is available since SDL 3.2.0.
*
* \sa SDL_AppInit
*/
extern SDLMAIN_DECLSPEC void SDLCALL SDL_AppQuit(void *appstate);
extern SDLMAIN_DECLSPEC void SDLCALL SDL_AppQuit(void *appstate, SDL_AppResult result);
#endif /* SDL_MAIN_USE_CALLBACKS */
@ -407,7 +488,7 @@ extern SDLMAIN_DECLSPEC void SDLCALL SDL_AppQuit(void *appstate);
* program completion, and small non-zero values are considered
* errors.
*
* \since This datatype is available since SDL 3.0.0.
* \since This datatype is available since SDL 3.2.0.
*/
typedef int (SDLCALL *SDL_main_func)(int argc, char *argv[]);
@ -440,7 +521,7 @@ typedef int (SDLCALL *SDL_main_func)(int argc, char *argv[]);
*
* \threadsafety This is the program entry point.
*
* \since This function is available since SDL 3.0.0.
* \since This function is available since SDL 3.2.0.
*/
extern SDLMAIN_DECLSPEC int SDLCALL SDL_main(int argc, char *argv[]);
@ -453,7 +534,7 @@ 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.
*
* \since This function is available since SDL 3.0.0.
* \since This function is available since SDL 3.2.0.
*
* \sa SDL_Init
*/
@ -485,7 +566,7 @@ extern SDL_DECLSPEC void SDLCALL SDL_SetMainReady(void);
* \threadsafety Generally this is called once, near startup, from the
* process's initial thread.
*
* \since This function is available since SDL 3.0.0.
* \since This function is available since SDL 3.2.0.
*/
extern SDL_DECLSPEC int SDLCALL SDL_RunApp(int argc, char *argv[], SDL_main_func mainFunction, void *reserved);
@ -512,12 +593,12 @@ extern SDL_DECLSPEC int SDLCALL SDL_RunApp(int argc, char *argv[], SDL_main_func
* \threadsafety It is not safe to call this anywhere except as the only
* function call in SDL_main.
*
* \since This function is available since SDL 3.0.0.
* \since This function is available since SDL 3.2.0.
*/
extern SDL_DECLSPEC int SDLCALL SDL_EnterAppMainCallbacks(int argc, char *argv[], SDL_AppInit_func appinit, SDL_AppIterate_func appiter, SDL_AppEvent_func appevent, SDL_AppQuit_func appquit);
#if defined(SDL_PLATFORM_WIN32) || defined(SDL_PLATFORM_GDK)
#if defined(SDL_PLATFORM_WINDOWS)
/**
* Register a win32 window class for SDL's use.
@ -538,12 +619,12 @@ extern SDL_DECLSPEC int SDLCALL SDL_EnterAppMainCallbacks(int argc, char *argv[]
* what is specified here.
* \param hInst the HINSTANCE to use in WNDCLASSEX::hInstance. If zero, SDL
* will use `GetModuleHandle(NULL)` instead.
* \returns SDL_TRUE on success or SDL_FALSE on failure; call SDL_GetError()
* for more information.
* \returns true on success or false on failure; call SDL_GetError() for more
* information.
*
* \since This function is available since SDL 3.0.0.
* \since This function is available since SDL 3.2.0.
*/
extern SDL_DECLSPEC SDL_bool SDLCALL SDL_RegisterApp(const char *name, Uint32 style, void *hInst);
extern SDL_DECLSPEC bool SDLCALL SDL_RegisterApp(const char *name, Uint32 style, void *hInst);
/**
* Deregister the win32 window class from an SDL_RegisterApp call.
@ -558,23 +639,22 @@ extern SDL_DECLSPEC SDL_bool SDLCALL SDL_RegisterApp(const char *name, Uint32 st
* deregistered when the registration counter in SDL_RegisterApp decrements to
* zero through calls to this function.
*
* \since This function is available since SDL 3.0.0.
* \since This function is available since SDL 3.2.0.
*/
extern SDL_DECLSPEC void SDLCALL SDL_UnregisterApp(void);
#endif /* defined(SDL_PLATFORM_WIN32) || defined(SDL_PLATFORM_GDK) */
#ifdef SDL_PLATFORM_GDK
#endif /* defined(SDL_PLATFORM_WINDOWS) */
/**
* Callback from the application to let the suspend continue.
*
* \since This function is available since SDL 3.0.0.
* This function is only needed for Xbox GDK support; all other platforms will
* do nothing and set an "unsupported" error message.
*
* \since This function is available since SDL 3.2.0.
*/
extern SDL_DECLSPEC void SDLCALL SDL_GDKSuspendComplete(void);
#endif /* SDL_PLATFORM_GDK */
#ifdef __cplusplus
}
#endif
@ -583,29 +663,10 @@ extern SDL_DECLSPEC void SDLCALL SDL_GDKSuspendComplete(void);
#if !defined(SDL_MAIN_HANDLED) && !defined(SDL_MAIN_NOIMPL)
/* include header-only SDL_main implementations */
#if defined(SDL_MAIN_USE_CALLBACKS) \
|| defined(SDL_PLATFORM_WIN32) || defined(SDL_PLATFORM_GDK) || defined(SDL_PLATFORM_IOS) || defined(SDL_PLATFORM_TVOS) \
|| defined(SDL_PLATFORM_3DS) || defined(SDL_PLATFORM_NGAGE) || defined(SDL_PLATFORM_PS2) || defined(SDL_PLATFORM_PSP) \
|| defined(SDL_PLATFORM_EMSCRIPTEN)
#if defined(SDL_MAIN_USE_CALLBACKS) || defined(SDL_MAIN_NEEDED) || defined(SDL_MAIN_AVAILABLE)
/* platforms which main (-equivalent) can be implemented in plain C */
#include <SDL3/SDL_main_impl.h>
#elif defined(SDL_PLATFORM_WINRT) /* C++ platforms */
#ifdef __cplusplus
#include <SDL3/SDL_main_impl.h>
#else
/* Note: to get rid of the following warning, you can #define SDL_MAIN_NOIMPL before including SDL_main.h
* in your C sourcefile that contains the standard main. Do *not* use SDL_MAIN_HANDLED for that, then SDL_main won't find your main()!
*/
#ifdef _MSC_VER
#pragma message("Note: Your platform needs the SDL_main implementation in a C++ source file. You can keep your main() in plain C (then continue including SDL_main.h there!) and create a fresh .cpp file that only contains #include <SDL3/SDL_main.h>")
#elif defined(__GNUC__) /* gcc, clang, mingw and compatible are matched by this and have #warning */
#warning "Note: Your platform needs the SDL_main implementation in a C++ source file. You can keep your main() in plain C and create a fresh .cpp file that only contains #include <SDL3/SDL_main.h>"
#endif /* __GNUC__ */
#endif /* __cplusplus */
#endif /* C++ platforms like SDL_PLATFORM_WINRT etc */
#endif
#endif
#endif /* SDL_main_h_ */

View File

@ -1,6 +1,6 @@
/*
Simple DirectMedia Layer
Copyright (C) 1997-2024 Sam Lantinga <slouken@libsdl.org>
Copyright (C) 1997-2025 Sam Lantinga <slouken@libsdl.org>
This software is provided 'as-is', without any express or implied
warranty. In no event will the authors be held liable for any damages
@ -29,7 +29,7 @@
#endif
/* if someone wants to include SDL_main.h but doesn't want the main handing magic,
(maybe to call SDL_RegisterApp()) they can #define SDL_MAIN_HANDLED first
(maybe to call SDL_RegisterApp()) they can #define SDL_MAIN_HANDLED first.
SDL_MAIN_NOIMPL is for SDL-internal usage (only affects implementation,
not definition of SDL_MAIN_AVAILABLE etc in SDL_main.h) and if the user wants
to have the SDL_main implementation (from this header) in another source file
@ -64,10 +64,15 @@
#endif /* SDL_MAIN_USE_CALLBACKS */
/* set up the usual SDL_main stuff if we're not using callbacks or if we are but need the normal entry point. */
#if !defined(SDL_MAIN_USE_CALLBACKS) || defined(SDL_MAIN_CALLBACK_STANDARD)
/* set up the usual SDL_main stuff if we're not using callbacks or if we are but need the normal entry point,
unless the real entry point needs to be somewhere else entirely, like Android where it's in Java code */
#if (!defined(SDL_MAIN_USE_CALLBACKS) || defined(SDL_MAIN_CALLBACK_STANDARD)) && !defined(SDL_MAIN_EXPORTED)
#if defined(SDL_PLATFORM_WIN32) || defined(SDL_PLATFORM_GDK)
#if defined(SDL_PLATFORM_PRIVATE_MAIN)
/* Private platforms may have their own ideas about entry points. */
#include "SDL_main_impl_private.h"
#elif defined(SDL_PLATFORM_WINDOWS)
/* these defines/typedefs are needed for the WinMain() definition */
#ifndef WINAPI
@ -82,7 +87,7 @@
#if defined(_MSC_VER) && !defined(SDL_PLATFORM_GDK)
/* This is where execution begins [console apps] */
#if defined( UNICODE ) && UNICODE
#if defined(UNICODE) && UNICODE
int wmain(int argc, wchar_t *wargv[], wchar_t *wenvp)
{
(void)argc;
@ -107,7 +112,7 @@
extern "C" {
#endif
#if defined( UNICODE ) && UNICODE
#if defined(UNICODE) && UNICODE
int WINAPI wWinMain(HINSTANCE hInst, HINSTANCE hPrev, PWSTR szCmdLine, int sw)
#else /* ANSI */
int WINAPI WinMain(HINSTANCE hInst, HINSTANCE hPrev, LPSTR szCmdLine, int sw)
@ -124,83 +129,7 @@
} /* extern "C" */
#endif
/* end of SDL_PLATFORM_WIN32 and SDL_PLATFORM_GDK impls */
#elif defined(SDL_PLATFORM_WINRT)
/* WinRT main based on SDL_winrt_main_NonXAML.cpp, placed in the public domain by David Ludwig 3/13/14 */
#include <wrl.h>
/* At least one file in any SDL/WinRT app appears to require compilation
with C++/CX, otherwise a Windows Metadata file won't get created, and
an APPX0702 build error can appear shortly after linking.
The following set of preprocessor code forces this file to be compiled
as C++/CX, which appears to cause Visual C++ 2012's build tools to
create this .winmd file, and will help allow builds of SDL/WinRT apps
to proceed without error.
If other files in an app's project enable C++/CX compilation, then it might
be possible for the .cpp file including SDL_main.h to be compiled without /ZW,
for Visual C++'s build tools to create a winmd file, and for the app to
build without APPX0702 errors. In this case, if
SDL_WINRT_METADATA_FILE_AVAILABLE is defined as a C/C++ macro, then
the #error (to force C++/CX compilation) will be disabled.
Please note that /ZW can be specified on a file-by-file basis. To do this,
right click on the file in Visual C++, click Properties, then change the
setting through the dialog that comes up.
*/
#ifndef SDL_WINRT_METADATA_FILE_AVAILABLE
#if !defined(__cplusplus) || (!defined(__cplusplus_winrt) && _MSVC_LANG < 202002L)
#error The C++ file that includes SDL_main.h must be compiled as C++ code with /ZW, otherwise build errors due to missing .winmd files can occur.
#endif
#endif
/* Prevent MSVC++ from warning about threading models when defining our
custom WinMain. The threading model will instead be set via a direct
call to Windows::Foundation::Initialize (rather than via an attributed
function).
To note, this warning (C4447) does not seem to come up unless this file
is compiled with C++/CX enabled (via the /ZW compiler flag).
*/
#ifdef _MSC_VER
#pragma warning(disable : 4447)
/* Make sure the function to initialize the Windows Runtime gets linked in. */
#pragma comment(lib, "runtimeobject.lib")
#endif
#ifdef __cplusplus
extern "C" {
#endif
int CALLBACK WinMain(HINSTANCE, HINSTANCE, LPSTR, int)
{
return SDL_RunApp(0, NULL, SDL_main, NULL);
}
#if _MSVC_LANG >= 202002L
int main(int argc, char** argv) {
return SDL_RunApp(argc, argv, SDL_main, NULL);
}
#endif
#ifdef __cplusplus
} /* extern "C" */
#endif
/* end of WinRT impl */
#elif defined(SDL_PLATFORM_NGAGE)
/* same typedef as in ngage SDKs e32def.h */
typedef signed int TInt;
/* TODO: if it turns out that this only works when built as C++,
move SDL_PLATFORM_NGAGE into the C++ section in SDL_main.h */
TInt E32Main()
{
return SDL_RunApp(0, NULL, SDL_main, NULL);
}
/* end of SDL_PLATFORM_NGAGE impl */
/* end of SDL_PLATFORM_WINDOWS impls */
#else /* platforms that use a standard main() and just call SDL_RunApp(), like iOS and 3DS */
int main(int argc, char *argv[])

View File

@ -1,6 +1,6 @@
/*
Simple DirectMedia Layer
Copyright (C) 1997-2024 Sam Lantinga <slouken@libsdl.org>
Copyright (C) 1997-2025 Sam Lantinga <slouken@libsdl.org>
This software is provided 'as-is', without any express or implied
warranty. In no event will the authors be held liable for any damages
@ -22,7 +22,18 @@
/**
* # CategoryMessagebox
*
* Message box support routines.
* SDL offers a simple message box API, which is useful for simple alerts,
* such as informing the user when something fatal happens at startup without
* the need to build a UI for it (or informing the user _before_ your UI is
* ready).
*
* These message boxes are native system dialogs where possible.
*
* There is both a customizable function (SDL_ShowMessageBox()) that offers
* lots of options for what to display and reports on what choice the user
* made, and also a much-simplified version (SDL_ShowSimpleMessageBox()),
* merely takes a text message and title, and waits until the user presses a
* single "OK" UI button. Often, this is all that is necessary.
*/
#ifndef SDL_messagebox_h_
@ -39,11 +50,11 @@ extern "C" {
#endif
/**
* SDL_MessageBox flags.
* Message box flags.
*
* If supported will display warning icon, etc.
*
* \since This datatype is available since SDL 3.0.0.
* \since This datatype is available since SDL 3.2.0.
*/
typedef Uint32 SDL_MessageBoxFlags;
@ -56,7 +67,7 @@ typedef Uint32 SDL_MessageBoxFlags;
/**
* SDL_MessageBoxButtonData flags.
*
* \since This datatype is available since SDL 3.0.0.
* \since This datatype is available since SDL 3.2.0.
*/
typedef Uint32 SDL_MessageBoxButtonFlags;
@ -66,7 +77,7 @@ typedef Uint32 SDL_MessageBoxButtonFlags;
/**
* Individual button data.
*
* \since This struct is available since SDL 3.0.0.
* \since This struct is available since SDL 3.2.0.
*/
typedef struct SDL_MessageBoxButtonData
{
@ -78,7 +89,7 @@ typedef struct SDL_MessageBoxButtonData
/**
* RGB value used in a message box color scheme
*
* \since This struct is available since SDL 3.0.0.
* \since This struct is available since SDL 3.2.0.
*/
typedef struct SDL_MessageBoxColor
{
@ -96,23 +107,23 @@ typedef enum SDL_MessageBoxColorType
SDL_MESSAGEBOX_COLOR_BUTTON_BORDER,
SDL_MESSAGEBOX_COLOR_BUTTON_BACKGROUND,
SDL_MESSAGEBOX_COLOR_BUTTON_SELECTED,
SDL_MESSAGEBOX_COLOR_MAX /**< Size of the colors array of SDL_MessageBoxColorScheme. */
SDL_MESSAGEBOX_COLOR_COUNT /**< Size of the colors array of SDL_MessageBoxColorScheme. */
} SDL_MessageBoxColorType;
/**
* A set of colors to use for message box dialogs
*
* \since This struct is available since SDL 3.0.0.
* \since This struct is available since SDL 3.2.0.
*/
typedef struct SDL_MessageBoxColorScheme
{
SDL_MessageBoxColor colors[SDL_MESSAGEBOX_COLOR_MAX];
SDL_MessageBoxColor colors[SDL_MESSAGEBOX_COLOR_COUNT];
} SDL_MessageBoxColorScheme;
/**
* MessageBox structure containing title, text, window, etc.
*
* \since This struct is available since SDL 3.0.0.
* \since This struct is available since SDL 3.2.0.
*/
typedef struct SDL_MessageBoxData
{
@ -154,14 +165,14 @@ typedef struct SDL_MessageBoxData
* other options.
* \param buttonid the pointer to which user id of hit button should be
* copied.
* \returns SDL_TRUE on success or SDL_FALSE on failure; call SDL_GetError()
* for more information.
* \returns true on success or false on failure; call SDL_GetError() for more
* information.
*
* \since This function is available since SDL 3.0.0.
* \since This function is available since SDL 3.2.0.
*
* \sa SDL_ShowSimpleMessageBox
*/
extern SDL_DECLSPEC SDL_bool SDLCALL SDL_ShowMessageBox(const SDL_MessageBoxData *messageboxdata, int *buttonid);
extern SDL_DECLSPEC bool SDLCALL SDL_ShowMessageBox(const SDL_MessageBoxData *messageboxdata, int *buttonid);
/**
* Display a simple modal message box.
@ -193,17 +204,17 @@ extern SDL_DECLSPEC SDL_bool SDLCALL SDL_ShowMessageBox(const SDL_MessageBoxData
* to stderr if you can.
*
* \param flags an SDL_MessageBoxFlags value.
* \param title uTF-8 title text.
* \param message uTF-8 message text.
* \param title UTF-8 title text.
* \param message UTF-8 message text.
* \param window the parent window, or NULL for no parent.
* \returns SDL_TRUE on success or SDL_FALSE on failure; call SDL_GetError()
* for more information.
* \returns true on success or false on failure; call SDL_GetError() for more
* information.
*
* \since This function is available since SDL 3.0.0.
* \since This function is available since SDL 3.2.0.
*
* \sa SDL_ShowMessageBox
*/
extern SDL_DECLSPEC SDL_bool SDLCALL SDL_ShowSimpleMessageBox(SDL_MessageBoxFlags flags, const char *title, const char *message, SDL_Window *window);
extern SDL_DECLSPEC bool SDLCALL SDL_ShowSimpleMessageBox(SDL_MessageBoxFlags flags, const char *title, const char *message, SDL_Window *window);
/* Ends C function definitions when using C++ */

View File

@ -1,6 +1,6 @@
/*
Simple DirectMedia Layer
Copyright (C) 1997-2024 Sam Lantinga <slouken@libsdl.org>
Copyright (C) 1997-2025 Sam Lantinga <slouken@libsdl.org>
This software is provided 'as-is', without any express or implied
warranty. In no event will the authors be held liable for any damages
@ -23,6 +23,10 @@
* # CategoryMetal
*
* Functions to creating Metal layers and views on SDL windows.
*
* This provides some platform-specific glue for Apple platforms. Most macOS
* and iOS apps can use SDL without these functions, but this API they can be
* useful for specific OS-level integration tasks.
*/
#ifndef SDL_metal_h_
@ -39,7 +43,7 @@ extern "C" {
/**
* A handle to a CAMetalLayer-backed NSView (macOS) or UIView (iOS/tvOS).
*
* \since This datatype is available since SDL 3.0.0.
* \since This datatype is available since SDL 3.2.0.
*/
typedef void *SDL_MetalView;
@ -61,7 +65,7 @@ typedef void *SDL_MetalView;
* \param window the window.
* \returns handle NSView or UIView.
*
* \since This function is available since SDL 3.0.0.
* \since This function is available since SDL 3.2.0.
*
* \sa SDL_Metal_DestroyView
* \sa SDL_Metal_GetLayer
@ -76,7 +80,7 @@ extern SDL_DECLSPEC SDL_MetalView SDLCALL SDL_Metal_CreateView(SDL_Window *windo
*
* \param view the SDL_MetalView object.
*
* \since This function is available since SDL 3.0.0.
* \since This function is available since SDL 3.2.0.
*
* \sa SDL_Metal_CreateView
*/
@ -88,7 +92,7 @@ extern SDL_DECLSPEC void SDLCALL SDL_Metal_DestroyView(SDL_MetalView view);
* \param view the SDL_MetalView object.
* \returns a pointer.
*
* \since This function is available since SDL 3.0.0.
* \since This function is available since SDL 3.2.0.
*/
extern SDL_DECLSPEC void * SDLCALL SDL_Metal_GetLayer(SDL_MetalView view);

View File

@ -1,6 +1,6 @@
/*
Simple DirectMedia Layer
Copyright (C) 1997-2024 Sam Lantinga <slouken@libsdl.org>
Copyright (C) 1997-2025 Sam Lantinga <slouken@libsdl.org>
This software is provided 'as-is', without any express or implied
warranty. In no event will the authors be held liable for any damages
@ -62,12 +62,12 @@ extern "C" {
*
* \param url a valid URL/URI to open. Use `file:///full/path/to/file` for
* local files, if supported.
* \returns SDL_TRUE on success or SDL_FALSE on failure; call SDL_GetError()
* for more information.
* \returns true on success or false on failure; call SDL_GetError() for more
* information.
*
* \since This function is available since SDL 3.0.0.
* \since This function is available since SDL 3.2.0.
*/
extern SDL_DECLSPEC SDL_bool SDLCALL SDL_OpenURL(const char *url);
extern SDL_DECLSPEC bool SDLCALL SDL_OpenURL(const char *url);
/* Ends C function definitions when using C++ */
#ifdef __cplusplus

View File

@ -1,6 +1,6 @@
/*
Simple DirectMedia Layer
Copyright (C) 1997-2024 Sam Lantinga <slouken@libsdl.org>
Copyright (C) 1997-2025 Sam Lantinga <slouken@libsdl.org>
This software is provided 'as-is', without any express or implied
warranty. In no event will the authors be held liable for any damages
@ -22,7 +22,36 @@
/**
* # CategoryMouse
*
* SDL mouse handling.
* Any GUI application has to deal with the mouse, and SDL provides functions
* to manage mouse input and the displayed cursor.
*
* Most interactions with the mouse will come through the event subsystem.
* Moving a mouse generates an SDL_EVENT_MOUSE_MOTION event, pushing a button
* generates SDL_EVENT_MOUSE_BUTTON_DOWN, etc, but one can also query the
* current state of the mouse at any time with SDL_GetMouseState().
*
* For certain games, it's useful to disassociate the mouse cursor from mouse
* input. An FPS, for example, would not want the player's motion to stop as
* the mouse hits the edge of the window. For these scenarios, use
* SDL_SetWindowRelativeMouseMode(), which hides the cursor, grabs mouse input
* to the window, and reads mouse input no matter how far it moves.
*
* Games that want the system to track the mouse but want to draw their own
* cursor can use SDL_HideCursor() and SDL_ShowCursor(). It might be more
* efficient to let the system manage the cursor, if possible, using
* SDL_SetCursor() with a custom image made through SDL_CreateColorCursor(),
* or perhaps just a specific system cursor from SDL_CreateSystemCursor().
*
* SDL can, on many platforms, differentiate between multiple connected mice,
* allowing for interesting input scenarios and multiplayer games. They can be
* enumerated with SDL_GetMice(), and SDL will send SDL_EVENT_MOUSE_ADDED and
* SDL_EVENT_MOUSE_REMOVED events as they are connected and unplugged.
*
* Since many apps only care about basic mouse input, SDL offers a virtual
* mouse device for touch and pen input, which often can make a desktop
* application work on a touchscreen phone without any code changes. Apps that
* care about touch/pen separately from mouse input should filter out events
* with a `which` field of SDL_TOUCH_MOUSEID/SDL_PEN_MOUSEID.
*/
#ifndef SDL_mouse_h_
@ -30,6 +59,7 @@
#include <SDL3/SDL_stdinc.h>
#include <SDL3/SDL_error.h>
#include <SDL3/SDL_surface.h>
#include <SDL3/SDL_video.h>
#include <SDL3/SDL_begin_code.h>
@ -46,7 +76,7 @@ extern "C" {
*
* The value 0 is an invalid ID.
*
* \since This datatype is available since SDL 3.0.0.
* \since This datatype is available since SDL 3.2.0.
*/
typedef Uint32 SDL_MouseID;
@ -55,14 +85,14 @@ typedef Uint32 SDL_MouseID;
*
* This is opaque data.
*
* \since This struct is available since SDL 3.0.0.
* \since This struct is available since SDL 3.2.0.
*/
typedef struct SDL_Cursor SDL_Cursor;
/**
* Cursor types for SDL_CreateSystemCursor().
*
* \since This enum is available since SDL 3.0.0.
* \since This enum is available since SDL 3.2.0.
*/
typedef enum SDL_SystemCursor
{
@ -86,13 +116,13 @@ typedef enum SDL_SystemCursor
SDL_SYSTEM_CURSOR_S_RESIZE, /**< Window resize bottom. May be NS_RESIZE. */
SDL_SYSTEM_CURSOR_SW_RESIZE, /**< Window resize bottom-left. May be NESW_RESIZE. */
SDL_SYSTEM_CURSOR_W_RESIZE, /**< Window resize left. May be EW_RESIZE. */
SDL_NUM_SYSTEM_CURSORS
SDL_SYSTEM_CURSOR_COUNT
} SDL_SystemCursor;
/**
* Scroll direction types for the Scroll event
*
* \since This enum is available since SDL 3.0.0.
* \since This enum is available since SDL 3.2.0.
*/
typedef enum SDL_MouseWheelDirection
{
@ -109,7 +139,7 @@ typedef enum SDL_MouseWheelDirection
* - Button 4: Side mouse button 1
* - Button 5: Side mouse button 2
*
* \since This datatype is available since SDL 3.0.0.
* \since This datatype is available since SDL 3.2.0.
*
* \sa SDL_GetMouseState
* \sa SDL_GetGlobalMouseState
@ -123,12 +153,12 @@ typedef Uint32 SDL_MouseButtonFlags;
#define SDL_BUTTON_X1 4
#define SDL_BUTTON_X2 5
#define SDL_BUTTON(X) (1u << ((X)-1))
#define SDL_BUTTON_LMASK SDL_BUTTON(SDL_BUTTON_LEFT)
#define SDL_BUTTON_MMASK SDL_BUTTON(SDL_BUTTON_MIDDLE)
#define SDL_BUTTON_RMASK SDL_BUTTON(SDL_BUTTON_RIGHT)
#define SDL_BUTTON_X1MASK SDL_BUTTON(SDL_BUTTON_X1)
#define SDL_BUTTON_X2MASK SDL_BUTTON(SDL_BUTTON_X2)
#define SDL_BUTTON_MASK(X) (1u << ((X)-1))
#define SDL_BUTTON_LMASK SDL_BUTTON_MASK(SDL_BUTTON_LEFT)
#define SDL_BUTTON_MMASK SDL_BUTTON_MASK(SDL_BUTTON_MIDDLE)
#define SDL_BUTTON_RMASK SDL_BUTTON_MASK(SDL_BUTTON_RIGHT)
#define SDL_BUTTON_X1MASK SDL_BUTTON_MASK(SDL_BUTTON_X1)
#define SDL_BUTTON_X2MASK SDL_BUTTON_MASK(SDL_BUTTON_X2)
/* Function prototypes */
@ -136,13 +166,15 @@ typedef Uint32 SDL_MouseButtonFlags;
/**
* Return whether a mouse is currently connected.
*
* \returns SDL_TRUE if a mouse is connected, SDL_FALSE otherwise.
* \returns true if a mouse is connected, false otherwise.
*
* \since This function is available since SDL 3.0.0.
* \threadsafety This function should only be called on the main thread.
*
* \since This function is available since SDL 3.2.0.
*
* \sa SDL_GetMice
*/
extern SDL_DECLSPEC SDL_bool SDLCALL SDL_HasMouse(void);
extern SDL_DECLSPEC bool SDLCALL SDL_HasMouse(void);
/**
* Get a list of currently connected mice.
@ -158,7 +190,9 @@ extern SDL_DECLSPEC SDL_bool SDLCALL SDL_HasMouse(void);
* call SDL_GetError() for more information. This should be freed
* with SDL_free() when it is no longer needed.
*
* \since This function is available since SDL 3.0.0.
* \threadsafety This function should only be called on the main thread.
*
* \since This function is available since SDL 3.2.0.
*
* \sa SDL_GetMouseNameForID
* \sa SDL_HasMouse
@ -174,7 +208,9 @@ extern SDL_DECLSPEC SDL_MouseID * SDLCALL SDL_GetMice(int *count);
* \returns the name of the selected mouse, or NULL on failure; call
* SDL_GetError() for more information.
*
* \since This function is available since SDL 3.0.0.
* \threadsafety This function should only be called on the main thread.
*
* \since This function is available since SDL 3.2.0.
*
* \sa SDL_GetMice
*/
@ -185,26 +221,39 @@ extern SDL_DECLSPEC const char * SDLCALL SDL_GetMouseNameForID(SDL_MouseID insta
*
* \returns the window with mouse focus.
*
* \since This function is available since SDL 3.0.0.
* \threadsafety This function should only be called on the main thread.
*
* \since This function is available since SDL 3.2.0.
*/
extern SDL_DECLSPEC SDL_Window * SDLCALL SDL_GetMouseFocus(void);
/**
* Retrieve the current state of the mouse.
* Query SDL's cache for the synchronous mouse button state and the
* window-relative SDL-cursor position.
*
* The current button state is returned as a button bitmask, which can be
* tested using the SDL_BUTTON(X) macro (where `X` is generally 1 for the
* left, 2 for middle, 3 for the right button), and `x` and `y` are set to the
* mouse cursor position relative to the focus window. You can pass NULL for
* either `x` or `y`.
* This function returns the cached synchronous state as SDL understands it
* from the last pump of the event queue.
*
* \param x the x coordinate of the mouse cursor position relative to the
* focus window.
* \param y the y coordinate of the mouse cursor position relative to the
* focus window.
* \returns a 32-bit button bitmask of the current button state.
* To query the platform for immediate asynchronous state, use
* SDL_GetGlobalMouseState.
*
* \since This function is available since SDL 3.0.0.
* Passing non-NULL pointers to `x` or `y` will write the destination with
* respective x or y coordinates relative to the focused window.
*
* In Relative Mode, the SDL-cursor's position usually contradicts the
* platform-cursor's position as manually calculated from
* SDL_GetGlobalMouseState() and SDL_GetWindowPosition.
*
* \param x a pointer to receive the SDL-cursor's x-position from the focused
* window's top left corner, can be NULL if unused.
* \param y a pointer to receive the SDL-cursor's y-position from the focused
* window's top left corner, can be NULL if unused.
* \returns a 32-bit bitmask of the button state that can be bitwise-compared
* against the SDL_BUTTON_MASK(X) macro.
*
* \threadsafety This function should only be called on the main thread.
*
* \since This function is available since SDL 3.2.0.
*
* \sa SDL_GetGlobalMouseState
* \sa SDL_GetRelativeMouseState
@ -212,51 +261,74 @@ extern SDL_DECLSPEC SDL_Window * SDLCALL SDL_GetMouseFocus(void);
extern SDL_DECLSPEC SDL_MouseButtonFlags SDLCALL SDL_GetMouseState(float *x, float *y);
/**
* Get the current state of the mouse in relation to the desktop.
* Query the platform for the asynchronous mouse button state and the
* desktop-relative platform-cursor position.
*
* This works similarly to SDL_GetMouseState(), but the coordinates will be
* reported relative to the top-left of the desktop. This can be useful if you
* need to track the mouse outside of a specific window and SDL_CaptureMouse()
* doesn't fit your needs. For example, it could be useful if you need to
* track the mouse while dragging a window, where coordinates relative to a
* window might not be in sync at all times.
* This function immediately queries the platform for the most recent
* asynchronous state, more costly than retrieving SDL's cached state in
* SDL_GetMouseState().
*
* Note: SDL_GetMouseState() returns the mouse position as SDL understands it
* from the last pump of the event queue. This function, however, queries the
* OS for the current mouse position, and as such, might be a slightly less
* efficient function. Unless you know what you're doing and have a good
* reason to use this function, you probably want SDL_GetMouseState() instead.
* Passing non-NULL pointers to `x` or `y` will write the destination with
* respective x or y coordinates relative to the desktop.
*
* \param x filled in with the current X coord relative to the desktop; can be
* NULL.
* \param y filled in with the current Y coord relative to the desktop; can be
* NULL.
* \returns the current button state as a bitmask which can be tested using
* the SDL_BUTTON(X) macros.
* In Relative Mode, the platform-cursor's position usually contradicts the
* SDL-cursor's position as manually calculated from SDL_GetMouseState() and
* SDL_GetWindowPosition.
*
* \since This function is available since SDL 3.0.0.
* This function can be useful if you need to track the mouse outside of a
* specific window and SDL_CaptureMouse() doesn't fit your needs. For example,
* it could be useful if you need to track the mouse while dragging a window,
* where coordinates relative to a window might not be in sync at all times.
*
* \param x a pointer to receive the platform-cursor's x-position from the
* desktop's top left corner, can be NULL if unused.
* \param y a pointer to receive the platform-cursor's y-position from the
* desktop's top left corner, can be NULL if unused.
* \returns a 32-bit bitmask of the button state that can be bitwise-compared
* against the SDL_BUTTON_MASK(X) macro.
*
* \threadsafety This function should only be called on the main thread.
*
* \since This function is available since SDL 3.2.0.
*
* \sa SDL_CaptureMouse
* \sa SDL_GetMouseState
* \sa SDL_GetGlobalMouseState
*/
extern SDL_DECLSPEC SDL_MouseButtonFlags SDLCALL SDL_GetGlobalMouseState(float *x, float *y);
/**
* Retrieve the relative state of the mouse.
* Query SDL's cache for the synchronous mouse button state and accumulated
* mouse delta since last call.
*
* The current button state is returned as a button bitmask, which can be
* tested using the `SDL_BUTTON(X)` macros (where `X` is generally 1 for the
* left, 2 for middle, 3 for the right button), and `x` and `y` are set to the
* mouse deltas since the last call to SDL_GetRelativeMouseState() or since
* event initialization. You can pass NULL for either `x` or `y`.
* This function returns the cached synchronous state as SDL understands it
* from the last pump of the event queue.
*
* \param x a pointer filled with the last recorded x coordinate of the mouse.
* \param y a pointer filled with the last recorded y coordinate of the mouse.
* \returns a 32-bit button bitmask of the relative button state.
* To query the platform for immediate asynchronous state, use
* SDL_GetGlobalMouseState.
*
* \since This function is available since SDL 3.0.0.
* Passing non-NULL pointers to `x` or `y` will write the destination with
* respective x or y deltas accumulated since the last call to this function
* (or since event initialization).
*
* This function is useful for reducing overhead by processing relative mouse
* inputs in one go per-frame instead of individually per-event, at the
* expense of losing the order between events within the frame (e.g. quickly
* pressing and releasing a button within the same frame).
*
* \param x a pointer to receive the x mouse delta accumulated since last
* call, can be NULL if unused.
* \param y a pointer to receive the y mouse delta accumulated since last
* call, can be NULL if unused.
* \returns a 32-bit bitmask of the button state that can be bitwise-compared
* against the SDL_BUTTON_MASK(X) macro.
*
* \threadsafety This function should only be called on the main thread.
*
* \since This function is available since SDL 3.2.0.
*
* \sa SDL_GetMouseState
* \sa SDL_GetGlobalMouseState
*/
extern SDL_DECLSPEC SDL_MouseButtonFlags SDLCALL SDL_GetRelativeMouseState(float *x, float *y);
@ -275,7 +347,9 @@ extern SDL_DECLSPEC SDL_MouseButtonFlags SDLCALL SDL_GetRelativeMouseState(float
* \param x the x coordinate within the window.
* \param y the y coordinate within the window.
*
* \since This function is available since SDL 3.0.0.
* \threadsafety This function should only be called on the main thread.
*
* \since This function is available since SDL 3.2.0.
*
* \sa SDL_WarpMouseGlobal
*/
@ -295,14 +369,16 @@ extern SDL_DECLSPEC void SDLCALL SDL_WarpMouseInWindow(SDL_Window * window,
*
* \param x the x coordinate.
* \param y the y coordinate.
* \returns SDL_TRUE on success or SDL_FALSE on failure; call SDL_GetError()
* for more information.
* \returns true on success or false on failure; call SDL_GetError() for more
* information.
*
* \since This function is available since SDL 3.0.0.
* \threadsafety This function should only be called on the main thread.
*
* \since This function is available since SDL 3.2.0.
*
* \sa SDL_WarpMouseInWindow
*/
extern SDL_DECLSPEC SDL_bool SDLCALL SDL_WarpMouseGlobal(float x, float y);
extern SDL_DECLSPEC bool SDLCALL SDL_WarpMouseGlobal(float x, float y);
/**
* Set relative mouse mode for a window.
@ -312,31 +388,39 @@ extern SDL_DECLSPEC SDL_bool SDLCALL SDL_WarpMouseGlobal(float x, float y);
* report continuous relative mouse motion even if the mouse is at the edge of
* the window.
*
* If you'd like to keep the mouse position fixed while in relative mode you
* can use SDL_SetWindowMouseRect(). If you'd like the cursor to be at a
* specific location when relative mode ends, you should use
* SDL_WarpMouseInWindow() before disabling relative mode.
*
* This function will flush any pending mouse motion for this window.
*
* \param window the window to change.
* \param enabled SDL_TRUE to enable relative mode, SDL_FALSE to disable.
* \returns SDL_TRUE on success or SDL_FALSE on failure; call SDL_GetError()
* for more information.
* \param enabled true to enable relative mode, false to disable.
* \returns true on success or false on failure; call SDL_GetError() for more
* information.
*
* \since This function is available since SDL 3.0.0.
* \threadsafety This function should only be called on the main thread.
*
* \since This function is available since SDL 3.2.0.
*
* \sa SDL_GetWindowRelativeMouseMode
*/
extern SDL_DECLSPEC SDL_bool SDLCALL SDL_SetWindowRelativeMouseMode(SDL_Window *window, SDL_bool enabled);
extern SDL_DECLSPEC bool SDLCALL SDL_SetWindowRelativeMouseMode(SDL_Window *window, bool enabled);
/**
* Query whether relative mouse mode is enabled for a window.
*
* \param window the window to query.
* \returns SDL_TRUE if relative mode is enabled for a window or SDL_FALSE
* otherwise.
* \returns true if relative mode is enabled for a window or false otherwise.
*
* \since This function is available since SDL 3.0.0.
* \threadsafety This function should only be called on the main thread.
*
* \since This function is available since SDL 3.2.0.
*
* \sa SDL_SetWindowRelativeMouseMode
*/
extern SDL_DECLSPEC SDL_bool SDLCALL SDL_GetWindowRelativeMouseMode(SDL_Window *window);
extern SDL_DECLSPEC bool SDLCALL SDL_GetWindowRelativeMouseMode(SDL_Window *window);
/**
* Capture the mouse and to track input outside an SDL window.
@ -374,15 +458,17 @@ extern SDL_DECLSPEC SDL_bool SDLCALL SDL_GetWindowRelativeMouseMode(SDL_Window *
* app, you can disable auto capture by setting the
* `SDL_HINT_MOUSE_AUTO_CAPTURE` hint to zero.
*
* \param enabled SDL_TRUE to enable capturing, SDL_FALSE to disable.
* \returns SDL_TRUE on success or SDL_FALSE on failure; call SDL_GetError()
* for more information.
* \param enabled true to enable capturing, false to disable.
* \returns true on success or false on failure; call SDL_GetError() for more
* information.
*
* \since This function is available since SDL 3.0.0.
* \threadsafety This function should only be called on the main thread.
*
* \since This function is available since SDL 3.2.0.
*
* \sa SDL_GetGlobalMouseState
*/
extern SDL_DECLSPEC SDL_bool SDLCALL SDL_CaptureMouse(SDL_bool enabled);
extern SDL_DECLSPEC bool SDLCALL SDL_CaptureMouse(bool enabled);
/**
* Create a cursor using the specified bitmap data and mask (in MSB format).
@ -419,7 +505,9 @@ extern SDL_DECLSPEC SDL_bool SDLCALL SDL_CaptureMouse(SDL_bool enabled);
* \returns a new cursor with the specified parameters on success or NULL on
* failure; call SDL_GetError() for more information.
*
* \since This function is available since SDL 3.0.0.
* \threadsafety This function should only be called on the main thread.
*
* \since This function is available since SDL 3.2.0.
*
* \sa SDL_CreateColorCursor
* \sa SDL_CreateSystemCursor
@ -450,7 +538,9 @@ extern SDL_DECLSPEC SDL_Cursor * SDLCALL SDL_CreateCursor(const Uint8 * data,
* \returns the new cursor on success or NULL on failure; call SDL_GetError()
* for more information.
*
* \since This function is available since SDL 3.0.0.
* \threadsafety This function should only be called on the main thread.
*
* \since This function is available since SDL 3.2.0.
*
* \sa SDL_CreateCursor
* \sa SDL_CreateSystemCursor
@ -468,7 +558,9 @@ extern SDL_DECLSPEC SDL_Cursor * SDLCALL SDL_CreateColorCursor(SDL_Surface *surf
* \returns a cursor on success or NULL on failure; call SDL_GetError() for
* more information.
*
* \since This function is available since SDL 3.0.0.
* \threadsafety This function should only be called on the main thread.
*
* \since This function is available since SDL 3.2.0.
*
* \sa SDL_DestroyCursor
*/
@ -483,14 +575,16 @@ extern SDL_DECLSPEC SDL_Cursor * SDLCALL SDL_CreateSystemCursor(SDL_SystemCursor
* this is desired for any reason.
*
* \param cursor a cursor to make active.
* \returns SDL_TRUE on success or SDL_FALSE on failure; call SDL_GetError()
* for more information.
* \returns true on success or false on failure; call SDL_GetError() for more
* information.
*
* \since This function is available since SDL 3.0.0.
* \threadsafety This function should only be called on the main thread.
*
* \since This function is available since SDL 3.2.0.
*
* \sa SDL_GetCursor
*/
extern SDL_DECLSPEC SDL_bool SDLCALL SDL_SetCursor(SDL_Cursor *cursor);
extern SDL_DECLSPEC bool SDLCALL SDL_SetCursor(SDL_Cursor *cursor);
/**
* Get the active cursor.
@ -500,7 +594,9 @@ extern SDL_DECLSPEC SDL_bool SDLCALL SDL_SetCursor(SDL_Cursor *cursor);
*
* \returns the active cursor or NULL if there is no mouse.
*
* \since This function is available since SDL 3.0.0.
* \threadsafety This function should only be called on the main thread.
*
* \since This function is available since SDL 3.2.0.
*
* \sa SDL_SetCursor
*/
@ -515,7 +611,9 @@ extern SDL_DECLSPEC SDL_Cursor * SDLCALL SDL_GetCursor(void);
* \returns the default cursor on success or NULL on failuree; call
* SDL_GetError() for more information.
*
* \since This function is available since SDL 3.0.0.
* \threadsafety This function should only be called on the main thread.
*
* \since This function is available since SDL 3.2.0.
*/
extern SDL_DECLSPEC SDL_Cursor * SDLCALL SDL_GetDefaultCursor(void);
@ -527,7 +625,9 @@ extern SDL_DECLSPEC SDL_Cursor * SDLCALL SDL_GetDefaultCursor(void);
*
* \param cursor the cursor to free.
*
* \since This function is available since SDL 3.0.0.
* \threadsafety This function should only be called on the main thread.
*
* \since This function is available since SDL 3.2.0.
*
* \sa SDL_CreateColorCursor
* \sa SDL_CreateCursor
@ -538,41 +638,47 @@ extern SDL_DECLSPEC void SDLCALL SDL_DestroyCursor(SDL_Cursor *cursor);
/**
* Show the cursor.
*
* \returns SDL_TRUE on success or SDL_FALSE on failure; call SDL_GetError()
* for more information.
* \returns true on success or false on failure; call SDL_GetError() for more
* information.
*
* \since This function is available since SDL 3.0.0.
* \threadsafety This function should only be called on the main thread.
*
* \since This function is available since SDL 3.2.0.
*
* \sa SDL_CursorVisible
* \sa SDL_HideCursor
*/
extern SDL_DECLSPEC SDL_bool SDLCALL SDL_ShowCursor(void);
extern SDL_DECLSPEC bool SDLCALL SDL_ShowCursor(void);
/**
* Hide the cursor.
*
* \returns SDL_TRUE on success or SDL_FALSE on failure; call SDL_GetError()
* for more information.
* \returns true on success or false on failure; call SDL_GetError() for more
* information.
*
* \since This function is available since SDL 3.0.0.
* \threadsafety This function should only be called on the main thread.
*
* \since This function is available since SDL 3.2.0.
*
* \sa SDL_CursorVisible
* \sa SDL_ShowCursor
*/
extern SDL_DECLSPEC SDL_bool SDLCALL SDL_HideCursor(void);
extern SDL_DECLSPEC bool SDLCALL SDL_HideCursor(void);
/**
* Return whether the cursor is currently being shown.
*
* \returns `SDL_TRUE` if the cursor is being shown, or `SDL_FALSE` if the
* cursor is hidden.
* \returns `true` if the cursor is being shown, or `false` if the cursor is
* hidden.
*
* \since This function is available since SDL 3.0.0.
* \threadsafety This function should only be called on the main thread.
*
* \since This function is available since SDL 3.2.0.
*
* \sa SDL_HideCursor
* \sa SDL_ShowCursor
*/
extern SDL_DECLSPEC SDL_bool SDLCALL SDL_CursorVisible(void);
extern SDL_DECLSPEC bool SDLCALL SDL_CursorVisible(void);
/* Ends C function definitions when using C++ */
#ifdef __cplusplus

View File

@ -1,6 +1,6 @@
/*
Simple DirectMedia Layer
Copyright (C) 1997-2024 Sam Lantinga <slouken@libsdl.org>
Copyright (C) 1997-2025 Sam Lantinga <slouken@libsdl.org>
This software is provided 'as-is', without any express or implied
warranty. In no event will the authors be held liable for any damages
@ -25,84 +25,245 @@
/**
* # CategoryMutex
*
* Functions to provide thread synchronization primitives.
* SDL offers several thread synchronization primitives. This document can't
* cover the complicated topic of thread safety, but reading up on what each
* of these primitives are, why they are useful, and how to correctly use them
* is vital to writing correct and safe multithreaded programs.
*
* - Mutexes: SDL_CreateMutex()
* - Read/Write locks: SDL_CreateRWLock()
* - Semaphores: SDL_CreateSemaphore()
* - Condition variables: SDL_CreateCondition()
*
* SDL also offers a datatype, SDL_InitState, which can be used to make sure
* only one thread initializes/deinitializes some resource that several
* threads might try to use for the first time simultaneously.
*/
#include <SDL3/SDL_stdinc.h>
#include <SDL3/SDL_atomic.h>
#include <SDL3/SDL_error.h>
#include <SDL3/SDL_thread.h>
/******************************************************************************/
/* Enable thread safety attributes only with clang.
#ifdef SDL_WIKI_DOCUMENTATION_SECTION
/**
* Enable thread safety attributes, only with clang.
*
* The attributes can be safely erased when compiling with other compilers.
*
* To enable analysis, set these environment variables before running cmake:
* export CC=clang
* export CFLAGS="-DSDL_THREAD_SAFETY_ANALYSIS -Wthread-safety"
*
* ```bash
* export CC=clang
* export CFLAGS="-DSDL_THREAD_SAFETY_ANALYSIS -Wthread-safety"
* ```
*/
#if defined(SDL_THREAD_SAFETY_ANALYSIS) && \
defined(__clang__) && (!defined(SWIG))
#define SDL_THREAD_ANNOTATION_ATTRIBUTE__(x) __attribute__((x))
#elif defined(SDL_THREAD_SAFETY_ANALYSIS) && defined(__clang__) && (!defined(SWIG))
#define SDL_THREAD_ANNOTATION_ATTRIBUTE__(x) __attribute__((x))
#else
#define SDL_THREAD_ANNOTATION_ATTRIBUTE__(x) /* no-op */
#endif
/**
* Wrapper around Clang thread safety analysis annotations.
*
* Please see https://clang.llvm.org/docs/ThreadSafetyAnalysis.html#mutex-h
*
* \since This macro is available since SDL 3.2.0.
*/
#define SDL_CAPABILITY(x) \
SDL_THREAD_ANNOTATION_ATTRIBUTE__(capability(x))
/**
* Wrapper around Clang thread safety analysis annotations.
*
* Please see https://clang.llvm.org/docs/ThreadSafetyAnalysis.html#mutex-h
*
* \since This macro is available since SDL 3.2.0.
*/
#define SDL_SCOPED_CAPABILITY \
SDL_THREAD_ANNOTATION_ATTRIBUTE__(scoped_lockable)
/**
* Wrapper around Clang thread safety analysis annotations.
*
* Please see https://clang.llvm.org/docs/ThreadSafetyAnalysis.html#mutex-h
*
* \since This macro is available since SDL 3.2.0.
*/
#define SDL_GUARDED_BY(x) \
SDL_THREAD_ANNOTATION_ATTRIBUTE__(guarded_by(x))
/**
* Wrapper around Clang thread safety analysis annotations.
*
* Please see https://clang.llvm.org/docs/ThreadSafetyAnalysis.html#mutex-h
*
* \since This macro is available since SDL 3.2.0.
*/
#define SDL_PT_GUARDED_BY(x) \
SDL_THREAD_ANNOTATION_ATTRIBUTE__(pt_guarded_by(x))
/**
* Wrapper around Clang thread safety analysis annotations.
*
* Please see https://clang.llvm.org/docs/ThreadSafetyAnalysis.html#mutex-h
*
* \since This macro is available since SDL 3.2.0.
*/
#define SDL_ACQUIRED_BEFORE(x) \
SDL_THREAD_ANNOTATION_ATTRIBUTE__(acquired_before(x))
/**
* Wrapper around Clang thread safety analysis annotations.
*
* Please see https://clang.llvm.org/docs/ThreadSafetyAnalysis.html#mutex-h
*
* \since This macro is available since SDL 3.2.0.
*/
#define SDL_ACQUIRED_AFTER(x) \
SDL_THREAD_ANNOTATION_ATTRIBUTE__(acquired_after(x))
/**
* Wrapper around Clang thread safety analysis annotations.
*
* Please see https://clang.llvm.org/docs/ThreadSafetyAnalysis.html#mutex-h
*
* \since This macro is available since SDL 3.2.0.
*/
#define SDL_REQUIRES(x) \
SDL_THREAD_ANNOTATION_ATTRIBUTE__(requires_capability(x))
/**
* Wrapper around Clang thread safety analysis annotations.
*
* Please see https://clang.llvm.org/docs/ThreadSafetyAnalysis.html#mutex-h
*
* \since This macro is available since SDL 3.2.0.
*/
#define SDL_REQUIRES_SHARED(x) \
SDL_THREAD_ANNOTATION_ATTRIBUTE__(requires_shared_capability(x))
/**
* Wrapper around Clang thread safety analysis annotations.
*
* Please see https://clang.llvm.org/docs/ThreadSafetyAnalysis.html#mutex-h
*
* \since This macro is available since SDL 3.2.0.
*/
#define SDL_ACQUIRE(x) \
SDL_THREAD_ANNOTATION_ATTRIBUTE__(acquire_capability(x))
/**
* Wrapper around Clang thread safety analysis annotations.
*
* Please see https://clang.llvm.org/docs/ThreadSafetyAnalysis.html#mutex-h
*
* \since This macro is available since SDL 3.2.0.
*/
#define SDL_ACQUIRE_SHARED(x) \
SDL_THREAD_ANNOTATION_ATTRIBUTE__(acquire_shared_capability(x))
/**
* Wrapper around Clang thread safety analysis annotations.
*
* Please see https://clang.llvm.org/docs/ThreadSafetyAnalysis.html#mutex-h
*
* \since This macro is available since SDL 3.2.0.
*/
#define SDL_RELEASE(x) \
SDL_THREAD_ANNOTATION_ATTRIBUTE__(release_capability(x))
/**
* Wrapper around Clang thread safety analysis annotations.
*
* Please see https://clang.llvm.org/docs/ThreadSafetyAnalysis.html#mutex-h
*
* \since This macro is available since SDL 3.2.0.
*/
#define SDL_RELEASE_SHARED(x) \
SDL_THREAD_ANNOTATION_ATTRIBUTE__(release_shared_capability(x))
/**
* Wrapper around Clang thread safety analysis annotations.
*
* Please see https://clang.llvm.org/docs/ThreadSafetyAnalysis.html#mutex-h
*
* \since This macro is available since SDL 3.2.0.
*/
#define SDL_RELEASE_GENERIC(x) \
SDL_THREAD_ANNOTATION_ATTRIBUTE__(release_generic_capability(x))
/**
* Wrapper around Clang thread safety analysis annotations.
*
* Please see https://clang.llvm.org/docs/ThreadSafetyAnalysis.html#mutex-h
*
* \since This macro is available since SDL 3.2.0.
*/
#define SDL_TRY_ACQUIRE(x, y) \
SDL_THREAD_ANNOTATION_ATTRIBUTE__(try_acquire_capability(x, y))
/**
* Wrapper around Clang thread safety analysis annotations.
*
* Please see https://clang.llvm.org/docs/ThreadSafetyAnalysis.html#mutex-h
*
* \since This macro is available since SDL 3.2.0.
*/
#define SDL_TRY_ACQUIRE_SHARED(x, y) \
SDL_THREAD_ANNOTATION_ATTRIBUTE__(try_acquire_shared_capability(x, y))
/**
* Wrapper around Clang thread safety analysis annotations.
*
* Please see https://clang.llvm.org/docs/ThreadSafetyAnalysis.html#mutex-h
*
* \since This macro is available since SDL 3.2.0.
*/
#define SDL_EXCLUDES(x) \
SDL_THREAD_ANNOTATION_ATTRIBUTE__(locks_excluded(x))
/**
* Wrapper around Clang thread safety analysis annotations.
*
* Please see https://clang.llvm.org/docs/ThreadSafetyAnalysis.html#mutex-h
*
* \since This macro is available since SDL 3.2.0.
*/
#define SDL_ASSERT_CAPABILITY(x) \
SDL_THREAD_ANNOTATION_ATTRIBUTE__(assert_capability(x))
/**
* Wrapper around Clang thread safety analysis annotations.
*
* Please see https://clang.llvm.org/docs/ThreadSafetyAnalysis.html#mutex-h
*
* \since This macro is available since SDL 3.2.0.
*/
#define SDL_ASSERT_SHARED_CAPABILITY(x) \
SDL_THREAD_ANNOTATION_ATTRIBUTE__(assert_shared_capability(x))
/**
* Wrapper around Clang thread safety analysis annotations.
*
* Please see https://clang.llvm.org/docs/ThreadSafetyAnalysis.html#mutex-h
*
* \since This macro is available since SDL 3.2.0.
*/
#define SDL_RETURN_CAPABILITY(x) \
SDL_THREAD_ANNOTATION_ATTRIBUTE__(lock_returned(x))
/**
* Wrapper around Clang thread safety analysis annotations.
*
* Please see https://clang.llvm.org/docs/ThreadSafetyAnalysis.html#mutex-h
*
* \since This macro is available since SDL 3.2.0.
*/
#define SDL_NO_THREAD_SAFETY_ANALYSIS \
SDL_THREAD_ANNOTATION_ATTRIBUTE__(no_thread_safety_analysis)
@ -130,7 +291,7 @@ extern "C" {
*
* https://en.wikipedia.org/wiki/Mutex
*
* \since This struct is available since SDL 3.0.0.
* \since This struct is available since SDL 3.2.0.
*/
typedef struct SDL_Mutex SDL_Mutex;
@ -147,7 +308,7 @@ typedef struct SDL_Mutex SDL_Mutex;
* \returns the initialized and unlocked mutex or NULL on failure; call
* SDL_GetError() for more information.
*
* \since This function is available since SDL 3.0.0.
* \since This function is available since SDL 3.2.0.
*
* \sa SDL_DestroyMutex
* \sa SDL_LockMutex
@ -173,7 +334,7 @@ extern SDL_DECLSPEC SDL_Mutex * SDLCALL SDL_CreateMutex(void);
*
* \param mutex the mutex to lock.
*
* \since This function is available since SDL 3.0.0.
* \since This function is available since SDL 3.2.0.
*
* \sa SDL_TryLockMutex
* \sa SDL_UnlockMutex
@ -184,22 +345,22 @@ extern SDL_DECLSPEC void SDLCALL SDL_LockMutex(SDL_Mutex *mutex) SDL_ACQUIRE(mut
* Try to lock a mutex without blocking.
*
* This works just like SDL_LockMutex(), but if the mutex is not available,
* this function returns SDL_FALSE immediately.
* this function returns false immediately.
*
* This technique is useful if you need exclusive access to a resource but
* don't want to wait for it, and will return to it to try again later.
*
* This function returns SDL_TRUE if passed a NULL mutex.
* This function returns true if passed a NULL mutex.
*
* \param mutex the mutex to try to lock.
* \returns SDL_TRUE on success, SDL_FALSE if the mutex would block.
* \returns true on success, false if the mutex would block.
*
* \since This function is available since SDL 3.0.0.
* \since This function is available since SDL 3.2.0.
*
* \sa SDL_LockMutex
* \sa SDL_UnlockMutex
*/
extern SDL_DECLSPEC SDL_bool SDLCALL SDL_TryLockMutex(SDL_Mutex *mutex) SDL_TRY_ACQUIRE(0, mutex);
extern SDL_DECLSPEC bool SDLCALL SDL_TryLockMutex(SDL_Mutex *mutex) SDL_TRY_ACQUIRE(0, mutex);
/**
* Unlock the mutex.
@ -213,7 +374,7 @@ extern SDL_DECLSPEC SDL_bool SDLCALL SDL_TryLockMutex(SDL_Mutex *mutex) SDL_TRY_
*
* \param mutex the mutex to unlock.
*
* \since This function is available since SDL 3.0.0.
* \since This function is available since SDL 3.2.0.
*
* \sa SDL_LockMutex
* \sa SDL_TryLockMutex
@ -231,7 +392,7 @@ extern SDL_DECLSPEC void SDLCALL SDL_UnlockMutex(SDL_Mutex *mutex) SDL_RELEASE(m
*
* \param mutex the mutex to destroy.
*
* \since This function is available since SDL 3.0.0.
* \since This function is available since SDL 3.2.0.
*
* \sa SDL_CreateMutex
*/
@ -261,7 +422,7 @@ extern SDL_DECLSPEC void SDLCALL SDL_DestroyMutex(SDL_Mutex *mutex);
* about how threads are scheduled and when they can be recursively locked.
* These are documented in the other rwlock functions.
*
* \since This struct is available since SDL 3.0.0.
* \since This struct is available since SDL 3.2.0.
*/
typedef struct SDL_RWLock SDL_RWLock;
@ -296,7 +457,7 @@ typedef struct SDL_RWLock SDL_RWLock;
* \returns the initialized and unlocked read/write lock or NULL on failure;
* call SDL_GetError() for more information.
*
* \since This function is available since SDL 3.0.0.
* \since This function is available since SDL 3.2.0.
*
* \sa SDL_DestroyRWLock
* \sa SDL_LockRWLockForReading
@ -336,7 +497,7 @@ extern SDL_DECLSPEC SDL_RWLock * SDLCALL SDL_CreateRWLock(void);
*
* \param rwlock the read/write lock to lock.
*
* \since This function is available since SDL 3.0.0.
* \since This function is available since SDL 3.2.0.
*
* \sa SDL_LockRWLockForWriting
* \sa SDL_TryLockRWLockForReading
@ -367,7 +528,7 @@ extern SDL_DECLSPEC void SDLCALL SDL_LockRWLockForReading(SDL_RWLock *rwlock) SD
*
* \param rwlock the read/write lock to lock.
*
* \since This function is available since SDL 3.0.0.
* \since This function is available since SDL 3.2.0.
*
* \sa SDL_LockRWLockForReading
* \sa SDL_TryLockRWLockForWriting
@ -379,7 +540,7 @@ extern SDL_DECLSPEC void SDLCALL SDL_LockRWLockForWriting(SDL_RWLock *rwlock) SD
* Try to lock a read/write lock _for reading_ without blocking.
*
* This works just like SDL_LockRWLockForReading(), but if the rwlock is not
* available, then this function returns SDL_FALSE immediately.
* available, then this function returns false immediately.
*
* This technique is useful if you need access to a resource but don't want to
* wait for it, and will return to it to try again later.
@ -387,24 +548,24 @@ extern SDL_DECLSPEC void SDLCALL SDL_LockRWLockForWriting(SDL_RWLock *rwlock) SD
* Trying to lock for read-only access can succeed if other threads are
* holding read-only locks, as this won't prevent access.
*
* This function returns SDL_TRUE if passed a NULL rwlock.
* This function returns true if passed a NULL rwlock.
*
* \param rwlock the rwlock to try to lock.
* \returns SDL_TRUE on success, SDL_FALSE if the lock would block.
* \returns true on success, false if the lock would block.
*
* \since This function is available since SDL 3.0.0.
* \since This function is available since SDL 3.2.0.
*
* \sa SDL_LockRWLockForReading
* \sa SDL_TryLockRWLockForWriting
* \sa SDL_UnlockRWLock
*/
extern SDL_DECLSPEC SDL_bool SDLCALL SDL_TryLockRWLockForReading(SDL_RWLock *rwlock) SDL_TRY_ACQUIRE_SHARED(0, rwlock);
extern SDL_DECLSPEC bool SDLCALL SDL_TryLockRWLockForReading(SDL_RWLock *rwlock) SDL_TRY_ACQUIRE_SHARED(0, rwlock);
/**
* Try to lock a read/write lock _for writing_ without blocking.
*
* This works just like SDL_LockRWLockForWriting(), but if the rwlock is not
* available, then this function returns SDL_FALSE immediately.
* available, then this function returns false immediately.
*
* This technique is useful if you need exclusive access to a resource but
* don't want to wait for it, and will return to it to try again later.
@ -417,18 +578,18 @@ extern SDL_DECLSPEC SDL_bool SDLCALL SDL_TryLockRWLockForReading(SDL_RWLock *rwl
* read-only lock. Doing so results in undefined behavior. Unlock the
* read-only lock before requesting a write lock.
*
* This function returns SDL_TRUE if passed a NULL rwlock.
* This function returns true if passed a NULL rwlock.
*
* \param rwlock the rwlock to try to lock.
* \returns SDL_TRUE on success, SDL_FALSE if the lock would block.
* \returns true on success, false if the lock would block.
*
* \since This function is available since SDL 3.0.0.
* \since This function is available since SDL 3.2.0.
*
* \sa SDL_LockRWLockForWriting
* \sa SDL_TryLockRWLockForReading
* \sa SDL_UnlockRWLock
*/
extern SDL_DECLSPEC SDL_bool SDLCALL SDL_TryLockRWLockForWriting(SDL_RWLock *rwlock) SDL_TRY_ACQUIRE(0, rwlock);
extern SDL_DECLSPEC bool SDLCALL SDL_TryLockRWLockForWriting(SDL_RWLock *rwlock) SDL_TRY_ACQUIRE(0, rwlock);
/**
* Unlock the read/write lock.
@ -446,7 +607,7 @@ extern SDL_DECLSPEC SDL_bool SDLCALL SDL_TryLockRWLockForWriting(SDL_RWLock *rwl
*
* \param rwlock the rwlock to unlock.
*
* \since This function is available since SDL 3.0.0.
* \since This function is available since SDL 3.2.0.
*
* \sa SDL_LockRWLockForReading
* \sa SDL_LockRWLockForWriting
@ -466,7 +627,7 @@ extern SDL_DECLSPEC void SDLCALL SDL_UnlockRWLock(SDL_RWLock *rwlock) SDL_RELEAS
*
* \param rwlock the rwlock to destroy.
*
* \since This function is available since SDL 3.0.0.
* \since This function is available since SDL 3.2.0.
*
* \sa SDL_CreateRWLock
*/
@ -492,7 +653,7 @@ extern SDL_DECLSPEC void SDLCALL SDL_DestroyRWLock(SDL_RWLock *rwlock);
*
* https://en.wikipedia.org/wiki/Semaphore_(programming)
*
* \since This struct is available since SDL 3.0.0.
* \since This struct is available since SDL 3.2.0.
*/
typedef struct SDL_Semaphore SDL_Semaphore;
@ -509,7 +670,7 @@ typedef struct SDL_Semaphore SDL_Semaphore;
* \returns a new semaphore or NULL on failure; call SDL_GetError() for more
* information.
*
* \since This function is available since SDL 3.0.0.
* \since This function is available since SDL 3.2.0.
*
* \sa SDL_DestroySemaphore
* \sa SDL_SignalSemaphore
@ -528,7 +689,7 @@ extern SDL_DECLSPEC SDL_Semaphore * SDLCALL SDL_CreateSemaphore(Uint32 initial_v
*
* \param sem the semaphore to destroy.
*
* \since This function is available since SDL 3.0.0.
* \since This function is available since SDL 3.2.0.
*
* \sa SDL_CreateSemaphore
*/
@ -546,7 +707,7 @@ extern SDL_DECLSPEC void SDLCALL SDL_DestroySemaphore(SDL_Semaphore *sem);
*
* \param sem the semaphore wait on.
*
* \since This function is available since SDL 3.0.0.
* \since This function is available since SDL 3.2.0.
*
* \sa SDL_SignalSemaphore
* \sa SDL_TryWaitSemaphore
@ -560,18 +721,18 @@ extern SDL_DECLSPEC void SDLCALL SDL_WaitSemaphore(SDL_Semaphore *sem);
* This function checks to see if the semaphore pointed to by `sem` has a
* positive value and atomically decrements the semaphore value if it does. If
* the semaphore doesn't have a positive value, the function immediately
* returns SDL_FALSE.
* returns false.
*
* \param sem the semaphore to wait on.
* \returns SDL_TRUE if the wait succeeds, SDL_FALSE if the wait would block.
* \returns true if the wait succeeds, false if the wait would block.
*
* \since This function is available since SDL 3.0.0.
* \since This function is available since SDL 3.2.0.
*
* \sa SDL_SignalSemaphore
* \sa SDL_WaitSemaphore
* \sa SDL_WaitSemaphoreTimeout
*/
extern SDL_DECLSPEC SDL_bool SDLCALL SDL_TryWaitSemaphore(SDL_Semaphore *sem);
extern SDL_DECLSPEC bool SDLCALL SDL_TryWaitSemaphore(SDL_Semaphore *sem);
/**
* Wait until a semaphore has a positive value and then decrements it.
@ -583,22 +744,22 @@ extern SDL_DECLSPEC SDL_bool SDLCALL SDL_TryWaitSemaphore(SDL_Semaphore *sem);
* \param sem the semaphore to wait on.
* \param timeoutMS the length of the timeout, in milliseconds, or -1 to wait
* indefinitely.
* \returns SDL_TRUE if the wait succeeds or SDL_FALSE if the wait times out.
* \returns true if the wait succeeds or false if the wait times out.
*
* \since This function is available since SDL 3.0.0.
* \since This function is available since SDL 3.2.0.
*
* \sa SDL_SignalSemaphore
* \sa SDL_TryWaitSemaphore
* \sa SDL_WaitSemaphore
*/
extern SDL_DECLSPEC SDL_bool SDLCALL SDL_WaitSemaphoreTimeout(SDL_Semaphore *sem, Sint32 timeoutMS);
extern SDL_DECLSPEC bool SDLCALL SDL_WaitSemaphoreTimeout(SDL_Semaphore *sem, Sint32 timeoutMS);
/**
* Atomically increment a semaphore's value and wake waiting threads.
*
* \param sem the semaphore to increment.
*
* \since This function is available since SDL 3.0.0.
* \since This function is available since SDL 3.2.0.
*
* \sa SDL_TryWaitSemaphore
* \sa SDL_WaitSemaphore
@ -612,7 +773,7 @@ extern SDL_DECLSPEC void SDLCALL SDL_SignalSemaphore(SDL_Semaphore *sem);
* \param sem the semaphore to query.
* \returns the current value of the semaphore.
*
* \since This function is available since SDL 3.0.0.
* \since This function is available since SDL 3.2.0.
*/
extern SDL_DECLSPEC Uint32 SDLCALL SDL_GetSemaphoreValue(SDL_Semaphore *sem);
@ -635,7 +796,7 @@ extern SDL_DECLSPEC Uint32 SDLCALL SDL_GetSemaphoreValue(SDL_Semaphore *sem);
*
* https://en.wikipedia.org/wiki/Condition_variable
*
* \since This struct is available since SDL 3.0.0.
* \since This struct is available since SDL 3.2.0.
*/
typedef struct SDL_Condition SDL_Condition;
@ -645,7 +806,7 @@ typedef struct SDL_Condition SDL_Condition;
* \returns a new condition variable or NULL on failure; call SDL_GetError()
* for more information.
*
* \since This function is available since SDL 3.0.0.
* \since This function is available since SDL 3.2.0.
*
* \sa SDL_BroadcastCondition
* \sa SDL_SignalCondition
@ -660,7 +821,7 @@ extern SDL_DECLSPEC SDL_Condition * SDLCALL SDL_CreateCondition(void);
*
* \param cond the condition variable to destroy.
*
* \since This function is available since SDL 3.0.0.
* \since This function is available since SDL 3.2.0.
*
* \sa SDL_CreateCondition
*/
@ -673,7 +834,7 @@ extern SDL_DECLSPEC void SDLCALL SDL_DestroyCondition(SDL_Condition *cond);
*
* \threadsafety It is safe to call this function from any thread.
*
* \since This function is available since SDL 3.0.0.
* \since This function is available since SDL 3.2.0.
*
* \sa SDL_BroadcastCondition
* \sa SDL_WaitCondition
@ -688,7 +849,7 @@ extern SDL_DECLSPEC void SDLCALL SDL_SignalCondition(SDL_Condition *cond);
*
* \threadsafety It is safe to call this function from any thread.
*
* \since This function is available since SDL 3.0.0.
* \since This function is available since SDL 3.2.0.
*
* \sa SDL_SignalCondition
* \sa SDL_WaitCondition
@ -716,7 +877,7 @@ extern SDL_DECLSPEC void SDLCALL SDL_BroadcastCondition(SDL_Condition *cond);
*
* \threadsafety It is safe to call this function from any thread.
*
* \since This function is available since SDL 3.0.0.
* \since This function is available since SDL 3.2.0.
*
* \sa SDL_BroadcastCondition
* \sa SDL_SignalCondition
@ -741,22 +902,167 @@ extern SDL_DECLSPEC void SDLCALL SDL_WaitCondition(SDL_Condition *cond, SDL_Mute
* \param mutex the mutex used to coordinate thread access.
* \param timeoutMS the maximum time to wait, in milliseconds, or -1 to wait
* indefinitely.
* \returns SDL_TRUE if the condition variable is signaled, SDL_FALSE if the
* condition is not signaled in the allotted time.
* \returns true if the condition variable is signaled, false if the condition
* is not signaled in the allotted time.
*
* \threadsafety It is safe to call this function from any thread.
*
* \since This function is available since SDL 3.0.0.
* \since This function is available since SDL 3.2.0.
*
* \sa SDL_BroadcastCondition
* \sa SDL_SignalCondition
* \sa SDL_WaitCondition
*/
extern SDL_DECLSPEC SDL_bool SDLCALL SDL_WaitConditionTimeout(SDL_Condition *cond,
extern SDL_DECLSPEC bool SDLCALL SDL_WaitConditionTimeout(SDL_Condition *cond,
SDL_Mutex *mutex, Sint32 timeoutMS);
/* @} *//* Condition variable functions */
/**
* \name Thread-safe initialization state functions
*/
/* @{ */
/**
* The current status of an SDL_InitState structure.
*
* \since This enum is available since SDL 3.2.0.
*/
typedef enum SDL_InitStatus
{
SDL_INIT_STATUS_UNINITIALIZED,
SDL_INIT_STATUS_INITIALIZING,
SDL_INIT_STATUS_INITIALIZED,
SDL_INIT_STATUS_UNINITIALIZING
} SDL_InitStatus;
/**
* A structure used for thread-safe initialization and shutdown.
*
* Here is an example of using this:
*
* ```c
* static SDL_AtomicInitState init;
*
* bool InitSystem(void)
* {
* if (!SDL_ShouldInit(&init)) {
* // The system is initialized
* return true;
* }
*
* // At this point, you should not leave this function without calling SDL_SetInitialized()
*
* bool initialized = DoInitTasks();
* SDL_SetInitialized(&init, initialized);
* return initialized;
* }
*
* bool UseSubsystem(void)
* {
* if (SDL_ShouldInit(&init)) {
* // Error, the subsystem isn't initialized
* SDL_SetInitialized(&init, false);
* return false;
* }
*
* // Do work using the initialized subsystem
*
* return true;
* }
*
* void QuitSystem(void)
* {
* if (!SDL_ShouldQuit(&init)) {
* // The system is not initialized
* return;
* }
*
* // At this point, you should not leave this function without calling SDL_SetInitialized()
*
* DoQuitTasks();
* SDL_SetInitialized(&init, false);
* }
* ```
*
* Note that this doesn't protect any resources created during initialization,
* or guarantee that nobody is using those resources during cleanup. You
* should use other mechanisms to protect those, if that's a concern for your
* code.
*
* \since This struct is available since SDL 3.2.0.
*/
typedef struct SDL_InitState
{
SDL_AtomicInt status;
SDL_ThreadID thread;
void *reserved;
} SDL_InitState;
/**
* Return whether initialization should be done.
*
* This function checks the passed in state and if initialization should be
* done, sets the status to `SDL_INIT_STATUS_INITIALIZING` and returns true.
* If another thread is already modifying this state, it will wait until
* that's done before returning.
*
* If this function returns true, the calling code must call
* SDL_SetInitialized() to complete the initialization.
*
* \param state the initialization state to check.
* \returns true if initialization needs to be done, 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_SetInitialized
* \sa SDL_ShouldQuit
*/
extern SDL_DECLSPEC bool SDLCALL SDL_ShouldInit(SDL_InitState *state);
/**
* Return whether cleanup should be done.
*
* This function checks the passed in state and if cleanup should be done,
* sets the status to `SDL_INIT_STATUS_UNINITIALIZING` and returns true.
*
* If this function returns true, the calling code must call
* SDL_SetInitialized() to complete the cleanup.
*
* \param state the initialization state to check.
* \returns true if cleanup needs to be done, 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_SetInitialized
* \sa SDL_ShouldInit
*/
extern SDL_DECLSPEC bool SDLCALL SDL_ShouldQuit(SDL_InitState *state);
/**
* Finish an initialization state transition.
*
* This function sets the status of the passed in state to
* `SDL_INIT_STATUS_INITIALIZED` or `SDL_INIT_STATUS_UNINITIALIZED` and allows
* any threads waiting for the status to proceed.
*
* \param state the initialization state to check.
* \param initialized the new initialization state.
*
* \threadsafety It is safe to call this function from any thread.
*
* \since This function is available since SDL 3.2.0.
*
* \sa SDL_ShouldInit
* \sa SDL_ShouldQuit
*/
extern SDL_DECLSPEC void SDLCALL SDL_SetInitialized(SDL_InitState *state, bool initialized);
/* @} *//* Thread-safe initialization state functions */
/* Ends C function definitions when using C++ */
#ifdef __cplusplus

View File

@ -1,6 +1,6 @@
/*
Simple DirectMedia Layer
Copyright (C) 1997-2024 Sam Lantinga <slouken@libsdl.org>
Copyright (C) 1997-2025 Sam Lantinga <slouken@libsdl.org>
This software is provided 'as-is', without any express or implied
warranty. In no event will the authors be held liable for any damages
@ -38,11 +38,14 @@
#ifdef SDL_ENABLE_OLD_NAMES
/* ##SDL_atomic.h */
#define SDL_AtomicCAS SDL_AtomicCompareAndSwap
#define SDL_AtomicCASPtr SDL_AtomicCompareAndSwapPointer
#define SDL_AtomicGetPtr SDL_AtomicGetPointer
#define SDL_AtomicAdd SDL_AddAtomicInt
#define SDL_AtomicCAS SDL_CompareAndSwapAtomicInt
#define SDL_AtomicCASPtr SDL_CompareAndSwapAtomicPointer
#define SDL_AtomicGet SDL_GetAtomicInt
#define SDL_AtomicGetPtr SDL_GetAtomicPointer
#define SDL_AtomicLock SDL_LockSpinlock
#define SDL_AtomicSetPtr SDL_AtomicSetPointer
#define SDL_AtomicSet SDL_SetAtomicInt
#define SDL_AtomicSetPtr SDL_SetAtomicPointer
#define SDL_AtomicTryLock SDL_TryLockSpinlock
#define SDL_AtomicUnlock SDL_UnlockSpinlock
#define SDL_atomic_t SDL_AtomicInt
@ -74,6 +77,7 @@
#define SDL_NewAudioStream SDL_CreateAudioStream
/* ##SDL_cpuinfo.h */
#define SDL_GetCPUCount SDL_GetNumLogicalCPUCores
#define SDL_SIMDGetAlignment SDL_GetSIMDAlignment
/* ##SDL_endian.h */
@ -166,14 +170,13 @@
#define SDL_WINDOWEVENT_RESTORED SDL_EVENT_WINDOW_RESTORED
#define SDL_WINDOWEVENT_SHOWN SDL_EVENT_WINDOW_SHOWN
#define SDL_WINDOWEVENT_SIZE_CHANGED SDL_EVENT_WINDOW_PIXEL_SIZE_CHANGED
#define SDL_WINDOWEVENT_TAKE_FOCUS SDL_EVENT_WINDOW_TAKE_FOCUS
#define SDL_eventaction SDL_EventAction
/* ##SDL_gamecontroller.h */
#define SDL_CONTROLLER_AXIS_INVALID SDL_GAMEPAD_AXIS_INVALID
#define SDL_CONTROLLER_AXIS_LEFTX SDL_GAMEPAD_AXIS_LEFTX
#define SDL_CONTROLLER_AXIS_LEFTY SDL_GAMEPAD_AXIS_LEFTY
#define SDL_CONTROLLER_AXIS_MAX SDL_GAMEPAD_AXIS_MAX
#define SDL_CONTROLLER_AXIS_MAX SDL_GAMEPAD_AXIS_COUNT
#define SDL_CONTROLLER_AXIS_RIGHTX SDL_GAMEPAD_AXIS_RIGHTX
#define SDL_CONTROLLER_AXIS_RIGHTY SDL_GAMEPAD_AXIS_RIGHTY
#define SDL_CONTROLLER_AXIS_TRIGGERLEFT SDL_GAMEPAD_AXIS_LEFT_TRIGGER
@ -193,7 +196,7 @@
#define SDL_CONTROLLER_BUTTON_INVALID SDL_GAMEPAD_BUTTON_INVALID
#define SDL_CONTROLLER_BUTTON_LEFTSHOULDER SDL_GAMEPAD_BUTTON_LEFT_SHOULDER
#define SDL_CONTROLLER_BUTTON_LEFTSTICK SDL_GAMEPAD_BUTTON_LEFT_STICK
#define SDL_CONTROLLER_BUTTON_MAX SDL_GAMEPAD_BUTTON_MAX
#define SDL_CONTROLLER_BUTTON_MAX SDL_GAMEPAD_BUTTON_COUNT
#define SDL_CONTROLLER_BUTTON_MISC1 SDL_GAMEPAD_BUTTON_MISC1
#define SDL_CONTROLLER_BUTTON_PADDLE1 SDL_GAMEPAD_BUTTON_RIGHT_PADDLE1
#define SDL_CONTROLLER_BUTTON_PADDLE2 SDL_GAMEPAD_BUTTON_LEFT_PADDLE1
@ -304,6 +307,8 @@
#define SDL_HINT_DIRECTINPUT_ENABLED SDL_HINT_JOYSTICK_DIRECTINPUT
#define SDL_HINT_GDK_TEXTINPUT_DEFAULT SDL_HINT_GDK_TEXTINPUT_DEFAULT_TEXT
#define SDL_HINT_JOYSTICK_GAMECUBE_RUMBLE_BRAKE SDL_HINT_JOYSTICK_HIDAPI_GAMECUBE_RUMBLE_BRAKE
#define SDL_HINT_JOYSTICK_HIDAPI_PS4_RUMBLE SDL_HINT_JOYSTICK_ENHANCED_REPORTS
#define SDL_HINT_JOYSTICK_HIDAPI_PS5_RUMBLE SDL_HINT_JOYSTICK_ENHANCED_REPORTS
#define SDL_HINT_LINUX_DIGITAL_HATS SDL_HINT_JOYSTICK_LINUX_DIGITAL_HATS
#define SDL_HINT_LINUX_HAT_DEADZONES SDL_HINT_JOYSTICK_LINUX_HAT_DEADZONES
#define SDL_HINT_LINUX_JOYSTICK_CLASSIC SDL_HINT_JOYSTICK_LINUX_CLASSIC
@ -419,9 +424,15 @@
#define SDL_LogSetAllPriority SDL_SetLogPriorities
#define SDL_LogSetOutputFunction SDL_SetLogOutputFunction
#define SDL_LogSetPriority SDL_SetLogPriority
#define SDL_NUM_LOG_PRIORITIES SDL_LOG_PRIORITY_COUNT
/* ##SDL_messagebox.h */
#define SDL_MESSAGEBOX_COLOR_MAX SDL_MESSAGEBOX_COLOR_COUNT
/* ##SDL_mouse.h */
#define SDL_BUTTON SDL_BUTTON_MASK
#define SDL_FreeCursor SDL_DestroyCursor
#define SDL_NUM_SYSTEM_CURSORS SDL_SYSTEM_CURSOR_COUNT
#define SDL_SYSTEM_CURSOR_ARROW SDL_SYSTEM_CURSOR_DEFAULT
#define SDL_SYSTEM_CURSOR_HAND SDL_SYSTEM_CURSOR_POINTER
#define SDL_SYSTEM_CURSOR_IBEAM SDL_SYSTEM_CURSOR_TEXT
@ -558,6 +569,7 @@
#define SDL_WriteLE64 SDL_WriteU64LE
/* ##SDL_scancode.h */
#define SDL_NUM_SCANCODES SDL_SCANCODE_COUNT
#define SDL_SCANCODE_AUDIOFASTFORWARD SDL_SCANCODE_MEDIA_FAST_FORWARD
#define SDL_SCANCODE_AUDIOMUTE SDL_SCANCODE_MUTE
#define SDL_SCANCODE_AUDIONEXT SDL_SCANCODE_MEDIA_NEXT_TRACK
@ -580,7 +592,12 @@
#define SDL_SensorUpdate SDL_UpdateSensors
/* ##SDL_stdinc.h */
#define SDL_FALSE false
#define SDL_TABLESIZE SDL_arraysize
#define SDL_TRUE true
#define SDL_bool bool
#define SDL_size_add_overflow SDL_size_add_check_overflow
#define SDL_size_mul_overflow SDL_size_mul_check_overflow
#define SDL_strtokr SDL_strtok_r
/* ##SDL_surface.h */
@ -623,14 +640,13 @@
#define SDL_LinuxSetThreadPriorityAndPolicy SDL_SetLinuxThreadPriorityAndPolicy
#define SDL_OnApplicationDidBecomeActive SDL_OnApplicationDidEnterForeground
#define SDL_OnApplicationWillResignActive SDL_OnApplicationWillEnterBackground
#define SDL_WinRTGetDeviceFamily SDL_GetWinRTDeviceFamily
#define SDL_GetWinRTFSPathUTF8 SDL_GetWinRTFSPath
#define SDL_iOSSetAnimationCallback SDL_SetiOSAnimationCallback
#define SDL_iOSSetEventPump SDL_SetiOSEventPump
#define SDL_iPhoneSetAnimationCallback SDL_SetiOSAnimationCallback
#define SDL_iPhoneSetEventPump SDL_SetiOSEventPump
/* ##SDL_thread.h */
#define SDL_SetThreadPriority SDL_SetCurrentThreadPriority
#define SDL_TLSCleanup SDL_CleanupTLS
#define SDL_TLSGet SDL_GetTLS
#define SDL_TLSSet SDL_SetTLS
@ -645,6 +661,10 @@
/* ##SDL_video.h */
#define SDL_GL_DeleteContext SDL_GL_DestroyContext
#define SDL_GLattr SDL_GLAttr
#define SDL_GLcontextFlag SDL_GLContextFlag
#define SDL_GLcontextReleaseFlag SDL_GLContextReleaseFlag
#define SDL_GLprofile SDL_GLProfile
#define SDL_GetClosestDisplayMode SDL_GetClosestFullscreenDisplayMode
#define SDL_GetDisplayOrientation SDL_GetCurrentDisplayOrientation
#define SDL_GetPointDisplayIndex SDL_GetDisplayForPoint
@ -661,11 +681,14 @@
#elif !defined(SDL_DISABLE_OLD_NAMES)
/* ##SDL_atomic.h */
#define SDL_AtomicCAS SDL_AtomicCAS_renamed_SDL_AtomicCompareAndSwap
#define SDL_AtomicCASPtr SDL_AtomicCASPtr_renamed_SDL_AtomicCompareAndSwapPointer
#define SDL_AtomicGetPtr SDL_AtomicGetPtr_renamed_SDL_AtomicGetPointer
#define SDL_AtomicAdd SDL_AtomicAdd_renamed_SDL_AddAtomicInt
#define SDL_AtomicCAS SDL_AtomicCAS_renamed_SDL_CompareAndSwapAtomicInt
#define SDL_AtomicCASPtr SDL_AtomicCASPtr_renamed_SDL_CompareAndSwapAtomicPointer
#define SDL_AtomicGet SDL_AtomicGet_renamed_SDL_GetAtomicInt
#define SDL_AtomicGetPtr SDL_AtomicGetPtr_renamed_SDL_GetAtomicPointer
#define SDL_AtomicLock SDL_AtomicLock_renamed_SDL_LockSpinlock
#define SDL_AtomicSetPtr SDL_AtomicSetPtr_renamed_SDL_AtomicSetPointer
#define SDL_AtomicSet SDL_AtomicSet_renamed_SDL_SetAtomicInt
#define SDL_AtomicSetPtr SDL_AtomicSetPtr_renamed_SDL_SetAtomicPointer
#define SDL_AtomicTryLock SDL_AtomicTryLock_renamed_SDL_TryLockSpinlock
#define SDL_AtomicUnlock SDL_AtomicUnlock_renamed_SDL_UnlockSpinlock
#define SDL_atomic_t SDL_atomic_t_renamed_SDL_AtomicInt
@ -697,6 +720,7 @@
#define SDL_NewAudioStream SDL_NewAudioStream_renamed_SDL_CreateAudioStream
/* ##SDL_cpuinfo.h */
#define SDL_GetCPUCount SDL_GetCPUCount_renamed_SDL_GetNumLogicalCPUCores
#define SDL_SIMDGetAlignment SDL_SIMDGetAlignment_renamed_SDL_GetSIMDAlignment
/* ##SDL_endian.h */
@ -789,14 +813,13 @@
#define SDL_WINDOWEVENT_RESTORED SDL_WINDOWEVENT_RESTORED_renamed_SDL_EVENT_WINDOW_RESTORED
#define SDL_WINDOWEVENT_SHOWN SDL_WINDOWEVENT_SHOWN_renamed_SDL_EVENT_WINDOW_SHOWN
#define SDL_WINDOWEVENT_SIZE_CHANGED SDL_WINDOWEVENT_SIZE_CHANGED_renamed_SDL_EVENT_WINDOW_PIXEL_SIZE_CHANGED
#define SDL_WINDOWEVENT_TAKE_FOCUS SDL_WINDOWEVENT_TAKE_FOCUS_renamed_SDL_EVENT_WINDOW_TAKE_FOCUS
#define SDL_eventaction SDL_eventaction_renamed_SDL_EventAction
/* ##SDL_gamecontroller.h */
#define SDL_CONTROLLER_AXIS_INVALID SDL_CONTROLLER_AXIS_INVALID_renamed_SDL_GAMEPAD_AXIS_INVALID
#define SDL_CONTROLLER_AXIS_LEFTX SDL_CONTROLLER_AXIS_LEFTX_renamed_SDL_GAMEPAD_AXIS_LEFTX
#define SDL_CONTROLLER_AXIS_LEFTY SDL_CONTROLLER_AXIS_LEFTY_renamed_SDL_GAMEPAD_AXIS_LEFTY
#define SDL_CONTROLLER_AXIS_MAX SDL_CONTROLLER_AXIS_MAX_renamed_SDL_GAMEPAD_AXIS_MAX
#define SDL_CONTROLLER_AXIS_MAX SDL_CONTROLLER_AXIS_MAX_renamed_SDL_GAMEPAD_AXIS_COUNT
#define SDL_CONTROLLER_AXIS_RIGHTX SDL_CONTROLLER_AXIS_RIGHTX_renamed_SDL_GAMEPAD_AXIS_RIGHTX
#define SDL_CONTROLLER_AXIS_RIGHTY SDL_CONTROLLER_AXIS_RIGHTY_renamed_SDL_GAMEPAD_AXIS_RIGHTY
#define SDL_CONTROLLER_AXIS_TRIGGERLEFT SDL_CONTROLLER_AXIS_TRIGGERLEFT_renamed_SDL_GAMEPAD_AXIS_LEFT_TRIGGER
@ -816,7 +839,7 @@
#define SDL_CONTROLLER_BUTTON_INVALID SDL_CONTROLLER_BUTTON_INVALID_renamed_SDL_GAMEPAD_BUTTON_INVALID
#define SDL_CONTROLLER_BUTTON_LEFTSHOULDER SDL_CONTROLLER_BUTTON_LEFTSHOULDER_renamed_SDL_GAMEPAD_BUTTON_LEFT_SHOULDER
#define SDL_CONTROLLER_BUTTON_LEFTSTICK SDL_CONTROLLER_BUTTON_LEFTSTICK_renamed_SDL_GAMEPAD_BUTTON_LEFT_STICK
#define SDL_CONTROLLER_BUTTON_MAX SDL_CONTROLLER_BUTTON_MAX_renamed_SDL_GAMEPAD_BUTTON_MAX
#define SDL_CONTROLLER_BUTTON_MAX SDL_CONTROLLER_BUTTON_MAX_renamed_SDL_GAMEPAD_BUTTON_COUNT
#define SDL_CONTROLLER_BUTTON_MISC1 SDL_CONTROLLER_BUTTON_MISC1_renamed_SDL_GAMEPAD_BUTTON_MISC1
#define SDL_CONTROLLER_BUTTON_PADDLE1 SDL_CONTROLLER_BUTTON_PADDLE1_renamed_SDL_GAMEPAD_BUTTON_RIGHT_PADDLE1
#define SDL_CONTROLLER_BUTTON_PADDLE2 SDL_CONTROLLER_BUTTON_PADDLE2_renamed_SDL_GAMEPAD_BUTTON_LEFT_PADDLE1
@ -928,6 +951,8 @@
#define SDL_HINT_DIRECTINPUT_ENABLED SDL_HINT_DIRECTINPUT_ENABLED_renamed_SDL_HINT_JOYSTICK_DIRECTINPUT
#define SDL_HINT_GDK_TEXTINPUT_DEFAULT SDL_HINT_GDK_TEXTINPUT_DEFAULT_renamed_SDL_HINT_GDK_TEXTINPUT_DEFAULT_TEXT
#define SDL_HINT_JOYSTICK_GAMECUBE_RUMBLE_BRAKE SDL_HINT_JOYSTICK_GAMECUBE_RUMBLE_BRAKE_renamed_SDL_HINT_JOYSTICK_HIDAPI_GAMECUBE_RUMBLE_BRAKE
#define SDL_HINT_JOYSTICK_HIDAPI_PS4_RUMBLE SDL_HINT_JOYSTICK_HIDAPI_PS4_RUMBLE_renamed_SDL_HINT_JOYSTICK_ENHANCED_REPORTS
#define SDL_HINT_JOYSTICK_HIDAPI_PS5_RUMBLE SDL_HINT_JOYSTICK_HIDAPI_PS5_RUMBLE_renamed_SDL_HINT_JOYSTICK_ENHANCED_REPORTS
#define SDL_HINT_LINUX_DIGITAL_HATS SDL_HINT_LINUX_DIGITAL_HATS_renamed_SDL_HINT_JOYSTICK_LINUX_DIGITAL_HATS
#define SDL_HINT_LINUX_HAT_DEADZONES SDL_HINT_LINUX_HAT_DEADZONES_renamed_SDL_HINT_JOYSTICK_LINUX_HAT_DEADZONES
#define SDL_HINT_LINUX_JOYSTICK_CLASSIC SDL_HINT_LINUX_JOYSTICK_CLASSIC_renamed_SDL_HINT_JOYSTICK_LINUX_CLASSIC
@ -1043,9 +1068,15 @@
#define SDL_LogSetAllPriority SDL_LogSetAllPriority_renamed_SDL_SetLogPriorities
#define SDL_LogSetOutputFunction SDL_LogSetOutputFunction_renamed_SDL_SetLogOutputFunction
#define SDL_LogSetPriority SDL_LogSetPriority_renamed_SDL_SetLogPriority
#define SDL_NUM_LOG_PRIORITIES SDL_NUM_LOG_PRIORITIES_renamed_SDL_LOG_PRIORITY_COUNT
/* ##SDL_messagebox.h */
#define SDL_MESSAGEBOX_COLOR_MAX SDL_MESSAGEBOX_COLOR_MAX_renamed_SDL_MESSAGEBOX_COLOR_COUNT
/* ##SDL_mouse.h */
#define SDL_BUTTON SDL_BUTTON_renamed_SDL_BUTTON_MASK
#define SDL_FreeCursor SDL_FreeCursor_renamed_SDL_DestroyCursor
#define SDL_NUM_SYSTEM_CURSORS SDL_NUM_SYSTEM_CURSORS_renamed_SDL_SYSTEM_CURSOR_COUNT
#define SDL_SYSTEM_CURSOR_ARROW SDL_SYSTEM_CURSOR_ARROW_renamed_SDL_SYSTEM_CURSOR_DEFAULT
#define SDL_SYSTEM_CURSOR_HAND SDL_SYSTEM_CURSOR_HAND_renamed_SDL_SYSTEM_CURSOR_POINTER
#define SDL_SYSTEM_CURSOR_IBEAM SDL_SYSTEM_CURSOR_IBEAM_renamed_SDL_SYSTEM_CURSOR_TEXT
@ -1182,6 +1213,7 @@
#define SDL_WriteLE64 SDL_WriteLE64_renamed_SDL_WriteU64LE
/* ##SDL_scancode.h */
#define SDL_NUM_SCANCODES SDL_NUM_SCANCODES_renamed_SDL_SCANCODE_COUNT
#define SDL_SCANCODE_AUDIOFASTFORWARD SDL_SCANCODE_AUDIOFASTFORWARD_renamed_SDL_SCANCODE_MEDIA_FAST_FORWARD
#define SDL_SCANCODE_AUDIOMUTE SDL_SCANCODE_AUDIOMUTE_renamed_SDL_SCANCODE_MUTE
#define SDL_SCANCODE_AUDIONEXT SDL_SCANCODE_AUDIONEXT_renamed_SDL_SCANCODE_MEDIA_NEXT_TRACK
@ -1204,7 +1236,12 @@
#define SDL_SensorUpdate SDL_SensorUpdate_renamed_SDL_UpdateSensors
/* ##SDL_stdinc.h */
#define SDL_FALSE SDL_FALSE_renamed_false
#define SDL_TABLESIZE SDL_TABLESIZE_renamed_SDL_arraysize
#define SDL_TRUE SDL_TRUE_renamed_true
#define SDL_bool SDL_bool_renamed_bool
#define SDL_size_add_overflow SDL_size_add_overflow_renamed_SDL_size_add_check_overflow
#define SDL_size_mul_overflow SDL_size_mul_overflow_renamed_SDL_size_mul_check_overflow
#define SDL_strtokr SDL_strtokr_renamed_SDL_strtok_r
/* ##SDL_surface.h */
@ -1247,14 +1284,13 @@
#define SDL_LinuxSetThreadPriorityAndPolicy SDL_LinuxSetThreadPriorityAndPolicy_renamed_SDL_SetLinuxThreadPriorityAndPolicy
#define SDL_OnApplicationDidBecomeActive SDL_OnApplicationDidBecomeActive_renamed_SDL_OnApplicationDidEnterForeground
#define SDL_OnApplicationWillResignActive SDL_OnApplicationWillResignActive_renamed_SDL_OnApplicationWillEnterBackground
#define SDL_WinRTGetDeviceFamily SDL_WinRTGetDeviceFamily_renamed_SDL_GetWinRTDeviceFamily
#define SDL_GetWinRTFSPathUTF8 SDL_GetWinRTFSPathUTF8_renamed_SDL_GetWinRTFSPath
#define SDL_iOSSetAnimationCallback SDL_iOSSetAnimationCallback_renamed_SDL_SetiOSAnimationCallback
#define SDL_iOSSetEventPump SDL_iOSSetEventPump_renamed_SDL_SetiOSEventPump
#define SDL_iPhoneSetAnimationCallback SDL_iPhoneSetAnimationCallback_renamed_SDL_iOSSetAnimationCallback
#define SDL_iPhoneSetEventPump SDL_iPhoneSetEventPump_renamed_SDL_iOSSetEventPump
/* ##SDL_thread.h */
#define SDL_SetThreadPriority SDL_SetThreadPriority_renamed_SDL_SetCurrentThreadPriority
#define SDL_TLSCleanup SDL_TLSCleanup_renamed_SDL_CleanupTLS
#define SDL_TLSGet SDL_TLSGet_renamed_SDL_GetTLS
#define SDL_TLSSet SDL_TLSSet_renamed_SDL_SetTLS
@ -1269,6 +1305,10 @@
/* ##SDL_video.h */
#define SDL_GL_DeleteContext SDL_GL_DeleteContext_renamed_SDL_GL_DestroyContext
#define SDL_GLattr SDL_GLattr_renamed_SDL_GLAttr
#define SDL_GLcontextFlag SDL_GLcontextFlag_renamed_SDL_GLContextFlag
#define SDL_GLcontextReleaseFlag SDL_GLcontextReleaseFlag_renamed_SDL_GLContextReleaseFlag
#define SDL_GLprofile SDL_GLprofile_renamed_SDL_GLProfile
#define SDL_GetClosestDisplayMode SDL_GetClosestDisplayMode_renamed_SDL_GetClosestFullscreenDisplayMode
#define SDL_GetDisplayOrientation SDL_GetDisplayOrientation_renamed_SDL_GetCurrentDisplayOrientation
#define SDL_GetPointDisplayIndex SDL_GetPointDisplayIndex_renamed_SDL_GetDisplayForPoint

File diff suppressed because it is too large Load Diff

View File

@ -1,6 +1,6 @@
/*
Simple DirectMedia Layer
Copyright (C) 1997-2024 Sam Lantinga <slouken@libsdl.org>
Copyright (C) 1997-2025 Sam Lantinga <slouken@libsdl.org>
This software is provided 'as-is', without any express or implied
warranty. In no event will the authors be held liable for any damages

View File

@ -1,6 +1,6 @@
/*
Simple DirectMedia Layer
Copyright (C) 1997-2024 Sam Lantinga <slouken@libsdl.org>
Copyright (C) 1997-2025 Sam Lantinga <slouken@libsdl.org>
This software is provided 'as-is', without any express or implied
warranty. In no event will the authors be held liable for any damages

View File

@ -1,6 +1,6 @@
/*
Simple DirectMedia Layer
Copyright (C) 1997-2024 Sam Lantinga <slouken@libsdl.org>
Copyright (C) 1997-2025 Sam Lantinga <slouken@libsdl.org>
This software is provided 'as-is', without any express or implied
warranty. In no event will the authors be held liable for any damages
@ -39,7 +39,9 @@
#ifndef SDL_pen_h_
#define SDL_pen_h_
#include <SDL3/SDL_error.h>
#include <SDL3/SDL_stdinc.h>
#include <SDL3/SDL_mouse.h>
#include <SDL3/SDL_touch.h>
/* Set up for C function definitions, even when using C++ */
#ifdef __cplusplus
@ -55,24 +57,39 @@ extern "C" {
* 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.
*
* \since This datatype is available since SDL 3.0.0.
* \since This datatype is available since SDL 3.2.0.
*/
typedef Uint32 SDL_PenID;
/**
* The SDL_MouseID for mouse events simulated with pen input.
*
* \since This macro is available since SDL 3.2.0.
*/
#define SDL_PEN_MOUSEID ((SDL_MouseID)-2)
/**
* The SDL_TouchID for touch events simulated with pen input.
*
* \since This macro is available since SDL 3.2.0.
*/
#define SDL_PEN_TOUCHID ((SDL_TouchID)-2)
/**
* Pen input flags, as reported by various pen events' `pen_state` field.
*
* \since This datatype is available since SDL 3.0.0.
* \since This datatype is available since SDL 3.2.0.
*/
typedef Uint32 SDL_PenInputFlags;
#define SDL_PEN_INPUT_DOWN (1u << 0) /**< & to see if pen is pressed down */
#define SDL_PEN_INPUT_BUTTON_1 (1u << 1) /**< & to see if button 1 is pressed */
#define SDL_PEN_INPUT_BUTTON_2 (1u << 2) /**< & to see if button 2 is pressed */
#define SDL_PEN_INPUT_BUTTON_3 (1u << 3) /**< & to see if button 3 is pressed */
#define SDL_PEN_INPUT_BUTTON_4 (1u << 4) /**< & to see if button 4 is pressed */
#define SDL_PEN_INPUT_BUTTON_5 (1u << 5) /**< & to see if button 5 is pressed */
#define SDL_PEN_INPUT_ERASER_TIP (1u << 30) /**< & to see if 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 */
/**
* Pen axis indices.
@ -87,20 +104,18 @@ typedef Uint32 SDL_PenInputFlags;
*
* `SDL_sinf(xtilt * SDL_PI_F / 180.0)`.
*
* \since This enum is available since SDL 3.0.0
* \since This enum is available since SDL 3.2.0.
*/
typedef enum SDL_PenAxis
{
SDL_PEN_AXIS_PRESSURE, /**< Pen pressure. Unidirectional: 0 to 1.0 */
SDL_PEN_AXIS_XTILT, /**< Pen horizontal tilt angle. Bidirectional: -90.0 to 90.0 (left-to-right).
The physical max/min tilt may be smaller than -90.0 / 90.0, check SDL_PenCapabilityInfo */
SDL_PEN_AXIS_YTILT, /**< Pen vertical tilt angle. Bidirectional: -90.0 to 90.0 (top-to-down).
The physical max/min tilt may be smaller than -90.0 / 90.0 check SDL_PenCapabilityInfo */
SDL_PEN_AXIS_XTILT, /**< Pen horizontal tilt angle. Bidirectional: -90.0 to 90.0 (left-to-right). */
SDL_PEN_AXIS_YTILT, /**< Pen vertical tilt angle. Bidirectional: -90.0 to 90.0 (top-to-down). */
SDL_PEN_AXIS_DISTANCE, /**< Pen distance to drawing surface. Unidirectional: 0.0 to 1.0 */
SDL_PEN_AXIS_ROTATION, /**< Pen barrel rotation. Bidirectional: -180 to 179.9 (clockwise, 0 is facing up, -180.0 is facing down). */
SDL_PEN_AXIS_SLIDER, /**< Pen finger wheel or slider (e.g., Airbrush Pen). Unidirectional: 0 to 1.0 */
SDL_PEN_AXIS_TANGENTIAL_PRESSURE, /**< Pressure from squeezing the pen ("barrel pressure"). */
SDL_PEN_NUM_AXES /**< Total known pen axis types in this version of SDL. This number may grow in future releases! */
SDL_PEN_AXIS_COUNT /**< Total known pen axis types in this version of SDL. This number may grow in future releases! */
} SDL_PenAxis;
/* Ends C function definitions when using C++ */
@ -110,4 +125,3 @@ typedef enum SDL_PenAxis
#endif /* SDL_pen_h_ */
/* vi: set ts=4 sw=4 expandtab: */

View File

@ -1,6 +1,6 @@
/*
Simple DirectMedia Layer
Copyright (C) 1997-2024 Sam Lantinga <slouken@libsdl.org>
Copyright (C) 1997-2025 Sam Lantinga <slouken@libsdl.org>
This software is provided 'as-is', without any express or implied
warranty. In no event will the authors be held liable for any damages
@ -22,7 +22,59 @@
/**
* # CategoryPixels
*
* Pixel management.
* SDL offers facilities for pixel management.
*
* Largely these facilities deal with pixel _format_: what does this set of
* bits represent?
*
* If you mostly want to think of a pixel as some combination of red, green,
* blue, and maybe alpha intensities, this is all pretty straightforward, and
* in many cases, is enough information to build a perfectly fine game.
*
* However, the actual definition of a pixel is more complex than that:
*
* Pixels are a representation of a color in a particular color space.
*
* The first characteristic of a color space is the color type. SDL
* understands two different color types, RGB and YCbCr, or in SDL also
* referred to as YUV.
*
* RGB colors consist of red, green, and blue channels of color that are added
* together to represent the colors we see on the screen.
*
* https://en.wikipedia.org/wiki/RGB_color_model
*
* YCbCr colors represent colors as a Y luma brightness component and red and
* blue chroma color offsets. This color representation takes advantage of the
* fact that the human eye is more sensitive to brightness than the color in
* an image. The Cb and Cr components are often compressed and have lower
* resolution than the luma component.
*
* https://en.wikipedia.org/wiki/YCbCr
*
* When the color information in YCbCr is compressed, the Y pixels are left at
* full resolution and each Cr and Cb pixel represents an average of the color
* information in a block of Y pixels. The chroma location determines where in
* that block of pixels the color information is coming from.
*
* The color range defines how much of the pixel to use when converting a
* pixel into a color on the display. When the full color range is used, the
* entire numeric range of the pixel bits is significant. When narrow color
* range is used, for historical reasons, the pixel uses only a portion of the
* numeric range to represent colors.
*
* The color primaries and white point are a definition of the colors in the
* color space relative to the standard XYZ color space.
*
* https://en.wikipedia.org/wiki/CIE_1931_color_space
*
* The transfer characteristic, or opto-electrical transfer function (OETF),
* is the way a color is converted from mathematically linear space into a
* non-linear output signals.
*
* https://en.wikipedia.org/wiki/Rec._709#Transfer_characteristics
*
* The matrix coefficients are used to convert between YCbCr and RGB colors.
*/
#ifndef SDL_pixels_h_
@ -41,22 +93,44 @@ extern "C" {
/**
* A fully opaque 8-bit alpha value.
*
* \since This macro is available since SDL 3.0.0.
* \since This macro is available since SDL 3.2.0.
*
* \sa SDL_ALPHA_TRANSPARENT
*/
#define SDL_ALPHA_OPAQUE 255
/**
* A fully opaque floating point alpha value.
*
* \since This macro is available since SDL 3.2.0.
*
* \sa SDL_ALPHA_TRANSPARENT_FLOAT
*/
#define SDL_ALPHA_OPAQUE_FLOAT 1.0f
/**
* A fully transparent 8-bit alpha value.
*
* \since This macro is available since SDL 3.0.0.
* \since This macro is available since SDL 3.2.0.
*
* \sa SDL_ALPHA_OPAQUE
*/
#define SDL_ALPHA_TRANSPARENT 0
/** Pixel type. */
/**
* A fully transparent floating point alpha value.
*
* \since This macro is available since SDL 3.2.0.
*
* \sa SDL_ALPHA_OPAQUE_FLOAT
*/
#define SDL_ALPHA_TRANSPARENT_FLOAT 0.0f
/**
* Pixel type.
*
* \since This enum is available since SDL 3.2.0.
*/
typedef enum SDL_PixelType
{
SDL_PIXELTYPE_UNKNOWN,
@ -75,7 +149,11 @@ typedef enum SDL_PixelType
SDL_PIXELTYPE_INDEX2
} SDL_PixelType;
/** Bitmap pixel order, high bit -> low bit. */
/**
* Bitmap pixel order, high bit -> low bit.
*
* \since This enum is available since SDL 3.2.0.
*/
typedef enum SDL_BitmapOrder
{
SDL_BITMAPORDER_NONE,
@ -83,7 +161,11 @@ typedef enum SDL_BitmapOrder
SDL_BITMAPORDER_1234
} SDL_BitmapOrder;
/** Packed component order, high bit -> low bit. */
/**
* Packed component order, high bit -> low bit.
*
* \since This enum is available since SDL 3.2.0.
*/
typedef enum SDL_PackedOrder
{
SDL_PACKEDORDER_NONE,
@ -97,7 +179,11 @@ typedef enum SDL_PackedOrder
SDL_PACKEDORDER_BGRA
} SDL_PackedOrder;
/** Array component order, low byte -> high byte. */
/**
* Array component order, low byte -> high byte.
*
* \since This enum is available since SDL 3.2.0.
*/
typedef enum SDL_ArrayOrder
{
SDL_ARRAYORDER_NONE,
@ -109,7 +195,11 @@ typedef enum SDL_ArrayOrder
SDL_ARRAYORDER_ABGR
} SDL_ArrayOrder;
/** Packed component layout. */
/**
* Packed component layout.
*
* \since This enum is available since SDL 3.2.0.
*/
typedef enum SDL_PackedLayout
{
SDL_PACKEDLAYOUT_NONE,
@ -123,25 +213,172 @@ typedef enum SDL_PackedLayout
SDL_PACKEDLAYOUT_1010102
} SDL_PackedLayout;
/**
* A macro for defining custom FourCC pixel formats.
*
* For example, defining SDL_PIXELFORMAT_YV12 looks like this:
*
* ```c
* SDL_DEFINE_PIXELFOURCC('Y', 'V', '1', '2')
* ```
*
* \param A the first character of the FourCC code.
* \param B the second character of the FourCC code.
* \param C the third character of the FourCC code.
* \param D the fourth character of the FourCC code.
* \returns a format value in the style of SDL_PixelFormat.
*
* \threadsafety It is safe to call this macro from any thread.
*
* \since This macro is available since SDL 3.2.0.
*/
#define SDL_DEFINE_PIXELFOURCC(A, B, C, D) SDL_FOURCC(A, B, C, D)
/**
* A macro for defining custom non-FourCC pixel formats.
*
* For example, defining SDL_PIXELFORMAT_RGBA8888 looks like this:
*
* ```c
* SDL_DEFINE_PIXELFORMAT(SDL_PIXELTYPE_PACKED32, SDL_PACKEDORDER_RGBA, SDL_PACKEDLAYOUT_8888, 32, 4)
* ```
*
* \param type the type of the new format, probably a SDL_PixelType value.
* \param order the order of the new format, probably a SDL_BitmapOrder,
* SDL_PackedOrder, or SDL_ArrayOrder value.
* \param layout the layout of the new format, probably an SDL_PackedLayout
* value or zero.
* \param bits the number of bits per pixel of the new format.
* \param bytes the number of bytes per pixel of the new format.
* \returns a format value in the style of SDL_PixelFormat.
*
* \threadsafety It is safe to call this macro from any thread.
*
* \since This macro is available since SDL 3.2.0.
*/
#define SDL_DEFINE_PIXELFORMAT(type, order, layout, bits, bytes) \
((1 << 28) | ((type) << 24) | ((order) << 20) | ((layout) << 16) | \
((bits) << 8) | ((bytes) << 0))
#define SDL_PIXELFLAG(X) (((X) >> 28) & 0x0F)
#define SDL_PIXELTYPE(X) (((X) >> 24) & 0x0F)
#define SDL_PIXELORDER(X) (((X) >> 20) & 0x0F)
#define SDL_PIXELLAYOUT(X) (((X) >> 16) & 0x0F)
#define SDL_BITSPERPIXEL(X) \
(SDL_ISPIXELFORMAT_FOURCC(X) ? 0 : (((X) >> 8) & 0xFF))
#define SDL_BYTESPERPIXEL(X) \
(SDL_ISPIXELFORMAT_FOURCC(X) ? \
((((X) == SDL_PIXELFORMAT_YUY2) || \
((X) == SDL_PIXELFORMAT_UYVY) || \
((X) == SDL_PIXELFORMAT_YVYU) || \
((X) == SDL_PIXELFORMAT_P010)) ? 2 : 1) : (((X) >> 0) & 0xFF))
/**
* A macro to retrieve the flags of an SDL_PixelFormat.
*
* This macro is generally not needed directly by an app, which should use
* specific tests, like SDL_ISPIXELFORMAT_FOURCC, instead.
*
* \param format an SDL_PixelFormat to check.
* \returns the flags of `format`.
*
* \threadsafety It is safe to call this macro from any thread.
*
* \since This macro is available since SDL 3.2.0.
*/
#define SDL_PIXELFLAG(format) (((format) >> 28) & 0x0F)
/**
* A macro to retrieve the type of an SDL_PixelFormat.
*
* This is usually a value from the SDL_PixelType enumeration.
*
* \param format an SDL_PixelFormat to check.
* \returns the type of `format`.
*
* \threadsafety It is safe to call this macro from any thread.
*
* \since This macro is available since SDL 3.2.0.
*/
#define SDL_PIXELTYPE(format) (((format) >> 24) & 0x0F)
/**
* A macro to retrieve the order of an SDL_PixelFormat.
*
* This is usually a value from the SDL_BitmapOrder, SDL_PackedOrder, or
* SDL_ArrayOrder enumerations, depending on the format type.
*
* \param format an SDL_PixelFormat to check.
* \returns the order of `format`.
*
* \threadsafety It is safe to call this macro from any thread.
*
* \since This macro is available since SDL 3.2.0.
*/
#define SDL_PIXELORDER(format) (((format) >> 20) & 0x0F)
/**
* A macro to retrieve the layout of an SDL_PixelFormat.
*
* This is usually a value from the SDL_PackedLayout enumeration, or zero if a
* layout doesn't make sense for the format type.
*
* \param format an SDL_PixelFormat to check.
* \returns the layout of `format`.
*
* \threadsafety It is safe to call this macro from any thread.
*
* \since This macro is available since SDL 3.2.0.
*/
#define SDL_PIXELLAYOUT(format) (((format) >> 16) & 0x0F)
/**
* A macro to determine an SDL_PixelFormat's bits per pixel.
*
* Note that this macro double-evaluates its parameter, so do not use
* expressions with side-effects here.
*
* FourCC formats will report zero here, as it rarely makes sense to measure
* them per-pixel.
*
* \param format an SDL_PixelFormat to check.
* \returns the bits-per-pixel of `format`.
*
* \threadsafety It is safe to call this macro from any thread.
*
* \since This macro is available since SDL 3.2.0.
*
* \sa SDL_BYTESPERPIXEL
*/
#define SDL_BITSPERPIXEL(format) \
(SDL_ISPIXELFORMAT_FOURCC(format) ? 0 : (((format) >> 8) & 0xFF))
/**
* A macro to determine an SDL_PixelFormat's bytes per pixel.
*
* Note that this macro double-evaluates its parameter, so do not use
* expressions with side-effects here.
*
* FourCC formats do their best here, but many of them don't have a meaningful
* measurement of bytes per pixel.
*
* \param format an SDL_PixelFormat to check.
* \returns the bytes-per-pixel of `format`.
*
* \threadsafety It is safe to call this macro from any thread.
*
* \since This macro is available since SDL 3.2.0.
*
* \sa SDL_BITSPERPIXEL
*/
#define SDL_BYTESPERPIXEL(format) \
(SDL_ISPIXELFORMAT_FOURCC(format) ? \
((((format) == SDL_PIXELFORMAT_YUY2) || \
((format) == SDL_PIXELFORMAT_UYVY) || \
((format) == SDL_PIXELFORMAT_YVYU) || \
((format) == SDL_PIXELFORMAT_P010)) ? 2 : 1) : (((format) >> 0) & 0xFF))
/**
* A macro to determine if an SDL_PixelFormat is an indexed format.
*
* Note that this macro double-evaluates its parameter, so do not use
* expressions with side-effects here.
*
* \param format an SDL_PixelFormat to check.
* \returns true if the format is indexed, false otherwise.
*
* \threadsafety It is safe to call this macro from any thread.
*
* \since This macro is available since SDL 3.2.0.
*/
#define SDL_ISPIXELFORMAT_INDEXED(format) \
(!SDL_ISPIXELFORMAT_FOURCC(format) && \
((SDL_PIXELTYPE(format) == SDL_PIXELTYPE_INDEX1) || \
@ -149,12 +386,38 @@ typedef enum SDL_PackedLayout
(SDL_PIXELTYPE(format) == SDL_PIXELTYPE_INDEX4) || \
(SDL_PIXELTYPE(format) == SDL_PIXELTYPE_INDEX8)))
/**
* A macro to determine if an SDL_PixelFormat is a packed format.
*
* Note that this macro double-evaluates its parameter, so do not use
* expressions with side-effects here.
*
* \param format an SDL_PixelFormat to check.
* \returns true if the format is packed, false otherwise.
*
* \threadsafety It is safe to call this macro from any thread.
*
* \since This macro is available since SDL 3.2.0.
*/
#define SDL_ISPIXELFORMAT_PACKED(format) \
(!SDL_ISPIXELFORMAT_FOURCC(format) && \
((SDL_PIXELTYPE(format) == SDL_PIXELTYPE_PACKED8) || \
(SDL_PIXELTYPE(format) == SDL_PIXELTYPE_PACKED16) || \
(SDL_PIXELTYPE(format) == SDL_PIXELTYPE_PACKED32)))
/**
* A macro to determine if an SDL_PixelFormat is an array format.
*
* Note that this macro double-evaluates its parameter, so do not use
* expressions with side-effects here.
*
* \param format an SDL_PixelFormat to check.
* \returns true if the format is an array, false otherwise.
*
* \threadsafety It is safe to call this macro from any thread.
*
* \since This macro is available since SDL 3.2.0.
*/
#define SDL_ISPIXELFORMAT_ARRAY(format) \
(!SDL_ISPIXELFORMAT_FOURCC(format) && \
((SDL_PIXELTYPE(format) == SDL_PIXELTYPE_ARRAYU8) || \
@ -163,25 +426,84 @@ typedef enum SDL_PackedLayout
(SDL_PIXELTYPE(format) == SDL_PIXELTYPE_ARRAYF16) || \
(SDL_PIXELTYPE(format) == SDL_PIXELTYPE_ARRAYF32)))
#define SDL_ISPIXELFORMAT_ALPHA(format) \
((SDL_ISPIXELFORMAT_PACKED(format) && \
((SDL_PIXELORDER(format) == SDL_PACKEDORDER_ARGB) || \
(SDL_PIXELORDER(format) == SDL_PACKEDORDER_RGBA) || \
(SDL_PIXELORDER(format) == SDL_PACKEDORDER_ABGR) || \
(SDL_PIXELORDER(format) == SDL_PACKEDORDER_BGRA))))
/**
* A macro to determine if an SDL_PixelFormat is a 10-bit format.
*
* Note that this macro double-evaluates its parameter, so do not use
* expressions with side-effects here.
*
* \param format an SDL_PixelFormat to check.
* \returns true if the format is 10-bit, false otherwise.
*
* \threadsafety It is safe to call this macro from any thread.
*
* \since This macro is available since SDL 3.2.0.
*/
#define SDL_ISPIXELFORMAT_10BIT(format) \
(!SDL_ISPIXELFORMAT_FOURCC(format) && \
((SDL_PIXELTYPE(format) == SDL_PIXELTYPE_PACKED32) && \
(SDL_PIXELLAYOUT(format) == SDL_PACKEDLAYOUT_2101010)))
/**
* A macro to determine if an SDL_PixelFormat is a floating point format.
*
* Note that this macro double-evaluates its parameter, so do not use
* expressions with side-effects here.
*
* \param format an SDL_PixelFormat to check.
* \returns true if the format is 10-bit, false otherwise.
*
* \threadsafety It is safe to call this macro from any thread.
*
* \since This macro is available since SDL 3.2.0.
*/
#define SDL_ISPIXELFORMAT_FLOAT(format) \
(!SDL_ISPIXELFORMAT_FOURCC(format) && \
((SDL_PIXELTYPE(format) == SDL_PIXELTYPE_ARRAYF16) || \
(SDL_PIXELTYPE(format) == SDL_PIXELTYPE_ARRAYF32)))
/* The flag is set to 1 because 0x1? is not in the printable ASCII range */
#define SDL_ISPIXELFORMAT_FOURCC(format) \
/**
* A macro to determine if an SDL_PixelFormat has an alpha channel.
*
* Note that this macro double-evaluates its parameter, so do not use
* expressions with side-effects here.
*
* \param format an SDL_PixelFormat to check.
* \returns true if the format has alpha, false otherwise.
*
* \threadsafety It is safe to call this macro from any thread.
*
* \since This macro is available since SDL 3.2.0.
*/
#define SDL_ISPIXELFORMAT_ALPHA(format) \
((SDL_ISPIXELFORMAT_PACKED(format) && \
((SDL_PIXELORDER(format) == SDL_PACKEDORDER_ARGB) || \
(SDL_PIXELORDER(format) == SDL_PACKEDORDER_RGBA) || \
(SDL_PIXELORDER(format) == SDL_PACKEDORDER_ABGR) || \
(SDL_PIXELORDER(format) == SDL_PACKEDORDER_BGRA))) || \
(SDL_ISPIXELFORMAT_ARRAY(format) && \
((SDL_PIXELORDER(format) == SDL_ARRAYORDER_ARGB) || \
(SDL_PIXELORDER(format) == SDL_ARRAYORDER_RGBA) || \
(SDL_PIXELORDER(format) == SDL_ARRAYORDER_ABGR) || \
(SDL_PIXELORDER(format) == SDL_ARRAYORDER_BGRA))))
/**
* A macro to determine if an SDL_PixelFormat is a "FourCC" format.
*
* This covers custom and other unusual formats.
*
* Note that this macro double-evaluates its parameter, so do not use
* expressions with side-effects here.
*
* \param format an SDL_PixelFormat to check.
* \returns true if the format has alpha, false otherwise.
*
* \threadsafety It is safe to call this macro from any thread.
*
* \since This macro is available since SDL 3.2.0.
*/
#define SDL_ISPIXELFORMAT_FOURCC(format) /* The flag is set to 1 because 0x1? is not in the printable ASCII range */ \
((format) && (SDL_PIXELFLAG(format) != 1))
/* Note: If you modify this enum, update SDL_GetPixelFormatName() */
@ -221,7 +543,7 @@ typedef enum SDL_PackedLayout
* an alias for ABGR8888 on little-endian CPUs like x86, or an alias for
* RGBA8888 on big-endian CPUs.
*
* \since This enum is available since SDL 3.0.0.
* \since This enum is available since SDL 3.2.0.
*/
typedef enum SDL_PixelFormat
{
@ -351,59 +673,35 @@ typedef enum SDL_PixelFormat
/* SDL_DEFINE_PIXELFOURCC('N', 'V', '2', '1'), */
SDL_PIXELFORMAT_P010 = 0x30313050u, /**< Planar mode: Y + U/V interleaved (2 planes) */
/* SDL_DEFINE_PIXELFOURCC('P', '0', '1', '0'), */
SDL_PIXELFORMAT_EXTERNAL_OES = 0x2053454fu /**< Android video texture format */
SDL_PIXELFORMAT_EXTERNAL_OES = 0x2053454fu, /**< Android video texture format */
/* SDL_DEFINE_PIXELFOURCC('O', 'E', 'S', ' ') */
/* Aliases for RGBA byte arrays of color data, for the current platform */
#if SDL_BYTEORDER == SDL_BIG_ENDIAN
SDL_PIXELFORMAT_RGBA32 = SDL_PIXELFORMAT_RGBA8888,
SDL_PIXELFORMAT_ARGB32 = SDL_PIXELFORMAT_ARGB8888,
SDL_PIXELFORMAT_BGRA32 = SDL_PIXELFORMAT_BGRA8888,
SDL_PIXELFORMAT_ABGR32 = SDL_PIXELFORMAT_ABGR8888,
SDL_PIXELFORMAT_RGBX32 = SDL_PIXELFORMAT_RGBX8888,
SDL_PIXELFORMAT_XRGB32 = SDL_PIXELFORMAT_XRGB8888,
SDL_PIXELFORMAT_BGRX32 = SDL_PIXELFORMAT_BGRX8888,
SDL_PIXELFORMAT_XBGR32 = SDL_PIXELFORMAT_XBGR8888
#else
SDL_PIXELFORMAT_RGBA32 = SDL_PIXELFORMAT_ABGR8888,
SDL_PIXELFORMAT_ARGB32 = SDL_PIXELFORMAT_BGRA8888,
SDL_PIXELFORMAT_BGRA32 = SDL_PIXELFORMAT_ARGB8888,
SDL_PIXELFORMAT_ABGR32 = SDL_PIXELFORMAT_RGBA8888,
SDL_PIXELFORMAT_RGBX32 = SDL_PIXELFORMAT_XBGR8888,
SDL_PIXELFORMAT_XRGB32 = SDL_PIXELFORMAT_BGRX8888,
SDL_PIXELFORMAT_BGRX32 = SDL_PIXELFORMAT_XRGB8888,
SDL_PIXELFORMAT_XBGR32 = SDL_PIXELFORMAT_RGBX8888
#endif
} SDL_PixelFormat;
/* Aliases for RGBA byte arrays of color data, for the current platform */
#if SDL_BYTEORDER == SDL_BIG_ENDIAN
#define SDL_PIXELFORMAT_RGBA32 SDL_PIXELFORMAT_RGBA8888
#define SDL_PIXELFORMAT_ARGB32 SDL_PIXELFORMAT_ARGB8888
#define SDL_PIXELFORMAT_BGRA32 SDL_PIXELFORMAT_BGRA8888
#define SDL_PIXELFORMAT_ABGR32 SDL_PIXELFORMAT_ABGR8888
#define SDL_PIXELFORMAT_RGBX32 SDL_PIXELFORMAT_RGBX8888
#define SDL_PIXELFORMAT_XRGB32 SDL_PIXELFORMAT_XRGB8888
#define SDL_PIXELFORMAT_BGRX32 SDL_PIXELFORMAT_BGRX8888
#define SDL_PIXELFORMAT_XBGR32 SDL_PIXELFORMAT_XBGR8888
#else
#define SDL_PIXELFORMAT_RGBA32 SDL_PIXELFORMAT_ABGR8888
#define SDL_PIXELFORMAT_ARGB32 SDL_PIXELFORMAT_BGRA8888
#define SDL_PIXELFORMAT_BGRA32 SDL_PIXELFORMAT_ARGB8888
#define SDL_PIXELFORMAT_ABGR32 SDL_PIXELFORMAT_RGBA8888
#define SDL_PIXELFORMAT_RGBX32 SDL_PIXELFORMAT_XBGR8888
#define SDL_PIXELFORMAT_XRGB32 SDL_PIXELFORMAT_BGRX8888
#define SDL_PIXELFORMAT_BGRX32 SDL_PIXELFORMAT_XRGB8888
#define SDL_PIXELFORMAT_XBGR32 SDL_PIXELFORMAT_RGBX8888
#endif
/**
* Pixels are a representation of a color in a particular color space.
*
* The first characteristic of a color space is the color type. SDL understands two different color types, RGB and YCbCr, or in SDL also referred to as YUV.
*
* RGB colors consist of red, green, and blue channels of color that are added together to represent the colors we see on the screen.
* https://en.wikipedia.org/wiki/RGB_color_model
*
* YCbCr colors represent colors as a Y luma brightness component and red and blue chroma color offsets. This color representation takes advantage of the fact that the human eye is more sensitive to brightness than the color in an image. The Cb and Cr components are often compressed and have lower resolution than the luma component.
* https://en.wikipedia.org/wiki/YCbCr
*
* When the color information in YCbCr is compressed, the Y pixels are left at full resolution and each Cr and Cb pixel represents an average of the color information in a block of Y pixels. The chroma location determines where in that block of pixels the color information is coming from.
*
* The color range defines how much of the pixel to use when converting a pixel into a color on the display. When the full color range is used, the entire numeric range of the pixel bits is significant. When narrow color range is used, for historical reasons, the pixel uses only a portion of the numeric range to represent colors.
*
* The color primaries and white point are a definition of the colors in the color space relative to the standard XYZ color space.
* https://en.wikipedia.org/wiki/CIE_1931_color_space
*
* The transfer characteristic, or opto-electrical transfer function (OETF), is the way a color is converted from mathematically linear space into a non-linear output signals.
* https://en.wikipedia.org/wiki/Rec._709#Transfer_characteristics
*
* The matrix coefficients are used to convert between YCbCr and RGB colors.
*/
/**
* Colorspace color type.
*
* \since This enum is available since SDL 3.0.0.
* \since This enum is available since SDL 3.2.0.
*/
typedef enum SDL_ColorType
{
@ -416,7 +714,7 @@ typedef enum SDL_ColorType
* Colorspace color range, as described by
* https://www.itu.int/rec/R-REC-BT.2100-2-201807-I/en
*
* \since This enum is available since SDL 3.0.0.
* \since This enum is available since SDL 3.2.0.
*/
typedef enum SDL_ColorRange
{
@ -429,7 +727,7 @@ typedef enum SDL_ColorRange
* Colorspace color primaries, as described by
* https://www.itu.int/rec/T-REC-H.273-201612-S/en
*
* \since This enum is available since SDL 3.0.0.
* \since This enum is available since SDL 3.2.0.
*/
typedef enum SDL_ColorPrimaries
{
@ -454,7 +752,7 @@ typedef enum SDL_ColorPrimaries
*
* These are as described by https://www.itu.int/rec/T-REC-H.273-201612-S/en
*
* \since This enum is available since SDL 3.0.0.
* \since This enum is available since SDL 3.2.0.
*/
typedef enum SDL_TransferCharacteristics
{
@ -484,7 +782,7 @@ typedef enum SDL_TransferCharacteristics
*
* These are as described by https://www.itu.int/rec/T-REC-H.273-201612-S/en
*
* \since This enum is available since SDL 3.0.0.
* \since This enum is available since SDL 3.2.0.
*/
typedef enum SDL_MatrixCoefficients
{
@ -508,7 +806,7 @@ typedef enum SDL_MatrixCoefficients
/**
* Colorspace chroma sample location.
*
* \since This enum is available since SDL 3.0.0.
* \since This enum is available since SDL 3.2.0.
*/
typedef enum SDL_ChromaLocation
{
@ -520,22 +818,177 @@ typedef enum SDL_ChromaLocation
/* Colorspace definition */
/**
* A macro for defining custom SDL_Colorspace formats.
*
* For example, defining SDL_COLORSPACE_SRGB looks like this:
*
* ```c
* SDL_DEFINE_COLORSPACE(SDL_COLOR_TYPE_RGB,
* SDL_COLOR_RANGE_FULL,
* SDL_COLOR_PRIMARIES_BT709,
* SDL_TRANSFER_CHARACTERISTICS_SRGB,
* SDL_MATRIX_COEFFICIENTS_IDENTITY,
* SDL_CHROMA_LOCATION_NONE)
* ```
*
* \param type the type of the new format, probably an SDL_ColorType value.
* \param range the range of the new format, probably a SDL_ColorRange value.
* \param primaries the primaries of the new format, probably an
* SDL_ColorPrimaries value.
* \param transfer the transfer characteristics of the new format, probably an
* SDL_TransferCharacteristics value.
* \param matrix the matrix coefficients of the new format, probably an
* SDL_MatrixCoefficients value.
* \param chroma the chroma sample location of the new format, probably an
* SDL_ChromaLocation value.
* \returns a format value in the style of SDL_Colorspace.
*
* \threadsafety It is safe to call this macro from any thread.
*
* \since This macro is available since SDL 3.2.0.
*/
#define SDL_DEFINE_COLORSPACE(type, range, primaries, transfer, matrix, chroma) \
(((Uint32)(type) << 28) | ((Uint32)(range) << 24) | ((Uint32)(chroma) << 20) | \
((Uint32)(primaries) << 10) | ((Uint32)(transfer) << 5) | ((Uint32)(matrix) << 0))
#define SDL_COLORSPACETYPE(X) (SDL_ColorType)(((X) >> 28) & 0x0F)
#define SDL_COLORSPACERANGE(X) (SDL_ColorRange)(((X) >> 24) & 0x0F)
#define SDL_COLORSPACECHROMA(X) (SDL_ChromaLocation)(((X) >> 20) & 0x0F)
#define SDL_COLORSPACEPRIMARIES(X) (SDL_ColorPrimaries)(((X) >> 10) & 0x1F)
#define SDL_COLORSPACETRANSFER(X) (SDL_TransferCharacteristics)(((X) >> 5) & 0x1F)
#define SDL_COLORSPACEMATRIX(X) (SDL_MatrixCoefficients)((X) & 0x1F)
/**
* A macro to retrieve the type of an SDL_Colorspace.
*
* \param cspace an SDL_Colorspace to check.
* \returns the SDL_ColorType for `cspace`.
*
* \threadsafety It is safe to call this macro from any thread.
*
* \since This macro is available since SDL 3.2.0.
*/
#define SDL_COLORSPACETYPE(cspace) (SDL_ColorType)(((cspace) >> 28) & 0x0F)
#define SDL_ISCOLORSPACE_MATRIX_BT601(X) (SDL_COLORSPACEMATRIX(X) == SDL_MATRIX_COEFFICIENTS_BT601 || SDL_COLORSPACEMATRIX(X) == SDL_MATRIX_COEFFICIENTS_BT470BG)
#define SDL_ISCOLORSPACE_MATRIX_BT709(X) (SDL_COLORSPACEMATRIX(X) == SDL_MATRIX_COEFFICIENTS_BT709)
#define SDL_ISCOLORSPACE_MATRIX_BT2020_NCL(X) (SDL_COLORSPACEMATRIX(X) == SDL_MATRIX_COEFFICIENTS_BT2020_NCL)
#define SDL_ISCOLORSPACE_LIMITED_RANGE(X) (SDL_COLORSPACERANGE(X) != SDL_COLOR_RANGE_FULL)
#define SDL_ISCOLORSPACE_FULL_RANGE(X) (SDL_COLORSPACERANGE(X) == SDL_COLOR_RANGE_FULL)
/**
* A macro to retrieve the range of an SDL_Colorspace.
*
* \param cspace an SDL_Colorspace to check.
* \returns the SDL_ColorRange of `cspace`.
*
* \threadsafety It is safe to call this macro from any thread.
*
* \since This macro is available since SDL 3.2.0.
*/
#define SDL_COLORSPACERANGE(cspace) (SDL_ColorRange)(((cspace) >> 24) & 0x0F)
/**
* A macro to retrieve the chroma sample location of an SDL_Colorspace.
*
* \param cspace an SDL_Colorspace to check.
* \returns the SDL_ChromaLocation of `cspace`.
*
* \threadsafety It is safe to call this macro from any thread.
*
* \since This macro is available since SDL 3.2.0.
*/
#define SDL_COLORSPACECHROMA(cspace) (SDL_ChromaLocation)(((cspace) >> 20) & 0x0F)
/**
* A macro to retrieve the primaries of an SDL_Colorspace.
*
* \param cspace an SDL_Colorspace to check.
* \returns the SDL_ColorPrimaries of `cspace`.
*
* \threadsafety It is safe to call this macro from any thread.
*
* \since This macro is available since SDL 3.2.0.
*/
#define SDL_COLORSPACEPRIMARIES(cspace) (SDL_ColorPrimaries)(((cspace) >> 10) & 0x1F)
/**
* A macro to retrieve the transfer characteristics of an SDL_Colorspace.
*
* \param cspace an SDL_Colorspace to check.
* \returns the SDL_TransferCharacteristics of `cspace`.
*
* \threadsafety It is safe to call this macro from any thread.
*
* \since This macro is available since SDL 3.2.0.
*/
#define SDL_COLORSPACETRANSFER(cspace) (SDL_TransferCharacteristics)(((cspace) >> 5) & 0x1F)
/**
* A macro to retrieve the matrix coefficients of an SDL_Colorspace.
*
* \param cspace an SDL_Colorspace to check.
* \returns the SDL_MatrixCoefficients of `cspace`.
*
* \threadsafety It is safe to call this macro from any thread.
*
* \since This macro is available since SDL 3.2.0.
*/
#define SDL_COLORSPACEMATRIX(cspace) (SDL_MatrixCoefficients)((cspace) & 0x1F)
/**
* A macro to determine if an SDL_Colorspace uses BT601 (or BT470BG) matrix
* coefficients.
*
* Note that this macro double-evaluates its parameter, so do not use
* expressions with side-effects here.
*
* \param cspace an SDL_Colorspace to check.
* \returns true if BT601 or BT470BG, false otherwise.
*
* \threadsafety It is safe to call this macro from any thread.
*
* \since This macro is available since SDL 3.2.0.
*/
#define SDL_ISCOLORSPACE_MATRIX_BT601(cspace) (SDL_COLORSPACEMATRIX(cspace) == SDL_MATRIX_COEFFICIENTS_BT601 || SDL_COLORSPACEMATRIX(cspace) == SDL_MATRIX_COEFFICIENTS_BT470BG)
/**
* A macro to determine if an SDL_Colorspace uses BT709 matrix coefficients.
*
* \param cspace an SDL_Colorspace to check.
* \returns true if BT709, false otherwise.
*
* \threadsafety It is safe to call this macro from any thread.
*
* \since This macro is available since SDL 3.2.0.
*/
#define SDL_ISCOLORSPACE_MATRIX_BT709(cspace) (SDL_COLORSPACEMATRIX(cspace) == SDL_MATRIX_COEFFICIENTS_BT709)
/**
* A macro to determine if an SDL_Colorspace uses BT2020_NCL matrix
* coefficients.
*
* \param cspace an SDL_Colorspace to check.
* \returns true if BT2020_NCL, false otherwise.
*
* \threadsafety It is safe to call this macro from any thread.
*
* \since This macro is available since SDL 3.2.0.
*/
#define SDL_ISCOLORSPACE_MATRIX_BT2020_NCL(cspace) (SDL_COLORSPACEMATRIX(cspace) == SDL_MATRIX_COEFFICIENTS_BT2020_NCL)
/**
* A macro to determine if an SDL_Colorspace has a limited range.
*
* \param cspace an SDL_Colorspace to check.
* \returns true if limited range, false otherwise.
*
* \threadsafety It is safe to call this macro from any thread.
*
* \since This macro is available since SDL 3.2.0.
*/
#define SDL_ISCOLORSPACE_LIMITED_RANGE(cspace) (SDL_COLORSPACERANGE(cspace) != SDL_COLOR_RANGE_FULL)
/**
* A macro to determine if an SDL_Colorspace has a full range.
*
* \param cspace an SDL_Colorspace to check.
* \returns true if full range, false otherwise.
*
* \threadsafety It is safe to call this macro from any thread.
*
* \since This macro is available since SDL 3.2.0.
*/
#define SDL_ISCOLORSPACE_FULL_RANGE(cspace) (SDL_COLORSPACERANGE(cspace) == SDL_COLOR_RANGE_FULL)
/**
* Colorspace definitions.
@ -544,7 +997,7 @@ typedef enum SDL_ChromaLocation
* function, etc.), this is not an exhaustive list, but rather a
* representative sample of the kinds of colorspaces supported in SDL.
*
* \since This enum is available since SDL 3.0.0.
* \since This enum is available since SDL 3.2.0.
*
* \sa SDL_ColorPrimaries
* \sa SDL_ColorRange
@ -631,7 +1084,7 @@ typedef enum SDL_Colorspace
SDL_MATRIX_COEFFICIENTS_BT2020_NCL,
SDL_CHROMA_LOCATION_LEFT), */
SDL_COLORSPACE_BT2020_FULL = 0x22102609u /**< Equivalent to DXGI_COLOR_SPACE_YCBCR_FULL_G22_LEFT_P2020 */
SDL_COLORSPACE_BT2020_FULL = 0x22102609u, /**< Equivalent to DXGI_COLOR_SPACE_YCBCR_FULL_G22_LEFT_P2020 */
/* SDL_DEFINE_COLORSPACE(SDL_COLOR_TYPE_YCBCR,
SDL_COLOR_RANGE_FULL,
SDL_COLOR_PRIMARIES_BT2020,
@ -639,15 +1092,10 @@ typedef enum SDL_Colorspace
SDL_MATRIX_COEFFICIENTS_BT2020_NCL,
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;
/* The default colorspace for RGB surfaces if no colorspace is specified */
#define SDL_COLORSPACE_RGB_DEFAULT SDL_COLORSPACE_SRGB
/* The default colorspace for YUV surfaces if no colorspace is specified */
#define SDL_COLORSPACE_YUV_DEFAULT SDL_COLORSPACE_JPEG
/**
* A structure that represents a color as RGBA components.
*
@ -656,7 +1104,7 @@ typedef enum SDL_Colorspace
* (SDL_PIXELFORMAT_ABGR8888 on little-endian systems and
* SDL_PIXELFORMAT_RGBA8888 on big-endian systems).
*
* \since This struct is available since SDL 3.0.0.
* \since This struct is available since SDL 3.2.0.
*/
typedef struct SDL_Color
{
@ -670,7 +1118,7 @@ typedef struct SDL_Color
* The bits of this structure can be directly reinterpreted as a float-packed
* color which uses the SDL_PIXELFORMAT_RGBA128_FLOAT format
*
* \since This struct is available since SDL 3.0.0.
* \since This struct is available since SDL 3.2.0.
*/
typedef struct SDL_FColor
{
@ -683,7 +1131,7 @@ typedef struct SDL_FColor
/**
* A set of indexed colors representing a palette.
*
* \since This struct is available since SDL 3.0.0.
* \since This struct is available since SDL 3.2.0.
*
* \sa SDL_SetPaletteColors
*/
@ -698,7 +1146,7 @@ typedef struct SDL_Palette
/**
* Details about the format of a pixel.
*
* \since This struct is available since SDL 3.0.0.
* \since This struct is available since SDL 3.2.0.
*/
typedef struct SDL_PixelFormatDetails
{
@ -729,7 +1177,7 @@ typedef struct SDL_PixelFormatDetails
*
* \threadsafety It is safe to call this function from any thread.
*
* \since This function is available since SDL 3.0.0.
* \since This function is available since SDL 3.2.0.
*/
extern SDL_DECLSPEC const char * SDLCALL SDL_GetPixelFormatName(SDL_PixelFormat format);
@ -742,16 +1190,16 @@ extern SDL_DECLSPEC const char * SDLCALL SDL_GetPixelFormatName(SDL_PixelFormat
* \param Gmask a pointer filled in with the green mask for the format.
* \param Bmask a pointer filled in with the blue mask for the format.
* \param Amask a pointer filled in with the alpha mask for the format.
* \returns SDL_TRUE on success or SDL_FALSE on failure; call SDL_GetError()
* for more information.
* \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.0.0.
* \since This function is available since SDL 3.2.0.
*
* \sa SDL_GetPixelFormatForMasks
*/
extern SDL_DECLSPEC SDL_bool SDLCALL SDL_GetMasksForPixelFormat(SDL_PixelFormat format, int *bpp, Uint32 *Rmask, Uint32 *Gmask, Uint32 *Bmask, Uint32 *Amask);
extern SDL_DECLSPEC bool SDLCALL SDL_GetMasksForPixelFormat(SDL_PixelFormat format, int *bpp, Uint32 *Rmask, Uint32 *Gmask, Uint32 *Bmask, Uint32 *Amask);
/**
* Convert a bpp value and RGBA masks to an enumerated pixel format.
@ -769,7 +1217,7 @@ extern SDL_DECLSPEC SDL_bool SDLCALL SDL_GetMasksForPixelFormat(SDL_PixelFormat
*
* \threadsafety It is safe to call this function from any thread.
*
* \since This function is available since SDL 3.0.0.
* \since This function is available since SDL 3.2.0.
*
* \sa SDL_GetMasksForPixelFormat
*/
@ -788,7 +1236,7 @@ extern SDL_DECLSPEC SDL_PixelFormat SDLCALL SDL_GetPixelFormatForMasks(int bpp,
*
* \threadsafety It is safe to call this function from any thread.
*
* \since This function is available since SDL 3.0.0.
* \since This function is available since SDL 3.2.0.
*/
extern SDL_DECLSPEC const SDL_PixelFormatDetails * SDLCALL SDL_GetPixelFormatDetails(SDL_PixelFormat format);
@ -804,7 +1252,7 @@ extern SDL_DECLSPEC const SDL_PixelFormatDetails * SDLCALL SDL_GetPixelFormatDet
*
* \threadsafety It is safe to call this function from any thread.
*
* \since This function is available since SDL 3.0.0.
* \since This function is available since SDL 3.2.0.
*
* \sa SDL_DestroyPalette
* \sa SDL_SetPaletteColors
@ -819,15 +1267,15 @@ extern SDL_DECLSPEC SDL_Palette * SDLCALL SDL_CreatePalette(int ncolors);
* \param colors an array of SDL_Color structures to copy into the palette.
* \param firstcolor the index of the first palette entry to modify.
* \param ncolors the number of entries to modify.
* \returns SDL_TRUE on success or SDL_FALSE on failure; call SDL_GetError()
* for more information.
* \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, as long as
* the palette is not modified or destroyed in another thread.
*
* \since This function is available since SDL 3.0.0.
* \since This function is available since SDL 3.2.0.
*/
extern SDL_DECLSPEC SDL_bool SDLCALL SDL_SetPaletteColors(SDL_Palette *palette, const SDL_Color *colors, int firstcolor, int ncolors);
extern SDL_DECLSPEC bool SDLCALL SDL_SetPaletteColors(SDL_Palette *palette, const SDL_Color *colors, int firstcolor, int ncolors);
/**
* Free a palette created with SDL_CreatePalette().
@ -837,7 +1285,7 @@ extern SDL_DECLSPEC SDL_bool SDLCALL SDL_SetPaletteColors(SDL_Palette *palette,
* \threadsafety It is safe to call this function from any thread, as long as
* the palette is not modified or destroyed in another thread.
*
* \since This function is available since SDL 3.0.0.
* \since This function is available since SDL 3.2.0.
*
* \sa SDL_CreatePalette
*/
@ -872,7 +1320,7 @@ extern SDL_DECLSPEC void SDLCALL SDL_DestroyPalette(SDL_Palette *palette);
* \threadsafety It is safe to call this function from any thread, as long as
* the palette is not modified.
*
* \since This function is available since SDL 3.0.0.
* \since This function is available since SDL 3.2.0.
*
* \sa SDL_GetPixelFormatDetails
* \sa SDL_GetRGB
@ -911,7 +1359,7 @@ extern SDL_DECLSPEC Uint32 SDLCALL SDL_MapRGB(const SDL_PixelFormatDetails *form
* \threadsafety It is safe to call this function from any thread, as long as
* the palette is not modified.
*
* \since This function is available since SDL 3.0.0.
* \since This function is available since SDL 3.2.0.
*
* \sa SDL_GetPixelFormatDetails
* \sa SDL_GetRGBA
@ -939,7 +1387,7 @@ extern SDL_DECLSPEC Uint32 SDLCALL SDL_MapRGBA(const SDL_PixelFormatDetails *for
* \threadsafety It is safe to call this function from any thread, as long as
* the palette is not modified.
*
* \since This function is available since SDL 3.0.0.
* \since This function is available since SDL 3.2.0.
*
* \sa SDL_GetPixelFormatDetails
* \sa SDL_GetRGBA
@ -971,7 +1419,7 @@ extern SDL_DECLSPEC void SDLCALL SDL_GetRGB(Uint32 pixel, const SDL_PixelFormatD
* \threadsafety It is safe to call this function from any thread, as long as
* the palette is not modified.
*
* \since This function is available since SDL 3.0.0.
* \since This function is available since SDL 3.2.0.
*
* \sa SDL_GetPixelFormatDetails
* \sa SDL_GetRGB

View File

@ -1,6 +1,6 @@
/*
Simple DirectMedia Layer
Copyright (C) 1997-2024 Sam Lantinga <slouken@libsdl.org>
Copyright (C) 1997-2025 Sam Lantinga <slouken@libsdl.org>
This software is provided 'as-is', without any express or implied
warranty. In no event will the authors be held liable for any damages
@ -51,7 +51,7 @@ extern "C" {
* \returns the name of the platform. If the correct platform name is not
* available, returns a string beginning with the text "Unknown".
*
* \since This function is available since SDL 3.0.0.
* \since This function is available since SDL 3.2.0.
*/
extern SDL_DECLSPEC const char * SDLCALL SDL_GetPlatform(void);

View File

@ -1,6 +1,6 @@
/*
Simple DirectMedia Layer
Copyright (C) 1997-2024 Sam Lantinga <slouken@libsdl.org>
Copyright (C) 1997-2025 Sam Lantinga <slouken@libsdl.org>
This software is provided 'as-is', without any express or implied
warranty. In no event will the authors be held liable for any damages
@ -29,180 +29,450 @@
#define SDL_platform_defines_h_
#ifdef _AIX
#define SDL_PLATFORM_AIX 1
/**
* A preprocessor macro that is only defined if compiling for AIX.
*
* \since This macro is available since SDL 3.2.0.
*/
#define SDL_PLATFORM_AIX 1
#endif
#ifdef __HAIKU__
#define SDL_PLATFORM_HAIKU 1
/**
* A preprocessor macro that is only defined if compiling for Haiku OS.
*
* \since This macro is available since SDL 3.2.0.
*/
#define SDL_PLATFORM_HAIKU 1
#endif
#if defined(bsdi) || defined(__bsdi) || defined(__bsdi__)
#define SDL_PLATFORM_BSDI 1
/**
* A preprocessor macro that is only defined if compiling for BSDi
*
* \since This macro is available since SDL 3.2.0.
*/
#define SDL_PLATFORM_BSDI 1
#endif
#if defined(__FreeBSD__) || defined(__FreeBSD_kernel__) || defined(__DragonFly__)
/**
* A preprocessor macro that is only defined if compiling for FreeBSD.
*
* \since This macro is available since SDL 3.2.0.
*/
#define SDL_PLATFORM_FREEBSD 1
#endif
#if defined(hpux) || defined(__hpux) || defined(__hpux__)
#define SDL_PLATFORM_HPUX 1
/**
* A preprocessor macro that is only defined if compiling for HP-UX.
*
* \since This macro is available since SDL 3.2.0.
*/
#define SDL_PLATFORM_HPUX 1
#endif
#if defined(sgi) || defined(__sgi) || defined(__sgi__) || defined(_SGI_SOURCE)
#define SDL_PLATFORM_IRIX 1
/**
* A preprocessor macro that is only defined if compiling for IRIX.
*
* \since This macro is available since SDL 3.2.0.
*/
#define SDL_PLATFORM_IRIX 1
#endif
#if (defined(linux) || defined(__linux) || defined(__linux__))
#define SDL_PLATFORM_LINUX 1
/**
* A preprocessor macro that is only defined if compiling for Linux.
*
* Note that Android, although ostensibly a Linux-based system, will not
* define this. It defines SDL_PLATFORM_ANDROID instead.
*
* \since This macro is available since SDL 3.2.0.
*/
#define SDL_PLATFORM_LINUX 1
#endif
#if defined(ANDROID) || defined(__ANDROID__)
#undef SDL_PLATFORM_LINUX /* do we need to do this? */
#define SDL_PLATFORM_ANDROID 1
#endif
#ifdef __NGAGE__
#define SDL_PLATFORM_NGAGE 1
/**
* A preprocessor macro that is only defined if compiling for Android.
*
* \since This macro is available since SDL 3.2.0.
*/
#define SDL_PLATFORM_ANDROID 1
#undef SDL_PLATFORM_LINUX
#endif
#if defined(__unix__) || defined(__unix) || defined(unix)
#define SDL_PLATFORM_UNIX 1
/**
* A preprocessor macro that is only defined if compiling for a Unix-like
* system.
*
* Other platforms, like Linux, might define this in addition to their primary
* define.
*
* \since This macro is available since SDL 3.2.0.
*/
#define SDL_PLATFORM_UNIX 1
#endif
#ifdef __APPLE__
#define SDL_PLATFORM_APPLE 1
/**
* A preprocessor macro that is only defined if compiling for Apple platforms.
*
* iOS, macOS, etc will additionally define a more specific platform macro.
*
* \since This macro is available since SDL 3.2.0.
*
* \sa SDL_PLATFORM_MACOS
* \sa SDL_PLATFORM_IOS
* \sa SDL_PLATFORM_TVOS
* \sa SDL_PLATFORM_VISIONOS
*/
#define SDL_PLATFORM_APPLE 1
/* lets us know what version of macOS we're compiling on */
#include <AvailabilityMacros.h>
#ifndef __has_extension /* Older compilers don't support this */
#define __has_extension(x) 0
#include <TargetConditionals.h>
#undef __has_extension
#define __has_extension(x) 0
#include <TargetConditionals.h>
#undef __has_extension
#else
#include <TargetConditionals.h>
#include <TargetConditionals.h>
#endif
/* Fix building with older SDKs that don't define these
See this for more information:
https://stackoverflow.com/questions/12132933/preprocessor-macro-for-os-x-targets
See this for more information:
https://stackoverflow.com/questions/12132933/preprocessor-macro-for-os-x-targets
*/
#ifndef TARGET_OS_MACCATALYST
#define TARGET_OS_MACCATALYST 0
#define TARGET_OS_MACCATALYST 0
#endif
#ifndef TARGET_OS_IOS
#define TARGET_OS_IOS 0
#define TARGET_OS_IOS 0
#endif
#ifndef TARGET_OS_IPHONE
#define TARGET_OS_IPHONE 0
#define TARGET_OS_IPHONE 0
#endif
#ifndef TARGET_OS_TV
#define TARGET_OS_TV 0
#define TARGET_OS_TV 0
#endif
#ifndef TARGET_OS_SIMULATOR
#define TARGET_OS_SIMULATOR 0
#define TARGET_OS_SIMULATOR 0
#endif
#ifndef TARGET_OS_VISION
#define TARGET_OS_VISION 0
#define TARGET_OS_VISION 0
#endif
#if TARGET_OS_TV
#define SDL_PLATFORM_TVOS 1
/**
* A preprocessor macro that is only defined if compiling for tvOS.
*
* \since This macro is available since SDL 3.2.0.
*
* \sa SDL_PLATFORM_APPLE
*/
#define SDL_PLATFORM_TVOS 1
#endif
#if TARGET_OS_VISION
/**
* A preprocessor macro that is only defined if compiling for VisionOS.
*
* \since This macro is available since SDL 3.2.0.
*
* \sa SDL_PLATFORM_APPLE
*/
#define SDL_PLATFORM_VISIONOS 1
#endif
#if TARGET_OS_IPHONE
#define SDL_PLATFORM_IOS 1
/**
* A preprocessor macro that is only defined if compiling for iOS.
*
* \since This macro is available since SDL 3.2.0.
*
* \sa SDL_PLATFORM_APPLE
*/
#define SDL_PLATFORM_IOS 1
#else
#define SDL_PLATFORM_MACOS 1
/**
* A preprocessor macro that is only defined if compiling for macOS.
*
* \since This macro is available since SDL 3.2.0.
*
* \sa SDL_PLATFORM_APPLE
*/
#define SDL_PLATFORM_MACOS 1
#if MAC_OS_X_VERSION_MIN_REQUIRED < 1070
# error SDL for macOS only supports deploying on 10.7 and above.
#error SDL for macOS only supports deploying on 10.7 and above.
#endif /* MAC_OS_X_VERSION_MIN_REQUIRED < 1070 */
#endif /* TARGET_OS_IPHONE */
#endif /* defined(SDL_PLATFORM_APPLE) */
#endif /* defined(__APPLE__) */
#ifdef __EMSCRIPTEN__
/**
* A preprocessor macro that is only defined if compiling for Emscripten.
*
* \since This macro is available since SDL 3.2.0.
*/
#define SDL_PLATFORM_EMSCRIPTEN 1
#endif
#ifdef __NetBSD__
/**
* A preprocessor macro that is only defined if compiling for NetBSD.
*
* \since This macro is available since SDL 3.2.0.
*/
#define SDL_PLATFORM_NETBSD 1
#endif
#ifdef __OpenBSD__
#define SDL_PLATFORM_OPENBSD 1
/**
* A preprocessor macro that is only defined if compiling for OpenBSD.
*
* \since This macro is available since SDL 3.2.0.
*/
#define SDL_PLATFORM_OPENBSD 1
#endif
#if defined(__OS2__) || defined(__EMX__)
#define SDL_PLATFORM_OS2 1
/**
* A preprocessor macro that is only defined if compiling for OS/2.
*
* \since This macro is available since SDL 3.2.0.
*/
#define SDL_PLATFORM_OS2 1
#endif
#if defined(osf) || defined(__osf) || defined(__osf__) || defined(_OSF_SOURCE)
#define SDL_PLATFORM_OSF 1
/**
* A preprocessor macro that is only defined if compiling for Tru64 (OSF/1).
*
* \since This macro is available since SDL 3.2.0.
*/
#define SDL_PLATFORM_OSF 1
#endif
#ifdef __QNXNTO__
/**
* A preprocessor macro that is only defined if compiling for QNX Neutrino.
*
* \since This macro is available since SDL 3.2.0.
*/
#define SDL_PLATFORM_QNXNTO 1
#endif
#if defined(riscos) || defined(__riscos) || defined(__riscos__)
/**
* A preprocessor macro that is only defined if compiling for RISC OS.
*
* \since This macro is available since SDL 3.2.0.
*/
#define SDL_PLATFORM_RISCOS 1
#endif
#if defined(__sun) && defined(__SVR4)
#define SDL_PLATFORM_SOLARIS 1
/**
* A preprocessor macro that is only defined if compiling for SunOS/Solaris.
*
* \since This macro is available since SDL 3.2.0.
*/
#define SDL_PLATFORM_SOLARIS 1
#endif
#if defined(__CYGWIN__)
/**
* A preprocessor macro that is only defined if compiling for Cygwin.
*
* \since This macro is available since SDL 3.2.0.
*/
#define SDL_PLATFORM_CYGWIN 1
#endif
#if defined(_WIN32) || defined(SDL_PLATFORM_CYGWIN)
#define SDL_PLATFORM_WINDOWS 1 /* Win32 api and Windows-based OSs */
/**
* A preprocessor macro that is only defined if compiling for Windows.
*
* This also covers several other platforms, like Microsoft GDK, Xbox, WinRT,
* etc. Each will have their own more-specific platform macros, too.
*
* \since This macro is available since SDL 3.2.0.
*
* \sa SDL_PLATFORM_WIN32
* \sa SDL_PLATFORM_XBOXONE
* \sa SDL_PLATFORM_XBOXSERIES
* \sa SDL_PLATFORM_WINGDK
* \sa SDL_PLATFORM_GDK
*/
#define SDL_PLATFORM_WINDOWS 1
/* Try to find out if we're compiling for WinRT, GDK or non-WinRT/GDK */
#if defined(_MSC_VER) && defined(__has_include)
#if __has_include(<winapifamily.h>)
#define HAVE_WINAPIFAMILY_H 1
#else
#define HAVE_WINAPIFAMILY_H 0
#endif
#if __has_include(<winapifamily.h>)
#define HAVE_WINAPIFAMILY_H 1
#else
#define HAVE_WINAPIFAMILY_H 0
#endif
/* If _USING_V110_SDK71_ is defined it means we are using the Windows XP toolset. */
/* If _USING_V110_SDK71_ is defined it means we are using the Windows XP toolset. */
#elif defined(_MSC_VER) && (_MSC_VER >= 1700 && !_USING_V110_SDK71_) /* _MSC_VER == 1700 for Visual Studio 2012 */
#define HAVE_WINAPIFAMILY_H 1
#define HAVE_WINAPIFAMILY_H 1
#else
#define HAVE_WINAPIFAMILY_H 0
#define HAVE_WINAPIFAMILY_H 0
#endif
#if HAVE_WINAPIFAMILY_H
#include <winapifamily.h>
#define WINAPI_FAMILY_WINRT (!WINAPI_FAMILY_PARTITION(WINAPI_PARTITION_DESKTOP) && WINAPI_FAMILY_PARTITION(WINAPI_PARTITION_APP))
#include <winapifamily.h>
#define WINAPI_FAMILY_WINRT (!WINAPI_FAMILY_PARTITION(WINAPI_PARTITION_DESKTOP) && WINAPI_FAMILY_PARTITION(WINAPI_PARTITION_APP))
#else
#define WINAPI_FAMILY_WINRT 0
#define WINAPI_FAMILY_WINRT 0
#endif /* HAVE_WINAPIFAMILY_H */
#if HAVE_WINAPIFAMILY_H && HAVE_WINAPIFAMILY_H
#ifdef SDL_WIKI_DOCUMENTATION_SECTION
/**
* A preprocessor macro that defined to 1 if compiling for Windows Phone.
*
* \since This macro is available since SDL 3.2.0.
*/
#define SDL_WINAPI_FAMILY_PHONE (WINAPI_FAMILY == WINAPI_FAMILY_PHONE_APP)
#elif defined(HAVE_WINAPIFAMILY_H) && HAVE_WINAPIFAMILY_H
#define SDL_WINAPI_FAMILY_PHONE (WINAPI_FAMILY == WINAPI_FAMILY_PHONE_APP)
#else
#define SDL_WINAPI_FAMILY_PHONE 0
#define SDL_WINAPI_FAMILY_PHONE 0
#endif
#if WINAPI_FAMILY_WINRT
#define SDL_PLATFORM_WINRT 1
#error Windows RT/UWP is no longer supported in SDL
#elif defined(_GAMING_DESKTOP) /* GDK project configuration always defines _GAMING_XXX */
/**
* A preprocessor macro that is only defined if compiling for Microsoft GDK
* for Windows.
*
* \since This macro is available since SDL 3.2.0.
*/
#define SDL_PLATFORM_WINGDK 1
#elif defined(_GAMING_XBOX_XBOXONE)
#define SDL_PLATFORM_XBOXONE 1
/**
* A preprocessor macro that is only defined if compiling for Xbox One.
*
* \since This macro is available since SDL 3.2.0.
*/
#define SDL_PLATFORM_XBOXONE 1
#elif defined(_GAMING_XBOX_SCARLETT)
/**
* A preprocessor macro that is only defined if compiling for Xbox Series.
*
* \since This macro is available since SDL 3.2.0.
*/
#define SDL_PLATFORM_XBOXSERIES 1
#else
#define SDL_PLATFORM_WIN32 1
/**
* A preprocessor macro that is only defined if compiling for desktop Windows.
*
* Despite the "32", this also covers 64-bit Windows; as an informal
* convention, its system layer tends to still be referred to as "the Win32
* API."
*
* \since This macro is available since SDL 3.2.0.
*/
#define SDL_PLATFORM_WIN32 1
#endif
#endif /* defined(WIN32) || defined(_WIN32) || defined(SDL_PLATFORM_CYGWIN) */
#endif /* defined(_WIN32) || defined(SDL_PLATFORM_CYGWIN) */
/* This is to support generic "any GDK" separate from a platform-specific GDK */
#if defined(SDL_PLATFORM_WINGDK) || defined(SDL_PLATFORM_XBOXONE) || defined(SDL_PLATFORM_XBOXSERIES)
#define SDL_PLATFORM_GDK 1
/**
* A preprocessor macro that is only defined if compiling for Microsoft GDK on
* any platform.
*
* \since This macro is available since SDL 3.2.0.
*/
#define SDL_PLATFORM_GDK 1
#endif
#if defined(__PSP__) || defined(__psp__)
#define SDL_PLATFORM_PSP 1
/**
* A preprocessor macro that is only defined if compiling for Sony PSP.
*
* \since This macro is available since SDL 3.2.0.
*/
#define SDL_PLATFORM_PSP 1
#endif
#if defined(__PS2__) || defined(PS2)
#define SDL_PLATFORM_PS2 1
/**
* A preprocessor macro that is only defined if compiling for Sony PlayStation
* 2.
*
* \since This macro is available since SDL 3.2.0.
*/
#define SDL_PLATFORM_PS2 1
#endif
#if defined(__vita__) || defined(__psp2__)
#define SDL_PLATFORM_VITA 1
/**
* A preprocessor macro that is only defined if compiling for Sony Vita.
*
* \since This macro is available since SDL 3.2.0.
*/
#define SDL_PLATFORM_VITA 1
#endif
#ifdef __3DS__
/**
* A preprocessor macro that is only defined if compiling for Nintendo 3DS.
*
* \since This macro is available since SDL 3.2.0.
*/
#define SDL_PLATFORM_3DS 1
#undef __3DS__
#define SDL_PLATFORM_3DS 1
#endif
#endif /* SDL_platform_defines_h_ */

View File

@ -1,6 +1,6 @@
/*
Simple DirectMedia Layer
Copyright (C) 1997-2024 Sam Lantinga <slouken@libsdl.org>
Copyright (C) 1997-2025 Sam Lantinga <slouken@libsdl.org>
This software is provided 'as-is', without any express or implied
warranty. In no event will the authors be held liable for any damages
@ -26,6 +26,15 @@
* # CategoryPower
*
* SDL power management routines.
*
* There is a single function in this category: SDL_GetPowerInfo().
*
* This function is useful for games on the go. This allows an app to know if
* it's running on a draining battery, which can be useful if the app wants to
* reduce processing, or perhaps framerate, to extend the duration of the
* battery's charge. Perhaps the app just wants to show a battery meter when
* fullscreen, or alert the user when the power is getting extremely low, so
* they can save their game.
*/
#include <SDL3/SDL_stdinc.h>
@ -42,7 +51,7 @@ extern "C" {
*
* These are results returned by SDL_GetPowerInfo().
*
* \since This enum is available since SDL 3.0.0
* \since This enum is available since SDL 3.2.0.
*/
typedef enum SDL_PowerState
{
@ -80,7 +89,7 @@ typedef enum SDL_PowerState
* \returns the current battery state or `SDL_POWERSTATE_ERROR` on failure;
* call SDL_GetError() for more information.
*
* \since This function is available since SDL 3.0.0.
* \since This function is available since SDL 3.2.0.
*/
extern SDL_DECLSPEC SDL_PowerState SDLCALL SDL_GetPowerInfo(int *seconds, int *percent);

View File

@ -0,0 +1,430 @@
/*
Simple DirectMedia Layer
Copyright (C) 1997-2025 Sam Lantinga <slouken@libsdl.org>
This software is provided 'as-is', without any express or implied
warranty. In no event will the authors be held liable for any damages
arising from the use of this software.
Permission is granted to anyone to use this software for any purpose,
including commercial applications, and to alter it and redistribute it
freely, subject to the following restrictions:
1. The origin of this software must not be misrepresented; you must not
claim that you wrote the original software. If you use this software
in a product, an acknowledgment in the product documentation would be
appreciated but is not required.
2. Altered source versions must be plainly marked as such, and must not be
misrepresented as being the original software.
3. This notice may not be removed or altered from any source distribution.
*/
/**
* # CategoryProcess
*
* Process control support.
*
* These functions provide a cross-platform way to spawn and manage OS-level
* processes.
*
* You can create a new subprocess with SDL_CreateProcess() and optionally
* read and write to it using SDL_ReadProcess() or SDL_GetProcessInput() and
* SDL_GetProcessOutput(). If more advanced functionality like chaining input
* between processes is necessary, you can use
* SDL_CreateProcessWithProperties().
*
* You can get the status of a created process with SDL_WaitProcess(), or
* terminate the process with SDL_KillProcess().
*
* Don't forget to call SDL_DestroyProcess() to clean up, whether the process
* process was killed, terminated on its own, or is still running!
*/
#ifndef SDL_process_h_
#define SDL_process_h_
#include <SDL3/SDL_stdinc.h>
#include <SDL3/SDL_error.h>
#include <SDL3/SDL_iostream.h>
#include <SDL3/SDL_properties.h>
#include <SDL3/SDL_begin_code.h>
/* Set up for C function definitions, even when using C++ */
#ifdef __cplusplus
extern "C" {
#endif
/**
* An opaque handle representing a system process.
*
* \since This datatype is available since SDL 3.2.0.
*
* \sa SDL_CreateProcess
*/
typedef struct SDL_Process SDL_Process;
/**
* Create a new process.
*
* The path to the executable is supplied in args[0]. args[1..N] are
* additional arguments passed on the command line of the new process, and the
* argument list should be terminated with a NULL, e.g.:
*
* ```c
* const char *args[] = { "myprogram", "argument", NULL };
* ```
*
* Setting pipe_stdio to true is equivalent to setting
* `SDL_PROP_PROCESS_CREATE_STDIN_NUMBER` and
* `SDL_PROP_PROCESS_CREATE_STDOUT_NUMBER` to `SDL_PROCESS_STDIO_APP`, and
* will allow the use of SDL_ReadProcess() or SDL_GetProcessInput() and
* SDL_GetProcessOutput().
*
* See SDL_CreateProcessWithProperties() for more details.
*
* \param args the path and arguments for the new process.
* \param pipe_stdio true to create pipes to the process's standard input and
* from the process's standard output, false for the process
* to have no input and inherit the application's standard
* output.
* \returns the newly created and running process, or NULL if the process
* couldn't be created.
*
* \threadsafety It is safe to call this function from any thread.
*
* \since This function is available since SDL 3.2.0.
*
* \sa SDL_CreateProcessWithProperties
* \sa SDL_GetProcessProperties
* \sa SDL_ReadProcess
* \sa SDL_GetProcessInput
* \sa SDL_GetProcessOutput
* \sa SDL_KillProcess
* \sa SDL_WaitProcess
* \sa SDL_DestroyProcess
*/
extern SDL_DECLSPEC SDL_Process *SDLCALL SDL_CreateProcess(const char * const *args, bool pipe_stdio);
/**
* Description of where standard I/O should be directed when creating a
* process.
*
* If a standard I/O stream is set to SDL_PROCESS_STDIO_INHERITED, it will go
* to the same place as the application's I/O stream. This is the default for
* standard output and standard error.
*
* If a standard I/O stream is set to SDL_PROCESS_STDIO_NULL, it is connected
* to `NUL:` on Windows and `/dev/null` on POSIX systems. This is the default
* for standard input.
*
* If a standard I/O stream is set to SDL_PROCESS_STDIO_APP, it is connected
* to a new SDL_IOStream that is available to the application. Standard input
* will be available as `SDL_PROP_PROCESS_STDIN_POINTER` and allows
* SDL_GetProcessInput(), standard output will be available as
* `SDL_PROP_PROCESS_STDOUT_POINTER` and allows SDL_ReadProcess() and
* SDL_GetProcessOutput(), and standard error will be available as
* `SDL_PROP_PROCESS_STDERR_POINTER` in the properties for the created
* process.
*
* If a standard I/O stream is set to SDL_PROCESS_STDIO_REDIRECT, it is
* connected to an existing SDL_IOStream provided by the application. Standard
* input is provided using `SDL_PROP_PROCESS_CREATE_STDIN_POINTER`, standard
* output is provided using `SDL_PROP_PROCESS_CREATE_STDOUT_POINTER`, and
* standard error is provided using `SDL_PROP_PROCESS_CREATE_STDERR_POINTER`
* in the creation properties. These existing streams should be closed by the
* application once the new process is created.
*
* In order to use an SDL_IOStream with SDL_PROCESS_STDIO_REDIRECT, it must
* have `SDL_PROP_IOSTREAM_WINDOWS_HANDLE_POINTER` or
* `SDL_PROP_IOSTREAM_FILE_DESCRIPTOR_NUMBER` set. This is true for streams
* representing files and process I/O.
*
* \since This enum is available since SDL 3.2.0.
*
* \sa SDL_CreateProcessWithProperties
* \sa SDL_GetProcessProperties
* \sa SDL_ReadProcess
* \sa SDL_GetProcessInput
* \sa SDL_GetProcessOutput
*/
typedef enum SDL_ProcessIO
{
SDL_PROCESS_STDIO_INHERITED, /**< The I/O stream is inherited from the application. */
SDL_PROCESS_STDIO_NULL, /**< The I/O stream is ignored. */
SDL_PROCESS_STDIO_APP, /**< The I/O stream is connected to a new SDL_IOStream that the application can read or write */
SDL_PROCESS_STDIO_REDIRECT /**< The I/O stream is redirected to an existing SDL_IOStream. */
} SDL_ProcessIO;
/**
* Create a new process with the specified properties.
*
* These are the supported properties:
*
* - `SDL_PROP_PROCESS_CREATE_ARGS_POINTER`: an array of strings containing
* the program to run, any arguments, and a NULL pointer, e.g. const char
* *args[] = { "myprogram", "argument", NULL }. This is a required property.
* - `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_STDIN_NUMBER`: an SDL_ProcessIO value describing
* where standard input for the process comes from, defaults to
* `SDL_PROCESS_STDIO_NULL`.
* - `SDL_PROP_PROCESS_CREATE_STDIN_POINTER`: an SDL_IOStream pointer used for
* standard input when `SDL_PROP_PROCESS_CREATE_STDIN_NUMBER` is set to
* `SDL_PROCESS_STDIO_REDIRECT`.
* - `SDL_PROP_PROCESS_CREATE_STDOUT_NUMBER`: an SDL_ProcessIO value
* describing where standard output for the process goes go, defaults to
* `SDL_PROCESS_STDIO_INHERITED`.
* - `SDL_PROP_PROCESS_CREATE_STDOUT_POINTER`: an SDL_IOStream pointer used
* for standard output when `SDL_PROP_PROCESS_CREATE_STDOUT_NUMBER` is set
* to `SDL_PROCESS_STDIO_REDIRECT`.
* - `SDL_PROP_PROCESS_CREATE_STDERR_NUMBER`: an SDL_ProcessIO value
* describing where standard error for the process goes go, defaults to
* `SDL_PROCESS_STDIO_INHERITED`.
* - `SDL_PROP_PROCESS_CREATE_STDERR_POINTER`: an SDL_IOStream pointer used
* for standard error when `SDL_PROP_PROCESS_CREATE_STDERR_NUMBER` is set to
* `SDL_PROCESS_STDIO_REDIRECT`.
* - `SDL_PROP_PROCESS_CREATE_STDERR_TO_STDOUT_BOOLEAN`: true if the error
* output of the process should be redirected into the standard output of
* the process. This property has no effect if
* `SDL_PROP_PROCESS_CREATE_STDERR_NUMBER` is set.
* - `SDL_PROP_PROCESS_CREATE_BACKGROUND_BOOLEAN`: true if the process should
* 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.
*
* On POSIX platforms, wait() and waitpid(-1, ...) should not be called, and
* SIGCHLD should not be ignored or handled because those would prevent SDL
* from properly tracking the lifetime of the underlying process. You should
* use SDL_WaitProcess() instead.
*
* \param props the properties to use.
* \returns the newly created and running process, or NULL if the process
* couldn't be created.
*
* \threadsafety It is safe to call this function from any thread.
*
* \since This function is available since SDL 3.2.0.
*
* \sa SDL_CreateProcess
* \sa SDL_GetProcessProperties
* \sa SDL_ReadProcess
* \sa SDL_GetProcessInput
* \sa SDL_GetProcessOutput
* \sa SDL_KillProcess
* \sa SDL_WaitProcess
* \sa SDL_DestroyProcess
*/
extern SDL_DECLSPEC SDL_Process *SDLCALL SDL_CreateProcessWithProperties(SDL_PropertiesID props);
#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_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"
#define SDL_PROP_PROCESS_CREATE_STDOUT_POINTER "SDL.process.create.stdout_source"
#define SDL_PROP_PROCESS_CREATE_STDERR_NUMBER "SDL.process.create.stderr_option"
#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"
/**
* Get the properties associated with a process.
*
* The following read-only properties are provided by SDL:
*
* - `SDL_PROP_PROCESS_PID_NUMBER`: the process ID of the process.
* - `SDL_PROP_PROCESS_STDIN_POINTER`: an SDL_IOStream that can be used to
* write input to the process, if it was created with
* `SDL_PROP_PROCESS_CREATE_STDIN_NUMBER` set to `SDL_PROCESS_STDIO_APP`.
* - `SDL_PROP_PROCESS_STDOUT_POINTER`: a non-blocking SDL_IOStream that can
* be used to read output from the process, if it was created with
* `SDL_PROP_PROCESS_CREATE_STDOUT_NUMBER` set to `SDL_PROCESS_STDIO_APP`.
* - `SDL_PROP_PROCESS_STDERR_POINTER`: a non-blocking SDL_IOStream that can
* be used to read error output from the process, if it was created with
* `SDL_PROP_PROCESS_CREATE_STDERR_NUMBER` set to `SDL_PROCESS_STDIO_APP`.
* - `SDL_PROP_PROCESS_BACKGROUND_BOOLEAN`: true if the process is running in
* the background.
*
* \param process the process to query.
* \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.
*
* \sa SDL_CreateProcess
* \sa SDL_CreateProcessWithProperties
*/
extern SDL_DECLSPEC SDL_PropertiesID SDLCALL SDL_GetProcessProperties(SDL_Process *process);
#define SDL_PROP_PROCESS_PID_NUMBER "SDL.process.pid"
#define SDL_PROP_PROCESS_STDIN_POINTER "SDL.process.stdin"
#define SDL_PROP_PROCESS_STDOUT_POINTER "SDL.process.stdout"
#define SDL_PROP_PROCESS_STDERR_POINTER "SDL.process.stderr"
#define SDL_PROP_PROCESS_BACKGROUND_BOOLEAN "SDL.process.background"
/**
* Read all the output from a process.
*
* If a process was created with I/O enabled, you can use this function to
* read the output. This function blocks until the process is complete,
* capturing all output, and providing the process exit code.
*
* The data is allocated with a zero byte at the end (null terminated) for
* convenience. This extra byte is not included in the value reported via
* `datasize`.
*
* The data should be freed with SDL_free().
*
* \param process The process to read.
* \param datasize a pointer filled in with the number of bytes read, may be
* NULL.
* \param exitcode a pointer filled in with the process exit code if the
* process has exited, may be NULL.
* \returns the data or NULL 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.
*
* \sa SDL_CreateProcess
* \sa SDL_CreateProcessWithProperties
* \sa SDL_DestroyProcess
*/
extern SDL_DECLSPEC void * SDLCALL SDL_ReadProcess(SDL_Process *process, size_t *datasize, int *exitcode);
/**
* Get the SDL_IOStream associated with process standard input.
*
* The process must have been created with SDL_CreateProcess() and pipe_stdio
* set to true, or with SDL_CreateProcessWithProperties() and
* `SDL_PROP_PROCESS_CREATE_STDIN_NUMBER` set to `SDL_PROCESS_STDIO_APP`.
*
* Writing to this stream can return less data than expected if the process
* hasn't read its input. It may be blocked waiting for its output to be read,
* if so you may need to call SDL_GetProcessOutput() and read the output in
* parallel with writing input.
*
* \param process The process to get the input stream for.
* \returns the input stream 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_CreateProcess
* \sa SDL_CreateProcessWithProperties
* \sa SDL_GetProcessOutput
*/
extern SDL_DECLSPEC SDL_IOStream *SDLCALL SDL_GetProcessInput(SDL_Process *process);
/**
* Get the SDL_IOStream associated with process standard output.
*
* The process must have been created with SDL_CreateProcess() and pipe_stdio
* set to true, or with SDL_CreateProcessWithProperties() and
* `SDL_PROP_PROCESS_CREATE_STDOUT_NUMBER` set to `SDL_PROCESS_STDIO_APP`.
*
* Reading from this stream can return 0 with SDL_GetIOStatus() returning
* SDL_IO_STATUS_NOT_READY if no output is available yet.
*
* \param process The process to get the output stream for.
* \returns the output stream 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_CreateProcess
* \sa SDL_CreateProcessWithProperties
* \sa SDL_GetProcessInput
*/
extern SDL_DECLSPEC SDL_IOStream *SDLCALL SDL_GetProcessOutput(SDL_Process *process);
/**
* Stop a process.
*
* \param process The process to stop.
* \param force true to terminate the process immediately, false to try to
* stop the process gracefully. In general you should try to stop
* the process gracefully first as terminating a process may
* leave it with half-written data or in some other unstable
* state.
* \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.
*
* \sa SDL_CreateProcess
* \sa SDL_CreateProcessWithProperties
* \sa SDL_WaitProcess
* \sa SDL_DestroyProcess
*/
extern SDL_DECLSPEC bool SDLCALL SDL_KillProcess(SDL_Process *process, bool force);
/**
* Wait for a process to finish.
*
* This can be called multiple times to get the status of a process.
*
* The exit code will be the exit code of the process if it terminates
* normally, a negative signal if it terminated due to a signal, or -255
* otherwise. It will not be changed if the process is still running.
*
* If you create a process with standard output piped to the application
* (`pipe_stdio` being true) then you should read all of the process output
* before calling SDL_WaitProcess(). If you don't do this the process might be
* blocked indefinitely waiting for output to be read and SDL_WaitProcess()
* will never return true;
*
* \param process The process to wait for.
* \param block If true, block until the process finishes; otherwise, report
* on the process' status.
* \param exitcode a pointer filled in with the process exit code if the
* process has exited, may be NULL.
* \returns true if the process exited, false otherwise.
*
* \threadsafety This function is not thread safe.
*
* \since This function is available since SDL 3.2.0.
*
* \sa SDL_CreateProcess
* \sa SDL_CreateProcessWithProperties
* \sa SDL_KillProcess
* \sa SDL_DestroyProcess
*/
extern SDL_DECLSPEC bool SDLCALL SDL_WaitProcess(SDL_Process *process, bool block, int *exitcode);
/**
* Destroy a previously created process object.
*
* Note that this does not stop the process, just destroys the SDL object used
* to track it. If you want to stop the process you should use
* SDL_KillProcess().
*
* \param process The process object to destroy.
*
* \threadsafety This function is not thread safe.
*
* \since This function is available since SDL 3.2.0.
*
* \sa SDL_CreateProcess
* \sa SDL_CreateProcessWithProperties
* \sa SDL_KillProcess
*/
extern SDL_DECLSPEC void SDLCALL SDL_DestroyProcess(SDL_Process *process);
/* Ends C function definitions when using C++ */
#ifdef __cplusplus
}
#endif
#include <SDL3/SDL_close_code.h>
#endif /* SDL_process_h_ */

View File

@ -1,6 +1,6 @@
/*
Simple DiretMedia Layer
Copyright (C) 1997-2024 Sam Lantinga <slouken@libsdl.org>
Simple DirectMedia Layer
Copyright (C) 1997-2025 Sam Lantinga <slouken@libsdl.org>
This software is provided 'as-is', without any express or implied
warranty. In no event will the authors be held liable for any damages
@ -61,14 +61,14 @@ extern "C" {
/**
* SDL properties ID
*
* \since This datatype is available since SDL 3.0.0.
* \since This datatype is available since SDL 3.2.0.
*/
typedef Uint32 SDL_PropertiesID;
/**
* SDL property type
*
* \since This enum is available since SDL 3.0.0.
* \since This enum is available since SDL 3.2.0.
*/
typedef enum SDL_PropertyType
{
@ -86,7 +86,7 @@ typedef enum SDL_PropertyType
* \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.0.0.
* \since This function is available since SDL 3.2.0.
*/
extern SDL_DECLSPEC SDL_PropertiesID SDLCALL SDL_GetGlobalProperties(void);
@ -100,7 +100,7 @@ extern SDL_DECLSPEC SDL_PropertiesID SDLCALL SDL_GetGlobalProperties(void);
*
* \threadsafety It is safe to call this function from any thread.
*
* \since This function is available since SDL 3.0.0.
* \since This function is available since SDL 3.2.0.
*
* \sa SDL_DestroyProperties
*/
@ -116,14 +116,14 @@ extern SDL_DECLSPEC SDL_PropertiesID SDLCALL SDL_CreateProperties(void);
*
* \param src the properties to copy.
* \param dst the destination properties.
* \returns SDL_TRUE on success or SDL_FALSE on failure; call SDL_GetError()
* for more information.
* \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.0.0.
* \since This function is available since SDL 3.2.0.
*/
extern SDL_DECLSPEC SDL_bool SDLCALL SDL_CopyProperties(SDL_PropertiesID src, SDL_PropertiesID dst);
extern SDL_DECLSPEC bool SDLCALL SDL_CopyProperties(SDL_PropertiesID src, SDL_PropertiesID dst);
/**
* Lock a group of properties.
@ -138,16 +138,16 @@ extern SDL_DECLSPEC SDL_bool SDLCALL SDL_CopyProperties(SDL_PropertiesID src, SD
* thread.
*
* \param props the properties to lock.
* \returns SDL_TRUE on success or SDL_FALSE on failure; call SDL_GetError()
* for more information.
* \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.0.0.
* \since This function is available since SDL 3.2.0.
*
* \sa SDL_UnlockProperties
*/
extern SDL_DECLSPEC SDL_bool SDLCALL SDL_LockProperties(SDL_PropertiesID props);
extern SDL_DECLSPEC bool SDLCALL SDL_LockProperties(SDL_PropertiesID props);
/**
* Unlock a group of properties.
@ -156,7 +156,7 @@ extern SDL_DECLSPEC SDL_bool SDLCALL SDL_LockProperties(SDL_PropertiesID props);
*
* \threadsafety It is safe to call this function from any thread.
*
* \since This function is available since SDL 3.0.0.
* \since This function is available since SDL 3.2.0.
*
* \sa SDL_LockProperties
*/
@ -180,7 +180,7 @@ extern SDL_DECLSPEC void SDLCALL SDL_UnlockProperties(SDL_PropertiesID props);
* \threadsafety This callback may fire without any locks held; if this is a
* concern, the app should provide its own locking.
*
* \since This datatype is available since SDL 3.0.0.
* \since This datatype is available since SDL 3.2.0.
*
* \sa SDL_SetPointerPropertyWithCleanup
*/
@ -204,18 +204,18 @@ typedef void (SDLCALL *SDL_CleanupPropertyCallback)(void *userdata, void *value)
* \param cleanup the function to call when this property is deleted, or NULL
* if no cleanup is necessary.
* \param userdata a pointer that is passed to the cleanup function.
* \returns SDL_TRUE on success or SDL_FALSE on failure; call SDL_GetError()
* for more information.
* \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.0.0.
* \since This function is available since SDL 3.2.0.
*
* \sa SDL_GetPointerProperty
* \sa SDL_SetPointerProperty
* \sa SDL_CleanupPropertyCallback
*/
extern SDL_DECLSPEC SDL_bool SDLCALL SDL_SetPointerPropertyWithCleanup(SDL_PropertiesID props, const char *name, void *value, SDL_CleanupPropertyCallback cleanup, void *userdata);
extern SDL_DECLSPEC bool SDLCALL SDL_SetPointerPropertyWithCleanup(SDL_PropertiesID props, const char *name, void *value, SDL_CleanupPropertyCallback cleanup, void *userdata);
/**
* Set a pointer property in a group of properties.
@ -223,12 +223,12 @@ extern SDL_DECLSPEC SDL_bool SDLCALL SDL_SetPointerPropertyWithCleanup(SDL_Prope
* \param props the properties to modify.
* \param name the name of the property to modify.
* \param value the new value of the property, or NULL to delete the property.
* \returns SDL_TRUE on success or SDL_FALSE on failure; call SDL_GetError()
* for more information.
* \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.0.0.
* \since This function is available since SDL 3.2.0.
*
* \sa SDL_GetPointerProperty
* \sa SDL_HasProperty
@ -238,7 +238,7 @@ extern SDL_DECLSPEC SDL_bool SDLCALL SDL_SetPointerPropertyWithCleanup(SDL_Prope
* \sa SDL_SetPointerPropertyWithCleanup
* \sa SDL_SetStringProperty
*/
extern SDL_DECLSPEC SDL_bool SDLCALL SDL_SetPointerProperty(SDL_PropertiesID props, const char *name, void *value);
extern SDL_DECLSPEC bool SDLCALL SDL_SetPointerProperty(SDL_PropertiesID props, const char *name, void *value);
/**
* Set a string property in a group of properties.
@ -249,16 +249,16 @@ extern SDL_DECLSPEC SDL_bool SDLCALL SDL_SetPointerProperty(SDL_PropertiesID pro
* \param props the properties to modify.
* \param name the name of the property to modify.
* \param value the new value of the property, or NULL to delete the property.
* \returns SDL_TRUE on success or SDL_FALSE on failure; call SDL_GetError()
* for more information.
* \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.0.0.
* \since This function is available since SDL 3.2.0.
*
* \sa SDL_GetStringProperty
*/
extern SDL_DECLSPEC SDL_bool SDLCALL SDL_SetStringProperty(SDL_PropertiesID props, const char *name, const char *value);
extern SDL_DECLSPEC bool SDLCALL SDL_SetStringProperty(SDL_PropertiesID props, const char *name, const char *value);
/**
* Set an integer property in a group of properties.
@ -266,16 +266,16 @@ extern SDL_DECLSPEC SDL_bool SDLCALL SDL_SetStringProperty(SDL_PropertiesID prop
* \param props the properties to modify.
* \param name the name of the property to modify.
* \param value the new value of the property.
* \returns SDL_TRUE on success or SDL_FALSE on failure; call SDL_GetError()
* for more information.
* \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.0.0.
* \since This function is available since SDL 3.2.0.
*
* \sa SDL_GetNumberProperty
*/
extern SDL_DECLSPEC SDL_bool SDLCALL SDL_SetNumberProperty(SDL_PropertiesID props, const char *name, Sint64 value);
extern SDL_DECLSPEC bool SDLCALL SDL_SetNumberProperty(SDL_PropertiesID props, const char *name, Sint64 value);
/**
* Set a floating point property in a group of properties.
@ -283,16 +283,16 @@ extern SDL_DECLSPEC SDL_bool SDLCALL SDL_SetNumberProperty(SDL_PropertiesID prop
* \param props the properties to modify.
* \param name the name of the property to modify.
* \param value the new value of the property.
* \returns SDL_TRUE on success or SDL_FALSE on failure; call SDL_GetError()
* for more information.
* \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.0.0.
* \since This function is available since SDL 3.2.0.
*
* \sa SDL_GetFloatProperty
*/
extern SDL_DECLSPEC SDL_bool SDLCALL SDL_SetFloatProperty(SDL_PropertiesID props, const char *name, float value);
extern SDL_DECLSPEC bool SDLCALL SDL_SetFloatProperty(SDL_PropertiesID props, const char *name, float value);
/**
* Set a boolean property in a group of properties.
@ -300,31 +300,31 @@ extern SDL_DECLSPEC SDL_bool SDLCALL SDL_SetFloatProperty(SDL_PropertiesID props
* \param props the properties to modify.
* \param name the name of the property to modify.
* \param value the new value of the property.
* \returns SDL_TRUE on success or SDL_FALSE on failure; call SDL_GetError()
* for more information.
* \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.0.0.
* \since This function is available since SDL 3.2.0.
*
* \sa SDL_GetBooleanProperty
*/
extern SDL_DECLSPEC SDL_bool SDLCALL SDL_SetBooleanProperty(SDL_PropertiesID props, const char *name, SDL_bool value);
extern SDL_DECLSPEC bool SDLCALL SDL_SetBooleanProperty(SDL_PropertiesID props, const char *name, bool value);
/**
* Return whether a property exists in a group of properties.
*
* \param props the properties to query.
* \param name the name of the property to query.
* \returns SDL_TRUE if the property exists, or SDL_FALSE if it doesn't.
* \returns true if the property exists, or false if it doesn't.
*
* \threadsafety It is safe to call this function from any thread.
*
* \since This function is available since SDL 3.0.0.
* \since This function is available since SDL 3.2.0.
*
* \sa SDL_GetPropertyType
*/
extern SDL_DECLSPEC SDL_bool SDLCALL SDL_HasProperty(SDL_PropertiesID props, const char *name);
extern SDL_DECLSPEC bool SDLCALL SDL_HasProperty(SDL_PropertiesID props, const char *name);
/**
* Get the type of a property in a group of properties.
@ -336,7 +336,7 @@ extern SDL_DECLSPEC SDL_bool SDLCALL SDL_HasProperty(SDL_PropertiesID props, con
*
* \threadsafety It is safe to call this function from any thread.
*
* \since This function is available since SDL 3.0.0.
* \since This function is available since SDL 3.2.0.
*
* \sa SDL_HasProperty
*/
@ -363,7 +363,7 @@ extern SDL_DECLSPEC SDL_PropertyType SDLCALL SDL_GetPropertyType(SDL_PropertiesI
* If you need to avoid this, use SDL_LockProperties() and
* SDL_UnlockProperties().
*
* \since This function is available since SDL 3.0.0.
* \since This function is available since SDL 3.2.0.
*
* \sa SDL_GetBooleanProperty
* \sa SDL_GetFloatProperty
@ -391,7 +391,7 @@ extern SDL_DECLSPEC void * SDLCALL SDL_GetPointerProperty(SDL_PropertiesID props
* If you need to avoid this, use SDL_LockProperties() and
* SDL_UnlockProperties().
*
* \since This function is available since SDL 3.0.0.
* \since This function is available since SDL 3.2.0.
*
* \sa SDL_GetPropertyType
* \sa SDL_HasProperty
@ -413,7 +413,7 @@ extern SDL_DECLSPEC const char * SDLCALL SDL_GetStringProperty(SDL_PropertiesID
*
* \threadsafety It is safe to call this function from any thread.
*
* \since This function is available since SDL 3.0.0.
* \since This function is available since SDL 3.2.0.
*
* \sa SDL_GetPropertyType
* \sa SDL_HasProperty
@ -435,7 +435,7 @@ extern SDL_DECLSPEC Sint64 SDLCALL SDL_GetNumberProperty(SDL_PropertiesID props,
*
* \threadsafety It is safe to call this function from any thread.
*
* \since This function is available since SDL 3.0.0.
* \since This function is available since SDL 3.2.0.
*
* \sa SDL_GetPropertyType
* \sa SDL_HasProperty
@ -457,27 +457,27 @@ extern SDL_DECLSPEC float SDLCALL SDL_GetFloatProperty(SDL_PropertiesID props, c
*
* \threadsafety It is safe to call this function from any thread.
*
* \since This function is available since SDL 3.0.0.
* \since This function is available since SDL 3.2.0.
*
* \sa SDL_GetPropertyType
* \sa SDL_HasProperty
* \sa SDL_SetBooleanProperty
*/
extern SDL_DECLSPEC SDL_bool SDLCALL SDL_GetBooleanProperty(SDL_PropertiesID props, const char *name, SDL_bool default_value);
extern SDL_DECLSPEC bool SDLCALL SDL_GetBooleanProperty(SDL_PropertiesID props, const char *name, bool default_value);
/**
* Clear a property from a group of properties.
*
* \param props the properties to modify.
* \param name the name of the property to clear.
* \returns SDL_TRUE on success or SDL_FALSE on failure; call SDL_GetError()
* for more information.
* \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.0.0.
* \since This function is available since SDL 3.2.0.
*/
extern SDL_DECLSPEC SDL_bool SDLCALL SDL_ClearProperty(SDL_PropertiesID props, const char *name);
extern SDL_DECLSPEC bool SDLCALL SDL_ClearProperty(SDL_PropertiesID props, const char *name);
/**
* A callback used to enumerate all the properties in a group of properties.
@ -492,7 +492,7 @@ extern SDL_DECLSPEC SDL_bool SDLCALL SDL_ClearProperty(SDL_PropertiesID props, c
* \threadsafety SDL_EnumerateProperties holds a lock on `props` during this
* callback.
*
* \since This datatype is available since SDL 3.0.0.
* \since This datatype is available since SDL 3.2.0.
*
* \sa SDL_EnumerateProperties
*/
@ -507,14 +507,14 @@ typedef void (SDLCALL *SDL_EnumeratePropertiesCallback)(void *userdata, SDL_Prop
* \param props the properties to query.
* \param callback the function to call for each property.
* \param userdata a pointer that is passed to `callback`.
* \returns SDL_TRUE on success or SDL_FALSE on failure; call SDL_GetError()
* for more information.
* \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.0.0.
* \since This function is available since SDL 3.2.0.
*/
extern SDL_DECLSPEC SDL_bool SDLCALL SDL_EnumerateProperties(SDL_PropertiesID props, SDL_EnumeratePropertiesCallback callback, void *userdata);
extern SDL_DECLSPEC bool SDLCALL SDL_EnumerateProperties(SDL_PropertiesID props, SDL_EnumeratePropertiesCallback callback, void *userdata);
/**
* Destroy a group of properties.
@ -528,7 +528,7 @@ extern SDL_DECLSPEC SDL_bool SDLCALL SDL_EnumerateProperties(SDL_PropertiesID pr
* locked or other threads might be setting or getting values
* from these properties.
*
* \since This function is available since SDL 3.0.0.
* \since This function is available since SDL 3.2.0.
*
* \sa SDL_CreateProperties
*/

View File

@ -1,6 +1,6 @@
/*
Simple DirectMedia Layer
Copyright (C) 1997-2024 Sam Lantinga <slouken@libsdl.org>
Copyright (C) 1997-2025 Sam Lantinga <slouken@libsdl.org>
This software is provided 'as-is', without any express or implied
warranty. In no event will the authors be held liable for any damages
@ -23,7 +23,7 @@
* # CategoryRect
*
* Some helper functions for managing rectangles and 2D points, in both
* interger and floating point versions.
* integer and floating point versions.
*/
#ifndef SDL_rect_h_
@ -41,7 +41,7 @@ extern "C" {
/**
* The structure that defines a point (using integers).
*
* \since This struct is available since SDL 3.0.0.
* \since This struct is available since SDL 3.2.0.
*
* \sa SDL_GetRectEnclosingPoints
* \sa SDL_PointInRect
@ -55,7 +55,7 @@ typedef struct SDL_Point
/**
* The structure that defines a point (using floating point values).
*
* \since This struct is available since SDL 3.0.0.
* \since This struct is available since SDL 3.2.0.
*
* \sa SDL_GetRectEnclosingPointsFloat
* \sa SDL_PointInRectFloat
@ -70,7 +70,7 @@ typedef struct SDL_FPoint
/**
* A rectangle, with the origin at the upper left (using integers).
*
* \since This struct is available since SDL 3.0.0.
* \since This struct is available since SDL 3.2.0.
*
* \sa SDL_RectEmpty
* \sa SDL_RectsEqual
@ -91,7 +91,7 @@ typedef struct SDL_Rect
* A rectangle, with the origin at the upper left (using floating point
* values).
*
* \since This struct is available since SDL 3.0.0.
* \since This struct is available since SDL 3.2.0.
*
* \sa SDL_RectEmptyFloat
* \sa SDL_RectsEqualFloat
@ -121,7 +121,7 @@ typedef struct SDL_FRect
*
* \threadsafety It is safe to call this function from any thread.
*
* \since This function is available since SDL 3.0.0.
* \since This function is available since SDL 3.2.0.
*/
SDL_FORCE_INLINE void SDL_RectToFRect(const SDL_Rect *rect, SDL_FRect *frect)
{
@ -146,16 +146,16 @@ SDL_FORCE_INLINE void SDL_RectToFRect(const SDL_Rect *rect, SDL_FRect *frect)
*
* \param p the point to test.
* \param r the rectangle to test.
* \returns SDL_TRUE if `p` is contained by `r`, SDL_FALSE otherwise.
* \returns true if `p` is contained by `r`, false otherwise.
*
* \threadsafety It is safe to call this function from any thread.
*
* \since This function is available since SDL 3.0.0.
* \since This function is available since SDL 3.2.0.
*/
SDL_FORCE_INLINE SDL_bool SDL_PointInRect(const SDL_Point *p, const SDL_Rect *r)
SDL_FORCE_INLINE bool SDL_PointInRect(const SDL_Point *p, const SDL_Rect *r)
{
return ( p && r && (p->x >= r->x) && (p->x < (r->x + r->w)) &&
(p->y >= r->y) && (p->y < (r->y + r->h)) ) ? SDL_TRUE : SDL_FALSE;
(p->y >= r->y) && (p->y < (r->y + r->h)) ) ? true : false;
}
/**
@ -170,15 +170,15 @@ SDL_FORCE_INLINE SDL_bool SDL_PointInRect(const SDL_Point *p, const SDL_Rect *r)
* be able to find this function inside SDL itself).
*
* \param r the rectangle to test.
* \returns SDL_TRUE if the rectangle is "empty", SDL_FALSE otherwise.
* \returns true if the rectangle is "empty", false otherwise.
*
* \threadsafety It is safe to call this function from any thread.
*
* \since This function is available since SDL 3.0.0.
* \since This function is available since SDL 3.2.0.
*/
SDL_FORCE_INLINE SDL_bool SDL_RectEmpty(const SDL_Rect *r)
SDL_FORCE_INLINE bool SDL_RectEmpty(const SDL_Rect *r)
{
return ((!r) || (r->w <= 0) || (r->h <= 0)) ? SDL_TRUE : SDL_FALSE;
return ((!r) || (r->w <= 0) || (r->h <= 0)) ? true : false;
}
/**
@ -194,51 +194,51 @@ SDL_FORCE_INLINE SDL_bool SDL_RectEmpty(const SDL_Rect *r)
*
* \param a the first rectangle to test.
* \param b the second rectangle to test.
* \returns SDL_TRUE if the rectangles are equal, SDL_FALSE otherwise.
* \returns true if the rectangles are equal, false otherwise.
*
* \threadsafety It is safe to call this function from any thread.
*
* \since This function is available since SDL 3.0.0.
* \since This function is available since SDL 3.2.0.
*/
SDL_FORCE_INLINE SDL_bool SDL_RectsEqual(const SDL_Rect *a, const SDL_Rect *b)
SDL_FORCE_INLINE bool SDL_RectsEqual(const SDL_Rect *a, const SDL_Rect *b)
{
return (a && b && (a->x == b->x) && (a->y == b->y) &&
(a->w == b->w) && (a->h == b->h)) ? SDL_TRUE : SDL_FALSE;
(a->w == b->w) && (a->h == b->h)) ? true : false;
}
/**
* Determine whether two rectangles intersect.
*
* If either pointer is NULL the function will return SDL_FALSE.
* If either pointer is NULL the function will return false.
*
* \param A an SDL_Rect structure representing the first rectangle.
* \param B an SDL_Rect structure representing the second rectangle.
* \returns SDL_TRUE if there is an intersection, SDL_FALSE otherwise.
* \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.0.0.
* \since This function is available since SDL 3.2.0.
*
* \sa SDL_GetRectIntersection
*/
extern SDL_DECLSPEC SDL_bool SDLCALL SDL_HasRectIntersection(const SDL_Rect *A, const SDL_Rect *B);
extern SDL_DECLSPEC bool SDLCALL SDL_HasRectIntersection(const SDL_Rect *A, const SDL_Rect *B);
/**
* Calculate the intersection of two rectangles.
*
* If `result` is NULL then this function will return SDL_FALSE.
* If `result` is NULL then this function will return false.
*
* \param A an SDL_Rect structure representing the first rectangle.
* \param B an SDL_Rect structure representing the second rectangle.
* \param result an SDL_Rect structure filled in with the intersection of
* rectangles `A` and `B`.
* \returns SDL_TRUE if there is an intersection, SDL_FALSE otherwise.
* \returns true if there is an intersection, false otherwise.
*
* \since This function is available since SDL 3.0.0.
* \since This function is available since SDL 3.2.0.
*
* \sa SDL_HasRectIntersection
*/
extern SDL_DECLSPEC SDL_bool SDLCALL SDL_GetRectIntersection(const SDL_Rect *A, const SDL_Rect *B, SDL_Rect *result);
extern SDL_DECLSPEC bool SDLCALL SDL_GetRectIntersection(const SDL_Rect *A, const SDL_Rect *B, SDL_Rect *result);
/**
* Calculate the union of two rectangles.
@ -247,12 +247,12 @@ extern SDL_DECLSPEC SDL_bool SDLCALL SDL_GetRectIntersection(const SDL_Rect *A,
* \param B an SDL_Rect structure representing the second rectangle.
* \param result an SDL_Rect structure filled in with the union of rectangles
* `A` and `B`.
* \returns SDL_TRUE on success or SDL_FALSE on failure; call SDL_GetError()
* for more information.
* \returns true on success or false on failure; call SDL_GetError() for more
* information.
*
* \since This function is available since SDL 3.0.0.
* \since This function is available since SDL 3.2.0.
*/
extern SDL_DECLSPEC SDL_bool SDLCALL SDL_GetRectUnion(const SDL_Rect *A, const SDL_Rect *B, SDL_Rect *result);
extern SDL_DECLSPEC bool SDLCALL SDL_GetRectUnion(const SDL_Rect *A, const SDL_Rect *B, SDL_Rect *result);
/**
* Calculate a minimal rectangle enclosing a set of points.
@ -266,12 +266,12 @@ extern SDL_DECLSPEC SDL_bool SDLCALL SDL_GetRectUnion(const SDL_Rect *A, const S
* \param clip an SDL_Rect used for clipping or NULL to enclose all points.
* \param result an SDL_Rect structure filled in with the minimal enclosing
* rectangle.
* \returns SDL_TRUE if any points were enclosed or SDL_FALSE if all the
* points were outside of the clipping rectangle.
* \returns true if any points were enclosed or false if all the points were
* outside of the clipping rectangle.
*
* \since This function is available since SDL 3.0.0.
* \since This function is available since SDL 3.2.0.
*/
extern SDL_DECLSPEC SDL_bool SDLCALL SDL_GetRectEnclosingPoints(const SDL_Point *points, int count, const SDL_Rect *clip, SDL_Rect *result);
extern SDL_DECLSPEC bool SDLCALL SDL_GetRectEnclosingPoints(const SDL_Point *points, int count, const SDL_Rect *clip, SDL_Rect *result);
/**
* Calculate the intersection of a rectangle and line segment.
@ -287,11 +287,11 @@ extern SDL_DECLSPEC SDL_bool SDLCALL SDL_GetRectEnclosingPoints(const SDL_Point
* \param Y1 a pointer to the starting Y-coordinate of the line.
* \param X2 a pointer to the ending X-coordinate of the line.
* \param Y2 a pointer to the ending Y-coordinate of the line.
* \returns SDL_TRUE if there is an intersection, SDL_FALSE otherwise.
* \returns true if there is an intersection, false otherwise.
*
* \since This function is available since SDL 3.0.0.
* \since This function is available since SDL 3.2.0.
*/
extern SDL_DECLSPEC SDL_bool SDLCALL SDL_GetRectAndLineIntersection(const SDL_Rect *rect, int *X1, int *Y1, int *X2, int *Y2);
extern SDL_DECLSPEC bool SDLCALL SDL_GetRectAndLineIntersection(const SDL_Rect *rect, int *X1, int *Y1, int *X2, int *Y2);
/* SDL_FRect versions... */
@ -311,16 +311,16 @@ extern SDL_DECLSPEC SDL_bool SDLCALL SDL_GetRectAndLineIntersection(const SDL_Re
*
* \param p the point to test.
* \param r the rectangle to test.
* \returns SDL_TRUE if `p` is contained by `r`, SDL_FALSE otherwise.
* \returns true if `p` is contained by `r`, false otherwise.
*
* \threadsafety It is safe to call this function from any thread.
*
* \since This function is available since SDL 3.0.0.
* \since This function is available since SDL 3.2.0.
*/
SDL_FORCE_INLINE SDL_bool SDL_PointInRectFloat(const SDL_FPoint *p, const SDL_FRect *r)
SDL_FORCE_INLINE bool SDL_PointInRectFloat(const SDL_FPoint *p, const SDL_FRect *r)
{
return ( p && r && (p->x >= r->x) && (p->x <= (r->x + r->w)) &&
(p->y >= r->y) && (p->y <= (r->y + r->h)) ) ? SDL_TRUE : SDL_FALSE;
(p->y >= r->y) && (p->y <= (r->y + r->h)) ) ? true : false;
}
/**
@ -335,15 +335,15 @@ SDL_FORCE_INLINE SDL_bool SDL_PointInRectFloat(const SDL_FPoint *p, const SDL_FR
* be able to find this function inside SDL itself).
*
* \param r the rectangle to test.
* \returns SDL_TRUE if the rectangle is "empty", SDL_FALSE otherwise.
* \returns true if the rectangle is "empty", false otherwise.
*
* \threadsafety It is safe to call this function from any thread.
*
* \since This function is available since SDL 3.0.0.
* \since This function is available since SDL 3.2.0.
*/
SDL_FORCE_INLINE SDL_bool SDL_RectEmptyFloat(const SDL_FRect *r)
SDL_FORCE_INLINE bool SDL_RectEmptyFloat(const SDL_FRect *r)
{
return ((!r) || (r->w < 0.0f) || (r->h < 0.0f)) ? SDL_TRUE : SDL_FALSE;
return ((!r) || (r->w < 0.0f) || (r->h < 0.0f)) ? true : false;
}
/**
@ -363,22 +363,22 @@ SDL_FORCE_INLINE SDL_bool SDL_RectEmptyFloat(const SDL_FRect *r)
* \param a the first rectangle to test.
* \param b the second rectangle to test.
* \param epsilon the epsilon value for comparison.
* \returns SDL_TRUE if the rectangles are equal, SDL_FALSE otherwise.
* \returns true if the rectangles are equal, false otherwise.
*
* \threadsafety It is safe to call this function from any thread.
*
* \since This function is available since SDL 3.0.0.
* \since This function is available since SDL 3.2.0.
*
* \sa SDL_RectsEqualFloat
*/
SDL_FORCE_INLINE SDL_bool SDL_RectsEqualEpsilon(const SDL_FRect *a, const SDL_FRect *b, const float epsilon)
SDL_FORCE_INLINE bool SDL_RectsEqualEpsilon(const SDL_FRect *a, const SDL_FRect *b, const float epsilon)
{
return (a && b && ((a == b) ||
((SDL_fabsf(a->x - b->x) <= epsilon) &&
(SDL_fabsf(a->y - b->y) <= epsilon) &&
(SDL_fabsf(a->w - b->w) <= epsilon) &&
(SDL_fabsf(a->h - b->h) <= epsilon))))
? SDL_TRUE : SDL_FALSE;
? true : false;
}
/**
@ -398,15 +398,15 @@ SDL_FORCE_INLINE SDL_bool SDL_RectsEqualEpsilon(const SDL_FRect *a, const SDL_FR
*
* \param a the first rectangle to test.
* \param b the second rectangle to test.
* \returns SDL_TRUE if the rectangles are equal, SDL_FALSE otherwise.
* \returns true if the rectangles are equal, false otherwise.
*
* \threadsafety It is safe to call this function from any thread.
*
* \since This function is available since SDL 3.0.0.
* \since This function is available since SDL 3.2.0.
*
* \sa SDL_RectsEqualEpsilon
*/
SDL_FORCE_INLINE SDL_bool SDL_RectsEqualFloat(const SDL_FRect *a, const SDL_FRect *b)
SDL_FORCE_INLINE bool SDL_RectsEqualFloat(const SDL_FRect *a, const SDL_FRect *b)
{
return SDL_RectsEqualEpsilon(a, b, SDL_FLT_EPSILON);
}
@ -414,34 +414,34 @@ SDL_FORCE_INLINE SDL_bool SDL_RectsEqualFloat(const SDL_FRect *a, const SDL_FRec
/**
* Determine whether two rectangles intersect with float precision.
*
* If either pointer is NULL the function will return SDL_FALSE.
* If either pointer is NULL the function will return false.
*
* \param A an SDL_FRect structure representing the first rectangle.
* \param B an SDL_FRect structure representing the second rectangle.
* \returns SDL_TRUE if there is an intersection, SDL_FALSE otherwise.
* \returns true if there is an intersection, false otherwise.
*
* \since This function is available since SDL 3.0.0.
* \since This function is available since SDL 3.2.0.
*
* \sa SDL_GetRectIntersection
*/
extern SDL_DECLSPEC SDL_bool SDLCALL SDL_HasRectIntersectionFloat(const SDL_FRect *A, const SDL_FRect *B);
extern SDL_DECLSPEC bool SDLCALL SDL_HasRectIntersectionFloat(const SDL_FRect *A, const SDL_FRect *B);
/**
* Calculate the intersection of two rectangles with float precision.
*
* If `result` is NULL then this function will return SDL_FALSE.
* If `result` is NULL then this function will return false.
*
* \param A an SDL_FRect structure representing the first rectangle.
* \param B an SDL_FRect structure representing the second rectangle.
* \param result an SDL_FRect structure filled in with the intersection of
* rectangles `A` and `B`.
* \returns SDL_TRUE if there is an intersection, SDL_FALSE otherwise.
* \returns true if there is an intersection, false otherwise.
*
* \since This function is available since SDL 3.0.0.
* \since This function is available since SDL 3.2.0.
*
* \sa SDL_HasRectIntersectionFloat
*/
extern SDL_DECLSPEC SDL_bool SDLCALL SDL_GetRectIntersectionFloat(const SDL_FRect *A, const SDL_FRect *B, SDL_FRect *result);
extern SDL_DECLSPEC bool SDLCALL SDL_GetRectIntersectionFloat(const SDL_FRect *A, const SDL_FRect *B, SDL_FRect *result);
/**
* Calculate the union of two rectangles with float precision.
@ -450,12 +450,12 @@ extern SDL_DECLSPEC SDL_bool SDLCALL SDL_GetRectIntersectionFloat(const SDL_FRec
* \param B an SDL_FRect structure representing the second rectangle.
* \param result an SDL_FRect structure filled in with the union of rectangles
* `A` and `B`.
* \returns SDL_TRUE on success or SDL_FALSE on failure; call SDL_GetError()
* for more information.
* \returns true on success or false on failure; call SDL_GetError() for more
* information.
*
* \since This function is available since SDL 3.0.0.
* \since This function is available since SDL 3.2.0.
*/
extern SDL_DECLSPEC SDL_bool SDLCALL SDL_GetRectUnionFloat(const SDL_FRect *A, const SDL_FRect *B, SDL_FRect *result);
extern SDL_DECLSPEC bool SDLCALL SDL_GetRectUnionFloat(const SDL_FRect *A, const SDL_FRect *B, SDL_FRect *result);
/**
* Calculate a minimal rectangle enclosing a set of points with float
@ -470,12 +470,12 @@ extern SDL_DECLSPEC SDL_bool SDLCALL SDL_GetRectUnionFloat(const SDL_FRect *A, c
* \param clip an SDL_FRect used for clipping or NULL to enclose all points.
* \param result an SDL_FRect structure filled in with the minimal enclosing
* rectangle.
* \returns SDL_TRUE if any points were enclosed or SDL_FALSE if all the
* points were outside of the clipping rectangle.
* \returns true if any points were enclosed or false if all the points were
* outside of the clipping rectangle.
*
* \since This function is available since SDL 3.0.0.
* \since This function is available since SDL 3.2.0.
*/
extern SDL_DECLSPEC SDL_bool SDLCALL SDL_GetRectEnclosingPointsFloat(const SDL_FPoint *points, int count, const SDL_FRect *clip, SDL_FRect *result);
extern SDL_DECLSPEC bool SDLCALL SDL_GetRectEnclosingPointsFloat(const SDL_FPoint *points, int count, const SDL_FRect *clip, SDL_FRect *result);
/**
* Calculate the intersection of a rectangle and line segment with float
@ -492,11 +492,11 @@ extern SDL_DECLSPEC SDL_bool SDLCALL SDL_GetRectEnclosingPointsFloat(const SDL_F
* \param Y1 a pointer to the starting Y-coordinate of the line.
* \param X2 a pointer to the ending X-coordinate of the line.
* \param Y2 a pointer to the ending Y-coordinate of the line.
* \returns SDL_TRUE if there is an intersection, SDL_FALSE otherwise.
* \returns true if there is an intersection, false otherwise.
*
* \since This function is available since SDL 3.0.0.
* \since This function is available since SDL 3.2.0.
*/
extern SDL_DECLSPEC SDL_bool SDLCALL SDL_GetRectAndLineIntersectionFloat(const SDL_FRect *rect, float *X1, float *Y1, float *X2, float *Y2);
extern SDL_DECLSPEC bool SDLCALL SDL_GetRectAndLineIntersectionFloat(const SDL_FRect *rect, float *X1, float *Y1, float *X2, float *Y2);
/* Ends C function definitions when using C++ */
#ifdef __cplusplus

File diff suppressed because it is too large Load Diff

View File

@ -1,22 +1,22 @@
/*
Simple DirectMedia Layer
Copyright (C) 1997-2024 Sam Lantinga <slouken@libsdl.org>
Simple DirectMedia Layer
Copyright (C) 1997-2025 Sam Lantinga <slouken@libsdl.org>
This software is provided 'as-is', without any express or implied
warranty. In no event will the authors be held liable for any damages
arising from the use of this software.
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:
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.
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: Version */
@ -48,9 +48,9 @@
*/
#define SDL_REVISION "Some arbitrary string decided at SDL build time"
#elif defined(SDL_VENDOR_INFO)
#define SDL_REVISION SDL_VENDOR_INFO
#define SDL_REVISION "release-3.2.0-0-g535d80bad (" SDL_VENDOR_INFO ")"
#else
#define SDL_REVISION ""
#define SDL_REVISION "release-3.2.0-0-g535d80bad"
#endif
#endif /* SDL_revision_h_ */

View File

@ -1,6 +1,6 @@
/*
Simple DirectMedia Layer
Copyright (C) 1997-2024 Sam Lantinga <slouken@libsdl.org>
Copyright (C) 1997-2025 Sam Lantinga <slouken@libsdl.org>
This software is provided 'as-is', without any express or implied
warranty. In no event will the authors be held liable for any damages
@ -23,6 +23,11 @@
* # CategoryScancode
*
* Defines keyboard scancodes.
*
* Please refer to the Best Keyboard Practices document for details on what
* this information means and how best to use it.
*
* https://wiki.libsdl.org/SDL3/BestKeyboardPractices
*/
#ifndef SDL_scancode_h_
@ -42,7 +47,7 @@
* The values in this enumeration are based on the USB usage page standard:
* https://usb.org/sites/default/files/hut1_5.pdf
*
* \since This enum is available since SDL 3.0.0.
* \since This enum is available since SDL 3.2.0.
*/
typedef enum SDL_Scancode
{
@ -417,8 +422,8 @@ typedef enum SDL_Scancode
SDL_SCANCODE_RESERVED = 400, /**< 400-500 reserved for dynamic keycodes */
SDL_NUM_SCANCODES = 512 /**< not a key, just marks the number of scancodes
for array bounds */
SDL_SCANCODE_COUNT = 512 /**< not a key, just marks the number of scancodes for array bounds */
} SDL_Scancode;
#endif /* SDL_scancode_h_ */

View File

@ -1,6 +1,6 @@
/*
Simple DirectMedia Layer
Copyright (C) 1997-2024 Sam Lantinga <slouken@libsdl.org>
Copyright (C) 1997-2025 Sam Lantinga <slouken@libsdl.org>
This software is provided 'as-is', without any express or implied
warranty. In no event will the authors be held liable for any damages
@ -23,6 +23,12 @@
* # CategorySensor
*
* SDL sensor management.
*
* These APIs grant access to gyros and accelerometers on various platforms.
*
* In order to use these functions, SDL_Init() must have been called with the
* SDL_INIT_SENSOR flag. This causes SDL to scan the system for sensors, and
* load appropriate drivers.
*/
#ifndef SDL_sensor_h_
@ -41,14 +47,10 @@ extern "C" {
#endif
/**
* SDL_sensor.h
* The opaque structure used to identify an opened SDL sensor.
*
* In order to use these functions, SDL_Init() must have been called
* with the SDL_INIT_SENSOR flag. This causes SDL to scan the system
* for sensors, and load appropriate drivers.
* \since This struct is available since SDL 3.2.0.
*/
struct SDL_Sensor;
typedef struct SDL_Sensor SDL_Sensor;
/**
@ -57,7 +59,7 @@ typedef struct SDL_Sensor SDL_Sensor;
*
* The value 0 is an invalid ID.
*
* \since This datatype is available since SDL 3.0.0.
* \since This datatype is available since SDL 3.2.0.
*/
typedef Uint32 SDL_SensorID;
@ -69,7 +71,7 @@ typedef Uint32 SDL_SensorID;
* rest will have an value of SDL_STANDARD_GRAVITY away from the center of the
* earth, which is a positive Y value.
*
* \since This macro is available since SDL 3.0.0.
* \since This macro is available since SDL 3.2.0.
*/
#define SDL_STANDARD_GRAVITY 9.80665f
@ -123,7 +125,7 @@ typedef Uint32 SDL_SensorID;
*
* The gyroscope axis data is not changed when the device is rotated.
*
* \since This enum is available since SDL 3.0.0.
* \since This enum is available since SDL 3.2.0.
*
* \sa SDL_GetCurrentDisplayOrientation
*/
@ -151,7 +153,7 @@ typedef enum SDL_SensorType
* call SDL_GetError() for more information. This should be freed
* with SDL_free() when it is no longer needed.
*
* \since This function is available since SDL 3.0.0.
* \since This function is available since SDL 3.2.0.
*/
extern SDL_DECLSPEC SDL_SensorID * SDLCALL SDL_GetSensors(int *count);
@ -163,7 +165,7 @@ extern SDL_DECLSPEC SDL_SensorID * SDLCALL SDL_GetSensors(int *count);
* \param instance_id the sensor instance ID.
* \returns the sensor name, or NULL if `instance_id` is not valid.
*
* \since This function is available since SDL 3.0.0.
* \since This function is available since SDL 3.2.0.
*/
extern SDL_DECLSPEC const char * SDLCALL SDL_GetSensorNameForID(SDL_SensorID instance_id);
@ -176,7 +178,7 @@ extern SDL_DECLSPEC const char * SDLCALL SDL_GetSensorNameForID(SDL_SensorID ins
* \returns the SDL_SensorType, or `SDL_SENSOR_INVALID` if `instance_id` is
* not valid.
*
* \since This function is available since SDL 3.0.0.
* \since This function is available since SDL 3.2.0.
*/
extern SDL_DECLSPEC SDL_SensorType SDLCALL SDL_GetSensorTypeForID(SDL_SensorID instance_id);
@ -189,7 +191,7 @@ extern SDL_DECLSPEC SDL_SensorType SDLCALL SDL_GetSensorTypeForID(SDL_SensorID i
* \returns the sensor platform dependent type, or -1 if `instance_id` is not
* valid.
*
* \since This function is available since SDL 3.0.0.
* \since This function is available since SDL 3.2.0.
*/
extern SDL_DECLSPEC int SDLCALL SDL_GetSensorNonPortableTypeForID(SDL_SensorID instance_id);
@ -200,7 +202,7 @@ extern SDL_DECLSPEC int SDLCALL SDL_GetSensorNonPortableTypeForID(SDL_SensorID i
* \returns an SDL_Sensor object or NULL on failure; call SDL_GetError() for
* more information.
*
* \since This function is available since SDL 3.0.0.
* \since This function is available since SDL 3.2.0.
*/
extern SDL_DECLSPEC SDL_Sensor * SDLCALL SDL_OpenSensor(SDL_SensorID instance_id);
@ -211,7 +213,7 @@ extern SDL_DECLSPEC SDL_Sensor * SDLCALL SDL_OpenSensor(SDL_SensorID instance_id
* \returns an SDL_Sensor object or NULL on failure; call SDL_GetError() for
* more information.
*
* \since This function is available since SDL 3.0.0.
* \since This function is available since SDL 3.2.0.
*/
extern SDL_DECLSPEC SDL_Sensor * SDLCALL SDL_GetSensorFromID(SDL_SensorID instance_id);
@ -222,7 +224,7 @@ extern SDL_DECLSPEC SDL_Sensor * SDLCALL SDL_GetSensorFromID(SDL_SensorID instan
* \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.0.0.
* \since This function is available since SDL 3.2.0.
*/
extern SDL_DECLSPEC SDL_PropertiesID SDLCALL SDL_GetSensorProperties(SDL_Sensor *sensor);
@ -233,7 +235,7 @@ extern SDL_DECLSPEC SDL_PropertiesID SDLCALL SDL_GetSensorProperties(SDL_Sensor
* \returns the sensor name or NULL on failure; call SDL_GetError() for more
* information.
*
* \since This function is available since SDL 3.0.0.
* \since This function is available since SDL 3.2.0.
*/
extern SDL_DECLSPEC const char * SDLCALL SDL_GetSensorName(SDL_Sensor *sensor);
@ -244,7 +246,7 @@ extern SDL_DECLSPEC const char * SDLCALL SDL_GetSensorName(SDL_Sensor *sensor);
* \returns the SDL_SensorType type, or `SDL_SENSOR_INVALID` if `sensor` is
* NULL.
*
* \since This function is available since SDL 3.0.0.
* \since This function is available since SDL 3.2.0.
*/
extern SDL_DECLSPEC SDL_SensorType SDLCALL SDL_GetSensorType(SDL_Sensor *sensor);
@ -254,7 +256,7 @@ extern SDL_DECLSPEC SDL_SensorType SDLCALL SDL_GetSensorType(SDL_Sensor *sensor)
* \param sensor the SDL_Sensor object to inspect.
* \returns the sensor platform dependent type, or -1 if `sensor` is NULL.
*
* \since This function is available since SDL 3.0.0.
* \since This function is available since SDL 3.2.0.
*/
extern SDL_DECLSPEC int SDLCALL SDL_GetSensorNonPortableType(SDL_Sensor *sensor);
@ -265,7 +267,7 @@ extern SDL_DECLSPEC int SDLCALL SDL_GetSensorNonPortableType(SDL_Sensor *sensor)
* \returns the sensor instance ID, or 0 on failure; call SDL_GetError() for
* more information.
*
* \since This function is available since SDL 3.0.0.
* \since This function is available since SDL 3.2.0.
*/
extern SDL_DECLSPEC SDL_SensorID SDLCALL SDL_GetSensorID(SDL_Sensor *sensor);
@ -277,19 +279,19 @@ extern SDL_DECLSPEC SDL_SensorID SDLCALL SDL_GetSensorID(SDL_Sensor *sensor);
* \param sensor the SDL_Sensor object to query.
* \param data a pointer filled with the current sensor state.
* \param num_values the number of values to write to data.
* \returns SDL_TRUE on success or SDL_FALSE on failure; call SDL_GetError()
* for more information.
* \returns true on success or false on failure; call SDL_GetError() for more
* information.
*
* \since This function is available since SDL 3.0.0.
* \since This function is available since SDL 3.2.0.
*/
extern SDL_DECLSPEC SDL_bool SDLCALL SDL_GetSensorData(SDL_Sensor *sensor, float *data, int num_values);
extern SDL_DECLSPEC bool SDLCALL SDL_GetSensorData(SDL_Sensor *sensor, float *data, int num_values);
/**
* Close a sensor previously opened with SDL_OpenSensor().
*
* \param sensor the SDL_Sensor object to close.
*
* \since This function is available since SDL 3.0.0.
* \since This function is available since SDL 3.2.0.
*/
extern SDL_DECLSPEC void SDLCALL SDL_CloseSensor(SDL_Sensor *sensor);
@ -302,7 +304,7 @@ extern SDL_DECLSPEC void SDLCALL SDL_CloseSensor(SDL_Sensor *sensor);
* This needs to be called from the thread that initialized the sensor
* subsystem.
*
* \since This function is available since SDL 3.0.0.
* \since This function is available since SDL 3.2.0.
*/
extern SDL_DECLSPEC void SDLCALL SDL_UpdateSensors(void);

File diff suppressed because it is too large Load Diff

View File

@ -1,6 +1,6 @@
/*
Simple DirectMedia Layer
Copyright (C) 1997-2024 Sam Lantinga <slouken@libsdl.org>
Copyright (C) 1997-2025 Sam Lantinga <slouken@libsdl.org>
This software is provided 'as-is', without any express or implied
warranty. In no event will the authors be held liable for any damages
@ -22,7 +22,222 @@
/**
* # CategoryStorage
*
* SDL storage container management.
* The storage API is a high-level API designed to abstract away the
* portability issues that come up when using something lower-level (in SDL's
* case, this sits on top of the [Filesystem](CategoryFilesystem) and
* [IOStream](CategoryIOStream) subsystems). It is significantly more
* restrictive than a typical filesystem API, for a number of reasons:
*
* 1. **What to Access:** A common pitfall with existing filesystem APIs is
* the assumption that all storage is monolithic. However, many other
* platforms (game consoles in particular) are more strict about what _type_
* of filesystem is being accessed; for example, game content and user data
* are usually two separate storage devices with entirely different
* characteristics (and possibly different low-level APIs altogether!).
*
* 2. **How to Access:** Another common mistake is applications assuming that
* all storage is universally writeable - again, many platforms treat game
* content and user data as two separate storage devices, and only user data
* is writeable while game content is read-only.
*
* 3. **When to Access:** The most common portability issue with filesystem
* access is _timing_ - you cannot always assume that the storage device is
* always accessible all of the time, nor can you assume that there are no
* limits to how long you have access to a particular device.
*
* Consider the following example:
*
* ```c
* void ReadGameData(void)
* {
* extern char** fileNames;
* extern size_t numFiles;
* for (size_t i = 0; i < numFiles; i += 1) {
* FILE *data = fopen(fileNames[i], "rwb");
* if (data == NULL) {
* // Something bad happened!
* } else {
* // A bunch of stuff happens here
* fclose(data);
* }
* }
* }
*
* void ReadSave(void)
* {
* FILE *save = fopen("saves/save0.sav", "rb");
* if (save == NULL) {
* // Something bad happened!
* } else {
* // A bunch of stuff happens here
* fclose(save);
* }
* }
*
* void WriteSave(void)
* {
* FILE *save = fopen("saves/save0.sav", "wb");
* if (save == NULL) {
* // Something bad happened!
* } else {
* // A bunch of stuff happens here
* fclose(save);
* }
* }
* ```
*
* Going over the bullet points again:
*
* 1. **What to Access:** This code accesses a global filesystem; game data
* and saves are all presumed to be in the current working directory (which
* may or may not be the game's installation folder!).
*
* 2. **How to Access:** This code assumes that content paths are writeable,
* and that save data is also writeable despite being in the same location as
* the game data.
*
* 3. **When to Access:** This code assumes that they can be called at any
* time, since the filesystem is always accessible and has no limits on how
* long the filesystem is being accessed.
*
* Due to these assumptions, the filesystem code is not portable and will fail
* under these common scenarios:
*
* - The game is installed on a device that is read-only, both content loading
* and game saves will fail or crash outright
* - Game/User storage is not implicitly mounted, so no files will be found
* for either scenario when a platform requires explicitly mounting
* filesystems
* - Save data may not be safe since the I/O is not being flushed or
* validated, so an error occurring elsewhere in the program may result in
* missing/corrupted save data
*
* When using SDL_Storage, these types of problems are virtually impossible to
* trip over:
*
* ```c
* void ReadGameData(void)
* {
* extern char** fileNames;
* extern size_t numFiles;
*
* SDL_Storage *title = SDL_OpenTitleStorage(NULL, 0);
* if (title == NULL) {
* // Something bad happened!
* }
* while (!SDL_StorageReady(title)) {
* SDL_Delay(1);
* }
*
* for (size_t i = 0; i < numFiles; i += 1) {
* void* dst;
* Uint64 dstLen = 0;
*
* if (SDL_GetStorageFileSize(title, fileNames[i], &dstLen) && dstLen > 0) {
* dst = SDL_malloc(dstLen);
* if (SDL_ReadStorageFile(title, fileNames[i], dst, dstLen)) {
* // A bunch of stuff happens here
* } else {
* // Something bad happened!
* }
* SDL_free(dst);
* } else {
* // Something bad happened!
* }
* }
*
* SDL_CloseStorage(title);
* }
*
* void ReadSave(void)
* {
* SDL_Storage *user = SDL_OpenUserStorage("libsdl", "Storage Example", 0);
* if (user == NULL) {
* // Something bad happened!
* }
* while (!SDL_StorageReady(user)) {
* SDL_Delay(1);
* }
*
* Uint64 saveLen = 0;
* if (SDL_GetStorageFileSize(user, "save0.sav", &saveLen) && saveLen > 0) {
* void* dst = SDL_malloc(saveLen);
* if (SDL_ReadStorageFile(user, "save0.sav", dst, saveLen)) {
* // A bunch of stuff happens here
* } else {
* // Something bad happened!
* }
* SDL_free(dst);
* } else {
* // Something bad happened!
* }
*
* SDL_CloseStorage(user);
* }
*
* void WriteSave(void)
* {
* SDL_Storage *user = SDL_OpenUserStorage("libsdl", "Storage Example", 0);
* if (user == NULL) {
* // Something bad happened!
* }
* while (!SDL_StorageReady(user)) {
* SDL_Delay(1);
* }
*
* extern void *saveData; // A bunch of stuff happened here...
* extern Uint64 saveLen;
* if (!SDL_WriteStorageFile(user, "save0.sav", saveData, saveLen)) {
* // Something bad happened!
* }
*
* SDL_CloseStorage(user);
* }
* ```
*
* Note the improvements that SDL_Storage makes:
*
* 1. **What to Access:** This code explicitly reads from a title or user
* storage device based on the context of the function.
*
* 2. **How to Access:** This code explicitly uses either a read or write
* function based on the context of the function.
*
* 3. **When to Access:** This code explicitly opens the device when it needs
* to, and closes it when it is finished working with the filesystem.
*
* The result is an application that is significantly more robust against the
* increasing demands of platforms and their filesystems!
*
* A publicly available example of an SDL_Storage backend is the
* [Steam Cloud](https://partner.steamgames.com/doc/features/cloud)
* backend - you can initialize Steamworks when starting the program, and then
* SDL will recognize that Steamworks is initialized and automatically use
* ISteamRemoteStorage when the application opens user storage. More
* importantly, when you _open_ storage it knows to begin a "batch" of
* filesystem operations, and when you _close_ storage it knows to end and
* flush the batch. This is used by Steam to support
* [Dynamic Cloud Sync](https://steamcommunity.com/groups/steamworks/announcements/detail/3142949576401813670)
* ; users can save data on one PC, put the device to sleep, and then continue
* playing on another PC (and vice versa) with the save data fully
* synchronized across all devices, allowing for a seamless experience without
* having to do full restarts of the program.
*
* ## Notes on valid paths
*
* All paths in the Storage API use Unix-style path separators ('/'). Using a
* different path separator will not work, even if the underlying platform
* would otherwise accept it. This is to keep code using the Storage API
* portable between platforms and Storage implementations and simplify app
* code.
*
* Paths with relative directories ("." and "..") are forbidden by the Storage
* API.
*
* All valid UTF-8 strings (discounting the NULL terminator character and the
* '/' path separator) are usable for filenames, however, an underlying
* Storage implementation may not support particularly strange sequences and
* refuse to create files with those names, etc.
*/
#ifndef SDL_storage_h_
@ -40,8 +255,6 @@
extern "C" {
#endif
/* !!! FIXME: Don't let this ship without async R/W support!!! */
/**
* Function interface for SDL_Storage.
*
@ -52,44 +265,61 @@ extern "C" {
* It is not usually necessary to do this; SDL provides standard
* implementations for many things you might expect to do with an SDL_Storage.
*
* \since This struct is available since SDL 3.0.0.
* This structure should be initialized using SDL_INIT_INTERFACE()
*
* \since This struct is available since SDL 3.2.0.
*
* \sa SDL_INIT_INTERFACE
*/
typedef struct SDL_StorageInterface
{
/* The version of this interface */
Uint32 version;
/* Called when the storage is closed */
SDL_bool (SDLCALL *close)(void *userdata);
bool (SDLCALL *close)(void *userdata);
/* Optional, returns whether the storage is currently ready for access */
SDL_bool (SDLCALL *ready)(void *userdata);
bool (SDLCALL *ready)(void *userdata);
/* Enumerate a directory, optional for write-only storage */
SDL_bool (SDLCALL *enumerate)(void *userdata, const char *path, SDL_EnumerateDirectoryCallback callback, void *callback_userdata);
bool (SDLCALL *enumerate)(void *userdata, const char *path, SDL_EnumerateDirectoryCallback callback, void *callback_userdata);
/* Get path information, optional for write-only storage */
SDL_bool (SDLCALL *info)(void *userdata, const char *path, SDL_PathInfo *info);
bool (SDLCALL *info)(void *userdata, const char *path, SDL_PathInfo *info);
/* Read a file from storage, optional for write-only storage */
SDL_bool (SDLCALL *read_file)(void *userdata, const char *path, void *destination, Uint64 length);
bool (SDLCALL *read_file)(void *userdata, const char *path, void *destination, Uint64 length);
/* Write a file to storage, optional for read-only storage */
SDL_bool (SDLCALL *write_file)(void *userdata, const char *path, const void *source, Uint64 length);
bool (SDLCALL *write_file)(void *userdata, const char *path, const void *source, Uint64 length);
/* Create a directory, optional for read-only storage */
SDL_bool (SDLCALL *mkdir)(void *userdata, const char *path);
bool (SDLCALL *mkdir)(void *userdata, const char *path);
/* Remove a file or empty directory, optional for read-only storage */
SDL_bool (SDLCALL *remove)(void *userdata, const char *path);
bool (SDLCALL *remove)(void *userdata, const char *path);
/* Rename a path, optional for read-only storage */
SDL_bool (SDLCALL *rename)(void *userdata, const char *oldpath, const char *newpath);
bool (SDLCALL *rename)(void *userdata, const char *oldpath, const char *newpath);
/* Copy a file, optional for read-only storage */
SDL_bool (SDLCALL *copy)(void *userdata, const char *oldpath, const char *newpath);
bool (SDLCALL *copy)(void *userdata, const char *oldpath, const char *newpath);
/* Get the space remaining, optional for read-only storage */
Uint64 (SDLCALL *space_remaining)(void *userdata);
} SDL_StorageInterface;
/* Check the size of SDL_StorageInterface
*
* If this assert fails, either the compiler is padding to an unexpected size,
* or the interface has been updated and this should be updated to match and
* the code using this interface should be updated to handle the old version.
*/
SDL_COMPILE_TIME_ASSERT(SDL_StorageInterface_SIZE,
(sizeof(void *) == 4 && sizeof(SDL_StorageInterface) == 48) ||
(sizeof(void *) == 8 && sizeof(SDL_StorageInterface) == 96));
/**
* An abstract interface for filesystem access.
*
@ -97,7 +327,7 @@ typedef struct SDL_StorageInterface
* functions like SDL_OpenTitleStorage or SDL_OpenUserStorage, etc, or create
* an object with a custom implementation using SDL_OpenStorage.
*
* \since This struct is available since SDL 3.0.0.
* \since This struct is available since SDL 3.2.0.
*/
typedef struct SDL_Storage SDL_Storage;
@ -109,7 +339,7 @@ typedef struct SDL_Storage SDL_Storage;
* \returns a title storage container on success or NULL on failure; call
* SDL_GetError() for more information.
*
* \since This function is available since SDL 3.0.0.
* \since This function is available since SDL 3.2.0.
*
* \sa SDL_CloseStorage
* \sa SDL_GetStorageFileSize
@ -132,7 +362,7 @@ extern SDL_DECLSPEC SDL_Storage * SDLCALL SDL_OpenTitleStorage(const char *overr
* \returns a user storage container on success or NULL on failure; call
* SDL_GetError() for more information.
*
* \since This function is available since SDL 3.0.0.
* \since This function is available since SDL 3.2.0.
*
* \sa SDL_CloseStorage
* \sa SDL_GetStorageFileSize
@ -156,7 +386,7 @@ extern SDL_DECLSPEC SDL_Storage * SDLCALL SDL_OpenUserStorage(const char *org, c
* \returns a filesystem storage container on success or NULL on failure; call
* SDL_GetError() for more information.
*
* \since This function is available since SDL 3.0.0.
* \since This function is available since SDL 3.2.0.
*
* \sa SDL_CloseStorage
* \sa SDL_GetStorageFileSize
@ -176,16 +406,21 @@ extern SDL_DECLSPEC SDL_Storage * SDLCALL SDL_OpenFileStorage(const char *path);
* should use the built-in implementations in SDL, like SDL_OpenTitleStorage()
* or SDL_OpenUserStorage().
*
* \param iface the function table to be used by this container.
* \param userdata the pointer that will be passed to the store interface.
* This function makes a copy of `iface` and the caller does not need to keep
* it around after this call.
*
* \param iface the interface that implements this storage, initialized using
* SDL_INIT_INTERFACE().
* \param userdata the pointer that will be passed to the interface functions.
* \returns a storage container on success or NULL on failure; call
* SDL_GetError() for more information.
*
* \since This function is available since SDL 3.0.0.
* \since This function is available since SDL 3.2.0.
*
* \sa SDL_CloseStorage
* \sa SDL_GetStorageFileSize
* \sa SDL_GetStorageSpaceRemaining
* \sa SDL_INIT_INTERFACE
* \sa SDL_ReadStorageFile
* \sa SDL_StorageReady
* \sa SDL_WriteStorageFile
@ -196,33 +431,33 @@ extern SDL_DECLSPEC SDL_Storage * SDLCALL SDL_OpenStorage(const SDL_StorageInter
* Closes and frees a storage container.
*
* \param storage a storage container to close.
* \returns SDL_TRUE if the container was freed with no errors, SDL_FALSE
* otherwise; call SDL_GetError() for more information. Even if the
* function returns an error, the container data will be freed; the
* error is only for informational purposes.
* \returns true if the container was freed with no errors, false otherwise;
* call SDL_GetError() for more information. Even if the function
* returns an error, the container data will be freed; the error is
* only for informational purposes.
*
* \since This function is available since SDL 3.0.0.
* \since This function is available since SDL 3.2.0.
*
* \sa SDL_OpenFileStorage
* \sa SDL_OpenStorage
* \sa SDL_OpenTitleStorage
* \sa SDL_OpenUserStorage
*/
extern SDL_DECLSPEC SDL_bool SDLCALL SDL_CloseStorage(SDL_Storage *storage);
extern SDL_DECLSPEC bool SDLCALL SDL_CloseStorage(SDL_Storage *storage);
/**
* Checks if the storage container is ready to use.
*
* This function should be called in regular intervals until it returns
* SDL_TRUE - however, it is not recommended to spinwait on this call, as the
* backend may depend on a synchronous message loop.
* This function should be called in regular intervals until it returns true -
* however, it is not recommended to spinwait on this call, as the backend may
* depend on a synchronous message loop.
*
* \param storage a storage container to query.
* \returns SDL_TRUE if the container is ready, SDL_FALSE otherwise.
* \returns true if the container is ready, false otherwise.
*
* \since This function is available since SDL 3.0.0.
* \since This function is available since SDL 3.2.0.
*/
extern SDL_DECLSPEC SDL_bool SDLCALL SDL_StorageReady(SDL_Storage *storage);
extern SDL_DECLSPEC bool SDLCALL SDL_StorageReady(SDL_Storage *storage);
/**
* Query the size of a file within a storage container.
@ -230,34 +465,38 @@ extern SDL_DECLSPEC SDL_bool SDLCALL SDL_StorageReady(SDL_Storage *storage);
* \param storage a storage container to query.
* \param path the relative path of the file to query.
* \param length a pointer to be filled with the file's length.
* \returns SDL_TRUE if the file could be queried or SDL_FALSE on failure;
* call SDL_GetError() for more information.
* \returns true if the file could be queried or false on failure; call
* SDL_GetError() for more information.
*
* \since This function is available since SDL 3.0.0.
* \since This function is available since SDL 3.2.0.
*
* \sa SDL_ReadStorageFile
* \sa SDL_StorageReady
*/
extern SDL_DECLSPEC SDL_bool SDLCALL SDL_GetStorageFileSize(SDL_Storage *storage, const char *path, Uint64 *length);
extern SDL_DECLSPEC bool SDLCALL SDL_GetStorageFileSize(SDL_Storage *storage, const char *path, Uint64 *length);
/**
* Synchronously read a file from a storage container into a client-provided
* buffer.
*
* The value of `length` must match the length of the file exactly; call
* SDL_GetStorageFileSize() to get this value. This behavior may be relaxed in
* a future release.
*
* \param storage a storage container to read from.
* \param path the relative path of the file to read.
* \param destination a client-provided buffer to read the file into.
* \param length the length of the destination buffer.
* \returns SDL_TRUE if the file was read or SDL_FALSE on failure; call
* SDL_GetError() for more information.
* \returns true if the file was read or false on failure; call SDL_GetError()
* for more information.
*
* \since This function is available since SDL 3.0.0.
* \since This function is available since SDL 3.2.0.
*
* \sa SDL_GetStorageFileSize
* \sa SDL_StorageReady
* \sa SDL_WriteStorageFile
*/
extern SDL_DECLSPEC SDL_bool SDLCALL SDL_ReadStorageFile(SDL_Storage *storage, const char *path, void *destination, Uint64 length);
extern SDL_DECLSPEC bool SDLCALL SDL_ReadStorageFile(SDL_Storage *storage, const char *path, void *destination, Uint64 length);
/**
* Synchronously write a file from client memory into a storage container.
@ -266,64 +505,73 @@ extern SDL_DECLSPEC SDL_bool SDLCALL SDL_ReadStorageFile(SDL_Storage *storage, c
* \param path the relative path of the file to write.
* \param source a client-provided buffer to write from.
* \param length the length of the source buffer.
* \returns SDL_TRUE if the file was written or SDL_FALSE on failure; call
* \returns true if the file was written or false on failure; call
* SDL_GetError() for more information.
*
* \since This function is available since SDL 3.0.0.
* \since This function is available since SDL 3.2.0.
*
* \sa SDL_GetStorageSpaceRemaining
* \sa SDL_ReadStorageFile
* \sa SDL_StorageReady
*/
extern SDL_DECLSPEC SDL_bool SDLCALL SDL_WriteStorageFile(SDL_Storage *storage, const char *path, const void *source, Uint64 length);
extern SDL_DECLSPEC bool SDLCALL SDL_WriteStorageFile(SDL_Storage *storage, const char *path, const void *source, Uint64 length);
/**
* Create a directory in a writable storage container.
*
* \param storage a storage container.
* \param path the path of the directory to create.
* \returns SDL_TRUE on success or SDL_FALSE on failure; call SDL_GetError()
* for more information.
* \returns true on success or false on failure; call SDL_GetError() for more
* information.
*
* \since This function is available since SDL 3.0.0.
* \since This function is available since SDL 3.2.0.
*
* \sa SDL_StorageReady
*/
extern SDL_DECLSPEC SDL_bool SDLCALL SDL_CreateStorageDirectory(SDL_Storage *storage, const char *path);
extern SDL_DECLSPEC bool SDLCALL SDL_CreateStorageDirectory(SDL_Storage *storage, const char *path);
/**
* Enumerate a directory in a storage container through a callback function.
*
* This function provides every directory entry through an app-provided
* callback, called once for each directory entry, until all results have been
* provided or the callback returns <= 0.
* provided or the callback returns either SDL_ENUM_SUCCESS or
* SDL_ENUM_FAILURE.
*
* This will return false if there was a system problem in general, or if a
* callback returns SDL_ENUM_FAILURE. A successful return means a callback
* returned SDL_ENUM_SUCCESS to halt enumeration, or all directory entries
* were enumerated.
*
* If `path` is NULL, this is treated as a request to enumerate the root of
* the storage container's tree. An empty string also works for this.
*
* \param storage a storage container.
* \param path the path of the directory to enumerate.
* \param path the path of the directory to enumerate, or NULL for the root.
* \param callback a function that is called for each entry in the directory.
* \param userdata a pointer that is passed to `callback`.
* \returns SDL_TRUE on success or SDL_FALSE on failure; call SDL_GetError()
* for more information.
* \returns true on success or false on failure; call SDL_GetError() for more
* information.
*
* \since This function is available since SDL 3.0.0.
* \since This function is available since SDL 3.2.0.
*
* \sa SDL_StorageReady
*/
extern SDL_DECLSPEC SDL_bool SDLCALL SDL_EnumerateStorageDirectory(SDL_Storage *storage, const char *path, SDL_EnumerateDirectoryCallback callback, void *userdata);
extern SDL_DECLSPEC bool SDLCALL SDL_EnumerateStorageDirectory(SDL_Storage *storage, const char *path, SDL_EnumerateDirectoryCallback callback, void *userdata);
/**
* 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.
* \returns SDL_TRUE on success or SDL_FALSE on failure; call SDL_GetError()
* for more information.
* \returns true on success or false on failure; call SDL_GetError() for more
* information.
*
* \since This function is available since SDL 3.0.0.
* \since This function is available since SDL 3.2.0.
*
* \sa SDL_StorageReady
*/
extern SDL_DECLSPEC SDL_bool SDLCALL SDL_RemoveStoragePath(SDL_Storage *storage, const char *path);
extern SDL_DECLSPEC bool SDLCALL SDL_RemoveStoragePath(SDL_Storage *storage, const char *path);
/**
* Rename a file or directory in a writable storage container.
@ -331,14 +579,14 @@ extern SDL_DECLSPEC SDL_bool SDLCALL SDL_RemoveStoragePath(SDL_Storage *storage,
* \param storage a storage container.
* \param oldpath the old path.
* \param newpath the new path.
* \returns SDL_TRUE on success or SDL_FALSE on failure; call SDL_GetError()
* for more information.
* \returns true on success or false on failure; call SDL_GetError() for more
* information.
*
* \since This function is available since SDL 3.0.0.
* \since This function is available since SDL 3.2.0.
*
* \sa SDL_StorageReady
*/
extern SDL_DECLSPEC SDL_bool SDLCALL SDL_RenameStoragePath(SDL_Storage *storage, const char *oldpath, const char *newpath);
extern SDL_DECLSPEC bool SDLCALL SDL_RenameStoragePath(SDL_Storage *storage, const char *oldpath, const char *newpath);
/**
* Copy a file in a writable storage container.
@ -346,14 +594,14 @@ extern SDL_DECLSPEC SDL_bool SDLCALL SDL_RenameStoragePath(SDL_Storage *storage,
* \param storage a storage container.
* \param oldpath the old path.
* \param newpath the new path.
* \returns SDL_TRUE on success or SDL_FALSE on failure; call SDL_GetError()
* for more information.
* \returns true on success or false on failure; call SDL_GetError() for more
* information.
*
* \since This function is available since SDL 3.0.0.
* \since This function is available since SDL 3.2.0.
*
* \sa SDL_StorageReady
*/
extern SDL_DECLSPEC SDL_bool SDLCALL SDL_CopyStorageFile(SDL_Storage *storage, const char *oldpath, const char *newpath);
extern SDL_DECLSPEC bool SDLCALL SDL_CopyStorageFile(SDL_Storage *storage, const char *oldpath, const char *newpath);
/**
* Get information about a filesystem path in a storage container.
@ -362,14 +610,14 @@ extern SDL_DECLSPEC SDL_bool SDLCALL SDL_CopyStorageFile(SDL_Storage *storage, c
* \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 SDL_TRUE on success or SDL_FALSE if the file doesn't exist, or
* another failure; call SDL_GetError() for more information.
* \returns true on success or false if the file doesn't exist, or another
* failure; call SDL_GetError() for more information.
*
* \since This function is available since SDL 3.0.0.
* \since This function is available since SDL 3.2.0.
*
* \sa SDL_StorageReady
*/
extern SDL_DECLSPEC SDL_bool SDLCALL SDL_GetStoragePathInfo(SDL_Storage *storage, const char *path, SDL_PathInfo *info);
extern SDL_DECLSPEC bool SDLCALL SDL_GetStoragePathInfo(SDL_Storage *storage, const char *path, SDL_PathInfo *info);
/**
* Queries the remaining space in a storage container.
@ -377,7 +625,7 @@ extern SDL_DECLSPEC SDL_bool SDLCALL SDL_GetStoragePathInfo(SDL_Storage *storage
* \param storage a storage container to query.
* \returns the amount of remaining space, in bytes.
*
* \since This function is available since SDL 3.0.0.
* \since This function is available since SDL 3.2.0.
*
* \sa SDL_StorageReady
* \sa SDL_WriteStorageFile
@ -401,8 +649,11 @@ extern SDL_DECLSPEC Uint64 SDLCALL SDL_GetStorageSpaceRemaining(SDL_Storage *sto
* convenience, but if `count` is non-NULL, on return it will contain the
* number of items in the array, not counting the NULL terminator.
*
* If `path` is NULL, this is treated as a request to enumerate the root of
* the storage container's tree. An empty string also works for this.
*
* \param storage a storage container.
* \param path the path of the directory to enumerate.
* \param path the path of the directory to enumerate, or NULL for the root.
* \param pattern the pattern that files in the directory must match. Can be
* NULL.
* \param flags `SDL_GLOB_*` bitflags that affect this search.
@ -417,7 +668,7 @@ extern SDL_DECLSPEC Uint64 SDLCALL SDL_GetStorageSpaceRemaining(SDL_Storage *sto
* \threadsafety It is safe to call this function from any thread, assuming
* the `storage` object is thread-safe.
*
* \since This function is available since SDL 3.0.0.
* \since This function is available since SDL 3.2.0.
*/
extern SDL_DECLSPEC char ** SDLCALL SDL_GlobStorageDirectory(SDL_Storage *storage, const char *path, const char *pattern, SDL_GlobFlags flags, int *count);

File diff suppressed because it is too large Load Diff

View File

@ -1,6 +1,6 @@
/*
Simple DirectMedia Layer
Copyright (C) 1997-2024 Sam Lantinga <slouken@libsdl.org>
Copyright (C) 1997-2025 Sam Lantinga <slouken@libsdl.org>
This software is provided 'as-is', without any express or implied
warranty. In no event will the authors be held liable for any damages
@ -22,7 +22,13 @@
/**
* # CategorySystem
*
* Platform-specific SDL API functions.
* Platform-specific SDL API functions. These are functions that deal with
* needs of specific operating systems, that didn't make sense to offer as
* platform-independent, generic APIs.
*
* Most apps can make do without these functions, but they can be useful for
* integrating with other parts of a specific system, adding platform-specific
* polish to an app, or solving problems that only affect one target.
*/
#ifndef SDL_system_h_
@ -31,7 +37,6 @@
#include <SDL3/SDL_stdinc.h>
#include <SDL3/SDL_error.h>
#include <SDL3/SDL_keyboard.h>
#include <SDL3/SDL_render.h>
#include <SDL3/SDL_video.h>
#include <SDL3/SDL_begin_code.h>
@ -44,16 +49,15 @@ extern "C" {
/*
* Platform specific functions for Windows
*/
#if defined(SDL_PLATFORM_WIN32) || defined(SDL_PLATFORM_GDK)
#if defined(SDL_PLATFORM_WINDOWS)
typedef struct tagMSG MSG;
/**
* A callback to be used with SDL_SetWindowsMessageHook.
*
* This callback may modify the message, and should return SDL_TRUE if the
* message should continue to be processed, or SDL_FALSE to prevent further
* processing.
* This callback may modify the message, and should return true if the message
* should continue to be processed, or false to prevent further processing.
*
* As this is processing a message directly from the Windows event loop, this
* callback should do the minimum required work and return quickly.
@ -61,36 +65,35 @@ typedef struct tagMSG MSG;
* \param userdata the app-defined pointer provided to
* SDL_SetWindowsMessageHook.
* \param msg a pointer to a Win32 event structure to process.
* \returns SDL_TRUE to let event continue on, SDL_FALSE to drop it.
* \returns true to let event continue on, false to drop it.
*
* \threadsafety This may only be called (by SDL) from the thread handling the
* Windows event loop.
*
* \since This datatype is available since SDL 3.0.0.
* \since This datatype is available since SDL 3.2.0.
*
* \sa SDL_SetWindowsMessageHook
* \sa SDL_HINT_WINDOWS_ENABLE_MESSAGELOOP
*/
typedef SDL_bool (SDLCALL *SDL_WindowsMessageHook)(void *userdata, MSG *msg);
typedef bool (SDLCALL *SDL_WindowsMessageHook)(void *userdata, MSG *msg);
/**
* Set a callback for every Windows message, run before TranslateMessage().
*
* The callback may modify the message, and should return SDL_TRUE if the
* message should continue to be processed, or SDL_FALSE to prevent further
* processing.
* The callback may modify the message, and should return true if the message
* should continue to be processed, or false to prevent further processing.
*
* \param callback the SDL_WindowsMessageHook function to call.
* \param userdata a pointer to pass to every iteration of `callback`.
*
* \since This function is available since SDL 3.0.0.
* \since This function is available since SDL 3.2.0.
*
* \sa SDL_WindowsMessageHook
* \sa SDL_HINT_WINDOWS_ENABLE_MESSAGELOOP
*/
extern SDL_DECLSPEC void SDLCALL SDL_SetWindowsMessageHook(SDL_WindowsMessageHook callback, void *userdata);
#endif /* defined(SDL_PLATFORM_WIN32) || defined(SDL_PLATFORM_GDK) */
#endif /* defined(SDL_PLATFORM_WINDOWS) */
#if defined(SDL_PLATFORM_WIN32) || defined(SDL_PLATFORM_WINGDK)
@ -104,14 +107,10 @@ extern SDL_DECLSPEC void SDLCALL SDL_SetWindowsMessageHook(SDL_WindowsMessageHoo
* \returns the D3D9 adapter index on success or -1 on failure; call
* SDL_GetError() for more information.
*
* \since This function is available since SDL 3.0.0.
* \since This function is available since SDL 3.2.0.
*/
extern SDL_DECLSPEC int SDLCALL SDL_GetDirect3D9AdapterIndex(SDL_DisplayID displayID);
#endif /* defined(SDL_PLATFORM_WIN32) || defined(SDL_PLATFORM_WINGDK) */
#if defined(SDL_PLATFORM_WIN32) || defined(SDL_PLATFORM_WINGDK)
/**
* Get the DXGI Adapter and Output indices for the specified display.
*
@ -122,33 +121,55 @@ extern SDL_DECLSPEC int SDLCALL SDL_GetDirect3D9AdapterIndex(SDL_DisplayID displ
* \param displayID the instance of the display to query.
* \param adapterIndex a pointer to be filled in with the adapter index.
* \param outputIndex a pointer to be filled in with the output index.
* \returns SDL_TRUE on success or SDL_FALSE on failure; call SDL_GetError()
* for more information.
* \returns true on success or false on failure; call SDL_GetError() for more
* information.
*
* \since This function is available since SDL 3.0.0.
* \since This function is available since SDL 3.2.0.
*/
extern SDL_DECLSPEC SDL_bool SDLCALL SDL_GetDXGIOutputInfo(SDL_DisplayID displayID, int *adapterIndex, int *outputIndex);
extern SDL_DECLSPEC bool SDLCALL SDL_GetDXGIOutputInfo(SDL_DisplayID displayID, int *adapterIndex, int *outputIndex);
#endif /* defined(SDL_PLATFORM_WIN32) || defined(SDL_PLATFORM_WINGDK) */
/*
* Platform specific functions for UNIX
*/
/* this is defined in Xlib's headers, just need a simple declaration here. */
typedef union _XEvent XEvent;
typedef SDL_bool (SDLCALL *SDL_X11EventHook)(void *userdata, XEvent *xevent);
/**
* A callback to be used with SDL_SetX11EventHook.
*
* This callback may modify the event, and should return true if the event
* should continue to be processed, or false to prevent further processing.
*
* As this is processing an event directly from the X11 event loop, this
* callback should do the minimum required work and return quickly.
*
* \param userdata the app-defined pointer provided to SDL_SetX11EventHook.
* \param xevent a pointer to an Xlib XEvent union to process.
* \returns true to let event continue on, false to drop it.
*
* \threadsafety This may only be called (by SDL) from the thread handling the
* X11 event loop.
*
* \since This datatype is available since SDL 3.2.0.
*
* \sa SDL_SetX11EventHook
*/
typedef bool (SDLCALL *SDL_X11EventHook)(void *userdata, XEvent *xevent);
/**
* Set a callback for every X11 event.
*
* The callback may modify the event, and should return SDL_TRUE if the event
* should continue to be processed, or SDL_FALSE to prevent further
* processing.
* The callback may modify the event, and should return true if the event
* should continue to be processed, or false to prevent further processing.
*
* \param callback the SDL_X11EventHook function to call.
* \param userdata a pointer to pass to every iteration of `callback`.
*
* \since This function is available since SDL 3.0.0.
* \since This function is available since SDL 3.2.0.
*/
extern SDL_DECLSPEC void SDLCALL SDL_SetX11EventHook(SDL_X11EventHook callback, void *userdata);
@ -162,12 +183,12 @@ extern SDL_DECLSPEC void SDLCALL SDL_SetX11EventHook(SDL_X11EventHook callback,
*
* \param threadID the Unix thread ID to change priority of.
* \param priority the new, Unix-specific, priority value.
* \returns SDL_TRUE on success or SDL_FALSE on failure; call SDL_GetError()
* for more information.
* \returns true on success or false on failure; call SDL_GetError() for more
* information.
*
* \since This function is available since SDL 3.0.0.
* \since This function is available since SDL 3.2.0.
*/
extern SDL_DECLSPEC SDL_bool SDLCALL SDL_SetLinuxThreadPriority(Sint64 threadID, int priority);
extern SDL_DECLSPEC bool SDLCALL SDL_SetLinuxThreadPriority(Sint64 threadID, int priority);
/**
* Sets the priority (not nice level) and scheduling policy for a thread.
@ -178,12 +199,12 @@ extern SDL_DECLSPEC SDL_bool SDLCALL SDL_SetLinuxThreadPriority(Sint64 threadID,
* \param sdlPriority the new SDL_ThreadPriority value.
* \param schedPolicy the new scheduling policy (SCHED_FIFO, SCHED_RR,
* SCHED_OTHER, etc...).
* \returns SDL_TRUE on success or SDL_FALSE on failure; call SDL_GetError()
* for more information.
* \returns true on success or false on failure; call SDL_GetError() for more
* information.
*
* \since This function is available since SDL 3.0.0.
* \since This function is available since SDL 3.2.0.
*/
extern SDL_DECLSPEC SDL_bool SDLCALL SDL_SetLinuxThreadPriorityAndPolicy(Sint64 threadID, int sdlPriority, int schedPolicy);
extern SDL_DECLSPEC bool SDLCALL SDL_SetLinuxThreadPriorityAndPolicy(Sint64 threadID, int sdlPriority, int schedPolicy);
#endif /* SDL_PLATFORM_LINUX */
@ -204,7 +225,7 @@ extern SDL_DECLSPEC SDL_bool SDLCALL SDL_SetLinuxThreadPriorityAndPolicy(Sint64
* \param userdata what was passed as `callbackParam` to
* SDL_SetiOSAnimationCallback as `callbackParam`.
*
* \since This datatype is available since SDL 3.0.0.
* \since This datatype is available since SDL 3.2.0.
*
* \sa SDL_SetiOSAnimationCallback
*/
@ -240,27 +261,27 @@ typedef void (SDLCALL *SDL_iOSAnimationCallback)(void *userdata);
* called.
* \param callback the function to call for every frame.
* \param callbackParam a pointer that is passed to `callback`.
* \returns SDL_TRUE on success or SDL_FALSE on failure; call SDL_GetError()
* for more information.
* \returns true on success or false on failure; call SDL_GetError() for more
* information.
*
* \since This function is available since SDL 3.0.0.
* \since This function is available since SDL 3.2.0.
*
* \sa SDL_SetiOSEventPump
*/
extern SDL_DECLSPEC SDL_bool SDLCALL SDL_SetiOSAnimationCallback(SDL_Window *window, int interval, SDL_iOSAnimationCallback callback, void *callbackParam);
extern SDL_DECLSPEC bool SDLCALL SDL_SetiOSAnimationCallback(SDL_Window *window, int interval, SDL_iOSAnimationCallback callback, void *callbackParam);
/**
* Use this function to enable or disable the SDL event pump on Apple iOS.
*
* This function is only available on Apple iOS.
*
* \param enabled SDL_TRUE to enable the event pump, SDL_FALSE to disable it.
* \param enabled true to enable the event pump, false to disable it.
*
* \since This function is available since SDL 3.0.0.
* \since This function is available since SDL 3.2.0.
*
* \sa SDL_SetiOSAnimationCallback
*/
extern SDL_DECLSPEC void SDLCALL SDL_SetiOSEventPump(SDL_bool enabled);
extern SDL_DECLSPEC void SDLCALL SDL_SetiOSEventPump(bool enabled);
#endif /* SDL_PLATFORM_IOS */
@ -286,7 +307,7 @@ extern SDL_DECLSPEC void SDLCALL SDL_SetiOSEventPump(SDL_bool enabled);
*
* \threadsafety It is safe to call this function from any thread.
*
* \since This function is available since SDL 3.0.0.
* \since This function is available since SDL 3.2.0.
*
* \sa SDL_GetAndroidActivity
*/
@ -311,7 +332,7 @@ extern SDL_DECLSPEC void * SDLCALL SDL_GetAndroidJNIEnv(void);
*
* \threadsafety It is safe to call this function from any thread.
*
* \since This function is available since SDL 3.0.0.
* \since This function is available since SDL 3.2.0.
*
* \sa SDL_GetAndroidJNIEnv
*/
@ -349,43 +370,34 @@ extern SDL_DECLSPEC void * SDLCALL SDL_GetAndroidActivity(void);
*
* \returns the Android API level.
*
* \since This function is available since SDL 3.0.0.
* \since This function is available since SDL 3.2.0.
*/
extern SDL_DECLSPEC int SDLCALL SDL_GetAndroidSDKVersion(void);
/**
* Query if the application is running on Android TV.
*
* \returns SDL_TRUE if this is Android TV, SDL_FALSE otherwise.
*
* \since This function is available since SDL 3.0.0.
*/
extern SDL_DECLSPEC SDL_bool SDLCALL SDL_IsAndroidTV(void);
/**
* Query if the application is running on a Chromebook.
*
* \returns SDL_TRUE if this is a Chromebook, SDL_FALSE otherwise.
* \returns true if this is a Chromebook, false otherwise.
*
* \since This function is available since SDL 3.0.0.
* \since This function is available since SDL 3.2.0.
*/
extern SDL_DECLSPEC SDL_bool SDLCALL SDL_IsChromebook(void);
extern SDL_DECLSPEC bool SDLCALL SDL_IsChromebook(void);
/**
* Query if the application is running on a Samsung DeX docking station.
*
* \returns SDL_TRUE if this is a DeX docking station, SDL_FALSE otherwise.
* \returns true if this is a DeX docking station, false otherwise.
*
* \since This function is available since SDL 3.0.0.
* \since This function is available since SDL 3.2.0.
*/
extern SDL_DECLSPEC SDL_bool SDLCALL SDL_IsDeXMode(void);
extern SDL_DECLSPEC bool SDLCALL SDL_IsDeXMode(void);
/**
* Trigger the Android system back button behavior.
*
* \threadsafety It is safe to call this function from any thread.
*
* \since This function is available since SDL 3.0.0.
* \since This function is available since SDL 3.2.0.
*/
extern SDL_DECLSPEC void SDLCALL SDL_SendAndroidBackButton(void);
@ -393,9 +405,16 @@ extern SDL_DECLSPEC void SDLCALL SDL_SendAndroidBackButton(void);
* See the official Android developer guide for more information:
* http://developer.android.com/guide/topics/data/data-storage.html
*
* \since This macro is available since SDL 3.0.0.
* \since This macro is available since SDL 3.2.0.
*/
#define SDL_ANDROID_EXTERNAL_STORAGE_READ 0x01
/**
* See the official Android developer guide for more information:
* http://developer.android.com/guide/topics/data/data-storage.html
*
* \since This macro is available since SDL 3.2.0.
*/
#define SDL_ANDROID_EXTERNAL_STORAGE_WRITE 0x02
/**
@ -414,9 +433,10 @@ extern SDL_DECLSPEC void SDLCALL SDL_SendAndroidBackButton(void);
* \returns the path used for internal storage or NULL on failure; call
* SDL_GetError() for more information.
*
* \since This function is available since SDL 3.0.0.
* \since This function is available since SDL 3.2.0.
*
* \sa SDL_GetAndroidExternalStorageState
* \sa SDL_GetAndroidExternalStoragePath
* \sa SDL_GetAndroidCachePath
*/
extern SDL_DECLSPEC const char * SDLCALL SDL_GetAndroidInternalStoragePath(void);
@ -431,7 +451,7 @@ extern SDL_DECLSPEC const char * SDLCALL SDL_GetAndroidInternalStoragePath(void)
* \returns the current state of external storage, or 0 if external storage is
* currently unavailable.
*
* \since This function is available since SDL 3.0.0.
* \since This function is available since SDL 3.2.0.
*
* \sa SDL_GetAndroidExternalStoragePath
*/
@ -453,9 +473,11 @@ extern SDL_DECLSPEC Uint32 SDLCALL SDL_GetAndroidExternalStorageState(void);
* \returns the path used for external storage for this application on success
* or NULL on failure; call SDL_GetError() for more information.
*
* \since This function is available since SDL 3.0.0.
* \since This function is available since SDL 3.2.0.
*
* \sa SDL_GetAndroidExternalStorageState
* \sa SDL_GetAndroidInternalStoragePath
* \sa SDL_GetAndroidCachePath
*/
extern SDL_DECLSPEC const char * SDLCALL SDL_GetAndroidExternalStoragePath(void);
@ -474,12 +496,25 @@ extern SDL_DECLSPEC const char * SDLCALL SDL_GetAndroidExternalStoragePath(void)
* \returns the path used for caches for this application on success or NULL
* on failure; call SDL_GetError() for more information.
*
* \since This function is available since SDL 3.0.0.
* \since This function is available since SDL 3.2.0.
*
* \sa SDL_GetAndroidInternalStoragePath
* \sa SDL_GetAndroidExternalStoragePath
*/
extern SDL_DECLSPEC const char * SDLCALL SDL_GetAndroidCachePath(void);
typedef void (SDLCALL *SDL_RequestAndroidPermissionCallback)(void *userdata, const char *permission, SDL_bool granted);
/**
* Callback that presents a response from a SDL_RequestAndroidPermission call.
*
* \param userdata an app-controlled pointer that is passed to the callback.
* \param permission the Android-specific permission name that was requested.
* \param granted true if permission is granted, false if denied.
*
* \since This datatype is available since SDL 3.2.0.
*
* \sa SDL_RequestAndroidPermission
*/
typedef void (SDLCALL *SDL_RequestAndroidPermissionCallback)(void *userdata, const char *permission, bool granted);
/**
* Request permissions at runtime, asynchronously.
@ -500,18 +535,22 @@ typedef void (SDLCALL *SDL_RequestAndroidPermissionCallback)(void *userdata, con
* like memory running out. Normally there will be a yes or no to the request
* through the callback.
*
* For the `permission` parameter, choose a value from here:
*
* https://developer.android.com/reference/android/Manifest.permission
*
* \param permission the permission to request.
* \param cb the callback to trigger when the request has a response.
* \param userdata an app-controlled pointer that is passed to the callback.
* \returns SDL_TRUE if the request was submitted, SDL_FALSE if there was an
* error submitting. The result of the request is only ever reported
* \returns true if the request was submitted, false if there was an error
* submitting. The result of the request is only ever reported
* through the callback, not this return value.
*
* \threadsafety It is safe to call this function from any thread.
*
* \since This function is available since SDL 3.0.0.
* \since This function is available since SDL 3.2.0.
*/
extern SDL_DECLSPEC SDL_bool SDLCALL SDL_RequestAndroidPermission(const char *permission, SDL_RequestAndroidPermissionCallback cb, void *userdata);
extern SDL_DECLSPEC bool SDLCALL SDL_RequestAndroidPermission(const char *permission, SDL_RequestAndroidPermissionCallback cb, void *userdata);
/**
* Shows an Android toast notification.
@ -532,14 +571,14 @@ extern SDL_DECLSPEC SDL_bool SDLCALL SDL_RequestAndroidPermission(const char *pe
* \param gravity where the notification should appear on the screen.
* \param xoffset set this parameter only when gravity >=0.
* \param yoffset set this parameter only when gravity >=0.
* \returns SDL_TRUE on success or SDL_FALSE on failure; call SDL_GetError()
* for more information.
* \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.0.0.
* \since This function is available since SDL 3.2.0.
*/
extern SDL_DECLSPEC SDL_bool SDLCALL SDL_ShowAndroidToast(const char *message, int duration, int gravity, int xoffset, int yoffset);
extern SDL_DECLSPEC bool SDLCALL SDL_ShowAndroidToast(const char *message, int duration, int gravity, int xoffset, int yoffset);
/**
* Send a user command to SDLActivity.
@ -548,111 +587,63 @@ extern SDL_DECLSPEC SDL_bool SDLCALL SDL_ShowAndroidToast(const char *message, i
*
* \param command user command that must be greater or equal to 0x8000.
* \param param user parameter.
* \returns SDL_TRUE on success or SDL_FALSE on failure; call SDL_GetError()
* for more information.
* \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.0.0.
* \since This function is available since SDL 3.2.0.
*/
extern SDL_DECLSPEC SDL_bool SDLCALL SDL_SendAndroidMessage(Uint32 command, int param);
extern SDL_DECLSPEC bool SDLCALL SDL_SendAndroidMessage(Uint32 command, int param);
#endif /* SDL_PLATFORM_ANDROID */
/*
* Platform specific functions for WinRT
*/
#ifdef SDL_PLATFORM_WINRT
/**
* WinRT / Windows Phone path types
*
* \since This enum is available since SDL 3.0.0.
*/
typedef enum SDL_WinRT_Path
{
/** The installed app's root directory.
Files here are likely to be read-only. */
SDL_WINRT_PATH_INSTALLED_LOCATION,
/** The app's local data store. Files may be written here */
SDL_WINRT_PATH_LOCAL_FOLDER,
/** The app's roaming data store. Unsupported on Windows Phone.
Files written here may be copied to other machines via a network
connection.
*/
SDL_WINRT_PATH_ROAMING_FOLDER,
/** The app's temporary data store. Unsupported on Windows Phone.
Files written here may be deleted at any time. */
SDL_WINRT_PATH_TEMP_FOLDER
} SDL_WinRT_Path;
/**
* WinRT Device Family
*
* \since This enum is available since SDL 3.0.0.
*/
typedef enum SDL_WinRT_DeviceFamily
{
/** Unknown family */
SDL_WINRT_DEVICEFAMILY_UNKNOWN,
/** Desktop family*/
SDL_WINRT_DEVICEFAMILY_DESKTOP,
/** Mobile family (for example smartphone) */
SDL_WINRT_DEVICEFAMILY_MOBILE,
/** XBox family */
SDL_WINRT_DEVICEFAMILY_XBOX,
} SDL_WinRT_DeviceFamily;
/**
* Retrieve a WinRT defined path on the local file system.
*
* Not all paths are available on all versions of Windows. This is especially
* true on Windows Phone. Check the documentation for the given SDL_WinRT_Path
* for more information on which path types are supported where.
*
* Documentation on most app-specific path types on WinRT can be found on
* MSDN, at the URL:
*
* https://msdn.microsoft.com/en-us/library/windows/apps/hh464917.aspx
*
* \param pathType the type of path to retrieve, one of SDL_WinRT_Path.
* \returns a UTF-8 string (8-bit, multi-byte) containing the path, or NULL if
* the path is not available for any reason; call SDL_GetError() for
* more information.
*
* \since This function is available since SDL 3.0.0.
*/
extern SDL_DECLSPEC const char * SDLCALL SDL_GetWinRTFSPath(SDL_WinRT_Path pathType);
/**
* Detects the device family of WinRT platform at runtime.
*
* \returns a value from the SDL_WinRT_DeviceFamily enum.
*
* \since This function is available since SDL 3.0.0.
*/
extern SDL_DECLSPEC SDL_WinRT_DeviceFamily SDLCALL SDL_GetWinRTDeviceFamily();
#endif /* SDL_PLATFORM_WINRT */
/**
* Query if the current device is a tablet.
*
* If SDL can't determine this, it will return SDL_FALSE.
* If SDL can't determine this, it will return false.
*
* \returns SDL_TRUE if the device is a tablet, SDL_FALSE otherwise.
* \returns true if the device is a tablet, false otherwise.
*
* \since This function is available since SDL 3.0.0.
* \since This function is available since SDL 3.2.0.
*/
extern SDL_DECLSPEC SDL_bool SDLCALL SDL_IsTablet(void);
extern SDL_DECLSPEC bool SDLCALL SDL_IsTablet(void);
/**
* Query if the current device is a TV.
*
* If SDL can't determine this, it will return false.
*
* \returns true if the device is a TV, false otherwise.
*
* \since This function is available since SDL 3.2.0.
*/
extern SDL_DECLSPEC bool SDLCALL SDL_IsTV(void);
/**
* Application sandbox environment.
*
* \since This enum is available since SDL 3.2.0.
*/
typedef enum SDL_Sandbox
{
SDL_SANDBOX_NONE = 0,
SDL_SANDBOX_UNKNOWN_CONTAINER,
SDL_SANDBOX_FLATPAK,
SDL_SANDBOX_SNAP,
SDL_SANDBOX_MACOS
} SDL_Sandbox;
/**
* Get the application sandbox environment, if any.
*
* \returns the application sandbox environment or SDL_SANDBOX_NONE if the
* application is not running in a sandbox environment.
*
* \since This function is available since SDL 3.2.0.
*/
extern SDL_DECLSPEC SDL_Sandbox SDLCALL SDL_GetSandbox(void);
/* Functions used by iOS app delegates to notify SDL about state changes. */
@ -669,7 +660,7 @@ extern SDL_DECLSPEC SDL_bool SDLCALL SDL_IsTablet(void);
*
* \threadsafety It is safe to call this function from any thread.
*
* \since This function is available since SDL 3.0.0.
* \since This function is available since SDL 3.2.0.
*/
extern SDL_DECLSPEC void SDLCALL SDL_OnApplicationWillTerminate(void);
@ -686,7 +677,7 @@ extern SDL_DECLSPEC void SDLCALL SDL_OnApplicationWillTerminate(void);
*
* \threadsafety It is safe to call this function from any thread.
*
* \since This function is available since SDL 3.0.0.
* \since This function is available since SDL 3.2.0.
*/
extern SDL_DECLSPEC void SDLCALL SDL_OnApplicationDidReceiveMemoryWarning(void);
@ -703,7 +694,7 @@ extern SDL_DECLSPEC void SDLCALL SDL_OnApplicationDidReceiveMemoryWarning(void);
*
* \threadsafety It is safe to call this function from any thread.
*
* \since This function is available since SDL 3.0.0.
* \since This function is available since SDL 3.2.0.
*/
extern SDL_DECLSPEC void SDLCALL SDL_OnApplicationWillEnterBackground(void);
@ -720,7 +711,7 @@ extern SDL_DECLSPEC void SDLCALL SDL_OnApplicationWillEnterBackground(void);
*
* \threadsafety It is safe to call this function from any thread.
*
* \since This function is available since SDL 3.0.0.
* \since This function is available since SDL 3.2.0.
*/
extern SDL_DECLSPEC void SDLCALL SDL_OnApplicationDidEnterBackground(void);
@ -737,7 +728,7 @@ extern SDL_DECLSPEC void SDLCALL SDL_OnApplicationDidEnterBackground(void);
*
* \threadsafety It is safe to call this function from any thread.
*
* \since This function is available since SDL 3.0.0.
* \since This function is available since SDL 3.2.0.
*/
extern SDL_DECLSPEC void SDLCALL SDL_OnApplicationWillEnterForeground(void);
@ -754,7 +745,7 @@ extern SDL_DECLSPEC void SDLCALL SDL_OnApplicationWillEnterForeground(void);
*
* \threadsafety It is safe to call this function from any thread.
*
* \since This function is available since SDL 3.0.0.
* \since This function is available since SDL 3.2.0.
*/
extern SDL_DECLSPEC void SDLCALL SDL_OnApplicationDidEnterForeground(void);
@ -773,7 +764,7 @@ extern SDL_DECLSPEC void SDLCALL SDL_OnApplicationDidEnterForeground(void);
*
* \threadsafety It is safe to call this function from any thread.
*
* \since This function is available since SDL 3.0.0.
* \since This function is available since SDL 3.2.0.
*/
extern SDL_DECLSPEC void SDLCALL SDL_OnApplicationDidChangeStatusBarOrientation(void);
#endif
@ -794,12 +785,12 @@ typedef struct XUser *XUserHandle;
* leak.
*
* \param outTaskQueue a pointer to be filled in with task queue handle.
* \returns SDL_TRUE on success or SDL_FALSE on failure; call SDL_GetError()
* for more information.
* \returns true on success or false on failure; call SDL_GetError() for more
* information.
*
* \since This function is available since SDL 3.0.0.
* \since This function is available since SDL 3.2.0.
*/
extern SDL_DECLSPEC SDL_bool SDLCALL SDL_GetGDKTaskQueue(XTaskQueueHandle *outTaskQueue);
extern SDL_DECLSPEC bool SDLCALL SDL_GetGDKTaskQueue(XTaskQueueHandle *outTaskQueue);
/**
* Gets a reference to the default user handle for GDK.
@ -809,12 +800,12 @@ extern SDL_DECLSPEC SDL_bool SDLCALL SDL_GetGDKTaskQueue(XTaskQueueHandle *outTa
*
* \param outUserHandle a pointer to be filled in with the default user
* handle.
* \returns SDL_TRUE if success or SDL_FALSE on failure; call SDL_GetError()
* for more information.
* \returns true if success or false on failure; call SDL_GetError() for more
* information.
*
* \since This function is available since SDL 3.0.0.
* \since This function is available since SDL 3.2.0.
*/
extern SDL_DECLSPEC SDL_bool SDLCALL SDL_GetGDKDefaultUser(XUserHandle *outUserHandle);
extern SDL_DECLSPEC bool SDLCALL SDL_GetGDKDefaultUser(XUserHandle *outUserHandle);
#endif

View File

@ -1,6 +1,6 @@
/*
Simple DirectMedia Layer
Copyright (C) 1997-2024 Sam Lantinga <slouken@libsdl.org>
Copyright (C) 1997-2025 Sam Lantinga <slouken@libsdl.org>
This software is provided 'as-is', without any express or implied
warranty. In no event will the authors be held liable for any damages
@ -25,7 +25,19 @@
/**
* # CategoryThread
*
* SDL thread management routines.
* SDL offers cross-platform thread management functions. These are mostly
* concerned with starting threads, setting their priority, and dealing with
* their termination.
*
* In addition, there is support for Thread Local Storage (data that is unique
* to each thread, but accessed from a single key).
*
* On platforms without thread support (such as Emscripten when built without
* pthreads), these functions still exist, but things like SDL_CreateThread()
* 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.
*/
#include <SDL3/SDL_stdinc.h>
@ -34,9 +46,8 @@
/* Thread synchronization primitives */
#include <SDL3/SDL_atomic.h>
#include <SDL3/SDL_mutex.h>
#if (defined(SDL_PLATFORM_WIN32) || defined(SDL_PLATFORM_GDK)) && !defined(SDL_PLATFORM_WINRT)
#if defined(SDL_PLATFORM_WINDOWS)
#include <process.h> /* _beginthreadex() and _endthreadex() */
#endif
@ -51,7 +62,7 @@ extern "C" {
*
* These are opaque data.
*
* \since This datatype is available since SDL 3.0.0.
* \since This datatype is available since SDL 3.2.0.
*
* \sa SDL_CreateThread
* \sa SDL_WaitThread
@ -65,7 +76,7 @@ typedef struct SDL_Thread SDL_Thread;
* application will operate on, but having a way to uniquely identify a thread
* can be useful at times.
*
* \since This datatype is available since SDL 3.0.0.
* \since This datatype is available since SDL 3.2.0.
*
* \sa SDL_GetThreadID
* \sa SDL_GetCurrentThreadID
@ -78,7 +89,7 @@ typedef Uint64 SDL_ThreadID;
* 0 is the invalid ID. An app can create these and then set data for these
* IDs that is unique to each thread.
*
* \since This datatype is available since SDL 3.0.0.
* \since This datatype is available since SDL 3.2.0.
*
* \sa SDL_GetTLS
* \sa SDL_SetTLS
@ -90,11 +101,11 @@ typedef SDL_AtomicInt SDL_TLSID;
*
* SDL will make system changes as necessary in order to apply the thread
* priority. Code which attempts to control thread state related to priority
* should be aware that calling SDL_SetThreadPriority may alter such state.
* SDL_HINT_THREAD_PRIORITY_POLICY can be used to control aspects of this
* behavior.
* should be aware that calling SDL_SetCurrentThreadPriority may alter such
* state. SDL_HINT_THREAD_PRIORITY_POLICY can be used to control aspects of
* this behavior.
*
* \since This enum is available since SDL 3.0.0.
* \since This enum is available since SDL 3.2.0.
*/
typedef enum SDL_ThreadPriority {
SDL_THREAD_PRIORITY_LOW,
@ -103,13 +114,30 @@ typedef enum SDL_ThreadPriority {
SDL_THREAD_PRIORITY_TIME_CRITICAL
} SDL_ThreadPriority;
/**
* The SDL thread state.
*
* The current state of a thread can be checked by calling SDL_GetThreadState.
*
* \since This enum is available since SDL 3.2.0.
*
* \sa SDL_GetThreadState
*/
typedef enum SDL_ThreadState
{
SDL_THREAD_UNKNOWN, /**< The thread is not valid */
SDL_THREAD_ALIVE, /**< The thread is currently running */
SDL_THREAD_DETACHED, /**< The thread is detached and can't be waited on */
SDL_THREAD_COMPLETE /**< The thread has finished and should be cleaned up with SDL_WaitThread() */
} SDL_ThreadState;
/**
* The function passed to SDL_CreateThread() as the new thread's entry point.
*
* \param data what was passed as `data` to SDL_CreateThread().
* \returns a value that can be reported through SDL_WaitThread().
*
* \since This datatype is available since SDL 3.0.0.
* \since This datatype is available since SDL 3.2.0.
*/
typedef int (SDLCALL * SDL_ThreadFunction) (void *data);
@ -179,7 +207,7 @@ typedef int (SDLCALL * SDL_ThreadFunction) (void *data);
* new thread could not be created; call SDL_GetError() for more
* information.
*
* \since This function is available since SDL 3.0.0.
* \since This function is available since SDL 3.2.0.
*
* \sa SDL_CreateThreadWithProperties
* \sa SDL_WaitThread
@ -245,7 +273,7 @@ extern SDL_DECLSPEC SDL_Thread * SDLCALL SDL_CreateThread(SDL_ThreadFunction fn,
* new thread could not be created; call SDL_GetError() for more
* information.
*
* \since This function is available since SDL 3.0.0.
* \since This function is available since SDL 3.2.0.
*
* \sa SDL_CreateThread
* \sa SDL_WaitThread
@ -263,7 +291,7 @@ extern SDL_DECLSPEC SDL_Thread * SDLCALL SDL_CreateThreadWithProperties(SDL_Prop
/* The real implementation, hidden from the wiki, so it can show this as real functions that don't have macro magic. */
#ifndef SDL_WIKI_DOCUMENTATION_SECTION
# if (defined(SDL_PLATFORM_WIN32) || defined(SDL_PLATFORM_GDK)) && !defined(SDL_PLATFORM_WINRT)
# if defined(SDL_PLATFORM_WINDOWS)
# ifndef SDL_BeginThreadFunction
# define SDL_BeginThreadFunction _beginthreadex
# endif
@ -300,7 +328,7 @@ extern SDL_DECLSPEC SDL_Thread * SDLCALL SDL_CreateThreadWithProperties(SDL_Prop
* new thread could not be created; call SDL_GetError() for more
* information.
*
* \since This function is available since SDL 3.0.0.
* \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);
@ -314,7 +342,7 @@ extern SDL_DECLSPEC SDL_Thread * SDLCALL SDL_CreateThreadRuntime(SDL_ThreadFunct
* new thread could not be created; call SDL_GetError() for more
* information.
*
* \since This function is available since SDL 3.0.0.
* \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);
@ -334,7 +362,7 @@ 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.
*
* \since This function is available since SDL 3.0.0.
* \since This function is available since SDL 3.2.0.
*/
extern SDL_DECLSPEC const char * SDLCALL SDL_GetThreadName(SDL_Thread *thread);
@ -350,7 +378,7 @@ extern SDL_DECLSPEC const char * SDLCALL SDL_GetThreadName(SDL_Thread *thread);
*
* \returns the ID of the current thread.
*
* \since This function is available since SDL 3.0.0.
* \since This function is available since SDL 3.2.0.
*
* \sa SDL_GetThreadID
*/
@ -367,7 +395,7 @@ 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.
*
* \since This function is available since SDL 3.0.0.
* \since This function is available since SDL 3.2.0.
*
* \sa SDL_GetCurrentThreadID
*/
@ -381,25 +409,25 @@ extern SDL_DECLSPEC SDL_ThreadID SDLCALL SDL_GetThreadID(SDL_Thread *thread);
* an administrator account. Be prepared for this to fail.
*
* \param priority the SDL_ThreadPriority to set.
* \returns SDL_TRUE on success or SDL_FALSE on failure; call SDL_GetError()
* for more information.
* \returns true on success or false on failure; call SDL_GetError() for more
* information.
*
* \since This function is available since SDL 3.0.0.
* \since This function is available since SDL 3.2.0.
*/
extern SDL_DECLSPEC SDL_bool SDLCALL SDL_SetThreadPriority(SDL_ThreadPriority priority);
extern SDL_DECLSPEC bool SDLCALL SDL_SetCurrentThreadPriority(SDL_ThreadPriority priority);
/**
* Wait for a thread to finish.
*
* Threads that haven't been detached will remain (as a "zombie") until this
* function cleans them up. Not doing so is a resource leak.
* Threads that haven't been detached will remain until this function cleans
* them up. Not doing so is a resource leak.
*
* Once a thread has been cleaned up through this function, the SDL_Thread
* that references it becomes invalid and should not be referenced again. As
* such, only one thread may call SDL_WaitThread() on another.
*
* The return code for the thread function is placed in the area pointed to by
* `status`, if `status` is not NULL.
* The return code from the thread function is placed in the area pointed to
* by `status`, if `status` is not NULL.
*
* You may not wait on a thread that has been used in a call to
* SDL_DetachThread(). Use either that function or this one, but not both, or
@ -412,17 +440,30 @@ extern SDL_DECLSPEC SDL_bool SDLCALL SDL_SetThreadPriority(SDL_ThreadPriority pr
*
* \param thread the SDL_Thread pointer that was returned from the
* SDL_CreateThread() call that started this thread.
* \param status pointer to an integer that will receive the value returned
* from the thread function by its 'return', or NULL to not
* receive such value back.
* \param status a pointer filled in with the value returned from the thread
* function by its 'return', or -1 if the thread has been
* detached or isn't valid, may be NULL.
*
* \since This function is available since SDL 3.0.0.
* \since This function is available since SDL 3.2.0.
*
* \sa SDL_CreateThread
* \sa SDL_DetachThread
*/
extern SDL_DECLSPEC void SDLCALL SDL_WaitThread(SDL_Thread *thread, int *status);
/**
* Get the current state of a thread.
*
* \param thread the thread to query.
* \returns the current state of a thread, or SDL_THREAD_UNKNOWN if the thread
* isn't valid.
*
* \since This function is available since SDL 3.2.0.
*
* \sa SDL_ThreadState
*/
extern SDL_DECLSPEC SDL_ThreadState SDLCALL SDL_GetThreadState(SDL_Thread *thread);
/**
* Let a thread clean up on exit without intervention.
*
@ -452,7 +493,7 @@ extern SDL_DECLSPEC void SDLCALL SDL_WaitThread(SDL_Thread *thread, int *status)
* \param thread the SDL_Thread pointer that was returned from the
* SDL_CreateThread() call that started this thread.
*
* \since This function is available since SDL 3.0.0.
* \since This function is available since SDL 3.2.0.
*
* \sa SDL_CreateThread
* \sa SDL_WaitThread
@ -468,7 +509,7 @@ extern SDL_DECLSPEC void SDLCALL SDL_DetachThread(SDL_Thread *thread);
*
* \threadsafety It is safe to call this function from any thread.
*
* \since This function is available since SDL 3.0.0.
* \since This function is available since SDL 3.2.0.
*
* \sa SDL_SetTLS
*/
@ -481,7 +522,7 @@ extern SDL_DECLSPEC void * SDLCALL SDL_GetTLS(SDL_TLSID *id);
*
* \param value a pointer previously handed to SDL_SetTLS.
*
* \since This datatype is available since SDL 3.0.0.
* \since This datatype is available since SDL 3.2.0.
*
* \sa SDL_SetTLS
*/
@ -504,16 +545,16 @@ typedef void (SDLCALL *SDL_TLSDestructorCallback)(void *value);
* \param value the value to associate with the ID for the current thread.
* \param destructor a function called when the thread exits, to free the
* value, may be NULL.
* \returns SDL_TRUE on success or SDL_FALSE on failure; call SDL_GetError()
* for more information.
* \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.0.0.
* \since This function is available since SDL 3.2.0.
*
* \sa SDL_GetTLS
*/
extern SDL_DECLSPEC SDL_bool SDLCALL SDL_SetTLS(SDL_TLSID *id, const void *value, SDL_TLSDestructorCallback destructor);
extern SDL_DECLSPEC bool SDLCALL SDL_SetTLS(SDL_TLSID *id, const void *value, SDL_TLSDestructorCallback destructor);
/**
* Cleanup all TLS data for this thread.
@ -524,7 +565,7 @@ extern SDL_DECLSPEC SDL_bool SDLCALL SDL_SetTLS(SDL_TLSID *id, const void *value
*
* \threadsafety It is safe to call this function from any thread.
*
* \since This function is available since SDL 3.0.0.
* \since This function is available since SDL 3.2.0.
*/
extern SDL_DECLSPEC void SDLCALL SDL_CleanupTLS(void);

View File

@ -1,6 +1,6 @@
/*
Simple DirectMedia Layer
Copyright (C) 1997-2024 Sam Lantinga <slouken@libsdl.org>
Copyright (C) 1997-2025 Sam Lantinga <slouken@libsdl.org>
This software is provided 'as-is', without any express or implied
warranty. In no event will the authors be held liable for any damages
@ -26,6 +26,14 @@ freely, subject to the following restrictions:
* # CategoryTime
*
* SDL realtime clock and date/time routines.
*
* There are two data types that are used in this category: SDL_Time, which
* represents the nanoseconds since a specific moment (an "epoch"), and
* SDL_DateTime, which breaks time down into human-understandable components:
* years, months, days, hours, etc.
*
* Much of the functionality is involved in converting those two types to
* other useful forms.
*/
#include <SDL3/SDL_error.h>
@ -41,7 +49,7 @@ extern "C" {
* A structure holding a calendar date and time broken down into its
* components.
*
* \since This struct is available since SDL 3.0.0.
* \since This struct is available since SDL 3.2.0.
*/
typedef struct SDL_DateTime
{
@ -59,7 +67,7 @@ typedef struct SDL_DateTime
/**
* The preferred date format of the current system locale.
*
* \since This enum is available since SDL 3.0.0.
* \since This enum is available since SDL 3.2.0.
*
* \sa SDL_GetDateTimeLocalePreferences
*/
@ -73,7 +81,7 @@ typedef enum SDL_DateFormat
/**
* The preferred time format of the current system locale.
*
* \since This enum is available since SDL 3.0.0.
* \since This enum is available since SDL 3.2.0.
*
* \sa SDL_GetDateTimeLocalePreferences
*/
@ -95,24 +103,24 @@ typedef enum SDL_TimeFormat
* format, may be NULL.
* \param timeFormat a pointer to the SDL_TimeFormat to hold the returned time
* format, may be NULL.
* \returns SDL_TRUE on success or SDL_FALSE on failure; call SDL_GetError()
* for more information.
* \returns true on success or false on failure; call SDL_GetError() for more
* information.
*
* \since This function is available since SDL 3.0.0.
* \since This function is available since SDL 3.2.0.
*/
extern SDL_DECLSPEC SDL_bool SDLCALL SDL_GetDateTimeLocalePreferences(SDL_DateFormat *dateFormat, SDL_TimeFormat *timeFormat);
extern SDL_DECLSPEC bool SDLCALL SDL_GetDateTimeLocalePreferences(SDL_DateFormat *dateFormat, SDL_TimeFormat *timeFormat);
/**
* Gets the current value of the system realtime clock in nanoseconds since
* Jan 1, 1970 in Universal Coordinated Time (UTC).
*
* \param ticks the SDL_Time to hold the returned tick count.
* \returns SDL_TRUE on success or SDL_FALSE on failure; call SDL_GetError()
* for more information.
* \returns true on success or false on failure; call SDL_GetError() for more
* information.
*
* \since This function is available since SDL 3.0.0.
* \since This function is available since SDL 3.2.0.
*/
extern SDL_DECLSPEC SDL_bool SDLCALL SDL_GetCurrentTime(SDL_Time *ticks);
extern SDL_DECLSPEC bool SDLCALL SDL_GetCurrentTime(SDL_Time *ticks);
/**
* Converts an SDL_Time in nanoseconds since the epoch to a calendar time in
@ -123,12 +131,12 @@ extern SDL_DECLSPEC SDL_bool SDLCALL SDL_GetCurrentTime(SDL_Time *ticks);
* \param localTime the resulting SDL_DateTime will be expressed in local time
* if true, otherwise it will be in Universal Coordinated
* Time (UTC).
* \returns SDL_TRUE on success or SDL_FALSE on failure; call SDL_GetError()
* for more information.
* \returns true on success or false on failure; call SDL_GetError() for more
* information.
*
* \since This function is available since SDL 3.0.0.
* \since This function is available since SDL 3.2.0.
*/
extern SDL_DECLSPEC SDL_bool SDLCALL SDL_TimeToDateTime(SDL_Time ticks, SDL_DateTime *dt, SDL_bool localTime);
extern SDL_DECLSPEC bool SDLCALL SDL_TimeToDateTime(SDL_Time ticks, SDL_DateTime *dt, bool localTime);
/**
* Converts a calendar time to an SDL_Time in nanoseconds since the epoch.
@ -138,12 +146,12 @@ extern SDL_DECLSPEC SDL_bool SDLCALL SDL_TimeToDateTime(SDL_Time ticks, SDL_Date
*
* \param dt the source SDL_DateTime.
* \param ticks the resulting SDL_Time.
* \returns SDL_TRUE on success or SDL_FALSE on failure; call SDL_GetError()
* for more information.
* \returns true on success or false on failure; call SDL_GetError() for more
* information.
*
* \since This function is available since SDL 3.0.0.
* \since This function is available since SDL 3.2.0.
*/
extern SDL_DECLSPEC SDL_bool SDLCALL SDL_DateTimeToTime(const SDL_DateTime *dt, SDL_Time *ticks);
extern SDL_DECLSPEC bool SDLCALL SDL_DateTimeToTime(const SDL_DateTime *dt, SDL_Time *ticks);
/**
* Converts an SDL time into a Windows FILETIME (100-nanosecond intervals
@ -157,7 +165,7 @@ extern SDL_DECLSPEC SDL_bool SDLCALL SDL_DateTimeToTime(const SDL_DateTime *dt,
* \param dwHighDateTime a pointer filled in with the high portion of the
* Windows FILETIME value.
*
* \since This function is available since SDL 3.0.0.
* \since This function is available since SDL 3.2.0.
*/
extern SDL_DECLSPEC void SDLCALL SDL_TimeToWindows(SDL_Time ticks, Uint32 *dwLowDateTime, Uint32 *dwHighDateTime);
@ -172,7 +180,7 @@ 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.
*
* \since This function is available since SDL 3.0.0.
* \since This function is available since SDL 3.2.0.
*/
extern SDL_DECLSPEC SDL_Time SDLCALL SDL_TimeFromWindows(Uint32 dwLowDateTime, Uint32 dwHighDateTime);
@ -184,7 +192,7 @@ 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.
*
* \since This function is available since SDL 3.0.0.
* \since This function is available since SDL 3.2.0.
*/
extern SDL_DECLSPEC int SDLCALL SDL_GetDaysInMonth(int year, int month);
@ -197,7 +205,7 @@ 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.
*
* \since This function is available since SDL 3.0.0.
* \since This function is available since SDL 3.2.0.
*/
extern SDL_DECLSPEC int SDLCALL SDL_GetDayOfYear(int year, int month, int day);
@ -210,7 +218,7 @@ 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.
*
* \since This function is available since SDL 3.0.0.
* \since This function is available since SDL 3.2.0.
*/
extern SDL_DECLSPEC int SDLCALL SDL_GetDayOfWeek(int year, int month, int day);

View File

@ -1,6 +1,6 @@
/*
Simple DirectMedia Layer
Copyright (C) 1997-2024 Sam Lantinga <slouken@libsdl.org>
Copyright (C) 1997-2025 Sam Lantinga <slouken@libsdl.org>
This software is provided 'as-is', without any express or implied
warranty. In no event will the authors be held liable for any damages
@ -25,7 +25,20 @@
/**
* # CategoryTimer
*
* SDL time management routines.
* SDL provides time management functionality. It is useful for dealing with
* (usually) small durations of time.
*
* This is not to be confused with _calendar time_ management, which is
* provided by [CategoryTime](CategoryTime).
*
* 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
* (SDL_AddTimer(), etc).
*
* There are also useful macros to convert between time units, like
* SDL_SECONDS_TO_NS() and such.
*/
#include <SDL3/SDL_stdinc.h>
@ -38,16 +51,137 @@ extern "C" {
#endif
/* SDL time constants */
/**
* Number of milliseconds in a second.
*
* This is always 1000.
*
* \since This macro is available since SDL 3.2.0.
*/
#define SDL_MS_PER_SECOND 1000
/**
* Number of microseconds in a second.
*
* This is always 1000000.
*
* \since This macro is available since SDL 3.2.0.
*/
#define SDL_US_PER_SECOND 1000000
/**
* Number of nanoseconds in a second.
*
* This is always 1000000000.
*
* \since This macro is available since SDL 3.2.0.
*/
#define SDL_NS_PER_SECOND 1000000000LL
/**
* Number of nanoseconds in a millisecond.
*
* This is always 1000000.
*
* \since This macro is available since SDL 3.2.0.
*/
#define SDL_NS_PER_MS 1000000
/**
* Number of nanoseconds in a microsecond.
*
* This is always 1000.
*
* \since This macro is available since SDL 3.2.0.
*/
#define SDL_NS_PER_US 1000
/**
* Convert seconds to nanoseconds.
*
* This only converts whole numbers, not fractional seconds.
*
* \param S the number of seconds to convert.
* \returns S, expressed in nanoseconds.
*
* \threadsafety It is safe to call this macro from any thread.
*
* \since This macro is available since SDL 3.2.0.
*/
#define SDL_SECONDS_TO_NS(S) (((Uint64)(S)) * SDL_NS_PER_SECOND)
/**
* Convert nanoseconds to seconds.
*
* This performs a division, so the results can be dramatically different if
* `NS` is an integer or floating point value.
*
* \param NS the number of nanoseconds to convert.
* \returns NS, expressed in seconds.
*
* \threadsafety It is safe to call this macro from any thread.
*
* \since This macro is available since SDL 3.2.0.
*/
#define SDL_NS_TO_SECONDS(NS) ((NS) / SDL_NS_PER_SECOND)
/**
* Convert milliseconds to nanoseconds.
*
* This only converts whole numbers, not fractional milliseconds.
*
* \param MS the number of milliseconds to convert.
* \returns MS, expressed in nanoseconds.
*
* \threadsafety It is safe to call this macro from any thread.
*
* \since This macro is available since SDL 3.2.0.
*/
#define SDL_MS_TO_NS(MS) (((Uint64)(MS)) * SDL_NS_PER_MS)
/**
* Convert nanoseconds to milliseconds.
*
* This performs a division, so the results can be dramatically different if
* `NS` is an integer or floating point value.
*
* \param NS the number of nanoseconds to convert.
* \returns NS, expressed in milliseconds.
*
* \threadsafety It is safe to call this macro from any thread.
*
* \since This macro is available since SDL 3.2.0.
*/
#define SDL_NS_TO_MS(NS) ((NS) / SDL_NS_PER_MS)
/**
* Convert microseconds to nanoseconds.
*
* This only converts whole numbers, not fractional microseconds.
*
* \param US the number of microseconds to convert.
* \returns US, expressed in nanoseconds.
*
* \threadsafety It is safe to call this macro from any thread.
*
* \since This macro is available since SDL 3.2.0.
*/
#define SDL_US_TO_NS(US) (((Uint64)(US)) * SDL_NS_PER_US)
/**
* Convert nanoseconds to microseconds.
*
* This performs a division, so the results can be dramatically different if
* `NS` is an integer or floating point value.
*
* \param NS the number of nanoseconds to convert.
* \returns NS, expressed in microseconds.
*
* \threadsafety It is safe to call this macro from any thread.
*
* \since This macro is available since SDL 3.2.0.
*/
#define SDL_NS_TO_US(NS) ((NS) / SDL_NS_PER_US)
/**
@ -56,7 +190,9 @@ extern "C" {
* \returns an unsigned 64-bit value representing the number of milliseconds
* since the SDL library initialized.
*
* \since This function is available since SDL 3.0.0.
* \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_GetTicks(void);
@ -66,7 +202,9 @@ extern SDL_DECLSPEC Uint64 SDLCALL SDL_GetTicks(void);
* \returns an unsigned 64-bit value representing the number of nanoseconds
* since the SDL library initialized.
*
* \since This function is available since SDL 3.0.0.
* \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_GetTicksNS(void);
@ -81,7 +219,9 @@ extern SDL_DECLSPEC Uint64 SDLCALL SDL_GetTicksNS(void);
*
* \returns the current counter value.
*
* \since This function is available since SDL 3.0.0.
* \threadsafety It is safe to call this function from any thread.
*
* \since This function is available since SDL 3.2.0.
*
* \sa SDL_GetPerformanceFrequency
*/
@ -92,7 +232,9 @@ extern SDL_DECLSPEC Uint64 SDLCALL SDL_GetPerformanceCounter(void);
*
* \returns a platform-specific count per second.
*
* \since This function is available since SDL 3.0.0.
* \threadsafety It is safe to call this function from any thread.
*
* \since This function is available since SDL 3.2.0.
*
* \sa SDL_GetPerformanceCounter
*/
@ -107,10 +249,33 @@ extern SDL_DECLSPEC Uint64 SDLCALL SDL_GetPerformanceFrequency(void);
*
* \param ms the number of milliseconds to delay.
*
* \since This function is available since SDL 3.0.0.
* \threadsafety It is safe to call this function from any thread.
*
* \since This function is available since SDL 3.2.0.
*
* \sa SDL_DelayNS
* \sa SDL_DelayPrecise
*/
extern SDL_DECLSPEC void SDLCALL SDL_Delay(Uint32 ms);
/**
* Wait a specified number of nanoseconds before returning.
*
* This function waits a specified number of nanoseconds before returning. It
* waits at least the specified time, but possibly longer due to OS
* scheduling.
*
* \param ns the number of nanoseconds to delay.
*
* \threadsafety It is safe to call this function from any thread.
*
* \since This function is available since SDL 3.2.0.
*
* \sa SDL_Delay
* \sa SDL_DelayPrecise
*/
extern SDL_DECLSPEC void SDLCALL SDL_DelayNS(Uint64 ns);
/**
* Wait a specified number of nanoseconds before returning.
*
@ -120,14 +285,19 @@ extern SDL_DECLSPEC void SDLCALL SDL_Delay(Uint32 ms);
*
* \param ns the number of nanoseconds to delay.
*
* \since This function is available since SDL 3.0.0.
* \threadsafety It is safe to call this function from any thread.
*
* \since This function is available since SDL 3.2.0.
*
* \sa SDL_Delay
* \sa SDL_DelayNS
*/
extern SDL_DECLSPEC void SDLCALL SDL_DelayNS(Uint64 ns);
extern SDL_DECLSPEC void SDLCALL SDL_DelayPrecise(Uint64 ns);
/**
* Definition of the timer ID type.
*
* \since This datatype is available since SDL 3.0.0.
* \since This datatype is available since SDL 3.2.0.
*/
typedef Uint32 SDL_TimerID;
@ -151,7 +321,7 @@ typedef Uint32 SDL_TimerID;
* thread; the application is responsible for locking resources
* the callback touches that need to be protected.
*
* \since This datatype is available since SDL 3.0.0.
* \since This datatype is available since SDL 3.2.0.
*
* \sa SDL_AddTimer
*/
@ -160,8 +330,6 @@ typedef Uint32 (SDLCALL *SDL_TimerCallback)(void *userdata, SDL_TimerID timerID,
/**
* Call a callback function at a future time.
*
* If you use this function, you must pass `SDL_INIT_TIMER` to SDL_Init().
*
* The callback function is passed the current timer interval and the user
* supplied parameter from the SDL_AddTimer() call and should return the next
* timer interval. If the value returned from the callback is 0, the timer is
@ -188,7 +356,7 @@ typedef Uint32 (SDLCALL *SDL_TimerCallback)(void *userdata, SDL_TimerID timerID,
*
* \threadsafety It is safe to call this function from any thread.
*
* \since This function is available since SDL 3.0.0.
* \since This function is available since SDL 3.2.0.
*
* \sa SDL_AddTimerNS
* \sa SDL_RemoveTimer
@ -215,7 +383,7 @@ extern SDL_DECLSPEC SDL_TimerID SDLCALL SDL_AddTimer(Uint32 interval, SDL_TimerC
* thread; the application is responsible for locking resources
* the callback touches that need to be protected.
*
* \since This datatype is available since SDL 3.0.0.
* \since This datatype is available since SDL 3.2.0.
*
* \sa SDL_AddTimerNS
*/
@ -224,8 +392,6 @@ typedef Uint64 (SDLCALL *SDL_NSTimerCallback)(void *userdata, SDL_TimerID timerI
/**
* Call a callback function at a future time.
*
* If you use this function, you must pass `SDL_INIT_TIMER` to SDL_Init().
*
* The callback function is passed the current timer interval and the user
* supplied parameter from the SDL_AddTimerNS() call and should return the
* next timer interval. If the value returned from the callback is 0, the
@ -252,7 +418,7 @@ typedef Uint64 (SDLCALL *SDL_NSTimerCallback)(void *userdata, SDL_TimerID timerI
*
* \threadsafety It is safe to call this function from any thread.
*
* \since This function is available since SDL 3.0.0.
* \since This function is available since SDL 3.2.0.
*
* \sa SDL_AddTimer
* \sa SDL_RemoveTimer
@ -263,14 +429,16 @@ extern SDL_DECLSPEC SDL_TimerID SDLCALL SDL_AddTimerNS(Uint64 interval, SDL_NSTi
* Remove a timer created with SDL_AddTimer().
*
* \param id the ID of the timer to remove.
* \returns SDL_TRUE on success or SDL_FALSE on failure; call SDL_GetError()
* for more information.
* \returns true on success or false on failure; call SDL_GetError() for more
* information.
*
* \since This function is available since SDL 3.0.0.
* \threadsafety It is safe to call this function from any thread.
*
* \since This function is available since SDL 3.2.0.
*
* \sa SDL_AddTimer
*/
extern SDL_DECLSPEC SDL_bool SDLCALL SDL_RemoveTimer(SDL_TimerID id);
extern SDL_DECLSPEC bool SDLCALL SDL_RemoveTimer(SDL_TimerID id);
/* Ends C function definitions when using C++ */

View File

@ -1,6 +1,6 @@
/*
Simple DirectMedia Layer
Copyright (C) 1997-2024 Sam Lantinga <slouken@libsdl.org>
Copyright (C) 1997-2025 Sam Lantinga <slouken@libsdl.org>
This software is provided 'as-is', without any express or implied
warranty. In no event will the authors be held liable for any damages
@ -22,7 +22,18 @@
/**
* # CategoryTouch
*
* SDL touch management.
* SDL offers touch input, on platforms that support it. It can manage
* multiple touch devices and track multiple fingers on those devices.
*
* Touches are mostly dealt with through the event system, in the
* SDL_EVENT_FINGER_DOWN, SDL_EVENT_FINGER_MOTION, and SDL_EVENT_FINGER_UP
* events, but there are also functions to query for hardware details, etc.
*
* The touch system, by default, will also send virtual mouse events; this can
* be useful for making a some desktop apps work on a phone without
* significant changes. For apps that care about mouse and touch input
* separately, they should ignore mouse events that have a `which` field of
* SDL_TOUCH_MOUSEID.
*/
#ifndef SDL_touch_h_
@ -31,7 +42,6 @@
#include <SDL3/SDL_stdinc.h>
#include <SDL3/SDL_error.h>
#include <SDL3/SDL_mouse.h>
#include <SDL3/SDL_video.h>
#include <SDL3/SDL_begin_code.h>
/* Set up for C function definitions, even when using C++ */
@ -39,25 +49,53 @@
extern "C" {
#endif
/**
* A unique ID for a touch device.
*
* This ID is valid for the time the device is connected to the system, and is
* never reused for the lifetime of the application.
*
* The value 0 is an invalid ID.
*
* \since This datatype is available since SDL 3.2.0.
*/
typedef Uint64 SDL_TouchID;
/**
* A unique ID for a single finger on a touch device.
*
* This ID is valid for the time the finger (stylus, etc) is touching and will
* be unique for all fingers currently in contact, so this ID tracks the
* lifetime of a single continuous touch. This value may represent an index, a
* pointer, or some other unique ID, depending on the platform.
*
* The value 0 is an invalid ID.
*
* \since This datatype is available since SDL 3.2.0.
*/
typedef Uint64 SDL_FingerID;
/**
* An enum that describes the type of a touch device.
*
* \since This enum is available since SDL 3.2.0.
*/
typedef enum SDL_TouchDeviceType
{
SDL_TOUCH_DEVICE_INVALID = -1,
SDL_TOUCH_DEVICE_DIRECT, /* touch screen with window-relative coordinates */
SDL_TOUCH_DEVICE_INDIRECT_ABSOLUTE, /* trackpad with absolute device coordinates */
SDL_TOUCH_DEVICE_INDIRECT_RELATIVE /* trackpad with screen cursor-relative coordinates */
SDL_TOUCH_DEVICE_DIRECT, /**< touch screen with window-relative coordinates */
SDL_TOUCH_DEVICE_INDIRECT_ABSOLUTE, /**< trackpad with absolute device coordinates */
SDL_TOUCH_DEVICE_INDIRECT_RELATIVE /**< trackpad with screen cursor-relative coordinates */
} SDL_TouchDeviceType;
/**
* Data about a single finger in a multitouch event.
*
* Each touch even is a collection of fingers that are simultaneously in
* Each touch event is a collection of fingers that are simultaneously in
* contact with the touch device (so a "touch" can be a "multitouch," in
* reality), and this struct reports details of the specific fingers.
*
* \since This struct is available since SDL 3.0.0.
* \since This struct is available since SDL 3.2.0.
*
* \sa SDL_GetTouchFingers
*/
@ -69,10 +107,18 @@ typedef struct SDL_Finger
float pressure; /**< the quantity of pressure applied, normalized (0...1) */
} SDL_Finger;
/* Used as the device ID for mouse events simulated with touch input */
/**
* The SDL_MouseID for mouse events simulated with touch input.
*
* \since This macro is available since SDL 3.2.0.
*/
#define SDL_TOUCH_MOUSEID ((SDL_MouseID)-1)
/* Used as the SDL_TouchID for touch events simulated with mouse input */
/**
* The SDL_TouchID for touch events simulated with mouse input.
*
* \since This macro is available since SDL 3.2.0.
*/
#define SDL_MOUSE_TOUCHID ((SDL_TouchID)-1)
@ -89,7 +135,7 @@ typedef struct SDL_Finger
* SDL_GetError() for more information. This should be freed with
* SDL_free() when it is no longer needed.
*
* \since This function is available since SDL 3.0.0.
* \since This function is available since SDL 3.2.0.
*/
extern SDL_DECLSPEC SDL_TouchID * SDLCALL SDL_GetTouchDevices(int *count);
@ -100,7 +146,7 @@ extern SDL_DECLSPEC SDL_TouchID * SDLCALL SDL_GetTouchDevices(int *count);
* \returns touch device name, or NULL on failure; call SDL_GetError() for
* more information.
*
* \since This function is available since SDL 3.0.0.
* \since This function is available since SDL 3.2.0.
*/
extern SDL_DECLSPEC const char * SDLCALL SDL_GetTouchDeviceName(SDL_TouchID touchID);
@ -110,7 +156,7 @@ extern SDL_DECLSPEC const char * SDLCALL SDL_GetTouchDeviceName(SDL_TouchID touc
* \param touchID the ID of a touch device.
* \returns touch device type.
*
* \since This function is available since SDL 3.0.0.
* \since This function is available since SDL 3.2.0.
*/
extern SDL_DECLSPEC SDL_TouchDeviceType SDLCALL SDL_GetTouchDeviceType(SDL_TouchID touchID);
@ -125,7 +171,7 @@ extern SDL_DECLSPEC SDL_TouchDeviceType SDLCALL SDL_GetTouchDeviceType(SDL_Touch
* allocation that should be freed with SDL_free() when it is no
* longer needed.
*
* \since This function is available since SDL 3.0.0.
* \since This function is available since SDL 3.2.0.
*/
extern SDL_DECLSPEC SDL_Finger ** SDLCALL SDL_GetTouchFingers(SDL_TouchID touchID, int *count);

View File

@ -0,0 +1,544 @@
/*
Simple DirectMedia Layer
Copyright (C) 1997-2025 Sam Lantinga <slouken@libsdl.org>
This software is provided 'as-is', without any express or implied
warranty. In no event will the authors be held liable for any damages
arising from the use of this software.
Permission is granted to anyone to use this software for any purpose,
including commercial applications, and to alter it and redistribute it
freely, subject to the following restrictions:
1. The origin of this software must not be misrepresented; you must not
claim that you wrote the original software. If you use this software
in a product, an acknowledgment in the product documentation would be
appreciated but is not required.
2. Altered source versions must be plainly marked as such, and must not be
misrepresented as being the original software.
3. This notice may not be removed or altered from any source distribution.
*/
/**
* # CategoryTray
*
* SDL offers a way to add items to the "system tray" (more correctly called
* the "notification area" on Windows). On platforms that offer this concept,
* an SDL app can add a tray icon, submenus, checkboxes, and clickable
* entries, and register a callback that is fired when the user clicks on
* these pieces.
*/
#ifndef SDL_tray_h_
#define SDL_tray_h_
#include <SDL3/SDL_stdinc.h>
#include <SDL3/SDL_error.h>
#include <SDL3/SDL_surface.h>
#include <SDL3/SDL_video.h>
#include <SDL3/SDL_begin_code.h>
/* Set up for C function definitions, even when using C++ */
#ifdef __cplusplus
extern "C" {
#endif
/**
* An opaque handle representing a toplevel system tray object.
*
* \since This struct is available since SDL 3.2.0.
*/
typedef struct SDL_Tray SDL_Tray;
/**
* An opaque handle representing a menu/submenu on a system tray object.
*
* \since This struct is available since SDL 3.2.0.
*/
typedef struct SDL_TrayMenu SDL_TrayMenu;
/**
* An opaque handle representing an entry on a system tray object.
*
* \since This struct is available since SDL 3.2.0.
*/
typedef struct SDL_TrayEntry SDL_TrayEntry;
/**
* Flags that control the creation of system tray entries.
*
* Some of these flags are required; exactly one of them must be specified at
* the time a tray entry is created. Other flags are optional; zero or more of
* those can be OR'ed together with the required flag.
*
* \since This datatype is available since SDL 3.2.0.
*
* \sa SDL_InsertTrayEntryAt
*/
typedef Uint32 SDL_TrayEntryFlags;
#define SDL_TRAYENTRY_BUTTON 0x00000001u /**< Make the entry a simple button. Required. */
#define SDL_TRAYENTRY_CHECKBOX 0x00000002u /**< Make the entry a checkbox. Required. */
#define SDL_TRAYENTRY_SUBMENU 0x00000004u /**< Prepare the entry to have a submenu. Required */
#define SDL_TRAYENTRY_DISABLED 0x80000000u /**< Make the entry disabled. Optional. */
#define SDL_TRAYENTRY_CHECKED 0x40000000u /**< Make the entry checked. This is valid only for checkboxes. Optional. */
/**
* A callback that is invoked when a tray entry is selected.
*
* \param userdata an optional pointer to pass extra data to the callback when
* it will be invoked.
* \param entry the tray entry that was selected.
*
* \since This datatype is available since SDL 3.2.0.
*
* \sa SDL_SetTrayEntryCallback
*/
typedef void (SDLCALL *SDL_TrayCallback)(void *userdata, SDL_TrayEntry *entry);
/**
* Create an icon to be placed in the operating system's tray, or equivalent.
*
* Many platforms advise not using a system tray unless persistence is a
* necessary feature. Avoid needlessly creating a tray icon, as the user may
* feel like it clutters their interface.
*
* Using tray icons require the video subsystem.
*
* \param icon a surface to be used as icon. May be NULL.
* \param tooltip a tooltip to be displayed when the mouse hovers the icon in
* UTF-8 encoding. Not supported on all platforms. May be NULL.
* \returns The newly created system tray icon.
*
* \threadsafety This function should only be called on the main thread.
*
* \since This function is available since SDL 3.2.0.
*
* \sa SDL_CreateTrayMenu
* \sa SDL_GetTrayMenu
* \sa SDL_DestroyTray
*/
extern SDL_DECLSPEC SDL_Tray *SDLCALL SDL_CreateTray(SDL_Surface *icon, const char *tooltip);
/**
* Updates the system tray icon's icon.
*
* \param tray the tray icon to be updated.
* \param icon the new icon. May be NULL.
*
* \threadsafety This function should be called on the thread that created the
* tray.
*
* \since This function is available since SDL 3.2.0.
*
* \sa SDL_CreateTray
*/
extern SDL_DECLSPEC void SDLCALL SDL_SetTrayIcon(SDL_Tray *tray, SDL_Surface *icon);
/**
* Updates the system tray icon's tooltip.
*
* \param tray the tray icon to be updated.
* \param tooltip the new tooltip in UTF-8 encoding. May be NULL.
*
* \threadsafety This function should be called on the thread that created the
* tray.
*
* \since This function is available since SDL 3.2.0.
*
* \sa SDL_CreateTray
*/
extern SDL_DECLSPEC void SDLCALL SDL_SetTrayTooltip(SDL_Tray *tray, const char *tooltip);
/**
* Create a menu for a system tray.
*
* This should be called at most once per tray icon.
*
* This function does the same thing as SDL_CreateTraySubmenu(), except that
* it takes a SDL_Tray instead of a SDL_TrayEntry.
*
* A menu does not need to be destroyed; it will be destroyed with the tray.
*
* \param tray the tray to bind the menu to.
* \returns the newly created menu.
*
* \threadsafety This function should be called on the thread that created the
* tray.
*
* \since This function is available since SDL 3.2.0.
*
* \sa SDL_CreateTray
* \sa SDL_GetTrayMenu
* \sa SDL_GetTrayMenuParentTray
*/
extern SDL_DECLSPEC SDL_TrayMenu *SDLCALL SDL_CreateTrayMenu(SDL_Tray *tray);
/**
* Create a submenu for a system tray entry.
*
* This should be called at most once per tray entry.
*
* This function does the same thing as SDL_CreateTrayMenu, except that it
* takes a SDL_TrayEntry instead of a SDL_Tray.
*
* A menu does not need to be destroyed; it will be destroyed with the tray.
*
* \param entry the tray entry to bind the menu to.
* \returns the newly created menu.
*
* \threadsafety This function should be called on the thread that created the
* tray.
*
* \since This function is available since SDL 3.2.0.
*
* \sa SDL_InsertTrayEntryAt
* \sa SDL_GetTraySubmenu
* \sa SDL_GetTrayMenuParentEntry
*/
extern SDL_DECLSPEC SDL_TrayMenu *SDLCALL SDL_CreateTraySubmenu(SDL_TrayEntry *entry);
/**
* Gets a previously created tray menu.
*
* You should have called SDL_CreateTrayMenu() on the tray object. This
* function allows you to fetch it again later.
*
* This function does the same thing as SDL_GetTraySubmenu(), except that it
* takes a SDL_Tray instead of a SDL_TrayEntry.
*
* A menu does not need to be destroyed; it will be destroyed with the tray.
*
* \param tray the tray entry to bind the menu to.
* \returns the newly created menu.
*
* \threadsafety This function should be called on the thread that created the
* tray.
*
* \since This function is available since SDL 3.2.0.
*
* \sa SDL_CreateTray
* \sa SDL_CreateTrayMenu
*/
extern SDL_DECLSPEC SDL_TrayMenu *SDLCALL SDL_GetTrayMenu(SDL_Tray *tray);
/**
* Gets a previously created tray entry submenu.
*
* You should have called SDL_CreateTraySubmenu() on the entry object. This
* function allows you to fetch it again later.
*
* This function does the same thing as SDL_GetTrayMenu(), except that it
* takes a SDL_TrayEntry instead of a SDL_Tray.
*
* A menu does not need to be destroyed; it will be destroyed with the tray.
*
* \param entry the tray entry to bind the menu to.
* \returns the newly created menu.
*
* \threadsafety This function should be called on the thread that created the
* tray.
*
* \since This function is available since SDL 3.2.0.
*
* \sa SDL_InsertTrayEntryAt
* \sa SDL_CreateTraySubmenu
*/
extern SDL_DECLSPEC SDL_TrayMenu *SDLCALL SDL_GetTraySubmenu(SDL_TrayEntry *entry);
/**
* Returns a list of entries in the menu, in order.
*
* \param menu The menu to get entries from.
* \param size An optional pointer to obtain the number of entries in the
* menu.
* \returns a NULL-terminated list of entries within the given menu. The
* pointer becomes invalid when any function that inserts or deletes
* entries in the menu is called.
*
* \threadsafety This function should be called on the thread that created the
* tray.
*
* \since This function is available since SDL 3.2.0.
*
* \sa SDL_RemoveTrayEntry
* \sa SDL_InsertTrayEntryAt
*/
extern SDL_DECLSPEC const SDL_TrayEntry **SDLCALL SDL_GetTrayEntries(SDL_TrayMenu *menu, int *size);
/**
* Removes a tray entry.
*
* \param entry The entry to be deleted.
*
* \threadsafety This function should be called on the thread that created the
* tray.
*
* \since This function is available since SDL 3.2.0.
*
* \sa SDL_GetTrayEntries
* \sa SDL_InsertTrayEntryAt
*/
extern SDL_DECLSPEC void SDLCALL SDL_RemoveTrayEntry(SDL_TrayEntry *entry);
/**
* Insert a tray entry at a given position.
*
* If label is NULL, the entry will be a separator. Many functions won't work
* for an entry that is a separator.
*
* An entry does not need to be destroyed; it will be destroyed with the tray.
*
* \param menu the menu to append the entry to.
* \param pos the desired position for the new entry. Entries at or following
* this place will be moved. If pos is -1, the entry is appended.
* \param label the text to be displayed on the entry, in UTF-8 encoding, or
* NULL for a separator.
* \param flags a combination of flags, some of which are mandatory.
* \returns the newly created entry, or NULL if pos is out of bounds.
*
* \threadsafety This function should be called on the thread that created the
* tray.
*
* \since This function is available since SDL 3.2.0.
*
* \sa SDL_TrayEntryFlags
* \sa SDL_GetTrayEntries
* \sa SDL_RemoveTrayEntry
* \sa SDL_GetTrayEntryParent
*/
extern SDL_DECLSPEC SDL_TrayEntry *SDLCALL SDL_InsertTrayEntryAt(SDL_TrayMenu *menu, int pos, const char *label, SDL_TrayEntryFlags flags);
/**
* Sets the label of an entry.
*
* An entry cannot change between a separator and an ordinary entry; that is,
* it is not possible to set a non-NULL label on an entry that has a NULL
* label (separators), or to set a NULL label to an entry that has a non-NULL
* label. The function will silently fail if that happens.
*
* \param entry the entry to be updated.
* \param label the new label for the entry in UTF-8 encoding.
*
* \threadsafety This function should be called on the thread that created the
* tray.
*
* \since This function is available since SDL 3.2.0.
*
* \sa SDL_GetTrayEntries
* \sa SDL_InsertTrayEntryAt
* \sa SDL_GetTrayEntryLabel
*/
extern SDL_DECLSPEC void SDLCALL SDL_SetTrayEntryLabel(SDL_TrayEntry *entry, const char *label);
/**
* Gets the label of an entry.
*
* If the returned value is NULL, the entry is a separator.
*
* \param entry the entry to be read.
* \returns the label of the entry in UTF-8 encoding.
*
* \threadsafety This function should be called on the thread that created the
* tray.
*
* \since This function is available since SDL 3.2.0.
*
* \sa SDL_GetTrayEntries
* \sa SDL_InsertTrayEntryAt
* \sa SDL_SetTrayEntryLabel
*/
extern SDL_DECLSPEC const char *SDLCALL SDL_GetTrayEntryLabel(SDL_TrayEntry *entry);
/**
* Sets whether or not an entry is checked.
*
* The entry must have been created with the SDL_TRAYENTRY_CHECKBOX flag.
*
* \param entry the entry to be updated.
* \param checked true if the entry should be checked; false otherwise.
*
* \threadsafety This function should be called on the thread that created the
* tray.
*
* \since This function is available since SDL 3.2.0.
*
* \sa SDL_GetTrayEntries
* \sa SDL_InsertTrayEntryAt
* \sa SDL_GetTrayEntryChecked
*/
extern SDL_DECLSPEC void SDLCALL SDL_SetTrayEntryChecked(SDL_TrayEntry *entry, bool checked);
/**
* Gets whether or not an entry is checked.
*
* The entry must have been created with the SDL_TRAYENTRY_CHECKBOX flag.
*
* \param entry the entry to be read.
* \returns true if the entry is checked; false otherwise.
*
* \threadsafety This function should be called on the thread that created the
* tray.
*
* \since This function is available since SDL 3.2.0.
*
* \sa SDL_GetTrayEntries
* \sa SDL_InsertTrayEntryAt
* \sa SDL_SetTrayEntryChecked
*/
extern SDL_DECLSPEC bool SDLCALL SDL_GetTrayEntryChecked(SDL_TrayEntry *entry);
/**
* Sets whether or not an entry is enabled.
*
* \param entry the entry to be updated.
* \param enabled true if the entry should be enabled; false otherwise.
*
* \threadsafety This function should be called on the thread that created the
* tray.
*
* \since This function is available since SDL 3.2.0.
*
* \sa SDL_GetTrayEntries
* \sa SDL_InsertTrayEntryAt
* \sa SDL_GetTrayEntryEnabled
*/
extern SDL_DECLSPEC void SDLCALL SDL_SetTrayEntryEnabled(SDL_TrayEntry *entry, bool enabled);
/**
* Gets whether or not an entry is enabled.
*
* \param entry the entry to be read.
* \returns true if the entry is enabled; false otherwise.
*
* \threadsafety This function should be called on the thread that created the
* tray.
*
* \since This function is available since SDL 3.2.0.
*
* \sa SDL_GetTrayEntries
* \sa SDL_InsertTrayEntryAt
* \sa SDL_SetTrayEntryEnabled
*/
extern SDL_DECLSPEC bool SDLCALL SDL_GetTrayEntryEnabled(SDL_TrayEntry *entry);
/**
* Sets a callback to be invoked when the entry is selected.
*
* \param entry the entry to be updated.
* \param callback a callback to be invoked when the entry is selected.
* \param userdata an optional pointer to pass extra data to the callback when
* it will be invoked.
*
* \threadsafety This function should be called on the thread that created the
* tray.
*
* \since This function is available since SDL 3.2.0.
*
* \sa SDL_GetTrayEntries
* \sa SDL_InsertTrayEntryAt
*/
extern SDL_DECLSPEC void SDLCALL SDL_SetTrayEntryCallback(SDL_TrayEntry *entry, SDL_TrayCallback callback, void *userdata);
/**
* Simulate a click on a tray entry.
*
* \param entry The entry to activate.
*
* \threadsafety This function should be called on the thread that created the
* tray.
*
* \since This function is available since SDL 3.2.0.
*/
extern SDL_DECLSPEC void SDLCALL SDL_ClickTrayEntry(SDL_TrayEntry *entry);
/**
* Destroys a tray object.
*
* This also destroys all associated menus and entries.
*
* \param tray the tray icon to be destroyed.
*
* \threadsafety This function should be called on the thread that created the
* tray.
*
* \since This function is available since SDL 3.2.0.
*
* \sa SDL_CreateTray
*/
extern SDL_DECLSPEC void SDLCALL SDL_DestroyTray(SDL_Tray *tray);
/**
* Gets the menu containing a certain tray entry.
*
* \param entry the entry for which to get the parent menu.
* \returns the parent menu.
*
* \threadsafety This function should be called on the thread that created the
* tray.
*
* \since This function is available since SDL 3.2.0.
*
* \sa SDL_InsertTrayEntryAt
*/
extern SDL_DECLSPEC SDL_TrayMenu *SDLCALL SDL_GetTrayEntryParent(SDL_TrayEntry *entry);
/**
* Gets the entry for which the menu is a submenu, if the current menu is a
* submenu.
*
* Either this function or SDL_GetTrayMenuParentTray() will return non-NULL
* for any given menu.
*
* \param menu the menu for which to get the parent entry.
* \returns the parent entry, or NULL if this menu is not a submenu.
*
* \threadsafety This function should be called on the thread that created the
* tray.
*
* \since This function is available since SDL 3.2.0.
*
* \sa SDL_CreateTraySubmenu
* \sa SDL_GetTrayMenuParentTray
*/
extern SDL_DECLSPEC SDL_TrayEntry *SDLCALL SDL_GetTrayMenuParentEntry(SDL_TrayMenu *menu);
/**
* Gets the tray for which this menu is the first-level menu, if the current
* menu isn't a submenu.
*
* Either this function or SDL_GetTrayMenuParentEntry() will return non-NULL
* for any given menu.
*
* \param menu the menu for which to get the parent enttrayry.
* \returns the parent tray, or NULL if this menu is a submenu.
*
* \threadsafety This function should be called on the thread that created the
* tray.
*
* \since This function is available since SDL 3.2.0.
*
* \sa SDL_CreateTrayMenu
* \sa SDL_GetTrayMenuParentEntry
*/
extern SDL_DECLSPEC SDL_Tray *SDLCALL SDL_GetTrayMenuParentTray(SDL_TrayMenu *menu);
/**
* Update the trays.
*
* This is called automatically by the event loop and is only needed if you're
* using trays but aren't handling SDL events.
*
* \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_UpdateTrays(void);
/* Ends C function definitions when using C++ */
#ifdef __cplusplus
}
#endif
#include <SDL3/SDL_close_code.h>
#endif /* SDL_tray_h_ */

View File

@ -1,6 +1,6 @@
/*
Simple DirectMedia Layer
Copyright (C) 1997-2024 Sam Lantinga <slouken@libsdl.org>
Copyright (C) 1997-2025 Sam Lantinga <slouken@libsdl.org>
This software is provided 'as-is', without any express or implied
warranty. In no event will the authors be held liable for any damages
@ -30,7 +30,6 @@
#define SDL_version_h_
#include <SDL3/SDL_stdinc.h>
#include <SDL3/SDL_error.h>
#include <SDL3/SDL_begin_code.h>
/* Set up for C function definitions, even when using C++ */
@ -43,7 +42,7 @@ extern "C" {
*
* If this were SDL version 3.2.1, this value would be 3.
*
* \since This macro is available since SDL 3.0.0.
* \since This macro is available since SDL 3.2.0.
*/
#define SDL_MAJOR_VERSION 3
@ -52,18 +51,18 @@ extern "C" {
*
* If this were SDL version 3.2.1, this value would be 2.
*
* \since This macro is available since SDL 3.0.0.
* \since This macro is available since SDL 3.2.0.
*/
#define SDL_MINOR_VERSION 1
#define SDL_MINOR_VERSION 2
/**
* The current micro (or patchlevel) version of the SDL headers.
*
* If this were SDL version 3.2.1, this value would be 1.
*
* \since This macro is available since SDL 3.0.0.
* \since This macro is available since SDL 3.2.0.
*/
#define SDL_MICRO_VERSION 2
#define SDL_MICRO_VERSION 0
/**
* This macro turns the version numbers into a numeric value.
@ -74,7 +73,7 @@ extern "C" {
* \param minor the minorversion number.
* \param patch the patch version number.
*
* \since This macro is available since SDL 3.0.0.
* \since This macro is available since SDL 3.2.0.
*/
#define SDL_VERSIONNUM(major, minor, patch) \
((major) * 1000000 + (minor) * 1000 + (patch))
@ -86,7 +85,7 @@ extern "C" {
*
* \param version the version number.
*
* \since This macro is available since SDL 3.0.0.
* \since This macro is available since SDL 3.2.0.
*/
#define SDL_VERSIONNUM_MAJOR(version) ((version) / 1000000)
@ -97,7 +96,7 @@ extern "C" {
*
* \param version the version number.
*
* \since This macro is available since SDL 3.0.0.
* \since This macro is available since SDL 3.2.0.
*/
#define SDL_VERSIONNUM_MINOR(version) (((version) / 1000) % 1000)
@ -108,14 +107,16 @@ extern "C" {
*
* \param version the version number.
*
* \since This macro is available since SDL 3.0.0.
* \since This macro is available since SDL 3.2.0.
*/
#define SDL_VERSIONNUM_MICRO(version) ((version) % 1000)
/**
* This is the version number macro for the current SDL version.
*
* \since This macro is available since SDL 3.0.0.
* \since This macro is available since SDL 3.2.0.
*
* \sa SDL_GetVersion
*/
#define SDL_VERSION \
SDL_VERSIONNUM(SDL_MAJOR_VERSION, SDL_MINOR_VERSION, SDL_MICRO_VERSION)
@ -123,7 +124,7 @@ extern "C" {
/**
* This macro will evaluate to true if compiled with SDL at least X.Y.Z.
*
* \since This macro is available since SDL 3.0.0.
* \since This macro is available since SDL 3.2.0.
*/
#define SDL_VERSION_ATLEAST(X, Y, Z) \
(SDL_VERSION >= SDL_VERSIONNUM(X, Y, Z))
@ -140,7 +141,7 @@ extern "C" {
*
* \returns the version of the linked library.
*
* \since This function is available since SDL 3.0.0.
* \since This function is available since SDL 3.2.0.
*
* \sa SDL_GetRevision
*/
@ -166,7 +167,7 @@ extern SDL_DECLSPEC int SDLCALL SDL_GetVersion(void);
* \returns an arbitrary string, uniquely identifying the exact revision of
* the SDL library in use.
*
* \since This function is available since SDL 3.0.0.
* \since This function is available since SDL 3.2.0.
*
* \sa SDL_GetVersion
*/

File diff suppressed because it is too large Load Diff

View File

@ -23,11 +23,25 @@
* # CategoryVulkan
*
* Functions for creating Vulkan surfaces on SDL windows.
*
* For the most part, Vulkan operates independent of SDL, but it benefits from
* a little support during setup.
*
* Use SDL_Vulkan_GetInstanceExtensions() to get platform-specific bits for
* creating a VkInstance, then SDL_Vulkan_GetVkGetInstanceProcAddr() to get
* the appropriate function for querying Vulkan entry points. Then
* SDL_Vulkan_CreateSurface() will get you the final pieces you need to
* prepare for rendering into an SDL_Window with Vulkan.
*
* Unlike OpenGL, most of the details of "context" creation and window buffer
* swapping are handled by the Vulkan API directly, so SDL doesn't provide
* Vulkan equivalents of SDL_GL_SwapWindow(), etc; they aren't necessary.
*/
#ifndef SDL_vulkan_h_
#define SDL_vulkan_h_
#include <SDL3/SDL_stdinc.h>
#include <SDL3/SDL_error.h>
#include <SDL3/SDL_video.h>
@ -55,6 +69,10 @@ VK_DEFINE_HANDLE(VkPhysicalDevice)
VK_DEFINE_NON_DISPATCHABLE_HANDLE(VkSurfaceKHR)
struct VkAllocationCallbacks;
/* Make sure to undef to avoid issues in case of later vulkan include */
#undef VK_DEFINE_HANDLE
#undef VK_DEFINE_NON_DISPATCHABLE_HANDLE
#endif /* !NO_SDL_VULKAN_TYPEDEFS */
/**
@ -69,6 +87,13 @@ struct VkAllocationCallbacks;
* creating any Vulkan windows. If no Vulkan loader library is loaded, the
* default library will be loaded upon creation of the first Vulkan window.
*
* SDL keeps a counter of how many times this function has been successfully
* called, so it is safe to call this function multiple times, so long as it
* is eventually paired with an equivalent number of calls to
* SDL_Vulkan_UnloadLibrary. The `path` argument is ignored unless there is no
* library currently loaded, and and the library isn't actually unloaded until
* there have been an equivalent number of calls to SDL_Vulkan_UnloadLibrary.
*
* It is fairly common for Vulkan applications to link with libvulkan instead
* of explicitly loading it at run time. This will work with SDL provided the
* application links to a dynamic library and both it and SDL use the same
@ -95,15 +120,17 @@ struct VkAllocationCallbacks;
* library version.
*
* \param path the platform dependent Vulkan loader library name or NULL.
* \returns SDL_TRUE on success or SDL_FALSE on failure; call SDL_GetError()
* for more information.
* \returns true on success or false on failure; call SDL_GetError() for more
* information.
*
* \since This function is available since SDL 3.0.0.
* \threadsafety This function is not thread safe.
*
* \since This function is available since SDL 3.2.0.
*
* \sa SDL_Vulkan_GetVkGetInstanceProcAddr
* \sa SDL_Vulkan_UnloadLibrary
*/
extern SDL_DECLSPEC SDL_bool SDLCALL SDL_Vulkan_LoadLibrary(const char *path);
extern SDL_DECLSPEC bool SDLCALL SDL_Vulkan_LoadLibrary(const char *path);
/**
* Get the address of the `vkGetInstanceProcAddr` function.
@ -122,14 +149,27 @@ extern SDL_DECLSPEC SDL_bool SDLCALL SDL_Vulkan_LoadLibrary(const char *path);
* \returns the function pointer for `vkGetInstanceProcAddr` or NULL on
* failure; call SDL_GetError() for more information.
*
* \since This function is available since SDL 3.0.0.
* \since This function is available since SDL 3.2.0.
*/
extern SDL_DECLSPEC SDL_FunctionPointer SDLCALL SDL_Vulkan_GetVkGetInstanceProcAddr(void);
/**
* Unload the Vulkan library previously loaded by SDL_Vulkan_LoadLibrary().
*
* \since This function is available since SDL 3.0.0.
* SDL keeps a counter of how many times this function has been called, so it
* is safe to call this function multiple times, so long as it is paired with
* an equivalent number of calls to SDL_Vulkan_LoadLibrary. The library isn't
* actually unloaded until there have been an equivalent number of calls to
* SDL_Vulkan_UnloadLibrary.
*
* Once the library has actually been unloaded, if any Vulkan instances
* remain, they will likely crash the program. Clean up any existing Vulkan
* resources, and destroy appropriate windows, renderers and GPU devices
* before calling this function.
*
* \threadsafety This function is not thread safe.
*
* \since This function is available since SDL 3.2.0.
*
* \sa SDL_Vulkan_LoadLibrary
*/
@ -153,7 +193,7 @@ extern SDL_DECLSPEC void SDLCALL SDL_Vulkan_UnloadLibrary(void);
* \returns an array of extension name strings on success, NULL on failure;
* call SDL_GetError() for more information.
*
* \since This function is available since SDL 3.0.0.
* \since This function is available since SDL 3.2.0.
*
* \sa SDL_Vulkan_CreateSurface
*/
@ -175,15 +215,15 @@ extern SDL_DECLSPEC char const * const * SDLCALL SDL_Vulkan_GetInstanceExtension
* allocator that creates the surface. Can be NULL.
* \param surface a pointer to a VkSurfaceKHR handle to output the newly
* created surface.
* \returns SDL_TRUE on success or SDL_FALSE on failure; call SDL_GetError()
* for more information.
* \returns true on success or false on failure; call SDL_GetError() for more
* information.
*
* \since This function is available since SDL 3.0.0.
* \since This function is available since SDL 3.2.0.
*
* \sa SDL_Vulkan_GetInstanceExtensions
* \sa SDL_Vulkan_DestroySurface
*/
extern SDL_DECLSPEC SDL_bool SDLCALL SDL_Vulkan_CreateSurface(SDL_Window *window,
extern SDL_DECLSPEC bool SDLCALL SDL_Vulkan_CreateSurface(SDL_Window *window,
VkInstance instance,
const struct VkAllocationCallbacks *allocator,
VkSurfaceKHR* surface);
@ -206,7 +246,7 @@ extern SDL_DECLSPEC SDL_bool SDLCALL SDL_Vulkan_CreateSurface(SDL_Window *window
* \param allocator a VkAllocationCallbacks struct, which lets the app set the
* allocator that destroys the surface. Can be NULL.
*
* \since This function is available since SDL 3.0.0.
* \since This function is available since SDL 3.2.0.
*
* \sa SDL_Vulkan_GetInstanceExtensions
* \sa SDL_Vulkan_CreateSurface
@ -226,14 +266,13 @@ extern SDL_DECLSPEC void SDLCALL SDL_Vulkan_DestroySurface(VkInstance instance,
* \param physicalDevice a valid Vulkan physical device handle.
* \param queueFamilyIndex a valid queue family index for the given physical
* device.
* \returns SDL_TRUE if supported, SDL_FALSE if unsupported or an error
* occurred.
* \returns true if supported, false if unsupported or an error occurred.
*
* \since This function is available since SDL 3.0.0.
* \since This function is available since SDL 3.2.0.
*
* \sa SDL_Vulkan_GetInstanceExtensions
*/
extern SDL_DECLSPEC SDL_bool SDLCALL SDL_Vulkan_GetPresentationSupport(VkInstance instance,
extern SDL_DECLSPEC bool SDLCALL SDL_Vulkan_GetPresentationSupport(VkInstance instance,
VkPhysicalDevice physicalDevice,
Uint32 queueFamilyIndex);

View File

@ -0,0 +1,41 @@
# Using this package
This package contains SDL built for Xcode.
To use this package in Xcode, drag `SDL3.framework` into your project.
# Documentation
An API reference, tutorials, and additional documentation is available at:
https://wiki.libsdl.org/SDL3
# Example code
There are simple example programs available at:
https://examples.libsdl.org/SDL3
# Discussions
## Discord
You can join the official Discord server at:
https://discord.com/invite/BwpFGBWsv8
## Forums/mailing lists
You can join SDL development discussions at:
https://discourse.libsdl.org/
Once you sign up, you can use the forum through the website or as a mailing list from your email client.
## Announcement list
You can sign up for the low traffic announcement list at:
https://www.libsdl.org/mailing-list.php

View File

@ -1,6 +1,4 @@
Simple DirectMedia Layer
Copyright (C) 1997-2024 Sam Lantinga <slouken@libsdl.org>
Copyright (C) 1997-2025 Sam Lantinga <slouken@libsdl.org>
This software is provided 'as-is', without any express or implied
warranty. In no event will the authors be held liable for any damages
@ -17,3 +15,4 @@ freely, subject to the following restrictions:
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.

View File

@ -0,0 +1,17 @@
Simple DirectMedia Layer (SDL for short) is a cross-platform library
designed to make it easy to write multi-media software, such as games
and emulators.
You can find the latest release and additional information at:
https://www.libsdl.org/
Installation instructions and a quick introduction is available in
[INSTALL.md](INSTALL.md)
This library is distributed under the terms of the zlib license,
available in [LICENSE.txt](LICENSE.txt).
Enjoy!
Sam Lantinga (slouken@libsdl.org)

View File

@ -1,44 +0,0 @@
The Simple DirectMedia Layer (SDL for short) is a cross-platform
library designed to make it easy to write multi-media software,
such as games and emulators.
The Simple DirectMedia Layer library source code is available from:
http://www.libsdl.org/
This library is distributed under the terms of the zlib license:
http://zlib.net/zlib_license.html
This packages contains the SDL framework for macOS.
Conforming with Apple guidelines, this framework
contains both the SDL runtime component and development header files.
To Install:
Copy "SDL3.xcframework" and "share" to /Library/Frameworks
You may alternatively install it in <Your home directory>/Library/Frameworks
if your access privileges are not high enough.
Use in CMake projects:
SDL3.xcframework can be used in CMake projects using the following pattern:
```cmake
find_package(SDL3 REQUIRED COMPONENTS SDL3)
add_executable(my_game ${MY_SOURCES})
target_link_libraries(my_game PRIVATE SDL3::SDL3)
```
If SDL3.framework is installed in a non-standard location,
please refer to the following link for ways to configure CMake:
https://cmake.org/cmake/help/latest/command/find_package.html#config-mode-search-procedure
Additional References:
- Screencast tutorials for getting started with OpenSceneGraph/macOS are
available at:
http://www.openscenegraph.org/projects/osg/wiki/Support/Tutorials/MacOSXTips
Though these are OpenSceneGraph centric, the same exact concepts apply to
SDL, thus the videos are recommended for everybody getting started with
developing on macOS. (You can skim over the PlugIns stuff since SDL
doesn't have any PlugIns to worry about.)

View File

@ -1,68 +0,0 @@
#!/bin/bash
set -x
set -e
cd `dirname "$0"`
shadernames=(FullscreenVert BlitFrom2D BlitFrom2DArray BlitFrom3D BlitFromCube)
generate_shaders()
{
fileplatform=$1
compileplatform=$2
sdkplatform=$3
minversion=$4
for shadername in "${shadernames[@]}"; do
xcrun -sdk $sdkplatform metal -c -std=$compileplatform-metal1.1 -m$sdkplatform-version-min=$minversion -Wall -O3 -D COMPILE_$shadername -o ./$shadername.air ./Metal_Blit.metal || exit $?
xcrun -sdk $sdkplatform metallib -o $shadername.metallib $shadername.air || exit $?
xxd -i $shadername.metallib | perl -w -p -e 's/\Aunsigned /const unsigned /;' >./${shadername}_$fileplatform.h
rm -f $shadername.air $shadername.metallib
done
}
generate_shaders macos macos macosx 10.11
generate_shaders ios ios iphoneos 8.0
generate_shaders iphonesimulator ios iphonesimulator 8.0
generate_shaders tvos ios appletvos 9.0
generate_shaders tvsimulator ios appletvsimulator 9.0
# Bundle together one mega-header
catShaders()
{
target=$1
for shadername in "${shadernames[@]}"; do
cat ${shadername}_$target.h >> Metal_Blit.h
done
}
rm -f Metal_Blit.h
echo "#if defined(SDL_PLATFORM_IOS)" >> Metal_Blit.h
echo "#if TARGET_OS_SIMULATOR" >> Metal_Blit.h
catShaders iphonesimulator
echo "#else" >> Metal_Blit.h
catShaders ios
echo "#endif" >> Metal_Blit.h
echo "#elif defined(SDL_PLATFORM_TVOS)" >> Metal_Blit.h
echo "#if TARGET_OS_SIMULATOR" >> Metal_Blit.h
catShaders tvsimulator
echo "#else" >> Metal_Blit.h
catShaders tvos
echo "#endif" >> Metal_Blit.h
echo "#else" >> Metal_Blit.h
catShaders macos
echo "#endif" >> Metal_Blit.h
# Clean up
cleanupShaders()
{
target=$1
for shadername in "${shadernames[@]}"; do
rm -f ${shadername}_$target.h
done
}
cleanupShaders iphonesimulator
cleanupShaders ios
cleanupShaders tvsimulator
cleanupShaders tvos
cleanupShaders macos

View File

@ -59,7 +59,7 @@ if(NOT TARGET SDL3::SDL3-shared)
set_target_properties(SDL3::SDL3-shared
PROPERTIES
FRAMEWORK "TRUE"
IMPORTED_LOCATION "${_sdl3_framework_path}/SDL3"
IMPORTED_LOCATION "${_sdl3_framework_path}"
INTERFACE_LINK_LIBRARIES "SDL3::Headers"
COMPATIBLE_INTERFACE_BOOL "SDL3_SHARED"
INTERFACE_SDL3_SHARED "ON"

View File

@ -1,6 +1,6 @@
/*
Simple DirectMedia Layer
Copyright (C) 1997-2024 Sam Lantinga <slouken@libsdl.org>
Copyright (C) 1997-2025 Sam Lantinga <slouken@libsdl.org>
This software is provided 'as-is', without any express or implied
warranty. In no event will the authors be held liable for any damages
@ -20,9 +20,12 @@
*/
/**
* \file SDL.h
* Main include header for the SDL library, version 3.2.0
*
* Main include header for the SDL library, version 3.1.2
* It is almost always best to include just this one header instead of
* picking out individual headers included here. There are exceptions to
* this rule--SDL_main.h is special and not included here--but usually
* letting SDL.h include the kitchen sink for you is the correct approach.
*/
#ifndef SDL_h_
@ -30,6 +33,7 @@
#include <SDL3/SDL_stdinc.h>
#include <SDL3/SDL_assert.h>
#include <SDL3/SDL_asyncio.h>
#include <SDL3/SDL_atomic.h>
#include <SDL3/SDL_audio.h>
#include <SDL3/SDL_bits.h>
@ -65,6 +69,7 @@
#include <SDL3/SDL_pixels.h>
#include <SDL3/SDL_platform.h>
#include <SDL3/SDL_power.h>
#include <SDL3/SDL_process.h>
#include <SDL3/SDL_properties.h>
#include <SDL3/SDL_rect.h>
#include <SDL3/SDL_render.h>
@ -76,6 +81,7 @@
#include <SDL3/SDL_thread.h>
#include <SDL3/SDL_time.h>
#include <SDL3/SDL_timer.h>
#include <SDL3/SDL_tray.h>
#include <SDL3/SDL_touch.h>
#include <SDL3/SDL_version.h>
#include <SDL3/SDL_video.h>

View File

@ -1,6 +1,6 @@
/*
Simple DirectMedia Layer
Copyright (C) 1997-2024 Sam Lantinga <slouken@libsdl.org>
Copyright (C) 1997-2025 Sam Lantinga <slouken@libsdl.org>
This software is provided 'as-is', without any express or implied
warranty. In no event will the authors be held liable for any damages
@ -51,9 +51,14 @@
* - It provides statistics and data on all failed assertions to the app.
* - It allows the default assertion handler to be controlled with environment
* variables, in case an automated script needs to control it.
* - It can be used as an aid to Clang's static analysis; it will treat SDL
* assertions as universally true (under the assumption that you are serious
* about the asserted claims and that your debug builds will detect when
* these claims were wrong). This can help the analyzer avoid false
* positives.
*
* To use it: do a debug build and just sprinkle around tests to check your
* code!
* To use it: compile a debug build and just sprinkle around tests to check
* your code!
*/
#ifndef SDL_assert_h_
@ -84,7 +89,7 @@ extern "C" {
* - 3: Paranoid settings: All SDL assertion macros enabled, including
* SDL_assert_paranoid.
*
* \since This macro is available since SDL 3.0.0.
* \since This macro is available since SDL 3.2.0.
*/
#define SDL_ASSERT_LEVEL SomeNumberBasedOnVariousFactors
@ -113,24 +118,27 @@ extern "C" {
*
* If the program is not running under a debugger, SDL_TriggerBreakpoint will
* likely terminate the app, possibly without warning. If the current platform
* isn't supported (SDL doesn't know how to trigger a breakpoint), this macro
* does nothing.
* isn't supported, this macro is left undefined.
*
* \threadsafety It is safe to call this function from any thread.
* \threadsafety It is safe to call this macro from any thread.
*
* \since This macro is available since SDL 3.0.0.
* \since This macro is available since SDL 3.2.0.
*/
#define SDL_TriggerBreakpoint() TriggerABreakpointInAPlatformSpecificManner
#elif defined(_MSC_VER)
#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(_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__))
#define SDL_TriggerBreakpoint() __asm__ __volatile__ ( "int $3\n\t" )
#elif (defined(__GNUC__) || defined(__clang__)) && defined(__riscv)
@ -147,18 +155,40 @@ extern "C" {
#include <signal.h>
#define SDL_TriggerBreakpoint() raise(SIGTRAP)
#else
/* How do we trigger breakpoints on this platform? */
#define SDL_TriggerBreakpoint()
/* SDL_TriggerBreakpoint is intentionally left undefined on unknown platforms. */
#endif
#if defined(__STDC_VERSION__) && (__STDC_VERSION__ >= 199901L) /* C99 supports __func__ as a standard. */
#ifdef SDL_WIKI_DOCUMENTATION_SECTION
/**
* A macro that reports the current function being compiled.
*
* If SDL can't figure how the compiler reports this, it will use "???".
*
* \since This macro is available since SDL 3.2.0.
*/
#define SDL_FUNCTION __FUNCTION__
#elif 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
/**
* A macro that reports the current file being compiled.
*
* \since This macro is available since SDL 3.2.0.
*/
#define SDL_FILE __FILE__
/**
* A macro that reports the current line number of the file being compiled.
*
* \since This macro is available since SDL 3.2.0.
*/
#define SDL_LINE __LINE__
/*
@ -176,14 +206,50 @@ This also solves the problem of...
disable assertions.
*/
#ifdef SDL_WIKI_DOCUMENTATION_SECTION
/**
* A macro for wrapping code in `do {} while (0);` without compiler warnings.
*
* Visual Studio with really aggressive warnings enabled needs this to avoid
* compiler complaints.
*
* the `do {} while (0);` trick is useful for wrapping code in a macro that
* may or may not be a single statement, to avoid various C language
* accidents.
*
* To use:
*
* ```c
* do { SomethingOnce(); } while (SDL_NULL_WHILE_LOOP_CONDITION (0));
* ```
*
* \since This macro is available since SDL 3.2.0.
*/
#define SDL_NULL_WHILE_LOOP_CONDITION (0)
#elif defined(_MSC_VER) /* 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! */
#ifdef _MSC_VER /* stupid /W4 warnings. */
#define SDL_NULL_WHILE_LOOP_CONDITION (0,0)
#else
#define SDL_NULL_WHILE_LOOP_CONDITION (0)
#endif
/**
* The macro used when an assertion is disabled.
*
* This isn't for direct use by apps, but this is the code that is inserted
* when an SDL_assert is disabled (perhaps in a release build).
*
* 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.
*
* \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)
@ -198,7 +264,7 @@ disable assertions.
* condition, try to break in a debugger, kill the program, or ignore the
* problem).
*
* \since This enum is available since SDL 3.0.0.
* \since This enum is available since SDL 3.2.0.
*/
typedef enum SDL_AssertState
{
@ -216,11 +282,11 @@ typedef enum SDL_AssertState
* used by the assertion handler, then added to the assertion report. This is
* returned as a linked list from SDL_GetAssertionReport().
*
* \since This struct is available since SDL 3.0.0.
* \since This struct is available since SDL 3.2.0.
*/
typedef struct SDL_AssertData
{
SDL_bool always_ignore; /**< SDL_TRUE if app should always continue when assertion is triggered. */
bool always_ignore; /**< true if app should always continue when assertion is triggered. */
unsigned int trigger_count; /**< Number of times this assertion has been triggered. */
const char *condition; /**< A string of this assert's test code. */
const char *filename; /**< The source file where this assert lives. */
@ -232,7 +298,7 @@ typedef struct SDL_AssertData
/**
* Never call this directly.
*
* Use the SDL_assert* macros instead.
* Use the SDL_assert macros instead.
*
* \param data assert data structure.
* \param func function name.
@ -240,29 +306,57 @@ typedef struct SDL_AssertData
* \param line line number.
* \returns assert state.
*
* \since This function is available since SDL 3.0.0.
* \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_AssertState SDLCALL SDL_ReportAssertion(SDL_AssertData *data,
const char *func,
const char *file, int line) SDL_ANALYZER_NORETURN;
/* Define the trigger breakpoint call used in asserts */
#ifndef SDL_AssertBreakpoint
#if defined(ANDROID) && defined(assert)
/* Define this as empty in case assert() is defined as SDL_assert */
#define SDL_AssertBreakpoint()
#else
#ifdef SDL_WIKI_DOCUMENTATION_SECTION
/**
* The macro used when an assertion triggers a breakpoint.
*
* This isn't for direct use by apps; use SDL_assert or SDL_TriggerBreakpoint
* instead.
*
* \since This macro is available since SDL 3.2.0.
*/
#define SDL_AssertBreakpoint() SDL_TriggerBreakpoint()
#endif
#elif !defined(SDL_AssertBreakpoint)
# if defined(ANDROID) && defined(assert)
/* Define this as empty in case assert() is defined as SDL_assert */
# define SDL_AssertBreakpoint()
# else
# define SDL_AssertBreakpoint() SDL_TriggerBreakpoint()
# endif
#endif /* !SDL_AssertBreakpoint */
/* the do {} while(0) avoids dangling else problems:
if (x) SDL_assert(y); else blah();
... without the do/while, the "else" could attach to this macro's "if".
We try to handle just the minimum we need here in a macro...the loop,
the static vars, and break points. The heavy lifting is handled in
SDL_ReportAssertion(), in SDL_assert.c.
*/
/**
* The macro used when an assertion is enabled.
*
* This isn't for direct use by apps, but this is the code that is inserted
* when an SDL_assert is enabled.
*
* The `do {} while(0)` avoids dangling else problems:
*
* ```c
* if (x) SDL_assert(y); else blah();
* ```
*
* ... without the do/while, the "else" could attach to this macro's "if". We
* try to handle just the minimum we need here in a macro...the loop, the
* static vars, and break points. The heavy lifting is handled in
* SDL_ReportAssertion().
*
* \param condition the condition to assert.
*
* \since This macro is available since SDL 3.2.0.
*/
#define SDL_enabled_assert(condition) \
do { \
while ( !(condition) ) { \
@ -305,7 +399,9 @@ extern SDL_DECLSPEC SDL_AssertState SDLCALL SDL_ReportAssertion(SDL_AssertData *
*
* \param condition boolean value to test.
*
* \since This macro is available since SDL 3.0.0.
* \threadsafety It is safe to call this macro from any thread.
*
* \since This macro is available since SDL 3.2.0.
*/
#define SDL_assert(condition) if (assertion_enabled && (condition)) { trigger_assertion; }
@ -336,7 +432,9 @@ extern SDL_DECLSPEC SDL_AssertState SDLCALL SDL_ReportAssertion(SDL_AssertData *
*
* \param condition boolean value to test.
*
* \since This macro is available since SDL 3.0.0.
* \threadsafety It is safe to call this macro from any thread.
*
* \since This macro is available since SDL 3.2.0.
*/
#define SDL_assert_release(condition) SDL_disabled_assert(condition)
@ -363,7 +461,9 @@ extern SDL_DECLSPEC SDL_AssertState SDLCALL SDL_ReportAssertion(SDL_AssertData *
*
* \param condition boolean value to test.
*
* \since This macro is available since SDL 3.0.0.
* \threadsafety It is safe to call this macro from any thread.
*
* \since This macro is available since SDL 3.2.0.
*/
#define SDL_assert_paranoid(condition) SDL_disabled_assert(condition)
@ -389,7 +489,7 @@ extern SDL_DECLSPEC SDL_AssertState SDLCALL SDL_ReportAssertion(SDL_AssertData *
#endif
/**
* An assertion test that always performed.
* An assertion test that is always performed.
*
* This macro is always enabled no matter what SDL_ASSERT_LEVEL is set to. You
* almost never want to use this, as it could trigger on an end-user's system,
@ -405,7 +505,9 @@ extern SDL_DECLSPEC SDL_AssertState SDLCALL SDL_ReportAssertion(SDL_AssertData *
*
* \param condition boolean value to test.
*
* \since This macro is available since SDL 3.0.0.
* \threadsafety It is safe to call this macro from any thread.
*
* \since This macro is available since SDL 3.2.0.
*/
#define SDL_assert_always(condition) SDL_enabled_assert(condition)
@ -418,7 +520,10 @@ extern SDL_DECLSPEC SDL_AssertState SDLCALL SDL_ReportAssertion(SDL_AssertData *
* \param userdata what was passed as `userdata` to SDL_SetAssertionHandler().
* \returns an SDL_AssertState value indicating how to handle the failure.
*
* \since This datatype is available since SDL 3.0.0.
* \threadsafety This callback may be called from any thread that triggers an
* assert at any time.
*
* \since This datatype is available since SDL 3.2.0.
*/
typedef SDL_AssertState (SDLCALL *SDL_AssertionHandler)(
const SDL_AssertData *data, void *userdata);
@ -440,7 +545,9 @@ typedef SDL_AssertState (SDLCALL *SDL_AssertionHandler)(
* fails or NULL for the default handler.
* \param userdata a pointer that is passed to `handler`.
*
* \since This function is available since SDL 3.0.0.
* \threadsafety It is safe to call this function from any thread.
*
* \since This function is available since SDL 3.2.0.
*
* \sa SDL_GetAssertionHandler
*/
@ -459,7 +566,9 @@ extern SDL_DECLSPEC void SDLCALL SDL_SetAssertionHandler(
* \returns the default SDL_AssertionHandler that is called when an assert
* triggers.
*
* \since This function is available since SDL 3.0.0.
* \threadsafety It is safe to call this function from any thread.
*
* \since This function is available since SDL 3.2.0.
*
* \sa SDL_GetAssertionHandler
*/
@ -482,7 +591,9 @@ extern SDL_DECLSPEC SDL_AssertionHandler SDLCALL SDL_GetDefaultAssertionHandler(
* was passed to SDL_SetAssertionHandler().
* \returns the SDL_AssertionHandler that is called when an assert triggers.
*
* \since This function is available since SDL 3.0.0.
* \threadsafety It is safe to call this function from any thread.
*
* \since This function is available since SDL 3.2.0.
*
* \sa SDL_SetAssertionHandler
*/
@ -508,9 +619,15 @@ extern SDL_DECLSPEC SDL_AssertionHandler SDLCALL SDL_GetAssertionHandler(void **
* ```
*
* \returns a list of all failed assertions or NULL if the list is empty. This
* memory should not be modified or freed by the application.
* memory should not be modified or freed by the application. This
* pointer remains valid until the next call to SDL_Quit() or
* SDL_ResetAssertionReport().
*
* \since This function is available since SDL 3.0.0.
* \threadsafety This function is not thread safe. Other threads calling
* SDL_ResetAssertionReport() simultaneously, may render the
* returned pointer invalid.
*
* \since This function is available since SDL 3.2.0.
*
* \sa SDL_ResetAssertionReport
*/
@ -524,7 +641,11 @@ extern SDL_DECLSPEC const SDL_AssertData * SDLCALL SDL_GetAssertionReport(void);
* no items. In addition, any previously-triggered assertions will be reset to
* a trigger_count of zero, and their always_ignore state will be false.
*
* \since This function is available since SDL 3.0.0.
* \threadsafety This function is not thread safe. Other threads triggering an
* assertion, or simultaneously calling this function may cause
* memory leaks or crashes.
*
* \since This function is available since SDL 3.2.0.
*
* \sa SDL_GetAssertionReport
*/

View File

@ -0,0 +1,546 @@
/*
Simple DirectMedia Layer
Copyright (C) 1997-2025 Sam Lantinga <slouken@libsdl.org>
This software is provided 'as-is', without any express or implied
warranty. In no event will the authors be held liable for any damages
arising from the use of this software.
Permission is granted to anyone to use this software for any purpose,
including commercial applications, and to alter it and redistribute it
freely, subject to the following restrictions:
1. The origin of this software must not be misrepresented; you must not
claim that you wrote the original software. If you use this software
in a product, an acknowledgment in the product documentation would be
appreciated but is not required.
2. Altered source versions must be plainly marked as such, and must not be
misrepresented as being the original software.
3. This notice may not be removed or altered from any source distribution.
*/
/* WIKI CATEGORY: AsyncIO */
/**
* # CategoryAsyncIO
*
* SDL offers a way to perform I/O asynchronously. This allows an app to read
* or write files without waiting for data to actually transfer; the functions
* that request I/O never block while the request is fulfilled.
*
* Instead, the data moves in the background and the app can check for results
* at their leisure.
*
* This is more complicated than just reading and writing files in a
* synchronous way, but it can allow for more efficiency, and never having
* framerate drops as the hard drive catches up, etc.
*
* The general usage pattern for async I/O is:
*
* - Create one or more SDL_AsyncIOQueue objects.
* - Open files with SDL_AsyncIOFromFile.
* - Start I/O tasks to the files with SDL_ReadAsyncIO or SDL_WriteAsyncIO,
* putting those tasks into one of the queues.
* - Later on, use SDL_GetAsyncIOResult on a queue to see if any task is
* finished without blocking. Tasks might finish in any order with success
* or failure.
* - When all your tasks are done, close the file with SDL_CloseAsyncIO. This
* also generates a task, since it might flush data to disk!
*
* This all works, without blocking, in a single thread, but one can also wait
* on a queue in a background thread, sleeping until new results have arrived:
*
* - Call SDL_WaitAsyncIOResult from one or more threads to efficiently block
* until new tasks complete.
* - When shutting down, call SDL_SignalAsyncIOQueue to unblock any sleeping
* threads despite there being no new tasks completed.
*
* And, of course, to match the synchronous SDL_LoadFile, we offer
* SDL_LoadFileAsync as a convenience function. This will handle allocating a
* buffer, slurping in the file data, and null-terminating it; you still check
* for results later.
*
* Behind the scenes, SDL will use newer, efficient APIs on platforms that
* support them: Linux's io_uring and Windows 11's IoRing, for example. If
* those technologies aren't available, SDL will offload the work to a thread
* pool that will manage otherwise-synchronous loads without blocking the app.
*
* ## Best Practices
*
* Simple non-blocking I/O--for an app that just wants to pick up data
* whenever it's ready without losing framerate waiting on disks to spin--can
* use whatever pattern works well for the program. In this case, simply call
* SDL_ReadAsyncIO, or maybe SDL_LoadFileAsync, as needed. Once a frame, call
* SDL_GetAsyncIOResult to check for any completed tasks and deal with the
* data as it arrives.
*
* If two separate pieces of the same program need their own I/O, it is legal
* for each to create their own queue. This will prevent either piece from
* accidentally consuming the other's completed tasks. Each queue does require
* some amount of resources, but it is not an overwhelming cost. Do not make a
* queue for each task, however. It is better to put many tasks into a single
* queue. They will be reported in order of completion, not in the order they
* were submitted, so it doesn't generally matter what order tasks are
* started.
*
* One async I/O queue can be shared by multiple threads, or one thread can
* have more than one queue, but the most efficient way--if ruthless
* efficiency is the goal--is to have one queue per thread, with multiple
* threads working in parallel, and attempt to keep each queue loaded with
* tasks that are both started by and consumed by the same thread. On modern
* platforms that can use newer interfaces, this can keep data flowing as
* efficiently as possible all the way from storage hardware to the app, with
* no contention between threads for access to the same queue.
*
* Written data is not guaranteed to make it to physical media by the time a
* closing task is completed, unless SDL_CloseAsyncIO is called with its
* `flush` parameter set to true, which is to say that a successful result
* here can still result in lost data during an unfortunately-timed power
* outage if not flushed. However, flushing will take longer and may be
* unnecessary, depending on the app's needs.
*/
#ifndef SDL_asyncio_h_
#define SDL_asyncio_h_
#include <SDL3/SDL_stdinc.h>
#include <SDL3/SDL_begin_code.h>
/* Set up for C function definitions, even when using C++ */
#ifdef __cplusplus
extern "C" {
#endif
/**
* The asynchronous I/O operation structure.
*
* This operates as an opaque handle. One can then request read or write
* operations on it.
*
* \since This struct is available since SDL 3.2.0.
*
* \sa SDL_AsyncIOFromFile
*/
typedef struct SDL_AsyncIO SDL_AsyncIO;
/**
* Types of asynchronous I/O tasks.
*
* \since This enum is available since SDL 3.2.0.
*/
typedef enum SDL_AsyncIOTaskType
{
SDL_ASYNCIO_TASK_READ, /**< A read operation. */
SDL_ASYNCIO_TASK_WRITE, /**< A write operation. */
SDL_ASYNCIO_TASK_CLOSE /**< A close operation. */
} SDL_AsyncIOTaskType;
/**
* Possible outcomes of an asynchronous I/O task.
*
* \since This enum is available since SDL 3.2.0.
*/
typedef enum SDL_AsyncIOResult
{
SDL_ASYNCIO_COMPLETE, /**< request was completed without error */
SDL_ASYNCIO_FAILURE, /**< request failed for some reason; check SDL_GetError()! */
SDL_ASYNCIO_CANCELED /**< request was canceled before completing. */
} SDL_AsyncIOResult;
/**
* Information about a completed asynchronous I/O request.
*
* \since This struct is available since SDL 3.2.0.
*/
typedef struct SDL_AsyncIOOutcome
{
SDL_AsyncIO *asyncio; /**< what generated this task. This pointer will be invalid if it was closed! */
SDL_AsyncIOTaskType type; /**< What sort of task was this? Read, write, etc? */
SDL_AsyncIOResult result; /**< the result of the work (success, failure, cancellation). */
void *buffer; /**< buffer where data was read/written. */
Uint64 offset; /**< offset in the SDL_AsyncIO where data was read/written. */
Uint64 bytes_requested; /**< number of bytes the task was to read/write. */
Uint64 bytes_transferred; /**< actual number of bytes that were read/written. */
void *userdata; /**< pointer provided by the app when starting the task */
} SDL_AsyncIOOutcome;
/**
* A queue of completed asynchronous I/O tasks.
*
* When starting an asynchronous operation, you specify a queue for the new
* task. A queue can be asked later if any tasks in it have completed,
* allowing an app to manage multiple pending tasks in one place, in whatever
* order they complete.
*
* \since This struct is available since SDL 3.2.0.
*
* \sa SDL_CreateAsyncIOQueue
* \sa SDL_ReadAsyncIO
* \sa SDL_WriteAsyncIO
* \sa SDL_GetAsyncIOResult
* \sa SDL_WaitAsyncIOResult
*/
typedef struct SDL_AsyncIOQueue SDL_AsyncIOQueue;
/**
* Use this function to create a new SDL_AsyncIO object for reading from
* and/or writing to a named file.
*
* The `mode` string understands the following values:
*
* - "r": Open a file for reading only. It must exist.
* - "w": Open a file for writing only. It will create missing files or
* truncate existing ones.
* - "r+": Open a file for update both reading and writing. The file must
* exist.
* - "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.
*
* There is no "b" mode, as there is only "binary" style I/O, and no "a" mode
* for appending, since you specify the position when starting a task.
*
* This function supports Unicode filenames, but they must be encoded in UTF-8
* format, regardless of the underlying operating system.
*
* This call is _not_ asynchronous; it will open the file before returning,
* under the assumption that doing so is generally a fast operation. Future
* reads and writes to the opened file will be async, however.
*
* \param file a UTF-8 string representing the filename to open.
* \param mode an ASCII string representing the mode to be used for opening
* the file.
* \returns a pointer to the SDL_AsyncIO structure that is created or NULL on
* failure; call SDL_GetError() for more information.
*
* \since This function is available since SDL 3.2.0.
*
* \sa SDL_CloseAsyncIO
* \sa SDL_ReadAsyncIO
* \sa SDL_WriteAsyncIO
*/
extern SDL_DECLSPEC SDL_AsyncIO * SDLCALL SDL_AsyncIOFromFile(const char *file, const char *mode);
/**
* Use this function to get the size of the data stream in an SDL_AsyncIO.
*
* This call is _not_ asynchronous; it assumes that obtaining this info is a
* non-blocking operation in most reasonable cases.
*
* \param asyncio the SDL_AsyncIO to get the size of the data stream from.
* \returns the size of the data stream in the SDL_IOStream on success or a
* negative error code 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 Sint64 SDLCALL SDL_GetAsyncIOSize(SDL_AsyncIO *asyncio);
/**
* Start an async read.
*
* This function reads up to `size` bytes from `offset` position in the data
* source to the area pointed at by `ptr`. This function may read less bytes
* than requested.
*
* This function returns as quickly as possible; it does not wait for the read
* to complete. On a successful return, this work will continue in the
* background. If the work begins, even failure is asynchronous: a failing
* return value from this function only means the work couldn't start at all.
*
* `ptr` must remain available until the work is done, and may be accessed by
* the system at any time until then. Do not allocate it on the stack, as this
* might take longer than the life of the calling function to complete!
*
* An SDL_AsyncIOQueue must be specified. The newly-created task will be added
* to it when it completes its work.
*
* \param asyncio a pointer to an SDL_AsyncIO structure.
* \param ptr a pointer to a buffer to read data into.
* \param offset the position to start reading in the data source.
* \param size the number of bytes to read from the data source.
* \param queue a queue to add the new SDL_AsyncIO to.
* \param userdata an app-defined pointer that will be provided with the task
* results.
* \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_WriteAsyncIO
* \sa SDL_CreateAsyncIOQueue
*/
extern SDL_DECLSPEC bool SDLCALL SDL_ReadAsyncIO(SDL_AsyncIO *asyncio, void *ptr, Uint64 offset, Uint64 size, SDL_AsyncIOQueue *queue, void *userdata);
/**
* Start an async write.
*
* This function writes `size` bytes from `offset` position in the data source
* to the area pointed at by `ptr`.
*
* This function returns as quickly as possible; it does not wait for the
* write to complete. On a successful return, this work will continue in the
* background. If the work begins, even failure is asynchronous: a failing
* return value from this function only means the work couldn't start at all.
*
* `ptr` must remain available until the work is done, and may be accessed by
* the system at any time until then. Do not allocate it on the stack, as this
* might take longer than the life of the calling function to complete!
*
* An SDL_AsyncIOQueue must be specified. The newly-created task will be added
* to it when it completes its work.
*
* \param asyncio a pointer to an SDL_AsyncIO structure.
* \param ptr a pointer to a buffer to write data from.
* \param offset the position to start writing to the data source.
* \param size the number of bytes to write to the data source.
* \param queue a queue to add the new SDL_AsyncIO to.
* \param userdata an app-defined pointer that will be provided with the task
* results.
* \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_ReadAsyncIO
* \sa SDL_CreateAsyncIOQueue
*/
extern SDL_DECLSPEC bool SDLCALL SDL_WriteAsyncIO(SDL_AsyncIO *asyncio, void *ptr, Uint64 offset, Uint64 size, SDL_AsyncIOQueue *queue, void *userdata);
/**
* Close and free any allocated resources for an async I/O object.
*
* Closing a file is _also_ an asynchronous task! If a write failure were to
* happen during the closing process, for example, the task results will
* report it as usual.
*
* Closing a file that has been written to does not guarantee the data has
* made it to physical media; it may remain in the operating system's file
* cache, for later writing to disk. This means that a successfully-closed
* file can be lost if the system crashes or loses power in this small window.
* To prevent this, call this function with the `flush` parameter set to true.
* This will make the operation take longer, and perhaps increase system load
* in general, but a successful result guarantees that the data has made it to
* physical storage. Don't use this for temporary files, caches, and
* unimportant data, and definitely use it for crucial irreplaceable files,
* like game saves.
*
* This function guarantees that the close will happen after any other pending
* tasks to `asyncio`, so it's safe to open a file, start several operations,
* close the file immediately, then check for all results later. This function
* will not block until the tasks have completed.
*
* Once this function returns true, `asyncio` is no longer valid, regardless
* of any future outcomes. Any completed tasks might still contain this
* pointer in their SDL_AsyncIOOutcome data, in case the app was using this
* value to track information, but it should not be used again.
*
* If this function returns false, the close wasn't started at all, and it's
* safe to attempt to close again later.
*
* An SDL_AsyncIOQueue must be specified. The newly-created task will be added
* to it when it completes its work.
*
* \param asyncio a pointer to an SDL_AsyncIO structure to close.
* \param flush true if data should sync to disk before the task completes.
* \param queue a queue to add the new SDL_AsyncIO to.
* \param userdata an app-defined pointer that will be provided with the task
* results.
* \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 two
* threads should not attempt to close the same object.
*
* \since This function is available since SDL 3.2.0.
*/
extern SDL_DECLSPEC bool SDLCALL SDL_CloseAsyncIO(SDL_AsyncIO *asyncio, bool flush, SDL_AsyncIOQueue *queue, void *userdata);
/**
* Create a task queue for tracking multiple I/O operations.
*
* Async I/O operations are assigned to a queue when started. The queue can be
* checked for completed tasks thereafter.
*
* \returns a new task queue object or NULL if there was an error; 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_DestroyAsyncIOQueue
* \sa SDL_GetAsyncIOResult
* \sa SDL_WaitAsyncIOResult
*/
extern SDL_DECLSPEC SDL_AsyncIOQueue * SDLCALL SDL_CreateAsyncIOQueue(void);
/**
* Destroy a previously-created async I/O task queue.
*
* If there are still tasks pending for this queue, this call will block until
* those tasks are finished. All those tasks will be deallocated. Their
* results will be lost to the app.
*
* Any pending reads from SDL_LoadFileAsync() that are still in this queue
* will have their buffers deallocated by this function, to prevent a memory
* leak.
*
* Once this function is called, the queue is no longer valid and should not
* be used, including by other threads that might access it while destruction
* is blocking on pending tasks.
*
* Do not destroy a queue that still has threads waiting on it through
* SDL_WaitAsyncIOResult(). You can call SDL_SignalAsyncIOQueue() first to
* unblock those threads, and take measures (such as SDL_WaitThread()) to make
* sure they have finished their wait and won't wait on the queue again.
*
* \param queue the task queue to destroy.
*
* \threadsafety It is safe to call this function from any thread, so long as
* no other thread is waiting on the queue with
* SDL_WaitAsyncIOResult.
*
* \since This function is available since SDL 3.2.0.
*/
extern SDL_DECLSPEC void SDLCALL SDL_DestroyAsyncIOQueue(SDL_AsyncIOQueue *queue);
/**
* Query an async I/O task queue for completed tasks.
*
* If a task assigned to this queue has finished, this will return true and
* fill in `outcome` with the details of the task. If no task in the queue has
* finished, this function will return false. This function does not block.
*
* If a task has completed, this function will free its resources and the task
* pointer will no longer be valid. The task will be removed from the queue.
*
* It is safe for multiple threads to call this function on the same queue at
* once; a completed task will only go to one of the threads.
*
* \param queue the async I/O task queue to query.
* \param outcome details of a finished task will be written here. May not be
* NULL.
* \returns true if a task has completed, 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_WaitAsyncIOResult
*/
extern SDL_DECLSPEC bool SDLCALL SDL_GetAsyncIOResult(SDL_AsyncIOQueue *queue, SDL_AsyncIOOutcome *outcome);
/**
* Block until an async I/O task queue has a completed task.
*
* This function puts the calling thread to sleep until there a task assigned
* to the queue that has finished.
*
* If a task assigned to the queue has finished, this will return true and
* fill in `outcome` with the details of the task. If no task in the queue has
* finished, this function will return false.
*
* If a task has completed, this function will free its resources and the task
* pointer will no longer be valid. The task will be removed from the queue.
*
* It is safe for multiple threads to call this function on the same queue at
* once; a completed task will only go to one of the threads.
*
* Note that by the nature of various platforms, more than one waiting thread
* may wake to handle a single task, but only one will obtain it, so
* `timeoutMS` is a _maximum_ wait time, and this function may return false
* sooner.
*
* This function may return false if there was a system error, the OS
* inadvertently awoke multiple threads, or if SDL_SignalAsyncIOQueue() was
* called to wake up all waiting threads without a finished task.
*
* A timeout can be used to specify a maximum wait time, but rather than
* polling, it is possible to have a timeout of -1 to wait forever, and use
* SDL_SignalAsyncIOQueue() to wake up the waiting threads later.
*
* \param queue the async I/O task queue to wait on.
* \param outcome details of a finished task will be written here. May not be
* NULL.
* \param timeoutMS the maximum time to wait, in milliseconds, or -1 to wait
* indefinitely.
* \returns true if task has completed, 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_SignalAsyncIOQueue
*/
extern SDL_DECLSPEC bool SDLCALL SDL_WaitAsyncIOResult(SDL_AsyncIOQueue *queue, SDL_AsyncIOOutcome *outcome, Sint32 timeoutMS);
/**
* Wake up any threads that are blocking in SDL_WaitAsyncIOResult().
*
* This will unblock any threads that are sleeping in a call to
* SDL_WaitAsyncIOResult for the specified queue, and cause them to return
* from that function.
*
* This can be useful when destroying a queue to make sure nothing is touching
* it indefinitely. In this case, once this call completes, the caller should
* take measures to make sure any previously-blocked threads have returned
* from their wait and will not touch the queue again (perhaps by setting a
* flag to tell the threads to terminate and then using SDL_WaitThread() to
* make sure they've done so).
*
* \param queue the async I/O task queue to signal.
*
* \threadsafety It is safe to call this function from any thread.
*
* \since This function is available since SDL 3.2.0.
*
* \sa SDL_WaitAsyncIOResult
*/
extern SDL_DECLSPEC void SDLCALL SDL_SignalAsyncIOQueue(SDL_AsyncIOQueue *queue);
/**
* Load all the data from a file path, asynchronously.
*
* This function returns as quickly as possible; it does not wait for the read
* to complete. On a successful return, this work will continue in the
* background. If the work begins, even failure is asynchronous: a failing
* return value from this function only means the work couldn't start at all.
*
* The data is allocated with a zero byte at the end (null terminated) for
* convenience. This extra byte is not included in SDL_AsyncIOOutcome's
* bytes_transferred value.
*
* This function will allocate the buffer to contain the file. It must be
* deallocated by calling SDL_free() on SDL_AsyncIOOutcome's buffer field
* after completion.
*
* An SDL_AsyncIOQueue must be specified. The newly-created task will be added
* to it when it completes its work.
*
* \param file the path to read all available data from.
* \param queue a queue to add the new SDL_AsyncIO to.
* \param userdata an app-defined pointer that will be provided with the task
* results.
* \returns true on success or false on failure; call SDL_GetError() for more
* information.
*
* \since This function is available since SDL 3.2.0.
*
* \sa SDL_LoadFile_IO
*/
extern SDL_DECLSPEC bool SDLCALL SDL_LoadFileAsync(const char *file, SDL_AsyncIOQueue *queue, void *userdata);
/* Ends C function definitions when using C++ */
#ifdef __cplusplus
}
#endif
#include <SDL3/SDL_close_code.h>
#endif /* SDL_asyncio_h_ */

View File

@ -1,6 +1,6 @@
/*
Simple DirectMedia Layer
Copyright (C) 1997-2024 Sam Lantinga <slouken@libsdl.org>
Copyright (C) 1997-2025 Sam Lantinga <slouken@libsdl.org>
This software is provided 'as-is', without any express or implied
warranty. In no event will the authors be held liable for any damages
@ -88,15 +88,16 @@ typedef int SDL_SpinLock;
* doing. Please be careful using any sort of spinlock!***
*
* \param lock a pointer to a lock variable.
* \returns SDL_TRUE if the lock succeeded, SDL_FALSE if the lock is already
* held.
* \returns true if the lock succeeded, false if the lock is already held.
*
* \since This function is available since SDL 3.0.0.
* \threadsafety It is safe to call this function from any thread.
*
* \since This function is available since SDL 3.2.0.
*
* \sa SDL_LockSpinlock
* \sa SDL_UnlockSpinlock
*/
extern SDL_DECLSPEC SDL_bool SDLCALL SDL_TryLockSpinlock(SDL_SpinLock *lock);
extern SDL_DECLSPEC bool SDLCALL SDL_TryLockSpinlock(SDL_SpinLock *lock);
/**
* Lock a spin lock by setting it to a non-zero value.
@ -106,7 +107,9 @@ extern SDL_DECLSPEC SDL_bool SDLCALL SDL_TryLockSpinlock(SDL_SpinLock *lock);
*
* \param lock a pointer to a lock variable.
*
* \since This function is available since SDL 3.0.0.
* \threadsafety It is safe to call this function from any thread.
*
* \since This function is available since SDL 3.2.0.
*
* \sa SDL_TryLockSpinlock
* \sa SDL_UnlockSpinlock
@ -123,7 +126,9 @@ extern SDL_DECLSPEC void SDLCALL SDL_LockSpinlock(SDL_SpinLock *lock);
*
* \param lock a pointer to a lock variable.
*
* \since This function is available since SDL 3.0.0.
* \threadsafety It is safe to call this function from any thread.
*
* \since This function is available since SDL 3.2.0.
*
* \sa SDL_LockSpinlock
* \sa SDL_TryLockSpinlock
@ -147,9 +152,10 @@ extern SDL_DECLSPEC void SDLCALL SDL_UnlockSpinlock(SDL_SpinLock *lock);
* time, but if you find yourself needing this, you are probably
* dealing with some very sensitive code; be careful!
*
* \since This macro is available since SDL 3.0.0.
* \since This macro is available since SDL 3.2.0.
*/
#define SDL_CompilerBarrier() DoCompilerSpecificReadWriteBarrier()
#elif defined(_MSC_VER) && (_MSC_VER > 1200) && !defined(__clang__)
void _ReadWriteBarrier(void);
#pragma intrinsic(_ReadWriteBarrier)
@ -166,7 +172,50 @@ extern __inline void SDL_CompilerBarrier(void);
#endif
/**
* Insert a memory release barrier.
* Insert a memory release barrier (function version).
*
* Please refer to SDL_MemoryBarrierRelease for details. This is a function
* version, which might be useful if you need to use this functionality from a
* scripting language, etc. Also, some of the macro versions call this
* function behind the scenes, where more heavy lifting can happen inside of
* SDL. Generally, though, an app written in C/C++/etc should use the macro
* version, as it will be more efficient.
*
* \threadsafety Obviously this function is safe to use from any thread at any
* time, but if you find yourself needing this, you are probably
* dealing with some very sensitive code; be careful!
*
* \since This function is available since SDL 3.2.0.
*
* \sa SDL_MemoryBarrierRelease
*/
extern SDL_DECLSPEC void SDLCALL SDL_MemoryBarrierReleaseFunction(void);
/**
* Insert a memory acquire barrier (function version).
*
* Please refer to SDL_MemoryBarrierRelease for details. This is a function
* version, which might be useful if you need to use this functionality from a
* scripting language, etc. Also, some of the macro versions call this
* function behind the scenes, where more heavy lifting can happen inside of
* SDL. Generally, though, an app written in C/C++/etc should use the macro
* version, as it will be more efficient.
*
* \threadsafety Obviously this function is safe to use from any thread at any
* time, but if you find yourself needing this, you are probably
* dealing with some very sensitive code; be careful!
*
* \since This function is available since SDL 3.2.0.
*
* \sa SDL_MemoryBarrierAcquire
*/
extern SDL_DECLSPEC void SDLCALL SDL_MemoryBarrierAcquireFunction(void);
#ifdef SDL_WIKI_DOCUMENTATION_SECTION
/**
* Insert a memory release barrier (macro version).
*
* Memory barriers are designed to prevent reads and writes from being
* reordered by the compiler and being seen out of order on multi-core CPUs.
@ -186,31 +235,47 @@ extern __inline void SDL_CompilerBarrier(void);
* For more information on these semantics, take a look at the blog post:
* http://preshing.com/20120913/acquire-and-release-semantics
*
* This is the macro version of this functionality; if possible, SDL will use
* compiler intrinsics or inline assembly, but some platforms might need to
* call the function version of this, SDL_MemoryBarrierReleaseFunction to do
* the heavy lifting. Apps that can use the macro should favor it over the
* function.
*
* \threadsafety Obviously this macro is safe to use from any thread at any
* time, but if you find yourself needing this, you are probably
* dealing with some very sensitive code; be careful!
*
* \since This function is available since SDL 3.0.0.
* \since This macro is available since SDL 3.2.0.
*
* \sa SDL_MemoryBarrierAcquire
* \sa SDL_MemoryBarrierReleaseFunction
*/
extern SDL_DECLSPEC void SDLCALL SDL_MemoryBarrierReleaseFunction(void);
#define SDL_MemoryBarrierRelease() SDL_MemoryBarrierReleaseFunction()
/**
* Insert a memory acquire barrier.
* Insert a memory acquire barrier (macro version).
*
* Please refer to SDL_MemoryBarrierReleaseFunction for the details!
* Please see SDL_MemoryBarrierRelease for the details on what memory barriers
* are and when to use them.
*
* \threadsafety Obviously this function is safe to use from any thread at any
* This is the macro version of this functionality; if possible, SDL will use
* compiler intrinsics or inline assembly, but some platforms might need to
* call the function version of this, SDL_MemoryBarrierAcquireFunction, to do
* the heavy lifting. Apps that can use the macro should favor it over the
* function.
*
* \threadsafety Obviously this macro is safe to use from any thread at any
* time, but if you find yourself needing this, you are probably
* dealing with some very sensitive code; be careful!
*
* \since This function is available since SDL 3.0.0.
* \since This macro is available since SDL 3.2.0.
*
* \sa SDL_MemoryBarrierReleaseFunction
* \sa SDL_MemoryBarrierRelease
* \sa SDL_MemoryBarrierAcquireFunction
*/
extern SDL_DECLSPEC void SDLCALL SDL_MemoryBarrierAcquireFunction(void);
#define SDL_MemoryBarrierAcquire() SDL_MemoryBarrierAcquireFunction()
/* !!! FIXME: this should have documentation! */
#if defined(__GNUC__) && (defined(__powerpc__) || defined(__ppc__))
#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__)
@ -225,8 +290,8 @@ extern SDL_DECLSPEC void SDLCALL SDL_MemoryBarrierAcquireFunction(void);
hard-coded at address 0xffff0fa0
*/
typedef void (*SDL_KernelMemoryBarrierFunc)();
#define SDL_MemoryBarrierRelease() ((SDL_KernelMemoryBarrierFunc)0xffff0fa0)()
#define SDL_MemoryBarrierAcquire() ((SDL_KernelMemoryBarrierFunc)0xffff0fa0)()
#define SDL_MemoryBarrierRelease() ((SDL_KernelMemoryBarrierFunc)0xffff0fa0)()
#define SDL_MemoryBarrierAcquire() ((SDL_KernelMemoryBarrierFunc)0xffff0fa0)()
#else
#if defined(__ARM_ARCH_7__) || defined(__ARM_ARCH_7A__) || defined(__ARM_ARCH_7EM__) || defined(__ARM_ARCH_7R__) || defined(__ARM_ARCH_7M__) || defined(__ARM_ARCH_7S__) || defined(__ARM_ARCH_8A__)
#define SDL_MemoryBarrierRelease() __asm__ __volatile__ ("dmb ish" : : : "memory")
@ -276,9 +341,10 @@ typedef void (*SDL_KernelMemoryBarrierFunc)();
*
* \threadsafety This macro is safe to use from any thread.
*
* \since This macro is available since SDL 3.0.0.
* \since This macro is available since SDL 3.2.0.
*/
#define SDL_CPUPauseInstruction() DoACPUPauseInACompilerAndArchitectureSpecificWay
#elif (defined(__GNUC__) || defined(__clang__)) && (defined(__i386__) || defined(__x86_64__))
#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__)
@ -303,9 +369,10 @@ typedef void (*SDL_KernelMemoryBarrierFunc)();
* A type representing an atomic integer value.
*
* This can be used to manage a value that is synchronized across multiple
* CPUs without a race condition; when an app sets a value with SDL_AtomicSet
* all other threads, regardless of the CPU it is running on, will see that
* value when retrieved with SDL_AtomicGet, regardless of CPU caches, etc.
* CPUs without a race condition; when an app sets a value with
* SDL_SetAtomicInt all other threads, regardless of the CPU it is running on,
* will see that value when retrieved with SDL_GetAtomicInt, regardless of CPU
* caches, etc.
*
* This is also useful for atomic compare-and-swap operations: a thread can
* change the value as long as its current value matches expectations. When
@ -316,14 +383,14 @@ typedef void (*SDL_KernelMemoryBarrierFunc)();
* this!).
*
* This is a struct so people don't accidentally use numeric operations on it
* directly. You have to use SDL_Atomic* functions.
* directly. You have to use SDL atomic functions.
*
* \since This struct is available since SDL 3.0.0.
* \since This struct is available since SDL 3.2.0.
*
* \sa SDL_AtomicCompareAndSwap
* \sa SDL_AtomicGet
* \sa SDL_AtomicSet
* \sa SDL_AtomicAdd
* \sa SDL_CompareAndSwapAtomicInt
* \sa SDL_GetAtomicInt
* \sa SDL_SetAtomicInt
* \sa SDL_AddAtomicInt
*/
typedef struct SDL_AtomicInt { int value; } SDL_AtomicInt;
@ -336,15 +403,16 @@ typedef struct SDL_AtomicInt { int value; } SDL_AtomicInt;
* \param a a pointer to an SDL_AtomicInt variable to be modified.
* \param oldval the old value.
* \param newval the new value.
* \returns SDL_TRUE if the atomic variable was set, SDL_FALSE otherwise.
* \returns true if the atomic variable was set, false otherwise.
*
* \threadsafety It is safe to call this function from any thread.
*
* \since This function is available since SDL 3.0.0.
* \since This function is available since SDL 3.2.0.
*
* \sa SDL_AtomicCompareAndSwapPointer
* \sa SDL_GetAtomicInt
* \sa SDL_SetAtomicInt
*/
extern SDL_DECLSPEC SDL_bool SDLCALL SDL_AtomicCompareAndSwap(SDL_AtomicInt *a, int oldval, int newval);
extern SDL_DECLSPEC bool SDLCALL SDL_CompareAndSwapAtomicInt(SDL_AtomicInt *a, int oldval, int newval);
/**
* Set an atomic variable to a value.
@ -360,11 +428,11 @@ extern SDL_DECLSPEC SDL_bool SDLCALL SDL_AtomicCompareAndSwap(SDL_AtomicInt *a,
*
* \threadsafety It is safe to call this function from any thread.
*
* \since This function is available since SDL 3.0.0.
* \since This function is available since SDL 3.2.0.
*
* \sa SDL_AtomicGet
* \sa SDL_GetAtomicInt
*/
extern SDL_DECLSPEC int SDLCALL SDL_AtomicSet(SDL_AtomicInt *a, int v);
extern SDL_DECLSPEC int SDLCALL SDL_SetAtomicInt(SDL_AtomicInt *a, int v);
/**
* Get the value of an atomic variable.
@ -377,11 +445,11 @@ extern SDL_DECLSPEC int SDLCALL SDL_AtomicSet(SDL_AtomicInt *a, int v);
*
* \threadsafety It is safe to call this function from any thread.
*
* \since This function is available since SDL 3.0.0.
* \since This function is available since SDL 3.2.0.
*
* \sa SDL_AtomicSet
* \sa SDL_SetAtomicInt
*/
extern SDL_DECLSPEC int SDLCALL SDL_AtomicGet(SDL_AtomicInt *a);
extern SDL_DECLSPEC int SDLCALL SDL_GetAtomicInt(SDL_AtomicInt *a);
/**
* Add to an atomic variable.
@ -397,12 +465,12 @@ extern SDL_DECLSPEC int SDLCALL SDL_AtomicGet(SDL_AtomicInt *a);
*
* \threadsafety It is safe to call this function from any thread.
*
* \since This function is available since SDL 3.0.0.
* \since This function is available since SDL 3.2.0.
*
* \sa SDL_AtomicDecRef
* \sa SDL_AtomicIncRef
*/
extern SDL_DECLSPEC int SDLCALL SDL_AtomicAdd(SDL_AtomicInt *a, int v);
extern SDL_DECLSPEC int SDLCALL SDL_AddAtomicInt(SDL_AtomicInt *a, int v);
#ifndef SDL_AtomicIncRef
@ -414,11 +482,13 @@ extern SDL_DECLSPEC int SDLCALL SDL_AtomicAdd(SDL_AtomicInt *a, int v);
* \param a a pointer to an SDL_AtomicInt to increment.
* \returns the previous value of the atomic variable.
*
* \since This macro is available since SDL 3.0.0.
* \threadsafety It is safe to call this macro from any thread.
*
* \since This macro is available since SDL 3.2.0.
*
* \sa SDL_AtomicDecRef
*/
#define SDL_AtomicIncRef(a) SDL_AtomicAdd(a, 1)
#define SDL_AtomicIncRef(a) SDL_AddAtomicInt(a, 1)
#endif
#ifndef SDL_AtomicDecRef
@ -429,16 +499,103 @@ extern SDL_DECLSPEC int SDLCALL SDL_AtomicAdd(SDL_AtomicInt *a, int v);
* ***Note: If you don't know what this macro is for, you shouldn't use it!***
*
* \param a a pointer to an SDL_AtomicInt to increment.
* \returns SDL_TRUE if the variable reached zero after decrementing,
* SDL_FALSE otherwise.
* \returns true if the variable reached zero after decrementing, false
* otherwise.
*
* \since This macro is available since SDL 3.0.0.
* \threadsafety It is safe to call this macro from any thread.
*
* \since This macro is available since SDL 3.2.0.
*
* \sa SDL_AtomicIncRef
*/
#define SDL_AtomicDecRef(a) (SDL_AtomicAdd(a, -1) == 1)
#define SDL_AtomicDecRef(a) (SDL_AddAtomicInt(a, -1) == 1)
#endif
/**
* A type representing an atomic unsigned 32-bit value.
*
* This can be used to manage a value that is synchronized across multiple
* CPUs without a race condition; when an app sets a value with
* SDL_SetAtomicU32 all other threads, regardless of the CPU it is running on,
* will see that value when retrieved with SDL_GetAtomicU32, regardless of CPU
* caches, etc.
*
* This is also useful for atomic compare-and-swap operations: a thread can
* change the value as long as its current value matches expectations. When
* done in a loop, one can guarantee data consistency across threads without a
* lock (but the usual warnings apply: if you don't know what you're doing, or
* you don't do it carefully, you can confidently cause any number of
* disasters with this, so in most cases, you _should_ use a mutex instead of
* this!).
*
* This is a struct so people don't accidentally use numeric operations on it
* directly. You have to use SDL atomic functions.
*
* \since This struct is available since SDL 3.2.0.
*
* \sa SDL_CompareAndSwapAtomicU32
* \sa SDL_GetAtomicU32
* \sa SDL_SetAtomicU32
*/
typedef struct SDL_AtomicU32 { Uint32 value; } SDL_AtomicU32;
/**
* Set an atomic variable to a new value if it is currently an old value.
*
* ***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 oldval the old value.
* \param newval the new value.
* \returns true if the atomic variable was set, 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_GetAtomicU32
* \sa SDL_SetAtomicU32
*/
extern SDL_DECLSPEC bool SDLCALL SDL_CompareAndSwapAtomicU32(SDL_AtomicU32 *a, Uint32 oldval, Uint32 newval);
/**
* Set an atomic variable to a value.
*
* 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.
* \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.2.0.
*
* \sa SDL_GetAtomicU32
*/
extern SDL_DECLSPEC Uint32 SDLCALL SDL_SetAtomicU32(SDL_AtomicU32 *a, Uint32 v);
/**
* Get the value of an atomic variable.
*
* ***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.
* \returns the current value of an atomic variable.
*
* \threadsafety It is safe to call this function from any thread.
*
* \since This function is available since SDL 3.2.0.
*
* \sa SDL_SetAtomicU32
*/
extern SDL_DECLSPEC Uint32 SDLCALL SDL_GetAtomicU32(SDL_AtomicU32 *a);
/**
* Set a pointer to a new value if it is currently an old value.
*
@ -448,17 +605,17 @@ extern SDL_DECLSPEC int SDLCALL SDL_AtomicAdd(SDL_AtomicInt *a, int v);
* \param a a pointer to a pointer.
* \param oldval the old pointer value.
* \param newval the new pointer value.
* \returns SDL_TRUE if the pointer was set, SDL_FALSE otherwise.
* \returns true if the pointer was set, false otherwise.
*
* \threadsafety It is safe to call this function from any thread.
*
* \since This function is available since SDL 3.0.0.
* \since This function is available since SDL 3.2.0.
*
* \sa SDL_AtomicCompareAndSwap
* \sa SDL_AtomicGetPointer
* \sa SDL_AtomicSetPointer
* \sa SDL_CompareAndSwapAtomicInt
* \sa SDL_GetAtomicPointer
* \sa SDL_SetAtomicPointer
*/
extern SDL_DECLSPEC SDL_bool SDLCALL SDL_AtomicCompareAndSwapPointer(void **a, void *oldval, void *newval);
extern SDL_DECLSPEC bool SDLCALL SDL_CompareAndSwapAtomicPointer(void **a, void *oldval, void *newval);
/**
* Set a pointer to a value atomically.
@ -472,12 +629,12 @@ extern SDL_DECLSPEC SDL_bool SDLCALL SDL_AtomicCompareAndSwapPointer(void **a, v
*
* \threadsafety It is safe to call this function from any thread.
*
* \since This function is available since SDL 3.0.0.
* \since This function is available since SDL 3.2.0.
*
* \sa SDL_AtomicCompareAndSwapPointer
* \sa SDL_AtomicGetPointer
* \sa SDL_CompareAndSwapAtomicPointer
* \sa SDL_GetAtomicPointer
*/
extern SDL_DECLSPEC void * SDLCALL SDL_AtomicSetPointer(void **a, void *v);
extern SDL_DECLSPEC void * SDLCALL SDL_SetAtomicPointer(void **a, void *v);
/**
* Get the value of a pointer atomically.
@ -490,12 +647,12 @@ extern SDL_DECLSPEC void * SDLCALL SDL_AtomicSetPointer(void **a, void *v);
*
* \threadsafety It is safe to call this function from any thread.
*
* \since This function is available since SDL 3.0.0.
* \since This function is available since SDL 3.2.0.
*
* \sa SDL_AtomicCompareAndSwapPointer
* \sa SDL_AtomicSetPointer
* \sa SDL_CompareAndSwapAtomicPointer
* \sa SDL_SetAtomicPointer
*/
extern SDL_DECLSPEC void * SDLCALL SDL_AtomicGetPointer(void **a);
extern SDL_DECLSPEC void * SDLCALL SDL_GetAtomicPointer(void **a);
/* Ends C function definitions when using C++ */
#ifdef __cplusplus

View File

@ -1,6 +1,6 @@
/*
Simple DirectMedia Layer
Copyright (C) 1997-2024 Sam Lantinga <slouken@libsdl.org>
Copyright (C) 1997-2025 Sam Lantinga <slouken@libsdl.org>
This software is provided 'as-is', without any express or implied
warranty. In no event will the authors be held liable for any damages
@ -22,9 +22,15 @@
/* WIKI CATEGORY: BeginCode */
/**
* SDL_begin_code.h sets things up for C dynamic library function definitions,
* static inlined functions, and structures aligned at 4-byte alignment.
* If you don't like ugly C preprocessor code, don't look at this file. :)
* # CategoryBeginCode
*
* `SDL_begin_code.h` sets things up for C dynamic library function
* definitions, static inlined functions, and structures aligned at 4-byte
* alignment. If you don't like ugly C preprocessor code, don't look at this
* file. :)
*
* SDL's headers use this; applications generally should not include this
* header directly.
*/
/* This shouldn't be nested -- included it around code only. */
@ -33,6 +39,259 @@
#endif
#define SDL_begin_code_h
#ifdef SDL_WIKI_DOCUMENTATION_SECTION
/**
* A macro to tag a symbol as deprecated.
*
* A function is marked deprecated by adding this macro to its declaration:
*
* ```c
* extern SDL_DEPRECATED int ThisFunctionWasABadIdea(void);
* ```
*
* Compilers with deprecation support can give a warning when a deprecated
* function is used. This symbol may be used in SDL's headers, but apps are
* welcome to use it for their own interfaces as well.
*
* SDL, on occasion, might deprecate a function for various reasons. However,
* SDL never removes symbols before major versions, so deprecated interfaces
* in SDL3 will remain available until SDL4, where it would be expected an app
* would have to take steps to migrate anyhow.
*
* On compilers without a deprecation mechanism, this is defined to nothing,
* and using a deprecated function will not generate a warning.
*
* \since This macro is available since SDL 3.2.0.
*/
#define SDL_DEPRECATED __attribute__((deprecated))
/**
* A macro to tag a symbol as a public API.
*
* SDL uses this macro for all its public functions. On some targets, it is
* used to signal to the compiler that this function needs to be exported from
* a shared library, but it might have other side effects.
*
* This symbol is used in SDL's headers, but apps and other libraries are
* welcome to use it for their own interfaces as well.
*
* \since This macro is available since SDL 3.2.0.
*/
#define SDL_DECLSPEC __attribute__ ((visibility("default")))
/**
* A macro to set a function's calling conventions.
*
* SDL uses this macro for all its public functions, and any callbacks it
* defines. This macro guarantees that calling conventions match between SDL
* and the app, even if the two were built with different compilers or
* optimization settings.
*
* When writing a callback function, it is very important for it to be
* correctly tagged with SDLCALL, as mismatched calling conventions can cause
* strange behaviors and can be difficult to diagnose. Plus, on many
* platforms, SDLCALL is defined to nothing, so compilers won't be able to
* warn that the tag is missing.
*
* This symbol is used in SDL's headers, but apps and other libraries are
* welcome to use it for their own interfaces as well.
*
* \since This macro is available since SDL 3.2.0.
*/
#define SDLCALL __cdecl
/**
* A macro to request a function be inlined.
*
* This is a hint to the compiler to inline a function. The compiler is free
* to ignore this request. On compilers without inline support, this is
* defined to nothing.
*
* \since This macro is available since SDL 3.2.0.
*/
#define SDL_INLINE __inline
/**
* A macro to demand a function be inlined.
*
* This is a command to the compiler to inline a function. SDL uses this macro
* in its public headers for a handful of simple functions. On compilers
* without forceinline support, this is defined to `static SDL_INLINE`, which
* is often good enough.
*
* This symbol is used in SDL's headers, but apps and other libraries are
* welcome to use it for their own interfaces as well.
*
* \since This macro is available since SDL 3.2.0.
*/
#define SDL_FORCE_INLINE __forceinline
/**
* A macro to tag a function as never-returning.
*
* This is a hint to the compiler that a function does not return. An example
* of a function like this is the C runtime's exit() function.
*
* This hint can lead to code optimizations, and help analyzers understand
* code flow better. On compilers without noreturn support, this is defined to
* nothing.
*
* This symbol is used in SDL's headers, but apps and other libraries are
* welcome to use it for their own interfaces as well.
*
* \since This macro is available since SDL 3.2.0.
*/
#define SDL_NORETURN __attribute__((noreturn))
/**
* A macro to tag a function as never-returning (for analysis purposes).
*
* This is almost identical to SDL_NORETURN, except functions marked with this
* _can_ actually return. The difference is that this isn't used for code
* generation, but rather static analyzers use this information to assume
* truths about program state and available code paths. Specifically, this tag
* is useful for writing an assertion mechanism. Indeed, SDL_assert uses this
* tag behind the scenes. Generally, apps that don't understand the specific
* use-case for this tag should avoid using it directly.
*
* On compilers without analyzer_noreturn support, this is defined to nothing.
*
* This symbol is used in SDL's headers, but apps and other libraries are
* welcome to use it for their own interfaces as well.
*
* \since This macro is available since SDL 3.2.0.
*/
#define SDL_ANALYZER_NORETURN __attribute__((analyzer_noreturn))
/**
* A macro to signal that a case statement without a `break` is intentional.
*
* C compilers have gotten more aggressive about warning when a switch's
* `case` block does not end with a `break` or other flow control statement,
* flowing into the next case's code, as this is a common accident that leads
* to strange bugs. But sometimes falling through to the next case is the
* correct and desired behavior. This symbol lets an app communicate this
* intention to the compiler, so it doesn't generate a warning.
*
* It is used like this:
*
* ```c
* switch (x) {
* case 1:
* DoSomethingOnlyForOne();
* SDL_FALLTHROUGH; // tell the compiler this was intentional.
* case 2:
* DoSomethingForOneAndTwo();
* break;
* }
* ```
*
* \since This macro is available since SDL 3.2.0.
*/
#define SDL_FALLTHROUGH [[fallthrough]]
/**
* A macro to tag a function's return value as critical.
*
* This is a hint to the compiler that a function's return value should not be
* ignored.
*
* If an NODISCARD function's return value is thrown away (the function is
* called as if it returns `void`), the compiler will issue a warning.
*
* While it's generally good practice to check return values for errors, often
* times legitimate programs do not for good reasons. Be careful about what
* functions are tagged as NODISCARD. It operates best when used on a function
* that's failure is surprising and catastrophic; a good example would be a
* program that checks the return values of all its file write function calls
* but not the call to close the file, which it assumes incorrectly never
* fails.
*
* Function callers that want to throw away a NODISCARD return value can call
* the function with a `(void)` cast, which informs the compiler the act is
* intentional.
*
* On compilers without nodiscard support, this is defined to nothing.
*
* \since This macro is available since SDL 3.2.0.
*/
#define SDL_NODISCARD [[nodiscard]]
/**
* A macro to tag a function as an allocator.
*
* This is a hint to the compiler that a function is an allocator, like
* malloc(), with certain rules. A description of how GCC treats this hint is
* here:
*
* https://gcc.gnu.org/onlinedocs/gcc/Common-Function-Attributes.html#index-malloc-function-attribute
*
* On compilers without allocator tag support, this is defined to nothing.
*
* Most apps don't need to, and should not, use this directly.
*
* \since This macro is available since SDL 3.2.0.
*/
#define SDL_MALLOC __declspec(allocator) __desclspec(restrict)
/**
* A macro to tag a function as returning a certain allocation.
*
* This is a hint to the compiler that a function allocates and returns a
* specific amount of memory based on one of its arguments. For example, the C
* runtime's malloc() function could use this macro with an argument of 1
* (first argument to malloc is the size of the allocation).
*
* On compilers without alloc_size support, this is defined to nothing.
*
* Most apps don't need to, and should not, use this directly.
*
* \since This macro is available since SDL 3.2.0.
*/
#define SDL_ALLOC_SIZE(p) __attribute__((alloc_size(p)))
/**
* A macro to tag a pointer variable, to help with pointer aliasing.
*
* A good explanation of the restrict keyword is here:
*
* https://en.wikipedia.org/wiki/Restrict
*
* On compilers without restrict support, this is defined to nothing.
*
* \since This macro is available since SDL 3.2.0.
*/
#define SDL_RESTRICT __restrict__
/**
* Check if the compiler supports a given builtin functionality.
*
* This allows preprocessor checks for things that otherwise might fail to
* compile.
*
* Supported by virtually all clang versions and more-recent GCCs. Use this
* instead of checking the clang version if possible.
*
* On compilers without has_builtin support, this is defined to 0 (always
* false).
*
* \since This macro is available since SDL 3.2.0.
*/
#define SDL_HAS_BUILTIN(x) __has_builtin(x)
/* end of wiki documentation section. */
#endif
#ifndef SDL_HAS_BUILTIN
#ifdef __has_builtin
#define SDL_HAS_BUILTIN(x) __has_builtin(x)
#else
#define SDL_HAS_BUILTIN(x) 0
#endif
#endif
#ifndef SDL_DEPRECATED
# if defined(__GNUC__) && (__GNUC__ >= 4) /* technically, this arrived in gcc 3.1, but oh well. */
# define SDL_DEPRECATED __attribute__((deprecated))
@ -53,7 +312,7 @@
/* Some compilers use a special export keyword */
#ifndef SDL_DECLSPEC
# if defined(SDL_PLATFORM_WIN32) || defined(SDL_PLATFORM_WINRT) || defined(SDL_PLATFORM_CYGWIN) || defined(SDL_PLATFORM_GDK)
# if defined(SDL_PLATFORM_WINDOWS)
# ifdef DLL_EXPORT
# define SDL_DECLSPEC __declspec(dllexport)
# else
@ -70,7 +329,7 @@
/* By default SDL uses the C calling convention */
#ifndef SDLCALL
#if (defined(SDL_PLATFORM_WIN32) || defined(SDL_PLATFORM_WINRT) || defined(SDL_PLATFORM_GDK)) && !defined(__GNUC__)
#if defined(SDL_PLATFORM_WINDOWS) && !defined(__GNUC__)
#define SDLCALL __cdecl
#else
#define SDLCALL

View File

@ -1,6 +1,6 @@
/*
Simple DirectMedia Layer
Copyright (C) 1997-2024 Sam Lantinga <slouken@libsdl.org>
Copyright (C) 1997-2025 Sam Lantinga <slouken@libsdl.org>
This software is provided 'as-is', without any express or implied
warranty. In no event will the authors be held liable for any damages
@ -36,10 +36,6 @@
extern "C" {
#endif
/**
* \file SDL_bits.h
*/
#if defined(__WATCOMC__) && defined(__386__)
extern __inline int _SDL_bsr_watcom(Uint32);
#pragma aux _SDL_bsr_watcom = \
@ -65,7 +61,7 @@ extern __inline int _SDL_bsr_watcom(Uint32);
*
* \threadsafety It is safe to call this function from any thread.
*
* \since This function is available since SDL 3.0.0.
* \since This function is available since SDL 3.2.0.
*/
SDL_FORCE_INLINE int SDL_MostSignificantBitIndex32(Uint32 x)
{
@ -82,10 +78,10 @@ SDL_FORCE_INLINE int SDL_MostSignificantBitIndex32(Uint32 x)
return -1;
}
return _SDL_bsr_watcom(x);
#elif defined(_MSC_VER)
#elif defined(_MSC_VER) && _MSC_VER >= 1400
unsigned long index;
if (_BitScanReverse(&index, x)) {
return index;
return (int)index;
}
return -1;
#else
@ -120,8 +116,7 @@ SDL_FORCE_INLINE int SDL_MostSignificantBitIndex32(Uint32 x)
* Determine if a unsigned 32-bit value has exactly one bit set.
*
* If there are no bits set (`x` is zero), or more than one bit set, this
* returns SDL_FALSE. If any one bit is exclusively set, this returns
* SDL_TRUE.
* returns false. If any one bit is exclusively set, this returns true.
*
* 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
@ -129,18 +124,18 @@ SDL_FORCE_INLINE int SDL_MostSignificantBitIndex32(Uint32 x)
* be able to find this function inside SDL itself).
*
* \param x the 32-bit value to examine.
* \returns SDL_TRUE if exactly one bit is set in `x`, SDL_FALSE otherwise.
* \returns true if exactly one bit is set in `x`, false otherwise.
*
* \threadsafety It is safe to call this function from any thread.
*
* \since This function is available since SDL 3.0.0.
* \since This function is available since SDL 3.2.0.
*/
SDL_FORCE_INLINE SDL_bool SDL_HasExactlyOneBitSet32(Uint32 x)
SDL_FORCE_INLINE bool SDL_HasExactlyOneBitSet32(Uint32 x)
{
if (x && !(x & (x - 1))) {
return SDL_TRUE;
return true;
}
return SDL_FALSE;
return false;
}
/* Ends C function definitions when using C++ */

View File

@ -1,6 +1,6 @@
/*
Simple DirectMedia Layer
Copyright (C) 1997-2024 Sam Lantinga <slouken@libsdl.org>
Copyright (C) 1997-2025 Sam Lantinga <slouken@libsdl.org>
This software is provided 'as-is', without any express or implied
warranty. In no event will the authors be held liable for any damages
@ -24,7 +24,7 @@
*
* Blend modes decide how two colors will mix together. There are both
* standard modes for basic needs and a means to create custom modes,
* dictating what sort of math to do what on what color components.
* dictating what sort of math to do on what color components.
*/
#ifndef SDL_blendmode_h_
@ -45,7 +45,7 @@ extern "C" {
*
* Additional values may be obtained from SDL_ComposeCustomBlendMode.
*
* \since This datatype is available since SDL 3.0.0.
* \since This datatype is available since SDL 3.2.0.
*
* \sa SDL_ComposeCustomBlendMode
*/
@ -64,7 +64,7 @@ typedef Uint32 SDL_BlendMode;
* The blend operation used when combining source and destination pixel
* components.
*
* \since This enum is available since SDL 3.0.0.
* \since This enum is available since SDL 3.2.0.
*/
typedef enum SDL_BlendOperation
{
@ -83,7 +83,7 @@ typedef enum SDL_BlendOperation
* operation. The comma-separated factors listed above are always applied in
* the component order red, green, blue, and alpha.
*
* \since This enum is available since SDL 3.0.0.
* \since This enum is available since SDL 3.2.0.
*/
typedef enum SDL_BlendFactor
{
@ -177,7 +177,9 @@ typedef enum SDL_BlendFactor
* \returns an SDL_BlendMode that represents the chosen factors and
* operations.
*
* \since This function is available since SDL 3.0.0.
* \threadsafety It is safe to call this function from any thread.
*
* \since This function is available since SDL 3.2.0.
*
* \sa SDL_SetRenderDrawBlendMode
* \sa SDL_GetRenderDrawBlendMode

View File

@ -1,6 +1,6 @@
/*
Simple DirectMedia Layer
Copyright (C) 1997-2024 Sam Lantinga <slouken@libsdl.org>
Copyright (C) 1997-2025 Sam Lantinga <slouken@libsdl.org>
This software is provided 'as-is', without any express or implied
warranty. In no event will the authors be held liable for any damages
@ -28,13 +28,51 @@
* devices can be enumerated, queried, and opened. Once opened, it will
* provide SDL_Surface objects as new frames of video come in. These surfaces
* can be uploaded to an SDL_Texture or processed as pixels in memory.
*
* Several platforms will alert the user if an app tries to access a camera,
* and some will present a UI asking the user if your application should be
* allowed to obtain images at all, which they can deny. A successfully opened
* camera will not provide images until permission is granted. Applications,
* after opening a camera device, can see if they were granted access by
* either polling with the SDL_GetCameraPermissionState() function, or waiting
* for an SDL_EVENT_CAMERA_DEVICE_APPROVED or SDL_EVENT_CAMERA_DEVICE_DENIED
* event. Platforms that don't have any user approval process will report
* approval immediately.
*
* Note that SDL cameras only provide video as individual frames; they will
* not provide full-motion video encoded in a movie file format, although an
* app is free to encode the acquired frames into any format it likes. It also
* does not provide audio from the camera hardware through this API; not only
* do many webcams not have microphones at all, many people--from streamers to
* people on Zoom calls--will want to use a separate microphone regardless of
* the camera. In any case, recorded audio will be available through SDL's
* audio API no matter what hardware provides the microphone.
*
* ## Camera gotchas
*
* Consumer-level camera hardware tends to take a little while to warm up,
* once the device has been opened. Generally most camera apps have some sort
* of UI to take a picture (a button to snap a pic while a preview is showing,
* some sort of multi-second countdown for the user to pose, like a photo
* booth), which puts control in the users' hands, or they are intended to
* stay on for long times (Pokemon Go, etc).
*
* It's not uncommon that a newly-opened camera will provide a couple of
* completely black frames, maybe followed by some under-exposed images. If
* taking a single frame automatically, or recording video from a camera's
* input without the user initiating it from a preview, it could be wise to
* drop the first several frames (if not the first several _seconds_ worth of
* frames!) before using images from a camera.
*/
#ifndef SDL_camera_h_
#define SDL_camera_h_
#include <SDL3/SDL_stdinc.h>
#include <SDL3/SDL_error.h>
#include <SDL3/SDL_video.h>
#include <SDL3/SDL_pixels.h>
#include <SDL3/SDL_properties.h>
#include <SDL3/SDL_surface.h>
#include <SDL3/SDL_begin_code.h>
/* Set up for C function definitions, even when using C++ */
@ -50,7 +88,7 @@ extern "C" {
*
* The value 0 is an invalid ID.
*
* \since This datatype is available since SDL 3.0.0.
* \since This datatype is available since SDL 3.2.0.
*
* \sa SDL_GetCameras
*/
@ -59,7 +97,7 @@ typedef Uint32 SDL_CameraID;
/**
* The opaque structure used to identify an opened SDL camera.
*
* \since This struct is available since SDL 3.0.0.
* \since This struct is available since SDL 3.2.0.
*/
typedef struct SDL_Camera SDL_Camera;
@ -69,7 +107,7 @@ typedef struct SDL_Camera SDL_Camera;
* Cameras often support multiple formats; each one will be encapsulated in
* this struct.
*
* \since This struct is available since SDL 3.0.0.
* \since This struct is available since SDL 3.2.0.
*
* \sa SDL_GetCameraSupportedFormats
* \sa SDL_GetCameraFormat
@ -87,7 +125,7 @@ typedef struct SDL_CameraSpec
/**
* The position of camera in relation to system device.
*
* \since This enum is available since SDL 3.0.0.
* \since This enum is available since SDL 3.2.0.
*
* \sa SDL_GetCameraPosition
*/
@ -116,7 +154,7 @@ typedef enum SDL_CameraPosition
*
* \threadsafety It is safe to call this function from any thread.
*
* \since This function is available since SDL 3.0.0.
* \since This function is available since SDL 3.2.0.
*
* \sa SDL_GetCameraDriver
*/
@ -140,7 +178,7 @@ extern SDL_DECLSPEC int SDLCALL SDL_GetNumCameraDrivers(void);
*
* \threadsafety It is safe to call this function from any thread.
*
* \since This function is available since SDL 3.0.0.
* \since This function is available since SDL 3.2.0.
*
* \sa SDL_GetNumCameraDrivers
*/
@ -158,7 +196,7 @@ extern SDL_DECLSPEC const char * SDLCALL SDL_GetCameraDriver(int index);
*
* \threadsafety It is safe to call this function from any thread.
*
* \since This function is available since SDL 3.0.0.
* \since This function is available since SDL 3.2.0.
*/
extern SDL_DECLSPEC const char * SDLCALL SDL_GetCurrentCameraDriver(void);
@ -173,7 +211,7 @@ extern SDL_DECLSPEC const char * SDLCALL SDL_GetCurrentCameraDriver(void);
*
* \threadsafety It is safe to call this function from any thread.
*
* \since This function is available since SDL 3.0.0.
* \since This function is available since SDL 3.2.0.
*
* \sa SDL_OpenCamera
*/
@ -211,7 +249,7 @@ extern SDL_DECLSPEC SDL_CameraID * SDLCALL SDL_GetCameras(int *count);
*
* \threadsafety It is safe to call this function from any thread.
*
* \since This function is available since SDL 3.0.0.
* \since This function is available since SDL 3.2.0.
*
* \sa SDL_GetCameras
* \sa SDL_OpenCamera
@ -227,7 +265,7 @@ extern SDL_DECLSPEC SDL_CameraSpec ** SDLCALL SDL_GetCameraSupportedFormats(SDL_
*
* \threadsafety It is safe to call this function from any thread.
*
* \since This function is available since SDL 3.0.0.
* \since This function is available since SDL 3.2.0.
*
* \sa SDL_GetCameras
*/
@ -246,7 +284,7 @@ extern SDL_DECLSPEC const char * SDLCALL SDL_GetCameraName(SDL_CameraID instance
*
* \threadsafety It is safe to call this function from any thread.
*
* \since This function is available since SDL 3.0.0.
* \since This function is available since SDL 3.2.0.
*
* \sa SDL_GetCameras
*/
@ -265,7 +303,7 @@ extern SDL_DECLSPEC SDL_CameraPosition SDLCALL SDL_GetCameraPosition(SDL_CameraI
*
* You can call SDL_GetCameraFormat() to get the actual data format if passing
* a NULL spec here. You can see the exact specs a device can support without
* conversion with SDL_GetCameraSupportedSpecs().
* conversion with SDL_GetCameraSupportedFormats().
*
* SDL will not attempt to emulate framerate; it will try to set the hardware
* to the rate closest to the requested speed, but it won't attempt to limit
@ -278,10 +316,11 @@ extern SDL_DECLSPEC SDL_CameraPosition SDLCALL SDL_GetCameraPosition(SDL_CameraI
* the camera, and they can choose Yes or No at that point. Until they do, the
* camera will not be usable. The app should either wait for an
* SDL_EVENT_CAMERA_DEVICE_APPROVED (or SDL_EVENT_CAMERA_DEVICE_DENIED) event,
* or poll SDL_IsCameraApproved() occasionally until it returns non-zero. On
* platforms that don't require explicit user approval (and perhaps in places
* where the user previously permitted access), the approval event might come
* immediately, but it might come seconds, minutes, or hours later!
* or poll SDL_GetCameraPermissionState() occasionally until it returns
* non-zero. On platforms that don't require explicit user approval (and
* perhaps in places where the user previously permitted access), the approval
* event might come immediately, but it might come seconds, minutes, or hours
* later!
*
* \param instance_id the camera device instance ID.
* \param spec the desired format for data the device will provide. Can be
@ -291,7 +330,7 @@ extern SDL_DECLSPEC SDL_CameraPosition SDLCALL SDL_GetCameraPosition(SDL_CameraI
*
* \threadsafety It is safe to call this function from any thread.
*
* \since This function is available since SDL 3.0.0.
* \since This function is available since SDL 3.2.0.
*
* \sa SDL_GetCameras
* \sa SDL_GetCameraFormat
@ -324,7 +363,7 @@ extern SDL_DECLSPEC SDL_Camera * SDLCALL SDL_OpenCamera(SDL_CameraID instance_id
*
* \threadsafety It is safe to call this function from any thread.
*
* \since This function is available since SDL 3.0.0.
* \since This function is available since SDL 3.2.0.
*
* \sa SDL_OpenCamera
* \sa SDL_CloseCamera
@ -340,7 +379,7 @@ extern SDL_DECLSPEC int SDLCALL SDL_GetCameraPermissionState(SDL_Camera *camera)
*
* \threadsafety It is safe to call this function from any thread.
*
* \since This function is available since SDL 3.0.0.
* \since This function is available since SDL 3.2.0.
*
* \sa SDL_OpenCamera
*/
@ -355,7 +394,7 @@ extern SDL_DECLSPEC SDL_CameraID SDLCALL SDL_GetCameraID(SDL_Camera *camera);
*
* \threadsafety It is safe to call this function from any thread.
*
* \since This function is available since SDL 3.0.0.
* \since This function is available since SDL 3.2.0.
*/
extern SDL_DECLSPEC SDL_PropertiesID SDLCALL SDL_GetCameraProperties(SDL_Camera *camera);
@ -366,23 +405,24 @@ extern SDL_DECLSPEC SDL_PropertiesID SDLCALL SDL_GetCameraProperties(SDL_Camera
* be converting to this format behind the scenes.
*
* If the system is waiting for the user to approve access to the camera, as
* some platforms require, this will return SDL_FALSE, but this isn't
* necessarily a fatal error; you should either wait for an
* some platforms require, this will return false, but this isn't necessarily
* a fatal error; you should either wait for an
* SDL_EVENT_CAMERA_DEVICE_APPROVED (or SDL_EVENT_CAMERA_DEVICE_DENIED) event,
* or poll SDL_IsCameraApproved() occasionally until it returns non-zero.
* or poll SDL_GetCameraPermissionState() occasionally until it returns
* non-zero.
*
* \param camera opened camera device.
* \param spec the SDL_CameraSpec to be initialized by this function.
* \returns SDL_TRUE on success or SDL_FALSE on failure; call SDL_GetError()
* for more information.
* \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.0.0.
* \since This function is available since SDL 3.2.0.
*
* \sa SDL_OpenCamera
*/
extern SDL_DECLSPEC SDL_bool SDLCALL SDL_GetCameraFormat(SDL_Camera *camera, SDL_CameraSpec *spec);
extern SDL_DECLSPEC bool SDLCALL SDL_GetCameraFormat(SDL_Camera *camera, SDL_CameraSpec *spec);
/**
* Acquire a frame.
@ -404,14 +444,14 @@ extern SDL_DECLSPEC SDL_bool SDLCALL SDL_GetCameraFormat(SDL_Camera *camera, SDL
* After use, the frame should be released with SDL_ReleaseCameraFrame(). If
* you don't do this, the system may stop providing more video!
*
* Do not call SDL_FreeSurface() on the returned surface! It must be given
* Do not call SDL_DestroySurface() on the returned surface! It must be given
* back to the camera subsystem with SDL_ReleaseCameraFrame!
*
* If the system is waiting for the user to approve access to the camera, as
* some platforms require, this will return NULL (no frames available); you
* should either wait for an SDL_EVENT_CAMERA_DEVICE_APPROVED (or
* SDL_EVENT_CAMERA_DEVICE_DENIED) event, or poll SDL_IsCameraApproved()
* occasionally until it returns non-zero.
* SDL_EVENT_CAMERA_DEVICE_DENIED) event, or poll
* SDL_GetCameraPermissionState() occasionally until it returns non-zero.
*
* \param camera opened camera device.
* \param timestampNS a pointer filled in with the frame's timestamp, or 0 on
@ -421,7 +461,7 @@ extern SDL_DECLSPEC SDL_bool SDLCALL SDL_GetCameraFormat(SDL_Camera *camera, SDL
*
* \threadsafety It is safe to call this function from any thread.
*
* \since This function is available since SDL 3.0.0.
* \since This function is available since SDL 3.2.0.
*
* \sa SDL_ReleaseCameraFrame
*/
@ -449,7 +489,7 @@ extern SDL_DECLSPEC SDL_Surface * SDLCALL SDL_AcquireCameraFrame(SDL_Camera *cam
*
* \threadsafety It is safe to call this function from any thread.
*
* \since This function is available since SDL 3.0.0.
* \since This function is available since SDL 3.2.0.
*
* \sa SDL_AcquireCameraFrame
*/
@ -464,9 +504,8 @@ extern SDL_DECLSPEC void SDLCALL SDL_ReleaseCameraFrame(SDL_Camera *camera, SDL_
* \threadsafety It is safe to call this function from any thread, but no
* thread may reference `device` once this function is called.
*
* \since This function is available since SDL 3.0.0.
* \since This function is available since SDL 3.2.0.
*
* \sa SDL_OpenCameraWithSpec
* \sa SDL_OpenCamera
*/
extern SDL_DECLSPEC void SDLCALL SDL_CloseCamera(SDL_Camera *camera);

View File

@ -1,6 +1,6 @@
/*
Simple DirectMedia Layer
Copyright (C) 1997-2024 Sam Lantinga <slouken@libsdl.org>
Copyright (C) 1997-2025 Sam Lantinga <slouken@libsdl.org>
This software is provided 'as-is', without any express or implied
warranty. In no event will the authors be held liable for any damages
@ -26,6 +26,51 @@
* from other processes and publishing information of its own.
*
* This is not just text! SDL apps can access and publish data by mimetype.
*
* ## Basic use (text)
*
* Obtaining and publishing simple text to the system clipboard is as easy as
* calling SDL_GetClipboardText() and SDL_SetClipboardText(), respectively.
* These deal with C strings in UTF-8 encoding. Data transmission and encoding
* conversion is completely managed by SDL.
*
* ## Clipboard callbacks (data other than text)
*
* Things get more complicated when the clipboard contains something other
* than text. Not only can the system clipboard contain data of any type, in
* some cases it can contain the same data in different formats! For example,
* an image painting app might let the user copy a graphic to the clipboard,
* and offers it in .BMP, .JPG, or .PNG format for other apps to consume.
*
* Obtaining clipboard data ("pasting") like this is a matter of calling
* SDL_GetClipboardData() and telling it the mimetype of the data you want.
* But how does one know if that format is available? SDL_HasClipboardData()
* can report if a specific mimetype is offered, and
* SDL_GetClipboardMimeTypes() can provide the entire list of mimetypes
* available, so the app can decide what to do with the data and what formats
* it can support.
*
* Setting the clipboard ("copying") to arbitrary data is done with
* SDL_SetClipboardData. The app does not provide the data in this call, but
* rather the mimetypes it is willing to provide and a callback function.
* During the callback, the app will generate the data. This allows massive
* data sets to be provided to the clipboard, without any data being copied
* before it is explicitly requested. More specifically, it allows an app to
* offer data in multiple formats without providing a copy of all of them
* upfront. If the app has an image that it could provide in PNG or JPG
* format, it doesn't have to encode it to either of those unless and until
* something tries to paste it.
*
* ## Primary Selection
*
* The X11 and Wayland video targets have a concept of the "primary selection"
* in addition to the usual clipboard. This is generally highlighted (but not
* explicitly copied) text from various apps. SDL offers APIs for this through
* SDL_GetPrimarySelectionText() and SDL_SetPrimarySelectionText(). SDL offers
* these APIs on platforms without this concept, too, but only so far that it
* will keep a copy of a string that the app sets for later retrieval; the
* operating system will not ever attempt to change the string externally if
* it doesn't support a primary selection.
*/
#ifndef SDL_clipboard_h_
@ -46,27 +91,31 @@ extern "C" {
* Put UTF-8 text into the clipboard.
*
* \param text the text to store in the clipboard.
* \returns SDL_TRUE on success or SDL_FALSE on failure; call SDL_GetError()
* for more information.
* \returns true on success or false on failure; call SDL_GetError() for more
* information.
*
* \since This function is available since SDL 3.0.0.
* \threadsafety This function should only be called on the main thread.
*
* \since This function is available since SDL 3.2.0.
*
* \sa SDL_GetClipboardText
* \sa SDL_HasClipboardText
*/
extern SDL_DECLSPEC SDL_bool SDLCALL SDL_SetClipboardText(const char *text);
extern SDL_DECLSPEC bool SDLCALL SDL_SetClipboardText(const char *text);
/**
* Get UTF-8 text from the clipboard.
*
* This functions returns empty string if there was not enough memory left for
* a copy of the clipboard's content.
* This functions returns an empty string if there was not enough memory left
* for a copy of the clipboard's content.
*
* \returns the clipboard text on success or an empty string on failure; call
* SDL_GetError() for more information. This should be freed with
* SDL_free() when it is no longer needed.
*
* \since This function is available since SDL 3.0.0.
* \threadsafety This function should only be called on the main thread.
*
* \since This function is available since SDL 3.2.0.
*
* \sa SDL_HasClipboardText
* \sa SDL_SetClipboardText
@ -76,40 +125,46 @@ extern SDL_DECLSPEC char * SDLCALL SDL_GetClipboardText(void);
/**
* Query whether the clipboard exists and contains a non-empty text string.
*
* \returns SDL_TRUE if the clipboard has text, or SDL_FALSE if it does not.
* \returns true if the clipboard has text, or false if it does not.
*
* \since This function is available since SDL 3.0.0.
* \threadsafety This function should only be called on the main thread.
*
* \since This function is available since SDL 3.2.0.
*
* \sa SDL_GetClipboardText
* \sa SDL_SetClipboardText
*/
extern SDL_DECLSPEC SDL_bool SDLCALL SDL_HasClipboardText(void);
extern SDL_DECLSPEC bool SDLCALL SDL_HasClipboardText(void);
/**
* Put UTF-8 text into the primary selection.
*
* \param text the text to store in the primary selection.
* \returns SDL_TRUE on success or SDL_FALSE on failure; call SDL_GetError()
* for more information.
* \returns true on success or false on failure; call SDL_GetError() for more
* information.
*
* \since This function is available since SDL 3.0.0.
* \threadsafety This function should only be called on the main thread.
*
* \since This function is available since SDL 3.2.0.
*
* \sa SDL_GetPrimarySelectionText
* \sa SDL_HasPrimarySelectionText
*/
extern SDL_DECLSPEC SDL_bool SDLCALL SDL_SetPrimarySelectionText(const char *text);
extern SDL_DECLSPEC bool SDLCALL SDL_SetPrimarySelectionText(const char *text);
/**
* Get UTF-8 text from the primary selection.
*
* This functions returns empty string if there was not enough memory left for
* a copy of the primary selection's content.
* This functions returns an empty string if there was not enough memory left
* for a copy of the primary selection's content.
*
* \returns the primary selection text on success or an empty string on
* failure; call SDL_GetError() for more information. This should be
* freed with SDL_free() when it is no longer needed.
*
* \since This function is available since SDL 3.0.0.
* \threadsafety This function should only be called on the main thread.
*
* \since This function is available since SDL 3.2.0.
*
* \sa SDL_HasPrimarySelectionText
* \sa SDL_SetPrimarySelectionText
@ -120,15 +175,16 @@ extern SDL_DECLSPEC char * SDLCALL SDL_GetPrimarySelectionText(void);
* Query whether the primary selection exists and contains a non-empty text
* string.
*
* \returns SDL_TRUE if the primary selection has text, or SDL_FALSE if it
* does not.
* \returns true if the primary selection has text, or false if it does not.
*
* \since This function is available since SDL 3.0.0.
* \threadsafety This function should only be called on the main thread.
*
* \since This function is available since SDL 3.2.0.
*
* \sa SDL_GetPrimarySelectionText
* \sa SDL_SetPrimarySelectionText
*/
extern SDL_DECLSPEC SDL_bool SDLCALL SDL_HasPrimarySelectionText(void);
extern SDL_DECLSPEC bool SDLCALL SDL_HasPrimarySelectionText(void);
/**
* Callback function that will be called when data for the specified mime-type
@ -148,7 +204,7 @@ extern SDL_DECLSPEC SDL_bool SDLCALL SDL_HasPrimarySelectionText(void);
* breakage in receiving applications. The returned data will not be
* freed so it needs to be retained and dealt with internally.
*
* \since This function is available since SDL 3.0.0.
* \since This function is available since SDL 3.2.0.
*
* \sa SDL_SetClipboardData
*/
@ -160,7 +216,7 @@ typedef const void *(SDLCALL *SDL_ClipboardDataCallback)(void *userdata, const c
*
* \param userdata a pointer to provided user data.
*
* \since This function is available since SDL 3.0.0.
* \since This function is available since SDL 3.2.0.
*
* \sa SDL_SetClipboardData
*/
@ -170,13 +226,13 @@ typedef void (SDLCALL *SDL_ClipboardCleanupCallback)(void *userdata);
* Offer clipboard data to the OS.
*
* Tell the operating system that the application is offering clipboard data
* for each of the proivded mime-types. Once another application requests the
* data the callback function will be called allowing it to generate and
* for each of the provided mime-types. Once another application requests the
* data the callback function will be called, allowing it to generate and
* respond with the data for the requested mime-type.
*
* The size of text data does not include any terminator, and the text does
* not need to be null terminated (e.g. you can directly copy a portion of a
* document)
* document).
*
* \param callback a function pointer to the function that provides the
* clipboard data.
@ -185,28 +241,32 @@ typedef void (SDLCALL *SDL_ClipboardCleanupCallback)(void *userdata);
* \param userdata an opaque pointer that will be forwarded to the callbacks.
* \param mime_types a list of mime-types that are being offered.
* \param num_mime_types the number of mime-types in the mime_types list.
* \returns SDL_TRUE on success or SDL_FALSE on failure; call SDL_GetError()
* for more information.
* \returns true on success or false on failure; call SDL_GetError() for more
* information.
*
* \since This function is available since SDL 3.0.0.
* \threadsafety This function should only be called on the main thread.
*
* \since This function is available since SDL 3.2.0.
*
* \sa SDL_ClearClipboardData
* \sa SDL_GetClipboardData
* \sa SDL_HasClipboardData
*/
extern SDL_DECLSPEC SDL_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 **mime_types, size_t num_mime_types);
/**
* Clear the clipboard data.
*
* \returns SDL_TRUE on success or SDL_FALSE on failure; call SDL_GetError()
* for more information.
* \returns true on success or false on failure; call SDL_GetError() for more
* information.
*
* \since This function is available since SDL 3.0.0.
* \threadsafety This function should only be called on the main thread.
*
* \since This function is available since SDL 3.2.0.
*
* \sa SDL_SetClipboardData
*/
extern SDL_DECLSPEC SDL_bool SDLCALL SDL_ClearClipboardData(void);
extern SDL_DECLSPEC bool SDLCALL SDL_ClearClipboardData(void);
/**
* Get the data from clipboard for a given mime type.
@ -220,7 +280,9 @@ extern SDL_DECLSPEC SDL_bool SDLCALL SDL_ClearClipboardData(void);
* for more information. This should be freed with SDL_free() when it
* is no longer needed.
*
* \since This function is available since SDL 3.0.0.
* \threadsafety This function should only be called on the main thread.
*
* \since This function is available since SDL 3.2.0.
*
* \sa SDL_HasClipboardData
* \sa SDL_SetClipboardData
@ -231,15 +293,34 @@ extern SDL_DECLSPEC void * SDLCALL SDL_GetClipboardData(const char *mime_type, s
* Query whether there is data in the clipboard for the provided mime type.
*
* \param mime_type the mime type to check for data for.
* \returns SDL_TRUE if there exists data in clipboard for the provided mime
* type, SDL_FALSE if it does not.
* \returns true if there exists data in clipboard for the provided mime type,
* false if it does not.
*
* \since This function is available since SDL 3.0.0.
* \threadsafety This function should only be called on the main thread.
*
* \since This function is available since SDL 3.2.0.
*
* \sa SDL_SetClipboardData
* \sa SDL_GetClipboardData
*/
extern SDL_DECLSPEC SDL_bool SDLCALL SDL_HasClipboardData(const char *mime_type);
extern SDL_DECLSPEC bool SDLCALL SDL_HasClipboardData(const char *mime_type);
/**
* Retrieve the list of mime types available in the clipboard.
*
* \param num_mime_types a pointer filled with the number of mime types, may
* be NULL.
* \returns a null terminated array of strings with mime types, or NULL on
* failure; call SDL_GetError() for more information. This should be
* freed with SDL_free() when it is no longer needed.
*
* \threadsafety This function should only be called on the main thread.
*
* \since This function is available since SDL 3.2.0.
*
* \sa SDL_SetClipboardData
*/
extern SDL_DECLSPEC char ** SDLCALL SDL_GetClipboardMimeTypes(size_t *num_mime_types);
/* Ends C function definitions when using C++ */
#ifdef __cplusplus

View File

@ -1,6 +1,6 @@
/*
Simple DirectMedia Layer
Copyright (C) 1997-2024 Sam Lantinga <slouken@libsdl.org>
Copyright (C) 1997-2025 Sam Lantinga <slouken@libsdl.org>
This software is provided 'as-is', without any express or implied
warranty. In no event will the authors be held liable for any damages
@ -21,7 +21,10 @@
/*
* This file reverses the effects of SDL_begin_code.h and should be included
* after you finish any function and structure declarations in your headers
* after you finish any function and structure declarations in your headers.
*
* SDL's headers use this; applications generally should not include this
* header directly.
*/
#ifndef SDL_begin_code_h

View File

@ -1,6 +1,6 @@
/*
Simple DirectMedia Layer
Copyright (C) 1997-2024 Sam Lantinga <slouken@libsdl.org>
Copyright (C) 1997-2025 Sam Lantinga <slouken@libsdl.org>
This software is provided 'as-is', without any express or implied
warranty. In no event will the authors be held liable for any damages

View File

@ -1,6 +1,6 @@
/*
Simple DirectMedia Layer
Copyright (C) 1997-2024 Sam Lantinga <slouken@libsdl.org>
Copyright (C) 1997-2025 Sam Lantinga <slouken@libsdl.org>
This software is provided 'as-is', without any express or implied
warranty. In no event will the authors be held liable for any damages
@ -29,6 +29,12 @@
* These functions are largely concerned with reporting if the system has
* access to various SIMD instruction sets, but also has other important info
* to share, such as system RAM size and number of logical CPU cores.
*
* CPU instruction set checks, like SDL_HasSSE() and SDL_HasNEON(), are
* available on all platforms, even if they don't make sense (an ARM processor
* will never have SSE and an x86 processor will never have NEON, for example,
* but these functions still exist and will simply return false in these
* cases).
*/
#ifndef SDL_cpuinfo_h_
@ -49,20 +55,22 @@ extern "C" {
* processors have a 128 byte cache line. We use the larger value to be
* generally safe.
*
* \since This macro is available since SDL 3.0.0.
* \since This macro is available since SDL 3.2.0.
*/
#define SDL_CACHELINE_SIZE 128
/**
* Get the number of CPU cores available.
* Get the number of logical CPU cores available.
*
* \returns the total number of logical CPU cores. On CPUs that include
* technologies such as hyperthreading, the number of logical cores
* may be more than the number of physical cores.
*
* \since This function is available since SDL 3.0.0.
* \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_GetCPUCount(void);
extern SDL_DECLSPEC int SDLCALL SDL_GetNumLogicalCPUCores(void);
/**
* Determine the L1 cache line size of the CPU.
@ -72,7 +80,9 @@ extern SDL_DECLSPEC int SDLCALL SDL_GetCPUCount(void);
*
* \returns the L1 cache line size of the CPU, in bytes.
*
* \since This function is available since SDL 3.0.0.
* \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_GetCPUCacheLineSize(void);
@ -82,144 +92,164 @@ extern SDL_DECLSPEC int SDLCALL SDL_GetCPUCacheLineSize(void);
* This always returns false on CPUs that aren't using PowerPC instruction
* sets.
*
* \returns SDL_TRUE if the CPU has AltiVec features or SDL_FALSE if not.
* \returns true if the CPU has AltiVec features or false if not.
*
* \since This function is available since SDL 3.0.0.
* \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_bool SDLCALL SDL_HasAltiVec(void);
extern SDL_DECLSPEC bool SDLCALL SDL_HasAltiVec(void);
/**
* Determine whether the CPU has MMX features.
*
* This always returns false on CPUs that aren't using Intel instruction sets.
*
* \returns SDL_TRUE if the CPU has MMX features or SDL_FALSE if not.
* \returns true if the CPU has MMX features or false if not.
*
* \since This function is available since SDL 3.0.0.
* \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_bool SDLCALL SDL_HasMMX(void);
extern SDL_DECLSPEC bool SDLCALL SDL_HasMMX(void);
/**
* Determine whether the CPU has SSE features.
*
* This always returns false on CPUs that aren't using Intel instruction sets.
*
* \returns SDL_TRUE if the CPU has SSE features or SDL_FALSE if not.
* \returns true if the CPU has SSE features or false if not.
*
* \since This function is available since SDL 3.0.0.
* \threadsafety It is safe to call this function from any thread.
*
* \since This function is available since SDL 3.2.0.
*
* \sa SDL_HasSSE2
* \sa SDL_HasSSE3
* \sa SDL_HasSSE41
* \sa SDL_HasSSE42
*/
extern SDL_DECLSPEC SDL_bool SDLCALL SDL_HasSSE(void);
extern SDL_DECLSPEC bool SDLCALL SDL_HasSSE(void);
/**
* Determine whether the CPU has SSE2 features.
*
* This always returns false on CPUs that aren't using Intel instruction sets.
*
* \returns SDL_TRUE if the CPU has SSE2 features or SDL_FALSE if not.
* \returns true if the CPU has SSE2 features or false if not.
*
* \since This function is available since SDL 3.0.0.
* \threadsafety It is safe to call this function from any thread.
*
* \since This function is available since SDL 3.2.0.
*
* \sa SDL_HasSSE
* \sa SDL_HasSSE3
* \sa SDL_HasSSE41
* \sa SDL_HasSSE42
*/
extern SDL_DECLSPEC SDL_bool SDLCALL SDL_HasSSE2(void);
extern SDL_DECLSPEC bool SDLCALL SDL_HasSSE2(void);
/**
* Determine whether the CPU has SSE3 features.
*
* This always returns false on CPUs that aren't using Intel instruction sets.
*
* \returns SDL_TRUE if the CPU has SSE3 features or SDL_FALSE if not.
* \returns true if the CPU has SSE3 features or false if not.
*
* \since This function is available since SDL 3.0.0.
* \threadsafety It is safe to call this function from any thread.
*
* \since This function is available since SDL 3.2.0.
*
* \sa SDL_HasSSE
* \sa SDL_HasSSE2
* \sa SDL_HasSSE41
* \sa SDL_HasSSE42
*/
extern SDL_DECLSPEC SDL_bool SDLCALL SDL_HasSSE3(void);
extern SDL_DECLSPEC bool SDLCALL SDL_HasSSE3(void);
/**
* Determine whether the CPU has SSE4.1 features.
*
* This always returns false on CPUs that aren't using Intel instruction sets.
*
* \returns SDL_TRUE if the CPU has SSE4.1 features or SDL_FALSE if not.
* \returns true if the CPU has SSE4.1 features or false if not.
*
* \since This function is available since SDL 3.0.0.
* \threadsafety It is safe to call this function from any thread.
*
* \since This function is available since SDL 3.2.0.
*
* \sa SDL_HasSSE
* \sa SDL_HasSSE2
* \sa SDL_HasSSE3
* \sa SDL_HasSSE42
*/
extern SDL_DECLSPEC SDL_bool SDLCALL SDL_HasSSE41(void);
extern SDL_DECLSPEC bool SDLCALL SDL_HasSSE41(void);
/**
* Determine whether the CPU has SSE4.2 features.
*
* This always returns false on CPUs that aren't using Intel instruction sets.
*
* \returns SDL_TRUE if the CPU has SSE4.2 features or SDL_FALSE if not.
* \returns true if the CPU has SSE4.2 features or false if not.
*
* \since This function is available since SDL 3.0.0.
* \threadsafety It is safe to call this function from any thread.
*
* \since This function is available since SDL 3.2.0.
*
* \sa SDL_HasSSE
* \sa SDL_HasSSE2
* \sa SDL_HasSSE3
* \sa SDL_HasSSE41
*/
extern SDL_DECLSPEC SDL_bool SDLCALL SDL_HasSSE42(void);
extern SDL_DECLSPEC bool SDLCALL SDL_HasSSE42(void);
/**
* Determine whether the CPU has AVX features.
*
* This always returns false on CPUs that aren't using Intel instruction sets.
*
* \returns SDL_TRUE if the CPU has AVX features or SDL_FALSE if not.
* \returns true if the CPU has AVX features or false if not.
*
* \since This function is available since SDL 3.0.0.
* \threadsafety It is safe to call this function from any thread.
*
* \since This function is available since SDL 3.2.0.
*
* \sa SDL_HasAVX2
* \sa SDL_HasAVX512F
*/
extern SDL_DECLSPEC SDL_bool SDLCALL SDL_HasAVX(void);
extern SDL_DECLSPEC bool SDLCALL SDL_HasAVX(void);
/**
* Determine whether the CPU has AVX2 features.
*
* This always returns false on CPUs that aren't using Intel instruction sets.
*
* \returns SDL_TRUE if the CPU has AVX2 features or SDL_FALSE if not.
* \returns true if the CPU has AVX2 features or false if not.
*
* \since This function is available since SDL 3.0.0.
* \threadsafety It is safe to call this function from any thread.
*
* \since This function is available since SDL 3.2.0.
*
* \sa SDL_HasAVX
* \sa SDL_HasAVX512F
*/
extern SDL_DECLSPEC SDL_bool SDLCALL SDL_HasAVX2(void);
extern SDL_DECLSPEC bool SDLCALL SDL_HasAVX2(void);
/**
* Determine whether the CPU has AVX-512F (foundation) features.
*
* This always returns false on CPUs that aren't using Intel instruction sets.
*
* \returns SDL_TRUE if the CPU has AVX-512F features or SDL_FALSE if not.
* \returns true if the CPU has AVX-512F features or false if not.
*
* \since This function is available since SDL 3.0.0.
* \threadsafety It is safe to call this function from any thread.
*
* \since This function is available since SDL 3.2.0.
*
* \sa SDL_HasAVX
* \sa SDL_HasAVX2
*/
extern SDL_DECLSPEC SDL_bool SDLCALL SDL_HasAVX512F(void);
extern SDL_DECLSPEC bool SDLCALL SDL_HasAVX512F(void);
/**
* Determine whether the CPU has ARM SIMD (ARMv6) features.
@ -228,24 +258,28 @@ extern SDL_DECLSPEC SDL_bool SDLCALL SDL_HasAVX512F(void);
*
* This always returns false on CPUs that aren't using ARM instruction sets.
*
* \returns SDL_TRUE if the CPU has ARM SIMD features or SDL_FALSE if not.
* \returns true if the CPU has ARM SIMD features or false if not.
*
* \since This function is available since SDL 3.0.0.
* \threadsafety It is safe to call this function from any thread.
*
* \since This function is available since SDL 3.2.0.
*
* \sa SDL_HasNEON
*/
extern SDL_DECLSPEC SDL_bool SDLCALL SDL_HasARMSIMD(void);
extern SDL_DECLSPEC bool SDLCALL SDL_HasARMSIMD(void);
/**
* Determine whether the CPU has NEON (ARM SIMD) features.
*
* This always returns false on CPUs that aren't using ARM instruction sets.
*
* \returns SDL_TRUE if the CPU has ARM NEON features or SDL_FALSE if not.
* \returns true if the CPU has ARM NEON features or false if not.
*
* \since This function is available since SDL 3.0.0.
* \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_bool SDLCALL SDL_HasNEON(void);
extern SDL_DECLSPEC bool SDLCALL SDL_HasNEON(void);
/**
* Determine whether the CPU has LSX (LOONGARCH SIMD) features.
@ -253,12 +287,13 @@ extern SDL_DECLSPEC SDL_bool SDLCALL SDL_HasNEON(void);
* This always returns false on CPUs that aren't using LOONGARCH instruction
* sets.
*
* \returns SDL_TRUE if the CPU has LOONGARCH LSX features or SDL_FALSE if
* not.
* \returns true if the CPU has LOONGARCH LSX features or false if not.
*
* \since This function is available since SDL 3.0.0.
* \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_bool SDLCALL SDL_HasLSX(void);
extern SDL_DECLSPEC bool SDLCALL SDL_HasLSX(void);
/**
* Determine whether the CPU has LASX (LOONGARCH SIMD) features.
@ -266,19 +301,22 @@ extern SDL_DECLSPEC SDL_bool SDLCALL SDL_HasLSX(void);
* This always returns false on CPUs that aren't using LOONGARCH instruction
* sets.
*
* \returns SDL_TRUE if the CPU has LOONGARCH LASX features or SDL_FALSE if
* not.
* \returns true if the CPU has LOONGARCH LASX features or false if not.
*
* \since This function is available since SDL 3.0.0.
* \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_bool SDLCALL SDL_HasLASX(void);
extern SDL_DECLSPEC bool SDLCALL SDL_HasLASX(void);
/**
* Get the amount of RAM configured in the system.
*
* \returns the amount of RAM configured in the system in MiB.
*
* \since This function is available since SDL 3.0.0.
* \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_GetSystemRAM(void);
@ -297,7 +335,9 @@ extern SDL_DECLSPEC int SDLCALL SDL_GetSystemRAM(void);
* \returns the alignment in bytes needed for available, known SIMD
* instructions.
*
* \since This function is available since SDL 3.0.0.
* \threadsafety It is safe to call this function from any thread.
*
* \since This function is available since SDL 3.2.0.
*
* \sa SDL_aligned_alloc
* \sa SDL_aligned_free

View File

@ -1,6 +1,6 @@
/*
Simple DirectMedia Layer
Copyright (C) 1997-2024 Sam Lantinga <slouken@libsdl.org>
Copyright (C) 1997-2025 Sam Lantinga <slouken@libsdl.org>
This software is provided 'as-is', without any express or implied
warranty. In no event will the authors be held liable for any damages
@ -23,12 +23,23 @@
* # CategoryDialog
*
* File dialog support.
*
* SDL offers file dialogs, to let users select files with native GUI
* interfaces. There are "open" dialogs, "save" dialogs, and folder selection
* dialogs. The app can control some details, such as filtering to specific
* files, or whether multiple files can be selected by the user.
*
* Note that launching a file dialog is a non-blocking operation; control
* returns to the app immediately, and a callback is called later (possibly in
* another thread) when the user makes a choice.
*/
#ifndef SDL_dialog_h_
#define SDL_dialog_h_
#include <SDL3/SDL_stdinc.h>
#include <SDL3/SDL_error.h>
#include <SDL3/SDL_properties.h>
#include <SDL3/SDL_video.h>
#include <SDL3/SDL_begin_code.h>
@ -48,12 +59,13 @@ extern "C" {
* hyphens, underscores and periods. Alternatively, the whole string can be a
* single asterisk ("*"), which serves as an "All files" filter.
*
* \since This struct is available since SDL 3.0.0.
* \since This struct is available since SDL 3.2.0.
*
* \sa SDL_DialogFileCallback
* \sa SDL_ShowOpenFileDialog
* \sa SDL_ShowSaveFileDialog
* \sa SDL_ShowOpenFolderDialog
* \sa SDL_ShowFileDialogWithProperties
*/
typedef struct SDL_DialogFileFilter
{
@ -75,31 +87,34 @@ typedef struct SDL_DialogFileFilter
* is a null-terminated list of pointers to C strings, each containing a
* path.
*
* The filelist argument does not need to be freed; it will automatically be
* freed when the callback returns.
* The filelist argument should not be freed; it will automatically be freed
* when the callback returns.
*
* The filter argument is the index of the filter that was selected, or -1 if
* no filter was selected or if the platform or method doesn't support
* fetching the selected filter.
*
* In Android, the `filelist` are `content://` URIs. They should be opened
* using SDL_IOFromFile() with appropriate modes. This applies both to open
* and save file dialog.
*
* \param userdata an app-provided pointer, for the callback's use.
* \param filelist the file(s) chosen by the user.
* \param filter index of the selected filter.
*
* \since This datatype is available since SDL 3.0.0.
* \since This datatype is available since SDL 3.2.0.
*
* \sa SDL_DialogFileFilter
* \sa SDL_ShowOpenFileDialog
* \sa SDL_ShowSaveFileDialog
* \sa SDL_ShowOpenFolderDialog
* \sa SDL_ShowFileDialogWithProperties
*/
typedef void (SDLCALL *SDL_DialogFileCallback)(void *userdata, const char * const *filelist, int filter);
/**
* Displays a dialog that lets the user select a file on their filesystem.
*
* This function should only be invoked from the main thread.
*
* This is an asynchronous function; it will return immediately, and the
* result will be passed to the callback.
*
@ -117,47 +132,41 @@ typedef void (SDLCALL *SDL_DialogFileCallback)(void *userdata, const char * cons
* requires an event-handling loop. Apps that do not use SDL to handle events
* should add a call to SDL_PumpEvents in their main loop.
*
* \param callback an SDL_DialogFileCallback to be invoked when the user
* selects a file and accepts, or cancels the dialog, or an
* error occurs. The first argument is a null-terminated list
* of C strings, representing the paths chosen by the user.
* The list will be empty if the user canceled the dialog, and
* it will be NULL if an error occurred. If an error occurred,
* it can be fetched with SDL_GetError(). The second argument
* is the userdata pointer passed to the function. The third
* argument is the index of the filter selected by the user,
* or one past the index of the last filter (therefore the
* index of the terminating NULL filter) if no filter was
* chosen, or -1 if the platform does not support detecting
* the selected filter.
* \param callback a function pointer to be invoked when the user selects a
* file and accepts, or cancels the dialog, or an error
* occurs.
* \param userdata an optional pointer to pass extra data to the callback when
* it will be invoked.
* \param window the window that the dialog should be modal for. May be NULL.
* \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 SDL_DialogFileFilter's. May be NULL. Not all
* platforms support this option, and platforms that do support
* it may allow the user to ignore the filters.
* \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 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.
* \param default_location the default folder or file to start the dialog at,
* may be NULL. Not all platforms support this option.
* \param allow_many if non-zero, the user will be allowed to select multiple
* entries. Not all platforms support this option.
*
* \since This function is available since SDL 3.0.0.
* \threadsafety This function should be called only from the main thread. The
* callback may be invoked from the same thread or from a
* different one, depending on the OS's constraints.
*
* \since This function is available since SDL 3.2.0.
*
* \sa SDL_DialogFileCallback
* \sa SDL_DialogFileFilter
* \sa SDL_ShowSaveFileDialog
* \sa SDL_ShowOpenFolderDialog
* \sa SDL_ShowFileDialogWithProperties
*/
extern SDL_DECLSPEC void SDLCALL SDL_ShowOpenFileDialog(SDL_DialogFileCallback callback, void *userdata, SDL_Window *window, const SDL_DialogFileFilter *filters, int nfilters, const char *default_location, SDL_bool allow_many);
extern SDL_DECLSPEC void SDLCALL SDL_ShowOpenFileDialog(SDL_DialogFileCallback callback, void *userdata, SDL_Window *window, const SDL_DialogFileFilter *filters, int nfilters, const char *default_location, bool allow_many);
/**
* Displays a dialog that lets the user choose a new or existing file on their
* filesystem.
*
* This function should only be invoked from the main thread.
*
* This is an asynchronous function; it will return immediately, and the
* result will be passed to the callback.
*
@ -174,44 +183,38 @@ extern SDL_DECLSPEC void SDLCALL SDL_ShowOpenFileDialog(SDL_DialogFileCallback c
* requires an event-handling loop. Apps that do not use SDL to handle events
* should add a call to SDL_PumpEvents in their main loop.
*
* \param callback an SDL_DialogFileCallback to be invoked when the user
* selects a file and accepts, or cancels the dialog, or an
* error occurs. The first argument is a null-terminated list
* of C strings, representing the paths chosen by the user.
* The list will be empty if the user canceled the dialog, and
* it will be NULL if an error occurred. If an error occurred,
* it can be fetched with SDL_GetError(). The second argument
* is the userdata pointer passed to the function. The third
* argument is the index of the filter selected by the user,
* or one past the index of the last filter (therefore the
* index of the terminating NULL filter) if no filter was
* chosen, or -1 if the platform does not support detecting
* the selected filter.
* \param callback a function pointer to be invoked when the user selects a
* file and accepts, or cancels the dialog, or an error
* occurs.
* \param userdata an optional pointer to pass extra data to the callback when
* it will be invoked.
* \param window the window that the dialog should be modal for. May be NULL.
* \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 SDL_DialogFileFilter's. May be NULL. Not all
* platforms support this option, and platforms that do support
* it may allow the user to ignore the filters.
* \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 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.
* \param default_location the default folder or file to start the dialog at,
* may be NULL. Not all platforms support this option.
*
* \since This function is available since SDL 3.0.0.
* \threadsafety This function should be called only from the main thread. The
* callback may be invoked from the same thread or from a
* different one, depending on the OS's constraints.
*
* \since This function is available since SDL 3.2.0.
*
* \sa SDL_DialogFileCallback
* \sa SDL_DialogFileFilter
* \sa SDL_ShowOpenFileDialog
* \sa SDL_ShowOpenFolderDialog
* \sa SDL_ShowFileDialogWithProperties
*/
extern SDL_DECLSPEC void SDLCALL SDL_ShowSaveFileDialog(SDL_DialogFileCallback callback, void *userdata, SDL_Window *window, const SDL_DialogFileFilter *filters, int nfilters, const char *default_location);
/**
* Displays a dialog that lets the user select a folder on their filesystem.
*
* This function should only be invoked from the main thread.
*
* This is an asynchronous function; it will return immediately, and the
* result will be passed to the callback.
*
@ -229,31 +232,105 @@ extern SDL_DECLSPEC void SDLCALL SDL_ShowSaveFileDialog(SDL_DialogFileCallback c
* requires an event-handling loop. Apps that do not use SDL to handle events
* should add a call to SDL_PumpEvents in their main loop.
*
* \param callback an SDL_DialogFileCallback to be invoked when the user
* selects a file and accepts, or cancels the dialog, or an
* error occurs. The first argument is a null-terminated list
* of C strings, representing the paths chosen by the user.
* The list will be empty if the user canceled the dialog, and
* it will be NULL if an error occurred. If an error occurred,
* it can be fetched with SDL_GetError(). The second argument
* is the userdata pointer passed to the function. The third
* argument is always -1 for SDL_ShowOpenFolderDialog.
* \param callback a function pointer to be invoked when the user selects a
* file and accepts, or cancels the dialog, or an error
* occurs.
* \param userdata an optional pointer to pass extra data to the callback when
* it will be invoked.
* \param window the window that the dialog should be modal for. May be NULL.
* \param window the window that the dialog should be modal for, may be NULL.
* Not all platforms support this option.
* \param default_location the default folder or file to start the dialog at.
* May be NULL. Not all platforms support this option.
* \param default_location the default folder or file to start the dialog at,
* may be NULL. Not all platforms support this option.
* \param allow_many if non-zero, the user will be allowed to select multiple
* entries. Not all platforms support this option.
*
* \since This function is available since SDL 3.0.0.
* \threadsafety This function should be called only from the main thread. The
* callback may be invoked from the same thread or from a
* different one, depending on the OS's constraints.
*
* \since This function is available since SDL 3.2.0.
*
* \sa SDL_DialogFileCallback
* \sa SDL_ShowOpenFileDialog
* \sa SDL_ShowSaveFileDialog
* \sa SDL_ShowFileDialogWithProperties
*/
extern SDL_DECLSPEC void SDLCALL SDL_ShowOpenFolderDialog(SDL_DialogFileCallback callback, void *userdata, SDL_Window *window, const char *default_location, SDL_bool allow_many);
extern SDL_DECLSPEC void SDLCALL SDL_ShowOpenFolderDialog(SDL_DialogFileCallback callback, void *userdata, SDL_Window *window, const char *default_location, bool allow_many);
/**
* Various types of file dialogs.
*
* This is used by SDL_ShowFileDialogWithProperties() to decide what kind of
* dialog to present to the user.
*
* \since This enum is available since SDL 3.2.0.
*
* \sa SDL_ShowFileDialogWithProperties
*/
typedef enum SDL_FileDialogType
{
SDL_FILEDIALOG_OPENFILE,
SDL_FILEDIALOG_SAVEFILE,
SDL_FILEDIALOG_OPENFOLDER
} SDL_FileDialogType;
/**
* Create and launch a file dialog with the specified properties.
*
* These are the supported properties:
*
* - `SDL_PROP_FILE_DIALOG_FILTERS_POINTER`: a pointer to a list of
* SDL_DialogFileFilter structs, which will be used as filters for
* file-based selections. Ignored if the dialog is an "Open Folder" dialog.
* If non-NULL, the array of filters must remain valid at least until the
* callback is invoked.
* - `SDL_PROP_FILE_DIALOG_NFILTERS_NUMBER`: the number of filters in the
* array of filters, if it exists.
* - `SDL_PROP_FILE_DIALOG_WINDOW_POINTER`: the window that the dialog should
* be modal for.
* - `SDL_PROP_FILE_DIALOG_LOCATION_STRING`: the default folder or file to
* start the dialog at.
* - `SDL_PROP_FILE_DIALOG_MANY_BOOLEAN`: true to allow the user to select
* more than one entry.
* - `SDL_PROP_FILE_DIALOG_TITLE_STRING`: the title for the dialog.
* - `SDL_PROP_FILE_DIALOG_ACCEPT_STRING`: the label that the accept button
* should have.
* - `SDL_PROP_FILE_DIALOG_CANCEL_STRING`: the label that the cancel button
* should have.
*
* Note that each platform may or may not support any of the properties.
*
* \param type the type of file dialog.
* \param callback a function pointer to be invoked when the user selects a
* file and accepts, or cancels the dialog, or an error
* occurs.
* \param userdata an optional pointer to pass extra data to the callback when
* it will be invoked.
* \param props the properties to use.
*
* \threadsafety This function should be called only from the main thread. The
* callback may be invoked from the same thread or from a
* different one, depending on the OS's constraints.
*
* \since This function is available since SDL 3.2.0.
*
* \sa SDL_FileDialogType
* \sa SDL_DialogFileCallback
* \sa SDL_DialogFileFilter
* \sa SDL_ShowOpenFileDialog
* \sa SDL_ShowSaveFileDialog
* \sa SDL_ShowOpenFolderDialog
*/
extern SDL_DECLSPEC void SDLCALL SDL_ShowFileDialogWithProperties(SDL_FileDialogType type, SDL_DialogFileCallback callback, void *userdata, SDL_PropertiesID props);
#define SDL_PROP_FILE_DIALOG_FILTERS_POINTER "SDL.filedialog.filters"
#define SDL_PROP_FILE_DIALOG_NFILTERS_NUMBER "SDL.filedialog.nfilters"
#define SDL_PROP_FILE_DIALOG_WINDOW_POINTER "SDL.filedialog.window"
#define SDL_PROP_FILE_DIALOG_LOCATION_STRING "SDL.filedialog.location"
#define SDL_PROP_FILE_DIALOG_MANY_BOOLEAN "SDL.filedialog.many"
#define SDL_PROP_FILE_DIALOG_TITLE_STRING "SDL.filedialog.title"
#define SDL_PROP_FILE_DIALOG_ACCEPT_STRING "SDL.filedialog.accept"
#define SDL_PROP_FILE_DIALOG_CANCEL_STRING "SDL.filedialog.cancel"
/* Ends C function definitions when using C++ */
#ifdef __cplusplus
@ -261,4 +338,4 @@ extern SDL_DECLSPEC void SDLCALL SDL_ShowOpenFolderDialog(SDL_DialogFileCallback
#endif
#include <SDL3/SDL_close_code.h>
#endif /* SDL_joystick_h_ */
#endif /* SDL_dialog_h_ */

View File

@ -1,6 +1,6 @@
/*
Simple DirectMedia Layer
Copyright (C) 1997-2024 Sam Lantinga <slouken@libsdl.org>
Copyright (C) 1997-2025 Sam Lantinga <slouken@libsdl.org>
This software is provided 'as-is', without any express or implied
warranty. In no event will the authors be held liable for any damages

View File

@ -1,6 +1,6 @@
/*
Simple DirectMedia Layer
Copyright (C) 1997-2024 Sam Lantinga <slouken@libsdl.org>
Copyright (C) 1997-2025 Sam Lantinga <slouken@libsdl.org>
This software is provided 'as-is', without any express or implied
warranty. In no event will the authors be held liable for any damages
@ -22,7 +22,20 @@
/**
* # CategoryEndian
*
* Functions for reading and writing endian-specific values.
* Functions converting endian-specific values to different byte orders.
*
* These functions either unconditionally swap byte order (SDL_Swap16,
* SDL_Swap32, SDL_Swap64, SDL_SwapFloat), or they swap to/from the system's
* native byte order (SDL_Swap16LE, SDL_Swap16BE, SDL_Swap32LE, SDL_Swap32BE,
* SDL_Swap32LE, SDL_Swap32BE, SDL_SwapFloatLE, SDL_SwapFloatBE). In the
* latter case, the functionality is provided by macros that become no-ops if
* a swap isn't necessary: on an x86 (littleendian) processor, SDL_Swap32LE
* does nothing, but SDL_Swap32BE reverses the bytes of the data. On a PowerPC
* processor (bigendian), the macros behavior is reversed.
*
* The swap routines are inline functions, and attempt to use compiler
* intrinsics, inline assembly, and other magic to make byteswapping
* efficient.
*/
#ifndef SDL_endian_h_
@ -51,12 +64,71 @@ _m_prefetch(void *__P)
* \name The two types of endianness
*/
/* @{ */
/**
* A value to represent littleendian byteorder.
*
* This is used with the preprocessor macro SDL_BYTEORDER, to determine a
* platform's byte ordering:
*
* ```c
* #if SDL_BYTEORDER == SDL_LIL_ENDIAN
* SDL_Log("This system is littleendian.");
* #endif
* ```
*
* \since This macro is available since SDL 3.2.0.
*
* \sa SDL_BYTEORDER
* \sa SDL_BIG_ENDIAN
*/
#define SDL_LIL_ENDIAN 1234
/**
* A value to represent bigendian byteorder.
*
* This is used with the preprocessor macro SDL_BYTEORDER, to determine a
* platform's byte ordering:
*
* ```c
* #if SDL_BYTEORDER == SDL_BIG_ENDIAN
* SDL_Log("This system is bigendian.");
* #endif
* ```
*
* \since This macro is available since SDL 3.2.0.
*
* \sa SDL_BYTEORDER
* \sa SDL_LIL_ENDIAN
*/
#define SDL_BIG_ENDIAN 4321
/* @} */
#ifndef SDL_BYTEORDER
#ifdef SDL_PLATFORM_LINUX
#ifdef SDL_WIKI_DOCUMENTATION_SECTION
/**
* A macro that reports the target system's byte order.
*
* This is set to either SDL_LIL_ENDIAN or SDL_BIG_ENDIAN (and maybe other
* values in the future, if something else becomes popular). This can be
* tested with the preprocessor, so decisions can be made at compile time.
*
* ```c
* #if SDL_BYTEORDER == SDL_BIG_ENDIAN
* SDL_Log("This system is bigendian.");
* #endif
* ```
*
* \since This macro is available since SDL 3.2.0.
*
* \sa SDL_LIL_ENDIAN
* \sa SDL_BIG_ENDIAN
*/
#define SDL_BYTEORDER SDL_LIL_ENDIAN___or_maybe___SDL_BIG_ENDIAN
#elif defined(SDL_PLATFORM_LINUX)
#include <endian.h>
#define SDL_BYTEORDER __BYTE_ORDER
#elif defined(SDL_PLATFORM_SOLARIS)
@ -97,8 +169,29 @@ _m_prefetch(void *__P)
#endif /* !SDL_BYTEORDER */
#ifndef SDL_FLOATWORDORDER
#ifdef SDL_WIKI_DOCUMENTATION_SECTION
/**
* A macro that reports the target system's floating point word order.
*
* This is set to either SDL_LIL_ENDIAN or SDL_BIG_ENDIAN (and maybe other
* values in the future, if something else becomes popular). This can be
* tested with the preprocessor, so decisions can be made at compile time.
*
* ```c
* #if SDL_FLOATWORDORDER == SDL_BIG_ENDIAN
* SDL_Log("This system's floats are bigendian.");
* #endif
* ```
*
* \since This macro is available since SDL 3.2.0.
*
* \sa SDL_LIL_ENDIAN
* \sa SDL_BIG_ENDIAN
*/
#define SDL_FLOATWORDORDER SDL_LIL_ENDIAN___or_maybe___SDL_BIG_ENDIAN
/* predefs from newer gcc versions: */
#if defined(__ORDER_LITTLE_ENDIAN__) && defined(__ORDER_BIG_ENDIAN__) && defined(__FLOAT_WORD_ORDER__)
#elif defined(__ORDER_LITTLE_ENDIAN__) && defined(__ORDER_BIG_ENDIAN__) && defined(__FLOAT_WORD_ORDER__)
#if (__FLOAT_WORD_ORDER__ == __ORDER_LITTLE_ENDIAN__)
#define SDL_FLOATWORDORDER SDL_LIL_ENDIAN
#elif (__FLOAT_WORD_ORDER__ == __ORDER_BIG_ENDIAN__)
@ -125,10 +218,6 @@ _m_prefetch(void *__P)
extern "C" {
#endif
/**
* \file SDL_endian.h
*/
/* various modern compilers may have builtin swap */
#if defined(__GNUC__) || defined(__clang__)
# define HAS_BUILTIN_BSWAP16 (SDL_HAS_BUILTIN(__builtin_bswap16)) || \
@ -148,6 +237,7 @@ extern "C" {
#endif
/* Byte swap 16-bit integer. */
#ifndef SDL_WIKI_DOCUMENTATION_SECTION
#if HAS_BUILTIN_BSWAP16
#define SDL_Swap16(x) __builtin_bswap16(x)
#elif (defined(_MSC_VER) && (_MSC_VER >= 1400)) && !defined(__ICL)
@ -191,8 +281,10 @@ SDL_FORCE_INLINE Uint16 SDL_Swap16(Uint16 x)
return SDL_static_cast(Uint16, ((x << 8) | (x >> 8)));
}
#endif
#endif
/* Byte swap 32-bit integer. */
#ifndef SDL_WIKI_DOCUMENTATION_SECTION
#if HAS_BUILTIN_BSWAP32
#define SDL_Swap32(x) __builtin_bswap32(x)
#elif (defined(_MSC_VER) && (_MSC_VER >= 1400)) && !defined(__ICL)
@ -239,8 +331,10 @@ SDL_FORCE_INLINE Uint32 SDL_Swap32(Uint32 x)
((x >> 8) & 0x0000FF00) | (x >> 24)));
}
#endif
#endif
/* Byte swap 64-bit integer. */
#ifndef SDL_WIKI_DOCUMENTATION_SECTION
#if HAS_BUILTIN_BSWAP64
#define SDL_Swap64(x) __builtin_bswap64(x)
#elif (defined(_MSC_VER) && (_MSC_VER >= 1400)) && !defined(__ICL)
@ -290,7 +384,7 @@ SDL_FORCE_INLINE Uint64 SDL_Swap64(Uint64 x)
return (x);
}
#endif
#endif
/**
* Byte-swap a floating point number.
@ -309,7 +403,7 @@ SDL_FORCE_INLINE Uint64 SDL_Swap64(Uint64 x)
*
* \threadsafety It is safe to call this function from any thread.
*
* \since This function is available since SDL 3.0.0.
* \since This function is available since SDL 3.2.0.
*/
SDL_FORCE_INLINE float SDL_SwapFloat(float x)
{
@ -348,7 +442,7 @@ SDL_FORCE_INLINE float SDL_SwapFloat(float x)
*
* \threadsafety It is safe to call this function from any thread.
*
* \since This function is available since SDL 3.0.0.
* \since This function is available since SDL 3.2.0.
*/
SDL_FORCE_INLINE Uint16 SDL_Swap16(Uint16 x) { return x_but_byteswapped; }
@ -369,7 +463,7 @@ SDL_FORCE_INLINE Uint16 SDL_Swap16(Uint16 x) { return x_but_byteswapped; }
*
* \threadsafety It is safe to call this function from any thread.
*
* \since This function is available since SDL 3.0.0.
* \since This function is available since SDL 3.2.0.
*/
SDL_FORCE_INLINE Uint32 SDL_Swap32(Uint32 x) { return x_but_byteswapped; }
@ -390,7 +484,7 @@ SDL_FORCE_INLINE Uint32 SDL_Swap32(Uint32 x) { return x_but_byteswapped; }
*
* \threadsafety It is safe to call this function from any thread.
*
* \since This function is available since SDL 3.0.0.
* \since This function is available since SDL 3.2.0.
*/
SDL_FORCE_INLINE Uint32 SDL_Swap64(Uint64 x) { return x_but_byteswapped; }
@ -404,7 +498,9 @@ SDL_FORCE_INLINE Uint32 SDL_Swap64(Uint64 x) { return x_but_byteswapped; }
* \param x the value to swap, in littleendian byte order.
* \returns `x` in native byte order.
*
* \since This macro is available since SDL 3.0.0.
* \threadsafety It is safe to call this macro from any thread.
*
* \since This macro is available since SDL 3.2.0.
*/
#define SDL_Swap16LE(x) SwapOnlyIfNecessary(x)
@ -418,7 +514,9 @@ SDL_FORCE_INLINE Uint32 SDL_Swap64(Uint64 x) { return x_but_byteswapped; }
* \param x the value to swap, in littleendian byte order.
* \returns `x` in native byte order.
*
* \since This macro is available since SDL 3.0.0.
* \threadsafety It is safe to call this macro from any thread.
*
* \since This macro is available since SDL 3.2.0.
*/
#define SDL_Swap32LE(x) SwapOnlyIfNecessary(x)
@ -432,7 +530,9 @@ SDL_FORCE_INLINE Uint32 SDL_Swap64(Uint64 x) { return x_but_byteswapped; }
* \param x the value to swap, in littleendian byte order.
* \returns `x` in native byte order.
*
* \since This macro is available since SDL 3.0.0.
* \threadsafety It is safe to call this macro from any thread.
*
* \since This macro is available since SDL 3.2.0.
*/
#define SDL_Swap64LE(x) SwapOnlyIfNecessary(x)
@ -446,7 +546,9 @@ SDL_FORCE_INLINE Uint32 SDL_Swap64(Uint64 x) { return x_but_byteswapped; }
* \param x the value to swap, in littleendian byte order.
* \returns `x` in native byte order.
*
* \since This macro is available since SDL 3.0.0.
* \threadsafety It is safe to call this macro from any thread.
*
* \since This macro is available since SDL 3.2.0.
*/
#define SDL_SwapFloatLE(x) SwapOnlyIfNecessary(x)
@ -460,7 +562,9 @@ SDL_FORCE_INLINE Uint32 SDL_Swap64(Uint64 x) { return x_but_byteswapped; }
* \param x the value to swap, in bigendian byte order.
* \returns `x` in native byte order.
*
* \since This macro is available since SDL 3.0.0.
* \threadsafety It is safe to call this macro from any thread.
*
* \since This macro is available since SDL 3.2.0.
*/
#define SDL_Swap16BE(x) SwapOnlyIfNecessary(x)
@ -474,7 +578,9 @@ SDL_FORCE_INLINE Uint32 SDL_Swap64(Uint64 x) { return x_but_byteswapped; }
* \param x the value to swap, in bigendian byte order.
* \returns `x` in native byte order.
*
* \since This macro is available since SDL 3.0.0.
* \threadsafety It is safe to call this macro from any thread.
*
* \since This macro is available since SDL 3.2.0.
*/
#define SDL_Swap32BE(x) SwapOnlyIfNecessary(x)
@ -488,7 +594,9 @@ SDL_FORCE_INLINE Uint32 SDL_Swap64(Uint64 x) { return x_but_byteswapped; }
* \param x the value to swap, in bigendian byte order.
* \returns `x` in native byte order.
*
* \since This macro is available since SDL 3.0.0.
* \threadsafety It is safe to call this macro from any thread.
*
* \since This macro is available since SDL 3.2.0.
*/
#define SDL_Swap64BE(x) SwapOnlyIfNecessary(x)
@ -502,7 +610,9 @@ SDL_FORCE_INLINE Uint32 SDL_Swap64(Uint64 x) { return x_but_byteswapped; }
* \param x the value to swap, in bigendian byte order.
* \returns `x` in native byte order.
*
* \since This macro is available since SDL 3.0.0.
* \threadsafety It is safe to call this macro from any thread.
*
* \since This macro is available since SDL 3.2.0.
*/
#define SDL_SwapFloatBE(x) SwapOnlyIfNecessary(x)

View File

@ -1,6 +1,6 @@
/*
Simple DirectMedia Layer
Copyright (C) 1997-2024 Sam Lantinga <slouken@libsdl.org>
Copyright (C) 1997-2025 Sam Lantinga <slouken@libsdl.org>
This software is provided 'as-is', without any express or implied
warranty. In no event will the authors be held liable for any damages
@ -23,6 +23,26 @@
* # CategoryError
*
* Simple error message routines for SDL.
*
* Most apps will interface with these APIs in exactly one function: when
* almost any SDL function call reports failure, you can get a human-readable
* string of the problem from SDL_GetError().
*
* These strings are maintained per-thread, and apps are welcome to set their
* own errors, which is popular when building libraries on top of SDL for
* other apps to consume. These strings are set by calling SDL_SetError().
*
* A common usage pattern is to have a function that returns true for success
* and false for failure, and do this when something fails:
*
* ```c
* if (something_went_wrong) {
* return SDL_SetError("The thing broke in this specific way: %d", errcode);
* }
* ```
*
* It's also common to just return `false` in this case if the failing thing
* is known to call SDL_SetError(), so errors simply propagate through.
*/
#ifndef SDL_error_h_
@ -44,8 +64,8 @@ extern "C" {
*
* Calling this function will replace any previous error message that was set.
*
* This function always returns -1, since SDL frequently uses -1 to signify an
* failing result, leading to this idiom:
* This function always returns false, since SDL frequently uses false to
* signify a failing result, leading to this idiom:
*
* ```c
* if (error_code) {
@ -56,25 +76,49 @@ extern "C" {
* \param fmt a printf()-style message format string.
* \param ... additional parameters matching % tokens in the `fmt` string, if
* any.
* \returns SDL_FALSE.
* \returns false.
*
* \since This function is available since SDL 3.0.0.
* \threadsafety It is safe to call this function from any thread.
*
* \since This function is available since SDL 3.2.0.
*
* \sa SDL_ClearError
* \sa SDL_GetError
* \sa SDL_SetErrorV
*/
extern SDL_DECLSPEC SDL_bool SDLCALL SDL_SetError(SDL_PRINTF_FORMAT_STRING const char *fmt, ...) SDL_PRINTF_VARARG_FUNC(1);
extern SDL_DECLSPEC bool SDLCALL SDL_SetError(SDL_PRINTF_FORMAT_STRING const char *fmt, ...) SDL_PRINTF_VARARG_FUNC(1);
/**
* Set the SDL error message for the current thread.
*
* Calling this function will replace any previous error message that was set.
*
* \param fmt a printf()-style message format string.
* \param ap a variable argument list.
* \returns false.
*
* \threadsafety It is safe to call this function from any thread.
*
* \since This function is available since SDL 3.2.0.
*
* \sa SDL_ClearError
* \sa SDL_GetError
* \sa SDL_SetError
*/
extern SDL_DECLSPEC bool SDLCALL SDL_SetErrorV(SDL_PRINTF_FORMAT_STRING const char *fmt, va_list ap) SDL_PRINTF_VARARG_FUNCV(1);
/**
* Set an error indicating that memory allocation failed.
*
* This function does not do any memory allocation.
*
* \returns SDL_FALSE.
* \returns false.
*
* \since This function is available since SDL 3.0.0.
* \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_bool SDLCALL SDL_OutOfMemory(void);
extern SDL_DECLSPEC bool SDLCALL SDL_OutOfMemory(void);
/**
* Retrieve a message about the last error that occurred on the current
@ -104,7 +148,9 @@ extern SDL_DECLSPEC SDL_bool SDLCALL SDL_OutOfMemory(void);
* or an empty string if there hasn't been an error message set since
* the last call to SDL_ClearError().
*
* \since This function is available since SDL 3.0.0.
* \threadsafety It is safe to call this function from any thread.
*
* \since This function is available since SDL 3.2.0.
*
* \sa SDL_ClearError
* \sa SDL_SetError
@ -114,14 +160,16 @@ extern SDL_DECLSPEC const char * SDLCALL SDL_GetError(void);
/**
* Clear any previous error message for this thread.
*
* \returns SDL_TRUE.
* \returns true.
*
* \since This function is available since SDL 3.0.0.
* \threadsafety It is safe to call this function from any thread.
*
* \since This function is available since SDL 3.2.0.
*
* \sa SDL_GetError
* \sa SDL_SetError
*/
extern SDL_DECLSPEC SDL_bool SDLCALL SDL_ClearError(void);
extern SDL_DECLSPEC bool SDLCALL SDL_ClearError(void);
/**
* \name Internal error functions
@ -130,8 +178,43 @@ extern SDL_DECLSPEC SDL_bool SDLCALL SDL_ClearError(void);
* Private error reporting function - used internally.
*/
/* @{ */
/**
* A macro to standardize error reporting on unsupported operations.
*
* This simply calls SDL_SetError() with a standardized error string, for
* convenience, consistency, and clarity.
*
* \threadsafety It is safe to call this macro from any thread.
*
* \since This macro is available since SDL 3.2.0.
*/
#define SDL_Unsupported() SDL_SetError("That operation is not supported")
/**
* A macro to standardize error reporting on unsupported operations.
*
* This simply calls SDL_SetError() with a standardized error string, for
* convenience, consistency, and clarity.
*
* A common usage pattern inside SDL is this:
*
* ```c
* bool MyFunction(const char *str) {
* if (!str) {
* return SDL_InvalidParamError("str"); // returns false.
* }
* DoSomething(str);
* return true;
* }
* ```
*
* \threadsafety It is safe to call this macro from any thread.
*
* \since This macro is available since SDL 3.2.0.
*/
#define SDL_InvalidParamError(param) SDL_SetError("Parameter '%s' is invalid", (param))
/* @} *//* Internal error functions */
/* Ends C function definitions when using C++ */

Some files were not shown because too many files have changed in this diff Show More