event: refactor HookSystem into a typed event bus (#13333)
Refactors the old HookSystem into a typed event bus with clear separation, discovery and types.
This commit is contained in:
parent
b4ee4674f9
commit
b88813c7ef
58 changed files with 493 additions and 516 deletions
|
|
@ -2,7 +2,6 @@
|
|||
#include "../Compositor.hpp"
|
||||
#include "../debug/HyprCtl.hpp"
|
||||
#include "../plugins/PluginSystem.hpp"
|
||||
#include "../managers/HookSystemManager.hpp"
|
||||
#include "../managers/eventLoop/EventLoopManager.hpp"
|
||||
#include "../config/ConfigManager.hpp"
|
||||
#include "../debug/HyprNotificationOverlay.hpp"
|
||||
|
|
@ -38,9 +37,9 @@ APICALL SP<HOOK_CALLBACK_FN> HyprlandAPI::registerCallbackDynamic(HANDLE handle,
|
|||
if (!PLUGIN)
|
||||
return nullptr;
|
||||
|
||||
auto PFN = g_pHookSystem->hookDynamic(event, fn, handle);
|
||||
PLUGIN->m_registeredCallbacks.emplace_back(std::make_pair<>(event, WP<HOOK_CALLBACK_FN>(PFN)));
|
||||
return PFN;
|
||||
//auto PFN = g_pHookSystem->hookDynamic(event, fn, handle);
|
||||
//PLUGIN->m_registeredCallbacks.emplace_back(std::make_pair<>(event, WP<HOOK_CALLBACK_FN>(PFN)));
|
||||
return nullptr;
|
||||
}
|
||||
|
||||
APICALL bool HyprlandAPI::unregisterCallback(HANDLE handle, SP<HOOK_CALLBACK_FN> fn) {
|
||||
|
|
@ -49,8 +48,8 @@ APICALL bool HyprlandAPI::unregisterCallback(HANDLE handle, SP<HOOK_CALLBACK_FN>
|
|||
if (!PLUGIN)
|
||||
return false;
|
||||
|
||||
g_pHookSystem->unhook(fn);
|
||||
std::erase_if(PLUGIN->m_registeredCallbacks, [&](const auto& other) { return other.second.lock() == fn; });
|
||||
//g_pHookSystem->unhook(fn);
|
||||
// std::erase_if(PLUGIN->m_registeredCallbacks, [&](const auto& other) { return other.second.lock() == fn; });
|
||||
|
||||
return true;
|
||||
}
|
||||
|
|
|
|||
|
|
@ -70,12 +70,15 @@ struct SVersionInfo {
|
|||
class IHyprLayout;
|
||||
class IHyprWindowDecoration;
|
||||
struct SConfigValue;
|
||||
class Hypr_dummyClass {};
|
||||
|
||||
namespace Layout {
|
||||
class ITiledAlgorithm;
|
||||
class IFloatingAlgorithm;
|
||||
};
|
||||
|
||||
using HOOK_CALLBACK_FN = Hypr_dummyClass;
|
||||
|
||||
/*
|
||||
These methods are for the plugin to implement
|
||||
Methods marked with REQUIRED are required.
|
||||
|
|
@ -148,6 +151,8 @@ namespace HyprlandAPI {
|
|||
APICALL Hyprlang::CConfigValue* getConfigValue(HANDLE handle, const std::string& name);
|
||||
|
||||
/*
|
||||
Deprecated: doesn't do anything anymore, use Event::bus()
|
||||
|
||||
Register a dynamic (function) callback to a selected event.
|
||||
Pointer will be free'd by Hyprland on unregisterCallback().
|
||||
|
||||
|
|
@ -155,7 +160,7 @@ namespace HyprlandAPI {
|
|||
|
||||
WARNING: Losing this pointer will unregister the callback!
|
||||
*/
|
||||
APICALL [[nodiscard]] SP<HOOK_CALLBACK_FN> registerCallbackDynamic(HANDLE handle, const std::string& event, HOOK_CALLBACK_FN fn);
|
||||
APICALL [[deprecated]] [[nodiscard]] SP<HOOK_CALLBACK_FN> registerCallbackDynamic(HANDLE handle, const std::string& event, HOOK_CALLBACK_FN fn);
|
||||
|
||||
/*
|
||||
Unregisters a callback. If the callback was dynamic, frees the memory.
|
||||
|
|
|
|||
|
|
@ -4,7 +4,6 @@
|
|||
#include <ranges>
|
||||
#include "../config/ConfigManager.hpp"
|
||||
#include "../debug/HyprCtl.hpp"
|
||||
#include "../managers/HookSystemManager.hpp"
|
||||
#include "../managers/eventLoop/EventLoopManager.hpp"
|
||||
#include "../managers/permissions/DynamicPermissionManager.hpp"
|
||||
#include "../debug/HyprNotificationOverlay.hpp"
|
||||
|
|
@ -151,10 +150,10 @@ void CPluginSystem::unloadPlugin(const CPlugin* plugin, bool eject) {
|
|||
exitFunc();
|
||||
}
|
||||
|
||||
for (auto const& [k, v] : plugin->m_registeredCallbacks) {
|
||||
if (const auto SHP = v.lock())
|
||||
g_pHookSystem->unhook(SHP);
|
||||
}
|
||||
// for (auto const& [k, v] : plugin->m_registeredCallbacks) {
|
||||
// if (const auto SHP = v.lock())
|
||||
// g_pHookSystem->unhook(SHP);
|
||||
// }
|
||||
|
||||
for (const auto& l : plugin->m_registeredAlgos) {
|
||||
Layout::Supplementary::algoMatcher()->unregisterAlgo(l);
|
||||
|
|
|
|||
|
|
@ -12,22 +12,22 @@ class IHyprWindowDecoration;
|
|||
|
||||
class CPlugin {
|
||||
public:
|
||||
std::string m_name = "";
|
||||
std::string m_description = "";
|
||||
std::string m_author = "";
|
||||
std::string m_version = "";
|
||||
std::string m_name = "";
|
||||
std::string m_description = "";
|
||||
std::string m_author = "";
|
||||
std::string m_version = "";
|
||||
|
||||
std::string m_path = "";
|
||||
std::string m_path = "";
|
||||
|
||||
bool m_loadedWithConfig = false;
|
||||
bool m_loadedWithConfig = false;
|
||||
|
||||
HANDLE m_handle = nullptr;
|
||||
HANDLE m_handle = nullptr;
|
||||
|
||||
std::vector<IHyprWindowDecoration*> m_registeredDecorations;
|
||||
std::vector<std::pair<std::string, WP<HOOK_CALLBACK_FN>>> m_registeredCallbacks;
|
||||
std::vector<std::string> m_registeredDispatchers;
|
||||
std::vector<WP<SHyprCtlCommand>> m_registeredHyprctlCommands;
|
||||
std::vector<std::string> m_registeredAlgos;
|
||||
std::vector<IHyprWindowDecoration*> m_registeredDecorations;
|
||||
//std::vector<std::pair<std::string, WP<HOOK_CALLBACK_FN>>> m_registeredCallbacks;
|
||||
std::vector<std::string> m_registeredDispatchers;
|
||||
std::vector<WP<SHyprCtlCommand>> m_registeredHyprctlCommands;
|
||||
std::vector<std::string> m_registeredAlgos;
|
||||
};
|
||||
|
||||
class CPluginSystem {
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue