setScreenSaverEnabled(false) not working on mac?


#1

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.


#2

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


#3

Why yes of course…

If i follow the debugger to juce_mac_MiscUtilities.mm, 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);
       #else
        IOPMAssertionCreate (kIOPMAssertionTypeNoIdleSleep, kIOPMAssertionLevelOn, <---- THIS LINE
                             &screenSaverDisablerID);
       #endif
    }[/code]

#4

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


#5

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…


#6

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!


#7

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.


#8

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

Here: http://developer.apple.com/library/mac/#documentation/Darwin/Reference/IOKit/IOPMLib_h/%23//apple_ref/c/func/IOPMAssertionCreateWithName

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…


#9

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


#10

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…