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 "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<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);
}

View file

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

View file

@ -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<u32>(static_cast<const QMouseEvent*>(event)->button()));
emit windowMouseEvent(static_cast<int>(button_index + 1u), event->type() == QEvent::MouseButtonPress);
return true;
}
case QEvent::Resize:
{
QWidget::event(event);

View file

@ -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;

View file

@ -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()

View file

@ -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<int, InputButtonHandler> m_keyboard_input_handlers;
QTimer* m_background_controller_polling_timer = nullptr;
u32 m_background_controller_polling_enable_count = 0;