Changeset View
Changeset View
Standalone View
Standalone View
src/screencasting.cpp
- This file was added.
1 | /* | ||||
---|---|---|---|---|---|
2 | SPDX-FileCopyrightText: 2020 Aleix Pol Gonzalez <aleixpol@kde.org> | ||||
3 | | ||||
4 | SPDX-License-Identifier: LGPL-2.1-only OR LGPL-3.0-only OR LicenseRef-KDE-Accepted-LGPL | ||||
5 | */ | ||||
6 | | ||||
7 | #include "screencasting.h" | ||||
8 | #include "qwayland-zkde-screencast-unstable-v1.h" | ||||
9 | #include <QRect> | ||||
10 | #include <QDebug> | ||||
11 | #include <KWayland/Client/output.h> | ||||
12 | | ||||
13 | using namespace KWayland::Client; | ||||
14 | | ||||
15 | class KWayland::Client::ScreencastingStreamPrivate : public QtWayland::zkde_screencast_stream_unstable_v1 | ||||
16 | { | ||||
17 | public: | ||||
18 | ScreencastingStreamPrivate(ScreencastingStream* q) : q(q) {} | ||||
19 | | ||||
20 | void zkde_screencast_stream_unstable_v1_closed() override { | ||||
21 | Q_EMIT q->closed(); | ||||
22 | } | ||||
23 | | ||||
24 | void zkde_screencast_stream_unstable_v1_created(uint32_t node, quint32 width, quint32 height) override { | ||||
25 | Q_EMIT q->created(node, QSize(width, height)); | ||||
26 | } | ||||
27 | void zkde_screencast_stream_unstable_v1_failed(const QString &error) override { | ||||
28 | Q_EMIT q->failed(error); | ||||
29 | } | ||||
30 | | ||||
31 | private: | ||||
32 | ScreencastingStream* const q; | ||||
33 | }; | ||||
34 | | ||||
35 | ScreencastingStream::ScreencastingStream(QObject* parent) | ||||
36 | : QObject(parent) | ||||
37 | , d(new ScreencastingStreamPrivate(this)) | ||||
38 | { | ||||
39 | } | ||||
40 | | ||||
41 | ScreencastingStream::~ScreencastingStream() = default; | ||||
42 | | ||||
43 | void ScreencastingStream::close() | ||||
44 | { | ||||
45 | d->close(); | ||||
46 | } | ||||
47 | | ||||
48 | class KWayland::Client::ScreencastingPrivate : public QtWayland::zkde_screencast_unstable_v1 | ||||
49 | { | ||||
50 | public: | ||||
51 | ScreencastingPrivate(Registry *registry, int id, int version, Screencasting *q) | ||||
52 | : QtWayland::zkde_screencast_unstable_v1(*registry, id, version) | ||||
53 | , q(q) | ||||
54 | { | ||||
55 | } | ||||
56 | | ||||
57 | ScreencastingPrivate(::zkde_screencast_unstable_v1* screencasting, Screencasting *q) | ||||
58 | : QtWayland::zkde_screencast_unstable_v1(screencasting) | ||||
59 | , q(q) | ||||
60 | { | ||||
61 | } | ||||
62 | | ||||
63 | ~ScreencastingPrivate() | ||||
64 | { | ||||
65 | destroy(); | ||||
66 | } | ||||
67 | | ||||
68 | Screencasting *const q; | ||||
69 | }; | ||||
70 | | ||||
71 | Screencasting::Screencasting(QObject* parent) | ||||
72 | : QObject(parent) | ||||
73 | {} | ||||
74 | | ||||
75 | Screencasting::Screencasting(Registry *registry, int id, int version, QObject* parent) | ||||
76 | : QObject(parent) | ||||
77 | , d(new ScreencastingPrivate(registry, id, version, this)) | ||||
78 | {} | ||||
79 | | ||||
80 | Screencasting::~Screencasting() = default; | ||||
81 | | ||||
82 | ScreencastingStream* Screencasting::createOutputStream(KWayland::Client::Output* output) | ||||
83 | { | ||||
84 | auto stream = new ScreencastingStream(this); | ||||
85 | stream->d->init(d->stream_output(*output)); | ||||
86 | return stream; | ||||
87 | } | ||||
88 | | ||||
89 | ScreencastingStream* Screencasting::createWindowStream(quint32 window) | ||||
90 | { | ||||
91 | auto stream = new ScreencastingStream(this); | ||||
92 | stream->d->init(d->stream_window(window)); | ||||
93 | return stream; | ||||
94 | } | ||||
95 | | ||||
96 | void Screencasting::setup(::zkde_screencast_unstable_v1* screencasting) | ||||
97 | { | ||||
98 | d.reset(new ScreencastingPrivate(screencasting, this)); | ||||
99 | } | ||||
100 | | ||||
101 | void Screencasting::destroy() | ||||
102 | { | ||||
103 | d.reset(nullptr); | ||||
104 | } |