Win32 disabling screensaver

Sadly, it doesn’t look like SDL has any support for disabling the
screensaver under Win32 - my #1 target platform. This is extremely
unfortunate, because joystick events don’t stop an imminent
screensaver from coming up. I’ve written the following code, but I am
looking for a better way to do it:

#ifdef WIN32
#include<windows.h>
#endif

// Call at SDL_Init() time
void DisableScreensaver( void )
{
#ifdef WIN32
BOOL active;

SystemParametersInfo(SPI_GETSCREENSAVEACTIVE, FALSE, &active, 0 );

if ( active )
{
   atexit( EnableScreensaver );
   SystemParametersInfo(SPI_SETSCREENSAVEACTIVE, FALSE, 0, 0);
}

#endif
}

void EnableScreensaver( void )
{
#ifdef WIN32
SystemParametersInfo(SPI_SETSCREENSAVEACTIVE, TRUE, 0, 0);
#endif
}

This works fine unless the program crashes or exits abnormally, where
atexit()'s bindings are not called, disabling the screensaver in the
OS for good. If there is a better way I can do this while remaining
with SDL, I would jump at the chance to do so.

Thanks–
Michael L. Labbe
http://www.threewavesoftware.com

[…disabling the screensaver…]

This works fine unless the program crashes or exits abnormally,
where atexit()'s bindings are not called, disabling the screensaver
in the OS for good. If there is a better way I can do this while
remaining with SDL, I would jump at the chance to do so.

Sounds like the SDL parachute should do the restoring. And this sounds
like a useful 1.3 feature. :slight_smile: I think there are patches and
solutions for a few platforms floating around…

//David Olofson - Programmer, Composer, Open Source Advocate

.- Audiality -----------------------------------------------.
| Free/Open Source audio engine for games and multimedia. |
| MIDI, modular synthesis, real time effects, scripting,… |
`-----------------------------------> http://audiality.org -’
http://olofson.nethttp://www.reologica.se —On Sunday 21 September 2003 19.15, Michael L. Labbe wrote:

Attached is the patch we use with StepMania. It’s incomplete: it should
be optional. (Normal apps that aren’t normally controlled with a joystick
shouldn’t arbitrarily disable the joystick.)

I didn’t submit this patch before since there’s no way to disable it by
the application (and not wanting to spend the time to improve the patch to
expose something like SDL_AllowScreenSaver). I just noticed that the
DX5 driver does this already, though, so it’s probably not an issue.On Sun, Sep 21, 2003 at 10:15:09AM -0700, Michael L. Labbe wrote:

Sadly, it doesn’t look like SDL has any support for disabling the
screensaver under Win32 - my #1 target platform. This is extremely
unfortunate, because joystick events don’t stop an imminent
screensaver from coming up. I’ve written the following code, but I am
looking for a better way to do it:


Glenn Maynard
-------------- next part --------------
Only in .: CVS
diff -u /home/glenn/SDL-1.2.6/src/video/windib/SDL_dibevents.c ./SDL_dibevents.c
— /home/glenn/SDL-1.2.6/src/video/windib/SDL_dibevents.c 2003-08-30 15:13:12.000000000 -0400
+++ ./SDL_dibevents.c 2003-09-22 18:43:54.000000000 -0400
@@ -160,6 +160,15 @@
}
return(0);

+#if defined(SC_SCREENSAVE) || defined(SC_MONITORPOWER)

  •   case WM_SYSCOMMAND: {
    
  •   	if ((wParam&0xFFF0)==SC_SCREENSAVE ||
    
  •   		(wParam&0xFFF0)==SC_MONITORPOWER)
    
  •   			return(0);
    
  •   }
    
  •   /* Fall through to default processing */
    

+#endif /* SC_SCREENSAVE || SC_MONITORPOWER /
+
default: {
/
Only post the event if we’re watching for it */
if ( SDL_ProcessEvents[SDL_SYSWMEVENT] == SDL_ENABLE ) {

Sam, are you considering this patch? It’s identical to the code in the
dx5 driver.–
Glenn Maynard

Sam, are you considering this patch? It’s identical to the code in the
dx5 driver.

Yup, just busy with work.

Thanks!
-Sam Lantinga, Software Engineer, Blizzard Entertainment

Sam Lantinga wrote:

Sam, are you considering this patch? It’s identical to the code in the
dx5 driver.

Yup, just busy with work.

I just put it in CVS; both the 1.2 and 1.3 branches.

Sam, if there’s no objection, I’ll apply the DirectFB MGA CRTC2 patch, too.

–ryan.

I just put it in CVS; both the 1.2 and 1.3 branches.

Sam, if there’s no objection, I’ll apply the DirectFB MGA CRTC2 patch, too.

Go for it. Please make sure that you don’t add any fixes to the 1.3 branch.
Once the next 1.2.x release is made, I’ll do a diff between the two releases
and apply that to the 1.3 branch, that way I’ll avoid merging changes that are
already in 1.3.

Thanks!
-Sam Lantinga, Software Engineer, Blizzard Entertainment

Go for it. Please make sure that you don’t add any fixes to the 1.3 branch.
Once the next 1.2.x release is made, I’ll do a diff between the two releases
and apply that to the 1.3 branch, that way I’ll avoid merging changes that are
already in 1.3.

Ah, whoops. Didn’t realize that. The screensaver patch is in 1.3, too.
I’ll avoid that in the future.

–ryan.