diff --git a/src/Ryujinx.Input.SDL2/SDL2GamepadDriver.cs b/src/Ryujinx.Input.SDL2/SDL2GamepadDriver.cs index c580e4e7d..251f53cba 100644 --- a/src/Ryujinx.Input.SDL2/SDL2GamepadDriver.cs +++ b/src/Ryujinx.Input.SDL2/SDL2GamepadDriver.cs @@ -173,5 +173,16 @@ namespace Ryujinx.Input.SDL2 return new SDL2Gamepad(gamepadHandle, id); } + + public IEnumerable GetGamepads() + { + lock (_gamepadsIds) + { + foreach (string gamepadId in _gamepadsIds) + { + yield return GetGamepad(gamepadId); + } + } + } } } diff --git a/src/Ryujinx.Input.SDL2/SDL2MouseDriver.cs b/src/Ryujinx.Input.SDL2/SDL2MouseDriver.cs index 768ea8c62..7a9679901 100644 --- a/src/Ryujinx.Input.SDL2/SDL2MouseDriver.cs +++ b/src/Ryujinx.Input.SDL2/SDL2MouseDriver.cs @@ -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 GetGamepads() => [GetGamepad("0")]; + public void Dispose() { if (_isDisposed) diff --git a/src/Ryujinx.Input.SDL2/SDLKeyboardDriver.cs b/src/Ryujinx.Input.SDL2/SDLKeyboardDriver.cs index 965f7935a..69e12bda0 100644 --- a/src/Ryujinx.Input.SDL2/SDLKeyboardDriver.cs +++ b/src/Ryujinx.Input.SDL2/SDLKeyboardDriver.cs @@ -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 GetGamepads() + { + foreach (var keyboardId in _keyboardIdentifers) + { + yield return GetGamepad(keyboardId); + } + } } } diff --git a/src/Ryujinx.Input/IGamepadDriver.cs b/src/Ryujinx.Input/IGamepadDriver.cs index 625c3e694..e61013ae1 100644 --- a/src/Ryujinx.Input/IGamepadDriver.cs +++ b/src/Ryujinx.Input/IGamepadDriver.cs @@ -1,4 +1,5 @@ using System; +using System.Collections.Generic; namespace Ryujinx.Input { @@ -33,6 +34,11 @@ namespace Ryujinx.Input /// The unique id of the gamepad /// An instance of associated to the gamepad id given or null if not found IGamepad GetGamepad(string id); + + /// + /// Returns an of the connected gamepads. + /// + IEnumerable GetGamepads(); /// /// Clear the internal state of the driver. diff --git a/src/Ryujinx/AppHost.cs b/src/Ryujinx/AppHost.cs index 4df3eab0d..31f27a965 100644 --- a/src/Ryujinx/AppHost.cs +++ b/src/Ryujinx/AppHost.cs @@ -587,6 +587,11 @@ namespace Ryujinx.Ava return; } + foreach (IGamepad gamepad in RyujinxApp.MainWindow.InputManager.GamepadDriver.GetGamepads()) + { + gamepad?.ClearLed(); + } + _isStopped = true; Stop(); } diff --git a/src/Ryujinx/Input/AvaloniaKeyboardDriver.cs b/src/Ryujinx/Input/AvaloniaKeyboardDriver.cs index 9f87e821a..214652265 100644 --- a/src/Ryujinx/Input/AvaloniaKeyboardDriver.cs +++ b/src/Ryujinx/Input/AvaloniaKeyboardDriver.cs @@ -59,6 +59,8 @@ namespace Ryujinx.Ava.Input return new AvaloniaKeyboard(this, _keyboardIdentifers[0], LocaleManager.Instance[LocaleKeys.AllKeyboards]); } + public IEnumerable GetGamepads() => [GetGamepad("0")]; + protected virtual void Dispose(bool disposing) { if (disposing) diff --git a/src/Ryujinx/Input/AvaloniaMouseDriver.cs b/src/Ryujinx/Input/AvaloniaMouseDriver.cs index e71bbf64a..be1441101 100644 --- a/src/Ryujinx/Input/AvaloniaMouseDriver.cs +++ b/src/Ryujinx/Input/AvaloniaMouseDriver.cs @@ -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 GetGamepads() => [GetGamepad("0")]; + public void Dispose() { if (_isDisposed) diff --git a/src/Ryujinx/UI/Views/Input/ControllerInputView.axaml.cs b/src/Ryujinx/UI/Views/Input/ControllerInputView.axaml.cs index a7c2c2d3c..81483ce0e 100644 --- a/src/Ryujinx/UI/Views/Input/ControllerInputView.axaml.cs +++ b/src/Ryujinx/UI/Views/Input/ControllerInputView.axaml.cs @@ -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(); diff --git a/src/Ryujinx/UI/Windows/SettingsWindow.axaml.cs b/src/Ryujinx/UI/Windows/SettingsWindow.axaml.cs index ab8f468fd..67deb9723 100644 --- a/src/Ryujinx/UI/Windows/SettingsWindow.axaml.cs +++ b/src/Ryujinx/UI/Windows/SettingsWindow.axaml.cs @@ -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();