diff --git a/src/Ryujinx/Input/AvaloniaKeyboardDriver.cs b/src/Ryujinx/Input/AvaloniaKeyboardDriver.cs index 61d233992..56c633181 100644 --- a/src/Ryujinx/Input/AvaloniaKeyboardDriver.cs +++ b/src/Ryujinx/Input/AvaloniaKeyboardDriver.cs @@ -24,6 +24,7 @@ namespace Ryujinx.Ava.Input private static readonly string[] _keyboardIdentifers = ["0"]; private readonly Control _control; + private readonly Window _window; private readonly HashSet _semanticPressedKeys; private readonly HashSet _physicalPressedKeys; private readonly Dictionary _observedPhysicalKeysBySemanticKey; @@ -42,6 +43,7 @@ namespace Ryujinx.Ava.Input public AvaloniaKeyboardDriver(Control control, KeyboardInputMode defaultMode = KeyboardInputMode.Semantic) { _control = control; + _window = control as Window ?? TopLevel.GetTopLevel(control) as Window; _semanticPressedKeys = []; _physicalPressedKeys = []; _observedPhysicalKeysBySemanticKey = []; @@ -56,6 +58,12 @@ namespace Ryujinx.Ava.Input _control.AddHandler(InputElement.KeyDownEvent, OnKeyPress, RoutingStrategies.Tunnel, true); _control.AddHandler(InputElement.KeyUpEvent, OnKeyRelease, RoutingStrategies.Tunnel, true); _control.TextInput += Control_TextInput; + _window?.Deactivated += Window_Deactivated; + } + + private void Window_Deactivated(object sender, EventArgs e) + { + Clear(); } private void Control_TextInput(object sender, TextInputEventArgs e) @@ -99,6 +107,10 @@ namespace Ryujinx.Ava.Input _control.RemoveHandler(InputElement.KeyDownEvent, OnKeyPress); _control.RemoveHandler(InputElement.KeyUpEvent, OnKeyRelease); _control.TextInput -= Control_TextInput; + if (_window != null) + { + _window.Deactivated -= Window_Deactivated; + } } } diff --git a/src/Ryujinx/Systems/AppHost.cs b/src/Ryujinx/Systems/AppHost.cs index 4b1e9cdb5..329a3ce55 100644 --- a/src/Ryujinx/Systems/AppHost.cs +++ b/src/Ryujinx/Systems/AppHost.cs @@ -1234,9 +1234,17 @@ namespace Ryujinx.Ava.Systems return false; } + bool hasModalFocusLoss = _viewModel.Window is MainWindow mainWindow && + mainWindow.SettingsWindow?.IsActive == true; + + if (!_viewModel.IsActive || hasModalFocusLoss) + { + _inputManager.KeyboardDriver.Clear(); + } + NpadManager.Update(ConfigurationState.Instance.Graphics.AspectRatio.Value.ToFloat()); - if (_viewModel.IsActive) + if (_viewModel.IsActive && !hasModalFocusLoss) { bool isCursorVisible = true; @@ -1369,7 +1377,7 @@ namespace Ryujinx.Ava.Systems // Touchscreen. bool hasTouch = false; - if (_viewModel.IsActive && !ConfigurationState.Instance.Hid.EnableMouse.Value) + if (_viewModel.IsActive && !hasModalFocusLoss && !ConfigurationState.Instance.Hid.EnableMouse.Value) { hasTouch = TouchScreenManager.Update(true, (_inputManager.MouseDriver as AvaloniaMouseDriver).IsButtonPressed(MouseButton.Button1), ConfigurationState.Instance.Graphics.AspectRatio.Value.ToFloat()); }