|
| 1 | +#include "ImageCopyCapture.hpp" |
| 2 | +#include "desktop/Window.hpp" |
| 3 | +#include "helpers/Monitor.hpp" |
| 4 | +#include "core/Seat.hpp" |
| 5 | + |
| 6 | +CImageCopyCaptureSession::CImageCopyCaptureSession(SP<CExtImageCopyCaptureSessionV1> resource, SP<CImageCaptureSource> source, extImageCopyCaptureManagerV1Options options) : |
| 7 | + m_resource(resource), m_source(source), m_paintCursor(options & EXT_IMAGE_COPY_CAPTURE_MANAGER_V1_OPTIONS_PAINT_CURSORS) { |
| 8 | + m_listeners.destroy = source->m_events.destroy.registerListener([this](std::any data) { PROTO::imageCopyCapture->destroyResource(this); }); |
| 9 | + |
| 10 | + // TODO: send buffer constraint events, i.e. buffer_size, shm_format, dmabuf_device, dmabuf_format, done |
| 11 | + // TODO: do create_frame, and frame class/object |
| 12 | +} |
| 13 | + |
| 14 | +CImageCopyCaptureSession::~CImageCopyCaptureSession() { |
| 15 | + // TODO: properly fail/close screenshare |
| 16 | +} |
| 17 | + |
| 18 | +CImageCopyCaptureProtocol::CImageCopyCaptureProtocol(const wl_interface* iface, const int& ver, const std::string& name) : IWaylandProtocol(iface, ver, name) { |
| 19 | + ; |
| 20 | +} |
| 21 | + |
| 22 | +void CImageCopyCaptureProtocol::bindManager(wl_client* client, void* data, uint32_t ver, uint32_t id) { |
| 23 | + const auto RESOURCE = m_managers.emplace_back(makeShared<CExtImageCopyCaptureManagerV1>(client, ver, id)); |
| 24 | + |
| 25 | + if UNLIKELY (!RESOURCE->resource()) { |
| 26 | + wl_client_post_no_memory(client); |
| 27 | + m_managers.pop_back(); |
| 28 | + return; |
| 29 | + } |
| 30 | + |
| 31 | + RESOURCE->setDestroy([this](CExtImageCopyCaptureManagerV1* pMgr) { destroyResource(pMgr); }); |
| 32 | + RESOURCE->setOnDestroy([this](CExtImageCopyCaptureManagerV1* pMgr) { destroyResource(pMgr); }); |
| 33 | + |
| 34 | + RESOURCE->setCreateSession([this](CExtImageCopyCaptureManagerV1* pMgr, uint32_t id, wl_resource* source_, extImageCopyCaptureManagerV1Options options) { |
| 35 | + auto source = PROTO::imageCaptureSource->sourceFromResource(source_); |
| 36 | + if (!source) { |
| 37 | + LOGM(LOG, "Client tried to create image copy capture session from invalid source"); |
| 38 | + pMgr->error(-1, "invalid image capture source"); |
| 39 | + return; |
| 40 | + } |
| 41 | + |
| 42 | + if (options > 1) { |
| 43 | + LOGM(LOG, "Client tried to create image copy capture session with invalid options"); |
| 44 | + pMgr->error(EXT_IMAGE_COPY_CAPTURE_MANAGER_V1_ERROR_INVALID_OPTION, "Options can't be above 1"); |
| 45 | + return; |
| 46 | + } |
| 47 | + |
| 48 | + m_sessions.emplace_back(makeShared<CImageCopyCaptureSession>(makeShared<CExtImageCopyCaptureSessionV1>(pMgr->client(), pMgr->version(), id), source, options)); |
| 49 | + LOGM(LOG, "New image copy capture session for source ({}): {}", source->getTypeName(), source->getName()); |
| 50 | + }); |
| 51 | + |
| 52 | + RESOURCE->setCreatePointerCursorSession([this](CExtImageCopyCaptureManagerV1* pMgr, uint32_t id, wl_resource* source_, wl_resource* pointer_) { |
| 53 | + SP<CImageCaptureSource> source = PROTO::imageCaptureSource->sourceFromResource(source_); |
| 54 | + if (!source) { |
| 55 | + LOGM(LOG, "Client tried to create image copy capture session from invalid source"); |
| 56 | + destroyResource(pMgr); |
| 57 | + return; |
| 58 | + } |
| 59 | + |
| 60 | + // TODO: find out what this would be, then implement constructor aswell |
| 61 | + // auto pointer = CWLPointerResource::fromResource(pointer_); |
| 62 | + |
| 63 | + m_sessions.emplace_back(makeShared<CImageCopyCaptureSession>(makeShared<CExtImageCopyCaptureSessionV1>(pMgr->client(), pMgr->version(), id), source, pointer)); |
| 64 | + LOGM(LOG, "New image copy capture session for source ({}): {}", source->getTypeName(), source->getName()); |
| 65 | + }); |
| 66 | +} |
| 67 | + |
| 68 | +void CImageCopyCaptureProtocol::destroyResource(CExtImageCopyCaptureManagerV1* resource) { |
| 69 | + std::erase_if(m_managers, [&](const auto& other) { return other.get() == resource; }); |
| 70 | +} |
| 71 | +void CImageCopyCaptureProtocol::destroyResource(CImageCopyCaptureSession* resource) { |
| 72 | + std::erase_if(m_sessions, [&](const auto& other) { return other.get() == resource; }); |
| 73 | +} |
0 commit comments