Qt: Fix inability to clear hat bindings

This commit is contained in:
Vicki Pfau 2021-03-06 20:03:09 -08:00
parent b6bc8d54e3
commit b20739093f
5 changed files with 19 additions and 8 deletions

View File

@ -93,6 +93,7 @@ Other fixes:
- Qt: Fix crashing when no OpenGL context can be obtained - Qt: Fix crashing when no OpenGL context can be obtained
- Qt: Fix issues with I/O viewer not properly synchronizing state - 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 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: Simplify register pair access on big endian
- SM83: Disassemble STOP as one byte - SM83: Disassemble STOP as one byte
- Wii: Fix crash on unloading irregularly sized GBA ROMs - Wii: Fix crash on unloading irregularly sized GBA ROMs

View File

@ -541,7 +541,6 @@ void mInputBindHat(struct mInputMap* map, uint32_t type, int id, const struct mI
*mInputHatListGetPointer(&impl->hats, id) = *bindings; *mInputHatListGetPointer(&impl->hats, id) = *bindings;
} }
bool mInputQueryHat(const struct mInputMap* map, uint32_t type, int id, struct mInputHatBindings* bindings) { bool mInputQueryHat(const struct mInputMap* map, uint32_t type, int id, struct mInputHatBindings* bindings) {
const struct mInputMapImpl* impl = _lookupMapConst(map, type); const struct mInputMapImpl* impl = _lookupMapConst(map, type);
if (!impl) { if (!impl) {
@ -559,18 +558,23 @@ void mInputUnbindHat(struct mInputMap* map, uint32_t type, int id) {
if (!impl) { if (!impl) {
return; return;
} }
if (mInputHatListSize(&impl->hats) && id + 1 == (ssize_t) mInputHatListSize(&impl->hats)) { if (id >= (ssize_t) mInputHatListSize(&impl->hats)) {
mInputHatListResize(&impl->hats, -1); return;
} else { }
struct mInputHatBindings* description = mInputHatListGetPointer(&impl->hats, id); struct mInputHatBindings* description = mInputHatListGetPointer(&impl->hats, id);
memset(description, -1, sizeof(*description)); memset(description, -1, sizeof(*description));
} }
}
void mInputUnbindAllHats(struct mInputMap* map, uint32_t type) { void mInputUnbindAllHats(struct mInputMap* map, uint32_t type) {
struct mInputMapImpl* impl = _lookupMap(map, type); struct mInputMapImpl* impl = _lookupMap(map, type);
if (impl) { if (!impl) {
mInputHatListClear(&impl->hats); return;
}
size_t id;
for (id = 0; id < mInputHatListSize(&impl->hats); ++id) {
struct mInputHatBindings* description = mInputHatListGetPointer(&impl->hats, id);
memset(description, -1, sizeof(*description));
} }
} }

View File

@ -215,6 +215,7 @@ void GBAKeyEditor::setNext() {
void GBAKeyEditor::save() { void GBAKeyEditor::save() {
#ifdef BUILD_SDL #ifdef BUILD_SDL
m_controller->unbindAllAxes(m_type); m_controller->unbindAllAxes(m_type);
m_controller->unbindAllHats(m_type);
#endif #endif
bindKey(m_keyDU, GBA_KEY_UP); bindKey(m_keyDU, GBA_KEY_UP);

View File

@ -569,6 +569,10 @@ void InputController::bindHat(uint32_t type, int hat, GamepadHatEvent::Direction
mInputBindHat(&m_inputMap, type, hat, &bindings); mInputBindHat(&m_inputMap, type, hat, &bindings);
} }
void InputController::unbindAllHats(uint32_t type) {
mInputUnbindAllHats(&m_inputMap, type);
}
void InputController::testGamepad(int type) { void InputController::testGamepad(int type) {
QWriteLocker l(&m_eventsLock); QWriteLocker l(&m_eventsLock);
auto activeAxes = activeGamepadAxes(type); auto activeAxes = activeGamepadAxes(type);

View File

@ -80,6 +80,7 @@ public:
void unbindAllAxes(uint32_t type); void unbindAllAxes(uint32_t type);
void bindHat(uint32_t type, int hat, GamepadHatEvent::Direction, GBAKey); void bindHat(uint32_t type, int hat, GamepadHatEvent::Direction, GBAKey);
void unbindAllHats(uint32_t type);
QStringList connectedGamepads(uint32_t type) const; QStringList connectedGamepads(uint32_t type) const;
int gamepad(uint32_t type) const; int gamepad(uint32_t type) const;