2020-08-02 22:22:19 +00:00
|
|
|
/*
|
|
|
|
KWin - the KDE window manager
|
|
|
|
This file is part of the KDE project.
|
2019-01-10 17:59:20 +00:00
|
|
|
|
2020-08-02 22:22:19 +00:00
|
|
|
SPDX-FileCopyrightText: 2019 Vlad Zahorodnii <vlad.zahorodnii@kde.org>
|
2019-01-10 17:59:20 +00:00
|
|
|
|
2020-08-02 22:22:19 +00:00
|
|
|
SPDX-License-Identifier: GPL-2.0-or-later
|
|
|
|
*/
|
2019-01-10 17:59:20 +00:00
|
|
|
|
|
|
|
#include "kwin_wayland_test.h"
|
|
|
|
|
|
|
|
#include "composite.h"
|
2022-08-29 07:55:49 +00:00
|
|
|
#include "core/platform.h"
|
2019-01-10 17:59:20 +00:00
|
|
|
#include "effectloader.h"
|
|
|
|
#include "effects.h"
|
|
|
|
#include "scene.h"
|
|
|
|
#include "wayland_server.h"
|
2022-04-22 17:39:12 +00:00
|
|
|
#include "window.h"
|
2019-01-10 17:59:20 +00:00
|
|
|
#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 *>();
|
2020-07-07 09:32:29 +00:00
|
|
|
QSignalSpy applicationStartedSpy(kwinApp(), &Application::started);
|
2019-01-10 17:59:20 +00:00
|
|
|
kwinApp()->platform()->setInitialWindowSize(QSize(1280, 1024));
|
2020-12-09 13:06:15 +00:00
|
|
|
QVERIFY(waylandServer()->init(s_socketName));
|
2022-09-16 08:42:55 +00:00
|
|
|
QMetaObject::invokeMethod(kwinApp()->platform(), "setVirtualOutputs", Qt::DirectConnection, Q_ARG(int, 2));
|
2019-01-10 17:59:20 +00:00
|
|
|
|
|
|
|
auto config = KSharedConfig::openConfig(QString(), KConfig::SimpleConfig);
|
|
|
|
KConfigGroup plugins(config, QStringLiteral("Plugins"));
|
2021-10-09 15:38:14 +00:00
|
|
|
const auto builtinNames = EffectLoader().listOfKnownEffects();
|
2019-01-10 17:59:20 +00:00
|
|
|
for (const QString &name : builtinNames) {
|
|
|
|
plugins.writeEntry(name + QStringLiteral("Enabled"), false);
|
|
|
|
}
|
|
|
|
config->sync();
|
|
|
|
kwinApp()->setConfig(config);
|
|
|
|
|
2022-09-07 10:16:36 +00:00
|
|
|
qputenv("KWIN_COMPOSE", QByteArrayLiteral("O2"));
|
2019-01-10 17:59:20 +00:00
|
|
|
qputenv("KWIN_EFFECTS_FORCE_ANIMATIONS", QByteArrayLiteral("1"));
|
|
|
|
|
|
|
|
kwinApp()->start();
|
2020-07-07 09:32:29 +00:00
|
|
|
QVERIFY(applicationStartedSpy.wait());
|
2019-01-10 17:59:20 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
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
|
2019-01-10 17:59:20 +00:00
|
|
|
// when it's maximized or restored.
|
|
|
|
|
2022-04-23 19:51:16 +00:00
|
|
|
// Create the test window.
|
2022-08-01 21:29:02 +00:00
|
|
|
std::unique_ptr<KWayland::Client::Surface> surface(Test::createSurface());
|
|
|
|
QVERIFY(surface != nullptr);
|
2019-01-10 17:59:20 +00:00
|
|
|
|
2022-08-01 21:29:02 +00:00
|
|
|
std::unique_ptr<Test::XdgToplevel> shellSurface(Test::createXdgToplevelSurface(surface.get(), Test::CreationSetup::CreateOnly));
|
2019-01-10 17:59:20 +00:00
|
|
|
|
|
|
|
// Wait for the initial configure event.
|
2021-05-11 05:26:51 +00:00
|
|
|
Test::XdgToplevel::States states;
|
2022-08-01 21:29:02 +00:00
|
|
|
QSignalSpy toplevelConfigureRequestedSpy(shellSurface.get(), &Test::XdgToplevel::configureRequested);
|
2021-05-11 05:26:51 +00:00
|
|
|
QSignalSpy surfaceConfigureRequestedSpy(shellSurface->xdgSurface(), &Test::XdgSurface::configureRequested);
|
2019-02-26 13:41:07 +00:00
|
|
|
|
2021-09-03 17:54:03 +00:00
|
|
|
surface->commit(KWayland::Client::Surface::CommitFlag::None);
|
2019-02-26 13:41:07 +00:00
|
|
|
|
2021-05-11 05:26:51 +00:00
|
|
|
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));
|
2019-01-10 17:59:20 +00:00
|
|
|
|
|
|
|
// Draw contents of the surface.
|
2021-05-11 05:26:51 +00:00
|
|
|
shellSurface->xdgSurface()->ack_configure(surfaceConfigureRequestedSpy.last().at(0).value<quint32>());
|
2022-08-01 21:29:02 +00:00
|
|
|
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);
|
2019-01-10 17:59:20 +00:00
|
|
|
|
2022-04-23 19:51:16 +00:00
|
|
|
// We should receive a configure event when the window becomes active.
|
2021-05-11 05:26:51 +00:00
|
|
|
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));
|
2019-01-10 17:59:20 +00:00
|
|
|
|
|
|
|
// 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));
|
2019-01-10 17:59:20 +00:00
|
|
|
|
|
|
|
workspace()->slotWindowMaximize();
|
2021-05-11 05:26:51 +00:00
|
|
|
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));
|
2019-01-10 17:59:20 +00:00
|
|
|
|
2022-04-23 19:51:16 +00:00
|
|
|
// Draw contents of the maximized window.
|
2021-05-11 05:26:51 +00:00
|
|
|
shellSurface->xdgSurface()->ack_configure(surfaceConfigureRequestedSpy.last().at(0).value<quint32>());
|
2022-08-01 21:29:02 +00:00
|
|
|
Test::render(surface.get(), QSize(1280, 1024), Qt::red);
|
2020-02-05 09:28:50 +00:00
|
|
|
QVERIFY(frameGeometryChangedSpy.wait());
|
|
|
|
QCOMPARE(frameGeometryChangedSpy.count(), 1);
|
2019-01-10 17:59:20 +00:00
|
|
|
QCOMPARE(maximizeChangedSpy.count(), 1);
|
2022-04-23 19:51:16 +00:00
|
|
|
QCOMPARE(window->maximizeMode(), MaximizeMode::MaximizeFull);
|
2019-01-10 17:59:20 +00:00
|
|
|
QVERIFY(effect->isActive());
|
|
|
|
|
|
|
|
// Eventually, the animation will be complete.
|
|
|
|
QTRY_VERIFY(!effect->isActive());
|
|
|
|
|
2022-04-23 19:51:16 +00:00
|
|
|
// Restore the window.
|
2019-01-10 17:59:20 +00:00
|
|
|
workspace()->slotWindowMaximize();
|
2021-05-11 05:26:51 +00:00
|
|
|
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));
|
2019-01-10 17:59:20 +00:00
|
|
|
|
2022-04-23 19:51:16 +00:00
|
|
|
// Draw contents of the restored window.
|
2021-05-11 05:26:51 +00:00
|
|
|
shellSurface->xdgSurface()->ack_configure(surfaceConfigureRequestedSpy.last().at(0).value<quint32>());
|
2022-08-01 21:29:02 +00:00
|
|
|
Test::render(surface.get(), QSize(100, 50), Qt::blue);
|
2020-02-05 09:28:50 +00:00
|
|
|
QVERIFY(frameGeometryChangedSpy.wait());
|
|
|
|
QCOMPARE(frameGeometryChangedSpy.count(), 2);
|
2019-01-10 17:59:20 +00:00
|
|
|
QCOMPARE(maximizeChangedSpy.count(), 2);
|
2022-04-23 19:51:16 +00:00
|
|
|
QCOMPARE(window->maximizeMode(), MaximizeMode::MaximizeRestore);
|
2019-01-10 17:59:20 +00:00
|
|
|
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.
|
2019-01-10 17:59:20 +00:00
|
|
|
surface.reset();
|
2022-04-23 19:51:16 +00:00
|
|
|
QVERIFY(Test::waitForWindowDestroyed(window));
|
2019-01-10 17:59:20 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
WAYLANDTEST_MAIN(MaximizeAnimationTest)
|
|
|
|
#include "maximize_animation_test.moc"
|