From 33487c06d6613dcd3531f665f2648d94336630c8 Mon Sep 17 00:00:00 2001 From: Julius Zint Date: Sat, 26 Feb 2022 09:22:31 +0100 Subject: [PATCH] Add all three VirtualInputDevices for autotests [3/6] Make autotests create fake input devices This commit adds back all three VirtualInputDevices for simulating keyboard, touch and pointer input events from autotests. --- autotests/integration/kwin_wayland_test.cpp | 42 +++++++++++++++++++++ autotests/integration/kwin_wayland_test.h | 16 ++++++++ 2 files changed, 58 insertions(+) diff --git a/autotests/integration/kwin_wayland_test.cpp b/autotests/integration/kwin_wayland_test.cpp index 3c14b1ad90..5d299fa153 100644 --- a/autotests/integration/kwin_wayland_test.cpp +++ b/autotests/integration/kwin_wayland_test.cpp @@ -87,12 +87,39 @@ WaylandTestApplication::~WaylandTestApplication() } delete m_xwayland; m_xwayland = nullptr; + destroyVirtualInputDevices(); destroyWorkspace(); destroyInputMethod(); destroyCompositor(); destroyInput(); } +void WaylandTestApplication::createVirtualInputDevices() +{ + m_virtualKeyboard.reset(new Test::VirtualInputDevice()); + m_virtualKeyboard->setName(QStringLiteral("Virtual Keyboard 1")); + m_virtualKeyboard->setKeyboard(true); + + m_virtualPointer.reset(new Test::VirtualInputDevice()); + m_virtualPointer->setName(QStringLiteral("Virtual Pointer 1")); + m_virtualPointer->setPointer(true); + + m_virtualTouch.reset(new Test::VirtualInputDevice()); + m_virtualTouch->setName(QStringLiteral("Virtual Touch 1")); + m_virtualTouch->setTouch(true); + + input()->addInputDevice(m_virtualPointer.get()); + input()->addInputDevice(m_virtualTouch.get()); + input()->addInputDevice(m_virtualKeyboard.get()); +} + +void WaylandTestApplication::destroyVirtualInputDevices() +{ + input()->removeInputDevice(m_virtualPointer.get()); + input()->removeInputDevice(m_virtualTouch.get()); + input()->removeInputDevice(m_virtualKeyboard.get()); +} + void WaylandTestApplication::performStartup() { if (!m_inputMethodServerToStart.isEmpty()) { @@ -114,6 +141,7 @@ void WaylandTestApplication::performStartup() // try creating the Wayland Backend createInput(); createPlugins(); + createVirtualInputDevices(); if (!platform()->enabledOutputs().isEmpty()) { continueStartupWithScreens(); @@ -160,4 +188,18 @@ void WaylandTestApplication::continueStartupWithScene() m_xwayland->start(); } +Test::VirtualInputDevice *WaylandTestApplication::virtualPointer() const +{ + return m_virtualPointer.get(); +} + +Test::VirtualInputDevice *WaylandTestApplication::virtualKeyboard() const +{ + return m_virtualKeyboard.get(); +} + +Test::VirtualInputDevice *WaylandTestApplication::virtualTouch() const +{ + return m_virtualTouch.get(); +} } diff --git a/autotests/integration/kwin_wayland_test.h b/autotests/integration/kwin_wayland_test.h index 9e7ebeadf4..3fc7206d25 100644 --- a/autotests/integration/kwin_wayland_test.h +++ b/autotests/integration/kwin_wayland_test.h @@ -64,6 +64,10 @@ class Xwayland; } class AbstractClient; +namespace Test +{ +class VirtualInputDevice; +} class WaylandTestApplication : public ApplicationWaylandAbstract { @@ -75,6 +79,11 @@ public: void setInputMethodServerToStart(const QString &inputMethodServer) { m_inputMethodServerToStart = inputMethodServer; } + + Test::VirtualInputDevice *virtualPointer() const; + Test::VirtualInputDevice *virtualKeyboard() const; + Test::VirtualInputDevice *virtualTouch() const; + protected: void performStartup() override; @@ -83,8 +92,15 @@ private: void continueStartupWithScene(); void finalizeStartup(); + void createVirtualInputDevices(); + void destroyVirtualInputDevices(); + Xwl::Xwayland *m_xwayland = nullptr; QString m_inputMethodServerToStart; + + QScopedPointer m_virtualPointer; + QScopedPointer m_virtualKeyboard; + QScopedPointer m_virtualTouch; }; namespace Test