🎉 Wrapped dynamic event handlers
This commit is contained in:
parent
000b16585f
commit
ad4fc28f78
12 changed files with 243 additions and 175 deletions
|
|
@ -26,13 +26,9 @@ SSurfaceTreeNode* createTree(wlr_surface* pSurface) {
|
|||
|
||||
PNODE->pSurface = pSurface;
|
||||
|
||||
PNODE->listen_newSubsurface.notify = Events::listener_newSubsurfaceNode;
|
||||
PNODE->listen_commit.notify = Events::listener_commitSubsurface;
|
||||
PNODE->listen_destroy.notify = Events::listener_destroySubsurfaceNode;
|
||||
|
||||
addWLSignal(&pSurface->events.commit, &PNODE->listen_commit, PNODE, "SurfaceTreeNode");
|
||||
addWLSignal(&pSurface->events.destroy, &PNODE->listen_destroy, PNODE, "SurfaceTreeNode");
|
||||
addWLSignal(&pSurface->events.new_subsurface, &PNODE->listen_newSubsurface, PNODE, "SurfaceTreeNode");
|
||||
PNODE->hyprListener_newSubsurface.initCallback(&pSurface->events.new_subsurface, &Events::listener_newSubsurfaceNode, PNODE, "SurfaceTreeNode");
|
||||
PNODE->hyprListener_commit.initCallback(&pSurface->events.commit, &Events::listener_commitSubsurface, PNODE, "SurfaceTreeNode");
|
||||
PNODE->hyprListener_destroy.initCallback(&pSurface->events.destroy, &Events::listener_destroySubsurfaceNode, PNODE, "SurfaceTreeNode");
|
||||
|
||||
return PNODE;
|
||||
}
|
||||
|
|
@ -75,9 +71,9 @@ void SubsurfaceTree::destroySurfaceTree(SSurfaceTreeNode* pNode) {
|
|||
|
||||
pNode->childSubsurfaces.clear();
|
||||
|
||||
wl_list_remove(&pNode->listen_newSubsurface.link);
|
||||
wl_list_remove(&pNode->listen_commit.link);
|
||||
wl_list_remove(&pNode->listen_destroy.link);
|
||||
pNode->hyprListener_commit.removeCallback();
|
||||
pNode->hyprListener_destroy.removeCallback();
|
||||
pNode->hyprListener_newSubsurface.removeCallback();
|
||||
|
||||
Debug::log(LOG, "SurfaceTree Node removed");
|
||||
}
|
||||
|
|
@ -88,17 +84,17 @@ void destroySubsurface(SSubsurface* pSubsurface) {
|
|||
pSubsurface->pChild = nullptr;
|
||||
}
|
||||
|
||||
wl_list_remove(&pSubsurface->listen_map.link);
|
||||
wl_list_remove(&pSubsurface->listen_unmap.link);
|
||||
wl_list_remove(&pSubsurface->listen_destroy.link);
|
||||
pSubsurface->hyprListener_destroy.removeCallback();
|
||||
pSubsurface->hyprListener_map.removeCallback();
|
||||
pSubsurface->hyprListener_unmap.removeCallback();
|
||||
}
|
||||
|
||||
//
|
||||
// Subsurface listeners
|
||||
//
|
||||
|
||||
void Events::listener_newSubsurfaceNode(wl_listener* listener, void* data) {
|
||||
SSurfaceTreeNode* pNode = wl_container_of(listener, pNode, listen_newSubsurface);
|
||||
void Events::listener_newSubsurfaceNode(void* owner, void* data) {
|
||||
SSurfaceTreeNode* pNode = (SSurfaceTreeNode*)owner;
|
||||
|
||||
const auto PSUBSURFACE = (wlr_subsurface*)data;
|
||||
|
||||
|
|
@ -110,25 +106,21 @@ void Events::listener_newSubsurfaceNode(wl_listener* listener, void* data) {
|
|||
PNEWSUBSURFACE->pSubsurface = PSUBSURFACE;
|
||||
PNEWSUBSURFACE->pParent = pNode;
|
||||
|
||||
PNEWSUBSURFACE->listen_map.notify = Events::listener_mapSubsurface;
|
||||
PNEWSUBSURFACE->listen_unmap.notify = Events::listener_unmapSubsurface;
|
||||
PNEWSUBSURFACE->listen_destroy.notify = Events::listener_destroySubsurface;
|
||||
|
||||
addWLSignal(&PSUBSURFACE->events.map, &PNEWSUBSURFACE->listen_map, PNEWSUBSURFACE, "Subsurface");
|
||||
addWLSignal(&PSUBSURFACE->events.unmap, &PNEWSUBSURFACE->listen_unmap, PNEWSUBSURFACE, "Subsurface");
|
||||
addWLSignal(&PSUBSURFACE->events.destroy, &PNEWSUBSURFACE->listen_destroy, PNEWSUBSURFACE, "Subsurface");
|
||||
PNEWSUBSURFACE->hyprListener_map.initCallback(&PSUBSURFACE->events.map, &Events::listener_mapSubsurface, PNEWSUBSURFACE, "Subsurface");
|
||||
PNEWSUBSURFACE->hyprListener_unmap.initCallback(&PSUBSURFACE->events.unmap, &Events::listener_unmapLayerSurface, PNEWSUBSURFACE, "Subsurface");
|
||||
PNEWSUBSURFACE->hyprListener_destroy.initCallback(&PSUBSURFACE->events.destroy, &Events::listener_destroySubsurface, PNEWSUBSURFACE, "Subsurface");
|
||||
}
|
||||
|
||||
void Events::listener_mapSubsurface(wl_listener* listener, void* data) {
|
||||
SSubsurface* subsurface = wl_container_of(listener, subsurface, listen_map);
|
||||
void Events::listener_mapSubsurface(void* owner, void* data) {
|
||||
SSubsurface* subsurface = (SSubsurface*)owner;
|
||||
|
||||
Debug::log(LOG, "Subsurface %x mapped", subsurface->pSubsurface);
|
||||
|
||||
subsurface->pChild = createSubsurfaceNode(subsurface->pParent, subsurface, subsurface->pSubsurface->surface);
|
||||
}
|
||||
|
||||
void Events::listener_unmapSubsurface(wl_listener* listener, void* data) {
|
||||
SSubsurface* subsurface = wl_container_of(listener, subsurface, listen_unmap);
|
||||
void Events::listener_unmapSubsurface(void* owner, void* data) {
|
||||
SSubsurface* subsurface = (SSubsurface*)owner;
|
||||
|
||||
Debug::log(LOG, "Subsurface %x unmapped", subsurface);
|
||||
|
||||
|
|
@ -149,29 +141,29 @@ void Events::listener_unmapSubsurface(wl_listener* listener, void* data) {
|
|||
}
|
||||
}
|
||||
|
||||
void Events::listener_commitSubsurface(wl_listener* listener, void* data) {
|
||||
SSurfaceTreeNode* pNode = wl_container_of(listener, pNode, listen_commit);
|
||||
void Events::listener_commitSubsurface(void* owner, void* data) {
|
||||
SSurfaceTreeNode* pNode = (SSurfaceTreeNode*)owner;
|
||||
}
|
||||
|
||||
void Events::listener_destroySubsurface(wl_listener* listener, void* data) {
|
||||
SSubsurface* subsurface = wl_container_of(listener, subsurface, listen_destroy);
|
||||
void Events::listener_destroySubsurface(void* owner, void* data) {
|
||||
SSubsurface* subsurface = (SSubsurface*)owner;
|
||||
|
||||
Debug::log(LOG, "Subsurface %x destroyed", subsurface);
|
||||
|
||||
subsurface->pParent->childSubsurfaces.remove(*subsurface);
|
||||
}
|
||||
|
||||
void Events::listener_destroySubsurfaceNode(wl_listener* listener, void* data) {
|
||||
SSurfaceTreeNode* pNode = wl_container_of(listener, pNode, listen_destroy);
|
||||
void Events::listener_destroySubsurfaceNode(void* owner, void* data) {
|
||||
SSurfaceTreeNode* pNode = (SSurfaceTreeNode*)owner;
|
||||
|
||||
Debug::log(LOG, "Subsurface Node %x destroyed", pNode);
|
||||
|
||||
for (auto& c : pNode->childSubsurfaces)
|
||||
destroySubsurface(&c);
|
||||
|
||||
wl_list_remove(&pNode->listen_newSubsurface.link);
|
||||
wl_list_remove(&pNode->listen_commit.link);
|
||||
wl_list_remove(&pNode->listen_destroy.link);
|
||||
pNode->hyprListener_commit.removeCallback();
|
||||
pNode->hyprListener_newSubsurface.removeCallback();
|
||||
pNode->hyprListener_destroy.removeCallback();
|
||||
|
||||
SubsurfaceTree::surfaceTreeNodes.remove(*pNode);
|
||||
}
|
||||
|
|
|
|||
|
|
@ -10,9 +10,9 @@ typedef void (*applyGlobalOffsetFn)(void *, int *, int *);
|
|||
struct SSurfaceTreeNode {
|
||||
wlr_surface* pSurface = nullptr;
|
||||
|
||||
DYNMULTILISTENER(newSubsurface);
|
||||
DYNMULTILISTENER(commit);
|
||||
DYNMULTILISTENER(destroy);
|
||||
DYNLISTENER(newSubsurface);
|
||||
DYNLISTENER(commit);
|
||||
DYNLISTENER(destroy);
|
||||
|
||||
SSurfaceTreeNode* pParent = nullptr;
|
||||
SSubsurface* pSubsurface = nullptr;
|
||||
|
|
@ -33,9 +33,9 @@ struct SSubsurface {
|
|||
SSurfaceTreeNode* pParent = nullptr;
|
||||
SSurfaceTreeNode* pChild = nullptr;
|
||||
|
||||
DYNMULTILISTENER(map);
|
||||
DYNMULTILISTENER(unmap);
|
||||
DYNMULTILISTENER(destroy);
|
||||
DYNLISTENER(map);
|
||||
DYNLISTENER(unmap);
|
||||
DYNLISTENER(destroy);
|
||||
|
||||
bool operator==(const SSubsurface& rhs) {
|
||||
return pSubsurface == rhs.pSubsurface;
|
||||
|
|
|
|||
50
src/helpers/WLListener.cpp
Normal file
50
src/helpers/WLListener.cpp
Normal file
|
|
@ -0,0 +1,50 @@
|
|||
#include "WLListener.hpp"
|
||||
#include "MiscFunctions.hpp"
|
||||
#include <string>
|
||||
|
||||
void handleWrapped(wl_listener* listener, void* data) {
|
||||
CHyprWLListener* pListener = wl_container_of(listener, pListener, m_sListener);
|
||||
|
||||
pListener->emit(data);
|
||||
}
|
||||
|
||||
CHyprWLListener::CHyprWLListener(wl_signal* pSignal, std::function<void(void*, void*)> callback, void* pOwner) {
|
||||
initCallback(pSignal, callback, pOwner);
|
||||
}
|
||||
|
||||
CHyprWLListener::CHyprWLListener() {
|
||||
; //
|
||||
}
|
||||
|
||||
CHyprWLListener::~CHyprWLListener() {
|
||||
removeCallback();
|
||||
}
|
||||
|
||||
void CHyprWLListener::removeCallback() {
|
||||
if (m_bIsConnected) {
|
||||
wl_list_remove(&m_sListener.link);
|
||||
wl_list_init(&m_sListener.link);
|
||||
}
|
||||
|
||||
m_bIsConnected = false;
|
||||
}
|
||||
|
||||
bool CHyprWLListener::isConnected() {
|
||||
return m_bIsConnected;
|
||||
}
|
||||
|
||||
void CHyprWLListener::initCallback(wl_signal* pSignal, std::function<void(void*, void*)> callback, void* pOwner, std::string author) {
|
||||
m_pOwner = pOwner;
|
||||
m_pCallback = callback;
|
||||
m_szAuthor = author;
|
||||
|
||||
m_sListener.notify = &handleWrapped;
|
||||
|
||||
m_bIsConnected = true;
|
||||
|
||||
addWLSignal(pSignal, &m_sListener, pOwner, m_szAuthor);
|
||||
}
|
||||
|
||||
void CHyprWLListener::emit(void* data) {
|
||||
m_pCallback(m_pOwner, data);
|
||||
}
|
||||
30
src/helpers/WLListener.hpp
Normal file
30
src/helpers/WLListener.hpp
Normal file
|
|
@ -0,0 +1,30 @@
|
|||
#pragma once
|
||||
|
||||
#include "../includes.hpp"
|
||||
#include <functional>
|
||||
|
||||
class CHyprWLListener {
|
||||
public:
|
||||
CHyprWLListener(wl_signal*, std::function<void(void*, void*)>, void* owner);
|
||||
CHyprWLListener();
|
||||
~CHyprWLListener();
|
||||
|
||||
void initCallback(wl_signal*, std::function<void(void*, void*)>, void* owner, std::string author = "");
|
||||
|
||||
void removeCallback();
|
||||
|
||||
bool isConnected();
|
||||
|
||||
wl_listener m_sListener;
|
||||
|
||||
void emit(void*);
|
||||
|
||||
private:
|
||||
bool m_bIsConnected = false;
|
||||
|
||||
void* m_pOwner = nullptr;
|
||||
|
||||
std::function<void(void*, void*)> m_pCallback = nullptr;
|
||||
|
||||
std::string m_szAuthor = "";
|
||||
};
|
||||
Loading…
Add table
Add a link
Reference in a new issue