summaryrefslogtreecommitdiff
path: root/src/protocols/SessionLock.cpp
diff options
context:
space:
mode:
authorVaxry <43317083+vaxerski@users.noreply.github.com>2024-06-08 10:07:59 +0200
committerGitHub <noreply@github.com>2024-06-08 10:07:59 +0200
commit6967a31450441fc5605c05db6f65505dace4b263 (patch)
tree255a3cff7f3e2eb8a50c952eab9b270a7937561d /src/protocols/SessionLock.cpp
parentc31d9ef4172452f6f219f91d9b87a24d91f0cf3a (diff)
wayland/core: move to new impl (#6268)
* wayland/core/dmabuf: move to new impl it's the final countdown
Diffstat (limited to 'src/protocols/SessionLock.cpp')
-rw-r--r--src/protocols/SessionLock.cpp89
1 files changed, 42 insertions, 47 deletions
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<CExtSessionLockSurfaceV1> resource_, wlr_surface* surface_, CMonitor* pMonitor_, WP<CSessionLock> owner_) :
+CSessionLockSurface::CSessionLockSurface(SP<CExtSessionLockSurfaceV1> resource_, SP<CWLSurfaceResource> surface_, CMonitor* pMonitor_, WP<CSessionLock> owner_) :
resource(resource_), sessionLock(owner_), pSurface(surface_), pMonitor(pMonitor_) {
if (!resource->resource())
return;
@@ -21,45 +23,38 @@ CSessionLockSurface::CSessionLockSurface(SP<CExtSessionLockSurfaceV1> 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<CExtSessionLockSurfaceV1> 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<CWLSurfaceResource> CSessionLockSurface::surface() {
+ return pSurface.lock();
}
CSessionLock::CSessionLock(SP<CExtSessionLockV1> 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<CSessionLock> sessionLock;
for (auto& l : m_vLocks) {