mirror of
https://github.com/RetroDECK/ES-DE.git
synced 2024-12-01 18:45:39 +00:00
commit
244bf47779
|
@ -4,6 +4,7 @@
|
||||||
#endif
|
#endif
|
||||||
#include "components/VideoVlcComponent.h"
|
#include "components/VideoVlcComponent.h"
|
||||||
#include "platform.h"
|
#include "platform.h"
|
||||||
|
#include "PowerSaver.h"
|
||||||
#include "Renderer.h"
|
#include "Renderer.h"
|
||||||
#include "Settings.h"
|
#include "Settings.h"
|
||||||
#include "SystemData.h"
|
#include "SystemData.h"
|
||||||
|
@ -100,6 +101,7 @@ void SystemScreenSaver::startScreenSaver()
|
||||||
mVideoScreensaver->setVideo(path);
|
mVideoScreensaver->setVideo(path);
|
||||||
mVideoScreensaver->setScreensaverMode(true);
|
mVideoScreensaver->setScreensaverMode(true);
|
||||||
mVideoScreensaver->onShow();
|
mVideoScreensaver->onShow();
|
||||||
|
PowerSaver::runningScreenSaver(true);
|
||||||
mTimer = 0;
|
mTimer = 0;
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
@ -114,6 +116,7 @@ void SystemScreenSaver::stopScreenSaver()
|
||||||
delete mVideoScreensaver;
|
delete mVideoScreensaver;
|
||||||
mVideoScreensaver = NULL;
|
mVideoScreensaver = NULL;
|
||||||
mState = STATE_INACTIVE;
|
mState = STATE_INACTIVE;
|
||||||
|
PowerSaver::runningScreenSaver(false);
|
||||||
}
|
}
|
||||||
|
|
||||||
void SystemScreenSaver::renderScreenSaver()
|
void SystemScreenSaver::renderScreenSaver()
|
||||||
|
|
|
@ -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");
|
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)));
|
screensaver_time->setValue((float)(Settings::getInstance()->getInt("ScreenSaverTime") / (1000 * 60)));
|
||||||
s->addWithLabel("SCREENSAVER AFTER", screensaver_time);
|
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
|
// screensaver behavior
|
||||||
auto screensaver_behavior = std::make_shared< OptionListComponent<std::string> >(mWindow, "SCREENSAVER BEHAVIOR", false);
|
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] {
|
s->addSaveFunc([move_carousel] {
|
||||||
if (move_carousel->getState()
|
if (move_carousel->getState()
|
||||||
&& !Settings::getInstance()->getBool("MoveCarousel")
|
&& !Settings::getInstance()->getBool("MoveCarousel")
|
||||||
&& PowerSaver::ps_instant == PowerSaver::getTimeout())
|
&& PowerSaver::getMode() == PowerSaver::INSTANT)
|
||||||
{
|
{
|
||||||
Settings::getInstance()->setString("PowerSaverMode", "default");
|
Settings::getInstance()->setString("PowerSaverMode", "default");
|
||||||
PowerSaver::init();
|
PowerSaver::init();
|
||||||
|
@ -199,7 +202,7 @@ GuiMenu::GuiMenu(Window* window) : GuiComponent(window), mMenu(window, "MAIN MEN
|
||||||
s->addSaveFunc([transition_style] {
|
s->addSaveFunc([transition_style] {
|
||||||
if (Settings::getInstance()->getString("TransitionStyle") == "instant"
|
if (Settings::getInstance()->getString("TransitionStyle") == "instant"
|
||||||
&& transition_style->getSelected() != "instant"
|
&& transition_style->getSelected() != "instant"
|
||||||
&& PowerSaver::ps_instant == PowerSaver::getTimeout())
|
&& PowerSaver::getMode() == PowerSaver::INSTANT)
|
||||||
{
|
{
|
||||||
Settings::getInstance()->setString("PowerSaverMode", "default");
|
Settings::getInstance()->setString("PowerSaverMode", "default");
|
||||||
PowerSaver::init();
|
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);
|
power_saver->add(*it, *it, Settings::getInstance()->getString("PowerSaverMode") == *it);
|
||||||
s->addWithLabel("POWER SAVER MODES", power_saver);
|
s->addWithLabel("POWER SAVER MODES", power_saver);
|
||||||
s->addSaveFunc([this, power_saver] {
|
s->addSaveFunc([this, power_saver] {
|
||||||
if (Settings::getInstance()->getString("PowerSaverMode") != "instant" && power_saver->getSelected() == "instant"){
|
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("TransitionStyle", "instant");
|
||||||
Settings::getInstance()->setString("PowerSaverMode", "instant");
|
|
||||||
Settings::getInstance()->setBool("MoveCarousel", false);
|
Settings::getInstance()->setBool("MoveCarousel", false);
|
||||||
PowerSaver::init();
|
}
|
||||||
}, "NO", nullptr)
|
|
||||||
);
|
|
||||||
} else {
|
|
||||||
Settings::getInstance()->setString("PowerSaverMode", power_saver->getSelected());
|
Settings::getInstance()->setString("PowerSaverMode", power_saver->getSelected());
|
||||||
PowerSaver::init();
|
PowerSaver::init();
|
||||||
}
|
|
||||||
});
|
});
|
||||||
|
|
||||||
// gamelists
|
// gamelists
|
||||||
|
|
|
@ -306,15 +306,12 @@ int main(int argc, char* argv[])
|
||||||
bool running = true;
|
bool running = true;
|
||||||
bool ps_standby = false;
|
bool ps_standby = false;
|
||||||
|
|
||||||
// assuming screensaver timeout is not updated regularly.
|
|
||||||
int timeout = (unsigned int) Settings::getInstance()->getInt("ScreenSaverTime");
|
|
||||||
|
|
||||||
while(running)
|
while(running)
|
||||||
{
|
{
|
||||||
SDL_Event event;
|
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
|
do
|
||||||
{
|
{
|
||||||
|
@ -359,7 +356,7 @@ int main(int argc, char* argv[])
|
||||||
lastTime = curTime;
|
lastTime = curTime;
|
||||||
|
|
||||||
// cap deltaTime
|
// cap deltaTime
|
||||||
if(deltaTime > timeout || deltaTime < 0)
|
if((deltaTime > PowerSaver::getTimeout() && PowerSaver::getTimeout() > 0) || deltaTime < 0)
|
||||||
deltaTime = 1000;
|
deltaTime = 1000;
|
||||||
|
|
||||||
window.update(deltaTime);
|
window.update(deltaTime);
|
||||||
|
|
|
@ -2,32 +2,49 @@
|
||||||
#include "Settings.h"
|
#include "Settings.h"
|
||||||
#include <string.h>
|
#include <string.h>
|
||||||
|
|
||||||
bool PowerSaver::mState = true;
|
bool PowerSaver::mState = false;
|
||||||
int PowerSaver::mTimeout = PowerSaver::ps_default;
|
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);
|
setState(true);
|
||||||
updateTimeout();
|
updateTimeouts();
|
||||||
|
updateMode();
|
||||||
}
|
}
|
||||||
|
|
||||||
int PowerSaver::getTimeout()
|
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");
|
std::string mode = Settings::getInstance()->getString("PowerSaverMode");
|
||||||
|
|
||||||
if (mode == "disabled") {
|
if (mode == "disabled") {
|
||||||
mTimeout = ps_disabled;
|
mMode = DISABLED;
|
||||||
} else if (mode == "instant") {
|
} else if (mode == "instant") {
|
||||||
mTimeout = ps_instant;
|
mMode = INSTANT;
|
||||||
} else if (mode == "enhanced") {
|
} else if (mode == "enhanced") {
|
||||||
mTimeout = ps_enhanced;
|
mMode = ENHANCED;
|
||||||
} else { // default
|
} else {
|
||||||
mTimeout = ps_default;
|
mMode = DEFAULT;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -42,3 +59,7 @@ void PowerSaver::setState(bool state)
|
||||||
mState = ps_enabled && state;
|
mState = ps_enabled && state;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void PowerSaver::runningScreenSaver(bool state)
|
||||||
|
{
|
||||||
|
mRunningScreenSaver = state;
|
||||||
|
}
|
||||||
|
|
|
@ -1,17 +1,26 @@
|
||||||
class PowerSaver
|
class PowerSaver
|
||||||
{
|
{
|
||||||
public:
|
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 int getTimeout();
|
||||||
static void updateTimeout();
|
static void updateTimeouts();
|
||||||
|
|
||||||
|
static mode getMode();
|
||||||
|
static void updateMode();
|
||||||
|
|
||||||
static bool getState();
|
static bool getState();
|
||||||
static void setState(bool state);
|
static void setState(bool state);
|
||||||
|
|
||||||
|
static void runningScreenSaver(bool state);
|
||||||
|
|
||||||
private:
|
private:
|
||||||
static bool mState;
|
static bool mState;
|
||||||
static int mTimeout;
|
static bool mRunningScreenSaver;
|
||||||
|
|
||||||
|
static mode mMode;
|
||||||
|
static int mPlayNextTimeout;
|
||||||
|
static int mScreenSaverTimeout;
|
||||||
};
|
};
|
||||||
|
|
Loading…
Reference in a new issue