KWin
Loading...
Searching...
No Matches
desktop_switching_animation_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: 2019 Vlad Zahorodnii <vlad.zahorodnii@kde.org>
6
7 SPDX-License-Identifier: GPL-2.0-or-later
8*/
9
10#include "kwin_wayland_test.h"
11
13#include "effect/effectloader.h"
14#include "virtualdesktops.h"
15#include "wayland_server.h"
16#include "window.h"
17#include "workspace.h"
18
19#include <KWayland/Client/surface.h>
20
21using namespace KWin;
22
23static const QString s_socketName = QStringLiteral("wayland_test_effects_desktop_switching_animation-0");
24
25class DesktopSwitchingAnimationTest : public QObject
26{
27 Q_OBJECT
28
29private Q_SLOTS:
30 void initTestCase();
31 void init();
32 void cleanup();
33
34 void testSwitchDesktops_data();
35 void testSwitchDesktops();
36};
37
38void DesktopSwitchingAnimationTest::initTestCase()
39{
41 QSKIP("no render node available");
42 return;
43 }
44 qputenv("XDG_DATA_DIRS", QCoreApplication::applicationDirPath().toUtf8());
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 auto config = KSharedConfig::openConfig(QString(), KConfig::SimpleConfig);
55 KConfigGroup plugins(config, QStringLiteral("Plugins"));
56 const auto builtinNames = EffectLoader().listOfKnownEffects();
57 for (const QString &name : builtinNames) {
58 plugins.writeEntry(name + QStringLiteral("Enabled"), false);
59 }
60 config->sync();
61 kwinApp()->setConfig(config);
62
63 qputenv("KWIN_COMPOSE", QByteArrayLiteral("O2"));
64 qputenv("KWIN_EFFECTS_FORCE_ANIMATIONS", QByteArrayLiteral("1"));
65
66 kwinApp()->start();
67 QVERIFY(applicationStartedSpy.wait());
68}
69
70void DesktopSwitchingAnimationTest::init()
71{
73}
74
75void DesktopSwitchingAnimationTest::cleanup()
76{
77 QVERIFY(effects);
79 QVERIFY(effects->loadedEffects().isEmpty());
80
81 VirtualDesktopManager::self()->setCount(1);
82
84}
85
86void DesktopSwitchingAnimationTest::testSwitchDesktops_data()
87{
88 QTest::addColumn<QString>("effectName");
89
90 QTest::newRow("Fade Desktop") << QStringLiteral("fadedesktop");
91 QTest::newRow("Slide") << QStringLiteral("slide");
92}
93
94void DesktopSwitchingAnimationTest::testSwitchDesktops()
95{
96 // This test verifies that virtual desktop switching animation effects actually
97 // try to animate switching between desktops.
98
99 // We need at least 2 virtual desktops for the test.
100 VirtualDesktopManager::self()->setCount(2);
101 QCOMPARE(VirtualDesktopManager::self()->current(), 1u);
102 QCOMPARE(VirtualDesktopManager::self()->count(), 2u);
103
104 // The Fade Desktop effect will do nothing if there are no windows to fade,
105 // so we have to create a dummy test window.
106 std::unique_ptr<KWayland::Client::Surface> surface(Test::createSurface());
107 QVERIFY(surface != nullptr);
108 std::unique_ptr<Test::XdgToplevel> shellSurface(Test::createXdgToplevelSurface(surface.get()));
109 QVERIFY(shellSurface != nullptr);
110 Window *window = Test::renderAndWaitForShown(surface.get(), QSize(100, 50), Qt::blue);
111 QVERIFY(window);
112 QCOMPARE(window->desktops().count(), 1);
113 QCOMPARE(window->desktops().first(), VirtualDesktopManager::self()->desktops().first());
114
115 // Load effect that will be tested.
116 QFETCH(QString, effectName);
117 QVERIFY(effects);
118 QVERIFY(effects->loadEffect(effectName));
119 QCOMPARE(effects->loadedEffects().count(), 1);
120 QCOMPARE(effects->loadedEffects().first(), effectName);
121 Effect *effect = effects->findEffect(effectName);
122 QVERIFY(effect);
123 QVERIFY(!effect->isActive());
124
125 // Switch to the second virtual desktop.
126 VirtualDesktopManager::self()->setCurrent(2u);
127 QCOMPARE(VirtualDesktopManager::self()->current(), 2u);
128 QVERIFY(effect->isActive());
129 QCOMPARE(effects->activeFullScreenEffect(), effect);
130
131 // Eventually, the animation will be complete.
132 QTRY_VERIFY(!effect->isActive());
133 QTRY_COMPARE(effects->activeFullScreenEffect(), nullptr);
134
135 // Destroy the test window.
136 surface.reset();
137 QVERIFY(Test::waitForWindowClosed(window));
138}
139
141#include "desktop_switching_animation_test.moc"
Base class for all KWin effects.
Definition effect.h:535
QStringList listOfKnownEffects() const override
All the Effects this loader knows of.
QStringList loadedEffects
Q_SCRIPTABLE bool loadEffect(const QString &name)
Effect * findEffect(const QString &name) const
Effect * activeFullScreenEffect() const
virtual bool isActive() const
Definition effect.cpp:447
#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 destroyWaylandConnection()
void setOutputConfig(const QList< QRect > &geometries)
bool setupWaylandConnection(AdditionalWaylandInterfaces flags=AdditionalWaylandInterfaces())
bool renderNodeAvailable()
std::unique_ptr< KWayland::Client::Surface > createSurface()
XdgToplevel * createXdgToplevelSurface(KWayland::Client::Surface *surface, QObject *parent=nullptr)
bool waitForWindowClosed(Window *window)
WaylandServer * waylandServer()
EffectsHandler * effects