2023-03-20 15:00:58 +00:00
|
|
|
#include "WLSurface.hpp"
|
2025-01-17 15:21:35 +00:00
|
|
|
#include "LayerSurface.hpp"
|
|
|
|
|
#include "../desktop/Window.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"
|
2025-01-17 15:21:35 +00:00
|
|
|
#include "../render/Renderer.hpp"
|
2023-03-20 15:00:58 +00:00
|
|
|
|
2024-06-08 10:07:59 +02:00
|
|
|
void CWLSurface::assign(SP<CWLSurfaceResource> pSurface) {
|
2025-04-25 02:37:12 +02:00
|
|
|
m_resource = pSurface;
|
2023-03-20 15:00:58 +00:00
|
|
|
init();
|
2025-04-25 02:37:12 +02:00
|
|
|
m_inert = false;
|
2023-03-20 15:00:58 +00:00
|
|
|
}
|
|
|
|
|
|
2024-06-08 10:07:59 +02:00
|
|
|
void CWLSurface::assign(SP<CWLSurfaceResource> pSurface, PHLWINDOW pOwner) {
|
2025-04-25 02:37:12 +02:00
|
|
|
m_windowOwner = pOwner;
|
|
|
|
|
m_resource = pSurface;
|
2024-02-29 15:07:11 +00:00
|
|
|
init();
|
2025-04-25 02:37:12 +02:00
|
|
|
m_inert = false;
|
2024-02-29 15:07:11 +00:00
|
|
|
}
|
|
|
|
|
|
2024-06-08 10:07:59 +02:00
|
|
|
void CWLSurface::assign(SP<CWLSurfaceResource> pSurface, PHLLS pOwner) {
|
2025-04-25 02:37:12 +02:00
|
|
|
m_layerOwner = pOwner;
|
|
|
|
|
m_resource = pSurface;
|
2024-02-29 15:07:11 +00:00
|
|
|
init();
|
2025-04-25 02:37:12 +02:00
|
|
|
m_inert = false;
|
2024-02-29 15:07:11 +00:00
|
|
|
}
|
|
|
|
|
|
2024-06-08 10:07:59 +02:00
|
|
|
void CWLSurface::assign(SP<CWLSurfaceResource> pSurface, CSubsurface* pOwner) {
|
2025-04-25 02:37:12 +02:00
|
|
|
m_subsurfaceOwner = pOwner;
|
|
|
|
|
m_resource = pSurface;
|
2024-02-29 15:07:11 +00:00
|
|
|
init();
|
2025-04-25 02:37:12 +02:00
|
|
|
m_inert = false;
|
2024-02-29 15:07:11 +00:00
|
|
|
}
|
|
|
|
|
|
2024-06-08 10:07:59 +02:00
|
|
|
void CWLSurface::assign(SP<CWLSurfaceResource> pSurface, CPopup* pOwner) {
|
2025-04-25 02:37:12 +02:00
|
|
|
m_popupOwner = pOwner;
|
|
|
|
|
m_resource = pSurface;
|
2023-03-20 15:00:58 +00:00
|
|
|
init();
|
2025-04-25 02:37:12 +02:00
|
|
|
m_inert = false;
|
2023-03-20 15:00:58 +00:00
|
|
|
}
|
|
|
|
|
|
2023-03-23 00:39:32 +00:00
|
|
|
void CWLSurface::unassign() {
|
|
|
|
|
destroy();
|
|
|
|
|
}
|
|
|
|
|
|
2023-03-20 15:00:58 +00:00
|
|
|
CWLSurface::~CWLSurface() {
|
|
|
|
|
destroy();
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
bool CWLSurface::exists() const {
|
2025-04-25 02:37:12 +02:00
|
|
|
return m_resource;
|
2023-03-20 15:00:58 +00:00
|
|
|
}
|
|
|
|
|
|
2024-06-08 10:07:59 +02:00
|
|
|
SP<CWLSurfaceResource> CWLSurface::resource() const {
|
2025-04-25 02:37:12 +02:00
|
|
|
return m_resource.lock();
|
2023-03-20 15:00:58 +00:00
|
|
|
}
|
|
|
|
|
|
2023-10-20 20:15:41 +01:00
|
|
|
bool CWLSurface::small() const {
|
2025-04-25 02:37:12 +02:00
|
|
|
if (!validMapped(m_windowOwner) || !exists())
|
2023-10-20 20:15:41 +01:00
|
|
|
return false;
|
|
|
|
|
|
2025-05-03 16:02:49 +02:00
|
|
|
if (!m_resource->m_current.texture)
|
2024-06-08 10:07:59 +02:00
|
|
|
return false;
|
|
|
|
|
|
2025-09-21 19:27:56 +02:00
|
|
|
const auto O = m_windowOwner.lock();
|
|
|
|
|
const auto REPORTED_SIZE = O->getReportedSize();
|
2024-04-27 12:43:12 +01:00
|
|
|
|
2025-09-21 19:27:56 +02:00
|
|
|
return REPORTED_SIZE.x > m_resource->m_current.size.x + 1 || REPORTED_SIZE.y > m_resource->m_current.size.y + 1;
|
2023-10-20 20:15:41 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
Vector2D CWLSurface::correctSmallVec() const {
|
2025-04-25 02:37:12 +02:00
|
|
|
if (!validMapped(m_windowOwner) || !exists() || !small() || m_fillIgnoreSmall)
|
2023-10-20 20:15:41 +01:00
|
|
|
return {};
|
|
|
|
|
|
2023-10-25 22:05:04 +01:00
|
|
|
const auto SIZE = getViewporterCorrectedSize();
|
2025-04-25 02:37:12 +02:00
|
|
|
const auto O = m_windowOwner.lock();
|
2025-09-21 19:27:56 +02:00
|
|
|
const auto REP = O->getReportedSize();
|
2023-10-25 22:05:04 +01:00
|
|
|
|
2025-09-21 19:27:56 +02:00
|
|
|
return Vector2D{(REP.x - SIZE.x) / 2, (REP.y - SIZE.y) / 2}.clamp({}, {INFINITY, INFINITY}) * (O->m_realSize->value() / REP);
|
2023-10-20 20:15:41 +01:00
|
|
|
}
|
|
|
|
|
|
2024-07-22 12:37:54 +02:00
|
|
|
Vector2D CWLSurface::correctSmallVecBuf() const {
|
2025-05-03 16:02:49 +02:00
|
|
|
if (!exists() || !small() || m_fillIgnoreSmall || !m_resource->m_current.texture)
|
2024-07-22 12:37:54 +02:00
|
|
|
return {};
|
|
|
|
|
|
|
|
|
|
const auto SIZE = getViewporterCorrectedSize();
|
2025-05-03 16:02:49 +02:00
|
|
|
const auto BS = m_resource->m_current.bufferSize;
|
2024-07-22 12:37:54 +02:00
|
|
|
|
|
|
|
|
return Vector2D{(BS.x - SIZE.x) / 2, (BS.y - SIZE.y) / 2}.clamp({}, {INFINITY, INFINITY});
|
|
|
|
|
}
|
|
|
|
|
|
2023-10-25 22:05:04 +01:00
|
|
|
Vector2D CWLSurface::getViewporterCorrectedSize() const {
|
2025-05-03 16:02:49 +02:00
|
|
|
if (!exists() || !m_resource->m_current.texture)
|
2023-10-25 22:05:04 +01:00
|
|
|
return {};
|
|
|
|
|
|
2025-05-03 16:02:49 +02:00
|
|
|
return m_resource->m_current.viewport.hasDestination ? m_resource->m_current.viewport.destination : m_resource->m_current.bufferSize;
|
2023-10-25 22:05:04 +01:00
|
|
|
}
|
|
|
|
|
|
2024-07-22 12:37:54 +02:00
|
|
|
CRegion CWLSurface::computeDamage() const {
|
2025-05-03 16:02:49 +02:00
|
|
|
if (!m_resource->m_current.texture)
|
2024-06-08 10:07:59 +02:00
|
|
|
return {};
|
|
|
|
|
|
2025-05-03 16:02:49 +02:00
|
|
|
CRegion damage = m_resource->m_current.accumulateBufferDamage();
|
|
|
|
|
damage.transform(wlTransformToHyprutils(m_resource->m_current.transform), m_resource->m_current.bufferSize.x, m_resource->m_current.bufferSize.y);
|
2024-02-19 11:24:54 +00:00
|
|
|
|
2025-05-03 16:02:49 +02:00
|
|
|
const auto BUFSIZE = m_resource->m_current.bufferSize;
|
2024-07-22 12:37:54 +02:00
|
|
|
const auto CORRECTVEC = correctSmallVecBuf();
|
2024-02-19 11:24:54 +00:00
|
|
|
|
2025-05-03 16:02:49 +02:00
|
|
|
if (m_resource->m_current.viewport.hasSource)
|
|
|
|
|
damage.intersect(m_resource->m_current.viewport.source);
|
2024-02-20 15:21:30 +00:00
|
|
|
|
2025-05-03 16:02:49 +02:00
|
|
|
const auto SCALEDSRCSIZE =
|
|
|
|
|
m_resource->m_current.viewport.hasSource ? m_resource->m_current.viewport.source.size() * m_resource->m_current.scale : m_resource->m_current.bufferSize;
|
2024-02-20 15:21:30 +00:00
|
|
|
|
2024-07-22 12:37:54 +02:00
|
|
|
damage.scale({BUFSIZE.x / SCALEDSRCSIZE.x, BUFSIZE.y / SCALEDSRCSIZE.y});
|
2024-02-19 11:24:54 +00:00
|
|
|
damage.translate(CORRECTVEC);
|
|
|
|
|
|
2024-07-22 12:37:54 +02:00
|
|
|
// go from buffer coords in the damage to hl logical
|
|
|
|
|
|
2025-10-19 02:56:55 +02:00
|
|
|
const auto BOX = getSurfaceBoxGlobal();
|
|
|
|
|
const auto SURFSIZE = m_resource->m_current.size;
|
|
|
|
|
const Vector2D SCALE = SURFSIZE / m_resource->m_current.bufferSize;
|
2024-07-22 12:37:54 +02:00
|
|
|
|
|
|
|
|
damage.scale(SCALE);
|
2025-10-24 22:19:21 +01:00
|
|
|
if (BOX.has_value()) {
|
|
|
|
|
if (m_windowOwner)
|
|
|
|
|
damage.intersect(CBox{{}, BOX->size() * m_windowOwner->m_X11SurfaceScaledBy});
|
|
|
|
|
else
|
|
|
|
|
damage.intersect(CBox{{}, BOX->size()});
|
|
|
|
|
}
|
2024-07-23 19:56:42 +02:00
|
|
|
|
2024-02-19 11:24:54 +00:00
|
|
|
return damage;
|
|
|
|
|
}
|
|
|
|
|
|
2023-03-20 15:00:58 +00:00
|
|
|
void CWLSurface::destroy() {
|
2025-04-25 02:37:12 +02:00
|
|
|
if (!m_resource)
|
2023-03-20 15:00:58 +00:00
|
|
|
return;
|
|
|
|
|
|
2025-04-25 02:37:12 +02:00
|
|
|
m_events.destroy.emit();
|
2024-04-26 23:55:41 +01:00
|
|
|
|
2025-04-25 02:37:12 +02:00
|
|
|
m_constraint.reset();
|
2024-03-02 21:04:55 +00:00
|
|
|
|
2025-04-25 02:37:12 +02:00
|
|
|
m_listeners.destroy.reset();
|
2025-05-03 16:02:49 +02:00
|
|
|
m_resource->m_hlSurface.reset();
|
2025-04-25 02:37:12 +02:00
|
|
|
m_windowOwner.reset();
|
|
|
|
|
m_layerOwner.reset();
|
|
|
|
|
m_popupOwner = nullptr;
|
|
|
|
|
m_subsurfaceOwner = nullptr;
|
|
|
|
|
m_inert = true;
|
2023-03-20 15:00:58 +00:00
|
|
|
|
2025-05-05 23:44:49 +02:00
|
|
|
if (g_pHyprRenderer && g_pHyprRenderer->m_lastCursorData.surf && g_pHyprRenderer->m_lastCursorData.surf->get() == this)
|
|
|
|
|
g_pHyprRenderer->m_lastCursorData.surf.reset();
|
2023-03-20 15:00:58 +00:00
|
|
|
|
2025-04-25 02:37:12 +02:00
|
|
|
m_resource.reset();
|
2023-03-23 00:22:43 +00:00
|
|
|
|
2025-08-14 19:44:56 +05:00
|
|
|
Debug::log(LOG, "CWLSurface {:x} called destroy()", rc<uintptr_t>(this));
|
2023-03-20 15:00:58 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
void CWLSurface::init() {
|
2025-04-25 02:37:12 +02:00
|
|
|
if (!m_resource)
|
2023-03-20 15:00:58 +00:00
|
|
|
return;
|
|
|
|
|
|
2025-05-03 16:02:49 +02:00
|
|
|
RASSERT(!m_resource->m_hlSurface, "Attempted to duplicate CWLSurface ownership!");
|
2023-03-20 15:00:58 +00:00
|
|
|
|
2025-05-03 16:02:49 +02:00
|
|
|
m_resource->m_hlSurface = m_self.lock();
|
2023-03-20 15:00:58 +00:00
|
|
|
|
2025-07-08 09:56:40 -07:00
|
|
|
m_listeners.destroy = m_resource->m_events.destroy.listen([this] { destroy(); });
|
2023-03-20 15:00:58 +00:00
|
|
|
|
2025-08-14 19:44:56 +05:00
|
|
|
Debug::log(LOG, "CWLSurface {:x} called init()", rc<uintptr_t>(this));
|
2024-02-29 15:07:11 +00:00
|
|
|
}
|
|
|
|
|
|
2024-07-22 12:37:54 +02:00
|
|
|
PHLWINDOW CWLSurface::getWindow() const {
|
2025-04-25 02:37:12 +02:00
|
|
|
return m_windowOwner.lock();
|
2024-02-29 15:07:11 +00:00
|
|
|
}
|
|
|
|
|
|
2024-07-22 12:37:54 +02:00
|
|
|
PHLLS CWLSurface::getLayer() const {
|
2025-04-25 02:37:12 +02:00
|
|
|
return m_layerOwner.lock();
|
2024-02-29 15:07:11 +00:00
|
|
|
}
|
|
|
|
|
|
2024-07-22 12:37:54 +02:00
|
|
|
CPopup* CWLSurface::getPopup() const {
|
2025-04-25 02:37:12 +02:00
|
|
|
return m_popupOwner;
|
2024-02-29 15:07:11 +00:00
|
|
|
}
|
|
|
|
|
|
2024-07-22 12:37:54 +02:00
|
|
|
CSubsurface* CWLSurface::getSubsurface() const {
|
2025-04-25 02:37:12 +02:00
|
|
|
return m_subsurfaceOwner;
|
2024-02-29 15:07:11 +00:00
|
|
|
}
|
|
|
|
|
|
2024-07-22 12:37:54 +02:00
|
|
|
bool CWLSurface::desktopComponent() const {
|
2025-04-25 02:37:12 +02:00
|
|
|
return !m_layerOwner.expired() || !m_windowOwner.expired() || m_subsurfaceOwner || m_popupOwner;
|
2024-02-29 15:07:11 +00:00
|
|
|
}
|
|
|
|
|
|
2024-07-22 12:37:54 +02:00
|
|
|
std::optional<CBox> CWLSurface::getSurfaceBoxGlobal() const {
|
2024-02-29 15:07:11 +00:00
|
|
|
if (!desktopComponent())
|
|
|
|
|
return {};
|
|
|
|
|
|
2025-04-25 02:37:12 +02:00
|
|
|
if (!m_windowOwner.expired())
|
|
|
|
|
return m_windowOwner->getWindowMainSurfaceBox();
|
|
|
|
|
if (!m_layerOwner.expired())
|
|
|
|
|
return m_layerOwner->m_geometry;
|
|
|
|
|
if (m_popupOwner)
|
|
|
|
|
return CBox{m_popupOwner->coordsGlobal(), m_popupOwner->size()};
|
|
|
|
|
if (m_subsurfaceOwner)
|
|
|
|
|
return CBox{m_subsurfaceOwner->coordsGlobal(), m_subsurfaceOwner->size()};
|
2024-02-29 15:07:11 +00:00
|
|
|
|
|
|
|
|
return {};
|
2024-03-02 01:35:17 +01:00
|
|
|
}
|
2024-03-02 21:04:55 +00:00
|
|
|
|
2024-05-05 17:16:00 +01:00
|
|
|
void CWLSurface::appendConstraint(WP<CPointerConstraint> constraint) {
|
2025-04-25 02:37:12 +02:00
|
|
|
m_constraint = constraint;
|
2024-03-02 21:04:55 +00:00
|
|
|
}
|
|
|
|
|
|
2024-07-22 12:37:54 +02:00
|
|
|
SP<CPointerConstraint> CWLSurface::constraint() const {
|
2025-04-25 02:37:12 +02:00
|
|
|
return m_constraint.lock();
|
2024-03-02 21:04:55 +00:00
|
|
|
}
|
2024-05-04 23:46:10 +01:00
|
|
|
|
|
|
|
|
bool CWLSurface::visible() {
|
2025-04-25 02:37:12 +02:00
|
|
|
if (!m_windowOwner.expired())
|
|
|
|
|
return g_pHyprRenderer->shouldRenderWindow(m_windowOwner.lock());
|
|
|
|
|
if (!m_layerOwner.expired())
|
2024-05-04 23:46:10 +01:00
|
|
|
return true;
|
2025-04-25 02:37:12 +02:00
|
|
|
if (m_popupOwner)
|
|
|
|
|
return m_popupOwner->visible();
|
|
|
|
|
if (m_subsurfaceOwner)
|
|
|
|
|
return m_subsurfaceOwner->visible();
|
2024-05-04 23:46:10 +01:00
|
|
|
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;
|
2025-05-03 16:02:49 +02:00
|
|
|
return pSurface->m_hlSurface.lock();
|
2024-06-08 10:07:59 +02:00
|
|
|
}
|
2024-07-27 15:03:52 +02:00
|
|
|
|
|
|
|
|
bool CWLSurface::keyboardFocusable() const {
|
2025-04-25 02:37:12 +02:00
|
|
|
if (m_windowOwner || m_popupOwner || m_subsurfaceOwner)
|
2024-07-27 15:03:52 +02:00
|
|
|
return true;
|
2025-04-25 02:37:12 +02:00
|
|
|
if (m_layerOwner && m_layerOwner->m_layerSurface)
|
2025-05-04 00:13:29 +02:00
|
|
|
return m_layerOwner->m_layerSurface->m_current.interactivity != ZWLR_LAYER_SURFACE_V1_KEYBOARD_INTERACTIVITY_NONE;
|
2024-07-27 15:03:52 +02:00
|
|
|
return false;
|
|
|
|
|
}
|