Merge pull request #7541 from unknownbrackets/ui-tweaks

Keep Windows devices from sleeping while playing
This commit is contained in:
Henrik Rydgård 2015-03-01 18:11:22 +01:00
commit 72a2c8d0fe
3 changed files with 28 additions and 1 deletions

View File

@ -42,6 +42,10 @@
#include "Core/Debugger/Breakpoints.h"
// Time until we stop considering the core active without user input.
// Should this be configurable? 2 hours currently.
static const double ACTIVITY_IDLE_TIMEOUT = 2.0 * 3600.0;
static event m_hStepEvent;
static recursive_mutex m_hStepMutex;
static event m_hInactiveEvent;
@ -49,6 +53,8 @@ static recursive_mutex m_hInactiveMutex;
static bool singleStepPending = false;
static std::set<Core_ShutdownFunc> shutdownFuncs;
static bool windowHidden = false;
static double lastActivity = 0.0;
static double lastKeepAwake = 0.0;
#ifdef _WIN32
InputState input_state;
@ -61,6 +67,10 @@ void Core_NotifyWindowHidden(bool hidden) {
// TODO: Wait until we can react?
}
void Core_NotifyActivity() {
lastActivity = time_now_d();
}
void Core_ListenShutdown(Core_ShutdownFunc func) {
shutdownFuncs.insert(func);
}
@ -200,6 +210,17 @@ void Core_RunLoop() {
#if defined(USING_WIN_UI)
if (!windowHidden && !Core_IsStepping()) {
GPU_SwapBuffers();
// Keep the system awake for longer than normal for cutscenes and the like.
const double now = time_now_d();
if (now < lastActivity + ACTIVITY_IDLE_TIMEOUT) {
// Only resetting it ever prime number seconds in case the call is expensive.
// Using a prime number to ensure there's no interaction with other periodic events.
if (now - lastKeepAwake > 89.0 || now < lastKeepAwake) {
SetThreadExecutionState(ES_SYSTEM_REQUIRED | ES_DISPLAY_REQUIRED);
lastKeepAwake = now;
}
}
}
#endif
}

View File

@ -46,4 +46,4 @@ bool UpdateScreenScale(int width, int height);
// Don't run the core when minimized etc.
void Core_NotifyWindowHidden(bool hidden);
void Core_NotifyActivity();

View File

@ -285,6 +285,8 @@ inline float clamp1(float x) {
}
bool EmuScreen::touch(const TouchInput &touch) {
Core_NotifyActivity();
if (root_) {
root_->Touch(touch);
return true;
@ -427,6 +429,8 @@ inline void EmuScreen::setVKeyAnalogY(int stick, int virtualKeyMin, int virtualK
}
bool EmuScreen::key(const KeyInput &key) {
Core_NotifyActivity();
std::vector<int> pspKeys;
KeyMap::KeyToPspButton(key.deviceId, key.keyCode, &pspKeys);
@ -470,6 +474,8 @@ void EmuScreen::pspKey(int pspKeyCode, int flags) {
}
bool EmuScreen::axis(const AxisInput &axis) {
Core_NotifyActivity();
if (axis.value > 0) {
processAxis(axis, 1);
return true;