File indexing completed on 2024-11-10 04:57:31

0001 /*
0002     SPDX-FileCopyrightText: 2020 Aleix Pol Gonzalez <aleixpol@kde.org>
0003 
0004     SPDX-License-Identifier: LGPL-2.1-only OR LGPL-3.0-only OR LicenseRef-KDE-Accepted-LGPL
0005 */
0006 
0007 #include "screencast_v1.h"
0008 #include "display.h"
0009 #include "output.h"
0010 
0011 #include <QDebug>
0012 #include <QRect>
0013 
0014 #include "qwayland-server-zkde-screencast-unstable-v1.h"
0015 
0016 namespace KWin
0017 {
0018 static int s_version = 3;
0019 
0020 class ScreencastStreamV1InterfacePrivate : public QtWaylandServer::zkde_screencast_stream_unstable_v1
0021 {
0022 public:
0023     ScreencastStreamV1InterfacePrivate(ScreencastStreamV1Interface *q)
0024         : q(q)
0025     {
0026     }
0027 
0028     void zkde_screencast_stream_unstable_v1_destroy_resource(Resource *resource) override
0029     {
0030         if (!stopped) {
0031             Q_EMIT q->finished();
0032         }
0033 
0034         q->deleteLater();
0035     }
0036 
0037     void zkde_screencast_stream_unstable_v1_close(Resource *resource) override
0038     {
0039         Q_EMIT q->finished();
0040         stopped = true;
0041         wl_resource_destroy(resource->handle);
0042     }
0043 
0044     bool stopped = false;
0045     ScreencastStreamV1Interface *const q;
0046 };
0047 
0048 ScreencastStreamV1Interface::ScreencastStreamV1Interface(QObject *parent)
0049     : QObject(parent)
0050     , d(new ScreencastStreamV1InterfacePrivate(this))
0051 {
0052 }
0053 
0054 ScreencastStreamV1Interface::~ScreencastStreamV1Interface() = default;
0055 
0056 void ScreencastStreamV1Interface::sendCreated(quint32 nodeid)
0057 {
0058     d->send_created(nodeid);
0059 }
0060 
0061 void ScreencastStreamV1Interface::sendFailed(const QString &error)
0062 {
0063     d->send_failed(error);
0064 }
0065 
0066 void ScreencastStreamV1Interface::sendClosed()
0067 {
0068     if (!d->stopped) {
0069         d->send_closed();
0070     }
0071 }
0072 
0073 class ScreencastV1InterfacePrivate : public QtWaylandServer::zkde_screencast_unstable_v1
0074 {
0075 public:
0076     ScreencastV1InterfacePrivate(Display *display, ScreencastV1Interface *q)
0077         : QtWaylandServer::zkde_screencast_unstable_v1(*display, s_version)
0078         , q(q)
0079     {
0080     }
0081 
0082     ScreencastStreamV1Interface *createStream(Resource *resource, quint32 streamid) const
0083     {
0084         auto stream = new ScreencastStreamV1Interface(q);
0085         stream->d->init(resource->client(), streamid, resource->version());
0086         return stream;
0087     }
0088 
0089     void zkde_screencast_unstable_v1_stream_output(Resource *resource, uint32_t streamid, struct ::wl_resource *output, uint32_t pointer) override
0090     {
0091         Q_EMIT q->outputScreencastRequested(createStream(resource, streamid), OutputInterface::get(output), ScreencastV1Interface::CursorMode(pointer));
0092     }
0093 
0094     void zkde_screencast_unstable_v1_stream_window(Resource *resource, uint32_t streamid, const QString &uuid, uint32_t pointer) override
0095     {
0096         Q_EMIT q->windowScreencastRequested(createStream(resource, streamid), uuid, ScreencastV1Interface::CursorMode(pointer));
0097     }
0098     void zkde_screencast_unstable_v1_stream_virtual_output(Resource *resource,
0099                                                            uint32_t streamid,
0100                                                            const QString &name,
0101                                                            int32_t width,
0102                                                            int32_t height,
0103                                                            wl_fixed_t scale,
0104                                                            uint32_t pointer) override
0105     {
0106         Q_EMIT q->virtualOutputScreencastRequested(createStream(resource, streamid),
0107                                                    name,
0108                                                    {width, height},
0109                                                    wl_fixed_to_double(scale),
0110                                                    ScreencastV1Interface::CursorMode(pointer));
0111     }
0112 
0113     void zkde_screencast_unstable_v1_stream_region(QtWaylandServer::zkde_screencast_unstable_v1::Resource *resource,
0114                                                    uint32_t stream,
0115                                                    int32_t x,
0116                                                    int32_t y,
0117                                                    uint32_t width,
0118                                                    uint32_t height,
0119                                                    wl_fixed_t scale,
0120                                                    uint32_t pointer) override
0121     {
0122         Q_EMIT q->regionScreencastRequested(createStream(resource, stream),
0123                                             {x, y, int(width), int(height)},
0124                                             wl_fixed_to_double(scale),
0125                                             ScreencastV1Interface::CursorMode(pointer));
0126     }
0127 
0128     void zkde_screencast_unstable_v1_destroy(Resource *resource) override
0129     {
0130         wl_resource_destroy(resource->handle);
0131     }
0132 
0133     ScreencastV1Interface *const q;
0134 };
0135 
0136 ScreencastV1Interface::ScreencastV1Interface(Display *display, QObject *parent)
0137     : QObject(parent)
0138     , d(new ScreencastV1InterfacePrivate(display, this))
0139 {
0140 }
0141 
0142 ScreencastV1Interface::~ScreencastV1Interface() = default;
0143 
0144 } // namespace KWin
0145 
0146 #include "moc_screencast_v1.cpp"