Add cross-platform "disable screen saver" setting (#497)

This commit is contained in:
lisa-wolfgang 2023-02-24 15:10:07 -06:00 committed by GitHub
parent 80b1c50b50
commit 4c697d3755
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
7 changed files with 65 additions and 7 deletions

View File

@ -112,11 +112,6 @@ void LattePerformanceMonitor_frameEnd()
LatteOverlay_updateStats(fps, drawCallCounter / elapsedFrames);
gui_updateWindowTitles(false, false, fps);
}
// prevent hibernation and screen saver/monitor off
#if BOOST_OS_WINDOWS
SetThreadExecutionState(ES_CONTINUOUS | ES_DISPLAY_REQUIRED | ES_SYSTEM_REQUIRED);
#endif
}
LatteOverlay_updateStatsPerFrame();
}

View File

@ -60,6 +60,7 @@ void CemuConfig::Load(XMLConfigParser& parser)
did_show_macos_disclaimer = parser.get("macos_disclaimer", did_show_macos_disclaimer);
fullscreen = parser.get("fullscreen", fullscreen);
proxy_server = parser.get("proxy_server", "");
disable_screensaver = parser.get("disable_screensaver", true);
// cpu_mode = parser.get("cpu_mode", cpu_mode.GetInitValue());
//console_region = parser.get("console_region", console_region.GetInitValue());
@ -363,7 +364,8 @@ void CemuConfig::Save(XMLConfigParser& parser)
config.set<bool>("macos_disclaimer", did_show_macos_disclaimer);
config.set<bool>("fullscreen", fullscreen);
config.set("proxy_server", proxy_server.GetValue().c_str());
config.set<bool>("disable_screensaver", disable_screensaver);
// config.set("cpu_mode", cpu_mode.GetValue());
//config.set("console_region", console_region.GetValue());
config.set("console_language", console_language.GetValue());

View File

@ -369,6 +369,7 @@ struct CemuConfig
ConfigValue<bool> fullscreen_menubar{ false };
ConfigValue<bool> fullscreen{ false };
ConfigValue<std::string> proxy_server{};
ConfigValue<bool> disable_screensaver{true};
std::vector<std::wstring> game_paths;
std::mutex game_cache_entries_mutex;

View File

@ -49,6 +49,8 @@
#include "Cafe/TitleList/TitleList.h"
#include "wxHelper.h"
#include "util/ScreenSaver/ScreenSaver.h"
const wxString kDirectSound(wxT("DirectSound"));
const wxString kXAudio27(wxT("XAudio2.7"));
const wxString kXAudio2(wxT("XAudio2"));
@ -172,6 +174,10 @@ wxPanel* GeneralSettings2::AddGeneralPage(wxNotebook* notebook)
m_permanent_storage = new wxCheckBox(box, wxID_ANY, _("Use permanent storage"));
m_permanent_storage->SetToolTip(_("Cemu will remember your custom mlc path in %LOCALAPPDATA%/Cemu for new installations."));
second_row->Add(m_permanent_storage, 0, botflag, 5);
second_row->AddSpacer(10);
m_disable_screensaver = new wxCheckBox(box, wxID_ANY, _("Disable screen saver"));
m_disable_screensaver->SetToolTip(_("Prevents the system from activating the screen saver or going to sleep while running a game."));
second_row->Add(m_disable_screensaver, 0, botflag, 5);
box_sizer->Add(second_row, 0, wxEXPAND, 5);
}
@ -882,6 +888,13 @@ void GeneralSettings2::StoreConfig()
config.permanent_storage = use_ps;
}
config.disable_screensaver = m_disable_screensaver->IsChecked();
// Toggle while a game is running
if (CafeSystem::IsTitleRunning())
{
ScreenSaver::SetInhibit(config.disable_screensaver);
}
if (!LaunchSettings::GetMLCPath().has_value())
config.SetMLCPath(wxHelper::MakeFSPath(m_mlc_path->GetValue()), false);
@ -1494,7 +1507,8 @@ void GeneralSettings2::ApplyConfig()
m_save_screenshot->SetValue(config.save_screenshot);
m_permanent_storage->SetValue(config.permanent_storage);
m_disable_screensaver->SetValue(config.disable_screensaver);
for (auto& path : config.game_paths)
{
m_game_paths->Append(path);

View File

@ -42,6 +42,7 @@ private:
wxCheckBox* m_discord_presence, *m_fullscreen_menubar;
wxCheckBox* m_auto_update, *m_save_screenshot;
wxCheckBox* m_permanent_storage;
wxCheckBox* m_disable_screensaver;
wxListBox* m_game_paths;
wxTextCtrl* m_mlc_path;

View File

@ -20,6 +20,7 @@
#include "util/helpers/helpers.h"
#include "config/CemuConfig.h"
#include "Cemu/DiscordPresence/DiscordPresence.h"
#include "util/ScreenSaver/ScreenSaver.h"
#include "gui/GeneralSettings2.h"
#include "gui/GraphicPacksWindow2.h"
#include "gui/GameProfileWindow.h"
@ -565,6 +566,14 @@ bool MainWindow::FileLoad(std::wstring fileName, wxLaunchGameEvent::INITIATED_BY
m_discord->UpdatePresence(DiscordPresence::Playing, m_launched_game_name);
#endif
if (GetConfig().disable_screensaver)
{
ScreenSaver::SetInhibit(true);
// TODO: disable when only the game, not Cemu, is closed (a feature not yet implemented)
// currently unnecessary because this will happen automatically when Cemu closes
// ScreenSaver::SetInhibit(false);
}
if (ActiveSettings::FullscreenEnabled())
SetFullScreen(true);

View File

@ -0,0 +1,36 @@
#include "Cemu/Logging/CemuLogging.h"
#include <SDL2/SDL.h>
class ScreenSaver
{
public:
static void SetInhibit(bool inhibit)
{
// Initialize video subsystem if necessary
if (SDL_WasInit(SDL_INIT_VIDEO) == 0)
{
int initErr = SDL_InitSubSystem(SDL_INIT_VIDEO);
if (initErr)
{
cemuLog_force("Could not disable screen saver (SDL video subsystem initialization error)");
}
}
// Toggle SDL's screen saver inhibition
if (inhibit)
{
SDL_DisableScreenSaver();
if (SDL_IsScreenSaverEnabled() == SDL_TRUE)
{
cemuLog_force("Could not verify if screen saver was disabled (`SDL_IsScreenSaverEnabled()` returned SDL_TRUE)");
}
}
else
{
SDL_EnableScreenSaver();
if (SDL_IsScreenSaverEnabled() == SDL_FALSE)
{
cemuLog_force("Could not verify if screen saver was re-enabled (`SDL_IsScreenSaverEnabled()` returned SDL_FALSE)");
}
}
};
};