SDL_system.h 33 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967
  1. /*
  2. Simple DirectMedia Layer
  3. Copyright (C) 1997-2026 Sam Lantinga <slouken@libsdl.org>
  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. * # CategorySystem
  20. *
  21. * Platform-specific SDL API functions. These are functions that deal with
  22. * needs of specific operating systems, that didn't make sense to offer as
  23. * platform-independent, generic APIs.
  24. *
  25. * Most apps can make do without these functions, but they can be useful for
  26. * integrating with other parts of a specific system, adding platform-specific
  27. * polish to an app, or solving problems that only affect one target.
  28. */
  29. #ifndef SDL_system_h_
  30. #define SDL_system_h_
  31. #include <SDL3/SDL_stdinc.h>
  32. #include <SDL3/SDL_error.h>
  33. #include <SDL3/SDL_keyboard.h>
  34. #include <SDL3/SDL_video.h>
  35. #include <SDL3/SDL_begin_code.h>
  36. /* Set up for C function definitions, even when using C++ */
  37. #ifdef __cplusplus
  38. extern "C" {
  39. #endif
  40. /*
  41. * Platform specific functions for Windows
  42. */
  43. #if defined(SDL_PLATFORM_WINDOWS)
  44. typedef struct tagMSG MSG;
  45. /**
  46. * A callback to be used with SDL_SetWindowsMessageHook.
  47. *
  48. * This callback may modify the message, and should return true if the message
  49. * should continue to be processed, or false to prevent further processing.
  50. *
  51. * As this is processing a message directly from the Windows event loop, this
  52. * callback should do the minimum required work and return quickly.
  53. *
  54. * \param userdata the app-defined pointer provided to
  55. * SDL_SetWindowsMessageHook.
  56. * \param msg a pointer to a Win32 event structure to process.
  57. * \returns true to let event continue on, false to drop it.
  58. *
  59. * \threadsafety This may only be called (by SDL) from the thread handling the
  60. * Windows event loop.
  61. *
  62. * \since This datatype is available since SDL 3.2.0.
  63. *
  64. * \sa SDL_SetWindowsMessageHook
  65. * \sa SDL_HINT_WINDOWS_ENABLE_MESSAGELOOP
  66. */
  67. typedef bool (SDLCALL *SDL_WindowsMessageHook)(void *userdata, MSG *msg);
  68. /**
  69. * Set a callback for every Windows message, run before TranslateMessage().
  70. *
  71. * The callback may modify the message, and should return true if the message
  72. * should continue to be processed, or false to prevent further processing.
  73. *
  74. * \param callback the SDL_WindowsMessageHook function to call.
  75. * \param userdata a pointer to pass to every iteration of `callback`.
  76. *
  77. * \threadsafety This function should only be called on the main thread.
  78. *
  79. * \since This function is available since SDL 3.2.0.
  80. *
  81. * \sa SDL_WindowsMessageHook
  82. * \sa SDL_HINT_WINDOWS_ENABLE_MESSAGELOOP
  83. */
  84. extern SDL_DECLSPEC void SDLCALL SDL_SetWindowsMessageHook(SDL_WindowsMessageHook callback, void *userdata);
  85. #endif /* defined(SDL_PLATFORM_WINDOWS) */
  86. #if defined(SDL_PLATFORM_WIN32) || defined(SDL_PLATFORM_WINGDK)
  87. /**
  88. * Get the D3D9 adapter index that matches the specified display.
  89. *
  90. * The returned adapter index can be passed to `IDirect3D9::CreateDevice` and
  91. * controls on which monitor a full screen application will appear.
  92. *
  93. * \param displayID the instance of the display to query.
  94. * \returns the D3D9 adapter index on success or -1 on failure; call
  95. * SDL_GetError() for more information.
  96. *
  97. * \since This function is available since SDL 3.2.0.
  98. */
  99. extern SDL_DECLSPEC int SDLCALL SDL_GetDirect3D9AdapterIndex(SDL_DisplayID displayID);
  100. /**
  101. * Get the DXGI Adapter and Output indices for the specified display.
  102. *
  103. * The DXGI Adapter and Output indices can be passed to `EnumAdapters` and
  104. * `EnumOutputs` respectively to get the objects required to create a DX10 or
  105. * DX11 device and swap chain.
  106. *
  107. * \param displayID the instance of the display to query.
  108. * \param adapterIndex a pointer to be filled in with the adapter index.
  109. * \param outputIndex a pointer to be filled in with the output index.
  110. * \returns true on success or false on failure; call SDL_GetError() for more
  111. * information.
  112. *
  113. * \since This function is available since SDL 3.2.0.
  114. */
  115. extern SDL_DECLSPEC bool SDLCALL SDL_GetDXGIOutputInfo(SDL_DisplayID displayID, int *adapterIndex, int *outputIndex);
  116. #endif /* defined(SDL_PLATFORM_WIN32) || defined(SDL_PLATFORM_WINGDK) */
  117. /*
  118. * Platform specific functions for UNIX
  119. */
  120. /* this is defined in Xlib's headers, just need a simple declaration here. */
  121. typedef union _XEvent XEvent;
  122. /**
  123. * A callback to be used with SDL_SetX11EventHook.
  124. *
  125. * This callback may modify the event, and should return true if the event
  126. * should continue to be processed, or false to prevent further processing.
  127. *
  128. * As this is processing an event directly from the X11 event loop, this
  129. * callback should do the minimum required work and return quickly.
  130. *
  131. * \param userdata the app-defined pointer provided to SDL_SetX11EventHook.
  132. * \param xevent a pointer to an Xlib XEvent union to process.
  133. * \returns true to let event continue on, false to drop it.
  134. *
  135. * \threadsafety This may only be called (by SDL) from the thread handling the
  136. * X11 event loop.
  137. *
  138. * \since This datatype is available since SDL 3.2.0.
  139. *
  140. * \sa SDL_SetX11EventHook
  141. */
  142. typedef bool (SDLCALL *SDL_X11EventHook)(void *userdata, XEvent *xevent);
  143. /**
  144. * Set a callback for every X11 event.
  145. *
  146. * The callback may modify the event, and should return true if the event
  147. * should continue to be processed, or false to prevent further processing.
  148. *
  149. * \param callback the SDL_X11EventHook function to call.
  150. * \param userdata a pointer to pass to every iteration of `callback`.
  151. *
  152. * \threadsafety This function should only be called on the main thread.
  153. *
  154. * \since This function is available since SDL 3.2.0.
  155. */
  156. extern SDL_DECLSPEC void SDLCALL SDL_SetX11EventHook(SDL_X11EventHook callback, void *userdata);
  157. /* Platform specific functions for Linux*/
  158. #ifdef SDL_PLATFORM_LINUX
  159. /**
  160. * Sets the UNIX nice value for a thread.
  161. *
  162. * This uses setpriority() if possible, and RealtimeKit if available.
  163. *
  164. * \param threadID the Unix thread ID to change priority of.
  165. * \param priority the new, Unix-specific, priority value.
  166. * \returns true on success or false on failure; call SDL_GetError() for more
  167. * information.
  168. *
  169. * \threadsafety It is safe to call this function from any thread.
  170. *
  171. * \since This function is available since SDL 3.2.0.
  172. */
  173. extern SDL_DECLSPEC bool SDLCALL SDL_SetLinuxThreadPriority(Sint64 threadID, int priority);
  174. /**
  175. * Sets the priority (not nice level) and scheduling policy for a thread.
  176. *
  177. * This uses setpriority() if possible, and RealtimeKit if available.
  178. *
  179. * \param threadID the Unix thread ID to change priority of.
  180. * \param sdlPriority the new SDL_ThreadPriority value.
  181. * \param schedPolicy the new scheduling policy (SCHED_FIFO, SCHED_RR,
  182. * SCHED_OTHER, etc...).
  183. * \returns true on success or false on failure; call SDL_GetError() for more
  184. * information.
  185. *
  186. * \threadsafety It is safe to call this function from any thread.
  187. *
  188. * \since This function is available since SDL 3.2.0.
  189. */
  190. extern SDL_DECLSPEC bool SDLCALL SDL_SetLinuxThreadPriorityAndPolicy(Sint64 threadID, int sdlPriority, int schedPolicy);
  191. #endif /* SDL_PLATFORM_LINUX */
  192. /*
  193. * Platform specific functions for iOS
  194. */
  195. #ifdef SDL_PLATFORM_IOS
  196. /**
  197. * The prototype for an Apple iOS animation callback.
  198. *
  199. * This datatype is only useful on Apple iOS.
  200. *
  201. * After passing a function pointer of this type to
  202. * SDL_SetiOSAnimationCallback, the system will call that function pointer at
  203. * a regular interval.
  204. *
  205. * \param userdata what was passed as `callbackParam` to
  206. * SDL_SetiOSAnimationCallback as `callbackParam`.
  207. *
  208. * \since This datatype is available since SDL 3.2.0.
  209. *
  210. * \sa SDL_SetiOSAnimationCallback
  211. */
  212. typedef void (SDLCALL *SDL_iOSAnimationCallback)(void *userdata);
  213. /**
  214. * Use this function to set the animation callback on Apple iOS.
  215. *
  216. * The function prototype for `callback` is:
  217. *
  218. * ```c
  219. * void callback(void *callbackParam);
  220. * ```
  221. *
  222. * Where its parameter, `callbackParam`, is what was passed as `callbackParam`
  223. * to SDL_SetiOSAnimationCallback().
  224. *
  225. * This function is only available on Apple iOS.
  226. *
  227. * For more information see:
  228. *
  229. * https://wiki.libsdl.org/SDL3/README-ios
  230. *
  231. * Note that if you use the "main callbacks" instead of a standard C `main`
  232. * function, you don't have to use this API, as SDL will manage this for you.
  233. *
  234. * Details on main callbacks are here:
  235. *
  236. * https://wiki.libsdl.org/SDL3/README-main-functions
  237. *
  238. * \param window the window for which the animation callback should be set.
  239. * \param interval the number of frames after which **callback** will be
  240. * called.
  241. * \param callback the function to call for every frame.
  242. * \param callbackParam a pointer that is passed to `callback`.
  243. * \returns true on success or false on failure; call SDL_GetError() for more
  244. * information.
  245. *
  246. * \threadsafety This function should only be called on the main thread.
  247. *
  248. * \since This function is available since SDL 3.2.0.
  249. *
  250. * \sa SDL_SetiOSEventPump
  251. */
  252. extern SDL_DECLSPEC bool SDLCALL SDL_SetiOSAnimationCallback(SDL_Window *window, int interval, SDL_iOSAnimationCallback callback, void *callbackParam);
  253. /**
  254. * Use this function to enable or disable the SDL event pump on Apple iOS.
  255. *
  256. * This function is only available on Apple iOS.
  257. *
  258. * \param enabled true to enable the event pump, false to disable it.
  259. *
  260. * \threadsafety This function should only be called on the main thread.
  261. *
  262. * \since This function is available since SDL 3.2.0.
  263. *
  264. * \sa SDL_SetiOSAnimationCallback
  265. */
  266. extern SDL_DECLSPEC void SDLCALL SDL_SetiOSEventPump(bool enabled);
  267. #endif /* SDL_PLATFORM_IOS */
  268. /*
  269. * Platform specific functions for Android
  270. */
  271. #ifdef SDL_PLATFORM_ANDROID
  272. /**
  273. * Get the Android Java Native Interface Environment of the current thread.
  274. *
  275. * This is the JNIEnv one needs to access the Java virtual machine from native
  276. * code, and is needed for many Android APIs to be usable from C.
  277. *
  278. * The prototype of the function in SDL's code actually declare a void* return
  279. * type, even if the implementation returns a pointer to a JNIEnv. The
  280. * rationale being that the SDL headers can avoid including jni.h.
  281. *
  282. * \returns a pointer to Java native interface object (JNIEnv) to which the
  283. * current thread is attached, or NULL on failure; call
  284. * SDL_GetError() for more information.
  285. *
  286. * \threadsafety It is safe to call this function from any thread.
  287. *
  288. * \since This function is available since SDL 3.2.0.
  289. *
  290. * \sa SDL_GetAndroidActivity
  291. */
  292. extern SDL_DECLSPEC void * SDLCALL SDL_GetAndroidJNIEnv(void);
  293. /**
  294. * Retrieve the Java instance of the Android activity class.
  295. *
  296. * The prototype of the function in SDL's code actually declares a void*
  297. * return type, even if the implementation returns a jobject. The rationale
  298. * being that the SDL headers can avoid including jni.h.
  299. *
  300. * The jobject returned by the function is a local reference and must be
  301. * released by the caller. See the PushLocalFrame() and PopLocalFrame() or
  302. * DeleteLocalRef() functions of the Java native interface:
  303. *
  304. * https://docs.oracle.com/javase/1.5.0/docs/guide/jni/spec/functions.html
  305. *
  306. * \returns the jobject representing the instance of the Activity class of the
  307. * Android application, or NULL on failure; call SDL_GetError() for
  308. * more information.
  309. *
  310. * \threadsafety It is safe to call this function from any thread.
  311. *
  312. * \since This function is available since SDL 3.2.0.
  313. *
  314. * \sa SDL_GetAndroidJNIEnv
  315. */
  316. extern SDL_DECLSPEC void * SDLCALL SDL_GetAndroidActivity(void);
  317. /**
  318. * Query Android API level of the current device.
  319. *
  320. * - API level 35: Android 15 (VANILLA_ICE_CREAM)
  321. * - API level 34: Android 14 (UPSIDE_DOWN_CAKE)
  322. * - API level 33: Android 13 (TIRAMISU)
  323. * - API level 32: Android 12L (S_V2)
  324. * - API level 31: Android 12 (S)
  325. * - API level 30: Android 11 (R)
  326. * - API level 29: Android 10 (Q)
  327. * - API level 28: Android 9 (P)
  328. * - API level 27: Android 8.1 (O_MR1)
  329. * - API level 26: Android 8.0 (O)
  330. * - API level 25: Android 7.1 (N_MR1)
  331. * - API level 24: Android 7.0 (N)
  332. * - API level 23: Android 6.0 (M)
  333. * - API level 22: Android 5.1 (LOLLIPOP_MR1)
  334. * - API level 21: Android 5.0 (LOLLIPOP, L)
  335. * - API level 20: Android 4.4W (KITKAT_WATCH)
  336. * - API level 19: Android 4.4 (KITKAT)
  337. * - API level 18: Android 4.3 (JELLY_BEAN_MR2)
  338. * - API level 17: Android 4.2 (JELLY_BEAN_MR1)
  339. * - API level 16: Android 4.1 (JELLY_BEAN)
  340. * - API level 15: Android 4.0.3 (ICE_CREAM_SANDWICH_MR1)
  341. * - API level 14: Android 4.0 (ICE_CREAM_SANDWICH)
  342. * - API level 13: Android 3.2 (HONEYCOMB_MR2)
  343. * - API level 12: Android 3.1 (HONEYCOMB_MR1)
  344. * - API level 11: Android 3.0 (HONEYCOMB)
  345. * - API level 10: Android 2.3.3 (GINGERBREAD_MR1)
  346. *
  347. * \returns the Android API level.
  348. *
  349. * \threadsafety It is safe to call this function from any thread.
  350. *
  351. * \since This function is available since SDL 3.2.0.
  352. */
  353. extern SDL_DECLSPEC int SDLCALL SDL_GetAndroidSDKVersion(void);
  354. /**
  355. * Query if the application is running on a Chromebook.
  356. *
  357. * \returns true if this is a Chromebook, false otherwise.
  358. *
  359. * \threadsafety It is safe to call this function from any thread.
  360. *
  361. * \since This function is available since SDL 3.2.0.
  362. */
  363. extern SDL_DECLSPEC bool SDLCALL SDL_IsChromebook(void);
  364. /**
  365. * Query if the application is running on a Samsung DeX docking station.
  366. *
  367. * \returns true if this is a DeX docking station, false otherwise.
  368. *
  369. * \threadsafety It is safe to call this function from any thread.
  370. *
  371. * \since This function is available since SDL 3.2.0.
  372. */
  373. extern SDL_DECLSPEC bool SDLCALL SDL_IsDeXMode(void);
  374. /**
  375. * Trigger the Android system back button behavior.
  376. *
  377. * \threadsafety It is safe to call this function from any thread.
  378. *
  379. * \since This function is available since SDL 3.2.0.
  380. */
  381. extern SDL_DECLSPEC void SDLCALL SDL_SendAndroidBackButton(void);
  382. /**
  383. * See the official Android developer guide for more information:
  384. * http://developer.android.com/guide/topics/data/data-storage.html
  385. *
  386. * \since This macro is available since SDL 3.2.0.
  387. */
  388. #define SDL_ANDROID_EXTERNAL_STORAGE_READ 0x01
  389. /**
  390. * See the official Android developer guide for more information:
  391. * http://developer.android.com/guide/topics/data/data-storage.html
  392. *
  393. * \since This macro is available since SDL 3.2.0.
  394. */
  395. #define SDL_ANDROID_EXTERNAL_STORAGE_WRITE 0x02
  396. /**
  397. * Get the path used for internal storage for this Android application.
  398. *
  399. * This path is unique to your application and cannot be written to by other
  400. * applications.
  401. *
  402. * Your internal storage path is typically:
  403. * `/data/data/your.app.package/files`.
  404. *
  405. * This is a C wrapper over `android.content.Context.getFilesDir()`:
  406. *
  407. * https://developer.android.com/reference/android/content/Context#getFilesDir()
  408. *
  409. * \returns the path used for internal storage or NULL on failure; call
  410. * SDL_GetError() for more information.
  411. *
  412. * \since This function is available since SDL 3.2.0.
  413. *
  414. * \sa SDL_GetAndroidExternalStoragePath
  415. * \sa SDL_GetAndroidCachePath
  416. */
  417. extern SDL_DECLSPEC const char * SDLCALL SDL_GetAndroidInternalStoragePath(void);
  418. /**
  419. * Get the current state of external storage for this Android application.
  420. *
  421. * The current state of external storage, a bitmask of these values:
  422. * `SDL_ANDROID_EXTERNAL_STORAGE_READ`, `SDL_ANDROID_EXTERNAL_STORAGE_WRITE`.
  423. *
  424. * If external storage is currently unavailable, this will return 0.
  425. *
  426. * \returns the current state of external storage, or 0 if external storage is
  427. * currently unavailable.
  428. *
  429. * \since This function is available since SDL 3.2.0.
  430. *
  431. * \sa SDL_GetAndroidExternalStoragePath
  432. */
  433. extern SDL_DECLSPEC Uint32 SDLCALL SDL_GetAndroidExternalStorageState(void);
  434. /**
  435. * Get the path used for external storage for this Android application.
  436. *
  437. * This path is unique to your application, but is public and can be written
  438. * to by other applications.
  439. *
  440. * Your external storage path is typically:
  441. * `/storage/sdcard0/Android/data/your.app.package/files`.
  442. *
  443. * This is a C wrapper over `android.content.Context.getExternalFilesDir()`:
  444. *
  445. * https://developer.android.com/reference/android/content/Context#getExternalFilesDir()
  446. *
  447. * \returns the path used for external storage for this application on success
  448. * or NULL on failure; call SDL_GetError() for more information.
  449. *
  450. * \since This function is available since SDL 3.2.0.
  451. *
  452. * \sa SDL_GetAndroidExternalStorageState
  453. * \sa SDL_GetAndroidInternalStoragePath
  454. * \sa SDL_GetAndroidCachePath
  455. */
  456. extern SDL_DECLSPEC const char * SDLCALL SDL_GetAndroidExternalStoragePath(void);
  457. /**
  458. * Get the path used for caching data for this Android application.
  459. *
  460. * This path is unique to your application, but is public and can be written
  461. * to by other applications.
  462. *
  463. * Your cache path is typically: `/data/data/your.app.package/cache/`.
  464. *
  465. * This is a C wrapper over `android.content.Context.getCacheDir()`:
  466. *
  467. * https://developer.android.com/reference/android/content/Context#getCacheDir()
  468. *
  469. * \returns the path used for caches for this application on success or NULL
  470. * on failure; call SDL_GetError() for more information.
  471. *
  472. * \since This function is available since SDL 3.2.0.
  473. *
  474. * \sa SDL_GetAndroidInternalStoragePath
  475. * \sa SDL_GetAndroidExternalStoragePath
  476. */
  477. extern SDL_DECLSPEC const char * SDLCALL SDL_GetAndroidCachePath(void);
  478. /**
  479. * Callback that presents a response from a SDL_RequestAndroidPermission call.
  480. *
  481. * \param userdata an app-controlled pointer that is passed to the callback.
  482. * \param permission the Android-specific permission name that was requested.
  483. * \param granted true if permission is granted, false if denied.
  484. *
  485. * \since This datatype is available since SDL 3.2.0.
  486. *
  487. * \sa SDL_RequestAndroidPermission
  488. */
  489. typedef void (SDLCALL *SDL_RequestAndroidPermissionCallback)(void *userdata, const char *permission, bool granted);
  490. /**
  491. * Request permissions at runtime, asynchronously.
  492. *
  493. * You do not need to call this for built-in functionality of SDL; recording
  494. * from a microphone or reading images from a camera, using standard SDL APIs,
  495. * will manage permission requests for you.
  496. *
  497. * This function never blocks. Instead, the app-supplied callback will be
  498. * called when a decision has been made. This callback may happen on a
  499. * different thread, and possibly much later, as it might wait on a user to
  500. * respond to a system dialog. If permission has already been granted for a
  501. * specific entitlement, the callback will still fire, probably on the current
  502. * thread and before this function returns.
  503. *
  504. * If the request submission fails, this function returns false and the
  505. * callback will NOT be called, but this should only happen in catastrophic
  506. * conditions, like memory running out. Normally there will be a yes or no to
  507. * the request through the callback.
  508. *
  509. * For the `permission` parameter, choose a value from here:
  510. *
  511. * https://developer.android.com/reference/android/Manifest.permission
  512. *
  513. * \param permission the permission to request.
  514. * \param cb the callback to trigger when the request has a response.
  515. * \param userdata an app-controlled pointer that is passed to the callback.
  516. * \returns true if the request was submitted, false if there was an error
  517. * submitting. The result of the request is only ever reported
  518. * through the callback, not this return value.
  519. *
  520. * \threadsafety It is safe to call this function from any thread.
  521. *
  522. * \since This function is available since SDL 3.2.0.
  523. */
  524. extern SDL_DECLSPEC bool SDLCALL SDL_RequestAndroidPermission(const char *permission, SDL_RequestAndroidPermissionCallback cb, void *userdata);
  525. /**
  526. * Shows an Android toast notification.
  527. *
  528. * Toasts are a sort of lightweight notification that are unique to Android.
  529. *
  530. * https://developer.android.com/guide/topics/ui/notifiers/toasts
  531. *
  532. * Shows toast in UI thread.
  533. *
  534. * For the `gravity` parameter, choose a value from here, or -1 if you don't
  535. * have a preference:
  536. *
  537. * https://developer.android.com/reference/android/view/Gravity
  538. *
  539. * \param message text message to be shown.
  540. * \param duration 0=short, 1=long.
  541. * \param gravity where the notification should appear on the screen.
  542. * \param xoffset set this parameter only when gravity >=0.
  543. * \param yoffset set this parameter only when gravity >=0.
  544. * \returns true on success or false on failure; call SDL_GetError() for more
  545. * information.
  546. *
  547. * \threadsafety It is safe to call this function from any thread.
  548. *
  549. * \since This function is available since SDL 3.2.0.
  550. */
  551. extern SDL_DECLSPEC bool SDLCALL SDL_ShowAndroidToast(const char *message, int duration, int gravity, int xoffset, int yoffset);
  552. /**
  553. * Send a user command to SDLActivity.
  554. *
  555. * Override "boolean onUnhandledMessage(Message msg)" to handle the message.
  556. *
  557. * \param command user command that must be greater or equal to 0x8000.
  558. * \param param user parameter.
  559. * \returns true on success or false on failure; call SDL_GetError() for more
  560. * information.
  561. *
  562. * \threadsafety It is safe to call this function from any thread.
  563. *
  564. * \since This function is available since SDL 3.2.0.
  565. */
  566. extern SDL_DECLSPEC bool SDLCALL SDL_SendAndroidMessage(Uint32 command, int param);
  567. #endif /* SDL_PLATFORM_ANDROID */
  568. /**
  569. * Query if the current device is a phone.
  570. *
  571. * If SDL can't determine this, it will return false.
  572. *
  573. * \returns true if the device is a phone, false otherwise.
  574. *
  575. * \threadsafety It is safe to call this function from any thread.
  576. *
  577. * \since This function is available since SDL 3.6.0.
  578. */
  579. extern SDL_DECLSPEC bool SDLCALL SDL_IsPhone(void);
  580. /**
  581. * Query if the current device is a tablet.
  582. *
  583. * If SDL can't determine this, it will return false.
  584. *
  585. * \returns true if the device is a tablet, false otherwise.
  586. *
  587. * \threadsafety It is safe to call this function from any thread.
  588. *
  589. * \since This function is available since SDL 3.2.0.
  590. */
  591. extern SDL_DECLSPEC bool SDLCALL SDL_IsTablet(void);
  592. /**
  593. * Query if the current device is a TV.
  594. *
  595. * If SDL can't determine this, it will return false.
  596. *
  597. * \returns true if the device is a TV, false otherwise.
  598. *
  599. * \threadsafety It is safe to call this function from any thread.
  600. *
  601. * \since This function is available since SDL 3.2.0.
  602. */
  603. extern SDL_DECLSPEC bool SDLCALL SDL_IsTV(void);
  604. /**
  605. * The possible form factors for a device.
  606. *
  607. * \since This enum is available since SDL 3.4.0.
  608. *
  609. * \sa SDL_GetDeviceFormFactor
  610. * \sa SDL_GetDeviceFormFactorName
  611. */
  612. typedef enum SDL_FormFactor {
  613. SDL_FORMFACTOR_UNKNOWN = 0,
  614. SDL_FORMFACTOR_DESKTOP,
  615. SDL_FORMFACTOR_LAPTOP,
  616. SDL_FORMFACTOR_PHONE,
  617. SDL_FORMFACTOR_TABLET,
  618. SDL_FORMFACTOR_CONSOLE,
  619. SDL_FORMFACTOR_HANDHELD,
  620. SDL_FORMFACTOR_WATCH,
  621. SDL_FORMFACTOR_TV,
  622. SDL_FORMFACTOR_HEADSET,
  623. SDL_FORMFACTOR_CAR
  624. } SDL_FormFactor;
  625. /**
  626. * Get the form factor of the current device.
  627. *
  628. * This function guesses what the device may be, but may report inaccurate or
  629. * outright wrong results. For example, it may report a laptop as a desktop,
  630. * or a car device as a phone.
  631. *
  632. * Depending on the usage, there may be different functions better suited for
  633. * each purpose. For example, activating touch controls can be done by
  634. * detecting the presence of a touchscreen rather than restricting to phones
  635. * and tablets.
  636. *
  637. * \returns the best guess for the form factor of the current device.
  638. *
  639. * \since This function is available since SDL 3.6.0.
  640. *
  641. * \sa SDL_FormFactor
  642. * \sa SDL_GetDeviceFormFactorName
  643. */
  644. extern SDL_DECLSPEC SDL_FormFactor SDLCALL SDL_GetDeviceFormFactor(void);
  645. /**
  646. * Get a short name for the current device.
  647. *
  648. * The name will be in English.
  649. *
  650. * \param form_factor the form factor to query.
  651. * \returns a human-readable name for the given form factor, or
  652. * "SDL_FORMFACTOR_UNKNOWN" if the form factor isn't recognized.
  653. *
  654. * \since This function is available since SDL 3.6.0.
  655. *
  656. * \sa SDL_FormFactor
  657. * \sa SDL_GetDeviceFormFactor
  658. */
  659. extern SDL_DECLSPEC const char* SDLCALL SDL_GetDeviceFormFactorName(SDL_FormFactor form_factor);
  660. /**
  661. * Application sandbox environment.
  662. *
  663. * \since This enum is available since SDL 3.2.0.
  664. */
  665. typedef enum SDL_Sandbox
  666. {
  667. SDL_SANDBOX_NONE = 0,
  668. SDL_SANDBOX_UNKNOWN_CONTAINER,
  669. SDL_SANDBOX_FLATPAK,
  670. SDL_SANDBOX_SNAP,
  671. SDL_SANDBOX_MACOS,
  672. SDL_SANDBOX_LOMIRI
  673. } SDL_Sandbox;
  674. /**
  675. * Get the application sandbox environment, if any.
  676. *
  677. * \returns the application sandbox environment or SDL_SANDBOX_NONE if the
  678. * application is not running in a sandbox environment.
  679. *
  680. * \since This function is available since SDL 3.2.0.
  681. */
  682. extern SDL_DECLSPEC SDL_Sandbox SDLCALL SDL_GetSandbox(void);
  683. /* Functions used by iOS app delegates to notify SDL about state changes. */
  684. /**
  685. * Let iOS apps with external event handling report
  686. * onApplicationWillTerminate.
  687. *
  688. * This functions allows iOS apps that have their own event handling to hook
  689. * into SDL to generate SDL events. This maps directly to an iOS-specific
  690. * event, but since it doesn't do anything iOS-specific internally, it is
  691. * available on all platforms, in case it might be useful for some specific
  692. * paradigm. Most apps do not need to use this directly; SDL's internal event
  693. * code will handle all this for windows created by SDL_CreateWindow!
  694. *
  695. * \threadsafety It is safe to call this function from any thread.
  696. *
  697. * \since This function is available since SDL 3.2.0.
  698. */
  699. extern SDL_DECLSPEC void SDLCALL SDL_OnApplicationWillTerminate(void);
  700. /**
  701. * Let iOS apps with external event handling report
  702. * onApplicationDidReceiveMemoryWarning.
  703. *
  704. * This functions allows iOS apps that have their own event handling to hook
  705. * into SDL to generate SDL events. This maps directly to an iOS-specific
  706. * event, but since it doesn't do anything iOS-specific internally, it is
  707. * available on all platforms, in case it might be useful for some specific
  708. * paradigm. Most apps do not need to use this directly; SDL's internal event
  709. * code will handle all this for windows created by SDL_CreateWindow!
  710. *
  711. * \threadsafety It is safe to call this function from any thread.
  712. *
  713. * \since This function is available since SDL 3.2.0.
  714. */
  715. extern SDL_DECLSPEC void SDLCALL SDL_OnApplicationDidReceiveMemoryWarning(void);
  716. /**
  717. * Let iOS apps with external event handling report
  718. * onApplicationWillResignActive.
  719. *
  720. * This functions allows iOS apps that have their own event handling to hook
  721. * into SDL to generate SDL events. This maps directly to an iOS-specific
  722. * event, but since it doesn't do anything iOS-specific internally, it is
  723. * available on all platforms, in case it might be useful for some specific
  724. * paradigm. Most apps do not need to use this directly; SDL's internal event
  725. * code will handle all this for windows created by SDL_CreateWindow!
  726. *
  727. * \threadsafety It is safe to call this function from any thread.
  728. *
  729. * \since This function is available since SDL 3.2.0.
  730. */
  731. extern SDL_DECLSPEC void SDLCALL SDL_OnApplicationWillEnterBackground(void);
  732. /**
  733. * Let iOS apps with external event handling report
  734. * onApplicationDidEnterBackground.
  735. *
  736. * This functions allows iOS apps that have their own event handling to hook
  737. * into SDL to generate SDL events. This maps directly to an iOS-specific
  738. * event, but since it doesn't do anything iOS-specific internally, it is
  739. * available on all platforms, in case it might be useful for some specific
  740. * paradigm. Most apps do not need to use this directly; SDL's internal event
  741. * code will handle all this for windows created by SDL_CreateWindow!
  742. *
  743. * \threadsafety It is safe to call this function from any thread.
  744. *
  745. * \since This function is available since SDL 3.2.0.
  746. */
  747. extern SDL_DECLSPEC void SDLCALL SDL_OnApplicationDidEnterBackground(void);
  748. /**
  749. * Let iOS apps with external event handling report
  750. * onApplicationWillEnterForeground.
  751. *
  752. * This functions allows iOS apps that have their own event handling to hook
  753. * into SDL to generate SDL events. This maps directly to an iOS-specific
  754. * event, but since it doesn't do anything iOS-specific internally, it is
  755. * available on all platforms, in case it might be useful for some specific
  756. * paradigm. Most apps do not need to use this directly; SDL's internal event
  757. * code will handle all this for windows created by SDL_CreateWindow!
  758. *
  759. * \threadsafety It is safe to call this function from any thread.
  760. *
  761. * \since This function is available since SDL 3.2.0.
  762. */
  763. extern SDL_DECLSPEC void SDLCALL SDL_OnApplicationWillEnterForeground(void);
  764. /**
  765. * Let iOS apps with external event handling report
  766. * onApplicationDidBecomeActive.
  767. *
  768. * This functions allows iOS apps that have their own event handling to hook
  769. * into SDL to generate SDL events. This maps directly to an iOS-specific
  770. * event, but since it doesn't do anything iOS-specific internally, it is
  771. * available on all platforms, in case it might be useful for some specific
  772. * paradigm. Most apps do not need to use this directly; SDL's internal event
  773. * code will handle all this for windows created by SDL_CreateWindow!
  774. *
  775. * \threadsafety It is safe to call this function from any thread.
  776. *
  777. * \since This function is available since SDL 3.2.0.
  778. */
  779. extern SDL_DECLSPEC void SDLCALL SDL_OnApplicationDidEnterForeground(void);
  780. #ifdef SDL_PLATFORM_IOS
  781. /**
  782. * Let iOS apps with external event handling report
  783. * onApplicationDidChangeStatusBarOrientation.
  784. *
  785. * This functions allows iOS apps that have their own event handling to hook
  786. * into SDL to generate SDL events. This maps directly to an iOS-specific
  787. * event, but since it doesn't do anything iOS-specific internally, it is
  788. * available on all platforms, in case it might be useful for some specific
  789. * paradigm. Most apps do not need to use this directly; SDL's internal event
  790. * code will handle all this for windows created by SDL_CreateWindow!
  791. *
  792. * \threadsafety It is safe to call this function from any thread.
  793. *
  794. * \since This function is available since SDL 3.2.0.
  795. */
  796. extern SDL_DECLSPEC void SDLCALL SDL_OnApplicationDidChangeStatusBarOrientation(void);
  797. #endif
  798. /*
  799. * Functions used only by GDK
  800. */
  801. #ifdef SDL_PLATFORM_GDK
  802. typedef struct XTaskQueueObject *XTaskQueueHandle;
  803. typedef struct XUser *XUserHandle;
  804. /**
  805. * Gets a reference to the global async task queue handle for GDK,
  806. * initializing if needed.
  807. *
  808. * Once you are done with the task queue, you should call
  809. * XTaskQueueCloseHandle to reduce the reference count to avoid a resource
  810. * leak.
  811. *
  812. * \param outTaskQueue a pointer to be filled in with task queue handle.
  813. * \returns true on success or false on failure; call SDL_GetError() for more
  814. * information.
  815. *
  816. * \since This function is available since SDL 3.2.0.
  817. */
  818. extern SDL_DECLSPEC bool SDLCALL SDL_GetGDKTaskQueue(XTaskQueueHandle *outTaskQueue);
  819. /**
  820. * Gets a reference to the default user handle for GDK.
  821. *
  822. * This is effectively a synchronous version of XUserAddAsync, which always
  823. * prefers the default user and allows a sign-in UI.
  824. *
  825. * \param outUserHandle a pointer to be filled in with the default user
  826. * handle.
  827. * \returns true if success or false on failure; call SDL_GetError() for more
  828. * information.
  829. *
  830. * \since This function is available since SDL 3.2.0.
  831. */
  832. extern SDL_DECLSPEC bool SDLCALL SDL_GetGDKDefaultUser(XUserHandle *outUserHandle);
  833. #endif
  834. /*
  835. * Functions used only with Ubuntu Touch
  836. */
  837. #ifdef SDL_PLATFORM_LINUX
  838. /**
  839. * Detect whether the current platform is Ubuntu Touch.
  840. *
  841. * \returns true if the platform is Ubuntu Touch; false otherwise.
  842. *
  843. * \since This function is available since SDL 3.6.0.
  844. */
  845. extern SDL_DECLSPEC bool SDLCALL SDL_IsUbuntuTouch(void);
  846. /**
  847. * The ID of the application on Ubuntu Touch, as reported in the manifest.
  848. *
  849. * This is often called the "App Name"; the human-readable name for an app is
  850. * called the "App Title".
  851. *
  852. * This string is needed by some low-level OS features to operate properly.
  853. *
  854. * \since This macro is available since SDL 3.6.0.
  855. *
  856. * \sa SDL_IsUbuntuTouch
  857. */
  858. #define SDL_PROP_GLOBAL_SYSTEM_UBUNTU_TOUCH_APPID_STRING "SDL.system.ubuntu_touch.appid"
  859. /**
  860. * The identifier for the specific hook which launched the current executable,
  861. * as reported in the manifest.
  862. *
  863. * This is relevant for application packages that ship multiple applications
  864. * with their desktop files; they will have the same app ID but will differ by
  865. * their hook.
  866. *
  867. * \since This macro is available since SDL 3.6.0.
  868. *
  869. * \sa SDL_IsUbuntuTouch
  870. */
  871. #define SDL_PROP_GLOBAL_SYSTEM_UBUNTU_TOUCH_HOOK_STRING "SDL.system.ubuntu_touch.hook"
  872. /**
  873. * The version of the application on Ubuntu Touch, as reported in the
  874. * manifest.
  875. *
  876. * \since This macro is available since SDL 3.6.0.
  877. *
  878. * \sa SDL_IsUbuntuTouch
  879. */
  880. #define SDL_PROP_GLOBAL_SYSTEM_UBUNTU_TOUCH_APP_VERSION_STRING "SDL.system.ubuntu_touch.app_version"
  881. #endif
  882. /* Ends C function definitions when using C++ */
  883. #ifdef __cplusplus
  884. }
  885. #endif
  886. #include <SDL3/SDL_close_code.h>
  887. #endif /* SDL_system_h_ */