summaryrefslogtreecommitdiff
path: root/src/input_common/sdl/sdl_impl.cpp
diff options
context:
space:
mode:
authorGravatar Morph2020-10-27 13:15:57 -0400
committerGravatar Morph2020-11-15 23:33:21 -0500
commit117bdc71e016629b9355b33a6d64655f0245f833 (patch)
tree8365da4241babfb3871303920e635699f2f3945d /src/input_common/sdl/sdl_impl.cpp
parentapplets/controller: Change the input button to create input profiles (diff)
downloadyuzu-117bdc71e016629b9355b33a6d64655f0245f833.tar.gz
yuzu-117bdc71e016629b9355b33a6d64655f0245f833.tar.xz
yuzu-117bdc71e016629b9355b33a6d64655f0245f833.zip
sdl_impl: Revert to the "old" method of mapping sticks
Not all controllers have a SDL_GameController binding. This caused controllers not present in the SDL GameController database to have buttons mapped instead of axes. Furthermore, it was not possible to invert the axes when it could be useful such as emulating a horizontal single joycon or other potential cases. This allows us to invert the axes by reversing the order of mapping (vertical, then horizontal).
Diffstat (limited to 'src/input_common/sdl/sdl_impl.cpp')
-rw-r--r--src/input_common/sdl/sdl_impl.cpp45
1 files changed, 13 insertions, 32 deletions
diff --git a/src/input_common/sdl/sdl_impl.cpp b/src/input_common/sdl/sdl_impl.cpp
index a9f7e5103..6024ed97a 100644
--- a/src/input_common/sdl/sdl_impl.cpp
+++ b/src/input_common/sdl/sdl_impl.cpp
@@ -1068,7 +1068,6 @@ public:
1068 1068
1069 void Start(const std::string& device_id) override { 1069 void Start(const std::string& device_id) override {
1070 SDLPoller::Start(device_id); 1070 SDLPoller::Start(device_id);
1071 // Load the game controller
1072 // Reset stored axes 1071 // Reset stored axes
1073 analog_x_axis = -1; 1072 analog_x_axis = -1;
1074 analog_y_axis = -1; 1073 analog_y_axis = -1;
@@ -1081,40 +1080,21 @@ public:
1081 if (event.type == SDL_JOYAXISMOTION && std::abs(event.jaxis.value / 32767.0) < 0.5) { 1080 if (event.type == SDL_JOYAXISMOTION && std::abs(event.jaxis.value / 32767.0) < 0.5) {
1082 continue; 1081 continue;
1083 } 1082 }
1084 // Simplify controller config by testing if game controller support is enabled.
1085 if (event.type == SDL_JOYAXISMOTION) { 1083 if (event.type == SDL_JOYAXISMOTION) {
1086 const auto axis = event.jaxis.axis; 1084 const auto axis = event.jaxis.axis;
1087 if (const auto joystick = state.GetSDLJoystickBySDLID(event.jaxis.which); 1085 // In order to return a complete analog param, we need inputs for both axes.
1088 auto* const controller = joystick->GetSDLGameController()) { 1086 // First we take the x-axis (horizontal) input, then the y-axis (vertical) input.
1089 const auto axis_left_x = 1087 if (analog_x_axis == -1) {
1090 SDL_GameControllerGetBindForAxis(controller, SDL_CONTROLLER_AXIS_LEFTX) 1088 analog_x_axis = axis;
1091 .value.axis; 1089 } else if (analog_y_axis == -1 && analog_x_axis != axis) {
1092 const auto axis_left_y = 1090 analog_y_axis = axis;
1093 SDL_GameControllerGetBindForAxis(controller, SDL_CONTROLLER_AXIS_LEFTY) 1091 }
1094 .value.axis; 1092 } else {
1095 const auto axis_right_x = 1093 // If the press wasn't accepted as a joy axis, check for a button press
1096 SDL_GameControllerGetBindForAxis(controller, SDL_CONTROLLER_AXIS_RIGHTX) 1094 auto button_press = button_poller.FromEvent(event);
1097 .value.axis; 1095 if (button_press) {
1098 const auto axis_right_y = 1096 return *button_press;
1099 SDL_GameControllerGetBindForAxis(controller, SDL_CONTROLLER_AXIS_RIGHTY)
1100 .value.axis;
1101
1102 if (axis == axis_left_x || axis == axis_left_y) {
1103 analog_x_axis = axis_left_x;
1104 analog_y_axis = axis_left_y;
1105 break;
1106 } else if (axis == axis_right_x || axis == axis_right_y) {
1107 analog_x_axis = axis_right_x;
1108 analog_y_axis = axis_right_y;
1109 break;
1110 }
1111 } 1097 }
1112 }
1113
1114 // If the press wasn't accepted as a joy axis, check for a button press
1115 auto button_press = button_poller.FromEvent(event);
1116 if (button_press) {
1117 return *button_press;
1118 } 1098 }
1119 } 1099 }
1120 1100
@@ -1127,6 +1107,7 @@ public:
1127 return params; 1107 return params;
1128 } 1108 }
1129 } 1109 }
1110
1130 return {}; 1111 return {};
1131 } 1112 }
1132 1113