Merge pull request #6280 from spycrab/qt_screensaver
Qt: Toggle Screensaver
This commit is contained in:
commit
1f89d91deb
|
@ -358,6 +358,7 @@ void MainWindow::Play(const std::optional<std::string>& savestate_path)
|
||||||
if (Core::GetState() == Core::State::Paused)
|
if (Core::GetState() == Core::State::Paused)
|
||||||
{
|
{
|
||||||
Core::SetState(Core::State::Running);
|
Core::SetState(Core::State::Running);
|
||||||
|
EnableScreenSaver(false);
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
|
@ -365,6 +366,7 @@ void MainWindow::Play(const std::optional<std::string>& savestate_path)
|
||||||
if (selection)
|
if (selection)
|
||||||
{
|
{
|
||||||
StartGame(selection->GetFilePath(), savestate_path);
|
StartGame(selection->GetFilePath(), savestate_path);
|
||||||
|
EnableScreenSaver(false);
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
|
@ -372,6 +374,7 @@ void MainWindow::Play(const std::optional<std::string>& savestate_path)
|
||||||
if (!default_path.isEmpty() && QFile::exists(default_path))
|
if (!default_path.isEmpty() && QFile::exists(default_path))
|
||||||
{
|
{
|
||||||
StartGame(default_path, savestate_path);
|
StartGame(default_path, savestate_path);
|
||||||
|
EnableScreenSaver(false);
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
|
@ -384,6 +387,7 @@ void MainWindow::Play(const std::optional<std::string>& savestate_path)
|
||||||
void MainWindow::Pause()
|
void MainWindow::Pause()
|
||||||
{
|
{
|
||||||
Core::SetState(Core::State::Paused);
|
Core::SetState(Core::State::Paused);
|
||||||
|
EnableScreenSaver(true);
|
||||||
}
|
}
|
||||||
|
|
||||||
void MainWindow::OnStopComplete()
|
void MainWindow::OnStopComplete()
|
||||||
|
@ -461,6 +465,7 @@ bool MainWindow::RequestStop()
|
||||||
void MainWindow::ForceStop()
|
void MainWindow::ForceStop()
|
||||||
{
|
{
|
||||||
BootManager::Stop();
|
BootManager::Stop();
|
||||||
|
EnableScreenSaver(true);
|
||||||
}
|
}
|
||||||
|
|
||||||
void MainWindow::Reset()
|
void MainWindow::Reset()
|
||||||
|
@ -821,6 +826,18 @@ void MainWindow::NetPlayQuit()
|
||||||
Settings::Instance().ResetNetPlayServer();
|
Settings::Instance().ResetNetPlayServer();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void MainWindow::EnableScreenSaver(bool enable)
|
||||||
|
{
|
||||||
|
#if defined(HAVE_XRANDR) && HAVE_XRANDR
|
||||||
|
UICommon::EnableScreenSaver(
|
||||||
|
static_cast<Display*>(QGuiApplication::platformNativeInterface()->nativeResourceForWindow(
|
||||||
|
"display", windowHandle())),
|
||||||
|
winId(), enable);
|
||||||
|
#else
|
||||||
|
UICommon::EnableScreenSaver(enable);
|
||||||
|
#endif
|
||||||
|
}
|
||||||
|
|
||||||
bool MainWindow::eventFilter(QObject* object, QEvent* event)
|
bool MainWindow::eventFilter(QObject* object, QEvent* event)
|
||||||
{
|
{
|
||||||
if (event->type() == QEvent::Close)
|
if (event->type() == QEvent::Close)
|
||||||
|
|
|
@ -118,6 +118,8 @@ private:
|
||||||
void OnStopRecording();
|
void OnStopRecording();
|
||||||
void OnExportRecording();
|
void OnExportRecording();
|
||||||
|
|
||||||
|
void EnableScreenSaver(bool enable);
|
||||||
|
|
||||||
void OnStopComplete();
|
void OnStopComplete();
|
||||||
void dragEnterEvent(QDragEnterEvent* event) override;
|
void dragEnterEvent(QDragEnterEvent* event) override;
|
||||||
void dropEvent(QDropEvent* event) override;
|
void dropEvent(QDropEvent* event) override;
|
||||||
|
|
|
@ -73,6 +73,8 @@
|
||||||
#include "InputCommon/ControllerInterface/ControllerInterface.h"
|
#include "InputCommon/ControllerInterface/ControllerInterface.h"
|
||||||
#include "InputCommon/GCPadStatus.h"
|
#include "InputCommon/GCPadStatus.h"
|
||||||
|
|
||||||
|
#include "UICommon/UICommon.h"
|
||||||
|
|
||||||
#include "VideoCommon/OnScreenDisplay.h"
|
#include "VideoCommon/OnScreenDisplay.h"
|
||||||
#include "VideoCommon/RenderBase.h"
|
#include "VideoCommon/RenderBase.h"
|
||||||
#include "VideoCommon/VertexShaderManager.h"
|
#include "VideoCommon/VertexShaderManager.h"
|
||||||
|
@ -702,61 +704,13 @@ WXLRESULT CFrame::MSWWindowProc(WXUINT nMsg, WXWPARAM wParam, WXLPARAM lParam)
|
||||||
}
|
}
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
void CFrame::InhibitScreensaver()
|
void CFrame::EnableScreenSaver(bool enable)
|
||||||
{
|
{
|
||||||
// Inhibit the screensaver. Depending on the operating system this may also
|
#if defined(HAVE_XRANDR) && HAVE_XRANDR
|
||||||
// disable low-power states and/or screen dimming.
|
UICommon::EnableScreenSaver(X11Utils::XDisplayFromHandle(GetHandle()),
|
||||||
|
X11Utils::XWindowFromHandle(GetHandle()), enable);
|
||||||
#if defined(HAVE_X11) && HAVE_X11
|
#else
|
||||||
if (SConfig::GetInstance().bDisableScreenSaver)
|
UICommon::EnableScreenSaver(enable);
|
||||||
{
|
|
||||||
X11Utils::InhibitScreensaver(X11Utils::XDisplayFromHandle(GetHandle()),
|
|
||||||
X11Utils::XWindowFromHandle(GetHandle()), true);
|
|
||||||
}
|
|
||||||
#endif
|
|
||||||
|
|
||||||
#ifdef _WIN32
|
|
||||||
// Prevents Windows from sleeping, turning off the display, or idling
|
|
||||||
EXECUTION_STATE should_screen_save =
|
|
||||||
SConfig::GetInstance().bDisableScreenSaver ? ES_DISPLAY_REQUIRED : 0;
|
|
||||||
SetThreadExecutionState(ES_CONTINUOUS | should_screen_save | ES_SYSTEM_REQUIRED);
|
|
||||||
#endif
|
|
||||||
|
|
||||||
#ifdef __APPLE__
|
|
||||||
if (SConfig::GetInstance().bDisableScreenSaver)
|
|
||||||
{
|
|
||||||
CFStringRef reason_for_activity = CFSTR("Emulation Running");
|
|
||||||
if (IOPMAssertionCreateWithName(kIOPMAssertionTypePreventUserIdleDisplaySleep,
|
|
||||||
kIOPMAssertionLevelOn, reason_for_activity,
|
|
||||||
&m_power_assertion) != kIOReturnSuccess)
|
|
||||||
{
|
|
||||||
m_power_assertion = kIOPMNullAssertionID;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
#endif
|
|
||||||
}
|
|
||||||
|
|
||||||
void CFrame::UninhibitScreensaver()
|
|
||||||
{
|
|
||||||
#if defined(HAVE_X11) && HAVE_X11
|
|
||||||
if (SConfig::GetInstance().bDisableScreenSaver)
|
|
||||||
{
|
|
||||||
X11Utils::InhibitScreensaver(X11Utils::XDisplayFromHandle(GetHandle()),
|
|
||||||
X11Utils::XWindowFromHandle(GetHandle()), false);
|
|
||||||
}
|
|
||||||
#endif
|
|
||||||
|
|
||||||
#ifdef _WIN32
|
|
||||||
// Allow windows to resume normal idling behavior
|
|
||||||
SetThreadExecutionState(ES_CONTINUOUS);
|
|
||||||
#endif
|
|
||||||
|
|
||||||
#ifdef __APPLE__
|
|
||||||
if (m_power_assertion != kIOPMNullAssertionID)
|
|
||||||
{
|
|
||||||
IOPMAssertionRelease(m_power_assertion);
|
|
||||||
m_power_assertion = kIOPMNullAssertionID;
|
|
||||||
}
|
|
||||||
#endif
|
#endif
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -27,10 +27,6 @@
|
||||||
#include "UICommon/X11Utils.h"
|
#include "UICommon/X11Utils.h"
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
#ifdef __APPLE__
|
|
||||||
#include <IOKit/pwr_mgt/IOPMLib.h>
|
|
||||||
#endif
|
|
||||||
|
|
||||||
struct BootParameters;
|
struct BootParameters;
|
||||||
|
|
||||||
// Class declarations
|
// Class declarations
|
||||||
|
@ -244,13 +240,8 @@ private:
|
||||||
WXLRESULT MSWWindowProc(WXUINT nMsg, WXWPARAM wParam, WXLPARAM lParam);
|
WXLRESULT MSWWindowProc(WXUINT nMsg, WXWPARAM wParam, WXLPARAM lParam);
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
// Screensaver
|
// Screensaver
|
||||||
#ifdef __APPLE__
|
void EnableScreenSaver(bool enable);
|
||||||
IOPMAssertionID m_power_assertion = kIOPMNullAssertionID;
|
|
||||||
#endif
|
|
||||||
void InhibitScreensaver();
|
|
||||||
void UninhibitScreensaver();
|
|
||||||
|
|
||||||
void DoOpen(bool Boot);
|
void DoOpen(bool Boot);
|
||||||
void DoPause();
|
void DoPause();
|
||||||
void DoToggleToolbar(bool);
|
void DoToggleToolbar(bool);
|
||||||
|
|
|
@ -744,7 +744,7 @@ void CFrame::StartGame(std::unique_ptr<BootParameters> boot)
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
InhibitScreensaver();
|
EnableScreenSaver(false);
|
||||||
|
|
||||||
// We need this specifically to support setting the focus properly when using
|
// We need this specifically to support setting the focus properly when using
|
||||||
// the 'render to main window' feature on Windows
|
// the 'render to main window' feature on Windows
|
||||||
|
@ -931,7 +931,7 @@ void CFrame::OnStopped()
|
||||||
m_tried_graceful_shutdown = false;
|
m_tried_graceful_shutdown = false;
|
||||||
wxPostEvent(GetMenuBar(), wxCommandEvent{DOLPHIN_EVT_UPDATE_LOAD_WII_MENU_ITEM});
|
wxPostEvent(GetMenuBar(), wxCommandEvent{DOLPHIN_EVT_UPDATE_LOAD_WII_MENU_ITEM});
|
||||||
|
|
||||||
UninhibitScreensaver();
|
EnableScreenSaver(true);
|
||||||
|
|
||||||
m_render_frame->SetTitle(StrToWxStr(Common::scm_rev_str));
|
m_render_frame->SetTitle(StrToWxStr(Common::scm_rev_str));
|
||||||
|
|
||||||
|
|
|
@ -26,6 +26,14 @@
|
||||||
#include "UICommon/UICommon.h"
|
#include "UICommon/UICommon.h"
|
||||||
#include "UICommon/USBUtils.h"
|
#include "UICommon/USBUtils.h"
|
||||||
|
|
||||||
|
#if defined(HAVE_XRANDR) && HAVE_XRANDR
|
||||||
|
#include "UICommon/X11Utils.h"
|
||||||
|
#endif
|
||||||
|
|
||||||
|
#ifdef __APPLE__
|
||||||
|
#include <IOKit/pwr_mgt/IOPMLib.h>
|
||||||
|
#endif
|
||||||
|
|
||||||
#include "VideoCommon/VideoBackendBase.h"
|
#include "VideoCommon/VideoBackendBase.h"
|
||||||
|
|
||||||
namespace UICommon
|
namespace UICommon
|
||||||
|
@ -248,4 +256,61 @@ bool TriggerSTMPowerEvent()
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
#if defined(HAVE_XRANDR) && HAVE_X11
|
||||||
|
void EnableScreenSaver(Display* display, Window win, bool enable)
|
||||||
|
#else
|
||||||
|
void EnableScreenSaver(bool enable)
|
||||||
|
#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 (SConfig::GetInstance().bDisableScreenSaver)
|
||||||
|
{
|
||||||
|
X11Utils::InhibitScreensaver(display, win, !enable);
|
||||||
|
}
|
||||||
|
#endif
|
||||||
|
|
||||||
|
#ifdef _WIN32
|
||||||
|
// Prevents Windows from sleeping, turning off the display, or idling
|
||||||
|
if (enable)
|
||||||
|
{
|
||||||
|
SetThreadExecutionState(ES_CONTINUOUS);
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
EXECUTION_STATE should_screen_save =
|
||||||
|
SConfig::GetInstance().bDisableScreenSaver ? ES_DISPLAY_REQUIRED : 0;
|
||||||
|
SetThreadExecutionState(ES_CONTINUOUS | should_screen_save | ES_SYSTEM_REQUIRED);
|
||||||
|
}
|
||||||
|
#endif
|
||||||
|
|
||||||
|
#ifdef __APPLE__
|
||||||
|
static IOPMAssertionID s_power_assertion = kIOPMNullAssertionID;
|
||||||
|
|
||||||
|
if (SConfig::GetInstance().bDisableScreenSaver)
|
||||||
|
{
|
||||||
|
if (enable)
|
||||||
|
{
|
||||||
|
if (s_power_assertion != kIOPMNullAssertionID)
|
||||||
|
{
|
||||||
|
IOPMAssertionRelease(s_power_assertion);
|
||||||
|
s_power_assertion = kIOPMNullAssertionID;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
CFStringRef reason_for_activity = CFSTR("Emulation Running");
|
||||||
|
if (IOPMAssertionCreateWithName(kIOPMAssertionTypePreventUserIdleDisplaySleep,
|
||||||
|
kIOPMAssertionLevelOn, reason_for_activity,
|
||||||
|
&s_power_assertion) != kIOReturnSuccess)
|
||||||
|
{
|
||||||
|
s_power_assertion = kIOPMNullAssertionID;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
#endif
|
||||||
|
}
|
||||||
|
|
||||||
} // namespace UICommon
|
} // namespace UICommon
|
||||||
|
|
|
@ -4,11 +4,21 @@
|
||||||
|
|
||||||
#pragma once
|
#pragma once
|
||||||
|
|
||||||
|
#if defined(HAVE_XRANDR) && HAVE_XRANDR
|
||||||
|
#include <X11/extensions/Xrandr.h>
|
||||||
|
#endif
|
||||||
|
|
||||||
namespace UICommon
|
namespace UICommon
|
||||||
{
|
{
|
||||||
void Init();
|
void Init();
|
||||||
void Shutdown();
|
void Shutdown();
|
||||||
|
|
||||||
|
#if defined(HAVE_XRANDR) && HAVE_XRANDR
|
||||||
|
void EnableScreenSaver(Display* display, Window win, bool enable);
|
||||||
|
#else
|
||||||
|
void EnableScreenSaver(bool enable);
|
||||||
|
#endif
|
||||||
|
|
||||||
void CreateDirectories();
|
void CreateDirectories();
|
||||||
void SetUserDirectory(const std::string& custom_path);
|
void SetUserDirectory(const std::string& custom_path);
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue