$$PWD/wlextendedsurface.h \
$$PWD/wlextendedoutput.h \
$$PWD/wlsubsurface.h \
- $$PWD/wltouch.h
+ $$PWD/wltouch.h \
+ $$PWD/../../shared/qwaylandmimehelper.h
SOURCES += \
$$PWD/wlcompositor.cpp \
$$PWD/wlextendedsurface.cpp \
$$PWD/wlextendedoutput.cpp \
$$PWD/wlsubsurface.cpp \
- $$PWD/wltouch.cpp
+ $$PWD/wltouch.cpp \
+ $$PWD/../../shared/qwaylandmimehelper.cpp
+
+INCLUDEPATH += $$PWD/../../shared
void Compositor::overrideSelection(QMimeData *data)
{
- Q_UNUSED(data);
- // ### TODO implement
+ m_data_device_manager->overrideSelection(*data);
}
bool Compositor::isDragging() const
void DataDevice::sendSelectionFocus()
{
- //do for all clipboards
+ if (m_data_device_manager->offerFromCompositorToClient(m_data_device_resource))
+ return;
+
DataSource *source = m_data_device_manager->currentSelectionSource();
if (!source) {
return;
#include "wlinputdevice.h"
#include "wlcompositor.h"
#include "wldataoffer.h"
+#include "wlsurface.h"
+#include "qwaylandmimehelper.h"
#include <QtCore/QDebug>
#include <QtCore/QSocketNotifier>
#include <fcntl.h>
#include <QtCore/private/qcore_unix_p.h>
+#include <QtCore/QFile>
namespace Wayland {
: m_compositor(compositor)
, m_current_selection_source(0)
, m_retainedReadNotifier(0)
+ , m_compositorOwnsSelection(false)
{
wl_display_add_global(compositor->wl_display(), &wl_data_device_manager_interface, this, DataDeviceManager::bind_func_drag);
}
return;
}
+ m_compositorOwnsSelection = false;
+
finishReadFromClient();
m_current_selection_source = source;
DataDeviceManager::get_data_device
};
+void DataDeviceManager::overrideSelection(const QMimeData &mimeData)
+{
+ QStringList formats = mimeData.formats();
+ if (formats.isEmpty())
+ return;
+
+ m_retainedData.clear();
+ foreach (const QString &format, formats)
+ m_retainedData.setData(format, mimeData.data(format));
+
+ m_compositor->feedRetainedSelectionData(&m_retainedData);
+
+ m_compositorOwnsSelection = true;
+
+ InputDevice *dev = m_compositor->defaultInputDevice();
+ Surface *focusSurface = dev->keyboardFocus();
+ if (focusSurface)
+ offerFromCompositorToClient(
+ dev->dataDevice(focusSurface->base()->resource.client)->dataDeviceResource());
+}
+
+bool DataDeviceManager::offerFromCompositorToClient(wl_resource *clientDataDeviceResource)
+{
+ if (!m_compositorOwnsSelection)
+ return false;
+
+ wl_client *client = clientDataDeviceResource->client;
+ qDebug("compositor offers %d types to %p", m_retainedData.formats().count(), client);
+
+ struct wl_resource *selectionOffer =
+ wl_client_new_object(client, &wl_data_offer_interface, &compositor_offer_interface, this);
+ wl_resource_post_event(clientDataDeviceResource, WL_DATA_DEVICE_DATA_OFFER, selectionOffer);
+ foreach (const QString &format, m_retainedData.formats()) {
+ QByteArray ba = format.toLatin1();
+ wl_resource_post_event(selectionOffer, WL_DATA_OFFER_OFFER, ba.constData());
+ }
+ wl_resource_post_event(clientDataDeviceResource, WL_DATA_DEVICE_SELECTION, selectionOffer);
+
+ return true;
+}
+
+void DataDeviceManager::comp_accept(wl_client *, wl_resource *, uint32_t, const char *)
+{
+}
+
+void DataDeviceManager::comp_receive(wl_client *client, wl_resource *resource, const char *mime_type, int32_t fd)
+{
+ DataDeviceManager *self = static_cast<DataDeviceManager *>(resource->data);
+ qDebug("client %p wants data for type %s from compositor", client, mime_type);
+ QByteArray content = QWaylandMimeHelper::getByteArray(&self->m_retainedData, QString::fromLatin1(mime_type));
+ if (!content.isEmpty()) {
+ QFile f;
+ if (f.open(fd, QIODevice::WriteOnly))
+ f.write(content);
+ }
+ close(fd);
+}
+
+void DataDeviceManager::comp_destroy(wl_client *, wl_resource *)
+{
+}
+
+const struct wl_data_offer_interface DataDeviceManager::compositor_offer_interface = {
+ DataDeviceManager::comp_accept,
+ DataDeviceManager::comp_receive,
+ DataDeviceManager::comp_destroy
+};
+
} //namespace
void sourceDestroyed(DataSource *source);
+ void overrideSelection(const QMimeData &mimeData);
+ bool offerFromCompositorToClient(wl_resource *clientDataDeviceResource);
+
private slots:
void readFromClient(int fd);
int m_retainedReadIndex;
QByteArray m_retainedReadBuf;
+ bool m_compositorOwnsSelection;
+
+
+ static void comp_accept(struct wl_client *client,
+ struct wl_resource *resource,
+ uint32_t time,
+ const char *type);
+ static void comp_receive(struct wl_client *client,
+ struct wl_resource *resource,
+ const char *mime_type,
+ int32_t fd);
+ static void comp_destroy(struct wl_client *client,
+ struct wl_resource *resource);
+
+ static const struct wl_data_offer_interface compositor_offer_interface;
};
}
****************************************************************************/
#include "qwaylanddataoffer.h"
-
#include "qwaylanddatadevicemanager.h"
-#include <QImage>
-#include <QColor>
-#include <QUrl>
-#include <QBuffer>
-#include <QImageWriter>
-
#include <QtGui/private/qguiapplication_p.h>
#include <QtGui/QPlatformClipboard>
#include <QtCore/QDebug>
-QByteArray QWaylandMimeHelper::getByteArray(QMimeData *mimeData, const QString &mimeType)
-{
- QByteArray content;
- if (mimeType == QLatin1String("text/plain")) {
- content = mimeData->text().toUtf8();
- } else if (mimeData->hasImage()
- && (mimeType == QLatin1String("application/x-qt-image")
- || mimeType.startsWith("image/"))) {
- QImage image = qvariant_cast<QImage>(mimeData->imageData());
- if (!image.isNull()) {
- QBuffer buf;
- buf.open(QIODevice::ReadWrite);
- QByteArray fmt = "BMP";
- if (mimeType.startsWith("image/")) {
- QByteArray imgFmt = mimeType.mid(6).toUpper().toAscii();
- if (QImageWriter::supportedImageFormats().contains(imgFmt))
- fmt = imgFmt;
- }
- QImageWriter wr(&buf, fmt);
- wr.write(image);
- content = buf.buffer();
- }
- } else if (mimeType == QLatin1String("application/x-color")) {
- content = qvariant_cast<QColor>(mimeData->colorData()).name().toAscii();
- } else if (mimeType == QLatin1String("text/uri-list")) {
- QList<QUrl> urls = mimeData->urls();
- for (int i = 0; i < urls.count(); ++i) {
- content.append(urls.at(i).toEncoded());
- content.append('\n');
- }
- } else {
- content = mimeData->data(mimeType);
- }
- return content;
-}
-
void QWaylandDataOffer::offer_sync_callback(void *data,
struct wl_callback *wl_callback,
class QWaylandDisplay;
-class QWaylandMimeHelper
-{
-public:
- static QByteArray getByteArray(QMimeData *mimeData, const QString &mimeType);
-};
-
class QWaylandDataOffer : public QInternalMimeData
{
public:
****************************************************************************/
#include "qwaylanddatasource.h"
-
#include "qwaylanddataoffer.h"
#include "qwaylandinputdevice.h"
+#include "qwaylandmimehelper.h"
#include <QtCore/QFile>
qwaylandextendedoutput.cpp \
qwaylandextendedsurface.cpp \
qwaylandsubsurface.cpp \
- qwaylandtouch.cpp
+ qwaylandtouch.cpp \
+ $$PWD/../../../shared/qwaylandmimehelper.cpp
HEADERS = qwaylandintegration.h \
qwaylandnativeinterface.h \
qwaylandextendedoutput.h \
qwaylandextendedsurface.h \
qwaylandsubsurface.h \
- qwaylandtouch.h
+ qwaylandtouch.h \
+ $$PWD/../../../shared/qwaylandmimehelper.h
+
+INCLUDEPATH += $$PWD/../../../shared
INCLUDEPATH += $$QMAKE_INCDIR_WAYLAND
+
LIBS += $$QMAKE_LIBS_WAYLAND
mac {
LIBS += -lwayland-client
--- /dev/null
+/****************************************************************************
+**
+** Copyright (C) 2012 Nokia Corporation and/or its subsidiary(-ies).
+** All rights reserved.
+** Contact: Nokia Corporation (qt-info@nokia.com)
+**
+** This file is part of the plugins of the Qt Toolkit.
+**
+** $QT_BEGIN_LICENSE:LGPL$
+** GNU Lesser General Public License Usage
+** This file may be used under the terms of the GNU Lesser General Public
+** License version 2.1 as published by the Free Software Foundation and
+** appearing in the file LICENSE.LGPL included in the packaging of this
+** file. Please review the following information to ensure the GNU Lesser
+** General Public License version 2.1 requirements will be met:
+** http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html.
+**
+** In addition, as a special exception, Nokia gives you certain additional
+** rights. These rights are described in the Nokia Qt LGPL Exception
+** version 1.1, included in the file LGPL_EXCEPTION.txt in this package.
+**
+** GNU General Public License Usage
+** Alternatively, this file may be used under the terms of the GNU General
+** Public License version 3.0 as published by the Free Software Foundation
+** and appearing in the file LICENSE.GPL included in the packaging of this
+** file. Please review the following information to ensure the GNU General
+** Public License version 3.0 requirements will be met:
+** http://www.gnu.org/copyleft/gpl.html.
+**
+** Other Usage
+** Alternatively, this file may be used in accordance with the terms and
+** conditions contained in a signed written agreement between you and Nokia.
+**
+**
+**
+**
+**
+** $QT_END_LICENSE$
+**
+****************************************************************************/
+
+#include "qwaylandmimehelper.h"
+#include <QImage>
+#include <QColor>
+#include <QUrl>
+#include <QBuffer>
+#include <QImageWriter>
+
+QByteArray QWaylandMimeHelper::getByteArray(QMimeData *mimeData, const QString &mimeType)
+{
+ QByteArray content;
+ if (mimeType == QLatin1String("text/plain")) {
+ content = mimeData->text().toUtf8();
+ } else if (mimeData->hasImage()
+ && (mimeType == QLatin1String("application/x-qt-image")
+ || mimeType.startsWith(QLatin1String("image/")))) {
+ QImage image = qvariant_cast<QImage>(mimeData->imageData());
+ if (!image.isNull()) {
+ QBuffer buf;
+ buf.open(QIODevice::ReadWrite);
+ QByteArray fmt = "BMP";
+ if (mimeType.startsWith(QLatin1String("image/"))) {
+ QByteArray imgFmt = mimeType.mid(6).toUpper().toAscii();
+ if (QImageWriter::supportedImageFormats().contains(imgFmt))
+ fmt = imgFmt;
+ }
+ QImageWriter wr(&buf, fmt);
+ wr.write(image);
+ content = buf.buffer();
+ }
+ } else if (mimeType == QLatin1String("application/x-color")) {
+ content = qvariant_cast<QColor>(mimeData->colorData()).name().toAscii();
+ } else if (mimeType == QLatin1String("text/uri-list")) {
+ QList<QUrl> urls = mimeData->urls();
+ for (int i = 0; i < urls.count(); ++i) {
+ content.append(urls.at(i).toEncoded());
+ content.append('\n');
+ }
+ } else {
+ content = mimeData->data(mimeType);
+ }
+ return content;
+}
--- /dev/null
+/****************************************************************************
+**
+** Copyright (C) 2012 Nokia Corporation and/or its subsidiary(-ies).
+** All rights reserved.
+** Contact: Nokia Corporation (qt-info@nokia.com)
+**
+** This file is part of the plugins of the Qt Toolkit.
+**
+** $QT_BEGIN_LICENSE:LGPL$
+** GNU Lesser General Public License Usage
+** This file may be used under the terms of the GNU Lesser General Public
+** License version 2.1 as published by the Free Software Foundation and
+** appearing in the file LICENSE.LGPL included in the packaging of this
+** file. Please review the following information to ensure the GNU Lesser
+** General Public License version 2.1 requirements will be met:
+** http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html.
+**
+** In addition, as a special exception, Nokia gives you certain additional
+** rights. These rights are described in the Nokia Qt LGPL Exception
+** version 1.1, included in the file LGPL_EXCEPTION.txt in this package.
+**
+** GNU General Public License Usage
+** Alternatively, this file may be used under the terms of the GNU General
+** Public License version 3.0 as published by the Free Software Foundation
+** and appearing in the file LICENSE.GPL included in the packaging of this
+** file. Please review the following information to ensure the GNU General
+** Public License version 3.0 requirements will be met:
+** http://www.gnu.org/copyleft/gpl.html.
+**
+** Other Usage
+** Alternatively, this file may be used in accordance with the terms and
+** conditions contained in a signed written agreement between you and Nokia.
+**
+**
+**
+**
+**
+** $QT_END_LICENSE$
+**
+****************************************************************************/
+
+#ifndef QWAYLANDMIMEHELPER_H
+#define QWAYLANDMIMEHELPER_H
+
+#include <QString>
+#include <QByteArray>
+#include <QMimeData>
+
+class QWaylandMimeHelper
+{
+public:
+ static QByteArray getByteArray(QMimeData *mimeData, const QString &mimeType);
+};
+
+#endif