Skip to content

Commit

Permalink
Config: use hyprutils helper (#77)
Browse files Browse the repository at this point in the history
* flake.lock: update

* config: use hyprutils helper

* Nix: add hyprutils dep

flake.lock: update
  • Loading branch information
fufexan authored Jul 16, 2024
1 parent 7c5747b commit fc4e3bd
Show file tree
Hide file tree
Showing 6 changed files with 57 additions and 35 deletions.
2 changes: 1 addition & 1 deletion CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -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})
Expand Down
60 changes: 37 additions & 23 deletions flake.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

8 changes: 8 additions & 0 deletions flake.nix
Original file line number Diff line number Diff line change
Expand Up @@ -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";
};
};

Expand Down
2 changes: 2 additions & 0 deletions nix/default.nix
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
cmake,
pkg-config,
hyprlang,
hyprutils,
sdbus-cpp,
systemd,
wayland,
Expand All @@ -22,6 +23,7 @@ stdenv.mkDerivation {

buildInputs = [
hyprlang
hyprutils
sdbus-cpp
systemd
wayland
Expand Down
1 change: 1 addition & 0 deletions nix/overlays.nix
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down
19 changes: 8 additions & 11 deletions src/config/ConfigManager.cpp
Original file line number Diff line number Diff line change
@@ -1,20 +1,17 @@
#include "ConfigManager.hpp"
#include <hyprutils/path/Path.hpp>
#include <filesystem>

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}) {
;
}

Expand Down

0 comments on commit fc4e3bd

Please sign in to comment.