diff options
Diffstat (limited to 'src')
| -rw-r--r-- | src/yuzu/configuration/configure_hotkeys.cpp | 41 | ||||
| -rw-r--r-- | src/yuzu/configuration/configure_hotkeys.h | 13 | ||||
| -rw-r--r-- | src/yuzu/hotkeys.cpp | 3 |
3 files changed, 37 insertions, 20 deletions
diff --git a/src/yuzu/configuration/configure_hotkeys.cpp b/src/yuzu/configuration/configure_hotkeys.cpp index 3d18670ce..3f68de12d 100644 --- a/src/yuzu/configuration/configure_hotkeys.cpp +++ b/src/yuzu/configuration/configure_hotkeys.cpp | |||
| @@ -45,15 +45,23 @@ ConfigureHotkeys::ConfigureHotkeys(Core::HID::HIDCore& hid_core, QWidget* parent | |||
| 45 | 45 | ||
| 46 | controller = hid_core.GetEmulatedController(Core::HID::NpadIdType::Player1); | 46 | controller = hid_core.GetEmulatedController(Core::HID::NpadIdType::Player1); |
| 47 | 47 | ||
| 48 | connect(timeout_timer.get(), &QTimer::timeout, [this] { SetPollingResult({}, true); }); | 48 | connect(timeout_timer.get(), &QTimer::timeout, [this] { |
| 49 | const bool is_button_pressed = pressed_buttons != Core::HID::NpadButton::None || | ||
| 50 | pressed_home_button || pressed_capture_button; | ||
| 51 | SetPollingResult(!is_button_pressed); | ||
| 52 | }); | ||
| 49 | 53 | ||
| 50 | connect(poll_timer.get(), &QTimer::timeout, [this] { | 54 | connect(poll_timer.get(), &QTimer::timeout, [this] { |
| 51 | const auto buttons = controller->GetNpadButtons(); | 55 | pressed_buttons |= controller->GetNpadButtons().raw; |
| 52 | const auto home_pressed = controller->GetHomeButtons().home != 0; | 56 | pressed_home_button |= this->controller->GetHomeButtons().home != 0; |
| 53 | const auto capture_pressed = controller->GetCaptureButtons().capture != 0; | 57 | pressed_capture_button |= this->controller->GetCaptureButtons().capture != 0; |
| 54 | if (home_pressed || capture_pressed) { | 58 | if (pressed_buttons != Core::HID::NpadButton::None || pressed_home_button || |
| 55 | SetPollingResult(buttons.raw, false); | 59 | pressed_capture_button) { |
| 56 | return; | 60 | const QString button_name = |
| 61 | GetButtonCombinationName(pressed_buttons, pressed_home_button, | ||
| 62 | pressed_capture_button) + | ||
| 63 | QStringLiteral("..."); | ||
| 64 | model->setData(button_model_index, button_name); | ||
| 57 | } | 65 | } |
| 58 | }); | 66 | }); |
| 59 | RetranslateUI(); | 67 | RetranslateUI(); |
| @@ -154,16 +162,14 @@ void ConfigureHotkeys::ConfigureController(QModelIndex index) { | |||
| 154 | 162 | ||
| 155 | const auto previous_key = model->data(index); | 163 | const auto previous_key = model->data(index); |
| 156 | 164 | ||
| 157 | input_setter = [this, index, previous_key](const Core::HID::NpadButton button, | 165 | input_setter = [this, index, previous_key](const bool cancel) { |
| 158 | const bool cancel) { | ||
| 159 | if (cancel) { | 166 | if (cancel) { |
| 160 | model->setData(index, previous_key); | 167 | model->setData(index, previous_key); |
| 161 | return; | 168 | return; |
| 162 | } | 169 | } |
| 163 | const auto home_pressed = this->controller->GetHomeButtons().home != 0; | 170 | |
| 164 | const auto capture_pressed = this->controller->GetCaptureButtons().capture != 0; | ||
| 165 | const QString button_string = | 171 | const QString button_string = |
| 166 | GetButtonCombinationName(button, home_pressed, capture_pressed); | 172 | GetButtonCombinationName(pressed_buttons, pressed_home_button, pressed_capture_button); |
| 167 | 173 | ||
| 168 | const auto [key_sequence_used, used_action] = IsUsedControllerKey(button_string); | 174 | const auto [key_sequence_used, used_action] = IsUsedControllerKey(button_string); |
| 169 | 175 | ||
| @@ -177,17 +183,22 @@ void ConfigureHotkeys::ConfigureController(QModelIndex index) { | |||
| 177 | } | 183 | } |
| 178 | }; | 184 | }; |
| 179 | 185 | ||
| 186 | button_model_index = index; | ||
| 187 | pressed_buttons = Core::HID::NpadButton::None; | ||
| 188 | pressed_home_button = false; | ||
| 189 | pressed_capture_button = false; | ||
| 190 | |||
| 180 | model->setData(index, tr("[waiting]")); | 191 | model->setData(index, tr("[waiting]")); |
| 181 | timeout_timer->start(2500); // Cancel after 2.5 seconds | 192 | timeout_timer->start(2500); // Cancel after 2.5 seconds |
| 182 | poll_timer->start(200); // Check for new inputs every 200ms | 193 | poll_timer->start(100); // Check for new inputs every 100ms |
| 183 | // We need to disable configuration to be able to read npad buttons | 194 | // We need to disable configuration to be able to read npad buttons |
| 184 | controller->DisableConfiguration(); | 195 | controller->DisableConfiguration(); |
| 185 | } | 196 | } |
| 186 | 197 | ||
| 187 | void ConfigureHotkeys::SetPollingResult(Core::HID::NpadButton button, const bool cancel) { | 198 | void ConfigureHotkeys::SetPollingResult(const bool cancel) { |
| 188 | timeout_timer->stop(); | 199 | timeout_timer->stop(); |
| 189 | poll_timer->stop(); | 200 | poll_timer->stop(); |
| 190 | (*input_setter)(button, cancel); | 201 | (*input_setter)(cancel); |
| 191 | // Re-Enable configuration | 202 | // Re-Enable configuration |
| 192 | controller->EnableConfiguration(); | 203 | controller->EnableConfiguration(); |
| 193 | 204 | ||
diff --git a/src/yuzu/configuration/configure_hotkeys.h b/src/yuzu/configuration/configure_hotkeys.h index 5fd1bcbfe..20ea3b515 100644 --- a/src/yuzu/configuration/configure_hotkeys.h +++ b/src/yuzu/configuration/configure_hotkeys.h | |||
| @@ -4,6 +4,7 @@ | |||
| 4 | #pragma once | 4 | #pragma once |
| 5 | 5 | ||
| 6 | #include <memory> | 6 | #include <memory> |
| 7 | #include <QStandardItemModel> | ||
| 7 | #include <QWidget> | 8 | #include <QWidget> |
| 8 | 9 | ||
| 9 | namespace Common { | 10 | namespace Common { |
| @@ -54,14 +55,20 @@ private: | |||
| 54 | void RestoreControllerHotkey(QModelIndex index); | 55 | void RestoreControllerHotkey(QModelIndex index); |
| 55 | void RestoreHotkey(QModelIndex index); | 56 | void RestoreHotkey(QModelIndex index); |
| 56 | 57 | ||
| 58 | void SetPollingResult(bool cancel); | ||
| 59 | QString GetButtonCombinationName(Core::HID::NpadButton button, bool home, bool capture) const; | ||
| 60 | |||
| 57 | std::unique_ptr<Ui::ConfigureHotkeys> ui; | 61 | std::unique_ptr<Ui::ConfigureHotkeys> ui; |
| 58 | 62 | ||
| 59 | QStandardItemModel* model; | 63 | QStandardItemModel* model; |
| 60 | 64 | ||
| 61 | void SetPollingResult(Core::HID::NpadButton button, bool cancel); | 65 | bool pressed_home_button; |
| 62 | QString GetButtonCombinationName(Core::HID::NpadButton button, bool home, bool capture) const; | 66 | bool pressed_capture_button; |
| 67 | QModelIndex button_model_index; | ||
| 68 | Core::HID::NpadButton pressed_buttons; | ||
| 69 | |||
| 63 | Core::HID::EmulatedController* controller; | 70 | Core::HID::EmulatedController* controller; |
| 64 | std::unique_ptr<QTimer> timeout_timer; | 71 | std::unique_ptr<QTimer> timeout_timer; |
| 65 | std::unique_ptr<QTimer> poll_timer; | 72 | std::unique_ptr<QTimer> poll_timer; |
| 66 | std::optional<std::function<void(Core::HID::NpadButton, bool)>> input_setter; | 73 | std::optional<std::function<void(bool)>> input_setter; |
| 67 | }; | 74 | }; |
diff --git a/src/yuzu/hotkeys.cpp b/src/yuzu/hotkeys.cpp index b7693ad0d..170f14684 100644 --- a/src/yuzu/hotkeys.cpp +++ b/src/yuzu/hotkeys.cpp | |||
| @@ -193,8 +193,7 @@ void ControllerShortcut::ControllerUpdateEvent(Core::HID::ControllerTriggerType | |||
| 193 | if (!Settings::values.controller_navigation) { | 193 | if (!Settings::values.controller_navigation) { |
| 194 | return; | 194 | return; |
| 195 | } | 195 | } |
| 196 | if (button_sequence.npad.raw == Core::HID::NpadButton::None && | 196 | if (button_sequence.npad.raw == Core::HID::NpadButton::None) { |
| 197 | button_sequence.capture.raw == 0 && button_sequence.home.raw == 0) { | ||
| 198 | return; | 197 | return; |
| 199 | } | 198 | } |
| 200 | 199 | ||