refactor: avoid useless class vars
parent
2b34f3a30f
commit
ffadd5c1a7
|
@ -26,13 +26,14 @@ class Client {
|
||||||
|
|
||||||
private:
|
private:
|
||||||
Client() = default;
|
Client() = default;
|
||||||
void setupConfigs(const std::string &config, const std::string &style);
|
std::tuple<const std::string, const std::string> getConfigs(const std::string &config,
|
||||||
|
const std::string &style) const;
|
||||||
void bindInterfaces();
|
void bindInterfaces();
|
||||||
const std::string getValidPath(const std::vector<std::string> &paths);
|
const std::string getValidPath(const std::vector<std::string> &paths) const;
|
||||||
void handleOutput(std::unique_ptr<struct waybar_output> &output);
|
void handleOutput(std::unique_ptr<struct waybar_output> &output);
|
||||||
bool isValidOutput(const Json::Value &config, std::unique_ptr<struct waybar_output> &output);
|
bool isValidOutput(const Json::Value &config, std::unique_ptr<struct waybar_output> &output);
|
||||||
auto setupConfig() -> void;
|
auto setupConfig(const std::string &config_file) -> void;
|
||||||
auto setupCss() -> void;
|
auto setupCss(const std::string &css_file) -> void;
|
||||||
std::unique_ptr<struct waybar_output> &getOutput(uint32_t wl_name);
|
std::unique_ptr<struct waybar_output> &getOutput(uint32_t wl_name);
|
||||||
std::vector<Json::Value> getOutputConfigs(std::unique_ptr<struct waybar_output> &output);
|
std::vector<Json::Value> getOutputConfigs(std::unique_ptr<struct waybar_output> &output);
|
||||||
|
|
||||||
|
@ -46,8 +47,6 @@ class Client {
|
||||||
static void handleDescription(void *, struct zxdg_output_v1 *, const char *);
|
static void handleDescription(void *, struct zxdg_output_v1 *, const char *);
|
||||||
|
|
||||||
Json::Value config_;
|
Json::Value config_;
|
||||||
std::string css_file_;
|
|
||||||
std::string config_file_;
|
|
||||||
Glib::RefPtr<Gtk::StyleContext> style_context_;
|
Glib::RefPtr<Gtk::StyleContext> style_context_;
|
||||||
Glib::RefPtr<Gtk::CssProvider> css_provider_;
|
Glib::RefPtr<Gtk::CssProvider> css_provider_;
|
||||||
std::vector<std::unique_ptr<struct waybar_output>> outputs_;
|
std::vector<std::unique_ptr<struct waybar_output>> outputs_;
|
||||||
|
|
|
@ -10,7 +10,7 @@ waybar::Client *waybar::Client::inst() {
|
||||||
return c;
|
return c;
|
||||||
}
|
}
|
||||||
|
|
||||||
const std::string waybar::Client::getValidPath(const std::vector<std::string> &paths) {
|
const std::string waybar::Client::getValidPath(const std::vector<std::string> &paths) const {
|
||||||
wordexp_t p;
|
wordexp_t p;
|
||||||
|
|
||||||
for (const std::string &path : paths) {
|
for (const std::string &path : paths) {
|
||||||
|
@ -172,8 +172,9 @@ void waybar::Client::handleDescription(void * /*data*/, struct zxdg_output_v1 *
|
||||||
// Nothing here
|
// Nothing here
|
||||||
}
|
}
|
||||||
|
|
||||||
void waybar::Client::setupConfigs(const std::string &config, const std::string &style) {
|
std::tuple<const std::string, const std::string> waybar::Client::getConfigs(
|
||||||
config_file_ = config.empty() ? getValidPath({
|
const std::string &config, const std::string &style) const {
|
||||||
|
auto config_file = config.empty() ? getValidPath({
|
||||||
"$XDG_CONFIG_HOME/waybar/config",
|
"$XDG_CONFIG_HOME/waybar/config",
|
||||||
"$HOME/.config/waybar/config",
|
"$HOME/.config/waybar/config",
|
||||||
"$HOME/waybar/config",
|
"$HOME/waybar/config",
|
||||||
|
@ -181,7 +182,7 @@ void waybar::Client::setupConfigs(const std::string &config, const std::string &
|
||||||
"./resources/config",
|
"./resources/config",
|
||||||
})
|
})
|
||||||
: config;
|
: config;
|
||||||
css_file_ = style.empty() ? getValidPath({
|
auto css_file = style.empty() ? getValidPath({
|
||||||
"$XDG_CONFIG_HOME/waybar/style.css",
|
"$XDG_CONFIG_HOME/waybar/style.css",
|
||||||
"$HOME/.config/waybar/style.css",
|
"$HOME/.config/waybar/style.css",
|
||||||
"$HOME/waybar/style.css",
|
"$HOME/waybar/style.css",
|
||||||
|
@ -189,14 +190,15 @@ void waybar::Client::setupConfigs(const std::string &config, const std::string &
|
||||||
"./resources/style.css",
|
"./resources/style.css",
|
||||||
})
|
})
|
||||||
: style;
|
: style;
|
||||||
if (css_file_.empty() || config_file_.empty()) {
|
if (css_file.empty() || config_file.empty()) {
|
||||||
throw std::runtime_error("Missing required resources files");
|
throw std::runtime_error("Missing required resources files");
|
||||||
}
|
}
|
||||||
spdlog::info("Resources files: {}, {}", config_file_, css_file_);
|
spdlog::info("Resources files: {}, {}", config_file, css_file);
|
||||||
|
return {config_file, css_file};
|
||||||
}
|
}
|
||||||
|
|
||||||
auto waybar::Client::setupConfig() -> void {
|
auto waybar::Client::setupConfig(const std::string &config_file) -> void {
|
||||||
std::ifstream file(config_file_);
|
std::ifstream file(config_file);
|
||||||
if (!file.is_open()) {
|
if (!file.is_open()) {
|
||||||
throw std::runtime_error("Can't open config file");
|
throw std::runtime_error("Can't open config file");
|
||||||
}
|
}
|
||||||
|
@ -205,12 +207,12 @@ auto waybar::Client::setupConfig() -> void {
|
||||||
config_ = parser.parse(str);
|
config_ = parser.parse(str);
|
||||||
}
|
}
|
||||||
|
|
||||||
auto waybar::Client::setupCss() -> void {
|
auto waybar::Client::setupCss(const std::string &css_file) -> void {
|
||||||
css_provider_ = Gtk::CssProvider::create();
|
css_provider_ = Gtk::CssProvider::create();
|
||||||
style_context_ = Gtk::StyleContext::create();
|
style_context_ = Gtk::StyleContext::create();
|
||||||
|
|
||||||
// Load our css file, wherever that may be hiding
|
// Load our css file, wherever that may be hiding
|
||||||
if (!css_provider_->load_from_path(css_file_)) {
|
if (!css_provider_->load_from_path(css_file)) {
|
||||||
throw std::runtime_error("Can't open style file");
|
throw std::runtime_error("Can't open style file");
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -268,9 +270,9 @@ int waybar::Client::main(int argc, char *argv[]) {
|
||||||
throw std::runtime_error("Bar need to run under Wayland");
|
throw std::runtime_error("Bar need to run under Wayland");
|
||||||
}
|
}
|
||||||
wl_display = gdk_wayland_display_get_wl_display(gdk_display->gobj());
|
wl_display = gdk_wayland_display_get_wl_display(gdk_display->gobj());
|
||||||
setupConfigs(config, style);
|
auto [config_file, css_file] = getConfigs(config, style);
|
||||||
setupConfig();
|
setupConfig(config_file);
|
||||||
setupCss();
|
setupCss(css_file);
|
||||||
bindInterfaces();
|
bindInterfaces();
|
||||||
gtk_app->hold();
|
gtk_app->hold();
|
||||||
gtk_app->run();
|
gtk_app->run();
|
||||||
|
|
Loading…
Reference in New Issue