2023-03-20 16:00:58 +01:00
|
|
|
#include "WLSurface.hpp"
|
|
|
|
#include "../Compositor.hpp"
|
|
|
|
|
2024-02-29 16:07:11 +01:00
|
|
|
void CWLSurface::assign(wlr_surface* pSurface) {
|
2023-03-20 16:00:58 +01:00
|
|
|
m_pWLRSurface = pSurface;
|
|
|
|
init();
|
2024-02-29 16:07:11 +01:00
|
|
|
m_bInert = false;
|
2023-03-20 16:00:58 +01:00
|
|
|
}
|
|
|
|
|
2024-04-27 13:43:12 +02:00
|
|
|
void CWLSurface::assign(wlr_surface* pSurface, PHLWINDOW pOwner) {
|
2024-02-29 16:07:11 +01:00
|
|
|
m_pWindowOwner = pOwner;
|
|
|
|
m_pWLRSurface = pSurface;
|
|
|
|
init();
|
|
|
|
m_bInert = false;
|
|
|
|
}
|
|
|
|
|
2024-04-30 03:41:27 +02:00
|
|
|
void CWLSurface::assign(wlr_surface* pSurface, PHLLS pOwner) {
|
2024-02-29 16:07:11 +01:00
|
|
|
m_pLayerOwner = pOwner;
|
|
|
|
m_pWLRSurface = pSurface;
|
|
|
|
init();
|
|
|
|
m_bInert = false;
|
|
|
|
}
|
|
|
|
|
|
|
|
void CWLSurface::assign(wlr_surface* pSurface, CSubsurface* pOwner) {
|
|
|
|
m_pSubsurfaceOwner = pOwner;
|
|
|
|
m_pWLRSurface = pSurface;
|
|
|
|
init();
|
|
|
|
m_bInert = false;
|
|
|
|
}
|
|
|
|
|
|
|
|
void CWLSurface::assign(wlr_surface* pSurface, CPopup* pOwner) {
|
|
|
|
m_pPopupOwner = pOwner;
|
2023-03-20 16:00:58 +01:00
|
|
|
m_pWLRSurface = pSurface;
|
|
|
|
init();
|
2024-02-29 16:07:11 +01:00
|
|
|
m_bInert = false;
|
2023-03-20 16:00:58 +01:00
|
|
|
}
|
|
|
|
|
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 {
|
2024-04-27 13:43:12 +02:00
|
|
|
if (!validMapped(m_pWindowOwner) || !exists())
|
2023-10-20 21:15:41 +02:00
|
|
|
return false;
|
|
|
|
|
2024-04-27 13:43:12 +02:00
|
|
|
const auto O = m_pWindowOwner.lock();
|
|
|
|
|
|
|
|
return O->m_vReportedSize.x > m_pWLRSurface->current.buffer_width + 1 || O->m_vReportedSize.y > m_pWLRSurface->current.buffer_height + 1;
|
2023-10-20 21:15:41 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
Vector2D CWLSurface::correctSmallVec() const {
|
2024-04-27 13:43:12 +02:00
|
|
|
if (!validMapped(m_pWindowOwner) || !exists() || !small() || m_bFillIgnoreSmall)
|
2023-10-20 21:15:41 +02:00
|
|
|
return {};
|
|
|
|
|
2023-10-25 23:05:04 +02:00
|
|
|
const auto SIZE = getViewporterCorrectedSize();
|
2024-04-27 13:43:12 +02:00
|
|
|
const auto O = m_pWindowOwner.lock();
|
2023-10-25 23:05:04 +02:00
|
|
|
|
2024-04-27 13:43:12 +02:00
|
|
|
return Vector2D{(O->m_vReportedSize.x - SIZE.x) / 2, (O->m_vReportedSize.y - SIZE.y) / 2}.clamp({}, {INFINITY, INFINITY}) * (O->m_vRealSize.value() / O->m_vReportedSize);
|
2023-10-20 21:15:41 +02:00
|
|
|
}
|
|
|
|
|
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};
|
|
|
|
}
|
|
|
|
|
2024-02-19 12:24:54 +01:00
|
|
|
CRegion CWLSurface::logicalDamage() const {
|
|
|
|
CRegion damage{&m_pWLRSurface->buffer_damage};
|
|
|
|
damage.transform(m_pWLRSurface->current.transform, m_pWLRSurface->current.buffer_width, m_pWLRSurface->current.buffer_height);
|
|
|
|
damage.scale(1.0 / m_pWLRSurface->current.scale);
|
|
|
|
|
2024-02-19 12:34:55 +01:00
|
|
|
const auto VPSIZE = getViewporterCorrectedSize();
|
2024-02-19 12:24:54 +01:00
|
|
|
const auto CORRECTVEC = correctSmallVec();
|
|
|
|
|
2024-02-20 16:21:30 +01:00
|
|
|
if (m_pWLRSurface->current.viewport.has_src) {
|
|
|
|
damage.intersect(CBox{std::floor(m_pWLRSurface->current.viewport.src.x), std::floor(m_pWLRSurface->current.viewport.src.y),
|
|
|
|
std::ceil(m_pWLRSurface->current.viewport.src.width), std::ceil(m_pWLRSurface->current.viewport.src.height)});
|
|
|
|
}
|
|
|
|
|
|
|
|
const auto SCALEDSRCSIZE = m_pWLRSurface->current.viewport.has_src ?
|
|
|
|
Vector2D{m_pWLRSurface->current.viewport.src.width, m_pWLRSurface->current.viewport.src.height} * m_pWLRSurface->current.scale :
|
|
|
|
Vector2D{m_pWLRSurface->current.buffer_width, m_pWLRSurface->current.buffer_height};
|
|
|
|
|
|
|
|
damage.scale({VPSIZE.x / SCALEDSRCSIZE.x, VPSIZE.y / SCALEDSRCSIZE.y});
|
2024-02-19 12:24:54 +01:00
|
|
|
damage.translate(CORRECTVEC);
|
|
|
|
|
|
|
|
return damage;
|
|
|
|
}
|
|
|
|
|
2023-03-20 16:00:58 +01:00
|
|
|
void CWLSurface::destroy() {
|
|
|
|
if (!m_pWLRSurface)
|
|
|
|
return;
|
|
|
|
|
2024-04-27 00:55:41 +02:00
|
|
|
events.destroy.emit();
|
|
|
|
|
2024-03-02 22:04:55 +01:00
|
|
|
m_pConstraint.reset();
|
|
|
|
|
2023-03-20 16:00:58 +01:00
|
|
|
hyprListener_destroy.removeCallback();
|
2024-03-02 22:04:55 +01:00
|
|
|
hyprListener_commit.removeCallback();
|
2023-03-20 16:00:58 +01:00
|
|
|
m_pWLRSurface->data = nullptr;
|
2024-04-27 13:43:12 +02:00
|
|
|
m_pWindowOwner.reset();
|
2024-04-30 03:41:27 +02:00
|
|
|
m_pLayerOwner.reset();
|
2024-04-27 13:43:12 +02:00
|
|
|
m_pPopupOwner = nullptr;
|
|
|
|
m_pSubsurfaceOwner = nullptr;
|
|
|
|
m_bInert = true;
|
2023-03-20 16:00:58 +01:00
|
|
|
|
2024-02-26 10:52:12 +01:00
|
|
|
if (g_pCompositor && g_pCompositor->m_pLastFocus == m_pWLRSurface)
|
2023-03-20 16:00:58 +01:00
|
|
|
g_pCompositor->m_pLastFocus = nullptr;
|
2024-02-26 10:52:12 +01:00
|
|
|
if (g_pInputManager && g_pInputManager->m_pLastMouseSurface == m_pWLRSurface)
|
2023-09-23 02:21:59 +02:00
|
|
|
g_pInputManager->m_pLastMouseSurface = nullptr;
|
2024-02-26 10:52:12 +01:00
|
|
|
if (g_pHyprRenderer && 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
|
|
|
}
|
|
|
|
|
2024-03-02 22:04:55 +01:00
|
|
|
static void onCommit(void* owner, void* data) {
|
|
|
|
const auto SURF = (CWLSurface*)owner;
|
|
|
|
SURF->onCommit();
|
|
|
|
}
|
|
|
|
|
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");
|
2024-03-02 22:04:55 +01:00
|
|
|
hyprListener_commit.initCallback(&m_pWLRSurface->events.commit, ::onCommit, this, "CWLSurface");
|
2023-03-20 16:00:58 +01:00
|
|
|
|
2023-09-06 12:51:36 +02:00
|
|
|
Debug::log(LOG, "CWLSurface {:x} called init()", (uintptr_t)this);
|
2024-02-29 16:07:11 +01:00
|
|
|
}
|
|
|
|
|
2024-04-27 13:43:12 +02:00
|
|
|
PHLWINDOW CWLSurface::getWindow() {
|
|
|
|
return m_pWindowOwner.lock();
|
2024-02-29 16:07:11 +01:00
|
|
|
}
|
|
|
|
|
2024-04-30 03:41:27 +02:00
|
|
|
PHLLS CWLSurface::getLayer() {
|
|
|
|
return m_pLayerOwner.lock();
|
2024-02-29 16:07:11 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
CPopup* CWLSurface::getPopup() {
|
|
|
|
return m_pPopupOwner;
|
|
|
|
}
|
|
|
|
|
|
|
|
CSubsurface* CWLSurface::getSubsurface() {
|
|
|
|
return m_pSubsurfaceOwner;
|
|
|
|
}
|
|
|
|
|
|
|
|
bool CWLSurface::desktopComponent() {
|
2024-04-30 03:41:27 +02:00
|
|
|
return !m_pLayerOwner.expired() || !m_pWindowOwner.expired() || m_pSubsurfaceOwner || m_pPopupOwner;
|
2024-02-29 16:07:11 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
std::optional<CBox> CWLSurface::getSurfaceBoxGlobal() {
|
|
|
|
if (!desktopComponent())
|
|
|
|
return {};
|
|
|
|
|
2024-04-27 13:43:12 +02:00
|
|
|
if (!m_pWindowOwner.expired())
|
|
|
|
return m_pWindowOwner.lock()->getWindowMainSurfaceBox();
|
2024-04-30 03:41:27 +02:00
|
|
|
if (!m_pLayerOwner.expired())
|
|
|
|
return m_pLayerOwner.lock()->geometry;
|
2024-02-29 16:07:11 +01:00
|
|
|
if (m_pPopupOwner)
|
|
|
|
return CBox{m_pPopupOwner->coordsGlobal(), m_pPopupOwner->size()};
|
|
|
|
if (m_pSubsurfaceOwner)
|
|
|
|
return CBox{m_pSubsurfaceOwner->coordsGlobal(), m_pSubsurfaceOwner->size()};
|
|
|
|
|
|
|
|
return {};
|
2024-03-02 01:35:17 +01:00
|
|
|
}
|
2024-03-02 22:04:55 +01:00
|
|
|
|
2024-04-27 00:55:41 +02:00
|
|
|
void CWLSurface::appendConstraint(std::weak_ptr<CPointerConstraint> constraint) {
|
|
|
|
m_pConstraint = constraint;
|
2024-03-02 22:04:55 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
void CWLSurface::onCommit() {
|
2024-04-27 00:55:41 +02:00
|
|
|
;
|
2024-03-02 22:04:55 +01:00
|
|
|
}
|
|
|
|
|
2024-04-27 00:55:41 +02:00
|
|
|
std::shared_ptr<CPointerConstraint> CWLSurface::constraint() {
|
|
|
|
return m_pConstraint.lock();
|
2024-03-02 22:04:55 +01:00
|
|
|
}
|