diff options
| author | vaxerski <vaxry@vaxry.net> | 2022-08-11 21:16:38 +0200 |
|---|---|---|
| committer | vaxerski <vaxry@vaxry.net> | 2022-08-11 21:16:38 +0200 |
| commit | 91024716103128ec74cf9a1da97889c74a676a3e (patch) | |
| tree | c04c80b5eb4bc19bfbad10021eb450129062d6bf /src/debug/HyprCtl.cpp | |
| parent | f85c7656342d2b9d515e364de5dff4662ec6865d (diff) | |
added hyprctl getoption
Diffstat (limited to 'src/debug/HyprCtl.cpp')
| -rw-r--r-- | src/debug/HyprCtl.cpp | 43 |
1 files changed, 43 insertions, 0 deletions
diff --git a/src/debug/HyprCtl.cpp b/src/debug/HyprCtl.cpp index 3042be2e..e09e4f8b 100644 --- a/src/debug/HyprCtl.cpp +++ b/src/debug/HyprCtl.cpp @@ -572,6 +572,47 @@ std::string dispatchSetCursor(std::string request) { return "ok"; } +std::string dispatchGetOption(std::string request, HyprCtl::eHyprCtlOutputFormat format) { + std::string curitem = ""; + + auto nextItem = [&]() { + auto idx = request.find_first_of(' '); + + if (idx != std::string::npos) { + curitem = request.substr(0, idx); + request = request.substr(idx + 1); + } else { + curitem = request; + request = ""; + } + + curitem = removeBeginEndSpacesTabs(curitem); + }; + + nextItem(); + nextItem(); + + const auto PCFGOPT = g_pConfigManager->getConfigValuePtrSafe(curitem); + + if (!PCFGOPT) + return "no such option"; + + if (format == HyprCtl::eHyprCtlOutputFormat::FORMAT_NORMAL) + return getFormat("option %s\n\tint: %i\n\tfloat: %f\n\tstr: \"%s\"", curitem.c_str(), PCFGOPT->intValue, PCFGOPT->floatValue, PCFGOPT->strValue.c_str()); + else { + return getFormat( +R"#( +{ + "option": "%s", + "int": %i, + "float": %f, + "str": "%s" +} +)#", curitem.c_str(), PCFGOPT->intValue, PCFGOPT->floatValue, PCFGOPT->strValue.c_str() + ); + } +} + std::string getReply(std::string request) { auto format = HyprCtl::FORMAT_NORMAL; @@ -619,6 +660,8 @@ std::string getReply(std::string request) { return dispatchKeyword(request); else if (request.find("setcursor") == 0) return dispatchSetCursor(request); + else if (request.find("getoption") == 0) + return dispatchGetOption(request, format); else if (request.find("[[BATCH]]") == 0) return dispatchBatch(request); |
