From 07080498fd050a6a6660eb68c36d12eb3f87a003 Mon Sep 17 00:00:00 2001 From: vaxerski <43317083+vaxerski@users.noreply.github.com> Date: Thu, 21 Apr 2022 16:56:27 +0200 Subject: Added hyprctl keyword --- src/config/ConfigManager.cpp | 63 +++++++++++++++++++++++++------------------- src/config/ConfigManager.hpp | 2 ++ src/debug/HyprCtl.cpp | 17 ++++++++++++ 3 files changed, 55 insertions(+), 27 deletions(-) (limited to 'src') diff --git a/src/config/ConfigManager.cpp b/src/config/ConfigManager.cpp index db5f5a8a..976c38b5 100644 --- a/src/config/ConfigManager.cpp +++ b/src/config/ConfigManager.cpp @@ -253,6 +253,41 @@ void CConfigManager::handleDefaultWorkspace(const std::string& command, const st } } +std::string CConfigManager::parseKeyword(const std::string& COMMAND, const std::string& VALUE, bool dynamic) { + if (dynamic) + parseError = ""; + + if (COMMAND == "exec") { + if (isFirstLaunch) { + firstExecRequests.push_back(VALUE); + } else { + handleRawExec(COMMAND, VALUE); + } + } else if (COMMAND == "exec-once") { + if (isFirstLaunch) { + firstExecRequests.push_back(VALUE); + } + } else if (COMMAND == "monitor") { + handleMonitor(COMMAND, VALUE); + } else if (COMMAND == "bind") { + handleBind(COMMAND, VALUE); + } else if (COMMAND == "workspace") { + handleDefaultWorkspace(COMMAND, VALUE); + } else if (COMMAND == "windowrule") { + handleWindowRule(COMMAND, VALUE); + } else { + configSetValueSafe(currentCategory + (currentCategory == "" ? "" : ":") + COMMAND, VALUE); + } + + if (dynamic) { + std::string retval = parseError; + parseError = ""; + return retval; + } + + return parseError; +} + void CConfigManager::parseLine(std::string& line) { // first check if its not a comment const auto COMMENTSTART = line.find_first_of('#'); @@ -298,33 +333,7 @@ void CConfigManager::parseLine(std::string& line) { const auto VALUE = removeBeginEndSpacesTabs(line.substr(EQUALSPLACE + 1)); // - if (COMMAND == "exec") { - if (isFirstLaunch) { - firstExecRequests.push_back(VALUE); - } else { - handleRawExec(COMMAND, VALUE); - } - return; - } else if (COMMAND == "exec-once") { - if (isFirstLaunch) { - firstExecRequests.push_back(VALUE); - } - return; - } else if (COMMAND == "monitor") { - handleMonitor(COMMAND, VALUE); - return; - } else if (COMMAND == "bind") { - handleBind(COMMAND, VALUE); - return; - } else if (COMMAND == "workspace") { - handleDefaultWorkspace(COMMAND, VALUE); - return; - } else if (COMMAND == "windowrule") { - handleWindowRule(COMMAND, VALUE); - return; - } - - configSetValueSafe(currentCategory + (currentCategory == "" ? "" : ":") + COMMAND, VALUE); + parseKeyword(COMMAND, VALUE); } void CConfigManager::loadConfigLoadVars() { diff --git a/src/config/ConfigManager.hpp b/src/config/ConfigManager.hpp index 314592a9..2f071a13 100644 --- a/src/config/ConfigManager.hpp +++ b/src/config/ConfigManager.hpp @@ -58,6 +58,8 @@ public: void performMonitorReload(); bool m_bWantsMonitorReload = false; + std::string parseKeyword(const std::string&, const std::string&, bool dynamic = false); + private: std::unordered_map configValues; time_t lastModifyTime = 0; // for reloading the config if changed diff --git a/src/debug/HyprCtl.cpp b/src/debug/HyprCtl.cpp index 998ea360..21023ef6 100644 --- a/src/debug/HyprCtl.cpp +++ b/src/debug/HyprCtl.cpp @@ -88,6 +88,22 @@ std::string dispatchRequest(std::string in) { return "ok"; } +std::string dispatchKeyword(std::string in) { + // get rid of the keyword keyword + in = in.substr(in.find_first_of(' ') + 1); + + const auto COMMAND = in.substr(0, in.find_first_of(' ')); + + const auto VALUE = in.substr(in.find_first_of(' ') + 1); + + std::string retval = g_pConfigManager->parseKeyword(COMMAND, VALUE, true); + + if (retval == "") + return "ok"; + + return retval; +} + void HyprCtl::startHyprCtlSocket() { std::thread([&]() { uint16_t connectPort = 9187; @@ -149,6 +165,7 @@ void HyprCtl::startHyprCtlSocket() { else if (request == "activewindow") reply = activeWindowRequest(); else if (request == "layers") reply = layersRequest(); else if (request.find("dispatch") == 0) reply = dispatchRequest(request); + else if (request.find("keyword") == 0) reply = dispatchKeyword(request); } catch (std::exception& e) { Debug::log(ERR, "Error in request: %s", e.what()); reply = "Err: " + std::string(e.what()); -- cgit v1.2.3