diff options
author | vaxerski <[email protected]> | 2022-08-11 21:16:38 +0200 |
---|---|---|
committer | vaxerski <[email protected]> | 2022-08-11 21:16:38 +0200 |
commit | 91024716103128ec74cf9a1da97889c74a676a3e (patch) | |
tree | c04c80b5eb4bc19bfbad10021eb450129062d6bf | |
parent | f85c7656342d2b9d515e364de5dff4662ec6865d (diff) | |
download | Hyprland-91024716103128ec74cf9a1da97889c74a676a3e.tar.gz Hyprland-91024716103128ec74cf9a1da97889c74a676a3e.zip |
added hyprctl getoption
-rw-r--r-- | hyprctl/main.cpp | 2 | ||||
-rw-r--r-- | src/config/ConfigManager.cpp | 9 | ||||
-rw-r--r-- | src/config/ConfigManager.hpp | 1 | ||||
-rw-r--r-- | src/debug/HyprCtl.cpp | 43 |
4 files changed, 55 insertions, 0 deletions
diff --git a/hyprctl/main.cpp b/hyprctl/main.cpp index a282b5d0..db8f48a3 100644 --- a/hyprctl/main.cpp +++ b/hyprctl/main.cpp @@ -35,6 +35,7 @@ commands: hyprpaper reload setcursor + getoption flags: -j -> output in JSON @@ -264,6 +265,7 @@ int main(int argc, char** argv) { else if (fullRequest.contains("/splash")) request(fullRequest); else if (fullRequest.contains("/devices")) request(fullRequest); else if (fullRequest.contains("/reload")) request(fullRequest); + else if (fullRequest.contains("/getoption")) request(fullRequest); else if (fullRequest.contains("/setcursor")) setcursorRequest(argc, argv); else if (fullRequest.contains("/dispatch")) dispatchRequest(argc, argv); else if (fullRequest.contains("/keyword")) keywordRequest(argc, argv); diff --git a/src/config/ConfigManager.cpp b/src/config/ConfigManager.cpp index 4b47e096..9e3a1bd3 100644 --- a/src/config/ConfigManager.cpp +++ b/src/config/ConfigManager.cpp @@ -1331,6 +1331,15 @@ SConfigValue* CConfigManager::getConfigValuePtr(std::string val) { return &configValues[val]; } +SConfigValue* CConfigManager::getConfigValuePtrSafe(std::string val) { + const auto IT = configValues.find(val); + + if (IT == configValues.end()) + return nullptr; + + return &(IT->second); +} + bool CConfigManager::deviceConfigExists(const std::string& dev) { const auto it = deviceConfigs.find(dev); diff --git a/src/config/ConfigManager.hpp b/src/config/ConfigManager.hpp index 4eef417f..a4e4091b 100644 --- a/src/config/ConfigManager.hpp +++ b/src/config/ConfigManager.hpp @@ -83,6 +83,7 @@ public: bool shouldBlurLS(const std::string&); SConfigValue* getConfigValuePtr(std::string); + SConfigValue* getConfigValuePtrSafe(std::string); SMonitorRule getMonitorRuleFor(std::string); 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); |