From 89c2c6c76bc8d260002e638e215565b607f56869 Mon Sep 17 00:00:00 2001 From: Aaron Murgatroyd Date: Sun, 17 Dec 2023 01:27:57 +1000 Subject: [PATCH 1/3] Fix issues with Invert X / Y and Rotate when mapping different physical stick to JoyCon logical stick --- src/Ryujinx.Input.SDL2/SDL2Gamepad.cs | 52 +++++++++++++++++++-------- 1 file changed, 37 insertions(+), 15 deletions(-) diff --git a/src/Ryujinx.Input.SDL2/SDL2Gamepad.cs b/src/Ryujinx.Input.SDL2/SDL2Gamepad.cs index 187ca48dd7..18e353567f 100644 --- a/src/Ryujinx.Input.SDL2/SDL2Gamepad.cs +++ b/src/Ryujinx.Input.SDL2/SDL2Gamepad.cs @@ -313,6 +313,33 @@ namespace Ryujinx.Input.SDL2 return value * ConvertRate; } + private JoyconConfigControllerStick GetLogicalJoyStickConfig(StickInputId inputId) + { + switch(inputId) + { + case StickInputId.Left: + if (_configuration.RightJoyconStick.Joystick == Common.Configuration.Hid.Controller.StickInputId.Left) + { + return _configuration.RightJoyconStick; + } + else + { + return _configuration.LeftJoyconStick; + } + case StickInputId.Right: + if (_configuration.LeftJoyconStick.Joystick == Common.Configuration.Hid.Controller.StickInputId.Right) + { + return _configuration.LeftJoyconStick; + } + else + { + return _configuration.RightJoyconStick; + } + } + + return null; + } + public (float, float) GetStick(StickInputId inputId) { if (inputId == StickInputId.Unbound) @@ -343,24 +370,19 @@ namespace Ryujinx.Input.SDL2 if (HasConfiguration) { - if ((inputId == StickInputId.Left && _configuration.LeftJoyconStick.InvertStickX) || - (inputId == StickInputId.Right && _configuration.RightJoyconStick.InvertStickX)) - { - resultX = -resultX; - } + var joyconStickConfig = GetLogicalJoyStickConfig(inputId); - if ((inputId == StickInputId.Left && _configuration.LeftJoyconStick.InvertStickY) || - (inputId == StickInputId.Right && _configuration.RightJoyconStick.InvertStickY)) + if (joyconStickConfig != null) { - resultY = -resultY; - } + if (joyconStickConfig.InvertStickX) resultX = -resultX; + if (joyconStickConfig.InvertStickY) resultY = -resultY; - if ((inputId == StickInputId.Left && _configuration.LeftJoyconStick.Rotate90CW) || - (inputId == StickInputId.Right && _configuration.RightJoyconStick.Rotate90CW)) - { - float temp = resultX; - resultX = resultY; - resultY = -temp; + if (joyconStickConfig.Rotate90CW) + { + float temp = resultX; + resultX = resultY; + resultY = -temp; + } } } From 3f6fca292111ff67441aa0e82fe8b0cef870c20b Mon Sep 17 00:00:00 2001 From: Aaron Murgatroyd Date: Sun, 17 Dec 2023 02:34:17 +1000 Subject: [PATCH 2/3] Fixed whitespace issues --- src/Ryujinx.Input.SDL2/SDL2Gamepad.cs | 19 +++++++++++++------ 1 file changed, 13 insertions(+), 6 deletions(-) diff --git a/src/Ryujinx.Input.SDL2/SDL2Gamepad.cs b/src/Ryujinx.Input.SDL2/SDL2Gamepad.cs index 18e353567f..14c3a865e5 100644 --- a/src/Ryujinx.Input.SDL2/SDL2Gamepad.cs +++ b/src/Ryujinx.Input.SDL2/SDL2Gamepad.cs @@ -313,9 +313,9 @@ namespace Ryujinx.Input.SDL2 return value * ConvertRate; } - private JoyconConfigControllerStick GetLogicalJoyStickConfig(StickInputId inputId) + private JoyconConfigControllerStick GetLogicalJoyStickConfig(StickInputId inputId) { - switch(inputId) + switch (inputId) { case StickInputId.Left: if (_configuration.RightJoyconStick.Joystick == Common.Configuration.Hid.Controller.StickInputId.Left) @@ -323,14 +323,14 @@ namespace Ryujinx.Input.SDL2 return _configuration.RightJoyconStick; } else - { + { return _configuration.LeftJoyconStick; } case StickInputId.Right: if (_configuration.LeftJoyconStick.Joystick == Common.Configuration.Hid.Controller.StickInputId.Right) { return _configuration.LeftJoyconStick; - } + } else { return _configuration.RightJoyconStick; @@ -374,8 +374,15 @@ namespace Ryujinx.Input.SDL2 if (joyconStickConfig != null) { - if (joyconStickConfig.InvertStickX) resultX = -resultX; - if (joyconStickConfig.InvertStickY) resultY = -resultY; + if (joyconStickConfig.InvertStickX) + { + resultX = -resultX; + } + + if (joyconStickConfig.InvertStickY) + { + resultY = -resultY; + } if (joyconStickConfig.Rotate90CW) { From 6aaec6da5d0ad7a1e3749dd688fa6d0a5a7afef2 Mon Sep 17 00:00:00 2001 From: Aaron Murgatroyd Date: Mon, 17 Jun 2024 00:32:11 +1000 Subject: [PATCH 3/3] Fixed duplicate controller names under Ava --- .../UI/ViewModels/Input/InputViewModel.cs | 30 +++++++++++++------ 1 file changed, 21 insertions(+), 9 deletions(-) diff --git a/src/Ryujinx/UI/ViewModels/Input/InputViewModel.cs b/src/Ryujinx/UI/ViewModels/Input/InputViewModel.cs index 89cc6496d5..fe7f5d6d53 100644 --- a/src/Ryujinx/UI/ViewModels/Input/InputViewModel.cs +++ b/src/Ryujinx/UI/ViewModels/Input/InputViewModel.cs @@ -45,7 +45,6 @@ namespace Ryujinx.Ava.UI.ViewModels.Input private PlayerIndex _playerId; private int _controller; - private int _controllerNumber; private string _controllerImage; private int _device; private object _configViewModel; @@ -439,6 +438,24 @@ namespace Ryujinx.Ava.UI.ViewModels.Input public void LoadDevices() { + string GetGamepadName(IGamepad gamepad, int controllerNumber) + { + return $"{GetShortGamepadName(gamepad.Name)} ({controllerNumber})"; + } + + string GetUniqueGamepadName(IGamepad gamepad, ref int controllerNumber) + { + var name = GetGamepadName(gamepad, controllerNumber); + + if (Devices.Any(controller => controller.Name == name)) + { + controllerNumber++; + name = GetGamepadName(gamepad, controllerNumber); + } + + return name; + } + lock (Devices) { Devices.Clear(); @@ -455,23 +472,18 @@ namespace Ryujinx.Ava.UI.ViewModels.Input } } + var controllerNumber = 0; foreach (string id in _mainWindow.InputManager.GamepadDriver.GamepadsIds) { using IGamepad gamepad = _mainWindow.InputManager.GamepadDriver.GetGamepad(id); if (gamepad != null) { - if (Devices.Any(controller => GetShortGamepadId(controller.Id) == GetShortGamepadId(gamepad.Id))) - { - _controllerNumber++; - } - - Devices.Add((DeviceType.Controller, id, $"{GetShortGamepadName(gamepad.Name)} ({_controllerNumber})")); + var name = GetUniqueGamepadName(gamepad, ref controllerNumber); + Devices.Add((DeviceType.Controller, id, name)); } } - _controllerNumber = 0; - DeviceList.AddRange(Devices.Select(x => x.Name)); Device = Math.Min(Device, DeviceList.Count); }