Merge pull request #199 from hex007/move-pstimeout

PowerSaver Updates
This commit is contained in:
Jools Wills 2017-08-04 02:46:44 +01:00 committed by GitHub
commit 244bf47779
6 changed files with 82 additions and 56 deletions

View file

@ -4,6 +4,7 @@
#endif
#include "components/VideoVlcComponent.h"
#include "platform.h"
#include "PowerSaver.h"
#include "Renderer.h"
#include "Settings.h"
#include "SystemData.h"
@ -100,6 +101,7 @@ void SystemScreenSaver::startScreenSaver()
mVideoScreensaver->setVideo(path);
mVideoScreensaver->setScreensaverMode(true);
mVideoScreensaver->onShow();
PowerSaver::runningScreenSaver(true);
mTimer = 0;
return;
}
@ -114,6 +116,7 @@ void SystemScreenSaver::stopScreenSaver()
delete mVideoScreensaver;
mVideoScreensaver = NULL;
mState = STATE_INACTIVE;
PowerSaver::runningScreenSaver(false);
}
void SystemScreenSaver::renderScreenSaver()

View file

@ -136,7 +136,10 @@ GuiMenu::GuiMenu(Window* window) : GuiComponent(window), mMenu(window, "MAIN MEN
auto screensaver_time = std::make_shared<SliderComponent>(mWindow, 0.f, 30.f, 1.f, "m");
screensaver_time->setValue((float)(Settings::getInstance()->getInt("ScreenSaverTime") / (1000 * 60)));
s->addWithLabel("SCREENSAVER AFTER", screensaver_time);
s->addSaveFunc([screensaver_time] { Settings::getInstance()->setInt("ScreenSaverTime", (int)round(screensaver_time->getValue()) * (1000 * 60)); });
s->addSaveFunc([screensaver_time] {
Settings::getInstance()->setInt("ScreenSaverTime", (int)round(screensaver_time->getValue()) * (1000 * 60));
PowerSaver::updateTimeouts();
});
// screensaver behavior
auto screensaver_behavior = std::make_shared< OptionListComponent<std::string> >(mWindow, "SCREENSAVER BEHAVIOR", false);
@ -179,7 +182,7 @@ GuiMenu::GuiMenu(Window* window) : GuiComponent(window), mMenu(window, "MAIN MEN
s->addSaveFunc([move_carousel] {
if (move_carousel->getState()
&& !Settings::getInstance()->getBool("MoveCarousel")
&& PowerSaver::ps_instant == PowerSaver::getTimeout())
&& PowerSaver::getMode() == PowerSaver::INSTANT)
{
Settings::getInstance()->setString("PowerSaverMode", "default");
PowerSaver::init();
@ -199,7 +202,7 @@ GuiMenu::GuiMenu(Window* window) : GuiComponent(window), mMenu(window, "MAIN MEN
s->addSaveFunc([transition_style] {
if (Settings::getInstance()->getString("TransitionStyle") == "instant"
&& transition_style->getSelected() != "instant"
&& PowerSaver::ps_instant == PowerSaver::getTimeout())
&& PowerSaver::getMode() == PowerSaver::INSTANT)
{
Settings::getInstance()->setString("PowerSaverMode", "default");
PowerSaver::init();
@ -288,19 +291,12 @@ GuiMenu::GuiMenu(Window* window) : GuiComponent(window), mMenu(window, "MAIN MEN
power_saver->add(*it, *it, Settings::getInstance()->getString("PowerSaverMode") == *it);
s->addWithLabel("POWER SAVER MODES", power_saver);
s->addSaveFunc([this, power_saver] {
if (Settings::getInstance()->getString("PowerSaverMode") != "instant" && power_saver->getSelected() == "instant"){
mWindow->pushGui(new GuiMsgBox(mWindow, "Setting Power Saver to Instant Mode disables Carousel transition and sets Transition Style to Instant. Would you like to continue?"
, "YES", [] {
Settings::getInstance()->setString("TransitionStyle", "instant");
Settings::getInstance()->setString("PowerSaverMode", "instant");
Settings::getInstance()->setBool("MoveCarousel", false);
PowerSaver::init();
}, "NO", nullptr)
);
} else {
Settings::getInstance()->setString("PowerSaverMode", power_saver->getSelected());
PowerSaver::init();
if (Settings::getInstance()->getString("PowerSaverMode") != "instant" && power_saver->getSelected() == "instant") {
Settings::getInstance()->setString("TransitionStyle", "instant");
Settings::getInstance()->setBool("MoveCarousel", false);
}
Settings::getInstance()->setString("PowerSaverMode", power_saver->getSelected());
PowerSaver::init();
});
// gamelists

View file

@ -306,15 +306,12 @@ int main(int argc, char* argv[])
bool running = true;
bool ps_standby = false;
// assuming screensaver timeout is not updated regularly.
int timeout = (unsigned int) Settings::getInstance()->getInt("ScreenSaverTime");
while(running)
{
SDL_Event event;
bool ps_standby = PowerSaver::getState() && SDL_GetTicks() - ps_time > PowerSaver::getTimeout();
bool ps_standby = PowerSaver::getState() && SDL_GetTicks() - ps_time > PowerSaver::getMode();
if(ps_standby ? SDL_WaitEventTimeout(&event, timeout - 100) : SDL_PollEvent(&event))
if(ps_standby ? SDL_WaitEventTimeout(&event, PowerSaver::getTimeout()) : SDL_PollEvent(&event))
{
do
{
@ -359,7 +356,7 @@ int main(int argc, char* argv[])
lastTime = curTime;
// cap deltaTime
if(deltaTime > timeout || deltaTime < 0)
if((deltaTime > PowerSaver::getTimeout() && PowerSaver::getTimeout() > 0) || deltaTime < 0)
deltaTime = 1000;
window.update(deltaTime);

View file

@ -2,32 +2,49 @@
#include "Settings.h"
#include <string.h>
bool PowerSaver::mState = true;
int PowerSaver::mTimeout = PowerSaver::ps_default;
bool PowerSaver::mState = false;
bool PowerSaver::mRunningScreenSaver = false;
void PowerSaver::init(bool state)
int PowerSaver::mPlayNextTimeout = -1;
int PowerSaver::mScreenSaverTimeout = -1;
PowerSaver::mode PowerSaver::mMode = PowerSaver::DISABLED;
void PowerSaver::init()
{
setState(true);
updateTimeout();
updateTimeouts();
updateMode();
}
int PowerSaver::getTimeout()
{
return mTimeout;
return mRunningScreenSaver ? mPlayNextTimeout : mScreenSaverTimeout;
}
void PowerSaver::updateTimeout()
void PowerSaver::updateTimeouts()
{
mScreenSaverTimeout = (unsigned int) Settings::getInstance()->getInt("ScreenSaverTime");
mScreenSaverTimeout = mScreenSaverTimeout > 0 ? mScreenSaverTimeout - 100 : -1;
mPlayNextTimeout = 30000;
}
PowerSaver::mode PowerSaver::getMode()
{
return mMode;
}
void PowerSaver::updateMode()
{
std::string mode = Settings::getInstance()->getString("PowerSaverMode");
if (mode == "disabled") {
mTimeout = ps_disabled;
mMode = DISABLED;
} else if (mode == "instant") {
mTimeout = ps_instant;
mMode = INSTANT;
} else if (mode == "enhanced") {
mTimeout = ps_enhanced;
} else { // default
mTimeout = ps_default;
mMode = ENHANCED;
} else {
mMode = DEFAULT;
}
}
@ -42,3 +59,7 @@ void PowerSaver::setState(bool state)
mState = ps_enabled && state;
}
void PowerSaver::runningScreenSaver(bool state)
{
mRunningScreenSaver = state;
}

View file

@ -1,17 +1,26 @@
class PowerSaver
{
public:
enum ps_state : int { ps_disabled = -1, ps_instant = 200, ps_enhanced = 3000, ps_default = 10000 };
enum mode : int { DISABLED = -1, INSTANT = 200, ENHANCED = 3000, DEFAULT = 10000 };
static void init(bool state = true);
static void init();
static int getTimeout();
static void updateTimeout();
static void updateTimeouts();
static mode getMode();
static void updateMode();
static bool getState();
static void setState(bool state);
static void runningScreenSaver(bool state);
private:
static bool mState;
static int mTimeout;
static bool mRunningScreenSaver;
static mode mMode;
static int mPlayNextTimeout;
static int mScreenSaverTimeout;
};