diff --git a/CMakeLists.txt b/CMakeLists.txt index 2525385..20483a0 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -33,7 +33,7 @@ message(STATUS "Checking deps...") find_package(Threads REQUIRED) find_package(PkgConfig REQUIRED) -pkg_check_modules(deps REQUIRED IMPORTED_TARGET wayland-client wayland-protocols hyprlang>=0.4.0 sdbus-c++) +pkg_check_modules(deps REQUIRED IMPORTED_TARGET wayland-client wayland-protocols hyprlang>=0.4.0 hyprutils>=0.2.0 sdbus-c++) file(GLOB_RECURSE SRCFILES CONFIGURE_DEPENDS "src/*.cpp") add_executable(hypridle ${SRCFILES}) diff --git a/src/config/ConfigManager.cpp b/src/config/ConfigManager.cpp index 4b2879c..95d6854 100644 --- a/src/config/ConfigManager.cpp +++ b/src/config/ConfigManager.cpp @@ -1,20 +1,17 @@ #include "ConfigManager.hpp" +#include #include -static std::string getConfigDir() { - static const char* xdgConfigHome = getenv("XDG_CONFIG_HOME"); - - if (xdgConfigHome && std::filesystem::path(xdgConfigHome).is_absolute()) - return xdgConfigHome; - - return getenv("HOME") + std::string("/.config"); -} - static std::string getMainConfigPath() { - return getConfigDir() + "/hypr/hypridle.conf"; + static const auto paths = Hyprutils::Path::findConfig("hypridle"); + 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) : m_config(configPath.empty() ? getMainConfigPath().c_str() : configPath.c_str(), Hyprlang::SConfigOptions{.throwAllErrors = true, .allowMissingConfig = false}) { +CConfigManager::CConfigManager(std::string configPath) : + m_config(configPath.empty() ? getMainConfigPath().c_str() : configPath.c_str(), Hyprlang::SConfigOptions{.throwAllErrors = true, .allowMissingConfig = false}) { ; }