Perform refactoring of pads to remove the ugly pad initialization.

This commit is contained in:
Robbie 2017-07-12 09:07:40 -05:00 committed by Ivan
parent b01e7e3362
commit d1cde4d0a7
8 changed files with 127 additions and 53 deletions

View file

@ -2,6 +2,8 @@
#include "keyboard_pad_handler.h"
#include <QApplication>
keyboard_pad_config g_kbpad_config;
void keyboard_pad_handler::Init(const u32 max_connect)
@ -12,15 +14,15 @@ void keyboard_pad_handler::Init(const u32 max_connect)
m_info.now_connect = std::min(m_pads.size(), (size_t)max_connect);
}
keyboard_pad_handler::keyboard_pad_handler(QObject* target, QObject* parent) : QObject(parent), m_target(target)
keyboard_pad_handler::keyboard_pad_handler() : QObject()
{
target->installEventFilter(this);
}
bool keyboard_pad_handler::eventFilter(QObject* target, QEvent* ev)
{
// Commenting target since I don't know how to target game window yet.
//if (target == m_target)
// !m_target is for future proofing when gsrender isn't automatically initialized on load.
// !m_target->isVisible() is a hack since currently a guiless application will STILL inititialize a gsrender (providing a valid target)
if (!m_target || !m_target->isVisible()|| target == m_target)
{
if (ev->type() == QEvent::KeyPress)
{
@ -34,6 +36,23 @@ bool keyboard_pad_handler::eventFilter(QObject* target, QEvent* ev)
return false;
}
/* Sets the target window for the event handler, and also installs an event filter on the target. */
void keyboard_pad_handler::SetTargetWindow(QWindow* target)
{
if (target != nullptr)
{
m_target = target;
target->installEventFilter(this);
}
else
{
QApplication::instance()->installEventFilter(this);
// If this is hit, it probably means that some refactoring occurs because currently a gsframe is created in Load.
// We still want events so filter from application instead since target is null.
LOG_ERROR(GENERAL, "Trying to set pad handler to a null target window.");
}
}
void keyboard_pad_handler::keyPressEvent(QKeyEvent* event)
{
if (event->isAutoRepeat())