Add testing infrastructure for virtual tablet pad and tools

This is for the ButtonRebindFilter tests, but this could be useful
in other places too.
This commit is contained in:
Joshua Goins 2024-07-19 20:09:22 -04:00 committed by Joshua Goins
parent 0ea1bcfe89
commit b89f85f46d
3 changed files with 96 additions and 2 deletions

View file

@ -133,9 +133,19 @@ void WaylandTestApplication::createVirtualInputDevices()
m_virtualTouch->setName(QStringLiteral("Virtual Touch 1"));
m_virtualTouch->setTouch(true);
m_virtualTabletPad = std::make_unique<Test::VirtualInputDevice>();
m_virtualTabletPad->setName(QStringLiteral("Virtual Tablet Pad 1"));
m_virtualTabletPad->setTabletPad(true);
m_virtualTabletTool = std::make_unique<Test::VirtualInputDevice>();
m_virtualTabletTool->setName(QStringLiteral("Virtual Tablet Tool 1"));
m_virtualTabletTool->setTabletTool(true);
input()->addInputDevice(m_virtualPointer.get());
input()->addInputDevice(m_virtualTouch.get());
input()->addInputDevice(m_virtualKeyboard.get());
input()->addInputDevice(m_virtualTabletPad.get());
input()->addInputDevice(m_virtualTabletTool.get());
}
void WaylandTestApplication::destroyVirtualInputDevices()
@ -149,6 +159,12 @@ void WaylandTestApplication::destroyVirtualInputDevices()
if (m_virtualKeyboard) {
input()->removeInputDevice(m_virtualKeyboard.get());
}
if (m_virtualTabletPad) {
input()->removeInputDevice(m_virtualTabletPad.get());
}
if (m_virtualTabletTool) {
input()->removeInputDevice(m_virtualTabletTool.get());
}
}
void WaylandTestApplication::performStartup()
@ -215,6 +231,16 @@ Test::VirtualInputDevice *WaylandTestApplication::virtualTouch() const
return m_virtualTouch.get();
}
Test::VirtualInputDevice *WaylandTestApplication::virtualTabletPad() const
{
return m_virtualTabletPad.get();
}
Test::VirtualInputDevice *WaylandTestApplication::virtualTabletTool() const
{
return m_virtualTabletTool.get();
}
#if KWIN_BUILD_X11
XwaylandInterface *WaylandTestApplication::xwayland() const
{

View file

@ -103,6 +103,8 @@ public:
Test::VirtualInputDevice *virtualPointer() const;
Test::VirtualInputDevice *virtualKeyboard() const;
Test::VirtualInputDevice *virtualTouch() const;
Test::VirtualInputDevice *virtualTabletPad() const;
Test::VirtualInputDevice *virtualTabletTool() const;
#if KWIN_BUILD_X11
XwaylandInterface *xwayland() const override;
#endif
@ -126,6 +128,8 @@ private:
std::unique_ptr<Test::VirtualInputDevice> m_virtualPointer;
std::unique_ptr<Test::VirtualInputDevice> m_virtualKeyboard;
std::unique_ptr<Test::VirtualInputDevice> m_virtualTouch;
std::unique_ptr<Test::VirtualInputDevice> m_virtualTabletPad;
std::unique_ptr<Test::VirtualInputDevice> m_virtualTabletTool;
};
namespace Test
@ -609,6 +613,8 @@ public:
void setKeyboard(bool set);
void setTouch(bool set);
void setLidSwitch(bool set);
void setTabletPad(bool set);
void setTabletTool(bool set);
void setName(const QString &name);
QString sysName() const override;
@ -635,6 +641,8 @@ private:
bool m_keyboard = false;
bool m_touch = false;
bool m_lidSwitch = false;
bool m_tabletPad = false;
bool m_tabletTool = false;
};
void keyboardKeyPressed(quint32 key, quint32 time);
@ -655,6 +663,13 @@ void touchCancel();
void touchDown(qint32 id, const QPointF &pos, quint32 time);
void touchMotion(qint32 id, const QPointF &pos, quint32 time);
void touchUp(qint32 id, quint32 time);
void tabletPadButtonPressed(quint32 button, quint32 time);
void tabletPadButtonReleased(quint32 button, quint32 time);
void tabletToolButtonPressed(quint32 button, quint32 time);
void tabletToolButtonReleased(quint32 button, quint32 time);
void tabletToolEvent(InputRedirection::TabletEventType type, const QPointF &pos,
qreal pressure, int xTilt, int yTilt, qreal rotation, bool tipDown,
bool tipNear, quint32 time);
/**
* Creates a Wayland Connection in a dedicated thread and creates various

View file

@ -15,6 +15,7 @@
#if KWIN_BUILD_SCREENLOCKER
#include "screenlockerwatcher.h"
#endif
#include "input_event.h"
#include "inputmethod.h"
#include "wayland/display.h"
#include "wayland_server.h"
@ -1573,6 +1574,16 @@ void VirtualInputDevice::setLidSwitch(bool set)
m_lidSwitch = set;
}
void VirtualInputDevice::setTabletPad(bool set)
{
m_tabletPad = set;
}
void VirtualInputDevice::setTabletTool(bool set)
{
m_tabletTool = set;
}
void VirtualInputDevice::setName(const QString &name)
{
m_name = name;
@ -1628,12 +1639,12 @@ bool VirtualInputDevice::isTouch() const
bool VirtualInputDevice::isTabletTool() const
{
return false;
return m_tabletTool;
}
bool VirtualInputDevice::isTabletPad() const
{
return false;
return m_tabletPad;
}
bool VirtualInputDevice::isTabletModeSwitch() const
@ -1723,6 +1734,48 @@ void touchUp(qint32 id, quint32 time)
auto virtualTouch = static_cast<WaylandTestApplication *>(kwinApp())->virtualTouch();
Q_EMIT virtualTouch->touchUp(id, std::chrono::milliseconds(time), virtualTouch);
}
void tabletPadButtonPressed(quint32 button, quint32 time)
{
auto virtualTabletPad = static_cast<WaylandTestApplication *>(kwinApp())->virtualTabletPad();
TabletPadId padId{
.name = virtualTabletPad->name()};
Q_EMIT virtualTabletPad->tabletPadButtonEvent(button, true, padId, std::chrono::milliseconds(time));
}
void tabletPadButtonReleased(quint32 button, quint32 time)
{
auto virtualTabletPad = static_cast<WaylandTestApplication *>(kwinApp())->virtualTabletPad();
TabletPadId padId{
.name = virtualTabletPad->name()};
Q_EMIT virtualTabletPad->tabletPadButtonEvent(button, false, padId, std::chrono::milliseconds(time));
}
void tabletToolButtonPressed(quint32 button, quint32 time)
{
auto virtualTabletTool = static_cast<WaylandTestApplication *>(kwinApp())->virtualTabletTool();
TabletToolId toolId{
.m_name = virtualTabletTool->name()};
Q_EMIT virtualTabletTool->tabletToolButtonEvent(button, true, toolId, std::chrono::milliseconds(time));
}
void tabletToolButtonReleased(quint32 button, quint32 time)
{
auto virtualTabletTool = static_cast<WaylandTestApplication *>(kwinApp())->virtualTabletTool();
TabletToolId toolId{
.m_name = virtualTabletTool->name()};
Q_EMIT virtualTabletTool->tabletToolButtonEvent(button, false, toolId, std::chrono::milliseconds(time));
}
void tabletToolEvent(InputRedirection::TabletEventType type, const QPointF &pos,
qreal pressure, int xTilt, int yTilt, qreal rotation, bool tipDown,
bool tipNear, quint32 time)
{
auto virtualTabletTool = static_cast<WaylandTestApplication *>(kwinApp())->virtualTabletTool();
TabletToolId toolId{
.m_name = virtualTabletTool->name()};
Q_EMIT virtualTabletTool->tabletToolEvent(type, pos, pressure, xTilt, yTilt, rotation, tipDown, tipNear, toolId, std::chrono::milliseconds(time));
}
}
}