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 = SDL_WindowsMessageHook;
55
77using WindowsMessageHookCB = std::function<bool(MSG* msg)>;
78
93inline void SetWindowsMessageHook(WindowsMessageHook callback, void* userdata)
94{
95 SDL_SetWindowsMessageHook(callback, userdata);
96}
97
112{
114 SetWindowsMessageHook(&Wrapper::CallSuffixed,
115 Wrapper::Wrap(std::move(callback)));
116}
117#endif // SDL_PLATFORM_WINDOWS
118
119#if defined(SDL_PLATFORM_WIN32) || defined(SDL_PLATFORM_WINGDK) || \
120 defined(SDL3PP_DOC)
134{
135 return CheckError(SDL_GetDirect3D9AdapterIndex(displayID));
136}
137
152inline void GetDXGIOutputInfo(Display displayID,
153 int* adapterIndex,
154 int* outputIndex)
155{
156 CheckError(SDL_GetDXGIOutputInfo(displayID, adapterIndex, outputIndex));
157}
158
159#endif // defined(SDL_PLATFORM_WIN32) || defined(SDL_PLATFORM_WINGDK)
160
163
184using X11EventHook = SDL_X11EventHook;
185
207using X11EventHookCB = std::function<bool(XEvent*)>;
208
220inline void SetX11EventHook(X11EventHook callback, void* userdata)
221{
222 SDL_SetX11EventHook(callback, userdata);
223}
224
235inline void SetX11EventHook(X11EventHookCB callback)
236{
238 SDL_SetX11EventHook(&Wrapper::Call, Wrapper::Wrap(std::move(callback)));
239}
240
241/* Platform specific functions for Linux*/
242#if defined(SDL_PLATFORM_LINUX) || defined(SDL3PP_DOC)
243
255inline void SetLinuxThreadPriority(Sint64 threadID, int priority)
256{
257 CheckError(SDL_SetLinuxThreadPriority(threadID, priority));
258}
259
274 int sdlPriority,
275 int schedPolicy)
276{
278 SDL_SetLinuxThreadPriorityAndPolicy(threadID, sdlPriority, schedPolicy));
279}
280
281#endif // SDL_PLATFORM_LINUX
282
283/*
284 * Platform specific functions for iOS
285 */
286#if defined(SDL_PLATFORM_IOS) || defined(SDL3PP_DOC)
287
303using iOSAnimationCallback = SDL_iOSAnimationCallback;
304
319using iOSAnimationCB = std::function<void()>;
320
357 int interval,
358 iOSAnimationCallback callback,
359 void* callbackParam)
360{
362 SDL_SetiOSAnimationCallback(window, interval, callback, callbackParam));
363}
364
400 int interval,
401 iOSAnimationCB callback)
402{
404 SetiOSAnimationCallback(&Wrapper::Call, Wrapper::Wrap(std::move(callback)));
405}
406
418inline void SetiOSEventPump(bool enabled) { SDL_SetiOSEventPump(enabled); }
419
420#endif // defined(SDL_PLATFORM_IOS)
421
422/*
423 * Platform specific functions for Android
424 */
425#if defined(SDL_PLATFORM_ANDROID) || defined(SDL3PP_DOC)
426
447inline void* GetAndroidJNIEnv() { return SDL_GetAndroidJNIEnv(); }
448
472inline void* GetAndroidActivity() { return SDL_GetAndroidActivity(); }
473
508inline int GetAndroidSDKVersion() { return SDL_GetAndroidSDKVersion(); }
509
517inline bool IsChromebook() { return SDL_IsChromebook(); }
518
526inline bool IsDeXMode() { return SDL_IsDeXMode(); }
527
535inline void SendAndroidBackButton() { SDL_SendAndroidBackButton(); }
536
544 SDL_ANDROID_EXTERNAL_STORAGE_READ;
545
553 SDL_ANDROID_EXTERNAL_STORAGE_WRITE;
554
576{
577 return SDL_GetAndroidInternalStoragePath();
578}
579
596{
597 return SDL_GetAndroidExternalStorageState();
598}
599
624{
625 return CheckError(SDL_GetAndroidExternalStoragePath());
626}
627
649inline const char* GetAndroidCachePath()
650{
651 return CheckError(SDL_GetAndroidCachePath());
652}
653
665using RequestAndroidPermissionCallback = SDL_RequestAndroidPermissionCallback;
666
680 std::function<void(const char* permission, bool granted)>;
681
718 void* userdata)
719{
720 return SDL_RequestAndroidPermission(permission, cb, userdata);
721}
722
758{
760 auto callback = Wrapper::Wrap(std::move(cb));
762 std::move(permission), &Wrapper::CallOnce, callback)) {
763 Wrapper::release(callback);
764 }
765}
766
792inline void ShowAndroidToast(StringParam message,
793 int duration,
794 int gravity,
795 int xoffset,
796 int yoffset)
797{
799 SDL_ShowAndroidToast(message, duration, gravity, xoffset, yoffset));
800}
801
815inline void SendAndroidMessage(Uint32 command, int param)
816{
817 CheckError(SDL_SendAndroidMessage(command, param));
818}
819
820#endif // defined(SDL_PLATFORM_ANDROID)
821
831inline bool IsTablet() { return SDL_IsTablet(); }
832
842inline bool IsTV() { return SDL_IsTV(); }
843
849using Sandbox = SDL_Sandbox;
850
851constexpr Sandbox SANDBOX_NONE = SDL_SANDBOX_NONE;
852
854 SDL_SANDBOX_UNKNOWN_CONTAINER;
855
856constexpr Sandbox SANDBOX_FLATPAK = SDL_SANDBOX_FLATPAK;
857
858constexpr Sandbox SANDBOX_SNAP = SDL_SANDBOX_SNAP;
859
860constexpr Sandbox SANDBOX_MACOS = SDL_SANDBOX_MACOS;
861
870inline Sandbox GetSandbox() { return SDL_GetSandbox(); }
871
886inline void OnApplicationWillTerminate() { SDL_OnApplicationWillTerminate(); }
887
904{
905 SDL_OnApplicationDidReceiveMemoryWarning();
906}
907
924{
925 SDL_OnApplicationWillEnterBackground();
926}
927
944{
945 SDL_OnApplicationDidEnterBackground();
946}
947
964{
965 SDL_OnApplicationWillEnterForeground();
966}
967
984{
985 SDL_OnApplicationDidEnterForeground();
986}
987
988#if defined(SDL_PLATFORM_IOS) || defined(SDL3PP_DOC)
989
1006{
1007 SDL_OnApplicationDidChangeStatusBarOrientation();
1008}
1009
1010#endif // defined(SDL_PLATFORM_IOS)
1011
1012#if defined(SDL_PLATFORM_GDK) || defined(SDL3PP_DOC)
1013
1016
1019
1032inline void GetGDKTaskQueue(XTaskQueueHandle* outTaskQueue)
1033{
1034 CheckError(SDL_GetGDKTaskQueue(outTaskQueue));
1035}
1036
1049inline bool GetGDKDefaultUser(XUserHandle* outUserHandle)
1050{
1051 return SDL_GetGDKDefaultUser(outUserHandle);
1052}
1053#endif // defined(SDL_PLATFORM_GDK)
1054
1056
1057} // namespace SDL
1058
1059#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:1049
constexpr Sandbox SANDBOX_UNKNOWN_CONTAINER
UNKNOWN_CONTAINER.
Definition: SDL3pp_system.h:853
void SendAndroidBackButton()
Trigger the Android system back button behavior.
Definition: SDL3pp_system.h:535
void SetiOSEventPump(bool enabled)
Use this function to enable or disable the SDL event pump on Apple iOS.
Definition: SDL3pp_system.h:418
Uint32 GetAndroidExternalStorageState()
Get the current state of external storage for this Android application.
Definition: SDL3pp_system.h:595
bool RequestAndroidPermission(StringParam permission, RequestAndroidPermissionCallback cb, void *userdata)
Request permissions at runtime, asynchronously.
Definition: SDL3pp_system.h:716
void OnApplicationDidReceiveMemoryWarning()
Let iOS apps with external event handling report onApplicationDidReceiveMemoryWarning.
Definition: SDL3pp_system.h:903
const char * GetAndroidInternalStoragePath()
Get the path used for internal storage for this Android application.
Definition: SDL3pp_system.h:575
const char * GetAndroidExternalStoragePath()
Get the path used for external storage for this Android application.
Definition: SDL3pp_system.h:623
void * GetAndroidJNIEnv()
Get the Android Java Native Interface Environment of the current thread.
Definition: SDL3pp_system.h:447
void OnApplicationWillTerminate()
Let iOS apps with external event handling report onApplicationWillTerminate.
Definition: SDL3pp_system.h:886
void SetLinuxThreadPriorityAndPolicy(Sint64 threadID, int sdlPriority, int schedPolicy)
Sets the priority (not nice level) and scheduling policy for a thread.
Definition: SDL3pp_system.h:273
void OnApplicationDidEnterBackground()
Let iOS apps with external event handling report onApplicationDidEnterBackground.
Definition: SDL3pp_system.h:943
::MSG MSG
MSG.
Definition: SDL3pp_system.h:31
SDL_Sandbox Sandbox
Application sandbox environment.
Definition: SDL3pp_system.h:849
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:356
::XTaskQueueHandle XTaskQueueHandle
XTaskQueueHandle.
Definition: SDL3pp_system.h:1015
constexpr Uint32 ANDROID_EXTERNAL_STORAGE_READ
See the official Android developer guide for more information: http://developer.android....
Definition: SDL3pp_system.h:543
void GetDXGIOutputInfo(Display displayID, int *adapterIndex, int *outputIndex)
Get the DXGI Adapter and Output indices for the specified display.
Definition: SDL3pp_system.h:152
Sandbox GetSandbox()
Get the application sandbox environment, if any.
Definition: SDL3pp_system.h:870
void OnApplicationWillEnterBackground()
Let iOS apps with external event handling report onApplicationWillResignActive.
Definition: SDL3pp_system.h:923
const char * GetAndroidCachePath()
Get the path used for caching data for this Android application.
Definition: SDL3pp_system.h:649
std::function< bool(MSG *msg)> WindowsMessageHookCB
A callback to be used with SetWindowsMessageHook.
Definition: SDL3pp_system.h:77
constexpr Uint32 ANDROID_EXTERNAL_STORAGE_WRITE
See the official Android developer guide for more information: http://developer.android....
Definition: SDL3pp_system.h:552
void SetWindowsMessageHook(WindowsMessageHook callback, void *userdata)
Set a callback for every Windows message, run before TranslateMessage().
Definition: SDL3pp_system.h:93
void * GetAndroidActivity()
Retrieve the Java instance of the Android activity class.
Definition: SDL3pp_system.h:472
void SendAndroidMessage(Uint32 command, int param)
Send a user command to SDLActivity.
Definition: SDL3pp_system.h:815
bool IsTablet()
Query if the current device is a tablet.
Definition: SDL3pp_system.h:831
SDL_RequestAndroidPermissionCallback RequestAndroidPermissionCallback
Callback that presents a response from a RequestAndroidPermission call.
Definition: SDL3pp_system.h:665
int GetAndroidSDKVersion()
Query Android API level of the current device.
Definition: SDL3pp_system.h:508
void OnApplicationDidEnterForeground()
Let iOS apps with external event handling report onApplicationDidBecomeActive.
Definition: SDL3pp_system.h:983
void GetGDKTaskQueue(XTaskQueueHandle *outTaskQueue)
Gets a reference to the global async task queue handle for GDK, initializing if needed.
Definition: SDL3pp_system.h:1032
bool IsChromebook()
Query if the application is running on a Chromebook.
Definition: SDL3pp_system.h:517
void OnApplicationWillEnterForeground()
Let iOS apps with external event handling report onApplicationWillEnterForeground.
Definition: SDL3pp_system.h:963
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:184
::XEvent XEvent
this is defined in Xlib's headers, just need a simple declaration here
Definition: SDL3pp_system.h:162
constexpr Sandbox SANDBOX_MACOS
MACOS.
Definition: SDL3pp_system.h:860
std::function< void(const char *permission, bool granted)> RequestAndroidPermissionCB
Callback that presents a response from a RequestAndroidPermission call.
Definition: SDL3pp_system.h:680
SDL_WindowsMessageHook WindowsMessageHook
A callback to be used with SetWindowsMessageHook.
Definition: SDL3pp_system.h:54
void OnApplicationDidChangeStatusBarOrientation()
Let iOS apps with external event handling report onApplicationDidChangeStatusBarOrientation.
Definition: SDL3pp_system.h:1005
void ShowAndroidToast(StringParam message, int duration, int gravity, int xoffset, int yoffset)
Shows an Android toast notification.
Definition: SDL3pp_system.h:792
bool IsDeXMode()
Query if the application is running on a Samsung DeX docking station.
Definition: SDL3pp_system.h:526
::XUserHandle XUserHandle
XUserHandle.
Definition: SDL3pp_system.h:1018
constexpr Sandbox SANDBOX_SNAP
SNAP.
Definition: SDL3pp_system.h:858
constexpr Sandbox SANDBOX_FLATPAK
FLATPAK.
Definition: SDL3pp_system.h:856
std::function< bool(XEvent *)> X11EventHookCB
A callback to be used with SetX11EventHook.
Definition: SDL3pp_system.h:207
void SetLinuxThreadPriority(Sint64 threadID, int priority)
Sets the UNIX nice value for a thread.
Definition: SDL3pp_system.h:255
int GetDirect3D9AdapterIndex(Display displayID)
Get the D3D9 adapter index that matches the specified display.
Definition: SDL3pp_system.h:133
bool IsTV()
Query if the current device is a TV.
Definition: SDL3pp_system.h:842
SDL_iOSAnimationCallback iOSAnimationCallback
The prototype for an Apple iOS animation callback.
Definition: SDL3pp_system.h:303
constexpr Sandbox SANDBOX_NONE
NONE.
Definition: SDL3pp_system.h:851
void SetX11EventHook(X11EventHook callback, void *userdata)
Set a callback for every X11 event.
Definition: SDL3pp_system.h:220
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:54