implement qaction hotkey support on controller

This commit is contained in:
David Griswold 2026-02-04 08:38:08 +03:00
parent 20612442fa
commit 76722813b1
4 changed files with 21 additions and 0 deletions

View File

@ -782,6 +782,7 @@ void GMainWindow::InitializeHotkeys() {
this->addAction(action);
if (!primary_only)
secondary_window->addAction(action);
hotkey_registry.SetAction(main_window, action_name, action);
};
link_action_shortcut(ui->action_Load_File, QStringLiteral("Load File"));

View File

@ -54,6 +54,9 @@ void ControllerHotkeyMonitor::checkAllButtons() {
it.lastStatus = currentStatus;
}
if (trigger) {
if (it.hk->action) {
it.hk->action->trigger();
}
for (auto const& [name, hotkey_shortcut] : it.hk->shortcuts) {
if (hotkey_shortcut && hotkey_shortcut->isEnabled()) {
QWidget* parent = qobject_cast<QWidget*>(hotkey_shortcut->parent());

View File

@ -2,6 +2,7 @@
// Licensed under GPLv2 or any later version
// Refer to the license.txt file included.
#include <QAction>
#include <QShortcut>
#include <QtGlobal>
#include "citra_qt/hotkeys.h"
@ -77,3 +78,8 @@ Qt::ShortcutContext HotkeyRegistry::GetShortcutContext(const QString& group,
Hotkey& hk = hotkey_groups[group][action];
return hk.context;
}
void HotkeyRegistry::SetAction(const QString& group, const QString& action_name, QAction* action) {
Hotkey& hk = hotkey_groups[group][action_name];
hk.action = action;
}

View File

@ -5,6 +5,7 @@
#pragma once
#include <map>
#include <QAction>
#include <QKeySequence>
#include <QString>
#include "core/frontend/input.h"
@ -22,6 +23,7 @@ struct Hotkey {
Qt::ShortcutContext context = Qt::WindowShortcut;
std::unique_ptr<Input::ButtonDevice> button_device = nullptr;
std::unique_ptr<Input::ButtonDevice> button_device2 = nullptr;
QAction* action = nullptr;
};
class HotkeyRegistry final {
@ -80,6 +82,15 @@ public:
*/
Qt::ShortcutContext GetShortcutContext(const QString& group, const QString& action);
/**
* Stores a QAction into the appropriate hotkey, for triggering by controller
*
* @param group General group this shortcut context belongs to
* @param action_name Name of the action
* @param action The QAction to store
*/
void SetAction(const QString& group, const QString& action_name, QAction* action);
private:
using HotkeyMap = std::map<QString, Hotkey>;
using HotkeyGroupMap = std::map<QString, HotkeyMap>;