kwin/src/wayland/datasource_interface.cpp

137 lines
4 KiB
C++
Raw Normal View History

/********************************************************************
Copyright 2014 Martin Gräßlin <mgraesslin@kde.org>
This library is free software; you can redistribute it and/or
modify it under the terms of the GNU Lesser General Public
License as published by the Free Software Foundation; either
version 2.1 of the License, or (at your option) version 3, or any
later version accepted by the membership of KDE e.V. (or its
successor approved by the membership of KDE e.V.), which shall
act as a proxy defined in Section 6 of version 3 of the license.
This library is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
Lesser General Public License for more details.
You should have received a copy of the GNU Lesser General Public
License along with this library. If not, see <http://www.gnu.org/licenses/>.
*********************************************************************/
#include "datasource_interface.h"
#include "datadevicemanager_interface.h"
#include "resource_p.h"
// Qt
#include <QStringList>
// Wayland
#include <wayland-server.h>
// system
#include <unistd.h>
namespace KWayland
{
namespace Server
{
class DataSourceInterface::Private : public Resource::Private
{
public:
2014-11-20 15:40:14 +00:00
Private(DataSourceInterface *q, DataDeviceManagerInterface *parent, wl_resource *parentResource);
~Private();
QStringList mimeTypes;
private:
DataSourceInterface *q_func() {
return reinterpret_cast<DataSourceInterface *>(q);
}
void offer(const QString &mimeType);
static void offerCallback(wl_client *client, wl_resource *resource, const char *mimeType);
static void destroyCallack(wl_client *client, wl_resource *resource);
const static struct wl_data_source_interface s_interface;
};
#ifndef DOXYGEN_SHOULD_SKIP_THIS
const struct wl_data_source_interface DataSourceInterface::Private::s_interface = {
offerCallback,
destroyCallack
};
#endif
2014-11-20 15:40:14 +00:00
DataSourceInterface::Private::Private(DataSourceInterface *q, DataDeviceManagerInterface *parent, wl_resource *parentResource)
: Resource::Private(q, parent, parentResource, &wl_data_source_interface, &s_interface)
{
}
DataSourceInterface::Private::~Private() = default;
void DataSourceInterface::Private::destroyCallack(wl_client *client, wl_resource *resource)
{
Q_UNUSED(client)
[server] Implement support for drag'n'drop through pointer device Summary: How drag'n'drop works on Wayland: When a surface has a pointer grab and a button pressed on the surface (implicit grab) the client can initiate a drag'n'drop operation on the data device. For this the client needs to provide a data source describing the data to be transmitted with the drag'n'drop operation. When a drag'n'drop operation is active all pointer events are interpreted as part of the drag'n'drop operation, the pointer device is grabbed. Pointer events are no longer sent to the focused pointer but to the focused data device. When the pointer moves to another surface an enter event is sent to a data device for that surface and a leave event is sent to the data device previously focused. An enter event carries a data offer which is created from the data source for the operation. During pointer motion there is a feedback mechanism. The data offer can signal to the data source that it can or cannot accept the data at the current pointer position. This can be used by the client being dragged from to update the cursor. The drag'n'drop operation ends with the implicit grab being removed, that is the pressed pointer button which triggered the operation gets released. The server sends a drop event to the focused data device. The data transfer can now be started. For that the receiving client creates a pipe and passes the file descriptor through the data offer to the sending data source. The sending client will write into the file descriptor and close it to finish the transfer. Drag'n'drop could also be initiated through a touch device grab, but this is not yet implemented. The implementation in this change focuses on the adjustments for pointer. For the user of the library drag'n'drop is implemented in the SeatInterface. Signals are emitted whenever drag is started or ended. The interaction for pointer events hardly changes. Motion, button press and button release can still be indicated in the same way. If a button release removes the implicit grab the drop is automatically performed, without the user of the library having to do anything. The only change during drag and drop for the library user is that setFocusedPointerSurface is blocked. To update the current drag target the library user should use setDragTarget. Sending the enter/leave to the data device gets performed automatically. The data device which triggered the drag and drop operation is exposed in the SeatInterface. The user of the library should make sure to render the additional drag icon provided on the data device. At least QtWayland based applications will freeze during drag and drop if the icon doesn't get rendered. The implementation is currently still lacking the client side and due to that also auto test. It's currently only tested with QtWayland clients. Reviewers: #plasma, sebas Subscribers: plasma-devel Projects: #plasma Differential Revision: https://phabricator.kde.org/D1046
2016-03-01 06:49:04 +00:00
auto p = cast<Private>(resource);
wl_resource_destroy(resource);
[server] Implement support for drag'n'drop through pointer device Summary: How drag'n'drop works on Wayland: When a surface has a pointer grab and a button pressed on the surface (implicit grab) the client can initiate a drag'n'drop operation on the data device. For this the client needs to provide a data source describing the data to be transmitted with the drag'n'drop operation. When a drag'n'drop operation is active all pointer events are interpreted as part of the drag'n'drop operation, the pointer device is grabbed. Pointer events are no longer sent to the focused pointer but to the focused data device. When the pointer moves to another surface an enter event is sent to a data device for that surface and a leave event is sent to the data device previously focused. An enter event carries a data offer which is created from the data source for the operation. During pointer motion there is a feedback mechanism. The data offer can signal to the data source that it can or cannot accept the data at the current pointer position. This can be used by the client being dragged from to update the cursor. The drag'n'drop operation ends with the implicit grab being removed, that is the pressed pointer button which triggered the operation gets released. The server sends a drop event to the focused data device. The data transfer can now be started. For that the receiving client creates a pipe and passes the file descriptor through the data offer to the sending data source. The sending client will write into the file descriptor and close it to finish the transfer. Drag'n'drop could also be initiated through a touch device grab, but this is not yet implemented. The implementation in this change focuses on the adjustments for pointer. For the user of the library drag'n'drop is implemented in the SeatInterface. Signals are emitted whenever drag is started or ended. The interaction for pointer events hardly changes. Motion, button press and button release can still be indicated in the same way. If a button release removes the implicit grab the drop is automatically performed, without the user of the library having to do anything. The only change during drag and drop for the library user is that setFocusedPointerSurface is blocked. To update the current drag target the library user should use setDragTarget. Sending the enter/leave to the data device gets performed automatically. The data device which triggered the drag and drop operation is exposed in the SeatInterface. The user of the library should make sure to render the additional drag icon provided on the data device. At least QtWayland based applications will freeze during drag and drop if the icon doesn't get rendered. The implementation is currently still lacking the client side and due to that also auto test. It's currently only tested with QtWayland clients. Reviewers: #plasma, sebas Subscribers: plasma-devel Projects: #plasma Differential Revision: https://phabricator.kde.org/D1046
2016-03-01 06:49:04 +00:00
p->resource = nullptr;
p->q->deleteLater();
}
void DataSourceInterface::Private::offerCallback(wl_client *client, wl_resource *resource, const char *mimeType)
{
Q_UNUSED(client)
cast<Private>(resource)->offer(QString::fromUtf8(mimeType));
}
void DataSourceInterface::Private::offer(const QString &mimeType)
{
mimeTypes << mimeType;
Q_Q(DataSourceInterface);
emit q->mimeTypeOffered(mimeType);
}
2014-11-20 15:40:14 +00:00
DataSourceInterface::DataSourceInterface(DataDeviceManagerInterface *parent, wl_resource *parentResource)
: Resource(new Private(this, parent, parentResource))
{
}
DataSourceInterface::~DataSourceInterface() = default;
void DataSourceInterface::accept(const QString &mimeType)
{
Q_D();
// TODO: does this require a sanity check on the possible mimeType?
wl_data_source_send_target(d->resource, mimeType.isEmpty() ? nullptr : mimeType.toUtf8().constData());
}
void DataSourceInterface::requestData(const QString &mimeType, qint32 fd)
{
Q_D();
// TODO: does this require a sanity check on the possible mimeType?
wl_data_source_send_send(d->resource, mimeType.toUtf8().constData(), int32_t(fd));
close(fd);
}
void DataSourceInterface::cancel()
{
Q_D();
wl_data_source_send_cancelled(d->resource);
}
QStringList DataSourceInterface::mimeTypes() const
{
Q_D();
return d->mimeTypes;
}
DataSourceInterface *DataSourceInterface::get(wl_resource *native)
{
return Private::get<DataSourceInterface>(native);
}
DataSourceInterface::Private *DataSourceInterface::d_func() const
{
return reinterpret_cast<DataSourceInterface::Private*>(d.data());
}
}
}