From 788a8f7c134a34085d683e44a328e344be6b21f3 Mon Sep 17 00:00:00 2001 From: Vaxry <43317083+vaxerski@users.noreply.github.com> Date: Mon, 20 Mar 2023 15:00:58 +0000 Subject: internal: wrap wlr surfaces (#1822) --- src/helpers/WLSurface.cpp | 51 +++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 51 insertions(+) create mode 100644 src/helpers/WLSurface.cpp (limited to 'src/helpers/WLSurface.cpp') diff --git a/src/helpers/WLSurface.cpp b/src/helpers/WLSurface.cpp new file mode 100644 index 00000000..889e9885 --- /dev/null +++ b/src/helpers/WLSurface.cpp @@ -0,0 +1,51 @@ +#include "WLSurface.hpp" +#include "../Compositor.hpp" + +CWLSurface::CWLSurface(wlr_surface* pSurface) { + m_pWLRSurface = pSurface; + init(); +} + +void CWLSurface::assign(wlr_surface* pSurface) { + m_pWLRSurface = pSurface; + init(); +} + +CWLSurface::~CWLSurface() { + destroy(); +} + +bool CWLSurface::exists() const { + return m_pWLRSurface; +} + +wlr_surface* CWLSurface::wlr() const { + return m_pWLRSurface; +} + +void CWLSurface::destroy() { + if (!m_pWLRSurface) + return; + + hyprListener_destroy.removeCallback(); + m_pWLRSurface->data = nullptr; + + if (g_pCompositor->m_pLastFocus == m_pWLRSurface) + g_pCompositor->m_pLastFocus = nullptr; + + Debug::log(LOG, "CWLSurface %x called destroy()", this); +} + +void CWLSurface::init() { + if (!m_pWLRSurface) + return; + + RASSERT(!m_pWLRSurface->data, "Attempted to duplicate CWLSurface ownership!"); + + m_pWLRSurface->data = this; + + hyprListener_destroy.initCallback( + &m_pWLRSurface->events.destroy, [&](void* owner, void* data) { destroy(); }, this, "CWLSurface"); + + Debug::log(LOG, "CWLSurface %x called init()", this); +} \ No newline at end of file -- cgit v1.2.3