From 43a13f3d9732ff4c35da01d2a0d9f195b57185a5 Mon Sep 17 00:00:00 2001 From: Pier Luigi Fiorini Date: Sat, 17 Aug 2019 10:37:39 +0200 Subject: [PATCH 1/8] Client: Expose default input device through integration Expose the whole default input device to clients. [ChangeLog][QPA plugin] Expose default input device to clients through the QPA API. Change-Id: I2608178f8b0ac09f766434588a280bcc2b30627d Reviewed-by: Johan Helsing --- .../platforms/wayland/qwaylandinputdevice.cpp | 15 +++++++++++++ .../platforms/wayland/qwaylandinputdevice_p.h | 10 +++++++++ .../wayland/qwaylandnativeinterface.cpp | 22 +++++++++++++++++++ 3 files changed, 47 insertions(+) diff --git a/src/plugins/platforms/wayland/qwaylandinputdevice.cpp b/src/plugins/platforms/wayland/qwaylandinputdevice.cpp index 8c794ddaedb..65f80f308bb 100644 --- a/src/plugins/platforms/wayland/qwaylandinputdevice.cpp +++ b/src/plugins/platforms/wayland/qwaylandinputdevice.cpp @@ -442,6 +442,21 @@ QWaylandInputDevice::Touch *QWaylandInputDevice::createTouch(QWaylandInputDevice return new Touch(device); } +QWaylandInputDevice::Keyboard *QWaylandInputDevice::keyboard() const +{ + return mKeyboard; +} + +QWaylandInputDevice::Pointer *QWaylandInputDevice::pointer() const +{ + return mPointer; +} + +QWaylandInputDevice::Touch *QWaylandInputDevice::touch() const +{ + return mTouch; +} + void QWaylandInputDevice::handleEndDrag() { if (mTouch) diff --git a/src/plugins/platforms/wayland/qwaylandinputdevice_p.h b/src/plugins/platforms/wayland/qwaylandinputdevice_p.h index 06ba5d5664e..4ac1dca3525 100644 --- a/src/plugins/platforms/wayland/qwaylandinputdevice_p.h +++ b/src/plugins/platforms/wayland/qwaylandinputdevice_p.h @@ -148,6 +148,10 @@ public: virtual Pointer *createPointer(QWaylandInputDevice *device); virtual Touch *createTouch(QWaylandInputDevice *device); + Keyboard *keyboard() const; + Pointer *pointer() const; + Touch *touch() const; + private: QWaylandDisplay *mQDisplay = nullptr; struct wl_display *mDisplay = nullptr; @@ -248,6 +252,8 @@ public: Qt::KeyboardModifiers modifiers() const; + struct ::wl_keyboard *wl_keyboard() { return QtWayland::wl_keyboard::object(); } + private slots: void handleFocusDestroyed(); void handleFocusLost(); @@ -284,6 +290,8 @@ public: #endif QWaylandInputDevice *seat() const { return mParent; } + struct ::wl_pointer *wl_pointer() { return QtWayland::wl_pointer::object(); } + protected: void pointer_enter(uint32_t serial, struct wl_surface *surface, wl_fixed_t sx, wl_fixed_t sy) override; @@ -377,6 +385,8 @@ public: bool allTouchPointsReleased(); void releasePoints(); + struct ::wl_touch *wl_touch() { return QtWayland::wl_touch::object(); } + QWaylandInputDevice *mParent = nullptr; QPointer mFocus; QList mTouchPoints; diff --git a/src/plugins/platforms/wayland/qwaylandnativeinterface.cpp b/src/plugins/platforms/wayland/qwaylandnativeinterface.cpp index cf227d489a5..b4ecc009098 100644 --- a/src/plugins/platforms/wayland/qwaylandnativeinterface.cpp +++ b/src/plugins/platforms/wayland/qwaylandnativeinterface.cpp @@ -47,6 +47,7 @@ #include "qwaylanddisplay_p.h" #include "qwaylandwindowmanagerintegration_p.h" #include "qwaylandscreen_p.h" +#include "qwaylandinputdevice_p.h" #include #include #include @@ -76,6 +77,27 @@ void *QWaylandNativeInterface::nativeResourceForIntegration(const QByteArray &re if (lowerCaseResource == "egldisplay" && m_integration->clientBufferIntegration()) return m_integration->clientBufferIntegration()->nativeResource(QWaylandClientBufferIntegration::EglDisplay); + if (lowerCaseResource == "wl_seat") + return m_integration->display()->defaultInputDevice()->wl_seat(); + if (lowerCaseResource == "wl_keyboard") { + auto *keyboard = m_integration->display()->defaultInputDevice()->keyboard(); + if (keyboard) + return keyboard->wl_keyboard(); + return nullptr; + } + if (lowerCaseResource == "wl_pointer") { + auto *pointer = m_integration->display()->defaultInputDevice()->pointer(); + if (pointer) + return pointer->wl_pointer(); + return nullptr; + } + if (lowerCaseResource == "wl_touch") { + auto *touch = m_integration->display()->defaultInputDevice()->touch(); + if (touch) + return touch->wl_touch(); + return nullptr; + } + return nullptr; } From 464f33e5b452e7e8b119f595353fa2e499010b2e Mon Sep 17 00:00:00 2001 From: Johan Klokkhammer Helsing Date: Fri, 23 Aug 2019 11:10:36 +0200 Subject: [PATCH 2/8] Client tests: Upgrade tests to wl_seat v5 This means that pointer events need to be followed by frame events. wl_seat version 4 is tested by the "tst_seatv4" autotest. Change-Id: Ifa8e6d6edc998853be7cd901003e619029fc6f68 Reviewed-by: Paul Olav Tvete --- .../wayland/datadevicev1/tst_datadevicev1.cpp | 8 +++- tests/auto/wayland/output/tst_output.cpp | 3 ++ .../tst_primaryselectionv1.cpp | 11 +++++- tests/auto/wayland/shared/coreprotocol.h | 2 +- tests/auto/wayland/xdgshell/tst_xdgshell.cpp | 39 +++++++++++-------- 5 files changed, 43 insertions(+), 20 deletions(-) diff --git a/tests/auto/wayland/datadevicev1/tst_datadevicev1.cpp b/tests/auto/wayland/datadevicev1/tst_datadevicev1.cpp index fe68d520d59..35ac7252866 100644 --- a/tests/auto/wayland/datadevicev1/tst_datadevicev1.cpp +++ b/tests/auto/wayland/datadevicev1/tst_datadevicev1.cpp @@ -66,7 +66,7 @@ void tst_datadevicev1::initTestCase() { QCOMPOSITOR_TRY_VERIFY(pointer()); QCOMPOSITOR_TRY_VERIFY(!pointer()->resourceMap().empty()); - QCOMPOSITOR_TRY_COMPARE(pointer()->resourceMap().first()->version(), 4); + QCOMPOSITOR_TRY_COMPARE(pointer()->resourceMap().first()->version(), 5); QCOMPOSITOR_TRY_VERIFY(keyboard()); @@ -104,8 +104,11 @@ void tst_datadevicev1::pasteAscii() keyboard()->sendEnter(surface); // Need to set keyboard focus according to protocol pointer()->sendEnter(surface, {32, 32}); + pointer()->sendFrame(client); pointer()->sendButton(client, BTN_LEFT, 1); + pointer()->sendFrame(client); pointer()->sendButton(client, BTN_LEFT, 0); + pointer()->sendFrame(client); }); QTRY_COMPARE(window.m_text, "normal ascii"); } @@ -139,8 +142,11 @@ void tst_datadevicev1::pasteUtf8() keyboard()->sendEnter(surface); // Need to set keyboard focus according to protocol pointer()->sendEnter(surface, {32, 32}); + pointer()->sendFrame(client); pointer()->sendButton(client, BTN_LEFT, 1); + pointer()->sendFrame(client); pointer()->sendButton(client, BTN_LEFT, 0); + pointer()->sendFrame(client); }); QTRY_COMPARE(window.m_text, "face with tears of joy: 😂"); } diff --git a/tests/auto/wayland/output/tst_output.cpp b/tests/auto/wayland/output/tst_output.cpp index 2d2c8efd682..29c773cf65e 100644 --- a/tests/auto/wayland/output/tst_output.cpp +++ b/tests/auto/wayland/output/tst_output.cpp @@ -196,8 +196,11 @@ void tst_output::removePrimaryScreen() exec([&] { auto *surface = xdgToplevel()->surface(); pointer()->sendEnter(surface, {32, 32}); + pointer()->sendFrame(client()); pointer()->sendButton(client(), BTN_LEFT, 1); + pointer()->sendFrame(client()); pointer()->sendButton(client(), BTN_LEFT, 0); + pointer()->sendFrame(client()); }); // Wait to make sure mouse events dont't cause a crash now that the screen has changed diff --git a/tests/auto/wayland/primaryselectionv1/tst_primaryselectionv1.cpp b/tests/auto/wayland/primaryselectionv1/tst_primaryselectionv1.cpp index 281e4c5d11a..216db85cd6b 100644 --- a/tests/auto/wayland/primaryselectionv1/tst_primaryselectionv1.cpp +++ b/tests/auto/wayland/primaryselectionv1/tst_primaryselectionv1.cpp @@ -268,7 +268,7 @@ void tst_primaryselectionv1::initTestCase() { QCOMPOSITOR_TRY_VERIFY(pointer()); QCOMPOSITOR_TRY_VERIFY(!pointer()->resourceMap().empty()); - QCOMPOSITOR_TRY_COMPARE(pointer()->resourceMap().first()->version(), 4); + QCOMPOSITOR_TRY_COMPARE(pointer()->resourceMap().first()->version(), 5); QCOMPOSITOR_TRY_VERIFY(keyboard()); } @@ -329,8 +329,11 @@ void tst_primaryselectionv1::pasteAscii() device->sendSelection(offer); pointer()->sendEnter(surface, {32, 32}); + pointer()->sendFrame(client()); pointer()->sendButton(client(), BTN_MIDDLE, 1); + pointer()->sendFrame(client()); pointer()->sendButton(client(), BTN_MIDDLE, 0); + pointer()->sendFrame(client()); }); QTRY_COMPARE(window.m_formats, QStringList{"text/plain"}); QTRY_COMPARE(window.m_text, "normal ascii"); @@ -372,8 +375,11 @@ void tst_primaryselectionv1::pasteUtf8() device->sendSelection(offer); pointer()->sendEnter(surface, {32, 32}); + pointer()->sendFrame(client()); pointer()->sendButton(client(), BTN_MIDDLE, 1); + pointer()->sendFrame(client()); pointer()->sendButton(client(), BTN_MIDDLE, 0); + pointer()->sendFrame(client()); }); QTRY_COMPARE(window.m_formats, QStringList({"text/plain", "text/plain;charset=utf-8"})); QTRY_COMPARE(window.m_text, "face with tears of joy: 😂"); @@ -428,8 +434,11 @@ void tst_primaryselectionv1::copy() auto *surface = xdgSurface()->m_surface; keyboard()->sendEnter(surface); // Need to set keyboard focus according to protocol pointer()->sendEnter(surface, {32, 32}); + pointer()->sendFrame(client()); mouseSerials << pointer()->sendButton(client(), BTN_MIDDLE, 1); + pointer()->sendFrame(client()); mouseSerials << pointer()->sendButton(client(), BTN_MIDDLE, 0); + pointer()->sendFrame(client()); }); QCOMPOSITOR_TRY_VERIFY(primarySelectionDevice()->m_selectionSource); QCOMPOSITOR_TRY_VERIFY(mouseSerials.contains(primarySelectionDevice()->m_serial)); diff --git a/tests/auto/wayland/shared/coreprotocol.h b/tests/auto/wayland/shared/coreprotocol.h index 264c5f694e6..2347a83656d 100644 --- a/tests/auto/wayland/shared/coreprotocol.h +++ b/tests/auto/wayland/shared/coreprotocol.h @@ -236,7 +236,7 @@ class Seat : public Global, public QtWaylandServer::wl_seat { Q_OBJECT public: - explicit Seat(CoreCompositor *compositor, uint capabilities = Seat::capability_pointer | Seat::capability_keyboard, int version = 4); + explicit Seat(CoreCompositor *compositor, uint capabilities = Seat::capability_pointer | Seat::capability_keyboard, int version = 5); ~Seat() override; void send_capabilities(Resource *resource, uint capabilities) = delete; // Use wrapper instead void send_capabilities(uint capabilities) = delete; // Use wrapper instead diff --git a/tests/auto/wayland/xdgshell/tst_xdgshell.cpp b/tests/auto/wayland/xdgshell/tst_xdgshell.cpp index c887e5d4442..ac5c24988f8 100644 --- a/tests/auto/wayland/xdgshell/tst_xdgshell.cpp +++ b/tests/auto/wayland/xdgshell/tst_xdgshell.cpp @@ -214,12 +214,13 @@ void tst_xdgshell::popup() uint clickSerial = exec([=] { auto *surface = xdgToplevel()->surface(); auto *p = pointer(); + auto *c = client(); p->sendEnter(surface, {100, 100}); -// p->sendFrame(); //TODO: uncomment when we support seat v5 + p->sendFrame(c); uint serial = p->sendButton(client(), BTN_LEFT, Pointer::button_state_pressed); - p->sendButton(client(), BTN_LEFT, Pointer::button_state_released); + p->sendButton(c, BTN_LEFT, Pointer::button_state_released); return serial; -// p->sendFrame(); //TODO: uncomment when we support seat v5 + p->sendFrame(c); }); QTRY_VERIFY(window.m_popup); @@ -298,13 +299,14 @@ void tst_xdgshell::tooltipOnPopup() exec([=] { auto *surface = xdgToplevel()->surface(); auto *p = pointer(); + auto *c = client(); p->sendEnter(surface, {100, 100}); -// p->sendFrame(); //TODO: uncomment when we support seat v5 + p->sendFrame(c); p->sendButton(client(), BTN_LEFT, Pointer::button_state_pressed); p->sendButton(client(), BTN_LEFT, Pointer::button_state_released); -// p->sendFrame(); + p->sendFrame(c); p->sendLeave(surface); -// p->sendFrame(); + p->sendFrame(c); }); QCOMPOSITOR_TRY_VERIFY(xdgPopup()); @@ -315,11 +317,12 @@ void tst_xdgshell::tooltipOnPopup() exec([=] { auto *surface = xdgPopup()->surface(); auto *p = pointer(); + auto *c = client(); p->sendEnter(surface, {100, 100}); -// p->sendFrame(); + p->sendFrame(c); p->sendButton(client(), BTN_LEFT, Pointer::button_state_pressed); p->sendButton(client(), BTN_LEFT, Pointer::button_state_released); -// p->sendFrame(); + p->sendFrame(c); }); QCOMPOSITOR_TRY_VERIFY(xdgPopup(1)); @@ -380,13 +383,14 @@ void tst_xdgshell::switchPopups() exec([=] { auto *surface = xdgToplevel()->surface(); auto *p = pointer(); + auto *c = client(); p->sendEnter(surface, {100, 100}); -// p->sendFrame(); //TODO: uncomment when we support seat v5 - p->sendButton(client(), BTN_LEFT, Pointer::button_state_pressed); - p->sendButton(client(), BTN_LEFT, Pointer::button_state_released); -// p->sendFrame(); + p->sendFrame(c); + p->sendButton(c, BTN_LEFT, Pointer::button_state_pressed); + p->sendButton(c, BTN_LEFT, Pointer::button_state_released); + p->sendFrame(c); p->sendLeave(surface); -// p->sendFrame(); + p->sendFrame(c); }); QCOMPOSITOR_TRY_VERIFY(xdgPopup()); @@ -399,11 +403,12 @@ void tst_xdgshell::switchPopups() exec([=] { auto *surface = xdgToplevel()->surface(); auto *p = pointer(); + auto *c = client(); p->sendEnter(surface, {100, 100}); -// p->sendFrame(); - p->sendButton(client(), BTN_LEFT, Pointer::button_state_pressed); - p->sendButton(client(), BTN_LEFT, Pointer::button_state_released); -// p->sendFrame(); + p->sendFrame(c); + p->sendButton(c, BTN_LEFT, Pointer::button_state_pressed); + p->sendButton(c, BTN_LEFT, Pointer::button_state_released); + p->sendFrame(c); }); // The client will now hide one popup and then show another From b36c46f2d6f483cb1c8ed3b3adb0ab92fa46e09d Mon Sep 17 00:00:00 2001 From: Johan Klokkhammer Helsing Date: Fri, 23 Aug 2019 09:17:07 +0200 Subject: [PATCH 3/8] Client tests: Remove redundant pointer helper function Change-Id: If5d435a227b54f566f121331385e849b615fb615 Reviewed-by: Paul Olav Tvete --- tests/auto/wayland/seatv5/tst_seatv5.cpp | 7 ------- 1 file changed, 7 deletions(-) diff --git a/tests/auto/wayland/seatv5/tst_seatv5.cpp b/tests/auto/wayland/seatv5/tst_seatv5.cpp index 5b9235d9aa3..4e5d6ccecac 100644 --- a/tests/auto/wayland/seatv5/tst_seatv5.cpp +++ b/tests/auto/wayland/seatv5/tst_seatv5.cpp @@ -46,13 +46,6 @@ public: add(capabilities, version); }); } - - Pointer *pointer() - { - auto *seat = get(); - Q_ASSERT(seat); - return seat->m_pointer; - } }; class tst_seatv5 : public QObject, private SeatV5Compositor From c0d8e3dc36b7e19fca711b81dd406a546219ad9e Mon Sep 17 00:00:00 2001 From: Johan Klokkhammer Helsing Date: Fri, 23 Aug 2019 09:19:03 +0200 Subject: [PATCH 4/8] Client tests: Add missing cleanup for keyboards Change-Id: Ia085dbe34b6e3b7cf83b4f55c265e12b1145ab8a Reviewed-by: Paul Olav Tvete --- tests/auto/wayland/shared/coreprotocol.cpp | 3 +++ 1 file changed, 3 insertions(+) diff --git a/tests/auto/wayland/shared/coreprotocol.cpp b/tests/auto/wayland/shared/coreprotocol.cpp index f9335e7834a..fcc9f311c4a 100644 --- a/tests/auto/wayland/shared/coreprotocol.cpp +++ b/tests/auto/wayland/shared/coreprotocol.cpp @@ -191,6 +191,9 @@ Seat::~Seat() { qDeleteAll(m_oldPointers); delete m_pointer; + + qDeleteAll(m_oldKeyboards); + delete m_keyboard; } void Seat::setCapabilities(uint capabilities) { From ae5db4fec199b25fa55fb0a3659f70ca94b1a0eb Mon Sep 17 00:00:00 2001 From: Johan Klokkhammer Helsing Date: Fri, 23 Aug 2019 09:20:00 +0200 Subject: [PATCH 5/8] Client tests: Fix incorrect test for keyboard capability Change-Id: I4e35e86f489941dcce986ba416f3fe55d968d186 Reviewed-by: Paul Olav Tvete --- tests/auto/wayland/shared/coreprotocol.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/tests/auto/wayland/shared/coreprotocol.cpp b/tests/auto/wayland/shared/coreprotocol.cpp index fcc9f311c4a..5f51e417729 100644 --- a/tests/auto/wayland/shared/coreprotocol.cpp +++ b/tests/auto/wayland/shared/coreprotocol.cpp @@ -239,7 +239,7 @@ void Seat::seat_get_pointer(Resource *resource, uint32_t id) void Seat::seat_get_keyboard(QtWaylandServer::wl_seat::Resource *resource, uint32_t id) { - if (~m_capabilities & capability_pointer) { + if (~m_capabilities & capability_keyboard) { qWarning() << "Client requested a wl_keyboard without the capability being available." << "This Could be a race condition when hotunplugging," << "but is most likely a client error"; From 74e3dd6d609a50aaf807bfef76fe8b63b1675161 Mon Sep 17 00:00:00 2001 From: Johan Klokkhammer Helsing Date: Fri, 23 Aug 2019 09:25:56 +0200 Subject: [PATCH 6/8] Client tests: Add touch infrastructure and simple test This doesn't test much, but adds the infrastructure needed for more thorough tests later on. More or less exactly matches the mocking for wl_keyboard and wl_pointer. Change-Id: I563bb9be7ccaaf0aa83611e84d051cc307455ccb Reviewed-by: Paul Olav Tvete --- tests/auto/wayland/seatv5/tst_seatv5.cpp | 13 ++++++++- tests/auto/wayland/shared/coreprotocol.cpp | 29 ++++++++++++++++++-- tests/auto/wayland/shared/coreprotocol.h | 16 +++++++++-- tests/auto/wayland/shared/mockcompositor.cpp | 2 +- tests/auto/wayland/shared/mockcompositor.h | 1 + 5 files changed, 54 insertions(+), 7 deletions(-) diff --git a/tests/auto/wayland/seatv5/tst_seatv5.cpp b/tests/auto/wayland/seatv5/tst_seatv5.cpp index 4e5d6ccecac..c2b1b0e4b4d 100644 --- a/tests/auto/wayland/seatv5/tst_seatv5.cpp +++ b/tests/auto/wayland/seatv5/tst_seatv5.cpp @@ -41,7 +41,7 @@ public: removeAll(); - uint capabilities = MockCompositor::Seat::capability_pointer; + uint capabilities = MockCompositor::Seat::capability_pointer | MockCompositor::Seat::capability_touch; int version = 5; add(capabilities, version); }); @@ -54,6 +54,8 @@ class tst_seatv5 : public QObject, private SeatV5Compositor private slots: void cleanup() { QTRY_VERIFY2(isClean(), qPrintable(dirtyMessage())); } void bindsToSeat(); + + // Pointer tests void createsPointer(); void setsCursorOnEnter(); void usesEnterSerial(); @@ -62,6 +64,9 @@ private slots: void fingerScroll(); void fingerScrollSlow(); void wheelDiscreteScroll(); + + // Touch tests + void createsTouch(); }; void tst_seatv5::bindsToSeat() @@ -376,5 +381,11 @@ void tst_seatv5::wheelDiscreteScroll() } } +void tst_seatv5::createsTouch() +{ + QCOMPOSITOR_TRY_COMPARE(touch()->resourceMap().size(), 1); + QCOMPOSITOR_TRY_COMPARE(touch()->resourceMap().first()->version(), 5); +} + QCOMPOSITOR_TEST_MAIN(tst_seatv5) #include "tst_seatv5.moc" diff --git a/tests/auto/wayland/shared/coreprotocol.cpp b/tests/auto/wayland/shared/coreprotocol.cpp index 5f51e417729..006c4a80bde 100644 --- a/tests/auto/wayland/shared/coreprotocol.cpp +++ b/tests/auto/wayland/shared/coreprotocol.cpp @@ -192,14 +192,14 @@ Seat::~Seat() qDeleteAll(m_oldPointers); delete m_pointer; + qDeleteAll(m_oldTouchs); + delete m_touch; + qDeleteAll(m_oldKeyboards); delete m_keyboard; } void Seat::setCapabilities(uint capabilities) { - // TODO: Add support for touch - Q_ASSERT(~capabilities & capability_touch); - m_capabilities = capabilities; if (m_capabilities & capability_pointer) { @@ -210,6 +210,14 @@ void Seat::setCapabilities(uint capabilities) { m_pointer = nullptr; } + if (m_capabilities & capability_touch) { + if (!m_touch) + m_touch = (new Touch(this)); + } else if (m_touch) { + m_oldTouchs << m_touch; + m_touch = nullptr; + } + if (m_capabilities & capability_keyboard) { if (!m_keyboard) m_keyboard = (new Keyboard(this)); @@ -237,6 +245,21 @@ void Seat::seat_get_pointer(Resource *resource, uint32_t id) m_pointer->add(resource->client(), id, resource->version()); } +void Seat::seat_get_touch(QtWaylandServer::wl_seat::Resource *resource, uint32_t id) +{ + if (~m_capabilities & capability_touch) { + qWarning() << "Client requested a wl_touch without the capability being available." + << "This Could be a race condition when hotunplugging," + << "but is most likely a client error"; + Touch *touch = new Touch(this); + touch->add(resource->client(), id, resource->version()); + // TODO: mark as destroyed + m_oldTouchs << touch; + return; + } + m_touch->add(resource->client(), id, resource->version()); +} + void Seat::seat_get_keyboard(QtWaylandServer::wl_seat::Resource *resource, uint32_t id) { if (~m_capabilities & capability_keyboard) { diff --git a/tests/auto/wayland/shared/coreprotocol.h b/tests/auto/wayland/shared/coreprotocol.h index 2347a83656d..6905ab5d54b 100644 --- a/tests/auto/wayland/shared/coreprotocol.h +++ b/tests/auto/wayland/shared/coreprotocol.h @@ -38,6 +38,7 @@ namespace MockCompositor { class WlCompositor; class Output; class Pointer; +class Touch; class Keyboard; class CursorRole; class ShmPool; @@ -236,7 +237,7 @@ class Seat : public Global, public QtWaylandServer::wl_seat { Q_OBJECT public: - explicit Seat(CoreCompositor *compositor, uint capabilities = Seat::capability_pointer | Seat::capability_keyboard, int version = 5); + explicit Seat(CoreCompositor *compositor, uint capabilities = Seat::capability_pointer | Seat::capability_keyboard | Seat::capability_touch, int version = 5); ~Seat() override; void send_capabilities(Resource *resource, uint capabilities) = delete; // Use wrapper instead void send_capabilities(uint capabilities) = delete; // Use wrapper instead @@ -247,6 +248,9 @@ public: Pointer* m_pointer = nullptr; QVector m_oldPointers; + Touch* m_touch = nullptr; + QVector m_oldTouchs; + Keyboard* m_keyboard = nullptr; QVector m_oldKeyboards; @@ -259,8 +263,8 @@ protected: } void seat_get_pointer(Resource *resource, uint32_t id) override; + void seat_get_touch(Resource *resource, uint32_t id) override; void seat_get_keyboard(Resource *resource, uint32_t id) override; -// void seat_get_touch(Resource *resource, uint32_t id) override; // void seat_release(Resource *resource) override; }; @@ -307,6 +311,14 @@ public: Surface *m_surface = nullptr; }; +class Touch : public QObject, public QtWaylandServer::wl_touch +{ + Q_OBJECT +public: + explicit Touch(Seat *seat) : m_seat(seat) {} + Seat *m_seat = nullptr; +}; + class Keyboard : public QObject, public QtWaylandServer::wl_keyboard { Q_OBJECT diff --git a/tests/auto/wayland/shared/mockcompositor.cpp b/tests/auto/wayland/shared/mockcompositor.cpp index 6b9af4295b8..5f2d89078e5 100644 --- a/tests/auto/wayland/shared/mockcompositor.cpp +++ b/tests/auto/wayland/shared/mockcompositor.cpp @@ -41,7 +41,7 @@ DefaultCompositor::DefaultCompositor() add(); auto *output = add(); output->m_data.physicalSize = output->m_data.mode.physicalSizeForDpi(96); - add(Seat::capability_pointer | Seat::capability_keyboard); + add(Seat::capability_pointer | Seat::capability_keyboard | Seat::capability_touch); add(); add(); // TODO: other shells, viewporter, xdgoutput etc diff --git a/tests/auto/wayland/shared/mockcompositor.h b/tests/auto/wayland/shared/mockcompositor.h index aa85a4aeace..3cb9b337c7c 100644 --- a/tests/auto/wayland/shared/mockcompositor.h +++ b/tests/auto/wayland/shared/mockcompositor.h @@ -60,6 +60,7 @@ public: XdgToplevel *xdgToplevel(int i = 0) { return get()->toplevel(i); } XdgPopup *xdgPopup(int i = 0) { return get()->popup(i); } Pointer *pointer() { auto *seat = get(); Q_ASSERT(seat); return seat->m_pointer; } + Touch *touch() { auto *seat = get(); Q_ASSERT(seat); return seat->m_touch; } Surface *cursorSurface() { auto *p = pointer(); return p ? p->cursorSurface() : nullptr; } Keyboard *keyboard() { auto *seat = get(); Q_ASSERT(seat); return seat->m_keyboard; } uint sendXdgShellPing(); From 0d745e8b28e6f1b1d731390095ec15db7617cc81 Mon Sep 17 00:00:00 2001 From: Johan Klokkhammer Helsing Date: Tue, 20 Aug 2019 14:12:51 +0200 Subject: [PATCH 7/8] Client: Don't try to disconnect destroy handler from destroyed objects Gets rid of warning about disconnecting null objects on application exit. Change-Id: Ie96d4321dfab113622d7059f6849acf15715dfa2 Reviewed-by: Pier Luigi Fiorini --- src/plugins/platforms/wayland/qwaylandinputdevice.cpp | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/src/plugins/platforms/wayland/qwaylandinputdevice.cpp b/src/plugins/platforms/wayland/qwaylandinputdevice.cpp index 65f80f308bb..8aa0239d079 100644 --- a/src/plugins/platforms/wayland/qwaylandinputdevice.cpp +++ b/src/plugins/platforms/wayland/qwaylandinputdevice.cpp @@ -789,8 +789,10 @@ void QWaylandInputDevice::Pointer::pointer_button(uint32_t serial, uint32_t time void QWaylandInputDevice::Pointer::invalidateFocus() { - disconnect(mFocus.data(), &QObject::destroyed, this, &Pointer::handleFocusDestroyed); - mFocus = nullptr; + if (mFocus) { + disconnect(mFocus.data(), &QObject::destroyed, this, &Pointer::handleFocusDestroyed); + mFocus = nullptr; + } mEnterSerial = 0; } From 68bbf5fd1c9dcd07a9b37c51a6beb46a7e98227b Mon Sep 17 00:00:00 2001 From: Johan Klokkhammer Helsing Date: Fri, 23 Aug 2019 09:25:56 +0200 Subject: [PATCH 8/8] Client tests: Add test for a simple wl_touch tap Change-Id: I35aec950da0ac0d10cf1fa0c4bc1f56ba232cf89 Reviewed-by: Paul Olav Tvete --- tests/auto/wayland/seatv5/tst_seatv5.cpp | 60 ++++++++++++++++++++++ tests/auto/wayland/shared/coreprotocol.cpp | 34 ++++++++++++ tests/auto/wayland/shared/coreprotocol.h | 4 ++ 3 files changed, 98 insertions(+) diff --git a/tests/auto/wayland/seatv5/tst_seatv5.cpp b/tests/auto/wayland/seatv5/tst_seatv5.cpp index c2b1b0e4b4d..76a68b86f04 100644 --- a/tests/auto/wayland/seatv5/tst_seatv5.cpp +++ b/tests/auto/wayland/seatv5/tst_seatv5.cpp @@ -67,6 +67,7 @@ private slots: // Touch tests void createsTouch(); + void singleTap(); }; void tst_seatv5::bindsToSeat() @@ -387,5 +388,64 @@ void tst_seatv5::createsTouch() QCOMPOSITOR_TRY_COMPARE(touch()->resourceMap().first()->version(), 5); } +class TouchWindow : public QRasterWindow { +public: + TouchWindow() + { + resize(64, 64); + show(); + } + void touchEvent(QTouchEvent *event) override + { + QRasterWindow::touchEvent(event); + m_events.append(Event{event}); + } + struct Event // Because I didn't find a convenient way to copy it entirely + { + explicit Event() = default; + explicit Event(const QTouchEvent *event) + : type(event->type()) + , touchPointStates(event->touchPointStates()) + , touchPoints(event->touchPoints()) + { + } + const QEvent::Type type{}; + const Qt::TouchPointStates touchPointStates{}; + const QList touchPoints; + }; + QVector m_events; +}; + +void tst_seatv5::singleTap() +{ + TouchWindow window; + QCOMPOSITOR_TRY_VERIFY(xdgSurface() && xdgSurface()->m_committedConfigureSerial); + + exec([=] { + auto *t = touch(); + auto *c = client(); + t->sendDown(xdgToplevel()->surface(), {32, 32}, 1); + t->sendFrame(c); + t->sendUp(c, 1); + t->sendFrame(c); + }); + + QTRY_VERIFY(!window.m_events.empty()); + { + auto e = window.m_events.takeFirst(); + QCOMPARE(e.type, QEvent::TouchBegin); + QCOMPARE(e.touchPointStates, Qt::TouchPointState::TouchPointPressed); + QCOMPARE(e.touchPoints.length(), 1); + QCOMPARE(e.touchPoints.first().pos(), QPointF(32-window.frameMargins().left(), 32-window.frameMargins().top())); + } + { + auto e = window.m_events.takeFirst(); + QCOMPARE(e.type, QEvent::TouchEnd); + QCOMPARE(e.touchPointStates, Qt::TouchPointState::TouchPointReleased); + QCOMPARE(e.touchPoints.length(), 1); + QCOMPARE(e.touchPoints.first().pos(), QPointF(32-window.frameMargins().left(), 32-window.frameMargins().top())); + } +} + QCOMPOSITOR_TEST_MAIN(tst_seatv5) #include "tst_seatv5.moc" diff --git a/tests/auto/wayland/shared/coreprotocol.cpp b/tests/auto/wayland/shared/coreprotocol.cpp index 006c4a80bde..120c256c653 100644 --- a/tests/auto/wayland/shared/coreprotocol.cpp +++ b/tests/auto/wayland/shared/coreprotocol.cpp @@ -397,6 +397,40 @@ void Pointer::pointer_set_cursor(Resource *resource, uint32_t serial, wl_resourc emit setCursor(serial); } +uint Touch::sendDown(Surface *surface, const QPointF &position, int id) +{ + wl_fixed_t x = wl_fixed_from_double(position.x()); + wl_fixed_t y = wl_fixed_from_double(position.y()); + uint serial = m_seat->m_compositor->nextSerial(); + auto time = m_seat->m_compositor->currentTimeMilliseconds(); + wl_client *client = surface->resource()->client(); + + const auto touchResources = resourceMap().values(client); + for (auto *r : touchResources) + wl_touch::send_down(r->handle, serial, time, surface->resource()->handle, id, x, y); + + return serial; +} + +uint Touch::sendUp(wl_client *client, int id) +{ + uint serial = m_seat->m_compositor->nextSerial(); + auto time = m_seat->m_compositor->currentTimeMilliseconds(); + + const auto touchResources = resourceMap().values(client); + for (auto *r : touchResources) + wl_touch::send_up(r->handle, serial, time, id); + + return serial; +} + +void Touch::sendFrame(wl_client *client) +{ + const auto touchResources = resourceMap().values(client); + for (auto *r : touchResources) + send_frame(r->handle); +} + uint Keyboard::sendEnter(Surface *surface) { auto serial = m_seat->m_compositor->nextSerial(); diff --git a/tests/auto/wayland/shared/coreprotocol.h b/tests/auto/wayland/shared/coreprotocol.h index 6905ab5d54b..50812c29658 100644 --- a/tests/auto/wayland/shared/coreprotocol.h +++ b/tests/auto/wayland/shared/coreprotocol.h @@ -316,6 +316,10 @@ class Touch : public QObject, public QtWaylandServer::wl_touch Q_OBJECT public: explicit Touch(Seat *seat) : m_seat(seat) {} + uint sendDown(Surface *surface, const QPointF &position, int id); + uint sendUp(wl_client *client, int id); + void sendFrame(wl_client *client); + Seat *m_seat = nullptr; };