Add recursive config includes

This commit is contained in:
Oskar Carl 2021-01-24 17:36:30 +01:00
parent d08fbb2ef2
commit 14f626d422
No known key found for this signature in database
GPG Key ID: 25FB862C4317BCA4
2 changed files with 19 additions and 1 deletions

View File

@ -39,6 +39,7 @@ class Client {
void handleOutput(struct waybar_output &output); void handleOutput(struct waybar_output &output);
bool isValidOutput(const Json::Value &config, struct waybar_output &output); bool isValidOutput(const Json::Value &config, struct waybar_output &output);
auto setupConfig(const std::string &config_file) -> void; auto setupConfig(const std::string &config_file) -> void;
auto mergeConfig(Json::Value &a_config_, Json::Value &b_config_) -> void;
auto setupCss(const std::string &css_file) -> void; auto setupCss(const std::string &css_file) -> void;
struct waybar_output & getOutput(void *); struct waybar_output & getOutput(void *);
std::vector<Json::Value> getOutputConfigs(struct waybar_output &output); std::vector<Json::Value> getOutputConfigs(struct waybar_output &output);

View File

@ -241,7 +241,24 @@ auto waybar::Client::setupConfig(const std::string &config_file) -> void {
} }
std::string str((std::istreambuf_iterator<char>(file)), std::istreambuf_iterator<char>()); std::string str((std::istreambuf_iterator<char>(file)), std::istreambuf_iterator<char>());
util::JsonParser parser; util::JsonParser parser;
config_ = parser.parse(str); Json::Value tmp_config_ = parser.parse(str);
if (tmp_config_["include"].isArray()) {
for (const auto& include : tmp_config_["include"]) {
spdlog::info("Including resource file: {}", include.asString());
setupConfig(getValidPath({include.asString()}));
}
}
mergeConfig(config_, tmp_config_);
}
auto waybar::Client::mergeConfig(Json::Value &a_config_, Json::Value &b_config_) -> void {
for (const auto& key : b_config_.getMemberNames()) {
if (a_config_[key].type() == Json::objectValue && b_config_[key].type() == Json::objectValue) {
mergeConfig(a_config_[key], b_config_[key]);
} else {
a_config_[key] = b_config_[key];
}
}
} }
auto waybar::Client::setupCss(const std::string &css_file) -> void { auto waybar::Client::setupCss(const std::string &css_file) -> void {