diff options
Diffstat (limited to 'src/input_common/sdl/sdl_impl.cpp')
| -rw-r--r-- | src/input_common/sdl/sdl_impl.cpp | 25 |
1 files changed, 23 insertions, 2 deletions
diff --git a/src/input_common/sdl/sdl_impl.cpp b/src/input_common/sdl/sdl_impl.cpp index d32eb732a..a88ae452f 100644 --- a/src/input_common/sdl/sdl_impl.cpp +++ b/src/input_common/sdl/sdl_impl.cpp | |||
| @@ -81,10 +81,14 @@ public: | |||
| 81 | } | 81 | } |
| 82 | 82 | ||
| 83 | bool RumblePlay(u16 amp_low, u16 amp_high) { | 83 | bool RumblePlay(u16 amp_low, u16 amp_high) { |
| 84 | constexpr u32 rumble_max_duration_ms = 1000; | ||
| 85 | |||
| 84 | if (sdl_controller) { | 86 | if (sdl_controller) { |
| 85 | return SDL_GameControllerRumble(sdl_controller.get(), amp_low, amp_high, 0) == 0; | 87 | return SDL_GameControllerRumble(sdl_controller.get(), amp_low, amp_high, |
| 88 | rumble_max_duration_ms) == 0; | ||
| 86 | } else if (sdl_joystick) { | 89 | } else if (sdl_joystick) { |
| 87 | return SDL_JoystickRumble(sdl_joystick.get(), amp_low, amp_high, 0) == 0; | 90 | return SDL_JoystickRumble(sdl_joystick.get(), amp_low, amp_high, |
| 91 | rumble_max_duration_ms) == 0; | ||
| 88 | } | 92 | } |
| 89 | 93 | ||
| 90 | return false; | 94 | return false; |
| @@ -373,6 +377,16 @@ public: | |||
| 373 | return {}; | 377 | return {}; |
| 374 | } | 378 | } |
| 375 | 379 | ||
| 380 | std::tuple<float, float> GetRawStatus() const override { | ||
| 381 | const float x = joystick->GetAxis(axis_x, range); | ||
| 382 | const float y = joystick->GetAxis(axis_y, range); | ||
| 383 | return {x, -y}; | ||
| 384 | } | ||
| 385 | |||
| 386 | Input::AnalogProperties GetAnalogProperties() const override { | ||
| 387 | return {deadzone, range, 0.5f}; | ||
| 388 | } | ||
| 389 | |||
| 376 | bool GetAnalogDirectionStatus(Input::AnalogDirection direction) const override { | 390 | bool GetAnalogDirectionStatus(Input::AnalogDirection direction) const override { |
| 377 | const auto [x, y] = GetStatus(); | 391 | const auto [x, y] = GetStatus(); |
| 378 | const float directional_deadzone = 0.5f; | 392 | const float directional_deadzone = 0.5f; |
| @@ -703,6 +717,13 @@ SDLState::SDLState() { | |||
| 703 | if (SDL_SetHint(SDL_HINT_JOYSTICK_ALLOW_BACKGROUND_EVENTS, "1") == SDL_FALSE) { | 717 | if (SDL_SetHint(SDL_HINT_JOYSTICK_ALLOW_BACKGROUND_EVENTS, "1") == SDL_FALSE) { |
| 704 | LOG_ERROR(Input, "Failed to set hint for background events with: {}", SDL_GetError()); | 718 | LOG_ERROR(Input, "Failed to set hint for background events with: {}", SDL_GetError()); |
| 705 | } | 719 | } |
| 720 | // these hints are only defined on sdl2.0.9 or higher | ||
| 721 | #if SDL_VERSION_ATLEAST(2, 0, 9) | ||
| 722 | #if !SDL_VERSION_ATLEAST(2, 0, 12) | ||
| 723 | // There are also hints to toggle the individual drivers if needed. | ||
| 724 | SDL_SetHint(SDL_HINT_JOYSTICK_HIDAPI, "0"); | ||
| 725 | #endif | ||
| 726 | #endif | ||
| 706 | 727 | ||
| 707 | SDL_AddEventWatch(&SDLEventWatcher, this); | 728 | SDL_AddEventWatch(&SDLEventWatcher, this); |
| 708 | 729 | ||