2014-11-06 09:02:49 +00:00
|
|
|
/********************************************************************
|
|
|
|
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 "datadevice_interface.h"
|
2014-11-14 08:45:02 +00:00
|
|
|
#include "datadevicemanager_interface.h"
|
2014-11-06 15:56:50 +00:00
|
|
|
#include "dataoffer_interface.h"
|
2014-11-06 09:02:49 +00:00
|
|
|
#include "datasource_interface.h"
|
2014-11-14 08:45:02 +00:00
|
|
|
#include "resource_p.h"
|
2014-11-06 09:02:49 +00:00
|
|
|
#include "seat_interface.h"
|
|
|
|
#include "surface_interface.h"
|
|
|
|
// Wayland
|
|
|
|
#include <wayland-server.h>
|
|
|
|
|
|
|
|
namespace KWayland
|
|
|
|
{
|
|
|
|
namespace Server
|
|
|
|
{
|
|
|
|
|
2014-11-14 08:45:02 +00:00
|
|
|
class DataDeviceInterface::Private : public Resource::Private
|
2014-11-06 09:02:49 +00:00
|
|
|
{
|
|
|
|
public:
|
2014-11-14 08:45:02 +00:00
|
|
|
Private(SeatInterface *seat, DataDeviceInterface *q, DataDeviceManagerInterface *manager);
|
2014-11-06 09:02:49 +00:00
|
|
|
~Private();
|
|
|
|
|
2014-11-14 08:45:02 +00:00
|
|
|
void create(wl_client *client, quint32 version, quint32 id) override;
|
2014-11-06 09:02:49 +00:00
|
|
|
|
2014-11-06 15:56:50 +00:00
|
|
|
DataOfferInterface *createDataOffer(DataSourceInterface *source);
|
|
|
|
|
2014-11-06 09:02:49 +00:00
|
|
|
SeatInterface *seat;
|
|
|
|
DataSourceInterface *source = nullptr;
|
|
|
|
SurfaceInterface *surface = nullptr;
|
|
|
|
SurfaceInterface *icon = nullptr;
|
|
|
|
|
|
|
|
DataSourceInterface *selection = nullptr;
|
|
|
|
|
|
|
|
private:
|
|
|
|
void startDrag(DataSourceInterface *dataSource, SurfaceInterface *origin, SurfaceInterface *icon);
|
|
|
|
void setSelection(DataSourceInterface *dataSource);
|
|
|
|
static void startDragCallback(wl_client *client, wl_resource *resource, wl_resource *source, wl_resource *origin, wl_resource *icon, uint32_t serial);
|
|
|
|
static void setSelectionCallback(wl_client *client, wl_resource *resource, wl_resource *source, uint32_t serial);
|
|
|
|
static void unbind(wl_resource *resource);
|
|
|
|
|
|
|
|
DataDeviceInterface *q;
|
|
|
|
|
|
|
|
static const struct wl_data_device_interface s_interface;
|
|
|
|
};
|
|
|
|
|
|
|
|
const struct wl_data_device_interface DataDeviceInterface::Private::s_interface = {
|
|
|
|
startDragCallback,
|
|
|
|
setSelectionCallback
|
|
|
|
};
|
|
|
|
|
2014-11-14 08:45:02 +00:00
|
|
|
DataDeviceInterface::Private::Private(SeatInterface *seat, DataDeviceInterface *q, DataDeviceManagerInterface *manager)
|
|
|
|
: Resource::Private(manager)
|
|
|
|
, seat(seat)
|
2014-11-06 09:02:49 +00:00
|
|
|
, q(q)
|
|
|
|
{
|
|
|
|
}
|
|
|
|
|
2014-11-14 08:45:02 +00:00
|
|
|
DataDeviceInterface::Private::~Private() = default;
|
2014-11-06 09:02:49 +00:00
|
|
|
|
|
|
|
void DataDeviceInterface::Private::startDragCallback(wl_client *client, wl_resource *resource, wl_resource *source, wl_resource *origin, wl_resource *icon, uint32_t serial)
|
|
|
|
{
|
|
|
|
Q_UNUSED(client)
|
|
|
|
Q_UNUSED(serial)
|
|
|
|
// TODO: verify serial
|
2014-11-14 09:20:43 +00:00
|
|
|
cast<Private>(resource)->startDrag(DataSourceInterface::get(source), SurfaceInterface::get(origin), SurfaceInterface::get(icon));
|
2014-11-06 09:02:49 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
void DataDeviceInterface::Private::startDrag(DataSourceInterface *dataSource, SurfaceInterface *origin, SurfaceInterface *i)
|
|
|
|
{
|
|
|
|
if (seat->pointer()->focusedSurface() != origin) {
|
2014-11-14 08:45:02 +00:00
|
|
|
wl_resource_post_error(resource, 0, "Surface doesn't have pointer grab");
|
2014-11-06 09:02:49 +00:00
|
|
|
return;
|
|
|
|
}
|
|
|
|
source = dataSource;
|
|
|
|
surface = origin;
|
|
|
|
icon = i;
|
|
|
|
emit q->dragStarted();
|
|
|
|
}
|
|
|
|
|
|
|
|
void DataDeviceInterface::Private::setSelectionCallback(wl_client *client, wl_resource *resource, wl_resource *source, uint32_t serial)
|
|
|
|
{
|
|
|
|
Q_UNUSED(client)
|
|
|
|
Q_UNUSED(serial)
|
|
|
|
// TODO: verify serial
|
2014-11-14 09:20:43 +00:00
|
|
|
cast<Private>(resource)->setSelection(DataSourceInterface::get(source));
|
2014-11-06 09:02:49 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
void DataDeviceInterface::Private::setSelection(DataSourceInterface *dataSource)
|
|
|
|
{
|
|
|
|
selection = dataSource;
|
|
|
|
if (selection) {
|
|
|
|
emit q->selectionChanged(selection);
|
|
|
|
} else {
|
|
|
|
emit q->selectionCleared();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
void DataDeviceInterface::Private::unbind(wl_resource *resource)
|
|
|
|
{
|
2014-11-14 09:20:43 +00:00
|
|
|
auto s = cast<Private>(resource);
|
2014-11-14 08:45:02 +00:00
|
|
|
s->resource = nullptr;
|
2014-11-06 09:02:49 +00:00
|
|
|
s->q->deleteLater();
|
|
|
|
}
|
|
|
|
|
|
|
|
void DataDeviceInterface::Private::create(wl_client *client, quint32 version, quint32 id)
|
|
|
|
{
|
2014-11-14 08:45:02 +00:00
|
|
|
Q_ASSERT(!resource);
|
|
|
|
resource = wl_resource_create(client, &wl_data_device_interface, version, id);
|
|
|
|
if (!resource) {
|
2014-11-06 09:02:49 +00:00
|
|
|
return;
|
|
|
|
}
|
2014-11-14 08:45:02 +00:00
|
|
|
wl_resource_set_implementation(resource, &s_interface, this, unbind);
|
2014-11-06 09:02:49 +00:00
|
|
|
}
|
|
|
|
|
2014-11-06 15:56:50 +00:00
|
|
|
DataOfferInterface *DataDeviceInterface::Private::createDataOffer(DataSourceInterface *source)
|
|
|
|
{
|
|
|
|
DataOfferInterface *offer = new DataOfferInterface(source, q);
|
2014-11-14 08:45:02 +00:00
|
|
|
offer->create(wl_resource_get_client(resource), wl_resource_get_version(resource), 0);
|
2014-11-06 15:56:50 +00:00
|
|
|
if (!offer->resource()) {
|
|
|
|
// TODO: send error?
|
|
|
|
delete offer;
|
|
|
|
return nullptr;
|
|
|
|
}
|
2014-11-14 08:45:02 +00:00
|
|
|
wl_data_device_send_data_offer(resource, offer->resource());
|
2014-11-06 15:56:50 +00:00
|
|
|
offer->sendAllOffers();
|
|
|
|
return offer;
|
|
|
|
}
|
2014-11-06 09:02:49 +00:00
|
|
|
|
|
|
|
DataDeviceInterface::DataDeviceInterface(SeatInterface *seat, DataDeviceManagerInterface *parent)
|
2014-11-14 08:45:02 +00:00
|
|
|
: Resource(new Private(seat, this, parent))
|
2014-11-06 09:02:49 +00:00
|
|
|
{
|
|
|
|
}
|
|
|
|
|
|
|
|
DataDeviceInterface::~DataDeviceInterface() = default;
|
|
|
|
|
|
|
|
SeatInterface *DataDeviceInterface::seat() const
|
|
|
|
{
|
2014-11-14 08:45:02 +00:00
|
|
|
Q_D();
|
2014-11-06 09:02:49 +00:00
|
|
|
return d->seat;
|
|
|
|
}
|
|
|
|
|
|
|
|
DataSourceInterface *DataDeviceInterface::dragSource() const
|
|
|
|
{
|
2014-11-14 08:45:02 +00:00
|
|
|
Q_D();
|
2014-11-06 09:02:49 +00:00
|
|
|
return d->source;
|
|
|
|
}
|
|
|
|
|
|
|
|
SurfaceInterface *DataDeviceInterface::icon() const
|
|
|
|
{
|
2014-11-14 08:45:02 +00:00
|
|
|
Q_D();
|
2014-11-06 09:02:49 +00:00
|
|
|
return d->icon;
|
|
|
|
}
|
|
|
|
|
|
|
|
SurfaceInterface *DataDeviceInterface::origin() const
|
|
|
|
{
|
2014-11-14 08:45:02 +00:00
|
|
|
Q_D();
|
2014-11-06 09:02:49 +00:00
|
|
|
return d->surface;
|
|
|
|
}
|
|
|
|
|
|
|
|
DataSourceInterface *DataDeviceInterface::selection() const
|
|
|
|
{
|
2014-11-14 08:45:02 +00:00
|
|
|
Q_D();
|
2014-11-06 09:02:49 +00:00
|
|
|
return d->selection;
|
|
|
|
}
|
|
|
|
|
2014-11-06 15:56:50 +00:00
|
|
|
void DataDeviceInterface::sendSelection(DataDeviceInterface *other)
|
|
|
|
{
|
2014-11-14 08:45:02 +00:00
|
|
|
Q_D();
|
2014-11-06 15:56:50 +00:00
|
|
|
auto r = d->createDataOffer(other->selection());
|
|
|
|
if (!r) {
|
|
|
|
return;
|
|
|
|
}
|
2014-11-14 08:45:02 +00:00
|
|
|
wl_data_device_send_selection(d->resource, r->resource());
|
|
|
|
}
|
|
|
|
|
|
|
|
DataDeviceInterface::Private *DataDeviceInterface::d_func() const
|
|
|
|
{
|
|
|
|
return reinterpret_cast<DataDeviceInterface::Private*>(d.data());
|
2014-11-06 15:56:50 +00:00
|
|
|
}
|
|
|
|
|
2014-11-06 09:02:49 +00:00
|
|
|
}
|
|
|
|
}
|