diff options
Diffstat (limited to 'src')
| -rw-r--r-- | src/input_common/keyboard.cpp | 31 | ||||
| -rw-r--r-- | src/input_common/mouse/mouse_input.cpp | 36 | ||||
| -rw-r--r-- | src/input_common/mouse/mouse_input.h | 5 | ||||
| -rw-r--r-- | src/input_common/mouse/mouse_poller.cpp | 20 | ||||
| -rw-r--r-- | src/yuzu/bootmanager.cpp | 8 | ||||
| -rw-r--r-- | src/yuzu/configuration/configure_input_player.cpp | 21 |
6 files changed, 109 insertions, 12 deletions
diff --git a/src/input_common/keyboard.cpp b/src/input_common/keyboard.cpp index 24a6f7a33..c467ff4c5 100644 --- a/src/input_common/keyboard.cpp +++ b/src/input_common/keyboard.cpp | |||
| @@ -12,20 +12,39 @@ namespace InputCommon { | |||
| 12 | 12 | ||
| 13 | class KeyButton final : public Input::ButtonDevice { | 13 | class KeyButton final : public Input::ButtonDevice { |
| 14 | public: | 14 | public: |
| 15 | explicit KeyButton(std::shared_ptr<KeyButtonList> key_button_list_) | 15 | explicit KeyButton(std::shared_ptr<KeyButtonList> key_button_list_, bool toggle_) |
| 16 | : key_button_list(std::move(key_button_list_)) {} | 16 | : key_button_list(std::move(key_button_list_)), toggle(toggle_) {} |
| 17 | 17 | ||
| 18 | ~KeyButton() override; | 18 | ~KeyButton() override; |
| 19 | 19 | ||
| 20 | bool GetStatus() const override { | 20 | bool GetStatus() const override { |
| 21 | if (toggle) { | ||
| 22 | return toggled_status.load(std::memory_order_relaxed); | ||
| 23 | } | ||
| 21 | return status.load(); | 24 | return status.load(); |
| 22 | } | 25 | } |
| 23 | 26 | ||
| 27 | void ToggleButton() { | ||
| 28 | if (lock) { | ||
| 29 | return; | ||
| 30 | } | ||
| 31 | lock = true; | ||
| 32 | const bool old_toggle_status = toggled_status.load(); | ||
| 33 | toggled_status.store(!old_toggle_status); | ||
| 34 | } | ||
| 35 | |||
| 36 | void UnlockButton() { | ||
| 37 | lock = false; | ||
| 38 | } | ||
| 39 | |||
| 24 | friend class KeyButtonList; | 40 | friend class KeyButtonList; |
| 25 | 41 | ||
| 26 | private: | 42 | private: |
| 27 | std::shared_ptr<KeyButtonList> key_button_list; | 43 | std::shared_ptr<KeyButtonList> key_button_list; |
| 28 | std::atomic<bool> status{false}; | 44 | std::atomic<bool> status{false}; |
| 45 | std::atomic<bool> toggled_status{false}; | ||
| 46 | bool lock{false}; | ||
| 47 | const bool toggle; | ||
| 29 | }; | 48 | }; |
| 30 | 49 | ||
| 31 | struct KeyButtonPair { | 50 | struct KeyButtonPair { |
| @@ -51,6 +70,11 @@ public: | |||
| 51 | for (const KeyButtonPair& pair : list) { | 70 | for (const KeyButtonPair& pair : list) { |
| 52 | if (pair.key_code == key_code) { | 71 | if (pair.key_code == key_code) { |
| 53 | pair.key_button->status.store(pressed); | 72 | pair.key_button->status.store(pressed); |
| 73 | if (pressed) { | ||
| 74 | pair.key_button->ToggleButton(); | ||
| 75 | } else { | ||
| 76 | pair.key_button->UnlockButton(); | ||
| 77 | } | ||
| 54 | } | 78 | } |
| 55 | } | 79 | } |
| 56 | } | 80 | } |
| @@ -75,7 +99,8 @@ KeyButton::~KeyButton() { | |||
| 75 | 99 | ||
| 76 | std::unique_ptr<Input::ButtonDevice> Keyboard::Create(const Common::ParamPackage& params) { | 100 | std::unique_ptr<Input::ButtonDevice> Keyboard::Create(const Common::ParamPackage& params) { |
| 77 | const int key_code = params.Get("code", 0); | 101 | const int key_code = params.Get("code", 0); |
| 78 | std::unique_ptr<KeyButton> button = std::make_unique<KeyButton>(key_button_list); | 102 | const bool toggle = params.Get("toggle", false); |
| 103 | std::unique_ptr<KeyButton> button = std::make_unique<KeyButton>(key_button_list, toggle); | ||
| 79 | key_button_list->AddKeyButton(key_code, button.get()); | 104 | key_button_list->AddKeyButton(key_code, button.get()); |
| 80 | return button; | 105 | return button; |
| 81 | } | 106 | } |
diff --git a/src/input_common/mouse/mouse_input.cpp b/src/input_common/mouse/mouse_input.cpp index d81e790ee..329e416c7 100644 --- a/src/input_common/mouse/mouse_input.cpp +++ b/src/input_common/mouse/mouse_input.cpp | |||
| @@ -162,6 +162,42 @@ void Mouse::EndConfiguration() { | |||
| 162 | configuring = false; | 162 | configuring = false; |
| 163 | } | 163 | } |
| 164 | 164 | ||
| 165 | bool Mouse::ToggleButton(std::size_t button_) { | ||
| 166 | if (button_ >= mouse_info.size()) { | ||
| 167 | return false; | ||
| 168 | } | ||
| 169 | const auto button = 1U << button_; | ||
| 170 | const bool button_state = (toggle_buttons & button) != 0; | ||
| 171 | const bool button_lock = (lock_buttons & button) != 0; | ||
| 172 | |||
| 173 | if (button_lock) { | ||
| 174 | return button_state; | ||
| 175 | } | ||
| 176 | |||
| 177 | lock_buttons |= static_cast<u16>(button); | ||
| 178 | |||
| 179 | if (button_state) { | ||
| 180 | toggle_buttons &= static_cast<u16>(0xFF - button); | ||
| 181 | } else { | ||
| 182 | toggle_buttons |= static_cast<u16>(button); | ||
| 183 | } | ||
| 184 | |||
| 185 | return !button_state; | ||
| 186 | } | ||
| 187 | |||
| 188 | bool Mouse::UnlockButton(std::size_t button_) { | ||
| 189 | if (button_ >= mouse_info.size()) { | ||
| 190 | return false; | ||
| 191 | } | ||
| 192 | |||
| 193 | const auto button = 1U << button_; | ||
| 194 | const bool button_state = (toggle_buttons & button) != 0; | ||
| 195 | |||
| 196 | lock_buttons &= static_cast<u16>(0xFF - button); | ||
| 197 | |||
| 198 | return button_state; | ||
| 199 | } | ||
| 200 | |||
| 165 | Common::SPSCQueue<MouseStatus>& Mouse::GetMouseQueue() { | 201 | Common::SPSCQueue<MouseStatus>& Mouse::GetMouseQueue() { |
| 166 | return mouse_queue; | 202 | return mouse_queue; |
| 167 | } | 203 | } |
diff --git a/src/input_common/mouse/mouse_input.h b/src/input_common/mouse/mouse_input.h index 3622fe080..750d9b011 100644 --- a/src/input_common/mouse/mouse_input.h +++ b/src/input_common/mouse/mouse_input.h | |||
| @@ -69,6 +69,9 @@ public: | |||
| 69 | */ | 69 | */ |
| 70 | void ReleaseButton(MouseButton button_); | 70 | void ReleaseButton(MouseButton button_); |
| 71 | 71 | ||
| 72 | [[nodiscard]] bool ToggleButton(std::size_t button_); | ||
| 73 | [[nodiscard]] bool UnlockButton(std::size_t button_); | ||
| 74 | |||
| 72 | [[nodiscard]] Common::SPSCQueue<MouseStatus>& GetMouseQueue(); | 75 | [[nodiscard]] Common::SPSCQueue<MouseStatus>& GetMouseQueue(); |
| 73 | [[nodiscard]] const Common::SPSCQueue<MouseStatus>& GetMouseQueue() const; | 76 | [[nodiscard]] const Common::SPSCQueue<MouseStatus>& GetMouseQueue() const; |
| 74 | 77 | ||
| @@ -94,6 +97,8 @@ private: | |||
| 94 | }; | 97 | }; |
| 95 | 98 | ||
| 96 | u16 buttons{}; | 99 | u16 buttons{}; |
| 100 | u16 toggle_buttons{}; | ||
| 101 | u16 lock_buttons{}; | ||
| 97 | std::thread update_thread; | 102 | std::thread update_thread; |
| 98 | MouseButton last_button{MouseButton::Undefined}; | 103 | MouseButton last_button{MouseButton::Undefined}; |
| 99 | std::array<MouseInfo, 7> mouse_info; | 104 | std::array<MouseInfo, 7> mouse_info; |
diff --git a/src/input_common/mouse/mouse_poller.cpp b/src/input_common/mouse/mouse_poller.cpp index bb56787ee..0e1db54fb 100644 --- a/src/input_common/mouse/mouse_poller.cpp +++ b/src/input_common/mouse/mouse_poller.cpp | |||
| @@ -14,16 +14,25 @@ namespace InputCommon { | |||
| 14 | 14 | ||
| 15 | class MouseButton final : public Input::ButtonDevice { | 15 | class MouseButton final : public Input::ButtonDevice { |
| 16 | public: | 16 | public: |
| 17 | explicit MouseButton(u32 button_, const MouseInput::Mouse* mouse_input_) | 17 | explicit MouseButton(u32 button_, bool toggle_, MouseInput::Mouse* mouse_input_) |
| 18 | : button(button_), mouse_input(mouse_input_) {} | 18 | : button(button_), toggle(toggle_), mouse_input(mouse_input_) {} |
| 19 | 19 | ||
| 20 | bool GetStatus() const override { | 20 | bool GetStatus() const override { |
| 21 | return mouse_input->GetMouseState(button).pressed; | 21 | const bool button_state = mouse_input->GetMouseState(button).pressed; |
| 22 | if (!toggle) { | ||
| 23 | return button_state; | ||
| 24 | } | ||
| 25 | |||
| 26 | if (button_state) { | ||
| 27 | return mouse_input->ToggleButton(button); | ||
| 28 | } | ||
| 29 | return mouse_input->UnlockButton(button); | ||
| 22 | } | 30 | } |
| 23 | 31 | ||
| 24 | private: | 32 | private: |
| 25 | const u32 button; | 33 | const u32 button; |
| 26 | const MouseInput::Mouse* mouse_input; | 34 | const bool toggle; |
| 35 | MouseInput::Mouse* mouse_input; | ||
| 27 | }; | 36 | }; |
| 28 | 37 | ||
| 29 | MouseButtonFactory::MouseButtonFactory(std::shared_ptr<MouseInput::Mouse> mouse_input_) | 38 | MouseButtonFactory::MouseButtonFactory(std::shared_ptr<MouseInput::Mouse> mouse_input_) |
| @@ -32,8 +41,9 @@ MouseButtonFactory::MouseButtonFactory(std::shared_ptr<MouseInput::Mouse> mouse_ | |||
| 32 | std::unique_ptr<Input::ButtonDevice> MouseButtonFactory::Create( | 41 | std::unique_ptr<Input::ButtonDevice> MouseButtonFactory::Create( |
| 33 | const Common::ParamPackage& params) { | 42 | const Common::ParamPackage& params) { |
| 34 | const auto button_id = params.Get("button", 0); | 43 | const auto button_id = params.Get("button", 0); |
| 44 | const auto toggle = params.Get("toggle", false); | ||
| 35 | 45 | ||
| 36 | return std::make_unique<MouseButton>(button_id, mouse_input.get()); | 46 | return std::make_unique<MouseButton>(button_id, toggle, mouse_input.get()); |
| 37 | } | 47 | } |
| 38 | 48 | ||
| 39 | Common::ParamPackage MouseButtonFactory::GetNextInput() const { | 49 | Common::ParamPackage MouseButtonFactory::GetNextInput() const { |
diff --git a/src/yuzu/bootmanager.cpp b/src/yuzu/bootmanager.cpp index ae49cbb45..15c09e0ad 100644 --- a/src/yuzu/bootmanager.cpp +++ b/src/yuzu/bootmanager.cpp | |||
| @@ -376,11 +376,15 @@ void GRenderWindow::closeEvent(QCloseEvent* event) { | |||
| 376 | } | 376 | } |
| 377 | 377 | ||
| 378 | void GRenderWindow::keyPressEvent(QKeyEvent* event) { | 378 | void GRenderWindow::keyPressEvent(QKeyEvent* event) { |
| 379 | input_subsystem->GetKeyboard()->PressKey(event->key()); | 379 | if (!event->isAutoRepeat()) { |
| 380 | input_subsystem->GetKeyboard()->PressKey(event->key()); | ||
| 381 | } | ||
| 380 | } | 382 | } |
| 381 | 383 | ||
| 382 | void GRenderWindow::keyReleaseEvent(QKeyEvent* event) { | 384 | void GRenderWindow::keyReleaseEvent(QKeyEvent* event) { |
| 383 | input_subsystem->GetKeyboard()->ReleaseKey(event->key()); | 385 | if (!event->isAutoRepeat()) { |
| 386 | input_subsystem->GetKeyboard()->ReleaseKey(event->key()); | ||
| 387 | } | ||
| 384 | } | 388 | } |
| 385 | 389 | ||
| 386 | MouseInput::MouseButton GRenderWindow::QtButtonToMouseButton(Qt::MouseButton button) { | 390 | MouseInput::MouseButton GRenderWindow::QtButtonToMouseButton(Qt::MouseButton button) { |
diff --git a/src/yuzu/configuration/configure_input_player.cpp b/src/yuzu/configuration/configure_input_player.cpp index bc572d319..c9318c562 100644 --- a/src/yuzu/configuration/configure_input_player.cpp +++ b/src/yuzu/configuration/configure_input_player.cpp | |||
| @@ -105,7 +105,9 @@ QString ButtonToText(const Common::ParamPackage& param) { | |||
| 105 | } | 105 | } |
| 106 | 106 | ||
| 107 | if (param.Get("engine", "") == "keyboard") { | 107 | if (param.Get("engine", "") == "keyboard") { |
| 108 | return GetKeyName(param.Get("code", 0)); | 108 | const QString button_str = GetKeyName(param.Get("code", 0)); |
| 109 | const QString toggle = QString::fromStdString(param.Get("toggle", false) ? "~" : ""); | ||
| 110 | return QObject::tr("%1%2").arg(toggle, button_str); | ||
| 109 | } | 111 | } |
| 110 | 112 | ||
| 111 | if (param.Get("engine", "") == "gcpad") { | 113 | if (param.Get("engine", "") == "gcpad") { |
| @@ -157,7 +159,8 @@ QString ButtonToText(const Common::ParamPackage& param) { | |||
| 157 | if (param.Get("engine", "") == "mouse") { | 159 | if (param.Get("engine", "") == "mouse") { |
| 158 | if (param.Has("button")) { | 160 | if (param.Has("button")) { |
| 159 | const QString button_str = QString::number(int(param.Get("button", 0))); | 161 | const QString button_str = QString::number(int(param.Get("button", 0))); |
| 160 | return QObject::tr("Click %1").arg(button_str); | 162 | const QString toggle = QString::fromStdString(param.Get("toggle", false) ? "~" : ""); |
| 163 | return QObject::tr("%1Click %2").arg(toggle, button_str); | ||
| 161 | } | 164 | } |
| 162 | return GetKeyName(param.Get("code", 0)); | 165 | return GetKeyName(param.Get("code", 0)); |
| 163 | } | 166 | } |
| @@ -301,6 +304,11 @@ ConfigureInputPlayer::ConfigureInputPlayer(QWidget* parent, std::size_t player_i | |||
| 301 | buttons_param[button_id].Clear(); | 304 | buttons_param[button_id].Clear(); |
| 302 | button_map[button_id]->setText(tr("[not set]")); | 305 | button_map[button_id]->setText(tr("[not set]")); |
| 303 | }); | 306 | }); |
| 307 | context_menu.addAction(tr("Toggle button"), [&] { | ||
| 308 | const bool toggle_value = !buttons_param[button_id].Get("toggle", false); | ||
| 309 | buttons_param[button_id].Set("toggle", toggle_value); | ||
| 310 | button_map[button_id]->setText(ButtonToText(buttons_param[button_id])); | ||
| 311 | }); | ||
| 304 | context_menu.exec(button_map[button_id]->mapToGlobal(menu_location)); | 312 | context_menu.exec(button_map[button_id]->mapToGlobal(menu_location)); |
| 305 | ui->controllerFrame->SetPlayerInput(player_index, buttons_param, analogs_param); | 313 | ui->controllerFrame->SetPlayerInput(player_index, buttons_param, analogs_param); |
| 306 | }); | 314 | }); |
| @@ -413,6 +421,15 @@ ConfigureInputPlayer::ConfigureInputPlayer(QWidget* parent, std::size_t player_i | |||
| 413 | analogs_param[analog_id].Set("modifier", ""); | 421 | analogs_param[analog_id].Set("modifier", ""); |
| 414 | analog_map_modifier_button[analog_id]->setText(tr("[not set]")); | 422 | analog_map_modifier_button[analog_id]->setText(tr("[not set]")); |
| 415 | }); | 423 | }); |
| 424 | context_menu.addAction(tr("Toggle button"), [&] { | ||
| 425 | Common::ParamPackage modifier_param = | ||
| 426 | Common::ParamPackage{analogs_param[analog_id].Get("modifier", "")}; | ||
| 427 | const bool toggle_value = !modifier_param.Get("toggle", false); | ||
| 428 | modifier_param.Set("toggle", toggle_value); | ||
| 429 | analogs_param[analog_id].Set("modifier", modifier_param.Serialize()); | ||
| 430 | analog_map_modifier_button[analog_id]->setText( | ||
| 431 | ButtonToText(modifier_param)); | ||
| 432 | }); | ||
| 416 | context_menu.exec( | 433 | context_menu.exec( |
| 417 | analog_map_modifier_button[analog_id]->mapToGlobal(menu_location)); | 434 | analog_map_modifier_button[analog_id]->mapToGlobal(menu_location)); |
| 418 | }); | 435 | }); |