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
qwaylanddatasource.cpp
Go to the documentation of this file.
1// Copyright (C) 2016 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
9
10#include <QtCore/QFile>
11
12#include <QtCore/QDebug>
13
14#include <unistd.h>
15#include <signal.h>
16#include <fcntl.h>
17
19
20namespace QtWaylandClient {
21
23 : QtWayland::wl_data_source(dataDeviceManager->create_data_source())
24 , m_mime_data(mimeData)
25{
26 if (!mimeData)
27 return;
29 for (const QString &format : formats) {
30 offer(format);
31 }
32}
33
38
43
44void QWaylandDataSource::data_source_send(const QString &mime_type, int32_t fd)
45{
46 QByteArray content = QWaylandMimeHelper::getByteArray(m_mime_data, mime_type);
47 if (!content.isEmpty()) {
48 // Create a sigpipe handler that does nothing, or clients may be forced to terminate
49 // if the pipe is closed in the other end.
50 struct sigaction action, oldAction;
51 action.sa_handler = SIG_IGN;
52 sigemptyset (&action.sa_mask);
53 action.sa_flags = 0;
54
55 sigaction(SIGPIPE, &action, &oldAction);
56 // Some compositors (e.g., mutter) make fd with O_NONBLOCK.
57 // Since wl_data_source.send describes that fd is closed here,
58 // it should be done in a loop and don't have any advantage.
59 // Blocking operation will be used.
60 // According to fcntl(2), FSETFL ignores O_WRONLY. So this
61 // call will just remove O_NONBLOCK.
62 fcntl(fd, F_SETFL, O_WRONLY);
63 ssize_t unused = write(fd, content.constData(), content.size());
64 Q_UNUSED(unused);
65 sigaction(SIGPIPE, &oldAction, nullptr);
66 }
67 close(fd);
68}
69
71{
72 m_accepted = !mime_type.isEmpty();
73 Q_EMIT dndResponseUpdated(m_accepted, m_dropAction);
74}
75
77{
79
80 if (action == WL_DATA_DEVICE_MANAGER_DND_ACTION_MOVE)
81 qtAction = Qt::MoveAction;
82 else if (action == WL_DATA_DEVICE_MANAGER_DND_ACTION_COPY)
83 qtAction = Qt::CopyAction;
84
85 m_dropAction = qtAction;
86 Q_EMIT dndResponseUpdated(m_accepted, m_dropAction);
87}
88
93
95{
96
97 Q_EMIT dndDropped(m_accepted, m_dropAction);
98}
99
100}
101
103
104#include "moc_qwaylanddatasource_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 QStringList formatsHelper(const QMimeData *data)
\inmodule QtCore
Definition qmimedata.h:16
\macro QT_RESTRICTED_CAST_FROM_ASCII
Definition qstring.h:129
static QByteArray getByteArray(QMimeData *mimeData, const QString &mimeType)
void dndDropped(bool accepted, Qt::DropAction action)
void data_source_target(const QString &mime_type) override
void data_source_action(uint32_t action) override
void dndResponseUpdated(bool accepted, Qt::DropAction action)
QWaylandDataSource(QWaylandDataDeviceManager *dataDeviceManager, QMimeData *mimeData)
void data_source_send(const QString &mime_type, int32_t fd) override
EGLint EGLint * formats
Combined button and popup list for selecting options.
DropAction
@ CopyAction
@ IgnoreAction
@ MoveAction
GLuint64 GLenum GLint fd
GLint GLsizei GLsizei GLenum format
#define Q_EMIT
#define Q_UNUSED(x)
gzip write("uncompressed data")
QMimeData * mimeData