141947d2e8
The main motivation behind this change is to prepare kwin for importing kwayland-server code in libkwin. As is, builtin effects are linked with libkwin. Some builtin effects have wayland specific code. If we move wayland stuff in libkwin, there's going to be a circular dependency between kwin4_effect_builtins and libkwin targets. This change intends to break that dependency by linking builtin effects to kwin executable. The main issue with that is that EffectLoader would need to discover the effects indirectly. QStaticPlugin is used for that purpose. Besides breaking the cyclic dependency, it makes builtin effects use the same plugin infrastructure in libkwineffects that external effects use. Metadata in src/effects/effect_builtins.cpp was converted in a list of python dictionaries, which was fed to a python script that generated main.cpp and metadata.json files.
185 lines
7 KiB
C++
185 lines
7 KiB
C++
/*
|
|
KWin - the KDE window manager
|
|
This file is part of the KDE project.
|
|
|
|
SPDX-FileCopyrightText: 2019 Vlad Zahorodnii <vlad.zahorodnii@kde.org>
|
|
|
|
SPDX-License-Identifier: GPL-2.0-or-later
|
|
*/
|
|
|
|
#include "kwin_wayland_test.h"
|
|
|
|
#include "abstract_client.h"
|
|
#include "composite.h"
|
|
#include "effectloader.h"
|
|
#include "effects.h"
|
|
#include "platform.h"
|
|
#include "scene.h"
|
|
#include "wayland_server.h"
|
|
#include "workspace.h"
|
|
|
|
#include <KWayland/Client/surface.h>
|
|
|
|
using namespace KWin;
|
|
|
|
static const QString s_socketName = QStringLiteral("wayland_test_effects_maximize_animation-0");
|
|
|
|
class MaximizeAnimationTest : public QObject
|
|
{
|
|
Q_OBJECT
|
|
|
|
private Q_SLOTS:
|
|
void initTestCase();
|
|
void init();
|
|
void cleanup();
|
|
|
|
void testMaximizeRestore();
|
|
};
|
|
|
|
void MaximizeAnimationTest::initTestCase()
|
|
{
|
|
qputenv("XDG_DATA_DIRS", QCoreApplication::applicationDirPath().toUtf8());
|
|
|
|
qRegisterMetaType<KWin::AbstractClient *>();
|
|
QSignalSpy applicationStartedSpy(kwinApp(), &Application::started);
|
|
QVERIFY(applicationStartedSpy.isValid());
|
|
kwinApp()->platform()->setInitialWindowSize(QSize(1280, 1024));
|
|
QVERIFY(waylandServer()->init(s_socketName));
|
|
|
|
auto config = KSharedConfig::openConfig(QString(), KConfig::SimpleConfig);
|
|
KConfigGroup plugins(config, QStringLiteral("Plugins"));
|
|
const auto builtinNames = EffectLoader().listOfKnownEffects();
|
|
for (const QString &name : builtinNames) {
|
|
plugins.writeEntry(name + QStringLiteral("Enabled"), false);
|
|
}
|
|
config->sync();
|
|
kwinApp()->setConfig(config);
|
|
|
|
qputenv("KWIN_EFFECTS_FORCE_ANIMATIONS", QByteArrayLiteral("1"));
|
|
|
|
kwinApp()->start();
|
|
QVERIFY(applicationStartedSpy.wait());
|
|
Test::initWaylandWorkspace();
|
|
}
|
|
|
|
void MaximizeAnimationTest::init()
|
|
{
|
|
QVERIFY(Test::setupWaylandConnection());
|
|
}
|
|
|
|
void MaximizeAnimationTest::cleanup()
|
|
{
|
|
auto effectsImpl = qobject_cast<EffectsHandlerImpl *>(effects);
|
|
QVERIFY(effectsImpl);
|
|
effectsImpl->unloadAllEffects();
|
|
QVERIFY(effectsImpl->loadedEffects().isEmpty());
|
|
|
|
Test::destroyWaylandConnection();
|
|
}
|
|
|
|
void MaximizeAnimationTest::testMaximizeRestore()
|
|
{
|
|
// This test verifies that the maximize effect animates a client
|
|
// when it's maximized or restored.
|
|
|
|
using namespace KWayland::Client;
|
|
|
|
// Create the test client.
|
|
QScopedPointer<KWayland::Client::Surface> surface(Test::createSurface());
|
|
QVERIFY(!surface.isNull());
|
|
|
|
QScopedPointer<Test::XdgToplevel> shellSurface(Test::createXdgToplevelSurface(surface.data(), nullptr, Test::CreationSetup::CreateOnly));
|
|
|
|
// Wait for the initial configure event.
|
|
Test::XdgToplevel::States states;
|
|
QSignalSpy toplevelConfigureRequestedSpy(shellSurface.data(), &Test::XdgToplevel::configureRequested);
|
|
QSignalSpy surfaceConfigureRequestedSpy(shellSurface->xdgSurface(), &Test::XdgSurface::configureRequested);
|
|
|
|
surface->commit(KWayland::Client::Surface::CommitFlag::None);
|
|
|
|
QVERIFY(surfaceConfigureRequestedSpy.wait());
|
|
QCOMPARE(surfaceConfigureRequestedSpy.count(), 1);
|
|
QCOMPARE(toplevelConfigureRequestedSpy.last().at(0).value<QSize>(), QSize(0, 0));
|
|
states = toplevelConfigureRequestedSpy.last().at(1).value<Test::XdgToplevel::States>();
|
|
QVERIFY(!states.testFlag(Test::XdgToplevel::State::Activated));
|
|
QVERIFY(!states.testFlag(Test::XdgToplevel::State::Maximized));
|
|
|
|
// Draw contents of the surface.
|
|
shellSurface->xdgSurface()->ack_configure(surfaceConfigureRequestedSpy.last().at(0).value<quint32>());
|
|
AbstractClient *client = Test::renderAndWaitForShown(surface.data(), QSize(100, 50), Qt::blue);
|
|
QVERIFY(client);
|
|
QVERIFY(client->isActive());
|
|
QCOMPARE(client->maximizeMode(), MaximizeMode::MaximizeRestore);
|
|
|
|
// We should receive a configure event when the client becomes active.
|
|
QVERIFY(surfaceConfigureRequestedSpy.wait());
|
|
QCOMPARE(surfaceConfigureRequestedSpy.count(), 2);
|
|
states = toplevelConfigureRequestedSpy.last().at(1).value<Test::XdgToplevel::States>();
|
|
QVERIFY(states.testFlag(Test::XdgToplevel::State::Activated));
|
|
QVERIFY(!states.testFlag(Test::XdgToplevel::State::Maximized));
|
|
|
|
// Load effect that will be tested.
|
|
const QString effectName = QStringLiteral("kwin4_effect_maximize");
|
|
auto effectsImpl = qobject_cast<EffectsHandlerImpl *>(effects);
|
|
QVERIFY(effectsImpl);
|
|
QVERIFY(effectsImpl->loadEffect(effectName));
|
|
QCOMPARE(effectsImpl->loadedEffects().count(), 1);
|
|
QCOMPARE(effectsImpl->loadedEffects().first(), effectName);
|
|
Effect *effect = effectsImpl->findEffect(effectName);
|
|
QVERIFY(effect);
|
|
QVERIFY(!effect->isActive());
|
|
|
|
// Maximize the client.
|
|
QSignalSpy frameGeometryChangedSpy(client, &AbstractClient::frameGeometryChanged);
|
|
QVERIFY(frameGeometryChangedSpy.isValid());
|
|
QSignalSpy maximizeChangedSpy(client, qOverload<AbstractClient *, bool, bool>(&AbstractClient::clientMaximizedStateChanged));
|
|
QVERIFY(maximizeChangedSpy.isValid());
|
|
|
|
workspace()->slotWindowMaximize();
|
|
QVERIFY(surfaceConfigureRequestedSpy.wait());
|
|
QCOMPARE(surfaceConfigureRequestedSpy.count(), 3);
|
|
QCOMPARE(toplevelConfigureRequestedSpy.last().at(0).value<QSize>(), QSize(1280, 1024));
|
|
states = toplevelConfigureRequestedSpy.last().at(1).value<Test::XdgToplevel::States>();
|
|
QVERIFY(states.testFlag(Test::XdgToplevel::State::Activated));
|
|
QVERIFY(states.testFlag(Test::XdgToplevel::State::Maximized));
|
|
|
|
// Draw contents of the maximized client.
|
|
shellSurface->xdgSurface()->ack_configure(surfaceConfigureRequestedSpy.last().at(0).value<quint32>());
|
|
Test::render(surface.data(), QSize(1280, 1024), Qt::red);
|
|
QVERIFY(frameGeometryChangedSpy.wait());
|
|
QCOMPARE(frameGeometryChangedSpy.count(), 1);
|
|
QCOMPARE(maximizeChangedSpy.count(), 1);
|
|
QCOMPARE(client->maximizeMode(), MaximizeMode::MaximizeFull);
|
|
QVERIFY(effect->isActive());
|
|
|
|
// Eventually, the animation will be complete.
|
|
QTRY_VERIFY(!effect->isActive());
|
|
|
|
// Restore the client.
|
|
workspace()->slotWindowMaximize();
|
|
QVERIFY(surfaceConfigureRequestedSpy.wait());
|
|
QCOMPARE(surfaceConfigureRequestedSpy.count(), 4);
|
|
QCOMPARE(toplevelConfigureRequestedSpy.last().at(0).value<QSize>(), QSize(100, 50));
|
|
states = toplevelConfigureRequestedSpy.last().at(1).value<Test::XdgToplevel::States>();
|
|
QVERIFY(states.testFlag(Test::XdgToplevel::State::Activated));
|
|
QVERIFY(!states.testFlag(Test::XdgToplevel::State::Maximized));
|
|
|
|
// Draw contents of the restored client.
|
|
shellSurface->xdgSurface()->ack_configure(surfaceConfigureRequestedSpy.last().at(0).value<quint32>());
|
|
Test::render(surface.data(), QSize(100, 50), Qt::blue);
|
|
QVERIFY(frameGeometryChangedSpy.wait());
|
|
QCOMPARE(frameGeometryChangedSpy.count(), 2);
|
|
QCOMPARE(maximizeChangedSpy.count(), 2);
|
|
QCOMPARE(client->maximizeMode(), MaximizeMode::MaximizeRestore);
|
|
QVERIFY(effect->isActive());
|
|
|
|
// Eventually, the animation will be complete.
|
|
QTRY_VERIFY(!effect->isActive());
|
|
|
|
// Destroy the test client.
|
|
surface.reset();
|
|
QVERIFY(Test::waitForWindowDestroyed(client));
|
|
}
|
|
|
|
WAYLANDTEST_MAIN(MaximizeAnimationTest)
|
|
#include "maximize_animation_test.moc"
|