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"
|
|
|
|
|
2023-11-20 14:53:25 +00:00
|
|
|
#include "effect/effecthandler.h"
|
2023-11-17 08:59:08 +00:00
|
|
|
#include "effect/effectloader.h"
|
2018-12-11 10:22:42 +00:00
|
|
|
#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()
|
|
|
|
{
|
2023-04-15 19:28:12 +00:00
|
|
|
if (!Test::renderNodeAvailable()) {
|
|
|
|
QSKIP("no render node available");
|
|
|
|
return;
|
|
|
|
}
|
2018-12-11 10:22:42 +00:00
|
|
|
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);
|
2020-12-09 13:06:15 +00:00
|
|
|
QVERIFY(waylandServer()->init(s_socketName));
|
2023-05-08 10:16:00 +00:00
|
|
|
Test::setOutputConfig({
|
|
|
|
QRect(0, 0, 1280, 1024),
|
|
|
|
QRect(1280, 0, 1280, 1024),
|
|
|
|
});
|
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());
|
2018-12-11 10:22:42 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
void ToplevelOpenCloseAnimationTest::init()
|
|
|
|
{
|
|
|
|
QVERIFY(Test::setupWaylandConnection());
|
|
|
|
}
|
|
|
|
|
|
|
|
void ToplevelOpenCloseAnimationTest::cleanup()
|
|
|
|
{
|
2023-11-15 09:51:56 +00:00
|
|
|
effects->unloadAllEffects();
|
|
|
|
QVERIFY(effects->loadedEffects().isEmpty());
|
2018-12-11 10:22:42 +00:00
|
|
|
|
|
|
|
Test::destroyWaylandConnection();
|
|
|
|
}
|
|
|
|
|
|
|
|
void ToplevelOpenCloseAnimationTest::testAnimateToplevels_data()
|
|
|
|
{
|
|
|
|
QTest::addColumn<QString>("effectName");
|
|
|
|
|
2023-03-17 19:51:32 +00:00
|
|
|
QTest::newRow("Fade") << QStringLiteral("fade");
|
2022-03-23 10:13:38 +00:00
|
|
|
QTest::newRow("Glide") << QStringLiteral("glide");
|
2023-03-17 19:51:32 +00:00
|
|
|
QTest::newRow("Scale") << QStringLiteral("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.
|
|
|
|
|
|
|
|
// Load effect that will be tested.
|
|
|
|
QFETCH(QString, effectName);
|
2023-11-15 09:51:56 +00:00
|
|
|
QVERIFY(effects->loadEffect(effectName));
|
|
|
|
QCOMPARE(effects->loadedEffects().count(), 1);
|
|
|
|
QCOMPARE(effects->loadedEffects().first(), effectName);
|
|
|
|
Effect *effect = effects->findEffect(effectName);
|
2018-12-11 10:22:42 +00:00
|
|
|
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.
|
2023-03-13 19:21:11 +00:00
|
|
|
QSignalSpy windowClosedSpy(window, &Window::closed);
|
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");
|
|
|
|
|
2023-03-17 19:51:32 +00:00
|
|
|
QTest::newRow("Fade") << QStringLiteral("fade");
|
2022-03-23 10:13:38 +00:00
|
|
|
QTest::newRow("Glide") << QStringLiteral("glide");
|
2023-03-17 19:51:32 +00:00
|
|
|
QTest::newRow("Scale") << QStringLiteral("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).
|
|
|
|
|
|
|
|
// 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);
|
2023-11-15 09:51:56 +00:00
|
|
|
QVERIFY(effects->loadEffect(effectName));
|
|
|
|
QCOMPARE(effects->loadedEffects().count(), 1);
|
|
|
|
QCOMPARE(effects->loadedEffects().first(), effectName);
|
|
|
|
Effect *effect = effects->findEffect(effectName);
|
2018-12-11 10:22:42 +00:00
|
|
|
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.
|
2023-03-13 19:21:11 +00:00
|
|
|
QSignalSpy popupClosedSpy(popup, &Window::closed);
|
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();
|
2023-04-21 20:28:48 +00:00
|
|
|
QVERIFY(Test::waitForWindowClosed(mainWindow));
|
2018-12-11 10:22:42 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
WAYLANDTEST_MAIN(ToplevelOpenCloseAnimationTest)
|
|
|
|
#include "toplevel_open_close_animation_test.moc"
|