2024-04-30 16:32:05 +01:00
|
|
|
#include "SessionLock.hpp"
|
|
|
|
|
#include "../Compositor.hpp"
|
2024-05-10 18:27:57 +01:00
|
|
|
#include "../managers/SeatManager.hpp"
|
2024-05-02 15:13:47 +01:00
|
|
|
#include "FractionalScale.hpp"
|
2025-01-19 18:21:36 +00:00
|
|
|
#include "LockNotify.hpp"
|
2024-06-08 10:07:59 +02:00
|
|
|
#include "core/Compositor.hpp"
|
|
|
|
|
#include "core/Output.hpp"
|
2025-01-17 15:21:35 +00:00
|
|
|
#include "../helpers/Monitor.hpp"
|
2025-07-01 11:31:10 +02:00
|
|
|
#include "../render/Renderer.hpp"
|
2024-04-30 16:32:05 +01:00
|
|
|
|
2024-10-19 23:03:29 +01:00
|
|
|
CSessionLockSurface::CSessionLockSurface(SP<CExtSessionLockSurfaceV1> resource_, SP<CWLSurfaceResource> surface_, PHLMONITOR pMonitor_, WP<CSessionLock> owner_) :
|
2025-05-04 19:21:36 +02:00
|
|
|
m_resource(resource_), m_sessionLock(owner_), m_surface(surface_), m_monitor(pMonitor_) {
|
|
|
|
|
if UNLIKELY (!m_resource->resource())
|
2024-04-30 16:32:05 +01:00
|
|
|
return;
|
|
|
|
|
|
2025-05-04 19:21:36 +02:00
|
|
|
m_resource->setDestroy([this](CExtSessionLockSurfaceV1* r) {
|
|
|
|
|
m_events.destroy.emit();
|
2024-04-30 16:32:05 +01:00
|
|
|
PROTO::sessionLock->destroyResource(this);
|
|
|
|
|
});
|
2025-05-04 19:21:36 +02:00
|
|
|
m_resource->setOnDestroy([this](CExtSessionLockSurfaceV1* r) {
|
|
|
|
|
m_events.destroy.emit();
|
2024-04-30 16:32:05 +01:00
|
|
|
PROTO::sessionLock->destroyResource(this);
|
|
|
|
|
});
|
|
|
|
|
|
2025-05-04 19:21:36 +02:00
|
|
|
m_resource->setAckConfigure([this](CExtSessionLockSurfaceV1* r, uint32_t serial) { m_ackdConfigure = true; });
|
2024-04-30 16:32:05 +01:00
|
|
|
|
2025-07-08 09:56:40 -07:00
|
|
|
m_listeners.surfaceCommit = m_surface->m_events.commit.listen([this] {
|
2025-05-04 19:21:36 +02:00
|
|
|
if (!m_surface->m_current.texture) {
|
2024-06-08 10:07:59 +02:00
|
|
|
LOGM(ERR, "SessionLock attached a null buffer");
|
2025-05-04 19:21:36 +02:00
|
|
|
m_resource->error(EXT_SESSION_LOCK_SURFACE_V1_ERROR_NULL_BUFFER, "Null buffer attached");
|
2024-06-08 10:07:59 +02:00
|
|
|
return;
|
|
|
|
|
}
|
|
|
|
|
|
2025-05-04 19:21:36 +02:00
|
|
|
if (!m_ackdConfigure) {
|
2024-06-08 10:07:59 +02:00
|
|
|
LOGM(ERR, "SessionLock committed without an ack");
|
2025-05-04 19:21:36 +02:00
|
|
|
m_resource->error(EXT_SESSION_LOCK_SURFACE_V1_ERROR_COMMIT_BEFORE_FIRST_ACK, "Committed surface before first ack");
|
2024-06-08 10:07:59 +02:00
|
|
|
return;
|
|
|
|
|
}
|
|
|
|
|
|
2025-05-04 19:21:36 +02:00
|
|
|
if (m_committed)
|
|
|
|
|
m_events.commit.emit();
|
2024-06-08 10:07:59 +02:00
|
|
|
else {
|
2025-05-04 19:21:36 +02:00
|
|
|
m_surface->map();
|
|
|
|
|
m_events.map.emit();
|
2024-06-08 10:07:59 +02:00
|
|
|
}
|
2025-05-04 19:21:36 +02:00
|
|
|
m_committed = true;
|
2024-06-08 10:07:59 +02:00
|
|
|
});
|
|
|
|
|
|
2025-07-08 09:56:40 -07:00
|
|
|
m_listeners.surfaceDestroy = m_surface->m_events.destroy.listen([this] {
|
2024-06-08 10:07:59 +02:00
|
|
|
LOGM(WARN, "SessionLockSurface object remains but surface is being destroyed???");
|
2025-05-04 19:21:36 +02:00
|
|
|
m_surface->unmap();
|
|
|
|
|
m_listeners.surfaceCommit.reset();
|
|
|
|
|
m_listeners.surfaceDestroy.reset();
|
|
|
|
|
if (g_pCompositor->m_lastFocus == m_surface)
|
2025-04-22 15:23:29 +02:00
|
|
|
g_pCompositor->m_lastFocus.reset();
|
2024-06-08 10:07:59 +02:00
|
|
|
|
2025-05-04 19:21:36 +02:00
|
|
|
m_surface.reset();
|
2024-06-08 10:07:59 +02:00
|
|
|
});
|
2024-04-30 16:32:05 +01:00
|
|
|
|
2025-04-30 23:45:20 +02:00
|
|
|
PROTO::fractional->sendScale(surface_, pMonitor_->m_scale);
|
2024-05-02 15:13:47 +01:00
|
|
|
|
2024-04-30 16:32:05 +01:00
|
|
|
sendConfigure();
|
|
|
|
|
|
2025-07-08 09:56:40 -07:00
|
|
|
m_listeners.monitorMode = m_monitor->m_events.modeChanged.listen([this] { sendConfigure(); });
|
2024-04-30 16:32:05 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
CSessionLockSurface::~CSessionLockSurface() {
|
2025-05-04 19:21:36 +02:00
|
|
|
if (m_surface && m_surface->m_mapped)
|
|
|
|
|
m_surface->unmap();
|
|
|
|
|
m_listeners.surfaceCommit.reset();
|
|
|
|
|
m_listeners.surfaceDestroy.reset();
|
|
|
|
|
m_events.destroy.emit(); // just in case.
|
2024-04-30 16:32:05 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
void CSessionLockSurface::sendConfigure() {
|
2025-05-04 19:21:36 +02:00
|
|
|
const auto SERIAL = g_pSeatManager->nextSerial(g_pSeatManager->seatResourceForClient(m_resource->client()));
|
|
|
|
|
m_resource->sendConfigure(SERIAL, m_monitor->m_size.x, m_monitor->m_size.y);
|
2024-04-30 16:32:05 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
bool CSessionLockSurface::good() {
|
2025-05-04 19:21:36 +02:00
|
|
|
return m_resource->resource();
|
2024-04-30 16:32:05 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
bool CSessionLockSurface::inert() {
|
2025-05-04 19:21:36 +02:00
|
|
|
return m_sessionLock.expired();
|
2024-04-30 16:32:05 +01:00
|
|
|
}
|
|
|
|
|
|
2024-10-19 23:03:29 +01:00
|
|
|
PHLMONITOR CSessionLockSurface::monitor() {
|
2025-05-04 19:21:36 +02:00
|
|
|
return m_monitor.lock();
|
2024-04-30 16:32:05 +01:00
|
|
|
}
|
|
|
|
|
|
2024-06-08 10:07:59 +02:00
|
|
|
SP<CWLSurfaceResource> CSessionLockSurface::surface() {
|
2025-05-04 19:21:36 +02:00
|
|
|
return m_surface.lock();
|
2024-04-30 16:32:05 +01:00
|
|
|
}
|
|
|
|
|
|
2025-05-04 19:21:36 +02:00
|
|
|
CSessionLock::CSessionLock(SP<CExtSessionLockV1> resource_) : m_resource(resource_) {
|
|
|
|
|
if UNLIKELY (!m_resource->resource())
|
2024-04-30 16:32:05 +01:00
|
|
|
return;
|
|
|
|
|
|
2025-05-04 19:21:36 +02:00
|
|
|
m_resource->setDestroy([this](CExtSessionLockV1* r) { PROTO::sessionLock->destroyResource(this); });
|
|
|
|
|
m_resource->setOnDestroy([this](CExtSessionLockV1* r) { PROTO::sessionLock->destroyResource(this); });
|
2024-04-30 16:32:05 +01:00
|
|
|
|
2025-05-04 19:21:36 +02:00
|
|
|
m_resource->setGetLockSurface([this](CExtSessionLockV1* r, uint32_t id, wl_resource* surf, wl_resource* output) {
|
|
|
|
|
if (m_inert) {
|
2024-04-30 16:32:05 +01:00
|
|
|
LOGM(ERR, "Lock is trying to send getLockSurface after it's inert");
|
|
|
|
|
return;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
PROTO::sessionLock->onGetLockSurface(r, id, surf, output);
|
|
|
|
|
});
|
|
|
|
|
|
2025-05-04 19:21:36 +02:00
|
|
|
m_resource->setUnlockAndDestroy([this](CExtSessionLockV1* r) {
|
|
|
|
|
if (m_inert) {
|
2024-05-07 18:42:55 +01:00
|
|
|
PROTO::sessionLock->destroyResource(this);
|
|
|
|
|
return;
|
|
|
|
|
}
|
|
|
|
|
|
2025-05-04 19:21:36 +02:00
|
|
|
PROTO::sessionLock->m_locked = false;
|
2024-06-11 17:18:51 +02:00
|
|
|
|
2025-01-19 18:21:36 +00:00
|
|
|
PROTO::lockNotify->onUnlocked();
|
|
|
|
|
|
2025-05-04 19:21:36 +02:00
|
|
|
m_events.unlockAndDestroy.emit();
|
2024-06-11 17:18:51 +02:00
|
|
|
|
2025-07-01 11:31:10 +02:00
|
|
|
// if lock tools have hidden it and doesnt restore it, we wont recieve a new cursor until the cursorshape protocol gives us one.
|
|
|
|
|
// so set it to left_ptr so the "desktop/wallpaper" doesnt end up missing a cursor until hover over a window sending us a shape.
|
|
|
|
|
g_pHyprRenderer->setCursorFromName("left_ptr");
|
|
|
|
|
|
2025-05-04 19:21:36 +02:00
|
|
|
m_inert = true;
|
2024-04-30 16:32:05 +01:00
|
|
|
PROTO::sessionLock->destroyResource(this);
|
|
|
|
|
});
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
CSessionLock::~CSessionLock() {
|
2025-05-04 19:21:36 +02:00
|
|
|
m_events.destroyed.emit();
|
2024-04-30 16:32:05 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
void CSessionLock::sendLocked() {
|
2025-05-04 19:21:36 +02:00
|
|
|
m_resource->sendLocked();
|
2025-01-19 18:21:36 +00:00
|
|
|
PROTO::lockNotify->onLocked();
|
2024-04-30 16:32:05 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
bool CSessionLock::good() {
|
2025-05-04 19:21:36 +02:00
|
|
|
return m_resource->resource();
|
2024-04-30 16:32:05 +01:00
|
|
|
}
|
|
|
|
|
|
2024-05-07 18:42:55 +01:00
|
|
|
void CSessionLock::sendDenied() {
|
2025-05-04 19:21:36 +02:00
|
|
|
m_inert = true;
|
|
|
|
|
m_resource->sendFinished();
|
2024-05-07 18:42:55 +01:00
|
|
|
}
|
|
|
|
|
|
2024-04-30 16:32:05 +01:00
|
|
|
CSessionLockProtocol::CSessionLockProtocol(const wl_interface* iface, const int& ver, const std::string& name) : IWaylandProtocol(iface, ver, name) {
|
|
|
|
|
;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
void CSessionLockProtocol::bindManager(wl_client* client, void* data, uint32_t ver, uint32_t id) {
|
2025-05-04 19:21:36 +02:00
|
|
|
const auto RESOURCE = m_managers.emplace_back(makeUnique<CExtSessionLockManagerV1>(client, ver, id)).get();
|
2024-04-30 16:32:05 +01:00
|
|
|
RESOURCE->setOnDestroy([this](CExtSessionLockManagerV1* p) { this->onManagerResourceDestroy(p->resource()); });
|
|
|
|
|
|
|
|
|
|
RESOURCE->setDestroy([this](CExtSessionLockManagerV1* pMgr) { this->onManagerResourceDestroy(pMgr->resource()); });
|
|
|
|
|
RESOURCE->setLock([this](CExtSessionLockManagerV1* pMgr, uint32_t id) { this->onLock(pMgr, id); });
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
void CSessionLockProtocol::onManagerResourceDestroy(wl_resource* res) {
|
2025-05-04 19:21:36 +02:00
|
|
|
std::erase_if(m_managers, [&](const auto& other) { return other->resource() == res; });
|
2024-04-30 16:32:05 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
void CSessionLockProtocol::destroyResource(CSessionLock* lock) {
|
2025-05-04 19:21:36 +02:00
|
|
|
std::erase_if(m_locks, [&](const auto& other) { return other.get() == lock; });
|
2024-04-30 16:32:05 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
void CSessionLockProtocol::destroyResource(CSessionLockSurface* surf) {
|
2025-05-04 19:21:36 +02:00
|
|
|
std::erase_if(m_lockSurfaces, [&](const auto& other) { return other.get() == surf; });
|
2024-04-30 16:32:05 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
void CSessionLockProtocol::onLock(CExtSessionLockManagerV1* pMgr, uint32_t id) {
|
|
|
|
|
|
|
|
|
|
LOGM(LOG, "New sessionLock with id {}", id);
|
|
|
|
|
|
2024-05-01 19:40:35 +01:00
|
|
|
const auto CLIENT = pMgr->client();
|
2025-05-04 19:21:36 +02:00
|
|
|
const auto RESOURCE = m_locks.emplace_back(makeShared<CSessionLock>(makeShared<CExtSessionLockV1>(CLIENT, pMgr->version(), id)));
|
2024-04-30 16:32:05 +01:00
|
|
|
|
2025-01-17 18:21:34 +01:00
|
|
|
if UNLIKELY (!RESOURCE->good()) {
|
2024-05-01 19:40:35 +01:00
|
|
|
pMgr->noMemory();
|
2025-05-04 19:21:36 +02:00
|
|
|
m_locks.pop_back();
|
2024-04-30 16:32:05 +01:00
|
|
|
return;
|
|
|
|
|
}
|
|
|
|
|
|
2025-05-04 19:21:36 +02:00
|
|
|
m_events.newLock.emit(RESOURCE);
|
2024-04-30 21:20:06 +01:00
|
|
|
|
2025-05-04 19:21:36 +02:00
|
|
|
m_locked = true;
|
2024-04-30 16:32:05 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
void CSessionLockProtocol::onGetLockSurface(CExtSessionLockV1* lock, uint32_t id, wl_resource* surface, wl_resource* output) {
|
|
|
|
|
LOGM(LOG, "New sessionLockSurface with id {}", id);
|
|
|
|
|
|
2024-06-08 10:07:59 +02:00
|
|
|
auto PSURFACE = CWLSurfaceResource::fromResource(surface);
|
2025-05-03 16:02:49 +02:00
|
|
|
auto PMONITOR = CWLOutputResource::fromResource(output)->m_monitor.lock();
|
2024-04-30 16:32:05 +01:00
|
|
|
|
|
|
|
|
SP<CSessionLock> sessionLock;
|
2025-05-04 19:21:36 +02:00
|
|
|
for (auto const& l : m_locks) {
|
|
|
|
|
if (l->m_resource.get() == lock) {
|
2024-04-30 16:32:05 +01:00
|
|
|
sessionLock = l;
|
|
|
|
|
break;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2024-05-05 17:16:00 +01:00
|
|
|
const auto RESOURCE =
|
2025-05-04 19:21:36 +02:00
|
|
|
m_lockSurfaces.emplace_back(makeShared<CSessionLockSurface>(makeShared<CExtSessionLockSurfaceV1>(lock->client(), lock->version(), id), PSURFACE, PMONITOR, sessionLock));
|
2024-04-30 16:32:05 +01:00
|
|
|
|
2025-01-17 18:21:34 +01:00
|
|
|
if UNLIKELY (!RESOURCE->good()) {
|
2024-05-01 19:40:35 +01:00
|
|
|
lock->noMemory();
|
2025-05-04 19:21:36 +02:00
|
|
|
m_lockSurfaces.pop_back();
|
2024-04-30 16:32:05 +01:00
|
|
|
return;
|
|
|
|
|
}
|
|
|
|
|
|
2025-05-04 19:21:36 +02:00
|
|
|
sessionLock->m_events.newLockSurface.emit(RESOURCE);
|
2024-04-30 16:32:05 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
bool CSessionLockProtocol::isLocked() {
|
2025-05-04 19:21:36 +02:00
|
|
|
return m_locked;
|
2025-01-17 15:21:35 +00:00
|
|
|
}
|