From 8b81f41e52b55835aaaa7e4962af23a00188cbdc Mon Sep 17 00:00:00 2001 From: Vaxry <43317083+vaxerski@users.noreply.github.com> Date: Mon, 27 Feb 2023 12:32:38 +0000 Subject: Plugin System (#1590) --------- Co-authored-by: Mihai Fufezan --- src/debug/HyprCtl.cpp | 50 ++++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 50 insertions(+) (limited to 'src/debug/HyprCtl.cpp') diff --git a/src/debug/HyprCtl.cpp b/src/debug/HyprCtl.cpp index 91af3938..f6ed285b 100644 --- a/src/debug/HyprCtl.cpp +++ b/src/debug/HyprCtl.cpp @@ -1087,6 +1087,50 @@ std::string dispatchOutput(std::string request) { return "ok"; } +std::string dispatchPlugin(std::string request) { + CVarList vars(request, 0, ' '); + + if (vars.size() < 2) + return "not enough args"; + + const auto OPERATION = vars[1]; + const auto PATH = vars[2]; + + if (OPERATION == "load") { + if (vars.size() < 3) + return "not enough args"; + + const auto PLUGIN = g_pPluginSystem->loadPlugin(PATH); + + if (!PLUGIN) + return "error in loading plugin"; + } else if (OPERATION == "unload") { + if (vars.size() < 3) + return "not enough args"; + + const auto PLUGIN = g_pPluginSystem->getPluginByPath(PATH); + + if (!PLUGIN) + return "plugin not loaded"; + + g_pPluginSystem->unloadPlugin(PLUGIN); + } else if (OPERATION == "list") { + const auto PLUGINS = g_pPluginSystem->getAllPlugins(); + + std::string list = ""; + for (auto& p : PLUGINS) { + list += getFormat("\nPlugin %s by %s:\n\tHandle: %lx\n\tVersion: %s\n\tDescription: %s\n", p->name.c_str(), p->author.c_str(), p->m_pHandle, p->version.c_str(), + p->description.c_str()); + } + + return list; + } else { + return "unknown opt"; + } + + return "ok"; +} + std::string getReply(std::string request) { auto format = HyprCtl::FORMAT_NORMAL; @@ -1134,6 +1178,8 @@ std::string getReply(std::string request) { return bindsRequest(format); else if (request == "animations") return animationsRequest(format); + else if (request.find("plugin") == 0) + return dispatchPlugin(request); else if (request.find("setprop") == 0) return dispatchSetProp(request); else if (request.find("seterror") == 0) @@ -1156,6 +1202,10 @@ std::string getReply(std::string request) { return "unknown request"; } +std::string HyprCtl::makeDynamicCall(const std::string& input) { + return getReply(input); +} + int hyprCtlFDTick(int fd, uint32_t mask, void* data) { if (mask & WL_EVENT_ERROR || mask & WL_EVENT_HANGUP) return 0; -- cgit v1.2.3