Clear LED on game close as well

This commit is contained in:
Evan Husted 2025-01-23 21:59:54 -06:00
parent a6dfbe9ec2
commit 344c1a5fef
9 changed files with 43 additions and 14 deletions

View File

@ -173,5 +173,16 @@ namespace Ryujinx.Input.SDL2
return new SDL2Gamepad(gamepadHandle, id);
}
public IEnumerable<IGamepad> GetGamepads()
{
lock (_gamepadsIds)
{
foreach (string gamepadId in _gamepadsIds)
{
yield return GetGamepad(gamepadId);
}
}
}
}
}

View File

@ -1,6 +1,7 @@
using Ryujinx.Common.Configuration;
using Ryujinx.Common.Logging;
using System;
using System.Collections.Generic;
using System.Diagnostics;
using System.Drawing;
using System.Numerics;
@ -164,6 +165,8 @@ namespace Ryujinx.Input.SDL2
return new SDL2Mouse(this);
}
public IEnumerable<IGamepad> GetGamepads() => [GetGamepad("0")];
public void Dispose()
{
if (_isDisposed)

View File

@ -1,5 +1,6 @@
using Ryujinx.SDL2.Common;
using System;
using System.Collections.Generic;
namespace Ryujinx.Input.SDL2
{
@ -51,5 +52,13 @@ namespace Ryujinx.Input.SDL2
return new SDL2Keyboard(this, _keyboardIdentifers[0], "All keyboards");
}
public IEnumerable<IGamepad> GetGamepads()
{
foreach (var keyboardId in _keyboardIdentifers)
{
yield return GetGamepad(keyboardId);
}
}
}
}

View File

@ -1,4 +1,5 @@
using System;
using System.Collections.Generic;
namespace Ryujinx.Input
{
@ -33,6 +34,11 @@ namespace Ryujinx.Input
/// <param name="id">The unique id of the gamepad</param>
/// <returns>An instance of <see cref="IGamepad"/> associated to the gamepad id given or null if not found</returns>
IGamepad GetGamepad(string id);
/// <summary>
/// Returns an <see cref="IEnumerable{T}"/> of the connected gamepads.
/// </summary>
IEnumerable<IGamepad> GetGamepads();
/// <summary>
/// Clear the internal state of the driver.

View File

@ -587,6 +587,11 @@ namespace Ryujinx.Ava
return;
}
foreach (IGamepad gamepad in RyujinxApp.MainWindow.InputManager.GamepadDriver.GetGamepads())
{
gamepad?.ClearLed();
}
_isStopped = true;
Stop();
}

View File

@ -59,6 +59,8 @@ namespace Ryujinx.Ava.Input
return new AvaloniaKeyboard(this, _keyboardIdentifers[0], LocaleManager.Instance[LocaleKeys.AllKeyboards]);
}
public IEnumerable<IGamepad> GetGamepads() => [GetGamepad("0")];
protected virtual void Dispose(bool disposing)
{
if (disposing)

View File

@ -3,6 +3,7 @@ using Avalonia.Controls;
using Avalonia.Input;
using Ryujinx.Input;
using System;
using System.Collections.Generic;
using System.Numerics;
using MouseButton = Ryujinx.Input.MouseButton;
using Size = System.Drawing.Size;
@ -134,6 +135,8 @@ namespace Ryujinx.Ava.Input
return new AvaloniaMouse(this);
}
public IEnumerable<IGamepad> GetGamepads() => [GetGamepad("0")];
public void Dispose()
{
if (_isDisposed)

View File

@ -237,14 +237,9 @@ namespace Ryujinx.Ava.UI.Views.Input
{
base.OnDetachedFromVisualTree(e);
if (DataContext is ControllerInputViewModel vm)
foreach (IGamepad gamepad in RyujinxApp.MainWindow.InputManager.GamepadDriver.GetGamepads())
{
foreach ((_, string id, _) in vm.ParentModel.Devices.Where(x => x.Type == DeviceType.Controller))
{
IGamepad gamepad = RyujinxApp.MainWindow.InputManager.GamepadDriver.GetGamepad(id);
gamepad?.ClearLed();
}
gamepad?.ClearLed();
}
_currentAssigner?.Cancel();

View File

@ -112,14 +112,9 @@ namespace Ryujinx.Ava.UI.Windows
{
HotkeysPage.Dispose();
if (InputPage.InputView.DataContext is InputViewModel vm)
foreach (IGamepad gamepad in RyujinxApp.MainWindow.InputManager.GamepadDriver.GetGamepads())
{
foreach ((_, string id, _) in vm.Devices.Where(x => x.Type == DeviceType.Controller))
{
IGamepad gamepad = RyujinxApp.MainWindow.InputManager.GamepadDriver.GetGamepad(id);
gamepad?.ClearLed();
}
gamepad?.ClearLed();
}
InputPage.Dispose();