Added a setting to only accept input from the first controller.

This commit is contained in:
Leon Styhre 2021-05-23 11:45:45 +02:00
parent 9125ab78e5
commit ecf8e50500
3 changed files with 27 additions and 0 deletions

View file

@ -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<SwitchComponent>(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();

View file

@ -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

View file

@ -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"] = { "", "" };