Compare commits

...

3 Commits

Author SHA1 Message Date
Babib3l
23b9a47d08 Refresh input modified state only when keybinds actually change 2026-03-30 22:04:23 +02:00
Babib3l
fa0696ca27 Rename and privatize input device refresh helper 2026-03-30 21:40:32 +02:00
Babib3l
087655972d Restore input device default reset behavior 2026-03-30 21:36:53 +02:00
5 changed files with 108 additions and 54 deletions

View File

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

View File

@@ -181,8 +181,8 @@ namespace Ryujinx.Ava.UI.ViewModels.Input
return;
}
MarkAsChanged();
ApplyControllerSelection(controllerIndex);
RefreshModifiedState();
}
}
@@ -265,21 +265,23 @@ namespace Ryujinx.Ava.UI.ViewModels.Input
return;
}
MarkAsChanged();
_device = value;
DeviceType selected = Devices[_device].Type;
if (selected != DeviceType.None)
{
LoadControllers();
if (_isLoaded)
{
LoadConfiguration(LoadDefaultConfiguration());
LoadSelectedDeviceDefaults();
}
else
{
LoadSelectedDeviceControllers();
}
}
RefreshModifiedState();
FindPairedDeviceInConfigFile();
OnPropertyChanged();
OnPropertyChanged(nameof(SelectedDeviceItem));
@@ -287,6 +289,21 @@ namespace Ryujinx.Ava.UI.ViewModels.Input
}
}
public void ResetCurrentDeviceToDefaults()
{
RefreshAvailableDevices();
if (_device <= 0 || _device >= Devices.Count || Devices[_device].Type == DeviceType.None)
{
return;
}
LoadSelectedDeviceDefaults();
RefreshModifiedState();
FindPairedDeviceInConfigFile();
NotifyChanges();
}
public object SelectedDeviceItem
{
get => _device >= 0 && _device < Devices.Count ? Devices[_device] : null;
@@ -335,7 +352,7 @@ namespace Ryujinx.Ava.UI.ViewModels.Input
_isLoaded = false;
LoadDevices();
RefreshAvailableDevices();
PlayerId = PlayerIndex.Player1;
}
@@ -376,20 +393,19 @@ namespace Ryujinx.Ava.UI.ViewModels.Input
private void LoadConfiguration(InputConfig inputConfig = null)
private InputConfig GetPersistedInputConfig()
{
InputConfig persistedConfig;
if (UseGlobalConfig && Program.UseExtraConfig)
{
persistedConfig = ConfigurationState.InstanceExtra.Hid.InputConfig.Value.FirstOrDefault(inputConfig => inputConfig.PlayerIndex == _playerId);
}
else
{
persistedConfig = ConfigurationState.Instance.Hid.InputConfig.Value.FirstOrDefault(inputConfig => inputConfig.PlayerIndex == _playerId);
return ConfigurationState.InstanceExtra.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)
{
@@ -434,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()
{
// "Disabled" mode is available after unbinding the device
@@ -503,6 +510,69 @@ namespace Ryujinx.Ava.UI.ViewModels.Input
NotifyChanges();
}
private void LoadSelectedDeviceControllers()
{
if (_device > 0 && _device < Devices.Count && Devices[_device].Type != DeviceType.None)
{
LoadControllers();
}
}
private void LoadSelectedDeviceDefaults()
{
LoadSelectedDeviceControllers();
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()
{
if (_device < 0)
@@ -542,7 +612,7 @@ namespace Ryujinx.Ava.UI.ViewModels.Input
bool shouldApplyKeyboardFallback = Config is StandardControllerInputConfig controllerConfig && controllerConfig.Id == id;
LoadDevices();
RefreshAvailableDevices();
if (shouldApplyKeyboardFallback)
{
@@ -567,7 +637,7 @@ namespace Ryujinx.Ava.UI.ViewModels.Input
{
_isChangeTrackingActive = false; // Disable configuration change tracking
LoadDevices();
RefreshAvailableDevices();
IsModified = true;
RevertChanges();
@@ -669,7 +739,7 @@ namespace Ryujinx.Ava.UI.ViewModels.Input
return str[(str.IndexOf(Hyphen) + Offset)..];
}
public void LoadDevices()
private void RefreshAvailableDevices()
{
int selectedDeviceIndex = 0;
(DeviceType Type, string Id, string Name) selectedDevice = default;
@@ -1129,25 +1199,7 @@ namespace Ryujinx.Ava.UI.ViewModels.Input
}
else
{
(DeviceType Type, string Id, string Name) device = Devices[Device];
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;
InputConfig config = GetSelectedDeviceConfig();
int i = newConfig.FindIndex(x => x.PlayerIndex == PlayerId);
if (i == -1)

View File

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

View File

@@ -175,7 +175,7 @@
MinWidth="0"
Margin="5,0,0,0"
VerticalAlignment="Center"
Command="{Binding LoadDevices}">
Command="{Binding ResetCurrentDeviceToDefaults}">
<ui:SymbolIcon
Symbol="Refresh"
FontSize="15"

View File

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