From 972d1150ee794eac3920df3e0fc611315ad8daf4 Mon Sep 17 00:00:00 2001 From: Johan Klokkhammer Helsing Date: Fri, 29 Jul 2016 15:54:08 +0200 Subject: Also test touch in client events test Following the same pattern as for mouse and keyboard, also test touch events. Change-Id: Ie84aa0ffe0b0f4f66e9f40207c63d94e32f6dbaf Reviewed-by: Paul Olav Tvete --- tests/auto/client/mockcompositor.cpp | 29 +++++++++++ tests/auto/client/mockcompositor.h | 10 ++++ tests/auto/client/mockinput.cpp | 95 +++++++++++++++++++++++++++++++++++- tests/auto/client/mockinput.h | 15 ++++++ tests/auto/client/tst_client.cpp | 16 ++++++ 5 files changed, 164 insertions(+), 1 deletion(-) diff --git a/tests/auto/client/mockcompositor.cpp b/tests/auto/client/mockcompositor.cpp index 2f73734f1..682452262 100644 --- a/tests/auto/client/mockcompositor.cpp +++ b/tests/auto/client/mockcompositor.cpp @@ -122,6 +122,34 @@ void MockCompositor::sendKeyRelease(const QSharedPointer &surface, processCommand(command); } +void MockCompositor::sendTouchDown(const QSharedPointer &surface, const QPoint &position, int id) +{ + Command command = makeCommand(Impl::Compositor::sendTouchDown, m_compositor); + command.parameters << QVariant::fromValue(surface) << position << id; + processCommand(command); +} + +void MockCompositor::sendTouchMotion(const QSharedPointer &surface, const QPoint &position, int id) +{ + Command command = makeCommand(Impl::Compositor::sendTouchMotion, m_compositor); + command.parameters << QVariant::fromValue(surface) << position << id; + processCommand(command); +} + +void MockCompositor::sendTouchUp(const QSharedPointer &surface, int id) +{ + Command command = makeCommand(Impl::Compositor::sendTouchUp, m_compositor); + command.parameters << QVariant::fromValue(surface) << id; + processCommand(command); +} + +void MockCompositor::sendTouchFrame(const QSharedPointer &surface) +{ + Command command = makeCommand(Impl::Compositor::sendTouchFrame, m_compositor); + command.parameters << QVariant::fromValue(surface); + processCommand(command); +} + QSharedPointer MockCompositor::surface() { QSharedPointer result; @@ -208,6 +236,7 @@ Compositor::Compositor() m_seat.reset(new Seat(this, m_display)); m_pointer = m_seat->pointer(); m_keyboard = m_seat->keyboard(); + m_touch = m_seat->touch(); wl_display_add_global(m_display, &wl_output_interface, this, bindOutput); wl_display_add_global(m_display, &wl_shell_interface, this, bindShell); diff --git a/tests/auto/client/mockcompositor.h b/tests/auto/client/mockcompositor.h index cf3b270a2..8731949c0 100644 --- a/tests/auto/client/mockcompositor.h +++ b/tests/auto/client/mockcompositor.h @@ -52,6 +52,7 @@ typedef void (**Implementation)(void); class Keyboard; class Pointer; +class Touch; class Seat; class DataDeviceManager; class Surface; @@ -80,6 +81,10 @@ public: static void sendMouseRelease(void *data, const QList ¶meters); static void sendKeyPress(void *data, const QList ¶meters); static void sendKeyRelease(void *data, const QList ¶meters); + static void sendTouchDown(void *data, const QList ¶meters); + static void sendTouchUp(void *data, const QList ¶meters); + static void sendTouchMotion(void *data, const QList ¶meters); + static void sendTouchFrame(void *data, const QList ¶meters); private: static void bindCompositor(wl_client *client, void *data, uint32_t version, uint32_t id); @@ -104,6 +109,7 @@ private: QScopedPointer m_seat; Pointer *m_pointer; Keyboard *m_keyboard; + Touch *m_touch; QScopedPointer m_data_device_manager; QVector m_surfaces; }; @@ -146,6 +152,10 @@ public: void sendMouseRelease(const QSharedPointer &surface); void sendKeyPress(const QSharedPointer &surface, uint code); void sendKeyRelease(const QSharedPointer &surface, uint code); + void sendTouchDown(const QSharedPointer &surface, const QPoint &position, int id); + void sendTouchMotion(const QSharedPointer &surface, const QPoint &position, int id); + void sendTouchUp(const QSharedPointer &surface, int id); + void sendTouchFrame(const QSharedPointer &surface); QSharedPointer surface(); diff --git a/tests/auto/client/mockinput.cpp b/tests/auto/client/mockinput.cpp index 5b1d4f4fd..dd0512e76 100644 --- a/tests/auto/client/mockinput.cpp +++ b/tests/auto/client/mockinput.cpp @@ -92,11 +92,64 @@ void Compositor::sendKeyRelease(void *data, const QList ¶meters) compositor->m_keyboard->sendKey(parameters.last().toUInt() - 8, 0); } +void Compositor::sendTouchDown(void *data, const QList ¶meters) +{ + Compositor *compositor = static_cast(data); + Surface *surface = resolveSurface(parameters.first()); + + Q_ASSERT(compositor); + Q_ASSERT(surface); + + QPoint position = parameters.at(1).toPoint(); + int id = parameters.at(2).toInt(); + + compositor->m_touch->sendDown(surface, position, id); +} + +void Compositor::sendTouchUp(void *data, const QList ¶meters) +{ + Compositor *compositor = static_cast(data); + Surface *surface = resolveSurface(parameters.first()); + + Q_ASSERT(compositor); + Q_ASSERT(surface); + + int id = parameters.at(1).toInt(); + + compositor->m_touch->sendUp(surface, id); +} + +void Compositor::sendTouchMotion(void *data, const QList ¶meters) +{ + Compositor *compositor = static_cast(data); + Surface *surface = resolveSurface(parameters.first()); + + Q_ASSERT(compositor); + Q_ASSERT(surface); + + QPoint position = parameters.at(1).toPoint(); + int id = parameters.at(2).toInt(); + + compositor->m_touch->sendMotion(surface, position, id); +} + +void Compositor::sendTouchFrame(void *data, const QList ¶meters) +{ + Compositor *compositor = static_cast(data); + Surface *surface = resolveSurface(parameters.first()); + + Q_ASSERT(compositor); + Q_ASSERT(surface); + + compositor->m_touch->sendFrame(surface); +} + Seat::Seat(Compositor *compositor, struct ::wl_display *display) : wl_seat(display, 2) , m_compositor(compositor) , m_keyboard(new Keyboard(compositor)) , m_pointer(new Pointer(compositor)) + , m_touch(new Touch(compositor)) { } @@ -106,7 +159,7 @@ Seat::~Seat() void Seat::seat_bind_resource(Resource *resource) { - send_capabilities(resource->handle, capability_keyboard | capability_pointer); + send_capabilities(resource->handle, capability_keyboard | capability_pointer | capability_touch); } void Seat::seat_get_keyboard(Resource *resource, uint32_t id) @@ -119,6 +172,11 @@ void Seat::seat_get_pointer(Resource *resource, uint32_t id) m_pointer->add(resource->client(), id, resource->version()); } +void Seat::seat_get_touch(Resource *resource, uint32_t id) +{ + m_touch->add(resource->client(), id, resource->version()); +} + Keyboard::Keyboard(Compositor *compositor) : wl_keyboard() , m_compositor(compositor) @@ -219,6 +277,41 @@ void Pointer::pointer_destroy_resource(wl_pointer::Resource *resource) m_focusResource = 0; } +Touch::Touch(Compositor *compositor) + : wl_touch() + , m_compositor(compositor) +{ +} + +void Touch::sendDown(Surface *surface, const QPoint &position, int id) +{ + uint32_t serial = m_compositor->nextSerial(); + uint32_t time = m_compositor->time(); + Q_ASSERT(surface); + Resource *resource = resourceMap().value(surface->resource()->client()); + Q_ASSERT(resource); + wl_touch_send_down(resource->handle, serial, time, surface->resource()->handle, id, position.x(), position.y()); +} + +void Touch::sendUp(Surface *surface, int id) +{ + Resource *resource = resourceMap().value(surface->resource()->client()); + wl_touch_send_up(resource->handle, m_compositor->nextSerial(), m_compositor->time(), id); +} + +void Touch::sendMotion(Surface *surface, const QPoint &position, int id) +{ + Resource *resource = resourceMap().value(surface->resource()->client()); + uint32_t time = m_compositor->time(); + wl_touch_send_motion(resource->handle, time, id, position.x(), position.y()); +} + +void Touch::sendFrame(Surface *surface) +{ + Resource *resource = resourceMap().value(surface->resource()->client()); + wl_touch_send_frame(resource->handle); +} + DataDevice::DataDevice(Compositor *compositor) : wl_data_device() , m_compositor(compositor) diff --git a/tests/auto/client/mockinput.h b/tests/auto/client/mockinput.h index 7d36a5325..61c507077 100644 --- a/tests/auto/client/mockinput.h +++ b/tests/auto/client/mockinput.h @@ -56,17 +56,20 @@ public: Keyboard *keyboard() const { return m_keyboard.data(); } Pointer *pointer() const { return m_pointer.data(); } + Touch *touch() const { return m_touch.data(); } protected: void seat_bind_resource(Resource *resource) Q_DECL_OVERRIDE; void seat_get_keyboard(Resource *resource, uint32_t id) Q_DECL_OVERRIDE; void seat_get_pointer(Resource *resource, uint32_t id) Q_DECL_OVERRIDE; + void seat_get_touch(Resource *resource, uint32_t id) Q_DECL_OVERRIDE; private: Compositor *m_compositor; QScopedPointer m_keyboard; QScopedPointer m_pointer; + QScopedPointer m_touch; }; class Keyboard : public QtWaylandServer::wl_keyboard @@ -112,6 +115,18 @@ private: Surface *m_focus; }; +class Touch : public QtWaylandServer::wl_touch +{ +public: + Touch(Compositor *compositor); + void sendDown(Surface *surface, const QPoint &position, int id); + void sendUp(Surface *surface, int id); + void sendMotion(Surface *surface, const QPoint &position, int id); + void sendFrame(Surface *surface); +private: + Compositor *m_compositor; +}; + class DataDevice : public QtWaylandServer::wl_data_device { public: diff --git a/tests/auto/client/tst_client.cpp b/tests/auto/client/tst_client.cpp index dd35b681c..3fde258d1 100644 --- a/tests/auto/client/tst_client.cpp +++ b/tests/auto/client/tst_client.cpp @@ -51,6 +51,7 @@ public: , keyReleaseEventCount(0) , mousePressEventCount(0) , mouseReleaseEventCount(0) + , touchEventCount(0) , keyCode(0) { setSurfaceType(QSurface::RasterSurface); @@ -91,12 +92,18 @@ public: ++mouseReleaseEventCount; } + void touchEvent(QTouchEvent *event) Q_DECL_OVERRIDE + { + ++touchEventCount; + } + int focusInEventCount; int focusOutEventCount; int keyPressEventCount; int keyReleaseEventCount; int mousePressEventCount; int mouseReleaseEventCount; + int touchEventCount; uint keyCode; QPoint mousePressPos; @@ -197,6 +204,15 @@ void tst_WaylandClient::events() QCOMPARE(window.mouseReleaseEventCount, 0); compositor->sendMouseRelease(surface); QTRY_COMPARE(window.mouseReleaseEventCount, 1); + + const int touchId = 0; + compositor->sendTouchDown(surface, QPoint(10, 10), touchId); + compositor->sendTouchFrame(surface); + QTRY_COMPARE(window.touchEventCount, 1); + + compositor->sendTouchUp(surface, touchId); + compositor->sendTouchFrame(surface); + QTRY_COMPARE(window.touchEventCount, 2); } void tst_WaylandClient::backingStore() -- cgit v1.2.3 From aefdb7652085afbd84d089d86dfc7d7e642a097d Mon Sep 17 00:00:00 2001 From: Johan Klokkhammer Helsing Date: Fri, 29 Jul 2016 15:46:52 +0200 Subject: Remove logging of drag-and-drop data Change-Id: Ic66faf02f7d4eb82aa898a2858a0271a007460a0 Reviewed-by: Pier Luigi Fiorini --- src/client/qwaylanddatadevice.cpp | 4 ---- 1 file changed, 4 deletions(-) diff --git a/src/client/qwaylanddatadevice.cpp b/src/client/qwaylanddatadevice.cpp index d1c755e37..8130578b5 100644 --- a/src/client/qwaylanddatadevice.cpp +++ b/src/client/qwaylanddatadevice.cpp @@ -55,8 +55,6 @@ #include #include -#include - QT_BEGIN_NAMESPACE namespace QtWaylandClient { @@ -128,8 +126,6 @@ void QWaylandDataDevice::data_device_drop() { QDrag *drag = static_cast(QGuiApplicationPrivate::platformIntegration()->drag())->currentDrag(); - qDebug() << Q_FUNC_INFO << drag << m_dragOffer.data(); - QMimeData *dragData = 0; Qt::DropActions supportedActions; if (drag) { -- cgit v1.2.3 From 798127e5c9a107ddd8cc1c04495ce39b64513bdb Mon Sep 17 00:00:00 2001 From: Johan Klokkhammer Helsing Date: Fri, 29 Jul 2016 15:46:25 +0200 Subject: Client tests: Unlock mutex while processing compositor commands Only lock the client autotest compositor mutex when necessary. This allows compositor commands to be queued while a command is being processed. Change-Id: Ib2ca6b4942f57f56f56a055cbe6ce6d876695529 Reviewed-by: Paul Olav Tvete --- tests/auto/client/mockcompositor.cpp | 18 ++++++++++++++---- 1 file changed, 14 insertions(+), 4 deletions(-) diff --git a/tests/auto/client/mockcompositor.cpp b/tests/auto/client/mockcompositor.cpp index 682452262..7eb683191 100644 --- a/tests/auto/client/mockcompositor.cpp +++ b/tests/auto/client/mockcompositor.cpp @@ -185,9 +185,16 @@ void MockCompositor::processCommand(const Command &command) void MockCompositor::dispatchCommands() { - foreach (const Command &command, m_commandQueue) + lock(); + int count = m_commandQueue.length(); + unlock(); + + for (int i = 0; i < count; ++i) { + lock(); + const Command command = m_commandQueue.takeFirst(); + unlock(); command.callback(command.target, command.parameters); - m_commandQueue.clear(); + } } void *MockCompositor::run(void *data) @@ -205,8 +212,11 @@ void *MockCompositor::run(void *data) } while (controller->m_alive) { - QMutexLocker locker(&controller->m_mutex); - controller->m_waitCondition.wait(&controller->m_mutex); + { + QMutexLocker locker(&controller->m_mutex); + if (controller->m_commandQueue.isEmpty()) + controller->m_waitCondition.wait(&controller->m_mutex); + } controller->dispatchCommands(); compositor.dispatchEvents(20); } -- cgit v1.2.3 From da364484aa51ce7c73d39ce0ca444169ce69588e Mon Sep 17 00:00:00 2001 From: Johan Klokkhammer Helsing Date: Mon, 1 Aug 2016 09:43:59 +0200 Subject: Fix crash when dragging with touch without first having pointer focus Also add drag-and-drop tests for both touch and mouse. Task-number: QTBUG-54756 Change-Id: Ibfff48b1f2377022a8624e28e9f638076187ddca Reviewed-by: Paul Olav Tvete --- src/client/qwaylanddatadevice.cpp | 3 + tests/auto/client/mockcompositor.cpp | 42 ++++++++++++ tests/auto/client/mockcompositor.h | 15 +++++ tests/auto/client/mockinput.cpp | 121 +++++++++++++++++++++++++++++++++++ tests/auto/client/mockinput.h | 18 ++++++ tests/auto/client/tst_client.cpp | 86 +++++++++++++++++++++++++ 6 files changed, 285 insertions(+) diff --git a/src/client/qwaylanddatadevice.cpp b/src/client/qwaylanddatadevice.cpp index 8130578b5..255b13f4c 100644 --- a/src/client/qwaylanddatadevice.cpp +++ b/src/client/qwaylanddatadevice.cpp @@ -107,7 +107,10 @@ void QWaylandDataDevice::startDrag(QMimeData *mimeData, QWaylandWindow *icon) { m_dragSource.reset(new QWaylandDataSource(m_display->dndSelectionHandler(), mimeData)); connect(m_dragSource.data(), &QWaylandDataSource::cancelled, this, &QWaylandDataDevice::dragSourceCancelled); + QWaylandWindow *origin = m_display->currentInputDevice()->pointerFocus(); + if (!origin) + origin = m_display->currentInputDevice()->touchFocus(); start_drag(m_dragSource->object(), origin->object(), icon->object(), m_display->currentInputDevice()->serial()); } diff --git a/tests/auto/client/mockcompositor.cpp b/tests/auto/client/mockcompositor.cpp index 7eb683191..83dd52ba2 100644 --- a/tests/auto/client/mockcompositor.cpp +++ b/tests/auto/client/mockcompositor.cpp @@ -150,6 +150,47 @@ void MockCompositor::sendTouchFrame(const QSharedPointer &surface) processCommand(command); } +void MockCompositor::sendDataDeviceDataOffer(const QSharedPointer &surface) +{ + Command command = makeCommand(Impl::Compositor::sendDataDeviceDataOffer, m_compositor); + command.parameters << QVariant::fromValue(surface); + processCommand(command); +} + +void MockCompositor::sendDataDeviceEnter(const QSharedPointer &surface, const QPoint& position) +{ + Command command = makeCommand(Impl::Compositor::sendDataDeviceEnter, m_compositor); + command.parameters << QVariant::fromValue(surface) << QVariant::fromValue(position); + processCommand(command); +} + +void MockCompositor::sendDataDeviceMotion(const QPoint &position) +{ + Command command = makeCommand(Impl::Compositor::sendDataDeviceMotion, m_compositor); + command.parameters << QVariant::fromValue(position); + processCommand(command); +} + +void MockCompositor::sendDataDeviceDrop(const QSharedPointer &surface) +{ + Command command = makeCommand(Impl::Compositor::sendDataDeviceDrop, m_compositor); + command.parameters << QVariant::fromValue(surface); + processCommand(command); +} + +void MockCompositor::sendDataDeviceLeave(const QSharedPointer &surface) +{ + Command command = makeCommand(Impl::Compositor::sendDataDeviceLeave, m_compositor); + command.parameters << QVariant::fromValue(surface); + processCommand(command); +} + +void MockCompositor::waitForStartDrag() +{ + Command command = makeCommand(Impl::Compositor::waitForStartDrag, m_compositor); + processCommand(command); +} + QSharedPointer MockCompositor::surface() { QSharedPointer result; @@ -228,6 +269,7 @@ namespace Impl { Compositor::Compositor() : m_display(wl_display_create()) + , m_startDragSeen(false) , m_time(0) { wl_list_init(&m_outputResources); diff --git a/tests/auto/client/mockcompositor.h b/tests/auto/client/mockcompositor.h index 8731949c0..2f0df4a0f 100644 --- a/tests/auto/client/mockcompositor.h +++ b/tests/auto/client/mockcompositor.h @@ -85,6 +85,15 @@ public: static void sendTouchUp(void *data, const QList ¶meters); static void sendTouchMotion(void *data, const QList ¶meters); static void sendTouchFrame(void *data, const QList ¶meters); + static void sendDataDeviceDataOffer(void *data, const QList ¶meters); + static void sendDataDeviceEnter(void *data, const QList ¶meters); + static void sendDataDeviceMotion(void *data, const QList ¶meters); + static void sendDataDeviceDrop(void *data, const QList ¶meters); + static void sendDataDeviceLeave(void *data, const QList ¶meters); + static void waitForStartDrag(void *data, const QList ¶meters); + +public: + bool m_startDragSeen; private: static void bindCompositor(wl_client *client, void *data, uint32_t version, uint32_t id); @@ -156,6 +165,12 @@ public: void sendTouchMotion(const QSharedPointer &surface, const QPoint &position, int id); void sendTouchUp(const QSharedPointer &surface, int id); void sendTouchFrame(const QSharedPointer &surface); + void sendDataDeviceDataOffer(const QSharedPointer &surface); + void sendDataDeviceEnter(const QSharedPointer &surface, const QPoint &position); + void sendDataDeviceMotion(const QPoint &position); + void sendDataDeviceDrop(const QSharedPointer &surface); + void sendDataDeviceLeave(const QSharedPointer &surface); + void waitForStartDrag(); QSharedPointer surface(); diff --git a/tests/auto/client/mockinput.cpp b/tests/auto/client/mockinput.cpp index dd0512e76..05df8604b 100644 --- a/tests/auto/client/mockinput.cpp +++ b/tests/auto/client/mockinput.cpp @@ -144,6 +144,70 @@ void Compositor::sendTouchFrame(void *data, const QList ¶meters) compositor->m_touch->sendFrame(surface); } +void Compositor::sendDataDeviceDataOffer(void *data, const QList ¶meters) +{ + Compositor *compositor = static_cast(data); + Surface *surface = resolveSurface(parameters.first()); + + Q_ASSERT(compositor); + Q_ASSERT(surface); + + compositor->m_data_device_manager->dataDevice()->sendDataOffer(surface->resource()->client()); +} + +void Compositor::sendDataDeviceEnter(void *data, const QList ¶meters) +{ + Compositor *compositor = static_cast(data); + Surface *surface = resolveSurface(parameters.first()); + QPoint position = parameters.at(1).toPoint(); + + Q_ASSERT(compositor); + Q_ASSERT(surface); + + compositor->m_data_device_manager->dataDevice()->sendEnter(surface, position); +} + +void Compositor::sendDataDeviceMotion(void *data, const QList ¶meters) +{ + Compositor *compositor = static_cast(data); + Q_ASSERT(compositor); + QPoint position = parameters.first().toPoint(); + compositor->m_data_device_manager->dataDevice()->sendMotion(position); +} + +void Compositor::sendDataDeviceDrop(void *data, const QList ¶meters) +{ + Compositor *compositor = static_cast(data); + Surface *surface = resolveSurface(parameters.first()); + + Q_ASSERT(compositor); + Q_ASSERT(surface); + + compositor->m_data_device_manager->dataDevice()->sendDrop(surface); +} + +void Compositor::sendDataDeviceLeave(void *data, const QList ¶meters) +{ + Compositor *compositor = static_cast(data); + Surface *surface = resolveSurface(parameters.first()); + + Q_ASSERT(compositor); + Q_ASSERT(surface); + + compositor->m_data_device_manager->dataDevice()->sendLeave(surface); +} + +void Compositor::waitForStartDrag(void *data, const QList ¶meters) +{ + Compositor *compositor = static_cast(data); + Q_ASSERT(compositor); + while (!compositor->m_startDragSeen) { + wl_display_flush_clients(compositor->m_display); + wl_event_loop_dispatch(compositor->m_loop, 100); + } + compositor->m_startDragSeen = false; +} + Seat::Seat(Compositor *compositor, struct ::wl_display *display) : wl_seat(display, 2) , m_compositor(compositor) @@ -312,11 +376,53 @@ void Touch::sendFrame(Surface *surface) wl_touch_send_frame(resource->handle); } +DataOffer::DataOffer() + : wl_data_offer() +{ + +} + DataDevice::DataDevice(Compositor *compositor) : wl_data_device() , m_compositor(compositor) + , m_dataOffer(nullptr) + , m_focus(nullptr) +{ + +} + +void DataDevice::sendDataOffer(wl_client *client) +{ + m_dataOffer = new QtWaylandServer::wl_data_offer(client, 0, 1); + Resource *resource = resourceMap().value(client); + send_data_offer(resource->handle, m_dataOffer->resource()->handle); +} + +void DataDevice::sendEnter(Surface *surface, const QPoint& position) +{ + uint serial = m_compositor->nextSerial(); + m_focus = surface; + Resource *resource = resourceMap().value(surface->resource()->client()); + send_enter(resource->handle, serial, surface->resource()->handle, position.x(), position.y(), m_dataOffer->resource()->handle); +} + +void DataDevice::sendMotion(const QPoint &position) +{ + uint32_t time = m_compositor->time(); + Resource *resource = resourceMap().value(m_focus->resource()->client()); + send_motion(resource->handle, time, position.x(), position.y()); +} + +void DataDevice::sendDrop(Surface *surface) { + Resource *resource = resourceMap().value(surface->resource()->client()); + send_drop(resource->handle); +} +void DataDevice::sendLeave(Surface *surface) +{ + Resource *resource = resourceMap().value(surface->resource()->client()); + send_leave(resource->handle); } DataDevice::~DataDevice() @@ -324,6 +430,11 @@ DataDevice::~DataDevice() } +void DataDevice::data_device_start_drag(QtWaylandServer::wl_data_device::Resource *resource, wl_resource *source, wl_resource *origin, wl_resource *icon, uint32_t serial) +{ + m_compositor->m_startDragSeen = true; +} + DataDeviceManager::DataDeviceManager(Compositor *compositor, wl_display *display) : wl_data_device_manager(display, 1) , m_compositor(compositor) @@ -336,6 +447,11 @@ DataDeviceManager::~DataDeviceManager() } +DataDevice *DataDeviceManager::dataDevice() const +{ + return m_data_device.data(); +} + void DataDeviceManager::data_device_manager_get_data_device(Resource *resource, uint32_t id, struct ::wl_resource *seat) { if (!m_data_device) @@ -343,4 +459,9 @@ void DataDeviceManager::data_device_manager_get_data_device(Resource *resource, m_data_device->add(resource->client(), id, 1); } +void DataDeviceManager::data_device_manager_create_data_source(QtWaylandServer::wl_data_device_manager::Resource *resource, uint32_t id) +{ + new QtWaylandServer::wl_data_source(resource->client(), id, 1); +} + } diff --git a/tests/auto/client/mockinput.h b/tests/auto/client/mockinput.h index 61c507077..d98328a66 100644 --- a/tests/auto/client/mockinput.h +++ b/tests/auto/client/mockinput.h @@ -127,14 +127,30 @@ private: Compositor *m_compositor; }; +class DataOffer : public QtWaylandServer::wl_data_offer +{ +public: + DataOffer(); +}; + class DataDevice : public QtWaylandServer::wl_data_device { public: DataDevice(Compositor *compositor); + void sendDataOffer(wl_client *client); + void sendEnter(Surface *surface, const QPoint &position); + void sendMotion(const QPoint &position); + void sendDrop(Surface *surface); + void sendLeave(Surface *surface); ~DataDevice(); +protected: + void data_device_start_drag(Resource *resource, struct ::wl_resource *source, struct ::wl_resource *origin, struct ::wl_resource *icon, uint32_t serial) override; + private: Compositor *m_compositor; + QtWaylandServer::wl_data_offer *m_dataOffer; + Surface* m_focus; }; class DataDeviceManager : public QtWaylandServer::wl_data_device_manager @@ -142,9 +158,11 @@ class DataDeviceManager : public QtWaylandServer::wl_data_device_manager public: DataDeviceManager(Compositor *compositor, struct ::wl_display *display); ~DataDeviceManager(); + DataDevice *dataDevice() const; protected: void data_device_manager_get_data_device(Resource *resource, uint32_t id, struct ::wl_resource *seat) Q_DECL_OVERRIDE; + void data_device_manager_create_data_source(Resource *resource, uint32_t id) override; private: Compositor *m_compositor; diff --git a/tests/auto/client/tst_client.cpp b/tests/auto/client/tst_client.cpp index 3fde258d1..5a1143220 100644 --- a/tests/auto/client/tst_client.cpp +++ b/tests/auto/client/tst_client.cpp @@ -36,6 +36,10 @@ #include #include #include +#include +#include +#include +#include #include @@ -141,6 +145,8 @@ private slots: void createDestroyWindow(); void events(); void backingStore(); + void touchDrag(); + void mouseDrag(); private: MockCompositor *compositor; @@ -251,6 +257,86 @@ void tst_WaylandClient::backingStore() QTRY_VERIFY(surface->image.isNull()); } +class DndWindow : public QWindow +{ + Q_OBJECT + +public: + DndWindow(QWindow *parent = 0) + : QWindow(parent) + , dragStarted(false) + { + QImage cursorImage(64,64,QImage::Format_ARGB32); + cursorImage.fill(Qt::blue); + m_dragIcon = QPixmap::fromImage(cursorImage); + } + ~DndWindow(){} + bool dragStarted; + +protected: + void mousePressEvent(QMouseEvent *event) Q_DECL_OVERRIDE + { + if (dragStarted) + return; + dragStarted = true; + + QByteArray dataBytes; + QMimeData *mimeData = new QMimeData; + mimeData->setData("application/x-dnditemdata", dataBytes); + QDrag *drag = new QDrag(this); + drag->setMimeData(mimeData); + drag->setPixmap(m_dragIcon); + drag->exec(Qt::CopyAction | Qt::MoveAction, Qt::CopyAction); + } +private: + QPixmap m_dragIcon; +}; + +void tst_WaylandClient::touchDrag() +{ + DndWindow window; + window.show(); + + QSharedPointer surface; + QTRY_VERIFY(surface = compositor->surface()); + + compositor->setKeyboardFocus(surface); + QTRY_COMPARE(QGuiApplication::focusWindow(), &window); + + const int id = 0; + compositor->sendTouchDown(surface, QPoint(10, 10), id); + compositor->sendTouchMotion(surface, QPoint(20, 20), id); + compositor->sendTouchFrame(surface); + compositor->waitForStartDrag(); + compositor->sendDataDeviceDataOffer(surface); + compositor->sendDataDeviceEnter(surface, QPoint(20, 20)); + compositor->sendDataDeviceMotion( QPoint(21, 21)); + compositor->sendDataDeviceDrop(surface); + compositor->sendDataDeviceLeave(surface); + QTRY_VERIFY(window.dragStarted); +} + +void tst_WaylandClient::mouseDrag() +{ + DndWindow window; + window.show(); + + QSharedPointer surface; + QTRY_VERIFY(surface = compositor->surface()); + + compositor->setKeyboardFocus(surface); + QTRY_COMPARE(QGuiApplication::focusWindow(), &window); + + compositor->sendMousePress(surface, QPoint(10, 10)); + compositor->sendDataDeviceDataOffer(surface); + compositor->sendDataDeviceEnter(surface, QPoint(20, 20)); + compositor->sendDataDeviceMotion( QPoint(21, 21)); + compositor->waitForStartDrag(); + compositor->sendDataDeviceDrop(surface); + compositor->sendDataDeviceLeave(surface); + QTRY_VERIFY(window.dragStarted); +} + int main(int argc, char **argv) { setenv("XDG_RUNTIME_DIR", ".", 1); -- cgit v1.2.3 From 1db3dee9432f28f35ec9c971444b8a889bbdd6e2 Mon Sep 17 00:00:00 2001 From: Johan Klokkhammer Helsing Date: Fri, 5 Aug 2016 10:59:51 +0200 Subject: Client: Refactor window active state Let shell surface implementations decide if they manage activated state. Moves the logic out of QWaylandDisplay. Change-Id: I75c86df68a1a93f9b1d2bf378b6603215d0b0128 Reviewed-by: Paul Olav Tvete --- src/client/qwaylanddisplay.cpp | 8 +------- src/client/qwaylanddisplay_p.h | 1 - src/client/qwaylandshellsurface_p.h | 1 + src/client/qwaylandxdgsurface_p.h | 2 ++ 4 files changed, 4 insertions(+), 8 deletions(-) diff --git a/src/client/qwaylanddisplay.cpp b/src/client/qwaylanddisplay.cpp index f6d86bb39..682172bf8 100644 --- a/src/client/qwaylanddisplay.cpp +++ b/src/client/qwaylanddisplay.cpp @@ -385,12 +385,6 @@ void QWaylandDisplay::setLastInputDevice(QWaylandInputDevice *device, uint32_t s mLastInputWindow = win; } -bool QWaylandDisplay::shellManagesActiveState() const -{ - //TODO: This should be part of a shell interface used by the shell protocol implementations - return mShellXdg; -} - void QWaylandDisplay::handleWindowActivated(QWaylandWindow *window) { if (mActiveWindows.contains(window)) @@ -414,7 +408,7 @@ void QWaylandDisplay::handleKeyboardFocusChanged(QWaylandInputDevice *inputDevic { QWaylandWindow *keyboardFocus = inputDevice->keyboardFocus(); - if (!shellManagesActiveState() && mLastKeyboardFocus != keyboardFocus) { + if (!keyboardFocus->shellSurface()->shellManagesActiveState() && mLastKeyboardFocus != keyboardFocus) { if (keyboardFocus) handleWindowActivated(keyboardFocus); if (mLastKeyboardFocus) diff --git a/src/client/qwaylanddisplay_p.h b/src/client/qwaylanddisplay_p.h index 237be5b78..3f5538ec2 100644 --- a/src/client/qwaylanddisplay_p.h +++ b/src/client/qwaylanddisplay_p.h @@ -169,7 +169,6 @@ public: QWaylandWindow *lastInputWindow() const; void setLastInputDevice(QWaylandInputDevice *device, uint32_t serial, QWaylandWindow *window); - bool shellManagesActiveState() const; void handleWindowActivated(QWaylandWindow *window); void handleWindowDeactivated(QWaylandWindow *window); void handleKeyboardFocusChanged(QWaylandInputDevice *inputDevice); diff --git a/src/client/qwaylandshellsurface_p.h b/src/client/qwaylandshellsurface_p.h index 726d103f9..c99e586d5 100644 --- a/src/client/qwaylandshellsurface_p.h +++ b/src/client/qwaylandshellsurface_p.h @@ -85,6 +85,7 @@ public: virtual void setContentOrientationMask(Qt::ScreenOrientations orientation) { Q_UNUSED(orientation) } virtual void sendProperty(const QString &name, const QVariant &value); + virtual bool shellManagesActiveState() const { return false; } inline QWaylandWindow *window() { return m_window; } diff --git a/src/client/qwaylandxdgsurface_p.h b/src/client/qwaylandxdgsurface_p.h index e367980b7..bc72820a1 100644 --- a/src/client/qwaylandxdgsurface_p.h +++ b/src/client/qwaylandxdgsurface_p.h @@ -89,6 +89,8 @@ public: void setWindowFlags(Qt::WindowFlags flags) Q_DECL_OVERRIDE; void sendProperty(const QString &name, const QVariant &value) Q_DECL_OVERRIDE; + bool shellManagesActiveState() const Q_DECL_OVERRIDE { return true; } + bool isFullscreen() const { return m_fullscreen; } bool isMaximized() const { return m_maximized; } -- cgit v1.2.3 From b3b4778c237c43cfde02c4750017c37112c315c4 Mon Sep 17 00:00:00 2001 From: Johan Klokkhammer Helsing Date: Fri, 5 Aug 2016 10:10:58 +0200 Subject: Make wl_shell and xdg_shell use the QWaylandShellIntegration interface This simplifies the code in QWaylandDisplay and hopefully makes it easier to implement a prioritized shell selection mechanism later. Change-Id: I2bb3a13f8acedb60a6606cb3a8b5b228095eadf9 Reviewed-by: Giulio Camuffo --- src/client/client.pro | 4 ++ src/client/qwaylanddisplay.cpp | 31 +++++-------- src/client/qwaylanddisplay_p.h | 6 +-- src/client/qwaylandintegration.cpp | 43 ++++++++++++++---- src/client/qwaylandintegration_p.h | 1 + src/client/qwaylandwlshellintegration.cpp | 62 +++++++++++++++++++++++++ src/client/qwaylandwlshellintegration_p.h | 72 +++++++++++++++++++++++++++++ src/client/qwaylandxdgshell.cpp | 5 ++ src/client/qwaylandxdgshell_p.h | 4 +- src/client/qwaylandxdgshellintegration.cpp | 63 ++++++++++++++++++++++++++ src/client/qwaylandxdgshellintegration_p.h | 73 ++++++++++++++++++++++++++++++ src/client/qwaylandxdgsurface.cpp | 9 ++-- src/client/qwaylandxdgsurface_p.h | 4 +- 13 files changed, 337 insertions(+), 40 deletions(-) create mode 100644 src/client/qwaylandwlshellintegration.cpp create mode 100644 src/client/qwaylandwlshellintegration_p.h create mode 100644 src/client/qwaylandxdgshellintegration.cpp create mode 100644 src/client/qwaylandxdgshellintegration_p.h diff --git a/src/client/client.pro b/src/client/client.pro index 59234b14e..d2d12d9fd 100644 --- a/src/client/client.pro +++ b/src/client/client.pro @@ -59,8 +59,10 @@ SOURCES += qwaylandintegration.cpp \ qwaylanddatasource.cpp \ qwaylandshellsurface.cpp \ qwaylandwlshellsurface.cpp \ + qwaylandwlshellintegration.cpp \ qwaylandxdgshell.cpp \ qwaylandxdgsurface.cpp \ + qwaylandxdgshellintegration.cpp \ qwaylandextendedsurface.cpp \ qwaylandsubsurface.cpp \ qwaylandtouch.cpp \ @@ -92,8 +94,10 @@ HEADERS += qwaylandintegration_p.h \ qwaylanddatasource_p.h \ qwaylandshellsurface_p.h \ qwaylandwlshellsurface_p.h \ + qwaylandwlshellintegration_p.h \ qwaylandxdgshell_p.h \ qwaylandxdgsurface_p.h \ + qwaylandxdgshellintegration_p.h \ qwaylandextendedsurface_p.h \ qwaylandsubsurface_p.h \ qwaylandtouch_p.h \ diff --git a/src/client/qwaylanddisplay.cpp b/src/client/qwaylanddisplay.cpp index 682172bf8..7225d24af 100644 --- a/src/client/qwaylanddisplay.cpp +++ b/src/client/qwaylanddisplay.cpp @@ -77,16 +77,8 @@ struct wl_surface *QWaylandDisplay::createSurface(void *handle) QWaylandShellSurface *QWaylandDisplay::createShellSurface(QWaylandWindow *window) { - if (mWaylandIntegration->shellIntegration()) - return mWaylandIntegration->shellIntegration()->createShellSurface(window); - - if (shellXdg()) { - return new QWaylandXdgSurface(shellXdg()->get_xdg_surface(window->object()), window); - } else if (shell()) { - return new QWaylandWlShellSurface(shell()->get_shell_surface(window->object()), window); - } - - return Q_NULLPTR; + Q_ASSERT(mWaylandIntegration->shellIntegration()); + return mWaylandIntegration->shellIntegration()->createShellSurface(window); } struct ::wl_region *QWaylandDisplay::createRegion(const QRegion &qregion) @@ -248,11 +240,6 @@ void QWaylandDisplay::registry_global(uint32_t id, const QString &interface, uin mCompositor.init(registry, id, mCompositorVersion); } else if (interface == QStringLiteral("wl_shm")) { mShm = static_cast(wl_registry_bind(registry, id, &wl_shm_interface,1)); - } else if (interface == QStringLiteral("xdg_shell") - && qEnvironmentVariableIsSet("QT_WAYLAND_USE_XDG_SHELL")) { - mShellXdg.reset(new QWaylandXdgShell(registry,id)); - } else if (interface == QStringLiteral("wl_shell")){ - mShell.reset(new QtWayland::wl_shell(registry, id, 1)); } else if (interface == QStringLiteral("wl_seat")) { QWaylandInputDevice *inputDevice = mWaylandIntegration->createInputDevice(this, version, id); mInputDevices.append(inputDevice); @@ -301,6 +288,15 @@ void QWaylandDisplay::registry_global_remove(uint32_t id) } } +bool QWaylandDisplay::hasRegistryGlobal(const QString &interfaceName) +{ + Q_FOREACH (const RegistryGlobal &global, mGlobals) + if (global.interface == interfaceName) + return true; + + return false; +} + void QWaylandDisplay::addRegistryListener(RegistryListener listener, void *data) { Listener l = { listener, data }; @@ -356,11 +352,6 @@ void QWaylandDisplay::forceRoundTrip() wl_callback_destroy(callback); } -QtWayland::xdg_shell *QWaylandDisplay::shellXdg() -{ - return mShellXdg.data(); -} - bool QWaylandDisplay::supportsWindowDecoration() const { static bool disabled = qgetenv("QT_WAYLAND_DISABLE_WINDOWDECORATION").toInt(); diff --git a/src/client/qwaylanddisplay_p.h b/src/client/qwaylanddisplay_p.h index 3f5538ec2..ea127d2f4 100644 --- a/src/client/qwaylanddisplay_p.h +++ b/src/client/qwaylanddisplay_p.h @@ -128,9 +128,6 @@ public: QtWayland::wl_compositor *compositor() { return &mCompositor; } int compositorVersion() const { return mCompositorVersion; } - QtWayland::wl_shell *shell() { return mShell.data(); } - QtWayland::xdg_shell *shellXdg(); - QList inputDevices() const { return mInputDevices; } QWaylandInputDevice *defaultInputDevice() const; QWaylandInputDevice *currentInputDevice() const { return defaultInputDevice(); } @@ -151,6 +148,7 @@ public: : id(id_), interface(interface_), version(version_), registry(registry_) { } }; QList globals() const { return mGlobals; } + bool hasRegistryGlobal(const QString &interfaceName); /* wl_registry_add_listener does not add but rather sets a listener, so this function is used * to enable many listeners at once. */ @@ -193,8 +191,6 @@ private: struct wl_display *mDisplay; QtWayland::wl_compositor mCompositor; struct wl_shm *mShm; - QScopedPointer mShell; - QScopedPointer mShellXdg; QList mScreens; QList mInputDevices; QList mRegistryListeners; diff --git a/src/client/qwaylandintegration.cpp b/src/client/qwaylandintegration.cpp index 39fff533d..e62ef87f1 100644 --- a/src/client/qwaylandintegration.cpp +++ b/src/client/qwaylandintegration.cpp @@ -69,6 +69,8 @@ #include "qwaylandshellintegration_p.h" #include "qwaylandshellintegrationfactory_p.h" +#include "qwaylandxdgshellintegration_p.h" +#include "qwaylandwlshellintegration_p.h" #include "qwaylandinputdeviceintegration_p.h" #include "qwaylandinputdeviceintegrationfactory_p.h" @@ -360,17 +362,29 @@ void QWaylandIntegration::initializeShellIntegration() QByteArray integrationName = qgetenv("QT_WAYLAND_SHELL_INTEGRATION"); QString targetKey = QString::fromLocal8Bit(integrationName); - if (targetKey.isEmpty()) { - return; + if (!targetKey.isEmpty()) { + QStringList keys = QWaylandShellIntegrationFactory::keys(); + if (keys.contains(targetKey)) { + qDebug("Using the '%s' shell integration", qPrintable(targetKey)); + mShellIntegration = QWaylandShellIntegrationFactory::create(targetKey, QStringList()); + } + } else { + QStringList preferredShells; + if (qEnvironmentVariableIsSet("QT_WAYLAND_USE_XDG_SHELL")) + preferredShells << QLatin1String("xdg_shell"); + preferredShells << QLatin1String("wl_shell"); + + Q_FOREACH (QString preferredShell, preferredShells) { + if (mDisplay->hasRegistryGlobal(preferredShell)) { + mShellIntegration = createShellIntegration(preferredShell); + break; + } + } } - QStringList keys = QWaylandShellIntegrationFactory::keys(); - if (keys.contains(targetKey)) { - mShellIntegration = QWaylandShellIntegrationFactory::create(targetKey, QStringList()); - } - if (mShellIntegration && mShellIntegration->initialize(mDisplay)) { - qDebug("Using the '%s' shell integration", qPrintable(targetKey)); - } else { + Q_ASSERT(mShellIntegration); + + if (!mShellIntegration->initialize(mDisplay)) { delete mShellIntegration; mShellIntegration = Q_NULLPTR; qWarning("Failed to load shell integration %s", qPrintable(targetKey)); @@ -403,6 +417,17 @@ void QWaylandIntegration::initializeInputDeviceIntegration() } } +QWaylandShellIntegration *QWaylandIntegration::createShellIntegration(const QString &interfaceName) +{ + if (interfaceName == QLatin1Literal("wl_shell")) { + return new QWaylandWlShellIntegration(mDisplay); + } else if (interfaceName == QLatin1Literal("xdg_shell")) { + return new QWaylandXdgShellIntegration(mDisplay); + } else { + return Q_NULLPTR; + } +} + } QT_END_NAMESPACE diff --git a/src/client/qwaylandintegration_p.h b/src/client/qwaylandintegration_p.h index 987d80599..671f7de28 100644 --- a/src/client/qwaylandintegration_p.h +++ b/src/client/qwaylandintegration_p.h @@ -115,6 +115,7 @@ private: void initializeServerBufferIntegration(); void initializeShellIntegration(); void initializeInputDeviceIntegration(); + QWaylandShellIntegration *createShellIntegration(const QString& interfaceName); QPlatformFontDatabase *mFontDb; QPlatformClipboard *mClipboard; diff --git a/src/client/qwaylandwlshellintegration.cpp b/src/client/qwaylandwlshellintegration.cpp new file mode 100644 index 000000000..6a9220d26 --- /dev/null +++ b/src/client/qwaylandwlshellintegration.cpp @@ -0,0 +1,62 @@ +/**************************************************************************** +** +** Copyright (C) 2016 The Qt Company Ltd. +** Contact: http://www.qt.io/licensing/ +** +** This file is part of the plugins of the Qt Toolkit. +** +** $QT_BEGIN_LICENSE:LGPL21$ +** Commercial License Usage +** Licensees holding valid commercial Qt licenses may use this file in +** accordance with the commercial license agreement provided with the +** Software or, alternatively, in accordance with the terms contained in +** a written agreement between you and The Qt Company. For licensing terms +** and conditions see http://www.qt.io/terms-conditions. For further +** information use the contact form at http://www.qt.io/contact-us. +** +** GNU Lesser General Public License Usage +** Alternatively, this file may be used under the terms of the GNU Lesser +** General Public License version 2.1 or version 3 as published by the Free +** Software Foundation and appearing in the file LICENSE.LGPLv21 and +** LICENSE.LGPLv3 included in the packaging of this file. Please review the +** following information to ensure the GNU Lesser General Public License +** requirements will be met: https://www.gnu.org/licenses/lgpl.html and +** http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html. +** +** As a special exception, The Qt Company gives you certain additional +** rights. These rights are described in The Qt Company LGPL Exception +** version 1.1, included in the file LGPL_EXCEPTION.txt in this package. +** +** $QT_END_LICENSE$ +** +****************************************************************************/ + +#include "qwaylandwlshellintegration_p.h" + +#include +#include +#include + +QT_BEGIN_NAMESPACE + +namespace QtWaylandClient { + +QWaylandWlShellIntegration::QWaylandWlShellIntegration(QWaylandDisplay *display) + : m_wlShell(Q_NULLPTR) +{ + Q_FOREACH (QWaylandDisplay::RegistryGlobal global, display->globals()) { + if (global.interface == QLatin1String("wl_shell")) { + m_wlShell = new QtWayland::wl_shell(display->wl_registry(), global.id, 1); + break; + } + } +} + +QWaylandShellSurface *QWaylandWlShellIntegration::createShellSurface(QWaylandWindow *window) +{ + return new QWaylandWlShellSurface(m_wlShell->get_shell_surface(window->object()), window); +} + +} + +QT_END_NAMESPACE diff --git a/src/client/qwaylandwlshellintegration_p.h b/src/client/qwaylandwlshellintegration_p.h new file mode 100644 index 000000000..8531eb3aa --- /dev/null +++ b/src/client/qwaylandwlshellintegration_p.h @@ -0,0 +1,72 @@ +/**************************************************************************** +** +** Copyright (C) 2016 The Qt Company Ltd. +** Contact: http://www.qt.io/licensing/ +** +** This file is part of the plugins of the Qt Toolkit. +** +** $QT_BEGIN_LICENSE:LGPL21$ +** Commercial License Usage +** Licensees holding valid commercial Qt licenses may use this file in +** accordance with the commercial license agreement provided with the +** Software or, alternatively, in accordance with the terms contained in +** a written agreement between you and The Qt Company. For licensing terms +** and conditions see http://www.qt.io/terms-conditions. For further +** information use the contact form at http://www.qt.io/contact-us. +** +** GNU Lesser General Public License Usage +** Alternatively, this file may be used under the terms of the GNU Lesser +** General Public License version 2.1 or version 3 as published by the Free +** Software Foundation and appearing in the file LICENSE.LGPLv21 and +** LICENSE.LGPLv3 included in the packaging of this file. Please review the +** following information to ensure the GNU Lesser General Public License +** requirements will be met: https://www.gnu.org/licenses/lgpl.html and +** http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html. +** +** As a special exception, The Qt Company gives you certain additional +** rights. These rights are described in The Qt Company LGPL Exception +** version 1.1, included in the file LGPL_EXCEPTION.txt in this package. +** +** $QT_END_LICENSE$ +** +****************************************************************************/ + +#ifndef QWAYLANDWLSHELLINTEGRATION_P_H +#define QWAYLANDWLSHELLINTEGRATION_P_H + +// +// W A R N I N G +// ------------- +// +// This file is not part of the Qt API. It exists purely as an +// implementation detail. This header file may change from version to +// version without notice, or even be removed. +// +// We mean it. +// + +#include +#include + +#include + +QT_BEGIN_NAMESPACE + +namespace QtWaylandClient { + +class Q_WAYLAND_CLIENT_EXPORT QWaylandWlShellIntegration : public QWaylandShellIntegration +{ +public: + QWaylandWlShellIntegration(QWaylandDisplay* display); + bool initialize(QWaylandDisplay *) Q_DECL_OVERRIDE { return m_wlShell != Q_NULLPTR; } + QWaylandShellSurface *createShellSurface(QWaylandWindow *window) Q_DECL_OVERRIDE; + +private: + QtWayland::wl_shell *m_wlShell; +}; + +} + +QT_END_NAMESPACE + +#endif // QWAYLANDWLSHELLINTEGRATION_P_H diff --git a/src/client/qwaylandxdgshell.cpp b/src/client/qwaylandxdgshell.cpp index 65fafcead..9b351da6a 100644 --- a/src/client/qwaylandxdgshell.cpp +++ b/src/client/qwaylandxdgshell.cpp @@ -37,6 +37,7 @@ #include "qwaylandwindow_p.h" #include "qwaylandinputdevice_p.h" #include "qwaylandscreen_p.h" +#include "qwaylandxdgsurface_p.h" #include @@ -60,6 +61,10 @@ QWaylandXdgShell::~QWaylandXdgShell() xdg_shell_destroy(object()); } +QWaylandXdgSurface *QWaylandXdgShell::createXdgSurface(QWaylandWindow *window) +{ + return new QWaylandXdgSurface(this, window); +} void QWaylandXdgShell::xdg_shell_ping(uint32_t serial) { diff --git a/src/client/qwaylandxdgshell_p.h b/src/client/qwaylandxdgshell_p.h index 3fd248fc4..cd1656415 100644 --- a/src/client/qwaylandxdgshell_p.h +++ b/src/client/qwaylandxdgshell_p.h @@ -61,15 +61,17 @@ namespace QtWaylandClient { class QWaylandWindow; class QWaylandInputDevice; +class QWaylandXdgSurface; class Q_WAYLAND_CLIENT_EXPORT QWaylandXdgShell : public QtWayland::xdg_shell { public: QWaylandXdgShell(struct ::xdg_shell *shell); QWaylandXdgShell(struct ::wl_registry *registry, uint32_t id); - virtual ~QWaylandXdgShell(); + QWaylandXdgSurface *createXdgSurface(QWaylandWindow *window); + private: void xdg_shell_ping(uint32_t serial) Q_DECL_OVERRIDE; }; diff --git a/src/client/qwaylandxdgshellintegration.cpp b/src/client/qwaylandxdgshellintegration.cpp new file mode 100644 index 000000000..5a569129f --- /dev/null +++ b/src/client/qwaylandxdgshellintegration.cpp @@ -0,0 +1,63 @@ +/**************************************************************************** +** +** Copyright (C) 2016 The Qt Company Ltd. +** Contact: http://www.qt.io/licensing/ +** +** This file is part of the plugins of the Qt Toolkit. +** +** $QT_BEGIN_LICENSE:LGPL21$ +** Commercial License Usage +** Licensees holding valid commercial Qt licenses may use this file in +** accordance with the commercial license agreement provided with the +** Software or, alternatively, in accordance with the terms contained in +** a written agreement between you and The Qt Company. For licensing terms +** and conditions see http://www.qt.io/terms-conditions. For further +** information use the contact form at http://www.qt.io/contact-us. +** +** GNU Lesser General Public License Usage +** Alternatively, this file may be used under the terms of the GNU Lesser +** General Public License version 2.1 or version 3 as published by the Free +** Software Foundation and appearing in the file LICENSE.LGPLv21 and +** LICENSE.LGPLv3 included in the packaging of this file. Please review the +** following information to ensure the GNU Lesser General Public License +** requirements will be met: https://www.gnu.org/licenses/lgpl.html and +** http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html. +** +** As a special exception, The Qt Company gives you certain additional +** rights. These rights are described in The Qt Company LGPL Exception +** version 1.1, included in the file LGPL_EXCEPTION.txt in this package. +** +** $QT_END_LICENSE$ +** +****************************************************************************/ + +#include "qwaylandxdgshellintegration_p.h" + +#include +#include +#include +#include + +QT_BEGIN_NAMESPACE + +namespace QtWaylandClient { + +QWaylandXdgShellIntegration::QWaylandXdgShellIntegration(QWaylandDisplay *display) + : m_xdgShell(Q_NULLPTR) +{ + Q_FOREACH (QWaylandDisplay::RegistryGlobal global, display->globals()) { + if (global.interface == QLatin1String("xdg_shell")) { + m_xdgShell = new QWaylandXdgShell(display->wl_registry(), global.id); + break; + } + } +} + +QWaylandShellSurface *QWaylandXdgShellIntegration::createShellSurface(QWaylandWindow *window) +{ + return m_xdgShell->createXdgSurface(window); +} + +} + +QT_END_NAMESPACE diff --git a/src/client/qwaylandxdgshellintegration_p.h b/src/client/qwaylandxdgshellintegration_p.h new file mode 100644 index 000000000..29374ff1d --- /dev/null +++ b/src/client/qwaylandxdgshellintegration_p.h @@ -0,0 +1,73 @@ +/**************************************************************************** +** +** Copyright (C) 2016 The Qt Company Ltd. +** Contact: http://www.qt.io/licensing/ +** +** This file is part of the plugins of the Qt Toolkit. +** +** $QT_BEGIN_LICENSE:LGPL21$ +** Commercial License Usage +** Licensees holding valid commercial Qt licenses may use this file in +** accordance with the commercial license agreement provided with the +** Software or, alternatively, in accordance with the terms contained in +** a written agreement between you and The Qt Company. For licensing terms +** and conditions see http://www.qt.io/terms-conditions. For further +** information use the contact form at http://www.qt.io/contact-us. +** +** GNU Lesser General Public License Usage +** Alternatively, this file may be used under the terms of the GNU Lesser +** General Public License version 2.1 or version 3 as published by the Free +** Software Foundation and appearing in the file LICENSE.LGPLv21 and +** LICENSE.LGPLv3 included in the packaging of this file. Please review the +** following information to ensure the GNU Lesser General Public License +** requirements will be met: https://www.gnu.org/licenses/lgpl.html and +** http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html. +** +** As a special exception, The Qt Company gives you certain additional +** rights. These rights are described in The Qt Company LGPL Exception +** version 1.1, included in the file LGPL_EXCEPTION.txt in this package. +** +** $QT_END_LICENSE$ +** +****************************************************************************/ + +#ifndef QWAYLANDXDGSHELLINTEGRATION_P_H +#define QWAYLANDXDGSHELLINTEGRATION_P_H + +// +// W A R N I N G +// ------------- +// +// This file is not part of the Qt API. It exists purely as an +// implementation detail. This header file may change from version to +// version without notice, or even be removed. +// +// We mean it. +// + +#include + +#include + +QT_BEGIN_NAMESPACE + +namespace QtWaylandClient { + +class QWaylandXdgShell; + +class Q_WAYLAND_CLIENT_EXPORT QWaylandXdgShellIntegration : public QWaylandShellIntegration +{ +public: + QWaylandXdgShellIntegration(QWaylandDisplay *display); + bool initialize(QWaylandDisplay *) Q_DECL_OVERRIDE { return m_xdgShell != Q_NULLPTR; } + QWaylandShellSurface *createShellSurface(QWaylandWindow *window) Q_DECL_OVERRIDE; + +private: + QWaylandXdgShell *m_xdgShell; +}; + +} + +QT_END_NAMESPACE + +#endif // QWAYLANDXDGSHELLINTEGRATION_P_H diff --git a/src/client/qwaylandxdgsurface.cpp b/src/client/qwaylandxdgsurface.cpp index bbda03dc3..f44e2d9fe 100644 --- a/src/client/qwaylandxdgsurface.cpp +++ b/src/client/qwaylandxdgsurface.cpp @@ -39,16 +39,18 @@ #include "qwaylandabstractdecoration_p.h" #include "qwaylandscreen_p.h" #include "qwaylandextendedsurface_p.h" +#include "qwaylandxdgshell_p.h" QT_BEGIN_NAMESPACE namespace QtWaylandClient { -QWaylandXdgSurface::QWaylandXdgSurface(struct ::xdg_surface *xdg_surface, QWaylandWindow *window) +QWaylandXdgSurface::QWaylandXdgSurface(QWaylandXdgShell *shell, QWaylandWindow *window) : QWaylandShellSurface(window) - , QtWayland::xdg_surface(xdg_surface) + , QtWayland::xdg_surface(shell->get_xdg_surface(window->object())) , m_window(window) + , m_shell(shell) , m_maximized(false) , m_minimized(false) , m_fullscreen(false) @@ -130,8 +132,7 @@ void QWaylandXdgSurface::updateTransientParent(QWindow *parent) QWaylandWindow *parent_wayland_window = static_cast(parent->handle()); if (!parent_wayland_window) return; - QtWayland::xdg_shell *shell = parent_wayland_window->display()->shellXdg(); - set_parent(shell->get_xdg_surface(parent_wayland_window->object())); + set_parent(m_shell->get_xdg_surface(parent_wayland_window->object())); } void QWaylandXdgSurface::setTitle(const QString & title) diff --git a/src/client/qwaylandxdgsurface_p.h b/src/client/qwaylandxdgsurface_p.h index bc72820a1..51c658ea4 100644 --- a/src/client/qwaylandxdgsurface_p.h +++ b/src/client/qwaylandxdgsurface_p.h @@ -63,13 +63,14 @@ namespace QtWaylandClient { class QWaylandWindow; class QWaylandInputDevice; class QWaylandExtendedSurface; +class QWaylandXdgShell; class Q_WAYLAND_CLIENT_EXPORT QWaylandXdgSurface : public QWaylandShellSurface , public QtWayland::xdg_surface { Q_OBJECT public: - QWaylandXdgSurface(struct ::xdg_surface *shell_surface, QWaylandWindow *window); + QWaylandXdgSurface(QWaylandXdgShell *shell, QWaylandWindow *window); virtual ~QWaylandXdgSurface(); using QtWayland::xdg_surface::resize; @@ -105,6 +106,7 @@ private: private: QWaylandWindow *m_window; + QWaylandXdgShell* m_shell; bool m_maximized; bool m_minimized; bool m_fullscreen; -- cgit v1.2.3 From 1bc3b0fdc8d934c1ab69a902054681896b56d672 Mon Sep 17 00:00:00 2001 From: Johan Klokkhammer Helsing Date: Fri, 5 Aug 2016 10:27:06 +0200 Subject: Client: Fix popup position for xdg shell Popups used xdg_surface instead of xdg_popup. It's not possible to set a position for an xdg_surface, because it's supposed to be a top level window (in xdg shell v5). Consequently, popups were treated as top level windows and positioned randomly on Weston. Using xdg_popup instead solves the problem. Task-number: QTBUG-55063 Change-Id: I223348677ef8a1ef1eee6a4c389276a6c802bcb5 Reviewed-by: Giulio Camuffo --- src/client/client.pro | 2 + src/client/qwaylandxdgpopup_p.cpp | 61 +++++++++++++++++++++++ src/client/qwaylandxdgpopup_p.h | 79 ++++++++++++++++++++++++++++++ src/client/qwaylandxdgshell.cpp | 14 ++++++ src/client/qwaylandxdgshell_p.h | 2 + src/client/qwaylandxdgshellintegration.cpp | 6 ++- 6 files changed, 163 insertions(+), 1 deletion(-) create mode 100644 src/client/qwaylandxdgpopup_p.cpp create mode 100644 src/client/qwaylandxdgpopup_p.h diff --git a/src/client/client.pro b/src/client/client.pro index d2d12d9fd..88b9ea124 100644 --- a/src/client/client.pro +++ b/src/client/client.pro @@ -62,6 +62,7 @@ SOURCES += qwaylandintegration.cpp \ qwaylandwlshellintegration.cpp \ qwaylandxdgshell.cpp \ qwaylandxdgsurface.cpp \ + qwaylandxdgpopup_p.cpp \ qwaylandxdgshellintegration.cpp \ qwaylandextendedsurface.cpp \ qwaylandsubsurface.cpp \ @@ -97,6 +98,7 @@ HEADERS += qwaylandintegration_p.h \ qwaylandwlshellintegration_p.h \ qwaylandxdgshell_p.h \ qwaylandxdgsurface_p.h \ + qwaylandxdgpopup_p.h \ qwaylandxdgshellintegration_p.h \ qwaylandextendedsurface_p.h \ qwaylandsubsurface_p.h \ diff --git a/src/client/qwaylandxdgpopup_p.cpp b/src/client/qwaylandxdgpopup_p.cpp new file mode 100644 index 000000000..abc25278b --- /dev/null +++ b/src/client/qwaylandxdgpopup_p.cpp @@ -0,0 +1,61 @@ +/**************************************************************************** +** +** Copyright (C) 2016 The Qt Company Ltd. +** Contact: http://www.qt.io/licensing/ +** +** This file is part of the plugins of the Qt Toolkit. +** +** $QT_BEGIN_LICENSE:LGPL21$ +** Commercial License Usage +** Licensees holding valid commercial Qt licenses may use this file in +** accordance with the commercial license agreement provided with the +** Software or, alternatively, in accordance with the terms contained in +** a written agreement between you and The Qt Company. For licensing terms +** and conditions see http://www.qt.io/terms-conditions. For further +** information use the contact form at http://www.qt.io/contact-us. +** +** GNU Lesser General Public License Usage +** Alternatively, this file may be used under the terms of the GNU Lesser +** General Public License version 2.1 or version 3 as published by the Free +** Software Foundation and appearing in the file LICENSE.LGPLv21 and +** LICENSE.LGPLv3 included in the packaging of this file. Please review the +** following information to ensure the GNU Lesser General Public License +** requirements will be met: https://www.gnu.org/licenses/lgpl.html and +** http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html. +** +** As a special exception, The Qt Company gives you certain additional +** rights. These rights are described in The Qt Company LGPL Exception +** version 1.1, included in the file LGPL_EXCEPTION.txt in this package. +** +** $QT_END_LICENSE$ +** +****************************************************************************/ + +#include "qwaylandxdgpopup_p.h" + +#include "qwaylandwindow_p.h" +#include "qwaylanddisplay_p.h" +#include "qwaylandextendedsurface_p.h" + +QT_BEGIN_NAMESPACE + +namespace QtWaylandClient { + +QWaylandXdgPopup::QWaylandXdgPopup(struct ::xdg_popup *popup, QWaylandWindow *window) + : QWaylandShellSurface(window) + , QtWayland::xdg_popup(popup) + , m_extendedWindow(nullptr) +{ + if (window->display()->windowExtension()) + m_extendedWindow = new QWaylandExtendedSurface(window); +} + +QWaylandXdgPopup::~QWaylandXdgPopup() +{ + xdg_popup_destroy(object()); + delete m_extendedWindow; +} + +} + +QT_END_NAMESPACE diff --git a/src/client/qwaylandxdgpopup_p.h b/src/client/qwaylandxdgpopup_p.h new file mode 100644 index 000000000..b7574dd11 --- /dev/null +++ b/src/client/qwaylandxdgpopup_p.h @@ -0,0 +1,79 @@ +/**************************************************************************** +** +** Copyright (C) 2016 The Qt Company Ltd. +** Contact: http://www.qt.io/licensing/ +** +** This file is part of the config.tests of the Qt Toolkit. +** +** $QT_BEGIN_LICENSE:LGPL21$ +** Commercial License Usage +** Licensees holding valid commercial Qt licenses may use this file in +** accordance with the commercial license agreement provided with the +** Software or, alternatively, in accordance with the terms contained in +** a written agreement between you and The Qt Company. For licensing terms +** and conditions see http://www.qt.io/terms-conditions. For further +** information use the contact form at http://www.qt.io/contact-us. +** +** GNU Lesser General Public License Usage +** Alternatively, this file may be used under the terms of the GNU Lesser +** General Public License version 2.1 or version 3 as published by the Free +** Software Foundation and appearing in the file LICENSE.LGPLv21 and +** LICENSE.LGPLv3 included in the packaging of this file. Please review the +** following information to ensure the GNU Lesser General Public License +** requirements will be met: https://www.gnu.org/licenses/lgpl.html and +** http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html. +** +** As a special exception, The Qt Company gives you certain additional +** rights. These rights are described in The Qt Company LGPL Exception +** version 1.1, included in the file LGPL_EXCEPTION.txt in this package. +** +** $QT_END_LICENSE$ +** +****************************************************************************/ + +#ifndef QWAYLANDXDGPOPUP_P_H +#define QWAYLANDXDGPOPUP_P_H + +// +// W A R N I N G +// ------------- +// +// This file is not part of the Qt API. It exists purely as an +// implementation detail. This header file may change from version to +// version without notice, or even be removed. +// +// We mean it. +// + +#include + +#include +#include +#include "qwaylandshellsurface_p.h" + +QT_BEGIN_NAMESPACE + +class QWindow; + +namespace QtWaylandClient { + +class QWaylandWindow; +class QWaylandExtendedSurface; + +class Q_WAYLAND_CLIENT_EXPORT QWaylandXdgPopup : public QWaylandShellSurface + , public QtWayland::xdg_popup +{ + Q_OBJECT +public: + QWaylandXdgPopup(struct ::xdg_popup *popup, QWaylandWindow *window); + virtual ~QWaylandXdgPopup(); + +private: + QWaylandExtendedSurface *m_extendedWindow; +}; + +QT_END_NAMESPACE + +} + +#endif // QWAYLANDXDGPOPUP_P_H diff --git a/src/client/qwaylandxdgshell.cpp b/src/client/qwaylandxdgshell.cpp index 9b351da6a..56bb3fae9 100644 --- a/src/client/qwaylandxdgshell.cpp +++ b/src/client/qwaylandxdgshell.cpp @@ -37,6 +37,7 @@ #include "qwaylandwindow_p.h" #include "qwaylandinputdevice_p.h" #include "qwaylandscreen_p.h" +#include "qwaylandxdgpopup_p.h" #include "qwaylandxdgsurface_p.h" #include @@ -66,6 +67,19 @@ QWaylandXdgSurface *QWaylandXdgShell::createXdgSurface(QWaylandWindow *window) return new QWaylandXdgSurface(this, window); } +QWaylandXdgPopup *QWaylandXdgShell::createXdgPopup(QWaylandWindow *window) +{ + QWaylandWindow *parentWindow = window->transientParent(); + ::wl_surface *parentSurface = parentWindow->object(); + QWaylandInputDevice *inputDevice = window->display()->lastInputDevice(); + ::wl_seat *seat = inputDevice->wl_seat(); + uint serial = inputDevice->serial(); + QPoint position = window->geometry().topLeft(); + int x = position.x() + parentWindow->frameMargins().left(); + int y = position.y() + parentWindow->frameMargins().top(); + return new QWaylandXdgPopup(get_xdg_popup(window->object(), parentSurface, seat, serial, x, y), window); +} + void QWaylandXdgShell::xdg_shell_ping(uint32_t serial) { pong(serial); diff --git a/src/client/qwaylandxdgshell_p.h b/src/client/qwaylandxdgshell_p.h index cd1656415..fc5adb486 100644 --- a/src/client/qwaylandxdgshell_p.h +++ b/src/client/qwaylandxdgshell_p.h @@ -62,6 +62,7 @@ namespace QtWaylandClient { class QWaylandWindow; class QWaylandInputDevice; class QWaylandXdgSurface; +class QWaylandXdgPopup; class Q_WAYLAND_CLIENT_EXPORT QWaylandXdgShell : public QtWayland::xdg_shell { @@ -71,6 +72,7 @@ public: virtual ~QWaylandXdgShell(); QWaylandXdgSurface *createXdgSurface(QWaylandWindow *window); + QWaylandXdgPopup *createXdgPopup(QWaylandWindow *window); private: void xdg_shell_ping(uint32_t serial) Q_DECL_OVERRIDE; diff --git a/src/client/qwaylandxdgshellintegration.cpp b/src/client/qwaylandxdgshellintegration.cpp index 5a569129f..b6b1d9d35 100644 --- a/src/client/qwaylandxdgshellintegration.cpp +++ b/src/client/qwaylandxdgshellintegration.cpp @@ -36,6 +36,7 @@ #include #include #include +#include #include QT_BEGIN_NAMESPACE @@ -55,7 +56,10 @@ QWaylandXdgShellIntegration::QWaylandXdgShellIntegration(QWaylandDisplay *displa QWaylandShellSurface *QWaylandXdgShellIntegration::createShellSurface(QWaylandWindow *window) { - return m_xdgShell->createXdgSurface(window); + if (window->window()->type() == Qt::WindowType::Popup) + return m_xdgShell->createXdgPopup(window); + else + return m_xdgShell->createXdgSurface(window); } } -- cgit v1.2.3