Qt: Mouse button binding support

This commit is contained in:
Connor McLaughlin 2020-04-26 17:23:42 +10:00
parent ce46475e41
commit 3723cd5867
6 changed files with 28 additions and 4 deletions

View file

@ -1,4 +1,5 @@
#include "inputbindingwidgets.h" #include "inputbindingwidgets.h"
#include "common/bitutils.h"
#include "core/settings.h" #include "core/settings.h"
#include "frontend-common/controller_interface.h" #include "frontend-common/controller_interface.h"
#include "qthostinterface.h" #include "qthostinterface.h"
@ -165,6 +166,14 @@ bool InputButtonBindingWidget::eventFilter(QObject* watched, QEvent* event)
return true; return true;
} }
else if (event_type == QEvent::MouseButtonRelease)
{
const u32 button_index = CountTrailingZeros(static_cast<u32>(static_cast<const QMouseEvent*>(event)->button()));
m_new_binding_value = QStringLiteral("Mouse/Button%1").arg(button_index + 1);
setNewBinding();
stopListeningForInput();
return true;
}
return InputBindingWidget::eventFilter(watched, event); return InputBindingWidget::eventFilter(watched, event);
} }

View file

@ -23,7 +23,7 @@ public Q_SLOTS:
void reloadBinding(); void reloadBinding();
protected Q_SLOTS: protected Q_SLOTS:
void onPressed(); void onClicked();
void onInputListenTimerTimeout(); void onInputListenTimerTimeout();
protected: protected:

View file

@ -1,4 +1,5 @@
#include "qtdisplaywidget.h" #include "qtdisplaywidget.h"
#include "common/bitutils.h"
#include "qthostdisplay.h" #include "qthostdisplay.h"
#include "qthostinterface.h" #include "qthostinterface.h"
#include "qtutils.h" #include "qtutils.h"
@ -64,6 +65,14 @@ bool QtDisplayWidget::event(QEvent* event)
return true; return true;
} }
case QEvent::MouseButtonPress:
case QEvent::MouseButtonRelease:
{
const u32 button_index = CountTrailingZeros(static_cast<u32>(static_cast<const QMouseEvent*>(event)->button()));
emit windowMouseEvent(static_cast<int>(button_index + 1u), event->type() == QEvent::MouseButtonPress);
return true;
}
case QEvent::Resize: case QEvent::Resize:
{ {
QWidget::event(event); QWidget::event(event);

View file

@ -21,6 +21,7 @@ Q_SIGNALS:
void windowRestoredEvent(); void windowRestoredEvent();
void windowClosedEvent(); void windowClosedEvent();
void windowKeyEvent(int key_code, bool pressed); void windowKeyEvent(int key_code, bool pressed);
void windowMouseEvent(int button, bool pressed);
protected: protected:
bool event(QEvent* event) override; bool event(QEvent* event) override;

View file

@ -220,6 +220,12 @@ void QtHostInterface::onDisplayWindowKeyEvent(int key, bool pressed)
HandleHostKeyEvent(key, pressed); HandleHostKeyEvent(key, pressed);
} }
void QtHostInterface::onDisplayWindowMouseEvent(int button, bool pressed)
{
DebugAssert(isOnWorkerThread());
HandleHostMouseEvent(button, pressed);
}
void QtHostInterface::onHostDisplayWindowResized(int width, int height) void QtHostInterface::onHostDisplayWindowResized(int width, int height)
{ {
// this can be null if it was destroyed and the main thread is late catching up // 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, connect(widget, &QtDisplayWidget::windowClosedEvent, this, &QtHostInterface::powerOffSystem,
Qt::BlockingQueuedConnection); Qt::BlockingQueuedConnection);
connect(widget, &QtDisplayWidget::windowKeyEvent, this, &QtHostInterface::onDisplayWindowKeyEvent); connect(widget, &QtDisplayWidget::windowKeyEvent, this, &QtHostInterface::onDisplayWindowKeyEvent);
connect(widget, &QtDisplayWidget::windowMouseEvent, this, &QtHostInterface::onDisplayWindowMouseEvent);
} }
void QtHostInterface::disconnectDisplaySignals() void QtHostInterface::disconnectDisplaySignals()

View file

@ -104,6 +104,7 @@ public Q_SLOTS:
void updateInputMap(); void updateInputMap();
void applyInputProfile(const QString& profile_path); void applyInputProfile(const QString& profile_path);
void onDisplayWindowKeyEvent(int key, bool pressed); void onDisplayWindowKeyEvent(int key, bool pressed);
void onDisplayWindowMouseEvent(int button, bool pressed);
void bootSystem(const SystemBootParameters& params); void bootSystem(const SystemBootParameters& params);
void resumeSystemFromState(const QString& filename, bool boot_on_failure); void resumeSystemFromState(const QString& filename, bool boot_on_failure);
void powerOffSystem(); void powerOffSystem();
@ -206,9 +207,6 @@ private:
std::atomic_bool m_shutdown_flag{false}; std::atomic_bool m_shutdown_flag{false};
// input key maps, todo hotkeys
std::map<int, InputButtonHandler> m_keyboard_input_handlers;
QTimer* m_background_controller_polling_timer = nullptr; QTimer* m_background_controller_polling_timer = nullptr;
u32 m_background_controller_polling_enable_count = 0; u32 m_background_controller_polling_enable_count = 0;