From 01fc3d6068f80c60e4113f14e375070e38329641 Mon Sep 17 00:00:00 2001 From: Mihai Fufezan Date: Thu, 14 Jul 2022 23:55:24 +0300 Subject: add config flag you can now specify a config with -c --- src/config/ConfigManager.cpp | 46 +++++++++++++++++++++++++++++--------------- 1 file changed, 31 insertions(+), 15 deletions(-) (limited to 'src/config/ConfigManager.cpp') diff --git a/src/config/ConfigManager.cpp b/src/config/ConfigManager.cpp index f01f9b40..ba73b777 100644 --- a/src/config/ConfigManager.cpp +++ b/src/config/ConfigManager.cpp @@ -12,8 +12,15 @@ CConfigManager::CConfigManager() { setDefaultVars(); - static const char* const ENVHOME = getenv("HOME"); - const std::string CONFIGPATH = ENVHOME + (ISDEBUG ? (std::string) "/.config/hypr/hyprlandd.conf" : (std::string) "/.config/hypr/hyprland.conf"); + + std::string CONFIGPATH; + if (g_pCompositor->explicitConfigPath == "") { + static const char* const ENVHOME = getenv("HOME"); + CONFIGPATH = ENVHOME + (ISDEBUG ? (std::string) "/.config/hypr/hyprlandd.conf" : (std::string) "/.config/hypr/hyprland.conf"); + } else { + CONFIGPATH = g_pCompositor->explicitConfigPath; + } + configPaths.emplace_back(CONFIGPATH); Debug::disableLogs = &configValues["debug:disable_logs"].intValue; @@ -801,28 +808,37 @@ void CConfigManager::loadConfigLoadVars() { // paths configPaths.clear(); + std::string CONFIGPATH; + static const char* const ENVHOME = getenv("HOME"); const std::string CONFIGPARENTPATH = ENVHOME + (std::string) "/.config/hypr/"; - const std::string CONFIGPATH = CONFIGPARENTPATH + (ISDEBUG ? "hyprlandd.conf" : "hyprland.conf"); - configPaths.push_back(CONFIGPATH); + if (g_pCompositor->explicitConfigPath == "") { + CONFIGPATH = CONFIGPARENTPATH + (ISDEBUG ? "hyprlandd.conf" : "hyprland.conf"); + } else { + CONFIGPATH = g_pCompositor->explicitConfigPath; + } + configPaths.push_back(CONFIGPATH); + std::ifstream ifs; ifs.open(CONFIGPATH); if (!ifs.good()) { - Debug::log(WARN, "Config reading error. (No file? Attempting to generate, backing up old one if exists)"); - try { - std::filesystem::rename(CONFIGPATH, CONFIGPATH + ".backup"); - } catch(...) { /* Probably doesn't exist */} + if(g_pCompositor->explicitConfigPath == "") { + Debug::log(WARN, "Config reading error. (No file? Attempting to generate, backing up old one if exists)"); + try { + std::filesystem::rename(CONFIGPATH, CONFIGPATH + ".backup"); + } catch(...) { /* Probably doesn't exist */} - try { - if (!std::filesystem::is_directory(CONFIGPARENTPATH)) - std::filesystem::create_directories(CONFIGPARENTPATH); - } - catch (...) { - parseError = "Broken config file! (Could not create directory)"; - return; + try { + if (!std::filesystem::is_directory(CONFIGPARENTPATH)) + std::filesystem::create_directories(CONFIGPARENTPATH); + } + catch (...) { + parseError = "Broken config file! (Could not create directory)"; + return; + } } std::ofstream ofs; -- cgit v1.2.3