Fix issues with batch requests

This commit is contained in:
bazuin-32 2022-07-12 16:34:28 -06:00
parent ac9ff795cd
commit ab859ec9fc
2 changed files with 24 additions and 18 deletions

View file

@ -186,8 +186,8 @@ void hyprpaperRequest(int argc, char** argv) {
requestHyprpaper(rq); requestHyprpaper(rq);
} }
void batchRequest(int argc, char** argv) { void batchRequest(std::string arg) {
std::string rq = "[[BATCH]]" + std::string(argv[2]); std::string rq = "[[BATCH]]" + arg.substr(arg.find_first_of(" ") + 1);
request(rq); request(rq);
} }
@ -200,13 +200,18 @@ int main(int argc, char** argv) {
return 1; 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; 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("/clients")) request(fullRequest);
else if (fullRequest.contains("/workspaces")) request(fullRequest); else if (fullRequest.contains("/workspaces")) request(fullRequest);
else if (fullRequest.contains("/activewindow")) 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("/dispatch")) dispatchRequest(argc, argv);
else if (fullRequest.contains("/keyword")) keywordRequest(argc, argv); else if (fullRequest.contains("/keyword")) keywordRequest(argc, argv);
else if (fullRequest.contains("/hyprpaper")) hyprpaperRequest(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 if (fullRequest.contains("/--help")) printf("%s", USAGE.c_str());
else { else {
printf("%s\n", USAGE.c_str()); printf("%s\n", USAGE.c_str());

View file

@ -513,22 +513,24 @@ std::string dispatchBatch(std::string request) {
std::string getReply(std::string request) { std::string getReply(std::string request) {
auto format = HyprCtl::FORMAT_NORMAL; auto format = HyprCtl::FORMAT_NORMAL;
// process flags // process flags for non-batch requests
int sepIndex = 0; if (!(request.find("[[BATCH]]") == 0)) {
for (const auto& c : request) { int sepIndex = 0;
if (c == '/') { // stop at separator for (const auto& c : request) {
break; if (c == '/') { // stop at separator
break;
}
sepIndex++;
if (c == 'j')
format = HyprCtl::FORMAT_JSON;
} }
sepIndex++; if (sepIndex < request.size())
request = request.substr(sepIndex + 1); // remove flags and separator so we can compare the rest of the string
if (c == 'j')
format = HyprCtl::FORMAT_JSON;
} }
if (sepIndex < request.size())
request = request.substr(sepIndex + 1); // remove flags and separator so we can compare the rest of the string
if (request == "monitors") if (request == "monitors")
return monitorsRequest(format); return monitorsRequest(format);
else if (request == "workspaces") else if (request == "workspaces")