diff options
| author | 2021-06-01 00:51:00 -0700 | |
|---|---|---|
| committer | 2021-06-01 00:51:00 -0700 | |
| commit | 348ca07e0d27e3d2a170fed81b989f1c1e8d5feb (patch) | |
| tree | bf7a3057af90515cc559ac77247f9609ca39c6b1 /src/input_common/sdl/sdl_impl.h | |
| parent | Merge pull request #6367 from ReinUsesLisp/vma-host (diff) | |
| parent | input_common: Add dual joycon support (diff) | |
| download | yuzu-348ca07e0d27e3d2a170fed81b989f1c1e8d5feb.tar.gz yuzu-348ca07e0d27e3d2a170fed81b989f1c1e8d5feb.tar.xz yuzu-348ca07e0d27e3d2a170fed81b989f1c1e8d5feb.zip | |
Merge pull request #6318 from german77/dualJoycon
input_common: Add dual joycon support
Diffstat (limited to 'src/input_common/sdl/sdl_impl.h')
| -rw-r--r-- | src/input_common/sdl/sdl_impl.h | 37 |
1 files changed, 35 insertions, 2 deletions
diff --git a/src/input_common/sdl/sdl_impl.h b/src/input_common/sdl/sdl_impl.h index 121e01913..b77afcbd8 100644 --- a/src/input_common/sdl/sdl_impl.h +++ b/src/input_common/sdl/sdl_impl.h | |||
| @@ -9,6 +9,17 @@ | |||
| 9 | #include <mutex> | 9 | #include <mutex> |
| 10 | #include <thread> | 10 | #include <thread> |
| 11 | #include <unordered_map> | 11 | #include <unordered_map> |
| 12 | |||
| 13 | // Ignore -Wimplicit-fallthrough due to https://github.com/libsdl-org/SDL/issues/4307 | ||
| 14 | #ifdef __GNUC__ | ||
| 15 | #pragma GCC diagnostic push | ||
| 16 | #pragma GCC diagnostic ignored "-Wimplicit-fallthrough" | ||
| 17 | #endif | ||
| 18 | #include <SDL.h> | ||
| 19 | #ifdef __GNUC__ | ||
| 20 | #pragma GCC diagnostic pop | ||
| 21 | #endif | ||
| 22 | |||
| 12 | #include "common/common_types.h" | 23 | #include "common/common_types.h" |
| 13 | #include "common/threadsafe_queue.h" | 24 | #include "common/threadsafe_queue.h" |
| 14 | #include "input_common/sdl/sdl.h" | 25 | #include "input_common/sdl/sdl.h" |
| @@ -18,6 +29,11 @@ using SDL_GameController = struct _SDL_GameController; | |||
| 18 | using SDL_Joystick = struct _SDL_Joystick; | 29 | using SDL_Joystick = struct _SDL_Joystick; |
| 19 | using SDL_JoystickID = s32; | 30 | using SDL_JoystickID = s32; |
| 20 | 31 | ||
| 32 | using ButtonBindings = | ||
| 33 | std::array<std::pair<Settings::NativeButton::Values, SDL_GameControllerButton>, 17>; | ||
| 34 | using ZButtonBindings = | ||
| 35 | std::array<std::pair<Settings::NativeButton::Values, SDL_GameControllerAxis>, 2>; | ||
| 36 | |||
| 21 | namespace InputCommon::SDL { | 37 | namespace InputCommon::SDL { |
| 22 | 38 | ||
| 23 | class SDLAnalogFactory; | 39 | class SDLAnalogFactory; |
| @@ -66,8 +82,25 @@ private: | |||
| 66 | /// Needs to be called before SDL_QuitSubSystem. | 82 | /// Needs to be called before SDL_QuitSubSystem. |
| 67 | void CloseJoysticks(); | 83 | void CloseJoysticks(); |
| 68 | 84 | ||
| 69 | /// Returns a custom name for specific controllers because the default name is not correct | 85 | /// Returns the default button bindings list for generic controllers |
| 70 | std::string GetControllerName(SDL_GameController* controller) const; | 86 | ButtonBindings GetDefaultButtonBinding() const; |
| 87 | |||
| 88 | /// Returns the default button bindings list for nintendo controllers | ||
| 89 | ButtonBindings GetNintendoButtonBinding(const std::shared_ptr<SDLJoystick>& joystick) const; | ||
| 90 | |||
| 91 | /// Returns the button mappings from a single controller | ||
| 92 | ButtonMapping GetSingleControllerMapping(const std::shared_ptr<SDLJoystick>& joystick, | ||
| 93 | const ButtonBindings& switch_to_sdl_button, | ||
| 94 | const ZButtonBindings& switch_to_sdl_axis) const; | ||
| 95 | |||
| 96 | /// Returns the button mappings from two different controllers | ||
| 97 | ButtonMapping GetDualControllerMapping(const std::shared_ptr<SDLJoystick>& joystick, | ||
| 98 | const std::shared_ptr<SDLJoystick>& joystick2, | ||
| 99 | const ButtonBindings& switch_to_sdl_button, | ||
| 100 | const ZButtonBindings& switch_to_sdl_axis) const; | ||
| 101 | |||
| 102 | /// Returns true if the button is on the left joycon | ||
| 103 | bool IsButtonOnLeftSide(Settings::NativeButton::Values button) const; | ||
| 71 | 104 | ||
| 72 | // Set to true if SDL supports game controller subsystem | 105 | // Set to true if SDL supports game controller subsystem |
| 73 | bool has_gamecontroller = false; | 106 | bool has_gamecontroller = false; |