Skip to content

Commit

Permalink
Add a -c|--config flag to set a config path
Browse files Browse the repository at this point in the history
  • Loading branch information
aruhier committed Feb 29, 2024
1 parent 6ea4e04 commit 9df4529
Show file tree
Hide file tree
Showing 4 changed files with 22 additions and 5 deletions.
11 changes: 10 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -48,3 +48,12 @@ Installation:
```sh
sudo cmake --install build
```

## Flags

```
-c <config_path>, --config <config_path>: specify a config path, by default
set to ${XDG_CONFIG_HOME}/hypr/hypridle.conf
-q, --quiet
-v, --verbose
```
4 changes: 2 additions & 2 deletions src/config/ConfigManager.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -10,11 +10,11 @@ static std::string getConfigDir() {
return getenv("HOME") + std::string("/.config");
}

static std::string getMainConfigPath() {
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 config_path) : m_config(config_path.c_str(), Hyprlang::SConfigOptions{.throwAllErrors = true, .allowMissingConfig = false}) {
;
}

Expand Down
4 changes: 3 additions & 1 deletion src/config/ConfigManager.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -7,9 +7,11 @@
#include <vector>
#include <memory>

std::string getMainConfigPath();

class CConfigManager {
public:
CConfigManager();
CConfigManager(std::string config_path);
void init();

struct STimeoutRule {
Expand Down
8 changes: 7 additions & 1 deletion src/main.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
#include "core/Hypridle.hpp"

int main(int argc, char** argv, char** envp) {
std::string config_path = getMainConfigPath();

for (int i = 1; i < argc; ++i) {
std::string arg = argv[i];
Expand All @@ -12,10 +13,15 @@ int main(int argc, char** argv, char** envp) {

else if (arg == "--quiet" || arg == "-q")
Debug::quiet = true;

else if (arg == "--config" || arg == "-c") {
config_path = argv[i + 1];
i++;
}
}

try {
g_pConfigManager = std::make_unique<CConfigManager>();
g_pConfigManager = std::make_unique<CConfigManager>(config_path);
g_pConfigManager->init();
} catch (const char* err) {
Debug::log(CRIT, "ConfigManager threw: {}", err);
Expand Down

0 comments on commit 9df4529

Please sign in to comment.