mirror of
https://github.com/hyprwm/Hyprland
synced 2024-11-29 19:05:58 +01:00
added hyprctl batch
This commit is contained in:
parent
726ba65785
commit
31a429899b
2 changed files with 65 additions and 16 deletions
|
@ -122,6 +122,12 @@ void keywordRequest(int argc, char** argv) {
|
||||||
request(rq);
|
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 main(int argc, char** argv) {
|
||||||
int bflag = 0, sflag = 0, index, c;
|
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], "version")) request("version");
|
||||||
else if (!strcmp(argv[1], "dispatch")) dispatchRequest(argc, argv);
|
else if (!strcmp(argv[1], "dispatch")) dispatchRequest(argc, argv);
|
||||||
else if (!strcmp(argv[1], "keyword")) keywordRequest(argc, argv);
|
else if (!strcmp(argv[1], "keyword")) keywordRequest(argc, argv);
|
||||||
|
else if (!strcmp(argv[1], "--batch")) batchRequest(argc, argv);
|
||||||
else {
|
else {
|
||||||
printf(USAGE.c_str());
|
printf(USAGE.c_str());
|
||||||
return 1;
|
return 1;
|
||||||
|
|
|
@ -130,6 +130,63 @@ std::string dispatchKeyword(std::string in) {
|
||||||
return retval;
|
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() {
|
void HyprCtl::tickHyprCtl() {
|
||||||
if (!requestMade)
|
if (!requestMade)
|
||||||
return;
|
return;
|
||||||
|
@ -137,22 +194,7 @@ void HyprCtl::tickHyprCtl() {
|
||||||
std::string reply = "";
|
std::string reply = "";
|
||||||
|
|
||||||
try {
|
try {
|
||||||
if (request == "monitors")
|
reply = getReply(request);
|
||||||
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);
|
|
||||||
} catch (std::exception& e) {
|
} catch (std::exception& e) {
|
||||||
Debug::log(ERR, "Error in request: %s", e.what());
|
Debug::log(ERR, "Error in request: %s", e.what());
|
||||||
reply = "Err: " + std::string(e.what());
|
reply = "Err: " + std::string(e.what());
|
||||||
|
|
Loading…
Reference in a new issue