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 <QDebug>
9#include <QGuiApplication>
10#include <QPointer>
11#include <QScreen>
12#include <qpa/qplatformnativeinterface.h>
13
14ScreencastingStream::ScreencastingStream()
15{
16}
17
18ScreencastingStream::~ScreencastingStream()
19{
20 close();
21}
22
23void ScreencastingStream::zkde_screencast_stream_unstable_v1_created(uint32_t node)
24{
25 Q_EMIT created(node);
26}
27
28void ScreencastingStream::zkde_screencast_stream_unstable_v1_closed()
29{
30 Q_EMIT closed();
31}
32
33void ScreencastingStream::zkde_screencast_stream_unstable_v1_failed(const QString &error)
34{
35 Q_EMIT failed(error);
36}
37
38Screencasting::Screencasting()
39 : QWaylandClientExtensionTemplate<Screencasting>(ZKDE_SCREENCAST_UNSTABLE_V1_STREAM_REGION_SINCE_VERSION)
40{
41 initialize();
42
43 if (!isInitialized()) {
44 qWarning() << "Remember requesting the interface on your desktop file: X-KDE-Wayland-Interfaces=zkde_screencast_unstable_v1";
45 }
46}
47
48Screencasting::~Screencasting()
49{
50 if (isActive()) {
51 destroy();
52 }
53}
54
55std::unique_ptr<ScreencastingStream> Screencasting::createOutputStream(const QString &outputName, pointer mode)
56{
57 if (!isActive()) {
58 return nullptr;
59 }
60
61 wl_output *output = nullptr;
62 for (auto screen : qGuiApp->screens()) {
63 if (screen->name() == outputName) {
64 output = (wl_output *)QGuiApplication::platformNativeInterface()->nativeResourceForScreen("output", screen);
65 }
66 }
67
68 if (!output) {
69 return nullptr;
70 }
71
72 auto stream = std::make_unique<ScreencastingStream>();
73 stream->setObjectName(outputName);
74 stream->init(stream_output(output, mode));
75 return stream;
76}
77
78std::unique_ptr<ScreencastingStream> Screencasting::createWindowStream(const QString &uuid, pointer mode)
79{
80 if (!isActive()) {
81 return nullptr;
82 }
83 auto stream = std::make_unique<ScreencastingStream>();
84 stream->init(stream_window(uuid, mode));
85 return stream;
86}
KCRASH_EXPORT void initialize()
KGuiItem close()
Q_EMITQ_EMIT
This file is part of the KDE documentation.
Documentation copyright © 1996-2024 The KDE developers.
Generated on Fri Nov 22 2024 12:06:10 by doxygen 1.12.0 written by Dimitri van Heesch, © 1997-2006

KDE's Doxygen guidelines are available online.