Skip to content
This repository has been archived by the owner on Feb 11, 2021. It is now read-only.

Commit

Permalink
Added an API to enable/disable the screen saver.
Browse files Browse the repository at this point in the history
The screensaver is disabled by default when using SDL 1.2 compatibility.
Use the new XScreenSaver extension, removed unused DPMS extension.
  • Loading branch information
slouken committed Jan 12, 2009
1 parent 4cae383 commit 0034bd7
Show file tree
Hide file tree
Showing 16 changed files with 184 additions and 147 deletions.
45 changes: 29 additions & 16 deletions configure.in
Expand Up @@ -1020,6 +1020,7 @@ AC_HELP_STRING([--enable-x11-shared], [dynamically load X11 support [[default=ma
xrender_lib='/usr/X11R6/lib/libXrender.1.dylib'
xrandr_lib='/usr/X11R6/lib/libXrandr.2.dylib'
xinput_lib='/usr/X11R6/lib/libXi.6.dylib'
xss_lib='/usr/X11R6/lib/libXss.6.dylib'
;;
*-*-osf*)
x11_lib='libX11.so'
Expand Down Expand Up @@ -1062,6 +1063,12 @@ AC_HELP_STRING([--enable-x11-shared], [dynamically load X11 support [[default=ma
xinput_lib=[`ls -- $path/libXi.so.[0-9]* 2>/dev/null | sort -r | sed 's/.*\/\(.*\)/\1/; q'`]
fi
fi
if test "x$xss_lib" = "x"; then
xss_lib=[`ls -- $path/libXss.so.[0-9] 2>/dev/null | sort -r | sed 's/.*\/\(.*\)/\1/; q'`]
if test "x$xss_lib" = "x"; then
xss_lib=[`ls -- $path/libXss.so.[0-9]* 2>/dev/null | sort -r | sed 's/.*\/\(.*\)/\1/; q'`]
fi
fi
done
;;
esac
Expand Down Expand Up @@ -1124,13 +1131,6 @@ AC_HELP_STRING([--enable-video-x11-xinerama], [enable X11 Xinerama support [[def
AC_DEFINE(SDL_VIDEO_DRIVER_X11_XINERAMA)
SOURCES="$SOURCES $srcdir/src/video/Xext/Xinerama/*.c"
fi
AC_ARG_ENABLE(video-x11-xme,
AC_HELP_STRING([--enable-video-x11-xme], [enable Xi Graphics XME for fullscreen [[default=yes]]]),
, enable_video_x11_xme=yes)
if test x$enable_video_x11_xme = xyes; then
AC_DEFINE(SDL_VIDEO_DRIVER_X11_XME)
SOURCES="$SOURCES $srcdir/src/video/Xext/XME/*.c"
fi
AC_ARG_ENABLE(video-x11-xrandr,
AC_HELP_STRING([--enable-video-x11-xrandr], [enable X11 Xrandr extension for fullscreen [[default=yes]]]),
, enable_video_x11_xrandr=yes)
Expand Down Expand Up @@ -1188,19 +1188,32 @@ AC_HELP_STRING([--enable-video-x11-xinput], [enable X11 XInput extension for man
if test x$definitely_enable_video_x11_xinput = xyes; then
AC_DEFINE(SDL_VIDEO_DRIVER_X11_XINPUT)
fi
AC_ARG_ENABLE(video-x11-dpms,
AC_HELP_STRING([--enable-video-x11-dpms], [enable X11 DPMS extension [[default=yes]]]),
, enable_video_x11_dpms=yes)
if test x$enable_video_x11_dpms = xyes; then
AC_CHECK_HEADER(X11/extensions/dpms.h,
have_dpms_h_hdr=yes,
have_dpms_h_hdr=no,
AC_ARG_ENABLE(video-x11-scrnsaver,
AC_HELP_STRING([--enable-video-x11-scrnsaver], [enable X11 screensaver extension [[default=yes]]]),
, enable_video_x11_scrnsaver=yes)
if test x$enable_video_x11_scrnsaver = xyes; then
AC_CHECK_HEADER(X11/extensions/scrnsaver.h,
have_scrnsaver_h_hdr=yes,
have_scrnsaver_h_hdr=no,
[#include <X11/Xlib.h>
])
if test x$have_dpms_h_hdr = xyes; then
AC_DEFINE(SDL_VIDEO_DRIVER_X11_DPMS)
if test x$have_scrnsaver_h_hdr = xyes; then
if test x$enable_x11_shared = xyes && test x$xss_lib != x ; then
echo "-- dynamic libXss -> $xss_lib"
AC_DEFINE_UNQUOTED(SDL_VIDEO_DRIVER_X11_DYNAMIC_XSS, "$xss_lib")
definitely_enable_video_x11_scrnsaver=yes
else
AC_CHECK_LIB(Xss, XScreenSaverSuspend, have_xss_lib=yes)
if test x$have_xss_lib = xyes ; then
EXTRA_LDFLAGS="$EXTRA_LDFLAGS -lXss"
definitely_enable_video_x11_scrnsaver=yes
fi
fi
fi
fi
if test x$definitely_enable_video_x11_scrnsaver = xyes; then
AC_DEFINE(SDL_VIDEO_DRIVER_X11_SCRNSAVER)
fi

AC_ARG_ENABLE(render-x11,
AC_HELP_STRING([--enable-render-x11], [enable the X11 render driver [[default=yes]]]),
Expand Down
4 changes: 2 additions & 2 deletions include/SDL_config.h.in
Expand Up @@ -291,17 +291,17 @@
#undef SDL_VIDEO_DRIVER_WIN32
#undef SDL_VIDEO_DRIVER_WSCONS
#undef SDL_VIDEO_DRIVER_X11
#undef SDL_VIDEO_DRIVER_X11_DPMS
#undef SDL_VIDEO_DRIVER_X11_DYNAMIC
#undef SDL_VIDEO_DRIVER_X11_DYNAMIC_XEXT
#undef SDL_VIDEO_DRIVER_X11_DYNAMIC_XRANDR
#undef SDL_VIDEO_DRIVER_X11_DYNAMIC_XRENDER
#undef SDL_VIDEO_DRIVER_X11_DYNAMIC_XINPUT
#undef SDL_VIDEO_DRIVER_X11_DYNAMIC_XSS
#undef SDL_VIDEO_DRIVER_X11_VIDMODE
#undef SDL_VIDEO_DRIVER_X11_XINERAMA
#undef SDL_VIDEO_DRIVER_X11_XME
#undef SDL_VIDEO_DRIVER_X11_XRANDR
#undef SDL_VIDEO_DRIVER_X11_XINPUT
#undef SDL_VIDEO_DRIVER_X11_SCRNSAVER
#undef SDL_VIDEO_DRIVER_X11_XV
#undef SDL_VIDEO_DRIVER_XBIOS

Expand Down
30 changes: 30 additions & 0 deletions include/SDL_video.h
Expand Up @@ -1311,6 +1311,36 @@ extern DECLSPEC void SDLCALL SDL_DestroyTexture(SDL_TextureID textureID);
*/
extern DECLSPEC void SDLCALL SDL_DestroyRenderer(SDL_WindowID windowID);

/**
* \fn SDL_bool SDL_IsScreenSaverEnabled();
*
* \brief Returns whether the screensaver is currently enabled (default off).
*
* \sa SDL_EnableScreenSaver()
* \sa SDL_DisableScreenSaver()
*/
extern DECLSPEC SDL_bool SDLCALL SDL_IsScreenSaverEnabled();

/**
* \fn void SDL_EnableScreenSaver();
*
* \brief Allow the screen to be blanked by a screensaver
*
* \sa SDL_IsScreenSaverEnabled()
* \sa SDL_DisableScreenSaver()
*/
extern DECLSPEC void SDLCALL SDL_EnableScreenSaver();

/**
* \fn void SDL_DisableScreenSaver();
*
* \brief Prevent the screen from being blanked by a screensaver
*
* \sa SDL_IsScreenSaverEnabled()
* \sa SDL_EnableScreenSaver()
*/
extern DECLSPEC void SDLCALL SDL_DisableScreenSaver();


/* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * */
/* OpenGL support functions. */
Expand Down
23 changes: 23 additions & 0 deletions src/SDL_compat.c
Expand Up @@ -376,6 +376,26 @@ ClearVideoSurface()
SDL_UpdateRect(SDL_PublicSurface, 0, 0, 0, 0);
}

static void
SetupScreenSaver()
{
const char *env;
SDL_bool allow_screensaver;

/* Allow environment override of screensaver disable */
env = SDL_getenv("SDL_VIDEO_ALLOW_SCREENSAVER");
if (env) {
allow_screensaver = SDL_atoi(env) ? SDL_TRUE : SDL_FALSE;
} else {
allow_screensaver = SDL_FALSE;
}
if (allow_screensaver) {
SDL_EnableScreenSaver();
} else {
SDL_DisableScreenSaver();
}
}

int
SDL_ResizeVideoMode(int width, int height, int bpp, Uint32 flags)
{
Expand Down Expand Up @@ -456,6 +476,7 @@ SDL_SetVideoMode(int width, int height, int bpp, Uint32 flags)
{
SDL_DisplayMode desktop_mode;
SDL_DisplayMode mode;
const char *env;
int window_x = SDL_WINDOWPOS_UNDEFINED;
int window_y = SDL_WINDOWPOS_UNDEFINED;
Uint32 window_flags;
Expand Down Expand Up @@ -679,6 +700,8 @@ SDL_SetVideoMode(int width, int height, int bpp, Uint32 flags)

ClearVideoSurface();

SetupScreenSaver();

/* We're finally done! */
return SDL_PublicSurface;
}
Expand Down
4 changes: 4 additions & 0 deletions src/video/SDL_sysvideo.h
Expand Up @@ -273,8 +273,12 @@ struct SDL_VideoDevice
*/
void (*PumpEvents) (_THIS);

/* Suspend the screensaver */
void (*SuspendScreenSaver) (_THIS);

/* * * */
/* Data common to all drivers */
SDL_bool suspend_screensaver;
int num_displays;
SDL_VideoDisplay *displays;
int current_display;
Expand Down
39 changes: 39 additions & 0 deletions src/video/SDL_video.c
Expand Up @@ -2326,6 +2326,45 @@ SDL_DestroyRenderer(SDL_WindowID windowID)
}
}

SDL_bool
SDL_IsScreenSaverEnabled()
{
if (!_this) {
return SDL_TRUE;
}
return _this->suspend_screensaver ? SDL_FALSE : SDL_TRUE;
}

void
SDL_EnableScreenSaver()
{
if (!_this) {
return;
}
if (!_this->suspend_screensaver) {
return;
}
_this->suspend_screensaver = SDL_FALSE;
if (_this->SuspendScreenSaver) {
_this->SuspendScreenSaver(_this);
}
}

void
SDL_DisableScreenSaver()
{
if (!_this) {
return;
}
if (_this->suspend_screensaver) {
return;
}
_this->suspend_screensaver = SDL_TRUE;
if (_this->SuspendScreenSaver) {
_this->SuspendScreenSaver(_this);
}
}

void
SDL_VideoQuit(void)
{
Expand Down
46 changes: 0 additions & 46 deletions src/video/Xext/extensions/xme.h

This file was deleted.

11 changes: 11 additions & 0 deletions src/video/cocoa/SDL_cocoaevents.m
Expand Up @@ -164,6 +164,17 @@ - (NSApplicationTerminateReply)applicationShouldTerminate:(NSApplication *)sende
{
NSAutoreleasePool *pool;

/* Update activity every 30 seconds to prevent screensaver */
if (_this->suspend_screensaver) {
SDL_VideoData *data = (SDL_VideoData *)_this->driverdata;
Uint32 now = SDL_GetTicks();
if (!data->screensaver_activity ||
(int)(now-data->screensaver_activity) >= 30000) {
UpdateSystemActivity(UsrActivity);
data->screensaver_activity = now;
}
}

pool = [[NSAutoreleasePool alloc] init];
while ([NSApp isRunning]) {
NSEvent *event = [NSApp nextEventMatchingMask:NSAnyEventMask untilDate:[NSDate distantPast] inMode:NSDefaultRunLoopMode dequeue:YES ];
Expand Down
1 change: 1 addition & 0 deletions src/video/cocoa/SDL_cocoavideo.h
Expand Up @@ -49,6 +49,7 @@ typedef struct SDL_VideoData
int keyboard;
void *key_layout;
NSText *fieldEdit;
Uint32 screensaver_activity;
} SDL_VideoData;

#endif /* _SDL_cocoavideo_h */
Expand Down
4 changes: 2 additions & 2 deletions src/video/win32/SDL_win32events.c
Expand Up @@ -578,8 +578,8 @@ WIN_WindowProc(HWND hwnd, UINT msg, WPARAM wParam, LPARAM lParam)
/* Don't start the screensaver or blank the monitor in fullscreen apps */
if ((wParam & 0xFFF0) == SC_SCREENSAVE ||
(wParam & 0xFFF0) == SC_MONITORPOWER) {
if (SDL_GetWindowFlags(data->windowID) &
SDL_WINDOW_FULLSCREEN) {
SDL_VideoData *videodata = data->videodata;
if (videodata->suspend_screensaver) {
return (0);
}
}
Expand Down
1 change: 1 addition & 0 deletions src/video/x11/SDL_x11dyn.c
Expand Up @@ -62,6 +62,7 @@ static x11dynlib x11libs[] = {
{NULL, SDL_VIDEO_DRIVER_X11_DYNAMIC_XRENDER},
{NULL, SDL_VIDEO_DRIVER_X11_DYNAMIC_XRANDR},
{NULL, SDL_VIDEO_DRIVER_X11_DYNAMIC_XINPUT},
{NULL, SDL_VIDEO_DRIVER_X11_DYNAMIC_XSS},
};

static void
Expand Down

0 comments on commit 0034bd7

Please sign in to comment.