diff options
| author | 2021-04-15 21:40:35 -0700 | |
|---|---|---|
| committer | 2021-04-15 21:40:35 -0700 | |
| commit | 0a5bc8ec14619080cabe3168a1b82c6da4a63a0f (patch) | |
| tree | d35eebf5da42ebbe24d521c90d2139c94b68f8e8 | |
| parent | Merge pull request #6199 from lioncash/log-ns (diff) | |
| parent | InputCommon: Name properly xbox 360 and one controllers, Fix mappings for Nin... (diff) | |
| download | yuzu-0a5bc8ec14619080cabe3168a1b82c6da4a63a0f.tar.gz yuzu-0a5bc8ec14619080cabe3168a1b82c6da4a63a0f.tar.xz yuzu-0a5bc8ec14619080cabe3168a1b82c6da4a63a0f.zip | |
Merge pull request #6119 from german77/SDLMapping
InputCommon: Address mapping and naming issues with SDL2
| -rw-r--r-- | src/input_common/sdl/sdl_impl.cpp | 26 | ||||
| -rw-r--r-- | src/input_common/sdl/sdl_impl.h | 4 |
2 files changed, 24 insertions, 6 deletions
diff --git a/src/input_common/sdl/sdl_impl.cpp b/src/input_common/sdl/sdl_impl.cpp index 8bca71731..9418e78fa 100644 --- a/src/input_common/sdl/sdl_impl.cpp +++ b/src/input_common/sdl/sdl_impl.cpp | |||
| @@ -761,7 +761,7 @@ std::vector<Common::ParamPackage> SDLState::GetInputDevices() { | |||
| 761 | for (const auto& joystick : value) { | 761 | for (const auto& joystick : value) { |
| 762 | if (auto* const controller = joystick->GetSDLGameController()) { | 762 | if (auto* const controller = joystick->GetSDLGameController()) { |
| 763 | std::string name = | 763 | std::string name = |
| 764 | fmt::format("{} {}", SDL_GameControllerName(controller), joystick->GetPort()); | 764 | fmt::format("{} {}", GetControllerName(controller), joystick->GetPort()); |
| 765 | devices.emplace_back(Common::ParamPackage{ | 765 | devices.emplace_back(Common::ParamPackage{ |
| 766 | {"class", "sdl"}, | 766 | {"class", "sdl"}, |
| 767 | {"display", std::move(name)}, | 767 | {"display", std::move(name)}, |
| @@ -782,6 +782,17 @@ std::vector<Common::ParamPackage> SDLState::GetInputDevices() { | |||
| 782 | return devices; | 782 | return devices; |
| 783 | } | 783 | } |
| 784 | 784 | ||
| 785 | std::string SDLState::GetControllerName(SDL_GameController* controller) const { | ||
| 786 | switch (SDL_GameControllerGetType(controller)) { | ||
| 787 | case SDL_CONTROLLER_TYPE_XBOX360: | ||
| 788 | return "XBox 360 Controller"; | ||
| 789 | case SDL_CONTROLLER_TYPE_XBOXONE: | ||
| 790 | return "XBox One Controller"; | ||
| 791 | default: | ||
| 792 | return SDL_GameControllerName(controller); | ||
| 793 | } | ||
| 794 | } | ||
| 795 | |||
| 785 | namespace { | 796 | namespace { |
| 786 | Common::ParamPackage BuildAnalogParamPackageForButton(int port, std::string guid, s32 axis, | 797 | Common::ParamPackage BuildAnalogParamPackageForButton(int port, std::string guid, s32 axis, |
| 787 | float value = 0.1f) { | 798 | float value = 0.1f) { |
| @@ -930,16 +941,19 @@ ButtonMapping SDLState::GetButtonMappingForDevice(const Common::ParamPackage& pa | |||
| 930 | return {}; | 941 | return {}; |
| 931 | } | 942 | } |
| 932 | 943 | ||
| 944 | const bool invert = | ||
| 945 | SDL_GameControllerGetType(controller) != SDL_CONTROLLER_TYPE_NINTENDO_SWITCH_PRO; | ||
| 946 | |||
| 933 | // This list is missing ZL/ZR since those are not considered buttons in SDL GameController. | 947 | // This list is missing ZL/ZR since those are not considered buttons in SDL GameController. |
| 934 | // We will add those afterwards | 948 | // We will add those afterwards |
| 935 | // This list also excludes Screenshot since theres not really a mapping for that | 949 | // This list also excludes Screenshot since theres not really a mapping for that |
| 936 | using ButtonBindings = | 950 | using ButtonBindings = |
| 937 | std::array<std::pair<Settings::NativeButton::Values, SDL_GameControllerButton>, 17>; | 951 | std::array<std::pair<Settings::NativeButton::Values, SDL_GameControllerButton>, 17>; |
| 938 | static constexpr ButtonBindings switch_to_sdl_button{{ | 952 | const ButtonBindings switch_to_sdl_button{{ |
| 939 | {Settings::NativeButton::A, SDL_CONTROLLER_BUTTON_B}, | 953 | {Settings::NativeButton::A, invert ? SDL_CONTROLLER_BUTTON_B : SDL_CONTROLLER_BUTTON_A}, |
| 940 | {Settings::NativeButton::B, SDL_CONTROLLER_BUTTON_A}, | 954 | {Settings::NativeButton::B, invert ? SDL_CONTROLLER_BUTTON_A : SDL_CONTROLLER_BUTTON_B}, |
| 941 | {Settings::NativeButton::X, SDL_CONTROLLER_BUTTON_Y}, | 955 | {Settings::NativeButton::X, invert ? SDL_CONTROLLER_BUTTON_Y : SDL_CONTROLLER_BUTTON_X}, |
| 942 | {Settings::NativeButton::Y, SDL_CONTROLLER_BUTTON_X}, | 956 | {Settings::NativeButton::Y, invert ? SDL_CONTROLLER_BUTTON_X : SDL_CONTROLLER_BUTTON_Y}, |
| 943 | {Settings::NativeButton::LStick, SDL_CONTROLLER_BUTTON_LEFTSTICK}, | 957 | {Settings::NativeButton::LStick, SDL_CONTROLLER_BUTTON_LEFTSTICK}, |
| 944 | {Settings::NativeButton::RStick, SDL_CONTROLLER_BUTTON_RIGHTSTICK}, | 958 | {Settings::NativeButton::RStick, SDL_CONTROLLER_BUTTON_RIGHTSTICK}, |
| 945 | {Settings::NativeButton::L, SDL_CONTROLLER_BUTTON_LEFTSHOULDER}, | 959 | {Settings::NativeButton::L, SDL_CONTROLLER_BUTTON_LEFTSHOULDER}, |
diff --git a/src/input_common/sdl/sdl_impl.h b/src/input_common/sdl/sdl_impl.h index 08044b00d..8b7363f56 100644 --- a/src/input_common/sdl/sdl_impl.h +++ b/src/input_common/sdl/sdl_impl.h | |||
| @@ -14,6 +14,7 @@ | |||
| 14 | #include "input_common/sdl/sdl.h" | 14 | #include "input_common/sdl/sdl.h" |
| 15 | 15 | ||
| 16 | union SDL_Event; | 16 | union SDL_Event; |
| 17 | using SDL_GameController = struct _SDL_GameController; | ||
| 17 | using SDL_Joystick = struct _SDL_Joystick; | 18 | using SDL_Joystick = struct _SDL_Joystick; |
| 18 | using SDL_JoystickID = s32; | 19 | using SDL_JoystickID = s32; |
| 19 | 20 | ||
| @@ -64,6 +65,9 @@ private: | |||
| 64 | /// Needs to be called before SDL_QuitSubSystem. | 65 | /// Needs to be called before SDL_QuitSubSystem. |
| 65 | void CloseJoysticks(); | 66 | void CloseJoysticks(); |
| 66 | 67 | ||
| 68 | /// Returns a custom name for specific controllers because the default name is not correct | ||
| 69 | std::string GetControllerName(SDL_GameController* controller) const; | ||
| 70 | |||
| 67 | // Set to true if SDL supports game controller subsystem | 71 | // Set to true if SDL supports game controller subsystem |
| 68 | bool has_gamecontroller = false; | 72 | bool has_gamecontroller = false; |
| 69 | 73 | ||