mirror of
https://git.ryujinx.app/ryubing/ryujinx.git
synced 2026-06-05 11:59:15 +00:00
Simplify keyboard input cleanup paths
This commit is contained in:
@@ -1,6 +1,5 @@
|
||||
using Ryujinx.Common.Configuration.Hid;
|
||||
using Ryujinx.Common.Configuration.Hid.Keyboard;
|
||||
using Ryujinx.Common.Logging;
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Numerics;
|
||||
@@ -15,10 +14,6 @@ namespace Ryujinx.Input.SDL3
|
||||
class SDL3Keyboard : IKeyboard
|
||||
{
|
||||
private readonly Lock _userMappingLock = new();
|
||||
|
||||
#pragma warning disable IDE0052 // Remove unread private member
|
||||
private readonly SDL3KeyboardDriver _driver;
|
||||
#pragma warning restore IDE0052
|
||||
private StandardKeyboardInputConfig _configuration;
|
||||
private readonly List<KeyboardInputMappingHelper.KeyboardButtonMapping> _buttonsUserMapping;
|
||||
|
||||
@@ -165,9 +160,8 @@ namespace Ryujinx.Input.SDL3
|
||||
SDL_Keycode.SDLK_0
|
||||
];
|
||||
|
||||
public SDL3Keyboard(SDL3KeyboardDriver driver, string id, string name)
|
||||
public SDL3Keyboard(string id, string name)
|
||||
{
|
||||
_driver = driver;
|
||||
Id = id;
|
||||
Name = name;
|
||||
_buttonsUserMapping = [];
|
||||
@@ -329,7 +323,7 @@ namespace Ryujinx.Input.SDL3
|
||||
|
||||
public void SetLed(uint packedRgb)
|
||||
{
|
||||
Logger.Info?.Print(LogClass.UI, "SetLed called on an SDL3Keyboard");
|
||||
// Keyboard LEDs are not supported by this backend.
|
||||
}
|
||||
|
||||
public void SetTriggerThreshold(float triggerThreshold)
|
||||
|
||||
@@ -4,7 +4,7 @@ using System.Collections.Generic;
|
||||
|
||||
namespace Ryujinx.Input.SDL3
|
||||
{
|
||||
public class SDL3KeyboardDriver : IKeyboardModeDriver
|
||||
public class SDL3KeyboardDriver : IGamepadDriver
|
||||
{
|
||||
public SDL3KeyboardDriver()
|
||||
{
|
||||
@@ -44,18 +44,13 @@ namespace Ryujinx.Input.SDL3
|
||||
}
|
||||
|
||||
public IGamepad GetGamepad(string id)
|
||||
{
|
||||
return GetKeyboard(id, KeyboardInputMode.Semantic);
|
||||
}
|
||||
|
||||
public IKeyboard GetKeyboard(string id, KeyboardInputMode mode)
|
||||
{
|
||||
if (!_keyboardIdentifers[0].Equals(id))
|
||||
{
|
||||
return null;
|
||||
}
|
||||
|
||||
return new SDL3Keyboard(this, _keyboardIdentifers[0], "All keyboards");
|
||||
return new SDL3Keyboard(_keyboardIdentifers[0], "All keyboards");
|
||||
}
|
||||
|
||||
public IEnumerable<IGamepad> GetGamepads()
|
||||
|
||||
@@ -1,6 +1,5 @@
|
||||
using Ryujinx.Common.Configuration.Hid;
|
||||
using Ryujinx.Common.Configuration.Hid.Keyboard;
|
||||
using Ryujinx.Common.Logging;
|
||||
using Ryujinx.Input;
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
@@ -16,7 +15,6 @@ namespace Ryujinx.Ava.Input
|
||||
private readonly AvaloniaKeyboardDriver _driver;
|
||||
private readonly KeyboardInputMode _mode;
|
||||
private StandardKeyboardInputConfig _configuration;
|
||||
private uint _ledValue;
|
||||
|
||||
private readonly Lock _userMappingLock = new();
|
||||
|
||||
@@ -117,16 +115,7 @@ namespace Ryujinx.Ava.Input
|
||||
|
||||
public void SetLed(uint packedRgb)
|
||||
{
|
||||
if (_ledValue == packedRgb)
|
||||
{
|
||||
return;
|
||||
}
|
||||
|
||||
_ledValue = packedRgb;
|
||||
|
||||
Logger.Info?.Print(LogClass.UI, "SetLed called on an AvaloniaKeyboard");
|
||||
|
||||
// Keyboard LED is not supported by this backend.
|
||||
// Keyboard LEDs are not supported by this backend.
|
||||
}
|
||||
|
||||
public void SetTriggerThreshold(float triggerThreshold) { }
|
||||
|
||||
@@ -5,6 +5,7 @@ using Ryujinx.Common.Configuration.Hid.Controller;
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Globalization;
|
||||
using Key = Ryujinx.Input.Key;
|
||||
|
||||
namespace Ryujinx.Ava.UI.Helpers
|
||||
{
|
||||
@@ -12,79 +13,6 @@ namespace Ryujinx.Ava.UI.Helpers
|
||||
{
|
||||
public static readonly KeyValueConverter Instance = new();
|
||||
|
||||
private static readonly Dictionary<Key, LocaleKeys> _keysMap = new()
|
||||
{
|
||||
{ Key.Unknown, LocaleKeys.KeyboardLayout_KeyUnknown },
|
||||
{ Key.ShiftLeft, LocaleKeys.KeyboardLayout_KeyShiftLeft },
|
||||
{ Key.ShiftRight, LocaleKeys.KeyboardLayout_KeyShiftRight },
|
||||
{ Key.ControlLeft, LocaleKeys.KeyboardLayout_KeyControlLeft },
|
||||
{ Key.ControlRight, LocaleKeys.KeyboardLayout_KeyControlRight },
|
||||
{ Key.AltLeft, LocaleKeys.KeyboardLayout_KeyAltLeft },
|
||||
{ Key.AltRight, LocaleKeys.KeyboardLayout_KeyAltRight },
|
||||
{ Key.WinLeft, LocaleKeys.KeyboardLayout_KeyWinLeft },
|
||||
{ Key.WinRight, LocaleKeys.KeyboardLayout_KeyWinRight },
|
||||
{ Key.Up, LocaleKeys.KeyboardLayout_KeyUp },
|
||||
{ Key.Down, LocaleKeys.KeyboardLayout_KeyDown },
|
||||
{ Key.Left, LocaleKeys.KeyboardLayout_KeyLeft },
|
||||
{ Key.Right, LocaleKeys.KeyboardLayout_KeyRight },
|
||||
{ Key.Enter, LocaleKeys.KeyboardLayout_KeyEnter },
|
||||
{ Key.Escape, LocaleKeys.KeyboardLayout_KeyEscape },
|
||||
{ Key.Space, LocaleKeys.KeyboardLayout_KeySpace },
|
||||
{ Key.Tab, LocaleKeys.KeyboardLayout_KeyTab },
|
||||
{ Key.BackSpace, LocaleKeys.KeyboardLayout_KeyBackSpace },
|
||||
{ Key.Insert, LocaleKeys.KeyboardLayout_KeyInsert },
|
||||
{ Key.Delete, LocaleKeys.KeyboardLayout_KeyDelete },
|
||||
{ Key.PageUp, LocaleKeys.KeyboardLayout_KeyPageUp },
|
||||
{ Key.PageDown, LocaleKeys.KeyboardLayout_KeyPageDown },
|
||||
{ Key.Home, LocaleKeys.KeyboardLayout_KeyHome },
|
||||
{ Key.End, LocaleKeys.KeyboardLayout_KeyEnd },
|
||||
{ Key.CapsLock, LocaleKeys.KeyboardLayout_KeyCapsLock },
|
||||
{ Key.ScrollLock, LocaleKeys.KeyboardLayout_KeyScrollLock },
|
||||
{ Key.PrintScreen, LocaleKeys.KeyboardLayout_KeyPrintScreen },
|
||||
{ Key.Pause, LocaleKeys.KeyboardLayout_KeyPause },
|
||||
{ Key.NumLock, LocaleKeys.KeyboardLayout_KeyNumLock },
|
||||
{ Key.Clear, LocaleKeys.KeyboardLayout_KeyClear },
|
||||
{ Key.Keypad0, LocaleKeys.KeyboardLayout_KeyKeypad0 },
|
||||
{ Key.Keypad1, LocaleKeys.KeyboardLayout_KeyKeypad1 },
|
||||
{ Key.Keypad2, LocaleKeys.KeyboardLayout_KeyKeypad2 },
|
||||
{ Key.Keypad3, LocaleKeys.KeyboardLayout_KeyKeypad3 },
|
||||
{ Key.Keypad4, LocaleKeys.KeyboardLayout_KeyKeypad4 },
|
||||
{ Key.Keypad5, LocaleKeys.KeyboardLayout_KeyKeypad5 },
|
||||
{ Key.Keypad6, LocaleKeys.KeyboardLayout_KeyKeypad6 },
|
||||
{ Key.Keypad7, LocaleKeys.KeyboardLayout_KeyKeypad7 },
|
||||
{ Key.Keypad8, LocaleKeys.KeyboardLayout_KeyKeypad8 },
|
||||
{ Key.Keypad9, LocaleKeys.KeyboardLayout_KeyKeypad9 },
|
||||
{ Key.KeypadDivide, LocaleKeys.KeyboardLayout_KeyKeypadDivide },
|
||||
{ Key.KeypadMultiply, LocaleKeys.KeyboardLayout_KeyKeypadMultiply },
|
||||
{ Key.KeypadSubtract, LocaleKeys.KeyboardLayout_KeyKeypadSubtract },
|
||||
{ Key.KeypadAdd, LocaleKeys.KeyboardLayout_KeyKeypadAdd },
|
||||
{ Key.KeypadDecimal, LocaleKeys.KeyboardLayout_KeyKeypadDecimal },
|
||||
{ Key.KeypadEnter, LocaleKeys.KeyboardLayout_KeyKeypadEnter },
|
||||
{ Key.Number0, LocaleKeys.KeyboardLayout_KeyNumber0 },
|
||||
{ Key.Number1, LocaleKeys.KeyboardLayout_KeyNumber1 },
|
||||
{ Key.Number2, LocaleKeys.KeyboardLayout_KeyNumber2 },
|
||||
{ Key.Number3, LocaleKeys.KeyboardLayout_KeyNumber3 },
|
||||
{ Key.Number4, LocaleKeys.KeyboardLayout_KeyNumber4 },
|
||||
{ Key.Number5, LocaleKeys.KeyboardLayout_KeyNumber5 },
|
||||
{ Key.Number6, LocaleKeys.KeyboardLayout_KeyNumber6 },
|
||||
{ Key.Number7, LocaleKeys.KeyboardLayout_KeyNumber7 },
|
||||
{ Key.Number8, LocaleKeys.KeyboardLayout_KeyNumber8 },
|
||||
{ Key.Number9, LocaleKeys.KeyboardLayout_KeyNumber9 },
|
||||
{ Key.Tilde, LocaleKeys.KeyboardLayout_KeyTilde },
|
||||
{ Key.Grave, LocaleKeys.KeyboardLayout_KeyGrave },
|
||||
{ Key.Minus, LocaleKeys.KeyboardLayout_KeyMinus },
|
||||
{ Key.Plus, LocaleKeys.KeyboardLayout_KeyPlus },
|
||||
{ Key.BracketLeft, LocaleKeys.KeyboardLayout_KeyBracketLeft },
|
||||
{ Key.BracketRight, LocaleKeys.KeyboardLayout_KeyBracketRight },
|
||||
{ Key.Semicolon, LocaleKeys.KeyboardLayout_KeySemicolon },
|
||||
{ Key.Quote, LocaleKeys.KeyboardLayout_KeyQuote },
|
||||
{ Key.Comma, LocaleKeys.KeyboardLayout_KeyComma },
|
||||
{ Key.Period, LocaleKeys.KeyboardLayout_KeyPeriod },
|
||||
{ Key.Slash, LocaleKeys.KeyboardLayout_KeySlash },
|
||||
{ Key.BackSlash, LocaleKeys.KeyboardLayout_KeyBackSlash },
|
||||
{ Key.Unbound, LocaleKeys.KeyboardLayout_KeyUnbound },
|
||||
};
|
||||
|
||||
private static readonly Dictionary<GamepadInputId, LocaleKeys> _gamepadInputIdMap = new()
|
||||
{
|
||||
{ GamepadInputId.LeftStick, LocaleKeys.GamepadLeftStick },
|
||||
@@ -123,28 +51,13 @@ namespace Ryujinx.Ava.UI.Helpers
|
||||
public object Convert(object value, Type targetType, object parameter, CultureInfo culture)
|
||||
{
|
||||
string keyString = string.Empty;
|
||||
LocaleKeys localeKey;
|
||||
|
||||
switch (value)
|
||||
{
|
||||
case Key key:
|
||||
if (_keysMap.TryGetValue(key, out localeKey))
|
||||
if (KeyboardLayoutLocaleHelper.TryGetSemanticLabel(key, out string localizedKeyLabel))
|
||||
{
|
||||
if (OperatingSystem.IsMacOS())
|
||||
{
|
||||
localeKey = localeKey switch
|
||||
{
|
||||
LocaleKeys.KeyboardLayout_KeyControlLeft => LocaleKeys.KeyboardLayout_KeyMacControlLeft,
|
||||
LocaleKeys.KeyboardLayout_KeyControlRight => LocaleKeys.KeyboardLayout_KeyMacControlRight,
|
||||
LocaleKeys.KeyboardLayout_KeyAltLeft => LocaleKeys.KeyboardLayout_KeyMacAltLeft,
|
||||
LocaleKeys.KeyboardLayout_KeyAltRight => LocaleKeys.KeyboardLayout_KeyMacAltRight,
|
||||
LocaleKeys.KeyboardLayout_KeyWinLeft => LocaleKeys.KeyboardLayout_KeyMacWinLeft,
|
||||
LocaleKeys.KeyboardLayout_KeyWinRight => LocaleKeys.KeyboardLayout_KeyMacWinRight,
|
||||
_ => localeKey
|
||||
};
|
||||
}
|
||||
|
||||
keyString = LocaleManager.Instance[localeKey];
|
||||
keyString = localizedKeyLabel;
|
||||
}
|
||||
else
|
||||
{
|
||||
@@ -156,6 +69,7 @@ namespace Ryujinx.Ava.UI.Helpers
|
||||
keyString = PhysicalKeyLabelHelper.GetDisplayString(physicalKey);
|
||||
break;
|
||||
case GamepadInputId gamepadInputId:
|
||||
LocaleKeys localeKey;
|
||||
if (_gamepadInputIdMap.TryGetValue(gamepadInputId, out localeKey))
|
||||
{
|
||||
keyString = LocaleManager.Instance[localeKey];
|
||||
|
||||
142
src/Ryujinx/UI/Helpers/KeyboardLayoutLocaleHelper.cs
Normal file
142
src/Ryujinx/UI/Helpers/KeyboardLayoutLocaleHelper.cs
Normal file
@@ -0,0 +1,142 @@
|
||||
using Ryujinx.Ava.Common.Locale;
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using ConfigPhysicalKey = Ryujinx.Common.Configuration.Hid.PhysicalKey;
|
||||
using InputKey = Ryujinx.Input.Key;
|
||||
|
||||
namespace Ryujinx.Ava.UI.Helpers
|
||||
{
|
||||
internal static class KeyboardLayoutLocaleHelper
|
||||
{
|
||||
private static readonly Dictionary<InputKey, LocaleKeys> _sharedLocalizedKeysMap = new()
|
||||
{
|
||||
[InputKey.Unknown] = LocaleKeys.KeyboardLayout_KeyUnknown,
|
||||
[InputKey.ShiftLeft] = LocaleKeys.KeyboardLayout_KeyShiftLeft,
|
||||
[InputKey.ShiftRight] = LocaleKeys.KeyboardLayout_KeyShiftRight,
|
||||
[InputKey.ControlLeft] = LocaleKeys.KeyboardLayout_KeyControlLeft,
|
||||
[InputKey.ControlRight] = LocaleKeys.KeyboardLayout_KeyControlRight,
|
||||
[InputKey.AltLeft] = LocaleKeys.KeyboardLayout_KeyAltLeft,
|
||||
[InputKey.AltRight] = LocaleKeys.KeyboardLayout_KeyAltRight,
|
||||
[InputKey.WinLeft] = LocaleKeys.KeyboardLayout_KeyWinLeft,
|
||||
[InputKey.WinRight] = LocaleKeys.KeyboardLayout_KeyWinRight,
|
||||
[InputKey.Up] = LocaleKeys.KeyboardLayout_KeyUp,
|
||||
[InputKey.Down] = LocaleKeys.KeyboardLayout_KeyDown,
|
||||
[InputKey.Left] = LocaleKeys.KeyboardLayout_KeyLeft,
|
||||
[InputKey.Right] = LocaleKeys.KeyboardLayout_KeyRight,
|
||||
[InputKey.Enter] = LocaleKeys.KeyboardLayout_KeyEnter,
|
||||
[InputKey.Escape] = LocaleKeys.KeyboardLayout_KeyEscape,
|
||||
[InputKey.Space] = LocaleKeys.KeyboardLayout_KeySpace,
|
||||
[InputKey.Tab] = LocaleKeys.KeyboardLayout_KeyTab,
|
||||
[InputKey.BackSpace] = LocaleKeys.KeyboardLayout_KeyBackSpace,
|
||||
[InputKey.Insert] = LocaleKeys.KeyboardLayout_KeyInsert,
|
||||
[InputKey.Delete] = LocaleKeys.KeyboardLayout_KeyDelete,
|
||||
[InputKey.PageUp] = LocaleKeys.KeyboardLayout_KeyPageUp,
|
||||
[InputKey.PageDown] = LocaleKeys.KeyboardLayout_KeyPageDown,
|
||||
[InputKey.Home] = LocaleKeys.KeyboardLayout_KeyHome,
|
||||
[InputKey.End] = LocaleKeys.KeyboardLayout_KeyEnd,
|
||||
[InputKey.CapsLock] = LocaleKeys.KeyboardLayout_KeyCapsLock,
|
||||
[InputKey.ScrollLock] = LocaleKeys.KeyboardLayout_KeyScrollLock,
|
||||
[InputKey.PrintScreen] = LocaleKeys.KeyboardLayout_KeyPrintScreen,
|
||||
[InputKey.Pause] = LocaleKeys.KeyboardLayout_KeyPause,
|
||||
[InputKey.NumLock] = LocaleKeys.KeyboardLayout_KeyNumLock,
|
||||
[InputKey.Clear] = LocaleKeys.KeyboardLayout_KeyClear,
|
||||
[InputKey.Keypad0] = LocaleKeys.KeyboardLayout_KeyKeypad0,
|
||||
[InputKey.Keypad1] = LocaleKeys.KeyboardLayout_KeyKeypad1,
|
||||
[InputKey.Keypad2] = LocaleKeys.KeyboardLayout_KeyKeypad2,
|
||||
[InputKey.Keypad3] = LocaleKeys.KeyboardLayout_KeyKeypad3,
|
||||
[InputKey.Keypad4] = LocaleKeys.KeyboardLayout_KeyKeypad4,
|
||||
[InputKey.Keypad5] = LocaleKeys.KeyboardLayout_KeyKeypad5,
|
||||
[InputKey.Keypad6] = LocaleKeys.KeyboardLayout_KeyKeypad6,
|
||||
[InputKey.Keypad7] = LocaleKeys.KeyboardLayout_KeyKeypad7,
|
||||
[InputKey.Keypad8] = LocaleKeys.KeyboardLayout_KeyKeypad8,
|
||||
[InputKey.Keypad9] = LocaleKeys.KeyboardLayout_KeyKeypad9,
|
||||
[InputKey.KeypadDivide] = LocaleKeys.KeyboardLayout_KeyKeypadDivide,
|
||||
[InputKey.KeypadMultiply] = LocaleKeys.KeyboardLayout_KeyKeypadMultiply,
|
||||
[InputKey.KeypadSubtract] = LocaleKeys.KeyboardLayout_KeyKeypadSubtract,
|
||||
[InputKey.KeypadAdd] = LocaleKeys.KeyboardLayout_KeyKeypadAdd,
|
||||
[InputKey.KeypadDecimal] = LocaleKeys.KeyboardLayout_KeyKeypadDecimal,
|
||||
[InputKey.KeypadEnter] = LocaleKeys.KeyboardLayout_KeyKeypadEnter,
|
||||
[InputKey.Unbound] = LocaleKeys.KeyboardLayout_KeyUnbound,
|
||||
};
|
||||
|
||||
private static readonly Dictionary<InputKey, LocaleKeys> _semanticPrintableKeysMap = new()
|
||||
{
|
||||
[InputKey.Number0] = LocaleKeys.KeyboardLayout_KeyNumber0,
|
||||
[InputKey.Number1] = LocaleKeys.KeyboardLayout_KeyNumber1,
|
||||
[InputKey.Number2] = LocaleKeys.KeyboardLayout_KeyNumber2,
|
||||
[InputKey.Number3] = LocaleKeys.KeyboardLayout_KeyNumber3,
|
||||
[InputKey.Number4] = LocaleKeys.KeyboardLayout_KeyNumber4,
|
||||
[InputKey.Number5] = LocaleKeys.KeyboardLayout_KeyNumber5,
|
||||
[InputKey.Number6] = LocaleKeys.KeyboardLayout_KeyNumber6,
|
||||
[InputKey.Number7] = LocaleKeys.KeyboardLayout_KeyNumber7,
|
||||
[InputKey.Number8] = LocaleKeys.KeyboardLayout_KeyNumber8,
|
||||
[InputKey.Number9] = LocaleKeys.KeyboardLayout_KeyNumber9,
|
||||
[InputKey.Tilde] = LocaleKeys.KeyboardLayout_KeyTilde,
|
||||
[InputKey.Grave] = LocaleKeys.KeyboardLayout_KeyGrave,
|
||||
[InputKey.Minus] = LocaleKeys.KeyboardLayout_KeyMinus,
|
||||
[InputKey.Plus] = LocaleKeys.KeyboardLayout_KeyPlus,
|
||||
[InputKey.BracketLeft] = LocaleKeys.KeyboardLayout_KeyBracketLeft,
|
||||
[InputKey.BracketRight] = LocaleKeys.KeyboardLayout_KeyBracketRight,
|
||||
[InputKey.Semicolon] = LocaleKeys.KeyboardLayout_KeySemicolon,
|
||||
[InputKey.Quote] = LocaleKeys.KeyboardLayout_KeyQuote,
|
||||
[InputKey.Comma] = LocaleKeys.KeyboardLayout_KeyComma,
|
||||
[InputKey.Period] = LocaleKeys.KeyboardLayout_KeyPeriod,
|
||||
[InputKey.Slash] = LocaleKeys.KeyboardLayout_KeySlash,
|
||||
[InputKey.BackSlash] = LocaleKeys.KeyboardLayout_KeyBackSlash,
|
||||
};
|
||||
|
||||
public static bool TryGetSemanticLabel(InputKey key, out string label)
|
||||
{
|
||||
if (TryGetSemanticLocaleKey(key, out LocaleKeys localeKey))
|
||||
{
|
||||
label = GetLocalizedString(localeKey);
|
||||
return true;
|
||||
}
|
||||
|
||||
label = string.Empty;
|
||||
return false;
|
||||
}
|
||||
|
||||
public static bool TryGetPhysicalLabel(ConfigPhysicalKey key, out string label)
|
||||
{
|
||||
if (TryGetPhysicalLocaleKey(key, out LocaleKeys localeKey))
|
||||
{
|
||||
label = GetLocalizedString(localeKey);
|
||||
return true;
|
||||
}
|
||||
|
||||
label = string.Empty;
|
||||
return false;
|
||||
}
|
||||
|
||||
public static bool TryGetPhysicalLocaleKey(ConfigPhysicalKey key, out LocaleKeys localeKey)
|
||||
{
|
||||
return _sharedLocalizedKeysMap.TryGetValue((InputKey)(int)key, out localeKey);
|
||||
}
|
||||
|
||||
private static bool TryGetSemanticLocaleKey(InputKey key, out LocaleKeys localeKey)
|
||||
{
|
||||
return _sharedLocalizedKeysMap.TryGetValue(key, out localeKey) ||
|
||||
_semanticPrintableKeysMap.TryGetValue(key, out localeKey);
|
||||
}
|
||||
|
||||
private static string GetLocalizedString(LocaleKeys localeKey)
|
||||
{
|
||||
if (OperatingSystem.IsMacOS())
|
||||
{
|
||||
localeKey = localeKey switch
|
||||
{
|
||||
LocaleKeys.KeyboardLayout_KeyControlLeft => LocaleKeys.KeyboardLayout_KeyMacControlLeft,
|
||||
LocaleKeys.KeyboardLayout_KeyControlRight => LocaleKeys.KeyboardLayout_KeyMacControlRight,
|
||||
LocaleKeys.KeyboardLayout_KeyAltLeft => LocaleKeys.KeyboardLayout_KeyMacAltLeft,
|
||||
LocaleKeys.KeyboardLayout_KeyAltRight => LocaleKeys.KeyboardLayout_KeyMacAltRight,
|
||||
LocaleKeys.KeyboardLayout_KeyWinLeft => LocaleKeys.KeyboardLayout_KeyMacWinLeft,
|
||||
LocaleKeys.KeyboardLayout_KeyWinRight => LocaleKeys.KeyboardLayout_KeyMacWinRight,
|
||||
_ => localeKey
|
||||
};
|
||||
}
|
||||
|
||||
return LocaleManager.Instance[localeKey];
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -4,7 +4,6 @@ using Ryujinx.Ava.Input;
|
||||
using Ryujinx.Common.Configuration.Hid;
|
||||
using System;
|
||||
using System.Collections.Concurrent;
|
||||
using System.Collections.Generic;
|
||||
using AvaPhysicalKey = Avalonia.Input.PhysicalKey;
|
||||
using ConfigPhysicalKey = Ryujinx.Common.Configuration.Hid.PhysicalKey;
|
||||
using InputKey = Ryujinx.Input.Key;
|
||||
@@ -16,62 +15,11 @@ namespace Ryujinx.Ava.UI.Helpers
|
||||
private static readonly ConcurrentDictionary<ConfigPhysicalKey, string> _observedLayoutLabels = new();
|
||||
public static event Action LabelsChanged;
|
||||
|
||||
private static readonly Dictionary<ConfigPhysicalKey, LocaleKeys> _localizedKeysMap = new()
|
||||
{
|
||||
[ConfigPhysicalKey.Unknown] = LocaleKeys.KeyboardLayout_KeyUnknown,
|
||||
[ConfigPhysicalKey.ShiftLeft] = LocaleKeys.KeyboardLayout_KeyShiftLeft,
|
||||
[ConfigPhysicalKey.ShiftRight] = LocaleKeys.KeyboardLayout_KeyShiftRight,
|
||||
[ConfigPhysicalKey.ControlLeft] = LocaleKeys.KeyboardLayout_KeyControlLeft,
|
||||
[ConfigPhysicalKey.ControlRight] = LocaleKeys.KeyboardLayout_KeyControlRight,
|
||||
[ConfigPhysicalKey.AltLeft] = LocaleKeys.KeyboardLayout_KeyAltLeft,
|
||||
[ConfigPhysicalKey.AltRight] = LocaleKeys.KeyboardLayout_KeyAltRight,
|
||||
[ConfigPhysicalKey.WinLeft] = LocaleKeys.KeyboardLayout_KeyWinLeft,
|
||||
[ConfigPhysicalKey.WinRight] = LocaleKeys.KeyboardLayout_KeyWinRight,
|
||||
[ConfigPhysicalKey.Up] = LocaleKeys.KeyboardLayout_KeyUp,
|
||||
[ConfigPhysicalKey.Down] = LocaleKeys.KeyboardLayout_KeyDown,
|
||||
[ConfigPhysicalKey.Left] = LocaleKeys.KeyboardLayout_KeyLeft,
|
||||
[ConfigPhysicalKey.Right] = LocaleKeys.KeyboardLayout_KeyRight,
|
||||
[ConfigPhysicalKey.Enter] = LocaleKeys.KeyboardLayout_KeyEnter,
|
||||
[ConfigPhysicalKey.Escape] = LocaleKeys.KeyboardLayout_KeyEscape,
|
||||
[ConfigPhysicalKey.Space] = LocaleKeys.KeyboardLayout_KeySpace,
|
||||
[ConfigPhysicalKey.Tab] = LocaleKeys.KeyboardLayout_KeyTab,
|
||||
[ConfigPhysicalKey.BackSpace] = LocaleKeys.KeyboardLayout_KeyBackSpace,
|
||||
[ConfigPhysicalKey.Insert] = LocaleKeys.KeyboardLayout_KeyInsert,
|
||||
[ConfigPhysicalKey.Delete] = LocaleKeys.KeyboardLayout_KeyDelete,
|
||||
[ConfigPhysicalKey.PageUp] = LocaleKeys.KeyboardLayout_KeyPageUp,
|
||||
[ConfigPhysicalKey.PageDown] = LocaleKeys.KeyboardLayout_KeyPageDown,
|
||||
[ConfigPhysicalKey.Home] = LocaleKeys.KeyboardLayout_KeyHome,
|
||||
[ConfigPhysicalKey.End] = LocaleKeys.KeyboardLayout_KeyEnd,
|
||||
[ConfigPhysicalKey.CapsLock] = LocaleKeys.KeyboardLayout_KeyCapsLock,
|
||||
[ConfigPhysicalKey.ScrollLock] = LocaleKeys.KeyboardLayout_KeyScrollLock,
|
||||
[ConfigPhysicalKey.PrintScreen] = LocaleKeys.KeyboardLayout_KeyPrintScreen,
|
||||
[ConfigPhysicalKey.Pause] = LocaleKeys.KeyboardLayout_KeyPause,
|
||||
[ConfigPhysicalKey.NumLock] = LocaleKeys.KeyboardLayout_KeyNumLock,
|
||||
[ConfigPhysicalKey.Clear] = LocaleKeys.KeyboardLayout_KeyClear,
|
||||
[ConfigPhysicalKey.Keypad0] = LocaleKeys.KeyboardLayout_KeyKeypad0,
|
||||
[ConfigPhysicalKey.Keypad1] = LocaleKeys.KeyboardLayout_KeyKeypad1,
|
||||
[ConfigPhysicalKey.Keypad2] = LocaleKeys.KeyboardLayout_KeyKeypad2,
|
||||
[ConfigPhysicalKey.Keypad3] = LocaleKeys.KeyboardLayout_KeyKeypad3,
|
||||
[ConfigPhysicalKey.Keypad4] = LocaleKeys.KeyboardLayout_KeyKeypad4,
|
||||
[ConfigPhysicalKey.Keypad5] = LocaleKeys.KeyboardLayout_KeyKeypad5,
|
||||
[ConfigPhysicalKey.Keypad6] = LocaleKeys.KeyboardLayout_KeyKeypad6,
|
||||
[ConfigPhysicalKey.Keypad7] = LocaleKeys.KeyboardLayout_KeyKeypad7,
|
||||
[ConfigPhysicalKey.Keypad8] = LocaleKeys.KeyboardLayout_KeyKeypad8,
|
||||
[ConfigPhysicalKey.Keypad9] = LocaleKeys.KeyboardLayout_KeyKeypad9,
|
||||
[ConfigPhysicalKey.KeypadDivide] = LocaleKeys.KeyboardLayout_KeyKeypadDivide,
|
||||
[ConfigPhysicalKey.KeypadMultiply] = LocaleKeys.KeyboardLayout_KeyKeypadMultiply,
|
||||
[ConfigPhysicalKey.KeypadSubtract] = LocaleKeys.KeyboardLayout_KeyKeypadSubtract,
|
||||
[ConfigPhysicalKey.KeypadAdd] = LocaleKeys.KeyboardLayout_KeyKeypadAdd,
|
||||
[ConfigPhysicalKey.KeypadDecimal] = LocaleKeys.KeyboardLayout_KeyKeypadDecimal,
|
||||
[ConfigPhysicalKey.KeypadEnter] = LocaleKeys.KeyboardLayout_KeyKeypadEnter,
|
||||
[ConfigPhysicalKey.Unbound] = LocaleKeys.KeyboardLayout_KeyUnbound,
|
||||
};
|
||||
|
||||
public static string GetDisplayString(ConfigPhysicalKey key)
|
||||
{
|
||||
if (_localizedKeysMap.TryGetValue(key, out LocaleKeys localeKey))
|
||||
if (KeyboardLayoutLocaleHelper.TryGetPhysicalLabel(key, out string localizedLabel))
|
||||
{
|
||||
return GetLocalizedString(localeKey);
|
||||
return localizedLabel;
|
||||
}
|
||||
|
||||
if (_observedLayoutLabels.TryGetValue(key, out string observedLabel))
|
||||
@@ -95,7 +43,8 @@ namespace Ryujinx.Ava.UI.Helpers
|
||||
}
|
||||
|
||||
InputKey inputKey = AvaloniaKeyboardMappingHelper.ToInputKey(args.PhysicalKey);
|
||||
if (!TryConvertToConfigPhysicalKey(inputKey, out ConfigPhysicalKey physicalKey) || _localizedKeysMap.ContainsKey(physicalKey))
|
||||
if (!TryConvertToConfigPhysicalKey(inputKey, out ConfigPhysicalKey physicalKey) ||
|
||||
KeyboardLayoutLocaleHelper.TryGetPhysicalLocaleKey(physicalKey, out _))
|
||||
{
|
||||
return;
|
||||
}
|
||||
@@ -169,24 +118,5 @@ namespace Ryujinx.Ava.UI.Helpers
|
||||
physicalKey = ConfigPhysicalKey.Unknown;
|
||||
return false;
|
||||
}
|
||||
|
||||
private static string GetLocalizedString(LocaleKeys localeKey)
|
||||
{
|
||||
if (OperatingSystem.IsMacOS())
|
||||
{
|
||||
localeKey = localeKey switch
|
||||
{
|
||||
LocaleKeys.KeyboardLayout_KeyControlLeft => LocaleKeys.KeyboardLayout_KeyMacControlLeft,
|
||||
LocaleKeys.KeyboardLayout_KeyControlRight => LocaleKeys.KeyboardLayout_KeyMacControlRight,
|
||||
LocaleKeys.KeyboardLayout_KeyAltLeft => LocaleKeys.KeyboardLayout_KeyMacAltLeft,
|
||||
LocaleKeys.KeyboardLayout_KeyAltRight => LocaleKeys.KeyboardLayout_KeyMacAltRight,
|
||||
LocaleKeys.KeyboardLayout_KeyWinLeft => LocaleKeys.KeyboardLayout_KeyMacWinLeft,
|
||||
LocaleKeys.KeyboardLayout_KeyWinRight => LocaleKeys.KeyboardLayout_KeyMacWinRight,
|
||||
_ => localeKey
|
||||
};
|
||||
}
|
||||
|
||||
return LocaleManager.Instance[localeKey];
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -16,9 +16,7 @@ namespace Ryujinx.Ava.UI.Views.Input
|
||||
|
||||
public InputView()
|
||||
{
|
||||
ViewModel = new InputViewModel(this, ConfigurationState.Instance.System.UseInputGlobalConfig);
|
||||
|
||||
InitializeComponent();
|
||||
ReplaceViewModel(ConfigurationState.Instance.System.UseInputGlobalConfig);
|
||||
}
|
||||
|
||||
protected override void OnAttachedToVisualTree(VisualTreeAttachmentEventArgs e)
|
||||
@@ -36,9 +34,18 @@ namespace Ryujinx.Ava.UI.Views.Input
|
||||
public void ToggleLocalGlobalInput(bool enableConfigGlobal)
|
||||
{
|
||||
Dispose();
|
||||
ViewModel = new InputViewModel(this, enableConfigGlobal); // Create new Input Page with global input configs
|
||||
ReplaceViewModel(enableConfigGlobal);
|
||||
}
|
||||
|
||||
private void ReplaceViewModel(bool useGlobalConfig)
|
||||
{
|
||||
ViewModel = new InputViewModel(this, useGlobalConfig); // Create new Input Page with the selected input config scope.
|
||||
InitializeComponent();
|
||||
ViewModel.RetargetKeyboardDriver(this);
|
||||
|
||||
if (VisualRoot is not null)
|
||||
{
|
||||
ViewModel.RetargetKeyboardDriver(this);
|
||||
}
|
||||
}
|
||||
|
||||
private async void PlayerIndexBox_OnSelectionChanged(object sender, SelectionChangedEventArgs e)
|
||||
|
||||
Reference in New Issue
Block a user