kwin/autotests/test_x11_timestamp_update.cpp
Vlad Zahorodnii 045da603a4 Make backends part of libkwin
Platform backends are provided as plugins. This is great for
extensibility, but the disadvantages of this design outweigh the
benefits.

The number of backends will be limited, it's safe to say that we will
have to maintain three backends for many years to come - kms/drm,
virtual, and wayland. The plugin system adds unnecessary complexity.

Startup logic is affected too. At the moment, platform backends provide
the session object, which is awkward as it starts adding dependencies
between backends. It will be nicer if the session is created depending
on the loaded session type.

In some cases, wayland code needs to talk to the backend directly, e.g.
for drm leasing, etc. With the plugin architecture it's hard to do that.
Not impossible though, we can approach it as in Qt 6, but it's still
harder than linking the code directly.

Of course, the main disadvantage of shipping backends in a lib is that
you will need to patch kwin if you need a custom platform, however such
cases will be rare.

Despite that disadvantage, I still think that it's a step in the right
direction where the goal is to have multi-purpose backends and other
reusable components of kwin.

The legacy X11 standalone platform is linked directly to kwin_x11
executable, while the remaining backends are linked to libkwin.
2022-07-23 11:52:42 +00:00

115 lines
2.8 KiB
C++

/*
KWin - the KDE window manager
This file is part of the KDE project.
SPDX-FileCopyrightText: 2017 Martin Gräßlin <mgraesslin@kde.org>
SPDX-License-Identifier: GPL-2.0-or-later
*/
#include <QTest>
#if QT_VERSION >= QT_VERSION_CHECK(6, 0, 0)
#include <private/qtx11extras_p.h>
#else
#include <QX11Info>
#endif
#include "main.h"
#include "utils/common.h"
namespace KWin
{
class X11TestApplication : public Application
{
Q_OBJECT
public:
X11TestApplication(int &argc, char **argv);
~X11TestApplication() override;
protected:
void performStartup() override;
};
X11TestApplication::X11TestApplication(int &argc, char **argv)
: Application(OperationModeX11, argc, argv)
{
setX11Connection(QX11Info::connection());
setX11RootWindow(QX11Info::appRootWindow());
}
X11TestApplication::~X11TestApplication()
{
}
void X11TestApplication::performStartup()
{
}
}
class X11TimestampUpdateTest : public QObject
{
Q_OBJECT
private Q_SLOTS:
void testGrabAfterServerTime();
void testBeforeLastGrabTime();
};
void X11TimestampUpdateTest::testGrabAfterServerTime()
{
// this test tries to grab the X keyboard with a timestamp in future
// that should fail, but after updating the X11 timestamp, it should
// work again
KWin::updateXTime();
QCOMPARE(KWin::grabXKeyboard(), true);
KWin::ungrabXKeyboard();
// now let's change the timestamp
KWin::kwinApp()->setX11Time(KWin::xTime() + 5 * 60 * 1000);
// now grab keyboard should fail
QCOMPARE(KWin::grabXKeyboard(), false);
// let's update timestamp, now it should work again
KWin::updateXTime();
QCOMPARE(KWin::grabXKeyboard(), true);
KWin::ungrabXKeyboard();
}
void X11TimestampUpdateTest::testBeforeLastGrabTime()
{
// this test tries to grab the X keyboard with a timestamp before the
// last grab time on the server. That should fail, but after updating the X11
// timestamp it should work again
// first set the grab timestamp
KWin::updateXTime();
QCOMPARE(KWin::grabXKeyboard(), true);
KWin::ungrabXKeyboard();
// now go to past
const auto timestamp = KWin::xTime();
KWin::kwinApp()->setX11Time(KWin::xTime() - 5 * 60 * 1000, KWin::Application::TimestampUpdate::Always);
QCOMPARE(KWin::xTime(), timestamp - 5 * 60 * 1000);
// now grab keyboard should fail
QCOMPARE(KWin::grabXKeyboard(), false);
// let's update timestamp, now it should work again
KWin::updateXTime();
QVERIFY(KWin::xTime() >= timestamp);
QCOMPARE(KWin::grabXKeyboard(), true);
KWin::ungrabXKeyboard();
}
int main(int argc, char *argv[])
{
setenv("QT_QPA_PLATFORM", "xcb", true);
KWin::X11TestApplication app(argc, argv);
app.setAttribute(Qt::AA_Use96Dpi, true);
X11TimestampUpdateTest tc;
return QTest::qExec(&tc, argc, argv);
}
#include "test_x11_timestamp_update.moc"