From: Samuel Rødal Date: Wed, 7 Mar 2012 09:40:31 +0000 (+0100) Subject: Added testing of key events to client auto test. X-Git-Tag: TIZEN~117 X-Git-Url: http://review.tizen.org/git/?a=commitdiff_plain;h=609b8a18d0fb10cbee4a71a68ccee25a29fb071b;p=profile%2Fivi%2Fqtwayland.git Added testing of key events to client auto test. This requires passing on the native key code as well when calling into QWindowSystemInterface from QWaylandInputDevice. Change-Id: Iea1f98dcc9e050bb42cc48927da17aa54085a5e8 Reviewed-by: Laszlo Agocs --- diff --git a/src/plugins/platforms/wayland/qwaylandinputdevice.cpp b/src/plugins/platforms/wayland/qwaylandinputdevice.cpp index 98980e6..8731439 100644 --- a/src/plugins/platforms/wayland/qwaylandinputdevice.cpp +++ b/src/plugins/platforms/wayland/qwaylandinputdevice.cpp @@ -307,18 +307,20 @@ void QWaylandInputDevice::inputHandleKey(void *data, sym = translateKey(sym, s, sizeof s); if (window) { - QWindowSystemInterface::handleKeyEvent(window->window(), - time, type, sym, - inputDevice->mModifiers, - QString::fromLatin1(s)); + QWindowSystemInterface::handleExtendedKeyEvent(window->window(), + time, type, sym, + inputDevice->mModifiers, + code, 0, 0, + QString::fromLatin1(s)); } #else // Generic fallback for single hard keys: Assume 'key' is a Qt key code. if (window) { - QWindowSystemInterface::handleKeyEvent(window->window(), - time, state ? QEvent::KeyPress : QEvent::KeyRelease, - key + 8, // qt-compositor substracts 8 for some reason - inputDevice->mModifiers); + QWindowSystemInterface::handleExtendedKeyEvent(window->window(), + time, state ? QEvent::KeyPress : QEvent::KeyRelease, + key + 8, // qt-compositor substracts 8 for some reason + inputDevice->mModifiers, + key + 8, 0, 0); } #endif } diff --git a/tests/auto/client/mockcompositor.cpp b/tests/auto/client/mockcompositor.cpp index 39bd6e3..c751bcc 100644 --- a/tests/auto/client/mockcompositor.cpp +++ b/tests/auto/client/mockcompositor.cpp @@ -114,6 +114,20 @@ void MockCompositor::sendMouseRelease(const QSharedPointer &surface processCommand(command); } +void MockCompositor::sendKeyPress(const QSharedPointer &surface, uint code) +{ + Command command = makeCommand(Impl::Compositor::sendKeyPress, m_compositor); + command.parameters << QVariant::fromValue(surface) << code; + processCommand(command); +} + +void MockCompositor::sendKeyRelease(const QSharedPointer &surface, uint code) +{ + Command command = makeCommand(Impl::Compositor::sendKeyRelease, m_compositor); + command.parameters << QVariant::fromValue(surface) << code; + processCommand(command); +} + QSharedPointer MockCompositor::surface() { QSharedPointer result; diff --git a/tests/auto/client/mockcompositor.h b/tests/auto/client/mockcompositor.h index ece1972..18de0e6 100644 --- a/tests/auto/client/mockcompositor.h +++ b/tests/auto/client/mockcompositor.h @@ -80,6 +80,8 @@ public: static void setKeyboardFocus(void *data, const QList ¶meters); static void sendMousePress(void *data, const QList ¶meters); static void sendMouseRelease(void *data, const QList ¶meters); + static void sendKeyPress(void *data, const QList ¶meters); + static void sendKeyRelease(void *data, const QList ¶meters); private: static void bindCompositor(wl_client *client, void *data, uint32_t version, uint32_t id); @@ -142,6 +144,8 @@ public: void setKeyboardFocus(const QSharedPointer &surface); void sendMousePress(const QSharedPointer &surface, const QPoint &pos); void sendMouseRelease(const QSharedPointer &surface); + void sendKeyPress(const QSharedPointer &surface, uint code); + void sendKeyRelease(const QSharedPointer &surface, uint code); QSharedPointer surface(); diff --git a/tests/auto/client/mockinput.cpp b/tests/auto/client/mockinput.cpp index 9d6286d..b5c90d7 100644 --- a/tests/auto/client/mockinput.cpp +++ b/tests/auto/client/mockinput.cpp @@ -121,5 +121,26 @@ void Compositor::sendMouseRelease(void *data, const QList ¶meters) wl_input_device_send_button(compositor->m_input.pointer_focus_resource, compositor->time(), 0x110, 0); } +void Compositor::sendKeyPress(void *data, const QList ¶meters) +{ + Compositor *compositor = static_cast(data); + wl_surface *surface = resolveSurface(parameters.first()); + if (!surface) + return; + + QPoint pos = parameters.last().toPoint(); + wl_input_device_send_key(compositor->m_input.keyboard_focus_resource, compositor->time(), parameters.last().toUInt() - 8, 1); +} + +void Compositor::sendKeyRelease(void *data, const QList ¶meters) +{ + Compositor *compositor = static_cast(data); + wl_surface *surface = resolveSurface(parameters.first()); + if (!surface) + return; + + wl_input_device_send_key(compositor->m_input.keyboard_focus_resource, compositor->time(), parameters.last().toUInt() - 8, 0); +} + } diff --git a/tests/auto/client/tst_client.cpp b/tests/auto/client/tst_client.cpp index fdcb129..9b63337 100644 --- a/tests/auto/client/tst_client.cpp +++ b/tests/auto/client/tst_client.cpp @@ -55,6 +55,7 @@ public: , keyReleaseEventCount(0) , mousePressEventCount(0) , mouseReleaseEventCount(0) + , keyCode(0) { setSurfaceType(QSurface::RasterSurface); setGeometry(0, 0, 32, 32); @@ -71,14 +72,16 @@ public: ++focusOutEventCount; } - void keyPressEvent(QKeyEvent *) + void keyPressEvent(QKeyEvent *event) { ++keyPressEventCount; + keyCode = event->nativeScanCode(); } - void keyReleaseEvent(QKeyEvent *) + void keyReleaseEvent(QKeyEvent *event) { ++keyReleaseEventCount; + keyCode = event->nativeScanCode(); } void mousePressEvent(QMouseEvent *event) @@ -99,6 +102,7 @@ public: int mousePressEventCount; int mouseReleaseEventCount; + uint keyCode; QPoint mousePressPos; }; @@ -166,6 +170,17 @@ void tst_WaylandClient::events() QTRY_COMPARE(window.focusInEventCount, 2); QTRY_COMPARE(QGuiApplication::focusWindow(), &window); + uint keyCode = 80; // arbitrarily chosen + QCOMPARE(window.keyPressEventCount, 0); + compositor->sendKeyPress(surface, keyCode); + QTRY_COMPARE(window.keyPressEventCount, 1); + QTRY_COMPARE(window.keyCode, keyCode); + + QCOMPARE(window.keyReleaseEventCount, 0); + compositor->sendKeyRelease(surface, keyCode); + QTRY_COMPARE(window.keyReleaseEventCount, 1); + QCOMPARE(window.keyCode, keyCode); + QPoint mousePressPos(16, 16); QCOMPARE(window.mousePressEventCount, 0); compositor->sendMousePress(surface, mousePressPos);