2020-08-02 22:22:19 +00:00
|
|
|
/*
|
|
|
|
KWin - the KDE window manager
|
|
|
|
This file is part of the KDE project.
|
2019-01-10 14:34:59 +00:00
|
|
|
|
2020-08-02 22:22:19 +00:00
|
|
|
SPDX-FileCopyrightText: 2019 Vlad Zahorodnii <vlad.zahorodnii@kde.org>
|
2019-01-10 14:34:59 +00:00
|
|
|
|
2020-08-02 22:22:19 +00:00
|
|
|
SPDX-License-Identifier: GPL-2.0-or-later
|
|
|
|
*/
|
2019-01-10 14:34:59 +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"
|
2019-01-10 14:34:59 +00:00
|
|
|
#include "wayland_server.h"
|
2022-04-22 17:39:12 +00:00
|
|
|
#include "window.h"
|
2019-01-10 14:34:59 +00:00
|
|
|
#include "workspace.h"
|
|
|
|
|
|
|
|
#include <KWayland/Client/plasmawindowmanagement.h>
|
|
|
|
#include <KWayland/Client/surface.h>
|
|
|
|
|
|
|
|
using namespace KWin;
|
|
|
|
|
|
|
|
static const QString s_socketName = QStringLiteral("wayland_test_effects_minimize_animation-0");
|
|
|
|
|
|
|
|
class MinimizeAnimationTest : public QObject
|
|
|
|
{
|
|
|
|
Q_OBJECT
|
|
|
|
|
|
|
|
private Q_SLOTS:
|
|
|
|
void initTestCase();
|
|
|
|
void init();
|
|
|
|
void cleanup();
|
|
|
|
|
|
|
|
void testMinimizeUnminimize_data();
|
|
|
|
void testMinimizeUnminimize();
|
|
|
|
};
|
|
|
|
|
|
|
|
void MinimizeAnimationTest::initTestCase()
|
|
|
|
{
|
2023-04-15 19:28:12 +00:00
|
|
|
if (!Test::renderNodeAvailable()) {
|
|
|
|
QSKIP("no render node available");
|
|
|
|
return;
|
|
|
|
}
|
2019-01-10 14:34:59 +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),
|
|
|
|
});
|
2019-01-10 14:34:59 +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 14:34:59 +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-10 14:34:59 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
void MinimizeAnimationTest::init()
|
|
|
|
{
|
2023-05-19 11:58:32 +00:00
|
|
|
QVERIFY(Test::setupWaylandConnection(Test::AdditionalWaylandInterface::LayerShellV1 | Test::AdditionalWaylandInterface::WindowManagement));
|
2019-01-10 14:34:59 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
void MinimizeAnimationTest::cleanup()
|
|
|
|
{
|
2023-11-15 09:51:56 +00:00
|
|
|
QVERIFY(effects);
|
|
|
|
effects->unloadAllEffects();
|
|
|
|
QVERIFY(effects->loadedEffects().isEmpty());
|
2019-01-10 14:34:59 +00:00
|
|
|
|
|
|
|
Test::destroyWaylandConnection();
|
|
|
|
}
|
|
|
|
|
|
|
|
void MinimizeAnimationTest::testMinimizeUnminimize_data()
|
|
|
|
{
|
|
|
|
QTest::addColumn<QString>("effectName");
|
|
|
|
|
|
|
|
QTest::newRow("Magic Lamp") << QStringLiteral("magiclamp");
|
2023-03-17 19:51:32 +00:00
|
|
|
QTest::newRow("Squash") << QStringLiteral("squash");
|
2019-01-10 14:34:59 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
void MinimizeAnimationTest::testMinimizeUnminimize()
|
|
|
|
{
|
2022-04-23 19:51:16 +00:00
|
|
|
// This test verifies that a minimize effect tries to animate a window
|
2019-01-10 14:34:59 +00:00
|
|
|
// when it's minimized or unminimized.
|
|
|
|
|
|
|
|
|
|
|
|
// Create a panel at the top of the screen.
|
|
|
|
const QRect panelRect = QRect(0, 0, 1280, 36);
|
2023-05-19 11:58:32 +00:00
|
|
|
std::unique_ptr<KWayland::Client::Surface> panelSurface{Test::createSurface()};
|
|
|
|
std::unique_ptr<Test::LayerSurfaceV1> panelShellSurface{Test::createLayerSurfaceV1(panelSurface.get(), QStringLiteral("dock"))};
|
|
|
|
panelShellSurface->set_size(panelRect.width(), panelRect.height());
|
|
|
|
panelShellSurface->set_exclusive_zone(panelRect.height());
|
|
|
|
panelShellSurface->set_anchor(Test::LayerSurfaceV1::anchor_top);
|
|
|
|
panelSurface->commit(KWayland::Client::Surface::CommitFlag::None);
|
|
|
|
|
|
|
|
QSignalSpy panelConfigureRequestedSpy(panelShellSurface.get(), &Test::LayerSurfaceV1::configureRequested);
|
|
|
|
QVERIFY(panelConfigureRequestedSpy.wait());
|
|
|
|
Window *panel = Test::renderAndWaitForShown(panelSurface.get(), panelConfigureRequestedSpy.last().at(1).toSize(), Qt::blue);
|
2019-01-10 14:34:59 +00:00
|
|
|
QVERIFY(panel);
|
|
|
|
QVERIFY(panel->isDock());
|
2019-09-27 10:01:10 +00:00
|
|
|
QCOMPARE(panel->frameGeometry(), panelRect);
|
2019-01-10 14:34:59 +00:00
|
|
|
|
2022-04-23 19:51:16 +00:00
|
|
|
// Create the test window.
|
2023-05-19 11:58:32 +00:00
|
|
|
QSignalSpy plasmaWindowCreatedSpy(Test::waylandWindowManagement(), &KWayland::Client::PlasmaWindowManagement::windowCreated);
|
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::red);
|
2022-04-23 19:51:16 +00:00
|
|
|
QVERIFY(window);
|
2019-01-10 14:34:59 +00:00
|
|
|
QVERIFY(plasmaWindowCreatedSpy.wait());
|
2023-05-19 11:58:32 +00:00
|
|
|
QCOMPARE(plasmaWindowCreatedSpy.count(), 1);
|
2019-01-10 14:34:59 +00:00
|
|
|
|
|
|
|
// We have to set the minimized geometry because the squash effect needs it,
|
|
|
|
// otherwise it won't start animation.
|
2022-11-07 21:33:00 +00:00
|
|
|
auto plasmaWindow = plasmaWindowCreatedSpy.last().first().value<KWayland::Client::PlasmaWindow *>();
|
2022-04-23 19:51:16 +00:00
|
|
|
QVERIFY(plasmaWindow);
|
2019-01-10 14:34:59 +00:00
|
|
|
const QRect iconRect = QRect(0, 0, 42, 36);
|
2022-08-01 21:29:02 +00:00
|
|
|
plasmaWindow->setMinimizedGeometry(panelSurface.get(), iconRect);
|
2019-01-10 14:34:59 +00:00
|
|
|
Test::flushWaylandConnection();
|
2022-05-16 20:13:39 +00:00
|
|
|
QTRY_COMPARE(window->iconGeometry(), iconRect.translated(panel->frameGeometry().topLeft().toPoint()));
|
2019-01-10 14:34:59 +00:00
|
|
|
|
|
|
|
// Load effect that will be tested.
|
|
|
|
QFETCH(QString, effectName);
|
2023-11-15 09:51:56 +00:00
|
|
|
QVERIFY(effects);
|
|
|
|
QVERIFY(effects->loadEffect(effectName));
|
|
|
|
QCOMPARE(effects->loadedEffects().count(), 1);
|
|
|
|
QCOMPARE(effects->loadedEffects().first(), effectName);
|
|
|
|
Effect *effect = effects->findEffect(effectName);
|
2019-01-10 14:34:59 +00:00
|
|
|
QVERIFY(effect);
|
|
|
|
QVERIFY(!effect->isActive());
|
|
|
|
|
|
|
|
// Start the minimize animation.
|
2023-03-07 10:45:02 +00:00
|
|
|
window->setMinimized(true);
|
2019-01-10 14:34:59 +00:00
|
|
|
QVERIFY(effect->isActive());
|
|
|
|
|
|
|
|
// Eventually, the animation will be complete.
|
|
|
|
QTRY_VERIFY(!effect->isActive());
|
|
|
|
|
|
|
|
// Start the unminimize animation.
|
2023-03-07 10:45:02 +00:00
|
|
|
window->setMinimized(false);
|
2019-01-10 14:34:59 +00:00
|
|
|
QVERIFY(effect->isActive());
|
|
|
|
|
|
|
|
// Eventually, the animation will be complete.
|
|
|
|
QTRY_VERIFY(!effect->isActive());
|
|
|
|
|
|
|
|
// Destroy the panel.
|
|
|
|
panelSurface.reset();
|
2023-04-21 20:28:48 +00:00
|
|
|
QVERIFY(Test::waitForWindowClosed(panel));
|
2019-01-10 14:34:59 +00:00
|
|
|
|
2022-04-23 19:51:16 +00:00
|
|
|
// Destroy the test window.
|
2019-01-10 14:34:59 +00:00
|
|
|
surface.reset();
|
2023-04-21 20:28:48 +00:00
|
|
|
QVERIFY(Test::waitForWindowClosed(window));
|
2019-01-10 14:34:59 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
WAYLANDTEST_MAIN(MinimizeAnimationTest)
|
|
|
|
#include "minimize_animation_test.moc"
|