diff --git a/src/SharedDefs.hpp b/src/SharedDefs.hpp index 711cf562..a6271556 100644 --- a/src/SharedDefs.hpp +++ b/src/SharedDefs.hpp @@ -3,6 +3,7 @@ #include "helpers/math/Math.hpp" #include #include +#include #include enum eIcons : uint8_t { @@ -50,6 +51,12 @@ struct SHyprCtlCommand { std::function fn; }; +struct SDispatchResult { + bool passEvent = false; + bool success = true; + std::string error; +}; + typedef int64_t WINDOWID; typedef int64_t MONITORID; typedef int64_t WORKSPACEID; diff --git a/src/managers/KeybindManager.hpp b/src/managers/KeybindManager.hpp index 6486ac3b..c8c6266c 100644 --- a/src/managers/KeybindManager.hpp +++ b/src/managers/KeybindManager.hpp @@ -74,12 +74,6 @@ enum eMultiKeyCase : uint8_t { MK_FULL_MATCH }; -struct SDispatchResult { - bool passEvent = false; - bool success = true; - std::string error; -}; - class CKeybindManager { public: CKeybindManager(); diff --git a/src/plugins/PluginAPI.cpp b/src/plugins/PluginAPI.cpp index 4172a856..5e1d9e58 100644 --- a/src/plugins/PluginAPI.cpp +++ b/src/plugins/PluginAPI.cpp @@ -202,6 +202,19 @@ APICALL bool HyprlandAPI::addDispatcher(HANDLE handle, const std::string& name, return true; } +APICALL bool HyprlandAPI::addDispatcherV2(HANDLE handle, const std::string& name, std::function handler) { + auto* const PLUGIN = g_pPluginSystem->getPluginByHandle(handle); + + if (!PLUGIN) + return false; + + PLUGIN->registeredDispatchers.push_back(name); + + g_pKeybindManager->m_mDispatchers[name] = handler; + + return true; +} + APICALL bool HyprlandAPI::removeDispatcher(HANDLE handle, const std::string& name) { auto* const PLUGIN = g_pPluginSystem->getPluginByHandle(handle); diff --git a/src/plugins/PluginAPI.hpp b/src/plugins/PluginAPI.hpp index 6b8c35f0..96c32bf1 100644 --- a/src/plugins/PluginAPI.hpp +++ b/src/plugins/PluginAPI.hpp @@ -236,8 +236,17 @@ namespace HyprlandAPI { Adds a keybind dispatcher. returns: true on success. False otherwise. + + DEPRECATED: use addDispatcherV2 */ - APICALL bool addDispatcher(HANDLE handle, const std::string& name, std::function handler); + APICALL [[deprecated]] bool addDispatcher(HANDLE handle, const std::string& name, std::function handler); + + /* + Adds a keybind dispatcher. + + returns: true on success. False otherwise. + */ + APICALL bool addDispatcherV2(HANDLE handle, const std::string& name, std::function handler); /* Removes a keybind dispatcher.