Clear the LED on all controllers when settings window is closed and when input view is removed from the visual tree.

This commit is contained in:
Evan Husted 2025-01-23 21:39:19 -06:00
parent 5f02765130
commit a6dfbe9ec2
2 changed files with 29 additions and 0 deletions

View File

@ -6,10 +6,12 @@ using Avalonia.Interactivity;
using Avalonia.LogicalTree;
using FluentAvalonia.UI.Controls;
using Ryujinx.Ava.UI.Helpers;
using Ryujinx.Ava.UI.Models;
using Ryujinx.Ava.UI.ViewModels.Input;
using Ryujinx.Common.Configuration.Hid.Controller;
using Ryujinx.Input;
using Ryujinx.Input.Assigner;
using System.Linq;
using StickInputId = Ryujinx.Common.Configuration.Hid.Controller.StickInputId;
namespace Ryujinx.Ava.UI.Views.Input
@ -234,6 +236,17 @@ namespace Ryujinx.Ava.UI.Views.Input
protected override void OnDetachedFromVisualTree(VisualTreeAttachmentEventArgs e)
{
base.OnDetachedFromVisualTree(e);
if (DataContext is ControllerInputViewModel vm)
{
foreach ((_, string id, _) in vm.ParentModel.Devices.Where(x => x.Type == DeviceType.Controller))
{
IGamepad gamepad = RyujinxApp.MainWindow.InputManager.GamepadDriver.GetGamepad(id);
gamepad?.ClearLed();
}
}
_currentAssigner?.Cancel();
_currentAssigner = null;
}

View File

@ -4,9 +4,14 @@ using Avalonia.Input;
using FluentAvalonia.Core;
using FluentAvalonia.UI.Controls;
using Ryujinx.Ava.Common.Locale;
using Ryujinx.Ava.UI.Models;
using Ryujinx.Ava.UI.ViewModels;
using Ryujinx.Ava.UI.ViewModels.Input;
using Ryujinx.HLE.FileSystem;
using Ryujinx.Input;
using System;
using System.Linq;
using Key = Avalonia.Input.Key;
namespace Ryujinx.Ava.UI.Windows
{
@ -106,6 +111,17 @@ namespace Ryujinx.Ava.UI.Windows
protected override void OnClosing(WindowClosingEventArgs e)
{
HotkeysPage.Dispose();
if (InputPage.InputView.DataContext is InputViewModel vm)
{
foreach ((_, string id, _) in vm.Devices.Where(x => x.Type == DeviceType.Controller))
{
IGamepad gamepad = RyujinxApp.MainWindow.InputManager.GamepadDriver.GetGamepad(id);
gamepad?.ClearLed();
}
}
InputPage.Dispose();
base.OnClosing(e);
}