hyprctl: fix hyprctl --batch not working with exec rules (#8952)

This commit is contained in:
Byso 2025-01-06 17:52:59 +01:00 committed by GitHub
parent 6a90b50545
commit 1bf4937b02
No known key found for this signature in database
GPG key ID: B5690EEEBB952194

View file

@ -1150,34 +1150,26 @@ static std::string cursorPosRequest(eHyprCtlOutputFormat format, std::string req
} }
static std::string dispatchBatch(eHyprCtlOutputFormat format, std::string request) { static std::string dispatchBatch(eHyprCtlOutputFormat format, std::string request) {
// split by ; // split by ; ignores ; inside [] and adds ; on last command
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 = trim(curitem);
};
nextItem();
request = request.substr(9);
std::string reply = "";
const std::string DELIMITER = "\n\n\n"; const std::string DELIMITER = "\n\n\n";
int bracket = 0;
size_t idx = 0;
while (curitem != "" || request != "") { for (size_t i = 0; i <= request.size(); ++i) {
reply += g_pHyprCtl->getReply(curitem) + DELIMITER; char ch = (i < request.size()) ? request[i] : ';';
if (ch == '[')
nextItem(); ++bracket;
else if (ch == ']')
--bracket;
else if (ch == ';' && bracket == 0) {
if (idx < i)
reply += g_pHyprCtl->getReply(trim(request.substr(idx, i - idx))).append(DELIMITER);
idx = i + 1;
continue;
}
} }
return reply.substr(0, std::max(static_cast<int>(reply.size() - DELIMITER.size()), 0)); return reply.substr(0, std::max(static_cast<int>(reply.size() - DELIMITER.size()), 0));