From f61ee4c25a97793be3312458fb99e052b76aa4c0 Mon Sep 17 00:00:00 2001 From: Mihai Fufezan Date: Fri, 8 May 2026 02:47:47 +0300 Subject: [PATCH] config: find lua paths first (#14335) * config: find lua paths first * config/supplementary/jeremy: use designated initializer list --- flake.lock | 6 ++-- src/config/supplementary/jeremy/Jeremy.cpp | 39 ++++++++-------------- 2 files changed, 16 insertions(+), 29 deletions(-) diff --git a/flake.lock b/flake.lock index 3330ff67e..a5ec42eb2 100644 --- a/flake.lock +++ b/flake.lock @@ -261,11 +261,11 @@ ] }, "locked": { - "lastModified": 1777492286, - "narHash": "sha256-PwuoEJQcjSKJNP5T55qhfDwIP0tw5zxEhfu8GDfKfeg=", + "lastModified": 1778179779, + "narHash": "sha256-Ri6rVf54CRD3aISHLhSY6H4tBScVjm9ebkv7rF2lcZM=", "owner": "hyprwm", "repo": "hyprutils", - "rev": "ec5c0c709706bad5b82f667fd8758eae442577ce", + "rev": "3e170e5ad010602671f5f25b327e8bdb8fdd532c", "type": "github" }, "original": { diff --git a/src/config/supplementary/jeremy/Jeremy.cpp b/src/config/supplementary/jeremy/Jeremy.cpp index 67b7b4937..b55481815 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 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 { 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}; + return SConfigStateReply{.path = CFG_ENV, .type = 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}; + 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."); };