From ecf8e50500b419c97e379f4467b3315afb5a2db2 Mon Sep 17 00:00:00 2001 From: Leon Styhre Date: Sun, 23 May 2021 11:45:45 +0200 Subject: [PATCH] Added a setting to only accept input from the first controller. --- es-app/src/guis/GuiMenu.cpp | 14 ++++++++++++++ es-core/src/InputManager.cpp | 10 ++++++++++ es-core/src/Settings.cpp | 3 +++ 3 files changed, 27 insertions(+) diff --git a/es-app/src/guis/GuiMenu.cpp b/es-app/src/guis/GuiMenu.cpp index adf0c847b..e1f295598 100644 --- a/es-app/src/guis/GuiMenu.cpp +++ b/es-app/src/guis/GuiMenu.cpp @@ -759,6 +759,20 @@ void GuiMenu::openInputDeviceOptions() { auto s = new GuiSettings(mWindow, "INPUT DEVICE SETTINGS"); + // Whether to only accept input from the first controller. + auto input_only_first_controller = std::make_shared(mWindow); + input_only_first_controller->setState(Settings::getInstance()-> + getBool("InputOnlyFirstController")); + s->addWithLabel("ONLY ACCEPT INPUT FROM FIRST CONTROLLER", input_only_first_controller); + s->addSaveFunc([input_only_first_controller, s] { + if (Settings::getInstance()->getBool("InputOnlyFirstController") != + input_only_first_controller->getState()) { + Settings::getInstance()->setBool("InputOnlyFirstController", + input_only_first_controller->getState()); + s->setNeedsSaving(); + } + }); + // Configure keyboard and controllers. ComponentListRow configure_input_row; configure_input_row.elements.clear(); diff --git a/es-core/src/InputManager.cpp b/es-core/src/InputManager.cpp index 456c51558..7eacad5d0 100644 --- a/es-core/src/InputManager.cpp +++ b/es-core/src/InputManager.cpp @@ -357,6 +357,11 @@ bool InputManager::parseEvent(const SDL_Event& event, Window* window) switch (event.type) { case SDL_CONTROLLERAXISMOTION: { + // Whether to only accept input from the first controller. + if (Settings::getInstance()->getBool("InputOnlyFirstController")) + if (mInputConfigs.begin()->first != event.cdevice.which) + return false; + // This is needed for a situation which sometimes occur when a game is launched, // some axis input is generated and then the controller is disconnected before // leaving the game. In this case, events for the old device index could be received @@ -395,6 +400,11 @@ bool InputManager::parseEvent(const SDL_Event& event, Window* window) case SDL_CONTROLLERBUTTONDOWN: { } case SDL_CONTROLLERBUTTONUP: { + // Whether to only accept input from the first controller. + if (Settings::getInstance()->getBool("InputOnlyFirstController")) + if (mInputConfigs.begin()->first != event.cdevice.which) + return false; + // The event filtering below is required as some controllers send button presses // starting with the state 0 when using the D-pad. I consider this invalid behaviour // and the more popular controllers such as those from Microsoft and Sony do not show diff --git a/es-core/src/Settings.cpp b/es-core/src/Settings.cpp index 774b19ba5..2cbb10ea5 100644 --- a/es-core/src/Settings.cpp +++ b/es-core/src/Settings.cpp @@ -196,6 +196,9 @@ void Settings::setDefaults() mBoolMap["ScreensaverVideoAudio"] = { false, false }; mBoolMap["NavigationSounds"] = { true, true }; + // Input device settings. + mBoolMap["InputOnlyFirstController"] = { false, false }; + // Game collection settings. mStringMap["CollectionSystemsAuto"] = { "", "" }; mStringMap["CollectionSystemsCustom"] = { "", "" };