🎉 Wrapped dynamic event handlers

This commit is contained in:
vaxerski 2022-03-28 22:31:39 +02:00
parent 000b16585f
commit ad4fc28f78
12 changed files with 243 additions and 175 deletions

View file

@ -1,6 +1,7 @@
#include "includes.hpp" #include "includes.hpp"
#include "debug/Log.hpp" #include "debug/Log.hpp"
#include "helpers/MiscFunctions.hpp" #include "helpers/MiscFunctions.hpp"
#include "helpers/WLListener.hpp"
#ifndef NDEBUG #ifndef NDEBUG
#define ISDEBUG true #define ISDEBUG true
@ -11,7 +12,8 @@
#define RIP(format, ... ) { fprintf(stderr, format "\n", ##__VA_ARGS__); exit(EXIT_FAILURE); } #define RIP(format, ... ) { fprintf(stderr, format "\n", ##__VA_ARGS__); exit(EXIT_FAILURE); }
#define LISTENER(name) void listener_##name(wl_listener*, void*); inline wl_listener listen_##name = { .notify = listener_##name }; #define LISTENER(name) void listener_##name(wl_listener*, void*); inline wl_listener listen_##name = { .notify = listener_##name };
#define DYNLISTENER(name) wl_listener listen_##name = { .notify = Events::listener_##name }; #define DYNLISTENFUNC(name) void listener_##name(void*, void*);
#define DYNLISTENER(name) CHyprWLListener hyprListener_##name;
#define DYNMULTILISTENER(name) wl_listener listen_##name; #define DYNMULTILISTENER(name) wl_listener listen_##name;
#define VECINRECT(vec, x1, y1, x2, y2) (vec.x >= (x1) && vec.x <= (x2) && vec.y >= (y1) && vec.y <= (y2)) #define VECINRECT(vec, x1, y1, x2, y2) (vec.x >= (x1) && vec.x <= (x2) && vec.y >= (y1) && vec.y <= (y2))

View file

@ -15,20 +15,20 @@
// // // //
// ---------------------------------------------------- // // ---------------------------------------------------- //
void Events::listener_keyboardDestroy(wl_listener* listener, void* data) { void Events::listener_keyboardDestroy(void* owner, void* data) {
SKeyboard* PKEYBOARD = wl_container_of(listener, PKEYBOARD, listen_keyboardDestroy); SKeyboard* PKEYBOARD = (SKeyboard*)owner;
g_pInputManager->destroyKeyboard(PKEYBOARD); g_pInputManager->destroyKeyboard(PKEYBOARD);
Debug::log(LOG, "Destroyed keyboard %x", PKEYBOARD); Debug::log(LOG, "Destroyed keyboard %x", PKEYBOARD);
} }
void Events::listener_keyboardKey(wl_listener* listener, void* data) { void Events::listener_keyboardKey(void* owner, void* data) {
SKeyboard* PKEYBOARD = wl_container_of(listener, PKEYBOARD, listen_keyboardKey); SKeyboard* PKEYBOARD = (SKeyboard*)owner;
g_pInputManager->onKeyboardKey((wlr_keyboard_key_event*)data, PKEYBOARD); g_pInputManager->onKeyboardKey((wlr_keyboard_key_event*)data, PKEYBOARD);
} }
void Events::listener_keyboardMod(wl_listener* listener, void* data) { void Events::listener_keyboardMod(void* owner, void* data) {
SKeyboard* PKEYBOARD = wl_container_of(listener, PKEYBOARD, listen_keyboardMod); SKeyboard* PKEYBOARD = (SKeyboard*)owner;
g_pInputManager->onKeyboardMod(data, PKEYBOARD); g_pInputManager->onKeyboardMod(data, PKEYBOARD);
} }

View file

