ES-DE/es-core/src/PowerSaver.cpp

93 lines
2.2 KiB
C++
Raw Normal View History

#include "PowerSaver.h"
#include "AudioManager.h"
#include "Settings.h"
#include <string.h>
bool PowerSaver::mState = false;
bool PowerSaver::mRunningScreenSaver = false;
2017-09-04 02:35:50 +00:00
int PowerSaver::mWakeupTimeout = -1;
int PowerSaver::mScreenSaverTimeout = -1;
PowerSaver::mode PowerSaver::mMode = PowerSaver::DISABLED;
void PowerSaver::init()
{
setState(true);
updateMode();
}
int PowerSaver::getTimeout()
{
if (SDL_GetAudioStatus() == SDL_AUDIO_PAUSED)
AudioManager::getInstance()->deinit();
// Used only for SDL_WaitEventTimeout. Use `getMode()` for modes.
2017-09-04 02:35:50 +00:00
return mRunningScreenSaver ? mWakeupTimeout : mScreenSaverTimeout;
}
void PowerSaver::loadWakeupTime()
{
// TODO : Move this to Screensaver Class
std::string behaviour = Settings::getInstance()->getString("ScreenSaverBehavior");
if (behaviour == "random video")
mWakeupTimeout = Settings::getInstance()->getInt("ScreenSaverSwapVideoTimeout") - getMode();
else if (behaviour == "slideshow")
mWakeupTimeout = Settings::getInstance()->getInt("ScreenSaverSwapImageTimeout") - getMode();
2017-09-04 02:35:50 +00:00
else // Dim and Blank
mWakeupTimeout = -1;
}
void PowerSaver::updateTimeouts()
{
mScreenSaverTimeout = (unsigned int) Settings::getInstance()->getInt("ScreenSaverTime");
mScreenSaverTimeout = mScreenSaverTimeout > 0 ? mScreenSaverTimeout - getMode() : -1;
2017-09-04 02:35:50 +00:00
loadWakeupTime();
}
PowerSaver::mode PowerSaver::getMode()
{
return mMode;
}
void PowerSaver::updateMode()
{
std::string mode = Settings::getInstance()->getString("PowerSaverMode");
if (mode == "disabled") {
mMode = DISABLED;
} else if (mode == "instant") {
mMode = INSTANT;
} else if (mode == "enhanced") {
mMode = ENHANCED;
} else {
mMode = DEFAULT;
}
updateTimeouts();
}
bool PowerSaver::getState()
{
return mState;
}
void PowerSaver::setState(bool state)
{
bool ps_enabled = Settings::getInstance()->getString("PowerSaverMode") != "disabled";
mState = ps_enabled && state;
}
void PowerSaver::runningScreenSaver(bool state)
{
mRunningScreenSaver = state;
2017-09-04 02:35:50 +00:00
if (mWakeupTimeout < mMode)
{
// Disable PS if wake up time is less than mode as PS will never trigger
setState(!state);
}
}
bool PowerSaver::isScreenSaverActive()
{
return mRunningScreenSaver;
}