2020-08-02 22:22:19 +00:00
|
|
|
/*
|
|
|
|
KWin - the KDE window manager
|
|
|
|
This file is part of the KDE project.
|
2018-12-11 10:22:42 +00:00
|
|
|
|
2020-08-02 22:22:19 +00:00
|
|
|
SPDX-FileCopyrightText: 2018 Vlad Zahorodnii <vlad.zahorodnii@kde.org>
|
2018-12-11 10:22:42 +00:00
|
|
|
|
2020-08-02 22:22:19 +00:00
|
|
|
SPDX-License-Identifier: GPL-2.0-or-later
|
|
|
|
*/
|
2018-12-11 10:22:42 +00:00
|
|
|
|
|
|
|
#include "kwin_wayland_test.h"
|
|
|
|
|
2019-01-06 15:34:10 +00:00
|
|
|
#include "composite.h"
|
2022-11-05 10:43:41 +00:00
|
|
|
#include "core/outputbackend.h"
|
2022-08-29 07:55:49 +00:00
|
|
|
#include "core/renderbackend.h"
|
2018-12-11 10:22:42 +00:00
|
|
|
#include "deleted.h"
|
|
|
|
#include "effectloader.h"
|
|
|
|
#include "effects.h"
|
|
|
|
#include "wayland_server.h"
|
2022-04-22 17:39:12 +00:00
|
|
|
#include "window.h"
|
2018-12-11 10:22:42 +00:00
|
|
|
#include "workspace.h"
|
|
|
|
|
|
|
|
#include <KWayland/Client/surface.h>
|
|
|
|
|
|
|
|
using namespace KWin;
|
|
|
|
|
|
|
|
static const QString s_socketName = QStringLiteral("wayland_test_effects_toplevel_open_close_animation-0");
|
|
|
|
|
|
|
|
class ToplevelOpenCloseAnimationTest : public QObject
|
|
|
|
{
|
|
|
|
Q_OBJECT
|
|
|
|
|
|
|
|
private Q_SLOTS:
|
|
|
|
void initTestCase();
|
|
|
|
void init();
|
|
|
|
void cleanup();
|
|
|
|
|
|
|
|
void testAnimateToplevels_data();
|
|
|
|
void testAnimateToplevels();
|
|
|
|
void testDontAnimatePopups_data();
|
|
|
|
void testDontAnimatePopups();
|
|
|
|
};
|
|
|
|
|
|
|
|
void ToplevelOpenCloseAnimationTest::initTestCase()
|
|
|
|
{
|
|
|
|
qputenv("XDG_DATA_DIRS", QCoreApplication::applicationDirPath().toUtf8());
|
|
|
|
|
2022-04-22 17:39:12 +00:00
|
|
|
qRegisterMetaType<KWin::Window *>();
|
2018-12-11 10:22:42 +00:00
|
|
|
qRegisterMetaType<KWin::Deleted *>();
|
2020-07-07 09:32:29 +00:00
|
|
|
QSignalSpy applicationStartedSpy(kwinApp(), &Application::started);
|
2022-11-05 10:43:41 +00:00
|
|
|
kwinApp()->outputBackend()->setInitialWindowSize(QSize(1280, 1024));
|
2020-12-09 13:06:15 +00:00
|
|
|
QVERIFY(waylandServer()->init(s_socketName));
|
2022-11-05 10:43:41 +00:00
|
|
|
QMetaObject::invokeMethod(kwinApp()->outputBackend(), "setVirtualOutputs", Qt::DirectConnection, Q_ARG(int, 2));
|
2018-12-11 10:22:42 +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();
|
2018-12-11 10:22:42 +00:00
|
|
|
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();
|
2020-07-07 09:32:29 +00:00
|
|
|
QVERIFY(applicationStartedSpy.wait());
|
2019-01-06 15:34:10 +00:00
|
|
|
|
2021-11-10 10:34:18 +00:00
|
|
|
QCOMPARE(Compositor::self()->backend()->compositingType(), KWin::OpenGLCompositing);
|
2018-12-11 10:22:42 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
void ToplevelOpenCloseAnimationTest::init()
|
|
|
|
{
|
|
|
|
QVERIFY(Test::setupWaylandConnection());
|
|
|
|
}
|
|
|
|
|
|
|
|
void ToplevelOpenCloseAnimationTest::cleanup()
|
|
|
|
{
|
|
|
|
auto effectsImpl = qobject_cast<EffectsHandlerImpl *>(effects);
|
|
|
|
QVERIFY(effectsImpl);
|
|
|
|
effectsImpl->unloadAllEffects();
|
|
|
|
QVERIFY(effectsImpl->loadedEffects().isEmpty());
|
|
|
|
|
|
|
|
Test::destroyWaylandConnection();
|
|
|
|
}
|
|
|
|
|
|
|
|
void ToplevelOpenCloseAnimationTest::testAnimateToplevels_data()
|
|
|
|
{
|
|
|
|
QTest::addColumn<QString>("effectName");
|
|
|
|
|
2022-03-23 10:13:38 +00:00
|
|
|
QTest::newRow("Fade") << QStringLiteral("kwin4_effect_fade");
|
|
|
|
QTest::newRow("Glide") << QStringLiteral("glide");
|
|
|
|
QTest::newRow("Scale") << QStringLiteral("kwin4_effect_scale");
|
2018-12-11 10:22:42 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
void ToplevelOpenCloseAnimationTest::testAnimateToplevels()
|
|
|
|
{
|
|
|
|
// This test verifies that window open/close animation effects try to
|
|
|
|
// animate the appearing and the disappearing of toplevel windows.
|
|
|
|
|
|
|
|
// Make sure that we have the right effects ptr.
|
|
|
|
auto effectsImpl = qobject_cast<EffectsHandlerImpl *>(effects);
|
|
|
|
QVERIFY(effectsImpl);
|
|
|
|
|
|
|
|
// Load effect that will be tested.
|
|
|
|
QFETCH(QString, effectName);
|
|
|
|
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
|
|
|
// Create the test window.
|
2022-08-01 21:29:02 +00:00
|
|
|
std::unique_ptr<KWayland::Client::Surface> surface(Test::createSurface());
|
|
|
|
QVERIFY(surface != nullptr);
|
|
|
|
std::unique_ptr<Test::XdgToplevel> shellSurface(Test::createXdgToplevelSurface(surface.get()));
|
|
|
|
QVERIFY(shellSurface != nullptr);
|
|
|
|
Window *window = Test::renderAndWaitForShown(surface.get(), QSize(100, 50), Qt::blue);
|
2022-04-23 19:51:16 +00:00
|
|
|
QVERIFY(window);
|
2018-12-11 10:22:42 +00:00
|
|
|
QVERIFY(effect->isActive());
|
|
|
|
|
2019-01-05 15:32:07 +00:00
|
|
|
// Eventually, the animation will be complete.
|
|
|
|
QTRY_VERIFY(!effect->isActive());
|
2018-12-11 10:22:42 +00:00
|
|
|
|
2022-04-23 19:51:16 +00:00
|
|
|
// Close the test window, the effect should start animating the disappearing
|
|
|
|
// of the window.
|
|
|
|
QSignalSpy windowClosedSpy(window, &Window::windowClosed);
|
2018-12-11 10:22:42 +00:00
|
|
|
shellSurface.reset();
|
|
|
|
surface.reset();
|
|
|
|
QVERIFY(windowClosedSpy.wait());
|
|
|
|
QVERIFY(effect->isActive());
|
|
|
|
|
2019-01-05 15:32:07 +00:00
|
|
|
// Eventually, the animation will be complete.
|
|
|
|
QTRY_VERIFY(!effect->isActive());
|
2018-12-11 10:22:42 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
void ToplevelOpenCloseAnimationTest::testDontAnimatePopups_data()
|
|
|
|
{
|
|
|
|
QTest::addColumn<QString>("effectName");
|
|
|
|
|
2022-03-23 10:13:38 +00:00
|
|
|
QTest::newRow("Fade") << QStringLiteral("kwin4_effect_fade");
|
|
|
|
QTest::newRow("Glide") << QStringLiteral("glide");
|
|
|
|
QTest::newRow("Scale") << QStringLiteral("kwin4_effect_scale");
|
2018-12-11 10:22:42 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
void ToplevelOpenCloseAnimationTest::testDontAnimatePopups()
|
|
|
|
{
|
|
|
|
// This test verifies that window open/close animation effects don't try
|
|
|
|
// to animate popups(e.g. popup menus, tooltips, etc).
|
|
|
|
|
|
|
|
// Make sure that we have the right effects ptr.
|
|
|
|
auto effectsImpl = qobject_cast<EffectsHandlerImpl *>(effects);
|
|
|
|
QVERIFY(effectsImpl);
|
|
|
|
|
|
|
|
// Create the main window.
|
2022-08-01 21:29:02 +00:00
|
|
|
std::unique_ptr<KWayland::Client::Surface> mainWindowSurface(Test::createSurface());
|
|
|
|
QVERIFY(mainWindowSurface != nullptr);
|
|
|
|
std::unique_ptr<Test::XdgToplevel> mainWindowShellSurface(Test::createXdgToplevelSurface(mainWindowSurface.get()));
|
|
|
|
QVERIFY(mainWindowShellSurface != nullptr);
|
|
|
|
Window *mainWindow = Test::renderAndWaitForShown(mainWindowSurface.get(), QSize(100, 50), Qt::blue);
|
2018-12-11 10:22:42 +00:00
|
|
|
QVERIFY(mainWindow);
|
|
|
|
|
|
|
|
// Load effect that will be tested.
|
|
|
|
QFETCH(QString, effectName);
|
|
|
|
QVERIFY(effectsImpl->loadEffect(effectName));
|
|
|
|
QCOMPARE(effectsImpl->loadedEffects().count(), 1);
|
|
|
|
QCOMPARE(effectsImpl->loadedEffects().first(), effectName);
|
|
|
|
Effect *effect = effectsImpl->findEffect(effectName);
|
|
|
|
QVERIFY(effect);
|
|
|
|
QVERIFY(!effect->isActive());
|
|
|
|
|
|
|
|
// Create a popup, it should not be animated.
|
2022-08-01 21:29:02 +00:00
|
|
|
std::unique_ptr<KWayland::Client::Surface> popupSurface(Test::createSurface());
|
|
|
|
QVERIFY(popupSurface != nullptr);
|
|
|
|
std::unique_ptr<Test::XdgPositioner> positioner(Test::createXdgPositioner());
|
2020-09-02 09:44:53 +00:00
|
|
|
QVERIFY(positioner);
|
|
|
|
positioner->set_size(20, 20);
|
|
|
|
positioner->set_anchor_rect(0, 0, 10, 10);
|
|
|
|
positioner->set_gravity(Test::XdgPositioner::gravity_bottom_right);
|
|
|
|
positioner->set_anchor(Test::XdgPositioner::anchor_bottom_left);
|
2022-08-01 21:29:02 +00:00
|
|
|
std::unique_ptr<Test::XdgPopup> popupShellSurface(Test::createXdgPopupSurface(popupSurface.get(), mainWindowShellSurface->xdgSurface(), positioner.get()));
|
|
|
|
QVERIFY(popupShellSurface != nullptr);
|
|
|
|
Window *popup = Test::renderAndWaitForShown(popupSurface.get(), QSize(20, 20), Qt::red);
|
2018-12-11 10:22:42 +00:00
|
|
|
QVERIFY(popup);
|
|
|
|
QVERIFY(popup->isPopupWindow());
|
|
|
|
QCOMPARE(popup->transientFor(), mainWindow);
|
|
|
|
QVERIFY(!effect->isActive());
|
|
|
|
|
|
|
|
// Destroy the popup, it should not be animated.
|
2022-04-22 17:39:12 +00:00
|
|
|
QSignalSpy popupClosedSpy(popup, &Window::windowClosed);
|
2018-12-11 10:22:42 +00:00
|
|
|
popupShellSurface.reset();
|
|
|
|
popupSurface.reset();
|
|
|
|
QVERIFY(popupClosedSpy.wait());
|
|
|
|
QVERIFY(!effect->isActive());
|
2019-01-07 12:35:44 +00:00
|
|
|
|
|
|
|
// Destroy the main window.
|
|
|
|
mainWindowSurface.reset();
|
|
|
|
QVERIFY(Test::waitForWindowDestroyed(mainWindow));
|
2018-12-11 10:22:42 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
WAYLANDTEST_MAIN(ToplevelOpenCloseAnimationTest)
|
|
|
|
#include "toplevel_open_close_animation_test.moc"
|