Added support for XDG_CONFIG_HOME (#62)

* Added support for XDG_CONFIG_HOME

* Style fixes and null check
This commit is contained in:
Ed Younis 2023-07-16 18:44:16 -04:00 committed by GitHub
parent a1d9ab7584
commit ac5f7b038d
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
2 changed files with 20 additions and 15 deletions

View file

@ -6,23 +6,13 @@ CConfigManager::CConfigManager() {
// Read file from default location
// or from an explicit location given by user
std::string configPath;
if (g_pHyprpaper->m_szExplicitConfigPath.empty()) {
const char* const ENVHOME = getenv("HOME");
configPath = ENVHOME + std::string("/.config/hypr/hyprpaper.conf");
} else {
configPath = g_pHyprpaper->m_szExplicitConfigPath;
}
std::string configPath = getMainConfigPath();
std::ifstream ifs;
ifs.open(configPath);
if (!ifs.good()) {
if (g_pHyprpaper->m_szExplicitConfigPath.empty()) {
Debug::log(CRIT, "No config file provided. Default config file `~/.config/hypr/hyprpaper.conf` couldn't be opened.");
} else {
Debug::log(CRIT, "No config file provided. Specified file `%s` couldn't be opened.", configPath.c_str());
}
Debug::log(CRIT, "Config file `%s` couldn't be opened.", configPath.c_str());
exit(1);
}
@ -58,6 +48,20 @@ CConfigManager::CConfigManager() {
}
}
std::string CConfigManager::getMainConfigPath() {
if (!g_pHyprpaper->m_szExplicitConfigPath.empty())
return g_pHyprpaper->m_szExplicitConfigPath;
static const char* xdgConfigHome = getenv("XDG_CONFIG_HOME");
std::string configPath;
if (!xdgConfigHome)
configPath = getenv("HOME") + std::string("/.config");
else
configPath = xdgConfigHome;
return configPath + "/hypr/hyprpaper.conf";
}
std::string CConfigManager::removeBeginEndSpacesTabs(std::string str) {
while (str[0] == ' ' || str[0] == '\t') {
str = str.substr(1);

View file

@ -9,6 +9,7 @@ public:
CConfigManager();
std::deque<std::string> m_dRequestedPreloads;
std::string getMainConfigPath();
private:
std::string parseError;