diff options
Diffstat (limited to 'src/input_common')
| -rw-r--r-- | src/input_common/drivers/sdl_driver.cpp | 46 | ||||
| -rw-r--r-- | src/input_common/drivers/sdl_driver.h | 7 |
2 files changed, 11 insertions, 42 deletions
diff --git a/src/input_common/drivers/sdl_driver.cpp b/src/input_common/drivers/sdl_driver.cpp index 9f26392b1..66e3ae9af 100644 --- a/src/input_common/drivers/sdl_driver.cpp +++ b/src/input_common/drivers/sdl_driver.cpp | |||
| @@ -523,6 +523,8 @@ SDLDriver::SDLDriver(std::string input_engine_) : InputEngine(std::move(input_en | |||
| 523 | } | 523 | } |
| 524 | 524 | ||
| 525 | SDL_SetHint(SDL_HINT_JOYSTICK_HIDAPI_SWITCH_PLAYER_LED, "1"); | 525 | SDL_SetHint(SDL_HINT_JOYSTICK_HIDAPI_SWITCH_PLAYER_LED, "1"); |
| 526 | // Share the same button mapping with non-Nintendo controllers | ||
| 527 | SDL_SetHint(SDL_HINT_GAMECONTROLLER_USE_BUTTON_LABELS, "0"); | ||
| 526 | 528 | ||
| 527 | // Disable hidapi driver for xbox. Already default on Windows, this causes conflict with native | 529 | // Disable hidapi driver for xbox. Already default on Windows, this causes conflict with native |
| 528 | // driver on Linux. | 530 | // driver on Linux. |
| @@ -800,16 +802,9 @@ ButtonMapping SDLDriver::GetButtonMappingForDevice(const Common::ParamPackage& p | |||
| 800 | 802 | ||
| 801 | // This list is missing ZL/ZR since those are not considered buttons in SDL GameController. | 803 | // This list is missing ZL/ZR since those are not considered buttons in SDL GameController. |
| 802 | // We will add those afterwards | 804 | // We will add those afterwards |
| 803 | // This list also excludes Screenshot since there's not really a mapping for that | ||
| 804 | ButtonBindings switch_to_sdl_button; | 805 | ButtonBindings switch_to_sdl_button; |
| 805 | 806 | ||
| 806 | if (SDL_GameControllerGetType(controller) == SDL_CONTROLLER_TYPE_NINTENDO_SWITCH_PRO || | 807 | switch_to_sdl_button = GetDefaultButtonBinding(joystick); |
| 807 | SDL_GameControllerGetType(controller) == SDL_CONTROLLER_TYPE_NINTENDO_SWITCH_JOYCON_LEFT || | ||
| 808 | SDL_GameControllerGetType(controller) == SDL_CONTROLLER_TYPE_NINTENDO_SWITCH_JOYCON_RIGHT) { | ||
| 809 | switch_to_sdl_button = GetNintendoButtonBinding(joystick); | ||
| 810 | } else { | ||
| 811 | switch_to_sdl_button = GetDefaultButtonBinding(); | ||
| 812 | } | ||
| 813 | 808 | ||
| 814 | // Add the missing bindings for ZL/ZR | 809 | // Add the missing bindings for ZL/ZR |
| 815 | static constexpr ZButtonBindings switch_to_sdl_axis{{ | 810 | static constexpr ZButtonBindings switch_to_sdl_axis{{ |
| @@ -830,32 +825,9 @@ ButtonMapping SDLDriver::GetButtonMappingForDevice(const Common::ParamPackage& p | |||
| 830 | return GetSingleControllerMapping(joystick, switch_to_sdl_button, switch_to_sdl_axis); | 825 | return GetSingleControllerMapping(joystick, switch_to_sdl_button, switch_to_sdl_axis); |
| 831 | } | 826 | } |
| 832 | 827 | ||
| 833 | ButtonBindings SDLDriver::GetDefaultButtonBinding() const { | 828 | ButtonBindings SDLDriver::GetDefaultButtonBinding( |
| 834 | return { | ||
| 835 | std::pair{Settings::NativeButton::A, SDL_CONTROLLER_BUTTON_B}, | ||
| 836 | {Settings::NativeButton::B, SDL_CONTROLLER_BUTTON_A}, | ||
| 837 | {Settings::NativeButton::X, SDL_CONTROLLER_BUTTON_Y}, | ||
| 838 | {Settings::NativeButton::Y, SDL_CONTROLLER_BUTTON_X}, | ||
| 839 | {Settings::NativeButton::LStick, SDL_CONTROLLER_BUTTON_LEFTSTICK}, | ||
| 840 | {Settings::NativeButton::RStick, SDL_CONTROLLER_BUTTON_RIGHTSTICK}, | ||
| 841 | {Settings::NativeButton::L, SDL_CONTROLLER_BUTTON_LEFTSHOULDER}, | ||
| 842 | {Settings::NativeButton::R, SDL_CONTROLLER_BUTTON_RIGHTSHOULDER}, | ||
| 843 | {Settings::NativeButton::Plus, SDL_CONTROLLER_BUTTON_START}, | ||
| 844 | {Settings::NativeButton::Minus, SDL_CONTROLLER_BUTTON_BACK}, | ||
| 845 | {Settings::NativeButton::DLeft, SDL_CONTROLLER_BUTTON_DPAD_LEFT}, | ||
| 846 | {Settings::NativeButton::DUp, SDL_CONTROLLER_BUTTON_DPAD_UP}, | ||
| 847 | {Settings::NativeButton::DRight, SDL_CONTROLLER_BUTTON_DPAD_RIGHT}, | ||
| 848 | {Settings::NativeButton::DDown, SDL_CONTROLLER_BUTTON_DPAD_DOWN}, | ||
| 849 | {Settings::NativeButton::SL, SDL_CONTROLLER_BUTTON_LEFTSHOULDER}, | ||
| 850 | {Settings::NativeButton::SR, SDL_CONTROLLER_BUTTON_RIGHTSHOULDER}, | ||
| 851 | {Settings::NativeButton::Home, SDL_CONTROLLER_BUTTON_GUIDE}, | ||
| 852 | {Settings::NativeButton::Screenshot, SDL_CONTROLLER_BUTTON_MISC1}, | ||
| 853 | }; | ||
| 854 | } | ||
| 855 | |||
| 856 | ButtonBindings SDLDriver::GetNintendoButtonBinding( | ||
| 857 | const std::shared_ptr<SDLJoystick>& joystick) const { | 829 | const std::shared_ptr<SDLJoystick>& joystick) const { |
| 858 | // Default SL/SR mapping for pro controllers | 830 | // Default SL/SR mapping for other controllers |
| 859 | auto sl_button = SDL_CONTROLLER_BUTTON_LEFTSHOULDER; | 831 | auto sl_button = SDL_CONTROLLER_BUTTON_LEFTSHOULDER; |
| 860 | auto sr_button = SDL_CONTROLLER_BUTTON_RIGHTSHOULDER; | 832 | auto sr_button = SDL_CONTROLLER_BUTTON_RIGHTSHOULDER; |
| 861 | 833 | ||
| @@ -869,10 +841,10 @@ ButtonBindings SDLDriver::GetNintendoButtonBinding( | |||
| 869 | } | 841 | } |
| 870 | 842 | ||
| 871 | return { | 843 | return { |
| 872 | std::pair{Settings::NativeButton::A, SDL_CONTROLLER_BUTTON_A}, | 844 | std::pair{Settings::NativeButton::A, SDL_CONTROLLER_BUTTON_B}, |
| 873 | {Settings::NativeButton::B, SDL_CONTROLLER_BUTTON_B}, | 845 | {Settings::NativeButton::B, SDL_CONTROLLER_BUTTON_A}, |
| 874 | {Settings::NativeButton::X, SDL_CONTROLLER_BUTTON_X}, | 846 | {Settings::NativeButton::X, SDL_CONTROLLER_BUTTON_Y}, |
| 875 | {Settings::NativeButton::Y, SDL_CONTROLLER_BUTTON_Y}, | 847 | {Settings::NativeButton::Y, SDL_CONTROLLER_BUTTON_X}, |
| 876 | {Settings::NativeButton::LStick, SDL_CONTROLLER_BUTTON_LEFTSTICK}, | 848 | {Settings::NativeButton::LStick, SDL_CONTROLLER_BUTTON_LEFTSTICK}, |
| 877 | {Settings::NativeButton::RStick, SDL_CONTROLLER_BUTTON_RIGHTSTICK}, | 849 | {Settings::NativeButton::RStick, SDL_CONTROLLER_BUTTON_RIGHTSTICK}, |
| 878 | {Settings::NativeButton::L, SDL_CONTROLLER_BUTTON_LEFTSHOULDER}, | 850 | {Settings::NativeButton::L, SDL_CONTROLLER_BUTTON_LEFTSHOULDER}, |
diff --git a/src/input_common/drivers/sdl_driver.h b/src/input_common/drivers/sdl_driver.h index ffde169b3..fcba4e3c6 100644 --- a/src/input_common/drivers/sdl_driver.h +++ b/src/input_common/drivers/sdl_driver.h | |||
| @@ -100,11 +100,8 @@ private: | |||
| 100 | int axis_y, float offset_x, | 100 | int axis_y, float offset_x, |
| 101 | float offset_y) const; | 101 | float offset_y) const; |
| 102 | 102 | ||
| 103 | /// Returns the default button bindings list for generic controllers | 103 | /// Returns the default button bindings list |
| 104 | ButtonBindings GetDefaultButtonBinding() const; | 104 | ButtonBindings GetDefaultButtonBinding(const std::shared_ptr<SDLJoystick>& joystick) const; |
| 105 | |||
| 106 | /// Returns the default button bindings list for nintendo controllers | ||
| 107 | ButtonBindings GetNintendoButtonBinding(const std::shared_ptr<SDLJoystick>& joystick) const; | ||
| 108 | 105 | ||
| 109 | /// Returns the button mappings from a single controller | 106 | /// Returns the button mappings from a single controller |
| 110 | ButtonMapping GetSingleControllerMapping(const std::shared_ptr<SDLJoystick>& joystick, | 107 | ButtonMapping GetSingleControllerMapping(const std::shared_ptr<SDLJoystick>& joystick, |