From 6cb22c9d38622225f9f787f483bd73369774cf77 Mon Sep 17 00:00:00 2001 From: Mary Date: Wed, 14 Apr 2021 12:28:43 +0200 Subject: [PATCH] Miria: The Death of OpenTK 3 (#2194) * openal: Update to OpenTK 4 * Ryujinx.Graphics.OpenGL: Update to OpenTK 4 * Entirely removed OpenTK 3, still wip * Use SPB for context creation and handling Still need to test on GLX and readd input support * Start implementing a new input system So far only gamepad are supported, no configuration possible via UI but detected via hotplug/removal Button mapping backend is implemented TODO: front end, configuration handling and configuration migration TODO: keyboard support * Enforce RGB only framebuffer on the GLWidget Fix possible transparent window * Implement UI gamepad frontend Also fix bad mapping of minus button and ensure gamepad config is updated in real time * Handle controller being disconnected and reconnected again * Revert "Enforce RGB only framebuffer on the GLWidget" This reverts commit 0949715d1a03ec793e35e37f7b610cbff2d63965. * Fix first color clear * Filter SDL2 events a bit * Start working on the keyboard detail - Rework configuration classes a bit to be more clean. - Integrate fully the keyboard configuration to the front end (TODO: assigner) - Start skeleton for the GTK3 keyboard driver * Add KeyboardStateSnapshot and its integration * Implement keyboard assigner and GTK3 key mapping TODO: controller configuration mapping and IGamepad implementation for keyboard * Add missing SR and SL definitions * Fix copy pasta mistake on config for previous commit * Implement IGamepad interface for GTK3 keyboard * Fix some implementation still being commented in the controller ui for keyboard * Port screen handle code * Remove all configuration management code and move HidNew to Hid * Rename InputConfigNew to InputConfig * Add a version field to the input config * Prepare serialization and deserialization of new input config and migrate profile loading and saving * Support input configuration saving to config and bump config version to 23. * Clean up in ConfigurationState * Reference SPB via a nuget package * Move new input system to Ryujinx.Input project and SDL2 detail to Ryujinx.Input.SDL2 * move GTK3 input to the right directory * Fix triggers on SDL2 * Update to SDL2 2.0.14 via our own fork * Update buttons definition for SDL2 2.0.14 and report gamepad features * Implement motion support again with SDL2 TODO: cemu hooks integration * Switch to latest of nightly SDL2 * SDL2: Fix bugs in gamepad id matching allowing different gamepad to match on the same device index * Ensure values are set in UI when the gamepad get hot plugged * Avoid trying to add controllers in the Update method and don't open SDL2 gamepad instance before checking ids This fixes permanent rumble of pro controller in some hotplug scenario * Fix more UI bugs * Move legcay motion code around before reintegration * gamecontroller UI tweaks here and there * Hide Motion on non motion configurations * Update the TODO grave Some TODO were fixed long time ago or are quite oudated... * Integrate cemu hooks motion configuration * Integrate cemu hooks configuration options to the UI again * cemuhooks => cemuhooks * Add cemu hook support again * Fix regression on normal motion and fix some very nasty bugs around * Fix for XCB multithreads issue on Linux * Enable motion by default * Block inputs in the main view when in the controller configuration window * Some fixes for the controller ui again * Add joycon support and fixes other hints * Bug fixes and clean up - Invert default mapping if not a Nintendo controller - Keep alive the controller being selected on the controller window (allow to avoid big delay for controller needing time to init when doing button assignment) - Clean up hints in use - Remove debug logs around - Fixes potential double free with SDL2Gamepad * Move the button assigner and motion logic to the Ryujinx.Input project * Reimplement raw keyboard hle input Also move out the logic of the hotkeys * Move all remaining Input manager stuffs to the Ryujinx.Input project * Increment configuration version yet again because of master changes * Ensure input config isn't null when not present * Fixes for VS not being nice * Fix broken gamepad caching logic causing crashes on ui * Ensure the background context is destroyed * Update dependencies * Readd retrocompat with old format of the config to avoid parsing and crashes on those versions Also updated the debug Config.json * Document new input APIs * Isolate SDL2Driver to the project and remove external export of it * Add support for external gamepad db mappings on SDL2 * Last clean up before PR * Addresses first part of comments * Address gdkchan's comments * Do not use JsonException * Last comment fixes --- .../OpenALHardwareDeviceDriver.cs | 17 +- .../OpenALHardwareDeviceSession.cs | 8 +- .../Ryujinx.Audio.Backends.OpenAL.csproj | 2 +- .../Configuration/ConfigurationFileFormat.cs | 19 +- .../Configuration/ConfigurationState.cs | 266 +++--- .../Hid/Controller/GamepadInputId.cs | 54 ++ .../GenericControllerInputConfig.cs | 37 + .../Controller/JoyconConfigControllerStick.cs | 10 + .../Motion/CemuHookMotionConfigController.cs | 30 + .../JsonMotionConfigControllerConverter.cs | 76 ++ .../Motion/MotionConfigController.cs | 22 + .../Motion/MotionInputBackendType.cs | 9 + .../Motion/StandardMotionConfigController.cs | 4 + .../StandardControllerInputConfig.cs | 4 + .../Hid/Controller/StickInputId.cs | 11 + .../Configuration/Hid/ControllerConfig.cs | 30 - .../Configuration/Hid/ControllerInputId.cs | 46 - .../Hid/GenericInputConfigurationCommon.cs | 15 + .../Configuration/Hid/InputBackendType.cs | 9 + .../Configuration/Hid/InputConfig.cs | 57 +- .../Hid/JsonInputConfigConverter.cs | 78 ++ Ryujinx.Common/Configuration/Hid/Key.cs | 283 +++--- .../Keyboard/GenericKeyboardInputConfig.cs | 15 + .../Hid/Keyboard/JoyconConfigKeyboardStick.cs | 11 + .../Keyboard/StandardKeyboardInputConfig.cs | 4 + .../Configuration/Hid/KeyboardConfig.cs | 18 - .../Configuration/Hid/KeyboardHotkeys.cs | 4 +- .../Hid/LeftJoyconCommonConfig.cs | 15 + .../Configuration/Hid/NpadControllerLeft.cs | 20 - .../Configuration/Hid/NpadControllerRight.cs | 20 - .../Configuration/Hid/NpadKeyboardLeft.cs | 22 - .../Configuration/Hid/NpadKeyboardRight.cs | 22 - .../Hid/RightJoyconCommonConfig.cs | 15 + Ryujinx.Common/Utilities/JsonHelper.cs | 6 +- .../BackgroundContextWorker.cs | 29 +- Ryujinx.Graphics.OpenGL/Helper/GLXHelper.cs | 36 + Ryujinx.Graphics.OpenGL/Helper/WGLHelper.cs | 15 + Ryujinx.Graphics.OpenGL/IOpenGLContext.cs | 27 + Ryujinx.Graphics.OpenGL/Renderer.cs | 4 +- .../Ryujinx.Graphics.OpenGL.csproj | 2 +- Ryujinx.Graphics.OpenGL/Window.cs | 4 +- Ryujinx.Input.SDL2/Ryujinx.Input.SDL2.csproj | 16 + Ryujinx.Input.SDL2/SDL2Driver.cs | 170 ++++ Ryujinx.Input.SDL2/SDL2Gamepad.cs | 366 ++++++++ Ryujinx.Input.SDL2/SDL2GamepadDriver.cs | 138 +++ .../Assigner/GamepadButtonAssigner.cs | 198 ++++ Ryujinx.Input/Assigner/IButtonAssigner.cs | 36 + Ryujinx.Input/Assigner/KeyboardKeyAssigner.cs | 50 + Ryujinx.Input/GamepadButtonInputId.cs | 57 ++ Ryujinx.Input/GamepadFeaturesFlag.cs | 28 + Ryujinx.Input/GamepadStateSnapshot.cs | 70 ++ Ryujinx.Input/HLE/InputManager.cs | 35 + Ryujinx.Input/HLE/NpadController.cs | 496 ++++++++++ Ryujinx.Input/HLE/NpadManager.cs | 222 +++++ Ryujinx.Input/IGamepad.cs | 122 +++ Ryujinx.Input/IGamepadDriver.cs | 37 + Ryujinx.Input/IKeyboard.cs | 41 + Ryujinx.Input/Key.cs | 142 +++ Ryujinx.Input/KeyboardStateSnapshot.cs | 29 + .../Motion/CemuHook}/Client.cs | 44 +- .../CemuHook}/Protocol/ControllerData.cs | 2 +- .../CemuHook}/Protocol/ControllerInfo.cs | 2 +- .../Motion/CemuHook}/Protocol/Header.cs | 2 +- .../Motion/CemuHook}/Protocol/MessageType.cs | 2 +- .../CemuHook}/Protocol/SharedResponse.cs | 2 +- .../Motion/MotionInput.cs | 5 +- .../Motion/MotionSensorFilter.cs | 4 +- Ryujinx.Input/MotionInputId.cs | 25 + Ryujinx.Input/Ryujinx.Input.csproj | 17 + Ryujinx.Input/StickInputId.cs | 14 + Ryujinx.sln | 12 + Ryujinx/Config.json | 69 +- Ryujinx/Input/GTK3/GTK3Keyboard.cs | 204 +++++ Ryujinx/Input/GTK3/GTK3KeyboardDriver.cs | 93 ++ Ryujinx/Input/GTK3/GTK3MappingHelper.cs | 154 ++++ Ryujinx/Modules/Motion/MotionDevice.cs | 81 -- Ryujinx/Program.cs | 17 +- Ryujinx/Ryujinx.csproj | 7 +- Ryujinx/Ui/GLRenderer.cs | 252 ++--- Ryujinx/Ui/GLWidget.cs | 118 +++ Ryujinx/Ui/Input/ButtonAssigner.cs | 17 - Ryujinx/Ui/Input/JoystickButtonAssigner.cs | 227 ----- Ryujinx/Ui/Input/KeyboardKeyAssigner.cs | 51 -- Ryujinx/Ui/JoystickController.cs | 149 --- Ryujinx/Ui/KeyboardController.cs | 291 ------ Ryujinx/Ui/MainWindow.cs | 13 +- Ryujinx/Ui/OpenToolkitBindingsContext.cs | 20 + Ryujinx/Ui/SPBOpenGLContext.cs | 49 + Ryujinx/Ui/Windows/ControllerWindow.cs | 865 +++++++++++------- Ryujinx/Ui/Windows/ControllerWindow.glade | 125 +-- Ryujinx/Ui/Windows/SettingsWindow.cs | 2 +- 91 files changed, 4516 insertions(+), 2048 deletions(-) create mode 100644 Ryujinx.Common/Configuration/Hid/Controller/GamepadInputId.cs create mode 100644 Ryujinx.Common/Configuration/Hid/Controller/GenericControllerInputConfig.cs create mode 100644 Ryujinx.Common/Configuration/Hid/Controller/JoyconConfigControllerStick.cs create mode 100644 Ryujinx.Common/Configuration/Hid/Controller/Motion/CemuHookMotionConfigController.cs create mode 100644 Ryujinx.Common/Configuration/Hid/Controller/Motion/JsonMotionConfigControllerConverter.cs create mode 100644 Ryujinx.Common/Configuration/Hid/Controller/Motion/MotionConfigController.cs create mode 100644 Ryujinx.Common/Configuration/Hid/Controller/Motion/MotionInputBackendType.cs create mode 100644 Ryujinx.Common/Configuration/Hid/Controller/Motion/StandardMotionConfigController.cs create mode 100644 Ryujinx.Common/Configuration/Hid/Controller/StandardControllerInputConfig.cs create mode 100644 Ryujinx.Common/Configuration/Hid/Controller/StickInputId.cs delete mode 100644 Ryujinx.Common/Configuration/Hid/ControllerConfig.cs delete mode 100644 Ryujinx.Common/Configuration/Hid/ControllerInputId.cs create mode 100644 Ryujinx.Common/Configuration/Hid/GenericInputConfigurationCommon.cs create mode 100644 Ryujinx.Common/Configuration/Hid/InputBackendType.cs create mode 100644 Ryujinx.Common/Configuration/Hid/JsonInputConfigConverter.cs create mode 100644 Ryujinx.Common/Configuration/Hid/Keyboard/GenericKeyboardInputConfig.cs create mode 100644 Ryujinx.Common/Configuration/Hid/Keyboard/JoyconConfigKeyboardStick.cs create mode 100644 Ryujinx.Common/Configuration/Hid/Keyboard/StandardKeyboardInputConfig.cs delete mode 100644 Ryujinx.Common/Configuration/Hid/KeyboardConfig.cs create mode 100644 Ryujinx.Common/Configuration/Hid/LeftJoyconCommonConfig.cs delete mode 100644 Ryujinx.Common/Configuration/Hid/NpadControllerLeft.cs delete mode 100644 Ryujinx.Common/Configuration/Hid/NpadControllerRight.cs delete mode 100644 Ryujinx.Common/Configuration/Hid/NpadKeyboardLeft.cs delete mode 100644 Ryujinx.Common/Configuration/Hid/NpadKeyboardRight.cs create mode 100644 Ryujinx.Common/Configuration/Hid/RightJoyconCommonConfig.cs create mode 100644 Ryujinx.Graphics.OpenGL/Helper/GLXHelper.cs create mode 100644 Ryujinx.Graphics.OpenGL/Helper/WGLHelper.cs create mode 100644 Ryujinx.Graphics.OpenGL/IOpenGLContext.cs create mode 100644 Ryujinx.Input.SDL2/Ryujinx.Input.SDL2.csproj create mode 100644 Ryujinx.Input.SDL2/SDL2Driver.cs create mode 100644 Ryujinx.Input.SDL2/SDL2Gamepad.cs create mode 100644 Ryujinx.Input.SDL2/SDL2GamepadDriver.cs create mode 100644 Ryujinx.Input/Assigner/GamepadButtonAssigner.cs create mode 100644 Ryujinx.Input/Assigner/IButtonAssigner.cs create mode 100644 Ryujinx.Input/Assigner/KeyboardKeyAssigner.cs create mode 100644 Ryujinx.Input/GamepadButtonInputId.cs create mode 100644 Ryujinx.Input/GamepadFeaturesFlag.cs create mode 100644 Ryujinx.Input/GamepadStateSnapshot.cs create mode 100644 Ryujinx.Input/HLE/InputManager.cs create mode 100644 Ryujinx.Input/HLE/NpadController.cs create mode 100644 Ryujinx.Input/HLE/NpadManager.cs create mode 100644 Ryujinx.Input/IGamepad.cs create mode 100644 Ryujinx.Input/IGamepadDriver.cs create mode 100644 Ryujinx.Input/IKeyboard.cs create mode 100644 Ryujinx.Input/Key.cs create mode 100644 Ryujinx.Input/KeyboardStateSnapshot.cs rename {Ryujinx/Modules/Motion => Ryujinx.Input/Motion/CemuHook}/Client.cs (88%) rename {Ryujinx/Modules/Motion => Ryujinx.Input/Motion/CemuHook}/Protocol/ControllerData.cs (96%) rename {Ryujinx/Modules/Motion => Ryujinx.Input/Motion/CemuHook}/Protocol/ControllerInfo.cs (91%) rename {Ryujinx/Modules/Motion => Ryujinx.Input/Motion/CemuHook}/Protocol/Header.cs (85%) rename {Ryujinx/Modules/Motion => Ryujinx.Input/Motion/CemuHook}/Protocol/MessageType.cs (67%) rename {Ryujinx/Modules/Motion => Ryujinx.Input/Motion/CemuHook}/Protocol/SharedResponse.cs (95%) rename {Ryujinx/Modules => Ryujinx.Input}/Motion/MotionInput.cs (97%) rename {Ryujinx/Modules => Ryujinx.Input}/Motion/MotionSensorFilter.cs (98%) create mode 100644 Ryujinx.Input/MotionInputId.cs create mode 100644 Ryujinx.Input/Ryujinx.Input.csproj create mode 100644 Ryujinx.Input/StickInputId.cs create mode 100644 Ryujinx/Input/GTK3/GTK3Keyboard.cs create mode 100644 Ryujinx/Input/GTK3/GTK3KeyboardDriver.cs create mode 100644 Ryujinx/Input/GTK3/GTK3MappingHelper.cs delete mode 100644 Ryujinx/Modules/Motion/MotionDevice.cs create mode 100644 Ryujinx/Ui/GLWidget.cs delete mode 100644 Ryujinx/Ui/Input/ButtonAssigner.cs delete mode 100644 Ryujinx/Ui/Input/JoystickButtonAssigner.cs delete mode 100644 Ryujinx/Ui/Input/KeyboardKeyAssigner.cs delete mode 100644 Ryujinx/Ui/JoystickController.cs delete mode 100644 Ryujinx/Ui/KeyboardController.cs create mode 100644 Ryujinx/Ui/OpenToolkitBindingsContext.cs create mode 100644 Ryujinx/Ui/SPBOpenGLContext.cs diff --git a/Ryujinx.Audio.Backends.OpenAL/OpenALHardwareDeviceDriver.cs b/Ryujinx.Audio.Backends.OpenAL/OpenALHardwareDeviceDriver.cs index 43f238ef..387ae772 100644 --- a/Ryujinx.Audio.Backends.OpenAL/OpenALHardwareDeviceDriver.cs +++ b/Ryujinx.Audio.Backends.OpenAL/OpenALHardwareDeviceDriver.cs @@ -1,9 +1,10 @@ -using OpenTK.Audio; +using OpenTK.Audio.OpenAL; using Ryujinx.Audio.Common; using Ryujinx.Audio.Integration; using Ryujinx.Memory; using System; using System.Collections.Generic; +using System.Linq; using System.Threading; using static Ryujinx.Audio.Integration.IHardwareDeviceDriver; @@ -12,8 +13,8 @@ namespace Ryujinx.Audio.Backends.OpenAL public class OpenALHardwareDeviceDriver : IHardwareDeviceDriver { private object _lock = new object(); - - private AudioContext _context; + private ALDevice _device; + private ALContext _context; private ManualResetEvent _updateRequiredEvent; private List _sessions; private bool _stillRunning; @@ -21,7 +22,8 @@ namespace Ryujinx.Audio.Backends.OpenAL public OpenALHardwareDeviceDriver() { - _context = new AudioContext(); + _device = ALC.OpenDevice(""); + _context = ALC.CreateContext(_device, new ALContextAttributes()); _updateRequiredEvent = new ManualResetEvent(false); _sessions = new List(); @@ -40,7 +42,7 @@ namespace Ryujinx.Audio.Backends.OpenAL { try { - return AudioContext.AvailableDevices.Count > 0; + return ALC.GetStringList(GetEnumerationStringList.DeviceSpecifier).Any(); } catch { @@ -95,6 +97,8 @@ namespace Ryujinx.Audio.Backends.OpenAL private void Update() { + ALC.MakeContextCurrent(_context); + while (_stillRunning) { bool updateRequired = false; @@ -143,7 +147,8 @@ namespace Ryujinx.Audio.Backends.OpenAL } } - _context.Dispose(); + ALC.DestroyContext(_context); + ALC.CloseDevice(_device); } } diff --git a/Ryujinx.Audio.Backends.OpenAL/OpenALHardwareDeviceSession.cs b/Ryujinx.Audio.Backends.OpenAL/OpenALHardwareDeviceSession.cs index 055c608b..f0227bf8 100644 --- a/Ryujinx.Audio.Backends.OpenAL/OpenALHardwareDeviceSession.cs +++ b/Ryujinx.Audio.Backends.OpenAL/OpenALHardwareDeviceSession.cs @@ -71,11 +71,11 @@ namespace Ryujinx.Audio.Backends.OpenAL OpenALAudioBuffer driverBuffer = new OpenALAudioBuffer { DriverIdentifier = buffer.DataPointer, - BufferId = AL.GenBuffer(), - SampleCount = GetSampleCount(buffer) + BufferId = AL.GenBuffer(), + SampleCount = GetSampleCount(buffer) }; - AL.BufferData(driverBuffer.BufferId, _targetFormat, buffer.Data, (int)buffer.DataSize, (int)RequestedSampleRate); + AL.BufferData(driverBuffer.BufferId, _targetFormat, buffer.Data, (int)RequestedSampleRate); _queuedBuffers.Enqueue(driverBuffer); @@ -125,7 +125,7 @@ namespace Ryujinx.Audio.Backends.OpenAL } } - public override void UnregisterBuffer(AudioBuffer buffer) {} + public override void UnregisterBuffer(AudioBuffer buffer) { } public override bool WasBufferFullyConsumed(AudioBuffer buffer) { diff --git a/Ryujinx.Audio.Backends.OpenAL/Ryujinx.Audio.Backends.OpenAL.csproj b/Ryujinx.Audio.Backends.OpenAL/Ryujinx.Audio.Backends.OpenAL.csproj index 187fe0fe..4619d73d 100644 --- a/Ryujinx.Audio.Backends.OpenAL/Ryujinx.Audio.Backends.OpenAL.csproj +++ b/Ryujinx.Audio.Backends.OpenAL/Ryujinx.Audio.Backends.OpenAL.csproj @@ -5,7 +5,7 @@ - + diff --git a/Ryujinx.Common/Configuration/ConfigurationFileFormat.cs b/Ryujinx.Common/Configuration/ConfigurationFileFormat.cs index 32e76375..1d47051a 100644 --- a/Ryujinx.Common/Configuration/ConfigurationFileFormat.cs +++ b/Ryujinx.Common/Configuration/ConfigurationFileFormat.cs @@ -14,7 +14,7 @@ namespace Ryujinx.Configuration /// /// The current version of the file format /// - public const int CurrentVersion = 23; + public const int CurrentVersion = 24; public int Version { get; set; } @@ -224,14 +224,23 @@ namespace Ryujinx.Configuration public KeyboardHotkeys Hotkeys { get; set; } /// - /// Keyboard control bindings + /// Legacy keyboard control bindings /// - public List KeyboardConfig { get; set; } + /// Kept for file format compatibility (to avoid possible failure when parsing configuration on old versions) + /// TODO: Remove this when those older versions aren't in use anymore. + public List KeyboardConfig { get; set; } /// - /// Controller control bindings + /// Legacy controller control bindings /// - public List ControllerConfig { get; set; } + /// Kept for file format compatibility (to avoid possible failure when parsing configuration on old versions) + /// TODO: Remove this when those older versions aren't in use anymore. + public List ControllerConfig { get; set; } + + /// + /// Input configurations + /// + public List InputConfig { get; set; } /// /// Loads a configuration file from disk diff --git a/Ryujinx.Common/Configuration/ConfigurationState.cs b/Ryujinx.Common/Configuration/ConfigurationState.cs index 1e26b4f4..7063110f 100644 --- a/Ryujinx.Common/Configuration/ConfigurationState.cs +++ b/Ryujinx.Common/Configuration/ConfigurationState.cs @@ -1,8 +1,8 @@ using Ryujinx.Common; using Ryujinx.Common.Configuration; using Ryujinx.Common.Configuration.Hid; +using Ryujinx.Common.Configuration.Hid.Keyboard; using Ryujinx.Common.Logging; -using Ryujinx.Configuration.Hid; using Ryujinx.Configuration.System; using Ryujinx.Configuration.Ui; using System; @@ -405,21 +405,6 @@ namespace Ryujinx.Configuration public ConfigurationFileFormat ToFileFormat() { - List controllerConfigList = new List(); - List keyboardConfigList = new List(); - - foreach (InputConfig inputConfig in Hid.InputConfig.Value) - { - if (inputConfig is ControllerConfig controllerConfig) - { - controllerConfigList.Add(controllerConfig); - } - else if (inputConfig is KeyboardConfig keyboardConfig) - { - keyboardConfigList.Add(keyboardConfig); - } - } - ConfigurationFileFormat configurationFile = new ConfigurationFileFormat { Version = ConfigurationFileFormat.CurrentVersion, @@ -479,8 +464,9 @@ namespace Ryujinx.Configuration StartFullscreen = Ui.StartFullscreen, EnableKeyboard = Hid.EnableKeyboard, Hotkeys = Hid.Hotkeys, - KeyboardConfig = keyboardConfigList, - ControllerConfig = controllerConfigList + KeyboardConfig = new List(), + ControllerConfig = new List(), + InputConfig = Hid.InputConfig, }; return configurationFile; @@ -543,54 +529,57 @@ namespace Ryujinx.Configuration }; Hid.InputConfig.Value = new List { - new KeyboardConfig - { - Index = 0, - ControllerType = ControllerType.JoyconPair, - PlayerIndex = PlayerIndex.Player1, - LeftJoycon = new NpadKeyboardLeft - { - StickUp = Key.W, - StickDown = Key.S, - StickLeft = Key.A, - StickRight = Key.D, - StickButton = Key.F, - DPadUp = Key.Up, - DPadDown = Key.Down, - DPadLeft = Key.Left, - DPadRight = Key.Right, - ButtonMinus = Key.Minus, - ButtonL = Key.E, - ButtonZl = Key.Q, - ButtonSl = Key.Home, - ButtonSr = Key.End - }, - RightJoycon = new NpadKeyboardRight - { - StickUp = Key.I, - StickDown = Key.K, - StickLeft = Key.J, - StickRight = Key.L, - StickButton = Key.H, - ButtonA = Key.Z, - ButtonB = Key.X, - ButtonX = Key.C, - ButtonY = Key.V, - ButtonPlus = Key.Plus, - ButtonR = Key.U, - ButtonZr = Key.O, - ButtonSl = Key.PageUp, - ButtonSr = Key.PageDown - }, - EnableMotion = false, - MirrorInput = false, - Slot = 0, - AltSlot = 0, - Sensitivity = 100, - GyroDeadzone = 1, - DsuServerHost = "127.0.0.1", - DsuServerPort = 26760 - } + new StandardKeyboardInputConfig + { + Version = InputConfig.CurrentVersion, + Backend = InputBackendType.WindowKeyboard, + Id = "0", + PlayerIndex = PlayerIndex.Player1, + ControllerType = ControllerType.JoyconPair, + LeftJoycon = new LeftJoyconCommonConfig + { + DpadUp = Key.Up, + DpadDown = Key.Down, + DpadLeft = Key.Left, + DpadRight = Key.Right, + ButtonMinus = Key.Minus, + ButtonL = Key.E, + ButtonZl = Key.Q, + ButtonSl = Key.Unbound, + ButtonSr = Key.Unbound + }, + + LeftJoyconStick = new JoyconConfigKeyboardStick + { + StickUp = Key.W, + StickDown = Key.S, + StickLeft = Key.A, + StickRight = Key.D, + StickButton = Key.F, + }, + + RightJoycon = new RightJoyconCommonConfig + { + ButtonA = Key.Z, + ButtonB = Key.X, + ButtonX = Key.C, + ButtonY = Key.V, + ButtonPlus = Key.Plus, + ButtonR = Key.U, + ButtonZr = Key.O, + ButtonSl = Key.Unbound, + ButtonSr = Key.Unbound + }, + + RightJoyconStick = new JoyconConfigKeyboardStick + { + StickUp = Key.I, + StickDown = Key.K, + StickLeft = Key.J, + StickRight = Key.L, + StickButton = Key.H, + } + } }; } @@ -643,80 +632,6 @@ namespace Ryujinx.Configuration configurationFileUpdated = true; } - if (configurationFileFormat.Version < 6) - { - Common.Logging.Logger.Warning?.Print(LogClass.Application, $"Outdated configuration version {configurationFileFormat.Version}, migrating to version 6."); - - configurationFileFormat.ControllerConfig = new List(); - configurationFileFormat.KeyboardConfig = new List - { - new KeyboardConfig - { - Index = 0, - ControllerType = ControllerType.JoyconPair, - PlayerIndex = PlayerIndex.Player1, - LeftJoycon = new NpadKeyboardLeft - { - StickUp = Key.W, - StickDown = Key.S, - StickLeft = Key.A, - StickRight = Key.D, - StickButton = Key.F, - DPadUp = Key.Up, - DPadDown = Key.Down, - DPadLeft = Key.Left, - DPadRight = Key.Right, - ButtonMinus = Key.Minus, - ButtonL = Key.E, - ButtonZl = Key.Q, - ButtonSl = Key.Unbound, - ButtonSr = Key.Unbound - }, - RightJoycon = new NpadKeyboardRight - { - StickUp = Key.I, - StickDown = Key.K, - StickLeft = Key.J, - StickRight = Key.L, - StickButton = Key.H, - ButtonA = Key.Z, - ButtonB = Key.X, - ButtonX = Key.C, - ButtonY = Key.V, - ButtonPlus = Key.Plus, - ButtonR = Key.U, - ButtonZr = Key.O, - ButtonSl = Key.Unbound, - ButtonSr = Key.Unbound - }, - EnableMotion = false, - MirrorInput = false, - Slot = 0, - AltSlot = 0, - Sensitivity = 100, - GyroDeadzone = 1, - DsuServerHost = "127.0.0.1", - DsuServerPort = 26760 - } - }; - - configurationFileUpdated = true; - } - - // Only needed for version 6 configurations. - if (configurationFileFormat.Version == 6) - { - Common.Logging.Logger.Warning?.Print(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++; - } - } - } - if (configurationFileFormat.Version < 8) { Common.Logging.Logger.Warning?.Print(LogClass.Application, $"Outdated configuration version {configurationFileFormat.Version}, migrating to version 8."); @@ -826,9 +741,67 @@ namespace Ryujinx.Configuration configurationFileUpdated = true; } - List inputConfig = new List(); - inputConfig.AddRange(configurationFileFormat.ControllerConfig); - inputConfig.AddRange(configurationFileFormat.KeyboardConfig); + if (configurationFileFormat.Version < 24) + { + Common.Logging.Logger.Warning?.Print(LogClass.Application, $"Outdated configuration version {configurationFileFormat.Version}, migrating to version 24."); + + configurationFileFormat.InputConfig = new List + { + new StandardKeyboardInputConfig + { + Version = InputConfig.CurrentVersion, + Backend = InputBackendType.WindowKeyboard, + Id = "0", + PlayerIndex = PlayerIndex.Player1, + ControllerType = ControllerType.JoyconPair, + LeftJoycon = new LeftJoyconCommonConfig + { + DpadUp = Key.Up, + DpadDown = Key.Down, + DpadLeft = Key.Left, + DpadRight = Key.Right, + ButtonMinus = Key.Minus, + ButtonL = Key.E, + ButtonZl = Key.Q, + ButtonSl = Key.Unbound, + ButtonSr = Key.Unbound + }, + + LeftJoyconStick = new JoyconConfigKeyboardStick + { + StickUp = Key.W, + StickDown = Key.S, + StickLeft = Key.A, + StickRight = Key.D, + StickButton = Key.F, + }, + + RightJoycon = new RightJoyconCommonConfig + { + ButtonA = Key.Z, + ButtonB = Key.X, + ButtonX = Key.C, + ButtonY = Key.V, + ButtonPlus = Key.Plus, + ButtonR = Key.U, + ButtonZr = Key.O, + ButtonSl = Key.Unbound, + ButtonSr = Key.Unbound + }, + + RightJoyconStick = new JoyconConfigKeyboardStick + { + StickUp = Key.I, + StickDown = Key.K, + StickLeft = Key.J, + StickRight = Key.L, + StickButton = Key.H, + } + } + }; + + configurationFileUpdated = true; + } Graphics.ResScale.Value = configurationFileFormat.ResScale; Graphics.ResScaleCustom.Value = configurationFileFormat.ResScaleCustom; @@ -880,7 +853,12 @@ namespace Ryujinx.Configuration Ui.StartFullscreen.Value = configurationFileFormat.StartFullscreen; Hid.EnableKeyboard.Value = configurationFileFormat.EnableKeyboard; Hid.Hotkeys.Value = configurationFileFormat.Hotkeys; - Hid.InputConfig.Value = inputConfig; + Hid.InputConfig.Value = configurationFileFormat.InputConfig; + + if (Hid.InputConfig.Value == null) + { + Hid.InputConfig.Value = new List(); + } if (configurationFileUpdated) { diff --git a/Ryujinx.Common/Configuration/Hid/Controller/GamepadInputId.cs b/Ryujinx.Common/Configuration/Hid/Controller/GamepadInputId.cs new file mode 100644 index 00000000..cae65fc9 --- /dev/null +++ b/Ryujinx.Common/Configuration/Hid/Controller/GamepadInputId.cs @@ -0,0 +1,54 @@ +namespace Ryujinx.Common.Configuration.Hid.Controller +{ + public enum GamepadInputId : byte + { + Unbound, + A, + B, + X, + Y, + LeftStick, + RightStick, + LeftShoulder, + RightShoulder, + + // Likely axis + LeftTrigger, + // Likely axis + RightTrigger, + + DpadUp, + DpadDown, + DpadLeft, + DpadRight, + + // Special buttons + + Minus, + Plus, + + Back = Minus, + Start = Plus, + + Guide, + Misc1, + + // Xbox Elite paddle + Paddle1, + Paddle2, + Paddle3, + Paddle4, + + // PS5 touchpad button + Touchpad, + + // Virtual buttons for single joycon + SingleLeftTrigger0, + SingleRightTrigger0, + + SingleLeftTrigger1, + SingleRightTrigger1, + + Count + } +} diff --git a/Ryujinx.Common/Configuration/Hid/Controller/GenericControllerInputConfig.cs b/Ryujinx.Common/Configuration/Hid/Controller/GenericControllerInputConfig.cs new file mode 100644 index 00000000..e3423bb5 --- /dev/null +++ b/Ryujinx.Common/Configuration/Hid/Controller/GenericControllerInputConfig.cs @@ -0,0 +1,37 @@ +using Ryujinx.Common.Configuration.Hid.Controller.Motion; + +namespace Ryujinx.Common.Configuration.Hid.Controller +{ + public class GenericControllerInputConfig : GenericInputConfigurationCommon False @@ -682,7 +667,7 @@ 80 True False - LStick Lt/Rt + LStick 0 @@ -691,20 +676,7 @@ - - 80 - True - False - LStick Up/Dn - 0 - - - 0 - 1 - - - - + 65 True @@ -716,22 +688,9 @@ 0 - - - - 65 - True - True - True - - - 1 - 1 - - - Invert + Invert Stick X True True False @@ -744,7 +703,7 @@ - Invert + Invert Stick Y True True False @@ -1501,7 +1460,7 @@ 80 True False - RStick Lt/Rt + RStick 0 @@ -1510,20 +1469,7 @@ - - 80 - True - False - RStick Up/Dn - 0 - - - 0 - 1 - - - - + 65 True @@ -1535,22 +1481,9 @@ 0 - - - - 65 - True - True - True - - - 1 - 1 - - - Invert + Invert Stick X True True False @@ -1563,7 +1496,7 @@ - Invert + Invert Stick Y True True False @@ -1640,7 +1573,7 @@ - + True False 10 @@ -1679,7 +1612,21 @@ - + + Use CemuHook compatible motion + True + True + False + True + + + False + True + 2 + + + + True False 10 @@ -1718,7 +1665,7 @@ False True 5 - 2 + 3 @@ -1761,11 +1708,11 @@ False True 5 - 3 + 4 - + True False vertical @@ -1829,11 +1776,11 @@ False True - 4 + 5 - + True False 30 @@ -1866,11 +1813,11 @@ False True 5 - 5 + 6 - + True False 30 @@ -1903,7 +1850,7 @@ False True 5 - 6 + 7 @@ -1916,7 +1863,7 @@ False True - 7 + 8 @@ -1930,7 +1877,7 @@ True True - 8 + 9 diff --git a/Ryujinx/Ui/Windows/SettingsWindow.cs b/Ryujinx/Ui/Windows/SettingsWindow.cs index 4cd5eb72..be9dc271 100644 --- a/Ryujinx/Ui/Windows/SettingsWindow.cs +++ b/Ryujinx/Ui/Windows/SettingsWindow.cs @@ -578,7 +578,7 @@ namespace Ryujinx.Ui.Windows { ((ToggleButton)sender).SetStateFlags(StateFlags.Normal, true); - ControllerWindow controllerWindow = new ControllerWindow(playerIndex); + ControllerWindow controllerWindow = new ControllerWindow(_parent, playerIndex); controllerWindow.SetSizeRequest((int)(controllerWindow.DefaultWidth * Program.WindowScaleFactor), (int)(controllerWindow.DefaultHeight * Program.WindowScaleFactor)); controllerWindow.Show();