From 6967a31450441fc5605c05db6f65505dace4b263 Mon Sep 17 00:00:00 2001 From: Vaxry <43317083+vaxerski@users.noreply.github.com> Date: Sat, 8 Jun 2024 10:07:59 +0200 Subject: wayland/core: move to new impl (#6268) * wayland/core/dmabuf: move to new impl it's the final countdown --- src/protocols/SessionLock.cpp | 89 ++++++++++++++++++++----------------------- 1 file changed, 42 insertions(+), 47 deletions(-) (limited to 'src/protocols/SessionLock.cpp') diff --git a/src/protocols/SessionLock.cpp b/src/protocols/SessionLock.cpp index fd803eda..ae45b0f1 100644 --- a/src/protocols/SessionLock.cpp +++ b/src/protocols/SessionLock.cpp @@ -2,10 +2,12 @@ #include "../Compositor.hpp" #include "../managers/SeatManager.hpp" #include "FractionalScale.hpp" +#include "core/Compositor.hpp" +#include "core/Output.hpp" #define LOGM PROTO::sessionLock->protoLog -CSessionLockSurface::CSessionLockSurface(SP resource_, wlr_surface* surface_, CMonitor* pMonitor_, WP owner_) : +CSessionLockSurface::CSessionLockSurface(SP resource_, SP surface_, CMonitor* pMonitor_, WP owner_) : resource(resource_), sessionLock(owner_), pSurface(surface_), pMonitor(pMonitor_) { if (!resource->resource()) return; @@ -21,45 +23,38 @@ CSessionLockSurface::CSessionLockSurface(SP resource_, resource->setAckConfigure([this](CExtSessionLockSurfaceV1* r, uint32_t serial) { ackdConfigure = true; }); - hyprListener_surfaceCommit.initCallback( - &pSurface->events.commit, - [this](void* owner, void* data) { - if (pSurface->pending.buffer_width <= 0 || pSurface->pending.buffer_height <= 0) { - LOGM(ERR, "SessionLock attached a null buffer"); - resource->error(EXT_SESSION_LOCK_SURFACE_V1_ERROR_NULL_BUFFER, "Null buffer attached"); - return; - } - - if (!ackdConfigure) { - LOGM(ERR, "SessionLock committed without an ack"); - resource->error(EXT_SESSION_LOCK_SURFACE_V1_ERROR_COMMIT_BEFORE_FIRST_ACK, "Committed surface before first ack"); - return; - } - - if (committed) - events.commit.emit(); - else { - wlr_surface_map(pSurface); - events.map.emit(); - } - committed = true; - }, - this, "SessionLockSurface"); - - hyprListener_surfaceDestroy.initCallback( - &pSurface->events.destroy, - [this](void* owner, void* data) { - LOGM(WARN, "SessionLockSurface object remains but surface is being destroyed???"); - wlr_surface_unmap(pSurface); - hyprListener_surfaceCommit.removeCallback(); - hyprListener_surfaceDestroy.removeCallback(); - - if (g_pCompositor->m_pLastFocus == pSurface) - g_pCompositor->m_pLastFocus = nullptr; - - pSurface = nullptr; - }, - this, "SessionLockSurface"); + listeners.surfaceCommit = pSurface->events.commit.registerListener([this](std::any d) { + if (!pSurface->current.buffer) { + LOGM(ERR, "SessionLock attached a null buffer"); + resource->error(EXT_SESSION_LOCK_SURFACE_V1_ERROR_NULL_BUFFER, "Null buffer attached"); + return; + } + + if (!ackdConfigure) { + LOGM(ERR, "SessionLock committed without an ack"); + resource->error(EXT_SESSION_LOCK_SURFACE_V1_ERROR_COMMIT_BEFORE_FIRST_ACK, "Committed surface before first ack"); + return; + } + + if (committed) + events.commit.emit(); + else { + pSurface->map(); + events.map.emit(); + } + committed = true; + }); + + listeners.surfaceDestroy = pSurface->events.destroy.registerListener([this](std::any d) { + LOGM(WARN, "SessionLockSurface object remains but surface is being destroyed???"); + pSurface->unmap(); + listeners.surfaceCommit.reset(); + listeners.surfaceDestroy.reset(); + if (g_pCompositor->m_pLastFocus == pSurface) + g_pCompositor->m_pLastFocus.reset(); + + pSurface.reset(); + }); PROTO::fractional->sendScale(surface_, pMonitor_->scale); @@ -70,9 +65,9 @@ CSessionLockSurface::CSessionLockSurface(SP resource_, CSessionLockSurface::~CSessionLockSurface() { if (pSurface && pSurface->mapped) - wlr_surface_unmap(pSurface); - hyprListener_surfaceCommit.removeCallback(); - hyprListener_surfaceDestroy.removeCallback(); + pSurface->unmap(); + listeners.surfaceCommit.reset(); + listeners.surfaceDestroy.reset(); events.destroy.emit(); // just in case. } @@ -93,8 +88,8 @@ CMonitor* CSessionLockSurface::monitor() { return pMonitor; } -wlr_surface* CSessionLockSurface::surface() { - return pSurface; +SP CSessionLockSurface::surface() { + return pSurface.lock(); } CSessionLock::CSessionLock(SP resource_) : resource(resource_) { @@ -195,8 +190,8 @@ void CSessionLockProtocol::onLock(CExtSessionLockManagerV1* pMgr, uint32_t id) { void CSessionLockProtocol::onGetLockSurface(CExtSessionLockV1* lock, uint32_t id, wl_resource* surface, wl_resource* output) { LOGM(LOG, "New sessionLockSurface with id {}", id); - auto PSURFACE = wlr_surface_from_resource(surface); - auto PMONITOR = g_pCompositor->getMonitorFromOutput(wlr_output_from_resource(output)); + auto PSURFACE = CWLSurfaceResource::fromResource(surface); + auto PMONITOR = CWLOutputResource::fromResource(output)->monitor.get(); SP sessionLock; for (auto& l : m_vLocks) { -- cgit v1.2.3