diff options
Diffstat (limited to 'src/input_common/sdl/sdl_impl.cpp')
| -rw-r--r-- | src/input_common/sdl/sdl_impl.cpp | 68 |
1 files changed, 37 insertions, 31 deletions
diff --git a/src/input_common/sdl/sdl_impl.cpp b/src/input_common/sdl/sdl_impl.cpp index 8d83184d2..a9e676f4b 100644 --- a/src/input_common/sdl/sdl_impl.cpp +++ b/src/input_common/sdl/sdl_impl.cpp | |||
| @@ -3,6 +3,7 @@ | |||
| 3 | // Refer to the license.txt file included. | 3 | // Refer to the license.txt file included. |
| 4 | 4 | ||
| 5 | #include <algorithm> | 5 | #include <algorithm> |
| 6 | #include <array> | ||
| 6 | #include <atomic> | 7 | #include <atomic> |
| 7 | #include <cmath> | 8 | #include <cmath> |
| 8 | #include <functional> | 9 | #include <functional> |
| @@ -670,29 +671,6 @@ Common::ParamPackage BuildParamPackageForAnalog(int port, const std::string& gui | |||
| 670 | } // Anonymous namespace | 671 | } // Anonymous namespace |
| 671 | 672 | ||
| 672 | ButtonMapping SDLState::GetButtonMappingForDevice(const Common::ParamPackage& params) { | 673 | ButtonMapping SDLState::GetButtonMappingForDevice(const Common::ParamPackage& params) { |
| 673 | // This list is missing ZL/ZR since those are not considered buttons in SDL GameController. | ||
| 674 | // We will add those afterwards | ||
| 675 | // This list also excludes Screenshot since theres not really a mapping for that | ||
| 676 | std::unordered_map<Settings::NativeButton::Values, SDL_GameControllerButton> | ||
| 677 | switch_to_sdl_button = { | ||
| 678 | {Settings::NativeButton::A, SDL_CONTROLLER_BUTTON_B}, | ||
| 679 | {Settings::NativeButton::B, SDL_CONTROLLER_BUTTON_A}, | ||
| 680 | {Settings::NativeButton::X, SDL_CONTROLLER_BUTTON_Y}, | ||
| 681 | {Settings::NativeButton::Y, SDL_CONTROLLER_BUTTON_X}, | ||
| 682 | {Settings::NativeButton::LStick, SDL_CONTROLLER_BUTTON_LEFTSTICK}, | ||
| 683 | {Settings::NativeButton::RStick, SDL_CONTROLLER_BUTTON_RIGHTSTICK}, | ||
| 684 | {Settings::NativeButton::L, SDL_CONTROLLER_BUTTON_LEFTSHOULDER}, | ||
| 685 | {Settings::NativeButton::R, SDL_CONTROLLER_BUTTON_RIGHTSHOULDER}, | ||
| 686 | {Settings::NativeButton::Plus, SDL_CONTROLLER_BUTTON_START}, | ||
| 687 | {Settings::NativeButton::Minus, SDL_CONTROLLER_BUTTON_BACK}, | ||
| 688 | {Settings::NativeButton::DLeft, SDL_CONTROLLER_BUTTON_DPAD_LEFT}, | ||
| 689 | {Settings::NativeButton::DUp, SDL_CONTROLLER_BUTTON_DPAD_UP}, | ||
| 690 | {Settings::NativeButton::DRight, SDL_CONTROLLER_BUTTON_DPAD_RIGHT}, | ||
| 691 | {Settings::NativeButton::DDown, SDL_CONTROLLER_BUTTON_DPAD_DOWN}, | ||
| 692 | {Settings::NativeButton::SL, SDL_CONTROLLER_BUTTON_LEFTSHOULDER}, | ||
| 693 | {Settings::NativeButton::SR, SDL_CONTROLLER_BUTTON_RIGHTSHOULDER}, | ||
| 694 | {Settings::NativeButton::Home, SDL_CONTROLLER_BUTTON_GUIDE}, | ||
| 695 | }; | ||
| 696 | if (!params.Has("guid") || !params.Has("port")) { | 674 | if (!params.Has("guid") || !params.Has("port")) { |
| 697 | return {}; | 675 | return {}; |
| 698 | } | 676 | } |
| @@ -702,20 +680,48 @@ ButtonMapping SDLState::GetButtonMappingForDevice(const Common::ParamPackage& pa | |||
| 702 | return {}; | 680 | return {}; |
| 703 | } | 681 | } |
| 704 | 682 | ||
| 705 | ButtonMapping mapping{}; | 683 | // This list is missing ZL/ZR since those are not considered buttons in SDL GameController. |
| 684 | // We will add those afterwards | ||
| 685 | // This list also excludes Screenshot since theres not really a mapping for that | ||
| 686 | using ButtonBindings = | ||
| 687 | std::array<std::pair<Settings::NativeButton::Values, SDL_GameControllerButton>, 17>; | ||
| 688 | static constexpr ButtonBindings switch_to_sdl_button{{ | ||
| 689 | {Settings::NativeButton::A, SDL_CONTROLLER_BUTTON_B}, | ||
| 690 | {Settings::NativeButton::B, SDL_CONTROLLER_BUTTON_A}, | ||
| 691 | {Settings::NativeButton::X, SDL_CONTROLLER_BUTTON_Y}, | ||
| 692 | {Settings::NativeButton::Y, SDL_CONTROLLER_BUTTON_X}, | ||
| 693 | {Settings::NativeButton::LStick, SDL_CONTROLLER_BUTTON_LEFTSTICK}, | ||
| 694 | {Settings::NativeButton::RStick, SDL_CONTROLLER_BUTTON_RIGHTSTICK}, | ||
| 695 | {Settings::NativeButton::L, SDL_CONTROLLER_BUTTON_LEFTSHOULDER}, | ||
| 696 | {Settings::NativeButton::R, SDL_CONTROLLER_BUTTON_RIGHTSHOULDER}, | ||
| 697 | {Settings::NativeButton::Plus, SDL_CONTROLLER_BUTTON_START}, | ||
| 698 | {Settings::NativeButton::Minus, SDL_CONTROLLER_BUTTON_BACK}, | ||
| 699 | {Settings::NativeButton::DLeft, SDL_CONTROLLER_BUTTON_DPAD_LEFT}, | ||
| 700 | {Settings::NativeButton::DUp, SDL_CONTROLLER_BUTTON_DPAD_UP}, | ||
| 701 | {Settings::NativeButton::DRight, SDL_CONTROLLER_BUTTON_DPAD_RIGHT}, | ||
| 702 | {Settings::NativeButton::DDown, SDL_CONTROLLER_BUTTON_DPAD_DOWN}, | ||
| 703 | {Settings::NativeButton::SL, SDL_CONTROLLER_BUTTON_LEFTSHOULDER}, | ||
| 704 | {Settings::NativeButton::SR, SDL_CONTROLLER_BUTTON_RIGHTSHOULDER}, | ||
| 705 | {Settings::NativeButton::Home, SDL_CONTROLLER_BUTTON_GUIDE}, | ||
| 706 | }}; | ||
| 707 | |||
| 708 | // Add the missing bindings for ZL/ZR | ||
| 709 | using ZBindings = | ||
| 710 | std::array<std::pair<Settings::NativeButton::Values, SDL_GameControllerAxis>, 2>; | ||
| 711 | static constexpr ZBindings switch_to_sdl_axis{{ | ||
| 712 | {Settings::NativeButton::ZL, SDL_CONTROLLER_AXIS_TRIGGERLEFT}, | ||
| 713 | {Settings::NativeButton::ZR, SDL_CONTROLLER_AXIS_TRIGGERRIGHT}, | ||
| 714 | }}; | ||
| 715 | |||
| 716 | ButtonMapping mapping; | ||
| 717 | mapping.reserve(switch_to_sdl_button.size() + switch_to_sdl_axis.size()); | ||
| 718 | |||
| 706 | for (const auto& [switch_button, sdl_button] : switch_to_sdl_button) { | 719 | for (const auto& [switch_button, sdl_button] : switch_to_sdl_button) { |
| 707 | const auto& binding = SDL_GameControllerGetBindForButton(controller, sdl_button); | 720 | const auto& binding = SDL_GameControllerGetBindForButton(controller, sdl_button); |
| 708 | mapping.insert_or_assign( | 721 | mapping.insert_or_assign( |
| 709 | switch_button, | 722 | switch_button, |
| 710 | BuildParamPackageForBinding(joystick->GetPort(), joystick->GetGUID(), binding)); | 723 | BuildParamPackageForBinding(joystick->GetPort(), joystick->GetGUID(), binding)); |
| 711 | } | 724 | } |
| 712 | |||
| 713 | // Add the missing bindings for ZL/ZR | ||
| 714 | std::unordered_map<Settings::NativeButton::Values, SDL_GameControllerAxis> switch_to_sdl_axis = | ||
| 715 | { | ||
| 716 | {Settings::NativeButton::ZL, SDL_CONTROLLER_AXIS_TRIGGERLEFT}, | ||
| 717 | {Settings::NativeButton::ZR, SDL_CONTROLLER_AXIS_TRIGGERRIGHT}, | ||
| 718 | }; | ||
| 719 | for (const auto& [switch_button, sdl_axis] : switch_to_sdl_axis) { | 725 | for (const auto& [switch_button, sdl_axis] : switch_to_sdl_axis) { |
| 720 | const auto& binding = SDL_GameControllerGetBindForAxis(controller, sdl_axis); | 726 | const auto& binding = SDL_GameControllerGetBindForAxis(controller, sdl_axis); |
| 721 | mapping.insert_or_assign( | 727 | mapping.insert_or_assign( |