From bcfb13c26b0f20c7596fd87ee735bfd6457d850e Mon Sep 17 00:00:00 2001 From: Mihai Fufezan Date: Tue, 16 Jul 2024 22:30:19 +0300 Subject: [PATCH] config: use hyprutils helper --- src/config/ConfigManager.cpp | 21 ++++++--------------- 1 file changed, 6 insertions(+), 15 deletions(-) diff --git a/src/config/ConfigManager.cpp b/src/config/ConfigManager.cpp index 30d7b9f..b6e6dc2 100644 --- a/src/config/ConfigManager.cpp +++ b/src/config/ConfigManager.cpp @@ -1,6 +1,7 @@ #include "ConfigManager.hpp" #include "../helpers/MiscFunctions.hpp" #include "src/helpers/Log.hpp" +#include #include #include #include @@ -18,22 +19,12 @@ static Hyprlang::CParseResult handleSource(const char* c, const char* v) { return result; } -static std::string getConfigDir() { - static const char* xdgConfigHome = getenv("XDG_CONFIG_HOME"); - - if (xdgConfigHome && std::filesystem::path(xdgConfigHome).is_absolute()) - return xdgConfigHome; - - static const char* home = getenv("HOME"); - - if (!home) - throw std::runtime_error("Neither HOME nor XDG_CONFIG_HOME is set in the environment. Cannot determine config directory."); - - return home + std::string("/.config"); -} - static std::string getMainConfigPath() { - return getConfigDir() + "/hypr/hyprlock.conf"; + static const auto paths = Hyprutils::Path::findConfig("hyprlock"); + if (paths.first.has_value()) + return paths.first.value(); + else + throw std::runtime_error("Could not find config in HOME, XDG_CONFIG_HOME, XDG_CONFIG_DIRS or /etc/hypr."); } CConfigManager::CConfigManager(std::string configPath) :