mirror of
https://github.com/dolphin-emu/dolphin.git
synced 2025-07-21 05:09:34 -06:00
UICommon: Move screensaver code to UICommon
This commit is contained in:
@ -26,6 +26,14 @@
|
||||
#include "UICommon/UICommon.h"
|
||||
#include "UICommon/USBUtils.h"
|
||||
|
||||
#if defined(HAVE_XRANDR) && HAVE_XRANDR
|
||||
#include "UICommon/X11Utils.h"
|
||||
#endif
|
||||
|
||||
#ifdef __APPLE__
|
||||
#include <IOKit/pwr_mgt/IOPMLib.h>
|
||||
#endif
|
||||
|
||||
#include "VideoCommon/VideoBackendBase.h"
|
||||
|
||||
namespace UICommon
|
||||
@ -248,4 +256,61 @@ bool TriggerSTMPowerEvent()
|
||||
return true;
|
||||
}
|
||||
|
||||
#if defined(HAVE_XRANDR) && HAVE_X11
|
||||
void EnableScreenSaver(Display* display, Window win, bool enable)
|
||||
#else
|
||||
void EnableScreenSaver(bool enable)
|
||||
#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 (SConfig::GetInstance().bDisableScreenSaver)
|
||||
{
|
||||
X11Utils::InhibitScreensaver(display, win, !enable);
|
||||
}
|
||||
#endif
|
||||
|
||||
#ifdef _WIN32
|
||||
// Prevents Windows from sleeping, turning off the display, or idling
|
||||
if (enable)
|
||||
{
|
||||
SetThreadExecutionState(ES_CONTINUOUS);
|
||||
}
|
||||
else
|
||||
{
|
||||
EXECUTION_STATE should_screen_save =
|
||||
SConfig::GetInstance().bDisableScreenSaver ? ES_DISPLAY_REQUIRED : 0;
|
||||
SetThreadExecutionState(ES_CONTINUOUS | should_screen_save | ES_SYSTEM_REQUIRED);
|
||||
}
|
||||
#endif
|
||||
|
||||
#ifdef __APPLE__
|
||||
static IOPMAssertionID s_power_assertion = kIOPMNullAssertionID;
|
||||
|
||||
if (SConfig::GetInstance().bDisableScreenSaver)
|
||||
{
|
||||
if (enable)
|
||||
{
|
||||
if (s_power_assertion != kIOPMNullAssertionID)
|
||||
{
|
||||
IOPMAssertionRelease(s_power_assertion);
|
||||
s_power_assertion = kIOPMNullAssertionID;
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
CFStringRef reason_for_activity = CFSTR("Emulation Running");
|
||||
if (IOPMAssertionCreateWithName(kIOPMAssertionTypePreventUserIdleDisplaySleep,
|
||||
kIOPMAssertionLevelOn, reason_for_activity,
|
||||
&s_power_assertion) != kIOReturnSuccess)
|
||||
{
|
||||
s_power_assertion = kIOPMNullAssertionID;
|
||||
}
|
||||
}
|
||||
}
|
||||
#endif
|
||||
}
|
||||
|
||||
} // namespace UICommon
|
||||
|
Reference in New Issue
Block a user