diff --git a/src/events/Windows.cpp b/src/events/Windows.cpp index 58c55be7..2a553fbd 100644 --- a/src/events/Windows.cpp +++ b/src/events/Windows.cpp @@ -312,7 +312,7 @@ void Events::listener_unmapWindow(void* owner, void* data) { Debug::log(LOG, "Window %x unmapped (class %s)", PWINDOW, g_pXWaylandManager->getAppIDClass(PWINDOW).c_str()); if (!PWINDOW->m_bIsX11) { - Debug::log(LOG, "Unregistered late callbacks XDG: %x %x %x %x", &PWINDOW->hyprListener_commitWindow.m_sListener.link, &PWINDOW->hyprListener_setTitleWindow.m_sListener.link, &PWINDOW->hyprListener_fullscreenWindow.m_sListener.link, &PWINDOW->hyprListener_newPopupXDG.m_sListener.link); + Debug::log(LOG, "Unregistered late callbacks XDG"); PWINDOW->hyprListener_commitWindow.removeCallback(); PWINDOW->hyprListener_setTitleWindow.removeCallback(); PWINDOW->hyprListener_fullscreenWindow.removeCallback(); @@ -322,7 +322,7 @@ void Events::listener_unmapWindow(void* owner, void* data) { PWINDOW->hyprListener_requestMove.removeCallback(); PWINDOW->hyprListener_requestResize.removeCallback(); } else { - Debug::log(LOG, "Unregistered late callbacks XWL: %x %x %x %x", &PWINDOW->hyprListener_fullscreenWindow.m_sListener.link, &PWINDOW->hyprListener_activateX11.m_sListener.link, &PWINDOW->hyprListener_configureX11.m_sListener.link, &PWINDOW->hyprListener_setTitleWindow.m_sListener.link); + Debug::log(LOG, "Unregistered late callbacks XWL"); PWINDOW->hyprListener_fullscreenWindow.removeCallback(); PWINDOW->hyprListener_activateX11.removeCallback(); PWINDOW->hyprListener_configureX11.removeCallback(); diff --git a/src/helpers/SubsurfaceTree.cpp b/src/helpers/SubsurfaceTree.cpp index 376153f5..4f8197f6 100644 --- a/src/helpers/SubsurfaceTree.cpp +++ b/src/helpers/SubsurfaceTree.cpp @@ -21,9 +21,7 @@ void addSurfaceGlobalOffset(SSurfaceTreeNode* node, int* lx, int* ly) { } SSurfaceTreeNode* createTree(wlr_surface* pSurface, CWindow* pWindow) { - SubsurfaceTree::surfaceTreeNodes.push_back(SSurfaceTreeNode()); - - const auto PNODE = &SubsurfaceTree::surfaceTreeNodes.back(); + const auto PNODE = &SubsurfaceTree::surfaceTreeNodes.emplace_back(); PNODE->pSurface = pSurface; PNODE->pWindowOwner = pWindow; @@ -128,8 +126,7 @@ void Events::listener_newSubsurfaceNode(void* owner, void* data) { const auto PSUBSURFACE = (wlr_subsurface*)data; - pNode->childSubsurfaces.push_back(SSubsurface()); - const auto PNEWSUBSURFACE = &pNode->childSubsurfaces.back(); + const auto PNEWSUBSURFACE = &pNode->childSubsurfaces.emplace_back(); Debug::log(LOG, "Added a new subsurface %x", PSUBSURFACE); diff --git a/src/helpers/WLListener.cpp b/src/helpers/WLListener.cpp index d48cce7d..78932a9f 100644 --- a/src/helpers/WLListener.cpp +++ b/src/helpers/WLListener.cpp @@ -4,9 +4,9 @@ #include "../debug/Log.hpp" void handleWrapped(wl_listener* listener, void* data) { - CHyprWLListener* pListener = wl_container_of(listener, pListener, m_sListener); + CHyprWLListener::SWrapper* pWrap = wl_container_of(listener, pWrap, m_sListener); - pListener->emit(data); + pWrap->m_pSelf->emit(data); } CHyprWLListener::CHyprWLListener(wl_signal* pSignal, std::function callback, void* pOwner) { @@ -14,7 +14,9 @@ CHyprWLListener::CHyprWLListener(wl_signal* pSignal, std::function %x, %s removed.", &m_pCallback, &m_pOwner, m_szAuthor.c_str()); - wl_list_remove(&m_sListener.link); - wl_list_init(&m_sListener.link); + wl_list_remove(&m_swWrapper.m_sListener.link); + wl_list_init(&m_swWrapper.m_sListener.link); } - - m_bIsConnected = false; } bool CHyprWLListener::isConnected() { - return m_bIsConnected; + return !wl_list_empty(&m_swWrapper.m_sListener.link); } void CHyprWLListener::initCallback(wl_signal* pSignal, std::function callback, void* pOwner, std::string author) { - if (m_bIsConnected) - removeCallback(); + if (isConnected()) { + Debug::log(ERR, "Tried to connect a listener twice?!"); + return; + } m_pOwner = pOwner; m_pCallback = callback; m_szAuthor = author; - m_sListener.notify = &handleWrapped; - - m_bIsConnected = true; - - wl_list_init(&m_sListener.link); - addWLSignal(pSignal, &m_sListener, pOwner, m_szAuthor); + addWLSignal(pSignal, &m_swWrapper.m_sListener, pOwner, m_szAuthor); } void CHyprWLListener::emit(void* data) { diff --git a/src/helpers/WLListener.hpp b/src/helpers/WLListener.hpp index f8511789..d8d1d7c1 100644 --- a/src/helpers/WLListener.hpp +++ b/src/helpers/WLListener.hpp @@ -9,18 +9,26 @@ public: CHyprWLListener(); ~CHyprWLListener(); + CHyprWLListener(const CHyprWLListener&) = delete; + CHyprWLListener(CHyprWLListener&&) = delete; + CHyprWLListener& operator=(const CHyprWLListener&) = delete; + CHyprWLListener& operator=(CHyprWLListener&&) = delete; + void initCallback(wl_signal*, std::function, void* owner, std::string author = ""); void removeCallback(); bool isConnected(); - wl_listener m_sListener; + struct SWrapper { + wl_listener m_sListener; + CHyprWLListener* m_pSelf; + }; void emit(void*); private: - bool m_bIsConnected = false; + SWrapper m_swWrapper; void* m_pOwner = nullptr;