Skip to content

Commit

Permalink
SteamController: Force to reconnect X360 controller on Resume
Browse files Browse the repository at this point in the history
  • Loading branch information
ayufan committed Jan 3, 2023
1 parent af02697 commit 40e2f62
Show file tree
Hide file tree
Showing 2 changed files with 19 additions and 0 deletions.
1 change: 1 addition & 0 deletions RELEASE.md
Original file line number Diff line number Diff line change
Expand Up @@ -30,3 +30,4 @@
- GPU detection will log errors to `Sentry.io`
- Support SMU of Vangogh GPU shipped with BIOS 113
- Fix Steam Game detection when in X360 controller mode
- Force to reconnect X360 controller on Resume
18 changes: 18 additions & 0 deletions SteamController/Devices/Xbox360Controller.cs
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
using Microsoft.Win32;
using Nefarius.ViGEm.Client;
using Nefarius.ViGEm.Client.Exceptions;
using Nefarius.ViGEm.Client.Targets;
Expand All @@ -21,13 +22,30 @@ public class Xbox360Controller : IDisposable

public Xbox360Controller()
{
Microsoft.Win32.SystemEvents.PowerModeChanged += SystemEvents_PowerModeChanged;
}

~Xbox360Controller()
{
Dispose();
}

public void Dispose()
{
GC.SuppressFinalize(this);
Microsoft.Win32.SystemEvents.PowerModeChanged -= SystemEvents_PowerModeChanged;
using (client) { }
}

private void SystemEvents_PowerModeChanged(object sender, PowerModeChangedEventArgs e)
{
if (e.Mode == Microsoft.Win32.PowerModes.Resume)
{
// Force to reconnect device on resume
lock (this) { Fail(); }
}
}

internal bool Tick()
{
if (this.device is not null)
Expand Down

0 comments on commit 40e2f62

Please sign in to comment.