From 65250c0452292b7cf1c5fcfbfc9ab5f1945dcf3a Mon Sep 17 00:00:00 2001 From: Salehen Shovon Rahman Date: Sat, 17 Dec 2016 20:40:03 -0800 Subject: [PATCH 1/3] Disable screensaver on OS X When playing a game on OS X, although the screen does not go to sleep, the screensaver is still enabled, and therefore, during gameplay, the screensaver may start running, which is not in accordance to the behaviour on other other environments (Windows and X11). It can be argued that the screensaver interrupting gameplay is a nuissance to many players. The changes in this commit are intended to allow Dolphin to disable the screensaver during gameplay, just as intended on other platforms. The changes have been tested on OS X 10.11 (El Capitan). --- Source/Core/DolphinWX/Frame.h | 8 ++++++++ Source/Core/DolphinWX/FrameTools.cpp | 19 +++++++++++++++++++ 2 files changed, 27 insertions(+) diff --git a/Source/Core/DolphinWX/Frame.h b/Source/Core/DolphinWX/Frame.h index e5453efe4a..e7a821bfe8 100644 --- a/Source/Core/DolphinWX/Frame.h +++ b/Source/Core/DolphinWX/Frame.h @@ -23,6 +23,10 @@ #include "UICommon/X11Utils.h" #endif +#ifdef __APPLE__ +#import +#endif + // Class declarations class CGameListCtrl; class CCodeWindow; @@ -160,6 +164,10 @@ private: ADD_PANE_CENTER }; +#ifdef __APPLE__ + IOPMAssertionID m_power_assertion = kIOPMNullAssertionID; +#endif + wxTimer m_poll_hotkey_timer; wxTimer m_handle_signal_timer; diff --git a/Source/Core/DolphinWX/FrameTools.cpp b/Source/Core/DolphinWX/FrameTools.cpp index 608141e94e..6ce69b42c8 100644 --- a/Source/Core/DolphinWX/FrameTools.cpp +++ b/Source/Core/DolphinWX/FrameTools.cpp @@ -84,6 +84,10 @@ #include "VideoCommon/VideoBackendBase.h" #include "VideoCommon/VideoConfig.h" +#ifdef __APPLE__ +#import +#endif + class InputConfig; class wxFrame; @@ -724,6 +728,14 @@ void CFrame::StartGame(const std::string& filename) SConfig::GetInstance().bDisableScreenSaver ? ES_DISPLAY_REQUIRED : 0; SetThreadExecutionState(ES_CONTINUOUS | shouldScreenSave | ES_SYSTEM_REQUIRED); #endif +#ifdef __APPLE__ + CFStringRef reason_for_activity = CFSTR("Emulation Running"); + if (IOPMAssertionCreateWithName(kIOPMAssertionTypeNoDisplaySleep, kIOPMAssertionLevelOn, + reason_for_activity, &m_power_assertion) != kIOReturnSuccess) + { + m_power_assertion = kIOPMNullAssertionID; + } +#endif // We need this specifically to support setting the focus properly when using // the 'render to main window' feature on Windows @@ -898,6 +910,13 @@ void CFrame::OnStopped() // 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 m_RenderFrame->SetTitle(StrToWxStr(scm_rev_str)); From c9b2c29eadae0947758a68b3304234f4e0050212 Mon Sep 17 00:00:00 2001 From: MerryMage Date: Sun, 9 Apr 2017 22:08:52 +0100 Subject: [PATCH 2/3] Frame: Extract screensaver-related code into InhibitScreensaver/UninhibitScreensaver --- Source/Core/DolphinWX/Frame.cpp | 57 ++++++++++++++++++++++++++++ Source/Core/DolphinWX/Frame.h | 13 ++++--- Source/Core/DolphinWX/FrameTools.cpp | 43 +-------------------- 3 files changed, 67 insertions(+), 46 deletions(-) diff --git a/Source/Core/DolphinWX/Frame.cpp b/Source/Core/DolphinWX/Frame.cpp index ddedd06525..232b0a90dc 100644 --- a/Source/Core/DolphinWX/Frame.cpp +++ b/Source/Core/DolphinWX/Frame.cpp @@ -690,6 +690,63 @@ WXLRESULT CFrame::MSWWindowProc(WXUINT nMsg, WXWPARAM wParam, WXLPARAM lParam) } #endif +void CFrame::InhibitScreensaver() +{ +// 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(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(kIOPMAssertionTypeNoDisplaySleep, 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 +} + void CFrame::UpdateTitle(const std::string& str) { if (SConfig::GetInstance().bRenderToMain && SConfig::GetInstance().m_InterfaceStatusbar) diff --git a/Source/Core/DolphinWX/Frame.h b/Source/Core/DolphinWX/Frame.h index e7a821bfe8..a097f975fd 100644 --- a/Source/Core/DolphinWX/Frame.h +++ b/Source/Core/DolphinWX/Frame.h @@ -24,7 +24,7 @@ #endif #ifdef __APPLE__ -#import +#include #endif // Class declarations @@ -164,10 +164,6 @@ private: ADD_PANE_CENTER }; -#ifdef __APPLE__ - IOPMAssertionID m_power_assertion = kIOPMNullAssertionID; -#endif - wxTimer m_poll_hotkey_timer; wxTimer m_handle_signal_timer; @@ -231,6 +227,13 @@ private: WXLRESULT MSWWindowProc(WXUINT nMsg, WXWPARAM wParam, WXLPARAM lParam); #endif +// Screensaver +#ifdef __APPLE__ + IOPMAssertionID m_power_assertion = kIOPMNullAssertionID; +#endif + void InhibitScreensaver(); + void UninhibitScreensaver(); + void DoOpen(bool Boot); void DoPause(); void DoToggleToolbar(bool); diff --git a/Source/Core/DolphinWX/FrameTools.cpp b/Source/Core/DolphinWX/FrameTools.cpp index 6ce69b42c8..a9e097ba54 100644 --- a/Source/Core/DolphinWX/FrameTools.cpp +++ b/Source/Core/DolphinWX/FrameTools.cpp @@ -84,10 +84,6 @@ #include "VideoCommon/VideoBackendBase.h" #include "VideoCommon/VideoConfig.h" -#ifdef __APPLE__ -#import -#endif - class InputConfig; class wxFrame; @@ -716,26 +712,7 @@ void CFrame::StartGame(const std::string& filename) } else { -#if defined(HAVE_X11) && HAVE_X11 - if (SConfig::GetInstance().bDisableScreenSaver) - X11Utils::InhibitScreensaver(X11Utils::XDisplayFromHandle(GetHandle()), - X11Utils::XWindowFromHandle(GetHandle()), true); -#endif - -#ifdef _WIN32 - // Prevents Windows from sleeping, turning off the display, or idling - EXECUTION_STATE shouldScreenSave = - SConfig::GetInstance().bDisableScreenSaver ? ES_DISPLAY_REQUIRED : 0; - SetThreadExecutionState(ES_CONTINUOUS | shouldScreenSave | ES_SYSTEM_REQUIRED); -#endif -#ifdef __APPLE__ - CFStringRef reason_for_activity = CFSTR("Emulation Running"); - if (IOPMAssertionCreateWithName(kIOPMAssertionTypeNoDisplaySleep, kIOPMAssertionLevelOn, - reason_for_activity, &m_power_assertion) != kIOReturnSuccess) - { - m_power_assertion = kIOPMNullAssertionID; - } -#endif + InhibitScreensaver(); // We need this specifically to support setting the focus properly when using // the 'render to main window' feature on Windows @@ -900,23 +877,7 @@ void CFrame::OnStopped() m_confirmStop = false; m_tried_graceful_shutdown = false; -#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 + UninhibitScreensaver(); m_RenderFrame->SetTitle(StrToWxStr(scm_rev_str)); From 4537969822c3a653f83bd7fea59062ebc6bbcdd3 Mon Sep 17 00:00:00 2001 From: MerryMage Date: Sun, 9 Apr 2017 22:11:55 +0100 Subject: [PATCH 3/3] Frame: Use kIOPMAssertionTypePreventUserIdleDisplaySleep to inhibit screensaver on macOS --- Source/Core/DolphinWX/Frame.cpp | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/Source/Core/DolphinWX/Frame.cpp b/Source/Core/DolphinWX/Frame.cpp index 232b0a90dc..e008224643 100644 --- a/Source/Core/DolphinWX/Frame.cpp +++ b/Source/Core/DolphinWX/Frame.cpp @@ -714,8 +714,9 @@ void CFrame::InhibitScreensaver() if (SConfig::GetInstance().bDisableScreenSaver) { CFStringRef reason_for_activity = CFSTR("Emulation Running"); - if (IOPMAssertionCreateWithName(kIOPMAssertionTypeNoDisplaySleep, kIOPMAssertionLevelOn, - reason_for_activity, &m_power_assertion) != kIOReturnSuccess) + if (IOPMAssertionCreateWithName(kIOPMAssertionTypePreventUserIdleDisplaySleep, + kIOPMAssertionLevelOn, reason_for_activity, + &m_power_assertion) != kIOReturnSuccess) { m_power_assertion = kIOPMNullAssertionID; }