Refresh input modified state only when keybinds actually change

This commit is contained in:
Babib3l
2026-03-30 22:04:23 +02:00
parent fa0696ca27
commit 23b9a47d08
4 changed files with 70 additions and 47 deletions

View File

@@ -88,19 +88,19 @@ namespace Ryujinx.Ava.UI.ViewModels.Input
public async void ShowMotionConfig() public async void ShowMotionConfig()
{ {
await MotionInputView.Show(this); await MotionInputView.Show(this);
ParentModel.IsModified = true; ParentModel.RefreshModifiedState();
} }
public async void ShowRumbleConfig() public async void ShowRumbleConfig()
{ {
await RumbleInputView.Show(this); await RumbleInputView.Show(this);
ParentModel.IsModified = true; ParentModel.RefreshModifiedState();
} }
public async void ShowLedConfig() public async void ShowLedConfig()
{ {
await LedInputView.Show(this); await LedInputView.Show(this);
ParentModel.IsModified = true; ParentModel.RefreshModifiedState();
} }
public void OnParentModelChanged() public void OnParentModelChanged()

View File

@@ -181,8 +181,8 @@ namespace Ryujinx.Ava.UI.ViewModels.Input
return; return;
} }
MarkAsChanged();
ApplyControllerSelection(controllerIndex); ApplyControllerSelection(controllerIndex);
RefreshModifiedState();
} }
} }
@@ -265,7 +265,6 @@ namespace Ryujinx.Ava.UI.ViewModels.Input
return; return;
} }
MarkAsChanged();
_device = value; _device = value;
DeviceType selected = Devices[_device].Type; DeviceType selected = Devices[_device].Type;
@@ -282,6 +281,7 @@ namespace Ryujinx.Ava.UI.ViewModels.Input
} }
} }
RefreshModifiedState();
FindPairedDeviceInConfigFile(); FindPairedDeviceInConfigFile();
OnPropertyChanged(); OnPropertyChanged();
OnPropertyChanged(nameof(SelectedDeviceItem)); OnPropertyChanged(nameof(SelectedDeviceItem));
@@ -298,8 +298,8 @@ namespace Ryujinx.Ava.UI.ViewModels.Input
return; return;
} }
MarkAsChanged();
LoadSelectedDeviceDefaults(); LoadSelectedDeviceDefaults();
RefreshModifiedState();
FindPairedDeviceInConfigFile(); FindPairedDeviceInConfigFile();
NotifyChanges(); NotifyChanges();
} }
@@ -393,20 +393,19 @@ namespace Ryujinx.Ava.UI.ViewModels.Input
private void LoadConfiguration(InputConfig inputConfig = null) private InputConfig GetPersistedInputConfig()
{ {
InputConfig persistedConfig;
if (UseGlobalConfig && Program.UseExtraConfig) if (UseGlobalConfig && Program.UseExtraConfig)
{ {
persistedConfig = ConfigurationState.InstanceExtra.Hid.InputConfig.Value.FirstOrDefault(inputConfig => inputConfig.PlayerIndex == _playerId); return ConfigurationState.InstanceExtra.Hid.InputConfig.Value.FirstOrDefault(inputConfig => inputConfig.PlayerIndex == _playerId);
}
else
{
persistedConfig = ConfigurationState.Instance.Hid.InputConfig.Value.FirstOrDefault(inputConfig => inputConfig.PlayerIndex == _playerId);
} }
Config = inputConfig ?? GetDisplayedInputConfig(persistedConfig); return ConfigurationState.Instance.Hid.InputConfig.Value.FirstOrDefault(inputConfig => inputConfig.PlayerIndex == _playerId);
}
private void LoadConfiguration(InputConfig inputConfig = null)
{
Config = inputConfig ?? GetDisplayedInputConfig(GetPersistedInputConfig());
if (Config is StandardKeyboardInputConfig keyboardInputConfig) if (Config is StandardKeyboardInputConfig keyboardInputConfig)
{ {
@@ -451,15 +450,6 @@ namespace Ryujinx.Ava.UI.ViewModels.Input
} }
} }
private void MarkAsChanged()
{
//If tracking is active, then allow changing the modifier
if (!IsModified && _isChangeTrackingActive)
{
IsModified = true;
}
}
public void UnlinkDevice() public void UnlinkDevice()
{ {
// "Disabled" mode is available after unbinding the device // "Disabled" mode is available after unbinding the device
@@ -534,6 +524,55 @@ namespace Ryujinx.Ava.UI.ViewModels.Input
LoadConfiguration(LoadDefaultConfiguration()); LoadConfiguration(LoadDefaultConfiguration());
} }
public void RefreshModifiedState()
{
if (!_isChangeTrackingActive)
{
return;
}
IsModified = !ConfigsMatch(GetSelectedDeviceConfig(), GetDisplayedInputConfig(GetPersistedInputConfig()));
}
private static bool ConfigsMatch(InputConfig currentConfig, InputConfig otherConfig)
{
if (currentConfig == null || otherConfig == null)
{
return currentConfig == otherConfig;
}
return JsonHelper.Serialize(currentConfig, _serializerContext.InputConfig) ==
JsonHelper.Serialize(otherConfig, _serializerContext.InputConfig);
}
private InputConfig GetSelectedDeviceConfig()
{
if (_device <= 0 || _device >= Devices.Count)
{
return null;
}
(DeviceType Type, string Id, string Name) device = Devices[_device];
InputConfig config = device.Type switch
{
DeviceType.Keyboard => (ConfigViewModel as KeyboardInputViewModel)?.Config.GetConfig(),
DeviceType.Controller => (ConfigViewModel as ControllerInputViewModel)?.Config.GetConfig(),
_ => null,
};
if (config == null)
{
return null;
}
config.Id = device.Type == DeviceType.Keyboard ? device.Id : device.Id.Split(" ")[0];
config.Name = device.Name;
config.PlayerIndex = _playerId;
config.ControllerType = Controllers[_controller].Type;
return config;
}
private void LoadInputDriver() private void LoadInputDriver()
{ {
if (_device < 0) if (_device < 0)
@@ -1160,25 +1199,7 @@ namespace Ryujinx.Ava.UI.ViewModels.Input
} }
else else
{ {
(DeviceType Type, string Id, string Name) device = Devices[Device]; InputConfig config = GetSelectedDeviceConfig();
if (device.Type == DeviceType.Keyboard)
{
KeyboardInputConfig inputConfig = (ConfigViewModel as KeyboardInputViewModel).Config;
inputConfig.Id = device.Id;
}
else
{
GamepadInputConfig inputConfig = (ConfigViewModel as ControllerInputViewModel).Config;
inputConfig.Id = device.Id.Split(" ")[0];
}
InputConfig config = !IsController
? (ConfigViewModel as KeyboardInputViewModel).Config.GetConfig()
: (ConfigViewModel as ControllerInputViewModel).Config.GetConfig();
config.ControllerType = Controllers[_controller].Type;
config.PlayerIndex = _playerId;
config.Name = device.Name;
int i = newConfig.FindIndex(x => x.PlayerIndex == PlayerId); int i = newConfig.FindIndex(x => x.PlayerIndex == PlayerId);
if (i == -1) if (i == -1)

View File

@@ -116,7 +116,6 @@ namespace Ryujinx.Ava.UI.Views.Input
if (e.ButtonValue.HasValue) if (e.ButtonValue.HasValue)
{ {
Button buttonValue = e.ButtonValue.Value; Button buttonValue = e.ButtonValue.Value;
FlagInputConfigChanged();
switch (button.Name) switch (button.Name)
{ {
@@ -187,6 +186,8 @@ namespace Ryujinx.Ava.UI.Views.Input
viewModel.Config.RightJoystick = buttonValue.AsHidType<StickInputId>(); viewModel.Config.RightJoystick = buttonValue.AsHidType<StickInputId>();
break; break;
} }
FlagInputConfigChanged();
} }
}; };
@@ -212,7 +213,7 @@ namespace Ryujinx.Ava.UI.Views.Input
private void FlagInputConfigChanged() private void FlagInputConfigChanged()
{ {
(DataContext as ControllerInputViewModel)!.ParentModel.IsModified = true; (DataContext as ControllerInputViewModel)!.ParentModel.RefreshModifiedState();
} }
private void MouseClick(object sender, PointerPressedEventArgs e) private void MouseClick(object sender, PointerPressedEventArgs e)

View File

@@ -73,7 +73,6 @@ namespace Ryujinx.Ava.UI.Views.Input
if (be.ButtonValue.HasValue) if (be.ButtonValue.HasValue)
{ {
Button buttonValue = be.ButtonValue.Value; Button buttonValue = be.ButtonValue.Value;
ViewModel.ParentModel.IsModified = true;
switch (button.Name) switch (button.Name)
{ {
@@ -162,6 +161,8 @@ namespace Ryujinx.Ava.UI.Views.Input
ViewModel.Config.RightStickLeft = buttonValue.AsHidType<PhysicalKey>(); ViewModel.Config.RightStickLeft = buttonValue.AsHidType<PhysicalKey>();
break; break;
} }
ViewModel.ParentModel.RefreshModifiedState();
} }
}; };
@@ -240,7 +241,7 @@ namespace Ryujinx.Ava.UI.Views.Input
if (buttonActions.TryGetValue(_currentAssigner.ToggledButton.Name, out Action action)) if (buttonActions.TryGetValue(_currentAssigner.ToggledButton.Name, out Action action))
{ {
action(); action();
ViewModel.ParentModel.IsModified = true; ViewModel.ParentModel.RefreshModifiedState();
} }
} }
} }