From 24a95621e5118e39e1a6e05b17ef89f4ec2c8c01 Mon Sep 17 00:00:00 2001 From: ArchSav <96357545+ArchSav@users.noreply.github.com> Date: Sat, 14 Mar 2026 00:48:01 +1100 Subject: input: add device specific binds (#13073) Adds support for device-specific binds --- src/config/ConfigManager.cpp | 29 ++++++++++++++++++++++------- 1 file changed, 22 insertions(+), 7 deletions(-) (limited to 'src/config/ConfigManager.cpp') diff --git a/src/config/ConfigManager.cpp b/src/config/ConfigManager.cpp index 3e0a9957..e4632bb9 100644 --- a/src/config/ConfigManager.cpp +++ b/src/config/ConfigManager.cpp @@ -2542,6 +2542,7 @@ std::optional CConfigManager::handleBind(const std::string& command bool click = false; bool drag = false; bool submapUniversal = false; + bool isPerDevice = false; const auto BINDARGS = command.substr(4); for (auto const& arg : BINDARGS) { @@ -2566,6 +2567,7 @@ std::optional CConfigManager::handleBind(const std::string& command release = true; break; case 'u': submapUniversal = true; break; + case 'k': isPerDevice = true; break; default: return "bind: invalid flag"; } } @@ -2579,13 +2581,14 @@ std::optional CConfigManager::handleBind(const std::string& command if (click && drag) return "flags c and g are mutually exclusive"; - const int numbArgs = hasDescription ? 5 : 4; + const int numbArgs = (hasDescription ? 5 : 4) + sc(isPerDevice); const auto ARGS = CVarList(value, numbArgs); - const int DESCR_OFFSET = hasDescription ? 1 : 0; + const int DESCR_OFFSET = hasDescription ? 1 : 0; + const int DEVICE_OFFSET = sc(isPerDevice); if ((ARGS.size() < 3 && !mouse) || (ARGS.size() < 3 && mouse)) return "bind: too few args"; - else if ((ARGS.size() > sc(4) + DESCR_OFFSET && !mouse) || (ARGS.size() > sc(3) + DESCR_OFFSET && mouse)) + else if ((ARGS.size() > sc(4) + DESCR_OFFSET + DEVICE_OFFSET && !mouse) || (ARGS.size() > sc(3) + DESCR_OFFSET + DEVICE_OFFSET && mouse)) return "bind: too many args"; std::set KEYSYMS; @@ -2604,11 +2607,13 @@ std::optional CConfigManager::handleBind(const std::string& command const auto KEY = multiKey ? "" : ARGS[1]; - const auto DESCRIPTION = hasDescription ? ARGS[2] : ""; + const auto DEVICEARGS = isPerDevice ? ARGS[2] : ""; - auto HANDLER = ARGS[2 + DESCR_OFFSET]; + const auto DESCRIPTION = hasDescription ? ARGS[2 + DEVICE_OFFSET] : ""; - const auto COMMAND = mouse ? HANDLER : ARGS[3 + DESCR_OFFSET]; + auto HANDLER = ARGS[2 + DESCR_OFFSET + DEVICE_OFFSET]; + + const auto COMMAND = mouse ? HANDLER : ARGS[3 + DESCR_OFFSET + DEVICE_OFFSET]; if (mouse) HANDLER = "mouse"; @@ -2628,6 +2633,16 @@ std::optional CConfigManager::handleBind(const std::string& command return "Invalid mod, requested mod \"" + MODSTR + "\" is not a valid mod."; } + //[!]keyboard1 keyboard2 ... + bool deviceInclusive = false; + std::unordered_set devices = {}; + if (!DEVICEARGS.empty()) { + deviceInclusive = DEVICEARGS[0] != '!'; + for (const auto deviceString : std::ranges::views::split(DEVICEARGS.substr(deviceInclusive ? 0 : 1), ' ')) { + devices.emplace(std::string_view(deviceString)); + } + } + if ((!KEY.empty()) || multiKey) { SParsedKey parsedKey = parseKey(KEY); @@ -2639,7 +2654,7 @@ std::optional CConfigManager::handleBind(const std::string& command g_pKeybindManager->addKeybind(SKeybind{parsedKey.key, KEYSYMS, parsedKey.keycode, parsedKey.catchAll, MOD, MODS, HANDLER, COMMAND, locked, m_currentSubmap, DESCRIPTION, release, repeat, longPress, mouse, nonConsuming, transparent, ignoreMods, multiKey, hasDescription, dontInhibit, - click, drag, submapUniversal}); + click, drag, submapUniversal, deviceInclusive, devices}); } return {}; -- cgit v1.2.3