Plasma-workspace

screencasting.cpp
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 <QDebug>
10#include <QGuiApplication>
11#include <QPointer>
12#include <QScreen>
13#include <QWaylandClientExtensionTemplate>
14#include <qpa/qplatformnativeinterface.h>
15#include <qtwaylandclientversion.h>
16
17class ScreencastingStreamPrivate : public QtWayland::zkde_screencast_stream_unstable_v1
18{
19public:
20 ScreencastingStreamPrivate(ScreencastingStream *q)
21 : q(q)
22 {
23 }
24 ~ScreencastingStreamPrivate()
25 {
26 close();
27 q->deleteLater();
28 }
29
30 void zkde_screencast_stream_unstable_v1_created(uint32_t node) override
31 {
32 m_nodeId = node;
33 Q_EMIT q->created(node);
34 }
35
36 void zkde_screencast_stream_unstable_v1_closed() override
37 {
38 Q_EMIT q->closed();
39 }
40
41 void zkde_screencast_stream_unstable_v1_failed(const QString &error) override
42 {
43 Q_EMIT q->failed(error);
44 }
45
46 uint m_nodeId = 0;
48};
49
50ScreencastingStream::ScreencastingStream(QObject *parent)
51 : QObject(parent)
52 , d(new ScreencastingStreamPrivate(this))
53{
54}
55
56ScreencastingStream::~ScreencastingStream() = default;
57
58quint32 ScreencastingStream::nodeId() const
59{
60 return d->m_nodeId;
61}
62
63class ScreencastingPrivate : public QWaylandClientExtensionTemplate<ScreencastingPrivate>, public QtWayland::zkde_screencast_unstable_v1
64{
65public:
66 ScreencastingPrivate(Screencasting *q)
67 : QWaylandClientExtensionTemplate<ScreencastingPrivate>(ZKDE_SCREENCAST_UNSTABLE_V1_STREAM_REGION_SINCE_VERSION)
68 , q(q)
69 {
70 initialize();
71
72 if (!isInitialized()) {
73 qWarning() << "Remember requesting the interface on your desktop file: X-KDE-Wayland-Interfaces=zkde_screencast_unstable_v1";
74 }
75 Q_ASSERT(isInitialized());
76 }
77
78 ~ScreencastingPrivate()
79 {
80 if (isActive()) {
81 destroy();
82 }
83 }
84
85 Screencasting *const q;
86};
87
88Screencasting::Screencasting(QObject *parent)
89 : QObject(parent)
90 , d(new ScreencastingPrivate(this))
91{
92}
93
94Screencasting::~Screencasting() = default;
95
96ScreencastingStream *Screencasting::createOutputStream(const QString &outputName, Screencasting::CursorMode mode)
97{
98 if (!d->isActive()) {
99 return nullptr;
100 }
101
102 wl_output *output = nullptr;
103 for (auto screen : qGuiApp->screens()) {
104 if (screen->name() == outputName) {
105 output = (wl_output *)QGuiApplication::platformNativeInterface()->nativeResourceForScreen("output", screen);
106 }
107 }
108
109 if (!output) {
110 return nullptr;
111 }
112
113 auto stream = new ScreencastingStream(this);
114 stream->setObjectName(outputName);
115 stream->d->init(d->stream_output(output, mode));
116 return stream;
117}
118
119ScreencastingStream *Screencasting::createWindowStream(const QString &uuid, CursorMode mode)
120{
121 if (!d->isActive()) {
122 return nullptr;
123 }
124 auto stream = new ScreencastingStream(this);
125 stream->d->init(d->stream_window(uuid, mode));
126 return stream;
127}
128
129void Screencasting::destroy()
130{
131 d.reset(nullptr);
132}
const QList< QKeySequence > & close()
void initialize(StandardShortcut id)
This file is part of the KDE documentation.
Documentation copyright © 1996-2024 The KDE developers.
Generated on Tue Mar 26 2024 11:17:42 by doxygen 1.10.0 written by Dimitri van Heesch, © 1997-2006

KDE's Doxygen guidelines are available online.