refactor(client): extract config handling into a new class

This commit is contained in:
Aleksei Bavshin
2021-08-13 06:08:27 -07:00
parent 4e256cf3f0
commit b377520a38
5 changed files with 204 additions and 156 deletions

View File

@ -3,11 +3,10 @@
#include <fmt/format.h>
#include <gdk/gdk.h>
#include <gdk/gdkwayland.h>
#include <unistd.h>
#include <wayland-client.h>
#include <wordexp.h>
#include "bar.hpp"
#include "config.hpp"
struct zwlr_layer_shell_v1;
struct zwp_idle_inhibitor_v1;
@ -32,15 +31,8 @@ class Client {
private:
Client() = default;
std::tuple<const std::string, const std::string> getConfigs(const std::string &config,
const std::string &style) const;
void bindInterfaces();
const std::string getValidPath(const std::vector<std::string> &paths) const;
void bindInterfaces();
void handleOutput(struct waybar_output &output);
bool isValidOutput(const Json::Value &config, struct waybar_output &output);
auto setupConfig(const std::string &config_file, int depth) -> void;
auto resolveConfigIncludes(Json::Value &config, int depth) -> void;
auto mergeConfig(Json::Value &a_config_, Json::Value &b_config_) -> void;
auto setupCss(const std::string &css_file) -> void;
struct waybar_output & getOutput(void *);
std::vector<Json::Value> getOutputConfigs(struct waybar_output &output);
@ -55,7 +47,7 @@ class Client {
void handleMonitorRemoved(Glib::RefPtr<Gdk::Monitor> monitor);
void handleDeferredMonitorRemoval(Glib::RefPtr<Gdk::Monitor> monitor);
Json::Value config_;
Config config_;
Glib::RefPtr<Gtk::StyleContext> style_context_;
Glib::RefPtr<Gtk::CssProvider> css_provider_;
std::list<struct waybar_output> outputs_;

31
include/config.hpp Normal file
View File

@ -0,0 +1,31 @@
#pragma once
#include <json/json.h>
#include <string>
namespace waybar {
class Config {
public:
Config() = default;
void load(const std::string &config, const std::string &style);
const std::string &getStyle() { return css_file_; }
Json::Value &getConfig() { return config_; }
std::vector<Json::Value> getOutputConfigs(const std::string &name, const std::string &identifier);
private:
void setupConfig(const std::string &config_file, int depth);
void resolveConfigIncludes(Json::Value &config, int depth);
void mergeConfig(Json::Value &a_config_, Json::Value &b_config_);
std::string config_file_;
std::string css_file_;
Json::Value config_;
};
} // namespace waybar