ButtonsRebindFilter: Add tests for the tablet binding types

This adds autotests for binding to tablet pad and tool buttons, which
was previously untested. Of note is that we don't explicitly test mouse
buttons, which is already tested in the other functions.
This commit is contained in:
Joshua Goins 2024-07-19 20:10:23 -04:00 committed by Joshua Goins
parent b89f85f46d
commit abc6dae6df
2 changed files with 72 additions and 8 deletions

View file

@ -38,6 +38,10 @@ private Q_SLOTS:
void testDisabled();
// NOTE: Mouse buttons are not tested because those are used in the other tests
void testBindingTabletPad();
void testBindingTabletTool();
private:
quint32 timestamp = 1;
};
@ -179,5 +183,60 @@ void TestButtonRebind::testDisabled()
Test::pointerButtonReleased(0x119, timestamp++);
}
void TestButtonRebind::testBindingTabletPad()
{
const QKeySequence sequence(Qt::Key_A);
KConfigGroup buttonGroup = KSharedConfig::openConfig(QStringLiteral("kcminputrc"))->group(QStringLiteral("ButtonRebinds")).group(QStringLiteral("Tablet")).group(QStringLiteral("Virtual Tablet Pad 1"));
buttonGroup.writeEntry("1", QStringList{"Key", sequence.toString(QKeySequence::PortableText)}, KConfig::Notify);
buttonGroup.sync();
std::unique_ptr<KWayland::Client::Surface> surface = Test::createSurface();
std::unique_ptr<Test::XdgToplevel> shellSurface = Test::createXdgToplevelSurface(surface.get());
Test::renderAndWaitForShown(surface.get(), QSize(100, 50), Qt::blue);
std::unique_ptr<KWayland::Client::Keyboard> keyboard(Test::waylandSeat()->createKeyboard());
QSignalSpy enteredSpy(keyboard.get(), &KWayland::Client::Keyboard::entered);
QSignalSpy keyChangedSpy(keyboard.get(), &KWayland::Client::Keyboard::keyChanged);
QVERIFY(enteredSpy.wait());
Test::tabletPadButtonPressed(1, timestamp++);
QVERIFY(keyChangedSpy.wait());
QCOMPARE(keyChangedSpy.count(), 1);
QCOMPARE(keyChangedSpy.at(0).at(0), KEY_A);
Test::tabletPadButtonReleased(1, timestamp++);
}
void TestButtonRebind::testBindingTabletTool()
{
const QKeySequence sequence(Qt::Key_A);
KConfigGroup buttonGroup = KSharedConfig::openConfig(QStringLiteral("kcminputrc"))->group(QStringLiteral("ButtonRebinds")).group(QStringLiteral("TabletTool")).group(QStringLiteral("Virtual Tablet Tool 1"));
buttonGroup.writeEntry(QString::number(BTN_STYLUS), QStringList{"Key", sequence.toString(QKeySequence::PortableText)}, KConfig::Notify);
buttonGroup.sync();
std::unique_ptr<KWayland::Client::Surface> surface = Test::createSurface();
std::unique_ptr<Test::XdgToplevel> shellSurface = Test::createXdgToplevelSurface(surface.get());
auto window = Test::renderAndWaitForShown(surface.get(), QSize(100, 50), Qt::blue);
std::unique_ptr<KWayland::Client::Keyboard> keyboard(Test::waylandSeat()->createKeyboard());
QSignalSpy enteredSpy(keyboard.get(), &KWayland::Client::Keyboard::entered);
QSignalSpy keyChangedSpy(keyboard.get(), &KWayland::Client::Keyboard::keyChanged);
QVERIFY(enteredSpy.wait());
const QRectF startGeometry = window->frameGeometry();
Test::tabletToolEvent(InputRedirection::Tip, startGeometry.center(), 1.0, 0, 0, 0, true, false, timestamp++);
Test::tabletToolButtonPressed(BTN_STYLUS, timestamp++);
QVERIFY(keyChangedSpy.wait());
QCOMPARE(keyChangedSpy.count(), 1);
QCOMPARE(keyChangedSpy.at(0).at(0), KEY_A);
Test::tabletToolButtonReleased(BTN_STYLUS, timestamp++);
}
WAYLANDTEST_MAIN(TestButtonRebind)
#include "buttonrebind_test.moc"

View file

@ -891,9 +891,9 @@ public:
{
static const wl_callback_listener listener = {
.done = [](void *data, wl_callback *callback, uint32_t callback_data) {
auto syncPoint = static_cast<WaylandSyncPoint *>(data);
Q_EMIT syncPoint->done();
},
auto syncPoint = static_cast<WaylandSyncPoint *>(data);
Q_EMIT syncPoint->done();
},
};
m_callback = wl_display_sync(connection->display());
@ -1739,7 +1739,8 @@ void tabletPadButtonPressed(quint32 button, quint32 time)
{
auto virtualTabletPad = static_cast<WaylandTestApplication *>(kwinApp())->virtualTabletPad();
TabletPadId padId{
.name = virtualTabletPad->name()};
.name = virtualTabletPad->name(),
};
Q_EMIT virtualTabletPad->tabletPadButtonEvent(button, true, padId, std::chrono::milliseconds(time));
}
@ -1747,7 +1748,8 @@ void tabletPadButtonReleased(quint32 button, quint32 time)
{
auto virtualTabletPad = static_cast<WaylandTestApplication *>(kwinApp())->virtualTabletPad();
TabletPadId padId{
.name = virtualTabletPad->name()};
.name = virtualTabletPad->name(),
};
Q_EMIT virtualTabletPad->tabletPadButtonEvent(button, false, padId, std::chrono::milliseconds(time));
}
@ -1755,7 +1757,8 @@ void tabletToolButtonPressed(quint32 button, quint32 time)
{
auto virtualTabletTool = static_cast<WaylandTestApplication *>(kwinApp())->virtualTabletTool();
TabletToolId toolId{
.m_name = virtualTabletTool->name()};
.m_name = virtualTabletTool->name(),
};
Q_EMIT virtualTabletTool->tabletToolButtonEvent(button, true, toolId, std::chrono::milliseconds(time));
}
@ -1763,7 +1766,8 @@ void tabletToolButtonReleased(quint32 button, quint32 time)
{
auto virtualTabletTool = static_cast<WaylandTestApplication *>(kwinApp())->virtualTabletTool();
TabletToolId toolId{
.m_name = virtualTabletTool->name()};
.m_name = virtualTabletTool->name(),
};
Q_EMIT virtualTabletTool->tabletToolButtonEvent(button, false, toolId, std::chrono::milliseconds(time));
}
@ -1773,7 +1777,8 @@ void tabletToolEvent(InputRedirection::TabletEventType type, const QPointF &pos,
{
auto virtualTabletTool = static_cast<WaylandTestApplication *>(kwinApp())->virtualTabletTool();
TabletToolId toolId{
.m_name = virtualTabletTool->name()};
.m_name = virtualTabletTool->name(),
};
Q_EMIT virtualTabletTool->tabletToolEvent(type, pos, pressure, xTilt, yTilt, rotation, tipDown, tipNear, toolId, std::chrono::milliseconds(time));
}
}