diff options
| author | xDarksome <dev@darkso.me> | 2022-07-02 19:43:52 +0300 |
|---|---|---|
| committer | GitHub <noreply@github.com> | 2022-07-02 19:43:52 +0300 |
| commit | 185c4d6ea13ad5f4483aa2e389e43bd09106002f (patch) | |
| tree | a7bc4a9510c39e367317b5ce64d2ee0e0a72d4f0 /src/config/ConfigManager.cpp | |
| parent | fc4b10d13c14c4eb08febb0637f27177cb6a1940 (diff) | |
| parent | b7b3344188e3ebd2baed14bc288ee42a1ae8d6f2 (diff) | |
Merge branch 'hyprwm:main' into main
Diffstat (limited to 'src/config/ConfigManager.cpp')
| -rw-r--r-- | src/config/ConfigManager.cpp | 151 |
1 files changed, 130 insertions, 21 deletions
diff --git a/src/config/ConfigManager.cpp b/src/config/ConfigManager.cpp index fb3aae1f..f313b155 100644 --- a/src/config/ConfigManager.cpp +++ b/src/config/ConfigManager.cpp @@ -15,6 +15,8 @@ CConfigManager::CConfigManager() { static const char* const ENVHOME = getenv("HOME"); const std::string CONFIGPATH = ENVHOME + (ISDEBUG ? (std::string) "/.config/hypr/hyprlandd.conf" : (std::string) "/.config/hypr/hyprland.conf"); configPaths.emplace_back(CONFIGPATH); + + Debug::disableLogs = &configValues["debug:disable_logs"].intValue; } void CConfigManager::setDefaultVars() { @@ -38,6 +40,8 @@ void CConfigManager::setDefaultVars() { configValues["debug:int"].intValue = 0; configValues["debug:log_damage"].intValue = 0; configValues["debug:overlay"].intValue = 0; + configValues["debug:damage_blink"].intValue = 0; + configValues["debug:disable_logs"].intValue = 0; configValues["decoration:rounding"].intValue = 1; configValues["decoration:blur"].intValue = 1; @@ -47,12 +51,13 @@ void CConfigManager::setDefaultVars() { configValues["decoration:active_opacity"].floatValue = 1; configValues["decoration:inactive_opacity"].floatValue = 1; configValues["decoration:fullscreen_opacity"].floatValue = 1; - configValues["decoration:multisample_edges"].intValue = 0; + configValues["decoration:multisample_edges"].intValue = 1; configValues["decoration:no_blur_on_oversized"].intValue = 1; configValues["decoration:drop_shadow"].intValue = 1; configValues["decoration:shadow_range"].intValue = 4; configValues["decoration:shadow_render_power"].intValue = 3; configValues["decoration:shadow_ignore_window"].intValue = 1; + configValues["decoration:shadow_offset"].strValue = "0 0"; configValues["decoration:col.shadow"].intValue = 0xee1a1a1a; configValues["dwindle:pseudotile"].intValue = 0; @@ -103,6 +108,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(); @@ -132,33 +155,58 @@ 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); } + CONFIGENTRY->set = true; - 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 + ">."; @@ -611,8 +659,8 @@ std::string CConfigManager::parseKeyword(const std::string& COMMAND, const std:: parseError = ""; // invalidate layouts jic - for (auto& m : g_pCompositor->m_lMonitors) - g_pLayoutManager->getCurrentLayout()->recalculateMonitor(m.ID); + for (auto& m : g_pCompositor->m_vMonitors) + g_pLayoutManager->getCurrentLayout()->recalculateMonitor(m->ID); // Update window border colors g_pCompositor->updateAllWindowsBorders(); @@ -704,6 +752,7 @@ void CConfigManager::loadConfigLoadVars() { g_pAnimationManager->removeAllBeziers(); m_mAdditionalReservedAreas.clear(); configDynamicVars.clear(); + deviceConfigs.clear(); // paths configPaths.clear(); @@ -772,8 +821,8 @@ void CConfigManager::loadConfigLoadVars() { ifs.close(); } - for (auto& m : g_pCompositor->m_lMonitors) - g_pLayoutManager->getCurrentLayout()->recalculateMonitor(m.ID); + for (auto& m : g_pCompositor->m_vMonitors) + g_pLayoutManager->getCurrentLayout()->recalculateMonitor(m->ID); // Update the keyboard layout to the cfg'd one if this is not the first launch if (!isFirstLaunch) @@ -806,6 +855,10 @@ void CConfigManager::loadConfigLoadVars() { // Update window border colors g_pCompositor->updateAllWindowsBorders(); + + // Force the compositor to fully re-render all monitors + for (auto& m : g_pCompositor->m_vMonitors) + m->forceFullFrames = 2; } void CConfigManager::tick() { @@ -843,7 +896,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]; @@ -851,15 +904,38 @@ 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]; + + // fallback if not set explicitly + if (!copy.set) { + for (auto& cv : configValues) { + if (cv.first.find(val) == cv.first.length() - val.length()) { + copy = cv.second; + } + } + } + + 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) @@ -868,6 +944,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; } @@ -964,14 +1057,30 @@ void CConfigManager::dispatchExecOnce() { } void CConfigManager::performMonitorReload() { - for (auto& m : g_pCompositor->m_lMonitors) { - auto rule = getMonitorRuleFor(m.szName); - g_pHyprRenderer->applyMonitorRule(&m, &rule); + + bool overAgain = false; + + for (auto& m : g_pCompositor->m_vMonitors) { + auto rule = getMonitorRuleFor(m->szName); + if (!g_pHyprRenderer->applyMonitorRule(m.get(), &rule)) { + overAgain = true; + break; + } } + if (overAgain) + performMonitorReload(); + m_bWantsMonitorReload = false; } 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(); +} + |
