From d29677b778f77fe6435f0f6e8697a697fe4c31e4 Mon Sep 17 00:00:00 2001 From: Sintendo Date: Sun, 8 Nov 2020 12:34:18 +0100 Subject: [PATCH] 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. --- bsnes/target-bsnes/bsnes.cpp | 1 - bsnes/target-bsnes/program/program.cpp | 11 ++++++++++- bsnes/target-bsnes/settings/emulator.cpp | 2 ++ 3 files changed, 12 insertions(+), 2 deletions(-) diff --git a/bsnes/target-bsnes/bsnes.cpp b/bsnes/target-bsnes/bsnes.cpp index b7236ab1..c7bb3dd3 100644 --- a/bsnes/target-bsnes/bsnes.cpp +++ b/bsnes/target-bsnes/bsnes.cpp @@ -40,7 +40,6 @@ auto nall::main(Arguments arguments) -> void { settings.load(); Application::setName("bsnes"); - Application::setScreenSaver(settings.general.screenSaver); Application::setToolTips(settings.general.toolTips); Instances::presentation.construct(); diff --git a/bsnes/target-bsnes/program/program.cpp b/bsnes/target-bsnes/program/program.cpp index 66575e0f..8b236dd3 100644 --- a/bsnes/target-bsnes/program/program.cpp +++ b/bsnes/target-bsnes/program/program.cpp @@ -85,7 +85,16 @@ auto Program::main() -> void { inputManager.poll(); 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(); usleep(20 * 1000); if(settings.emulator.runAhead.frames == 0) viewportRefresh(); diff --git a/bsnes/target-bsnes/settings/emulator.cpp b/bsnes/target-bsnes/settings/emulator.cpp index 5561ac6f..00f94e76 100644 --- a/bsnes/target-bsnes/settings/emulator.cpp +++ b/bsnes/target-bsnes/settings/emulator.cpp @@ -25,6 +25,8 @@ auto EmulatorSettings::create() -> void { }); screenSaver.setText("Allow screensaver during emulation").setChecked(settings.general.screenSaver).onToggle([&] { 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});