mirror of
https://git.ryujinx.app/ryubing/ryujinx.git
synced 2026-06-04 11:29:14 +00:00
Refresh keyboard labels when layout changes
This commit is contained in:
@@ -14,6 +14,7 @@ namespace Ryujinx.Ava.UI.Helpers
|
||||
internal static class PhysicalKeyLabelHelper
|
||||
{
|
||||
private static readonly ConcurrentDictionary<ConfigPhysicalKey, string> _observedLayoutLabels = new();
|
||||
public static event Action LabelsChanged;
|
||||
|
||||
private static readonly Dictionary<ConfigPhysicalKey, LocaleKeys> _localizedKeysMap = new()
|
||||
{
|
||||
@@ -101,7 +102,13 @@ namespace Ryujinx.Ava.UI.Helpers
|
||||
|
||||
if (TryNormalizeObservedPrintableLabel(args.KeySymbol, out string label))
|
||||
{
|
||||
if (_observedLayoutLabels.TryGetValue(physicalKey, out string existingLabel) && existingLabel == label)
|
||||
{
|
||||
return;
|
||||
}
|
||||
|
||||
_observedLayoutLabels[physicalKey] = label;
|
||||
LabelsChanged?.Invoke();
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -198,5 +198,37 @@ namespace Ryujinx.Ava.UI.Models.Input
|
||||
|
||||
return config;
|
||||
}
|
||||
|
||||
public void NotifyKeyLabelsChanged()
|
||||
{
|
||||
OnPropertiesChanged(nameof(LeftStickUp),
|
||||
nameof(LeftStickDown),
|
||||
nameof(LeftStickLeft),
|
||||
nameof(LeftStickRight),
|
||||
nameof(LeftStickButton),
|
||||
nameof(RightStickUp),
|
||||
nameof(RightStickDown),
|
||||
nameof(RightStickLeft),
|
||||
nameof(RightStickRight),
|
||||
nameof(RightStickButton),
|
||||
nameof(DpadUp),
|
||||
nameof(DpadDown),
|
||||
nameof(DpadLeft),
|
||||
nameof(DpadRight),
|
||||
nameof(ButtonMinus),
|
||||
nameof(ButtonPlus),
|
||||
nameof(ButtonA),
|
||||
nameof(ButtonB),
|
||||
nameof(ButtonX),
|
||||
nameof(ButtonY),
|
||||
nameof(ButtonL),
|
||||
nameof(ButtonR),
|
||||
nameof(ButtonZl),
|
||||
nameof(ButtonZr),
|
||||
nameof(LeftButtonSl),
|
||||
nameof(LeftButtonSr),
|
||||
nameof(RightButtonSl),
|
||||
nameof(RightButtonSr));
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1,6 +1,7 @@
|
||||
using Avalonia.Collections;
|
||||
using Avalonia.Controls;
|
||||
using Avalonia.Svg.Skia;
|
||||
using Avalonia.Threading;
|
||||
using CommunityToolkit.Mvvm.ComponentModel;
|
||||
using Gommon;
|
||||
using Ryujinx.Ava.Common.Locale;
|
||||
@@ -293,6 +294,7 @@ namespace Ryujinx.Ava.UI.ViewModels.Input
|
||||
AvaloniaKeyboardDriver keyboardDriver = new(owner, KeyboardInputMode.Physical);
|
||||
keyboardDriver.KeyPressed += PhysicalKeyLabelHelper.ObserveKeyPress;
|
||||
AvaloniaKeyboardDriver = keyboardDriver;
|
||||
PhysicalKeyLabelHelper.LabelsChanged += OnPhysicalKeyLabelsChanged;
|
||||
|
||||
_mainWindow.InputManager.GamepadDriver.OnGamepadConnected += HandleOnGamepadConnected;
|
||||
_mainWindow.InputManager.GamepadDriver.OnGamepadDisconnected += HandleOnGamepadDisconnected;
|
||||
@@ -1062,9 +1064,18 @@ namespace Ryujinx.Ava.UI.ViewModels.Input
|
||||
NotifyChangesEvent?.Invoke();
|
||||
}
|
||||
|
||||
private void OnPhysicalKeyLabelsChanged()
|
||||
{
|
||||
if (ConfigViewModel is KeyboardInputViewModel keyboardInputViewModel)
|
||||
{
|
||||
Dispatcher.UIThread.Post(keyboardInputViewModel.Config.NotifyKeyLabelsChanged);
|
||||
}
|
||||
}
|
||||
|
||||
public void Dispose()
|
||||
{
|
||||
GC.SuppressFinalize(this);
|
||||
PhysicalKeyLabelHelper.LabelsChanged -= OnPhysicalKeyLabelsChanged;
|
||||
|
||||
_mainWindow.InputManager.GamepadDriver.OnGamepadConnected -= HandleOnGamepadConnected;
|
||||
_mainWindow.InputManager.GamepadDriver.OnGamepadDisconnected -= HandleOnGamepadDisconnected;
|
||||
|
||||
Reference in New Issue
Block a user