mirror of
https://github.com/RetroDECK/Duckstation.git
synced 2024-11-22 05:45:38 +00:00
Qt: Mouse button binding support
This commit is contained in:
parent
ce46475e41
commit
3723cd5867
|
@ -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);
|
||||
}
|
||||
|
|
|
@ -23,7 +23,7 @@ public Q_SLOTS:
|
|||
void reloadBinding();
|
||||
|
||||
protected Q_SLOTS:
|
||||
void onPressed();
|
||||
void onClicked();
|
||||
void onInputListenTimerTimeout();
|
||||
|
||||
protected:
|
||||
|
|
|
@ -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);
|
||||
|
|
|
@ -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;
|
||||
|
|
|
@ -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()
|
||||
|
|
|
@ -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;
|
||||
|
||||
|
|
Loading…
Reference in a new issue