kwin/autotests/integration/effects/maximize_animation_test.cpp

181 lines
7 KiB
C++
Raw Normal View History

2020-08-02 22:22:19 +00:00
/*
KWin - the KDE window manager
This file is part of the KDE project.
2020-08-02 22:22:19 +00:00
SPDX-FileCopyrightText: 2019 Vlad Zahorodnii <vlad.zahorodnii@kde.org>
2020-08-02 22:22:19 +00:00
SPDX-License-Identifier: GPL-2.0-or-later
*/
#include "kwin_wayland_test.h"
#include "composite.h"
2022-11-05 10:43:41 +00:00
#include "core/outputbackend.h"
#include "effectloader.h"
#include "effects.h"
#include "scene/workspacescene.h"
#include "wayland_server.h"
2022-04-22 17:39:12 +00:00
#include "window.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());
2022-04-22 17:39:12 +00:00
qRegisterMetaType<KWin::Window *>();
QSignalSpy applicationStartedSpy(kwinApp(), &Application::started);
QVERIFY(waylandServer()->init(s_socketName));
QMetaObject::invokeMethod(kwinApp()->outputBackend(), "setVirtualOutputs", Qt::DirectConnection, Q_ARG(QVector<QRect>, QVector<QRect>() << QRect(0, 0, 1280, 1024) << QRect(1280, 0, 1280, 1024)));
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_COMPOSE", QByteArrayLiteral("O2"));
qputenv("KWIN_EFFECTS_FORCE_ANIMATIONS", QByteArrayLiteral("1"));
kwinApp()->start();
QVERIFY(applicationStartedSpy.wait());
}
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()
{
2022-04-23 19:51:16 +00:00
// This test verifies that the maximize effect animates a window
// when it's maximized or restored.
2022-04-23 19:51:16 +00:00
// Create the test window.
std::unique_ptr<KWayland::Client::Surface> surface(Test::createSurface());
QVERIFY(surface != nullptr);
std::unique_ptr<Test::XdgToplevel> shellSurface(Test::createXdgToplevelSurface(surface.get(), Test::CreationSetup::CreateOnly));
// Wait for the initial configure event.
Test::XdgToplevel::States states;
QSignalSpy toplevelConfigureRequestedSpy(shellSurface.get(), &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>());
Window *window = Test::renderAndWaitForShown(surface.get(), QSize(100, 50), Qt::blue);
2022-04-23 19:51:16 +00:00
QVERIFY(window);
QVERIFY(window->isActive());
QCOMPARE(window->maximizeMode(), MaximizeMode::MaximizeRestore);
2022-04-23 19:51:16 +00:00
// We should receive a configure event when the window 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());
2022-04-23 19:51:16 +00:00
// Maximize the window.
QSignalSpy frameGeometryChangedSpy(window, &Window::frameGeometryChanged);
QSignalSpy maximizeChangedSpy(window, qOverload<Window *, bool, bool>(&Window::clientMaximizedStateChanged));
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));
2022-04-23 19:51:16 +00:00
// Draw contents of the maximized window.
shellSurface->xdgSurface()->ack_configure(surfaceConfigureRequestedSpy.last().at(0).value<quint32>());
Test::render(surface.get(), QSize(1280, 1024), Qt::red);
QVERIFY(frameGeometryChangedSpy.wait());
QCOMPARE(frameGeometryChangedSpy.count(), 1);
QCOMPARE(maximizeChangedSpy.count(), 1);
2022-04-23 19:51:16 +00:00
QCOMPARE(window->maximizeMode(), MaximizeMode::MaximizeFull);
QVERIFY(effect->isActive());
// Eventually, the animation will be complete.
QTRY_VERIFY(!effect->isActive());
2022-04-23 19:51:16 +00:00
// Restore the window.
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));
2022-04-23 19:51:16 +00:00
// Draw contents of the restored window.
shellSurface->xdgSurface()->ack_configure(surfaceConfigureRequestedSpy.last().at(0).value<quint32>());
Test::render(surface.get(), QSize(100, 50), Qt::blue);
QVERIFY(frameGeometryChangedSpy.wait());
QCOMPARE(frameGeometryChangedSpy.count(), 2);
QCOMPARE(maximizeChangedSpy.count(), 2);
2022-04-23 19:51:16 +00:00
QCOMPARE(window->maximizeMode(), MaximizeMode::MaximizeRestore);
QVERIFY(effect->isActive());
// Eventually, the animation will be complete.
QTRY_VERIFY(!effect->isActive());
2022-04-23 19:51:16 +00:00
// Destroy the test window.
surface.reset();
2022-04-23 19:51:16 +00:00
QVERIFY(Test::waitForWindowDestroyed(window));
}
WAYLANDTEST_MAIN(MaximizeAnimationTest)
#include "maximize_animation_test.moc"