SDL_*SceenSaver(): change return value to int. // add SDL_Unsupported() errors

main
Sylvain 2023-02-09 15:34:43 +01:00 committed by Sam Lantinga
parent e2e5e670bf
commit cee245b6a9
17 changed files with 50 additions and 32 deletions

View File

@ -1557,12 +1557,15 @@ extern DECLSPEC SDL_bool SDLCALL SDL_ScreenSaverEnabled(void);
/** /**
* Allow the screen to be blanked by a screen saver. * 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. * \since This function is available since SDL 3.0.0.
* *
* \sa SDL_DisableScreenSaver * \sa SDL_DisableScreenSaver
* \sa SDL_ScreenSaverEnabled * \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. * 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 is disabled by default since SDL 2.0.2. Before SDL 2.0.2
* the screensaver was enabled by default. * 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. * \since This function is available since SDL 3.0.0.
* *
* \sa SDL_EnableScreenSaver * \sa SDL_EnableScreenSaver
* \sa SDL_ScreenSaverEnabled * \sa SDL_ScreenSaverEnabled
*/ */
extern DECLSPEC void SDLCALL SDL_DisableScreenSaver(void); extern DECLSPEC int SDLCALL SDL_DisableScreenSaver(void);
/** /**

View File

@ -2151,9 +2151,9 @@ int Android_JNI_SendMessage(int command, int param)
return success ? 0 : -1; 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) void Android_JNI_ShowTextInput(SDL_Rect *inputRect)

View File

@ -86,7 +86,7 @@ void Android_JNI_HapticRun(int device_id, float intensity, int length);
void Android_JNI_HapticStop(int device_id); void Android_JNI_HapticStop(int device_id);
/* Video */ /* Video */
void Android_JNI_SuspendScreenSaver(SDL_bool suspend); int Android_JNI_SuspendScreenSaver(SDL_bool suspend);
/* Touch support */ /* Touch support */
void Android_JNI_InitTouch(void); void Android_JNI_InitTouch(void);

View File

@ -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_DestroyWindow,(SDL_Window *a),(a),)
SDL_DYNAPI_PROC(void,SDL_DetachThread,(SDL_Thread *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(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_Surface*,SDL_DuplicateSurface,(SDL_Surface *a),(a),return)
SDL_DYNAPI_PROC(SDL_EGLConfig,SDL_EGL_GetCurrentEGLConfig,(void),(),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_EGLDisplay,SDL_EGL_GetCurrentEGLDisplay,(void),(),return)
SDL_DYNAPI_PROC(SDL_FunctionPointer,SDL_EGL_GetProcAddress,(const char *a),(a),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(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_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(int,SDL_Error,(SDL_errorcode a),(a),return)
SDL_DYNAPI_PROC(SDL_bool,SDL_EventEnabled,(Uint32 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) SDL_DYNAPI_PROC(int,SDL_FillSurfaceRect,(SDL_Surface *a, const SDL_Rect *b, Uint32 c),(a,b,c),return)

View File

@ -327,7 +327,7 @@ struct SDL_VideoDevice
void (*PumpEvents)(_THIS); void (*PumpEvents)(_THIS);
/* Suspend the screensaver */ /* Suspend the screensaver */
void (*SuspendScreenSaver)(_THIS); int (*SuspendScreenSaver)(_THIS);
/* Text input */ /* Text input */
void (*StartTextInput)(_THIS); void (*StartTextInput)(_THIS);

View File

@ -3219,32 +3219,36 @@ SDL_bool SDL_ScreenSaverEnabled()
return _this->suspend_screensaver ? SDL_FALSE : SDL_TRUE; return _this->suspend_screensaver ? SDL_FALSE : SDL_TRUE;
} }
void SDL_EnableScreenSaver() int SDL_EnableScreenSaver()
{ {
if (_this == NULL) { if (_this == NULL) {
return; return 0;
} }
if (!_this->suspend_screensaver) { if (!_this->suspend_screensaver) {
return; return 0;
} }
_this->suspend_screensaver = SDL_FALSE; _this->suspend_screensaver = SDL_FALSE;
if (_this->SuspendScreenSaver) { if (_this->SuspendScreenSaver) {
_this->SuspendScreenSaver(_this); return _this->SuspendScreenSaver(_this);
} }
return SDL_Unsupported();
} }
void SDL_DisableScreenSaver() int SDL_DisableScreenSaver()
{ {
if (_this == NULL) { if (_this == NULL) {
return; return 0;
} }
if (_this->suspend_screensaver) { if (_this->suspend_screensaver) {
return; return 0;
} }
_this->suspend_screensaver = SDL_TRUE; _this->suspend_screensaver = SDL_TRUE;
if (_this->SuspendScreenSaver) { if (_this->SuspendScreenSaver) {
_this->SuspendScreenSaver(_this); return _this->SuspendScreenSaver(_this);
} }
return SDL_Unsupported();
} }
void SDL_VideoQuit(void) void SDL_VideoQuit(void)

View File

@ -66,9 +66,9 @@ SDL_sem *Android_PauseSem = NULL;
SDL_sem *Android_ResumeSem = NULL; SDL_sem *Android_ResumeSem = NULL;
SDL_mutex *Android_ActivityMutex = 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) static void Android_DeleteDevice(SDL_VideoDevice *device)

View File

@ -28,6 +28,6 @@ extern Uint64 Cocoa_GetEventTimestamp(NSTimeInterval nsTimestamp);
extern void Cocoa_PumpEvents(_THIS); extern void Cocoa_PumpEvents(_THIS);
extern int Cocoa_WaitEventTimeout(_THIS, Sint64 timeoutNS); extern int Cocoa_WaitEventTimeout(_THIS, Sint64 timeoutNS);
extern void Cocoa_SendWakeupEvent(_THIS, SDL_Window *window); extern void Cocoa_SendWakeupEvent(_THIS, SDL_Window *window);
extern void Cocoa_SuspendScreenSaver(_THIS); extern int Cocoa_SuspendScreenSaver(_THIS);
#endif /* SDL_cocoaevents_h_ */ #endif /* SDL_cocoaevents_h_ */

View File

@ -567,7 +567,7 @@ void Cocoa_SendWakeupEvent(_THIS, SDL_Window *window)
} }
} }
void Cocoa_SuspendScreenSaver(_THIS) int Cocoa_SuspendScreenSaver(_THIS)
{ {
@autoreleasepool { @autoreleasepool {
SDL_VideoData *data = _this->driverdata; SDL_VideoData *data = _this->driverdata;
@ -592,6 +592,7 @@ void Cocoa_SuspendScreenSaver(_THIS)
data.screensaver_assertion = assertion; data.screensaver_assertion = assertion;
} }
} }
return 0;
} }
#endif /* SDL_VIDEO_DRIVER_COCOA */ #endif /* SDL_VIDEO_DRIVER_COCOA */

