diff --git a/src/server/datadevice_interface.cpp b/src/server/datadevice_interface.cpp index e12af62..02a1718 100644 --- a/src/server/datadevice_interface.cpp +++ b/src/server/datadevice_interface.cpp @@ -1,210 +1,290 @@ /******************************************************************** Copyright 2014 Martin Gräßlin 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 . *********************************************************************/ #include "datadevice_interface.h" #include "datadevicemanager_interface.h" #include "dataoffer_interface.h" #include "datasource_interface.h" #include "display.h" #include "resource_p.h" #include "pointer_interface.h" #include "seat_interface.h" #include "surface_interface.h" // Wayland #include namespace KWayland { namespace Server { class DataDeviceInterface::Private : public Resource::Private { public: Private(SeatInterface *seat, DataDeviceInterface *q, DataDeviceManagerInterface *manager, wl_resource *parentResource); ~Private(); DataOfferInterface *createDataOffer(DataSourceInterface *source); SeatInterface *seat; DataSourceInterface *source = nullptr; SurfaceInterface *surface = nullptr; SurfaceInterface *icon = nullptr; DataSourceInterface *selection = nullptr; + struct Drag { + SurfaceInterface *surface = nullptr; + QMetaObject::Connection destroyConnection; + QMetaObject::Connection pointerPosConnection; + quint32 serial = 0; + }; + Drag drag; + private: DataDeviceInterface *q_func() { return reinterpret_cast(q); } - void startDrag(DataSourceInterface *dataSource, SurfaceInterface *origin, SurfaceInterface *icon); + void startDrag(DataSourceInterface *dataSource, SurfaceInterface *origin, SurfaceInterface *icon, quint32 serial); 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 releaseCallback(wl_client *client, wl_resource *resource); static const struct wl_data_device_interface s_interface; }; #ifndef DOXYGEN_SHOULD_SKIP_THIS const struct wl_data_device_interface DataDeviceInterface::Private::s_interface = { startDragCallback, setSelectionCallback, releaseCallback }; #endif DataDeviceInterface::Private::Private(SeatInterface *seat, DataDeviceInterface *q, DataDeviceManagerInterface *manager, wl_resource *parentResource) : Resource::Private(q, manager, parentResource, &wl_data_device_interface, &s_interface) , seat(seat) { } DataDeviceInterface::Private::~Private() = default; 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 - cast(resource)->startDrag(DataSourceInterface::get(source), SurfaceInterface::get(origin), SurfaceInterface::get(icon)); + cast(resource)->startDrag(DataSourceInterface::get(source), SurfaceInterface::get(origin), SurfaceInterface::get(icon), serial); } -void DataDeviceInterface::Private::startDrag(DataSourceInterface *dataSource, SurfaceInterface *origin, SurfaceInterface *i) +void DataDeviceInterface::Private::startDrag(DataSourceInterface *dataSource, SurfaceInterface *origin, SurfaceInterface *i, quint32 serial) { - if (seat->focusedPointerSurface() != origin) { + // TODO: allow touch + if (seat->hasImplicitPointerGrab(serial) && seat->focusedPointerSurface() != origin) { wl_resource_post_error(resource, 0, "Surface doesn't have pointer grab"); return; } + // TODO: source is allowed to be null, handled client internally! source = dataSource; surface = origin; icon = i; + drag.serial = serial; Q_Q(DataDeviceInterface); 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 cast(resource)->setSelection(DataSourceInterface::get(source)); } void DataDeviceInterface::Private::releaseCallback(wl_client *client, wl_resource *resource) { Q_UNUSED(client); Private *p = reinterpret_cast(wl_resource_get_user_data(resource)); wl_resource_destroy(resource); p->q->deleteLater(); } void DataDeviceInterface::Private::setSelection(DataSourceInterface *dataSource) { Q_Q(DataDeviceInterface); selection = dataSource; if (selection) { emit q->selectionChanged(selection); } else { emit q->selectionCleared(); } } DataOfferInterface *DataDeviceInterface::Private::createDataOffer(DataSourceInterface *source) { Q_Q(DataDeviceInterface); DataOfferInterface *offer = new DataOfferInterface(source, q, resource); auto c = q->global()->display()->getConnection(wl_resource_get_client(resource)); offer->create(c, wl_resource_get_version(resource), 0); if (!offer->resource()) { // TODO: send error? delete offer; return nullptr; } wl_data_device_send_data_offer(resource, offer->resource()); offer->sendAllOffers(); return offer; } DataDeviceInterface::DataDeviceInterface(SeatInterface *seat, DataDeviceManagerInterface *parent, wl_resource *parentResource) : Resource(new Private(seat, this, parent, parentResource)) { } DataDeviceInterface::~DataDeviceInterface() = default; SeatInterface *DataDeviceInterface::seat() const { Q_D(); return d->seat; } DataSourceInterface *DataDeviceInterface::dragSource() const { Q_D(); return d->source; } SurfaceInterface *DataDeviceInterface::icon() const { Q_D(); return d->icon; } SurfaceInterface *DataDeviceInterface::origin() const { Q_D(); return d->surface; } DataSourceInterface *DataDeviceInterface::selection() const { Q_D(); return d->selection; } void DataDeviceInterface::sendSelection(DataDeviceInterface *other) { Q_D(); auto r = d->createDataOffer(other->selection()); if (!r) { return; } if (!d->resource) { return; } wl_data_device_send_selection(d->resource, r->resource()); } void DataDeviceInterface::sendClearSelection() { Q_D(); if (!d->resource) { return; } wl_data_device_send_selection(d->resource, nullptr); } +void DataDeviceInterface::drop() +{ + Q_D(); + if (!d->resource) { + return; + } + wl_data_device_send_drop(d->resource); + client()->flush(); +} + +void DataDeviceInterface::updateDragTarget(SurfaceInterface *surface, quint32 serial) +{ + Q_D(); + if (d->drag.surface) { + if (d->resource && d->drag.surface->resource()) { + wl_data_device_send_leave(d->resource); + } + if (d->drag.pointerPosConnection) { + disconnect(d->drag.pointerPosConnection); + d->drag.pointerPosConnection = QMetaObject::Connection(); + } + disconnect(d->drag.destroyConnection); + d->drag.destroyConnection = QMetaObject::Connection(); + d->drag.surface = nullptr; + // don't update serial, we need it + } + if (!surface) { + return; + } + DataOfferInterface *offer = d->createDataOffer(d->seat->dragSource()->dragSource()); + d->drag.surface = surface; + if (d->seat->isDragPointer()) { + d->drag.pointerPosConnection = connect(d->seat, &SeatInterface::pointerPosChanged, this, + [this] { + Q_D(); + const QPointF pos = d->seat->dragSurfaceTransformation().map(d->seat->pointerPos()); + wl_data_device_send_motion(d->resource, d->seat->timestamp(), + wl_fixed_from_double(pos.x()), wl_fixed_from_double(pos.y())); + client()->flush(); + } + ); + } + // TODO: same for touch + d->drag.destroyConnection = connect(d->drag.surface, &QObject::destroyed, this, + [this] { + Q_D(); + if (d->resource) { + wl_data_device_send_leave(d->resource); + } + if (d->drag.pointerPosConnection) { + disconnect(d->drag.pointerPosConnection); + } + d->drag = Private::Drag(); + } + ); + + // TODO: handle touch position + const QPointF pos = d->seat->dragSurfaceTransformation().map(d->seat->pointerPos()); + wl_data_device_send_enter(d->resource, serial, surface->resource(), + wl_fixed_from_double(pos.x()), wl_fixed_from_double(pos.y()), offer ? offer->resource() : nullptr); + d->client->flush(); +} + +quint32 DataDeviceInterface::dragImplicitGrabSerial() const +{ + Q_D(); + return d->drag.serial; +} + DataDeviceInterface::Private *DataDeviceInterface::d_func() const { return reinterpret_cast(d.data()); } } } diff --git a/src/server/datadevice_interface.h b/src/server/datadevice_interface.h index 0b53fc3..5ab8719 100644 --- a/src/server/datadevice_interface.h +++ b/src/server/datadevice_interface.h @@ -1,79 +1,104 @@ /******************************************************************** Copyright 2014 Martin Gräßlin 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 . *********************************************************************/ #ifndef WAYLAND_SERVER_DATA_DEVICE_INTERFACE_H #define WAYLAND_SERVER_DATA_DEVICE_INTERFACE_H #include #include #include "resource.h" namespace KWayland { namespace Server { class DataDeviceManagerInterface; +class DataOfferInterface; class DataSourceInterface; class SeatInterface; class SurfaceInterface; /** * @brief Represents the Resource for the wl_data_device interface. * * @see SeatInterface * @see DataSourceInterface **/ class KWAYLANDSERVER_EXPORT DataDeviceInterface : public Resource { Q_OBJECT public: virtual ~DataDeviceInterface(); SeatInterface *seat() const; DataSourceInterface *dragSource() const; SurfaceInterface *origin() const; SurfaceInterface *icon() const; + /** + * @returns the serial of the implicit grab which started the drag + * @since 5.6 + **/ + quint32 dragImplicitGrabSerial() const; + DataSourceInterface *selection() const; void sendSelection(DataDeviceInterface *other); void sendClearSelection(); + /** + * The event is sent when a drag-and-drop operation is ended because the implicit grab is removed. + * @since 5.6 + **/ + void drop(); + /** + * Updates the SurfaceInterface to which drag motion events are sent. + * + * If a SurfaceInterface was registered in this DataDeviceInterface for drag motion events, it + * will be sent a leave event. + * + * If @p surface is not null it will be sent a drag enter event. + * + * @param surface The SurfaceInterface which gets motion events + * @param serial The serial to be used for enter/leave + * @since 5.6 + **/ + void updateDragTarget(SurfaceInterface *surface, quint32 serial); Q_SIGNALS: void dragStarted(); void selectionChanged(KWayland::Server::DataSourceInterface*); void selectionCleared(); private: friend class DataDeviceManagerInterface; explicit DataDeviceInterface(SeatInterface *seat, DataDeviceManagerInterface *parent, wl_resource *parentResource); class Private; Private *d_func() const; }; } } Q_DECLARE_METATYPE(KWayland::Server::DataDeviceInterface*) #endif diff --git a/src/server/dataoffer_interface.cpp b/src/server/dataoffer_interface.cpp index 516caa5..1b6fa3d 100644 --- a/src/server/dataoffer_interface.cpp +++ b/src/server/dataoffer_interface.cpp @@ -1,127 +1,136 @@ /******************************************************************** Copyright 2014 Martin Gräßlin 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 . *********************************************************************/ #include "dataoffer_interface.h" #include "datadevice_interface.h" #include "datasource_interface.h" #include "resource_p.h" // Qt #include // Wayland #include namespace KWayland { namespace Server { class DataOfferInterface::Private : public Resource::Private { public: Private(DataSourceInterface *source, DataDeviceInterface *parentInterface, DataOfferInterface *q, wl_resource *parentResource); ~Private(); DataSourceInterface *source; DataDeviceInterface *dataDevice; private: DataOfferInterface *q_func() { return reinterpret_cast(q); } void receive(const QString &mimeType, qint32 fd); static void acceptCallback(wl_client *client, wl_resource *resource, uint32_t serial, const char *mimeType); static void receiveCallback(wl_client *client, wl_resource *resource, const char *mimeType, int32_t fd); static void destroyCallback(wl_client *client, wl_resource *resource); static const struct wl_data_offer_interface s_interface; }; #ifndef DOXYGEN_SHOULD_SKIP_THIS const struct wl_data_offer_interface DataOfferInterface::Private::s_interface = { acceptCallback, receiveCallback, destroyCallback }; #endif DataOfferInterface::Private::Private(DataSourceInterface *source, DataDeviceInterface *parentInterface, DataOfferInterface *q, wl_resource *parentResource) : Resource::Private(q, nullptr, parentResource, &wl_data_offer_interface, &s_interface) , source(source) , dataDevice(parentInterface) { // TODO: connect to new selections } DataOfferInterface::Private::~Private() = default; void DataOfferInterface::Private::acceptCallback(wl_client *client, wl_resource *resource, uint32_t serial, const char *mimeType) { Q_UNUSED(client) - Q_UNUSED(resource) Q_UNUSED(serial) - Q_UNUSED(mimeType) + auto p = cast(resource); + if (!p->source) { + return; + } + p->source->accept(mimeType ? QString::fromUtf8(mimeType) : QString()); } void DataOfferInterface::Private::destroyCallback(wl_client *client, wl_resource *resource) { Q_UNUSED(client) wl_resource_destroy(resource); } void DataOfferInterface::Private::receiveCallback(wl_client *client, wl_resource *resource, const char *mimeType, int32_t fd) { Q_UNUSED(client) cast(resource)->receive(QString::fromUtf8(mimeType), fd); } void DataOfferInterface::Private::receive(const QString &mimeType, qint32 fd) { source->requestData(mimeType, fd); } DataOfferInterface::DataOfferInterface(DataSourceInterface *source, DataDeviceInterface *parentInterface, wl_resource *parentResource) : Resource(new Private(source, parentInterface, this, parentResource), parentInterface) { connect(source, &DataSourceInterface::mimeTypeOffered, this, [this](const QString &mimeType) { Q_D(); if (!d->resource) { return; } wl_data_offer_send_offer(d->resource, mimeType.toUtf8().constData()); } ); + QObject::connect(source, &QObject::destroyed, this, + [this] { + Q_D(); + d->source = nullptr; + } + ); } DataOfferInterface::~DataOfferInterface() = default; void DataOfferInterface::sendAllOffers() { Q_D(); for (const QString &mimeType : d->source->mimeTypes()) { wl_data_offer_send_offer(d->resource, mimeType.toUtf8().constData()); } } DataOfferInterface::Private *DataOfferInterface::d_func() const { return reinterpret_cast(d.data()); } } } diff --git a/src/server/datasource_interface.cpp b/src/server/datasource_interface.cpp index 47b51cf..42f2266 100644 --- a/src/server/datasource_interface.cpp +++ b/src/server/datasource_interface.cpp @@ -1,133 +1,136 @@ /******************************************************************** Copyright 2014 Martin Gräßlin 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 . *********************************************************************/ #include "datasource_interface.h" #include "datadevicemanager_interface.h" #include "resource_p.h" // Qt #include // Wayland #include // system #include namespace KWayland { namespace Server { class DataSourceInterface::Private : public Resource::Private { public: Private(DataSourceInterface *q, DataDeviceManagerInterface *parent, wl_resource *parentResource); ~Private(); QStringList mimeTypes; private: DataSourceInterface *q_func() { return reinterpret_cast(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 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) + auto p = cast(resource); wl_resource_destroy(resource); + p->resource = nullptr; + p->q->deleteLater(); } void DataSourceInterface::Private::offerCallback(wl_client *client, wl_resource *resource, const char *mimeType) { Q_UNUSED(client) cast(resource)->offer(QString::fromUtf8(mimeType)); } void DataSourceInterface::Private::offer(const QString &mimeType) { mimeTypes << mimeType; Q_Q(DataSourceInterface); emit q->mimeTypeOffered(mimeType); } 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(native); } DataSourceInterface::Private *DataSourceInterface::d_func() const { return reinterpret_cast(d.data()); } } } diff --git a/src/server/pointer_interface.cpp b/src/server/pointer_interface.cpp index 8fa1b81..0c8486b 100644 --- a/src/server/pointer_interface.cpp +++ b/src/server/pointer_interface.cpp @@ -1,263 +1,268 @@ /******************************************************************** Copyright 2014 Martin Gräßlin 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 . *********************************************************************/ #include "pointer_interface.h" #include "resource_p.h" #include "seat_interface.h" #include "display.h" #include "surface_interface.h" // Wayland #include namespace KWayland { namespace Server { class PointerInterface::Private : public Resource::Private { public: Private(SeatInterface *parent, wl_resource *parentResource, PointerInterface *q); SeatInterface *seat; SurfaceInterface *focusedSurface = nullptr; QMetaObject::Connection destroyConnection; Cursor *cursor = nullptr; private: PointerInterface *q_func() { return reinterpret_cast(q); } void setCursor(quint32 serial, SurfaceInterface *surface, const QPoint &hotspot); // interface static void setCursorCallback(wl_client *client, wl_resource *resource, uint32_t serial, wl_resource *surface, int32_t hotspot_x, int32_t hotspot_y); // since version 3 static void releaseCallback(wl_client *client, wl_resource *resource); static const struct wl_pointer_interface s_interface; }; class Cursor::Private { public: Private(Cursor *q, PointerInterface *pointer); PointerInterface *pointer; quint32 enteredSerial = 0; QPoint hotspot; QPointer surface; void update(const QPointer &surface, quint32 serial, const QPoint &hotspot); private: Cursor *q; }; PointerInterface::Private::Private(SeatInterface *parent, wl_resource *parentResource, PointerInterface *q) : Resource::Private(q, parent, parentResource, &wl_pointer_interface, &s_interface) , seat(parent) { } void PointerInterface::Private::setCursor(quint32 serial, SurfaceInterface *surface, const QPoint &hotspot) { if (!cursor) { Q_Q(PointerInterface); cursor = new Cursor(q); cursor->d->update(QPointer(surface), serial, hotspot); QObject::connect(cursor, &Cursor::changed, q, &PointerInterface::cursorChanged); emit q->cursorChanged(); } else { cursor->d->update(QPointer(surface), serial, hotspot); } } #ifndef DOXYGEN_SHOULD_SKIP_THIS const struct wl_pointer_interface PointerInterface::Private::s_interface = { setCursorCallback, releaseCallback }; #endif PointerInterface::PointerInterface(SeatInterface *parent, wl_resource *parentResource) : Resource(new Private(parent, parentResource, this), parent) { + // TODO: handle touch connect(parent, &SeatInterface::pointerPosChanged, this, [this] { Q_D(); + if (d->seat->isDragPointer()) { + // handled by DataDevice + return; + } if (d->focusedSurface && d->resource) { const QPointF pos = d->seat->focusedPointerSurfaceTransformation().map(d->seat->pointerPos()); wl_pointer_send_motion(d->resource, d->seat->timestamp(), wl_fixed_from_double(pos.x()), wl_fixed_from_double(pos.y())); } }); } PointerInterface::~PointerInterface() = default; void PointerInterface::setFocusedSurface(SurfaceInterface *surface, quint32 serial) { Q_D(); if (d->focusedSurface) { if (d->resource && d->focusedSurface->resource()) { wl_pointer_send_leave(d->resource, serial, d->focusedSurface->resource()); } disconnect(d->destroyConnection); } if (!surface) { d->focusedSurface = nullptr; return; } d->focusedSurface = surface; d->destroyConnection = connect(d->focusedSurface, &QObject::destroyed, this, [this] { Q_D(); d->focusedSurface = nullptr; } ); const QPointF pos = d->seat->focusedPointerSurfaceTransformation().map(d->seat->pointerPos()); wl_pointer_send_enter(d->resource, serial, d->focusedSurface->resource(), wl_fixed_from_double(pos.x()), wl_fixed_from_double(pos.y())); d->client->flush(); } void PointerInterface::buttonPressed(quint32 button, quint32 serial) { Q_D(); Q_ASSERT(d->focusedSurface); if (!d->resource) { return; } wl_pointer_send_button(d->resource, serial, d->seat->timestamp(), button, WL_POINTER_BUTTON_STATE_PRESSED); } void PointerInterface::buttonReleased(quint32 button, quint32 serial) { Q_D(); Q_ASSERT(d->focusedSurface); if (!d->resource) { return; } wl_pointer_send_button(d->resource, serial, d->seat->timestamp(), button, WL_POINTER_BUTTON_STATE_RELEASED); } void PointerInterface::axis(Qt::Orientation orientation, quint32 delta) { Q_D(); Q_ASSERT(d->focusedSurface); if (!d->resource) { return; } wl_pointer_send_axis(d->resource, d->seat->timestamp(), (orientation == Qt::Vertical) ? WL_POINTER_AXIS_VERTICAL_SCROLL : WL_POINTER_AXIS_HORIZONTAL_SCROLL, wl_fixed_from_int(delta)); } void PointerInterface::Private::setCursorCallback(wl_client *client, wl_resource *resource, uint32_t serial, wl_resource *surface, int32_t hotspot_x, int32_t hotspot_y) { auto p = cast(resource); Q_ASSERT(p->client->client() == client); p->setCursor(serial, SurfaceInterface::get(surface), QPoint(hotspot_x, hotspot_y)); } void PointerInterface::Private::releaseCallback(wl_client *client, wl_resource *resource) { Q_UNUSED(client) unbind(resource); } Cursor *PointerInterface::cursor() const { Q_D(); return d->cursor; } PointerInterface::Private *PointerInterface::d_func() const { return reinterpret_cast(d.data()); } Cursor::Private::Private(Cursor *q, PointerInterface *pointer) : pointer(pointer) , q(q) { } void Cursor::Private::update(const QPointer< SurfaceInterface > &s, quint32 serial, const QPoint &p) { bool emitChanged = false; if (enteredSerial != serial) { enteredSerial = serial; emitChanged = true; emit q->enteredSerialChanged(); } if (hotspot != p) { hotspot = p; emitChanged = true; emit q->hotspotChanged(); } if (surface != s) { if (!surface.isNull()) { QObject::disconnect(surface.data(), &SurfaceInterface::damaged, q, &Cursor::changed); } surface = s; if (!surface.isNull()) { QObject::connect(surface.data(), &SurfaceInterface::damaged, q, &Cursor::changed); } emitChanged = true; emit q->surfaceChanged(); } if (emitChanged) { emit q->changed(); } } Cursor::Cursor(PointerInterface *parent) : QObject(parent) , d(new Private(this, parent)) { } Cursor::~Cursor() = default; quint32 Cursor::enteredSerial() const { return d->enteredSerial; } QPoint Cursor::hotspot() const { return d->hotspot; } PointerInterface *Cursor::pointer() const { return d->pointer; } QPointer< SurfaceInterface > Cursor::surface() const { return d->surface; } } } diff --git a/src/server/seat_interface.cpp b/src/server/seat_interface.cpp index 4aa0c79..75c7741 100644 --- a/src/server/seat_interface.cpp +++ b/src/server/seat_interface.cpp @@ -1,1001 +1,1150 @@ /******************************************************************** Copyright 2014 Martin Gräßlin 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 . *********************************************************************/ #include "seat_interface.h" #include "seat_interface_p.h" #include "display.h" #include "datadevice_interface.h" #include "datasource_interface.h" #include "keyboard_interface.h" #include "pointer_interface.h" #include "surface_interface.h" // Wayland #ifndef WL_SEAT_NAME_SINCE_VERSION #define WL_SEAT_NAME_SINCE_VERSION 2 #endif // linux #include namespace KWayland { namespace Server { const quint32 SeatInterface::Private::s_version = 4; const qint32 SeatInterface::Private::s_pointerVersion = 3; const qint32 SeatInterface::Private::s_touchVersion = 3; const qint32 SeatInterface::Private::s_keyboardVersion = 4; SeatInterface::Private::Private(SeatInterface *q, Display *display) : Global::Private(display, &wl_seat_interface, s_version) , q(q) { } #ifndef DOXYGEN_SHOULD_SKIP_THIS const struct wl_seat_interface SeatInterface::Private::s_interface = { getPointerCallback, getKeyboardCallback, getTouchCallback }; #endif SeatInterface::SeatInterface(Display *display, QObject *parent) : Global(new Private(this, display), parent) { Q_D(); connect(this, &SeatInterface::nameChanged, this, [this, d] { for (auto it = d->resources.constBegin(); it != d->resources.constEnd(); ++it) { d->sendName(*it); } } ); auto sendCapabilitiesAll = [this, d] { for (auto it = d->resources.constBegin(); it != d->resources.constEnd(); ++it) { d->sendCapabilities(*it); } }; connect(this, &SeatInterface::hasPointerChanged, this, sendCapabilitiesAll); connect(this, &SeatInterface::hasKeyboardChanged, this, sendCapabilitiesAll); connect(this, &SeatInterface::hasTouchChanged, this, sendCapabilitiesAll); } SeatInterface::~SeatInterface() { Q_D(); while (!d->resources.isEmpty()) { wl_resource_destroy(d->resources.takeLast()); } } void SeatInterface::Private::bind(wl_client *client, uint32_t version, uint32_t id) { wl_resource *r = wl_resource_create(client, &wl_seat_interface, qMin(s_version, version), id); if (!r) { wl_client_post_no_memory(client); return; } resources << r; wl_resource_set_implementation(r, &s_interface, this, unbind); sendCapabilities(r); sendName(r); } void SeatInterface::Private::unbind(wl_resource *r) { cast(r)->resources.removeAll(r); } void SeatInterface::Private::updatePointerButtonSerial(quint32 button, quint32 serial) { auto it = globalPointer.buttonSerials.find(button); if (it == globalPointer.buttonSerials.end()) { globalPointer.buttonSerials.insert(button, serial); return; } it.value() = serial; } void SeatInterface::Private::updatePointerButtonState(quint32 button, Pointer::State state) { auto it = globalPointer.buttonStates.find(button); if (it == globalPointer.buttonStates.end()) { globalPointer.buttonStates.insert(button, state); return; } it.value() = state; } void SeatInterface::Private::updateKey(quint32 key, Keyboard::State state) { auto it = keys.states.find(key); if (it == keys.states.end()) { keys.states.insert(key, state); return; } it.value() = state; } void SeatInterface::Private::sendName(wl_resource *r) { if (wl_resource_get_version(r) < WL_SEAT_NAME_SINCE_VERSION) { return; } wl_seat_send_name(r, name.toUtf8().constData()); } void SeatInterface::Private::sendCapabilities(wl_resource *r) { uint32_t capabilities = 0; if (pointer) { capabilities |= WL_SEAT_CAPABILITY_POINTER; } if (keyboard) { capabilities |= WL_SEAT_CAPABILITY_KEYBOARD; } if (touch) { capabilities |= WL_SEAT_CAPABILITY_TOUCH; } wl_seat_send_capabilities(r, capabilities); } SeatInterface::Private *SeatInterface::Private::cast(wl_resource *r) { return r ? reinterpret_cast(wl_resource_get_user_data(r)) : nullptr; } namespace { template static T *interfaceForSurface(SurfaceInterface *surface, const QVector &interfaces) { if (!surface) { return nullptr; } for (auto it = interfaces.begin(); it != interfaces.end(); ++it) { if ((*it)->client() == surface->client()) { return (*it); } } return nullptr; } } PointerInterface *SeatInterface::Private::pointerForSurface(SurfaceInterface *surface) const { return interfaceForSurface(surface, pointers); } KeyboardInterface *SeatInterface::Private::keyboardForSurface(SurfaceInterface *surface) const { return interfaceForSurface(surface, keyboards); } TouchInterface *SeatInterface::Private::touchForSurface(SurfaceInterface *surface) const { return interfaceForSurface(surface, touchs); } DataDeviceInterface *SeatInterface::Private::dataDeviceForSurface(SurfaceInterface *surface) const { return interfaceForSurface(surface, dataDevices); } void SeatInterface::Private::registerDataDevice(DataDeviceInterface *dataDevice) { Q_ASSERT(dataDevice->seat() == q); dataDevices << dataDevice; QObject::connect(dataDevice, &QObject::destroyed, q, [this, dataDevice] { dataDevices.removeAt(dataDevices.indexOf(dataDevice)); if (keys.focus.selection == dataDevice) { keys.focus.selection = nullptr; } if (currentSelection == dataDevice) { // current selection is cleared currentSelection = nullptr; if (keys.focus.selection) { keys.focus.selection->sendClearSelection(); } } } ); QObject::connect(dataDevice, &DataDeviceInterface::selectionChanged, q, [this, dataDevice] { updateSelection(dataDevice, true); } ); QObject::connect(dataDevice, &DataDeviceInterface::selectionCleared, q, [this, dataDevice] { updateSelection(dataDevice, false); } ); + QObject::connect(dataDevice, &DataDeviceInterface::dragStarted, q, + [this, dataDevice] { + if (q->hasImplicitPointerGrab(dataDevice->dragImplicitGrabSerial())) { + drag.mode = Drag::Mode::Pointer; + } else { + // TODO: touch + return; + } + drag.source = dataDevice; + drag.target = dataDevice; + drag.surface = dataDevice->origin(); + drag.sourcePointer = interfaceForSurface(drag.surface, pointers); + // TODO: transformation needs to be either pointer or touch + drag.transformation = globalPointer.focus.transformation; + drag.destroyConnection = QObject::connect(dataDevice, &QObject::destroyed, q, + [this] { + endDrag(display->nextSerial()); + } + ); + dataDevice->updateDragTarget(dataDevice->origin(), dataDevice->dragImplicitGrabSerial()); + emit q->dragStarted(); + emit q->dragSurfaceChanged(); + } + ); // is the new DataDevice for the current keyoard focus? if (keys.focus.surface && !keys.focus.selection) { // same client? if (keys.focus.surface->client() == dataDevice->client()) { keys.focus.selection = dataDevice; if (currentSelection) { dataDevice->sendSelection(currentSelection); } } } } +void SeatInterface::Private::endDrag(quint32 serial) +{ + auto target = drag.target; + QObject::disconnect(drag.destroyConnection); + if (target) { + target->drop(); + target->updateDragTarget(nullptr, serial); + } + drag = Drag(); + emit q->dragSurfaceChanged(); + emit q->dragEnded(); +} + void SeatInterface::Private::updateSelection(DataDeviceInterface *dataDevice, bool set) { if (keys.focus.surface && (keys.focus.surface->client() == dataDevice->client())) { // new selection on a data device belonging to current keyboard focus currentSelection = dataDevice; } if (dataDevice == currentSelection) { // need to send out the selection if (keys.focus.selection) { if (set) { keys.focus.selection->sendSelection(dataDevice); } else { keys.focus.selection->sendClearSelection(); } } } } void SeatInterface::setHasKeyboard(bool has) { Q_D(); if (d->keyboard == has) { return; } d->keyboard = has; emit hasKeyboardChanged(d->keyboard); } void SeatInterface::setHasPointer(bool has) { Q_D(); if (d->pointer == has) { return; } d->pointer = has; emit hasPointerChanged(d->pointer); } void SeatInterface::setHasTouch(bool has) { Q_D(); if (d->touch == has) { return; } d->touch = has; emit hasTouchChanged(d->touch); } void SeatInterface::setName(const QString &name) { Q_D(); if (d->name == name) { return; } d->name = name; emit nameChanged(d->name); } void SeatInterface::Private::getPointerCallback(wl_client *client, wl_resource *resource, uint32_t id) { cast(resource)->getPointer(client, resource, id); } void SeatInterface::Private::getPointer(wl_client *client, wl_resource *resource, uint32_t id) { // TODO: only create if seat has pointer? PointerInterface *pointer = new PointerInterface(q, resource); pointer->create(display->getConnection(client), qMin(wl_resource_get_version(resource), s_pointerVersion), id); if (!pointer->resource()) { wl_resource_post_no_memory(resource); delete pointer; return; } pointers << pointer; if (globalPointer.focus.surface && globalPointer.focus.surface->client()->client() == client) { // this is a pointer for the currently focused pointer surface if (!globalPointer.focus.pointer) { globalPointer.focus.pointer = pointer; pointer->setFocusedSurface(globalPointer.focus.surface, globalPointer.focus.serial); emit q->focusedPointerChanged(pointer); } } QObject::connect(pointer, &QObject::destroyed, q, [pointer,this] { pointers.removeAt(pointers.indexOf(pointer)); if (globalPointer.focus.pointer == pointer) { globalPointer.focus.pointer = nullptr; emit q->focusedPointerChanged(nullptr); } } ); emit q->pointerCreated(pointer); } void SeatInterface::Private::getKeyboardCallback(wl_client *client, wl_resource *resource, uint32_t id) { cast(resource)->getKeyboard(client, resource, id); } void SeatInterface::Private::getKeyboard(wl_client *client, wl_resource *resource, uint32_t id) { // TODO: only create if seat has keyboard? KeyboardInterface *keyboard = new KeyboardInterface(q, resource); keyboard->create(display->getConnection(client), qMin(wl_resource_get_version(resource), s_keyboardVersion) , id); if (!keyboard->resource()) { wl_resource_post_no_memory(resource); delete keyboard; return; } keyboard->repeatInfo(keys.keyRepeat.charactersPerSecond, keys.keyRepeat.delay); if (keys.keymap.xkbcommonCompatible) { keyboard->setKeymap(keys.keymap.fd, keys.keymap.size); } keyboards << keyboard; if (keys.focus.surface && keys.focus.surface->client()->client() == client) { // this is a keyboard for the currently focused keyboard surface if (!keys.focus.keyboard) { keys.focus.keyboard = keyboard; keyboard->setFocusedSurface(keys.focus.surface, keys.focus.serial); } } QObject::connect(keyboard, &QObject::destroyed, q, [keyboard,this] { keyboards.removeAt(keyboards.indexOf(keyboard)); if (keys.focus.keyboard == keyboard) { keys.focus.keyboard = nullptr; } } ); emit q->keyboardCreated(keyboard); } void SeatInterface::Private::getTouchCallback(wl_client *client, wl_resource *resource, uint32_t id) { cast(resource)->getTouch(client, resource, id); } void SeatInterface::Private::getTouch(wl_client *client, wl_resource *resource, uint32_t id) { // TODO: only create if seat has touch? TouchInterface *touch = new TouchInterface(q, resource); touch->create(display->getConnection(client), qMin(wl_resource_get_version(resource), s_touchVersion), id); if (!touch->resource()) { wl_resource_post_no_memory(resource); delete touch; return; } touchs << touch; if (touchInterface.focus.surface && touchInterface.focus.surface->client()->client() == client) { // this is a touch for the currently focused touch surface if (!touchInterface.focus.touch) { touchInterface.focus.touch = touch; if (!touchInterface.ids.isEmpty()) { // TODO: send out all the points } } } QObject::connect(touch, &QObject::destroyed, q, [touch,this] { touchs.removeAt(touchs.indexOf(touch)); if (touchInterface.focus.touch == touch) { touchInterface.focus.touch = nullptr; } } ); emit q->touchCreated(touch); } QString SeatInterface::name() const { Q_D(); return d->name; } bool SeatInterface::hasPointer() const { Q_D(); return d->pointer; } bool SeatInterface::hasKeyboard() const { Q_D(); return d->keyboard; } bool SeatInterface::hasTouch() const { Q_D(); return d->touch; } SeatInterface *SeatInterface::get(wl_resource *native) { return Private::get(native); } SeatInterface::Private *SeatInterface::d_func() const { return reinterpret_cast(d.data()); } QPointF SeatInterface::pointerPos() const { Q_D(); return d->globalPointer.pos; } void SeatInterface::setPointerPos(const QPointF &pos) { Q_D(); if (d->globalPointer.pos == pos) { return; } d->globalPointer.pos = pos; emit pointerPosChanged(pos); } quint32 SeatInterface::timestamp() const { Q_D(); return d->timestamp; } void SeatInterface::setTimestamp(quint32 time) { Q_D(); if (d->timestamp == time) { return; } d->timestamp = time; emit timestampChanged(time); } +void SeatInterface::setDragTarget(SurfaceInterface *surface, const QPointF &globalPosition, const QMatrix4x4 &inputTransformation) +{ + Q_D(); + if (surface == d->drag.surface) { + // no change + return; + } + const quint32 serial = d->display->nextSerial(); + if (d->drag.target) { + d->drag.target->updateDragTarget(nullptr, serial); + } + d->drag.target = d->dataDeviceForSurface(surface); + // TODO: update touch + if (d->drag.mode == Private::Drag::Mode::Pointer) { + setPointerPos(globalPosition); + } + if (d->drag.target) { + d->drag.surface = surface; + d->drag.transformation = inputTransformation; + d->drag.target->updateDragTarget(surface, serial); + } else { + d->drag.surface = nullptr; + } + emit dragSurfaceChanged(); + return; +} + +void SeatInterface::setDragTarget(SurfaceInterface *surface, const QMatrix4x4 &inputTransformation) +{ + // TODO: handle touch + setDragTarget(surface, pointerPos(), inputTransformation); +} + SurfaceInterface *SeatInterface::focusedPointerSurface() const { Q_D(); return d->globalPointer.focus.surface; } void SeatInterface::setFocusedPointerSurface(SurfaceInterface *surface, const QPointF &surfacePosition) { QMatrix4x4 m; m.translate(-surfacePosition.x(), -surfacePosition.y()); setFocusedPointerSurface(surface, m); Q_D(); if (d->globalPointer.focus.surface) { d->globalPointer.focus.offset = surfacePosition; } } void SeatInterface::setFocusedPointerSurface(SurfaceInterface *surface, const QMatrix4x4 &transformation) { Q_D(); + if (d->drag.mode == Private::Drag::Mode::Pointer) { + // ignore + return; + } const quint32 serial = d->display->nextSerial(); if (d->globalPointer.focus.pointer) { d->globalPointer.focus.pointer->setFocusedSurface(nullptr, serial); } if (d->globalPointer.focus.surface) { disconnect(d->globalPointer.focus.destroyConnection); } d->globalPointer.focus = Private::Pointer::Focus(); d->globalPointer.focus.surface = surface; PointerInterface *p = d->pointerForSurface(surface); if (p && !p->resource()) { p = nullptr; } d->globalPointer.focus.pointer = p; if (d->globalPointer.focus.surface) { d->globalPointer.focus.destroyConnection = connect(surface, &QObject::destroyed, this, [this] { Q_D(); d->globalPointer.focus = Private::Pointer::Focus(); emit focusedPointerChanged(nullptr); } ); d->globalPointer.focus.offset = QPointF(); d->globalPointer.focus.transformation = transformation; d->globalPointer.focus.serial = serial; } emit focusedPointerChanged(p); if (!p) { return; } p->setFocusedSurface(surface, serial); } PointerInterface *SeatInterface::focusedPointer() const { Q_D(); return d->globalPointer.focus.pointer; } void SeatInterface::setFocusedPointerSurfacePosition(const QPointF &surfacePosition) { Q_D(); if (d->globalPointer.focus.surface) { d->globalPointer.focus.offset = surfacePosition; d->globalPointer.focus.transformation = QMatrix4x4(); d->globalPointer.focus.transformation.translate(-surfacePosition.x(), -surfacePosition.y()); } } QPointF SeatInterface::focusedPointerSurfacePosition() const { Q_D(); return d->globalPointer.focus.offset; } void SeatInterface::setFocusedPointerSurfaceTransformation(const QMatrix4x4 &transformation) { Q_D(); if (d->globalPointer.focus.surface) { d->globalPointer.focus.transformation = transformation; } } QMatrix4x4 SeatInterface::focusedPointerSurfaceTransformation() const { Q_D(); return d->globalPointer.focus.transformation; } namespace { static quint32 qtToWaylandButton(Qt::MouseButton button) { static const QHash s_buttons({ {Qt::LeftButton, BTN_LEFT}, {Qt::RightButton, BTN_RIGHT}, {Qt::MiddleButton, BTN_MIDDLE}, {Qt::ExtraButton1, BTN_BACK}, // note: QtWayland maps BTN_SIDE {Qt::ExtraButton2, BTN_FORWARD}, // note: QtWayland maps BTN_EXTRA {Qt::ExtraButton3, BTN_TASK}, // note: QtWayland maps BTN_FORWARD {Qt::ExtraButton4, BTN_EXTRA}, // note: QtWayland maps BTN_BACK {Qt::ExtraButton5, BTN_SIDE}, // note: QtWayland maps BTN_TASK {Qt::ExtraButton6, BTN_TASK + 1}, {Qt::ExtraButton7, BTN_TASK + 2}, {Qt::ExtraButton8, BTN_TASK + 3}, {Qt::ExtraButton9, BTN_TASK + 4}, {Qt::ExtraButton10, BTN_TASK + 5}, {Qt::ExtraButton11, BTN_TASK + 6}, {Qt::ExtraButton12, BTN_TASK + 7}, {Qt::ExtraButton13, BTN_TASK + 8} // further mapping not possible, 0x120 is BTN_JOYSTICK }); return s_buttons.value(button, 0); } } bool SeatInterface::isPointerButtonPressed(Qt::MouseButton button) const { return isPointerButtonPressed(qtToWaylandButton(button)); } bool SeatInterface::isPointerButtonPressed(quint32 button) const { Q_D(); auto it = d->globalPointer.buttonStates.constFind(button); if (it == d->globalPointer.buttonStates.constEnd()) { return false; } return it.value() == Private::Pointer::State::Pressed ? true : false; } void SeatInterface::pointerAxis(Qt::Orientation orientation, quint32 delta) { Q_D(); + if (d->drag.mode == Private::Drag::Mode::Pointer) { + // ignore + return; + } if (d->globalPointer.focus.pointer && d->globalPointer.focus.surface) { d->globalPointer.focus.pointer->axis(orientation, delta); } } void SeatInterface::pointerButtonPressed(Qt::MouseButton button) { const quint32 nativeButton = qtToWaylandButton(button); if (nativeButton == 0) { return; } pointerButtonPressed(nativeButton); } void SeatInterface::pointerButtonPressed(quint32 button) { Q_D(); const quint32 serial = d->display->nextSerial(); d->updatePointerButtonSerial(button, serial); d->updatePointerButtonState(button, Private::Pointer::State::Pressed); + if (d->drag.mode == Private::Drag::Mode::Pointer) { + // ignore + return; + } if (d->globalPointer.focus.pointer && d->globalPointer.focus.surface) { d->globalPointer.focus.pointer->buttonPressed(button, serial); } } void SeatInterface::pointerButtonReleased(Qt::MouseButton button) { const quint32 nativeButton = qtToWaylandButton(button); if (nativeButton == 0) { return; } pointerButtonReleased(nativeButton); } void SeatInterface::pointerButtonReleased(quint32 button) { Q_D(); const quint32 serial = d->display->nextSerial(); + const quint32 currentButtonSerial = pointerButtonSerial(button); d->updatePointerButtonSerial(button, serial); d->updatePointerButtonState(button, Private::Pointer::State::Released); + if (d->drag.mode == Private::Drag::Mode::Pointer) { + if (d->drag.source->dragImplicitGrabSerial() != currentButtonSerial) { + // not our drag button - ignore + return; + } + d->endDrag(serial); + return; + } if (d->globalPointer.focus.pointer && d->globalPointer.focus.surface) { d->globalPointer.focus.pointer->buttonReleased(button, serial); } } quint32 SeatInterface::pointerButtonSerial(Qt::MouseButton button) const { return pointerButtonSerial(qtToWaylandButton(button)); } quint32 SeatInterface::pointerButtonSerial(quint32 button) const { Q_D(); auto it = d->globalPointer.buttonSerials.constFind(button); if (it == d->globalPointer.buttonSerials.constEnd()) { return 0; } return it.value(); } void SeatInterface::keyPressed(quint32 key) { Q_D(); d->keys.lastStateSerial = d->display->nextSerial(); d->updateKey(key, Private::Keyboard::State::Pressed); if (d->keys.focus.keyboard && d->keys.focus.surface) { d->keys.focus.keyboard->keyPressed(key, d->keys.lastStateSerial); } } void SeatInterface::keyReleased(quint32 key) { Q_D(); d->keys.lastStateSerial = d->display->nextSerial(); d->updateKey(key, Private::Keyboard::State::Released); if (d->keys.focus.keyboard && d->keys.focus.surface) { d->keys.focus.keyboard->keyReleased(key, d->keys.lastStateSerial); } } SurfaceInterface *SeatInterface::focusedKeyboardSurface() const { Q_D(); return d->keys.focus.surface; } void SeatInterface::setFocusedKeyboardSurface(SurfaceInterface *surface) { Q_D(); const quint32 serial = d->display->nextSerial(); if (d->keys.focus.keyboard) { d->keys.focus.keyboard->setFocusedSurface(nullptr, serial); } if (d->keys.focus.surface) { disconnect(d->keys.focus.destroyConnection); } d->keys.focus = Private::Keyboard::Focus(); d->keys.focus.surface = surface; KeyboardInterface *k = d->keyboardForSurface(surface); if (k && !k->resource()) { k = nullptr; } d->keys.focus.keyboard = k; if (d->keys.focus.surface) { d->keys.focus.destroyConnection = connect(surface, &QObject::destroyed, this, [this] { Q_D(); d->keys.focus = Private::Keyboard::Focus(); } ); d->keys.focus.serial = serial; // selection? d->keys.focus.selection = d->dataDeviceForSurface(surface); if (d->keys.focus.selection) { if (d->currentSelection) { d->keys.focus.selection->sendSelection(d->currentSelection); } } } if (!k) { return; } k->setFocusedSurface(surface, serial); } void SeatInterface::setKeymap(int fd, quint32 size) { Q_D(); d->keys.keymap.xkbcommonCompatible = true; d->keys.keymap.fd = fd; d->keys.keymap.size = size; for (auto it = d->keyboards.constBegin(); it != d->keyboards.constEnd(); ++it) { (*it)->setKeymap(fd, size); } } void SeatInterface::updateKeyboardModifiers(quint32 depressed, quint32 latched, quint32 locked, quint32 group) { Q_D(); bool changed = false; #define UPDATE( value ) \ if (d->keys.modifiers.value != value) { \ d->keys.modifiers.value = value; \ changed = true; \ } UPDATE(depressed) UPDATE(latched) UPDATE(locked) UPDATE(group) if (!changed) { return; } const quint32 serial = d->display->nextSerial(); d->keys.modifiers.serial = serial; if (d->keys.focus.keyboard && d->keys.focus.surface) { d->keys.focus.keyboard->updateModifiers(depressed, latched, locked, group, serial); } } void SeatInterface::setKeyRepeatInfo(qint32 charactersPerSecond, qint32 delay) { Q_D(); d->keys.keyRepeat.charactersPerSecond = qMax(charactersPerSecond, 0); d->keys.keyRepeat.delay = qMax(delay, 0); for (auto it = d->keyboards.constBegin(); it != d->keyboards.constEnd(); ++it) { (*it)->repeatInfo(d->keys.keyRepeat.charactersPerSecond, d->keys.keyRepeat.delay); } } qint32 SeatInterface::keyRepeatDelay() const { Q_D(); return d->keys.keyRepeat.delay; } qint32 SeatInterface::keyRepeatRate() const { Q_D(); return d->keys.keyRepeat.charactersPerSecond; } bool SeatInterface::isKeymapXkbCompatible() const { Q_D(); return d->keys.keymap.xkbcommonCompatible; } int SeatInterface::keymapFileDescriptor() const { Q_D(); return d->keys.keymap.fd; } quint32 SeatInterface::keymapSize() const { Q_D(); return d->keys.keymap.size; } quint32 SeatInterface::depressedModifiers() const { Q_D(); return d->keys.modifiers.depressed; } quint32 SeatInterface::groupModifiers() const { Q_D(); return d->keys.modifiers.group; } quint32 SeatInterface::latchedModifiers() const { Q_D(); return d->keys.modifiers.latched; } quint32 SeatInterface::lockedModifiers() const { Q_D(); return d->keys.modifiers.locked; } quint32 SeatInterface::lastModifiersSerial() const { Q_D(); return d->keys.modifiers.serial; } QVector< quint32 > SeatInterface::pressedKeys() const { Q_D(); QVector keys; for (auto it = d->keys.states.begin(); it != d->keys.states.end(); ++it) { if (it.value() == Private::Keyboard::State::Pressed) { keys << it.key(); } } return keys; } KeyboardInterface *SeatInterface::focusedKeyboard() const { Q_D(); return d->keys.focus.keyboard; } void SeatInterface::cancelTouchSequence() { Q_D(); if (d->touchInterface.focus.touch) { d->touchInterface.focus.touch->cancel(); } d->touchInterface.ids.clear(); } TouchInterface *SeatInterface::focusedTouch() const { Q_D(); return d->touchInterface.focus.touch; } SurfaceInterface *SeatInterface::focusedTouchSurface() const { Q_D(); return d->touchInterface.focus.surface; } QPointF SeatInterface::focusedTouchSurfacePosition() const { Q_D(); return d->touchInterface.focus.offset; } bool SeatInterface::isTouchSequence() const { Q_D(); return !d->touchInterface.ids.isEmpty(); } void SeatInterface::setFocusedTouchSurface(SurfaceInterface *surface, const QPointF &surfacePosition) { if (isTouchSequence()) { // changing surface not allowed during a touch sequence return; } Q_D(); if (d->touchInterface.focus.surface) { disconnect(d->touchInterface.focus.destroyConnection); } d->touchInterface.focus = Private::Touch::Focus(); d->touchInterface.focus.surface = surface; d->touchInterface.focus.offset = surfacePosition; TouchInterface *t = d->touchForSurface(surface); if (t && !t->resource()) { t = nullptr; } d->touchInterface.focus.touch = t; if (d->touchInterface.focus.surface) { d->touchInterface.focus.destroyConnection = connect(surface, &QObject::destroyed, this, [this] { Q_D(); if (isTouchSequence() && d->touchInterface.focus.touch) { // Surface destroyed during touch sequence - send a cancel d->touchInterface.focus.touch->cancel(); } d->touchInterface.focus = Private::Touch::Focus(); } ); } } void SeatInterface::setFocusedTouchSurfacePosition(const QPointF &surfacePosition) { Q_D(); d->touchInterface.focus.offset = surfacePosition; } qint32 SeatInterface::touchDown(const QPointF &globalPosition) { Q_D(); const qint32 id = d->touchInterface.ids.isEmpty() ? 0 : d->touchInterface.ids.last() + 1; const quint32 serial = display()->nextSerial(); if (d->touchInterface.focus.touch && d->touchInterface.focus.surface) { d->touchInterface.focus.touch->down(id, serial, globalPosition - d->touchInterface.focus.offset); } else if (id == 0 && focusedTouchSurface()) { auto p = d->pointerForSurface(focusedTouchSurface()); if (!p) { return id; } const QPointF pos = globalPosition - d->touchInterface.focus.offset; wl_pointer_send_enter(p->resource(), serial, focusedTouchSurface()->resource(), wl_fixed_from_double(pos.x()), wl_fixed_from_double(pos.y())); wl_pointer_send_motion(p->resource(), timestamp(), wl_fixed_from_double(pos.x()), wl_fixed_from_double(pos.y())); wl_pointer_send_button(p->resource(), serial, timestamp(), BTN_LEFT, WL_POINTER_BUTTON_STATE_PRESSED); } d->touchInterface.ids << id; return id; } void SeatInterface::touchMove(qint32 id, const QPointF &globalPosition) { Q_D(); if (d->touchInterface.focus.touch && d->touchInterface.focus.surface) { d->touchInterface.focus.touch->move(id, globalPosition - d->touchInterface.focus.offset); } else if (id == 0 && focusedTouchSurface()) { auto p = d->pointerForSurface(focusedTouchSurface()); if (!p) { return; } const QPointF pos = globalPosition - d->touchInterface.focus.offset; wl_pointer_send_motion(p->resource(), timestamp(), wl_fixed_from_double(pos.x()), wl_fixed_from_double(pos.y())); } } void SeatInterface::touchUp(qint32 id) { Q_D(); Q_ASSERT(d->touchInterface.ids.contains(id)); if (d->touchInterface.focus.touch && d->touchInterface.focus.surface) { d->touchInterface.focus.touch->up(id, display()->nextSerial()); } else if (id == 0 && focusedTouchSurface()) { const quint32 serial = display()->nextSerial(); auto p = d->pointerForSurface(focusedTouchSurface()); if (!p) { return; } wl_pointer_send_button(p->resource(), serial, timestamp(), BTN_LEFT, WL_POINTER_BUTTON_STATE_RELEASED); } d->touchInterface.ids.removeAll(id); } void SeatInterface::touchFrame() { Q_D(); if (d->touchInterface.focus.touch && d->touchInterface.focus.surface) { d->touchInterface.focus.touch->frame(); } } +bool SeatInterface::isDrag() const +{ + Q_D(); + return d->drag.mode != Private::Drag::Mode::None; +} + +bool SeatInterface::isDragPointer() const +{ + Q_D(); + return d->drag.mode == Private::Drag::Mode::Pointer; +} + +bool SeatInterface::isDragTouch() const +{ + Q_D(); + return d->drag.mode == Private::Drag::Mode::Touch; +} + +bool SeatInterface::hasImplicitPointerGrab(quint32 serial) const +{ + Q_D(); + const auto &serials = d->globalPointer.buttonSerials; + for (auto it = serials.begin(), end = serials.end(); it != end; it++) { + if (it.value() == serial) { + return isPointerButtonPressed(it.key()); + } + } + return false; +} + +QMatrix4x4 SeatInterface::dragSurfaceTransformation() const +{ + Q_D(); + return d->drag.transformation; +} + +SurfaceInterface *SeatInterface::dragSurface() const +{ + Q_D(); + return d->drag.surface; +} + +PointerInterface *SeatInterface::dragPointer() const +{ + Q_D(); + if (d->drag.mode != Private::Drag::Mode::Pointer) { + return nullptr; + } + + return d->drag.sourcePointer; +} + +DataDeviceInterface *SeatInterface::dragSource() const +{ + Q_D(); + return d->drag.source; +} + } } diff --git a/src/server/seat_interface.h b/src/server/seat_interface.h index 9326b9f..f2574a0 100644 --- a/src/server/seat_interface.h +++ b/src/server/seat_interface.h @@ -1,396 +1,491 @@ /******************************************************************** Copyright 2014 Martin Gräßlin 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 . *********************************************************************/ #ifndef WAYLAND_SERVER_SEAT_INTERFACE_H #define WAYLAND_SERVER_SEAT_INTERFACE_H #include #include #include #include #include "global.h" #include "keyboard_interface.h" #include "pointer_interface.h" #include "touch_interface.h" struct wl_client; struct wl_resource; namespace KWayland { namespace Server { +class DataDeviceInterface; class Display; class SurfaceInterface; /** * @brief Represents a Seat on the Wayland Display. * * A Seat is a set of input devices (e.g. Keyboard, Pointer and Touch) the client can connect * to. The server needs to announce which input devices are supported and passes dedicated input * focus to a SurfaceInterface. Only the focused surface receives input events. * * The SeatInterface internally handles enter and release events when setting a focused surface. * Also it handles input translation from global to the local coordination, removing the need from * the user of the API to track the focused surfaces and can just interact with this class. * * To create a SeatInterface use @link Display::createSeat @endlink. Then one can set up what is * supported. Last but not least create needs to be called. * * @code * SeatInterface *seat = display->createSeat(); * // set up * seat->setName(QStringLiteral("seat0")); * seat->setHasPointer(true); * seat->setHasKeyboard(true); * seat->setHasTouch(false); * // now fully create * seat->create(); * @endcode * * To forward input events one needs to set the focused surface, update time stamp and then * forward the actual events: * * @code * // example for pointer * seat->setFocusedPointerSurface(surface, QPointF(100, 200)); // surface at it's global position * seat->setTimestamp(100); * seat->setPointerPos(QPointF(350, 210)); // global pos, local pos in surface: 250,10 * seat->setTimestamp(110); * seat->pointerButtonPressed(Qt::LeftButton); * seat->setTimestamp(120); * seat->pointerButtonReleased(Qt::LeftButton); * @endcode * * @see KeyboardInterface * @see PointerInterface * @see TouchInterface * @see SurfaceInterface **/ class KWAYLANDSERVER_EXPORT SeatInterface : public Global { Q_OBJECT /** * The name of the Seat **/ Q_PROPERTY(QString name READ name WRITE setName NOTIFY nameChanged) /** * Whether the SeatInterface supports a pointer device. **/ Q_PROPERTY(bool pointer READ hasPointer WRITE setHasPointer NOTIFY hasPointerChanged) /** * Whether the SeatInterface supports a keyboard device. **/ Q_PROPERTY(bool keyboard READ hasKeyboard WRITE setHasKeyboard NOTIFY hasKeyboardChanged) /** * Whether the SeatInterface supports a touch device. * @deprecated use touch **/ Q_PROPERTY(bool tourch READ hasTouch WRITE setHasTouch NOTIFY hasTouchChanged) /** * Whether the SeatInterface supports a touch device. **/ Q_PROPERTY(bool touch READ hasTouch WRITE setHasTouch NOTIFY hasTouchChanged) /** * The global pointer position. **/ Q_PROPERTY(QPointF pointerPos READ pointerPos WRITE setPointerPos NOTIFY pointerPosChanged) /** * The current timestamp passed to the input events. **/ Q_PROPERTY(quint32 timestamp READ timestamp WRITE setTimestamp NOTIFY timestampChanged) public: virtual ~SeatInterface(); QString name() const; bool hasPointer() const; bool hasKeyboard() const; bool hasTouch() const; void setName(const QString &name); void setHasPointer(bool has); void setHasKeyboard(bool has); void setHasTouch(bool has); void setTimestamp(quint32 time); quint32 timestamp() const; + /** + * @name Drag'n'Drop related methods + **/ + ///@{ + /** + * @returns whether there is currently a drag'n'drop going on. + * @since 5.6 + * @see isDragPointer + * @see isDragTouch + * @see dragStarted + * @see dragEnded + **/ + bool isDrag() const; + /** + * @returns whether the drag'n'drop is operated through the pointer device + * @since 5.6 + * @see isDrag + * @see isDragTouch + **/ + bool isDragPointer() const; + /** + * @returns whether the drag'n'drop is operated through the touch device + * @since 5.6 + * @see isDrag + * @see isDragPointer + **/ + bool isDragTouch() const; + /** + * @returns The transformation applied to go from global to local coordinates for drag motion events. + * @see dragSurfaceTransformation + * @since 5.6 + **/ + QMatrix4x4 dragSurfaceTransformation() const; + /** + * @returns The currently focused Surface for drag motion events. + * @since 5.6 + * @see dragSurfaceTransformation + * @see dragSurfaceChanged + **/ + SurfaceInterface *dragSurface() const; + /** + * @returns The PointerInterface which triggered the drag operation + * @since 5.6 + * @see isDragPointer + **/ + PointerInterface *dragPointer() const; + /** + * @returns The DataDeviceInterface which started the drag and drop operation. + * @see isDrag + * @since 5.6 + **/ + DataDeviceInterface *dragSource() const; + /** + * Sets the current drag target to @p surface. + * + * Sends a drag leave event to the current target and an enter event to @p surface. + * The enter position is derived from @p globalPosition and transformed by @p inputTransformation. + * @since 5.6 + **/ + void setDragTarget(SurfaceInterface *surface, const QPointF &globalPosition, const QMatrix4x4 &inputTransformation); + /** + * Sets the current drag target to @p surface. + * + * Sends a drag leave event to the current target and an enter event to @p surface. + * The enter position is derived from current global position and transformed by @p inputTransformation. + * @since 5.6 + **/ + void setDragTarget(SurfaceInterface *surface, const QMatrix4x4 &inputTransformation = QMatrix4x4()); + ///@} + /** * @name Pointer related methods **/ ///@{ /** * Updates the global pointer @p pos. * * Sends a pointer motion event to the focused pointer surface. **/ void setPointerPos(const QPointF &pos); /** * @returns the global pointer position **/ QPointF pointerPos() const; /** * Sets the focused pointer @p surface. * All pointer events will be sent to the @p surface till a new focused pointer surface gets * installed. When the focus pointer surface changes a leave event is sent to the previous * focused surface. * * To unset the focused pointer surface pass @c nullptr as @p surface. * * Pointer motion events are adjusted to the local position based on the @p surfacePosition. * If the surface changes it's position in the global coordinate system * use setFocusedPointerSurfacePosition to update. * The surface position is used to create the base transformation matrix to go from global * to surface local coordinates. The default generated matrix is a translation with * negative @p surfacePosition. * * @param surface The surface which should become the new focused pointer surface. * @param surfacePosition The position of the surface in the global coordinate system * * @see setPointerPos * @see focucedPointerSurface * @see focusedPointer * @see setFocusedPointerSurfacePosition * @see focusedPointerSurfacePosition * @see setFocusedPointerSurfaceTransformation * @see focusedPointerSurfaceTransformation **/ void setFocusedPointerSurface(SurfaceInterface *surface, const QPointF &surfacePosition = QPoint()); /** * Sets the focused pointer @p surface. * All pointer events will be sent to the @p surface till a new focused pointer surface gets * installed. When the focus pointer surface changes a leave event is sent to the previous * focused surface. * * To unset the focused pointer surface pass @c nullptr as @p surface. * * Pointer motion events are adjusted to the local position based on the @p transformation. * If the surface changes it's position in the global coordinate system * use setFocusedPointerSurfaceTransformation to update. * * @param surface The surface which should become the new focused pointer surface. * @param transformation The transformation to transform global into local coordinates * * @see setPointerPos * @see focucedPointerSurface * @see focusedPointer * @see setFocusedPointerSurfacePosition * @see focusedPointerSurfacePosition * @see setFocusedPointerSurfaceTransformation * @see focusedPointerSurfaceTransformation * @since 5.6 **/ void setFocusedPointerSurface(SurfaceInterface *surface, const QMatrix4x4 &transformation); /** * @returns The currently focused pointer surface, that is the surface receiving pointer events. * @see setFocusedPointerSurface **/ SurfaceInterface *focusedPointerSurface() const; /** * @returns The PointerInterface belonging to the focused pointer surface, if any. * @see setFocusedPointerSurface **/ PointerInterface *focusedPointer() const; /** * Updates the global position of the currently focused pointer surface. * * Updating the focused surface position also generates a new transformation matrix. * The default generated matrix is a translation with negative @p surfacePosition. * If a different transformation is required a dedicated call to * @link setFocusedPointerSurfaceTransformation is required. * * @param surfacePosition The new global position of the focused pointer surface * @see focusedPointerSurface * @see setFocusedPointerSurface * @see focusedPointerSurfaceTransformation * @see setFocusedPointerSurfaceTransformation **/ void setFocusedPointerSurfacePosition(const QPointF &surfacePosition); /** * @returns The position of the focused pointer surface in global coordinates. * @see setFocusedPointerSurfacePosition * @see setFocusedPointerSurface * @see focusedPointerSurfaceTransformation **/ QPointF focusedPointerSurfacePosition() const; /** * Sets the @p transformation for going from global to local coordinates. * * The default transformation gets generated from the surface position and reset whenever * the surface position changes. * * @see focusedPointerSurfaceTransformation * @see focusedPointerSurfacePosition * @see setFocusedPointerSurfacePosition * @since 5.6 **/ void setFocusedPointerSurfaceTransformation(const QMatrix4x4 &transformation); /** * @returns The transformation applied to pointer position to go from global to local coordinates. * @see setFocusedPointerSurfaceTransformation * @since 5.6 **/ QMatrix4x4 focusedPointerSurfaceTransformation() const; /** * Marks the @p button as pressed. * * If there is a focused pointer surface a button pressed event is sent to it. * * @param button The Linux button code **/ void pointerButtonPressed(quint32 button); /** * @overload **/ void pointerButtonPressed(Qt::MouseButton button); /** * Marks the @p button as released. * * If there is a focused pointer surface a button release event is sent to it. * * @param button The Linux button code **/ void pointerButtonReleased(quint32 button); /** * @overload **/ void pointerButtonReleased(Qt::MouseButton button); /** * @returns whether the @p button is pressed **/ bool isPointerButtonPressed(quint32 button) const; /** * @returns whether the @p button is pressed **/ bool isPointerButtonPressed(Qt::MouseButton button) const; /** * @returns the last serial for @p button. **/ quint32 pointerButtonSerial(quint32 button) const; /** * @returns the last serial for @p button. **/ quint32 pointerButtonSerial(Qt::MouseButton button) const; void pointerAxis(Qt::Orientation orientation, quint32 delta); + /** + * @returns true if there is a pressed button with the given @p serial + * @since 5.6 + **/ + bool hasImplicitPointerGrab(quint32 serial) const; ///@} /** * @name keyboard related methods **/ ///@{ void setKeymap(int fd, quint32 size); void keyPressed(quint32 key); void keyReleased(quint32 key); void updateKeyboardModifiers(quint32 depressed, quint32 latched, quint32 locked, quint32 group); /** * Sets the key repeat information to be forwarded to all bound keyboards. * * To disable key repeat set a @p charactersPerSecond of @c 0. * * Requires wl_seat version 4. * * @param charactersPerSecond The characters per second rate, value of @c 0 disables key repeating * @param delay The delay on key press before starting repeating keys * * @since 5.5 ***/ void setKeyRepeatInfo(qint32 charactersPerSecond, qint32 delay); quint32 depressedModifiers() const; quint32 latchedModifiers() const; quint32 lockedModifiers() const; quint32 groupModifiers() const; quint32 lastModifiersSerial() const; int keymapFileDescriptor() const; quint32 keymapSize() const; bool isKeymapXkbCompatible() const; QVector pressedKeys() const; /** * @returns The key repeat in character per second * @since 5.5 * @see setKeyRepeatInfo * @see keyRepeatDelay **/ qint32 keyRepeatRate() const; /** * @returns The delay on key press before starting repeating keys * @since 5.5 * @see keyRepeatRate * @see setKeyRepeatInfo **/ qint32 keyRepeatDelay() const; void setFocusedKeyboardSurface(SurfaceInterface *surface); SurfaceInterface *focusedKeyboardSurface() const; KeyboardInterface *focusedKeyboard() const; ///@} /** * @name touch related methods **/ ///@{ void setFocusedTouchSurface(SurfaceInterface *surface, const QPointF &surfacePosition = QPointF()); SurfaceInterface *focusedTouchSurface() const; TouchInterface *focusedTouch() const; void setFocusedTouchSurfacePosition(const QPointF &surfacePosition); QPointF focusedTouchSurfacePosition() const; qint32 touchDown(const QPointF &globalPosition); void touchUp(qint32 id); void touchMove(qint32 id, const QPointF &globalPosition); void touchFrame(); void cancelTouchSequence(); bool isTouchSequence() const; ///@} static SeatInterface *get(wl_resource *native); Q_SIGNALS: void nameChanged(const QString&); void hasPointerChanged(bool); void hasKeyboardChanged(bool); void hasTouchChanged(bool); void pointerPosChanged(const QPointF &pos); void timestampChanged(quint32); void pointerCreated(KWayland::Server::PointerInterface*); void keyboardCreated(KWayland::Server::KeyboardInterface*); void touchCreated(KWayland::Server::TouchInterface*); /** * Emitted whenever the focused pointer changes * @since 5.6 **/ void focusedPointerChanged(KWayland::Server::PointerInterface*); + /** + * Emitted when a drag'n'drop operation is started + * @since 5.6 + * @see dragEnded + **/ + void dragStarted(); + /** + * Emitted when a drag'n'drop operation ended, either by dropping or canceling. + * @since 5.6 + * @see dragStarted + **/ + void dragEnded(); + /** + * Emitted whenever the drag surface for motion events changed. + * @since 5.6 + * @see dragSurface + **/ + void dragSurfaceChanged(); + private: friend class Display; friend class DataDeviceManagerInterface; explicit SeatInterface(Display *display, QObject *parent); class Private; Private *d_func() const; }; } } Q_DECLARE_METATYPE(KWayland::Server::SeatInterface*) #endif diff --git a/src/server/seat_interface_p.h b/src/server/seat_interface_p.h index af1eabd..4a4ddd3 100644 --- a/src/server/seat_interface_p.h +++ b/src/server/seat_interface_p.h @@ -1,165 +1,182 @@ /******************************************************************** Copyright 2014 Martin Gräßlin 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 . *********************************************************************/ #ifndef WAYLAND_SERVER_SEAT_INTERFACE_P_H #define WAYLAND_SERVER_SEAT_INTERFACE_P_H // KWayland #include "seat_interface.h" #include "global_p.h" // Qt #include #include // Wayland #include namespace KWayland { namespace Server { class DataDeviceInterface; class SeatInterface::Private : public Global::Private { public: Private(SeatInterface *q, Display *d); void bind(wl_client *client, uint32_t version, uint32_t id) override; void sendCapabilities(wl_resource *r); void sendName(wl_resource *r); PointerInterface *pointerForSurface(SurfaceInterface *surface) const; KeyboardInterface *keyboardForSurface(SurfaceInterface *surface) const; TouchInterface *touchForSurface(SurfaceInterface *surface) const; DataDeviceInterface *dataDeviceForSurface(SurfaceInterface *surface) const; void registerDataDevice(DataDeviceInterface *dataDevice); + void endDrag(quint32 serial); QString name; bool pointer = false; bool keyboard = false; bool touch = false; QList resources; quint32 timestamp = 0; QVector pointers; QVector keyboards; QVector touchs; QVector dataDevices; DataDeviceInterface *currentSelection = nullptr; // Pointer related members struct Pointer { enum class State { Released, Pressed }; QHash buttonSerials; QHash buttonStates; QPointF pos; struct Focus { SurfaceInterface *surface = nullptr; PointerInterface *pointer = nullptr; QMetaObject::Connection destroyConnection; QPointF offset = QPointF(); QMatrix4x4 transformation; quint32 serial = 0; }; Focus focus; }; Pointer globalPointer; void updatePointerButtonSerial(quint32 button, quint32 serial); void updatePointerButtonState(quint32 button, Pointer::State state); // Keyboard related members struct Keyboard { enum class State { Released, Pressed }; QHash states; struct Keymap { int fd = -1; quint32 size = 0; bool xkbcommonCompatible = false; }; Keymap keymap; struct Modifiers { quint32 depressed = 0; quint32 latched = 0; quint32 locked = 0; quint32 group = 0; quint32 serial = 0; }; Modifiers modifiers; struct Focus { SurfaceInterface *surface = nullptr; KeyboardInterface *keyboard = nullptr; QMetaObject::Connection destroyConnection; quint32 serial = 0; DataDeviceInterface *selection = nullptr; }; Focus focus; quint32 lastStateSerial = 0; struct { qint32 charactersPerSecond = 0; qint32 delay = 0; } keyRepeat; }; Keyboard keys; void updateKey(quint32 key, Keyboard::State state); struct Touch { struct Focus { SurfaceInterface *surface = nullptr; TouchInterface *touch = nullptr; QMetaObject::Connection destroyConnection; QPointF offset = QPointF(); }; Focus focus; QVector ids; }; Touch touchInterface; + struct Drag { + enum class Mode { + None, + Pointer, + Touch + }; + Mode mode = Mode::None; + DataDeviceInterface *source = nullptr; + DataDeviceInterface *target = nullptr; + SurfaceInterface *surface = nullptr; + PointerInterface *sourcePointer = nullptr; + QMatrix4x4 transformation; + QMetaObject::Connection destroyConnection; + }; + Drag drag; + static SeatInterface *get(wl_resource *native) { auto s = cast(native); return s ? s->q : nullptr; } private: void getPointer(wl_client *client, wl_resource *resource, uint32_t id); void getKeyboard(wl_client *client, wl_resource *resource, uint32_t id); void getTouch(wl_client *client, wl_resource *resource, uint32_t id); void updateSelection(DataDeviceInterface *dataDevice, bool set); static Private *cast(wl_resource *r); static void unbind(wl_resource *r); // interface static void getPointerCallback(wl_client *client, wl_resource *resource, uint32_t id); static void getKeyboardCallback(wl_client *client, wl_resource *resource, uint32_t id); static void getTouchCallback(wl_client *client, wl_resource *resource, uint32_t id); static const struct wl_seat_interface s_interface; static const quint32 s_version; static const qint32 s_pointerVersion; static const qint32 s_touchVersion; static const qint32 s_keyboardVersion; SeatInterface *q; }; } } #endif