Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Prevent Windows Display Sleep #1850

Merged
merged 1 commit into from
Jan 24, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
35 changes: 35 additions & 0 deletions Ryujinx.Common/System/DisplaySleep.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
using System;
using System.Runtime.InteropServices;

namespace Ryujinx.Common.System
{
public class DisplaySleep
{
[Flags]
enum EXECUTION_STATE : uint
{
ES_CONTINUOUS = 0x80000000,
ES_DISPLAY_REQUIRED = 0x00000002,
ES_SYSTEM_REQUIRED = 0x00000001
}

[DllImport("kernel32.dll", CharSet = CharSet.Auto, SetLastError = true)]
static extern EXECUTION_STATE SetThreadExecutionState(EXECUTION_STATE esFlags);

static public void Prevent()
{
if (RuntimeInformation.IsOSPlatform(OSPlatform.Windows))
{
SetThreadExecutionState(EXECUTION_STATE.ES_CONTINUOUS | EXECUTION_STATE.ES_SYSTEM_REQUIRED | EXECUTION_STATE.ES_DISPLAY_REQUIRED);
}
}

static public void Restore()
{
if (RuntimeInformation.IsOSPlatform(OSPlatform.Windows))
{
SetThreadExecutionState(EXECUTION_STATE.ES_CONTINUOUS);
}
}
}
}
3 changes: 3 additions & 0 deletions Ryujinx/Ui/MainWindow.cs
Original file line number Diff line number Diff line change
Expand Up @@ -549,6 +549,8 @@ private void CreateGameWindow()
_windowsMultimediaTimerResolution = new WindowsMultimediaTimerResolution(1);
}

DisplaySleep.Prevent();

GlRendererWidget = new GlRenderer(_emulationContext, ConfigurationState.Instance.Logger.GraphicsDebugLevel);

Application.Invoke(delegate
Expand Down Expand Up @@ -600,6 +602,7 @@ private void CreateGameWindow()

_windowsMultimediaTimerResolution?.Dispose();
_windowsMultimediaTimerResolution = null;
DisplaySleep.Restore();

_viewBox.Add(_gameTableWindow);

Expand Down
3 changes: 2 additions & 1 deletion Ryujinx/Ui/Windows/SettingsWindow.glade
Original file line number Diff line number Diff line change
Expand Up @@ -1283,6 +1283,7 @@
<object class="GtkLabel">
<property name="visible">True</property>
<property name="can-focus">False</property>
<property name="tooltip-text" translatable="yes">Change System Time</property>
<property name="halign">end</property>
<property name="label" translatable="yes">System Time:</property>
</object>
Expand Down Expand Up @@ -1493,7 +1494,7 @@
<object class="GtkLabel">
<property name="visible">True</property>
<property name="can-focus">False</property>
<property name="tooltip-text" translatable="yes">Change System Region</property>
<property name="tooltip-text" translatable="yes">Change Audio Backend</property>
<property name="halign">end</property>
<property name="margin-right">5</property>
<property name="label" translatable="yes">Audio Backend: </property>
Expand Down