View File

@ -37,7 +37,7 @@ CGRect UIKit_ComputeViewFrame(SDL_Window *window, UIScreen *screen);
#endif /* __OBJC__ */ #endif /* __OBJC__ */
void UIKit_SuspendScreenSaver(_THIS); int UIKit_SuspendScreenSaver(_THIS);
void UIKit_ForceUpdateHomeIndicator(void); void UIKit_ForceUpdateHomeIndicator(void);

View File

@ -164,7 +164,7 @@ void UIKit_VideoQuit(_THIS)
UIKit_QuitModes(_this); UIKit_QuitModes(_this);
} }
void UIKit_SuspendScreenSaver(_THIS) int UIKit_SuspendScreenSaver(_THIS)
{ {
@autoreleasepool { @autoreleasepool {
UIApplication *app = [UIApplication sharedApplication]; UIApplication *app = [UIApplication sharedApplication];
@ -172,6 +172,7 @@ void UIKit_SuspendScreenSaver(_THIS)
/* Prevent the display from dimming and going to sleep. */ /* Prevent the display from dimming and going to sleep. */
app.idleTimerDisabled = (_this->suspend_screensaver != SDL_FALSE); app.idleTimerDisabled = (_this->suspend_screensaver != SDL_FALSE);
} }
return 0;
} }
SDL_bool SDL_bool

View File

@ -2005,13 +2005,13 @@ void Wayland_SetWindowTitle(_THIS, SDL_Window *window)
WAYLAND_wl_display_flush(viddata->display); WAYLAND_wl_display_flush(viddata->display);
} }
void Wayland_SuspendScreenSaver(_THIS) int Wayland_SuspendScreenSaver(_THIS)
{ {
SDL_VideoData *data = _this->driverdata; SDL_VideoData *data = _this->driverdata;
#if SDL_USE_LIBDBUS #if SDL_USE_LIBDBUS
if (SDL_DBus_ScreensaverInhibit(_this->suspend_screensaver)) { if (SDL_DBus_ScreensaverInhibit(_this->suspend_screensaver)) {
return; return 0;
} }
#endif #endif
@ -2040,6 +2040,8 @@ void Wayland_SuspendScreenSaver(_THIS)
window = window->next; window = window->next;
} }
} }
return 0;
} }
void Wayland_DestroyWindow(_THIS, SDL_Window *window) void Wayland_DestroyWindow(_THIS, SDL_Window *window)

View File

