From 8f51938e2b22ee438ce8f849cc9258026ec5da29 Mon Sep 17 00:00:00 2001
From: TSRBerry <20988865+TSRBerry@users.noreply.github.com>
Date: Fri, 17 May 2024 21:58:03 +0200
Subject: [PATCH] Disable keyboard controller input while swkbd is open
(foreground) (second attempt) (#6808)
* Block input updates while swkbd is open in foreground mode
* Flush internal driver state before unblocking input updates
* Rename Flush to Clear and remove unnecessary attribute
* Clear the driver state only if the GamepadDriver isn't null
---
src/Ryujinx.Gtk3/Input/GTK3/GTK3KeyboardDriver.cs | 5 +++++
src/Ryujinx.Gtk3/UI/Applet/GtkHostUIHandler.cs | 3 +++
src/Ryujinx.Input/HLE/NpadManager.cs | 5 +++++
src/Ryujinx.Input/IGamepadDriver.cs | 6 ++++++
src/Ryujinx/Input/AvaloniaKeyboard.cs | 2 +-
src/Ryujinx/Input/AvaloniaKeyboardDriver.cs | 2 +-
src/Ryujinx/UI/Applet/AvaHostUIHandler.cs | 2 ++
7 files changed, 23 insertions(+), 2 deletions(-)
diff --git a/src/Ryujinx.Gtk3/Input/GTK3/GTK3KeyboardDriver.cs b/src/Ryujinx.Gtk3/Input/GTK3/GTK3KeyboardDriver.cs
index e502254be1..bd71c7933f 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 Clear()
+ {
+ _pressedKeys.Clear();
+ }
+
public IGamepad GetGamepad(string id)
{
if (!_keyboardIdentifers[0].Equals(id))
diff --git a/src/Ryujinx.Gtk3/UI/Applet/GtkHostUIHandler.cs b/src/Ryujinx.Gtk3/UI/Applet/GtkHostUIHandler.cs
index 1d918d21b6..b3f509a090 100644
--- a/src/Ryujinx.Gtk3/UI/Applet/GtkHostUIHandler.cs
+++ b/src/Ryujinx.Gtk3/UI/Applet/GtkHostUIHandler.cs
@@ -107,6 +107,8 @@ namespace Ryujinx.UI.Applet
swkbdDialog.SetInputLengthValidation(args.StringLengthMin, args.StringLengthMax);
swkbdDialog.SetInputValidation(args.KeyboardMode);
+ ((MainWindow)_parent).RendererWidget.NpadManager.BlockInputUpdates();
+
if (swkbdDialog.Run() == (int)ResponseType.Ok)
{
inputText = swkbdDialog.InputEntry.Text;
@@ -128,6 +130,7 @@ namespace Ryujinx.UI.Applet
});
dialogCloseEvent.WaitOne();
+ ((MainWindow)_parent).RendererWidget.NpadManager.UnblockInputUpdates();
userText = error ? null : inputText;
diff --git a/src/Ryujinx.Input/HLE/NpadManager.cs b/src/Ryujinx.Input/HLE/NpadManager.cs
index 4c7bb8b7a4..1bc54d6946 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?.Clear();
+ }
+
_blockInputUpdates = false;
}
}
diff --git a/src/Ryujinx.Input/IGamepadDriver.cs b/src/Ryujinx.Input/IGamepadDriver.cs
index 67b01c26ca..625c3e6941 100644
--- a/src/Ryujinx.Input/IGamepadDriver.cs
+++ b/src/Ryujinx.Input/IGamepadDriver.cs
@@ -33,5 +33,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);
+
+ ///
+ /// Clear the internal state of the driver.
+ ///
+ /// Does nothing by default.
+ void Clear() { }
}
}
diff --git a/src/Ryujinx/Input/AvaloniaKeyboard.cs b/src/Ryujinx/Input/AvaloniaKeyboard.cs
index fbaaaabab8..ff88de79e4 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?.Clear();
}
public void Dispose() { }
diff --git a/src/Ryujinx/Input/AvaloniaKeyboardDriver.cs b/src/Ryujinx/Input/AvaloniaKeyboardDriver.cs
index e9e71b99bd..9f87e821ad 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 Clear()
{
_pressedKeys.Clear();
}
diff --git a/src/Ryujinx/UI/Applet/AvaHostUIHandler.cs b/src/Ryujinx/UI/Applet/AvaHostUIHandler.cs
index 4bcc35a7a5..4bcf8eb949 100644
--- a/src/Ryujinx/UI/Applet/AvaHostUIHandler.cs
+++ b/src/Ryujinx/UI/Applet/AvaHostUIHandler.cs
@@ -122,6 +122,7 @@ namespace Ryujinx.Ava.UI.Applet
{
try
{
+ _parent.ViewModel.AppHost.NpadManager.BlockInputUpdates();
var response = await SwkbdAppletDialog.ShowInputDialog(LocaleManager.Instance[LocaleKeys.SoftwareKeyboard], args);
if (response.Result == UserResult.Ok)
@@ -143,6 +144,7 @@ namespace Ryujinx.Ava.UI.Applet
});
dialogCloseEvent.WaitOne();
+ _parent.ViewModel.AppHost.NpadManager.UnblockInputUpdates();
userText = error ? null : inputText;