Members of the KDE Community are recommended to subscribe to the kde-community mailing list at https://mail.kde.org/mailman/listinfo/kde-community to allow them to participate in important discussions and receive other important announcements

Commit 531a7e72 authored by Jan Grulich's avatar Jan Grulich

Move Wayland integration bits into separated class so they can be shared between portals

parent cd513b72
......@@ -28,7 +28,8 @@ if (SCREENCAST_ENABLED)
screencaststream.cpp
screenchooserdialog.cpp
remotedesktop.cpp
remotedesktopdialog.cpp)
remotedesktopdialog.cpp
waylandintegration.cpp)
ki18n_wrap_ui(xdg_desktop_portal_kde_SRCS
screenchooserdialog.ui
......
......@@ -43,6 +43,9 @@ DesktopPortal::DesktopPortal(QObject *parent)
#endif
, m_screenshot(new ScreenshotPortal(this))
{
#if SCREENCAST_ENABLED
WaylandIntegration::init();
#endif
}
DesktopPortal::~DesktopPortal()
......
......@@ -34,6 +34,7 @@
#if SCREENCAST_ENABLED
#include "screencast.h"
#include "remotedesktop.h"
#include "waylandintegration.h"
#endif
#include "screenshot.h"
......
This diff is collapsed.
......@@ -25,56 +25,15 @@
#include <QDBusObjectPath>
#include <QSize>
#include <gbm.h>
#include <epoxy/egl.h>
#include <epoxy/gl.h>
namespace KWayland {
namespace Client {
class ConnectionThread;
class EventQueue;
class OutputDevice;
class Registry;
class RemoteAccessManager;
class RemoteBuffer;
class Output;
}
}
class ScreenChooserDialog;
class ScreenCastStream;
class ScreenCastPortalOutput
{
enum OutputType {
Laptop,
Monitor,
Television
};
void setOutputType(const QString &type);
QString manufacturer;
QString model;
QSize resolution;
OutputType outputType;
// Needed for later output binding
int waylandOutputName;
int waylandOutputVersion;
friend class ScreenCastPortal;
friend class ScreenChooserDialog;
};
class ScreenCastPortal : public QDBusAbstractAdaptor
{
Q_OBJECT
Q_CLASSINFO("D-Bus Interface", "org.freedesktop.impl.portal.ScreenCast")
Q_PROPERTY(uint version READ version)
Q_PROPERTY(uint AvailableSourceTypes READ AvailableSourceTypes)
public:
typedef struct {
uint nodeId;
......@@ -115,40 +74,14 @@ public Q_SLOTS:
QVariantMap &results);
private Q_SLOTS:
void addOutput(quint32 name, quint32 version);
void removeOutput(quint32 name);
void processBuffer(const KWayland::Client::RemoteBuffer *rbuf);
void setupRegistry();
void stopStreaming();
private:
void createPipeWireStream(const QSize &resolution);
void initDrm();
void initEGL();
void initWayland();
bool m_registryInitialized;
bool m_streamingEnabled;
QMap<quint32, ScreenCastPortalOutput> m_outputMap;
QList<KWayland::Client::Output*> m_bindOutputs;
QThread *m_thread;
ScreenCastStream *m_stream;
KWayland::Client::ConnectionThread *m_connection;
KWayland::Client::EventQueue *m_queue;
KWayland::Client::Registry *m_registry;
KWayland::Client::RemoteAccessManager *m_remoteAccessManager;
qint32 m_drmFd = 0; // for GBM buffer mmap
gbm_device *m_gbmDevice = nullptr; // for passed GBM buffer retrieval
struct {
QList<QByteArray> extensions;
EGLDisplay display = EGL_NO_DISPLAY;
EGLContext context = EGL_NO_CONTEXT;
} m_egl;
bool m_streamingEnabled;
};
#endif // XDG_DESKTOP_PORTAL_KDE_SCREENCAST_H
......
......@@ -70,9 +70,11 @@ public:
// Public because we need access from static functions
bool createStream();
void removeStream();
public Q_SLOTS:
bool recordFrame(uint8_t *screenData);
void removeStream();
Q_SIGNALS:
void streamReady(uint nodeId);
void startStreaming();
......
......@@ -21,6 +21,7 @@
#include "screenchooserdialog.h"
#include "ui_screenchooserdialog.h"
#include "screencast.h"
#include "waylandintegration.h"
#include <QLoggingCategory>
#include <QSettings>
......@@ -29,26 +30,26 @@
Q_LOGGING_CATEGORY(XdgDesktopPortalKdeScreenChooserDialog, "xdp-kde-screen-chooser-dialog")
ScreenChooserDialog::ScreenChooserDialog(const QMap<quint32, ScreenCastPortalOutput> &screens, bool multiple, QDialog *parent, Qt::WindowFlags flags)
ScreenChooserDialog::ScreenChooserDialog(bool multiple, QDialog *parent, Qt::WindowFlags flags)
: QDialog(parent, flags)
, m_dialog(new Ui::ScreenChooserDialog)
{
m_dialog->setupUi(this);
QMapIterator<quint32, ScreenCastPortalOutput> it(screens);
QMapIterator<quint32, WaylandIntegration::WaylandOutput> it(WaylandIntegration::screens());
while (it.hasNext()) {
it.next();
QListWidgetItem *widgetItem = new QListWidgetItem(m_dialog->screenView);
widgetItem->setData(Qt::UserRole, it.key());
if (it.value().outputType == ScreenCastPortalOutput::Laptop) {
if (it.value().outputType() == WaylandIntegration::WaylandOutput::Laptop) {
widgetItem->setIcon(QIcon::fromTheme("computer-laptop"));
widgetItem->setText(i18n("Laptop screen\nModel: %1", it.value().model));
} else if (it.value().outputType == ScreenCastPortalOutput::Monitor) {
widgetItem->setText(i18n("Laptop screen\nModel: %1", it.value().model()));
} else if (it.value().outputType() == WaylandIntegration::WaylandOutput::Monitor) {
widgetItem->setIcon(QIcon::fromTheme("video-display"));
widgetItem->setText(i18n("Manufacturer: %1\nModel: %2", it.value().manufacturer, it.value().model));
widgetItem->setText(i18n("Manufacturer: %1\nModel: %2", it.value().manufacturer(), it.value().model()));
} else {
widgetItem->setIcon(QIcon::fromTheme("video-television"));
widgetItem->setText(i18n("Manufacturer: %1\nModel: %2", it.value().manufacturer, it.value().model));
widgetItem->setText(i18n("Manufacturer: %1\nModel: %2", it.value().manufacturer(), it.value().model()));
}
}
......
......@@ -29,19 +29,17 @@ namespace Ui
class ScreenChooserDialog;
}
class ScreenCastPortalOutput;
class ScreenChooserDialog : public QDialog
{
Q_OBJECT
public:
ScreenChooserDialog(const QMap<quint32, ScreenCastPortalOutput> &screens, bool multiple = false, QDialog *parent = nullptr, Qt::WindowFlags flags = {});
ScreenChooserDialog(bool multiple = false, QDialog *parent = nullptr, Qt::WindowFlags flags = {});
~ScreenChooserDialog();
QList<quint32> selectedScreens() const;
private:
Ui::ScreenChooserDialog * m_dialog;
Ui::ScreenChooserDialog *m_dialog;
};
#endif // XDG_DESKTOP_PORTAL_KDE_SCREENCHOOSER_DIALOG_H
This diff is collapsed.
/*
* Copyright © 2018 Red Hat, Inc
*
* This program is free software; you can redistribute it and/or
* modify it under the terms of the GNU Lesser General Public
* License as published by the Free Software Foundation; either
* version 2 of the License, or (at your option) any later version.
*
* This library is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
* Lesser General Public License for more details.
*
* You should have received a copy of the GNU Lesser General Public
* License along with this library. If not, see <http://www.gnu.org/licenses/>.
*
* Authors:
* Jan Grulich <jgrulich@redhat.com>
*/
#ifndef XDG_DESKTOP_PORTAL_KDE_WAYLAND_INTEGRATION_H
#define XDG_DESKTOP_PORTAL_KDE_WAYLAND_INTEGRATION_H
#include <QObject>
#include <QSize>
#include <QtCore/QtGlobal>
namespace WaylandIntegration
{
class WaylandOutput
{
public:
enum OutputType {
Laptop,
Monitor,
Television
};
void setManufacturer(const QString &manufacturer) { m_manufacturer = manufacturer; }
QString manufacturer() const { return m_manufacturer; }
void setModel(const QString &model) { m_model = model; }
QString model() const { return m_model; }
void setResolution(const QSize &resolution) { m_resolution = resolution; }
QSize resolution() const { return m_resolution; }
void setOutputType(const QString &type);
OutputType outputType() const { return m_outputType; }
void setWaylandOutputName(int outputName) { m_waylandOutputName = outputName; }
int waylandOutputName() const { return m_waylandOutputName; }
void setWaylandOutputVersion(int outputVersion) { m_waylandOutputVersion = outputVersion; }
int waylandOutputVersion() const { return m_waylandOutputVersion; }
private:
QString m_manufacturer;
QString m_model;
QSize m_resolution;
OutputType m_outputType;
// Needed for later output binding
int m_waylandOutputName;
int m_waylandOutputVersion;
};
class WaylandIntegration : public QObject
{
Q_OBJECT
Q_SIGNALS:
void newBuffer(uint8_t *screenData);
};
void init();
void bindOutput(int outputName, int outputVersion);
void startStreaming();
void stopStreaming();
QMap<quint32, WaylandOutput> screens();
WaylandIntegration *waylandIntegration();
}
#endif // XDG_DESKTOP_PORTAL_KDE_WAYLAND_INTEGRATION_H
/*
* Copyright © 2018 Red Hat, Inc
*
* This program is free software; you can redistribute it and/or
* modify it under the terms of the GNU Lesser General Public
* License as published by the Free Software Foundation; either
* version 2 of the License, or (at your option) any later version.
*
* This library is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
* Lesser General Public License for more details.
*
* You should have received a copy of the GNU Lesser General Public
* License along with this library. If not, see <http://www.gnu.org/licenses/>.
*
* Authors:
* Jan Grulich <jgrulich@redhat.com>
*/
#ifndef XDG_DESKTOP_PORTAL_KDE_WAYLAND_INTEGRATION_P_H
#define XDG_DESKTOP_PORTAL_KDE_WAYLAND_INTEGRATION_P_H
#include "waylandintegration.h"
#include <QObject>
#include <QMap>
#include <gbm.h>
#include <epoxy/egl.h>
#include <epoxy/gl.h>
namespace KWayland {
namespace Client {
class ConnectionThread;
class EventQueue;
class OutputDevice;
class Registry;
class RemoteAccessManager;
class RemoteBuffer;
class Output;
}
}
namespace WaylandIntegration
{
class WaylandIntegrationPrivate : public WaylandIntegration::WaylandIntegration
{
Q_OBJECT
public:
WaylandIntegrationPrivate();
~WaylandIntegrationPrivate();
void initDrm();
void initEGL();
void initWayland();
void bindOutput(int outputName, int outputVersion);
void startStreaming();
void stopStreaming();
QMap<quint32, WaylandOutput> screens();
protected Q_SLOTS:
void addOutput(quint32 name, quint32 version);
void removeOutput(quint32 name);
void processBuffer(const KWayland::Client::RemoteBuffer *rbuf);
void setupRegistry();
private:
bool m_streamingEnabled;
bool m_registryInitialized;
QThread *m_thread;
QMap<quint32, WaylandOutput> m_outputMap;
QList<KWayland::Client::Output*> m_bindOutputs;
KWayland::Client::ConnectionThread *m_connection;
KWayland::Client::EventQueue *m_queue;
KWayland::Client::Registry *m_registry;
KWayland::Client::RemoteAccessManager *m_remoteAccessManager;
qint32 m_drmFd = 0; // for GBM buffer mmap
gbm_device *m_gbmDevice = nullptr; // for passed GBM buffer retrieval
struct {
QList<QByteArray> extensions;
EGLDisplay display = EGL_NO_DISPLAY;
EGLContext context = EGL_NO_CONTEXT;
} m_egl;
};
}
#endif // XDG_DESKTOP_PORTAL_KDE_WAYLAND_INTEGRATION_P_H
Markdown is supported
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