all repos — mgba @ ba1fb17dde839e1596a68b8553f0dbfc6aa51a04

mGBA Game Boy Advance Emulator

Qt: Update SensorView to work with focus stealing
Jeffrey Pfau jeffrey@endrift.com
Sun, 16 Aug 2015 18:06:15 -0700
commit

ba1fb17dde839e1596a68b8553f0dbfc6aa51a04

parent

05a956cacd7028044ae85a62abdcd49bb8a6aefc

2 files changed, 13 insertions(+), 0 deletions(-)

jump to
M src/platform/qt/SensorView.cppsrc/platform/qt/SensorView.cpp

@@ -61,6 +61,7 @@ m_ui.gyroSensitivity->setValue(m_input->gyroSensitivity() / 1e8f);

connect(m_ui.gyroSensitivity, static_cast<void (QDoubleSpinBox::*)(double)>(&QDoubleSpinBox::valueChanged), [this](double value) { m_input->setGyroSensitivity(value * 1e8f); }); + m_input->stealFocus(this); } void SensorView::jiggerer(QAbstractButton* button, void (InputController::*setter)(int)) {

@@ -68,13 +69,24 @@ connect(button, &QAbstractButton::toggled, [this, button, setter](bool checked) {

if (!checked) { m_jiggered = nullptr; } else { + button->setFocus(); m_jiggered = [this, button, setter](int axis) { (m_input->*setter)(axis); button->setChecked(false); + button->clearFocus(); }; } }); button->installEventFilter(this); +} + +bool SensorView::event(QEvent* event) { + if (event->type() == QEvent::WindowActivate) { + m_input->stealFocus(this); + } else if (event->type() == QEvent::WindowDeactivate) { + m_input->releaseFocus(this); + } + return QWidget::event(event); } bool SensorView::eventFilter(QObject*, QEvent* event) {
M src/platform/qt/SensorView.hsrc/platform/qt/SensorView.h

@@ -30,6 +30,7 @@ SensorView(GameController* controller, InputController* input, QWidget* parent = nullptr);

protected: bool eventFilter(QObject*, QEvent* event) override; + bool event(QEvent* event); private slots: void updateSensors();