diff --git a/hyprtester/src/tests/main/hyprctl.cpp b/hyprtester/src/tests/main/hyprctl.cpp index df86af592..25ed8014e 100644 --- a/hyprtester/src/tests/main/hyprctl.cpp +++ b/hyprtester/src/tests/main/hyprctl.cpp @@ -14,7 +14,21 @@ using namespace Hyprutils::Memory; #define UP CUniquePointer #define SP CSharedPointer -static std::string getCommandStdOut(std::string command) { +static constexpr auto CONFIGURED_DESCRIPTION_VALUES = R"( + def matches($name; $default; $current): + ([.[] | select(.name == $name)] | + length == 1 and + .[0].default == $default and + .[0].current == $current); + + matches("general:border_size"; 1; 2) and + matches("general:snap:enabled"; false; true) and + matches("decoration:rounding"; 0; 10) and + matches("master:new_status"; "slave"; "master") and + matches("scrolling:follow_min_visible"; 0.4; 1) +)"; + +static std::string getCommandStdOut(std::string command) { CProcess process("bash", {"-c", command}); process.addEnv("HYPRLAND_INSTANCE_SIGNATURE", HIS); process.runSync(); @@ -25,6 +39,13 @@ static std::string getCommandStdOut(std::string command) { return stdOut.substr(0, stdOut.length() - 1); } +static bool descriptionsMatch(const std::string& filter) { + CProcess jqProc("bash", {"-c", std::format("hyprctl descriptions | jq -e '{}'", filter)}); + jqProc.addEnv("HYPRLAND_INSTANCE_SIGNATURE", HIS); + jqProc.runSync(); + return jqProc.exitCode() == 0; +} + static void setWindowProp(const std::string& selector, const std::string& prop, const std::string& value) { getFromSocket(std::format("/dispatch hl.dsp.window.set_prop({{ window = '{}', prop = '{}', value = '{}' }})", selector, prop, value)); } @@ -160,10 +181,31 @@ TEST_CASE(hyprctlSubmap) { } TEST_CASE(hyprctlJsonErrors) { - CProcess jqProc("bash", {"-c", "hyprctl descriptions | jq"}); - jqProc.addEnv("HYPRLAND_INSTANCE_SIGNATURE", HIS); - jqProc.runSync(); - EXPECT(jqProc.exitCode(), 0); + EXPECT(descriptionsMatch(R"(type == "array")"), true); +} + +TEST_CASE(hyprctlDescriptionsCurrentValues) { + EXPECT(descriptionsMatch(CONFIGURED_DESCRIPTION_VALUES), true); + + OK(getFromSocket( + "/eval hl.config({ general = { border_size = 7, snap = { enabled = false } }, master = { new_status = 'inherit' }, scrolling = { follow_min_visible = 0.625 } })")); + + EXPECT(descriptionsMatch(R"( + def matches($name; $default; $current): + ([.[] | select(.name == $name)] | + length == 1 and + .[0].default == $default and + .[0].current == $current); + + matches("general:border_size"; 1; 7) and + matches("general:snap:enabled"; false; false) and + matches("master:new_status"; "slave"; "inherit") and + matches("scrolling:follow_min_visible"; 0.4; 0.625) + )"), + true); + + OK(getFromSocket("/reload")); + EXPECT(descriptionsMatch(CONFIGURED_DESCRIPTION_VALUES), true); } TEST_CASE(hyprctlBindsJson) { diff --git a/src/config/ConfigManager.cpp b/src/config/ConfigManager.cpp index b1b4200ca..8a43154ed 100644 --- a/src/config/ConfigManager.cpp +++ b/src/config/ConfigManager.cpp @@ -2,6 +2,7 @@ #include "supplementary/jeremy/Jeremy.hpp" #include "lua/ConfigManager.hpp" #include "../debug/log/Logger.hpp" +#include "values/ConfigValues.hpp" #include #include @@ -49,6 +50,10 @@ bool Config::initConfigManager() { } } + for (const auto& v : Values::CONFIG_VALUES) { + v->commence(); + } + return true; } @@ -61,4 +66,4 @@ const char* Config::typeToString(eConfigManagerType t) { case CONFIG_LUA: return "lua"; default: return "error"; } -} \ No newline at end of file +} diff --git a/src/config/lua/ConfigManager.cpp b/src/config/lua/ConfigManager.cpp index fd90bff81..6382f4073 100644 --- a/src/config/lua/ConfigManager.cpp +++ b/src/config/lua/ConfigManager.cpp @@ -410,7 +410,7 @@ CConfigManager::SDeviceConfig::SDeviceConfig() { CConfigManager::CConfigManager() : m_mainConfigPath(Supplementary::Jeremy::getMainConfigPath()->path) { for (const auto& v : Values::CONFIG_VALUES) { - m_configValues.emplace(luaConfigValueName(v->name()), fromGenericValue(v)); + registerValue(luaConfigValueName(v->name()).c_str(), fromGenericValue(v)); } m_configValues["autogenerated"] = fromGenericValue(makeShared("autogenerated", "whether the config is autogenerated or not", 0)); @@ -495,8 +495,8 @@ eConfigManagerType CConfigManager::type() { return CONFIG_LUA; } -void CConfigManager::registerValue(const char* name, ILuaConfigValue* val) { - m_configValues.emplace(name, UP(val)); +void CConfigManager::registerValue(const char* name, UP&& val) { + m_configValues.emplace(name, std::move(val)); } void CConfigManager::cleanTimers() { diff --git a/src/config/lua/ConfigManager.hpp b/src/config/lua/ConfigManager.hpp index 9bf847877..1ed1e4b86 100644 --- a/src/config/lua/ConfigManager.hpp +++ b/src/config/lua/ConfigManager.hpp @@ -157,7 +157,7 @@ namespace Config::Lua { private: void reinitLuaState(); void postConfigReload(); - void registerValue(const char* name, ILuaConfigValue* val); + void registerValue(const char* name, UP&& val); void cleanTimers(); void clearLuaLayoutProviders(); void clearHeldLuaRefs();