Prevent Mac Screen Saver

Viewed 191

In older versions of MacOSX, one would use

UpdateSystemActivity(UsrActivity);

In order to reset the screensaver timer.

In modern versions of MacOSX, the most commonly recommended solution is:

static IOPMAssertionID activity_assertion_id = kIOPMNullAssertionID;
IOReturn r = IOPMAssertionDeclareUserActivity(CFSTR("FractalUserActivity"),
               kIOPMUserActiveLocal, &activity_assertion_id);

or

IOReturn result = IOPMAssertionCreateWithName(
            kIOPMAssertionTypeNoDisplaySleep,
            kIOPMAssertionLevelOn,
            CFSTR("FractalNewFrameActivity"),
            &power_assertion_id);
IOPMAssertionRelease(power_assertion_id);

However, neither of these in my testing appear to actually reset the MacOSX Screensaver timer. When I set my screensaver to 1minute, but run the above code in a loop at 60FPS, the screensaver still turns on eventually.

Often it's said that IOPMAssertionRelease should only be called after the screen no longer wants to be held awake, but I don't think that's the functionality I need. I need to simply reset the 1min screensaver timer. Because, the timer should be reset every single time a framebuffer gets rendered [due to the application changing what's being displayed]. But, if no frame gets rendered in a 1minute interval, the screensaver should be displayed.

Is there no way to do this in modern versions of MacOSX? Chromium currently exhibits the exact feature that I desire. When watching a YouTube Video, 1minute after the video ends, is when the screensaver will turn on, regardless of how long the youtube video is, even if it's e.g. a 10min Youtube Video.

~ I don't want to hardcode 1minute, since obviously it should regardless of what your screensaver time setting is.

0 Answers
Related