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