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;
|
|
|
|
}
|
|
|
|
|
2023-10-20 21:15:41 +02:00
|
|
|
bool CWLSurface::small() const {
|
|
|
|
if (!m_pOwner || !exists())
|
|
|
|
return false;
|
|
|
|
|
2023-11-04 18:39:56 +01:00
|
|
|
return m_pOwner->m_vReportedSize.x > m_pWLRSurface->current.buffer_width + 1 || m_pOwner->m_vReportedSize.y > m_pWLRSurface->current.buffer_height + 1;
|
2023-10-20 21:15:41 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
Vector2D CWLSurface::correctSmallVec() const {
|
|
|
|
if (!m_pOwner || !exists() || !small() || m_bFillIgnoreSmall)
|
|
|
|
return {};
|
|
|
|
|
2023-10-25 23:05:04 +02:00
|
|
|
const auto SIZE = getViewporterCorrectedSize();
|
|
|
|
|
|
|
|
return Vector2D{(m_pOwner->m_vReportedSize.x - SIZE.x) / 2, (m_pOwner->m_vReportedSize.y - SIZE.y) / 2}.clamp({}, {INFINITY, INFINITY}) *
|
2023-10-20 21:15:41 +02:00
|
|
|
(m_pOwner->m_vRealSize.vec() / m_pOwner->m_vReportedSize);
|
|
|
|
}
|
|
|
|
|
2023-10-25 23:05:04 +02:00
|
|
|
Vector2D CWLSurface::getViewporterCorrectedSize() const {
|
|
|
|
if (!exists())
|
|
|
|
return {};
|
|
|
|
|
|
|
|
return m_pWLRSurface->current.viewport.has_dst ? Vector2D{m_pWLRSurface->current.viewport.dst_width, m_pWLRSurface->current.viewport.dst_height} :
|
|
|
|
Vector2D{m_pWLRSurface->current.buffer_width, m_pWLRSurface->current.buffer_height};
|
|
|
|
}
|
|
|
|
|
2023-03-20 16:00:58 +01:00
|
|
|
void CWLSurface::destroy() {
|
|
|
|
if (!m_pWLRSurface)
|
|
|
|
return;
|
|
|
|
|
|
|
|
hyprListener_destroy.removeCallback();
|
|
|
|
m_pWLRSurface->data = nullptr;
|
2023-10-20 21:15:41 +02:00
|
|
|
m_pOwner = nullptr;
|
2023-03-20 16:00:58 +01:00
|
|
|
|
|
|
|
if (g_pCompositor->m_pLastFocus == m_pWLRSurface)
|
|
|
|
g_pCompositor->m_pLastFocus = nullptr;
|
2023-09-23 02:21:59 +02:00
|
|
|
if (g_pInputManager->m_pLastMouseSurface == m_pWLRSurface)
|
|
|
|
g_pInputManager->m_pLastMouseSurface = nullptr;
|
2023-10-29 19:09:05 +01:00
|
|
|
if (g_pHyprRenderer->m_sLastCursorData.surf == m_pWLRSurface)
|
2023-11-26 15:53:22 +01:00
|
|
|
g_pHyprRenderer->m_sLastCursorData.surf.reset();
|
2023-03-20 16:00:58 +01:00
|
|
|
|
2023-03-23 01:22:43 +01:00
|
|
|
m_pWLRSurface = nullptr;
|
|
|
|
|
2023-09-06 12:51:36 +02:00
|
|
|
Debug::log(LOG, "CWLSurface {:x} called destroy()", (uintptr_t)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-09-06 12:51:36 +02:00
|
|
|
Debug::log(LOG, "CWLSurface {:x} called init()", (uintptr_t)this);
|
2023-03-20 16:00:58 +01:00
|
|
|
}
|