@ -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 int Wayland_SetWindowModalFor(_THIS, SDL_Window *modal_window, SDL_Window *parent_window);
extern void Wayland_SetWindowTitle(_THIS, SDL_Window *window); extern void Wayland_SetWindowTitle(_THIS, SDL_Window *window);
extern void Wayland_DestroyWindow(_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_GetWindowWMInfo(_THIS, SDL_Window *window, SDL_SysWMinfo *info);
extern int Wayland_SetWindowHitTest(SDL_Window *window, SDL_bool enabled); extern int Wayland_SetWindowHitTest(SDL_Window *window, SDL_bool enabled);

View File

@ -58,13 +58,14 @@ static void SDLCALL UpdateWindowFrameUsableWhileCursorHidden(void *userdata, con
} }
#if !defined(__XBOXONE__) && !defined(__XBOXSERIES__) #if !defined(__XBOXONE__) && !defined(__XBOXSERIES__)
static void WIN_SuspendScreenSaver(_THIS) static int WIN_SuspendScreenSaver(_THIS)
{ {
if (_this->suspend_screensaver) { if (_this->suspend_screensaver) {
SetThreadExecutionState(ES_CONTINUOUS | ES_DISPLAY_REQUIRED); SetThreadExecutionState(ES_CONTINUOUS | ES_DISPLAY_REQUIRED);
} else { } else {
SetThreadExecutionState(ES_CONTINUOUS); SetThreadExecutionState(ES_CONTINUOUS);
} }
return 0;
} }
#endif #endif

View File

@ -84,7 +84,7 @@ static int WINRT_GetWindowWMInfo(_THIS, SDL_Window *window, SDL_SysWMinfo *info)
/* Misc functions */ /* Misc functions */
static ABI::Windows::System::Display::IDisplayRequest *WINRT_CreateDisplayRequest(_THIS); static ABI::Windows::System::Display::IDisplayRequest *WINRT_CreateDisplayRequest(_THIS);
extern void WINRT_SuspendScreenSaver(_THIS); extern int WINRT_SuspendScreenSaver(_THIS);
/* SDL-internal globals: */ /* SDL-internal globals: */
SDL_Window *WINRT_GlobalSDLWindow = NULL; SDL_Window *WINRT_GlobalSDLWindow = NULL;
@ -837,7 +837,7 @@ done:
return pDisplayRequest; return pDisplayRequest;
} }
void WINRT_SuspendScreenSaver(_THIS) int WINRT_SuspendScreenSaver(_THIS)
{ {
SDL_VideoData *driverdata = _this->driverdata; SDL_VideoData *driverdata = _this->driverdata;
if (driverdata && driverdata->displayRequest) { if (driverdata && driverdata->displayRequest) {
@ -848,6 +848,7 @@ void WINRT_SuspendScreenSaver(_THIS)
displayRequest->RequestRelease(); displayRequest->RequestRelease();
} }
} }
return 0;
} }
#endif /* SDL_VIDEO_DRIVER_WINRT */ #endif /* SDL_VIDEO_DRIVER_WINRT */

View File

@ -1726,7 +1726,7 @@ void X11_PumpEvents(_THIS)
} }
} }
void X11_SuspendScreenSaver(_THIS) int X11_SuspendScreenSaver(_THIS)
{ {
#if SDL_VIDEO_DRIVER_X11_XSCRNSAVER #if SDL_VIDEO_DRIVER_X11_XSCRNSAVER
SDL_VideoData *data = _this->driverdata; SDL_VideoData *data = _this->driverdata;
@ -1736,7 +1736,7 @@ void X11_SuspendScreenSaver(_THIS)
#if SDL_USE_LIBDBUS #if SDL_USE_LIBDBUS
if (SDL_DBus_ScreensaverInhibit(_this->suspend_screensaver)) { if (SDL_DBus_ScreensaverInhibit(_this->suspend_screensaver)) {
return; return 0;
} }
if (_this->suspend_screensaver) { if (_this->suspend_screensaver) {
@ -1751,13 +1751,15 @@ void X11_SuspendScreenSaver(_THIS)
!X11_XScreenSaverQueryVersion(data->display, !X11_XScreenSaverQueryVersion(data->display,
&major_version, &minor_version) || &major_version, &minor_version) ||
major_version < 1 || (major_version == 1 && minor_version < 1)) { major_version < 1 || (major_version == 1 && minor_version < 1)) {
return; return SDL_Unsupported();
} }
X11_XScreenSaverSuspend(data->display, _this->suspend_screensaver); X11_XScreenSaverSuspend(data->display, _this->suspend_screensaver);
X11_XResetScreenSaver(data->display); X11_XResetScreenSaver(data->display);
return 0;
} }
#endif #endif
return SDL_Unsupported();
} }
#endif /* SDL_VIDEO_DRIVER_X11 */ #endif /* SDL_VIDEO_DRIVER_X11 */

View File

@ -26,7 +26,7 @@
extern void X11_PumpEvents(_THIS); extern void X11_PumpEvents(_THIS);
extern int X11_WaitEventTimeout(_THIS, Sint64 timeoutNS); extern int X11_WaitEventTimeout(_THIS, Sint64 timeoutNS);
extern void X11_SendWakeupEvent(_THIS, SDL_Window *window); extern void X11_SendWakeupEvent(_THIS, SDL_Window *window);
extern void X11_SuspendScreenSaver(_THIS); extern int X11_SuspendScreenSaver(_THIS);
extern void X11_ReconcileKeyboardState(_THIS); extern void X11_ReconcileKeyboardState(_THIS);
#endif /* SDL_x11events_h_ */ #endif /* SDL_x11events_h_ */