/ src / Ryujinx.Common / SystemInterop / DisplaySleep.cs
DisplaySleep.cs
 1  using System;
 2  using System.Runtime.InteropServices;
 3  
 4  namespace Ryujinx.Common.SystemInterop
 5  {
 6      public partial class DisplaySleep
 7      {
 8          [Flags]
 9          enum EXECUTION_STATE : uint
10          {
11              ES_CONTINUOUS = 0x80000000,
12              ES_DISPLAY_REQUIRED = 0x00000002,
13              ES_SYSTEM_REQUIRED = 0x00000001,
14          }
15  
16          [LibraryImport("kernel32.dll", SetLastError = true)]
17          private static partial EXECUTION_STATE SetThreadExecutionState(EXECUTION_STATE esFlags);
18  
19          static public void Prevent()
20          {
21              if (OperatingSystem.IsWindows())
22              {
23                  SetThreadExecutionState(EXECUTION_STATE.ES_CONTINUOUS | EXECUTION_STATE.ES_SYSTEM_REQUIRED | EXECUTION_STATE.ES_DISPLAY_REQUIRED);
24              }
25          }
26  
27          static public void Restore()
28          {
29              if (OperatingSystem.IsWindows())
30              {
31                  SetThreadExecutionState(EXECUTION_STATE.ES_CONTINUOUS);
32              }
33          }
34      }
35  }