From a15e3e1f380e3b90f976bc7d1d8b4daabd4cbd3b Mon Sep 17 00:00:00 2001 From: Philip Damianik <39028343+pdamianik@users.noreply.github.com> Date: Wed, 6 Sep 2023 16:14:18 +0200 Subject: config/input: Improve fallback behavior for unset device config values (#3184) * Fix fallback behavior for unset device config values * Replace overload with default argument for fallback config key * Remove default value for fallback argument in source * Fix typos --- src/config/ConfigManager.cpp | 31 +++++++++++-------------------- src/config/ConfigManager.hpp | 8 ++++---- 2 files changed, 15 insertions(+), 24 deletions(-) (limited to 'src/config') diff --git a/src/config/ConfigManager.cpp b/src/config/ConfigManager.cpp index 5aea669b..0865eae6 100644 --- a/src/config/ConfigManager.cpp +++ b/src/config/ConfigManager.cpp @@ -1685,7 +1685,7 @@ SConfigValue CConfigManager::getConfigValueSafe(const std::string& val) { return copy; } -SConfigValue CConfigManager::getConfigValueSafeDevice(const std::string& dev, const std::string& val, std::optional touchpad) { +SConfigValue CConfigManager::getConfigValueSafeDevice(const std::string& dev, const std::string& val, const std::string& fallback) { std::lock_guard lg(configmtx); const auto it = deviceConfigs.find(dev); @@ -1695,23 +1695,14 @@ SConfigValue CConfigManager::getConfigValueSafeDevice(const std::string& dev, co return SConfigValue(); } - SConfigValue copy = it->second[val]; + const SConfigValue DEVICECONFIG = it->second[val]; // fallback if not set explicitly - if (!copy.set) { - for (auto& cv : configValues) { - auto foundIt = cv.first.find(val); - if (foundIt == std::string::npos) - continue; - - if (cv.first == "input:" + val || (touchpad.value_or(true) && cv.first == "input:touchpad:" + val) || cv.first == "input:touchdevice:" + val || - cv.first == "input:tablet:" + val || cv.first == "input:tablet:" + val) { - copy = cv.second; - } - } + if (!DEVICECONFIG.set && !fallback.empty()) { + return configValues[fallback]; } - return copy; + return DEVICECONFIG; } int CConfigManager::getInt(const std::string& v) { @@ -1731,16 +1722,16 @@ std::string CConfigManager::getString(const std::string& v) { return VAL; } -int CConfigManager::getDeviceInt(const std::string& dev, const std::string& v, std::optional touchpad) { - return getConfigValueSafeDevice(dev, v, touchpad).intValue; +int CConfigManager::getDeviceInt(const std::string& dev, const std::string& v, const std::string& fallback) { + return getConfigValueSafeDevice(dev, v, fallback).intValue; } -float CConfigManager::getDeviceFloat(const std::string& dev, const std::string& v, std::optional touchpad) { - return getConfigValueSafeDevice(dev, v, touchpad).floatValue; +float CConfigManager::getDeviceFloat(const std::string& dev, const std::string& v, const std::string& fallback) { + return getConfigValueSafeDevice(dev, v, fallback).floatValue; } -std::string CConfigManager::getDeviceString(const std::string& dev, const std::string& v, std::optional touchpad) { - auto VAL = getConfigValueSafeDevice(dev, v, touchpad).strValue; +std::string CConfigManager::getDeviceString(const std::string& dev, const std::string& v, const std::string& fallback) { + auto VAL = getConfigValueSafeDevice(dev, v, fallback).strValue; if (VAL == STRVAL_EMPTY) return ""; diff --git a/src/config/ConfigManager.hpp b/src/config/ConfigManager.hpp index a14f5470..8586ec89 100644 --- a/src/config/ConfigManager.hpp +++ b/src/config/ConfigManager.hpp @@ -156,9 +156,9 @@ class CConfigManager { void setInt(const std::string&, int); void setString(const std::string&, const std::string&); - int getDeviceInt(const std::string&, const std::string&, std::optional touchpad = {}); - float getDeviceFloat(const std::string&, const std::string&, std::optional touchpad = {}); - std::string getDeviceString(const std::string&, const std::string&, std::optional touchpad = {}); + int getDeviceInt(const std::string&, const std::string&, const std::string& fallback = ""); + float getDeviceFloat(const std::string&, const std::string&, const std::string& fallback = ""); + std::string getDeviceString(const std::string&, const std::string&, const std::string& fallback = ""); bool deviceConfigExists(const std::string&); bool shouldBlurLS(const std::string&); @@ -255,7 +255,7 @@ class CConfigManager { void applyUserDefinedVars(std::string&, const size_t); void loadConfigLoadVars(); SConfigValue getConfigValueSafe(const std::string&); - SConfigValue getConfigValueSafeDevice(const std::string&, const std::string&, std::optional touchpad); + SConfigValue getConfigValueSafeDevice(const std::string&, const std::string&, const std::string& fallback = ""); void parseLine(std::string&); void configSetValueSafe(const std::string&, const std::string&); void handleDeviceConfig(const std::string&, const std::string&); -- cgit v1.2.3