From ad00f7f03a1211d21c90a7cf4c56703de80e0e36 Mon Sep 17 00:00:00 2001 From: Richard Bainesly Date: Wed, 19 Jun 2024 15:24:34 -0400 Subject: [PATCH] allow setting rollinglog delay --- hyprctl/main.cpp | 13 ++++++++----- src/debug/HyprCtl.cpp | 2 ++ 2 files changed, 10 insertions(+), 5 deletions(-) diff --git a/hyprctl/main.cpp b/hyprctl/main.cpp index d70d5874..87915a23 100644 --- a/hyprctl/main.cpp +++ b/hyprctl/main.cpp @@ -107,7 +107,7 @@ void intHandler(int sig) { std::cout << "[hyprctl] SIGINT received, closing connection" << std::endl; } -int rollingRead(const int socket) { +int rollingRead(const int socket, int delay) { sigintReceived = false; signal(SIGINT, intHandler); @@ -132,13 +132,13 @@ int rollingRead(const int socket) { buffer.fill('\0'); } - usleep(1000); + usleep(delay * 1000); } close(socket); return 0; } -int request(std::string arg, int minArgs = 0, bool needRoll = false) { +int request(std::string arg, int minArgs = 0, bool needRoll = false, int rollDelay = 50) { const auto SERVERSOCKET = socket(AF_UNIX, SOCK_STREAM, 0); auto t = timeval{.tv_sec = 0, .tv_usec = 100000}; @@ -183,7 +183,7 @@ int request(std::string arg, int minArgs = 0, bool needRoll = false) { } if (needRoll) - return rollingRead(SERVERSOCKET); + return rollingRead(SERVERSOCKET, rollDelay); std::string reply = ""; char buffer[8192] = {0}; @@ -329,6 +329,7 @@ int main(int argc, char** argv) { const auto ARGS = splitArgs(argc, argv); bool json = false; bool needRoll = false; + int rollDelay = 50; std::string overrideInstance = ""; for (std::size_t i = 0; i < ARGS.size(); ++i) { @@ -351,6 +352,8 @@ int main(int argc, char** argv) { } else if ((ARGS[i] == "-f" || ARGS[i] == "--follow") && !fullArgs.contains("f")) { fullArgs += "f"; needRoll = true; + if (ARGS.size() >= 3) + rollDelay = std::stoi(ARGS[2]); } else if (ARGS[i] == "--batch") { fullRequest = "--batch "; } else if (ARGS[i] == "--instance" || ARGS[i] == "-i") { @@ -475,7 +478,7 @@ int main(int argc, char** argv) { else if (fullRequest.contains("/--help")) std::cout << USAGE << std::endl; else if (fullRequest.contains("/rollinglog") && needRoll) - exitStatus = request(fullRequest, 0, true); + exitStatus = request(fullRequest, 0, true, rollDelay); else { exitStatus = request(fullRequest); } diff --git a/src/debug/HyprCtl.cpp b/src/debug/HyprCtl.cpp index ed42872b..7aff6d1f 100644 --- a/src/debug/HyprCtl.cpp +++ b/src/debug/HyprCtl.cpp @@ -1677,6 +1677,8 @@ std::string CHyprCtl::getReply(std::string request) { std::string result = ""; + request = request.substr(0, request.find(" ")); + // parse exact cmds first, then non-exact. for (auto& cmd : m_vCommands) { if (!cmd->exact)