Skip to content

Commit

Permalink
config: avoid querying the fs every tick
Browse files Browse the repository at this point in the history
  • Loading branch information
vaxerski committed Jan 2, 2025
1 parent 1697171 commit 4971725
Show file tree
Hide file tree
Showing 2 changed files with 28 additions and 24 deletions.
32 changes: 18 additions & 14 deletions src/config/ConfigManager.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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() {
Expand Down
20 changes: 10 additions & 10 deletions src/config/ConfigManager.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down Expand Up @@ -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<std::string> resetHLConfig();
static std::optional<std::string> generateConfig(std::string configPath);
static std::optional<std::string> 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<std::string> resetHLConfig();
std::optional<std::string> generateConfig(std::string configPath);
std::optional<std::string> verifyConfigExists();
void postConfigReload(const Hyprlang::CParseResult& result);
void reload();
SWorkspaceRule mergeWorkspaceRules(const SWorkspaceRule&, const SWorkspaceRule&);
};

inline std::unique_ptr<CConfigManager> g_pConfigManager;

0 comments on commit 4971725

Please sign in to comment.