diff options
author | Garrett Brown <themagnificentmrb@gmail.com> | 2024-01-06 12:11:12 -0800 |
---|---|---|
committer | GitHub <noreply@github.com> | 2024-01-06 12:11:12 -0800 |
commit | e9c27d48515fa6cc146cfa43c759e4361b473aea (patch) | |
tree | 5c4d80832547a467b561b927d0a1b0df29c8ca6f | |
parent | 0b5629e3ee5f79d175580b1b25fb27227e9f3c89 (diff) | |
parent | a25ba905bcb2d03ea6db00d450c2f3ff13bc5f4e (diff) |
Merge pull request #24403 from garbear/backport-virtual-joysticks
[Backport] Filter out "virtual" Android joysticks
-rw-r--r-- | xbmc/games/agents/GameAgentManager.cpp | 58 |
1 files changed, 58 insertions, 0 deletions
diff --git a/xbmc/games/agents/GameAgentManager.cpp b/xbmc/games/agents/GameAgentManager.cpp index cbb75f626c..5b72fbfecf 100644 --- a/xbmc/games/agents/GameAgentManager.cpp +++ b/xbmc/games/agents/GameAgentManager.cpp @@ -19,6 +19,8 @@ #include "peripherals/devices/PeripheralJoystick.h" #include "utils/log.h" +#include <array> + using namespace KODI; using namespace GAME; @@ -147,6 +149,62 @@ void CGameAgentManager::ProcessJoysticks(PERIPHERALS::EventLockHandlePtr& inputH PERIPHERALS::PeripheralVector joysticks; m_peripheralManager.GetPeripheralsWithFeature(joysticks, PERIPHERALS::FEATURE_JOYSTICK); + // Remove "virtual" Android joysticks + // + // The heuristic used to identify these is to check if the device name is all + // lowercase letters and dashes (and contains at least one dash). The + // following virtual devices have been observed: + // + // shield-ask-remote + // sunxi-ir-uinput + // virtual-search + // + // Additionally, we specifically allow the following devices: + // + // virtual-remote + // + joysticks.erase( + std::remove_if(joysticks.begin(), joysticks.end(), + [](const PERIPHERALS::PeripheralPtr& joystick) + { + const std::string& joystickName = joystick->DeviceName(); + + // Skip joysticks in the allowlist + static const std::array<std::string, 1> peripheralAllowlist = { + "virtual-remote", + }; + if (std::find_if(peripheralAllowlist.begin(), peripheralAllowlist.end(), + [&joystickName](const std::string& allowedJoystick) { + return allowedJoystick == joystickName; + }) != peripheralAllowlist.end()) + { + return false; + } + + // Require at least one dash + if (std::find_if(joystickName.begin(), joystickName.end(), + [](char c) { return c == '-'; }) == joystickName.end()) + { + return false; + } + + // Require all lowercase letters or dashes + if (std::find_if(joystickName.begin(), joystickName.end(), + [](char c) + { + const bool isLowercase = ('a' <= c && c <= 'z'); + const bool isDash = (c == '-'); + return !(isLowercase || isDash); + }) != joystickName.end()) + { + return false; + } + + // Joystick matches the pattern, remove it + return true; + }), + joysticks.end()); + // Update expired joysticks UpdateExpiredJoysticks(joysticks, inputHandlingLock); |