2017-07-20 07:07:02 +00:00
|
|
|
#include "PowerSaver.h"
|
2017-11-01 22:21:10 +00:00
|
|
|
|
2017-09-14 01:33:21 +00:00
|
|
|
#include "AudioManager.h"
|
2017-07-20 07:07:02 +00:00
|
|
|
#include "Settings.h"
|
|
|
|
|
2017-08-02 19:56:33 +00:00
|
|
|
bool PowerSaver::mState = false;
|
|
|
|
bool PowerSaver::mRunningScreenSaver = false;
|
2017-07-20 07:07:02 +00:00
|
|
|
|
2017-09-04 02:35:50 +00:00
|
|
|
int PowerSaver::mWakeupTimeout = -1;
|
2017-08-02 19:56:33 +00:00
|
|
|
int PowerSaver::mScreenSaverTimeout = -1;
|
|
|
|
PowerSaver::mode PowerSaver::mMode = PowerSaver::DISABLED;
|
|
|
|
|
|
|
|
void PowerSaver::init()
|
2017-07-20 07:07:02 +00:00
|
|
|
{
|
|
|
|
setState(true);
|
2017-08-02 19:56:33 +00:00
|
|
|
updateMode();
|
2017-07-20 07:07:02 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
int PowerSaver::getTimeout()
|
|
|
|
{
|
2017-09-14 01:33:21 +00:00
|
|
|
if (SDL_GetAudioStatus() == SDL_AUDIO_PAUSED)
|
|
|
|
AudioManager::getInstance()->deinit();
|
|
|
|
|
2017-08-11 17:03:12 +00:00
|
|
|
// 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();
|
2017-09-09 03:45:50 +00:00
|
|
|
else if (behaviour == "slideshow")
|
|
|
|
mWakeupTimeout = Settings::getInstance()->getInt("ScreenSaverSwapImageTimeout") - getMode();
|
2017-09-04 02:35:50 +00:00
|
|
|
else // Dim and Blank
|
|
|
|
mWakeupTimeout = -1;
|
2017-08-02 19:56:33 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
void PowerSaver::updateTimeouts()
|
|
|
|
{
|
|
|
|
mScreenSaverTimeout = (unsigned int) Settings::getInstance()->getInt("ScreenSaverTime");
|
2017-08-11 17:03:12 +00:00
|
|
|
mScreenSaverTimeout = mScreenSaverTimeout > 0 ? mScreenSaverTimeout - getMode() : -1;
|
2017-09-04 02:35:50 +00:00
|
|
|
loadWakeupTime();
|
2017-08-02 19:56:33 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
PowerSaver::mode PowerSaver::getMode()
|
|
|
|
{
|
|
|
|
return mMode;
|
2017-07-20 07:07:02 +00:00
|
|
|
}
|
|
|
|
|
2017-08-02 19:56:33 +00:00
|
|
|
void PowerSaver::updateMode()
|
2017-07-20 07:07:02 +00:00
|
|
|
{
|
|
|
|
std::string mode = Settings::getInstance()->getString("PowerSaverMode");
|
2017-08-02 19:56:33 +00:00
|
|
|
|
2017-07-20 07:07:02 +00:00
|
|
|
if (mode == "disabled") {
|
2017-08-02 19:56:33 +00:00
|
|
|
mMode = DISABLED;
|
2017-07-20 07:07:02 +00:00
|
|
|
} else if (mode == "instant") {
|
2017-08-02 19:56:33 +00:00
|
|
|
mMode = INSTANT;
|
2017-07-20 07:07:02 +00:00
|
|
|
} else if (mode == "enhanced") {
|
2017-08-02 19:56:33 +00:00
|
|
|
mMode = ENHANCED;
|
|
|
|
} else {
|
|
|
|
mMode = DEFAULT;
|
2017-07-20 07:07:02 +00:00
|
|
|
}
|
2017-08-11 17:03:12 +00:00
|
|
|
updateTimeouts();
|
2017-07-20 07:07:02 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
bool PowerSaver::getState()
|
|
|
|
{
|
|
|
|
return mState;
|
|
|
|
}
|
|
|
|
|
|
|
|
void PowerSaver::setState(bool state)
|
|
|
|
{
|
|
|
|
bool ps_enabled = Settings::getInstance()->getString("PowerSaverMode") != "disabled";
|
|
|
|
mState = ps_enabled && state;
|
|
|
|
}
|
|
|
|
|
2017-08-02 19:56:33 +00:00
|
|
|
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);
|
|
|
|
}
|
2017-08-02 19:56:33 +00:00
|
|
|
}
|
2017-08-11 17:03:12 +00:00
|
|
|
|
|
|
|
bool PowerSaver::isScreenSaverActive()
|
|
|
|
{
|
|
|
|
return mRunningScreenSaver;
|
|
|
|
}
|