config: find lua paths first (#14335)

* config: find lua paths first

* config/supplementary/jeremy: use designated initializer list
This commit is contained in:
Mihai Fufezan 2026-05-08 02:47:47 +03:00 committed by GitHub
parent 4c8c45d754
commit f61ee4c25a
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
2 changed files with 16 additions and 29 deletions

6
flake.lock generated
View file

@ -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": {

View file

@ -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};
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.");
};