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 applying savetype-only overrides
- Qt: Fix crash in sprite view for partially out-of-bounds sprites (fixes mgba.io/i/2165) - 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: 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 - Util: Fix loading UPS patches that affect the last byte of the file
Misc: Misc:
- Core: Suspend runloop when a core crashes - 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)) { void SensorView::jiggerer(QAbstractButton* button, void (InputController::*setter)(int)) {
connect(button, &QAbstractButton::toggled, [this, button, setter](bool checked) { connect(button, &QAbstractButton::toggled, [this, button, setter](bool checked) {
if (!checked) { if (!checked) {
m_jiggered = nullptr; m_button = nullptr;
} else { } else {
button->setFocus(); button->setFocus();
m_jiggered = [this, button, setter](int axis) { m_button = button;
(m_input->*setter)(axis); m_setter = setter;
button->setChecked(false);
button->clearFocus();
};
} }
}); });
button->installEventFilter(this); button->installEventFilter(this);
@ -106,8 +103,12 @@ bool SensorView::eventFilter(QObject*, QEvent* event) {
if (event->type() == GamepadAxisEvent::Type()) { if (event->type() == GamepadAxisEvent::Type()) {
GamepadAxisEvent* gae = static_cast<GamepadAxisEvent*>(event); GamepadAxisEvent* gae = static_cast<GamepadAxisEvent*>(event);
gae->accept(); gae->accept();
if (m_jiggered && gae->direction() != GamepadAxisEvent::NEUTRAL && gae->isNew()) { if (m_button && gae->direction() != GamepadAxisEvent::NEUTRAL && gae->isNew()) {
m_jiggered(gae->axis()); m_button->removeEventFilter(this);
m_button->clearFocus();
m_button->setChecked(false);
(m_input->*m_setter)(gae->axis());
m_button = nullptr;
} }
return true; return true;
} }

View File

@ -42,7 +42,9 @@ private slots:
private: private:
Ui::SensorView m_ui; 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; std::shared_ptr<CoreController> m_controller;
InputController* m_input; InputController* m_input;
mRotationSource* m_rotation; mRotationSource* m_rotation;