diff --git a/include/client.hpp b/include/client.hpp index 01551050..f3ef1351 100644 --- a/include/client.hpp +++ b/include/client.hpp @@ -29,6 +29,7 @@ class Client { private: void bindInterfaces(); auto setupCss(); + const std::string getValidPath(std::vector paths); static void handleGlobal(void *data, struct wl_registry *registry, uint32_t name, const char *interface, uint32_t version); diff --git a/src/client.cpp b/src/client.cpp index 1d7464c7..daa52cf3 100644 --- a/src/client.cpp +++ b/src/client.cpp @@ -12,30 +12,14 @@ waybar::Client::Client(int argc, char* argv[]) throw std::runtime_error("Bar need to run under Wayland"); } wl_display = gdk_wayland_display_get_wl_display(gdk_display->gobj()); - auto getFirstValidPath = [] (std::vector possiblePaths) { - wordexp_t p; - for (const std::string &path: possiblePaths) { - if (wordexp(path.c_str(), &p, 0) == 0) { - if (access(*p.we_wordv, F_OK) == 0) { - std::string result = *p.we_wordv; - wordfree(&p); - return result; - } - wordfree(&p); - } - } - - return std::string(); - }; - - config_file = getFirstValidPath({ + config_file = getValidPath({ "$XDG_CONFIG_HOME/waybar/config", "$HOME/waybar/config", "/etc/xdg/waybar/config", "./resources/config", }); - css_file = getFirstValidPath({ + css_file = getValidPath({ "$XDG_CONFIG_HOME/waybar/style.css", "$HOME/waybar/style.css", "/etc/xdg/waybar/style.css", @@ -47,6 +31,24 @@ waybar::Client::Client(int argc, char* argv[]) std::cout << "Resources files: " + config_file + ", " + css_file << std::endl; } +const std::string waybar::Client::getValidPath(std::vector paths) +{ + wordexp_t p; + + for (const std::string &path: paths) { + if (wordexp(path.c_str(), &p, 0) == 0) { + if (access(*p.we_wordv, F_OK) == 0) { + std::string result = *p.we_wordv; + wordfree(&p); + return result; + } + wordfree(&p); + } + } + + return std::string(); +} + void waybar::Client::handleGlobal(void *data, struct wl_registry *registry, uint32_t name, const char *interface, uint32_t version) {