diff --git a/borders-plus-plus/main.cpp b/borders-plus-plus/main.cpp index a07b3c6..ffb7ee4 100644 --- a/borders-plus-plus/main.cpp +++ b/borders-plus-plus/main.cpp @@ -43,7 +43,7 @@ APICALL EXPORT PLUGIN_DESCRIPTION_INFO PLUGIN_INIT(HANDLE handle) { HyprlandAPI::reloadConfig(); - HyprlandAPI::registerCallbackDynamic(PHANDLE, "openWindow", [&](void* self, SCallbackInfo& info, std::any data) { onNewWindow(self, data); }); + static auto P = HyprlandAPI::registerCallbackDynamic(PHANDLE, "openWindow", [&](void* self, SCallbackInfo& info, std::any data) { onNewWindow(self, data); }); // add deco to existing windows for (auto& w : g_pCompositor->m_vWindows) { diff --git a/hyprbars/barDeco.hpp b/hyprbars/barDeco.hpp index e93bb10..96e1cc2 100644 --- a/hyprbars/barDeco.hpp +++ b/hyprbars/barDeco.hpp @@ -34,35 +34,35 @@ class CHyprBar : public IHyprWindowDecoration { CWindow* getOwner(); private: - SWindowDecorationExtents m_seExtents; + SWindowDecorationExtents m_seExtents; - CWindow* m_pWindow = nullptr; + CWindow* m_pWindow = nullptr; - CBox m_bAssignedBox; + CBox m_bAssignedBox; - CTexture m_tTextTex; - CTexture m_tButtonsTex; + CTexture m_tTextTex; + CTexture m_tButtonsTex; - bool m_bWindowSizeChanged = false; + bool m_bWindowSizeChanged = false; - Vector2D cursorRelativeToBar(); + Vector2D cursorRelativeToBar(); - void renderBarTitle(const Vector2D& bufferSize, const float scale); - void renderText(CTexture& out, const std::string& text, const CColor& color, const Vector2D& bufferSize, const float scale, const int fontSize); - void renderBarButtons(const Vector2D& bufferSize, const float scale); - void renderBarButtonsText(CBox* barBox, const float scale, const float a); - void onMouseDown(SCallbackInfo& info, wlr_pointer_button_event* e); - void onMouseMove(Vector2D coords); - CBox assignedBoxGlobal(); + void renderBarTitle(const Vector2D& bufferSize, const float scale); + void renderText(CTexture& out, const std::string& text, const CColor& color, const Vector2D& bufferSize, const float scale, const int fontSize); + void renderBarButtons(const Vector2D& bufferSize, const float scale); + void renderBarButtonsText(CBox* barBox, const float scale, const float a); + void onMouseDown(SCallbackInfo& info, wlr_pointer_button_event* e); + void onMouseMove(Vector2D coords); + CBox assignedBoxGlobal(); - HOOK_CALLBACK_FN* m_pMouseButtonCallback; - HOOK_CALLBACK_FN* m_pMouseMoveCallback; + std::shared_ptr m_pMouseButtonCallback; + std::shared_ptr m_pMouseMoveCallback; - std::string m_szLastTitle; + std::string m_szLastTitle; - bool m_bDraggingThis = false; - bool m_bDragPending = false; - bool m_bCancelledDown = false; + bool m_bDraggingThis = false; + bool m_bDragPending = false; + bool m_bCancelledDown = false; // for dynamic updates int m_iLastHeight = 0; diff --git a/hyprbars/main.cpp b/hyprbars/main.cpp index 19f2809..61b94c5 100644 --- a/hyprbars/main.cpp +++ b/hyprbars/main.cpp @@ -86,8 +86,8 @@ APICALL EXPORT PLUGIN_DESCRIPTION_INFO PLUGIN_INIT(HANDLE handle) { g_pGlobalState = std::make_unique(); - HyprlandAPI::registerCallbackDynamic(PHANDLE, "openWindow", [&](void* self, SCallbackInfo& info, std::any data) { onNewWindow(self, data); }); - HyprlandAPI::registerCallbackDynamic(PHANDLE, "closeWindow", [&](void* self, SCallbackInfo& info, std::any data) { onCloseWindow(self, data); }); + static auto P = HyprlandAPI::registerCallbackDynamic(PHANDLE, "openWindow", [&](void* self, SCallbackInfo& info, std::any data) { onNewWindow(self, data); }); + static auto P2 = HyprlandAPI::registerCallbackDynamic(PHANDLE, "closeWindow", [&](void* self, SCallbackInfo& info, std::any data) { onCloseWindow(self, data); }); HyprlandAPI::addConfigValue(PHANDLE, "plugin:hyprbars:bar_color", Hyprlang::INT{configStringToInt("rgba(33333388)")}); HyprlandAPI::addConfigValue(PHANDLE, "plugin:hyprbars:bar_height", Hyprlang::INT{15}); diff --git a/hyprexpo/main.cpp b/hyprexpo/main.cpp index 6c901e7..1b54f8d 100644 --- a/hyprexpo/main.cpp +++ b/hyprexpo/main.cpp @@ -138,8 +138,7 @@ static void onExpoDispatcher(std::string arg) { } static void failNotif(const std::string& reason) { - HyprlandAPI::addNotification(PHANDLE, "[hyprexpo] Failure in initialization: " + reason, - CColor{1.0, 0.2, 0.2, 1.0}, 5000); + HyprlandAPI::addNotification(PHANDLE, "[hyprexpo] Failure in initialization: " + reason, CColor{1.0, 0.2, 0.2, 1.0}, 5000); } APICALL EXPORT PLUGIN_DESCRIPTION_INFO PLUGIN_INIT(HANDLE handle) { @@ -185,15 +184,15 @@ APICALL EXPORT PLUGIN_DESCRIPTION_INFO PLUGIN_INIT(HANDLE handle) { throw std::runtime_error("[he] Failed initializing hooks"); } - HyprlandAPI::registerCallbackDynamic(PHANDLE, "preRender", [](void* self, SCallbackInfo& info, std::any param) { + static auto P = HyprlandAPI::registerCallbackDynamic(PHANDLE, "preRender", [](void* self, SCallbackInfo& info, std::any param) { if (!g_pOverview) return; g_pOverview->onPreRender(); }); - HyprlandAPI::registerCallbackDynamic(PHANDLE, "swipeBegin", [](void* self, SCallbackInfo& info, std::any data) { swipeBegin(self, info, data); }); - HyprlandAPI::registerCallbackDynamic(PHANDLE, "swipeEnd", [](void* self, SCallbackInfo& info, std::any data) { swipeEnd(self, info, data); }); - HyprlandAPI::registerCallbackDynamic(PHANDLE, "swipeUpdate", [](void* self, SCallbackInfo& info, std::any data) { swipeUpdate(self, info, data); }); + static auto P2 = HyprlandAPI::registerCallbackDynamic(PHANDLE, "swipeBegin", [](void* self, SCallbackInfo& info, std::any data) { swipeBegin(self, info, data); }); + static auto P3 = HyprlandAPI::registerCallbackDynamic(PHANDLE, "swipeEnd", [](void* self, SCallbackInfo& info, std::any data) { swipeEnd(self, info, data); }); + static auto P4 = HyprlandAPI::registerCallbackDynamic(PHANDLE, "swipeUpdate", [](void* self, SCallbackInfo& info, std::any data) { swipeUpdate(self, info, data); }); HyprlandAPI::addDispatcher(PHANDLE, "hyprexpo:expo", onExpoDispatcher); diff --git a/hyprexpo/overview.cpp b/hyprexpo/overview.cpp index 56f0787..515c1a8 100644 --- a/hyprexpo/overview.cpp +++ b/hyprexpo/overview.cpp @@ -17,10 +17,6 @@ static void removeOverview(void*) { COverview::~COverview() { g_pHyprRenderer->makeEGLCurrent(); images.clear(); // otherwise we get a vram leak - g_pHookSystem->unhook(touchUpHook); - g_pHookSystem->unhook(touchMoveHook); - g_pHookSystem->unhook(mouseButtonHook); - g_pHookSystem->unhook(mouseMoveHook); g_pInputManager->unsetCursorImage(); g_pHyprOpenGL->markBlurDirtyForMonitor(pMonitor); } diff --git a/hyprexpo/overview.hpp b/hyprexpo/overview.hpp index 8bd9972..ad5efb7 100644 --- a/hyprexpo/overview.hpp +++ b/hyprexpo/overview.hpp @@ -54,27 +54,27 @@ class COverview { CBox box; }; - Vector2D lastMousePosLocal = Vector2D{}; + Vector2D lastMousePosLocal = Vector2D{}; - int openedID = -1; - int closeOnID = -1; + int openedID = -1; + int closeOnID = -1; - std::vector images; + std::vector images; - PHLWORKSPACE startedOn; + PHLWORKSPACE startedOn; - CAnimatedVariable size; - CAnimatedVariable pos; + CAnimatedVariable size; + CAnimatedVariable pos; - bool closing = false; + bool closing = false; - HOOK_CALLBACK_FN* mouseMoveHook = nullptr; - HOOK_CALLBACK_FN* mouseButtonHook = nullptr; - HOOK_CALLBACK_FN* touchMoveHook = nullptr; - HOOK_CALLBACK_FN* touchUpHook = nullptr; + std::shared_ptr mouseMoveHook; + std::shared_ptr mouseButtonHook; + std::shared_ptr touchMoveHook; + std::shared_ptr touchUpHook; - bool swipe = false; - bool swipeWasCommenced = false; + bool swipe = false; + bool swipeWasCommenced = false; }; inline std::unique_ptr g_pOverview; \ No newline at end of file diff --git a/hyprtrails/trail.cpp b/hyprtrails/trail.cpp index 47ac6a0..671735d 100644 --- a/hyprtrails/trail.cpp +++ b/hyprtrails/trail.cpp @@ -31,12 +31,12 @@ CTrail::CTrail(CWindow* pWindow) : IHyprWindowDecoration(pWindow), m_pWindow(pWi m_vLastWindowPos = pWindow->m_vRealPosition.value(); m_vLastWindowSize = pWindow->m_vRealSize.value(); - pTickCb = g_pHookSystem->hookDynamic("trailTick", [this](void* self, SCallbackInfo& info, std::any data) { this->onTick(); }); + pTickCb = HyprlandAPI::registerCallbackDynamic(PHANDLE, "trailTick", [this](void* self, SCallbackInfo& info, std::any data) { this->onTick(); }); } CTrail::~CTrail() { damageEntire(); - g_pHookSystem->unhook(pTickCb); + HyprlandAPI::unregisterCallback(PHANDLE, pTickCb); } SDecorationPositioningInfo CTrail::getPositioningInfo() { diff --git a/hyprtrails/trail.hpp b/hyprtrails/trail.hpp index 3a3e18d..501955f 100644 --- a/hyprtrails/trail.hpp +++ b/hyprtrails/trail.hpp @@ -46,7 +46,7 @@ class CTrail : public IHyprWindowDecoration { virtual void damageEntire(); private: - HOOK_CALLBACK_FN* pTickCb = nullptr; + std::shared_ptr pTickCb; void onTick(); std::deque> m_dLastGeoms; diff --git a/hyprwinwrap/main.cpp b/hyprwinwrap/main.cpp index 5c771e9..6cf78aa 100644 --- a/hyprwinwrap/main.cpp +++ b/hyprwinwrap/main.cpp @@ -138,10 +138,12 @@ APICALL EXPORT PLUGIN_DESCRIPTION_INFO PLUGIN_INIT(HANDLE handle) { throw std::runtime_error("[hww] Version mismatch"); } - HyprlandAPI::registerCallbackDynamic(PHANDLE, "openWindow", [&](void* self, SCallbackInfo& info, std::any data) { onNewWindow(std::any_cast(data)); }); - HyprlandAPI::registerCallbackDynamic(PHANDLE, "closeWindow", [&](void* self, SCallbackInfo& info, std::any data) { onCloseWindow(std::any_cast(data)); }); - HyprlandAPI::registerCallbackDynamic(PHANDLE, "render", [&](void* self, SCallbackInfo& info, std::any data) { onRenderStage(std::any_cast(data)); }); - HyprlandAPI::registerCallbackDynamic(PHANDLE, "configReloaded", [&](void* self, SCallbackInfo& info, std::any data) { onConfigReloaded(); }); + // clang-format off + static auto P = HyprlandAPI::registerCallbackDynamic(PHANDLE, "openWindow", [&](void* self, SCallbackInfo& info, std::any data) { onNewWindow(std::any_cast(data)); }); + static auto P2 = HyprlandAPI::registerCallbackDynamic(PHANDLE, "closeWindow", [&](void* self, SCallbackInfo& info, std::any data) { onCloseWindow(std::any_cast(data)); }); + static auto P3 = HyprlandAPI::registerCallbackDynamic(PHANDLE, "render", [&](void* self, SCallbackInfo& info, std::any data) { onRenderStage(std::any_cast(data)); }); + static auto P4 = HyprlandAPI::registerCallbackDynamic(PHANDLE, "configReloaded", [&](void* self, SCallbackInfo& info, std::any data) { onConfigReloaded(); }); + // clang-format on auto fns = HyprlandAPI::findFunctionsByName(PHANDLE, "onCommit"); if (fns.size() < 1)