Skip to content

Commit

Permalink
Browse files Browse the repository at this point in the history
Merge pull request #8613 from jordan-woyak/expose-disable-ss
Config: Expose "DisableScreenSaver" in the UI and default it to true.
  • Loading branch information
leoetlino committed Oct 19, 2020
2 parents 55b4924 + 50ec747 commit 8a8dc3d
Show file tree
Hide file tree
Showing 8 changed files with 40 additions and 49 deletions.
2 changes: 1 addition & 1 deletion Source/Core/Core/Config/MainSettings.cpp
Expand Up @@ -123,7 +123,7 @@ const Info<int> MAIN_RENDER_WINDOW_HEIGHT{{System::Main, "Display", "RenderWindo
const Info<bool> MAIN_RENDER_WINDOW_AUTOSIZE{{System::Main, "Display", "RenderWindowAutoSize"},
false};
const Info<bool> MAIN_KEEP_WINDOW_ON_TOP{{System::Main, "Display", "KeepWindowOnTop"}, false};
const Info<bool> MAIN_DISABLE_SCREENSAVER{{System::Main, "Display", "DisableScreenSaver"}, false};
const Info<bool> MAIN_DISABLE_SCREENSAVER{{System::Main, "Display", "DisableScreenSaver"}, true};

// Main.DSP

Expand Down
3 changes: 3 additions & 0 deletions Source/Core/DolphinNoGUI/PlatformWin32.cpp
Expand Up @@ -107,6 +107,9 @@ bool PlatformWin32::Init()
ProcessEvents();
}

if (Config::Get(Config::MAIN_DISABLE_SCREENSAVER))
SetThreadExecutionState(ES_CONTINUOUS | ES_DISPLAY_REQUIRED | ES_SYSTEM_REQUIRED);

UpdateWindowPosition();
return true;
}
Expand Down
23 changes: 10 additions & 13 deletions Source/Core/DolphinQt/MainWindow.cpp
Expand Up @@ -737,15 +737,13 @@ void MainWindow::Play(const std::optional<std::string>& savestate_path)
if (selection)
{
StartGame(selection->GetFilePath(), ScanForSecondDisc::Yes, savestate_path);
EnableScreenSaver(false);
}
else
{
const QString default_path = QString::fromStdString(Config::Get(Config::MAIN_DEFAULT_ISO));
if (!default_path.isEmpty() && QFile::exists(default_path))
{
StartGame(default_path, ScanForSecondDisc::Yes, savestate_path);
EnableScreenSaver(false);
}
else
{
Expand Down Expand Up @@ -776,7 +774,6 @@ void MainWindow::OnStopComplete()
{
m_stop_requested = false;
HideRenderWidget();
EnableScreenSaver(true);
#ifdef USE_DISCORD_PRESENCE
if (!m_netplay_dialog->isVisible())
Discord::UpdateDiscordPresence();
Expand Down Expand Up @@ -993,13 +990,6 @@ void MainWindow::StartGame(std::unique_ptr<BootParameters>&& parameters)

if (Config::Get(Config::MAIN_FULLSCREEN))
m_fullscreen_requested = true;

#ifdef Q_OS_WIN
// Prevents Windows from sleeping, turning off the display, or idling
EXECUTION_STATE shouldScreenSave =
Config::Get(Config::MAIN_DISABLE_SCREENSAVER) ? ES_DISPLAY_REQUIRED : 0;
SetThreadExecutionState(ES_CONTINUOUS | shouldScreenSave | ES_SYSTEM_REQUIRED);
#endif
}

void MainWindow::SetFullScreenResolution(bool fullscreen)
Expand Down Expand Up @@ -1304,6 +1294,10 @@ void MainWindow::NetPlayInit()
Discord::InitNetPlayFunctionality(*m_netplay_discord);
m_netplay_discord->Start();
#endif
connect(&Settings::Instance(), &Settings::ConfigChanged, this,
&MainWindow::UpdateScreenSaverInhibition);
connect(&Settings::Instance(), &Settings::EmulationStateChanged, this,
&MainWindow::UpdateScreenSaverInhibition);
}

bool MainWindow::NetPlayJoin()
Expand Down Expand Up @@ -1435,13 +1429,16 @@ void MainWindow::NetPlayQuit()
#endif
}

