From 13f6f0b923ff3ec94a3bec886c28b90402ceef91 Mon Sep 17 00:00:00 2001 From: Vaxry <43317083+vaxerski@users.noreply.github.com> Date: Sun, 18 Feb 2024 15:00:34 +0000 Subject: Migrate the config to hyprlang (#4656) * Migrate to hyprlang * pop up errors * fix swapped args * Meson & Nix: build with hyprlang * CI: add hyprlang to setup action * add infra for plugin stuff * fix hyprctl getoption * fix hyprctl getoption with json * format * fix post parse logic * fix autogen config * oops missed exec-once * fmt * fix ws rules * require 0.3.0 for hyprlang * nix: flaek * minor type fixes * fix cfg usages in swipe * use cvarlist for ws rules * fix throw in addPluginConfigVar * Nix: update hyprlang * minor fixes * fix disableLogs * mention hyprlang docs * bump hyprlang dep in cmake * Meson: bump min hyprlang version Nix: update hyprlang * minor fix * Nix: update meson patch --------- Co-authored-by: Mihai Fufezan --- src/debug/HyprCtl.cpp | 55 ++++++++++++++++++++++++++++++++------------------- 1 file changed, 35 insertions(+), 20 deletions(-) (limited to 'src/debug/HyprCtl.cpp') diff --git a/src/debug/HyprCtl.cpp b/src/debug/HyprCtl.cpp index e805bca6..b0f70e98 100644 --- a/src/debug/HyprCtl.cpp +++ b/src/debug/HyprCtl.cpp @@ -14,6 +14,7 @@ #include #include +#include static void trimTrailingComma(std::string& str) { if (!str.empty() && str.back() == ',') @@ -856,7 +857,7 @@ std::string dispatchKeyword(eHyprCtlOutputFormat format, std::string in) { const auto VALUE = in.substr(in.find_first_of(' ') + 1); - std::string retval = g_pConfigManager->parseKeyword(COMMAND, VALUE, true); + std::string retval = g_pConfigManager->parseKeyword(COMMAND, VALUE); if (COMMAND == "monitor") g_pConfigManager->m_bWantsMonitorReload = true; // for monitor keywords @@ -868,8 +869,10 @@ std::string dispatchKeyword(eHyprCtlOutputFormat format, std::string in) { g_pInputManager->setTabletConfigs(); // update tablets } + static auto* const PLAYOUT = (Hyprlang::STRING const*)g_pConfigManager->getConfigValuePtr("general:layout"); + if (COMMAND.contains("general:layout")) - g_pLayoutManager->switchToLayout(g_pConfigManager->getString("general:layout")); // update layout + g_pLayoutManager->switchToLayout(*PLAYOUT); // update layout if (COMMAND.contains("decoration:screen_shader")) g_pHyprOpenGL->m_bReloadScreenShader = true; @@ -1193,28 +1196,40 @@ std::string dispatchGetOption(eHyprCtlOutputFormat format, std::string request) nextItem(); nextItem(); - const auto PCFGOPT = g_pConfigManager->getConfigValuePtrSafe(curitem); + const auto VAR = g_pConfigManager->getHyprlangConfigValuePtr(curitem); - if (!PCFGOPT) + if (!VAR) return "no such option"; - if (format == eHyprCtlOutputFormat::FORMAT_NORMAL) - return std::format("option {}\n\tint: {}\n\tfloat: {:.5f}\n\tstr: \"{}\"\n\tdata: {:x}\n\tset: {}", curitem, PCFGOPT->intValue, PCFGOPT->floatValue, PCFGOPT->strValue, - (uintptr_t)PCFGOPT->data.get(), PCFGOPT->set); - else { - return std::format( - R"#( -{{ - "option": "{}", - "int": {}, - "float": {:.5f}, - "str": "{}", - "data": "0x{:x}", - "set": {} -}} -)#", - curitem, PCFGOPT->intValue, PCFGOPT->floatValue, PCFGOPT->strValue, (uintptr_t)PCFGOPT->data.get(), PCFGOPT->set); + const auto VAL = VAR->getValue(); + const auto TYPE = std::type_index(VAL.type()); + + if (format == FORMAT_NORMAL) { + if (TYPE == typeid(Hyprlang::INT)) + return std::format("int: {}\nset: {}", std::any_cast(VAL), VAR->m_bSetByUser); + else if (TYPE == typeid(Hyprlang::FLOAT)) + return std::format("float: {:2f}\nset: {}", std::any_cast(VAL), VAR->m_bSetByUser); + else if (TYPE == typeid(Hyprlang::VEC2)) + return std::format("vec2: [{}, {}]\nset: {}", std::any_cast(VAL).x, std::any_cast(VAL).y, VAR->m_bSetByUser); + else if (TYPE == typeid(Hyprlang::STRING)) + return std::format("str: {}\nset: {}", std::any_cast(VAL), VAR->m_bSetByUser); + else if (TYPE == typeid(Hyprlang::CUSTOMTYPE*)) + return std::format("custom type at: {:x}\nset: {}", (uintptr_t)std::any_cast(VAL), VAR->m_bSetByUser); + } else { + if (TYPE == typeid(Hyprlang::INT)) + return std::format("{{\"option\": \"{}\", \"int\": {}, \"set\": {} }}", curitem, std::any_cast(VAL), VAR->m_bSetByUser); + else if (TYPE == typeid(Hyprlang::FLOAT)) + return std::format("{{\"option\": \"{}\", \"float\": {:2f}, \"set\": {} }}", curitem, std::any_cast(VAL), VAR->m_bSetByUser); + else if (TYPE == typeid(Hyprlang::VEC2)) + return std::format("{{\"option\": \"{}\", \"vec2\": [{},{}], \"set\": {} }}", curitem, std::any_cast(VAL).x, std::any_cast(VAL).y, + VAR->m_bSetByUser); + else if (TYPE == typeid(Hyprlang::STRING)) + return std::format("{{\"option\": \"{}\", \"str\": \"{}\", \"set\": {} }}", curitem, escapeJSONStrings(std::any_cast(VAL)), VAR->m_bSetByUser); + else if (TYPE == typeid(Hyprlang::CUSTOMTYPE*)) + return std::format("{{\"option\": \"{}\", \"custom\": \"{:x}\", \"set\": {} }}", curitem, (uintptr_t)std::any_cast(VAL), VAR->m_bSetByUser); } + + return "invalid type (internal error)"; } std::string decorationRequest(eHyprCtlOutputFormat format, std::string request) { -- cgit v1.2.3