mirror of https://github.com/bsnes-emu/bsnes.git
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:
parent
f78502e131
commit
0a9d15a978
|
@ -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 {
|
||||
|
|
Loading…
Reference in New Issue