mirror of
https://github.com/dolphin-emu/dolphin.git
synced 2025-07-24 14:49:42 -06:00
DolphinQt: Make input mapping and output testing non-blocking.
This commit is contained in:
@ -3,12 +3,34 @@
|
||||
|
||||
#include "DolphinQt/QtUtils/BlockUserInputFilter.h"
|
||||
|
||||
#include <QEvent>
|
||||
#include <chrono>
|
||||
|
||||
bool BlockUserInputFilter::eventFilter(QObject* object, QEvent* event)
|
||||
#include <QEvent>
|
||||
#include <QTimer>
|
||||
|
||||
namespace QtUtils
|
||||
{
|
||||
const QEvent::Type event_type = event->type();
|
||||
return event_type == QEvent::KeyPress || event_type == QEvent::KeyRelease ||
|
||||
event_type == QEvent::MouseButtonPress || event_type == QEvent::MouseButtonRelease ||
|
||||
event_type == QEvent::MouseButtonDblClick;
|
||||
|
||||
// Leave filter active for a bit to prevent Return/Space detection from reactivating the button.
|
||||
constexpr auto REMOVAL_DELAY = std::chrono::milliseconds{100};
|
||||
|
||||
BlockKeyboardInputFilter::BlockKeyboardInputFilter(QObject* parent) : QObject{parent}
|
||||
{
|
||||
parent->installEventFilter(this);
|
||||
}
|
||||
|
||||
void BlockKeyboardInputFilter::ScheduleRemoval()
|
||||
{
|
||||
auto* const timer = new QTimer(this);
|
||||
timer->setSingleShot(true);
|
||||
connect(timer, &QTimer::timeout, [this] { delete this; });
|
||||
timer->start(REMOVAL_DELAY);
|
||||
}
|
||||
|
||||
bool BlockKeyboardInputFilter::eventFilter(QObject* object, QEvent* event)
|
||||
{
|
||||
const auto event_type = event->type();
|
||||
return event_type == QEvent::KeyPress || event_type == QEvent::KeyRelease;
|
||||
}
|
||||
|
||||
} // namespace QtUtils
|
||||
|
@ -5,14 +5,26 @@
|
||||
|
||||
#include <QObject>
|
||||
|
||||
class QEvent;
|
||||
namespace QtUtils
|
||||
{
|
||||
|
||||
class BlockUserInputFilter : public QObject
|
||||
class BlockKeyboardInputFilter : public QObject
|
||||
{
|
||||
Q_OBJECT
|
||||
public:
|
||||
using QObject::QObject;
|
||||
BlockKeyboardInputFilter(QObject* parent);
|
||||
void ScheduleRemoval();
|
||||
|
||||
private:
|
||||
bool eventFilter(QObject* object, QEvent* event) override;
|
||||
};
|
||||
|
||||
template <typename T>
|
||||
void InstallKeyboardBlocker(QObject* obj, T* removal_signal_object, void (T::*removal_signal)())
|
||||
{
|
||||
removal_signal_object->connect(removal_signal_object, removal_signal,
|
||||
new QtUtils::BlockKeyboardInputFilter{obj},
|
||||
&QtUtils::BlockKeyboardInputFilter::ScheduleRemoval);
|
||||
}
|
||||
|
||||
} // namespace QtUtils
|
||||
|
Reference in New Issue
Block a user