Advance Wayland and KDE package bring-up
Ultraworked with [Sisyphus](https://github.com/code-yeongyu/oh-my-openagent) Co-authored-by: Sisyphus <clio-agent@sisyphuslabs.ai>
This commit is contained in:
@@ -0,0 +1,60 @@
|
||||
/*
|
||||
SPDX-FileCopyrightText: 2020 David Edmundson <davidedmundson@kde.org>
|
||||
|
||||
SPDX-License-Identifier: LGPL-2.0-or-later
|
||||
*/
|
||||
|
||||
#include "ksystemclipboard.h"
|
||||
#include "kguiaddons_debug.h"
|
||||
|
||||
#include "qtclipboard_p.h"
|
||||
#include "waylandclipboard_p.h"
|
||||
|
||||
#include <QDebug>
|
||||
#include <QGuiApplication>
|
||||
#include <QMimeData>
|
||||
|
||||
KSystemClipboard *KSystemClipboard::instance()
|
||||
{
|
||||
if (!qGuiApp || qGuiApp->closingDown()) {
|
||||
return nullptr;
|
||||
}
|
||||
static KSystemClipboard *systemClipboard = nullptr;
|
||||
|
||||
#ifdef WITH_WAYLAND
|
||||
static bool s_waylandChecked = false;
|
||||
if (!systemClipboard && qGuiApp->platformName() == QLatin1String("wayland") && !s_waylandChecked) {
|
||||
WaylandClipboard *waylandClipboard = new WaylandClipboard(qApp);
|
||||
s_waylandChecked = true;
|
||||
|
||||
if (waylandClipboard->isValid()) {
|
||||
systemClipboard = waylandClipboard;
|
||||
} else {
|
||||
delete waylandClipboard;
|
||||
qCWarning(KGUIADDONS_LOG) << "Could not init WaylandClipboard, falling back to QtClipboard.";
|
||||
}
|
||||
}
|
||||
#endif
|
||||
|
||||
if (!systemClipboard) {
|
||||
systemClipboard = new QtClipboard(qApp);
|
||||
}
|
||||
|
||||
return systemClipboard;
|
||||
}
|
||||
|
||||
QString KSystemClipboard::text(QClipboard::Mode mode)
|
||||
{
|
||||
const QMimeData *data = mimeData(mode);
|
||||
if (data) {
|
||||
return data->text();
|
||||
}
|
||||
return QString();
|
||||
}
|
||||
|
||||
KSystemClipboard::KSystemClipboard(QObject *parent)
|
||||
: QObject(parent)
|
||||
{
|
||||
}
|
||||
|
||||
#include "moc_ksystemclipboard.cpp"
|
||||
@@ -0,0 +1,63 @@
|
||||
/*
|
||||
SPDX-FileCopyrightText: 2020 David Edmundson <davidedmundson@kde.org>
|
||||
|
||||
SPDX-License-Identifier: LGPL-2.0-or-later
|
||||
*/
|
||||
|
||||
#ifndef KSYSTEMCLIPBOARD_H
|
||||
#define KSYSTEMCLIPBOARD_H
|
||||
|
||||
#include <kguiaddons_export.h>
|
||||
|
||||
#include <QClipboard>
|
||||
#include <QObject>
|
||||
|
||||
class QMimeData;
|
||||
|
||||
/**
|
||||
* This class mimics QClipboard but unlike QClipboard it will continue
|
||||
* to get updates even when our window does not have focus.
|
||||
*
|
||||
* This may require extra access permissions
|
||||
*
|
||||
* @since 5.89
|
||||
*/
|
||||
class KGUIADDONS_EXPORT KSystemClipboard : public QObject
|
||||
{
|
||||
Q_OBJECT
|
||||
public:
|
||||
/**
|
||||
* Returns a shared global SystemClipboard instance
|
||||
*/
|
||||
static KSystemClipboard *instance();
|
||||
|
||||
/**
|
||||
* Sets the clipboard to the new contents
|
||||
* The clipboard takes ownership of mime
|
||||
*/
|
||||
virtual void setMimeData(QMimeData *mime, QClipboard::Mode mode) = 0;
|
||||
/**
|
||||
* Clears the current clipboard
|
||||
*/
|
||||
virtual void clear(QClipboard::Mode mode) = 0;
|
||||
/**
|
||||
* Returns the current mime data received by the clipboard
|
||||
*/
|
||||
virtual const QMimeData *mimeData(QClipboard::Mode mode) const = 0;
|
||||
/**
|
||||
* Returns the text content of the Clipboard
|
||||
*
|
||||
* Similar to QClipboard::text(QClipboard::Mode mode)
|
||||
*/
|
||||
QString text(QClipboard::Mode mode);
|
||||
Q_SIGNALS:
|
||||
/**
|
||||
* Emitted when the clipboard changes similar to QClipboard::changed
|
||||
*/
|
||||
void changed(QClipboard::Mode mode);
|
||||
|
||||
protected:
|
||||
KSystemClipboard(QObject *parent);
|
||||
};
|
||||
|
||||
#endif
|
||||
@@ -0,0 +1,31 @@
|
||||
/*
|
||||
SPDX-FileCopyrightText: 2020 David Edmundson <davidedmundson@kde.org>
|
||||
|
||||
SPDX-License-Identifier: LGPL-2.0-or-later
|
||||
*/
|
||||
|
||||
#include "qtclipboard_p.h"
|
||||
|
||||
#include <QClipboard>
|
||||
#include <QGuiApplication>
|
||||
|
||||
QtClipboard::QtClipboard(QObject *parent)
|
||||
: KSystemClipboard(parent)
|
||||
{
|
||||
connect(qGuiApp->clipboard(), &QClipboard::changed, this, &QtClipboard::changed);
|
||||
}
|
||||
|
||||
void QtClipboard::setMimeData(QMimeData *mime, QClipboard::Mode mode)
|
||||
{
|
||||
qGuiApp->clipboard()->setMimeData(mime, mode);
|
||||
}
|
||||
|
||||
void QtClipboard::clear(QClipboard::Mode mode)
|
||||
{
|
||||
qGuiApp->clipboard()->clear(mode);
|
||||
}
|
||||
|
||||
const QMimeData *QtClipboard::mimeData(QClipboard::Mode mode) const
|
||||
{
|
||||
return qGuiApp->clipboard()->mimeData(mode);
|
||||
}
|
||||
@@ -0,0 +1,21 @@
|
||||
/*
|
||||
SPDX-FileCopyrightText: 2020 David Edmundson <davidedmundson@kde.org>
|
||||
|
||||
SPDX-License-Identifier: LGPL-2.0-or-later
|
||||
*/
|
||||
|
||||
#ifndef QTCLIPBOARD_H
|
||||
#define QTCLIPBOARD_H
|
||||
|
||||
#include "ksystemclipboard.h"
|
||||
|
||||
class QtClipboard : public KSystemClipboard
|
||||
{
|
||||
public:
|
||||
explicit QtClipboard(QObject *parent);
|
||||
void setMimeData(QMimeData *mime, QClipboard::Mode mode) override;
|
||||
void clear(QClipboard::Mode mode) override;
|
||||
const QMimeData *mimeData(QClipboard::Mode mode) const override;
|
||||
};
|
||||
|
||||
#endif
|
||||
@@ -0,0 +1,44 @@
|
||||
/*
|
||||
SPDX-FileCopyrightText: 2020 David Edmundson <davidedmundson@kde.org>
|
||||
|
||||
SPDX-License-Identifier: GPL-2.0-or-later
|
||||
*/
|
||||
|
||||
#include <QDebug>
|
||||
#include <QGuiApplication>
|
||||
#include <QImage>
|
||||
#include <QMimeData>
|
||||
|
||||
#include "../systemclipboard/ksystemclipboard.h"
|
||||
|
||||
int main(int argc, char **argv)
|
||||
{
|
||||
QGuiApplication app(argc, argv);
|
||||
auto clip = KSystemClipboard::instance();
|
||||
QObject::connect(clip, &KSystemClipboard::changed, &app, [clip](QClipboard::Mode mode) {
|
||||
if (mode != QClipboard::Clipboard) {
|
||||
return;
|
||||
}
|
||||
auto dbg = qDebug();
|
||||
dbg << "New clipboard content: ";
|
||||
|
||||
const QMimeData *mime = clip->mimeData(QClipboard::Clipboard);
|
||||
|
||||
if (mime) {
|
||||
if (mime->hasText()) {
|
||||
dbg << "text data:" << mime->text();
|
||||
} else if (mime->hasImage()) {
|
||||
const QImage image = qvariant_cast<QImage>(mime->imageData());
|
||||
dbg << "image data: " << image.size();
|
||||
} else {
|
||||
dbg << "data: " << mime->formats();
|
||||
}
|
||||
} else {
|
||||
dbg << "[empty]";
|
||||
}
|
||||
});
|
||||
|
||||
qDebug() << "Watching for new clipboard content...";
|
||||
|
||||
return app.exec();
|
||||
}
|
||||
@@ -0,0 +1,706 @@
|
||||
/*
|
||||
SPDX-FileCopyrightText: 2020 David Edmundson <davidedmundson@kde.org>
|
||||
SPDX-FileCopyrightText: 2021 Méven Car <meven.car@enioka.com>
|
||||
|
||||
SPDX-License-Identifier: LGPL-2.0-or-later
|
||||
*/
|
||||
|
||||
#include "waylandclipboard_p.h"
|
||||
|
||||
#include <QBuffer>
|
||||
#include <QFile>
|
||||
#include <QGuiApplication>
|
||||
#include <QImageReader>
|
||||
#include <QImageWriter>
|
||||
#include <QMimeData>
|
||||
#include <QPointer>
|
||||
#include <QWaylandClientExtension>
|
||||
#include <QWindow>
|
||||
#include <QtWaylandClientVersion>
|
||||
|
||||
#include <errno.h>
|
||||
#include <poll.h>
|
||||
#include <signal.h>
|
||||
#include <string.h>
|
||||
#include <unistd.h>
|
||||
|
||||
#include "qwayland-wayland.h"
|
||||
#include "qwayland-wlr-data-control-unstable-v1.h"
|
||||
|
||||
static inline QString applicationQtXImageLiteral()
|
||||
{
|
||||
return QStringLiteral("application/x-qt-image");
|
||||
}
|
||||
|
||||
// copied from https://code.woboq.org/qt5/qtbase/src/gui/kernel/qinternalmimedata.cpp.html
|
||||
static QString utf8Text()
|
||||
{
|
||||
return QStringLiteral("text/plain;charset=utf-8");
|
||||
}
|
||||
|
||||
static QStringList imageMimeFormats(const QList<QByteArray> &imageFormats)
|
||||
{
|
||||
QStringList formats;
|
||||
formats.reserve(imageFormats.size());
|
||||
for (const auto &format : imageFormats)
|
||||
formats.append(QLatin1String("image/") + QLatin1String(format.toLower()));
|
||||
// put png at the front because it is best
|
||||
int pngIndex = formats.indexOf(QLatin1String("image/png"));
|
||||
if (pngIndex != -1 && pngIndex != 0)
|
||||
formats.move(pngIndex, 0);
|
||||
return formats;
|
||||
}
|
||||
|
||||
static inline QStringList imageReadMimeFormats()
|
||||
{
|
||||
return imageMimeFormats(QImageReader::supportedImageFormats());
|
||||
}
|
||||
|
||||
static inline QStringList imageWriteMimeFormats()
|
||||
{
|
||||
return imageMimeFormats(QImageWriter::supportedImageFormats());
|
||||
}
|
||||
// end copied
|
||||
|
||||
class DataControlDeviceManager : public QWaylandClientExtensionTemplate<DataControlDeviceManager>, public QtWayland::zwlr_data_control_manager_v1
|
||||
{
|
||||
Q_OBJECT
|
||||
public:
|
||||
DataControlDeviceManager()
|
||||
: QWaylandClientExtensionTemplate<DataControlDeviceManager>(2)
|
||||
{
|
||||
}
|
||||
|
||||
void instantiate()
|
||||
{
|
||||
initialize();
|
||||
}
|
||||
|
||||
~DataControlDeviceManager()
|
||||
{
|
||||
if (isInitialized()) {
|
||||
destroy();
|
||||
}
|
||||
}
|
||||
};
|
||||
|
||||
class DataControlOffer : public QMimeData, public QtWayland::zwlr_data_control_offer_v1
|
||||
{
|
||||
Q_OBJECT
|
||||
public:
|
||||
DataControlOffer(struct ::zwlr_data_control_offer_v1 *id)
|
||||
: QtWayland::zwlr_data_control_offer_v1(id)
|
||||
{
|
||||
}
|
||||
|
||||
~DataControlOffer()
|
||||
{
|
||||
destroy();
|
||||
}
|
||||
|
||||
QStringList formats() const override
|
||||
{
|
||||
return m_receivedFormats;
|
||||
}
|
||||
|
||||
bool containsImageData() const
|
||||
{
|
||||
if (m_receivedFormats.contains(applicationQtXImageLiteral())) {
|
||||
return true;
|
||||
}
|
||||
const auto formats = imageReadMimeFormats();
|
||||
for (const auto &receivedFormat : m_receivedFormats) {
|
||||
if (formats.contains(receivedFormat)) {
|
||||
return true;
|
||||
}
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
bool hasFormat(const QString &mimeType) const override
|
||||
{
|
||||
if (mimeType == QStringLiteral("text/plain") && m_receivedFormats.contains(utf8Text())) {
|
||||
return true;
|
||||
}
|
||||
if (m_receivedFormats.contains(mimeType)) {
|
||||
return true;
|
||||
}
|
||||
|
||||
// If we have image data
|
||||
if (containsImageData()) {
|
||||
// is the requested output mimeType supported ?
|
||||
const QStringList imageFormats = imageWriteMimeFormats();
|
||||
for (const QString &imageFormat : imageFormats) {
|
||||
if (imageFormat == mimeType) {
|
||||
return true;
|
||||
}
|
||||
}
|
||||
if (mimeType == applicationQtXImageLiteral()) {
|
||||
return true;
|
||||
}
|
||||
}
|
||||
|
||||
return false;
|
||||
}
|
||||
|
||||
protected:
|
||||
void zwlr_data_control_offer_v1_offer(const QString &mime_type) override
|
||||
{
|
||||
if (!m_receivedFormats.contains(mime_type)) {
|
||||
m_receivedFormats << mime_type;
|
||||
}
|
||||
}
|
||||
|
||||
QVariant retrieveData(const QString &mimeType, QMetaType type) const override;
|
||||
|
||||
private:
|
||||
/** reads data from a file descriptor with a timeout of 1 second
|
||||
* true if data is read successfully
|
||||
*/
|
||||
static bool readData(int fd, QByteArray &data);
|
||||
QStringList m_receivedFormats;
|
||||
mutable QHash<QString, QVariant> m_data;
|
||||
};
|
||||
|
||||
QVariant DataControlOffer::retrieveData(const QString &mimeType, QMetaType type) const
|
||||
{
|
||||
Q_UNUSED(type);
|
||||
|
||||
auto it = m_data.constFind(mimeType);
|
||||
if (it != m_data.constEnd())
|
||||
return *it;
|
||||
|
||||
QString mime;
|
||||
if (!m_receivedFormats.contains(mimeType)) {
|
||||
if (mimeType == QStringLiteral("text/plain") && m_receivedFormats.contains(utf8Text())) {
|
||||
mime = utf8Text();
|
||||
} else if (mimeType == applicationQtXImageLiteral()) {
|
||||
const auto writeFormats = imageWriteMimeFormats();
|
||||
for (const auto &receivedFormat : m_receivedFormats) {
|
||||
if (writeFormats.contains(receivedFormat)) {
|
||||
mime = receivedFormat;
|
||||
break;
|
||||
}
|
||||
}
|
||||
if (mime.isEmpty()) {
|
||||
// default exchange format
|
||||
mime = QStringLiteral("image/png");
|
||||
}
|
||||
}
|
||||
|
||||
if (mime.isEmpty()) {
|
||||
return QVariant();
|
||||
}
|
||||
} else {
|
||||
mime = mimeType;
|
||||
}
|
||||
|
||||
int pipeFds[2];
|
||||
if (pipe(pipeFds) != 0) {
|
||||
return QVariant();
|
||||
}
|
||||
|
||||
auto t = const_cast<DataControlOffer *>(this);
|
||||
t->receive(mime, pipeFds[1]);
|
||||
|
||||
close(pipeFds[1]);
|
||||
|
||||
/*
|
||||
* Ideally we need to introduce a non-blocking QMimeData object
|
||||
* Or a non-blocking constructor to QMimeData with the mimetypes that are relevant
|
||||
*
|
||||
* However this isn't actually any worse than X.
|
||||
*/
|
||||
|
||||
auto waylandApp = qGuiApp->nativeInterface<QNativeInterface::QWaylandApplication>();
|
||||
auto display = waylandApp->display();
|
||||
|
||||
wl_display_flush(display);
|
||||
|
||||
QFile readPipe;
|
||||
if (readPipe.open(pipeFds[0], QIODevice::ReadOnly)) {
|
||||
QByteArray data;
|
||||
if (readData(pipeFds[0], data)) {
|
||||
close(pipeFds[0]);
|
||||
|
||||
if (mimeType == applicationQtXImageLiteral()) {
|
||||
QImage img = QImage::fromData(data, mime.mid(mime.indexOf(QLatin1Char('/')) + 1).toLatin1().toUpper().data());
|
||||
if (!img.isNull()) {
|
||||
m_data.insert(mimeType, img);
|
||||
return img;
|
||||
}
|
||||
} else if (data.size() > 1 && mimeType == u"text/uri-list") {
|
||||
const auto urls = data.split('\n');
|
||||
QVariantList list;
|
||||
list.reserve(urls.size());
|
||||
for (const QByteArray &s : urls) {
|
||||
#if QT_VERSION >= QT_VERSION_CHECK(6, 7, 0)
|
||||
if (QUrl url(QUrl::fromEncoded(QByteArrayView(s).trimmed())); url.isValid()) {
|
||||
#else
|
||||
if (QUrl url(QUrl::fromEncoded(QByteArrayView(s).trimmed().toByteArray())); url.isValid()) {
|
||||
#endif
|
||||
list.emplace_back(std::move(url));
|
||||
}
|
||||
}
|
||||
m_data.insert(mimeType, list);
|
||||
return list;
|
||||
}
|
||||
m_data.insert(mimeType, data);
|
||||
return data;
|
||||
}
|
||||
close(pipeFds[0]);
|
||||
}
|
||||
|
||||
return QVariant();
|
||||
}
|
||||
|
||||
bool DataControlOffer::readData(int fd, QByteArray &data)
|
||||
{
|
||||
pollfd pfds[1];
|
||||
pfds[0].fd = fd;
|
||||
pfds[0].events = POLLIN;
|
||||
|
||||
while (true) {
|
||||
const int ready = poll(pfds, 1, 1000);
|
||||
if (ready < 0) {
|
||||
if (errno != EINTR) {
|
||||
qWarning("DataControlOffer: poll() failed: %s", strerror(errno));
|
||||
return false;
|
||||
}
|
||||
} else if (ready == 0) {
|
||||
qWarning("DataControlOffer: timeout reading from pipe");
|
||||
return false;
|
||||
} else {
|
||||
char buf[4096];
|
||||
int n = read(fd, buf, sizeof buf);
|
||||
|
||||
if (n < 0) {
|
||||
qWarning("DataControlOffer: read() failed: %s", strerror(errno));
|
||||
return false;
|
||||
} else if (n == 0) {
|
||||
return true;
|
||||
} else if (n > 0) {
|
||||
data.append(buf, n);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
class DataControlSource : public QObject, public QtWayland::zwlr_data_control_source_v1
|
||||
{
|
||||
Q_OBJECT
|
||||
public:
|
||||
DataControlSource(struct ::zwlr_data_control_source_v1 *id, QMimeData *mimeData);
|
||||
DataControlSource() = default;
|
||||
~DataControlSource()
|
||||
{
|
||||
destroy();
|
||||
}
|
||||
|
||||
QMimeData *mimeData()
|
||||
{
|
||||
return m_mimeData.get();
|
||||
}
|
||||
std::unique_ptr<QMimeData> releaseMimeData()
|
||||
{
|
||||
return std::move(m_mimeData);
|
||||
}
|
||||
|
||||
Q_SIGNALS:
|
||||
void cancelled();
|
||||
|
||||
protected:
|
||||
void zwlr_data_control_source_v1_send(const QString &mime_type, int32_t fd) override;
|
||||
void zwlr_data_control_source_v1_cancelled() override;
|
||||
|
||||
private:
|
||||
std::unique_ptr<QMimeData> m_mimeData;
|
||||
};
|
||||
|
||||
DataControlSource::DataControlSource(struct ::zwlr_data_control_source_v1 *id, QMimeData *mimeData)
|
||||
: QtWayland::zwlr_data_control_source_v1(id)
|
||||
, m_mimeData(mimeData)
|
||||
{
|
||||
const auto formats = mimeData->formats();
|
||||
for (const QString &format : formats) {
|
||||
offer(format);
|
||||
}
|
||||
if (mimeData->hasText()) {
|
||||
// ensure GTK applications get this mimetype to avoid them discarding the offer
|
||||
offer(QStringLiteral("text/plain;charset=utf-8"));
|
||||
}
|
||||
|
||||
if (mimeData->hasImage()) {
|
||||
const QStringList imageFormats = imageWriteMimeFormats();
|
||||
for (const QString &imageFormat : imageFormats) {
|
||||
if (!formats.contains(imageFormat)) {
|
||||
offer(imageFormat);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
void DataControlSource::zwlr_data_control_source_v1_send(const QString &mime_type, int32_t fd)
|
||||
{
|
||||
QString send_mime_type = mime_type;
|
||||
if (send_mime_type == QStringLiteral("text/plain;charset=utf-8")) {
|
||||
// if we get a request on the fallback mime, send the data from the original mime type
|
||||
send_mime_type = QStringLiteral("text/plain");
|
||||
}
|
||||
|
||||
QByteArray ba;
|
||||
if (m_mimeData->hasImage()) {
|
||||
// adapted from QInternalMimeData::renderDataHelper
|
||||
if (mime_type == applicationQtXImageLiteral()) {
|
||||
QImage image = qvariant_cast<QImage>(m_mimeData->imageData());
|
||||
QBuffer buf(&ba);
|
||||
buf.open(QBuffer::WriteOnly);
|
||||
// would there not be PNG ??
|
||||
image.save(&buf, "PNG");
|
||||
|
||||
} else if (mime_type.startsWith(QLatin1String("image/"))) {
|
||||
QImage image = qvariant_cast<QImage>(m_mimeData->imageData());
|
||||
QBuffer buf(&ba);
|
||||
buf.open(QBuffer::WriteOnly);
|
||||
image.save(&buf, mime_type.mid(mime_type.indexOf(QLatin1Char('/')) + 1).toLatin1().toUpper().data());
|
||||
}
|
||||
// end adapted
|
||||
} else {
|
||||
ba = m_mimeData->data(send_mime_type);
|
||||
}
|
||||
|
||||
// Create a sigpipe handler that does nothing, or clients may be forced to terminate
|
||||
// if the pipe is closed in the other end.
|
||||
struct sigaction action, oldAction;
|
||||
action.sa_handler = SIG_IGN;
|
||||
sigemptyset(&action.sa_mask);
|
||||
action.sa_flags = 0;
|
||||
sigaction(SIGPIPE, &action, &oldAction);
|
||||
write(fd, ba.constData(), ba.size());
|
||||
sigaction(SIGPIPE, &oldAction, nullptr);
|
||||
close(fd);
|
||||
}
|
||||
|
||||
void DataControlSource::zwlr_data_control_source_v1_cancelled()
|
||||
{
|
||||
Q_EMIT cancelled();
|
||||
}
|
||||
|
||||
class DataControlDevice : public QObject, public QtWayland::zwlr_data_control_device_v1
|
||||
{
|
||||
Q_OBJECT
|
||||
public:
|
||||
DataControlDevice(struct ::zwlr_data_control_device_v1 *id)
|
||||
: QtWayland::zwlr_data_control_device_v1(id)
|
||||
{
|
||||
}
|
||||
|
||||
~DataControlDevice()
|
||||
{
|
||||
destroy();
|
||||
}
|
||||
|
||||
void setSelection(std::unique_ptr<DataControlSource> selection);
|
||||
QMimeData *receivedSelection()
|
||||
{
|
||||
return m_receivedSelection.get();
|
||||
}
|
||||
QMimeData *selection()
|
||||
{
|
||||
return m_selection ? m_selection->mimeData() : nullptr;
|
||||
}
|
||||
|
||||
void setPrimarySelection(std::unique_ptr<DataControlSource> selection);
|
||||
QMimeData *receivedPrimarySelection()
|
||||
{
|
||||
return m_receivedPrimarySelection.get();
|
||||
}
|
||||
QMimeData *primarySelection()
|
||||
{
|
||||
return m_primarySelection ? m_primarySelection->mimeData() : nullptr;
|
||||
}
|
||||
|
||||
Q_SIGNALS:
|
||||
void receivedSelectionChanged();
|
||||
void selectionChanged();
|
||||
|
||||
void receivedPrimarySelectionChanged();
|
||||
void primarySelectionChanged();
|
||||
|
||||
protected:
|
||||
void zwlr_data_control_device_v1_data_offer(struct ::zwlr_data_control_offer_v1 *id) override
|
||||
{
|
||||
// this will become memory managed when we retrieve the selection event
|
||||
// a compositor calling data_offer without doing that would be a bug
|
||||
new DataControlOffer(id);
|
||||
}
|
||||
|
||||
void zwlr_data_control_device_v1_selection(struct ::zwlr_data_control_offer_v1 *id) override
|
||||
{
|
||||
if (!id) {
|
||||
m_receivedSelection.reset();
|
||||
} else {
|
||||
auto derivated = QtWayland::zwlr_data_control_offer_v1::fromObject(id);
|
||||
auto offer = dynamic_cast<DataControlOffer *>(derivated); // dynamic because of the dual inheritance
|
||||
m_receivedSelection.reset(offer);
|
||||
}
|
||||
Q_EMIT receivedSelectionChanged();
|
||||
}
|
||||
|
||||
void zwlr_data_control_device_v1_primary_selection(struct ::zwlr_data_control_offer_v1 *id) override
|
||||
{
|
||||
if (!id) {
|
||||
m_receivedPrimarySelection.reset();
|
||||
} else {
|
||||
auto derivated = QtWayland::zwlr_data_control_offer_v1::fromObject(id);
|
||||
auto offer = dynamic_cast<DataControlOffer *>(derivated); // dynamic because of the dual inheritance
|
||||
m_receivedPrimarySelection.reset(offer);
|
||||
}
|
||||
Q_EMIT receivedPrimarySelectionChanged();
|
||||
}
|
||||
|
||||
private:
|
||||
std::unique_ptr<DataControlSource> m_selection; // selection set locally
|
||||
std::unique_ptr<DataControlOffer> m_receivedSelection; // latest selection set from externally to here
|
||||
|
||||
std::unique_ptr<DataControlSource> m_primarySelection; // selection set locally
|
||||
std::unique_ptr<DataControlOffer> m_receivedPrimarySelection; // latest selection set from externally to here
|
||||
friend WaylandClipboard;
|
||||
};
|
||||
|
||||
void DataControlDevice::setSelection(std::unique_ptr<DataControlSource> selection)
|
||||
{
|
||||
m_selection = std::move(selection);
|
||||
connect(m_selection.get(), &DataControlSource::cancelled, this, [this]() {
|
||||
m_selection.reset();
|
||||
});
|
||||
set_selection(m_selection->object());
|
||||
Q_EMIT selectionChanged();
|
||||
}
|
||||
|
||||
void DataControlDevice::setPrimarySelection(std::unique_ptr<DataControlSource> selection)
|
||||
{
|
||||
m_primarySelection = std::move(selection);
|
||||
connect(m_primarySelection.get(), &DataControlSource::cancelled, this, [this]() {
|
||||
m_primarySelection.reset();
|
||||
});
|
||||
|
||||
if (zwlr_data_control_device_v1_get_version(object()) >= ZWLR_DATA_CONTROL_DEVICE_V1_SET_PRIMARY_SELECTION_SINCE_VERSION) {
|
||||
set_primary_selection(m_primarySelection->object());
|
||||
Q_EMIT primarySelectionChanged();
|
||||
}
|
||||
}
|
||||
class Keyboard;
|
||||
// We are binding to Seat/Keyboard manually because we want to react to gaining focus but inside Qt the events are Qt and arrive to late
|
||||
class KeyboardFocusWatcher : public QWaylandClientExtensionTemplate<KeyboardFocusWatcher>, public QtWayland::wl_seat
|
||||
{
|
||||
Q_OBJECT
|
||||
public:
|
||||
KeyboardFocusWatcher()
|
||||
: QWaylandClientExtensionTemplate(5)
|
||||
{
|
||||
initialize();
|
||||
auto waylandApp = qGuiApp->nativeInterface<QNativeInterface::QWaylandApplication>();
|
||||
auto display = waylandApp->display();
|
||||
// so we get capabilities
|
||||
wl_display_roundtrip(display);
|
||||
}
|
||||
~KeyboardFocusWatcher() override
|
||||
{
|
||||
if (isActive()) {
|
||||
release();
|
||||
}
|
||||
}
|
||||
void seat_capabilities(uint32_t capabilities) override
|
||||
{
|
||||
const bool hasKeyboard = capabilities & capability_keyboard;
|
||||
if (hasKeyboard && !m_keyboard) {
|
||||
m_keyboard = std::make_unique<Keyboard>(get_keyboard(), *this);
|
||||
} else if (!hasKeyboard && m_keyboard) {
|
||||
m_keyboard.reset();
|
||||
}
|
||||
}
|
||||
bool hasFocus() const
|
||||
{
|
||||
return m_focus;
|
||||
}
|
||||
Q_SIGNALS:
|
||||
void keyboardEntered();
|
||||
|
||||
private:
|
||||
friend Keyboard;
|
||||
bool m_focus = false;
|
||||
std::unique_ptr<Keyboard> m_keyboard;
|
||||
};
|
||||
|
||||
class Keyboard : public QtWayland::wl_keyboard
|
||||
{
|
||||
public:
|
||||
Keyboard(::wl_keyboard *keyboard, KeyboardFocusWatcher &seat)
|
||||
: wl_keyboard(keyboard)
|
||||
, m_seat(seat)
|
||||
{
|
||||
}
|
||||
~Keyboard()
|
||||
{
|
||||
release();
|
||||
}
|
||||
|
||||
private:
|
||||
void keyboard_enter([[maybe_unused]] uint32_t serial, [[maybe_unused]] wl_surface *surface, [[maybe_unused]] wl_array *keys) override
|
||||
{
|
||||
m_seat.m_focus = true;
|
||||
Q_EMIT m_seat.keyboardEntered();
|
||||
}
|
||||
void keyboard_leave([[maybe_unused]] uint32_t serial, [[maybe_unused]] wl_surface *surface) override
|
||||
{
|
||||
m_seat.m_focus = false;
|
||||
}
|
||||
KeyboardFocusWatcher &m_seat;
|
||||
};
|
||||
|
||||
WaylandClipboard::WaylandClipboard(QObject *parent)
|
||||
: KSystemClipboard(parent)
|
||||
, m_keyboardFocusWatcher(new KeyboardFocusWatcher)
|
||||
, m_manager(new DataControlDeviceManager)
|
||||
{
|
||||
connect(m_manager.get(), &DataControlDeviceManager::activeChanged, this, [this]() {
|
||||
if (m_manager->isActive()) {
|
||||
auto waylandApp = qGuiApp->nativeInterface<QNativeInterface::QWaylandApplication>();
|
||||
if (!waylandApp) {
|
||||
return;
|
||||
}
|
||||
auto seat = waylandApp->seat();
|
||||
|
||||
if (!seat) {
|
||||
return;
|
||||
}
|
||||
m_device.reset(new DataControlDevice(m_manager->get_data_device(seat)));
|
||||
|
||||
connect(m_device.get(), &DataControlDevice::receivedSelectionChanged, this, [this]() {
|
||||
// When our source is still valid, so the offer is for setting it or we emit changed when it is cancelled
|
||||
if (!m_device->selection()) {
|
||||
Q_EMIT changed(QClipboard::Clipboard);
|
||||
}
|
||||
});
|
||||
connect(m_device.get(), &DataControlDevice::selectionChanged, this, [this]() {
|
||||
Q_EMIT changed(QClipboard::Clipboard);
|
||||
});
|
||||
|
||||
connect(m_device.get(), &DataControlDevice::receivedPrimarySelectionChanged, this, [this]() {
|
||||
// When our source is still valid, so the offer is for setting it or we emit changed when it is cancelled
|
||||
if (!m_device->primarySelection()) {
|
||||
Q_EMIT changed(QClipboard::Selection);
|
||||
}
|
||||
});
|
||||
connect(m_device.get(), &DataControlDevice::primarySelectionChanged, this, [this]() {
|
||||
Q_EMIT changed(QClipboard::Selection);
|
||||
});
|
||||
|
||||
} else {
|
||||
m_device.reset();
|
||||
}
|
||||
});
|
||||
|
||||
m_manager->instantiate();
|
||||
}
|
||||
|
||||
WaylandClipboard::~WaylandClipboard() = default;
|
||||
|
||||
bool WaylandClipboard::isValid()
|
||||
{
|
||||
return m_manager && m_manager->isInitialized();
|
||||
}
|
||||
|
||||
void WaylandClipboard::setMimeData(QMimeData *mime, QClipboard::Mode mode)
|
||||
{
|
||||
if (!m_device) {
|
||||
return;
|
||||
}
|
||||
|
||||
// roundtrip to have accurate focus state when losing focus but setting mime data before processing wayland events.
|
||||
auto waylandApp = qGuiApp->nativeInterface<QNativeInterface::QWaylandApplication>();
|
||||
auto display = waylandApp->display();
|
||||
wl_display_roundtrip(display);
|
||||
|
||||
// If the application is focused, use the normal mechanism so a future paste will not deadlock itselfs
|
||||
if (m_keyboardFocusWatcher->hasFocus()) {
|
||||
QGuiApplication::clipboard()->setMimeData(mime, mode);
|
||||
// if we short-circuit the wlr_data_device, when we receive the data
|
||||
// we cannot identify ourselves as the owner
|
||||
// because of that we act like it's a synchronous action to not confuse klipper.
|
||||
wl_display_roundtrip(display);
|
||||
return;
|
||||
}
|
||||
// If not, set the clipboard once the app receives focus to avoid the deadlock
|
||||
connect(m_keyboardFocusWatcher.get(), &KeyboardFocusWatcher::keyboardEntered, this, &WaylandClipboard::gainedFocus, Qt::UniqueConnection);
|
||||
auto source = std::make_unique<DataControlSource>(m_manager->create_data_source(), mime);
|
||||
if (mode == QClipboard::Clipboard) {
|
||||
m_device->setSelection(std::move(source));
|
||||
} else if (mode == QClipboard::Selection) {
|
||||
m_device->setPrimarySelection(std::move(source));
|
||||
}
|
||||
}
|
||||
|
||||
void WaylandClipboard::gainedFocus()
|
||||
{
|
||||
disconnect(m_keyboardFocusWatcher.get(), &KeyboardFocusWatcher::keyboardEntered, this, nullptr);
|
||||
// QClipboard takes ownership of the QMimeData so we need to transfer and unset our selections
|
||||
if (auto &selection = m_device->m_selection) {
|
||||
std::unique_ptr<QMimeData> data = selection->releaseMimeData();
|
||||
selection.reset();
|
||||
QGuiApplication::clipboard()->setMimeData(data.release(), QClipboard::Clipboard);
|
||||
}
|
||||
if (auto &primarySelection = m_device->m_primarySelection) {
|
||||
std::unique_ptr<QMimeData> data = primarySelection->releaseMimeData();
|
||||
primarySelection.reset();
|
||||
QGuiApplication::clipboard()->setMimeData(data.release(), QClipboard::Selection);
|
||||
}
|
||||
}
|
||||
|
||||
void WaylandClipboard::clear(QClipboard::Mode mode)
|
||||
{
|
||||
if (!m_device) {
|
||||
return;
|
||||
}
|
||||
if (mode == QClipboard::Clipboard) {
|
||||
m_device->set_selection(nullptr);
|
||||
m_device->m_selection.reset();
|
||||
} else if (mode == QClipboard::Selection) {
|
||||
if (zwlr_data_control_device_v1_get_version(m_device->object()) >= ZWLR_DATA_CONTROL_DEVICE_V1_SET_PRIMARY_SELECTION_SINCE_VERSION) {
|
||||
m_device->set_primary_selection(nullptr);
|
||||
m_device->m_primarySelection.reset();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
const QMimeData *WaylandClipboard::mimeData(QClipboard::Mode mode) const
|
||||
{
|
||||
if (!m_device) {
|
||||
return nullptr;
|
||||
}
|
||||
|
||||
// return our locally set selection if it's not cancelled to avoid copying data to ourselves
|
||||
if (mode == QClipboard::Clipboard) {
|
||||
if (m_device->selection()) {
|
||||
return m_device->selection();
|
||||
}
|
||||
// This application owns the clipboard via the regular data_device, use it so we don't block ourselves
|
||||
if (QGuiApplication::clipboard()->ownsClipboard()) {
|
||||
return QGuiApplication::clipboard()->mimeData(mode);
|
||||
}
|
||||
return m_device->receivedSelection();
|
||||
} else if (mode == QClipboard::Selection) {
|
||||
if (m_device->primarySelection()) {
|
||||
return m_device->primarySelection();
|
||||
}
|
||||
// This application owns the primary selection via the regular primary_selection_device, use it so we don't block ourselves
|
||||
if (QGuiApplication::clipboard()->ownsSelection()) {
|
||||
return QGuiApplication::clipboard()->mimeData(mode);
|
||||
}
|
||||
return m_device->receivedPrimarySelection();
|
||||
}
|
||||
return nullptr;
|
||||
}
|
||||
|
||||
#include "waylandclipboard.moc"
|
||||
@@ -0,0 +1,36 @@
|
||||
/*
|
||||
SPDX-FileCopyrightText: 2020 David Edmundson <davidedmundson@kde.org>
|
||||
|
||||
SPDX-License-Identifier: LGPL-2.0-or-later
|
||||
*/
|
||||
|
||||
#ifndef WAYLANDCLIPBOARD_H
|
||||
#define WAYLANDCLIPBOARD_H
|
||||
|
||||
#include "ksystemclipboard.h"
|
||||
|
||||
#include <memory>
|
||||
|
||||
class DataControlDevice;
|
||||
class DataControlDeviceManager;
|
||||
class KeyboardFocusWatcher;
|
||||
|
||||
class WaylandClipboard : public KSystemClipboard
|
||||
{
|
||||
public:
|
||||
WaylandClipboard(QObject *parent);
|
||||
~WaylandClipboard();
|
||||
void setMimeData(QMimeData *mime, QClipboard::Mode mode) override;
|
||||
void clear(QClipboard::Mode mode) override;
|
||||
const QMimeData *mimeData(QClipboard::Mode mode) const override;
|
||||
|
||||
bool isValid();
|
||||
|
||||
private:
|
||||
void gainedFocus();
|
||||
std::unique_ptr<KeyboardFocusWatcher> m_keyboardFocusWatcher;
|
||||
std::unique_ptr<DataControlDeviceManager> m_manager;
|
||||
std::unique_ptr<DataControlDevice> m_device;
|
||||
};
|
||||
|
||||
#endif
|
||||
+278
@@ -0,0 +1,278 @@
|
||||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
<protocol name="wlr_data_control_unstable_v1">
|
||||
<copyright>
|
||||
Copyright © 2018 Simon Ser
|
||||
Copyright © 2019 Ivan Molodetskikh
|
||||
|
||||
Permission to use, copy, modify, distribute, and sell this
|
||||
software and its documentation for any purpose is hereby granted
|
||||
without fee, provided that the above copyright notice appear in
|
||||
all copies and that both that copyright notice and this permission
|
||||
notice appear in supporting documentation, and that the name of
|
||||
the copyright holders not be used in advertising or publicity
|
||||
pertaining to distribution of the software without specific,
|
||||
written prior permission. The copyright holders make no
|
||||
representations about the suitability of this software for any
|
||||
purpose. It is provided "as is" without express or implied
|
||||
warranty.
|
||||
|
||||
THE COPYRIGHT HOLDERS DISCLAIM ALL WARRANTIES WITH REGARD TO THIS
|
||||
SOFTWARE, INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY AND
|
||||
FITNESS, IN NO EVENT SHALL THE COPYRIGHT HOLDERS BE LIABLE FOR ANY
|
||||
SPECIAL, INDIRECT OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES
|
||||
WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN
|
||||
AN ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION,
|
||||
ARISING OUT OF OR IN CONNECTION WITH THE USE OR PERFORMANCE OF
|
||||
THIS SOFTWARE.
|
||||
</copyright>
|
||||
|
||||
<description summary="control data devices">
|
||||
This protocol allows a privileged client to control data devices. In
|
||||
particular, the client will be able to manage the current selection and take
|
||||
the role of a clipboard manager.
|
||||
|
||||
Warning! The protocol described in this file is experimental and
|
||||
backward incompatible changes may be made. Backward compatible changes
|
||||
may be added together with the corresponding interface version bump.
|
||||
Backward incompatible changes are done by bumping the version number in
|
||||
the protocol and interface names and resetting the interface version.
|
||||
Once the protocol is to be declared stable, the 'z' prefix and the
|
||||
version number in the protocol and interface names are removed and the
|
||||
interface version number is reset.
|
||||
</description>
|
||||
|
||||
<interface name="zwlr_data_control_manager_v1" version="2">
|
||||
<description summary="manager to control data devices">
|
||||
This interface is a manager that allows creating per-seat data device
|
||||
controls.
|
||||
</description>
|
||||
|
||||
<request name="create_data_source">
|
||||
<description summary="create a new data source">
|
||||
Create a new data source.
|
||||
</description>
|
||||
<arg name="id" type="new_id" interface="zwlr_data_control_source_v1"
|
||||
summary="data source to create"/>
|
||||
</request>
|
||||
|
||||
<request name="get_data_device">
|
||||
<description summary="get a data device for a seat">
|
||||
Create a data device that can be used to manage a seat's selection.
|
||||
</description>
|
||||
<arg name="id" type="new_id" interface="zwlr_data_control_device_v1"/>
|
||||
<arg name="seat" type="object" interface="wl_seat"/>
|
||||
</request>
|
||||
|
||||
<request name="destroy" type="destructor">
|
||||
<description summary="destroy the manager">
|
||||
All objects created by the manager will still remain valid, until their
|
||||
appropriate destroy request has been called.
|
||||
</description>
|
||||
</request>
|
||||
</interface>
|
||||
|
||||
<interface name="zwlr_data_control_device_v1" version="2">
|
||||
<description summary="manage a data device for a seat">
|
||||
This interface allows a client to manage a seat's selection.
|
||||
|
||||
When the seat is destroyed, this object becomes inert.
|
||||
</description>
|
||||
|
||||
<request name="set_selection">
|
||||
<description summary="copy data to the selection">
|
||||
This request asks the compositor to set the selection to the data from
|
||||
the source on behalf of the client.
|
||||
|
||||
The given source may not be used in any further set_selection or
|
||||
set_primary_selection requests. Attempting to use a previously used
|
||||
source is a protocol error.
|
||||
|
||||
To unset the selection, set the source to NULL.
|
||||
</description>
|
||||
<arg name="source" type="object" interface="zwlr_data_control_source_v1"
|
||||
allow-null="true"/>
|
||||
</request>
|
||||
|
||||
<request name="destroy" type="destructor">
|
||||
<description summary="destroy this data device">
|
||||
Destroys the data device object.
|
||||
</description>
|
||||
</request>
|
||||
|
||||
<event name="data_offer">
|
||||
<description summary="introduce a new wlr_data_control_offer">
|
||||
The data_offer event introduces a new wlr_data_control_offer object,
|
||||
which will subsequently be used in either the
|
||||
wlr_data_control_device.selection event (for the regular clipboard
|
||||
selections) or the wlr_data_control_device.primary_selection event (for
|
||||
the primary clipboard selections). Immediately following the
|
||||
wlr_data_control_device.data_offer event, the new data_offer object
|
||||
will send out wlr_data_control_offer.offer events to describe the MIME
|
||||
types it offers.
|
||||
</description>
|
||||
<arg name="id" type="new_id" interface="zwlr_data_control_offer_v1"/>
|
||||
</event>
|
||||
|
||||
<event name="selection">
|
||||
<description summary="advertise new selection">
|
||||
The selection event is sent out to notify the client of a new
|
||||
wlr_data_control_offer for the selection for this device. The
|
||||
wlr_data_control_device.data_offer and the wlr_data_control_offer.offer
|
||||
events are sent out immediately before this event to introduce the data
|
||||
offer object. The selection event is sent to a client when a new
|
||||
selection is set. The wlr_data_control_offer is valid until a new
|
||||
wlr_data_control_offer or NULL is received. The client must destroy the
|
||||
previous selection wlr_data_control_offer, if any, upon receiving this
|
||||
event.
|
||||
|
||||
The first selection event is sent upon binding the
|
||||
wlr_data_control_device object.
|
||||
</description>
|
||||
<arg name="id" type="object" interface="zwlr_data_control_offer_v1"
|
||||
allow-null="true"/>
|
||||
</event>
|
||||
|
||||
<event name="finished">
|
||||
<description summary="this data control is no longer valid">
|
||||
This data control object is no longer valid and should be destroyed by
|
||||
the client.
|
||||
</description>
|
||||
</event>
|
||||
|
||||
<!-- Version 2 additions -->
|
||||
|
||||
<event name="primary_selection" since="2">
|
||||
<description summary="advertise new primary selection">
|
||||
The primary_selection event is sent out to notify the client of a new
|
||||
wlr_data_control_offer for the primary selection for this device. The
|
||||
wlr_data_control_device.data_offer and the wlr_data_control_offer.offer
|
||||
events are sent out immediately before this event to introduce the data
|
||||
offer object. The primary_selection event is sent to a client when a
|
||||
new primary selection is set. The wlr_data_control_offer is valid until
|
||||
a new wlr_data_control_offer or NULL is received. The client must
|
||||
destroy the previous primary selection wlr_data_control_offer, if any,
|
||||
upon receiving this event.
|
||||
|
||||
If the compositor supports primary selection, the first
|
||||
primary_selection event is sent upon binding the
|
||||
wlr_data_control_device object.
|
||||
</description>
|
||||
<arg name="id" type="object" interface="zwlr_data_control_offer_v1"
|
||||
allow-null="true"/>
|
||||
</event>
|
||||
|
||||
<request name="set_primary_selection" since="2">
|
||||
<description summary="copy data to the primary selection">
|
||||
This request asks the compositor to set the primary selection to the
|
||||
data from the source on behalf of the client.
|
||||
|
||||
The given source may not be used in any further set_selection or
|
||||
set_primary_selection requests. Attempting to use a previously used
|
||||
source is a protocol error.
|
||||
|
||||
To unset the primary selection, set the source to NULL.
|
||||
|
||||
The compositor will ignore this request if it does not support primary
|
||||
selection.
|
||||
</description>
|
||||
<arg name="source" type="object" interface="zwlr_data_control_source_v1"
|
||||
allow-null="true"/>
|
||||
</request>
|
||||
|
||||
<enum name="error" since="2">
|
||||
<entry name="used_source" value="1"
|
||||
summary="source given to set_selection or set_primary_selection was already used before"/>
|
||||
</enum>
|
||||
</interface>
|
||||
|
||||
<interface name="zwlr_data_control_source_v1" version="1">
|
||||
<description summary="offer to transfer data">
|
||||
The wlr_data_control_source object is the source side of a
|
||||
wlr_data_control_offer. It is created by the source client in a data
|
||||
transfer and provides a way to describe the offered data and a way to
|
||||
respond to requests to transfer the data.
|
||||
</description>
|
||||
|
||||
<enum name="error">
|
||||
<entry name="invalid_offer" value="1"
|
||||
summary="offer sent after wlr_data_control_device.set_selection"/>
|
||||
</enum>
|
||||
|
||||
<request name="offer">
|
||||
<description summary="add an offered MIME type">
|
||||
This request adds a MIME type to the set of MIME types advertised to
|
||||
targets. Can be called several times to offer multiple types.
|
||||
|
||||
Calling this after wlr_data_control_device.set_selection is a protocol
|
||||
error.
|
||||
</description>
|
||||
<arg name="mime_type" type="string"
|
||||
summary="MIME type offered by the data source"/>
|
||||
</request>
|
||||
|
||||
<request name="destroy" type="destructor">
|
||||
<description summary="destroy this source">
|
||||
Destroys the data source object.
|
||||
</description>
|
||||
</request>
|
||||
|
||||
<event name="send">
|
||||
<description summary="send the data">
|
||||
Request for data from the client. Send the data as the specified MIME
|
||||
type over the passed file descriptor, then close it.
|
||||
</description>
|
||||
<arg name="mime_type" type="string" summary="MIME type for the data"/>
|
||||
<arg name="fd" type="fd" summary="file descriptor for the data"/>
|
||||
</event>
|
||||
|
||||
<event name="cancelled">
|
||||
<description summary="selection was cancelled">
|
||||
This data source is no longer valid. The data source has been replaced
|
||||
by another data source.
|
||||
|
||||
The client should clean up and destroy this data source.
|
||||
</description>
|
||||
</event>
|
||||
</interface>
|
||||
|
||||
<interface name="zwlr_data_control_offer_v1" version="1">
|
||||
<description summary="offer to transfer data">
|
||||
A wlr_data_control_offer represents a piece of data offered for transfer
|
||||
by another client (the source client). The offer describes the different
|
||||
MIME types that the data can be converted to and provides the mechanism
|
||||
for transferring the data directly from the source client.
|
||||
</description>
|
||||
|
||||
<request name="receive">
|
||||
<description summary="request that the data is transferred">
|
||||
To transfer the offered data, the client issues this request and
|
||||
indicates the MIME type it wants to receive. The transfer happens
|
||||
through the passed file descriptor (typically created with the pipe
|
||||
system call). The source client writes the data in the MIME type
|
||||
representation requested and then closes the file descriptor.
|
||||
|
||||
The receiving client reads from the read end of the pipe until EOF and
|
||||
then closes its end, at which point the transfer is complete.
|
||||
|
||||
This request may happen multiple times for different MIME types.
|
||||
</description>
|
||||
<arg name="mime_type" type="string"
|
||||
summary="MIME type desired by receiver"/>
|
||||
<arg name="fd" type="fd" summary="file descriptor for data transfer"/>
|
||||
</request>
|
||||
|
||||
<request name="destroy" type="destructor">
|
||||
<description summary="destroy this offer">
|
||||
Destroys the data offer object.
|
||||
</description>
|
||||
</request>
|
||||
|
||||
<event name="offer">
|
||||
<description summary="advertise offered MIME type">
|
||||
Sent immediately after creating the wlr_data_control_offer object.
|
||||
One event per offered MIME type.
|
||||
</description>
|
||||
<arg name="mime_type" type="string" summary="offered MIME type"/>
|
||||
</event>
|
||||
</interface>
|
||||
</protocol>
|
||||
Reference in New Issue
Block a user