mirror of https://github.com/cemu-project/Cemu.git
Add cross-platform "disable screen saver" setting (#497)
This commit is contained in:
parent
80b1c50b50
commit
4c697d3755
|
@ -112,11 +112,6 @@ void LattePerformanceMonitor_frameEnd()
|
||||||
LatteOverlay_updateStats(fps, drawCallCounter / elapsedFrames);
|
LatteOverlay_updateStats(fps, drawCallCounter / elapsedFrames);
|
||||||
gui_updateWindowTitles(false, false, fps);
|
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();
|
LatteOverlay_updateStatsPerFrame();
|
||||||
}
|
}
|
||||||
|
|
|
@ -60,6 +60,7 @@ void CemuConfig::Load(XMLConfigParser& parser)
|
||||||
did_show_macos_disclaimer = parser.get("macos_disclaimer", did_show_macos_disclaimer);
|
did_show_macos_disclaimer = parser.get("macos_disclaimer", did_show_macos_disclaimer);
|
||||||
fullscreen = parser.get("fullscreen", fullscreen);
|
fullscreen = parser.get("fullscreen", fullscreen);
|
||||||
proxy_server = parser.get("proxy_server", "");
|
proxy_server = parser.get("proxy_server", "");
|
||||||
|
disable_screensaver = parser.get("disable_screensaver", true);
|
||||||
|
|
||||||
// cpu_mode = parser.get("cpu_mode", cpu_mode.GetInitValue());
|
// cpu_mode = parser.get("cpu_mode", cpu_mode.GetInitValue());
|
||||||
//console_region = parser.get("console_region", console_region.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>("macos_disclaimer", did_show_macos_disclaimer);
|
||||||
config.set<bool>("fullscreen", fullscreen);
|
config.set<bool>("fullscreen", fullscreen);
|
||||||
config.set("proxy_server", proxy_server.GetValue().c_str());
|
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("cpu_mode", cpu_mode.GetValue());
|
||||||
//config.set("console_region", console_region.GetValue());
|
//config.set("console_region", console_region.GetValue());
|
||||||
config.set("console_language", console_language.GetValue());
|
config.set("console_language", console_language.GetValue());
|
||||||
|
|
|
@ -369,6 +369,7 @@ struct CemuConfig
|
||||||
ConfigValue<bool> fullscreen_menubar{ false };
|
ConfigValue<bool> fullscreen_menubar{ false };
|
||||||
ConfigValue<bool> fullscreen{ false };
|
ConfigValue<bool> fullscreen{ false };
|
||||||
ConfigValue<std::string> proxy_server{};
|
ConfigValue<std::string> proxy_server{};
|
||||||
|
ConfigValue<bool> disable_screensaver{true};
|
||||||
|
|
||||||
std::vector<std::wstring> game_paths;
|
std::vector<std::wstring> game_paths;
|
||||||
std::mutex game_cache_entries_mutex;
|
std::mutex game_cache_entries_mutex;
|
||||||
|
|
|
@ -49,6 +49,8 @@
|
||||||
#include "Cafe/TitleList/TitleList.h"
|
#include "Cafe/TitleList/TitleList.h"
|
||||||
#include "wxHelper.h"
|
#include "wxHelper.h"
|
||||||
|
|
||||||
|
#include "util/ScreenSaver/ScreenSaver.h"
|
||||||
|
|
||||||
const wxString kDirectSound(wxT("DirectSound"));
|
const wxString kDirectSound(wxT("DirectSound"));
|
||||||
const wxString kXAudio27(wxT("XAudio2.7"));
|
const wxString kXAudio27(wxT("XAudio2.7"));
|
||||||
const wxString kXAudio2(wxT("XAudio2"));
|
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 = 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."));
|
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->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);
|
box_sizer->Add(second_row, 0, wxEXPAND, 5);
|
||||||
}
|
}
|
||||||
|
@ -882,6 +888,13 @@ void GeneralSettings2::StoreConfig()
|
||||||
config.permanent_storage = use_ps;
|
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())
|
if (!LaunchSettings::GetMLCPath().has_value())
|
||||||
config.SetMLCPath(wxHelper::MakeFSPath(m_mlc_path->GetValue()), false);
|
config.SetMLCPath(wxHelper::MakeFSPath(m_mlc_path->GetValue()), false);
|
||||||
|
|
||||||
|
@ -1494,7 +1507,8 @@ void GeneralSettings2::ApplyConfig()
|
||||||
m_save_screenshot->SetValue(config.save_screenshot);
|
m_save_screenshot->SetValue(config.save_screenshot);
|
||||||
|
|
||||||
m_permanent_storage->SetValue(config.permanent_storage);
|
m_permanent_storage->SetValue(config.permanent_storage);
|
||||||
|
m_disable_screensaver->SetValue(config.disable_screensaver);
|
||||||
|
|
||||||
for (auto& path : config.game_paths)
|
for (auto& path : config.game_paths)
|
||||||
{
|
{
|
||||||
m_game_paths->Append(path);
|
m_game_paths->Append(path);
|
||||||
|
|
|
@ -42,6 +42,7 @@ private:
|
||||||
wxCheckBox* m_discord_presence, *m_fullscreen_menubar;
|
wxCheckBox* m_discord_presence, *m_fullscreen_menubar;
|
||||||
wxCheckBox* m_auto_update, *m_save_screenshot;
|
wxCheckBox* m_auto_update, *m_save_screenshot;
|
||||||
wxCheckBox* m_permanent_storage;
|
wxCheckBox* m_permanent_storage;
|
||||||
|
wxCheckBox* m_disable_screensaver;
|
||||||
wxListBox* m_game_paths;
|
wxListBox* m_game_paths;
|
||||||
wxTextCtrl* m_mlc_path;
|
wxTextCtrl* m_mlc_path;
|
||||||
|
|
||||||
|
|
|
@ -20,6 +20,7 @@
|
||||||
#include "util/helpers/helpers.h"
|
#include "util/helpers/helpers.h"
|
||||||
#include "config/CemuConfig.h"
|
#include "config/CemuConfig.h"
|
||||||
#include "Cemu/DiscordPresence/DiscordPresence.h"
|
#include "Cemu/DiscordPresence/DiscordPresence.h"
|
||||||
|
#include "util/ScreenSaver/ScreenSaver.h"
|
||||||
#include "gui/GeneralSettings2.h"
|
#include "gui/GeneralSettings2.h"
|
||||||
#include "gui/GraphicPacksWindow2.h"
|
#include "gui/GraphicPacksWindow2.h"
|
||||||
#include "gui/GameProfileWindow.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);
|
m_discord->UpdatePresence(DiscordPresence::Playing, m_launched_game_name);
|
||||||
#endif
|
#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())
|
if (ActiveSettings::FullscreenEnabled())
|
||||||
SetFullScreen(true);
|
SetFullScreen(true);
|
||||||
|
|
||||||
|
|
|
@ -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)");
|
||||||
|
}
|
||||||
|
}
|
||||||
|
};
|
||||||
|
};
|
Loading…
Reference in New Issue