BizHawk/BizHawk.Client.EmuHawk/ScreenSaver.cs

60 lines
1.5 KiB
C#
Raw Normal View History

using BizHawk.Common;
namespace BizHawk.Client.EmuHawk
2011-01-11 02:55:51 +00:00
{
2019-05-18 05:42:32 +00:00
/// <remarks>Derived from http://www.codeproject.com/KB/cs/ScreenSaverControl.aspx</remarks>
public static class ScreenSaver
{
2019-05-18 05:42:32 +00:00
private interface IScreenBlankTimer
{
2019-05-18 05:42:32 +00:00
/// <summary>
/// The screen saver timeout setting, in seconds
/// </summary>
int Duration { get; set; }
}
2019-05-18 05:42:32 +00:00
private class Win32ScreenBlankTimer : IScreenBlankTimer
{
2019-05-18 05:42:32 +00:00
public int Duration
{
2019-05-18 05:42:32 +00:00
get
{
const int SPI_GETSCREENSAVERTIMEOUT = 14;
int value = default;
Win32Imports.SystemParametersInfo(SPI_GETSCREENSAVERTIMEOUT, 0, ref value, 0);
2019-05-18 05:42:32 +00:00
return value;
}
set
{
const int SPI_SETSCREENSAVERTIMEOUT = 15;
const int SPIF_SENDWININICHANGE = 2;
int nullVar = default;
Win32Imports.SystemParametersInfo(SPI_SETSCREENSAVERTIMEOUT, value, ref nullVar, SPIF_SENDWININICHANGE);
2019-05-18 05:42:32 +00:00
}
}
}
2011-01-11 02:55:51 +00:00
2019-05-18 05:42:32 +00:00
private class UnixScreenBlankTimer : IScreenBlankTimer
{
2019-05-18 05:42:32 +00:00
public int Duration { get; set; } = 0; //TODO implementation
}
2011-01-11 02:55:51 +00:00
private static readonly IScreenBlankTimer _screenBlankTimer = OSTailoredCode.IsUnixHost
? (IScreenBlankTimer) new UnixScreenBlankTimer()
: new Win32ScreenBlankTimer();
2019-05-18 05:42:32 +00:00
private static int ctr;
2011-01-11 02:55:51 +00:00
2019-05-18 05:42:32 +00:00
public static void ResetTimerImmediate()
{
2019-05-18 05:42:32 +00:00
_screenBlankTimer.Duration = _screenBlankTimer.Duration;
}
2011-01-11 02:55:51 +00:00
2019-05-18 05:42:32 +00:00
public static void ResetTimerPeriodically()
{
2019-05-18 05:42:32 +00:00
if (++ctr < 120) return;
ctr = 0;
ResetTimerImmediate();
}
}
2019-05-18 05:42:32 +00:00
}