diff options
| author | Byso <byso.dm@pm.me> | 2025-01-06 17:52:59 +0100 |
|---|---|---|
| committer | GitHub <noreply@github.com> | 2025-01-06 16:52:59 +0000 |
| commit | 1bf4937b0292dc156e2530185c231608280be27f (patch) | |
| tree | b250b6402bfc5b025b0f27c7dc97c28a15a6a107 /src/debug/HyprCtl.cpp | |
| parent | 6a90b505456cc708ec2779e0943eb9764e7630a5 (diff) | |
hyprctl: fix hyprctl --batch not working with exec rules (#8952)
Diffstat (limited to 'src/debug/HyprCtl.cpp')
| -rw-r--r-- | src/debug/HyprCtl.cpp | 44 |
1 files changed, 18 insertions, 26 deletions
diff --git a/src/debug/HyprCtl.cpp b/src/debug/HyprCtl.cpp index b946da6e..8724d2c7 100644 --- a/src/debug/HyprCtl.cpp +++ b/src/debug/HyprCtl.cpp @@ -1150,34 +1150,26 @@ static std::string cursorPosRequest(eHyprCtlOutputFormat format, std::string req } static std::string dispatchBatch(eHyprCtlOutputFormat format, 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 = trim(curitem); - }; - - nextItem(); + // split by ; ignores ; inside [] and adds ; on last command + request = request.substr(9); + std::string reply = ""; const std::string DELIMITER = "\n\n\n"; - - while (curitem != "" || request != "") { - reply += g_pHyprCtl->getReply(curitem) + DELIMITER; - - nextItem(); + int bracket = 0; + size_t idx = 0; + + for (size_t i = 0; i <= request.size(); ++i) { + char ch = (i < request.size()) ? request[i] : ';'; + if (ch == '[') + ++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)); |
