KWin
Loading...
Searching...
No Matches
test_x11_timestamp_update.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: 2017 Martin Gräßlin <mgraesslin@kde.org>
6
7 SPDX-License-Identifier: GPL-2.0-or-later
8*/
9
10#include <QTest>
11#include <private/qtx11extras_p.h>
12
13#include "effect/xcb.h"
14#include "main.h"
15#include "utils/common.h"
16
17namespace KWin
18{
19
21{
22 Q_OBJECT
23public:
24 X11TestApplication(int &argc, char **argv);
25 ~X11TestApplication() override;
26
27protected:
28 void performStartup() override;
29};
30
32 : Application(OperationModeX11, argc, argv)
33{
34 setX11Connection(QX11Info::connection());
35 setX11RootWindow(QX11Info::appRootWindow());
36}
37
41
45
46}
47
48class X11TimestampUpdateTest : public QObject
49{
50 Q_OBJECT
51private Q_SLOTS:
52 void testGrabAfterServerTime();
53 void testBeforeLastGrabTime();
54};
55
56void X11TimestampUpdateTest::testGrabAfterServerTime()
57{
58 // this test tries to grab the X keyboard with a timestamp in future
59 // that should fail, but after updating the X11 timestamp, it should
60 // work again
61 KWin::kwinApp()->updateXTime();
62 QCOMPARE(KWin::grabXKeyboard(), true);
64
65 // now let's change the timestamp
66 KWin::kwinApp()->setX11Time(KWin::xTime() + 5 * 60 * 1000);
67
68 // now grab keyboard should fail
69 QCOMPARE(KWin::grabXKeyboard(), false);
70
71 // let's update timestamp, now it should work again
72 KWin::kwinApp()->updateXTime();
73 QCOMPARE(KWin::grabXKeyboard(), true);
75}
76
77void X11TimestampUpdateTest::testBeforeLastGrabTime()
78{
79 // this test tries to grab the X keyboard with a timestamp before the
80 // last grab time on the server. That should fail, but after updating the X11
81 // timestamp it should work again
82
83 // first set the grab timestamp
84 KWin::kwinApp()->updateXTime();
85 QCOMPARE(KWin::grabXKeyboard(), true);
87
88 // now go to past
89 const auto timestamp = KWin::xTime();
90 KWin::kwinApp()->setX11Time(KWin::xTime() - 5 * 60 * 1000, KWin::Application::TimestampUpdate::Always);
91 QCOMPARE(KWin::xTime(), timestamp - 5 * 60 * 1000);
92
93 // now grab keyboard should fail
94 QCOMPARE(KWin::grabXKeyboard(), false);
95
96 // let's update timestamp, now it should work again
97 KWin::kwinApp()->updateXTime();
98 QVERIFY(KWin::xTime() >= timestamp);
99 QCOMPARE(KWin::grabXKeyboard(), true);
101}
102
103int main(int argc, char *argv[])
104{
105 setenv("QT_QPA_PLATFORM", "xcb", true);
106 KWin::X11TestApplication app(argc, argv);
107 app.setAttribute(Qt::AA_Use96Dpi, true);
109 return QTest::qExec(&tc, argc, argv);
110}
111
112#include "test_x11_timestamp_update.moc"
void setX11RootWindow(xcb_window_t root)
Definition main.h:204
void updateXTime()
Definition main.cpp:529
void setX11Time(xcb_timestamp_t timestamp, TimestampUpdate force=TimestampUpdate::OnlyIfLarger)
Definition main.h:154
void setX11Connection(xcb_connection_t *c)
Definition main.h:212
X11TestApplication(int &argc, char **argv)
KWIN_EXPORT xcb_timestamp_t xTime()
Definition xcb.h:29
void KWIN_EXPORT ungrabXKeyboard()
Definition common.cpp:121
bool KWIN_EXPORT grabXKeyboard(xcb_window_t w=XCB_WINDOW_NONE)
Definition common.cpp:90