2023-03-20 16:00:58 +01:00
|
|
|
#include "WLSurface.hpp"
|
|
|
|
#include "../Compositor.hpp"
|
2024-06-08 10:07:59 +02:00
|
|
|
#include "../protocols/core/Compositor.hpp"
|
2024-07-27 15:03:52 +02:00
|
|
|
#include "../protocols/LayerShell.hpp"
|
2023-03-20 16:00:58 +01:00
|
|
|
|
2024-06-08 10:07:59 +02:00
|
|
|
void CWLSurface::assign(SP<CWLSurfaceResource> pSurface) {
|
|
|
|
m_pResource = pSurface;
|
2023-03-20 16:00:58 +01:00
|
|
|
init();
|
2024-02-29 16:07:11 +01:00
|
|
|
m_bInert = false;
|
2023-03-20 16:00:58 +01:00
|
|
|
}
|
|
|
|
|
2024-06-08 10:07:59 +02:00
|
|
|
void CWLSurface::assign(SP<CWLSurfaceResource> pSurface, PHLWINDOW pOwner) {
|
2024-02-29 16:07:11 +01:00
|
|
|
m_pWindowOwner = pOwner;
|
2024-06-08 10:07:59 +02:00
|
|
|
m_pResource = pSurface;
|
2024-02-29 16:07:11 +01:00
|
|
|
init();
|
|
|
|
m_bInert = false;
|
|
|
|
}
|
|
|
|
|
2024-06-08 10:07:59 +02:00
|
|
|
void CWLSurface::assign(SP<CWLSurfaceResource> pSurface, PHLLS pOwner) {
|
2024-02-29 16:07:11 +01:00
|
|
|
m_pLayerOwner = pOwner;
|
2024-06-08 10:07:59 +02:00
|
|
|
m_pResource = pSurface;
|
2024-02-29 16:07:11 +01:00
|
|
|
init();
|
|
|
|
m_bInert = false;
|
|
|
|
}
|
|
|
|
|
2024-06-08 10:07:59 +02:00
|
|
|
void CWLSurface::assign(SP<CWLSurfaceResource> pSurface, CSubsurface* pOwner) {
|
2024-02-29 16:07:11 +01:00
|
|
|
m_pSubsurfaceOwner = pOwner;
|
2024-06-08 10:07:59 +02:00
|
|
|
m_pResource = pSurface;
|
2024-02-29 16:07:11 +01:00
|
|
|
init();
|
|
|
|
m_bInert = false;
|
|
|
|
}
|
|
|
|
|
2024-06-08 10:07:59 +02:00
|
|
|
void CWLSurface::assign(SP<CWLSurfaceResource> pSurface, CPopup* pOwner) {
|
2024-02-29 16:07:11 +01:00
|
|
|
m_pPopupOwner = pOwner;
|
2024-06-08 10:07:59 +02:00
|
|
|
m_pResource = pSurface;
|
2023-03-20 16:00:58 +01:00
|
|
|
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 {
|
2024-06-08 10:07:59 +02:00
|
|
|
return m_pResource;
|
2023-03-20 16:00:58 +01:00
|
|
|
}
|
|
|
|
|
2024-06-08 10:07:59 +02:00
|
|
|
SP<CWLSurfaceResource> CWLSurface::resource() const {
|
|
|
|
return m_pResource.lock();
|
2023-03-20 16:00:58 +01:00
|
|
|
}
|
|
|
|
|
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-06-08 10:07:59 +02:00
|
|
|
if (!m_pResource->current.buffer)
|
|
|
|
return false;
|
|
|
|
|
2024-04-27 13:43:12 +02:00
|
|
|
const auto O = m_pWindowOwner.lock();
|
|
|
|
|
2024-06-08 10:07:59 +02:00
|
|
|
return O->m_vReportedSize.x > m_pResource->current.buffer->size.x + 1 || O->m_vReportedSize.y > m_pResource->current.buffer->size.y + 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
|
|
|
}
|
|
|
|
|
2024-07-22 12:37:54 +02:00
|
|
|
Vector2D CWLSurface::correctSmallVecBuf() const {
|
|
|
|
if (!exists() || !small() || m_bFillIgnoreSmall || !m_pResource->current.buffer)
|
|
|
|
return {};
|
|
|
|
|
|
|
|
const auto SIZE = getViewporterCorrectedSize();
|
|
|
|
const auto BS = m_pResource->current.buffer->size;
|
|
|
|
|
|
|
|
return Vector2D{(BS.x - SIZE.x) / 2, (BS.y - SIZE.y) / 2}.clamp({}, {INFINITY, INFINITY});
|
|
|
|
}
|
|
|
|
|
2023-10-25 23:05:04 +02:00
|
|
|
Vector2D CWLSurface::getViewporterCorrectedSize() const {
|
2024-06-08 10:07:59 +02:00
|
|
|
if (!exists() || !m_pResource->current.buffer)
|
2023-10-25 23:05:04 +02:00
|
|
|
return {};
|
|
|
|
|
2024-06-08 10:07:59 +02:00
|
|
|
return m_pResource->current.viewport.hasDestination ? m_pResource->current.viewport.destination : m_pResource->current.buffer->size;
|
2023-10-25 23:05:04 +02:00
|
|
|
}
|
|
|
|
|
2024-07-22 12:37:54 +02:00
|
|
|
CRegion CWLSurface::computeDamage() const {
|
2024-06-08 10:07:59 +02:00
|
|
|
if (!m_pResource->current.buffer)
|
|
|
|
return {};
|
|
|
|
|
|
|
|
CRegion damage = m_pResource->accumulateCurrentBufferDamage();
|
2024-06-19 16:20:06 +02:00
|
|
|
damage.transform(wlTransformToHyprutils(m_pResource->current.transform), m_pResource->current.buffer->size.x, m_pResource->current.buffer->size.y);
|
2024-02-19 12:24:54 +01:00
|
|
|
|
2024-07-22 12:37:54 +02:00
|
|
|
const auto BUFSIZE = m_pResource->current.buffer->size;
|
|
|
|
const auto CORRECTVEC = correctSmallVecBuf();
|
2024-02-19 12:24:54 +01:00
|
|
|
|
2024-06-08 10:07:59 +02:00
|
|
|
if (m_pResource->current.viewport.hasSource)
|
|
|
|
damage.intersect(m_pResource->current.viewport.source);
|
2024-02-20 16:21:30 +01:00
|
|
|
|
2024-06-08 10:07:59 +02:00
|
|
|
const auto SCALEDSRCSIZE =
|
|
|
|
m_pResource->current.viewport.hasSource ? m_pResource->current.viewport.source.size() * m_pResource->current.scale : m_pResource->current.buffer->size;
|
2024-02-20 16:21:30 +01:00
|
|
|
|
2024-07-22 12:37:54 +02:00
|
|
|
damage.scale({BUFSIZE.x / SCALEDSRCSIZE.x, BUFSIZE.y / SCALEDSRCSIZE.y});
|
2024-02-19 12:24:54 +01:00
|
|
|
damage.translate(CORRECTVEC);
|
|
|
|
|
2024-07-22 12:37:54 +02:00
|
|
|
// go from buffer coords in the damage to hl logical
|
|
|
|
|
|
|
|
const auto BOX = getSurfaceBoxGlobal();
|
|
|
|
const Vector2D SCALE = BOX.has_value() ? BOX->size() / m_pResource->current.buffer->size :
|
|
|
|
Vector2D{1.0 / m_pResource->current.scale, 1.0 / m_pResource->current.scale /* Wrong... but we can't really do better */};
|
|
|
|
|
|
|
|
damage.scale(SCALE);
|
|
|
|
|
2024-07-23 19:56:42 +02:00
|
|
|
if (m_pWindowOwner)
|
|
|
|
damage.scale(m_pWindowOwner->m_fX11SurfaceScaledBy); // fix xwayland:force_zero_scaling stuff that will be fucked by the above a bit
|
|
|
|
|
2024-02-19 12:24:54 +01:00
|
|
|
return damage;
|
|
|
|
}
|
|
|
|
|
2023-03-20 16:00:58 +01:00
|
|
|
void CWLSurface::destroy() {
|
2024-06-08 10:07:59 +02:00
|
|
|
if (!m_pResource)
|
2023-03-20 16:00:58 +01:00
|
|
|
return;
|
|
|
|
|
2024-04-27 00:55:41 +02:00
|
|
|
events.destroy.emit();
|
|
|
|
|
2024-03-02 22:04:55 +01:00
|
|
|
m_pConstraint.reset();
|
|
|
|
|
2024-06-08 10:07:59 +02:00
|
|
|
listeners.destroy.reset();
|
|
|
|
m_pResource->hlSurface.reset();
|
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-06-08 10:07:59 +02:00
|
|
|
if (g_pHyprRenderer && g_pHyprRenderer->m_sLastCursorData.surf && g_pHyprRenderer->m_sLastCursorData.surf->get() == this)
|
2023-11-26 15:53:22 +01:00
|
|
|
g_pHyprRenderer->m_sLastCursorData.surf.reset();
|
2023-03-20 16:00:58 +01:00
|
|
|
|
2024-06-08 10:07:59 +02:00
|
|
|
m_pResource.reset();
|
2023-03-23 01:22:43 +01:00
|
|
|
|
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() {
|
2024-06-08 10:07:59 +02:00
|
|
|
if (!m_pResource)
|
2023-03-20 16:00:58 +01:00
|
|
|
return;
|
|
|
|
|
2024-06-08 10:07:59 +02:00
|
|
|
RASSERT(!m_pResource->hlSurface, "Attempted to duplicate CWLSurface ownership!");
|
2023-03-20 16:00:58 +01:00
|
|
|
|
2024-06-08 10:07:59 +02:00
|
|
|
m_pResource->hlSurface = self.lock();
|
2023-03-20 16:00:58 +01:00
|
|
|
|
2024-06-08 10:07:59 +02:00
|
|
|
listeners.destroy = m_pResource->events.destroy.registerListener([this](std::any d) { destroy(); });
|
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-07-22 12:37:54 +02:00
|
|
|
PHLWINDOW CWLSurface::getWindow() const {
|
2024-04-27 13:43:12 +02:00
|
|
|
return m_pWindowOwner.lock();
|
2024-02-29 16:07:11 +01:00
|
|
|
}
|
|
|
|
|
2024-07-22 12:37:54 +02:00
|
|
|
PHLLS CWLSurface::getLayer() const {
|
2024-04-30 03:41:27 +02:00
|
|
|
return m_pLayerOwner.lock();
|
2024-02-29 16:07:11 +01:00
|
|
|
}
|
|
|
|
|
2024-07-22 12:37:54 +02:00
|
|
|
CPopup* CWLSurface::getPopup() const {
|
2024-02-29 16:07:11 +01:00
|
|
|
return m_pPopupOwner;
|
|
|
|
}
|
|
|
|
|
2024-07-22 12:37:54 +02:00
|
|
|
CSubsurface* CWLSurface::getSubsurface() const {
|
2024-02-29 16:07:11 +01:00
|
|
|
return m_pSubsurfaceOwner;
|
|
|
|
}
|
|
|
|
|
2024-07-22 12:37:54 +02:00
|
|
|
bool CWLSurface::desktopComponent() const {
|
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
|
|
|
}
|
|
|
|
|
2024-07-22 12:37:54 +02:00
|
|
|
std::optional<CBox> CWLSurface::getSurfaceBoxGlobal() const {
|
2024-02-29 16:07:11 +01:00
|
|
|
if (!desktopComponent())
|
|
|
|
return {};
|
|
|
|
|
2024-04-27 13:43:12 +02:00
|
|
|
if (!m_pWindowOwner.expired())
|
2024-05-05 18:16:00 +02:00
|
|
|
return m_pWindowOwner->getWindowMainSurfaceBox();
|
2024-04-30 03:41:27 +02:00
|
|
|
if (!m_pLayerOwner.expired())
|
2024-05-05 18:16:00 +02:00
|
|
|
return m_pLayerOwner->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-05-05 18:16:00 +02:00
|
|
|
void CWLSurface::appendConstraint(WP<CPointerConstraint> constraint) {
|
2024-04-27 00:55:41 +02:00
|
|
|
m_pConstraint = constraint;
|
2024-03-02 22:04:55 +01:00
|
|
|
}
|
|
|
|
|
2024-07-22 12:37:54 +02:00
|
|
|
SP<CPointerConstraint> CWLSurface::constraint() const {
|
2024-04-27 00:55:41 +02:00
|
|
|
return m_pConstraint.lock();
|
2024-03-02 22:04:55 +01:00
|
|
|
}
|
2024-05-05 00:46:10 +02:00
|
|
|
|
|
|
|
bool CWLSurface::visible() {
|
|
|
|
if (!m_pWindowOwner.expired())
|
|
|
|
return g_pHyprRenderer->shouldRenderWindow(m_pWindowOwner.lock());
|
|
|
|
if (!m_pLayerOwner.expired())
|
|
|
|
return true;
|
|
|
|
if (m_pPopupOwner)
|
|
|
|
return m_pPopupOwner->visible();
|
|
|
|
if (m_pSubsurfaceOwner)
|
|
|
|
return m_pSubsurfaceOwner->visible();
|
|
|
|
return true; // non-desktop, we don't know much.
|
|
|
|
}
|
2024-06-08 10:07:59 +02:00
|
|
|
|
|
|
|
SP<CWLSurface> CWLSurface::fromResource(SP<CWLSurfaceResource> pSurface) {
|
|
|
|
if (!pSurface)
|
|
|
|
return nullptr;
|
|
|
|
return pSurface->hlSurface.lock();
|
|
|
|
}
|
2024-07-27 15:03:52 +02:00
|
|
|
|
|
|
|
bool CWLSurface::keyboardFocusable() const {
|
|
|
|
if (m_pWindowOwner || m_pPopupOwner || m_pSubsurfaceOwner)
|
|
|
|
return true;
|
|
|
|
if (m_pLayerOwner)
|
|
|
|
return m_pLayerOwner->layerSurface->current.interactivity != ZWLR_LAYER_SURFACE_V1_KEYBOARD_INTERACTIVITY_NONE;
|
|
|
|
return false;
|
|
|
|
}
|