[SDL] SDL tampers with display power settings on the sly

Erik esigra at gmail.com
Mon Feb 25 02:29:30 PST 2008

Sam Lantinga skrev:
> SDL turns off screensaver by default because 99% of the applications
> which use SDL are games or media players,
I get the point about media players, but games?!? Games are interactive 
like most other programs. It is not like people start a game and then 
just sit there watching it without doing anything at all for several 
minutes. At least that is *not* how I have played games, and I have 
played plenty of them.

> and authors have often requested this functionality.
100% of users that have set up a screensaver want it to work. Although I 
know that SDL targets developers and they decide whether SDL gets used 
or not.

> In SDL 1.3 it will be an API function, but to preserve API compatibility
> it's controlled by an environment variable in SDL 1.2.
> Still, it's supposed to restore the settings when you call SDL_Quit().
What about the case when an SDL program is running in a window? What 
happens when the window loses focus? Even if an SDL program was supposed 
to disable the screensaver, it  should certainly not do that when 
running in a window in the background (the user is working with another 
program currently).

> it's supposed to restore the settings when you call SDL_Quit(). Is that happening properly in your application?
That is the wrong question. It should be "Does that happen properly in 
*every* application in *every* codepath, even if an exception is thrown, 
the process is killed or something similar?" And even if it would be 
guaranteed to restore the setting at exit, it would still be broken 
while the program is running (even in background).

And what about reentrance? What if program A is started, reads the 
screensaver settings, disables it. Then program B starts, reads the 
screensaver settings (which is to not have a screensaver). Then program 
A terminates and restorest the screensaver setting. Then program B would 
not have the screensaver disabled any more, as it was intended by SDL. 
But when it terminates it will disable the screensaver again (because 
that was the state when it started), and leave the system broken.

I noticed this comment in the code:
"Note that this doesn't stop anything on Vista if the screensaver has a 

So it seems like some systems protect against this kind of tampering and 
put security first. I just tried it on my system and found out that it 
seems just as secure as Vista in this regard. It will lock the session 
and ask for a password after the specified time, even with an SDL 
program running.

Screensavers are important features that users enable for reasons, so a 
library is not supposed to just turn it off at will, directly against 
the user's orders. Some of the reasons that people use screensavers are:
* Lock the session when they have been away for a minute or so (this 
seems to work despite SDL, at least on my system and Vista).
* Prevent people from looking what is on the screen (even if they are 
not doing anything).
* Make the battery time longer. I really hate it when I have been away 
from the computer for a while and some SDL program running in the 
background has drained the battery so that the system has shut off, when 
it should have turned off the display so that almost no energy would 
have been used while I was away.
* Save energy as such (without thinking about battery time).
* Save display hardware.

More information about the SDL mailing list