diff options
author | vaxerski <[email protected]> | 2022-04-29 19:44:09 +0200 |
---|---|---|
committer | vaxerski <[email protected]> | 2022-04-29 19:44:09 +0200 |
commit | 31a429899b3132a704211eb5bffb5cde3ec3c9fc (patch) | |
tree | 0c51e6ea7503581ddd788185ad53b96f36b1e9b0 | |
parent | 726ba657850ef1680c82d3815c91421d9c588844 (diff) | |
download | Hyprland-31a429899b3132a704211eb5bffb5cde3ec3c9fc.tar.gz Hyprland-31a429899b3132a704211eb5bffb5cde3ec3c9fc.zip |
added hyprctl batch
-rw-r--r-- | hyprctl/main.cpp | 7 | ||||
-rw-r--r-- | src/debug/HyprCtl.cpp | 74 |
2 files changed, 65 insertions, 16 deletions
diff --git a/hyprctl/main.cpp b/hyprctl/main.cpp index 6d0b2fc9..6a9a9bda 100644 --- a/hyprctl/main.cpp +++ b/hyprctl/main.cpp @@ -122,6 +122,12 @@ void keywordRequest(int argc, char** argv) { request(rq); } +void batchRequest(int argc, char** argv) { + std::string rq = "[[BATCH]]" + std::string(argv[2]); + + request(rq); +} + int main(int argc, char** argv) { int bflag = 0, sflag = 0, index, c; @@ -138,6 +144,7 @@ int main(int argc, char** argv) { else if (!strcmp(argv[1], "version")) request("version"); else if (!strcmp(argv[1], "dispatch")) dispatchRequest(argc, argv); else if (!strcmp(argv[1], "keyword")) keywordRequest(argc, argv); + else if (!strcmp(argv[1], "--batch")) batchRequest(argc, argv); else { printf(USAGE.c_str()); return 1; diff --git a/src/debug/HyprCtl.cpp b/src/debug/HyprCtl.cpp index fab67969..d670ea37 100644 --- a/src/debug/HyprCtl.cpp +++ b/src/debug/HyprCtl.cpp @@ -130,6 +130,63 @@ std::string dispatchKeyword(std::string in) { return retval; } +std::string getReply(std::string); + +std::string dispatchBatch(std::string request) { + // split by ; + + request = request.substr(9); + std::string curitem = ""; + std::string reply = ""; + + 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(); + + while (curitem != "") { + reply += getReply(curitem); + + nextItem(); + } + + return reply; +} + +std::string getReply(std::string request) { + if (request == "monitors") + return monitorsRequest(); + else if (request == "workspaces") + return workspacesRequest(); + else if (request == "clients") + return clientsRequest(); + else if (request == "activewindow") + return activeWindowRequest(); + else if (request == "layers") + return layersRequest(); + else if (request == "version") + return versionRequest(); + else if (request.find("dispatch") == 0) + return dispatchRequest(request); + else if (request.find("keyword") == 0) + return dispatchKeyword(request); + else if (request.find("[[BATCH]]") == 0) + return dispatchBatch(request); + + return "unknown request"; +} + void HyprCtl::tickHyprCtl() { if (!requestMade) return; @@ -137,22 +194,7 @@ void HyprCtl::tickHyprCtl() { std::string reply = ""; try { - if (request == "monitors") - reply = monitorsRequest(); - else if (request == "workspaces") - reply = workspacesRequest(); - else if (request == "clients") - reply = clientsRequest(); - else if (request == "activewindow") - reply = activeWindowRequest(); - else if (request == "layers") - reply = layersRequest(); - else if (request == "version") - reply = versionRequest(); - else if (request.find("dispatch") == 0) - reply = dispatchRequest(request); - else if (request.find("keyword") == 0) - reply = dispatchKeyword(request); + reply = getReply(request); } catch (std::exception& e) { Debug::log(ERR, "Error in request: %s", e.what()); reply = "Err: " + std::string(e.what()); |