DolphinQt: Make input mapping and output testing non-blocking.

This commit is contained in:
Jordan Woyak
2024-11-02 02:52:18 -05:00
parent bc95c001c8
commit f12846a0e9
12 changed files with 339 additions and 183 deletions

View File

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

View File

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