summaryrefslogtreecommitdiffstats
path: root/src/input_common/sdl/sdl_impl.cpp
diff options
context:
space:
mode:
Diffstat (limited to '')
-rw-r--r--src/input_common/sdl/sdl_impl.cpp37
1 files changed, 27 insertions, 10 deletions
diff --git a/src/input_common/sdl/sdl_impl.cpp b/src/input_common/sdl/sdl_impl.cpp
index f102410d1..ecb00d428 100644
--- a/src/input_common/sdl/sdl_impl.cpp
+++ b/src/input_common/sdl/sdl_impl.cpp
@@ -21,7 +21,7 @@
#include "common/logging/log.h"
#include "common/math_util.h"
#include "common/param_package.h"
-#include "common/settings_input.h"
+#include "common/settings.h"
#include "common/threadsafe_queue.h"
#include "core/frontend/input.h"
#include "input_common/motion_input.h"
@@ -170,7 +170,8 @@ public:
float GetAxis(int axis, float range, float offset) const {
std::lock_guard lock{mutex};
const float value = static_cast<float>(state.axes.at(axis)) / 32767.0f;
- return (value + offset) / range;
+ const float offset_scale = (value + offset) > 0.0f ? 1.0f + offset : 1.0f - offset;
+ return (value + offset) / range / offset_scale;
}
bool RumblePlay(u16 amp_low, u16 amp_high) {
@@ -254,11 +255,25 @@ public:
}
bool IsJoyconLeft() const {
- return std::strstr(GetControllerName().c_str(), "Joy-Con Left") != nullptr;
+ const std::string controller_name = GetControllerName();
+ if (std::strstr(controller_name.c_str(), "Joy-Con Left") != nullptr) {
+ return true;
+ }
+ if (std::strstr(controller_name.c_str(), "Joy-Con (L)") != nullptr) {
+ return true;
+ }
+ return false;
}
bool IsJoyconRight() const {
- return std::strstr(GetControllerName().c_str(), "Joy-Con Right") != nullptr;
+ const std::string controller_name = GetControllerName();
+ if (std::strstr(controller_name.c_str(), "Joy-Con Right") != nullptr) {
+ return true;
+ }
+ if (std::strstr(controller_name.c_str(), "Joy-Con (R)") != nullptr) {
+ return true;
+ }
+ return false;
}
std::string GetControllerName() const {
@@ -775,8 +790,8 @@ public:
const std::string invert_y_value = params.Get("invert_y", "+");
const bool invert_x = invert_x_value == "-";
const bool invert_y = invert_y_value == "-";
- const float offset_x = params.Get("offset_x", 0.0f);
- const float offset_y = params.Get("offset_y", 0.0f);
+ const float offset_x = std::clamp(params.Get("offset_x", 0.0f), -0.99f, 0.99f);
+ const float offset_y = std::clamp(params.Get("offset_y", 0.0f), -0.99f, 0.99f);
auto joystick = state.GetSDLJoystickByGUID(guid, port);
// This is necessary so accessing GetAxis with axis_x and axis_y won't crash
@@ -889,8 +904,10 @@ SDLState::SDLState() {
RegisterFactory<VibrationDevice>("sdl", vibration_factory);
RegisterFactory<MotionDevice>("sdl", motion_factory);
- // Disable raw input. When enabled this setting causes SDL to die when a web applet opens
- SDL_SetHint(SDL_HINT_JOYSTICK_RAWINPUT, "0");
+ if (!Settings::values.enable_raw_input) {
+ // Disable raw input. When enabled this setting causes SDL to die when a web applet opens
+ SDL_SetHint(SDL_HINT_JOYSTICK_RAWINPUT, "0");
+ }
// Enable HIDAPI rumble. This prevents SDL from disabling motion on PS4 and PS5 controllers
SDL_SetHint(SDL_HINT_JOYSTICK_HIDAPI_PS4_RUMBLE, "1");
@@ -898,10 +915,10 @@ SDLState::SDLState() {
// Tell SDL2 to use the hidapi driver. This will allow joycons to be detected as a
// GameController and not a generic one
- SDL_SetHint("SDL_JOYSTICK_HIDAPI_JOY_CONS", "1");
+ SDL_SetHint(SDL_HINT_JOYSTICK_HIDAPI_JOY_CONS, "1");
// Turn off Pro controller home led
- SDL_SetHint("SDL_JOYSTICK_HIDAPI_SWITCH_HOME_LED", "0");
+ SDL_SetHint(SDL_HINT_JOYSTICK_HIDAPI_SWITCH_HOME_LED, "0");
// If the frontend is going to manage the event loop, then we don't start one here
start_thread = SDL_WasInit(SDL_INIT_JOYSTICK) == 0;