kwin/src/wayland/datadevice_interface.cpp

365 lines
12 KiB
C++
Raw Normal View History

/*
SPDX-FileCopyrightText: 2014 Martin Gräßlin <mgraesslin@kde.org>
SPDX-FileCopyrightText: 2020 David Edmundson <davidedmundson@kde.org>
SPDX-FileCopyrightText: 2020 Vlad Zahorodnii <vlad.zahorodnii@kde.org>
SPDX-License-Identifier: LGPL-2.1-only OR LGPL-3.0-only OR LicenseRef-KDE-Accepted-LGPL
*/
#include "datadevice_interface.h"
#include "datadevice_interface_p.h"
#include "datadevicemanager_interface.h"
#include "datasource_interface.h"
#include "dataoffer_interface.h"
#include "display.h"
#include "pointer_interface.h"
#include "seat_interface.h"
#include "seat_interface_p.h"
#include "surface_interface.h"
#include "surfacerole_p.h"
2020-04-29 14:56:38 +00:00
namespace KWaylandServer
{
class DragAndDropIconPrivate : public SurfaceRole
{
public:
explicit DragAndDropIconPrivate(SurfaceInterface *surface);
void commit() override;
QPoint position;
};
DragAndDropIconPrivate::DragAndDropIconPrivate(SurfaceInterface *surface)
: SurfaceRole(surface, QByteArrayLiteral("dnd_icon"))
{
}
void DragAndDropIconPrivate::commit()
{
position += surface()->offset();
}
DragAndDropIcon::DragAndDropIcon(SurfaceInterface *surface, QObject *parent)
: QObject(parent)
, d(new DragAndDropIconPrivate(surface))
{
}
DragAndDropIcon::~DragAndDropIcon()
{
}
QPoint DragAndDropIcon::position() const
{
return d->position;
}
SurfaceInterface *DragAndDropIcon::surface() const
{
return d->surface();
}
DataDeviceInterfacePrivate *DataDeviceInterfacePrivate::get(DataDeviceInterface *device)
{
return device->d.data();
}
DataDeviceInterfacePrivate::DataDeviceInterfacePrivate(SeatInterface *seat, DataDeviceInterface *_q, wl_resource *resource)
: QtWaylandServer::wl_data_device(resource)
, seat(seat)
, q(_q)
{
}
void DataDeviceInterfacePrivate::endDrag()
{
icon.reset();
}
void DataDeviceInterfacePrivate::data_device_start_drag(Resource *resource, wl_resource *sourceResource, wl_resource *originResource, wl_resource *iconResource, uint32_t serial)
{
SurfaceInterface *iconSurface = SurfaceInterface::get(iconResource);
const SurfaceRole *surfaceRole = SurfaceRole::get(iconSurface);
if (surfaceRole) {
wl_resource_post_error(resource->handle, error_role,
"the icon surface already has a role assigned %s",
surfaceRole->name().constData());
return;
}
SurfaceInterface *focusSurface = SurfaceInterface::get(originResource);
DataSourceInterface *dataSource = nullptr;
if (sourceResource) {
dataSource = DataSourceInterface::get(sourceResource);
}
if (proxyRemoteSurface) {
// origin is a proxy surface
focusSurface = proxyRemoteSurface.data();
}
const bool pointerGrab = seat->hasImplicitPointerGrab(serial) && seat->focusedPointerSurface() == focusSurface;
if (!pointerGrab) {
// Client doesn't have pointer grab.
const bool touchGrab = seat->hasImplicitTouchGrab(serial) && seat->focusedTouchSurface() == focusSurface;
if (!touchGrab) {
// Client neither has pointer nor touch grab. No drag start allowed.
return;
}
}
[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
// TODO: source is allowed to be null, handled client internally!
source = dataSource;
if (dataSource) {
QObject::connect(dataSource, &AbstractDataSource::aboutToBeDestroyed, q, [this] { source = nullptr; });
}
if (iconSurface) {
icon.reset(new DragAndDropIcon(iconSurface));
QObject::connect(iconSurface, &SurfaceInterface::aboutToBeDestroyed, icon.data(), [this] { icon.reset(); });
}
surface = focusSurface;
[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
drag.serial = serial;
emit q->dragStarted();
}
void DataDeviceInterfacePrivate::data_device_set_selection(Resource *resource, wl_resource *source, uint32_t serial)
{
Q_UNUSED(resource)
Q_UNUSED(serial)
DataSourceInterface *dataSource = DataSourceInterface::get(source);
if (dataSource && dataSource->supportedDragAndDropActions() && wl_resource_get_version(dataSource->resource()) >= WL_DATA_SOURCE_ACTION_SINCE_VERSION) {
wl_resource_post_error(dataSource->resource(), QtWaylandServer::wl_data_source::error_invalid_source, "Data source is for drag and drop");
return;
}
if (selection == dataSource) {
return;
}
if (selection) {
selection->cancel();
}
selection = dataSource;
if (selection) {
emit q->selectionChanged(selection);
} else {
emit q->selectionCleared();
}
}
void DataDeviceInterfacePrivate::data_device_release(QtWaylandServer::wl_data_device::Resource *resource)
{
wl_resource_destroy(resource->handle);
}
DataOfferInterface *DataDeviceInterfacePrivate::createDataOffer(AbstractDataSource *source)
{
if (!source) {
// a data offer can only exist together with a source
return nullptr;
}
wl_resource *data_offer_resource = wl_resource_create(resource()->client(), &wl_data_offer_interface, resource()->version(), 0);
if (!data_offer_resource) {
wl_resource_post_no_memory(resource()->handle);
return nullptr;
}
DataOfferInterface *offer = new DataOfferInterface(source, data_offer_resource);
send_data_offer(offer->resource());
offer->sendAllOffers();
return offer;
}
void DataDeviceInterfacePrivate::data_device_destroy_resource(QtWaylandServer::wl_data_device::Resource *resource)
{
Q_UNUSED(resource)
emit q->aboutToBeDestroyed();
delete q;
}
DataDeviceInterface::DataDeviceInterface(SeatInterface *seat, wl_resource *resource)
: QObject(nullptr)
, d(new DataDeviceInterfacePrivate(seat, this, resource))
{
seat->d_func()->registerDataDevice(this);
}
DataDeviceInterface::~DataDeviceInterface() = default;
SeatInterface *DataDeviceInterface::seat() const
{
return d->seat;
}
DataSourceInterface *DataDeviceInterface::dragSource() const
{
return d->source;
}
DragAndDropIcon *DataDeviceInterface::icon() const
{
return d->icon.data();
}
SurfaceInterface *DataDeviceInterface::origin() const
{
return d->proxyRemoteSurface ? d->proxyRemoteSurface.data() : d->surface;
}
DataSourceInterface *DataDeviceInterface::selection() const
{
return d->selection;
}
void DataDeviceInterface::sendSelection(AbstractDataSource *other)
{
auto r = d->createDataOffer(other);
if (!r) {
return;
}
d->send_selection(r->resource());
}
void DataDeviceInterface::sendClearSelection()
{
d->send_selection(nullptr);
}
[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
void DataDeviceInterface::drop()
{
d->send_drop();
if (d->drag.posConnection) {
disconnect(d->drag.posConnection);
d->drag.posConnection = QMetaObject::Connection();
}
disconnect(d->drag.destroyConnection);
d->drag.destroyConnection = QMetaObject::Connection();
d->drag.surface = nullptr;
wl_client_flush(d->resource()->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
}
void DataDeviceInterface::updateDragTarget(SurfaceInterface *surface, quint32 serial)
{
if (d->drag.surface) {
if (d->drag.surface->resource()) {
d->send_leave();
[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
}
if (d->drag.posConnection) {
disconnect(d->drag.posConnection);
d->drag.posConnection = QMetaObject::Connection();
[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
}
disconnect(d->drag.destroyConnection);
d->drag.destroyConnection = QMetaObject::Connection();
d->drag.surface = nullptr;
if (d->drag.sourceActionConnection) {
disconnect(d->drag.sourceActionConnection);
d->drag.sourceActionConnection = QMetaObject::Connection();
}
if (d->drag.targetActionConnection) {
disconnect(d->drag.targetActionConnection);
d->drag.targetActionConnection = QMetaObject::Connection();
}
[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
// don't update serial, we need it
}
if (!surface) {
if (auto s = d->seat->dragSource()->dragSource()) {
s->dndAction(DataDeviceManagerInterface::DnDAction::None);
}
[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
return;
}
if (d->proxyRemoteSurface && d->proxyRemoteSurface == surface) {
// A proxy can not have the remote surface as target.
// TODO: do this for all client's surfaces?
return;
}
auto *source = d->seat->dragSource()->dragSource();
if (source) {
source->setAccepted(false);
}
DataOfferInterface *offer = d->createDataOffer(source);
[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
d->drag.surface = surface;
if (d->seat->isDragPointer()) {
d->drag.posConnection = connect(d->seat, &SeatInterface::pointerPosChanged, this,
[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
[this] {
const QPointF pos = d->seat->dragSurfaceTransformation().map(d->seat->pointerPos());
d->send_motion(d->seat->timestamp(),
[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
wl_fixed_from_double(pos.x()), wl_fixed_from_double(pos.y()));
wl_client_flush(d->resource()->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
}
);
} else if (d->seat->isDragTouch()) {
d->drag.posConnection = connect(d->seat, &SeatInterface::touchMoved, this,
[this](qint32 id, quint32 serial, const QPointF &globalPosition) {
Q_UNUSED(id);
if (serial != d->drag.serial) {
// different touch down has been moved
return;
}
const QPointF pos = d->seat->dragSurfaceTransformation().map(globalPosition);
d->send_motion(d->seat->timestamp(),
wl_fixed_from_double(pos.x()), wl_fixed_from_double(pos.y()));
wl_client_flush(d->resource()->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
}
d->drag.destroyConnection = connect(d->drag.surface, &QObject::destroyed, this,
[this] {
d->send_leave();
if (d->drag.posConnection) {
disconnect(d->drag.posConnection);
[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
}
d->drag = DataDeviceInterfacePrivate::Drag();
[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
}
);
// TODO: handle touch position
const QPointF pos = d->seat->dragSurfaceTransformation().map(d->seat->pointerPos());
d->send_enter(serial, surface->resource(),
wl_fixed_from_double(pos.x()), wl_fixed_from_double(pos.y()), offer ? offer->resource() : nullptr);
if (offer) {
offer->sendSourceActions();
auto matchOffers = [source, offer] {
DataDeviceManagerInterface::DnDAction action{DataDeviceManagerInterface::DnDAction::None};
if (source->supportedDragAndDropActions().testFlag(offer->preferredDragAndDropAction())) {
action = offer->preferredDragAndDropAction();
} else {
if (source->supportedDragAndDropActions().testFlag(DataDeviceManagerInterface::DnDAction::Copy) &&
offer->supportedDragAndDropActions().testFlag(DataDeviceManagerInterface::DnDAction::Copy)) {
action = DataDeviceManagerInterface::DnDAction::Copy;
} else if (source->supportedDragAndDropActions().testFlag(DataDeviceManagerInterface::DnDAction::Move) &&
offer->supportedDragAndDropActions().testFlag(DataDeviceManagerInterface::DnDAction::Move)) {
action = DataDeviceManagerInterface::DnDAction::Move;
} else if (source->supportedDragAndDropActions().testFlag(DataDeviceManagerInterface::DnDAction::Ask) &&
offer->supportedDragAndDropActions().testFlag(DataDeviceManagerInterface::DnDAction::Ask)) {
action = DataDeviceManagerInterface::DnDAction::Ask;
}
}
offer->dndAction(action);
source->dndAction(action);
};
d->drag.targetActionConnection = connect(offer, &DataOfferInterface::dragAndDropActionsChanged, source, matchOffers);
d->drag.sourceActionConnection = connect(source, &DataSourceInterface::supportedDragAndDropActionsChanged, source, matchOffers);
}
wl_client_flush(d->resource()->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
}
quint32 DataDeviceInterface::dragImplicitGrabSerial() const
{
return d->drag.serial;
}
void DataDeviceInterface::updateProxy(SurfaceInterface *remote)
{
// TODO: connect destroy signal?
d->proxyRemoteSurface = remote;
}
wl_client *DataDeviceInterface::client()
{
return d->resource()->client();
}
}