@ -14,41 +14,41 @@ namespace Events {
// Layer events // Layer events
LISTENER(newLayerSurface); LISTENER(newLayerSurface);
LISTENER(destroyLayerSurface); DYNLISTENFUNC(destroyLayerSurface);
LISTENER(mapLayerSurface); DYNLISTENFUNC(mapLayerSurface);
LISTENER(unmapLayerSurface); DYNLISTENFUNC(unmapLayerSurface);
LISTENER(commitLayerSurface); DYNLISTENFUNC(commitLayerSurface);
// Subsurfaces // Subsurfaces
LISTENER(newSubsurfaceNode); DYNLISTENFUNC(newSubsurfaceNode);
LISTENER(destroySubsurfaceNode); DYNLISTENFUNC(destroySubsurfaceNode);
LISTENER(mapSubsurface); DYNLISTENFUNC(mapSubsurface);
LISTENER(unmapSubsurface); DYNLISTENFUNC(unmapSubsurface);
LISTENER(destroySubsurface); DYNLISTENFUNC(destroySubsurface);
LISTENER(commitSubsurface); DYNLISTENFUNC(commitSubsurface);
// Popups // Popups
LISTENER(newPopup); // LayerSurface DYNLISTENFUNC(newPopup); // LayerSurface
LISTENER(newPopupXDG); DYNLISTENFUNC(newPopupXDG);
LISTENER(mapPopupXDG); DYNLISTENFUNC(mapPopupXDG);
LISTENER(unmapPopupXDG); DYNLISTENFUNC(unmapPopupXDG);
LISTENER(destroyPopupXDG); DYNLISTENFUNC(destroyPopupXDG);
LISTENER(commitPopupXDG); DYNLISTENFUNC(commitPopupXDG);
LISTENER(newPopupFromPopupXDG); DYNLISTENFUNC(newPopupFromPopupXDG);
// Surface XDG (window) // Surface XDG (window)
LISTENER(newXDGSurface); LISTENER(newXDGSurface);
// Window events // Window events
LISTENER(commitWindow); DYNLISTENFUNC(commitWindow);
LISTENER(mapWindow); DYNLISTENFUNC(mapWindow);
LISTENER(unmapWindow); DYNLISTENFUNC(unmapWindow);
LISTENER(destroyWindow); DYNLISTENFUNC(destroyWindow);
LISTENER(setTitleWindow); DYNLISTENFUNC(setTitleWindow);
LISTENER(fullscreenWindow); DYNLISTENFUNC(fullscreenWindow);
LISTENER(activateX11); DYNLISTENFUNC(activateX11);
LISTENER(configureX11); DYNLISTENFUNC(configureX11);
// Window subsurfaces // Window subsurfaces
// LISTENER(newSubsurfaceWindow); // LISTENER(newSubsurfaceWindow);
@ -62,23 +62,23 @@ namespace Events {
LISTENER(newInput); LISTENER(newInput);
LISTENER(keyboardKey); DYNLISTENFUNC(keyboardKey);
LISTENER(keyboardMod); DYNLISTENFUNC(keyboardMod);
LISTENER(keyboardDestroy); DYNLISTENFUNC(keyboardDestroy);
// Various // Various
LISTENER(requestMouse); LISTENER(requestMouse);
LISTENER(requestSetSel); LISTENER(requestSetSel);
LISTENER(requestSetPrimarySel); LISTENER(requestSetPrimarySel);
LISTENER(activate); DYNLISTENFUNC(activate);
// outputMgr // outputMgr
LISTENER(outputMgrApply); LISTENER(outputMgrApply);
LISTENER(outputMgrTest); LISTENER(outputMgrTest);
// Monitor part 2 the sequel // Monitor part 2 the sequel
LISTENER(monitorFrame); DYNLISTENFUNC(monitorFrame);
LISTENER(monitorDestroy); DYNLISTENFUNC(monitorDestroy);
// XWayland // XWayland
LISTENER(readyXWayland); LISTENER(readyXWayland);

View file

@ -39,11 +39,11 @@ void Events::listener_newLayerSurface(wl_listener* listener, void* data) {
WLRLAYERSURFACE->output = g_pCompositor->m_lMonitors.front().output; // TODO: current mon WLRLAYERSURFACE->output = g_pCompositor->m_lMonitors.front().output; // TODO: current mon
} }
addWLSignal(&WLRLAYERSURFACE->surface->events.commit, &layerSurface->listen_commitLayerSurface, layerSurface, "layerSurface"); layerSurface->hyprListener_commitLayerSurface.initCallback(&WLRLAYERSURFACE->surface->events.commit, &Events::listener_commitLayerSurface, layerSurface, "layerSurface");
addWLSignal(&WLRLAYERSURFACE->surface->events.destroy, &layerSurface->listen_destroyLayerSurface, layerSurface, "layerSurface"); layerSurface->hyprListener_destroyLayerSurface.initCallback(&WLRLAYERSURFACE->surface->events.destroy, &Events::listener_destroyLayerSurface, layerSurface, "layerSurface");
addWLSignal(&WLRLAYERSURFACE->events.map, &layerSurface->listen_mapLayerSurface, layerSurface, "layerSurface"); layerSurface->hyprListener_mapLayerSurface.initCallback(&WLRLAYERSURFACE->events.map, &Events::listener_mapLayerSurface, layerSurface, "layerSurface");
addWLSignal(&WLRLAYERSURFACE->events.unmap, &layerSurface->listen_unmapLayerSurface, layerSurface, "layerSurface"); layerSurface->hyprListener_unmapLayerSurface.initCallback(&WLRLAYERSURFACE->events.unmap, &Events::listener_unmapLayerSurface, layerSurface, "layerSurface");
addWLSignal(&WLRLAYERSURFACE->events.new_popup, &layerSurface->listen_newPopup, layerSurface, "layerSurface"); layerSurface->hyprListener_newPopup.initCallback(&WLRLAYERSURFACE->events.new_popup, &Events::listener_newPopup, layerSurface, "layerSurface");
layerSurface->layerSurface = WLRLAYERSURFACE; layerSurface->layerSurface = WLRLAYERSURFACE;
layerSurface->layer = WLRLAYERSURFACE->current.layer; layerSurface->layer = WLRLAYERSURFACE->current.layer;
@ -53,8 +53,8 @@ void Events::listener_newLayerSurface(wl_listener* listener, void* data) {
Debug::log(LOG, "LayerSurface %x (namespace %s layer %d) created on monitor %s", layerSurface->layerSurface, layerSurface->layerSurface->_namespace, layerSurface->layer, PMONITOR->szName.c_str()); Debug::log(LOG, "LayerSurface %x (namespace %s layer %d) created on monitor %s", layerSurface->layerSurface, layerSurface->layerSurface->_namespace, layerSurface->layer, PMONITOR->szName.c_str());
} }
void Events::listener_destroyLayerSurface(wl_listener* listener, void* data) { void Events::listener_destroyLayerSurface(void* owner, void* data) {
SLayerSurface* layersurface = wl_container_of(listener, layersurface, listen_destroyLayerSurface); SLayerSurface* layersurface = (SLayerSurface*)owner;
Debug::log(LOG, "LayerSurface %x destroyed", layersurface->layerSurface); Debug::log(LOG, "LayerSurface %x destroyed", layersurface->layerSurface);
@ -64,10 +64,11 @@ void Events::listener_destroyLayerSurface(wl_listener* listener, void* data) {
if (layersurface->layerSurface->surface == g_pCompositor->m_pLastFocus) if (layersurface->layerSurface->surface == g_pCompositor->m_pLastFocus)
g_pCompositor->m_pLastFocus = nullptr; g_pCompositor->m_pLastFocus = nullptr;
wl_list_remove(&layersurface->listen_destroyLayerSurface.link); layersurface->hyprListener_commitLayerSurface.removeCallback();
wl_list_remove(&layersurface->listen_mapLayerSurface.link); layersurface->hyprListener_destroyLayerSurface.removeCallback();
wl_list_remove(&layersurface->listen_unmapLayerSurface.link); layersurface->hyprListener_mapLayerSurface.removeCallback();
wl_list_remove(&layersurface->listen_commitLayerSurface.link); layersurface->hyprListener_unmapLayerSurface.removeCallback();
layersurface->hyprListener_newPopup.removeCallback();
const auto PMONITOR = g_pCompositor->getMonitorFromID(layersurface->monitorID); const auto PMONITOR = g_pCompositor->getMonitorFromID(layersurface->monitorID);
@ -82,8 +83,8 @@ void Events::listener_destroyLayerSurface(wl_listener* listener, void* data) {
} }
} }
void Events::listener_mapLayerSurface(wl_listener* listener, void* data) { void Events::listener_mapLayerSurface(void* owner, void* data) {
SLayerSurface* layersurface = wl_container_of(listener, layersurface, listen_mapLayerSurface); SLayerSurface* layersurface = (SLayerSurface*)owner;
Debug::log(LOG, "LayerSurface %x mapped", layersurface->layerSurface); Debug::log(LOG, "LayerSurface %x mapped", layersurface->layerSurface);
@ -111,8 +112,8 @@ void Events::listener_mapLayerSurface(wl_listener* listener, void* data) {
layersurface->position = Vector2D(layersurface->geometry.x, layersurface->geometry.y); layersurface->position = Vector2D(layersurface->geometry.x, layersurface->geometry.y);
} }
void Events::listener_unmapLayerSurface(wl_listener* listener, void* data) { void Events::listener_unmapLayerSurface(void* owner, void* data) {
SLayerSurface* layersurface = wl_container_of(listener, layersurface, listen_unmapLayerSurface); SLayerSurface* layersurface = (SLayerSurface*)owner;
Debug::log(LOG, "LayerSurface %x unmapped", layersurface->layerSurface); Debug::log(LOG, "LayerSurface %x unmapped", layersurface->layerSurface);
@ -123,8 +124,8 @@ void Events::listener_unmapLayerSurface(wl_listener* listener, void* data) {
g_pCompositor->m_pLastFocus = nullptr; g_pCompositor->m_pLastFocus = nullptr;
} }
void Events::listener_commitLayerSurface(wl_listener* listener, void* data) { void Events::listener_commitLayerSurface(void* owner, void* data) {
SLayerSurface* layersurface = wl_container_of(listener, layersurface, listen_commitLayerSurface); SLayerSurface* layersurface = (SLayerSurface*)owner;
if (!layersurface->layerSurface || !layersurface->layerSurface->output) if (!layersurface->layerSurface || !layersurface->layerSurface->output)
return; return;

View file

@ -79,8 +79,8 @@ void Events::listener_newOutput(wl_listener* listener, void* data) {
g_pCompositor->m_lMonitors.push_back(newMonitor); g_pCompositor->m_lMonitors.push_back(newMonitor);
// //
addWLSignal(&OUTPUT->events.frame, &g_pCompositor->m_lMonitors.back().listen_monitorFrame, &g_pCompositor->m_lMonitors.back(), "Monitor"); g_pCompositor->m_lMonitors.back().hyprListener_monitorFrame.initCallback(&OUTPUT->events.frame, &Events::listener_monitorFrame, &g_pCompositor->m_lMonitors.back());
addWLSignal(&OUTPUT->events.destroy, &g_pCompositor->m_lMonitors.back().listen_monitorDestroy, &g_pCompositor->m_lMonitors.back(), "Monitor"); g_pCompositor->m_lMonitors.back().hyprListener_monitorDestroy.initCallback(&OUTPUT->events.destroy, &Events::listener_monitorDestroy, &g_pCompositor->m_lMonitors.back());
wlr_output_enable(OUTPUT, 1); wlr_output_enable(OUTPUT, 1);
if (!wlr_output_commit(OUTPUT)) { if (!wlr_output_commit(OUTPUT)) {
@ -95,8 +95,8 @@ void Events::listener_newOutput(wl_listener* listener, void* data) {
Debug::log(LOG, "Added new monitor with name %s at %i,%i with size %ix%i@%i, pointer %x", OUTPUT->name, (int)monitorRule.offset.x, (int)monitorRule.offset.y, (int)monitorRule.resolution.x, (int)monitorRule.resolution.y, (int)monitorRule.refreshRate, OUTPUT); Debug::log(LOG, "Added new monitor with name %s at %i,%i with size %ix%i@%i, pointer %x", OUTPUT->name, (int)monitorRule.offset.x, (int)monitorRule.offset.y, (int)monitorRule.resolution.x, (int)monitorRule.resolution.y, (int)monitorRule.refreshRate, OUTPUT);
} }
void Events::listener_monitorFrame(wl_listener* listener, void* data) { void Events::listener_monitorFrame(void* owner, void* data) {
SMonitor* const PMONITOR = wl_container_of(listener, PMONITOR, listen_monitorFrame); SMonitor* const PMONITOR = (SMonitor*)owner;
// Hack: only check when monitor number 1 refreshes, saves a bit of resources. // Hack: only check when monitor number 1 refreshes, saves a bit of resources.
// This is for stuff that should be run every frame // This is for stuff that should be run every frame
@ -125,7 +125,7 @@ void Events::listener_monitorFrame(wl_listener* listener, void* data) {
wlr_output_commit(PMONITOR->output); wlr_output_commit(PMONITOR->output);
} }
void Events::listener_monitorDestroy(wl_listener* listener, void* data) { void Events::listener_monitorDestroy(void* owner, void* data) {
const auto OUTPUT = (wlr_output*)data; const auto OUTPUT = (wlr_output*)data;
SMonitor* pMonitor = nullptr; SMonitor* pMonitor = nullptr;

View file

@ -43,15 +43,10 @@ void addPopupGlobalCoords(void* pPopup, int* x, int* y) {
void createNewPopup(wlr_xdg_popup* popup, SXDGPopup* pHyprPopup) { void createNewPopup(wlr_xdg_popup* popup, SXDGPopup* pHyprPopup) {
pHyprPopup->popup = popup; pHyprPopup->popup = popup;
pHyprPopup->listen_mapPopupXDG.notify = Events::listener_mapPopupXDG; pHyprPopup->hyprListener_destroyPopupXDG.initCallback(&popup->base->surface->events.destroy, &Events::listener_destroyPopupXDG, pHyprPopup, "HyprPopup");
pHyprPopup->listen_unmapPopupXDG.notify = Events::listener_unmapPopupXDG; pHyprPopup->hyprListener_mapPopupXDG.initCallback(&popup->base->events.map, &Events::listener_mapPopupXDG, pHyprPopup, "HyprPopup");
pHyprPopup->listen_destroyPopupXDG.notify = Events::listener_destroyPopupXDG; pHyprPopup->hyprListener_unmapPopupXDG.initCallback(&popup->base->events.unmap, &Events::listener_unmapPopupXDG, pHyprPopup, "HyprPopup");
pHyprPopup->listen_newPopupFromPopupXDG.notify = Events::listener_newPopupXDG; pHyprPopup->hyprListener_newPopupFromPopupXDG.initCallback(&popup->base->events.new_popup, &Events::listener_newPopupFromPopupXDG, pHyprPopup, "HyprPopup");
addWLSignal(&popup->base->events.map, &pHyprPopup->listen_mapPopupXDG, pHyprPopup, "HyprPopup");
addWLSignal(&popup->base->events.unmap, &pHyprPopup->listen_unmapPopupXDG, pHyprPopup, "HyprPopup");
addWLSignal(&popup->base->surface->events.destroy, &pHyprPopup->listen_destroyPopupXDG, pHyprPopup, "HyprPopup");
addWLSignal(&popup->base->events.new_popup, &pHyprPopup->listen_newPopupFromPopupXDG, pHyprPopup, "HyprPopup");
const auto PMONITOR = g_pCompositor->m_pLastMonitor; const auto PMONITOR = g_pCompositor->m_pLastMonitor;
@ -60,8 +55,8 @@ void createNewPopup(wlr_xdg_popup* popup, SXDGPopup* pHyprPopup) {
wlr_xdg_popup_unconstrain_from_box(popup, &box); wlr_xdg_popup_unconstrain_from_box(popup, &box);
} }
void Events::listener_newPopup(wl_listener* listener, void* data) { void Events::listener_newPopup(void* owner, void* data) {
SLayerSurface* layersurface = wl_container_of(listener, layersurface, listen_newPopup); SLayerSurface* layersurface = (SLayerSurface*)owner;
Debug::log(LOG, "New layer popup created from surface %x", layersurface); Debug::log(LOG, "New layer popup created from surface %x", layersurface);
@ -76,8 +71,8 @@ void Events::listener_newPopup(wl_listener* listener, void* data) {
createNewPopup(WLRPOPUP, PNEWPOPUP); createNewPopup(WLRPOPUP, PNEWPOPUP);
} }
void Events::listener_newPopupXDG(wl_listener* listener, void* data) { void Events::listener_newPopupXDG(void* owner, void* data) {
CWindow* PWINDOW = wl_container_of(listener, PWINDOW, listen_newPopupXDG); CWindow* PWINDOW = (CWindow*)owner;
Debug::log(LOG, "New layer popup created from XDG window %x -> %s", PWINDOW, PWINDOW->m_szTitle.c_str()); Debug::log(LOG, "New layer popup created from XDG window %x -> %s", PWINDOW, PWINDOW->m_szTitle.c_str());
@ -92,8 +87,8 @@ void Events::listener_newPopupXDG(wl_listener* listener, void* data) {
createNewPopup(WLRPOPUP, PNEWPOPUP); createNewPopup(WLRPOPUP, PNEWPOPUP);
} }
void Events::listener_newPopupFromPopupXDG(wl_listener* listener, void* data) { void Events::listener_newPopupFromPopupXDG(void* owner, void* data) {
SXDGPopup* PPOPUP = wl_container_of(listener, PPOPUP, listen_newPopupFromPopupXDG); SXDGPopup* PPOPUP = (SXDGPopup*)owner;
Debug::log(LOG, "New layer popup created from XDG popup %x -> %s", PPOPUP, PPOPUP->parentWindow->m_szTitle.c_str()); Debug::log(LOG, "New layer popup created from XDG popup %x -> %s", PPOPUP, PPOPUP->parentWindow->m_szTitle.c_str());
@ -110,8 +105,8 @@ void Events::listener_newPopupFromPopupXDG(wl_listener* listener, void* data) {
createNewPopup(WLRPOPUP, PNEWPOPUP); createNewPopup(WLRPOPUP, PNEWPOPUP);
} }
void Events::listener_mapPopupXDG(wl_listener* listener, void* data) { void Events::listener_mapPopupXDG(void* owner, void* data) {
SXDGPopup* PPOPUP = wl_container_of(listener, PPOPUP, listen_mapPopupXDG); SXDGPopup* PPOPUP = (SXDGPopup*)owner;
Debug::log(LOG, "New XDG Popup mapped"); Debug::log(LOG, "New XDG Popup mapped");
@ -120,8 +115,8 @@ void Events::listener_mapPopupXDG(wl_listener* listener, void* data) {
Debug::log(LOG, "XDG Popup got assigned a surfaceTreeNode %x", PPOPUP->pSurfaceTree); Debug::log(LOG, "XDG Popup got assigned a surfaceTreeNode %x", PPOPUP->pSurfaceTree);
} }
void Events::listener_unmapPopupXDG(wl_listener* listener, void* data) { void Events::listener_unmapPopupXDG(void* owner, void* data) {
SXDGPopup* PPOPUP = wl_container_of(listener, PPOPUP, listen_unmapPopupXDG); SXDGPopup* PPOPUP = (SXDGPopup*)owner;
Debug::log(LOG, "XDG Popup unmapped"); Debug::log(LOG, "XDG Popup unmapped");
SubsurfaceTree::destroySurfaceTree(PPOPUP->pSurfaceTree); SubsurfaceTree::destroySurfaceTree(PPOPUP->pSurfaceTree);
@ -129,8 +124,8 @@ void Events::listener_unmapPopupXDG(wl_listener* listener, void* data) {
PPOPUP->pSurfaceTree = nullptr; PPOPUP->pSurfaceTree = nullptr;
} }
void Events::listener_destroyPopupXDG(wl_listener* listener, void* data) { void Events::listener_destroyPopupXDG(void* owner, void* data) {
SXDGPopup* PPOPUP = wl_container_of(listener, PPOPUP, listen_destroyPopupXDG); SXDGPopup* PPOPUP = (SXDGPopup*)owner;
Debug::log(LOG, "Destroyed popup XDG %x", PPOPUP); Debug::log(LOG, "Destroyed popup XDG %x", PPOPUP);

View file

@ -21,8 +21,8 @@ void addViewCoords(void* pWindow, int* x, int* y) {
*y += PWINDOW->m_vEffectivePosition.y; *y += PWINDOW->m_vEffectivePosition.y;
} }
void Events::listener_mapWindow(wl_listener* listener, void* data) { void Events::listener_mapWindow(void* owner, void* data) {
CWindow* PWINDOW = wl_container_of(listener, PWINDOW, listen_mapWindow); CWindow* PWINDOW = (CWindow*)owner;
const auto PMONITOR = g_pCompositor->getMonitorFromCursor(); const auto PMONITOR = g_pCompositor->getMonitorFromCursor();
PWINDOW->m_iMonitorID = PMONITOR->ID; PWINDOW->m_iMonitorID = PMONITOR->ID;
@ -115,37 +115,37 @@ void Events::listener_mapWindow(wl_listener* listener, void* data) {
Debug::log(LOG, "Window got assigned a surfaceTreeNode %x", PWINDOW->m_pSurfaceTree); Debug::log(LOG, "Window got assigned a surfaceTreeNode %x", PWINDOW->m_pSurfaceTree);
if (!PWINDOW->m_bIsX11) { if (!PWINDOW->m_bIsX11) {
addWLSignal(&PWINDOW->m_uSurface.xdg->surface->events.commit, &PWINDOW->listen_commitWindow, PWINDOW, "XDG Window Late"); PWINDOW->hyprListener_commitWindow.initCallback(&PWINDOW->m_uSurface.xdg->surface->events.commit, &Events::listener_commitWindow, PWINDOW, "XDG Window Late");
addWLSignal(&PWINDOW->m_uSurface.xdg->toplevel->events.set_title, &PWINDOW->listen_setTitleWindow, PWINDOW, "XDG Window Late"); PWINDOW->hyprListener_setTitleWindow.initCallback(&PWINDOW->m_uSurface.xdg->toplevel->events.set_title, &Events::listener_setTitleWindow, PWINDOW, "XDG Window Late");
addWLSignal(&PWINDOW->m_uSurface.xdg->toplevel->events.request_fullscreen, &PWINDOW->listen_fullscreenWindow, PWINDOW, "XDG Window Late"); PWINDOW->hyprListener_fullscreenWindow.initCallback(&PWINDOW->m_uSurface.xdg->toplevel->events.request_fullscreen, &Events::listener_fullscreenWindow, PWINDOW, "XDG Window Late");
addWLSignal(&PWINDOW->m_uSurface.xdg->events.new_popup, &PWINDOW->listen_newPopupXDG, PWINDOW, "XDG Window Late"); PWINDOW->hyprListener_newPopupXDG.initCallback(&PWINDOW->m_uSurface.xdg->events.new_popup, &Events::listener_newPopupXDG, PWINDOW, "XDG Window Late");
} else { } else {
addWLSignal(&PWINDOW->m_uSurface.xwayland->events.request_fullscreen, &PWINDOW->listen_fullscreenWindow, PWINDOW, "XWayland Window Late"); PWINDOW->hyprListener_fullscreenWindow.initCallback(&PWINDOW->m_uSurface.xwayland->events.request_fullscreen, &Events::listener_fullscreenWindow, PWINDOW, "XWayland Window Late");
addWLSignal(&PWINDOW->m_uSurface.xwayland->events.request_activate, &PWINDOW->listen_activateX11, PWINDOW, "XWayland Window Late"); PWINDOW->hyprListener_activateX11.initCallback(&PWINDOW->m_uSurface.xwayland->events.request_activate, &Events::listener_activateX11, PWINDOW, "XWayland Window Late");
addWLSignal(&PWINDOW->m_uSurface.xwayland->events.request_configure, &PWINDOW->listen_configureX11, PWINDOW, "XWayland Window Late"); PWINDOW->hyprListener_configureX11.initCallback(&PWINDOW->m_uSurface.xwayland->events.request_configure, &Events::listener_configureX11, PWINDOW, "XWayland Window Late");
addWLSignal(&PWINDOW->m_uSurface.xwayland->events.set_title, &PWINDOW->listen_setTitleWindow, PWINDOW, "XWayland Window Late"); PWINDOW->hyprListener_setTitleWindow.initCallback(&PWINDOW->m_uSurface.xwayland->events.set_title, &Events::listener_setTitleWindow, PWINDOW, "XWayland Window Late");
} }
Debug::log(LOG, "Map request dispatched, monitor %s, xywh: %f %f %f %f", PMONITOR->szName.c_str(), PWINDOW->m_vEffectivePosition.x, PWINDOW->m_vEffectivePosition.y, PWINDOW->m_vEffectiveSize.x, PWINDOW->m_vEffectiveSize.y); Debug::log(LOG, "Map request dispatched, monitor %s, xywh: %f %f %f %f", PMONITOR->szName.c_str(), PWINDOW->m_vEffectivePosition.x, PWINDOW->m_vEffectivePosition.y, PWINDOW->m_vEffectiveSize.x, PWINDOW->m_vEffectiveSize.y);
} }
void Events::listener_unmapWindow(wl_listener* listener, void* data) { void Events::listener_unmapWindow(void* owner, void* data) {
CWindow* PWINDOW = wl_container_of(listener, PWINDOW, listen_unmapWindow); CWindow* PWINDOW = (CWindow*)owner;
Debug::log(LOG, "Window %x unmapped", PWINDOW); Debug::log(LOG, "Window %x unmapped", PWINDOW);
if (!PWINDOW->m_bIsX11) { if (!PWINDOW->m_bIsX11) {
wl_list_remove(&PWINDOW->listen_commitWindow.link); 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);
wl_list_remove(&PWINDOW->listen_setTitleWindow.link); PWINDOW->hyprListener_commitWindow.removeCallback();
wl_list_remove(&PWINDOW->listen_fullscreenWindow.link); PWINDOW->hyprListener_setTitleWindow.removeCallback();
wl_list_remove(&PWINDOW->listen_newPopupXDG.link); PWINDOW->hyprListener_fullscreenWindow.removeCallback();
Debug::log(LOG, "Unregistered late callbacks XDG: %x %x %x %x", &PWINDOW->listen_commitWindow.link, &PWINDOW->listen_setTitleWindow.link, &PWINDOW->listen_fullscreenWindow.link, &PWINDOW->listen_newPopupXDG.link); PWINDOW->hyprListener_newPopupXDG.removeCallback();
} else { } else {
wl_list_remove(&PWINDOW->listen_fullscreenWindow.link); 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);
wl_list_remove(&PWINDOW->listen_activateX11.link); PWINDOW->hyprListener_fullscreenWindow.removeCallback();
wl_list_remove(&PWINDOW->listen_configureX11.link); PWINDOW->hyprListener_activateX11.removeCallback();
wl_list_remove(&PWINDOW->listen_setTitleWindow.link); PWINDOW->hyprListener_configureX11.removeCallback();
Debug::log(LOG, "Unregistered late callbacks XWL: %x %x %x %x", &PWINDOW->listen_fullscreenWindow.link, &PWINDOW->listen_activateX11.link, &PWINDOW->listen_configureX11.link, &PWINDOW->listen_setTitleWindow.link); PWINDOW->hyprListener_setTitleWindow.removeCallback();
} }
if (g_pXWaylandManager->getWindowSurface(PWINDOW) == g_pCompositor->m_pLastFocus) if (g_pXWaylandManager->getWindowSurface(PWINDOW) == g_pCompositor->m_pLastFocus)
@ -173,23 +173,23 @@ void Events::listener_unmapWindow(wl_listener* listener, void* data) {
PWINDOW->m_pSurfaceTree = nullptr; PWINDOW->m_pSurfaceTree = nullptr;
} }
void Events::listener_commitWindow(wl_listener* listener, void* data) { void Events::listener_commitWindow(void* owner, void* data) {
CWindow* PWINDOW = wl_container_of(listener, PWINDOW, listen_commitWindow); CWindow* PWINDOW = (CWindow*)owner;
// Debug::log(LOG, "Window %x committed", PWINDOW); // SPAM! // Debug::log(LOG, "Window %x committed", PWINDOW); // SPAM!
} }
void Events::listener_destroyWindow(wl_listener* listener, void* data) { void Events::listener_destroyWindow(void* owner, void* data) {
CWindow* PWINDOW = wl_container_of(listener, PWINDOW, listen_destroyWindow); CWindow* PWINDOW = (CWindow*)owner;
Debug::log(LOG, "Window %x destroyed", PWINDOW); Debug::log(LOG, "Window %x destroyed", PWINDOW);
if (g_pXWaylandManager->getWindowSurface(PWINDOW) == g_pCompositor->m_pLastFocus) if (g_pXWaylandManager->getWindowSurface(PWINDOW) == g_pCompositor->m_pLastFocus)
g_pCompositor->m_pLastFocus = nullptr; g_pCompositor->m_pLastFocus = nullptr;
wl_list_remove(&PWINDOW->listen_mapWindow.link); PWINDOW->hyprListener_mapWindow.removeCallback();
wl_list_remove(&PWINDOW->listen_unmapWindow.link); PWINDOW->hyprListener_unmapWindow.removeCallback();
wl_list_remove(&PWINDOW->listen_destroyWindow.link); PWINDOW->hyprListener_destroyWindow.removeCallback();
g_pLayoutManager->getCurrentLayout()->onWindowRemoved(PWINDOW); g_pLayoutManager->getCurrentLayout()->onWindowRemoved(PWINDOW);
@ -201,8 +201,8 @@ void Events::listener_destroyWindow(wl_listener* listener, void* data) {
g_pCompositor->removeWindowFromVectorSafe(PWINDOW); g_pCompositor->removeWindowFromVectorSafe(PWINDOW);
} }
void Events::listener_setTitleWindow(wl_listener* listener, void* data) { void Events::listener_setTitleWindow(void* owner, void* data) {
CWindow* PWINDOW = wl_container_of(listener, PWINDOW, listen_setTitleWindow); CWindow* PWINDOW = (CWindow*)owner;
if (!g_pCompositor->windowValidMapped(PWINDOW)) if (!g_pCompositor->windowValidMapped(PWINDOW))
return; return;
@ -212,28 +212,28 @@ void Events::listener_setTitleWindow(wl_listener* listener, void* data) {
PWINDOW->m_szTitle = g_pXWaylandManager->getTitle(PWINDOW); PWINDOW->m_szTitle = g_pXWaylandManager->getTitle(PWINDOW);
} }
void Events::listener_fullscreenWindow(wl_listener* listener, void* data) { void Events::listener_fullscreenWindow(void* owner, void* data) {
CWindow* PWINDOW = wl_container_of(listener, PWINDOW, listen_fullscreenWindow); CWindow* PWINDOW = (CWindow*)owner;
Debug::log(LOG, "Window %x fullscreen to %i", PWINDOW, PWINDOW->m_bIsFullscreen); Debug::log(LOG, "Window %x fullscreen to %i", PWINDOW, PWINDOW->m_bIsFullscreen);
g_pLayoutManager->getCurrentLayout()->fullscreenRequestForWindow(PWINDOW); g_pLayoutManager->getCurrentLayout()->fullscreenRequestForWindow(PWINDOW);
} }
void Events::listener_activate(wl_listener* listener, void* data) { void Events::listener_activate(void* owner, void* data) {
// TODO // TODO
} }
void Events::listener_activateX11(wl_listener* listener, void* data) { void Events::listener_activateX11(void* owner, void* data) {
CWindow* PWINDOW = wl_container_of(listener, PWINDOW, listen_activateX11); CWindow* PWINDOW = (CWindow*)owner;
if (PWINDOW->m_iX11Type == 1 /* Managed */) { if (PWINDOW->m_iX11Type == 1 /* Managed */) {
wlr_xwayland_surface_activate(PWINDOW->m_uSurface.xwayland, 1); wlr_xwayland_surface_activate(PWINDOW->m_uSurface.xwayland, 1);
} }
} }
void Events::listener_configureX11(wl_listener* listener, void* data) { void Events::listener_configureX11(void* owner, void* data) {
CWindow* PWINDOW = wl_container_of(listener, PWINDOW, listen_configureX11); CWindow* PWINDOW = (CWindow*)owner;
const auto E = (wlr_xwayland_surface_configure_event*)data; const auto E = (wlr_xwayland_surface_configure_event*)data;
@ -253,10 +253,9 @@ void Events::listener_surfaceXWayland(wl_listener* listener, void* data) {
PNEWWINDOW->m_iX11Type = XWSURFACE->override_redirect ? 2 : 1; PNEWWINDOW->m_iX11Type = XWSURFACE->override_redirect ? 2 : 1;
PNEWWINDOW->m_bIsX11 = true; PNEWWINDOW->m_bIsX11 = true;
addWLSignal(&XWSURFACE->events.map, &PNEWWINDOW->listen_mapWindow, PNEWWINDOW, "XWayland Window"); PNEWWINDOW->hyprListener_mapWindow.initCallback(&XWSURFACE->events.map, &Events::listener_mapWindow, PNEWWINDOW, "XWayland Window");
addWLSignal(&XWSURFACE->events.unmap, &PNEWWINDOW->listen_unmapWindow, PNEWWINDOW, "XWayland Window"); PNEWWINDOW->hyprListener_unmapWindow.initCallback(&XWSURFACE->events.unmap, &Events::listener_unmapWindow, PNEWWINDOW, "XWayland Window");
addWLSignal(&XWSURFACE->events.destroy, &PNEWWINDOW->listen_destroyWindow, PNEWWINDOW, "XWayland Window"); PNEWWINDOW->hyprListener_destroyWindow.initCallback(&XWSURFACE->events.destroy, &Events::listener_destroyWindow, PNEWWINDOW, "XWayland Window");
} }
void Events::listener_newXDGSurface(wl_listener* listener, void* data) { void Events::listener_newXDGSurface(wl_listener* listener, void* data) {
@ -272,8 +271,7 @@ void Events::listener_newXDGSurface(wl_listener* listener, void* data) {
const auto PNEWWINDOW = &g_pCompositor->m_lWindows.back(); const auto PNEWWINDOW = &g_pCompositor->m_lWindows.back();
PNEWWINDOW->m_uSurface.xdg = XDGSURFACE; PNEWWINDOW->m_uSurface.xdg = XDGSURFACE;
PNEWWINDOW->hyprListener_mapWindow.initCallback(&XDGSURFACE->events.map, &Events::listener_mapWindow, PNEWWINDOW, "XDG Window");
addWLSignal(&XDGSURFACE->events.map, &PNEWWINDOW->listen_mapWindow, PNEWWINDOW, "XDG Window"); PNEWWINDOW->hyprListener_unmapWindow.initCallback(&XDGSURFACE->events.unmap, &Events::listener_unmapWindow, PNEWWINDOW, "XDG Window");
addWLSignal(&XDGSURFACE->events.unmap, &PNEWWINDOW->listen_unmapWindow, PNEWWINDOW, "XDG Window"); PNEWWINDOW->hyprListener_destroyWindow.initCallback(&XDGSURFACE->events.destroy, &Events::listener_destroyWindow, PNEWWINDOW, "XDG Window");
addWLSignal(&XDGSURFACE->events.destroy, &PNEWWINDOW->listen_destroyWindow, PNEWWINDOW, "XDG Window");
} }

View file

@ -26,13 +26,9 @@ SSurfaceTreeNode* createTree(wlr_surface* pSurface) {
PNODE->pSurface = pSurface; PNODE->pSurface = pSurface;
PNODE->listen_newSubsurface.notify = Events::listener_newSubsurfaceNode; PNODE->hyprListener_newSubsurface.initCallback(&pSurface->events.new_subsurface, &Events::listener_newSubsurfaceNode, PNODE, "SurfaceTreeNode");
PNODE->listen_commit.notify = Events::listener_commitSubsurface; PNODE->hyprListener_commit.initCallback(&pSurface->events.commit, &Events::listener_commitSubsurface, PNODE, "SurfaceTreeNode");
PNODE->listen_destroy.notify = Events::listener_destroySubsurfaceNode; PNODE->hyprListener_destroy.initCallback(&pSurface->events.destroy, &Events::listener_destroySubsurfaceNode, PNODE, "SurfaceTreeNode");
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");
return PNODE; return PNODE;
} }
@ -75,9 +71,9 @@ void SubsurfaceTree::destroySurfaceTree(SSurfaceTreeNode* pNode) {
pNode->childSubsurfaces.clear(); pNode->childSubsurfaces.clear();
wl_list_remove(&pNode->listen_newSubsurface.link); pNode->hyprListener_commit.removeCallback();
wl_list_remove(&pNode->listen_commit.link); pNode->hyprListener_destroy.removeCallback();
wl_list_remove(&pNode->listen_destroy.link); pNode->hyprListener_newSubsurface.removeCallback();
Debug::log(LOG, "SurfaceTree Node removed"); Debug::log(LOG, "SurfaceTree Node removed");
} }
@ -88,17 +84,17 @@ void destroySubsurface(SSubsurface* pSubsurface) {
pSubsurface->pChild = nullptr; pSubsurface->pChild = nullptr;
} }
wl_list_remove(&pSubsurface->listen_map.link); pSubsurface->hyprListener_destroy.removeCallback();
wl_list_remove(&pSubsurface->listen_unmap.link); pSubsurface->hyprListener_map.removeCallback();
wl_list_remove(&pSubsurface->listen_destroy.link); pSubsurface->hyprListener_unmap.removeCallback();
} }
// //
// Subsurface listeners // Subsurface listeners
// //
void Events::listener_newSubsurfaceNode(wl_listener* listener, void* data) { void Events::listener_newSubsurfaceNode(void* owner, void* data) {
SSurfaceTreeNode* pNode = wl_container_of(listener, pNode, listen_newSubsurface); SSurfaceTreeNode* pNode = (SSurfaceTreeNode*)owner;
const auto PSUBSURFACE = (wlr_subsurface*)data; const auto PSUBSURFACE = (wlr_subsurface*)data;
@ -110,25 +106,21 @@ void Events::listener_newSubsurfaceNode(wl_listener* listener, void* data) {
PNEWSUBSURFACE->pSubsurface = PSUBSURFACE; PNEWSUBSURFACE->pSubsurface = PSUBSURFACE;
PNEWSUBSURFACE->pParent = pNode; PNEWSUBSURFACE->pParent = pNode;
PNEWSUBSURFACE->listen_map.notify = Events::listener_mapSubsurface; PNEWSUBSURFACE->hyprListener_map.initCallback(&PSUBSURFACE->events.map, &Events::listener_mapSubsurface, PNEWSUBSURFACE, "Subsurface");
PNEWSUBSURFACE->listen_unmap.notify = Events::listener_unmapSubsurface; PNEWSUBSURFACE->hyprListener_unmap.initCallback(&PSUBSURFACE->events.unmap, &Events::listener_unmapLayerSurface, PNEWSUBSURFACE, "Subsurface");
PNEWSUBSURFACE->listen_destroy.notify = Events::listener_destroySubsurface; PNEWSUBSURFACE->hyprListener_destroy.initCallback(&PSUBSURFACE->events.destroy, &Events::listener_destroySubsurface, PNEWSUBSURFACE, "Subsurface");
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");
} }
void Events::listener_mapSubsurface(wl_listener* listener, void* data) { void Events::listener_mapSubsurface(void* owner, void* data) {
SSubsurface* subsurface = wl_container_of(listener, subsurface, listen_map); SSubsurface* subsurface = (SSubsurface*)owner;
Debug::log(LOG, "Subsurface %x mapped", subsurface->pSubsurface); Debug::log(LOG, "Subsurface %x mapped", subsurface->pSubsurface);
subsurface->pChild = createSubsurfaceNode(subsurface->pParent, subsurface, subsurface->pSubsurface->surface); subsurface->pChild = createSubsurfaceNode(subsurface->pParent, subsurface, subsurface->pSubsurface->surface);
} }
void Events::listener_unmapSubsurface(wl_listener* listener, void* data) { void Events::listener_unmapSubsurface(void* owner, void* data) {
SSubsurface* subsurface = wl_container_of(listener, subsurface, listen_unmap); SSubsurface* subsurface = (SSubsurface*)owner;
Debug::log(LOG, "Subsurface %x unmapped", subsurface); 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) { void Events::listener_commitSubsurface(void* owner, void* data) {
SSurfaceTreeNode* pNode = wl_container_of(listener, pNode, listen_commit); SSurfaceTreeNode* pNode = (SSurfaceTreeNode*)owner;
} }
void Events::listener_destroySubsurface(wl_listener* listener, void* data) { void Events::listener_destroySubsurface(void* owner, void* data) {
SSubsurface* subsurface = wl_container_of(listener, subsurface, listen_destroy); SSubsurface* subsurface = (SSubsurface*)owner;
Debug::log(LOG, "Subsurface %x destroyed", subsurface); Debug::log(LOG, "Subsurface %x destroyed", subsurface);
subsurface->pParent->childSubsurfaces.remove(*subsurface); subsurface->pParent->childSubsurfaces.remove(*subsurface);
} }
void Events::listener_destroySubsurfaceNode(wl_listener* listener, void* data) { void Events::listener_destroySubsurfaceNode(void* owner, void* data) {
SSurfaceTreeNode* pNode = wl_container_of(listener, pNode, listen_destroy); SSurfaceTreeNode* pNode = (SSurfaceTreeNode*)owner;
Debug::log(LOG, "Subsurface Node %x destroyed", pNode); Debug::log(LOG, "Subsurface Node %x destroyed", pNode);
for (auto& c : pNode->childSubsurfaces) for (auto& c : pNode->childSubsurfaces)
destroySubsurface(&c); destroySubsurface(&c);
wl_list_remove(&pNode->listen_newSubsurface.link); pNode->hyprListener_commit.removeCallback();
wl_list_remove(&pNode->listen_commit.link); pNode->hyprListener_newSubsurface.removeCallback();
wl_list_remove(&pNode->listen_destroy.link); pNode->hyprListener_destroy.removeCallback();
SubsurfaceTree::surfaceTreeNodes.remove(*pNode); SubsurfaceTree::surfaceTreeNodes.remove(*pNode);
} }

View file

@ -10,9 +10,9 @@ typedef void (*applyGlobalOffsetFn)(void *, int *, int *);
struct SSurfaceTreeNode { struct SSurfaceTreeNode {
wlr_surface* pSurface = nullptr; wlr_surface* pSurface = nullptr;
DYNMULTILISTENER(newSubsurface); DYNLISTENER(newSubsurface);
DYNMULTILISTENER(commit); DYNLISTENER(commit);
DYNMULTILISTENER(destroy); DYNLISTENER(destroy);
SSurfaceTreeNode* pParent = nullptr; SSurfaceTreeNode* pParent = nullptr;
SSubsurface* pSubsurface = nullptr; SSubsurface* pSubsurface = nullptr;
@ -33,9 +33,9 @@ struct SSubsurface {
SSurfaceTreeNode* pParent = nullptr; SSurfaceTreeNode* pParent = nullptr;
SSurfaceTreeNode* pChild = nullptr; SSurfaceTreeNode* pChild = nullptr;
DYNMULTILISTENER(map); DYNLISTENER(map);
DYNMULTILISTENER(unmap); DYNLISTENER(unmap);
DYNMULTILISTENER(destroy); DYNLISTENER(destroy);
bool operator==(const SSubsurface& rhs) { bool operator==(const SSubsurface& rhs) {
return pSubsurface == rhs.pSubsurface; return pSubsurface == rhs.pSubsurface;

View 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);
}

View 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 = "";
};

View file

@ -137,9 +137,9 @@ void CInputManager::newKeyboard(wlr_input_device* keyboard) {
xkb_context_unref(CONTEXT); xkb_context_unref(CONTEXT);
wlr_keyboard_set_repeat_info(keyboard->keyboard, 25, 600); wlr_keyboard_set_repeat_info(keyboard->keyboard, 25, 600);
addWLSignal(&keyboard->keyboard->events.modifiers, &PNEWKEYBOARD->listen_keyboardMod, PNEWKEYBOARD, "Keyboard"); PNEWKEYBOARD->hyprListener_keyboardMod.initCallback(&keyboard->keyboard->events.modifiers, &Events::listener_keyboardMod, PNEWKEYBOARD, "Keyboard");
addWLSignal(&keyboard->keyboard->events.key, &PNEWKEYBOARD->listen_keyboardKey, PNEWKEYBOARD, "Keyboard"); PNEWKEYBOARD->hyprListener_keyboardKey.initCallback(&keyboard->keyboard->events.key, &Events::listener_keyboardKey, PNEWKEYBOARD, "Keyboard");
addWLSignal(&keyboard->events.destroy, &PNEWKEYBOARD->listen_keyboardDestroy, PNEWKEYBOARD, "Keyboard"); PNEWKEYBOARD->hyprListener_keyboardDestroy.initCallback(&keyboard->events.destroy, &Events::listener_keyboardDestroy, PNEWKEYBOARD, "Keyboard");
wlr_seat_set_keyboard(g_pCompositor->m_sSeat.seat, keyboard->keyboard); wlr_seat_set_keyboard(g_pCompositor->m_sSeat.seat, keyboard->keyboard);
@ -200,9 +200,9 @@ void CInputManager::newMouse(wlr_input_device* mouse) {
} }
void CInputManager::destroyKeyboard(SKeyboard* pKeyboard) { void CInputManager::destroyKeyboard(SKeyboard* pKeyboard) {
wl_list_remove(&pKeyboard->listen_keyboardMod.link); pKeyboard->hyprListener_keyboardDestroy.removeCallback();
wl_list_remove(&pKeyboard->listen_keyboardKey.link); pKeyboard->hyprListener_keyboardMod.removeCallback();
wl_list_remove(&pKeyboard->listen_keyboardDestroy.link); pKeyboard->hyprListener_keyboardKey.removeCallback();
m_lKeyboards.remove(*pKeyboard); m_lKeyboards.remove(*pKeyboard);
} }