From 9df70836ea64e0131c68bd8a13762cec47ca36f4 Mon Sep 17 00:00:00 2001 From: Lukas Holecek Date: Mon, 11 Nov 2024 20:43:22 +0100 Subject: [PATCH] Wayland: Remove no longer used code --- .../x11/systemclipboard/waylandclipboard.cpp | 224 ------------------ .../x11/systemclipboard/waylandclipboard.h | 2 - 2 files changed, 226 deletions(-) diff --git a/src/platform/x11/systemclipboard/waylandclipboard.cpp b/src/platform/x11/systemclipboard/waylandclipboard.cpp index 94d718f9e5..89db023de5 100644 --- a/src/platform/x11/systemclipboard/waylandclipboard.cpp +++ b/src/platform/x11/systemclipboard/waylandclipboard.cpp @@ -23,7 +23,6 @@ #include #include #include -#include #include #include @@ -66,42 +65,6 @@ static inline QStringList imageWriteMimeFormats() namespace { -class SendThread : public QThread { -public: - SendThread(int fd, const QByteArray &data) - : m_data(data) - , m_fd(fd) - {} - -protected: - void run() override { - QFile c; - if (c.open(m_fd, QFile::WriteOnly, QFile::AutoCloseHandle)) { - // 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); - // Unset O_NONBLOCK - fcntl(m_fd, F_SETFL, 0); - const qint64 written = c.write(m_data); - sigaction(SIGPIPE, &oldAction, nullptr); - c.close(); - - if (written != m_data.size()) { - qWarning() << "Failed to send all clipobard data; sent" - << written << "bytes out of" << m_data.size(); - } - } - } - -private: - QByteArray m_data; - int m_fd; -}; - class ReceiveThread : public QThread { public: ReceiveThread(int fd) @@ -337,106 +300,6 @@ QVariant DataControlOffer::retrieveData(const QString &mimeType, QVariant::Type return data; } -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() - { - if (m_mimeData) { - m_mimeData->deleteLater(); - m_mimeData = nullptr; - } - if ( isInitialized() ) - destroy(); - } - - QMimeData *mimeData() - { - return m_mimeData; - } - - bool isCancelled() const { return m_cancelled; } - -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: - QMimeData *m_mimeData = nullptr; - bool m_cancelled = false; -}; - -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") - && !m_mimeData->hasFormat(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(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(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); - } - - auto thread = new SendThread(fd, m_mimeData->data(send_mime_type)); - connect(thread, &QThread::finished, thread, &QObject::deleteLater); - thread->start(); -} - -void DataControlSource::zwlr_data_control_source_v1_cancelled() -{ - m_cancelled = true; - Q_EMIT cancelled(); -} - class DataControlDevice : public QObject, public QtWayland::zwlr_data_control_device_v1 { Q_OBJECT @@ -452,32 +315,20 @@ class DataControlDevice : public QObject, public QtWayland::zwlr_data_control_de destroy(); } - void setSelection(std::unique_ptr selection); QMimeData *receivedSelection() { return m_receivedSelection.get(); } - QMimeData *selection() - { - return m_selection ? m_selection->mimeData() : nullptr; - } - void setPrimarySelection(std::unique_ptr 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 @@ -520,38 +371,10 @@ class DataControlDevice : public QObject, public QtWayland::zwlr_data_control_de } private: - std::unique_ptr m_selection; // selection set locally std::unique_ptr m_receivedSelection; // latest selection set from externally to here - - std::unique_ptr m_primarySelection; // selection set locally std::unique_ptr m_receivedPrimarySelection; // latest selection set from externally to here }; -void DataControlDevice::setSelection(std::unique_ptr selection) -{ - m_selection = std::move(selection); - connect(m_selection.get(), &DataControlSource::cancelled, this, [this]() { - m_selection.reset(); - Q_EMIT selectionChanged(); - }); - set_selection(m_selection->object()); - Q_EMIT selectionChanged(); -} - -void DataControlDevice::setPrimarySelection(std::unique_ptr selection) -{ - m_primarySelection = std::move(selection); - connect(m_primarySelection.get(), &DataControlSource::cancelled, this, [this]() { - m_primarySelection.reset(); - Q_EMIT primarySelectionChanged(); - }); - - 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(); - } -} - WaylandClipboard::WaylandClipboard(QObject *parent) : QObject(parent) , m_manager(new DataControlDeviceManager) @@ -570,25 +393,12 @@ WaylandClipboard::WaylandClipboard(QObject *parent) 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(); } @@ -616,49 +426,15 @@ WaylandClipboard *WaylandClipboard::createInstance() return clipboard; } -void WaylandClipboard::setMimeData(QMimeData *mime, QClipboard::Mode mode) -{ - if (!m_device) { - return; - } - std::unique_ptr source(new 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::clear(QClipboard::Mode mode) -{ - if (!m_device) { - return; - } - if (mode == QClipboard::Clipboard) { - m_device->set_selection(nullptr); - } 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); - } - } -} - 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(); - } return m_device->receivedSelection(); } else if (mode == QClipboard::Selection) { - if (m_device->primarySelection()) { - return m_device->primarySelection(); - } return m_device->receivedPrimarySelection(); } return nullptr; diff --git a/src/platform/x11/systemclipboard/waylandclipboard.h b/src/platform/x11/systemclipboard/waylandclipboard.h index 0b68a6ff74..43a6122070 100644 --- a/src/platform/x11/systemclipboard/waylandclipboard.h +++ b/src/platform/x11/systemclipboard/waylandclipboard.h @@ -22,8 +22,6 @@ class WaylandClipboard final : public QObject ~WaylandClipboard(); - void setMimeData(QMimeData *mime, QClipboard::Mode mode); - void clear(QClipboard::Mode mode); const QMimeData *mimeData(QClipboard::Mode mode) const; bool isActive() const { return m_device != nullptr; } bool isSelectionSupported() const;