mirror of
https://git.ryujinx.app/ryubing/ryujinx.git
synced 2026-06-05 03:49:17 +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
|
internal static class PhysicalKeyLabelHelper
|
||||||
{
|
{
|
||||||
private static readonly ConcurrentDictionary<ConfigPhysicalKey, string> _observedLayoutLabels = new();
|
private static readonly ConcurrentDictionary<ConfigPhysicalKey, string> _observedLayoutLabels = new();
|
||||||
|
public static event Action LabelsChanged;
|
||||||
|
|
||||||
private static readonly Dictionary<ConfigPhysicalKey, LocaleKeys> _localizedKeysMap = new()
|
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 (TryNormalizeObservedPrintableLabel(args.KeySymbol, out string label))
|
||||||
{
|
{
|
||||||
|
if (_observedLayoutLabels.TryGetValue(physicalKey, out string existingLabel) && existingLabel == label)
|
||||||
|
{
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
_observedLayoutLabels[physicalKey] = label;
|
_observedLayoutLabels[physicalKey] = label;
|
||||||
|
LabelsChanged?.Invoke();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -198,5 +198,37 @@ namespace Ryujinx.Ava.UI.Models.Input
|
|||||||
|
|
||||||
return config;
|
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.Collections;
|
||||||
using Avalonia.Controls;
|
using Avalonia.Controls;
|
||||||
using Avalonia.Svg.Skia;
|
using Avalonia.Svg.Skia;
|
||||||
|
using Avalonia.Threading;
|
||||||
using CommunityToolkit.Mvvm.ComponentModel;
|
using CommunityToolkit.Mvvm.ComponentModel;
|
||||||
using Gommon;
|
using Gommon;
|
||||||
using Ryujinx.Ava.Common.Locale;
|
using Ryujinx.Ava.Common.Locale;
|
||||||
@@ -293,6 +294,7 @@ namespace Ryujinx.Ava.UI.ViewModels.Input
|
|||||||
AvaloniaKeyboardDriver keyboardDriver = new(owner, KeyboardInputMode.Physical);
|
AvaloniaKeyboardDriver keyboardDriver = new(owner, KeyboardInputMode.Physical);
|
||||||
keyboardDriver.KeyPressed += PhysicalKeyLabelHelper.ObserveKeyPress;
|
keyboardDriver.KeyPressed += PhysicalKeyLabelHelper.ObserveKeyPress;
|
||||||
AvaloniaKeyboardDriver = keyboardDriver;
|
AvaloniaKeyboardDriver = keyboardDriver;
|
||||||
|
PhysicalKeyLabelHelper.LabelsChanged += OnPhysicalKeyLabelsChanged;
|
||||||
|
|
||||||
_mainWindow.InputManager.GamepadDriver.OnGamepadConnected += HandleOnGamepadConnected;
|
_mainWindow.InputManager.GamepadDriver.OnGamepadConnected += HandleOnGamepadConnected;
|
||||||
_mainWindow.InputManager.GamepadDriver.OnGamepadDisconnected += HandleOnGamepadDisconnected;
|
_mainWindow.InputManager.GamepadDriver.OnGamepadDisconnected += HandleOnGamepadDisconnected;
|
||||||
@@ -1062,9 +1064,18 @@ namespace Ryujinx.Ava.UI.ViewModels.Input
|
|||||||
NotifyChangesEvent?.Invoke();
|
NotifyChangesEvent?.Invoke();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
private void OnPhysicalKeyLabelsChanged()
|
||||||
|
{
|
||||||
|
if (ConfigViewModel is KeyboardInputViewModel keyboardInputViewModel)
|
||||||
|
{
|
||||||
|
Dispatcher.UIThread.Post(keyboardInputViewModel.Config.NotifyKeyLabelsChanged);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
public void Dispose()
|
public void Dispose()
|
||||||
{
|
{
|
||||||
GC.SuppressFinalize(this);
|
GC.SuppressFinalize(this);
|
||||||
|
PhysicalKeyLabelHelper.LabelsChanged -= OnPhysicalKeyLabelsChanged;
|
||||||
|
|
||||||
_mainWindow.InputManager.GamepadDriver.OnGamepadConnected -= HandleOnGamepadConnected;
|
_mainWindow.InputManager.GamepadDriver.OnGamepadConnected -= HandleOnGamepadConnected;
|
||||||
_mainWindow.InputManager.GamepadDriver.OnGamepadDisconnected -= HandleOnGamepadDisconnected;
|
_mainWindow.InputManager.GamepadDriver.OnGamepadDisconnected -= HandleOnGamepadDisconnected;
|
||||||
|
|||||||
Reference in New Issue
Block a user