init screencastingrequest file

This commit is contained in:
buxiaoqing 2023-04-25 11:31:12 +08:00
parent 9d2277d297
commit e6cf84cbb3
7 changed files with 215 additions and 8 deletions

View File

@ -15,6 +15,7 @@ find_package(Qt${QT_VERSION_MAJOR} COMPONENTS Core Gui Quick Widgets DBus X11Ext
#find kde modules
find_package(Qt5Xdg REQUIRED)
find_package(KF5Wayland)
#find other modules
find_package(PkgConfig REQUIRED)
@ -54,6 +55,7 @@ target_link_libraries(${PROJECT_NAME}
${GLIB2_LIBRARIES}
${GIO2_LIBRARIES}
${Gsetting_LIBRARIES}
KF5::WaylandClient
)
target_compile_definitions(taskmanager PRIVATE TASKMANAGER_LIBRARY)

View File

@ -1,8 +1,9 @@
#ifndef PIPEWIRESOURCEITEM_H
#define PIPEWIRESOURCEITEM_H
#include <QQuickItem>
class PipeWireSourceItem
class PipeWireSourceItem : public QQuickItem
{
public:
PipeWireSourceItem();

View File

@ -1,8 +1,45 @@
#ifndef SCREENCASTING_H
#define SCREENCASTING_H
#include <QObject>
#include <QSharedPointer>
#include <QVector>
#include <optional>
struct zkde_screencast_unstable_v1;
class Screencasting
namespace KWayland
{
namespace Client
{
class PlasmaWindow;
class Registry;
class Output;
}
}
class ScreencastingPrivate;
class ScreencastingSourcePrivate;
class ScreencastingStreamPrivate;
class ScreencastingStream : public QObject
{
Q_OBJECT
public:
ScreencastingStream(QObject *parent);
~ScreencastingStream() override;
quint32 nodeId() const;
Q_SIGNALS:
void created(quint32 nodeid);
void failed(const QString &error);
void closed();
private:
friend class Screencasting;
QScopedPointer<ScreencastingStreamPrivate> d;
};
class Screencasting : public QObject
{
public:
Screencasting();

View File

@ -1,5 +1,128 @@
#include "screencastingrequest.h"
#include <KWayland/Client/connection_thread.h>
#include <KWayland/Client/registry.h>
#include <QCoreApplication>
#include <QDebug>
#include <QPointer>
#include <functional>
ScreencastingRequest::ScreencastingRequest()
class ScreencastingSingleton : public QObject
{
Q_OBJECT
public:
ScreencastingSingleton(QObject *parent)
: QObject(parent)
{
KWayland::Client::ConnectionThread *connection = KWayland::Client::ConnectionThread::fromApplication(this);
if (!connection) {
return;
}
KWayland::Client::Registry *registry = new KWayland::Client::Registry(this);
connect(registry,
&KWayland::Client::Registry::interfaceAnnounced,
this,
[this, registry](const QByteArray &interfaceName, quint32 name, quint32 version) {
if (interfaceName != "zkde_screencast_unstable_v1")
return;
// m_screencasting = new Screencasting(registry, name, version, this);
// Q_EMIT created(m_screencasting);
});
registry->create(connection);
registry->setup();
}
static ScreencastingSingleton *self()
{
static QPointer<ScreencastingSingleton> s_self;
if (!s_self && QCoreApplication::instance())
s_self = new ScreencastingSingleton(QCoreApplication::instance());
return s_self;
}
void requestInterface(ScreencastingRequest *item)
{
if (!m_screencasting) {
connect(this, &ScreencastingSingleton::created, item, &ScreencastingRequest::create, Qt::UniqueConnection);
} else {
item->create(m_screencasting);
}
}
Q_SIGNALS:
void created(Screencasting *screencasting);
private:
Screencasting *m_screencasting = nullptr;
};
ScreencastingRequest::ScreencastingRequest(QObject *parent)
:QObject(parent)
{
}
ScreencastingRequest::~ScreencastingRequest() = default;
quint32 ScreencastingRequest::nodeId() const
{
return m_nodeId;
}
void ScreencastingRequest::setNodeid(uint nodeId)
{
if (nodeId == m_nodeId) {
return;
}
m_nodeId = nodeId;
Q_EMIT nodeIdChanged(nodeId);
}
QString ScreencastingRequest::uuid() const
{
return m_uuid;
}
void ScreencastingRequest::setUuid(const QString &uuid)
{
if (m_uuid == uuid) {
return;
}
Q_EMIT closeRunningStreams();
setNodeid(0);
m_uuid = uuid;
if (!m_uuid.isEmpty()) {
ScreencastingSingleton::self()->requestInterface(this);
}
Q_EMIT uuidChanged(uuid);
}
void ScreencastingRequest::create(Screencasting *screencasting)
{
// auto stream = screencasting->createWindowStream(m_uuid, Screencasting::CursorMode::Hidden);
// stream->setObjectName(m_uuid);
// connect(stream, &ScreencastingStream::created, this, [stream, this](int nodeId) {
// if (stream->objectName() == m_uuid) {
// setNodeid(nodeId);
// }
// });
// connect(stream, &ScreencastingStream::failed, this, [](const QString &error) {
// qWarning() << "error creating screencast" << error;
// });
// connect(stream, &ScreencastingStream::closed, this, [this, stream] {
// if (stream->nodeId() == m_nodeId) {
// setNodeid(0);
// }
// });
// connect(this, &ScreencastingRequest::closeRunningStreams, stream, &QObject::deleteLater);
}
#include "screencastingrequest.moc"

View File

@ -2,11 +2,34 @@
#define SCREENCASTINGREQUEST_H
#include "libtaskmanager_global.h"
#include "screencasting.h"
#include <QObject>
class LIBTASKMANAGER_EXPORT ScreencastingRequest
class ScreencastingStream;
class ScreencastingRequest : public QObject
{
public:
ScreencastingRequest();
ScreencastingRequest(QObject *parent = nullptr);
~ScreencastingRequest();
void setUuid(const QString &uuid);
QString uuid() const;
quint32 nodeId() const;
void create(Screencasting *screencasting);
Q_SIGNALS:
void nodeIdChanged(quint32 nodeId);
void uuidChanged(const QString &uuid);
void closeRunningStreams();
private:
void setNodeid(uint nodeId);
ScreencastingStream *m_stream = nullptr;
QString m_uuid;
KWayland::Client::Output *m_output = nullptr;
quint32 m_nodeId = 0;
};
#endif // SCREENCASTINGREQUEST_H

View File

@ -1,6 +1,18 @@
#include "taskmanagerplugin.h"
#include "pipewiresourceitem.h"
#include "screencasting.h"
#include "screencastingrequest.h"
TaskManagerPlugin::TaskManagerPlugin()
namespace TaskManager
{
void TaskManagerPlugin::registerTypes(const char *uri)
{
Q_ASSERT(uri == QLatin1String("org.ukui.panel.taskmanager"));
qmlRegisterType<PipeWireSourceItem>(uri, 0, 1, "PipeWireSourceItem");
qmlRegisterType<ScreencastingRequest>(uri, 0, 1, "ScreencastingRequest");
qmlRegisterUncreatableType<Screencasting>(uri, 0, 1, "Screencasting", "Use ScreencastingItem");
}
}

View File

@ -1,11 +1,20 @@
#ifndef TASKMANAGERPLUGIN_H
#define TASKMANAGERPLUGIN_H
#include <QQmlEngine>
#include <QQmlExtensionPlugin>
class TaskManagerPlugin
namespace TaskManager
{
class TaskManagerPlugin : public QQmlExtensionPlugin
{
Q_OBJECT
Q_PLUGIN_METADATA(IID "org.qt-project.Qt.QQmlExtensionInterface")
public:
TaskManagerPlugin();
void registerTypes(const char *uri) override;
};
}
#endif // TASKMANAGERPLUGIN_H