2023-03-20 16:00:58 +01:00
|
|
|
#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();
|
|
|
|
}
|
|
|
|
|
2023-03-23 01:39:32 +01:00
|
|
|
void CWLSurface::unassign() {
|
|
|
|
destroy();
|
|
|
|
}
|
|
|
|
|
2023-03-20 16:00:58 +01:00
|
|
|
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;
|
|
|
|
|
2023-03-23 01:22:43 +01:00
|
|
|
m_pWLRSurface = nullptr;
|
|
|
|
|
2023-04-17 18:35:28 +02:00
|
|
|
Debug::log(LOG, "CWLSurface %lx called destroy()", this);
|
2023-03-20 16:00:58 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
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");
|
|
|
|
|
2023-04-17 18:35:28 +02:00
|
|
|
Debug::log(LOG, "CWLSurface %lx called init()", this);
|
2023-03-20 16:00:58 +01:00
|
|
|
}
|