From 029f08805a2297966d295a52a6e62c3801926a52 Mon Sep 17 00:00:00 2001 From: Anthony Ruhier Date: Thu, 29 Feb 2024 17:19:33 +0100 Subject: [PATCH] config: Add a -c|--config flag to set a config path (#25) --- README.md | 11 ++++++++++- src/config/ConfigManager.cpp | 2 +- src/config/ConfigManager.hpp | 2 +- src/main.cpp | 7 ++++++- 4 files changed, 18 insertions(+), 4 deletions(-) diff --git a/README.md b/README.md index a3b7880..c871250 100644 --- a/README.md +++ b/README.md @@ -13,7 +13,7 @@ hyprland syntax. ```ini general { - lock_cmd = notify-send "lock!" # dbus/sysd lock command (loginctl lock-session) + lock_cmd = notify-send "lock!" # dbus/sysd lock command (loginctl lock-session) unlock_cmd = notify-send "unlock!" # same as above, but unlock before_sleep_cmd = notify-send "Zzz" # command ran before sleep after_sleep_cmd = notify-send "Awake!" # command ran after sleep @@ -48,3 +48,12 @@ Installation: ```sh sudo cmake --install build ``` + +## Flags + +``` +-c , --config : specify a config path, by default + set to ${XDG_CONFIG_HOME}/hypr/hypridle.conf +-q, --quiet +-v, --verbose +``` diff --git a/src/config/ConfigManager.cpp b/src/config/ConfigManager.cpp index 1a8d988..65f9403 100644 --- a/src/config/ConfigManager.cpp +++ b/src/config/ConfigManager.cpp @@ -14,7 +14,7 @@ static std::string getMainConfigPath() { return getConfigDir() + "/hypr/hypridle.conf"; } -CConfigManager::CConfigManager() : m_config(getMainConfigPath().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}) { ; } diff --git a/src/config/ConfigManager.hpp b/src/config/ConfigManager.hpp index 6b82960..8557984 100644 --- a/src/config/ConfigManager.hpp +++ b/src/config/ConfigManager.hpp @@ -9,7 +9,7 @@ class CConfigManager { public: - CConfigManager(); + CConfigManager(std::string configPath); void init(); struct STimeoutRule { diff --git a/src/main.cpp b/src/main.cpp index 129c6c5..700c846 100644 --- a/src/main.cpp +++ b/src/main.cpp @@ -3,6 +3,7 @@ #include "core/Hypridle.hpp" int main(int argc, char** argv, char** envp) { + std::string configPath; for (int i = 1; i < argc; ++i) { std::string arg = argv[i]; @@ -12,10 +13,14 @@ int main(int argc, char** argv, char** envp) { else if (arg == "--quiet" || arg == "-q") Debug::quiet = true; + + else if (arg == "--config" || arg == "-c") { + configPath = argv[++i]; + } } try { - g_pConfigManager = std::make_unique(); + g_pConfigManager = std::make_unique(configPath); g_pConfigManager->init(); } catch (const char* err) { Debug::log(CRIT, "ConfigManager threw: {}", err);