Relative paths in included configs

This commit is contained in:
Arkoniak
2025-07-29 10:45:31 +03:00
parent 0776e694df
commit f824ae9334
4 changed files with 27 additions and 5 deletions

View File

@ -35,6 +35,7 @@ class Config {
void setupConfig(Json::Value &dst, const std::string &config_file, int depth); void setupConfig(Json::Value &dst, const std::string &config_file, int depth);
void resolveConfigIncludes(Json::Value &config, int depth); void resolveConfigIncludes(Json::Value &config, int depth);
void mergeConfig(Json::Value &a_config_, Json::Value &b_config_); void mergeConfig(Json::Value &a_config_, Json::Value &b_config_);
std::optional<std::string> findIncludePath(const std::string name);
std::string config_file_; std::string config_file_;

View File

@ -496,7 +496,11 @@ void waybar::Bar::getModules(const Factory& factory, const std::string& pos,
auto vertical = (group != nullptr ? group->getBox().get_orientation() auto vertical = (group != nullptr ? group->getBox().get_orientation()
: box_.get_orientation()) == Gtk::ORIENTATION_VERTICAL; : box_.get_orientation()) == Gtk::ORIENTATION_VERTICAL;
auto* group_module = new waybar::Group(id_name, class_name, config[ref], vertical); auto group_config = config[ref];
if (group_config["modules"].isNull()) {
spdlog::warn("Group definition '{}' has not been found, group will be hidden", ref);
}
auto* group_module = new waybar::Group(id_name, class_name, group_config, vertical);
getModules(factory, ref, group_module); getModules(factory, ref, group_module);
module = group_module; module = group_module;
} else { } else {

View File

@ -89,19 +89,33 @@ void Config::setupConfig(Json::Value &dst, const std::string &config_file, int d
mergeConfig(dst, tmp_config); mergeConfig(dst, tmp_config);
} }
std::optional<std::string> Config::findIncludePath(const std::string name) {
auto match1 = tryExpandPath(name, "");
if (!match1.empty()) {
return match1.front();
}
return findConfigPath({name});
}
void Config::resolveConfigIncludes(Json::Value &config, int depth) { void Config::resolveConfigIncludes(Json::Value &config, int depth) {
Json::Value includes = config["include"]; Json::Value includes = config["include"];
if (includes.isArray()) { if (includes.isArray()) {
for (const auto &include : includes) { for (const auto &include : includes) {
spdlog::info("Including resource file: {}", include.asString()); spdlog::info("Including resource file: {}", include.asString());
for (const auto &match : tryExpandPath(include.asString(), "")) { auto match = findIncludePath(include.asString());
setupConfig(config, match, depth + 1); if (match.has_value()) {
setupConfig(config, match.value(), depth + 1);
} else {
spdlog::warn("Unable to find resource file: {}", include.asString());
} }
} }
} else if (includes.isString()) { } else if (includes.isString()) {
spdlog::info("Including resource file: {}", includes.asString()); spdlog::info("Including resource file: {}", includes.asString());
for (const auto &match : tryExpandPath(includes.asString(), "")) { auto match = findIncludePath(includes.asString());
setupConfig(config, match, depth + 1); if (match.has_value()) {
setupConfig(config, match.value(), depth + 1);
} else {
spdlog::warn("Unable to find resource file: {}", includes.asString());
} }
} }
} }

View File

@ -14,6 +14,9 @@ waybar::modules::Custom::Custom(const std::string& name, const std::string& id,
percentage_(0), percentage_(0),
fp_(nullptr), fp_(nullptr),
pid_(-1) { pid_(-1) {
if (config.isNull()) {
spdlog::warn("There is no configuration for 'custom/{}', element will be hidden", name);
}
dp.emit(); dp.emit();
if (!config_["signal"].empty() && config_["interval"].empty() && if (!config_["signal"].empty() && config_["interval"].empty() &&
config_["restart-interval"].empty()) { config_["restart-interval"].empty()) {