2021-08-13 13:08:27 +00:00
|
|
|
#pragma once
|
|
|
|
|
|
|
|
#include <json/json.h>
|
|
|
|
|
2021-08-13 14:19:47 +00:00
|
|
|
#include <optional>
|
2021-08-13 13:08:27 +00:00
|
|
|
#include <string>
|
|
|
|
|
2021-08-13 14:19:47 +00:00
|
|
|
#ifndef SYSCONFDIR
|
|
|
|
#define SYSCONFDIR "/etc"
|
|
|
|
#endif
|
|
|
|
|
2021-08-13 13:08:27 +00:00
|
|
|
namespace waybar {
|
|
|
|
|
|
|
|
class Config {
|
|
|
|
public:
|
2021-08-13 14:19:47 +00:00
|
|
|
static const std::vector<std::string> CONFIG_DIRS;
|
2022-06-25 10:16:40 +00:00
|
|
|
static const char *CONFIG_PATH_ENV;
|
2021-08-13 13:08:27 +00:00
|
|
|
|
2021-08-13 14:19:47 +00:00
|
|
|
/* Try to find any of provided names in the supported set of config directories */
|
|
|
|
static std::optional<std::string> findConfigPath(
|
|
|
|
const std::vector<std::string> &names, const std::vector<std::string> &dirs = CONFIG_DIRS);
|
|
|
|
|
2024-08-01 09:47:10 +00:00
|
|
|
static std::optional<std::string> tryExpandPath(const std::string &base,
|
|
|
|
const std::string &filename);
|
|
|
|
|
2021-08-13 14:19:47 +00:00
|
|
|
Config() = default;
|
2021-08-13 13:08:27 +00:00
|
|
|
|
2021-08-13 14:19:47 +00:00
|
|
|
void load(const std::string &config);
|
2021-08-13 13:08:27 +00:00
|
|
|
|
|
|
|
Json::Value &getConfig() { return config_; }
|
|
|
|
|
|
|
|
std::vector<Json::Value> getOutputConfigs(const std::string &name, const std::string &identifier);
|
|
|
|
|
|
|
|
private:
|
2021-09-14 05:16:37 +00:00
|
|
|
void setupConfig(Json::Value &dst, const std::string &config_file, int depth);
|
2021-08-13 13:08:27 +00:00
|
|
|
void resolveConfigIncludes(Json::Value &config, int depth);
|
|
|
|
void mergeConfig(Json::Value &a_config_, Json::Value &b_config_);
|
|
|
|
|
|
|
|
std::string config_file_;
|
|
|
|
|
|
|
|
Json::Value config_;
|
|
|
|
};
|
|
|
|
} // namespace waybar
|