From 4ad739ec63c9a11f0537a884ae2a4c56d6bab10b Mon Sep 17 00:00:00 2001 From: Vaxry Date: Sat, 20 Apr 2024 20:16:42 +0100 Subject: HookSystem: improve callback safety --- src/protocols/Screencopy.hpp | 22 +++++++++++----------- src/protocols/TearingControl.cpp | 2 +- src/protocols/XDGOutput.cpp | 6 +++--- 3 files changed, 15 insertions(+), 15 deletions(-) (limited to 'src/protocols') diff --git a/src/protocols/Screencopy.hpp b/src/protocols/Screencopy.hpp index 0c709c7b..8facc53e 100644 --- a/src/protocols/Screencopy.hpp +++ b/src/protocols/Screencopy.hpp @@ -20,21 +20,21 @@ class CScreencopyClient { CScreencopyClient(); ~CScreencopyClient(); - int ref = 0; - wl_resource* resource = nullptr; + int ref = 0; + wl_resource* resource = nullptr; - eClientOwners clientOwner = CLIENT_SCREENCOPY; + eClientOwners clientOwner = CLIENT_SCREENCOPY; - int frameCounter = 0; - int framesInLastHalfSecond = 0; - CTimer lastMeasure; - CTimer lastFrame; - bool sentScreencast = false; + int frameCounter = 0; + int framesInLastHalfSecond = 0; + CTimer lastMeasure; + CTimer lastFrame; + bool sentScreencast = false; - void onTick(); - HOOK_CALLBACK_FN* tickCallback = nullptr; + void onTick(); + std::shared_ptr tickCallback; - bool operator==(const CScreencopyClient& other) const { + bool operator==(const CScreencopyClient& other) const { return resource == other.resource; } }; diff --git a/src/protocols/TearingControl.cpp b/src/protocols/TearingControl.cpp index 679f2404..21d37e3c 100644 --- a/src/protocols/TearingControl.cpp +++ b/src/protocols/TearingControl.cpp @@ -4,7 +4,7 @@ #include "../Compositor.hpp" CTearingControlProtocol::CTearingControlProtocol(const wl_interface* iface, const int& ver, const std::string& name) : IWaylandProtocol(iface, ver, name) { - g_pHookSystem->hookDynamic("destroyWindow", [this](void* self, SCallbackInfo& info, std::any param) { this->onWindowDestroy(std::any_cast(param)); }); + static auto P = g_pHookSystem->hookDynamic("destroyWindow", [this](void* self, SCallbackInfo& info, std::any param) { this->onWindowDestroy(std::any_cast(param)); }); } void CTearingControlProtocol::bindManager(wl_client* client, void* data, uint32_t ver, uint32_t id) { diff --git a/src/protocols/XDGOutput.cpp b/src/protocols/XDGOutput.cpp index 265b88ed..551d9d90 100644 --- a/src/protocols/XDGOutput.cpp +++ b/src/protocols/XDGOutput.cpp @@ -33,9 +33,9 @@ void CXDGOutputProtocol::bindManager(wl_client* client, void* data, uint32_t ver } CXDGOutputProtocol::CXDGOutputProtocol(const wl_interface* iface, const int& ver, const std::string& name) : IWaylandProtocol(iface, ver, name) { - g_pHookSystem->hookDynamic("monitorLayoutChanged", [this](void* self, SCallbackInfo& info, std::any param) { this->updateAllOutputs(); }); - g_pHookSystem->hookDynamic("configReloaded", [this](void* self, SCallbackInfo& info, std::any param) { this->updateAllOutputs(); }); - g_pHookSystem->hookDynamic("monitorRemoved", [this](void* self, SCallbackInfo& info, std::any param) { + static auto P = g_pHookSystem->hookDynamic("monitorLayoutChanged", [this](void* self, SCallbackInfo& info, std::any param) { this->updateAllOutputs(); }); + static auto P2 = g_pHookSystem->hookDynamic("configReloaded", [this](void* self, SCallbackInfo& info, std::any param) { this->updateAllOutputs(); }); + static auto P3 = g_pHookSystem->hookDynamic("monitorRemoved", [this](void* self, SCallbackInfo& info, std::any param) { const auto PMONITOR = std::any_cast(param); for (auto& o : m_vXDGOutputs) { if (o->monitor == PMONITOR) -- cgit v1.2.3