diff options
| author | Vaxry <vaxry@vaxry.net> | 2024-02-05 01:56:38 +0000 |
|---|---|---|
| committer | Vaxry <vaxry@vaxry.net> | 2024-02-05 01:57:29 +0000 |
| commit | 60bda7ee3d0a77d19277540cce53ecbddeabd716 (patch) | |
| tree | 813a2342a3e56c174b5bee91bf274bc6081ef56c /src/plugins | |
| parent | 939696f97e2dcfa9ed6b91aa7ddf608c454d49e5 (diff) | |
pluginapi: allow registering hyprctl commands
closes #4616
Diffstat (limited to 'src/plugins')
| -rw-r--r-- | src/plugins/PluginAPI.cpp | 24 | ||||
| -rw-r--r-- | src/plugins/PluginAPI.hpp | 14 | ||||
| -rw-r--r-- | src/plugins/PluginSystem.cpp | 4 | ||||
| -rw-r--r-- | src/plugins/PluginSystem.hpp | 1 |
4 files changed, 43 insertions, 0 deletions
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<SHyprCtlCommand> 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<SHyprCtlCommand> 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 diff --git a/src/plugins/PluginAPI.hpp b/src/plugins/PluginAPI.hpp index 12e7c128..e7a6c899 100644 --- a/src/plugins/PluginAPI.hpp +++ b/src/plugins/PluginAPI.hpp @@ -273,6 +273,20 @@ namespace HyprlandAPI { for a different hash. */ APICALL SVersionInfo getHyprlandVersion(HANDLE handle); + + /* + Registers a hyprctl command + + returns: Pointer. Nullptr on fail. + */ + APICALL std::shared_ptr<SHyprCtlCommand> registerHyprCtlCommand(HANDLE handle, SHyprCtlCommand cmd); + + /* + Unregisters a hyprctl command + + returns: true on success. False otherwise. + */ + APICALL bool unregisterHyprCtlCommand(HANDLE handle, std::shared_ptr<SHyprCtlCommand> cmd); }; /* diff --git a/src/plugins/PluginSystem.cpp b/src/plugins/PluginSystem.cpp index 1468cb79..44b4de1f 100644 --- a/src/plugins/PluginSystem.cpp +++ b/src/plugins/PluginSystem.cpp @@ -113,6 +113,10 @@ void CPluginSystem::unloadPlugin(const CPlugin* plugin, bool eject) { for (auto& d : rdi) HyprlandAPI::removeDispatcher(plugin->m_pHandle, d); + const auto rhc = plugin->registeredHyprctlCommands; + for (auto& c : rhc) + HyprlandAPI::unregisterHyprCtlCommand(plugin->m_pHandle, c); + g_pConfigManager->removePluginConfig(plugin->m_pHandle); dlclose(plugin->m_pHandle); diff --git a/src/plugins/PluginSystem.hpp b/src/plugins/PluginSystem.hpp index f0c9c9ad..ce2c2bb2 100644 --- a/src/plugins/PluginSystem.hpp +++ b/src/plugins/PluginSystem.hpp @@ -23,6 +23,7 @@ class CPlugin { std::vector<IHyprWindowDecoration*> registeredDecorations; std::vector<std::pair<std::string, HOOK_CALLBACK_FN*>> registeredCallbacks; std::vector<std::string> registeredDispatchers; + std::vector<std::shared_ptr<SHyprCtlCommand>> registeredHyprctlCommands; }; class CPluginSystem { |
