summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorGiulio Camuffo <giulio.camuffo@jollamobile.com>2014-09-12 13:44:42 +0300
committerGiulio Camuffo <giulio.camuffo@jollamobile.com>2014-09-15 11:54:03 +0200
commited912471bd449044ddc36b902ebb32b53ee548de (patch)
tree56e235405d9a554daf3784d50827c4012714ecae
parent99c1b8e53f9a2ba6e8c549f15b0d3008bf12c3f1 (diff)
Fix retrieving the selection/dnd data
Installing a roudtrip on the custom event queue in the wl_data_offer.offer handler is broken because that triggers a wl_data_device.selection event, which emits the QClipboard changed signal, so code listening to it may end up trying to retrieve the clipboard data before the roundtrip ends. Additionally, we're calling wl_data_offer.receive for each mime type, even if then we never read from the fd, making the source client do work for no reason. Instead, call wl_data_offer.receive retrieveData_sys, that is when actually retreiving the data. We don't need to install a roundtrip after that, just flushing out the requests is enough, because we wait up to one second for the source client to write into the fd. Change-Id: I180779e375ebd5a22af7084458505a41107fab19 Reviewed-by: Robin Burchell <robin.burchell@viroteck.net>
-rw-r--r--src/client/qwaylanddataoffer.cpp34
-rw-r--r--src/client/qwaylanddataoffer_p.h2
2 files changed, 17 insertions, 19 deletions
diff --git a/src/client/qwaylanddataoffer.cpp b/src/client/qwaylanddataoffer.cpp
index d1c85c7a4..4ad73dc7e 100644
--- a/src/client/qwaylanddataoffer.cpp
+++ b/src/client/qwaylanddataoffer.cpp
@@ -94,30 +94,18 @@ QWaylandMimeData::~QWaylandMimeData()
void QWaylandMimeData::appendFormat(const QString &mimeType)
{
- if (m_types.contains(mimeType))
- close(m_types.take(mimeType)); // Unconsumed data
+ m_types << mimeType;
m_data.remove(mimeType); // Clear previous contents
-
- int pipefd[2];
- if (::pipe2(pipefd, O_CLOEXEC|O_NONBLOCK) == -1) {
- qWarning("QWaylandMimeData: pipe2() failed");
- return;
- }
-
- m_dataOffer->receive(mimeType, pipefd[1]);
- m_display->forceRoundTrip();
- close(pipefd[1]);
- m_types.insert(mimeType, pipefd[0]);
}
bool QWaylandMimeData::hasFormat_sys(const QString &mimeType) const
{
- return m_types.contains(mimeType) || m_data.contains(mimeType);
+ return m_types.contains(mimeType);
}
QStringList QWaylandMimeData::formats_sys() const
{
- return m_types.keys() << m_data.keys();
+ return m_types;
}
QVariant QWaylandMimeData::retrieveData_sys(const QString &mimeType, QVariant::Type type) const
@@ -130,14 +118,24 @@ QVariant QWaylandMimeData::retrieveData_sys(const QString &mimeType, QVariant::T
if (!m_types.contains(mimeType))
return QVariant();
+ int pipefd[2];
+ if (::pipe2(pipefd, O_CLOEXEC|O_NONBLOCK) == -1) {
+ qWarning("QWaylandMimeData: pipe2() failed");
+ return QVariant();
+ }
+
+ m_dataOffer->receive(mimeType, pipefd[1]);
+ m_display->flushRequests();
+
+ close(pipefd[1]);
+
QByteArray content;
- int fd = m_types.take(mimeType);
- if (readData(fd, content) != 0) {
+ if (readData(pipefd[0], content) != 0) {
qWarning("QWaylandDataOffer: error reading data for mimeType %s", qPrintable(mimeType));
content = QByteArray();
}
- close(fd);
+ close(pipefd[0]);
m_data.insert(mimeType, content);
return content;
}
diff --git a/src/client/qwaylanddataoffer_p.h b/src/client/qwaylanddataoffer_p.h
index a21e18bdc..12fc0a22f 100644
--- a/src/client/qwaylanddataoffer_p.h
+++ b/src/client/qwaylanddataoffer_p.h
@@ -87,7 +87,7 @@ private:
mutable QWaylandDataOffer *m_dataOffer;
QWaylandDisplay *m_display;
- mutable QHash<QString, int> m_types;
+ mutable QStringList m_types;
mutable QHash<QString, QByteArray> m_data;
};