KWaylandServer

screencast_v1_interface.cpp
1 /*
2  SPDX-FileCopyrightText: 2020 Aleix Pol Gonzalez <[email protected]>
3 
4  SPDX-License-Identifier: LGPL-2.1-only OR LGPL-3.0-only OR LicenseRef-KDE-Accepted-LGPL
5 */
6 
7 #include "screencast_v1_interface.h"
8 #include "display.h"
9 #include "output_interface.h"
10 
11 #include <QDebug>
12 
13 #include "qwayland-server-zkde-screencast-unstable-v1.h"
14 
15 namespace KWaylandServer
16 {
17 static int s_version = 2;
18 
19 class ScreencastStreamV1InterfacePrivate : public QtWaylandServer::zkde_screencast_stream_unstable_v1
20 {
21 public:
22  ScreencastStreamV1InterfacePrivate(ScreencastStreamV1Interface *q)
23  : q(q)
24  {
25  }
26 
27  void zkde_screencast_stream_unstable_v1_destroy_resource(Resource *resource) override
28  {
29  Q_UNUSED(resource);
30  if (!stopped) {
31  Q_EMIT q->finished();
32  }
33 
34  q->deleteLater();
35  }
36 
37  void zkde_screencast_stream_unstable_v1_close(Resource *resource) override
38  {
39  Q_UNUSED(resource);
40  Q_EMIT q->finished();
41  stopped = true;
42  wl_resource_destroy(resource->handle);
43  }
44 
45  bool stopped = false;
46  ScreencastStreamV1Interface *const q;
47 };
48 
49 ScreencastStreamV1Interface::ScreencastStreamV1Interface(QObject *parent)
50  : QObject(parent)
51  , d(new ScreencastStreamV1InterfacePrivate(this))
52 {
53 }
54 
55 ScreencastStreamV1Interface::~ScreencastStreamV1Interface() = default;
56 
57 void ScreencastStreamV1Interface::sendCreated(quint32 nodeid)
58 {
59  d->send_created(nodeid);
60 }
61 
62 void ScreencastStreamV1Interface::sendFailed(const QString &error)
63 {
64  d->send_failed(error);
65 }
66 
67 void ScreencastStreamV1Interface::sendClosed()
68 {
69  if (!d->stopped) {
70  d->send_closed();
71  }
72 }
73 
74 class ScreencastV1InterfacePrivate : public QtWaylandServer::zkde_screencast_unstable_v1
75 {
76 public:
77  ScreencastV1InterfacePrivate(Display *display, ScreencastV1Interface *q)
78  : QtWaylandServer::zkde_screencast_unstable_v1(*display, s_version)
79  , q(q)
80  {
81  }
82 
83  ScreencastStreamV1Interface *createStream(Resource *resource, quint32 streamid) const
84  {
85  auto stream = new ScreencastStreamV1Interface(q);
86  stream->d->init(resource->client(), streamid, resource->version());
87  return stream;
88  }
89 
90  void zkde_screencast_unstable_v1_stream_output(Resource *resource, uint32_t streamid, struct ::wl_resource *output, uint32_t pointer) override
91  {
92  Q_EMIT q->outputScreencastRequested(createStream(resource, streamid), OutputInterface::get(output), ScreencastV1Interface::CursorMode(pointer));
93  }
94 
95  void zkde_screencast_unstable_v1_stream_window(Resource *resource, uint32_t streamid, const QString &uuid, uint32_t pointer) override
96  {
97  Q_EMIT q->windowScreencastRequested(createStream(resource, streamid), uuid, ScreencastV1Interface::CursorMode(pointer));
98  }
99  void zkde_screencast_unstable_v1_stream_virtual_output(Resource *resource,
100  uint32_t streamid,
101  const QString &name,
102  int32_t width,
103  int32_t height,
104  wl_fixed_t scale,
105  uint32_t pointer) override
106  {
107  Q_EMIT q->virtualOutputScreencastRequested(createStream(resource, streamid),
108  name,
109  {width, height},
110  wl_fixed_to_double(scale),
111  ScreencastV1Interface::CursorMode(pointer));
112  }
113 
114  void zkde_screencast_unstable_v1_destroy(Resource *resource) override
115  {
116  wl_resource_destroy(resource->handle);
117  }
118 
119  ScreencastV1Interface *const q;
120 };
121 
122 ScreencastV1Interface::ScreencastV1Interface(Display *display, QObject *parent)
123  : QObject(parent)
124  , d(new ScreencastV1InterfacePrivate(display, this))
125 {
126 }
127 
128 ScreencastV1Interface::~ScreencastV1Interface() = default;
129 
130 } // namespace KWaylandServer
QObject * parent() const const
Q_EMITQ_EMIT
This file is part of the KDE documentation.
Documentation copyright © 1996-2021 The KDE developers.
Generated on Sat Oct 23 2021 23:08:28 by doxygen 1.8.11 written by Dimitri van Heesch, © 1997-2006

KDE's Doxygen guidelines are available online.