From e13c4deb2478eb47366cfd86a20c39db6c956640 Mon Sep 17 00:00:00 2001 From: David Griswold Date: Thu, 2 Apr 2026 20:54:59 +0300 Subject: [PATCH] honor shortcut context with controller hotkeys --- src/citra_qt/hotkey_monitor.cpp | 23 ++++++++++++++++++++++- src/citra_qt/hotkeys.h | 2 +- 2 files changed, 23 insertions(+), 2 deletions(-) diff --git a/src/citra_qt/hotkey_monitor.cpp b/src/citra_qt/hotkey_monitor.cpp index 0a4b81796..7ffce7df1 100644 --- a/src/citra_qt/hotkey_monitor.cpp +++ b/src/citra_qt/hotkey_monitor.cpp @@ -3,6 +3,7 @@ // Refer to the license.txt file included. #include +#include #include #include #include @@ -39,8 +40,11 @@ void ControllerHotkeyMonitor::removeButton(const QString& name) { } void ControllerHotkeyMonitor::checkAllButtons() { + // Controller Hotkeys for (auto& [name, it] : *m_buttons) { bool trigger = false; + if (!it.hk || !it.hk->button_device) + continue; bool currentStatus = it.hk->button_device->GetStatus(); if (it.hk->button_device2) { // two buttons, need both pressed and one *just now* pressed @@ -60,7 +64,24 @@ void ControllerHotkeyMonitor::checkAllButtons() { for (auto const& [name, hotkey_shortcut] : it.hk->shortcuts) { if (hotkey_shortcut && hotkey_shortcut->isEnabled()) { QWidget* parent = qobject_cast(hotkey_shortcut->parent()); - if (parent && parent->isActiveWindow()) { + if (!parent) + continue; + if (name == QStringLiteral("move down")) { + std::cout << "move down triggered before context check" << std::endl; + } + bool shouldFire = true; + // Code to honor context, so we can set different contexts and parents + // appropriately + if (hotkey_shortcut->context() == Qt::WidgetShortcut) { + shouldFire = parent == QApplication::focusWidget(); + } else if (hotkey_shortcut->context() == Qt::WidgetWithChildrenShortcut) { + shouldFire = parent == QApplication::focusWidget() || + parent->isAncestorOf(QApplication::focusWidget()); + } else if (hotkey_shortcut->context() == Qt::WindowShortcut) { + shouldFire = parent->window()->isActiveWindow(); + } + + if (shouldFire) { hotkey_shortcut->activated(); break; } diff --git a/src/citra_qt/hotkeys.h b/src/citra_qt/hotkeys.h index 6ac13cc14..b597d7193 100644 --- a/src/citra_qt/hotkeys.h +++ b/src/citra_qt/hotkeys.h @@ -20,7 +20,7 @@ struct Hotkey { QKeySequence keyseq; QString controller_keyseq; std::map shortcuts; - Qt::ShortcutContext context = Qt::WindowShortcut; + Qt::ShortcutContext context = Qt::ApplicationShortcut; std::unique_ptr button_device = nullptr; std::unique_ptr button_device2 = nullptr; QAction* action = nullptr;