1
0
Fork 0
mirror of https://github.com/Ryujinx/Ryujinx.git synced 2024-10-01 12:30:00 +02:00

system: Make index 0 of keyboards in configuration 'all keyboards'

This commit is contained in:
Thog 2020-05-03 15:00:29 +02:00
parent afecb551c5
commit 80d0cc7d6f
7 changed files with 43 additions and 15 deletions

View file

@ -13,7 +13,7 @@ namespace Ryujinx.Configuration
/// <summary>
/// The current version of the file format
/// </summary>
public const int CurrentVersion = 6;
public const int CurrentVersion = 7;
public int Version { get; set; }

View file

@ -556,6 +556,20 @@ namespace Ryujinx.Configuration
configurationFileUpdated = true;
}
// Only needed for version 6 configurations.
if (configurationFileFormat.Version == 6)
{
Common.Logging.Logger.PrintWarning(LogClass.Application, $"Outdated configuration version {configurationFileFormat.Version}, migrating to version 7.");
for (int i = 0; i < configurationFileFormat.KeyboardConfig.Count; i++)
{
if (configurationFileFormat.KeyboardConfig[i].Index != KeyboardConfig.AllKeyboardsIndex)
{
configurationFileFormat.KeyboardConfig[i].Index++;
}
}
}
List<InputConfig> inputConfig = new List<InputConfig>();
foreach (ControllerConfig controllerConfig in configurationFileFormat.ControllerConfig)
{

View file

@ -2,6 +2,9 @@ namespace Ryujinx.Common.Configuration.Hid
{
public class KeyboardConfig : InputConfig
{
// DO NOT MODIFY
public const uint AllKeyboardsIndex = 0;
/// <summary>
/// Left JoyCon Keyboard Bindings
/// </summary>

View file

@ -1,5 +1,5 @@
{
"version": 6,
"version": 7,
"max_anisotropy": -1,
"graphics_shaders_dump_path": "",
"logging_enable_debug": false,

View file

@ -11,6 +11,7 @@ using Ryujinx.HLE.FileSystem;
using GUI = Gtk.Builder.ObjectAttribute;
using Key = Ryujinx.Configuration.Hid.Key;
using Ryujinx.Common.Logging;
namespace Ryujinx.Ui
{
@ -138,10 +139,12 @@ namespace Ryujinx.Ui
_inputDevice.Append("disabled", "Disabled");
_inputDevice.SetActiveId("disabled");
_inputDevice.Append($"keyboard/{KeyboardConfig.AllKeyboardsIndex}", "All keyboards");
for (int i = 0; i < 20; i++)
{
if (Keyboard.GetState(i).IsConnected)
_inputDevice.Append($"keyboard/{i}", $"Keyboard/{i}");
if (KeyboardController.GetKeyboardState(i + 1).IsConnected)
_inputDevice.Append($"keyboard/{i + 1}", $"Keyboard/{i + 1}");
if (GamePad.GetState(i).IsConnected)
_inputDevice.Append($"controller/{i}", $"Controller/{i} ({GamePad.GetName(i)})");
@ -505,9 +508,9 @@ namespace Ryujinx.Ui
return null;
}
private static bool IsAnyKeyPressed(out Key pressedKey, int index = 0)
private static bool IsAnyKeyPressed(out Key pressedKey, int index)
{
KeyboardState keyboardState = Keyboard.GetState(index);
KeyboardState keyboardState = KeyboardController.GetKeyboardState(index);
foreach (Key key in Enum.GetValues(typeof(Key)))
{

View file

@ -12,8 +12,6 @@ namespace Ryujinx.Ui
{
private readonly ControllerConfig _config;
// NOTE: This should be initialized AFTER GTK for compat reasons with OpenTK SDL2 backend and GTK on Linux.
// BODY: Usage of Joystick.GetState must be defer to after GTK full initialization. Otherwise, GTK will segfault because SDL2 was already init *sighs*
public JoystickController(ControllerConfig config)
{
_config = config;
@ -26,6 +24,8 @@ namespace Ryujinx.Ui
public ControllerKeys GetButtons()
{
// NOTE: This should be initialized AFTER GTK for compat reasons with OpenTK SDL2 backend and GTK on Linux.
// BODY: Usage of Joystick.GetState must be defer to after GTK full initialization. Otherwise, GTK will segfault because SDL2 was already init *sighs*
if (!IsEnabled())
{
return 0;

View file

@ -15,16 +15,24 @@ namespace Ryujinx.Ui
{
private readonly KeyboardConfig _config;
// NOTE: This should be initialized AFTER GTK for compat reasons with OpenTK SDL2 backend and GTK on Linux.
// BODY: Usage of Joystick.GetState must be defer to after GTK full initialization. Otherwise, GTK will segfault because SDL2 was already init *sighs*
public KeyboardController(KeyboardConfig config)
{
_config = config;
}
public static KeyboardState GetKeyboardState(int index)
{
if (index == KeyboardConfig.AllKeyboardsIndex || index < 0)
{
return Keyboard.GetState();
}
return Keyboard.GetState(index - 1);
}
public ControllerKeys GetButtons()
{
KeyboardState keyboard = Keyboard.GetState(_config.Index);
KeyboardState keyboard = GetKeyboardState(_config.Index);
ControllerKeys buttons = 0;
@ -55,7 +63,7 @@ namespace Ryujinx.Ui
public (short, short) GetLeftStick()
{
KeyboardState keyboard = Keyboard.GetState(_config.Index);
KeyboardState keyboard = GetKeyboardState(_config.Index);
short dx = 0;
short dy = 0;
@ -70,7 +78,7 @@ namespace Ryujinx.Ui
public (short, short) GetRightStick()
{
KeyboardState keyboard = Keyboard.GetState(_config.Index);
KeyboardState keyboard = GetKeyboardState(_config.Index);
short dx = 0;
short dy = 0;
@ -85,7 +93,7 @@ namespace Ryujinx.Ui
public HotkeyButtons GetHotkeyButtons()
{
KeyboardState keyboard = Keyboard.GetState(_config.Index);
KeyboardState keyboard = GetKeyboardState(_config.Index);
HotkeyButtons buttons = 0;
@ -246,7 +254,7 @@ namespace Ryujinx.Ui
public KeyboardInput GetKeysDown()
{
KeyboardState keyboard = Keyboard.GetState(_config.Index);
KeyboardState keyboard = GetKeyboardState(_config.Index);
KeyboardInput hidKeyboard = new KeyboardInput
{