diff options
| author | Mihai Fufezan <mihai@fufexan.net> | 2026-05-08 02:47:47 +0300 |
|---|---|---|
| committer | GitHub <noreply@github.com> | 2026-05-08 00:47:47 +0100 |
| commit | f61ee4c25a97793be3312458fb99e052b76aa4c0 (patch) | |
| tree | c868e2e408439afe4a8633274607ba6216ebd56b /src/config/supplementary/jeremy/Jeremy.cpp | |
| parent | 4c8c45d754c9956d611bbe373b3e33a7d5957d68 (diff) | |
config: find lua paths first (#14335)
* config: find lua paths first
* config/supplementary/jeremy: use designated initializer list
Diffstat (limited to 'src/config/supplementary/jeremy/Jeremy.cpp')
| -rw-r--r-- | src/config/supplementary/jeremy/Jeremy.cpp | 41 |
1 files changed, 14 insertions, 27 deletions
diff --git a/src/config/supplementary/jeremy/Jeremy.cpp b/src/config/supplementary/jeremy/Jeremy.cpp index 67b7b493..b5548181 100644 --- a/src/config/supplementary/jeremy/Jeremy.cpp +++ b/src/config/supplementary/jeremy/Jeremy.cpp @@ -12,41 +12,28 @@ using namespace Config::Supplementary::Jeremy; std::expected<SConfigStateReply, std::string> Jeremy::getMainConfigPath() { static bool lastSafeMode = g_pCompositor->m_safeMode; - static auto regularOrLuaIfAvail = [](std::filesystem::path p) -> std::filesystem::path { - std::error_code ec; - auto p2 = p; - p2.replace_extension(".lua"); - - // if we don't have a .conf file, use lua by default. - if (!std::filesystem::exists(p, ec) || ec) - return p2; - - // if we have a .lua file, use that - if (std::filesystem::exists(p2, ec) && !ec) - return p2; - - // otherwise use .conf - return p; - }; - static auto getCfgPath = []() -> std::expected<SConfigStateReply, std::string> { lastSafeMode = g_pCompositor->m_safeMode; if (g_pCompositor->m_safeMode) - return SConfigStateReply{(std::filesystem::path{g_pCompositor->m_instancePath} / "recoverycfg.conf").string(), CONFIG_TYPE_SPECIAL}; + return SConfigStateReply{.path = (std::filesystem::path{g_pCompositor->m_instancePath} / "recoverycfg.conf").string(), .type = CONFIG_TYPE_SPECIAL}; if (!g_pCompositor->m_explicitConfigPath.empty()) - return SConfigStateReply{g_pCompositor->m_explicitConfigPath, CONFIG_TYPE_EXPLICIT}; + return SConfigStateReply{.path = g_pCompositor->m_explicitConfigPath, .type = CONFIG_TYPE_EXPLICIT}; if (const auto CFG_ENV = getenv("HYPRLAND_CONFIG"); CFG_ENV) - return SConfigStateReply{CFG_ENV, CONFIG_TYPE_EXPLICIT}; - - const auto PATHS = Hyprutils::Path::findConfig(ISDEBUG ? "hyprlandd" : "hyprland"); - if (PATHS.first.has_value()) { - return SConfigStateReply{regularOrLuaIfAvail(PATHS.first.value()), CONFIG_TYPE_REGULAR}; - } else if (PATHS.second.has_value()) { - auto CONFIGPATH = Hyprutils::Path::fullConfigPath(PATHS.second.value(), ISDEBUG ? "hyprlandd" : "hyprland"); - return SConfigStateReply{regularOrLuaIfAvail(CONFIGPATH), CONFIG_TYPE_REGULAR}; + return SConfigStateReply{.path = CFG_ENV, .type = CONFIG_TYPE_EXPLICIT}; + + const auto LUA_PATHS = Hyprutils::Path::findConfig(ISDEBUG ? "hyprlandd" : "hyprland", "lua"); + const auto CONF_PATHS = Hyprutils::Path::findConfig(ISDEBUG ? "hyprlandd" : "hyprland", "conf"); + + if (LUA_PATHS.first.has_value()) + return SConfigStateReply{.path = LUA_PATHS.first.value(), .type = CONFIG_TYPE_REGULAR}; + else if (CONF_PATHS.first.has_value()) + return SConfigStateReply{.path = CONF_PATHS.first.value(), .type = CONFIG_TYPE_REGULAR}; + else if (LUA_PATHS.second.has_value()) { + auto CONFIGPATH = Hyprutils::Path::fullConfigPath(LUA_PATHS.second.value(), ISDEBUG ? "hyprlandd" : "hyprland"); + return SConfigStateReply{.path = CONFIGPATH, .type = CONFIG_TYPE_REGULAR}; } else return std::unexpected("Neither HOME nor XDG_CONFIG_HOME are set in the environment. Could not find config in XDG_CONFIG_DIRS or /etc/xdg."); }; |
