From 3723cd5867f33e39c20b69a179a691f89d48d27b Mon Sep 17 00:00:00 2001 From: Connor McLaughlin Date: Sun, 26 Apr 2020 17:23:42 +1000 Subject: [PATCH] Qt: Mouse button binding support --- src/duckstation-qt/inputbindingwidgets.cpp | 9 +++++++++ src/duckstation-qt/inputbindingwidgets.h | 2 +- src/duckstation-qt/qtdisplaywidget.cpp | 9 +++++++++ src/duckstation-qt/qtdisplaywidget.h | 1 + src/duckstation-qt/qthostinterface.cpp | 7 +++++++ src/duckstation-qt/qthostinterface.h | 4 +--- 6 files changed, 28 insertions(+), 4 deletions(-) diff --git a/src/duckstation-qt/inputbindingwidgets.cpp b/src/duckstation-qt/inputbindingwidgets.cpp index 2b7f502c2..f1357dd74 100644 --- a/src/duckstation-qt/inputbindingwidgets.cpp +++ b/src/duckstation-qt/inputbindingwidgets.cpp @@ -1,4 +1,5 @@ #include "inputbindingwidgets.h" +#include "common/bitutils.h" #include "core/settings.h" #include "frontend-common/controller_interface.h" #include "qthostinterface.h" @@ -165,6 +166,14 @@ bool InputButtonBindingWidget::eventFilter(QObject* watched, QEvent* event) return true; } + else if (event_type == QEvent::MouseButtonRelease) + { + const u32 button_index = CountTrailingZeros(static_cast(static_cast(event)->button())); + m_new_binding_value = QStringLiteral("Mouse/Button%1").arg(button_index + 1); + setNewBinding(); + stopListeningForInput(); + return true; + } return InputBindingWidget::eventFilter(watched, event); } diff --git a/src/duckstation-qt/inputbindingwidgets.h b/src/duckstation-qt/inputbindingwidgets.h index e4058d098..bf97fa512 100644 --- a/src/duckstation-qt/inputbindingwidgets.h +++ b/src/duckstation-qt/inputbindingwidgets.h @@ -23,7 +23,7 @@ public Q_SLOTS: void reloadBinding(); protected Q_SLOTS: - void onPressed(); + void onClicked(); void onInputListenTimerTimeout(); protected: diff --git a/src/duckstation-qt/qtdisplaywidget.cpp b/src/duckstation-qt/qtdisplaywidget.cpp index 80c6fe9be..69e3ca37c 100644 --- a/src/duckstation-qt/qtdisplaywidget.cpp +++ b/src/duckstation-qt/qtdisplaywidget.cpp @@ -1,4 +1,5 @@ #include "qtdisplaywidget.h" +#include "common/bitutils.h" #include "qthostdisplay.h" #include "qthostinterface.h" #include "qtutils.h" @@ -64,6 +65,14 @@ bool QtDisplayWidget::event(QEvent* event) return true; } + case QEvent::MouseButtonPress: + case QEvent::MouseButtonRelease: + { + const u32 button_index = CountTrailingZeros(static_cast(static_cast(event)->button())); + emit windowMouseEvent(static_cast(button_index + 1u), event->type() == QEvent::MouseButtonPress); + return true; + } + case QEvent::Resize: { QWidget::event(event); diff --git a/src/duckstation-qt/qtdisplaywidget.h b/src/duckstation-qt/qtdisplaywidget.h index eeeaf8c13..a53d4422f 100644 --- a/src/duckstation-qt/qtdisplaywidget.h +++ b/src/duckstation-qt/qtdisplaywidget.h @@ -21,6 +21,7 @@ Q_SIGNALS: void windowRestoredEvent(); void windowClosedEvent(); void windowKeyEvent(int key_code, bool pressed); + void windowMouseEvent(int button, bool pressed); protected: bool event(QEvent* event) override; diff --git a/src/duckstation-qt/qthostinterface.cpp b/src/duckstation-qt/qthostinterface.cpp index aa0b4d00c..162216cc6 100644 --- a/src/duckstation-qt/qthostinterface.cpp +++ b/src/duckstation-qt/qthostinterface.cpp @@ -220,6 +220,12 @@ void QtHostInterface::onDisplayWindowKeyEvent(int key, bool pressed) HandleHostKeyEvent(key, pressed); } +void QtHostInterface::onDisplayWindowMouseEvent(int button, bool pressed) +{ + DebugAssert(isOnWorkerThread()); + HandleHostMouseEvent(button, pressed); +} + void QtHostInterface::onHostDisplayWindowResized(int width, int height) { // this can be null if it was destroyed and the main thread is late catching up @@ -316,6 +322,7 @@ void QtHostInterface::connectDisplaySignals() connect(widget, &QtDisplayWidget::windowClosedEvent, this, &QtHostInterface::powerOffSystem, Qt::BlockingQueuedConnection); connect(widget, &QtDisplayWidget::windowKeyEvent, this, &QtHostInterface::onDisplayWindowKeyEvent); + connect(widget, &QtDisplayWidget::windowMouseEvent, this, &QtHostInterface::onDisplayWindowMouseEvent); } void QtHostInterface::disconnectDisplaySignals() diff --git a/src/duckstation-qt/qthostinterface.h b/src/duckstation-qt/qthostinterface.h index cdfb12f1a..4e63e7d1f 100644 --- a/src/duckstation-qt/qthostinterface.h +++ b/src/duckstation-qt/qthostinterface.h @@ -104,6 +104,7 @@ public Q_SLOTS: void updateInputMap(); void applyInputProfile(const QString& profile_path); void onDisplayWindowKeyEvent(int key, bool pressed); + void onDisplayWindowMouseEvent(int button, bool pressed); void bootSystem(const SystemBootParameters& params); void resumeSystemFromState(const QString& filename, bool boot_on_failure); void powerOffSystem(); @@ -206,9 +207,6 @@ private: std::atomic_bool m_shutdown_flag{false}; - // input key maps, todo hotkeys - std::map m_keyboard_input_handlers; - QTimer* m_background_controller_polling_timer = nullptr; u32 m_background_controller_polling_enable_count = 0;