summaryrefslogtreecommitdiff
path: root/src/input_common/sdl/sdl_impl.cpp
diff options
context:
space:
mode:
Diffstat (limited to 'src/input_common/sdl/sdl_impl.cpp')
-rw-r--r--src/input_common/sdl/sdl_impl.cpp38
1 files changed, 31 insertions, 7 deletions
diff --git a/src/input_common/sdl/sdl_impl.cpp b/src/input_common/sdl/sdl_impl.cpp
index f67de37e3..f682a6db4 100644
--- a/src/input_common/sdl/sdl_impl.cpp
+++ b/src/input_common/sdl/sdl_impl.cpp
@@ -17,14 +17,24 @@
17#include <unordered_map> 17#include <unordered_map>
18#include <utility> 18#include <utility>
19#include <vector> 19#include <vector>
20
21// Ignore -Wimplicit-fallthrough due to https://github.com/libsdl-org/SDL/issues/4307
22#ifdef __clang__
23#pragma clang diagnostic push
24#pragma clang diagnostic ignored "-Wimplicit-fallthrough"
25#endif
20#include <SDL.h> 26#include <SDL.h>
27#ifdef __clang__
28#pragma clang diagnostic pop
29#endif
30
21#include "common/logging/log.h" 31#include "common/logging/log.h"
22#include "common/param_package.h" 32#include "common/param_package.h"
33#include "common/settings_input.h"
23#include "common/threadsafe_queue.h" 34#include "common/threadsafe_queue.h"
24#include "core/frontend/input.h" 35#include "core/frontend/input.h"
25#include "input_common/motion_input.h" 36#include "input_common/motion_input.h"
26#include "input_common/sdl/sdl_impl.h" 37#include "input_common/sdl/sdl_impl.h"
27#include "input_common/settings.h"
28 38
29namespace InputCommon::SDL { 39namespace InputCommon::SDL {
30 40
@@ -761,7 +771,7 @@ std::vector<Common::ParamPackage> SDLState::GetInputDevices() {
761 for (const auto& joystick : value) { 771 for (const auto& joystick : value) {
762 if (auto* const controller = joystick->GetSDLGameController()) { 772 if (auto* const controller = joystick->GetSDLGameController()) {
763 std::string name = 773 std::string name =
764 fmt::format("{} {}", SDL_GameControllerName(controller), joystick->GetPort()); 774 fmt::format("{} {}", GetControllerName(controller), joystick->GetPort());
765 devices.emplace_back(Common::ParamPackage{ 775 devices.emplace_back(Common::ParamPackage{
766 {"class", "sdl"}, 776 {"class", "sdl"},
767 {"display", std::move(name)}, 777 {"display", std::move(name)},
@@ -782,6 +792,17 @@ std::vector<Common::ParamPackage> SDLState::GetInputDevices() {
782 return devices; 792 return devices;
783} 793}
784 794
795std::string SDLState::GetControllerName(SDL_GameController* controller) const {
796 switch (SDL_GameControllerGetType(controller)) {
797 case SDL_CONTROLLER_TYPE_XBOX360:
798 return "XBox 360 Controller";
799 case SDL_CONTROLLER_TYPE_XBOXONE:
800 return "XBox One Controller";
801 default:
802 return SDL_GameControllerName(controller);
803 }
804}
805
785namespace { 806namespace {
786Common::ParamPackage BuildAnalogParamPackageForButton(int port, std::string guid, s32 axis, 807Common::ParamPackage BuildAnalogParamPackageForButton(int port, std::string guid, s32 axis,
787 float value = 0.1f) { 808 float value = 0.1f) {
@@ -930,16 +951,19 @@ ButtonMapping SDLState::GetButtonMappingForDevice(const Common::ParamPackage& pa
930 return {}; 951 return {};
931 } 952 }
932 953
954 const bool invert =
955 SDL_GameControllerGetType(controller) != SDL_CONTROLLER_TYPE_NINTENDO_SWITCH_PRO;
956
933 // This list is missing ZL/ZR since those are not considered buttons in SDL GameController. 957 // This list is missing ZL/ZR since those are not considered buttons in SDL GameController.
934 // We will add those afterwards 958 // We will add those afterwards
935 // This list also excludes Screenshot since theres not really a mapping for that 959 // This list also excludes Screenshot since theres not really a mapping for that
936 using ButtonBindings = 960 using ButtonBindings =
937 std::array<std::pair<Settings::NativeButton::Values, SDL_GameControllerButton>, 17>; 961 std::array<std::pair<Settings::NativeButton::Values, SDL_GameControllerButton>, 17>;
938 static constexpr ButtonBindings switch_to_sdl_button{{ 962 const ButtonBindings switch_to_sdl_button{{
939 {Settings::NativeButton::A, SDL_CONTROLLER_BUTTON_B}, 963 {Settings::NativeButton::A, invert ? SDL_CONTROLLER_BUTTON_B : SDL_CONTROLLER_BUTTON_A},
940 {Settings::NativeButton::B, SDL_CONTROLLER_BUTTON_A}, 964 {Settings::NativeButton::B, invert ? SDL_CONTROLLER_BUTTON_A : SDL_CONTROLLER_BUTTON_B},
941 {Settings::NativeButton::X, SDL_CONTROLLER_BUTTON_Y}, 965 {Settings::NativeButton::X, invert ? SDL_CONTROLLER_BUTTON_Y : SDL_CONTROLLER_BUTTON_X},
942 {Settings::NativeButton::Y, SDL_CONTROLLER_BUTTON_X}, 966 {Settings::NativeButton::Y, invert ? SDL_CONTROLLER_BUTTON_X : SDL_CONTROLLER_BUTTON_Y},
943 {Settings::NativeButton::LStick, SDL_CONTROLLER_BUTTON_LEFTSTICK}, 967 {Settings::NativeButton::LStick, SDL_CONTROLLER_BUTTON_LEFTSTICK},
944 {Settings::NativeButton::RStick, SDL_CONTROLLER_BUTTON_RIGHTSTICK}, 968 {Settings::NativeButton::RStick, SDL_CONTROLLER_BUTTON_RIGHTSTICK},
945 {Settings::NativeButton::L, SDL_CONTROLLER_BUTTON_LEFTSHOULDER}, 969 {Settings::NativeButton::L, SDL_CONTROLLER_BUTTON_LEFTSHOULDER},