From b20739093faaccd9e226f484dd1217fceb1a52d4 Mon Sep 17 00:00:00 2001 From: Vicki Pfau Date: Sat, 6 Mar 2021 20:03:09 -0800 Subject: [PATCH] Qt: Fix inability to clear hat bindings --- CHANGES | 1 + src/core/input.c | 20 ++++++++++++-------- src/platform/qt/GBAKeyEditor.cpp | 1 + src/platform/qt/InputController.cpp | 4 ++++ src/platform/qt/InputController.h | 1 + 5 files changed, 19 insertions(+), 8 deletions(-) diff --git a/CHANGES b/CHANGES index a42382559..f55a25c97 100644 --- a/CHANGES +++ b/CHANGES @@ -93,6 +93,7 @@ Other fixes: - Qt: Fix crashing when no OpenGL context can be obtained - Qt: Fix issues with I/O viewer not properly synchronizing state - Qt: Fix loading a new game crashing on Wayland (fixes mgba.io/i/1992) + - Qt: Fix inability to clear hat bindings - SM83: Simplify register pair access on big endian - SM83: Disassemble STOP as one byte - Wii: Fix crash on unloading irregularly sized GBA ROMs diff --git a/src/core/input.c b/src/core/input.c index 307fed216..c143805ac 100644 --- a/src/core/input.c +++ b/src/core/input.c @@ -541,7 +541,6 @@ void mInputBindHat(struct mInputMap* map, uint32_t type, int id, const struct mI *mInputHatListGetPointer(&impl->hats, id) = *bindings; } - bool mInputQueryHat(const struct mInputMap* map, uint32_t type, int id, struct mInputHatBindings* bindings) { const struct mInputMapImpl* impl = _lookupMapConst(map, type); if (!impl) { @@ -559,18 +558,23 @@ void mInputUnbindHat(struct mInputMap* map, uint32_t type, int id) { if (!impl) { return; } - if (mInputHatListSize(&impl->hats) && id + 1 == (ssize_t) mInputHatListSize(&impl->hats)) { - mInputHatListResize(&impl->hats, -1); - } else { - struct mInputHatBindings* description = mInputHatListGetPointer(&impl->hats, id); - memset(description, -1, sizeof(*description)); + if (id >= (ssize_t) mInputHatListSize(&impl->hats)) { + return; } + struct mInputHatBindings* description = mInputHatListGetPointer(&impl->hats, id); + memset(description, -1, sizeof(*description)); } void mInputUnbindAllHats(struct mInputMap* map, uint32_t type) { struct mInputMapImpl* impl = _lookupMap(map, type); - if (impl) { - mInputHatListClear(&impl->hats); + if (!impl) { + return; + } + + size_t id; + for (id = 0; id < mInputHatListSize(&impl->hats); ++id) { + struct mInputHatBindings* description = mInputHatListGetPointer(&impl->hats, id); + memset(description, -1, sizeof(*description)); } } diff --git a/src/platform/qt/GBAKeyEditor.cpp b/src/platform/qt/GBAKeyEditor.cpp index 16f0d29b9..7890812e7 100644 --- a/src/platform/qt/GBAKeyEditor.cpp +++ b/src/platform/qt/GBAKeyEditor.cpp @@ -215,6 +215,7 @@ void GBAKeyEditor::setNext() { void GBAKeyEditor::save() { #ifdef BUILD_SDL m_controller->unbindAllAxes(m_type); + m_controller->unbindAllHats(m_type); #endif bindKey(m_keyDU, GBA_KEY_UP); diff --git a/src/platform/qt/InputController.cpp b/src/platform/qt/InputController.cpp index c72e892c5..e58580138 100644 --- a/src/platform/qt/InputController.cpp +++ b/src/platform/qt/InputController.cpp @@ -569,6 +569,10 @@ void InputController::bindHat(uint32_t type, int hat, GamepadHatEvent::Direction mInputBindHat(&m_inputMap, type, hat, &bindings); } +void InputController::unbindAllHats(uint32_t type) { + mInputUnbindAllHats(&m_inputMap, type); +} + void InputController::testGamepad(int type) { QWriteLocker l(&m_eventsLock); auto activeAxes = activeGamepadAxes(type); diff --git a/src/platform/qt/InputController.h b/src/platform/qt/InputController.h index 50729952b..a056b1b38 100644 --- a/src/platform/qt/InputController.h +++ b/src/platform/qt/InputController.h @@ -80,6 +80,7 @@ public: void unbindAllAxes(uint32_t type); void bindHat(uint32_t type, int hat, GamepadHatEvent::Direction, GBAKey); + void unbindAllHats(uint32_t type); QStringList connectedGamepads(uint32_t type) const; int gamepad(uint32_t type) const;