From 4b334594dc0d8989d8bb09c7db76694aacc71951 Mon Sep 17 00:00:00 2001 From: vaxerski <43317083+vaxerski@users.noreply.github.com> Date: Sun, 10 Jul 2022 15:41:26 +0200 Subject: Added splashes --- hyprctl/main.cpp | 2 ++ 1 file changed, 2 insertions(+) (limited to 'hyprctl/main.cpp') diff --git a/hyprctl/main.cpp b/hyprctl/main.cpp index a1a1122d..b0aa1be8 100644 --- a/hyprctl/main.cpp +++ b/hyprctl/main.cpp @@ -27,6 +27,7 @@ const std::string USAGE = R"#(usage: hyprctl [command] [(opt)args] keyword version kill + splash hyprpaper reload)#"; @@ -201,6 +202,7 @@ int main(int argc, char** argv) { 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); -- cgit v1.2.3 From 036f431206b6c530497fb6e204c9765745c2c17d Mon Sep 17 00:00:00 2001 From: bazuin-32 Date: Tue, 12 Jul 2022 11:57:33 -0600 Subject: Add hyprctl output in json when `-j` flag is used --- hyprctl/main.cpp | 27 +++++++++++++++++---------- 1 file changed, 17 insertions(+), 10 deletions(-) (limited to 'hyprctl/main.cpp') diff --git a/hyprctl/main.cpp b/hyprctl/main.cpp index b0aa1be8..291fc207 100644 --- a/hyprctl/main.cpp +++ b/hyprctl/main.cpp @@ -195,16 +195,23 @@ 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"); + std::string args(argv[1]); + + if (argc > 2) { + args += " "; + args += argv[2]; + } + + if (!strcmp(argv[1], "monitors")) request(args); + else if (!strcmp(argv[1], "clients")) request(args); + else if (!strcmp(argv[1], "workspaces")) request(args); + else if (!strcmp(argv[1], "activewindow")) request(args); + else if (!strcmp(argv[1], "layers")) request(args); + else if (!strcmp(argv[1], "version")) request(args); + else if (!strcmp(argv[1], "kill")) request(args); + else if (!strcmp(argv[1], "splash")) request(args); + else if (!strcmp(argv[1], "devices")) request(args); + else if (!strcmp(argv[1], "reload")) request(args); 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); -- cgit v1.2.3 From 2402f2e36498686dfebe7c06f1203f595b888252 Mon Sep 17 00:00:00 2001 From: bazuin-32 Date: Tue, 12 Jul 2022 14:59:36 -0600 Subject: Use enum for specifying hyprctl output format and change the way flags are passed for json output --- hyprctl/main.cpp | 45 +++++++++++++++++++++++---------------------- 1 file changed, 23 insertions(+), 22 deletions(-) (limited to 'hyprctl/main.cpp') diff --git a/hyprctl/main.cpp b/hyprctl/main.cpp index 291fc207..5ab170e6 100644 --- a/hyprctl/main.cpp +++ b/hyprctl/main.cpp @@ -195,28 +195,29 @@ int main(int argc, char** argv) { return 1; } - std::string args(argv[1]); - - if (argc > 2) { - args += " "; - args += argv[2]; - } - - if (!strcmp(argv[1], "monitors")) request(args); - else if (!strcmp(argv[1], "clients")) request(args); - else if (!strcmp(argv[1], "workspaces")) request(args); - else if (!strcmp(argv[1], "activewindow")) request(args); - else if (!strcmp(argv[1], "layers")) request(args); - else if (!strcmp(argv[1], "version")) request(args); - else if (!strcmp(argv[1], "kill")) request(args); - else if (!strcmp(argv[1], "splash")) request(args); - else if (!strcmp(argv[1], "devices")) request(args); - else if (!strcmp(argv[1], "reload")) request(args); - 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 ourRequest = argv[1]; + + if (!ourRequest.contains("/")) { + ourRequest = "/" + ourRequest; + } + + ourRequest.contains("/"); + + if (ourRequest.contains("/monitors")) request(ourRequest); + else if (ourRequest.contains("/clients")) request(ourRequest); + else if (ourRequest.contains("/workspaces")) request(ourRequest); + else if (ourRequest.contains("/activewindow")) request(ourRequest); + else if (ourRequest.contains("/layers")) request(ourRequest); + else if (ourRequest.contains("/version")) request(ourRequest); + else if (ourRequest.contains("/kill")) request(ourRequest); + else if (ourRequest.contains("/splash")) request(ourRequest); + else if (ourRequest.contains("/devices")) request(ourRequest); + else if (ourRequest.contains("/reload")) request(ourRequest); + else if (ourRequest.contains("/dispatch")) dispatchRequest(argc, argv); + else if (ourRequest.contains("/keyword")) keywordRequest(argc, argv); + else if (ourRequest.contains("/hyprpaper")) hyprpaperRequest(argc, argv); + else if (ourRequest.contains("/--batch")) batchRequest(argc, argv); + else if (ourRequest.contains("/--help")) printf("%s", USAGE.c_str()); else { printf("%s\n", USAGE.c_str()); return 1; -- cgit v1.2.3 From bca93f4d3cd29c88ff32af96dcc1338196feabdb Mon Sep 17 00:00:00 2001 From: vaxerski <43317083+vaxerski@users.noreply.github.com> Date: Tue, 12 Jul 2022 23:17:55 +0200 Subject: code styling --- hyprctl/main.cpp | 44 +++++++++++++++++++++----------------------- 1 file changed, 21 insertions(+), 23 deletions(-) (limited to 'hyprctl/main.cpp') diff --git a/hyprctl/main.cpp b/hyprctl/main.cpp index 5ab170e6..4c7e3a04 100644 --- a/hyprctl/main.cpp +++ b/hyprctl/main.cpp @@ -195,29 +195,27 @@ int main(int argc, char** argv) { return 1; } - std::string ourRequest = argv[1]; - - if (!ourRequest.contains("/")) { - ourRequest = "/" + ourRequest; - } - - ourRequest.contains("/"); - - if (ourRequest.contains("/monitors")) request(ourRequest); - else if (ourRequest.contains("/clients")) request(ourRequest); - else if (ourRequest.contains("/workspaces")) request(ourRequest); - else if (ourRequest.contains("/activewindow")) request(ourRequest); - else if (ourRequest.contains("/layers")) request(ourRequest); - else if (ourRequest.contains("/version")) request(ourRequest); - else if (ourRequest.contains("/kill")) request(ourRequest); - else if (ourRequest.contains("/splash")) request(ourRequest); - else if (ourRequest.contains("/devices")) request(ourRequest); - else if (ourRequest.contains("/reload")) request(ourRequest); - else if (ourRequest.contains("/dispatch")) dispatchRequest(argc, argv); - else if (ourRequest.contains("/keyword")) keywordRequest(argc, argv); - else if (ourRequest.contains("/hyprpaper")) hyprpaperRequest(argc, argv); - else if (ourRequest.contains("/--batch")) batchRequest(argc, argv); - else if (ourRequest.contains("/--help")) printf("%s", USAGE.c_str()); + std::string fullRequest = argv[1]; + + if (!fullRequest.contains("/")) { + fullRequest = "/" + fullRequest; + } + + 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("/--batch")) batchRequest(argc, argv); + else if (fullRequest.contains("/--help")) printf("%s", USAGE.c_str()); else { printf("%s\n", USAGE.c_str()); return 1; -- cgit v1.2.3 From 4bea3467e03eae7c3db251b84605345c576c4313 Mon Sep 17 00:00:00 2001 From: vaxerski <43317083+vaxerski@users.noreply.github.com> Date: Tue, 12 Jul 2022 23:21:00 +0200 Subject: update hyprctl help --- hyprctl/main.cpp | 9 +++++++-- 1 file changed, 7 insertions(+), 2 deletions(-) (limited to 'hyprctl/main.cpp') diff --git a/hyprctl/main.cpp b/hyprctl/main.cpp index 4c7e3a04..b2c00ce7 100644 --- a/hyprctl/main.cpp +++ b/hyprctl/main.cpp @@ -15,8 +15,9 @@ #include #include -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); -- cgit v1.2.3 From ab859ec9fcd749f3f898684710085ff8dc1303d4 Mon Sep 17 00:00:00 2001 From: bazuin-32 Date: Tue, 12 Jul 2022 16:34:28 -0600 Subject: Fix issues with batch requests --- hyprctl/main.cpp | 16 ++++++++++------ 1 file changed, 10 insertions(+), 6 deletions(-) (limited to 'hyprctl/main.cpp') diff --git a/hyprctl/main.cpp b/hyprctl/main.cpp index b2c00ce7..0f30e588 100644 --- a/hyprctl/main.cpp +++ b/hyprctl/main.cpp @@ -186,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); } @@ -200,13 +200,18 @@ int main(int argc, char** argv) { return 1; } - std::string fullRequest = argv[1]; + std::string fullRequest = ""; + for (int i = 1; i < argc; i++) { + fullRequest += std::string(argv[i]) + " "; + } + fullRequest.pop_back(); // remove trailing space - if (!fullRequest.contains("/")) { + if (!std::string(argv[1]).contains("/")) { fullRequest = "/" + fullRequest; } - if (fullRequest.contains("/monitors")) request(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); @@ -219,7 +224,6 @@ int main(int argc, char** argv) { 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("/--batch")) batchRequest(argc, argv); else if (fullRequest.contains("/--help")) printf("%s", USAGE.c_str()); else { printf("%s\n", USAGE.c_str()); -- cgit v1.2.3 From 99e950373234e0a095a59b1737a2c5b1783631bb Mon Sep 17 00:00:00 2001 From: vaxerski <43317083+vaxerski@users.noreply.github.com> Date: Wed, 13 Jul 2022 15:47:35 +0200 Subject: flag pos --- hyprctl/main.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'hyprctl/main.cpp') diff --git a/hyprctl/main.cpp b/hyprctl/main.cpp index 0f30e588..dc5e62f5 100644 --- a/hyprctl/main.cpp +++ b/hyprctl/main.cpp @@ -15,7 +15,7 @@ #include #include -const std::string USAGE = R"#(usage: hyprctl [(opt)flag] [command] [(opt)args] +const std::string USAGE = R"#(usage: hyprctl [command] [(opt)flag] [(opt)args] commands: monitors -- cgit v1.2.3 From e93b45615c726afd5f92db36205baedb6249a281 Mon Sep 17 00:00:00 2001 From: vaxerski <43317083+vaxerski@users.noreply.github.com> Date: Wed, 13 Jul 2022 15:50:46 +0200 Subject: better doc in help --- hyprctl/main.cpp | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) (limited to 'hyprctl/main.cpp') diff --git a/hyprctl/main.cpp b/hyprctl/main.cpp index dc5e62f5..ce77054f 100644 --- a/hyprctl/main.cpp +++ b/hyprctl/main.cpp @@ -15,7 +15,7 @@ #include #include -const std::string USAGE = R"#(usage: hyprctl [command] [(opt)flag] [(opt)args] +const std::string USAGE = R"#(usage: hyprctl [(opt)flag /][command] [(opt)args] commands: monitors @@ -33,7 +33,7 @@ commands: reload flags: - -j -> output in JSON + j -> output in JSON )#"; void request(std::string arg) { -- cgit v1.2.3 From 0085319c18ce7a62139cda318c5a5ccc0e4beed6 Mon Sep 17 00:00:00 2001 From: bazuin-32 Date: Thu, 14 Jul 2022 11:23:18 -0600 Subject: Fix error when running `hyprctl dispatch exec` with an arg that contains a `/` --- hyprctl/main.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'hyprctl/main.cpp') diff --git a/hyprctl/main.cpp b/hyprctl/main.cpp index ce77054f..2e8bbb06 100644 --- a/hyprctl/main.cpp +++ b/hyprctl/main.cpp @@ -159,7 +159,7 @@ void dispatchRequest(int argc, char** argv) { return; } - std::string rq = "dispatch " + std::string(argv[2]) + " " + std::string(argv[3]); + std::string rq = "/dispatch " + std::string(argv[2]) + " " + std::string(argv[3]); request(rq); } -- cgit v1.2.3 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: fixed up hyprctl flags --- hyprctl/main.cpp | 38 ++++++++++++++++++++++++++++++++------ 1 file changed, 32 insertions(+), 6 deletions(-) (limited to 'hyprctl/main.cpp') 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); -- cgit v1.2.3