diff options
author | Vaxry <[email protected]> | 2024-04-20 20:16:42 +0100 |
---|---|---|
committer | Vaxry <[email protected]> | 2024-04-20 20:16:42 +0100 |
commit | 4ad739ec63c9a11f0537a884ae2a4c56d6bab10b (patch) | |
tree | 0842db7489691fc6e7cbb3cd6d3321dd0d4790b6 /src/plugins/PluginAPI.cpp | |
parent | 1055e6bee677ef9c4ab4d09e43155e00a98a3b49 (diff) | |
download | Hyprland-4ad739ec63c9a11f0537a884ae2a4c56d6bab10b.tar.gz Hyprland-4ad739ec63c9a11f0537a884ae2a4c56d6bab10b.zip |
HookSystem: improve callback safety
Diffstat (limited to 'src/plugins/PluginAPI.cpp')
-rw-r--r-- | src/plugins/PluginAPI.cpp | 18 |
1 files changed, 3 insertions, 15 deletions
diff --git a/src/plugins/PluginAPI.cpp b/src/plugins/PluginAPI.cpp index 78870666..c89918f5 100644 --- a/src/plugins/PluginAPI.cpp +++ b/src/plugins/PluginAPI.cpp @@ -13,30 +13,18 @@ APICALL const char* __hyprland_api_get_hash() { return GIT_COMMIT_HASH; } -APICALL bool HyprlandAPI::registerCallbackStatic(HANDLE handle, const std::string& event, HOOK_CALLBACK_FN* fn) { - auto* const PLUGIN = g_pPluginSystem->getPluginByHandle(handle); - - if (!PLUGIN) - return false; - - g_pHookSystem->hookStatic(event, fn, handle); - PLUGIN->registeredCallbacks.emplace_back(std::make_pair<>(event, fn)); - - return true; -} - -APICALL HOOK_CALLBACK_FN* HyprlandAPI::registerCallbackDynamic(HANDLE handle, const std::string& event, HOOK_CALLBACK_FN fn) { +APICALL std::shared_ptr<HOOK_CALLBACK_FN> HyprlandAPI::registerCallbackDynamic(HANDLE handle, const std::string& event, HOOK_CALLBACK_FN fn) { auto* const PLUGIN = g_pPluginSystem->getPluginByHandle(handle); if (!PLUGIN) return nullptr; - auto* const PFN = g_pHookSystem->hookDynamic(event, fn, handle); + auto PFN = g_pHookSystem->hookDynamic(event, fn, handle); PLUGIN->registeredCallbacks.emplace_back(std::make_pair<>(event, PFN)); return PFN; } -APICALL bool HyprlandAPI::unregisterCallback(HANDLE handle, HOOK_CALLBACK_FN* fn) { +APICALL bool HyprlandAPI::unregisterCallback(HANDLE handle, std::shared_ptr<HOOK_CALLBACK_FN> fn) { auto* const PLUGIN = g_pPluginSystem->getPluginByHandle(handle); if (!PLUGIN) |