Sleep broken on Mac

I’ve noticed that when my SDL app is running on the Mac, the
Mac will NOT go to sleep. Shut down the app, wait long
enough, and it WILL sleep - so the SDL app definitely
seems to be the cause.

I had the same problem on Windows, and fixed it by adding
this line within the WinMessage function in sdl_sysevents.c :

case WM_POWERBROADCAST :
return DefWindowProc(hwnd, msg, wParam, lParam);

(i.e. this message was getting ‘eaten’ by SDL, preventing
normal processing for power/sleep-related stuff.)

I assume something similar may be going on for the Mac,
but I’m much less familiar with Mac’s messaging stuff.

Can anybody tell me what, if anything I can add/change
to get it working on the Mac?

I’ve noticed that when my SDL app is running on the Mac, the
Mac will NOT go to sleep. Shut down the app, wait long
enough, and it WILL sleep - so the SDL app definitely
seems to be the cause.

Technically it’s not “broken”…it’s that we don’t want the screensaver
to trigger when a game is running.

If you want to disable this, chop the following code out of
QZ_PumpEvents() in SDL12/src/video/quartz/SDL_QuartzEvents.m …

/* Update activity every five seconds to prevent screensaver. --ryan. */
static Uint32 screensaverTicks = 0;
Uint32 nowTicks = SDL_GetTicks();
if ((nowTicks - screensaverTicks) > 5000)
{
UpdateSystemActivity(UsrActivity);
screensaverTicks = nowTicks;
}

–ryan.

SDL_HINT_VIDEO_ALLOW_SCREENSAVER has since been added as a solution