summaryrefslogtreecommitdiff
path: root/src/config/ConfigManager.cpp
diff options
context:
space:
mode:
authorvaxerski <43317083+vaxerski@users.noreply.github.com>2022-06-30 21:26:00 +0200
committervaxerski <43317083+vaxerski@users.noreply.github.com>2022-06-30 21:26:00 +0200
commitd010ca20492c7638d15690e888d80c6020685df1 (patch)
treea5f6ea02252fb8bddf00970f6b1a6349dd1e7537 /src/config/ConfigManager.cpp
parent4510764f348d1a7c4cca613925ee22acfa38b388 (diff)
added per-device config options
Diffstat (limited to 'src/config/ConfigManager.cpp')
-rw-r--r--src/config/ConfigManager.cpp106
1 files changed, 93 insertions, 13 deletions
diff --git a/src/config/ConfigManager.cpp b/src/config/ConfigManager.cpp
index 75546a63..d76a1800 100644
--- a/src/config/ConfigManager.cpp
+++ b/src/config/ConfigManager.cpp
@@ -105,6 +105,24 @@ void CConfigManager::setDefaultVars() {
configValues["autogenerated"].intValue = 0;
}
+void CConfigManager::setDeviceDefaultVars(const std::string& dev) {
+ auto& cfgValues = deviceConfigs[dev];
+
+ cfgValues["kb_layout"].strValue = "us";
+ cfgValues["kb_variant"].strValue = STRVAL_EMPTY;
+ cfgValues["kb_options"].strValue = STRVAL_EMPTY;
+ cfgValues["kb_rules"].strValue = STRVAL_EMPTY;
+ cfgValues["kb_model"].strValue = STRVAL_EMPTY;
+ cfgValues["repeat_rate"].intValue = 25;
+ cfgValues["repeat_delay"].intValue = 600;
+ cfgValues["natural_scroll"].intValue = 0;
+ cfgValues["numlock_by_default"].intValue = 0;
+ cfgValues["disable_while_typing"].intValue = 1;
+ cfgValues["clickfinger_behavior"].intValue = 0;
+ cfgValues["middle_button_emulation"].intValue = 0;
+ cfgValues["tap-to-click"].intValue = 1;
+}
+
void CConfigManager::init() {
loadConfigLoadVars();
@@ -134,33 +152,56 @@ void CConfigManager::configSetValueSafe(const std::string& COMMAND, const std::s
parseError = "Error setting value <" + VALUE + "> for field <" + COMMAND + ">: No such field.";
}
- return;
+ if (COMMAND.find("device:") == 0 /* devices parsed later */) {
+ parseError = "";
+ } else {
+ return;
+ }
}
+ SConfigValue* CONFIGENTRY = nullptr;
+
+ if (COMMAND.find("device:") == 0) {
+ const auto DEVICE = COMMAND.substr(7).substr(0, COMMAND.find_last_of(':') - 7);
+ const auto CONFIGVAR = COMMAND.substr(COMMAND.find_last_of(':') + 1);
+
+ if (!deviceConfigExists(DEVICE))
+ setDeviceDefaultVars(DEVICE);
+
+ auto it = deviceConfigs.find(DEVICE);
+
+ if (it->second.find(CONFIGVAR) == it->second.end()) {
+ parseError = "Error setting value <" + VALUE + "> for field <" + COMMAND + ">: No such field.";
+ return;
+ }
+
+ CONFIGENTRY = &it->second.at(CONFIGVAR);
+ } else {
+ CONFIGENTRY = &configValues.at(COMMAND);
+ }
- auto& CONFIGENTRY = configValues.at(COMMAND);
- if (CONFIGENTRY.intValue != -1) {
+ if (CONFIGENTRY->intValue != -1) {
try {
if (VALUE.find("0x") == 0) {
// Values with 0x are hex
const auto VALUEWITHOUTHEX = VALUE.substr(2);
- CONFIGENTRY.intValue = stol(VALUEWITHOUTHEX, nullptr, 16);
+ CONFIGENTRY->intValue = stol(VALUEWITHOUTHEX, nullptr, 16);
} else
- CONFIGENTRY.intValue = stol(VALUE);
+ CONFIGENTRY->intValue = stol(VALUE);
} catch (...) {
Debug::log(WARN, "Error reading value of %s", COMMAND.c_str());
parseError = "Error setting value <" + VALUE + "> for field <" + COMMAND + ">.";
}
- } else if (CONFIGENTRY.floatValue != -1) {
+ } else if (CONFIGENTRY->floatValue != -1) {
try {
- CONFIGENTRY.floatValue = stof(VALUE);
+ CONFIGENTRY->floatValue = stof(VALUE);
} catch (...) {
Debug::log(WARN, "Error reading value of %s", COMMAND.c_str());
parseError = "Error setting value <" + VALUE + "> for field <" + COMMAND + ">.";
}
- } else if (CONFIGENTRY.strValue != "") {
+ } else if (CONFIGENTRY->strValue != "") {
try {
- CONFIGENTRY.strValue = VALUE;
+ CONFIGENTRY->strValue = VALUE;
} catch (...) {
Debug::log(WARN, "Error reading value of %s", COMMAND.c_str());
parseError = "Error setting value <" + VALUE + "> for field <" + COMMAND + ">.";
@@ -706,6 +747,7 @@ void CConfigManager::loadConfigLoadVars() {
g_pAnimationManager->removeAllBeziers();
m_mAdditionalReservedAreas.clear();
configDynamicVars.clear();
+ deviceConfigs.clear();
// paths
configPaths.clear();
@@ -849,7 +891,7 @@ void CConfigManager::tick() {
}
std::mutex configmtx;
-SConfigValue CConfigManager::getConfigValueSafe(std::string val) {
+SConfigValue CConfigManager::getConfigValueSafe(const std::string& val) {
std::lock_guard<std::mutex> lg(configmtx);
SConfigValue copy = configValues[val];
@@ -857,15 +899,29 @@ SConfigValue CConfigManager::getConfigValueSafe(std::string val) {
return copy;
}
-int CConfigManager::getInt(std::string v) {
+SConfigValue CConfigManager::getConfigValueSafeDevice(const std::string& dev, const std::string& val) {
+ std::lock_guard<std::mutex> lg(configmtx);
+
+ const auto it = deviceConfigs.find(dev);
+
+ if (it == deviceConfigs.end()) {
+ return SConfigValue();
+ }
+
+ SConfigValue copy = it->second[val];
+
+ return copy;
+}
+
+int CConfigManager::getInt(const std::string& v) {
return getConfigValueSafe(v).intValue;
}
-float CConfigManager::getFloat(std::string v) {
+float CConfigManager::getFloat(const std::string& v) {
return getConfigValueSafe(v).floatValue;
}
-std::string CConfigManager::getString(std::string v) {
+std::string CConfigManager::getString(const std::string& v) {
const auto VAL = getConfigValueSafe(v).strValue;
if (VAL == STRVAL_EMPTY)
@@ -874,6 +930,23 @@ std::string CConfigManager::getString(std::string v) {
return VAL;
}
+int CConfigManager::getDeviceInt(const std::string& dev, const std::string& v) {
+ return getConfigValueSafeDevice(dev, v).intValue;
+}
+
+float CConfigManager::getDeviceFloat(const std::string& dev, const std::string& v) {
+ return getConfigValueSafeDevice(dev, v).floatValue;
+}
+
+std::string CConfigManager::getDeviceString(const std::string& dev, const std::string& v) {
+ const auto VAL = getConfigValueSafeDevice(dev, v).strValue;
+
+ if (VAL == STRVAL_EMPTY)
+ return "";
+
+ return VAL;
+}
+
void CConfigManager::setInt(std::string v, int val) {
configValues[v].intValue = val;
}
@@ -981,3 +1054,10 @@ void CConfigManager::performMonitorReload() {
SConfigValue* CConfigManager::getConfigValuePtr(std::string val) {
return &configValues[val];
}
+
+bool CConfigManager::deviceConfigExists(const std::string& dev) {
+ const auto it = deviceConfigs.find(dev);
+
+ return it != deviceConfigs.end();
+}
+