SDL_init.h 15 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361
  1. /*
  2. Simple DirectMedia Layer
  3. Copyright (C) 1997-2024 Sam Lantinga <[email protected]>
  4. This software is provided 'as-is', without any express or implied
  5. warranty. In no event will the authors be held liable for any damages
  6. arising from the use of this software.
  7. Permission is granted to anyone to use this software for any purpose,
  8. including commercial applications, and to alter it and redistribute it
  9. freely, subject to the following restrictions:
  10. 1. The origin of this software must not be misrepresented; you must not
  11. claim that you wrote the original software. If you use this software
  12. in a product, an acknowledgment in the product documentation would be
  13. appreciated but is not required.
  14. 2. Altered source versions must be plainly marked as such, and must not be
  15. misrepresented as being the original software.
  16. 3. This notice may not be removed or altered from any source distribution.
  17. */
  18. /**
  19. * # CategoryInit
  20. *
  21. * SDL subsystem init and quit functions.
  22. */
  23. #ifndef SDL_init_h_
  24. #define SDL_init_h_
  25. #include <SDL3/SDL_stdinc.h>
  26. #include <SDL3/SDL_error.h>
  27. #include <SDL3/SDL_begin_code.h>
  28. /* Set up for C function definitions, even when using C++ */
  29. #ifdef __cplusplus
  30. extern "C" {
  31. #endif
  32. /* As of version 0.5, SDL is loaded dynamically into the application */
  33. /**
  34. * Initialization flags for SDL_Init and/or SDL_InitSubSystem
  35. *
  36. * These are the flags which may be passed to SDL_Init(). You should specify
  37. * the subsystems which you will be using in your application.
  38. *
  39. * \since This datatype is available since SDL 3.0.0.
  40. *
  41. * \sa SDL_Init
  42. * \sa SDL_Quit
  43. * \sa SDL_InitSubSystem
  44. * \sa SDL_QuitSubSystem
  45. * \sa SDL_WasInit
  46. */
  47. typedef Uint32 SDL_InitFlags;
  48. #define SDL_INIT_TIMER 0x00000001u
  49. #define SDL_INIT_AUDIO 0x00000010u /**< `SDL_INIT_AUDIO` implies `SDL_INIT_EVENTS` */
  50. #define SDL_INIT_VIDEO 0x00000020u /**< `SDL_INIT_VIDEO` implies `SDL_INIT_EVENTS` */
  51. #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 */
  52. #define SDL_INIT_HAPTIC 0x00001000u
  53. #define SDL_INIT_GAMEPAD 0x00002000u /**< `SDL_INIT_GAMEPAD` implies `SDL_INIT_JOYSTICK` */
  54. #define SDL_INIT_EVENTS 0x00004000u
  55. #define SDL_INIT_SENSOR 0x00008000u /**< `SDL_INIT_SENSOR` implies `SDL_INIT_EVENTS` */
  56. #define SDL_INIT_CAMERA 0x00010000u /**< `SDL_INIT_CAMERA` implies `SDL_INIT_EVENTS` */
  57. /**
  58. * Return values for optional main callbacks.
  59. *
  60. * Returning SDL_APP_SUCCESS or SDL_APP_FAILURE from SDL_AppInit,
  61. * SDL_AppEvent, or SDL_AppIterate will terminate the program and report
  62. * success/failure to the operating system. What that means is
  63. * platform-dependent. On Unix, for example, on success, the process error
  64. * code will be zero, and on failure it will be 1. This interface doesn't
  65. * allow you to return specific exit codes, just whether there was an error
  66. * generally or not.
  67. *
  68. * Returning SDL_APP_CONTINUE from these functions will let the app continue
  69. * to run.
  70. *
  71. * See
  72. * [Main callbacks in SDL3](https://wiki.libsdl.org/SDL3/README/main-functions#main-callbacks-in-sdl3)
  73. * for complete details.
  74. *
  75. * \since This enum is available since SDL 3.0.0.
  76. */
  77. typedef enum SDL_AppResult
  78. {
  79. SDL_APP_CONTINUE, /** Value that requests that the app continue from the main callbacks. */
  80. SDL_APP_SUCCESS, /** Value that requests termination with success from the main callbacks. */
  81. SDL_APP_FAILURE /** Value that requests termination with error from the main callbacks. */
  82. } SDL_AppResult;
  83. typedef SDL_AppResult (SDLCALL *SDL_AppInit_func)(void **appstate, int argc, char *argv[]);
  84. typedef SDL_AppResult (SDLCALL *SDL_AppIterate_func)(void *appstate);
  85. typedef SDL_AppResult (SDLCALL *SDL_AppEvent_func)(void *appstate, const SDL_Event *event);
  86. typedef void (SDLCALL *SDL_AppQuit_func)(void *appstate);
  87. /**
  88. * Initialize the SDL library.
  89. *
  90. * SDL_Init() simply forwards to calling SDL_InitSubSystem(). Therefore, the
  91. * two may be used interchangeably. Though for readability of your code
  92. * SDL_InitSubSystem() might be preferred.
  93. *
  94. * The file I/O (for example: SDL_IOFromFile) and threading (SDL_CreateThread)
  95. * subsystems are initialized by default. Message boxes
  96. * (SDL_ShowSimpleMessageBox) also attempt to work without initializing the
  97. * video subsystem, in hopes of being useful in showing an error dialog when
  98. * SDL_Init fails. You must specifically initialize other subsystems if you
  99. * use them in your application.
  100. *
  101. * Logging (such as SDL_Log) works without initialization, too.
  102. *
  103. * `flags` may be any of the following OR'd together:
  104. *
  105. * - `SDL_INIT_TIMER`: timer subsystem
  106. * - `SDL_INIT_AUDIO`: audio subsystem; automatically initializes the events
  107. * subsystem
  108. * - `SDL_INIT_VIDEO`: video subsystem; automatically initializes the events
  109. * subsystem
  110. * - `SDL_INIT_JOYSTICK`: joystick subsystem; automatically initializes the
  111. * events subsystem
  112. * - `SDL_INIT_HAPTIC`: haptic (force feedback) subsystem
  113. * - `SDL_INIT_GAMEPAD`: gamepad subsystem; automatically initializes the
  114. * joystick subsystem
  115. * - `SDL_INIT_EVENTS`: events subsystem
  116. * - `SDL_INIT_SENSOR`: sensor subsystem; automatically initializes the events
  117. * subsystem
  118. * - `SDL_INIT_CAMERA`: camera subsystem; automatically initializes the events
  119. * subsystem
  120. *
  121. * Subsystem initialization is ref-counted, you must call SDL_QuitSubSystem()
  122. * for each SDL_InitSubSystem() to correctly shutdown a subsystem manually (or
  123. * call SDL_Quit() to force shutdown). If a subsystem is already loaded then
  124. * this call will increase the ref-count and return.
  125. *
  126. * Consider reporting some basic metadata about your application before
  127. * calling SDL_Init, using either SDL_SetAppMetadata() or
  128. * SDL_SetAppMetadataProperty().
  129. *
  130. * \param flags subsystem initialization flags.
  131. * \returns 0 on success or a negative error code on failure; call
  132. * SDL_GetError() for more information.
  133. *
  134. * \since This function is available since SDL 3.0.0.
  135. *
  136. * \sa SDL_SetAppMetadata
  137. * \sa SDL_SetAppMetadataProperty
  138. * \sa SDL_InitSubSystem
  139. * \sa SDL_Quit
  140. * \sa SDL_SetMainReady
  141. * \sa SDL_WasInit
  142. */
  143. extern SDL_DECLSPEC int SDLCALL SDL_Init(SDL_InitFlags flags);
  144. /**
  145. * Compatibility function to initialize the SDL library.
  146. *
  147. * This function and SDL_Init() are interchangeable.
  148. *
  149. * \param flags any of the flags used by SDL_Init(); see SDL_Init for details.
  150. * \returns 0 on success or a negative error code on failure; call
  151. * SDL_GetError() for more information.
  152. *
  153. * \since This function is available since SDL 3.0.0.
  154. *
  155. * \sa SDL_Init
  156. * \sa SDL_Quit
  157. * \sa SDL_QuitSubSystem
  158. */
  159. extern SDL_DECLSPEC int SDLCALL SDL_InitSubSystem(SDL_InitFlags flags);
  160. /**
  161. * Shut down specific SDL subsystems.
  162. *
  163. * You still need to call SDL_Quit() even if you close all open subsystems
  164. * with SDL_QuitSubSystem().
  165. *
  166. * \param flags any of the flags used by SDL_Init(); see SDL_Init for details.
  167. *
  168. * \since This function is available since SDL 3.0.0.
  169. *
  170. * \sa SDL_InitSubSystem
  171. * \sa SDL_Quit
  172. */
  173. extern SDL_DECLSPEC void SDLCALL SDL_QuitSubSystem(SDL_InitFlags flags);
  174. /**
  175. * Get a mask of the specified subsystems which are currently initialized.
  176. *
  177. * \param flags any of the flags used by SDL_Init(); see SDL_Init for details.
  178. * \returns a mask of all initialized subsystems if `flags` is 0, otherwise it
  179. * returns the initialization status of the specified subsystems.
  180. *
  181. * \since This function is available since SDL 3.0.0.
  182. *
  183. * \sa SDL_Init
  184. * \sa SDL_InitSubSystem
  185. */
  186. extern SDL_DECLSPEC SDL_InitFlags SDLCALL SDL_WasInit(SDL_InitFlags flags);
  187. /**
  188. * Clean up all initialized subsystems.
  189. *
  190. * You should call this function even if you have already shutdown each
  191. * initialized subsystem with SDL_QuitSubSystem(). It is safe to call this
  192. * function even in the case of errors in initialization.
  193. *
  194. * You can use this function with atexit() to ensure that it is run when your
  195. * application is shutdown, but it is not wise to do this from a library or
  196. * other dynamically loaded code.
  197. *
  198. * \since This function is available since SDL 3.0.0.
  199. *
  200. * \sa SDL_Init
  201. * \sa SDL_QuitSubSystem
  202. */
  203. extern SDL_DECLSPEC void SDLCALL SDL_Quit(void);
  204. /**
  205. * Specify basic metadata about your app.
  206. *
  207. * You can optionally provide metadata about your app to SDL. This is not
  208. * required, but strongly encouraged.
  209. *
  210. * There are several locations where SDL can make use of metadata (an "About"
  211. * box in the macOS menu bar, the name of the app can be shown on some audio
  212. * mixers, etc). Any piece of metadata can be left as NULL, if a specific
  213. * detail doesn't make sense for the app.
  214. *
  215. * This function should be called as early as possible, before SDL_Init.
  216. * Multiple calls to this function are allowed, but various state might not
  217. * change once it has been set up with a previous call to this function.
  218. *
  219. * Passing a NULL removes any previous metadata.
  220. *
  221. * This is a simplified interface for the most important information. You can
  222. * supply significantly more detailed metadata with
  223. * SDL_SetAppMetadataProperty().
  224. *
  225. * \param appname The name of the application ("My Game 2: Bad Guy's
  226. * Revenge!").
  227. * \param appversion The version of the application ("1.0.0beta5" or a git
  228. * hash, or whatever makes sense).
  229. * \param appidentifier A unique string in reverse-domain format that
  230. * identifies this app ("com.example.mygame2").
  231. * \returns 0 on success or a negative error code on failure; call
  232. * SDL_GetError() for more information.
  233. *
  234. * \threadsafety It is safe to call this function from any thread.
  235. *
  236. * \since This function is available since SDL 3.0.0.
  237. *
  238. * \sa SDL_SetAppMetadataProperty
  239. */
  240. extern SDL_DECLSPEC int SDLCALL SDL_SetAppMetadata(const char *appname, const char *appversion, const char *appidentifier);
  241. /**
  242. * Specify metadata about your app through a set of properties.
  243. *
  244. * You can optionally provide metadata about your app to SDL. This is not
  245. * required, but strongly encouraged.
  246. *
  247. * There are several locations where SDL can make use of metadata (an "About"
  248. * box in the macOS menu bar, the name of the app can be shown on some audio
  249. * mixers, etc). Any piece of metadata can be left out, if a specific detail
  250. * doesn't make sense for the app.
  251. *
  252. * This function should be called as early as possible, before SDL_Init.
  253. * Multiple calls to this function are allowed, but various state might not
  254. * change once it has been set up with a previous call to this function.
  255. *
  256. * Once set, this metadata can be read using SDL_GetMetadataProperty().
  257. *
  258. * These are the supported properties:
  259. *
  260. * - `SDL_PROP_APP_METADATA_NAME_STRING`: The human-readable name of the
  261. * application, like "My Game 2: Bad Guy's Revenge!". This will show up
  262. * anywhere the OS shows the name of the application separately from window
  263. * titles, such as volume control applets, etc. This defaults to "SDL
  264. * Application".
  265. * - SDL_PROP_APP_METADATA_VERSION_STRING`: The version of the app that is
  266. * running; there are no rules on format, so "1.0.3beta2" and "April 22nd,
  267. * 2024" and a git hash are all valid options. This has no default.
  268. * - `SDL_PROP_APP_METADATA_IDENTIFIER_STRING`: A unique string that
  269. * identifies this app. This must be in reverse-domain format, like
  270. * "com.example.mygame2". This string is used by desktop compositors to
  271. * identify and group windows together, as well as match applications with
  272. * associated desktop settings and icons. If you plan to package your
  273. * application in a container such as Flatpak, the app ID should match the
  274. * name of your Flatpak container as well. This has no default.
  275. * - SDL_PROP_APP_METADATA_CREATOR_STRING`: The human-readable name of the
  276. * creator/developer/maker of this app, like "MojoWorkshop, LLC"
  277. * - SDL_PROP_APP_METADATA_COPYRIGHT_STRING`: The human-readable copyright
  278. * notice, like "Copyright (c) 2024 MojoWorkshop, LLC" or whatnot. Keep this
  279. * to one line, don't paste a copy of a whole software license in here. This
  280. * has no default.
  281. * - SDL_PROP_APP_METADATA_URL_STRING`: A URL to the app on the web. Maybe a
  282. * product page, or a storefront, or even a GitHub repository, for user's
  283. * further information This has no default.
  284. * - SDL_PROP_APP_METADATA_TYPE_STRING`: The type of application this is.
  285. * Currently this string can be "game" for a video game, "mediaplayer" for a
  286. * media player, or generically "application" if nothing else applies.
  287. * Future versions of SDL might add new types. This defaults to
  288. * "application".
  289. *
  290. * \param name the name of the metadata property to set.
  291. * \param value the value of the property, or NULL to remove that property.
  292. * \returns 0 on success or a negative error code on failure; call
  293. * SDL_GetError() for more information.
  294. *
  295. * \threadsafety It is safe to call this function from any thread.
  296. *
  297. * \since This function is available since SDL 3.0.0.
  298. *
  299. * \sa SDL_GetAppMetadataProperty
  300. * \sa SDL_SetAppMetadata
  301. */
  302. extern SDL_DECLSPEC int SDLCALL SDL_SetAppMetadataProperty(const char *name, const char *value);
  303. #define SDL_PROP_APP_METADATA_NAME_STRING "SDL.app.metadata.name"
  304. #define SDL_PROP_APP_METADATA_VERSION_STRING "SDL.app.metadata.version"
  305. #define SDL_PROP_APP_METADATA_IDENTIFIER_STRING "SDL.app.metadata.identifier"
  306. #define SDL_PROP_APP_METADATA_CREATOR_STRING "SDL.app.metadata.creator"
  307. #define SDL_PROP_APP_METADATA_COPYRIGHT_STRING "SDL.app.metadata.copyright"
  308. #define SDL_PROP_APP_METADATA_URL_STRING "SDL.app.metadata.url"
  309. #define SDL_PROP_APP_METADATA_TYPE_STRING "SDL.app.metadata.type"
  310. /**
  311. * Get metadata about your app.
  312. *
  313. * This returns metadata previously set using SDL_SetAppMetadata() or
  314. * SDL_SetAppMetadataProperty(). See SDL_SetAppMetadataProperty() for the list
  315. * of available properties and their meanings.
  316. *
  317. * \param name the name of the metadata property to get.
  318. * \returns the current value of the metadata property, or the default if it
  319. * is not set, NULL for properties with no default.
  320. *
  321. * \threadsafety It is safe to call this function from any thread, although
  322. * the string returned is not protected and could potentially be
  323. * freed if you call SDL_SetAppMetadataProperty() to set that
  324. * property from another thread.
  325. *
  326. * \since This function is available since SDL 3.0.0.
  327. *
  328. * \sa SDL_SetAppMetadata
  329. * \sa SDL_SetAppMetadataProperty
  330. */
  331. extern SDL_DECLSPEC const char * SDLCALL SDL_GetAppMetadataProperty(const char *name);
  332. /* Ends C function definitions when using C++ */
  333. #ifdef __cplusplus
  334. }
  335. #endif
  336. #include <SDL3/SDL_close_code.h>
  337. #endif /* SDL_init_h_ */