From ba48e7ceea01a6dbb20d5c29d26de609c6020a28 Mon Sep 17 00:00:00 2001 From: vaxerski <43317083+vaxerski@users.noreply.github.com> Date: Fri, 15 Jul 2022 11:58:09 +0200 Subject: [PATCH] fixed up hyprctl flags --- hyprctl/main.cpp | 38 ++++++++++++++++++++++++++++++++------ 1 file changed, 32 insertions(+), 6 deletions(-) diff --git a/hyprctl/main.cpp b/hyprctl/main.cpp index 2e8bbb06..92ab4f5e 100644 --- a/hyprctl/main.cpp +++ b/hyprctl/main.cpp @@ -14,8 +14,9 @@ #include #include #include +#include -const std::string USAGE = R"#(usage: hyprctl [(opt)flag /][command] [(opt)args] +const std::string USAGE = R"#(usage: hyprctl [(opt)flags] [command] [(opt)args] commands: monitors @@ -192,6 +193,15 @@ void batchRequest(std::string arg) { request(rq); } +std::deque splitArgs(int argc, char** argv) { + std::deque result; + + for (auto i = 1 /* skip the executable */; i < argc; ++i) + result.push_back(std::string(argv[i])); + + return result; +} + int main(int argc, char** argv) { int bflag = 0, sflag = 0, index, c; @@ -201,14 +211,30 @@ int main(int argc, char** argv) { } std::string fullRequest = ""; - for (int i = 1; i < argc; i++) { - fullRequest += std::string(argv[i]) + " "; + std::string fullArgs = ""; + const auto ARGS = splitArgs(argc, argv); + + for (auto i = 0; i < ARGS.size(); ++i) { + if (ARGS[i].contains("-")) { + // parse + if (ARGS[i] == "-j" && !fullArgs.contains("j")) { + fullArgs += "j"; + } else if (ARGS[i] == "--batch") { + fullRequest = "--batch "; + } else { + printf("%s\n", USAGE.c_str()); + return 1; + } + + continue; + } + + fullRequest += ARGS[i] + " "; } + fullRequest.pop_back(); // remove trailing space - if (!std::string(argv[1]).contains("/")) { - fullRequest = "/" + fullRequest; - } + fullRequest = fullArgs + "/" + fullRequest; if (fullRequest.contains("/--batch")) batchRequest(fullRequest); else if (fullRequest.contains("/monitors")) request(fullRequest);