From fc4e3bd2dccd3b2e816c7cbe2dca25fa5e83a4bd Mon Sep 17 00:00:00 2001 From: Mihai Fufezan Date: Tue, 16 Jul 2024 23:36:07 +0300 Subject: [PATCH] Config: use hyprutils helper (#77) * flake.lock: update * config: use hyprutils helper * Nix: add hyprutils dep flake.lock: update --- CMakeLists.txt | 2 +- flake.lock | 60 ++++++++++++++++++++++-------------- flake.nix | 8 +++++ nix/default.nix | 2 ++ nix/overlays.nix | 1 + src/config/ConfigManager.cpp | 19 +++++------- 6 files changed, 57 insertions(+), 35 deletions(-) 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/flake.lock b/flake.lock index 5a4bc9a..0c9f072 100644 --- a/flake.lock +++ b/flake.lock @@ -2,17 +2,22 @@ "nodes": { "hyprlang": { "inputs": { + "hyprutils": [ + "hyprutils" + ], "nixpkgs": [ "nixpkgs" ], - "systems": "systems" + "systems": [ + "systems" + ] }, "locked": { - "lastModified": 1713121246, - "narHash": "sha256-502X0Q0fhN6tJK7iEUA8CghONKSatW/Mqj4Wappd++0=", + "lastModified": 1720381373, + "narHash": "sha256-lyC/EZdHULsaAKVryK11lgHY9u6pXr7qR4irnxNWC7k=", "owner": "hyprwm", "repo": "hyprlang", - "rev": "78fcaa27ae9e1d782faa3ff06c8ea55ddce63706", + "rev": "5df0174fd09de4ac5475233d65ffc703e89b82eb", "type": "github" }, "original": { @@ -21,13 +26,36 @@ "type": "github" } }, + "hyprutils": { + "inputs": { + "nixpkgs": [ + "nixpkgs" + ], + "systems": [ + "systems" + ] + }, + "locked": { + "lastModified": 1721071737, + "narHash": "sha256-qmC9jGfbE4+EIBbbSAkrfR/p49wShjpv4/KztgE/P54=", + "owner": "hyprwm", + "repo": "hyprutils", + "rev": "eb1ceff2b87f6820789249f63faa8e9dcb54d05f", + "type": "github" + }, + "original": { + "owner": "hyprwm", + "repo": "hyprutils", + "type": "github" + } + }, "nixpkgs": { "locked": { - "lastModified": 1712963716, - "narHash": "sha256-WKm9CvgCldeIVvRz87iOMi8CFVB1apJlkUT4GGvA0iM=", + "lastModified": 1720957393, + "narHash": "sha256-oedh2RwpjEa+TNxhg5Je9Ch6d3W1NKi7DbRO1ziHemA=", "owner": "NixOS", "repo": "nixpkgs", - "rev": "cfd6b5fc90b15709b780a5a1619695a88505a176", + "rev": "693bc46d169f5af9c992095736e82c3488bf7dbb", "type": "github" }, "original": { @@ -40,8 +68,9 @@ "root": { "inputs": { "hyprlang": "hyprlang", + "hyprutils": "hyprutils", "nixpkgs": "nixpkgs", - "systems": "systems_2" + "systems": "systems" } }, "systems": { @@ -58,21 +87,6 @@ "repo": "default-linux", "type": "github" } - }, - "systems_2": { - "locked": { - "lastModified": 1689347949, - "narHash": "sha256-12tWmuL2zgBgZkdoB6qXZsgJEH9LR3oUgpaQq2RbI80=", - "owner": "nix-systems", - "repo": "default-linux", - "rev": "31732fcf5e8fea42e59c2488ad31a0e651500f68", - "type": "github" - }, - "original": { - "owner": "nix-systems", - "repo": "default-linux", - "type": "github" - } } }, "root": "root", diff --git a/flake.nix b/flake.nix index 1f07e96..24364c7 100644 --- a/flake.nix +++ b/flake.nix @@ -8,6 +8,14 @@ hyprlang = { url = "github:hyprwm/hyprlang"; inputs.nixpkgs.follows = "nixpkgs"; + inputs.systems.follows = "systems"; + inputs.hyprutils.follows = "hyprutils"; + }; + + hyprutils = { + url = "github:hyprwm/hyprutils"; + inputs.nixpkgs.follows = "nixpkgs"; + inputs.systems.follows = "systems"; }; }; diff --git a/nix/default.nix b/nix/default.nix index c96914f..4ada676 100644 --- a/nix/default.nix +++ b/nix/default.nix @@ -4,6 +4,7 @@ cmake, pkg-config, hyprlang, + hyprutils, sdbus-cpp, systemd, wayland, @@ -22,6 +23,7 @@ stdenv.mkDerivation { buildInputs = [ hyprlang + hyprutils sdbus-cpp systemd wayland diff --git a/nix/overlays.nix b/nix/overlays.nix index 216345e..5ab3bd5 100644 --- a/nix/overlays.nix +++ b/nix/overlays.nix @@ -12,6 +12,7 @@ in { hypridle = lib.composeManyExtensions [ inputs.hyprlang.overlays.default + inputs.hyprutils.overlays.default (final: prev: { hypridle = prev.callPackage ./default.nix { stdenv = prev.gcc13Stdenv; 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}) { ; }