target-bsnes: Only suppress screensavers when active

This commit reworks when the screensaver suppression kicks in.

Previously, bsnes would only engage screensaver suppression once, on
application launch. Now that the option is exposed and can be toggled at
any time, we have to be a little more clever.

Additionally, screensaver suppression is now only engaged while
emulation is active, because it doesn't make much sense otherwise.
This commit is contained in:
Sintendo 2020-11-08 12:34:18 +01:00 committed by Screwtapello
parent dba608a808
commit d29677b778
3 changed files with 12 additions and 2 deletions

View File

@ -40,7 +40,6 @@ auto nall::main(Arguments arguments) -> void {
settings.load(); settings.load();
Application::setName("bsnes"); Application::setName("bsnes");
Application::setScreenSaver(settings.general.screenSaver);
Application::setToolTips(settings.general.toolTips); Application::setToolTips(settings.general.toolTips);
Instances::presentation.construct(); Instances::presentation.construct();

View File

@ -85,7 +85,16 @@ auto Program::main() -> void {
inputManager.poll(); inputManager.poll();
inputManager.pollHotkeys(); inputManager.pollHotkeys();
if(inactive()) { static bool previouslyInactive = true;
bool currentlyInactive = inactive();
// check if emulator has transitioned from active to inactive or vice versa
if(previouslyInactive != currentlyInactive) {
previouslyInactive = currentlyInactive;
Application::setScreenSaver(currentlyInactive || settings.general.screenSaver);
}
if(currentlyInactive) {
audio.clear(); audio.clear();
usleep(20 * 1000); usleep(20 * 1000);
if(settings.emulator.runAhead.frames == 0) viewportRefresh(); if(settings.emulator.runAhead.frames == 0) viewportRefresh();

View File

@ -25,6 +25,8 @@ auto EmulatorSettings::create() -> void {
}); });
screenSaver.setText("Allow screensaver during emulation").setChecked(settings.general.screenSaver).onToggle([&] { screenSaver.setText("Allow screensaver during emulation").setChecked(settings.general.screenSaver).onToggle([&] {
settings.general.screenSaver = screenSaver.checked(); settings.general.screenSaver = screenSaver.checked();
// setting can be toggled while emulation is active
if(!program.inactive()) Application::setScreenSaver(settings.general.screenSaver);
}); });
optionsSpacer.setColor({192, 192, 192}); optionsSpacer.setColor({192, 192, 192});