diff options
Diffstat (limited to 'src')
| -rw-r--r-- | src/input_common/sdl/sdl_impl.cpp | 55 | ||||
| -rw-r--r-- | src/yuzu/configuration/configure_input_player.cpp | 3 |
2 files changed, 53 insertions, 5 deletions
diff --git a/src/input_common/sdl/sdl_impl.cpp b/src/input_common/sdl/sdl_impl.cpp index 1656b85fb..7778b3562 100644 --- a/src/input_common/sdl/sdl_impl.cpp +++ b/src/input_common/sdl/sdl_impl.cpp | |||
| @@ -115,6 +115,41 @@ public: | |||
| 115 | return state.buttons.at(button); | 115 | return state.buttons.at(button); |
| 116 | } | 116 | } |
| 117 | 117 | ||
| 118 | bool ToggleButton(int button) { | ||
| 119 | std::lock_guard lock{mutex}; | ||
| 120 | |||
| 121 | if (!state.toggle_buttons.contains(button) || !state.lock_buttons.contains(button)) { | ||
| 122 | state.toggle_buttons.insert_or_assign(button, false); | ||
| 123 | state.lock_buttons.insert_or_assign(button, false); | ||
| 124 | } | ||
| 125 | |||
| 126 | const bool button_state = state.toggle_buttons.at(button); | ||
| 127 | const bool button_lock = state.lock_buttons.at(button); | ||
| 128 | |||
| 129 | if (button_lock) { | ||
| 130 | return button_state; | ||
| 131 | } | ||
| 132 | |||
| 133 | state.lock_buttons.insert_or_assign(button, true); | ||
| 134 | |||
| 135 | if (button_state) { | ||
| 136 | state.toggle_buttons.insert_or_assign(button, false); | ||
| 137 | } else { | ||
| 138 | state.toggle_buttons.insert_or_assign(button, true); | ||
| 139 | } | ||
| 140 | |||
| 141 | return !button_state; | ||
| 142 | } | ||
| 143 | |||
| 144 | bool UnlockButton(int button) { | ||
| 145 | std::lock_guard lock{mutex}; | ||
| 146 | if (!state.toggle_buttons.contains(button)) { | ||
| 147 | return false; | ||
| 148 | } | ||
| 149 | state.lock_buttons.insert_or_assign(button, false); | ||
| 150 | return state.toggle_buttons.at(button); | ||
| 151 | } | ||
| 152 | |||
| 118 | void SetAxis(int axis, Sint16 value) { | 153 | void SetAxis(int axis, Sint16 value) { |
| 119 | std::lock_guard lock{mutex}; | 154 | std::lock_guard lock{mutex}; |
| 120 | state.axes.insert_or_assign(axis, value); | 155 | state.axes.insert_or_assign(axis, value); |
| @@ -241,6 +276,8 @@ public: | |||
| 241 | private: | 276 | private: |
| 242 | struct State { | 277 | struct State { |
| 243 | std::unordered_map<int, bool> buttons; | 278 | std::unordered_map<int, bool> buttons; |
| 279 | std::unordered_map<int, bool> toggle_buttons{}; | ||
| 280 | std::unordered_map<int, bool> lock_buttons{}; | ||
| 244 | std::unordered_map<int, Sint16> axes; | 281 | std::unordered_map<int, Sint16> axes; |
| 245 | std::unordered_map<int, Uint8> hats; | 282 | std::unordered_map<int, Uint8> hats; |
| 246 | } state; | 283 | } state; |
| @@ -402,16 +439,25 @@ void SDLState::CloseJoysticks() { | |||
| 402 | 439 | ||
| 403 | class SDLButton final : public Input::ButtonDevice { | 440 | class SDLButton final : public Input::ButtonDevice { |
| 404 | public: | 441 | public: |
| 405 | explicit SDLButton(std::shared_ptr<SDLJoystick> joystick_, int button_) | 442 | explicit SDLButton(std::shared_ptr<SDLJoystick> joystick_, int button_, bool toggle_) |
| 406 | : joystick(std::move(joystick_)), button(button_) {} | 443 | : joystick(std::move(joystick_)), button(button_), toggle(toggle_) {} |
| 407 | 444 | ||
| 408 | bool GetStatus() const override { | 445 | bool GetStatus() const override { |
| 409 | return joystick->GetButton(button); | 446 | const bool button_state = joystick->GetButton(button); |
| 447 | if (!toggle) { | ||
| 448 | return button_state; | ||
| 449 | } | ||
| 450 | |||
| 451 | if (button_state) { | ||
| 452 | return joystick->ToggleButton(button); | ||
| 453 | } | ||
| 454 | return joystick->UnlockButton(button); | ||
| 410 | } | 455 | } |
| 411 | 456 | ||
| 412 | private: | 457 | private: |
| 413 | std::shared_ptr<SDLJoystick> joystick; | 458 | std::shared_ptr<SDLJoystick> joystick; |
| 414 | int button; | 459 | int button; |
| 460 | bool toggle; | ||
| 415 | }; | 461 | }; |
| 416 | 462 | ||
| 417 | class SDLDirectionButton final : public Input::ButtonDevice { | 463 | class SDLDirectionButton final : public Input::ButtonDevice { |
| @@ -635,6 +681,7 @@ public: | |||
| 635 | std::unique_ptr<Input::ButtonDevice> Create(const Common::ParamPackage& params) override { | 681 | std::unique_ptr<Input::ButtonDevice> Create(const Common::ParamPackage& params) override { |
| 636 | const std::string guid = params.Get("guid", "0"); | 682 | const std::string guid = params.Get("guid", "0"); |
| 637 | const int port = params.Get("port", 0); | 683 | const int port = params.Get("port", 0); |
| 684 | const auto toggle = params.Get("toggle", false); | ||
| 638 | 685 | ||
| 639 | auto joystick = state.GetSDLJoystickByGUID(guid, port); | 686 | auto joystick = state.GetSDLJoystickByGUID(guid, port); |
| 640 | 687 | ||
| @@ -679,7 +726,7 @@ public: | |||
| 679 | const int button = params.Get("button", 0); | 726 | const int button = params.Get("button", 0); |
| 680 | // This is necessary so accessing GetButton with button won't crash | 727 | // This is necessary so accessing GetButton with button won't crash |
| 681 | joystick->SetButton(button, false); | 728 | joystick->SetButton(button, false); |
| 682 | return std::make_unique<SDLButton>(joystick, button); | 729 | return std::make_unique<SDLButton>(joystick, button, toggle); |
| 683 | } | 730 | } |
| 684 | 731 | ||
| 685 | private: | 732 | private: |
diff --git a/src/yuzu/configuration/configure_input_player.cpp b/src/yuzu/configuration/configure_input_player.cpp index d5d624b96..14579c220 100644 --- a/src/yuzu/configuration/configure_input_player.cpp +++ b/src/yuzu/configuration/configure_input_player.cpp | |||
| @@ -149,8 +149,9 @@ QString ButtonToText(const Common::ParamPackage& param) { | |||
| 149 | 149 | ||
| 150 | if (param.Has("button")) { | 150 | if (param.Has("button")) { |
| 151 | const QString button_str = QString::fromStdString(param.Get("button", "")); | 151 | const QString button_str = QString::fromStdString(param.Get("button", "")); |
| 152 | const QString toggle = QString::fromStdString(param.Get("toggle", false) ? "~" : ""); | ||
| 152 | 153 | ||
| 153 | return QObject::tr("Button %1").arg(button_str); | 154 | return QObject::tr("%1Button %2").arg(toggle, button_str); |
| 154 | } | 155 | } |
| 155 | 156 | ||
| 156 | if (param.Has("motion")) { | 157 | if (param.Has("motion")) { |