2023-03-20 15:00:58 +00:00
|
|
|
#include "WLSurface.hpp"
|
2025-01-17 15:21:35 +00:00
|
|
|
#include "LayerSurface.hpp"
|
2025-12-08 15:04:40 +00:00
|
|
|
#include "Window.hpp"
|
|
|
|
|
#include "../../protocols/core/Compositor.hpp"
|
|
|
|
|
#include "../../protocols/LayerShell.hpp"
|
|
|
|
|
#include "../../render/Renderer.hpp"
|
|
|
|
|
|
|
|
|
|
using namespace Desktop;
|
|
|
|
|
using namespace Desktop::View;
|
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
|
|
|
}
|
|
|
|
|
|
2025-12-08 15:04:40 +00:00
|
|
|
void CWLSurface::assign(SP<CWLSurfaceResource> pSurface, SP<IView> pOwner) {
|
|
|
|
|
m_view = 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-12-11 16:29:26 +00:00
|
|
|
if (!m_view || !m_view->aliveAndVisible() || m_view->type() != VIEW_TYPE_WINDOW || !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-12-08 15:04:40 +00:00
|
|
|
const auto O = dynamicPointerCast<CWindow>(m_view.lock());
|
2025-09-21 19:27:56 +02:00
|
|
|
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-12-11 16:29:26 +00:00
|
|
|
if (!m_view || !m_view->aliveAndVisible() || m_view->type() != VIEW_TYPE_WINDOW || !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-12-08 15:04:40 +00:00
|
|
|
const auto O = dynamicPointerCast<CWindow>(m_view.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()) {
|
2025-12-08 15:04:40 +00:00
|
|
|
if (m_view->type() == VIEW_TYPE_WINDOW)
|
|
|
|
|
damage.intersect(CBox{{}, BOX->size() * dynamicPointerCast<CWindow>(m_view.lock())->m_X11SurfaceScaledBy});
|
2025-10-24 22:19:21 +01:00
|
|
|
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-12-08 15:04:40 +00:00
|
|
|
m_view.reset();
|
|
|
|
|
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-12-18 17:23:24 +00:00
|
|
|
Log::logger->log(Log::DEBUG, "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-12-18 17:23:24 +00:00
|
|
|
Log::logger->log(Log::DEBUG, "CWLSurface {:x} called init()", rc<uintptr_t>(this));
|
2024-02-29 15:07:11 +00:00
|
|
|
}
|
|
|
|
|
|
2025-12-08 15:04:40 +00:00
|
|
|
SP<IView> CWLSurface::view() const {
|
|
|
|
|
return m_view.lock();
|
2024-02-29 15:07:11 +00:00
|
|
|
}
|
|
|
|
|
|
2024-07-22 12:37:54 +02:00
|
|
|
bool CWLSurface::desktopComponent() const {
|
2025-12-08 15:04:40 +00:00
|
|
|
return m_view && m_view->visible();
|
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-12-08 15:04:40 +00:00
|
|
|
return m_view->surfaceLogicalBox();
|
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
|
|
|
|
2025-12-08 15:04:40 +00:00
|
|
|
SP<Desktop::View::CWLSurface> CWLSurface::fromResource(SP<CWLSurfaceResource> pSurface) {
|
2024-06-08 10:07:59 +02:00
|
|
|
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-12-08 15:04:40 +00:00
|
|
|
if (!m_view)
|
|
|
|
|
return false;
|
|
|
|
|
if (m_view->type() == VIEW_TYPE_WINDOW || m_view->type() == VIEW_TYPE_SUBSURFACE || m_view->type() == VIEW_TYPE_POPUP)
|
2024-07-27 15:03:52 +02:00
|
|
|
return true;
|
2025-12-08 15:04:40 +00:00
|
|
|
if (const auto LS = CLayerSurface::fromView(m_view.lock()); LS && LS->m_layerSurface)
|
|
|
|
|
return LS->m_layerSurface->m_current.interactivity != ZWLR_LAYER_SURFACE_V1_KEYBOARD_INTERACTIVITY_NONE;
|
2024-07-27 15:03:52 +02:00
|
|
|
return false;
|
|
|
|
|
}
|