diff options
Diffstat (limited to '')
| -rw-r--r-- | src/input_common/sdl/sdl_impl.cpp | 26 |
1 files changed, 20 insertions, 6 deletions
diff --git a/src/input_common/sdl/sdl_impl.cpp b/src/input_common/sdl/sdl_impl.cpp index f67de37e3..51c26c6c3 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}, |