DisplaySleep.cs 1.0 KB

1234567891011121314151617181920212223242526272829303132333435
  1. using System;
  2. using System.Runtime.InteropServices;
  3. namespace Ryujinx.Common.System
  4. {
  5. public class DisplaySleep
  6. {
  7. [Flags]
  8. enum EXECUTION_STATE : uint
  9. {
  10. ES_CONTINUOUS = 0x80000000,
  11. ES_DISPLAY_REQUIRED = 0x00000002,
  12. ES_SYSTEM_REQUIRED = 0x00000001
  13. }
  14. [DllImport("kernel32.dll", CharSet = CharSet.Auto, SetLastError = true)]
  15. static extern EXECUTION_STATE SetThreadExecutionState(EXECUTION_STATE esFlags);
  16. static public void Prevent()
  17. {
  18. if (RuntimeInformation.IsOSPlatform(OSPlatform.Windows))
  19. {
  20. SetThreadExecutionState(EXECUTION_STATE.ES_CONTINUOUS | EXECUTION_STATE.ES_SYSTEM_REQUIRED | EXECUTION_STATE.ES_DISPLAY_REQUIRED);
  21. }
  22. }
  23. static public void Restore()
  24. {
  25. if (RuntimeInformation.IsOSPlatform(OSPlatform.Windows))
  26. {
  27. SetThreadExecutionState(EXECUTION_STATE.ES_CONTINUOUS);
  28. }
  29. }
  30. }
  31. }