diff --git a/src/Ryujinx/UI/Views/Input/ControllerInputView.axaml.cs b/src/Ryujinx/UI/Views/Input/ControllerInputView.axaml.cs index 7bf755116..6b3c691c3 100644 --- a/src/Ryujinx/UI/Views/Input/ControllerInputView.axaml.cs +++ b/src/Ryujinx/UI/Views/Input/ControllerInputView.axaml.cs @@ -104,7 +104,7 @@ namespace Ryujinx.Ava.UI.Views.Input PointerPressed += MouseClick; - ControllerInputViewModel viewModel = (DataContext as ControllerInputViewModel); + ControllerInputViewModel viewModel = ViewModel; IKeyboard keyboard = (IKeyboard)viewModel.ParentModel.AvaloniaKeyboardDriver @@ -113,7 +113,7 @@ namespace Ryujinx.Ava.UI.Views.Input _currentAssigner.ButtonAssigned += (sender, e) => { - if (e.ButtonValue.HasValue) + if (e.ButtonValue.HasValue && IsActiveAssignmentContext(viewModel)) { Button buttonValue = e.ButtonValue.Value; @@ -213,7 +213,15 @@ namespace Ryujinx.Ava.UI.Views.Input private void FlagInputConfigChanged() { - (DataContext as ControllerInputViewModel)!.ParentModel.RefreshModifiedState(); + if (DataContext is ControllerInputViewModel viewModel && VisualRoot is not null) + { + viewModel.ParentModel.RefreshModifiedState(); + } + } + + private bool IsActiveAssignmentContext(ControllerInputViewModel viewModel) + { + return VisualRoot is not null && ReferenceEquals(DataContext, viewModel); } private void MouseClick(object sender, PointerPressedEventArgs e) diff --git a/src/Ryujinx/UI/Views/Input/KeyboardInputView.axaml.cs b/src/Ryujinx/UI/Views/Input/KeyboardInputView.axaml.cs index 1ff38424b..ef800ed50 100644 --- a/src/Ryujinx/UI/Views/Input/KeyboardInputView.axaml.cs +++ b/src/Ryujinx/UI/Views/Input/KeyboardInputView.axaml.cs @@ -63,106 +63,108 @@ namespace Ryujinx.Ava.UI.Views.Input PointerPressed += MouseClick; + KeyboardInputViewModel viewModel = ViewModel; + IKeyboard keyboard = - (IKeyboard)ViewModel.ParentModel.AvaloniaKeyboardDriver.GetGamepad("0"); // Open Avalonia keyboard for cancel operations. + (IKeyboard)viewModel.ParentModel.AvaloniaKeyboardDriver.GetGamepad("0"); // Open Avalonia keyboard for cancel operations. IButtonAssigner assigner = - new KeyboardKeyAssigner((IKeyboard)ViewModel.ParentModel.SelectedGamepad); + new KeyboardKeyAssigner((IKeyboard)viewModel.ParentModel.SelectedGamepad); _currentAssigner.ButtonAssigned += (_, be) => { - if (be.ButtonValue.HasValue) + if (be.ButtonValue.HasValue && IsActiveAssignmentContext(viewModel)) { Button buttonValue = be.ButtonValue.Value; switch (button.Name) { case "ButtonZl": - ViewModel.Config.ButtonZl = buttonValue.AsHidType(); + viewModel.Config.ButtonZl = buttonValue.AsHidType(); break; case "ButtonL": - ViewModel.Config.ButtonL = buttonValue.AsHidType(); + viewModel.Config.ButtonL = buttonValue.AsHidType(); break; case "ButtonMinus": - ViewModel.Config.ButtonMinus = buttonValue.AsHidType(); + viewModel.Config.ButtonMinus = buttonValue.AsHidType(); break; case "LeftStickButton": - ViewModel.Config.LeftStickButton = buttonValue.AsHidType(); + viewModel.Config.LeftStickButton = buttonValue.AsHidType(); break; case "LeftStickUp": - ViewModel.Config.LeftStickUp = buttonValue.AsHidType(); + viewModel.Config.LeftStickUp = buttonValue.AsHidType(); break; case "LeftStickDown": - ViewModel.Config.LeftStickDown = buttonValue.AsHidType(); + viewModel.Config.LeftStickDown = buttonValue.AsHidType(); break; case "LeftStickRight": - ViewModel.Config.LeftStickRight = buttonValue.AsHidType(); + viewModel.Config.LeftStickRight = buttonValue.AsHidType(); break; case "LeftStickLeft": - ViewModel.Config.LeftStickLeft = buttonValue.AsHidType(); + viewModel.Config.LeftStickLeft = buttonValue.AsHidType(); break; case "DpadUp": - ViewModel.Config.DpadUp = buttonValue.AsHidType(); + viewModel.Config.DpadUp = buttonValue.AsHidType(); break; case "DpadDown": - ViewModel.Config.DpadDown = buttonValue.AsHidType(); + viewModel.Config.DpadDown = buttonValue.AsHidType(); break; case "DpadLeft": - ViewModel.Config.DpadLeft = buttonValue.AsHidType(); + viewModel.Config.DpadLeft = buttonValue.AsHidType(); break; case "DpadRight": - ViewModel.Config.DpadRight = buttonValue.AsHidType(); + viewModel.Config.DpadRight = buttonValue.AsHidType(); break; case "LeftButtonSr": - ViewModel.Config.LeftButtonSr = buttonValue.AsHidType(); + viewModel.Config.LeftButtonSr = buttonValue.AsHidType(); break; case "LeftButtonSl": - ViewModel.Config.LeftButtonSl = buttonValue.AsHidType(); + viewModel.Config.LeftButtonSl = buttonValue.AsHidType(); break; case "RightButtonSr": - ViewModel.Config.RightButtonSr = buttonValue.AsHidType(); + viewModel.Config.RightButtonSr = buttonValue.AsHidType(); break; case "RightButtonSl": - ViewModel.Config.RightButtonSl = buttonValue.AsHidType(); + viewModel.Config.RightButtonSl = buttonValue.AsHidType(); break; case "ButtonZr": - ViewModel.Config.ButtonZr = buttonValue.AsHidType(); + viewModel.Config.ButtonZr = buttonValue.AsHidType(); break; case "ButtonR": - ViewModel.Config.ButtonR = buttonValue.AsHidType(); + viewModel.Config.ButtonR = buttonValue.AsHidType(); break; case "ButtonPlus": - ViewModel.Config.ButtonPlus = buttonValue.AsHidType(); + viewModel.Config.ButtonPlus = buttonValue.AsHidType(); break; case "ButtonA": - ViewModel.Config.ButtonA = buttonValue.AsHidType(); + viewModel.Config.ButtonA = buttonValue.AsHidType(); break; case "ButtonB": - ViewModel.Config.ButtonB = buttonValue.AsHidType(); + viewModel.Config.ButtonB = buttonValue.AsHidType(); break; case "ButtonX": - ViewModel.Config.ButtonX = buttonValue.AsHidType(); + viewModel.Config.ButtonX = buttonValue.AsHidType(); break; case "ButtonY": - ViewModel.Config.ButtonY = buttonValue.AsHidType(); + viewModel.Config.ButtonY = buttonValue.AsHidType(); break; case "RightStickButton": - ViewModel.Config.RightStickButton = buttonValue.AsHidType(); + viewModel.Config.RightStickButton = buttonValue.AsHidType(); break; case "RightStickUp": - ViewModel.Config.RightStickUp = buttonValue.AsHidType(); + viewModel.Config.RightStickUp = buttonValue.AsHidType(); break; case "RightStickDown": - ViewModel.Config.RightStickDown = buttonValue.AsHidType(); + viewModel.Config.RightStickDown = buttonValue.AsHidType(); break; case "RightStickRight": - ViewModel.Config.RightStickRight = buttonValue.AsHidType(); + viewModel.Config.RightStickRight = buttonValue.AsHidType(); break; case "RightStickLeft": - ViewModel.Config.RightStickLeft = buttonValue.AsHidType(); + viewModel.Config.RightStickLeft = buttonValue.AsHidType(); break; } - ViewModel.ParentModel.RefreshModifiedState(); + viewModel.ParentModel.RefreshModifiedState(); } }; @@ -252,5 +254,10 @@ namespace Ryujinx.Ava.UI.Views.Input _currentAssigner?.Cancel(); _currentAssigner = null; } + + private bool IsActiveAssignmentContext(KeyboardInputViewModel viewModel) + { + return VisualRoot is not null && ReferenceEquals(DataContext, viewModel); + } } }