From f01d31e893bdc0b0f9cb7aab5062e66e23c23db1 Mon Sep 17 00:00:00 2001 From: TSR Berry <20988865+TSRBerry@users.noreply.github.com> Date: Sat, 13 Apr 2024 00:15:30 +0200 Subject: [PATCH] Flush internal driver state before unblocking input updates --- src/Ryujinx.Gtk3/Input/GTK3/GTK3KeyboardDriver.cs | 5 +++++ src/Ryujinx.Input/HLE/NpadManager.cs | 5 +++++ src/Ryujinx.Input/IGamepadDriver.cs | 8 ++++++++ src/Ryujinx/Input/AvaloniaKeyboard.cs | 2 +- src/Ryujinx/Input/AvaloniaKeyboardDriver.cs | 2 +- 5 files changed, 20 insertions(+), 2 deletions(-) diff --git a/src/Ryujinx.Gtk3/Input/GTK3/GTK3KeyboardDriver.cs b/src/Ryujinx.Gtk3/Input/GTK3/GTK3KeyboardDriver.cs index e502254be1..1eaf430e11 100644 --- a/src/Ryujinx.Gtk3/Input/GTK3/GTK3KeyboardDriver.cs +++ b/src/Ryujinx.Gtk3/Input/GTK3/GTK3KeyboardDriver.cs @@ -81,6 +81,11 @@ namespace Ryujinx.Input.GTK3 return _pressedKeys.Contains(nativeKey); } + public void Flush() + { + _pressedKeys.Clear(); + } + public IGamepad GetGamepad(string id) { if (!_keyboardIdentifers[0].Equals(id)) diff --git a/src/Ryujinx.Input/HLE/NpadManager.cs b/src/Ryujinx.Input/HLE/NpadManager.cs index 4c7bb8b7a4..97f4a4c2ee 100644 --- a/src/Ryujinx.Input/HLE/NpadManager.cs +++ b/src/Ryujinx.Input/HLE/NpadManager.cs @@ -174,6 +174,11 @@ namespace Ryujinx.Input.HLE { lock (_lock) { + foreach (InputConfig inputConfig in _inputConfig) + { + _controllers[(int)inputConfig.PlayerIndex].GamepadDriver.Flush(); + } + _blockInputUpdates = false; } } diff --git a/src/Ryujinx.Input/IGamepadDriver.cs b/src/Ryujinx.Input/IGamepadDriver.cs index 67b01c26ca..83c6821d9c 100644 --- a/src/Ryujinx.Input/IGamepadDriver.cs +++ b/src/Ryujinx.Input/IGamepadDriver.cs @@ -1,4 +1,5 @@ using System; +using System.Runtime.CompilerServices; namespace Ryujinx.Input { @@ -33,5 +34,12 @@ 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); + + /// + /// Flush the internal state of the driver. + /// + /// Does nothing by default. + [MethodImpl(MethodImplOptions.AggressiveInlining)] + void Flush() { } } } diff --git a/src/Ryujinx/Input/AvaloniaKeyboard.cs b/src/Ryujinx/Input/AvaloniaKeyboard.cs index fbaaaabab8..42cc6a0ac4 100644 --- a/src/Ryujinx/Input/AvaloniaKeyboard.cs +++ b/src/Ryujinx/Input/AvaloniaKeyboard.cs @@ -195,7 +195,7 @@ namespace Ryujinx.Ava.Input public void Clear() { - _driver?.ResetKeys(); + _driver?.Flush(); } public void Dispose() { } diff --git a/src/Ryujinx/Input/AvaloniaKeyboardDriver.cs b/src/Ryujinx/Input/AvaloniaKeyboardDriver.cs index e9e71b99bd..34b0b5d015 100644 --- a/src/Ryujinx/Input/AvaloniaKeyboardDriver.cs +++ b/src/Ryujinx/Input/AvaloniaKeyboardDriver.cs @@ -94,7 +94,7 @@ namespace Ryujinx.Ava.Input return _pressedKeys.Contains(nativeKey); } - public void ResetKeys() + public void Flush() { _pressedKeys.Clear(); }