diff options
| author | Vaxry <43317083+vaxerski@users.noreply.github.com> | 2022-07-13 15:44:59 +0200 |
|---|---|---|
| committer | GitHub <noreply@github.com> | 2022-07-13 15:44:59 +0200 |
| commit | be69098cb819931f5eb4013275ca9cb7f3a842d4 (patch) | |
| tree | 47d712165310be10240f3fc4054bf914f024bb81 /hyprctl/main.cpp | |
| parent | bf762f566f1c8c5e9c636f0d1ad4e485ad322da9 (diff) | |
| parent | ab859ec9fcd749f3f898684710085ff8dc1303d4 (diff) | |
Merge pull request #360 from bazuin-32/main
Add hyprctl output in json when `-j` flag is used
Diffstat (limited to 'hyprctl/main.cpp')
| -rw-r--r-- | hyprctl/main.cpp | 53 |
1 files changed, 34 insertions, 19 deletions
diff --git a/hyprctl/main.cpp b/hyprctl/main.cpp index b0aa1be8..0f30e588 100644 --- a/hyprctl/main.cpp +++ b/hyprctl/main.cpp @@ -15,8 +15,9 @@ #include <fstream> #include <string> -const std::string USAGE = R"#(usage: hyprctl [command] [(opt)args] +const std::string USAGE = R"#(usage: hyprctl [(opt)flag] [command] [(opt)args] +commands: monitors workspaces clients @@ -29,7 +30,11 @@ const std::string USAGE = R"#(usage: hyprctl [command] [(opt)args] kill splash hyprpaper - reload)#"; + reload + +flags: + -j -> output in JSON +)#"; void request(std::string arg) { const auto SERVERSOCKET = socket(AF_UNIX, SOCK_STREAM, 0); @@ -181,8 +186,8 @@ void hyprpaperRequest(int argc, char** argv) { requestHyprpaper(rq); } -void batchRequest(int argc, char** argv) { - std::string rq = "[[BATCH]]" + std::string(argv[2]); +void batchRequest(std::string arg) { + std::string rq = "[[BATCH]]" + arg.substr(arg.find_first_of(" ") + 1); request(rq); } @@ -195,21 +200,31 @@ int main(int argc, char** argv) { return 1; } - if (!strcmp(argv[1], "monitors")) request("monitors"); - else if (!strcmp(argv[1], "clients")) request("clients"); - else if (!strcmp(argv[1], "workspaces")) request("workspaces"); - else if (!strcmp(argv[1], "activewindow")) request("activewindow"); - else if (!strcmp(argv[1], "layers")) request("layers"); - else if (!strcmp(argv[1], "version")) request("version"); - else if (!strcmp(argv[1], "kill")) request("kill"); - else if (!strcmp(argv[1], "splash")) request("splash"); - else if (!strcmp(argv[1], "devices")) request("devices"); - else if (!strcmp(argv[1], "reload")) request("reload"); - else if (!strcmp(argv[1], "dispatch")) dispatchRequest(argc, argv); - else if (!strcmp(argv[1], "keyword")) keywordRequest(argc, argv); - else if (!strcmp(argv[1], "hyprpaper")) hyprpaperRequest(argc, argv); - else if (!strcmp(argv[1], "--batch")) batchRequest(argc, argv); - else if (!strcmp(argv[1], "--help")) printf("%s", USAGE.c_str()); + std::string fullRequest = ""; + for (int i = 1; i < argc; i++) { + fullRequest += std::string(argv[i]) + " "; + } + fullRequest.pop_back(); // remove trailing space + + if (!std::string(argv[1]).contains("/")) { + fullRequest = "/" + fullRequest; + } + + if (fullRequest.contains("/--batch")) batchRequest(fullRequest); + else if (fullRequest.contains("/monitors")) request(fullRequest); + else if (fullRequest.contains("/clients")) request(fullRequest); + else if (fullRequest.contains("/workspaces")) request(fullRequest); + else if (fullRequest.contains("/activewindow")) request(fullRequest); + else if (fullRequest.contains("/layers")) request(fullRequest); + else if (fullRequest.contains("/version")) request(fullRequest); + else if (fullRequest.contains("/kill")) request(fullRequest); + 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("/dispatch")) dispatchRequest(argc, argv); + else if (fullRequest.contains("/keyword")) keywordRequest(argc, argv); + else if (fullRequest.contains("/hyprpaper")) hyprpaperRequest(argc, argv); + else if (fullRequest.contains("/--help")) printf("%s", USAGE.c_str()); else { printf("%s\n", USAGE.c_str()); return 1; |
