diff --git a/src/config/ConfigManager.cpp b/src/config/ConfigManager.cpp index 67df5bf4..bdce573f 100644 --- a/src/config/ConfigManager.cpp +++ b/src/config/ConfigManager.cpp @@ -716,20 +716,24 @@ std::optional CConfigManager::generateConfig(std::string configPath } std::string CConfigManager::getMainConfigPath() { - if (!g_pCompositor->explicitConfigPath.empty()) - return g_pCompositor->explicitConfigPath; + static std::string CONFIG_PATH = [this]() -> std::string { + if (!g_pCompositor->explicitConfigPath.empty()) + return g_pCompositor->explicitConfigPath; - if (const auto CFG_ENV = getenv("HYPRLAND_CONFIG"); CFG_ENV) - return CFG_ENV; + if (const auto CFG_ENV = getenv("HYPRLAND_CONFIG"); CFG_ENV) + return CFG_ENV; - const auto PATHS = Hyprutils::Path::findConfig(ISDEBUG ? "hyprlandd" : "hyprland"); - if (PATHS.first.has_value()) { - return PATHS.first.value(); - } else if (PATHS.second.has_value()) { - const auto CONFIGPATH = Hyprutils::Path::fullConfigPath(PATHS.second.value(), ISDEBUG ? "hyprlandd" : "hyprland"); - return generateConfig(CONFIGPATH).value(); - } else - throw std::runtime_error("Neither HOME nor XDG_CONFIG_HOME are set in the environment. Could not find config in XDG_CONFIG_DIRS or /etc/xdg."); + const auto PATHS = Hyprutils::Path::findConfig(ISDEBUG ? "hyprlandd" : "hyprland"); + if (PATHS.first.has_value()) { + return PATHS.first.value(); + } else if (PATHS.second.has_value()) { + const auto CONFIGPATH = Hyprutils::Path::fullConfigPath(PATHS.second.value(), ISDEBUG ? "hyprlandd" : "hyprland"); + return generateConfig(CONFIGPATH).value(); + } else + throw std::runtime_error("Neither HOME nor XDG_CONFIG_HOME are set in the environment. Could not find config in XDG_CONFIG_DIRS or /etc/xdg."); + }(); + + return CONFIG_PATH; } std::optional CConfigManager::verifyConfigExists() { diff --git a/src/config/ConfigManager.hpp b/src/config/ConfigManager.hpp index b1e7e7fd..0cd0a0a4 100644 --- a/src/config/ConfigManager.hpp +++ b/src/config/ConfigManager.hpp @@ -163,7 +163,7 @@ class CConfigManager { void* const* getConfigValuePtr(const std::string&); Hyprlang::CConfigValue* getHyprlangConfigValuePtr(const std::string& name, const std::string& specialCat = ""); - static std::string getMainConfigPath(); + std::string getMainConfigPath(); std::string getConfigString(); SMonitorRule getMonitorRuleFor(const PHLMONITOR); @@ -300,15 +300,15 @@ class CConfigManager { std::string m_szConfigErrors = ""; // internal methods - void setAnimForChildren(SAnimationPropertyConfig* const); - void updateBlurredLS(const std::string&, const bool); - void setDefaultAnimationVars(); - std::optional resetHLConfig(); - static std::optional generateConfig(std::string configPath); - static std::optional verifyConfigExists(); - void postConfigReload(const Hyprlang::CParseResult& result); - void reload(); - SWorkspaceRule mergeWorkspaceRules(const SWorkspaceRule&, const SWorkspaceRule&); + void setAnimForChildren(SAnimationPropertyConfig* const); + void updateBlurredLS(const std::string&, const bool); + void setDefaultAnimationVars(); + std::optional resetHLConfig(); + std::optional generateConfig(std::string configPath); + std::optional verifyConfigExists(); + void postConfigReload(const Hyprlang::CParseResult& result); + void reload(); + SWorkspaceRule mergeWorkspaceRules(const SWorkspaceRule&, const SWorkspaceRule&); }; inline std::unique_ptr g_pConfigManager;