summaryrefslogtreecommitdiff
path: root/src/helpers/WLSurface.cpp
diff options
context:
space:
mode:
authorVaxry <43317083+vaxerski@users.noreply.github.com>2023-03-20 15:00:58 +0000
committerGitHub <noreply@github.com>2023-03-20 15:00:58 +0000
commit788a8f7c134a34085d683e44a328e344be6b21f3 (patch)
treebed90c82b3c3e65722b5f1f97a6d04240ad3c7fc /src/helpers/WLSurface.cpp
parentd23bbd1687a5413fb7f2c08b67692d4e64f8efef (diff)
internal: wrap wlr surfaces (#1822)
Diffstat (limited to 'src/helpers/WLSurface.cpp')
-rw-r--r--src/helpers/WLSurface.cpp51
1 files changed, 51 insertions, 0 deletions
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