setScreenSaverEnabled(false) not working on mac?

Hi guys,

I’m trying to disable the screensaver from appearing in my app. It seems to work on widows, but not on the mac build.
I’m using the git version of juce as of 14-05-2011, built on 10.6 with 10.5 base sdk.

The code i’m using is this:

void MainWindow::activeWindowStatusChanged() { if(isActiveWindow()) Desktop::setScreenSaverEnabled(false); }

As you see disable the screensaver every time it gains focus.

Any suggestions would be greatly appreciated.

And have you actually debugged it to make sure the function is getting called?

Why yes of course…

If i follow the debugger to, it goes to line 321:

    [code]if (screenSaverDisablerID == 0)
       #if defined (MAC_OS_X_VERSION_10_6) && MAC_OS_X_VERSION_MAX_ALLOWED >= MAC_OS_X_VERSION_10_6
        IOPMAssertionCreateWithName (kIOPMAssertionTypeNoIdleSleep, kIOPMAssertionLevelOn,
                                     CFSTR ("Juce"), &screenSaverDisablerID);
        IOPMAssertionCreate (kIOPMAssertionTypeNoIdleSleep, kIOPMAssertionLevelOn, <---- THIS LINE

Well that’s the standard code for disabling the screensaver… Did you check that screenSaverDisablerID gets set to a non-null value?

Yeah it’s non-zero. Maybe I’m calling this from the wrong thread? I presume any activeWindowStatusChanged callback gets called from the message thread…

There’s no obvious reason why it’d need to be called by the message thread, but I guess there could be something quirky going on in the OSX code, so it’s worth a try!

Well the code does get called from the message thread. Still no luck though… I’ll try it on 10.5, see if that makes any difference.

I couldn’t get my hands on a 10.5 machine, but I looked up the doc’s for the macro kIOPMAssertionTypeNoIdleSleep


It seems that this only prevents the system from going to sleep, but the docs mention nothing about screen savers.
I take it that the display going to sleep is something different from the screen saver.
Thus far I haven’t found anything in the docs…

One (very ugly) way to do it is calling UpdateSystemActivity(OverallAct) every now and then… But this requires a timer to do it.

Hmm, interesting. I used to use that function, but it disappeared in 64-bit builds, which is why I added the other IO code. But doing a bit of digging, it seems that it’s actually returned again, and shouldn’t have been removed! I’ll see what I can figure out…