mirror of
https://github.com/Lime3DS/Lime3DS.git
synced 2026-06-01 20:45:00 -06:00
honor shortcut context with controller hotkeys
This commit is contained in:
parent
30db1a71fd
commit
e13c4deb24
@ -3,6 +3,7 @@
|
|||||||
// Refer to the license.txt file included.
|
// Refer to the license.txt file included.
|
||||||
|
|
||||||
#include <iostream>
|
#include <iostream>
|
||||||
|
#include <QApplication>
|
||||||
#include <QShortcut>
|
#include <QShortcut>
|
||||||
#include <QTimer>
|
#include <QTimer>
|
||||||
#include <QWidget>
|
#include <QWidget>
|
||||||
@ -39,8 +40,11 @@ void ControllerHotkeyMonitor::removeButton(const QString& name) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
void ControllerHotkeyMonitor::checkAllButtons() {
|
void ControllerHotkeyMonitor::checkAllButtons() {
|
||||||
|
// Controller Hotkeys
|
||||||
for (auto& [name, it] : *m_buttons) {
|
for (auto& [name, it] : *m_buttons) {
|
||||||
bool trigger = false;
|
bool trigger = false;
|
||||||
|
if (!it.hk || !it.hk->button_device)
|
||||||
|
continue;
|
||||||
bool currentStatus = it.hk->button_device->GetStatus();
|
bool currentStatus = it.hk->button_device->GetStatus();
|
||||||
if (it.hk->button_device2) {
|
if (it.hk->button_device2) {
|
||||||
// two buttons, need both pressed and one *just now* pressed
|
// 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) {
|
for (auto const& [name, hotkey_shortcut] : it.hk->shortcuts) {
|
||||||
if (hotkey_shortcut && hotkey_shortcut->isEnabled()) {
|
if (hotkey_shortcut && hotkey_shortcut->isEnabled()) {
|
||||||
QWidget* parent = qobject_cast<QWidget*>(hotkey_shortcut->parent());
|
QWidget* parent = qobject_cast<QWidget*>(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();
|
hotkey_shortcut->activated();
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
|
|||||||
@ -20,7 +20,7 @@ struct Hotkey {
|
|||||||
QKeySequence keyseq;
|
QKeySequence keyseq;
|
||||||
QString controller_keyseq;
|
QString controller_keyseq;
|
||||||
std::map<QString, QShortcut*> shortcuts;
|
std::map<QString, QShortcut*> shortcuts;
|
||||||
Qt::ShortcutContext context = Qt::WindowShortcut;
|
Qt::ShortcutContext context = Qt::ApplicationShortcut;
|
||||||
std::unique_ptr<Input::ButtonDevice> button_device = nullptr;
|
std::unique_ptr<Input::ButtonDevice> button_device = nullptr;
|
||||||
std::unique_ptr<Input::ButtonDevice> button_device2 = nullptr;
|
std::unique_ptr<Input::ButtonDevice> button_device2 = nullptr;
|
||||||
QAction* action = nullptr;
|
QAction* action = nullptr;
|
||||||
|
|||||||
Loading…
Reference in New Issue
Block a user