Qt: Redo sensor binding to be less fragile

This commit is contained in:
Vicki Pfau 2021-06-28 22:38:25 -07:00
parent 9a26c1a679
commit de16ea49c7
3 changed files with 13 additions and 9 deletions

View File

@ -34,6 +34,7 @@ Other fixes:
- Qt: Fix applying savetype-only overrides
- Qt: Fix crash in sprite view for partially out-of-bounds sprites (fixes mgba.io/i/2165)
- Qt: Fix having to press controller buttons twice for menu items (fixes mgba.io/i/2143)
- Qt: Redo sensor binding to be less fragile
- Util: Fix loading UPS patches that affect the last byte of the file
Misc:
- Core: Suspend runloop when a core crashes

View File

@ -79,14 +79,11 @@ void SensorView::setController(std::shared_ptr<CoreController> controller) {
void SensorView::jiggerer(QAbstractButton* button, void (InputController::*setter)(int)) {
connect(button, &QAbstractButton::toggled, [this, button, setter](bool checked) {
if (!checked) {
m_jiggered = nullptr;
m_button = nullptr;
} else {
button->setFocus();
m_jiggered = [this, button, setter](int axis) {
(m_input->*setter)(axis);
button->setChecked(false);
button->clearFocus();
};
m_button = button;
m_setter = setter;
}
});
button->installEventFilter(this);
@ -106,8 +103,12 @@ bool SensorView::eventFilter(QObject*, QEvent* event) {
if (event->type() == GamepadAxisEvent::Type()) {
GamepadAxisEvent* gae = static_cast<GamepadAxisEvent*>(event);
gae->accept();
if (m_jiggered && gae->direction() != GamepadAxisEvent::NEUTRAL && gae->isNew()) {
m_jiggered(gae->axis());
if (m_button && gae->direction() != GamepadAxisEvent::NEUTRAL && gae->isNew()) {
m_button->removeEventFilter(this);
m_button->clearFocus();
m_button->setChecked(false);
(m_input->*m_setter)(gae->axis());
m_button = nullptr;
}
return true;
}

View File

@ -42,7 +42,9 @@ private slots:
private:
Ui::SensorView m_ui;
std::function<void(int)> m_jiggered;
QAbstractButton* m_button = nullptr;
void (InputController::*m_setter)(int);
std::shared_ptr<CoreController> m_controller;
InputController* m_input;
mRotationSource* m_rotation;