SDL_system.h 29 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840
  1. /*
  2. Simple DirectMedia Layer
  3. Copyright (C) 1997-2026 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. * # 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 -1 and the callback
  505. * will NOT be called, but this should only happen in catastrophic conditions,
  506. * like memory running out. Normally there will be a yes or no to the request
  507. * 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 tablet.
  570. *
  571. * If SDL can't determine this, it will return false.
  572. *
  573. * \returns true if the device is a tablet, 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.2.0.
  578. */
  579. extern SDL_DECLSPEC bool SDLCALL SDL_IsTablet(void);
  580. /**
  581. * Query if the current device is a TV.
  582. *
  583. * If SDL can't determine this, it will return false.
  584. *
  585. * \returns true if the device is a TV, 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_IsTV(void);
  592. /**
  593. * Application sandbox environment.
  594. *
  595. * \since This enum is available since SDL 3.2.0.
  596. */
  597. typedef enum SDL_Sandbox
  598. {
  599. SDL_SANDBOX_NONE = 0,
  600. SDL_SANDBOX_UNKNOWN_CONTAINER,
  601. SDL_SANDBOX_FLATPAK,
  602. SDL_SANDBOX_SNAP,
  603. SDL_SANDBOX_MACOS
  604. } SDL_Sandbox;
  605. /**
  606. * Get the application sandbox environment, if any.
  607. *
  608. * \returns the application sandbox environment or SDL_SANDBOX_NONE if the
  609. * application is not running in a sandbox environment.
  610. *
  611. * \since This function is available since SDL 3.2.0.
  612. */
  613. extern SDL_DECLSPEC SDL_Sandbox SDLCALL SDL_GetSandbox(void);
  614. /* Functions used by iOS app delegates to notify SDL about state changes. */
  615. /**
  616. * Let iOS apps with external event handling report
  617. * onApplicationWillTerminate.
  618. *
  619. * This functions allows iOS apps that have their own event handling to hook
  620. * into SDL to generate SDL events. This maps directly to an iOS-specific
  621. * event, but since it doesn't do anything iOS-specific internally, it is
  622. * available on all platforms, in case it might be useful for some specific
  623. * paradigm. Most apps do not need to use this directly; SDL's internal event
  624. * code will handle all this for windows created by SDL_CreateWindow!
  625. *
  626. * \threadsafety It is safe to call this function from any thread.
  627. *
  628. * \since This function is available since SDL 3.2.0.
  629. */
  630. extern SDL_DECLSPEC void SDLCALL SDL_OnApplicationWillTerminate(void);
  631. /**
  632. * Let iOS apps with external event handling report
  633. * onApplicationDidReceiveMemoryWarning.
  634. *
  635. * This functions allows iOS apps that have their own event handling to hook
  636. * into SDL to generate SDL events. This maps directly to an iOS-specific
  637. * event, but since it doesn't do anything iOS-specific internally, it is
  638. * available on all platforms, in case it might be useful for some specific
  639. * paradigm. Most apps do not need to use this directly; SDL's internal event
  640. * code will handle all this for windows created by SDL_CreateWindow!
  641. *
  642. * \threadsafety It is safe to call this function from any thread.
  643. *
  644. * \since This function is available since SDL 3.2.0.
  645. */
  646. extern SDL_DECLSPEC void SDLCALL SDL_OnApplicationDidReceiveMemoryWarning(void);
  647. /**
  648. * Let iOS apps with external event handling report
  649. * onApplicationWillResignActive.
  650. *
  651. * This functions allows iOS apps that have their own event handling to hook
  652. * into SDL to generate SDL events. This maps directly to an iOS-specific
  653. * event, but since it doesn't do anything iOS-specific internally, it is
  654. * available on all platforms, in case it might be useful for some specific
  655. * paradigm. Most apps do not need to use this directly; SDL's internal event
  656. * code will handle all this for windows created by SDL_CreateWindow!
  657. *
  658. * \threadsafety It is safe to call this function from any thread.
  659. *
  660. * \since This function is available since SDL 3.2.0.
  661. */
  662. extern SDL_DECLSPEC void SDLCALL SDL_OnApplicationWillEnterBackground(void);
  663. /**
  664. * Let iOS apps with external event handling report
  665. * onApplicationDidEnterBackground.
  666. *
  667. * This functions allows iOS apps that have their own event handling to hook
  668. * into SDL to generate SDL events. This maps directly to an iOS-specific
  669. * event, but since it doesn't do anything iOS-specific internally, it is
  670. * available on all platforms, in case it might be useful for some specific
  671. * paradigm. Most apps do not need to use this directly; SDL's internal event
  672. * code will handle all this for windows created by SDL_CreateWindow!
  673. *
  674. * \threadsafety It is safe to call this function from any thread.
  675. *
  676. * \since This function is available since SDL 3.2.0.
  677. */
  678. extern SDL_DECLSPEC void SDLCALL SDL_OnApplicationDidEnterBackground(void);
  679. /**
  680. * Let iOS apps with external event handling report
  681. * onApplicationWillEnterForeground.
  682. *
  683. * This functions allows iOS apps that have their own event handling to hook
  684. * into SDL to generate SDL events. This maps directly to an iOS-specific
  685. * event, but since it doesn't do anything iOS-specific internally, it is
  686. * available on all platforms, in case it might be useful for some specific
  687. * paradigm. Most apps do not need to use this directly; SDL's internal event
  688. * code will handle all this for windows created by SDL_CreateWindow!
  689. *
  690. * \threadsafety It is safe to call this function from any thread.
  691. *
  692. * \since This function is available since SDL 3.2.0.
  693. */
  694. extern SDL_DECLSPEC void SDLCALL SDL_OnApplicationWillEnterForeground(void);
  695. /**
  696. * Let iOS apps with external event handling report
  697. * onApplicationDidBecomeActive.
  698. *
  699. * This functions allows iOS apps that have their own event handling to hook
  700. * into SDL to generate SDL events. This maps directly to an iOS-specific
  701. * event, but since it doesn't do anything iOS-specific internally, it is
  702. * available on all platforms, in case it might be useful for some specific
  703. * paradigm. Most apps do not need to use this directly; SDL's internal event
  704. * code will handle all this for windows created by SDL_CreateWindow!
  705. *
  706. * \threadsafety It is safe to call this function from any thread.
  707. *
  708. * \since This function is available since SDL 3.2.0.
  709. */
  710. extern SDL_DECLSPEC void SDLCALL SDL_OnApplicationDidEnterForeground(void);
  711. #ifdef SDL_PLATFORM_IOS
  712. /**
  713. * Let iOS apps with external event handling report
  714. * onApplicationDidChangeStatusBarOrientation.
  715. *
  716. * This functions allows iOS apps that have their own event handling to hook
  717. * into SDL to generate SDL events. This maps directly to an iOS-specific
  718. * event, but since it doesn't do anything iOS-specific internally, it is
  719. * available on all platforms, in case it might be useful for some specific
  720. * paradigm. Most apps do not need to use this directly; SDL's internal event
  721. * code will handle all this for windows created by SDL_CreateWindow!
  722. *
  723. * \threadsafety It is safe to call this function from any thread.
  724. *
  725. * \since This function is available since SDL 3.2.0.
  726. */
  727. extern SDL_DECLSPEC void SDLCALL SDL_OnApplicationDidChangeStatusBarOrientation(void);
  728. #endif
  729. /*
  730. * Functions used only by GDK
  731. */
  732. #ifdef SDL_PLATFORM_GDK
  733. typedef struct XTaskQueueObject *XTaskQueueHandle;
  734. typedef struct XUser *XUserHandle;
  735. /**
  736. * Gets a reference to the global async task queue handle for GDK,
  737. * initializing if needed.
  738. *
  739. * Once you are done with the task queue, you should call
  740. * XTaskQueueCloseHandle to reduce the reference count to avoid a resource
  741. * leak.
  742. *
  743. * \param outTaskQueue a pointer to be filled in with task queue handle.
  744. * \returns true on success or false on failure; call SDL_GetError() for more
  745. * information.
  746. *
  747. * \since This function is available since SDL 3.2.0.
  748. */
  749. extern SDL_DECLSPEC bool SDLCALL SDL_GetGDKTaskQueue(XTaskQueueHandle *outTaskQueue);
  750. /**
  751. * Gets a reference to the default user handle for GDK.
  752. *
  753. * This is effectively a synchronous version of XUserAddAsync, which always
  754. * prefers the default user and allows a sign-in UI.
  755. *
  756. * \param outUserHandle a pointer to be filled in with the default user
  757. * handle.
  758. * \returns true if success or false on failure; call SDL_GetError() for more
  759. * information.
  760. *
  761. * \since This function is available since SDL 3.2.0.
  762. */
  763. extern SDL_DECLSPEC bool SDLCALL SDL_GetGDKDefaultUser(XUserHandle *outUserHandle);
  764. #endif
  765. /* Ends C function definitions when using C++ */
  766. #ifdef __cplusplus
  767. }
  768. #endif
  769. #include <SDL3/SDL_close_code.h>
  770. #endif /* SDL_system_h_ */