diff options
| author | vaxerski <vaxry@vaxry.net> | 2025-01-02 18:29:10 +0100 |
|---|---|---|
| committer | vaxerski <vaxry@vaxry.net> | 2025-01-02 18:29:10 +0100 |
| commit | 4971725b69768d156047289b7606e470c6963f59 (patch) | |
| tree | 47b5fa8eb20b94d52909e52df7cb75eaf9f71f6e /src/config/ConfigManager.cpp | |
| parent | 1697171fc003d26dace4a7d70e2f8038df60a196 (diff) | |
config: avoid querying the fs every tick
Diffstat (limited to 'src/config/ConfigManager.cpp')
| -rw-r--r-- | src/config/ConfigManager.cpp | 32 |
1 files changed, 18 insertions, 14 deletions
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<std::string> CConfigManager::generateConfig(std::string configPath } std::string CConfigManager::getMainConfigPath() { - if (!g_pCompositor->explicitConfigPath.empty()) - return g_pCompositor->explicitConfigPath; - - 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."); + 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; + + 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<std::string> CConfigManager::verifyConfigExists() { |
