summaryrefslogtreecommitdiff
path: root/Source/Core
diff options
context:
space:
mode:
authorspycrab <spycrab@users.noreply.github.com>2018-01-01 21:03:50 +0000
committerspycrab <spycrab@users.noreply.github.com>2018-01-03 12:38:33 +0100
commit0dd52ca7abdadbf24c831bfbf9ac8f39a7627ec9 (patch)
treedb43cfb5ef6eea3e7bcb4c5037804adf23bc268d /Source/Core
parent26a9957285aac023ee7d35cf506b82381575df9a (diff)
UICommon: Move screensaver code to UICommon
Diffstat (limited to 'Source/Core')
-rw-r--r--Source/Core/DolphinWX/Frame.cpp62
-rw-r--r--Source/Core/DolphinWX/Frame.h13
-rw-r--r--Source/Core/DolphinWX/FrameTools.cpp4
-rw-r--r--Source/Core/UICommon/UICommon.cpp65
-rw-r--r--Source/Core/UICommon/UICommon.h10
5 files changed, 87 insertions, 67 deletions
diff --git a/Source/Core/DolphinWX/Frame.cpp b/Source/Core/DolphinWX/Frame.cpp
index afe4817917..c9745efb33 100644
--- a/Source/Core/DolphinWX/Frame.cpp
+++ b/Source/Core/DolphinWX/Frame.cpp
@@ -73,6 +73,8 @@
#include "InputCommon/ControllerInterface/ControllerInterface.h"
#include "InputCommon/GCPadStatus.h"
+#include "UICommon/UICommon.h"
+
#include "VideoCommon/OnScreenDisplay.h"
#include "VideoCommon/RenderBase.h"
#include "VideoCommon/VertexShaderManager.h"
@@ -702,61 +704,13 @@ 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(kIOPMAssertionTypePreventUserIdleDisplaySleep,
- kIOPMAssertionLevelOn, reason_for_activity,
- &m_power_assertion) != kIOReturnSuccess)
- {
- m_power_assertion = kIOPMNullAssertionID;
- }
- }
-#endif
-}
-
-void CFrame::UninhibitScreensaver()
+void CFrame::EnableScreenSaver(bool enable)
{
-#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;
- }
+#if defined(HAVE_XRANDR) && HAVE_XRANDR
+ UICommon::EnableScreenSaver(X11Utils::XDisplayFromHandle(GetHandle()),
+ X11Utils::XWindowFromHandle(GetHandle()), enable);
+#else
+ UICommon::EnableScreenSaver(enable);
#endif
}
diff --git a/Source/Core/DolphinWX/Frame.h b/Source/Core/DolphinWX/Frame.h
index bdef068a58..4f2178862a 100644
--- a/Source/Core/DolphinWX/Frame.h
+++ b/Source/Core/DolphinWX/Frame.h
@@ -27,10 +27,6 @@
#include "UICommon/X11Utils.h"
#endif
-#ifdef __APPLE__
-#include <IOKit/pwr_mgt/IOPMLib.h>
-#endif
-
struct BootParameters;
// Class declarations
@@ -244,13 +240,8 @@ private:
WXLRESULT MSWWindowProc(WXUINT nMsg, WXWPARAM wParam, WXLPARAM lParam);
#endif
-// Screensaver
-#ifdef __APPLE__
- IOPMAssertionID m_power_assertion = kIOPMNullAssertionID;
-#endif
- void InhibitScreensaver();
- void UninhibitScreensaver();
-
+ // Screensaver
+ void EnableScreenSaver(bool enable);
void DoOpen(bool Boot);
void DoPause();
void DoToggleToolbar(bool);
diff --git a/Source/Core/DolphinWX/FrameTools.cpp b/Source/Core/DolphinWX/FrameTools.cpp
index 929e435bd9..28bce659e3 100644
--- a/Source/Core/DolphinWX/FrameTools.cpp
+++ b/Source/Core/DolphinWX/FrameTools.cpp
@@ -744,7 +744,7 @@ void CFrame::StartGame(std::unique_ptr<BootParameters> boot)
}
else
{
- InhibitScreensaver();
+ EnableScreenSaver(false);
// We need this specifically to support setting the focus properly when using
// the 'render to main window' feature on Windows
@@ -931,7 +931,7 @@ void CFrame::OnStopped()
m_tried_graceful_shutdown = false;
wxPostEvent(GetMenuBar(), wxCommandEvent{DOLPHIN_EVT_UPDATE_LOAD_WII_MENU_ITEM});
- UninhibitScreensaver();
+ EnableScreenSaver(true);
m_render_frame->SetTitle(StrToWxStr(Common::scm_rev_str));
diff --git a/Source/Core/UICommon/UICommon.cpp b/Source/Core/UICommon/UICommon.cpp
index 96719f5051..06d4db5850 100644
--- a/Source/Core/UICommon/UICommon.cpp
+++ b/Source/Core/UICommon/UICommon.cpp
@@ -26,6 +26,14 @@
#include "UICommon/UICommon.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"
namespace UICommon
@@ -248,4 +256,61 @@ bool TriggerSTMPowerEvent()
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
diff --git a/Source/Core/UICommon/UICommon.h b/Source/Core/UICommon/UICommon.h
index 3781c2c58f..5e11c9bfc2 100644
--- a/Source/Core/UICommon/UICommon.h
+++ b/Source/Core/UICommon/UICommon.h
@@ -4,11 +4,21 @@
#pragma once
+#if defined(HAVE_XRANDR) && HAVE_XRANDR
+#include <X11/extensions/Xrandr.h>
+#endif
+
namespace UICommon
{
void Init();
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 SetUserDirectory(const std::string& custom_path);