hiro/cocoa: Implement Application::setScreenSaver

Based on code from Dolphin and SDL2.

908d6f8fa0/Source/Core/UICommon/UICommon.cpp (L416)
cf1c192936/src/video/cocoa/SDL_cocoaevents.m (L514)
This commit is contained in:
Sintendo 2020-11-08 10:34:17 +01:00 committed by Screwtapello
parent f78502e131
commit 0a9d15a978
1 changed files with 19 additions and 1 deletions

View File

@ -1,4 +1,5 @@
#if defined(Hiro_Application)
#include <IOKit/pwr_mgt/IOPMLib.h>
@implementation CocoaDelegate : NSObject
@ -92,7 +93,24 @@ auto pApplication::quit() -> void {
}
auto pApplication::setScreenSaver(bool screenSaver) -> void {
//TODO: not implemented
static IOPMAssertionID powerAssertion = kIOPMNullAssertionID;
// do nothing if current already matches desired state
bool current = powerAssertion == kIOPMNullAssertionID;
if(current == screenSaver) return;
@autoreleasepool {
if(screenSaver) {
IOPMAssertionRelease(powerAssertion);
powerAssertion = kIOPMNullAssertionID;
} else {
string reason = {Application::state().name, " screensaver suppression"};
NSString* assertionName = [NSString stringWithUTF8String:reason.data()];
bool success = IOPMAssertionCreateWithName(kIOPMAssertionTypePreventUserIdleDisplaySleep,
kIOPMAssertionLevelOn, (CFStringRef) assertionName, &powerAssertion) != kIOReturnSuccess;
if(success) powerAssertion = kIOPMNullAssertionID;
}
}
}
auto pApplication::initialize() -> void {