From 80d0cc7d6fd57ee888649a31d162f96fed9bd082 Mon Sep 17 00:00:00 2001 From: Thog Date: Sun, 3 May 2020 15:00:29 +0200 Subject: [PATCH] system: Make index 0 of keyboards in configuration 'all keyboards' --- .../Configuration/ConfigurationFileFormat.cs | 2 +- .../Configuration/ConfigurationState.cs | 14 ++++++++++++ .../Configuration/Hid/KeyboardConfig.cs | 3 +++ Ryujinx/Config.json | 2 +- Ryujinx/Ui/ControllerWindow.cs | 11 ++++++---- Ryujinx/Ui/JoystickController.cs | 4 ++-- Ryujinx/Ui/KeyboardController.cs | 22 +++++++++++++------ 7 files changed, 43 insertions(+), 15 deletions(-) diff --git a/Ryujinx.Common/Configuration/ConfigurationFileFormat.cs b/Ryujinx.Common/Configuration/ConfigurationFileFormat.cs index 09252b773..db542ad7b 100644 --- a/Ryujinx.Common/Configuration/ConfigurationFileFormat.cs +++ b/Ryujinx.Common/Configuration/ConfigurationFileFormat.cs @@ -13,7 +13,7 @@ namespace Ryujinx.Configuration /// /// The current version of the file format /// - public const int CurrentVersion = 6; + public const int CurrentVersion = 7; public int Version { get; set; } diff --git a/Ryujinx.Common/Configuration/ConfigurationState.cs b/Ryujinx.Common/Configuration/ConfigurationState.cs index a994e6d57..d0a00cb51 100644 --- a/Ryujinx.Common/Configuration/ConfigurationState.cs +++ b/Ryujinx.Common/Configuration/ConfigurationState.cs @@ -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 = new List(); foreach (ControllerConfig controllerConfig in configurationFileFormat.ControllerConfig) { diff --git a/Ryujinx.Common/Configuration/Hid/KeyboardConfig.cs b/Ryujinx.Common/Configuration/Hid/KeyboardConfig.cs index 664fdff08..7dfbcb87e 100644 --- a/Ryujinx.Common/Configuration/Hid/KeyboardConfig.cs +++ b/Ryujinx.Common/Configuration/Hid/KeyboardConfig.cs @@ -2,6 +2,9 @@ namespace Ryujinx.Common.Configuration.Hid { public class KeyboardConfig : InputConfig { + // DO NOT MODIFY + public const uint AllKeyboardsIndex = 0; + /// /// Left JoyCon Keyboard Bindings /// diff --git a/Ryujinx/Config.json b/Ryujinx/Config.json index c5d08f9fb..2479d2d5e 100644 --- a/Ryujinx/Config.json +++ b/Ryujinx/Config.json @@ -1,5 +1,5 @@ { - "version": 6, + "version": 7, "max_anisotropy": -1, "graphics_shaders_dump_path": "", "logging_enable_debug": false, diff --git a/Ryujinx/Ui/ControllerWindow.cs b/Ryujinx/Ui/ControllerWindow.cs index 065417430..06a78ecec 100644 --- a/Ryujinx/Ui/ControllerWindow.cs +++ b/Ryujinx/Ui/ControllerWindow.cs @@ -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))) { diff --git a/Ryujinx/Ui/JoystickController.cs b/Ryujinx/Ui/JoystickController.cs index f5d7450ab..3ced101ab 100644 --- a/Ryujinx/Ui/JoystickController.cs +++ b/Ryujinx/Ui/JoystickController.cs @@ -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; diff --git a/Ryujinx/Ui/KeyboardController.cs b/Ryujinx/Ui/KeyboardController.cs index ed4a4b3fe..efa7bf566 100644 --- a/Ryujinx/Ui/KeyboardController.cs +++ b/Ryujinx/Ui/KeyboardController.cs @@ -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 {