6#include <QtWaylandCompositor/QWaylandCompositor>
8#include <QtWaylandCompositor/private/qwaylandcompositor_p.h>
9#include <QtWaylandCompositor/private/qwaylandseat_p.h>
15#include <QtCore/QDebug>
16#include <QtCore/QSocketNotifier>
18#include <QtCore/private/qcore_unix_p.h>
19#include <QtCore/QFile>
33 if (m_current_selection_source &&
source
34 && m_current_selection_source->
time() >
source->time()) {
35 qDebug() <<
"Trying to set older selection";
39 m_compositorOwnsSelection =
false;
41 finishReadFromClient();
43 m_current_selection_source =
source;
53 if (
source && m_compositor->retainedSelectionEnabled()) {
54 m_retainedData.
clear();
55 m_retainedReadIndex = 0;
62 if (m_current_selection_source ==
source)
63 finishReadFromClient();
66void DataDeviceManager::retain()
69 finishReadFromClient();
70 if (m_retainedReadIndex >= offers.
size()) {
75 m_retainedReadBuf.
clear();
78 qWarning(
"Clipboard: Failed to create pipe");
81 fcntl(
fd[0], F_SETFL, fcntl(
fd[0], F_GETFL, 0) | O_NONBLOCK);
87void DataDeviceManager::finishReadFromClient(
bool exhausted)
90 if (m_retainedReadNotifier) {
92 int fd = m_retainedReadNotifier->
socket();
93 delete m_retainedReadNotifier;
98 m_obsoleteRetainedReadNotifiers.
append(m_retainedReadNotifier);
100 m_retainedReadNotifier =
nullptr;
104void DataDeviceManager::readFromClient(
int fd)
106 static char buf[4096];
107 int obsCount = m_obsoleteRetainedReadNotifiers.
size();
108 for (
int i = 0;
i < obsCount; ++
i) {
118 if (
n != -1 || (errno != EAGAIN && errno != EWOULDBLOCK)) {
119 m_obsoleteRetainedReadNotifiers.
removeAt(
i);
128 if (
n != -1 || (errno != EAGAIN && errno != EWOULDBLOCK)) {
129 finishReadFromClient(
true);
133 ++m_retainedReadIndex;
143 return m_current_selection_source;
148 return m_compositor->display();
157 m_retainedData.
clear();
163 m_compositorOwnsSelection =
true;
174 if (!m_compositorOwnsSelection)
177 wl_client *client = wl_resource_get_client(clientDataDeviceResource);
180 struct wl_resource *selectionOffer =
181 wl_resource_create(client, &wl_data_offer_interface, -1, 0);
182 wl_resource_set_implementation(selectionOffer, &compositor_offer_interface,
this,
nullptr);
183 wl_data_device_send_data_offer(clientDataDeviceResource, selectionOffer);
187 wl_data_offer_send_offer(selectionOffer,
ba.
constData());
189 wl_data_device_send_selection(clientDataDeviceResource, selectionOffer);
196 if (m_retainedData.
formats().isEmpty())
199 m_compositorOwnsSelection =
true;
205 new DataSource(resource->client(),
id, m_compositor->currentTimeMsecs());
214void DataDeviceManager::comp_accept(wl_client *, wl_resource *, uint32_t,
const char *)
218void DataDeviceManager::comp_receive(wl_client *client, wl_resource *resource,
const char *mime_type, int32_t
fd)
221 DataDeviceManager *self =
static_cast<DataDeviceManager *
>(wl_resource_get_user_data(resource));
232void DataDeviceManager::comp_destroy(wl_client *, wl_resource *)
240 DataDeviceManager::comp_accept,
241 DataDeviceManager::comp_receive,
242 DataDeviceManager::comp_destroy
249#include "moc_qwldatadevicemanager_p.cpp"
const char * constData() const noexcept
Returns a pointer to the const data stored in the byte array.
bool isEmpty() const noexcept
Returns true if the byte array has size 0; otherwise returns false.
void clear()
Clears the contents of the byte array and makes it null.
QByteArray & append(char c)
This is an overloaded member function, provided for convenience. It differs from the above function o...
qsizetype size() const noexcept
void removeAt(qsizetype i)
const_reference at(qsizetype i) const noexcept
void append(parameter_type t)
void setData(const QString &mimetype, const QByteArray &data)
Sets the data associated with the MIME type given by mimeType to the specified data.
QByteArray data(const QString &mimetype) const
Returns the data stored in the object in the format described by the MIME type specified by mimeType.
void clear()
Removes all the MIME type and data entries in the object.
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
void activated(QSocketDescriptor socket, QSocketNotifier::Type activationEvent, QPrivateSignal)
qintptr socket() const
Returns the socket identifier assigned to this object.
\macro QT_RESTRICTED_CAST_FROM_ASCII
static QString fromLatin1(QByteArrayView ba)
This is an overloaded member function, provided for convenience. It differs from the above function o...
static QWaylandCompositorPrivate * get(QWaylandCompositor *compositor)
void feedRetainedSelectionData(QMimeData *data)
\qmltype WaylandCompositor \instantiates QWaylandCompositor \inqmlmodule QtWayland....
static QByteArray getByteArray(QMimeData *mimeData, const QString &mimeType)
static QWaylandSeatPrivate * get(QWaylandSeat *device)
\qmltype WaylandSeat \instantiates QWaylandSeat \inqmlmodule QtWayland.Compositor
static QWaylandSeat * fromSeatResource(struct ::wl_resource *resource)
Returns the QWaylandSeat corresponding to the resource.
QWaylandSurface * keyboardFocus() const
Returns the current focused surface for keyboard input.
\qmltype WaylandSurface \instantiates QWaylandSurface \inqmlmodule QtWayland.Compositor
::wl_client * waylandClient() const
Holds the wl_client using this QWaylandSurface.
void send(const QString &mimeType, int fd)
QList< QString > mimeTypes() const
struct wl_display * display
Combined button and popup list for selecting options.
#define QT_WARNING_DISABLE_GCC(text)
#define QT_WARNING_DISABLE_CLANG(text)
EGLOutputLayerEXT EGLint EGLAttrib value
[5]
static QOpenGLCompositor * compositor
GLenum GLuint GLenum GLsizei const GLchar * buf
GLint GLsizei GLsizei GLenum format
GLsizei GLsizei GLchar * source
bool offerFromCompositorToClient(wl_resource *clientDataDeviceResource)
void data_device_manager_get_data_device(Resource *resource, uint32_t id, struct ::wl_resource *seat) override
DataDeviceManager(QWaylandCompositor *compositor)
struct wl_display * display() const
void overrideSelection(const QMimeData &mimeData)
void sourceDestroyed(DataSource *source)
void offerRetainedSelection(wl_resource *clientDataDeviceResource)
DataSource * currentSelectionSource()
void setCurrentSelectionSource(DataSource *source)
void data_device_manager_create_data_source(Resource *resource, uint32_t id) override