Skip to content

Commit c07137b

Browse files
committed
implement image copy capture protocol
1 parent d313cbd commit c07137b

File tree

4 files changed

+120
-0
lines changed

4 files changed

+120
-0
lines changed

CMakeLists.txt

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -385,6 +385,7 @@ protocolnew("staging/ext-workspace" "ext-workspace-v1" false)
385385
protocolnew("staging/ext-data-control" "ext-data-control-v1" false)
386386
protocolnew("staging/pointer-warp" "pointer-warp-v1" false)
387387
protocolnew("staging/ext-image-capture-source" "ext-image-capture-source-v1" false)
388+
protocolnew("staging/ext-image-copy-capture" "ext-image-copy-capture-v1" false)
388389

389390
protocolwayland()
390391

protocols/meson.build

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -79,6 +79,7 @@ protocols = [
7979
wayland_protocol_dir / 'staging/ext-data-control/ext-data-control-v1.xml',
8080
wayland_protocol_dir / 'staging/pointer-warp/pointer-warp-v1.xml',
8181
wayland_protocol_dir / 'staging/ext-image-capture-source/ext-image-capture-source-v1.xml',
82+
wayland_protocol_dir / 'staging/ext-image-copy-capture/ext-image-copy-capture-v1.xml',
8283
]
8384

8485
wl_protocols = []

src/protocols/ImageCopyCapture.cpp

Lines changed: 73 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,73 @@
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+
}

src/protocols/ImageCopyCapture.hpp

Lines changed: 45 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,45 @@
1+
#pragma once
2+
3+
// TODO: implement rest of proto
4+
5+
#include <vector>
6+
7+
#include "../defines.hpp"
8+
#include "../helpers/signal/Signal.hpp"
9+
#include "WaylandProtocol.hpp"
10+
#include "ImageCaptureSource.hpp"
11+
#include "ext-image-copy-capture-v1.hpp"
12+
13+
class CImageCopyCaptureSession {
14+
public:
15+
CImageCopyCaptureSession(SP<CExtImageCopyCaptureSessionV1> resource, SP<CImageCaptureSource> source, extImageCopyCaptureManagerV1Options options);
16+
~CImageCopyCaptureSession();
17+
18+
private:
19+
SP<CExtImageCopyCaptureSessionV1> m_resource;
20+
SP<CImageCaptureSource> m_source;
21+
22+
struct {
23+
CHyprSignalListener destroy;
24+
} m_listeners;
25+
26+
bool m_paintCursor;
27+
};
28+
29+
class CImageCopyCaptureProtocol : public IWaylandProtocol {
30+
public:
31+
CImageCopyCaptureProtocol(const wl_interface* iface, const int& ver, const std::string& name);
32+
33+
virtual void bindManager(wl_client* client, void* data, uint32_t ver, uint32_t id);
34+
35+
void destroyResource(CExtImageCopyCaptureManagerV1* resource);
36+
void destroyResource(CImageCopyCaptureSession* resource);
37+
38+
private:
39+
std::vector<SP<CExtImageCopyCaptureManagerV1>> m_managers;
40+
std::vector<SP<CImageCopyCaptureSession>> m_sessions;
41+
};
42+
43+
namespace PROTO {
44+
inline UP<CImageCopyCaptureProtocol> imageCopyCapture;
45+
};

0 commit comments

Comments
 (0)