diff --git a/es-app/src/SystemScreenSaver.cpp b/es-app/src/SystemScreenSaver.cpp index 6136e6d16c..10f791c6d9 100644 --- a/es-app/src/SystemScreenSaver.cpp +++ b/es-app/src/SystemScreenSaver.cpp @@ -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() @@ -318,4 +321,4 @@ void SystemScreenSaver::launchGame() { view->launch(mCurrentGame); } -} \ No newline at end of file +} diff --git a/es-app/src/SystemScreenSaver.h b/es-app/src/SystemScreenSaver.h index 55d99c1610..1865d3aff7 100644 --- a/es-app/src/SystemScreenSaver.h +++ b/es-app/src/SystemScreenSaver.h @@ -45,5 +45,5 @@ class SystemScreenSaver : public Window::ScreenSaver int mTimer; FileData* mCurrentGame; std::string mGameName; - std::string mSystemName; + std::string mSystemName; }; diff --git a/es-app/src/guis/GuiMenu.cpp b/es-app/src/guis/GuiMenu.cpp index 62a8738d2a..696e444e2c 100644 --- a/es-app/src/guis/GuiMenu.cpp +++ b/es-app/src/guis/GuiMenu.cpp @@ -88,7 +88,7 @@ GuiMenu::GuiMenu(Window* window) : GuiComponent(window), mMenu(window, "MAIN MEN for(auto it = transitions.begin(); it != transitions.end(); it++) vol_dev->add(*it, *it, Settings::getInstance()->getString("AudioDevice") == *it); s->addWithLabel("AUDIO DEVICE", vol_dev); - s->addSaveFunc([vol_dev] { + s->addSaveFunc([vol_dev] { Settings::getInstance()->setString("AudioDevice", vol_dev->getSelected()); VolumeControl::getInstance()->deinit(); VolumeControl::getInstance()->init(); @@ -136,7 +136,10 @@ GuiMenu::GuiMenu(Window* window) : GuiComponent(window), mMenu(window, "MAIN MEN auto screensaver_time = std::make_shared(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 >(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(); @@ -266,7 +269,7 @@ GuiMenu::GuiMenu(Window* window) : GuiComponent(window), mMenu(window, "MAIN MEN addEntry("GAME COLLECTION SETTINGS", 0x777777FF, true, [this] { openCollectionSystemSettings(); }); - + addEntry("OTHER SETTINGS", 0x777777FF, true, [this] { auto s = new GuiSettings(mWindow, "OTHER SETTINGS"); @@ -288,21 +291,14 @@ 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 auto save_gamelists = std::make_shared(mWindow); save_gamelists->setState(Settings::getInstance()->getBool("SaveGamelistsOnExit")); diff --git a/es-app/src/main.cpp b/es-app/src/main.cpp index 46085e5913..e0f2d49061 100644 --- a/es-app/src/main.cpp +++ b/es-app/src/main.cpp @@ -54,7 +54,7 @@ bool parseArgs(int argc, char* argv[], unsigned int* width, unsigned int* height #ifndef WIN32 }else if(strcmp(argv[i], "--show-hidden-files") == 0) { - Settings::getInstance()->setBool("ShowHiddenFiles", true); + Settings::getInstance()->setBool("ShowHiddenFiles", true); #endif }else if(strcmp(argv[i], "--draw-framerate") == 0) { @@ -95,7 +95,7 @@ bool parseArgs(int argc, char* argv[], unsigned int* width, unsigned int* height AttachConsole(ATTACH_PARENT_PROCESS); freopen("CONOUT$", "wb", stdout); #endif - std::cout << + std::cout << "EmulationStation, a graphical front-end for ROM browsing.\n" "Written by Alec \"Aloshi\" Lofquist.\n" "Version " << PROGRAM_VERSION_STRING << ", built " << PROGRAM_BUILT_STRING << "\n\n" @@ -139,7 +139,7 @@ bool verifyHomeFolderExists() return true; } -// Returns true if everything is OK, +// Returns true if everything is OK, bool loadSystemConfigFile(const char** errorString) { *errorString = NULL; @@ -187,8 +187,8 @@ int main(int argc, char* argv[]) // only show the console on Windows if HideConsole is false #ifdef WIN32 // MSVC has a "SubSystem" option, with two primary options: "WINDOWS" and "CONSOLE". - // In "WINDOWS" mode, no console is automatically created for us. This is good, - // because we can choose to only create the console window if the user explicitly + // In "WINDOWS" mode, no console is automatically created for us. This is good, + // because we can choose to only create the console window if the user explicitly // asks for it, preventing it from flashing open and then closing. // In "CONSOLE" mode, a console is always automatically created for us before we // enter main. In this case, we can only hide the console after the fact, which @@ -210,7 +210,7 @@ int main(int argc, char* argv[]) }else{ // we want to hide the console // if we're compiled with the "WINDOWS" subsystem, this is already done. - // if we're compiled with the "CONSOLE" subsystem, a console is already created; + // if we're compiled with the "CONSOLE" subsystem, a console is already created; // it'll flash open, but we hide it nearly immediately if(GetConsoleWindow()) // should only pass in "CONSOLE" mode ShowWindow(GetConsoleWindow(), SW_HIDE); @@ -266,7 +266,7 @@ int main(int argc, char* argv[]) // we can't handle es_systems.cfg file problems inside ES itself, so display the error message then quit window.pushGui(new GuiMsgBox(&window, errorMsg, - "QUIT", [] { + "QUIT", [] { SDL_Event* quit = new SDL_Event(); quit->type = SDL_QUIT; SDL_PushEvent(quit); @@ -302,19 +302,16 @@ int main(int argc, char* argv[]) int lastTime = SDL_GetTicks(); int ps_time = SDL_GetTicks(); - + 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(); - - if(ps_standby ? SDL_WaitEventTimeout(&event, timeout - 100) : SDL_PollEvent(&event)) + bool ps_standby = PowerSaver::getState() && SDL_GetTicks() - ps_time > PowerSaver::getMode(); + + if(ps_standby ? SDL_WaitEventTimeout(&event, PowerSaver::getTimeout()) : SDL_PollEvent(&event)) { do { @@ -337,12 +334,12 @@ int main(int argc, char* argv[]) break; } } while(SDL_PollEvent(&event)); - + // triggered if exiting from SDL_WaitEvent if (ps_standby) // show as if continuing from last event lastTime = SDL_GetTicks(); - + // reset counter ps_time = SDL_GetTicks(); } @@ -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); diff --git a/es-core/src/PowerSaver.cpp b/es-core/src/PowerSaver.cpp index d12886a153..90a617ec64 100644 --- a/es-core/src/PowerSaver.cpp +++ b/es-core/src/PowerSaver.cpp @@ -2,32 +2,49 @@ #include "Settings.h" #include -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::updateTimeouts() +{ + mScreenSaverTimeout = (unsigned int) Settings::getInstance()->getInt("ScreenSaverTime"); + mScreenSaverTimeout = mScreenSaverTimeout > 0 ? mScreenSaverTimeout - 100 : -1; + mPlayNextTimeout = 30000; +} + +PowerSaver::mode PowerSaver::getMode() +{ + return mMode; } -void PowerSaver::updateTimeout() +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; +} diff --git a/es-core/src/PowerSaver.h b/es-core/src/PowerSaver.h index b6fd2a67f3..32b0de4d8f 100644 --- a/es-core/src/PowerSaver.h +++ b/es-core/src/PowerSaver.h @@ -1,17 +1,26 @@ class PowerSaver { public: - enum ps_state : int { ps_disabled = -1, ps_instant = 200, ps_enhanced = 3000, ps_default = 10000 }; - - static void init(bool state = true); - + enum mode : int { DISABLED = -1, INSTANT = 200, ENHANCED = 3000, DEFAULT = 10000 }; + + 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; };