Commit 6692060c authored by Devin Lin's avatar Devin Lin 🎨 Committed by Aleix Pol Gonzalez
Browse files

libtaskmanager: Add outputName to ScreencastingRequest

parent 8a0252a1
Pipeline #219596 passed with stage
in 9 minutes and 34 seconds
......@@ -10,7 +10,10 @@
#include <KWayland/Client/plasmawindowmanagement.h>
#include <KWayland/Client/registry.h>
#include <QDebug>
#include <QGuiApplication>
#include <QRect>
#include <QScreen>
#include <qpa/qplatformnativeinterface.h>
using namespace KWayland::Client;
......@@ -96,6 +99,25 @@ Screencasting::Screencasting(Registry *registry, int id, int version, QObject *p
Screencasting::~Screencasting() = default;
ScreencastingStream *Screencasting::createOutputStream(const QString &outputName, Screencasting::CursorMode mode)
{
wl_output *output = nullptr;
for (auto screen : qGuiApp->screens()) {
if (screen->name() == outputName) {
output = (wl_output *)QGuiApplication::platformNativeInterface()->nativeResourceForScreen("output", screen);
}
}
if (!output) {
return nullptr;
}
auto stream = new ScreencastingStream(this);
stream->setObjectName(outputName);
stream->d->init(d->stream_output(output, mode));
return stream;
}
ScreencastingStream *Screencasting::createOutputStream(Output *output, CursorMode mode)
{
auto stream = new ScreencastingStream(this);
......
......@@ -60,6 +60,7 @@ public:
};
Q_ENUM(CursorMode)
ScreencastingStream *createOutputStream(const QString &outputName, CursorMode mode);
ScreencastingStream *createOutputStream(KWayland::Client::Output *output, CursorMode mode);
ScreencastingStream *createWindowStream(KWayland::Client::PlasmaWindow *window, CursorMode mode);
ScreencastingStream *createWindowStream(const QString &uuid, CursorMode mode);
......
......@@ -106,11 +106,30 @@ void ScreencastingRequest::setNodeid(uint nodeId)
Q_EMIT nodeIdChanged(nodeId);
}
void ScreencastingRequest::create(Screencasting *screencasting)
QString ScreencastingRequest::outputName() const
{
auto stream = screencasting->createWindowStream(m_uuid, Screencasting::CursorMode::Hidden);
stream->setObjectName(m_uuid);
return m_outputName;
}
void ScreencastingRequest::setOutputName(const QString &outputName)
{
if (m_outputName == outputName) {
return;
}
setNodeid(0);
m_outputName = outputName;
Q_EMIT outputNameChanged(outputName);
if (!m_outputName.isEmpty()) {
auto screencasting = new Screencasting(this);
auto stream = screencasting->createOutputStream(m_outputName, Screencasting::CursorMode::Hidden);
adopt(stream);
}
}
void ScreencastingRequest::adopt(ScreencastingStream *stream)
{
connect(stream, &ScreencastingStream::created, this, [stream, this](int nodeId) {
if (stream->objectName() == m_uuid) {
setNodeid(nodeId);
......@@ -127,6 +146,13 @@ void ScreencastingRequest::create(Screencasting *screencasting)
connect(this, &ScreencastingRequest::closeRunningStreams, stream, &QObject::deleteLater);
}
void ScreencastingRequest::create(Screencasting *screencasting)
{
auto stream = screencasting->createWindowStream(m_uuid, Screencasting::CursorMode::Hidden);
stream->setObjectName(m_uuid);
adopt(stream);
}
QString ScreencastingRequest::uuid() const
{
return m_uuid;
......
......@@ -31,6 +31,11 @@ class ScreencastingRequest : public QObject
*/
Q_PROPERTY(QString uuid READ uuid WRITE setUuid NOTIFY uuidChanged)
/**
* The output name as define in Screen.name
*/
Q_PROPERTY(QString outputName READ outputName WRITE setOutputName NOTIFY outputNameChanged)
/** The offered nodeId to give to a source */
Q_PROPERTY(quint32 nodeId READ nodeId NOTIFY nodeIdChanged)
public:
......@@ -39,21 +44,26 @@ public:
void setUuid(const QString &uuid);
QString uuid() const;
void setOutputName(const QString &outputName);
QString outputName() const;
quint32 nodeId() const;
void create(Screencasting *screencasting);
Q_SIGNALS:
void nodeIdChanged(quint32 nodeId);
void outputNameChanged(const QString &outputNames);
void uuidChanged(const QString &uuid);
void closeRunningStreams();
void cursorModeChanged(Screencasting::CursorMode cursorMode);
private:
void adopt(ScreencastingStream *stream);
void setNodeid(uint nodeId);
ScreencastingStream *m_stream = nullptr;
QString m_uuid;
QString m_outputName;
KWayland::Client::Output *m_output = nullptr;
quint32 m_nodeId = 0;
};
Supports Markdown
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment