From 60bda7ee3d0a77d19277540cce53ecbddeabd716 Mon Sep 17 00:00:00 2001 From: Vaxry Date: Mon, 5 Feb 2024 01:56:38 +0000 Subject: pluginapi: allow registering hyprctl commands closes #4616 --- src/plugins/PluginAPI.cpp | 24 ++++++++++++++++++++++++ 1 file changed, 24 insertions(+) (limited to 'src/plugins/PluginAPI.cpp') diff --git a/src/plugins/PluginAPI.cpp b/src/plugins/PluginAPI.cpp index e6fe6138..b6a353ea 100644 --- a/src/plugins/PluginAPI.cpp +++ b/src/plugins/PluginAPI.cpp @@ -362,4 +362,28 @@ APICALL SVersionInfo HyprlandAPI::getHyprlandVersion(HANDLE handle) { return {}; return {GIT_COMMIT_HASH, GIT_TAG, GIT_DIRTY != std::string(""), GIT_BRANCH, GIT_COMMIT_MESSAGE}; +} + +APICALL std::shared_ptr HyprlandAPI::registerHyprCtlCommand(HANDLE handle, SHyprCtlCommand cmd) { + auto* const PLUGIN = g_pPluginSystem->getPluginByHandle(handle); + + if (!PLUGIN) + return nullptr; + + auto PTR = g_pHyprCtl->registerCommand(cmd); + PLUGIN->registeredHyprctlCommands.push_back(PTR); + return PTR; +} + +APICALL bool HyprlandAPI::unregisterHyprCtlCommand(HANDLE handle, std::shared_ptr cmd) { + + auto* const PLUGIN = g_pPluginSystem->getPluginByHandle(handle); + + if (!PLUGIN) + return false; + + std::erase(PLUGIN->registeredHyprctlCommands, cmd); + g_pHyprCtl->unregisterCommand(cmd); + + return true; } \ No newline at end of file -- cgit v1.2.3