From 5ba33f846129f3e6c0505b19f94634b24505e828 Mon Sep 17 00:00:00 2001 From: Vaxry <43317083+vaxerski@users.noreply.github.com> Date: Sun, 26 Apr 2026 15:16:36 +0100 Subject: config/lua: init lua config manager, use lua if available (#13817) Adds a new lua config manager, which will automatically be used if there is a lua config present. --- src/config/ConfigManager.cpp | 51 ++++++++++++++++++++++++++++++++++++++------ 1 file changed, 44 insertions(+), 7 deletions(-) (limited to 'src/config/ConfigManager.cpp') diff --git a/src/config/ConfigManager.cpp b/src/config/ConfigManager.cpp index 5238f9dd..aaad6dc9 100644 --- a/src/config/ConfigManager.cpp +++ b/src/config/ConfigManager.cpp @@ -1,6 +1,7 @@ #include "ConfigManager.hpp" #include "supplementary/jeremy/Jeremy.hpp" #include "legacy/ConfigManager.hpp" +#include "lua/ConfigManager.hpp" #include "../debug/log/Logger.hpp" #include @@ -19,21 +20,49 @@ bool Config::initConfigManager() { const auto CFG_PATH = Supplementary::Jeremy::getMainConfigPath(); if (!CFG_PATH) { - Log::logger->log(Log::CRIT, "Couldn't load config: {}", CFG_PATH.error()); + Log::logger->log(Log::CRIT, "[cfg] Couldn't load config: {}", CFG_PATH.error()); return false; } - std::filesystem::path filePath = *CFG_PATH; + std::filesystem::path filePath = CFG_PATH->path; - // TODO: - // filePath.replace_extension(".lua"); + if (CFG_PATH->type == Supplementary::Jeremy::CONFIG_TYPE_REGULAR) { + Log::logger->log(Log::DEBUG, "[cfg] Regular config at {}", filePath.string()); - g_mgr = makeUnique(); + std::error_code ec; + if (std::filesystem::exists(filePath, ec) && !ec && filePath.extension() == ".lua") { + // we have lua! + Log::logger->log(Log::DEBUG, "[cfg] Using lua config found at {}", filePath.string()); + g_mgr = makeUnique(); + } else { + filePath.replace_extension(".conf"); + Log::logger->log(Log::DEBUG, "[cfg] Lua config not found, using legacy config at {}", filePath.string()); + g_mgr = makeUnique(); + } + } else { + Log::logger->log(Log::DEBUG, "[cfg] Config is either explicit or special."); + + if (filePath.extension() == ".lua" || filePath.extension() == "lua") { + Log::logger->log(Log::DEBUG, "[cfg] Config is lua, loading lua mgr"); + g_mgr = makeUnique(); + } else { + Log::logger->log(Log::DEBUG, "[cfg] Config is NOT lua, loading regular mgr"); + g_mgr = makeUnique(); + } + } + + RASSERT(g_mgr, "failed to create a suitable config manager"); std::error_code ec; if (!std::filesystem::exists(filePath, ec) || ec) { if (ec) { - Log::logger->log(Log::CRIT, "Couldn't load config: {}", ec.message()); + Log::logger->log(Log::CRIT, "[cfg] Couldn't load config: {}", ec.message()); + return false; + } + + // generate default + if (const auto v = g_mgr->generateDefaultConfig(filePath); !v) { + Log::logger->log(Log::CRIT, "[cfg] Couldn't generate default config: {}", v.error()); return false; } } @@ -43,4 +72,12 @@ bool Config::initConfigManager() { UP& Config::mgr() { return g_mgr; -} \ No newline at end of file +} + +const char* Config::typeToString(eConfigManagerType t) { + switch (t) { + case CONFIG_LUA: return "lua"; + case CONFIG_LEGACY: return "hyprlang"; + default: return "error"; + } +} -- cgit v1.2.3