Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add different default paths for config and css files #1

Merged
merged 1 commit into from Aug 9, 2018
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 5 additions & 2 deletions include/client.hpp
Original file line number Diff line number Diff line change
@@ -1,5 +1,8 @@
#pragma once

#include <unistd.h>
#include <wordexp.h>

#include <iostream>

#include <fmt/format.h>
Expand All @@ -21,8 +24,8 @@ namespace waybar {

struct Client {
uint32_t height = 30;
std::string cssFile = "./resources/style.css";
std::string configFile = "./resources/config";
std::string cssFile;
std::string configFile;

Gtk::Main gtk_main;

Expand Down
32 changes: 31 additions & 1 deletion src/client.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,37 @@ waybar::Client::Client(int argc, char* argv[])
: gtk_main(argc, argv),
gdk_display(Gdk::Display::get_default()),
wlDisplay(gdk_wayland_display_get_wl_display(gdk_display->gobj()))
{}
{
auto getFirstValidPath = [] (std::vector<std::string> possiblePaths) {
wordexp_t p;

for (std::string path: possiblePaths) {
if (wordexp(path.c_str(), &p, 0) == 0) {
if (access(p.we_wordv[0], F_OK) == 0) {
std::string result = p.we_wordv[0];
wordfree(&p);
return result;
} else {
wordfree(&p);
}
}
}

return std::string();
};

configFile = getFirstValidPath({
"$XDG_CONFIG_HOME/waybar/config",
"$HOME/waybar/config",
"./resources/config",
});
cssFile = getFirstValidPath({
"$XDG_CONFIG_HOME/waybar/style.css",
"$HOME/waybar/style.css",
"./resources/style.css",
});

}

void waybar::Client::bind_interfaces()
{
Expand Down