void MainWindow::EnableScreenSaver(bool enable)
void MainWindow::UpdateScreenSaverInhibition()
{
const bool inhibit =
Config::Get(Config::MAIN_DISABLE_SCREENSAVER) && (Core::GetState() == Core::State::Running);

#if defined(HAVE_XRANDR) && HAVE_XRANDR
if (GetWindowSystemType() == WindowSystemType::X11)
UICommon::EnableScreenSaver(winId(), enable);
UICommon::InhibitScreenSaver(winId(), inhibit);
#else
UICommon::EnableScreenSaver(enable);
UICommon::InhibitScreenSaver(inhibit);
#endif
}

Expand Down
2 changes: 1 addition & 1 deletion Source/Core/DolphinQt/MainWindow.h
Expand Up @@ -182,7 +182,7 @@ class MainWindow final : public QMainWindow

QStringList PromptFileNames();

void EnableScreenSaver(bool enable);
void UpdateScreenSaverInhibition();

void OnStopComplete();
void dragEnterEvent(QDragEnterEvent* event) override;
Expand Down
5 changes: 5 additions & 0 deletions Source/Core/DolphinQt/Settings/InterfacePane.cpp
Expand Up @@ -148,12 +148,14 @@ void InterfacePane::CreateUI()
new QCheckBox(tr("Download Game Covers from GameTDB.com for Use in Grid Mode"));
m_checkbox_show_debugging_ui = new QCheckBox(tr("Show Debugging UI"));
m_checkbox_focused_hotkeys = new QCheckBox(tr("Hotkeys Require Window Focus"));
m_checkbox_disable_screensaver = new QCheckBox(tr("Inhibit Screensaver During Emulation"));

groupbox_layout->addWidget(m_checkbox_use_builtin_title_database);
groupbox_layout->addWidget(m_checkbox_use_userstyle);
groupbox_layout->addWidget(m_checkbox_use_covers);
groupbox_layout->addWidget(m_checkbox_show_debugging_ui);
groupbox_layout->addWidget(m_checkbox_focused_hotkeys);
groupbox_layout->addWidget(m_checkbox_disable_screensaver);
}

void InterfacePane::CreateInGame()
Expand Down Expand Up @@ -185,6 +187,7 @@ void InterfacePane::ConnectLayout()
connect(m_checkbox_use_builtin_title_database, &QCheckBox::toggled, this,
&InterfacePane::OnSaveConfig);
connect(m_checkbox_use_covers, &QCheckBox::toggled, this, &InterfacePane::OnSaveConfig);
connect(m_checkbox_disable_screensaver, &QCheckBox::toggled, this, &InterfacePane::OnSaveConfig);
connect(m_checkbox_show_debugging_ui, &QCheckBox::toggled, this, &InterfacePane::OnSaveConfig);
connect(m_checkbox_focused_hotkeys, &QCheckBox::toggled, this, &InterfacePane::OnSaveConfig);
connect(m_combobox_theme, qOverload<int>(&QComboBox::currentIndexChanged), this,
Expand Down Expand Up @@ -237,6 +240,7 @@ void InterfacePane::LoadConfig()
m_checkbox_use_covers->setChecked(Config::Get(Config::MAIN_USE_GAME_COVERS));
m_checkbox_focused_hotkeys->setChecked(Config::Get(Config::MAIN_FOCUSED_HOTKEYS));
m_checkbox_hide_mouse->setChecked(Settings::Instance().GetHideCursor());
m_checkbox_disable_screensaver->setChecked(Config::Get(Config::MAIN_DISABLE_SCREENSAVER));
}

void InterfacePane::OnSaveConfig()
Expand Down Expand Up @@ -280,6 +284,7 @@ void InterfacePane::OnSaveConfig()
}

Config::SetBase(Config::MAIN_FOCUSED_HOTKEYS, m_checkbox_focused_hotkeys->isChecked());
Config::SetBase(Config::MAIN_DISABLE_SCREENSAVER, m_checkbox_disable_screensaver->isChecked());

