Skip to content

Commit

Permalink
Merge pull request #6104 from peppy/process-priority
Browse files Browse the repository at this point in the history
Set process priority of framework window to high when focused
  • Loading branch information
bdach authored Jan 8, 2024
2 parents 0c2abe9 + 1b3e934 commit 6f99a96
Showing 1 changed file with 17 additions and 0 deletions.
17 changes: 17 additions & 0 deletions osu.Framework/Platform/Windows/WindowsGameHost.cs
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@

using System;
using System.Collections.Generic;
using System.Diagnostics;
using System.IO;
using System.Linq;
using System.Runtime.Versioning;
Expand Down Expand Up @@ -93,13 +94,29 @@ protected override void Dispose(bool isDisposing)
protected override void OnActivated()
{
Execution.SetThreadExecutionState(Execution.ExecutionState.Continuous | Execution.ExecutionState.SystemRequired | Execution.ExecutionState.DisplayRequired);
setGamePriority(true);
base.OnActivated();
}

protected override void OnDeactivated()
{
Execution.SetThreadExecutionState(Execution.ExecutionState.Continuous);
setGamePriority(false);
base.OnDeactivated();
}

private void setGamePriority(bool active)
{
try
{
// We set process priority after the window becomes active, because for whatever reason windows will
// reset this when the window becomes active after being inactive when game mode is enabled.
Process.GetCurrentProcess().PriorityClass = active ? ProcessPriorityClass.High : ProcessPriorityClass.Normal;
}
catch
{
// Failure to set priority is not critical.
}
}
}
}

0 comments on commit 6f99a96

Please sign in to comment.