From 7c3108327ba933a3ea4d4d6fbb353e19b2d0e13f Mon Sep 17 00:00:00 2001 From: "[ ]" <[ ]> Date: Tue, 27 Sep 2022 09:31:25 +0900 Subject: [PATCH 1/2] Add support for --config|-c --- src/Hyprpaper.hpp | 1 + src/config/ConfigManager.cpp | 10 ++++++++-- src/main.cpp | 15 +++++++++++++++ 3 files changed, 24 insertions(+), 2 deletions(-) diff --git a/src/Hyprpaper.hpp b/src/Hyprpaper.hpp index 0dad476..fd563fd 100644 --- a/src/Hyprpaper.hpp +++ b/src/Hyprpaper.hpp @@ -34,6 +34,7 @@ public: std::vector> m_vMonitors; bool m_bIPCEnabled = true; + std::string explicitConfigPath; void removeOldHyprpaperImages(); void preloadAllWallpapersFromConfig(); diff --git a/src/config/ConfigManager.cpp b/src/config/ConfigManager.cpp index 357b625..4d68203 100644 --- a/src/config/ConfigManager.cpp +++ b/src/config/ConfigManager.cpp @@ -4,8 +4,14 @@ CConfigManager::CConfigManager() { // init the entire thing - const char* const ENVHOME = getenv("HOME"); - const std::string CONFIGPATH = ENVHOME + (std::string) "/.config/hypr/hyprpaper.conf"; + std::string CONFIGPATH; + if (g_pHyprpaper->explicitConfigPath == "") { + const char *const ENVHOME = getenv("HOME"); + CONFIGPATH = ENVHOME + (std::string) "/.config/hypr/hyprpaper.conf"; + } + else { + CONFIGPATH = g_pHyprpaper->explicitConfigPath; + } std::ifstream ifs; ifs.open(CONFIGPATH); diff --git a/src/main.cpp b/src/main.cpp index 23b3aac..c60c501 100644 --- a/src/main.cpp +++ b/src/main.cpp @@ -5,8 +5,23 @@ int main(int argc, char** argv, char** envp) { Debug::log(LOG, "Welcome to hyprpaper!\nbuilt from commit %s (%s)", GIT_COMMIT_HASH, GIT_COMMIT_MESSAGE); + // parse some args + std::string configPath; + for (int i = 1; i < argc; ++i) { + if ((!strcmp(argv[i], "-c") || !strcmp(argv[i], "--config")) && argc >= i + 2) { + configPath = std::string(argv[++i]); + Debug::log(LOG, "Using config location %s.", configPath.c_str()); + } else { + std::cout << "Hyprpaper usage: hyprpaper [arg [...]].\n\nArguments:\n" << + "--help -h | Show this help message\n" << + "--config -c | Specify config file to use\n"; + return 1; + } + } + // starts g_pHyprpaper = std::make_unique(); + g_pHyprpaper->explicitConfigPath = configPath; g_pHyprpaper->init(); return 0; From dc46514d7ed3da10f5437160f57a993443ee116a Mon Sep 17 00:00:00 2001 From: "[ ]" <[ ]> Date: Wed, 28 Sep 2022 12:29:33 +0900 Subject: [PATCH 2/2] style: Rename some variables --- src/Hyprpaper.hpp | 2 +- src/config/ConfigManager.cpp | 10 +++++----- src/main.cpp | 2 +- 3 files changed, 7 insertions(+), 7 deletions(-) diff --git a/src/Hyprpaper.hpp b/src/Hyprpaper.hpp index fd563fd..c7bed0a 100644 --- a/src/Hyprpaper.hpp +++ b/src/Hyprpaper.hpp @@ -34,7 +34,7 @@ public: std::vector> m_vMonitors; bool m_bIPCEnabled = true; - std::string explicitConfigPath; + std::string m_szExplicitConfigPath; void removeOldHyprpaperImages(); void preloadAllWallpapersFromConfig(); diff --git a/src/config/ConfigManager.cpp b/src/config/ConfigManager.cpp index 4d68203..c09cba9 100644 --- a/src/config/ConfigManager.cpp +++ b/src/config/ConfigManager.cpp @@ -4,17 +4,17 @@ CConfigManager::CConfigManager() { // init the entire thing - std::string CONFIGPATH; - if (g_pHyprpaper->explicitConfigPath == "") { + std::string configPath; + if (g_pHyprpaper->m_szExplicitConfigPath == "") { const char *const ENVHOME = getenv("HOME"); - CONFIGPATH = ENVHOME + (std::string) "/.config/hypr/hyprpaper.conf"; + configPath = ENVHOME + (std::string) "/.config/hypr/hyprpaper.conf"; } else { - CONFIGPATH = g_pHyprpaper->explicitConfigPath; + configPath = g_pHyprpaper->m_szExplicitConfigPath; } std::ifstream ifs; - ifs.open(CONFIGPATH); + ifs.open(configPath); if (!ifs.good()) { Debug::log(CRIT, "Hyprpaper was not provided a config!"); diff --git a/src/main.cpp b/src/main.cpp index c60c501..a360c4b 100644 --- a/src/main.cpp +++ b/src/main.cpp @@ -21,7 +21,7 @@ int main(int argc, char** argv, char** envp) { // starts g_pHyprpaper = std::make_unique(); - g_pHyprpaper->explicitConfigPath = configPath; + g_pHyprpaper->m_szExplicitConfigPath = configPath; g_pHyprpaper->init(); return 0;