settings.SaveSettings();
}
1 change: 1 addition & 0 deletions Source/Core/DolphinQt/Settings/InterfacePane.h
Expand Up @@ -37,6 +37,7 @@ class InterfacePane final : public QWidget
QCheckBox* m_checkbox_show_debugging_ui;
QCheckBox* m_checkbox_focused_hotkeys;
QCheckBox* m_checkbox_use_covers;
QCheckBox* m_checkbox_disable_screensaver;

QCheckBox* m_checkbox_confirm_on_stop;
QCheckBox* m_checkbox_use_panic_handlers;
Expand Down
49 changes: 17 additions & 32 deletions Source/Core/UICommon/UICommon.cpp
Expand Up @@ -397,57 +397,42 @@ bool TriggerSTMPowerEvent()
}

#if defined(HAVE_XRANDR) && HAVE_XRANDR
void EnableScreenSaver(Window win, bool enable)
void InhibitScreenSaver(Window win, bool inhibit)
#else
void EnableScreenSaver(bool enable)
void InhibitScreenSaver(bool inhibit)
#endif
{
// Inhibit the screensaver. Depending on the operating system this may also
// disable low-power states and/or screen dimming.

#if defined(HAVE_X11) && HAVE_X11
if (Config::Get(Config::MAIN_DISABLE_SCREENSAVER))
{
X11Utils::InhibitScreensaver(win, !enable);
}
X11Utils::InhibitScreensaver(win, inhibit);
#endif

#ifdef _WIN32
// Prevents Windows from sleeping, turning off the display, or idling
if (enable)
{
SetThreadExecutionState(ES_CONTINUOUS);
}
else
{
EXECUTION_STATE should_screen_save =
Config::Get(Config::MAIN_DISABLE_SCREENSAVER) ? ES_DISPLAY_REQUIRED : 0;
SetThreadExecutionState(ES_CONTINUOUS | should_screen_save | ES_SYSTEM_REQUIRED);
}
SetThreadExecutionState(ES_CONTINUOUS |
(inhibit ? (ES_DISPLAY_REQUIRED | ES_SYSTEM_REQUIRED) : 0));
#endif

#ifdef __APPLE__
static IOPMAssertionID s_power_assertion = kIOPMNullAssertionID;

if (Config::Get(Config::MAIN_DISABLE_SCREENSAVER))
if (inhibit)
{
if (enable)
CFStringRef reason_for_activity = CFSTR("Emulation Running");
if (IOPMAssertionCreateWithName(kIOPMAssertionTypePreventUserIdleDisplaySleep,
kIOPMAssertionLevelOn, reason_for_activity,
&s_power_assertion) != kIOReturnSuccess)
{
if (s_power_assertion != kIOPMNullAssertionID)
{
IOPMAssertionRelease(s_power_assertion);
s_power_assertion = kIOPMNullAssertionID;
}
s_power_assertion = kIOPMNullAssertionID;
}
else
}
else
{
if (s_power_assertion != kIOPMNullAssertionID)
{
CFStringRef reason_for_activity = CFSTR("Emulation Running");
if (IOPMAssertionCreateWithName(kIOPMAssertionTypePreventUserIdleDisplaySleep,
kIOPMAssertionLevelOn, reason_for_activity,
&s_power_assertion) != kIOReturnSuccess)
{
s_power_assertion = kIOPMNullAssertionID;
}
IOPMAssertionRelease(s_power_assertion);
s_power_assertion = kIOPMNullAssertionID;
}
}
#endif
Expand Down
4 changes: 2 additions & 2 deletions Source/Core/UICommon/UICommon.h
Expand Up @@ -14,9 +14,9 @@ void Init();
void Shutdown();

#if defined(HAVE_XRANDR) && HAVE_XRANDR
void EnableScreenSaver(unsigned long win, bool enable);
void InhibitScreenSaver(unsigned long win, bool enable);
#else
void EnableScreenSaver(bool enable);
void InhibitScreenSaver(bool enable);
#endif

// Calls std::locale::global, selecting a fallback locale if the
Expand Down

0 comments on commit 8a8dc3d

Please sign in to comment.