SDL3pp
A slim C++ wrapper for SDL3
Loading...
Searching...
No Matches
SDL3pp_system.h
1#ifndef SDL3PP_SYSTEM_H_
2#define SDL3PP_SYSTEM_H_
3
4#include <SDL3/SDL_system.h>
5#include "SDL3pp_keyboard.h"
6#include "SDL3pp_stdinc.h"
7#include "SDL3pp_video.h"
8
9namespace SDL {
10
25/*
26 * Platform specific functions for Windows
27 */
28#if defined(SDL_PLATFORM_WINDOWS) || defined(SDL3PP_DOC)
29
31using MSG = ::MSG;
32
54using WindowsMessageHook = bool(SDLCALL*)(void* userdata, MSG* msg);
55
70inline void SetWindowsMessageHook(WindowsMessageHook callback, void* userdata)
71{
72 SDL_SetWindowsMessageHook(callback, userdata);
73}
74
75#endif // SDL_PLATFORM_WINDOWS
76
77#if defined(SDL_PLATFORM_WIN32) || defined(SDL_PLATFORM_WINGDK) || \
78 defined(SDL3PP_DOC)
79
92inline int GetDirect3D9AdapterIndex(Display displayID)
93{
94 return CheckError(SDL_GetDirect3D9AdapterIndex(displayID));
95}
96
111inline void GetDXGIOutputInfo(Display displayID,
112 int* adapterIndex,
113 int* outputIndex)
114{
115 CheckError(SDL_GetDXGIOutputInfo(displayID, adapterIndex, outputIndex));
116}
117
118#endif // defined(SDL_PLATFORM_WIN32) || defined(SDL_PLATFORM_WINGDK)
119
122
143using X11EventHook = bool(SDLCALL*)(void* userdata, XEvent* xevent);
144
156inline void SetX11EventHook(X11EventHook callback, void* userdata)
157{
158 SDL_SetX11EventHook(callback, userdata);
159}
160
161/* Platform specific functions for Linux*/
162#if defined(SDL_PLATFORM_LINUX) || defined(SDL3PP_DOC)
163
175inline void SetLinuxThreadPriority(Sint64 threadID, int priority)
176{
177 CheckError(SDL_SetLinuxThreadPriority(threadID, priority));
178}
179
194 int sdlPriority,
195 int schedPolicy)
196{
198 SDL_SetLinuxThreadPriorityAndPolicy(threadID, sdlPriority, schedPolicy));
199}
200
201#endif // SDL_PLATFORM_LINUX
202
203/*
204 * Platform specific functions for iOS
205 */
206#if defined(SDL_PLATFORM_IOS) || defined(SDL3PP_DOC)
207
223using iOSAnimationCallback = void(SDLCALL*)(void* userdata);
224
261 int interval,
262 iOSAnimationCallback callback,
263 void* callbackParam)
264{
266 SDL_SetiOSAnimationCallback(window, interval, callback, callbackParam));
267}
268
280inline void SetiOSEventPump(bool enabled) { SDL_SetiOSEventPump(enabled); }
281
282#endif // defined(SDL_PLATFORM_IOS)
283
284/*
285 * Platform specific functions for Android
286 */
287#if defined(SDL_PLATFORM_ANDROID) || defined(SDL3PP_DOC)
288
309inline void* GetAndroidJNIEnv() { return SDL_GetAndroidJNIEnv(); }
310
334inline void* GetAndroidActivity() { return SDL_GetAndroidActivity(); }
335
370inline int GetAndroidSDKVersion() { return SDL_GetAndroidSDKVersion(); }
371
379inline bool IsChromebook() { return SDL_IsChromebook(); }
380
388inline bool IsDeXMode() { return SDL_IsDeXMode(); }
389
397inline void SendAndroidBackButton() { SDL_SendAndroidBackButton(); }
398
406 SDL_ANDROID_EXTERNAL_STORAGE_READ;
407
415 SDL_ANDROID_EXTERNAL_STORAGE_WRITE;
416
438{
439 return SDL_GetAndroidInternalStoragePath();
440}
441
458{
459 return SDL_GetAndroidExternalStorageState();
460}
461
486{
487 return CheckError(SDL_GetAndroidExternalStoragePath());
488}
489
511inline const char* GetAndroidCachePath()
512{
513 return CheckError(SDL_GetAndroidCachePath());
514}
515
527using RequestAndroidPermissionCallback = void(SDLCALL*)(void* userdata,
528 const char* permission,
529 bool granted);
530
544 std::function<void(const char* permission, bool granted)>;
545
582 void* userdata)
583{
584 return SDL_RequestAndroidPermission(permission, cb, userdata);
585}
586
622{
624 auto callback = Wrapper::Wrap(std::move(cb));
626 std::move(permission), &Wrapper::CallOnce, callback)) {
627 Wrapper::release(callback);
628 }
629}
630
656inline void ShowAndroidToast(StringParam message,
657 int duration,
658 int gravity,
659 int xoffset,
660 int yoffset)
661{
663 SDL_ShowAndroidToast(message, duration, gravity, xoffset, yoffset));
664}
665
679inline void SendAndroidMessage(Uint32 command, int param)
680{
681 CheckError(SDL_SendAndroidMessage(command, param));
682}
683
684#endif // defined(SDL_PLATFORM_ANDROID)
685
695inline bool IsTablet() { return SDL_IsTablet(); }
696
706inline bool IsTV() { return SDL_IsTV(); }
707
713using Sandbox = SDL_Sandbox;
714
715constexpr Sandbox SANDBOX_NONE = SDL_SANDBOX_NONE;
716
718 SDL_SANDBOX_UNKNOWN_CONTAINER;
719
720constexpr Sandbox SANDBOX_FLATPAK = SDL_SANDBOX_FLATPAK;
721
722constexpr Sandbox SANDBOX_SNAP = SDL_SANDBOX_SNAP;
723
724constexpr Sandbox SANDBOX_MACOS = SDL_SANDBOX_MACOS;
725
734inline Sandbox GetSandbox() { return SDL_GetSandbox(); }
735
750inline void OnApplicationWillTerminate() { SDL_OnApplicationWillTerminate(); }
751
768{
769 SDL_OnApplicationDidReceiveMemoryWarning();
770}
771
788{
789 SDL_OnApplicationWillEnterBackground();
790}
791
808{
809 SDL_OnApplicationDidEnterBackground();
810}
811
828{
829 SDL_OnApplicationWillEnterForeground();
830}
831
848{
849 SDL_OnApplicationDidEnterForeground();
850}
851
852#if defined(SDL_PLATFORM_IOS) || defined(SDL3PP_DOC)
853
870{
871 SDL_OnApplicationDidChangeStatusBarOrientation();
872}
873
874#endif // defined(SDL_PLATFORM_IOS)
875
876#if defined(SDL_PLATFORM_GDK) || defined(SDL3PP_DOC)
877
880
883
896inline void GetGDKTaskQueue(XTaskQueueHandle* outTaskQueue)
897{
898 CheckError(SDL_GetGDKTaskQueue(outTaskQueue));
899}
900
913inline bool GetGDKDefaultUser(XUserHandle* outUserHandle)
914{
915 return SDL_GetGDKDefaultUser(outUserHandle);
916}
917#endif // defined(SDL_PLATFORM_GDK)
918
920
921} // namespace SDL
922
923#endif /* SDL3PP_SYSTEM_H_ */
This is a unique ID for a display for the time it is connected to the system, and is never reused for...
Definition: SDL3pp_video.h:172
Helpers to use C++ strings parameters.
Definition: SDL3pp_strings.h:43
constexpr void CheckError(bool result)
Check and throw if returned value from SDL is an error.
Definition: SDL3pp_error.h:197
::Uint32 Uint32
An unsigned 32-bit integer type.
Definition: SDL3pp_stdinc.h:341
::Sint64 Sint64
A signed 64-bit integer type.
Definition: SDL3pp_stdinc.h:356
bool GetGDKDefaultUser(XUserHandle *outUserHandle)
Gets a reference to the default user handle for GDK.
Definition: SDL3pp_system.h:913
constexpr Sandbox SANDBOX_UNKNOWN_CONTAINER
UNKNOWN_CONTAINER.
Definition: SDL3pp_system.h:717
void SendAndroidBackButton()
Trigger the Android system back button behavior.
Definition: SDL3pp_system.h:397
void SetiOSEventPump(bool enabled)
Use this function to enable or disable the SDL event pump on Apple iOS.
Definition: SDL3pp_system.h:280
Uint32 GetAndroidExternalStorageState()
Get the current state of external storage for this Android application.
Definition: SDL3pp_system.h:457
bool RequestAndroidPermission(StringParam permission, RequestAndroidPermissionCallback cb, void *userdata)
Request permissions at runtime, asynchronously.
Definition: SDL3pp_system.h:580
void OnApplicationDidReceiveMemoryWarning()
Let iOS apps with external event handling report onApplicationDidReceiveMemoryWarning.
Definition: SDL3pp_system.h:767
const char * GetAndroidInternalStoragePath()
Get the path used for internal storage for this Android application.
Definition: SDL3pp_system.h:437
const char * GetAndroidExternalStoragePath()
Get the path used for external storage for this Android application.
Definition: SDL3pp_system.h:485
void * GetAndroidJNIEnv()
Get the Android Java Native Interface Environment of the current thread.
Definition: SDL3pp_system.h:309
void OnApplicationWillTerminate()
Let iOS apps with external event handling report onApplicationWillTerminate.
Definition: SDL3pp_system.h:750
void SetLinuxThreadPriorityAndPolicy(Sint64 threadID, int sdlPriority, int schedPolicy)
Sets the priority (not nice level) and scheduling policy for a thread.
Definition: SDL3pp_system.h:193
void OnApplicationDidEnterBackground()
Let iOS apps with external event handling report onApplicationDidEnterBackground.
Definition: SDL3pp_system.h:807
::MSG MSG
MSG.
Definition: SDL3pp_system.h:31
SDL_Sandbox Sandbox
Application sandbox environment.
Definition: SDL3pp_system.h:713
void SetiOSAnimationCallback(WindowParam window, int interval, iOSAnimationCallback callback, void *callbackParam)
Use this function to set the animation callback on Apple iOS.
Definition: SDL3pp_system.h:260
::XTaskQueueHandle XTaskQueueHandle
XTaskQueueHandle.
Definition: SDL3pp_system.h:879
constexpr Uint32 ANDROID_EXTERNAL_STORAGE_READ
See the official Android developer guide for more information: http://developer.android....
Definition: SDL3pp_system.h:405
void GetDXGIOutputInfo(Display displayID, int *adapterIndex, int *outputIndex)
Get the DXGI Adapter and Output indices for the specified display.
Definition: SDL3pp_system.h:111
Sandbox GetSandbox()
Get the application sandbox environment, if any.
Definition: SDL3pp_system.h:734
void OnApplicationWillEnterBackground()
Let iOS apps with external event handling report onApplicationWillResignActive.
Definition: SDL3pp_system.h:787
const char * GetAndroidCachePath()
Get the path used for caching data for this Android application.
Definition: SDL3pp_system.h:511
constexpr Uint32 ANDROID_EXTERNAL_STORAGE_WRITE
See the official Android developer guide for more information: http://developer.android....
Definition: SDL3pp_system.h:414
void SetWindowsMessageHook(WindowsMessageHook callback, void *userdata)
Set a callback for every Windows message, run before TranslateMessage().
Definition: SDL3pp_system.h:70
void * GetAndroidActivity()
Retrieve the Java instance of the Android activity class.
Definition: SDL3pp_system.h:334
void SendAndroidMessage(Uint32 command, int param)
Send a user command to SDLActivity.
Definition: SDL3pp_system.h:679
bool IsTablet()
Query if the current device is a tablet.
Definition: SDL3pp_system.h:695
int GetAndroidSDKVersion()
Query Android API level of the current device.
Definition: SDL3pp_system.h:370
void OnApplicationDidEnterForeground()
Let iOS apps with external event handling report onApplicationDidBecomeActive.
Definition: SDL3pp_system.h:847
void GetGDKTaskQueue(XTaskQueueHandle *outTaskQueue)
Gets a reference to the global async task queue handle for GDK, initializing if needed.
Definition: SDL3pp_system.h:896
bool IsChromebook()
Query if the application is running on a Chromebook.
Definition: SDL3pp_system.h:379
void(SDLCALL *)(void *userdata, const char *permission, bool granted) RequestAndroidPermissionCallback
Callback that presents a response from a RequestAndroidPermission call.
Definition: SDL3pp_system.h:529
void OnApplicationWillEnterForeground()
Let iOS apps with external event handling report onApplicationWillEnterForeground.
Definition: SDL3pp_system.h:827
void(SDLCALL *)(void *userdata) iOSAnimationCallback
The prototype for an Apple iOS animation callback.
Definition: SDL3pp_system.h:223
bool(SDLCALL *)(void *userdata, MSG *msg) WindowsMessageHook
A callback to be used with SetWindowsMessageHook.
Definition: SDL3pp_system.h:54
::XEvent XEvent
this is defined in Xlib's headers, just need a simple declaration here
Definition: SDL3pp_system.h:121
constexpr Sandbox SANDBOX_MACOS
MACOS.
Definition: SDL3pp_system.h:724
std::function< void(const char *permission, bool granted)> RequestAndroidPermissionCB
Callback that presents a response from a RequestAndroidPermission call.
Definition: SDL3pp_system.h:544
bool(SDLCALL *)(void *userdata, XEvent *xevent) X11EventHook
A callback to be used with SetX11EventHook.
Definition: SDL3pp_system.h:143
void OnApplicationDidChangeStatusBarOrientation()
Let iOS apps with external event handling report onApplicationDidChangeStatusBarOrientation.
Definition: SDL3pp_system.h:869
void ShowAndroidToast(StringParam message, int duration, int gravity, int xoffset, int yoffset)
Shows an Android toast notification.
Definition: SDL3pp_system.h:656
bool IsDeXMode()
Query if the application is running on a Samsung DeX docking station.
Definition: SDL3pp_system.h:388
::XUserHandle XUserHandle
XUserHandle.
Definition: SDL3pp_system.h:882
constexpr Sandbox SANDBOX_SNAP
SNAP.
Definition: SDL3pp_system.h:722
constexpr Sandbox SANDBOX_FLATPAK
FLATPAK.
Definition: SDL3pp_system.h:720
void SetLinuxThreadPriority(Sint64 threadID, int priority)
Sets the UNIX nice value for a thread.
Definition: SDL3pp_system.h:175
int GetDirect3D9AdapterIndex(Display displayID)
Get the D3D9 adapter index that matches the specified display.
Definition: SDL3pp_system.h:92
bool IsTV()
Query if the current device is a TV.
Definition: SDL3pp_system.h:706
constexpr Sandbox SANDBOX_NONE
NONE.
Definition: SDL3pp_system.h:715
void SetX11EventHook(X11EventHook callback, void *userdata)
Set a callback for every X11 event.
Definition: SDL3pp_system.h:156
Main include header for the SDL3pp library.
Definition: SDL3pp_callbackWrapper.h:20
Safely wrap Window for non owning parameters.
Definition: SDL3pp_video.h:54