From cee245b6a94a3096aad189b550b48e74f9b1fe06 Mon Sep 17 00:00:00 2001
From: Sylvain <[EMAIL REDACTED]>
Date: Thu, 9 Feb 2023 15:34:43 +0100
Subject: [PATCH] SDL_*SceenSaver(): change return value to int. // add
SDL_Unsupported() errors
---
include/SDL3/SDL_video.h | 10 ++++++++--
src/core/android/SDL_android.c | 4 ++--
src/core/android/SDL_android.h | 2 +-
src/dynapi/SDL_dynapi_procs.h | 4 ++--
src/video/SDL_sysvideo.h | 2 +-
src/video/SDL_video.c | 20 ++++++++++++--------
src/video/android/SDL_androidvideo.c | 4 ++--
src/video/cocoa/SDL_cocoaevents.h | 2 +-
src/video/cocoa/SDL_cocoaevents.m | 3 ++-
src/video/uikit/SDL_uikitvideo.h | 2 +-
src/video/uikit/SDL_uikitvideo.m | 3 ++-
src/video/wayland/SDL_waylandwindow.c | 6 ++++--
src/video/wayland/SDL_waylandwindow.h | 2 +-
src/video/windows/SDL_windowsvideo.c | 3 ++-
src/video/winrt/SDL_winrtvideo.cpp | 5 +++--
src/video/x11/SDL_x11events.c | 8 +++++---
src/video/x11/SDL_x11events.h | 2 +-
17 files changed, 50 insertions(+), 32 deletions(-)
diff --git a/include/SDL3/SDL_video.h b/include/SDL3/SDL_video.h
index b161013def3c..98ef1c0ad72b 100644
--- a/include/SDL3/SDL_video.h
+++ b/include/SDL3/SDL_video.h
@@ -1557,12 +1557,15 @@ extern DECLSPEC SDL_bool SDLCALL SDL_ScreenSaverEnabled(void);
/**
* Allow the screen to be blanked by a screen saver.
*
+ * \returns 0 on success or a negative error code on failure; call
+ * SDL_GetError() for more information.
+ *
* \since This function is available since SDL 3.0.0.
*
* \sa SDL_DisableScreenSaver
* \sa SDL_ScreenSaverEnabled
*/
-extern DECLSPEC void SDLCALL SDL_EnableScreenSaver(void);
+extern DECLSPEC int SDLCALL SDL_EnableScreenSaver(void);
/**
* Prevent the screen from being blanked by a screen saver.
@@ -1573,12 +1576,15 @@ extern DECLSPEC void SDLCALL SDL_EnableScreenSaver(void);
* The screensaver is disabled by default since SDL 2.0.2. Before SDL 2.0.2
* the screensaver was enabled by default.
*
+ * \returns 0 on success or a negative error code on failure; call
+ * SDL_GetError() for more information.
+ *
* \since This function is available since SDL 3.0.0.
*
* \sa SDL_EnableScreenSaver
* \sa SDL_ScreenSaverEnabled
*/
-extern DECLSPEC void SDLCALL SDL_DisableScreenSaver(void);
+extern DECLSPEC int SDLCALL SDL_DisableScreenSaver(void);
/**
diff --git a/src/core/android/SDL_android.c b/src/core/android/SDL_android.c
index 2ffa8e016bac..aa267c450deb 100644
--- a/src/core/android/SDL_android.c
+++ b/src/core/android/SDL_android.c
@@ -2151,9 +2151,9 @@ int Android_JNI_SendMessage(int command, int param)
return success ? 0 : -1;
}
-void Android_JNI_SuspendScreenSaver(SDL_bool suspend)
+int Android_JNI_SuspendScreenSaver(SDL_bool suspend)
{
- Android_JNI_SendMessage(COMMAND_SET_KEEP_SCREEN_ON, (suspend == SDL_FALSE) ? 0 : 1);
+ return Android_JNI_SendMessage(COMMAND_SET_KEEP_SCREEN_ON, (suspend == SDL_FALSE) ? 0 : 1);
}
void Android_JNI_ShowTextInput(SDL_Rect *inputRect)
diff --git a/src/core/android/SDL_android.h b/src/core/android/SDL_android.h
index e818327a2ad0..3e318ac9edb8 100644
--- a/src/core/android/SDL_android.h
+++ b/src/core/android/SDL_android.h
@@ -86,7 +86,7 @@ void Android_JNI_HapticRun(int device_id, float intensity, int length);
void Android_JNI_HapticStop(int device_id);
/* Video */
-void Android_JNI_SuspendScreenSaver(SDL_bool suspend);
+int Android_JNI_SuspendScreenSaver(SDL_bool suspend);
/* Touch support */
void Android_JNI_InitTouch(void);
diff --git a/src/dynapi/SDL_dynapi_procs.h b/src/dynapi/SDL_dynapi_procs.h
index 4b6cf251faae..3b6b019c5ea8 100644
--- a/src/dynapi/SDL_dynapi_procs.h
+++ b/src/dynapi/SDL_dynapi_procs.h
@@ -193,14 +193,14 @@ SDL_DYNAPI_PROC(void,SDL_DestroyTexture,(SDL_Texture *a),(a),)
SDL_DYNAPI_PROC(void,SDL_DestroyWindow,(SDL_Window *a),(a),)
SDL_DYNAPI_PROC(void,SDL_DetachThread,(SDL_Thread *a),(a),)
SDL_DYNAPI_PROC(int,SDL_DetachVirtualJoystick,(SDL_JoystickID a),(a),return)
-SDL_DYNAPI_PROC(void,SDL_DisableScreenSaver,(void),(),)
+SDL_DYNAPI_PROC(int,SDL_DisableScreenSaver,(void),(),return)
SDL_DYNAPI_PROC(SDL_Surface*,SDL_DuplicateSurface,(SDL_Surface *a),(a),return)
SDL_DYNAPI_PROC(SDL_EGLConfig,SDL_EGL_GetCurrentEGLConfig,(void),(),return)
SDL_DYNAPI_PROC(SDL_EGLDisplay,SDL_EGL_GetCurrentEGLDisplay,(void),(),return)
SDL_DYNAPI_PROC(SDL_FunctionPointer,SDL_EGL_GetProcAddress,(const char *a),(a),return)
SDL_DYNAPI_PROC(SDL_EGLSurface,SDL_EGL_GetWindowEGLSurface,(SDL_Window *a),(a),return)
SDL_DYNAPI_PROC(void,SDL_EGL_SetEGLAttributeCallbacks,(SDL_EGLAttribArrayCallback a, SDL_EGLIntArrayCallback b, SDL_EGLIntArrayCallback c),(a,b,c),)
-SDL_DYNAPI_PROC(void,SDL_EnableScreenSaver,(void),(),)
+SDL_DYNAPI_PROC(int,SDL_EnableScreenSaver,(void),(),return)
SDL_DYNAPI_PROC(int,SDL_Error,(SDL_errorcode a),(a),return)
SDL_DYNAPI_PROC(SDL_bool,SDL_EventEnabled,(Uint32 a),(a),return)
SDL_DYNAPI_PROC(int,SDL_FillSurfaceRect,(SDL_Surface *a, const SDL_Rect *b, Uint32 c),(a,b,c),return)
diff --git a/src/video/SDL_sysvideo.h b/src/video/SDL_sysvideo.h
index b0bc1db3866c..d444af0bd092 100644
--- a/src/video/SDL_sysvideo.h
+++ b/src/video/SDL_sysvideo.h
@@ -327,7 +327,7 @@ struct SDL_VideoDevice
void (*PumpEvents)(_THIS);
/* Suspend the screensaver */
- void (*SuspendScreenSaver)(_THIS);
+ int (*SuspendScreenSaver)(_THIS);
/* Text input */
void (*StartTextInput)(_THIS);
diff --git a/src/video/SDL_video.c b/src/video/SDL_video.c
index 94811edb880f..64eac9c4104c 100644
--- a/src/video/SDL_video.c
+++ b/src/video/SDL_video.c
@@ -3219,32 +3219,36 @@ SDL_bool SDL_ScreenSaverEnabled()
return _this->suspend_screensaver ? SDL_FALSE : SDL_TRUE;
}
-void SDL_EnableScreenSaver()
+int SDL_EnableScreenSaver()
{
if (_this == NULL) {
- return;
+ return 0;
}
if (!_this->suspend_screensaver) {
- return;
+ return 0;
}
_this->suspend_screensaver = SDL_FALSE;
if (_this->SuspendScreenSaver) {
- _this->SuspendScreenSaver(_this);
+ return _this->SuspendScreenSaver(_this);
}
+
+ return SDL_Unsupported();
}
-void SDL_DisableScreenSaver()
+int SDL_DisableScreenSaver()
{
if (_this == NULL) {
- return;
+ return 0;
}
if (_this->suspend_screensaver) {
- return;
+ return 0;
}
_this->suspend_screensaver = SDL_TRUE;
if (_this->SuspendScreenSaver) {
- _this->SuspendScreenSaver(_this);
+ return _this->SuspendScreenSaver(_this);
}
+
+ return SDL_Unsupported();
}
void SDL_VideoQuit(void)
diff --git a/src/video/android/SDL_androidvideo.c b/src/video/android/SDL_androidvideo.c
index e7d0f592646a..05ef30179378 100644
--- a/src/video/android/SDL_androidvideo.c
+++ b/src/video/android/SDL_androidvideo.c
@@ -66,9 +66,9 @@ SDL_sem *Android_PauseSem = NULL;
SDL_sem *Android_ResumeSem = NULL;
SDL_mutex *Android_ActivityMutex = NULL;
-static void Android_SuspendScreenSaver(_THIS)
+static int Android_SuspendScreenSaver(_THIS)
{
- Android_JNI_SuspendScreenSaver(_this->suspend_screensaver);
+ return Android_JNI_SuspendScreenSaver(_this->suspend_screensaver);
}
static void Android_DeleteDevice(SDL_VideoDevice *device)
diff --git a/src/video/cocoa/SDL_cocoaevents.h b/src/video/cocoa/SDL_cocoaevents.h
index 17b64e19ec56..606747f271fe 100644
--- a/src/video/cocoa/SDL_cocoaevents.h
+++ b/src/video/cocoa/SDL_cocoaevents.h
@@ -28,6 +28,6 @@ extern Uint64 Cocoa_GetEventTimestamp(NSTimeInterval nsTimestamp);
extern void Cocoa_PumpEvents(_THIS);
extern int Cocoa_WaitEventTimeout(_THIS, Sint64 timeoutNS);
extern void Cocoa_SendWakeupEvent(_THIS, SDL_Window *window);
-extern void Cocoa_SuspendScreenSaver(_THIS);
+extern int Cocoa_SuspendScreenSaver(_THIS);
#endif /* SDL_cocoaevents_h_ */
diff --git a/src/video/cocoa/SDL_cocoaevents.m b/src/video/cocoa/SDL_cocoaevents.m
index 1edac9eac89e..bf8b58ebc0a6 100644
--- a/src/video/cocoa/SDL_cocoaevents.m
+++ b/src/video/cocoa/SDL_cocoaevents.m
@@ -567,7 +567,7 @@ void Cocoa_SendWakeupEvent(_THIS, SDL_Window *window)
}
}
-void Cocoa_SuspendScreenSaver(_THIS)
+int Cocoa_SuspendScreenSaver(_THIS)
{
@autoreleasepool {
SDL_VideoData *data = _this->driverdata;
@@ -592,6 +592,7 @@ void Cocoa_SuspendScreenSaver(_THIS)
data.screensaver_assertion = assertion;
}
}
+ return 0;
}
#endif /* SDL_VIDEO_DRIVER_COCOA */
diff --git a/src/video/uikit/SDL_uikitvideo.h b/src/video/uikit/SDL_uikitvideo.h
index 8c47b2a22ebd..d791ac4c70b7 100644
--- a/src/video/uikit/SDL_uikitvideo.h
+++ b/src/video/uikit/SDL_uikitvideo.h
@@ -37,7 +37,7 @@ CGRect UIKit_ComputeViewFrame(SDL_Window *window, UIScreen *screen);
#endif /* __OBJC__ */
-void UIKit_SuspendScreenSaver(_THIS);
+int UIKit_SuspendScreenSaver(_THIS);
void UIKit_ForceUpdateHomeIndicator(void);
diff --git a/src/video/uikit/SDL_uikitvideo.m b/src/video/uikit/SDL_uikitvideo.m
index faa2575626ee..596670faf221 100644
--- a/src/video/uikit/SDL_uikitvideo.m
+++ b/src/video/uikit/SDL_uikitvideo.m
@@ -164,7 +164,7 @@ void UIKit_VideoQuit(_THIS)
UIKit_QuitModes(_this);
}
-void UIKit_SuspendScreenSaver(_THIS)
+int UIKit_SuspendScreenSaver(_THIS)
{
@autoreleasepool {
UIApplication *app = [UIApplication sharedApplication];
@@ -172,6 +172,7 @@ void UIKit_SuspendScreenSaver(_THIS)
/* Prevent the display from dimming and going to sleep. */
app.idleTimerDisabled = (_this->suspend_screensaver != SDL_FALSE);
}
+ return 0;
}
SDL_bool
diff --git a/src/video/wayland/SDL_waylandwindow.c b/src/video/wayland/SDL_waylandwindow.c
index 452a5f0e2e68..55263fdfd33c 100644
--- a/src/video/wayland/SDL_waylandwindow.c
+++ b/src/video/wayland/SDL_waylandwindow.c
@@ -2005,13 +2005,13 @@ void Wayland_SetWindowTitle(_THIS, SDL_Window *window)
WAYLAND_wl_display_flush(viddata->display);
}
-void Wayland_SuspendScreenSaver(_THIS)
+int Wayland_SuspendScreenSaver(_THIS)
{
SDL_VideoData *data = _this->driverdata;
#if SDL_USE_LIBDBUS
if (SDL_DBus_ScreensaverInhibit(_this->suspend_screensaver)) {
- return;
+ return 0;
}
#endif
@@ -2040,6 +2040,8 @@ void Wayland_SuspendScreenSaver(_THIS)
window = window->next;
}
}
+
+ return 0;
}
void Wayland_DestroyWindow(_THIS, SDL_Window *window)
diff --git a/src/video/wayland/SDL_waylandwindow.h b/src/video/wayland/SDL_waylandwindow.h
index d45a61e44c29..292a5f8130e9 100644
--- a/src/video/wayland/SDL_waylandwindow.h
+++ b/src/video/wayland/SDL_waylandwindow.h
@@ -139,7 +139,7 @@ extern void Wayland_GetWindowSizeInPixels(_THIS, SDL_Window *window, int *w, int
extern int Wayland_SetWindowModalFor(_THIS, SDL_Window *modal_window, SDL_Window *parent_window);
extern void Wayland_SetWindowTitle(_THIS, SDL_Window *window);
extern void Wayland_DestroyWindow(_THIS, SDL_Window *window);
-extern void Wayland_SuspendScreenSaver(_THIS);
+extern int Wayland_SuspendScreenSaver(_THIS);
extern int Wayland_GetWindowWMInfo(_THIS, SDL_Window *window, SDL_SysWMinfo *info);
extern int Wayland_SetWindowHitTest(SDL_Window *window, SDL_bool enabled);
diff --git a/src/video/windows/SDL_windowsvideo.c b/src/video/windows/SDL_windowsvideo.c
index b59bbeb879b5..98c8bacb41c8 100644
--- a/src/video/windows/SDL_windowsvideo.c
+++ b/src/video/windows/SDL_windowsvideo.c
@@ -58,13 +58,14 @@ static void SDLCALL UpdateWindowFrameUsableWhileCursorHidden(void *userdata, con
}
#if !defined(__XBOXONE__) && !defined(__XBOXSERIES__)
-static void WIN_SuspendScreenSaver(_THIS)
+static int WIN_SuspendScreenSaver(_THIS)
{
if (_this->suspend_screensaver) {
SetThreadExecutionState(ES_CONTINUOUS | ES_DISPLAY_REQUIRED);
} else {
SetThreadExecutionState(ES_CONTINUOUS);
}
+ return 0;
}
#endif
diff --git a/src/video/winrt/SDL_winrtvideo.cpp b/src/video/winrt/SDL_winrtvideo.cpp
index e5a37faf5ccb..bd26bb3312c0 100644
--- a/src/video/winrt/SDL_winrtvideo.cpp
+++ b/src/video/winrt/SDL_winrtvideo.cpp
@@ -84,7 +84,7 @@ static int WINRT_GetWindowWMInfo(_THIS, SDL_Window *window, SDL_SysWMinfo *info)
/* Misc functions */
static ABI::Windows::System::Display::IDisplayRequest *WINRT_CreateDisplayRequest(_THIS);
-extern void WINRT_SuspendScreenSaver(_THIS);
+extern int WINRT_SuspendScreenSaver(_THIS);
/* SDL-internal globals: */
SDL_Window *WINRT_GlobalSDLWindow = NULL;
@@ -837,7 +837,7 @@ static ABI::Windows::System::Display::IDisplayRequest *WINRT_CreateDisplayReques
return pDisplayRequest;
}
-void WINRT_SuspendScreenSaver(_THIS)
+int WINRT_SuspendScreenSaver(_THIS)
{
SDL_VideoData *driverdata = _this->driverdata;
if (driverdata && driverdata->displayRequest) {
@@ -848,6 +848,7 @@ void WINRT_SuspendScreenSaver(_THIS)
displayRequest->RequestRelease();
}
}
+ return 0;
}
#endif /* SDL_VIDEO_DRIVER_WINRT */
diff --git a/src/video/x11/SDL_x11events.c b/src/video/x11/SDL_x11events.c
index 152578a0e7c1..99014a863797 100644
--- a/src/video/x11/SDL_x11events.c
+++ b/src/video/x11/SDL_x11events.c
@@ -1726,7 +1726,7 @@ void X11_PumpEvents(_THIS)
}
}
-void X11_SuspendScreenSaver(_THIS)
+int X11_SuspendScreenSaver(_THIS)
{
#if SDL_VIDEO_DRIVER_X11_XSCRNSAVER
SDL_VideoData *data = _this->driverdata;
@@ -1736,7 +1736,7 @@ void X11_SuspendScreenSaver(_THIS)
#if SDL_USE_LIBDBUS
if (SDL_DBus_ScreensaverInhibit(_this->suspend_screensaver)) {
- return;
+ return 0;
}
if (_this->suspend_screensaver) {
@@ -1751,13 +1751,15 @@ void X11_SuspendScreenSaver(_THIS)
!X11_XScreenSaverQueryVersion(data->display,
&major_version, &minor_version) ||
major_version < 1 || (major_version == 1 && minor_version < 1)) {
- return;
+ return SDL_Unsupported();
}
X11_XScreenSaverSuspend(data->display, _this->suspend_screensaver);
X11_XResetScreenSaver(data->display);
+ return 0;
}
#endif
+ return SDL_Unsupported();
}
#endif /* SDL_VIDEO_DRIVER_X11 */
diff --git a/src/video/x11/SDL_x11events.h b/src/video/x11/SDL_x11events.h
index 8f2c8be1c522..a95b58454d49 100644
--- a/src/video/x11/SDL_x11events.h
+++ b/src/video/x11/SDL_x11events.h
@@ -26,7 +26,7 @@
extern void X11_PumpEvents(_THIS);
extern int X11_WaitEventTimeout(_THIS, Sint64 timeoutNS);
extern void X11_SendWakeupEvent(_THIS, SDL_Window *window);
-extern void X11_SuspendScreenSaver(_THIS);
+extern int X11_SuspendScreenSaver(_THIS);
extern void X11_ReconcileKeyboardState(_THIS);
#endif /* SDL_x11events_h_ */