From 76722813b1ac41fe7eb7633253dba6a57afadccb Mon Sep 17 00:00:00 2001 From: David Griswold Date: Wed, 4 Feb 2026 08:38:08 +0300 Subject: [PATCH] implement qaction hotkey support on controller --- src/citra_qt/citra_qt.cpp | 1 + src/citra_qt/hotkey_monitor.cpp | 3 +++ src/citra_qt/hotkeys.cpp | 6 ++++++ src/citra_qt/hotkeys.h | 11 +++++++++++ 4 files changed, 21 insertions(+) diff --git a/src/citra_qt/citra_qt.cpp b/src/citra_qt/citra_qt.cpp index 5b300ac02..16ce5e509 100644 --- a/src/citra_qt/citra_qt.cpp +++ b/src/citra_qt/citra_qt.cpp @@ -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")); diff --git a/src/citra_qt/hotkey_monitor.cpp b/src/citra_qt/hotkey_monitor.cpp index a1103999b..454f1f3fb 100644 --- a/src/citra_qt/hotkey_monitor.cpp +++ b/src/citra_qt/hotkey_monitor.cpp @@ -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(hotkey_shortcut->parent()); diff --git a/src/citra_qt/hotkeys.cpp b/src/citra_qt/hotkeys.cpp index 0bde5769a..6cce80e11 100644 --- a/src/citra_qt/hotkeys.cpp +++ b/src/citra_qt/hotkeys.cpp @@ -2,6 +2,7 @@ // Licensed under GPLv2 or any later version // Refer to the license.txt file included. +#include #include #include #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; +} diff --git a/src/citra_qt/hotkeys.h b/src/citra_qt/hotkeys.h index a550131c4..141ad0e5f 100644 --- a/src/citra_qt/hotkeys.h +++ b/src/citra_qt/hotkeys.h @@ -5,6 +5,7 @@ #pragma once #include +#include #include #include #include "core/frontend/input.h" @@ -22,6 +23,7 @@ struct Hotkey { Qt::ShortcutContext context = Qt::WindowShortcut; std::unique_ptr button_device = nullptr; std::unique_ptr 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; using HotkeyGroupMap = std::map;