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
24
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
72inline void SetWindowsMessageHook(WindowsMessageHook callback, void* userdata)
73{
74 SDL_SetWindowsMessageHook(callback, userdata);
75}
76
77#endif // SDL_PLATFORM_WINDOWS
78
79#if defined(SDL_PLATFORM_WIN32) || defined(SDL_PLATFORM_WINGDK) || \
80 defined(SDL3PP_DOC)
81
94inline int GetDirect3D9AdapterIndex(Display displayID)
95{
96 return CheckError(SDL_GetDirect3D9AdapterIndex(displayID));
97}
98
113inline void GetDXGIOutputInfo(Display displayID,
114 int* adapterIndex,
115 int* outputIndex)
116{
117 CheckError(SDL_GetDXGIOutputInfo(displayID, adapterIndex, outputIndex));
118}
119
120#endif // defined(SDL_PLATFORM_WIN32) || defined(SDL_PLATFORM_WINGDK)
121
124
145using X11EventHook = bool(SDLCALL*)(void* userdata, XEvent* xevent);
146
160inline void SetX11EventHook(X11EventHook callback, void* userdata)
161{
162 SDL_SetX11EventHook(callback, userdata);
163}
164
165/* Platform specific functions for Linux*/
166#if defined(SDL_PLATFORM_LINUX) || defined(SDL3PP_DOC)
167
181inline void SetLinuxThreadPriority(Sint64 threadID, int priority)
182{
183 CheckError(SDL_SetLinuxThreadPriority(threadID, priority));
184}
185
202 int sdlPriority,
203 int schedPolicy)
204{
206 SDL_SetLinuxThreadPriorityAndPolicy(threadID, sdlPriority, schedPolicy));
207}
208
209#endif // SDL_PLATFORM_LINUX
210
211/*
212 * Platform specific functions for iOS
213 */
214#if defined(SDL_PLATFORM_IOS) || defined(SDL3PP_DOC)
215
231using iOSAnimationCallback = void(SDLCALL*)(void* userdata);
232
271 int interval,
272 iOSAnimationCallback callback,
273 void* callbackParam)
274{
276 SDL_SetiOSAnimationCallback(window, interval, callback, callbackParam));
277}
278
292inline void SetiOSEventPump(bool enabled) { SDL_SetiOSEventPump(enabled); }
293
294#endif // defined(SDL_PLATFORM_IOS)
295
296/*
297 * Platform specific functions for Android
298 */
299#if defined(SDL_PLATFORM_ANDROID) || defined(SDL3PP_DOC)
300
322inline void* GetAndroidJNIEnv() { return CheckError(SDL_GetAndroidJNIEnv()); }
323
348inline void* GetAndroidActivity()
349{
350 return CheckError(SDL_GetAndroidActivity());
351}
352
389inline int GetAndroidSDKVersion() { return SDL_GetAndroidSDKVersion(); }
390
400inline bool IsChromebook() { return SDL_IsChromebook(); }
401
411inline bool IsDeXMode() { return SDL_IsDeXMode(); }
412
420inline void SendAndroidBackButton() { SDL_SendAndroidBackButton(); }
421
429 SDL_ANDROID_EXTERNAL_STORAGE_READ;
430
438 SDL_ANDROID_EXTERNAL_STORAGE_WRITE;
439
461{
462 return SDL_GetAndroidInternalStoragePath();
463}
464
481{
482 return SDL_GetAndroidExternalStorageState();
483}
484
509{
510 return CheckError(SDL_GetAndroidExternalStoragePath());
511}
512
534inline const char* GetAndroidCachePath()
535{
536 return CheckError(SDL_GetAndroidCachePath());
537}
538
550using RequestAndroidPermissionCallback = void(SDLCALL*)(void* userdata,
551 const char* permission,
552 bool granted);
553
567 std::function<void(const char* permission, bool granted)>;
568
605 void* userdata)
606{
607 return SDL_RequestAndroidPermission(permission, cb, userdata);
608}
609
645{
647 auto callback = Wrapper::Wrap(std::move(cb));
648 if (!RequestAndroidPermission(permission, &Wrapper::CallOnce, callback)) {
649 Wrapper::release(callback);
650 }
651}
652
678inline void ShowAndroidToast(StringParam message,
679 int duration,
680 int gravity,
681 int xoffset,
682 int yoffset)
683{
685 SDL_ShowAndroidToast(message, duration, gravity, xoffset, yoffset));
686}
687
701inline void SendAndroidMessage(Uint32 command, int param)
702{
703 CheckError(SDL_SendAndroidMessage(command, param));
704}
705
706#endif // defined(SDL_PLATFORM_ANDROID)
707
719inline bool IsTablet() { return SDL_IsTablet(); }
720
732inline bool IsTV() { return SDL_IsTV(); }
733
739using Sandbox = SDL_Sandbox;
740
741constexpr Sandbox SANDBOX_NONE = SDL_SANDBOX_NONE;
742
744 SDL_SANDBOX_UNKNOWN_CONTAINER;
745
746constexpr Sandbox SANDBOX_FLATPAK = SDL_SANDBOX_FLATPAK;
747
748constexpr Sandbox SANDBOX_SNAP = SDL_SANDBOX_SNAP;
749
750constexpr Sandbox SANDBOX_MACOS = SDL_SANDBOX_MACOS;
751
760inline Sandbox GetSandbox() { return SDL_GetSandbox(); }
761
776inline void OnApplicationWillTerminate() { SDL_OnApplicationWillTerminate(); }
777
794{
795 SDL_OnApplicationDidReceiveMemoryWarning();
796}
797
814{
815 SDL_OnApplicationWillEnterBackground();
816}
817
834{
835 SDL_OnApplicationDidEnterBackground();
836}
837
854{
855 SDL_OnApplicationWillEnterForeground();
856}
857
874{
875 SDL_OnApplicationDidEnterForeground();
876}
877
878#if defined(SDL_PLATFORM_IOS) || defined(SDL3PP_DOC)
879
896{
897 SDL_OnApplicationDidChangeStatusBarOrientation();
898}
899
900#endif // defined(SDL_PLATFORM_IOS)
901
902#if defined(SDL_PLATFORM_GDK) || defined(SDL3PP_DOC)
903
906
909
922inline void GetGDKTaskQueue(XTaskQueueHandle* outTaskQueue)
923{
924 CheckError(SDL_GetGDKTaskQueue(outTaskQueue));
925}
926
939inline bool GetGDKDefaultUser(XUserHandle* outUserHandle)
940{
941 return SDL_GetGDKDefaultUser(outUserHandle);
942}
943#endif // defined(SDL_PLATFORM_GDK)
944
946
947} // namespace SDL
948
949#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:142
Helpers to use C++ strings parameters.
Definition SDL3pp_strings.h:58
constexpr void CheckError(bool result)
Check and throw if returned value from SDL is an error.
Definition SDL3pp_error.h:199
::Sint64 Sint64
A signed 64-bit integer type.
Definition SDL3pp_stdinc.h:311
::Uint32 Uint32
An unsigned 32-bit integer type.
Definition SDL3pp_stdinc.h:296
bool GetGDKDefaultUser(XUserHandle *outUserHandle)
Gets a reference to the default user handle for GDK.
Definition SDL3pp_system.h:939
constexpr Sandbox SANDBOX_UNKNOWN_CONTAINER
UNKNOWN_CONTAINER.
Definition SDL3pp_system.h:743
void SendAndroidBackButton()
Trigger the Android system back button behavior.
Definition SDL3pp_system.h:420
void SetiOSEventPump(bool enabled)
Use this function to enable or disable the SDL event pump on Apple iOS.
Definition SDL3pp_system.h:292
Uint32 GetAndroidExternalStorageState()
Get the current state of external storage for this Android application.
Definition SDL3pp_system.h:480
bool RequestAndroidPermission(StringParam permission, RequestAndroidPermissionCallback cb, void *userdata)
Request permissions at runtime, asynchronously.
Definition SDL3pp_system.h:603
void OnApplicationDidReceiveMemoryWarning()
Let iOS apps with external event handling report onApplicationDidReceiveMemoryWarning.
Definition SDL3pp_system.h:793
const char * GetAndroidInternalStoragePath()
Get the path used for internal storage for this Android application.
Definition SDL3pp_system.h:460
const char * GetAndroidExternalStoragePath()
Get the path used for external storage for this Android application.
Definition SDL3pp_system.h:508
void * GetAndroidJNIEnv()
Get the Android Java Native Interface Environment of the current thread.
Definition SDL3pp_system.h:322
void OnApplicationWillTerminate()
Let iOS apps with external event handling report onApplicationWillTerminate.
Definition SDL3pp_system.h:776
void SetLinuxThreadPriorityAndPolicy(Sint64 threadID, int sdlPriority, int schedPolicy)
Sets the priority (not nice level) and scheduling policy for a thread.
Definition SDL3pp_system.h:201
::XEvent XEvent
this is defined in Xlib's headers, just need a simple declaration here
Definition SDL3pp_system.h:123
void OnApplicationDidEnterBackground()
Let iOS apps with external event handling report onApplicationDidEnterBackground.
Definition SDL3pp_system.h:833
SDL_Sandbox Sandbox
Application sandbox environment.
Definition SDL3pp_system.h:739
constexpr Uint32 ANDROID_EXTERNAL_STORAGE_READ
See the official Android developer guide for more information: http://developer.android....
Definition SDL3pp_system.h:428
::MSG MSG
MSG.
Definition SDL3pp_system.h:31
void GetDXGIOutputInfo(Display displayID, int *adapterIndex, int *outputIndex)
Get the DXGI Adapter and Output indices for the specified display.
Definition SDL3pp_system.h:113
Sandbox GetSandbox()
Get the application sandbox environment, if any.
Definition SDL3pp_system.h:760
void OnApplicationWillEnterBackground()
Let iOS apps with external event handling report onApplicationWillResignActive.
Definition SDL3pp_system.h:813
const char * GetAndroidCachePath()
Get the path used for caching data for this Android application.
Definition SDL3pp_system.h:534
constexpr Uint32 ANDROID_EXTERNAL_STORAGE_WRITE
See the official Android developer guide for more information: http://developer.android....
Definition SDL3pp_system.h:437
void(SDLCALL *)(void *userdata, const char *permission, bool granted) RequestAndroidPermissionCallback
Callback that presents a response from a RequestAndroidPermission call.
Definition SDL3pp_system.h:550
void SetWindowsMessageHook(WindowsMessageHook callback, void *userdata)
Set a callback for every Windows message, run before TranslateMessage().
Definition SDL3pp_system.h:72
void * GetAndroidActivity()
Retrieve the Java instance of the Android activity class.
Definition SDL3pp_system.h:348
void SendAndroidMessage(Uint32 command, int param)
Send a user command to SDLActivity.
Definition SDL3pp_system.h:701
bool IsTablet()
Query if the current device is a tablet.
Definition SDL3pp_system.h:719
int GetAndroidSDKVersion()
Query Android API level of the current device.
Definition SDL3pp_system.h:389
void OnApplicationDidEnterForeground()
Let iOS apps with external event handling report onApplicationDidBecomeActive.
Definition SDL3pp_system.h:873
void GetGDKTaskQueue(XTaskQueueHandle *outTaskQueue)
Gets a reference to the global async task queue handle for GDK, initializing if needed.
Definition SDL3pp_system.h:922
bool IsChromebook()
Query if the application is running on a Chromebook.
Definition SDL3pp_system.h:400
void OnApplicationWillEnterForeground()
Let iOS apps with external event handling report onApplicationWillEnterForeground.
Definition SDL3pp_system.h:853
constexpr Sandbox SANDBOX_MACOS
MACOS.
Definition SDL3pp_system.h:750
::XUserHandle XUserHandle
XUserHandle.
Definition SDL3pp_system.h:908
void SetiOSAnimationCallback(WindowRef window, int interval, iOSAnimationCallback callback, void *callbackParam)
Use this function to set the animation callback on Apple iOS.
Definition SDL3pp_system.h:270
void(SDLCALL *)(void *userdata) iOSAnimationCallback
The prototype for an Apple iOS animation callback.
Definition SDL3pp_system.h:231
void OnApplicationDidChangeStatusBarOrientation()
Let iOS apps with external event handling report onApplicationDidChangeStatusBarOrientation.
Definition SDL3pp_system.h:895
void ShowAndroidToast(StringParam message, int duration, int gravity, int xoffset, int yoffset)
Shows an Android toast notification.
Definition SDL3pp_system.h:678
bool IsDeXMode()
Query if the application is running on a Samsung DeX docking station.
Definition SDL3pp_system.h:411
constexpr Sandbox SANDBOX_SNAP
SNAP.
Definition SDL3pp_system.h:748
constexpr Sandbox SANDBOX_FLATPAK
FLATPAK.
Definition SDL3pp_system.h:746
std::function< void(const char *permission, bool granted)> RequestAndroidPermissionCB
Callback that presents a response from a RequestAndroidPermission call.
Definition SDL3pp_system.h:566
bool(SDLCALL *)(void *userdata, MSG *msg) WindowsMessageHook
A callback to be used with SetWindowsMessageHook.
Definition SDL3pp_system.h:54
void SetLinuxThreadPriority(Sint64 threadID, int priority)
Sets the UNIX nice value for a thread.
Definition SDL3pp_system.h:181
int GetDirect3D9AdapterIndex(Display displayID)
Get the D3D9 adapter index that matches the specified display.
Definition SDL3pp_system.h:94
::XTaskQueueHandle XTaskQueueHandle
XTaskQueueHandle.
Definition SDL3pp_system.h:905
bool(SDLCALL *)(void *userdata, XEvent *xevent) X11EventHook
A callback to be used with SetX11EventHook.
Definition SDL3pp_system.h:145
bool IsTV()
Query if the current device is a TV.
Definition SDL3pp_system.h:732
constexpr Sandbox SANDBOX_NONE
NONE.
Definition SDL3pp_system.h:741
void SetX11EventHook(X11EventHook callback, void *userdata)
Set a callback for every X11 event.
Definition SDL3pp_system.h:160
ResourceRefT< WindowBase > WindowRef
Reference for Window.
Definition SDL3pp_video.h:57
Main include header for the SDL3pp library.
Definition SDL3pp_callbackWrapper.h:20