From b1ff5782010428307ffb397b66e2987dbdb2b627 Mon Sep 17 00:00:00 2001 From: Vicki Pfau Date: Sun, 20 Jun 2021 00:34:45 -0700 Subject: [PATCH] Qt: Only set default controller bindings if loading fails (fixes #799) --- CHANGES | 1 + include/mgba/core/input.h | 2 +- src/core/input.c | 4 ++-- src/platform/qt/InputController.cpp | 18 ++++++++++++------ src/platform/qt/InputController.h | 4 ++-- 5 files changed, 18 insertions(+), 11 deletions(-) diff --git a/CHANGES b/CHANGES index 5d72836bc..495f06de7 100644 --- a/CHANGES +++ b/CHANGES @@ -32,6 +32,7 @@ Misc: - Core: Suspend runloop when a core crashes - Qt: Rearrange menus some - Qt: Clean up cheats dialog + - Qt: Only set default controller bindings if loading fails (fixes mgba.io/i/799) - Util: Improve speed of UPS patch loading 0.9.1: (2021-04-18) diff --git a/include/mgba/core/input.h b/include/mgba/core/input.h index e5f64d72a..f7ef212a5 100644 --- a/include/mgba/core/input.h +++ b/include/mgba/core/input.h @@ -70,7 +70,7 @@ bool mInputQueryHat(const struct mInputMap*, uint32_t type, int id, struct mInpu void mInputUnbindHat(struct mInputMap*, uint32_t type, int id); void mInputUnbindAllHats(struct mInputMap*, uint32_t type); -void mInputMapLoad(struct mInputMap*, uint32_t type, const struct Configuration*); +bool mInputMapLoad(struct mInputMap*, uint32_t type, const struct Configuration*); void mInputMapSave(const struct mInputMap*, uint32_t type, struct Configuration*); bool mInputProfileLoad(struct mInputMap*, uint32_t type, const struct Configuration*, const char* profile); diff --git a/src/core/input.c b/src/core/input.c index c143805ac..76296a373 100644 --- a/src/core/input.c +++ b/src/core/input.c @@ -578,10 +578,10 @@ void mInputUnbindAllHats(struct mInputMap* map, uint32_t type) { } } -void mInputMapLoad(struct mInputMap* map, uint32_t type, const struct Configuration* config) { +bool mInputMapLoad(struct mInputMap* map, uint32_t type, const struct Configuration* config) { char sectionName[SECTION_NAME_MAX]; _makeSectionName(map->info->platformName, sectionName, SECTION_NAME_MAX, type); - _loadAll(map, type, sectionName, config); + return _loadAll(map, type, sectionName, config); } void mInputMapSave(const struct mInputMap* map, uint32_t type, struct Configuration* config) { diff --git a/src/platform/qt/InputController.cpp b/src/platform/qt/InputController.cpp index 0c5a848c1..9a8458e1d 100644 --- a/src/platform/qt/InputController.cpp +++ b/src/platform/qt/InputController.cpp @@ -44,7 +44,6 @@ InputController::InputController(int playerId, QWidget* topLevel, QObject* paren } ++s_sdlInited; m_sdlPlayer.bindings = &m_inputMap; - mSDLInitBindingsGBA(&m_inputMap); updateJoysticks(); #endif @@ -163,23 +162,28 @@ void InputController::setConfiguration(ConfigController* config) { if (!m_playerAttached) { m_playerAttached = mSDLAttachPlayer(&s_sdlEvents, &m_sdlPlayer); } - loadConfiguration(SDL_BINDING_BUTTON); + if (!loadConfiguration(SDL_BINDING_BUTTON)) { + mSDLInitBindingsGBA(&m_inputMap); + } loadProfile(SDL_BINDING_BUTTON, profileForType(SDL_BINDING_BUTTON)); #endif } -void InputController::loadConfiguration(uint32_t type) { - mInputMapLoad(&m_inputMap, type, m_config->input()); +bool InputController::loadConfiguration(uint32_t type) { + if (!mInputMapLoad(&m_inputMap, type, m_config->input())) { + return false; + } #ifdef BUILD_SDL if (m_playerAttached) { mSDLPlayerLoadConfig(&m_sdlPlayer, m_config->input()); } #endif + return true; } -void InputController::loadProfile(uint32_t type, const QString& profile) { +bool InputController::loadProfile(uint32_t type, const QString& profile) { if (profile.isEmpty()) { - return; + return false; } bool loaded = mInputProfileLoad(&m_inputMap, type, m_config->input(), profile.toUtf8().constData()); recalibrateAxes(); @@ -187,9 +191,11 @@ void InputController::loadProfile(uint32_t type, const QString& profile) { const InputProfile* ip = InputProfile::findProfile(profile); if (ip) { ip->apply(this); + loaded = true; } } emit profileLoaded(profile); + return loaded; } void InputController::saveConfiguration() { diff --git a/src/platform/qt/InputController.h b/src/platform/qt/InputController.h index 93f77091f..a370ba80e 100644 --- a/src/platform/qt/InputController.h +++ b/src/platform/qt/InputController.h @@ -56,8 +56,8 @@ public: void setConfiguration(ConfigController* config); void saveConfiguration(); - void loadConfiguration(uint32_t type); - void loadProfile(uint32_t type, const QString& profile); + bool loadConfiguration(uint32_t type); + bool loadProfile(uint32_t type, const QString& profile); void saveConfiguration(uint32_t type); void saveProfile(uint32_t type, const QString& profile); const char* profileForType(uint32_t type);