diff options
| author | german77 <juangerman-13@hotmail.com> | 2021-11-15 17:57:41 -0600 | 
|---|---|---|
| committer | german77 <juangerman-13@hotmail.com> | 2022-01-06 21:26:05 -0600 | 
| commit | 72c8a94a6cdb4d3f322fa6d4b06eab824f53dba6 (patch) | |
| tree | 1be3b99cfa76a7e7c360fa467d8ea6de69a29dc8 /src/yuzu/configuration | |
| parent | b94e947793dcb53e9e00ef8bf587b2f689d38d41 (diff) | |
yuzu: Add controller hotkeys
Diffstat (limited to 'src/yuzu/configuration')
| -rw-r--r-- | src/yuzu/configuration/config.cpp | 54 | ||||
| -rw-r--r-- | src/yuzu/configuration/configure_dialog.cpp | 2 | ||||
| -rw-r--r-- | src/yuzu/configuration/configure_hotkeys.cpp | 242 | ||||
| -rw-r--r-- | src/yuzu/configuration/configure_hotkeys.h | 23 | 
4 files changed, 262 insertions, 59 deletions
| diff --git a/src/yuzu/configuration/config.cpp b/src/yuzu/configuration/config.cpp index 0f679c37e..99a7397fc 100644 --- a/src/yuzu/configuration/config.cpp +++ b/src/yuzu/configuration/config.cpp @@ -66,27 +66,27 @@ const std::array<int, 2> Config::default_stick_mod = {  // UISetting::values.shortcuts, which is alphabetically ordered.  // clang-format off  const std::array<UISettings::Shortcut, 21> Config::default_hotkeys{{ -    {QStringLiteral("Capture Screenshot"),       QStringLiteral("Main Window"), {QStringLiteral("Ctrl+P"), Qt::WidgetWithChildrenShortcut}}, -    {QStringLiteral("Change Docked Mode"),       QStringLiteral("Main Window"), {QStringLiteral("F10"), Qt::ApplicationShortcut}}, -    {QStringLiteral("Continue/Pause Emulation"), QStringLiteral("Main Window"), {QStringLiteral("F4"), Qt::WindowShortcut}}, -    {QStringLiteral("Decrease Speed Limit"),     QStringLiteral("Main Window"), {QStringLiteral("-"), Qt::ApplicationShortcut}}, -    {QStringLiteral("Exit Fullscreen"),          QStringLiteral("Main Window"), {QStringLiteral("Esc"), Qt::WindowShortcut}}, -    {QStringLiteral("Exit yuzu"),                QStringLiteral("Main Window"), {QStringLiteral("Ctrl+Q"), Qt::WindowShortcut}}, -    {QStringLiteral("Fullscreen"),               QStringLiteral("Main Window"), {QStringLiteral("F11"), Qt::WindowShortcut}}, -    {QStringLiteral("Increase Speed Limit"),     QStringLiteral("Main Window"), {QStringLiteral("+"), Qt::ApplicationShortcut}}, -    {QStringLiteral("Load Amiibo"),              QStringLiteral("Main Window"), {QStringLiteral("F2"), Qt::WidgetWithChildrenShortcut}}, -    {QStringLiteral("Load File"),                QStringLiteral("Main Window"), {QStringLiteral("Ctrl+O"), Qt::WidgetWithChildrenShortcut}}, -    {QStringLiteral("Mute Audio"),               QStringLiteral("Main Window"), {QStringLiteral("Ctrl+M"), Qt::WindowShortcut}}, -    {QStringLiteral("Restart Emulation"),        QStringLiteral("Main Window"), {QStringLiteral("F6"), Qt::WindowShortcut}}, -    {QStringLiteral("Stop Emulation"),           QStringLiteral("Main Window"), {QStringLiteral("F5"), Qt::WindowShortcut}}, -    {QStringLiteral("TAS Start/Stop"),           QStringLiteral("Main Window"), {QStringLiteral("Ctrl+F5"), Qt::ApplicationShortcut}}, -    {QStringLiteral("TAS Reset"),                QStringLiteral("Main Window"), {QStringLiteral("Ctrl+F6"), Qt::ApplicationShortcut}}, -    {QStringLiteral("TAS Record"),               QStringLiteral("Main Window"), {QStringLiteral("Ctrl+F7"), Qt::ApplicationShortcut}}, -    {QStringLiteral("Toggle Filter Bar"),        QStringLiteral("Main Window"), {QStringLiteral("Ctrl+F"), Qt::WindowShortcut}}, -    {QStringLiteral("Toggle Framerate Limit"),   QStringLiteral("Main Window"), {QStringLiteral("Ctrl+U"), Qt::ApplicationShortcut}}, -    {QStringLiteral("Toggle Mouse Panning"),     QStringLiteral("Main Window"), {QStringLiteral("Ctrl+F9"), Qt::ApplicationShortcut}}, -    {QStringLiteral("Toggle Speed Limit"),       QStringLiteral("Main Window"), {QStringLiteral("Ctrl+Z"), Qt::ApplicationShortcut}}, -    {QStringLiteral("Toggle Status Bar"),        QStringLiteral("Main Window"), {QStringLiteral("Ctrl+S"), Qt::WindowShortcut}}, +    {QStringLiteral("Capture Screenshot"),       QStringLiteral("Main Window"), {QStringLiteral("Ctrl+P"),  QStringLiteral("Screenshot"), Qt::WidgetWithChildrenShortcut}}, +    {QStringLiteral("Change Docked Mode"),       QStringLiteral("Main Window"), {QStringLiteral("F10"),     QStringLiteral("Home+X"), Qt::ApplicationShortcut}}, +    {QStringLiteral("Continue/Pause Emulation"), QStringLiteral("Main Window"), {QStringLiteral("F4"),      QStringLiteral("Home+Plus"), Qt::WindowShortcut}}, +    {QStringLiteral("Decrease Speed Limit"),     QStringLiteral("Main Window"), {QStringLiteral("-"),       QStringLiteral(""), Qt::ApplicationShortcut}}, +    {QStringLiteral("Exit Fullscreen"),          QStringLiteral("Main Window"), {QStringLiteral("Esc"),     QStringLiteral(""), Qt::WindowShortcut}}, +    {QStringLiteral("Exit yuzu"),                QStringLiteral("Main Window"), {QStringLiteral("Ctrl+Q"),  QStringLiteral("Home+Minus"), Qt::WindowShortcut}}, +    {QStringLiteral("Fullscreen"),               QStringLiteral("Main Window"), {QStringLiteral("F11"),     QStringLiteral("Home+B"), Qt::WindowShortcut}}, +    {QStringLiteral("Increase Speed Limit"),     QStringLiteral("Main Window"), {QStringLiteral("+"),       QStringLiteral(""), Qt::ApplicationShortcut}}, +    {QStringLiteral("Load Amiibo"),              QStringLiteral("Main Window"), {QStringLiteral("F2"),      QStringLiteral("Home+A"), Qt::WidgetWithChildrenShortcut}}, +    {QStringLiteral("Load File"),                QStringLiteral("Main Window"), {QStringLiteral("Ctrl+O"),  QStringLiteral(""), Qt::WidgetWithChildrenShortcut}}, +    {QStringLiteral("Mute Audio"),               QStringLiteral("Main Window"), {QStringLiteral("Ctrl+M"),  QStringLiteral(""), Qt::WindowShortcut}}, +    {QStringLiteral("Restart Emulation"),        QStringLiteral("Main Window"), {QStringLiteral("F6"),      QStringLiteral(""), Qt::WindowShortcut}}, +    {QStringLiteral("Stop Emulation"),           QStringLiteral("Main Window"), {QStringLiteral("F5"),      QStringLiteral(""), Qt::WindowShortcut}}, +    {QStringLiteral("TAS Start/Stop"),           QStringLiteral("Main Window"), {QStringLiteral("Ctrl+F5"), QStringLiteral(""), Qt::ApplicationShortcut}}, +    {QStringLiteral("TAS Reset"),                QStringLiteral("Main Window"), {QStringLiteral("Ctrl+F6"), QStringLiteral(""), Qt::ApplicationShortcut}}, +    {QStringLiteral("TAS Record"),               QStringLiteral("Main Window"), {QStringLiteral("Ctrl+F7"), QStringLiteral(""), Qt::ApplicationShortcut}}, +    {QStringLiteral("Toggle Filter Bar"),        QStringLiteral("Main Window"), {QStringLiteral("Ctrl+F"),  QStringLiteral(""), Qt::WindowShortcut}}, +    {QStringLiteral("Toggle Framerate Limit"),   QStringLiteral("Main Window"), {QStringLiteral("Ctrl+U"),  QStringLiteral("Home+Y"), Qt::ApplicationShortcut}}, +    {QStringLiteral("Toggle Mouse Panning"),     QStringLiteral("Main Window"), {QStringLiteral("Ctrl+F9"), QStringLiteral(""), Qt::ApplicationShortcut}}, +    {QStringLiteral("Toggle Speed Limit"),       QStringLiteral("Main Window"), {QStringLiteral("Ctrl+Z"),  QStringLiteral(""), Qt::ApplicationShortcut}}, +    {QStringLiteral("Toggle Status Bar"),        QStringLiteral("Main Window"), {QStringLiteral("Ctrl+S"),  QStringLiteral(""), Qt::WindowShortcut}},  }};  // clang-format on @@ -679,7 +679,6 @@ void Config::ReadShortcutValues() {      qt_config->beginGroup(QStringLiteral("Shortcuts"));      for (const auto& [name, group, shortcut] : default_hotkeys) { -        const auto& [keyseq, context] = shortcut;          qt_config->beginGroup(group);          qt_config->beginGroup(name);          // No longer using ReadSetting for shortcut.second as it innacurately returns a value of 1 @@ -688,7 +687,10 @@ void Config::ReadShortcutValues() {          UISettings::values.shortcuts.push_back(              {name,               group, -             {ReadSetting(QStringLiteral("KeySeq"), keyseq).toString(), shortcut.second}}); +             {ReadSetting(QStringLiteral("KeySeq"), shortcut.keyseq).toString(), +              ReadSetting(QStringLiteral("Controller_KeySeq"), shortcut.controller_keyseq) +                  .toString(), +              shortcut.context}});          qt_config->endGroup();          qt_config->endGroup();      } @@ -1227,8 +1229,10 @@ void Config::SaveShortcutValues() {          qt_config->beginGroup(group);          qt_config->beginGroup(name); -        WriteSetting(QStringLiteral("KeySeq"), shortcut.first, default_hotkey.first); -        WriteSetting(QStringLiteral("Context"), shortcut.second, default_hotkey.second); +        WriteSetting(QStringLiteral("KeySeq"), shortcut.keyseq, default_hotkey.keyseq); +        WriteSetting(QStringLiteral("Controller_KeySeq"), shortcut.controller_keyseq, +                     default_hotkey.controller_keyseq); +        WriteSetting(QStringLiteral("Context"), shortcut.context, default_hotkey.context);          qt_config->endGroup();          qt_config->endGroup();      } diff --git a/src/yuzu/configuration/configure_dialog.cpp b/src/yuzu/configuration/configure_dialog.cpp index 642a5f966..464e7a489 100644 --- a/src/yuzu/configuration/configure_dialog.cpp +++ b/src/yuzu/configuration/configure_dialog.cpp @@ -45,7 +45,7 @@ ConfigureDialog::ConfigureDialog(QWidget* parent, HotkeyRegistry& registry,        general_tab{std::make_unique<ConfigureGeneral>(system_, this)},        graphics_tab{std::make_unique<ConfigureGraphics>(system_, this)},        graphics_advanced_tab{std::make_unique<ConfigureGraphicsAdvanced>(system_, this)}, -      hotkeys_tab{std::make_unique<ConfigureHotkeys>(this)}, +      hotkeys_tab{std::make_unique<ConfigureHotkeys>(system_.HIDCore(), this)},        input_tab{std::make_unique<ConfigureInput>(system_, this)},        network_tab{std::make_unique<ConfigureNetwork>(system_, this)},        profile_tab{std::make_unique<ConfigureProfileManager>(system_, this)}, diff --git a/src/yuzu/configuration/configure_hotkeys.cpp b/src/yuzu/configuration/configure_hotkeys.cpp index ed76fe18e..be10e0a31 100644 --- a/src/yuzu/configuration/configure_hotkeys.cpp +++ b/src/yuzu/configuration/configure_hotkeys.cpp @@ -5,15 +5,24 @@  #include <QMenu>  #include <QMessageBox>  #include <QStandardItemModel> -#include "common/settings.h" +#include <QTimer> + +#include "core/hid/emulated_controller.h" +#include "core/hid/hid_core.h" +  #include "ui_configure_hotkeys.h"  #include "yuzu/configuration/config.h"  #include "yuzu/configuration/configure_hotkeys.h"  #include "yuzu/hotkeys.h"  #include "yuzu/util/sequence_dialog/sequence_dialog.h" -ConfigureHotkeys::ConfigureHotkeys(QWidget* parent) -    : QWidget(parent), ui(std::make_unique<Ui::ConfigureHotkeys>()) { +constexpr int name_column = 0; +constexpr int hotkey_column = 1; +constexpr int controller_column = 2; + +ConfigureHotkeys::ConfigureHotkeys(Core::HID::HIDCore& hid_core, QWidget* parent) +    : QWidget(parent), ui(std::make_unique<Ui::ConfigureHotkeys>()), +      timeout_timer(std::make_unique<QTimer>()), poll_timer(std::make_unique<QTimer>()) {      ui->setupUi(this);      setFocusPolicy(Qt::ClickFocus); @@ -26,16 +35,24 @@ ConfigureHotkeys::ConfigureHotkeys(QWidget* parent)      ui->hotkey_list->setContextMenuPolicy(Qt::CustomContextMenu);      ui->hotkey_list->setModel(model); -    // TODO(Kloen): Make context configurable as well (hiding the column for now) -    ui->hotkey_list->hideColumn(2); - -    ui->hotkey_list->setColumnWidth(0, 200); -    ui->hotkey_list->resizeColumnToContents(1); +    ui->hotkey_list->setColumnWidth(name_column, 200); +    ui->hotkey_list->resizeColumnToContents(hotkey_column);      connect(ui->button_restore_defaults, &QPushButton::clicked, this,              &ConfigureHotkeys::RestoreDefaults);      connect(ui->button_clear_all, &QPushButton::clicked, this, &ConfigureHotkeys::ClearAll); +    controller = hid_core.GetEmulatedController(Core::HID::NpadIdType::Player1); + +    connect(timeout_timer.get(), &QTimer::timeout, [this] { SetPollingResult({}, true); }); + +    connect(poll_timer.get(), &QTimer::timeout, [this] { +        const auto buttons = controller->GetNpadButtons(); +        if (buttons.raw != Core::HID::NpadButton::None) { +            SetPollingResult(buttons.raw, false); +            return; +        } +    });      RetranslateUI();  } @@ -49,15 +66,18 @@ void ConfigureHotkeys::Populate(const HotkeyRegistry& registry) {              auto* action = new QStandardItem(hotkey.first);              auto* keyseq =                  new QStandardItem(hotkey.second.keyseq.toString(QKeySequence::NativeText)); +            auto* controller_keyseq = new QStandardItem(hotkey.second.controller_keyseq);              action->setEditable(false);              keyseq->setEditable(false); -            parent_item->appendRow({action, keyseq}); +            controller_keyseq->setEditable(false); +            parent_item->appendRow({action, keyseq, controller_keyseq});          }          model->appendRow(parent_item);      }      ui->hotkey_list->expandAll(); -    ui->hotkey_list->resizeColumnToContents(0); +    ui->hotkey_list->resizeColumnToContents(name_column); +    ui->hotkey_list->resizeColumnToContents(hotkey_column);  }  void ConfigureHotkeys::changeEvent(QEvent* event) { @@ -71,7 +91,7 @@ void ConfigureHotkeys::changeEvent(QEvent* event) {  void ConfigureHotkeys::RetranslateUI() {      ui->retranslateUi(this); -    model->setHorizontalHeaderLabels({tr("Action"), tr("Hotkey"), tr("Context")}); +    model->setHorizontalHeaderLabels({tr("Action"), tr("Hotkey"), tr("Controller Hotkey")});  }  void ConfigureHotkeys::Configure(QModelIndex index) { @@ -79,7 +99,15 @@ void ConfigureHotkeys::Configure(QModelIndex index) {          return;      } -    index = index.sibling(index.row(), 1); +    // Controller configuration is selected +    if (index.column() == controller_column) { +        ConfigureController(index); +        return; +    } + +    // Swap to the hotkey column +    index = index.sibling(index.row(), hotkey_column); +      const auto previous_key = model->data(index);      SequenceDialog hotkey_dialog{this}; @@ -99,13 +127,113 @@ void ConfigureHotkeys::Configure(QModelIndex index) {          model->setData(index, key_sequence.toString(QKeySequence::NativeText));      }  } +void ConfigureHotkeys::ConfigureController(QModelIndex index) { +    if (timeout_timer->isActive()) { +        return; +    } + +    const auto previous_key = model->data(index); + +    input_setter = [this, index, previous_key](const Core::HID::NpadButton button, +                                               const bool cancel) { +        if (cancel) { +            model->setData(index, previous_key); +            return; +        } + +        const QString button_string = tr("Home+%1").arg(GetButtonName(button)); + +        const auto [key_sequence_used, used_action] = IsUsedControllerKey(button_string); + +        if (key_sequence_used) { +            QMessageBox::warning( +                this, tr("Conflicting Key Sequence"), +                tr("The entered key sequence is already assigned to: %1").arg(used_action)); +            model->setData(index, previous_key); +        } else { +            model->setData(index, button_string); +        } +    }; + +    model->setData(index, tr("[waiting]")); +    timeout_timer->start(2500); // Cancel after 2.5 seconds +    poll_timer->start(200);     // Check for new inputs every 200ms +    // We need to disable configuration to be able to read npad buttons +    controller->DisableConfiguration(); +    controller->DisableSystemButtons(); +} + +void ConfigureHotkeys::SetPollingResult(Core::HID::NpadButton button, const bool cancel) { +    timeout_timer->stop(); +    poll_timer->stop(); +    // Re-Enable configuration +    controller->EnableConfiguration(); +    controller->EnableSystemButtons(); + +    (*input_setter)(button, cancel); + +    input_setter = std::nullopt; +} + +QString ConfigureHotkeys::GetButtonName(Core::HID::NpadButton button) const { +    Core::HID::NpadButtonState state{button}; +    if (state.a) { +        return tr("A"); +    } +    if (state.b) { +        return tr("B"); +    } +    if (state.x) { +        return tr("X"); +    } +    if (state.y) { +        return tr("Y"); +    } +    if (state.l || state.right_sl || state.left_sl) { +        return tr("L"); +    } +    if (state.r || state.right_sr || state.left_sr) { +        return tr("R"); +    } +    if (state.zl) { +        return tr("ZL"); +    } +    if (state.zr) { +        return tr("ZR"); +    } +    if (state.left) { +        return tr("Dpad_Left"); +    } +    if (state.right) { +        return tr("Dpad_Right"); +    } +    if (state.up) { +        return tr("Dpad_Up"); +    } +    if (state.down) { +        return tr("Dpad_Down"); +    } +    if (state.stick_l) { +        return tr("Left_Stick"); +    } +    if (state.stick_r) { +        return tr("Right_Stick"); +    } +    if (state.minus) { +        return tr("Minus"); +    } +    if (state.plus) { +        return tr("Plus"); +    } +    return tr("Invalid"); +}  std::pair<bool, QString> ConfigureHotkeys::IsUsedKey(QKeySequence key_sequence) const {      for (int r = 0; r < model->rowCount(); ++r) {          const QStandardItem* const parent = model->item(r, 0);          for (int r2 = 0; r2 < parent->rowCount(); ++r2) { -            const QStandardItem* const key_seq_item = parent->child(r2, 1); +            const QStandardItem* const key_seq_item = parent->child(r2, hotkey_column);              const auto key_seq_str = key_seq_item->text();              const auto key_seq = QKeySequence::fromString(key_seq_str, QKeySequence::NativeText); @@ -118,12 +246,31 @@ std::pair<bool, QString> ConfigureHotkeys::IsUsedKey(QKeySequence key_sequence)      return std::make_pair(false, QString());  } +std::pair<bool, QString> ConfigureHotkeys::IsUsedControllerKey(const QString& key_sequence) const { +    for (int r = 0; r < model->rowCount(); ++r) { +        const QStandardItem* const parent = model->item(r, 0); + +        for (int r2 = 0; r2 < parent->rowCount(); ++r2) { +            const QStandardItem* const key_seq_item = parent->child(r2, controller_column); +            const auto key_seq_str = key_seq_item->text(); + +            if (key_sequence == key_seq_str) { +                return std::make_pair(true, parent->child(r2, 0)->text()); +            } +        } +    } + +    return std::make_pair(false, QString()); +} +  void ConfigureHotkeys::ApplyConfiguration(HotkeyRegistry& registry) {      for (int key_id = 0; key_id < model->rowCount(); key_id++) {          const QStandardItem* parent = model->item(key_id, 0);          for (int key_column_id = 0; key_column_id < parent->rowCount(); key_column_id++) { -            const QStandardItem* action = parent->child(key_column_id, 0); -            const QStandardItem* keyseq = parent->child(key_column_id, 1); +            const QStandardItem* action = parent->child(key_column_id, name_column); +            const QStandardItem* keyseq = parent->child(key_column_id, hotkey_column); +            const QStandardItem* controller_keyseq = +                parent->child(key_column_id, controller_column);              for (auto& [group, sub_actions] : registry.hotkey_groups) {                  if (group != parent->text())                      continue; @@ -131,6 +278,7 @@ void ConfigureHotkeys::ApplyConfiguration(HotkeyRegistry& registry) {                      if (action_name != action->text())                          continue;                      hotkey.keyseq = QKeySequence(keyseq->text()); +                    hotkey.controller_keyseq = controller_keyseq->text();                  }              }          } @@ -144,7 +292,12 @@ void ConfigureHotkeys::RestoreDefaults() {          const QStandardItem* parent = model->item(r, 0);          for (int r2 = 0; r2 < parent->rowCount(); ++r2) { -            model->item(r, 0)->child(r2, 1)->setText(Config::default_hotkeys[r2].shortcut.first); +            model->item(r, 0) +                ->child(r2, hotkey_column) +                ->setText(Config::default_hotkeys[r2].shortcut.keyseq); +            model->item(r, 0) +                ->child(r2, controller_column) +                ->setText(Config::default_hotkeys[r2].shortcut.controller_keyseq);          }      }  } @@ -154,7 +307,8 @@ void ConfigureHotkeys::ClearAll() {          const QStandardItem* parent = model->item(r, 0);          for (int r2 = 0; r2 < parent->rowCount(); ++r2) { -            model->item(r, 0)->child(r2, 1)->setText(QString{}); +            model->item(r, 0)->child(r2, hotkey_column)->setText(QString{}); +            model->item(r, 0)->child(r2, controller_column)->setText(QString{});          }      }  } @@ -165,28 +319,52 @@ void ConfigureHotkeys::PopupContextMenu(const QPoint& menu_location) {          return;      } -    const auto selected = index.sibling(index.row(), 1); +    // Swap to the hotkey column if the controller hotkey column is not selected +    if (index.column() != controller_column) { +        index = index.sibling(index.row(), hotkey_column); +    } +      QMenu context_menu;      QAction* restore_default = context_menu.addAction(tr("Restore Default"));      QAction* clear = context_menu.addAction(tr("Clear")); -    connect(restore_default, &QAction::triggered, [this, selected] { -        const QKeySequence& default_key_sequence = QKeySequence::fromString( -            Config::default_hotkeys[selected.row()].shortcut.first, QKeySequence::NativeText); -        const auto [key_sequence_used, used_action] = IsUsedKey(default_key_sequence); - -        if (key_sequence_used && -            default_key_sequence != QKeySequence(model->data(selected).toString())) { - -            QMessageBox::warning( -                this, tr("Conflicting Key Sequence"), -                tr("The default key sequence is already assigned to: %1").arg(used_action)); -        } else { -            model->setData(selected, default_key_sequence.toString(QKeySequence::NativeText)); +    connect(restore_default, &QAction::triggered, [this, index] { +        if (index.column() == controller_column) { +            RestoreControllerHotkey(index); +            return;          } +        RestoreHotkey(index);      }); -    connect(clear, &QAction::triggered, [this, selected] { model->setData(selected, QString{}); }); +    connect(clear, &QAction::triggered, [this, index] { model->setData(index, QString{}); });      context_menu.exec(ui->hotkey_list->viewport()->mapToGlobal(menu_location));  } + +void ConfigureHotkeys::RestoreControllerHotkey(QModelIndex index) { +    const QString& default_key_sequence = +        Config::default_hotkeys[index.row()].shortcut.controller_keyseq; +    const auto [key_sequence_used, used_action] = IsUsedControllerKey(default_key_sequence); + +    if (key_sequence_used && default_key_sequence != model->data(index).toString()) { +        QMessageBox::warning( +            this, tr("Conflicting Button Sequence"), +            tr("The default button sequence is already assigned to: %1").arg(used_action)); +    } else { +        model->setData(index, default_key_sequence); +    } +} + +void ConfigureHotkeys::RestoreHotkey(QModelIndex index) { +    const QKeySequence& default_key_sequence = QKeySequence::fromString( +        Config::default_hotkeys[index.row()].shortcut.keyseq, QKeySequence::NativeText); +    const auto [key_sequence_used, used_action] = IsUsedKey(default_key_sequence); + +    if (key_sequence_used && default_key_sequence != QKeySequence(model->data(index).toString())) { +        QMessageBox::warning( +            this, tr("Conflicting Key Sequence"), +            tr("The default key sequence is already assigned to: %1").arg(used_action)); +    } else { +        model->setData(index, default_key_sequence.toString(QKeySequence::NativeText)); +    } +} diff --git a/src/yuzu/configuration/configure_hotkeys.h b/src/yuzu/configuration/configure_hotkeys.h index a2ec3323e..f943ec538 100644 --- a/src/yuzu/configuration/configure_hotkeys.h +++ b/src/yuzu/configuration/configure_hotkeys.h @@ -7,6 +7,16 @@  #include <memory>  #include <QWidget> +namespace Common { +class ParamPackage; +} + +namespace Core::HID { +class HIDCore; +class EmulatedController; +enum class NpadButton : u64; +} // namespace Core::HID +  namespace Ui {  class ConfigureHotkeys;  } @@ -18,7 +28,7 @@ class ConfigureHotkeys : public QWidget {      Q_OBJECT  public: -    explicit ConfigureHotkeys(QWidget* parent = nullptr); +    explicit ConfigureHotkeys(Core::HID::HIDCore& hid_core_, QWidget* parent = nullptr);      ~ConfigureHotkeys() override;      void ApplyConfiguration(HotkeyRegistry& registry); @@ -35,13 +45,24 @@ private:      void RetranslateUI();      void Configure(QModelIndex index); +    void ConfigureController(QModelIndex index);      std::pair<bool, QString> IsUsedKey(QKeySequence key_sequence) const; +    std::pair<bool, QString> IsUsedControllerKey(const QString& key_sequence) const;      void RestoreDefaults();      void ClearAll();      void PopupContextMenu(const QPoint& menu_location); +    void RestoreControllerHotkey(QModelIndex index); +    void RestoreHotkey(QModelIndex index);      std::unique_ptr<Ui::ConfigureHotkeys> ui;      QStandardItemModel* model; + +    void SetPollingResult(Core::HID::NpadButton button, bool cancel); +    QString GetButtonName(Core::HID::NpadButton button) const; +    Core::HID::EmulatedController* controller; +    std::unique_ptr<QTimer> timeout_timer; +    std::unique_ptr<QTimer> poll_timer; +    std::optional<std::function<void(Core::HID::NpadButton, bool)>> input_setter;  }; | 
