Commit 5ad5a081 authored by Sam Lantinga's avatar Sam Lantinga

* Added configure option --enable-screensaver, to allow enabling the screensaver by default.

* Use XResetScreenSaver() instead of disabling screensaver entirely.

Full discussion summary from Erik on the SDL mailing list:

Current behaviour
=================

SDL changes the user's display power management settings without
permission from the user and without telling the user.

The interface that it uses to do so is DPMSDisable/DPMSEnable, which
should only ever be used by configuration utilities like KControl, never
by normal application programs, let alone by the libraries that they
use. Using an interface that is not at all intended for what SDL tries
to achieve means that it will not work as it should. Firstly, the power
management is completely disabled during the whole lifetime of the SDL
program, not only when it should be. Secondly, it makes SDL
non-reentrant, meaning that things will break when multiple SDL programs
are clients of the same X server simultaneously. Thirdly, no cleanup
mechanism ensures that the setting is restored if the client does not do
that (for example if it crashes).

In addition to that, this interface is broken on xorg,
[http://bugs.freedesktop.org/show_bug.cgi?id=13962], so what SDL tries
to do does not work at all on that implementation of the X Window
System. (The reason that the DPMSEnable works in KControl is that it
calls DPMSSetTimeout immediately after,
[http://websvn.kde.org/tags/KDE/3.5.9/kdebase/kcontrol/energy/energy.cpp?annotate=774532#l343]).


The problems that the current behaviour causes
==============================================
1. Information leak. When the user is away, someone might see what the
user has on the display when the user counts on the screensaver
preventing this. This does not even require physical access to the
workstation, it is enough to see it from a distance.
2. Draining battery. An SDL program that runs on a laptop will quickly
drain the battery while the user is away. The system will soon shut down
and require recharging before being usable again, while it should in
fact have consumed very little energy if the user's settings would have
been obeyed.
3. Wasting energy. Even if battery issues are not considered, energy as
such is wasted.
4. Display wear. The display may be worn out.


The problems that the current behaviour tries to solve
======================================================

1. Preventing screensaver while playing movies.
   Many SDL applications are media players. They have reasons to prevent
screensavers from being activated while a movie is being played. When a
user clicks on the play button it can be interpreted as saying "play
this movie, but do not turn off the display while playing it, because I
will watch it even though I do not interact with the system".

2. Preventing screensaver when some input bypasses X.
   Sometimes SDL uses input from another source than the X server, so
that the X server is bypassed. This obviously breaks the screensaver
handling. SDL tries to work around that.

3. Preventing screensaver when all input bypasses X.
   There is something called Direct Graphics Access mode, where a
program takes control of both the display and the input devices from the
X server. This obviously means that the X server can not handle the
screensaver alone, since screensaver handling depends on input handling.
SDL does not do what it should to help the X server to handle the
screensaver. Nor does SDL take care of screeensaver handling itself. SDL
simply disables the screensaver completely.


How the problems should be solved
=================================

The correct way for an application program to prevent the screensaver
under X is to call XResetScreenSaver. This was recently discovered and
implemented by the mplayer developers,
[http://svn.mplayerhq.hu/mplayer?view=rev&revision=25637]. SDL needs to
wrap this in an API call (SDL_ResetScreenSaver) and implement it for the
other video targets (if they do not have a corresponding call, SDL
should do what it takes on that particular target, for example sending
fake key events).

1. When a movie is played, the player should reset the screensaver when
the animation is advanced to a new frame. The same applies to anything
similar, like slideshows.

2. When the X server is handling input, it must handle all input
(keyboards, mice, gamepads, ...). This is necessary, not only to be able
to handle the screensaver, but also so that it can send the events to
the correct (the currently active) client. If there is an input device
that the X server can not handle for some reason (such as lack of Plug
and Play capability), the program that handles the device as a
workaround must simulate what would happen if the X server would have
handled the device, by calling XResetScreenSaver when input is received
from the device.

3. When the X server is not handling the input, it depends on the
program that does to call XResetScreenSaver whenever an input event
occurs. Alternatively the program must handle the screensaver countdown
internally and call XActivateScreenSaver.

--HG--
branch : SDL-1.2
extra : convert_revision : svn%3Ac70aab31-4412-0410-b14c-859654838e24/branches/SDL-1.2%402733
parent d19e81db
...@@ -1090,19 +1090,6 @@ AC_HELP_STRING([--enable-video-x11-xrandr], [enable X11 Xrandr extension for ful ...@@ -1090,19 +1090,6 @@ AC_HELP_STRING([--enable-video-x11-xrandr], [enable X11 Xrandr extension for ful
if test x$definitely_enable_video_x11_xrandr = xyes; then if test x$definitely_enable_video_x11_xrandr = xyes; then
AC_DEFINE(SDL_VIDEO_DRIVER_X11_XRANDR) AC_DEFINE(SDL_VIDEO_DRIVER_X11_XRANDR)
fi 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,
[#include <X11/Xlib.h>
])
if test x$have_dpms_h_hdr = xyes; then
AC_DEFINE(SDL_VIDEO_DRIVER_X11_DPMS)
fi
fi
fi fi
fi fi
} }
...@@ -1673,6 +1660,13 @@ AC_HELP_STRING([--enable-osmesa-shared], [dynamically load OSMesa OpenGL support ...@@ -1673,6 +1660,13 @@ AC_HELP_STRING([--enable-osmesa-shared], [dynamically load OSMesa OpenGL support
fi fi
} }
AC_ARG_ENABLE(screensaver,
AC_HELP_STRING([--enable-screensaver], [enable screensaver by default while any SDL application is running [[default=no]]]),
, enable_screensaver=no)
if test x$enable_screensaver = xno; then
AC_DEFINE(SDL_VIDEO_DISABLE_SCREENSAVER)
fi
dnl See if we can use the new unified event interface in Linux 2.4 dnl See if we can use the new unified event interface in Linux 2.4
CheckInputEvents() CheckInputEvents()
{ {
......
...@@ -14,6 +14,45 @@ The latest stable release may be found on the ...@@ -14,6 +14,45 @@ The latest stable release may be found on the
<H2> <A HREF="docs/index.html">API Documentation</A> </H2> <H2> <A HREF="docs/index.html">API Documentation</A> </H2>
<H2> SDL 1.2.14 Release Notes </H2>
<P>
SDL 1.2.14 is a minor bug fix release.
</P>
<H3> General Notes </H3>
<BLOCKQUOTE>
<P>
</P>
</BLOCKQUOTE>
<H3> Unix Notes </H3>
<BLOCKQUOTE>
<P>
Added configure option --enable-screensaver, to allow enabling the screensaver by default.
</P>
<P>
Use XResetScreenSaver() instead of disabling screensaver entirely.
</P>
</BLOCKQUOTE>
<H3> Windows Notes </H3>
<BLOCKQUOTE>
<P>
</P>
</BLOCKQUOTE>
<H3> Mac OS X Notes </H3>
<BLOCKQUOTE>
<P>
</P>
</BLOCKQUOTE>
<IMG SRC="docs/images/rainbow.gif" ALT="[separator]" WIDTH="100%">
<H2> SDL 1.2.13 Release Notes </H2> <H2> SDL 1.2.13 Release Notes </H2>
<P> <P>
SDL 1.2.13 is a minor bug fix release. SDL 1.2.13 is a minor bug fix release.
......
...@@ -279,7 +279,6 @@ ...@@ -279,7 +279,6 @@
#undef SDL_VIDEO_DRIVER_WSCONS #undef SDL_VIDEO_DRIVER_WSCONS
#undef SDL_VIDEO_DRIVER_X11 #undef SDL_VIDEO_DRIVER_X11
#undef SDL_VIDEO_DRIVER_X11_DGAMOUSE #undef SDL_VIDEO_DRIVER_X11_DGAMOUSE
#undef SDL_VIDEO_DRIVER_X11_DPMS
#undef SDL_VIDEO_DRIVER_X11_DYNAMIC #undef SDL_VIDEO_DRIVER_X11_DYNAMIC
#undef SDL_VIDEO_DRIVER_X11_DYNAMIC_XEXT #undef SDL_VIDEO_DRIVER_X11_DYNAMIC_XEXT
#undef SDL_VIDEO_DRIVER_X11_DYNAMIC_XRANDR #undef SDL_VIDEO_DRIVER_X11_DYNAMIC_XRANDR
...@@ -298,6 +297,9 @@ ...@@ -298,6 +297,9 @@
#undef SDL_VIDEO_OPENGL_OSMESA #undef SDL_VIDEO_OPENGL_OSMESA
#undef SDL_VIDEO_OPENGL_OSMESA_DYNAMIC #undef SDL_VIDEO_OPENGL_OSMESA_DYNAMIC
/* Disable screensaver */
#undef SDL_VIDEO_DISABLE_SCREENSAVER
/* Enable assembly routines */ /* Enable assembly routines */
#undef SDL_ASSEMBLY_ROUTINES #undef SDL_ASSEMBLY_ROUTINES
#undef SDL_HERMES_BLITTERS #undef SDL_HERMES_BLITTERS
......
...@@ -126,6 +126,9 @@ ...@@ -126,6 +126,9 @@
/* Enable OpenGL support */ /* Enable OpenGL support */
#define SDL_VIDEO_OPENGL 1 #define SDL_VIDEO_OPENGL 1
/* Disable screensaver */
#define SDL_VIDEO_DISABLE_SCREENSAVER 1
/* Enable assembly routines */ /* Enable assembly routines */
#define SDL_ASSEMBLY_ROUTINES 1 #define SDL_ASSEMBLY_ROUTINES 1
#ifdef __ppc__ #ifdef __ppc__
......
...@@ -172,6 +172,9 @@ typedef unsigned int uintptr_t; ...@@ -172,6 +172,9 @@ typedef unsigned int uintptr_t;
#define SDL_VIDEO_OPENGL_WGL 1 #define SDL_VIDEO_OPENGL_WGL 1
#endif #endif
/* Disable screensaver */
#define SDL_VIDEO_DISABLE_SCREENSAVER 1
/* Enable assembly routines (Win64 doesn't have inline asm) */ /* Enable assembly routines (Win64 doesn't have inline asm) */
#ifndef _WIN64 #ifndef _WIN64
#define SDL_ASSEMBLY_ROUTINES 1 #define SDL_ASSEMBLY_ROUTINES 1
......
...@@ -137,9 +137,21 @@ void DGA_PumpEvents(_THIS) ...@@ -137,9 +137,21 @@ void DGA_PumpEvents(_THIS)
{ {
/* Keep processing pending events */ /* Keep processing pending events */
LOCK_DISPLAY(); LOCK_DISPLAY();
/* Update activity every five seconds to prevent screensaver. --ryan. */
if (!allow_screensaver) {
static Uint32 screensaverTicks;
Uint32 nowTicks = SDL_GetTicks();
if ((nowTicks - screensaverTicks) > 5000) {
XResetScreenSaver(DGA_Display);
screensaverTicks = nowTicks;
}
}
while ( X11_Pending(DGA_Display) ) { while ( X11_Pending(DGA_Display) ) {
DGA_DispatchEvent(this); DGA_DispatchEvent(this);
} }
UNLOCK_DISPLAY(); UNLOCK_DISPLAY();
} }
......
...@@ -43,11 +43,6 @@ ...@@ -43,11 +43,6 @@
/*#define DGA_DEBUG*/ /*#define DGA_DEBUG*/
/* Heheh we're using X11 event code */
extern void X11_SaveScreenSaver(Display *display, int *saved_timeout, BOOL *dpms);
extern void X11_DisableScreenSaver(Display *display);
extern void X11_RestoreScreenSaver(Display *display, int saved_timeout, BOOL dpms);
/* Initialization/Query functions */ /* Initialization/Query functions */
static int DGA_VideoInit(_THIS, SDL_PixelFormat *vformat); static int DGA_VideoInit(_THIS, SDL_PixelFormat *vformat);
static SDL_Rect **DGA_ListModes(_THIS, SDL_PixelFormat *format, Uint32 flags); static SDL_Rect **DGA_ListModes(_THIS, SDL_PixelFormat *format, Uint32 flags);
...@@ -333,6 +328,7 @@ static void UpdateHWInfo(_THIS, SDL_NAME(XDGAMode) *mode) ...@@ -333,6 +328,7 @@ static void UpdateHWInfo(_THIS, SDL_NAME(XDGAMode) *mode)
static int DGA_VideoInit(_THIS, SDL_PixelFormat *vformat) static int DGA_VideoInit(_THIS, SDL_PixelFormat *vformat)
{ {
const char *env;
const char *display; const char *display;
int event_base, error_base; int event_base, error_base;
int major_version, minor_version; int major_version, minor_version;
...@@ -401,9 +397,17 @@ static int DGA_VideoInit(_THIS, SDL_PixelFormat *vformat) ...@@ -401,9 +397,17 @@ static int DGA_VideoInit(_THIS, SDL_PixelFormat *vformat)
return(-1); return(-1);
} }
/* Save DPMS and screensaver settings */ /* Allow environment override of screensaver disable. */
X11_SaveScreenSaver(DGA_Display, &screensaver_timeout, &dpms_enabled); env = SDL_getenv("SDL_VIDEO_ALLOW_SCREENSAVER");
X11_DisableScreenSaver(DGA_Display); if ( env ) {
allow_screensaver = SDL_atoi(env);
} else {
#ifdef SDL_VIDEO_DISABLE_SCREENSAVER
allow_screensaver = 0;
#else
allow_screensaver = 1;
#endif
}
/* Query for the list of available video modes */ /* Query for the list of available video modes */
modes = SDL_NAME(XDGAQueryModes)(DGA_Display, DGA_Screen, &num_modes); modes = SDL_NAME(XDGAQueryModes)(DGA_Display, DGA_Screen, &num_modes);
...@@ -1091,9 +1095,6 @@ void DGA_VideoQuit(_THIS) ...@@ -1091,9 +1095,6 @@ void DGA_VideoQuit(_THIS)
/* Clean up the memory bucket list */ /* Clean up the memory bucket list */
DGA_FreeHWSurfaces(this); DGA_FreeHWSurfaces(this);
/* Restore DPMS and screensaver settings */
X11_RestoreScreenSaver(DGA_Display, screensaver_timeout, dpms_enabled);
/* Close up the display */ /* Close up the display */
XCloseDisplay(DGA_Display); XCloseDisplay(DGA_Display);
} }
......
...@@ -32,10 +32,6 @@ ...@@ -32,10 +32,6 @@
#include "SDL_mutex.h" #include "SDL_mutex.h"
#include "../SDL_sysvideo.h" #include "../SDL_sysvideo.h"
#if SDL_VIDEO_DRIVER_X11_DPMS
#include <X11/extensions/dpms.h>
#endif
/* Hidden "this" pointer for the video functions */ /* Hidden "this" pointer for the video functions */
#define _THIS SDL_VideoDevice *this #define _THIS SDL_VideoDevice *this
...@@ -94,9 +90,9 @@ struct SDL_PrivateVideoData { ...@@ -94,9 +90,9 @@ struct SDL_PrivateVideoData {
#endif #endif
/* Screensaver settings */ /* Screensaver settings */
int screensaver_timeout; int allow_screensaver;
BOOL dpms_enabled;
}; };
/* Old variable names */ /* Old variable names */
#define DGA_Display (this->hidden->DGA_Display) #define DGA_Display (this->hidden->DGA_Display)
#define DGA_Screen DefaultScreen(DGA_Display) #define DGA_Screen DefaultScreen(DGA_Display)
...@@ -117,7 +113,6 @@ struct SDL_PrivateVideoData { ...@@ -117,7 +113,6 @@ struct SDL_PrivateVideoData {
#define hw_lock (this->hidden->hw_lock) #define hw_lock (this->hidden->hw_lock)
#define DGA_event_base (this->hidden->event_base) #define DGA_event_base (this->hidden->event_base)
#define event_lock (this->hidden->event_lock) #define event_lock (this->hidden->event_lock)
#define screensaver_timeout (this->hidden->screensaver_timeout) #define allow_screensaver (this->hidden->allow_screensaver)
#define dpms_enabled (this->hidden->dpms_enabled)
#endif /* _SDL_dgavideo_h */ #endif /* _SDL_dgavideo_h */
...@@ -717,8 +717,6 @@ static int QZ_OtherMouseButtonToSDL(int button) ...@@ -717,8 +717,6 @@ static int QZ_OtherMouseButtonToSDL(int button)
void QZ_PumpEvents (_THIS) void QZ_PumpEvents (_THIS)
{ {
static Uint32 screensaverTicks = 0;
Uint32 nowTicks;
CGMouseDelta dx, dy; CGMouseDelta dx, dy;
NSDate *distantPast; NSDate *distantPast;
...@@ -731,7 +729,8 @@ void QZ_PumpEvents (_THIS) ...@@ -731,7 +729,8 @@ void QZ_PumpEvents (_THIS)
/* Update activity every five seconds to prevent screensaver. --ryan. */ /* Update activity every five seconds to prevent screensaver. --ryan. */
if (!allow_screensaver) { if (!allow_screensaver) {
nowTicks = SDL_GetTicks(); static Uint32 screensaverTicks;
Uint32 nowTicks = SDL_GetTicks();
if ((nowTicks - screensaverTicks) > 5000) if ((nowTicks - screensaverTicks) > 5000)
{ {
UpdateSystemActivity(UsrActivity); UpdateSystemActivity(UsrActivity);
......
...@@ -188,8 +188,17 @@ static int QZ_VideoInit (_THIS, SDL_PixelFormat *video_format) { ...@@ -188,8 +188,17 @@ static int QZ_VideoInit (_THIS, SDL_PixelFormat *video_format) {
mode_list = CGDisplayAvailableModes (display_id); mode_list = CGDisplayAvailableModes (display_id);
palette = CGPaletteCreateDefaultColorPalette (); palette = CGPaletteCreateDefaultColorPalette ();
/* Allow environment override of screensaver disable. */
env = SDL_getenv("SDL_VIDEO_ALLOW_SCREENSAVER"); env = SDL_getenv("SDL_VIDEO_ALLOW_SCREENSAVER");
allow_screensaver = ( env && SDL_atoi(env) ) ? YES : NO; if ( env ) {
allow_screensaver = SDL_atoi(env);
} else {
#ifdef SDL_VIDEO_DISABLE_SCREENSAVER
allow_screensaver = 0;
#else
allow_screensaver = 1;
#endif
}
/* Gather some information that is useful to know about the display */ /* Gather some information that is useful to know about the display */
CFNumberGetValue (CFDictionaryGetValue (save_mode, kCGDisplayBitsPerPixel), CFNumberGetValue (CFDictionaryGetValue (save_mode, kCGDisplayBitsPerPixel),
......
...@@ -227,7 +227,7 @@ LRESULT DIB_HandleMessage(_THIS, HWND hwnd, UINT msg, WPARAM wParam, LPARAM lPar ...@@ -227,7 +227,7 @@ LRESULT DIB_HandleMessage(_THIS, HWND hwnd, UINT msg, WPARAM wParam, LPARAM lPar
case WM_SYSCOMMAND: { case WM_SYSCOMMAND: {
const DWORD val = (DWORD) (wParam & 0xFFF0); const DWORD val = (DWORD) (wParam & 0xFFF0);
if ((val == SC_SCREENSAVE) || (val == SC_MONITORPOWER)) { if ((val == SC_SCREENSAVE) || (val == SC_MONITORPOWER)) {
if (!this->hidden->allow_screensaver) { if (!allow_screensaver) {
/* Note that this doesn't stop anything on Vista /* Note that this doesn't stop anything on Vista
if the screensaver has a password. */ if the screensaver has a password. */
return(0); return(0);
......
...@@ -396,7 +396,15 @@ int DIB_VideoInit(_THIS, SDL_PixelFormat *vformat) ...@@ -396,7 +396,15 @@ int DIB_VideoInit(_THIS, SDL_PixelFormat *vformat)
/* Allow environment override of screensaver disable. */ /* Allow environment override of screensaver disable. */
env = SDL_getenv("SDL_VIDEO_ALLOW_SCREENSAVER"); env = SDL_getenv("SDL_VIDEO_ALLOW_SCREENSAVER");
this->hidden->allow_screensaver = ( (env && SDL_atoi(env)) ? 1 : 0 ); if ( env ) {
allow_screensaver = SDL_atoi(env);
} else {
#ifdef SDL_VIDEO_DISABLE_SCREENSAVER
allow_screensaver = 0;
#else
allow_screensaver = 1;
#endif
}
/* We're done! */ /* We're done! */
return(0); return(0);
......
...@@ -43,8 +43,6 @@ struct SDL_PrivateVideoData { ...@@ -43,8 +43,6 @@ struct SDL_PrivateVideoData {
LOGPALETTE *screen_logpal; LOGPALETTE *screen_logpal;
BOOL grab_palette; BOOL grab_palette;
int allow_screensaver;
#define NUM_MODELISTS 4 /* 8, 16, 24, and 32 bits-per-pixel */ #define NUM_MODELISTS 4 /* 8, 16, 24, and 32 bits-per-pixel */
int SDL_nummodes[NUM_MODELISTS]; int SDL_nummodes[NUM_MODELISTS];
SDL_Rect **SDL_modelist[NUM_MODELISTS]; SDL_Rect **SDL_modelist[NUM_MODELISTS];
...@@ -56,6 +54,9 @@ struct SDL_PrivateVideoData { ...@@ -56,6 +54,9 @@ struct SDL_PrivateVideoData {
int supportRotation; /* for Pocket PC devices */ int supportRotation; /* for Pocket PC devices */
DWORD origRotation; /* for Pocket PC devices */ DWORD origRotation; /* for Pocket PC devices */
#endif #endif
/* Screensaver settings */
int allow_screensaver;
}; };
/* Old variable names */ /* Old variable names */
#define screen_bmp (this->hidden->screen_bmp) #define screen_bmp (this->hidden->screen_bmp)
...@@ -64,5 +65,6 @@ struct SDL_PrivateVideoData { ...@@ -64,5 +65,6 @@ struct SDL_PrivateVideoData {
#define grab_palette (this->hidden->grab_palette) #define grab_palette (this->hidden->grab_palette)
#define SDL_nummodes (this->hidden->SDL_nummodes) #define SDL_nummodes (this->hidden->SDL_nummodes)
#define SDL_modelist (this->hidden->SDL_modelist) #define SDL_modelist (this->hidden->SDL_modelist)
#define allow_screensaver (this->hidden->allow_screensaver)
#endif /* _SDL_dibvideo_h */ #endif /* _SDL_dibvideo_h */
...@@ -920,6 +920,16 @@ void X11_PumpEvents(_THIS) ...@@ -920,6 +920,16 @@ void X11_PumpEvents(_THIS)
{ {
int pending; int pending;
/* Update activity every five seconds to prevent screensaver. --ryan. */
if (!allow_screensaver) {
static Uint32 screensaverTicks;
Uint32 nowTicks = SDL_GetTicks();
if ((nowTicks - screensaverTicks) > 5000) {
XResetScreenSaver(SDL_Display);
screensaverTicks = nowTicks;
}
}
/* Keep processing pending events */ /* Keep processing pending events */
pending = 0; pending = 0;
while ( X11_Pending(SDL_Display) ) { while ( X11_Pending(SDL_Display) ) {
...@@ -1389,67 +1399,3 @@ void X11_InitOSKeymap(_THIS) ...@@ -1389,67 +1399,3 @@ void X11_InitOSKeymap(_THIS)
X11_InitKeymap(); X11_InitKeymap();
} }
void X11_SaveScreenSaver(Display *display, int *saved_timeout, BOOL *dpms)
{
int timeout, interval, prefer_blank, allow_exp;
XGetScreenSaver(display, &timeout, &interval, &prefer_blank, &allow_exp);
*saved_timeout = timeout;
#if SDL_VIDEO_DRIVER_X11_DPMS
if ( SDL_X11_HAVE_DPMS ) {
int dummy;
if ( DPMSQueryExtension(display, &dummy, &dummy) ) {
CARD16 state;
DPMSInfo(display, &state, dpms);
}
}
#else
*dpms = 0;
#endif /* SDL_VIDEO_DRIVER_X11_DPMS */
}
void X11_DisableScreenSaver(_THIS, Display *display)
{
int timeout, interval, prefer_blank, allow_exp;
if (this->hidden->allow_screensaver) {
return;
}
XGetScreenSaver(display, &timeout, &interval, &prefer_blank, &allow_exp);
timeout = 0;
XSetScreenSaver(display, timeout, interval, prefer_blank, allow_exp);
#if SDL_VIDEO_DRIVER_X11_DPMS
if ( SDL_X11_HAVE_DPMS ) {
int dummy;
if ( DPMSQueryExtension(display, &dummy, &dummy) ) {
DPMSDisable(display);
}
}
#endif /* SDL_VIDEO_DRIVER_X11_DPMS */
}
void X11_RestoreScreenSaver(_THIS, Display *display, int saved_timeout, BOOL dpms)
{
int timeout, interval, prefer_blank, allow_exp;
if (this->hidden->allow_screensaver) {
return;
}
XGetScreenSaver(display, &timeout, &interval, &prefer_blank, &allow_exp);
timeout = saved_timeout;
XSetScreenSaver(display, timeout, interval, prefer_blank, allow_exp);
#if SDL_VIDEO_DRIVER_X11_DPMS
if ( SDL_X11_HAVE_DPMS ) {
int dummy;
if ( DPMSQueryExtension(display, &dummy, &dummy) ) {
if ( dpms ) {
DPMSEnable(display);
}
}
}
#endif /* SDL_VIDEO_DRIVER_X11_DPMS */
}
...@@ -27,7 +27,3 @@ ...@@ -27,7 +27,3 @@
extern void X11_InitOSKeymap(_THIS); extern void X11_InitOSKeymap(_THIS);
extern void X11_PumpEvents(_THIS); extern void X11_PumpEvents(_THIS);
extern void X11_SetKeyboardState(Display *display, const char *key_vec); extern void X11_SetKeyboardState(Display *display, const char *key_vec);
extern void X11_SaveScreenSaver(Display *display, int *saved_timeout, BOOL *dpms);
extern void X11_DisableScreenSaver(_THIS, Display *display);
extern void X11_RestoreScreenSaver(_THIS, Display *display, int saved_timeout, BOOL dpms);
...@@ -56,7 +56,6 @@ SDL_X11_SYM(int,XFreePixmap,(Display* a,Pixmap b),(a,b),return) ...@@ -56,7 +56,6 @@ SDL_X11_SYM(int,XFreePixmap,(Display* a,Pixmap b),(a,b),return)
SDL_X11_SYM(int,XGetErrorDatabaseText,(Display* a,_Xconst char* b,_Xconst char* c,_Xconst char* d,char* e,int f),(a,b,c,d,e,f),return) SDL_X11_SYM(int,XGetErrorDatabaseText,(Display* a,_Xconst char* b,_Xconst char* c,_Xconst char* d,char* e,int f),(a,b,c,d,e,f),return)
SDL_X11_SYM(XModifierKeymap*,XGetModifierMapping,(Display* a),(a),return) SDL_X11_SYM(XModifierKeymap*,XGetModifierMapping,(Display* a),(a),return)
SDL_X11_SYM(int,XGetPointerControl,(Display* a,int* b,int* c,int* d),(a,b,c,d),return) SDL_X11_SYM(int,XGetPointerControl,(Display* a,int* b,int* c,int* d),(a,b,c,d),return)
SDL_X11_SYM(int,XGetScreenSaver,(Display* a,int* b,int* c,int* d, int* e),(a,b,c,d,e),return)
SDL_X11_SYM(XVisualInfo*,XGetVisualInfo,(Display* a,long b,XVisualInfo* c,int* d),(a,b,c,d),return) SDL_X11_SYM(XVisualInfo*,XGetVisualInfo,(Display* a,long b,XVisualInfo* c,int* d),(a,b,c,d),return)
SDL_X11_SYM(XWMHints*,XGetWMHints,(Display* a,Window b),(a,b),return) SDL_X11_SYM(XWMHints*,XGetWMHints,(Display* a,Window b),(a,b),return)
SDL_X11_SYM(Status,XGetWindowAttributes,(Display* a,Window b,XWindowAttributes* c),(a,b,c),return) SDL_X11_SYM(Status,XGetWindowAttributes,(Display* a,Window b,XWindowAttributes* c),(a,b,c),return)
...@@ -85,13 +84,13 @@ SDL_X11_SYM(int,XQueryKeymap,(Display* a,char *b),(a,b),return) ...@@ -85,13 +84,13 @@ SDL_X11_SYM(int,XQueryKeymap,(Display* a,char *b),(a,b),return)
SDL_X11_SYM(Bool,XQueryPointer,(Display* a,Window b,Window* c,Window* d,int* e,int* f,int* g,int* h,unsigned int* i),(a,b,c,d,e,f,g,h,i),return) SDL_X11_SYM(Bool,XQueryPointer,(Display* a,Window b,Window* c,Window* d,int* e,int* f,int* g,int* h,unsigned int* i),(a,b,c,d,e,f,g,h,i),return)
SDL_X11_SYM(int,XRaiseWindow,(Display* a,Window b),(a,b),return) SDL_X11_SYM(int,XRaiseWindow,(Display* a,Window b),(a,b),return)
SDL_X11_SYM(int,XReparentWindow,(Display* a,Window b,Window c,int d,int e),(a,b,c,d,e),return) SDL_X11_SYM(int,XReparentWindow,(Display* a,Window b,Window c,int d,int e),(a,b,c,d,e),return)
SDL_X11_SYM(int,XResetScreenSaver,(Display* a),(a),return)
SDL_X11_SYM(int,XResizeWindow,(Display* a,Window b,unsigned int c,unsigned int d),(a,b,c,d),return) SDL_X11_SYM(int,XResizeWindow,(Display* a,Window b,unsigned int c,unsigned int d),(a,b,c,d),return)
SDL_X11_SYM(int,XSelectInput,(Display* a,Window b,long c),(a,b,c),return) SDL_X11_SYM(int,XSelectInput,(Display* a,Window b,long c),(a,b,c),return)
SDL_X11_SYM(Status,XSendEvent,(Display* a,Window b,Bool c,long d,XEvent* e),(a,b,c,d,e),return) SDL_X11_SYM(Status,XSendEvent,(Display* a,Window b,Bool c,long d,XEvent* e),(a,b,c,d,e),return)
SDL_X11_SYM(int,XSetClassHint,(Display* a,Window b,XClassHint* c),(a,b,c),return) SDL_X11_SYM(int,XSetClassHint,(Display* a,Window b,XClassHint* c),(a,b,c),return)
SDL_X11_SYM(XErrorHandler,XSetErrorHandler,(XErrorHandler a),(a),return) SDL_X11_SYM(XErrorHandler,XSetErrorHandler,(XErrorHandler a),(a),return)
SDL_X11_SYM(XIOErrorHandler,XSetIOErrorHandler,(XIOErrorHandler a),(a),return) SDL_X11_SYM(XIOErrorHandler,XSetIOErrorHandler,(XIOErrorHandler a),(a),return)
SDL_X11_SYM(int,XSetScreenSaver,(Display* a,int b,int c,int d,int e),(a,b,c,d,e),return)
SDL_X11_SYM(int,XSetTransientForHint,(Display* a,Window b,Window c),(a,b,c),return) SDL_X11_SYM(int,XSetTransientForHint,(Display* a,Window b,Window c),(a,b,c),return)
SDL_X11_SYM(int,XSetWMHints,(Display* a,Window b,XWMHints* c),(a,b,c),return) SDL_X11_SYM(int,XSetWMHints,(Display* a,Window b,XWMHints* c),(a,b,c),return)
SDL_X11_SYM(void,XSetTextProperty,(Display* a,Window b,XTextProperty* c,Atom d),(a,b,c,d),) SDL_X11_SYM(void,XSetTextProperty,(Display* a,Window b,XTextProperty* c,Atom d),(a,b,c,d),)
...@@ -192,14 +191,5 @@ SDL_X11_SYM(Status,XRRSetScreenConfig,(Display *dpy, XRRScreenConfiguration *con ...@@ -192,14 +191,5 @@ SDL_X11_SYM(Status,XRRSetScreenConfig,(Display *dpy, XRRScreenConfiguration *con
SDL_X11_SYM(void,XRRFreeScreenConfigInfo,(XRRScreenConfiguration *config),(config),) SDL_X11_SYM(void,XRRFreeScreenConfigInfo,(XRRScreenConfiguration *config),(config),)
#endif #endif
/* DPMS support */
#if SDL_VIDEO_DRIVER_X11_DPMS
SDL_X11_MODULE(DPMS)
SDL_X11_SYM(Status,DPMSQueryExtension,(Display *dpy,int *major_versionp,int *minor_versionp),(dpy,major_versionp,minor_versionp),return)
SDL_X11_SYM(Status,DPMSInfo,(Display *dpy,CARD16 *state,BOOL *onoff),(dpy,state,onoff),return)
SDL_X11_SYM(Status,DPMSEnable,(Display *dpy),(dpy),return)
SDL_X11_SYM(Status,DPMSDisable,(Display *dpy),(dpy),return)
#endif
/* end of SDL_x11sym.h ... */ /* end of SDL_x11sym.h ... */
...@@ -556,7 +556,7 @@ static void create_aux_windows(_THIS) ...@@ -556,7 +556,7 @@ static void create_aux_windows(_THIS)
static int X11_VideoInit(_THIS, SDL_PixelFormat *vformat) static int X11_VideoInit(_THIS, SDL_PixelFormat *vformat)
{ {
const char *env = NULL; const char *env;
char *display; char *display;
int i; int i;
...@@ -669,11 +669,15 @@ static int X11_VideoInit(_THIS, SDL_PixelFormat *vformat) ...@@ -669,11 +669,15 @@ static int X11_VideoInit(_THIS, SDL_PixelFormat *vformat)
/* Allow environment override of screensaver disable. */ /* Allow environment override of screensaver disable. */
env = SDL_getenv("SDL_VIDEO_ALLOW_SCREENSAVER"); env = SDL_getenv("SDL_VIDEO_ALLOW_SCREENSAVER");
this->hidden->allow_screensaver = ( (env && SDL_atoi(env)) ? 1 : 0 ); if ( env ) {
allow_screensaver = SDL_atoi(env);
/* Save DPMS and screensaver settings */ } else {
X11_SaveScreenSaver(SDL_Display, &screensaver_timeout, &dpms_enabled); #ifdef SDL_VIDEO_DISABLE_SCREENSAVER
X11_DisableScreenSaver(this, SDL_Display); allow_screensaver = 0;
#else
allow_screensaver = 1;
#endif
}
/* See if we have been passed a window to use */ /* See if we have been passed a window to use */
SDL_windowid = SDL_getenv("SDL_WINDOWID"); SDL_windowid = SDL_getenv("SDL_WINDOWID");
...@@ -1506,9 +1510,6 @@ void X11_VideoQuit(_THIS) ...@@ -1506,9 +1510,6 @@ void X11_VideoQuit(_THIS)
X11_SwapVidModeGamma(this); X11_SwapVidModeGamma(this);
} }
/* Restore DPMS and screensaver settings */
X11_RestoreScreenSaver(this, SDL_Display, screensaver_timeout, dpms_enabled);
/* Free that blank cursor */ /* Free that blank cursor */
if ( SDL_BlankCursor != NULL ) { if ( SDL_BlankCursor != NULL ) {
this->FreeWMCursor(this, SDL_BlankCursor); this->FreeWMCursor(this, SDL_BlankCursor);
......
...@@ -46,9 +46,6 @@ ...@@ -46,9 +46,6 @@
#if SDL_VIDEO_DRIVER_X11_XME #if SDL_VIDEO_DRIVER_X11_XME
#include "../Xext/extensions/xme.h" #include "../Xext/extensions/xme.h"
#endif #endif
#if SDL_VIDEO_DRIVER_X11_DPMS
#include <X11/extensions/dpms.h>
#endif
#include "SDL_x11dyn.h" #include "SDL_x11dyn.h"
...@@ -139,8 +136,6 @@ struct SDL_PrivateVideoData { ...@@ -139,8 +136,6 @@ struct SDL_PrivateVideoData {
int use_xme; int use_xme;
int currently_fullscreen; int currently_fullscreen;
int allow_screensaver;
/* Automatic mode switching support (entering/leaving fullscreen) */ /* Automatic mode switching support (entering/leaving fullscreen) */
Uint32 switch_waiting; Uint32 switch_waiting;
Uint32 switch_time; Uint32 switch_time;
...@@ -158,8 +153,7 @@ struct SDL_PrivateVideoData { ...@@ -158,8 +153,7 @@ struct SDL_PrivateVideoData {
short *iconcolors; /* List of colors used by the icon */ short *iconcolors; /* List of colors used by the icon */
/* Screensaver settings */ /* Screensaver settings */
int screensaver_timeout; int allow_screensaver;
BOOL dpms_enabled;
}; };
/* Old variable names */ /* Old variable names */
...@@ -210,8 +204,8 @@ struct SDL_PrivateVideoData { ...@@ -210,8 +204,8 @@ struct SDL_PrivateVideoData {
#define gamma_saved (this->hidden->gamma_saved) #define gamma_saved (this->hidden->gamma_saved)
#define gamma_changed (this->hidden->gamma_changed) #define gamma_changed (this->hidden->gamma_changed)
#define SDL_iconcolors (this->hidden->iconcolors) #define SDL_iconcolors (this->hidden->iconcolors)
#define screensaver_timeout (this->hidden->screensaver_timeout) #define allow_screensaver (this->hidden->allow_screensaver)
#define dpms_enabled (this->hidden->dpms_enabled)
/* Some versions of XFree86 have bugs - detect if this is one of them */ /* Some versions of XFree86 have bugs - detect if this is one of them */
#define BUGGY_XFREE86(condition, buggy_version) \ #define BUGGY_XFREE86(condition, buggy_version) \
((SDL_strcmp(ServerVendor(SDL_Display), "The XFree86 Project, Inc") == 0) && \ ((SDL_strcmp(ServerVendor(SDL_Display), "The XFree86 Project, Inc") == 0) && \
......
...@@ -85,10 +85,12 @@ void SDL_XBIOS_CentscreenSetmode(_THIS, int width, int height, int planes) ...@@ -85,10 +85,12 @@ void SDL_XBIOS_CentscreenSetmode(_THIS, int width, int height, int planes)
newmode.plan = planes; newmode.plan = planes;
Vwrite(0, &newmode, &curmode); Vwrite(0, &newmode, &curmode);
#ifdef SDL_VIDEO_DISABLE_SCREENSAVER
/* Disable screensaver */ /* Disable screensaver */
Vread(&newmode); Vread(&newmode);
newmode.mode &= ~(CSCREEN_SAVER|CSCREEN_ENERGYSTAR); newmode.mode &= ~(CSCREEN_SAVER|CSCREEN_ENERGYSTAR);
Vwrite(0, &newmode, &curmode); Vwrite(0, &newmode, &curmode);
#endif /* SDL_VIDEO_DISABLE_SCREENSAVER */
} }
void SDL_XBIOS_CentscreenRestore(_THIS, int prev_handle) void SDL_XBIOS_CentscreenRestore(_THIS, int prev_handle)
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment