summaryrefslogtreecommitdiff
path: root/src/config/ConfigManager.cpp
diff options
context:
space:
mode:
authorVaxry <43317083+vaxerski@users.noreply.github.com>2026-04-26 15:16:36 +0100
committerGitHub <noreply@github.com>2026-04-26 15:16:36 +0100
commit5ba33f846129f3e6c0505b19f94634b24505e828 (patch)
treeaaacabe678006040c342935481a86607c66607fd /src/config/ConfigManager.cpp
parent329b2b356dd92ac07f4e2aa69cbce82ee9ba9d19 (diff)
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.
Diffstat (limited to 'src/config/ConfigManager.cpp')
-rw-r--r--src/config/ConfigManager.cpp51
1 files changed, 44 insertions, 7 deletions
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 <hyprutils/path/Path.hpp>
@@ -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<Legacy::CConfigManager>();
+ 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<Lua::CConfigManager>();
+ } else {
+ filePath.replace_extension(".conf");
+ Log::logger->log(Log::DEBUG, "[cfg] Lua config not found, using legacy config at {}", filePath.string());
+ g_mgr = makeUnique<Legacy::CConfigManager>();
+ }
+ } 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<Lua::CConfigManager>();
+ } else {
+ Log::logger->log(Log::DEBUG, "[cfg] Config is NOT lua, loading regular mgr");
+ g_mgr = makeUnique<Legacy::CConfigManager>();
+ }
+ }
+
+ 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<IConfigManager>& 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";
+ }
+}