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)
51using WindowsMessageHook = SDL_WindowsMessageHook;
52
76using WindowsMessageHookCB = std::function<bool(MSG* msg)>;
77
92inline void SetWindowsMessageHook(WindowsMessageHook callback, void* userdata)
93{
94 SDL_SetWindowsMessageHook(callback, userdata);
95}
96
111{
113 SetWindowsMessageHook(&Wrapper::CallSuffixed,
114 Wrapper::Wrap(std::move(callback)));
115}
116#endif // SDL_PLATFORM_WINDOWS
117
118#if defined(SDL_PLATFORM_WIN32) || defined(SDL_PLATFORM_WINGDK) || \
119 defined(SDL3PP_DOC)
133{
134 return CheckError(SDL_GetDirect3D9AdapterIndex(displayID));
135}
136
151inline void GetDXGIOutputInfo(Display displayID,
152 int* adapterIndex,
153 int* outputIndex)
154{
155 CheckError(SDL_GetDXGIOutputInfo(displayID, adapterIndex, outputIndex));
156}
157
158#endif // defined(SDL_PLATFORM_WIN32) || defined(SDL_PLATFORM_WINGDK)
159
180using X11EventHook = SDL_X11EventHook;
181
203using X11EventHookCB = std::function<bool(XEvent*)>;
204
216inline void SetX11EventHook(X11EventHook callback, void* userdata)
217{
218 SDL_SetX11EventHook(callback, userdata);
219}
220
231inline void SetX11EventHook(X11EventHookCB callback)
232{
234 SDL_SetX11EventHook(&Wrapper::Call, Wrapper::Wrap(std::move(callback)));
235}
236
237/* Platform specific functions for Linux*/
238#if defined(SDL_PLATFORM_LINUX) || defined(SDL3PP_DOC)
239
251inline void SetLinuxThreadPriority(Sint64 threadID, int priority)
252{
253 CheckError(SDL_SetLinuxThreadPriority(threadID, priority));
254}
255
270 int sdlPriority,
271 int schedPolicy)
272{
274 SDL_SetLinuxThreadPriorityAndPolicy(threadID, sdlPriority, schedPolicy));
275}
276
277#endif // SDL_PLATFORM_LINUX
278
279/*
280 * Platform specific functions for iOS
281 */
282#if defined(SDL_PLATFORM_IOS) || defined(SDL3PP_DOC)
283
300using iOSAnimationCallback = SDL_iOSAnimationCallback;
301
319using iOSAnimationCB = std::function<void()>;
320
358 int interval,
359 iOSAnimationCallback callback,
360 void* callbackParam)
361{
363 SDL_SetiOSAnimationCallback(window, interval, callback, callbackParam));
364}
365
402 int interval,
403 iOSAnimationCB callback)
404{
406 SetiOSAnimationCallback(&Wrapper::Call, Wrapper::Wrap(std::move(callback)));
407}
408
420inline void SetiOSEventPump(bool enabled) { SDL_SetiOSEventPump(enabled); }
421
422#endif // defined(SDL_PLATFORM_IOS)
423
424/*
425 * Platform specific functions for Android
426 */
427#if defined(SDL_PLATFORM_ANDROID) || defined(SDL3PP_DOC)
428
449inline void* GetAndroidJNIEnv() { return SDL_GetAndroidJNIEnv(); }
450
474inline void* GetAndroidActivity() { return SDL_GetAndroidActivity(); }
475
510inline int GetAndroidSDKVersion() { return SDL_GetAndroidSDKVersion(); }
511
519inline bool IsChromebook() { return SDL_IsChromebook(); }
520
528inline bool IsDeXMode() { return SDL_IsDeXMode(); }
529
537inline void SendAndroidBackButton() { SDL_SendAndroidBackButton(); }
538
546 SDL_ANDROID_EXTERNAL_STORAGE_READ;
547
555 SDL_ANDROID_EXTERNAL_STORAGE_WRITE;
556
579{
580 return SDL_GetAndroidInternalStoragePath();
581}
582
599{
600 return SDL_GetAndroidExternalStorageState();
601}
602
626{
627 return CheckError(SDL_GetAndroidExternalStoragePath());
628}
629
650inline const char* GetAndroidCachePath()
651{
652 return CheckError(SDL_GetAndroidCachePath());
653}
654
666using RequestAndroidPermissionCallback = SDL_RequestAndroidPermissionCallback;
667
681 std::function<void(const char* permission, bool granted)>;
682
719 void* userdata)
720{
721 return SDL_RequestAndroidPermission(permission, cb, userdata);
722}
723
759{
761 auto callback = Wrapper::Wrap(std::move(cb));
763 std::move(permission), &Wrapper::CallOnce, callback)) {
764 Wrapper::release(callback);
765 }
766}
767
793inline void ShowAndroidToast(StringParam message,
794 int duration,
795 int gravity,
796 int xoffset,
797 int yoffset)
798{
800 SDL_ShowAndroidToast(message, duration, gravity, xoffset, yoffset));
801}
802
816inline void SendAndroidMessage(Uint32 command, int param)
817{
818 CheckError(SDL_SendAndroidMessage(command, param));
819}
820
821#endif // defined(SDL_PLATFORM_ANDROID)
822
832inline bool IsTablet() { return SDL_IsTablet(); }
833
843inline bool IsTV() { return SDL_IsTV(); }
844
850using Sandbox = SDL_Sandbox;
851
852constexpr Sandbox SANDBOX_NONE = SDL_SANDBOX_NONE;
853
855 SDL_SANDBOX_UNKNOWN_CONTAINER;
856
857constexpr Sandbox SANDBOX_FLATPAK = SDL_SANDBOX_FLATPAK;
858
859constexpr Sandbox SANDBOX_SNAP = SDL_SANDBOX_SNAP;
860
861constexpr Sandbox SANDBOX_MACOS = SDL_SANDBOX_MACOS;
862
871inline Sandbox GetSandbox() { return SDL_GetSandbox(); }
872
888inline void OnApplicationWillTerminate() { SDL_OnApplicationWillTerminate(); }
889
906{
907 SDL_OnApplicationDidReceiveMemoryWarning();
908}
909
926{
927 SDL_OnApplicationWillEnterBackground();
928}
929
946{
947 SDL_OnApplicationDidEnterBackground();
948}
949
966{
967 SDL_OnApplicationWillEnterForeground();
968}
969
986{
987 SDL_OnApplicationDidEnterForeground();
988}
989
990#if defined(SDL_PLATFORM_IOS) || defined(SDL3PP_DOC)
991
1008{
1009 SDL_OnApplicationDidChangeStatusBarOrientation();
1010}
1011
1012#endif // defined(SDL_PLATFORM_IOS)
1013
1014#if defined(SDL_PLATFORM_GDK) || defined(SDL3PP_DOC)
1015
1029inline void GetGDKTaskQueue(XTaskQueueHandle* outTaskQueue)
1030{
1031 CheckError(SDL_GetGDKTaskQueue(outTaskQueue));
1032}
1033
1047inline bool GetGDKDefaultUser(XUserHandle* outUserHandle)
1048{
1049 return SDL_GetGDKDefaultUser(outUserHandle);
1050}
1051#endif // defined(SDL_PLATFORM_GDK)
1052
1054
1055} // namespace SDL
1056
1057#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:175
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:198
Sint64 Sint64
A signed 64-bit integer type.
Definition: SDL3pp_stdinc.h:347
Uint32 Uint32
An unsigned 32-bit integer type.
Definition: SDL3pp_stdinc.h:328
bool GetGDKDefaultUser(XUserHandle *outUserHandle)
Gets a reference to the default user handle for GDK.
Definition: SDL3pp_system.h:1047
constexpr Sandbox SANDBOX_UNKNOWN_CONTAINER
UNKNOWN_CONTAINER.
Definition: SDL3pp_system.h:854
void SendAndroidBackButton()
Trigger the Android system back button behavior.
Definition: SDL3pp_system.h:537
void SetiOSEventPump(bool enabled)
Use this function to enable or disable the SDL event pump on Apple iOS.
Definition: SDL3pp_system.h:420
Uint32 GetAndroidExternalStorageState()
Get the current state of external storage for this Android application.
Definition: SDL3pp_system.h:598
bool RequestAndroidPermission(StringParam permission, RequestAndroidPermissionCallback cb, void *userdata)
Request permissions at runtime, asynchronously.
Definition: SDL3pp_system.h:717
void OnApplicationDidReceiveMemoryWarning()
Let iOS apps with external event handling report onApplicationDidReceiveMemoryWarning.
Definition: SDL3pp_system.h:905
const char * GetAndroidInternalStoragePath()
Get the path used for internal storage for this Android application.
Definition: SDL3pp_system.h:578
const char * GetAndroidExternalStoragePath()
Get the path used for external storage for this Android application.
Definition: SDL3pp_system.h:625
void * GetAndroidJNIEnv()
Get the Android Java Native Interface Environment of the current thread.
Definition: SDL3pp_system.h:449
void OnApplicationWillTerminate()
Let iOS apps with external event handling report onApplicationWillTerminate.
Definition: SDL3pp_system.h:888
void SetLinuxThreadPriorityAndPolicy(Sint64 threadID, int sdlPriority, int schedPolicy)
Sets the priority (not nice level) and scheduling policy for a thread.
Definition: SDL3pp_system.h:269
void OnApplicationDidEnterBackground()
Let iOS apps with external event handling report onApplicationDidEnterBackground.
Definition: SDL3pp_system.h:945
SDL_Sandbox Sandbox
Application sandbox environment.
Definition: SDL3pp_system.h:850
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:357
constexpr Uint32 ANDROID_EXTERNAL_STORAGE_READ
See the official Android developer guide for more information: http://developer.android....
Definition: SDL3pp_system.h:545
void GetDXGIOutputInfo(Display displayID, int *adapterIndex, int *outputIndex)
Get the DXGI Adapter and Output indices for the specified display.
Definition: SDL3pp_system.h:151
Sandbox GetSandbox()
Get the application sandbox environment, if any.
Definition: SDL3pp_system.h:871
void OnApplicationWillEnterBackground()
Let iOS apps with external event handling report onApplicationWillResignActive.
Definition: SDL3pp_system.h:925
const char * GetAndroidCachePath()
Get the path used for caching data for this Android application.
Definition: SDL3pp_system.h:650
std::function< bool(MSG *msg)> WindowsMessageHookCB
A callback to be used with SetWindowsMessageHook.
Definition: SDL3pp_system.h:76
constexpr Uint32 ANDROID_EXTERNAL_STORAGE_WRITE
See the official Android developer guide for more information: http://developer.android....
Definition: SDL3pp_system.h:554
void SetWindowsMessageHook(WindowsMessageHook callback, void *userdata)
Set a callback for every Windows message, run before TranslateMessage().
Definition: SDL3pp_system.h:92
void * GetAndroidActivity()
Retrieve the Java instance of the Android activity class.
Definition: SDL3pp_system.h:474
void SendAndroidMessage(Uint32 command, int param)
Send a user command to SDLActivity.
Definition: SDL3pp_system.h:816
bool IsTablet()
Query if the current device is a tablet.
Definition: SDL3pp_system.h:832
SDL_RequestAndroidPermissionCallback RequestAndroidPermissionCallback
Callback that presents a response from a RequestAndroidPermission call.
Definition: SDL3pp_system.h:666
int GetAndroidSDKVersion()
Query Android API level of the current device.
Definition: SDL3pp_system.h:510
void OnApplicationDidEnterForeground()
Let iOS apps with external event handling report onApplicationDidBecomeActive.
Definition: SDL3pp_system.h:985
void GetGDKTaskQueue(XTaskQueueHandle *outTaskQueue)
Gets a reference to the global async task queue handle for GDK, initializing if needed.
Definition: SDL3pp_system.h:1029
bool IsChromebook()
Query if the application is running on a Chromebook.
Definition: SDL3pp_system.h:519
void OnApplicationWillEnterForeground()
Let iOS apps with external event handling report onApplicationWillEnterForeground.
Definition: SDL3pp_system.h:965
std::function< void()> iOSAnimationCB
The prototype for an Apple iOS animation callback.
Definition: SDL3pp_system.h:319
SDL_X11EventHook X11EventHook
A callback to be used with SetX11EventHook.
Definition: SDL3pp_system.h:180
constexpr Sandbox SANDBOX_MACOS
MACOS.
Definition: SDL3pp_system.h:861
std::function< void(const char *permission, bool granted)> RequestAndroidPermissionCB
Callback that presents a response from a RequestAndroidPermission call.
Definition: SDL3pp_system.h:681
SDL_WindowsMessageHook WindowsMessageHook
A callback to be used with SetWindowsMessageHook.
Definition: SDL3pp_system.h:51
void OnApplicationDidChangeStatusBarOrientation()
Let iOS apps with external event handling report onApplicationDidChangeStatusBarOrientation.
Definition: SDL3pp_system.h:1007
void ShowAndroidToast(StringParam message, int duration, int gravity, int xoffset, int yoffset)
Shows an Android toast notification.
Definition: SDL3pp_system.h:793
bool IsDeXMode()
Query if the application is running on a Samsung DeX docking station.
Definition: SDL3pp_system.h:528
constexpr Sandbox SANDBOX_SNAP
SNAP.
Definition: SDL3pp_system.h:859
constexpr Sandbox SANDBOX_FLATPAK
FLATPAK.
Definition: SDL3pp_system.h:857
std::function< bool(XEvent *)> X11EventHookCB
A callback to be used with SetX11EventHook.
Definition: SDL3pp_system.h:203
void SetLinuxThreadPriority(Sint64 threadID, int priority)
Sets the UNIX nice value for a thread.
Definition: SDL3pp_system.h:251
int GetDirect3D9AdapterIndex(Display displayID)
Get the D3D9 adapter index that matches the specified display.
Definition: SDL3pp_system.h:132
bool IsTV()
Query if the current device is a TV.
Definition: SDL3pp_system.h:843
SDL_iOSAnimationCallback iOSAnimationCallback
The prototype for an Apple iOS animation callback.
Definition: SDL3pp_system.h:300
constexpr Sandbox SANDBOX_NONE
NONE.
Definition: SDL3pp_system.h:852
void SetX11EventHook(X11EventHook callback, void *userdata)
Set a callback for every X11 event.
Definition: SDL3pp_system.h:216
Main include header for the SDL3pp library.
Definition: SDL3pp_callbackWrapper.h:66
Stored Wrapper unique by type result callbacks.
Definition: SDL3pp_callbackWrapper.h:242
Safely wrap Window for non owning parameters.
Definition: SDL3pp_video.h:57