2011-01-11 02:55:51 +00:00
|
|
|
|
using System;
|
|
|
|
|
using System.Runtime.InteropServices;
|
|
|
|
|
|
2018-11-04 17:05:20 +00:00
|
|
|
|
using BizHawk.Client.Common;
|
2019-01-03 22:50:55 +00:00
|
|
|
|
using BizHawk.Common;
|
2018-11-04 17:05:20 +00:00
|
|
|
|
|
2013-11-03 03:54:37 +00:00
|
|
|
|
namespace BizHawk.Client.EmuHawk
|
2011-01-11 02:55:51 +00:00
|
|
|
|
{
|
2011-06-19 23:39:25 +00:00
|
|
|
|
// Derived from http://www.codeproject.com/KB/cs/ScreenSaverControl.aspx
|
|
|
|
|
public static class ScreenSaver
|
|
|
|
|
{
|
2018-11-04 17:05:20 +00:00
|
|
|
|
private interface PlatformSpecificScreenBlankInterface
|
|
|
|
|
{
|
|
|
|
|
Int32 Get();
|
|
|
|
|
void Set(Int32 v);
|
|
|
|
|
}
|
|
|
|
|
private class WinScreenBlankInterface : PlatformSpecificScreenBlankInterface
|
|
|
|
|
{
|
|
|
|
|
[DllImport("user32.dll", CharSet = CharSet.Auto)]
|
|
|
|
|
private static extern bool SystemParametersInfo(int uAction, int uParam, ref int lpvParam, int flags);
|
|
|
|
|
public Int32 Get()
|
|
|
|
|
{
|
|
|
|
|
Int32 value = 0;
|
|
|
|
|
SystemParametersInfo(SPI_GETSCREENSAVERTIMEOUT, 0, ref value, 0);
|
|
|
|
|
return value;
|
|
|
|
|
}
|
|
|
|
|
public void Set(Int32 v)
|
|
|
|
|
{
|
|
|
|
|
int nullVar = 0;
|
|
|
|
|
SystemParametersInfo(SPI_SETSCREENSAVERTIMEOUT, v, ref nullVar, SPIF_SENDWININICHANGE);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
private class MiscUnixScreenBlankInterface : PlatformSpecificScreenBlankInterface
|
|
|
|
|
{
|
|
|
|
|
public Int32 Get()
|
|
|
|
|
{
|
|
|
|
|
return 0; //TODO implement
|
|
|
|
|
}
|
|
|
|
|
public void Set(Int32 v)
|
|
|
|
|
{
|
|
|
|
|
//TODO implement
|
|
|
|
|
}
|
|
|
|
|
}
|
2019-01-03 22:50:55 +00:00
|
|
|
|
private static PlatformSpecificScreenBlankInterface screenBlankInterface = PlatformLinkedLibSingleton.RunningOnUnix
|
2018-11-04 17:05:20 +00:00
|
|
|
|
? (PlatformSpecificScreenBlankInterface) new MiscUnixScreenBlankInterface()
|
|
|
|
|
: (PlatformSpecificScreenBlankInterface) new WinScreenBlankInterface();
|
2011-01-11 02:55:51 +00:00
|
|
|
|
|
2011-06-19 23:39:25 +00:00
|
|
|
|
private const int SPI_GETSCREENSAVERTIMEOUT = 14;
|
|
|
|
|
private const int SPI_SETSCREENSAVERTIMEOUT = 15;
|
|
|
|
|
private const int SPIF_SENDWININICHANGE = 2;
|
2011-01-11 02:55:51 +00:00
|
|
|
|
|
2011-06-19 23:39:25 +00:00
|
|
|
|
public static void ResetTimerImmediate()
|
|
|
|
|
{
|
|
|
|
|
SetScreenSaverTimeout(GetScreenSaverTimeout());
|
|
|
|
|
}
|
2011-01-11 02:55:51 +00:00
|
|
|
|
|
2011-06-19 23:39:25 +00:00
|
|
|
|
private static int ctr;
|
|
|
|
|
public static void ResetTimerPeriodically()
|
|
|
|
|
{
|
|
|
|
|
ctr++;
|
|
|
|
|
if (ctr == 120)
|
|
|
|
|
{
|
|
|
|
|
SetScreenSaverTimeout(GetScreenSaverTimeout());
|
|
|
|
|
ctr = 0;
|
|
|
|
|
}
|
|
|
|
|
}
|
2011-01-11 02:55:51 +00:00
|
|
|
|
|
2011-06-19 23:39:25 +00:00
|
|
|
|
// Returns the screen saver timeout setting, in seconds
|
|
|
|
|
private static Int32 GetScreenSaverTimeout()
|
|
|
|
|
{
|
2018-11-04 17:05:20 +00:00
|
|
|
|
return screenBlankInterface.Get();
|
2011-06-19 23:39:25 +00:00
|
|
|
|
}
|
2011-01-11 02:55:51 +00:00
|
|
|
|
|
2011-06-19 23:39:25 +00:00
|
|
|
|
// Pass in the number of seconds to set the screen saver timeout value.
|
|
|
|
|
private static void SetScreenSaverTimeout(Int32 Value)
|
|
|
|
|
{
|
2018-11-04 17:05:20 +00:00
|
|
|
|
screenBlankInterface.Set(Value);
|
2011-06-19 23:39:25 +00:00
|
|
|
|
}
|
|
|
|
|
}
|
2011-01-11 02:55:51 +00:00
|
|
|
|
}
|