1
0
Fork 0
forked from suyu/suyu

yuzu: Make controller keys easier to assign

This commit is contained in:
german77 2024-02-05 22:34:05 -06:00 committed by Narr the Reg
parent a2f23746c2
commit 12f86f89fc
3 changed files with 37 additions and 20 deletions

View file

@ -45,15 +45,23 @@ ConfigureHotkeys::ConfigureHotkeys(Core::HID::HIDCore& hid_core, QWidget* parent
controller = hid_core.GetEmulatedController(Core::HID::NpadIdType::Player1); controller = hid_core.GetEmulatedController(Core::HID::NpadIdType::Player1);
connect(timeout_timer.get(), &QTimer::timeout, [this] { SetPollingResult({}, true); }); connect(timeout_timer.get(), &QTimer::timeout, [this] {
const bool is_button_pressed = pressed_buttons != Core::HID::NpadButton::None ||
pressed_home_button || pressed_capture_button;
SetPollingResult(!is_button_pressed);
});
connect(poll_timer.get(), &QTimer::timeout, [this] { connect(poll_timer.get(), &QTimer::timeout, [this] {
const auto buttons = controller->GetNpadButtons(); pressed_buttons |= controller->GetNpadButtons().raw;
const auto home_pressed = controller->GetHomeButtons().home != 0; pressed_home_button |= this->controller->GetHomeButtons().home != 0;
const auto capture_pressed = controller->GetCaptureButtons().capture != 0; pressed_capture_button |= this->controller->GetCaptureButtons().capture != 0;
if (home_pressed || capture_pressed) { if (pressed_buttons != Core::HID::NpadButton::None || pressed_home_button ||
SetPollingResult(buttons.raw, false); pressed_capture_button) {
return; const QString button_name =
GetButtonCombinationName(pressed_buttons, pressed_home_button,
pressed_capture_button) +
QStringLiteral("...");
model->setData(button_model_index, button_name);
} }
}); });
RetranslateUI(); RetranslateUI();
@ -154,16 +162,14 @@ void ConfigureHotkeys::ConfigureController(QModelIndex index) {
const auto previous_key = model->data(index); const auto previous_key = model->data(index);
input_setter = [this, index, previous_key](const Core::HID::NpadButton button, input_setter = [this, index, previous_key](const bool cancel) {
const bool cancel) {
if (cancel) { if (cancel) {
model->setData(index, previous_key); model->setData(index, previous_key);
return; return;
} }
const auto home_pressed = this->controller->GetHomeButtons().home != 0;
const auto capture_pressed = this->controller->GetCaptureButtons().capture != 0;
const QString button_string = const QString button_string =
GetButtonCombinationName(button, home_pressed, capture_pressed); GetButtonCombinationName(pressed_buttons, pressed_home_button, pressed_capture_button);
const auto [key_sequence_used, used_action] = IsUsedControllerKey(button_string); const auto [key_sequence_used, used_action] = IsUsedControllerKey(button_string);
@ -177,17 +183,22 @@ void ConfigureHotkeys::ConfigureController(QModelIndex index) {
} }
}; };
button_model_index = index;
pressed_buttons = Core::HID::NpadButton::None;
pressed_home_button = false;
pressed_capture_button = false;
model->setData(index, tr("[waiting]")); model->setData(index, tr("[waiting]"));
timeout_timer->start(2500); // Cancel after 2.5 seconds timeout_timer->start(2500); // Cancel after 2.5 seconds
poll_timer->start(200); // Check for new inputs every 200ms poll_timer->start(100); // Check for new inputs every 100ms
// We need to disable configuration to be able to read npad buttons // We need to disable configuration to be able to read npad buttons
controller->DisableConfiguration(); controller->DisableConfiguration();
} }
void ConfigureHotkeys::SetPollingResult(Core::HID::NpadButton button, const bool cancel) { void ConfigureHotkeys::SetPollingResult(const bool cancel) {
timeout_timer->stop(); timeout_timer->stop();
poll_timer->stop(); poll_timer->stop();
(*input_setter)(button, cancel); (*input_setter)(cancel);
// Re-Enable configuration // Re-Enable configuration
controller->EnableConfiguration(); controller->EnableConfiguration();

View file

@ -4,6 +4,7 @@
#pragma once #pragma once
#include <memory> #include <memory>
#include <QStandardItemModel>
#include <QWidget> #include <QWidget>
namespace Common { namespace Common {
@ -54,14 +55,20 @@ private:
void RestoreControllerHotkey(QModelIndex index); void RestoreControllerHotkey(QModelIndex index);
void RestoreHotkey(QModelIndex index); void RestoreHotkey(QModelIndex index);
void SetPollingResult(bool cancel);
QString GetButtonCombinationName(Core::HID::NpadButton button, bool home, bool capture) const;
std::unique_ptr<Ui::ConfigureHotkeys> ui; std::unique_ptr<Ui::ConfigureHotkeys> ui;
QStandardItemModel* model; QStandardItemModel* model;
void SetPollingResult(Core::HID::NpadButton button, bool cancel); bool pressed_home_button;
QString GetButtonCombinationName(Core::HID::NpadButton button, bool home, bool capture) const; bool pressed_capture_button;
QModelIndex button_model_index;
Core::HID::NpadButton pressed_buttons;
Core::HID::EmulatedController* controller; Core::HID::EmulatedController* controller;
std::unique_ptr<QTimer> timeout_timer; std::unique_ptr<QTimer> timeout_timer;
std::unique_ptr<QTimer> poll_timer; std::unique_ptr<QTimer> poll_timer;
std::optional<std::function<void(Core::HID::NpadButton, bool)>> input_setter; std::optional<std::function<void(bool)>> input_setter;
}; };

View file

@ -193,8 +193,7 @@ void ControllerShortcut::ControllerUpdateEvent(Core::HID::ControllerTriggerType
if (!Settings::values.controller_navigation) { if (!Settings::values.controller_navigation) {
return; return;
} }
if (button_sequence.npad.raw == Core::HID::NpadButton::None && if (button_sequence.npad.raw == Core::HID::NpadButton::None) {
button_sequence.capture.raw == 0 && button_sequence.home.raw == 0) {
return; return;
} }