mirror of
https://github.com/rad4day/Waybar.git
synced 2023-12-21 10:22:59 +01:00
refactor(client): lambda to method
This commit is contained in:
parent
2c2a0473f4
commit
087de4e956
@ -29,6 +29,7 @@ class Client {
|
|||||||
private:
|
private:
|
||||||
void bindInterfaces();
|
void bindInterfaces();
|
||||||
auto setupCss();
|
auto setupCss();
|
||||||
|
const std::string getValidPath(std::vector<std::string> paths);
|
||||||
|
|
||||||
static void handleGlobal(void *data, struct wl_registry *registry,
|
static void handleGlobal(void *data, struct wl_registry *registry,
|
||||||
uint32_t name, const char *interface, uint32_t version);
|
uint32_t name, const char *interface, uint32_t version);
|
||||||
|
@ -12,10 +12,30 @@ waybar::Client::Client(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());
|
||||||
auto getFirstValidPath = [] (std::vector<std::string> possiblePaths) {
|
|
||||||
|
config_file = getValidPath({
|
||||||
|
"$XDG_CONFIG_HOME/waybar/config",
|
||||||
|
"$HOME/waybar/config",
|
||||||
|
"/etc/xdg/waybar/config",
|
||||||
|
"./resources/config",
|
||||||
|
});
|
||||||
|
css_file = getValidPath({
|
||||||
|
"$XDG_CONFIG_HOME/waybar/style.css",
|
||||||
|
"$HOME/waybar/style.css",
|
||||||
|
"/etc/xdg/waybar/style.css",
|
||||||
|
"./resources/style.css",
|
||||||
|
});
|
||||||
|
if (css_file.empty() || config_file.empty()) {
|
||||||
|
throw std::runtime_error("Missing required resources files");
|
||||||
|
}
|
||||||
|
std::cout << "Resources files: " + config_file + ", " + css_file << std::endl;
|
||||||
|
}
|
||||||
|
|
||||||
|
const std::string waybar::Client::getValidPath(std::vector<std::string> paths)
|
||||||
|
{
|
||||||
wordexp_t p;
|
wordexp_t p;
|
||||||
|
|
||||||
for (const std::string &path: possiblePaths) {
|
for (const std::string &path: paths) {
|
||||||
if (wordexp(path.c_str(), &p, 0) == 0) {
|
if (wordexp(path.c_str(), &p, 0) == 0) {
|
||||||
if (access(*p.we_wordv, F_OK) == 0) {
|
if (access(*p.we_wordv, F_OK) == 0) {
|
||||||
std::string result = *p.we_wordv;
|
std::string result = *p.we_wordv;
|
||||||
@ -27,24 +47,6 @@ waybar::Client::Client(int argc, char* argv[])
|
|||||||
}
|
}
|
||||||
|
|
||||||
return std::string();
|
return std::string();
|
||||||
};
|
|
||||||
|
|
||||||
config_file = getFirstValidPath({
|
|
||||||
"$XDG_CONFIG_HOME/waybar/config",
|
|
||||||
"$HOME/waybar/config",
|
|
||||||
"/etc/xdg/waybar/config",
|
|
||||||
"./resources/config",
|
|
||||||
});
|
|
||||||
css_file = getFirstValidPath({
|
|
||||||
"$XDG_CONFIG_HOME/waybar/style.css",
|
|
||||||
"$HOME/waybar/style.css",
|
|
||||||
"/etc/xdg/waybar/style.css",
|
|
||||||
"./resources/style.css",
|
|
||||||
});
|
|
||||||
if (css_file.empty() || config_file.empty()) {
|
|
||||||
throw std::runtime_error("Missing required resources files");
|
|
||||||
}
|
|
||||||
std::cout << "Resources files: " + config_file + ", " + css_file << std::endl;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
void waybar::Client::handleGlobal(void *data, struct wl_registry *registry,
|
void waybar::Client::handleGlobal(void *data, struct wl_registry *registry,
|
||||||
|
Loading…
Reference in New Issue
Block a user