2022-12-22 01:05:10 -05:00
/*
Simple DirectMedia Layer
2024-01-01 13:15:26 -08:00
Copyright ( C ) 1997 - 2024 Sam Lantinga < slouken @ libsdl . org >
2022-12-22 01:05:10 -05:00
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 .
*/
/**
2024-05-16 10:44:37 -04:00
* # CategoryInit
2022-12-22 01:05:10 -05:00
*
2024-10-04 16:19:19 -04:00
* 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
2024-10-04 20:23:29 +00:00
* 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 .
2024-10-04 16:19:19 -04:00
*
* Most apps , when terminating , should call SDL_Quit ( ) . This will clean up
* ( nearly ) everything that SDL might have allocated , and crucially , it ' ll
2024-10-04 20:23:29 +00:00
* make sure that the display ' s resolution is back to what the user expects if
* you had previously changed it for your game .
2024-10-04 16:19:19 -04:00
*
2024-10-04 20:27:58 +00:00
* SDL3 apps are strongly encouraged to call SDL_SetAppMetadata ( ) at startup
* to fill in details about the program . This is completely optional , but it
2024-10-04 16:19:19 -04:00
* 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 ( ) .
2022-12-22 01:05:10 -05:00
*/
# ifndef SDL_init_h_
# define SDL_init_h_
# include <SDL3/SDL_stdinc.h>
2024-04-04 18:38:21 +02:00
# include <SDL3/SDL_error.h>
2024-08-20 07:30:45 -07:00
# include <SDL3/SDL_events.h>
2022-12-22 01:05:10 -05:00
2022-12-22 11:38:59 -05:00
# include <SDL3/SDL_begin_code.h>
2022-12-22 01:05:10 -05:00
/* Set up for C function definitions, even when using C++ */
# ifdef __cplusplus
extern " C " {
# endif
/* As of version 0.5, SDL is loaded dynamically into the application */
/**
2024-04-09 00:49:23 -04:00
* Initialization flags for SDL_Init and / or SDL_InitSubSystem
2022-12-22 01:05:10 -05:00
*
2024-04-09 00:49:23 -04:00
* These are the flags which may be passed to SDL_Init ( ) . You should specify
* the subsystems which you will be using in your application .
2023-01-23 23:04:43 -07:00
*
2024-10-23 12:19:38 -04:00
* \ since This datatype is available since SDL 3.1 .3 .
2024-04-11 13:34:29 -04:00
*
2023-01-23 23:04:43 -07:00
* \ sa SDL_Init
* \ sa SDL_Quit
* \ sa SDL_InitSubSystem
* \ sa SDL_QuitSubSystem
* \ sa SDL_WasInit
2022-12-22 01:05:10 -05:00
*/
2024-05-07 11:12:53 -07:00
typedef Uint32 SDL_InitFlags ;
# define SDL_INIT_AUDIO 0x00000010u /**< `SDL_INIT_AUDIO` implies `SDL_INIT_EVENTS` */
2024-12-05 09:45:32 -08:00
# define SDL_INIT_VIDEO 0x00000020u /**< `SDL_INIT_VIDEO` implies `SDL_INIT_EVENTS`, should be initialized on the main thread */
2024-05-07 11:12:53 -07:00
# 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` */
# define SDL_INIT_EVENTS 0x00004000u
# define SDL_INIT_SENSOR 0x00008000u /**< `SDL_INIT_SENSOR` implies `SDL_INIT_EVENTS` */
# define SDL_INIT_CAMERA 0x00010000u /**< `SDL_INIT_CAMERA` implies `SDL_INIT_EVENTS` */
2022-12-22 01:05:10 -05:00
2024-08-16 09:54:35 -07:00
/**
* Return values for optional main callbacks .
*
2024-08-17 04:39:06 +00:00
* Returning SDL_APP_SUCCESS or SDL_APP_FAILURE from SDL_AppInit ,
* SDL_AppEvent , or SDL_AppIterate will terminate the program and report
* success / failure to the operating system . What that means is
* platform - dependent . On Unix , for example , on success , the process error
* code will be zero , and on failure it will be 1. This interface doesn ' t
* allow you to return specific exit codes , just whether there was an error
* generally or not .
2024-08-17 00:37:56 -04:00
*
2024-08-17 04:39:06 +00:00
* Returning SDL_APP_CONTINUE from these functions will let the app continue
* to run .
2024-08-17 00:37:56 -04:00
*
2024-08-17 00:41:31 -04:00
* See
* [ Main callbacks in SDL3 ] ( https : //wiki.libsdl.org/SDL3/README/main-functions#main-callbacks-in-sdl3)
* for complete details .
*
2024-10-23 12:19:38 -04:00
* \ since This enum is available since SDL 3.1 .3 .
2024-08-16 09:54:35 -07:00
*/
typedef enum SDL_AppResult
{
2024-08-27 21:44:52 +02:00
SDL_APP_CONTINUE , /**< Value that requests that the app continue from the main callbacks. */
SDL_APP_SUCCESS , /**< Value that requests termination with success from the main callbacks. */
SDL_APP_FAILURE /**< Value that requests termination with error from the main callbacks. */
2024-08-16 09:54:35 -07:00
} SDL_AppResult ;
typedef SDL_AppResult ( SDLCALL * SDL_AppInit_func ) ( void * * appstate , int argc , char * argv [ ] ) ;
typedef SDL_AppResult ( SDLCALL * SDL_AppIterate_func ) ( void * appstate ) ;
2024-09-03 07:45:30 -07:00
typedef SDL_AppResult ( SDLCALL * SDL_AppEvent_func ) ( void * appstate , SDL_Event * event ) ;
2024-09-29 22:17:11 -04:00
typedef void ( SDLCALL * SDL_AppQuit_func ) ( void * appstate , SDL_AppResult result ) ;
2024-08-16 09:54:35 -07:00
2022-12-22 01:05:10 -05:00
/**
* Initialize the SDL library .
*
* SDL_Init ( ) simply forwards to calling SDL_InitSubSystem ( ) . Therefore , the
* two may be used interchangeably . Though for readability of your code
* SDL_InitSubSystem ( ) might be preferred .
*
2024-03-14 19:32:50 -04:00
* The file I / O ( for example : SDL_IOFromFile ) and threading ( SDL_CreateThread )
2022-12-22 01:05:10 -05:00
* subsystems are initialized by default . Message boxes
* ( SDL_ShowSimpleMessageBox ) also attempt to work without initializing the
* video subsystem , in hopes of being useful in showing an error dialog when
* SDL_Init fails . You must specifically initialize other subsystems if you
* use them in your application .
*
* Logging ( such as SDL_Log ) works without initialization , too .
*
* ` flags ` may be any of the following OR ' d together :
*
2024-05-10 14:30:13 +00:00
* - ` SDL_INIT_AUDIO ` : audio subsystem ; automatically initializes the events
* subsystem
2022-12-22 01:05:10 -05:00
* - ` SDL_INIT_VIDEO ` : video subsystem ; automatically initializes the events
2024-12-05 09:45:32 -08:00
* subsystem , should be initialized on the main thread .
2022-12-22 01:05:10 -05:00
* - ` SDL_INIT_JOYSTICK ` : joystick subsystem ; automatically initializes the
* events subsystem
* - ` SDL_INIT_HAPTIC ` : haptic ( force feedback ) subsystem
2023-01-25 12:58:29 -05:00
* - ` SDL_INIT_GAMEPAD ` : gamepad subsystem ; automatically initializes the
* joystick subsystem
2022-12-22 01:05:10 -05:00
* - ` SDL_INIT_EVENTS ` : events subsystem
2024-05-10 14:30:13 +00:00
* - ` SDL_INIT_SENSOR ` : sensor subsystem ; automatically initializes the events
* subsystem
* - ` SDL_INIT_CAMERA ` : camera subsystem ; automatically initializes the events
* subsystem
2022-12-22 01:05:10 -05:00
*
* Subsystem initialization is ref - counted , you must call SDL_QuitSubSystem ( )
* for each SDL_InitSubSystem ( ) to correctly shutdown a subsystem manually ( or
* call SDL_Quit ( ) to force shutdown ) . If a subsystem is already loaded then
* this call will increase the ref - count and return .
*
2024-07-28 07:22:46 -07:00
* Consider reporting some basic metadata about your application before
* calling SDL_Init , using either SDL_SetAppMetadata ( ) or
* SDL_SetAppMetadataProperty ( ) .
*
2024-06-14 02:09:55 -04:00
* \ param flags subsystem initialization flags .
2024-09-18 15:33:11 +00:00
* \ returns true on success or false on failure ; call SDL_GetError ( ) for more
* information .
2022-12-22 01:05:10 -05:00
*
2024-10-23 12:19:38 -04:00
* \ since This function is available since SDL 3.1 .3 .
2022-12-22 01:05:10 -05:00
*
2024-07-28 07:22:46 -07:00
* \ sa SDL_SetAppMetadata
* \ sa SDL_SetAppMetadataProperty
2022-12-22 01:05:10 -05:00
* \ sa SDL_InitSubSystem
* \ sa SDL_Quit
* \ sa SDL_SetMainReady
* \ sa SDL_WasInit
*/
2024-09-18 07:52:28 -07:00
extern SDL_DECLSPEC bool SDLCALL SDL_Init ( SDL_InitFlags flags ) ;
2022-12-22 01:05:10 -05:00
/**
* Compatibility function to initialize the SDL library .
*
* This function and SDL_Init ( ) are interchangeable .
*
* \ param flags any of the flags used by SDL_Init ( ) ; see SDL_Init for details .
2024-09-18 15:33:11 +00:00
* \ returns true on success or false on failure ; call SDL_GetError ( ) for more
* information .
2022-12-22 01:05:10 -05:00
*
2024-10-23 12:19:38 -04:00
* \ since This function is available since SDL 3.1 .3 .
2022-12-22 01:05:10 -05:00
*
* \ sa SDL_Init
* \ sa SDL_Quit
* \ sa SDL_QuitSubSystem
*/
2024-09-18 07:52:28 -07:00
extern SDL_DECLSPEC bool SDLCALL SDL_InitSubSystem ( SDL_InitFlags flags ) ;
2022-12-22 01:05:10 -05:00
/**
* Shut down specific SDL subsystems .
*
* You still need to call SDL_Quit ( ) even if you close all open subsystems
* with SDL_QuitSubSystem ( ) .
*
* \ param flags any of the flags used by SDL_Init ( ) ; see SDL_Init for details .
*
2024-10-23 12:19:38 -04:00
* \ since This function is available since SDL 3.1 .3 .
2022-12-22 01:05:10 -05:00
*
* \ sa SDL_InitSubSystem
* \ sa SDL_Quit
*/
2024-05-17 16:52:36 -07:00
extern SDL_DECLSPEC void SDLCALL SDL_QuitSubSystem ( SDL_InitFlags flags ) ;
2022-12-22 01:05:10 -05:00
/**
* Get a mask of the specified subsystems which are currently initialized .
*
* \ param flags any of the flags used by SDL_Init ( ) ; see SDL_Init for details .
* \ returns a mask of all initialized subsystems if ` flags ` is 0 , otherwise it
* returns the initialization status of the specified subsystems .
*
2024-10-23 12:19:38 -04:00
* \ since This function is available since SDL 3.1 .3 .
2022-12-22 01:05:10 -05:00
*
* \ sa SDL_Init
* \ sa SDL_InitSubSystem
*/
2024-05-17 16:52:36 -07:00
extern SDL_DECLSPEC SDL_InitFlags SDLCALL SDL_WasInit ( SDL_InitFlags flags ) ;
2022-12-22 01:05:10 -05:00
/**
* Clean up all initialized subsystems .
*
* You should call this function even if you have already shutdown each
* initialized subsystem with SDL_QuitSubSystem ( ) . It is safe to call this
* function even in the case of errors in initialization .
*
* You can use this function with atexit ( ) to ensure that it is run when your
* application is shutdown , but it is not wise to do this from a library or
* other dynamically loaded code .
*
2024-10-23 12:19:38 -04:00
* \ since This function is available since SDL 3.1 .3 .
2022-12-22 01:05:10 -05:00
*
* \ sa SDL_Init
* \ sa SDL_QuitSubSystem
*/
2024-05-17 16:52:36 -07:00
extern SDL_DECLSPEC void SDLCALL SDL_Quit ( void ) ;
2022-12-22 01:05:10 -05:00
2024-12-05 12:35:23 -08:00
/**
* Return whether this is the main thread .
*
2024-12-06 00:49:29 +00:00
* 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 .
2024-12-05 12:35:23 -08:00
*
* \ returns true if this thread is the main thread , or false otherwise .
*
* \ threadsafety It is safe to call this function from any thread .
*
2024-12-06 00:49:29 +00:00
* \ since This function is available since SDL 3.2 .0 .
2024-12-05 12:35:23 -08:00
*
* \ 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.1 .8 .
*
* \ sa SDL_RunOnMainThread
*/
typedef void ( SDLCALL * SDL_MainThreadCallback ) ( void * userdata ) ;
/**
* Call a function on the main thread during event processing .
*
2024-12-06 00:49:29 +00:00
* 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 .
2024-12-05 12:35:23 -08:00
*
2024-12-06 00:49:29 +00:00
* 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 .
2024-12-05 12:35:23 -08:00
*
* \ param callback the callback to call on the main thread .
* \ param userdata a pointer that is passed to ` callback ` .
2024-12-06 00:49:29 +00:00
* \ param wait_complete true to wait for the callback to complete , false to
* return immediately .
2024-12-05 12:35:23 -08:00
* \ 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 .
*
2024-12-06 00:49:29 +00:00
* \ since This function is available since SDL 3.2 .0 .
2024-12-05 12:35:23 -08:00
*
* \ sa SDL_IsMainThread
*/
extern SDL_DECLSPEC bool SDLCALL SDL_RunOnMainThread ( SDL_MainThreadCallback callback , void * userdata , bool wait_complete ) ;
2024-07-28 07:22:46 -07:00
/**
* Specify basic metadata about your app .
*
* You can optionally provide metadata about your app to SDL . This is not
* required , but strongly encouraged .
*
* There are several locations where SDL can make use of metadata ( an " About "
* box in the macOS menu bar , the name of the app can be shown on some audio
2024-07-28 14:23:13 +00:00
* mixers , etc ) . Any piece of metadata can be left as NULL , if a specific
* detail doesn ' t make sense for the app .
2024-07-28 07:22:46 -07:00
*
* This function should be called as early as possible , before SDL_Init .
* 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 .
*
* Passing a NULL removes any previous metadata .
*
* This is a simplified interface for the most important information . You can
2024-07-28 14:23:13 +00:00
* supply significantly more detailed metadata with
* SDL_SetAppMetadataProperty ( ) .
2024-07-28 07:22:46 -07:00
*
2024-07-28 14:23:13 +00:00
* \ param appname The name of the application ( " My Game 2: Bad Guy's
* Revenge ! " ).
* \ param appversion The version of the application ( " 1.0.0beta5 " or a git
* hash , or whatever makes sense ) .
* \ param appidentifier A unique string in reverse - domain format that
* identifies this app ( " com.example.mygame2 " ) .
2024-09-18 15:33:11 +00:00
* \ returns true on success or false on failure ; call SDL_GetError ( ) for more
* information .
2024-07-28 07:22:46 -07:00
*
* \ threadsafety It is safe to call this function from any thread .
*
2024-10-23 12:19:38 -04:00
* \ since This function is available since SDL 3.1 .3 .
2024-07-28 14:23:13 +00:00
*
2024-07-28 07:22:46 -07:00
* \ sa SDL_SetAppMetadataProperty
*/
2024-09-18 07:52:28 -07:00
extern SDL_DECLSPEC bool SDLCALL SDL_SetAppMetadata ( const char * appname , const char * appversion , const char * appidentifier ) ;
2024-07-28 07:22:46 -07:00
/**
* Specify metadata about your app through a set of properties .
*
* You can optionally provide metadata about your app to SDL . This is not
* required , but strongly encouraged .
*
* There are several locations where SDL can make use of metadata ( an " About "
* box in the macOS menu bar , the name of the app can be shown on some audio
* mixers , etc ) . Any piece of metadata can be left out , if a specific detail
* doesn ' t make sense for the app .
*
* This function should be called as early as possible , before SDL_Init .
* 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 .
*
2024-11-21 16:16:49 +03:00
* Once set , this metadata can be read using SDL_GetAppMetadataProperty ( ) .
2024-07-28 07:22:46 -07:00
*
* These are the supported properties :
*
2024-07-28 14:23:13 +00:00
* - ` SDL_PROP_APP_METADATA_NAME_STRING ` : The human - readable name of the
2024-07-29 11:26:36 +00:00
* application , like " My Game 2: Bad Guy's Revenge! " . This will show up
* anywhere the OS shows the name of the application separately from window
* titles , such as volume control applets , etc . This defaults to " SDL
* Application " .
2024-08-29 23:54:57 +00:00
* - ` SDL_PROP_APP_METADATA_VERSION_STRING ` : The version of the app that is
2024-07-28 14:23:13 +00:00
* running ; there are no rules on format , so " 1.0.3beta2 " and " April 22nd,
* 2024 " and a git hash are all valid options. This has no default.
2024-07-28 07:22:46 -07:00
* - ` SDL_PROP_APP_METADATA_IDENTIFIER_STRING ` : A unique string that
* identifies this app . This must be in reverse - domain format , like
* " com.example.mygame2 " . This string is used by desktop compositors to
2024-07-28 14:23:13 +00:00
* identify and group windows together , as well as match applications with
2024-07-29 11:26:36 +00:00
* associated desktop settings and icons . If you plan to package your
* application in a container such as Flatpak , the app ID should match the
* name of your Flatpak container as well . This has no default .
2024-08-29 23:54:57 +00:00
* - ` SDL_PROP_APP_METADATA_CREATOR_STRING ` : The human - readable name of the
2024-07-28 14:23:13 +00:00
* creator / developer / maker of this app , like " MojoWorkshop, LLC "
2024-08-29 23:54:57 +00:00
* - ` SDL_PROP_APP_METADATA_COPYRIGHT_STRING ` : The human - readable copyright
2024-07-28 14:23:13 +00:00
* notice , like " Copyright (c) 2024 MojoWorkshop, LLC " or whatnot . Keep this
* to one line , don ' t paste a copy of a whole software license in here . This
* has no default .
2024-08-29 23:54:57 +00:00
* - ` SDL_PROP_APP_METADATA_URL_STRING ` : A URL to the app on the web . Maybe a
2024-07-28 14:23:13 +00:00
* product page , or a storefront , or even a GitHub repository , for user ' s
* further information This has no default .
2024-08-29 23:54:57 +00:00
* - ` SDL_PROP_APP_METADATA_TYPE_STRING ` : The type of application this is .
2024-07-28 14:23:13 +00:00
* Currently this string can be " game " for a video game , " mediaplayer " for a
* media player , or generically " application " if nothing else applies .
* Future versions of SDL might add new types . This defaults to
* " application " .
2024-07-28 07:22:46 -07:00
*
* \ param name the name of the metadata property to set .
* \ param value the value of the property , or NULL to remove that property .
2024-09-18 15:33:11 +00:00
* \ returns true on success or false on failure ; call SDL_GetError ( ) for more
* information .
2024-07-28 07:22:46 -07:00
*
* \ threadsafety It is safe to call this function from any thread .
*
2024-10-23 12:19:38 -04:00
* \ since This function is available since SDL 3.1 .3 .
2024-07-28 14:23:13 +00:00
*
2024-07-28 07:22:46 -07:00
* \ sa SDL_GetAppMetadataProperty
* \ sa SDL_SetAppMetadata
*/
2024-09-18 07:52:28 -07:00
extern SDL_DECLSPEC bool SDLCALL SDL_SetAppMetadataProperty ( const char * name , const char * value ) ;
2024-07-28 07:22:46 -07:00
# define SDL_PROP_APP_METADATA_NAME_STRING "SDL.app.metadata.name"
# define SDL_PROP_APP_METADATA_VERSION_STRING "SDL.app.metadata.version"
# define SDL_PROP_APP_METADATA_IDENTIFIER_STRING "SDL.app.metadata.identifier"
# define SDL_PROP_APP_METADATA_CREATOR_STRING "SDL.app.metadata.creator"
# define SDL_PROP_APP_METADATA_COPYRIGHT_STRING "SDL.app.metadata.copyright"
# define SDL_PROP_APP_METADATA_URL_STRING "SDL.app.metadata.url"
# define SDL_PROP_APP_METADATA_TYPE_STRING "SDL.app.metadata.type"
/**
* Get metadata about your app .
*
2024-07-28 14:23:13 +00:00
* This returns metadata previously set using SDL_SetAppMetadata ( ) or
* SDL_SetAppMetadataProperty ( ) . See SDL_SetAppMetadataProperty ( ) for the list
* of available properties and their meanings .
2024-07-28 07:22:46 -07:00
*
* \ param name the name of the metadata property to get .
2024-07-28 14:23:13 +00:00
* \ returns the current value of the metadata property , or the default if it
* is not set , NULL for properties with no default .
2024-07-28 07:22:46 -07:00
*
* \ threadsafety It is safe to call this function from any thread , although
* the string returned is not protected and could potentially be
2024-07-28 14:23:13 +00:00
* freed if you call SDL_SetAppMetadataProperty ( ) to set that
* property from another thread .
*
2024-10-23 12:19:38 -04:00
* \ since This function is available since SDL 3.1 .3 .
2024-07-28 07:22:46 -07:00
*
* \ sa SDL_SetAppMetadata
* \ sa SDL_SetAppMetadataProperty
*/
extern SDL_DECLSPEC const char * SDLCALL SDL_GetAppMetadataProperty ( const char * name ) ;
2022-12-22 01:05:10 -05:00
/* Ends C function definitions when using C++ */
# ifdef __cplusplus
}
# endif
2022-12-22 11:38:59 -05:00
# include <SDL3/SDL_close_code.h>
2022-12-22 01:05:10 -05:00
# endif /* SDL_init_h_ */