From 4fab2afced44e745d5af85184fd9c3997af2374a Mon Sep 17 00:00:00 2001 From: Vaxry Date: Thu, 7 May 2026 00:39:04 +0100 Subject: config: use lua by default, generate lua if no config present --- src/config/ConfigManager.cpp | 4 ++-- src/config/legacy/ConfigManager.cpp | 5 ++--- src/config/legacy/DefaultConfig.hpp | 27 ++++++++++++++++----------- src/config/lua/ConfigManager.cpp | 6 +++--- src/config/lua/DefaultConfig.hpp | 6 +++--- src/config/supplementary/jeremy/Jeremy.cpp | 8 ++++++++ 6 files changed, 34 insertions(+), 22 deletions(-) diff --git a/src/config/ConfigManager.cpp b/src/config/ConfigManager.cpp index aaad6dc9..297e9c04 100644 --- a/src/config/ConfigManager.cpp +++ b/src/config/ConfigManager.cpp @@ -30,7 +30,7 @@ bool Config::initConfigManager() { Log::logger->log(Log::DEBUG, "[cfg] Regular config at {}", filePath.string()); std::error_code ec; - if (std::filesystem::exists(filePath, ec) && !ec && filePath.extension() == ".lua") { + if (filePath.extension() == ".lua") { // we have lua! Log::logger->log(Log::DEBUG, "[cfg] Using lua config found at {}", filePath.string()); g_mgr = makeUnique(); @@ -42,7 +42,7 @@ bool Config::initConfigManager() { } else { Log::logger->log(Log::DEBUG, "[cfg] Config is either explicit or special."); - if (filePath.extension() == ".lua" || filePath.extension() == "lua") { + if (filePath.extension() == ".lua") { Log::logger->log(Log::DEBUG, "[cfg] Config is lua, loading lua mgr"); g_mgr = makeUnique(); } else { diff --git a/src/config/legacy/ConfigManager.cpp b/src/config/legacy/ConfigManager.cpp index 04d76260..08bfe086 100644 --- a/src/config/legacy/ConfigManager.cpp +++ b/src/config/legacy/ConfigManager.cpp @@ -2096,10 +2096,9 @@ std::expected CConfigManager::generateDefaultConfig(const std if (!ofs.good()) return std::unexpected("Config could not be generated."); - if (!safeMode) { - ofs << AUTOGENERATED_PREFIX; + if (!safeMode) ofs << EXAMPLE_CONFIG; - } else { + else { std::string n = std::string{EXAMPLE_CONFIG}; replaceInString(n, "\n$menu = hyprlauncher\n", "\n$menu = hyprland-run\n"); ofs << n; diff --git a/src/config/legacy/DefaultConfig.hpp b/src/config/legacy/DefaultConfig.hpp index dea4ec51..284a7b48 100644 --- a/src/config/legacy/DefaultConfig.hpp +++ b/src/config/legacy/DefaultConfig.hpp @@ -2,17 +2,22 @@ #include -inline constexpr std::string_view AUTOGENERATED_PREFIX = R"#( -# ####################################################################################### -# AUTOGENERATED HYPRLAND CONFIG. -# EDIT THIS CONFIG ACCORDING TO THE WIKI INSTRUCTIONS. -# ####################################################################################### +inline constexpr std::string_view EXAMPLE_CONFIG = R"#( -autogenerated = 1 # remove this line to remove the warning +# This config is a STUB! This should never be generated. +# Use the default lua config from https://github.com/hyprwm/Hyprland/blob/main/example/hyprland.lua -)#"; -inline constexpr char EXAMPLE_CONFIG_BYTES[] = { -#embed "../../../example/hyprland.conf" -}; +autogenerated = 1 + +$mainMod = SUPER +$terminal = kitty +$fileManager = dolphin +$menu = hyprlauncher -inline constexpr std::string_view EXAMPLE_CONFIG = {EXAMPLE_CONFIG_BYTES, sizeof(EXAMPLE_CONFIG_BYTES)}; +bind = $mainMod, Q, exec, $terminal +bind = $mainMod, C, killactive, +bind = $mainMod, M, exec, command -v hyprshutdown >/dev/null 2>&1 && hyprshutdown || hyprctl dispatch exit +bind = $mainMod, E, exec, $fileManager +bind = $mainMod, V, togglefloating, +bind = $mainMod, R, exec, $menu +)#"; diff --git a/src/config/lua/ConfigManager.cpp b/src/config/lua/ConfigManager.cpp index 0f0c1030..8b90b4be 100644 --- a/src/config/lua/ConfigManager.cpp +++ b/src/config/lua/ConfigManager.cpp @@ -805,10 +805,10 @@ std::expected CConfigManager::generateDefaultConfig(const std return std::unexpected("Config could not be generated."); if (!safeMode) { - ofs << AUTOGENERATED_PREFIX; - ofs << EXAMPLE_CONFIG; + ofs << AUTOGENERATED_PREFIX_LUA; + ofs << EXAMPLE_CONFIG_LUA; } else { - std::string n = std::string{EXAMPLE_CONFIG}; + std::string n = std::string{EXAMPLE_CONFIG_LUA}; replaceInString(n, "\nlocal menu = \"hyprlauncher\"\n", "\nlocal menu = \"hyprland-run\"\n"); ofs << n; } diff --git a/src/config/lua/DefaultConfig.hpp b/src/config/lua/DefaultConfig.hpp index 6fe92679..8911a8cb 100644 --- a/src/config/lua/DefaultConfig.hpp +++ b/src/config/lua/DefaultConfig.hpp @@ -2,7 +2,7 @@ #include -inline constexpr std::string_view AUTOGENERATED_PREFIX = R"#( +inline constexpr std::string_view AUTOGENERATED_PREFIX_LUA = R"#( -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- AUTOGENERATED HYPRLAND CONFIG. -- -- EDIT THIS CONFIG ACCORDING TO THE WIKI INSTRUCTIONS. -- @@ -11,8 +11,8 @@ inline constexpr std::string_view AUTOGENERATED_PREFIX = R"#( hl.config({ autogenerated = true }) -- remove this line to remove the warning )#"; -inline constexpr char EXAMPLE_CONFIG_BYTES[] = { +inline constexpr char EXAMPLE_CONFIG_BYTES_LUA[] = { #embed "../../../example/hyprland.lua" }; -inline constexpr std::string_view EXAMPLE_CONFIG = {EXAMPLE_CONFIG_BYTES, sizeof(EXAMPLE_CONFIG_BYTES)}; +inline constexpr std::string_view EXAMPLE_CONFIG_LUA = {EXAMPLE_CONFIG_BYTES_LUA, sizeof(EXAMPLE_CONFIG_BYTES_LUA)}; diff --git a/src/config/supplementary/jeremy/Jeremy.cpp b/src/config/supplementary/jeremy/Jeremy.cpp index e8be2914..67b7b493 100644 --- a/src/config/supplementary/jeremy/Jeremy.cpp +++ b/src/config/supplementary/jeremy/Jeremy.cpp @@ -16,8 +16,16 @@ std::expected Jeremy::getMainConfigPath() { 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; }; -- cgit v1.2.3