moved sleep prevention code for further abstraction, implemented macOS

This commit is contained in:
itsmattkc
2021-11-11 16:14:37 -08:00
parent 65446fd70b
commit ab8d9e14e8
5 changed files with 53 additions and 10 deletions
+34
View File
@@ -0,0 +1,34 @@
#include "viewerpreventsleep.h"
#include <QtGlobal>
#if defined(Q_OS_WINDOWS)
#include <winbase.h>
#elif defined(Q_OS_MAC)
#include <IOKit/pwr_mgt/IOPMLib.h>
#endif
namespace olive {
#if defined(Q_OS_MAC)
IOPMAssertionID assertionID = 0;
#endif
void PreventSleep(bool on)
{
#if defined(Q_OS_WINDOWS)
SetThreadExecutionState(on ? ES_DISPLAY_REQUIRED | ES_CONTINUOUS : ES_CONTINUOUS);
#elif defined(Q_OS_MAC)
if (on) {
static const CFStringRef reasonForActivity = CFSTR("Video Playback");
IOPMAssertionCreateWithName(kIOPMAssertionTypeNoDisplaySleep,
kIOPMAssertionLevelOn, reasonForActivity, &assertionID);
} else if (assertionID) {
IOPMAssertionRelease(assertionID);
assertionID = 0;
}
#endif
}
}