Merge pull request #8613 from jordan-woyak/expose-disable-ss

Config: Expose "DisableScreenSaver" in the UI and default it to true.
This commit is contained in:
Léo Lam
2020-10-20 01:20:24 +02:00
committed by GitHub
8 changed files with 40 additions and 49 deletions

View File

@ -397,57 +397,42 @@ bool TriggerSTMPowerEvent()
}
#if defined(HAVE_XRANDR) && HAVE_XRANDR
void EnableScreenSaver(Window win, bool enable)
void InhibitScreenSaver(Window win, bool inhibit)
#else
void EnableScreenSaver(bool enable)
void InhibitScreenSaver(bool inhibit)
#endif
{
// Inhibit the screensaver. Depending on the operating system this may also
// disable low-power states and/or screen dimming.
#if defined(HAVE_X11) && HAVE_X11
if (Config::Get(Config::MAIN_DISABLE_SCREENSAVER))
{
X11Utils::InhibitScreensaver(win, !enable);
}
X11Utils::InhibitScreensaver(win, inhibit);
#endif
#ifdef _WIN32
// Prevents Windows from sleeping, turning off the display, or idling
if (enable)
{
SetThreadExecutionState(ES_CONTINUOUS);
}
else
{
EXECUTION_STATE should_screen_save =
Config::Get(Config::MAIN_DISABLE_SCREENSAVER) ? ES_DISPLAY_REQUIRED : 0;
SetThreadExecutionState(ES_CONTINUOUS | should_screen_save | ES_SYSTEM_REQUIRED);
}
SetThreadExecutionState(ES_CONTINUOUS |
(inhibit ? (ES_DISPLAY_REQUIRED | ES_SYSTEM_REQUIRED) : 0));
#endif
#ifdef __APPLE__
static IOPMAssertionID s_power_assertion = kIOPMNullAssertionID;
if (Config::Get(Config::MAIN_DISABLE_SCREENSAVER))
if (inhibit)
{
if (enable)
CFStringRef reason_for_activity = CFSTR("Emulation Running");
if (IOPMAssertionCreateWithName(kIOPMAssertionTypePreventUserIdleDisplaySleep,
kIOPMAssertionLevelOn, reason_for_activity,
&s_power_assertion) != kIOReturnSuccess)
{
if (s_power_assertion != kIOPMNullAssertionID)
{
IOPMAssertionRelease(s_power_assertion);
s_power_assertion = kIOPMNullAssertionID;
}
s_power_assertion = kIOPMNullAssertionID;
}
else
}
else
{
if (s_power_assertion != kIOPMNullAssertionID)
{
CFStringRef reason_for_activity = CFSTR("Emulation Running");
if (IOPMAssertionCreateWithName(kIOPMAssertionTypePreventUserIdleDisplaySleep,
kIOPMAssertionLevelOn, reason_for_activity,
&s_power_assertion) != kIOReturnSuccess)
{
s_power_assertion = kIOPMNullAssertionID;
}
IOPMAssertionRelease(s_power_assertion);
s_power_assertion = kIOPMNullAssertionID;
}
}
#endif

View File

@ -14,9 +14,9 @@ void Init();
void Shutdown();
#if defined(HAVE_XRANDR) && HAVE_XRANDR
void EnableScreenSaver(unsigned long win, bool enable);
void InhibitScreenSaver(unsigned long win, bool enable);
#else
void EnableScreenSaver(bool enable);
void InhibitScreenSaver(bool enable);
#endif
// Calls std::locale::global, selecting a fallback locale if the