BizHawk/BizHawk.Client.EmuHawk/ScreenSaver.cs

66 lines
1.7 KiB
C#
Raw Normal View History

2019-05-18 05:42:32 +00:00
using System.Runtime.InteropServices;
2011-01-11 02:55:51 +00:00
Add preliminary Unix compatibility (using Mono; resolves #1384) (#1380) * Move PlatformSpecificLinkedLibs and implementations to common and rename * Specify file ext. at LoadPlatformSpecific call site * Move Client.Common.Global.RunningOnUnix to PlatformLinkedLibSingleton * Inline var Resolver * Use PlatformLinkedLibManager internally * Move plugin load check to LinkedLibManager, use LinkedLibManager * Interpolate * Return exit code from dlclose/FreeLibrary * Skip all calls to externs in BlipBufDll when using mono * Use PlatformLinkedLibManager in SevenZipLibraryManager * Add expected return value to workaround (from testing on Win32) * Remove ".dll" from DllImport attr, remove temporary workaround, see desc. The library can be built by changing the output file name in `.../blip_buf/Makefile` to `libblip_buf.so`, and running `make`. It will be loaded if placed in the `.../output` folder. * Remove unused code, add TODO (this class is req. for Waterbox.PeWrapper) The TODO is to [rewrite with C#](https://docs.microsoft.com/en-us/dotnet/standard/io/memory-mapped-files) instead of importing from `kernel32.dll`. * Update OpenTK again but better (for #1384) * Add Mono run script * Add libblip_buf.so (temporary) Temporary because it should be a separate package which BizHawk depends on. * Add distro detection, add "already running" and "unknown distro" messages * Gray-out Lua Console on Unix * Extract superclass from EmuLuaLibrary, add shell implementation for Unix * Specify libdl version, Fedora doesn't have the versionless symlink * Remove empty `ToolStripMenuItem`, null `Text` caused crash on Unix * Transform OpenTK keyboard input into a `List<KeyEvent>` and read that Also fixes crash on rebind * Remove debug `using ...;`
2019-01-03 22:50:55 +00:00
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
{
[DllImport("user32.dll", CharSet = CharSet.Auto)]
private static extern bool SystemParametersInfo(int uAction, int uParam, ref int lpvParam, int flags);
2019-05-18 05:42:32 +00:00
private const int SPI_GETSCREENSAVERTIMEOUT = 14;
private const int SPI_SETSCREENSAVERTIMEOUT = 15;
private const int SPIF_SENDWININICHANGE = 2;
public int Duration
{
2019-05-18 05:42:32 +00:00
get
{
var value = 0;
SystemParametersInfo(SPI_GETSCREENSAVERTIMEOUT, 0, ref value, 0);
return value;
}
set
{
var nullVar = 0;
SystemParametersInfo(SPI_SETSCREENSAVERTIMEOUT, value, ref nullVar, SPIF_SENDWININICHANGE);
}
}
}
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
2019-05-18 05:42:32 +00:00
private static readonly IScreenBlankTimer _screenBlankTimer = OSTailoredCode.CurrentOS == OSTailoredCode.DistinctOS.Windows
? (IScreenBlankTimer) new Win32ScreenBlankTimer()
: new UnixScreenBlankTimer();
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
}