Move VirtualInputDevice to autotests

[1/6] Make autotests create fake input devices

The goal of this patch set is simulating user input in unit tests via
InputDevices and no longer use the Platform to fake input. This matches
more closely with how input is processed when running a full plasma
wayland session, i.e. with the DRM and libinput backends.
This commit is contained in:
Julius Zint 2022-02-23 13:53:23 +01:00 committed by Vlad Zahorodnii
parent 4b810833b5
commit 3134198a30
4 changed files with 139 additions and 207 deletions

View file

@ -10,6 +10,7 @@
#define KWIN_WAYLAND_TEST_H
#include "abstract_client.h"
#include "inputdevice.h"
#include "main.h"
// Qt
@ -460,6 +461,45 @@ enum class AdditionalWaylandInterface {
OutputDeviceV2 = 1 << 14,
};
Q_DECLARE_FLAGS(AdditionalWaylandInterfaces, AdditionalWaylandInterface)
class VirtualInputDevice : public InputDevice
{
Q_OBJECT
public:
explicit VirtualInputDevice(QObject *parent = nullptr);
void setPointer(bool set);
void setKeyboard(bool set);
void setTouch(bool set);
void setName(const QString &name);
QString sysName() const override;
QString name() const override;
bool isEnabled() const override;
void setEnabled(bool enabled) override;
LEDs leds() const override;
void setLeds(LEDs leds) override;
bool isKeyboard() const override;
bool isAlphaNumericKeyboard() const override;
bool isPointer() const override;
bool isTouchpad() const override;
bool isTouch() const override;
bool isTabletTool() const override;
bool isTabletPad() const override;
bool isTabletModeSwitch() const override;
bool isLidSwitch() const override;
private:
QString m_name;
bool m_pointer = false;
bool m_keyboard = false;
bool m_touch = false;
};
/**
* Creates a Wayland Connection in a dedicated thread and creates various
* client side objects which can be used to create windows.

View file

@ -1272,5 +1272,104 @@ uint32_t WaylandOutputDeviceV2::rgbRange() const
return m_rgbRange;
}
VirtualInputDevice::VirtualInputDevice(QObject *parent)
: InputDevice(parent)
{
}
void VirtualInputDevice::setPointer(bool set)
{
m_pointer = set;
}
void VirtualInputDevice::setKeyboard(bool set)
{
m_keyboard = set;
}
void VirtualInputDevice::setTouch(bool set)
{
m_touch = set;
}
void VirtualInputDevice::setName(const QString &name)
{
m_name = name;
}
QString VirtualInputDevice::sysName() const
{
return QString();
}
QString VirtualInputDevice::name() const
{
return m_name;
}
bool VirtualInputDevice::isEnabled() const
{
return true;
}
void VirtualInputDevice::setEnabled(bool enabled)
{
Q_UNUSED(enabled)
}
LEDs VirtualInputDevice::leds() const
{
return LEDs();
}
void VirtualInputDevice::setLeds(LEDs leds)
{
Q_UNUSED(leds)
}
bool VirtualInputDevice::isKeyboard() const
{
return m_keyboard;
}
bool VirtualInputDevice::isAlphaNumericKeyboard() const
{
return m_keyboard;
}
bool VirtualInputDevice::isPointer() const
{
return m_pointer;
}
bool VirtualInputDevice::isTouchpad() const
{
return false;
}
bool VirtualInputDevice::isTouch() const
{
return m_touch;
}
bool VirtualInputDevice::isTabletTool() const
{
return false;
}
bool VirtualInputDevice::isTabletPad() const
{
return false;
}
bool VirtualInputDevice::isTabletModeSwitch() const
{
return false;
}
bool VirtualInputDevice::isLidSwitch() const
{
return false;
}
}
}

View file

@ -22,135 +22,10 @@
namespace KWin
{
VirtualInputDevice::VirtualInputDevice(QObject *parent)
: InputDevice(parent)
{
}
void VirtualInputDevice::setPointer(bool set)
{
m_pointer = set;
}
void VirtualInputDevice::setKeyboard(bool set)
{
m_keyboard = set;
}
void VirtualInputDevice::setTouch(bool set)
{
m_touch = set;
}
void VirtualInputDevice::setName(const QString &name)
{
m_name = name;
}
QString VirtualInputDevice::sysName() const
{
return QString();
}
QString VirtualInputDevice::name() const
{
return m_name;
}
bool VirtualInputDevice::isEnabled() const
{
return true;
}
void VirtualInputDevice::setEnabled(bool enabled)
{
Q_UNUSED(enabled)
}
LEDs VirtualInputDevice::leds() const
{
return LEDs();
}
void VirtualInputDevice::setLeds(LEDs leds)
{
Q_UNUSED(leds)
}
bool VirtualInputDevice::isKeyboard() const
{
return m_keyboard;
}
bool VirtualInputDevice::isAlphaNumericKeyboard() const
{
return m_keyboard;
}
bool VirtualInputDevice::isPointer() const
{
return m_pointer;
}
bool VirtualInputDevice::isTouchpad() const
{
return false;
}
bool VirtualInputDevice::isTouch() const
{
return m_touch;
}
bool VirtualInputDevice::isTabletTool() const
{
return false;
}
bool VirtualInputDevice::isTabletPad() const
{
return false;
}
bool VirtualInputDevice::isTabletModeSwitch() const
{
return false;
}
bool VirtualInputDevice::isLidSwitch() const
{
return false;
}
VirtualInputBackend::VirtualInputBackend(VirtualBackend *backend, QObject *parent)
: InputBackend(parent)
, m_backend(backend)
{
}
void VirtualInputBackend::initialize()
{
Q_EMIT deviceAdded(m_backend->virtualPointer());
Q_EMIT deviceAdded(m_backend->virtualKeyboard());
Q_EMIT deviceAdded(m_backend->virtualTouch());
}
VirtualBackend::VirtualBackend(QObject *parent)
: Platform(parent)
, m_session(Session::create(Session::Type::Noop, this))
{
m_virtualKeyboard.reset(new VirtualInputDevice());
m_virtualKeyboard->setName(QStringLiteral("Virtual Keyboard 1"));
m_virtualKeyboard->setKeyboard(true);
m_virtualPointer.reset(new VirtualInputDevice());
m_virtualPointer->setName(QStringLiteral("Virtual Pointer 1"));
m_virtualPointer->setPointer(true);
m_virtualTouch.reset(new VirtualInputDevice());
m_virtualTouch->setName(QStringLiteral("Virtual Touch 1"));
m_virtualTouch->setTouch(true);
if (qEnvironmentVariableIsSet("KWIN_WAYLAND_VIRTUAL_SCREENSHOTS")) {
m_screenshotDir.reset(new QTemporaryDir);
if (!m_screenshotDir->isValid()) {
@ -200,21 +75,6 @@ bool VirtualBackend::initialize()
return true;
}
VirtualInputDevice *VirtualBackend::virtualPointer() const
{
return m_virtualPointer.data();
}
VirtualInputDevice *VirtualBackend::virtualKeyboard() const
{
return m_virtualKeyboard.data();
}
VirtualInputDevice *VirtualBackend::virtualTouch() const
{
return m_virtualTouch.data();
}
QString VirtualBackend::screenshotDirPath() const
{
if (m_screenshotDir.isNull()) {
@ -223,11 +83,6 @@ QString VirtualBackend::screenshotDirPath() const
return m_screenshotDir->path();
}
InputBackend *VirtualBackend::createInputBackend()
{
return new VirtualInputBackend(this);
}
QPainterBackend *VirtualBackend::createQPainterBackend()
{
return new VirtualQPainterBackend(this);

View file

@ -9,8 +9,6 @@
#ifndef KWIN_VIRTUAL_BACKEND_H
#define KWIN_VIRTUAL_BACKEND_H
#include "inputbackend.h"
#include "inputdevice.h"
#include "platform.h"
#include <kwin_export.h>
@ -25,57 +23,6 @@ namespace KWin
class VirtualBackend;
class VirtualOutput;
class VirtualInputDevice : public InputDevice
{
Q_OBJECT
public:
explicit VirtualInputDevice(QObject *parent = nullptr);
void setPointer(bool set);
void setKeyboard(bool set);
void setTouch(bool set);
void setName(const QString &name);
QString sysName() const override;
QString name() const override;
bool isEnabled() const override;
void setEnabled(bool enabled) override;
LEDs leds() const override;
void setLeds(LEDs leds) override;
bool isKeyboard() const override;
bool isAlphaNumericKeyboard() const override;
bool isPointer() const override;
bool isTouchpad() const override;
bool isTouch() const override;
bool isTabletTool() const override;
bool isTabletPad() const override;
bool isTabletModeSwitch() const override;
bool isLidSwitch() const override;
private:
QString m_name;
bool m_pointer = false;
bool m_keyboard = false;
bool m_touch = false;
};
class VirtualInputBackend : public InputBackend
{
Q_OBJECT
public:
explicit VirtualInputBackend(VirtualBackend *backend, QObject *parent = nullptr);
void initialize() override;
private:
VirtualBackend *m_backend;
};
class KWIN_EXPORT VirtualBackend : public Platform
{
Q_OBJECT
@ -94,11 +41,6 @@ public:
}
QString screenshotDirPath() const;
VirtualInputDevice *virtualPointer() const;
VirtualInputDevice *virtualKeyboard() const;
VirtualInputDevice *virtualTouch() const;
InputBackend *createInputBackend() override;
QPainterBackend* createQPainterBackend() override;
OpenGLBackend *createOpenGLBackend() override;
@ -126,10 +68,6 @@ private:
QVector<VirtualOutput*> m_outputsEnabled;
QScopedPointer<QTemporaryDir> m_screenshotDir;
Session *m_session;
QScopedPointer<VirtualInputDevice> m_virtualPointer;
QScopedPointer<VirtualInputDevice> m_virtualKeyboard;
QScopedPointer<VirtualInputDevice> m_virtualTouch;
};
}