KWin
Loading...
Searching...
No Matches
bounce_keys_test.cpp
Go to the documentation of this file.
1/*
2 KWin - the KDE window manager
3 This file is part of the KDE project.
4
5 SPDX-FileCopyrightText: 2016 Martin Gräßlin <mgraesslin@kde.org>
6 SPDX-FileCopyrightText: 2023 Nicolas Fella <nicolas.fella@gmx.de>
7
8 SPDX-License-Identifier: GPL-2.0-or-later
9*/
10#include "kwin_wayland_test.h"
11
12#include "keyboard_input.h"
13#include "pluginmanager.h"
14#include "pointer_input.h"
15#include "wayland_server.h"
16#include "window.h"
17#include "workspace.h"
18
19#include <KWayland/Client/keyboard.h>
20#include <KWayland/Client/seat.h>
21
22#include <linux/input.h>
23
24namespace KWin
25{
26
27static const QString s_socketName = QStringLiteral("wayland_test_kwin_bounce_keys-0");
28
29class BounceKeysTest : public QObject
30{
31 Q_OBJECT
32private Q_SLOTS:
33 void initTestCase();
34 void init();
35 void cleanup();
36 void testBounce();
37};
38
39void BounceKeysTest::initTestCase()
40{
41 KConfig kaccessConfig("kaccessrc");
42 kaccessConfig.group(QStringLiteral("Keyboard")).writeEntry("BounceKeys", true);
43 kaccessConfig.group(QStringLiteral("Keyboard")).writeEntry("BounceKeysDelay", 200);
44 kaccessConfig.sync();
45
46 qRegisterMetaType<KWin::Window *>();
47 QSignalSpy applicationStartedSpy(kwinApp(), &Application::started);
48 QVERIFY(waylandServer()->init(s_socketName));
50 QRect(0, 0, 1280, 1024),
51 QRect(1280, 0, 1280, 1024),
52 });
53
54 qputenv("XKB_DEFAULT_RULES", "evdev");
55
56 kwinApp()->start();
57 QVERIFY(applicationStartedSpy.wait());
58}
59
60void BounceKeysTest::init()
61{
64}
65
66void BounceKeysTest::cleanup()
67{
69}
70
71void BounceKeysTest::testBounce()
72{
73 std::unique_ptr<KWayland::Client::Keyboard> keyboard(Test::waylandSeat()->createKeyboard());
74
75 std::unique_ptr<KWayland::Client::Surface> surface(Test::createSurface());
76 QVERIFY(surface != nullptr);
77 std::unique_ptr<Test::XdgToplevel> shellSurface(Test::createXdgToplevelSurface(surface.get()));
78 QVERIFY(shellSurface != nullptr);
79 Window *waylandWindow = Test::renderAndWaitForShown(surface.get(), QSize(10, 10), Qt::blue);
80 QVERIFY(waylandWindow);
81
82 QVERIFY(keyboard);
83 QSignalSpy enteredSpy(keyboard.get(), &KWayland::Client::Keyboard::entered);
84 QVERIFY(enteredSpy.wait());
85
86 QSignalSpy keySpy(keyboard.get(), &KWayland::Client::Keyboard::keyChanged);
87 QVERIFY(keySpy.isValid());
88
89 quint32 timestamp = 0;
90
91 // Press a key, verify that it goes through
92 Test::keyboardKeyPressed(KEY_A, timestamp);
93 QVERIFY(keySpy.wait());
94 QCOMPARE(keySpy.first()[0], KEY_A);
95 QCOMPARE(keySpy.first()[1].value<KWayland::Client::Keyboard::KeyState>(), KWayland::Client::Keyboard::KeyState::Pressed);
96 keySpy.clear();
97
98 Test::keyboardKeyReleased(KEY_A, timestamp++);
99 QVERIFY(keySpy.wait());
100 QCOMPARE(keySpy.first()[0], KEY_A);
101 QCOMPARE(keySpy.first()[1].value<KWayland::Client::Keyboard::KeyState>(), KWayland::Client::Keyboard::KeyState::Released);
102 keySpy.clear();
103
104 // Press it again within the bounce interval, verify that it does *not* go through
105 timestamp += 100;
106 Test::keyboardKeyPressed(KEY_A, timestamp);
107 QVERIFY(!keySpy.wait(100));
108 keySpy.clear();
109
110 // Press it again after the bouce interval, verify that it does go through
111 timestamp += 1000;
112 Test::keyboardKeyPressed(KEY_A, timestamp);
113 QVERIFY(keySpy.wait());
114 QCOMPARE(keySpy.first()[0], KEY_A);
115 QCOMPARE(keySpy.first()[1].value<KWayland::Client::Keyboard::KeyState>(), KWayland::Client::Keyboard::KeyState::Pressed);
116 keySpy.clear();
117
118 Test::keyboardKeyReleased(KEY_A, timestamp++);
119 QVERIFY(keySpy.wait());
120 QCOMPARE(keySpy.first()[0], KEY_A);
121 QCOMPARE(keySpy.first()[1].value<KWayland::Client::Keyboard::KeyState>(), KWayland::Client::Keyboard::KeyState::Released);
122 keySpy.clear();
123}
124}
125
127#include "bounce_keys_test.moc"
#define WAYLANDTEST_MAIN(TestObject)
Window * renderAndWaitForShown(KWayland::Client::Surface *surface, const QSize &size, const QColor &color, const QImage::Format &format=QImage::Format_ARGB32, int timeout=5000)
void keyboardKeyReleased(quint32 key, quint32 time)
void destroyWaylandConnection()
void setOutputConfig(const QList< QRect > &geometries)
void keyboardKeyPressed(quint32 key, quint32 time)
bool waitForWaylandKeyboard()
bool setupWaylandConnection(AdditionalWaylandInterfaces flags=AdditionalWaylandInterfaces())
KWayland::Client::Seat * waylandSeat()
std::unique_ptr< KWayland::Client::Surface > createSurface()
XdgToplevel * createXdgToplevelSurface(KWayland::Client::Surface *surface, QObject *parent=nullptr)
WaylandServer * waylandServer()