Qt
Internal/Contributor docs for the Qt SDK. <b>Note:</b> These are NOT official API docs; those are found <a href='https://doc.qt.io/'>here</a>.
Loading...
Searching...
No Matches
qwaylandprimaryselectionv1.cpp
Go to the documentation of this file.
1// Copyright (C) 2019 The Qt Company Ltd.
2// SPDX-License-Identifier: LicenseRef-Qt-Commercial OR LGPL-3.0-only OR GPL-2.0-only OR GPL-3.0-only
3
6#include "qwaylanddisplay_p.h"
8
9#include <QtGui/private/qguiapplication_p.h>
10
11#include <qpa/qplatformclipboard.h>
12
14
15namespace QtWaylandClient {
16
18 : zwp_primary_selection_device_manager_v1(display->wl_registry(), id, qMin(version, uint(1)))
19 , m_display(display)
20{
21}
22
27
32
34 : zwp_primary_selection_offer_v1(offer)
35 , m_display(display)
36 , m_mimeData(new QWaylandMimeData(this))
37{}
38
40{
41 receive(mimeType, fd);
42 wl_display_flush(m_display->wl_display());
43}
44
46{
47 m_mimeData->appendFormat(mime_type);
48}
49
50QWaylandPrimarySelectionDeviceV1::QWaylandPrimarySelectionDeviceV1(
52 : QtWayland::zwp_primary_selection_device_v1(manager->get_device(seat->wl_seat()))
53 , m_display(manager->display())
54 , m_seat(seat)
55{
56}
57
62
64{
65 if (!m_selectionOffer)
66 return;
67
68 m_selectionOffer.reset();
70}
71
73{
74 if (source) {
76 m_selectionSource.reset();
78 });
79 }
80 set_selection(source ? source->object() : nullptr, m_seat->serial());
81 m_selectionSource.reset(source);
82}
83
85{
86 new QWaylandPrimarySelectionOfferV1(m_display, offer);
87}
88
90{
91
92 if (id)
93 m_selectionOffer.reset(static_cast<QWaylandPrimarySelectionOfferV1 *>(zwp_primary_selection_offer_v1_get_user_data(id)));
94 else
95 m_selectionOffer.reset();
96
98}
99
101 : QtWayland::zwp_primary_selection_source_v1(manager->create_source())
102 , m_mimeData(mimeData)
103{
104 if (!mimeData)
105 return;
106 for (auto &format : mimeData->formats())
107 offer(format);
108}
109
114
116{
117 QByteArray content = QWaylandMimeHelper::getByteArray(m_mimeData, mime_type);
118 if (!content.isEmpty()) {
119 // Create a sigpipe handler that does nothing, or clients may be forced to terminate
120 // if the pipe is closed in the other end.
121 struct sigaction action, oldAction;
122 action.sa_handler = SIG_IGN;
123 sigemptyset (&action.sa_mask);
124 action.sa_flags = 0;
125
126 sigaction(SIGPIPE, &action, &oldAction);
127 ssize_t unused = write(fd, content.constData(), size_t(content.size()));
128 Q_UNUSED(unused);
129 sigaction(SIGPIPE, &oldAction, nullptr);
130 }
131 close(fd);
132}
133
134} // namespace QtWaylandClient
135
137
138#include "moc_qwaylandprimaryselectionv1_p.cpp"
\inmodule QtCore
Definition qbytearray.h:57
qsizetype size() const noexcept
Returns the number of bytes in this byte array.
Definition qbytearray.h:494
const char * constData() const noexcept
Returns a pointer to the const data stored in the byte array.
Definition qbytearray.h:124
bool isEmpty() const noexcept
Returns true if the byte array has size 0; otherwise returns false.
Definition qbytearray.h:107
static QPlatformIntegration * platformIntegration()
\inmodule QtCore
Definition qmimedata.h:16
virtual QStringList formats() const
Returns a list of formats supported by the object.
static QMetaObject::Connection connect(const QObject *sender, const char *signal, const QObject *receiver, const char *member, Qt::ConnectionType=Qt::AutoConnection)
\threadsafe
Definition qobject.cpp:2960
\macro QT_RESTRICTED_CAST_FROM_ASCII
Definition qstring.h:129
static QByteArray getByteArray(QMimeData *mimeData, const QString &mimeType)
struct wl_display * wl_display() const
QWaylandPrimarySelectionDeviceManagerV1(QWaylandDisplay *display, uint id, uint version)
QWaylandPrimarySelectionDeviceV1 * createDevice(QWaylandInputDevice *seat)
void zwp_primary_selection_device_v1_selection(struct ::zwp_primary_selection_offer_v1 *id) override
void zwp_primary_selection_device_v1_data_offer(struct ::zwp_primary_selection_offer_v1 *offer) override
void setSelectionSource(QWaylandPrimarySelectionSourceV1 *source)
void startReceiving(const QString &mimeType, int fd) override
void zwp_primary_selection_offer_v1_offer(const QString &mime_type) override
QWaylandPrimarySelectionOfferV1(QWaylandDisplay *display, ::zwp_primary_selection_offer_v1 *offer)
QWaylandPrimarySelectionSourceV1(QWaylandPrimarySelectionDeviceManagerV1 *manager, QMimeData *mimeData)
void zwp_primary_selection_source_v1_send(const QString &mime_type, int32_t fd) override
#define this
Definition dialogs.cpp:9
struct wl_display * display
Definition linuxdmabuf.h:41
Combined button and popup list for selecting options.
const char * mimeType
constexpr const T & qMin(const T &a, const T &b)
Definition qminmax.h:40
GLenum GLuint id
[7]
GLuint64 GLenum GLint fd
GLint GLsizei GLsizei GLenum format
GLsizei GLsizei GLchar * source
#define Q_UNUSED(x)
unsigned int uint
Definition qtypes.h:34
gzip write("uncompressed data")
QMimeData * mimeData
QNetworkAccessManager manager