From a3d8a2c128f7f610b4c62e78c801a100a731cd95 Mon Sep 17 00:00:00 2001 From: Mihai Fufezan Date: Tue, 16 Jul 2024 23:35:48 +0300 Subject: [PATCH] Config: use hyprutils helper (#422) * flake.lock: update * gitignore: add CMake residual files * config: use hyprutils helper * CMake: update required hyprutils version --- .gitignore | 6 +++++- CMakeLists.txt | 2 +- flake.lock | 18 +++++++++--------- src/config/ConfigManager.cpp | 21 ++++++--------------- 4 files changed, 21 insertions(+), 26 deletions(-) diff --git a/.gitignore b/.gitignore index 068ac23..2e1902e 100644 --- a/.gitignore +++ b/.gitignore @@ -1,7 +1,11 @@ -.cache +**/.cache .direnv .envrc .vscode/ +CMakeCache.txt +CMakeFiles/ +Makefile +cmake_install.cmake build/ compile_commands.json protocols/*.c diff --git a/CMakeLists.txt b/CMakeLists.txt index 162a1e6..8500386 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -39,7 +39,7 @@ message(STATUS "Checking deps...") find_package(Threads REQUIRED) find_package(PkgConfig REQUIRED) find_package(OpenGL REQUIRED) -pkg_check_modules(deps REQUIRED IMPORTED_TARGET wayland-client wayland-protocols wayland-egl hyprlang>=0.4.0 egl opengl xkbcommon libjpeg libwebp libmagic cairo pangocairo libdrm gbm hyprutils>=0.1.1) +pkg_check_modules(deps REQUIRED IMPORTED_TARGET wayland-client wayland-protocols wayland-egl hyprlang>=0.4.0 egl opengl xkbcommon libjpeg libwebp libmagic cairo pangocairo libdrm gbm hyprutils>=0.2.0) file(GLOB_RECURSE SRCFILES CONFIGURE_DEPENDS "src/*.cpp") add_executable(hyprlock ${SRCFILES}) diff --git a/flake.lock b/flake.lock index 7a53cde..0c9f072 100644 --- a/flake.lock +++ b/flake.lock @@ -13,11 +13,11 @@ ] }, "locked": { - "lastModified": 1717881852, - "narHash": "sha256-XeeVoKHQgfKuXoP6q90sUqKyl7EYy3ol2dVZGM+Jj94=", + "lastModified": 1720381373, + "narHash": "sha256-lyC/EZdHULsaAKVryK11lgHY9u6pXr7qR4irnxNWC7k=", "owner": "hyprwm", "repo": "hyprlang", - "rev": "ec6938c66253429192274d612912649a0cfe4d28", + "rev": "5df0174fd09de4ac5475233d65ffc703e89b82eb", "type": "github" }, "original": { @@ -36,11 +36,11 @@ ] }, "locked": { - "lastModified": 1717881334, - "narHash": "sha256-a0inRgJhPL6v9v7RPM/rx1kbXdfe3xJA1c9z0ZkYnh4=", + "lastModified": 1721071737, + "narHash": "sha256-qmC9jGfbE4+EIBbbSAkrfR/p49wShjpv4/KztgE/P54=", "owner": "hyprwm", "repo": "hyprutils", - "rev": "0693f9398ab693d89c9a0aa3b3d062dd61b7a60e", + "rev": "eb1ceff2b87f6820789249f63faa8e9dcb54d05f", "type": "github" }, "original": { @@ -51,11 +51,11 @@ }, "nixpkgs": { "locked": { - "lastModified": 1717602782, - "narHash": "sha256-pL9jeus5QpX5R+9rsp3hhZ+uplVHscNJh8n8VpqscM0=", + "lastModified": 1720957393, + "narHash": "sha256-oedh2RwpjEa+TNxhg5Je9Ch6d3W1NKi7DbRO1ziHemA=", "owner": "NixOS", "repo": "nixpkgs", - "rev": "e8057b67ebf307f01bdcc8fba94d94f75039d1f6", + "rev": "693bc46d169f5af9c992095736e82c3488bf7dbb", "type": "github" }, "original": { 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) :