2023-11-23 08:17:00 +00:00
|
|
|
/*
|
|
|
|
KWin - the KDE window manager
|
|
|
|
This file is part of the KDE project.
|
|
|
|
|
|
|
|
SPDX-FileCopyrightText: 2016 Martin Gräßlin <mgraesslin@kde.org>
|
|
|
|
SPDX-FileCopyrightText: 2023 Nicolas Fella <nicolas.fella@gmx.de>
|
|
|
|
|
|
|
|
SPDX-License-Identifier: GPL-2.0-or-later
|
|
|
|
*/
|
|
|
|
#include "kwin_wayland_test.h"
|
|
|
|
|
|
|
|
#include "keyboard_input.h"
|
|
|
|
#include "pluginmanager.h"
|
|
|
|
#include "pointer_input.h"
|
|
|
|
#include "wayland_server.h"
|
|
|
|
#include "window.h"
|
|
|
|
#include "workspace.h"
|
|
|
|
|
|
|
|
#include <KWayland/Client/keyboard.h>
|
|
|
|
#include <KWayland/Client/seat.h>
|
|
|
|
|
|
|
|
#include <linux/input.h>
|
|
|
|
|
|
|
|
namespace KWin
|
|
|
|
{
|
|
|
|
|
|
|
|
static const QString s_socketName = QStringLiteral("wayland_test_kwin_sticky_keys-0");
|
|
|
|
|
|
|
|
class StickyKeysTest : public QObject
|
|
|
|
{
|
|
|
|
Q_OBJECT
|
|
|
|
private Q_SLOTS:
|
|
|
|
void initTestCase();
|
|
|
|
void init();
|
|
|
|
void cleanup();
|
|
|
|
void testStick();
|
2024-03-05 19:33:45 +00:00
|
|
|
void testStick_data();
|
2023-11-23 08:17:00 +00:00
|
|
|
void testLock();
|
2024-07-16 14:59:46 +00:00
|
|
|
void testLock_data();
|
2023-11-23 08:17:00 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
void StickyKeysTest::initTestCase()
|
|
|
|
{
|
|
|
|
KConfig kaccessConfig("kaccessrc");
|
|
|
|
kaccessConfig.group(QStringLiteral("Keyboard")).writeEntry("StickyKeys", true);
|
|
|
|
kaccessConfig.sync();
|
|
|
|
|
2024-03-05 19:33:45 +00:00
|
|
|
// Use a keyboard layout where right alt triggers Mod5/AltGr
|
|
|
|
KConfig kxkbrc("kxkbrc");
|
|
|
|
kxkbrc.group(QStringLiteral("Layout")).writeEntry("LayoutList", "us");
|
|
|
|
kxkbrc.group(QStringLiteral("Layout")).writeEntry("VariantList", "altgr-intl");
|
|
|
|
kxkbrc.sync();
|
|
|
|
|
2023-11-23 08:17:00 +00:00
|
|
|
qRegisterMetaType<KWin::Window *>();
|
|
|
|
QSignalSpy applicationStartedSpy(kwinApp(), &Application::started);
|
|
|
|
QVERIFY(waylandServer()->init(s_socketName));
|
|
|
|
Test::setOutputConfig({
|
|
|
|
QRect(0, 0, 1280, 1024),
|
|
|
|
QRect(1280, 0, 1280, 1024),
|
|
|
|
});
|
|
|
|
|
|
|
|
qputenv("XKB_DEFAULT_RULES", "evdev");
|
|
|
|
|
|
|
|
kwinApp()->start();
|
|
|
|
QVERIFY(applicationStartedSpy.wait());
|
|
|
|
}
|
|
|
|
|
|
|
|
void StickyKeysTest::init()
|
|
|
|
{
|
|
|
|
QVERIFY(Test::setupWaylandConnection(Test::AdditionalWaylandInterface::Seat));
|
|
|
|
QVERIFY(Test::waitForWaylandKeyboard());
|
|
|
|
}
|
|
|
|
|
|
|
|
void StickyKeysTest::cleanup()
|
|
|
|
{
|
|
|
|
Test::destroyWaylandConnection();
|
|
|
|
}
|
|
|
|
|
2024-03-05 19:33:45 +00:00
|
|
|
void StickyKeysTest::testStick_data()
|
|
|
|
{
|
|
|
|
QTest::addColumn<int>("modifierKey");
|
|
|
|
QTest::addColumn<int>("expectedMods");
|
|
|
|
|
|
|
|
QTest::addRow("Shift") << KEY_LEFTSHIFT << 1;
|
|
|
|
QTest::addRow("Ctrl") << KEY_LEFTCTRL << 4;
|
|
|
|
QTest::addRow("Alt") << KEY_LEFTALT << 8;
|
|
|
|
QTest::addRow("AltGr") << KEY_RIGHTALT << 128;
|
|
|
|
}
|
|
|
|
|
2023-11-23 08:17:00 +00:00
|
|
|
void StickyKeysTest::testStick()
|
|
|
|
{
|
2024-03-05 19:33:45 +00:00
|
|
|
QFETCH(int, modifierKey);
|
|
|
|
QFETCH(int, expectedMods);
|
|
|
|
|
2023-11-23 08:17:00 +00:00
|
|
|
std::unique_ptr<KWayland::Client::Keyboard> keyboard(Test::waylandSeat()->createKeyboard());
|
|
|
|
|
|
|
|
std::unique_ptr<KWayland::Client::Surface> surface(Test::createSurface());
|
|
|
|
QVERIFY(surface != nullptr);
|
|
|
|
std::unique_ptr<Test::XdgToplevel> shellSurface(Test::createXdgToplevelSurface(surface.get()));
|
|
|
|
QVERIFY(shellSurface != nullptr);
|
|
|
|
Window *waylandWindow = Test::renderAndWaitForShown(surface.get(), QSize(10, 10), Qt::blue);
|
|
|
|
QVERIFY(waylandWindow);
|
|
|
|
|
|
|
|
QSignalSpy modifierSpy(keyboard.get(), &KWayland::Client::Keyboard::modifiersChanged);
|
|
|
|
QVERIFY(modifierSpy.wait());
|
|
|
|
modifierSpy.clear();
|
|
|
|
|
|
|
|
quint32 timestamp = 0;
|
|
|
|
|
2024-03-05 19:33:45 +00:00
|
|
|
// press mod to latch it
|
|
|
|
Test::keyboardKeyPressed(modifierKey, ++timestamp);
|
2023-11-23 08:17:00 +00:00
|
|
|
QVERIFY(modifierSpy.wait());
|
|
|
|
// arguments are: quint32 depressed, quint32 latched, quint32 locked, quint32 group
|
2024-03-05 19:33:45 +00:00
|
|
|
QCOMPARE(modifierSpy.first()[0], expectedMods); // verify that mod is depressed
|
|
|
|
QCOMPARE(modifierSpy.first()[1], expectedMods); // verify that mod is latched
|
2023-11-23 08:17:00 +00:00
|
|
|
|
|
|
|
modifierSpy.clear();
|
2024-07-16 14:08:14 +00:00
|
|
|
// release mod, the modifier should still be latched
|
2024-03-05 19:33:45 +00:00
|
|
|
Test::keyboardKeyReleased(modifierKey, ++timestamp);
|
2023-11-23 08:17:00 +00:00
|
|
|
QVERIFY(modifierSpy.wait());
|
2024-03-05 19:33:45 +00:00
|
|
|
QCOMPARE(modifierSpy.first()[0], 0); // verify that mod is not depressed
|
|
|
|
QCOMPARE(modifierSpy.first()[1], expectedMods); // verify that mod is still latched
|
2023-11-23 08:17:00 +00:00
|
|
|
|
|
|
|
// press and release a letter, this unlatches the modifier
|
|
|
|
modifierSpy.clear();
|
|
|
|
Test::keyboardKeyPressed(KEY_A, ++timestamp);
|
|
|
|
QVERIFY(modifierSpy.wait());
|
2024-03-05 19:33:45 +00:00
|
|
|
QCOMPARE(modifierSpy.first()[0], 0); // verify that mod is not depressed
|
|
|
|
QCOMPARE(modifierSpy.first()[1], 0); // verify that mod is not latched any more
|
2023-11-23 08:17:00 +00:00
|
|
|
|
|
|
|
Test::keyboardKeyReleased(KEY_A, ++timestamp);
|
|
|
|
}
|
|
|
|
|
2024-07-16 14:59:46 +00:00
|
|
|
void StickyKeysTest::testLock_data()
|
|
|
|
{
|
|
|
|
QTest::addColumn<int>("modifierKey");
|
|
|
|
QTest::addColumn<int>("expectedMods");
|
|
|
|
|
|
|
|
QTest::addRow("Shift") << KEY_LEFTSHIFT << 1;
|
|
|
|
QTest::addRow("Ctrl") << KEY_LEFTCTRL << 4;
|
|
|
|
QTest::addRow("Alt") << KEY_LEFTALT << 8;
|
|
|
|
QTest::addRow("AltGr") << KEY_RIGHTALT << 128;
|
|
|
|
}
|
|
|
|
|
2023-11-23 08:17:00 +00:00
|
|
|
void StickyKeysTest::testLock()
|
|
|
|
{
|
2024-07-16 14:59:46 +00:00
|
|
|
QFETCH(int, modifierKey);
|
|
|
|
QFETCH(int, expectedMods);
|
|
|
|
|
2023-11-23 08:17:00 +00:00
|
|
|
KConfig kaccessConfig("kaccessrc");
|
|
|
|
kaccessConfig.group(QStringLiteral("Keyboard")).writeEntry("StickyKeysLatch", true);
|
|
|
|
kaccessConfig.sync();
|
|
|
|
|
|
|
|
// reload the plugin to pick up the new config
|
|
|
|
kwinApp()->pluginManager()->unloadPlugin("StickyKeysPlugin");
|
|
|
|
kwinApp()->pluginManager()->loadPlugin("StickyKeysPlugin");
|
|
|
|
|
|
|
|
QVERIFY(Test::waylandSeat()->hasKeyboard());
|
|
|
|
std::unique_ptr<KWayland::Client::Keyboard> keyboard(Test::waylandSeat()->createKeyboard());
|
|
|
|
|
|
|
|
std::unique_ptr<KWayland::Client::Surface> surface(Test::createSurface());
|
|
|
|
QVERIFY(surface != nullptr);
|
|
|
|
std::unique_ptr<Test::XdgToplevel> shellSurface(Test::createXdgToplevelSurface(surface.get()));
|
|
|
|
QVERIFY(shellSurface != nullptr);
|
|
|
|
Window *waylandWindow = Test::renderAndWaitForShown(surface.get(), QSize(10, 10), Qt::blue);
|
|
|
|
QVERIFY(waylandWindow);
|
|
|
|
waylandWindow->move(QPoint(0, 0));
|
|
|
|
|
|
|
|
QSignalSpy modifierSpy(keyboard.get(), &KWayland::Client::Keyboard::modifiersChanged);
|
|
|
|
QVERIFY(modifierSpy.wait());
|
|
|
|
modifierSpy.clear();
|
|
|
|
|
|
|
|
quint32 timestamp = 0;
|
|
|
|
|
2024-07-16 14:59:46 +00:00
|
|
|
// press mod to latch it
|
|
|
|
Test::keyboardKeyPressed(modifierKey, ++timestamp);
|
2023-11-23 08:17:00 +00:00
|
|
|
QVERIFY(modifierSpy.wait());
|
|
|
|
// arguments are: quint32 depressed, quint32 latched, quint32 locked, quint32 group
|
2024-07-16 14:59:46 +00:00
|
|
|
QCOMPARE(modifierSpy.first()[0], expectedMods); // verify that mod is depressed
|
|
|
|
QCOMPARE(modifierSpy.first()[1], expectedMods); // verify that mod is latched
|
2023-11-23 08:17:00 +00:00
|
|
|
|
|
|
|
modifierSpy.clear();
|
2024-07-16 14:59:46 +00:00
|
|
|
// release mod, the modifier should still be latched
|
|
|
|
Test::keyboardKeyReleased(modifierKey, ++timestamp);
|
2023-11-23 08:17:00 +00:00
|
|
|
QVERIFY(modifierSpy.wait());
|
2024-07-16 14:59:46 +00:00
|
|
|
QCOMPARE(modifierSpy.first()[0], 0); // verify that mod is not depressed
|
|
|
|
QCOMPARE(modifierSpy.first()[1], expectedMods); // verify that mod is still latched
|
2023-11-23 08:17:00 +00:00
|
|
|
|
2024-07-16 14:59:46 +00:00
|
|
|
// press mod again to lock it
|
2023-11-23 08:17:00 +00:00
|
|
|
modifierSpy.clear();
|
2024-07-16 14:59:46 +00:00
|
|
|
Test::keyboardKeyPressed(modifierKey, ++timestamp);
|
2023-11-23 08:17:00 +00:00
|
|
|
QVERIFY(modifierSpy.wait());
|
2024-07-16 14:59:46 +00:00
|
|
|
QCOMPARE(modifierSpy.first()[0], expectedMods); // verify that mod is depressed
|
2024-07-16 13:48:16 +00:00
|
|
|
QCOMPARE(modifierSpy.first()[1], 0); // verify that mod is unlatched
|
2024-07-16 14:59:46 +00:00
|
|
|
QCOMPARE(modifierSpy.first()[2], expectedMods); // verify that mod is locked
|
2023-11-23 08:17:00 +00:00
|
|
|
|
2024-07-16 14:59:46 +00:00
|
|
|
// release mod, modifier should still be locked
|
2024-07-16 14:55:13 +00:00
|
|
|
modifierSpy.clear();
|
2024-07-16 14:59:46 +00:00
|
|
|
Test::keyboardKeyReleased(modifierKey, ++timestamp);
|
2024-07-16 14:55:13 +00:00
|
|
|
QVERIFY(modifierSpy.wait());
|
|
|
|
// TODO
|
|
|
|
|
2023-11-23 08:17:00 +00:00
|
|
|
// press and release a letter, this does not unlock the modifier
|
|
|
|
modifierSpy.clear();
|
|
|
|
Test::keyboardKeyPressed(KEY_A, ++timestamp);
|
|
|
|
QVERIFY(!modifierSpy.wait(10));
|
|
|
|
|
|
|
|
Test::keyboardKeyReleased(KEY_A, ++timestamp);
|
|
|
|
QVERIFY(!modifierSpy.wait(10));
|
|
|
|
|
2024-07-16 14:59:46 +00:00
|
|
|
// press mod again to unlock it
|
|
|
|
Test::keyboardKeyPressed(modifierKey, ++timestamp);
|
2023-11-23 08:17:00 +00:00
|
|
|
QVERIFY(modifierSpy.wait());
|
2024-07-16 14:59:46 +00:00
|
|
|
QCOMPARE(modifierSpy.first()[0], expectedMods); // verify that mod is depressed
|
2024-07-16 13:48:16 +00:00
|
|
|
QCOMPARE(modifierSpy.first()[1], 0); // verify that mod is unlatched
|
2024-07-16 14:59:46 +00:00
|
|
|
QCOMPARE(modifierSpy.first()[2], 0); // verify that mod is not locked
|
2023-11-23 08:17:00 +00:00
|
|
|
|
2024-07-16 14:59:46 +00:00
|
|
|
Test::keyboardKeyReleased(modifierKey, ++timestamp);
|
2023-11-23 08:17:00 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
WAYLANDTEST_MAIN(KWin::StickyKeysTest)
|
|
|
|
#include "sticky_keys_test.moc"
|