all repos — mgba @ b20739093faaccd9e226f484dd1217fceb1a52d4

mGBA Game Boy Advance Emulator

Qt: Fix inability to clear hat bindings
Vicki Pfau vi@endrift.com
Sat, 06 Mar 2021 20:03:09 -0800
commit

b20739093faaccd9e226f484dd1217fceb1a52d4

parent

b6bc8d54e3ba7f8d11c1888003b18bab738c1e89

M CHANGESCHANGES

@@ -93,6 +93,7 @@ - Qt: Fix crash when editing shortcuts with none selected (fixes mgba.io/i/1964)

- 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
M src/core/input.csrc/core/input.c

@@ -541,7 +541,6 @@ }

*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 @@ struct mInputMapImpl* impl = _lookupMap(map, type);

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)); } }
M src/platform/qt/GBAKeyEditor.cppsrc/platform/qt/GBAKeyEditor.cpp

@@ -215,6 +215,7 @@

void GBAKeyEditor::save() { #ifdef BUILD_SDL m_controller->unbindAllAxes(m_type); + m_controller->unbindAllHats(m_type); #endif bindKey(m_keyDU, GBA_KEY_UP);
M src/platform/qt/InputController.cppsrc/platform/qt/InputController.cpp

@@ -569,6 +569,10 @@ }

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);
M src/platform/qt/InputController.hsrc/platform/qt/InputController.h

@@ -80,6 +80,7 @@ void bindAxis(uint32_t type, int axis, GamepadAxisEvent::Direction, GBAKey);

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;